]> SALOME platform Git repositories - modules/smesh.git/blob - src/SMESHGUI/SMESHGUI_Swig.cxx
Salome HOME
Merging with WPdev
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Swig.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : SMESH_Swig.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27 //  $Header$
28
29 #include "SMESHGUI_Swig.hxx"
30
31 #include "Utils_ORB_INIT.hxx"
32 #include "Utils_SINGLETON.hxx"
33
34 #include "SMESHGUI.h"
35 #include "SMESHGUI_Utils.h"
36 #include "SMESHGUI_GEOMGenUtils.h"
37 #include "SMESHGUI_Displayer.h"
38
39 // SALOME Includes
40 #include "SUIT_ResourceMgr.h"
41 #include "SUIT_Session.h"
42 #include "SUIT_ViewModel.h"
43 #include "VTKViewer_ViewModel.h"
44
45 #include "SALOME_Event.hxx"
46 #include "SALOME_NamingService.hxx"
47 #include "SalomeApp_Application.h"
48 #include "SALOMEDSClient_ClientFactory.hxx"
49
50 #include "utilities.h"
51
52 // Open CASCADE Includes
53 #include <TopoDS.hxx>
54
55 // QT Includes
56 #include <qapplication.h>
57
58 // IDL Headers
59 #include <SALOMEconfig.h>
60 #include CORBA_SERVER_HEADER(SMESH_Gen)
61 #include CORBA_SERVER_HEADER(SMESH_Mesh)
62 #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
63
64 using namespace std;
65
66 static CORBA::ORB_var anORB;
67
68 // Tags definition 
69 static long Tag_HypothesisRoot = 1;
70 static long Tag_AlgorithmsRoot = 2;
71   
72 static long Tag_RefOnShape = 1;
73 static long Tag_RefOnAppliedHypothesis = 2;
74 static long Tag_RefOnAppliedAlgorithms = 3;
75
76 static long Tag_SubMeshOnVertex = 4;
77 static long Tag_SubMeshOnEdge = 5;
78 static long Tag_SubMeshOnFace = 6;
79 static long Tag_SubMeshOnSolid = 7;
80 static long Tag_SubMeshOnCompound  = 8;
81
82 namespace
83 {
84   //---------------------------------------------------------------
85   inline
86   CORBA::Object_var
87   StringToObject(const std::string& theIOR)
88   {
89     return anORB->string_to_object(theIOR.c_str());
90   }
91
92
93   //---------------------------------------------------------------
94   inline
95   SALOMEDS::SObject_var
96   GetDomainRoot(const SALOMEDS::SComponent_var& theSComponentMesh,
97                 const SALOMEDS::StudyBuilder_var& theStudyBuilder,
98                 CORBA::Long theDomainRootTag,
99                 const QString& theName,
100                 const QString& thePixmap)
101   {
102     SALOMEDS::SObject_var aDomainRoot;
103     if (!theSComponentMesh->FindSubObject(theDomainRootTag,aDomainRoot)) {
104       aDomainRoot = theStudyBuilder->NewObjectToTag(theSComponentMesh,theDomainRootTag);
105       SALOMEDS::GenericAttribute_var anAttr = theStudyBuilder->FindOrCreateAttribute(aDomainRoot,"AttributeName");
106       SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
107       aName->SetValue(theName.latin1());
108       anAttr = theStudyBuilder->FindOrCreateAttribute(aDomainRoot,"AttributePixMap");
109       SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
110       aPixmap->SetPixMap(thePixmap.latin1());
111       anAttr = theStudyBuilder->FindOrCreateAttribute(aDomainRoot,"AttributeSelectable");
112       SALOMEDS::AttributeSelectable_var aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
113       aSelAttr->SetSelectable(false);
114     }
115
116     return aDomainRoot;
117   }
118
119
120   //---------------------------------------------------------------
121   inline
122   SALOMEDS::SObject_var
123   GetHypothesisRoot(const SALOMEDS::SComponent_var& theSComponentMesh,
124                     const SALOMEDS::StudyBuilder_var& theStudyBuilder)
125   {
126     return GetDomainRoot(theSComponentMesh,
127                          theStudyBuilder,
128                          Tag_HypothesisRoot,
129                          QObject::tr("SMESH_MEN_HYPOTHESIS"),
130                          "ICON_SMESH_TREE_HYPO");
131   }
132   
133
134   //---------------------------------------------------------------
135   inline
136   SALOMEDS::SObject_var
137   GetAlgorithmsRoot(const SALOMEDS::SComponent_var& theSComponentMesh,
138                     const SALOMEDS::StudyBuilder_var& theStudyBuilder)
139   {
140     return GetDomainRoot(theSComponentMesh,
141                          theStudyBuilder,
142                          Tag_AlgorithmsRoot,
143                          QObject::tr("SMESH_MEN_ALGORITHMS"),
144                          "ICON_SMESH_TREE_ALGO");
145   }
146
147
148   //---------------------------------------------------------------
149   inline
150   SALOMEDS::SObject_var
151   AddToDomain(const std::string& theIOR,
152               const SALOMEDS::SComponent_var& theSComponentMesh,
153               const SALOMEDS::StudyBuilder_var& theStudyBuilder,
154               CORBA::Long theDomainRootTag,
155               const QString& theDomainName,
156               const QString& theDomainPixmap)
157   {
158     SALOMEDS::SObject_var aDomain = GetDomainRoot(theSComponentMesh,
159                                                   theStudyBuilder,
160                                                   Tag_AlgorithmsRoot,
161                                                   theDomainName,
162                                                   theDomainPixmap);
163     // Add New Hypothesis
164     SALOMEDS::SObject_var aSObject = theStudyBuilder->NewObject(aDomain);
165     SALOMEDS::GenericAttribute_var anAttr = theStudyBuilder->FindOrCreateAttribute(aSObject,"AttributePixMap");
166     SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
167     CORBA::Object_var anObject = StringToObject(theIOR);
168     SMESH::SMESH_Hypothesis_var aDomainItem = SMESH::SMESH_Hypothesis::_narrow(anObject.in());
169     CORBA::String_var aType = aDomainItem->GetName();
170     QString aPixmapName = theDomainPixmap + "_" + aType.in();
171     aPixmap->SetPixMap(aPixmapName.latin1());
172     anAttr = theStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeIOR");
173     SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
174     anIOR->SetValue(theIOR.c_str());
175     
176     return aSObject;
177   }
178
179
180   //---------------------------------------------------------------
181   SALOMEDS::SObject_var
182   AddHypothesis(const std::string& theIOR,
183                 const SALOMEDS::SComponent_var& theSComponentMesh,
184                 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
185   {
186     return AddToDomain(theIOR,
187                        theSComponentMesh,
188                        theStudyBuilder,
189                        Tag_HypothesisRoot,
190                        QObject::tr("SMESH_MEN_HYPOTHESIS"),
191                        "ICON_SMESH_TREE_HYPO");
192   }
193
194
195   //---------------------------------------------------------------
196   SALOMEDS::SObject_var
197   AddAlgorithms(const std::string& theIOR,
198                 const SALOMEDS::SComponent_var& theSComponentMesh,
199                 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
200   {
201     return AddToDomain(theIOR,
202                        theSComponentMesh,
203                        theStudyBuilder,
204                        Tag_AlgorithmsRoot,
205                        QObject::tr("SMESH_MEN_ALGORITHMS"),
206                        "ICON_SMESH_TREE_ALGO");
207   }
208
209
210   //---------------------------------------------------------------
211   void
212   SetDomain(const char* theMeshOrSubMeshEntry, 
213             const char* theDomainEntry,
214             const SALOMEDS::Study_var& theStudy,
215             const SALOMEDS::StudyBuilder_var& theStudyBuilder,
216             long theRefOnAppliedDomainTag,
217             const QString& theAppliedDomainMEN,
218             const QString& theAppliedDomainICON)
219   {
220     SALOMEDS::SObject_var aMeshOrSubMeshSO = theStudy->FindObjectID(theMeshOrSubMeshEntry);
221     SALOMEDS::SObject_var aHypothesisSO = theStudy->FindObjectID(theDomainEntry);
222
223     if(!aMeshOrSubMeshSO->_is_nil() && !aHypothesisSO->_is_nil()){
224       //Find or Create Applied Hypothesis root
225       SALOMEDS::SObject_var anAppliedDomainSO;
226       if(!aMeshOrSubMeshSO->FindSubObject(theRefOnAppliedDomainTag,anAppliedDomainSO)){
227         anAppliedDomainSO = theStudyBuilder->NewObjectToTag(aMeshOrSubMeshSO,theRefOnAppliedDomainTag);
228         SALOMEDS::GenericAttribute_var anAttr = 
229           theStudyBuilder->FindOrCreateAttribute(anAppliedDomainSO,"AttributeName");
230         SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
231         aName->SetValue(theAppliedDomainMEN.latin1());
232         anAttr = theStudyBuilder->FindOrCreateAttribute(anAppliedDomainSO,"AttributeSelectable");
233         SALOMEDS::AttributeSelectable_var aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
234         aSelAttr->SetSelectable(false);
235         anAttr = theStudyBuilder->FindOrCreateAttribute(anAppliedDomainSO,"AttributePixMap");
236         SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
237         aPixmap->SetPixMap(theAppliedDomainICON.latin1());
238       }
239       SALOMEDS::SObject_var aSObject = theStudyBuilder->NewObject(anAppliedDomainSO);
240       theStudyBuilder->Addreference(aSObject,aHypothesisSO);
241     }
242   }
243
244
245   //---------------------------------------------------------------
246   void
247   SetHypothesis(const char* theMeshOrSubMeshEntry, 
248                 const char* theDomainEntry,
249                 const SALOMEDS::Study_var& theStudy,
250                 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
251   {
252     SetDomain(theMeshOrSubMeshEntry,
253               theDomainEntry,
254               theStudy,
255               theStudyBuilder,
256               Tag_RefOnAppliedHypothesis,
257               QObject::tr("SMESH_MEN_APPLIED_HYPOTHESIS"),
258               "ICON_SMESH_TREE_HYPO");
259   }
260
261
262   //---------------------------------------------------------------
263   void
264   SetAlgorithms(const char* theMeshOrSubMeshEntry, 
265                 const char* theDomainEntry,
266                 const SALOMEDS::Study_var& theStudy,
267                 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
268   {
269     SetDomain(theMeshOrSubMeshEntry,
270               theDomainEntry,
271               theStudy,
272               theStudyBuilder,
273               Tag_RefOnAppliedAlgorithms,
274               QObject::tr("SMESH_MEN_APPLIED_ALGORIHTMS"),
275               "ICON_SMESH_TREE_ALGO");
276   }
277 }
278
279
280 //===============================================================
281 SMESH_Swig::SMESH_Swig()
282 {
283   class TEvent: public SALOME_Event
284   {
285     CORBA::ORB_var& myORB;
286   public:
287
288     TEvent(CORBA::ORB_var& theORB):
289       myORB(theORB)
290     {}
291
292     virtual
293     void
294     Execute()
295     {
296       try {
297         ORB_INIT &anORBInit = *SINGLETON_<ORB_INIT>::Instance();
298         ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
299         myORB = anORBInit( 0 , 0 );
300       } catch (...) {
301         INFOS("internal error : orb not found");
302       }
303     }
304   };
305
306   MESSAGE("Constructeur");
307
308   if(CORBA::is_nil(anORB))
309     ProcessVoidEvent(new TEvent(anORB));
310
311   ASSERT(!CORBA::is_nil(anORB));
312 }
313
314
315 //===============================================================
316 void
317 SMESH_Swig::Init(int theStudyID)
318 {
319   class TEvent: public SALOME_Event
320   {
321     int myStudyID;
322     SALOMEDS::Study_var& myStudy;
323     SALOMEDS::StudyBuilder_var& myStudyBuilder;
324     SALOMEDS::SComponent_var& mySComponentMesh;
325   public:
326     TEvent(int theStudyID,
327            SALOMEDS::Study_var& theStudy,
328            SALOMEDS::StudyBuilder_var& theStudyBuilder,
329            SALOMEDS::SComponent_var& theSComponentMesh):
330       myStudyID(theStudyID),
331       myStudy(theStudy),
332       myStudyBuilder(theStudyBuilder),
333       mySComponentMesh(theSComponentMesh)
334     {}
335
336     virtual
337     void
338     Execute()
339     {
340       SUIT_Session* aSession = SUIT_Session::session();
341       SUIT_Application* anApplication = aSession->activeApplication();
342       SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
343
344       SALOME_NamingService* aNamingService = anApp->namingService();
345       CORBA::Object_var anObject = aNamingService->Resolve("/myStudyManager");
346       SALOMEDS::StudyManager_var aStudyMgr = SALOMEDS::StudyManager::_narrow(anObject);
347       myStudy = aStudyMgr->GetStudyByID(myStudyID);
348
349       SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
350       aSMESHGen->SetCurrentStudy( myStudy.in() ); 
351
352       myStudyBuilder = myStudy->NewBuilder();
353
354       SALOMEDS::GenericAttribute_var anAttr;
355       SALOMEDS::AttributeName_var    aName;
356       SALOMEDS::AttributePixMap_var  aPixmap;
357
358       SALOMEDS::SComponent_var aSComponent = myStudy->FindComponent("SMESH");
359       if(aSComponent->_is_nil()){
360         bool aLocked = myStudy->GetProperties()->IsLocked();
361         if (aLocked) 
362           myStudy->GetProperties()->SetLocked(false);
363         
364         aSComponent = myStudyBuilder->NewComponent("SMESH");
365         anAttr = myStudyBuilder->FindOrCreateAttribute(aSComponent,"AttributeName");
366         aName = SALOMEDS::AttributeName::_narrow(anAttr);
367
368         SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI(); //SRN: BugID IPAL9186, load a SMESH gui if it hasn't been loaded
369         if(!aSMESHGUI){
370           CAM_Module* aModule = anApp->module("Mesh");
371           if(!aModule) 
372               aModule = anApp->loadModule("Mesh");
373           aSMESHGUI = dynamic_cast<SMESHGUI*>(aModule); 
374         } //SRN: BugID IPAL9186: end of a fix
375         aName->SetValue(aSMESHGUI->moduleName());
376         anAttr = myStudyBuilder->FindOrCreateAttribute(aSComponent,"AttributePixMap");
377         aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
378         aPixmap->SetPixMap( "ICON_OBJBROWSER_SMESH" );
379         myStudyBuilder->DefineComponentInstance(aSComponent,aSMESHGen);
380         if(aLocked) 
381           myStudy->GetProperties()->SetLocked(true);
382       }
383
384       mySComponentMesh = SALOMEDS::SComponent::_narrow(aSComponent);
385
386       qApp->processEvents(); // Workaround for bug 12662
387     }
388   };
389
390   MESSAGE("Init");
391
392   ProcessVoidEvent(new TEvent(theStudyID,
393                               myStudy,
394                               myStudyBuilder,
395                               mySComponentMesh));
396 }
397
398
399 //===============================================================
400 SMESH_Swig::~SMESH_Swig()
401 {
402   MESSAGE("Destructeur");
403 }
404
405
406 //===============================================================
407 const char* 
408 SMESH_Swig::AddNewMesh(const char* theIOR)
409 {
410   MESSAGE("AddNewMesh");
411
412   // VSR: added temporarily - to be removed - objects are published automatically by engine
413   SALOMEDS::SObject_var aSObject = myStudy->FindObjectIOR(theIOR);
414   if(aSObject->_is_nil()){
415     //Find or Create Hypothesis root
416     GetHypothesisRoot(mySComponentMesh,myStudyBuilder);
417     GetAlgorithmsRoot(mySComponentMesh,myStudyBuilder);
418     
419     // Add New Mesh
420     aSObject = myStudyBuilder->NewObject(mySComponentMesh);
421     SALOMEDS::GenericAttribute_var anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributePixMap");
422     SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
423     aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH" );
424     anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeIOR");
425     SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
426     anIOR->SetValue(theIOR);
427   }
428
429   CORBA::String_var anEntry = aSObject->GetID();
430
431   return anEntry._retn();
432 }
433
434
435 //===============================================================
436 const char* 
437 SMESH_Swig::AddNewHypothesis(const char* theIOR)
438 {
439
440   MESSAGE("AddNewHypothesis");
441   
442   SALOMEDS::SObject_var aSObject = ::AddHypothesis(theIOR,
443                                                    mySComponentMesh,
444                                                    myStudyBuilder);
445   CORBA::String_var anEntry = aSObject->GetID();
446   return anEntry._retn();
447 }
448
449
450 //===============================================================
451 const char* 
452 SMESH_Swig::AddNewAlgorithms(const char* theIOR)
453 {
454   MESSAGE("AddNewAlgorithms");
455   
456   SALOMEDS::SObject_var aSObject = ::AddAlgorithms(theIOR,
457                                                    mySComponentMesh,
458                                                    myStudyBuilder);
459   CORBA::String_var anEntry = aSObject->GetID();
460   return anEntry._retn();
461 }
462
463
464 //===============================================================
465 void 
466 SMESH_Swig::SetShape(const char* theShapeEntry, 
467                      const char* theMeshEntry)
468 {
469   SALOMEDS::SObject_var aMeshSO = myStudy->FindObjectID( theMeshEntry );
470   SALOMEDS::SObject_var aGeomShapeSO = myStudy->FindObjectID( theShapeEntry );
471   
472   if(!aMeshSO->_is_nil() && !aGeomShapeSO->_is_nil()){
473     SALOMEDS::SObject_var aSObject = myStudyBuilder->NewObjectToTag(aMeshSO,Tag_RefOnShape);
474     myStudyBuilder->Addreference(aSObject,aGeomShapeSO);
475   }
476 }
477
478
479 //===============================================================
480 void 
481 SMESH_Swig::SetHypothesis(const char* theMeshOrSubMeshEntry, 
482                           const char* theDomainEntry)
483 {
484   ::SetHypothesis(theMeshOrSubMeshEntry,
485                   theDomainEntry,
486                   myStudy,
487                   myStudyBuilder);
488 }
489
490
491 //===============================================================
492 void 
493 SMESH_Swig::SetAlgorithms(const char* theMeshOrSubMeshEntry, 
494                           const char* theDomainEntry)
495 {
496   ::SetAlgorithms(theMeshOrSubMeshEntry,
497                   theDomainEntry,
498                   myStudy,
499                   myStudyBuilder);
500 }
501
502
503 //===============================================================
504 void
505 SMESH_Swig::UnSetHypothesis(const char* theDomainEntry)
506 {
507   SALOMEDS::SObject_var aDomainSO = myStudy->FindObjectID(theDomainEntry);
508   if(!aDomainSO->_is_nil())
509     myStudyBuilder->RemoveObject(aDomainSO);
510 }
511
512 const char* 
513 SMESH_Swig::AddSubMesh(const char* theMeshEntry, 
514                        const char* theSubMeshIOR, 
515                        int theShapeType)
516 {
517   SALOMEDS::SObject_var aMeshSO = myStudy->FindObjectID(theMeshEntry);
518   if(!aMeshSO->_is_nil()){
519     long aShapeTag;
520     QString aSubMeshName;
521     switch(theShapeType){
522     case TopAbs_SOLID:
523       aShapeTag = Tag_SubMeshOnSolid;
524       aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnSolid");
525       break;
526     case TopAbs_FACE:
527       aShapeTag = Tag_SubMeshOnFace;
528       aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnFace");
529       break;
530     case TopAbs_EDGE:
531       aShapeTag = Tag_SubMeshOnEdge;
532       aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnEdge");
533       break;
534     case TopAbs_VERTEX:
535       aShapeTag = Tag_SubMeshOnVertex;
536       aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnVertex");
537       break;
538     default:
539       aShapeTag = Tag_SubMeshOnCompound;
540       aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnCompound");      
541     }
542       
543     SALOMEDS::SObject_var aSubMeshesRoot;
544     SALOMEDS::GenericAttribute_var anAttr;
545     if(!aMeshSO->FindSubObject(aShapeTag,aSubMeshesRoot)){
546       aSubMeshesRoot = myStudyBuilder->NewObjectToTag(aMeshSO,aShapeTag);
547       anAttr = myStudyBuilder->FindOrCreateAttribute(aSubMeshesRoot,"AttributeName");
548       SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
549       aName->SetValue(aSubMeshName.latin1());
550       anAttr = myStudyBuilder->FindOrCreateAttribute(aSubMeshesRoot,"AttributeSelectable");
551       SALOMEDS::AttributeSelectable_var aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
552       aSelAttr->SetSelectable(false);
553     }
554
555     SALOMEDS::SObject_var aSObject = myStudyBuilder->NewObject(aSubMeshesRoot);
556     anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeIOR");
557     SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
558     anIOR->SetValue(theSubMeshIOR);
559
560     CORBA::String_var aString = aSObject->GetID();
561     return aString._retn();
562   }
563
564   return "";
565 }
566
567 const char* 
568 SMESH_Swig::AddSubMeshOnShape(const char* theMeshEntry, 
569                               const char* theGeomShapeEntry, 
570                               const char* theSubMeshIOR, 
571                               int ShapeType)
572 {
573   SALOMEDS::SObject_var aGeomShapeSO = myStudy->FindObjectID(theGeomShapeEntry);
574   if(!aGeomShapeSO->_is_nil()){
575     const char * aSubMeshEntry = AddSubMesh(theMeshEntry,theSubMeshIOR,ShapeType);
576     SALOMEDS::SObject_var aSubMeshSO = myStudy->FindObjectID(aSubMeshEntry);
577     if(!aSubMeshSO->_is_nil()){
578       SetShape(theGeomShapeEntry,aSubMeshEntry);
579       CORBA::String_var aString = aSubMeshSO->GetID();
580       return aString._retn();
581     }
582   }
583
584   return "";
585 }
586
587 void SMESH_Swig::CreateAndDisplayActor( const char* Mesh_Entry )
588 {
589   //  SMESH_Actor* Mesh = smeshGUI->ReadScript(aM);
590   class TEvent: public SALOME_Event
591   {
592   private:
593     const char* _entry;
594   public:
595     TEvent(const char* Mesh_Entry) {
596       _entry = Mesh_Entry;
597     }
598     virtual void Execute() {
599       //SMESH::UpdateView(SMESH::eDisplay, _entry);
600       SUIT_Session* aSession = SUIT_Session::session();
601       SUIT_Application* anApplication = aSession->activeApplication();
602       SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
603       SUIT_ViewManager* vman = anApp->getViewManager(VTKViewer_Viewer::Type(),true);
604       SMESHGUI_Displayer* aDisp = new SMESHGUI_Displayer(anApp);
605       aDisp->Display(_entry,1);
606     }
607   };
608   
609   ProcessVoidEvent(new TEvent(Mesh_Entry));
610   
611 }
612
613 void
614 SMESH_Swig::SetName(const char* theEntry, 
615                     const char* theName)
616 {
617   SALOMEDS::SObject_var aSObject = myStudy->FindObjectID(theEntry);
618   SALOMEDS::GenericAttribute_var anAttr;
619   SALOMEDS::AttributeName_var aName;
620   if(!aSObject->_is_nil()){
621     anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeName");
622     aName = SALOMEDS::AttributeName::_narrow(anAttr);
623     aName->SetValue(theName);
624   }
625 }
626
627 //================================================================================
628 /*!
629  * \brief Set mesh icon according to compute status
630   * \param Mesh_Entry - entry of a mesh
631   * \param isComputed - is mesh computed or not
632  */
633 //================================================================================
634
635 void SMESH_Swig::SetMeshIcon(const char* theMeshEntry, 
636                              const bool theIsComputed)
637 {
638   class TEvent: public SALOME_Event
639   {
640     SALOMEDS::Study_var myStudy;
641     std::string myMeshEntry;
642     bool myIsComputed;
643   public:
644     TEvent(const SALOMEDS::Study_var& theStudy,
645            const std::string& theMeshEntry,
646            const bool theIsComputed):
647       myStudy(theStudy),
648       myMeshEntry(theMeshEntry),
649       myIsComputed(theIsComputed)
650     {}
651
652     virtual
653     void
654     Execute()
655     {
656       SALOMEDS::SObject_var aMeshSO = myStudy->FindObjectID(myMeshEntry.c_str());
657       if(!aMeshSO->_is_nil())
658         if(_PTR(SObject) aMesh = ClientFactory::SObject(aMeshSO))
659           SMESH::ModifiedMesh(aMesh,myIsComputed);
660     }
661   };
662
663   ProcessVoidEvent(new TEvent(myStudy,
664                               theMeshEntry,
665                               theIsComputed));
666 }