1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // VISU VISUGUI : GUI of VISU component
23 // File : VisuGUI_Tools.cxx
24 // Author : Sergey Anikin
27 #include "VisuGUI_Tools.h"
28 #include "VisuGUI_ViewTools.h"
29 #include "VisuGUI_Prs3dTools.h"
30 #include "VisuGUI_DialogRunner.h"
34 #include "VISU_Tools.h"
36 #include "VISU_Gen_i.hh"
37 #include "VISU_Prs3d_i.hh"
38 #include "VISU_Result_i.hh"
39 #include "VISU_Table_i.hh"
40 //#include "VISU_Mesh_i.hh"
41 #include "VISU_ViewManager_i.hh"
43 #include "VISU_Actor.h"
44 #include "VISU_ScalarMapAct.h"
46 #include "SalomeApp_Module.h"
47 #include "SalomeApp_Study.h"
48 #include "SalomeApp_Application.h"
50 #include "LightApp_DataObject.h"
51 #include "LightApp_SelectionMgr.h"
54 //#include "OB_Browser.h"
56 #include "SALOME_ListIO.hxx"
57 #include "SALOME_ListIteratorOfListIO.hxx"
59 #include "SVTK_ViewWindow.h"
60 #include "SVTK_Functor.h"
62 #include "VTKViewer_Algorithm.h"
64 #include "SPlot2d_ViewModel.h"
65 #include "Plot2d_ViewFrame.h"
66 #include "Plot2d_ViewManager.h"
68 #include "SUIT_Session.h"
69 #include "SUIT_MessageBox.h"
70 #include "SUIT_Desktop.h"
71 #include "SUIT_ViewWindow.h"
73 #include "CAM_DataModel.h"
75 #include <vtkRenderer.h>
76 #include <vtkActorCollection.h>
80 #include <QDoubleSpinBox>
84 //=============================================================================
87 //------------------------------------------------------------
89 GetDesktop(const CAM_Module* theModule)
91 return theModule && theModule->application() ? theModule->application()->desktop() : 0;
94 //------------------------------------------------------------
95 LightApp_SelectionMgr*
96 GetSelectionMgr(const SalomeApp_Module* theModule)
98 return theModule && theModule->getApp() ? theModule->getApp()->selectionMgr() : 0;
101 //------------------------------------------------------------
103 GetAppStudy(const CAM_Module* theModule)
105 return theModule && theModule->application() ?
106 dynamic_cast<SalomeApp_Study*>(theModule->application()->activeStudy()) : 0;
109 //------------------------------------------------------------
111 GetCStudy(const SalomeApp_Study* theStudy)
113 return theStudy ? theStudy->studyDS() : _PTR(Study)();
116 //------------------------------------------------------------
118 IsStudyLocked( _PTR(Study) theStudy )
120 return theStudy ? theStudy->GetProperties()->IsLocked() : true;
123 //------------------------------------------------------------
125 CheckLock( _PTR(Study) theStudy,
128 if(IsStudyLocked(theStudy)){
129 SUIT_MessageBox::warning(theWidget,
130 QObject::tr("WRN_VISU_WARNING"),
131 QObject::tr("WRN_STUDY_LOCKED") );
137 //------------------------------------------------------------
139 runAndWait( QDialog* dlg, const bool modal )
141 VisuGUI_DialogRunner r( dlg );
142 return r.run( modal );
145 //------------------------------------------------------------
147 FindDataObject(SUIT_DataObject* theDataObject,
148 const QString& theEntry,
151 int aLevel = theDataObject->level() + 2;
152 QString aSourceEntry = theEntry.section(':',0,aLevel);
153 DataObjectList aList;
154 theDataObject->children(aList);
155 DataObjectList::Iterator aDataObjectIter = aList.begin();
156 while( aDataObjectIter!= aList.end() ) {
157 if(LightApp_DataObject* aChildDataObject = dynamic_cast<LightApp_DataObject*>(*aDataObjectIter)){
158 QString anEntry = aChildDataObject->entry();
159 QString aCurrentEntry = anEntry.section(':',0,aLevel);
160 if(aSourceEntry == aCurrentEntry){
161 if(theLevel == aLevel){
162 return aChildDataObject;
164 return FindDataObject(aChildDataObject,theEntry,theLevel);
173 //------------------------------------------------------------
175 FindDataObject(CAM_Module* theModule,
176 _PTR(SObject) theSObject)
178 CAM_DataModel* aDataModel = theModule->dataModel();
179 CAM_DataObject* aRootDataObject = aDataModel->root();
180 if(_PTR(SComponent) aComponent = theSObject)
181 return dynamic_cast<LightApp_DataObject*>(aRootDataObject);
183 int aLevel = theSObject->Depth();
184 std::string anEntry = theSObject->GetID();
185 return FindDataObject(aRootDataObject,anEntry.c_str(),aLevel);
188 //------------------------------------------------------------
190 UpdateObjBrowser(SalomeApp_Module* theModule,
191 bool theIsUpdateDataModel,
192 _PTR(SObject) theSObject)
194 LightApp_DataObject* aDataObject = NULL;
196 aDataObject = FindDataObject(theModule,theSObject);
198 theModule->updateObjBrowser(theIsUpdateDataModel,aDataObject);
199 theModule->getApp()->updateActions();
202 //------------------------------------------------------------
204 IsSObjectTable( _PTR(SObject) theSObject )
207 _PTR(GenericAttribute) anAttr;
208 if (theSObject->FindAttribute( anAttr, "AttributeTableOfInteger" ))
210 if (theSObject->FindAttribute( anAttr, "AttributeTableOfReal" ))
216 //------------------------------------------------------------
218 GetVisuGen(const CAM_Module* theModule)
220 static VISU_Gen_i* aGen = NULL;
222 SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
223 Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","VISU");
224 VISU_Gen_var aVISU = VISU_Gen::_narrow(aComponent);
225 if(!CORBA::is_nil(aVISU)){
226 if((aGen = VISU_Gen_i::GetVisuGenImpl()))
227 aGen->SetCurrentStudy(GetDSStudy(GetCStudy(GetAppStudy(theModule))));
231 throw std::runtime_error(QObject::tr("ERR_CANT_FIND_VISU_COMPONENT").toLatin1().data());
235 //------------------------------------------------------------
236 SALOME_MED::MED_Gen_var
239 static SALOME_MED::MED_Gen_var aGen;
240 if(CORBA::is_nil(aGen)){
241 SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
242 Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","MED");
243 aGen = SALOME_MED::MED_Gen::_narrow(aComponent);
245 if(CORBA::is_nil(aGen))
246 throw std::runtime_error(QObject::tr("ERR_CANT_FIND_MED_COMPONENT").toLatin1().data());
251 //----------------------------------------------------------------------------
254 GetSelectedObjects(const SalomeApp_Module* theModule)
256 TSelectionInfo aSelectionInfo;
257 const SalomeApp_Study* aStudy = GetAppStudy(theModule);
258 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
259 if ( aStudy && aSelectionMgr ) {
260 SALOME_ListIO aListIO;
261 aSelectionMgr->selectedObjects(aListIO);
262 SALOME_ListIteratorOfListIO anIter(aListIO);
265 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
268 TObjectInfo anObjectInfo = GetObjectByEntry(aStudy, anIO->getEntry());
269 if(anObjectInfo.mySObject){
270 TSelectionItem aSelectionItem;
271 aSelectionItem.myObjectInfo = anObjectInfo;
272 aSelectionItem.myIO = anIO;
273 aSelectionInfo.push_back(aSelectionItem);
276 anIter.Next(); // MULTIPR fixed
279 return aSelectionInfo;
282 //----------------------------------------------------------------------------
284 GetObjectByEntry(const SalomeApp_Study* theStudy,
285 const std::string& theEntry)
287 TObjectInfo anObjectInfo;
288 if(!theStudy || theEntry == "")
291 _PTR(Study) aStudy = GetCStudy(theStudy);
292 if(_PTR(SObject) aSObject = aStudy->FindObjectID(theEntry)){
293 anObjectInfo.mySObject = aSObject;
294 CORBA::Object_var anObject = ClientSObjectToObject(aSObject);
295 if(VISU::Base_i* aBase = GetServantInterface<VISU::Base_i>(anObject))
296 anObjectInfo.myBase = aBase;
303 //----------------------------------------------------------------------------
305 GetPrs3dToModify(const SalomeApp_Module* theModule,
308 if (CheckLock(GetCStudy(GetAppStudy(theModule)), GetDesktop(theModule)))
311 return GetPrs3dFromBase(theBase);
314 //----------------------------------------------------------------------------
316 GetPrs3dFromBase(Base_i* theBase)
318 if(theBase && theBase->GetType() == VISU::TCOLOREDPRS3DHOLDER){
319 CORBA::Object_var anObject = theBase->_this();
320 VISU::ColoredPrs3dHolder_var aHolder = VISU::ColoredPrs3dHolder::_narrow(anObject);
321 VISU::Prs3d_var aPrs3d = aHolder->GetDevice();
322 return VISU::GetServantInterface<VISU::Prs3d_i>(aPrs3d);
324 return dynamic_cast<VISU::Prs3d_i*>(theBase);
328 //----------------------------------------------------------------------------
330 GetPrs3dSelectionInfo(const SalomeApp_Module* theModule,
331 VISU::Prs3d_i*& thePrs3d,
332 SVTK_ViewWindow*& theViewWindow,
333 VISU_Actor*& thenActor)
335 VISU::TSelectionInfo aSelectionInfo = VISU::GetSelectedObjects(theModule);
336 if(aSelectionInfo.empty())
339 VISU::TSelectionItem aSelectionItem = aSelectionInfo.front();
340 thePrs3d = GetPrs3dFromBase(aSelectionItem.myObjectInfo.myBase);
344 theViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
348 thenActor = FindActor(theViewWindow, thePrs3d);
356 //----------------------------------------------------------------------------
358 Add(LightApp_SelectionMgr* theSelectionMgr,
359 const Handle(SALOME_InteractiveObject)& theIO)
361 SALOME_ListIO aListIO;
362 theSelectionMgr->selectedObjects(aListIO);
363 aListIO.Append(theIO);
364 theSelectionMgr->setSelectedObjects(aListIO);
367 //------------------------------------------------------------
369 Remove(LightApp_SelectionMgr* theSelectionMgr,
370 const Handle(SALOME_InteractiveObject)& theIO)
372 if (theIO.IsNull()) return;
373 SALOME_ListIO aListIO, aNewListIO;
374 theSelectionMgr->selectedObjects(aListIO);
375 SALOME_ListIteratorOfListIO anIter (aListIO);
376 for (; anIter.More(); anIter.Next()) {
377 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
378 if (!anIO->isSame(theIO)) {
379 aNewListIO.Append(theIO);
382 theSelectionMgr->setSelectedObjects(aNewListIO);
386 * \brief Check, if the object can be deleted
388 * \param theEntry - entry of the object to check
389 * \param theModule - is used to access Study and VISU_Gen
390 * \retval bool - returns TRUE if the object is removable
393 IsRemovable (const std::string theEntry,
394 const SalomeApp_Module* theModule)
396 // asv : if selected object is a Save Point object selected in object browser - return false
397 if ( QString( theEntry.c_str() ).startsWith( QObject::tr( "SAVE_POINT_DEF_NAME" ) ) )
400 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
402 _PTR(SObject) aSObject = aStudy->FindObjectID(theEntry);
403 VISU::Storable::TRestoringMap pMap;
405 CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(aSObject);
406 if (!CORBA::is_nil(aCORBAObject)) {
407 VISU::RemovableObject_var aRemovableObj = VISU::RemovableObject::_narrow(aCORBAObject);
408 if (CORBA::is_nil(aRemovableObj)) {
409 // Not removable CORBA object
413 // Can be removed, if lays directly under VISU
414 // (first sub-level) or is a child of such an object
415 string aNAME, aVisuNAME = GetVisuGen(theModule)->ComponentDataType();
416 _PTR(GenericAttribute) anAttr;
417 _PTR(AttributeString) aComment;
419 _PTR(SObject) aRefSObject;
420 if (aSObject->ReferencedObject(aRefSObject)) {
421 // It can be a reference on curve, published under a container. IPAL 20317
422 VISU::TObjectInfo aRefObjectInfo = GetObjectByEntry(GetAppStudy(theModule), aRefSObject->GetID());
423 VISU::Base_i* aRefBase = aRefObjectInfo.myBase;
424 if( (aRefBase && aRefBase->GetType() == VISU::TCURVE) || (aRefBase && aRefBase->GetType() == VISU::TMESH) )
428 bool isUnderVISU = false;
429 _PTR(SObject) aFatherSObject = aSObject->GetFather();
430 if (aFatherSObject->FindAttribute(anAttr, "AttributeName")) {
431 // mkr : 24.11.2006 : use AttributeName and module title for correct "Delete"
432 // popup item displaying in object browser popup
433 _PTR(AttributeName) aComment (anAttr);
434 aNAME = aComment->Value();
435 QString aVisuTITLE = theModule->getApp()->moduleTitle(aVisuNAME.c_str());
436 if (!aVisuTITLE.compare(aNAME.c_str())) {
441 // Not directly under VISU component, check father
442 aCORBAObject = VISU::ClientSObjectToObject(aFatherSObject);
443 if (!CORBA::is_nil(aCORBAObject)) {
449 aFatherSObject = aFatherSObject->GetFather();
450 if (aFatherSObject->FindAttribute(anAttr, "AttributeString")) {
451 _PTR(AttributeString) aComment (anAttr);
452 aNAME = aComment->Value();
453 if (aNAME == aVisuNAME) {
458 // Father is not directly under VISU component
468 * \brief Check, if "Delete" popup-menu can be put on current selection
470 * \param theModule - is used to access SelectionManager, Study and VISU_Gen
471 * \retval bool - returns TRUE if all currently selected objects are removable
474 IsRemovableSelected (const SalomeApp_Module* theModule)
476 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
477 SALOME_ListIO aListIO;
478 aSelectionMgr->selectedObjects(aListIO);
480 if (aListIO.Extent() < 1)
483 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
484 if (!aStudy) return false;
486 SALOME_ListIteratorOfListIO anIter (aListIO);
487 for (; anIter.More(); anIter.Next()) {
488 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
489 if (anIO->hasEntry()) {
490 if (!IsRemovable(anIO->getEntry(), theModule))
497 //------------------------------------------------------------
499 DeleteSObject(VisuGUI* theModule,
500 _PTR(Study) theStudy,
501 _PTR(SObject) theSObject)
503 _PTR(ChildIterator) aChildIter = theStudy->NewChildIterator(theSObject);
504 for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
505 _PTR(SObject) aSObject = aChildIter->Value();
506 TObjectInfo anObjectInfo = GetObjectByEntry(GetAppStudy(theModule), aSObject->GetID());
507 ErasePrs(theModule, anObjectInfo.myBase, /*repaint_view_window = */false);
510 TObjectInfo anObjectInfo = GetObjectByEntry(GetAppStudy(theModule), theSObject->GetID());
511 if(anObjectInfo.myBase){
512 ErasePrs(theModule, anObjectInfo.myBase, /*repaint_view_window = */true);
514 CORBA::Object_var anObject = ClientSObjectToObject(theSObject);
515 VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObject);
516 if (!CORBA::is_nil(aRemovableObject)) {
517 aRemovableObject->RemoveFromStudy();
520 // Remove aSObject together with all its sub-objects
521 VISU::RemoveFromStudy(theSObject,
522 false, // remove not only IOR attribute, but Object With Children
523 false); // not Destroy() sub-objects
527 //------------------------------------------------------------
529 DeletePrs3d(VisuGUI* theModule,
530 VISU::Prs3d_i* thePrs)
535 if (CheckLock(GetCStudy(GetAppStudy(theModule)),GetDesktop(theModule)))
538 if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule))
539 RemoveScalarBarPosition(theModule, aViewWindow, thePrs);
541 if(VISU::ColoredPrs3d_i* aColoredPrs3d = dynamic_cast<VISU::ColoredPrs3d_i*>(thePrs)){
542 std::string anEntry = aColoredPrs3d->GetHolderEntry();
544 VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(GetAppStudy(theModule), anEntry);
545 if(VISU::Base_i* aBase = anObjectInfo.myBase){
546 if(aBase->GetType() == VISU::TCOLOREDPRS3DHOLDER){
547 CORBA::Object_var anObject = aBase->_this();
548 VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObject);
549 aRemovableObject->RemoveFromStudy();
556 thePrs->RemoveFromStudy();
560 //------------------------------------------------------------
561 // Presentation management
563 ChangeRepresentation (const SalomeApp_Module* theModule,
564 VISU::PresentationType theType)
566 TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
567 if(aSelectionInfo.empty())
570 VISU::Prs3d_i* aPrs3d;
571 VISU::PointMap3d_i* aTable;
573 VISU_ActorBase* anActorBase;
575 TSelectionItem aSelectionItem = aSelectionInfo.front();
576 aPrs3d = GetPrs3dFromBase(aSelectionItem.myObjectInfo.myBase);
578 aTable = dynamic_cast<VISU::PointMap3d_i*>(aSelectionItem.myObjectInfo.myBase);
583 SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
588 anActor = FindActor(aViewWindow, aPrs3d);
592 anActorBase = VISU::FindActorBase(aViewWindow, aTable);
601 if (anActor->IsShrunk()) {
606 anActor->SetShrink();
609 if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
610 aMesh->SetShrink(toShrink);
613 if (anActorBase->IsShrunk())
614 anActorBase->UnShrink();
616 anActorBase->SetShrink();
621 if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
622 aMesh->SetPresentationType(theType);
623 RecreateActor(theModule, aMesh);
625 anActor->SetRepresentation(theType);
629 anActorBase->SetRepresentation(theType);
632 aViewWindow->Repaint();
636 void ChangeQuadratic2DRepresentation (const SalomeApp_Module* theModule,
637 VISU::Quadratic2DPresentationType theType)
639 TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
640 if(aSelectionInfo.empty())
643 TSelectionItem aSelectionItem = aSelectionInfo.front();
645 VISU::Prs3d_i* aPrs3d = GetPrs3dFromBase(aSelectionItem.myObjectInfo.myBase);
647 SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
649 if(!aPrs3d || !aViewWindow)
652 VISU_Actor *anActor = FindActor(aViewWindow, aPrs3d);
656 if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
657 aMesh->SetQuadratic2DPresentationType(theType);
658 RecreateActor(theModule, aMesh);
662 anActor->SetQuadratic2DRepresentation(VISU_Actor::eLines);
665 anActor->SetQuadratic2DRepresentation(VISU_Actor::eArcs);
673 //------------------------------------------------------------
675 SetShading ( const SalomeApp_Module* theModule,
678 TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
679 if(aSelectionInfo.empty())
682 TSelectionItem aSelectionItem = GetSelectedObjects(theModule).front();
683 VISU::Prs3d_i* aPrs3d = GetPrs3dFromBase(aSelectionItem.myObjectInfo.myBase);
687 SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
691 VISU_Actor* anActor = FindActor(aViewWindow, aPrs3d);
695 if(VISU_ScalarMapAct* aScalarMapActor = dynamic_cast<VISU_ScalarMapAct*>(anActor)){
696 aScalarMapActor->SetShading(theOn);
697 aViewWindow->Repaint();
701 //------------------------------------------------------------
704 CheckTimeStamp(const SalomeApp_Module* theModule,
705 _PTR(SObject)& theSObject,
706 Handle(SALOME_InteractiveObject)& theIO,
707 ColoredPrs3d_i::EPublishInStudyMode& thePublishInStudyMode)
709 TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
710 if(!aSelectionInfo.empty()){
711 TSelectionItem aSelectionItem = aSelectionInfo.front();
712 theIO = aSelectionItem.myIO;
713 theSObject = aSelectionItem.myObjectInfo.mySObject;
714 VISU::VISUType aType = VISU::Storable::SObject2Type(theSObject);
715 if (VISU::TTIMESTAMP == aType){
716 thePublishInStudyMode = ColoredPrs3d_i::EPublishUnderTimeStamp;
719 if (VISU::TFIELD == aType){
720 thePublishInStudyMode = ColoredPrs3d_i::EPublishIndependently;
721 if(theSObject->FindSubObject(2,theSObject))
725 SUIT_MessageBox::warning(GetDesktop(theModule),
726 QObject::tr("WRN_VISU"),
727 QObject::tr("WRN_NO_AVAILABLE_DATA") );
731 //------------------------------------------------------------
733 CheckResult(const SalomeApp_Module* theModule,
734 _PTR(SObject) theSource,
735 VISU::Result_var& theResult)
737 if(theSource->Depth() < 3) // Bug of SALOMEDS : can\t get father from root object
740 _PTR(SObject) aSObj = theSource->GetFather();
744 aSObj = aSObj->GetFather();
748 aSObj = aSObj->GetFather();
752 CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
753 if (CORBA::is_nil(anObject)) {
754 aSObj = aSObj->GetFather();
757 anObject = VISU::ClientSObjectToObject(aSObj);
760 if (CORBA::is_nil(anObject))
763 theResult = VISU::Result::_narrow(anObject);
764 return dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
767 //------------------------------------------------------------
770 PublishMeshInView(const SalomeApp_Module* theModule,
771 VISU::Prs3d_i* thePrs,
772 SVTK_ViewWindow* theViewWindow)
774 VISU_Actor* aActor = NULL;
775 if (!thePrs || !theViewWindow)
778 QApplication::setOverrideCursor( Qt::WaitCursor );
780 if ((aActor = thePrs->CreateActor()))
781 theViewWindow->AddActor(aActor);
782 } catch(std::exception& exc) {
783 SUIT_MessageBox::warning
784 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
785 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()) );
787 QApplication::restoreOverrideCursor();
792 //------------------------------------------------------------
794 RepaintViewWindows (const SalomeApp_Module* theModule,
795 const Handle(SALOME_InteractiveObject)& theIObject)
797 TViewWindows aViewWindows;
798 if (SalomeApp_Application* anApp = theModule->getApp()) {
799 ViewManagerList aViewManagerList;
800 anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
801 QList<SUIT_ViewManager*>::Iterator anIter = aViewManagerList.begin();
802 while ( anIter != aViewManagerList.end() )
804 QVector<SUIT_ViewWindow*> aViews = (*anIter)->getViews();
805 for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
806 if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
807 if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
808 if (vw->isVisible(theIObject)) {
809 vw->getRenderer()->ResetCameraClippingRange();
811 vw->highlight(theIObject, true, true);
821 //------------------------------------------------------------
823 FindActor(const SalomeApp_Study* theStudy,
824 SVTK_ViewWindow* theViewWindow,
825 const QString& theEntry)
827 TObjectInfo anObjectInfo = GetObjectByEntry(theStudy, theEntry.toLatin1().data());
828 VISU::Prs3d_i* aPrs3d = GetPrs3dFromBase(anObjectInfo.myBase);
829 return FindActor(theViewWindow, aPrs3d);
832 //------------------------------------------------------------
834 FindActorBase(const SalomeApp_Study* theStudy,
835 SVTK_ViewWindow* theViewWindow,
836 const QString& theEntry)
838 TObjectInfo anObjectInfo = GetObjectByEntry(theStudy, theEntry.toLatin1().constData());
839 VISU::PointMap3d_i* aTable = dynamic_cast<VISU::PointMap3d_i*>(anObjectInfo.myBase);
840 return FindActorBase(theViewWindow, aTable);
843 //------------------------------------------------------------
845 RecreateActor (const SalomeApp_Module* theModule,
846 VISU::Prs3d_i* thePrs)
848 QApplication::setOverrideCursor(Qt::WaitCursor);
850 /* SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
851 CORBA::String_var anEntry = aSObject->GetID();*/
854 thePrs->UpdateActors();
855 } catch (std::runtime_error& exc) {
857 QApplication::restoreOverrideCursor();
858 SUIT_MessageBox::warning
859 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
860 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()) );
862 thePrs->RemoveActors();
865 QApplication::restoreOverrideCursor();
868 //------------------------------------------------------------
870 ComputeVisiblePropBounds(SVTK_ViewWindow* theViewWindow,
871 vtkFloatingPointType allBounds[6],
872 const char* theActorClassName)
874 vtkRenderer *aRen = theViewWindow->getRenderer();
875 VTK::ActorCollectionCopy aCopy(aRen->GetActors());
876 vtkActorCollection *anActColl = aCopy.GetActors();
878 vtkFloatingPointType *bounds;
879 int somethingVisible = false;
881 allBounds[0] = allBounds[2] = allBounds[4] = VTK_LARGE_FLOAT;
882 allBounds[1] = allBounds[3] = allBounds[5] = -VTK_LARGE_FLOAT;
883 // loop through all props
884 for (anActColl->InitTraversal(); (prop = anActColl->GetNextProp()); ) {
885 // if it's invisible, or has no geometry, we can skip the rest
886 if (prop->GetVisibility() && prop->IsA(theActorClassName)) {
887 bounds = prop->GetBounds();
888 // make sure we haven't got bogus bounds
889 if (bounds != NULL &&
890 bounds[0] > -VTK_LARGE_FLOAT && bounds[1] < VTK_LARGE_FLOAT &&
891 bounds[2] > -VTK_LARGE_FLOAT && bounds[3] < VTK_LARGE_FLOAT &&
892 bounds[4] > -VTK_LARGE_FLOAT && bounds[5] < VTK_LARGE_FLOAT)
894 somethingVisible = true;
895 if (bounds[0] < allBounds[0]) allBounds[0] = bounds[0];
896 if (bounds[1] > allBounds[1]) allBounds[1] = bounds[1];
897 if (bounds[2] < allBounds[2]) allBounds[2] = bounds[2];
898 if (bounds[3] > allBounds[3]) allBounds[3] = bounds[3];
899 if (bounds[4] < allBounds[4]) allBounds[4] = bounds[4];
900 if (bounds[5] > allBounds[5]) allBounds[5] = bounds[5];
904 return somethingVisible;
907 //------------------------------------------------------------
908 void SetFitAll(SVTK_ViewWindow* theViewWindow)
910 static vtkFloatingPointType PRECISION = 0.000001;
911 static vtkFloatingPointType DEVIATION = 600;
912 vtkFloatingPointType XYZ_Bnd[6];
913 if (!ComputeVisiblePropBounds(theViewWindow, XYZ_Bnd)) return;
915 vtkFloatingPointType absX = XYZ_Bnd[1] - XYZ_Bnd[0];
916 vtkFloatingPointType absY = XYZ_Bnd[3] - XYZ_Bnd[2];
917 vtkFloatingPointType absZ = XYZ_Bnd[5] - XYZ_Bnd[4];
919 enum CameraOrient {e3D, eFront, eLeft, eTop};
920 CameraOrient aCameraOrient = e3D;
921 if (absX <= PRECISION) aCameraOrient = eFront;
923 if (absY <= PRECISION) aCameraOrient = eLeft;
925 if (absZ <= PRECISION) aCameraOrient = eTop;
927 // all the three dimensions exceeds precision
928 vtkFloatingPointType dev_abs_XY = absX / absY;
929 vtkFloatingPointType dev_abs_YZ = absY / absZ;
930 vtkFloatingPointType dev_abs_XZ = absX / absZ;
931 if (dev_abs_XY >= DEVIATION || 1./dev_abs_YZ >= DEVIATION)
932 aCameraOrient = eLeft;
934 if (1./dev_abs_XY >= DEVIATION || 1./dev_abs_XZ >= DEVIATION)
935 aCameraOrient = eFront;
937 if (dev_abs_XZ >= DEVIATION || dev_abs_YZ >= DEVIATION)
938 aCameraOrient = eTop;
945 switch (aCameraOrient) {
946 case eFront: theViewWindow->onFrontView(); break;
947 case eLeft: theViewWindow->onLeftView(); break;
948 case eTop: theViewWindow->onTopView(); break;
949 case e3D: theViewWindow->onResetView(); break;
951 theViewWindow->getRenderer()->ResetCameraClippingRange();
952 theViewWindow->onFitAll();
955 //************************************************************
959 GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate)
961 if(SalomeApp_Application* anApp = theModule->getApp()){
962 if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){
963 return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
969 //------------------------------------------------------------
971 PlotTable(const SalomeApp_Module* theModule,
972 VISU::Table_i* table,
975 SalomeApp_Study* aStudy = GetAppStudy( theModule );
979 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
982 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
986 // implementation moved to VISU_I package (see VISU_Tools.h)
987 VISU::PlotTable( aStudy, aPlot, table, theDisplaying );
990 //------------------------------------------------------------
992 PlotCurve(const SalomeApp_Module* theModule,
993 VISU::Curve_i* theCurve,
996 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
999 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1003 // implementation moved to VISU_I package (see VISU_Tools.h)
1004 VISU::PlotCurve( aPlot, theCurve, theDisplaying );
1007 //------------------------------------------------------------
1009 PlotRemoveCurve(const SalomeApp_Module* theModule,
1010 VISU::Curve_i* pCrv)
1012 // implementation moved to VISU_I package (see VISU_Tools.h)
1013 VISU::PlotRemoveCurve( theModule->getApp(), pCrv );
1016 //------------------------------------------------------------
1018 PlotContainer(const SalomeApp_Module* theModule,
1019 VISU::Container_i* container,
1022 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1025 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1029 // implementation moved to VISU_I package (see VISU_Tools.h)
1030 VISU::PlotContainer( aPlot, container, theDisplaying );
1033 //------------------------------------------------------------
1035 CreatePlot(SalomeApp_Module* theModule,
1036 _PTR(SObject) theTableSO)
1038 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1041 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1045 VISU::VISU_Gen_i* aVisuGen = VISU::GetVisuGen( theModule );
1047 // implementation moved to VISU_I package (see VISU_Tools.h)
1048 VISU::CreatePlot( aVisuGen, aPlot, theTableSO );
1051 //************************************************************
1054 CreateMesh(VisuGUI* theModule,
1055 const Handle(SALOME_InteractiveObject)& theIO,
1056 SVTK_ViewWindow* theViewWindow)
1058 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
1059 //if (CheckLock(aStudy))
1062 _PTR(SObject) aResultSObj = aStudy->FindObjectID(theIO->getEntry());
1065 VISU::Result_var aResult;
1066 VISU::Result_i* pResult = CheckResult(theModule, aResultSObj, aResult);
1067 if (pResult == NULL)
1070 Storable::TRestoringMap aMap = Storable::GetStorableMap(aResultSObj);
1074 CORBA::Object_var aMesh;
1075 string aComment = Storable::FindValue(aMap,"myComment").toLatin1().data();
1076 string aMeshName = Storable::FindValue(aMap,"myMeshName").toLatin1().data();
1081 if (aComment == "ENTITY") {
1082 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myId").toInt();
1083 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity))
1084 aMesh = GetVisuGen(theModule)->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
1085 } else if (aComment == "FAMILY") {
1086 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myEntityId").toInt();
1087 string aFamilyName = Storable::FindValue(aMap,"myName").toLatin1().data();
1088 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()))
1089 aMesh = GetVisuGen(theModule)->FamilyMeshOnEntity
1090 (aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
1091 } else if (aComment == "GROUP") {
1092 string aGroupName = Storable::FindValue(aMap,"myName").toLatin1().data();
1093 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str()))
1094 aMesh = GetVisuGen(theModule)->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
1098 MESSAGE("VisuGUI::CreateMesh() - CREATE MESH");
1102 //QApplication::restoreOverrideCursor();
1103 VISU::Mesh_i* pPresent = NULL;
1104 if (!CORBA::is_nil(aMesh))
1105 pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
1106 if (pPresent == NULL) {
1107 SUIT_MessageBox::warning (GetDesktop(theModule),
1108 QObject::tr("WRN_VISU"),
1109 QObject::tr("ERR_CANT_BUILD_PRESENTATION") );
1113 if (theViewWindow) {
1119 if(GetResourceMgr()->booleanValue("VISU","display_only",false)){
1120 const VisuGUI* av = dynamic_cast<const VisuGUI*>(theModule);
1121 if(av)(const_cast<VisuGUI*>(av))->OnEraseAll();
1123 PublishMeshInView(theModule, pPresent, theViewWindow);
1124 if(GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false)){
1125 SetFitAll(theViewWindow);
1129 MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
1132 } catch (std::runtime_error& exc) {
1134 SUIT_MessageBox::warning(GetDesktop(theModule), QObject::tr("WRN_VISU"),
1135 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()) );
1139 UpdateObjBrowser(theModule, false, aResultSObj);
1141 theModule->application()->putInfo(QObject::tr("INF_DONE"));
1142 // Make "Save" button active
1143 theModule->getApp()->updateActions();
1147 // ========================================================================================
1148 // GetPrs3dList: find list of presentations for the given object
1149 // ========================================================================================
1150 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1151 const Handle(SALOME_InteractiveObject)& theIO,
1154 std::vector<VISU::Prs3d_i*> aList;
1155 if (!theIO.IsNull() && theIO->hasEntry()) {
1156 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1157 _PTR(SObject) aSObject = aCStudy->FindObjectID(theIO->getEntry());
1158 aList = GetPrs3dList(theModule, aSObject, theGP);
1163 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1164 _PTR(SObject) theObject,
1167 std::vector<VISU::Prs3d_i*> aList; int k = 0;
1171 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1173 CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(theObject);
1174 if (!CORBA::is_nil(aCORBAObject)) {
1175 VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
1176 if (!CORBA::is_nil(aVisuObj)) {
1177 VISU::VISUType aType = aVisuObj->GetType();
1179 case VISU::TGAUSSPOINTS:
1180 if ( !theGP ) break;
1181 case VISU::TSCALARMAP:
1182 case VISU::TISOSURFACES:
1183 case VISU::TDEFORMEDSHAPE:
1184 case VISU::TCUTPLANES:
1185 case VISU::TCUTLINES:
1186 case VISU::TCUTSEGMENT:
1187 case VISU::TVECTORS:
1188 case VISU::TSTREAMLINES:
1190 case VISU::TSCALARMAPONDEFORMEDSHAPE:
1191 case VISU::TDEFORMEDSHAPEANDSCALARMAP:
1194 PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1195 if (aServant.in()) {
1196 VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
1198 aList[k] = aPrsObject;
1205 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1206 _PTR(SObject) aTimeStamp;
1207 anIter->Next(); // First is reference on support
1208 for (; anIter->More(); anIter->Next()) {
1209 aTimeStamp = anIter->Value();
1210 if (!aTimeStamp) continue;
1211 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1212 if (!aSubList.empty()) {
1213 int n = aSubList.size();
1215 for (int i = 0; i < n; i++) {
1216 aList[k] = aSubList[i];
1226 VISU::VISUType aType = VISU::Storable::SObject2Type(theObject);
1228 case VISU::TFIELD: {
1229 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1230 _PTR(SObject) aTimeStamp;
1231 anIter->Next(); // First is reference on support
1232 for (; anIter->More(); anIter->Next()) {
1233 aTimeStamp = anIter->Value();
1234 if (!aTimeStamp) continue;
1235 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1236 if (!aSubList.empty()) {
1237 int n = aSubList.size();
1239 for (int i = 0; i < n; i++) {
1240 aList[k] = aSubList[i];
1247 case VISU::TTIMESTAMP: {
1248 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1250 for (; anIter->More(); anIter->Next()) {
1251 aPrs = anIter->Value();
1252 if (!aPrs) continue;
1253 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
1254 if (!aSubList.empty()) {
1255 int n = aSubList.size();
1257 for (int i = 0; i < n; i++) {
1258 aList[k] = aSubList[i];
1269 //------------------------------------------------------------
1270 int GetFreePositionOfDefaultScalarBar(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow)
1273 std::set<int> aIndexes;
1274 TViewToPrs3d aMap = theModule->getScalarBarsMap();
1275 TViewToPrs3d::const_iterator aViewToPrsIter = aMap.find(theViewWindow);
1276 if (aViewToPrsIter != aMap.end()) {
1277 TSetPrs3d::const_iterator aPrsIter = (aViewToPrsIter->second).begin();
1278 for (; aPrsIter != (aViewToPrsIter->second).end(); aPrsIter++) {
1279 aIndexes.insert((*aPrsIter).second);
1282 std::set<int>::const_iterator aIter = aIndexes.begin();
1283 for (int i = 1,length = aIndexes.size(); i <= length; i++) {
1284 std::set<int>::const_iterator aIter = aIndexes.find(i);
1285 if (aIter == aIndexes.end()) { minIndx = i; break; }
1286 else minIndx = i + 1;
1291 //------------------------------------------------------------
1292 void AddScalarBarPosition (VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1293 VISU::Prs3d_i* thePrs3d, int pos)
1295 TViewToPrs3d& aMap = theModule->getScalarBarsMap();
1296 TPrs3dToInd aPair; aPair.first = thePrs3d; aPair.second = pos;
1297 aMap[theViewWindow].insert(aPair);
1300 //------------------------------------------------------------
1301 void RemoveScalarBarPosition(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1302 VISU::Prs3d_i* thePrs3d)
1304 TViewToPrs3d& aMap = theModule->getScalarBarsMap();
1305 TSetPrs3d::iterator aIter = aMap[theViewWindow].begin();
1306 for (; aIter != aMap[theViewWindow].end(); aIter++)
1307 if ((*aIter).first == thePrs3d) {
1308 aMap[theViewWindow].erase(*aIter);
1312 //------------------------------------------------------------
1313 void initSpinBox( QSpinBox* spinBox,
1314 int min, int max, int step )
1316 spinBox->setRange( min, max );
1317 spinBox->setSingleStep( step );
1319 //------------------------------------------------------------
1320 void initSpinBox( QDoubleSpinBox* spinBox,
1321 double min, double max,
1322 double step, int decimals )
1324 spinBox->setRange( min, max );
1325 spinBox->setSingleStep( step );
1326 spinBox->setDecimals( decimals );
1328 //------------------------------------------------------------
1329 bool getClippingPlanesFolder(_PTR(Study) theStudy, _PTR(SObject)& theSObject)
1331 _PTR(SComponent) aVisuSO = theStudy->FindComponent("VISU");
1332 if (!aVisuSO) return false;
1333 _PTR(SObject) aFolder = theStudy->FindObject(CLIP_PLANES_FOLDER);
1335 _PTR(StudyBuilder) aBuilder = theStudy->NewBuilder();
1336 aFolder = aBuilder->NewObject(aVisuSO);
1338 _PTR(GenericAttribute) anAttr;
1339 anAttr = aBuilder->FindOrCreateAttribute(aFolder,"AttributeName");
1340 _PTR(AttributeName) aName(anAttr);
1341 aName->SetValue(CLIP_PLANES_FOLDER);
1343 theSObject = aFolder;