1 // Copyright (C) 2007-2010 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
23 // VISU VISUGUI : GUI of VISU component
24 // File : VisuGUI_Tools.cxx
25 // Author : Sergey Anikin
28 #include "VisuGUI_Tools.h"
29 #include "VisuGUI_ViewTools.h"
30 #include "VisuGUI_Prs3dTools.h"
31 #include "VisuGUI_DialogRunner.h"
35 #include "VISU_Tools.h"
37 #include "VISU_ColoredPrs3dHolder_i.hh"
38 #include "VISU_Gen_i.hh"
39 #include "VISU_Prs3d_i.hh"
40 #include "VISU_Result_i.hh"
41 #include "VISU_Table_i.hh"
42 //#include "VISU_Mesh_i.hh"
43 #include "VISU_ViewManager_i.hh"
45 #include "VISU_Actor.h"
46 #include "VISU_ScalarMapAct.h"
48 #include "SalomeApp_Module.h"
49 #include "SalomeApp_Study.h"
50 #include "SalomeApp_Application.h"
51 #include "SalomeApp_IntSpinBox.h"
52 #include "SalomeApp_DoubleSpinBox.h"
54 #include "LightApp_DataObject.h"
55 #include "LightApp_SelectionMgr.h"
58 //#include "OB_Browser.h"
60 #include "SALOME_ListIO.hxx"
61 #include "SALOME_ListIteratorOfListIO.hxx"
63 #include "SVTK_ViewWindow.h"
64 #include "SVTK_Functor.h"
66 #include "VTKViewer_Algorithm.h"
68 #include "SPlot2d_ViewModel.h"
69 #include "Plot2d_ViewFrame.h"
70 #include "Plot2d_ViewManager.h"
72 #include "SUIT_Session.h"
73 #include "SUIT_MessageBox.h"
74 #include "SUIT_Desktop.h"
75 #include "SUIT_ViewWindow.h"
76 #include "SUIT_ResourceMgr.h"
78 #include "CAM_DataModel.h"
80 #include <vtkRenderer.h>
81 #include <vtkActorCollection.h>
85 #include <QDoubleSpinBox>
90 //=============================================================================
93 //------------------------------------------------------------
95 GetDesktop(const CAM_Module* theModule)
97 return theModule && theModule->application() ? theModule->application()->desktop() : 0;
100 //------------------------------------------------------------
101 LightApp_SelectionMgr*
102 GetSelectionMgr(const SalomeApp_Module* theModule)
104 return theModule && theModule->getApp() ? theModule->getApp()->selectionMgr() : 0;
107 //------------------------------------------------------------
109 GetAppStudy(const CAM_Module* theModule)
111 return theModule && theModule->application() ?
112 dynamic_cast<SalomeApp_Study*>(theModule->application()->activeStudy()) : 0;
115 //------------------------------------------------------------
117 GetCStudy(const SalomeApp_Study* theStudy)
119 return theStudy ? theStudy->studyDS() : _PTR(Study)();
122 //------------------------------------------------------------
124 IsStudyLocked( _PTR(Study) theStudy )
126 return theStudy ? theStudy->GetProperties()->IsLocked() : true;
129 //------------------------------------------------------------
131 CheckLock( _PTR(Study) theStudy,
134 if(IsStudyLocked(theStudy)){
135 SUIT_MessageBox::warning(theWidget,
136 QObject::tr("WRN_VISU_WARNING"),
137 QObject::tr("WRN_STUDY_LOCKED") );
143 //------------------------------------------------------------
145 runAndWait( QDialog* dlg, const bool modal )
147 VisuGUI_DialogRunner r( dlg );
148 return r.run( modal );
151 //------------------------------------------------------------
153 FindDataObject(SUIT_DataObject* theDataObject,
154 const QString& theEntry,
157 int aLevel = theDataObject->level() + 2;
158 QString aSourceEntry = theEntry.section(':',0,aLevel);
159 DataObjectList aList;
160 theDataObject->children(aList);
161 DataObjectList::Iterator aDataObjectIter = aList.begin();
162 while( aDataObjectIter!= aList.end() ) {
163 if(LightApp_DataObject* aChildDataObject = dynamic_cast<LightApp_DataObject*>(*aDataObjectIter)){
164 QString anEntry = aChildDataObject->entry();
165 QString aCurrentEntry = anEntry.section(':',0,aLevel);
166 if(aSourceEntry == aCurrentEntry){
167 if(theLevel == aLevel){
168 return aChildDataObject;
170 return FindDataObject(aChildDataObject,theEntry,theLevel);
179 //------------------------------------------------------------
181 FindDataObject(CAM_Module* theModule,
182 _PTR(SObject) theSObject)
184 CAM_DataModel* aDataModel = theModule->dataModel();
185 CAM_DataObject* aRootDataObject = aDataModel->root();
186 if(_PTR(SComponent) aComponent = theSObject)
187 return dynamic_cast<LightApp_DataObject*>(aRootDataObject);
189 int aLevel = theSObject->Depth();
190 std::string anEntry = theSObject->GetID();
191 return FindDataObject(aRootDataObject,anEntry.c_str(),aLevel);
194 //------------------------------------------------------------
196 UpdateObjBrowser(SalomeApp_Module* theModule,
197 bool theIsUpdateDataModel,
198 _PTR(SObject) theSObject)
200 LightApp_DataObject* aDataObject = NULL;
202 aDataObject = FindDataObject(theModule,theSObject);
204 theModule->updateObjBrowser(theIsUpdateDataModel,aDataObject);
205 theModule->getApp()->updateActions();
208 //------------------------------------------------------------
210 IsSObjectTable( _PTR(SObject) theSObject )
213 _PTR(GenericAttribute) anAttr;
214 if (theSObject->FindAttribute( anAttr, "AttributeTableOfInteger" ))
216 if (theSObject->FindAttribute( anAttr, "AttributeTableOfReal" ))
222 //------------------------------------------------------------
224 GetVisuGen(const CAM_Module* theModule)
226 static VISU_Gen_i* aGen = 0;
228 SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
229 Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","VISU");
230 VISU_Gen_var aVISU = VISU_Gen::_narrow(aComponent);
231 if(!CORBA::is_nil(aVISU))
232 aGen = VISU_Gen_i::GetVisuGenImpl();
236 aGen->SetCurrentStudy(GetDSStudy(GetCStudy(GetAppStudy(theModule))));
238 throw std::runtime_error(QObject::tr("ERR_CANT_FIND_VISU_COMPONENT").toLatin1().data());
242 //------------------------------------------------------------
243 SALOME_MED::MED_Gen_var
246 static SALOME_MED::MED_Gen_var aGen;
247 if(CORBA::is_nil(aGen)){
248 SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
249 Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","MED");
250 aGen = SALOME_MED::MED_Gen::_narrow(aComponent);
252 if(CORBA::is_nil(aGen))
253 throw std::runtime_error(QObject::tr("ERR_CANT_FIND_MED_COMPONENT").toLatin1().data());
258 //----------------------------------------------------------------------------
261 GetSelectedObjects(const SalomeApp_Module* theModule)
263 TSelectionInfo aSelectionInfo;
264 const SalomeApp_Study* aStudy = GetAppStudy(theModule);
265 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
266 if ( aStudy && aSelectionMgr ) {
267 SALOME_ListIO aListIO;
268 aSelectionMgr->selectedObjects(aListIO);
269 SALOME_ListIteratorOfListIO anIter(aListIO);
272 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
275 TObjectInfo anObjectInfo = GetObjectByEntry(aStudy, anIO->getEntry());
276 if(anObjectInfo.mySObject){
277 TSelectionItem aSelectionItem;
278 aSelectionItem.myObjectInfo = anObjectInfo;
279 aSelectionItem.myIO = anIO;
280 aSelectionInfo.push_back(aSelectionItem);
283 anIter.Next(); // MULTIPR fixed
286 return aSelectionInfo;
289 //----------------------------------------------------------------------------
291 GetObjectByEntry(const SalomeApp_Study* theStudy,
292 const std::string& theEntry)
294 TObjectInfo anObjectInfo;
295 if(!theStudy || theEntry == "")
298 _PTR(Study) aStudy = GetCStudy(theStudy);
299 if(_PTR(SObject) aSObject = aStudy->FindObjectID(theEntry)){
300 anObjectInfo.mySObject = aSObject;
301 CORBA::Object_var anObject = ClientSObjectToObject(aSObject);
302 if(VISU::Base_i* aBase = GetServantInterface<VISU::Base_i>(anObject))
303 anObjectInfo.myBase = aBase;
310 //----------------------------------------------------------------------------
312 GetPrs3dToModify(const SalomeApp_Module* theModule,
315 if (CheckLock(GetCStudy(GetAppStudy(theModule)), GetDesktop(theModule)))
318 return GetPrs3dFromBase(theBase);
321 //----------------------------------------------------------------------------
323 GetPrs3dFromBase(Base_i* theBase)
325 if(theBase && theBase->GetType() == VISU::TCOLOREDPRS3DHOLDER){
326 CORBA::Object_var anObject = theBase->_this();
327 VISU::ColoredPrs3dHolder_var aHolder = VISU::ColoredPrs3dHolder::_narrow(anObject);
328 VISU::Prs3d_var aPrs3d = aHolder->GetDevice();
329 return VISU::GetServantInterface<VISU::Prs3d_i>(aPrs3d);
331 return dynamic_cast<VISU::Prs3d_i*>(theBase);
335 //----------------------------------------------------------------------------
337 GetPrs3dSelectionInfo(const SalomeApp_Module* theModule,
338 VISU::Prs3d_i*& thePrs3d,
339 SVTK_ViewWindow*& theViewWindow,
340 VISU_Actor*& thenActor)
342 VISU::TSelectionInfo aSelectionInfo = VISU::GetSelectedObjects(theModule);
343 if(aSelectionInfo.empty())
346 VISU::TSelectionItem aSelectionItem = aSelectionInfo.front();
347 thePrs3d = GetPrs3dFromBase(aSelectionItem.myObjectInfo.myBase);
351 theViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
355 thenActor = FindActor(theViewWindow, thePrs3d);
363 //----------------------------------------------------------------------------
365 Add(LightApp_SelectionMgr* theSelectionMgr,
366 const Handle(SALOME_InteractiveObject)& theIO)
368 SALOME_ListIO aListIO;
369 theSelectionMgr->selectedObjects(aListIO);
370 aListIO.Append(theIO);
371 theSelectionMgr->setSelectedObjects(aListIO);
374 //------------------------------------------------------------
376 Remove(LightApp_SelectionMgr* theSelectionMgr,
377 const Handle(SALOME_InteractiveObject)& theIO)
379 if (theIO.IsNull()) return;
380 SALOME_ListIO aListIO, aNewListIO;
381 theSelectionMgr->selectedObjects(aListIO);
382 SALOME_ListIteratorOfListIO anIter (aListIO);
383 for (; anIter.More(); anIter.Next()) {
384 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
385 if (!anIO->isSame(theIO)) {
386 aNewListIO.Append(theIO);
389 theSelectionMgr->setSelectedObjects(aNewListIO);
393 * \brief Check, if the object can be deleted
395 * \param theEntry - entry of the object to check
396 * \param theModule - is used to access Study and VISU_Gen
397 * \retval bool - returns TRUE if the object is removable
400 IsRemovable (const std::string theEntry,
401 const SalomeApp_Module* theModule)
403 // asv : if selected object is a Save Point object selected in object browser - return false
404 if ( QString( theEntry.c_str() ).startsWith( QObject::tr( "SAVE_POINT_DEF_NAME" ) ) )
407 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
409 _PTR(SObject) aSObject = aStudy->FindObjectID(theEntry);
410 VISU::Storable::TRestoringMap pMap;
412 CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(aSObject);
413 if (!CORBA::is_nil(aCORBAObject)) {
414 VISU::RemovableObject_var aRemovableObj = VISU::RemovableObject::_narrow(aCORBAObject);
415 if (CORBA::is_nil(aRemovableObj)) {
416 // Not removable CORBA object
420 // Can be removed, if lays directly under VISU
421 // (first sub-level) or is a child of such an object
422 string aNAME, aVisuNAME = GetVisuGen(theModule)->ComponentDataType();
423 _PTR(GenericAttribute) anAttr;
424 _PTR(AttributeString) aComment;
426 _PTR(SObject) aRefSObject;
427 if (aSObject->ReferencedObject(aRefSObject)) {
428 // It can be a reference on curve, published under a container. IPAL 20317
429 VISU::TObjectInfo aRefObjectInfo = GetObjectByEntry(GetAppStudy(theModule), aRefSObject->GetID());
430 VISU::Base_i* aRefBase = aRefObjectInfo.myBase;
431 if( (aRefBase && aRefBase->GetType() == VISU::TCURVE) || (aRefBase && aRefBase->GetType() == VISU::TMESH) )
435 bool isUnderVISU = false;
436 _PTR(SObject) aFatherSObject = aSObject->GetFather();
437 if (aFatherSObject->FindAttribute(anAttr, "AttributeName")) {
438 // mkr : 24.11.2006 : use AttributeName and module title for correct "Delete"
439 // popup item displaying in object browser popup
440 _PTR(AttributeName) aComment (anAttr);
441 aNAME = aComment->Value();
442 QString aVisuTITLE = theModule->getApp()->moduleTitle(aVisuNAME.c_str());
443 if (!aVisuTITLE.compare(aNAME.c_str())) {
448 // Not directly under VISU component, check father
449 aCORBAObject = VISU::ClientSObjectToObject(aFatherSObject);
450 if (!CORBA::is_nil(aCORBAObject)) {
456 aFatherSObject = aFatherSObject->GetFather();
457 if (aFatherSObject->FindAttribute(anAttr, "AttributeString")) {
458 _PTR(AttributeString) aComment (anAttr);
459 aNAME = aComment->Value();
460 if (aNAME == aVisuNAME) {
465 // Father is not directly under VISU component
475 * \brief Check, if "Delete" popup-menu can be put on current selection
477 * \param theModule - is used to access SelectionManager, Study and VISU_Gen
478 * \retval bool - returns TRUE if all currently selected objects are removable
481 IsRemovableSelected (const SalomeApp_Module* theModule)
483 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
484 SALOME_ListIO aListIO;
485 aSelectionMgr->selectedObjects(aListIO);
487 if (aListIO.Extent() < 1)
490 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
491 if (!aStudy) return false;
493 SALOME_ListIteratorOfListIO anIter (aListIO);
494 for (; anIter.More(); anIter.Next()) {
495 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
496 if (anIO->hasEntry()) {
497 if (!IsRemovable(anIO->getEntry(), theModule))
504 //------------------------------------------------------------
506 DeleteSObject(VisuGUI* theModule,
507 _PTR(Study) theStudy,
508 _PTR(SObject) theSObject)
510 _PTR(ChildIterator) aChildIter = theStudy->NewChildIterator(theSObject);
511 for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
512 _PTR(SObject) aSObject = aChildIter->Value();
513 TObjectInfo anObjectInfo = GetObjectByEntry(GetAppStudy(theModule), aSObject->GetID());
514 ErasePrs(theModule, anObjectInfo.myBase, /*repaint_view_window = */false);
517 TObjectInfo anObjectInfo = GetObjectByEntry(GetAppStudy(theModule), theSObject->GetID());
518 if(anObjectInfo.myBase){
519 ErasePrs(theModule, anObjectInfo.myBase, /*repaint_view_window = */true);
521 CORBA::Object_var anObject = ClientSObjectToObject(theSObject);
522 VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObject);
523 if (!CORBA::is_nil(aRemovableObject)) {
524 aRemovableObject->RemoveFromStudy();
527 // Remove aSObject together with all its sub-objects
528 VISU::RemoveFromStudy(theSObject,
529 false, // remove not only IOR attribute, but Object With Children
530 false); // not Destroy() sub-objects
534 //------------------------------------------------------------
536 DeletePrs3d(VisuGUI* theModule,
537 VISU::Prs3d_i* thePrs)
542 if (CheckLock(GetCStudy(GetAppStudy(theModule)),GetDesktop(theModule)))
545 if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule))
546 RemoveScalarBarPosition(theModule, aViewWindow, thePrs);
548 if(VISU::ColoredPrs3d_i* aColoredPrs3d = dynamic_cast<VISU::ColoredPrs3d_i*>(thePrs)){
549 std::string anEntry = aColoredPrs3d->GetHolderEntry();
551 VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(GetAppStudy(theModule), anEntry);
552 if(VISU::Base_i* aBase = anObjectInfo.myBase){
553 if(aBase->GetType() == VISU::TCOLOREDPRS3DHOLDER){
554 CORBA::Object_var anObject = aBase->_this();
555 VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObject);
556 aRemovableObject->RemoveFromStudy();
563 thePrs->RemoveFromStudy();
567 //------------------------------------------------------------
568 // Presentation management
570 ChangeRepresentation (const SalomeApp_Module* theModule,
571 VISU::PresentationType theType)
573 TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
574 if(aSelectionInfo.empty())
577 VISU::Prs3d_i* aPrs3d;
578 VISU::PointMap3d_i* aTable;
580 VISU_ActorBase* anActorBase;
582 TSelectionItem aSelectionItem = aSelectionInfo.front();
583 aPrs3d = GetPrs3dFromBase(aSelectionItem.myObjectInfo.myBase);
585 aTable = dynamic_cast<VISU::PointMap3d_i*>(aSelectionItem.myObjectInfo.myBase);
590 SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
595 anActor = FindActor(aViewWindow, aPrs3d);
599 anActorBase = VISU::FindActorBase(aViewWindow, aTable);
608 if (anActor->IsShrunk()) {
613 anActor->SetShrink();
616 if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
617 aMesh->SetShrink(toShrink);
620 if (anActorBase->IsShrunk())
621 anActorBase->UnShrink();
623 anActorBase->SetShrink();
628 if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
629 aMesh->SetPresentationType(theType);
630 RecreateActor(theModule, aMesh);
632 anActor->SetRepresentation(theType);
636 anActorBase->SetRepresentation(theType);
639 aViewWindow->Repaint();
643 void ChangeQuadratic2DRepresentation (const SalomeApp_Module* theModule,
644 VISU::Quadratic2DPresentationType theType)
646 TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
647 if(aSelectionInfo.empty())
650 TSelectionItem aSelectionItem = aSelectionInfo.front();
652 VISU::Prs3d_i* aPrs3d = GetPrs3dFromBase(aSelectionItem.myObjectInfo.myBase);
654 SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
656 if(!aPrs3d || !aViewWindow)
659 VISU_Actor *anActor = FindActor(aViewWindow, aPrs3d);
663 if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
664 aMesh->SetQuadratic2DPresentationType(theType);
665 RecreateActor(theModule, aMesh);
669 anActor->SetQuadratic2DRepresentation(VISU_Actor::eLines);
672 anActor->SetQuadratic2DRepresentation(VISU_Actor::eArcs);
680 //------------------------------------------------------------
682 SetShading ( const SalomeApp_Module* theModule,
685 TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
686 if(aSelectionInfo.empty())
689 TSelectionItem aSelectionItem = GetSelectedObjects(theModule).front();
690 VISU::Prs3d_i* aPrs3d = GetPrs3dFromBase(aSelectionItem.myObjectInfo.myBase);
694 SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
698 VISU_Actor* anActor = FindActor(aViewWindow, aPrs3d);
702 if(VISU_ScalarMapAct* aScalarMapActor = dynamic_cast<VISU_ScalarMapAct*>(anActor)){
703 aScalarMapActor->SetShading(theOn);
704 aViewWindow->Repaint();
708 //------------------------------------------------------------
711 CheckTimeStamp(const SalomeApp_Module* theModule,
712 _PTR(SObject)& theSObject,
713 Handle(SALOME_InteractiveObject)& theIO,
714 ColoredPrs3d_i::EPublishInStudyMode& thePublishInStudyMode)
716 TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
717 if(!aSelectionInfo.empty()){
718 TSelectionItem aSelectionItem = aSelectionInfo.front();
719 theIO = aSelectionItem.myIO;
720 theSObject = aSelectionItem.myObjectInfo.mySObject;
721 VISU::VISUType aType = VISU::Storable::SObject2Type(theSObject);
722 if (VISU::TTIMESTAMP == aType){
723 thePublishInStudyMode = ColoredPrs3d_i::EPublishUnderTimeStamp;
726 if (VISU::TFIELD == aType){
727 thePublishInStudyMode = ColoredPrs3d_i::EPublishIndependently;
728 if(theSObject->FindSubObject(2,theSObject))
732 SUIT_MessageBox::warning(GetDesktop(theModule),
733 QObject::tr("WRN_VISU"),
734 QObject::tr("WRN_NO_AVAILABLE_DATA") );
738 //------------------------------------------------------------
740 CheckResult(const SalomeApp_Module* theModule,
741 _PTR(SObject) theSource,
742 VISU::Result_var& theResult)
744 if(theSource->Depth() < 3) // Bug of SALOMEDS : can\t get father from root object
747 _PTR(SObject) aSObj = theSource->GetFather();
751 aSObj = aSObj->GetFather();
755 aSObj = aSObj->GetFather();
759 CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
760 if (CORBA::is_nil(anObject)) {
761 aSObj = aSObj->GetFather();
764 anObject = VISU::ClientSObjectToObject(aSObj);
767 if (CORBA::is_nil(anObject))
770 theResult = VISU::Result::_narrow(anObject);
771 return dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
774 //------------------------------------------------------------
777 PublishMeshInView(const SalomeApp_Module* theModule,
778 VISU::Prs3d_i* thePrs,
779 SVTK_ViewWindow* theViewWindow)
781 VISU_Actor* aActor = NULL;
782 if (!thePrs || !theViewWindow)
785 QApplication::setOverrideCursor( Qt::WaitCursor );
787 if ((aActor = thePrs->CreateActor()))
788 theViewWindow->AddActor(aActor);
789 } catch(std::exception& exc) {
790 SUIT_MessageBox::warning
791 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
792 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()) );
794 QApplication::restoreOverrideCursor();
799 //------------------------------------------------------------
801 RepaintViewWindows (const SalomeApp_Module* theModule,
802 const Handle(SALOME_InteractiveObject)& theIObject)
804 TViewWindows aViewWindows;
805 if (SalomeApp_Application* anApp = theModule->getApp()) {
806 ViewManagerList aViewManagerList;
807 anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
808 QList<SUIT_ViewManager*>::Iterator anIter = aViewManagerList.begin();
809 while ( anIter != aViewManagerList.end() )
811 QVector<SUIT_ViewWindow*> aViews = (*anIter)->getViews();
812 for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
813 if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
814 if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
815 if (vw->isVisible(theIObject)) {
816 vw->getRenderer()->ResetCameraClippingRange();
818 vw->highlight(theIObject, true, true);
828 //------------------------------------------------------------
830 FindActor(const SalomeApp_Study* theStudy,
831 SVTK_ViewWindow* theViewWindow,
832 const QString& theEntry)
834 TObjectInfo anObjectInfo = GetObjectByEntry(theStudy, theEntry.toLatin1().data());
835 VISU::Prs3d_i* aPrs3d = GetPrs3dFromBase(anObjectInfo.myBase);
836 return FindActor(theViewWindow, aPrs3d);
839 //------------------------------------------------------------
841 FindActorBase(const SalomeApp_Study* theStudy,
842 SVTK_ViewWindow* theViewWindow,
843 const QString& theEntry)
845 TObjectInfo anObjectInfo = GetObjectByEntry(theStudy, theEntry.toLatin1().constData());
846 VISU::PointMap3d_i* aTable = dynamic_cast<VISU::PointMap3d_i*>(anObjectInfo.myBase);
847 return FindActorBase(theViewWindow, aTable);
850 //------------------------------------------------------------
852 RecreateActor (const SalomeApp_Module* theModule,
853 VISU::Prs3d_i* thePrs)
855 QApplication::setOverrideCursor(Qt::WaitCursor);
857 /* SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
858 CORBA::String_var anEntry = aSObject->GetID();*/
861 thePrs->UpdateActors();
862 } catch (std::runtime_error& exc) {
864 QApplication::restoreOverrideCursor();
865 SUIT_MessageBox::warning
866 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
867 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()) );
869 thePrs->RemoveActors();
872 QApplication::restoreOverrideCursor();
875 //------------------------------------------------------------
877 ComputeVisiblePropBounds(SVTK_ViewWindow* theViewWindow,
878 vtkFloatingPointType allBounds[6],
879 const char* theActorClassName)
881 vtkRenderer *aRen = theViewWindow->getRenderer();
882 VTK::ActorCollectionCopy aCopy(aRen->GetActors());
883 vtkActorCollection *anActColl = aCopy.GetActors();
885 vtkFloatingPointType *bounds;
886 int somethingVisible = false;
888 allBounds[0] = allBounds[2] = allBounds[4] = VTK_LARGE_FLOAT;
889 allBounds[1] = allBounds[3] = allBounds[5] = -VTK_LARGE_FLOAT;
890 // loop through all props
891 for (anActColl->InitTraversal(); (prop = anActColl->GetNextProp()); ) {
892 // if it's invisible, or has no geometry, we can skip the rest
893 if (prop->GetVisibility() && prop->IsA(theActorClassName)) {
894 bounds = prop->GetBounds();
895 // make sure we haven't got bogus bounds
896 if (bounds != NULL &&
897 bounds[0] > -VTK_LARGE_FLOAT && bounds[1] < VTK_LARGE_FLOAT &&
898 bounds[2] > -VTK_LARGE_FLOAT && bounds[3] < VTK_LARGE_FLOAT &&
899 bounds[4] > -VTK_LARGE_FLOAT && bounds[5] < VTK_LARGE_FLOAT)
901 somethingVisible = true;
902 if (bounds[0] < allBounds[0]) allBounds[0] = bounds[0];
903 if (bounds[1] > allBounds[1]) allBounds[1] = bounds[1];
904 if (bounds[2] < allBounds[2]) allBounds[2] = bounds[2];
905 if (bounds[3] > allBounds[3]) allBounds[3] = bounds[3];
906 if (bounds[4] < allBounds[4]) allBounds[4] = bounds[4];
907 if (bounds[5] > allBounds[5]) allBounds[5] = bounds[5];
911 return somethingVisible;
914 //------------------------------------------------------------
915 void SetFitAll(SVTK_ViewWindow* theViewWindow)
917 static vtkFloatingPointType PRECISION = 0.000001;
918 static vtkFloatingPointType DEVIATION = 600;
919 vtkFloatingPointType XYZ_Bnd[6];
920 if (!ComputeVisiblePropBounds(theViewWindow, XYZ_Bnd)) return;
922 vtkFloatingPointType absX = XYZ_Bnd[1] - XYZ_Bnd[0];
923 vtkFloatingPointType absY = XYZ_Bnd[3] - XYZ_Bnd[2];
924 vtkFloatingPointType absZ = XYZ_Bnd[5] - XYZ_Bnd[4];
926 enum CameraOrient {e3D, eFront, eLeft, eTop};
927 CameraOrient aCameraOrient = e3D;
928 if (absX <= PRECISION) aCameraOrient = eFront;
930 if (absY <= PRECISION) aCameraOrient = eLeft;
932 if (absZ <= PRECISION) aCameraOrient = eTop;
934 // all the three dimensions exceeds precision
935 vtkFloatingPointType dev_abs_XY = absX / absY;
936 vtkFloatingPointType dev_abs_YZ = absY / absZ;
937 vtkFloatingPointType dev_abs_XZ = absX / absZ;
938 if (dev_abs_XY >= DEVIATION || 1./dev_abs_YZ >= DEVIATION)
939 aCameraOrient = eLeft;
941 if (1./dev_abs_XY >= DEVIATION || 1./dev_abs_XZ >= DEVIATION)
942 aCameraOrient = eFront;
944 if (dev_abs_XZ >= DEVIATION || dev_abs_YZ >= DEVIATION)
945 aCameraOrient = eTop;
952 switch (aCameraOrient) {
953 case eFront: theViewWindow->onFrontView(); break;
954 case eLeft: theViewWindow->onLeftView(); break;
955 case eTop: theViewWindow->onTopView(); break;
956 case e3D: theViewWindow->onResetView(); break;
958 theViewWindow->getRenderer()->ResetCameraClippingRange();
959 theViewWindow->onFitAll();
962 //************************************************************
966 GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate)
968 if(SalomeApp_Application* anApp = theModule->getApp()){
969 if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){
970 return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
976 //------------------------------------------------------------
978 PlotTable(const SalomeApp_Module* theModule,
979 VISU::Table_i* table,
982 SalomeApp_Study* aStudy = GetAppStudy( theModule );
986 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
989 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
993 // implementation moved to VISU_I package (see VISU_Tools.h)
994 VISU::PlotTable( aStudy, aPlot, table, theDisplaying );
997 //------------------------------------------------------------
999 PlotCurve(const SalomeApp_Module* theModule,
1000 VISU::Curve_i* theCurve,
1003 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1006 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1010 // implementation moved to VISU_I package (see VISU_Tools.h)
1011 VISU::PlotCurve( aPlot, theCurve, theDisplaying );
1014 //------------------------------------------------------------
1016 PlotRemoveCurve(const SalomeApp_Module* theModule,
1017 VISU::Curve_i* pCrv)
1019 // implementation moved to VISU_I package (see VISU_Tools.h)
1020 VISU::PlotRemoveCurve( theModule->getApp(), pCrv );
1023 //------------------------------------------------------------
1025 PlotContainer(const SalomeApp_Module* theModule,
1026 VISU::Container_i* container,
1029 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1032 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1036 // implementation moved to VISU_I package (see VISU_Tools.h)
1037 VISU::PlotContainer( aPlot, container, theDisplaying );
1040 //------------------------------------------------------------
1042 CreatePlot(SalomeApp_Module* theModule,
1043 _PTR(SObject) theTableSO)
1045 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1048 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1052 VISU::VISU_Gen_i* aVisuGen = VISU::GetVisuGen( theModule );
1054 // implementation moved to VISU_I package (see VISU_Tools.h)
1055 VISU::CreatePlot( aVisuGen, aPlot, theTableSO );
1058 //************************************************************
1061 CreateMesh(VisuGUI* theModule,
1062 const Handle(SALOME_InteractiveObject)& theIO,
1063 SVTK_ViewWindow* theViewWindow)
1065 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
1066 //if (CheckLock(aStudy))
1069 _PTR(SObject) aResultSObj = aStudy->FindObjectID(theIO->getEntry());
1072 VISU::Result_var aResult;
1073 VISU::Result_i* pResult = CheckResult(theModule, aResultSObj, aResult);
1074 if (pResult == NULL)
1077 Storable::TRestoringMap aMap = Storable::GetStorableMap(aResultSObj);
1081 CORBA::Object_var aMesh;
1082 string aComment = Storable::FindValue(aMap,"myComment").toLatin1().data();
1083 string aMeshName = Storable::FindValue(aMap,"myMeshName").toLatin1().data();
1088 if (aComment == "ENTITY") {
1089 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myId").toInt();
1090 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity))
1091 aMesh = GetVisuGen(theModule)->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
1092 } else if (aComment == "FAMILY") {
1093 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myEntityId").toInt();
1094 string aFamilyName = Storable::FindValue(aMap,"myName").toLatin1().data();
1095 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()))
1096 aMesh = GetVisuGen(theModule)->FamilyMeshOnEntity
1097 (aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
1098 } else if (aComment == "GROUP") {
1099 string aGroupName = Storable::FindValue(aMap,"myName").toLatin1().data();
1100 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str()))
1101 aMesh = GetVisuGen(theModule)->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
1105 MESSAGE("VisuGUI::CreateMesh() - CREATE MESH");
1109 //QApplication::restoreOverrideCursor();
1110 VISU::Mesh_i* pPresent = NULL;
1111 if (!CORBA::is_nil(aMesh))
1112 pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
1113 if (pPresent == NULL) {
1114 SUIT_MessageBox::warning (GetDesktop(theModule),
1115 QObject::tr("WRN_VISU"),
1116 QObject::tr("ERR_CANT_BUILD_PRESENTATION") );
1120 if (theViewWindow) {
1126 if(GetResourceMgr()->booleanValue("VISU","display_only",false)){
1127 const VisuGUI* av = dynamic_cast<const VisuGUI*>(theModule);
1128 if(av)(const_cast<VisuGUI*>(av))->OnEraseAll();
1130 PublishMeshInView(theModule, pPresent, theViewWindow);
1131 if(GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false)){
1132 SetFitAll(theViewWindow);
1136 MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
1139 } catch (std::runtime_error& exc) {
1141 SUIT_MessageBox::warning(GetDesktop(theModule), QObject::tr("WRN_VISU"),
1142 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()) );
1146 UpdateObjBrowser(theModule, false, aResultSObj);
1148 theModule->application()->putInfo(QObject::tr("INF_DONE"));
1149 // Make "Save" button active
1150 theModule->getApp()->updateActions();
1154 // ========================================================================================
1155 // GetPrs3dList: find list of presentations for the given object
1156 // ========================================================================================
1157 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1158 const Handle(SALOME_InteractiveObject)& theIO,
1161 std::vector<VISU::Prs3d_i*> aList;
1162 if (!theIO.IsNull() && theIO->hasEntry()) {
1163 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1164 _PTR(SObject) aSObject = aCStudy->FindObjectID(theIO->getEntry());
1165 aList = GetPrs3dList(theModule, aSObject, theGP);
1170 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1171 _PTR(SObject) theObject,
1174 std::vector<VISU::Prs3d_i*> aList; int k = 0;
1178 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1180 CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(theObject);
1181 if (!CORBA::is_nil(aCORBAObject)) {
1182 VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
1183 if (!CORBA::is_nil(aVisuObj)) {
1184 VISU::VISUType aType = aVisuObj->GetType();
1186 case VISU::TGAUSSPOINTS:
1187 if ( !theGP ) break;
1188 case VISU::TSCALARMAP:
1189 case VISU::TISOSURFACES:
1190 case VISU::TDEFORMEDSHAPE:
1191 case VISU::TCUTPLANES:
1192 case VISU::TCUTLINES:
1193 case VISU::TCUTSEGMENT:
1194 case VISU::TVECTORS:
1195 case VISU::TSTREAMLINES:
1197 case VISU::TSCALARMAPONDEFORMEDSHAPE:
1198 case VISU::TDEFORMEDSHAPEANDSCALARMAP:
1201 PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1202 if (aServant.in()) {
1203 VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
1205 aList[k] = aPrsObject;
1212 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1213 _PTR(SObject) aTimeStamp;
1214 anIter->Next(); // First is reference on support
1215 for (; anIter->More(); anIter->Next()) {
1216 aTimeStamp = anIter->Value();
1217 if (!aTimeStamp) continue;
1218 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1219 if (!aSubList.empty()) {
1220 int n = aSubList.size();
1222 for (int i = 0; i < n; i++) {
1223 aList[k] = aSubList[i];
1230 case VISU::TCOLOREDPRS3DHOLDER:
1232 PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1233 if (aServant.in()) {
1234 VISU::ColoredPrs3dHolder_i* aPrsHolderObject = dynamic_cast<VISU::ColoredPrs3dHolder_i*>(aServant.in());
1235 if( aPrsHolderObject ) {
1236 VISU::Prs3d_i* aPrsObject = aPrsHolderObject->GetPrs3dDevice();
1238 aList[k] = aPrsObject;
1246 VISU::VISUType aType = VISU::Storable::SObject2Type(theObject);
1248 case VISU::TFIELD: {
1249 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1250 _PTR(SObject) aTimeStamp;
1251 anIter->Next(); // First is reference on support
1252 for (; anIter->More(); anIter->Next()) {
1253 aTimeStamp = anIter->Value();
1254 if (!aTimeStamp) continue;
1255 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1256 if (!aSubList.empty()) {
1257 int n = aSubList.size();
1259 for (int i = 0; i < n; i++) {
1260 aList[k] = aSubList[i];
1267 case VISU::TTIMESTAMP: {
1268 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1270 for (; anIter->More(); anIter->Next()) {
1271 aPrs = anIter->Value();
1272 if (!aPrs) continue;
1273 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
1274 if (!aSubList.empty()) {
1275 int n = aSubList.size();
1277 for (int i = 0; i < n; i++) {
1278 aList[k] = aSubList[i];
1289 //------------------------------------------------------------
1290 int GetFreePositionOfDefaultScalarBar(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow)
1293 std::set<int> aIndexes;
1294 TViewToPrs3d aMap = theModule->getScalarBarsMap();
1295 TViewToPrs3d::const_iterator aViewToPrsIter = aMap.find(theViewWindow);
1296 if (aViewToPrsIter != aMap.end()) {
1297 TSetPrs3d::const_iterator aPrsIter = (aViewToPrsIter->second).begin();
1298 for (; aPrsIter != (aViewToPrsIter->second).end(); aPrsIter++) {
1299 aIndexes.insert((*aPrsIter).second);
1302 std::set<int>::const_iterator aIter = aIndexes.begin();
1303 for (int i = 1,length = aIndexes.size(); i <= length; i++) {
1304 std::set<int>::const_iterator aIter = aIndexes.find(i);
1305 if (aIter == aIndexes.end()) { minIndx = i; break; }
1306 else minIndx = i + 1;
1311 //------------------------------------------------------------
1312 void AddScalarBarPosition (VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1313 VISU::Prs3d_i* thePrs3d, int pos)
1315 TViewToPrs3d& aMap = theModule->getScalarBarsMap();
1316 TPrs3dToInd aPair; aPair.first = thePrs3d; aPair.second = pos;
1317 aMap[theViewWindow].insert(aPair);
1320 //------------------------------------------------------------
1321 void RemoveScalarBarPosition(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1322 VISU::Prs3d_i* thePrs3d)
1324 TViewToPrs3d& aMap = theModule->getScalarBarsMap();
1325 TSetPrs3d::iterator aIter = aMap[theViewWindow].begin();
1326 for (; aIter != aMap[theViewWindow].end(); aIter++)
1327 if ((*aIter).first == thePrs3d) {
1328 aMap[theViewWindow].erase(*aIter);
1332 //------------------------------------------------------------
1333 bool getClippingPlanesFolder(_PTR(Study) theStudy, _PTR(SObject)& theSObject)
1335 _PTR(SComponent) aVisuSO = theStudy->FindComponent("VISU");
1336 if (!aVisuSO) return false;
1337 _PTR(SObject) aFolder = theStudy->FindObject(CLIP_PLANES_FOLDER);
1339 _PTR(StudyBuilder) aBuilder = theStudy->NewBuilder();
1340 aFolder = aBuilder->NewObject(aVisuSO);
1342 _PTR(GenericAttribute) anAttr;
1343 anAttr = aBuilder->FindOrCreateAttribute(aFolder,"AttributeName");
1344 _PTR(AttributeName) aName(anAttr);
1345 aName->SetValue(CLIP_PLANES_FOLDER);
1347 theSObject = aFolder;
1351 //------------------------------------------------------------
1352 void initSpinBox( SalomeApp_IntSpinBox* sb,
1357 sb->setAcceptNames( false );
1358 sb->setRange( bottom, top );
1359 sb->setSingleStep( step );
1362 //------------------------------------------------------------
1363 void initSpinBox( SalomeApp_DoubleSpinBox* sb,
1364 const double& bottom,
1367 const char* quantity )
1369 // Obtain precision from preferences
1370 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1371 int precision = resMgr->integerValue( "VISU", quantity, 3 );
1373 sb->setPrecision ( precision );
1374 sb->setDecimals ( qAbs(precision) );
1375 sb->setRange ( bottom, top );
1376 sb->setSingleStep ( step );
1377 sb->setDefaultValue( bottom );
1378 sb->setAcceptNames ( false );
1380 // Add a hint for the user saying how to tune precision
1381 QString userPropName = QObject::tr( QString( "VISU_PREF_%1" ).arg( quantity ).toLatin1().constData() );
1382 sb->setProperty( "validity_tune_hint",
1383 QVariant( QObject::tr( "VISU_PRECISION_HINT" ).arg( userPropName ) ) );