Salome HOME
Test case bugs/N4. A fix by PKV.
[modules/geom.git] / src / DisplayGUI / DisplayGUI.cxx
index c7f5df89c5cafbb03f8e179a89bc97a913b66960..67665f66e955fdf6141b9baedbc8fb7e66640277 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
 
 // GEOM GEOMGUI : GUI for Geometry component
 // File   : DisplayGUI.cxx
 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
-//
+
 #include "DisplayGUI.h"
 #include <GeometryGUI.h>
 #include "GeometryGUI_Operations.h"
@@ -92,29 +91,15 @@ bool DisplayGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
   SALOME_ListIO selected;
   Sel->selectedObjects( selected );
 
-  QString aDispModeName;
-  int aDispMode;
-  if ( theCommandID == GEOMOp::OpDisplayMode )
-    aDispMode = GetDisplayMode();
-
   switch ( theCommandID ) {
-  case GEOMOp::OpDisplayMode:    // MENU VIEW - DISPLAY MODE - WIREFRAME/SHADING/SHADING WITH EDGES
-    //InvertDisplayMode();
-    switch ( aDispMode) {
-    case 0:
-      aDispModeName = tr( "GEOM_MEN_WIREFRAME" );
-      break;
-    case 1:
-      aDispModeName = tr("GEOM_MEN_SHADING");
-      break;
-    case 2:
-      aDispModeName = tr("GEOM_MEN_SHADING_WITH_EDGES");
-      break;
-    default:
-      break;
-    }
-    getGeometryGUI()->action( GEOMOp::OpDisplayMode )->setText( aDispModeName );
-    getGeometryGUI()->menuMgr()->update();
+  case GEOMOp::OpDMWireframe:         // MENU VIEW - DISPLAY MODE - WIREFRAME
+    SetDisplayMode( 0 );
+    break;
+  case GEOMOp::OpDMShading:           // MENU VIEW - DISPLAY MODE - SHADING
+    SetDisplayMode( 1 );
+    break;
+  case GEOMOp::OpDMShadingWithEdges:  // MENU VIEW - DISPLAY MODE - SHADING WITH EDGES
+    SetDisplayMode( 2 );
     break;
   case GEOMOp::OpShowAll:        // MENU VIEW - SHOW ALL
     getGeometryGUI()->EmitSignalDeactivateDialog();
@@ -124,6 +109,10 @@ bool DisplayGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
     getGeometryGUI()->EmitSignalDeactivateDialog();
     DisplayOnly();
     break;
+  case GEOMOp::OpShowOnlyChildren: // POPUP MENU - SHOW ONLY CHILDREN
+    getGeometryGUI()->EmitSignalDeactivateDialog();
+    DisplayOnlyChildren();
+    break;
   case GEOMOp::OpHideAll:        // MENU VIEW - HIDE ALL
     EraseAll();
     break;
@@ -231,6 +220,62 @@ void DisplayGUI::DisplayOnly()
   Display();
 }
 
+//=====================================================================================
+// function : DisplayGUI::DisplayOnlyChildren()
+// purpose  : Display only children of selected GEOM objects and erase other
+//=====================================================================================
+void DisplayGUI::DisplayOnlyChildren()
+{
+  EraseAll();
+
+  SALOME_ListIO listIO;
+
+  SalomeApp_Application* app = getGeometryGUI()->getApp();
+  if (!app) return;
+
+  SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
+  if (!anActiveStudy) return;
+
+  LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
+  if (!aSelMgr) return;
+
+  // get selection
+  SALOME_ListIO aList;
+  //aSelMgr->selectedObjects(aList);
+  aSelMgr->selectedObjects(aList, "ObjectBrowser", false);
+  SALOME_ListIteratorOfListIO It (aList);
+
+  SUIT_OverrideCursor();
+
+  for (; It.More(); It.Next()) {
+    Handle(SALOME_InteractiveObject) anIObject = It.Value();
+    if (anIObject->hasEntry()) {
+      _PTR(SObject) SO (anActiveStudy->studyDS()->FindObjectID(anIObject->getEntry()));
+      if (SO) {
+        _PTR(SComponent) SC (SO->GetFatherComponent());
+        if (QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str())) {
+          // if component is selected, pass it
+        }
+        else {
+          _PTR(ChildIterator) anIter (anActiveStudy->studyDS()->NewChildIterator(SO));
+          anIter->InitEx(true);
+          while (anIter->More()) {
+            _PTR(SObject) valSO (anIter->Value());
+            _PTR(SObject) refSO;
+            if (!valSO->ReferencedObject(refSO)) {
+              listIO.Append(new SALOME_InteractiveObject(valSO->GetID().c_str(),
+                                                         SC->ComponentDataType().c_str(),
+                                                         valSO->GetName().c_str()));
+            }
+            anIter->Next();
+          }
+        }
+      }
+    }
+  }
+  GEOM_Displayer(anActiveStudy).Display(listIO, true);
+}
+
 //=====================================================================================
 // function : DisplayGUI::Display()
 // purpose  : Display selected GEOM objects
@@ -400,7 +445,12 @@ void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
     while( ite.More() ) {
       if( ite.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
        Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( ite.Value() );
-       ic->SetDisplayMode( aSh, Standard_Integer( newmode ),true );
+        if(aSh->isTopLevel()) {
+           aSh->setPrevDisplayMode(Standard_Integer( newmode ));
+        }
+        else {
+          ic->SetDisplayMode( aSh, Standard_Integer( newmode ),true );
+        }
       }
       ite.Next();
     }
@@ -411,27 +461,6 @@ void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
   }
 }
 
-//=====================================================================================
-// function : DisplayGUI::GetDisplayMode()
-// purpose  : Get display mode of the viewer (current viewer if <viewWindow> - 0 )
-//=====================================================================================
-int DisplayGUI::GetDisplayMode( SUIT_ViewWindow* viewWindow )
-{
-  int dispMode = 0;
-  if ( !viewWindow ) 
-    viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
-  if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
-    SVTK_View* aView = ((SVTK_ViewWindow*)viewWindow)->getView();
-    dispMode = aView->GetDisplayMode();
-  } 
-  else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
-    OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
-    Handle(AIS_InteractiveContext) ic = v3d->getAISContext();    
-    dispMode = ic->DisplayMode();
-  }
-  return dispMode;
-}
-
 //=====================================================================================
 // function : DisplayGUI::SetVectorsMode()
 // purpose  : Set vector mode for the viewer
@@ -493,16 +522,6 @@ int DisplayGUI::GetVectorMode( SUIT_ViewWindow* viewWindow )
   return viewWindow->property( "VectorsMode" ).toBool();
 }
 
-//=====================================================================================
-// function : DisplayGUI::InvertDisplayMode()
-// purpose  : Invert display mode ( shading <-> wireframe ) for the viewer 
-//            (current viewer if <viewWindow> = 0 )
-//=====================================================================================
-void DisplayGUI::InvertDisplayMode( SUIT_ViewWindow* viewWindow )
-{
-  SetDisplayMode( 1 - GetDisplayMode( viewWindow ) );
-}
-
 //=====================================================================================
 // function : DisplayGUI::ChangeDisplayMode()
 // purpose  : Set display mode for selected objects in the viewer given
@@ -584,17 +603,21 @@ void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow
         AIS_ListOfInteractive shapes; occPrs->GetObjects( shapes );
         AIS_ListIteratorOfListOfInteractive interIter( shapes );
         for ( ; interIter.More(); interIter.Next() ) {
-         if ( mode == 0 )
-            ic->SetDisplayMode( interIter.Value(), AIS_WireFrame, false );
-         else if ( mode == 1 )
-            ic->SetDisplayMode( interIter.Value(), AIS_Shaded, false );
-         else if ( mode == 2 )
-           ic->SetDisplayMode( interIter.Value(), GEOM_AISShape::ShadingWithEdges, false );
-         else if ( mode == 3 )
-            ic->SetDisplayMode( interIter.Value(), AIS_ExactHLR, false );
-         else if (mode == 4 ) {
-           Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( interIter.Value() );
-            if ( !aSh.IsNull() ) {
+          Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( interIter.Value() );
+          if ( !aSh.IsNull() ) {
+            if(!aSh->isTopLevel()) {
+                   if ( mode == 0 )
+                ic->SetDisplayMode( interIter.Value(), AIS_WireFrame, false );
+                   else if ( mode == 1 )
+                ic->SetDisplayMode( interIter.Value(), AIS_Shaded, false );
+                   else if ( mode == 2 )
+                     ic->SetDisplayMode( interIter.Value(), GEOM_AISShape::ShadingWithEdges, false );
+                   else if ( mode == 3 )
+                ic->SetDisplayMode( interIter.Value(), AIS_ExactHLR, false );
+            } else {
+              aSh->setPrevDisplayMode(mode);
+            }
+               if (mode == 4 ) {           
               vectorMode = !aSh->isShowVectors();      
               aSh->SetDisplayVectors(vectorMode);
               ic->RecomputePrsOnly(interIter.Value());