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"
27 #include <SVTK_Selector.h>
30 #include <SMESHGUI_Utils.h>
31 #include <SMESHGUI_Displayer.h>
32 #include <SMESHGUI_VTKUtils.h>
33 #include <SMESH_Actor.h>
35 // SALOME KERNEL includes
36 #include <Utils_ORB_INIT.hxx>
37 #include <Utils_SINGLETON.hxx>
38 #include <SALOMEDSClient_ClientFactory.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>
53 #include <VTKViewer_Algorithm.h>
57 #include <TColStd_MapOfInteger.hxx>
60 #include <QApplication>
63 #include <SALOMEconfig.h>
64 #include CORBA_SERVER_HEADER(SMESH_Gen)
65 #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
68 #include <vtkActorCollection.h>
69 #include <vtkRenderer.h>
71 static CORBA::ORB_var anORB;
75 //---------------------------------------------------------------
78 StringToObject(const std::string& theIOR)
80 return anORB->string_to_object(theIOR.c_str());
84 //---------------------------------------------------------------
87 GetDomainRoot(const SALOMEDS::SComponent_var& theSComponentMesh,
88 const SALOMEDS::StudyBuilder_var& theStudyBuilder,
89 CORBA::Long theDomainRootTag,
90 const QString& theName,
91 const QString& thePixmap)
93 SALOMEDS::SObject_var aDomainRoot;
94 if (!theSComponentMesh->FindSubObject(theDomainRootTag,aDomainRoot)) {
95 aDomainRoot = theStudyBuilder->NewObjectToTag(theSComponentMesh,theDomainRootTag);
96 SALOMEDS::GenericAttribute_var anAttr = theStudyBuilder->FindOrCreateAttribute(aDomainRoot,"AttributeName");
97 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
98 aName->SetValue(theName.toLatin1().data());
100 anAttr = theStudyBuilder->FindOrCreateAttribute(aDomainRoot,"AttributePixMap");
101 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
102 aPixmap->SetPixMap(thePixmap.toLatin1().data());
103 aPixmap->UnRegister();
104 anAttr = theStudyBuilder->FindOrCreateAttribute(aDomainRoot,"AttributeSelectable");
105 SALOMEDS::AttributeSelectable_var aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
106 aSelAttr->SetSelectable(false);
107 aSelAttr->UnRegister();
114 //---------------------------------------------------------------
116 SALOMEDS::SObject_var
117 GetHypothesisRoot(const SALOMEDS::SComponent_var& theSComponentMesh,
118 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
120 return GetDomainRoot(theSComponentMesh,
122 SMESH::Tag_HypothesisRoot,
123 QObject::tr("SMESH_MEN_HYPOTHESIS"),
124 "ICON_SMESH_TREE_HYPO");
128 //---------------------------------------------------------------
130 SALOMEDS::SObject_var
131 GetAlgorithmsRoot(const SALOMEDS::SComponent_var& theSComponentMesh,
132 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
134 return GetDomainRoot(theSComponentMesh,
136 SMESH::Tag_AlgorithmsRoot,
137 QObject::tr("SMESH_MEN_ALGORITHMS"),
138 "ICON_SMESH_TREE_ALGO");
142 //---------------------------------------------------------------
144 SALOMEDS::SObject_var
145 AddToDomain(const std::string& theIOR,
146 const SALOMEDS::SComponent_var& theSComponentMesh,
147 const SALOMEDS::StudyBuilder_var& theStudyBuilder,
148 CORBA::Long theDomainRootTag,
149 const QString& theDomainName,
150 const QString& theDomainPixmap)
152 SALOMEDS::SObject_var aDomain = GetDomainRoot(theSComponentMesh,
154 SMESH::Tag_AlgorithmsRoot,
157 // Add New Hypothesis
158 SALOMEDS::SObject_var aSObject = theStudyBuilder->NewObject(aDomain);
159 aDomain->UnRegister();
160 SALOMEDS::GenericAttribute_var anAttr = theStudyBuilder->FindOrCreateAttribute(aSObject,"AttributePixMap");
161 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
162 CORBA::Object_var anObject = StringToObject(theIOR);
163 SMESH::SMESH_Hypothesis_var aDomainItem = SMESH::SMESH_Hypothesis::_narrow(anObject.in());
164 CORBA::String_var aType = aDomainItem->GetName();
165 QString aPixmapName = theDomainPixmap + "_" + aType.in();
166 aPixmap->SetPixMap(aPixmapName.toLatin1().data());
167 aPixmap->UnRegister();
168 anAttr = theStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeIOR");
169 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
170 anIOR->SetValue(theIOR.c_str());
177 //---------------------------------------------------------------
178 SALOMEDS::SObject_var
179 AddHypothesis(const std::string& theIOR,
180 const SALOMEDS::SComponent_var& theSComponentMesh,
181 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
183 return AddToDomain(theIOR,
186 SMESH::Tag_HypothesisRoot,
187 QObject::tr("SMESH_MEN_HYPOTHESIS"),
188 "ICON_SMESH_TREE_HYPO");
192 //---------------------------------------------------------------
193 SALOMEDS::SObject_var
194 AddAlgorithms(const std::string& theIOR,
195 const SALOMEDS::SComponent_var& theSComponentMesh,
196 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
198 return AddToDomain(theIOR,
201 SMESH::Tag_AlgorithmsRoot,
202 QObject::tr("SMESH_MEN_ALGORITHMS"),
203 "ICON_SMESH_TREE_ALGO");
207 //---------------------------------------------------------------
209 SetDomain(const char* theMeshOrSubMeshEntry,
210 const char* theDomainEntry,
211 const SALOMEDS::Study_var& theStudy,
212 const SALOMEDS::StudyBuilder_var& theStudyBuilder,
213 long theRefOnAppliedDomainTag,
214 const QString& theAppliedDomainMEN,
215 const QString& theAppliedDomainICON)
217 SALOMEDS::SObject_var aMeshOrSubMeshSO = theStudy->FindObjectID(theMeshOrSubMeshEntry);
218 SALOMEDS::SObject_var aHypothesisSO = theStudy->FindObjectID(theDomainEntry);
220 if(!aMeshOrSubMeshSO->_is_nil() && !aHypothesisSO->_is_nil()){
221 //Find or Create Applied Hypothesis root
222 SALOMEDS::SObject_var anAppliedDomainSO;
223 if( !aMeshOrSubMeshSO->FindSubObject( theRefOnAppliedDomainTag, anAppliedDomainSO ))
225 anAppliedDomainSO = theStudyBuilder->NewObjectToTag(aMeshOrSubMeshSO,theRefOnAppliedDomainTag);
226 SALOMEDS::GenericAttribute_var anAttr =
227 theStudyBuilder->FindOrCreateAttribute(anAppliedDomainSO,"AttributeName");
228 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
229 aName->SetValue(theAppliedDomainMEN.toLatin1().data());
231 anAttr = theStudyBuilder->FindOrCreateAttribute(anAppliedDomainSO,"AttributeSelectable");
232 SALOMEDS::AttributeSelectable_var aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
233 aSelAttr->SetSelectable(false);
234 aSelAttr->UnRegister();
235 anAttr = theStudyBuilder->FindOrCreateAttribute(anAppliedDomainSO,"AttributePixMap");
236 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
237 aPixmap->SetPixMap(theAppliedDomainICON.toLatin1().data());
238 aPixmap->UnRegister();
240 SALOMEDS::SObject_var aSObject = theStudyBuilder->NewObject(anAppliedDomainSO);
241 theStudyBuilder->Addreference(aSObject,aHypothesisSO);
242 aSObject->UnRegister();
243 anAppliedDomainSO->UnRegister();
245 if ( !aMeshOrSubMeshSO->_is_nil() ) aMeshOrSubMeshSO->UnRegister();
246 if ( !aHypothesisSO->_is_nil()) aHypothesisSO->UnRegister();
250 //---------------------------------------------------------------
252 SetHypothesis(const char* theMeshOrSubMeshEntry,
253 const char* theDomainEntry,
254 const SALOMEDS::Study_var& theStudy,
255 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
257 SetDomain(theMeshOrSubMeshEntry,
261 SMESH::Tag_RefOnAppliedHypothesis,
262 QObject::tr("SMESH_MEN_APPLIED_HYPOTHESIS"),
263 "ICON_SMESH_TREE_HYPO");
267 //---------------------------------------------------------------
269 SetAlgorithms(const char* theMeshOrSubMeshEntry,
270 const char* theDomainEntry,
271 const SALOMEDS::Study_var& theStudy,
272 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
274 SetDomain(theMeshOrSubMeshEntry,
278 SMESH::Tag_RefOnAppliedAlgorithms,
279 QObject::tr("SMESH_MEN_APPLIED_ALGORIHTMS"),
280 "ICON_SMESH_TREE_ALGO");
285 //===============================================================
286 SMESH_Swig::SMESH_Swig()
288 class TEvent: public SALOME_Event
290 CORBA::ORB_var& myORB;
293 TEvent(CORBA::ORB_var& theORB):
302 ORB_INIT &anORBInit = *SINGLETON_<ORB_INIT>::Instance();
303 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
304 myORB = anORBInit( 0, 0 );
306 INFOS("internal error : orb not found");
311 //MESSAGE("Constructeur");
313 if(CORBA::is_nil(anORB))
314 ProcessVoidEvent(new TEvent(anORB));
316 ASSERT(!CORBA::is_nil(anORB));
320 //===============================================================
322 SMESH_Swig::Init(int theStudyID)
324 class TEvent: public SALOME_Event
327 SALOMEDS::Study_var& myStudy;
328 SALOMEDS::StudyBuilder_var& myStudyBuilder;
329 SALOMEDS::SComponent_var& mySComponentMesh;
331 TEvent(int theStudyID,
332 SALOMEDS::Study_var& theStudy,
333 SALOMEDS::StudyBuilder_var& theStudyBuilder,
334 SALOMEDS::SComponent_var& theSComponentMesh):
335 myStudyID (theStudyID),
337 myStudyBuilder (theStudyBuilder),
338 mySComponentMesh(theSComponentMesh)
343 if ( !mySComponentMesh->_is_nil() ) mySComponentMesh->UnRegister();
350 SUIT_Session* aSession = SUIT_Session::session();
351 SUIT_Application* anApplication = aSession->activeApplication();
352 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
354 SALOME_NamingService* aNamingService = anApp->namingService();
355 CORBA::Object_var anObject = aNamingService->Resolve("/myStudyManager");
356 SALOMEDS::StudyManager_var aStudyMgr = SALOMEDS::StudyManager::_narrow(anObject);
357 myStudy = aStudyMgr->GetStudyByID(myStudyID);
359 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
360 aSMESHGen->SetCurrentStudy( myStudy.in() );
362 myStudyBuilder = myStudy->NewBuilder();
364 SALOMEDS::GenericAttribute_var anAttr;
365 SALOMEDS::AttributeName_var aName;
366 SALOMEDS::AttributePixMap_var aPixmap;
368 SALOMEDS::SComponent_var aSComponent = myStudy->FindComponent("SMESH");
369 if ( aSComponent->_is_nil() )
371 bool aLocked = myStudy->GetProperties()->IsLocked();
373 myStudy->GetProperties()->SetLocked(false);
375 SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
376 //SRN: BugID IPAL9186, load a SMESH gui if it hasn't been loaded
378 CAM_Module* aModule = anApp->module("Mesh");
380 aModule = anApp->loadModule("Mesh");
381 aSMESHGUI = dynamic_cast<SMESHGUI*>(aModule);
382 } //SRN: BugID IPAL9186: end of a fix
384 aSComponent = myStudyBuilder->NewComponent("SMESH");
386 anAttr = myStudyBuilder->FindOrCreateAttribute(aSComponent,"AttributeName");
387 aName = SALOMEDS::AttributeName::_narrow(anAttr);
388 aName->SetValue(aSMESHGUI->moduleName().toLatin1().data());
391 anAttr = myStudyBuilder->FindOrCreateAttribute(aSComponent,"AttributePixMap");
392 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
393 aPixmap->SetPixMap( "ICON_OBJBROWSER_SMESH" );
394 aPixmap->UnRegister();
396 SALOMEDS::UseCaseBuilder_var useCaseBuilder = myStudy->GetUseCaseBuilder();
397 useCaseBuilder->SetRootCurrent();
398 useCaseBuilder->Append( aSComponent.in() );
400 myStudyBuilder->DefineComponentInstance(aSComponent,aSMESHGen);
402 myStudy->GetProperties()->SetLocked(true);
405 mySComponentMesh = SALOMEDS::SComponent::_narrow(aSComponent);
407 qApp->processEvents(); // Workaround for bug 12662
413 ProcessVoidEvent(new TEvent(theStudyID,
420 //===============================================================
421 SMESH_Swig::~SMESH_Swig()
423 //MESSAGE("Destructeur");
427 //===============================================================
428 const char* SMESH_Swig::AddNewMesh(const char* theIOR)
431 // VSR: added temporarily - to be removed - objects are published automatically by engine
432 SALOMEDS::SObject_var aSObject = myStudy->FindObjectIOR(theIOR);
433 if (aSObject->_is_nil())
435 //Find or Create Hypothesis root
436 SALOMEDS::SObject_var hroot = GetHypothesisRoot(mySComponentMesh,myStudyBuilder);
437 SALOMEDS::SObject_var aroot = GetAlgorithmsRoot(mySComponentMesh,myStudyBuilder);
442 aSObject = myStudyBuilder->NewObject(mySComponentMesh);
443 SALOMEDS::GenericAttribute_var anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributePixMap");
444 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
445 aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH" );
446 aPixmap->UnRegister();
448 anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeIOR");
449 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
450 anIOR->SetValue(theIOR);
454 CORBA::String_var anEntry = aSObject->GetID();
455 aSObject->UnRegister();
457 return anEntry._retn();
461 //===============================================================
462 const char* SMESH_Swig::AddNewHypothesis(const char* theIOR)
464 SALOMEDS::SObject_var aSObject = ::AddHypothesis(theIOR,
467 CORBA::String_var anEntry = aSObject->GetID();
468 aSObject->UnRegister();
470 return anEntry._retn();
474 //===============================================================
475 const char* SMESH_Swig::AddNewAlgorithms(const char* theIOR)
477 SALOMEDS::SObject_var aSObject = ::AddAlgorithms(theIOR,
480 CORBA::String_var anEntry = aSObject->GetID();
481 aSObject->UnRegister();
483 return anEntry._retn();
487 //===============================================================
488 void SMESH_Swig::SetShape(const char* theShapeEntry,
489 const char* theMeshEntry)
491 SALOMEDS::SObject_var aGeomShapeSO = myStudy->FindObjectID( theShapeEntry );
492 SALOMEDS::SObject_var aMeshSO = myStudy->FindObjectID( theMeshEntry );
494 if(!aMeshSO->_is_nil() && !aGeomShapeSO->_is_nil()){
495 SALOMEDS::SObject_var aSObject = myStudyBuilder->NewObjectToTag(aMeshSO, SMESH::Tag_RefOnShape);
496 myStudyBuilder->Addreference(aSObject,aGeomShapeSO);
497 aSObject->UnRegister();
499 if ( !aMeshSO->_is_nil() ) aMeshSO->UnRegister();
500 if ( !aGeomShapeSO->_is_nil() ) aGeomShapeSO->UnRegister();
504 //===============================================================
505 void SMESH_Swig::SetHypothesis(const char* theMeshOrSubMeshEntry,
506 const char* theDomainEntry)
508 ::SetHypothesis(theMeshOrSubMeshEntry,
515 //===============================================================
516 void SMESH_Swig::SetAlgorithms(const char* theMeshOrSubMeshEntry,
517 const char* theDomainEntry)
519 ::SetAlgorithms(theMeshOrSubMeshEntry,
526 //===============================================================
528 SMESH_Swig::UnSetHypothesis(const char* theDomainEntry)
530 SALOMEDS::SObject_var aDomainSO = myStudy->FindObjectID(theDomainEntry);
531 if(!aDomainSO->_is_nil())
532 myStudyBuilder->RemoveObject(aDomainSO);
535 const char* SMESH_Swig::AddSubMesh(const char* theMeshEntry,
536 const char* theSubMeshIOR,
539 SALOMEDS::SObject_var aMeshSO = myStudy->FindObjectID(theMeshEntry);
540 if(!aMeshSO->_is_nil()) {
542 QString aSubMeshName;
543 switch(theShapeType) {
545 aShapeTag = SMESH::Tag_SubMeshOnSolid;
546 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnSolid");
549 aShapeTag = SMESH::Tag_SubMeshOnFace;
550 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnFace");
553 aShapeTag = SMESH::Tag_SubMeshOnEdge;
554 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnEdge");
557 aShapeTag = SMESH::Tag_SubMeshOnVertex;
558 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnVertex");
561 aShapeTag = SMESH::Tag_SubMeshOnCompound;
562 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnCompound");
565 SALOMEDS::GenericAttribute_var anAttr;
566 SALOMEDS::SObject_var aSubMeshesRoot;
567 if ( !aMeshSO->FindSubObject( aShapeTag, aSubMeshesRoot ) )
569 aSubMeshesRoot = myStudyBuilder->NewObjectToTag(aMeshSO,aShapeTag);
570 anAttr = myStudyBuilder->FindOrCreateAttribute(aSubMeshesRoot,"AttributeName");
571 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
572 aName->SetValue(aSubMeshName.toLatin1().data());
574 anAttr = myStudyBuilder->FindOrCreateAttribute(aSubMeshesRoot,"AttributeSelectable");
575 SALOMEDS::AttributeSelectable_var aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
576 aSelAttr->SetSelectable(false);
577 aSelAttr->UnRegister();
579 aSubMeshesRoot->UnRegister();
580 aMeshSO->UnRegister();
582 SALOMEDS::SObject_var aSObject = myStudyBuilder->NewObject(aSubMeshesRoot);
583 anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeIOR");
584 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
585 anIOR->SetValue(theSubMeshIOR);
588 CORBA::String_var aString = aSObject->GetID();
589 aSObject->UnRegister();
591 return aString._retn();
597 const char* SMESH_Swig::AddSubMeshOnShape(const char* theMeshEntry,
598 const char* theGeomShapeEntry,
599 const char* theSubMeshIOR,
602 SALOMEDS::SObject_var aGeomShapeSO = myStudy->FindObjectID(theGeomShapeEntry);
603 if(!aGeomShapeSO->_is_nil())
605 const char * aSubMeshEntry = AddSubMesh(theMeshEntry,theSubMeshIOR,ShapeType);
606 SALOMEDS::SObject_var aSubMeshSO = myStudy->FindObjectID(aSubMeshEntry);
607 if ( !aSubMeshSO->_is_nil()) {
608 SetShape( theGeomShapeEntry, aSubMeshEntry );
609 CORBA::String_var aString = aSubMeshSO->GetID();
610 aSubMeshSO->UnRegister();
611 return aString._retn();
613 aGeomShapeSO->UnRegister();
620 \brief Gets window with specified identifier
622 \param id window identifier
623 \return pointer on the window
626 SUIT_ViewWindow* getWnd( const int id )
628 SUIT_ViewWindow* resWnd = 0;
629 SUIT_Session* aSession = SUIT_Session::session();
630 SUIT_Application* anApplication = aSession->activeApplication();
631 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(anApplication);
633 ViewManagerList vmlist = app->viewManagers();
634 foreach( SUIT_ViewManager* vm, vmlist ) {
635 QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
636 foreach ( SUIT_ViewWindow* vw, vwlist ) {
637 if ( id == vw->getId() ) {
647 class TGetActorAspect: public SALOME_Event
650 typedef actorAspect TResult;
654 TGetActorAspect( const char* Mesh_Entry, int viewId )
659 virtual void Execute()
661 SMESH_Actor* anActor;
664 SUIT_ViewWindow* w = getWnd(_wid);
665 anActor = SMESH::FindActorByEntry( w, _entry );
668 anActor = SMESH::FindActorByEntry( _entry );
671 MESSAGE("GetActorAspect: no actor corresponding to: " << _entry);
674 anActor->GetSufaceColor(myResult.surfaceColor.r,
675 myResult.surfaceColor.g,
676 myResult.surfaceColor.b,
677 myResult.surfaceColor.delta);
678 anActor->GetVolumeColor(myResult.volumeColor.r,
679 myResult.volumeColor.g,
680 myResult.volumeColor.b,
681 myResult.volumeColor.delta);
682 anActor->GetEdgeColor(myResult.edgeColor.r,
683 myResult.edgeColor.g,
684 myResult.edgeColor.b);
685 anActor->GetNodeColor(myResult.nodeColor.r,
686 myResult.nodeColor.g,
687 myResult.nodeColor.b);
688 myResult.opacity= anActor->GetOpacity();
689 MESSAGE("opacity: " << myResult.opacity);
693 actorAspect SMESH_Swig::GetActorAspect( const char* Mesh_Entry, int viewId )
695 return ProcessEvent(new TGetActorAspect( Mesh_Entry, viewId));
698 void SMESH_Swig::SetActorAspect( const actorAspect& actorPres, const char* Mesh_Entry, int viewId )
700 class TSetActorAspect: public SALOME_Event
704 actorAspect _actorPres;
706 TSetActorAspect(const actorAspect& actorPres, const char* Mesh_Entry, int viewId )
709 _actorPres = actorPres;
712 virtual void Execute()
714 SMESH_Actor* anActor;
717 SUIT_ViewWindow* w = getWnd(_wid);
718 anActor = SMESH::FindActorByEntry( w, _entry );
721 anActor = SMESH::FindActorByEntry( _entry );
724 MESSAGE("SetActorAspect: no actor corresponding to: " << _entry);
727 anActor->SetSufaceColor(_actorPres.surfaceColor.r,
728 _actorPres.surfaceColor.g,
729 _actorPres.surfaceColor.b,
730 _actorPres.surfaceColor.delta);
731 anActor->SetVolumeColor(_actorPres.volumeColor.r,
732 _actorPres.volumeColor.g,
733 _actorPres.volumeColor.b,
734 _actorPres.volumeColor.delta);
735 anActor->SetEdgeColor(_actorPres.edgeColor.r,
736 _actorPres.edgeColor.g,
737 _actorPres.edgeColor.b);
738 anActor->SetNodeColor(_actorPres.nodeColor.r,
739 _actorPres.nodeColor.g,
740 _actorPres.nodeColor.b);
741 anActor->SetOpacity(_actorPres.opacity);
744 SUIT_ViewWindow* w = getWnd(_wid);
749 SUIT_Session* aSession = SUIT_Session::session();
750 SUIT_Application* anApplication = aSession->activeApplication();
751 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
752 SUIT_ViewManager* vman = anApp->getViewManager(VTKViewer_Viewer::Type(),true);
753 vman->getActiveView()->repaint();
758 ProcessVoidEvent(new TSetActorAspect(actorPres, Mesh_Entry, viewId));
761 void SMESH_Swig::CreateAndDisplayActor( const char* Mesh_Entry )
763 // SMESH_Actor* Mesh = smeshGUI->ReadScript(aM);
764 class TEvent: public SALOME_Event
769 TEvent(const char* Mesh_Entry) {
772 virtual void Execute() {
773 //SMESH::UpdateView(SMESH::eDisplay, _entry);
774 SUIT_Session* aSession = SUIT_Session::session();
775 SUIT_Application* anApplication = aSession->activeApplication();
776 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
777 /*SUIT_ViewManager* vman = */anApp->getViewManager(VTKViewer_Viewer::Type(),true);
778 SMESHGUI_Displayer* aDisp = new SMESHGUI_Displayer(anApp);
779 aDisp->Display(_entry,1);
783 ProcessVoidEvent(new TEvent(Mesh_Entry));
786 void SMESH_Swig::EraseActor( const char* Mesh_Entry, const bool allViewers )
788 class TEvent: public SALOME_Event
794 TEvent(const char* Mesh_Entry, const bool allViewers ) {
796 _allViewers = allViewers;
798 virtual void Execute() {
799 SUIT_Session* aSession = SUIT_Session::session();
800 SUIT_Application* anApplication = aSession->activeApplication();
801 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
802 SMESHGUI_Displayer* aDisp = new SMESHGUI_Displayer(anApp);
803 ViewManagerList aManagers;
804 if ( !_allViewers ) {
805 aManagers << anApp->activeViewManager();
808 aManagers = anApp->viewManagers();
810 foreach( SUIT_ViewManager* aMgr, aManagers ) {
811 if ( aMgr && aMgr->getType() == VTKViewer_Viewer::Type() ) {
812 SALOME_View* aSalomeView = dynamic_cast<SALOME_View*>(aMgr->getViewModel());
814 aDisp->Erase(_entry,true, true, aSalomeView);
821 ProcessVoidEvent(new TEvent(Mesh_Entry, allViewers));
824 void SMESH_Swig::UpdateActor( const char* Mesh_Entry ) {
825 class TEvent: public SALOME_Event
830 TEvent( const char* Mesh_Entry ) {
833 virtual void Execute() {
834 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
835 ( _entry, "SMESH", "" );
836 SMESH::Update( anIO, true );
840 ProcessVoidEvent( new TEvent(Mesh_Entry) );
843 void SMESH_Swig::SetName(const char* theEntry,
846 SALOMEDS::SObject_var aSObject = myStudy->FindObjectID(theEntry);
847 SALOMEDS::GenericAttribute_var anAttr;
848 SALOMEDS::AttributeName_var aName;
849 if(!aSObject->_is_nil()){
850 anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeName");
851 aName = SALOMEDS::AttributeName::_narrow(anAttr);
852 aName->SetValue(theName);
854 aSObject->UnRegister();
858 //================================================================================
860 * \brief Set mesh icon according to compute status
861 * \param Mesh_Entry - entry of a mesh
862 * \param isComputed - is mesh computed or not
864 //================================================================================
866 void SMESH_Swig::SetMeshIcon(const char* theMeshEntry,
867 const bool theIsComputed,
870 class TEvent: public SALOME_Event
872 SALOMEDS::Study_var myStudy;
873 std::string myMeshEntry;
874 bool myIsComputed, myIsEmpty;
876 TEvent(const SALOMEDS::Study_var& theStudy,
877 const std::string& theMeshEntry,
878 const bool theIsComputed,
881 myMeshEntry (theMeshEntry),
882 myIsComputed(theIsComputed),
890 SALOMEDS::SObject_ptr aMeshSO = myStudy->FindObjectID(myMeshEntry.c_str());
891 if(_PTR(SObject) aMesh = ClientFactory::SObject(aMeshSO))
892 SMESH::ModifiedMesh(aMesh,myIsComputed,myIsEmpty);
893 // aMeshSO->UnRegister(); ~aMesh() already called UnRegister()!
897 ProcessVoidEvent(new TEvent(myStudy,
904 \brief Helper class for selection event.
906 class TSelectListEvent: public SALOME_Event
909 std::vector<int> myIdsList;
913 TSelectListEvent(const char* id, std::vector<int> ids, bool append) :
918 virtual void Execute()
921 LightApp_SelectionMgr* selMgr = 0;
922 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
924 selMgr = dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
929 selMgr->clearFilters();
931 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
935 SMESH_Actor* anActor = SMESH::FindActorByEntry( myId );
937 if (!anActor || !anActor->hasIO())
940 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
943 selMgr->setSelectedObjects(aList, false);
945 if ( aViewWindow->SelectionMode() == ActorSelection ) {
949 TColStd_MapOfInteger aMap;
950 std::vector<int>::const_iterator anIter;
951 for (anIter = myIdsList.begin(); anIter != myIdsList.end(); ++anIter) {
956 SVTK_Selector* aSelector = aViewWindow->GetSelector();
957 aSelector->AddOrRemoveIndex(anIO, aMap, myIsAppend);
958 aViewWindow->highlight( anIO, true, true );
959 aViewWindow->GetInteractor()->onEmitSelectionChanged();
964 \brief Select the elements on the mesh, sub-mesh or group.
965 \param id object entry
966 \param ids list of the element ids
967 \param mode selection mode
969 void SMESH_Swig::select( const char* id, std::vector<int> ids, bool append ) {
970 ProcessVoidEvent( new TSelectListEvent( id, ids, append ) );
974 \brief Select the elements on the mesh, sub-mesh or group.
975 \param id object entry
976 \param id id of the element
977 \param mode selection mode
979 void SMESH_Swig::select( const char* id, int id1, bool append ) {
980 std::vector<int> ids;
981 ids.push_back( id1 );
982 ProcessVoidEvent( new TSelectListEvent( id, ids, append ) );
986 \brief Helper class for selection edges of cell event
988 class TSelectListOfPairEvent: public SALOME_Event
991 std::vector<std::pair<int, int> > myIdsList;
995 TSelectListOfPairEvent(const char* id, std::vector<std::pair<int, int> > ids, bool append) :
1000 virtual void Execute()
1003 LightApp_SelectionMgr* selMgr = 0;
1004 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1006 selMgr = dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
1011 selMgr->clearFilters();
1013 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
1017 SMESH_Actor* anActor = SMESH::FindActorByEntry( myId );
1019 if (!anActor || !anActor->hasIO())
1022 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
1023 SALOME_ListIO aList;
1025 selMgr->setSelectedObjects(aList, false);
1027 if ( aViewWindow->SelectionMode() != EdgeOfCellSelection ) {
1031 SVTK_IndexedMapOfIds aMap;
1032 std::vector<std::pair<int, int> >::const_iterator anIter;
1033 for (anIter = myIdsList.begin(); anIter != myIdsList.end(); ++anIter) {
1034 std::vector<int> aCompositeId;
1035 aCompositeId.push_back((*anIter).first);
1036 aCompositeId.push_back((*anIter).second);
1037 aMap.Add(aCompositeId);
1040 // Set new selection
1041 SVTK_Selector* aSelector = aViewWindow->GetSelector();
1042 aSelector->AddOrRemoveCompositeIndex(anIO, aMap, myIsAppend);
1043 aViewWindow->highlight( anIO, true, true );
1044 aViewWindow->GetInteractor()->onEmitSelectionChanged();
1049 \brief Select the elements on the mesh, sub-mesh or group.
1050 \param id object entry
1051 \param ids list of the element ids
1052 \param mode selection mode
1054 void SMESH_Swig::select( const char* id, std::vector<std::pair<int,int> > ids, bool append ) {
1055 ProcessVoidEvent( new TSelectListOfPairEvent( id, ids, append ) );
1058 class TGetSelectionModeEvent : public SALOME_Event
1061 typedef SelectionMode TResult;
1063 TGetSelectionModeEvent() : myResult( Undefined ) {}
1064 virtual void Execute()
1066 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( );
1070 myResult = (SelectionMode) aViewWindow->SelectionMode();
1075 \brief Get selection mode of the active VTK View window.
1077 SelectionMode SMESH_Swig::getSelectionMode() {
1078 return ProcessEvent( new TGetSelectionModeEvent() );
1083 * Event to set selection mode
1085 class TSetSelectionModeEvent : public SALOME_Event
1087 SelectionMode mySelectionMode;
1091 TSetSelectionModeEvent(const SelectionMode selectionMode) :
1092 mySelectionMode(selectionMode)
1095 virtual void Execute()
1097 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
1101 Selection_Mode prevMode = aViewWindow->SelectionMode();
1102 bool changePointRepresentation = ( prevMode == NodeSelection && mySelectionMode != Node ) ||
1103 (prevMode != NodeSelection && mySelectionMode == Node);
1105 if( changePointRepresentation ) {
1106 vtkRenderer *aRenderer = aViewWindow->getRenderer();
1107 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1108 vtkActorCollection *aCollection = aCopy.GetActors();
1109 aCollection->InitTraversal();
1110 while(vtkActor *anAct = aCollection->GetNextActor()){
1111 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
1112 if(anActor->GetVisibility()){
1113 anActor->SetPointRepresentation(mySelectionMode == Node);
1118 aViewWindow->SetSelectionMode(mySelectionMode);
1122 void SMESH_Swig::setSelectionMode(SelectionMode selectionMode){
1123 ProcessVoidEvent( new TSetSelectionModeEvent( selectionMode ) );
1126 class TGetSelectedEvent : public SALOME_Event
1129 typedef std::vector<int> TResult;
1133 TGetSelectedEvent( const char* id) :
1134 myResult( std::vector<int>() ),
1138 virtual void Execute()
1140 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
1144 SVTK_Selector* aSelector = aViewWindow->GetSelector();
1148 SMESH_Actor* anActor = SMESH::FindActorByEntry( myId );
1150 if ( !anActor || !anActor->hasIO() )
1153 TColStd_IndexedMapOfInteger aMapIndex;
1154 aSelector->GetIndex(anActor->getIO(),aMapIndex);
1156 for( int i = 1; i <= aMapIndex.Extent(); i++ )
1157 myResult.push_back( aMapIndex( i ) );
1161 std::vector<int> SMESH_Swig::getSelected( const char* Mesh_Entry ) {
1162 return ProcessEvent( new TGetSelectedEvent(Mesh_Entry) );
1165 class TGetSelectedPairEvent : public SALOME_Event
1168 typedef std::vector<std::pair<int, int> > TResult;
1172 TGetSelectedPairEvent( const char* id) :
1173 myResult( std::vector<std::pair<int,int> >() ),
1177 virtual void Execute()
1179 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
1183 if(aViewWindow->SelectionMode() != EdgeOfCellSelection )
1186 SVTK_Selector* aSelector = aViewWindow->GetSelector();
1190 SMESH_Actor* anActor = SMESH::FindActorByEntry( myId );
1192 if ( !anActor || !anActor->hasIO() )
1195 SVTK_IndexedMapOfIds aMapIndex;
1196 aSelector->GetCompositeIndex(anActor->getIO(),aMapIndex);
1198 for( int i = 1; i <= aMapIndex.Extent(); i++ )
1199 myResult.push_back( std::make_pair<int,int>( (int)aMapIndex( i )[0], (int)aMapIndex( i )[1]) );
1203 std::vector<std::pair<int,int> > SMESH_Swig::getSelectedEdgeOfCell( const char* Mesh_Entry ) {
1204 return ProcessEvent( new TGetSelectedPairEvent(Mesh_Entry) );