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>
39 #include <SALOME_KernelServices.hxx>
41 #include <utilities.h>
43 // SALOME GUI includes
44 #include <SUIT_Session.h>
45 #include <SUIT_ViewManager.h>
46 #include <SALOME_Prs.h>
47 #include <SUIT_ViewWindow.h>
48 #include <SVTK_ViewWindow.h>
49 #include <VTKViewer_ViewModel.h>
50 #include <SALOME_Event.h>
51 #include <SalomeApp_Application.h>
52 #include <LightApp_SelectionMgr.h>
53 #include <SVTK_RenderWindowInteractor.h>
54 #include <VTKViewer_Algorithm.h>
58 #include <TColStd_MapOfInteger.hxx>
61 #include <QApplication>
64 #include <SALOMEconfig.h>
65 #include CORBA_SERVER_HEADER(SMESH_Gen)
66 #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
69 #include <vtkActorCollection.h>
70 #include <vtkRenderer.h>
72 static CORBA::ORB_var anORB;
76 //---------------------------------------------------------------
79 StringToObject(const std::string& theIOR)
81 return anORB->string_to_object(theIOR.c_str());
85 //---------------------------------------------------------------
88 GetDomainRoot(const SALOMEDS::SComponent_var& theSComponentMesh,
89 const SALOMEDS::StudyBuilder_var& theStudyBuilder,
90 CORBA::Long theDomainRootTag,
91 const QString& theName,
92 const QString& thePixmap)
94 SALOMEDS::SObject_var aDomainRoot;
95 if (!theSComponentMesh->FindSubObject(theDomainRootTag,aDomainRoot)) {
96 aDomainRoot = theStudyBuilder->NewObjectToTag(theSComponentMesh,theDomainRootTag);
97 SALOMEDS::GenericAttribute_var anAttr = theStudyBuilder->FindOrCreateAttribute(aDomainRoot,"AttributeName");
98 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
99 aName->SetValue(theName.toUtf8().data());
101 anAttr = theStudyBuilder->FindOrCreateAttribute(aDomainRoot,"AttributePixMap");
102 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
103 aPixmap->SetPixMap(thePixmap.toLatin1().data());
104 aPixmap->UnRegister();
105 anAttr = theStudyBuilder->FindOrCreateAttribute(aDomainRoot,"AttributeSelectable");
106 SALOMEDS::AttributeSelectable_var aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
107 aSelAttr->SetSelectable(false);
108 aSelAttr->UnRegister();
115 //---------------------------------------------------------------
117 SALOMEDS::SObject_var
118 GetHypothesisRoot(const SALOMEDS::SComponent_var& theSComponentMesh,
119 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
121 return GetDomainRoot(theSComponentMesh,
123 SMESH::Tag_HypothesisRoot,
124 QObject::tr("SMESH_MEN_HYPOTHESIS"),
125 "ICON_SMESH_TREE_HYPO");
129 //---------------------------------------------------------------
131 SALOMEDS::SObject_var
132 GetAlgorithmsRoot(const SALOMEDS::SComponent_var& theSComponentMesh,
133 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
135 return GetDomainRoot(theSComponentMesh,
137 SMESH::Tag_AlgorithmsRoot,
138 QObject::tr("SMESH_MEN_ALGORITHMS"),
139 "ICON_SMESH_TREE_ALGO");
143 //---------------------------------------------------------------
145 SALOMEDS::SObject_var
146 AddToDomain(const std::string& theIOR,
147 const SALOMEDS::SComponent_var& theSComponentMesh,
148 const SALOMEDS::StudyBuilder_var& theStudyBuilder,
149 CORBA::Long theDomainRootTag,
150 const QString& theDomainName,
151 const QString& theDomainPixmap)
153 SALOMEDS::SObject_var aDomain = GetDomainRoot(theSComponentMesh,
155 SMESH::Tag_AlgorithmsRoot,
158 // Add New Hypothesis
159 SALOMEDS::SObject_var aSObject = theStudyBuilder->NewObject(aDomain);
160 aDomain->UnRegister();
161 SALOMEDS::GenericAttribute_var anAttr = theStudyBuilder->FindOrCreateAttribute(aSObject,"AttributePixMap");
162 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
163 CORBA::Object_var anObject = StringToObject(theIOR);
164 SMESH::SMESH_Hypothesis_var aDomainItem = SMESH::SMESH_Hypothesis::_narrow(anObject.in());
165 CORBA::String_var aType = aDomainItem->GetName();
166 QString aPixmapName = theDomainPixmap + "_" + aType.in();
167 aPixmap->SetPixMap(aPixmapName.toLatin1().data());
168 aPixmap->UnRegister();
169 anAttr = theStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeIOR");
170 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
171 anIOR->SetValue(theIOR.c_str());
178 //---------------------------------------------------------------
179 SALOMEDS::SObject_var
180 AddHypothesis(const std::string& theIOR,
181 const SALOMEDS::SComponent_var& theSComponentMesh,
182 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
184 return AddToDomain(theIOR,
187 SMESH::Tag_HypothesisRoot,
188 QObject::tr("SMESH_MEN_HYPOTHESIS"),
189 "ICON_SMESH_TREE_HYPO");
193 //---------------------------------------------------------------
194 SALOMEDS::SObject_var
195 AddAlgorithms(const std::string& theIOR,
196 const SALOMEDS::SComponent_var& theSComponentMesh,
197 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
199 return AddToDomain(theIOR,
202 SMESH::Tag_AlgorithmsRoot,
203 QObject::tr("SMESH_MEN_ALGORITHMS"),
204 "ICON_SMESH_TREE_ALGO");
208 //---------------------------------------------------------------
210 SetDomain(const char* theMeshOrSubMeshEntry,
211 const char* theDomainEntry,
212 const SALOMEDS::StudyBuilder_var& theStudyBuilder,
213 long theRefOnAppliedDomainTag,
214 const QString& theAppliedDomainMEN,
215 const QString& theAppliedDomainICON)
217 SALOMEDS::SObject_var aMeshOrSubMeshSO = KERNEL::getStudyServant()->FindObjectID(theMeshOrSubMeshEntry);
218 SALOMEDS::SObject_var aHypothesisSO = KERNEL::getStudyServant()->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.toUtf8().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::StudyBuilder_var& theStudyBuilder)
256 SetDomain(theMeshOrSubMeshEntry,
259 SMESH::Tag_RefOnAppliedHypothesis,
260 QObject::tr("SMESH_MEN_APPLIED_HYPOTHESIS"),
261 "ICON_SMESH_TREE_HYPO");
265 //---------------------------------------------------------------
267 SetAlgorithms(const char* theMeshOrSubMeshEntry,
268 const char* theDomainEntry,
269 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
271 SetDomain(theMeshOrSubMeshEntry,
274 SMESH::Tag_RefOnAppliedAlgorithms,
275 QObject::tr("SMESH_MEN_APPLIED_ALGORIHTMS"),
276 "ICON_SMESH_TREE_ALGO");
281 //===============================================================
282 SMESH_Swig::SMESH_Swig()
284 class TEvent: public SALOME_Event
286 CORBA::ORB_var& myORB;
289 TEvent(CORBA::ORB_var& theORB):
298 ORB_INIT &anORBInit = *SINGLETON_<ORB_INIT>::Instance();
299 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
300 myORB = anORBInit( 0, 0 );
302 INFOS("internal error : orb not found");
307 //MESSAGE("Constructeur");
309 if(CORBA::is_nil(anORB))
310 ProcessVoidEvent(new TEvent(anORB));
312 ASSERT(!CORBA::is_nil(anORB));
316 //===============================================================
320 class TEvent: public SALOME_Event
322 SALOMEDS::StudyBuilder_var& myStudyBuilder;
323 SALOMEDS::SComponent_var& mySComponentMesh;
325 TEvent(SALOMEDS::StudyBuilder_var& theStudyBuilder,
326 SALOMEDS::SComponent_var& theSComponentMesh):
327 myStudyBuilder (theStudyBuilder),
328 mySComponentMesh(theSComponentMesh)
333 if ( !mySComponentMesh->_is_nil() ) mySComponentMesh->UnRegister();
340 SUIT_Session* aSession = SUIT_Session::session();
341 SUIT_Application* anApplication = aSession->activeApplication();
342 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
344 SALOMEDS::Study_var aStudy = KERNEL::getStudyServant();
346 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
348 myStudyBuilder = aStudy->NewBuilder();
350 SALOMEDS::GenericAttribute_var anAttr;
351 SALOMEDS::AttributeName_var aName;
352 SALOMEDS::AttributePixMap_var aPixmap;
354 SALOMEDS::SComponent_var aSComponent = aStudy->FindComponent("SMESH");
355 if ( aSComponent->_is_nil() )
357 bool aLocked = aStudy->GetProperties()->IsLocked();
359 aStudy->GetProperties()->SetLocked(false);
361 SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
362 //SRN: BugID IPAL9186, load a SMESH gui if it hasn't been loaded
364 CAM_Module* aModule = anApp->module("Mesh");
366 aModule = anApp->loadModule("Mesh");
367 aSMESHGUI = dynamic_cast<SMESHGUI*>(aModule);
368 } //SRN: BugID IPAL9186: end of a fix
370 aSComponent = myStudyBuilder->NewComponent("SMESH");
372 anAttr = myStudyBuilder->FindOrCreateAttribute(aSComponent,"AttributeName");
373 aName = SALOMEDS::AttributeName::_narrow(anAttr);
374 aName->SetValue(aSMESHGUI->moduleName().toLatin1().data());
377 anAttr = myStudyBuilder->FindOrCreateAttribute(aSComponent,"AttributePixMap");
378 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
379 aPixmap->SetPixMap( "ICON_OBJBROWSER_SMESH" );
380 aPixmap->UnRegister();
382 SALOMEDS::UseCaseBuilder_var useCaseBuilder = KERNEL::getStudyServant()->GetUseCaseBuilder();
383 useCaseBuilder->SetRootCurrent();
384 useCaseBuilder->Append( aSComponent.in() );
386 myStudyBuilder->DefineComponentInstance(aSComponent,aSMESHGen);
388 KERNEL::getStudyServant()->GetProperties()->SetLocked(true);
391 mySComponentMesh = SALOMEDS::SComponent::_narrow(aSComponent);
393 qApp->processEvents(); // Workaround for bug 12662
399 ProcessVoidEvent(new TEvent(myStudyBuilder,
404 //===============================================================
405 SMESH_Swig::~SMESH_Swig()
407 //MESSAGE("Destructeur");
411 //===============================================================
412 const char* SMESH_Swig::AddNewMesh(const char* theIOR)
415 // VSR: added temporarily - to be removed - objects are published automatically by engine
416 SALOMEDS::SObject_var aSObject = KERNEL::getStudyServant()->FindObjectIOR(theIOR);
417 if (aSObject->_is_nil())
419 //Find or Create Hypothesis root
420 SALOMEDS::SObject_var hroot = GetHypothesisRoot(mySComponentMesh,myStudyBuilder);
421 SALOMEDS::SObject_var aroot = GetAlgorithmsRoot(mySComponentMesh,myStudyBuilder);
426 aSObject = myStudyBuilder->NewObject(mySComponentMesh);
427 SALOMEDS::GenericAttribute_var anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributePixMap");
428 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
429 aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH" );
430 aPixmap->UnRegister();
432 anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeIOR");
433 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
434 anIOR->SetValue(theIOR);
438 CORBA::String_var anEntry = aSObject->GetID();
439 aSObject->UnRegister();
441 return anEntry._retn();
445 //===============================================================
446 const char* SMESH_Swig::AddNewHypothesis(const char* theIOR)
448 SALOMEDS::SObject_var aSObject = ::AddHypothesis(theIOR,
451 CORBA::String_var anEntry = aSObject->GetID();
452 aSObject->UnRegister();
454 return anEntry._retn();
458 //===============================================================
459 const char* SMESH_Swig::AddNewAlgorithms(const char* theIOR)
461 SALOMEDS::SObject_var aSObject = ::AddAlgorithms(theIOR,
464 CORBA::String_var anEntry = aSObject->GetID();
465 aSObject->UnRegister();
467 return anEntry._retn();
471 //===============================================================
472 void SMESH_Swig::SetShape(const char* theShapeEntry,
473 const char* theMeshEntry)
475 SALOMEDS::SObject_var aGeomShapeSO = KERNEL::getStudyServant()->FindObjectID( theShapeEntry );
476 SALOMEDS::SObject_var aMeshSO = KERNEL::getStudyServant()->FindObjectID( theMeshEntry );
478 if(!aMeshSO->_is_nil() && !aGeomShapeSO->_is_nil()){
479 SALOMEDS::SObject_var aSObject = myStudyBuilder->NewObjectToTag(aMeshSO, SMESH::Tag_RefOnShape);
480 myStudyBuilder->Addreference(aSObject,aGeomShapeSO);
481 aSObject->UnRegister();
483 if ( !aMeshSO->_is_nil() ) aMeshSO->UnRegister();
484 if ( !aGeomShapeSO->_is_nil() ) aGeomShapeSO->UnRegister();
488 //===============================================================
489 void SMESH_Swig::SetHypothesis(const char* theMeshOrSubMeshEntry,
490 const char* theDomainEntry)
492 ::SetHypothesis(theMeshOrSubMeshEntry,
498 //===============================================================
499 void SMESH_Swig::SetAlgorithms(const char* theMeshOrSubMeshEntry,
500 const char* theDomainEntry)
502 ::SetAlgorithms(theMeshOrSubMeshEntry,
508 //===============================================================
510 SMESH_Swig::UnSetHypothesis(const char* theDomainEntry)
512 SALOMEDS::SObject_var aDomainSO = KERNEL::getStudyServant()->FindObjectID(theDomainEntry);
513 if(!aDomainSO->_is_nil())
514 myStudyBuilder->RemoveObject(aDomainSO);
517 const char* SMESH_Swig::AddSubMesh(const char* theMeshEntry,
518 const char* theSubMeshIOR,
521 SALOMEDS::SObject_var aMeshSO = KERNEL::getStudyServant()->FindObjectID(theMeshEntry);
522 if(!aMeshSO->_is_nil()) {
524 QString aSubMeshName;
525 switch(theShapeType) {
527 aShapeTag = SMESH::Tag_SubMeshOnSolid;
528 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnSolid");
531 aShapeTag = SMESH::Tag_SubMeshOnFace;
532 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnFace");
535 aShapeTag = SMESH::Tag_SubMeshOnEdge;
536 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnEdge");
539 aShapeTag = SMESH::Tag_SubMeshOnVertex;
540 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnVertex");
543 aShapeTag = SMESH::Tag_SubMeshOnCompound;
544 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnCompound");
547 SALOMEDS::GenericAttribute_var anAttr;
548 SALOMEDS::SObject_var aSubMeshesRoot;
549 if ( !aMeshSO->FindSubObject( aShapeTag, aSubMeshesRoot ) )
551 aSubMeshesRoot = myStudyBuilder->NewObjectToTag(aMeshSO,aShapeTag);
552 anAttr = myStudyBuilder->FindOrCreateAttribute(aSubMeshesRoot,"AttributeName");
553 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
554 aName->SetValue(aSubMeshName.toUtf8().data());
556 anAttr = myStudyBuilder->FindOrCreateAttribute(aSubMeshesRoot,"AttributeSelectable");
557 SALOMEDS::AttributeSelectable_var aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
558 aSelAttr->SetSelectable(false);
559 aSelAttr->UnRegister();
561 aSubMeshesRoot->UnRegister();
562 aMeshSO->UnRegister();
564 SALOMEDS::SObject_var aSObject = myStudyBuilder->NewObject(aSubMeshesRoot);
565 anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeIOR");
566 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
567 anIOR->SetValue(theSubMeshIOR);
570 CORBA::String_var aString = aSObject->GetID();
571 aSObject->UnRegister();
573 return aString._retn();
579 const char* SMESH_Swig::AddSubMeshOnShape(const char* theMeshEntry,
580 const char* theGeomShapeEntry,
581 const char* theSubMeshIOR,
584 SALOMEDS::SObject_var aGeomShapeSO = KERNEL::getStudyServant()->FindObjectID(theGeomShapeEntry);
585 if(!aGeomShapeSO->_is_nil())
587 const char * aSubMeshEntry = AddSubMesh(theMeshEntry,theSubMeshIOR,ShapeType);
588 SALOMEDS::SObject_var aSubMeshSO = KERNEL::getStudyServant()->FindObjectID(aSubMeshEntry);
589 if ( !aSubMeshSO->_is_nil()) {
590 SetShape( theGeomShapeEntry, aSubMeshEntry );
591 CORBA::String_var aString = aSubMeshSO->GetID();
592 aSubMeshSO->UnRegister();
593 return aString._retn();
595 aGeomShapeSO->UnRegister();
602 \brief Gets window with specified identifier
604 \param id window identifier
605 \return pointer on the window
608 SUIT_ViewWindow* getWnd( const int id )
610 SUIT_ViewWindow* resWnd = 0;
611 SUIT_Session* aSession = SUIT_Session::session();
612 SUIT_Application* anApplication = aSession->activeApplication();
613 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(anApplication);
615 ViewManagerList vmlist = app->viewManagers();
616 foreach( SUIT_ViewManager* vm, vmlist ) {
617 QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
618 foreach ( SUIT_ViewWindow* vw, vwlist ) {
619 if ( id == vw->getId() ) {
629 class TGetActorAspect: public SALOME_Event
632 typedef actorAspect TResult;
636 TGetActorAspect( const char* Mesh_Entry, int viewId )
641 virtual void Execute()
643 SMESH_Actor* anActor;
646 SUIT_ViewWindow* w = getWnd(_wid);
647 anActor = SMESH::FindActorByEntry( w, _entry );
650 anActor = SMESH::FindActorByEntry( _entry );
653 MESSAGE("GetActorAspect: no actor corresponding to: " << _entry);
656 anActor->GetSufaceColor(myResult.surfaceColor.r,
657 myResult.surfaceColor.g,
658 myResult.surfaceColor.b,
659 myResult.surfaceColor.delta);
660 anActor->GetVolumeColor(myResult.volumeColor.r,
661 myResult.volumeColor.g,
662 myResult.volumeColor.b,
663 myResult.volumeColor.delta);
664 anActor->GetEdgeColor(myResult.edgeColor.r,
665 myResult.edgeColor.g,
666 myResult.edgeColor.b);
667 anActor->GetNodeColor(myResult.nodeColor.r,
668 myResult.nodeColor.g,
669 myResult.nodeColor.b);
670 myResult.opacity= anActor->GetOpacity();
671 MESSAGE("opacity: " << myResult.opacity);
675 actorAspect SMESH_Swig::GetActorAspect( const char* Mesh_Entry, int viewId )
677 return ProcessEvent(new TGetActorAspect( Mesh_Entry, viewId));
680 void SMESH_Swig::SetActorAspect( const actorAspect& actorPres, const char* Mesh_Entry, int viewId )
682 class TSetActorAspect: public SALOME_Event
686 actorAspect _actorPres;
688 TSetActorAspect(const actorAspect& actorPres, const char* Mesh_Entry, int viewId )
691 _actorPres = actorPres;
694 virtual void Execute()
696 SMESH_Actor* anActor;
699 SUIT_ViewWindow* w = getWnd(_wid);
700 anActor = SMESH::FindActorByEntry( w, _entry );
703 anActor = SMESH::FindActorByEntry( _entry );
706 MESSAGE("SetActorAspect: no actor corresponding to: " << _entry);
709 anActor->SetSufaceColor(_actorPres.surfaceColor.r,
710 _actorPres.surfaceColor.g,
711 _actorPres.surfaceColor.b,
712 _actorPres.surfaceColor.delta);
713 anActor->SetVolumeColor(_actorPres.volumeColor.r,
714 _actorPres.volumeColor.g,
715 _actorPres.volumeColor.b,
716 _actorPres.volumeColor.delta);
717 anActor->SetEdgeColor(_actorPres.edgeColor.r,
718 _actorPres.edgeColor.g,
719 _actorPres.edgeColor.b);
720 anActor->SetNodeColor(_actorPres.nodeColor.r,
721 _actorPres.nodeColor.g,
722 _actorPres.nodeColor.b);
723 anActor->SetOpacity(_actorPres.opacity);
726 SUIT_ViewWindow* w = getWnd(_wid);
731 SUIT_Session* aSession = SUIT_Session::session();
732 SUIT_Application* anApplication = aSession->activeApplication();
733 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
734 SUIT_ViewManager* vman = anApp->getViewManager(VTKViewer_Viewer::Type(),true);
735 vman->getActiveView()->repaint();
740 ProcessVoidEvent(new TSetActorAspect(actorPres, Mesh_Entry, viewId));
743 void SMESH_Swig::CreateAndDisplayActor( const char* Mesh_Entry )
745 // SMESH_Actor* Mesh = smeshGUI->ReadScript(aM);
746 class TEvent: public SALOME_Event
751 TEvent(const char* Mesh_Entry) {
754 virtual void Execute() {
755 //SMESH::UpdateView(SMESH::eDisplay, _entry);
756 SUIT_Session* aSession = SUIT_Session::session();
757 SUIT_Application* anApplication = aSession->activeApplication();
758 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
759 /*SUIT_ViewManager* vman = */anApp->getViewManager(VTKViewer_Viewer::Type(),true);
760 SMESHGUI_Displayer* aDisp = new SMESHGUI_Displayer(anApp);
761 aDisp->Display(_entry,1);
765 ProcessVoidEvent(new TEvent(Mesh_Entry));
768 void SMESH_Swig::EraseActor( const char* Mesh_Entry, const bool allViewers )
770 class TEvent: public SALOME_Event
776 TEvent(const char* Mesh_Entry, const bool allViewers ) {
778 _allViewers = allViewers;
780 virtual void Execute() {
781 SUIT_Session* aSession = SUIT_Session::session();
782 SUIT_Application* anApplication = aSession->activeApplication();
783 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
784 SMESHGUI_Displayer* aDisp = new SMESHGUI_Displayer(anApp);
785 ViewManagerList aManagers;
786 if ( !_allViewers ) {
787 aManagers << anApp->activeViewManager();
790 aManagers = anApp->viewManagers();
792 foreach( SUIT_ViewManager* aMgr, aManagers ) {
793 if ( aMgr && aMgr->getType() == VTKViewer_Viewer::Type() ) {
794 SALOME_View* aSalomeView = dynamic_cast<SALOME_View*>(aMgr->getViewModel());
796 aDisp->Erase(_entry,true, true, aSalomeView);
803 ProcessVoidEvent(new TEvent(Mesh_Entry, allViewers));
806 void SMESH_Swig::UpdateActor( const char* Mesh_Entry ) {
807 class TEvent: public SALOME_Event
812 TEvent( const char* Mesh_Entry ) {
815 virtual void Execute() {
816 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
817 ( _entry, "SMESH", "" );
818 SMESH::Update( anIO, true );
822 ProcessVoidEvent( new TEvent(Mesh_Entry) );
825 void SMESH_Swig::SetName(const char* theEntry,
828 SALOMEDS::SObject_var aSObject = KERNEL::getStudyServant()->FindObjectID(theEntry);
829 SALOMEDS::GenericAttribute_var anAttr;
830 SALOMEDS::AttributeName_var aName;
831 if(!aSObject->_is_nil()){
832 anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeName");
833 aName = SALOMEDS::AttributeName::_narrow(anAttr);
834 aName->SetValue(theName);
836 aSObject->UnRegister();
840 //================================================================================
842 * \brief Set mesh icon according to compute status
843 * \param Mesh_Entry - entry of a mesh
844 * \param isComputed - is mesh computed or not
846 //================================================================================
848 void SMESH_Swig::SetMeshIcon(const char* theMeshEntry,
849 const bool theIsComputed,
852 class TEvent: public SALOME_Event
854 std::string myMeshEntry;
855 bool myIsComputed, myIsEmpty;
857 TEvent(const std::string& theMeshEntry,
858 const bool theIsComputed,
860 myMeshEntry (theMeshEntry),
861 myIsComputed(theIsComputed),
869 SALOMEDS::SObject_ptr aMeshSO = KERNEL::getStudyServant()->FindObjectID(myMeshEntry.c_str());
870 if(_PTR(SObject) aMesh = ClientFactory::SObject(aMeshSO))
871 SMESH::ModifiedMesh(aMesh,myIsComputed,myIsEmpty);
872 // aMeshSO->UnRegister(); ~aMesh() already called UnRegister()!
876 ProcessVoidEvent(new TEvent(theMeshEntry,
882 \brief Helper class for selection event.
884 class TSelectListEvent: public SALOME_Event
887 std::vector<int> myIdsList;
891 TSelectListEvent(const char* id, std::vector<int> ids, bool append) :
896 virtual void Execute()
899 LightApp_SelectionMgr* selMgr = 0;
900 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
902 selMgr = dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
907 selMgr->clearFilters();
909 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
913 SMESH_Actor* anActor = SMESH::FindActorByEntry( myId );
915 if (!anActor || !anActor->hasIO())
918 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
921 selMgr->setSelectedObjects(aList, false);
923 if ( aViewWindow->SelectionMode() == ActorSelection ) {
927 TColStd_MapOfInteger aMap;
928 std::vector<int>::const_iterator anIter;
929 for (anIter = myIdsList.begin(); anIter != myIdsList.end(); ++anIter) {
934 SVTK_Selector* aSelector = aViewWindow->GetSelector();
935 aSelector->AddOrRemoveIndex(anIO, aMap, myIsAppend);
936 aViewWindow->highlight( anIO, true, true );
937 aViewWindow->GetInteractor()->onEmitSelectionChanged();
942 \brief Select the elements on the mesh, sub-mesh or group.
943 \param id object entry
944 \param ids list of the element ids
945 \param mode selection mode
947 void SMESH_Swig::select( const char* id, std::vector<int> ids, bool append ) {
948 ProcessVoidEvent( new TSelectListEvent( id, ids, append ) );
952 \brief Select the elements on the mesh, sub-mesh or group.
953 \param id object entry
954 \param id id of the element
955 \param mode selection mode
957 void SMESH_Swig::select( const char* id, int id1, bool append ) {
958 std::vector<int> ids;
959 ids.push_back( id1 );
960 ProcessVoidEvent( new TSelectListEvent( id, ids, append ) );
964 \brief Helper class for selection edges of cell event
966 class TSelectListOfPairEvent: public SALOME_Event
969 std::vector<std::pair<int, int> > myIdsList;
973 TSelectListOfPairEvent(const char* id, std::vector<std::pair<int, int> > ids, bool append) :
978 virtual void Execute()
981 LightApp_SelectionMgr* selMgr = 0;
982 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
984 selMgr = dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
989 selMgr->clearFilters();
991 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
995 SMESH_Actor* anActor = SMESH::FindActorByEntry( myId );
997 if (!anActor || !anActor->hasIO())
1000 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
1001 SALOME_ListIO aList;
1003 selMgr->setSelectedObjects(aList, false);
1005 if ( aViewWindow->SelectionMode() != EdgeOfCellSelection ) {
1009 SVTK_IndexedMapOfIds aMap;
1010 std::vector<std::pair<int, int> >::const_iterator anIter;
1011 for (anIter = myIdsList.begin(); anIter != myIdsList.end(); ++anIter) {
1012 std::vector<int> aCompositeId;
1013 aCompositeId.push_back((*anIter).first);
1014 aCompositeId.push_back((*anIter).second);
1015 aMap.Add(aCompositeId);
1018 // Set new selection
1019 SVTK_Selector* aSelector = aViewWindow->GetSelector();
1020 aSelector->AddOrRemoveCompositeIndex(anIO, aMap, myIsAppend);
1021 aViewWindow->highlight( anIO, true, true );
1022 aViewWindow->GetInteractor()->onEmitSelectionChanged();
1027 \brief Select the elements on the mesh, sub-mesh or group.
1028 \param id object entry
1029 \param ids list of the element ids
1030 \param mode selection mode
1032 void SMESH_Swig::select( const char* id, std::vector<std::pair<int,int> > ids, bool append ) {
1033 ProcessVoidEvent( new TSelectListOfPairEvent( id, ids, append ) );
1036 class TGetSelectionModeEvent : public SALOME_Event
1039 typedef SelectionMode TResult;
1041 TGetSelectionModeEvent() : myResult( Undefined ) {}
1042 virtual void Execute()
1044 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( );
1048 myResult = (SelectionMode) aViewWindow->SelectionMode();
1053 \brief Get selection mode of the active VTK View window.
1055 SelectionMode SMESH_Swig::getSelectionMode() {
1056 return ProcessEvent( new TGetSelectionModeEvent() );
1061 * Event to set selection mode
1063 class TSetSelectionModeEvent : public SALOME_Event
1065 SelectionMode mySelectionMode;
1069 TSetSelectionModeEvent(const SelectionMode selectionMode) :
1070 mySelectionMode(selectionMode)
1073 virtual void Execute()
1075 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
1079 Selection_Mode prevMode = aViewWindow->SelectionMode();
1080 bool changePointRepresentation = ( prevMode == NodeSelection && mySelectionMode != Node ) ||
1081 (prevMode != NodeSelection && mySelectionMode == Node);
1083 if( changePointRepresentation ) {
1084 vtkRenderer *aRenderer = aViewWindow->getRenderer();
1085 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1086 vtkActorCollection *aCollection = aCopy.GetActors();
1087 aCollection->InitTraversal();
1088 while(vtkActor *anAct = aCollection->GetNextActor()){
1089 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
1090 if(anActor->GetVisibility()){
1091 anActor->SetPointRepresentation(mySelectionMode == Node);
1096 aViewWindow->SetSelectionMode(mySelectionMode);
1100 void SMESH_Swig::setSelectionMode(SelectionMode selectionMode){
1101 ProcessVoidEvent( new TSetSelectionModeEvent( selectionMode ) );
1104 class TGetSelectedEvent : public SALOME_Event
1107 typedef std::vector<int> TResult;
1111 TGetSelectedEvent( const char* id) :
1112 myResult( std::vector<int>() ),
1116 virtual void Execute()
1118 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
1122 SVTK_Selector* aSelector = aViewWindow->GetSelector();
1126 SMESH_Actor* anActor = SMESH::FindActorByEntry( myId );
1128 if ( !anActor || !anActor->hasIO() )
1131 TColStd_IndexedMapOfInteger aMapIndex;
1132 aSelector->GetIndex(anActor->getIO(),aMapIndex);
1134 for( int i = 1; i <= aMapIndex.Extent(); i++ )
1135 myResult.push_back( aMapIndex( i ) );
1139 std::vector<int> SMESH_Swig::getSelected( const char* Mesh_Entry ) {
1140 return ProcessEvent( new TGetSelectedEvent(Mesh_Entry) );
1143 class TGetSelectedPairEvent : public SALOME_Event
1146 typedef std::vector<std::pair<int, int> > TResult;
1150 TGetSelectedPairEvent( const char* id) :
1151 myResult( std::vector<std::pair<int,int> >() ),
1155 virtual void Execute()
1157 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
1161 if(aViewWindow->SelectionMode() != EdgeOfCellSelection )
1164 SVTK_Selector* aSelector = aViewWindow->GetSelector();
1168 SMESH_Actor* anActor = SMESH::FindActorByEntry( myId );
1170 if ( !anActor || !anActor->hasIO() )
1173 SVTK_IndexedMapOfIds aMapIndex;
1174 aSelector->GetCompositeIndex(anActor->getIO(),aMapIndex);
1176 for( int i = 1; i <= aMapIndex.Extent(); i++ )
1177 myResult.push_back( std::make_pair<int,int>( (int)aMapIndex( i )[0], (int)aMapIndex( i )[1]) );
1181 std::vector<std::pair<int,int> > SMESH_Swig::getSelectedEdgeOfCell( const char* Mesh_Entry ) {
1182 return ProcessEvent( new TGetSelectedPairEvent(Mesh_Entry) );