Salome HOME
Copyright update 2022
[modules/geom.git] / src / GEOM_SWIG_WITHIHM / libGEOM_Swig.cxx
index 1fa77355deff84b4852ee6fc10d43f7e94282089..69d65636041cee7972a74a8257cf79c5f6ee4dd2 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022  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
 #include "GEOM_Displayer.h"
 #include "GEOM_Constants.h"
 #include "Material_Model.h"
+#include "GEOM_Swig_LocalSelector.h"
+#include "GEOMGUI_OCCSelector.h"
+#include "OCCViewer_ViewManager.h"
 
 #include <SUIT_Desktop.h>
 #include <SUIT_Session.h>
 #include <SUIT_ViewManager.h>
 #include <SUIT_ViewModel.h>
+#include <SUIT_SelectionMgr.h>
+#include <LightApp_SelectionMgr.h>
 #include <SalomeApp_Application.h>
 #include <SalomeApp_Study.h>
 #include <OCCViewer_ViewFrame.h>
 #include <SVTK_ViewWindow.h>
 
 #include <SALOME_Event.h>
+#include <utilities.h>
 
 // IDL Headers
 #include <SALOMEconfig.h>
 #include CORBA_SERVER_HEADER(GEOM_Gen)
 
+GEOM_Swig_LocalSelector* GEOM_Swig::myLocalSelector = 0;
+GEOMGUI_OCCSelector* GEOM_Swig::myOCCSelector =0;
+
 /*!
   \brief Constructor
 */
-GEOM_Swig::GEOM_Swig()
+GEOM_Swig::GEOM_Swig( bool updateOB )
 {
-  init();
+  init(updateOB);
 }
 
 /*!
@@ -62,12 +71,14 @@ GEOM_Swig::~GEOM_Swig()
 /*!
   \brief Internal initialization
 */
-void GEOM_Swig::init()
+void GEOM_Swig::init( bool updateOB )
 {
   class TEvent: public SALOME_Event
   {
+    bool myUpdateOB;
   public:
-    TEvent()
+    TEvent( bool _updateOB ):
+      myUpdateOB(_updateOB)
     {}
     virtual void Execute()
     {
@@ -99,12 +110,14 @@ void GEOM_Swig::init()
       }
 
       // update Object browser
-      if ( dynamic_cast<SalomeApp_Application*>( app ) )
+      if (myUpdateOB && dynamic_cast<SalomeApp_Application*>( app ) )
         dynamic_cast<SalomeApp_Application*>( app )->updateObjectBrowser( true );
+
+      //myLocalSelector = 0;
     }
   };
 
-  ProcessVoidEvent( new TEvent() );
+  ProcessVoidEvent( new TEvent(updateOB) );
 }
 
 /*!
@@ -124,14 +137,9 @@ void GEOM_Swig::createAndDisplayGO( const char* theEntry, bool theUpdateViewer )
     {}
     virtual void Execute()
     {
-      SUIT_Application* app = SUIT_Session::session()->activeApplication();
-      if ( !app ) return;
-      SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
-      if ( !study ) return;
-
       Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( myEntry.c_str(), "GEOM", "" );
 
-      GEOM_Displayer( study ).Display( io, myUpdateViewer );
+      GEOM_Displayer().Display( io, myUpdateViewer );
     }
   };
 
@@ -186,14 +194,9 @@ void GEOM_Swig::eraseGO( const char* theEntry, bool theUpdateViewer )
     {}
     virtual void Execute()
     {
-      SUIT_Application* app = SUIT_Session::session()->activeApplication();
-      if ( !app ) return;
-      SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
-      if ( !study ) return;
-
       Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( myEntry.c_str(), "GEOM", "" );
 
-      GEOM_Displayer( study ).Erase( io, true, myUpdateViewer );
+      GEOM_Displayer().Erase( io, true, myUpdateViewer );
     }
   };
 
@@ -212,13 +215,7 @@ void GEOM_Swig::UpdateViewer()
     {}
     virtual void Execute()
     {
-      SUIT_Application* app = SUIT_Session::session()->activeApplication();
-      if ( !app ) return;
-
-      SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
-      if ( !study ) return;
-      
-      GEOM_Displayer( study ).UpdateViewer();
+      GEOM_Displayer().UpdateViewer();
     }
   };
   
@@ -248,7 +245,7 @@ int GEOM_Swig::getIndexTopology( const char* theSubIOR, const char* theMainIOR )
   if ( !CORBA::is_nil( aGeomGen ) && !CORBA::is_nil( aMainShape ) && !CORBA::is_nil( aSubShape ) ) {
     // get shapes operations interface
     GEOM::GEOM_IShapesOperations_var anIShapesOperations =
-      aGeomGen->GetIShapesOperations( aMainShape->GetStudyID() );
+      aGeomGen->GetIShapesOperations();
     if ( !CORBA::is_nil( anIShapesOperations ) )
       index = anIShapesOperations->GetTopologyIndex( aMainShape, aSubShape );
   }
@@ -275,7 +272,7 @@ const char* GEOM_Swig::getShapeTypeString( const char* theIOR )
   if ( !CORBA::is_nil( aGeomGen ) && !CORBA::is_nil( aShape ) ) {
     // get shapes operations interface
     GEOM::GEOM_IShapesOperations_var anIShapesOperations =
-      aGeomGen->GetIShapesOperations( aShape->GetStudyID() );
+      aGeomGen->GetIShapesOperations();
     if ( !CORBA::is_nil( anIShapesOperations ) )
       aTypeName = anIShapesOperations->GetShapeTypeString( aShape );
   }
@@ -354,7 +351,7 @@ void TSetPropertyEvent::Execute()
   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
   if ( !study ) return;
   
-  GEOM_Displayer displayer( study );
+  GEOM_Displayer displayer;
   
   SALOME_View* window = displayer.GetActiveView();
   if ( !window ) return;
@@ -363,7 +360,7 @@ void TSetPropertyEvent::Execute()
 
   study->setObjectProperty( mgrId, myEntry, myProperty, myValue );
   
-  Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( myEntry.toLatin1().data(), "GEOM" );
+  Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( myEntry.toUtf8().data(), "GEOM" );
   if ( window->isVisible( io ) ) displayer.Redisplay( io, myUpdateViewer );
 }
 
@@ -391,6 +388,30 @@ void GEOM_Swig::setVectorsMode( const char* theEntry, bool theOn, bool theUpdate
                                            theOn, theUpdateViewer ) );
 }
 
+/*!
+  \brief Show / hide vertices for the presentation
+  \param theEntry geometry object's entry
+  \param theOn \c true to show vertices or \c false otherwise
+  \param theUpdateViewer \c true to update active view's contents
+*/
+void GEOM_Swig::setVerticesMode( const char* theEntry, bool theOn, bool theUpdateViewer )
+{
+  ProcessVoidEvent( new TSetPropertyEvent( theEntry, GEOM::propertyName( GEOM::Vertices ), 
+                                           theOn, theUpdateViewer ) );
+}
+
+/*!
+  \brief Show / hide name of shape for the presentation
+  \param theEntry geometry object's entry
+  \param theOn \c true to show name or \c false otherwise
+  \param theUpdateViewer \c true to update active view's contents
+*/
+void GEOM_Swig::setNameMode( const char* theEntry, bool theOn, bool theUpdateViewer )
+{
+  ProcessVoidEvent( new TSetPropertyEvent( theEntry, GEOM::propertyName( GEOM::ShowName ),
+                                           theOn, theUpdateViewer ) );
+}
+
 /*!
   \brief Change color of the presentation
   \param theEntry geometry object's entry
@@ -408,8 +429,8 @@ void GEOM_Swig::setColor( const char* theEntry, int theRed, int theGreen, int th
 /*!
   \brief Set number of iso-lines to the presentation
   \param theEntry geometry object's entry
-  \param theNbU number of iso-lines along U axis (interger value >= 0)
-  \param theNbV number of iso-lines along V axis (interger value >= 0)
+  \param theNbU number of iso-lines along U axis (integer value >= 0)
+  \param theNbV number of iso-lines along V axis (integer value >= 0)
   \param theUpdateViewer \c true to update active view's contents
 */
 void GEOM_Swig::setIsos( const char* theEntry, int theNbU, int theNbV, bool theUpdateViewer )
@@ -469,6 +490,119 @@ void GEOM_Swig::setMaterialProperty( const char* theEntry, const char* theMateri
                                            theMaterial, theUpdateViewer ) );
 }
 
+/*!
+  \brief initialize local subShapes selection on a given shape
+  \param theEntry geometry object's entry
+  \param theMode from enum TopAbs_ShapeEnum
+ */
+void GEOM_Swig::initLocalSelection( const char* theEntry, int theMode)
+{
+  class TEventInitLocalSelection: public SALOME_Event
+  {
+    std::string myEntry;
+    int myMode;
+  public:
+    TEventInitLocalSelection(const char* _entry, int _mode)
+    : myEntry(_entry), myMode(_mode)
+    {}
+    virtual void Execute()
+    {
+      if (myLocalSelector)
+        return;
+      SUIT_Application* app = SUIT_Session::session()->activeApplication();
+      if ( app )
+        {
+          //SUIT_ViewWindow* window = app->desktop()->activeWindow();
+          SUIT_ViewWindow* wnd = 0;
+          LightApp_Application* lapp = dynamic_cast<LightApp_Application*>(app);
+          if ( lapp )
+            {
+              SUIT_ViewManager* viewMgr = lapp->activeViewManager();
+              if ( viewMgr )
+                {
+                  wnd = viewMgr->getActiveView();
+                }
+              LightApp_SelectionMgr* mgr = lapp->selectionMgr();
+              if (!myOCCSelector)
+                {
+                  myOCCSelector = new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)viewMgr)->getOCCViewer(), mgr );
+                }
+
+              QList<SUIT_Selector*> aSelectorList;
+              mgr->selectors( "OCCViewer", aSelectorList );
+              for (int i=0; i< aSelectorList.size(); ++i)
+                {
+                  if ( LightApp_OCCSelector* aSelector = dynamic_cast<LightApp_OCCSelector*>( aSelectorList.at(i) ) )
+                    {
+                      aSelector->setEnabled(false);
+                    }
+                  if ( GEOMGUI_OCCSelector* aSelector = dynamic_cast<GEOMGUI_OCCSelector*>( aSelectorList.at(i) ) )
+                    {
+                      aSelector->setEnabled(true);
+                    }
+                }
+              myOCCSelector->setEnabled(true);
+            }
+
+          myLocalSelector = new GEOM_Swig_LocalSelector(app->desktop(), wnd, myEntry, myMode);
+          MESSAGE("TEventInitLocalSelection myLocalSelector: " << myLocalSelector);
+        }
+    }
+  };
+
+  ProcessVoidEvent(new TEventInitLocalSelection(theEntry, theMode));
+}
+
+/*!
+  \brief get local subShapes selection on a given shape
+  \return a list of selected subShapes indexes
+ */
+std::vector<int> GEOM_Swig::getLocalSelection()
+{
+  class TEventGetLocalSelection: public SALOME_Event
+  {
+  public:
+    typedef std::vector<int> TResult;
+    TResult myResult;
+
+    TEventGetLocalSelection(){}
+
+    virtual void Execute()
+    {
+      MESSAGE("TEventGetLocalSelection myLocalSelector: " << myLocalSelector);
+      if (myLocalSelector)
+        myResult = myLocalSelector->getSelection();
+    }
+  };
+
+  std::vector<int> result = ProcessEvent(new TEventGetLocalSelection());
+  return result;
+}
+
+/*!
+  \brief close local subShapes selection on a given shape
+ */
+void GEOM_Swig::closeLocalSelection()
+{
+  class TEventCloseLocalSelection: public SALOME_Event
+  {
+  public:
+    TEventCloseLocalSelection()
+    {}
+    virtual void Execute()
+    {
+      MESSAGE("TEventCloseLocalSelection myLocalSelector: " << myLocalSelector);
+      if (myLocalSelector)
+        {
+          delete myLocalSelector;
+          myLocalSelector = 0;
+        }
+    }
+  };
+
+  ProcessVoidEvent(new TEventCloseLocalSelection());
+}
+
 class TInitGeomGenEvent: public SALOME_Event
 {
 public:
@@ -484,7 +618,7 @@ public:
 
 /*!
   \brief Initialize GEOM module's engine
-  \return \c true if initialization succeedes or \c false otherwise
+  \return \c true if initialization succeeds or \c false otherwise
 */
 bool GEOM_Swig::initGeomGen()
 {