Salome HOME
#refs 327 - Polyline is not shown during creation
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Shape.cxx
index c5f3bbd2011b0da005c39e9fdce0966a7279837e..eccdb6208f75b444cb6525e27f3d7b1d77d04ce6 100644 (file)
 #include <QFile>
 
 HYDROGUI_Shape::HYDROGUI_Shape( const Handle(AIS_InteractiveContext)& theContext,
-                                const Handle(HYDROData_Entity)&       theObject )
+                                const Handle(HYDROData_Entity)&       theObject,
+                                const int                             theZLayer )
 : myContext( theContext ),
   myObject( theObject ),
+  myZLayer( theZLayer ),
   myIsHighlight( false ),
   myFillingColor( Qt::transparent ),
   myBorderColor( Qt::black ),
@@ -101,7 +103,7 @@ void HYDROGUI_Shape::display( const bool theIsUpdateViewer )
   if ( myContext.IsNull() || myShape.IsNull() || !isVisible() )
     return;
 
-  myContext->Display( myShape, theIsUpdateViewer );
+  displayShape( theIsUpdateViewer );
 }
 
 void HYDROGUI_Shape::erase( const bool theIsUpdateViewer )
@@ -112,8 +114,7 @@ void HYDROGUI_Shape::erase( const bool theIsUpdateViewer )
   myContext->Erase( myShape, theIsUpdateViewer );
 }
 
-void HYDROGUI_Shape::update( const bool theIsUpdateViewer,
-                             const bool theIsDisplayOnTop )
+void HYDROGUI_Shape::update( const bool theIsUpdateViewer )
 {
   setIsToUpdate( false );
 
@@ -389,17 +390,7 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer,
   if ( myShape.IsNull() || !isVisible() )
     return;
 
-  myContext->Display( myShape, theIsUpdateViewer );
-  
-  if ( theIsDisplayOnTop ) {
-    // Display the shape on the top Z layer
-    Standard_Integer aNewLayerId = -1;
-    if ( myContext->CurrentViewer() && 
-         myContext->CurrentViewer()->AddZLayer( aNewLayerId ) &&
-         aNewLayerId > 0 ) {
-      myContext->SetZLayer( myShape, aNewLayerId );
-    }
-  }
+  displayShape( theIsUpdateViewer );
 
   if (isDeactivateSelection)
     myContext->Deactivate(myShape);
@@ -408,16 +399,18 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer,
 void HYDROGUI_Shape::setVisible( const bool theState,
                                  const bool theIsUpdateViewer )
 {
-  if ( myIsVisible == theState )
-    return;
-
   myIsVisible = theState;
 
   if ( myShape.IsNull() )
     return;
 
-  if ( myIsVisible )
-    myContext->Display( myShape, theIsUpdateViewer );
+  if ( ( myIsVisible && myContext->IsDisplayed( myShape ) ) ||
+       ( !myIsVisible && !myContext->IsDisplayed( myShape ) ) )
+    return;
+
+  if ( myIsVisible ) {
+    displayShape( theIsUpdateViewer );
+  }
   else
     myContext->Erase( myShape, theIsUpdateViewer );
 }
@@ -433,7 +426,7 @@ void HYDROGUI_Shape::highlight( bool theIsHighlight, bool isUpdateViewer )
     return;
 
   colorShapeBorder( getActiveColor() );
-  myContext->Display( myShape, isUpdateViewer );
+  displayShape( isUpdateViewer );
 }
 
 bool HYDROGUI_Shape::isHighlighted() const
@@ -567,6 +560,16 @@ QString HYDROGUI_Shape::getTextureFileName() const
   return myTextureFileName;
 }
 
+void HYDROGUI_Shape::setZLayer( const int theZLayer )
+{
+  if ( myZLayer == theZLayer )
+    return;
+
+  myZLayer = theZLayer;
+  if ( !myShape.IsNull() && isVisible() && !myContext.IsNull() && myZLayer >= 0 )
+    myContext->SetZLayer( myShape, myZLayer );
+}
+
 void HYDROGUI_Shape::buildShape()
 {
   // Erase previously created shape
@@ -680,7 +683,17 @@ void HYDROGUI_Shape::updateShape( const bool theToDisplay,
   if ( !theToDisplay || !isVisible() || myContext.IsNull() )
     return;
   
-  myContext->Display( myShape, theIsUpdateViewer );
+  displayShape( theIsUpdateViewer );
+}
+
+void HYDROGUI_Shape::displayShape( const bool theIsUpdateViewer )
+{
+  myContext->Display( myShape, Standard_False );
+
+  if ( myZLayer >= 0 )
+    myContext->SetZLayer( myShape, myZLayer );
+
+  myContext->UpdateCurrentViewer();
 }
 
 QColor HYDROGUI_Shape::getActiveColor() const