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>
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::StudyBuilder_var& theStudyBuilder,
212 long theRefOnAppliedDomainTag,
213 const QString& theAppliedDomainMEN,
214 const QString& theAppliedDomainICON)
216 SALOMEDS::SObject_var aMeshOrSubMeshSO = KERNEL::getStudyServant()->FindObjectID(theMeshOrSubMeshEntry);
217 SALOMEDS::SObject_var aHypothesisSO = KERNEL::getStudyServant()->FindObjectID(theDomainEntry);
219 if(!aMeshOrSubMeshSO->_is_nil() && !aHypothesisSO->_is_nil()){
220 //Find or Create Applied Hypothesis root
221 SALOMEDS::SObject_var anAppliedDomainSO;
222 if( !aMeshOrSubMeshSO->FindSubObject( theRefOnAppliedDomainTag, anAppliedDomainSO ))
224 anAppliedDomainSO = theStudyBuilder->NewObjectToTag(aMeshOrSubMeshSO,theRefOnAppliedDomainTag);
225 SALOMEDS::GenericAttribute_var anAttr =
226 theStudyBuilder->FindOrCreateAttribute(anAppliedDomainSO,"AttributeName");
227 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
228 aName->SetValue(theAppliedDomainMEN.toLatin1().data());
230 anAttr = theStudyBuilder->FindOrCreateAttribute(anAppliedDomainSO,"AttributeSelectable");
231 SALOMEDS::AttributeSelectable_var aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
232 aSelAttr->SetSelectable(false);
233 aSelAttr->UnRegister();
234 anAttr = theStudyBuilder->FindOrCreateAttribute(anAppliedDomainSO,"AttributePixMap");
235 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
236 aPixmap->SetPixMap(theAppliedDomainICON.toLatin1().data());
237 aPixmap->UnRegister();
239 SALOMEDS::SObject_var aSObject = theStudyBuilder->NewObject(anAppliedDomainSO);
240 theStudyBuilder->Addreference(aSObject,aHypothesisSO);
241 aSObject->UnRegister();
242 anAppliedDomainSO->UnRegister();
244 if ( !aMeshOrSubMeshSO->_is_nil() ) aMeshOrSubMeshSO->UnRegister();
245 if ( !aHypothesisSO->_is_nil()) aHypothesisSO->UnRegister();
249 //---------------------------------------------------------------
251 SetHypothesis(const char* theMeshOrSubMeshEntry,
252 const char* theDomainEntry,
253 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
255 SetDomain(theMeshOrSubMeshEntry,
258 SMESH::Tag_RefOnAppliedHypothesis,
259 QObject::tr("SMESH_MEN_APPLIED_HYPOTHESIS"),
260 "ICON_SMESH_TREE_HYPO");
264 //---------------------------------------------------------------
266 SetAlgorithms(const char* theMeshOrSubMeshEntry,
267 const char* theDomainEntry,
268 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
270 SetDomain(theMeshOrSubMeshEntry,
273 SMESH::Tag_RefOnAppliedAlgorithms,
274 QObject::tr("SMESH_MEN_APPLIED_ALGORIHTMS"),
275 "ICON_SMESH_TREE_ALGO");
280 //===============================================================
281 SMESH_Swig::SMESH_Swig()
283 class TEvent: public SALOME_Event
285 CORBA::ORB_var& myORB;
288 TEvent(CORBA::ORB_var& theORB):
297 ORB_INIT &anORBInit = *SINGLETON_<ORB_INIT>::Instance();
298 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
299 myORB = anORBInit( 0, 0 );
301 INFOS("internal error : orb not found");
306 //MESSAGE("Constructeur");
308 if(CORBA::is_nil(anORB))
309 ProcessVoidEvent(new TEvent(anORB));
311 ASSERT(!CORBA::is_nil(anORB));
315 //===============================================================
319 class TEvent: public SALOME_Event
321 SALOMEDS::StudyBuilder_var& myStudyBuilder;
322 SALOMEDS::SComponent_var& mySComponentMesh;
324 TEvent(SALOMEDS::StudyBuilder_var& theStudyBuilder,
325 SALOMEDS::SComponent_var& theSComponentMesh):
326 myStudyBuilder (theStudyBuilder),
327 mySComponentMesh(theSComponentMesh)
332 if ( !mySComponentMesh->_is_nil() ) mySComponentMesh->UnRegister();
339 SUIT_Session* aSession = SUIT_Session::session();
340 SUIT_Application* anApplication = aSession->activeApplication();
341 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
343 SALOMEDS::Study_var aStudy = KERNEL::getStudyServant();
345 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
347 myStudyBuilder = aStudy->NewBuilder();
349 SALOMEDS::GenericAttribute_var anAttr;
350 SALOMEDS::AttributeName_var aName;
351 SALOMEDS::AttributePixMap_var aPixmap;
353 SALOMEDS::SComponent_var aSComponent = aStudy->FindComponent("SMESH");
354 if ( aSComponent->_is_nil() )
356 bool aLocked = aStudy->GetProperties()->IsLocked();
358 aStudy->GetProperties()->SetLocked(false);
360 SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
361 //SRN: BugID IPAL9186, load a SMESH gui if it hasn't been loaded
363 CAM_Module* aModule = anApp->module("Mesh");
365 aModule = anApp->loadModule("Mesh");
366 aSMESHGUI = dynamic_cast<SMESHGUI*>(aModule);
367 } //SRN: BugID IPAL9186: end of a fix
369 aSComponent = myStudyBuilder->NewComponent("SMESH");
371 anAttr = myStudyBuilder->FindOrCreateAttribute(aSComponent,"AttributeName");
372 aName = SALOMEDS::AttributeName::_narrow(anAttr);
373 aName->SetValue(aSMESHGUI->moduleName().toLatin1().data());
376 anAttr = myStudyBuilder->FindOrCreateAttribute(aSComponent,"AttributePixMap");
377 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
378 aPixmap->SetPixMap( "ICON_OBJBROWSER_SMESH" );
379 aPixmap->UnRegister();
381 SALOMEDS::UseCaseBuilder_var useCaseBuilder = KERNEL::getStudyServant()->GetUseCaseBuilder();
382 useCaseBuilder->SetRootCurrent();
383 useCaseBuilder->Append( aSComponent.in() );
385 myStudyBuilder->DefineComponentInstance(aSComponent,aSMESHGen);
387 KERNEL::getStudyServant()->GetProperties()->SetLocked(true);
390 mySComponentMesh = SALOMEDS::SComponent::_narrow(aSComponent);
392 qApp->processEvents(); // Workaround for bug 12662
398 ProcessVoidEvent(new TEvent(myStudyBuilder,
403 //===============================================================
404 SMESH_Swig::~SMESH_Swig()
406 //MESSAGE("Destructeur");
410 //===============================================================
411 const char* SMESH_Swig::AddNewMesh(const char* theIOR)
414 // VSR: added temporarily - to be removed - objects are published automatically by engine
415 SALOMEDS::SObject_var aSObject = KERNEL::getStudyServant()->FindObjectIOR(theIOR);
416 if (aSObject->_is_nil())
418 //Find or Create Hypothesis root
419 SALOMEDS::SObject_var hroot = GetHypothesisRoot(mySComponentMesh,myStudyBuilder);
420 SALOMEDS::SObject_var aroot = GetAlgorithmsRoot(mySComponentMesh,myStudyBuilder);
425 aSObject = myStudyBuilder->NewObject(mySComponentMesh);
426 SALOMEDS::GenericAttribute_var anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributePixMap");
427 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
428 aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH" );
429 aPixmap->UnRegister();
431 anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeIOR");
432 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
433 anIOR->SetValue(theIOR);
437 CORBA::String_var anEntry = aSObject->GetID();
438 aSObject->UnRegister();
440 return anEntry._retn();
444 //===============================================================
445 const char* SMESH_Swig::AddNewHypothesis(const char* theIOR)
447 SALOMEDS::SObject_var aSObject = ::AddHypothesis(theIOR,
450 CORBA::String_var anEntry = aSObject->GetID();
451 aSObject->UnRegister();
453 return anEntry._retn();
457 //===============================================================
458 const char* SMESH_Swig::AddNewAlgorithms(const char* theIOR)
460 SALOMEDS::SObject_var aSObject = ::AddAlgorithms(theIOR,
463 CORBA::String_var anEntry = aSObject->GetID();
464 aSObject->UnRegister();
466 return anEntry._retn();
470 //===============================================================
471 void SMESH_Swig::SetShape(const char* theShapeEntry,
472 const char* theMeshEntry)
474 SALOMEDS::SObject_var aGeomShapeSO = KERNEL::getStudyServant()->FindObjectID( theShapeEntry );
475 SALOMEDS::SObject_var aMeshSO = KERNEL::getStudyServant()->FindObjectID( theMeshEntry );
477 if(!aMeshSO->_is_nil() && !aGeomShapeSO->_is_nil()){
478 SALOMEDS::SObject_var aSObject = myStudyBuilder->NewObjectToTag(aMeshSO, SMESH::Tag_RefOnShape);
479 myStudyBuilder->Addreference(aSObject,aGeomShapeSO);
480 aSObject->UnRegister();
482 if ( !aMeshSO->_is_nil() ) aMeshSO->UnRegister();
483 if ( !aGeomShapeSO->_is_nil() ) aGeomShapeSO->UnRegister();
487 //===============================================================
488 void SMESH_Swig::SetHypothesis(const char* theMeshOrSubMeshEntry,
489 const char* theDomainEntry)
491 ::SetHypothesis(theMeshOrSubMeshEntry,
497 //===============================================================
498 void SMESH_Swig::SetAlgorithms(const char* theMeshOrSubMeshEntry,
499 const char* theDomainEntry)
501 ::SetAlgorithms(theMeshOrSubMeshEntry,
507 //===============================================================
509 SMESH_Swig::UnSetHypothesis(const char* theDomainEntry)
511 SALOMEDS::SObject_var aDomainSO = KERNEL::getStudyServant()->FindObjectID(theDomainEntry);
512 if(!aDomainSO->_is_nil())
513 myStudyBuilder->RemoveObject(aDomainSO);
516 const char* SMESH_Swig::AddSubMesh(const char* theMeshEntry,
517 const char* theSubMeshIOR,
520 SALOMEDS::SObject_var aMeshSO = KERNEL::getStudyServant()->FindObjectID(theMeshEntry);
521 if(!aMeshSO->_is_nil()) {
523 QString aSubMeshName;
524 switch(theShapeType) {
526 aShapeTag = SMESH::Tag_SubMeshOnSolid;
527 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnSolid");
530 aShapeTag = SMESH::Tag_SubMeshOnFace;
531 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnFace");
534 aShapeTag = SMESH::Tag_SubMeshOnEdge;
535 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnEdge");
538 aShapeTag = SMESH::Tag_SubMeshOnVertex;
539 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnVertex");
542 aShapeTag = SMESH::Tag_SubMeshOnCompound;
543 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnCompound");
546 SALOMEDS::GenericAttribute_var anAttr;
547 SALOMEDS::SObject_var aSubMeshesRoot;
548 if ( !aMeshSO->FindSubObject( aShapeTag, aSubMeshesRoot ) )
550 aSubMeshesRoot = myStudyBuilder->NewObjectToTag(aMeshSO,aShapeTag);
551 anAttr = myStudyBuilder->FindOrCreateAttribute(aSubMeshesRoot,"AttributeName");
552 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
553 aName->SetValue(aSubMeshName.toLatin1().data());
555 anAttr = myStudyBuilder->FindOrCreateAttribute(aSubMeshesRoot,"AttributeSelectable");
556 SALOMEDS::AttributeSelectable_var aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
557 aSelAttr->SetSelectable(false);
558 aSelAttr->UnRegister();
560 aSubMeshesRoot->UnRegister();
561 aMeshSO->UnRegister();
563 SALOMEDS::SObject_var aSObject = myStudyBuilder->NewObject(aSubMeshesRoot);
564 anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeIOR");
565 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
566 anIOR->SetValue(theSubMeshIOR);
569 CORBA::String_var aString = aSObject->GetID();
570 aSObject->UnRegister();
572 return aString._retn();
578 const char* SMESH_Swig::AddSubMeshOnShape(const char* theMeshEntry,
579 const char* theGeomShapeEntry,
580 const char* theSubMeshIOR,
583 SALOMEDS::SObject_var aGeomShapeSO = KERNEL::getStudyServant()->FindObjectID(theGeomShapeEntry);
584 if(!aGeomShapeSO->_is_nil())
586 const char * aSubMeshEntry = AddSubMesh(theMeshEntry,theSubMeshIOR,ShapeType);
587 SALOMEDS::SObject_var aSubMeshSO = KERNEL::getStudyServant()->FindObjectID(aSubMeshEntry);
588 if ( !aSubMeshSO->_is_nil()) {
589 SetShape( theGeomShapeEntry, aSubMeshEntry );
590 CORBA::String_var aString = aSubMeshSO->GetID();
591 aSubMeshSO->UnRegister();
592 return aString._retn();
594 aGeomShapeSO->UnRegister();
601 \brief Gets window with specified identifier
603 \param id window identifier
604 \return pointer on the window
607 SUIT_ViewWindow* getWnd( const int id )
609 SUIT_ViewWindow* resWnd = 0;
610 SUIT_Session* aSession = SUIT_Session::session();
611 SUIT_Application* anApplication = aSession->activeApplication();
612 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(anApplication);
614 ViewManagerList vmlist = app->viewManagers();
615 foreach( SUIT_ViewManager* vm, vmlist ) {
616 QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
617 foreach ( SUIT_ViewWindow* vw, vwlist ) {
618 if ( id == vw->getId() ) {
628 class TGetActorAspect: public SALOME_Event
631 typedef actorAspect TResult;
635 TGetActorAspect( const char* Mesh_Entry, int viewId )
640 virtual void Execute()
642 SMESH_Actor* anActor;
645 SUIT_ViewWindow* w = getWnd(_wid);
646 anActor = SMESH::FindActorByEntry( w, _entry );
649 anActor = SMESH::FindActorByEntry( _entry );
652 MESSAGE("GetActorAspect: no actor corresponding to: " << _entry);
655 anActor->GetSufaceColor(myResult.surfaceColor.r,
656 myResult.surfaceColor.g,
657 myResult.surfaceColor.b,
658 myResult.surfaceColor.delta);
659 anActor->GetVolumeColor(myResult.volumeColor.r,
660 myResult.volumeColor.g,
661 myResult.volumeColor.b,
662 myResult.volumeColor.delta);
663 anActor->GetEdgeColor(myResult.edgeColor.r,
664 myResult.edgeColor.g,
665 myResult.edgeColor.b);
666 anActor->GetNodeColor(myResult.nodeColor.r,
667 myResult.nodeColor.g,
668 myResult.nodeColor.b);
669 myResult.opacity= anActor->GetOpacity();
670 MESSAGE("opacity: " << myResult.opacity);
674 actorAspect SMESH_Swig::GetActorAspect( const char* Mesh_Entry, int viewId )
676 return ProcessEvent(new TGetActorAspect( Mesh_Entry, viewId));
679 void SMESH_Swig::SetActorAspect( const actorAspect& actorPres, const char* Mesh_Entry, int viewId )
681 class TSetActorAspect: public SALOME_Event
685 actorAspect _actorPres;
687 TSetActorAspect(const actorAspect& actorPres, const char* Mesh_Entry, int viewId )
690 _actorPres = actorPres;
693 virtual void Execute()
695 SMESH_Actor* anActor;
698 SUIT_ViewWindow* w = getWnd(_wid);
699 anActor = SMESH::FindActorByEntry( w, _entry );
702 anActor = SMESH::FindActorByEntry( _entry );
705 MESSAGE("SetActorAspect: no actor corresponding to: " << _entry);
708 anActor->SetSufaceColor(_actorPres.surfaceColor.r,
709 _actorPres.surfaceColor.g,
710 _actorPres.surfaceColor.b,
711 _actorPres.surfaceColor.delta);
712 anActor->SetVolumeColor(_actorPres.volumeColor.r,
713 _actorPres.volumeColor.g,
714 _actorPres.volumeColor.b,
715 _actorPres.volumeColor.delta);
716 anActor->SetEdgeColor(_actorPres.edgeColor.r,
717 _actorPres.edgeColor.g,
718 _actorPres.edgeColor.b);
719 anActor->SetNodeColor(_actorPres.nodeColor.r,
720 _actorPres.nodeColor.g,
721 _actorPres.nodeColor.b);
722 anActor->SetOpacity(_actorPres.opacity);
725 SUIT_ViewWindow* w = getWnd(_wid);
730 SUIT_Session* aSession = SUIT_Session::session();
731 SUIT_Application* anApplication = aSession->activeApplication();
732 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
733 SUIT_ViewManager* vman = anApp->getViewManager(VTKViewer_Viewer::Type(),true);
734 vman->getActiveView()->repaint();
739 ProcessVoidEvent(new TSetActorAspect(actorPres, Mesh_Entry, viewId));
742 void SMESH_Swig::CreateAndDisplayActor( const char* Mesh_Entry )
744 // SMESH_Actor* Mesh = smeshGUI->ReadScript(aM);
745 class TEvent: public SALOME_Event
750 TEvent(const char* Mesh_Entry) {
753 virtual void Execute() {
754 //SMESH::UpdateView(SMESH::eDisplay, _entry);
755 SUIT_Session* aSession = SUIT_Session::session();
756 SUIT_Application* anApplication = aSession->activeApplication();
757 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
758 /*SUIT_ViewManager* vman = */anApp->getViewManager(VTKViewer_Viewer::Type(),true);
759 SMESHGUI_Displayer* aDisp = new SMESHGUI_Displayer(anApp);
760 aDisp->Display(_entry,1);
764 ProcessVoidEvent(new TEvent(Mesh_Entry));
767 void SMESH_Swig::EraseActor( const char* Mesh_Entry, const bool allViewers )
769 class TEvent: public SALOME_Event
775 TEvent(const char* Mesh_Entry, const bool allViewers ) {
777 _allViewers = allViewers;
779 virtual void Execute() {
780 SUIT_Session* aSession = SUIT_Session::session();
781 SUIT_Application* anApplication = aSession->activeApplication();
782 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
783 SMESHGUI_Displayer* aDisp = new SMESHGUI_Displayer(anApp);
784 ViewManagerList aManagers;
785 if ( !_allViewers ) {
786 aManagers << anApp->activeViewManager();
789 aManagers = anApp->viewManagers();
791 foreach( SUIT_ViewManager* aMgr, aManagers ) {
792 if ( aMgr && aMgr->getType() == VTKViewer_Viewer::Type() ) {
793 SALOME_View* aSalomeView = dynamic_cast<SALOME_View*>(aMgr->getViewModel());
795 aDisp->Erase(_entry,true, true, aSalomeView);
802 ProcessVoidEvent(new TEvent(Mesh_Entry, allViewers));
805 void SMESH_Swig::SetName(const char* theEntry,
808 SALOMEDS::SObject_var aSObject = KERNEL::getStudyServant()->FindObjectID(theEntry);
809 SALOMEDS::GenericAttribute_var anAttr;
810 SALOMEDS::AttributeName_var aName;
811 if(!aSObject->_is_nil()){
812 anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeName");
813 aName = SALOMEDS::AttributeName::_narrow(anAttr);
814 aName->SetValue(theName);
816 aSObject->UnRegister();
820 //================================================================================
822 * \brief Set mesh icon according to compute status
823 * \param Mesh_Entry - entry of a mesh
824 * \param isComputed - is mesh computed or not
826 //================================================================================
828 void SMESH_Swig::SetMeshIcon(const char* theMeshEntry,
829 const bool theIsComputed,
832 class TEvent: public SALOME_Event
834 std::string myMeshEntry;
835 bool myIsComputed, myIsEmpty;
837 TEvent(const std::string& theMeshEntry,
838 const bool theIsComputed,
840 myMeshEntry (theMeshEntry),
841 myIsComputed(theIsComputed),
849 SALOMEDS::SObject_ptr aMeshSO = KERNEL::getStudyServant()->FindObjectID(myMeshEntry.c_str());
850 if(_PTR(SObject) aMesh = ClientFactory::SObject(aMeshSO))
851 SMESH::ModifiedMesh(aMesh,myIsComputed,myIsEmpty);
852 // aMeshSO->UnRegister(); ~aMesh() already called UnRegister()!
856 ProcessVoidEvent(new TEvent(theMeshEntry,
862 \brief Helper class for selection event.
864 class TSelectListEvent: public SALOME_Event
867 std::vector<int> myIdsList;
871 TSelectListEvent(const char* id, std::vector<int> ids, bool append) :
876 virtual void Execute()
879 LightApp_SelectionMgr* selMgr = 0;
880 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
882 selMgr = dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
887 selMgr->clearFilters();
889 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
893 SMESH_Actor* anActor = SMESH::FindActorByEntry( myId );
895 if (!anActor || !anActor->hasIO())
898 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
901 selMgr->setSelectedObjects(aList, false);
903 if ( aViewWindow->SelectionMode() == ActorSelection ) {
907 TColStd_MapOfInteger aMap;
908 std::vector<int>::const_iterator anIter;
909 for (anIter = myIdsList.begin(); anIter != myIdsList.end(); ++anIter) {
914 SVTK_Selector* aSelector = aViewWindow->GetSelector();
915 aSelector->AddOrRemoveIndex(anIO, aMap, myIsAppend);
916 aViewWindow->highlight( anIO, true, true );
917 aViewWindow->GetInteractor()->onEmitSelectionChanged();
922 \brief Select the elements on the mesh, sub-mesh or group.
923 \param id object entry
924 \param ids list of the element ids
925 \param mode selection mode
927 void SMESH_Swig::select( const char* id, std::vector<int> ids, bool append ) {
928 ProcessVoidEvent( new TSelectListEvent( id, ids, append ) );
932 \brief Select the elements on the mesh, sub-mesh or group.
933 \param id object entry
934 \param id id of the element
935 \param mode selection mode
937 void SMESH_Swig::select( const char* id, int id1, bool append ) {
938 std::vector<int> ids;
939 ids.push_back( id1 );
940 ProcessVoidEvent( new TSelectListEvent( id, ids, append ) );
944 class TGetSelectionModeEvent : public SALOME_Event
947 typedef SelectionMode TResult;
949 TGetSelectionModeEvent() : myResult( Undefined ) {}
950 virtual void Execute()
952 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( );
956 myResult = (SelectionMode) aViewWindow->SelectionMode();
961 \brief Get selection mode of the active VTK View window.
963 SelectionMode SMESH_Swig::getSelectionMode() {
964 return ProcessEvent( new TGetSelectionModeEvent() );
969 * Event to set selection mode
971 class TSetSelectionModeEvent : public SALOME_Event
973 SelectionMode mySelectionMode;
977 TSetSelectionModeEvent(const SelectionMode selectionMode) :
978 mySelectionMode(selectionMode)
981 virtual void Execute()
983 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
987 Selection_Mode prevMode = aViewWindow->SelectionMode();
988 bool changePointRepresentation = ( prevMode == NodeSelection && mySelectionMode != Node ) ||
989 (prevMode != NodeSelection && mySelectionMode == Node);
991 if( changePointRepresentation ) {
992 vtkRenderer *aRenderer = aViewWindow->getRenderer();
993 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
994 vtkActorCollection *aCollection = aCopy.GetActors();
995 aCollection->InitTraversal();
996 while(vtkActor *anAct = aCollection->GetNextActor()){
997 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
998 if(anActor->GetVisibility()){
999 anActor->SetPointRepresentation(mySelectionMode == Node);
1004 aViewWindow->SetSelectionMode(mySelectionMode);
1008 void SMESH_Swig::setSelectionMode(SelectionMode selectionMode){
1009 ProcessVoidEvent( new TSetSelectionModeEvent( selectionMode ) );
1012 class TGetSelectedEvent : public SALOME_Event
1015 typedef std::vector<int> TResult;
1019 TGetSelectedEvent( const char* id) :
1020 myResult( std::vector<int>() ),
1024 virtual void Execute()
1026 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
1030 SVTK_Selector* aSelector = aViewWindow->GetSelector();
1034 SMESH_Actor* anActor = SMESH::FindActorByEntry( myId );
1036 if ( !anActor || !anActor->hasIO() )
1039 TColStd_IndexedMapOfInteger aMapIndex;
1040 aSelector->GetIndex(anActor->getIO(),aMapIndex);
1042 for( int i = 1; i <= aMapIndex.Extent(); i++ )
1043 myResult.push_back( aMapIndex( i ) );
1047 std::vector<int> SMESH_Swig::getSelected( const char* Mesh_Entry ) {
1048 return ProcessEvent( new TGetSelectedEvent(Mesh_Entry) );