Salome HOME
correct selection mode activation
[modules/hydro.git] / src / HYDRO_tests / TestViewer.cxx
index 6cf7242fa3f7666d7884c5f33df9583cf15a8e84..f54fdfc064a7b80137e9c1de65fa5c1f91a484cf 100644 (file)
@@ -1,8 +1,10 @@
 
 #include <TestViewer.h>
 #include <HYDROData_Tool.h>
-#include <random.h>
 #include <OCCViewer_ViewManager.h>
+#ifdef WIN32
+  #pragma warning ( disable: 4251 )
+#endif
 #include <OCCViewer_ViewPort3d.h>
 #ifdef WIN32
   #pragma warning ( disable: 4251 )
@@ -19,7 +21,6 @@
 #include <AIS_Shape.hxx>
 #include <Aspect_ColorScale.hxx>
 #include <TopoDS_Iterator.hxx>
-
 #include <QDir>
 #include <QPainter>
 #include <QHash>
@@ -68,20 +69,33 @@ Handle(AIS_InteractiveContext) context()
   return TestViewer::viewer()->getAISContext();
 }
 
-QColor randomColor()
+QColor TestViewer::GetColor(int i)
 {
-  int r = test_rand();
-  int aHue = r%255;
-  //std::cout << "hue: " << aHue << std::endl;
-  QColor aColor = QColor::fromHsl( aHue, 255, 128 );
-  return aColor;
+  static QVector<QColor> aCV;
+  if( aCV.isEmpty() )
+  {
+    aCV  << QColor(0,0,255) 
+         << QColor(0,255,0)
+         << QColor(255,0,0)
+         << QColor(255,255,20) 
+         << QColor(20,255,255) 
+         << QColor(100,100,20) 
+         << QColor(10,100,150);
+  }
+  return aCV[i];
 }
 
 void TestViewer::show( const Handle(AIS_InteractiveObject)& theObject,
                        int theMode, int theSelectionMode, bool isFitAll, const char* theKey )
 {
+  context()->CloseLocalContext();
   context()->EraseAll( Standard_False );
-  context()->Display( theObject, theMode, theSelectionMode );
+  if( theSelectionMode > 0 )
+  {
+    context()->Display( theObject, theMode, theSelectionMode );
+    context()->OpenLocalContext();
+    context()->Activate( theObject, theSelectionMode, Standard_True );
+  }
 
   myKey = theKey;
 
@@ -111,15 +125,15 @@ void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll,
   context()->EraseAll( Standard_False );
   
   myKey = theKey;
-  test_srand( 0 );
-  if( theShape.ShapeType()==TopAbs_COMPOUND )
+  int i = 0;
+  if( theShape.ShapeType()==TopAbs_SHELL )
   {
     TopoDS_Iterator anIt( theShape );
-    for( ; anIt.More(); anIt.Next() )
-      show( anIt.Value(), theMode, false, randomColor() );
+    for( ; anIt.More(); anIt.Next(), i++ )
+      show( anIt.Value(), theMode, false, GetColor(i) );
   }
   else
-    show( theShape, theMode, false, randomColor() );
+    show( theShape, theMode, false, GetColor(0) );
 
   if( isFitAll )
   {
@@ -182,7 +196,7 @@ bool TestViewer::AssertImages( QString& theMessage )
   return false;
 }
 
-Handle_Aspect_ColorScale TestViewer::showColorScale()
+Handle_Aspect_ColorScale TestViewer::showColorScale( bool isShow )
 {
   Handle(V3d_View) aView = myViewWindow->getViewPort()->getView();
   if( aView.IsNull() )
@@ -209,8 +223,15 @@ Handle_Aspect_ColorScale TestViewer::showColorScale()
   aColorScale->SetTitle( "test" );
   aColorScale->SetRange( 0, 1 );
 
-  if( !aView->ColorScaleIsDisplayed() )
-    aView->ColorScaleDisplay();
-
+  if( isShow )
+  {
+    if( !aView->ColorScaleIsDisplayed() )
+      aView->ColorScaleDisplay();
+  }
+  else
+  {
+    if( aView->ColorScaleIsDisplayed() )
+      aView->ColorScaleErase();
+  }
   return aColorScale;
 }