Back to index

salome-gui  6.5.0
GLViewer_BaseObjects.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "GLViewer_BaseObjects.h"
00024 #include "GLViewer_BaseDrawers.h"
00025 #include "GLViewer_AspectLine.h"
00026 #include "GLViewer_CoordSystem.h"
00027 #include "GLViewer_Text.h"
00028 #include "GLViewer_Group.h"
00029 #include "GLViewer_Drawer.h"
00030 
00031 #include <QFile>
00032 
00036 GLViewer_MarkerSet::GLViewer_MarkerSet( int number, float size, const QString& toolTip ) :
00037   GLViewer_Object(),
00038   myNumber( 0 ),
00039   myXCoord( 0 ),
00040   myYCoord( 0 )       
00041 {
00042     
00043     myMarkerSize = size;
00044     myHNumbers.clear();
00045     myUHNumbers.clear();
00046     mySelNumbers.clear();
00047     myUSelNumbers.clear();
00048     myCurSelNumbers.clear();
00049     myPrevHNumbers.clear();    
00050 
00051     myType = "GLViewer_MarkerSet";
00052     myToolTipText = toolTip;
00053     
00054     setNumMarkers( number );    
00055 }
00056 
00060 GLViewer_MarkerSet::~GLViewer_MarkerSet()
00061 {
00062     if ( myXCoord )
00063         delete[] myXCoord;
00064     if ( myYCoord )
00065         delete[] myYCoord;
00066 }
00067 
00078 void AddCoordsToHPGL( QString& buffer, QString command, GLViewer_CoordSystem* aViewerCS, 
00079                       GLViewer_CoordSystem* aPaperCS, double x, double y, bool NewLine = true )
00080 {
00081     if( aViewerCS && aPaperCS )
00082         aViewerCS->transform( *aPaperCS, x, y );
00083 
00084     QString temp = command + "%1, %2;";
00085     buffer += temp.arg( x ).arg( y );
00086     if( NewLine )
00087         buffer += ";\n";
00088 }
00089 
00100 void AddCoordsToPS( QString& buffer, QString command, GLViewer_CoordSystem* aViewerCS, 
00101                     GLViewer_CoordSystem* aPaperCS, double x, double y, bool NewLine = true )
00102 {
00103     if( aViewerCS && aPaperCS )
00104         aViewerCS->transform( *aPaperCS, x, y );
00105 
00106     QString temp = "%1 %2 "+command;    
00107     buffer += temp.arg( x ).arg( y );
00108     if( NewLine )
00109         buffer += "\n";
00110 }
00111 
00119 void AddLineAspectToPS( QString& buffer, GLViewer_AspectLine* anAspect, 
00120                         GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPaperCS )
00121 {
00122     if( anAspect )
00123     {
00124         QColor col1, col2, col3;
00125         anAspect->getLineColors( col1, col2, col3 );
00126 
00127         float aWidth = anAspect->getLineWidth();
00128         int aLineType = anAspect->getLineType();
00129 
00130         QString temp = "%1 %2 %3 setrgbcolor\n";
00131         double rr = 1 - double( col1.red() ) / 255.0, //color inverting
00132                gg = 1 - double( col1.green() ) / 255.0,
00133                bb = 1 - double( col1.blue() ) / 255.0;
00134 
00135         buffer += temp.arg( rr ).arg( gg ).arg( bb );
00136 
00137         double x_stretch, y_stretch;
00138         aViewerCS->getStretching( *aPaperCS, x_stretch, y_stretch );
00139         buffer += temp.arg( x_stretch * aWidth )+" setlinewidth\n";
00140 
00141         if( aLineType==0 ) //solid
00142             buffer += "[] 0 setdash\n";
00143         else if( aLineType==1 ) //strip
00144             buffer += "[2] 0 setdash\n";
00145     }
00146 }
00147 
00148 #ifdef WIN32
00149 
00156 HPEN AddLineAspectToEMF( HDC hDC, GLViewer_AspectLine* anAspect, 
00157                          GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPaperCS )
00158 {
00159     if( anAspect )
00160     {
00161         QColor col1, col2, col3;
00162         anAspect->getLineColors( col1, col2, col3 );
00163 
00164         double x_stretch, y_stretch;
00165         aViewerCS->getStretching( *aPaperCS, x_stretch, y_stretch );
00166 
00167         double aWidth = anAspect->getLineWidth()*x_stretch;
00168         int aLineType = anAspect->getLineType();
00169 
00170         return CreatePen( PS_SOLID, aWidth, RGB( 255-col1.red(), 255-col1.green(), 255-col1.blue() ) );
00171     }
00172     else
00173         return NULL;
00174 }
00175 #endif
00176 
00183 bool GLViewer_MarkerSet::translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS )
00184 {   
00185     int noPoints = 20;
00186 
00187     QString aBuffer = "newpath\n";
00188 
00189     AddLineAspectToPS( aBuffer, getAspectLine(), aViewerCS, aPSCS );
00190 
00191     for( int i=0; i<myNumber; i++ )
00192     {       
00193         aBuffer += "\n";
00194 
00195         double x_stretch, y_stretch;
00196         aViewerCS->getStretching( *aPSCS, x_stretch, y_stretch );
00197 
00198         double x0 = myXCoord[i],
00199                y0 = myYCoord[i],
00200                r  = myMarkerSize,
00201                x, y;
00202 
00203         for( int j=0; j<=noPoints; j++ )
00204         {
00205             x = x0 + r*cos( double(j)*2*PI/double(noPoints) );
00206             y = y0 + r*sin( double(j)*2*PI/double(noPoints) );          
00207             if( j==0 )
00208                 AddCoordsToPS( aBuffer, "moveto", aViewerCS, aPSCS, x, y, true );               
00209             else
00210                 AddCoordsToPS( aBuffer, "lineto", aViewerCS, aPSCS, x, y, true );
00211         }
00212     }
00213     aBuffer+="closepath\nstroke\n";
00214 
00215     hFile.write( aBuffer.toAscii() );
00216 
00217     return true;
00218 }
00219 
00226 bool GLViewer_MarkerSet::translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS,
00227                                        GLViewer_CoordSystem* aHPGLCS )
00228 {
00229     int noPoints = 20;
00230     QString aBuffer;
00231     for( int i=0; i<myNumber; i++ )
00232     {
00233         aBuffer = "";
00234 
00235         double x_stretch, y_stretch;
00236         aViewerCS->getStretching( *aHPGLCS, x_stretch, y_stretch );
00237 
00238         double x0 = myXCoord[i],
00239                y0 = myYCoord[i],
00240                r  = myMarkerSize,
00241                x, y;
00242 
00243         AddCoordsToHPGL( aBuffer, "PA", aViewerCS, aHPGLCS, x0+r, y0 );
00244         aBuffer+="PD;\n";
00245         for( int j=1; j<=noPoints; j++ )
00246         {
00247             x = x0 + r*cos( double(j)*2*PI/double(noPoints) );
00248             y = y0 + r*sin( double(j)*2*PI/double(noPoints) );
00249             AddCoordsToHPGL( aBuffer, "PD", aViewerCS, aHPGLCS, x, y );
00250         }
00251         aBuffer+="PU;\n";
00252 
00253         hFile.write( aBuffer.toAscii() );
00254     }
00255 
00256     return true;
00257 }
00258 
00259 #ifdef WIN32
00260 
00266 bool GLViewer_MarkerSet::translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS )
00267 {
00268     int noPoints = 20;
00269     if( !aViewerCS || !aEMFCS )
00270         return false;
00271     
00272     HPEN pen = AddLineAspectToEMF( dc, getAspectLine(), aViewerCS, aEMFCS );
00273     HGDIOBJ old = SelectObject( dc, pen );
00274 
00275     for( int i=0; i<myNumber; i++ )
00276     {
00277         double x0 = myXCoord[i],
00278                y0 = myYCoord[i],
00279                r  = myMarkerSize,
00280                x, y;
00281 
00282         for( int j=0; j<=noPoints; j++ )
00283         {
00284             x = x0 + r*cos( double(j)*2*PI/double(noPoints) );
00285             y = y0 + r*sin( double(j)*2*PI/double(noPoints) );
00286             aViewerCS->transform( *aEMFCS, x, y );
00287             if( j==0 )
00288                 MoveToEx( dc, x, y, NULL );
00289             else
00290                 LineTo( dc, x, y );
00291         }
00292     }
00293 
00294     SelectObject( dc, old );
00295     if( pen )
00296         DeleteObject( pen );
00297     return true;
00298 }
00299 #endif
00300 
00304 void GLViewer_MarkerSet::compute()
00305 {
00306 //  cout << "GLViewer_MarkerSet::compute" << endl;
00307   GLfloat xa = myXCoord[0]; 
00308   GLfloat xb = myXCoord[0]; 
00309   GLfloat ya = myYCoord[0]; 
00310   GLfloat yb = myYCoord[0]; 
00311 
00312   for ( int i = 0; i < myNumber; i++ )  
00313   {
00314     xa = qMin( xa, myXCoord[i] );
00315     xb = qMax( xb, myXCoord[i] );
00316     ya = qMin( ya, myYCoord[i] );
00317     yb = qMax( yb, myYCoord[i] );
00318   }
00319   
00320   myXGap = ( xb - xa ) / 10;
00321   myYGap = ( yb - ya ) / 10;
00322 
00323   myRect->setLeft( xa - myXGap );
00324   myRect->setTop( yb + myYGap ); 
00325   myRect->setRight( xb + myXGap );
00326   myRect->setBottom( ya - myYGap );
00327 }
00328 
00332 GLViewer_Drawer* GLViewer_MarkerSet::createDrawer()
00333 {
00334 //  cout << "GLViewer_MarkerSet::createDrawer" << endl;
00335   return myDrawer = new GLViewer_MarkerDrawer();
00336 }
00337 
00346 GLboolean GLViewer_MarkerSet::highlight( GLfloat x, GLfloat y, GLfloat tol, GLboolean isCircle )
00347 {
00348     if( !myIsVisible )
00349         return false;
00350 //  cout << "GLViewer_MarkerSet::highlight " << x <<" " << y << " " << tol << endl;
00351   int count = 0;
00352   GLfloat xdist, ydist, radius;
00353   QList<int>::Iterator it;
00354   QList<int> curHNumbers;
00355   bool isFound;
00356   GLboolean update;
00357   int cnt = 0;
00358 
00359   radius = tol - myMarkerSize / 2.;
00360   
00361   myUHNumbers += myHNumbers;
00362   myHNumbers.clear();
00363 
00364   for ( int i = 0; i < myNumber; i++ ) 
00365   {
00366     xdist = ( myXCoord[i] - x ) * myXScale;
00367     ydist = ( myYCoord[i] - y ) * myYScale;
00368 
00369 //    if ( isCircle && ( xdist * xdist + ydist * ydist <= radius * radius ) ||
00370     if ( ( isCircle && ( xdist * xdist + ydist * ydist <= myMarkerSize * myMarkerSize ) ) ||
00371          ( !isCircle && ( fabs( xdist ) <= radius && fabs( ydist ) <= radius ) ) )
00372     {
00373       isFound = FALSE;
00374       count++;
00375       for ( it = myCurSelNumbers.begin(); it != myCurSelNumbers.end(); ++it )
00376         if( i == *it )
00377         {
00378           isFound = TRUE;
00379           curHNumbers.append( i );
00380         }
00381       
00382       if( !isFound )
00383           myHNumbers.append( i );
00384       else
00385         cnt++;
00386     }
00387   }
00388   myCurSelNumbers = curHNumbers;
00389 
00390   myIsHigh = ( GLboolean )count;
00391   update = ( GLboolean )( myHNumbers != myPrevHNumbers );
00392 
00393   myPrevHNumbers = myHNumbers;
00394 
00395   //cout << "GLViewer_MarkerSet::highlight complete with " << (int)myIsHigh << endl;
00396   return update;
00397 }
00398 
00402 GLboolean GLViewer_MarkerSet::unhighlight()
00403 {
00404   if( !myHNumbers.isEmpty() )
00405   {
00406     myUHNumbers += myHNumbers;
00407     myPrevHNumbers.clear();
00408     myHNumbers.clear();
00409     //??? myCurSelNumbers.clear();
00410     return GL_TRUE;
00411   }
00412   
00413   return GL_FALSE;
00414 }
00415 
00425 GLboolean GLViewer_MarkerSet::select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect, GLboolean isFull,
00426                                       GLboolean isCircle, GLboolean isShift )
00427 {
00428     if( !myIsVisible )
00429         return false;
00430 //  cout << "GLViewer_MarkerSet::select " << x << " " << y << endl;
00431   int count = 0;
00432   GLfloat xdist, ydist, radius;
00433   QList<int>::Iterator it;
00434   QList<int>::Iterator it1;
00435   QList<int>::Iterator remIt;
00436   QList<int>::Iterator curIt;
00437 
00438   radius = tol - myMarkerSize / 2.;
00439 
00440   if( radius < myMarkerSize / 2.)
00441     radius = myMarkerSize / 2.;
00442 
00443   count = isShift ? mySelNumbers.count() : 0;
00444 
00445   myUSelNumbers = mySelNumbers;
00446 
00447   if ( !isShift )
00448   {
00449     mySelNumbers.clear();
00450     myCurSelNumbers.clear();
00451   }
00452 
00453   for ( int i = 0; i < myNumber; i++ ) 
00454   {
00455     xdist = ( myXCoord[i] - x ) * myXScale;
00456     ydist = ( myYCoord[i] - y ) * myYScale;
00457 
00458     //if ( isCircle && ( xdist * xdist + ydist * ydist <= radius * radius ) ||
00459     if ( ( isCircle && ( xdist * xdist + ydist * ydist <= myMarkerSize * myMarkerSize ) ) ||
00460          ( !isCircle && ( fabs( xdist ) <= radius && fabs( ydist ) <= radius ) ) )
00461     {
00462       count++;
00463       if ( isShift )
00464       {
00465         bool isFound = FALSE;
00466           for( it = mySelNumbers.begin(); it != mySelNumbers.end(); ++it )
00467             if ( *it == i )
00468             {
00469               myUSelNumbers.append( *it );
00470             remIt = it;
00471               isFound = TRUE;
00472               break;
00473             }
00474 
00475           if ( !isFound )
00476         {
00477           mySelNumbers.append( i );
00478             myCurSelNumbers.append( i );
00479             for ( it1 = myHNumbers.begin(); it1 != myHNumbers.end(); ++it1 )
00480               if( i == *it1 )
00481               {
00482                 myHNumbers.erase( it1 );
00483                 break;
00484               }
00485       for ( it1 = myUHNumbers.begin(); it1 != myUHNumbers.end(); ++it1 )
00486         if( i == *it1 )
00487         {
00488           myUHNumbers.erase( it1 );
00489           break;
00490         }
00491         }
00492     else
00493         {
00494       mySelNumbers.erase( remIt );
00495       for ( curIt = myCurSelNumbers.begin(); curIt != myCurSelNumbers.end(); ++curIt )
00496         if( *curIt == *remIt)
00497         {
00498           myCurSelNumbers.erase( curIt );
00499           break;
00500         }
00501       for ( it1 = myHNumbers.begin(); it1 != myHNumbers.end(); ++it1 )
00502         if( i == *it1 )
00503         {
00504           myHNumbers.erase( it1 );
00505           break;
00506         }
00507       for ( it1 = myUHNumbers.begin(); it1 != myUHNumbers.end(); ++it1 )
00508         if( i == *it1 )
00509         {
00510           myUHNumbers.erase( it1 );
00511           break;
00512         }
00513         }
00514       }
00515       else
00516       {
00517     mySelNumbers.append( i );
00518     myCurSelNumbers.append( i );
00519     for ( it1 = myHNumbers.begin(); it1 != myHNumbers.end(); ++it1 )
00520       if( i == *it1 )
00521       {
00522         myHNumbers.erase( it1 );
00523         break;
00524       }
00525     for ( it1 = myUHNumbers.begin(); it1 != myUHNumbers.end(); ++it1 )
00526       if( i == *it1 )
00527           {
00528         myUHNumbers.erase( it1 );
00529         break;
00530       }        
00531       }     
00532     }
00533   }
00534 
00535   for( it = mySelNumbers.begin(); it != mySelNumbers.end(); ++it )
00536     for( it1 = myUSelNumbers.begin(); it1 != myUSelNumbers.end(); ++it1 )
00537       if( *it == *it1 )
00538       {
00539         it1 = myUSelNumbers.erase( it1 );
00540         it1--;
00541       }
00542   
00543   myIsSel = (GLboolean)count;
00544 
00545 //  cout << "GLViewer_MarkerSet::select complete with " << (int)myIsSel << endl;
00546   return myIsSel;
00547 }
00548 
00552 GLboolean GLViewer_MarkerSet::unselect()
00553 {
00554   if( !mySelNumbers.isEmpty() )
00555   {
00556     myUSelNumbers = mySelNumbers;
00557     mySelNumbers.clear();
00558     myCurSelNumbers.clear();
00559     return GL_TRUE;
00560   }
00561 
00562   return GL_FALSE;
00563 }
00564 
00569 GLViewer_Rect* GLViewer_MarkerSet::getUpdateRect()
00570 {
00571   GLViewer_Rect* rect = new GLViewer_Rect();
00572   
00573   rect->setLeft( myRect->left() + myXGap - myMarkerSize / myXScale );
00574   rect->setTop( myRect->top() + myYGap + myMarkerSize / myYScale ); 
00575   rect->setRight( myRect->right() - myXGap + myMarkerSize / myXScale );
00576   rect->setBottom( myRect->bottom() - myYGap - myMarkerSize / myYScale );
00577   //cout << " Additional tolerance " << myMarkerSize / myYScale << endl;
00578   //rect->setLeft( myRect->left() - myMarkerSize / myXScale );
00579   //rect->setTop( myRect->top() - myMarkerSize / myYScale ); 
00580   //rect->setRight( myRect->right() + myMarkerSize / myXScale );
00581   //rect->setBottom( myRect->bottom() + myMarkerSize / myYScale );
00582   
00583   return rect;
00584 }
00585 
00591 void GLViewer_MarkerSet::setXCoord( GLfloat* xCoord, int size )
00592 {
00593   myXCoord = new GLfloat[ size ];
00594   for( int i = 0; i < size; i++ )
00595      myXCoord[i] = xCoord[i];
00596 }
00597 
00603 void GLViewer_MarkerSet::setYCoord( GLfloat* yCoord, int size )
00604 {
00605   myYCoord = new GLfloat[ size ];
00606   for( int i = 0; i < size; i++ )
00607      myYCoord[i] = yCoord[i];
00608 }
00609 
00614 void GLViewer_MarkerSet::setNumMarkers( GLint number )
00615 {
00616   if ( myNumber == number )
00617     return;
00618     
00619   if ( myXCoord && myYCoord )
00620   {
00621     delete[] myXCoord;
00622     delete[] myYCoord;
00623   }
00624 
00625   myNumber = number;
00626   myXCoord = new GLfloat[ myNumber ];
00627   myYCoord = new GLfloat[ myNumber ];
00628 }
00629 
00630 
00634 void GLViewer_MarkerSet::exportNumbers( QList<int>& highlight,
00635                      QList<int>& unhighlight,
00636                      QList<int>& select,
00637                      QList<int>& unselect )
00638 {
00639     highlight = myHNumbers;
00640     unhighlight = myUHNumbers;
00641     select = mySelNumbers;
00642     unselect = myUSelNumbers;
00643 
00644     myUHNumbers = myHNumbers;
00645 }
00646 
00651 bool GLViewer_MarkerSet::addOrRemoveSelected( int index )
00652 {
00653   if( index < 0 || index > myNumber )
00654     return FALSE;
00655 
00656   int n = mySelNumbers.indexOf( index );
00657   if( n == -1 )
00658     mySelNumbers.append( index );
00659   else
00660   {
00661     mySelNumbers.removeAt(n);
00662     myUSelNumbers.append( index );
00663   }
00664   return TRUE;
00665 }
00666 
00671 void GLViewer_MarkerSet::addSelected( const TColStd_SequenceOfInteger& seq )
00672 {
00673   for ( int i = 1; i <= seq.Length(); i++ )
00674     if( mySelNumbers.indexOf( seq.Value( i ) ) == -1 )
00675       mySelNumbers.append( seq.Value( i ) - 1 );
00676 }
00677 
00682 void GLViewer_MarkerSet::setSelected( const TColStd_SequenceOfInteger& seq )
00683 {
00684 //   for( QList<int>::Iterator it = mySelNumbers.begin(); it != mySelNumbers.end(); ++it )
00685 //     if( myUSelNumbers.findIndex( *it ) == -1 )
00686 //       myUSelNumbers.append( *it );
00687 
00688   myUSelNumbers = mySelNumbers;
00689   mySelNumbers.clear();
00690     
00691   for ( int i = 1; i <= seq.Length(); i++ )
00692     mySelNumbers.append( seq.Value( i ) - 1 );
00693 }
00694 
00700 void GLViewer_MarkerSet::moveObject( float theX, float theY, bool fromGroup )
00701 {
00702     if( !fromGroup && myGroup)
00703     {
00704       myGroup->dragingObjects( theX, theY );
00705       return;
00706     }
00707     for( int i = 0; i < myNumber;  i++ )
00708     {
00709         myXCoord[i] = myXCoord[i] + theX;
00710         myYCoord[i] = myYCoord[i] + theY;
00711     }
00712     compute();    
00713 }
00714 
00719 QByteArray GLViewer_MarkerSet::getByteCopy()
00720 {
00721     int i = 0;
00722     int anISize = sizeof( GLint );
00723     int aFSize = sizeof( GLfloat );
00724     
00725     QByteArray aObject = GLViewer_Object::getByteCopy();
00726 
00727     QByteArray aResult;
00728     aResult.resize( anISize + 2*aFSize*myNumber + aFSize + aObject.size());
00729 
00730     char* aPointer = (char*)&myNumber;
00731     for( i = 0; i < anISize; i++, aPointer++ )
00732         aResult[i] = *aPointer;
00733 
00734     aPointer = (char*)myXCoord;
00735     for( ; i < anISize + aFSize*myNumber; i++, aPointer++ )
00736         aResult[i] = *aPointer;
00737     aPointer = (char*)myYCoord;
00738     for( ; i < anISize + 2*aFSize*myNumber; i++, aPointer++ )
00739         aResult[i] = *aPointer;
00740     
00741     aPointer = (char*)&myMarkerSize;
00742     for( ; i < anISize + 2*aFSize*myNumber + aFSize; i++, aPointer++ )
00743         aResult[i] = *aPointer;
00744         
00745     
00746     for ( ; i < (int)aResult.size(); i++ )
00747         aResult[i] = aObject[i - anISize - 2*aFSize*myNumber - aFSize];
00748 
00749     return aResult;
00750 }
00751 
00756 bool GLViewer_MarkerSet::initializeFromByteCopy( QByteArray theArray )
00757 {
00758     int i = 0;
00759     int anISize = sizeof( GLint );
00760     int aFSize = sizeof( GLfloat );
00761 
00762     char* aPointer = (char*)&myNumber;
00763     for( i = 0; i < anISize; i++, aPointer++ )
00764         *aPointer = theArray[i];
00765 
00766     int aSize = theArray.size();
00767     if( aSize < anISize + 2*aFSize*myNumber + aFSize)
00768         return false;
00769 
00770     myXCoord = new GLfloat[myNumber];
00771     myYCoord = new GLfloat[myNumber];
00772     aPointer = (char*)myXCoord;
00773     for( ; i < anISize + aFSize*myNumber; i++, aPointer++ )
00774         *aPointer = theArray[i];
00775     aPointer = (char*)myYCoord;
00776     for( ; i < anISize + 2*aFSize*myNumber; i++, aPointer++ )
00777         *aPointer = theArray[i];
00778 
00779     aPointer = (char*)&myMarkerSize;
00780     for( ; i < anISize + 2*aFSize*myNumber + aFSize; i++, aPointer++ )
00781          *aPointer = theArray[i];
00782          
00783     int aCurIndex = anISize + 2*aFSize*myNumber + aFSize;
00784     QByteArray aObject;
00785     aObject.resize( aSize - aCurIndex );
00786     for( ; i < aSize; i++ )
00787         aObject[i - aCurIndex] = theArray[i];
00788         
00789 
00790     if( !GLViewer_Object::initializeFromByteCopy( aObject ) || myType != "GLViewer_MarkerSet" )
00791         return false;
00792 
00793     myHNumbers.clear();
00794     myUHNumbers.clear();
00795     mySelNumbers.clear();
00796     myUSelNumbers.clear();
00797     myCurSelNumbers.clear();
00798     myPrevHNumbers.clear();
00799 
00800     return true;        
00801 }
00802 
00808 #define SECTIONS 100
00809 #define DISTANTION 5
00810 
00817 GLViewer_Polyline::GLViewer_Polyline( int number, float size, const QString& toolTip ):
00818   GLViewer_Object(),
00819   myNumber( 0 ),
00820   myXCoord( 0 ),
00821   myYCoord( 0 )       
00822 {
00823   myHighFlag = GL_TRUE;
00824 
00825   myHNumbers.clear();
00826   myUHNumbers.clear();
00827   mySelNumbers.clear();
00828   myUSelNumbers.clear();
00829   myCurSelNumbers.clear();
00830   myPrevHNumbers.clear();
00831 
00832   setNumber( number );
00833 
00834   myType = "GLViewer_Polyline";
00835   myToolTipText = toolTip;
00836 }
00837 
00841 GLViewer_Polyline::~GLViewer_Polyline()
00842 {
00843   if ( myXCoord )
00844     delete[] myXCoord;
00845   if ( myYCoord )
00846     delete[] myYCoord;
00847 }
00848 
00855 bool GLViewer_Polyline::translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS )
00856 {
00857     QString aBuffer = "newpath\n";
00858 
00859     AddLineAspectToPS( aBuffer, getAspectLine(), aViewerCS, aPSCS );
00860 
00861     for( int i=0; i<myNumber; i++ )
00862         if( i==0 )
00863             AddCoordsToPS( aBuffer, "moveto", aViewerCS, aPSCS, myXCoord[i], myYCoord[i] );
00864         else
00865             AddCoordsToPS( aBuffer, "lineto", aViewerCS, aPSCS, myXCoord[i], myYCoord[i] );
00866 
00867     if( myIsClosed )
00868         AddCoordsToPS( aBuffer, "lineto", aViewerCS, aPSCS, myXCoord[0], myYCoord[0] );
00869 
00870     aBuffer+="closepath\nstroke\n";
00871     
00872     hFile.write( aBuffer.toAscii() );
00873 
00874     return true;
00875 }
00876 
00883 bool GLViewer_Polyline::translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS )
00884 {
00885     QString aBuffer = "";
00886     for( int i=0; i<myNumber; i++ )
00887     {
00888         AddCoordsToHPGL( aBuffer, "PA", aViewerCS, aHPGLCS, myXCoord[i], myYCoord[i] );
00889         if( i==0 )
00890             aBuffer+="PD;\n";
00891     }
00892 
00893     if( myIsClosed )
00894         AddCoordsToHPGL( aBuffer, "PA", aViewerCS, aHPGLCS, myXCoord[0], myYCoord[0] );
00895 
00896     aBuffer+="PU;\n";
00897     
00898     hFile.write( aBuffer.toAscii() );
00899 
00900     return true;
00901 }
00902 
00903 #ifdef WIN32
00904 
00910 bool GLViewer_Polyline::translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS )
00911 {
00912     if( !aViewerCS || !aEMFCS )
00913         return false;
00914     
00915     HPEN pen = AddLineAspectToEMF( dc, getAspectLine(), aViewerCS, aEMFCS );
00916     HGDIOBJ old = SelectObject( dc, pen );
00917 
00918     double x, y;
00919     for( int i=0; i<myNumber; i++ )
00920     {
00921         x = myXCoord[i];
00922         y = myYCoord[i];
00923         aViewerCS->transform( *aEMFCS, x, y );
00924         if( i==0 )
00925             MoveToEx( dc, x, y, NULL );
00926         else
00927             LineTo( dc, x, y );
00928     }
00929 
00930     if( myIsClosed )
00931     {
00932         x = myXCoord[0];
00933         y = myYCoord[0];
00934         aViewerCS->transform( *aEMFCS, x, y );
00935         LineTo( dc, x, y );
00936     }
00937 
00938     SelectObject( dc, old );
00939     if( pen )
00940         DeleteObject( pen );
00941 
00942     return true;
00943 }
00944 #endif
00945 
00949 void GLViewer_Polyline::compute()
00950 {
00951 //  cout << "GLViewer_MarkerSet::compute" << endl;
00952   GLfloat xa = myXCoord[0]; 
00953   GLfloat xb = myXCoord[0]; 
00954   GLfloat ya = myYCoord[0]; 
00955   GLfloat yb = myYCoord[0]; 
00956 
00957   for ( int i = 0; i < myNumber; i++ )  
00958   {
00959     xa = qMin( xa, myXCoord[i] );
00960     xb = qMax( xb, myXCoord[i] );
00961     ya = qMin( ya, myYCoord[i] );
00962     yb = qMax( yb, myYCoord[i] );
00963   }
00964 
00965   GLfloat xGap = ( xb - xa ) / 10;
00966   GLfloat yGap = ( yb - ya ) / 10;
00967 
00968   myRect->setLeft( xa - xGap );
00969   myRect->setTop( yb + yGap ); 
00970   myRect->setRight( xb + xGap );
00971   myRect->setBottom( ya - yGap );
00972 }
00973 
00978 GLViewer_Rect* GLViewer_Polyline::getUpdateRect()
00979 {
00980     GLViewer_Rect* rect = new GLViewer_Rect();
00981 
00982     rect->setLeft( myRect->left() - myXGap );
00983     rect->setTop( myRect->top() + myYGap ); 
00984     rect->setRight( myRect->right() + myXGap );
00985     rect->setBottom( myRect->bottom() - myYGap );
00986 
00987     return rect;
00988 }
00989 
00993 GLViewer_Drawer* GLViewer_Polyline::createDrawer()
00994 {
00995 //  cout << "GLViewer_MarkerSet::createDrawer" << endl;
00996     return myDrawer = new GLViewer_PolylineDrawer();
00997 }
00998 
01007 GLboolean GLViewer_Polyline::highlight( GLfloat x, GLfloat y, GLfloat tol, GLboolean isCircle )
01008 {
01009     if( !myIsVisible )
01010         return false;
01011     GLfloat xa, xb, ya, yb, l;
01012     GLfloat rsin, rcos, r, ra, rb;
01013     GLboolean update;
01014     GLboolean highlighted = myIsHigh;
01015 
01016     myIsHigh = GL_FALSE;
01017 
01018     int c = 0;
01019     if( myIsClosed )
01020         c = 1;
01021 
01022     for( int i = 0; i < myNumber-1+c; i++ ) 
01023     {
01024         xa = myXCoord[i];
01025         ya = myYCoord[i];
01026         if( i != myNumber-1 )
01027         {
01028               xb = myXCoord[i+1];
01029               yb = myYCoord[i+1];
01030         }
01031         else
01032         {    
01033               xb = myXCoord[0];      
01034               yb = myYCoord[0];
01035         }
01036 
01037         l = sqrt( (xb-xa)*(xb-xa) + (yb-ya)*(yb-ya) );
01038         rsin = (yb-ya) / l;
01039         rcos = (xb-xa) / l;
01040         r = ( (x-xa)*(y-yb) - (x-xb)*(y-ya) ) / ( rsin*(ya-yb) + rcos*(xa-xb) );
01041         ra = sqrt( (x-xa)*(x-xa) + (y-ya)*(y-ya) );
01042         rb = sqrt( (x-xb)*(x-xb) + (y-yb)*(y-yb) );
01043         if( fabs( r ) * myXScale <= DISTANTION && ra <= l + DISTANTION && rb <= l + DISTANTION )
01044         {
01045             myIsHigh = GL_TRUE;
01046             break;
01047         }
01048     }
01049 
01050     if( !myHighFlag && myIsHigh )
01051         myIsHigh = GL_FALSE;
01052     else
01053         myHighFlag = GL_TRUE;
01054 
01055     update = ( GLboolean )( myIsHigh != highlighted );
01056 
01057 //  cout << "GLViewer_Polyline::highlight complete with " << (int)myIsHigh << endl;
01058     return update;
01059 }
01060 
01064 GLboolean GLViewer_Polyline::unhighlight()
01065 {
01066 //   if( !myHNumbers.isEmpty() )
01067 //   {
01068 //     myUHNumbers = myHNumbers;
01069 //     myHNumbers.clear();
01070 //     return GL_TRUE;
01071 //   }
01072 
01073   if( myIsHigh )
01074   {
01075     myIsHigh = GL_FALSE;
01076     return GL_TRUE;
01077   }
01078 
01079   return GL_FALSE;
01080 }
01081 
01091 GLboolean GLViewer_Polyline::select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect, GLboolean isFull,
01092                                      GLboolean isCircle, GLboolean isShift )
01093 {
01094     if( !myIsVisible )
01095         return false;
01096     GLfloat xa, xb, ya, yb, l;
01097     GLfloat rsin, rcos, r, ra, rb;
01098     // GLboolean update;
01099     GLboolean selected = myIsSel;
01100 
01101     myIsSel = GL_FALSE;
01102 
01103     int c = 0;
01104     if( myIsClosed )
01105         c = 1;
01106 
01107     for( int i = 0; i < myNumber-1+c; i++ ) 
01108     {
01109         xa = myXCoord[i];
01110         ya = myYCoord[i];
01111         if( i != myNumber-1 )
01112         {
01113             xb = myXCoord[i+1];
01114             yb = myYCoord[i+1];
01115         }
01116         else
01117         {
01118             xb = myXCoord[0];
01119             yb = myYCoord[0];
01120         }
01121 
01122         l = sqrt( (xb-xa)*(xb-xa) + (yb-ya)*(yb-ya) );
01123         rsin = (yb-ya) / l;
01124         rcos = (xb-xa) / l;
01125         r = ( (x-xa)*(y-yb) - (x-xb)*(y-ya) ) / ( rsin*(ya-yb) + rcos*(xa-xb) );
01126         ra = sqrt( (x-xa)*(x-xa) + (y-ya)*(y-ya) );
01127         rb = sqrt( (x-xb)*(x-xb) + (y-yb)*(y-yb) );
01128         if( fabs( r ) * myXScale <= DISTANTION && ra <= l + DISTANTION && rb <= l + DISTANTION )
01129         {
01130             myIsSel = GL_TRUE;
01131             break;
01132         }
01133     }
01134 
01135     if ( myIsSel )
01136     {
01137         myHighFlag = GL_FALSE;
01138         myIsHigh = GL_FALSE;
01139     }
01140     else
01141         myHighFlag = GL_TRUE;
01142 
01143     // update = ( GLboolean )( myIsSel != selected );
01144 
01145     //  cout << "GLViewer_Polyline::select complete with " << (int)myIsSel << endl;
01146 
01147     //  return update;  !!!!!!!!!!!!!!!!!!!!!!!!!!! no here
01148     return myIsSel;
01149 }
01150 
01154 GLboolean GLViewer_Polyline::unselect()
01155 {
01156 //   if( !mySelNumbers.isEmpty() )
01157 //   {
01158 //     myUSelNumbers = mySelNumbers;
01159 //     mySelNumbers.clear();
01160 //     myCurSelNumbers.clear();
01161 //     return GL_TRUE;
01162 //   }
01163 
01164   if( myIsSel )
01165   {
01166     myIsSel = GL_FALSE;
01167     return GL_TRUE;
01168   }
01169 
01170   return GL_FALSE;
01171 }
01172 
01178 void GLViewer_Polyline::setXCoord( GLfloat* xCoord, int size )
01179 {
01180   myXCoord = new GLfloat[ size ];
01181   for( int i = 0; i < size; i++ )
01182      myXCoord[i] = xCoord[i];
01183 }
01184 
01190 void GLViewer_Polyline::setYCoord( GLfloat* yCoord, int size )
01191 {
01192   myYCoord = new GLfloat[ size ];
01193   for( int i = 0; i < size; i++ )
01194      myYCoord[i] = yCoord[i];
01195 }
01196 
01201 void GLViewer_Polyline::setNumber( GLint number )
01202 {
01203   if ( myNumber == number )
01204     return;
01205     
01206   if ( myXCoord && myYCoord )
01207   {
01208     delete[] myXCoord;
01209     delete[] myYCoord;
01210   }
01211 
01212   myNumber = number;
01213   myXCoord = new GLfloat[ myNumber ];
01214   myYCoord = new GLfloat[ myNumber ];
01215 }
01216 
01220 void GLViewer_Polyline::exportNumbers( QList<int>& highlight,
01221                      QList<int>& unhighlight,
01222                      QList<int>& select,
01223                      QList<int>& unselect )
01224 {
01225   highlight = myHNumbers;
01226   unhighlight = myUHNumbers;
01227   select = mySelNumbers;
01228   unselect = myUSelNumbers;
01229 }
01230 
01237 void GLViewer_Polyline::moveObject( float theX, float theY, bool fromGroup )
01238 {
01239   if( !fromGroup && myGroup)
01240   {
01241     myGroup->dragingObjects( theX, theY );
01242     return;
01243   }
01244   for( int i = 0; i < myNumber;  i++ )
01245   {
01246       myXCoord[i] = myXCoord[i] + theX;
01247       myYCoord[i] = myYCoord[i] + theY;
01248   }
01249   compute();    
01250 }
01251 
01256 QByteArray GLViewer_Polyline::getByteCopy()
01257 {
01258     int i = 0;
01259     int anISize = sizeof( GLint );
01260     int aFSize = sizeof( GLfloat );
01261     int aBSize = sizeof( GLboolean );
01262 
01263     QByteArray aObject = GLViewer_Object::getByteCopy();
01264 
01265     QByteArray aResult;
01266     aResult.resize( aFSize*myNumber*2 + anISize + 2*aBSize + aObject.size());
01267 
01268     char* aPointer = (char*)&myNumber;
01269     for( i = 0; i < anISize; i++, aPointer++ )
01270         aResult[i] = *aPointer;
01271 
01272     aPointer = (char*)myXCoord;
01273     for( ; i < anISize + aFSize*myNumber; i++, aPointer++ )
01274         aResult[i] = *aPointer;
01275     aPointer = (char*)myYCoord;
01276     for( ; i < anISize + 2*aFSize*myNumber; i++, aPointer++ )
01277         aResult[i] = *aPointer;
01278     
01279     aPointer = (char*)&myIsClosed;
01280     for( ; i < anISize + 2*aFSize*myNumber + aBSize; i++, aPointer++ )
01281         aResult[i] = *aPointer;
01282     aPointer = (char*)&myHighSelAll;
01283     for( ; i < anISize + 2*aFSize*myNumber + 2*aBSize; i++, aPointer++ )
01284         aResult[i] = *aPointer;
01285 
01286     for ( ; i < (int)aResult.size(); i++ )
01287         aResult[i] = aObject[i - anISize - 2*aFSize*myNumber - 2*aBSize];
01288 
01289     return aResult;
01290 }
01291 
01292 
01297 bool GLViewer_Polyline::initializeFromByteCopy( QByteArray theArray )
01298 {
01299     int i = 0;
01300     int anISize = sizeof( GLint );
01301     int aFSize = sizeof( GLfloat );
01302     int aBSize = sizeof( GLboolean );
01303 
01304     char* aPointer = (char*)&myNumber;
01305     for( i = 0; i < anISize; i++, aPointer++ )
01306         *aPointer = theArray[i];
01307 
01308     int aSize = theArray.size();
01309     if( aSize < aFSize*myNumber*2 + anISize + 2*aBSize )
01310         return false;
01311 
01312     myXCoord = new GLfloat[myNumber];
01313     myYCoord = new GLfloat[myNumber];
01314     aPointer = (char*)myXCoord;
01315     for( ; i < anISize + aFSize*myNumber; i++, aPointer++ )
01316         *aPointer = theArray[i];
01317     aPointer = (char*)myYCoord;
01318     for( ; i < anISize + 2*aFSize*myNumber; i++, aPointer++ )
01319         *aPointer = theArray[i];
01320 
01321     aPointer = (char*)&myIsClosed;
01322     for( ; i < anISize + 2*aFSize*myNumber + aBSize; i++, aPointer++ )
01323          *aPointer = theArray[i];
01324     aPointer = (char*)&myHighSelAll;
01325     for( ; i < anISize + 2*aFSize*myNumber + 2*aBSize; i++, aPointer++ )
01326          *aPointer = theArray[i];
01327 
01328     int aCurIndex = anISize + 2*aFSize*myNumber + 2*aBSize;
01329     QByteArray aObject;
01330     aObject.resize( aSize - aCurIndex );
01331     for( ; i < aSize; i++ )
01332         aObject[i - aCurIndex] = theArray[i];
01333 
01334     if( !GLViewer_Object::initializeFromByteCopy( aObject ) || myType != "GLViewer_Polyline" )
01335         return false;
01336 
01337     myHNumbers.clear();
01338     myUHNumbers.clear();
01339     mySelNumbers.clear();
01340     myUSelNumbers.clear();
01341     myCurSelNumbers.clear();
01342     myPrevHNumbers.clear();
01343 
01344     return true;        
01345 }
01346 
01347 
01348 
01357 GLViewer_TextObject::GLViewer_TextObject( const QString& theStr, float xPos, float yPos, 
01358                                     const QColor& color, const QString& toolTip )
01359                                     : GLViewer_Object()
01360 {
01361     myGLText = new GLViewer_Text( theStr, xPos, yPos, color );
01362     myWidth = 0;
01363     myHeight = 0;
01364 
01365     myHighFlag = GL_TRUE;
01366 
01367     myToolTipText = toolTip;
01368 }
01369 
01373 GLViewer_TextObject::~GLViewer_TextObject()
01374 {
01375   if ( myGLText )
01376     delete myGLText;
01377 }
01378 
01385 bool GLViewer_TextObject::translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS )
01386 {
01387     QString aText = myGLText->getText();    
01388     float xPos, yPos;
01389     myGLText->getPosition( xPos, yPos );
01390 
01391     QString aBuffer = "/Times-Roman findfont\n";
01392     aBuffer += "12 scalefont setfont\n";
01393 
01394     AddCoordsToPS( aBuffer, "moveto", aViewerCS, aPSCS, double(xPos), double(yPos) );
01395     aBuffer += "(" + aText + ") show\n";
01396 
01397     hFile.write( aBuffer.toAscii() );
01398 
01399     return true;
01400 }
01401 
01408 bool GLViewer_TextObject::translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS )
01409 {
01410     QString aText = myGLText->getText();    
01411     float xPos, yPos;
01412     myGLText->getPosition( xPos, yPos );
01413 
01414     QString aBuffer = "";
01415     AddCoordsToHPGL( aBuffer, "PA", aViewerCS, aHPGLCS, double(xPos), double(yPos) );
01416     
01417     aBuffer = "LB" + aText + "#;";
01418     
01419     hFile.write( aBuffer.toAscii() );
01420 
01421     return true;
01422 }
01423 
01424 #ifdef WIN32
01425 
01431 bool GLViewer_TextObject::translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS )
01432 {
01433     QString aText = myGLText->getText();    
01434     float xPos, yPos;
01435     myGLText->getPosition( xPos, yPos );
01436 
01437     double x = double( xPos ), 
01438            y = double( yPos );
01439 
01440     aViewerCS->transform( *aEMFCS, x, y );
01441     const char* str = aText.toAscii();
01442 
01443     int nHeight = 35*14;       // height of font
01444     int nWidth = 35*12;        // average character width
01445     int nEscapement = 0;       // angle of escapement
01446     int nOrientation = 0;      // base-line orientation angle
01447     int fnWeight = FW_NORMAL;  // font weight
01448     DWORD fdwItalic = FALSE;    // italic attribute option
01449     DWORD fdwUnderline = FALSE; // underline attribute option
01450     DWORD fdwStrikeOut = FALSE; // strikeout attribute option
01451     DWORD fdwCharSet = ANSI_CHARSET; // character set identifier
01452     DWORD fdwOutputPrecision = OUT_DEFAULT_PRECIS;  // output precision
01453     DWORD fdwClipPrecision = CLIP_DEFAULT_PRECIS;    // clipping precision
01454     DWORD fdwQuality = PROOF_QUALITY;          // output quality
01455     DWORD fdwPitchAndFamily = FIXED_PITCH | FF_DONTCARE;   // pitch and family
01456     LPCTSTR lpszFace = NULL;         // typeface name
01457 
01458 
01459     HFONT aFont = CreateFont( nHeight, nWidth, nEscapement, nOrientation, fnWeight, fdwItalic,
01460                               fdwUnderline, fdwStrikeOut, fdwCharSet, fdwOutputPrecision, 
01461                               fdwClipPrecision, fdwQuality, fdwPitchAndFamily, lpszFace );
01462     LOGBRUSH aBrushData;
01463     aBrushData.lbStyle = BS_HOLLOW;
01464 
01465     HBRUSH aBrush = CreateBrushIndirect( &aBrushData );
01466 
01467     HGDIOBJ old1 = SelectObject( dc, aFont );
01468     HGDIOBJ old2 = SelectObject( dc, aBrush );
01469 
01470     TextOut( dc, x, y, str, aText.length() );
01471 
01472     SelectObject ( dc, old1 );
01473     SelectObject ( dc, old2 );
01474 
01475     DeleteObject( aFont );
01476 
01477     return true;
01478 }
01479 #endif
01480 
01484 GLViewer_Drawer* GLViewer_TextObject::createDrawer()
01485 {
01486     myDrawer = new GLViewer_TextDrawer();
01487     compute();
01488     return myDrawer;
01489 }
01490 
01494 void GLViewer_TextObject::compute()
01495 {
01496     float xPos, yPos;
01497     QString aStr = myGLText->getText();
01498     myGLText->getPosition( xPos, yPos );
01499 
01500     myWidth = myGLText->getWidth();
01501     myHeight = myGLText->getHeight();
01502     myRect->setLeft( xPos );
01503     myRect->setTop( yPos + myHeight  ); 
01504     myRect->setRight( xPos + myWidth );
01505     myRect->setBottom( yPos );
01506 }
01507 
01512 void GLViewer_TextObject::setDrawer( GLViewer_Drawer* theDrawer )
01513 {
01514     myDrawer = theDrawer;
01515     //compute();
01516 }
01517 
01522 GLViewer_Rect* GLViewer_TextObject::getUpdateRect()
01523 {    
01524     GLViewer_Rect* rect = new GLViewer_Rect();
01525 
01526     float xPos, yPos;
01527     QString aStr = myGLText->getText();
01528     myGLText->getPosition( xPos, yPos );
01529 
01530     rect->setLeft( myRect->left() + myXGap - myWidth / myXScale );
01531     rect->setTop( myRect->top() + myYGap + myHeight / myYScale );
01532     rect->setRight( myRect->right() - myXGap + myWidth / myXScale );
01533     rect->setBottom( myRect->bottom() - myYGap - myHeight / myYScale );
01534 
01535     return rect;
01536 }
01537 
01546 GLboolean GLViewer_TextObject::highlight( GLfloat theX, GLfloat theY, GLfloat theTol, GLboolean isCircle )
01547 {
01548     if( !myIsVisible )
01549         return false;
01550 
01551     float xPos, yPos;
01552     myGLText->getPosition( xPos, yPos );
01553 
01554     QRect aRect;
01555     aRect.setLeft( (int)xPos );
01556     aRect.setRight( (int)(xPos + myWidth / myXScale) );
01557     aRect.setTop( (int)yPos );// - myHeight / myYScale );
01558     aRect.setBottom( (int)(yPos + myHeight / myYScale) );
01559 
01560     //cout << "theX: " << theX << "  theY: " << theY << endl;
01561     //cout << "aRect.left(): " << aRect.left() << "  aRect.right(): " << aRect.right() << endl;
01562     //cout << "aRect.top(): " << aRect.top() << "  aRect.bottom(): " << aRect.bottom() << endl;
01563 
01564     QRegion obj( aRect );
01565     QRegion intersection;
01566     QRect region;
01567 
01568     region.setLeft( (int)(theX - theTol) );
01569     region.setRight( (int)(theX + theTol) );
01570     region.setTop( (int)(theY - theTol) );
01571     region.setBottom( (int)(theY + theTol) );
01572 
01573     QRegion circle( (int)(theX - theTol), (int)(theY - theTol),
01574                       (int)(2 * theTol), (int)(2 * theTol), QRegion::Ellipse );
01575     if( isCircle )
01576         intersection = obj.intersect( circle );
01577     else
01578         intersection = obj.intersect( region );
01579     
01580     if( intersection.isEmpty() )
01581         myIsHigh = false;
01582     else
01583         myIsHigh = true;
01584     
01585     if( !myHighFlag && myIsHigh )
01586         myIsHigh = GL_FALSE;
01587     else
01588         myHighFlag = GL_TRUE;
01589 
01590     return myIsHigh;
01591 }
01592 
01596 GLboolean GLViewer_TextObject::unhighlight()
01597 {
01598     if( myIsHigh )
01599     {
01600         myIsHigh = GL_FALSE;
01601         return GL_TRUE;
01602     }
01603 
01604     return GL_FALSE;
01605 }
01606 
01616 GLboolean GLViewer_TextObject::select( GLfloat theX, GLfloat theY, GLfloat theTol, GLViewer_Rect rect,
01617                                        GLboolean isFull, GLboolean isCircle, GLboolean isShift )
01618 { 
01619     if( !myIsVisible )
01620         return false;
01621 
01622     QRegion obj( myRect->toQRect() );
01623     QRegion intersection;
01624     QRect region;
01625 
01626     region.setLeft( (int)(theX - theTol) );
01627     region.setRight( (int)(theX + theTol) );
01628     region.setTop( (int)(theY - theTol) );
01629     region.setBottom( (int)(theY + theTol) );
01630 
01631     QRegion circle( (int)(theX - theTol), (int)(theY - theTol),
01632                       (int)(2 * theTol), (int)(2 * theTol), QRegion::Ellipse );
01633     if( isCircle )
01634         intersection = obj.intersect( circle );
01635     else
01636         intersection = obj.intersect( region );
01637     
01638     if( intersection.isEmpty() )
01639         myIsSel = false;
01640     else
01641         myIsSel = true;
01642 
01643     if ( myIsSel )
01644     {
01645         myHighFlag = GL_FALSE;
01646         myIsHigh = GL_FALSE;
01647     }
01648     else
01649         myHighFlag = GL_TRUE;
01650 
01651     return myIsSel;
01652 }
01653 
01657 GLboolean GLViewer_TextObject::unselect()
01658 {
01659     if( myIsSel )
01660     {
01661         myIsSel = GL_FALSE;
01662         return GL_TRUE;
01663     }
01664 
01665     return GL_FALSE;
01666 }
01667 
01674 void GLViewer_TextObject::moveObject( float theX, float theY, bool fromGroup )
01675 {
01676   if( !fromGroup && myGroup)
01677   {
01678     myGroup->dragingObjects( theX, theY );
01679     return;
01680   }
01681   float aX, anY;
01682   myGLText->getPosition( aX, anY );
01683   aX += theX;
01684   anY += theY;
01685   myGLText->setPosition( aX, anY );
01686   compute();
01687 }
01688 
01693 QByteArray GLViewer_TextObject::getByteCopy()
01694 {
01695     QByteArray aObject = GLViewer_Object::getByteCopy();
01696 
01697     return aObject;
01698 }
01699 
01704 bool GLViewer_TextObject::initializeFromByteCopy( QByteArray theArray )
01705 {
01706     if( !GLViewer_Object::initializeFromByteCopy( theArray ) || myType != "GLViewer_TextObject" )
01707         return false;
01708 
01709     myHighFlag = true;
01710     return true;        
01711 }