Salome HOME
PAL10237. Add a button assigning a set of hypotheses
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Swig.cxx
index b82c7b32a0ff30ae803bf6fd4d2faff6d23dfb51..d8a0805e3da46398c16a278d572ded7f16cc79a3 100644 (file)
@@ -32,10 +32,17 @@ using namespace std;
 #include "Utils_ORB_INIT.hxx"
 #include "Utils_SINGLETON.hxx"
 
+#include "SMESHGUI.h"
+#include "SMESHGUI_Utils.h"
+#include "SMESHGUI_GEOMGenUtils.h"
+
 // SALOME Includes
-#include "QAD_Application.h"
-#include "QAD_Desktop.h"
-#include "QAD_ResourceMgr.h"
+#include "SUIT_ResourceMgr.h"
+#include "SUIT_Session.h"
+
+#include "SALOMEDS_SObject.hxx"
+
+#include "SalomeApp_Application.h"
 
 #include "utilities.h"
 
@@ -50,11 +57,6 @@ using namespace std;
 
 static CORBA::ORB_var _orb;
 
-static char* ObjectToString (CORBA::Object_ptr obj)
-{
-  return _orb->object_to_string(obj);
-}
-
 static CORBA::Object_ptr StringToObject (const char* ior)
 {
   return _orb->string_to_object(ior);
@@ -69,20 +71,22 @@ SMESH_Swig::SMESH_Swig()
 void SMESH_Swig::Init(int studyID)
 {
   MESSAGE("Init");
-  Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "SMESH");
-  SMESH::SMESH_Gen_var CompMesh = SMESH::SMESH_Gen::_narrow(comp);
-
-  Engines::Component_var comp1 = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
-  GEOM::GEOM_Gen_var CompGeom = GEOM::GEOM_Gen::_narrow(comp1);
+  SMESH::SMESH_Gen_var CompMesh = SMESHGUI::GetSMESHGen();
+  GEOM::GEOM_Gen_var CompGeom = SMESH::GetGEOMGen();
 
-  QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
+  SUIT_ResourceMgr* resMgr = SMESHGUI::resourceMgr();
   if ( resMgr ) {
-    QString msg;
+    resMgr->loadLanguage( QString::null, "en" );
+    /*QString msg;
     if (!resMgr->loadResources( "SMESH", msg ))
-      MESSAGE ( msg )
+      MESSAGE ( msg )*/
   }
 
-  CORBA::Object_var obj = QAD_Application::getDesktop()->getNameService()->Resolve("/myStudyManager");
+  SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
+  if( !app )
+    return;
+
+  CORBA::Object_var obj = app->namingService()->Resolve("/myStudyManager");
   SALOMEDS::StudyManager_var myStudyMgr = SALOMEDS::StudyManager::_narrow(obj);
   myStudy = myStudyMgr->GetStudyByID(studyID);
 
@@ -95,7 +99,7 @@ void SMESH_Swig::Init(int studyID)
 
   // See return value of SMESH::SMESH_Gen::ComponentDataType()
   SALOMEDS::SComponent_var father = myStudy->FindComponent("SMESH");
-  
+
   if (father->_is_nil()) {
     bool aLocked = myStudy->GetProperties()->IsLocked();
     if (aLocked) myStudy->GetProperties()->SetLocked(false);
@@ -103,7 +107,19 @@ void SMESH_Swig::Init(int studyID)
     anAttr = myStudyBuilder->FindOrCreateAttribute(father, "AttributeName");
     aName = SALOMEDS::AttributeName::_narrow(anAttr);
     //NRI    aName->SetValue(QObject::tr("SMESH_MEN_COMPONENT"));
-    aName->SetValue( QAD_Application::getDesktop()->getComponentUserName( "SMESH" ) );
+    SMESHGUI* gui = SMESHGUI::GetSMESHGUI(); //SRN: BugID IPAL9186, load a SMESH gui if it hasn't been loaded
+    if(!gui) {
+      SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication()); 
+      if(app) {
+        CAM_Module* module = app->module( "Mesh" );
+       if(!module) module = app->loadModule("Mesh");
+       gui = dynamic_cast<SMESHGUI*>( module ); 
+      }
+      else {
+        MESSAGE("Can't find the application");
+      }
+    }  //SRN: BugID IPAL9186: end of a fix
+    aName->SetValue( gui->moduleName() );
     anAttr = myStudyBuilder->FindOrCreateAttribute(father, "AttributePixMap");
     aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
     aPixmap->SetPixMap( "ICON_OBJBROWSER_SMESH" );
@@ -132,7 +148,6 @@ SMESH_Swig::~SMESH_Swig()
   MESSAGE("Destructeur");
 }
 
-
 const char* SMESH_Swig::AddNewMesh(const char* IOR)
 {
   MESSAGE("AddNewMesh");
@@ -328,6 +343,7 @@ void SMESH_Swig::SetHypothesis(const char* Mesh_Or_SubMesh_Entry, const char* Hy
     myStudyBuilder->Addreference (SO,SO_Hypothesis);
   }
 }
+
 void SMESH_Swig::SetAlgorithms(const char* Mesh_Or_SubMesh_Entry, const char* Algorithms_Entry)
 {
   SALOMEDS::SObject_var SO_MorSM = myStudy->FindObjectID( Mesh_Or_SubMesh_Entry );
@@ -364,7 +380,6 @@ void SMESH_Swig::UnSetHypothesis(const char* Applied_Hypothesis_Entry )
     myStudyBuilder->RemoveObject(SO_Applied_Hypothesis);
 }
 
-
 const char* SMESH_Swig::AddSubMesh(const char* SO_Mesh_Entry, const char* SM_IOR, int ST)
 {
   SALOMEDS::SObject_var SO_Mesh = myStudy->FindObjectID( SO_Mesh_Entry );
@@ -438,7 +453,6 @@ void SMESH_Swig::SetName(const char* Entry, const char* Name)
   }
 }
 
-
 void SMESH_Swig::setOrb()
 {
   try {
@@ -451,3 +465,21 @@ void SMESH_Swig::setOrb()
   }
   ASSERT(! CORBA::is_nil(_orb));
 }
+
+//================================================================================
+/*!
+ * \brief Set mesh icon according to compute status
+  * \param Mesh_Entry - entry of a mesh
+  * \param isComputed - is mesh computed or not
+ */
+//================================================================================
+
+void SMESH_Swig::SetMeshIcon(const char* Mesh_Entry, const bool isComputed)
+{
+  SALOMEDS::SObject_var mesh_var = myStudy->FindObjectID( Mesh_Entry );
+  if ( !mesh_var->_is_nil() ) {
+    _PTR(SObject) mesh = _PTR(SObject)(new SALOMEDS_SObject( mesh_var ));
+    if ( mesh )
+      SMESH::ModifiedMesh( mesh, isComputed );
+  }
+}