drawSegsEntity.c

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------*/
00002 /* file: drawSegsEntity.h                                                 */
00003 /* Copyright INRIA 2006                                                   */
00004 /* Authors : Jean-Baptiste Silvy                                          */
00005 /* desc : Contains functions needed to draw a segs handle                  */
00006 /*------------------------------------------------------------------------*/
00007 
00008 #include "drawSegsEntity.h"
00009 #include "GetProperty.h"
00010 #include "periScreen.h"
00011 #include "BasicAlgos.h"
00012 #include "PloEch.h"
00013 #include "math_graphics.h"
00014 #include "Xcall1.h"
00015 #include "drawMarks.h"
00016 #include "clipping.h"
00017 #include "MALLOC.h"
00018 #include "axesScale.h"
00019 #include "Champ.h"
00020 #include "MALLOC.h"
00021 #include "clipping.h"
00022 #include "sciprint.h"
00023 #include "PloEch.h"
00024 
00025 /*---------------------------------------------------------------------------------*/
00026 int drawSegsEntity( sciPointObj * pObj )
00027 {
00028   sciSegs * ppSegs = pSEGS_FEATURE( pObj ) ;
00029   sciPointObj * parentSubWin = sciGetParentSubwin( pObj ) ;
00030   int foreground = sciGetForeground( pObj ) ;
00031   int lineWidth = sciGetLineWidth( pObj ) ;
00032   int lineStyle = sciGetLineStyle( pObj ) ;
00033   int markStyle = sciGetMarkStyle( pObj ) ;
00034   int v = 0 ;
00035   double dv = 0.0 ;
00036   int verbose = 0 ;
00037   int DPI[2] ;
00038 
00039   if ( !sciGetVisibility(pObj) ) { return 0 ; }
00040 
00041   sciClip(pObj);
00042 
00043   GetDPIFromDriver( DPI ) ;
00044 
00045 #ifdef _MSC_VER
00046   flag_DO = MaybeSetWinhdc() ;
00047 #endif
00048 
00049   C2F (dr) ("xset", "dashes", &foreground, &foreground, &v, &v, &v, &v, &dv,
00050     &dv, &dv, &dv, 5L, 4096);
00051   C2F (dr) ("xset", "thickness", &lineWidth, PI0, PI0, PI0, PI0, PI0, PD0,
00052     PD0, PD0, PD0, 0L, 0L);    
00053   C2F (dr) ("xset", "line style", &lineStyle, PI0, PI0, PI0, PI0, PI0, PD0,
00054     PD0, PD0, PD0, 0L, 0L);
00055   C2F (dr) ("xset", "mark", &markStyle, &lineWidth, PI0, PI0, PI0, PI0, PD0, PD0,
00056     PD0, PD0, 0L, 0L);
00057 #ifdef _MSC_VER
00058   if ( flag_DO == 1) { ReleaseWinHdc () ; }
00059 #endif
00060 
00061   if ( ppSegs->ptype == 0 ) /* ptype == 0 F.Leray : This is NOT A champ */
00062   {  
00063     int n = ppSegs->Nbr1 ;
00064     int * xCoords = NULL ;
00065     int * yCoords = NULL ;
00066     int * pstyle  = NULL ;
00067     int i ;
00068 
00069     xCoords = MALLOC( n * sizeof(int) ) ;
00070     if ( xCoords == NULL )
00071     {
00072       sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00073       return -1 ;
00074     }
00075 
00076     yCoords = MALLOC( n * sizeof(int) ) ;
00077     if ( yCoords == NULL )
00078     {
00079       FREE( xCoords ) ;
00080       sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00081       return -1 ;
00082     }
00083 
00084     if ((pstyle = MALLOC ( (n/2) * sizeof(integer))) == NULL) { return -1 ; } /* SS 19.04*/
00085 
00086     pstyle = MALLOC( (n/2) * sizeof(int) ) ;
00087     if ( pstyle == NULL )
00088     {
00089       FREE( xCoords ) ;
00090       FREE( yCoords ) ;
00091       sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00092       return -1 ;
00093     }
00094 
00095     if ( ppSegs->iflag == 1)
00096     {
00097       for ( i =0 ; i < (n/2) ; i++ )
00098       {
00099         pstyle[i] = sciGetGoodIndex( pObj, ppSegs->pstyle[i] ) ;
00100       }
00101     }
00102     else
00103     {
00104       pstyle[0] = sciGetGoodIndex( pObj, ppSegs->pstyle[0]) ;
00105     }
00106 
00107     if ( sciGetIs3d( parentSubWin ) ) 
00108     {
00109       /* 3d mode */
00110       double * xvect = NULL;
00111       double * yvect = NULL;
00112       double * zvect = NULL;
00113 
00114       xvect = createDoubleArrayCopy( ppSegs->vx, n ) ;
00115       if ( xvect == NULL )
00116       {
00117         FREE( xCoords ) ;
00118         FREE( yCoords ) ;
00119         FREE( pstyle  ) ;
00120         sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00121         return -1 ;
00122       }
00123 
00124       yvect = createDoubleArrayCopy( ppSegs->vy, n ) ;
00125       if ( yvect == NULL )
00126       {
00127         FREE( xCoords ) ;
00128         FREE( yCoords ) ;
00129         FREE( pstyle  ) ;
00130         FREE( xvect   ) ;
00131         sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00132         return -1 ;
00133       }
00134 
00135       if ( ppSegs->vz != NULL )
00136       {
00137         zvect = createDoubleArrayCopy( ppSegs->vz, n ) ;
00138         if ( zvect == NULL )
00139         {
00140           FREE( xCoords ) ;
00141           FREE( yCoords ) ;
00142           FREE( pstyle  ) ;
00143           FREE( xvect   ) ;
00144           FREE( yvect   ) ;
00145           sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00146           return -1 ;
00147         }
00148       }
00149 
00150       ReverseDataFor3D(parentSubWin,xvect,yvect,zvect,n);
00151 
00152       trans3d(parentSubWin,n,xCoords,yCoords,xvect,yvect,zvect);
00153 
00154       FREE( xvect ) ;
00155       FREE( yvect ) ;
00156       if ( zvect != NULL )
00157       {
00158         FREE( zvect ) ;
00159       }
00160     }
00161     else
00162     {
00163       for ( i = 0 ; i < n ; i++ )
00164       {
00165         xCoords[i] = XScale( ppSegs->vx[i] ) ; 
00166         yCoords[i] = YScale( ppSegs->vy[i] ) ;
00167       }
00168     }
00169 #ifdef _MSC_VER 
00170     flag_DO = MaybeSetWinhdc();
00171 #endif
00172 
00173     if( sciGetIsMark(pObj) )
00174     {
00175       drawPolyMarks( pObj, n, xCoords, yCoords, DPI ) ;
00176     }
00177 
00178     if( sciGetIsLine( pObj ) )
00179     {
00180 
00181       C2F (dr) ("xset", "dashes", &foreground, &foreground, &v, &v, &v, &v, &dv,
00182         &dv, &dv, &dv, 5L, 4096);
00183       C2F (dr) ("xset", "thickness", &lineWidth, PI0, PI0, PI0, PI0, PI0, PD0,
00184         PD0, PD0, PD0, 0L, 0L);    
00185       C2F (dr) ("xset", "line style", &lineStyle, PI0, PI0, PI0, PI0, PI0, PD0,
00186         PD0, PD0, PD0, 0L, 0L);
00187 
00188       if ( ppSegs->arrowsize == 0 )
00189       {
00190         /* only lines */
00191         C2F(dr)("xsegs","v",xCoords,yCoords,&n,pstyle,&ppSegs->iflag,
00192           PI0,PD0,PD0,PD0,PD0,0L,0L);
00193       }
00194       else
00195       {
00196         int arrowSize = computeRealArrowSize( pObj, n, xCoords, yCoords ) ;                         
00197         C2F(dr)("xarrow","v",xCoords,yCoords,&n,&arrowSize,pstyle,&ppSegs->iflag,PD0,PD0,PD0,PD0,0L,0L);
00198         /* with C2F(dr)("xarrow",... did not work: why? What does (dr1) routine make more than (dr) in New Graphics mode ?? */
00199         /* Answer : dr deals with pixels value (data: xm and ym are integers!!) whereas dr1 deals with double value coming from the user */
00200         /* This is true for old and new graphics mode. */
00201       }
00202 
00203     }
00204 
00205 
00206 #ifdef _MSC_VER 
00207     if ( flag_DO == 1) ReleaseWinHdc ();
00208 #endif 
00209     FREE( xCoords ) ;
00210     FREE( yCoords ) ;
00211     FREE( pstyle  ) ;
00212   }
00213   else    /*ptype == 1*/ /* ptype == 1 F.Leray : This IS A champ */
00214   {
00215     int xz[10] ;
00216     int useColor = 0 ;
00217     int narg = 0 ;
00218     int nbArrow = 0 ;
00219     int arrowSize = 0 ;
00220     int * xCoords = NULL ;
00221     int * yCoords = NULL ;
00222     int * zCoords = NULL ;
00223     int n = 2 * ppSegs->Nbr1 * ppSegs->Nbr2 ;
00224 
00225 
00226 #ifdef _MSC_VER 
00227     flag_DO = MaybeSetWinhdc();
00228 #endif
00229     C2F(dr)("xget","use color",&verbose, &useColor, &narg,&v,&v,&v,&dv,&dv,&dv,&dv,0L,0L);
00230     if (useColor)
00231     {
00232       C2F(dr)("xget","color",&verbose,xz,&narg,&v,&v,&v,&dv,&dv,&dv,&dv,0L,0L);
00233     }
00234     else
00235     {
00236       C2F(dr)("xget","line style",&verbose,xz,&narg,&v,&v,&v,&dv,&dv,&dv,&dv,0L,0L);
00237     }
00238 #ifdef _MSC_VER 
00239     if ( flag_DO == 1) { ReleaseWinHdc () ; }
00240 #endif 
00241 
00242     
00243 
00244 
00245     xCoords = MALLOC( n * sizeof (int) ) ;
00246     if ( xCoords == NULL )
00247     {
00248       sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00249       return -1 ;
00250     }
00251 
00252     yCoords = MALLOC( n * sizeof (int) ) ;
00253     if( yCoords == NULL )
00254     {
00255       FREE( xCoords ) ;
00256       sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00257       return -1 ;
00258     }
00259 
00260     if ( ppSegs->typeofchamp == 1 )
00261     { /* champ1 has been called */
00262 
00263       zCoords = MALLOC ( (n/2) * sizeof(int) ) ;
00264 
00265       if ( zCoords == NULL ) 
00266       {
00267         FREE( xCoords ) ;
00268         FREE( yCoords ) ;
00269         sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00270         return -1 ;
00271       }      
00272     }
00273 
00274     sciChamp2DRealToPixel(xCoords,yCoords,zCoords,&nbArrow,&arrowSize,
00275       ppSegs->vx,ppSegs->vy,ppSegs->vfx,
00276       ppSegs->vfy,&(ppSegs->Nbr1),
00277       &(ppSegs->Nbr2),&(ppSegs->parfact),&(ppSegs->typeofchamp), FALSE ) ;
00278 #ifdef _MSC_VER 
00279     flag_DO = MaybeSetWinhdc();
00280 #endif
00281 
00283     /* a bit tricky */
00284 
00285     /* test if we are in 3d HERE */
00286     if ( sciGetIs3d( parentSubWin ) )
00287     {
00288       double * xvect = NULL;
00289       double * yvect = NULL;
00290       int i ;
00291 
00292       xvect = MALLOC( n * sizeof(double) ) ;
00293       if ( xvect == NULL )
00294       {
00295         FREE( xCoords ) ;
00296         FREE( yCoords ) ;
00297         if ( zCoords != NULL ) { FREE( zCoords ) ; }
00298         sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00299         return -1 ;
00300       }
00301 
00302       yvect = MALLOC( n * sizeof(double) ) ;
00303       if ( yvect == NULL )
00304       {
00305         FREE( xCoords ) ;
00306         FREE( yCoords ) ;
00307         if ( zCoords != NULL ) { FREE(zCoords) ; }
00308         FREE( xvect ) ;
00309         sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00310         return -1 ;
00311       }
00312 
00313       for( i = 0 ; i < n ; i++ )
00314       {
00315         xvect[i] = XPi2R(xCoords[i]);
00316         yvect[i] = YPi2R(yCoords[i]);
00317       }
00318 
00319 
00320       /* F.Leray 06.12.04 */
00321       /* A REVOIR : ne marche pas en 3D */
00322       ReverseDataFor3D(parentSubWin,xvect,yvect,NULL,n);
00323 
00324       trans3d(parentSubWin,n,xCoords,yCoords,xvect,yvect,NULL);
00325 
00326       FREE(xvect) ;
00327       FREE(yvect) ;
00328     }
00329 
00330     if ( sciGetIsMark( pObj ) )
00331     {
00332       drawPolyMarks( pObj, n, xCoords, yCoords, DPI ) ;
00333     }
00334 
00335     if( sciGetIsLine( pObj ) )
00336     {
00337       arrowSize =  computeRealArrowSize( pObj, nbArrow, xCoords, yCoords ) ;
00338 
00339       C2F (dr) ("xset", "dashes", &foreground, &foreground, &v, &v, &v, &v, &dv,
00340         &dv, &dv, &dv, 5L, 4096);
00341       C2F (dr) ("xset", "thickness", &lineWidth, PI0, PI0, PI0, PI0, PI0, PD0,
00342         PD0, PD0, PD0, 0L, 0L);    
00343       C2F (dr) ("xset", "line style", &lineStyle, PI0, PI0, PI0, PI0, PI0, PD0,
00344         PD0, PD0, PD0, 0L, 0L);
00345       if( ppSegs->typeofchamp == 0 )
00346       {
00347         int sflag = 0 ;
00348         C2F(dr)("xarrow","v",xCoords,yCoords,&nbArrow,&arrowSize,xz,&sflag,&dv,&dv,&dv,&dv,0L,0L);
00349       }
00350       else
00351       {
00352         int sflag = 1 ;
00353         C2F(dr)("xarrow","v",xCoords,yCoords,&nbArrow,&arrowSize,zCoords,&sflag,&dv,&dv,&dv,&dv,0L,0L);
00354       }
00355     }
00356 
00357 
00358 #ifdef _MSC_VER 
00359     if ( flag_DO == 1) { ReleaseWinHdc(); }
00360 #endif 
00361     FREE(xCoords) ;
00362     FREE(yCoords) ;
00363     if( zCoords != NULL )
00364     {
00365       FREE( zCoords ) ;
00366     }
00367   }  
00368   
00369   sciUnClip(pObj);
00370 
00371   return 0 ;
00372 }
00373 /*---------------------------------------------------------------------------------*/
00381 int computeRealArrowSize( sciPointObj * pSegs, int nbSegs, int xCoord[], int yCoord[] )
00382 {
00383   sciSegs * ppSegs = pSEGS_FEATURE( pSegs ) ;
00384   double arrowSize = ppSegs->arrowsize ;
00385   int one = 1 ;
00386 
00387   if ( ppSegs->ptype == 0 )
00388   {
00389     if ( arrowSize > 0 )
00390     {
00391       int iAs2 = 0 ;
00392       int iAs  = 0 ;
00393       C2F(echelle2dl)( &arrowSize, &arrowSize, &iAs, &iAs2, &one, &one, "f2i" ) ;
00394       return iAs / 2 ;
00395     }
00396     else
00397     {
00398       /* taken from Xcall1.c */
00399       int i ;
00400       double length = 0.0 ;
00401       for ( i = 0 ; i < nbSegs / 2 ; i++ )
00402       {
00403         double dx ;
00404         double dy ;
00405         dx=( xCoord[2*i+1] - xCoord[2*i] ) ;
00406         dy=( yCoord[2*i+1] - yCoord[2*i] ) ;
00407         length += sqrt( dx * dx + dy * dy ) ;
00408       }
00409       if ( nbSegs != 0 )
00410       {
00411         length /= nbSegs / 2 ;
00412       }
00413       return round( -arrowSize * length ) ;
00414     }
00415   }
00416   else
00417   {
00418     if ( ppSegs->arrowsize >= 0 )
00419     {
00420       double arsize1 = ((double) Cscale.WIRect1[2])/(5*( ppSegs->Nbr1));
00421       double arsize2 = ((double) Cscale.WIRect1[3])/(5*( ppSegs->Nbr2));
00422       double arsize  =  (arsize1 < arsize2) ? inint(arsize1*10.0) : inint(arsize2*10.0) ;
00423       return (int)((arsize)*(ppSegs->arrowsize));
00424     }
00425   }
00426 
00427   return 0 ;
00428 
00429 }
00430 /*---------------------------------------------------------------------------------*/

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