From a5009740c80cfdb38418c14f56b8248ec53e252d Mon Sep 17 00:00:00 2001 From: ouv Date: Thu, 12 Aug 2010 07:37:04 +0000 Subject: [PATCH] Improvement of selection mechanism - presentations are selected taking into account their display priority. --- src/GLViewer/GLViewer_Context.cxx | 30 ++++++++++++++++++++++++------ src/GLViewer/GLViewer_Context.h | 4 ++++ src/GLViewer/GLViewer_Drawer.cxx | 13 ++++++++++++- src/GLViewer/GLViewer_Drawer.h | 4 +--- src/GLViewer/GLViewer_Object.cxx | 10 ++-------- src/GLViewer/GLViewer_Object.h | 5 ++++- 6 files changed, 47 insertions(+), 19 deletions(-) diff --git a/src/GLViewer/GLViewer_Context.cxx b/src/GLViewer/GLViewer_Context.cxx index 984e53726..e76eb0ea9 100644 --- a/src/GLViewer/GLViewer_Context.cxx +++ b/src/GLViewer/GLViewer_Context.cxx @@ -505,7 +505,7 @@ int GLViewer_Context::insertObject( GLViewer_Object* object, bool display, bool if( isActive ) { - myActiveObjects.append( object ); + insertObjectToList( object ); if( display ) { //QRect* rect = object->getRect()->toQRect(); @@ -514,7 +514,7 @@ int GLViewer_Context::insertObject( GLViewer_Object* object, bool display, bool } } else - myInactiveObjects.append( object ); + insertObjectToList( object, false ); return myActiveObjects.count() + myInactiveObjects.count(); } @@ -532,14 +532,14 @@ bool GLViewer_Context::replaceObject( GLViewer_Object* oldObject, GLViewer_Objec if( myActiveObjects.contains( oldObject ) ) { myActiveObjects.removeAll( oldObject ); - myActiveObjects.append( newObject ); + insertObjectToList( newObject ); return true; } if( myInactiveObjects.contains( oldObject ) ) { myInactiveObjects.removeAll( oldObject ); - myInactiveObjects.append( newObject ); + insertObjectToList( newObject, false ); return true; } @@ -700,7 +700,7 @@ bool GLViewer_Context::setActive( GLViewer_Object* theObject ) return false; myInactiveObjects.removeAll( theObject ); - myActiveObjects.append( theObject ); + insertObjectToList( theObject ); return true; } @@ -714,6 +714,24 @@ bool GLViewer_Context::setInactive( GLViewer_Object* theObject ) return false; myActiveObjects.removeAll( theObject ); - myInactiveObjects.append( theObject ); + insertObjectToList( theObject, false ); return true; } + +/*! + Inserts the object to the corresponding list to the position based on its priority + \param theObject - object to be inserted + \param isActive - true if needs inserting object in active list +*/ +void GLViewer_Context::insertObjectToList( GLViewer_Object* theObject, bool isActive ) +{ + int aPriority = theObject->getPriority(); + + ObjList& anObjList = isActive ? myActiveObjects : myInactiveObjects; + ObjList::Iterator anIter = anObjList.begin(), anIterEnd = anObjList.end(); + for( ; anIter != anIterEnd; anIter++ ) + if( (*anIter)->getPriority() > aPriority ) + break; + + anObjList.insert( anIter, theObject ); +} diff --git a/src/GLViewer/GLViewer_Context.h b/src/GLViewer/GLViewer_Context.h index 0e583c1fb..3ec2ecfed 100644 --- a/src/GLViewer/GLViewer_Context.h +++ b/src/GLViewer/GLViewer_Context.h @@ -156,6 +156,10 @@ public: //! A function installing to theObject inactive status bool setInactive( GLViewer_Object* theObject ); +protected: + //! Inserts the object to the corresponding list to the position based on its priority + void insertObjectToList( GLViewer_Object* theObject, bool isActive = true ); + protected: //! Flag of updating viewer after highlight /*! diff --git a/src/GLViewer/GLViewer_Drawer.cxx b/src/GLViewer/GLViewer_Drawer.cxx index b4ed40a26..ec365e067 100644 --- a/src/GLViewer/GLViewer_Drawer.cxx +++ b/src/GLViewer/GLViewer_Drawer.cxx @@ -483,7 +483,6 @@ GLViewer_Drawer::GLViewer_Drawer() myObjects.clear(); myTextList = 0/*-1*/; myObjectType = "GLViewer_Object"; - myPriority = 0; myTextFormat = DTF_BITMAP; myTextScale = 0.125; } @@ -497,6 +496,18 @@ GLViewer_Drawer::~GLViewer_Drawer() glDeleteLists( myTextList, 1 ); } +/*! + Returns object priority +*/ +int GLViewer_Drawer::getPriority() const +{ + if( !myObjects.isEmpty() ) + if( GLViewer_Object* anObject = myObjects.first() ) + return anObject->getPriority(); + return 0; +} + + /*! Clears all generated textures */ diff --git a/src/GLViewer/GLViewer_Drawer.h b/src/GLViewer/GLViewer_Drawer.h index 56f3d21f4..853ca8edc 100644 --- a/src/GLViewer/GLViewer_Drawer.h +++ b/src/GLViewer/GLViewer_Drawer.h @@ -233,7 +233,7 @@ public: QString getObjectType() const { return myObjectType; } //! Returns object priority - int getPriority() const { return myPriority; } + int getPriority() const; //! The function enables and disables antialiasing in Open GL (for points, lines and polygons). void setAntialiasing(const bool on); @@ -428,8 +428,6 @@ protected: //! Type of supporting object QString myObjectType; - //! Dislay priority - int myPriority; //! Default font for drawGLText() method QFont myFont; diff --git a/src/GLViewer/GLViewer_Object.cxx b/src/GLViewer/GLViewer_Object.cxx index 40234b886..2cdb4242e 100644 --- a/src/GLViewer/GLViewer_Object.cxx +++ b/src/GLViewer/GLViewer_Object.cxx @@ -53,6 +53,8 @@ GLViewer_Object::GLViewer_Object() myAspectLine = new GLViewer_AspectLine(); myType = "GLViewer_Object"; + myPriority = 0; + myOwner = NULL; myDrawer = NULL; @@ -81,14 +83,6 @@ GLViewer_Object::~GLViewer_Object() delete myAspectLine; } -/*! - \return priority of object -*/ -int GLViewer_Object::getPriority() const -{ - return myDrawer ? myDrawer->getPriority() : 0; -} - /*! \return true if object is inside rectangle \param theRect - rectangle diff --git a/src/GLViewer/GLViewer_Object.h b/src/GLViewer/GLViewer_Object.h index d2bc9845c..e946154dc 100644 --- a/src/GLViewer/GLViewer_Object.h +++ b/src/GLViewer/GLViewer_Object.h @@ -178,7 +178,7 @@ public: QString getName() const { return myName; } //! Returns object priority - virtual int getPriority() const; + virtual int getPriority() const { return myPriority; } //! Moves object per by recomputing /*! @@ -295,6 +295,9 @@ protected: //! Line aspect for object presentation GLViewer_AspectLine* myAspectLine; + //! Display priority + int myPriority; + //! Objet tool tip text QString myToolTipText; //! HTML object tool tip status -- 2.39.2