1 // Copyright (C) 2005 OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
19 // Author : OPEN CASCADE
22 /***************************************************************************
23 ** Class: GLViewer_BaseObjects
24 ** Descr: Internal OpenGL Objects
26 ** Created: UI team, 02.09.02
27 ****************************************************************************/
29 //#include <GLViewerAfx.h>
30 #include "GLViewer_BaseObjects.h"
31 #include "GLViewer_BaseDrawers.h"
32 #include "GLViewer_AspectLine.h"
33 #include "GLViewer_CoordSystem.h"
34 #include "GLViewer_Text.h"
35 #include "GLViewer_Group.h"
37 #include "GLViewer_Drawer.h"
40 //using namespace std;
42 /***************************************************************************
43 ** Class: GLViewer_MarkerSet
44 ** Descr: OpenGL MarkerSet
46 ** Created: UI team, 03.09.02
47 ****************************************************************************/
49 GLViewer_MarkerSet::GLViewer_MarkerSet( int number, float size, const QString& toolTip ) :
60 myUSelNumbers.clear();
61 myCurSelNumbers.clear();
62 myPrevHNumbers.clear();
64 myType = "GLViewer_MarkerSet";
65 myToolTipText = toolTip;
67 setNumMarkers( number );
70 GLViewer_MarkerSet::~GLViewer_MarkerSet()
78 void AddCoordsToHPGL( QString& buffer, QString command, GLViewer_CoordSystem* aViewerCS,
79 GLViewer_CoordSystem* aPaperCS, double x, double y, bool NewLine = true )
81 if( aViewerCS && aPaperCS )
82 aViewerCS->transform( *aPaperCS, x, y );
84 QString temp = command + "%1, %2;";
85 buffer += temp.arg( x ).arg( y );
90 void AddCoordsToPS( QString& buffer, QString command, GLViewer_CoordSystem* aViewerCS,
91 GLViewer_CoordSystem* aPaperCS, double x, double y, bool NewLine = true )
93 if( aViewerCS && aPaperCS )
94 aViewerCS->transform( *aPaperCS, x, y );
96 QString temp = "%1 %2 "+command;
97 buffer += temp.arg( x ).arg( y );
102 void AddLineAspectToPS( QString& buffer, GLViewer_AspectLine* anAspect,
103 GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPaperCS )
107 QColor col1, col2, col3;
108 anAspect->getLineColors( col1, col2, col3 );
110 float aWidth = anAspect->getLineWidth();
111 int aLineType = anAspect->getLineType();
113 QString temp = "%1 %2 %3 setrgbcolor\n";
114 double rr = 1 - double( col1.red() ) / 255.0, //color inverting
115 gg = 1 - double( col1.green() ) / 255.0,
116 bb = 1 - double( col1.blue() ) / 255.0;
118 buffer += temp.arg( rr ).arg( gg ).arg( bb );
120 double x_stretch, y_stretch;
121 aViewerCS->getStretching( *aPaperCS, x_stretch, y_stretch );
122 buffer += temp.arg( x_stretch * aWidth )+" setlinewidth\n";
124 if( aLineType==0 ) //solid
125 buffer += "[] 0 setdash\n";
126 else if( aLineType==1 ) //strip
127 buffer += "[2] 0 setdash\n";
132 HPEN AddLineAspectToEMF( HDC hDC, GLViewer_AspectLine* anAspect,
133 GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPaperCS )
137 QColor col1, col2, col3;
138 anAspect->getLineColors( col1, col2, col3 );
140 double x_stretch, y_stretch;
141 aViewerCS->getStretching( *aPaperCS, x_stretch, y_stretch );
143 double aWidth = anAspect->getLineWidth()*x_stretch;
144 int aLineType = anAspect->getLineType();
146 return CreatePen( PS_SOLID, aWidth, RGB( 255-col1.red(), 255-col1.green(), 255-col1.blue() ) );
153 bool GLViewer_MarkerSet::translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS )
157 QString aBuffer = "newpath\n";
159 AddLineAspectToPS( aBuffer, getAspectLine(), aViewerCS, aPSCS );
161 for( int i=0; i<myNumber; i++ )
165 double x_stretch, y_stretch;
166 aViewerCS->getStretching( *aPSCS, x_stretch, y_stretch );
168 double x0 = myXCoord[i],
173 for( int j=0; j<=noPoints; j++ )
175 x = x0 + r*cos( double(j)*2*PI/double(noPoints) );
176 y = y0 + r*sin( double(j)*2*PI/double(noPoints) );
178 AddCoordsToPS( aBuffer, "moveto", aViewerCS, aPSCS, x, y, true );
180 AddCoordsToPS( aBuffer, "lineto", aViewerCS, aPSCS, x, y, true );
183 aBuffer+="closepath\nstroke\n";
185 hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
190 bool GLViewer_MarkerSet::translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS,
191 GLViewer_CoordSystem* aHPGLCS )
195 for( int i=0; i<myNumber; i++ )
199 double x_stretch, y_stretch;
200 aViewerCS->getStretching( *aHPGLCS, x_stretch, y_stretch );
202 double x0 = myXCoord[i],
207 AddCoordsToHPGL( aBuffer, "PA", aViewerCS, aHPGLCS, x0+r, y0 );
209 for( int j=1; j<=noPoints; j++ )
211 x = x0 + r*cos( double(j)*2*PI/double(noPoints) );
212 y = y0 + r*sin( double(j)*2*PI/double(noPoints) );
213 AddCoordsToHPGL( aBuffer, "PD", aViewerCS, aHPGLCS, x, y );
217 hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
224 bool GLViewer_MarkerSet::translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS )
227 if( !aViewerCS || !aEMFCS )
230 HPEN pen = AddLineAspectToEMF( dc, getAspectLine(), aViewerCS, aEMFCS );
231 HGDIOBJ old = SelectObject( dc, pen );
233 for( int i=0; i<myNumber; i++ )
235 double x0 = myXCoord[i],
240 for( int j=0; j<=noPoints; j++ )
242 x = x0 + r*cos( double(j)*2*PI/double(noPoints) );
243 y = y0 + r*sin( double(j)*2*PI/double(noPoints) );
244 aViewerCS->transform( *aEMFCS, x, y );
246 MoveToEx( dc, x, y, NULL );
252 SelectObject( dc, old );
260 void GLViewer_MarkerSet::compute()
262 // cout << "GLViewer_MarkerSet::compute" << endl;
263 GLfloat xa = myXCoord[0];
264 GLfloat xb = myXCoord[0];
265 GLfloat ya = myYCoord[0];
266 GLfloat yb = myYCoord[0];
268 for ( int i = 0; i < myNumber; i++ )
270 xa = QMIN( xa, myXCoord[i] );
271 xb = QMAX( xb, myXCoord[i] );
272 ya = QMIN( ya, myYCoord[i] );
273 yb = QMAX( yb, myYCoord[i] );
276 myXGap = ( xb - xa ) / 10;
277 myYGap = ( yb - ya ) / 10;
279 myRect->setLeft( xa - myXGap );
280 myRect->setTop( yb + myYGap );
281 myRect->setRight( xb + myXGap );
282 myRect->setBottom( ya - myYGap );
285 GLViewer_Drawer* GLViewer_MarkerSet::createDrawer()
287 // cout << "GLViewer_MarkerSet::createDrawer" << endl;
288 return myDrawer = new GLViewer_MarkerDrawer();
292 GLboolean GLViewer_MarkerSet::highlight( GLfloat x, GLfloat y, GLfloat tol, GLboolean isCircle )
296 // cout << "GLViewer_MarkerSet::highlight " << x <<" " << y << " " << tol << endl;
298 GLfloat xdist, ydist, radius;
299 QValueList<int>::Iterator it;
300 QValueList<int> curHNumbers;
305 radius = tol - myMarkerSize / 2.;
307 myUHNumbers += myHNumbers;
310 for ( int i = 0; i < myNumber; i++ )
312 xdist = ( myXCoord[i] - x ) * myXScale;
313 ydist = ( myYCoord[i] - y ) * myYScale;
315 // if ( isCircle && ( xdist * xdist + ydist * ydist <= radius * radius ) ||
316 if ( isCircle && ( xdist * xdist + ydist * ydist <= myMarkerSize * myMarkerSize ) ||
317 !isCircle && ( fabs( xdist ) <= radius && fabs( ydist ) <= radius ) )
321 for ( it = myCurSelNumbers.begin(); it != myCurSelNumbers.end(); ++it )
325 curHNumbers.append( i );
329 myHNumbers.append( i );
334 myCurSelNumbers = curHNumbers;
336 myIsHigh = ( GLboolean )count;
337 update = ( GLboolean )( myHNumbers != myPrevHNumbers );
339 myPrevHNumbers = myHNumbers;
341 //cout << "GLViewer_MarkerSet::highlight complete with " << (int)myIsHigh << endl;
345 GLboolean GLViewer_MarkerSet::unhighlight()
347 if( !myHNumbers.isEmpty() )
349 myUHNumbers += myHNumbers;
350 myPrevHNumbers.clear();
352 //??? myCurSelNumbers.clear();
359 GLboolean GLViewer_MarkerSet::select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect, GLboolean isFull,
360 GLboolean isCircle, GLboolean isShift )
364 // cout << "GLViewer_MarkerSet::select " << x << " " << y << endl;
366 GLfloat xdist, ydist, radius;
367 QValueList<int>::Iterator it;
368 QValueList<int>::Iterator it1;
369 QValueList<int>::Iterator remIt;
370 QValueList<int>::Iterator curIt;
372 radius = tol - myMarkerSize / 2.;
374 if( radius < myMarkerSize / 2.)
375 radius = myMarkerSize / 2.;
377 count = isShift ? mySelNumbers.count() : 0;
379 myUSelNumbers = mySelNumbers;
383 mySelNumbers.clear();
384 myCurSelNumbers.clear();
387 for ( int i = 0; i < myNumber; i++ )
389 xdist = ( myXCoord[i] - x ) * myXScale;
390 ydist = ( myYCoord[i] - y ) * myYScale;
392 //if ( isCircle && ( xdist * xdist + ydist * ydist <= radius * radius ) ||
393 if ( isCircle && ( xdist * xdist + ydist * ydist <= myMarkerSize * myMarkerSize ) ||
394 !isCircle && ( fabs( xdist ) <= radius && fabs( ydist ) <= radius ) )
399 bool isFound = FALSE;
400 for( it = mySelNumbers.begin(); it != mySelNumbers.end(); ++it )
403 myUSelNumbers.append( *it );
411 mySelNumbers.append( i );
412 myCurSelNumbers.append( i );
413 for ( it1 = myHNumbers.begin(); it1 != myHNumbers.end(); ++it1 )
416 myHNumbers.remove( it1 );
419 for ( it1 = myUHNumbers.begin(); it1 != myUHNumbers.end(); ++it1 )
422 myUHNumbers.remove( it1 );
428 mySelNumbers.remove( remIt );
429 for ( curIt = myCurSelNumbers.begin(); curIt != myCurSelNumbers.end(); ++curIt )
430 if( *curIt == *remIt)
432 myCurSelNumbers.remove( curIt );
435 for ( it1 = myHNumbers.begin(); it1 != myHNumbers.end(); ++it1 )
438 myHNumbers.remove( it1 );
441 for ( it1 = myUHNumbers.begin(); it1 != myUHNumbers.end(); ++it1 )
444 myUHNumbers.remove( it1 );
451 mySelNumbers.append( i );
452 myCurSelNumbers.append( i );
453 for ( it1 = myHNumbers.begin(); it1 != myHNumbers.end(); ++it1 )
456 myHNumbers.remove( it1 );
459 for ( it1 = myUHNumbers.begin(); it1 != myUHNumbers.end(); ++it1 )
462 myUHNumbers.remove( it1 );
469 for( it = mySelNumbers.begin(); it != mySelNumbers.end(); ++it )
470 for( it1 = myUSelNumbers.begin(); it1 != myUSelNumbers.end(); ++it1 )
473 it1 = myUSelNumbers.remove( it1 );
477 myIsSel = (GLboolean)count;
479 // cout << "GLViewer_MarkerSet::select complete with " << (int)myIsSel << endl;
483 GLboolean GLViewer_MarkerSet::unselect()
485 if( !mySelNumbers.isEmpty() )
487 myUSelNumbers = mySelNumbers;
488 mySelNumbers.clear();
489 myCurSelNumbers.clear();
496 GLViewer_Rect* GLViewer_MarkerSet::getUpdateRect()
498 GLViewer_Rect* rect = new GLViewer_Rect();
500 rect->setLeft( myRect->left() + myXGap - myMarkerSize / myXScale );
501 rect->setTop( myRect->top() + myYGap + myMarkerSize / myYScale );
502 rect->setRight( myRect->right() - myXGap + myMarkerSize / myXScale );
503 rect->setBottom( myRect->bottom() - myYGap - myMarkerSize / myYScale );
504 //cout << " Additional tolerance " << myMarkerSize / myYScale << endl;
505 //rect->setLeft( myRect->left() - myMarkerSize / myXScale );
506 //rect->setTop( myRect->top() - myMarkerSize / myYScale );
507 //rect->setRight( myRect->right() + myMarkerSize / myXScale );
508 //rect->setBottom( myRect->bottom() + myMarkerSize / myYScale );
514 void GLViewer_MarkerSet::setXCoord( GLfloat* xCoord, int size )
516 myXCoord = new GLfloat[ size ];
517 for( int i = 0; i < size; i++ )
518 myXCoord[i] = xCoord[i];
521 void GLViewer_MarkerSet::setYCoord( GLfloat* yCoord, int size )
523 myYCoord = new GLfloat[ size ];
524 for( int i = 0; i < size; i++ )
525 myYCoord[i] = yCoord[i];
528 void GLViewer_MarkerSet::setNumMarkers( GLint number )
530 if ( myNumber == number )
533 if ( myXCoord && myYCoord )
540 myXCoord = new GLfloat[ myNumber ];
541 myYCoord = new GLfloat[ myNumber ];
544 void GLViewer_MarkerSet::onSelectionDone( bool append)
546 mySelectedIndexes.Clear();
547 QValueList<int>::Iterator it;
548 //for( it = myMarkers->mySelNumbers.begin(); it != myMarkers->mySelNumbers.end(); ++it )
549 // mySelectedIndexes.Append( *it / 2 ); //!!!
551 emit dvMarkersSelected( mySelectedIndexes );
554 void GLViewer_MarkerSet::onSelectionCancel()
556 mySelectedIndexes.Clear();
557 emit dvMarkersSelected( mySelectedIndexes );
560 void GLViewer_MarkerSet::exportNumbers( QValueList<int>& highlight,
561 QValueList<int>& unhighlight,
562 QValueList<int>& select,
563 QValueList<int>& unselect )
565 highlight = myHNumbers;
566 unhighlight = myUHNumbers;
567 select = mySelNumbers;
568 unselect = myUSelNumbers;
570 myUHNumbers = myHNumbers;
573 bool GLViewer_MarkerSet::addOrRemoveSelected( int index )
575 if( index < 0 || index > myNumber )
578 int n = mySelNumbers.findIndex( index );
580 mySelNumbers.append( index );
583 QValueList<int>::Iterator it;
584 it = mySelNumbers.at( n );
585 mySelNumbers.remove( it );
586 myUSelNumbers.append( index );
591 void GLViewer_MarkerSet::addSelected( const TColStd_SequenceOfInteger& seq )
593 for ( int i = 1; i <= seq.Length(); i++ )
594 if( mySelNumbers.findIndex( seq.Value( i ) ) == -1 )
595 mySelNumbers.append( seq.Value( i ) - 1 );
598 void GLViewer_MarkerSet::setSelected( const TColStd_SequenceOfInteger& seq )
600 // for( QValueList<int>::Iterator it = mySelNumbers.begin(); it != mySelNumbers.end(); ++it )
601 // if( myUSelNumbers.findIndex( *it ) == -1 )
602 // myUSelNumbers.append( *it );
604 myUSelNumbers = mySelNumbers;
605 mySelNumbers.clear();
607 for ( int i = 1; i <= seq.Length(); i++ )
608 mySelNumbers.append( seq.Value( i ) - 1 );
611 void GLViewer_MarkerSet::moveObject( float theX, float theY, bool fromGroup )
613 if( !fromGroup && myGroup)
615 myGroup->dragingObjects( theX, theY );
618 for( int i = 0; i < myNumber; i++ )
620 myXCoord[i] = myXCoord[i] + theX;
621 myYCoord[i] = myYCoord[i] + theY;
626 QByteArray GLViewer_MarkerSet::getByteCopy()
629 int anISize = sizeof( GLint );
630 int aFSize = sizeof( GLfloat );
632 QByteArray aObject = GLViewer_Object::getByteCopy();
634 QByteArray aResult( anISize + 2*aFSize*myNumber + aFSize + aObject.size());
636 char* aPointer = (char*)&myNumber;
637 for( i = 0; i < anISize; i++, aPointer++ )
638 aResult[i] = *aPointer;
640 aPointer = (char*)myXCoord;
641 for( ; i < anISize + aFSize*myNumber; i++, aPointer++ )
642 aResult[i] = *aPointer;
643 aPointer = (char*)myYCoord;
644 for( ; i < anISize + 2*aFSize*myNumber; i++, aPointer++ )
645 aResult[i] = *aPointer;
647 aPointer = (char*)&myMarkerSize;
648 for( ; i < anISize + 2*aFSize*myNumber + aFSize; i++, aPointer++ )
649 aResult[i] = *aPointer;
652 for( ; i < aResult.size(); i++ )
653 aResult[i] = aObject[i - anISize - 2*aFSize*myNumber - aFSize];
658 bool GLViewer_MarkerSet::initializeFromByteCopy( QByteArray theArray )
661 int anISize = sizeof( GLint );
662 int aFSize = sizeof( GLfloat );
664 char* aPointer = (char*)&myNumber;
665 for( i = 0; i < anISize; i++, aPointer++ )
666 *aPointer = theArray[i];
668 int aSize = theArray.size();
669 if( aSize < anISize + 2*aFSize*myNumber + aFSize)
672 myXCoord = new GLfloat[myNumber];
673 myYCoord = new GLfloat[myNumber];
674 aPointer = (char*)myXCoord;
675 for( ; i < anISize + aFSize*myNumber; i++, aPointer++ )
676 *aPointer = theArray[i];
677 aPointer = (char*)myYCoord;
678 for( ; i < anISize + 2*aFSize*myNumber; i++, aPointer++ )
679 *aPointer = theArray[i];
681 aPointer = (char*)&myMarkerSize;
682 for( ; i < anISize + 2*aFSize*myNumber + aFSize; i++, aPointer++ )
683 *aPointer = theArray[i];
685 int aCurIndex = anISize + 2*aFSize*myNumber + aFSize;
686 QByteArray aObject( aSize - aCurIndex );
687 for( ; i < aSize; i++ )
688 aObject[i - aCurIndex] = theArray[i];
691 if( !GLViewer_Object::initializeFromByteCopy( aObject ) || myType != "GLViewer_MarkerSet" )
696 mySelNumbers.clear();
697 myUSelNumbers.clear();
698 myCurSelNumbers.clear();
699 myPrevHNumbers.clear();
704 /***************************************************************************
705 ** Class: GLViewer_Polyline
706 ** Descr: OpenGL Polyline
708 ** Created: UI team, 03.09.02
709 ****************************************************************************/
714 GLViewer_Polyline::GLViewer_Polyline( int number, float size, const QString& toolTip ):
720 myHighFlag = GL_TRUE;
724 mySelNumbers.clear();
725 myUSelNumbers.clear();
726 myCurSelNumbers.clear();
727 myPrevHNumbers.clear();
731 myType = "GLViewer_Polyline";
732 myToolTipText = toolTip;
735 GLViewer_Polyline::~GLViewer_Polyline()
743 bool GLViewer_Polyline::translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS )
745 QString aBuffer = "newpath\n";
747 AddLineAspectToPS( aBuffer, getAspectLine(), aViewerCS, aPSCS );
749 for( int i=0; i<myNumber; i++ )
751 AddCoordsToPS( aBuffer, "moveto", aViewerCS, aPSCS, myXCoord[i], myYCoord[i] );
753 AddCoordsToPS( aBuffer, "lineto", aViewerCS, aPSCS, myXCoord[i], myYCoord[i] );
756 AddCoordsToPS( aBuffer, "lineto", aViewerCS, aPSCS, myXCoord[0], myYCoord[0] );
758 aBuffer+="closepath\nstroke\n";
760 hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
765 bool GLViewer_Polyline::translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS )
767 QString aBuffer = "";
768 for( int i=0; i<myNumber; i++ )
770 AddCoordsToHPGL( aBuffer, "PA", aViewerCS, aHPGLCS, myXCoord[i], myYCoord[i] );
776 AddCoordsToHPGL( aBuffer, "PA", aViewerCS, aHPGLCS, myXCoord[0], myYCoord[0] );
780 hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
786 bool GLViewer_Polyline::translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS )
788 if( !aViewerCS || !aEMFCS )
791 HPEN pen = AddLineAspectToEMF( dc, getAspectLine(), aViewerCS, aEMFCS );
792 HGDIOBJ old = SelectObject( dc, pen );
795 for( int i=0; i<myNumber; i++ )
799 aViewerCS->transform( *aEMFCS, x, y );
801 MoveToEx( dc, x, y, NULL );
810 aViewerCS->transform( *aEMFCS, x, y );
814 SelectObject( dc, old );
822 void GLViewer_Polyline::compute()
824 // cout << "GLViewer_MarkerSet::compute" << endl;
825 GLfloat xa = myXCoord[0];
826 GLfloat xb = myXCoord[0];
827 GLfloat ya = myYCoord[0];
828 GLfloat yb = myYCoord[0];
830 for ( int i = 0; i < myNumber; i++ )
832 xa = QMIN( xa, myXCoord[i] );
833 xb = QMAX( xb, myXCoord[i] );
834 ya = QMIN( ya, myYCoord[i] );
835 yb = QMAX( yb, myYCoord[i] );
838 GLfloat xGap = ( xb - xa ) / 10;
839 GLfloat yGap = ( yb - ya ) / 10;
841 myRect->setLeft( xa - xGap );
842 myRect->setTop( yb + yGap );
843 myRect->setRight( xb + xGap );
844 myRect->setBottom( ya - yGap );
847 GLViewer_Rect* GLViewer_Polyline::getUpdateRect()
849 GLViewer_Rect* rect = new GLViewer_Rect();
851 rect->setLeft( myRect->left() - myXGap );
852 rect->setTop( myRect->top() + myYGap );
853 rect->setRight( myRect->right() + myXGap );
854 rect->setBottom( myRect->bottom() - myYGap );
859 GLViewer_Drawer* GLViewer_Polyline::createDrawer()
861 // cout << "GLViewer_MarkerSet::createDrawer" << endl;
862 return myDrawer = new GLViewer_PolylineDrawer();
865 GLboolean GLViewer_Polyline::highlight( GLfloat x, GLfloat y, GLfloat tol, GLboolean isCircle )
869 GLfloat xa, xb, ya, yb, l;
870 GLfloat rsin, rcos, r, ra, rb;
872 GLboolean highlighted = myIsHigh;
880 for( int i = 0; i < myNumber-1+c; i++ )
884 if( i != myNumber-1 )
895 l = sqrt( (xb-xa)*(xb-xa) + (yb-ya)*(yb-ya) );
898 r = ( (x-xa)*(y-yb) - (x-xb)*(y-ya) ) / ( rsin*(ya-yb) + rcos*(xa-xb) );
899 ra = sqrt( (x-xa)*(x-xa) + (y-ya)*(y-ya) );
900 rb = sqrt( (x-xb)*(x-xb) + (y-yb)*(y-yb) );
901 if( fabs( r ) * myXScale <= DISTANTION && ra <= l + DISTANTION && rb <= l + DISTANTION )
908 if( !myHighFlag && myIsHigh )
911 myHighFlag = GL_TRUE;
913 update = ( GLboolean )( myIsHigh != highlighted );
915 // cout << "GLViewer_Polyline::highlight complete with " << (int)myIsHigh << endl;
919 GLboolean GLViewer_Polyline::unhighlight()
921 // if( !myHNumbers.isEmpty() )
923 // myUHNumbers = myHNumbers;
924 // myHNumbers.clear();
937 GLboolean GLViewer_Polyline::select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect, GLboolean isFull,
938 GLboolean isCircle, GLboolean isShift )
942 GLfloat xa, xb, ya, yb, l;
943 GLfloat rsin, rcos, r, ra, rb;
945 GLboolean selected = myIsSel;
953 for( int i = 0; i < myNumber-1+c; i++ )
957 if( i != myNumber-1 )
968 l = sqrt( (xb-xa)*(xb-xa) + (yb-ya)*(yb-ya) );
971 r = ( (x-xa)*(y-yb) - (x-xb)*(y-ya) ) / ( rsin*(ya-yb) + rcos*(xa-xb) );
972 ra = sqrt( (x-xa)*(x-xa) + (y-ya)*(y-ya) );
973 rb = sqrt( (x-xb)*(x-xb) + (y-yb)*(y-yb) );
974 if( fabs( r ) * myXScale <= DISTANTION && ra <= l + DISTANTION && rb <= l + DISTANTION )
983 myHighFlag = GL_FALSE;
987 myHighFlag = GL_TRUE;
989 update = ( GLboolean )( myIsSel != selected );
991 // cout << "GLViewer_Polyline::select complete with " << (int)myIsSel << endl;
993 // return update; !!!!!!!!!!!!!!!!!!!!!!!!!!! no here
997 GLboolean GLViewer_Polyline::unselect()
999 // if( !mySelNumbers.isEmpty() )
1001 // myUSelNumbers = mySelNumbers;
1002 // mySelNumbers.clear();
1003 // myCurSelNumbers.clear();
1016 void GLViewer_Polyline::setXCoord( GLfloat* xCoord, int size )
1018 myXCoord = new GLfloat[ size ];
1019 for( int i = 0; i < size; i++ )
1020 myXCoord[i] = xCoord[i];
1023 void GLViewer_Polyline::setYCoord( GLfloat* yCoord, int size )
1025 myYCoord = new GLfloat[ size ];
1026 for( int i = 0; i < size; i++ )
1027 myYCoord[i] = yCoord[i];
1030 void GLViewer_Polyline::setNumber( GLint number )
1032 if ( myNumber == number )
1035 if ( myXCoord && myYCoord )
1042 myXCoord = new GLfloat[ myNumber ];
1043 myYCoord = new GLfloat[ myNumber ];
1046 void GLViewer_Polyline::onSelectionDone( bool append)
1048 mySelectedIndexes.Clear();
1049 QValueList<int>::Iterator it;
1050 //for( it = myMarkers->mySelNumbers.begin(); it != myMarkers->mySelNumbers.end(); ++it )
1051 // mySelectedIndexes.Append( *it / 2 ); //!!!
1054 void GLViewer_Polyline::onSelectionCancel()
1056 mySelectedIndexes.Clear();
1059 void GLViewer_Polyline::exportNumbers( QValueList<int>& highlight,
1060 QValueList<int>& unhighlight,
1061 QValueList<int>& select,
1062 QValueList<int>& unselect )
1064 highlight = myHNumbers;
1065 unhighlight = myUHNumbers;
1066 select = mySelNumbers;
1067 unselect = myUSelNumbers;
1070 void GLViewer_Polyline::moveObject( float theX, float theY, bool fromGroup )
1072 if( !fromGroup && myGroup)
1074 myGroup->dragingObjects( theX, theY );
1077 for( int i = 0; i < myNumber; i++ )
1079 myXCoord[i] = myXCoord[i] + theX;
1080 myYCoord[i] = myYCoord[i] + theY;
1085 QByteArray GLViewer_Polyline::getByteCopy()
1088 int anISize = sizeof( GLint );
1089 int aFSize = sizeof( GLfloat );
1090 int aBSize = sizeof( GLboolean );
1092 QByteArray aObject = GLViewer_Object::getByteCopy();
1094 QByteArray aResult( aFSize*myNumber*2 + anISize + 2*aBSize + aObject.size());
1096 char* aPointer = (char*)&myNumber;
1097 for( i = 0; i < anISize; i++, aPointer++ )
1098 aResult[i] = *aPointer;
1100 aPointer = (char*)myXCoord;
1101 for( ; i < anISize + aFSize*myNumber; i++, aPointer++ )
1102 aResult[i] = *aPointer;
1103 aPointer = (char*)myYCoord;
1104 for( ; i < anISize + 2*aFSize*myNumber; i++, aPointer++ )
1105 aResult[i] = *aPointer;
1107 aPointer = (char*)&myIsClosed;
1108 for( ; i < anISize + 2*aFSize*myNumber + aBSize; i++, aPointer++ )
1109 aResult[i] = *aPointer;
1110 aPointer = (char*)&myHighSelAll;
1111 for( ; i < anISize + 2*aFSize*myNumber + 2*aBSize; i++, aPointer++ )
1112 aResult[i] = *aPointer;
1114 for( ; i < aResult.size(); i++ )
1115 aResult[i] = aObject[i - anISize - 2*aFSize*myNumber - 2*aBSize];
1121 bool GLViewer_Polyline::initializeFromByteCopy( QByteArray theArray )
1124 int anISize = sizeof( GLint );
1125 int aFSize = sizeof( GLfloat );
1126 int aBSize = sizeof( GLboolean );
1128 char* aPointer = (char*)&myNumber;
1129 for( i = 0; i < anISize; i++, aPointer++ )
1130 *aPointer = theArray[i];
1132 int aSize = theArray.size();
1133 if( aSize < aFSize*myNumber*2 + anISize + 2*aBSize )
1136 myXCoord = new GLfloat[myNumber];
1137 myYCoord = new GLfloat[myNumber];
1138 aPointer = (char*)myXCoord;
1139 for( ; i < anISize + aFSize*myNumber; i++, aPointer++ )
1140 *aPointer = theArray[i];
1141 aPointer = (char*)myYCoord;
1142 for( ; i < anISize + 2*aFSize*myNumber; i++, aPointer++ )
1143 *aPointer = theArray[i];
1145 aPointer = (char*)&myIsClosed;
1146 for( ; i < anISize + 2*aFSize*myNumber + aBSize; i++, aPointer++ )
1147 *aPointer = theArray[i];
1148 aPointer = (char*)&myHighSelAll;
1149 for( ; i < anISize + 2*aFSize*myNumber + 2*aBSize; i++, aPointer++ )
1150 *aPointer = theArray[i];
1152 int aCurIndex = anISize + 2*aFSize*myNumber + 2*aBSize;
1153 QByteArray aObject( aSize - aCurIndex );
1154 for( ; i < aSize; i++ )
1155 aObject[i - aCurIndex] = theArray[i];
1157 if( !GLViewer_Object::initializeFromByteCopy( aObject ) || myType != "GLViewer_Polyline" )
1161 myUHNumbers.clear();
1162 mySelNumbers.clear();
1163 myUSelNumbers.clear();
1164 myCurSelNumbers.clear();
1165 myPrevHNumbers.clear();
1170 /***************************************************************************
1171 ** Class: GLViewer_TextObject
1172 ** Descr: Text as Object for OpenGL
1174 ** Created: UI team, 12.02.04
1175 ****************************************************************************/
1177 GLViewer_TextObject::GLViewer_TextObject( const QString& theStr, float xPos, float yPos,
1178 const QColor& color, const QString& toolTip )
1181 myGLText = new GLViewer_Text( theStr, xPos, yPos, color );
1185 myHighFlag = GL_TRUE;
1187 myToolTipText = toolTip;
1189 GLViewer_TextObject::~GLViewer_TextObject()
1195 bool GLViewer_TextObject::translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS )
1197 QString aText = myGLText->getText();
1199 myGLText->getPosition( xPos, yPos );
1201 QString aBuffer = "/Times-Roman findfont\n";
1202 aBuffer += "12 scalefont setfont\n";
1204 AddCoordsToPS( aBuffer, "moveto", aViewerCS, aPSCS, double(xPos), double(yPos) );
1205 aBuffer += "(" + aText + ") show\n";
1207 hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
1212 bool GLViewer_TextObject::translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS )
1214 QString aText = myGLText->getText();
1216 myGLText->getPosition( xPos, yPos );
1218 QString aBuffer = "";
1219 AddCoordsToHPGL( aBuffer, "PA", aViewerCS, aHPGLCS, double(xPos), double(yPos) );
1221 aBuffer = "LB" + aText + "#;";
1223 hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
1229 bool GLViewer_TextObject::translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS )
1231 QString aText = myGLText->getText();
1233 myGLText->getPosition( xPos, yPos );
1235 double x = double( xPos ),
1238 aViewerCS->transform( *aEMFCS, x, y );
1239 const char* str = aText.ascii();
1241 int nHeight = 35*14; // height of font
1242 int nWidth = 35*12; // average character width
1243 int nEscapement = 0; // angle of escapement
1244 int nOrientation = 0; // base-line orientation angle
1245 int fnWeight = FW_NORMAL; // font weight
1246 DWORD fdwItalic = FALSE; // italic attribute option
1247 DWORD fdwUnderline = FALSE; // underline attribute option
1248 DWORD fdwStrikeOut = FALSE; // strikeout attribute option
1249 DWORD fdwCharSet = ANSI_CHARSET; // character set identifier
1250 DWORD fdwOutputPrecision = OUT_DEFAULT_PRECIS; // output precision
1251 DWORD fdwClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
1252 DWORD fdwQuality = PROOF_QUALITY; // output quality
1253 DWORD fdwPitchAndFamily = FIXED_PITCH | FF_DONTCARE; // pitch and family
1254 LPCTSTR lpszFace = NULL; // typeface name
1257 HFONT aFont = CreateFont( nHeight, nWidth, nEscapement, nOrientation, fnWeight, fdwItalic,
1258 fdwUnderline, fdwStrikeOut, fdwCharSet, fdwOutputPrecision,
1259 fdwClipPrecision, fdwQuality, fdwPitchAndFamily, lpszFace );
1260 LOGBRUSH aBrushData;
1261 aBrushData.lbStyle = BS_HOLLOW;
1263 HBRUSH aBrush = CreateBrushIndirect( &aBrushData );
1265 HGDIOBJ old1 = SelectObject( dc, aFont );
1266 HGDIOBJ old2 = SelectObject( dc, aBrush );
1268 TextOut( dc, x, y, str, aText.length() );
1270 SelectObject ( dc, old1 );
1271 SelectObject ( dc, old2 );
1273 DeleteObject( aFont );
1279 GLViewer_Drawer* GLViewer_TextObject::createDrawer()
1281 myDrawer = new GLViewer_TextDrawer();
1286 void GLViewer_TextObject::compute()
1289 QString aStr = myGLText->getText();
1290 myGLText->getPosition( xPos, yPos );
1292 myWidth = myGLText->getWidth();
1293 myHeight = myGLText->getHeight();
1294 myRect->setLeft( xPos );
1295 myRect->setTop( yPos + myHeight );
1296 myRect->setRight( xPos + myWidth );
1297 myRect->setBottom( yPos );
1300 void GLViewer_TextObject::setDrawer( GLViewer_Drawer* theDrawer )
1302 myDrawer = theDrawer;
1306 GLViewer_Rect* GLViewer_TextObject::getUpdateRect()
1308 GLViewer_Rect* rect = new GLViewer_Rect();
1311 QString aStr = myGLText->getText();
1312 myGLText->getPosition( xPos, yPos );
1314 rect->setLeft( myRect->left() + myXGap - myWidth / myXScale );
1315 rect->setTop( myRect->top() + myYGap + myHeight / myYScale );
1316 rect->setRight( myRect->right() - myXGap + myWidth / myXScale );
1317 rect->setBottom( myRect->bottom() - myYGap - myHeight / myYScale );
1322 GLboolean GLViewer_TextObject::highlight( GLfloat theX, GLfloat theY, GLfloat theTol, GLboolean isCircle )
1328 myGLText->getPosition( xPos, yPos );
1331 aRect.setLeft( (int)xPos );
1332 aRect.setRight( (int)(xPos + myWidth / myXScale) );
1333 aRect.setTop( (int)yPos );// - myHeight / myYScale );
1334 aRect.setBottom( (int)(yPos + myHeight / myYScale) );
1336 //cout << "theX: " << theX << " theY: " << theY << endl;
1337 //cout << "aRect.left(): " << aRect.left() << " aRect.right(): " << aRect.right() << endl;
1338 //cout << "aRect.top(): " << aRect.top() << " aRect.bottom(): " << aRect.bottom() << endl;
1340 QRegion obj( aRect );
1341 QRegion intersection;
1344 region.setLeft( (int)(theX - theTol) );
1345 region.setRight( (int)(theX + theTol) );
1346 region.setTop( (int)(theY - theTol) );
1347 region.setBottom( (int)(theY + theTol) );
1349 QRegion circle( (int)(theX - theTol), (int)(theY - theTol),
1350 (int)(2 * theTol), (int)(2 * theTol), QRegion::Ellipse );
1352 intersection = obj.intersect( circle );
1354 intersection = obj.intersect( region );
1356 if( intersection.isEmpty() )
1361 if( !myHighFlag && myIsHigh )
1362 myIsHigh = GL_FALSE;
1364 myHighFlag = GL_TRUE;
1369 GLboolean GLViewer_TextObject::unhighlight()
1373 myIsHigh = GL_FALSE;
1380 GLboolean GLViewer_TextObject::select( GLfloat theX, GLfloat theY, GLfloat theTol, GLViewer_Rect rect,
1381 GLboolean isFull, GLboolean isCircle, GLboolean isShift )
1386 QRegion obj( myRect->toQRect() );
1387 QRegion intersection;
1390 region.setLeft( (int)(theX - theTol) );
1391 region.setRight( (int)(theX + theTol) );
1392 region.setTop( (int)(theY - theTol) );
1393 region.setBottom( (int)(theY + theTol) );
1395 QRegion circle( (int)(theX - theTol), (int)(theY - theTol),
1396 (int)(2 * theTol), (int)(2 * theTol), QRegion::Ellipse );
1398 intersection = obj.intersect( circle );
1400 intersection = obj.intersect( region );
1402 if( intersection.isEmpty() )
1409 myHighFlag = GL_FALSE;
1410 myIsHigh = GL_FALSE;
1413 myHighFlag = GL_TRUE;
1418 GLboolean GLViewer_TextObject::unselect()
1429 void GLViewer_TextObject::moveObject( float theX, float theY, bool fromGroup )
1431 if( !fromGroup && myGroup)
1433 myGroup->dragingObjects( theX, theY );
1437 myGLText->getPosition( aX, anY );
1440 myGLText->setPosition( aX, anY );
1444 QByteArray GLViewer_TextObject::getByteCopy()
1446 QByteArray aObject = GLViewer_Object::getByteCopy();
1451 bool GLViewer_TextObject::initializeFromByteCopy( QByteArray theArray )
1453 if( !GLViewer_Object::initializeFromByteCopy( theArray ) || myType != "GLViewer_TextObject" )