1 // File: GLViewer_Object.cxx
2 // Created: November, 2004
4 // Copyright (C) CEA 2004
6 /***************************************************************************
7 ** Class: GLViewer_Object
8 ** Descr: OpenGL Object
10 ** Created: UI team, 02.09.02
11 ****************************************************************************/
13 #include "GLViewer_Object.h"
14 #include "GLViewer_Drawer.h"
16 #include "GLViewer_Group.h"
18 #include <qfontmetrics.h>
19 #include <qstringlist.h>
24 #define CONSTANT_FOR_RECT 10
26 /***************************************************************************
27 ** Class: GLViewer_Text
28 ** Descr: Substitution of Prs3d_Text for OpenGL
30 ** Created: UI team, 10.07.03
31 ****************************************************************************/
33 GLViewer_Text::GLViewer_Text( const QString& text, float xPos, float yPos, const QColor& color )
39 myQFont = QFont::defaultFont();
44 GLViewer_Text::GLViewer_Text( const QString& text, float xPos, float yPos, const QColor& color, QFont theFont, int theSeparator )
51 mySeparator = theSeparator;
55 GLViewer_Text::~GLViewer_Text()
59 int GLViewer_Text::getWidth()
62 QFontMetrics aFM( myQFont );
63 for( int i = 0; i < myText.length(); i++ )
64 aResult += aFM.width( myText[i] ) + mySeparator;
68 int GLViewer_Text::getHeight()
70 QFontMetrics aFM( myQFont );
74 QByteArray GLViewer_Text::getByteCopy() const
77 int aSize = 5*sizeof( int ) + myText.length();
79 int aR = myColor.red();
80 int aG = myColor.green();
81 int aB = myColor.blue();
82 const char* aStr = myText.data();
84 int anISize = sizeof( int );
85 QByteArray aResult( aSize );
87 char* aPointer = (char*)&myXPos;
88 for( i = 0; i < anISize; i++, aPointer++ )
89 aResult[i] = *aPointer;
90 aPointer = (char*)&myYPos;
91 for( ; i < 2*anISize; i++, aPointer++ )
92 aResult[i] = *aPointer;
94 aPointer = (char*)&aR;
95 for( ; i < 3*anISize; i++, aPointer++ )
96 aResult[i] = *aPointer;
97 aPointer = (char*)&aG;
98 for( ; i < 4*anISize; i++, aPointer++ )
99 aResult[i] = *aPointer;
100 aPointer = (char*)&aB;
101 for( ; i < 5*anISize; i++, aPointer++ )
102 aResult[i] = *aPointer;
104 int aTextSize = myText.length();
105 aPointer = (char*)&aTextSize;
106 for( ; i < 6*anISize; i++, aPointer++ )
107 aResult[i] = *aPointer;
109 for( i = 0; i < aTextSize; i++ )
110 aResult[6*anISize + i] = aStr[i];
112 aPointer = (char*)&mySeparator;
113 for( ; i < 7*anISize + aTextSize; i++, aPointer++ )
114 aResult[i] = *aPointer;
116 const char* aFontStr = myQFont.toString().data();
117 int aFontSize = myQFont.toString().length();
119 for( i = 0; i < aFontSize; i++ )
120 aResult[7*anISize + aTextSize + i] = aFontStr[i];
125 GLViewer_Text* GLViewer_Text::fromByteCopy( QByteArray theBuf )
128 int aSize = (int)theBuf.size();
129 int aR = 0, aG = 0, aB = 0;
131 int xPos = 0, yPos = 0;
133 int anISize = sizeof( int );
134 char* aPointer = (char*)&xPos;
135 for ( i = 0; i < anISize; i++, aPointer++ )
136 *aPointer = theBuf[i];
138 aPointer = (char*)&yPos;
139 for ( ; i < 2*anISize; i++, aPointer++ )
140 *aPointer = theBuf[i];
142 aPointer = (char*)&aR;
143 for( ; i < 3*anISize; i++, aPointer++ )
144 *aPointer = theBuf[i];
145 aPointer = (char*)&aG;
146 for( ; i < 4*anISize; i++, aPointer++ )
147 *aPointer = theBuf[i];
148 aPointer = (char*)&aB;
149 for( ; i < 5*anISize; i++, aPointer++ )
150 *aPointer = theBuf[i];
153 aPointer = (char*)&aTextSize;
154 for( ; i < 6*anISize; i++, aPointer++ )
155 *aPointer = theBuf[i];
158 for( ; i < 6*anISize + aTextSize; i++ )
160 QChar aChar( theBuf[i] );
165 aPointer = (char*)&aSeparator;
166 for( ; i < 7*anISize + aTextSize; i++, aPointer++ )
167 *aPointer = theBuf[i];
170 for( ; i < aSize; i++ )
172 QChar aChar( theBuf[i] );
177 if( !aFont.fromString( aFontStr ) )
180 GLViewer_Text* aGlText = new GLViewer_Text( aText, xPos, yPos, QColor( aR,aG,aB ), aFont, aSeparator );
185 /***************************************************************************
186 ** Class: GLViewer_CoordSystem
189 ** Created: UI team, 03.09.02
190 ****************************************************************************/
192 GLViewer_CoordSystem::GLViewer_CoordSystem( CSType aType, double X0, double Y0,
193 double XUnit, double YUnit, double Rotation )
197 setUnits( XUnit, YUnit );
198 setRotation( Rotation );
201 void GLViewer_CoordSystem::getOrigin( double& x, double& y ) const
207 void GLViewer_CoordSystem::setOrigin( double x, double y )
213 void GLViewer_CoordSystem::getUnits( double& x, double& y ) const
219 void GLViewer_CoordSystem::setUnits( double x, double y )
232 double GLViewer_CoordSystem::getRotation() const
237 void GLViewer_CoordSystem::setRotation( double rotation )
239 myRotation = rotation;
242 GLViewer_CoordSystem::CSType GLViewer_CoordSystem::getType() const
247 void GLViewer_CoordSystem::setType( CSType type )
252 void GLViewer_CoordSystem::toReference( double& x, double& y )
254 if( myType==Cartesian )
256 double newx = myX0 + myXUnit*x*cos(myRotation) - myYUnit*y*sin(myRotation),
257 newy = myY0 + myXUnit*x*sin(myRotation) + myYUnit*y*cos(myRotation);
261 else if( myType==Polar )
263 double r = x, phi = y;
264 x = myX0 + myXUnit*r*cos(phi+myRotation);
265 y = myY0 + myXUnit*r*sin(phi+myRotation);
269 void GLViewer_CoordSystem::fromReference( double& x, double& y )
271 x = (x - myX0) / myXUnit;
272 y = (y - myY0) / myYUnit;
274 if( myType==Cartesian )
276 double newx = x*cos(myRotation) + y*sin(myRotation),
277 newy = -x*sin(myRotation) + y*cos(myRotation);
281 else if( myType==Polar )
283 double r = sqrt( x*x+y*y );
285 double eps = 1E-8, pi = 3.14159265;
292 if( x<0 ) // 2-nd or 4-rd quarter
305 void GLViewer_CoordSystem::transform( GLViewer_CoordSystem& aSystem, double& x, double& y )
308 aSystem.fromReference( x, y );
311 void GLViewer_CoordSystem::getStretching( GLViewer_CoordSystem& aSystem, double& theX, double& theY )
313 theX = myXUnit / aSystem.myXUnit;
314 theY = myYUnit / aSystem.myYUnit;
317 /***************************************************************************
318 ** Class: GLViewer_Object
319 ** Descr: OpenGL Object
321 ** Created: UI team, 03.09.02
322 ****************************************************************************/
323 GLViewer_Object::GLViewer_Object()
334 myRect = new GLViewer_Rect();
335 myGLText = new GLViewer_Text( 0, 0, 0, QColor(0,0,0) );
337 myAspectLine = new GLViewer_AspectLine();
338 myType = "GLViewer_Object";
345 isToolTipHTML = false;
350 GLViewer_Object::~GLViewer_Object()
362 GLboolean GLViewer_Object::isInside( GLViewer_Rect theRect )
364 return theRect.toQRect()->contains( *(myRect->toQRect()) );
367 GLboolean GLViewer_Object::setZoom( GLfloat zoom, GLboolean )
376 GLboolean GLViewer_Object::updateZoom( bool zoomIn )
379 float step = zoomIn ? 1 : -1;
380 double epsilon = 0.001;
382 if( myZoom - 1 > epsilon )
383 newZoom = ( myZoom * 2 + step ) / 2;
384 else if( 1 - myZoom > epsilon )
385 newZoom = 2 / ( 2 / myZoom - step );
387 newZoom = zoomIn ? 3./2. : 2./3.;
389 if( newZoom < 0.01 || newZoom > 100.0 )
392 setZoom( newZoom, GL_TRUE );
396 QByteArray GLViewer_Object::getByteCopy()
399 int anISize = sizeof( int );
400 int aFSize = sizeof( GLfloat );
402 int aLeft = (int)myRect->left(),
403 aTop = (int)myRect->top(),
404 aRight = (int)myRect->right(),
405 aBottom = (int)myRect->bottom();
407 const char* aTypeStr = myType.data();
408 const char* aToolTipStr = myToolTipText.data();
410 int aTypeLength = myType.length();
411 int aToolTipLength = myToolTipText.length();
414 QByteArray aGLText = myGLText->getByteCopy();
415 QByteArray aAspect = myAspectLine->getByteCopy();
417 QByteArray aResult( 2*anISize + 8*aFSize +
418 aTypeLength + aToolTipLength +
419 aGLText.size() + aAspect.size() );
421 char* aPointer = (char*)&aLeft;
422 for( i = 0; i < aFSize; i++, aPointer++ )
423 aResult[i] = *aPointer;
424 aPointer = (char*)&aTop;
425 for( ; i < 2*aFSize; i++, aPointer++ )
426 aResult[i] = *aPointer;
427 aPointer = (char*)&aRight;
428 for( ; i < 3*aFSize; i++, aPointer++ )
429 aResult[i] = *aPointer;
430 aPointer = (char*)&aBottom;
431 for( ; i < 4*aFSize; i++, aPointer++ )
432 aResult[i] = *aPointer;
434 aPointer = (char*)&myXScale;
435 for( ; i < 5*aFSize; i++, aPointer++ )
436 aResult[i] = *aPointer;
437 aPointer = (char*)&myYScale;
438 for( ; i < 6*aFSize; i++, aPointer++ )
439 aResult[i] = *aPointer;
440 aPointer = (char*)&myXGap;
441 for( ; i < 7*aFSize; i++, aPointer++ )
442 aResult[i] = *aPointer;
443 aPointer = (char*)&myYGap;
444 for( ; i < 8*aFSize; i++, aPointer++ )
445 aResult[i] = *aPointer;
447 aPointer = (char*)&aTypeLength;
448 for( ; i < anISize + 8*aFSize; i++, aPointer++ )
449 aResult[i] = *aPointer;
450 for( ; i < anISize + 8*aFSize + aTypeLength; i++ )
451 aResult[i] = aTypeStr[i - anISize - 8*aFSize ];
453 aPointer = (char*)&aToolTipLength;
454 for( ; i < 2*anISize + 8*aFSize + aTypeLength; i++, aPointer++ )
455 aResult[i] = *aPointer;
456 for( ; i < 2*anISize + 8*aFSize + aTypeLength + aToolTipLength; i++ )
457 aResult[ i] = aToolTipStr[i - 2*anISize - 8*aFSize - aTypeLength];
459 int aCurPos = 2*anISize + 8*aFSize + aTypeLength + aToolTipLength;
461 for( i = aCurPos; i < aCurPos + aAspect.size(); i++ )
462 aResult[i] = aAspect[i - aCurPos];
464 aCurPos = aCurPos + aAspect.size();
466 for( i = aCurPos; i < aCurPos + aGLText.size(); i++ )
467 aResult[i] = aGLText[i - aCurPos];
469 aCurPos += aGLText.size();
471 aPointer = (char*)&myOwner;
472 for( i = 0; i < sizeof( GLViewer_Owner* ); i++, aPointer++ )
473 aResult[ aCurPos+i ] = *aPointer;
478 bool GLViewer_Object::initializeFromByteCopy( QByteArray theArray )
481 int anISize = sizeof( int );
482 int aFSize = sizeof( GLfloat );
484 int aLeft = 0, aTop = 0, aRight = 0, aBottom = 0;
486 //QString aTypeStr, aToolTipStr;
487 int aTypeLength = 0, aToolTipLength = 0;
489 int aSize = theArray.size();
491 GLViewer_Text* aGLText = new GLViewer_Text( 0, 0, 0, QColor(255,255,255));
492 int aGLTextMinSize = (aGLText->getByteCopy()).size();
493 GLViewer_AspectLine* aAspectLine = new GLViewer_AspectLine();
494 int aGLAspLineSize = (aAspectLine->getByteCopy()).size();
496 QByteArray aGLTextArray, aAspect( aGLAspLineSize );
498 if( aSize < 2*anISize + 8*aFSize + aGLTextMinSize + aGLAspLineSize )
501 char* aPointer = (char*)&aLeft;
502 for( i = 0; i < aFSize; i++, aPointer++ )
503 *aPointer = theArray[i];
504 aPointer = (char*)&aTop;
505 for( ; i < 2*aFSize; i++, aPointer++ )
506 *aPointer = theArray[i];
507 aPointer = (char*)&aRight;
508 for( ; i < 3*aFSize; i++, aPointer++ )
509 *aPointer = theArray[i];
510 aPointer = (char*)&aBottom;
511 for( ; i < 4*aFSize; i++, aPointer++ )
512 *aPointer = theArray[i];
514 //myRect = new QRect( aLeft, aTop, aRight - aLeft, aBottom - aTop );
515 myRect = new GLViewer_Rect( aLeft, aRight, aTop, aBottom );
517 aPointer = (char*)&myXScale;
518 for( ; i < 5*aFSize; i++, aPointer++ )
519 *aPointer = theArray[i];
520 aPointer = (char*)&myYScale;
521 for( ; i < 6*aFSize; i++, aPointer++ )
522 *aPointer = theArray[i];
523 aPointer = (char*)&myXGap;
524 for( ; i < 7*aFSize; i++, aPointer++ )
525 *aPointer = theArray[i];
526 aPointer = (char*)&myYGap;
527 for( ; i < 8*aFSize; i++, aPointer++ )
528 *aPointer = theArray[i];
534 aPointer = (char*)&aTypeLength;
535 for( ; i < anISize + 8*aFSize; i++, aPointer++ )
536 *aPointer = theArray[i];
538 for( ; i < anISize + 8*aFSize + aTypeLength; i++ )
540 QChar aChar( theArray[i] );
544 aPointer = (char*)&aToolTipLength;
545 for( ; i < 2*anISize + 8*aFSize + aTypeLength; i++, aPointer++ )
546 *aPointer = theArray[i];
548 for( ; i < 2*anISize + 8*aFSize + aTypeLength + aToolTipLength; i++ )
550 QChar aChar( theArray[i] );
551 myToolTipText += aChar;
554 int aCurPos = 2*anISize + 8*aFSize + aTypeLength + aToolTipLength;
555 if( aSize - aCurPos < aGLTextMinSize + aGLAspLineSize )
558 for( i = 0; i < aGLAspLineSize; i++ )
559 aAspect[i] = theArray[ aCurPos + i ];
560 myAspectLine = GLViewer_AspectLine::fromByteCopy( aAspect );
562 aCurPos = aCurPos + aGLAspLineSize;
563 aGLTextArray.resize( aSize - aCurPos );
564 for( i = 0; i + aCurPos < aSize; i++ )
565 aGLTextArray[i] = theArray[ aCurPos + i ];
566 // replace gl_text pointer by other
569 myGLText = GLViewer_Text::fromByteCopy( aGLTextArray );
572 /*aCurPos += aSize - aCurPos;
573 aPointer = (char*)&myOwner;
574 for( i = 0; i < sizeof( GLViewer_Owner* ); i++, aPointer++ )
575 *aPointer = theArray[ aCurPos + i ];*/
580 void GLViewer_Object::setGroup( GLViewer_Group* theGroup )
583 myGroup->removeObject( this );
587 myGroup->addObject( this );
590 GLViewer_Group* GLViewer_Object::getGroup() const
595 GLViewer_Owner* GLViewer_Object::owner() const
600 void GLViewer_Object::setOwner( GLViewer_Owner* owner )
606 /***************************************************************************
607 ** Class: GLViewer_MarkerSet
608 ** Descr: OpenGL MarkerSet
610 ** Created: UI team, 03.09.02
611 ****************************************************************************/
613 GLViewer_MarkerSet::GLViewer_MarkerSet( int number, float size, const QString& toolTip ) :
614 GLViewer_Object(), myNumber( 0 ), myXCoord( 0 ), myYCoord( 0 )
619 mySelNumbers.clear();
620 myUSelNumbers.clear();
621 myCurSelNumbers.clear();
622 myPrevHNumbers.clear();
624 myType = "GLViewer_MarkerSet";
625 myToolTipText = toolTip;
627 setNumMarkers( number );
630 GLViewer_MarkerSet::~GLViewer_MarkerSet()
642 void AddCoordsToHPGL( QString& buffer, QString command, GLViewer_CoordSystem* aViewerCS,
643 GLViewer_CoordSystem* aPaperCS, double x, double y, bool NewLine = true )
645 if( aViewerCS && aPaperCS )
646 aViewerCS->transform( *aPaperCS, x, y );
648 QString temp = command + "%1, %2;";
649 buffer += temp.arg( x ).arg( y );
654 void AddCoordsToPS( QString& buffer, QString command, GLViewer_CoordSystem* aViewerCS,
655 GLViewer_CoordSystem* aPaperCS, double x, double y, bool NewLine = true )
657 if( aViewerCS && aPaperCS )
658 aViewerCS->transform( *aPaperCS, x, y );
660 QString temp = "%1 %2 "+command;
661 buffer += temp.arg( x ).arg( y );
666 void AddLineAspectToPS( QString& buffer, GLViewer_AspectLine* anAspect,
667 GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPaperCS )
671 QColor col1, col2, col3;
672 anAspect->getLineColors( col1, col2, col3 );
674 float aWidth = anAspect->getLineWidth();
675 int aLineType = anAspect->getLineType();
677 QString temp = "%1 %2 %3 setrgbcolor\n";
678 double rr = 1 - double( col1.red() ) / 255.0, //color inverting
679 gg = 1 - double( col1.green() ) / 255.0,
680 bb = 1 - double( col1.blue() ) / 255.0;
682 buffer += temp.arg( rr ).arg( gg ).arg( bb );
684 double x_stretch, y_stretch;
685 aViewerCS->getStretching( *aPaperCS, x_stretch, y_stretch );
686 buffer += temp.arg( x_stretch * aWidth )+" setlinewidth\n";
688 if( aLineType==0 ) //solid
689 buffer += "[] 0 setdash\n";
690 else if( aLineType==1 ) //strip
691 buffer += "[2] 0 setdash\n";
696 HPEN AddLineAspectToEMF( HDC hDC, GLViewer_AspectLine* anAspect,
697 GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPaperCS )
701 QColor col1, col2, col3;
702 anAspect->getLineColors( col1, col2, col3 );
704 double x_stretch, y_stretch;
705 aViewerCS->getStretching( *aPaperCS, x_stretch, y_stretch );
707 double aWidth = anAspect->getLineWidth()*x_stretch;
708 int aLineType = anAspect->getLineType();
710 return CreatePen( PS_SOLID, aWidth, RGB( 255-col1.red(), 255-col1.green(), 255-col1.blue() ) );
717 bool GLViewer_MarkerSet::translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS )
721 QString aBuffer = "newpath\n";
723 AddLineAspectToPS( aBuffer, getAspectLine(), aViewerCS, aPSCS );
725 for( int i=0; i<myNumber; i++ )
729 double x_stretch, y_stretch;
730 aViewerCS->getStretching( *aPSCS, x_stretch, y_stretch );
732 double x0 = myXCoord[i],
737 for( int j=0; j<=noPoints; j++ )
739 x = x0 + r*cos( double(j)*2*PI/double(noPoints) );
740 y = y0 + r*sin( double(j)*2*PI/double(noPoints) );
742 AddCoordsToPS( aBuffer, "moveto", aViewerCS, aPSCS, x, y, true );
744 AddCoordsToPS( aBuffer, "lineto", aViewerCS, aPSCS, x, y, true );
747 aBuffer+="closepath\nstroke\n";
749 hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
754 bool GLViewer_MarkerSet::translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS,
755 GLViewer_CoordSystem* aHPGLCS )
759 for( int i=0; i<myNumber; i++ )
763 double x_stretch, y_stretch;
764 aViewerCS->getStretching( *aHPGLCS, x_stretch, y_stretch );
766 double x0 = myXCoord[i],
771 AddCoordsToHPGL( aBuffer, "PA", aViewerCS, aHPGLCS, x0+r, y0 );
773 for( int j=1; j<=noPoints; j++ )
775 x = x0 + r*cos( double(j)*2*PI/double(noPoints) );
776 y = y0 + r*sin( double(j)*2*PI/double(noPoints) );
777 AddCoordsToHPGL( aBuffer, "PD", aViewerCS, aHPGLCS, x, y );
781 hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
788 bool GLViewer_MarkerSet::translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS )
791 if( !aViewerCS || !aEMFCS )
794 HPEN pen = AddLineAspectToEMF( dc, getAspectLine(), aViewerCS, aEMFCS );
795 HGDIOBJ old = SelectObject( dc, pen );
797 for( int i=0; i<myNumber; i++ )
799 double x0 = myXCoord[i],
804 for( int j=0; j<=noPoints; j++ )
806 x = x0 + r*cos( double(j)*2*PI/double(noPoints) );
807 y = y0 + r*sin( double(j)*2*PI/double(noPoints) );
808 aViewerCS->transform( *aEMFCS, x, y );
810 MoveToEx( dc, x, y, NULL );
816 SelectObject( dc, old );
824 void GLViewer_MarkerSet::compute()
826 // cout << "GLViewer_MarkerSet::compute" << endl;
827 GLfloat xa = myXCoord[0];
828 GLfloat xb = myXCoord[0];
829 GLfloat ya = myYCoord[0];
830 GLfloat yb = myYCoord[0];
832 for ( int i = 0; i < myNumber; i++ )
834 xa = QMIN( xa, myXCoord[i] );
835 xb = QMAX( xb, myXCoord[i] );
836 ya = QMIN( ya, myYCoord[i] );
837 yb = QMAX( yb, myYCoord[i] );
840 myXGap = ( xb - xa ) / CONSTANT_FOR_RECT;
841 myYGap = ( yb - ya ) / CONSTANT_FOR_RECT;
843 myRect->setLeft( xa - myXGap );
844 myRect->setTop( yb + myYGap );
845 myRect->setRight( xb + myXGap );
846 myRect->setBottom( ya - myYGap );
849 GLViewer_Drawer* GLViewer_MarkerSet::createDrawer()
851 // cout << "GLViewer_MarkerSet::createDrawer" << endl;
852 return myDrawer = new GLViewer_MarkerDrawer();
856 GLboolean GLViewer_MarkerSet::highlight( GLfloat x, GLfloat y, GLfloat tol, GLboolean isCircle )
860 // cout << "GLViewer_MarkerSet::highlight " << x <<" " << y << " " << tol << endl;
862 GLfloat xdist, ydist, radius;
863 QValueList<int>::Iterator it;
864 QValueList<int> curHNumbers;
869 radius = tol - myMarkerSize / 2.;
871 myUHNumbers += myHNumbers;
874 for ( int i = 0; i < myNumber; i++ )
876 xdist = ( myXCoord[i] - x ) * myXScale;
877 ydist = ( myYCoord[i] - y ) * myYScale;
879 // if ( isCircle && ( xdist * xdist + ydist * ydist <= radius * radius ) ||
880 if ( isCircle && ( xdist * xdist + ydist * ydist <= myMarkerSize * myMarkerSize ) ||
881 !isCircle && ( abs( xdist ) <= radius && abs( ydist ) <= radius ) )
885 for ( it = myCurSelNumbers.begin(); it != myCurSelNumbers.end(); ++it )
889 curHNumbers.append( i );
893 myHNumbers.append( i );
898 myCurSelNumbers = curHNumbers;
900 myIsHigh = ( GLboolean )count;
901 update = ( GLboolean )( myHNumbers != myPrevHNumbers );
903 myPrevHNumbers = myHNumbers;
905 //cout << "GLViewer_MarkerSet::highlight complete with " << (int)myIsHigh << endl;
909 GLboolean GLViewer_MarkerSet::unhighlight()
911 if( !myHNumbers.isEmpty() )
913 myUHNumbers += myHNumbers;
914 myPrevHNumbers.clear();
916 //??? myCurSelNumbers.clear();
923 GLboolean GLViewer_MarkerSet::select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect, GLboolean isFull,
924 GLboolean isCircle, GLboolean isShift )
928 // cout << "GLViewer_MarkerSet::select " << x << " " << y << endl;
930 GLfloat xdist, ydist, radius;
931 QValueList<int>::Iterator it;
932 QValueList<int>::Iterator it1;
933 QValueList<int>::Iterator remIt;
934 QValueList<int>::Iterator curIt;
936 radius = tol - myMarkerSize / 2.;
938 if( radius < myMarkerSize / 2.)
939 radius = myMarkerSize / 2.;
941 count = isShift ? mySelNumbers.count() : 0;
943 myUSelNumbers = mySelNumbers;
947 mySelNumbers.clear();
948 myCurSelNumbers.clear();
951 for ( int i = 0; i < myNumber; i++ )
953 xdist = ( myXCoord[i] - x ) * myXScale;
954 ydist = ( myYCoord[i] - y ) * myYScale;
956 //if ( isCircle && ( xdist * xdist + ydist * ydist <= radius * radius ) ||
957 if ( isCircle && ( xdist * xdist + ydist * ydist <= myMarkerSize * myMarkerSize ) ||
958 !isCircle && ( abs( xdist ) <= radius && abs( ydist ) <= radius ) )
963 bool isFound = FALSE;
964 for( it = mySelNumbers.begin(); it != mySelNumbers.end(); ++it )
967 myUSelNumbers.append( *it );
975 mySelNumbers.append( i );
976 myCurSelNumbers.append( i );
977 for ( it1 = myHNumbers.begin(); it1 != myHNumbers.end(); ++it1 )
980 myHNumbers.remove( it1 );
983 for ( it1 = myUHNumbers.begin(); it1 != myUHNumbers.end(); ++it1 )
986 myUHNumbers.remove( it1 );
992 mySelNumbers.remove( remIt );
993 for ( curIt = myCurSelNumbers.begin(); curIt != myCurSelNumbers.end(); ++curIt )
994 if( *curIt == *remIt)
996 myCurSelNumbers.remove( curIt );
999 for ( it1 = myHNumbers.begin(); it1 != myHNumbers.end(); ++it1 )
1002 myHNumbers.remove( it1 );
1005 for ( it1 = myUHNumbers.begin(); it1 != myUHNumbers.end(); ++it1 )
1008 myUHNumbers.remove( it1 );
1015 mySelNumbers.append( i );
1016 myCurSelNumbers.append( i );
1017 for ( it1 = myHNumbers.begin(); it1 != myHNumbers.end(); ++it1 )
1020 myHNumbers.remove( it1 );
1023 for ( it1 = myUHNumbers.begin(); it1 != myUHNumbers.end(); ++it1 )
1026 myUHNumbers.remove( it1 );
1033 for( it = mySelNumbers.begin(); it != mySelNumbers.end(); ++it )
1034 for( it1 = myUSelNumbers.begin(); it1 != myUSelNumbers.end(); ++it1 )
1037 it1 = myUSelNumbers.remove( it1 );
1041 myIsSel = (GLboolean)count;
1043 // cout << "GLViewer_MarkerSet::select complete with " << (int)myIsSel << endl;
1047 GLboolean GLViewer_MarkerSet::unselect()
1049 if( !mySelNumbers.isEmpty() )
1051 myUSelNumbers = mySelNumbers;
1052 mySelNumbers.clear();
1053 myCurSelNumbers.clear();
1060 GLViewer_Rect* GLViewer_MarkerSet::getUpdateRect()
1062 GLViewer_Rect* rect = new GLViewer_Rect();
1064 rect->setLeft( myRect->left() + myXGap - myMarkerSize / myXScale );
1065 rect->setTop( myRect->top() + myYGap + myMarkerSize / myYScale );
1066 rect->setRight( myRect->right() - myXGap + myMarkerSize / myXScale );
1067 rect->setBottom( myRect->bottom() - myYGap - myMarkerSize / myYScale );
1068 //cout << " Additional tolerance " << myMarkerSize / myYScale << endl;
1069 //rect->setLeft( myRect->left() - myMarkerSize / myXScale );
1070 //rect->setTop( myRect->top() - myMarkerSize / myYScale );
1071 //rect->setRight( myRect->right() + myMarkerSize / myXScale );
1072 //rect->setBottom( myRect->bottom() + myMarkerSize / myYScale );
1078 void GLViewer_MarkerSet::setXCoord( GLfloat* xCoord, int size )
1080 myXCoord = new GLfloat[ size ];
1081 for( int i = 0; i < size; i++ )
1082 myXCoord[i] = xCoord[i];
1085 void GLViewer_MarkerSet::setYCoord( GLfloat* yCoord, int size )
1087 myYCoord = new GLfloat[ size ];
1088 for( int i = 0; i < size; i++ )
1089 myYCoord[i] = yCoord[i];
1092 void GLViewer_MarkerSet::setNumMarkers( GLint number )
1094 if ( myNumber == number )
1097 if ( myXCoord && myYCoord )
1104 myXCoord = new GLfloat[ myNumber ];
1105 myYCoord = new GLfloat[ myNumber ];
1108 void GLViewer_MarkerSet::onSelectionDone( bool append)
1110 mySelectedIndexes.Clear();
1112 QValueList<int>::Iterator it;
1113 for( it = myMarkers->mySelNumbers.begin(); it != myMarkers->mySelNumbers.end(); ++it )
1115 mySelectedIndexes.Append( *it / 2 ); //!!!
1118 emit dvMarkersSelected( mySelectedIndexes );
1121 void GLViewer_MarkerSet::onSelectionCancel()
1123 mySelectedIndexes.Clear();
1124 emit dvMarkersSelected( mySelectedIndexes );
1127 void GLViewer_MarkerSet::exportNumbers( QValueList<int>& highlight,
1128 QValueList<int>& unhighlight,
1129 QValueList<int>& select,
1130 QValueList<int>& unselect )
1132 highlight = myHNumbers;
1133 unhighlight = myUHNumbers;
1134 select = mySelNumbers;
1135 unselect = myUSelNumbers;
1137 myUHNumbers = myHNumbers;
1140 bool GLViewer_MarkerSet::addOrRemoveSelected( int index )
1142 if( index < 0 || index > myNumber )
1145 int n = mySelNumbers.findIndex( index );
1147 mySelNumbers.append( index );
1150 QValueList<int>::Iterator it;
1151 it = mySelNumbers.at( n );
1152 mySelNumbers.remove( it );
1153 myUSelNumbers.append( index );
1158 void GLViewer_MarkerSet::addSelected( const TColStd_SequenceOfInteger& seq )
1160 for ( int i = 1; i <= seq.Length(); i++ )
1161 if( mySelNumbers.findIndex( seq.Value( i ) ) == -1 )
1162 mySelNumbers.append( seq.Value( i ) - 1 );
1165 void GLViewer_MarkerSet::setSelected( const TColStd_SequenceOfInteger& seq )
1167 // for( QValueList<int>::Iterator it = mySelNumbers.begin(); it != mySelNumbers.end(); ++it )
1168 // if( myUSelNumbers.findIndex( *it ) == -1 )
1169 // myUSelNumbers.append( *it );
1171 myUSelNumbers = mySelNumbers;
1172 mySelNumbers.clear();
1174 for ( int i = 1; i <= seq.Length(); i++ )
1175 mySelNumbers.append( seq.Value( i ) - 1 );
1178 void GLViewer_MarkerSet::moveObject( float theX, float theY, bool fromGroup )
1180 if( !fromGroup && myGroup)
1182 myGroup->dragingObjects( theX, theY );
1185 for( int i = 0; i < myNumber; i++ )
1187 myXCoord[i] = myXCoord[i] + theX;
1188 myYCoord[i] = myYCoord[i] + theY;
1193 QByteArray GLViewer_MarkerSet::getByteCopy()
1196 int anISize = sizeof( GLint );
1197 int aFSize = sizeof( GLfloat );
1199 QByteArray aObject = GLViewer_Object::getByteCopy();
1201 QByteArray aResult( anISize + 2*aFSize*myNumber + aFSize + aObject.size());
1203 char* aPointer = (char*)&myNumber;
1204 for( i = 0; i < anISize; i++, aPointer++ )
1205 aResult[i] = *aPointer;
1207 aPointer = (char*)myXCoord;
1208 for( ; i < anISize + aFSize*myNumber; i++, aPointer++ )
1209 aResult[i] = *aPointer;
1210 aPointer = (char*)myYCoord;
1211 for( ; i < anISize + 2*aFSize*myNumber; i++, aPointer++ )
1212 aResult[i] = *aPointer;
1214 aPointer = (char*)&myMarkerSize;
1215 for( ; i < anISize + 2*aFSize*myNumber + aFSize; i++, aPointer++ )
1216 aResult[i] = *aPointer;
1219 for( ; i < aResult.size(); i++ )
1220 aResult[i] = aObject[i - anISize - 2*aFSize*myNumber - aFSize];
1225 bool GLViewer_MarkerSet::initializeFromByteCopy( QByteArray theArray )
1228 int anISize = sizeof( GLint );
1229 int aFSize = sizeof( GLfloat );
1230 //int aBSize = sizeof( GLboolean );
1232 char* aPointer = (char*)&myNumber;
1233 for( i = 0; i < anISize; i++, aPointer++ )
1234 *aPointer = theArray[i];
1236 int aSize = theArray.size();
1237 if( aSize < anISize + 2*aFSize*myNumber + aFSize)
1240 myXCoord = new GLfloat[myNumber];
1241 myYCoord = new GLfloat[myNumber];
1242 aPointer = (char*)myXCoord;
1243 for( ; i < anISize + aFSize*myNumber; i++, aPointer++ )
1244 *aPointer = theArray[i];
1245 aPointer = (char*)myYCoord;
1246 for( ; i < anISize + 2*aFSize*myNumber; i++, aPointer++ )
1247 *aPointer = theArray[i];
1249 aPointer = (char*)&myMarkerSize;
1250 for( ; i < anISize + 2*aFSize*myNumber + aFSize; i++, aPointer++ )
1251 *aPointer = theArray[i];
1253 int aCurIndex = anISize + 2*aFSize*myNumber + aFSize;
1254 QByteArray aObject( aSize - aCurIndex );
1255 for( ; i < aSize; i++ )
1256 aObject[i - aCurIndex] = theArray[i];
1259 if( !GLViewer_Object::initializeFromByteCopy( aObject ) || myType != "GLViewer_MarkerSet" )
1263 myUHNumbers.clear();
1264 mySelNumbers.clear();
1265 myUSelNumbers.clear();
1266 myCurSelNumbers.clear();
1267 myPrevHNumbers.clear();
1272 /***************************************************************************
1273 ** Class: GLViewer_Polyline
1274 ** Descr: OpenGL Polyline
1276 ** Created: UI team, 03.09.02
1277 ****************************************************************************/
1279 #define SECTIONS 100
1280 #define DISTANTION 5
1282 GLViewer_Polyline::GLViewer_Polyline( int number, float size, const QString& toolTip ) :
1283 GLViewer_Object(), myNumber( 0 ), myXCoord( 0 ), myYCoord( 0 )
1285 myHighFlag = GL_TRUE;
1288 myUHNumbers.clear();
1289 mySelNumbers.clear();
1290 myUSelNumbers.clear();
1291 myCurSelNumbers.clear();
1292 myPrevHNumbers.clear();
1294 setNumber( number );
1296 myType = "GLViewer_Polyline";
1297 myToolTipText = toolTip;
1300 GLViewer_Polyline::~GLViewer_Polyline()
1308 delete myAspectLine;
1311 bool GLViewer_Polyline::translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS )
1313 QString aBuffer = "newpath\n";
1315 AddLineAspectToPS( aBuffer, getAspectLine(), aViewerCS, aPSCS );
1317 for( int i=0; i<myNumber; i++ )
1319 AddCoordsToPS( aBuffer, "moveto", aViewerCS, aPSCS, myXCoord[i], myYCoord[i] );
1321 AddCoordsToPS( aBuffer, "lineto", aViewerCS, aPSCS, myXCoord[i], myYCoord[i] );
1324 AddCoordsToPS( aBuffer, "lineto", aViewerCS, aPSCS, myXCoord[0], myYCoord[0] );
1326 aBuffer+="closepath\nstroke\n";
1328 hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
1333 bool GLViewer_Polyline::translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS )
1335 QString aBuffer = "";
1336 for( int i=0; i<myNumber; i++ )
1338 AddCoordsToHPGL( aBuffer, "PA", aViewerCS, aHPGLCS, myXCoord[i], myYCoord[i] );
1344 AddCoordsToHPGL( aBuffer, "PA", aViewerCS, aHPGLCS, myXCoord[0], myYCoord[0] );
1348 hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
1354 bool GLViewer_Polyline::translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS )
1356 if( !aViewerCS || !aEMFCS )
1359 HPEN pen = AddLineAspectToEMF( dc, getAspectLine(), aViewerCS, aEMFCS );
1360 HGDIOBJ old = SelectObject( dc, pen );
1363 for( int i=0; i<myNumber; i++ )
1367 aViewerCS->transform( *aEMFCS, x, y );
1369 MoveToEx( dc, x, y, NULL );
1378 aViewerCS->transform( *aEMFCS, x, y );
1382 SelectObject( dc, old );
1384 DeleteObject( pen );
1392 void GLViewer_Polyline::compute()
1394 // cout << "GLViewer_MarkerSet::compute" << endl;
1395 GLfloat xa = myXCoord[0];
1396 GLfloat xb = myXCoord[0];
1397 GLfloat ya = myYCoord[0];
1398 GLfloat yb = myYCoord[0];
1400 for ( int i = 0; i < myNumber; i++ )
1402 xa = QMIN( xa, myXCoord[i] );
1403 xb = QMAX( xb, myXCoord[i] );
1404 ya = QMIN( ya, myYCoord[i] );
1405 yb = QMAX( yb, myYCoord[i] );
1408 GLfloat xGap = ( xb - xa ) / 10;
1409 GLfloat yGap = ( yb - ya ) / 10;
1411 myRect->setLeft( xa - xGap );
1412 myRect->setTop( yb + yGap );
1413 myRect->setRight( xb + xGap );
1414 myRect->setBottom( ya - yGap );
1417 GLViewer_Rect* GLViewer_Polyline::getUpdateRect()
1419 GLViewer_Rect* rect = new GLViewer_Rect();
1421 rect->setLeft( myRect->left() - myXGap );
1422 rect->setTop( myRect->top() + myYGap );
1423 rect->setRight( myRect->right() + myXGap );
1424 rect->setBottom( myRect->bottom() - myYGap );
1429 GLViewer_Drawer* GLViewer_Polyline::createDrawer()
1431 // cout << "GLViewer_MarkerSet::createDrawer" << endl;
1432 return myDrawer = new GLViewer_PolylineDrawer();
1435 GLboolean GLViewer_Polyline::highlight( GLfloat x, GLfloat y, GLfloat tol, GLboolean isCircle )
1439 GLfloat xa, xb, ya, yb, l;
1440 GLfloat rsin, rcos, r, ra, rb;
1442 GLboolean highlighted = myIsHigh;
1444 myIsHigh = GL_FALSE;
1450 for( int i = 0; i < myNumber-1+c; i++ )
1454 if( i != myNumber-1 )
1465 l = sqrt( (xb-xa)*(xb-xa) + (yb-ya)*(yb-ya) );
1468 r = ( (x-xa)*(y-yb) - (x-xb)*(y-ya) ) / ( rsin*(ya-yb) + rcos*(xa-xb) );
1469 ra = sqrt( (x-xa)*(x-xa) + (y-ya)*(y-ya) );
1470 rb = sqrt( (x-xb)*(x-xb) + (y-yb)*(y-yb) );
1471 if( fabs( r ) * myXScale <= DISTANTION && ra <= l + DISTANTION && rb <= l + DISTANTION )
1478 if( !myHighFlag && myIsHigh )
1479 myIsHigh = GL_FALSE;
1481 myHighFlag = GL_TRUE;
1483 update = ( GLboolean )( myIsHigh != highlighted );
1485 // cout << "GLViewer_Polyline::highlight complete with " << (int)myIsHigh << endl;
1489 GLboolean GLViewer_Polyline::unhighlight()
1491 // if( !myHNumbers.isEmpty() )
1493 // myUHNumbers = myHNumbers;
1494 // myHNumbers.clear();
1500 myIsHigh = GL_FALSE;
1507 GLboolean GLViewer_Polyline::select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect, GLboolean isFull,
1508 GLboolean isCircle, GLboolean isShift )
1512 GLfloat xa, xb, ya, yb, l;
1513 GLfloat rsin, rcos, r, ra, rb;
1515 GLboolean selected = myIsSel;
1523 for( int i = 0; i < myNumber-1+c; i++ )
1527 if( i != myNumber-1 )
1538 l = sqrt( (xb-xa)*(xb-xa) + (yb-ya)*(yb-ya) );
1541 r = ( (x-xa)*(y-yb) - (x-xb)*(y-ya) ) / ( rsin*(ya-yb) + rcos*(xa-xb) );
1542 ra = sqrt( (x-xa)*(x-xa) + (y-ya)*(y-ya) );
1543 rb = sqrt( (x-xb)*(x-xb) + (y-yb)*(y-yb) );
1544 if( fabs( r ) * myXScale <= DISTANTION && ra <= l + DISTANTION && rb <= l + DISTANTION )
1553 myHighFlag = GL_FALSE;
1554 myIsHigh = GL_FALSE;
1557 myHighFlag = GL_TRUE;
1559 update = ( GLboolean )( myIsSel != selected );
1561 // cout << "GLViewer_Polyline::select complete with " << (int)myIsSel << endl;
1563 // return update; !!!!!!!!!!!!!!!!!!!!!!!!!!! no here
1567 GLboolean GLViewer_Polyline::unselect()
1569 // if( !mySelNumbers.isEmpty() )
1571 // myUSelNumbers = mySelNumbers;
1572 // mySelNumbers.clear();
1573 // myCurSelNumbers.clear();
1586 void GLViewer_Polyline::setXCoord( GLfloat* xCoord, int size )
1588 myXCoord = new GLfloat[ size ];
1589 for( int i = 0; i < size; i++ )
1590 myXCoord[i] = xCoord[i];
1593 void GLViewer_Polyline::setYCoord( GLfloat* yCoord, int size )
1595 myYCoord = new GLfloat[ size ];
1596 for( int i = 0; i < size; i++ )
1597 myYCoord[i] = yCoord[i];
1600 void GLViewer_Polyline::setNumber( GLint number )
1602 if ( myNumber == number )
1605 if ( myXCoord && myYCoord )
1612 myXCoord = new GLfloat[ myNumber ];
1613 myYCoord = new GLfloat[ myNumber ];
1616 void GLViewer_Polyline::onSelectionDone( bool append)
1618 mySelectedIndexes.Clear();
1620 QValueList<int>::Iterator it;
1621 for( it = myMarkers->mySelNumbers.begin(); it != myMarkers->mySelNumbers.end(); ++it )
1623 mySelectedIndexes.Append( *it / 2 ); //!!!
1628 void GLViewer_Polyline::onSelectionCancel()
1630 mySelectedIndexes.Clear();
1633 void GLViewer_Polyline::exportNumbers( QValueList<int>& highlight,
1634 QValueList<int>& unhighlight,
1635 QValueList<int>& select,
1636 QValueList<int>& unselect )
1638 highlight = myHNumbers;
1639 unhighlight = myUHNumbers;
1640 select = mySelNumbers;
1641 unselect = myUSelNumbers;
1644 void GLViewer_Polyline::moveObject( float theX, float theY, bool fromGroup )
1646 if( !fromGroup && myGroup)
1648 myGroup->dragingObjects( theX, theY );
1651 for( int i = 0; i < myNumber; i++ )
1653 myXCoord[i] = myXCoord[i] + theX;
1654 myYCoord[i] = myYCoord[i] + theY;
1659 QByteArray GLViewer_Polyline::getByteCopy()
1662 int anISize = sizeof( GLint );
1663 int aFSize = sizeof( GLfloat );
1664 int aBSize = sizeof( GLboolean );
1666 QByteArray aObject = GLViewer_Object::getByteCopy();
1668 QByteArray aResult( aFSize*myNumber*2 + anISize + 2*aBSize + aObject.size());
1670 char* aPointer = (char*)&myNumber;
1671 for( i = 0; i < anISize; i++, aPointer++ )
1672 aResult[i] = *aPointer;
1674 aPointer = (char*)myXCoord;
1675 for( ; i < anISize + aFSize*myNumber; i++, aPointer++ )
1676 aResult[i] = *aPointer;
1677 aPointer = (char*)myYCoord;
1678 for( ; i < anISize + 2*aFSize*myNumber; i++, aPointer++ )
1679 aResult[i] = *aPointer;
1681 aPointer = (char*)&myIsClosed;
1682 for( ; i < anISize + 2*aFSize*myNumber + aBSize; i++, aPointer++ )
1683 aResult[i] = *aPointer;
1684 aPointer = (char*)&myHighSelAll;
1685 for( ; i < anISize + 2*aFSize*myNumber + 2*aBSize; i++, aPointer++ )
1686 aResult[i] = *aPointer;
1688 for( ; i < aResult.size(); i++ )
1689 aResult[i] = aObject[i - anISize - 2*aFSize*myNumber - 2*aBSize];
1695 bool GLViewer_Polyline::initializeFromByteCopy( QByteArray theArray )
1698 int anISize = sizeof( GLint );
1699 int aFSize = sizeof( GLfloat );
1700 int aBSize = sizeof( GLboolean );
1702 char* aPointer = (char*)&myNumber;
1703 for( i = 0; i < anISize; i++, aPointer++ )
1704 *aPointer = theArray[i];
1706 int aSize = theArray.size();
1707 if( aSize < aFSize*myNumber*2 + anISize + 2*aBSize )
1710 myXCoord = new GLfloat[myNumber];
1711 myYCoord = new GLfloat[myNumber];
1712 aPointer = (char*)myXCoord;
1713 for( ; i < anISize + aFSize*myNumber; i++, aPointer++ )
1714 *aPointer = theArray[i];
1715 aPointer = (char*)myYCoord;
1716 for( ; i < anISize + 2*aFSize*myNumber; i++, aPointer++ )
1717 *aPointer = theArray[i];
1719 aPointer = (char*)&myIsClosed;
1720 for( ; i < anISize + 2*aFSize*myNumber + aBSize; i++, aPointer++ )
1721 *aPointer = theArray[i];
1722 aPointer = (char*)&myHighSelAll;
1723 for( ; i < anISize + 2*aFSize*myNumber + 2*aBSize; i++, aPointer++ )
1724 *aPointer = theArray[i];
1726 int aCurIndex = anISize + 2*aFSize*myNumber + 2*aBSize;
1727 QByteArray aObject( aSize - aCurIndex );
1728 for( ; i < aSize; i++ )
1729 aObject[i - aCurIndex] = theArray[i];
1731 if( !GLViewer_Object::initializeFromByteCopy( aObject ) || myType != "GLViewer_Polyline" )
1735 myUHNumbers.clear();
1736 mySelNumbers.clear();
1737 myUSelNumbers.clear();
1738 myCurSelNumbers.clear();
1739 myPrevHNumbers.clear();
1744 /***************************************************************************
1745 ** Class: GLViewer_TextObject
1746 ** Descr: Text as Object for OpenGL
1748 ** Created: UI team, 12.02.04
1749 ****************************************************************************/
1751 GLViewer_TextObject::GLViewer_TextObject( const QString& theStr, float xPos, float yPos,
1752 const QColor& color, const QString& toolTip )
1755 myGLText = new GLViewer_Text( theStr, xPos, yPos, color );
1759 myHighFlag = GL_TRUE;
1761 myType = "GLViewer_TextObject";
1762 myToolTipText = toolTip;
1764 GLViewer_TextObject::~GLViewer_TextObject()
1770 delete myAspectLine;
1773 bool GLViewer_TextObject::translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS )
1775 QString aText = myGLText->getText();
1777 myGLText->getPosition( xPos, yPos );
1779 QString aBuffer = "/Times-Roman findfont\n";
1780 aBuffer += "12 scalefont setfont\n";
1782 AddCoordsToPS( aBuffer, "moveto", aViewerCS, aPSCS, double(xPos), double(yPos) );
1783 aBuffer += "(" + aText + ") show\n";
1785 hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
1790 bool GLViewer_TextObject::translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS )
1792 QString aText = myGLText->getText();
1794 myGLText->getPosition( xPos, yPos );
1796 QString aBuffer = "";
1797 AddCoordsToHPGL( aBuffer, "PA", aViewerCS, aHPGLCS, double(xPos), double(yPos) );
1799 aBuffer = "LB" + aText + "#;";
1801 hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
1807 bool GLViewer_TextObject::translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS )
1809 QString aText = myGLText->getText();
1811 myGLText->getPosition( xPos, yPos );
1813 double x = double( xPos ),
1816 aViewerCS->transform( *aEMFCS, x, y );
1817 const char* str = aText.ascii();
1819 int nHeight = 35*14; // height of font
1820 int nWidth = 35*12; // average character width
1821 int nEscapement = 0; // angle of escapement
1822 int nOrientation = 0; // base-line orientation angle
1823 int fnWeight = FW_NORMAL; // font weight
1824 DWORD fdwItalic = FALSE; // italic attribute option
1825 DWORD fdwUnderline = FALSE; // underline attribute option
1826 DWORD fdwStrikeOut = FALSE; // strikeout attribute option
1827 DWORD fdwCharSet = ANSI_CHARSET; // character set identifier
1828 DWORD fdwOutputPrecision = OUT_DEFAULT_PRECIS; // output precision
1829 DWORD fdwClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
1830 DWORD fdwQuality = PROOF_QUALITY; // output quality
1831 DWORD fdwPitchAndFamily = FIXED_PITCH | FF_DONTCARE; // pitch and family
1832 LPCTSTR lpszFace = NULL; // typeface name
1835 HFONT aFont = CreateFont( nHeight, nWidth, nEscapement, nOrientation, fnWeight, fdwItalic,
1836 fdwUnderline, fdwStrikeOut, fdwCharSet, fdwOutputPrecision,
1837 fdwClipPrecision, fdwQuality, fdwPitchAndFamily, lpszFace );
1838 LOGBRUSH aBrushData;
1839 aBrushData.lbStyle = BS_HOLLOW;
1841 HBRUSH aBrush = CreateBrushIndirect( &aBrushData );
1843 HGDIOBJ old1 = SelectObject( dc, aFont );
1844 HGDIOBJ old2 = SelectObject( dc, aBrush );
1846 TextOut( dc, x, y, str, aText.length() );
1848 SelectObject ( dc, old1 );
1849 SelectObject ( dc, old2 );
1851 DeleteObject( aFont );
1857 GLViewer_Drawer* GLViewer_TextObject::createDrawer()
1859 myDrawer = new GLViewer_TextDrawer();
1864 void GLViewer_TextObject::compute()
1867 QString aStr = myGLText->getText();
1868 myGLText->getPosition( xPos, yPos );
1870 myWidth = myGLText->getWidth();
1871 myHeight = myGLText->getHeight();
1872 myRect->setLeft( xPos );
1873 myRect->setTop( yPos + myHeight );
1874 myRect->setRight( xPos + myWidth );
1875 myRect->setBottom( yPos );
1878 void GLViewer_TextObject::setDrawer( GLViewer_Drawer* theDrawer )
1880 myDrawer = theDrawer;
1884 GLViewer_Rect* GLViewer_TextObject::getUpdateRect()
1886 GLViewer_Rect* rect = new GLViewer_Rect();
1889 QString aStr = myGLText->getText();
1890 myGLText->getPosition( xPos, yPos );
1892 rect->setLeft( myRect->left() + myXGap - myWidth / myXScale );
1893 rect->setTop( myRect->top() + myYGap + myHeight / myYScale );
1894 rect->setRight( myRect->right() - myXGap + myWidth / myXScale );
1895 rect->setBottom( myRect->bottom() - myYGap - myHeight / myYScale );
1900 GLboolean GLViewer_TextObject::highlight( GLfloat theX, GLfloat theY, GLfloat theTol, GLboolean isCircle )
1906 myGLText->getPosition( xPos, yPos );
1909 aRect.setLeft( (int)xPos );
1910 aRect.setRight( (int)(xPos + myWidth / myXScale) );
1911 aRect.setTop( (int)yPos );// - myHeight / myYScale );
1912 aRect.setBottom( (int)(yPos + myHeight / myYScale) );
1914 //cout << "theX: " << theX << " theY: " << theY << endl;
1915 //cout << "aRect.left(): " << aRect.left() << " aRect.right(): " << aRect.right() << endl;
1916 //cout << "aRect.top(): " << aRect.top() << " aRect.bottom(): " << aRect.bottom() << endl;
1918 QRegion obj( aRect );
1919 QRegion intersection;
1922 int l = (int)(theX - theTol);
1923 int r = (int)(theX + theTol);
1924 int t = (int)(theY - theTol);
1925 int b = (int)(theY + theTol);
1926 region.setLeft( l );
1927 region.setRight( r );
1929 region.setBottom( b );
1931 QRegion circle( l, t, (int)(2 * theTol), (int)(2 * theTol), QRegion::Ellipse );
1933 intersection = obj.intersect( circle );
1935 intersection = obj.intersect( region );
1937 if( intersection.isEmpty() )
1942 if( !myHighFlag && myIsHigh )
1943 myIsHigh = GL_FALSE;
1945 myHighFlag = GL_TRUE;
1950 GLboolean GLViewer_TextObject::unhighlight()
1954 myIsHigh = GL_FALSE;
1961 GLboolean GLViewer_TextObject::select( GLfloat theX, GLfloat theY, GLfloat theTol, GLViewer_Rect rect,
1962 GLboolean isFull, GLboolean isCircle, GLboolean isShift )
1967 QRegion obj( *(myRect->toQRect()) );
1968 QRegion intersection;
1971 int l = (int)(theX - theTol);
1972 int r = (int)(theX + theTol);
1973 int t = (int)(theY - theTol);
1974 int b = (int)(theY + theTol);
1975 region.setLeft( l );
1976 region.setRight( r );
1978 region.setBottom( b );
1980 QRegion circle( l, t, (int)(2 * theTol), (int)(2 * theTol), QRegion::Ellipse );
1982 intersection = obj.intersect( circle );
1984 intersection = obj.intersect( region );
1986 if( intersection.isEmpty() )
1993 myHighFlag = GL_FALSE;
1994 myIsHigh = GL_FALSE;
1997 myHighFlag = GL_TRUE;
2002 GLboolean GLViewer_TextObject::unselect()
2013 void GLViewer_TextObject::moveObject( float theX, float theY, bool fromGroup )
2015 if( !fromGroup && myGroup)
2017 myGroup->dragingObjects( theX, theY );
2021 myGLText->getPosition( aX, anY );
2024 myGLText->setPosition( aX, anY );
2028 QByteArray GLViewer_TextObject::getByteCopy()
2030 QByteArray aObject = GLViewer_Object::getByteCopy();
2036 bool GLViewer_TextObject::initializeFromByteCopy( QByteArray theArray )
2038 if( !GLViewer_Object::initializeFromByteCopy( theArray ) || myType != "GLViewer_TextObject" )
2046 /***************************************************************************
2047 ** Class: GLViewer_AspectLine
2048 ** Descr: Substitution of Prs2d_AspectLine for OpenGL
2050 ** Created: UI team, 05.11.02
2051 ****************************************************************************/
2053 GLViewer_AspectLine::GLViewer_AspectLine()
2055 myNColor = QColor( 255, 255, 255 );
2056 myHColor = QColor( 0, 255, 255 );
2057 mySColor = QColor( 255, 0, 0 );
2063 GLViewer_AspectLine::GLViewer_AspectLine( int type, float width )
2065 myNColor = QColor( 255, 255, 255 );
2066 myHColor = QColor( 0, 255, 255 );
2067 mySColor = QColor( 255, 0, 0 );
2069 myLineWidth = width;
2070 if( type == 1 || type == 0 )
2076 GLViewer_AspectLine::~GLViewer_AspectLine()
2080 void GLViewer_AspectLine::setLineColors( QColor nc, QColor hc, QColor sc )
2087 int GLViewer_AspectLine::setLineType( const int type )
2089 if( type == 1 || type == 0 )
2097 int GLViewer_AspectLine::setLineWidth( const float width )
2101 myLineWidth = width;
2107 void GLViewer_AspectLine::getLineColors( QColor& nc, QColor& hc, QColor& sc ) const
2114 QByteArray GLViewer_AspectLine::getByteCopy() const
2116 int anISize = sizeof( int );
2117 int aFSize = sizeof( float );
2118 int aNR = myNColor.red(), aNG = myNColor.green(), aNB = myNColor.blue();
2119 int aHR = myHColor.red(), aHG = myHColor.green(), aHB = myHColor.blue();
2120 int aSR = mySColor.red(), aSG = mySColor.green(), aSB = mySColor.blue();
2122 QByteArray aResult( anISize * 10 + aFSize );
2126 char* aPointer = (char*)&aNR;
2127 for( i = 0; i < anISize; i++, aPointer++ )
2128 aResult[i] = *aPointer;
2129 aPointer = (char*)&aNG;
2130 for( ; i < 2*anISize; i++, aPointer++ )
2131 aResult[i] = *aPointer;
2132 aPointer = (char*)&aNB;
2133 for( ; i < 3*anISize; i++, aPointer++ )
2134 aResult[i] = *aPointer;
2136 aPointer = (char*)&aHR;
2137 for( ; i < 4*anISize; i++, aPointer++ )
2138 aResult[i] = *aPointer;
2139 aPointer = (char*)&aHG;
2140 for( ; i < 5*anISize; i++, aPointer++ )
2141 aResult[i] = *aPointer;
2142 aPointer = (char*)&aHB;
2143 for( ; i < 6*anISize; i++, aPointer++ )
2144 aResult[i] = *aPointer;
2146 aPointer = (char*)&aSR;
2147 for( ; i < 7*anISize; i++, aPointer++ )
2148 aResult[i] = *aPointer;
2149 aPointer = (char*)&aSG;
2150 for( ; i < 8*anISize; i++, aPointer++ )
2151 aResult[i] = *aPointer;
2152 aPointer = (char*)&aSB;
2153 for( ; i < 9*anISize; i++, aPointer++ )
2154 aResult[i] = *aPointer;
2156 aPointer = (char*)&myLineWidth;
2157 for( ; i < 9*anISize + aFSize; i++, aPointer++ )
2158 aResult[i] = *aPointer;
2160 aPointer = (char*)&myLineType;
2161 for( ; i < 10*anISize + aFSize; i++, aPointer++ )
2162 aResult[i] = *aPointer;
2167 GLViewer_AspectLine* GLViewer_AspectLine::fromByteCopy( QByteArray theBytes )
2170 int anISize = sizeof( int );
2171 int aFSize = sizeof( float );
2172 int aNR = 0, aNG = 0, aNB = 0;
2173 int aHR = 0, aHG = 0, aHB = 0;
2174 int aSR = 0, aSG = 0, aSB = 0;
2176 float aLineWidth = 0;
2180 char* aPointer = (char*)&aNR;
2181 for( i = 0; i < anISize; i++, aPointer++ )
2182 *aPointer = theBytes[i];
2183 aPointer = (char*)&aNG;
2184 for( ; i < 2*anISize; i++, aPointer++ )
2185 *aPointer = theBytes[i];
2186 aPointer = (char*)&aNB;
2187 for( ; i < 3*anISize; i++, aPointer++ )
2188 *aPointer = theBytes[i];
2190 aPointer = (char*)&aHR;
2191 for( ; i < 4*anISize; i++, aPointer++ )
2192 *aPointer = theBytes[i];
2193 aPointer = (char*)&aHG;
2194 for( ; i < 5*anISize; i++, aPointer++ )
2195 *aPointer = theBytes[i];
2196 aPointer = (char*)&aHB;
2197 for( ; i < 6*anISize; i++, aPointer++ )
2198 *aPointer = theBytes[i];
2200 aPointer = (char*)&aSR;
2201 for( ; i < 7*anISize; i++, aPointer++ )
2202 *aPointer = theBytes[i];
2203 aPointer = (char*)&aSG;
2204 for( ; i < 8*anISize; i++, aPointer++ )
2205 *aPointer = theBytes[i];
2206 aPointer = (char*)&aSB;
2207 for( ; i < 9*anISize; i++, aPointer++ )
2208 *aPointer = theBytes[i];
2210 aPointer = (char*)&aLineWidth;
2211 for( ; i < 9*anISize + aFSize; i++, aPointer++ )
2212 *aPointer = theBytes[i];
2214 aPointer = (char*)&aLineType;
2215 for( ; i < 10*anISize + aFSize; i++, aPointer++ )
2216 *aPointer = theBytes[i];
2218 GLViewer_AspectLine* anAspect = new GLViewer_AspectLine( aLineType, aLineWidth );
2219 anAspect->setLineColors( QColor( aNR, aNG, aNB ),
2220 QColor( aHR, aHG, aHB ),
2221 QColor( aSR, aSG, aSB ) );
2225 /***************************************************************************
2226 ** Class: GLViewer_MimeSource
2227 ** Descr: Needs for a work with QClipboard
2229 ** Created: UI team, 22.03.04
2230 ****************************************************************************/
2231 GLViewer_MimeSource::~GLViewer_MimeSource()
2235 bool GLViewer_MimeSource::setObjects( QValueList<GLViewer_Object*> theObjects )
2237 if( !theObjects.empty() )
2239 QStringList aObjectsType;
2240 QValueList<QByteArray> aObjects;
2241 QValueList<GLViewer_Object*>::const_iterator anIt = theObjects.begin();
2242 QValueList<GLViewer_Object*>::const_iterator anEndIt = theObjects.end();
2244 int aObjByteSize = 0;
2245 for( ; anIt != anEndIt; anIt++ )
2247 aObjects.append( (*anIt)->getByteCopy() );
2248 aObjByteSize += aObjects.last().size();
2249 aObjectsType.append( (*anIt)->getObjectType() );
2252 int anISize = sizeof( int );
2253 QString aTypes = aObjectsType.join("");
2254 int aStrByteSize = aTypes.length();
2255 int aObjNum = aObjects.count();
2257 myByteArray = QByteArray( anISize * (1 + 2*aObjNum) + aStrByteSize + aObjByteSize );
2259 int anIndex = 0, j = 0;
2260 char* aPointer = (char*)&aObjNum;
2261 for( anIndex = 0; anIndex < anISize; anIndex++, aPointer++ )
2262 myByteArray[anIndex] = *aPointer;
2264 QStringList::const_iterator aStrIt = aObjectsType.begin();
2265 QStringList::const_iterator aEndStrIt = aObjectsType.end();
2266 for( j = 1; aStrIt != aEndStrIt; aStrIt++, j++ )
2268 int aStrLen = (*aStrIt).length();
2269 aPointer = (char*)&aStrLen;
2270 for( ; anIndex < anISize*( 1 + j ); anIndex++, aPointer++ )
2271 myByteArray[anIndex] = *aPointer;
2274 int aCurIndex = anIndex;
2275 const char* aStr = aTypes.data();
2277 for( j = 0 ; anIndex < aCurIndex + aStrByteSize; aPointer++, anIndex++, j++ )
2278 myByteArray[anIndex] = aStr[j];
2280 aCurIndex = anIndex;
2281 QValueList<QByteArray>::iterator anObjIt = aObjects.begin();
2282 QValueList<QByteArray>::iterator anEndObjIt = aObjects.end();
2283 for( j = 1; anObjIt != anEndObjIt; anObjIt++, j++ )
2285 int aObjLen = (int)((*anObjIt).size());
2286 aPointer = (char*)&aObjLen;
2287 for( ; anIndex < aCurIndex + anISize*j; anIndex++, aPointer++ )
2288 myByteArray[anIndex] = *aPointer;
2291 aCurIndex = anIndex;
2292 anObjIt = aObjects.begin();
2294 for( ; anObjIt != anEndObjIt; anObjIt++ )
2296 int aObjLen = (int)((*anObjIt).size());
2297 for( j = 0 ; anIndex < aCurIndex + aObjLen; anIndex++, aPointer++, j++ )
2298 myByteArray[anIndex] = (*anObjIt)[j];
2299 aCurIndex = anIndex;
2307 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!NOTE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2308 //If you want to use new class, following two method must be redefined
2309 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!NOTE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2310 GLViewer_Object* GLViewer_MimeSource::getObject( QByteArray theArray, QString theType )
2312 if( !theArray.isEmpty() )
2314 if( theType == "GLViewer_MarkerSet" )
2316 GLViewer_MarkerSet* aObject = new GLViewer_MarkerSet( 0, (float)0.0, 0 );
2317 if( aObject->initializeFromByteCopy( theArray ) )
2320 else if ( theType == "GLViewer_Polyline" )
2322 GLViewer_Polyline* aObject = new GLViewer_Polyline( 0, (float)0.0, 0 );
2323 if( aObject->initializeFromByteCopy( theArray ) )
2326 else if( theType == "GLViewer_TextObject" )
2328 GLViewer_TextObject* aObject = new GLViewer_TextObject( 0, 0, 0, QColor(255,255,255), 0 );
2329 if( aObject->initializeFromByteCopy( theArray ) )
2337 QValueList<GLViewer_Object*> GLViewer_MimeSource::getObjects( QByteArray theArray, QString theType )
2339 if( !theArray.isEmpty() )
2341 int anISize = sizeof( int );
2342 if( theType == "GLViewer_Objects" )
2344 QStringList aTypeList;
2345 QValueList<QByteArray> aObjects;
2346 QValueList<GLViewer_Object*> aObjectList;
2348 QValueList<int> aTypeSizeList;
2349 QValueList<int> aObjSizeList;
2351 char* aPointer = (char*)&aObjNum;
2353 int anIndex = 0, j = 0;
2354 for( anIndex = 0; anIndex < anISize; anIndex++, aPointer++ )
2355 *aPointer = theArray[anIndex];
2357 for( j = 0; j < aObjNum; j++ )
2360 aPointer = (char*)&aTempVal;
2361 for( ; anIndex < anISize*(j+2); anIndex++, aPointer++ )
2362 *aPointer = theArray[anIndex];
2363 aTypeSizeList.append( aTempVal );
2366 int aCurIndex = anIndex;
2367 for( j = 0; j < aObjNum; j++ )
2370 for( ; anIndex < aCurIndex + aTypeSizeList[j]; anIndex++ )
2372 char aLetter = theArray[anIndex];
2373 aTempStr.append( aLetter );
2375 aTypeList.append( aTempStr );
2376 aCurIndex = anIndex;
2379 for( j = 0; j < aObjNum; j++ )
2382 aPointer = (char*)&aTempVal;
2383 for( ; anIndex < aCurIndex + anISize*(j+1); anIndex++, aPointer++ )
2384 *aPointer = theArray[anIndex];
2385 aObjSizeList.append( aTempVal );
2388 aCurIndex = anIndex;
2389 for( j = 0; j < aObjNum; j++ )
2391 QByteArray aTempArray(aObjSizeList[j]);
2392 for( ; anIndex < aCurIndex + aObjSizeList[j]; anIndex++ )
2393 aTempArray[anIndex-aCurIndex] = theArray[anIndex];
2394 aObjects.append( aTempArray );
2395 aCurIndex = anIndex;
2398 for( j = 0; j < aObjNum; j++ )
2399 aObjectList.append( getObject( aObjects[j], aTypeList[j] ) );
2405 return QValueList<GLViewer_Object*>();
2408 const char* GLViewer_MimeSource::format( int theIndex ) const
2412 case 0: return "GLViewer_Objects";
2413 //case 1: return "GLViewer_MarkerSet";
2414 //case 2: return "GLViewer_Polyline";
2415 //case 3: return "GLViewer_TextObject";
2421 QByteArray GLViewer_MimeSource::encodedData( const char* theObjectType ) const
2423 if( theObjectType == "GLViewer_Objects" )
2426 return QByteArray();