1 /***************************************************************************
2 ** Class: GLViewer_BaseObjects
3 ** Descr: Internal OpenGL Objects
5 ** Created: UI team, 02.09.02
6 ****************************************************************************/
8 //#include <GLViewerAfx.h>
9 #include "GLViewer_BaseObjects.h"
10 #include "GLViewer_BaseDrawers.h"
11 #include "GLViewer_AspectLine.h"
12 #include "GLViewer_CoordSystem.h"
13 #include "GLViewer_Text.h"
14 #include "GLViewer_Group.h"
16 #include "GLViewer_Drawer.h"
19 //using namespace std;
21 /***************************************************************************
22 ** Class: GLViewer_MarkerSet
23 ** Descr: OpenGL MarkerSet
25 ** Created: UI team, 03.09.02
26 ****************************************************************************/
28 GLViewer_MarkerSet::GLViewer_MarkerSet( int number, float size, const QString& toolTip ) :
39 myUSelNumbers.clear();
40 myCurSelNumbers.clear();
41 myPrevHNumbers.clear();
43 myType = "GLViewer_MarkerSet";
44 myToolTipText = toolTip;
46 setNumMarkers( number );
49 GLViewer_MarkerSet::~GLViewer_MarkerSet()
57 void AddCoordsToHPGL( QString& buffer, QString command, GLViewer_CoordSystem* aViewerCS,
58 GLViewer_CoordSystem* aPaperCS, double x, double y, bool NewLine = true )
60 if( aViewerCS && aPaperCS )
61 aViewerCS->transform( *aPaperCS, x, y );
63 QString temp = command + "%1, %2;";
64 buffer += temp.arg( x ).arg( y );
69 void AddCoordsToPS( QString& buffer, QString command, GLViewer_CoordSystem* aViewerCS,
70 GLViewer_CoordSystem* aPaperCS, double x, double y, bool NewLine = true )
72 if( aViewerCS && aPaperCS )
73 aViewerCS->transform( *aPaperCS, x, y );
75 QString temp = "%1 %2 "+command;
76 buffer += temp.arg( x ).arg( y );
81 void AddLineAspectToPS( QString& buffer, GLViewer_AspectLine* anAspect,
82 GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPaperCS )
86 QColor col1, col2, col3;
87 anAspect->getLineColors( col1, col2, col3 );
89 float aWidth = anAspect->getLineWidth();
90 int aLineType = anAspect->getLineType();
92 QString temp = "%1 %2 %3 setrgbcolor\n";
93 double rr = 1 - double( col1.red() ) / 255.0, //color inverting
94 gg = 1 - double( col1.green() ) / 255.0,
95 bb = 1 - double( col1.blue() ) / 255.0;
97 buffer += temp.arg( rr ).arg( gg ).arg( bb );
99 double x_stretch, y_stretch;
100 aViewerCS->getStretching( *aPaperCS, x_stretch, y_stretch );
101 buffer += temp.arg( x_stretch * aWidth )+" setlinewidth\n";
103 if( aLineType==0 ) //solid
104 buffer += "[] 0 setdash\n";
105 else if( aLineType==1 ) //strip
106 buffer += "[2] 0 setdash\n";
111 HPEN AddLineAspectToEMF( HDC hDC, GLViewer_AspectLine* anAspect,
112 GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPaperCS )
116 QColor col1, col2, col3;
117 anAspect->getLineColors( col1, col2, col3 );
119 double x_stretch, y_stretch;
120 aViewerCS->getStretching( *aPaperCS, x_stretch, y_stretch );
122 double aWidth = anAspect->getLineWidth()*x_stretch;
123 int aLineType = anAspect->getLineType();
125 return CreatePen( PS_SOLID, aWidth, RGB( 255-col1.red(), 255-col1.green(), 255-col1.blue() ) );
132 bool GLViewer_MarkerSet::translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS )
136 QString aBuffer = "newpath\n";
138 AddLineAspectToPS( aBuffer, getAspectLine(), aViewerCS, aPSCS );
140 for( int i=0; i<myNumber; i++ )
144 double x_stretch, y_stretch;
145 aViewerCS->getStretching( *aPSCS, x_stretch, y_stretch );
147 double x0 = myXCoord[i],
152 for( int j=0; j<=noPoints; j++ )
154 x = x0 + r*cos( double(j)*2*PI/double(noPoints) );
155 y = y0 + r*sin( double(j)*2*PI/double(noPoints) );
157 AddCoordsToPS( aBuffer, "moveto", aViewerCS, aPSCS, x, y, true );
159 AddCoordsToPS( aBuffer, "lineto", aViewerCS, aPSCS, x, y, true );
162 aBuffer+="closepath\nstroke\n";
164 hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
169 bool GLViewer_MarkerSet::translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS,
170 GLViewer_CoordSystem* aHPGLCS )
174 for( int i=0; i<myNumber; i++ )
178 double x_stretch, y_stretch;
179 aViewerCS->getStretching( *aHPGLCS, x_stretch, y_stretch );
181 double x0 = myXCoord[i],
186 AddCoordsToHPGL( aBuffer, "PA", aViewerCS, aHPGLCS, x0+r, y0 );
188 for( int j=1; j<=noPoints; j++ )
190 x = x0 + r*cos( double(j)*2*PI/double(noPoints) );
191 y = y0 + r*sin( double(j)*2*PI/double(noPoints) );
192 AddCoordsToHPGL( aBuffer, "PD", aViewerCS, aHPGLCS, x, y );
196 hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
203 bool GLViewer_MarkerSet::translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS )
206 if( !aViewerCS || !aEMFCS )
209 HPEN pen = AddLineAspectToEMF( dc, getAspectLine(), aViewerCS, aEMFCS );
210 HGDIOBJ old = SelectObject( dc, pen );
212 for( int i=0; i<myNumber; i++ )
214 double x0 = myXCoord[i],
219 for( int j=0; j<=noPoints; j++ )
221 x = x0 + r*cos( double(j)*2*PI/double(noPoints) );
222 y = y0 + r*sin( double(j)*2*PI/double(noPoints) );
223 aViewerCS->transform( *aEMFCS, x, y );
225 MoveToEx( dc, x, y, NULL );
231 SelectObject( dc, old );
239 void GLViewer_MarkerSet::compute()
241 // cout << "GLViewer_MarkerSet::compute" << endl;
242 GLfloat xa = myXCoord[0];
243 GLfloat xb = myXCoord[0];
244 GLfloat ya = myYCoord[0];
245 GLfloat yb = myYCoord[0];
247 for ( int i = 0; i < myNumber; i++ )
249 xa = QMIN( xa, myXCoord[i] );
250 xb = QMAX( xb, myXCoord[i] );
251 ya = QMIN( ya, myYCoord[i] );
252 yb = QMAX( yb, myYCoord[i] );
255 myXGap = ( xb - xa ) / 10;
256 myYGap = ( yb - ya ) / 10;
258 myRect->setLeft( xa - myXGap );
259 myRect->setTop( yb + myYGap );
260 myRect->setRight( xb + myXGap );
261 myRect->setBottom( ya - myYGap );
264 GLViewer_Drawer* GLViewer_MarkerSet::createDrawer()
266 // cout << "GLViewer_MarkerSet::createDrawer" << endl;
267 return myDrawer = new GLViewer_MarkerDrawer();
271 GLboolean GLViewer_MarkerSet::highlight( GLfloat x, GLfloat y, GLfloat tol, GLboolean isCircle )
275 // cout << "GLViewer_MarkerSet::highlight " << x <<" " << y << " " << tol << endl;
277 GLfloat xdist, ydist, radius;
278 QValueList<int>::Iterator it;
279 QValueList<int> curHNumbers;
284 radius = tol - myMarkerSize / 2.;
286 myUHNumbers += myHNumbers;
289 for ( int i = 0; i < myNumber; i++ )
291 xdist = ( myXCoord[i] - x ) * myXScale;
292 ydist = ( myYCoord[i] - y ) * myYScale;
294 // if ( isCircle && ( xdist * xdist + ydist * ydist <= radius * radius ) ||
295 if ( isCircle && ( xdist * xdist + ydist * ydist <= myMarkerSize * myMarkerSize ) ||
296 !isCircle && ( fabs( xdist ) <= radius && fabs( ydist ) <= radius ) )
300 for ( it = myCurSelNumbers.begin(); it != myCurSelNumbers.end(); ++it )
304 curHNumbers.append( i );
308 myHNumbers.append( i );
313 myCurSelNumbers = curHNumbers;
315 myIsHigh = ( GLboolean )count;
316 update = ( GLboolean )( myHNumbers != myPrevHNumbers );
318 myPrevHNumbers = myHNumbers;
320 //cout << "GLViewer_MarkerSet::highlight complete with " << (int)myIsHigh << endl;
324 GLboolean GLViewer_MarkerSet::unhighlight()
326 if( !myHNumbers.isEmpty() )
328 myUHNumbers += myHNumbers;
329 myPrevHNumbers.clear();
331 //??? myCurSelNumbers.clear();
338 GLboolean GLViewer_MarkerSet::select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect, GLboolean isFull,
339 GLboolean isCircle, GLboolean isShift )
343 // cout << "GLViewer_MarkerSet::select " << x << " " << y << endl;
345 GLfloat xdist, ydist, radius;
346 QValueList<int>::Iterator it;
347 QValueList<int>::Iterator it1;
348 QValueList<int>::Iterator remIt;
349 QValueList<int>::Iterator curIt;
351 radius = tol - myMarkerSize / 2.;
353 if( radius < myMarkerSize / 2.)
354 radius = myMarkerSize / 2.;
356 count = isShift ? mySelNumbers.count() : 0;
358 myUSelNumbers = mySelNumbers;
362 mySelNumbers.clear();
363 myCurSelNumbers.clear();
366 for ( int i = 0; i < myNumber; i++ )
368 xdist = ( myXCoord[i] - x ) * myXScale;
369 ydist = ( myYCoord[i] - y ) * myYScale;
371 //if ( isCircle && ( xdist * xdist + ydist * ydist <= radius * radius ) ||
372 if ( isCircle && ( xdist * xdist + ydist * ydist <= myMarkerSize * myMarkerSize ) ||
373 !isCircle && ( fabs( xdist ) <= radius && fabs( ydist ) <= radius ) )
378 bool isFound = FALSE;
379 for( it = mySelNumbers.begin(); it != mySelNumbers.end(); ++it )
382 myUSelNumbers.append( *it );
390 mySelNumbers.append( i );
391 myCurSelNumbers.append( i );
392 for ( it1 = myHNumbers.begin(); it1 != myHNumbers.end(); ++it1 )
395 myHNumbers.remove( it1 );
398 for ( it1 = myUHNumbers.begin(); it1 != myUHNumbers.end(); ++it1 )
401 myUHNumbers.remove( it1 );
407 mySelNumbers.remove( remIt );
408 for ( curIt = myCurSelNumbers.begin(); curIt != myCurSelNumbers.end(); ++curIt )
409 if( *curIt == *remIt)
411 myCurSelNumbers.remove( curIt );
414 for ( it1 = myHNumbers.begin(); it1 != myHNumbers.end(); ++it1 )
417 myHNumbers.remove( it1 );
420 for ( it1 = myUHNumbers.begin(); it1 != myUHNumbers.end(); ++it1 )
423 myUHNumbers.remove( it1 );
430 mySelNumbers.append( i );
431 myCurSelNumbers.append( i );
432 for ( it1 = myHNumbers.begin(); it1 != myHNumbers.end(); ++it1 )
435 myHNumbers.remove( it1 );
438 for ( it1 = myUHNumbers.begin(); it1 != myUHNumbers.end(); ++it1 )
441 myUHNumbers.remove( it1 );
448 for( it = mySelNumbers.begin(); it != mySelNumbers.end(); ++it )
449 for( it1 = myUSelNumbers.begin(); it1 != myUSelNumbers.end(); ++it1 )
452 it1 = myUSelNumbers.remove( it1 );
456 myIsSel = (GLboolean)count;
458 // cout << "GLViewer_MarkerSet::select complete with " << (int)myIsSel << endl;
462 GLboolean GLViewer_MarkerSet::unselect()
464 if( !mySelNumbers.isEmpty() )
466 myUSelNumbers = mySelNumbers;
467 mySelNumbers.clear();
468 myCurSelNumbers.clear();
475 GLViewer_Rect* GLViewer_MarkerSet::getUpdateRect()
477 GLViewer_Rect* rect = new GLViewer_Rect();
479 rect->setLeft( myRect->left() + myXGap - myMarkerSize / myXScale );
480 rect->setTop( myRect->top() + myYGap + myMarkerSize / myYScale );
481 rect->setRight( myRect->right() - myXGap + myMarkerSize / myXScale );
482 rect->setBottom( myRect->bottom() - myYGap - myMarkerSize / myYScale );
483 //cout << " Additional tolerance " << myMarkerSize / myYScale << endl;
484 //rect->setLeft( myRect->left() - myMarkerSize / myXScale );
485 //rect->setTop( myRect->top() - myMarkerSize / myYScale );
486 //rect->setRight( myRect->right() + myMarkerSize / myXScale );
487 //rect->setBottom( myRect->bottom() + myMarkerSize / myYScale );
493 void GLViewer_MarkerSet::setXCoord( GLfloat* xCoord, int size )
495 myXCoord = new GLfloat[ size ];
496 for( int i = 0; i < size; i++ )
497 myXCoord[i] = xCoord[i];
500 void GLViewer_MarkerSet::setYCoord( GLfloat* yCoord, int size )
502 myYCoord = new GLfloat[ size ];
503 for( int i = 0; i < size; i++ )
504 myYCoord[i] = yCoord[i];
507 void GLViewer_MarkerSet::setNumMarkers( GLint number )
509 if ( myNumber == number )
512 if ( myXCoord && myYCoord )
519 myXCoord = new GLfloat[ myNumber ];
520 myYCoord = new GLfloat[ myNumber ];
523 void GLViewer_MarkerSet::onSelectionDone( bool append)
525 mySelectedIndexes.Clear();
526 QValueList<int>::Iterator it;
527 //for( it = myMarkers->mySelNumbers.begin(); it != myMarkers->mySelNumbers.end(); ++it )
528 // mySelectedIndexes.Append( *it / 2 ); //!!!
530 emit dvMarkersSelected( mySelectedIndexes );
533 void GLViewer_MarkerSet::onSelectionCancel()
535 mySelectedIndexes.Clear();
536 emit dvMarkersSelected( mySelectedIndexes );
539 void GLViewer_MarkerSet::exportNumbers( QValueList<int>& highlight,
540 QValueList<int>& unhighlight,
541 QValueList<int>& select,
542 QValueList<int>& unselect )
544 highlight = myHNumbers;
545 unhighlight = myUHNumbers;
546 select = mySelNumbers;
547 unselect = myUSelNumbers;
549 myUHNumbers = myHNumbers;
552 bool GLViewer_MarkerSet::addOrRemoveSelected( int index )
554 if( index < 0 || index > myNumber )
557 int n = mySelNumbers.findIndex( index );
559 mySelNumbers.append( index );
562 QValueList<int>::Iterator it;
563 it = mySelNumbers.at( n );
564 mySelNumbers.remove( it );
565 myUSelNumbers.append( index );
570 void GLViewer_MarkerSet::addSelected( const TColStd_SequenceOfInteger& seq )
572 for ( int i = 1; i <= seq.Length(); i++ )
573 if( mySelNumbers.findIndex( seq.Value( i ) ) == -1 )
574 mySelNumbers.append( seq.Value( i ) - 1 );
577 void GLViewer_MarkerSet::setSelected( const TColStd_SequenceOfInteger& seq )
579 // for( QValueList<int>::Iterator it = mySelNumbers.begin(); it != mySelNumbers.end(); ++it )
580 // if( myUSelNumbers.findIndex( *it ) == -1 )
581 // myUSelNumbers.append( *it );
583 myUSelNumbers = mySelNumbers;
584 mySelNumbers.clear();
586 for ( int i = 1; i <= seq.Length(); i++ )
587 mySelNumbers.append( seq.Value( i ) - 1 );
590 void GLViewer_MarkerSet::moveObject( float theX, float theY, bool fromGroup )
592 if( !fromGroup && myGroup)
594 myGroup->dragingObjects( theX, theY );
597 for( int i = 0; i < myNumber; i++ )
599 myXCoord[i] = myXCoord[i] + theX;
600 myYCoord[i] = myYCoord[i] + theY;
605 QByteArray GLViewer_MarkerSet::getByteCopy()
608 int anISize = sizeof( GLint );
609 int aFSize = sizeof( GLfloat );
611 QByteArray aObject = GLViewer_Object::getByteCopy();
613 QByteArray aResult( anISize + 2*aFSize*myNumber + aFSize + aObject.size());
615 char* aPointer = (char*)&myNumber;
616 for( i = 0; i < anISize; i++, aPointer++ )
617 aResult[i] = *aPointer;
619 aPointer = (char*)myXCoord;
620 for( ; i < anISize + aFSize*myNumber; i++, aPointer++ )
621 aResult[i] = *aPointer;
622 aPointer = (char*)myYCoord;
623 for( ; i < anISize + 2*aFSize*myNumber; i++, aPointer++ )
624 aResult[i] = *aPointer;
626 aPointer = (char*)&myMarkerSize;
627 for( ; i < anISize + 2*aFSize*myNumber + aFSize; i++, aPointer++ )
628 aResult[i] = *aPointer;
631 for( ; i < aResult.size(); i++ )
632 aResult[i] = aObject[i - anISize - 2*aFSize*myNumber - aFSize];
637 bool GLViewer_MarkerSet::initializeFromByteCopy( QByteArray theArray )
640 int anISize = sizeof( GLint );
641 int aFSize = sizeof( GLfloat );
643 char* aPointer = (char*)&myNumber;
644 for( i = 0; i < anISize; i++, aPointer++ )
645 *aPointer = theArray[i];
647 int aSize = theArray.size();
648 if( aSize < anISize + 2*aFSize*myNumber + aFSize)
651 myXCoord = new GLfloat[myNumber];
652 myYCoord = new GLfloat[myNumber];
653 aPointer = (char*)myXCoord;
654 for( ; i < anISize + aFSize*myNumber; i++, aPointer++ )
655 *aPointer = theArray[i];
656 aPointer = (char*)myYCoord;
657 for( ; i < anISize + 2*aFSize*myNumber; i++, aPointer++ )
658 *aPointer = theArray[i];
660 aPointer = (char*)&myMarkerSize;
661 for( ; i < anISize + 2*aFSize*myNumber + aFSize; i++, aPointer++ )
662 *aPointer = theArray[i];
664 int aCurIndex = anISize + 2*aFSize*myNumber + aFSize;
665 QByteArray aObject( aSize - aCurIndex );
666 for( ; i < aSize; i++ )
667 aObject[i - aCurIndex] = theArray[i];
670 if( !GLViewer_Object::initializeFromByteCopy( aObject ) || myType != "GLViewer_MarkerSet" )
675 mySelNumbers.clear();
676 myUSelNumbers.clear();
677 myCurSelNumbers.clear();
678 myPrevHNumbers.clear();
683 /***************************************************************************
684 ** Class: GLViewer_Polyline
685 ** Descr: OpenGL Polyline
687 ** Created: UI team, 03.09.02
688 ****************************************************************************/
693 GLViewer_Polyline::GLViewer_Polyline( int number, float size, const QString& toolTip ):
699 myHighFlag = GL_TRUE;
703 mySelNumbers.clear();
704 myUSelNumbers.clear();
705 myCurSelNumbers.clear();
706 myPrevHNumbers.clear();
710 myType = "GLViewer_Polyline";
711 myToolTipText = toolTip;
714 GLViewer_Polyline::~GLViewer_Polyline()
722 bool GLViewer_Polyline::translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS )
724 QString aBuffer = "newpath\n";
726 AddLineAspectToPS( aBuffer, getAspectLine(), aViewerCS, aPSCS );
728 for( int i=0; i<myNumber; i++ )
730 AddCoordsToPS( aBuffer, "moveto", aViewerCS, aPSCS, myXCoord[i], myYCoord[i] );
732 AddCoordsToPS( aBuffer, "lineto", aViewerCS, aPSCS, myXCoord[i], myYCoord[i] );
735 AddCoordsToPS( aBuffer, "lineto", aViewerCS, aPSCS, myXCoord[0], myYCoord[0] );
737 aBuffer+="closepath\nstroke\n";
739 hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
744 bool GLViewer_Polyline::translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS )
746 QString aBuffer = "";
747 for( int i=0; i<myNumber; i++ )
749 AddCoordsToHPGL( aBuffer, "PA", aViewerCS, aHPGLCS, myXCoord[i], myYCoord[i] );
755 AddCoordsToHPGL( aBuffer, "PA", aViewerCS, aHPGLCS, myXCoord[0], myYCoord[0] );
759 hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
765 bool GLViewer_Polyline::translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS )
767 if( !aViewerCS || !aEMFCS )
770 HPEN pen = AddLineAspectToEMF( dc, getAspectLine(), aViewerCS, aEMFCS );
771 HGDIOBJ old = SelectObject( dc, pen );
774 for( int i=0; i<myNumber; i++ )
778 aViewerCS->transform( *aEMFCS, x, y );
780 MoveToEx( dc, x, y, NULL );
789 aViewerCS->transform( *aEMFCS, x, y );
793 SelectObject( dc, old );
801 void GLViewer_Polyline::compute()
803 // cout << "GLViewer_MarkerSet::compute" << endl;
804 GLfloat xa = myXCoord[0];
805 GLfloat xb = myXCoord[0];
806 GLfloat ya = myYCoord[0];
807 GLfloat yb = myYCoord[0];
809 for ( int i = 0; i < myNumber; i++ )
811 xa = QMIN( xa, myXCoord[i] );
812 xb = QMAX( xb, myXCoord[i] );
813 ya = QMIN( ya, myYCoord[i] );
814 yb = QMAX( yb, myYCoord[i] );
817 GLfloat xGap = ( xb - xa ) / 10;
818 GLfloat yGap = ( yb - ya ) / 10;
820 myRect->setLeft( xa - xGap );
821 myRect->setTop( yb + yGap );
822 myRect->setRight( xb + xGap );
823 myRect->setBottom( ya - yGap );
826 GLViewer_Rect* GLViewer_Polyline::getUpdateRect()
828 GLViewer_Rect* rect = new GLViewer_Rect();
830 rect->setLeft( myRect->left() - myXGap );
831 rect->setTop( myRect->top() + myYGap );
832 rect->setRight( myRect->right() + myXGap );
833 rect->setBottom( myRect->bottom() - myYGap );
838 GLViewer_Drawer* GLViewer_Polyline::createDrawer()
840 // cout << "GLViewer_MarkerSet::createDrawer" << endl;
841 return myDrawer = new GLViewer_PolylineDrawer();
844 GLboolean GLViewer_Polyline::highlight( GLfloat x, GLfloat y, GLfloat tol, GLboolean isCircle )
848 GLfloat xa, xb, ya, yb, l;
849 GLfloat rsin, rcos, r, ra, rb;
851 GLboolean highlighted = myIsHigh;
859 for( int i = 0; i < myNumber-1+c; i++ )
863 if( i != myNumber-1 )
874 l = sqrt( (xb-xa)*(xb-xa) + (yb-ya)*(yb-ya) );
877 r = ( (x-xa)*(y-yb) - (x-xb)*(y-ya) ) / ( rsin*(ya-yb) + rcos*(xa-xb) );
878 ra = sqrt( (x-xa)*(x-xa) + (y-ya)*(y-ya) );
879 rb = sqrt( (x-xb)*(x-xb) + (y-yb)*(y-yb) );
880 if( fabs( r ) * myXScale <= DISTANTION && ra <= l + DISTANTION && rb <= l + DISTANTION )
887 if( !myHighFlag && myIsHigh )
890 myHighFlag = GL_TRUE;
892 update = ( GLboolean )( myIsHigh != highlighted );
894 // cout << "GLViewer_Polyline::highlight complete with " << (int)myIsHigh << endl;
898 GLboolean GLViewer_Polyline::unhighlight()
900 // if( !myHNumbers.isEmpty() )
902 // myUHNumbers = myHNumbers;
903 // myHNumbers.clear();
916 GLboolean GLViewer_Polyline::select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect, GLboolean isFull,
917 GLboolean isCircle, GLboolean isShift )
921 GLfloat xa, xb, ya, yb, l;
922 GLfloat rsin, rcos, r, ra, rb;
924 GLboolean selected = myIsSel;
932 for( int i = 0; i < myNumber-1+c; i++ )
936 if( i != myNumber-1 )
947 l = sqrt( (xb-xa)*(xb-xa) + (yb-ya)*(yb-ya) );
950 r = ( (x-xa)*(y-yb) - (x-xb)*(y-ya) ) / ( rsin*(ya-yb) + rcos*(xa-xb) );
951 ra = sqrt( (x-xa)*(x-xa) + (y-ya)*(y-ya) );
952 rb = sqrt( (x-xb)*(x-xb) + (y-yb)*(y-yb) );
953 if( fabs( r ) * myXScale <= DISTANTION && ra <= l + DISTANTION && rb <= l + DISTANTION )
962 myHighFlag = GL_FALSE;
966 myHighFlag = GL_TRUE;
968 update = ( GLboolean )( myIsSel != selected );
970 // cout << "GLViewer_Polyline::select complete with " << (int)myIsSel << endl;
972 // return update; !!!!!!!!!!!!!!!!!!!!!!!!!!! no here
976 GLboolean GLViewer_Polyline::unselect()
978 // if( !mySelNumbers.isEmpty() )
980 // myUSelNumbers = mySelNumbers;
981 // mySelNumbers.clear();
982 // myCurSelNumbers.clear();
995 void GLViewer_Polyline::setXCoord( GLfloat* xCoord, int size )
997 myXCoord = new GLfloat[ size ];
998 for( int i = 0; i < size; i++ )
999 myXCoord[i] = xCoord[i];
1002 void GLViewer_Polyline::setYCoord( GLfloat* yCoord, int size )
1004 myYCoord = new GLfloat[ size ];
1005 for( int i = 0; i < size; i++ )
1006 myYCoord[i] = yCoord[i];
1009 void GLViewer_Polyline::setNumber( GLint number )
1011 if ( myNumber == number )
1014 if ( myXCoord && myYCoord )
1021 myXCoord = new GLfloat[ myNumber ];
1022 myYCoord = new GLfloat[ myNumber ];
1025 void GLViewer_Polyline::onSelectionDone( bool append)
1027 mySelectedIndexes.Clear();
1028 QValueList<int>::Iterator it;
1029 //for( it = myMarkers->mySelNumbers.begin(); it != myMarkers->mySelNumbers.end(); ++it )
1030 // mySelectedIndexes.Append( *it / 2 ); //!!!
1033 void GLViewer_Polyline::onSelectionCancel()
1035 mySelectedIndexes.Clear();
1038 void GLViewer_Polyline::exportNumbers( QValueList<int>& highlight,
1039 QValueList<int>& unhighlight,
1040 QValueList<int>& select,
1041 QValueList<int>& unselect )
1043 highlight = myHNumbers;
1044 unhighlight = myUHNumbers;
1045 select = mySelNumbers;
1046 unselect = myUSelNumbers;
1049 void GLViewer_Polyline::moveObject( float theX, float theY, bool fromGroup )
1051 if( !fromGroup && myGroup)
1053 myGroup->dragingObjects( theX, theY );
1056 for( int i = 0; i < myNumber; i++ )
1058 myXCoord[i] = myXCoord[i] + theX;
1059 myYCoord[i] = myYCoord[i] + theY;
1064 QByteArray GLViewer_Polyline::getByteCopy()
1067 int anISize = sizeof( GLint );
1068 int aFSize = sizeof( GLfloat );
1069 int aBSize = sizeof( GLboolean );
1071 QByteArray aObject = GLViewer_Object::getByteCopy();
1073 QByteArray aResult( aFSize*myNumber*2 + anISize + 2*aBSize + aObject.size());
1075 char* aPointer = (char*)&myNumber;
1076 for( i = 0; i < anISize; i++, aPointer++ )
1077 aResult[i] = *aPointer;
1079 aPointer = (char*)myXCoord;
1080 for( ; i < anISize + aFSize*myNumber; i++, aPointer++ )
1081 aResult[i] = *aPointer;
1082 aPointer = (char*)myYCoord;
1083 for( ; i < anISize + 2*aFSize*myNumber; i++, aPointer++ )
1084 aResult[i] = *aPointer;
1086 aPointer = (char*)&myIsClosed;
1087 for( ; i < anISize + 2*aFSize*myNumber + aBSize; i++, aPointer++ )
1088 aResult[i] = *aPointer;
1089 aPointer = (char*)&myHighSelAll;
1090 for( ; i < anISize + 2*aFSize*myNumber + 2*aBSize; i++, aPointer++ )
1091 aResult[i] = *aPointer;
1093 for( ; i < aResult.size(); i++ )
1094 aResult[i] = aObject[i - anISize - 2*aFSize*myNumber - 2*aBSize];
1100 bool GLViewer_Polyline::initializeFromByteCopy( QByteArray theArray )
1103 int anISize = sizeof( GLint );
1104 int aFSize = sizeof( GLfloat );
1105 int aBSize = sizeof( GLboolean );
1107 char* aPointer = (char*)&myNumber;
1108 for( i = 0; i < anISize; i++, aPointer++ )
1109 *aPointer = theArray[i];
1111 int aSize = theArray.size();
1112 if( aSize < aFSize*myNumber*2 + anISize + 2*aBSize )
1115 myXCoord = new GLfloat[myNumber];
1116 myYCoord = new GLfloat[myNumber];
1117 aPointer = (char*)myXCoord;
1118 for( ; i < anISize + aFSize*myNumber; i++, aPointer++ )
1119 *aPointer = theArray[i];
1120 aPointer = (char*)myYCoord;
1121 for( ; i < anISize + 2*aFSize*myNumber; i++, aPointer++ )
1122 *aPointer = theArray[i];
1124 aPointer = (char*)&myIsClosed;
1125 for( ; i < anISize + 2*aFSize*myNumber + aBSize; i++, aPointer++ )
1126 *aPointer = theArray[i];
1127 aPointer = (char*)&myHighSelAll;
1128 for( ; i < anISize + 2*aFSize*myNumber + 2*aBSize; i++, aPointer++ )
1129 *aPointer = theArray[i];
1131 int aCurIndex = anISize + 2*aFSize*myNumber + 2*aBSize;
1132 QByteArray aObject( aSize - aCurIndex );
1133 for( ; i < aSize; i++ )
1134 aObject[i - aCurIndex] = theArray[i];
1136 if( !GLViewer_Object::initializeFromByteCopy( aObject ) || myType != "GLViewer_Polyline" )
1140 myUHNumbers.clear();
1141 mySelNumbers.clear();
1142 myUSelNumbers.clear();
1143 myCurSelNumbers.clear();
1144 myPrevHNumbers.clear();
1149 /***************************************************************************
1150 ** Class: GLViewer_TextObject
1151 ** Descr: Text as Object for OpenGL
1153 ** Created: UI team, 12.02.04
1154 ****************************************************************************/
1156 GLViewer_TextObject::GLViewer_TextObject( const QString& theStr, float xPos, float yPos,
1157 const QColor& color, const QString& toolTip )
1160 myGLText = new GLViewer_Text( theStr, xPos, yPos, color );
1164 myHighFlag = GL_TRUE;
1166 myToolTipText = toolTip;
1168 GLViewer_TextObject::~GLViewer_TextObject()
1174 bool GLViewer_TextObject::translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS )
1176 QString aText = myGLText->getText();
1178 myGLText->getPosition( xPos, yPos );
1180 QString aBuffer = "/Times-Roman findfont\n";
1181 aBuffer += "12 scalefont setfont\n";
1183 AddCoordsToPS( aBuffer, "moveto", aViewerCS, aPSCS, double(xPos), double(yPos) );
1184 aBuffer += "(" + aText + ") show\n";
1186 hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
1191 bool GLViewer_TextObject::translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS )
1193 QString aText = myGLText->getText();
1195 myGLText->getPosition( xPos, yPos );
1197 QString aBuffer = "";
1198 AddCoordsToHPGL( aBuffer, "PA", aViewerCS, aHPGLCS, double(xPos), double(yPos) );
1200 aBuffer = "LB" + aText + "#;";
1202 hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
1208 bool GLViewer_TextObject::translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS )
1210 QString aText = myGLText->getText();
1212 myGLText->getPosition( xPos, yPos );
1214 double x = double( xPos ),
1217 aViewerCS->transform( *aEMFCS, x, y );
1218 const char* str = aText.ascii();
1220 int nHeight = 35*14; // height of font
1221 int nWidth = 35*12; // average character width
1222 int nEscapement = 0; // angle of escapement
1223 int nOrientation = 0; // base-line orientation angle
1224 int fnWeight = FW_NORMAL; // font weight
1225 DWORD fdwItalic = FALSE; // italic attribute option
1226 DWORD fdwUnderline = FALSE; // underline attribute option
1227 DWORD fdwStrikeOut = FALSE; // strikeout attribute option
1228 DWORD fdwCharSet = ANSI_CHARSET; // character set identifier
1229 DWORD fdwOutputPrecision = OUT_DEFAULT_PRECIS; // output precision
1230 DWORD fdwClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
1231 DWORD fdwQuality = PROOF_QUALITY; // output quality
1232 DWORD fdwPitchAndFamily = FIXED_PITCH | FF_DONTCARE; // pitch and family
1233 LPCTSTR lpszFace = NULL; // typeface name
1236 HFONT aFont = CreateFont( nHeight, nWidth, nEscapement, nOrientation, fnWeight, fdwItalic,
1237 fdwUnderline, fdwStrikeOut, fdwCharSet, fdwOutputPrecision,
1238 fdwClipPrecision, fdwQuality, fdwPitchAndFamily, lpszFace );
1239 LOGBRUSH aBrushData;
1240 aBrushData.lbStyle = BS_HOLLOW;
1242 HBRUSH aBrush = CreateBrushIndirect( &aBrushData );
1244 HGDIOBJ old1 = SelectObject( dc, aFont );
1245 HGDIOBJ old2 = SelectObject( dc, aBrush );
1247 TextOut( dc, x, y, str, aText.length() );
1249 SelectObject ( dc, old1 );
1250 SelectObject ( dc, old2 );
1252 DeleteObject( aFont );
1258 GLViewer_Drawer* GLViewer_TextObject::createDrawer()
1260 myDrawer = new GLViewer_TextDrawer();
1265 void GLViewer_TextObject::compute()
1268 QString aStr = myGLText->getText();
1269 myGLText->getPosition( xPos, yPos );
1271 myWidth = myGLText->getWidth();
1272 myHeight = myGLText->getHeight();
1273 myRect->setLeft( xPos );
1274 myRect->setTop( yPos + myHeight );
1275 myRect->setRight( xPos + myWidth );
1276 myRect->setBottom( yPos );
1279 void GLViewer_TextObject::setDrawer( GLViewer_Drawer* theDrawer )
1281 myDrawer = theDrawer;
1285 GLViewer_Rect* GLViewer_TextObject::getUpdateRect()
1287 GLViewer_Rect* rect = new GLViewer_Rect();
1290 QString aStr = myGLText->getText();
1291 myGLText->getPosition( xPos, yPos );
1293 rect->setLeft( myRect->left() + myXGap - myWidth / myXScale );
1294 rect->setTop( myRect->top() + myYGap + myHeight / myYScale );
1295 rect->setRight( myRect->right() - myXGap + myWidth / myXScale );
1296 rect->setBottom( myRect->bottom() - myYGap - myHeight / myYScale );
1301 GLboolean GLViewer_TextObject::highlight( GLfloat theX, GLfloat theY, GLfloat theTol, GLboolean isCircle )
1307 myGLText->getPosition( xPos, yPos );
1310 aRect.setLeft( (int)xPos );
1311 aRect.setRight( (int)(xPos + myWidth / myXScale) );
1312 aRect.setTop( (int)yPos );// - myHeight / myYScale );
1313 aRect.setBottom( (int)(yPos + myHeight / myYScale) );
1315 //cout << "theX: " << theX << " theY: " << theY << endl;
1316 //cout << "aRect.left(): " << aRect.left() << " aRect.right(): " << aRect.right() << endl;
1317 //cout << "aRect.top(): " << aRect.top() << " aRect.bottom(): " << aRect.bottom() << endl;
1319 QRegion obj( aRect );
1320 QRegion intersection;
1323 region.setLeft( (int)(theX - theTol) );
1324 region.setRight( (int)(theX + theTol) );
1325 region.setTop( (int)(theY - theTol) );
1326 region.setBottom( (int)(theY + theTol) );
1328 QRegion circle( (int)(theX - theTol), (int)(theY - theTol),
1329 (int)(2 * theTol), (int)(2 * theTol), QRegion::Ellipse );
1331 intersection = obj.intersect( circle );
1333 intersection = obj.intersect( region );
1335 if( intersection.isEmpty() )
1340 if( !myHighFlag && myIsHigh )
1341 myIsHigh = GL_FALSE;
1343 myHighFlag = GL_TRUE;
1348 GLboolean GLViewer_TextObject::unhighlight()
1352 myIsHigh = GL_FALSE;
1359 GLboolean GLViewer_TextObject::select( GLfloat theX, GLfloat theY, GLfloat theTol, GLViewer_Rect rect,
1360 GLboolean isFull, GLboolean isCircle, GLboolean isShift )
1365 QRegion obj( myRect->toQRect() );
1366 QRegion intersection;
1369 region.setLeft( (int)(theX - theTol) );
1370 region.setRight( (int)(theX + theTol) );
1371 region.setTop( (int)(theY - theTol) );
1372 region.setBottom( (int)(theY + theTol) );
1374 QRegion circle( (int)(theX - theTol), (int)(theY - theTol),
1375 (int)(2 * theTol), (int)(2 * theTol), QRegion::Ellipse );
1377 intersection = obj.intersect( circle );
1379 intersection = obj.intersect( region );
1381 if( intersection.isEmpty() )
1388 myHighFlag = GL_FALSE;
1389 myIsHigh = GL_FALSE;
1392 myHighFlag = GL_TRUE;
1397 GLboolean GLViewer_TextObject::unselect()
1408 void GLViewer_TextObject::moveObject( float theX, float theY, bool fromGroup )
1410 if( !fromGroup && myGroup)
1412 myGroup->dragingObjects( theX, theY );
1416 myGLText->getPosition( aX, anY );
1419 myGLText->setPosition( aX, anY );
1423 QByteArray GLViewer_TextObject::getByteCopy()
1425 QByteArray aObject = GLViewer_Object::getByteCopy();
1430 bool GLViewer_TextObject::initializeFromByteCopy( QByteArray theArray )
1432 if( !GLViewer_Object::initializeFromByteCopy( theArray ) || myType != "GLViewer_TextObject" )