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>
38 #include <SALOME_KernelServices.hxx>
40 #include <utilities.h>
42 // SALOME GUI includes
43 #include <SUIT_Session.h>
44 #include <SUIT_ViewManager.h>
45 #include <SALOME_Prs.h>
46 #include <SUIT_ViewWindow.h>
47 #include <SVTK_ViewWindow.h>
48 #include <VTKViewer_ViewModel.h>
49 #include <SALOME_Event.h>
50 #include <SalomeApp_Application.h>
51 #include <LightApp_SelectionMgr.h>
52 #include <SVTK_RenderWindowInteractor.h>
56 #include <TColStd_MapOfInteger.hxx>
59 #include <QApplication>
62 #include <SALOMEconfig.h>
63 #include CORBA_SERVER_HEADER(SMESH_Gen)
64 #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
66 static CORBA::ORB_var anORB;
70 //---------------------------------------------------------------
73 StringToObject(const std::string& theIOR)
75 return anORB->string_to_object(theIOR.c_str());
79 //---------------------------------------------------------------
82 GetDomainRoot(const SALOMEDS::SComponent_var& theSComponentMesh,
83 const SALOMEDS::StudyBuilder_var& theStudyBuilder,
84 CORBA::Long theDomainRootTag,
85 const QString& theName,
86 const QString& thePixmap)
88 SALOMEDS::SObject_var aDomainRoot;
89 if (!theSComponentMesh->FindSubObject(theDomainRootTag,aDomainRoot)) {
90 aDomainRoot = theStudyBuilder->NewObjectToTag(theSComponentMesh,theDomainRootTag);
91 SALOMEDS::GenericAttribute_var anAttr = theStudyBuilder->FindOrCreateAttribute(aDomainRoot,"AttributeName");
92 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
93 aName->SetValue(theName.toLatin1().data());
95 anAttr = theStudyBuilder->FindOrCreateAttribute(aDomainRoot,"AttributePixMap");
96 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
97 aPixmap->SetPixMap(thePixmap.toLatin1().data());
98 aPixmap->UnRegister();
99 anAttr = theStudyBuilder->FindOrCreateAttribute(aDomainRoot,"AttributeSelectable");
100 SALOMEDS::AttributeSelectable_var aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
101 aSelAttr->SetSelectable(false);
102 aSelAttr->UnRegister();
109 //---------------------------------------------------------------
111 SALOMEDS::SObject_var
112 GetHypothesisRoot(const SALOMEDS::SComponent_var& theSComponentMesh,
113 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
115 return GetDomainRoot(theSComponentMesh,
117 SMESH::Tag_HypothesisRoot,
118 QObject::tr("SMESH_MEN_HYPOTHESIS"),
119 "ICON_SMESH_TREE_HYPO");
123 //---------------------------------------------------------------
125 SALOMEDS::SObject_var
126 GetAlgorithmsRoot(const SALOMEDS::SComponent_var& theSComponentMesh,
127 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
129 return GetDomainRoot(theSComponentMesh,
131 SMESH::Tag_AlgorithmsRoot,
132 QObject::tr("SMESH_MEN_ALGORITHMS"),
133 "ICON_SMESH_TREE_ALGO");
137 //---------------------------------------------------------------
139 SALOMEDS::SObject_var
140 AddToDomain(const std::string& theIOR,
141 const SALOMEDS::SComponent_var& theSComponentMesh,
142 const SALOMEDS::StudyBuilder_var& theStudyBuilder,
143 CORBA::Long theDomainRootTag,
144 const QString& theDomainName,
145 const QString& theDomainPixmap)
147 SALOMEDS::SObject_var aDomain = GetDomainRoot(theSComponentMesh,
149 SMESH::Tag_AlgorithmsRoot,
152 // Add New Hypothesis
153 SALOMEDS::SObject_var aSObject = theStudyBuilder->NewObject(aDomain);
154 aDomain->UnRegister();
155 SALOMEDS::GenericAttribute_var anAttr = theStudyBuilder->FindOrCreateAttribute(aSObject,"AttributePixMap");
156 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
157 CORBA::Object_var anObject = StringToObject(theIOR);
158 SMESH::SMESH_Hypothesis_var aDomainItem = SMESH::SMESH_Hypothesis::_narrow(anObject.in());
159 CORBA::String_var aType = aDomainItem->GetName();
160 QString aPixmapName = theDomainPixmap + "_" + aType.in();
161 aPixmap->SetPixMap(aPixmapName.toLatin1().data());
162 aPixmap->UnRegister();
163 anAttr = theStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeIOR");
164 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
165 anIOR->SetValue(theIOR.c_str());
172 //---------------------------------------------------------------
173 SALOMEDS::SObject_var
174 AddHypothesis(const std::string& theIOR,
175 const SALOMEDS::SComponent_var& theSComponentMesh,
176 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
178 return AddToDomain(theIOR,
181 SMESH::Tag_HypothesisRoot,
182 QObject::tr("SMESH_MEN_HYPOTHESIS"),
183 "ICON_SMESH_TREE_HYPO");
187 //---------------------------------------------------------------
188 SALOMEDS::SObject_var
189 AddAlgorithms(const std::string& theIOR,
190 const SALOMEDS::SComponent_var& theSComponentMesh,
191 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
193 return AddToDomain(theIOR,
196 SMESH::Tag_AlgorithmsRoot,
197 QObject::tr("SMESH_MEN_ALGORITHMS"),
198 "ICON_SMESH_TREE_ALGO");
202 //---------------------------------------------------------------
204 SetDomain(const char* theMeshOrSubMeshEntry,
205 const char* theDomainEntry,
206 const SALOMEDS::StudyBuilder_var& theStudyBuilder,
207 long theRefOnAppliedDomainTag,
208 const QString& theAppliedDomainMEN,
209 const QString& theAppliedDomainICON)
211 SALOMEDS::SObject_var aMeshOrSubMeshSO = KERNEL::getStudyServant()->FindObjectID(theMeshOrSubMeshEntry);
212 SALOMEDS::SObject_var aHypothesisSO = KERNEL::getStudyServant()->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::StudyBuilder_var& theStudyBuilder)
250 SetDomain(theMeshOrSubMeshEntry,
253 SMESH::Tag_RefOnAppliedHypothesis,
254 QObject::tr("SMESH_MEN_APPLIED_HYPOTHESIS"),
255 "ICON_SMESH_TREE_HYPO");
259 //---------------------------------------------------------------
261 SetAlgorithms(const char* theMeshOrSubMeshEntry,
262 const char* theDomainEntry,
263 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
265 SetDomain(theMeshOrSubMeshEntry,
268 SMESH::Tag_RefOnAppliedAlgorithms,
269 QObject::tr("SMESH_MEN_APPLIED_ALGORIHTMS"),
270 "ICON_SMESH_TREE_ALGO");
275 //===============================================================
276 SMESH_Swig::SMESH_Swig()
278 class TEvent: public SALOME_Event
280 CORBA::ORB_var& myORB;
283 TEvent(CORBA::ORB_var& theORB):
292 ORB_INIT &anORBInit = *SINGLETON_<ORB_INIT>::Instance();
293 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
294 myORB = anORBInit( 0, 0 );
296 INFOS("internal error : orb not found");
301 //MESSAGE("Constructeur");
303 if(CORBA::is_nil(anORB))
304 ProcessVoidEvent(new TEvent(anORB));
306 ASSERT(!CORBA::is_nil(anORB));
310 //===============================================================
314 class TEvent: public SALOME_Event
316 SALOMEDS::StudyBuilder_var& myStudyBuilder;
317 SALOMEDS::SComponent_var& mySComponentMesh;
319 TEvent(SALOMEDS::StudyBuilder_var& theStudyBuilder,
320 SALOMEDS::SComponent_var& theSComponentMesh):
321 myStudyBuilder (theStudyBuilder),
322 mySComponentMesh(theSComponentMesh)
327 if ( !mySComponentMesh->_is_nil() ) mySComponentMesh->UnRegister();
334 SUIT_Session* aSession = SUIT_Session::session();
335 SUIT_Application* anApplication = aSession->activeApplication();
336 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
338 SALOMEDS::Study_var aStudy = KERNEL::getStudyServant();
340 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
342 myStudyBuilder = aStudy->NewBuilder();
344 SALOMEDS::GenericAttribute_var anAttr;
345 SALOMEDS::AttributeName_var aName;
346 SALOMEDS::AttributePixMap_var aPixmap;
348 SALOMEDS::SComponent_var aSComponent = aStudy->FindComponent("SMESH");
349 if ( aSComponent->_is_nil() )
351 bool aLocked = aStudy->GetProperties()->IsLocked();
353 aStudy->GetProperties()->SetLocked(false);
355 SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
356 //SRN: BugID IPAL9186, load a SMESH gui if it hasn't been loaded
358 CAM_Module* aModule = anApp->module("Mesh");
360 aModule = anApp->loadModule("Mesh");
361 aSMESHGUI = dynamic_cast<SMESHGUI*>(aModule);
362 } //SRN: BugID IPAL9186: end of a fix
364 aSComponent = myStudyBuilder->NewComponent("SMESH");
366 anAttr = myStudyBuilder->FindOrCreateAttribute(aSComponent,"AttributeName");
367 aName = SALOMEDS::AttributeName::_narrow(anAttr);
368 aName->SetValue(aSMESHGUI->moduleName().toLatin1().data());
371 anAttr = myStudyBuilder->FindOrCreateAttribute(aSComponent,"AttributePixMap");
372 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
373 aPixmap->SetPixMap( "ICON_OBJBROWSER_SMESH" );
374 aPixmap->UnRegister();
376 SALOMEDS::UseCaseBuilder_var useCaseBuilder = KERNEL::getStudyServant()->GetUseCaseBuilder();
377 useCaseBuilder->SetRootCurrent();
378 useCaseBuilder->Append( aSComponent.in() );
380 myStudyBuilder->DefineComponentInstance(aSComponent,aSMESHGen);
382 KERNEL::getStudyServant()->GetProperties()->SetLocked(true);
385 mySComponentMesh = SALOMEDS::SComponent::_narrow(aSComponent);
387 qApp->processEvents(); // Workaround for bug 12662
393 ProcessVoidEvent(new TEvent(myStudyBuilder,
398 //===============================================================
399 SMESH_Swig::~SMESH_Swig()
401 //MESSAGE("Destructeur");
405 //===============================================================
406 const char* SMESH_Swig::AddNewMesh(const char* theIOR)
409 // VSR: added temporarily - to be removed - objects are published automatically by engine
410 SALOMEDS::SObject_var aSObject = KERNEL::getStudyServant()->FindObjectIOR(theIOR);
411 if (aSObject->_is_nil())
413 //Find or Create Hypothesis root
414 SALOMEDS::SObject_var hroot = GetHypothesisRoot(mySComponentMesh,myStudyBuilder);
415 SALOMEDS::SObject_var aroot = GetAlgorithmsRoot(mySComponentMesh,myStudyBuilder);
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 aPixmap->UnRegister();
426 anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeIOR");
427 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
428 anIOR->SetValue(theIOR);
432 CORBA::String_var anEntry = aSObject->GetID();
433 aSObject->UnRegister();
435 return anEntry._retn();
439 //===============================================================
440 const char* SMESH_Swig::AddNewHypothesis(const char* theIOR)
442 SALOMEDS::SObject_var aSObject = ::AddHypothesis(theIOR,
445 CORBA::String_var anEntry = aSObject->GetID();
446 aSObject->UnRegister();
448 return anEntry._retn();
452 //===============================================================
453 const char* SMESH_Swig::AddNewAlgorithms(const char* theIOR)
455 SALOMEDS::SObject_var aSObject = ::AddAlgorithms(theIOR,
458 CORBA::String_var anEntry = aSObject->GetID();
459 aSObject->UnRegister();
461 return anEntry._retn();
465 //===============================================================
466 void SMESH_Swig::SetShape(const char* theShapeEntry,
467 const char* theMeshEntry)
469 SALOMEDS::SObject_var aGeomShapeSO = KERNEL::getStudyServant()->FindObjectID( theShapeEntry );
470 SALOMEDS::SObject_var aMeshSO = KERNEL::getStudyServant()->FindObjectID( theMeshEntry );
472 if(!aMeshSO->_is_nil() && !aGeomShapeSO->_is_nil()){
473 SALOMEDS::SObject_var aSObject = myStudyBuilder->NewObjectToTag(aMeshSO, SMESH::Tag_RefOnShape);
474 myStudyBuilder->Addreference(aSObject,aGeomShapeSO);
475 aSObject->UnRegister();
477 if ( !aMeshSO->_is_nil() ) aMeshSO->UnRegister();
478 if ( !aGeomShapeSO->_is_nil() ) aGeomShapeSO->UnRegister();
482 //===============================================================
483 void SMESH_Swig::SetHypothesis(const char* theMeshOrSubMeshEntry,
484 const char* theDomainEntry)
486 ::SetHypothesis(theMeshOrSubMeshEntry,
492 //===============================================================
493 void SMESH_Swig::SetAlgorithms(const char* theMeshOrSubMeshEntry,
494 const char* theDomainEntry)
496 ::SetAlgorithms(theMeshOrSubMeshEntry,
502 //===============================================================
504 SMESH_Swig::UnSetHypothesis(const char* theDomainEntry)
506 SALOMEDS::SObject_var aDomainSO = KERNEL::getStudyServant()->FindObjectID(theDomainEntry);
507 if(!aDomainSO->_is_nil())
508 myStudyBuilder->RemoveObject(aDomainSO);
511 const char* SMESH_Swig::AddSubMesh(const char* theMeshEntry,
512 const char* theSubMeshIOR,
515 SALOMEDS::SObject_var aMeshSO = KERNEL::getStudyServant()->FindObjectID(theMeshEntry);
516 if(!aMeshSO->_is_nil()) {
518 QString aSubMeshName;
519 switch(theShapeType) {
521 aShapeTag = SMESH::Tag_SubMeshOnSolid;
522 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnSolid");
525 aShapeTag = SMESH::Tag_SubMeshOnFace;
526 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnFace");
529 aShapeTag = SMESH::Tag_SubMeshOnEdge;
530 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnEdge");
533 aShapeTag = SMESH::Tag_SubMeshOnVertex;
534 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnVertex");
537 aShapeTag = SMESH::Tag_SubMeshOnCompound;
538 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnCompound");
541 SALOMEDS::GenericAttribute_var anAttr;
542 SALOMEDS::SObject_var aSubMeshesRoot;
543 if ( !aMeshSO->FindSubObject( aShapeTag, aSubMeshesRoot ) )
545 aSubMeshesRoot = myStudyBuilder->NewObjectToTag(aMeshSO,aShapeTag);
546 anAttr = myStudyBuilder->FindOrCreateAttribute(aSubMeshesRoot,"AttributeName");
547 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
548 aName->SetValue(aSubMeshName.toLatin1().data());
550 anAttr = myStudyBuilder->FindOrCreateAttribute(aSubMeshesRoot,"AttributeSelectable");
551 SALOMEDS::AttributeSelectable_var aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
552 aSelAttr->SetSelectable(false);
553 aSelAttr->UnRegister();
555 aSubMeshesRoot->UnRegister();
556 aMeshSO->UnRegister();
558 SALOMEDS::SObject_var aSObject = myStudyBuilder->NewObject(aSubMeshesRoot);
559 anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeIOR");
560 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
561 anIOR->SetValue(theSubMeshIOR);
564 CORBA::String_var aString = aSObject->GetID();
565 aSObject->UnRegister();
567 return aString._retn();
573 const char* SMESH_Swig::AddSubMeshOnShape(const char* theMeshEntry,
574 const char* theGeomShapeEntry,
575 const char* theSubMeshIOR,
578 SALOMEDS::SObject_var aGeomShapeSO = KERNEL::getStudyServant()->FindObjectID(theGeomShapeEntry);
579 if(!aGeomShapeSO->_is_nil())
581 const char * aSubMeshEntry = AddSubMesh(theMeshEntry,theSubMeshIOR,ShapeType);
582 SALOMEDS::SObject_var aSubMeshSO = KERNEL::getStudyServant()->FindObjectID(aSubMeshEntry);
583 if ( !aSubMeshSO->_is_nil()) {
584 SetShape( theGeomShapeEntry, aSubMeshEntry );
585 CORBA::String_var aString = aSubMeshSO->GetID();
586 aSubMeshSO->UnRegister();
587 return aString._retn();
589 aGeomShapeSO->UnRegister();
596 \brief Gets window with specified identifier
598 \param id window identifier
599 \return pointer on the window
602 SUIT_ViewWindow* getWnd( const int id )
604 SUIT_ViewWindow* resWnd = 0;
605 SUIT_Session* aSession = SUIT_Session::session();
606 SUIT_Application* anApplication = aSession->activeApplication();
607 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(anApplication);
609 ViewManagerList vmlist = app->viewManagers();
610 foreach( SUIT_ViewManager* vm, vmlist ) {
611 QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
612 foreach ( SUIT_ViewWindow* vw, vwlist ) {
613 if ( id == vw->getId() ) {
623 class TGetActorAspect: public SALOME_Event
626 typedef actorAspect TResult;
630 TGetActorAspect( const char* Mesh_Entry, int viewId )
635 virtual void Execute()
637 SMESH_Actor* anActor;
640 SUIT_ViewWindow* w = getWnd(_wid);
641 anActor = SMESH::FindActorByEntry( w, _entry );
644 anActor = SMESH::FindActorByEntry( _entry );
647 MESSAGE("GetActorAspect: no actor corresponding to: " << _entry);
650 anActor->GetSufaceColor(myResult.surfaceColor.r,
651 myResult.surfaceColor.g,
652 myResult.surfaceColor.b,
653 myResult.surfaceColor.delta);
654 anActor->GetVolumeColor(myResult.volumeColor.r,
655 myResult.volumeColor.g,
656 myResult.volumeColor.b,
657 myResult.volumeColor.delta);
658 anActor->GetEdgeColor(myResult.edgeColor.r,
659 myResult.edgeColor.g,
660 myResult.edgeColor.b);
661 anActor->GetNodeColor(myResult.nodeColor.r,
662 myResult.nodeColor.g,
663 myResult.nodeColor.b);
664 myResult.opacity= anActor->GetOpacity();
665 MESSAGE("opacity: " << myResult.opacity);
669 actorAspect SMESH_Swig::GetActorAspect( const char* Mesh_Entry, int viewId )
671 return ProcessEvent(new TGetActorAspect( Mesh_Entry, viewId));
674 void SMESH_Swig::SetActorAspect( const actorAspect& actorPres, const char* Mesh_Entry, int viewId )
676 class TSetActorAspect: public SALOME_Event
680 actorAspect _actorPres;
682 TSetActorAspect(const actorAspect& actorPres, const char* Mesh_Entry, int viewId )
685 _actorPres = actorPres;
688 virtual void Execute()
690 SMESH_Actor* anActor;
693 SUIT_ViewWindow* w = getWnd(_wid);
694 anActor = SMESH::FindActorByEntry( w, _entry );
697 anActor = SMESH::FindActorByEntry( _entry );
700 MESSAGE("SetActorAspect: no actor corresponding to: " << _entry);
703 anActor->SetSufaceColor(_actorPres.surfaceColor.r,
704 _actorPres.surfaceColor.g,
705 _actorPres.surfaceColor.b,
706 _actorPres.surfaceColor.delta);
707 anActor->SetVolumeColor(_actorPres.volumeColor.r,
708 _actorPres.volumeColor.g,
709 _actorPres.volumeColor.b,
710 _actorPres.volumeColor.delta);
711 anActor->SetEdgeColor(_actorPres.edgeColor.r,
712 _actorPres.edgeColor.g,
713 _actorPres.edgeColor.b);
714 anActor->SetNodeColor(_actorPres.nodeColor.r,
715 _actorPres.nodeColor.g,
716 _actorPres.nodeColor.b);
717 anActor->SetOpacity(_actorPres.opacity);
720 SUIT_ViewWindow* w = getWnd(_wid);
725 SUIT_Session* aSession = SUIT_Session::session();
726 SUIT_Application* anApplication = aSession->activeApplication();
727 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
728 SUIT_ViewManager* vman = anApp->getViewManager(VTKViewer_Viewer::Type(),true);
729 vman->getActiveView()->repaint();
734 ProcessVoidEvent(new TSetActorAspect(actorPres, Mesh_Entry, viewId));
737 void SMESH_Swig::CreateAndDisplayActor( const char* Mesh_Entry )
739 // SMESH_Actor* Mesh = smeshGUI->ReadScript(aM);
740 class TEvent: public SALOME_Event
745 TEvent(const char* Mesh_Entry) {
748 virtual void Execute() {
749 //SMESH::UpdateView(SMESH::eDisplay, _entry);
750 SUIT_Session* aSession = SUIT_Session::session();
751 SUIT_Application* anApplication = aSession->activeApplication();
752 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
753 /*SUIT_ViewManager* vman = */anApp->getViewManager(VTKViewer_Viewer::Type(),true);
754 SMESHGUI_Displayer* aDisp = new SMESHGUI_Displayer(anApp);
755 aDisp->Display(_entry,1);
759 ProcessVoidEvent(new TEvent(Mesh_Entry));
762 void SMESH_Swig::EraseActor( const char* Mesh_Entry, const bool allViewers )
764 class TEvent: public SALOME_Event
770 TEvent(const char* Mesh_Entry, const bool allViewers ) {
772 _allViewers = allViewers;
774 virtual void Execute() {
775 SUIT_Session* aSession = SUIT_Session::session();
776 SUIT_Application* anApplication = aSession->activeApplication();
777 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
778 SMESHGUI_Displayer* aDisp = new SMESHGUI_Displayer(anApp);
779 ViewManagerList aManagers;
780 if ( !_allViewers ) {
781 aManagers << anApp->activeViewManager();
784 aManagers = anApp->viewManagers();
786 foreach( SUIT_ViewManager* aMgr, aManagers ) {
787 if ( aMgr && aMgr->getType() == VTKViewer_Viewer::Type() ) {
788 SALOME_View* aSalomeView = dynamic_cast<SALOME_View*>(aMgr->getViewModel());
790 aDisp->Erase(_entry,true, true, aSalomeView);
797 ProcessVoidEvent(new TEvent(Mesh_Entry, allViewers));
800 void SMESH_Swig::SetName(const char* theEntry,
803 SALOMEDS::SObject_var aSObject = KERNEL::getStudyServant()->FindObjectID(theEntry);
804 SALOMEDS::GenericAttribute_var anAttr;
805 SALOMEDS::AttributeName_var aName;
806 if(!aSObject->_is_nil()){
807 anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeName");
808 aName = SALOMEDS::AttributeName::_narrow(anAttr);
809 aName->SetValue(theName);
811 aSObject->UnRegister();
815 //================================================================================
817 * \brief Set mesh icon according to compute status
818 * \param Mesh_Entry - entry of a mesh
819 * \param isComputed - is mesh computed or not
821 //================================================================================
823 void SMESH_Swig::SetMeshIcon(const char* theMeshEntry,
824 const bool theIsComputed,
827 class TEvent: public SALOME_Event
829 std::string myMeshEntry;
830 bool myIsComputed, myIsEmpty;
832 TEvent(const std::string& theMeshEntry,
833 const bool theIsComputed,
835 myMeshEntry (theMeshEntry),
836 myIsComputed(theIsComputed),
844 SALOMEDS::SObject_ptr aMeshSO = KERNEL::getStudyServant()->FindObjectID(myMeshEntry.c_str());
845 if(_PTR(SObject) aMesh = ClientFactory::SObject(aMeshSO))
846 SMESH::ModifiedMesh(aMesh,myIsComputed,myIsEmpty);
847 // aMeshSO->UnRegister(); ~aMesh() already called UnRegister()!
851 ProcessVoidEvent(new TEvent(theMeshEntry,
857 \brief Helper class for selection event.
859 class TSelectListEvent: public SALOME_Event
862 std::vector<int> myIdsList;
866 TSelectListEvent(const char* id, std::vector<int> ids, bool append) :
871 virtual void Execute()
873 SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
877 LightApp_SelectionMgr* selMgr = SMESH::GetSelectionMgr( aSMESHGUI );
881 selMgr->clearFilters();
883 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( aSMESHGUI );
887 SMESH_Actor* anActor = SMESH::FindActorByEntry( myId );
889 if (!anActor || !anActor->hasIO())
892 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
895 selMgr->setSelectedObjects(aList, false);
897 if ( aViewWindow->SelectionMode() == ActorSelection ) {
901 TColStd_MapOfInteger aMap;
902 std::vector<int>::const_iterator anIter;
903 for (anIter = myIdsList.begin(); anIter != myIdsList.end(); ++anIter) {
908 SVTK_Selector* aSelector = aViewWindow->GetSelector();
909 aSelector->AddOrRemoveIndex(anIO, aMap, myIsAppend);
910 aViewWindow->highlight( anIO, true, true );
911 aViewWindow->GetInteractor()->onEmitSelectionChanged();
916 \brief Select the elements on the mesh, sub-mesh or group.
917 \param id object entry
918 \param ids list of the element ids
919 \param mode selection mode
921 void SMESH_Swig::select( const char* id, std::vector<int> ids, bool append ) {
922 ProcessVoidEvent( new TSelectListEvent( id, ids, append ) );
926 \brief Select the elements on the mesh, sub-mesh or group.
927 \param id object entry
928 \param id id of the element
929 \param mode selection mode
931 void SMESH_Swig::select( const char* id, int id1, bool append ) {
932 std::vector<int> ids;
933 ids.push_back( id1 );
934 ProcessVoidEvent( new TSelectListEvent( id, ids, append ) );
938 class TGetSelectionModeEvent : public SALOME_Event
943 TGetSelectionModeEvent() : myResult( -1 ) {}
944 virtual void Execute()
946 SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
950 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( aSMESHGUI );
954 myResult = aViewWindow->SelectionMode();
959 \brief Get selection mode of the active VTK View window.
961 int SMESH_Swig::getSelectionMode() {
962 return ProcessEvent( new TGetSelectionModeEvent() );