Salome HOME
Merge multi-study removal branch.
[modules/geom.git] / src / DisplayGUI / DisplayGUI.cxx
index fee7c9787ea0ec074c4a1249c6acffbec723bf21..19339c6ea1399894a6038d7a93ecdedcbdc4e554 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  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
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -40,7 +40,6 @@
 #include <OCCViewer_ViewModel.h>
 
 #include <SALOME_ListIO.hxx>
-#include <SALOME_ListIteratorOfListIO.hxx>
 
 #include <SVTK_ViewWindow.h>
 #include <SVTK_View.h>
@@ -102,6 +101,9 @@ bool DisplayGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
   case GEOMOp::OpDMShadingWithEdges:  // MENU VIEW - DISPLAY MODE - SHADING WITH EDGES
     SetDisplayMode( 2 );
     break;
+  case GEOMOp::OpDMTexture:           // MENU VIEW - DISPLAY MODE - TEXTURE
+    SetDisplayMode( 3 );
+    break;
   case GEOMOp::OpShowAll:        // MENU VIEW - SHOW ALL
     getGeometryGUI()->EmitSignalDeactivateDialog();
     DisplayAll();
@@ -130,6 +132,18 @@ bool DisplayGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
       ( GetVectorMode() ? tr("MEN_VECTOR_MODE_ON") : tr( "MEN_VECTOR_MODE_OFF" ) );
     getGeometryGUI()->menuMgr()->update();
     break;
+  case GEOMOp::OpSwitchVertices:  // MENU VIEW - DISPLAY MODE - SHOW/HIDE VERTICES
+    SetVerticesMode(!GetVerticesMode());
+    getGeometryGUI()->action( GEOMOp::OpSwitchVertices )->setText
+      ( GetVerticesMode() ? tr("MEN_VERTICES_MODE_ON") : tr( "MEN_VERTICES_MODE_OFF" ) );
+    getGeometryGUI()->menuMgr()->update();
+    break;
+  case GEOMOp::OpSwitchName:  // MENU VIEW - DISPLAY MODE - SHOW/HIDE NAME
+    SetNameMode(!GetNameMode());
+    getGeometryGUI()->action( GEOMOp::OpSwitchName )->setText
+      ( GetNameMode() ? tr("MEN_NAME_MODE_ON") : tr( "MEN_NAME_MODE_OFF" ) );
+    getGeometryGUI()->menuMgr()->update();
+    break;
   case GEOMOp::OpWireframe:      // POPUP MENU - DISPLAY MODE - WIREFRAME
     ChangeDisplayMode( 0 );
     break;
@@ -142,14 +156,21 @@ bool DisplayGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
   case GEOMOp::OpTexture:        // POPUP MENU - DISPLAY MODE - TEXTURE
     ChangeDisplayMode( 3 );
     break;
-    case GEOMOp::OpVectors:        // POPUP MENU - DISPLAY MODE - SHOW EDGE DIRECTION
+  case GEOMOp::OpVectors:        // POPUP MENU - DISPLAY MODE - SHOW EDGE DIRECTION
     ChangeDisplayMode( 4 );
     break;
+  case GEOMOp::OpVertices:       // POPUP MENU - DISPLAY MODE - SHOW VERTICES
+    ChangeDisplayMode( 5 );
+    break;
+  case GEOMOp::OpShowName:       // POPUP MENU - DISPLAY MODE - SHOW NAME
+    ChangeDisplayMode( 6 );
+    break;
   default:
     app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
     break;
   }
   Sel->setSelectedObjects( selected );
+  GEOM_Displayer().UpdateColorScale();
   return true;
 }
 
@@ -159,12 +180,7 @@ bool DisplayGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
 //=====================================================================================
 void DisplayGUI::DisplayAll()
 {
-  SalomeApp_Application* app = getGeometryGUI()->getApp();
-  if ( !app ) return;
-
-  SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
-  if ( !appStudy ) return;
-  _PTR(Study) aStudy = appStudy->studyDS();
+  _PTR(Study) aStudy = SalomeApp_Application::getStudy();
   if ( !aStudy ) return;
   _PTR(SComponent) SC ( aStudy->FindComponent( "GEOM" ) );
   if ( !SC )
@@ -174,7 +190,7 @@ void DisplayGUI::DisplayAll()
   _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( SC ) );
   anIter->InitEx( true );
 
-  SUIT_OverrideCursor();
+  SUIT_OverrideCursor wc;
 
   while( anIter->More() ) {
     _PTR(SObject) valSO ( anIter->Value() );
@@ -186,7 +202,7 @@ void DisplayGUI::DisplayAll()
     } 
     anIter->Next();
   }
-  GEOM_Displayer( appStudy ).Display( listIO, true );
+  GEOM_Displayer().Display( listIO, true );
 }
 
 //=====================================================================================
@@ -195,17 +211,16 @@ void DisplayGUI::DisplayAll()
 //=====================================================================================
 void DisplayGUI::EraseAll()
 {
-  SUIT_OverrideCursor();
+  SUIT_OverrideCursor wc;
 
   SUIT_Application* app = getGeometryGUI()->getApp();
   if ( app ) {
     SUIT_ViewWindow* vw = app->desktop()->activeWindow();
     if ( vw ) {
-      SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
       SUIT_ViewManager* vman = vw->getViewManager();
       if ( vman->getType() == OCCViewer_Viewer::Type() || 
            vman->getType() == SVTK_Viewer::Type() ) {
-        GEOM_Displayer( appStudy ).EraseAll(true);
+        GEOM_Displayer().EraseAll(true);
       }
     }
   }
@@ -234,8 +249,8 @@ void DisplayGUI::DisplayOnlyChildren()
   SalomeApp_Application* app = getGeometryGUI()->getApp();
   if (!app) return;
 
-  SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
-  if (!anActiveStudy) return;
+  SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
+  if (!aStudy) return;
 
   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
   if (!aSelMgr) return;
@@ -246,19 +261,19 @@ void DisplayGUI::DisplayOnlyChildren()
   aSelMgr->selectedObjects(aList, "ObjectBrowser", false);
   SALOME_ListIteratorOfListIO It (aList);
 
-  SUIT_OverrideCursor();
+  SUIT_OverrideCursor wc;
 
   for (; It.More(); It.Next()) {
     Handle(SALOME_InteractiveObject) anIObject = It.Value();
     if (anIObject->hasEntry()) {
-      _PTR(SObject) SO (anActiveStudy->studyDS()->FindObjectID(anIObject->getEntry()));
+      _PTR(SObject) SO (aStudy->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));
+          _PTR(ChildIterator) anIter (aStudy->studyDS()->NewChildIterator(SO));
           anIter->InitEx(true);
           while (anIter->More()) {
             _PTR(SObject) valSO (anIter->Value());
@@ -274,7 +289,7 @@ void DisplayGUI::DisplayOnlyChildren()
       }
     }
   }
-  GEOM_Displayer(anActiveStudy).Display(listIO, true);
+  GEOM_Displayer().Display(listIO, true);
 }
 
 //=====================================================================================
@@ -288,8 +303,8 @@ void DisplayGUI::Display()
   SalomeApp_Application* app = getGeometryGUI()->getApp();
   if ( !app ) return;
 
-  SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
-  if ( !anActiveStudy ) return;
+  SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
+  if ( !aStudy ) return;
 
   //get SalomeApp selection manager
   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
@@ -299,17 +314,17 @@ void DisplayGUI::Display()
   aSelMgr->selectedObjects( aList );
   SALOME_ListIteratorOfListIO It( aList );
 
-  SUIT_OverrideCursor();
+  SUIT_OverrideCursor wc;
 
   for( ;It.More();It.Next() ) {
     Handle(SALOME_InteractiveObject) anIObject = It.Value();
     if ( anIObject->hasEntry() ) {
-      _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
+      _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
       if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
         _PTR(SComponent) SC ( SO->GetFatherComponent() );
         // if component is selected
         listIO.Clear();
-        _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
+        _PTR(ChildIterator) anIter ( aStudy->studyDS()->NewChildIterator( SO ) );
         anIter->InitEx( true );
         while( anIter->More() ) {
           _PTR(SObject) valSO ( anIter->Value() );
@@ -331,7 +346,7 @@ void DisplayGUI::Display()
       listIO.Append( anIObject );
     }
   }
-  GEOM_Displayer( anActiveStudy ).Display( listIO, true );
+  GEOM_Displayer().Display( listIO, true );
 }
 
 
@@ -346,8 +361,8 @@ void DisplayGUI::Erase()
   SalomeApp_Application* app = getGeometryGUI()->getApp();
   if ( !app ) return;
 
-  SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
-  if ( !anActiveStudy ) return;
+  SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
+  if ( !aStudy ) return;
 
   //get SalomeApp selection manager
   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
@@ -357,17 +372,17 @@ void DisplayGUI::Erase()
   aSelMgr->selectedObjects( aList );
   SALOME_ListIteratorOfListIO It( aList );
 
-  SUIT_OverrideCursor();
+  SUIT_OverrideCursor wc;
 
   for( ; It.More(); It.Next() ) {
     Handle(SALOME_InteractiveObject) anIObject = It.Value();
     if ( anIObject->hasEntry() ) {
-      _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
+      _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
       if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
         _PTR(SComponent) SC ( SO->GetFatherComponent() );
         // if component is selected
         listIO.Clear();
-        _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
+        _PTR(ChildIterator) anIter ( aStudy->studyDS()->NewChildIterator( SO ) );
         anIter->InitEx( true );
         while( anIter->More() ) {
           _PTR(SObject) valSO ( anIter->Value() );
@@ -395,7 +410,7 @@ void DisplayGUI::Erase()
   if(viewWindow->getViewManager()->getType() == SVTK_Viewer::Type())
     aIsForced = false;
 
-  GEOM_Displayer(anActiveStudy).Erase( listIO, aIsForced);
+  GEOM_Displayer().Erase( listIO, aIsForced);
   getGeometryGUI()->getApp()->selectionMgr()->clearSelected();
 }
 
@@ -405,7 +420,7 @@ void DisplayGUI::Erase()
 //=====================================================================================
 void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
 {
-  SUIT_OverrideCursor();
+  SUIT_OverrideCursor wc;
 
   SalomeApp_Application* app = getGeometryGUI()->getApp();
   if ( !app ) return;
@@ -416,12 +431,15 @@ void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
   SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
   if ( !aStudy ) return;
 
-  GEOM_Displayer displayer( aStudy );
+  GEOM_Displayer displayer;
 
   int mgrId = viewWindow->getViewManager()->getGlobalId();
 
+  SALOME_View* window = displayer.GetActiveView();
+  if ( !window ) return;
+
   SALOME_ListIO anIOlst;
-  displayer.GetActiveView()->GetVisible( anIOlst );
+  window->GetVisible( anIOlst );
 
   for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
     Handle( SALOME_InteractiveObject ) io = It.Value();
@@ -438,7 +456,7 @@ void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
 //=====================================================================================
 void DisplayGUI::SetVectorMode( const bool mode, SUIT_ViewWindow* viewWindow )
 {
-  SUIT_OverrideCursor();
+  SUIT_OverrideCursor wc;
 
   SalomeApp_Application* app = getGeometryGUI()->getApp();
   if ( !app ) return;
@@ -449,14 +467,17 @@ void DisplayGUI::SetVectorMode( const bool mode, SUIT_ViewWindow* viewWindow )
   if ( !viewWindow ) 
     viewWindow = app->desktop()->activeWindow();
 
-  GEOM_Displayer displayer( aStudy );
+  GEOM_Displayer displayer;
 
   viewWindow->setProperty( "VectorsMode", mode );
 
   int aMgrId = viewWindow->getViewManager()->getGlobalId();
 
+  SALOME_View* window = displayer.GetActiveView();
+  if ( !window ) return;
+
   SALOME_ListIO anIOlst;
-  displayer.GetActiveView()->GetVisible( anIOlst );
+  window->GetVisible( anIOlst );
 
   for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
     Handle( SALOME_InteractiveObject ) io = It.Value();
@@ -478,6 +499,104 @@ int DisplayGUI::GetVectorMode( SUIT_ViewWindow* viewWindow )
   return viewWindow->property( "VectorsMode" ).toBool();
 }
 
+//=====================================================================================
+// function : DisplayGUI::SetVerticesMode()
+// purpose  : Set vertices mode for the viewer
+//=====================================================================================
+void DisplayGUI::SetVerticesMode( const bool mode, SUIT_ViewWindow* viewWindow )
+{
+  SUIT_OverrideCursor wc;
+
+  SalomeApp_Application* app = getGeometryGUI()->getApp();
+  if ( !app ) return;
+
+  SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
+  if ( !aStudy ) return;
+
+  if ( !viewWindow ) 
+    viewWindow = app->desktop()->activeWindow();
+
+  GEOM_Displayer displayer;
+
+  viewWindow->setProperty( "VerticesMode", mode );
+
+  int aMgrId = viewWindow->getViewManager()->getGlobalId();
+
+  SALOME_View* window = displayer.GetActiveView();
+  if ( !window ) return;
+
+  SALOME_ListIO anIOlst;
+  window->GetVisible( anIOlst );
+
+  for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
+    Handle( SALOME_InteractiveObject ) io = It.Value();
+    aStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Vertices ), mode );
+    displayer.Redisplay( io, false );
+  }
+  displayer.UpdateViewer();
+  GeometryGUI::Modified();
+}
+
+//=====================================================================================
+// function : DisplayGUI::GetVerticesMode()
+// purpose  : Get the "show vertices" mode of the viewer
+//=====================================================================================
+int DisplayGUI::GetVerticesMode( SUIT_ViewWindow* viewWindow )
+{
+  if ( !viewWindow ) 
+    viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
+  return viewWindow->property( "VerticesMode" ).toBool();
+}
+
+//=====================================================================================
+// function : DisplayGUI::SetNameMode()
+// purpose  : Set name mode for the viewer
+//=====================================================================================
+void DisplayGUI::SetNameMode( const bool mode, SUIT_ViewWindow* viewWindow )
+{
+  SUIT_OverrideCursor();
+
+  SalomeApp_Application* app = getGeometryGUI()->getApp();
+  if ( !app ) return;
+
+  SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
+  if ( !aStudy ) return;
+
+  if ( !viewWindow )
+    viewWindow = app->desktop()->activeWindow();
+
+  viewWindow->setProperty( "NameMode", mode );
+
+  GEOM_Displayer displayer;
+
+  int aMgrId = viewWindow->getViewManager()->getGlobalId();
+
+  SALOME_View* window = displayer.GetActiveView();
+  if ( !window ) return;
+
+  SALOME_ListIO anIOlst;
+  window->GetVisible( anIOlst );
+
+  for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
+    Handle( SALOME_InteractiveObject ) io = It.Value();
+    aStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::ShowName ), mode );
+    displayer.Redisplay( io, false );
+  }
+  displayer.UpdateViewer();
+  GeometryGUI::Modified();
+}
+
+//=====================================================================================
+// function : DisplayGUI::GetNameMode()
+// purpose  : Get the "show name" mode of the viewer
+//=====================================================================================
+int DisplayGUI::GetNameMode( SUIT_ViewWindow* viewWindow )
+{
+  if ( !viewWindow )
+    viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
+  return viewWindow->property( "NameMode" ).toBool();
+}
+
 //=====================================================================================
 // function : DisplayGUI::ChangeDisplayMode()
 // purpose  : Set display mode for selected objects in the viewer given
@@ -497,18 +616,22 @@ void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow
   SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
   if ( !aStudy ) return;
 
-  SUIT_OverrideCursor();
+  SUIT_OverrideCursor wc;
 
   SALOME_ListIO selected;
   aSelMgr->selectedObjects( selected );
   if ( selected.IsEmpty() ) return;
 
-  GEOM_Displayer displayer( aStudy );
+  GEOM_Displayer displayer;
 
   int mgrId = viewWindow->getViewManager()->getGlobalId();
 
   QVariant v = aStudy->getObjectProperty( mgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), QVariant() );
   bool vectorMode =  v.isValid() ? !v.toBool() : false;
+  v = aStudy->getObjectProperty( mgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Vertices ), QVariant() );
+  bool verticesMode =  v.isValid() ? !v.toBool() : false;
+  v = aStudy->getObjectProperty( mgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::ShowName ), QVariant() );
+  bool nameMode =  v.isValid() ? !v.toBool() : false;
 
   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
     Handle( SALOME_InteractiveObject ) io = It.Value();
@@ -518,6 +641,12 @@ void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow
     else if ( mode == 4 ) {
       aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), vectorMode );
     }
+    else if ( mode == 5 ) {
+      aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Vertices ), verticesMode );
+    }
+    else if ( mode == 6 ) {
+      aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::ShowName ), nameMode );
+    }
     displayer.Redisplay( io, false );
   }
   displayer.UpdateViewer();