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