HandleManagement.c

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------
00002  *    Graphic library 
00003  *    Copyright INRIA
00004  *    newGraph Library header
00005  *    Matthieu PHILIPPE  , INRIA 2001-2002
00006  *    Djalel ABDEMOUCHE  , INRIA 2002-2004
00007  *    Fabrice Leray      , INRIA 2004-2006
00008  *    Jean Baptiste Silvy, INRIA 2005-xxxx
00009  *    Comment:
00010  *    This file contains all functions used in graphics handle management.
00011  --------------------------------------------------------------------------*/
00012 
00013 #include <stdio.h> 
00014 #include <string.h>
00015 #include <math.h>
00016 #include <stdlib.h>
00017 #include <stdarg.h>
00018 #include <time.h>
00019 
00020 #include "HandleManagement.h"
00021 #include "InitObjects.h"
00022 #include "DrawObjects.h"
00023 #include "DestroyObjects.h"
00024 #include "SetProperty.h"
00025 #include "GetProperty.h"
00026 #include "BuildObjects.h"
00027 #include "bcg.h"
00028 #include "WindowList.h"
00029 #include "../../../data_structures/includes/DoublyLinkedList.h" /* REORGANISATION TEMPORAIRE */
00030 #include "sciprint.h"
00031 #include "CurrentObjectsManagement.h"
00032 #include "ObjectSelection.h"
00033 
00034 
00035 #include "MALLOC.h" /* MALLOC */
00036 
00037 sciHandleTab * PENDOFHANDLETAB;
00038 
00039 int sciSwapObjects( sciPointObj * firstObject, sciPointObj * secondObject );
00040 int sciRelocateObject( sciPointObj * movedObj, sciPointObj * newParent );
00041 
00042 /*********************************** Handle ******************************************/
00043 
00047 void
00048 sciSetHandle (sciPointObj * pobj, sciHandleTab * pvalue)
00049 {
00050   if ( (pobj != getFigureModel()) && (pobj != getAxesModel()))
00051   {
00052     sciGetRelationship(pobj)->phandle = pvalue ; 
00053   }
00054 }
00055 
00056 
00057 sciHandleTab * sciGetpendofhandletab()
00058 {
00059   return PENDOFHANDLETAB;
00060 }
00061 
00065 int
00066 sciAddNewHandle (sciPointObj * pobj)
00067 {
00068   sciHandleTab *newhd;
00069   
00070   if ((newhd = MALLOC ((sizeof (sciHandleTab)))) == NULL)
00071     return -1;
00072   newhd->pprev = PENDOFHANDLETAB;/* We have to use directly PENDOFHANDLETAB and not sciGetHandleTabPointer */
00073   newhd->pnext = (sciHandleTab *) NULL;
00074   newhd->index = (long)pobj;/* pour l'instant je prend la valeur du pointeur comme handle !!! */
00075   
00076   newhd->pointobj = pobj;
00077   if (PENDOFHANDLETAB != (sciHandleTab *) NULL)
00078     PENDOFHANDLETAB->pnext = newhd;
00079   else
00080     newhd->pprev = (sciHandleTab *) NULL;
00081   PENDOFHANDLETAB = newhd;
00082   
00083   sciSetHandle (pobj, PENDOFHANDLETAB);
00084   return 0;
00085 }
00086 
00087 
00091 sciHandleTab * sciGetHandleTabPointer (sciPointObj * pobj)
00092 {
00093   return sciGetRelationship (pobj)->phandle ;
00094 }
00095 
00096 
00097 
00098 
00102 extern int sciDelHandle
00103 (sciPointObj * pobj)
00104 {
00105   int tmp = 0;
00106   sciHandleTab *phandletabtodel;        /* point to a handle structure (prev, value, next) */
00107 
00108   /* We get the handle pointer */
00109   tmp = 0;
00110   phandletabtodel = (sciHandleTab *) sciGetHandleTabPointer (pobj);
00111   if (phandletabtodel == (sciHandleTab *) NULL)
00112     tmp = 1;
00113   else
00114     {
00115       if (phandletabtodel->pprev == (sciHandleTab *) NULL)
00116         tmp += 2;
00117       if (phandletabtodel->pnext == (sciHandleTab *) NULL)
00118         tmp += 4;
00119     }
00120   switch (tmp)
00121     {
00122     case 0: /* le phandletabtodel->pprev != NULL et le phandletabtodel->pnext != NULL */
00123       /*(phandletabtodel->pnext)->pprev = (phandletabtodel->pprev)->pnext; ERREUR */
00124       (phandletabtodel->pnext)->pprev = phandletabtodel->pprev;
00125       (phandletabtodel->pprev)->pnext = phandletabtodel->pnext;
00126       FREE (phandletabtodel);
00127       break;
00128     case 2:/* le phandletabtodel->pprev == NULL et le phandletabtodel->pnext !NULL */
00129       (phandletabtodel->pnext)->pprev = (sciHandleTab *) NULL;
00130       FREE (phandletabtodel);
00131       break;
00132     case 4:/* le phandletabtodel->pprev != NULL et le phandletabtodel->pnext == NULL */
00133       (phandletabtodel->pprev)->pnext = (sciHandleTab *) NULL;
00134       PENDOFHANDLETAB = phandletabtodel->pprev;
00135       FREE (phandletabtodel);    
00136       break;
00137     case 6:/* le phandletabtodel->pprev == NULL et le phandletabtodel->pnext == NULL */
00138       FREE (phandletabtodel);
00139       PENDOFHANDLETAB = (sciHandleTab *) NULL;
00140       break;
00141     case 1:/* the handeltab is empty */
00142     case 3:/* in prevision */
00143     case 5:/* in prevision */
00144     case 7:/* in prevision */
00145     default:
00146       sciprint ("no handle to del\n");
00147       return -1;
00148       break;
00149     }
00150   return 0;
00151 }
00152 
00153 
00157 long sciGetHandle (sciPointObj * pobj)
00158 {
00159   return (sciGetRelationship(pobj))->phandle->index ;
00160 }
00161 
00162 
00163 
00167 sciPointObj *
00168 sciGetPointerFromHandle (long handle)
00169 {
00170 
00171   sciHandleTab *phandletab;
00172   if ( handle != sciGetHandle(getFigureModel()) && handle != sciGetHandle(getAxesModel()))
00173     {
00174       phandletab = PENDOFHANDLETAB;
00175       while ((phandletab != NULL) && (phandletab->index != handle))
00176         phandletab = phandletab->pprev;
00177       
00178       if (phandletab == NULL)
00179         {
00180           /* sciprint ("this is not or no more a valid handle !!\n");  F.Leray Adding 'or no more' */
00181           return (sciPointObj *) NULL;
00182         }  
00183       return (sciPointObj *) phandletab->pointobj;
00184     }
00185   else if ( handle == sciGetHandle(getFigureModel()))
00186     return (sciPointObj *) getFigureModel();
00187   else if ( handle == sciGetHandle(getAxesModel()))
00188     return (sciPointObj *) getAxesModel();
00189   else
00190     {
00191       /* sciprint ("this is not or no more a valid handle !!\n");  F.Leray Adding 'or no more' */
00192       return (sciPointObj *) NULL;
00193     }
00194     
00195 }
00196 
00197 /************************************************ End Handle *************************************************/
00198 
00199 
00200 
00201 
00205 sciRelationShip *
00206 sciGetRelationship (sciPointObj * pobj)
00207 {
00208   sciRelationShip *tmp=NULL;
00209   switch (sciGetEntityType (pobj))
00210     {
00211     case SCI_FIGURE:
00212       return &(pFIGURE_FEATURE (pobj)->relationship);
00213       break;
00214     case SCI_SUBWIN:
00215       return  &(pSUBWIN_FEATURE (pobj)->relationship);
00216       break;
00217     case SCI_TEXT:
00218       return  &(pTEXT_FEATURE (pobj)->relationship);
00219       break;
00220     case SCI_TITLE:
00221       return  &(pTITLE_FEATURE (pobj)->text.relationship);
00222       break;
00223     case SCI_LEGEND:
00224       return  &(pLEGEND_FEATURE (pobj)->text.relationship);
00225       break;
00226     case SCI_ARC:
00227       return  &(pARC_FEATURE (pobj)->relationship);
00228       break;
00229     case SCI_SEGS: 
00230       return  &(pSEGS_FEATURE (pobj)->relationship);
00231       break; 
00232     case SCI_FEC:  
00233       return  &(pFEC_FEATURE (pobj)->relationship);
00234       break;
00235     case SCI_GRAYPLOT:
00236       return  &(pGRAYPLOT_FEATURE (pobj)->relationship);
00237       break;
00238     case SCI_POLYLINE:
00239       return  &(pPOLYLINE_FEATURE (pobj)->relationship);
00240       break;
00241     case SCI_RECTANGLE:
00242       return  &(pRECTANGLE_FEATURE (pobj)->relationship);
00243       break;
00244     case SCI_SURFACE:
00245       return  &(pSURFACE_FEATURE (pobj)->relationship);
00246       break;
00247     case SCI_LIGHT:
00248       return  &(pLIGHT_FEATURE (pobj)->relationship);
00249       break;
00250     case SCI_AXES:
00251       return  &(pAXES_FEATURE (pobj)->relationship);
00252       break;
00253     case SCI_PANNER:
00254       return  &(pPANNER_FEATURE (pobj)->relationship);
00255       break;
00256     case SCI_SBH:
00257       return  &(pSBH_FEATURE (pobj)->relationship);
00258       break;
00259     case SCI_SBV:
00260       return  &(pSBV_FEATURE (pobj)->relationship);
00261       break;
00262     case SCI_MENU:
00263       return  &(pMENU_FEATURE (pobj)->relationship);
00264       break;
00265     case SCI_MENUCONTEXT:
00266       return  &(pMENUCONTEXT_FEATURE (pobj)->relationship);
00267       break;
00268     case SCI_STATUSB:
00269       return  &(pSTATUSB_FEATURE (pobj)->relationship);
00270       break;
00271     case SCI_AGREG:
00272       return  &(pAGREG_FEATURE (pobj)->relationship);
00273       break; 
00274     case SCI_MERGE:
00275       return  &(pMERGE_FEATURE (pobj)->relationship);
00276       break;
00277     case SCI_LABEL: /* F.Leray 27.05.04 */
00278       return  sciGetRelationship( pLABEL_FEATURE (pobj)->text ) ;
00279       break;
00280     case SCI_UIMENU: 
00281       tmp=&(pUIMENU_FEATURE (pobj)->label.relationship);
00282       return  &(pUIMENU_FEATURE (pobj)->label.relationship);
00283       break;
00284     case SCI_CONSOLE:
00285       return  &(pCONSOLE_FEATURE (pobj)->relationship);
00286       break;
00287     case SCI_FRAME:
00288       return  &(pFRAME_FEATURE (pobj)->relationship);
00289       break;
00290     case SCI_WINDOW:
00291       return  &(pWINDOW_FEATURE (pobj)->relationship);
00292       break;
00293     case SCI_WINDOWFRAME:
00294       return  &(pWINDOWFRAME_FEATURE (pobj)->relationship);
00295       break;
00296     case SCI_SCREEN:
00297       return  &(pSCREEN_FEATURE (pobj)->relationship);
00298       break;
00299     default:
00300       return (sciRelationShip *) NULL;
00301       break;
00302     }
00303   return (sciRelationShip *) NULL;
00304 }
00305 
00306 
00312 int sciSetParent (sciPointObj * pson, sciPointObj * pparent)
00313 {
00314   sciGetRelationship(pson)->pparent = pparent ;
00315   return 0;
00316 }
00317 
00318 
00322 sciPointObj * sciGetParent (sciPointObj * pobj)
00323 {
00324   return sciGetRelationship(pobj)->pparent ;
00325 }
00326 
00327 
00328 /****************************************** SONS ******************************************/
00329 
00330 
00335 BOOL
00336 sciAddThisToItsParent (sciPointObj * pthis, sciPointObj * pparent)
00337 {
00338   sciSons * OneSon = NULL ;
00339   
00340   if ( sciSetParent(pthis, pparent) == -1 )
00341   {
00342     return FALSE ;
00343   }
00344 
00345   if ( pparent == NULL )
00346   {
00347     /* nothing more to do */
00348     return TRUE ;
00349   }
00350 
00351   /* Si c'est null alors il n'y a pas encore de fils d'affecte */
00352   if ( sciGetRelationship (pparent)->psons != NULL )
00353   {                     
00354     /* Il existe au moins un fils d'affecte */
00355     /* on cree la nouvelle variable */
00356     if ( (OneSon = MALLOC(sizeof(sciSons))) == NULL ) { return FALSE ; }
00357     OneSon->pnext = sciGetRelationship (pparent)->psons ;
00358     OneSon->pprev = NULL;
00359     sciGetRelationship(pparent)->psons->pprev = OneSon ;
00360   }
00361   else
00362   {
00363     /* C'est tout neuf alors on cree la variable */
00364     if ( (OneSon = MALLOC( sizeof(sciSons) )) == NULL ) {return FALSE ; }
00365     OneSon->pnext = NULL ;
00366     OneSon->pprev = NULL ;
00367     sciGetRelationship(pparent)->plastsons = OneSon ;
00368   }
00369   OneSon->pointobj = pthis ;
00370   sciGetRelationship(pparent)->psons = OneSon;
00371   return TRUE;
00372 }
00373 
00374 
00381 BOOL sciDelThisToItsParent (sciPointObj * pthis, sciPointObj * pparent)
00382 {
00383   int tmp = 0 ;
00384   sciSons *OneSon     = NULL ;
00385   sciSons *OneSonprev = NULL ;
00386 
00387   if ( pparent == NULL )
00388   {
00389     /* nothing to do */
00390     return TRUE ;
00391   }
00392 
00393   /* recherche de l'objet a effacer*/
00394   OneSon = (sciGetRelationship (pparent)->psons);
00395   OneSonprev = OneSon;
00396   while ( (OneSon != NULL) &&  (OneSon->pointobj != pthis) )
00397   {
00398     OneSonprev = OneSon ; 
00399     OneSon = OneSon->pnext;
00400   }
00401 
00402   /* dans quel cas de figure somme nous ? */
00403   if ( OneSon == NULL )
00404   {
00405     tmp++ ;
00406   }
00407   else 
00408   {
00409     if ( OneSon->pprev == NULL ) { tmp += 2 ; }
00410     if ( OneSon->pnext == NULL ) { tmp += 4 ; }
00411   }
00412 
00413   switch(tmp)
00414   {
00415     case 0:/* ok<-OneSon->ok     */
00416       (OneSon->pnext)->pprev = (OneSon->pprev);
00417       (OneSon->pprev)->pnext = (OneSon->pnext);
00418       FREE(OneSon);
00419       return TRUE;
00420       break;
00421     case 2:/* ok<-OneSon->NULL   */
00422       (sciGetRelationship (pparent)->psons) = OneSon->pnext;
00423       (sciGetRelationship (pparent)->psons)->pprev = NULL ;
00424       FREE(OneSon);
00425       return TRUE;
00426       break;
00427     case 4:/* NULL<-OneSon->ok   */
00428       sciGetRelationship (pparent)->plastsons = OneSon->pprev;
00429       (sciGetRelationship (pparent)->plastsons)->pnext = NULL;
00430       FREE(OneSon);
00431       return TRUE;
00432       break;
00433     case 6:/* NULL<-OneSon->NULL */
00434       sciGetRelationship (pparent)->plastsons = NULL;
00435       sciGetRelationship (pparent)->psons = NULL;
00436       FREE(OneSon);
00437       return TRUE;
00438       break;
00439     case 1:/* OneSon == NULL     */
00440     case 3:
00441     case 5:
00442     case 7:
00443     default :
00444       sciprint ("There is no Son in this Parent!!!!\n");
00445       return FALSE;
00446       break;
00447     }
00448 
00449   return FALSE ;
00450 }
00451 
00452 
00457 sciSons * sciGetSons (sciPointObj * pobj)
00458 {
00459   return (sciSons *) (sciGetRelationship (pobj)->psons);
00460 }
00461 
00462 
00467 sciSons * sciGetLastSons (sciPointObj * pobj)
00468 {
00469   return (sciSons *)sciGetRelationship (pobj)->plastsons ;
00470 }
00471 
00472 /*-----------------------------------------------------------------------------------*/
00477 sciSons * sciGetNextAccessibleSon( sciSons * son )
00478 {
00479   sciSons * nextSon = son->pnext ;
00480   while ( nextSon != NULL && !(sciGetIsAccessibleChild( nextSon->pointobj ) ) )
00481   {
00482     nextSon = nextSon->pnext ;
00483   }
00484   return nextSon ;
00485 }
00486 /*-----------------------------------------------------------------------------------*/
00490 sciSons * sciGetFirstAccessibleSon( sciPointObj * pObj )
00491 {
00492   sciSons * firstSon = sciGetSons( pObj ) ;
00493   while( firstSon != NULL && !(sciGetIsAccessibleChild( firstSon->pointobj ) ) )
00494   {
00495     firstSon = firstSon->pnext ;
00496   }
00497   return firstSon ;
00498 }
00499 /*-----------------------------------------------------------------------------------*/
00506 sciSons * sciFindSon( sciPointObj * searchedObj, sciPointObj * parentObj )
00507 {
00508   sciSons * curSon = sciGetSons( parentObj ) ;
00509   while ( curSon != NULL && curSon->pointobj != searchedObj )
00510   {
00511     curSon = curSon->pnext ;
00512   }
00513   return curSon ;
00514 }
00515 /*-----------------------------------------------------------------------------------*/
00516 
00517 /************************************ END SONS **************************************/
00518 /*-----------------------------------------------------------------------------------*/
00526 int sciRelocateObject( sciPointObj * movedObj, sciPointObj * newParent )
00527 {
00528   sciPointObj * oldParent = sciGetParent( movedObj ) ;
00529   
00530   if ( oldParent == newParent )
00531   {
00532     /* nothing to do */
00533     return 0 ;
00534   }
00535   
00536   sciDelThisToItsParent( movedObj, oldParent ) ;
00537   sciAddThisToItsParent( movedObj, newParent ) ;
00538 
00539   /* if an axis has been moved, its previous parent, a figure might haven't son any more.*/
00540   if ( sciGetEntityType( movedObj ) == SCI_SUBWIN && sciGetIsSelected( movedObj ) )
00541   {
00542     sciSelectFirstSubwin( oldParent ) ;
00543     if ( sciGetNbTypedObjects( oldParent, SCI_SUBWIN ) == 0 )
00544     {
00545       /* we need to recreate a subwin */
00546       sciPointObj * newSubWin = ConstructSubWin( oldParent, sciGetNumFigure( oldParent ) ) ;
00547       if ( newSubWin == NULL )
00548       {
00549         return -1 ;
00550       }
00551       /* we must set the selected subwin */
00552       sciSetOriginalSubWin( oldParent, newSubWin ) ;
00553       sciInitSelectedSubWin( newSubWin ) ;
00554     }
00555   }
00556   else if ( sciGetEntityType( movedObj ) == SCI_SURFACE )
00557   {
00558     /* we must take care of the merge objects */
00559     sciPointObj * oldParentSubwin = sciGetParentSubwin( oldParent ) ;
00560     sciPointObj * newParentSubwin = sciGetParentSubwin( newParent ) ;
00561 
00562     /* the merge object will be the same if the surfaces are in the same subwin */
00563     if ( oldParentSubwin != newParentSubwin )
00564     {
00565       pSUBWIN_FEATURE(oldParent)->surfcounter-- ;
00566       pSUBWIN_FEATURE(newParent)->surfcounter++ ;
00567       
00568       /* reccompute the merge objects */
00569       updateMerge( oldParentSubwin ) ;
00570       updateMerge( newParentSubwin ) ;
00571     }
00572   }
00573 
00574   return 0 ;
00575 }
00576 /*-----------------------------------------------------------------------------------*/
00580 int sciGetNbFigures( void )
00581 {
00582   int nbFigure = 0 ;
00583   int flag     = 0 ;
00584   int ids          ;
00585   getWins( &nbFigure, &ids, &flag ) ;
00586   return nbFigure ;
00587 }
00588 /*-----------------------------------------------------------------------------------*/
00598 BOOL sciCanBeSonOf( sciPointObj * son, sciPointObj * parent )
00599 {
00600   sciEntityType parentType ;
00601 
00602   if ( parent == NULL || son == NULL )
00603   {
00604     return FALSE ;
00605   }
00606   
00607   parentType = sciGetEntityType( parent ) ;
00608   switch ( sciGetEntityType( son ) )
00609   {
00610   case SCI_SCREEN:
00611     return FALSE ;
00612   case SCI_WINDOWFRAME:
00613     return ( parentType == SCI_SCREEN ) ;
00614   case SCI_WINDOW:
00615     return ( parentType == SCI_WINDOWFRAME ) ;
00616   case SCI_FRAME:
00617     return ( parentType == SCI_WINDOW || parentType == SCI_FRAME ) ;
00618   case SCI_CONSOLE:
00619     return ( parentType == SCI_FRAME ) ;
00620   case SCI_FIGURE:
00621     return ( parentType == SCI_FRAME ) ;
00622   case SCI_SUBWIN:
00623     /* axes can only have figure parents */
00624     return ( parentType == SCI_FIGURE ) ;
00625   default:
00626     return ( parentType == SCI_SUBWIN || parentType == SCI_AGREG ) ;
00627   }
00628   return FALSE ;
00629 }
00630 /*-----------------------------------------------------------------------------------*/
00639 int sciRelocateHandles( unsigned long handles[], int nbHandles, unsigned long newParentHandle )
00640 {
00641   sciPointObj ** movedObjs = NULL ; /* array of moved objects */
00642   sciPointObj *  parentObj = sciGetPointerFromHandle( newParentHandle ) ;
00643   int i ;
00644   int nbFigure = 0 ;
00645   DoublyLinkedList * modifiedFiguresList = DoublyLinkedList_new() ; /* list of modified figures. */
00646                                                               /* Only the needed figures are redrawn at the end of the function. */
00647   
00648   /* check parent */
00649   if ( parentObj == NULL )
00650   {
00651     Scierror( 999,"The parent handle is not or no more valid.\r\n" ) ;
00652     return -1 ;
00653   }
00654 
00655   /* we copy the pointer on the objects in this array */
00656   movedObjs = MALLOC( nbHandles * sizeof(sciPointObj *) ) ;
00657   if ( movedObjs == NULL )
00658   {
00659     Scierror(999,"Memory full, aborting operation.\r\n") ;
00660     return -1 ;
00661   }
00662 
00663   /* check handles and copy their object in an array */
00664   /* It is better to do a first loop, just to test the validity of the handles. */
00665   /* As a result, we won't need to stop in the middle of the changes. */
00666   for ( i = 0 ; i < nbHandles ; i++ )
00667   {
00668     movedObjs[i] = sciGetPointerFromHandle( handles[i] ) ;
00669     /* check handle validity */
00670     if ( movedObjs[i] == NULL )
00671     {
00672        Scierror(999,"Handle number %d is not or no more valid.\r\n", i + 1  ) ;
00673        FREE( movedObjs ) ;
00674        return -1 ;
00675     }
00676     /* check that handles can be inserted under the parent */
00677     if ( !sciCanBeSonOf( movedObjs[i], parentObj ) )
00678     {
00679       Scierror(999,"Handle number %d is not compatible with the parent handle.\r\n", i + 1 ) ;
00680       FREE( movedObjs ) ;
00681       return -1 ;
00682     }
00683   }
00684 
00685   /* allocate the array with as much space as number of figures. */
00686   nbFigure = sciGetNbFigures() ;
00687 
00688   /* now move each object */
00689   for ( i = 0 ; i < nbHandles ; i++ )
00690   {
00691     /* both the current and future (wich might be the same) figure of the object */
00692     /* are modified. */
00693     sciPointObj * currentFig = sciGetParentFigure( movedObjs[i] ) ;
00694     sciPointObj * futureFig  = sciGetParentFigure( parentObj    ) ;
00695 
00696     if ( List_find( modifiedFiguresList, currentFig ) == NULL )
00697     {
00698       /* the figure was not already considered modified */
00699       modifiedFiguresList = List_push( modifiedFiguresList, currentFig ) ;
00700     }
00701 
00702     if ( List_find( modifiedFiguresList, futureFig ) == NULL )
00703     {
00704       /* the figure was not already considered modified */
00705       modifiedFiguresList = List_push( modifiedFiguresList, futureFig ) ;
00706     }
00707 
00708     if ( sciRelocateObject( movedObjs[i], parentObj ) != 0 )
00709     {
00710       Scierror(999,"Error relocating handle %d.", i  ) ;
00711     }
00712   }
00713   
00714   FREE( movedObjs ) ;
00715  
00716   
00717 
00718 
00719   /* redraw the modified figures */
00720   while( !List_is_empty( modifiedFiguresList ) )
00721   {
00722     sciPointObj * modifiedFig  = NULL ;
00723     modifiedFiguresList = List_pop( modifiedFiguresList, (void *)&modifiedFig ) ;
00724     sciDrawObj( modifiedFig ) ;
00725   }
00726   
00727   List_free( modifiedFiguresList ) ;
00728   
00729   return 0 ;
00730 }
00731 /*-----------------------------------------------------------------------------------*/
00737 int sciSwapObjects( sciPointObj * firstObject, sciPointObj * secondObject )
00738 {
00739   sciSons * firstSon  = NULL ; /* the two sons entitities pointing on the objects */
00740   sciSons * secondSon = NULL ;
00741   sciPointObj * firstParent  = sciGetParent( firstObject  ) ; /* current parent of the first object */
00742   sciPointObj * secondParent = sciGetParent( secondObject ) ;
00743 
00744   /* check compatibility of the objects with new parents */
00745   if ( !sciCanBeSonOf( firstObject, sciGetParent( secondObject ) ) )
00746   {
00747     Scierror(999,"First handle is not compatible with its new parent.\r\n" ) ;
00748     return -1 ;
00749   }
00750   
00751   if ( !sciCanBeSonOf( secondObject, sciGetParent( firstObject ) ) )
00752   {
00753     Scierror(999,"Second handle is not compatible with its new parent.\r\n" ) ;
00754     return -1 ;
00755   }
00756 
00757   firstSon  = sciFindSon( firstObject , firstParent  ) ;
00758   secondSon = sciFindSon( secondObject, secondParent ) ;
00759   
00760   /* check if the sons are correct. This should always be true. */
00761   if ( firstSon == NULL )
00762   {
00763     Scierror( 999,"First object is not correctly placed in the hierarchy.\r\n" ) ;
00764     return -1 ;
00765   }
00766   if ( secondSon == NULL )
00767   {
00768     Scierror( 999,"Second object is not correctly placed in the hierarchy.\r\n" ) ;
00769     return -1 ;
00770   }
00771 
00772   /* Swap the two pointed values of the handles */
00773   firstSon->pointobj  = secondObject ;
00774   secondSon->pointobj = firstObject  ;
00775 
00776   /* change their parents */
00777   sciSetParent( firstObject , secondParent ) ;
00778   sciSetParent( secondObject, firstParent  ) ;
00779 
00780 
00781   /* In the case of surface handles we must take care of merge objects */
00782   if (    sciGetEntityType( firstObject ) == SCI_SURFACE
00783        || sciGetEntityType( secondObject ) == SCI_SURFACE )
00784   {
00785     sciPointObj * firstParentSubwin  = sciGetParentSubwin( firstObject  ) ;
00786     sciPointObj * secondParentSubwin = sciGetParentSubwin( secondObject ) ;
00787 
00788     /* update the number of figure for each objects */
00789     if ( sciGetEntityType( firstObject ) == SCI_SURFACE )
00790     {
00791       /* beware, the objects have already been moved to their new parents */
00792       pSUBWIN_FEATURE( firstParentSubwin  )->surfcounter++ ;
00793       pSUBWIN_FEATURE( secondParentSubwin )->surfcounter-- ;
00794     }
00795 
00796     if ( sciGetEntityType( secondObject ) == SCI_SURFACE )
00797     {
00798       pSUBWIN_FEATURE( secondParentSubwin )->surfcounter++ ;
00799       pSUBWIN_FEATURE( firstParentSubwin  )->surfcounter-- ;
00800     }
00801 
00802     updateMerge( firstParentSubwin  ) ;
00803     updateMerge( secondParentSubwin ) ;
00804   }
00805   
00806 
00807   return 0 ;
00808 
00809 }
00810 /*-----------------------------------------------------------------------------------*/
00818 int swapHandles( unsigned long firstHdl, unsigned long secondHdl )
00819 {
00820   sciPointObj * firstObject  = sciGetPointerFromHandle( firstHdl  )  ;
00821   sciPointObj * secondObject = sciGetPointerFromHandle( secondHdl )  ;
00822   sciPointObj * firstParentFig  = NULL ;
00823   sciPointObj * secondParentFig = NULL ;
00824   
00825   if ( firstObject == NULL )
00826   {
00827     Scierror( 999,"First handle is not or no more valid.\r\n" ) ;
00828     return -1 ;
00829   }
00830 
00831   if ( secondObject == NULL )
00832   {
00833      Scierror( 999,"Second handle is not or no more valid.\r\n" ) ;
00834     return -1 ;
00835   }
00836 
00837   if ( sciSwapObjects( firstObject, secondObject ) != 0 )
00838   {
00839     return -1 ;
00840   }
00841 
00842   firstParentFig  = sciGetParentFigure( firstObject ) ;
00843   secondParentFig = sciGetParentFigure( secondObject ) ;
00844 
00845   /* redraw the parent figures */
00846   if ( firstParentFig == secondParentFig )
00847   {
00848     /* we need only to redraw once since it is the same figure */
00849     sciDrawObj( firstParentFig ) ;
00850   }
00851   else
00852   {
00853     sciDrawObj( firstParentFig )  ;
00854     sciDrawObj( secondParentFig ) ;
00855   }
00856   
00857   return 0 ;
00858 
00859 }
00860 /*-----------------------------------------------------------------------------------*/

Generated on Sun Mar 4 15:03:52 2007 for Scilab [trunk] by  doxygen 1.5.1