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 IsRemovableSelected (const SalomeApp_Module* theModule)
277 SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
278 SALOME_ListIO aListIO;
279 aSelectionMgr->selectedObjects(aListIO);
281 if (aListIO.Extent() < 1)
284 SALOME_ListIteratorOfListIO anIter (aListIO);
285 for (; anIter.More(); anIter.Next()) {
286 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
287 if (anIO->hasEntry()) {
288 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
289 _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry());
290 VISU::Storable::TRestoringMap pMap;
292 CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(aSObject);
293 if (!CORBA::is_nil(aCORBAObject)) {
294 VISU::RemovableObject_var aRemovableObj = VISU::RemovableObject::_narrow(aCORBAObject);
295 if (CORBA::is_nil(aRemovableObj)) {
296 // Not removable CORBA object
300 // Can be removed, if lays directly under VISU
301 // (first sub-level) or is a child of such an object
302 string aNAME, aVisuNAME = GetVisuGen(theModule)->ComponentDataType();
303 _PTR(GenericAttribute) anAttr;
304 _PTR(AttributeComment) aComment;
306 bool isUnderVISU = false;
307 _PTR(SObject) aFatherSObject = aSObject->GetFather();
308 if (aFatherSObject->FindAttribute(anAttr, "AttributeComment")) {
309 _PTR(AttributeComment) aComment (anAttr);
310 aNAME = aComment->Value();
311 if (aNAME == aVisuNAME) {
316 // Not directly under VISU component, check father
317 aCORBAObject = VISU::ClientSObjectToObject(aFatherSObject);
318 if (!CORBA::is_nil(aCORBAObject)) {
324 aFatherSObject = aFatherSObject->GetFather();
325 if (aFatherSObject->FindAttribute(anAttr, "AttributeComment")) {
326 _PTR(AttributeComment) aComment (anAttr);
327 aNAME = aComment->Value();
328 if (aNAME == aVisuNAME) {
333 // Father is not directly under VISU component
344 //************************************************************
348 ErasePrs (const SalomeApp_Module* theModule,
349 CORBA::Object_ptr theObject, bool theUpdate)
351 if (!CORBA::is_nil(theObject)) {
352 VISU::Base_var aBase = VISU::Base::_narrow(theObject);
353 if (CORBA::is_nil(aBase)) return;
354 VISU::VISUType aType = aBase->GetType();
358 if (VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aBase).in()))
359 PlotCurve(theModule, aCurve, VISU::eErase );
362 case VISU::TCONTAINER:
364 if (VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aBase).in()))
365 PlotContainer(theModule, aContainer, VISU::eErase );
370 if (VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aBase).in()))
371 PlotTable(theModule, aTable, VISU::eErase );
376 if (VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(aBase).in())) {
377 ErasePrs3d(theModule, aPrsObject);
379 if (SVTK_ViewWindow* vw = GetViewWindow(theModule))
389 DeleteSObject (SalomeApp_Module* theModule,
390 SALOMEDS::Study_ptr theStudy,
391 SALOMEDS::SObject_ptr theSObject)
393 SALOMEDS::ChildIterator_var aChildIter = theStudy->NewChildIterator(theSObject);
394 for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
395 SALOMEDS::SObject_var aChildSObject = aChildIter->Value();
396 CORBA::Object_var aChildObj = VISU::SObjectToObject(aChildSObject);
397 ErasePrs(theModule, aChildObj);
400 CORBA::Object_var anObj = VISU::SObjectToObject(theSObject);
401 if (!CORBA::is_nil(anObj)) {
402 VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObj);
403 if (!CORBA::is_nil(aRemovableObject)) {
404 aRemovableObject->RemoveFromStudy();
407 // Remove aSObject together with all its sub-objects
408 VISU::RemoveFromStudy(theSObject,
409 false, // remove not only IOR attribute, but Object With Children
410 false); // not Destroy() sub-objects
415 DeletePrs3d(SalomeApp_Module* theModule,
416 VISU::Prs3d_i* thePrs,
417 const Handle(SALOME_InteractiveObject)& theIO)
421 if(CheckLock(GetCStudy(GetAppStudy(theModule))))
423 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
424 CORBA::String_var anEntry = aSObject->GetID();
425 SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
426 Remove(aSelectionMgr,theIO);
427 TViewWindows aViewWindows = GetViews(theModule);
428 for(int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++){
429 SVTK_ViewWindow* aView = aViewWindows[i];
430 if(VISU_Actor* anActor = FindActor(aView,anEntry.in())){
431 aView->RemoveActor(anActor);
435 thePrs->RemoveFromStudy();
436 theModule->updateObjBrowser(); //update Object browser
440 ErasePrs3d(const SalomeApp_Module* theModule,
441 VISU::Prs3d_i* thePrs)
443 if ( SVTK_ViewWindow* vw = GetViewWindow( theModule ) ){
444 VISU_Actor* anVISUActor = FindActor( vw, thePrs );
446 anVISUActor->VisibilityOff();
451 //************************************************************
452 // Presentation management
455 ChangeRepresentation (const SalomeApp_Module* theModule,
456 VISU::PresentationType theType)
458 SUIT_ViewWindow* aView = GetActiveView(theModule, VTKViewer_Viewer::Type());
460 SVTK_ViewWindow* vw = (SVTK_ViewWindow*) aView;
462 Handle(SALOME_InteractiveObject) anIO;
463 CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
464 if (CORBA::is_nil(anObject)) return;
465 PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
466 if (!aServant.in()) return;
468 VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
470 if (VISU_Actor* anActor = GetActor(aPrs3d, vw)) {
473 if (anActor->IsShrunk())
476 anActor->SetShrink();
479 if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
480 aMesh->SetPresentationType(theType);
481 RecreateActor(theModule, aMesh);
483 anActor->SetRepresentation(theType);
491 //************************************************************
495 CheckTimeStamp(const SalomeApp_Module* theModule,
496 SALOMEDS::SObject_var& theSObject,
497 Handle(SALOME_InteractiveObject)* theIO)
499 Handle(SALOME_InteractiveObject) anIO;
500 CORBA::Object_var anObject = GetSelectedObj(theModule,&anIO);
503 if(!anIO.IsNull() && anIO->hasEntry()){
504 SALOMEDS::Study_var aStudy = GetDSStudy(GetCStudy(GetAppStudy(theModule)));
505 theSObject = aStudy->FindObjectID(anIO->getEntry());
506 QString aValue = getValue(theSObject,"myType");
507 if(aValue.toInt() == int(VISU::TTIMESTAMP))
510 SUIT_MessageBox::warn1(GetDesktop(theModule),
511 QObject::tr("WRN_VISU"),
512 QObject::tr("WRN_NO_AVAILABLE_DATA"),
513 QObject::tr("BUT_OK") );
519 CheckResult(const SalomeApp_Module* theModule,
520 SALOMEDS::SObject_var theSource,
521 VISU::Result_var& theResult)
523 SALOMEDS::SObject_var aSObj;
525 aSObj = theSource->GetFather();
526 if (CORBA::is_nil(aSObj))
529 aSObj = aSObj->GetFather();
530 if (CORBA::is_nil(aSObj))
533 aSObj = aSObj->GetFather();
534 if (CORBA::is_nil(aSObj))
537 CORBA::Object_var anObject = VISU::SObjectToObject(aSObj);
538 if (CORBA::is_nil(anObject)) {
539 aSObj = aSObj->GetFather();
540 if (CORBA::is_nil(aSObj))
542 anObject = VISU::SObjectToObject(aSObj);
545 if (CORBA::is_nil(anObject))
548 theResult = VISU::Result::_narrow(anObject);
549 VISU::Result_i* pResult = dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
551 SUIT_MessageBox::warn1(GetDesktop(theModule),
552 QObject::tr("WRN_VISU"),
553 QObject::tr("WRN_NO_AVAILABLE_DATA"),
554 QObject::tr("BUT_OK"));
558 //************************************************************
561 SUIT_ViewWindow* GetActiveView(const SalomeApp_Module* theModule, QString theType)
563 if(SalomeApp_Application* anApp = theModule->getApp()){
564 if(SUIT_ViewManager* aViewManager = anApp->activeViewManager()){
565 if (!theType.isNull()) {
566 if (aViewManager->getType() != theType)
569 return aViewManager->getActiveView();
575 //************************************************************
579 GetViews(const SalomeApp_Module* theModule)
581 TViewWindows aViewWindows;
582 if(SalomeApp_Application* anApp = theModule->getApp()){
583 ViewManagerList aViewManagerList;
584 anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
585 QPtrListIterator<SUIT_ViewManager> anIter(aViewManagerList);
586 while(SUIT_ViewManager* aViewManager = anIter.current()){
587 QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
588 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
589 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
590 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
591 aViewWindows.push_back(aView);
600 GetViewWindow(const SalomeApp_Module* theModule, const bool theCreate )
602 if(SalomeApp_Application* anApp = theModule->getApp()){
603 if(SUIT_ViewManager* aViewManager = anApp->getViewManager( SVTK_Viewer::Type(), theCreate )){
604 if(SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()){
605 return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
616 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
617 (SUIT_Session::session()->activeApplication());
619 if (SUIT_ViewManager* aViewManager = anApp->activeViewManager()) {
620 if (aViewManager->getType() == SVTK_Viewer::Type()) {
621 if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
622 return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
631 PublishInView(const SalomeApp_Module* theModule,
632 VISU::Prs3d_i* thePrs)
634 VISU_Actor* aActor = NULL;
637 if(SVTK_ViewWindow* aView = GetViewWindow(theModule)){
638 QApplication::setOverrideCursor( Qt::waitCursor );
639 if(aActor = thePrs->CreateActor()){
640 aView->AddActor(aActor);
642 QApplication::restoreOverrideCursor();
648 UpdateViewer(const SalomeApp_Module* theModule,
649 VISU::Prs3d_i* thePrs,
652 SVTK_ViewWindow* vw = GetViewWindow( theModule );
653 if (!vw) return NULL;
655 vtkRenderer *aRen = vw->getRenderer();
656 vtkActorCollection *anActColl = aRen->GetActors();
659 VISU_Actor* anVISUActor = NULL;
660 VISU_Actor* aResActor = NULL;
661 for(anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ){
662 if(!SALOME_Actor::SafeDownCast(anActor))
664 if(anActor->IsA("VISU_Actor")){
665 anVISUActor = VISU_Actor::SafeDownCast(anActor);
666 VISU::Prs3d_i* aPrs = anVISUActor->GetPrs3d();
667 if(aPrs == NULL) continue;
668 if (thePrs == aPrs) {
669 aResActor = anVISUActor->GetParent();
670 thePrs->UpdateActor(aResActor);
671 aResActor->VisibilityOn();
673 } else if (theDispOnly) {
674 anVISUActor->GetParent()->VisibilityOff();
677 } else if (theDispOnly && anActor->GetVisibility()) {
678 anActor->VisibilityOff();
685 anVISUActor = PublishInView( theModule, thePrs );
690 FindActor(SVTK_ViewWindow* theViewWindow,
691 const char* theEntry)
694 if(vtkRenderer* aRenderer = theViewWindow->getRenderer()){
695 if(vtkActorCollection* aCollection = aRenderer->GetActors()){
696 if(VISU_Actor* anActor = Find<VISU_Actor>(aCollection,TIsSameEntry<VISU_Actor>(theEntry))){
697 return anActor->GetParent();
705 FindActor(SVTK_ViewWindow* theViewWindow,
706 VISU::Prs3d_i* thePrs)
708 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
709 CORBA::String_var anEntry = aSObject->GetID();
710 return FindActor(theViewWindow,anEntry.in());
714 RecreateActor (const SalomeApp_Module* theModule,
715 VISU::Prs3d_i* thePrs)
717 QApplication::setOverrideCursor(Qt::waitCursor);
719 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
720 CORBA::String_var anEntry = aSObject->GetID();
725 TViewWindows aViewWindows = GetViews(theModule);
726 for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
727 SVTK_ViewWindow* aView = aViewWindows[i];
728 if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
729 thePrs->UpdateActor(anActor);
732 } catch (std::runtime_error& ex) {
734 QApplication::restoreOverrideCursor();
735 SUIT_MessageBox::warn1 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
736 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + " " + QObject::tr(ex.what()),
737 QObject::tr("BUT_OK"));
739 TViewWindows aViewWindows = GetViews(theModule);
740 for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
741 SVTK_ViewWindow* aView = aViewWindows[i];
742 if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
743 aView->RemoveActor(anActor);
749 QApplication::restoreOverrideCursor();
752 //************************************************************
756 GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate)
758 if(SalomeApp_Application* anApp = theModule->getApp()){
759 if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){
760 return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
766 // Internal function used by several public functions below
768 UpdateCurve(VISU::Curve_i* theCurve,
769 Plot2d_ViewFrame* aPlot,
770 SPlot2d_Curve* plotCurve,
773 if ( theDisplaying == VISU::eErase ) {
775 aPlot->eraseCurve( plotCurve, false );
777 else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
779 plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() );
780 //plotCurve->setVerTitle( ( theCurve->GetVerTitle().c_str() ) );
781 plotCurve->setVerTitle( theCurve->GetName() );
782 plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() );
783 plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() );
786 int nbPoints = theCurve->GetData( xList, yList );
787 if ( nbPoints > 0 && xList && yList ) {
788 plotCurve->setData( xList, yList, nbPoints );
790 if ( !theCurve->IsAuto() ) {
791 plotCurve->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
792 plotCurve->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() );
793 SALOMEDS::Color color = theCurve->GetColor();
794 plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
796 plotCurve->setAutoAssign( theCurve->IsAuto() );
797 aPlot->displayCurve( plotCurve, false );
800 Plot2d_Curve* crv = theCurve->CreatePresentation();
802 aPlot->displayCurve( crv, false );
803 theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
804 theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
805 SALOMEDS::Color newColor;
806 newColor.R = crv->getColor().red()/255.;
807 newColor.G = crv->getColor().green()/255.;
808 newColor.B = crv->getColor().blue()/255.;
809 theCurve->SetColor( newColor );
810 crv->setAutoAssign( theCurve->IsAuto() );
817 PlotTable(const SalomeApp_Module* theModule,
818 VISU::Table_i* table,
821 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
824 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
828 if ( theDisplaying == VISU::eDisplayOnly )
830 QList<Plot2d_Curve> clist;
831 aPlot->getCurves( clist );
832 _PTR(Study) aStudy = GetCStudy( GetAppStudy( theModule ) );
833 _PTR(SObject) TableSO = aStudy->FindObjectID( table->GetEntry().latin1() );
835 _PTR(ChildIterator) Iter = aStudy->NewChildIterator( TableSO );
836 for ( ; Iter->More(); Iter->Next() ) {
837 CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
838 if( !CORBA::is_nil( childObject ) ) {
839 CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
840 if( !CORBA::is_nil( aCurve ) ) {
841 VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
842 SPlot2d_Curve* plotCurve = 0;
843 SPlot2d_Curve* tmpCurve;
844 for ( int i = 0; i < clist.count(); i++ ) {
845 tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
846 if (tmpCurve && tmpCurve->hasIO() &&
847 !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
848 plotCurve = tmpCurve;
853 UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
855 if ( theDisplaying == VISU::eErase && plotCurve ) {
856 clist.remove( plotCurve );
866 PlotCurve(const SalomeApp_Module* theModule,
867 VISU::Curve_i* theCurve,
870 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
873 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
877 // if ( theDisplaying == VISU::eDisplayOnly )
878 // aPlot->EraseAll();
879 QList<Plot2d_Curve> clist;
880 aPlot->getCurves( clist );
881 SPlot2d_Curve* plotCurve = 0;
882 SPlot2d_Curve* tmpCurve;
883 for (int i = 0; i < clist.count(); i++) {
884 tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
885 if (tmpCurve && tmpCurve->hasIO() &&
886 !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
887 plotCurve = tmpCurve;
888 } else if (theDisplaying == VISU::eDisplayOnly) {
889 aPlot->eraseCurve(clist.at(i));
893 UpdateCurve(theCurve, aPlot, plotCurve, theDisplaying);
899 PlotContainer(const SalomeApp_Module* theModule,
900 VISU::Container_i* container,
903 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
906 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
910 if ( theDisplaying == VISU::eDisplayOnly )
912 QList<Plot2d_Curve> clist;
913 aPlot->getCurves( clist );
914 if ( container->GetNbCurves() > 0 ) {
915 int nbCurves = container->GetNbCurves();
916 for ( int k = 1; k <= nbCurves; k++ ) {
917 VISU::Curve_i* theCurve = container->GetCurve( k );
918 if ( theCurve && theCurve->IsValid() ) {
919 SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>
920 (aView->getCurveByIO(new SALOME_InteractiveObject (theCurve->GetEntry(), "", "")));
922 UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
924 if ( plotCurve && theDisplaying == VISU::eErase ) {
925 clist.remove( plotCurve );
934 CreatePlot(SalomeApp_Module* theModule,
935 _PTR(SObject) theTableSO)
937 if ( IsSObjectTable(theTableSO) ) {
938 CORBA::Object_var aTable = VISU::ClientSObjectToObject(theTableSO);
939 CORBA::Object_var aContainer = GetVisuGen( theModule )->CreateContainer();
940 if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) {
941 VISU::Table_i* pTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
942 VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aContainer).in());
944 if ( pContainer && pTable ) {
945 for ( int i = 2; i <= pTable->GetNbRows(); i++ ) {
946 CORBA::Object_var aNewCurve = GetVisuGen( theModule )->CreateCurve( pTable->_this(), 1, i );
947 if( !CORBA::is_nil( aNewCurve ) ) {
948 VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aNewCurve).in() );
950 pContainer->AddCurve( pCrv->_this() );
954 theModule->updateObjBrowser();
955 PlotContainer( theModule, pContainer, VISU::eDisplay );
961 //************************************************************
964 void CreateMesh (const SalomeApp_Module* theModule,
965 const Handle(SALOME_InteractiveObject)& theIO)
967 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
968 //if (CheckLock(aStudy))
971 SALOMEDS::SObject_var aResultSObj =
972 GetDSStudy(aStudy)->FindObjectID(theIO->getEntry());
975 VISU::Result_var aResult;
976 VISU::Result_i* pResult = CheckResult(theModule, aResultSObj, aResult);
980 Storable::TRestoringMap aMap = getMapOfValue(aResultSObj);
982 string aComment = Storable::FindValue(aMap,"myComment",&isExist).latin1();
986 CORBA::Object_var aMesh;
987 string aMeshName = Storable::FindValue(aMap,"myMeshName").latin1();
992 if (aComment == "ENTITY") {
993 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myId").toInt();
994 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity))
995 aMesh = GetVisuGen(theModule)->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
996 } else if (aComment == "FAMILY") {
997 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myEntityId").toInt();
998 string aFamilyName = Storable::FindValue(aMap,"myName").latin1();
999 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()))
1000 aMesh = GetVisuGen(theModule)->FamilyMeshOnEntity
1001 (aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
1002 } else if (aComment == "GROUP") {
1003 string aGroupName = Storable::FindValue(aMap,"myName").latin1();
1004 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str()))
1005 aMesh = GetVisuGen(theModule)->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
1009 MESSAGE("VisuGUI::CreateMesh() - CREATE MESH");
1013 QApplication::restoreOverrideCursor();
1014 VISU::Mesh_i* pPresent = NULL;
1015 if (!CORBA::is_nil(aMesh))
1016 pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
1017 if (pPresent == NULL) {
1018 SUIT_MessageBox::warn1 (GetDesktop(theModule),
1019 QObject::tr("WRN_VISU"),
1020 QObject::tr("ERR_CANT_BUILD_PRESENTATION"),
1021 QObject::tr("BUT_OK"));
1025 if (SVTK_ViewWindow* aView = GetViewWindow(theModule)) {
1031 PublishInView(theModule, pPresent);
1035 MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
1038 theModule->application()->putInfo(QObject::tr("INF_DONE"));
1039 } catch (std::runtime_error& exc) {
1041 SUIT_MessageBox::warn1 (GetDesktop(theModule),
1042 QObject::tr("WRN_VISU"),
1043 QObject::tr("ERR_CANT_CREATE_ACTOR") + " " + QObject::tr(exc.what()),
1044 QObject::tr("BUT_OK"));
1049 // ========================================================================================
1050 // GetPrs3dList: find list of presentations for the given object
1051 // ========================================================================================
1052 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1053 const Handle(SALOME_InteractiveObject)& theIO)
1055 std::vector<VISU::Prs3d_i*> aList;
1056 if (!theIO.IsNull() && theIO->hasEntry()) {
1057 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1058 SALOMEDS::Study_var aStudy = GetDSStudy(aCStudy);
1059 SALOMEDS::SObject_var aSObject = aStudy->FindObjectID(theIO->getEntry());
1060 aList = GetPrs3dList(theModule, aSObject);
1065 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1066 SALOMEDS::SObject_ptr theObject)
1068 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1069 SALOMEDS::Study_var aStudy = GetDSStudy(aCStudy);
1071 std::vector<VISU::Prs3d_i*> aList; int k = 0;
1072 if (!theObject->_is_nil()) {
1073 CORBA::Object_var aCORBAObject = VISU::SObjectToObject(theObject);
1074 if (!CORBA::is_nil(aCORBAObject)) {
1075 VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
1076 if (!CORBA::is_nil(aVisuObj)) {
1077 VISU::VISUType aType = aVisuObj->GetType();
1079 case VISU::TSCALARMAP:
1080 case VISU::TISOSURFACE:
1081 case VISU::TDEFORMEDSHAPE:
1082 case VISU::TCUTPLANES:
1083 case VISU::TCUTLINES:
1084 case VISU::TVECTORS:
1085 case VISU::TSTREAMLINES:
1088 PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1089 if (aServant.in()) {
1090 VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
1091 aList.resize(k+1); aList[k] = aPrsObject; k++;
1097 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theObject);
1098 SALOMEDS::SObject_var aTimeStamp;
1099 anIter->Next(); // First is reference on support
1100 for(;anIter->More();anIter->Next()) {
1101 aTimeStamp = anIter->Value();
1102 if (aTimeStamp->_is_nil()) continue;
1103 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1104 if (!aSubList.empty()) {
1105 int n = aSubList.size();
1107 for (int i = 0; i < n; i++)
1108 { aList[k] = aSubList[i]; k++; }
1116 SALOMEDS::GenericAttribute_var anAttr;
1117 if (theObject->FindAttribute(anAttr, "AttributeComment")) {
1118 SALOMEDS::AttributeComment_var aComment =
1119 SALOMEDS::AttributeComment::_narrow(anAttr);
1120 string aComm = aComment->Value();
1121 QString strIn( aComm.c_str() );
1122 VISU::Storable::TRestoringMap pMap;
1123 VISU::Storable::StrToMap( strIn, pMap );
1125 VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(pMap,"myType",&isExist).toInt();
1130 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theObject);
1131 SALOMEDS::SObject_var aTimeStamp;
1132 anIter->Next(); // First is reference on support
1133 for (;anIter->More();anIter->Next()) {
1134 aTimeStamp = anIter->Value();
1135 if (aTimeStamp->_is_nil()) continue;
1136 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1137 if (!aSubList.empty()) {
1138 int n = aSubList.size();
1140 for (int i = 0; i < n; i++)
1141 { aList[k] = aSubList[i]; k++; }
1146 case VISU::TTIMESTAMP:
1148 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theObject);
1149 SALOMEDS::SObject_var aPrs;
1150 for (;anIter->More();anIter->Next()) {
1151 aPrs = anIter->Value();
1152 if (aPrs->_is_nil()) continue;
1153 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
1154 if (!aSubList.empty()) {
1155 int n = aSubList.size();
1157 for (int i = 0; i < n; i++)
1158 { aList[k] = aSubList[i]; k++; }