]> SALOME platform Git repositories - modules/smesh.git/blob - SMESHGUI/SMESHGUI_Swig.cxx
Salome HOME
bos #43434 [CEA][Windows] auto in function declaration
[modules/smesh.git] / SMESHGUI / SMESHGUI_Swig.cxx
1 using namespace std;
2 //  File      : SMESH_Swig.cxx
3 //  Created   : Mon Jun 17 13:41:43 2002
4 //  Author    : Nicolas REJNERI
5
6 //  Project   : SALOME
7 //  Module    : SMESH
8 //  Copyright : Open CASCADE 2002
9 //  $Header$
10
11
12 #include "SMESHGUI_Swig.hxx"
13
14 #include "Utils_ORB_INIT.hxx"
15 #include "Utils_SINGLETON.hxx"
16
17 // SALOME Includes
18 #include "QAD_Application.h"
19 #include "QAD_Desktop.h"
20 #include "QAD_ResourceMgr.h"
21
22 #include "utilities.h"
23
24 // Open CASCADE Includes
25 #include <TopoDS.hxx>
26
27 // IDL Headers
28 #include <SALOMEconfig.h>
29 #include CORBA_SERVER_HEADER(SMESH_Gen)
30 #include CORBA_SERVER_HEADER(SMESH_Mesh)
31 #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
32 #include CORBA_SERVER_HEADER(GEOM_Shape)
33
34 static CORBA::ORB_var _orb;
35
36 static char* ObjectToString (CORBA::Object_ptr obj)
37 {
38   return _orb->object_to_string(obj);
39 }
40
41 static CORBA::Object_ptr StringToObject (const char* ior)
42 {
43   return _orb->string_to_object(ior);
44 }
45
46 SMESH_Swig::SMESH_Swig()
47 {
48   MESSAGE("Constructeur");
49   setOrb();
50 }
51
52 void SMESH_Swig::Init(int studyID)
53 {
54   MESSAGE("Init");
55   Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "SMESH");
56   SMESH::SMESH_Gen_var CompMesh = SMESH::SMESH_Gen::_narrow(comp);
57
58   QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
59   if ( resMgr ) {
60     QString msg;
61     if (!resMgr->loadResources( "SMESH", msg ))
62       MESSAGE ( msg )
63   }
64
65   CORBA::Object_var obj = QAD_Application::getDesktop()->getNameService()->Resolve("/myStudyManager");
66   SALOMEDS::StudyManager_var myStudyMgr = SALOMEDS::StudyManager::_narrow(obj);
67   myStudy = myStudyMgr->GetStudyByID(studyID);
68   myStudyBuilder = myStudy->NewBuilder();
69   SALOMEDS::GenericAttribute_var anAttr;
70   SALOMEDS::AttributeName_var    aName;
71   SALOMEDS::AttributePixMap_var  aPixmap;
72
73   SALOMEDS::SComponent_var father = myStudy->FindComponent("MESH");
74   
75   if (father->_is_nil()) {
76     father = myStudyBuilder->NewComponent("MESH");
77     anAttr = myStudyBuilder->FindOrCreateAttribute(father, "AttributeName");
78     aName = SALOMEDS::AttributeName::_narrow(anAttr);
79     //NRI    aName->SetValue(QObject::tr("SMESH_MEN_COMPONENT"));
80     aName->SetValue( QAD_Application::getDesktop()->getComponentUserName( "SMESH" ) );
81     anAttr = myStudyBuilder->FindOrCreateAttribute(father, "AttributePixMap");
82     aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
83     aPixmap->SetPixMap( "ICON_OBJBROWSER_SMESH" );
84   }
85   myStudyBuilder->DefineComponentInstance(father, CompMesh );
86   mySComponentMesh = SALOMEDS::SComponent::_narrow( father );
87
88   // Tags definition 
89   Tag_HypothesisRoot  = 1;
90   Tag_AlgorithmsRoot  = 2;
91   
92   Tag_RefOnShape      = 1;
93   Tag_RefOnAppliedHypothesis = 2;
94   Tag_RefOnAppliedAlgorithms = 3;
95   
96   Tag_SubMeshOnVertex = 4;
97   Tag_SubMeshOnEdge = 5;
98   Tag_SubMeshOnFace = 6;
99   Tag_SubMeshOnSolid = 7;
100   Tag_SubMeshOnCompound = 8;
101 }
102
103 SMESH_Swig::~SMESH_Swig()
104 {
105   MESSAGE("Destructeur");
106 }
107
108
109 const char* SMESH_Swig::AddNewMesh(const char* IOR)
110 {
111   MESSAGE("AddNewMesh");
112   //Find or Create Hypothesis root
113   SALOMEDS::GenericAttribute_var    anAttr;
114   SALOMEDS::AttributeName_var       aName;
115   SALOMEDS::AttributeIOR_var        anIOR;
116   SALOMEDS::AttributeSelectable_var aSelAttr;
117   SALOMEDS::AttributePixMap_var     aPixmap;
118
119   SALOMEDS::SObject_var HypothesisRoot;
120   if (!mySComponentMesh->FindSubObject (Tag_HypothesisRoot, HypothesisRoot)) {
121     HypothesisRoot = myStudyBuilder->NewObjectToTag (mySComponentMesh, Tag_HypothesisRoot);
122     anAttr = myStudyBuilder->FindOrCreateAttribute(HypothesisRoot, "AttributeName");
123     aName = SALOMEDS::AttributeName::_narrow(anAttr);
124     aName->SetValue(QObject::tr("SMESH_MEN_HYPOTHESIS"));
125     anAttr = myStudyBuilder->FindOrCreateAttribute(HypothesisRoot, "AttributePixMap");
126     aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
127     aPixmap->SetPixMap( "ICON_SMESH_TREE_HYPO" );
128     anAttr = myStudyBuilder->FindOrCreateAttribute(HypothesisRoot, "AttributeSelectable");
129     aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
130     aSelAttr->SetSelectable(false);
131   }
132
133   SALOMEDS::SObject_var AlgorithmsRoot;
134   if (!mySComponentMesh->FindSubObject (Tag_AlgorithmsRoot, AlgorithmsRoot)) {
135     AlgorithmsRoot = myStudyBuilder->NewObjectToTag (mySComponentMesh, Tag_AlgorithmsRoot);
136     anAttr = myStudyBuilder->FindOrCreateAttribute(AlgorithmsRoot, "AttributeName");
137     aName = SALOMEDS::AttributeName::_narrow(anAttr);
138     aName->SetValue(QObject::tr("SMESH_MEN_ALGORITHMS"));
139     anAttr = myStudyBuilder->FindOrCreateAttribute(AlgorithmsRoot, "AttributePixMap");
140     aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
141     aPixmap->SetPixMap( "ICON_SMESH_TREE_ALGO" );
142     anAttr = myStudyBuilder->FindOrCreateAttribute(AlgorithmsRoot, "AttributeSelectable");
143     aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
144     aSelAttr->SetSelectable(false);
145   }
146
147   // Add New Mesh
148   SALOMEDS::SObject_var newMesh = myStudyBuilder->NewObject(mySComponentMesh);
149   anAttr = myStudyBuilder->FindOrCreateAttribute(newMesh, "AttributePixMap");
150   aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
151   aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH" );
152   anAttr = myStudyBuilder->FindOrCreateAttribute(newMesh, "AttributeIOR");
153   anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
154   anIOR->SetValue(IOR);
155   return SALOMEDS::SObject::_narrow( newMesh )->GetID();
156 }
157
158 const char* SMESH_Swig::AddNewHypothesis(const char* IOR)
159 {
160   MESSAGE("AddNewHypothesis");
161   //Find or Create Hypothesis root
162   SALOMEDS::SObject_var             HypothesisRoot;
163   SALOMEDS::GenericAttribute_var    anAttr;
164   SALOMEDS::AttributeName_var       aName;
165   SALOMEDS::AttributeIOR_var        anIOR;
166   SALOMEDS::AttributeSelectable_var aSelAttr;
167   SALOMEDS::AttributePixMap_var     aPixmap;
168
169   if (!mySComponentMesh->FindSubObject (Tag_HypothesisRoot, HypothesisRoot)) {
170     HypothesisRoot = myStudyBuilder->NewObjectToTag (mySComponentMesh, Tag_HypothesisRoot);
171     anAttr = myStudyBuilder->FindOrCreateAttribute(HypothesisRoot, "AttributeName");
172     aName = SALOMEDS::AttributeName::_narrow(anAttr);
173     aName->SetValue(QObject::tr("SMESH_MEN_HYPOTHESIS"));
174     anAttr = myStudyBuilder->FindOrCreateAttribute(HypothesisRoot, "AttributeSelectable");
175     aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
176     aSelAttr->SetSelectable(false);
177     anAttr = myStudyBuilder->FindOrCreateAttribute(HypothesisRoot, "AttributePixMap");
178     aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
179     aPixmap->SetPixMap( "ICON_SMESH_TREE_HYPO" );
180   }
181   // Add New Hypothesis
182   SALOMEDS::SObject_var newHypo = myStudyBuilder->NewObject(HypothesisRoot);
183   anAttr = myStudyBuilder->FindOrCreateAttribute(newHypo, "AttributePixMap");
184   aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
185   SMESH::SMESH_Hypothesis_var H = SMESH::SMESH_Hypothesis::_narrow( StringToObject(IOR) );
186   QString aType = H->GetName();
187   aPixmap->SetPixMap( "ICON_SMESH_TREE_HYPO_" + aType );
188 //    if ( aType.compare("LocalLength") == 0 )
189 //      aPixmap->SetPixMap( "ICON_SMESH_TREE_HYPO_LENGTH" );
190 //    else if ( aType.compare("NumberOfSegments") == 0 )
191 //      aPixmap->SetPixMap( "ICON_SMESH_TREE_HYPO_SEGMENT" );
192 //    else if ( aType.compare("MaxElementArea") == 0 )
193 //      aPixmap->SetPixMap( "ICON_SMESH_TREE_HYPO_AREA" );
194 //    else if ( aType.compare("MaxElementVolume") == 0 )
195 //      aPixmap->SetPixMap( "ICON_SMESH_TREE_HYPO_VOLUME" );
196   anAttr = myStudyBuilder->FindOrCreateAttribute(newHypo, "AttributeIOR");
197   anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
198   anIOR->SetValue(IOR);
199   return SALOMEDS::SObject::_narrow(newHypo)->GetID();
200 }
201
202 const char* SMESH_Swig::AddNewAlgorithms(const char* IOR)
203 {
204   MESSAGE("AddNewAlgorithms");
205   //Find or Create Algorithms root
206   SALOMEDS::SObject_var             AlgorithmsRoot;
207   SALOMEDS::GenericAttribute_var    anAttr;
208   SALOMEDS::AttributeName_var       aName;
209   SALOMEDS::AttributeIOR_var        anIOR;
210   SALOMEDS::AttributeSelectable_var aSelAttr;
211   SALOMEDS::AttributePixMap_var     aPixmap;
212
213   if (!mySComponentMesh->FindSubObject (Tag_AlgorithmsRoot, AlgorithmsRoot)) {
214     AlgorithmsRoot = myStudyBuilder->NewObjectToTag (mySComponentMesh, Tag_AlgorithmsRoot);
215     anAttr = myStudyBuilder->FindOrCreateAttribute(AlgorithmsRoot, "AttributeName");
216     aName = SALOMEDS::AttributeName::_narrow(anAttr);
217     aName->SetValue(QObject::tr("SMESH_MEN_ALGORITHMS"));
218     anAttr = myStudyBuilder->FindOrCreateAttribute(AlgorithmsRoot, "AttributeSelectable");
219     aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
220     aSelAttr->SetSelectable(false);
221     anAttr = myStudyBuilder->FindOrCreateAttribute(AlgorithmsRoot, "AttributePixMap");
222     aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
223     aPixmap->SetPixMap( "ICON_SMESH_TREE_ALGO" );
224   }
225   // Add New Algorithms
226   SALOMEDS::SObject_var newHypo = myStudyBuilder->NewObject(AlgorithmsRoot);
227   anAttr = myStudyBuilder->FindOrCreateAttribute(newHypo, "AttributePixMap");
228   aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
229   SMESH::SMESH_Hypothesis_var H = SMESH::SMESH_Hypothesis::_narrow( StringToObject(IOR) );
230   QString aType = H->GetName();
231   aPixmap->SetPixMap( "ICON_SMESH_TREE_ALGO_" + aType );
232 //    if ( aType.compare("Regular_1D") == 0 )
233 //      aPixmap->SetPixMap( "ICON_SMESH_TREE_ALGO_REGULAR" );
234 //    else if ( aType.compare("MEFISTO_2D") == 0 )
235 //      aPixmap->SetPixMap( "ICON_SMESH_TREE_ALGO_MEFISTO" );
236 //    else if ( aType.compare("Quadrangle_2D") == 0 )
237 //      aPixmap->SetPixMap( "ICON_SMESH_TREE_ALGO_QUAD" );
238 //    else if ( aType.compare("Hexa_3D") == 0 )
239 //      aPixmap->SetPixMap( "ICON_SMESH_TREE_ALGO_HEXA" );
240   anAttr = myStudyBuilder->FindOrCreateAttribute(newHypo, "AttributeIOR");
241   anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
242   anIOR->SetValue(IOR);
243   return SALOMEDS::SObject::_narrow(newHypo)->GetID();
244 }
245
246 void SMESH_Swig::SetShape(const char* ShapeEntry, const char* MeshEntry)
247 {
248   SALOMEDS::SObject_var SO_MorSM = myStudy->FindObjectID( MeshEntry );
249   SALOMEDS::SObject_var SO_GeomShape = myStudy->FindObjectID( ShapeEntry );
250
251   if ( !SO_MorSM->_is_nil() && !SO_GeomShape->_is_nil() ) {
252     SALOMEDS::SObject_var SO = myStudyBuilder->NewObjectToTag (SO_MorSM, Tag_RefOnShape);
253     myStudyBuilder->Addreference (SO,SO_GeomShape);
254   }
255 }
256
257 void SMESH_Swig::SetHypothesis(const char* Mesh_Or_SubMesh_Entry, const char* Hypothesis_Entry)
258 {
259   SALOMEDS::SObject_var SO_MorSM = myStudy->FindObjectID( Mesh_Or_SubMesh_Entry );
260   SALOMEDS::SObject_var SO_Hypothesis = myStudy->FindObjectID( Hypothesis_Entry );
261   SALOMEDS::GenericAttribute_var    anAttr;
262   SALOMEDS::AttributeName_var       aName;
263   SALOMEDS::AttributeSelectable_var aSelAttr;
264   SALOMEDS::AttributePixMap_var     aPixmap;
265
266   if ( !SO_MorSM->_is_nil() && !SO_Hypothesis->_is_nil() ) {
267     
268     //Find or Create Applied Hypothesis root
269     SALOMEDS::SObject_var AHR;
270     if (!SO_MorSM->FindSubObject (Tag_RefOnAppliedHypothesis, AHR)) {
271       AHR = myStudyBuilder->NewObjectToTag (SO_MorSM, Tag_RefOnAppliedHypothesis);
272       anAttr = myStudyBuilder->FindOrCreateAttribute(AHR, "AttributeName");
273       aName = SALOMEDS::AttributeName::_narrow(anAttr);
274       aName->SetValue(QObject::tr("SMESH_MEN_APPLIED_HYPOTHESIS"));
275       anAttr = myStudyBuilder->FindOrCreateAttribute(AHR, "AttributeSelectable");
276       aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
277       aSelAttr->SetSelectable(false);
278       anAttr = myStudyBuilder->FindOrCreateAttribute(AHR, "AttributePixMap");
279       aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
280       aPixmap->SetPixMap( "ICON_SMESH_TREE_HYPO" );
281     }
282     SALOMEDS::SObject_var SO = myStudyBuilder->NewObject(AHR);
283     myStudyBuilder->Addreference (SO,SO_Hypothesis);
284   }
285 }
286 void SMESH_Swig::SetAlgorithms(const char* Mesh_Or_SubMesh_Entry, const char* Algorithms_Entry)
287 {
288   SALOMEDS::SObject_var SO_MorSM = myStudy->FindObjectID( Mesh_Or_SubMesh_Entry );
289   SALOMEDS::SObject_var SO_Algorithms = myStudy->FindObjectID( Algorithms_Entry );
290   SALOMEDS::GenericAttribute_var    anAttr;
291   SALOMEDS::AttributeName_var       aName;
292   SALOMEDS::AttributeSelectable_var aSelAttr;
293   SALOMEDS::AttributePixMap_var     aPixmap;
294
295   if ( !SO_MorSM->_is_nil() && !SO_Algorithms->_is_nil() ) {
296     //Find or Create Applied Algorithms root
297     SALOMEDS::SObject_var AHR;
298     if (!SO_MorSM->FindSubObject (Tag_RefOnAppliedAlgorithms, AHR)) {
299       AHR = myStudyBuilder->NewObjectToTag (SO_MorSM, Tag_RefOnAppliedAlgorithms);
300       anAttr = myStudyBuilder->FindOrCreateAttribute(AHR, "AttributeName");
301       aName = SALOMEDS::AttributeName::_narrow(anAttr);
302       aName->SetValue(QObject::tr("SMESH_MEN_APPLIED_ALGORIHTMS"));
303       anAttr = myStudyBuilder->FindOrCreateAttribute(AHR, "AttributeSelectable");
304       aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
305       aSelAttr->SetSelectable(false);
306       anAttr = myStudyBuilder->FindOrCreateAttribute(AHR, "AttributePixMap");
307       aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
308       aPixmap->SetPixMap( "ICON_SMESH_TREE_ALGO" );
309     }
310     SALOMEDS::SObject_var SO = myStudyBuilder->NewObject(AHR);
311     myStudyBuilder->Addreference (SO,SO_Algorithms);
312   }
313 }
314
315 void SMESH_Swig::UnSetHypothesis(const char* Applied_Hypothesis_Entry )
316 {
317   SALOMEDS::SObject_var SO_Applied_Hypothesis = myStudy->FindObjectID( Applied_Hypothesis_Entry );
318   if ( !SO_Applied_Hypothesis->_is_nil() )
319     myStudyBuilder->RemoveObject(SO_Applied_Hypothesis);
320 }
321
322
323 const char* SMESH_Swig::AddSubMesh(const char* SO_Mesh_Entry, const char* SM_IOR, int ST)
324 {
325   SALOMEDS::SObject_var SO_Mesh = myStudy->FindObjectID( SO_Mesh_Entry );
326   if ( !SO_Mesh->_is_nil() ) {
327
328     long Tag_Shape ;
329     Standard_CString Name;
330     
331     if      (ST == TopAbs_SOLID) {Tag_Shape = Tag_SubMeshOnSolid;    Name = strdup(QObject::tr("SMESH_MEN_SubMeshesOnSolid"));}
332     else if (ST == TopAbs_FACE)  {Tag_Shape = Tag_SubMeshOnFace;     Name = strdup(QObject::tr("SMESH_MEN_SubMeshesOnFace"));}
333     else if (ST == TopAbs_EDGE)  {Tag_Shape = Tag_SubMeshOnEdge;     Name = strdup(QObject::tr("SMESH_MEN_SubMeshesOnEdge"));}
334     else if (ST == TopAbs_VERTEX){Tag_Shape = Tag_SubMeshOnVertex;   Name = strdup(QObject::tr("SMESH_MEN_SubMeshesOnVertex"));}
335     else {
336       Tag_Shape = Tag_SubMeshOnCompound; Name = strdup(QObject::tr("SMESH_MEN_SubMeshesOnCompound"));
337     }
338     SALOMEDS::SObject_var SubmeshesRoot;
339     SALOMEDS::GenericAttribute_var        anAttr;
340     SALOMEDS::AttributeName_var           aName;
341     SALOMEDS::AttributeIOR_var            anIOR;
342     SALOMEDS::AttributeSelectable_var     aSelAttr;
343     if (!SO_Mesh->FindSubObject (Tag_Shape,SubmeshesRoot )) {
344       SubmeshesRoot = myStudyBuilder->NewObjectToTag (SO_Mesh, Tag_Shape);
345       anAttr = myStudyBuilder->FindOrCreateAttribute(SubmeshesRoot, "AttributeName");
346       aName = SALOMEDS::AttributeName::_narrow(anAttr);
347       aName->SetValue(Name);
348       anAttr = myStudyBuilder->FindOrCreateAttribute(SubmeshesRoot, "AttributeSelectable");
349       aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
350       aSelAttr->SetSelectable(false);
351     }
352     SALOMEDS::SObject_var SO = myStudyBuilder->NewObject (SubmeshesRoot);
353     anAttr = myStudyBuilder->FindOrCreateAttribute(SO, "AttributeIOR");
354     anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
355     anIOR->SetValue(SM_IOR);
356     return SALOMEDS::SObject::_narrow( SO )->GetID();
357   }
358   return "";
359 }
360
361 const char* SMESH_Swig::AddSubMeshOnShape(const char* Mesh_Entry, const char* GeomShape_Entry, 
362                                              const char* SM_IOR, int ST)
363 {
364   SALOMEDS::SObject_var SO_GeomShape = myStudy->FindObjectID( GeomShape_Entry );
365   if ( !SO_GeomShape->_is_nil() ) {
366     const char * SM_Entry = AddSubMesh (Mesh_Entry,SM_IOR,ST);
367     SALOMEDS::SObject_var SO_SM = myStudy->FindObjectID( SM_Entry );
368     if ( !SO_SM->_is_nil() ) {
369       SetShape (GeomShape_Entry, SM_Entry);
370       return SALOMEDS::SObject::_narrow( SO_SM )->GetID();
371     }
372   }
373   return "";
374 }
375
376 void SMESH_Swig::CreateAndDisplayActor( const char* Mesh_Entry )
377 {
378   //  SMESH_Actor* Mesh = smeshGUI->ReadScript(aM);
379 }
380
381 void SMESH_Swig::SetName(const char* Entry, const char* Name)
382 {
383   SALOMEDS::SObject_var SO = myStudy->FindObjectID( Entry );
384   SALOMEDS::GenericAttribute_var anAttr;
385   SALOMEDS::AttributeName_var    aName;
386   if ( !SO->_is_nil() )  {
387     anAttr = myStudyBuilder->FindOrCreateAttribute(SO, "AttributeName");
388     aName = SALOMEDS::AttributeName::_narrow(anAttr);
389     aName->SetValue(Name);
390   }
391 }
392
393
394 void SMESH_Swig::setOrb()
395 {
396   try {
397     ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
398     ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
399     _orb = init( 0 , 0 );
400   } catch (...) {
401     INFOS("internal error : orb not found");
402     _orb = 0;
403   }
404   ASSERT(! CORBA::is_nil(_orb));
405 }