#ifdef WNT
#ifdef GLVIEWER_EXPORTS
-#define GLVIEWER_EXPORT __declspec(dllexport)
+#define GLVIEWER_API __declspec(dllexport)
#else
-#define GLVIEWER_EXPORT __declspec(dllimport)
+#define GLVIEWER_API __declspec(dllimport)
#endif
+
#else
-#define GLVIEWER_EXPORT
+#define GLVIEWER_API
#endif // WNT
-#ifndef PI
-#define PI 3.14159265359
-#endif
--- /dev/null
+/***************************************************************************
+** Class: GLViewer_AspectLine
+** Descr: Substitution of Prs2d_AspectLine for OpenGL
+** Module: GLViewer
+** Created: UI team, 05.11.02
+****************************************************************************/
+
+//#include <GLViewerAfx.h>
+#include "GLViewer_AspectLine.h"
+
+GLViewer_AspectLine::GLViewer_AspectLine()
+{
+ myNColor = QColor( 255, 255, 255 );
+ myHColor = QColor( 0, 255, 255 );
+ mySColor = QColor( 255, 0, 0 );
+
+ myLineWidth = 1.0;
+ myLineType = 0;
+}
+
+GLViewer_AspectLine::GLViewer_AspectLine( int type, float width )
+{
+ myNColor = QColor( 255, 255, 255 );
+ myHColor = QColor( 0, 255, 255 );
+ mySColor = QColor( 255, 0, 0 );
+
+ myLineWidth = width;
+ if( type == 1 || type == 0 )
+ myLineType = type;
+ else
+ myLineType = 0;
+}
+
+GLViewer_AspectLine::~GLViewer_AspectLine()
+{
+}
+
+void GLViewer_AspectLine::setLineColors( QColor nc, QColor hc, QColor sc )
+{
+ myNColor = nc;
+ myHColor = hc;
+ mySColor = sc;
+}
+
+int GLViewer_AspectLine::setLineType( const int type )
+{
+ if( type == 1 || type == 0 )
+ {
+ myLineType = type;
+ return 0;
+ }
+ return 1;
+}
+
+int GLViewer_AspectLine::setLineWidth( const float width )
+{
+ if( width > 0 )
+ {
+ myLineWidth = width;
+ return 0;
+ }
+ return 1;
+}
+
+void GLViewer_AspectLine::getLineColors( QColor& nc, QColor& hc, QColor& sc ) const
+{
+ nc = myNColor;
+ hc = myHColor;
+ sc = mySColor;
+}
+
+QByteArray GLViewer_AspectLine::getByteCopy() const
+{
+ int anISize = sizeof( int );
+ int aFSize = sizeof( float );
+ int aNR = myNColor.red(), aNG = myNColor.green(), aNB = myNColor.blue();
+ int aHR = myHColor.red(), aHG = myHColor.green(), aHB = myHColor.blue();
+ int aSR = mySColor.red(), aSG = mySColor.green(), aSB = mySColor.blue();
+
+ QByteArray aResult( anISize * 10 + aFSize );
+
+ int i = 0;
+
+ char* aPointer = (char*)&aNR;
+ for( i = 0; i < anISize; i++, aPointer++ )
+ aResult[i] = *aPointer;
+ aPointer = (char*)&aNG;
+ for( ; i < 2*anISize; i++, aPointer++ )
+ aResult[i] = *aPointer;
+ aPointer = (char*)&aNB;
+ for( ; i < 3*anISize; i++, aPointer++ )
+ aResult[i] = *aPointer;
+
+ aPointer = (char*)&aHR;
+ for( ; i < 4*anISize; i++, aPointer++ )
+ aResult[i] = *aPointer;
+ aPointer = (char*)&aHG;
+ for( ; i < 5*anISize; i++, aPointer++ )
+ aResult[i] = *aPointer;
+ aPointer = (char*)&aHB;
+ for( ; i < 6*anISize; i++, aPointer++ )
+ aResult[i] = *aPointer;
+
+ aPointer = (char*)&aSR;
+ for( ; i < 7*anISize; i++, aPointer++ )
+ aResult[i] = *aPointer;
+ aPointer = (char*)&aSG;
+ for( ; i < 8*anISize; i++, aPointer++ )
+ aResult[i] = *aPointer;
+ aPointer = (char*)&aSB;
+ for( ; i < 9*anISize; i++, aPointer++ )
+ aResult[i] = *aPointer;
+
+ aPointer = (char*)&myLineWidth;
+ for( ; i < 9*anISize + aFSize; i++, aPointer++ )
+ aResult[i] = *aPointer;
+
+ aPointer = (char*)&myLineType;
+ for( ; i < 10*anISize + aFSize; i++, aPointer++ )
+ aResult[i] = *aPointer;
+
+ return aResult;
+}
+
+GLViewer_AspectLine* GLViewer_AspectLine::fromByteCopy( QByteArray theBytes )
+{
+
+ int anISize = sizeof( int );
+ int aFSize = sizeof( float );
+ int aNR = 0, aNG = 0, aNB = 0;
+ int aHR = 0, aHG = 0, aHB = 0;
+ int aSR = 0, aSG = 0, aSB = 0;
+ int aLineType = 0;
+ float aLineWidth = 0;
+
+ int i = 0;
+
+ char* aPointer = (char*)&aNR;
+ for( i = 0; i < anISize; i++, aPointer++ )
+ *aPointer = theBytes[i];
+ aPointer = (char*)&aNG;
+ for( ; i < 2*anISize; i++, aPointer++ )
+ *aPointer = theBytes[i];
+ aPointer = (char*)&aNB;
+ for( ; i < 3*anISize; i++, aPointer++ )
+ *aPointer = theBytes[i];
+
+ aPointer = (char*)&aHR;
+ for( ; i < 4*anISize; i++, aPointer++ )
+ *aPointer = theBytes[i];
+ aPointer = (char*)&aHG;
+ for( ; i < 5*anISize; i++, aPointer++ )
+ *aPointer = theBytes[i];
+ aPointer = (char*)&aHB;
+ for( ; i < 6*anISize; i++, aPointer++ )
+ *aPointer = theBytes[i];
+
+ aPointer = (char*)&aSR;
+ for( ; i < 7*anISize; i++, aPointer++ )
+ *aPointer = theBytes[i];
+ aPointer = (char*)&aSG;
+ for( ; i < 8*anISize; i++, aPointer++ )
+ *aPointer = theBytes[i];
+ aPointer = (char*)&aSB;
+ for( ; i < 9*anISize; i++, aPointer++ )
+ *aPointer = theBytes[i];
+
+ aPointer = (char*)&aLineWidth;
+ for( ; i < 9*anISize + aFSize; i++, aPointer++ )
+ *aPointer = theBytes[i];
+
+ aPointer = (char*)&aLineType;
+ for( ; i < 10*anISize + aFSize; i++, aPointer++ )
+ *aPointer = theBytes[i];
+
+ GLViewer_AspectLine* anAspect = new GLViewer_AspectLine( aLineType, aLineWidth );
+ anAspect->setLineColors( QColor( aNR, aNG, aNB ),
+ QColor( aHR, aHG, aHB ),
+ QColor( aSR, aSG, aSB ) );
+ return anAspect;
+}
--- /dev/null
+// File: GLViewer_AspectLine.h
+// Created: November, 2004
+// Author: OCC team
+// Copyright (C) CEA 2004
+
+#ifndef GLVIEWER_ASPECTLINE_H
+#define GLVIEWER_ASPECTLINE_H
+
+#include "GLViewer.h"
+
+#include <qcolor.h>
+
+#ifdef WNT
+#pragma warning( disable:4251 )
+#endif
+
+// Class: GLViewer_AspectLine
+// Descr: Substitution of Prs2d_AspectLine for OpenGL
+
+class GLVIEWER_API GLViewer_AspectLine
+{
+public:
+ GLViewer_AspectLine();
+ GLViewer_AspectLine( int, float );
+ ~GLViewer_AspectLine();
+
+ void setLineColors( QColor nc = Qt::black,
+ QColor hc = Qt::cyan,
+ QColor sc = Qt::red );
+ int setLineWidth( const float );
+ int setLineType( const int );
+
+ void getLineColors( QColor&, QColor&, QColor& ) const;
+ float getLineWidth() const { return myLineWidth; };
+ int getLineType() const { return myLineType; };
+
+ QByteArray getByteCopy() const;
+
+ static GLViewer_AspectLine* fromByteCopy( QByteArray );
+
+protected:
+ QColor myNColor;
+ QColor myHColor;
+ QColor mySColor;
+ float myLineWidth;
+ int myLineType; // 0 - normal, 1 - strip
+};
+
+#ifdef WNT
+#pragma warning ( default:4251 )
+#endif
+
+#endif
--- /dev/null
+// File: GLViewer_BaseDrawers.cxx
+// Created: November, 2004
+// Author: OCC team
+// Copyright (C) CEA 2004
+
+//#include <GLViewerAfx.h>
+#include "GLViewer_BaseDrawers.h"
+#include "GLViewer_Object.h"
+#include "GLViewer_Text.h"
+#include "GLViewer_AspectLine.h"
+#include "GLViewer_BaseObjects.h"
+
+#ifndef WIN32
+#include <GL/glx.h>
+#endif
+
+/***************************************************************************
+** Class: GLViewer_MarkerDrawer
+** Descr: Drawer for GLViewer_MarkerSet
+** Module: GLViewer
+** Created: UI team, 03.10.01
+****************************************************************************/
+
+GLfloat sin_table[SEGMENTS];
+GLfloat cos_table[SEGMENTS];
+
+GLViewer_MarkerDrawer::GLViewer_MarkerDrawer()
+: GLViewer_Drawer()
+{
+ GLfloat angle = 0.0;
+ for ( int i = 0; i < SEGMENTS; i++ )
+ {
+ sin_table[i] = sin( angle );
+ cos_table[i] = cos( angle );
+ angle += float( STEP );
+ }
+ myObjectType = "GLViewer_MarkerSet";
+}
+
+GLViewer_MarkerDrawer::~GLViewer_MarkerDrawer()
+{
+}
+
+void GLViewer_MarkerDrawer::create( float xScale, float yScale, bool onlyUpdate )
+{
+ QValueList<int>::Iterator it;
+ QValueList<int>::Iterator EndIt;
+ QValueList<GLViewer_Object*>::Iterator anObjectIt = myObjects.begin();
+ QValueList<GLViewer_Object*>::Iterator anEndObjectIt = myObjects.end();
+
+ myXScale = xScale;
+ myYScale = yScale;
+
+ QColor colorN, colorH, colorS;
+
+ GLViewer_MarkerSet* aMarkerSet = NULL;
+ GLViewer_AspectLine* anAspectLine = NULL;
+
+ for( ; anObjectIt != anEndObjectIt; anObjectIt++ )
+ {
+ aMarkerSet = ( GLViewer_MarkerSet* )(*anObjectIt);
+ anAspectLine = aMarkerSet->getAspectLine();
+ anAspectLine->getLineColors( colorN, colorH, colorS );
+
+ float* aXCoord = aMarkerSet->getXCoord();
+ float* anYCoord = aMarkerSet->getYCoord();
+ float aRadius = aMarkerSet->getMarkerSize();
+
+ QValueList<int> aHNumbers, anUHNumbers, aSelNumbers, anUSelNumbers;
+ aMarkerSet->exportNumbers( aHNumbers, anUHNumbers, aSelNumbers, anUSelNumbers );
+
+ if( onlyUpdate )
+ {
+ EndIt = anUHNumbers.end();
+ for( it = anUHNumbers.begin(); it != EndIt; ++it )
+ {
+ drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorN, anAspectLine );
+ }
+
+ EndIt = anUSelNumbers.end();
+ for( it = anUSelNumbers.begin(); it != EndIt; ++it )
+ drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorN, anAspectLine );
+
+ EndIt = aSelNumbers.end();
+ for( it = aSelNumbers.begin(); it != EndIt; ++it )
+ drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorS, anAspectLine );
+
+ EndIt = aHNumbers.end();
+ for( it = aHNumbers.begin(); it != EndIt; ++it )
+ {
+ drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorH, anAspectLine );
+ }
+ }
+ else
+ {
+ int aNumber = aMarkerSet->getNumMarkers();
+ for( int i = 0; i < aNumber; i++ )
+ drawMarker( aXCoord[i], anYCoord[i], aRadius, colorN, anAspectLine );
+
+ EndIt = anUSelNumbers.end();
+ for( it = anUSelNumbers.begin(); it != EndIt; ++it )
+ drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorN, anAspectLine );
+
+ EndIt = aSelNumbers.end();
+ for( it = aSelNumbers.begin(); it != EndIt; ++it )
+ drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorS, anAspectLine );
+ }
+ if( aMarkerSet->getGLText()->getText() != "" )
+ {
+ //float aXPos = 0, anYPos = 0;
+ //aMarkerSet->getGLText()->getPosition( aXPos, anYPos );
+ //drawText( aMarkerSet->getGLText()->getText(), aXPos, anYPos, colorN, &aMarkerSet->getGLText()->getFont(), aMarkerSet->getGLText()->getSeparator() );
+ drawText( aMarkerSet );
+ }
+ }
+}
+
+void GLViewer_MarkerDrawer::drawMarker( float& theXCoord, float& theYCoord,
+ float& theRadius, QColor& theColor, GLViewer_AspectLine* theAspectLine )
+{
+ glColor3f( ( GLfloat )theColor.red() / 255,
+ ( GLfloat )theColor.green() / 255,
+ ( GLfloat )theColor.blue() / 255 );
+
+ glLineWidth( theAspectLine->getLineWidth() );
+
+ if ( theAspectLine->getLineType() == 0 )
+ glBegin( GL_LINE_LOOP );
+ else
+ glBegin( GL_LINE_STRIP);
+
+ for ( int i = 0; i < SEGMENTS; i++ )
+ glVertex2f( theXCoord + cos_table[i] * theRadius / myXScale,
+ theYCoord + sin_table[i] * theRadius / myYScale );
+ glEnd();
+}
+
+/***************************************************************************
+** Class: GLViewer_PolylineDrawer
+** Descr: Drawer for GLViewer_Polyline
+** Module: GLViewer
+** Created: UI team, 03.10.01
+****************************************************************************/
+
+GLViewer_PolylineDrawer::GLViewer_PolylineDrawer()
+:GLViewer_Drawer()
+{
+ myObjectType = "GLViewer_Polyline";
+}
+
+GLViewer_PolylineDrawer::~GLViewer_PolylineDrawer()
+{
+}
+
+void GLViewer_PolylineDrawer::create( float xScale, float yScale, bool onlyUpdate )
+{
+ QValueList<GLViewer_Object*>::Iterator aObjectIt = myObjects.begin();
+ QValueList<GLViewer_Object*>::Iterator aObjectEndIt = myObjects.end();
+
+ myXScale = xScale;
+ myYScale = yScale;
+
+ QColor color, colorN, colorH, colorS;
+ GLViewer_AspectLine* anAspect = NULL;
+ GLViewer_Polyline* aPolyline = NULL;
+ for( ; aObjectIt != aObjectEndIt; aObjectIt++ )
+ {
+ anAspect = (*aObjectIt)->getAspectLine();
+ aPolyline = (GLViewer_Polyline*)(*aObjectIt);
+
+
+ anAspect->getLineColors( colorN, colorH, colorS );
+ if( onlyUpdate )
+ {
+ if( aPolyline->isHighlighted() )
+ color = colorH;
+ else if( aPolyline->isSelected() )
+ color = colorS;
+ else
+ color = colorN;
+ }
+ else
+ {
+ if( aPolyline->isSelected() )
+ color = colorS;
+ else
+ color = colorN;
+ }
+
+ float* aXCoord = aPolyline->getXCoord();
+ float* anYCoord = aPolyline->getYCoord();
+ int aSize = aPolyline->getNumber();
+
+ glColor3f( ( GLfloat )color.red() / 255,
+ ( GLfloat )color.green() / 255,
+ ( GLfloat )color.blue() / 255 );
+
+ glLineWidth( anAspect->getLineWidth() );
+
+ if ( anAspect->getLineType() == 0 )
+ glBegin( GL_LINE_LOOP );
+ else
+ glBegin( GL_LINE_STRIP);
+
+ for( int i = 0; i < aSize ; i++ )
+ glVertex2f( aXCoord[ i ], anYCoord[ i ] );
+
+ if( aPolyline->isClosed() )
+ glVertex2f( aXCoord[ 0 ], anYCoord[ 0 ] );
+
+ glEnd();
+
+ if( aPolyline->getGLText()->getText() != "" )
+ {
+ //float aXPos = 0, anYPos = 0;
+ //aPolyline->getGLText()->getPosition( aXPos, anYPos );
+ //drawText( aPolyline->getGLText()->getText(), aXPos, anYPos, color, &aPolyline->getGLText()->getFont(), aPolyline->getGLText()->getSeparator() );
+ drawText( aPolyline );
+ }
+ }
+}
+
+/***************************************************************************
+** Class: GLViewer_TextDrawer
+** Descr:
+** Module: GLViewer
+** Created: UI team, 27.02.04
+****************************************************************************/
+
+GLViewer_TextDrawer::GLViewer_TextDrawer()
+: GLViewer_Drawer()
+{
+ myObjectType = "GLViewer_TextObject";
+}
+
+GLViewer_TextDrawer::~GLViewer_TextDrawer()
+{
+}
+
+void GLViewer_TextDrawer::create( float xScale, float yScale, bool onlyUpdate )
+{
+ QValueList<GLViewer_Object*>::Iterator aObjectIt = myObjects.begin();
+ QValueList<GLViewer_Object*>::Iterator aObjectEndIt = myObjects.end();
+
+ myXScale = xScale;
+ myYScale = yScale;
+
+ QColor color, colorN, colorH, colorS;
+ GLViewer_AspectLine* anAspect = NULL;
+ GLViewer_TextObject* anObject = NULL;
+ //float aXPos = 0, anYPos = 0;
+ for( ; aObjectIt != aObjectEndIt; aObjectIt++ )
+ {
+ anObject = (GLViewer_TextObject*)(*aObjectIt);
+ anAspect = anObject->getAspectLine();
+
+ anAspect->getLineColors( colorN, colorH, colorS );
+ if( onlyUpdate )
+ {
+ if( anObject->isHighlighted() )
+ color = colorH;
+ else if( anObject->isSelected() )
+ color = colorS;
+ else
+ color = colorN;
+ }
+ else
+ {
+ if( anObject->isSelected() )
+ color = colorS;
+ else
+ color = colorN;
+ }
+
+ //anObject->getGLText()->getPosition( aXPos, anYPos );
+ //drawText( anObject->getGLText()->getText(), aXPos, anYPos, color, &(anObject->getGLText()->getFont()), anObject->getGLText()->getSeparator() );
+ drawText( anObject );
+ }
+}
+
+void GLViewer_TextDrawer::updateObjects()
+{
+ QValueList<GLViewer_Object*>::Iterator aObjectIt = myObjects.begin();
+ QValueList<GLViewer_Object*>::Iterator aObjectEndIt = myObjects.end();
+ for( ; aObjectIt != aObjectEndIt; aObjectIt++ )
+ (*aObjectIt)->compute();
+}
--- /dev/null
+// File: GLViewer_BaseDrawers.h
+// Created: November, 2004
+// Author: OCC team
+// Copyright (C) CEA 2004
+
+#ifndef GLVIEWER_BASEDRAWERS_H
+#define GLVIEWER_BASEDRAWERS_H
+
+#include <qcolor.h>
+#include <qobject.h>
+#include <qfile.h>
+#include <qfont.h>
+#include <qgl.h>
+
+#include "GLViewer.h"
+#include "GLViewer_Drawer.h"
+
+class GLViewer_AspectLine;
+
+#ifdef WNT
+#pragma warning( disable:4251 )
+#endif
+
+// Class: GLViewer_MarkerDrawer
+// Descr: Drawer for GLViewer_MarkerSet
+
+class GLVIEWER_API GLViewer_MarkerDrawer : public GLViewer_Drawer
+{
+public:
+ GLViewer_MarkerDrawer();
+ ~GLViewer_MarkerDrawer();
+
+ virtual void create( float, float, bool );
+
+private:
+ void drawMarker( float&, float&, float&, QColor&, GLViewer_AspectLine* );
+};
+
+// Class: GLViewer_PolylineDrawer
+// Descr: Drawer for GLViewer_Polyline
+
+class GLVIEWER_API GLViewer_PolylineDrawer : public GLViewer_Drawer
+{
+public:
+ GLViewer_PolylineDrawer();
+ ~GLViewer_PolylineDrawer();
+
+ virtual void create( float, float, bool );
+};
+
+// Class: GLViewer_TextDrawer
+// Descr:
+
+class GLVIEWER_API GLViewer_TextDrawer: public GLViewer_Drawer
+{
+
+public:
+ GLViewer_TextDrawer();
+ ~GLViewer_TextDrawer();
+
+ virtual void create( float, float, bool );
+ void updateObjects(); //after update font
+};
+
+#ifdef WNT
+#pragma warning ( default:4251 )
+#endif
+
+#endif
--- /dev/null
+/***************************************************************************
+** Class: GLViewer_BaseObjects
+** Descr: Internal OpenGL Objects
+** Module: GLViewer
+** Created: UI team, 02.09.02
+****************************************************************************/
+
+//#include <GLViewerAfx.h>
+#include "GLViewer_BaseObjects.h"
+#include "GLViewer_BaseDrawers.h"
+#include "GLViewer_AspectLine.h"
+#include "GLViewer_CoordSystem.h"
+#include "GLViewer_Text.h"
+#include "GLViewer_Group.h"
+
+#include "GLViewer_Drawer.h"
+
+//#include <cmath>
+//using namespace std;
+
+/***************************************************************************
+** Class: GLViewer_MarkerSet
+** Descr: OpenGL MarkerSet
+** Module: GLViewer
+** Created: UI team, 03.09.02
+****************************************************************************/
+
+GLViewer_MarkerSet::GLViewer_MarkerSet( int number, float size, const QString& toolTip ) :
+ GLViewer_Object(),
+ myNumber( 0 ),
+ myXCoord( 0 ),
+ myYCoord( 0 )
+{
+
+ myMarkerSize = size;
+ myHNumbers.clear();
+ myUHNumbers.clear();
+ mySelNumbers.clear();
+ myUSelNumbers.clear();
+ myCurSelNumbers.clear();
+ myPrevHNumbers.clear();
+
+ myType = "GLViewer_MarkerSet";
+ myToolTipText = toolTip;
+
+ setNumMarkers( number );
+}
+
+GLViewer_MarkerSet::~GLViewer_MarkerSet()
+{
+ if ( myXCoord )
+ delete[] myXCoord;
+ if ( myYCoord )
+ delete[] myYCoord;
+}
+
+void AddCoordsToHPGL( QString& buffer, QString command, GLViewer_CoordSystem* aViewerCS,
+ GLViewer_CoordSystem* aPaperCS, double x, double y, bool NewLine = true )
+{
+ if( aViewerCS && aPaperCS )
+ aViewerCS->transform( *aPaperCS, x, y );
+
+ QString temp = command + "%1, %2;";
+ buffer += temp.arg( x ).arg( y );
+ if( NewLine )
+ buffer += ";\n";
+}
+
+void AddCoordsToPS( QString& buffer, QString command, GLViewer_CoordSystem* aViewerCS,
+ GLViewer_CoordSystem* aPaperCS, double x, double y, bool NewLine = true )
+{
+ if( aViewerCS && aPaperCS )
+ aViewerCS->transform( *aPaperCS, x, y );
+
+ QString temp = "%1 %2 "+command;
+ buffer += temp.arg( x ).arg( y );
+ if( NewLine )
+ buffer += "\n";
+}
+
+void AddLineAspectToPS( QString& buffer, GLViewer_AspectLine* anAspect,
+ GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPaperCS )
+{
+ if( anAspect )
+ {
+ QColor col1, col2, col3;
+ anAspect->getLineColors( col1, col2, col3 );
+
+ float aWidth = anAspect->getLineWidth();
+ int aLineType = anAspect->getLineType();
+
+ QString temp = "%1 %2 %3 setrgbcolor\n";
+ double rr = 1 - double( col1.red() ) / 255.0, //color inverting
+ gg = 1 - double( col1.green() ) / 255.0,
+ bb = 1 - double( col1.blue() ) / 255.0;
+
+ buffer += temp.arg( rr ).arg( gg ).arg( bb );
+
+ double x_stretch, y_stretch;
+ aViewerCS->getStretching( *aPaperCS, x_stretch, y_stretch );
+ buffer += temp.arg( x_stretch * aWidth )+" setlinewidth\n";
+
+ if( aLineType==0 ) //solid
+ buffer += "[] 0 setdash\n";
+ else if( aLineType==1 ) //strip
+ buffer += "[2] 0 setdash\n";
+ }
+}
+
+#ifdef WIN32
+HPEN AddLineAspectToEMF( HDC hDC, GLViewer_AspectLine* anAspect,
+ GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPaperCS )
+{
+ if( anAspect )
+ {
+ QColor col1, col2, col3;
+ anAspect->getLineColors( col1, col2, col3 );
+
+ double x_stretch, y_stretch;
+ aViewerCS->getStretching( *aPaperCS, x_stretch, y_stretch );
+
+ double aWidth = anAspect->getLineWidth()*x_stretch;
+ int aLineType = anAspect->getLineType();
+
+ return CreatePen( PS_SOLID, aWidth, RGB( 255-col1.red(), 255-col1.green(), 255-col1.blue() ) );
+ }
+ else
+ return NULL;
+}
+#endif
+
+bool GLViewer_MarkerSet::translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS )
+{
+ int noPoints = 20;
+
+ QString aBuffer = "newpath\n";
+
+ AddLineAspectToPS( aBuffer, getAspectLine(), aViewerCS, aPSCS );
+
+ for( int i=0; i<myNumber; i++ )
+ {
+ aBuffer += "\n";
+
+ double x_stretch, y_stretch;
+ aViewerCS->getStretching( *aPSCS, x_stretch, y_stretch );
+
+ double x0 = myXCoord[i],
+ y0 = myYCoord[i],
+ r = myMarkerSize,
+ x, y;
+
+ for( int j=0; j<=noPoints; j++ )
+ {
+ x = x0 + r*cos( double(j)*2*PI/double(noPoints) );
+ y = y0 + r*sin( double(j)*2*PI/double(noPoints) );
+ if( j==0 )
+ AddCoordsToPS( aBuffer, "moveto", aViewerCS, aPSCS, x, y, true );
+ else
+ AddCoordsToPS( aBuffer, "lineto", aViewerCS, aPSCS, x, y, true );
+ }
+ }
+ aBuffer+="closepath\nstroke\n";
+
+ hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
+
+ return true;
+}
+
+bool GLViewer_MarkerSet::translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS,
+ GLViewer_CoordSystem* aHPGLCS )
+{
+ int noPoints = 20;
+ QString aBuffer;
+ for( int i=0; i<myNumber; i++ )
+ {
+ aBuffer = "";
+
+ double x_stretch, y_stretch;
+ aViewerCS->getStretching( *aHPGLCS, x_stretch, y_stretch );
+
+ double x0 = myXCoord[i],
+ y0 = myYCoord[i],
+ r = myMarkerSize,
+ x, y;
+
+ AddCoordsToHPGL( aBuffer, "PA", aViewerCS, aHPGLCS, x0+r, y0 );
+ aBuffer+="PD;\n";
+ for( int j=1; j<=noPoints; j++ )
+ {
+ x = x0 + r*cos( double(j)*2*PI/double(noPoints) );
+ y = y0 + r*sin( double(j)*2*PI/double(noPoints) );
+ AddCoordsToHPGL( aBuffer, "PD", aViewerCS, aHPGLCS, x, y );
+ }
+ aBuffer+="PU;\n";
+
+ hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
+ }
+
+ return true;
+}
+
+#ifdef WIN32
+bool GLViewer_MarkerSet::translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS )
+{
+ int noPoints = 20;
+ if( !aViewerCS || !aEMFCS )
+ return false;
+
+ HPEN pen = AddLineAspectToEMF( dc, getAspectLine(), aViewerCS, aEMFCS );
+ HGDIOBJ old = SelectObject( dc, pen );
+
+ for( int i=0; i<myNumber; i++ )
+ {
+ double x0 = myXCoord[i],
+ y0 = myYCoord[i],
+ r = myMarkerSize,
+ x, y;
+
+ for( int j=0; j<=noPoints; j++ )
+ {
+ x = x0 + r*cos( double(j)*2*PI/double(noPoints) );
+ y = y0 + r*sin( double(j)*2*PI/double(noPoints) );
+ aViewerCS->transform( *aEMFCS, x, y );
+ if( j==0 )
+ MoveToEx( dc, x, y, NULL );
+ else
+ LineTo( dc, x, y );
+ }
+ }
+
+ SelectObject( dc, old );
+ if( pen )
+ DeleteObject( pen );
+ return true;
+}
+#endif
+
+
+void GLViewer_MarkerSet::compute()
+{
+// cout << "GLViewer_MarkerSet::compute" << endl;
+ GLfloat xa = myXCoord[0];
+ GLfloat xb = myXCoord[0];
+ GLfloat ya = myYCoord[0];
+ GLfloat yb = myYCoord[0];
+
+ for ( int i = 0; i < myNumber; i++ )
+ {
+ xa = QMIN( xa, myXCoord[i] );
+ xb = QMAX( xb, myXCoord[i] );
+ ya = QMIN( ya, myYCoord[i] );
+ yb = QMAX( yb, myYCoord[i] );
+ }
+
+ myXGap = ( xb - xa ) / 10;
+ myYGap = ( yb - ya ) / 10;
+
+ myRect->setLeft( xa - myXGap );
+ myRect->setTop( yb + myYGap );
+ myRect->setRight( xb + myXGap );
+ myRect->setBottom( ya - myYGap );
+}
+
+GLViewer_Drawer* GLViewer_MarkerSet::createDrawer()
+{
+// cout << "GLViewer_MarkerSet::createDrawer" << endl;
+ return myDrawer = new GLViewer_MarkerDrawer();
+}
+
+
+GLboolean GLViewer_MarkerSet::highlight( GLfloat x, GLfloat y, GLfloat tol, GLboolean isCircle )
+{
+ if( !myIsVisible )
+ return false;
+// cout << "GLViewer_MarkerSet::highlight " << x <<" " << y << " " << tol << endl;
+ int count = 0;
+ GLfloat xdist, ydist, radius;
+ QValueList<int>::Iterator it;
+ QValueList<int> curHNumbers;
+ bool isFound;
+ GLboolean update;
+ int cnt = 0;
+
+ radius = tol - myMarkerSize / 2.;
+
+ myUHNumbers += myHNumbers;
+ myHNumbers.clear();
+
+ for ( int i = 0; i < myNumber; i++ )
+ {
+ xdist = ( myXCoord[i] - x ) * myXScale;
+ ydist = ( myYCoord[i] - y ) * myYScale;
+
+// if ( isCircle && ( xdist * xdist + ydist * ydist <= radius * radius ) ||
+ if ( isCircle && ( xdist * xdist + ydist * ydist <= myMarkerSize * myMarkerSize ) ||
+ !isCircle && ( fabs( xdist ) <= radius && fabs( ydist ) <= radius ) )
+ {
+ isFound = FALSE;
+ count++;
+ for ( it = myCurSelNumbers.begin(); it != myCurSelNumbers.end(); ++it )
+ if( i == *it )
+ {
+ isFound = TRUE;
+ curHNumbers.append( i );
+ }
+
+ if( !isFound )
+ myHNumbers.append( i );
+ else
+ cnt++;
+ }
+ }
+ myCurSelNumbers = curHNumbers;
+
+ myIsHigh = ( GLboolean )count;
+ update = ( GLboolean )( myHNumbers != myPrevHNumbers );
+
+ myPrevHNumbers = myHNumbers;
+
+ //cout << "GLViewer_MarkerSet::highlight complete with " << (int)myIsHigh << endl;
+ return update;
+}
+
+GLboolean GLViewer_MarkerSet::unhighlight()
+{
+ if( !myHNumbers.isEmpty() )
+ {
+ myUHNumbers += myHNumbers;
+ myPrevHNumbers.clear();
+ myHNumbers.clear();
+ //??? myCurSelNumbers.clear();
+ return GL_TRUE;
+ }
+
+ return GL_FALSE;
+}
+
+GLboolean GLViewer_MarkerSet::select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect, GLboolean isFull,
+ GLboolean isCircle, GLboolean isShift )
+{
+ if( !myIsVisible )
+ return false;
+// cout << "GLViewer_MarkerSet::select " << x << " " << y << endl;
+ int count = 0;
+ GLfloat xdist, ydist, radius;
+ QValueList<int>::Iterator it;
+ QValueList<int>::Iterator it1;
+ QValueList<int>::Iterator remIt;
+ QValueList<int>::Iterator curIt;
+
+ radius = tol - myMarkerSize / 2.;
+
+ if( radius < myMarkerSize / 2.)
+ radius = myMarkerSize / 2.;
+
+ count = isShift ? mySelNumbers.count() : 0;
+
+ myUSelNumbers = mySelNumbers;
+
+ if ( !isShift )
+ {
+ mySelNumbers.clear();
+ myCurSelNumbers.clear();
+ }
+
+ for ( int i = 0; i < myNumber; i++ )
+ {
+ xdist = ( myXCoord[i] - x ) * myXScale;
+ ydist = ( myYCoord[i] - y ) * myYScale;
+
+ //if ( isCircle && ( xdist * xdist + ydist * ydist <= radius * radius ) ||
+ if ( isCircle && ( xdist * xdist + ydist * ydist <= myMarkerSize * myMarkerSize ) ||
+ !isCircle && ( fabs( xdist ) <= radius && fabs( ydist ) <= radius ) )
+ {
+ count++;
+ if ( isShift )
+ {
+ bool isFound = FALSE;
+ for( it = mySelNumbers.begin(); it != mySelNumbers.end(); ++it )
+ if ( *it == i )
+ {
+ myUSelNumbers.append( *it );
+ remIt = it;
+ isFound = TRUE;
+ break;
+ }
+
+ if ( !isFound )
+ {
+ mySelNumbers.append( i );
+ myCurSelNumbers.append( i );
+ for ( it1 = myHNumbers.begin(); it1 != myHNumbers.end(); ++it1 )
+ if( i == *it1 )
+ {
+ myHNumbers.remove( it1 );
+ break;
+ }
+ for ( it1 = myUHNumbers.begin(); it1 != myUHNumbers.end(); ++it1 )
+ if( i == *it1 )
+ {
+ myUHNumbers.remove( it1 );
+ break;
+ }
+ }
+ else
+ {
+ mySelNumbers.remove( remIt );
+ for ( curIt = myCurSelNumbers.begin(); curIt != myCurSelNumbers.end(); ++curIt )
+ if( *curIt == *remIt)
+ {
+ myCurSelNumbers.remove( curIt );
+ break;
+ }
+ for ( it1 = myHNumbers.begin(); it1 != myHNumbers.end(); ++it1 )
+ if( i == *it1 )
+ {
+ myHNumbers.remove( it1 );
+ break;
+ }
+ for ( it1 = myUHNumbers.begin(); it1 != myUHNumbers.end(); ++it1 )
+ if( i == *it1 )
+ {
+ myUHNumbers.remove( it1 );
+ break;
+ }
+ }
+ }
+ else
+ {
+ mySelNumbers.append( i );
+ myCurSelNumbers.append( i );
+ for ( it1 = myHNumbers.begin(); it1 != myHNumbers.end(); ++it1 )
+ if( i == *it1 )
+ {
+ myHNumbers.remove( it1 );
+ break;
+ }
+ for ( it1 = myUHNumbers.begin(); it1 != myUHNumbers.end(); ++it1 )
+ if( i == *it1 )
+ {
+ myUHNumbers.remove( it1 );
+ break;
+ }
+ }
+ }
+ }
+
+ for( it = mySelNumbers.begin(); it != mySelNumbers.end(); ++it )
+ for( it1 = myUSelNumbers.begin(); it1 != myUSelNumbers.end(); ++it1 )
+ if( *it == *it1 )
+ {
+ it1 = myUSelNumbers.remove( it1 );
+ it1--;
+ }
+
+ myIsSel = (GLboolean)count;
+
+// cout << "GLViewer_MarkerSet::select complete with " << (int)myIsSel << endl;
+ return myIsSel;
+}
+
+GLboolean GLViewer_MarkerSet::unselect()
+{
+ if( !mySelNumbers.isEmpty() )
+ {
+ myUSelNumbers = mySelNumbers;
+ mySelNumbers.clear();
+ myCurSelNumbers.clear();
+ return GL_TRUE;
+ }
+
+ return GL_FALSE;
+}
+
+GLViewer_Rect* GLViewer_MarkerSet::getUpdateRect()
+{
+ GLViewer_Rect* rect = new GLViewer_Rect();
+
+ rect->setLeft( myRect->left() + myXGap - myMarkerSize / myXScale );
+ rect->setTop( myRect->top() + myYGap + myMarkerSize / myYScale );
+ rect->setRight( myRect->right() - myXGap + myMarkerSize / myXScale );
+ rect->setBottom( myRect->bottom() - myYGap - myMarkerSize / myYScale );
+ //cout << " Additional tolerance " << myMarkerSize / myYScale << endl;
+ //rect->setLeft( myRect->left() - myMarkerSize / myXScale );
+ //rect->setTop( myRect->top() - myMarkerSize / myYScale );
+ //rect->setRight( myRect->right() + myMarkerSize / myXScale );
+ //rect->setBottom( myRect->bottom() + myMarkerSize / myYScale );
+
+ return rect;
+}
+
+
+void GLViewer_MarkerSet::setXCoord( GLfloat* xCoord, int size )
+{
+ myXCoord = new GLfloat[ size ];
+ for( int i = 0; i < size; i++ )
+ myXCoord[i] = xCoord[i];
+}
+
+void GLViewer_MarkerSet::setYCoord( GLfloat* yCoord, int size )
+{
+ myYCoord = new GLfloat[ size ];
+ for( int i = 0; i < size; i++ )
+ myYCoord[i] = yCoord[i];
+}
+
+void GLViewer_MarkerSet::setNumMarkers( GLint number )
+{
+ if ( myNumber == number )
+ return;
+
+ if ( myXCoord && myYCoord )
+ {
+ delete[] myXCoord;
+ delete[] myYCoord;
+ }
+
+ myNumber = number;
+ myXCoord = new GLfloat[ myNumber ];
+ myYCoord = new GLfloat[ myNumber ];
+}
+/*
+void GLViewer_MarkerSet::onSelectionDone( bool append)
+{
+ mySelectedIndexes.Clear();
+ QValueList<int>::Iterator it;
+ //for( it = myMarkers->mySelNumbers.begin(); it != myMarkers->mySelNumbers.end(); ++it )
+ // mySelectedIndexes.Append( *it / 2 ); //!!!
+
+ emit dvMarkersSelected( mySelectedIndexes );
+}
+
+void GLViewer_MarkerSet::onSelectionCancel()
+{
+ mySelectedIndexes.Clear();
+ emit dvMarkersSelected( mySelectedIndexes );
+}
+*/
+void GLViewer_MarkerSet::exportNumbers( QValueList<int>& highlight,
+ QValueList<int>& unhighlight,
+ QValueList<int>& select,
+ QValueList<int>& unselect )
+{
+ highlight = myHNumbers;
+ unhighlight = myUHNumbers;
+ select = mySelNumbers;
+ unselect = myUSelNumbers;
+
+ myUHNumbers = myHNumbers;
+}
+
+bool GLViewer_MarkerSet::addOrRemoveSelected( int index )
+{
+ if( index < 0 || index > myNumber )
+ return FALSE;
+
+ int n = mySelNumbers.findIndex( index );
+ if( n == -1 )
+ mySelNumbers.append( index );
+ else
+ {
+ QValueList<int>::Iterator it;
+ it = mySelNumbers.at( n );
+ mySelNumbers.remove( it );
+ myUSelNumbers.append( index );
+ }
+ return TRUE;
+}
+
+void GLViewer_MarkerSet::addSelected( const TColStd_SequenceOfInteger& seq )
+{
+ for ( int i = 1; i <= seq.Length(); i++ )
+ if( mySelNumbers.findIndex( seq.Value( i ) ) == -1 )
+ mySelNumbers.append( seq.Value( i ) - 1 );
+}
+
+void GLViewer_MarkerSet::setSelected( const TColStd_SequenceOfInteger& seq )
+{
+// for( QValueList<int>::Iterator it = mySelNumbers.begin(); it != mySelNumbers.end(); ++it )
+// if( myUSelNumbers.findIndex( *it ) == -1 )
+// myUSelNumbers.append( *it );
+
+ myUSelNumbers = mySelNumbers;
+ mySelNumbers.clear();
+
+ for ( int i = 1; i <= seq.Length(); i++ )
+ mySelNumbers.append( seq.Value( i ) - 1 );
+}
+
+void GLViewer_MarkerSet::moveObject( float theX, float theY, bool fromGroup )
+{
+ if( !fromGroup && myGroup)
+ {
+ myGroup->dragingObjects( theX, theY );
+ return;
+ }
+ for( int i = 0; i < myNumber; i++ )
+ {
+ myXCoord[i] = myXCoord[i] + theX;
+ myYCoord[i] = myYCoord[i] + theY;
+ }
+ compute();
+}
+
+QByteArray GLViewer_MarkerSet::getByteCopy()
+{
+ int i = 0;
+ int anISize = sizeof( GLint );
+ int aFSize = sizeof( GLfloat );
+
+ QByteArray aObject = GLViewer_Object::getByteCopy();
+
+ QByteArray aResult( anISize + 2*aFSize*myNumber + aFSize + aObject.size());
+
+ char* aPointer = (char*)&myNumber;
+ for( i = 0; i < anISize; i++, aPointer++ )
+ aResult[i] = *aPointer;
+
+ aPointer = (char*)myXCoord;
+ for( ; i < anISize + aFSize*myNumber; i++, aPointer++ )
+ aResult[i] = *aPointer;
+ aPointer = (char*)myYCoord;
+ for( ; i < anISize + 2*aFSize*myNumber; i++, aPointer++ )
+ aResult[i] = *aPointer;
+
+ aPointer = (char*)&myMarkerSize;
+ for( ; i < anISize + 2*aFSize*myNumber + aFSize; i++, aPointer++ )
+ aResult[i] = *aPointer;
+
+
+ for( ; i < aResult.size(); i++ )
+ aResult[i] = aObject[i - anISize - 2*aFSize*myNumber - aFSize];
+
+ return aResult;
+}
+
+bool GLViewer_MarkerSet::initializeFromByteCopy( QByteArray theArray )
+{
+ int i = 0;
+ int anISize = sizeof( GLint );
+ int aFSize = sizeof( GLfloat );
+
+ char* aPointer = (char*)&myNumber;
+ for( i = 0; i < anISize; i++, aPointer++ )
+ *aPointer = theArray[i];
+
+ int aSize = theArray.size();
+ if( aSize < anISize + 2*aFSize*myNumber + aFSize)
+ return false;
+
+ myXCoord = new GLfloat[myNumber];
+ myYCoord = new GLfloat[myNumber];
+ aPointer = (char*)myXCoord;
+ for( ; i < anISize + aFSize*myNumber; i++, aPointer++ )
+ *aPointer = theArray[i];
+ aPointer = (char*)myYCoord;
+ for( ; i < anISize + 2*aFSize*myNumber; i++, aPointer++ )
+ *aPointer = theArray[i];
+
+ aPointer = (char*)&myMarkerSize;
+ for( ; i < anISize + 2*aFSize*myNumber + aFSize; i++, aPointer++ )
+ *aPointer = theArray[i];
+
+ int aCurIndex = anISize + 2*aFSize*myNumber + aFSize;
+ QByteArray aObject( aSize - aCurIndex );
+ for( ; i < aSize; i++ )
+ aObject[i - aCurIndex] = theArray[i];
+
+
+ if( !GLViewer_Object::initializeFromByteCopy( aObject ) || myType != "GLViewer_MarkerSet" )
+ return false;
+
+ myHNumbers.clear();
+ myUHNumbers.clear();
+ mySelNumbers.clear();
+ myUSelNumbers.clear();
+ myCurSelNumbers.clear();
+ myPrevHNumbers.clear();
+
+ return true;
+}
+
+/***************************************************************************
+** Class: GLViewer_Polyline
+** Descr: OpenGL Polyline
+** Module: GLViewer
+** Created: UI team, 03.09.02
+****************************************************************************/
+
+#define SECTIONS 100
+#define DISTANTION 5
+
+GLViewer_Polyline::GLViewer_Polyline( int number, float size, const QString& toolTip ):
+ GLViewer_Object(),
+ myNumber( 0 ),
+ myXCoord( 0 ),
+ myYCoord( 0 )
+{
+ myHighFlag = GL_TRUE;
+
+ myHNumbers.clear();
+ myUHNumbers.clear();
+ mySelNumbers.clear();
+ myUSelNumbers.clear();
+ myCurSelNumbers.clear();
+ myPrevHNumbers.clear();
+
+ setNumber( number );
+
+ myType = "GLViewer_Polyline";
+ myToolTipText = toolTip;
+}
+
+GLViewer_Polyline::~GLViewer_Polyline()
+{
+ if ( myXCoord )
+ delete[] myXCoord;
+ if ( myYCoord )
+ delete[] myYCoord;
+}
+
+bool GLViewer_Polyline::translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS )
+{
+ QString aBuffer = "newpath\n";
+
+ AddLineAspectToPS( aBuffer, getAspectLine(), aViewerCS, aPSCS );
+
+ for( int i=0; i<myNumber; i++ )
+ if( i==0 )
+ AddCoordsToPS( aBuffer, "moveto", aViewerCS, aPSCS, myXCoord[i], myYCoord[i] );
+ else
+ AddCoordsToPS( aBuffer, "lineto", aViewerCS, aPSCS, myXCoord[i], myYCoord[i] );
+
+ if( myIsClosed )
+ AddCoordsToPS( aBuffer, "lineto", aViewerCS, aPSCS, myXCoord[0], myYCoord[0] );
+
+ aBuffer+="closepath\nstroke\n";
+
+ hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
+
+ return true;
+}
+
+bool GLViewer_Polyline::translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS )
+{
+ QString aBuffer = "";
+ for( int i=0; i<myNumber; i++ )
+ {
+ AddCoordsToHPGL( aBuffer, "PA", aViewerCS, aHPGLCS, myXCoord[i], myYCoord[i] );
+ if( i==0 )
+ aBuffer+="PD;\n";
+ }
+
+ if( myIsClosed )
+ AddCoordsToHPGL( aBuffer, "PA", aViewerCS, aHPGLCS, myXCoord[0], myYCoord[0] );
+
+ aBuffer+="PU;\n";
+
+ hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
+
+ return true;
+}
+
+#ifdef WIN32
+bool GLViewer_Polyline::translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS )
+{
+ if( !aViewerCS || !aEMFCS )
+ return false;
+
+ HPEN pen = AddLineAspectToEMF( dc, getAspectLine(), aViewerCS, aEMFCS );
+ HGDIOBJ old = SelectObject( dc, pen );
+
+ double x, y;
+ for( int i=0; i<myNumber; i++ )
+ {
+ x = myXCoord[i];
+ y = myYCoord[i];
+ aViewerCS->transform( *aEMFCS, x, y );
+ if( i==0 )
+ MoveToEx( dc, x, y, NULL );
+ else
+ LineTo( dc, x, y );
+ }
+
+ if( myIsClosed )
+ {
+ x = myXCoord[0];
+ y = myYCoord[0];
+ aViewerCS->transform( *aEMFCS, x, y );
+ LineTo( dc, x, y );
+ }
+
+ SelectObject( dc, old );
+ if( pen )
+ DeleteObject( pen );
+
+ return true;
+}
+#endif
+
+void GLViewer_Polyline::compute()
+{
+// cout << "GLViewer_MarkerSet::compute" << endl;
+ GLfloat xa = myXCoord[0];
+ GLfloat xb = myXCoord[0];
+ GLfloat ya = myYCoord[0];
+ GLfloat yb = myYCoord[0];
+
+ for ( int i = 0; i < myNumber; i++ )
+ {
+ xa = QMIN( xa, myXCoord[i] );
+ xb = QMAX( xb, myXCoord[i] );
+ ya = QMIN( ya, myYCoord[i] );
+ yb = QMAX( yb, myYCoord[i] );
+ }
+
+ GLfloat xGap = ( xb - xa ) / 10;
+ GLfloat yGap = ( yb - ya ) / 10;
+
+ myRect->setLeft( xa - xGap );
+ myRect->setTop( yb + yGap );
+ myRect->setRight( xb + xGap );
+ myRect->setBottom( ya - yGap );
+}
+
+GLViewer_Rect* GLViewer_Polyline::getUpdateRect()
+{
+ GLViewer_Rect* rect = new GLViewer_Rect();
+
+ rect->setLeft( myRect->left() - myXGap );
+ rect->setTop( myRect->top() + myYGap );
+ rect->setRight( myRect->right() + myXGap );
+ rect->setBottom( myRect->bottom() - myYGap );
+
+ return rect;
+}
+
+GLViewer_Drawer* GLViewer_Polyline::createDrawer()
+{
+// cout << "GLViewer_MarkerSet::createDrawer" << endl;
+ return myDrawer = new GLViewer_PolylineDrawer();
+}
+
+GLboolean GLViewer_Polyline::highlight( GLfloat x, GLfloat y, GLfloat tol, GLboolean isCircle )
+{
+ if( !myIsVisible )
+ return false;
+ GLfloat xa, xb, ya, yb, l;
+ GLfloat rsin, rcos, r, ra, rb;
+ GLboolean update;
+ GLboolean highlighted = myIsHigh;
+
+ myIsHigh = GL_FALSE;
+
+ int c = 0;
+ if( myIsClosed )
+ c = 1;
+
+ for( int i = 0; i < myNumber-1+c; i++ )
+ {
+ xa = myXCoord[i];
+ ya = myYCoord[i];
+ if( i != myNumber-1 )
+ {
+ xb = myXCoord[i+1];
+ yb = myYCoord[i+1];
+ }
+ else
+ {
+ xb = myXCoord[0];
+ yb = myYCoord[0];
+ }
+
+ l = sqrt( (xb-xa)*(xb-xa) + (yb-ya)*(yb-ya) );
+ rsin = (yb-ya) / l;
+ rcos = (xb-xa) / l;
+ r = ( (x-xa)*(y-yb) - (x-xb)*(y-ya) ) / ( rsin*(ya-yb) + rcos*(xa-xb) );
+ ra = sqrt( (x-xa)*(x-xa) + (y-ya)*(y-ya) );
+ rb = sqrt( (x-xb)*(x-xb) + (y-yb)*(y-yb) );
+ if( fabs( r ) * myXScale <= DISTANTION && ra <= l + DISTANTION && rb <= l + DISTANTION )
+ {
+ myIsHigh = GL_TRUE;
+ break;
+ }
+ }
+
+ if( !myHighFlag && myIsHigh )
+ myIsHigh = GL_FALSE;
+ else
+ myHighFlag = GL_TRUE;
+
+ update = ( GLboolean )( myIsHigh != highlighted );
+
+// cout << "GLViewer_Polyline::highlight complete with " << (int)myIsHigh << endl;
+ return update;
+}
+
+GLboolean GLViewer_Polyline::unhighlight()
+{
+// if( !myHNumbers.isEmpty() )
+// {
+// myUHNumbers = myHNumbers;
+// myHNumbers.clear();
+// return GL_TRUE;
+// }
+
+ if( myIsHigh )
+ {
+ myIsHigh = GL_FALSE;
+ return GL_TRUE;
+ }
+
+ return GL_FALSE;
+}
+
+GLboolean GLViewer_Polyline::select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect, GLboolean isFull,
+ GLboolean isCircle, GLboolean isShift )
+{
+ if( !myIsVisible )
+ return false;
+ GLfloat xa, xb, ya, yb, l;
+ GLfloat rsin, rcos, r, ra, rb;
+ GLboolean update;
+ GLboolean selected = myIsSel;
+
+ myIsSel = GL_FALSE;
+
+ int c = 0;
+ if( myIsClosed )
+ c = 1;
+
+ for( int i = 0; i < myNumber-1+c; i++ )
+ {
+ xa = myXCoord[i];
+ ya = myYCoord[i];
+ if( i != myNumber-1 )
+ {
+ xb = myXCoord[i+1];
+ yb = myYCoord[i+1];
+ }
+ else
+ {
+ xb = myXCoord[0];
+ yb = myYCoord[0];
+ }
+
+ l = sqrt( (xb-xa)*(xb-xa) + (yb-ya)*(yb-ya) );
+ rsin = (yb-ya) / l;
+ rcos = (xb-xa) / l;
+ r = ( (x-xa)*(y-yb) - (x-xb)*(y-ya) ) / ( rsin*(ya-yb) + rcos*(xa-xb) );
+ ra = sqrt( (x-xa)*(x-xa) + (y-ya)*(y-ya) );
+ rb = sqrt( (x-xb)*(x-xb) + (y-yb)*(y-yb) );
+ if( fabs( r ) * myXScale <= DISTANTION && ra <= l + DISTANTION && rb <= l + DISTANTION )
+ {
+ myIsSel = GL_TRUE;
+ break;
+ }
+ }
+
+ if ( myIsSel )
+ {
+ myHighFlag = GL_FALSE;
+ myIsHigh = GL_FALSE;
+ }
+ else
+ myHighFlag = GL_TRUE;
+
+ update = ( GLboolean )( myIsSel != selected );
+
+ // cout << "GLViewer_Polyline::select complete with " << (int)myIsSel << endl;
+
+ // return update; !!!!!!!!!!!!!!!!!!!!!!!!!!! no here
+ return myIsSel;
+}
+
+GLboolean GLViewer_Polyline::unselect()
+{
+// if( !mySelNumbers.isEmpty() )
+// {
+// myUSelNumbers = mySelNumbers;
+// mySelNumbers.clear();
+// myCurSelNumbers.clear();
+// return GL_TRUE;
+// }
+
+ if( myIsSel )
+ {
+ myIsSel = GL_FALSE;
+ return GL_TRUE;
+ }
+
+ return GL_FALSE;
+}
+
+void GLViewer_Polyline::setXCoord( GLfloat* xCoord, int size )
+{
+ myXCoord = new GLfloat[ size ];
+ for( int i = 0; i < size; i++ )
+ myXCoord[i] = xCoord[i];
+}
+
+void GLViewer_Polyline::setYCoord( GLfloat* yCoord, int size )
+{
+ myYCoord = new GLfloat[ size ];
+ for( int i = 0; i < size; i++ )
+ myYCoord[i] = yCoord[i];
+}
+
+void GLViewer_Polyline::setNumber( GLint number )
+{
+ if ( myNumber == number )
+ return;
+
+ if ( myXCoord && myYCoord )
+ {
+ delete[] myXCoord;
+ delete[] myYCoord;
+ }
+
+ myNumber = number;
+ myXCoord = new GLfloat[ myNumber ];
+ myYCoord = new GLfloat[ myNumber ];
+}
+/*
+void GLViewer_Polyline::onSelectionDone( bool append)
+{
+ mySelectedIndexes.Clear();
+ QValueList<int>::Iterator it;
+ //for( it = myMarkers->mySelNumbers.begin(); it != myMarkers->mySelNumbers.end(); ++it )
+ // mySelectedIndexes.Append( *it / 2 ); //!!!
+}
+
+void GLViewer_Polyline::onSelectionCancel()
+{
+ mySelectedIndexes.Clear();
+}
+*/
+void GLViewer_Polyline::exportNumbers( QValueList<int>& highlight,
+ QValueList<int>& unhighlight,
+ QValueList<int>& select,
+ QValueList<int>& unselect )
+{
+ highlight = myHNumbers;
+ unhighlight = myUHNumbers;
+ select = mySelNumbers;
+ unselect = myUSelNumbers;
+}
+
+void GLViewer_Polyline::moveObject( float theX, float theY, bool fromGroup )
+{
+ if( !fromGroup && myGroup)
+ {
+ myGroup->dragingObjects( theX, theY );
+ return;
+ }
+ for( int i = 0; i < myNumber; i++ )
+ {
+ myXCoord[i] = myXCoord[i] + theX;
+ myYCoord[i] = myYCoord[i] + theY;
+ }
+ compute();
+}
+
+QByteArray GLViewer_Polyline::getByteCopy()
+{
+ int i = 0;
+ int anISize = sizeof( GLint );
+ int aFSize = sizeof( GLfloat );
+ int aBSize = sizeof( GLboolean );
+
+ QByteArray aObject = GLViewer_Object::getByteCopy();
+
+ QByteArray aResult( aFSize*myNumber*2 + anISize + 2*aBSize + aObject.size());
+
+ char* aPointer = (char*)&myNumber;
+ for( i = 0; i < anISize; i++, aPointer++ )
+ aResult[i] = *aPointer;
+
+ aPointer = (char*)myXCoord;
+ for( ; i < anISize + aFSize*myNumber; i++, aPointer++ )
+ aResult[i] = *aPointer;
+ aPointer = (char*)myYCoord;
+ for( ; i < anISize + 2*aFSize*myNumber; i++, aPointer++ )
+ aResult[i] = *aPointer;
+
+ aPointer = (char*)&myIsClosed;
+ for( ; i < anISize + 2*aFSize*myNumber + aBSize; i++, aPointer++ )
+ aResult[i] = *aPointer;
+ aPointer = (char*)&myHighSelAll;
+ for( ; i < anISize + 2*aFSize*myNumber + 2*aBSize; i++, aPointer++ )
+ aResult[i] = *aPointer;
+
+ for( ; i < aResult.size(); i++ )
+ aResult[i] = aObject[i - anISize - 2*aFSize*myNumber - 2*aBSize];
+
+ return aResult;
+}
+
+
+bool GLViewer_Polyline::initializeFromByteCopy( QByteArray theArray )
+{
+ int i = 0;
+ int anISize = sizeof( GLint );
+ int aFSize = sizeof( GLfloat );
+ int aBSize = sizeof( GLboolean );
+
+ char* aPointer = (char*)&myNumber;
+ for( i = 0; i < anISize; i++, aPointer++ )
+ *aPointer = theArray[i];
+
+ int aSize = theArray.size();
+ if( aSize < aFSize*myNumber*2 + anISize + 2*aBSize )
+ return false;
+
+ myXCoord = new GLfloat[myNumber];
+ myYCoord = new GLfloat[myNumber];
+ aPointer = (char*)myXCoord;
+ for( ; i < anISize + aFSize*myNumber; i++, aPointer++ )
+ *aPointer = theArray[i];
+ aPointer = (char*)myYCoord;
+ for( ; i < anISize + 2*aFSize*myNumber; i++, aPointer++ )
+ *aPointer = theArray[i];
+
+ aPointer = (char*)&myIsClosed;
+ for( ; i < anISize + 2*aFSize*myNumber + aBSize; i++, aPointer++ )
+ *aPointer = theArray[i];
+ aPointer = (char*)&myHighSelAll;
+ for( ; i < anISize + 2*aFSize*myNumber + 2*aBSize; i++, aPointer++ )
+ *aPointer = theArray[i];
+
+ int aCurIndex = anISize + 2*aFSize*myNumber + 2*aBSize;
+ QByteArray aObject( aSize - aCurIndex );
+ for( ; i < aSize; i++ )
+ aObject[i - aCurIndex] = theArray[i];
+
+ if( !GLViewer_Object::initializeFromByteCopy( aObject ) || myType != "GLViewer_Polyline" )
+ return false;
+
+ myHNumbers.clear();
+ myUHNumbers.clear();
+ mySelNumbers.clear();
+ myUSelNumbers.clear();
+ myCurSelNumbers.clear();
+ myPrevHNumbers.clear();
+
+ return true;
+}
+
+/***************************************************************************
+** Class: GLViewer_TextObject
+** Descr: Text as Object for OpenGL
+** Module: GLViewer
+** Created: UI team, 12.02.04
+****************************************************************************/
+
+GLViewer_TextObject::GLViewer_TextObject( const QString& theStr, float xPos, float yPos,
+ const QColor& color, const QString& toolTip )
+ : GLViewer_Object()
+{
+ myGLText = new GLViewer_Text( theStr, xPos, yPos, color );
+ myWidth = 0;
+ myHeight = 0;
+
+ myHighFlag = GL_TRUE;
+
+ myToolTipText = toolTip;
+}
+GLViewer_TextObject::~GLViewer_TextObject()
+{
+ if ( myGLText )
+ delete myGLText;
+}
+
+bool GLViewer_TextObject::translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS )
+{
+ QString aText = myGLText->getText();
+ float xPos, yPos;
+ myGLText->getPosition( xPos, yPos );
+
+ QString aBuffer = "/Times-Roman findfont\n";
+ aBuffer += "12 scalefont setfont\n";
+
+ AddCoordsToPS( aBuffer, "moveto", aViewerCS, aPSCS, double(xPos), double(yPos) );
+ aBuffer += "(" + aText + ") show\n";
+
+ hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
+
+ return true;
+}
+
+bool GLViewer_TextObject::translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS )
+{
+ QString aText = myGLText->getText();
+ float xPos, yPos;
+ myGLText->getPosition( xPos, yPos );
+
+ QString aBuffer = "";
+ AddCoordsToHPGL( aBuffer, "PA", aViewerCS, aHPGLCS, double(xPos), double(yPos) );
+
+ aBuffer = "LB" + aText + "#;";
+
+ hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
+
+ return true;
+}
+
+#ifdef WIN32
+bool GLViewer_TextObject::translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS )
+{
+ QString aText = myGLText->getText();
+ float xPos, yPos;
+ myGLText->getPosition( xPos, yPos );
+
+ double x = double( xPos ),
+ y = double( yPos );
+
+ aViewerCS->transform( *aEMFCS, x, y );
+ const char* str = aText.ascii();
+
+ int nHeight = 35*14; // height of font
+ int nWidth = 35*12; // average character width
+ int nEscapement = 0; // angle of escapement
+ int nOrientation = 0; // base-line orientation angle
+ int fnWeight = FW_NORMAL; // font weight
+ DWORD fdwItalic = FALSE; // italic attribute option
+ DWORD fdwUnderline = FALSE; // underline attribute option
+ DWORD fdwStrikeOut = FALSE; // strikeout attribute option
+ DWORD fdwCharSet = ANSI_CHARSET; // character set identifier
+ DWORD fdwOutputPrecision = OUT_DEFAULT_PRECIS; // output precision
+ DWORD fdwClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
+ DWORD fdwQuality = PROOF_QUALITY; // output quality
+ DWORD fdwPitchAndFamily = FIXED_PITCH | FF_DONTCARE; // pitch and family
+ LPCTSTR lpszFace = NULL; // typeface name
+
+
+ HFONT aFont = CreateFont( nHeight, nWidth, nEscapement, nOrientation, fnWeight, fdwItalic,
+ fdwUnderline, fdwStrikeOut, fdwCharSet, fdwOutputPrecision,
+ fdwClipPrecision, fdwQuality, fdwPitchAndFamily, lpszFace );
+ LOGBRUSH aBrushData;
+ aBrushData.lbStyle = BS_HOLLOW;
+
+ HBRUSH aBrush = CreateBrushIndirect( &aBrushData );
+
+ HGDIOBJ old1 = SelectObject( dc, aFont );
+ HGDIOBJ old2 = SelectObject( dc, aBrush );
+
+ TextOut( dc, x, y, str, aText.length() );
+
+ SelectObject ( dc, old1 );
+ SelectObject ( dc, old2 );
+
+ DeleteObject( aFont );
+
+ return true;
+}
+#endif
+
+GLViewer_Drawer* GLViewer_TextObject::createDrawer()
+{
+ myDrawer = new GLViewer_TextDrawer();
+ compute();
+ return myDrawer;
+}
+
+void GLViewer_TextObject::compute()
+{
+ float xPos, yPos;
+ QString aStr = myGLText->getText();
+ myGLText->getPosition( xPos, yPos );
+
+ myWidth = myGLText->getWidth();
+ myHeight = myGLText->getHeight();
+ myRect->setLeft( xPos );
+ myRect->setTop( yPos + myHeight );
+ myRect->setRight( xPos + myWidth );
+ myRect->setBottom( yPos );
+}
+
+void GLViewer_TextObject::setDrawer( GLViewer_Drawer* theDrawer )
+{
+ myDrawer = theDrawer;
+ //compute();
+}
+
+GLViewer_Rect* GLViewer_TextObject::getUpdateRect()
+{
+ GLViewer_Rect* rect = new GLViewer_Rect();
+
+ float xPos, yPos;
+ QString aStr = myGLText->getText();
+ myGLText->getPosition( xPos, yPos );
+
+ rect->setLeft( myRect->left() + myXGap - myWidth / myXScale );
+ rect->setTop( myRect->top() + myYGap + myHeight / myYScale );
+ rect->setRight( myRect->right() - myXGap + myWidth / myXScale );
+ rect->setBottom( myRect->bottom() - myYGap - myHeight / myYScale );
+
+ return rect;
+}
+
+GLboolean GLViewer_TextObject::highlight( GLfloat theX, GLfloat theY, GLfloat theTol, GLboolean isCircle )
+{
+ if( !myIsVisible )
+ return false;
+
+ float xPos, yPos;
+ myGLText->getPosition( xPos, yPos );
+
+ QRect aRect;
+ aRect.setLeft( (int)xPos );
+ aRect.setRight( (int)(xPos + myWidth / myXScale) );
+ aRect.setTop( (int)yPos );// - myHeight / myYScale );
+ aRect.setBottom( (int)(yPos + myHeight / myYScale) );
+
+ //cout << "theX: " << theX << " theY: " << theY << endl;
+ //cout << "aRect.left(): " << aRect.left() << " aRect.right(): " << aRect.right() << endl;
+ //cout << "aRect.top(): " << aRect.top() << " aRect.bottom(): " << aRect.bottom() << endl;
+
+ QRegion obj( aRect );
+ QRegion intersection;
+ QRect region;
+
+ region.setLeft( (int)(theX - theTol) );
+ region.setRight( (int)(theX + theTol) );
+ region.setTop( (int)(theY - theTol) );
+ region.setBottom( (int)(theY + theTol) );
+
+ QRegion circle( (int)(theX - theTol), (int)(theY - theTol),
+ (int)(2 * theTol), (int)(2 * theTol), QRegion::Ellipse );
+ if( isCircle )
+ intersection = obj.intersect( circle );
+ else
+ intersection = obj.intersect( region );
+
+ if( intersection.isEmpty() )
+ myIsHigh = false;
+ else
+ myIsHigh = true;
+
+ if( !myHighFlag && myIsHigh )
+ myIsHigh = GL_FALSE;
+ else
+ myHighFlag = GL_TRUE;
+
+ return myIsHigh;
+}
+
+GLboolean GLViewer_TextObject::unhighlight()
+{
+ if( myIsHigh )
+ {
+ myIsHigh = GL_FALSE;
+ return GL_TRUE;
+ }
+
+ return GL_FALSE;
+}
+
+GLboolean GLViewer_TextObject::select( GLfloat theX, GLfloat theY, GLfloat theTol, GLViewer_Rect rect,
+ GLboolean isFull, GLboolean isCircle, GLboolean isShift )
+{
+ if( !myIsVisible )
+ return false;
+
+ QRegion obj( myRect->toQRect() );
+ QRegion intersection;
+ QRect region;
+
+ region.setLeft( (int)(theX - theTol) );
+ region.setRight( (int)(theX + theTol) );
+ region.setTop( (int)(theY - theTol) );
+ region.setBottom( (int)(theY + theTol) );
+
+ QRegion circle( (int)(theX - theTol), (int)(theY - theTol),
+ (int)(2 * theTol), (int)(2 * theTol), QRegion::Ellipse );
+ if( isCircle )
+ intersection = obj.intersect( circle );
+ else
+ intersection = obj.intersect( region );
+
+ if( intersection.isEmpty() )
+ myIsSel = false;
+ else
+ myIsSel = true;
+
+ if ( myIsSel )
+ {
+ myHighFlag = GL_FALSE;
+ myIsHigh = GL_FALSE;
+ }
+ else
+ myHighFlag = GL_TRUE;
+
+ return myIsSel;
+}
+
+GLboolean GLViewer_TextObject::unselect()
+{
+ if( myIsSel )
+ {
+ myIsSel = GL_FALSE;
+ return GL_TRUE;
+ }
+
+ return GL_FALSE;
+}
+
+void GLViewer_TextObject::moveObject( float theX, float theY, bool fromGroup )
+{
+ if( !fromGroup && myGroup)
+ {
+ myGroup->dragingObjects( theX, theY );
+ return;
+ }
+ float aX, anY;
+ myGLText->getPosition( aX, anY );
+ aX += theX;
+ anY += theY;
+ myGLText->setPosition( aX, anY );
+ compute();
+}
+
+QByteArray GLViewer_TextObject::getByteCopy()
+{
+ QByteArray aObject = GLViewer_Object::getByteCopy();
+
+ return aObject;
+}
+
+bool GLViewer_TextObject::initializeFromByteCopy( QByteArray theArray )
+{
+ if( !GLViewer_Object::initializeFromByteCopy( theArray ) || myType != "GLViewer_TextObject" )
+ return false;
+
+ myHighFlag = true;
+ return true;
+}
--- /dev/null
+// File: GLViewer_BaseObjects.h
+// Created: November, 2004
+// Author: OCC team
+// Copyright (C) CEA 2004
+
+#ifndef GLVIEWER_BASEOBJECTS_H
+#define GLVIEWER_BASEOBJECTS_H
+
+#include "GLViewer.h"
+#include "GLViewer_Object.h"
+
+#include <qcolor.h>
+#include <qvaluelist.h>
+
+#include <TColStd_SequenceOfInteger.hxx>
+
+#ifdef WNT
+#pragma warning( disable:4251 )
+#endif
+
+// Class: GLViewer_MarkerSet
+// Descr: OpenGL MarkerSet
+
+class GLVIEWER_API GLViewer_MarkerSet : public GLViewer_Object
+{
+public:
+ GLViewer_MarkerSet( int number = 1, float size = 5.0, const QString& toolTip = "GLMarker" );
+ ~GLViewer_MarkerSet();
+
+ virtual void compute();
+ virtual GLViewer_Drawer* createDrawer();
+
+ virtual GLboolean highlight( GLfloat x, GLfloat y, GLfloat tol = 15.0, GLboolean isCircle = GL_FALSE );
+ virtual GLboolean unhighlight();
+ virtual GLboolean select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect, GLboolean isFull = GL_FALSE,
+ GLboolean isCircle = GL_FALSE, GLboolean isShift = GL_FALSE );
+ virtual GLboolean unselect();
+
+ virtual GLViewer_Rect* getUpdateRect();
+
+ void setXCoord( GLfloat* xCoord, int size );
+ void setYCoord( GLfloat* yCoord, int size );
+ GLfloat* getXCoord() const { return myXCoord; }
+ GLfloat* getYCoord() const { return myYCoord; }
+ void setNumMarkers( GLint );
+ GLint getNumMarkers() const { return myNumber; };
+
+ void setMarkerSize( const float size ) { myMarkerSize = size; }
+ float getMarkerSize() const { return myMarkerSize; }
+
+ void exportNumbers( QValueList<int>&, QValueList<int>& , QValueList<int>&, QValueList<int>& );
+
+ QValueList<int> getSelectedElements() { return mySelNumbers; }
+ bool addOrRemoveSelected( int index );
+ void addSelected( const TColStd_SequenceOfInteger& );
+ void setSelected( const TColStd_SequenceOfInteger& );
+
+ virtual void moveObject( float, float, bool fromGroup = false );
+
+ virtual QByteArray getByteCopy();
+ virtual bool initializeFromByteCopy( QByteArray );
+
+ virtual bool translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
+ virtual bool translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );
+
+#ifdef WIN32
+ virtual bool translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
+#endif
+
+protected:
+ GLint myNumber;
+ GLfloat* myXCoord;
+ GLfloat* myYCoord;
+ GLfloat myMarkerSize;
+ QValueList<int> myHNumbers;
+ QValueList<int> myUHNumbers;
+ QValueList<int> mySelNumbers;
+ QValueList<int> myCurSelNumbers;
+ QValueList<int> myUSelNumbers;
+ QValueList<int> myPrevHNumbers;
+ TColStd_SequenceOfInteger mySelectedIndexes;
+};
+
+// Class: GLViewer_Polyline
+// Descr: OpenGL Polyline
+
+class GLVIEWER_API GLViewer_Polyline: public GLViewer_Object
+{
+public:
+ GLViewer_Polyline( int number = 1, float size = 5.0, const QString& toolTip = "GLPolyline" );
+ ~GLViewer_Polyline();
+
+ virtual void compute();
+ virtual GLViewer_Drawer* createDrawer();
+
+ virtual GLboolean highlight( GLfloat x, GLfloat y, GLfloat tol = 15.0, GLboolean isCircle = GL_FALSE );
+ virtual GLboolean unhighlight();
+ virtual GLboolean select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect, GLboolean isFull = GL_FALSE,
+ GLboolean isCircle = GL_FALSE, GLboolean isShift = GL_FALSE );
+ virtual GLboolean unselect();
+
+ virtual GLViewer_Rect* getUpdateRect();
+
+ void setXCoord( GLfloat* xCoord, int size );
+ void setYCoord( GLfloat* yCoord, int size );
+ GLfloat* getXCoord() const { return myXCoord; }
+ GLfloat* getYCoord() const { return myYCoord; }
+ void setNumber( GLint );
+ GLint getNumber() const { return myNumber; };
+
+ void setClosed( GLboolean closed ) { myIsClosed = closed; }
+ GLboolean isClosed() const { return myIsClosed; }
+
+ void setHighSelAll( GLboolean highSelAll ) { myHighSelAll = highSelAll; }
+ GLboolean isHighSelAll() const { return myHighSelAll; }
+
+ void exportNumbers( QValueList<int>&, QValueList<int>& , QValueList<int>&, QValueList<int>& );
+
+ QValueList<int> getSelectedElements() { return mySelNumbers; }
+
+ virtual void moveObject( float, float, bool fromGroup = false );
+
+ virtual QByteArray getByteCopy();
+ virtual bool initializeFromByteCopy( QByteArray );
+
+ virtual bool translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
+ virtual bool translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );
+
+#ifdef WIN32
+ virtual bool translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
+#endif
+
+protected:
+ GLfloat* myXCoord;
+ GLfloat* myYCoord;
+ GLint myNumber;
+ GLboolean myIsClosed;
+ GLboolean myHighSelAll;
+
+ QValueList<int> myHNumbers;
+ QValueList<int> myUHNumbers;
+ QValueList<int> mySelNumbers;
+ QValueList<int> myUSelNumbers;
+ QValueList<int> myCurSelNumbers;
+ QValueList<int> myPrevHNumbers;
+ TColStd_SequenceOfInteger mySelectedIndexes;
+
+ GLboolean myHighFlag;
+};
+
+// Class: GLViewer_TextObject
+// Descr: Text as Object for OpenGL
+
+class GLVIEWER_API GLViewer_TextObject : public GLViewer_Object
+{
+public:
+ GLViewer_TextObject( const QString&, float xPos = 0, float yPos = 0,
+ const QColor& color = QColor( 0, 255, 0 ), const QString& toolTip = "GLText" );
+ ~GLViewer_TextObject();
+
+ virtual void compute();
+ virtual GLViewer_Drawer* createDrawer();
+
+ virtual void setDrawer( GLViewer_Drawer* theDrawer );
+
+ virtual GLboolean highlight( GLfloat x, GLfloat y, GLfloat tol, GLboolean isCircle = GL_FALSE );
+ virtual GLboolean unhighlight();
+ virtual GLboolean select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect, GLboolean isFull = GL_FALSE,
+ GLboolean isCircle = GL_FALSE, GLboolean isShift = GL_FALSE );
+ virtual GLboolean unselect();
+
+ virtual GLViewer_Rect* getUpdateRect();
+
+ virtual void moveObject( float, float, bool fromGroup = false );
+
+ virtual QByteArray getByteCopy();
+ virtual bool initializeFromByteCopy( QByteArray );
+
+ virtual bool translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
+ virtual bool translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );
+
+#ifdef WIN32
+ virtual bool translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
+#endif
+
+ int getWidth(){ return myWidth; }
+ int getHeight(){ return myWidth; }
+ void setWidth( int w ){ myWidth=w; }
+ void setHeight( int h ){ myHeight=h; }
+
+protected:
+ bool myHighFlag;
+ int myWidth;
+ int myHeight;
+};
+
+#ifdef WNT
+#pragma warning ( default:4251 )
+#endif
+
+#endif
--- /dev/null
+// File: GLViewer_Compass.cxx
+// Created: November, 2004
+// Author: OCC team
+// Copyright (C) CEA 2004
+
+//#include <GLViewerAfx.h>
+#include "GLViewer_Compass.h"
+#include "GLViewer_Drawer.h"
+
+GLViewer_Compass::GLViewer_Compass ( const QColor& color, const int size, const Position pos,
+ const int WidthTop, const int WidthBottom, const int HeightTop,
+ const int HeightBottom ){
+ myCol = color;
+ mySize = size;
+ myPos = pos;
+ myArrowWidthTop = WidthTop;
+ myArrowWidthBottom = WidthBottom;
+ myArrowHeightTop = HeightTop;
+ myArrowHeightBottom = HeightBottom;
+ myIsVisible = true;
+ QFont* aFont = new QFont("Times",16);
+ myFont = new GLViewer_TexFont( aFont );
+ isGenereted = false;
+ //myFont->generateTexture();
+}
+
+GLViewer_Compass::~GLViewer_Compass()
+{
+ delete myFont;
+}
+
+GLViewer_TexFont* GLViewer_Compass::getFont()
+{
+ if(!isGenereted)
+ {
+ myFont->generateTexture();
+ isGenereted = true;
+ }
+ return myFont;
+}
+
+void GLViewer_Compass::setFont( QFont theFont )
+{
+ delete myFont;
+ myFont = new GLViewer_TexFont( &theFont );
+}
--- /dev/null
+// File: GLViewer_Compass.h
+// Created: November, 2004
+// Author: OCC team
+// Copyright (C) CEA 2004
+
+#ifndef GLVIEWER_COMPASS_H
+#define GLVIEWER_COMPASS_H
+
+#include "GLViewer.h"
+
+#include <qcolor.h>
+
+#ifdef WNT
+#pragma warning( disable:4251 )
+#endif
+
+class GLViewer_TexFont;
+
+class GLVIEWER_API GLViewer_Compass
+{
+public:
+ enum Position { TopLeft, TopRight, BottomLeft, BottomRight };
+
+ GLViewer_Compass( const QColor& color = QColor ( 0, 255, 0 ),
+ const int size = 60,
+ const Position pos = TopRight,
+ const int WidthTop = 20,
+ const int WidthBottom = 10,
+ const int HeightTop = 25,
+ const int HeightBottom = 7 );
+ ~GLViewer_Compass();
+
+ void setCompass( const QColor& color, const int size, const Position pos )
+ {myCol=color;mySize=size;myPos=pos;};
+ void setVisible( const bool vis = true );
+ bool getVisible(){ return myIsVisible; };
+
+ void setSize( const int size ){mySize=size;};
+ int getSize(){ return mySize; };
+
+ void setPos( const Position pos ){myPos=pos;};
+ int getPos(){ return myPos; };
+
+ void setColor( const QColor& color ){myCol=color;};
+ QColor getColor(){ return myCol; };
+
+ void setArrowWidthTop( const int WidthTop ){ if( WidthTop<myArrowWidthBottom ||
+ WidthTop>mySize ) return;
+ myArrowWidthTop=WidthTop; };
+ int getArrowWidthTop(){return myArrowWidthTop;};
+
+ void setArrowWidthBottom( const int WidthBot ){ if( WidthBot>myArrowWidthTop || WidthBot<1 )return;
+ myArrowWidthBottom=WidthBot; };
+ int getArrowWidthBottom(){return myArrowWidthBottom;};
+
+ void setArrowHeightTop( const int HeightTop ){ if( HeightTop>(2*mySize-myArrowHeightBottom ) ||
+ HeightTop<1 )return;
+ myArrowHeightTop=HeightTop;};
+ int getArrowHeightTop(){return myArrowHeightTop;};
+
+ void setArrowHeightBottom( const int HeightBot ){ if( HeightBot>( 2*mySize-myArrowHeightTop ) ||
+ HeightBot<1)return;
+ myArrowHeightBottom=HeightBot;};
+ int getArrowHeightBottom(){return myArrowHeightBottom;};
+
+ GLViewer_TexFont* getFont();
+ void setFont( QFont theFont );
+
+protected:
+ QColor myCol;
+ int mySize;
+ int myPos;
+ bool myIsVisible;
+ int myArrowWidthTop;
+ int myArrowWidthBottom;
+ int myArrowHeightTop;
+ int myArrowHeightBottom;
+ GLViewer_TexFont* myFont;
+ bool isGenereted;
+};
+
+#ifdef WNT
+#pragma warning ( default:4251 )
+#endif
+
+#endif
** Created: UI team, 20.09.02
*****************************************************************************/
+//#include <GLViewerAfx.h>
+
#include "GLViewer_Context.h"
+#include "GLViewer_Group.h"
#include "GLViewer_Object.h"
#include "GLViewer_Viewer2d.h"
#include "GLViewer_ViewPort2d.h"
myGLViewer2d( v ),
myHighlightColor( Quantity_NOC_CYAN1 ),
mySelectionColor( Quantity_NOC_RED ),
- myTolerance( TOLERANCE ),
- myNumber( 0 )
+ myTolerance( TOLERANCE )
{
- myLastPicked = NULL;
- isLastPickedChanged = false;
+ myUpdateAll = true;
+
+ myLastPicked = 0;
+ myLastPickedChanged = false;
+
myHFlag = GL_TRUE;
mySFlag = GL_TRUE;
+
mySelCurIndex = 0;
}
GLViewer_Context::~GLViewer_Context()
{
+ myActiveObjects.clear();
+ myInactiveObjects.clear();
+ mySelectedObjects.clear();
}
int GLViewer_Context::MoveTo( int xi, int yi, bool byCircle )
{
- GLfloat x = (GLfloat)xi;
- GLfloat y = (GLfloat)yi;
- myGLViewer2d->transPoint( x, y );
- //cout << "GLViewer_Context::MoveTo " << x << " " << y << endl;
+ GLfloat x = (GLfloat)xi;
+ GLfloat y = (GLfloat)yi;
+ myGLViewer2d->transPoint( x, y );
- QValueList<GLViewer_Object*> anUpdatedObjects;
-
- ObjectMap::Iterator it;
-
- myXhigh = x;
- myYhigh = y;
-
- //if( !myHFlag )
- // return 1;
-
- GLfloat aXScale;
- GLfloat aYScale;
- GLViewer_ViewPort2d* vp = ( GLViewer_ViewPort2d* )myGLViewer2d->getActiveView()->getViewPort();
- vp->getScale( aXScale, aYScale );
-
- //bool onlyUpdate = true;
- GLboolean update = GL_FALSE;
- GLboolean isHigh = GL_FALSE;
- GLboolean onObject = GL_FALSE;
+ myXhigh = x;
+ myYhigh = y;
+
+ GLboolean isHigh = GL_FALSE;
+ GLboolean onObject = GL_FALSE;
+
+ GLViewer_Object* aPrevLastPicked = myLastPicked;
+ GLViewer_Object* lastPicked = 0;
+
+ ObjList anUpdatedObjects;
- GLViewer_Object* aPrevLastPicked = myLastPicked;
- GLViewer_Object* lastPicked = NULL;
- QRect* rect;
- QRegion obj;
- QRegion intersection;
- QRect region;
-
- region.setLeft( (int)(x - myTolerance) );
- region.setRight( (int)(x + myTolerance) );
- region.setTop( (int)(y - myTolerance) );
- region.setBottom( (int)(y + myTolerance) );
-
- for( it = myObjects.begin(); it != myObjects.end(); ++it )
- {
- it.key()->setScale( aXScale, aYScale );
- rect = it.key()->getUpdateRect()->toQRect();
- obj = QRegion( *rect );
+ if( myActiveObjects.isEmpty() )
+ return -1;
- if( !byCircle && rect->intersects( region ) )
+ ObjList::iterator it = myActiveObjects.end();
+ ObjList::iterator itEnd = myActiveObjects.begin();
+ for( it--; ; --it )
{
- // cout << "object : " << it.data() << endl;
- update = it.key()->highlight( x, y, myTolerance, GL_FALSE );
- isHigh = it.key()->isHighlighted();
- onObject = GL_TRUE;
- //if( update )
- // cout << "update" << endl;
- //if( isHigh )
- // cout << "highlight" << endl;
+ GLViewer_Object* object = *it;
+
+ GLViewer_Rect* rect = object->getUpdateRect();
+ if( rect->contains( GLViewer_Pnt( x, y ) ) )
+ {
+ onObject = GL_TRUE;
+ object->highlight( x, y, myTolerance, GL_FALSE );
+ isHigh = object->isHighlighted();
+ }
+
+ if( isHigh )
+ {
+ lastPicked = object;
+ break;
+ }
+
+ if( it == itEnd )
+ break;
}
- if( byCircle )
+ if( !myHFlag )
{
- QRegion circle( (int)(x - myTolerance), (int)(y - myTolerance),
- (int)(2 * myTolerance), (int)(2 * myTolerance), QRegion::Ellipse );
- intersection = obj.intersect( circle );
- if( !intersection.isEmpty() )
- {
- update = it.key()->highlight( x, y, myTolerance, GL_TRUE );
- isHigh = it.key()->isHighlighted();
- onObject = GL_TRUE;
- }
+ myLastPicked = lastPicked;
+ return -1;
}
- if( isHigh )
+ if ( !onObject )
{
- lastPicked = it.key();
- break;
- }
- }
+ //cout << 0 << endl;
+ it = myActiveObjects.begin();
+ itEnd = myActiveObjects.end();
- if( !myHFlag )
- {
- myLastPicked = lastPicked; //we need this information everytime
- return -1;
- }
-
- if ( !onObject )
- {
- for( it = myObjects.begin(); it != myObjects.end(); ++it )
- if( it.key()->unhighlight() )
- anUpdatedObjects.append( it.key() );
-
- myLastPicked = NULL;
- isLastPickedChanged = aPrevLastPicked != myLastPicked;
-
- if( isLastPickedChanged )
- myGLViewer2d->updateAll();
-
- return 0;
- }
-
- if( !myLastPicked && isHigh )
- {
- //cout << "1" << endl;
- myLastPicked = lastPicked;
- myHNumber = myObjects[ lastPicked ];
- anUpdatedObjects.append( myLastPicked );
- }
- else if( myLastPicked && !isHigh )
- {
- //cout << "2" << endl;
- //onlyUpdate =
- myLastPicked->unhighlight();
- anUpdatedObjects.append( myLastPicked );
- //eraseObject( myLastPicked, true );
- myLastPicked = NULL;
- myHNumber = -1;
- }
- else if( myLastPicked && isHigh )
- {
- //cout << "3" << endl;
- //cout << "HNumber" << myHNumber << endl;
+ for( ; it != itEnd; ++it )
+ (*it)->unhighlight();
- myLastPicked->highlight( x, y, myTolerance, byCircle );
- if( !myLastPicked->isHighlighted() )
- {
- myLastPicked->unhighlight();
- anUpdatedObjects.append( myLastPicked );
- myLastPicked = lastPicked;
- myHNumber = myObjects[ lastPicked ];
- }
- anUpdatedObjects.append( myLastPicked );
- }
+ anUpdatedObjects.append( (*it) );
+
+ myLastPicked = 0;
+ myLastPickedChanged = aPrevLastPicked != myLastPicked;
- isLastPickedChanged = ( aPrevLastPicked != myLastPicked );
+ if( myLastPickedChanged )
+ myGLViewer2d->updateAll();
- if( isLastPickedChanged/*!onlyUpdate*/ )
+ return 0;
+ }
+
+ if( !myLastPicked && isHigh )
{
- myGLViewer2d->updateAll();
- //myGLViewer2d->activateAllDrawers( true );
+ //cout << 1 << endl;
+ myLastPicked = lastPicked;
+ anUpdatedObjects.append( myLastPicked );
+ }
+ else if( myLastPicked && !isHigh )
+ {
+ //cout << 2 << endl;
+ myLastPicked->unhighlight();
+ anUpdatedObjects.append( myLastPicked );
+ myLastPicked = 0;
+ }
+ else if( myLastPicked && isHigh )
+ {
+ //cout << 3 << endl;
+ //myLastPicked->highlight( x, y, myTolerance, byCircle );
+ if( myLastPicked != lastPicked )
+ {
+ myLastPicked->unhighlight();
+ if( myLastPicked != lastPicked )
+ {
+ myLastPicked = lastPicked;
+ anUpdatedObjects.append( myLastPicked );
+ }
+ }
}
- else
- myGLViewer2d->activateDrawers( anUpdatedObjects, TRUE, TRUE );
- return 0;
+ myLastPickedChanged = ( aPrevLastPicked != myLastPicked );
+
+ if( myLastPickedChanged || myUpdateAll )
+ myGLViewer2d->updateAll();
+ else
+ myGLViewer2d->activateDrawers( anUpdatedObjects, TRUE, TRUE );
+
+ return 0;
}
int GLViewer_Context::Select( bool Append, bool byCircle )
{
- //cout << "GLViewer_Context::Select " << (int)Append << endl;
- QValueList<int>::Iterator it;
- ObjectMap::Iterator oit;
- SelectionStatus status = SS_Invalid;
+ ObjList::Iterator it, itEnd, oit, oitEnd;
+ SelectionStatus status = SS_Invalid;
- bool onlyUpdate = false;
+ bool updateAll = false;
- QValueList<GLViewer_Object*> aList;
+ ObjList aList;
- if ( !mySFlag )
- return status;//invalid
-
- if( myHFlag && myLastPicked )
- {
- if( mySelNumbers.count() == 1 && mySelNumbers.first() == myHNumber )
- status = SS_LocalChanged;
-
- if ( !Append )
+ if ( !mySFlag )
+ return status;//invalid
+
+ if( myHFlag && myLastPicked )
{
- for( it = mySelNumbers.begin(); it != mySelNumbers.end(); ++it )
- for( oit = myObjects.begin(); oit != myObjects.end(); ++oit )
- if( *it == myObjects[ oit.key() ] )
- if ( myLastPicked != oit.key() )
- {
- onlyUpdate = oit.key()->unselect();
- aList.append( oit.key() );
- }
+ if( mySelectedObjects.count() == 1 && mySelectedObjects.first() == myLastPicked )
+ status = SS_LocalChanged;
- if( onlyUpdate )
- myGLViewer2d->updateAll();
- else
- myGLViewer2d->activateDrawers( aList, TRUE, TRUE );
+ if ( !Append )
+ {
+ for( it = mySelectedObjects.begin(), itEnd = mySelectedObjects.end() ; it != itEnd; ++it )
+ if( myLastPicked != *it )
+ {
+ updateAll = (*it)->unselect() || updateAll;
+ aList.append( *it );
+ }
- if( mySelNumbers.count() != 0 && status == SS_Invalid )
- status = SS_GlobalChanged;
- mySelNumbers.clear();
- }
+ if( updateAll || myUpdateAll )
+ myGLViewer2d->updateAll();
+ else
+ myGLViewer2d->activateDrawers( aList, TRUE, TRUE );
- if ( myLastPicked->select( myXhigh, myYhigh, myTolerance, GLViewer_Rect(), false, byCircle, Append )
- && mySelNumbers.findIndex( myHNumber ) == -1 )
- /*if ( myLastPicked->select( myXhigh, myYhigh, myTolerance, byCircle, Append ) )
- //&&( mySelNumbers.findIndex( myHNumber ) == -1 ) )*/
- {
- mySelNumbers.append( myHNumber );
- //cout << "context::select object #" << myHNumber << endl;
- myGLViewer2d->activateDrawer( myLastPicked, TRUE, TRUE );
-
- if( status == SS_Invalid )
- status = SS_GlobalChanged;
-// else
-// status = SS_GlobalChanged;
+ if( mySelectedObjects.count() != 0 && status == SS_Invalid )
+ status = SS_GlobalChanged;
+ mySelectedObjects.clear();
+ }
+
+ if ( myLastPicked->select( myXhigh, myYhigh, myTolerance, GLViewer_Rect(), false, byCircle, Append )
+ && mySelectedObjects.findIndex( myLastPicked ) == -1 )
+ {
+ mySelectedObjects.append( myLastPicked );
+ myGLViewer2d->activateDrawer( myLastPicked, TRUE, TRUE );
+
+ if( status == SS_Invalid )
+ status = SS_GlobalChanged;
+ }
+ else if( status = SS_LocalChanged )
+ status = SS_GlobalChanged;
+
+ return status;
}
- else if( status == SS_LocalChanged )
- status = SS_GlobalChanged;
-
- return status;
- }
-
- if( myHFlag && !myLastPicked )
- {
- if ( !Append )
+
+ if( myHFlag && !myLastPicked )
{
- for( it = mySelNumbers.begin(); it != mySelNumbers.end(); ++it )
- for( oit = myObjects.begin(); oit != myObjects.end(); ++oit )
- if( *it == myObjects[ oit.key() ] )
- {
- onlyUpdate = oit.key()->unselect();
- //list.Append( *it );
- aList.append( oit.key() );
- }
-
- if( onlyUpdate )
- myGLViewer2d->updateAll();
- else
- myGLViewer2d->activateDrawers( aList, TRUE, TRUE );
-
- if( mySelNumbers.count() != 0 )
- status = SS_GlobalChanged;
-
- mySelNumbers.clear();
- //cout << " myHFlag && !myLastPicked " << endl;
+ if ( !Append )
+ {
+ for( it = mySelectedObjects.begin(), itEnd = mySelectedObjects.end() ; it != itEnd; ++it )
+ if ( myLastPicked != *it )
+ {
+ updateAll = (*it)->unselect() || updateAll;
+ aList.append( *it );
+ }
+
+ if( updateAll || myUpdateAll )
+ myGLViewer2d->updateAll();
+ else
+ myGLViewer2d->activateDrawers( aList, TRUE, TRUE );
+
+ if( mySelectedObjects.count() != 0 )
+ status = SS_GlobalChanged;
+
+ mySelectedObjects.clear();
+ }
+ return status;
}
- return status;
- }
-// if( !myHFlag )
-// {
-// GLViewer_Object* lastPicked = NULL;
-// GLboolean update = FALSE;
-// GLboolean isSel = GL_FALSE;
-// list = new int[2];
-// number = 0;
-// float xa, xb, ya, yb;
-// QRect* rect;
-
-// ObjectMap::Iterator it;
-// for( it = myObjects.begin(); it != myObjects.end(); ++it )
-// {
-// rect = it.key()->getRect();
-// xa = rect->left();
-// xb = rect->right();
-// ya = rect->top();
-// yb = rect->bottom();
-
-// if( myXhigh >= xa && myXhigh <= xb && myYhigh >= ya && myYhigh <= yb )
-// {
-// update = it.key()->select( myXhigh, myYhigh, myTolerance, byCircle, Append );
-// isSel = it.key()->isSelected();
-// if( isSel )
-// {
-// myLastPicked = it.key();
-// number = myObjects[ lastPicked ];
-// }
-// }
-// }
-
-// if ( !Append )
-// {
-// for( it = mySelNumbers.begin(); it != mySelNumbers.end(); ++it )
-// for( it1 = myObjects.begin(); it1 != myObjects.end(); ++it1 )
-// if( *it == myObjects[ it1.key() ] )
-// {
-// it1.key()->unselect();
-// myGLViewer2d->initDrawer( it1.key(), it.data() );
-// list.Append( *it );
-// }
-// myGLViewer2d->activateDrawers( list, TRUE );
-// mySelNumbers.clear();
-// }
-// if ( mySelNumbers.findIndex( myObjects[lastPicked] ) == -1)
-// mySelNumbers.append( myObjects[lastPicked] );
-
-// number = mySelNumbers.count();
-// list = new int[number + 1];
-// list[0] = number;
-
-// for( it = mySelNumbers.begin(), i = 1; it != mySelNumbers.end(); ++it, i++ )
-// list[i] = *it;
-
-// myGLViewer2d->initDrawer( myLastPicked, myHNumber );
-// myGLViewer2d->activateDrawers( list, TRUE );
-// }
-
- if( !myHFlag )
- {
- bool isSel = false;
- GLfloat aXScale;
- GLfloat aYScale;
- GLViewer_ViewPort2d* vp = ( GLViewer_ViewPort2d* )myGLViewer2d->getActiveView()->getViewPort();
- vp->getScale( aXScale, aYScale );
-
- QRect* rect;
- QRect region;
- QRegion obj;
-
- region.setLeft( ( int )( myXhigh - myTolerance ) );
- region.setRight( ( int )( myXhigh + myTolerance ) );
- region.setTop( ( int )( myYhigh - myTolerance ) );
- region.setBottom( ( int )( myYhigh + myTolerance ) );
-
- QRegion circle( ( int )( myXhigh - myTolerance ), ( int )( myYhigh - myTolerance ),
- 2 * myTolerance, 2 * myTolerance, QRegion::Ellipse );
-
- if ( !Append )
+ if( !myHFlag )
{
- for( it = mySelNumbers.begin(); it != mySelNumbers.end(); ++it )
- for( oit = myObjects.begin(); oit != myObjects.end(); ++oit )
- if( *it == myObjects[ oit.key() ] )
- {
- onlyUpdate |= (bool)oit.key()->unselect();
- aList.append( oit.key() );
- }
-
- if( onlyUpdate )
- myGLViewer2d->updateAll();
- else
- myGLViewer2d->activateDrawers( aList, TRUE, TRUE );
-
- if( mySelNumbers.count() != 0 )
- status = SS_GlobalChanged;
-
- mySelNumbers.clear();
- }
-
- for( oit = myObjects.begin(); oit != myObjects.end(); ++oit )
- {
- oit.key()->setScale( aXScale, aYScale );
- rect = oit.key()->getUpdateRect()->toQRect();
- obj = QRegion( *rect );
-
- if( !byCircle && rect->intersects( region ) )
- {
- oit.key()->select( myXhigh, myYhigh, myTolerance, GLViewer_Rect(), false, byCircle, Append );
- isSel = oit.key()->isSelected();
- }
-
- if( byCircle && !obj.intersect( circle ).isEmpty() )
- {
- oit.key()->select( myXhigh, myYhigh, myTolerance, GLViewer_Rect(), false, byCircle, Append );
- isSel = oit.key()->isSelected();
- }
- if( isSel )
- {
- myLastPicked = oit.key();
- mySelNumbers.append( myObjects[ myLastPicked ] );
- myGLViewer2d->activateDrawer( myLastPicked, TRUE, TRUE );
- status = SS_GlobalChanged;
- return status;
- }
+ bool isSel = false;
+ GLfloat aXScale;
+ GLfloat aYScale;
+ GLViewer_ViewPort2d* vp = ( GLViewer_ViewPort2d* )myGLViewer2d->getActiveView()->getViewPort();
+ vp->getScale( aXScale, aYScale );
+
+ if ( !Append )
+ {
+ for( it = mySelectedObjects.begin(), itEnd = mySelectedObjects.end() ; it != itEnd; ++it )
+ if( myLastPicked != *it )
+ {
+ updateAll = (*it)->unselect() || updateAll;
+ aList.append( *it );
+ }
+
+ if( updateAll || myUpdateAll )
+ myGLViewer2d->updateAll();
+ else
+ myGLViewer2d->activateDrawers( aList, TRUE, TRUE );
+
+ if( mySelectedObjects.count() != 0 )
+ status = SS_GlobalChanged;
+
+ mySelectedObjects.clear();
+ }
+
+ for( oit = myActiveObjects.begin(), oitEnd = myActiveObjects.end(); oit != oitEnd; ++oit )
+ {
+ (*oit)->setScale( aXScale, aYScale );
+ GLViewer_Rect* rect = (*oit)->getUpdateRect();
+
+ if( rect->contains( GLViewer_Pnt( myXhigh, myXhigh ) ) )
+ {
+ (*oit)->select( myXhigh, myYhigh, myTolerance, GLViewer_Rect(), false, byCircle, Append );
+ isSel = (*oit)->isSelected();
+ }
+ if( isSel )
+ {
+ myLastPicked = *oit;
+ mySelectedObjects.append( myLastPicked );
+ myGLViewer2d->activateDrawer( myLastPicked, TRUE, TRUE );
+ status = SS_GlobalChanged;
+ return status;
+ }
+ }
}
- }
- return SS_NoChanged;
+ return SS_NoChanged;
}
int GLViewer_Context::SelectByRect( const QRect& theRect, bool Append )
SelectionStatus status = SS_NoChanged;
- QValueList<int>::Iterator it;
- ObjectMap::Iterator oit;
+ ObjList aList;
+ ObjList::Iterator it, itEnd;
- QValueList<GLViewer_Object*> aList;
-
- if ( !mySFlag || myObjList.empty() )
+ if ( !mySFlag || myActiveObjects.empty() )
return SS_Invalid;
bool updateAll = false;
if( !Append )
{
- if( mySelNumbers.count() != 0 )
+ if( mySelectedObjects.count() != 0 )
status = SS_GlobalChanged;
- for( it = mySelNumbers.begin(); it != mySelNumbers.end(); ++it )
- for( oit = myObjects.begin(); oit != myObjects.end(); ++oit )
- if( *it == myObjects[ oit.key() ] )
- {
- updateAll |= (bool)oit.key()->unselect();
- aList.append( oit.key() );
- }
- mySelNumbers.clear();
+ for( it = mySelectedObjects.begin(), itEnd = mySelectedObjects.end(); it != itEnd; ++it )
+ {
+ updateAll = (*it)->unselect() || updateAll;
+ aList.append( *it );
+ }
+ mySelectedObjects.clear();
}
- for( oit = myObjects.begin(); oit != myObjects.end(); ++oit )
+ for( it = myActiveObjects.begin(), itEnd = myActiveObjects.end(); it != itEnd; ++it )
{
bool isSel = false;
- oit.key()->setScale( aXScale, aYScale );
- QRect rect = //myGLViewer2d->getWinObjectRect( oit.key() ); //->getUpdateRect()->toQRect();
- myGLViewer2d->getQRect( *(oit.key()->getRect()) );
+ (*it)->setScale( aXScale, aYScale );
+ QRect rect = myGLViewer2d->getQRect( *( (*it)->getRect() ) );
if( rect.intersects( theRect ) )
{
GLViewer_Rect aRect = myGLViewer2d->getGLVRect( theRect );
- oit.key()->select( myXhigh, myYhigh, myTolerance, aRect, false, false, Append );
- isSel = oit.key()->isSelected();
+ (*it)->select( myXhigh, myYhigh, myTolerance, aRect, false, false, Append );
+ isSel = (*it)->isSelected();
}
- if( isSel && mySelNumbers.findIndex( oit.data() ) == -1 )
+ if( isSel && mySelectedObjects.findIndex( *it ) == -1 )
{
- aList.append( oit.key() );
- mySelNumbers.append( oit.data() );
+ aList.append( *it );
+ mySelectedObjects.append( *it );
status = SS_GlobalChanged;
}
}
- if( updateAll ) //i.e only update
- {
- //cout << "Unhilight.ALL" << endl;
+ if( updateAll || myUpdateAll )
myGLViewer2d->updateAll();
- }
else
myGLViewer2d->activateDrawers( aList, TRUE, TRUE );
int GLViewer_Context::NbSelected()
{
- return mySelNumbers.count();
+ return mySelectedObjects.count();
}
void GLViewer_Context::InitSelected()
GLViewer_Object* GLViewer_Context::SelectedObject()
{
- ObjectMap::Iterator it;
- for( it = myObjects.begin(); it != myObjects.end(); ++it )
- if( mySelNumbers[mySelCurIndex] == it.data() )
- return it.key();
-
- return NULL;
+ return mySelectedObjects[ mySelCurIndex ];
}
bool GLViewer_Context::isSelected( GLViewer_Object* theObj )
{
- for( InitSelected(); MoreSelected(); NextSelected() )
- if( SelectedObject() == theObj )
- return true;
-
- return false;
+ return mySelectedObjects.contains( theObj );
}
-int GLViewer_Context::insertObject( GLViewer_Object* object, bool display )
+int GLViewer_Context::insertObject( GLViewer_Object* object, bool display, bool isActive )
{
// cout << "GLViewer_Context::insertObject" << endl;
-
- myObjects.insert( object, myNumber++ );
- myObjList.append( object );
- if( display )
+ if( !object )
+ return -1;
+
+ if( isActive )
{
- //QRect* rect = object->getRect()->toQRect();
- //myGLViewer2d->updateBorders( *rect );
- myGLViewer2d->activateDrawer( object, FALSE );
+ myActiveObjects.append( object );
+ if( display )
+ {
+ //QRect* rect = object->getRect()->toQRect();
+ //myGLViewer2d->updateBorders( *rect );
+ myGLViewer2d->activateDrawer( object, FALSE );
+ }
}
+ else
+ myInactiveObjects.append( object );
- return myNumber - 1;
+ return myActiveObjects.count() + myInactiveObjects.count();
}
bool GLViewer_Context::replaceObject( GLViewer_Object* oldObject, GLViewer_Object* newObject )
{
- if( myObjects.contains( oldObject ) )
+ if( !oldObject || !newObject )
+ return false;
+
+ if( myActiveObjects.contains( oldObject ) )
+ {
+ myActiveObjects.remove( oldObject );
+ myActiveObjects.append( newObject );
+ return true;
+ }
+
+ if( myInactiveObjects.contains( oldObject ) )
{
- int index = myObjects[ oldObject ];
- myObjects.remove( oldObject );
- myObjects.insert( newObject, index );
- return GL_TRUE;
+ myInactiveObjects.remove( oldObject );
+ myInactiveObjects.append( newObject );
+ return true;
}
- return GL_FALSE;
+ return false;
}
void GLViewer_Context::updateScales( GLfloat scX, GLfloat scY )
{
- if( scX && scY )
- for ( ObjectMap::Iterator it = myObjects.begin(); it != myObjects.end(); ++it )
- it.key()->setScale( scX, scY );
+ if( scX <= 0 || scY <= 0 )
+ return;
+
+ ObjList::iterator it, itEnd;
+
+ for( it = myActiveObjects.begin(), itEnd = myActiveObjects.end(); it != itEnd; ++it )
+ (*it)->setScale( scX, scY );
+
+ for( it = myInactiveObjects.begin(), itEnd = myInactiveObjects.end(); it != itEnd; ++it )
+ (*it)->setScale( scX, scY );
}
-void GLViewer_Context::clearSelected( bool updateViewer )
+void GLViewer_Context::clearHighlighted()
{
- QValueList<int>::Iterator it;
- ObjectMap::Iterator oit;
+ if( myHFlag && myLastPicked )
+ {
+ myLastPicked->unhighlight();
+ myLastPicked = 0;
- TColStd_SequenceOfInteger list;
+ myGLViewer2d->updateAll();
+ }
+}
+void GLViewer_Context::clearSelected( bool updateViewer )
+{
if( !mySFlag )
- return ;
-
- for( it = mySelNumbers.begin(); it != mySelNumbers.end(); ++it )
- for( oit = myObjects.begin(); oit != myObjects.end(); ++oit )
- if( *it == myObjects[ oit.key() ] )
- {
- oit.key()->unselect();
- //myGLViewer2d->initDrawer( oit.key(), oit.data() );
- ///myGLViewer2d->initDrawer( oit.key() );
- list.Append( *it );
- }
+ return;
+
+ ObjList::Iterator it, itEnd;
+ ObjList aList;
+
+ for( it = mySelectedObjects.begin(), itEnd = mySelectedObjects.end(); it != itEnd; ++it )
+ {
+ (*it)->unselect();
+ aList.append( *it );
+ }
if( updateViewer )
- myGLViewer2d->activateDrawers( list, TRUE );
- mySelNumbers.clear();
+ myGLViewer2d->activateDrawers( aList, TRUE );
+ mySelectedObjects.clear();
}
void GLViewer_Context::setSelected( GLViewer_Object* object, bool updateViewer )
{
- int index = -1;
- if ( myObjects.contains( object ) )
- index = myObjects[object];
-
- if( index == -1 || mySelNumbers.findIndex( index ) != -1 )
+ if( !object )
return;
- mySelNumbers.append( index );
- object->setSelected( TRUE );
-
+ if( myActiveObjects.contains( object ) && !mySelectedObjects.contains( object ) )
+ {
+ object->setSelected( TRUE );
+ mySelectedObjects.append( object );
+ }
+
if( updateViewer )
myGLViewer2d->activateDrawer( object, TRUE, TRUE );
}
void GLViewer_Context::remSelected( GLViewer_Object* object, bool updateViewer )
{
- int index = -1;
- if ( myObjects.contains( object ) )
- index = myObjects[object];
-
- if( index == -1 || mySelNumbers.findIndex( index ) == -1 )
+ if( !object || !mySelectedObjects.contains( object ) )
return;
- mySelNumbers.remove( index );
+ mySelectedObjects.remove( object );
object->unselect();
-
+
if( updateViewer )
myGLViewer2d->activateDrawer( object, TRUE, TRUE );
}
void GLViewer_Context::eraseObject( GLViewer_Object* theObject, bool theUpdateViewer )
{
- if( !theObject )
+ if( !theObject || !myActiveObjects.contains( theObject ) )
return;
theObject->unhighlight();
if( theUpdateViewer )
myGLViewer2d->updateAll();
- //myGLViewer2d->activateAllDrawers( true );
}
void GLViewer_Context::deleteObject( GLViewer_Object* theObject, bool updateViewer )
{
- if( !theObject || !myObjects.contains(theObject) )
+ if( !theObject ||
+ ( !myActiveObjects.contains( theObject ) && !myInactiveObjects.contains( theObject ) ) )
+ return;
+
+ if( myActiveObjects.contains( theObject ) )
+ myActiveObjects.remove( theObject );
+ else if( myInactiveObjects.contains( theObject ) )
+ myInactiveObjects.remove( theObject );
+ else
return;
+
+ if( mySelectedObjects.contains( theObject ) )
+ mySelectedObjects.remove( theObject );
- int anIndex = myObjects[theObject];
- myObjects.remove( theObject );
- myObjList.remove( theObject );
+ GLViewer_Group* aGroup = theObject->getGroup();
+ if( aGroup )
+ aGroup->removeObject( theObject );
if( myLastPicked == theObject )
- {
- myLastPicked = NULL;
- myHNumber = -1;
- }
+ myLastPicked = 0;
+
+ myGLViewer2d->updateAll();
+}
- QValueList<int>::Iterator anIt= mySelNumbers.find( anIndex );
- if( anIt != mySelNumbers.end() )
- mySelNumbers.remove( anIt );
+bool GLViewer_Context::setActive( GLViewer_Object* theObject )
+{
+ if( !theObject || !myInactiveObjects.contains( theObject ) )
+ return false;
- if( mySelCurIndex == anIndex )
- mySelCurIndex = 0;
+ myInactiveObjects.remove( theObject );
+ myActiveObjects.append( theObject );
+ return true;
+}
- if ( updateViewer )
- myGLViewer2d->updateAll();
+bool GLViewer_Context::setInactive( GLViewer_Object* theObject )
+{
+ if( !theObject || !myActiveObjects.contains( theObject ) )
+ return false;
+
+ myActiveObjects.remove( theObject );
+ myInactiveObjects.append( theObject );
+ return true;
}
#include "windows.h"
#endif
-//#include "QAD.h"
#include "GLViewer_Object.h"
#include <qmap.h>
SS_NoChanged
};
-class GLVIEWER_EXPORT GLViewer_Context : public QObject
+class GLVIEWER_API GLViewer_Context
{
- Q_OBJECT
-
public:
GLViewer_Context( GLViewer_Viewer2d* );
~GLViewer_Context();
+ void setUpdateAll( bool on ) { myUpdateAll = on; }
+ bool isUpdateAll() const { return myUpdateAll; }
+
int MoveTo( int x, int y, bool byCircle = FALSE );
int Select( bool Append = FALSE, bool byCircle = FALSE );
int SelectByRect( const QRect&, bool Append = FALSE );
void SetSelectionColor( Quantity_NameOfColor aCol );
Quantity_NameOfColor HighlightColor() { return myHighlightColor; }
Quantity_NameOfColor SelectionColor() { return mySelectionColor; }
+
int NbSelected();
void InitSelected();
bool MoreSelected();
bool isSelected( GLViewer_Object* );
- int insertObject( GLViewer_Object*, bool display = FALSE );
+ int insertObject( GLViewer_Object*, bool display = false, bool isActive = true );
bool replaceObject( GLViewer_Object*, GLViewer_Object* );
void updateScales( GLfloat, GLfloat );
void setTolerance( int tol ) { myTolerance = tol; }
- const ObjectMap& getObjects() { return myObjects; }
- const ObjList& getObjList() { return myObjList; }
- GLViewer_Object* getFirstObject() { return myObjects.begin().key(); }
+ //const ObjectMap& getObjects() { return myObjects; }
+ const ObjList& getObjects( bool isActive = true )
+ { return isActive ? myActiveObjects : myInactiveObjects; }
+ GLViewer_Object* getFirstObject() { return *( myActiveObjects.begin() ); }
+
+ void clearHighlighted();
void clearSelected( bool updateViewer );
void setSelected( GLViewer_Object*, bool updateViewer );
void remSelected( GLViewer_Object*, bool updateViewer );
GLViewer_Object* getCurrentObject() { return myLastPicked; }
- bool currentObjectIsChanged() { return isLastPickedChanged; }
+ bool currentObjectIsChanged() { return myLastPickedChanged; }
void eraseObject( GLViewer_Object*, bool updateViewer = true );
void deleteObject( GLViewer_Object*, bool updateViewer = true );
+ bool setActive( GLViewer_Object* );
+ bool setInactive( GLViewer_Object* );
+
protected:
+ bool myUpdateAll;
+
GLViewer_Viewer2d* myGLViewer2d;
GLViewer_Object* myLastPicked;
- bool isLastPickedChanged;
- ObjectMap myObjects;
- ObjList myObjList;
- int myNumber;
- QValueList<int> mySelNumbers;
+ bool myLastPickedChanged;
+
+ ObjList myActiveObjects;
+ ObjList myInactiveObjects;
+
+ ObjList mySelectedObjects;
int mySelCurIndex;
- int myHNumber;
+
GLfloat myXhigh;
GLfloat myYhigh;
Quantity_NameOfColor myHighlightColor;
--- /dev/null
+/***************************************************************************
+** Class: GLViewer_CoordSystem
+** Descr:
+** Module: GLViewer
+** Created: UI team, 03.09.02
+****************************************************************************/
+
+//#include <GLViewerAfx.h>
+#include "GLViewer_CoordSystem.h"
+#include <math.h>
+
+GLViewer_CoordSystem::GLViewer_CoordSystem( CSType aType, double X0, double Y0,
+ double XUnit, double YUnit, double Rotation )
+{
+ setType( aType );
+ setOrigin( X0, Y0 );
+ setUnits( XUnit, YUnit );
+ setRotation( Rotation );
+}
+
+void GLViewer_CoordSystem::getOrigin( double& x, double& y ) const
+{
+ x = myX0;
+ y = myY0;
+}
+
+void GLViewer_CoordSystem::setOrigin( double x, double y )
+{
+ myX0 = x;
+ myY0 = y;
+}
+
+void GLViewer_CoordSystem::getUnits( double& x, double& y ) const
+{
+ x = myXUnit;
+ y = myYUnit;
+}
+
+void GLViewer_CoordSystem::setUnits( double x, double y )
+{
+ if( x>0 )
+ myXUnit = x;
+ else
+ myXUnit = 1.0;
+
+ if( y>0 )
+ myYUnit = y;
+ else
+ myYUnit = 1.0;
+}
+
+double GLViewer_CoordSystem::getRotation() const
+{
+ return myRotation;
+}
+
+void GLViewer_CoordSystem::setRotation( double rotation )
+{
+ myRotation = rotation;
+}
+
+GLViewer_CoordSystem::CSType GLViewer_CoordSystem::getType() const
+{
+ return myType;
+}
+
+void GLViewer_CoordSystem::setType( CSType type )
+{
+ myType = type;
+}
+
+void GLViewer_CoordSystem::toReference( double& x, double& y )
+{
+ if( myType==Cartesian )
+ {
+ double newx = myX0 + myXUnit*x*cos(myRotation) - myYUnit*y*sin(myRotation),
+ newy = myY0 + myXUnit*x*sin(myRotation) + myYUnit*y*cos(myRotation);
+ x = newx;
+ y = newy;
+ }
+ else if( myType==Polar )
+ {
+ double r = x, phi = y;
+ x = myX0 + myXUnit*r*cos(phi+myRotation);
+ y = myY0 + myXUnit*r*sin(phi+myRotation);
+ }
+}
+
+void GLViewer_CoordSystem::fromReference( double& x, double& y )
+{
+ x = (x - myX0) / myXUnit;
+ y = (y - myY0) / myYUnit;
+
+ if( myType==Cartesian )
+ {
+ double newx = x*cos(myRotation) + y*sin(myRotation),
+ newy = -x*sin(myRotation) + y*cos(myRotation);
+ x = newx;
+ y = newy;
+ }
+ else if( myType==Polar )
+ {
+ double r = sqrt( x*x+y*y );
+ double phi = 0.0;
+ double eps = 1E-8, pi = 3.14159265;
+
+ if( r>eps )
+ if( fabs(x)>eps )
+ {
+ double arg = y/x;
+ phi = atan(arg);
+ if( x<0 ) // 2-nd or 4-rd quarter
+ phi+=pi;
+ }
+ else if( y>0 )
+ phi = pi/2.0;
+ else
+ phi = 3*pi/2.0;
+
+ x = r;
+ y = phi-myRotation;
+ }
+}
+
+void GLViewer_CoordSystem::transform( GLViewer_CoordSystem& aSystem, double& x, double& y )
+{
+ toReference( x, y );
+ aSystem.fromReference( x, y );
+}
+
+void GLViewer_CoordSystem::getStretching( GLViewer_CoordSystem& aSystem, double& theX, double& theY )
+{
+ theX = myXUnit / aSystem.myXUnit;
+ theY = myYUnit / aSystem.myYUnit;
+}
--- /dev/null
+// File: GLViewer_CoordSystem.h
+// Created: November, 2004
+// Author: OCC team
+// Copyright (C) CEA 2004
+
+#ifndef GLVIEWER_COORDSYSTEM_H
+#define GLVIEWER_COORDSYSTEM_H
+
+#include "GLViewer.h"
+
+#ifdef WNT
+#pragma warning( disable:4251 )
+#endif
+
+// Class: GLViewer_CoordSystem
+
+class GLVIEWER_API GLViewer_CoordSystem
+{
+public:
+ enum CSType { Cartesian, Polar };
+
+private:
+ double myX0, myY0; //The coordinates of origin in the reference CS
+ double myXUnit, myYUnit; //The lengths of axis units in the reference unit
+ double myRotation; //The rotation in radians relative to reference CS
+
+ //!!! In the polar CS myYUnit is ignored, but myXUnit is the unit of polar radius
+
+ CSType myType;
+
+public:
+ GLViewer_CoordSystem( CSType aType, double X0 = 0.0, double Y0 = 0.0,
+ double XUnit = 1.0, double YUnit = 1.0, double Rotation = 0.0 );
+
+ void getOrigin( double& x, double& y ) const;
+ void setOrigin( double x, double y );
+
+ void getUnits( double& x, double& y ) const;
+ void setUnits( double x, double y );
+
+ double getRotation() const;
+ void setRotation( double rotation );
+
+ CSType getType() const;
+ void setType( CSType type );
+
+ void transform( GLViewer_CoordSystem& aSystem, double& x, double& y );
+ //Transform the coordinates x, y from current CS to aSystem
+
+ virtual void getStretching( GLViewer_CoordSystem& aSystem, double& theX, double& theY );
+ //Return how many times line width in aSystem system bigger than in current
+
+protected:
+ virtual void toReference( double& x, double& y );
+ virtual void fromReference( double& x, double& y );
+};
+
+#ifdef WNT
+#pragma warning ( default:4251 )
+#endif
+
+#endif
#ifndef GLVIEWER_DEFS_H
#define GLVIEWER_DEFS_H
-//Selection status
+//Selection staus
enum SelectionChangeStatus
{
SCS_Invalid,
DTF_BITMAP = 1
};
+#define SEGMENTS 32
+#define PI 3.14159265359
+#define STEP ( float )( 2 * PI / SEGMENTS )
#endif// GLVIEWER_DEFS_H
// Author: OCC team
// Copyright (C) CEA 2004
-/***************************************************************************
-** Class: GLViewer_Drawer
-** Descr: Drawer for GLViewer_Object
-** Module: GLViewer
-** Created: UI team, 01.10.01
-****************************************************************************/
-
+//#include <GLViewerAfx.h>
#include "GLViewer_Drawer.h"
#include "GLViewer_Object.h"
+#include "GLViewer_Text.h"
#include "GLViewer_ViewFrame.h"
#include "GLViewer_ViewPort2d.h"
-//#include "OSD_Timer.hxx"
-
#ifndef WIN32
#include <GL/glx.h>
#endif
-//#include <qdir.h>
-//-----------
-#include <qpixmap.h>
#include <qimage.h>
-#include <qfontmetrics.h>
#include <qpainter.h>
-//-----------
-
-#include <string>
-#include <utility>
-//#include "QAD_TMFont.h"
-//using namespace qad_tmfont;
static int FirstSymbolNumber = 32;
static int LastSymbolNumber = 127;
-//int GLViewer_TexFont::LastmyTexStoredId = 0;
+
QMap<GLViewer_TexFindId,GLViewer_TexIdStored> GLViewer_TexFont::TexFontBase;
-// Next line should be commented, if tex-mapped fonts are completely well
-// and should be used instead of bitmap ones
-#define DEB_TEX_FONT
+#define TEXT_GAP 5
+
+GLboolean TFLoaded = GL_FALSE;
+
+GLdouble modelMatrix[16], projMatrix[16];
+GLint viewport[4];
+GLdouble winx, winy, winz;
+GLint status;
+
+GLViewer_TexFont* staticGlFont;
+
/***************************************************************************
** Class: GLViewer_TexFont
mySeparator = 2;
for( int k = FirstSymbolNumber, aWidth = 0; k <= LastSymbolNumber; k++ )
{
- //char aLetter = (char)k;
myWidths[ k - FirstSymbolNumber ] = aFM.width( k );
myPositions[ k - FirstSymbolNumber ] = aWidth;
aWidth += myWidths[ k - FirstSymbolNumber ] + 2;//mySeparator;
mySeparator = theSeparator;
for( int k = FirstSymbolNumber, aWidth = 0; k <= LastSymbolNumber; k++ )
{
- //char aLetter = (char)k;
myWidths[ k - FirstSymbolNumber ] = aFM.width( k );
myPositions[ k - FirstSymbolNumber ] = aWidth;
aWidth += myWidths[ k - FirstSymbolNumber ] + 2;//mySeparator;
GLViewer_TexFont::~GLViewer_TexFont()
{
- //delete myQFont;
delete[] myWidths;
delete[] myPositions;
- //glDeleteTextures( 1, &myTexFont );
}
void GLViewer_TexFont::generateTexture()
{
QFontMetrics aFM( myQFont );
- //QString aFontStr = myQFont.toString();
- //QGLContext aContext = QGLContext::currentContext();
GLViewer_TexFindId aFindFont;
aFindFont.myFontString = myQFont.toString();
myTexFont = aTexture.myTexFontId;
myTexFontWidth = aTexture.myTexFontWidth;
myTexFontHeight = aTexture.myTexFontHeight;
- //cout << "No generating " << myTexFont << "; current context " << QGLContext::currentContext()<< endl;
}
else
{
- //cout << "Is generating! current context " << QGLContext::currentContext() << endl;
-
QString aStr;
int pixelsWidth = 0;
int pixelsHight = aFM.height();
aPixmap.fill( QColor( 0, 0, 0) );
QPainter aPainter( &aPixmap );
aPainter.setFont( myQFont );
- for( int l = 0/*, gap = 0*/; l < LastSymbolNumber - FirstSymbolNumber; l++ )
+ for( int l = 0/*, gap = 0*/; l < LastSymbolNumber - FirstSymbolNumber; l++ )
{
QString aLetter;
aLetter += (char)(FirstSymbolNumber + l);
aPainter.setPen( QColor( 255,255,255) );
- aPainter.drawText ( /*gap*/myPositions[l], pixelsHight, aLetter );
- //gap += myWidths[l] + 2;
+ aPainter.drawText ( myPositions[l], pixelsHight, aLetter );
}
QImage aImage = aPixmap.convertToImage();
- //aImage.save( "c:/work/CATHARE/pic.bmp", "BMP");
-
char* pixels = new char[myTexFontWidth * myTexFontHeight * 2];
for( int i = 0; i < myTexFontHeight; i++ )
aGap += myWidths[aLettIndex]-1 + mySeparator;
}
- //cout << "the down:" << theY << endl;
- //cout << "the top:" << theY + myTexFontHeight << endl;
- //cout << "the text height: " << pixelsHeight << endl;
-
-
glEnd();
glDisable(GL_ALPHA_TEST);
glDisable(GL_TEXTURE_2D);
void GLViewer_Drawer::destroyAllTextures()
{
- //int aCount = GLViewer_TexFont::TexFontBase.count();
QMap<GLViewer_TexFindId,GLViewer_TexIdStored>::Iterator anIt= GLViewer_TexFont::TexFontBase.begin();
QMap<GLViewer_TexFindId,GLViewer_TexIdStored>::Iterator anEndIt= GLViewer_TexFont::TexFontBase.end();
glDeleteTextures( 1, &(anIt.data().myTexFontId) );
}
-#define TEXTURE
-
-#define TEXT_GAP 5
-
-#ifdef TEXTURE
-//QAD_TMFont myTMFont;
- GLboolean TFLoaded = GL_FALSE;
-
- GLdouble modelMatrix[16], projMatrix[16];
- GLint viewport[4];
- GLdouble winx, winy, winz;
- GLint status;
-
- GLViewer_TexFont* staticGlFont;
-
-void printOrtho(GLdouble x, GLdouble y, const char *string, int set, GLdouble w, GLdouble h)
-{
-// int width, heigth;
- if (set>1)
- {
- set=1;
- }
-//d glDisable(GL_DEPTH_TEST);
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- glOrtho(0,w,0,h,-100,100);
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
-
-/* //--------abd
- myTMFont.Begin();
- myTMFont.DrawString( string, x, y );
- //--------abd */
- staticGlFont->drawString( string, x, y );
-
-/* width = myTMFont.GetStringWidth( string );
- heigth = myTMFont.GetStringHeight( string );
- cout << "W=" << width << " H=" << heigth << endl;
-*/
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
-//d glEnable(GL_DEPTH_TEST);
-}
-
-void loadGLfont(/*int scalar*/)
-{
- if (!TFLoaded)
- {
-/* //-------abd
- QString filename = getenv( "CSF_QADResources" );
- filename = filename + QDir::separator() + "times.tmf";
- if (!myTMFont.Create( filename, 19436))
- {
- cout << "!Texture loading error" << endl;
- return;
- }
- //-------abd */
- staticGlFont = new GLViewer_TexFont();
- staticGlFont->generateTexture();
-
- TFLoaded = GL_TRUE;
-//! BuildFont(size);
- }
-}
-
static GLuint displayListBase( QFont* theFont )
{
GLuint aList = 0;
{
myXScale = myYScale = 0.0;
myObjects.clear();
- myTextList = -1;
+ myTextList = 0/*-1*/;
myObjectType = "GLViewer_Object";
+ myPriority = 0;
}
GLViewer_Drawer::~GLViewer_Drawer()
glDeleteLists( myTextList, 1 );
}
+GLuint GLViewer_Drawer::loadTexture( const QString& fileName )
+{
+ QImage buf;
+ if ( fileName.isEmpty() || !buf.load( fileName ) )
+ return 0;
+
+ int w = buf.width();
+ int h = buf.height();
+
+ int size = 16;
+ while( size < w || size < h )
+ size = size * 2;
+
+ GLuint texture;
+ GLubyte* pixels = new GLubyte[ size * size * 4 ];
+
+ for( int i = 0; i < size; i++ )
+ {
+ for( int j = 0; j < size; j++ )
+ {
+ GLubyte r, g, b;
+ if( j < w && i < h )
+ {
+ QRgb pixel = buf.pixel( j, h - i - 1 );
+ r = (GLubyte)qRed( pixel );
+ g = (GLubyte)qGreen( pixel );
+ b = (GLubyte)qBlue( pixel );
+ }
+ else
+ {
+ r = (GLubyte)255;
+ g = (GLubyte)255;
+ b = (GLubyte)255;
+ }
+
+ int index = 4 * ( i * size + j );
+ pixels[ index ] = r;
+ pixels[ index + 1 ] = g;
+ pixels[ index + 2 ] = b;
+
+ if( r == (GLubyte)255 && g == (GLubyte)255 && b == (GLubyte)255 )
+ pixels[ index + 3 ] = (GLubyte)0;
+ else
+ pixels[ index + 3 ] = (GLubyte)255;
+ }
+ }
+
+ //initialize texture
+ glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
+ glGenTextures( 1, &texture );
+ glBindTexture( GL_TEXTURE_2D, texture );
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
+ glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, size, size, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, pixels );
+
+ delete[] pixels;
+
+ return texture;
+}
+
+void GLViewer_Drawer::drawTexture( GLuint texture, GLint size, GLfloat x, GLfloat y )
+{
+ float xScale = myXScale;
+ float yScale = myYScale;
+
+ glColor4f( 1.0, 1.0, 1.0, 1.0 );
+
+ glEnable( GL_TEXTURE_2D );
+ glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
+ glAlphaFunc( GL_GREATER, 0.95F );
+ glEnable( GL_ALPHA_TEST );
+
+ glBindTexture( GL_TEXTURE_2D, texture );
+ glBegin( GL_QUADS );
+
+ glTexCoord2f( 0.0, 0.0 );
+ glVertex3f( x-size/2./xScale, y-size/2./yScale, 0.0 );
+
+ glTexCoord2f( 0.0, 1.0 );
+ glVertex3f( x-size/2./xScale, y+size/2./yScale, 0.0 );
+
+ glTexCoord2f( 1.0, 1.0 );
+ glVertex3f( x+size/2./xScale, y+size/2./yScale, 0.0 );
+
+ glTexCoord2f( 1.0, 0.0 );
+ glVertex3f( x+size/2./xScale, y-size/2./yScale, 0.0 );
+
+ glEnd();
+ glFlush();
+
+ glDisable( GL_ALPHA_TEST );
+ glDisable( GL_TEXTURE_2D );
+}
+
void GLViewer_Drawer::drawText( const QString& text, GLfloat xPos, GLfloat yPos,
const QColor& color, QFont* theFont, int theSeparator, DisplayTextFormat theFormat )
{
}
}
-#else //#ifdef BITMAP
-GLuint fontOffset;
-
-GLubyte space[] =
- {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
-
-GLubyte letters[][13] = {
- {0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18},
- {0x00, 0x00, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe},
- {0x00, 0x00, 0x7e, 0xe7, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xe7, 0x7e},
- {0x00, 0x00, 0xfc, 0xce, 0xc7, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc7, 0xce, 0xfc},
- {0x00, 0x00, 0xff, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0xff},
- {0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xc0, 0xff},
- {0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xcf, 0xc0, 0xc0, 0xc0, 0xc0, 0xe7, 0x7e},
- {0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3},
- {0x00, 0x00, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e},
- {0x00, 0x00, 0x7c, 0xee, 0xc6, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06},
- {0x00, 0x00, 0xc3, 0xc6, 0xcc, 0xd8, 0xf0, 0xe0, 0xf0, 0xd8, 0xcc, 0xc6, 0xc3},
- {0x00, 0x00, 0xff, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0},
- {0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xdb, 0xff, 0xff, 0xe7, 0xc3},
- {0x00, 0x00, 0xc7, 0xc7, 0xcf, 0xcf, 0xdf, 0xdb, 0xfb, 0xf3, 0xf3, 0xe3, 0xe3},
- {0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xe7, 0x7e},
- {0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe},
- {0x00, 0x00, 0x3f, 0x6e, 0xdf, 0xdb, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0x66, 0x3c},
- {0x00, 0x00, 0xc3, 0xc6, 0xcc, 0xd8, 0xf0, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe},
- {0x00, 0x00, 0x7e, 0xe7, 0x03, 0x03, 0x07, 0x7e, 0xe0, 0xc0, 0xc0, 0xe7, 0x7e},
- {0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff},
- {0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3},
- {0x00, 0x00, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3},
- {0x00, 0x00, 0xc3, 0xe7, 0xff, 0xff, 0xdb, 0xdb, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3},
- {0x00, 0x00, 0xc3, 0x66, 0x66, 0x3c, 0x3c, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3},
- {0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3},
- {0x00, 0x00, 0xff, 0xc0, 0xc0, 0x60, 0x30, 0x7e, 0x0c, 0x06, 0x03, 0x03, 0xff}
-};
-
-void makeRasterFont()
+void GLViewer_Drawer::drawText( GLViewer_Object* theObject )
{
- GLuint i, j;
- glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
+ if( !theObject )
+ return;
- fontOffset = glGenLists( 128 );
- for ( i = 0, j = 'A'; i < 26; i++, j++ )
- {
- glNewList( fontOffset + j, GL_COMPILE );
- glBitmap( CHAR_W, CHAR_H, 0.0, 2.0, CHAR_W+WIDTH, 0.0, letters[i] );
- glEndList();
- }
- glNewList( fontOffset + ' ', GL_COMPILE );
- glBitmap( CHAR_W, CHAR_H, 0.0, 2.0, CHAR_W+WIDTH, 0.0, space );
- glEndList();
+ GLViewer_Text* aText = theObject->getGLText();
+ if( !aText )
+ return;
+
+ GLfloat aPosX, aPosY;
+ aText->getPosition( aPosX, aPosY );
+ // get temporary copy of font
+ QFont aTmpVarFont = aText->getFont();
+ drawText( aText->getText(), aPosX, aPosY, aText->getColor(), &aTmpVarFont, aText->getSeparator(), aText->getDisplayTextFormat() );
}
-void GLViewer_Drawer::drawText( const QString& text, int xPos, int yPos, const QColor& color, QFont theFont, int theSeparator )
+void GLViewer_Drawer::drawGLText( QString text, float x, float y,
+ int hPosition, int vPosition, QColor color, bool smallFont )
{
- glShadeModel( GL_FLAT );
- makeRasterFont();
+ QFont aFont( "Arial", 10, QFont::Bold );
+ if( smallFont )
+ aFont.setPointSize( 8 );
- myTextList = glGenLists( 1 );
- glNewList( myTextList, GL_COMPILE );
- glColor3f( ( GLfloat )color.red() / 255,
- ( GLfloat )color.green() / 255,
- ( GLfloat )color.blue() / 255 );
- glRasterPos2i( xPos + TEXT_GAP / myXScale, yPos + TEXT_GAP / myYScale );
- printString( text );
- glEndList();
+ QFontMetrics aFontMetrics( aFont );
+ float width = aFontMetrics.width( text ) / myXScale;
+ float height = aFontMetrics.height() / myXScale;
+ float gap = 5 / myXScale;
- if ( myTextList != -1 )
- glCallList( myTextList );
+ switch( hPosition )
+ {
+ case GLText_Left : x -= ( gap + width ); break;
+ case GLText_Center : x -= width / 2; break;
+ case GLText_Right : x += gap; break;
+ default : break;
+ }
+
+ switch( vPosition )
+ {
+ case GLText_Top : y += height * 0.5; break;
+ case GLText_Center : y -= height * 0.5; break;
+ case GLText_Bottom : y -= height * 1.5; break;
+ default : break;
+ }
+
+ drawText( text, x, y, color, &aFont, 2 );
}
-#endif //BITMAP
-void GLViewer_Drawer::drawText( GLViewer_Object* theObject )
+void GLViewer_Drawer::drawRectangle( GLViewer_Rect* rect, QColor color )
{
- if( !theObject )
- return;
-
- GLViewer_Text* aText = theObject->getGLText();
- if( !aText )
+ if( !rect )
return;
- GLfloat aPosX, aPosY;
- aText->getPosition( aPosX, aPosY );
- drawText( aText->getText(), aPosX, aPosY, aText->getColor(), &(aText->getFont()), aText->getSeparator(), aText->getDisplayTextFormat() );
+ float x1 = rect->left();
+ float x2 = rect->right();
+ float y1 = rect->bottom();
+ float y2 = rect->top();
+
+ glColor3f( ( GLfloat )color.red() / 255,
+ ( GLfloat )color.green() / 255,
+ ( GLfloat )color.blue() / 255 );
+ glLineWidth( 1.0 );
+
+ glBegin( GL_LINE_LOOP );
+ glVertex2f( x1, y1 );
+ glVertex2f( x1, y2 );
+ glVertex2f( x2, y2 );
+ glVertex2f( x2, y1 );
+ glEnd();
}
bool GLViewer_Drawer::translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS )
return result;
}
#endif
-
-/***************************************************************************
-** Class: GLViewer_MarkerDrawer
-** Descr: Drawer for GLViewer_MarkerSet
-** Module: GLViewer
-** Created: UI team, 03.10.01
-****************************************************************************/
-#define SEGMENTS 20
-#define STEP 2 * PI / SEGMENTS
-
-GLfloat sin_table[SEGMENTS];
-GLfloat cos_table[SEGMENTS];
-
-GLViewer_MarkerDrawer::GLViewer_MarkerDrawer()
-: GLViewer_Drawer()
-{
- GLfloat angle = 0.0;
- for ( int i = 0; i < SEGMENTS; i++ )
- {
- sin_table[i] = sin( angle );
- cos_table[i] = cos( angle );
- angle += float( STEP );
- }
- myTextList = 0;//-1;
- myObjectType = "GLViewer_MarkerSet";
-}
-
-GLViewer_MarkerDrawer::~GLViewer_MarkerDrawer()
-{
- glDeleteLists( myTextList, 1 );
-}
-
-void GLViewer_MarkerDrawer::create( float xScale, float yScale, bool onlyUpdate )
-{
-// cout << "GLViewer_MarkerDrawer::create " << scaleX << " " << scaleY << endl;
-
- QValueList<int>::Iterator it;
- QValueList<int>::Iterator EndIt;
- QValueList<GLViewer_Object*>::Iterator anObjectIt = myObjects.begin();
- QValueList<GLViewer_Object*>::Iterator anEndObjectIt = myObjects.end();
-
- myXScale = xScale;
- myYScale = yScale;
-
- QColor colorN, colorH, colorS;
-
- GLViewer_MarkerSet* aMarkerSet = NULL;
- GLViewer_AspectLine* anAspectLine = NULL;
-
- for( ; anObjectIt != anEndObjectIt; anObjectIt++ )
- {
- aMarkerSet = ( GLViewer_MarkerSet* )(*anObjectIt);
- anAspectLine = aMarkerSet->getAspectLine();
- anAspectLine->getLineColors( colorN, colorH, colorS );
-
- float* aXCoord = aMarkerSet->getXCoord();
- float* anYCoord = aMarkerSet->getYCoord();
- float aRadius = aMarkerSet->getMarkerSize();
-
- QValueList<int> aHNumbers, anUHNumbers, aSelNumbers, anUSelNumbers;
- aMarkerSet->exportNumbers( aHNumbers, anUHNumbers, aSelNumbers, anUSelNumbers );
-
- if( onlyUpdate )
- {
- EndIt = anUHNumbers.end();
- for( it = anUHNumbers.begin(); it != EndIt; ++it )
- {
- drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorN, anAspectLine );
- //cout << "GLViewer_MarkerDrawer::create UH " << *it << endl;
- }
-
- EndIt = anUSelNumbers.end();
- for( it = anUSelNumbers.begin(); it != EndIt; ++it )
- drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorN, anAspectLine );
-
- EndIt = aSelNumbers.end();
- for( it = aSelNumbers.begin(); it != EndIt; ++it )
- drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorS, anAspectLine );
-
- EndIt = aHNumbers.end();
- for( it = aHNumbers.begin(); it != EndIt; ++it )
- {
- drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorH, anAspectLine );
- //cout << "GLViewer_MarkerDrawer::create H " << *it << endl;
- }
- }
- else
- {
- int aNumber = aMarkerSet->getNumMarkers();
- for( int i = 0; i < aNumber; i++ )
- drawMarker( aXCoord[i], anYCoord[i], aRadius, colorN, anAspectLine );
-
- EndIt = anUSelNumbers.end();
- for( it = anUSelNumbers.begin(); it != EndIt; ++it )
- drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorN, anAspectLine );
-
- EndIt = aSelNumbers.end();
- for( it = aSelNumbers.begin(); it != EndIt; ++it )
- drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorS, anAspectLine );
- }
- //float aXPos = 0, anYPos = 0;
- if( aMarkerSet->getGLText()->getText() != "" )
- {
- //float aXPos = 0, anYPos = 0;
- //aMarkerSet->getGLText()->getPosition( aXPos, anYPos );
- //drawText( aMarkerSet->getGLText()->getText(), aXPos, anYPos, colorN, &aMarkerSet->getGLText()->getFont(), aMarkerSet->getGLText()->getSeparator() );
- drawText( aMarkerSet );
- }
- }
-}
-
-void GLViewer_MarkerDrawer::drawMarker( float& theXCoord, float& theYCoord,
- float& theRadius, QColor& theColor, GLViewer_AspectLine* theAspectLine )
-{
- glColor3f( ( GLfloat )theColor.red() / 255,
- ( GLfloat )theColor.green() / 255,
- ( GLfloat )theColor.blue() / 255 );
-
- glLineWidth( theAspectLine->getLineWidth() );
-
- if ( theAspectLine->getLineType() == 0 )
- glBegin( GL_LINE_LOOP );
- else
- glBegin( GL_LINE_STRIP);
-
- for ( int i = 0; i < SEGMENTS; i++ )
- glVertex2f( theXCoord + cos_table[i] * theRadius / myXScale,
- theYCoord + sin_table[i] * theRadius / myYScale );
- glEnd();
-}
-
-/***************************************************************************
-** Class: GLViewer_PolylineDrawer
-** Descr: Drawer for GLViewer_Polyline
-** Module: GLViewer
-** Created: UI team, 03.10.01
-****************************************************************************/
-
-GLViewer_PolylineDrawer::GLViewer_PolylineDrawer()
-:GLViewer_Drawer()
-{
- myTextList = 0;//-1;
- myObjects.clear();
- myObjectType = "GLViewer_Polyline";
-}
-
-GLViewer_PolylineDrawer::~GLViewer_PolylineDrawer()
-{
- glDeleteLists( myTextList, 1 );
-}
-
-void GLViewer_PolylineDrawer::create( float xScale, float yScale, bool onlyUpdate )
-{
- QValueList<GLViewer_Object*>::Iterator aObjectIt = myObjects.begin();
- QValueList<GLViewer_Object*>::Iterator aObjectEndIt = myObjects.end();
-
- myXScale = xScale;
- myYScale = yScale;
-
- QColor color, colorN, colorH, colorS;
- GLViewer_AspectLine* anAspect = NULL;
- GLViewer_Polyline* aPolyline = NULL;
-// myAspectLine->getLineColors( colorN, colorH, colorS );
- for( ; aObjectIt != aObjectEndIt; aObjectIt++ )
- {
- anAspect = (*aObjectIt)->getAspectLine();
- aPolyline = (GLViewer_Polyline*)(*aObjectIt);
-
-
- anAspect->getLineColors( colorN, colorH, colorS );
- if( onlyUpdate )
- {
- if( aPolyline->isHighlighted() )
- color = colorH;
- else if( aPolyline->isSelected() )
- color = colorS;
- else
- color = colorN;
- }
- else
- {
- if( aPolyline->isSelected() )
- color = colorS;
- else
- color = colorN;
- }
-
- float* aXCoord = aPolyline->getXCoord();
- float* anYCoord = aPolyline->getYCoord();
- int aSize = aPolyline->getNumber();
-
- glColor3f( ( GLfloat )color.red() / 255,
- ( GLfloat )color.green() / 255,
- ( GLfloat )color.blue() / 255 );
-
- glLineWidth( anAspect->getLineWidth() );
-
- if ( anAspect->getLineType() == 0 )
- glBegin( GL_LINE_LOOP );
- else
- glBegin( GL_LINE_STRIP);
-
- for( int i = 0; i < aSize ; i++ )
- glVertex2f( aXCoord[ i ], anYCoord[ i ] );
-
- if( aPolyline->isClosed() )
- glVertex2f( aXCoord[ 0 ], anYCoord[ 0 ] );
-
- glEnd();
-
- if( aPolyline->getGLText()->getText() != "" )
- {
- //float aXPos = 0, anYPos = 0;
- //aPolyline->getGLText()->getPosition( aXPos, anYPos );
- //drawText( aPolyline->getGLText()->getText(), aXPos, anYPos, color, &aPolyline->getGLText()->getFont(), aPolyline->getGLText()->getSeparator() );
- drawText( aPolyline );
- }
- }
-}
-
-/***************************************************************************
-** Class: GLViewer_TextDrawer
-** Descr:
-** Module: GLViewer
-** Created: UI team, 27.02.04
-****************************************************************************/
-
-GLViewer_TextDrawer::GLViewer_TextDrawer()
-: GLViewer_Drawer()
-{
- myTextList = 0;//-1;
- myObjects.clear();
- myObjectType = "GLViewer_TextObject";
-}
-
-GLViewer_TextDrawer::~GLViewer_TextDrawer()
-{
- glDeleteLists( myTextList, 1 );
-}
-
-void GLViewer_TextDrawer::create( float xScale, float yScale, bool onlyUpdate )
-{
- QValueList<GLViewer_Object*>::Iterator aObjectIt = myObjects.begin();
- QValueList<GLViewer_Object*>::Iterator aObjectEndIt = myObjects.end();
-
- myXScale = xScale;
- myYScale = yScale;
-
- QColor color, colorN, colorH, colorS;
- GLViewer_AspectLine* anAspect = NULL;
- GLViewer_TextObject* anObject = NULL;
- //float aXPos = 0, anYPos = 0;
- for( ; aObjectIt != aObjectEndIt; aObjectIt++ )
- {
- anObject = (GLViewer_TextObject*)(*aObjectIt);
- anAspect = anObject->getAspectLine();
-
- anAspect->getLineColors( colorN, colorH, colorS );
- if( onlyUpdate )
- {
- if( anObject->isHighlighted() )
- color = colorH;
- else if( anObject->isSelected() )
- color = colorS;
- else
- color = colorN;
- }
- else
- {
- if( anObject->isSelected() )
- color = colorS;
- else
- color = colorN;
- }
-
- //anObject->getGLText()->getPosition( aXPos, anYPos );
- //drawText( anObject->getGLText()->getText(), aXPos, anYPos, color, &(anObject->getGLText()->getFont()), anObject->getGLText()->getSeparator() );
- drawText( anObject );
- }
-}
-
-void GLViewer_TextDrawer::updateObjects()
-{
- QValueList<GLViewer_Object*>::Iterator aObjectIt = myObjects.begin();
- QValueList<GLViewer_Object*>::Iterator aObjectEndIt = myObjects.end();
- for( ; aObjectIt != aObjectEndIt; aObjectIt++ )
- (*aObjectIt)->compute();
-}
#include "GLViewer_Defs.h"
class GLViewer_Object;
-class GLViewer_Text;
-class GLViewer_AspectLine;
+class GLViewer_Rect;
class GLViewer_CoordSystem;
#ifdef WNT
#pragma warning( disable:4251 )
#endif
-struct GLVIEWER_EXPORT GLViewer_TexIdStored
+struct GLVIEWER_API GLViewer_TexIdStored
{
- GLuint myTexFontId;
- int myTexFontWidth;
- int myTexFontHeight;
+ GLuint myTexFontId;
+ int myTexFontWidth;
+ int myTexFontHeight;
};
-struct GLVIEWER_EXPORT GLViewer_TexFindId
+struct GLVIEWER_API GLViewer_TexFindId
{
- QString myFontString;
- int myViewPortId;
- bool operator < (const GLViewer_TexFindId theStruct) const
- {
- if ( myViewPortId != theStruct.myViewPortId ) return myViewPortId < theStruct.myViewPortId;
- else return myFontString < theStruct.myFontString;
- }
+ QString myFontString;
+ int myViewPortId;
+ bool operator < (const GLViewer_TexFindId theStruct) const
+ {
+ if ( myViewPortId != theStruct.myViewPortId ) return myViewPortId < theStruct.myViewPortId;
+ else return myFontString < theStruct.myFontString;
+ }
};
-class GLVIEWER_EXPORT GLViewer_TexFont
+class GLVIEWER_API GLViewer_TexFont
{
public:
- GLViewer_TexFont();
- GLViewer_TexFont( QFont* theFont, int theSeparator = 2 );
- ~GLViewer_TexFont();
-
- void generateTexture();
- void drawString( QString theStr, GLdouble theX = 0.0, GLdouble theY = 0.0 );
-
- int getSeparator(){ return mySeparator; }
- void setSeparator( int theSeparator ){ mySeparator = theSeparator; }
-
- int getStringWidth( QString );
- int getStringHeight();
-
- static QMap<GLViewer_TexFindId,GLViewer_TexIdStored> TexFontBase;
- static int LastmyTexStoredId;
-
+ GLViewer_TexFont();
+ GLViewer_TexFont( QFont* theFont, int theSeparator = 2 );
+ ~GLViewer_TexFont();
+
+ void generateTexture();
+ void drawString( QString theStr, GLdouble theX = 0.0, GLdouble theY = 0.0 );
+
+ int getSeparator(){ return mySeparator; }
+ void setSeparator( int theSeparator ){ mySeparator = theSeparator; }
+
+ int getStringWidth( QString );
+ int getStringHeight();
+
+ static QMap<GLViewer_TexFindId,GLViewer_TexIdStored> TexFontBase;
+ static int LastmyTexStoredId;
+
protected:
- int* myWidths;
- int* myPositions;
- QFont myQFont;
- GLuint myTexFont;
- int myTexFontWidth;
- int myTexFontHeight;
- int mySeparator;
+ int* myWidths;
+ int* myPositions;
+ QFont myQFont;
+ GLuint myTexFont;
+ int myTexFontWidth;
+ int myTexFontHeight;
+ int mySeparator;
};
/***************************************************************************
** Module: GLViewer
** Created: UI team, 03.10.01
****************************************************************************/
-class GLVIEWER_EXPORT GLViewer_Drawer: public QObject
+class GLVIEWER_API GLViewer_Drawer
{
- Q_OBJECT
-
public:
- GLViewer_Drawer();
- virtual ~GLViewer_Drawer();
+ enum { GLText_Center = 0, GLText_Left, GLText_Right, GLText_Top, GLText_Bottom };
+
+public:
+ GLViewer_Drawer();
+ virtual ~GLViewer_Drawer();
+
+ enum ObjectStatus { OS_Normal = 0, OS_Highlighted = 1, OS_Selected = 2 };
+ enum ClosedStatus { CS_CLOSED = 0, CS_OPEN = 1 };
+
+ virtual void create( float, float, bool ) = 0;
+
+ virtual void addObject( GLViewer_Object* theObject ){ myObjects.append( theObject ); }
+ virtual void clear(){ myObjects.clear(); }
- enum ObjectStatus { OS_Normal = 0, OS_Highlighted = 1, OS_Selected = 2 };
- enum ClosedStatus { CS_CLOSED = 0, CS_OPEN = 1 };
-
- virtual void create( float, float, bool ) = 0;
-
- virtual void addObject( GLViewer_Object* theObject ){ myObjects.append( theObject ); }
- virtual void clear(){ myObjects.clear(); }
-
- QString getObjectType(){ return myObjectType; }
-
- static void destroyAllTextures();
-
- virtual bool translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );
- virtual bool translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
+ QString getObjectType() const { return myObjectType; }
+ int getPriority() const { return myPriority; }
+
+ static void destroyAllTextures();
+
+ virtual bool translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );
+ virtual bool translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
#ifdef WIN32
- virtual bool translateToEMF( HDC hDC, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
+ virtual bool translateToEMF( HDC hDC, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
#endif
-
- void drawText( const QString& text,
- GLfloat xPos, GLfloat yPos,
- const QColor& color,
- QFont* aFont, int,
- DisplayTextFormat = DTF_BITMAP );
- protected:
- virtual void drawText( GLViewer_Object* );
-
- float myXScale;
- float myYScale;
-
- QValueList<GLViewer_Object*> myObjects;
- GLuint myTextList;
-
- QString myObjectType;
-};
-
-/***************************************************************************
-** Class: GLViewer_MarkerDrawer
-** Descr: Drawer for GLViewer_MarkerSet
-** Module: GLViewer
-** Created: UI team, 03.10.01
-****************************************************************************/
-#ifndef GLVIEWER_MARKERDRAWER_H
-#define GLVIEWER_MARKERDRAWER_H
-
-class GLVIEWER_EXPORT GLViewer_MarkerDrawer : public GLViewer_Drawer
-{
-public:
- GLViewer_MarkerDrawer();
- ~GLViewer_MarkerDrawer();
-
- virtual void create( float, float, bool );
-
-private:
- void drawMarker( float&, float&, float&, QColor&, GLViewer_AspectLine* );
-};
+
+ GLuint loadTexture( const QString& fileName );
+ void drawTexture( GLuint texture, GLint size, GLfloat x, GLfloat y );
-#endif // GLVIEWER_MARKERDRAWER_H
+ void drawText( const QString& text,
+ GLfloat xPos, GLfloat yPos,
+ const QColor& color,
+ QFont* aFont, int,
+ DisplayTextFormat = DTF_BITMAP );
-/***************************************************************************
-** Class: GLViewer_PolylineDrawer
-** Descr: Drawer for GLViewer_Polyline
-** Module: GLViewer
-** Created: UI team, 03.10.01
-****************************************************************************/
-#ifndef GLVIEWER_POLYLINEDRAWER_H
-#define GLVIEWER_POLYLINEDRAWER_H
+ void drawGLText( QString text, float x, float y,
+ int hPosition = GLText_Center, int vPosition = GLText_Center,
+ QColor color = Qt::black, bool smallFont = false );
-class GLVIEWER_EXPORT GLViewer_PolylineDrawer : public GLViewer_Drawer
-{
-public:
- GLViewer_PolylineDrawer();
- ~GLViewer_PolylineDrawer();
-
- virtual void create( float, float, bool );
-};
+ static void drawRectangle( GLViewer_Rect*, QColor = Qt::black );
-#endif // GLVIEWER_POLYLINEDRAWER_H
-
-/***************************************************************************
-** Class: GLViewer_TextDrawer
-** Descr:
-** Module: GLViewer
-** Created: UI team, 27.02.04
-****************************************************************************/
-#ifndef GLVIEWER_TEXTDRAWER
-#define GLVIEWER_TEXTDRAWER
+protected:
+ virtual void drawText( GLViewer_Object* );
-class GLVIEWER_EXPORT GLViewer_TextDrawer: public GLViewer_Drawer
-{
+ float myXScale;
+ float myYScale;
-public:
- GLViewer_TextDrawer();
- ~GLViewer_TextDrawer();
-
- virtual void create( float, float, bool );
- void updateObjects(); //after update font
+ QValueList<GLViewer_Object*> myObjects;
+ GLuint myTextList;
+
+ QString myObjectType;
+ int myPriority;
};
-#endif // GLVIEWER_TEXTDRAWER
-
#ifdef WNT
#pragma warning ( default:4251 )
#endif
--- /dev/null
+/***************************************************************************
+** Class: GLViewer_Geom
+** Descr:
+** Module: GLViewer
+** Created: UI team, 16.11.04
+****************************************************************************/
+
+//#include <GLViewerAfx.h>
+#include <GLViewer_Geom.h>
+
+#define FAR_POINT 1e10 // Value used as a "very distant" co-ordinate
+#define TOLERANCE 1e-3
+
+//================================================================
+// Function : GLViewer_Segment
+// Purpose : constructs a real segment bounded by two points
+//================================================================
+GLViewer_Segment::GLViewer_Segment( const GLViewer_Pnt& thePnt1,
+ const GLViewer_Pnt& thePnt2 )
+: myPnt1( thePnt1 ),
+ myPnt2( thePnt2 )
+{
+ myA = myPnt1.y() - myPnt2.y();
+ myB = myPnt2.x() - myPnt1.x();
+ myC = myPnt1.x() * myPnt2.y() - myPnt2.x() * myPnt1.y();
+}
+
+//================================================================
+// Function : GLViewer_Segment
+// Purpose : constructs a ray starting at <thePnt> and directed
+// along positive X axis direction (or Y axis if vertical )
+//================================================================
+GLViewer_Segment::GLViewer_Segment( const GLViewer_Pnt& thePnt,
+ const GLfloat theA,
+ const GLfloat theB,
+ const GLfloat theC )
+: myPnt1( thePnt ),
+ myA( theA ),
+ myB( theB ),
+ myC( theC )
+{
+ if ( fabs( myB ) < TOLERANCE )
+ myPnt2 = GLViewer_Pnt( myPnt1.x(), FAR_POINT );
+ else
+ myPnt2 = GLViewer_Pnt( FAR_POINT, - myA / myB * FAR_POINT - myC / myB );
+}
+
+//================================================================
+// Function : GLViewer_Segment
+// Purpose : destructor, does nothing
+//================================================================
+GLViewer_Segment::~GLViewer_Segment()
+{
+}
+
+//================================================================
+// Function : HasIntersection
+// Purpose : detects intersection with segment <theOther>
+//================================================================
+bool GLViewer_Segment::HasIntersection( const GLViewer_Segment& theOther ) const
+{
+ bool aRes = false;
+ GLfloat aDiv = myA * theOther.myB - myB * theOther.myA;
+ if ( fabs( aDiv ) > TOLERANCE )
+ {
+ GLfloat aX = ( myB * theOther.myC - theOther.myB * myC ) / aDiv;
+ GLfloat aX11 = myPnt1.x() > myPnt2.x() ? myPnt2.x() : myPnt1.x();
+ GLfloat aX12 = myPnt1.x() > myPnt2.x() ? myPnt1.x() : myPnt2.x();
+ GLfloat aX21 = theOther.myPnt1.x() > theOther.myPnt2.x() ? theOther.myPnt2.x() : theOther.myPnt1.x();
+ GLfloat aX22 = theOther.myPnt1.x() > theOther.myPnt2.x() ? theOther.myPnt1.x() : theOther.myPnt2.x();
+
+ GLfloat aY = ( myC * theOther.myA - theOther.myC * myA ) / aDiv;
+ GLfloat aY11 = myPnt1.y() > myPnt2.y() ? myPnt2.y() : myPnt1.y();
+ GLfloat aY12 = myPnt1.y() > myPnt2.y() ? myPnt1.y() : myPnt2.y();
+ GLfloat aY21 = theOther.myPnt1.y() > theOther.myPnt2.y() ? theOther.myPnt2.y() : theOther.myPnt1.y();
+ GLfloat aY22 = theOther.myPnt1.y() > theOther.myPnt2.y() ? theOther.myPnt1.y() : theOther.myPnt2.y();
+
+ if ( fabs( aX11 - aX12 ) > TOLERANCE )
+ aRes = aX11 < aX && aX < aX12;
+ else
+ aRes = aY11 < aY && aY < aY12;
+
+ if ( aRes )
+ {
+ if ( fabs( aX21 - aX22 ) > TOLERANCE )
+ aRes = aX21 < aX && aX < aX22;
+ else
+ aRes = aY21 < aY && aY < aY22;
+ }
+ }
+
+ return aRes;
+}
+
+//================================================================
+// Function : GLViewer_Poly
+// Purpose : constructs a closed polygon from the given ordered list of points
+//================================================================
+GLViewer_Poly::GLViewer_Poly( const GLViewer_PntList* thePoints )
+: myPoints( (GLViewer_PntList*)thePoints )
+{
+}
+
+//================================================================
+// Function : ~GLViewer_Poly
+// Purpose : destructor, <myPoints> mustn't be deleted here!
+//================================================================
+GLViewer_Poly::~GLViewer_Poly()
+{
+}
+
+//================================================================
+// Function : IsIn
+// Purpose : returns true if <thePnt> lies within this polygon
+//================================================================
+bool GLViewer_Poly::IsIn( const GLViewer_Pnt& thePnt ) const
+{
+ if ( !myPoints )
+ return false;
+
+ //cout << thePnt.x() << endl;
+ //cout << thePnt.y() << endl << endl;
+
+ int aNbInter = 0;
+ GLViewer_Segment aRay( thePnt, 0., 1., -thePnt.y() );
+
+ GLViewer_PntList::const_iterator it1 = myPoints->begin();
+ GLViewer_PntList::const_iterator it2 = myPoints->begin();
+ ++it2;
+ for ( ; it1 != myPoints->end(); ++it1, ++it2 )
+ {
+ if ( it2 == myPoints->end() )
+ it2 = myPoints->begin();
+
+ if ( aRay.HasIntersection( GLViewer_Segment( *it1, *it2 ) ) )
+ aNbInter++;
+ }
+
+ return ( aNbInter % 2 == 1 );
+}
+/*
+//================================================================
+// Function : IsIn
+// Purpose : returns true if <thePnt> lies within this polygon
+//================================================================
+bool GLViewer_Poly::IsIn( const GLViewer_Pnt& thePnt, const float tolerance ) const
+{
+ if ( !myPoints )
+ return false;
+
+ float x = thePnt.x();
+ float y = thePnt.y();
+ bool res = false;
+
+ GLViewer_Pnt p1( x - tolerance, y - tolerance );
+ GLViewer_Pnt p2( x - tolerance, y + tolerance );
+ GLViewer_Pnt p3( x + tolerance, y - tolerance );
+ GLViewer_Pnt p4( x + tolerance, y + tolerance );
+
+ res = ( IsInPnt( thePnt ) ||
+ IsInPnt( p1 ) || IsInPnt( p2 ) || IsInPnt( p3 ) || IsInPnt( p4 ) );
+
+ return res;
+}
+*/
+//================================================================
+// Function : IsCovers
+// Purpose : returns true if <thePoly> covers this polygon
+//================================================================
+bool GLViewer_Poly::IsCovers( const GLViewer_Poly& thePoly ) const
+{
+ if ( !myPoints || !thePoly.Count() )
+ return false;
+
+ GLViewer_PntList::const_iterator it = myPoints->begin();
+
+ for ( ; it != myPoints->end(); ++it )
+ {
+ if( !thePoly.IsIn( *it ) )
+ return false;
+ }
+
+ return true;
+}
+
+//================================================================
+// Function : IsCovers
+// Purpose : returns true if <theRect> covers this polygon
+//================================================================
+bool GLViewer_Poly::IsCovers( const GLViewer_Rect& theRect ) const
+{
+ if ( !myPoints ) //needs check for <theRect>
+ return false;
+
+ GLViewer_PntList aList;
+ GLViewer_PntList::iterator it = aList.begin();
+
+ aList.insert( it, GLViewer_Pnt( theRect.left(), theRect.top() ) );
+ aList.insert( it, GLViewer_Pnt( theRect.right(), theRect.top() ) );
+ aList.insert( it, GLViewer_Pnt( theRect.right(), theRect.bottom() ) );
+ aList.insert( it, GLViewer_Pnt( theRect.left(), theRect.bottom() ) );
+
+ return IsCovers( GLViewer_Poly( &aList ) );
+}
+
+//================================================================
+// Function : HasIntersection
+// Purpose : looks for any
+//================================================================
+bool GLViewer_Poly::HasIntersection( const GLViewer_Segment& theSegment ) const
+{
+ if ( !myPoints )
+ return false;
+
+ bool aRes = false;
+ GLViewer_PntList::const_iterator it1 = myPoints->begin();
+ GLViewer_PntList::const_iterator it2 = myPoints->begin();
+ ++it2;
+ for ( ; !aRes && it1 != myPoints->end(); ++it1, ++it2 )
+ {
+ if ( it2 == myPoints->end() )
+ it2 = myPoints->begin();
+
+ aRes = theSegment.HasIntersection( GLViewer_Segment( *it1, *it2 ) );
+ }
+
+ return aRes;
+}
--- /dev/null
+// File: GLViewer_Geom.h
+// Created: November, 2004
+// Author: OCC team
+// Copyright (C) CEA 2004
+
+#ifndef GLVIEWER_GEOM_H
+#define GLVIEWER_GEOM_H
+
+#include "GLViewer.h"
+
+#include <qrect.h>
+#include <qvaluelist.h>
+#include <qgl.h>
+#include <math.h>
+
+
+#ifdef WNT
+#pragma warning( disable:4251 )
+#endif
+
+// Class: GLViewer_Pnt
+// Descr: Substitution of QPoint for OpenGL
+
+struct GLVIEWER_API GLViewer_Pnt
+{
+public:
+ GLViewer_Pnt() : myX( 0. ), myY( 0. ) {};
+ GLViewer_Pnt( GLfloat theX, GLfloat theY ) : myX( theX ), myY( theY ) {}
+
+ GLfloat x() const { return myX; }
+ GLfloat y() const { return myY; }
+ void setX( GLfloat theX ) { myX = theX; }
+ void setY( GLfloat theY ) { myY = theY; }
+ void setXY( GLfloat theX, GLfloat theY ) { myX = theX; myY = theY; }
+ void move( GLfloat theDX, GLfloat theDY ) { myX += theDX; myY += theDY; }
+
+private:
+ GLfloat myX;
+ GLfloat myY;
+};
+
+typedef QValueList<GLViewer_Pnt> GLViewer_PntList;
+
+// Class: GLViewer_Rect
+// Descr: Substitution of QRect for OpenGL
+
+class GLVIEWER_API GLViewer_Rect
+{
+public:
+ GLViewer_Rect(): myLeft(0.0), myRight(0.0), myTop(0.0), myBottom(0.0){}
+ GLViewer_Rect( float theLeft, float theRight, float theTop, float theBottom )
+ : myLeft(theLeft), myRight(theRight), myTop(theTop), myBottom(theBottom) {}
+ GLViewer_Rect( QRect theRect ) {
+ myLeft = ( float )theRect.left(); myRight = ( float )theRect.right();
+ myTop = ( float )theRect.top(); myBottom = ( float )theRect.bottom(); }
+
+ float left() const { return myLeft; }
+ float right() const { return myRight; }
+ float top() const { return myTop; }
+ float bottom() const { return myBottom; }
+
+ float width() const { return fabs( myRight - myLeft ); }
+ float height() const { return fabs( myTop - myBottom ); }
+
+ void setLeft( float theLeft ) { myLeft = theLeft; }
+ void setRight( float theRight ) { myRight = theRight; }
+ void setTop( float theTop ) { myTop = theTop; }
+ void setBottom( float theBottom ) { myBottom = theBottom; }
+
+ void setCoords( float theLeft, float theRight, float theBottom, float theTop )
+ { myLeft = theLeft; myRight = theRight; myBottom = theBottom; myTop = theTop; }
+
+ QRect toQRect() { return QRect( ( int )myLeft, ( int )myBottom,
+ ( int )( myRight - myLeft ),
+ ( int )( myTop - myBottom ) ); }
+
+ void setIsEmpty( bool on ) { myIsEmpty = on; }
+ bool isEmpty() const { return myIsEmpty; }
+
+ bool isNull() const { return myLeft == 0.0 && myRight == 0.0 && myBottom == 0.0 && myTop == 0.0; }
+ bool isValid() const { return ( myLeft < myRight && myBottom < myTop ); }
+
+ bool contains( GLViewer_Pnt pnt ) { return ( pnt.x() > left() &&
+ pnt.x() < right() &&
+ pnt.y() > bottom() &&
+ pnt.y() < top() ); }
+
+protected:
+ float myLeft;
+ float myRight;
+ float myTop;
+ float myBottom;
+
+ bool myIsEmpty;
+};
+
+// Class: GLViewer_Segment
+// Descr: Segment for 2d detection
+
+class GLVIEWER_API GLViewer_Segment
+{
+public:
+ GLViewer_Segment( const GLViewer_Pnt& thePnt1,
+ const GLViewer_Pnt& thePnt2 );
+ // Ordinary segment construction
+
+ GLViewer_Segment( const GLViewer_Pnt& thePnt,
+ const GLfloat theA,
+ const GLfloat theB,
+ const GLfloat theC );
+ // Construction of a ray with given equation Ax + By + C = 0
+
+ ~GLViewer_Segment();
+
+ bool HasIntersection( const GLViewer_Segment& theOther ) const;
+ // Detects intersection with another segment or ray
+
+private:
+ GLViewer_Pnt myPnt1;
+ GLViewer_Pnt myPnt2;
+ GLfloat myA;
+ GLfloat myB;
+ GLfloat myC;
+};
+
+// Class: GLViewer_Poly
+// Descr: Polygon for 2d detection
+
+class GLVIEWER_API GLViewer_Poly
+{
+public:
+ GLViewer_Poly( const GLViewer_PntList* thePoints );
+ virtual ~GLViewer_Poly();
+
+ int Count() const { return myPoints->count(); }
+
+ virtual bool IsIn( const GLViewer_Pnt& thePnt ) const;
+ //virtual bool IsIn( const GLViewer_Pnt& thePnt, const float tolerance = 0 ) const;
+ // Detects if a point lies inside this polygon
+
+ virtual bool IsCovers( const GLViewer_Poly& thePoly ) const;
+ // Detect if a other polygon covers this polygon
+
+ virtual bool IsCovers( const GLViewer_Rect& theRect ) const;
+ // likes the above function
+
+ virtual bool HasIntersection( const GLViewer_Segment& theSegment ) const;
+ // Detects intersection of this polygon with a segment or a ray
+
+private:
+ GLViewer_PntList* myPoints;
+};
+
+#ifdef WNT
+#pragma warning ( default:4251 )
+#endif
+
+#endif
--- /dev/null
+// File: GLViewer_Grid.cxx
+// Created: November, 2004
+// Author: OCC team
+// Copyright (C) CEA 2004
+
+//#include <GLViewerAfx.h>
+#include "GLViewer_Grid.h"
+#include "GLViewer_Defs.h"
+
+#include <Precision.hxx>
+#include <qglobal.h>
+
+GLViewer_Grid::GLViewer_Grid() :
+ myGridList( 0 ), myGridHeight( (GLfloat)0.0 ), myGridWidth( (GLfloat)0.0 ),
+ myWinW( (GLfloat)0.0 ), myWinH( (GLfloat)0.0 ), myXSize( (GLfloat)0.0 ), myYSize( (GLfloat)0.0 ),
+ myXPan( (GLfloat)0.0 ), myYPan( (GLfloat)0.0 ), myXScale( (GLfloat)1.0 ), myYScale( (GLfloat)1.0 ),
+ myLineWidth( (GLfloat)0.05 ), myCenterWidth( (GLfloat)1.5 ), myCenterRadius( 5 ),
+ myScaleFactor( 10 ), myIsUpdate( GL_FALSE )
+{
+ myGridColor[0] = 0.5;
+ myGridColor[1] = 0.5;
+ myGridColor[2] = 0.5;
+ myAxisColor[0] = 0.75;
+ myAxisColor[1] = 0.75;
+ myAxisColor[2] = 0.75;
+}
+
+GLViewer_Grid::GLViewer_Grid( GLfloat width, GLfloat height,
+ GLfloat winW, GLfloat winH,
+ GLfloat xSize, GLfloat ySize,
+ GLfloat xPan, GLfloat yPan,
+ GLfloat xScale, GLfloat yScale ) :
+ myGridList( 0 ), myGridHeight( (GLfloat)0.0 ), myGridWidth( (GLfloat)0.0 ),
+ myWinW( (GLfloat)0.0 ), myWinH( (GLfloat)0.0 ), myXSize( (GLfloat)0.0 ), myYSize( (GLfloat)0.0 ),
+ myXPan( (GLfloat)0.0 ), myYPan( (GLfloat)0.0 ), myXScale( (GLfloat)1.0 ), myYScale( (GLfloat)1.0 ),
+ myLineWidth( (GLfloat)0.05 ), myCenterWidth( (GLfloat)1.5 ), myCenterRadius( 5 ),
+ myScaleFactor( 10 ), myIsUpdate( GL_FALSE )
+{
+ myGridColor[0] = 0.5;
+ myGridColor[1] = 0.5;
+ myGridColor[2] = 0.5;
+ myAxisColor[0] = 0.75;
+ myAxisColor[1] = 0.75;
+ myAxisColor[2] = 0.75;
+}
+
+GLViewer_Grid::~GLViewer_Grid()
+{
+}
+
+void GLViewer_Grid::draw()
+{
+ if ( myGridList == 0 || myIsUpdate )
+ initList();
+
+ glCallList( myGridList );
+}
+
+void GLViewer_Grid::setGridColor( GLfloat r, GLfloat g, GLfloat b )
+{
+ if( myGridColor[0] == r && myGridColor[1] == g && myGridColor[2] == b )
+ return;
+
+ myGridColor[0] = r;
+ myGridColor[1] = g;
+ myGridColor[2] = b;
+ myIsUpdate = GL_TRUE;
+}
+
+void GLViewer_Grid::setAxisColor( GLfloat r, GLfloat g, GLfloat b )
+{
+ if( myAxisColor[0] == r && myAxisColor[1] == g && myAxisColor[2] == b )
+ return;
+
+ myAxisColor[0] = r;
+ myAxisColor[1] = g;
+ myAxisColor[2] = b;
+ myIsUpdate = GL_TRUE;
+}
+
+void GLViewer_Grid::setGridWidth( float w )
+{
+ if( myGridWidth == w )
+ return;
+
+ myGridWidth = w;
+ myIsUpdate = GL_TRUE;
+}
+
+void GLViewer_Grid::setCenterRadius( int r )
+{
+ if( myCenterRadius == r )
+ return;
+
+ myCenterRadius = r;
+ myIsUpdate = GL_TRUE;
+}
+
+void GLViewer_Grid::setSize( float xSize, float ySize )
+{
+ if( myXSize == xSize && myYSize == ySize )
+ return;
+
+ myXSize = xSize;
+ myYSize = ySize;
+ myIsUpdate = GL_TRUE;
+}
+
+void GLViewer_Grid::setPan( float xPan, float yPan )
+{
+ if( myXPan == xPan && myYPan == yPan )
+ return;
+
+ myXPan = xPan;
+ myYPan = yPan;
+ myIsUpdate = GL_TRUE;
+}
+
+bool GLViewer_Grid::setZoom( float zoom )
+{
+ if( zoom == 1.0 )
+ return true;
+
+ //backup values
+ float bXScale = myXScale;
+ float bYScale = myYScale;
+
+ myXScale /= zoom;
+ myYScale /= zoom;
+
+ if( fabs(myXScale) < Precision::Confusion() || fabs(myYScale) < Precision::Confusion() )
+ { //undo
+ myXScale = bXScale;
+ myYScale = bYScale;
+ return false;
+ }
+
+ myGridWidth /= zoom;
+ myGridHeight /= zoom;
+ myIsUpdate = GL_TRUE;
+ return true;
+}
+
+void GLViewer_Grid::setResize( float WinW, float WinH, float zoom )
+{
+ if( myWinW == WinW && myWinH == WinH && zoom == 1.0 )
+ return;
+
+ myGridWidth = myGridWidth + ( WinW - myWinW ) * myXScale;
+ myGridHeight = myGridHeight + ( WinH - myWinH ) * myYScale;
+ myWinW = WinW;
+ myWinH = WinH;
+ setZoom( zoom );
+ myIsUpdate = GL_TRUE;
+}
+
+void GLViewer_Grid::getSize( float& xSize, float& ySize ) const
+{
+ xSize = myXSize;
+ ySize = myYSize;
+}
+
+void GLViewer_Grid::getPan( float& xPan, float& yPan ) const
+{
+ xPan = myXPan;
+ yPan = myYPan;
+}
+
+void GLViewer_Grid::getScale( float& xScale, float& yScale ) const
+{
+ xScale = myXScale;
+ yScale = myYScale;
+}
+
+bool GLViewer_Grid::initList()
+{
+ myIsUpdate = GL_FALSE;
+
+ if( myXSize == (GLfloat)0.0 )
+ myXSize = (GLfloat)0.1;
+ if( myYSize == (GLfloat)0.0 )
+ myYSize = (GLfloat)0.1;
+
+label:
+ if( ( myXSize >= myGridWidth/5 ) && ( myYSize >= myGridHeight/5 ) )
+ { //zoom in
+ myXSize /= myScaleFactor;
+ myYSize /= myScaleFactor;
+ goto label;
+ }
+ else if( ( myXSize * myScaleFactor < myGridWidth/5 )
+ || ( myYSize * myScaleFactor < myGridHeight/5 ) )
+ { //zoom out
+ myXSize *= myScaleFactor;
+ myYSize *= myScaleFactor;
+ goto label;
+ }
+
+ //int n = myGridWidth / myXSize;
+ //int m = myGridHeight / myYSize;
+ // do not initialise integer by float
+ //if( ( n != 0 ) || ( m != 0 ) )
+ if( ( myGridWidth > 0.5 * myXSize ) || ( myGridHeight > 0.5 * myYSize ) )
+ {
+ if ( myGridList != 0 )
+ {
+ glDeleteLists( myGridList, 1 );
+ if ( glGetError() != GL_NO_ERROR )
+ return FALSE;
+ }
+
+ float xLoc = (int)(myXPan / myXSize) * myXSize;
+ float yLoc = (int)(myYPan / myYSize) * myYSize;
+
+ myGridList = glGenLists( 1 );
+ glNewList( myGridList, GL_COMPILE );
+
+ glColor3f( myGridColor[0], myGridColor[1], myGridColor[2] );
+ glLineWidth( myLineWidth );
+
+ glBegin( GL_LINES );
+ for( int j = 0; ( j-1 ) * myXSize <= myGridWidth / 2 ; j++ )
+ {
+ glVertex2d( -myXSize * j - xLoc, -myGridHeight / 2 - myYSize - yLoc );
+ glVertex2d( -myXSize * j - xLoc, myGridHeight / 2 + myYSize - yLoc );
+ glVertex2d( myXSize * j - xLoc, -myGridHeight / 2 - myYSize - yLoc );
+ glVertex2d( myXSize * j - xLoc, myGridHeight / 2 + myYSize - yLoc );
+ }
+ for( int i = 0; ( i-1 ) * myYSize <= myGridHeight / 2 ; i++)
+ {
+ glVertex2d( -myGridWidth / 2 - myXSize - xLoc, -myYSize * i - yLoc );
+ glVertex2d( myGridWidth / 2 + myXSize - xLoc, -myYSize * i - yLoc );
+ glVertex2d( -myGridWidth / 2 - myXSize - xLoc, myYSize * i - yLoc );
+ glVertex2d( myGridWidth / 2 + myXSize - xLoc, myYSize * i - yLoc );
+ }
+ glEnd();
+
+ glColor3f( myAxisColor[0], myAxisColor[1], myAxisColor[2] );
+ glLineWidth( myCenterWidth );
+
+ glBegin( GL_LINES );
+ glVertex2d( myGridWidth / 2 + myXSize - xLoc, 0);
+ glVertex2d( -myGridWidth / 2 - myXSize - xLoc, 0);
+ glVertex2d( 0, myGridHeight / 2 + myYSize - yLoc );
+ glVertex2d( 0, -myGridHeight / 2 - myYSize - yLoc );
+ glEnd();
+
+ glBegin( GL_LINE_LOOP );
+ double angle = 0.0;
+ for ( int k = 0; k < SEGMENTS; k++ )
+ {
+ glVertex2f( cos(angle) * myCenterRadius * myXScale,
+ sin(angle) * myCenterRadius * myYScale );
+ angle += STEP;
+ }
+ glEnd();
+
+ glEndList();
+ }
+ return TRUE;
+}
--- /dev/null
+// File: GLViewer_Grid.h
+// Created: November, 2004
+// Author: OCC team
+// Copyright (C) CEA 2004
+
+#ifndef GLVIEWER_GRID_H
+#define GLVIEWER_GRID_H
+
+#ifdef WNT
+#include "windows.h"
+#endif
+
+#include "GLViewer.h"
+
+#include <GL/gl.h>
+#include <GL/glu.h>
+
+#ifdef WNT
+#pragma warning( disable:4251 )
+#endif
+
+class GLVIEWER_API GLViewer_Grid
+{
+public:
+ GLViewer_Grid();
+ GLViewer_Grid( float, float, float, float, float, float, float, float, float, float );
+ ~GLViewer_Grid();
+
+ void draw();
+
+ void setGridColor( GLfloat, GLfloat, GLfloat );
+ void setAxisColor( GLfloat, GLfloat, GLfloat );
+ void setGridWidth( float );
+ void setCenterRadius( int );
+
+ void setSize( float, float );
+ void setPan( float, float );
+ bool setZoom( float );
+ void setResize( float, float, float );
+
+ void getSize( float&, float& ) const;
+ void getPan( float&, float& ) const;
+ void getScale( float&, float& ) const;
+
+ void setScaleFactor( int );
+ int getScaleFactor();
+
+protected:
+ bool initList();
+
+ GLuint myGridList;
+ GLfloat myGridColor[3];
+ GLfloat myAxisColor[3];
+ GLfloat myGridHeight;
+ GLfloat myGridWidth;
+ GLfloat myWinW;
+ GLfloat myWinH;
+ GLfloat myXSize;
+ GLfloat myYSize;
+ GLfloat myXPan;
+ GLfloat myYPan;
+ GLfloat myXScale;
+ GLfloat myYScale;
+ GLfloat myLineWidth;
+ GLfloat myCenterWidth;
+ GLint myCenterRadius;
+ GLint myScaleFactor;
+ GLboolean myIsUpdate;
+};
+
+#ifdef WNT
+#pragma warning ( default:4251 )
+#endif
+
+#endif
// Created: March, 2005
// Author: OCC team
// Copyright (C) CEA 2005
+
//#include "GLViewerAfx.h"
#include "GLViewer_Group.h"
#include "GLViewer_Object.h"
//Function: dragingObjects
//Description:
//--------------------------------------------------------------------------
-void GLViewer_Group::dragingObjects( float x, float y )
+void GLViewer_Group::dragingObjects( float x, float y, bool once )
{
- if( !mySelObjNum )
+ if( !once )
{
- OGIterator it = myList.begin();
- OGIterator end_it = myList.end();
- for( int i = 0; it != end_it; ++it, i++ )
- if( (*it)->isSelected() )
- mySelObjNum++;
+ if( !mySelObjNum )
+ {
+ OGIterator it = myList.begin();
+ OGIterator end_it = myList.end();
+ for( int i = 0; it != end_it; ++it, i++ )
+ if( (*it)->isSelected() )
+ mySelObjNum++;
- if( mySelObjNum )
+ if( mySelObjNum )
+ mySelObjNum--;
+ }
+ else
+ {
mySelObjNum--;
- }
- else
- {
- mySelObjNum--;
- return;
+ return;
+ }
}
OGIterator it = myList.begin();
{
GLViewer_Object* anObject = *it;
if( anObject != sender )
- anObject->setZoom( zoom, GL_TRUE );
+ anObject->setZoom( zoom, true, true );
}
}
** Created: UI team, 25.03.05
****************************************************************************/
-class GLVIEWER_EXPORT GLViewer_Group
+class GLVIEWER_API GLViewer_Group
{
public:
GLViewer_Group();
int addObject( GLViewer_Object* );
int removeObject( GLViewer_Object* );
+ OGList getObjects() const { return myList; }
//operations
- void dragingObjects( float x, float y );
+ void dragingObjects( float x, float y, bool once = false );
void updateZoom( GLViewer_Object* sender, float zoom );
private:
--- /dev/null
+/***************************************************************************
+** Class: GLViewer_MimeSource
+** Descr: Needs for a work with QClipboard
+** Module: GLViewer
+** Created: UI team, 22.03.04
+****************************************************************************/
+
+//#include <GLViewerAfx.h>
+#include "GLViewer_MimeSource.h"
+#include "GLViewer_BaseObjects.h"
+
+//#include <cmath>
+//using namespace std;
+
+GLViewer_MimeSource::~GLViewer_MimeSource()
+{
+}
+
+bool GLViewer_MimeSource::setObjects( QValueList<GLViewer_Object*> theObjects )
+{
+ if( !theObjects.empty() )
+ {
+ QStringList aObjectsType;
+ QValueList<QByteArray> aObjects;
+ QValueList<GLViewer_Object*>::const_iterator anIt = theObjects.begin();
+ QValueList<GLViewer_Object*>::const_iterator anEndIt = theObjects.end();
+
+ int aObjByteSize = 0;
+ for( ; anIt != anEndIt; anIt++ )
+ {
+ aObjects.append( (*anIt)->getByteCopy() );
+ aObjByteSize += aObjects.last().size();
+ aObjectsType.append( (*anIt)->getObjectType() );
+ }
+
+ int anISize = sizeof( int );
+ QString aTypes = aObjectsType.join("");
+ int aStrByteSize = aTypes.length();
+ int aObjNum = aObjects.count();
+
+ myByteArray = QByteArray( anISize * (1 + 2*aObjNum) + aStrByteSize + aObjByteSize );
+
+ int anIndex = 0, j = 0;
+ char* aPointer = (char*)&aObjNum;
+ for( anIndex = 0; anIndex < anISize; anIndex++, aPointer++ )
+ myByteArray[anIndex] = *aPointer;
+
+ QStringList::const_iterator aStrIt = aObjectsType.begin();
+ QStringList::const_iterator aEndStrIt = aObjectsType.end();
+ for( j = 1; aStrIt != aEndStrIt; aStrIt++, j++ )
+ {
+ int aStrLen = (*aStrIt).length();
+ aPointer = (char*)&aStrLen;
+ for( ; anIndex < anISize*( 1 + j ); anIndex++, aPointer++ )
+ myByteArray[anIndex] = *aPointer;
+ }
+
+ int aCurIndex = anIndex;
+ const char* aStr = aTypes.data();
+
+ for( j = 0 ; anIndex < aCurIndex + aStrByteSize; aPointer++, anIndex++, j++ )
+ myByteArray[anIndex] = aStr[j];
+
+ aCurIndex = anIndex;
+ QValueList<QByteArray>::iterator anObjIt = aObjects.begin();
+ QValueList<QByteArray>::iterator anEndObjIt = aObjects.end();
+ for( j = 1; anObjIt != anEndObjIt; anObjIt++, j++ )
+ {
+ int aObjLen = (int)((*anObjIt).size());
+ aPointer = (char*)&aObjLen;
+ for( ; anIndex < aCurIndex + anISize*j; anIndex++, aPointer++ )
+ myByteArray[anIndex] = *aPointer;
+ }
+
+ aCurIndex = anIndex;
+ anObjIt = aObjects.begin();
+
+ for( ; anObjIt != anEndObjIt; anObjIt++ )
+ {
+ int aObjLen = (int)((*anObjIt).size());
+ for( j = 0 ; anIndex < aCurIndex + aObjLen; anIndex++, aPointer++, j++ )
+ myByteArray[anIndex] = (*anObjIt)[j];
+ aCurIndex = anIndex;
+ }
+
+ return true;
+ }
+
+ return false;
+}
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!NOTE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+//If you want to use new class, following two method must be redefined
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!NOTE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+GLViewer_Object* GLViewer_MimeSource::getObject( QByteArray theArray, QString theType )
+{
+ if( !theArray.isEmpty() )
+ {
+ if( theType == "GLViewer_MarkerSet" )
+ {
+ GLViewer_MarkerSet* aObject = new GLViewer_MarkerSet( 0, (float)0.0, 0 );
+ if( aObject->initializeFromByteCopy( theArray ) )
+ return aObject;
+ }
+ else if ( theType == "GLViewer_Polyline" )
+ {
+ GLViewer_Polyline* aObject = new GLViewer_Polyline( 0, (float)0.0, 0 );
+ if( aObject->initializeFromByteCopy( theArray ) )
+ return aObject;
+ }
+ else if( theType == "GLViewer_TextObject" )
+ {
+ GLViewer_TextObject* aObject = new GLViewer_TextObject( 0, 0, 0, QColor(255,255,255), 0 );
+ if( aObject->initializeFromByteCopy( theArray ) )
+ return aObject;
+ }
+ }
+
+ return NULL;
+}
+
+QValueList<GLViewer_Object*> GLViewer_MimeSource::getObjects( QByteArray theArray, QString theType )
+{
+ if( !theArray.isEmpty() )
+ {
+ int anISize = sizeof( int );
+ if( theType == "GLViewer_Objects" )
+ {
+ QStringList aTypeList;
+ QValueList<QByteArray> aObjects;
+ QValueList<GLViewer_Object*> aObjectList;
+
+ QValueList<int> aTypeSizeList;
+ QValueList<int> aObjSizeList;
+ int aObjNum = 0;
+ char* aPointer = (char*)&aObjNum;
+
+ int anIndex = 0, j = 0;
+ for( anIndex = 0; anIndex < anISize; anIndex++, aPointer++ )
+ *aPointer = theArray[anIndex];
+
+ for( j = 0; j < aObjNum; j++ )
+ {
+ int aTempVal = 0;
+ aPointer = (char*)&aTempVal;
+ for( ; anIndex < anISize*(j+2); anIndex++, aPointer++ )
+ *aPointer = theArray[anIndex];
+ aTypeSizeList.append( aTempVal );
+ }
+
+ int aCurIndex = anIndex;
+ for( j = 0; j < aObjNum; j++ )
+ {
+ QString aTempStr;
+ for( ; anIndex < aCurIndex + aTypeSizeList[j]; anIndex++ )
+ {
+ char aLetter = theArray[anIndex];
+ aTempStr.append( aLetter );
+ }
+ aTypeList.append( aTempStr );
+ aCurIndex = anIndex;
+ }
+
+ for( j = 0; j < aObjNum; j++ )
+ {
+ int aTempVal = 0;
+ aPointer = (char*)&aTempVal;
+ for( ; anIndex < aCurIndex + anISize*(j+1); anIndex++, aPointer++ )
+ *aPointer = theArray[anIndex];
+ aObjSizeList.append( aTempVal );
+ }
+
+ aCurIndex = anIndex;
+ for( j = 0; j < aObjNum; j++ )
+ {
+ QByteArray aTempArray(aObjSizeList[j]);
+ for( ; anIndex < aCurIndex + aObjSizeList[j]; anIndex++ )
+ aTempArray[anIndex-aCurIndex] = theArray[anIndex];
+ aObjects.append( aTempArray );
+ aCurIndex = anIndex;
+ }
+
+ for( j = 0; j < aObjNum; j++ )
+ aObjectList.append( getObject( aObjects[j], aTypeList[j] ) );
+
+ return aObjectList;
+ }
+ }
+
+ return QValueList<GLViewer_Object*>();
+}
+
+const char* GLViewer_MimeSource::format( int theIndex ) const
+{
+ switch( theIndex )
+ {
+ case 0: return "GLViewer_Objects";
+ //case 1: return "GLViewer_MarkerSet";
+ //case 2: return "GLViewer_Polyline";
+ //case 3: return "GLViewer_TextObject";
+ default: return 0;
+ }
+
+}
+
+QByteArray GLViewer_MimeSource::encodedData( const char* theObjectType ) const
+{
+ if( theObjectType == "GLViewer_Objects" )
+ return myByteArray;
+
+ return QByteArray();
+}
--- /dev/null
+// File: GLViewer_MimeSource.h
+// Created: November, 2004
+// Author: OCC team
+// Copyright (C) CEA 2004
+
+#ifndef GLVIEWER_MIMESOURCE_H
+#define GLVIEWER_MIMESOURCE_H
+
+#ifdef WNT
+#include <windows.h>
+#endif
+
+#include "GLViewer.h"
+
+#include <qmime.h>
+#include <qvaluelist.h>
+
+#ifdef WNT
+#pragma warning( disable:4251 )
+#endif
+
+class GLViewer_Object;
+
+// Class: GLViewer_MimeSource
+// Descr: Needs for a work with QClipboard
+
+class GLVIEWER_API GLViewer_MimeSource: public QMimeSource
+{
+public:
+ GLViewer_MimeSource():QMimeSource(){};
+ ~GLViewer_MimeSource();
+
+ bool setObjects( QValueList<GLViewer_Object*> );
+ static QValueList<GLViewer_Object*> getObjects( QByteArray, QString );
+ static GLViewer_Object* getObject( QByteArray, QString );
+
+ virtual const char* format( int theIndex = 0 ) const;
+ virtual QByteArray encodedData( const char* ) const;
+
+private:
+ QByteArray myByteArray;
+};
+
+#ifdef WNT
+#pragma warning ( default:4251 )
+#endif
+
+#endif
-// File: GLViewer_Object.cxx
-// Created: November, 2004
-// Author: OCC team
-// Copyright (C) CEA 2004
-
/***************************************************************************
** Class: GLViewer_Object
** Descr: OpenGL Object
** Module: GLViewer
-** Created: UI team, 02.09.02
+** Created: UI team, 03.09.02
****************************************************************************/
+//#include <GLViewerAfx.h>
#include "GLViewer_Object.h"
#include "GLViewer_Drawer.h"
-
+#include "GLViewer_AspectLine.h"
+#include "GLViewer_Geom.h"
+#include "GLViewer_Text.h"
#include "GLViewer_Group.h"
-#include <qfontmetrics.h>
-#include <qstringlist.h>
-
-#include <cmath>
-using namespace std;
-
-#define CONSTANT_FOR_RECT 10
-
-/***************************************************************************
-** Class: GLViewer_Text
-** Descr: Substitution of Prs3d_Text for OpenGL
-** Module: GLViewer
-** Created: UI team, 10.07.03
-****************************************************************************/
-
-GLViewer_Text::GLViewer_Text( const QString& text, float xPos, float yPos, const QColor& color )
-{
- myText = text;
- myXPos = xPos;
- myYPos = yPos;
- myColor = color;
- myQFont = QFont::defaultFont();
- mySeparator = 2;
- myDTF = DTF_BITMAP;
-}
-
-GLViewer_Text::GLViewer_Text( const QString& text, float xPos, float yPos, const QColor& color, QFont theFont, int theSeparator )
-{
- myText = text;
- myXPos = xPos;
- myYPos = yPos;
- myColor = color;
- myQFont = theFont;
- mySeparator = theSeparator;
- myDTF = DTF_BITMAP;
-}
-
-GLViewer_Text::~GLViewer_Text()
-{
-}
-
-int GLViewer_Text::getWidth()
-{
- int aResult = 0;
- QFontMetrics aFM( myQFont );
- for( int i = 0; i < myText.length(); i++ )
- aResult += aFM.width( myText[i] ) + mySeparator;
- return aResult;
-}
-
-int GLViewer_Text::getHeight()
-{
- QFontMetrics aFM( myQFont );
- return aFM.height();
-}
-
-QByteArray GLViewer_Text::getByteCopy() const
-{
- int i;
- int aSize = 5*sizeof( int ) + myText.length();
-
- int aR = myColor.red();
- int aG = myColor.green();
- int aB = myColor.blue();
- const char* aStr = myText.data();
-
- int anISize = sizeof( int );
- QByteArray aResult( aSize );
-
- char* aPointer = (char*)&myXPos;
- for( i = 0; i < anISize; i++, aPointer++ )
- aResult[i] = *aPointer;
- aPointer = (char*)&myYPos;
- for( ; i < 2*anISize; i++, aPointer++ )
- aResult[i] = *aPointer;
-
- aPointer = (char*)&aR;
- for( ; i < 3*anISize; i++, aPointer++ )
- aResult[i] = *aPointer;
- aPointer = (char*)&aG;
- for( ; i < 4*anISize; i++, aPointer++ )
- aResult[i] = *aPointer;
- aPointer = (char*)&aB;
- for( ; i < 5*anISize; i++, aPointer++ )
- aResult[i] = *aPointer;
-
- int aTextSize = myText.length();
- aPointer = (char*)&aTextSize;
- for( ; i < 6*anISize; i++, aPointer++ )
- aResult[i] = *aPointer;
-
- for( i = 0; i < aTextSize; i++ )
- aResult[6*anISize + i] = aStr[i];
-
- aPointer = (char*)&mySeparator;
- for( ; i < 7*anISize + aTextSize; i++, aPointer++ )
- aResult[i] = *aPointer;
-
- const char* aFontStr = myQFont.toString().data();
- int aFontSize = myQFont.toString().length();
-
- for( i = 0; i < aFontSize; i++ )
- aResult[7*anISize + aTextSize + i] = aFontStr[i];
-
- return aResult;
-}
-
-GLViewer_Text* GLViewer_Text::fromByteCopy( QByteArray theBuf )
-{
- int i = 0;
- int aSize = (int)theBuf.size();
- int aR = 0, aG = 0, aB = 0;
-
- int xPos = 0, yPos = 0;
-
- int anISize = sizeof( int );
- char* aPointer = (char*)&xPos;
- for ( i = 0; i < anISize; i++, aPointer++ )
- *aPointer = theBuf[i];
-
- aPointer = (char*)&yPos;
- for ( ; i < 2*anISize; i++, aPointer++ )
- *aPointer = theBuf[i];
-
- aPointer = (char*)&aR;
- for( ; i < 3*anISize; i++, aPointer++ )
- *aPointer = theBuf[i];
- aPointer = (char*)&aG;
- for( ; i < 4*anISize; i++, aPointer++ )
- *aPointer = theBuf[i];
- aPointer = (char*)&aB;
- for( ; i < 5*anISize; i++, aPointer++ )
- *aPointer = theBuf[i];
-
- int aTextSize = 0;
- aPointer = (char*)&aTextSize;
- for( ; i < 6*anISize; i++, aPointer++ )
- *aPointer = theBuf[i];
-
- QString aText;
- for( ; i < 6*anISize + aTextSize; i++ )
- {
- QChar aChar( theBuf[i] );
- aText += aChar;
- }
-
- int aSeparator = 0;
- aPointer = (char*)&aSeparator;
- for( ; i < 7*anISize + aTextSize; i++, aPointer++ )
- *aPointer = theBuf[i];
-
- QString aFontStr;
- for( ; i < aSize; i++ )
- {
- QChar aChar( theBuf[i] );
- aFontStr += aChar;
- }
- QFont aFont;
-
- if( !aFont.fromString( aFontStr ) )
- return NULL;
-
- GLViewer_Text* aGlText = new GLViewer_Text( aText, xPos, yPos, QColor( aR,aG,aB ), aFont, aSeparator );
+//#include <cmath>
+//using namespace std;
- return aGlText;
-}
-
-/***************************************************************************
-** Class: GLViewer_CoordSystem
-** Descr:
-** Module: GLViewer
-** Created: UI team, 03.09.02
-****************************************************************************/
-
-GLViewer_CoordSystem::GLViewer_CoordSystem( CSType aType, double X0, double Y0,
- double XUnit, double YUnit, double Rotation )
-{
- setType( aType );
- setOrigin( X0, Y0 );
- setUnits( XUnit, YUnit );
- setRotation( Rotation );
-}
-
-void GLViewer_CoordSystem::getOrigin( double& x, double& y ) const
-{
- x = myX0;
- y = myY0;
-}
-
-void GLViewer_CoordSystem::setOrigin( double x, double y )
-{
- myX0 = x;
- myY0 = y;
-}
-
-void GLViewer_CoordSystem::getUnits( double& x, double& y ) const
-{
- x = myXUnit;
- y = myYUnit;
-}
-
-void GLViewer_CoordSystem::setUnits( double x, double y )
-{
- if( x>0 )
- myXUnit = x;
- else
- myXUnit = 1.0;
-
- if( y>0 )
- myYUnit = y;
- else
- myYUnit = 1.0;
-}
-
-double GLViewer_CoordSystem::getRotation() const
-{
- return myRotation;
-}
-
-void GLViewer_CoordSystem::setRotation( double rotation )
-{
- myRotation = rotation;
-}
-
-GLViewer_CoordSystem::CSType GLViewer_CoordSystem::getType() const
-{
- return myType;
-}
-
-void GLViewer_CoordSystem::setType( CSType type )
-{
- myType = type;
-}
-
-void GLViewer_CoordSystem::toReference( double& x, double& y )
-{
- if( myType==Cartesian )
- {
- double newx = myX0 + myXUnit*x*cos(myRotation) - myYUnit*y*sin(myRotation),
- newy = myY0 + myXUnit*x*sin(myRotation) + myYUnit*y*cos(myRotation);
- x = newx;
- y = newy;
- }
- else if( myType==Polar )
- {
- double r = x, phi = y;
- x = myX0 + myXUnit*r*cos(phi+myRotation);
- y = myY0 + myXUnit*r*sin(phi+myRotation);
- }
-}
-
-void GLViewer_CoordSystem::fromReference( double& x, double& y )
-{
- x = (x - myX0) / myXUnit;
- y = (y - myY0) / myYUnit;
-
- if( myType==Cartesian )
- {
- double newx = x*cos(myRotation) + y*sin(myRotation),
- newy = -x*sin(myRotation) + y*cos(myRotation);
- x = newx;
- y = newy;
- }
- else if( myType==Polar )
- {
- double r = sqrt( x*x+y*y );
- double phi = 0.0;
- double eps = 1E-8, pi = 3.14159265;
-
- if( r>eps )
- if( fabs(x)>eps )
- {
- double arg = y/x;
- phi = atan(arg);
- if( x<0 ) // 2-nd or 4-rd quarter
- phi+=pi;
- }
- else if( y>0 )
- phi = pi/2.0;
- else
- phi = 3*pi/2.0;
-
- x = r;
- y = phi-myRotation;
- }
-}
-
-void GLViewer_CoordSystem::transform( GLViewer_CoordSystem& aSystem, double& x, double& y )
-{
- toReference( x, y );
- aSystem.fromReference( x, y );
-}
-
-void GLViewer_CoordSystem::getStretching( GLViewer_CoordSystem& aSystem, double& theX, double& theY )
-{
- theX = myXUnit / aSystem.myXUnit;
- theY = myYUnit / aSystem.myYUnit;
-}
-
-/***************************************************************************
-** Class: GLViewer_Object
-** Descr: OpenGL Object
-** Module: GLViewer
-** Created: UI team, 03.09.02
-****************************************************************************/
GLViewer_Object::GLViewer_Object()
{
myXScale = 1.0;
myIsHigh = GL_FALSE;
myIsSel = GL_FALSE;
- myRect = new GLViewer_Rect();
+ myRect = new GLViewer_Rect();;
+ myUpdateRect = new GLViewer_Rect();;
myGLText = new GLViewer_Text( 0, 0, 0, QColor(0,0,0) );
myAspectLine = new GLViewer_AspectLine();
myType = "GLViewer_Object";
- setOwner( NULL );
- setDrawer( NULL );
+ myOwner = NULL;
+ myDrawer = NULL;
myIsVisible = true;
if( myRect )
delete myRect;
+ if( myUpdateRect )
+ delete myUpdateRect;
+
if( myGLText )
delete myGLText;
delete myAspectLine;
}
+int GLViewer_Object::getPriority() const
+{
+ return myDrawer ? myDrawer->getPriority() : 0;
+}
+
GLboolean GLViewer_Object::isInside( GLViewer_Rect theRect )
{
- return theRect.toQRect()->contains( *(myRect->toQRect()) );
+ return theRect.toQRect().contains( myRect->toQRect() );
}
-GLboolean GLViewer_Object::setZoom( GLfloat zoom, GLboolean )
+GLboolean GLViewer_Object::setZoom( GLfloat zoom, bool, bool )
{
if( myZoom == zoom )
return GL_FALSE;
if( newZoom < 0.01 || newZoom > 100.0 )
return GL_FALSE;
- setZoom( newZoom, GL_TRUE );
- return GL_TRUE;
+ return setZoom( newZoom, true );
}
QByteArray GLViewer_Object::getByteCopy()
{
int i = 0;
int anISize = sizeof( int );
- int aFSize = sizeof( GLfloat );
-
- int aLeft = (int)myRect->left(),
- aTop = (int)myRect->top(),
- aRight = (int)myRect->right(),
- aBottom = (int)myRect->bottom();
const char* aTypeStr = myType.data();
const char* aToolTipStr = myToolTipText.data();
QByteArray aGLText = myGLText->getByteCopy();
QByteArray aAspect = myAspectLine->getByteCopy();
- QByteArray aResult( 2*anISize + 8*aFSize +
- aTypeLength + aToolTipLength +
- aGLText.size() + aAspect.size() );
+ float aRectData[8];
+ aRectData[ 0 ] = myRect->left();
+ aRectData[ 1 ] = myRect->top();
+ aRectData[ 2 ] = myRect->right();
+ aRectData[ 3 ] = myRect->bottom();
+ aRectData[ 4 ] = myXScale;
+ aRectData[ 5 ] = myYScale;
+ aRectData[ 6 ] = myXGap;
+ aRectData[ 7 ] = myYGap;
- char* aPointer = (char*)&aLeft;
- for( i = 0; i < aFSize; i++, aPointer++ )
- aResult[i] = *aPointer;
- aPointer = (char*)&aTop;
- for( ; i < 2*aFSize; i++, aPointer++ )
- aResult[i] = *aPointer;
- aPointer = (char*)&aRight;
- for( ; i < 3*aFSize; i++, aPointer++ )
- aResult[i] = *aPointer;
- aPointer = (char*)&aBottom;
- for( ; i < 4*aFSize; i++, aPointer++ )
- aResult[i] = *aPointer;
+ int sizeOf8Float = sizeof( aRectData );
- aPointer = (char*)&myXScale;
- for( ; i < 5*aFSize; i++, aPointer++ )
- aResult[i] = *aPointer;
- aPointer = (char*)&myYScale;
- for( ; i < 6*aFSize; i++, aPointer++ )
- aResult[i] = *aPointer;
- aPointer = (char*)&myXGap;
- for( ; i < 7*aFSize; i++, aPointer++ )
- aResult[i] = *aPointer;
- aPointer = (char*)&myYGap;
- for( ; i < 8*aFSize; i++, aPointer++ )
+ QByteArray aResult( 2*anISize + sizeOf8Float +
+ aTypeLength + aToolTipLength +
+ aGLText.size() + aAspect.size() );
+ // puts 8 float values into the byte array
+ char* aPointer = (char*)&aRectData;
+ for( i = 0; i < sizeOf8Float; i++, aPointer++ )
aResult[i] = *aPointer;
-
+ // puts length of type string
aPointer = (char*)&aTypeLength;
- for( ; i < anISize + 8*aFSize; i++, aPointer++ )
+ for( ; i < anISize + sizeOf8Float; i++, aPointer++ )
aResult[i] = *aPointer;
- for( ; i < anISize + 8*aFSize + aTypeLength; i++ )
- aResult[i] = aTypeStr[i - anISize - 8*aFSize ];
-
+ // puts type string
+ for( ; i < anISize + sizeOf8Float + aTypeLength; i++ )
+ aResult[i] = aTypeStr[i - anISize - sizeOf8Float ];
+ // puts length of tooltiptext string
aPointer = (char*)&aToolTipLength;
- for( ; i < 2*anISize + 8*aFSize + aTypeLength; i++, aPointer++ )
+ for( ; i < 2*anISize + sizeOf8Float + aTypeLength; i++, aPointer++ )
aResult[i] = *aPointer;
- for( ; i < 2*anISize + 8*aFSize + aTypeLength + aToolTipLength; i++ )
- aResult[ i] = aToolTipStr[i - 2*anISize - 8*aFSize - aTypeLength];
-
- int aCurPos = 2*anISize + 8*aFSize + aTypeLength + aToolTipLength;
+ // puts tooltiptext string
+ for( ; i < 2*anISize + sizeOf8Float + aTypeLength + aToolTipLength; i++ )
+ aResult[ i] = aToolTipStr[i - 2*anISize - sizeOf8Float - aTypeLength];
+ int aCurPos = 2*anISize + sizeOf8Float + aTypeLength + aToolTipLength;
+ // adds aspect byte array
for( i = aCurPos; i < aCurPos + aAspect.size(); i++ )
aResult[i] = aAspect[i - aCurPos];
aCurPos = aCurPos + aAspect.size();
-
+ // adds GL text byte array
for( i = aCurPos; i < aCurPos + aGLText.size(); i++ )
aResult[i] = aGLText[i - aCurPos];
aCurPos += aGLText.size();
-
aPointer = (char*)&myOwner;
for( i = 0; i < sizeof( GLViewer_Owner* ); i++, aPointer++ )
- aResult[ aCurPos+i ] = *aPointer;
+ aResult[ aCurPos + i ] = *aPointer;
return aResult;
}
int anISize = sizeof( int );
int aFSize = sizeof( GLfloat );
- int aLeft = 0, aTop = 0, aRight = 0, aBottom = 0;
+ float aLeft = 0, aTop = 0, aRight = 0, aBottom = 0;
//QString aTypeStr, aToolTipStr;
int aTypeLength = 0, aToolTipLength = 0;
delete myGLText;
myGLText = GLViewer_Text::fromByteCopy( aGLTextArray );
-
- /*aCurPos += aSize - aCurPos;
- aPointer = (char*)&myOwner;
- for( i = 0; i < sizeof( GLViewer_Owner* ); i++, aPointer++ )
- *aPointer = theArray[ aCurPos + i ];*/
-
return true;
}
{
return myGroup;
}
-
-GLViewer_Owner* GLViewer_Object::owner() const
-{
- return myOwner;
-}
-
-void GLViewer_Object::setOwner( GLViewer_Owner* owner )
-{
- myOwner = owner;
-}
-
-
-/***************************************************************************
-** Class: GLViewer_MarkerSet
-** Descr: OpenGL MarkerSet
-** Module: GLViewer
-** Created: UI team, 03.09.02
-****************************************************************************/
-
-GLViewer_MarkerSet::GLViewer_MarkerSet( int number, float size, const QString& toolTip ) :
- GLViewer_Object(), myNumber( 0 ), myXCoord( 0 ), myYCoord( 0 )
-{
- myMarkerSize = size;
- myHNumbers.clear();
- myUHNumbers.clear();
- mySelNumbers.clear();
- myUSelNumbers.clear();
- myCurSelNumbers.clear();
- myPrevHNumbers.clear();
-
- myType = "GLViewer_MarkerSet";
- myToolTipText = toolTip;
-
- setNumMarkers( number );
-}
-
-GLViewer_MarkerSet::~GLViewer_MarkerSet()
-{
- delete myRect;
-
- if ( myXCoord )
- delete[] myXCoord;
- if ( myYCoord )
- delete[] myYCoord;
-
- delete myAspectLine;
-}
-
-void AddCoordsToHPGL( QString& buffer, QString command, GLViewer_CoordSystem* aViewerCS,
- GLViewer_CoordSystem* aPaperCS, double x, double y, bool NewLine = true )
-{
- if( aViewerCS && aPaperCS )
- aViewerCS->transform( *aPaperCS, x, y );
-
- QString temp = command + "%1, %2;";
- buffer += temp.arg( x ).arg( y );
- if( NewLine )
- buffer += ";\n";
-}
-
-void AddCoordsToPS( QString& buffer, QString command, GLViewer_CoordSystem* aViewerCS,
- GLViewer_CoordSystem* aPaperCS, double x, double y, bool NewLine = true )
-{
- if( aViewerCS && aPaperCS )
- aViewerCS->transform( *aPaperCS, x, y );
-
- QString temp = "%1 %2 "+command;
- buffer += temp.arg( x ).arg( y );
- if( NewLine )
- buffer += "\n";
-}
-
-void AddLineAspectToPS( QString& buffer, GLViewer_AspectLine* anAspect,
- GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPaperCS )
-{
- if( anAspect )
- {
- QColor col1, col2, col3;
- anAspect->getLineColors( col1, col2, col3 );
-
- float aWidth = anAspect->getLineWidth();
- int aLineType = anAspect->getLineType();
-
- QString temp = "%1 %2 %3 setrgbcolor\n";
- double rr = 1 - double( col1.red() ) / 255.0, //color inverting
- gg = 1 - double( col1.green() ) / 255.0,
- bb = 1 - double( col1.blue() ) / 255.0;
-
- buffer += temp.arg( rr ).arg( gg ).arg( bb );
-
- double x_stretch, y_stretch;
- aViewerCS->getStretching( *aPaperCS, x_stretch, y_stretch );
- buffer += temp.arg( x_stretch * aWidth )+" setlinewidth\n";
-
- if( aLineType==0 ) //solid
- buffer += "[] 0 setdash\n";
- else if( aLineType==1 ) //strip
- buffer += "[2] 0 setdash\n";
- }
-}
-
-#ifdef WIN32
-HPEN AddLineAspectToEMF( HDC hDC, GLViewer_AspectLine* anAspect,
- GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPaperCS )
-{
- if( anAspect )
- {
- QColor col1, col2, col3;
- anAspect->getLineColors( col1, col2, col3 );
-
- double x_stretch, y_stretch;
- aViewerCS->getStretching( *aPaperCS, x_stretch, y_stretch );
-
- double aWidth = anAspect->getLineWidth()*x_stretch;
- int aLineType = anAspect->getLineType();
-
- return CreatePen( PS_SOLID, aWidth, RGB( 255-col1.red(), 255-col1.green(), 255-col1.blue() ) );
- }
- else
- return NULL;
-}
-#endif
-
-bool GLViewer_MarkerSet::translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS )
-{
- int noPoints = 20;
-
- QString aBuffer = "newpath\n";
-
- AddLineAspectToPS( aBuffer, getAspectLine(), aViewerCS, aPSCS );
-
- for( int i=0; i<myNumber; i++ )
- {
- aBuffer += "\n";
-
- double x_stretch, y_stretch;
- aViewerCS->getStretching( *aPSCS, x_stretch, y_stretch );
-
- double x0 = myXCoord[i],
- y0 = myYCoord[i],
- r = myMarkerSize,
- x, y;
-
- for( int j=0; j<=noPoints; j++ )
- {
- x = x0 + r*cos( double(j)*2*PI/double(noPoints) );
- y = y0 + r*sin( double(j)*2*PI/double(noPoints) );
- if( j==0 )
- AddCoordsToPS( aBuffer, "moveto", aViewerCS, aPSCS, x, y, true );
- else
- AddCoordsToPS( aBuffer, "lineto", aViewerCS, aPSCS, x, y, true );
- }
- }
- aBuffer+="closepath\nstroke\n";
-
- hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
-
- return true;
-}
-
-bool GLViewer_MarkerSet::translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS,
- GLViewer_CoordSystem* aHPGLCS )
-{
- int noPoints = 20;
- QString aBuffer;
- for( int i=0; i<myNumber; i++ )
- {
- aBuffer = "";
-
- double x_stretch, y_stretch;
- aViewerCS->getStretching( *aHPGLCS, x_stretch, y_stretch );
-
- double x0 = myXCoord[i],
- y0 = myYCoord[i],
- r = myMarkerSize,
- x, y;
-
- AddCoordsToHPGL( aBuffer, "PA", aViewerCS, aHPGLCS, x0+r, y0 );
- aBuffer+="PD;\n";
- for( int j=1; j<=noPoints; j++ )
- {
- x = x0 + r*cos( double(j)*2*PI/double(noPoints) );
- y = y0 + r*sin( double(j)*2*PI/double(noPoints) );
- AddCoordsToHPGL( aBuffer, "PD", aViewerCS, aHPGLCS, x, y );
- }
- aBuffer+="PU;\n";
-
- hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
- }
-
- return true;
-}
-
-#ifdef WIN32
-bool GLViewer_MarkerSet::translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS )
-{
- int noPoints = 20;
- if( !aViewerCS || !aEMFCS )
- return false;
-
- HPEN pen = AddLineAspectToEMF( dc, getAspectLine(), aViewerCS, aEMFCS );
- HGDIOBJ old = SelectObject( dc, pen );
-
- for( int i=0; i<myNumber; i++ )
- {
- double x0 = myXCoord[i],
- y0 = myYCoord[i],
- r = myMarkerSize,
- x, y;
-
- for( int j=0; j<=noPoints; j++ )
- {
- x = x0 + r*cos( double(j)*2*PI/double(noPoints) );
- y = y0 + r*sin( double(j)*2*PI/double(noPoints) );
- aViewerCS->transform( *aEMFCS, x, y );
- if( j==0 )
- MoveToEx( dc, x, y, NULL );
- else
- LineTo( dc, x, y );
- }
- }
-
- SelectObject( dc, old );
- if( pen )
- DeleteObject( pen );
- return true;
-}
-#endif
-
-
-void GLViewer_MarkerSet::compute()
-{
-// cout << "GLViewer_MarkerSet::compute" << endl;
- GLfloat xa = myXCoord[0];
- GLfloat xb = myXCoord[0];
- GLfloat ya = myYCoord[0];
- GLfloat yb = myYCoord[0];
-
- for ( int i = 0; i < myNumber; i++ )
- {
- xa = QMIN( xa, myXCoord[i] );
- xb = QMAX( xb, myXCoord[i] );
- ya = QMIN( ya, myYCoord[i] );
- yb = QMAX( yb, myYCoord[i] );
- }
-
- myXGap = ( xb - xa ) / CONSTANT_FOR_RECT;
- myYGap = ( yb - ya ) / CONSTANT_FOR_RECT;
-
- myRect->setLeft( xa - myXGap );
- myRect->setTop( yb + myYGap );
- myRect->setRight( xb + myXGap );
- myRect->setBottom( ya - myYGap );
-}
-
-GLViewer_Drawer* GLViewer_MarkerSet::createDrawer()
-{
-// cout << "GLViewer_MarkerSet::createDrawer" << endl;
- return myDrawer = new GLViewer_MarkerDrawer();
-}
-
-
-GLboolean GLViewer_MarkerSet::highlight( GLfloat x, GLfloat y, GLfloat tol, GLboolean isCircle )
-{
- if( !myIsVisible )
- return false;
-// cout << "GLViewer_MarkerSet::highlight " << x <<" " << y << " " << tol << endl;
- int count = 0;
- GLfloat xdist, ydist, radius;
- QValueList<int>::Iterator it;
- QValueList<int> curHNumbers;
- bool isFound;
- GLboolean update;
- int cnt = 0;
-
- radius = tol - myMarkerSize / 2.;
-
- myUHNumbers += myHNumbers;
- myHNumbers.clear();
-
- for ( int i = 0; i < myNumber; i++ )
- {
- xdist = ( myXCoord[i] - x ) * myXScale;
- ydist = ( myYCoord[i] - y ) * myYScale;
-
-// if ( isCircle && ( xdist * xdist + ydist * ydist <= radius * radius ) ||
- if ( isCircle && ( xdist * xdist + ydist * ydist <= myMarkerSize * myMarkerSize ) ||
- !isCircle && ( abs( xdist ) <= radius && abs( ydist ) <= radius ) )
- {
- isFound = FALSE;
- count++;
- for ( it = myCurSelNumbers.begin(); it != myCurSelNumbers.end(); ++it )
- if( i == *it )
- {
- isFound = TRUE;
- curHNumbers.append( i );
- }
-
- if( !isFound )
- myHNumbers.append( i );
- else
- cnt++;
- }
- }
- myCurSelNumbers = curHNumbers;
-
- myIsHigh = ( GLboolean )count;
- update = ( GLboolean )( myHNumbers != myPrevHNumbers );
-
- myPrevHNumbers = myHNumbers;
-
- //cout << "GLViewer_MarkerSet::highlight complete with " << (int)myIsHigh << endl;
- return update;
-}
-
-GLboolean GLViewer_MarkerSet::unhighlight()
-{
- if( !myHNumbers.isEmpty() )
- {
- myUHNumbers += myHNumbers;
- myPrevHNumbers.clear();
- myHNumbers.clear();
- //??? myCurSelNumbers.clear();
- return GL_TRUE;
- }
-
- return GL_FALSE;
-}
-
-GLboolean GLViewer_MarkerSet::select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect, GLboolean isFull,
- GLboolean isCircle, GLboolean isShift )
-{
- if( !myIsVisible )
- return false;
-// cout << "GLViewer_MarkerSet::select " << x << " " << y << endl;
- int count = 0;
- GLfloat xdist, ydist, radius;
- QValueList<int>::Iterator it;
- QValueList<int>::Iterator it1;
- QValueList<int>::Iterator remIt;
- QValueList<int>::Iterator curIt;
-
- radius = tol - myMarkerSize / 2.;
-
- if( radius < myMarkerSize / 2.)
- radius = myMarkerSize / 2.;
-
- count = isShift ? mySelNumbers.count() : 0;
-
- myUSelNumbers = mySelNumbers;
-
- if ( !isShift )
- {
- mySelNumbers.clear();
- myCurSelNumbers.clear();
- }
-
- for ( int i = 0; i < myNumber; i++ )
- {
- xdist = ( myXCoord[i] - x ) * myXScale;
- ydist = ( myYCoord[i] - y ) * myYScale;
-
- //if ( isCircle && ( xdist * xdist + ydist * ydist <= radius * radius ) ||
- if ( isCircle && ( xdist * xdist + ydist * ydist <= myMarkerSize * myMarkerSize ) ||
- !isCircle && ( abs( xdist ) <= radius && abs( ydist ) <= radius ) )
- {
- count++;
- if ( isShift )
- {
- bool isFound = FALSE;
- for( it = mySelNumbers.begin(); it != mySelNumbers.end(); ++it )
- if ( *it == i )
- {
- myUSelNumbers.append( *it );
- remIt = it;
- isFound = TRUE;
- break;
- }
-
- if ( !isFound )
- {
- mySelNumbers.append( i );
- myCurSelNumbers.append( i );
- for ( it1 = myHNumbers.begin(); it1 != myHNumbers.end(); ++it1 )
- if( i == *it1 )
- {
- myHNumbers.remove( it1 );
- break;
- }
- for ( it1 = myUHNumbers.begin(); it1 != myUHNumbers.end(); ++it1 )
- if( i == *it1 )
- {
- myUHNumbers.remove( it1 );
- break;
- }
- }
- else
- {
- mySelNumbers.remove( remIt );
- for ( curIt = myCurSelNumbers.begin(); curIt != myCurSelNumbers.end(); ++curIt )
- if( *curIt == *remIt)
- {
- myCurSelNumbers.remove( curIt );
- break;
- }
- for ( it1 = myHNumbers.begin(); it1 != myHNumbers.end(); ++it1 )
- if( i == *it1 )
- {
- myHNumbers.remove( it1 );
- break;
- }
- for ( it1 = myUHNumbers.begin(); it1 != myUHNumbers.end(); ++it1 )
- if( i == *it1 )
- {
- myUHNumbers.remove( it1 );
- break;
- }
- }
- }
- else
- {
- mySelNumbers.append( i );
- myCurSelNumbers.append( i );
- for ( it1 = myHNumbers.begin(); it1 != myHNumbers.end(); ++it1 )
- if( i == *it1 )
- {
- myHNumbers.remove( it1 );
- break;
- }
- for ( it1 = myUHNumbers.begin(); it1 != myUHNumbers.end(); ++it1 )
- if( i == *it1 )
- {
- myUHNumbers.remove( it1 );
- break;
- }
- }
- }
- }
-
- for( it = mySelNumbers.begin(); it != mySelNumbers.end(); ++it )
- for( it1 = myUSelNumbers.begin(); it1 != myUSelNumbers.end(); ++it1 )
- if( *it == *it1 )
- {
- it1 = myUSelNumbers.remove( it1 );
- it1--;
- }
-
- myIsSel = (GLboolean)count;
-
-// cout << "GLViewer_MarkerSet::select complete with " << (int)myIsSel << endl;
- return myIsSel;
-}
-
-GLboolean GLViewer_MarkerSet::unselect()
-{
- if( !mySelNumbers.isEmpty() )
- {
- myUSelNumbers = mySelNumbers;
- mySelNumbers.clear();
- myCurSelNumbers.clear();
- return GL_TRUE;
- }
-
- return GL_FALSE;
-}
-
-GLViewer_Rect* GLViewer_MarkerSet::getUpdateRect()
-{
- GLViewer_Rect* rect = new GLViewer_Rect();
-
- rect->setLeft( myRect->left() + myXGap - myMarkerSize / myXScale );
- rect->setTop( myRect->top() + myYGap + myMarkerSize / myYScale );
- rect->setRight( myRect->right() - myXGap + myMarkerSize / myXScale );
- rect->setBottom( myRect->bottom() - myYGap - myMarkerSize / myYScale );
- //cout << " Additional tolerance " << myMarkerSize / myYScale << endl;
- //rect->setLeft( myRect->left() - myMarkerSize / myXScale );
- //rect->setTop( myRect->top() - myMarkerSize / myYScale );
- //rect->setRight( myRect->right() + myMarkerSize / myXScale );
- //rect->setBottom( myRect->bottom() + myMarkerSize / myYScale );
-
- return rect;
-}
-
-
-void GLViewer_MarkerSet::setXCoord( GLfloat* xCoord, int size )
-{
- myXCoord = new GLfloat[ size ];
- for( int i = 0; i < size; i++ )
- myXCoord[i] = xCoord[i];
-}
-
-void GLViewer_MarkerSet::setYCoord( GLfloat* yCoord, int size )
-{
- myYCoord = new GLfloat[ size ];
- for( int i = 0; i < size; i++ )
- myYCoord[i] = yCoord[i];
-}
-
-void GLViewer_MarkerSet::setNumMarkers( GLint number )
-{
- if ( myNumber == number )
- return;
-
- if ( myXCoord && myYCoord )
- {
- delete[] myXCoord;
- delete[] myYCoord;
- }
-
- myNumber = number;
- myXCoord = new GLfloat[ myNumber ];
- myYCoord = new GLfloat[ myNumber ];
-}
-
-void GLViewer_MarkerSet::onSelectionDone( bool append)
-{
- mySelectedIndexes.Clear();
-/*
- QValueList<int>::Iterator it;
- for( it = myMarkers->mySelNumbers.begin(); it != myMarkers->mySelNumbers.end(); ++it )
- {
- mySelectedIndexes.Append( *it / 2 ); //!!!
- }
-*/
- emit dvMarkersSelected( mySelectedIndexes );
-}
-
-void GLViewer_MarkerSet::onSelectionCancel()
-{
- mySelectedIndexes.Clear();
- emit dvMarkersSelected( mySelectedIndexes );
-}
-
-void GLViewer_MarkerSet::exportNumbers( QValueList<int>& highlight,
- QValueList<int>& unhighlight,
- QValueList<int>& select,
- QValueList<int>& unselect )
-{
- highlight = myHNumbers;
- unhighlight = myUHNumbers;
- select = mySelNumbers;
- unselect = myUSelNumbers;
-
- myUHNumbers = myHNumbers;
-}
-
-bool GLViewer_MarkerSet::addOrRemoveSelected( int index )
-{
- if( index < 0 || index > myNumber )
- return FALSE;
-
- int n = mySelNumbers.findIndex( index );
- if( n == -1 )
- mySelNumbers.append( index );
- else
- {
- QValueList<int>::Iterator it;
- it = mySelNumbers.at( n );
- mySelNumbers.remove( it );
- myUSelNumbers.append( index );
- }
- return TRUE;
-}
-
-void GLViewer_MarkerSet::addSelected( const TColStd_SequenceOfInteger& seq )
-{
- for ( int i = 1; i <= seq.Length(); i++ )
- if( mySelNumbers.findIndex( seq.Value( i ) ) == -1 )
- mySelNumbers.append( seq.Value( i ) - 1 );
-}
-
-void GLViewer_MarkerSet::setSelected( const TColStd_SequenceOfInteger& seq )
-{
-// for( QValueList<int>::Iterator it = mySelNumbers.begin(); it != mySelNumbers.end(); ++it )
-// if( myUSelNumbers.findIndex( *it ) == -1 )
-// myUSelNumbers.append( *it );
-
- myUSelNumbers = mySelNumbers;
- mySelNumbers.clear();
-
- for ( int i = 1; i <= seq.Length(); i++ )
- mySelNumbers.append( seq.Value( i ) - 1 );
-}
-
-void GLViewer_MarkerSet::moveObject( float theX, float theY, bool fromGroup )
-{
- if( !fromGroup && myGroup)
- {
- myGroup->dragingObjects( theX, theY );
- return;
- }
- for( int i = 0; i < myNumber; i++ )
- {
- myXCoord[i] = myXCoord[i] + theX;
- myYCoord[i] = myYCoord[i] + theY;
- }
- compute();
-}
-
-QByteArray GLViewer_MarkerSet::getByteCopy()
-{
- int i = 0;
- int anISize = sizeof( GLint );
- int aFSize = sizeof( GLfloat );
-
- QByteArray aObject = GLViewer_Object::getByteCopy();
-
- QByteArray aResult( anISize + 2*aFSize*myNumber + aFSize + aObject.size());
-
- char* aPointer = (char*)&myNumber;
- for( i = 0; i < anISize; i++, aPointer++ )
- aResult[i] = *aPointer;
-
- aPointer = (char*)myXCoord;
- for( ; i < anISize + aFSize*myNumber; i++, aPointer++ )
- aResult[i] = *aPointer;
- aPointer = (char*)myYCoord;
- for( ; i < anISize + 2*aFSize*myNumber; i++, aPointer++ )
- aResult[i] = *aPointer;
-
- aPointer = (char*)&myMarkerSize;
- for( ; i < anISize + 2*aFSize*myNumber + aFSize; i++, aPointer++ )
- aResult[i] = *aPointer;
-
-
- for( ; i < aResult.size(); i++ )
- aResult[i] = aObject[i - anISize - 2*aFSize*myNumber - aFSize];
-
- return aResult;
-}
-
-bool GLViewer_MarkerSet::initializeFromByteCopy( QByteArray theArray )
-{
- int i = 0;
- int anISize = sizeof( GLint );
- int aFSize = sizeof( GLfloat );
- //int aBSize = sizeof( GLboolean );
-
- char* aPointer = (char*)&myNumber;
- for( i = 0; i < anISize; i++, aPointer++ )
- *aPointer = theArray[i];
-
- int aSize = theArray.size();
- if( aSize < anISize + 2*aFSize*myNumber + aFSize)
- return false;
-
- myXCoord = new GLfloat[myNumber];
- myYCoord = new GLfloat[myNumber];
- aPointer = (char*)myXCoord;
- for( ; i < anISize + aFSize*myNumber; i++, aPointer++ )
- *aPointer = theArray[i];
- aPointer = (char*)myYCoord;
- for( ; i < anISize + 2*aFSize*myNumber; i++, aPointer++ )
- *aPointer = theArray[i];
-
- aPointer = (char*)&myMarkerSize;
- for( ; i < anISize + 2*aFSize*myNumber + aFSize; i++, aPointer++ )
- *aPointer = theArray[i];
-
- int aCurIndex = anISize + 2*aFSize*myNumber + aFSize;
- QByteArray aObject( aSize - aCurIndex );
- for( ; i < aSize; i++ )
- aObject[i - aCurIndex] = theArray[i];
-
-
- if( !GLViewer_Object::initializeFromByteCopy( aObject ) || myType != "GLViewer_MarkerSet" )
- return false;
-
- myHNumbers.clear();
- myUHNumbers.clear();
- mySelNumbers.clear();
- myUSelNumbers.clear();
- myCurSelNumbers.clear();
- myPrevHNumbers.clear();
-
- return true;
-}
-
-/***************************************************************************
-** Class: GLViewer_Polyline
-** Descr: OpenGL Polyline
-** Module: GLViewer
-** Created: UI team, 03.09.02
-****************************************************************************/
-
-#define SECTIONS 100
-#define DISTANTION 5
-
-GLViewer_Polyline::GLViewer_Polyline( int number, float size, const QString& toolTip ) :
- GLViewer_Object(), myNumber( 0 ), myXCoord( 0 ), myYCoord( 0 )
-{
- myHighFlag = GL_TRUE;
-
- myHNumbers.clear();
- myUHNumbers.clear();
- mySelNumbers.clear();
- myUSelNumbers.clear();
- myCurSelNumbers.clear();
- myPrevHNumbers.clear();
-
- setNumber( number );
-
- myType = "GLViewer_Polyline";
- myToolTipText = toolTip;
-}
-
-GLViewer_Polyline::~GLViewer_Polyline()
-{
- delete myRect;
- if ( myXCoord )
- delete[] myXCoord;
- if ( myYCoord )
- delete[] myYCoord;
-
- delete myAspectLine;
-}
-
-bool GLViewer_Polyline::translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS )
-{
- QString aBuffer = "newpath\n";
-
- AddLineAspectToPS( aBuffer, getAspectLine(), aViewerCS, aPSCS );
-
- for( int i=0; i<myNumber; i++ )
- if( i==0 )
- AddCoordsToPS( aBuffer, "moveto", aViewerCS, aPSCS, myXCoord[i], myYCoord[i] );
- else
- AddCoordsToPS( aBuffer, "lineto", aViewerCS, aPSCS, myXCoord[i], myYCoord[i] );
-
- if( myIsClosed )
- AddCoordsToPS( aBuffer, "lineto", aViewerCS, aPSCS, myXCoord[0], myYCoord[0] );
-
- aBuffer+="closepath\nstroke\n";
-
- hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
-
- return true;
-}
-
-bool GLViewer_Polyline::translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS )
-{
- QString aBuffer = "";
- for( int i=0; i<myNumber; i++ )
- {
- AddCoordsToHPGL( aBuffer, "PA", aViewerCS, aHPGLCS, myXCoord[i], myYCoord[i] );
- if( i==0 )
- aBuffer+="PD;\n";
- }
-
- if( myIsClosed )
- AddCoordsToHPGL( aBuffer, "PA", aViewerCS, aHPGLCS, myXCoord[0], myYCoord[0] );
-
- aBuffer+="PU;\n";
-
- hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
-
- return true;
-}
-
-#ifdef WIN32
-bool GLViewer_Polyline::translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS )
-{
- if( !aViewerCS || !aEMFCS )
- return false;
-
- HPEN pen = AddLineAspectToEMF( dc, getAspectLine(), aViewerCS, aEMFCS );
- HGDIOBJ old = SelectObject( dc, pen );
-
- double x, y;
- for( int i=0; i<myNumber; i++ )
- {
- x = myXCoord[i];
- y = myYCoord[i];
- aViewerCS->transform( *aEMFCS, x, y );
- if( i==0 )
- MoveToEx( dc, x, y, NULL );
- else
- LineTo( dc, x, y );
- }
-
- if( myIsClosed )
- {
- x = myXCoord[0];
- y = myYCoord[0];
- aViewerCS->transform( *aEMFCS, x, y );
- LineTo( dc, x, y );
- }
-
- SelectObject( dc, old );
- if( pen )
- DeleteObject( pen );
-
- return true;
-
- return true;
-}
-#endif
-
-void GLViewer_Polyline::compute()
-{
-// cout << "GLViewer_MarkerSet::compute" << endl;
- GLfloat xa = myXCoord[0];
- GLfloat xb = myXCoord[0];
- GLfloat ya = myYCoord[0];
- GLfloat yb = myYCoord[0];
-
- for ( int i = 0; i < myNumber; i++ )
- {
- xa = QMIN( xa, myXCoord[i] );
- xb = QMAX( xb, myXCoord[i] );
- ya = QMIN( ya, myYCoord[i] );
- yb = QMAX( yb, myYCoord[i] );
- }
-
- GLfloat xGap = ( xb - xa ) / 10;
- GLfloat yGap = ( yb - ya ) / 10;
-
- myRect->setLeft( xa - xGap );
- myRect->setTop( yb + yGap );
- myRect->setRight( xb + xGap );
- myRect->setBottom( ya - yGap );
-}
-
-GLViewer_Rect* GLViewer_Polyline::getUpdateRect()
-{
- GLViewer_Rect* rect = new GLViewer_Rect();
-
- rect->setLeft( myRect->left() - myXGap );
- rect->setTop( myRect->top() + myYGap );
- rect->setRight( myRect->right() + myXGap );
- rect->setBottom( myRect->bottom() - myYGap );
-
- return rect;
-}
-
-GLViewer_Drawer* GLViewer_Polyline::createDrawer()
-{
-// cout << "GLViewer_MarkerSet::createDrawer" << endl;
- return myDrawer = new GLViewer_PolylineDrawer();
-}
-
-GLboolean GLViewer_Polyline::highlight( GLfloat x, GLfloat y, GLfloat tol, GLboolean isCircle )
-{
- if( !myIsVisible )
- return false;
- GLfloat xa, xb, ya, yb, l;
- GLfloat rsin, rcos, r, ra, rb;
- GLboolean update;
- GLboolean highlighted = myIsHigh;
-
- myIsHigh = GL_FALSE;
-
- int c = 0;
- if( myIsClosed )
- c = 1;
-
- for( int i = 0; i < myNumber-1+c; i++ )
- {
- xa = myXCoord[i];
- ya = myYCoord[i];
- if( i != myNumber-1 )
- {
- xb = myXCoord[i+1];
- yb = myYCoord[i+1];
- }
- else
- {
- xb = myXCoord[0];
- yb = myYCoord[0];
- }
-
- l = sqrt( (xb-xa)*(xb-xa) + (yb-ya)*(yb-ya) );
- rsin = (yb-ya) / l;
- rcos = (xb-xa) / l;
- r = ( (x-xa)*(y-yb) - (x-xb)*(y-ya) ) / ( rsin*(ya-yb) + rcos*(xa-xb) );
- ra = sqrt( (x-xa)*(x-xa) + (y-ya)*(y-ya) );
- rb = sqrt( (x-xb)*(x-xb) + (y-yb)*(y-yb) );
- if( fabs( r ) * myXScale <= DISTANTION && ra <= l + DISTANTION && rb <= l + DISTANTION )
- {
- myIsHigh = GL_TRUE;
- break;
- }
- }
-
- if( !myHighFlag && myIsHigh )
- myIsHigh = GL_FALSE;
- else
- myHighFlag = GL_TRUE;
-
- update = ( GLboolean )( myIsHigh != highlighted );
-
-// cout << "GLViewer_Polyline::highlight complete with " << (int)myIsHigh << endl;
- return update;
-}
-
-GLboolean GLViewer_Polyline::unhighlight()
-{
-// if( !myHNumbers.isEmpty() )
-// {
-// myUHNumbers = myHNumbers;
-// myHNumbers.clear();
-// return GL_TRUE;
-// }
-
- if( myIsHigh )
- {
- myIsHigh = GL_FALSE;
- return GL_TRUE;
- }
-
- return GL_FALSE;
-}
-
-GLboolean GLViewer_Polyline::select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect, GLboolean isFull,
- GLboolean isCircle, GLboolean isShift )
-{
- if( !myIsVisible )
- return false;
- GLfloat xa, xb, ya, yb, l;
- GLfloat rsin, rcos, r, ra, rb;
- GLboolean update;
- GLboolean selected = myIsSel;
-
- myIsSel = GL_FALSE;
-
- int c = 0;
- if( myIsClosed )
- c = 1;
-
- for( int i = 0; i < myNumber-1+c; i++ )
- {
- xa = myXCoord[i];
- ya = myYCoord[i];
- if( i != myNumber-1 )
- {
- xb = myXCoord[i+1];
- yb = myYCoord[i+1];
- }
- else
- {
- xb = myXCoord[0];
- yb = myYCoord[0];
- }
-
- l = sqrt( (xb-xa)*(xb-xa) + (yb-ya)*(yb-ya) );
- rsin = (yb-ya) / l;
- rcos = (xb-xa) / l;
- r = ( (x-xa)*(y-yb) - (x-xb)*(y-ya) ) / ( rsin*(ya-yb) + rcos*(xa-xb) );
- ra = sqrt( (x-xa)*(x-xa) + (y-ya)*(y-ya) );
- rb = sqrt( (x-xb)*(x-xb) + (y-yb)*(y-yb) );
- if( fabs( r ) * myXScale <= DISTANTION && ra <= l + DISTANTION && rb <= l + DISTANTION )
- {
- myIsSel = GL_TRUE;
- break;
- }
- }
-
- if ( myIsSel )
- {
- myHighFlag = GL_FALSE;
- myIsHigh = GL_FALSE;
- }
- else
- myHighFlag = GL_TRUE;
-
- update = ( GLboolean )( myIsSel != selected );
-
- // cout << "GLViewer_Polyline::select complete with " << (int)myIsSel << endl;
-
- // return update; !!!!!!!!!!!!!!!!!!!!!!!!!!! no here
- return myIsSel;
-}
-
-GLboolean GLViewer_Polyline::unselect()
-{
-// if( !mySelNumbers.isEmpty() )
-// {
-// myUSelNumbers = mySelNumbers;
-// mySelNumbers.clear();
-// myCurSelNumbers.clear();
-// return GL_TRUE;
-// }
-
- if( myIsSel )
- {
- myIsSel = GL_FALSE;
- return GL_TRUE;
- }
-
- return GL_FALSE;
-}
-
-void GLViewer_Polyline::setXCoord( GLfloat* xCoord, int size )
-{
- myXCoord = new GLfloat[ size ];
- for( int i = 0; i < size; i++ )
- myXCoord[i] = xCoord[i];
-}
-
-void GLViewer_Polyline::setYCoord( GLfloat* yCoord, int size )
-{
- myYCoord = new GLfloat[ size ];
- for( int i = 0; i < size; i++ )
- myYCoord[i] = yCoord[i];
-}
-
-void GLViewer_Polyline::setNumber( GLint number )
-{
- if ( myNumber == number )
- return;
-
- if ( myXCoord && myYCoord )
- {
- delete[] myXCoord;
- delete[] myYCoord;
- }
-
- myNumber = number;
- myXCoord = new GLfloat[ myNumber ];
- myYCoord = new GLfloat[ myNumber ];
-}
-
-void GLViewer_Polyline::onSelectionDone( bool append)
-{
- mySelectedIndexes.Clear();
-/*
- QValueList<int>::Iterator it;
- for( it = myMarkers->mySelNumbers.begin(); it != myMarkers->mySelNumbers.end(); ++it )
- {
- mySelectedIndexes.Append( *it / 2 ); //!!!
- }
-*/
-}
-
-void GLViewer_Polyline::onSelectionCancel()
-{
- mySelectedIndexes.Clear();
-}
-
-void GLViewer_Polyline::exportNumbers( QValueList<int>& highlight,
- QValueList<int>& unhighlight,
- QValueList<int>& select,
- QValueList<int>& unselect )
-{
- highlight = myHNumbers;
- unhighlight = myUHNumbers;
- select = mySelNumbers;
- unselect = myUSelNumbers;
-}
-
-void GLViewer_Polyline::moveObject( float theX, float theY, bool fromGroup )
-{
- if( !fromGroup && myGroup)
- {
- myGroup->dragingObjects( theX, theY );
- return;
- }
- for( int i = 0; i < myNumber; i++ )
- {
- myXCoord[i] = myXCoord[i] + theX;
- myYCoord[i] = myYCoord[i] + theY;
- }
- compute();
-}
-
-QByteArray GLViewer_Polyline::getByteCopy()
-{
- int i = 0;
- int anISize = sizeof( GLint );
- int aFSize = sizeof( GLfloat );
- int aBSize = sizeof( GLboolean );
-
- QByteArray aObject = GLViewer_Object::getByteCopy();
-
- QByteArray aResult( aFSize*myNumber*2 + anISize + 2*aBSize + aObject.size());
-
- char* aPointer = (char*)&myNumber;
- for( i = 0; i < anISize; i++, aPointer++ )
- aResult[i] = *aPointer;
-
- aPointer = (char*)myXCoord;
- for( ; i < anISize + aFSize*myNumber; i++, aPointer++ )
- aResult[i] = *aPointer;
- aPointer = (char*)myYCoord;
- for( ; i < anISize + 2*aFSize*myNumber; i++, aPointer++ )
- aResult[i] = *aPointer;
-
- aPointer = (char*)&myIsClosed;
- for( ; i < anISize + 2*aFSize*myNumber + aBSize; i++, aPointer++ )
- aResult[i] = *aPointer;
- aPointer = (char*)&myHighSelAll;
- for( ; i < anISize + 2*aFSize*myNumber + 2*aBSize; i++, aPointer++ )
- aResult[i] = *aPointer;
-
- for( ; i < aResult.size(); i++ )
- aResult[i] = aObject[i - anISize - 2*aFSize*myNumber - 2*aBSize];
-
- return aResult;
-}
-
-
-bool GLViewer_Polyline::initializeFromByteCopy( QByteArray theArray )
-{
- int i = 0;
- int anISize = sizeof( GLint );
- int aFSize = sizeof( GLfloat );
- int aBSize = sizeof( GLboolean );
-
- char* aPointer = (char*)&myNumber;
- for( i = 0; i < anISize; i++, aPointer++ )
- *aPointer = theArray[i];
-
- int aSize = theArray.size();
- if( aSize < aFSize*myNumber*2 + anISize + 2*aBSize )
- return false;
-
- myXCoord = new GLfloat[myNumber];
- myYCoord = new GLfloat[myNumber];
- aPointer = (char*)myXCoord;
- for( ; i < anISize + aFSize*myNumber; i++, aPointer++ )
- *aPointer = theArray[i];
- aPointer = (char*)myYCoord;
- for( ; i < anISize + 2*aFSize*myNumber; i++, aPointer++ )
- *aPointer = theArray[i];
-
- aPointer = (char*)&myIsClosed;
- for( ; i < anISize + 2*aFSize*myNumber + aBSize; i++, aPointer++ )
- *aPointer = theArray[i];
- aPointer = (char*)&myHighSelAll;
- for( ; i < anISize + 2*aFSize*myNumber + 2*aBSize; i++, aPointer++ )
- *aPointer = theArray[i];
-
- int aCurIndex = anISize + 2*aFSize*myNumber + 2*aBSize;
- QByteArray aObject( aSize - aCurIndex );
- for( ; i < aSize; i++ )
- aObject[i - aCurIndex] = theArray[i];
-
- if( !GLViewer_Object::initializeFromByteCopy( aObject ) || myType != "GLViewer_Polyline" )
- return false;
-
- myHNumbers.clear();
- myUHNumbers.clear();
- mySelNumbers.clear();
- myUSelNumbers.clear();
- myCurSelNumbers.clear();
- myPrevHNumbers.clear();
-
- return true;
-}
-
-/***************************************************************************
-** Class: GLViewer_TextObject
-** Descr: Text as Object for OpenGL
-** Module: GLViewer
-** Created: UI team, 12.02.04
-****************************************************************************/
-
-GLViewer_TextObject::GLViewer_TextObject( const QString& theStr, float xPos, float yPos,
- const QColor& color, const QString& toolTip )
- : GLViewer_Object()
-{
- myGLText = new GLViewer_Text( theStr, xPos, yPos, color );
- myWidth = 0;
- myHeight = 0;
-
- myHighFlag = GL_TRUE;
-
- myType = "GLViewer_TextObject";
- myToolTipText = toolTip;
-}
-GLViewer_TextObject::~GLViewer_TextObject()
-{
- if ( myGLText )
- delete myGLText;
-
- delete myRect;
- delete myAspectLine;
-}
-
-bool GLViewer_TextObject::translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS )
-{
- QString aText = myGLText->getText();
- float xPos, yPos;
- myGLText->getPosition( xPos, yPos );
-
- QString aBuffer = "/Times-Roman findfont\n";
- aBuffer += "12 scalefont setfont\n";
-
- AddCoordsToPS( aBuffer, "moveto", aViewerCS, aPSCS, double(xPos), double(yPos) );
- aBuffer += "(" + aText + ") show\n";
-
- hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
-
- return true;
-}
-
-bool GLViewer_TextObject::translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS )
-{
- QString aText = myGLText->getText();
- float xPos, yPos;
- myGLText->getPosition( xPos, yPos );
-
- QString aBuffer = "";
- AddCoordsToHPGL( aBuffer, "PA", aViewerCS, aHPGLCS, double(xPos), double(yPos) );
-
- aBuffer = "LB" + aText + "#;";
-
- hFile.writeBlock( aBuffer.ascii(), aBuffer.length() );
-
- return true;
-}
-
-#ifdef WIN32
-bool GLViewer_TextObject::translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS )
-{
- QString aText = myGLText->getText();
- float xPos, yPos;
- myGLText->getPosition( xPos, yPos );
-
- double x = double( xPos ),
- y = double( yPos );
-
- aViewerCS->transform( *aEMFCS, x, y );
- const char* str = aText.ascii();
-
- int nHeight = 35*14; // height of font
- int nWidth = 35*12; // average character width
- int nEscapement = 0; // angle of escapement
- int nOrientation = 0; // base-line orientation angle
- int fnWeight = FW_NORMAL; // font weight
- DWORD fdwItalic = FALSE; // italic attribute option
- DWORD fdwUnderline = FALSE; // underline attribute option
- DWORD fdwStrikeOut = FALSE; // strikeout attribute option
- DWORD fdwCharSet = ANSI_CHARSET; // character set identifier
- DWORD fdwOutputPrecision = OUT_DEFAULT_PRECIS; // output precision
- DWORD fdwClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
- DWORD fdwQuality = PROOF_QUALITY; // output quality
- DWORD fdwPitchAndFamily = FIXED_PITCH | FF_DONTCARE; // pitch and family
- LPCTSTR lpszFace = NULL; // typeface name
-
-
- HFONT aFont = CreateFont( nHeight, nWidth, nEscapement, nOrientation, fnWeight, fdwItalic,
- fdwUnderline, fdwStrikeOut, fdwCharSet, fdwOutputPrecision,
- fdwClipPrecision, fdwQuality, fdwPitchAndFamily, lpszFace );
- LOGBRUSH aBrushData;
- aBrushData.lbStyle = BS_HOLLOW;
-
- HBRUSH aBrush = CreateBrushIndirect( &aBrushData );
-
- HGDIOBJ old1 = SelectObject( dc, aFont );
- HGDIOBJ old2 = SelectObject( dc, aBrush );
-
- TextOut( dc, x, y, str, aText.length() );
-
- SelectObject ( dc, old1 );
- SelectObject ( dc, old2 );
-
- DeleteObject( aFont );
-
- return true;
-}
-#endif
-
-GLViewer_Drawer* GLViewer_TextObject::createDrawer()
-{
- myDrawer = new GLViewer_TextDrawer();
- compute();
- return myDrawer;
-}
-
-void GLViewer_TextObject::compute()
-{
- float xPos, yPos;
- QString aStr = myGLText->getText();
- myGLText->getPosition( xPos, yPos );
-
- myWidth = myGLText->getWidth();
- myHeight = myGLText->getHeight();
- myRect->setLeft( xPos );
- myRect->setTop( yPos + myHeight );
- myRect->setRight( xPos + myWidth );
- myRect->setBottom( yPos );
-}
-
-void GLViewer_TextObject::setDrawer( GLViewer_Drawer* theDrawer )
-{
- myDrawer = theDrawer;
- //compute();
-}
-
-GLViewer_Rect* GLViewer_TextObject::getUpdateRect()
-{
- GLViewer_Rect* rect = new GLViewer_Rect();
-
- float xPos, yPos;
- QString aStr = myGLText->getText();
- myGLText->getPosition( xPos, yPos );
-
- rect->setLeft( myRect->left() + myXGap - myWidth / myXScale );
- rect->setTop( myRect->top() + myYGap + myHeight / myYScale );
- rect->setRight( myRect->right() - myXGap + myWidth / myXScale );
- rect->setBottom( myRect->bottom() - myYGap - myHeight / myYScale );
-
- return rect;
-}
-
-GLboolean GLViewer_TextObject::highlight( GLfloat theX, GLfloat theY, GLfloat theTol, GLboolean isCircle )
-{
- if( !myIsVisible )
- return false;
-
- float xPos, yPos;
- myGLText->getPosition( xPos, yPos );
-
- QRect aRect;
- aRect.setLeft( (int)xPos );
- aRect.setRight( (int)(xPos + myWidth / myXScale) );
- aRect.setTop( (int)yPos );// - myHeight / myYScale );
- aRect.setBottom( (int)(yPos + myHeight / myYScale) );
-
- //cout << "theX: " << theX << " theY: " << theY << endl;
- //cout << "aRect.left(): " << aRect.left() << " aRect.right(): " << aRect.right() << endl;
- //cout << "aRect.top(): " << aRect.top() << " aRect.bottom(): " << aRect.bottom() << endl;
-
- QRegion obj( aRect );
- QRegion intersection;
- QRect region;
-
- int l = (int)(theX - theTol);
- int r = (int)(theX + theTol);
- int t = (int)(theY - theTol);
- int b = (int)(theY + theTol);
- region.setLeft( l );
- region.setRight( r );
- region.setTop( t );
- region.setBottom( b );
-
- QRegion circle( l, t, (int)(2 * theTol), (int)(2 * theTol), QRegion::Ellipse );
- if( isCircle )
- intersection = obj.intersect( circle );
- else
- intersection = obj.intersect( region );
-
- if( intersection.isEmpty() )
- myIsHigh = false;
- else
- myIsHigh = true;
-
- if( !myHighFlag && myIsHigh )
- myIsHigh = GL_FALSE;
- else
- myHighFlag = GL_TRUE;
-
- return myIsHigh;
-}
-
-GLboolean GLViewer_TextObject::unhighlight()
-{
- if( myIsHigh )
- {
- myIsHigh = GL_FALSE;
- return GL_TRUE;
- }
-
- return GL_FALSE;
-}
-
-GLboolean GLViewer_TextObject::select( GLfloat theX, GLfloat theY, GLfloat theTol, GLViewer_Rect rect,
- GLboolean isFull, GLboolean isCircle, GLboolean isShift )
-{
- if( !myIsVisible )
- return false;
-
- QRegion obj( *(myRect->toQRect()) );
- QRegion intersection;
- QRect region;
-
- int l = (int)(theX - theTol);
- int r = (int)(theX + theTol);
- int t = (int)(theY - theTol);
- int b = (int)(theY + theTol);
- region.setLeft( l );
- region.setRight( r );
- region.setTop( t );
- region.setBottom( b );
-
- QRegion circle( l, t, (int)(2 * theTol), (int)(2 * theTol), QRegion::Ellipse );
- if( isCircle )
- intersection = obj.intersect( circle );
- else
- intersection = obj.intersect( region );
-
- if( intersection.isEmpty() )
- myIsSel = false;
- else
- myIsSel = true;
-
- if ( myIsSel )
- {
- myHighFlag = GL_FALSE;
- myIsHigh = GL_FALSE;
- }
- else
- myHighFlag = GL_TRUE;
-
- return myIsSel;
-}
-
-GLboolean GLViewer_TextObject::unselect()
-{
- if( myIsSel )
- {
- myIsSel = GL_FALSE;
- return GL_TRUE;
- }
-
- return GL_FALSE;
-}
-
-void GLViewer_TextObject::moveObject( float theX, float theY, bool fromGroup )
-{
- if( !fromGroup && myGroup)
- {
- myGroup->dragingObjects( theX, theY );
- return;
- }
- float aX, anY;
- myGLText->getPosition( aX, anY );
- aX += theX;
- anY += theY;
- myGLText->setPosition( aX, anY );
- compute();
-}
-
-QByteArray GLViewer_TextObject::getByteCopy()
-{
- QByteArray aObject = GLViewer_Object::getByteCopy();
-
- return aObject;
-}
-
-
-bool GLViewer_TextObject::initializeFromByteCopy( QByteArray theArray )
-{
- if( !GLViewer_Object::initializeFromByteCopy( theArray ) || myType != "GLViewer_TextObject" )
- return false;
-
- myHighFlag = true;
- return true;
-}
-
-
-/***************************************************************************
-** Class: GLViewer_AspectLine
-** Descr: Substitution of Prs2d_AspectLine for OpenGL
-** Module: GLViewer
-** Created: UI team, 05.11.02
-****************************************************************************/
-
-GLViewer_AspectLine::GLViewer_AspectLine()
-{
- myNColor = QColor( 255, 255, 255 );
- myHColor = QColor( 0, 255, 255 );
- mySColor = QColor( 255, 0, 0 );
-
- myLineWidth = 1.0;
- myLineType = 0;
-}
-
-GLViewer_AspectLine::GLViewer_AspectLine( int type, float width )
-{
- myNColor = QColor( 255, 255, 255 );
- myHColor = QColor( 0, 255, 255 );
- mySColor = QColor( 255, 0, 0 );
-
- myLineWidth = width;
- if( type == 1 || type == 0 )
- myLineType = type;
- else
- myLineType = 0;
-}
-
-GLViewer_AspectLine::~GLViewer_AspectLine()
-{
-}
-
-void GLViewer_AspectLine::setLineColors( QColor nc, QColor hc, QColor sc )
-{
- myNColor = nc;
- myHColor = hc;
- mySColor = sc;
-}
-
-int GLViewer_AspectLine::setLineType( const int type )
-{
- if( type == 1 || type == 0 )
- {
- myLineType = type;
- return 0;
- }
- return 1;
-}
-
-int GLViewer_AspectLine::setLineWidth( const float width )
-{
- if( width > 0 )
- {
- myLineWidth = width;
- return 0;
- }
- return 1;
-}
-
-void GLViewer_AspectLine::getLineColors( QColor& nc, QColor& hc, QColor& sc ) const
-{
- nc = myNColor;
- hc = myHColor;
- sc = mySColor;
-}
-
-QByteArray GLViewer_AspectLine::getByteCopy() const
-{
- int anISize = sizeof( int );
- int aFSize = sizeof( float );
- int aNR = myNColor.red(), aNG = myNColor.green(), aNB = myNColor.blue();
- int aHR = myHColor.red(), aHG = myHColor.green(), aHB = myHColor.blue();
- int aSR = mySColor.red(), aSG = mySColor.green(), aSB = mySColor.blue();
-
- QByteArray aResult( anISize * 10 + aFSize );
-
- int i = 0;
-
- char* aPointer = (char*)&aNR;
- for( i = 0; i < anISize; i++, aPointer++ )
- aResult[i] = *aPointer;
- aPointer = (char*)&aNG;
- for( ; i < 2*anISize; i++, aPointer++ )
- aResult[i] = *aPointer;
- aPointer = (char*)&aNB;
- for( ; i < 3*anISize; i++, aPointer++ )
- aResult[i] = *aPointer;
-
- aPointer = (char*)&aHR;
- for( ; i < 4*anISize; i++, aPointer++ )
- aResult[i] = *aPointer;
- aPointer = (char*)&aHG;
- for( ; i < 5*anISize; i++, aPointer++ )
- aResult[i] = *aPointer;
- aPointer = (char*)&aHB;
- for( ; i < 6*anISize; i++, aPointer++ )
- aResult[i] = *aPointer;
-
- aPointer = (char*)&aSR;
- for( ; i < 7*anISize; i++, aPointer++ )
- aResult[i] = *aPointer;
- aPointer = (char*)&aSG;
- for( ; i < 8*anISize; i++, aPointer++ )
- aResult[i] = *aPointer;
- aPointer = (char*)&aSB;
- for( ; i < 9*anISize; i++, aPointer++ )
- aResult[i] = *aPointer;
-
- aPointer = (char*)&myLineWidth;
- for( ; i < 9*anISize + aFSize; i++, aPointer++ )
- aResult[i] = *aPointer;
-
- aPointer = (char*)&myLineType;
- for( ; i < 10*anISize + aFSize; i++, aPointer++ )
- aResult[i] = *aPointer;
-
- return aResult;
-}
-
-GLViewer_AspectLine* GLViewer_AspectLine::fromByteCopy( QByteArray theBytes )
-{
-
- int anISize = sizeof( int );
- int aFSize = sizeof( float );
- int aNR = 0, aNG = 0, aNB = 0;
- int aHR = 0, aHG = 0, aHB = 0;
- int aSR = 0, aSG = 0, aSB = 0;
- int aLineType = 0;
- float aLineWidth = 0;
-
- int i = 0;
-
- char* aPointer = (char*)&aNR;
- for( i = 0; i < anISize; i++, aPointer++ )
- *aPointer = theBytes[i];
- aPointer = (char*)&aNG;
- for( ; i < 2*anISize; i++, aPointer++ )
- *aPointer = theBytes[i];
- aPointer = (char*)&aNB;
- for( ; i < 3*anISize; i++, aPointer++ )
- *aPointer = theBytes[i];
-
- aPointer = (char*)&aHR;
- for( ; i < 4*anISize; i++, aPointer++ )
- *aPointer = theBytes[i];
- aPointer = (char*)&aHG;
- for( ; i < 5*anISize; i++, aPointer++ )
- *aPointer = theBytes[i];
- aPointer = (char*)&aHB;
- for( ; i < 6*anISize; i++, aPointer++ )
- *aPointer = theBytes[i];
-
- aPointer = (char*)&aSR;
- for( ; i < 7*anISize; i++, aPointer++ )
- *aPointer = theBytes[i];
- aPointer = (char*)&aSG;
- for( ; i < 8*anISize; i++, aPointer++ )
- *aPointer = theBytes[i];
- aPointer = (char*)&aSB;
- for( ; i < 9*anISize; i++, aPointer++ )
- *aPointer = theBytes[i];
-
- aPointer = (char*)&aLineWidth;
- for( ; i < 9*anISize + aFSize; i++, aPointer++ )
- *aPointer = theBytes[i];
-
- aPointer = (char*)&aLineType;
- for( ; i < 10*anISize + aFSize; i++, aPointer++ )
- *aPointer = theBytes[i];
-
- GLViewer_AspectLine* anAspect = new GLViewer_AspectLine( aLineType, aLineWidth );
- anAspect->setLineColors( QColor( aNR, aNG, aNB ),
- QColor( aHR, aHG, aHB ),
- QColor( aSR, aSG, aSB ) );
- return anAspect;
-}
-
-/***************************************************************************
-** Class: GLViewer_MimeSource
-** Descr: Needs for a work with QClipboard
-** Module: GLViewer
-** Created: UI team, 22.03.04
-****************************************************************************/
-GLViewer_MimeSource::~GLViewer_MimeSource()
-{
-}
-
-bool GLViewer_MimeSource::setObjects( QValueList<GLViewer_Object*> theObjects )
-{
- if( !theObjects.empty() )
- {
- QStringList aObjectsType;
- QValueList<QByteArray> aObjects;
- QValueList<GLViewer_Object*>::const_iterator anIt = theObjects.begin();
- QValueList<GLViewer_Object*>::const_iterator anEndIt = theObjects.end();
-
- int aObjByteSize = 0;
- for( ; anIt != anEndIt; anIt++ )
- {
- aObjects.append( (*anIt)->getByteCopy() );
- aObjByteSize += aObjects.last().size();
- aObjectsType.append( (*anIt)->getObjectType() );
- }
-
- int anISize = sizeof( int );
- QString aTypes = aObjectsType.join("");
- int aStrByteSize = aTypes.length();
- int aObjNum = aObjects.count();
-
- myByteArray = QByteArray( anISize * (1 + 2*aObjNum) + aStrByteSize + aObjByteSize );
-
- int anIndex = 0, j = 0;
- char* aPointer = (char*)&aObjNum;
- for( anIndex = 0; anIndex < anISize; anIndex++, aPointer++ )
- myByteArray[anIndex] = *aPointer;
-
- QStringList::const_iterator aStrIt = aObjectsType.begin();
- QStringList::const_iterator aEndStrIt = aObjectsType.end();
- for( j = 1; aStrIt != aEndStrIt; aStrIt++, j++ )
- {
- int aStrLen = (*aStrIt).length();
- aPointer = (char*)&aStrLen;
- for( ; anIndex < anISize*( 1 + j ); anIndex++, aPointer++ )
- myByteArray[anIndex] = *aPointer;
- }
-
- int aCurIndex = anIndex;
- const char* aStr = aTypes.data();
-
- for( j = 0 ; anIndex < aCurIndex + aStrByteSize; aPointer++, anIndex++, j++ )
- myByteArray[anIndex] = aStr[j];
-
- aCurIndex = anIndex;
- QValueList<QByteArray>::iterator anObjIt = aObjects.begin();
- QValueList<QByteArray>::iterator anEndObjIt = aObjects.end();
- for( j = 1; anObjIt != anEndObjIt; anObjIt++, j++ )
- {
- int aObjLen = (int)((*anObjIt).size());
- aPointer = (char*)&aObjLen;
- for( ; anIndex < aCurIndex + anISize*j; anIndex++, aPointer++ )
- myByteArray[anIndex] = *aPointer;
- }
-
- aCurIndex = anIndex;
- anObjIt = aObjects.begin();
-
- for( ; anObjIt != anEndObjIt; anObjIt++ )
- {
- int aObjLen = (int)((*anObjIt).size());
- for( j = 0 ; anIndex < aCurIndex + aObjLen; anIndex++, aPointer++, j++ )
- myByteArray[anIndex] = (*anObjIt)[j];
- aCurIndex = anIndex;
- }
-
- return true;
- }
-
- return false;
-}
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!NOTE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-//If you want to use new class, following two method must be redefined
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!NOTE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-GLViewer_Object* GLViewer_MimeSource::getObject( QByteArray theArray, QString theType )
-{
- if( !theArray.isEmpty() )
- {
- if( theType == "GLViewer_MarkerSet" )
- {
- GLViewer_MarkerSet* aObject = new GLViewer_MarkerSet( 0, (float)0.0, 0 );
- if( aObject->initializeFromByteCopy( theArray ) )
- return aObject;
- }
- else if ( theType == "GLViewer_Polyline" )
- {
- GLViewer_Polyline* aObject = new GLViewer_Polyline( 0, (float)0.0, 0 );
- if( aObject->initializeFromByteCopy( theArray ) )
- return aObject;
- }
- else if( theType == "GLViewer_TextObject" )
- {
- GLViewer_TextObject* aObject = new GLViewer_TextObject( 0, 0, 0, QColor(255,255,255), 0 );
- if( aObject->initializeFromByteCopy( theArray ) )
- return aObject;
- }
- }
-
- return NULL;
-}
-
-QValueList<GLViewer_Object*> GLViewer_MimeSource::getObjects( QByteArray theArray, QString theType )
-{
- if( !theArray.isEmpty() )
- {
- int anISize = sizeof( int );
- if( theType == "GLViewer_Objects" )
- {
- QStringList aTypeList;
- QValueList<QByteArray> aObjects;
- QValueList<GLViewer_Object*> aObjectList;
-
- QValueList<int> aTypeSizeList;
- QValueList<int> aObjSizeList;
- int aObjNum = 0;
- char* aPointer = (char*)&aObjNum;
-
- int anIndex = 0, j = 0;
- for( anIndex = 0; anIndex < anISize; anIndex++, aPointer++ )
- *aPointer = theArray[anIndex];
-
- for( j = 0; j < aObjNum; j++ )
- {
- int aTempVal = 0;
- aPointer = (char*)&aTempVal;
- for( ; anIndex < anISize*(j+2); anIndex++, aPointer++ )
- *aPointer = theArray[anIndex];
- aTypeSizeList.append( aTempVal );
- }
-
- int aCurIndex = anIndex;
- for( j = 0; j < aObjNum; j++ )
- {
- QString aTempStr;
- for( ; anIndex < aCurIndex + aTypeSizeList[j]; anIndex++ )
- {
- char aLetter = theArray[anIndex];
- aTempStr.append( aLetter );
- }
- aTypeList.append( aTempStr );
- aCurIndex = anIndex;
- }
-
- for( j = 0; j < aObjNum; j++ )
- {
- int aTempVal = 0;
- aPointer = (char*)&aTempVal;
- for( ; anIndex < aCurIndex + anISize*(j+1); anIndex++, aPointer++ )
- *aPointer = theArray[anIndex];
- aObjSizeList.append( aTempVal );
- }
-
- aCurIndex = anIndex;
- for( j = 0; j < aObjNum; j++ )
- {
- QByteArray aTempArray(aObjSizeList[j]);
- for( ; anIndex < aCurIndex + aObjSizeList[j]; anIndex++ )
- aTempArray[anIndex-aCurIndex] = theArray[anIndex];
- aObjects.append( aTempArray );
- aCurIndex = anIndex;
- }
-
- for( j = 0; j < aObjNum; j++ )
- aObjectList.append( getObject( aObjects[j], aTypeList[j] ) );
-
- return aObjectList;
- }
- }
-
- return QValueList<GLViewer_Object*>();
-}
-
-const char* GLViewer_MimeSource::format( int theIndex ) const
-{
- switch( theIndex )
- {
- case 0: return "GLViewer_Objects";
- //case 1: return "GLViewer_MarkerSet";
- //case 2: return "GLViewer_Polyline";
- //case 3: return "GLViewer_TextObject";
- default: return 0;
- }
-
-}
-
-QByteArray GLViewer_MimeSource::encodedData( const char* theObjectType ) const
-{
- if( theObjectType == "GLViewer_Objects" )
- return myByteArray;
-
- return QByteArray();
-}
#include "GLViewer.h"
#include "GLViewer_Defs.h"
+#include "GLViewer_Geom.h"
+
+#include <SUIT_DataOwner.h>
#include <GL/gl.h>
-#include <qfont.h>
-#include <qobject.h>
+#include <qfile.h>
#include <qstring.h>
-#include <qcolor.h>
-#include <qmime.h>
#include <qrect.h>
-#include <qvaluelist.h>
-
-#include <TColStd_SequenceOfInteger.hxx>
-
-class QFile;
#ifdef WNT
#pragma warning( disable:4251 )
#endif
-class GLVIEWER_EXPORT GLViewer_Pnt
-{
-public:
- GLViewer_Pnt() : myX( 0. ), myY( 0. ) {}
- GLViewer_Pnt( GLfloat theX, GLfloat theY ) : myX( theX ), myY( theY ) {}
-
- GLfloat x() const { return myX; }
- GLfloat y() const { return myY; }
- void setX( GLfloat theX ) { myX = theX; }
- void setY( GLfloat theY ) { myY = theY; }
- void setXY( GLfloat theX, GLfloat theY ) { myX = theX; myY = theY; }
- void move( GLfloat theDX, GLfloat theDY ) { myX += theDX; myY += theDY; }
-
-private:
- GLfloat myX;
- GLfloat myY;
-};
+// Class: GLViewer_Object
+// Descr: OpenGL Object
-typedef QValueList<GLViewer_Pnt> GLViewer_PntList;
+class GLViewer_Drawer;
+class GLViewer_AspectLine;
+class GLViewer_Group;
+class GLViewer_CoordSystem;
+class GLViewer_Text;
+class GLViewer_Owner;
-/***************************************************************************
-** Class: GLViewer_Rect
-** Descr: Substitution of QRect for OpenGL
-** Module: GLViewer
-** Created: UI team, 19.04.04
-****************************************************************************/
-class GLVIEWER_EXPORT GLViewer_Rect
+class GLVIEWER_API GLViewer_Object
{
public:
- GLViewer_Rect(): myLeft(0.0), myRight(0.0), myTop(0.0), myBottom(0.0){}
- GLViewer_Rect( float theLeft, float theRight, float theTop, float theBottom )
- : myLeft(theLeft), myRight(theRight), myTop(theTop), myBottom(theBottom) {}
- GLViewer_Rect( QRect theRect ) {
- myLeft = ( float )theRect.left(); myRight = ( float )theRect.right();
- myTop = ( float )theRect.top(); myBottom = ( float )theRect.bottom(); }
+ GLViewer_Object();
+ virtual ~GLViewer_Object();
-
- float left() const { return myLeft; }
- float right() const { return myRight; }
- float top() const { return myTop; }
- float bottom() const { return myBottom; }
-
- void setLeft( float theLeft ) { myLeft = theLeft; }
- void setRight( float theRight ) { myRight = theRight; }
- void setTop( float theTop ) { myTop = theTop; }
- void setBottom( float theBottom ) { myBottom = theBottom; }
-
- void setCoords( float theLeft, float theRight, float theTop, float theBottom )
- { myLeft = theLeft; myRight = theRight; myTop = theTop; myBottom = theBottom; }
-
- QRect* toQRect() { return new QRect( ( int )myLeft, ( int )myBottom,
- ( int )( myRight - myLeft ), ( int )( myTop - myBottom ) ); }
+ virtual void compute() = 0;
+ virtual GLViewer_Drawer* createDrawer() = 0;
- bool isNull() const { return myLeft == myRight || myTop == myBottom; }
- bool isValid() const { return !( myLeft > myRight || myTop < myBottom ); }
+ virtual void setDrawer( GLViewer_Drawer* theDrawer ) { myDrawer = theDrawer; }
+ GLViewer_Drawer* getDrawer() const { return myDrawer; }
- bool contains( GLViewer_Pnt pnt ) { return ( pnt.x() > left() &&
- pnt.x() < right() &&
- pnt.y() > top() &&
- pnt.y() < bottom() ); }
+ virtual GLboolean highlight( GLfloat x, GLfloat y, GLfloat tol, GLboolean isCircle = GL_FALSE ) = 0;
+ virtual GLboolean unhighlight() = 0;
+ virtual GLboolean select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect,
+ GLboolean isFull = GL_FALSE, GLboolean isCircle = GL_FALSE, GLboolean isShift = GL_FALSE ) = 0;
+ virtual GLboolean unselect() = 0;
-protected:
- float myLeft;
- float myRight;
- float myTop;
- float myBottom;
-};
-
-/***************************************************************************
-** Class: GLViewer_Text
-** Descr: Substitution of Prs3d_Text for OpenGL
-** Module: GLViewer
-** Created: UI team, 10.07.03
-****************************************************************************/
-class GLVIEWER_EXPORT GLViewer_Text
-{
-public:
- GLViewer_Text( const QString&, float xPos = 0.0, float yPos = 0.0, const QColor& color = QColor( 0, 255, 0 ) );
- GLViewer_Text( const QString&, float xPos, float yPos, const QColor& , QFont, int );
- ~GLViewer_Text();
+ virtual GLboolean isInside( GLViewer_Rect );
- void setText( const QString& text ) { myText = text; }
- QString getText() const { return myText; }
+ virtual bool portContains( GLViewer_Pnt ) { return false; }
+ virtual bool startPulling( GLViewer_Pnt ) { return false; }
+ virtual void pull( GLViewer_Pnt, GLViewer_Object* ) {}
+ virtual void finishPulling() {}
+ virtual bool isPulling() { return false; }
+ virtual GLViewer_Rect getPullingRect() const { return GLViewer_Rect(
+ myRect->left(), myRect->right(), myRect->top(), myRect->bottom() ); }
- void setPosition( float xPos, float yPos ) { myXPos = xPos; myYPos = yPos; }
- void getPosition( float& xPos, float& yPos ) { xPos = myXPos; yPos = myYPos; }
+ virtual void setRect( GLViewer_Rect* rect) { myRect = rect; }
+ virtual GLViewer_Rect* getRect() const { return myRect; }
+ virtual GLViewer_Rect* getUpdateRect() = 0;
- void setColor( const QColor& color ) { myColor = color; }
- QColor getColor() const { return myColor; }
-
- void setFont( const QFont theQFont) { myQFont = theQFont; }
- QFont getFont() const { return myQFont; }
+ virtual void setScale( GLfloat xScale, GLfloat yScale ) { myXScale = xScale; myYScale = yScale; }
+ virtual void getScale( GLfloat& xScale, GLfloat& yScale ) const { xScale = myXScale; yScale = myYScale;}
+
+ virtual GLboolean setZoom( GLfloat zoom, bool recompute, bool fromGroup = false );
+ virtual GLfloat getZoom() const { return myZoom; }
+ virtual GLboolean updateZoom( bool zoomIn );
- int getSeparator(){ return mySeparator; }
- void setSeparator( int theSep ){ mySeparator = theSep; }
+ virtual GLboolean isHighlighted() const { return myIsHigh; }
+ virtual GLboolean isSelected() const { return myIsSel; }
+ virtual void setSelected( GLboolean state ) { myIsSel = state; }
- int getWidth();
- int getHeight();
+ void setGLText( GLViewer_Text* glText ) { myGLText = glText; }
+ GLViewer_Text* getGLText() const { return myGLText; }
- QByteArray getByteCopy() const;
+ virtual void setAspectLine ( GLViewer_AspectLine* aspect ) { myAspectLine = aspect; }
+ virtual GLViewer_AspectLine* getAspectLine() const { return myAspectLine; }
- static GLViewer_Text* fromByteCopy( QByteArray );
+ QString getObjectType() const { return myType; }
- DisplayTextFormat getDisplayTextFormat() const { return myDTF; }
- void setTextDisplayFormat( DisplayTextFormat theDTF ) { myDTF = theDTF; }
+ void setName( QString name ) { myName = name; }
+ QString getName() const { return myName; }
-protected:
- QString myText;
- float myXPos;
- float myYPos;
- QColor myColor;
- QFont myQFont;
- int mySeparator;
- DisplayTextFormat myDTF;
-};
+ virtual int getPriority() const;
-/***************************************************************************
-** Class: GLViewer_CoordSystem
-** Descr:
-** Module: GLViewer
-** Created: UI team, 02.09.02
-****************************************************************************/
-class GLVIEWER_EXPORT GLViewer_CoordSystem
-{
-public:
- enum CSType { Cartesian, Polar };
-
-private:
- double myX0, myY0; //The coordinates of origin in the reference CS
- double myXUnit, myYUnit; //The lengths of axis units in the reference unit
- double myRotation; //The rotation in radians relative to reference CS
-
- //!!! In the polar CS myYUnit is ignored, but myXUnit is the unit of polar radius
-
- CSType myType;
-
-public:
- GLViewer_CoordSystem( CSType aType, double X0 = 0.0, double Y0 = 0.0,
- double XUnit = 1.0, double YUnit = 1.0,
- double Rotation = 0.0 );
-
- void getOrigin( double& x, double& y ) const;
- void setOrigin( double x, double y );
+ virtual void moveObject( float, float, bool fromGroup = false ) = 0;
+ virtual bool finishMove() { return true; }
- void getUnits( double& x, double& y ) const;
- void setUnits( double x, double y );
+ bool getVisible() const { return myIsVisible; }
+ virtual void setVisible( bool theStatus ) { myIsVisible = theStatus; }
- double getRotation() const;
- void setRotation( double rotation );
+ void setToolTipText( QString str ){ myToolTipText = str; }
+ virtual QString getToolTipText(){ return myToolTipText; }
- CSType getType() const;
- void setType( CSType type );
+ bool isTooTipHTML() const { return isToolTipHTML; }
+ void setToolTipFormat( bool isHTML ) { isToolTipHTML = isHTML; }
- void transform( GLViewer_CoordSystem& aSystem, double& x, double& y );
- //Transform the coordinates x, y from current CS to aSystem
+ virtual QByteArray getByteCopy();
+ virtual bool initializeFromByteCopy( QByteArray );
- virtual void getStretching( GLViewer_CoordSystem& aSystem, double& theX, double& theY );
- //Return how many times line width in aSystem system bigger than in current
+ virtual bool translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS ) = 0;
+ virtual bool translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS ) = 0;
-protected:
- virtual void toReference( double& x, double& y );
- virtual void fromReference( double& x, double& y );
-};
-
-/***************************************************************************
-** Class: GLViewer_Object
-** Descr: OpenGL Object
-** Module: GLViewer
-** Created: UI team, 02.09.02
-****************************************************************************/
-#ifdef WNT
-#include <windows.h>
+#ifdef WIN32
+ virtual bool translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS ) = 0;
#endif
-class GLViewer_Drawer;
-class GLViewer_AspectLine;
-class GLViewer_Owner;
-class GLViewer_Group;
+ GLViewer_Owner* owner() const { return myOwner; }
+ void setOwner( GLViewer_Owner* owner ) { myOwner = owner; }
+
+ void setGroup( GLViewer_Group* );
+ GLViewer_Group* getGroup() const;
-class GLVIEWER_EXPORT GLViewer_Object : public QObject
-{
- Q_OBJECT
+ virtual GLViewer_Object* getOwner() { return this; }
-public:
- GLViewer_Object();
- virtual ~GLViewer_Object();
+ virtual bool isSelectable() { return true; }
+ virtual bool isScalable() { return true; }
- virtual void compute() = 0;
- virtual GLViewer_Drawer* createDrawer() = 0;
- GLViewer_Drawer* getDrawer(){ return myDrawer; }
- virtual void setDrawer( GLViewer_Drawer* theDrawer ) { myDrawer = theDrawer; }
-
- virtual GLboolean highlight( GLfloat x, GLfloat y, GLfloat tol, GLboolean isCircle = GL_FALSE ) = 0;
- virtual GLboolean unhighlight() = 0;
- virtual GLboolean select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect, GLboolean isFull = GL_FALSE,
- GLboolean isCircle = GL_FALSE, GLboolean isShift = GL_FALSE ) = 0;
- virtual GLboolean unselect() = 0;
-
- virtual GLboolean isInside( GLViewer_Rect );
-
- virtual bool portContains( GLViewer_Pnt ) { return false; }
- virtual bool startPulling( GLViewer_Pnt ) { return false; }
- virtual void pull( GLViewer_Pnt, GLViewer_Object* ) {}
- virtual void finishPulling() {}
- virtual bool isPulling() { return false; }
-
- virtual void setRect( GLViewer_Rect* rect) { myRect = rect; }
- virtual GLViewer_Rect* getRect() const { return myRect; }
- virtual GLViewer_Rect* getUpdateRect() = 0;
-
- virtual void setScale( GLfloat xScale, GLfloat yScale ) { myXScale = xScale; myYScale = yScale; }
- virtual void getScale( GLfloat& xScale, GLfloat& yScale ) const { xScale = myXScale; yScale = myYScale;}
-
- virtual GLboolean setZoom( GLfloat zoom, GLboolean = GL_FALSE );
- virtual GLfloat getZoom() const { return myZoom; }
- virtual GLboolean updateZoom( bool zoomIn );
-
- virtual GLboolean isHighlighted() const { return myIsHigh; }
- virtual GLboolean isSelected() const { return myIsSel; }
- virtual void setSelected( GLboolean state ) { myIsSel = state; }
-
- void setGLText( GLViewer_Text* glText ) { myGLText = glText; }
- GLViewer_Text* getGLText() const { return myGLText; }
-
- virtual void setAspectLine ( GLViewer_AspectLine* aspect ) { myAspectLine = aspect; }
- virtual GLViewer_AspectLine* getAspectLine() const { return myAspectLine; }
-
- QString getObjectType() const { return myType; }
-
- void setName( QString name ) { myName = name; }
- QString getName() const { return myName; }
-
- virtual void moveObject( float, float, bool fromGroup = false ) = 0;
- virtual void finishMove() {}
-
- bool getVisible(){ return myIsVisible; }
- void setVisible( bool theStatus ){ myIsVisible = theStatus; }
-
- void setToolTipText( QString str ){ myToolTipText = str; }
- virtual QString getToolTipText(){ return myToolTipText; }
-
- bool isTooTipHTML() const { return isToolTipHTML; }
- void setToolTipFormat( bool isHTML ) { isToolTipHTML = isHTML; }
-
- virtual QByteArray getByteCopy();
- virtual bool initializeFromByteCopy( QByteArray );
-
- virtual bool translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS ) = 0;
- virtual bool translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS ) = 0;
-
-#ifdef WIN32
- virtual bool translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS ) = 0;
-#endif
-
- GLViewer_Owner* owner() const;
- void setOwner( GLViewer_Owner* );
-
- void setGroup( GLViewer_Group* );
- GLViewer_Group* getGroup() const;
-
protected:
- QString myName;
- QString myType;
-
- GLViewer_Rect* myRect;
- GLfloat myXScale;
- GLfloat myYScale;
- GLfloat myXGap;
- GLfloat myYGap;
-
- GLfloat myZoom;
+ QString myName;
+ QString myType;
- GLboolean myIsHigh;
- GLboolean myIsSel;
- GLViewer_Text* myGLText;
+ GLViewer_Rect* myRect;
+ GLViewer_Rect* myUpdateRect;
+ GLViewer_Text* myGLText;
- GLViewer_Drawer* myDrawer;
- GLViewer_AspectLine* myAspectLine;
- QString myToolTipText;
- bool isToolTipHTML;
-
- bool myIsVisible;
- GLViewer_Owner* myOwner;
- GLViewer_Group* myGroup;
-};
+ GLfloat myXScale;
+ GLfloat myYScale;
+ GLfloat myXGap;
+ GLfloat myYGap;
-/***************************************************************************
-** Class: GLViewer_Owner
-** Descr:
-** Module: GLViewer
-** Created: UI team, 15.12.04
-****************************************************************************/
-#include <SUIT_DataOwner.h>
+ GLfloat myZoom;
-class GLVIEWER_EXPORT GLViewer_Owner: public SUIT_DataOwner
-{
-public:
- GLViewer_Owner():SUIT_DataOwner() {};
- ~GLViewer_Owner() {};
+ GLboolean myIsHigh;
+ GLboolean myIsSel;
-public:
- int getIndex() const { return myIndex; }
+ GLViewer_Drawer* myDrawer;
+ GLViewer_AspectLine* myAspectLine;
-protected:
- int myIndex;
-};
+ QString myToolTipText;
+ bool isToolTipHTML;
-/***************************************************************************
-** Class: GLViewer_MarkerSet
-** Descr: OpenGL MarkerSet
-** Module: GLViewer
-** Created: UI team, 03.09.02
-****************************************************************************/
-class GLVIEWER_EXPORT GLViewer_MarkerSet: public GLViewer_Object
-{
- Q_OBJECT
-
-public:
- GLViewer_MarkerSet( int number = 1, float size = 5.0, const QString& toolTip = "GLMarker" );
- ~GLViewer_MarkerSet();
-
- virtual void compute();
- virtual GLViewer_Drawer* createDrawer();
-
- virtual GLboolean highlight( GLfloat x, GLfloat y, GLfloat tol = 15.0, GLboolean isCircle = GL_FALSE );
- virtual GLboolean unhighlight();
- virtual GLboolean select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect, GLboolean isFull = GL_FALSE,
- GLboolean isCircle = GL_FALSE, GLboolean isShift = GL_FALSE );
- virtual GLboolean unselect();
-
- virtual GLViewer_Rect* getUpdateRect();
-
- void setXCoord( GLfloat* xCoord, int size );
- void setYCoord( GLfloat* yCoord, int size );
- GLfloat* getXCoord() const { return myXCoord; }
- GLfloat* getYCoord() const { return myYCoord; }
- void setNumMarkers( GLint );
- GLint getNumMarkers() const { return myNumber; };
-
- void setMarkerSize( const float size ) { myMarkerSize = size; }
- float getMarkerSize() const { return myMarkerSize; }
-
- void exportNumbers( QValueList<int>&, QValueList<int>& , QValueList<int>&, QValueList<int>& );
-
- QValueList<int> getSelectedElements() { return mySelNumbers; }
- bool addOrRemoveSelected( int index );
- void addSelected( const TColStd_SequenceOfInteger& );
- void setSelected( const TColStd_SequenceOfInteger& );
-
- virtual void moveObject( float, float, bool fromGroup = false );
-
- virtual QByteArray getByteCopy();
- virtual bool initializeFromByteCopy( QByteArray );
-
- virtual bool translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
- virtual bool translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );
-
-#ifdef WIN32
- virtual bool translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
-#endif
-
-protected slots:
- void onSelectionDone( bool );
- void onSelectionCancel();
-
-signals:
- void dvMarkersSelected( const TColStd_SequenceOfInteger& );
-
-protected:
- GLint myNumber;
- GLfloat* myXCoord;
- GLfloat* myYCoord;
- GLfloat myMarkerSize;
- QValueList<int> myHNumbers;
- QValueList<int> myUHNumbers;
- QValueList<int> mySelNumbers;
- QValueList<int> myCurSelNumbers;
- QValueList<int> myUSelNumbers;
- QValueList<int> myPrevHNumbers;
- TColStd_SequenceOfInteger mySelectedIndexes;
-};
-
-/***************************************************************************
-** Class: GLViewer_Polyline
-** Descr: OpenGL Polyline
-** Module: GLViewer
-** Created: UI team, 03.09.02
-****************************************************************************/
-class GLVIEWER_EXPORT GLViewer_Polyline: public GLViewer_Object
-{
- Q_OBJECT
-
-public:
- GLViewer_Polyline( int number = 1, float size = 5.0, const QString& toolTip = "GLPolyline" );
- ~GLViewer_Polyline();
-
- virtual void compute();
- virtual GLViewer_Drawer* createDrawer();
-
- virtual GLboolean highlight( GLfloat x, GLfloat y, GLfloat tol = 15.0, GLboolean isCircle = GL_FALSE );
- virtual GLboolean unhighlight();
- virtual GLboolean select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect, GLboolean isFull = GL_FALSE,
- GLboolean isCircle = GL_FALSE, GLboolean isShift = GL_FALSE );
- virtual GLboolean unselect();
-
- virtual GLViewer_Rect* getUpdateRect();
-
- void setXCoord( GLfloat* xCoord, int size );
- void setYCoord( GLfloat* yCoord, int size );
- GLfloat* getXCoord() const { return myXCoord; }
- GLfloat* getYCoord() const { return myYCoord; }
- void setNumber( GLint );
- GLint getNumber() const { return myNumber; };
-
- void setClosed( GLboolean closed ) { myIsClosed = closed; }
- GLboolean isClosed() const { return myIsClosed; }
-
- void setHighSelAll( GLboolean highSelAll ) { myHighSelAll = highSelAll; }
- GLboolean isHighSelAll() const { return myHighSelAll; }
-
- void exportNumbers( QValueList<int>&, QValueList<int>& , QValueList<int>&, QValueList<int>& );
-
- QValueList<int> getSelectedElements() { return mySelNumbers; }
-
- virtual void moveObject( float, float, bool fromGroup = false );
-
- virtual QByteArray getByteCopy();
- virtual bool initializeFromByteCopy( QByteArray );
-
- virtual bool translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
- virtual bool translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );
-
-#ifdef WIN32
- virtual bool translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
-#endif
-
-protected slots:
- void onSelectionDone( bool );
- void onSelectionCancel();
-
-protected:
- GLfloat* myXCoord;
- GLfloat* myYCoord;
- GLint myNumber;
- GLboolean myIsClosed;
- GLboolean myHighSelAll;
-
- QValueList<int> myHNumbers;
- QValueList<int> myUHNumbers;
- QValueList<int> mySelNumbers;
- QValueList<int> myUSelNumbers;
- QValueList<int> myCurSelNumbers;
- QValueList<int> myPrevHNumbers;
- TColStd_SequenceOfInteger mySelectedIndexes;
-
- GLboolean myHighFlag;
-};
+ bool myIsVisible;
-
-/***************************************************************************
-** Class: GLViewer_TextObject
-** Descr: Text as Object for OpenGL
-** Module: GLViewer
-** Created: UI team, 27.02.04
-****************************************************************************/
-class GLVIEWER_EXPORT GLViewer_TextObject : public GLViewer_Object
-{
- Q_OBJECT
-
-public:
- GLViewer_TextObject( const QString&, float xPos = 0, float yPos = 0,
- const QColor& color = QColor( 0, 255, 0 ), const QString& toolTip = "GLText" );
- ~GLViewer_TextObject();
-
- virtual void compute();
- virtual GLViewer_Drawer* createDrawer();
-
- virtual void setDrawer( GLViewer_Drawer* theDrawer );
-
- virtual GLboolean highlight( GLfloat x, GLfloat y, GLfloat tol, GLboolean isCircle = GL_FALSE );
- virtual GLboolean unhighlight();
- virtual GLboolean select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect, GLboolean isFull = GL_FALSE,
- GLboolean isCircle = GL_FALSE, GLboolean isShift = GL_FALSE );
- virtual GLboolean unselect();
-
- virtual GLViewer_Rect* getUpdateRect();
-
- virtual void moveObject( float, float, bool fromGroup = false );
-
- virtual QByteArray getByteCopy();
- virtual bool initializeFromByteCopy( QByteArray );
-
- virtual bool translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
- virtual bool translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );
-
-#ifdef WIN32
- virtual bool translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
-#endif
-
- int getWidth(){ return myWidth; }
- int getHeight(){ return myWidth; }
- void setWidth( int w ){ myWidth=w; }
- void setHeight( int h ){ myHeight=h; }
-
-protected:
- bool myHighFlag;
- int myWidth;
- int myHeight;
+ GLViewer_Owner* myOwner;
+ GLViewer_Group* myGroup;
};
+// Class: GLViewer_Object
+// Descr: OpenGL Object
-/***************************************************************************
-** Class: GLViewer_AspectLine
-** Descr: Substitution of Prs2d_AspectLine for OpenGL
-** Module: GLViewer
-** Created: UI team, 05.11.02
-****************************************************************************/
-class GLVIEWER_EXPORT GLViewer_AspectLine
+class GLVIEWER_API GLViewer_Owner : public SUIT_DataOwner
{
public:
- GLViewer_AspectLine();
- GLViewer_AspectLine( int, float );
- ~GLViewer_AspectLine();
-
- void setLineColors( QColor nc = QColor( 0, 0, 0 ),
- QColor hc = QColor( 0, 255, 255 ),
- QColor sc = QColor( 255, 0, 0 ) );
- int setLineWidth( const float );
- int setLineType( const int );
-
- void getLineColors( QColor&, QColor&, QColor& ) const;
- float getLineWidth() const { return myLineWidth; };
- int getLineType() const { return myLineType; };
-
- QByteArray getByteCopy() const;
-
- static GLViewer_AspectLine* fromByteCopy( QByteArray );
-
+ GLViewer_Owner() : SUIT_DataOwner() {}
+ ~GLViewer_Owner() {}
+
protected:
- QColor myNColor;
- QColor myHColor;
- QColor mySColor;
- float myLineWidth;
- int myLineType; // 0 - normal, 1 - strip (not support in markers)
-};
-/***************************************************************************
-** Class: GLViewer_MimeSource
-** Descr: Needs for a work with QClipboard
-** Module: GLViewer
-** Created: UI team, 22.03.04
-****************************************************************************/
-class GLVIEWER_EXPORT GLViewer_MimeSource: public QMimeSource
-{
-public:
- GLViewer_MimeSource():QMimeSource(){};
- ~GLViewer_MimeSource();
-
- bool setObjects( QValueList<GLViewer_Object*> );
- static QValueList<GLViewer_Object*> getObjects( QByteArray, QString );
- static GLViewer_Object* getObject( QByteArray, QString );
-
- virtual const char* format( int theIndex = 0 ) const;
- virtual QByteArray encodedData( const char* ) const;
-
-private:
- QByteArray myByteArray;
};
#ifdef WNT
#pragma warning ( default:4251 )
#endif
-#endif // GLVIEWER_OBJECT_H
+#endif
** Created: UI team, 22.09.00
*****************************************************************************/
+//#include <GLViewerAfx.h>
#include "GLViewer_Selector.h"
#include "GLViewer_Viewer.h"
class GLViewer_Viewer;
-class GLVIEWER_EXPORT GLViewer_Selector : public QObject
+class GLVIEWER_API GLViewer_Selector : public QObject
{
Q_OBJECT
void setMinRectSize( const QSize& minSize );
virtual void detect( int, int ) = 0;
+ virtual void undetectAll() = 0;
+
virtual void select( bool append = false ) = 0;
virtual void select( const QRect&, bool append = false ) = 0;
virtual void unselectAll() = 0;
void selSelectionDone( bool append, SelectionChangeStatus status );
protected:
+// void setStatus( SelectionChangeStatus theStatus ){ myStatus = theStatus; }
+// SelectionChangeStatus status( return myStatus; }
+
GLViewer_Viewer* myViewer;
bool myLocked;
QSize myMinRectSize;
private:
+// SelectionChangeStatus myStatus;
static int apppendKey;
};
** Created: UI team, 20.09.02
*****************************************************************************/
+//#include <GLViewerAfx.h>
#include "GLViewer_Selector2d.h"
#include "GLViewer_Viewer2d.h"
#include "GLViewer_Context.h"
myGLContext->MoveTo( x, y );
}
+void GLViewer_Selector2d::undetectAll()
+{
+ if ( myLocked || !myGLContext || !myViewer || !myViewer->getActiveView() ||
+ myViewer->getSelectionMode() == GLViewer_Viewer::NoSelection )
+ return;
+
+ GLViewer_ViewPort* vp = myViewer->getActiveView()->getViewPort();
+ if( !vp->inherits( "GLViewer_ViewPort2d" ) )
+ return;
+
+ myGLContext->clearHighlighted();
+}
+
void GLViewer_Selector2d::select( bool append )
{
//cout << "GLViewer_Selector2d : select ( " << (int)append << " )" << endl;
GLViewer_ViewPort* vp = myViewer->getActiveView()->getViewPort();
if( !vp->inherits( "GLViewer_ViewPort2d" ) )
return;
+
int status = myGLContext->Select( append );
checkSelection( selBefore, append, status );
}
GLViewer_ViewPort* vp = myViewer->getActiveView()->getViewPort();
if( !vp->inherits( "GLViewer_ViewPort2d" ) )
return;
+
int aStatus = myGLContext->SelectByRect( selRect, append );
checkSelection( selBefore, append, aStatus );
}
#include "windows.h"
#endif
-//#include "QAD.h"
#include "GLViewer_Selector.h"
#include <Quantity_NameOfColor.hxx>
class GLViewer_Viewer2d;
class GLViewer_Context;
-class GLVIEWER_EXPORT GLViewer_Selector2d : public GLViewer_Selector
+class GLVIEWER_API GLViewer_Selector2d : public GLViewer_Selector
{
Q_OBJECT
void setSelectColor( Quantity_NameOfColor );
void detect( int, int );
+ void undetectAll();
+
void select( bool append = false );
void select( const QRect&, bool append = false );
void unselectAll();
--- /dev/null
+/***************************************************************************
+** Class: GLViewer_Text
+** Descr: Substitution of Prs3d_Text for OpenGL
+** Module: GLViewer
+** Created: UI team, 10.07.03
+****************************************************************************/
+
+//#include <GLViewerAfx.h>
+#include "GLViewer_Text.h"
+
+GLViewer_Text::GLViewer_Text( const QString& text, float xPos, float yPos, const QColor& color )
+{
+ myText = text;
+ myXPos = xPos;
+ myYPos = yPos;
+ myColor = color;
+ myQFont = QFont::defaultFont();
+ mySeparator = 2;
+ myDTF = DTF_BITMAP;
+}
+
+GLViewer_Text::GLViewer_Text( const QString& text, float xPos, float yPos, const QColor& color, QFont theFont, int theSeparator )
+{
+ myText = text;
+ myXPos = xPos;
+ myYPos = yPos;
+ myColor = color;
+ myQFont = theFont;
+ mySeparator = theSeparator;
+ myDTF = DTF_BITMAP;
+}
+
+GLViewer_Text::~GLViewer_Text()
+{
+}
+
+int GLViewer_Text::getWidth()
+{
+ int aResult = 0;
+ QFontMetrics aFM( myQFont );
+ for( uint i = 0; i < myText.length(); i++ )
+ aResult += aFM.width( myText.at(i) ) + mySeparator;
+ return aResult;
+}
+
+int GLViewer_Text::getHeight()
+{
+ QFontMetrics aFM( myQFont );
+ return aFM.height();
+}
+
+QByteArray GLViewer_Text::getByteCopy() const
+{
+ int i;
+ int aSize = 5*sizeof( int ) + myText.length();
+
+ int aR = myColor.red();
+ int aG = myColor.green();
+ int aB = myColor.blue();
+ const char* aStr = myText.data();
+
+ int anISize = sizeof( int );
+ QByteArray aResult( aSize );
+
+ char* aPointer = (char*)&myXPos;
+ for( i = 0; i < anISize; i++, aPointer++ )
+ aResult[i] = *aPointer;
+ aPointer = (char*)&myYPos;
+ for( ; i < 2*anISize; i++, aPointer++ )
+ aResult[i] = *aPointer;
+
+ aPointer = (char*)&aR;
+ for( ; i < 3*anISize; i++, aPointer++ )
+ aResult[i] = *aPointer;
+ aPointer = (char*)&aG;
+ for( ; i < 4*anISize; i++, aPointer++ )
+ aResult[i] = *aPointer;
+ aPointer = (char*)&aB;
+ for( ; i < 5*anISize; i++, aPointer++ )
+ aResult[i] = *aPointer;
+
+ int aTextSize = myText.length();
+ aPointer = (char*)&aTextSize;
+ for( ; i < 6*anISize; i++, aPointer++ )
+ aResult[i] = *aPointer;
+
+ for( i = 0; i < aTextSize; i++ )
+ aResult[6*anISize + i] = aStr[i];
+
+ aPointer = (char*)&mySeparator;
+ for( ; i < 7*anISize + aTextSize; i++, aPointer++ )
+ aResult[i] = *aPointer;
+
+ const char* aFontStr = myQFont.toString().data();
+ int aFontSize = myQFont.toString().length();
+
+ for( i = 0; i < aFontSize; i++ )
+ aResult[7*anISize + aTextSize + i] = aFontStr[i];
+
+ return aResult;
+}
+
+GLViewer_Text* GLViewer_Text::fromByteCopy( QByteArray theBuf )
+{
+ int i = 0;
+ int aSize = (int)theBuf.size();
+ int aR = 0, aG = 0, aB = 0;
+
+ int xPos = 0, yPos = 0;
+
+ int anISize = sizeof( int );
+ char* aPointer = (char*)&xPos;
+ for ( i = 0; i < anISize; i++, aPointer++ )
+ *aPointer = theBuf[i];
+
+ aPointer = (char*)&yPos;
+ for ( ; i < 2*anISize; i++, aPointer++ )
+ *aPointer = theBuf[i];
+
+ aPointer = (char*)&aR;
+ for( ; i < 3*anISize; i++, aPointer++ )
+ *aPointer = theBuf[i];
+ aPointer = (char*)&aG;
+ for( ; i < 4*anISize; i++, aPointer++ )
+ *aPointer = theBuf[i];
+ aPointer = (char*)&aB;
+ for( ; i < 5*anISize; i++, aPointer++ )
+ *aPointer = theBuf[i];
+
+ int aTextSize = 0;
+ aPointer = (char*)&aTextSize;
+ for( ; i < 6*anISize; i++, aPointer++ )
+ *aPointer = theBuf[i];
+
+ QString aText;
+ for( ; i < 6*anISize + aTextSize; i++ )
+ {
+ QChar aChar( theBuf[i] );
+ aText += aChar;
+ }
+
+ int aSeparator = 0;
+ aPointer = (char*)&aSeparator;
+ for( ; i < 7*anISize + aTextSize; i++, aPointer++ )
+ *aPointer = theBuf[i];
+
+ QString aFontStr;
+ for( ; i < aSize; i++ )
+ {
+ QChar aChar( theBuf[i] );
+ aFontStr += aChar;
+ }
+ QFont aFont;
+
+ if( !aFont.fromString( aFontStr ) )
+ return NULL;
+
+ GLViewer_Text* aGlText = new GLViewer_Text( aText, xPos, yPos, QColor( aR,aG,aB ), aFont, aSeparator );
+
+ return aGlText;
+}
--- /dev/null
+// File: GLViewer_Text.h
+// Created: November, 2004
+// Author: OCC team
+// Copyright (C) CEA 2004
+
+#ifndef GLVIEWER_TEXT_H
+#define GLVIEWER_TEXT_H
+
+#ifdef WNT
+#include <windows.h>
+#endif
+
+#include "GLViewer.h"
+#include "GLViewer_Defs.h"
+
+#include <GL/gl.h>
+
+#include <qfont.h>
+#include <qstring.h>
+#include <qcolor.h>
+#include <qfontmetrics.h>
+
+#ifdef WNT
+#pragma warning( disable:4251 )
+#endif
+
+// Class: GLViewer_Text
+// Descr: Substitution of Prs3d_Text for OpenGL
+
+class GLVIEWER_API GLViewer_Text
+{
+public:
+ GLViewer_Text( const QString&, float xPos = 0.0, float yPos = 0.0, const QColor& color = QColor( 0, 255, 0 ) );
+ GLViewer_Text( const QString&, float xPos, float yPos, const QColor& , QFont, int );
+ ~GLViewer_Text();
+
+ void setText( const QString& text ) { myText = text; }
+ QString getText() const { return myText; }
+
+ void setPosition( float xPos, float yPos ) { myXPos = xPos; myYPos = yPos; }
+ void getPosition( float& xPos, float& yPos ) { xPos = myXPos; yPos = myYPos; }
+
+ void setColor( const QColor& color ) { myColor = color; }
+ QColor getColor() const { return myColor; }
+
+ void setFont( const QFont theQFont) { myQFont = theQFont; }
+ QFont getFont() const { return myQFont; }
+
+ int getSeparator(){ return mySeparator; }
+ void setSeparator( int theSep ){ mySeparator = theSep; }
+
+ int getWidth();
+ int getHeight();
+
+ QByteArray getByteCopy() const;
+
+ static GLViewer_Text* fromByteCopy( QByteArray );
+
+ DisplayTextFormat getDisplayTextFormat() const { return myDTF; }
+ void setTextDisplayFormat( DisplayTextFormat theDTF ) { myDTF = theDTF; }
+
+protected:
+ QString myText;
+ float myXPos;
+ float myYPos;
+ QColor myColor;
+ QFont myQFont;
+ int mySeparator;
+ DisplayTextFormat myDTF;
+};
+
+#ifdef WNT
+#pragma warning ( default:4251 )
+#endif
+
+#endif
--- /dev/null
+// File: GLViewer_ToolTip.xx
+// Created: March, 2005
+// Author: OCC team
+// Copyright (C) CEA 2005
+
+//#include "GLViewerAfx.h"
+#include "GLViewer_Context.h"
+#include "GLViewer_ToolTip.h"
+#include "GLViewer_Viewer2d.h"
+#include "GLViewer_ViewPort2d.h"
+
+#include <qlabel.h>
+#include <qtimer.h>
+#include <qbitmap.h>
+#include <qapplication.h>
+#include <qtooltip.h>
+
+/***************************************************************************
+** Class: GLViewer_ToolTip
+** Descr: ToolTip of GLViewer_Objects
+** Module: GLViewer
+** Created: UI team, 25.03.05
+****************************************************************************/
+
+//--------------------------------------------------------------------------
+//Function: GLViewer_ToolTip()
+//Description: constructor
+//--------------------------------------------------------------------------
+GLViewer_ObjectTip::GLViewer_ObjectTip( GLViewer_ViewPort2d* theParent )
+:QObject(),
+ myText(),
+ myPoint( -1, -1 )
+{
+ mypViewPort = theParent;
+ //mypLabel = NULL;
+ mypLabel = new QLabel( "Test", NULL, "ObjectTipText",
+ WStyle_StaysOnTop | WStyle_Customize | WStyle_NoBorder | WStyle_Tool | WX11BypassWM );
+ mypLabel->setMargin( 1 );
+ mypLabel->setAutoMask( FALSE );
+ mypLabel->setFrameStyle( QFrame::Plain | QFrame::Box );
+ mypLabel->setLineWidth( 1 );
+ mypLabel->setAlignment( AlignAuto | AlignTop );
+ mypLabel->setIndent( 0 );
+ mypLabel->polish();
+
+ //mypLabel->setPalette( QToolTip::palette() );
+
+ mypTimer = new QTimer( this );
+
+ connect( mypTimer, SIGNAL( timeout() ), this, SLOT( showTip() ) );
+}
+
+//--------------------------------------------------------------------------
+//Function: GLViewer_ToolTip()
+//Description: destructor
+//--------------------------------------------------------------------------
+GLViewer_ObjectTip::~GLViewer_ObjectTip()
+{
+// delete mypRect;
+ if( mypLabel )
+ delete mypLabel;
+
+ //if( mypPoint )
+ // delete mypPoint;
+
+ //if( mypTimer )
+ // delete mypTimer;
+}
+
+
+//--------------------------------------------------------------------------
+//Function: GLViewer_ToolTip()
+//Description: destructor
+//--------------------------------------------------------------------------
+bool GLViewer_ObjectTip::maybeTip( const QPoint &p )
+{
+
+
+ GLViewer_Context* aContext = ((GLViewer_Viewer2d*)mypViewPort->getViewFrame()->getViewer())->getGLContext();
+
+ /*if( !aContext->currentObjectIsChanged() )
+ return false;
+ else
+ return true;
+ if( myPoint.x() == -1 && myPoint.y() == -1 || aContext->currentObjectIsChanged())
+ {
+ myPoint = p;
+ }
+ else/if( abs(myPoint.y() - p.y()) < 16 )
+ {
+ return;
+ }
+ else // > 16
+ {
+ myPoint = p;
+ }
+*/
+ GLViewer_Object* anObj = aContext->getCurrentObject();
+ if( anObj )
+ {
+ setText( anObj->getName() );
+ return true;
+ }
+
+ return false;
+ /*if( anObj )
+ {
+ //GLViewer_Rect* aRect = anObj->getRect();
+ //QRect aWinRect = mypViewPort->GLV2win( *aRect );
+ tip( QRect( p.x(), p.y(), 1, 1 ), anObj->getName() );
+ //QFontMetrics aFM( font() );
+ //showTip( aWinRect, anObj->getName(), QRect( 0, 0, aFM.width( anObj->getName() + " " ), aFM.height()*1.5 ) );
+ //tip( aWinRect, anObj->getName(), aWinRect( aFM.width( anObj->getName() + " " ), aFM.height()*1.5 ) );
+ }
+// else
+// clear();
+
+ //tip( QRect( 0, 0, mypViewPort->getGLWidget()->width(),mypViewPort->getGLWidget()->height() ) , "test Tool tip" );
+ */
+}
+
+bool GLViewer_ObjectTip::eventFilter( QObject* theObj, QEvent* e )
+{
+ hideTipAndSleep();
+ switch( e->type() )
+ {
+ /*case QEvent::MouseButtonPress:
+ case QEvent::MouseButtonRelease:
+ case QEvent::MouseButtonDblClick:
+ case QEvent::KeyPress:
+ case QEvent::KeyRelease:
+ // input - turn off tool tip mode
+ hideTipAndSleep();
+ break;*/
+ case QEvent::MouseMove:
+ {
+ //hideTipAndSleep();
+ /*if( mypTimer->isActive() )
+ {
+ mypTimer->Stop();
+ wakeUp();
+ }*/
+ QWidget* aWidget = (QWidget*) theObj;
+ if( aWidget == mypViewPort->getGLWidget() )
+ {
+ wakeup();
+ QMouseEvent* m = (QMouseEvent *)e;
+ //if( !mypPoint )
+ // mypPoint = new QPoint();
+
+ myPoint.setX( m->x() );
+ myPoint.setY( m->y() );
+ }
+ }
+ }
+ return false;
+}
+
+
+void GLViewer_ObjectTip::hideTipAndSleep()
+{
+ //if( mypPoint )
+ // delete mypPoint;
+ myPoint.setX(-1);
+ myPoint.setY(-1);
+
+ if( mypLabel )
+ {
+ mypLabel->hide();
+ //delete mypLabel;
+ }
+ mypTimer->stop();
+}
+
+void GLViewer_ObjectTip::showTip()
+{
+ if( maybeTip( myPoint ) )
+ {
+
+ mypLabel->setText( myText );
+ mypLabel->adjustSize( );
+
+ QPoint pos = mypViewPort->getGLWidget()->mapToGlobal( myPoint );
+
+ //mypLabel->show();
+ int cur_height = 24;
+ QCursor* aCursor = QApplication::overrideCursor();
+ if( aCursor )
+ {
+ const QBitmap* aBitmap = aCursor->bitmap();
+ if( aBitmap )
+ cur_height = aBitmap->height();
+ }
+ mypLabel->setGeometry( pos.x(), pos.y() + cur_height, mypLabel->width(), mypLabel->height() );
+ mypLabel->setPalette( QToolTip::palette() );
+
+ mypLabel->show();
+
+ }
+}
+
+void GLViewer_ObjectTip::wakeup( int theTime )
+{
+ if( mypTimer->isActive() )
+ mypTimer->stop();
+ mypTimer->start( theTime );
+}
--- /dev/null
+// File: GLViewer_ToolTip.h
+// Created: March, 2005
+// Author: OCC team
+// Copyright (C) CEA 2005
+
+#ifndef GLVIEWER_TOOLTIP_H
+#define GLVIEWER_TOOLTIP_H
+
+#include "GLViewer.h"
+
+//#include <qtooltip.h>
+//#include <QtxToolTip.h>
+#include <qobject.h>
+
+#define TIP_TIME 1000
+
+class GLViewer_ViewPort2d;
+class QLabel;
+/***************************************************************************
+** Class: GLViewer_ObjectTip
+** Descr: ToolTip of GLViewer_Objects
+** Module: GLViewer
+** Created: UI team, 28.03.05
+****************************************************************************/
+class GLVIEWER_API GLViewer_ObjectTip: public QObject//QToolTip//QtxToolTip
+{
+ Q_OBJECT
+public:
+ GLViewer_ObjectTip( GLViewer_ViewPort2d* );
+ ~GLViewer_ObjectTip();
+
+//protected:
+// virtual void maybeTip( const QPoint& p );
+ virtual bool eventFilter( QObject*, QEvent* );
+
+ virtual bool maybeTip( const QPoint&);
+
+ void setText( const QString& theText ){ myText = theText; }
+ QString getText() const { return myText; }
+
+protected:
+ void timeIsOut();
+
+private:
+
+ void hideTipAndSleep();
+ void wakeup( int mseconds = TIP_TIME );
+
+private slots:
+ void showTip();
+
+private:
+ GLViewer_ViewPort2d* mypViewPort;
+
+ QTimer* mypTimer;
+ QPoint myPoint;
+ QLabel* mypLabel;
+
+ QString myText;
+};
+
+#endif //GLVIEWER_TOOLTIP_H
--- /dev/null
+// File: GLViewer_Tools.cxx
+// Created: April, 2005
+// Author: OCC team
+
+//#include "GLViewerAfx.h"
+#include "GLViewer_Tools.h"
+
+#include <GL/gl.h>
+
+#include <iostream.h>
+
+/****************************************************************************
+** Class: GLViewer_LineList
+** Descr: Tools for distinct line
+** Module: GLViewer
+** Created: UI team, 27.10.05
+*****************************************************************************/
+GLViewer_LineList::GLViewer_LineList( int size )
+{
+ myRealSize = 2*size;
+ mySegmentNumber = 0;
+ myMainCoord = 0.0;
+
+ myArray = new double[myRealSize];
+
+ if( !myArray )
+ {
+ cout << "Can't allocate memory: " << size << endl;
+ myRealSize = 0;
+ }
+ else
+ memset( myArray, 0, myRealSize*sizeof(double) );
+}
+
+GLViewer_LineList::~GLViewer_LineList()
+{
+ delete myArray;
+}
+
+bool GLViewer_LineList::addSegment( double coord1, double coord2 )
+{
+ if( coord1 > coord2 )
+ {
+ double temp = coord1;
+ coord1 = coord2;
+ coord2 = temp;
+ }
+
+ if( 2*mySegmentNumber == myRealSize || !myArray )
+ return false;
+
+ int index = 0;
+ double c1, c2;
+ while( index < mySegmentNumber)
+ {
+ readSegment( index, c1, c2 );
+ if( coord1 < c1 && coord2 < c1 )
+ {
+ for( int i = mySegmentNumber; i > index - 1; i--)
+ {
+ myArray[2*i] = myArray[2*i-2]; //2*(i-1)
+ myArray[2*i+1] = myArray[2*i-1];//2*(i-1)+1
+ }
+ myArray[0] = coord1;
+ myArray[1] = coord2;
+ // mySegmentNumber; what is means ?
+ return true;
+ }
+ else if( coord1 < c1 && coord2 < c2 )
+ {
+ myArray[index*2] = coord1;
+ return true;
+ }
+ else if( c1 < coord1 && coord2 < c2 )
+ {
+ return true;
+ }
+ else if( coord1 < c2 && c2 < coord2 )
+ {
+ if( c1 > coord1 )
+ myArray[2*index] = coord1;
+
+ if( index != mySegmentNumber - 1 )
+ {
+ for( int i = index+1; i < mySegmentNumber; i++ )
+ {
+ if( coord2 < myArray[2*i] )
+ {
+ myArray[2*index+1] = coord2;
+ if( index+1 != i )
+ {
+ for( int j = 0; i+j < mySegmentNumber;j++ )
+ {
+ myArray[2*(index+1+j)] = myArray[2*(i+j)];
+ myArray[2*(index+1+j)+1] = myArray[2*(i+j)+1];
+ }
+ for( int k = 0; k < mySegmentNumber - i; k++ )
+ {
+ myArray[2*(mySegmentNumber - 1- k)] = 0.0;
+ myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
+ }
+ mySegmentNumber -= i - index-1;
+ }
+ return true;
+ }
+ else if( coord2 < myArray[2*i+1] )
+ {
+ myArray[2*index+1] = myArray[2*i+1];
+
+ for( int j = index+1; j < mySegmentNumber-1;j++ )
+ {
+ myArray[2*j] = myArray[2*(i+j-index)];
+ myArray[2*j+1] = myArray[2*(i+j-index)+1];
+ }
+ for( int k = 0; k < mySegmentNumber - i-1; k++ )
+ {
+ myArray[2*(mySegmentNumber - 1- k)] = 0.0;
+ myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
+ }
+ mySegmentNumber -= i - index;
+ return true;
+ }
+ }
+ }
+ else
+ {
+ myArray[2*index+1] = coord2;
+ return true;
+ }
+ }
+ index++;
+ }
+
+ myArray[mySegmentNumber*2] = coord1;
+ myArray[mySegmentNumber*2+1] = coord2;
+ mySegmentNumber++;
+
+ return true;
+}
+
+bool GLViewer_LineList::readSegment( int theIndex, double& coord1, double& coord2 )
+{
+ if( theIndex > mySegmentNumber || !myArray)
+ return false;
+
+ coord1 = myArray[theIndex*2];
+ coord2 = myArray[theIndex*2+1];
+
+ return true;
+}
+
+int GLViewer_LineList::contains( double thePoint ) const
+{
+ if( !myArray || mySegmentNumber == 0 )
+ return -1;
+
+ for( int i = 0; i < mySegmentNumber; i++ )
+ if( myArray[2*i] <= thePoint && thePoint <= myArray[2*i+1] )
+ return i;
+
+ return -1;
+
+}
+
+bool GLViewer_LineList::removeSegment( int theIndex )
+{
+ if( theIndex > mySegmentNumber || !myArray)
+ return false;
+
+ for( int i = theIndex; i < mySegmentNumber; i++ )
+ {
+ myArray[i*2] = myArray[(i+1)*2];
+ myArray[i*2+1] = myArray[(i+1)*2+1];
+ }
+ mySegmentNumber--;
+ myArray[mySegmentNumber*2] = 0.0;
+ myArray[mySegmentNumber*2+1] = 0.0;
+ return true;
+}
+
+bool GLViewer_LineList::removeSegment( double coord1, double coord2 )
+{
+ if( coord1 > coord2 )
+ {
+ double temp = coord1;
+ coord1 = coord2;
+ coord2 = temp;
+ }
+
+ if( 2*mySegmentNumber == myRealSize || !myArray )
+ return false;
+
+ int index = 0;
+ double c1, c2;
+ while( index < mySegmentNumber)
+ {
+ readSegment( index, c1, c2 );
+ if( coord1 < c1 && coord2 < c1 )
+ {
+ //nothing
+ return true;
+ }
+ else if( coord1 < c1 && coord2 < c2 )
+ {
+ myArray[index*2] = coord2;
+ return true;
+ }
+ else if( c1 < coord1 && coord2 < c2 )
+ {
+ if( 2*mySegmentNumber == myRealSize )
+ return false;
+ for( int i = mySegmentNumber; i > index + 1; i-- )
+ {
+ myArray[2*i] = myArray[2*(i-1)];
+ myArray[2*i+1] = myArray[2*(i-1)+1];
+ }
+ myArray[2*(index+1)+1] = myArray[2*index+1];
+ myArray[2*(index+1)] = coord2;
+ myArray[2*index+1] = coord1;
+ mySegmentNumber++;
+ return true;
+ }
+ else if( coord1 < c2 && c2 < coord2 )
+ {
+ if( c1 < coord1 )
+ {
+ myArray[2*index+1] = coord1;
+ }
+
+ if( index != mySegmentNumber - 1 )
+ {
+ for( int i = index+1; i < mySegmentNumber; i++ )
+ {
+ if( coord2 < myArray[2*i] )
+ {
+ if( index+1 != i )
+ {
+ for( int j = 1; i+j-1 < mySegmentNumber;j++ )
+ {
+ myArray[2*(index+j)] = myArray[2*(i+j-1)];
+ myArray[2*(index+j)+1] = myArray[2*(i+j-1)+1];
+ }
+ for( int k = 0; k < mySegmentNumber - i; k++ )
+ {
+ myArray[2*(mySegmentNumber - 1- k)] = 0.0;
+ myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
+ }
+ mySegmentNumber -= i - index -1;
+ }
+ else
+ {
+ if( !(c1 < coord1) )
+ {
+ for( int j = 0; index + j + 1 < mySegmentNumber;j++ )
+ {
+ myArray[2*(index+j)] = myArray[2*(index+j+1)];
+ myArray[2*(index+j)+1] = myArray[2*(index+j+1)+1];
+ }
+
+ myArray[2*(mySegmentNumber - 1)] = 0.0;
+ myArray[2*(mySegmentNumber - 1)+1] = 0.0;
+
+ mySegmentNumber --;
+ }
+
+ }
+
+ return true;
+
+ }
+ else if( coord2 < myArray[2*i+1] )
+ {
+ if( index+1 != i )
+ {
+ if( c1 < coord1 )
+ index++;
+
+ myArray[2*index] = coord2;
+ myArray[2*index+1] = myArray[2*i+1];
+
+ for( int j = 1; i+j < mySegmentNumber;j++ )
+ {
+ myArray[2*(index+j)] = myArray[2*(i+j)];
+ myArray[2*(index+j)+1] = myArray[2*(i+j)+1];
+ }
+ for( int k = 0; k < mySegmentNumber - i - 1; k++ )
+ {
+ myArray[2*(mySegmentNumber - 1- k)] = 0.0;
+ myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
+ }
+ mySegmentNumber -= i - index;
+ }
+ else
+ {
+ if( c1 < coord1 )
+ {
+ myArray[2*(index+1)] = coord2;
+ return true;
+ }
+ else
+ {
+ myArray[2*(index)] = coord2;
+ myArray[2*(index)+1] = myArray[2*(index+1)+1];
+ for( int j = index+1; j < mySegmentNumber-1; j++ )
+ {
+ myArray[2*j] = myArray[2*(j+1)];
+ myArray[2*j+1] = myArray[2*(j+1)+1];
+ }
+ mySegmentNumber--;
+ myArray[2*mySegmentNumber] = 0.0;
+ myArray[2*mySegmentNumber+1] = 0.0;
+ }
+ }
+ return true;
+ }
+ }
+ }
+ else
+ {
+ if( !(c1 < coord1) )
+ {
+ mySegmentNumber--;
+ myArray[2*index] = 0.0;
+ myArray[2*index+1] = 0.0;
+ }
+ }
+ }
+ index++;
+ }
+ return true;
+}
+
+void GLViewer_LineList::clear()
+{
+ if( myArray )
+ memset( myArray, 0, myRealSize*sizeof(double) );
+}
+
+void GLViewer_LineList::print()
+{
+ cout << "MainCoord: " << myMainCoord <<" SIZE: " << myRealSize << " ENum: " << mySegmentNumber << " :::";
+ for( int i = 0; i < mySegmentNumber; i++ )
+ cout << " " << myArray[2*i] << " " << myArray[2*i+1] << " | ";
+
+ cout << endl;
+}
+
+void GLViewer_LineList::show( FieldDim theDim )
+{
+ if( !myArray )
+ return;
+
+ glColor3f( 1.0, 0.0, 1.0 );
+ if( theDim == FD_X )
+ {
+ glBegin( GL_LINES );
+ for( int i = 0; i < mySegmentNumber; i++ )
+ {
+ glVertex2d( myArray[2*i], myMainCoord );
+ glVertex2d( myArray[2*i+1], myMainCoord );
+ }
+ glEnd();
+ }
+ else if( theDim == FD_Y )
+ {
+ glBegin( GL_LINES );
+ for( int i = 0; i < mySegmentNumber; i++ )
+ {
+ glVertex2d( myMainCoord, myArray[2*i] );
+ glVertex2d( myMainCoord, myArray[2*i+1] );
+ }
+ glEnd();
+ }
+}
+
+/****************************************************************************
+** Class: GLViewer_LineField
+** Descr: Tools for solving
+** Module: GLViewer
+** Created: UI team, 27.10.05
+*****************************************************************************/
+GLViewer_LineField::GLViewer_LineField()
+{
+ myCurArrayIndex = 0;
+ myGraphArray1 = NULL;
+ myGraphArray2 = NULL;
+
+ myCurCount = 0;
+
+ myXSize = 0;
+ myYSize = 0;
+ myXLineArray = NULL;
+ myYLineArray = NULL;
+}
+GLViewer_LineField::GLViewer_LineField( const int theMAXSize, const int theXN, const int theYN )
+{
+ myCurArrayIndex = 0;
+ myGraphArray1 = NULL;
+ myGraphArray2 = NULL;
+
+ myCurCount = 0;
+
+ if( theXN <= 0 || theYN <= 0 )
+ {
+ myXSize = 0;
+ myYSize = 0;
+ myXLineArray = NULL;
+ myYLineArray = NULL;
+ }
+ else
+ {
+ myXLineArray = new GLViewer_LineList*[theXN];
+ myYLineArray = new GLViewer_LineList*[theYN];
+
+ for( int i = 0; i < theXN; i++ )
+ myXLineArray[i] = new GLViewer_LineList( theMAXSize );
+
+ for( int j = 0; j < theYN; j++ )
+ myYLineArray[j] = new GLViewer_LineList( theMAXSize );
+
+ myXSize = theXN;
+ myYSize = theYN;
+ }
+}
+
+GLViewer_LineField::~GLViewer_LineField()
+{
+ if( myXLineArray )
+ {
+ for( int i = 0; i < myXSize; i++ )
+ delete myXLineArray[i];
+
+ delete myXLineArray;
+ }
+
+ if( myYLineArray )
+ {
+ for( int j = 0; j < myYSize; j++ )
+ delete myYLineArray[j];
+
+ delete myYLineArray;
+ }
+
+ if( myGraphArray1 )
+ delete myGraphArray1;
+
+ if( myGraphArray2 )
+ delete myGraphArray2;
+}
+
+void GLViewer_LineField::addLine( FieldDim theDim, GLViewer_LineList* )
+{
+ //not implemented
+}
+
+void GLViewer_LineField:: addLine( FieldDim theDim, double theMC, double theBegin, double theEnd )
+{
+ GLViewer_LineList* aLL = new GLViewer_LineList( 1 );
+ aLL->addSegment( theBegin, theEnd );
+ aLL->setMainCoord( theMC );
+ addLine( theDim, aLL );
+}
+
+
+int GLViewer_LineField::insertLine( FieldDim theDim, GLViewer_LineList* theLL, int thePosition )
+{
+ if( !myXLineArray || !myYLineArray )
+ return -1;
+
+ GLViewer_LineList** anArray = getLLArray( theDim );
+ if( !anArray )
+ return -1;
+
+ int size = getDimSize( theDim );
+
+ if( thePosition >= size )
+ return -1;
+ else if( thePosition < 0 )
+ {
+ if( anArray[size-1]->count() != 0 ) // no more space
+ return -1;
+
+ for( int i = 0; i < size; i++ )
+ {
+ if( anArray[i]->count() == 0 )
+ {
+ delete anArray[i];
+ anArray[i] = theLL;
+ return i;
+ }
+
+ double cur_mc = anArray[i]->mainCoord();
+ if( theLL->mainCoord() < cur_mc )
+ {
+ for( int j = 0; j+i+1 < size; j++ )
+ {
+ delete anArray[size-j-1];
+ anArray[size-j-1] = anArray[size-j-2];
+ }
+ delete anArray[i];
+ anArray[i] = theLL;
+ return i;
+ }
+ }
+ }
+ else
+ {
+ delete anArray[thePosition];
+ anArray[thePosition] = theLL;
+ return thePosition;
+ }
+
+ return -1;
+}
+
+int GLViewer_LineField::insertLine( FieldDim theDim, double theMainCoord, double theBegin, double theEnd, int thePosition )
+{
+ GLViewer_LineList* aLL = new GLViewer_LineList( 1 );
+ aLL->addSegment( theBegin, theEnd );
+ aLL->setMainCoord( theMainCoord );
+ return insertLine( theDim, aLL, thePosition );
+}
+
+
+FieldDim GLViewer_LineField::invertDim( FieldDim theFD )
+{
+ if( theFD == FD_X )
+ return FD_Y;
+ else
+ return FD_X;
+}
+
+GLViewer_LineList* GLViewer_LineField::getLine( int theIndex, FieldDim theFD )
+{
+ if( !myXLineArray || !myYLineArray )
+ return NULL;
+
+ if( theFD == FD_X )
+ {
+ if( theIndex > myXSize )
+ return NULL;
+
+ return myXLineArray[theIndex];
+ }
+ else if( theFD == FD_Y )
+ {
+ if( theIndex > myYSize )
+ return NULL;
+
+ return myYLineArray[theIndex];
+ }
+
+ return NULL;
+}
+
+void GLViewer_LineField::setBorders( double X1, double X2, double Y1, double Y2 )
+{
+ if( !myXLineArray || !myYLineArray )
+ return;
+
+ for( int i = 0; i < myXSize; i++ )
+ {
+ myXLineArray[i]->clear();
+ myXLineArray[i]->addSegment( X1, X2 );
+ myXLineArray[i]->setMainCoord( Y1 + (Y2-Y1)*(double(i)/(myXSize-1)) );
+ }
+
+ for( int j = 0; j < myYSize; j++ )
+ {
+ myYLineArray[j]->clear();
+ myYLineArray[j]->addSegment( Y1, Y2 );
+ myYLineArray[j]->setMainCoord( X1 + (X2-X1)*(double(j)/(myYSize-1)) );
+ }
+}
+
+void GLViewer_LineField::addRectangle( double top, double right, double bottom, double left )
+{
+ if( !myXLineArray || !myYLineArray )
+ return;
+ for( int i = 0; i < myXSize; i++ )
+ {
+ double mainCoord = myXLineArray[i]->mainCoord();
+ if( mainCoord < top && mainCoord > bottom )
+ myXLineArray[i]->removeSegment( left, right );
+ }
+
+ for( int j = 0; j < myYSize; j++ )
+ {
+ double mainCoord = myYLineArray[j]->mainCoord();
+ if( mainCoord < right && mainCoord > left )
+ myYLineArray[j]->removeSegment( bottom, top );
+ }
+}
+
+void GLViewer_LineField::print()
+{
+ cout << "My X matrix Number: " << myXSize << endl;
+ for( int i = 0; i < myXSize; i++ )
+ myXLineArray[i]->print();
+
+ cout << "My Y matrix Number: " << myYSize << endl;
+ for( int j = 0; j < myYSize; j++ )
+ myYLineArray[j]->print();
+}
+
+void GLViewer_LineField::show()
+{
+ for( int i = 0; i < myXSize; i++ )
+ getLine( i, FD_X )->show( FD_X );
+
+ for( int j = 0; j < myYSize; j++ )
+ getLine( j, FD_Y )->show( FD_Y );
+ int count = 0;
+ double* anArray = solution( count );
+ glColor3f( 1.0, 0.0, 0.0 );
+ glBegin( GL_LINES );
+ for( int k = 0; k < count; k++ )
+ {
+ glVertex2d( anArray[4*k], anArray[4*k+1] );
+ glVertex2d( anArray[4*k+2], anArray[4*k+3] );
+ }
+ glEnd();
+ delete[] anArray;
+ cout << "Show function" << endl;
+}
+
+int GLViewer_LineField::getDimSize( FieldDim theDim )
+{
+ if( theDim == FD_X )
+ return myXSize;
+ else if( theDim == FD_Y )
+ return myYSize;
+
+ return -1;
+}
+
+int* GLViewer_LineField::intersectIndexes( FieldDim theDim, int theIndex, const GLViewer_LineList* theLL, int& theSize )
+{
+ theSize = 0;
+ if( !myXLineArray || !myYLineArray )
+ return NULL;
+
+ int aDimSize = getDimSize( theDim );
+ int* anArray = new int[aDimSize*2 ];
+
+ for( int i = 0; i < aDimSize; i++ )
+ {
+ GLViewer_LineList* aLL = getLine( i, theDim );
+ int index = aLL->contains( theLL->mainCoord() );
+ if( index != -1 && theLL->contains( aLL->mainCoord() ) == theIndex )
+ {
+ anArray[theSize*2] = i;
+ anArray[theSize*2+1] = index;
+ theSize++;
+ }
+ }
+
+ return anArray;
+}
+
+
+bool GLViewer_LineField::setPoint( FieldPoint thePoint, double theX, double theY )
+{
+ if( !myXLineArray || !myYLineArray )
+ return false;
+
+ int i = -1, j = -1;
+ int xSeg = -1, ySeg = -1;
+ for( i = 0; i < myXSize; i++ )
+ {
+ GLViewer_LineList* aLL = getLine( i, FD_X );
+ if( aLL->mainCoord() == theY )
+ {
+ xSeg = aLL->contains( theX );
+ break;
+ }
+ }
+
+ for( j = 0; j < myYSize; j++ )
+ {
+ GLViewer_LineList* aLL = getLine( j, FD_Y );
+ if( aLL->mainCoord() == theX )
+ {
+ ySeg = aLL->contains( theY );
+ break;
+ }
+ }
+
+ if( xSeg != -1 && ySeg != -1 )
+ {
+ if( thePoint == FP_Start )
+ {
+ myStartPoint.myXLineIndex = i;
+ myStartPoint.myXSegmentIndex = xSeg;
+ myStartPoint.myYLineIndex = j;
+ myStartPoint.myYSegmentIndex = ySeg;
+ myStartPoint.mySolveIndex = -1;
+ }
+ else
+ {
+ myEndPoint.myXLineIndex = i;
+ myEndPoint.myXSegmentIndex = xSeg;
+ myEndPoint.myYLineIndex = j;
+ myEndPoint.myYSegmentIndex = ySeg;
+ myEndPoint.mySolveIndex = -1;
+ }
+ return true;
+ }
+ else
+ return false;
+}
+
+int GLViewer_LineField::segmentNumber()
+{
+ if( !(myXLineArray || myYLineArray) )
+ return -1;
+
+ int aNumber = 0;
+ for( int aDim = 0; aDim < 2; aDim++ )
+ for( int i = 0, n = getDimSize( (FieldDim)aDim ); i < n; i++ )
+ aNumber += getLine( i, (FieldDim)aDim )->count();
+
+ return aNumber;
+}
+
+void GLViewer_LineField::optimize()
+{
+ if( !myXLineArray || !myYLineArray )
+ return;
+
+ for( int aDim = 0; aDim < 2; aDim++ )
+ {
+ for( int i = 0, n = getDimSize( (FieldDim)aDim ); i < n; i++ )
+ {
+ GLViewer_LineList* aLL = getLine( i, (FieldDim)aDim );
+ for( int k =0, aSegNum = aLL->count(); k < aSegNum; k++ )
+ {
+ // int index = i; unused
+ double a1, a2;
+ aLL->readSegment( k, a1, a2 );
+ for( int l = i+1, m = getDimSize( (FieldDim)aDim ); l < m; l++ )
+ {
+ int end = -1;
+ GLViewer_LineList* aCurLL = getLine( l, (FieldDim)aDim );
+ for( int j = 0, count = aCurLL->count(); j < count; j++ )
+ {
+ double c1, c2;
+ aCurLL->readSegment( j, c1, c2 );
+ if( a1 == c1 && a2 == c2 )
+ {
+ if( !(aDim == 0 && myStartPoint.myXLineIndex == l && myStartPoint.myXSegmentIndex == j) &&
+ !(aDim == 0 && myEndPoint.myXLineIndex == l && myEndPoint.myXSegmentIndex == j) &&
+ !(aDim == 1 && myStartPoint.myYLineIndex == l && myStartPoint.myYSegmentIndex == j) &&
+ !(aDim == 1 && myEndPoint.myYLineIndex == l && myEndPoint.myYSegmentIndex == j) )
+ aCurLL->removeSegment( j );
+ end = 0;
+ break;
+ }
+ if( a1 < c1 )
+ {
+ end = 1;
+ break;
+ }
+ }
+ if( end == -1 || end == 1)
+ break;
+ }
+ }
+ }
+ }
+}
+
+void GLViewer_LineField::initialize()
+{
+ if( !myXLineArray || !myYLineArray )
+ return;
+
+ int size = segmentNumber();
+
+ myCurArrayIndex = 0;
+ myCurCount = 0;
+
+ myGraphArray1 = new GraphNode[size];
+ myGraphArray2 = new GraphNode[size];
+
+ int index = 0;
+ bool isXSet = false,
+ isYSet = false;
+ for( int aDim = 0; aDim < 2; aDim++ )
+ {
+ for( int i = 0, n = getDimSize( (FieldDim)aDim ); i < n; i++ )
+ {
+ GLViewer_LineList* aLL = getLine( i, (FieldDim)aDim );
+ for( int k =0, aSegNum = aLL->count(); k < aSegNum; k++ )
+ {
+ myGraphArray1[index].myCount = size;
+ myGraphArray1[index].myDim = (FieldDim)aDim;
+ myGraphArray1[index].myLineIndex = i;
+ myGraphArray1[index].mySegmentindex = k;
+ myGraphArray1[index].prevNodeIndex = -1;
+
+ myGraphArray2[index].myCount = size;
+ myGraphArray2[index].myDim = (FieldDim)aDim;
+ myGraphArray2[index].myLineIndex = i;
+ myGraphArray2[index].mySegmentindex = k;
+ myGraphArray2[index].prevNodeIndex = -1;
+
+ if( !isXSet && aDim == FD_X && myStartPoint.myXLineIndex == i && myStartPoint.myXSegmentIndex == k )
+ {
+ myGraphArray1[index].myCount = 0;
+ isXSet = true;
+ }
+
+ if( aDim == FD_Y && !isYSet && myStartPoint.myYLineIndex == i && myStartPoint.myYSegmentIndex == k )
+ {
+ myGraphArray1[index].myCount = 0;
+ isYSet = true;
+ }
+
+ index++;
+ }
+ }
+ }
+}
+
+void GLViewer_LineField::iteration()
+{
+ int aParam = myCurCount;
+ myCurCount++;
+
+ int* aNodes = findByCount( aParam );
+ GraphNode* aCurArray = getCurArray();
+
+ for( int i = 0; i < aParam; i++ )
+ {
+ GraphNode aCurNode = aCurArray[aNodes[i]];
+ int aSize = 0;
+ int* aInterNodes = intersectIndexes( invertDim( aCurNode.myDim ), aCurNode.mySegmentindex,
+ getLine( aCurNode.myLineIndex, aCurNode.myDim ), aSize );
+ for( int j = 0; j < aSize; j++ )
+ {
+ int index = findBySegment( invertDim( aCurNode.myDim ), aInterNodes[2*j], aInterNodes[2*j+1], false );
+ if( index != -1 )
+ if( aCurArray[index].myCount > myCurCount )
+ {
+ aCurArray[index].myCount = myCurCount;
+ aCurArray[index].prevNodeIndex = aNodes[i];
+ }
+ }
+
+ delete[] aInterNodes;
+ }
+
+ delete[] aNodes;
+}
+
+GLViewer_LineField::IterationStatus GLViewer_LineField::checkComplete()
+{
+ if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
+ return IS_ERROR;
+
+ int count = 0;
+ GraphNode* aCurArray = getCurArray(),
+ * aSecArray = getSecArray();
+
+ for( int i = 0, n = segmentNumber(); i < n; i++ )
+ {
+ if( aCurArray[i].myCount != aSecArray[i].myCount )
+ {
+ if( aCurArray[i].myDim == FD_X &&
+ aCurArray[i].myLineIndex == myEndPoint.myXLineIndex &&
+ aCurArray[i].mySegmentindex == myEndPoint.myXSegmentIndex )
+ {
+ cout << "Algorithm complete X!!!!!!!" << endl;
+ myEndPoint.mySolveIndex = i;
+ return IS_SOLVED;
+ }
+ else if( aCurArray[i].myDim == FD_Y &&
+ aCurArray[i].myLineIndex == myEndPoint.myYLineIndex &&
+ aCurArray[i].mySegmentindex == myEndPoint.myYSegmentIndex )
+ {
+ cout << "Algorithm complete Y!!!!!!!" << endl;
+ myEndPoint.mySolveIndex = i;
+ return IS_SOLVED;
+ }
+ else
+ {
+ count++;
+ aSecArray[i].myCount = aCurArray[i].myCount;
+ aSecArray[i].prevNodeIndex = aCurArray[i].prevNodeIndex;
+ }
+ }
+ }
+
+ if( myCurArrayIndex == 0)
+ myCurArrayIndex = 1;
+ else
+ myCurArrayIndex = 0;
+
+ cout << "Number of ways: " << count << endl;
+ if( count == 0 )
+ return IS_LOOP;
+
+ return IS_NOT_SOLVED;
+}
+
+int* GLViewer_LineField::findByCount( int& theParam )
+{
+ if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
+ return NULL;
+
+ int count = segmentNumber();
+ int* anArray = new int[count];
+ int aSize = 0;
+
+ GraphNode* aCurArray = getCurArray();
+ for( int i = 0; i < count; i++ )
+ {
+ GraphNode aCurNode = aCurArray[i];
+ if( aCurNode.myCount == theParam )
+ {
+ anArray[aSize] = i;
+ aSize++;
+ }
+ }
+
+ theParam = aSize;
+ return anArray;
+}
+
+int GLViewer_LineField::findBySegment( FieldDim theDim, int theLineIndex, int theSegment, bool inCurArray )
+{
+ if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 || getDimSize( theDim ) <= theLineIndex )
+ return -1;
+
+ GraphNode* aCurArray;
+ if( inCurArray )
+ aCurArray = getCurArray();
+ else
+ aCurArray = getSecArray();
+
+ for( int i = 0, n = segmentNumber(); i < n; i++ )
+ {
+ GraphNode aCurNode = aCurArray[i];
+ if( aCurNode.myDim == theDim && aCurNode.myLineIndex == theLineIndex && aCurNode.mySegmentindex == theSegment )
+ return i;
+ }
+
+ return -1;
+}
+
+GLViewer_LineField::EndStatus GLViewer_LineField::startAlgorithm()
+{
+ if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
+ return ES_ERROR;
+
+ while( true )
+ {
+ cout << "-----------Iteration #" << myCurCount << "-------------" << endl;
+ iteration();
+
+ IterationStatus is = checkComplete();
+ if( is == IS_ERROR )
+ return ES_ERROR;
+ else if( is == IS_LOOP )
+ return ES_LOOP;
+ else if( is == IS_SOLVED )
+ return ES_SOLVED;
+ }
+ return ES_SOLVED;
+}
+
+double* GLViewer_LineField::solution( int& theSize )
+{
+ if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
+ return NULL;
+
+ if( myEndPoint.mySolveIndex == -1 )
+ return NULL;
+
+ theSize = myCurCount+1;
+ double* anArray = new double[theSize*4];
+
+ GraphNode* aCurArray = getCurArray();
+
+ int index = myEndPoint.mySolveIndex;
+ for( int i = 0; i <= myCurCount; i++ )
+ {
+ if( index == -1 )
+ break;
+ double c1, c2;
+ GLViewer_LineList* aLL = getLine( aCurArray[index].myLineIndex, aCurArray[index].myDim );
+ aLL->readSegment( aCurArray[index].mySegmentindex, c1, c2 );
+
+ if( aCurArray[index].myDim == FD_X )
+ {
+ anArray[i*4] = c1;
+ anArray[i*4+1] = aLL->mainCoord();
+ anArray[i*4+2] = c2;
+ anArray[i*4+3] = aLL->mainCoord();
+ }
+ else
+ {
+ anArray[i*4] = aLL->mainCoord();
+ anArray[i*4+1] = c1;
+ anArray[i*4+2] = aLL->mainCoord();
+ anArray[i*4+3] = c2;
+ }
+
+ index = aCurArray[index].prevNodeIndex;
+ }
+
+ return anArray;
+}
+
+GraphNode* GLViewer_LineField::getCurArray()
+{
+ if( !myGraphArray1 || !myGraphArray2 )
+ return NULL;
+
+ if( myCurArrayIndex == 0)
+ return myGraphArray1;
+ else
+ return myGraphArray2;
+}
+
+GraphNode* GLViewer_LineField::getSecArray()
+{
+ if( !myGraphArray1 || !myGraphArray2 )
+ return NULL;
+
+ if( myCurArrayIndex == 0)
+ return myGraphArray2;
+ else
+ return myGraphArray1;
+}
+
+int GLViewer_LineField::maxSegmentNum()
+{
+ if( !myXLineArray || !myYLineArray )
+ return -1;
+
+ int max_num = -1;
+ for( int aDim = 0; aDim < 2; aDim++ )
+ {
+ for( int i = 0, n = getDimSize( (FieldDim)aDim ); i < n; i++ )
+ {
+ int count = getLine( i, (FieldDim)aDim )->count();
+ if( count > max_num )
+ max_num = count;
+ }
+ }
+
+ return max_num;
+}
+
+GLViewer_LineList** GLViewer_LineField::getLLArray( FieldDim theDim )
+{
+ if( theDim == FD_X )
+ return myXLineArray;
+ else if( theDim == FD_Y )
+ return myYLineArray;
+ else
+ return NULL;
+}
--- /dev/null
+// File: GLViewer_Tools.h
+// Created: April, 2005
+// Author: OCC team
+
+#ifndef GLVIEWER_TOOLS_H
+#define GLVIEWER_TOOLS_H
+
+#ifdef WNT
+#include "windows.h"
+#endif
+
+#include "GLViewer.h"
+#include "GLViewer_Defs.h"
+
+class GLViewer_LineField;
+
+/****************************************************************************
+** Class: GLViewer_Tools
+** Descr: Tools for Viewer
+** Module: GLViewer
+** Created: UI team, 27.10.05
+*****************************************************************************/
+class GLVIEWER_API GLViewer_Tools
+{
+public:
+ //GLViewer_Tools();
+ //virtual ~GLViewer_Tools();
+ //static
+
+};
+
+enum FieldDim
+{
+ FD_X = 0,
+ FD_Y = 1
+};
+
+/****************************************************************************
+** Class: GLViewer_LineList
+** Descr: Tools for distinct line
+** Module: GLViewer
+** Created: UI team, 27.10.05
+*****************************************************************************/
+class GLViewer_LineList
+{
+public:
+ GLViewer_LineList( int );
+ virtual ~GLViewer_LineList();
+
+ int count() const { return mySegmentNumber; }
+ int size() const { return myRealSize; }
+
+ bool addSegment( double coord1, double coord2 );
+ bool removeSegment( int index );
+ bool removeSegment( double coord1, double coord2 );
+
+ bool readSegment( int index, double&, double& );
+
+ int contains( double thePoint ) const;
+
+ void setMainCoord( double theVal ) { myMainCoord = theVal; }
+ double mainCoord() const { return myMainCoord; }
+
+ void clear();
+ void print();
+
+ void show( FieldDim );
+
+ GLViewer_LineList& operator = ( GLViewer_LineList );
+
+private:
+ double* myArray;
+ int myRealSize;
+ int mySegmentNumber;
+
+ double myMainCoord;
+};
+
+struct GraphNode
+{
+ int myCount;
+ FieldDim myDim;
+ int myLineIndex;
+ int mySegmentindex;
+ int prevNodeIndex; //feedback for searching for solution
+};
+
+struct SearchPoint
+{
+ int myXLineIndex;
+ int myXSegmentIndex;
+ int myYLineIndex;
+ int myYSegmentIndex;
+ int mySolveIndex;
+};
+
+/****************************************************************************
+** Class: GLViewer_LineField
+** Descr: Tools for solving
+** Module: GLViewer
+** Created: UI team, 27.10.05
+*****************************************************************************/
+class GLViewer_LineField
+{
+public:
+ enum FieldPoint
+ {
+ FP_Start = 0,
+ FP_End = 1
+ };
+
+ enum IterationStatus
+ {
+ IS_ERROR = 0,
+ IS_LOOP,
+ IS_NOT_SOLVED,
+ IS_SOLVED
+ };
+
+ enum EndStatus
+ {
+ ES_ERROR = 0,
+ ES_LOOP,
+ ES_SOLVED
+ };
+
+ GLViewer_LineField();
+ GLViewer_LineField( const int theMAXSize, const int xn, const int yn );
+ virtual ~GLViewer_LineField();
+
+ //best way, if line is already sorted
+ void addLine( FieldDim, GLViewer_LineList* );
+ void addLine( FieldDim theDim, double theMC, double theBegin, double theEnd );
+// void addLine( FieldDim, double theMainCoord, double theBegin, double theEnd ):
+
+ int insertLine( FieldDim theDim, GLViewer_LineList*, int thePosition ); // return position
+ int insertLine( FieldDim theDim, double theMC, double theBegin, double theEnd, int thePosition ); // return position
+
+ static FieldDim invertDim( FieldDim );
+
+ GLViewer_LineList* getLine( int index, FieldDim );
+
+ void setBorders( double X1, double X2, double Y1, double Y2 );
+ void addRectangle( double top, double right, double bottom, double left );
+
+ int* intersectIndexes( FieldDim theDim, int theIndex, const GLViewer_LineList* theLL , int& theSize );
+
+ void print();
+
+ void show();
+
+ int getDimSize( FieldDim );
+ int segmentNumber();
+
+ bool setPoint( FieldPoint, double, double );
+
+ void optimize();
+ void initialize();//needs call setPoint before
+ EndStatus startAlgorithm();//main method
+
+ double* solution( int& );
+
+protected:
+ void iteration();
+ IterationStatus checkComplete();
+
+ int* findByCount( int& theParam );
+ int findBySegment( FieldDim, int, int, bool inCurArray = true );
+
+ GraphNode* getCurArray();
+ GraphNode* getSecArray();
+
+ int maxSegmentNum();
+
+ GLViewer_LineList** getLLArray( FieldDim );
+
+private:
+ GLViewer_LineList** myXLineArray,
+ ** myYLineArray;
+
+ int myXSize,
+ myYSize;
+
+ GraphNode* myGraphArray1,
+ * myGraphArray2;
+ int myCurArrayIndex;
+
+ SearchPoint myStartPoint,
+ myEndPoint;
+ int myCurCount;
+};
+
+#endif //GLVIEWER_TOOLS_H
** Created: UI team, 05.09.00
****************************************************************************/
+//#include <GLViewerAfx.h>
#include "GLViewer_ViewFrame.h"
-
#include "GLViewer_Viewer.h"
#include "GLViewer_Viewer2d.h"
#include "GLViewer_ViewPort2d.h"
#include <SUIT_Desktop.h>
-#include <SUIT_Application.h>
#include <SUIT_Session.h>
#include <SUIT_ToolButton.h>
#include <SUIT_ResourceMgr.h>
-#include <SUIT_Tools.h>
-#include <QtxAction.h>
#include <SUIT_MessageBox.h>
#include <qcolor.h>
+#include <qfiledialog.h>
#include <qimage.h>
#include <qlayout.h>
#include <qstring.h>
//================================================================
void GLViewer_ViewFrame::createActions()
{
- if ( !myActionsMap.isEmpty() )
- return;
-
- QtxAction* aAction;
+ if (!myActionsMap.isEmpty()) return;
SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+ QAction* aAction;
// Dump view
- aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_DUMP" ) ),
+ aAction = new QAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_DUMP" ) ),
tr( "MNU_DUMP_VIEW" ), 0, this);
aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
- connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView()));
+ connect(aAction, SIGNAL(activated()), this, SLOT(onViewDump()));
myActionsMap[ DumpId ] = aAction;
// FitAll
- aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_FITALL" ) ),
+ aAction = new QAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_FITALL" ) ),
tr( "MNU_FITALL" ), 0, this);
aAction->setStatusTip(tr("DSC_FITALL"));
connect(aAction, SIGNAL(activated()), this, SLOT(onViewFitAll()));
myActionsMap[ FitAllId ] = aAction;
// FitRect
- aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_FITAREA" ) ),
+ aAction = new QAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_FITAREA" ) ),
tr( "MNU_FITRECT" ), 0, this);
aAction->setStatusTip(tr("DSC_FITRECT"));
connect(aAction, SIGNAL(activated()), this, SLOT(onViewFitArea()));
myActionsMap[ FitRectId ] = aAction;
// FitSelect
- aAction = new QtxAction(tr("MNU_FITSELECT"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_FITSELECT" ) ),
- tr( "MNU_FITSELECT" ), 0, this);
+ aAction = new QAction(tr("MNU_FITSELECT"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_FITSELECT" ) ),
+ tr( "MNU_FITSELECT" ), 0, this);
aAction->setStatusTip(tr("DSC_FITSELECT"));
connect(aAction, SIGNAL(activated()), this, SLOT(onViewFitSelect()));
myActionsMap[ FitSelectId ] = aAction;
// Zoom
- aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_ZOOM" ) ),
+ aAction = new QAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_ZOOM" ) ),
tr( "MNU_ZOOM_VIEW" ), 0, this);
aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
connect(aAction, SIGNAL(activated()), this, SLOT(onViewZoom()));
myActionsMap[ ZoomId ] = aAction;
// Panning
- aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_PAN" ) ),
+ aAction = new QAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_PAN" ) ),
tr( "MNU_PAN_VIEW" ), 0, this);
aAction->setStatusTip(tr("DSC_PAN_VIEW"));
connect(aAction, SIGNAL(activated()), this, SLOT(onViewPan()));
myActionsMap[ PanId ] = aAction;
// Global Panning
- aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_GLOBALPAN" ) ),
+ aAction = new QAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_GLOBALPAN" ) ),
tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
connect(aAction, SIGNAL(activated()), this, SLOT(onViewGlobalPan()));
myActionsMap[ GlobalPanId ] = aAction;
- aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_RESET" ) ),
+ aAction = new QAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_RESET" ) ),
tr( "MNU_RESET_VIEW" ), 0, this);
aAction->setStatusTip(tr("DSC_RESET_VIEW"));
connect(aAction, SIGNAL(activated()), this, SLOT(onViewReset()));
disconnect( myVP, SIGNAL( vpDrawExternal( QPainter* ) ), this, SIGNAL( vfDrawExternal( QPainter* ) ) );
disconnect( myVP, SIGNAL( vpMouseEvent( QMouseEvent* ) ), this, SLOT( mouseEvent( QMouseEvent* ) ) );
disconnect( myVP, SIGNAL( vpKeyEvent( QKeyEvent* ) ), this, SLOT( keyEvent( QKeyEvent* ) ) );
- disconnect( myVP, SIGNAL(contextMenuRequested( QContextMenuEvent * )),
- this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) );
disconnect( myVP, SIGNAL( vpWheelEvent( QWheelEvent* ) ), this, SLOT( wheelEvent( QWheelEvent* ) ) );
+ disconnect( myVP, SIGNAL( contextMenuRequested( QContextMenuEvent* ) ),
+ this, SIGNAL( contextMenuRequested( QContextMenuEvent* ) ) );
}
myVP = vp;
if ( myVP )
connect( myVP, SIGNAL( vpDrawExternal( QPainter* ) ), this, SIGNAL( vfDrawExternal( QPainter* ) ) );
connect( myVP, SIGNAL( vpMouseEvent( QMouseEvent* ) ), this, SLOT( mouseEvent( QMouseEvent* ) ) );
connect( myVP, SIGNAL( vpKeyEvent( QKeyEvent* ) ), this, SLOT( keyEvent( QKeyEvent* ) ) );
- connect( myVP, SIGNAL(contextMenuRequested( QContextMenuEvent * )),
- this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) );
connect( myVP, SIGNAL( vpWheelEvent( QWheelEvent* ) ), this, SLOT( wheelEvent( QWheelEvent* ) ) );
+ connect( myVP, SIGNAL( contextMenuRequested( QContextMenuEvent* ) ),
+ this, SIGNAL( contextMenuRequested( QContextMenuEvent* ) ) );
}
}
{
}
-QImage GLViewer_ViewFrame::dumpView()
+//#include <windows.h>
+
+void GLViewer_ViewFrame::onViewDump()
{
GLViewer_Widget* aWidget = ((GLViewer_ViewPort2d*)myVP)->getGLWidget();
int width, height;
}
delete [] imageBits;
- return anImage;
+
+ QString aFilter( "*.bmp\n*.png" );
+
+ QFileDialog aFileDlg( QDir::current().absPath(), aFilter, this );
+ aFileDlg.setCaption( tr( "DUMP_VIEW_SAVE_FILE_DLG_CAPTION" ) );
+ aFileDlg.setMode( QFileDialog::AnyFile );
+
+ if( !aFileDlg.exec() )
+ return;
+
+ QString aFileName = aFileDlg.selectedFile();
+ QString aFileExt = aFileDlg.selectedFilter();
+
+ if( aFileName.isEmpty() )
+ {
+ SUIT_MessageBox::error1( this,
+ tr( "DUMP_VIEW_ERROR_DLG_CAPTION" ),
+ tr( "DUMP_VIEW_ERROR_DLG_TEXT" ),
+ tr( "BUT_OK" ) );
+ }
+
+ QString aSaveOp = "BMP";
+ QString aTypedFileExt = QFileInfo( aFileName ).extension( false ).lower();
+
+ if( aFileExt == "*.bmp" )
+ {
+ if( aTypedFileExt.isEmpty() )
+ aFileName += ".bmp";
+ aSaveOp = "BMP";
+ }
+ else if( aFileExt == "*.png" )
+ if( aTypedFileExt.isEmpty() )
+ aFileName += ".png";
+ aSaveOp = "PNG";
+
+//#ifdef WNT
+// if( !anImage.save( aFileName, aSaveOp ) )
+//#else
+ if( !aWidget->grabFrameBuffer().save( aFileName, aSaveOp ) )
+//#endif
+ {
+ SUIT_MessageBox::error1( this,
+ tr( "DUMP_VIEW_ERROR_DLG_CAPTION" ),
+ tr( "DUMP_VIEW_ERROR_DLG_TEXT" ),
+ tr( "BUT_OK" ) );
+ }
}
void GLViewer_ViewFrame::onViewPan()
break;
}
}
-
class QColor;
class SUIT_Desktop;
-class QtxAction;
+
class GLViewer_Viewer;
class GLViewer_ViewPort;
+#include <qaction.h>
+
#ifdef WNT
#pragma warning( disable:4251 )
#endif
-class GLVIEWER_EXPORT GLViewer_ViewFrame: public SUIT_ViewWindow
+class GLVIEWER_API GLViewer_ViewFrame: public SUIT_ViewWindow
{
Q_OBJECT
GLViewer_Viewer* myViewer;
GLViewer_ViewPort* myVP;
-protected:
- QImage dumpView();
-
public:
//ViewType getTypeView() const { return VIEW_GL; };
QWidget* getViewWidget() { return ( QWidget* )getViewPort(); };
protected slots:
+ void onViewDump();
void onViewPan();
void onViewZoom();
void onViewFitAll();
private:
enum { DumpId, FitAllId, FitRectId, FitSelectId, ZoomId, PanId, GlobalPanId, ResetId };
- typedef QMap<int, QtxAction*> ActionsMap;
+ typedef QMap<int, QAction*> ActionsMap;
private:
ActionsMap myActionsMap;
// Author: OCC team
// Copyright (C) CEA 2004
-
+//#include <GLViewerAfx.h>
#include "GLViewer_ViewManager.h"
#include "GLViewer_ViewFrame.h"
#include "GLViewer_Viewer2d.h"
int GLViewer_ViewManager::myMaxId = 0;
//***************************************************************
-GLViewer_ViewManager::GLViewer_ViewManager( SUIT_Study* aStudy,
- SUIT_Desktop* theDesktop )
-: SUIT_ViewManager( aStudy, theDesktop )
+GLViewer_ViewManager::GLViewer_ViewManager( SUIT_Study* theStudy, SUIT_Desktop* theDesktop )
+: SUIT_ViewManager( theStudy, theDesktop )
{
myId = ++myMaxId;
setViewModel( new GLViewer_Viewer2d( "GLViewer" ) );
class SUIT_Desktop;
-class GLVIEWER_EXPORT GLViewer_ViewManager : public SUIT_ViewManager
+class GLVIEWER_API GLViewer_ViewManager : public SUIT_ViewManager
{
- Q_OBJECT
-
+ Q_OBJECT
public:
- GLViewer_ViewManager( SUIT_Study*, SUIT_Desktop* );
- ~GLViewer_ViewManager();
+ GLViewer_ViewManager( SUIT_Study* theStudy, SUIT_Desktop* theDesktop );
+ ~GLViewer_ViewManager();
+
+ GLViewer_Viewer* getGLViewer() { return (GLViewer_Viewer*) myViewModel; }
- GLViewer_Viewer* getGLViewer() { return (GLViewer_Viewer*) myViewModel; }
-
- virtual void contextMenuPopup( QPopupMenu* );
+ virtual void contextMenuPopup( QPopupMenu* );
protected:
- void setViewName(SUIT_ViewWindow* theView);
+ void setViewName(SUIT_ViewWindow* theView);
protected:
- static int myMaxId;
- int myId;
+ static int myMaxId;
+ int myId;
};
#endif // GLVIEWER_VIEWMANAGER_H
** Created: UI team, 05.09.00
****************************************************************************/
+//#include <GLViewerAfx.h>
+
#if !defined WNT
#define QT_CLEAN_NAMESPACE /* avoid definition of INT32 and INT8 */
#endif
panCursor = new QCursor( SizeAllCursor );
SUIT_ResourceMgr* rmgr = SUIT_Session::session()->resourceMgr();
- zoomCursor = new QCursor( rmgr->loadPixmap( "GLViewer", tr( "ICON_CURSOR_ZOOM" ) ) );
- rotCursor = new QCursor( rmgr->loadPixmap( "GLViewer", tr( "ICON_CURSOR_ROTATE" ) ) );
- sketchCursor = new QCursor( rmgr->loadPixmap( "GLViewer", tr( "ICON_CURSOR_SKETCH" ) ) );
+ zoomCursor = new QCursor( rmgr->loadPixmap( "GLViewer", tr( "ICON_GL_CURSOR_ZOOM" ) ) );
+ rotCursor = new QCursor( rmgr->loadPixmap( "GLViewer", tr( "ICON_GL_CURSOR_ROTATE" ) ) );
+ sketchCursor = new QCursor( rmgr->loadPixmap( "GLViewer", tr( "ICON_GL_CURSOR_SKETCH" ) ) );
}
/*!
setMouseTracking( true );
setBackgroundMode( NoBackground );
- // set focus policy to threat QContextMenuEvent from keyboard
+
setFocusPolicy( StrongFocus );
}
if ( x11Display() )
{
/* Initialization with the default VisualID */
- Visual *v = DefaultVisual( x11Display(), DefaultScreen( x11Display() ) );
- /*int visualID = */XVisualIDFromVisual( v );
+ //Visual *v = DefaultVisual( x11Display(), DefaultScreen( x11Display() ) );
+ // int visualID = XVisualIDFromVisual( v ); unused
/* Here we use the settings from Optimizer_ViewInfo::TxglCreateWindow() */
int visualAttr[] = { GLX_RGBA, GLX_DEPTH_SIZE, 1, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1,
{
}
-/*!
- Creates the popup. [ virtual protected ]
-*/
-void GLViewer_ViewPort::onCreatePopup( QPopupMenu* popup )
-{
-/*
- if ( popup )
- {
- if( myPopupActions.isEmpty() )
- return;
- QAction* a = new QAction( "", tr( "MEN_VP_CHANGEBGR" ), 0, this );
- a->setStatusTip( tr( "PRP_VP_CHANGEBGR" ) );
- connect( a, SIGNAL( activated() ), SLOT( onChangeBgColor() ) );
- myPopupActions.append( a );
- a->addTo( popup );
- }
-*/
-}
-
-/*!
- Destroys the popup. [ virtual protected ]
-*/
-void GLViewer_ViewPort::onDestroyPopup( QPopupMenu* popup )
-{
-/*
- if ( popup )
- {
- for ( QAction* a = myPopupActions.first(); a; a = myPopupActions.next() )
- a->removeFrom( popup );
- myPopupActions.clear();
- }
-*/
-}
-
/*!
Sets the background color with color selection dialog. [ virtual protected slot ]
*/
setBackgroundColor( selColor );
}
-
-//****************************************************************
-void GLViewer_ViewPort::contextMenuEvent ( QContextMenuEvent * e )
+void GLViewer_ViewPort::contextMenuEvent( QContextMenuEvent* e )
{
//if ( e->reason() != QContextMenuEvent::Mouse )
emit contextMenuRequested( e );
BS_Dragging = 0x0004
};
-class GLVIEWER_EXPORT GLViewer_ViewPort: public QWidget//, public QAD_PopupServer
+class GLVIEWER_API GLViewer_ViewPort: public QWidget
{
Q_OBJECT
friend class GLViewer_ViewSketcher;
virtual void fitSelect() = 0;
virtual void fitAll( bool keepScale = false, bool withZ = true ) = 0;
-// POPUP
- virtual void onCreatePopup() {}
- virtual void onCreatePopup( QPopupMenu* );
- virtual void onDestroyPopup( QPopupMenu* );
-
protected slots:
virtual void onChangeBgColor();
void vpMouseEvent( QMouseEvent* );
void vpWheelEvent( QWheelEvent* );
void vpDrawExternal( QPainter* );
- void contextMenuRequested( QContextMenuEvent *e );
+
+ void contextMenuRequested( QContextMenuEvent* );
private:
void initialize();
/* GLViewer_ViewPort2d Source File */
+//#include <GLViewerAfx.h>
#include "GLViewer_ViewPort2d.h"
#include "GLViewer_Viewer2d.h"
#include "GLViewer_ViewFrame.h"
+#include "GLViewer_MimeSource.h"
#include "GLViewer_Context.h"
-#include "GLViewer_Object.h"
-#include "QtxToolTip.h"
+#include "GLViewer_Compass.h"
+#include "GLViewer_Grid.h"
-//#include "QAD_Desktop.h"
-
-#include <Precision.hxx>
-
-#include <cmath>
-using namespace std;
-//#include <math.h>
-//#include <stdlib.h>
-//#include <iostream.h>
+#include <QtxToolTip.h>
+#include <qlayout.h>
#include <qevent.h>
#include <qrect.h>
-#include <qlayout.h>
#include <qpopupmenu.h>
-#include <qimage.h>
#include <qtooltip.h>
#include <qapplication.h>
#include <qclipboard.h>
#include <qpainter.h>
#include <qbitmap.h>
+#include <qlabel.h>
-/***************************************************************************
-** Class: GLViewer_RectangularGrid
-** Descr: OpenGL Grid for GLViewer_ViewPort2d
-** Module: GLViewer
-** Created: UI team, 16.09.02
-****************************************************************************/
-
-#define SEGMENTS 20
-#define STEP 2*PI/SEGMENTS
-#define XSIZE 100
-#define YSIZE 100
-#define MIN_SIZE 1
-
-GLViewer_RectangularGrid::GLViewer_RectangularGrid() :
- myGridList( -1 ), myGridHeight( (GLfloat)0.0 ), myGridWidth( (GLfloat)0.0 ),
- myWinW( (GLfloat)0.0 ), myWinH( (GLfloat)0.0 ), myXSize( (GLfloat)0.0 ), myYSize( (GLfloat)0.0 ),
- myXPan( (GLfloat)0.0 ), myYPan( (GLfloat)0.0 ), myXScale( (GLfloat)1.0 ), myYScale( (GLfloat)1.0 ),
- myLineWidth( (GLfloat)0.05 ), myCenterWidth( (GLfloat)1.5 ), myCenterRadius( (GLint)5.0 ),
- myScaleFactor( 10 ), myIsUpdate( GL_FALSE )
-{
- myGridColor[0] = 0.5;
- myGridColor[1] = 0.5;
- myGridColor[2] = 0.5;
- myAxisColor[0] = 0.75;
- myAxisColor[1] = 0.75;
- myAxisColor[2] = 0.75;
-}
-
-GLViewer_RectangularGrid::GLViewer_RectangularGrid( GLfloat width, GLfloat height,
- GLfloat winW, GLfloat winH,
- GLfloat xSize, GLfloat ySize,
- GLfloat xPan, GLfloat yPan,
- GLfloat xScale, GLfloat yScale ) :
- myGridList( -1 ), myGridHeight( (GLfloat)0.0 ), myGridWidth( (GLfloat)0.0 ),
- myWinW( (GLfloat)0.0 ), myWinH( (GLfloat)0.0 ), myXSize( (GLfloat)0.0 ), myYSize( (GLfloat)0.0 ),
- myXPan( (GLfloat)0.0 ), myYPan( (GLfloat)0.0 ), myXScale( (GLfloat)1.0 ), myYScale( (GLfloat)1.0 ),
- myLineWidth( (GLfloat)0.05 ), myCenterWidth( (GLfloat)1.5 ), myCenterRadius( (GLint)5.0 ),
- myScaleFactor( 10 ), myIsUpdate( GL_FALSE )
-{
- myGridColor[0] = 0.5;
- myGridColor[1] = 0.5;
- myGridColor[2] = 0.5;
- myAxisColor[0] = 0.75;
- myAxisColor[1] = 0.75;
- myAxisColor[2] = 0.75;
-}
-
-GLViewer_RectangularGrid::~GLViewer_RectangularGrid()
-{
-}
-
-void GLViewer_RectangularGrid::draw()
-{
- if ( myGridList == -1 || myIsUpdate )
- initList();
-
- glCallList( myGridList );
-}
-
-void GLViewer_RectangularGrid::setGridColor( GLfloat r, GLfloat g, GLfloat b )
-{
- if( myGridColor[0] == r && myGridColor[1] == g && myGridColor[2] == b )
- return;
-
- myGridColor[0] = r;
- myGridColor[1] = g;
- myGridColor[2] = b;
- myIsUpdate = GL_TRUE;
-}
-
-void GLViewer_RectangularGrid::setAxisColor( GLfloat r, GLfloat g, GLfloat b )
-{
- if( myAxisColor[0] == r && myAxisColor[1] == g && myAxisColor[2] == b )
- return;
-
- myAxisColor[0] = r;
- myAxisColor[1] = g;
- myAxisColor[2] = b;
- myIsUpdate = GL_TRUE;
-}
-
-void GLViewer_RectangularGrid::setGridWidth( float w )
-{
- if( myGridWidth == w )
- return;
-
- myGridWidth = w;
- myIsUpdate = GL_TRUE;
-}
-
-void GLViewer_RectangularGrid::setCenterRadius( int r )
-{
- if( myCenterRadius == r )
- return;
-
- myCenterRadius = r;
- myIsUpdate = GL_TRUE;
-}
-
-void GLViewer_RectangularGrid::setSize( float xSize, float ySize )
-{
- if( myXSize == xSize && myYSize == ySize )
- return;
-
- myXSize = xSize;
- myYSize = ySize;
- myIsUpdate = GL_TRUE;
-}
-
-void GLViewer_RectangularGrid::setPan( float xPan, float yPan )
-{
- if( myXPan == xPan && myYPan == yPan )
- return;
-
- myXPan = xPan;
- myYPan = yPan;
- myIsUpdate = GL_TRUE;
-}
-
-bool GLViewer_RectangularGrid::setZoom( float zoom )
-{
- if( zoom == 1.0 )
- return true;
-
- //backup values
- float bXScale = myXScale;
- float bYScale = myYScale;
-
- myXScale /= zoom;
- myYScale /= zoom;
-
- if( fabs(myXScale) < Precision::Confusion() || fabs(myYScale) < Precision::Confusion() )
- { //undo
- myXScale = bXScale;
- myYScale = bYScale;
- return false;
- }
-
- myGridWidth /= zoom;
- myGridHeight /= zoom;
- myIsUpdate = GL_TRUE;
- return true;
-}
-
-void GLViewer_RectangularGrid::setResize( float WinW, float WinH, float zoom )
-{
- if( myWinW == WinW && myWinH == WinH && zoom == 1.0 )
- return;
-
- myGridWidth = myGridWidth + ( WinW - myWinW ) * myXScale;
- myGridHeight = myGridHeight + ( WinH - myWinH ) * myYScale;
- myWinW = WinW;
- myWinH = WinH;
- setZoom( zoom );
- myIsUpdate = GL_TRUE;
-}
-
-void GLViewer_RectangularGrid::getSize( float& xSize, float& ySize ) const
-{
- xSize = myXSize;
- ySize = myYSize;
-}
+#define WIDTH 640
+#define HEIGHT 480
+#define MARGIN 100
-void GLViewer_RectangularGrid::getPan( float& xPan, float& yPan ) const
-{
- xPan = myXPan;
- yPan = myYPan;
-}
-
-void GLViewer_RectangularGrid::getScale( float& xScale, float& yScale ) const
-{
- xScale = myXScale;
- yScale = myYScale;
-}
-
-bool GLViewer_RectangularGrid::initList()
-{
- myIsUpdate = GL_FALSE;
- int n, m;
- float xLoc, yLoc;
- int xLoc1, yLoc1;
-
- if( myXSize == (GLfloat)0.0 )
- myXSize = (GLfloat)0.1;
- if( myYSize == (GLfloat)0.0 )
- myYSize = (GLfloat)0.1;
-
-label:
- if( ( myXSize >= myGridWidth/5 ) && ( myYSize >= myGridHeight/5 ) )
- { //zoom in
- myXSize /= myScaleFactor;
- myYSize /= myScaleFactor;
- goto label;
- }
- else if( ( myXSize * myScaleFactor < myGridWidth/5 )
- || ( myYSize * myScaleFactor < myGridHeight/5 ) )
- { //zoom out
- myXSize *= myScaleFactor;
- myYSize *= myScaleFactor;
- goto label;
- }
-
- n = ( int )( myGridWidth / myXSize );
- m = ( int )( myGridHeight / myYSize );
-
- if( ( n != 0 ) || ( m != 0 ) )
- {
- if ( myGridList != -1 )
- {
- glDeleteLists( myGridList, 1 );
- if ( glGetError() != GL_NO_ERROR )
- return FALSE;
- }
-
- xLoc1 = ( int )( myXPan / myXSize );
- yLoc1 = ( int )( myYPan / myYSize );
-
- xLoc = xLoc1 * myXSize;
- yLoc = yLoc1 * myYSize;
-
- myGridList = glGenLists( 1 );
- glNewList( myGridList, GL_COMPILE );
-
- glColor3f( myGridColor[0], myGridColor[1], myGridColor[2] );
- glLineWidth( myLineWidth );
-
- glBegin( GL_LINES );
- for( int j = 0; ( j-1 ) * myXSize <= myGridWidth / 2 ; j++ )
- {
- glVertex2d( -myXSize * j - xLoc, -myGridHeight / 2 - myYSize - yLoc );
- glVertex2d( -myXSize * j - xLoc, myGridHeight / 2 + myYSize - yLoc );
- glVertex2d( myXSize * j - xLoc, -myGridHeight / 2 - myYSize - yLoc );
- glVertex2d( myXSize * j - xLoc, myGridHeight / 2 + myYSize - yLoc );
- }
- for( int i = 0; ( i-1 ) * myYSize <= myGridHeight / 2 ; i++)
- {
- glVertex2d( -myGridWidth / 2 - myXSize - xLoc, -myYSize * i - yLoc );
- glVertex2d( myGridWidth / 2 + myXSize - xLoc, -myYSize * i - yLoc );
- glVertex2d( -myGridWidth / 2 - myXSize - xLoc, myYSize * i - yLoc );
- glVertex2d( myGridWidth / 2 + myXSize - xLoc, myYSize * i - yLoc );
- }
- glEnd();
-
- glColor3f( myAxisColor[0], myAxisColor[1], myAxisColor[2] );
- glLineWidth( myCenterWidth );
-
- glBegin( GL_LINES );
- glVertex2d( myGridWidth / 2 + myXSize - xLoc, 0);
- glVertex2d( -myGridWidth / 2 - myXSize - xLoc, 0);
- glVertex2d( 0, myGridHeight / 2 + myYSize - yLoc );
- glVertex2d( 0, -myGridHeight / 2 - myYSize - yLoc );
- glEnd();
-
- glBegin( GL_LINE_LOOP );
- double angle = 0.0;
- for ( int k = 0; k < SEGMENTS; k++ )
- {
- glVertex2f( cos(angle) * myCenterRadius * myXScale,
- sin(angle) * myCenterRadius * myYScale );
- angle += STEP;
- }
- glEnd();
-
- glEndList();
- }
- return TRUE;
-}
-/***************************************************************************
-** Class: GLViewer_Compass
-** Descr: OpenGL Compass for ViewPort 2D
-** Module: GLViewer
-** Created: UI team, 29.03.04
-****************************************************************************/
-GLViewer_Compass::GLViewer_Compass ( const QColor& color, const int size, const Position pos,
- const int WidthTop, const int WidthBottom, const int HeightTop,
- const int HeightBottom ){
- myCol = color;
- mySize = size;
- myPos = pos;
- myArrowWidthTop = WidthTop;
- myArrowWidthBottom = WidthBottom;
- myArrowHeightTop = HeightTop;
- myArrowHeightBottom = HeightBottom;
- myIsVisible = true;
- QFont* aFont = new QFont("Times",16);
- myFont = new GLViewer_TexFont( aFont );
- isGenereted = false;
- //myFont->generateTexture();
-}
-
-GLViewer_TexFont* GLViewer_Compass::getFont()
-{
- if(!isGenereted)
- {
- myFont->generateTexture();
- isGenereted = true;
- }
- return myFont;
-}
-
-
-/***************************************************************************
-** Class: GLViewer_ViewPort2d
-** Descr: OpenGL ViewPort 2D
-** Module: GLViewer
-** Created: UI team, 02.09.02
-****************************************************************************/
-
-#define WIDTH 640
-#define HEIGHT 480
-#define MARGIN 10
+#define GRID_XSIZE 100
+#define GRID_YSIZE 100
int static aLastViewPostId = 0;
else
myViewFrame = theViewFrame;
- myBorder = new QRect(0,0,0,0);
- myGrid = NULL;
+ myGrid = 0;
+ myCompass = 0;
+ myBorder = new GLViewer_Rect();
+
QBoxLayout* qbl = new QHBoxLayout( this );
myGLWidget = new GLViewer_Widget( this, 0 ) ;
qbl->addWidget( myGLWidget );
myCurDragPosX = NULL;
myCurDragPosY = NULL;
- myCompass = 0;
- //myCompass = new GLViewer_Compass();
- //myCompass = new GLViewer_Compass( Qt::green, 30, GLViewer_Compass::TopRight, 10, 5, 12, 3 );
-
myIsPulling = false;
myViewPortId = aLastViewPostId;
mypLastPoint = NULL;
myObjectTip = new QtxToolTip( myGLWidget );///GLViewer_ObjectTip( this );
+ myObjectTip->setShowDelayTime( 60000 );
connect( myObjectTip, SIGNAL( maybeTip( QPoint, QString&, QFont&, QRect&, QRect& ) ),
this, SLOT( onMaybeTip( QPoint, QString&, QFont&, QRect&, QRect& ) ) );
// myGLWidget->installEventFilter( myObjectTip );
delete myGLWidget;
}
-void GLViewer_ViewPort2d::onCreatePopup()
-{
- //cout << "GLViewer_ViewPort2d::onCreatePopup" << endl;
-
- //QAD_Desktop* desktop = (QAD_Desktop*) QAD_Application::getDesktop();
-
- QString theContext;
- QString theParent("Viewer");
- QString theObject;
-
- //desktop->definePopup( theContext, theParent, theObject );
- //desktop->createPopup( myPopup, theContext, theParent, theObject);
- //desktop->customPopup( myPopup, theContext, theParent, theObject );
-
- /*
- if ( myPopup->count() > 0 )
- myIDs.append ( myPopup->insertSeparator() );
- int id;
- myIDs.append ( id = myPopup->insertItem (tr ("MEN_VP3D_CHANGEBGR")) );
- QAD_ASSERT ( myPopup->connectItem ( id, this, SLOT(onChangeBackgroundColor())) );
- */
-
- /*
- if ( myPopup )
- {
- GLViewer_Viewer2d* aViewer = (GLViewer_Viewer2d*)getViewFrame()->getViewer();
-
- QAD_ASSERT( myPopupActions.isEmpty() );
-
- QAction* a = new QAction( "", tr( "MEN_VP_CHANGEBGR" ), 0, this );
- a->setStatusTip( tr( "PRP_VP_CHANGEBGR" ) );
- connect( a, SIGNAL( activated() ), SLOT( onChangeBgColor() ) );
- myPopupActions.append( a );
- a->addTo( myPopup );
-
- myPopup->insertSeparator();
-
- a = new QAction( "", tr( "MEN_VP_CREATE_GLMARKERS" ), 0, this );
- a->setStatusTip( tr( "PRP_VP_CREATE_GLMARKERS" ) );
- connect( a, SIGNAL( activated() ), aViewer, SLOT( onCreateGLMarkers() ) );
- myPopupActions.append( a );
- a->addTo( myPopup );
-
- a = new QAction( "", tr( "MEN_VP_CREATE_GLPOLYLINE" ), 0, this );
- a->setStatusTip( tr( "PRP_VP_CREATE_GLPOLYLINE" ) );
- connect( a, SIGNAL( activated() ), aViewer, SLOT( onCreateGLPolyline() ) );
- myPopupActions.append( a );
- a->addTo( myPopup );
-
- a = new QAction( "", tr( "MEN_VP_CREATE_GLTEXT" ), 0, this );
- a->setStatusTip( tr( "PRP_VP_CREATE_GLTEXT" ) );
- connect( a, SIGNAL( activated() ), aViewer, SLOT( onCreateGLText() ) );
- myPopupActions.append( a );
- a->addTo( myPopup );
-
- myPopup->insertSeparator();
-
- //GLViewer_Object* aMovingObject = ((GLViewer_Viewer2d*)getViewFrame()->getViewer())->getGLContext()->getCurrentObject();
- int aSelObjects = aViewer->getGLContext()->NbSelected();
- if( aSelObjects > 0 )
- {
- a = new QAction( "", tr( "MEN_VP_CUTOBJ" ), 0, this );
- a->setStatusTip( tr( "PRP_VP_CUTOBJ" ) );
- connect( a, SIGNAL( activated() ), SLOT( onCutObject() ) );
- myPopupActions.append( a );
- a->addTo( myPopup );
-
- a = new QAction( "", tr( "MEN_VP_COPYOBJ" ), 0, this );
- a->setStatusTip( tr( "PRP_VP_COPYOBJ" ) );
- connect( a, SIGNAL( activated() ), SLOT( onCopyObject() ) );
- myPopupActions.append( a );
- a->addTo( myPopup );
- }
-
- a = new QAction( "", tr( "MEN_VP_PASTEOBJ" ), 0, this );
- a->setStatusTip( tr( "PRP_VP_PASTEOBJ" ) );
- connect( a, SIGNAL( activated() ), SLOT( onPasteObject() ) );
- myPopupActions.append( a );
- a->addTo( myPopup );
-
- QClipboard *aClipboard = QApplication::clipboard();
- QMimeSource* aMimeSource = aClipboard->data();
- if( !aMimeSource->provides( "GLViewer_Objects" ) )
- a->setEnabled( false );
-
-
- if( aSelObjects > 0 )
- {
- myPopup->insertSeparator();
- a = new QAction( "", tr( "MEN_VP_DRAGOBJ" ), 0, this );
- a->setStatusTip( tr( "PRP_VP_DRAGOBJ" ) );
- connect( a, SIGNAL( activated() ), SLOT( onStartDragObject() ) );
- myPopupActions.append( a );
- a->addTo( myPopup );
- myCurDragPosX = new float((float)QCursor::pos().x());
- myCurDragPosY = new float((float)QCursor::pos().y());
- //myCurDragMousePos = QCursor::pos();
- }
- }
- */
-}
-
-void GLViewer_ViewPort2d::onCreatePopup( QPopupMenu* popup )
-{
-/*
- if ( popup )
- {
- GLViewer_Viewer2d* aViewer = (GLViewer_Viewer2d*)getViewFrame()->getViewer();
- if( !aViewer->isSketchingActive() )
- {
- if( !myPopupActions.isEmpty() )
- return;
- QAction* a = new QAction( "", tr( "MEN_VP_CHANGEBGR" ), 0, this );
- a->setStatusTip( tr( "PRP_VP_CHANGEBGR" ) );
- connect( a, SIGNAL( activated() ), SLOT( onChangeBgColor() ) );
- myPopupActions.append( a );
- a->addTo( popup );
-
- popup->insertSeparator();
-
- //GLViewer_Object* aMovingObject = ((GLViewer_Viewer2d*)getViewFrame()->getViewer())->getGLContext()->getCurrentObject();
- int aSelObjects = aViewer->getGLContext()->NbSelected();
- if( aSelObjects > 0 )
- {
- a = new QAction( "", tr( "MEN_VP_CUTOBJ" ), 0, this );
- a->setStatusTip( tr( "PRP_VP_CUTOBJ" ) );
- connect( a, SIGNAL( activated() ), SLOT( onCutObject() ) );
- myPopupActions.append( a );
- a->addTo( popup );
-
- a = new QAction( "", tr( "MEN_VP_COPYOBJ" ), 0, this );
- a->setStatusTip( tr( "PRP_VP_COPYOBJ" ) );
- connect( a, SIGNAL( activated() ), SLOT( onCopyObject() ) );
- myPopupActions.append( a );
- a->addTo( popup );
- }
-
- a = new QAction( "", tr( "MEN_VP_PASTEOBJ" ), 0, this );
- a->setStatusTip( tr( "PRP_VP_PASTEOBJ" ) );
- connect( a, SIGNAL( activated() ), SLOT( onPasteObject() ) );
- myPopupActions.append( a );
- a->addTo( popup );
-
- QClipboard *aClipboard = QApplication::clipboard();
- QMimeSource* aMimeSource = aClipboard->data();
- if( !aMimeSource->provides( "GLViewer_Objects" ) )
- a->setEnabled( false );
-
-
- if( aSelObjects > 0 )
- {
- popup->insertSeparator();
- a = new QAction( "", tr( "MEN_VP_DRAGOBJ" ), 0, this );
- a->setStatusTip( tr( "PRP_VP_DRAGOBJ" ) );
- connect( a, SIGNAL( activated() ), SLOT( onStartDragObject() ) );
- myPopupActions.append( a );
- a->addTo( popup );
- myCurDragPosX = new float((float)QCursor::pos().x());
- myCurDragPosY = new float((float)QCursor::pos().y());
- //myCurDragMousePos = QCursor::pos();
- }
- }
- else
- {//sketching mode
- QAD_ASSERT( myPopupActions.isEmpty() );
- QAction* a = new QAction( "", tr( "MEN_VP_SKETCH_DEL_OBJECT" ), 0, this );
- a->setStatusTip( tr( "PRP_VP_SKETCH_DEL_OBJECT" ) );
- connect( a, SIGNAL( activated() ), aViewer, SLOT( onSketchDelObject() ) );
- myPopupActions.append( a );
- a->addTo( popup );
-
- popup->insertSeparator();
-
- a = new QAction( "", tr( "MEN_VP_SKETCH_UNDO_LAST" ), 0, this );
- a->setStatusTip( tr( "PRP_VP_SKETCH_UNDO_LAST" ) );
- connect( a, SIGNAL( activated() ), aViewer, SLOT( onSketchUndoLast() ) );
- myPopupActions.append( a );
- a->addTo( popup );
-
- int aSkType = aViewer->getSketchingType();
- if( ( aSkType == GLViewer_Viewer2d::Polyline ) ||
- ( aSkType == GLViewer_Viewer2d::Curve) ||
- ( aSkType == GLViewer_Viewer2d::Scribble ) )
- {
- a = new QAction( "", tr( "MEN_VP_SKETCH_FINISH" ), 0, this );
- a->setStatusTip( tr( "PRP_VP_SKETCH_FINISH" ) );
- connect( a, SIGNAL( activated() ), aViewer, SLOT( onSketchFinish() ) );
- myPopupActions.append( a );
- a->addTo( popup );
- }
- }
- }
-*/
-}
-
-void GLViewer_ViewPort2d::onDestroyPopup( QPopupMenu* popup )
-{
-/*
- if ( popup )
- {
- for ( QAction* a = myPopupActions.first(); a; a = myPopupActions.next() )
- a->removeFrom( popup );
- myPopupActions.clear();
- popup->clear();
- }
-*/
-}
-
-
void GLViewer_ViewPort2d::onStartDragObject( )
{
if( myIsDragProcess == noDrag )
{
myIsDragProcess = initDrag;
- QCursor::setPos( ( int )( *myCurDragPosX ), ( int )( *myCurDragPosY ) );
+ QCursor::setPos( (int)(*myCurDragPosX), (int)(*myCurDragPosY) );
//myCurDragMousePos = QPoint( 0, 0 );
delete myCurDragPosX;
delete myCurDragPosY;
((GLViewer_Viewer2d*)getViewFrame()->getViewer())->getGLContext()->insertObject( aObject, true );
}
*/
- //QClipboard *aClipboard = QApplication::clipboard();
- //QMimeSource* aMimeSource = aClipboard->data();
-
/* ouv 6.05.04
+ QClipboard *aClipboard = QApplication::clipboard();
+
+ QMimeSource* aMimeSource = aClipboard->data();
if( aMimeSource->provides( "GLViewer_Objects" ) )
{
QByteArray anArray = aMimeSource->encodedData( "GLViewer_Objects" );
{
for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() )
{
- GLViewer_Object* aMovingObject = aContext->SelectedObject();
- //= aViewer->getGLContext()->getCurrentObject();
- if( aMovingObject )
- {
- aMovingObject->moveObject( aX - *myCurDragPosX ,
- anY - *myCurDragPosY);
- //QRect* rect = aMovingObject->getRect()->toQRect();
- //aViewer->updateBorders( *rect );
- aViewer->updateBorders();
- }
+ GLViewer_Object* aMovingObject = aContext->SelectedObject();
+ if( aMovingObject )
+ aMovingObject->moveObject( aX - *myCurDragPosX, anY - *myCurDragPosY);
}
}
else
}
else if( aContext->NbSelected() && (e->state() & MidButton ) )
for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() )
- (aContext->SelectedObject())->moveObject( aX - *myCurDragPosX, anY - *myCurDragPosY);
+ (aContext->SelectedObject())->moveObject( aX - *myCurDragPosX, anY - *myCurDragPosY);
- aViewer->updateBorders();
-
delete myCurDragPosX;
delete myCurDragPosY;
myCurDragPosX = new float(aX);
/*!
Emits 'mouseEvent' signal. [ virtual protected ]
*/
-void GLViewer_ViewPort2d::mousePressEvent( QMouseEvent *e )
-{
-
- //if( )
- /*GLViewer_Object* aMovingObject = ((GLViewer_Viewer2d*)getViewFrame()->getViewer())->getGLContext()->getCurrentObject();
- if( aMovingObject )
- {
- onStartDragObject();
- }*/
+void GLViewer_ViewPort2d::mousePressEvent( QMouseEvent* e )
+{
emit vpMouseEvent( e );
GLViewer_Viewer2d* aViewer = (GLViewer_Viewer2d*)getViewFrame()->getViewer();
GLViewer_Object* anObject = NULL;
if( aContext )
- anObject = aContext->getCurrentObject();
+ anObject = aContext->getCurrentObject();
bool accel = e->state() & GLViewer_ViewTransformer::accelKey();
- if( ( anObject && !( accel || e->button() == Qt::RightButton ) )
- ||
+ if( ( anObject && !( accel || e->button() == Qt::RightButton ) ) ||
( aContext->NbSelected() && !accel && e->button() == Qt::MidButton ) )
{
- myIsDragProcess = inDrag;
+ myIsDragProcess = inDrag;
}
}
*/
void GLViewer_ViewPort2d::mouseMoveEvent( QMouseEvent* e )
{
- //GLViewer_Context* context = ((GLViewer_Viewer2d*)getViewFrame()->getViewer())->getGLContext();
- //if( context->getCurrentObject() ) cout << "LASTPICKED" << endl;
emit vpMouseEvent( e );
- GLViewer_Viewer2d* aViewer = (GLViewer_Viewer2d*)getViewFrame()->getViewer();
- GLViewer_Context* aContext = aViewer->getGLContext();
-
if( myIsDragProcess == inDrag )
onDragObject( e );
-
+
+ /*GLViewer_Viewer2d* aViewer = (GLViewer_Viewer2d*)getViewFrame()->getViewer();
+ GLViewer_Context* aContext = aViewer->getGLContext();
+
GLViewer_Object* anObj = aContext->getCurrentObject();
if( anObj && aContext->currentObjectIsChanged() )
{
//QRect* aRect = (aViewer->getWinObjectRect(anObj));
//QToolTip::remove( myGLWidget, *aRect );
myGLWidget->removeToolTip();
- }
+ }*/
}
/*!
Emits 'mouseEvent' signal. [ virtual protected ]
*/
-void GLViewer_ViewPort2d::mouseReleaseEvent( QMouseEvent *e )
-{
- /*if( myIsDragProcess == inDrag )
- {
- GLViewer_Viewer2d* aViewer = (GLViewer_Viewer2d*)getViewFrame()->getViewer();
- GLViewer_Context* aContext = aViewer->getGLContext();
- for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() )
- {
- GLViewer_Object* aMovingObject = aContext->SelectedObject();
- if( aMovingObject )
- aMovingObject->finishMove();
- }
-
- myIsDragProcess = noDrag;
- //yCurDragMousePos.setX( 0 );
- //myCurDragMousePos.setY( 0 );
- delete myCurDragPosX;
- delete myCurDragPosY;
- myCurDragPosX = NULL;
- myCurDragPosY = NULL;
- }*/
-
-
+void GLViewer_ViewPort2d::mouseReleaseEvent( QMouseEvent* e )
+{
/* show popup menu */
if ( e->button() == Qt::RightButton )
{
bool isAnyMoved = false;
GLViewer_Viewer2d* aViewer = (GLViewer_Viewer2d*)getViewFrame()->getViewer();
GLViewer_Context* aContext = aViewer->getGLContext();
+ GLViewer_Object* aMovingObject;
for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() )
{
- GLViewer_Object* aMovingObject = aContext->SelectedObject();
+ aMovingObject = aContext->SelectedObject();
if( aMovingObject )
- {
- aMovingObject->finishMove();
- isAnyMoved = true;
- }
+ isAnyMoved = aMovingObject->finishMove() || isAnyMoved;
}
- GLViewer_Object* anObject = aContext->getCurrentObject();
- if( anObject )
- anObject->finishMove();
+ aMovingObject = aContext->getCurrentObject();
+ if( aMovingObject )
+ isAnyMoved = aMovingObject->finishMove() || isAnyMoved;
myIsDragProcess = noDrag;
- //yCurDragMousePos.setX( 0 );
+ //myCurDragMousePos.setX( 0 );
//myCurDragMousePos.setY( 0 );
delete myCurDragPosX;
delete myCurDragPosY;
myCurDragPosX = NULL;
myCurDragPosY = NULL;
- emit objectMoved();
+
+ if( isAnyMoved )
+ {
+ emit objectMoved();
+ aViewer->updateBorders();
+ }
}
}
void GLViewer_ViewPort2d::turnGrid( GLboolean on )
{
if( on )
- myGrid = new GLViewer_RectangularGrid( 2*WIDTH, 2*HEIGHT,
- 2*WIDTH, 2*HEIGHT,
- XSIZE, YSIZE,
- myXPan, myYPan,
- myXScale, myYScale );
+ {
+ myGrid = new GLViewer_Grid( 2*WIDTH, 2*HEIGHT,
+ 2*WIDTH, 2*HEIGHT,
+ GRID_XSIZE, GRID_YSIZE,
+ myXPan, myYPan,
+ myXScale, myYScale );
+ }
else if( myGrid )
- delete myGrid;
+ delete myGrid;
}
void GLViewer_ViewPort2d::setGridColor( const QColor gridColor, const QColor axisColor )
void GLViewer_ViewPort2d::fitRect( const QRect& rect )
{
- //cout << "GLViewer_ViewPort2d::fitRect" << endl;
-
float x0, x1, y0, y1;
float dx, dy, zm, centerX, centerY;
zm = vpWidth / dx < vpHeight / dy ? vpWidth / dx : vpHeight / dy;
- //myXPan += ( vpWidth / 2. - centerX ) / myXScale;
- //myYPan -= ( vpHeight / 2. - centerY ) / myYScale;
-
float aDX = ( vpWidth / 2. - centerX ) / myXScale;
float aDY = ( vpHeight / 2. - centerY ) / myYScale;
float dx, dy, zm;
float xScale, yScale;
- myMargin = QMAX( myBorder->width(), myBorder->height() ) / 10;
+ myMargin = QMAX( myBorder->width(), myBorder->height() ) / 5;
xa = myBorder->left() - myMargin;
xb = myBorder->right() + myMargin;
- ya = myBorder->top() - myMargin;
- yb = myBorder->bottom() + myMargin;
+ ya = myBorder->bottom() - myMargin;
+ yb = myBorder->top() + myMargin;
float aPoints[8] = { xa, ya, xb, ya, xa, yb, xb, yb };
xScale = myXScale;
yScale = myYScale;
- zm = vpWidth / dx < vpHeight / dy ? vpWidth / dx : vpHeight / dy;
+ if( dx && dy )
+ zm = vpWidth / dx < vpHeight / dy ? vpWidth / dx : vpHeight / dy;
+ else
+ zm = 1.0;
myXScale = zm;
myYScale = zm;
void GLViewer_ViewPort2d::startRotation( int x, int y )
{
- //cout << "GLViewer_ViewPort2d::startRotation" << endl;
-
myGLWidget->setRotationStart( x, y, 1.0 );
}
-void GLViewer_ViewPort2d::rotate( int x, int y )
+void GLViewer_ViewPort2d::rotate( int intX, int intY )
{
- //cout << "GLViewer_ViewPort2d::rotate " << x << " " << y << endl;
-
GLint val[4];
GLint vpWidth, vpHeight;
vpWidth = val[2];
vpHeight = val[3];
+ float x = intX, y = intY;
float x0 = vpWidth/2;
float y0 = vpHeight/2;
myGLWidget->getRotationStart( xs, ys, zs );
xs = xs - x0;
- x = ( int )( x - x0 );
+ x = x - x0;
dx = x - xs;
ys = y0 - ys;
- y = ( int )( y0 - y );
+ y = y0 - y;
dy = y - ys;
float l1 = pow( double( xs*xs + ys*ys ), 0.5 );
float angleNew = sign * acos( ( l1*l1 + l2*l2 - l*l ) / ( 2 * l1 * l2 )) * 180. / PI;
float angle = anglePrev + angleNew;
- //GLfloat anAngle = angle * PI / 180.;
-
- //if( myGrid )
- // myGrid->setPan( myXPan*cos(anAngle) + myYPan*sin(anAngle),
- // -myXPan*sin(anAngle) + myYPan*cos(anAngle) );
-
- //cout << l1 << endl;
- //cout << l2 << endl;
- //cout << l << endl;
-
- //cout << xs << " " << ys << " " << x << " " << y << endl;
- //cout << "MULTIPLICATION : " << mult << endl;
-
- //cout << "ANGLE_PREV = " << anglePrev << endl;
- //cout << "ANGLE_NEW = " << angleNew << endl;
- //cout << "ANGLE = " << angle << endl;
+ // GLfloat anAngle = angle * PI / 180.; unused
float ra, rx, ry, rz;
myGLWidget->getRotation( ra, rx, ry, rz );
void GLViewer_ViewPort2d::endRotation()
{
- //cout << "GLViewer_ViewPort2d::endRotation" << endl;
-
float ra, rx, ry, rz;
myGLWidget->getRotation( ra, rx, ry, rz );
myGLWidget->setRotationAngle( ra );
}
-void GLViewer_ViewPort2d::drawCompass(){
- if( !myCompass->getVisible() ) return;
+void GLViewer_ViewPort2d::drawCompass()
+{
+ if( !myCompass->getVisible() )
+ return;
GLfloat xScale, yScale, xPan, yPan;
int cPos = myCompass->getPos();
int cSize = myCompass->getSize();
- QColor* cCol = &(myCompass->getColor());
+ QColor cCol = myCompass->getColor();
int cWidthTop = myCompass->getArrowWidthTop();
int cWidthBot = myCompass->getArrowWidthBottom();
int cHeightTop = myCompass->getArrowHeightTop();
int cHeightBot = myCompass->getArrowHeightBottom();
- GLfloat colorR = (cCol->red())/255;
- GLfloat colorG = (cCol->green())/255;
- GLfloat colorB = (cCol->blue())/255;
+ GLfloat colorR = (cCol.red())/255;
+ GLfloat colorG = (cCol.green())/255;
+ GLfloat colorB = (cCol.blue())/255;
float delX = cSize * 0.5;
float delY = cSize * 0.5;
{
GLViewer_Viewer2d* aViewer = (GLViewer_Viewer2d*)getViewFrame()->getViewer();
GLViewer_Context* aContext = aViewer->getGLContext();
- ObjectMap anObjects = aContext->getObjects();
+ ObjList anObjects = aContext->getObjects();
- for( ObjectMap::Iterator it = anObjects.begin(); it != anObjects.end(); ++it )
+ for( ObjList::Iterator it = anObjects.begin(); it != anObjects.end(); ++it )
{
- GLViewer_Rect* aRect = it.key()->getRect();
+ GLViewer_Object* anObject = *it;
+ GLViewer_Rect aRect = anObject->getPullingRect();
- if( aRect->contains( point ) && it.key()->startPulling( point ) )
+ if( aRect.contains( point ) && anObject->startPulling( point ) )
{
myIsPulling = true;
- myPullingObject = it.key();
+ myPullingObject = anObject;
setCursor( *getHandCursor() );
return true;
}
{
GLViewer_Viewer2d* aViewer = (GLViewer_Viewer2d*)getViewFrame()->getViewer();
GLViewer_Context* aContext = aViewer->getGLContext();
- ObjectMap anObjects = aContext->getObjects();
+ ObjList anObjects = aContext->getObjects();
GLViewer_Object* aLockedObject = 0;
- for( ObjectMap::Iterator it = anObjects.begin(); it != anObjects.end(); ++it )
+ for( ObjList::Iterator it = anObjects.begin(); it != anObjects.end(); ++it )
{
- GLViewer_Rect* aRect = it.key()->getRect();
+ GLViewer_Object* anObject = *it;
+ if( !anObject->getVisible() )
+ continue;
+
+ GLViewer_Rect aRect = anObject->getPullingRect();
- if( aRect->contains( point ) && it.key()->portContains( point ) )
+ if( aRect.contains( point ) && anObject->portContains( point ) )
{
- aLockedObject = it.key();
+ aLockedObject = anObject;
break;
}
}
gluProject( theRect.left(), theRect.top(), 0, modelMatrix, projMatrix, viewport, &winx1, &winy1, &winz );
gluProject( theRect.right(), theRect.bottom(), 0, modelMatrix, projMatrix, viewport, &winx2, &winy2, &winz );
- aRect.setLeft( (int)(winx1) );
- aRect.setTop( (int)(viewport[3] - winy1) );
- aRect.setRight( (int)(winx2) );
- aRect.setBottom( (int)(viewport[3] - winy2) );
+ aRect.setLeft( (int)winx1 );
+ aRect.setTop( viewport[3] - (int)winy1 );
+ aRect.setRight( (int)winx2 );
+ aRect.setBottom( viewport[3] - (int)winy2 );
return aRect;
}
if( aBitmap )
cur_height = aBitmap->height();
}
- QFontMetrics fm( theFont );
+
//temp
- theTextReg = QRect( thePoint.x(), thePoint.y() + cur_height, fm.width( /*theText*/aList[index] ), fm.height()*aList.count() + 2 );
+ QSize aSize = QLabel( theText, 0 ).sizeHint();
+ theTextReg = QRect( thePoint.x(), thePoint.y() + cur_height,
+ aSize.width(), aSize.height() );
theRegion = QRect( thePoint.x(), thePoint.y(), 1, 1 );
}
}
// Author: OCC team
// Copyright (C) CEA 2004
-/* GLViewer_ViewPort2d Header File */
+#ifndef GLVIEWER_VIEWPORT2D_H
+#define GLVIEWER_VIEWPORT2D_H
#ifdef WNT
#include <windows.h>
#include <GL/glu.h>
#include "GLViewer_ViewPort.h"
-#include "GLViewer_Drawer.h"
+#include "GLViewer_Widget.h"
+#include "GLViewer_Geom.h"
+#include <qgl.h>
#include <qcolor.h>
-
-class GLViewer_ViewFrame;
-class GLViewer_Object;
-class GLViewer_Pnt;
-class GLViewer_Rect;
-
-/***************************************************************************
-** Class: GLViewer_RectangularGrid
-** Descr: OpenGL Grid for GLViewer_ViewPort2d
-** Module: QAD
-** Created: UI team, 16.09.02
-****************************************************************************/
-#ifndef GLVIEWER_RECTANGULARGRID_H
-#define GLVIEWER_RECTANGULARGRID_H
-
-class GLVIEWER_EXPORT GLViewer_RectangularGrid
-{
-public:
- GLViewer_RectangularGrid();
- GLViewer_RectangularGrid( float, float, float, float, float, float, float, float, float, float );
- ~GLViewer_RectangularGrid();
-
- void draw();
-
- void setGridColor( GLfloat, GLfloat, GLfloat );
- void setAxisColor( GLfloat, GLfloat, GLfloat );
- void setGridWidth( float );
- void setCenterRadius( int );
-
- void setSize( float, float );
- void setPan( float, float );
- bool setZoom( float );
- void setResize( float, float, float );
-
- void getSize( float&, float& ) const;
- void getPan( float&, float& ) const;
- void getScale( float&, float& ) const;
-
- void setScaleFactor( int );
- int getScaleFactor();
-
-protected:
- bool initList();
-
- GLuint myGridList;
- GLfloat myGridColor[3];
- GLfloat myAxisColor[3];
- GLfloat myGridHeight;
- GLfloat myGridWidth;
- GLfloat myWinW;
- GLfloat myWinH;
- GLfloat myXSize;
- GLfloat myYSize;
- GLfloat myXPan;
- GLfloat myYPan;
- GLfloat myXScale;
- GLfloat myYScale;
- GLfloat myLineWidth;
- GLfloat myCenterWidth;
- GLint myCenterRadius;
- GLint myScaleFactor;
- GLboolean myIsUpdate;
-};
-
-#endif
-
-/***************************************************************************
-** Class: GLViewer_ViewPort2d
-** Descr: OpenGL ViewPort 2D
-** Module: QAD
-** Created: UI team, 02.09.02
-****************************************************************************/
-
-//********* class compass for viewport******************
-class GLVIEWER_EXPORT GLViewer_Compass {
-public:
- enum Position { TopLeft, TopRight, BottomLeft, BottomRight };
-
- GLViewer_Compass( const QColor& color = QColor ( 0, 255, 0 ),
- const int size = 60,
- const Position pos = TopRight,
- const int WidthTop = 20,
- const int WidthBottom = 10,
- const int HeightTop = 25,
- const int HeightBottom = 7 );
- ~GLViewer_Compass(){ delete myFont; }
-
- void setCompass( const QColor& color, const int size, const Position pos )
- {myCol=color;mySize=size;myPos=pos;};
- void setVisible( const bool vis = true );
- bool getVisible(){ return myIsVisible; };
-
- void setSize( const int size ){mySize=size;};
- int getSize(){ return mySize; };
-
- void setPos( const Position pos ){myPos=pos;};
- int getPos(){ return myPos; };
-
- void setColor( const QColor& color ){myCol=color;};
- QColor getColor(){ return myCol; };
-
- void setArrowWidthTop( const int WidthTop ){ if( WidthTop<myArrowWidthBottom ||
- WidthTop>mySize ) return;
- myArrowWidthTop=WidthTop; };
- int getArrowWidthTop(){return myArrowWidthTop;};
-
- void setArrowWidthBottom( const int WidthBot ){ if( WidthBot>myArrowWidthTop || WidthBot<1 )return;
- myArrowWidthBottom=WidthBot; };
- int getArrowWidthBottom(){return myArrowWidthBottom;};
-
- void setArrowHeightTop( const int HeightTop ){ if( HeightTop>(2*mySize-myArrowHeightBottom ) ||
- HeightTop<1 )return;
- myArrowHeightTop=HeightTop;};
- int getArrowHeightTop(){return myArrowHeightTop;};
-
- void setArrowHeightBottom( const int HeightBot ){ if( HeightBot>( 2*mySize-myArrowHeightTop ) ||
- HeightBot<1)return;
- myArrowHeightBottom=HeightBot;};
- int getArrowHeightBottom(){return myArrowHeightBottom;};
-
- GLViewer_TexFont* getFont();
- void setFont( QFont theFont ){ delete myFont; myFont = new GLViewer_TexFont( &theFont ); }
-
-protected:
- QColor myCol;
- int mySize;
- int myPos;
- bool myIsVisible;
- int myArrowWidthTop;
- int myArrowWidthBottom;
- int myArrowHeightTop;
- int myArrowHeightBottom;
- GLViewer_TexFont* myFont;
- bool isGenereted;
-};
-
-
-#ifndef GLVIEWER_VIEWPORT2D_H
-#define GLVIEWER_VIEWPORT2D_H
-
#include <qwidget.h>
-#include <qmap.h>
#include <qpaintdevice.h>
-#include <qgl.h>
-#include "GLViewer_Widget.h"
+#ifdef WNT
+#pragma warning( disable:4251 )
+#endif
+
+class GLViewer_Compass;
+class GLViewer_Grid;
+class GLViewer_Object;
+class GLViewer_ViewFrame;
class QtxToolTip;
~GLViewer_ViewPort2d();
void turnGrid( GLboolean on );
- GLViewer_RectangularGrid* getGrid() const { return myGrid; }
+ GLViewer_Grid* getGrid() const { return myGrid; }
void setGridColor( const QColor gridColor, const QColor axisColor );
GLViewer_ViewFrame* getViewFrame() const { return myViewFrame; }
void setBackgroundColor( const QColor& color);
QColor backgroundColor() const;
- void setBorder( QRect* border ) { myBorder = border; }
- QRect* getBorder() const { return myBorder; }
+ void setBorder( GLViewer_Rect* border ) { myBorder = border; }
+ GLViewer_Rect* getBorder() const { return myBorder; }
void setMargin( GLfloat margin ) { myMargin = margin; }
GLfloat getMargin() const { return myMargin; }
void objectMoved();
protected:
- void onCreatePopup();
- void onCreatePopup( QPopupMenu* );
- void onDestroyPopup( QPopupMenu* );
-
void onDragObject( QMouseEvent* );
virtual void mouseMoveEvent( QMouseEvent *);
void onMaybeTip( QPoint, QString&, QFont&, QRect&, QRect& );
protected:
+ GLViewer_ViewFrame* myViewFrame;
GLViewer_Widget* myGLWidget;
+ GLViewer_Rect* myBorder;
QColor myBackgroundColor;
- QRect* myBorder;
+
GLfloat myMargin;
int myHeight;
int myWidth;
+
GLfloat myXScale;
GLfloat myYScale;
GLfloat myXOldScale;
GLfloat myYOldScale;
GLfloat myXPan;
GLfloat myYPan;
- GLViewer_RectangularGrid* myGrid;
- GLViewer_ViewFrame* myViewFrame;
- bool myDegenerated;
+ GLViewer_Grid* myGrid;
+ GLViewer_Compass* myCompass;
//dragging
int myIsDragProcess;
float* myCurDragPosX;
float* myCurDragPosY;
-
- GLViewer_Compass* myCompass;
//selection by rect
QPoint* mypFirstPoint;
QtxToolTip* myObjectTip;
};
+#ifdef WNT
+#pragma warning ( default:4251 )
+#endif
+
#endif
** Created: UI team, 05.09.00
****************************************************************************/
+//#include <GLViewerAfx.h>
#include "GLViewer_Viewer.h"
-
#include "GLViewer_Selector.h"
#include "GLViewer_ViewPort.h"
#include "GLViewer_ViewFrame.h"
#include "SUIT_Desktop.h"
#include "SUIT_ViewWindow.h"
-#include <qpainter.h>
#include <qapplication.h>
+#include <qpainter.h>
+#include <qpopupmenu.h>
+#include <qcolordialog.h>
/* used for sketching */
static QEvent* l_mbPressEvent = 0;
}
}
+//================================================================
+// Function : contextMenuPopup
+// Purpose :
+//================================================================
+void GLViewer_Viewer::contextMenuPopup( QPopupMenu* thePopup )
+{
+ if( thePopup->count() > 0 )
+ thePopup->insertSeparator();
+
+ thePopup->insertItem( tr( "CHANGE_BGCOLOR" ), this, SLOT( onChangeBgColor() ) );
+}
+
+/*!
+ Sets the background color with color selection dialog. [ virtual protected slot ]
+*/
+void GLViewer_Viewer::onChangeBgColor()
+{
+ GLViewer_ViewPort* vp = getActiveView()->getViewPort();
+ QColor selColor = QColorDialog::getColor( vp->backgroundColor() );
+
+ if( selColor.isValid() )
+ vp->setBackgroundColor( selColor );
+}
+
/*!
Returns the active view. [ public ]
*/
transform */
if( !myTransformer )
return;
- //int type = myTransformer->type();
qApp->installEventFilter( this );
}
/* Stop watch events */
if( !myTransformer )
return;
- //int type = myTransformer->type();
qApp->removeEventFilter( this );
}
if( !getActiveView() )
return false;
- if( getActiveView()->getViewPort() == o->parent() ) // for QAD_GLWidget
+ if( getActiveView()->getViewPort() == o->parent() )
o = o->parent();
bool mouseClickedOutside = ( e->type() == QEvent::MouseButtonPress &&
void GLViewer_Viewer::unhilightDetected()
{
if ( getSelector() )
- getSelector()->detect( -1, -1 );
+ getSelector()->undetectAll();
}
/*!
if( !avp )
return;
- //QAD_Desktop* d = QAD_Application::getDesktop();
switch( myType )
{
case GLViewer_Viewer::Zoom:
myMajorBtn = zoomButton();
avp->setCursor( *avp->getZoomCursor() );
- //d->putInfo( myViewer->tr( "PRP_VW_ZOOM" ) );
break;
case GLViewer_Viewer::Pan:
myMajorBtn = panButton();
avp->setCursor( *avp->getPanCursor() );
- //d->putInfo( myViewer->tr( "PRP_VW_PAN" ) );
break;
case GLViewer_Viewer::PanGlobal:
myMajorBtn = panGlobalButton();
avp->setCursor( *avp->getPanglCursor() );
avp->fitAll( true, false ); /* view is ready now */
- //d->putInfo( myViewer->tr( "PRP_VW_POINTCENTER" ) );
break;
case GLViewer_Viewer::FitRect:
myMajorBtn = fitRectButton();
avp->setCursor( *avp->getHandCursor() );
- //d->putInfo( myViewer->tr( "PRP_VW_SKETCHAREA" ) );
break;
case GLViewer_Viewer::Reset:
avp->reset(); onTransform( Fin );
if ( myType == GLViewer_Viewer::Rect )
delete ( QRect* ) myData;
-
- //QAD_Application::getDesktop()->clearInfo();
}
/*!
#pragma warning( disable:4251 )
#endif
-class GLVIEWER_EXPORT GLViewer_Viewer: public SUIT_ViewModel
+class GLVIEWER_API GLViewer_Viewer: public SUIT_ViewModel
{
Q_OBJECT
virtual QString getType() const { return Type(); }
static QString Type() { return "GLViewer_ViewModel"; }
+ virtual void contextMenuPopup( QPopupMenu* );
+
public:
void setSelectionMode( SelectionMode );
SelectionMode getSelectionMode() const;
virtual void onSelectionCancel();
virtual void onSelectionDone( bool add, SelectionChangeStatus status );
+ virtual void onChangeBgColor();
+
private:
void handleMouseMove( QMouseEvent* );
void handleMousePress( QMouseEvent* );
** Class: GLViewer_ViewTransformer
**
*****************************************************************/
-class GLVIEWER_EXPORT GLViewer_ViewTransformer : public QObject
+class GLVIEWER_API GLViewer_ViewTransformer : public QObject
{
public:
GLViewer_ViewTransformer( GLViewer_Viewer*, int type );
** Class: GLViewer_ViewSketcher
**
*****************************************************************/
-class GLVIEWER_EXPORT GLViewer_ViewSketcher : public QObject
+class GLVIEWER_API GLViewer_ViewSketcher : public QObject
{
public:
GLViewer_ViewSketcher( GLViewer_Viewer*, int type );
** Created: UI team, 04.09.02
****************************************************************************/
+//#include <GLViewerAfx.h>
#include "GLViewer_Viewer2d.h"
-
#include "GLViewer_Object.h"
+#include "GLViewer_BaseObjects.h"
+#include "GLViewer_CoordSystem.h"
#include "GLViewer_Context.h"
#include "GLViewer_Drawer.h"
#include "GLViewer_Selector2d.h"
#include "SUIT_Desktop.h"
#include "SUIT_ViewWindow.h"
-#include <OSD_Timer.hxx>
+#include "OSD_Timer.hxx"
#include <TColStd_MapOfInteger.hxx>
+#include <qpopupmenu.h>
#include <qpointarray.h>
#include <qcolordialog.h>
-#include <qpopupmenu.h>
GLViewer_Viewer2d::GLViewer_Viewer2d( const QString& title) :
GLViewer_Viewer( title )
{
myGLContext = new GLViewer_Context( this );
+
//myGLSketcher = new GLViewer_Sketcher( this );
- mySelMode = GLViewer_Viewer::Multiple;
+
createSelector();
+
+ mySelMode = GLViewer_Viewer::Multiple;
+
myDrawers.clear();
}
return new GLViewer_ViewFrame( theDesktop, this );
}
-void GLViewer_Viewer2d::contextMenuPopup( QPopupMenu* thePopup )
+void GLViewer_Viewer2d::addPopupItems( QPopupMenu* thePopup )
{
- // "Change background color" menu item is available if there are no selected objects
+ // CTH8434. "Change background color" menu item is available if there are no selected objects
if ( getSelector() == 0 || getSelector()->numSelected() == 0 )
{
if( thePopup->count() > 0 )
thePopup->insertSeparator();
- thePopup->insertItem( tr( "MNU_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
thePopup->insertItem( tr( "CHANGE_BGCOLOR" ), this, SLOT( onChangeBgColor() ) );
}
}
it.key()->setSColor( colorS );
}
*/
- ObjectMap anObjects = myGLContext->getObjects();
- ObjectMap::Iterator beginIt = anObjects.begin();
- ObjectMap::Iterator endIt = anObjects.end();
- for ( ObjectMap::Iterator it = beginIt; it != endIt; ++it )
+ /*
+ ObjList anObjects = myGLContext->getObjects();
+ ObjList::Iterator beginIt = anObjects.begin();
+ ObjList::Iterator endIt = anObjects.end();
+ for ( ObjList::Iterator it = beginIt; it != endIt; ++it )
{
- //GLViewer_Drawer* aDrawer = it.key()->getDrawer();
+ //GLViewer_Drawer* aDrawer = (*it)->getDrawer();
//aDrawer->setHColor( colorH );
//aDrawer->setSColor( colorS );
}
+ */
activateAllDrawers( TRUE );
}
-void GLViewer_Viewer2d::updateBorders( const QRect& rect )
+void GLViewer_Viewer2d::updateBorders( GLViewer_Rect* theRect )
{
- float xa = rect.left();
- float xb = rect.right();
- float ya = rect.top();
- float yb = rect.bottom();
-
QPtrVector<SUIT_ViewWindow> views = getViewManager()->getViews();
for ( int i = 0, n = views.count(); i < n; i++ )
{
- QRect* border = ( ( GLViewer_ViewPort2d* )((GLViewer_ViewFrame*)views[i])->getViewPort() )->getBorder();
+ GLViewer_Rect* border = ( ( GLViewer_ViewPort2d* )((GLViewer_ViewFrame*)views[i])->getViewPort() )->getBorder();
- if ( xa < border->left() ) border->setLeft( (int)xa );
- if ( xb > border->right() ) border->setRight( (int)xb );
- if ( ya < border->top() ) border->setTop( (int)ya );
- if ( yb > border->bottom() ) border->setBottom( (int)yb );
+ border->setLeft( QMIN( border->left(), theRect->left() ) );
+ border->setRight( QMAX( border->right(), theRect->right() ) );
+ border->setBottom( QMIN( border->bottom(), theRect->bottom() ) );
+ border->setTop( QMAX( border->top(), theRect->top() ) );
}
}
{
QPtrVector<SUIT_ViewWindow> views = getViewManager()->getViews();
- ObjectMap anObjects = myGLContext->getObjects();
- ObjectMap::Iterator beginIt = anObjects.begin();
- ObjectMap::Iterator endIt = anObjects.end();
+ ObjList anObjects = myGLContext->getObjects();
+ ObjList::Iterator beginIt = anObjects.begin();
+ ObjList::Iterator endIt = anObjects.end();
for ( int i = 0, n = views.count(); i < n; i++ )
{
- QRect* border = ( ( GLViewer_ViewPort2d* )((GLViewer_ViewFrame*)views[i])->getViewPort() )->getBorder();
- border->setRect( 0, 0, 0, 0 );
- for ( ObjectMap::Iterator it = beginIt; it != endIt; ++it )
+ GLViewer_Rect* border = ( ( GLViewer_ViewPort2d* )((GLViewer_ViewFrame*)views[i])->getViewPort() )->getBorder();
+ border->setIsEmpty( true );
+ for ( ObjList::Iterator it = beginIt; it != endIt; ++it )
{
- QRect* aRect = it.key()->getRect()->toQRect();
- if( !it.key()->getVisible() || aRect->isNull() )
+ GLViewer_Object* anObject = *it;
+ GLViewer_Rect* aRect = anObject->getRect();
+ if( !anObject->isSelectable() || !anObject->getVisible() )
continue;
- if( border->isNull() )
- border->setRect( aRect->left(), aRect->top(), aRect->width(), aRect->height() );
+ if( border->isEmpty() )
+ {
+ border->setIsEmpty( false );
+ border->setCoords( aRect->left(), aRect->right(), aRect->bottom(), aRect->top() );
+ }
else
- {
- border->setLeft( QMIN( border->left(), aRect->left() ) );
- border->setRight( QMAX( border->right(), aRect->right() ) );
- border->setTop( QMIN( border->top(), aRect->top() ) );
- border->setBottom( QMAX( border->bottom(), aRect->bottom() ) );
- }
+ {
+ border->setLeft( QMIN( border->left(), aRect->left() ) );
+ border->setRight( QMAX( border->right(), aRect->right() ) );
+ border->setBottom( QMIN( border->bottom(), aRect->bottom() ) );
+ border->setTop( QMAX( border->top(), aRect->top() ) );
+ }
}
- /*
- float gap = QMAX( border->width(), border->height() ) / 20;
- border->setLeft( border->left() - gap );
- border->setRight( border->right() + gap );
- border->setTop( border->top() - gap );
- border->setBottom( border->bottom() + gap );
- */
}
}
activateAllDrawers( update );
}
-void GLViewer_Viewer2d::activateDrawers( TColStd_SequenceOfInteger& sequence, bool onlyUpdate, GLboolean swap )
-{
-// cout << "GLViewer_Viewer2d::activateDrawers" << endl;
-// if( onlyUpdate )
-// cout << "Only update" << endl;
-// else
-// cout << "Not only update" << endl;
-
- TColStd_MapOfInteger aMap;
- for ( int i = 1, n = sequence.Length(); i <= n; i++)
- if ( !aMap.Contains( sequence( i ) ) )
- aMap.Add( sequence( i ) );
-
- const ObjectMap& anObjects = myGLContext->getObjects();
- const ObjList& objList = myGLContext->getObjList();
- ObjList anActiveObjects;
- for( ObjList::const_iterator it = objList.begin(); it != objList.end(); ++it )
- {
- if ( (*it)->getVisible() && aMap.Contains( anObjects[*it] ) )
- anActiveObjects.append( *it );
- }
-
- activateDrawers( anActiveObjects, onlyUpdate, swap );
-}
-
void GLViewer_Viewer2d::activateDrawers( QValueList<GLViewer_Object*>& theObjects, bool onlyUpdate, GLboolean swap )
{
//cout << "GLViewer_Viewer2d::activateDrawers " << (int)onlyUpdate << " " << (int)swap << endl;
- float xScale;
- float yScale;
-
QValueList<GLViewer_Drawer*>::Iterator anIt = myDrawers.begin();
QValueList<GLViewer_Drawer*>::Iterator endDIt = myDrawers.end();
for( ; anIt != endDIt; anIt++ )
- (*anIt)->clear();
+ (*anIt)->clear();
QValueList<GLViewer_Drawer*> anActiveDrawers;
QValueList<GLViewer_Object*>::Iterator endOIt = theObjects.end();
GLViewer_Drawer* aDrawer = (*oit)->getDrawer();
if( !aDrawer )
{
- anIt = myDrawers.begin();
+ anIt = myDrawers.begin();
+ endDIt = myDrawers.end();
for( ; anIt != endDIt; anIt++ )
if( (*anIt)->getObjectType() == (*oit)->getObjectType() )
break;
}
- if( !aDrawer ) //are not exists
+ if( !aDrawer )
{
myDrawers.append( (*oit)->createDrawer() );
aDrawer = (*oit)->getDrawer();
}
}
aDrawer->addObject( (*oit) );
- if( anActiveDrawers.findIndex( aDrawer ) == -1 )
- anActiveDrawers.append( aDrawer );
+
+ int aPriority = aDrawer->getPriority();
+
+ if( anActiveDrawers.findIndex( aDrawer ) != -1 )
+ continue;
+
+ QValueList<GLViewer_Drawer*>::Iterator aDIt = anActiveDrawers.begin();
+ QValueList<GLViewer_Drawer*>::Iterator aDEndIt = anActiveDrawers.end();
+ for( ; aDIt != aDEndIt; ++aDIt )
+ if( (*aDIt)->getPriority() > aPriority )
+ break;
+
+ anActiveDrawers.insert( aDIt, aDrawer );
}
QValueList<GLViewer_Drawer*>::Iterator aDIt = anActiveDrawers.begin();
QPtrVector<SUIT_ViewWindow> views = getViewManager()->getViews();
for ( int i = 0, n = views.count(); i < n; i++ )
{
+ float xScale, yScale;
GLViewer_ViewPort2d* vp = ( GLViewer_ViewPort2d* )((GLViewer_ViewFrame*)views[i])->getViewPort();
vp->getScale( xScale, yScale );
vp->getGLWidget()->makeCurrent();
-
for( ; aDIt != aDEndIt; aDIt++ )
- (*aDIt)->create( xScale, yScale, onlyUpdate );
-
- // tmp
- /*
- QRect* border = ( ( GLViewer_ViewPort2d* )((GLViewer_ViewFrame*)views[i])->getViewPort() )->getBorder();
- float x1 = border->left();
- float x2 = border->right();
- float y1 = border->bottom();
- float y2 = border->top();
-
- QColor color = Qt::blue;
- glColor3f( ( GLfloat )color.red() / 255,
- ( GLfloat )color.green() / 255,
- ( GLfloat )color.blue() / 255 );
- glLineWidth( 1.0 );
-
- glBegin( GL_LINE_LOOP );
- glVertex2f( x1, y1 );
- glVertex2f( x1, y2 );
- glVertex2f( x2, y2 );
- glVertex2f( x2, y1 );
- glEnd();
+ {
+ GLViewer_Drawer* aDrawer = *aDIt;
+ if( aDrawer )
+ aDrawer->create( xScale, yScale, onlyUpdate );
+ }
+/*
+ // draw border
+ GLViewer_Rect* border = ( ( GLViewer_ViewPort2d* )((GLViewer_ViewFrame*)views[i])->getViewPort() )->getBorder();
+ (*aDIt)->drawRectangle( border, Qt::blue );
QString coords = QString::number( border->left() ) + " " + QString::number( border->right() ) + " " +
- QString::number( border->top() ) + " " + QString::number( border->bottom() );
- (*aDIt)->drawText( "Border : " + coords, x1, y1+10/yScale, Qt::blue, &QFont( "Courier", 8, QFont::Normal ), 2 );
- */
+ QString::number( border->bottom() ) + " " + QString::number( border->top() );
+ (*aDIt)->drawText( "Border : " + coords, border->left(), border->top() + 10 / yScale,
+ Qt::blue, &QFont( "Courier", 8, QFont::Normal ), 2 );
+*/
if ( swap )
vp->getGLWidget()->swapBuffers();
}
( ( GLViewer_ViewPort2d* )getActiveView()->getViewPort() )->getGLWidget()->makeCurrent();
}
-void GLViewer_Viewer2d::activateDrawer( int index, bool onlyUpdate, GLboolean swap )
-{
- GLViewer_Object* anObj = 0;
- const ObjectMap& anObjects = myGLContext->getObjects();
- for ( ObjectMap::const_iterator it = anObjects.begin(); it != anObjects.end(); ++it )
- if ( it.data() == index )
- {
- anObj = (GLViewer_Object*)it.key();
- break;
- }
-
- if ( anObj )
- activateDrawer( anObj, onlyUpdate, swap );
-}
-
void GLViewer_Viewer2d::activateDrawer( GLViewer_Object* theObject, bool onlyUpdate, GLboolean swap )
{
ObjList aList;
return;
ObjList anActiveObjs;
- const ObjList& objs = myGLContext->getObjList();
+ const ObjList& objs = myGLContext->getObjects();
for( ObjList::const_iterator it = objs.begin(); it != objs.end(); ++it )
{
GLViewer_Object* obj = (GLViewer_Object*)(*it);
aMarkerSet->setYCoord( anYCoord, theMarkersNum );
aMarkerSet->compute();
- QRect* rect = aMarkerSet->getRect()->toQRect();
- updateBorders( *rect );
+ updateBorders( aMarkerSet->getRect() );
activateAllDrawers( false );
activateTransform( GLViewer_Viewer::FitAll );
aPolyline->setYCoord( anYCoord, theAnglesNum );
aPolyline->compute();
- QRect* rect = aPolyline->getRect()->toQRect();
- updateBorders( *rect );
+ updateBorders( aPolyline->getRect() );
}
activateAllDrawers( false );
aText->compute();
getGLContext()->insertObject( aText );
- QRect* rect = aText->getRect()->toQRect();
- updateBorders( *rect );
+ updateBorders( aText->getRect() );
}
activateAllDrawers( false );
curvp->getScale( xScale, yScale );
curvp->getPan( xPan, yPan );
- QRect* aObjRect = theObject->getRect()->toQRect();
- float aLeft = aObjRect->left() + xPan, aRight = aObjRect->right() + xPan;
- float aTop = aObjRect->top() + yPan, aBot = aObjRect->bottom() + yPan;
+ QRect aObjRect = theObject->getRect()->toQRect();
+ float aLeft = aObjRect.left() + xPan, aRight = aObjRect.right() + xPan;
+ float aTop = aObjRect.top() + yPan, aBot = aObjRect.bottom() + yPan;
GLfloat anAngle = curvp->getGLWidget()->getRotationAngle() * PI / 180.;
QPointArray aPointArray(4);
- int ls = (int)(aLeft*sin(anAngle)), lc = (int)(aLeft*cos(anAngle)),
- rs = (int)(aRight*sin(anAngle)), rc = (int)(aRight*cos(anAngle)),
- ts = (int)(aTop*sin(anAngle)), tc = (int)(aTop*cos(anAngle)),
- bs = (int)(aBot*sin(anAngle)), bc = (int)(aBot*cos(anAngle));
- aPointArray[0] = QPoint( lc - ts, ls + tc );
- aPointArray[1] = QPoint( rc - ts, rs + tc );
- aPointArray[2] = QPoint( rc - bs, rs + bc );
- aPointArray[3] = QPoint( lc - bs, ls + bc );
+ aPointArray[0] = QPoint( (int)(aLeft*cos(anAngle) - aTop*sin(anAngle)),
+ (int)(aLeft*sin(anAngle) + aTop*cos(anAngle)) );
+ aPointArray[1] = QPoint( (int)(aRight*cos(anAngle) - aTop*sin(anAngle)),
+ (int)(aRight*sin(anAngle) + aTop*cos(anAngle)) );
+ aPointArray[2] = QPoint( (int)(aRight*cos(anAngle) - aBot*sin(anAngle)),
+ (int)(aRight*sin(anAngle) + aBot*cos(anAngle)) );
+ aPointArray[3] = QPoint( (int)(aLeft*cos(anAngle) - aBot*sin(anAngle)),
+ (int)(aLeft*sin(anAngle) + aBot*cos(anAngle)) );
int aMinLeft = aPointArray[0].x(), aMaxRight = aPointArray[0].x(),
aMinTop = aPointArray[0].y(), aMaxBottom = aPointArray[0].y();
return;
ObjList anActiveObjs;
- const ObjList& objs = myGLContext->getObjList();
+ const ObjList& objs = myGLContext->getObjects();
for( ObjList::const_iterator it = objs.begin(); it != objs.end(); ++it )
{
GLViewer_Object* obj = (GLViewer_Object*)(*it);
updateAll();
}
-/*!
- Processes "Dump view..." context popup menu command
-*/
-void GLViewer_Viewer2d::onDumpView()
-{
- if ( getActiveView() )
- getActiveView()->onDumpView();
-}
/****************************************************************
** Class: GLViewer_View2dTransformer
/* additional transforms */
GLViewer_ViewPort* vp = myViewer->getActiveView()->getViewPort();
- //QAD_ASSERT( vp->inherits( "QAD_ViewPort3d" ) );
GLViewer_ViewPort2d* avp = (GLViewer_ViewPort2d*)vp;
switch ( myType )
{
return;
GLViewer_ViewPort* vp = myViewer->getActiveView()->getViewPort();
- //QAD_ASSERT( vp->inherits( "QAD_ViewPort3d" ) );
GLViewer_ViewPort2d* avp = (GLViewer_ViewPort2d*)vp;
if ( type() == GLViewer_Viewer::Rotate )
{
}
GLViewer_ViewTransformer::onTransform( state );
}
-
#include <qrect.h>
#include "GLViewer_Viewer.h"
+#include "GLViewer_Object.h"
#include "GLViewer_ViewFrame.h"
#include "GLViewer_Drawer.h"
#include <GL/gl.h>
class GLViewer_Object;
-class GLViewer_Rect;
class GLViewer_Context;
class GLViewer_Selector2d;
//class GLViewer_Sketcher;
#pragma warning( disable:4251 )
#endif
-class GLVIEWER_EXPORT GLViewer_Viewer2d : public GLViewer_Viewer
+class GLVIEWER_API GLViewer_Viewer2d : public GLViewer_Viewer
{
Q_OBJECT
public:
SUIT_ViewWindow* createView( SUIT_Desktop* );
- virtual void contextMenuPopup( QPopupMenu* );
+ void addPopupItems( QPopupMenu* );
//void activateGLSketching( int );
+ const QValueList<GLViewer_Drawer*>& getDrawers() const { return myDrawers; }
+
GLViewer_Context* getGLContext() const { return myGLContext; }
void updateColors( QColor colorH, QColor colorS );
- void updateBorders( const QRect& rect );
+ void updateBorders( GLViewer_Rect* theRect );
void updateBorders();
void updateAll();
void updateDrawers( GLboolean update, GLfloat scX = 0.0, GLfloat scY = 0.0 );
- void activateDrawers( TColStd_SequenceOfInteger& list, bool onlyUpdate,
- GLboolean swap = GL_TRUE );
void activateDrawers( QValueList<GLViewer_Object*>& theObjects, bool onlyUpdate, GLboolean swap = GL_FALSE );
- void activateDrawer( int index, bool onlyUpdate, GLboolean swap = GL_FALSE );
void activateDrawer( GLViewer_Object*, bool onlyUpdate, GLboolean swap = GL_FALSE );
void activateAllDrawers( bool onlyUpdate, GLboolean swap = GL_FALSE );
void transPoint( GLfloat& x, GLfloat& y );
- QRect* getWinObjectRect( GLViewer_Object* theObject );
-
+ QRect* getWinObjectRect( GLViewer_Object* );
+
+
GLViewer_Rect getGLVRect( const QRect& ) const;
QRect getQRect( const GLViewer_Rect& ) const;
protected slots:
void onMouseEvent( SUIT_ViewWindow*, QMouseEvent* );
- void onDumpView();
private:
bool testRotation( QMouseEvent* );
** Class: GLViewer_View2dTransformer
**
*****************************************************************/
-class GLVIEWER_EXPORT GLViewer_View2dTransformer : public GLViewer_ViewTransformer
+class GLVIEWER_API GLViewer_View2dTransformer : public GLViewer_ViewTransformer
{
public:
GLViewer_View2dTransformer( GLViewer_Viewer*, int );
** Created: UI team, 27.03.03
****************************************************************************/
+//#include <GLViewerAfx.h>
#include "GLViewer_Widget.h"
-
#include "GLViewer_ViewPort2d.h"
#include "GLViewer_Viewer2d.h"
+#include "GLViewer_Compass.h"
+#include "GLViewer_Grid.h"
#include "GLViewer_Object.h"
-
-//#include "QAD_Application.h"
-//#include <QAD_Desktop.h>
+#include "GLViewer_CoordSystem.h"
#include <cmath>
using namespace std;
#include <qpainter.h>
//-----------
-static GLuint texFont;
-static int fontW;
-static int fontH;
-
+//static GLuint texFont;
+//static int fontW;
+//static int fontH;
+/*
static void genFont()
{
bool ok;
- QFont aFont = QFontDialog::getFont( &ok/*, QAD_Application::getDesktop()*/ );
+ QFont aFont = QFontDialog::getFont( &ok );
QFontMetrics aFM( aFont );
QString aStr;
for( int k = 32; k <= 127; k++ )
glDisable(GL_ALPHA_TEST);
glDisable(GL_TEXTURE_2D);
}
-
+*/
GLViewer_Widget::GLViewer_Widget( QWidget* parent, const char* name ):
QGLWidget( parent, 0/*, WRepaintNoErase | WResizeNoErase*/ )
}
- GLViewer_RectangularGrid* grid = myViewPort->getGrid();
+ GLViewer_Grid* grid = myViewPort->getGrid();
if( grid )
grid->draw();
//myViewPort->drawCompass();
myViewPort->initResize( w, h );
- GLViewer_Viewer2d* v = ( GLViewer_Viewer2d* )getViewPort()->getViewFrame()->getViewer();
- v->updateDrawers( GL_FALSE, myXScale, myYScale );
+ //GLViewer_Viewer2d* v = ( GLViewer_Viewer2d* )getViewPort()->getViewFrame()->getViewer();
+ //v->updateDrawers( GL_FALSE, myXScale, myYScale );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
inline char hex( uchar c )
{
- if( c>=0 && c<=9 )
- return '0'+c;
- else
- return 'a'+c-10;
+ if( c<=9 )
+ return '0'+c;
+ else
+ return 'a' + c - 10;
}
void AddImagePart( QFile& hFile, QImage& image, int w1, int w2, int h1, int h2,
memcpy( dest + 2*i, &color, 2 );
break;
case 24:
- *( dest + 3*i ) = 255*b;
- *( dest + 3*i+1 ) = 255*g;
- *( dest + 3*i+2 ) = 255*r;
+ *( dest + 3*i ) = (uchar)(255*b);
+ *( dest + 3*i+1 ) = (uchar)(255*g);
+ *( dest + 3*i+2 ) = (uchar)(255*r);
break;
case 32:
- *( dest + 4*i ) = 255*b;
- *( dest + 4*i+1 ) = 255*g;
- *( dest + 4*i+2 ) = 255*r;
+ *( dest + 4*i ) = (uchar)(255*b);
+ *( dest + 4*i+1 ) = (uchar)(255*g);
+ *( dest + 4*i+2 ) = (uchar)(255*r);
*( dest + 4*i+3 ) = 0;
break;
}
class GLViewer_ViewPort2d;
class GLViewer_CoordSystem;
-class GLVIEWER_EXPORT GLViewer_Widget : public QGLWidget
+class GLVIEWER_API GLViewer_Widget : public QGLWidget
{
Q_OBJECT
# header files
EXPORT_HEADERS= GLViewer.h \
+ GLViewer_AspectLine.h \
+ GLViewer_BaseDrawers.h \
+ GLViewer_BaseObjects.h \
+ GLViewer_Compass.h \
GLViewer_Context.h \
+ GLViewer_CoordSystem.h \
GLViewer_Defs.h \
- GLViewer_Drawer.h \
+ GLViewer_Drawer.h \
+ GLViewer_Geom.h \
+ GLViewer_Grid.h \
GLViewer_Group.h \
+ GLViewer_MimeSource.h \
GLViewer_Object.h \
GLViewer_Selector.h \
GLViewer_Selector2d.h \
+ GLViewer_Text.h \
+ GLViewer_Tools.h \
+ GLViewer_ToolTip.h \
GLViewer_ViewFrame.h \
GLViewer_ViewManager.h \
GLViewer_ViewPort.h \
# Libraries targets
LIB = libGLViewer.la
+<<<<<<< Makefile.in
+LIB_SRC= GLViewer_AspectLine.cxx \
+ GLViewer_BaseDrawers.cxx \
+ GLViewer_BaseObjects.cxx \
+ GLViewer_Compass.cxx \
+ GLViewer_Context.cxx \
+ GLViewer_CoordSystem.cxx \
+=======
LIB_SRC= GLViewer_Context.cxx \
+>>>>>>> 1.3
GLViewer_Drawer.cxx \
+ GLViewer_Geom.cxx \
+ GLViewer_Grid.cxx \
GLViewer_Group.cxx \
+ GLViewer_MimeSource.cxx \
GLViewer_Object.cxx \
GLViewer_Selector.cxx \
GLViewer_Selector2d.cxx \
+ GLViewer_Text.cxx \
+ GLViewer_Tools.cxx \
+ GLViewer_ToolTip.cxx \
GLViewer_ViewFrame.cxx \
GLViewer_ViewManager.cxx \
GLViewer_ViewPort.cxx \
GLViewer_Viewer2d.cxx \
GLViewer_Widget.cxx
-LIB_MOC = GLViewer_Context.h \
- GLViewer_Drawer.h \
- GLViewer_Object.h \
- GLViewer_Selector.h \
+LIB_MOC = GLViewer_Selector.h \
GLViewer_Selector2d.h \
+ GLViewer_ToolTip.h \
GLViewer_ViewFrame.h \
GLViewer_ViewManager.h \
GLViewer_ViewPort.h \
LDFLAGS+=$(QT_MT_LIBS) $(CAS_KERNEL)
-LIBS+= -lsuit -L/usr/X11R6/lib -lGLU
+LIBS+= -L${GUI_ROOT_DIR}/lib/salome -lsuit -L/usr/X11R6/lib -lGLU
@CONCLUDE@