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();
93 IsStudyLocked( _PTR(Study) theStudy )
96 return theStudy->GetProperties()->IsLocked();
101 CheckLock( _PTR(Study) theStudy )
103 if(IsStudyLocked(theStudy))
104 throw std::runtime_error(QObject::tr("WRN_STUDY_LOCKED").latin1());
109 GetVisuGen(const CAM_Module* theModule)
111 static VISU_Gen_i* aGen = NULL;
113 SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
114 Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","VISU");
115 VISU_Gen_var aVISU = VISU_Gen::_narrow(aComponent);
116 if(!CORBA::is_nil(aVISU)){
117 aGen = VISU_Gen_i::GetVisuGenImpl();
118 aGen->SetCurrentStudy(GetDSStudy(GetCStudy(GetAppStudy(theModule))));
122 throw std::runtime_error(QObject::tr("ERR_CANT_FIND_VISU_COMPONENT").latin1());
126 SALOME_MED::MED_Gen_var
129 static SALOME_MED::MED_Gen_var aGen;
130 if(CORBA::is_nil(aGen)){
131 SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
132 Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","MED");
133 aGen = SALOME_MED::MED_Gen::_narrow(aComponent);
135 if(CORBA::is_nil(aGen))
136 throw std::runtime_error(QObject::tr("ERR_CANT_FIND_MED_COMPONENT").latin1());
141 VISU::Storable::TRestoringMap getMapOfValue (_PTR(SObject) theSObject)
143 VISU::Storable::TRestoringMap aMap;
145 _PTR(GenericAttribute) anAttr;
146 if (theSObject->FindAttribute(anAttr, "AttributeComment")) {
147 _PTR(AttributeComment) aComment (anAttr);
148 std::string aValue = aComment->Value();
149 QString aString (aValue.c_str());
150 VISU::Storable::StrToMap(aString, aMap);
156 QString getValue (_PTR(SObject) theSObject, QString theKey)
159 VISU::Storable::TRestoringMap aMap = getMapOfValue(theSObject);
161 aStr = VISU::Storable::FindValue(aMap, theKey.latin1());
165 //------------------------------------------------------------
168 GetSelectedObj(const SalomeApp_Study* theStudy,
169 const QString& theEntry,
170 VISU::Storable::TRestoringMap* theMap)
172 if (!theStudy || theEntry.isEmpty())
173 return CORBA::Object::_nil();
175 _PTR(Study) aStudy = GetCStudy(theStudy);
176 _PTR(SObject) aSObject = aStudy->FindObjectID(theEntry.latin1());
178 _PTR(GenericAttribute) anAttr;
179 if (theMap && aSObject->FindAttribute(anAttr,"AttributeComment")) {
180 _PTR(AttributeComment) aComment (anAttr);
181 std::string aValue = aComment->Value();
182 QString aString (aValue.c_str());
183 VISU::Storable::StrToMap(aString, *theMap);
185 return VISU::ClientSObjectToObject(aSObject);
187 return CORBA::Object::_nil();
191 GetSelectedObj(const SalomeApp_Module* theModule,
192 Handle(SALOME_InteractiveObject)* theIO,
193 VISU::Storable::TRestoringMap* theMap)
195 SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
196 SALOME_ListIO aListIO;
197 aSelectionMgr->selectedObjects(aListIO);
198 SALOME_ListIteratorOfListIO anIter(aListIO);
200 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
204 return GetSelectedObj( GetAppStudy(theModule), anIO->getEntry(), theMap );
206 return CORBA::Object::_nil();
210 GetPrsToModify(const SalomeApp_Module* theModule,
211 Handle(SALOME_InteractiveObject)* theIO,
212 VISU::Storable::TRestoringMap* theMap)
214 if (CheckLock(GetCStudy(GetAppStudy(theModule))))
217 CORBA::Object_var anObject = GetSelectedObj(theModule, theIO);
218 if (CORBA::is_nil(anObject))
221 PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
225 return dynamic_cast<VISU::Prs3d_i*>(aServant.in());
229 Add(SalomeApp_SelectionMgr* theSelectionMgr,
230 const Handle(SALOME_InteractiveObject)& theIO)
232 SALOME_ListIO aListIO;
233 theSelectionMgr->selectedObjects(aListIO);
234 aListIO.Append(theIO);
235 theSelectionMgr->setSelectedObjects(aListIO);
239 Remove(SalomeApp_SelectionMgr* theSelectionMgr,
240 const Handle(SALOME_InteractiveObject)& theIO)
242 if (theIO.IsNull()) return;
243 SALOME_ListIO aListIO, aNewListIO;
244 theSelectionMgr->selectedObjects(aListIO);
245 SALOME_ListIteratorOfListIO anIter (aListIO);
246 for (; anIter.More(); anIter.Next()) {
247 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
248 if (!anIO->isSame(theIO)) {
249 aNewListIO.Append(theIO);
252 theSelectionMgr->setSelectedObjects(aNewListIO);
256 * \brief Check, if "Delete" popup-menu can be put on current selection
258 * \param theModule - is used to access SelectionManager, Study and VISU_Gen
259 * \retval bool - returns TRUE if all currently selected objects are removable
262 IsRemovableSelected (const SalomeApp_Module* theModule)
264 SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
265 SALOME_ListIO aListIO;
266 aSelectionMgr->selectedObjects(aListIO);
268 if (aListIO.Extent() < 1)
271 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
272 if (!aStudy) return false;
274 // In some cases single selection can have its own popup-menu item for deletion
275 /*if (aListIO.Extent() == 1) {
276 Handle(SALOME_InteractiveObject) anIO = aListIO.First();
277 _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry());
279 VISU::VISUType aType = (VISU::VISUType)getValue(aSObject, "myType").toInt();
280 if (aType == VISU::TVIEW3D) {
281 return false; // special case
286 SALOME_ListIteratorOfListIO anIter (aListIO);
287 for (; anIter.More(); anIter.Next()) {
288 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
289 if (anIO->hasEntry()) {
290 _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry());
291 VISU::Storable::TRestoringMap pMap;
293 CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(aSObject);
294 if (!CORBA::is_nil(aCORBAObject)) {
295 VISU::RemovableObject_var aRemovableObj = VISU::RemovableObject::_narrow(aCORBAObject);
296 if (CORBA::is_nil(aRemovableObj)) {
297 // Not removable CORBA object
301 // Can be removed, if lays directly under VISU
302 // (first sub-level) or is a child of such an object
303 string aNAME, aVisuNAME = GetVisuGen(theModule)->ComponentDataType();
304 _PTR(GenericAttribute) anAttr;
305 _PTR(AttributeComment) aComment;
307 bool isUnderVISU = false;
308 _PTR(SObject) aFatherSObject = aSObject->GetFather();
309 if (aFatherSObject->FindAttribute(anAttr, "AttributeComment")) {
310 _PTR(AttributeComment) aComment (anAttr);
311 aNAME = aComment->Value();
312 if (aNAME == aVisuNAME) {
317 // Not directly under VISU component, check father
318 aCORBAObject = VISU::ClientSObjectToObject(aFatherSObject);
319 if (!CORBA::is_nil(aCORBAObject)) {
325 aFatherSObject = aFatherSObject->GetFather();
326 if (aFatherSObject->FindAttribute(anAttr, "AttributeComment")) {
327 _PTR(AttributeComment) aComment (anAttr);
328 aNAME = aComment->Value();
329 if (aNAME == aVisuNAME) {
334 // Father is not directly under VISU component
345 //************************************************************
349 ErasePrs (const SalomeApp_Module* theModule,
350 CORBA::Object_ptr theObject, bool theUpdate)
352 if (!CORBA::is_nil(theObject)) {
353 VISU::Base_var aBase = VISU::Base::_narrow(theObject);
354 if (CORBA::is_nil(aBase)) return;
355 VISU::VISUType aType = aBase->GetType();
359 if (VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aBase).in()))
360 PlotCurve(theModule, aCurve, VISU::eErase );
363 case VISU::TCONTAINER:
365 if (VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aBase).in()))
366 PlotContainer(theModule, aContainer, VISU::eErase );
371 if (VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aBase).in()))
372 PlotTable(theModule, aTable, VISU::eErase );
377 if (VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(aBase).in())) {
378 ErasePrs3d(theModule, aPrsObject);
380 if (SVTK_ViewWindow* vw = GetViewWindow(theModule))
390 DeleteSObject (SalomeApp_Module* theModule,
391 _PTR(Study) theStudy,
392 _PTR(SObject) theSObject)
394 SalomeApp_Study* study = GetAppStudy( theModule );
395 study->deleteReferencesTo( theSObject );
397 _PTR(ChildIterator) aChildIter = theStudy->NewChildIterator(theSObject);
398 for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
399 _PTR(SObject) aChildSObject = aChildIter->Value();
400 study->deleteReferencesTo( aChildSObject );
401 CORBA::Object_var aChildObj = VISU::ClientSObjectToObject(aChildSObject);
402 ErasePrs(theModule, aChildObj);
405 CORBA::Object_var anObj = VISU::ClientSObjectToObject(theSObject);
406 if (!CORBA::is_nil(anObj)) {
407 ErasePrs(theModule, anObj);
409 VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObj);
410 if (!CORBA::is_nil(aRemovableObject)) {
411 aRemovableObject->RemoveFromStudy();
414 // Remove aSObject together with all its sub-objects
416 VISU::RemoveFromStudy(theSObject,
417 false, // remove not only IOR attribute, but Object With Children
418 false); // not Destroy() sub-objects
423 DeletePrs3d(SalomeApp_Module* theModule,
424 VISU::Prs3d_i* thePrs,
425 const Handle(SALOME_InteractiveObject)& theIO)
429 if (CheckLock(GetCStudy(GetAppStudy(theModule))))
431 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
432 CORBA::String_var anEntry = aSObject->GetID();
433 SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
434 Remove(aSelectionMgr,theIO);
435 TViewWindows aViewWindows = GetViews(theModule);
436 for(int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++){
437 SVTK_ViewWindow* aView = aViewWindows[i];
438 if(VISU_Actor* anActor = FindActor(aView,anEntry.in())){
439 aView->RemoveActor(anActor);
443 thePrs->RemoveFromStudy();
447 ErasePrs3d(const SalomeApp_Module* theModule,
448 VISU::Prs3d_i* thePrs)
450 if ( SVTK_ViewWindow* vw = GetViewWindow( theModule ) ){
451 VISU_Actor* anVISUActor = FindActor( vw, thePrs );
453 anVISUActor->VisibilityOff();
458 //************************************************************
459 // Presentation management
462 ChangeRepresentation (const SalomeApp_Module* theModule,
463 VISU::PresentationType theType)
465 SUIT_ViewWindow* aView = GetActiveView(theModule, SVTK_Viewer::Type());
467 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( aView );
471 Handle(SALOME_InteractiveObject) anIO;
472 CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
473 if (CORBA::is_nil(anObject)) return;
475 VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
476 if (CORBA::is_nil(aVisuObj)) return;
478 PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
479 if (!aServant.in()) return;
481 VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
483 if (VISU_Actor* anActor = GetActor(aPrs3d, vw)) {
486 if (anActor->IsShrunk())
489 anActor->SetShrink();
492 if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
493 aMesh->SetPresentationType(theType);
494 RecreateActor(theModule, aMesh);
496 anActor->SetRepresentation(theType);
504 //************************************************************
508 CheckTimeStamp(const SalomeApp_Module* theModule,
509 _PTR(SObject)& theSObject,
510 Handle(SALOME_InteractiveObject)* theIO)
512 Handle(SALOME_InteractiveObject) anIO;
513 CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
516 if (!anIO.IsNull() && anIO->hasEntry()){
517 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
518 theSObject = aStudy->FindObjectID(anIO->getEntry());
519 QString aValue = getValue(theSObject,"myType");
520 if (aValue.toInt() == int(VISU::TTIMESTAMP))
523 SUIT_MessageBox::warn1(GetDesktop(theModule),
524 QObject::tr("WRN_VISU"),
525 QObject::tr("WRN_NO_AVAILABLE_DATA"),
526 QObject::tr("BUT_OK") );
531 CheckResult(const SalomeApp_Module* theModule,
532 _PTR(SObject) theSource,
533 VISU::Result_var& theResult)
535 _PTR(SObject) aSObj = theSource->GetFather();
539 aSObj = aSObj->GetFather();
543 aSObj = aSObj->GetFather();
547 CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
548 if (CORBA::is_nil(anObject)) {
549 aSObj = aSObj->GetFather();
552 anObject = VISU::ClientSObjectToObject(aSObj);
555 if (CORBA::is_nil(anObject))
558 theResult = VISU::Result::_narrow(anObject);
559 VISU::Result_i* pResult = dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
561 SUIT_MessageBox::warn1(GetDesktop(theModule),
562 QObject::tr("WRN_VISU"),
563 QObject::tr("WRN_NO_AVAILABLE_DATA"),
564 QObject::tr("BUT_OK"));
568 //************************************************************
571 SUIT_ViewWindow* GetActiveView(const SalomeApp_Module* theModule, QString theType)
573 if(SalomeApp_Application* anApp = theModule->getApp()){
574 if(SUIT_ViewManager* aViewManager = anApp->activeViewManager()){
575 if (!theType.isNull()) {
576 if (aViewManager->getType() != theType)
579 return aViewManager->getActiveView();
585 //************************************************************
589 GetViews(const SalomeApp_Module* theModule)
591 TViewWindows aViewWindows;
592 if(SalomeApp_Application* anApp = theModule->getApp()){
593 ViewManagerList aViewManagerList;
594 anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
595 QPtrListIterator<SUIT_ViewManager> anIter(aViewManagerList);
596 while(SUIT_ViewManager* aViewManager = anIter.current()){
597 QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
598 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
599 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
600 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
601 aViewWindows.push_back(aView);
610 GetViewWindow(const SalomeApp_Module* theModule, const bool theCreate )
612 if(SalomeApp_Application* anApp = theModule->getApp()){
613 if(SUIT_ViewManager* aViewManager = anApp->getViewManager( SVTK_Viewer::Type(), theCreate )){
614 if(SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()){
615 return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
626 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
627 (SUIT_Session::session()->activeApplication());
629 if (SUIT_ViewManager* aViewManager = anApp->activeViewManager()) {
630 if (aViewManager->getType() == SVTK_Viewer::Type()) {
631 if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
632 return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
641 PublishInView(const SalomeApp_Module* theModule,
642 VISU::Prs3d_i* thePrs)
644 VISU_Actor* aActor = NULL;
647 if(SVTK_ViewWindow* aView = GetViewWindow(theModule)){
648 QApplication::setOverrideCursor( Qt::waitCursor );
650 if(aActor = thePrs->CreateActor())
651 aView->AddActor(aActor);
652 }catch(std::exception& exc){
653 SUIT_MessageBox::warn1(GetDesktop(theModule),
654 QObject::tr("WRN_VISU"),
655 QObject::tr("ERR_CANT_CREATE_ACTOR"),
656 QObject::tr("BUT_OK"));
658 QApplication::restoreOverrideCursor();
664 UpdateViewer(const SalomeApp_Module* theModule,
665 VISU::Prs3d_i* thePrs,
668 SVTK_ViewWindow* vw = GetViewWindow( theModule );
669 if (!vw) return NULL;
671 vtkRenderer *aRen = vw->getRenderer();
672 vtkActorCollection *anActColl = aRen->GetActors();
675 VISU_Actor* anVISUActor = NULL;
676 VISU_Actor* aResActor = NULL;
677 for(anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ){
678 if(!SALOME_Actor::SafeDownCast(anActor))
680 if(anActor->IsA("VISU_Actor")){
681 anVISUActor = VISU_Actor::SafeDownCast(anActor);
682 VISU::Prs3d_i* aPrs = anVISUActor->GetPrs3d();
683 if(aPrs == NULL) continue;
684 if (thePrs == aPrs) {
685 aResActor = anVISUActor->GetParent();
686 thePrs->UpdateActor(aResActor);
687 aResActor->VisibilityOn();
689 } else if (theDispOnly) {
690 anVISUActor->GetParent()->VisibilityOff();
693 } else if (theDispOnly && anActor->GetVisibility()) {
694 anActor->VisibilityOff();
701 anVISUActor = PublishInView( theModule, thePrs );
706 RepaintViewWindows (const SalomeApp_Module* theModule,
707 const Handle(SALOME_InteractiveObject)& theIObject)
709 TViewWindows aViewWindows;
710 if (SalomeApp_Application* anApp = theModule->getApp()) {
711 ViewManagerList aViewManagerList;
712 anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
713 QPtrListIterator<SUIT_ViewManager> anIter (aViewManagerList);
714 while (SUIT_ViewManager* aViewManager = anIter.current()) {
715 QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
716 for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
717 if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
718 if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
719 if (vw->isVisible(theIObject)) {
720 vw->getRenderer()->ResetCameraClippingRange();
722 vw->highlight(theIObject, true, true);
733 FindActor(SVTK_ViewWindow* theViewWindow,
734 const char* theEntry)
737 if(vtkRenderer* aRenderer = theViewWindow->getRenderer()){
738 if(vtkActorCollection* aCollection = aRenderer->GetActors()){
739 if(VISU_Actor* anActor = Find<VISU_Actor>(aCollection,TIsSameEntry<VISU_Actor>(theEntry))){
740 return anActor->GetParent();
748 FindActor(SVTK_ViewWindow* theViewWindow,
749 VISU::Prs3d_i* thePrs)
751 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
752 CORBA::String_var anEntry = aSObject->GetID();
753 return FindActor(theViewWindow,anEntry.in());
757 RecreateActor (const SalomeApp_Module* theModule,
758 VISU::Prs3d_i* thePrs)
760 QApplication::setOverrideCursor(Qt::waitCursor);
762 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
763 CORBA::String_var anEntry = aSObject->GetID();
768 TViewWindows aViewWindows = GetViews(theModule);
769 for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
770 SVTK_ViewWindow* aView = aViewWindows[i];
771 if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
772 thePrs->UpdateActor(anActor);
775 } catch (std::runtime_error& ex) {
777 QApplication::restoreOverrideCursor();
778 SUIT_MessageBox::warn1 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
779 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + " " + QObject::tr(ex.what()),
780 QObject::tr("BUT_OK"));
782 TViewWindows aViewWindows = GetViews(theModule);
783 for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
784 SVTK_ViewWindow* aView = aViewWindows[i];
785 if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
786 aView->RemoveActor(anActor);
792 QApplication::restoreOverrideCursor();
795 //************************************************************
799 GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate)
801 if(SalomeApp_Application* anApp = theModule->getApp()){
802 if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){
803 return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
809 // Internal function used by several public functions below
811 UpdateCurve(VISU::Curve_i* theCurve,
812 Plot2d_ViewFrame* aPlot,
813 SPlot2d_Curve* plotCurve,
816 if ( theDisplaying == VISU::eErase ) {
818 aPlot->eraseCurve( plotCurve, false );
820 else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
822 plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() );
823 //plotCurve->setVerTitle( ( theCurve->GetVerTitle().c_str() ) );
824 plotCurve->setVerTitle( theCurve->GetName() );
825 plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() );
826 plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() );
829 int nbPoints = theCurve->GetData( xList, yList );
830 if ( nbPoints > 0 && xList && yList ) {
831 plotCurve->setData( xList, yList, nbPoints );
833 if ( !theCurve->IsAuto() ) {
834 plotCurve->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
835 plotCurve->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() );
836 SALOMEDS::Color color = theCurve->GetColor();
837 plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
839 plotCurve->setAutoAssign( theCurve->IsAuto() );
840 aPlot->displayCurve( plotCurve, false );
843 Plot2d_Curve* crv = theCurve->CreatePresentation();
845 aPlot->displayCurve( crv, false );
846 theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
847 theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
848 SALOMEDS::Color newColor;
849 newColor.R = crv->getColor().red()/255.;
850 newColor.G = crv->getColor().green()/255.;
851 newColor.B = crv->getColor().blue()/255.;
852 theCurve->SetColor( newColor );
853 crv->setAutoAssign( theCurve->IsAuto() );
860 PlotTable(const SalomeApp_Module* theModule,
861 VISU::Table_i* table,
864 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
867 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
871 if ( theDisplaying == VISU::eDisplayOnly )
873 QList<Plot2d_Curve> clist;
874 aPlot->getCurves( clist );
875 _PTR(Study) aStudy = GetCStudy( GetAppStudy( theModule ) );
876 _PTR(SObject) TableSO = aStudy->FindObjectID( table->GetEntry().latin1() );
878 _PTR(ChildIterator) Iter = aStudy->NewChildIterator( TableSO );
879 for ( ; Iter->More(); Iter->Next() ) {
880 CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
881 if( !CORBA::is_nil( childObject ) ) {
882 CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
883 if( !CORBA::is_nil( aCurve ) ) {
884 VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
885 SPlot2d_Curve* plotCurve = 0;
886 SPlot2d_Curve* tmpCurve;
887 for ( int i = 0; i < clist.count(); i++ ) {
888 tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
889 if (tmpCurve && tmpCurve->hasIO() &&
890 !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
891 plotCurve = tmpCurve;
896 UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
898 if ( theDisplaying == VISU::eErase && plotCurve ) {
899 clist.remove( plotCurve );
909 PlotCurve(const SalomeApp_Module* theModule,
910 VISU::Curve_i* theCurve,
913 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
916 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
920 // if ( theDisplaying == VISU::eDisplayOnly )
921 // aPlot->EraseAll();
922 QList<Plot2d_Curve> clist;
923 aPlot->getCurves( clist );
924 SPlot2d_Curve* plotCurve = 0;
925 SPlot2d_Curve* tmpCurve;
926 for (int i = 0; i < clist.count(); i++) {
927 tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
928 if (tmpCurve && tmpCurve->hasIO() &&
929 !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
930 plotCurve = tmpCurve;
931 } else if (theDisplaying == VISU::eDisplayOnly) {
932 aPlot->eraseCurve(clist.at(i));
936 UpdateCurve(theCurve, aPlot, plotCurve, theDisplaying);
942 PlotContainer(const SalomeApp_Module* theModule,
943 VISU::Container_i* container,
946 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
949 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
953 if ( theDisplaying == VISU::eDisplayOnly )
955 QList<Plot2d_Curve> clist;
956 aPlot->getCurves( clist );
957 if ( container->GetNbCurves() > 0 ) {
958 int nbCurves = container->GetNbCurves();
959 for ( int k = 1; k <= nbCurves; k++ ) {
960 VISU::Curve_i* theCurve = container->GetCurve( k );
961 if ( theCurve && theCurve->IsValid() ) {
962 SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>
963 (aView->getCurveByIO(new SALOME_InteractiveObject (theCurve->GetEntry(), "", "")));
965 UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
967 if ( plotCurve && theDisplaying == VISU::eErase ) {
968 clist.remove( plotCurve );
977 CreatePlot(SalomeApp_Module* theModule,
978 _PTR(SObject) theTableSO)
980 if ( IsSObjectTable(theTableSO) ) {
981 CORBA::Object_var aTable = VISU::ClientSObjectToObject(theTableSO);
982 CORBA::Object_var aContainer = GetVisuGen( theModule )->CreateContainer();
983 if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) {
984 VISU::Table_i* pTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
985 VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aContainer).in());
987 if ( pContainer && pTable ) {
988 for ( int i = 2; i <= pTable->GetNbRows(); i++ ) {
989 CORBA::Object_var aNewCurve = GetVisuGen( theModule )->CreateCurve( pTable->_this(), 1, i );
990 if( !CORBA::is_nil( aNewCurve ) ) {
991 VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aNewCurve).in() );
993 pContainer->AddCurve( pCrv->_this() );
997 PlotContainer( theModule, pContainer, VISU::eDisplay );
1003 //************************************************************
1006 void CreateMesh (const SalomeApp_Module* theModule,
1007 const Handle(SALOME_InteractiveObject)& theIO)
1009 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
1010 //if (CheckLock(aStudy))
1013 _PTR(SObject) aResultSObj = aStudy->FindObjectID(theIO->getEntry());
1016 VISU::Result_var aResult;
1017 VISU::Result_i* pResult = CheckResult(theModule, aResultSObj, aResult);
1018 if (pResult == NULL)
1021 Storable::TRestoringMap aMap = getMapOfValue(aResultSObj);
1023 string aComment = Storable::FindValue(aMap,"myComment",&isExist).latin1();
1027 CORBA::Object_var aMesh;
1028 string aMeshName = Storable::FindValue(aMap,"myMeshName").latin1();
1033 if (aComment == "ENTITY") {
1034 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myId").toInt();
1035 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity))
1036 aMesh = GetVisuGen(theModule)->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
1037 } else if (aComment == "FAMILY") {
1038 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myEntityId").toInt();
1039 string aFamilyName = Storable::FindValue(aMap,"myName").latin1();
1040 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()))
1041 aMesh = GetVisuGen(theModule)->FamilyMeshOnEntity
1042 (aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
1043 } else if (aComment == "GROUP") {
1044 string aGroupName = Storable::FindValue(aMap,"myName").latin1();
1045 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str()))
1046 aMesh = GetVisuGen(theModule)->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
1050 MESSAGE("VisuGUI::CreateMesh() - CREATE MESH");
1054 QApplication::restoreOverrideCursor();
1055 VISU::Mesh_i* pPresent = NULL;
1056 if (!CORBA::is_nil(aMesh))
1057 pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
1058 if (pPresent == NULL) {
1059 SUIT_MessageBox::warn1 (GetDesktop(theModule),
1060 QObject::tr("WRN_VISU"),
1061 QObject::tr("ERR_CANT_BUILD_PRESENTATION"),
1062 QObject::tr("BUT_OK"));
1066 if (SVTK_ViewWindow* aView = GetViewWindow(theModule)) {
1072 PublishInView(theModule, pPresent);
1076 MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
1079 theModule->application()->putInfo(QObject::tr("INF_DONE"));
1080 // Make "Save" button active
1081 theModule->getApp()->updateActions();
1082 } catch (std::runtime_error& exc) {
1084 SUIT_MessageBox::warn1 (GetDesktop(theModule),
1085 QObject::tr("WRN_VISU"),
1086 QObject::tr("ERR_CANT_CREATE_ACTOR") + " " + QObject::tr(exc.what()),
1087 QObject::tr("BUT_OK"));
1092 // ========================================================================================
1093 // GetPrs3dList: find list of presentations for the given object
1094 // ========================================================================================
1095 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1096 const Handle(SALOME_InteractiveObject)& theIO)
1098 std::vector<VISU::Prs3d_i*> aList;
1099 if (!theIO.IsNull() && theIO->hasEntry()) {
1100 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1101 _PTR(SObject) aSObject = aCStudy->FindObjectID(theIO->getEntry());
1102 aList = GetPrs3dList(theModule, aSObject);
1107 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1108 _PTR(SObject) theObject)
1110 std::vector<VISU::Prs3d_i*> aList; int k = 0;
1114 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1116 CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(theObject);
1117 if (!CORBA::is_nil(aCORBAObject)) {
1118 VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
1119 if (!CORBA::is_nil(aVisuObj)) {
1120 VISU::VISUType aType = aVisuObj->GetType();
1122 case VISU::TSCALARMAP:
1123 case VISU::TISOSURFACE:
1124 case VISU::TDEFORMEDSHAPE:
1125 case VISU::TCUTPLANES:
1126 case VISU::TCUTLINES:
1127 case VISU::TVECTORS:
1128 case VISU::TSTREAMLINES:
1131 PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1132 if (aServant.in()) {
1133 VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
1135 aList[k] = aPrsObject;
1142 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1143 _PTR(SObject) aTimeStamp;
1144 anIter->Next(); // First is reference on support
1145 for (; anIter->More(); anIter->Next()) {
1146 aTimeStamp = anIter->Value();
1147 if (!aTimeStamp) continue;
1148 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1149 if (!aSubList.empty()) {
1150 int n = aSubList.size();
1152 for (int i = 0; i < n; i++) {
1153 aList[k] = aSubList[i];
1163 _PTR(GenericAttribute) anAttr;
1164 if (theObject->FindAttribute(anAttr, "AttributeComment")) {
1165 _PTR(AttributeComment) aComment (anAttr);
1166 string aComm = aComment->Value();
1167 QString strIn (aComm.c_str());
1168 VISU::Storable::TRestoringMap pMap;
1169 VISU::Storable::StrToMap(strIn, pMap);
1171 VISU::VISUType aType =
1172 (VISU::VISUType)VISU::Storable::FindValue(pMap,"myType",&isExist).toInt();
1177 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1178 _PTR(SObject) aTimeStamp;
1179 anIter->Next(); // First is reference on support
1180 for (; anIter->More(); anIter->Next()) {
1181 aTimeStamp = anIter->Value();
1182 if (!aTimeStamp) 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];
1195 case VISU::TTIMESTAMP:
1197 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1199 for (; anIter->More(); anIter->Next()) {
1200 aPrs = anIter->Value();
1201 if (!aPrs) continue;
1202 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
1203 if (!aSubList.empty()) {
1204 int n = aSubList.size();
1206 for (int i = 0; i < n; i++) {
1207 aList[k] = aSubList[i];