1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // SMESH SMESH : GUI for SMESH component
21 // File : libSMESH_Swig.cxx
22 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
25 #include "libSMESH_Swig.h"
29 #include <SMESHGUI_Utils.h>
30 #include <SMESHGUI_Displayer.h>
31 #include <SMESHGUI_VTKUtils.h>
32 #include <SMESH_Actor.h>
34 // SALOME KERNEL includes
35 #include <Utils_ORB_INIT.hxx>
36 #include <Utils_SINGLETON.hxx>
37 #include <SALOMEDSClient_ClientFactory.hxx>
39 #include <utilities.h>
41 // SALOME GUI includes
42 #include <SUIT_Session.h>
43 #include <SUIT_ViewManager.h>
44 #include <SALOME_Prs.h>
45 #include <SUIT_ViewWindow.h>
46 #include <SVTK_ViewWindow.h>
47 #include <VTKViewer_ViewModel.h>
48 #include <SALOME_Event.h>
49 #include <SalomeApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
51 #include <SVTK_RenderWindowInteractor.h>
52 #include <VTKViewer_Algorithm.h>
56 #include <TColStd_MapOfInteger.hxx>
59 #include <QApplication>
62 #include <SALOMEconfig.h>
63 #include CORBA_SERVER_HEADER(SMESH_Gen)
64 #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
67 #include <vtkActorCollection.h>
68 #include <vtkRenderer.h>
70 static CORBA::ORB_var anORB;
74 //---------------------------------------------------------------
77 StringToObject(const std::string& theIOR)
79 return anORB->string_to_object(theIOR.c_str());
83 //---------------------------------------------------------------
86 GetDomainRoot(const SALOMEDS::SComponent_var& theSComponentMesh,
87 const SALOMEDS::StudyBuilder_var& theStudyBuilder,
88 CORBA::Long theDomainRootTag,
89 const QString& theName,
90 const QString& thePixmap)
92 SALOMEDS::SObject_var aDomainRoot;
93 if (!theSComponentMesh->FindSubObject(theDomainRootTag,aDomainRoot)) {
94 aDomainRoot = theStudyBuilder->NewObjectToTag(theSComponentMesh,theDomainRootTag);
95 SALOMEDS::GenericAttribute_var anAttr = theStudyBuilder->FindOrCreateAttribute(aDomainRoot,"AttributeName");
96 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
97 aName->SetValue(theName.toLatin1().data());
99 anAttr = theStudyBuilder->FindOrCreateAttribute(aDomainRoot,"AttributePixMap");
100 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
101 aPixmap->SetPixMap(thePixmap.toLatin1().data());
102 aPixmap->UnRegister();
103 anAttr = theStudyBuilder->FindOrCreateAttribute(aDomainRoot,"AttributeSelectable");
104 SALOMEDS::AttributeSelectable_var aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
105 aSelAttr->SetSelectable(false);
106 aSelAttr->UnRegister();
113 //---------------------------------------------------------------
115 SALOMEDS::SObject_var
116 GetHypothesisRoot(const SALOMEDS::SComponent_var& theSComponentMesh,
117 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
119 return GetDomainRoot(theSComponentMesh,
121 SMESH::Tag_HypothesisRoot,
122 QObject::tr("SMESH_MEN_HYPOTHESIS"),
123 "ICON_SMESH_TREE_HYPO");
127 //---------------------------------------------------------------
129 SALOMEDS::SObject_var
130 GetAlgorithmsRoot(const SALOMEDS::SComponent_var& theSComponentMesh,
131 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
133 return GetDomainRoot(theSComponentMesh,
135 SMESH::Tag_AlgorithmsRoot,
136 QObject::tr("SMESH_MEN_ALGORITHMS"),
137 "ICON_SMESH_TREE_ALGO");
141 //---------------------------------------------------------------
143 SALOMEDS::SObject_var
144 AddToDomain(const std::string& theIOR,
145 const SALOMEDS::SComponent_var& theSComponentMesh,
146 const SALOMEDS::StudyBuilder_var& theStudyBuilder,
147 CORBA::Long theDomainRootTag,
148 const QString& theDomainName,
149 const QString& theDomainPixmap)
151 SALOMEDS::SObject_var aDomain = GetDomainRoot(theSComponentMesh,
153 SMESH::Tag_AlgorithmsRoot,
156 // Add New Hypothesis
157 SALOMEDS::SObject_var aSObject = theStudyBuilder->NewObject(aDomain);
158 aDomain->UnRegister();
159 SALOMEDS::GenericAttribute_var anAttr = theStudyBuilder->FindOrCreateAttribute(aSObject,"AttributePixMap");
160 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
161 CORBA::Object_var anObject = StringToObject(theIOR);
162 SMESH::SMESH_Hypothesis_var aDomainItem = SMESH::SMESH_Hypothesis::_narrow(anObject.in());
163 CORBA::String_var aType = aDomainItem->GetName();
164 QString aPixmapName = theDomainPixmap + "_" + aType.in();
165 aPixmap->SetPixMap(aPixmapName.toLatin1().data());
166 aPixmap->UnRegister();
167 anAttr = theStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeIOR");
168 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
169 anIOR->SetValue(theIOR.c_str());
176 //---------------------------------------------------------------
177 SALOMEDS::SObject_var
178 AddHypothesis(const std::string& theIOR,
179 const SALOMEDS::SComponent_var& theSComponentMesh,
180 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
182 return AddToDomain(theIOR,
185 SMESH::Tag_HypothesisRoot,
186 QObject::tr("SMESH_MEN_HYPOTHESIS"),
187 "ICON_SMESH_TREE_HYPO");
191 //---------------------------------------------------------------
192 SALOMEDS::SObject_var
193 AddAlgorithms(const std::string& theIOR,
194 const SALOMEDS::SComponent_var& theSComponentMesh,
195 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
197 return AddToDomain(theIOR,
200 SMESH::Tag_AlgorithmsRoot,
201 QObject::tr("SMESH_MEN_ALGORITHMS"),
202 "ICON_SMESH_TREE_ALGO");
206 //---------------------------------------------------------------
208 SetDomain(const char* theMeshOrSubMeshEntry,
209 const char* theDomainEntry,
210 const SALOMEDS::Study_var& theStudy,
211 const SALOMEDS::StudyBuilder_var& theStudyBuilder,
212 long theRefOnAppliedDomainTag,
213 const QString& theAppliedDomainMEN,
214 const QString& theAppliedDomainICON)
216 SALOMEDS::SObject_var aMeshOrSubMeshSO = theStudy->FindObjectID(theMeshOrSubMeshEntry);
217 SALOMEDS::SObject_var aHypothesisSO = theStudy->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::Study_var& theStudy,
254 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
256 SetDomain(theMeshOrSubMeshEntry,
260 SMESH::Tag_RefOnAppliedHypothesis,
261 QObject::tr("SMESH_MEN_APPLIED_HYPOTHESIS"),
262 "ICON_SMESH_TREE_HYPO");
266 //---------------------------------------------------------------
268 SetAlgorithms(const char* theMeshOrSubMeshEntry,
269 const char* theDomainEntry,
270 const SALOMEDS::Study_var& theStudy,
271 const SALOMEDS::StudyBuilder_var& theStudyBuilder)
273 SetDomain(theMeshOrSubMeshEntry,
277 SMESH::Tag_RefOnAppliedAlgorithms,
278 QObject::tr("SMESH_MEN_APPLIED_ALGORIHTMS"),
279 "ICON_SMESH_TREE_ALGO");
284 //===============================================================
285 SMESH_Swig::SMESH_Swig()
287 class TEvent: public SALOME_Event
289 CORBA::ORB_var& myORB;
292 TEvent(CORBA::ORB_var& theORB):
301 ORB_INIT &anORBInit = *SINGLETON_<ORB_INIT>::Instance();
302 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
303 myORB = anORBInit( 0, 0 );
305 INFOS("internal error : orb not found");
310 //MESSAGE("Constructeur");
312 if(CORBA::is_nil(anORB))
313 ProcessVoidEvent(new TEvent(anORB));
315 ASSERT(!CORBA::is_nil(anORB));
319 //===============================================================
321 SMESH_Swig::Init(int theStudyID)
323 class TEvent: public SALOME_Event
326 SALOMEDS::Study_var& myStudy;
327 SALOMEDS::StudyBuilder_var& myStudyBuilder;
328 SALOMEDS::SComponent_var& mySComponentMesh;
330 TEvent(int theStudyID,
331 SALOMEDS::Study_var& theStudy,
332 SALOMEDS::StudyBuilder_var& theStudyBuilder,
333 SALOMEDS::SComponent_var& theSComponentMesh):
334 myStudyID (theStudyID),
336 myStudyBuilder (theStudyBuilder),
337 mySComponentMesh(theSComponentMesh)
342 if ( !mySComponentMesh->_is_nil() ) mySComponentMesh->UnRegister();
349 SUIT_Session* aSession = SUIT_Session::session();
350 SUIT_Application* anApplication = aSession->activeApplication();
351 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
353 SALOME_NamingService* aNamingService = anApp->namingService();
354 CORBA::Object_var anObject = aNamingService->Resolve("/myStudyManager");
355 SALOMEDS::StudyManager_var aStudyMgr = SALOMEDS::StudyManager::_narrow(anObject);
356 myStudy = aStudyMgr->GetStudyByID(myStudyID);
358 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
359 aSMESHGen->SetCurrentStudy( myStudy.in() );
361 myStudyBuilder = myStudy->NewBuilder();
363 SALOMEDS::GenericAttribute_var anAttr;
364 SALOMEDS::AttributeName_var aName;
365 SALOMEDS::AttributePixMap_var aPixmap;
367 SALOMEDS::SComponent_var aSComponent = myStudy->FindComponent("SMESH");
368 if ( aSComponent->_is_nil() )
370 bool aLocked = myStudy->GetProperties()->IsLocked();
372 myStudy->GetProperties()->SetLocked(false);
374 SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
375 //SRN: BugID IPAL9186, load a SMESH gui if it hasn't been loaded
377 CAM_Module* aModule = anApp->module("Mesh");
379 aModule = anApp->loadModule("Mesh");
380 aSMESHGUI = dynamic_cast<SMESHGUI*>(aModule);
381 } //SRN: BugID IPAL9186: end of a fix
383 aSComponent = myStudyBuilder->NewComponent("SMESH");
385 anAttr = myStudyBuilder->FindOrCreateAttribute(aSComponent,"AttributeName");
386 aName = SALOMEDS::AttributeName::_narrow(anAttr);
387 aName->SetValue(aSMESHGUI->moduleName().toLatin1().data());
390 anAttr = myStudyBuilder->FindOrCreateAttribute(aSComponent,"AttributePixMap");
391 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
392 aPixmap->SetPixMap( "ICON_OBJBROWSER_SMESH" );
393 aPixmap->UnRegister();
395 SALOMEDS::UseCaseBuilder_var useCaseBuilder = myStudy->GetUseCaseBuilder();
396 useCaseBuilder->SetRootCurrent();
397 useCaseBuilder->Append( aSComponent.in() );
399 myStudyBuilder->DefineComponentInstance(aSComponent,aSMESHGen);
401 myStudy->GetProperties()->SetLocked(true);
404 mySComponentMesh = SALOMEDS::SComponent::_narrow(aSComponent);
406 qApp->processEvents(); // Workaround for bug 12662
412 ProcessVoidEvent(new TEvent(theStudyID,
419 //===============================================================
420 SMESH_Swig::~SMESH_Swig()
422 //MESSAGE("Destructeur");
426 //===============================================================
427 const char* SMESH_Swig::AddNewMesh(const char* theIOR)
430 // VSR: added temporarily - to be removed - objects are published automatically by engine
431 SALOMEDS::SObject_var aSObject = myStudy->FindObjectIOR(theIOR);
432 if (aSObject->_is_nil())
434 //Find or Create Hypothesis root
435 SALOMEDS::SObject_var hroot = GetHypothesisRoot(mySComponentMesh,myStudyBuilder);
436 SALOMEDS::SObject_var aroot = GetAlgorithmsRoot(mySComponentMesh,myStudyBuilder);
441 aSObject = myStudyBuilder->NewObject(mySComponentMesh);
442 SALOMEDS::GenericAttribute_var anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributePixMap");
443 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
444 aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH" );
445 aPixmap->UnRegister();
447 anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeIOR");
448 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
449 anIOR->SetValue(theIOR);
453 CORBA::String_var anEntry = aSObject->GetID();
454 aSObject->UnRegister();
456 return anEntry._retn();
460 //===============================================================
461 const char* SMESH_Swig::AddNewHypothesis(const char* theIOR)
463 SALOMEDS::SObject_var aSObject = ::AddHypothesis(theIOR,
466 CORBA::String_var anEntry = aSObject->GetID();
467 aSObject->UnRegister();
469 return anEntry._retn();
473 //===============================================================
474 const char* SMESH_Swig::AddNewAlgorithms(const char* theIOR)
476 SALOMEDS::SObject_var aSObject = ::AddAlgorithms(theIOR,
479 CORBA::String_var anEntry = aSObject->GetID();
480 aSObject->UnRegister();
482 return anEntry._retn();
486 //===============================================================
487 void SMESH_Swig::SetShape(const char* theShapeEntry,
488 const char* theMeshEntry)
490 SALOMEDS::SObject_var aGeomShapeSO = myStudy->FindObjectID( theShapeEntry );
491 SALOMEDS::SObject_var aMeshSO = myStudy->FindObjectID( theMeshEntry );
493 if(!aMeshSO->_is_nil() && !aGeomShapeSO->_is_nil()){
494 SALOMEDS::SObject_var aSObject = myStudyBuilder->NewObjectToTag(aMeshSO, SMESH::Tag_RefOnShape);
495 myStudyBuilder->Addreference(aSObject,aGeomShapeSO);
496 aSObject->UnRegister();
498 if ( !aMeshSO->_is_nil() ) aMeshSO->UnRegister();
499 if ( !aGeomShapeSO->_is_nil() ) aGeomShapeSO->UnRegister();
503 //===============================================================
504 void SMESH_Swig::SetHypothesis(const char* theMeshOrSubMeshEntry,
505 const char* theDomainEntry)
507 ::SetHypothesis(theMeshOrSubMeshEntry,
514 //===============================================================
515 void SMESH_Swig::SetAlgorithms(const char* theMeshOrSubMeshEntry,
516 const char* theDomainEntry)
518 ::SetAlgorithms(theMeshOrSubMeshEntry,
525 //===============================================================
527 SMESH_Swig::UnSetHypothesis(const char* theDomainEntry)
529 SALOMEDS::SObject_var aDomainSO = myStudy->FindObjectID(theDomainEntry);
530 if(!aDomainSO->_is_nil())
531 myStudyBuilder->RemoveObject(aDomainSO);
534 const char* SMESH_Swig::AddSubMesh(const char* theMeshEntry,
535 const char* theSubMeshIOR,
538 SALOMEDS::SObject_var aMeshSO = myStudy->FindObjectID(theMeshEntry);
539 if(!aMeshSO->_is_nil()) {
541 QString aSubMeshName;
542 switch(theShapeType) {
544 aShapeTag = SMESH::Tag_SubMeshOnSolid;
545 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnSolid");
548 aShapeTag = SMESH::Tag_SubMeshOnFace;
549 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnFace");
552 aShapeTag = SMESH::Tag_SubMeshOnEdge;
553 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnEdge");
556 aShapeTag = SMESH::Tag_SubMeshOnVertex;
557 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnVertex");
560 aShapeTag = SMESH::Tag_SubMeshOnCompound;
561 aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnCompound");
564 SALOMEDS::GenericAttribute_var anAttr;
565 SALOMEDS::SObject_var aSubMeshesRoot;
566 if ( !aMeshSO->FindSubObject( aShapeTag, aSubMeshesRoot ) )
568 aSubMeshesRoot = myStudyBuilder->NewObjectToTag(aMeshSO,aShapeTag);
569 anAttr = myStudyBuilder->FindOrCreateAttribute(aSubMeshesRoot,"AttributeName");
570 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
571 aName->SetValue(aSubMeshName.toLatin1().data());
573 anAttr = myStudyBuilder->FindOrCreateAttribute(aSubMeshesRoot,"AttributeSelectable");
574 SALOMEDS::AttributeSelectable_var aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
575 aSelAttr->SetSelectable(false);
576 aSelAttr->UnRegister();
578 aSubMeshesRoot->UnRegister();
579 aMeshSO->UnRegister();
581 SALOMEDS::SObject_var aSObject = myStudyBuilder->NewObject(aSubMeshesRoot);
582 anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeIOR");
583 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
584 anIOR->SetValue(theSubMeshIOR);
587 CORBA::String_var aString = aSObject->GetID();
588 aSObject->UnRegister();
590 return aString._retn();
596 const char* SMESH_Swig::AddSubMeshOnShape(const char* theMeshEntry,
597 const char* theGeomShapeEntry,
598 const char* theSubMeshIOR,
601 SALOMEDS::SObject_var aGeomShapeSO = myStudy->FindObjectID(theGeomShapeEntry);
602 if(!aGeomShapeSO->_is_nil())
604 const char * aSubMeshEntry = AddSubMesh(theMeshEntry,theSubMeshIOR,ShapeType);
605 SALOMEDS::SObject_var aSubMeshSO = myStudy->FindObjectID(aSubMeshEntry);
606 if ( !aSubMeshSO->_is_nil()) {
607 SetShape( theGeomShapeEntry, aSubMeshEntry );
608 CORBA::String_var aString = aSubMeshSO->GetID();
609 aSubMeshSO->UnRegister();
610 return aString._retn();
612 aGeomShapeSO->UnRegister();
619 \brief Gets window with specified identifier
621 \param id window identifier
622 \return pointer on the window
625 SUIT_ViewWindow* getWnd( const int id )
627 SUIT_ViewWindow* resWnd = 0;
628 SUIT_Session* aSession = SUIT_Session::session();
629 SUIT_Application* anApplication = aSession->activeApplication();
630 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(anApplication);
632 ViewManagerList vmlist = app->viewManagers();
633 foreach( SUIT_ViewManager* vm, vmlist ) {
634 QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
635 foreach ( SUIT_ViewWindow* vw, vwlist ) {
636 if ( id == vw->getId() ) {
646 class TGetActorAspect: public SALOME_Event
649 typedef actorAspect TResult;
653 TGetActorAspect( const char* Mesh_Entry, int viewId )
658 virtual void Execute()
660 SMESH_Actor* anActor;
663 SUIT_ViewWindow* w = getWnd(_wid);
664 anActor = SMESH::FindActorByEntry( w, _entry );
667 anActor = SMESH::FindActorByEntry( _entry );
670 MESSAGE("GetActorAspect: no actor corresponding to: " << _entry);
673 anActor->GetSufaceColor(myResult.surfaceColor.r,
674 myResult.surfaceColor.g,
675 myResult.surfaceColor.b,
676 myResult.surfaceColor.delta);
677 anActor->GetVolumeColor(myResult.volumeColor.r,
678 myResult.volumeColor.g,
679 myResult.volumeColor.b,
680 myResult.volumeColor.delta);
681 anActor->GetEdgeColor(myResult.edgeColor.r,
682 myResult.edgeColor.g,
683 myResult.edgeColor.b);
684 anActor->GetNodeColor(myResult.nodeColor.r,
685 myResult.nodeColor.g,
686 myResult.nodeColor.b);
687 myResult.opacity= anActor->GetOpacity();
688 MESSAGE("opacity: " << myResult.opacity);
692 actorAspect SMESH_Swig::GetActorAspect( const char* Mesh_Entry, int viewId )
694 return ProcessEvent(new TGetActorAspect( Mesh_Entry, viewId));
697 void SMESH_Swig::SetActorAspect( const actorAspect& actorPres, const char* Mesh_Entry, int viewId )
699 class TSetActorAspect: public SALOME_Event
703 actorAspect _actorPres;
705 TSetActorAspect(const actorAspect& actorPres, const char* Mesh_Entry, int viewId )
708 _actorPres = actorPres;
711 virtual void Execute()
713 SMESH_Actor* anActor;
716 SUIT_ViewWindow* w = getWnd(_wid);
717 anActor = SMESH::FindActorByEntry( w, _entry );
720 anActor = SMESH::FindActorByEntry( _entry );
723 MESSAGE("SetActorAspect: no actor corresponding to: " << _entry);
726 anActor->SetSufaceColor(_actorPres.surfaceColor.r,
727 _actorPres.surfaceColor.g,
728 _actorPres.surfaceColor.b,
729 _actorPres.surfaceColor.delta);
730 anActor->SetVolumeColor(_actorPres.volumeColor.r,
731 _actorPres.volumeColor.g,
732 _actorPres.volumeColor.b,
733 _actorPres.volumeColor.delta);
734 anActor->SetEdgeColor(_actorPres.edgeColor.r,
735 _actorPres.edgeColor.g,
736 _actorPres.edgeColor.b);
737 anActor->SetNodeColor(_actorPres.nodeColor.r,
738 _actorPres.nodeColor.g,
739 _actorPres.nodeColor.b);
740 anActor->SetOpacity(_actorPres.opacity);
743 SUIT_ViewWindow* w = getWnd(_wid);
748 SUIT_Session* aSession = SUIT_Session::session();
749 SUIT_Application* anApplication = aSession->activeApplication();
750 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
751 SUIT_ViewManager* vman = anApp->getViewManager(VTKViewer_Viewer::Type(),true);
752 vman->getActiveView()->repaint();
757 ProcessVoidEvent(new TSetActorAspect(actorPres, Mesh_Entry, viewId));
760 void SMESH_Swig::CreateAndDisplayActor( const char* Mesh_Entry )
762 // SMESH_Actor* Mesh = smeshGUI->ReadScript(aM);
763 class TEvent: public SALOME_Event
768 TEvent(const char* Mesh_Entry) {
771 virtual void Execute() {
772 //SMESH::UpdateView(SMESH::eDisplay, _entry);
773 SUIT_Session* aSession = SUIT_Session::session();
774 SUIT_Application* anApplication = aSession->activeApplication();
775 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
776 /*SUIT_ViewManager* vman = */anApp->getViewManager(VTKViewer_Viewer::Type(),true);
777 SMESHGUI_Displayer* aDisp = new SMESHGUI_Displayer(anApp);
778 aDisp->Display(_entry,1);
782 ProcessVoidEvent(new TEvent(Mesh_Entry));
785 void SMESH_Swig::EraseActor( const char* Mesh_Entry, const bool allViewers )
787 class TEvent: public SALOME_Event
793 TEvent(const char* Mesh_Entry, const bool allViewers ) {
795 _allViewers = allViewers;
797 virtual void Execute() {
798 SUIT_Session* aSession = SUIT_Session::session();
799 SUIT_Application* anApplication = aSession->activeApplication();
800 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
801 SMESHGUI_Displayer* aDisp = new SMESHGUI_Displayer(anApp);
802 ViewManagerList aManagers;
803 if ( !_allViewers ) {
804 aManagers << anApp->activeViewManager();
807 aManagers = anApp->viewManagers();
809 foreach( SUIT_ViewManager* aMgr, aManagers ) {
810 if ( aMgr && aMgr->getType() == VTKViewer_Viewer::Type() ) {
811 SALOME_View* aSalomeView = dynamic_cast<SALOME_View*>(aMgr->getViewModel());
813 aDisp->Erase(_entry,true, true, aSalomeView);
820 ProcessVoidEvent(new TEvent(Mesh_Entry, allViewers));
823 void SMESH_Swig::SetName(const char* theEntry,
826 SALOMEDS::SObject_var aSObject = myStudy->FindObjectID(theEntry);
827 SALOMEDS::GenericAttribute_var anAttr;
828 SALOMEDS::AttributeName_var aName;
829 if(!aSObject->_is_nil()){
830 anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeName");
831 aName = SALOMEDS::AttributeName::_narrow(anAttr);
832 aName->SetValue(theName);
834 aSObject->UnRegister();
838 //================================================================================
840 * \brief Set mesh icon according to compute status
841 * \param Mesh_Entry - entry of a mesh
842 * \param isComputed - is mesh computed or not
844 //================================================================================
846 void SMESH_Swig::SetMeshIcon(const char* theMeshEntry,
847 const bool theIsComputed,
850 class TEvent: public SALOME_Event
852 SALOMEDS::Study_var myStudy;
853 std::string myMeshEntry;
854 bool myIsComputed, myIsEmpty;
856 TEvent(const SALOMEDS::Study_var& theStudy,
857 const std::string& theMeshEntry,
858 const bool theIsComputed,
861 myMeshEntry (theMeshEntry),
862 myIsComputed(theIsComputed),
870 SALOMEDS::SObject_ptr aMeshSO = myStudy->FindObjectID(myMeshEntry.c_str());
871 if(_PTR(SObject) aMesh = ClientFactory::SObject(aMeshSO))
872 SMESH::ModifiedMesh(aMesh,myIsComputed,myIsEmpty);
873 // aMeshSO->UnRegister(); ~aMesh() already called UnRegister()!
877 ProcessVoidEvent(new TEvent(myStudy,
884 \brief Helper class for selection event.
886 class TSelectListEvent: public SALOME_Event
889 std::vector<int> myIdsList;
893 TSelectListEvent(const char* id, std::vector<int> ids, bool append) :
898 virtual void Execute()
901 LightApp_SelectionMgr* selMgr = 0;
902 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
904 selMgr = dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
909 selMgr->clearFilters();
911 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
915 SMESH_Actor* anActor = SMESH::FindActorByEntry( myId );
917 if (!anActor || !anActor->hasIO())
920 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
923 selMgr->setSelectedObjects(aList, false);
925 if ( aViewWindow->SelectionMode() == ActorSelection ) {
929 TColStd_MapOfInteger aMap;
930 std::vector<int>::const_iterator anIter;
931 for (anIter = myIdsList.begin(); anIter != myIdsList.end(); ++anIter) {
936 SVTK_Selector* aSelector = aViewWindow->GetSelector();
937 aSelector->AddOrRemoveIndex(anIO, aMap, myIsAppend);
938 aViewWindow->highlight( anIO, true, true );
939 aViewWindow->GetInteractor()->onEmitSelectionChanged();
944 \brief Select the elements on the mesh, sub-mesh or group.
945 \param id object entry
946 \param ids list of the element ids
947 \param mode selection mode
949 void SMESH_Swig::select( const char* id, std::vector<int> ids, bool append ) {
950 ProcessVoidEvent( new TSelectListEvent( id, ids, append ) );
954 \brief Select the elements on the mesh, sub-mesh or group.
955 \param id object entry
956 \param id id of the element
957 \param mode selection mode
959 void SMESH_Swig::select( const char* id, int id1, bool append ) {
960 std::vector<int> ids;
961 ids.push_back( id1 );
962 ProcessVoidEvent( new TSelectListEvent( id, ids, append ) );
966 class TGetSelectionModeEvent : public SALOME_Event
969 typedef SelectionMode TResult;
971 TGetSelectionModeEvent() : myResult( Undefined ) {}
972 virtual void Execute()
974 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( );
978 myResult = (SelectionMode) aViewWindow->SelectionMode();
983 \brief Get selection mode of the active VTK View window.
985 SelectionMode SMESH_Swig::getSelectionMode() {
986 return ProcessEvent( new TGetSelectionModeEvent() );
991 * Event to set selection mode
993 class TSetSelectionModeEvent : public SALOME_Event
995 SelectionMode mySelectionMode;
999 TSetSelectionModeEvent(const SelectionMode selectionMode) :
1000 mySelectionMode(selectionMode)
1003 virtual void Execute()
1005 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
1009 Selection_Mode prevMode = aViewWindow->SelectionMode();
1010 bool changePointRepresentation = ( prevMode == NodeSelection && mySelectionMode != Node ) ||
1011 (prevMode != NodeSelection && mySelectionMode == Node);
1013 if( changePointRepresentation ) {
1014 vtkRenderer *aRenderer = aViewWindow->getRenderer();
1015 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1016 vtkActorCollection *aCollection = aCopy.GetActors();
1017 aCollection->InitTraversal();
1018 while(vtkActor *anAct = aCollection->GetNextActor()){
1019 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
1020 if(anActor->GetVisibility()){
1021 anActor->SetPointRepresentation(mySelectionMode == Node);
1026 aViewWindow->SetSelectionMode(mySelectionMode);
1030 void SMESH_Swig::setSelectionMode(SelectionMode selectionMode){
1031 ProcessVoidEvent( new TSetSelectionModeEvent( selectionMode ) );
1034 class TGetSelectedEvent : public SALOME_Event
1037 typedef std::vector<int> TResult;
1041 TGetSelectedEvent( const char* id) :
1042 myResult( std::vector<int>() ),
1046 virtual void Execute()
1048 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
1052 SVTK_Selector* aSelector = aViewWindow->GetSelector();
1056 SMESH_Actor* anActor = SMESH::FindActorByEntry( myId );
1058 if ( !anActor || !anActor->hasIO() )
1061 TColStd_IndexedMapOfInteger aMapIndex;
1062 aSelector->GetIndex(anActor->getIO(),aMapIndex);
1064 for( int i = 1; i <= aMapIndex.Extent(); i++ )
1065 myResult.push_back( aMapIndex( i ) );
1069 std::vector<int> SMESH_Swig::getSelected( const char* Mesh_Entry ) {
1070 return ProcessEvent( new TGetSelectedEvent(Mesh_Entry) );