1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : VisuGUI_Tools.cxx
25 // Author : Sergey Anikin
29 #include "VisuGUI_Tools.h"
31 #include "VISU_Gen_i.hh"
32 #include "VISU_Prs3d_i.hh"
33 #include "VISU_Result_i.hh"
34 #include "VISU_Table_i.hh"
35 #include "VISU_Mesh_i.hh"
36 #include "VISU_ViewManager_i.hh"
38 #include "VISU_Actor.h"
40 #include "SalomeApp_Module.h"
41 #include "SalomeApp_Study.h"
42 #include "SalomeApp_Application.h"
43 #include "SalomeApp_SelectionMgr.h"
45 #include "SALOME_ListIO.hxx"
46 #include "SALOME_ListIteratorOfListIO.hxx"
48 #include "SVTK_ViewWindow.h"
49 #include "SVTK_ViewModel.h"
50 #include "SVTK_Functor.h"
52 #include "VTKViewer_Algorithm.h"
54 #include "SPlot2d_ViewModel.h"
55 #include "Plot2d_ViewFrame.h"
57 #include "SUIT_Session.h"
58 #include "SUIT_MessageBox.h"
60 #include <vtkRenderer.h>
61 #include <vtkActorCollection.h>
64 //=============================================================================
68 GetDesktop(const CAM_Module* theModule)
70 return theModule->application()->desktop();
73 SalomeApp_SelectionMgr*
74 GetSelectionMgr(const SalomeApp_Module* theModule)
76 return theModule->getApp()->selectionMgr();
80 GetAppStudy(const CAM_Module* theModule)
83 dynamic_cast<SalomeApp_Study*>(theModule->application()->activeStudy());
87 GetCStudy(const SalomeApp_Study* theStudy)
89 return theStudy->studyDS();
92 SALOMEDS::StudyManager_var
95 static SALOMEDS::StudyManager_var aStudyManager;
96 if(CORBA::is_nil(aStudyManager)){
97 SALOME_NamingService *aNamingService = SalomeApp_Application::namingService();
98 CORBA::Object_var anObject = aNamingService->Resolve("/myStudyManager");
99 aStudyManager = SALOMEDS::StudyManager::_narrow(anObject);
101 return aStudyManager;
105 IsStudyLocked( _PTR(Study) theStudy )
108 return theStudy->GetProperties()->IsLocked();
113 CheckLock( _PTR(Study) theStudy )
115 if(IsStudyLocked(theStudy))
116 throw std::runtime_error(QObject::tr("WRN_STUDY_LOCKED").latin1());
121 GetVisuGen(const CAM_Module* theModule)
123 static VISU_Gen_i* aGen = NULL;
125 SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
126 Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","VISU");
127 VISU_Gen_var aVISU = VISU_Gen::_narrow(aComponent);
128 if(!CORBA::is_nil(aVISU)){
129 aGen = VISU_Gen_i::GetVisuGenImpl();
130 aGen->SetCurrentStudy(GetDSStudy(GetCStudy(GetAppStudy(theModule))));
134 throw std::runtime_error(QObject::tr("ERR_CANT_FIND_VISU_COMPONENT").latin1());
138 SALOME_MED::MED_Gen_var
141 static SALOME_MED::MED_Gen_var aGen;
142 if(CORBA::is_nil(aGen)){
143 SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
144 Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","MED");
145 aGen = SALOME_MED::MED_Gen::_narrow(aComponent);
147 if(CORBA::is_nil(aGen))
148 throw std::runtime_error(QObject::tr("ERR_CANT_FIND_MED_COMPONENT").latin1());
152 VISU::Storable::TRestoringMap
153 getMapOfValue(SALOMEDS::SObject_var theSObject)
155 VISU::Storable::TRestoringMap aMap;
156 if(!theSObject->_is_nil()){
157 SALOMEDS::GenericAttribute_var anAttr;
158 if (theSObject->FindAttribute(anAttr, "AttributeComment")) {
159 SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
160 CORBA::String_var aValue = aComment->Value();
161 QString aString(aValue.in());
162 VISU::Storable::StrToMap(aString,aMap);
169 getValue(SALOMEDS::SObject_var theSObject,
173 VISU::Storable::TRestoringMap aMap = getMapOfValue(theSObject);
175 aStr = VISU::Storable::FindValue(aMap,theKey.latin1());
179 VISU::Storable::TRestoringMap getMapOfValue (_PTR(SObject) theSObject)
181 VISU::Storable::TRestoringMap aMap;
183 _PTR(GenericAttribute) anAttr;
184 if (theSObject->FindAttribute(anAttr, "AttributeComment")) {
185 _PTR(AttributeComment) aComment (anAttr);
186 std::string aValue = aComment->Value();
187 QString aString (aValue.c_str());
188 VISU::Storable::StrToMap(aString, aMap);
194 QString getValue (_PTR(SObject) theSObject, QString theKey)
197 VISU::Storable::TRestoringMap aMap = getMapOfValue(theSObject);
199 aStr = VISU::Storable::FindValue(aMap, theKey.latin1());
203 //************************************************************
206 GetSelectedObj(const SalomeApp_Study* theStudy,
207 const QString& theEntry,
208 VISU::Storable::TRestoringMap* theMap)
210 if ( !theStudy || theEntry.isEmpty() )
211 return CORBA::Object::_nil();
213 SALOMEDS::Study_var aStudy = GetDSStudy(GetCStudy( theStudy ));
214 SALOMEDS::SObject_var aSObject = aStudy->FindObjectID( theEntry.latin1() );
215 if(!aSObject->_is_nil()){
216 SALOMEDS::GenericAttribute_var anAttr;
217 if(theMap && aSObject->FindAttribute(anAttr,"AttributeComment")){
218 SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
219 std::string aValue = aComment->Value();
220 QString aString(aValue.c_str());
221 VISU::Storable::StrToMap(aString,*theMap);
223 return VISU::SObjectToObject(aSObject);
225 return CORBA::Object::_nil();
229 GetSelectedObj(const SalomeApp_Module* theModule,
230 Handle(SALOME_InteractiveObject)* theIO,
231 VISU::Storable::TRestoringMap* theMap)
233 SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
234 SALOME_ListIO aListIO;
235 aSelectionMgr->selectedObjects(aListIO);
236 SALOME_ListIteratorOfListIO anIter(aListIO);
238 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
242 return GetSelectedObj( GetAppStudy(theModule), anIO->getEntry(), theMap );
244 return CORBA::Object::_nil();
248 Add(SalomeApp_SelectionMgr* theSelectionMgr,
249 const Handle(SALOME_InteractiveObject)& theIO)
251 SALOME_ListIO aListIO;
252 theSelectionMgr->selectedObjects(aListIO);
253 aListIO.Append(theIO);
254 theSelectionMgr->setSelectedObjects(aListIO);
258 Remove(SalomeApp_SelectionMgr* theSelectionMgr,
259 const Handle(SALOME_InteractiveObject)& theIO)
261 if (theIO.IsNull()) return;
262 SALOME_ListIO aListIO, aNewListIO;
263 theSelectionMgr->selectedObjects(aListIO);
264 SALOME_ListIteratorOfListIO anIter (aListIO);
265 for (; anIter.More(); anIter.Next()) {
266 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
267 if (!anIO->isSame(theIO)) {
268 aNewListIO.Append(theIO);
271 theSelectionMgr->setSelectedObjects(aNewListIO);
275 * \brief Check, if "Delete" popup-menu can be put on current selection
277 * \param theModule - is used to access SelectionManager, Study and VISU_Gen
278 * \retval bool - returns TRUE if all currently selected objects are removable
281 IsRemovableSelected (const SalomeApp_Module* theModule)
283 SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
284 SALOME_ListIO aListIO;
285 aSelectionMgr->selectedObjects(aListIO);
287 if (aListIO.Extent() < 1)
290 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
291 if (!aStudy) return false;
293 // In some cases single selection can have its own popup-menu item for deletion
294 if (aListIO.Extent() == 1) {
295 Handle(SALOME_InteractiveObject) anIO = aListIO.First();
296 _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry());
298 VISU::VISUType aType = (VISU::VISUType)getValue(aSObject, "myType").toInt();
299 if (aType == VISU::TVIEW3D) {
300 return false; // special case
305 SALOME_ListIteratorOfListIO anIter (aListIO);
306 for (; anIter.More(); anIter.Next()) {
307 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
308 if (anIO->hasEntry()) {
309 _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry());
310 VISU::Storable::TRestoringMap pMap;
312 CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(aSObject);
313 if (!CORBA::is_nil(aCORBAObject)) {
314 VISU::RemovableObject_var aRemovableObj = VISU::RemovableObject::_narrow(aCORBAObject);
315 if (CORBA::is_nil(aRemovableObj)) {
316 // Not removable CORBA object
320 // Can be removed, if lays directly under VISU
321 // (first sub-level) or is a child of such an object
322 string aNAME, aVisuNAME = GetVisuGen(theModule)->ComponentDataType();
323 _PTR(GenericAttribute) anAttr;
324 _PTR(AttributeComment) aComment;
326 bool isUnderVISU = false;
327 _PTR(SObject) aFatherSObject = aSObject->GetFather();
328 if (aFatherSObject->FindAttribute(anAttr, "AttributeComment")) {
329 _PTR(AttributeComment) aComment (anAttr);
330 aNAME = aComment->Value();
331 if (aNAME == aVisuNAME) {
336 // Not directly under VISU component, check father
337 aCORBAObject = VISU::ClientSObjectToObject(aFatherSObject);
338 if (!CORBA::is_nil(aCORBAObject)) {
344 aFatherSObject = aFatherSObject->GetFather();
345 if (aFatherSObject->FindAttribute(anAttr, "AttributeComment")) {
346 _PTR(AttributeComment) aComment (anAttr);
347 aNAME = aComment->Value();
348 if (aNAME == aVisuNAME) {
353 // Father is not directly under VISU component
364 //************************************************************
368 ErasePrs (const SalomeApp_Module* theModule,
369 CORBA::Object_ptr theObject, bool theUpdate)
371 if (!CORBA::is_nil(theObject)) {
372 VISU::Base_var aBase = VISU::Base::_narrow(theObject);
373 if (CORBA::is_nil(aBase)) return;
374 VISU::VISUType aType = aBase->GetType();
378 if (VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aBase).in()))
379 PlotCurve(theModule, aCurve, VISU::eErase );
382 case VISU::TCONTAINER:
384 if (VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aBase).in()))
385 PlotContainer(theModule, aContainer, VISU::eErase );
390 if (VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aBase).in()))
391 PlotTable(theModule, aTable, VISU::eErase );
396 if (VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(aBase).in())) {
397 ErasePrs3d(theModule, aPrsObject);
399 if (SVTK_ViewWindow* vw = GetViewWindow(theModule))
409 DeleteSObject (SalomeApp_Module* theModule,
410 SALOMEDS::Study_ptr theStudy,
411 SALOMEDS::SObject_ptr theSObject)
413 SALOMEDS::ChildIterator_var aChildIter = theStudy->NewChildIterator(theSObject);
414 for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
415 SALOMEDS::SObject_var aChildSObject = aChildIter->Value();
416 CORBA::Object_var aChildObj = VISU::SObjectToObject(aChildSObject);
417 ErasePrs(theModule, aChildObj);
420 CORBA::Object_var anObj = VISU::SObjectToObject(theSObject);
421 if (!CORBA::is_nil(anObj)) {
422 VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObj);
423 if (!CORBA::is_nil(aRemovableObject)) {
424 aRemovableObject->RemoveFromStudy();
427 // Remove aSObject together with all its sub-objects
428 VISU::RemoveFromStudy(theSObject,
429 false, // remove not only IOR attribute, but Object With Children
430 false); // not Destroy() sub-objects
435 DeletePrs3d(SalomeApp_Module* theModule,
436 VISU::Prs3d_i* thePrs,
437 const Handle(SALOME_InteractiveObject)& theIO)
441 if(CheckLock(GetCStudy(GetAppStudy(theModule))))
443 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
444 CORBA::String_var anEntry = aSObject->GetID();
445 SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
446 Remove(aSelectionMgr,theIO);
447 TViewWindows aViewWindows = GetViews(theModule);
448 for(int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++){
449 SVTK_ViewWindow* aView = aViewWindows[i];
450 if(VISU_Actor* anActor = FindActor(aView,anEntry.in())){
451 aView->RemoveActor(anActor);
455 thePrs->RemoveFromStudy();
456 theModule->updateObjBrowser(); //update Object browser
460 ErasePrs3d(const SalomeApp_Module* theModule,
461 VISU::Prs3d_i* thePrs)
463 if ( SVTK_ViewWindow* vw = GetViewWindow( theModule ) ){
464 VISU_Actor* anVISUActor = FindActor( vw, thePrs );
466 anVISUActor->VisibilityOff();
471 //************************************************************
472 // Presentation management
475 ChangeRepresentation (const SalomeApp_Module* theModule,
476 VISU::PresentationType theType)
478 SUIT_ViewWindow* aView = GetActiveView(theModule, VTKViewer_Viewer::Type());
480 SVTK_ViewWindow* vw = (SVTK_ViewWindow*) aView;
482 Handle(SALOME_InteractiveObject) anIO;
483 CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
484 if (CORBA::is_nil(anObject)) return;
485 PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
486 if (!aServant.in()) return;
488 VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
490 if (VISU_Actor* anActor = GetActor(aPrs3d, vw)) {
493 if (anActor->IsShrunk())
496 anActor->SetShrink();
499 if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
500 aMesh->SetPresentationType(theType);
501 RecreateActor(theModule, aMesh);
503 anActor->SetRepresentation(theType);
511 //************************************************************
515 CheckTimeStamp(const SalomeApp_Module* theModule,
516 SALOMEDS::SObject_var& theSObject,
517 Handle(SALOME_InteractiveObject)* theIO)
519 Handle(SALOME_InteractiveObject) anIO;
520 CORBA::Object_var anObject = GetSelectedObj(theModule,&anIO);
523 if(!anIO.IsNull() && anIO->hasEntry()){
524 SALOMEDS::Study_var aStudy = GetDSStudy(GetCStudy(GetAppStudy(theModule)));
525 theSObject = aStudy->FindObjectID(anIO->getEntry());
526 QString aValue = getValue(theSObject,"myType");
527 if(aValue.toInt() == int(VISU::TTIMESTAMP))
530 SUIT_MessageBox::warn1(GetDesktop(theModule),
531 QObject::tr("WRN_VISU"),
532 QObject::tr("WRN_NO_AVAILABLE_DATA"),
533 QObject::tr("BUT_OK") );
539 CheckResult(const SalomeApp_Module* theModule,
540 SALOMEDS::SObject_var theSource,
541 VISU::Result_var& theResult)
543 SALOMEDS::SObject_var aSObj;
545 aSObj = theSource->GetFather();
546 if (CORBA::is_nil(aSObj))
549 aSObj = aSObj->GetFather();
550 if (CORBA::is_nil(aSObj))
553 aSObj = aSObj->GetFather();
554 if (CORBA::is_nil(aSObj))
557 CORBA::Object_var anObject = VISU::SObjectToObject(aSObj);
558 if (CORBA::is_nil(anObject)) {
559 aSObj = aSObj->GetFather();
560 if (CORBA::is_nil(aSObj))
562 anObject = VISU::SObjectToObject(aSObj);
565 if (CORBA::is_nil(anObject))
568 theResult = VISU::Result::_narrow(anObject);
569 VISU::Result_i* pResult = dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
571 SUIT_MessageBox::warn1(GetDesktop(theModule),
572 QObject::tr("WRN_VISU"),
573 QObject::tr("WRN_NO_AVAILABLE_DATA"),
574 QObject::tr("BUT_OK"));
578 //************************************************************
581 SUIT_ViewWindow* GetActiveView(const SalomeApp_Module* theModule, QString theType)
583 if(SalomeApp_Application* anApp = theModule->getApp()){
584 if(SUIT_ViewManager* aViewManager = anApp->activeViewManager()){
585 if (!theType.isNull()) {
586 if (aViewManager->getType() != theType)
589 return aViewManager->getActiveView();
595 //************************************************************
599 GetViews(const SalomeApp_Module* theModule)
601 TViewWindows aViewWindows;
602 if(SalomeApp_Application* anApp = theModule->getApp()){
603 ViewManagerList aViewManagerList;
604 anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
605 QPtrListIterator<SUIT_ViewManager> anIter(aViewManagerList);
606 while(SUIT_ViewManager* aViewManager = anIter.current()){
607 QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
608 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
609 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
610 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
611 aViewWindows.push_back(aView);
620 GetViewWindow(const SalomeApp_Module* theModule, const bool theCreate )
622 if(SalomeApp_Application* anApp = theModule->getApp()){
623 if(SUIT_ViewManager* aViewManager = anApp->getViewManager( SVTK_Viewer::Type(), theCreate )){
624 if(SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()){
625 return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
636 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
637 (SUIT_Session::session()->activeApplication());
639 if (SUIT_ViewManager* aViewManager = anApp->activeViewManager()) {
640 if (aViewManager->getType() == SVTK_Viewer::Type()) {
641 if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
642 return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
651 PublishInView(const SalomeApp_Module* theModule,
652 VISU::Prs3d_i* thePrs)
654 VISU_Actor* aActor = NULL;
657 if(SVTK_ViewWindow* aView = GetViewWindow(theModule)){
658 QApplication::setOverrideCursor( Qt::waitCursor );
659 if(aActor = thePrs->CreateActor()){
660 aView->AddActor(aActor);
662 QApplication::restoreOverrideCursor();
668 UpdateViewer(const SalomeApp_Module* theModule,
669 VISU::Prs3d_i* thePrs,
672 SVTK_ViewWindow* vw = GetViewWindow( theModule );
673 if (!vw) return NULL;
675 vtkRenderer *aRen = vw->getRenderer();
676 vtkActorCollection *anActColl = aRen->GetActors();
679 VISU_Actor* anVISUActor = NULL;
680 VISU_Actor* aResActor = NULL;
681 for(anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ){
682 if(!SALOME_Actor::SafeDownCast(anActor))
684 if(anActor->IsA("VISU_Actor")){
685 anVISUActor = VISU_Actor::SafeDownCast(anActor);
686 VISU::Prs3d_i* aPrs = anVISUActor->GetPrs3d();
687 if(aPrs == NULL) continue;
688 if (thePrs == aPrs) {
689 aResActor = anVISUActor->GetParent();
690 thePrs->UpdateActor(aResActor);
691 aResActor->VisibilityOn();
693 } else if (theDispOnly) {
694 anVISUActor->GetParent()->VisibilityOff();
697 } else if (theDispOnly && anActor->GetVisibility()) {
698 anActor->VisibilityOff();
705 anVISUActor = PublishInView( theModule, thePrs );
710 RepaintViewWindows (const SalomeApp_Module* theModule,
711 const Handle(SALOME_InteractiveObject)& theIObject)
713 TViewWindows aViewWindows;
714 if (SalomeApp_Application* anApp = theModule->getApp()) {
715 ViewManagerList aViewManagerList;
716 anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
717 QPtrListIterator<SUIT_ViewManager> anIter (aViewManagerList);
718 while (SUIT_ViewManager* aViewManager = anIter.current()) {
719 QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
720 for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
721 if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
722 if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
723 if (vw->isVisible(theIObject)) {
724 vw->getRenderer()->ResetCameraClippingRange();
726 vw->highlight(theIObject, true, true);
737 FindActor(SVTK_ViewWindow* theViewWindow,
738 const char* theEntry)
741 if(vtkRenderer* aRenderer = theViewWindow->getRenderer()){
742 if(vtkActorCollection* aCollection = aRenderer->GetActors()){
743 if(VISU_Actor* anActor = Find<VISU_Actor>(aCollection,TIsSameEntry<VISU_Actor>(theEntry))){
744 return anActor->GetParent();
752 FindActor(SVTK_ViewWindow* theViewWindow,
753 VISU::Prs3d_i* thePrs)
755 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
756 CORBA::String_var anEntry = aSObject->GetID();
757 return FindActor(theViewWindow,anEntry.in());
761 RecreateActor (const SalomeApp_Module* theModule,
762 VISU::Prs3d_i* thePrs)
764 QApplication::setOverrideCursor(Qt::waitCursor);
766 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
767 CORBA::String_var anEntry = aSObject->GetID();
772 TViewWindows aViewWindows = GetViews(theModule);
773 for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
774 SVTK_ViewWindow* aView = aViewWindows[i];
775 if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
776 thePrs->UpdateActor(anActor);
779 } catch (std::runtime_error& ex) {
781 QApplication::restoreOverrideCursor();
782 SUIT_MessageBox::warn1 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
783 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + " " + QObject::tr(ex.what()),
784 QObject::tr("BUT_OK"));
786 TViewWindows aViewWindows = GetViews(theModule);
787 for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
788 SVTK_ViewWindow* aView = aViewWindows[i];
789 if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
790 aView->RemoveActor(anActor);
796 QApplication::restoreOverrideCursor();
799 //************************************************************
803 GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate)
805 if(SalomeApp_Application* anApp = theModule->getApp()){
806 if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){
807 return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
813 // Internal function used by several public functions below
815 UpdateCurve(VISU::Curve_i* theCurve,
816 Plot2d_ViewFrame* aPlot,
817 SPlot2d_Curve* plotCurve,
820 if ( theDisplaying == VISU::eErase ) {
822 aPlot->eraseCurve( plotCurve, false );
824 else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
826 plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() );
827 //plotCurve->setVerTitle( ( theCurve->GetVerTitle().c_str() ) );
828 plotCurve->setVerTitle( theCurve->GetName() );
829 plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() );
830 plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() );
833 int nbPoints = theCurve->GetData( xList, yList );
834 if ( nbPoints > 0 && xList && yList ) {
835 plotCurve->setData( xList, yList, nbPoints );
837 if ( !theCurve->IsAuto() ) {
838 plotCurve->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
839 plotCurve->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() );
840 SALOMEDS::Color color = theCurve->GetColor();
841 plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
843 plotCurve->setAutoAssign( theCurve->IsAuto() );
844 aPlot->displayCurve( plotCurve, false );
847 Plot2d_Curve* crv = theCurve->CreatePresentation();
849 aPlot->displayCurve( crv, false );
850 theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
851 theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
852 SALOMEDS::Color newColor;
853 newColor.R = crv->getColor().red()/255.;
854 newColor.G = crv->getColor().green()/255.;
855 newColor.B = crv->getColor().blue()/255.;
856 theCurve->SetColor( newColor );
857 crv->setAutoAssign( theCurve->IsAuto() );
864 PlotTable(const SalomeApp_Module* theModule,
865 VISU::Table_i* table,
868 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
871 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
875 if ( theDisplaying == VISU::eDisplayOnly )
877 QList<Plot2d_Curve> clist;
878 aPlot->getCurves( clist );
879 _PTR(Study) aStudy = GetCStudy( GetAppStudy( theModule ) );
880 _PTR(SObject) TableSO = aStudy->FindObjectID( table->GetEntry().latin1() );
882 _PTR(ChildIterator) Iter = aStudy->NewChildIterator( TableSO );
883 for ( ; Iter->More(); Iter->Next() ) {
884 CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
885 if( !CORBA::is_nil( childObject ) ) {
886 CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
887 if( !CORBA::is_nil( aCurve ) ) {
888 VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
889 SPlot2d_Curve* plotCurve = 0;
890 SPlot2d_Curve* tmpCurve;
891 for ( int i = 0; i < clist.count(); i++ ) {
892 tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
893 if (tmpCurve && tmpCurve->hasIO() &&
894 !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
895 plotCurve = tmpCurve;
900 UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
902 if ( theDisplaying == VISU::eErase && plotCurve ) {
903 clist.remove( plotCurve );
913 PlotCurve(const SalomeApp_Module* theModule,
914 VISU::Curve_i* theCurve,
917 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
920 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
924 // if ( theDisplaying == VISU::eDisplayOnly )
925 // aPlot->EraseAll();
926 QList<Plot2d_Curve> clist;
927 aPlot->getCurves( clist );
928 SPlot2d_Curve* plotCurve = 0;
929 SPlot2d_Curve* tmpCurve;
930 for (int i = 0; i < clist.count(); i++) {
931 tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
932 if (tmpCurve && tmpCurve->hasIO() &&
933 !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
934 plotCurve = tmpCurve;
935 } else if (theDisplaying == VISU::eDisplayOnly) {
936 aPlot->eraseCurve(clist.at(i));
940 UpdateCurve(theCurve, aPlot, plotCurve, theDisplaying);
946 PlotContainer(const SalomeApp_Module* theModule,
947 VISU::Container_i* container,
950 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
953 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
957 if ( theDisplaying == VISU::eDisplayOnly )
959 QList<Plot2d_Curve> clist;
960 aPlot->getCurves( clist );
961 if ( container->GetNbCurves() > 0 ) {
962 int nbCurves = container->GetNbCurves();
963 for ( int k = 1; k <= nbCurves; k++ ) {
964 VISU::Curve_i* theCurve = container->GetCurve( k );
965 if ( theCurve && theCurve->IsValid() ) {
966 SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>
967 (aView->getCurveByIO(new SALOME_InteractiveObject (theCurve->GetEntry(), "", "")));
969 UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
971 if ( plotCurve && theDisplaying == VISU::eErase ) {
972 clist.remove( plotCurve );
981 CreatePlot(SalomeApp_Module* theModule,
982 _PTR(SObject) theTableSO)
984 if ( IsSObjectTable(theTableSO) ) {
985 CORBA::Object_var aTable = VISU::ClientSObjectToObject(theTableSO);
986 CORBA::Object_var aContainer = GetVisuGen( theModule )->CreateContainer();
987 if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) {
988 VISU::Table_i* pTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
989 VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aContainer).in());
991 if ( pContainer && pTable ) {
992 for ( int i = 2; i <= pTable->GetNbRows(); i++ ) {
993 CORBA::Object_var aNewCurve = GetVisuGen( theModule )->CreateCurve( pTable->_this(), 1, i );
994 if( !CORBA::is_nil( aNewCurve ) ) {
995 VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aNewCurve).in() );
997 pContainer->AddCurve( pCrv->_this() );
1001 theModule->updateObjBrowser();
1002 PlotContainer( theModule, pContainer, VISU::eDisplay );
1008 //************************************************************
1011 void CreateMesh (const SalomeApp_Module* theModule,
1012 const Handle(SALOME_InteractiveObject)& theIO)
1014 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
1015 //if (CheckLock(aStudy))
1018 SALOMEDS::SObject_var aResultSObj =
1019 GetDSStudy(aStudy)->FindObjectID(theIO->getEntry());
1022 VISU::Result_var aResult;
1023 VISU::Result_i* pResult = CheckResult(theModule, aResultSObj, aResult);
1024 if (pResult == NULL)
1027 Storable::TRestoringMap aMap = getMapOfValue(aResultSObj);
1029 string aComment = Storable::FindValue(aMap,"myComment",&isExist).latin1();
1033 CORBA::Object_var aMesh;
1034 string aMeshName = Storable::FindValue(aMap,"myMeshName").latin1();
1039 if (aComment == "ENTITY") {
1040 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myId").toInt();
1041 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity))
1042 aMesh = GetVisuGen(theModule)->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
1043 } else if (aComment == "FAMILY") {
1044 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myEntityId").toInt();
1045 string aFamilyName = Storable::FindValue(aMap,"myName").latin1();
1046 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()))
1047 aMesh = GetVisuGen(theModule)->FamilyMeshOnEntity
1048 (aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
1049 } else if (aComment == "GROUP") {
1050 string aGroupName = Storable::FindValue(aMap,"myName").latin1();
1051 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str()))
1052 aMesh = GetVisuGen(theModule)->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
1056 MESSAGE("VisuGUI::CreateMesh() - CREATE MESH");
1060 QApplication::restoreOverrideCursor();
1061 VISU::Mesh_i* pPresent = NULL;
1062 if (!CORBA::is_nil(aMesh))
1063 pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
1064 if (pPresent == NULL) {
1065 SUIT_MessageBox::warn1 (GetDesktop(theModule),
1066 QObject::tr("WRN_VISU"),
1067 QObject::tr("ERR_CANT_BUILD_PRESENTATION"),
1068 QObject::tr("BUT_OK"));
1072 if (SVTK_ViewWindow* aView = GetViewWindow(theModule)) {
1078 PublishInView(theModule, pPresent);
1082 MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
1085 theModule->application()->putInfo(QObject::tr("INF_DONE"));
1086 } catch (std::runtime_error& exc) {
1088 SUIT_MessageBox::warn1 (GetDesktop(theModule),
1089 QObject::tr("WRN_VISU"),
1090 QObject::tr("ERR_CANT_CREATE_ACTOR") + " " + QObject::tr(exc.what()),
1091 QObject::tr("BUT_OK"));
1096 // ========================================================================================
1097 // GetPrs3dList: find list of presentations for the given object
1098 // ========================================================================================
1099 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1100 const Handle(SALOME_InteractiveObject)& theIO)
1102 std::vector<VISU::Prs3d_i*> aList;
1103 if (!theIO.IsNull() && theIO->hasEntry()) {
1104 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1105 SALOMEDS::Study_var aStudy = GetDSStudy(aCStudy);
1106 SALOMEDS::SObject_var aSObject = aStudy->FindObjectID(theIO->getEntry());
1107 aList = GetPrs3dList(theModule, aSObject);
1112 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1113 SALOMEDS::SObject_ptr theObject)
1115 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1116 SALOMEDS::Study_var aStudy = GetDSStudy(aCStudy);
1118 std::vector<VISU::Prs3d_i*> aList; int k = 0;
1119 if (!theObject->_is_nil()) {
1120 CORBA::Object_var aCORBAObject = VISU::SObjectToObject(theObject);
1121 if (!CORBA::is_nil(aCORBAObject)) {
1122 VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
1123 if (!CORBA::is_nil(aVisuObj)) {
1124 VISU::VISUType aType = aVisuObj->GetType();
1126 case VISU::TSCALARMAP:
1127 case VISU::TISOSURFACE:
1128 case VISU::TDEFORMEDSHAPE:
1129 case VISU::TCUTPLANES:
1130 case VISU::TCUTLINES:
1131 case VISU::TVECTORS:
1132 case VISU::TSTREAMLINES:
1135 PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1136 if (aServant.in()) {
1137 VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
1138 aList.resize(k+1); aList[k] = aPrsObject; k++;
1144 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theObject);
1145 SALOMEDS::SObject_var aTimeStamp;
1146 anIter->Next(); // First is reference on support
1147 for(;anIter->More();anIter->Next()) {
1148 aTimeStamp = anIter->Value();
1149 if (aTimeStamp->_is_nil()) continue;
1150 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1151 if (!aSubList.empty()) {
1152 int n = aSubList.size();
1154 for (int i = 0; i < n; i++)
1155 { aList[k] = aSubList[i]; k++; }
1163 SALOMEDS::GenericAttribute_var anAttr;
1164 if (theObject->FindAttribute(anAttr, "AttributeComment")) {
1165 SALOMEDS::AttributeComment_var aComment =
1166 SALOMEDS::AttributeComment::_narrow(anAttr);
1167 string aComm = aComment->Value();
1168 QString strIn( aComm.c_str() );
1169 VISU::Storable::TRestoringMap pMap;
1170 VISU::Storable::StrToMap( strIn, pMap );
1172 VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(pMap,"myType",&isExist).toInt();
1177 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theObject);
1178 SALOMEDS::SObject_var aTimeStamp;
1179 anIter->Next(); // First is reference on support
1180 for (;anIter->More();anIter->Next()) {
1181 aTimeStamp = anIter->Value();
1182 if (aTimeStamp->_is_nil()) continue;
1183 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1184 if (!aSubList.empty()) {
1185 int n = aSubList.size();
1187 for (int i = 0; i < n; i++)
1188 { aList[k] = aSubList[i]; k++; }
1193 case VISU::TTIMESTAMP:
1195 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theObject);
1196 SALOMEDS::SObject_var aPrs;
1197 for (;anIter->More();anIter->Next()) {
1198 aPrs = anIter->Value();
1199 if (aPrs->_is_nil()) continue;
1200 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
1201 if (!aSubList.empty()) {
1202 int n = aSubList.size();
1204 for (int i = 0; i < n; i++)
1205 { aList[k] = aSubList[i]; k++; }