1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // SMESH SMESH : GUI for SMESH component
21 // File : libSMESH_Swig.cxx
22 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
25 #include "libSMESH_Swig.h"
29 #include <SMESHGUI_Utils.h>
30 #include <SMESHGUI_Displayer.h>
31 #include <SMESHGUI_VTKUtils.h>
32 #include <SMESH_Actor.h>
34 // SALOME KERNEL includes
35 #include <Utils_ORB_INIT.hxx>
36 #include <Utils_SINGLETON.hxx>
37 #include <SALOMEDSClient_ClientFactory.hxx>
39 #include <utilities.h>
41 // SALOME GUI includes
42 #include <SUIT_Session.h>
43 #include <SUIT_ViewManager.h>
44 #include <SALOME_Prs.h>
45 #include <SUIT_ViewWindow.h>
46 #include <SVTK_ViewWindow.h>
47 #include <VTKViewer_ViewModel.h>
48 #include <SALOME_Event.h>
49 #include <SalomeApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
51 #include <SVTK_RenderWindowInteractor.h>
55 #include <TColStd_MapOfInteger.hxx>
58 #include <QApplication>
61 #include <SALOMEconfig.h>
62 #include CORBA_SERVER_HEADER(SMESH_Gen)
63 #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
65 static CORBA::ORB_var anORB;
69 //---------------------------------------------------------------
72 StringToObject(const std::string& theIOR)
74 return anORB->string_to_object(theIOR.c_str());
78 //---------------------------------------------------------------
81 GetDomainRoot(const SALOMEDS::SComponent_var& theSComponentMesh,
82 const SALOMEDS::StudyBuilder_var& theStudyBuilder,
83 CORBA::Long theDomainRootTag,
84 const QString& theName,
85 const QString& thePixmap)
87 SALOMEDS::SObject_var aDomainRoot;
88 if (!theSComponentMesh->FindSubObject(theDomainRootTag,aDomainRoot)) {
89 aDomainRoot = theStudyBuilder->NewObjectToTag(theSComponentMesh,theDomainRootTag);
90 SALOMEDS::GenericAttribute_var anAttr = theStudyBuilder->FindOrCreateAttribute(aDomainRoot,"AttributeName");
91 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
92 aName->SetValue(theName.toLatin1().data());
94 anAttr = theStudyBuilder->FindOrCreateAttribute(aDomainRoot,"AttributePixMap");
95 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
96 aPixmap->SetPixMap(thePixmap.toLatin1().data());
97 aPixmap->UnRegister();
98 anAttr = theStudyBuilder->FindOrCreateAttribute(aDomainRoot,"AttributeSelectable");
99 SALOMEDS::AttributeSelectable_var aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
100 aSelAttr->SetSelectable(false);
101 aSelAttr->UnRegister();
108 //---------------------------------------------------------------
110 SALOMEDS::SObject_var
111 GetHypothesisRoot(const SALOMEDS::SComponent_var& theSComponentMesh,
112 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
114 return GetDomainRoot(theSComponentMesh,
116 SMESH::Tag_HypothesisRoot,
117 QObject::tr("SMESH_MEN_HYPOTHESIS"),
118 "ICON_SMESH_TREE_HYPO");
122 //---------------------------------------------------------------
124 SALOMEDS::SObject_var
125 GetAlgorithmsRoot(const SALOMEDS::SComponent_var& theSComponentMesh,
126 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
128 return GetDomainRoot(theSComponentMesh,
130 SMESH::Tag_AlgorithmsRoot,
131 QObject::tr("SMESH_MEN_ALGORITHMS"),
132 "ICON_SMESH_TREE_ALGO");
136 //---------------------------------------------------------------
138 SALOMEDS::SObject_var
139 AddToDomain(const std::string& theIOR,
140 const SALOMEDS::SComponent_var& theSComponentMesh,
141 const SALOMEDS::StudyBuilder_var& theStudyBuilder,
142 CORBA::Long theDomainRootTag,
143 const QString& theDomainName,
144 const QString& theDomainPixmap)
146 SALOMEDS::SObject_var aDomain = GetDomainRoot(theSComponentMesh,
148 SMESH::Tag_AlgorithmsRoot,
151 // Add New Hypothesis
152 SALOMEDS::SObject_var aSObject = theStudyBuilder->NewObject(aDomain);
153 aDomain->UnRegister();
154 SALOMEDS::GenericAttribute_var anAttr = theStudyBuilder->FindOrCreateAttribute(aSObject,"AttributePixMap");
155 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
156 CORBA::Object_var anObject = StringToObject(theIOR);
157 SMESH::SMESH_Hypothesis_var aDomainItem = SMESH::SMESH_Hypothesis::_narrow(anObject.in());
158 CORBA::String_var aType = aDomainItem->GetName();
159 QString aPixmapName = theDomainPixmap + "_" + aType.in();
160 aPixmap->SetPixMap(aPixmapName.toLatin1().data());
161 aPixmap->UnRegister();
162 anAttr = theStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeIOR");
163 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
164 anIOR->SetValue(theIOR.c_str());
171 //---------------------------------------------------------------
172 SALOMEDS::SObject_var
173 AddHypothesis(const std::string& theIOR,
174 const SALOMEDS::SComponent_var& theSComponentMesh,
175 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
177 return AddToDomain(theIOR,
180 SMESH::Tag_HypothesisRoot,
181 QObject::tr("SMESH_MEN_HYPOTHESIS"),
182 "ICON_SMESH_TREE_HYPO");
186 //---------------------------------------------------------------
187 SALOMEDS::SObject_var
188 AddAlgorithms(const std::string& theIOR,
189 const SALOMEDS::SComponent_var& theSComponentMesh,
190 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
192 return AddToDomain(theIOR,
195 SMESH::Tag_AlgorithmsRoot,
196 QObject::tr("SMESH_MEN_ALGORITHMS"),
197 "ICON_SMESH_TREE_ALGO");
201 //---------------------------------------------------------------
203 SetDomain(const char* theMeshOrSubMeshEntry,
204 const char* theDomainEntry,
205 const SALOMEDS::Study_var& theStudy,
206 const SALOMEDS::StudyBuilder_var& theStudyBuilder,
207 long theRefOnAppliedDomainTag,
208 const QString& theAppliedDomainMEN,
209 const QString& theAppliedDomainICON)
211 SALOMEDS::SObject_var aMeshOrSubMeshSO = theStudy->FindObjectID(theMeshOrSubMeshEntry);
212 SALOMEDS::SObject_var aHypothesisSO = theStudy->FindObjectID(theDomainEntry);
214 if(!aMeshOrSubMeshSO->_is_nil() && !aHypothesisSO->_is_nil()){
215 //Find or Create Applied Hypothesis root
216 SALOMEDS::SObject_var anAppliedDomainSO;
217 if( !aMeshOrSubMeshSO->FindSubObject( theRefOnAppliedDomainTag, anAppliedDomainSO ))
219 anAppliedDomainSO = theStudyBuilder->NewObjectToTag(aMeshOrSubMeshSO,theRefOnAppliedDomainTag);
220 SALOMEDS::GenericAttribute_var anAttr =
221 theStudyBuilder->FindOrCreateAttribute(anAppliedDomainSO,"AttributeName");
222 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
223 aName->SetValue(theAppliedDomainMEN.toLatin1().data());
225 anAttr = theStudyBuilder->FindOrCreateAttribute(anAppliedDomainSO,"AttributeSelectable");
226 SALOMEDS::AttributeSelectable_var aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
227 aSelAttr->SetSelectable(false);
228 aSelAttr->UnRegister();
229 anAttr = theStudyBuilder->FindOrCreateAttribute(anAppliedDomainSO,"AttributePixMap");
230 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
231 aPixmap->SetPixMap(theAppliedDomainICON.toLatin1().data());
232 aPixmap->UnRegister();
234 SALOMEDS::SObject_var aSObject = theStudyBuilder->NewObject(anAppliedDomainSO);
235 theStudyBuilder->Addreference(aSObject,aHypothesisSO);
236 aSObject->UnRegister();
237 anAppliedDomainSO->UnRegister();
239 if ( !aMeshOrSubMeshSO->_is_nil() ) aMeshOrSubMeshSO->UnRegister();
240 if ( !aHypothesisSO->_is_nil()) aHypothesisSO->UnRegister();
244 //---------------------------------------------------------------
246 SetHypothesis(const char* theMeshOrSubMeshEntry,
247 const char* theDomainEntry,
248 const SALOMEDS::Study_var& theStudy,
249 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
251 SetDomain(theMeshOrSubMeshEntry,
255 SMESH::Tag_RefOnAppliedHypothesis,
256 QObject::tr("SMESH_MEN_APPLIED_HYPOTHESIS"),
257 "ICON_SMESH_TREE_HYPO");
261 //---------------------------------------------------------------
263 SetAlgorithms(const char* theMeshOrSubMeshEntry,
264 const char* theDomainEntry,
265 const SALOMEDS::Study_var& theStudy,
266 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
268 SetDomain(theMeshOrSubMeshEntry,
272 SMESH::Tag_RefOnAppliedAlgorithms,
273 QObject::tr("SMESH_MEN_APPLIED_ALGORIHTMS"),
274 "ICON_SMESH_TREE_ALGO");
279 //===============================================================
280 SMESH_Swig::SMESH_Swig()
282 class TEvent: public SALOME_Event
284 CORBA::ORB_var& myORB;
287 TEvent(CORBA::ORB_var& theORB):
296 ORB_INIT &anORBInit = *SINGLETON_<ORB_INIT>::Instance();
297 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
298 myORB = anORBInit( 0, 0 );
300 INFOS("internal error : orb not found");
305 //MESSAGE("Constructeur");
307 if(CORBA::is_nil(anORB))
308 ProcessVoidEvent(new TEvent(anORB));
310 ASSERT(!CORBA::is_nil(anORB));
314 //===============================================================
316 SMESH_Swig::Init(int theStudyID)
318 class TEvent: public SALOME_Event
321 SALOMEDS::Study_var& myStudy;
322 SALOMEDS::StudyBuilder_var& myStudyBuilder;
323 SALOMEDS::SComponent_var& mySComponentMesh;
325 TEvent(int theStudyID,
326 SALOMEDS::Study_var& theStudy,
327 SALOMEDS::StudyBuilder_var& theStudyBuilder,
328 SALOMEDS::SComponent_var& theSComponentMesh):
329 myStudyID (theStudyID),
331 myStudyBuilder (theStudyBuilder),
332 mySComponentMesh(theSComponentMesh)
337 if ( !mySComponentMesh->_is_nil() ) mySComponentMesh->UnRegister();
344 SUIT_Session* aSession = SUIT_Session::session();
345 SUIT_Application* anApplication = aSession->activeApplication();
346 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
348 SALOME_NamingService* aNamingService = anApp->namingService();
349 CORBA::Object_var anObject = aNamingService->Resolve("/myStudyManager");
350 SALOMEDS::StudyManager_var aStudyMgr = SALOMEDS::StudyManager::_narrow(anObject);
351 myStudy = aStudyMgr->GetStudyByID(myStudyID);
353 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
354 aSMESHGen->SetCurrentStudy( myStudy.in() );
356 myStudyBuilder = myStudy->NewBuilder();
358 SALOMEDS::GenericAttribute_var anAttr;
359 SALOMEDS::AttributeName_var aName;
360 SALOMEDS::AttributePixMap_var aPixmap;
362 SALOMEDS::SComponent_var aSComponent = myStudy->FindComponent("SMESH");
363 if ( aSComponent->_is_nil() )
365 bool aLocked = myStudy->GetProperties()->IsLocked();
367 myStudy->GetProperties()->SetLocked(false);
369 SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
370 //SRN: BugID IPAL9186, load a SMESH gui if it hasn't been loaded
372 CAM_Module* aModule = anApp->module("Mesh");
374 aModule = anApp->loadModule("Mesh");
375 aSMESHGUI = dynamic_cast<SMESHGUI*>(aModule);
376 } //SRN: BugID IPAL9186: end of a fix
378 aSComponent = myStudyBuilder->NewComponent("SMESH");
380 anAttr = myStudyBuilder->FindOrCreateAttribute(aSComponent,"AttributeName");
381 aName = SALOMEDS::AttributeName::_narrow(anAttr);
382 aName->SetValue(aSMESHGUI->moduleName().toLatin1().data());
385 anAttr = myStudyBuilder->FindOrCreateAttribute(aSComponent,"AttributePixMap");
386 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
387 aPixmap->SetPixMap( "ICON_OBJBROWSER_SMESH" );
388 aPixmap->UnRegister();
390 SALOMEDS::UseCaseBuilder_var useCaseBuilder = myStudy->GetUseCaseBuilder();
391 useCaseBuilder->SetRootCurrent();
392 useCaseBuilder->Append( aSComponent.in() );
394 myStudyBuilder->DefineComponentInstance(aSComponent,aSMESHGen);
396 myStudy->GetProperties()->SetLocked(true);
399 mySComponentMesh = SALOMEDS::SComponent::_narrow(aSComponent);
401 qApp->processEvents(); // Workaround for bug 12662
407 ProcessVoidEvent(new TEvent(theStudyID,
414 //===============================================================
415 SMESH_Swig::~SMESH_Swig()
417 //MESSAGE("Destructeur");
421 //===============================================================
422 const char* SMESH_Swig::AddNewMesh(const char* theIOR)
425 // VSR: added temporarily - to be removed - objects are published automatically by engine
426 SALOMEDS::SObject_var aSObject = myStudy->FindObjectIOR(theIOR);
427 if (aSObject->_is_nil())
429 //Find or Create Hypothesis root
430 SALOMEDS::SObject_var hroot = GetHypothesisRoot(mySComponentMesh,myStudyBuilder);
431 SALOMEDS::SObject_var aroot = GetAlgorithmsRoot(mySComponentMesh,myStudyBuilder);
436 aSObject = myStudyBuilder->NewObject(mySComponentMesh);
437 SALOMEDS::GenericAttribute_var anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributePixMap");
438 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
439 aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH" );
440 aPixmap->UnRegister();
442 anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeIOR");
443 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
444 anIOR->SetValue(theIOR);
448 CORBA::String_var anEntry = aSObject->GetID();
449 aSObject->UnRegister();
451 return anEntry._retn();
455 //===============================================================
456 const char* SMESH_Swig::AddNewHypothesis(const char* theIOR)
458 SALOMEDS::SObject_var aSObject = ::AddHypothesis(theIOR,
461 CORBA::String_var anEntry = aSObject->GetID();
462 aSObject->UnRegister();
464 return anEntry._retn();
468 //===============================================================
469 const char* SMESH_Swig::AddNewAlgorithms(const char* theIOR)
471 SALOMEDS::SObject_var aSObject = ::AddAlgorithms(theIOR,
474 CORBA::String_var anEntry = aSObject->GetID();
475 aSObject->UnRegister();
477 return anEntry._retn();
481 //===============================================================
482 void SMESH_Swig::SetShape(const char* theShapeEntry,
483 const char* theMeshEntry)
485 SALOMEDS::SObject_var aGeomShapeSO = myStudy->FindObjectID( theShapeEntry );
486 SALOMEDS::SObject_var aMeshSO = myStudy->FindObjectID( theMeshEntry );
488 if(!aMeshSO->_is_nil() && !aGeomShapeSO->_is_nil()){
489 SALOMEDS::SObject_var aSObject = myStudyBuilder->NewObjectToTag(aMeshSO, SMESH::Tag_RefOnShape);
490 myStudyBuilder->Addreference(aSObject,aGeomShapeSO);
491 aSObject->UnRegister();
493 if ( !aMeshSO->_is_nil() ) aMeshSO->UnRegister();
494 if ( !aGeomShapeSO->_is_nil() ) aGeomShapeSO->UnRegister();
498 //===============================================================
499 void SMESH_Swig::SetHypothesis(const char* theMeshOrSubMeshEntry,
500 const char* theDomainEntry)
502 ::SetHypothesis(theMeshOrSubMeshEntry,
509 //===============================================================
510 void SMESH_Swig::SetAlgorithms(const char* theMeshOrSubMeshEntry,
511 const char* theDomainEntry)
513 ::SetAlgorithms(theMeshOrSubMeshEntry,
520 //===============================================================
522 SMESH_Swig::UnSetHypothesis(const char* theDomainEntry)
524 SALOMEDS::SObject_var aDomainSO = myStudy->FindObjectID(theDomainEntry);
525 if(!aDomainSO->_is_nil())
526 myStudyBuilder->RemoveObject(aDomainSO);
529 const char* SMESH_Swig::AddSubMesh(const char* theMeshEntry,
530 const char* theSubMeshIOR,
533 SALOMEDS::SObject_var aMeshSO = myStudy->FindObjectID(theMeshEntry);
534 if(!aMeshSO->_is_nil()) {
536 QString aSubMeshName;
537 switch(theShapeType) {
539 aShapeTag = SMESH::Tag_SubMeshOnSolid;
540 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnSolid");
543 aShapeTag = SMESH::Tag_SubMeshOnFace;
544 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnFace");
547 aShapeTag = SMESH::Tag_SubMeshOnEdge;
548 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnEdge");
551 aShapeTag = SMESH::Tag_SubMeshOnVertex;
552 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnVertex");
555 aShapeTag = SMESH::Tag_SubMeshOnCompound;
556 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnCompound");
559 SALOMEDS::GenericAttribute_var anAttr;
560 SALOMEDS::SObject_var aSubMeshesRoot;
561 if ( !aMeshSO->FindSubObject( aShapeTag, aSubMeshesRoot ) )
563 aSubMeshesRoot = myStudyBuilder->NewObjectToTag(aMeshSO,aShapeTag);
564 anAttr = myStudyBuilder->FindOrCreateAttribute(aSubMeshesRoot,"AttributeName");
565 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
566 aName->SetValue(aSubMeshName.toLatin1().data());
568 anAttr = myStudyBuilder->FindOrCreateAttribute(aSubMeshesRoot,"AttributeSelectable");
569 SALOMEDS::AttributeSelectable_var aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
570 aSelAttr->SetSelectable(false);
571 aSelAttr->UnRegister();
573 aSubMeshesRoot->UnRegister();
574 aMeshSO->UnRegister();
576 SALOMEDS::SObject_var aSObject = myStudyBuilder->NewObject(aSubMeshesRoot);
577 anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeIOR");
578 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
579 anIOR->SetValue(theSubMeshIOR);
582 CORBA::String_var aString = aSObject->GetID();
583 aSObject->UnRegister();
585 return aString._retn();
591 const char* SMESH_Swig::AddSubMeshOnShape(const char* theMeshEntry,
592 const char* theGeomShapeEntry,
593 const char* theSubMeshIOR,
596 SALOMEDS::SObject_var aGeomShapeSO = myStudy->FindObjectID(theGeomShapeEntry);
597 if(!aGeomShapeSO->_is_nil())
599 const char * aSubMeshEntry = AddSubMesh(theMeshEntry,theSubMeshIOR,ShapeType);
600 SALOMEDS::SObject_var aSubMeshSO = myStudy->FindObjectID(aSubMeshEntry);
601 if ( !aSubMeshSO->_is_nil()) {
602 SetShape( theGeomShapeEntry, aSubMeshEntry );
603 CORBA::String_var aString = aSubMeshSO->GetID();
604 aSubMeshSO->UnRegister();
605 return aString._retn();
607 aGeomShapeSO->UnRegister();
614 \brief Gets window with specified identifier
616 \param id window identifier
617 \return pointer on the window
620 SUIT_ViewWindow* getWnd( const int id )
622 SUIT_ViewWindow* resWnd = 0;
623 SUIT_Session* aSession = SUIT_Session::session();
624 SUIT_Application* anApplication = aSession->activeApplication();
625 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(anApplication);
627 ViewManagerList vmlist = app->viewManagers();
628 foreach( SUIT_ViewManager* vm, vmlist ) {
629 QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
630 foreach ( SUIT_ViewWindow* vw, vwlist ) {
631 if ( id == vw->getId() ) {
641 class TGetActorAspect: public SALOME_Event
644 typedef actorAspect TResult;
648 TGetActorAspect( const char* Mesh_Entry, int viewId )
653 virtual void Execute()
655 SMESH_Actor* anActor;
658 SUIT_ViewWindow* w = getWnd(_wid);
659 anActor = SMESH::FindActorByEntry( w, _entry );
662 anActor = SMESH::FindActorByEntry( _entry );
665 MESSAGE("GetActorAspect: no actor corresponding to: " << _entry);
668 anActor->GetSufaceColor(myResult.surfaceColor.r,
669 myResult.surfaceColor.g,
670 myResult.surfaceColor.b,
671 myResult.surfaceColor.delta);
672 anActor->GetVolumeColor(myResult.volumeColor.r,
673 myResult.volumeColor.g,
674 myResult.volumeColor.b,
675 myResult.volumeColor.delta);
676 anActor->GetEdgeColor(myResult.edgeColor.r,
677 myResult.edgeColor.g,
678 myResult.edgeColor.b);
679 anActor->GetNodeColor(myResult.nodeColor.r,
680 myResult.nodeColor.g,
681 myResult.nodeColor.b);
682 myResult.opacity= anActor->GetOpacity();
683 MESSAGE("opacity: " << myResult.opacity);
687 actorAspect SMESH_Swig::GetActorAspect( const char* Mesh_Entry, int viewId )
689 return ProcessEvent(new TGetActorAspect( Mesh_Entry, viewId));
692 void SMESH_Swig::SetActorAspect( const actorAspect& actorPres, const char* Mesh_Entry, int viewId )
694 class TSetActorAspect: public SALOME_Event
698 actorAspect _actorPres;
700 TSetActorAspect(const actorAspect& actorPres, const char* Mesh_Entry, int viewId )
703 _actorPres = actorPres;
706 virtual void Execute()
708 SMESH_Actor* anActor;
711 SUIT_ViewWindow* w = getWnd(_wid);
712 anActor = SMESH::FindActorByEntry( w, _entry );
715 anActor = SMESH::FindActorByEntry( _entry );
718 MESSAGE("SetActorAspect: no actor corresponding to: " << _entry);
721 anActor->SetSufaceColor(_actorPres.surfaceColor.r,
722 _actorPres.surfaceColor.g,
723 _actorPres.surfaceColor.b,
724 _actorPres.surfaceColor.delta);
725 anActor->SetVolumeColor(_actorPres.volumeColor.r,
726 _actorPres.volumeColor.g,
727 _actorPres.volumeColor.b,
728 _actorPres.volumeColor.delta);
729 anActor->SetEdgeColor(_actorPres.edgeColor.r,
730 _actorPres.edgeColor.g,
731 _actorPres.edgeColor.b);
732 anActor->SetNodeColor(_actorPres.nodeColor.r,
733 _actorPres.nodeColor.g,
734 _actorPres.nodeColor.b);
735 anActor->SetOpacity(_actorPres.opacity);
738 SUIT_ViewWindow* w = getWnd(_wid);
743 SUIT_Session* aSession = SUIT_Session::session();
744 SUIT_Application* anApplication = aSession->activeApplication();
745 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
746 SUIT_ViewManager* vman = anApp->getViewManager(VTKViewer_Viewer::Type(),true);
747 vman->getActiveView()->repaint();
752 ProcessVoidEvent(new TSetActorAspect(actorPres, Mesh_Entry, viewId));
755 void SMESH_Swig::CreateAndDisplayActor( const char* Mesh_Entry )
757 // SMESH_Actor* Mesh = smeshGUI->ReadScript(aM);
758 class TEvent: public SALOME_Event
763 TEvent(const char* Mesh_Entry) {
766 virtual void Execute() {
767 //SMESH::UpdateView(SMESH::eDisplay, _entry);
768 SUIT_Session* aSession = SUIT_Session::session();
769 SUIT_Application* anApplication = aSession->activeApplication();
770 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
771 /*SUIT_ViewManager* vman = */anApp->getViewManager(VTKViewer_Viewer::Type(),true);
772 SMESHGUI_Displayer* aDisp = new SMESHGUI_Displayer(anApp);
773 aDisp->Display(_entry,1);
777 ProcessVoidEvent(new TEvent(Mesh_Entry));
780 void SMESH_Swig::EraseActor( const char* Mesh_Entry, const bool allViewers )
782 class TEvent: public SALOME_Event
788 TEvent(const char* Mesh_Entry, const bool allViewers ) {
790 _allViewers = allViewers;
792 virtual void Execute() {
793 SUIT_Session* aSession = SUIT_Session::session();
794 SUIT_Application* anApplication = aSession->activeApplication();
795 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
796 SMESHGUI_Displayer* aDisp = new SMESHGUI_Displayer(anApp);
797 ViewManagerList aManagers;
798 if ( !_allViewers ) {
799 aManagers << anApp->activeViewManager();
802 aManagers = anApp->viewManagers();
804 foreach( SUIT_ViewManager* aMgr, aManagers ) {
805 if ( aMgr && aMgr->getType() == VTKViewer_Viewer::Type() ) {
806 SALOME_View* aSalomeView = dynamic_cast<SALOME_View*>(aMgr->getViewModel());
808 aDisp->Erase(_entry,true, true, aSalomeView);
815 ProcessVoidEvent(new TEvent(Mesh_Entry, allViewers));
818 void SMESH_Swig::SetName(const char* theEntry,
821 SALOMEDS::SObject_var aSObject = myStudy->FindObjectID(theEntry);
822 SALOMEDS::GenericAttribute_var anAttr;
823 SALOMEDS::AttributeName_var aName;
824 if(!aSObject->_is_nil()){
825 anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeName");
826 aName = SALOMEDS::AttributeName::_narrow(anAttr);
827 aName->SetValue(theName);
829 aSObject->UnRegister();
833 //================================================================================
835 * \brief Set mesh icon according to compute status
836 * \param Mesh_Entry - entry of a mesh
837 * \param isComputed - is mesh computed or not
839 //================================================================================
841 void SMESH_Swig::SetMeshIcon(const char* theMeshEntry,
842 const bool theIsComputed,
845 class TEvent: public SALOME_Event
847 SALOMEDS::Study_var myStudy;
848 std::string myMeshEntry;
849 bool myIsComputed, myIsEmpty;
851 TEvent(const SALOMEDS::Study_var& theStudy,
852 const std::string& theMeshEntry,
853 const bool theIsComputed,
856 myMeshEntry (theMeshEntry),
857 myIsComputed(theIsComputed),
865 SALOMEDS::SObject_ptr aMeshSO = myStudy->FindObjectID(myMeshEntry.c_str());
866 if(_PTR(SObject) aMesh = ClientFactory::SObject(aMeshSO))
867 SMESH::ModifiedMesh(aMesh,myIsComputed,myIsEmpty);
868 // aMeshSO->UnRegister(); ~aMesh() already called UnRegister()!
872 ProcessVoidEvent(new TEvent(myStudy,
879 \brief Helper class for selection event.
881 class TSelectListEvent: public SALOME_Event
884 std::vector<int> myIdsList;
888 TSelectListEvent(const char* id, std::vector<int> ids, bool append) :
893 virtual void Execute()
895 SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
899 LightApp_SelectionMgr* selMgr = SMESH::GetSelectionMgr( aSMESHGUI );
903 selMgr->clearFilters();
905 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( aSMESHGUI );
909 SMESH_Actor* anActor = SMESH::FindActorByEntry( myId );
911 if (!anActor || !anActor->hasIO())
914 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
917 selMgr->setSelectedObjects(aList, false);
919 if ( aViewWindow->SelectionMode() == ActorSelection ) {
923 TColStd_MapOfInteger aMap;
924 std::vector<int>::const_iterator anIter;
925 for (anIter = myIdsList.begin(); anIter != myIdsList.end(); ++anIter) {
930 SVTK_Selector* aSelector = aViewWindow->GetSelector();
931 aSelector->AddOrRemoveIndex(anIO, aMap, myIsAppend);
932 aViewWindow->highlight( anIO, true, true );
933 aViewWindow->GetInteractor()->onEmitSelectionChanged();
938 \brief Select the elements on the mesh, sub-mesh or group.
939 \param id object entry
940 \param ids list of the element ids
941 \param mode selection mode
943 void SMESH_Swig::select( const char* id, std::vector<int> ids, bool append ) {
944 ProcessVoidEvent( new TSelectListEvent( id, ids, append ) );
948 \brief Select the elements on the mesh, sub-mesh or group.
949 \param id object entry
950 \param id id of the element
951 \param mode selection mode
953 void SMESH_Swig::select( const char* id, int id1, bool append ) {
954 std::vector<int> ids;
955 ids.push_back( id1 );
956 ProcessVoidEvent( new TSelectListEvent( id, ids, append ) );
960 class TGetSelectionModeEvent : public SALOME_Event
965 TGetSelectionModeEvent() : myResult( -1 ) {}
966 virtual void Execute()
968 SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
972 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( aSMESHGUI );
976 myResult = aViewWindow->SelectionMode();
981 \brief Get selection mode of the active VTK View window.
983 int SMESH_Swig::getSelectionMode() {
984 return ProcessEvent( new TGetSelectionModeEvent() );