1 // Copyright (C) 2007-2013 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::EngineComponent_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());
243 //------------------------------------------------------------
244 SALOME_MED::MED_Gen_var
247 static SALOME_MED::MED_Gen_var aGen;
248 if(CORBA::is_nil(aGen)){
249 SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
250 Engines::EngineComponent_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","MED");
251 aGen = SALOME_MED::MED_Gen::_narrow(aComponent);
253 if(CORBA::is_nil(aGen))
254 throw std::runtime_error(QObject::tr("ERR_CANT_FIND_MED_COMPONENT").toLatin1().data());
257 #endif // WITH_MEDGEN
259 //----------------------------------------------------------------------------
262 GetSelectedObjects(const SalomeApp_Module* theModule)
264 TSelectionInfo aSelectionInfo;
265 const SalomeApp_Study* aStudy = GetAppStudy(theModule);
266 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
267 if ( aStudy && aSelectionMgr ) {
268 SALOME_ListIO aListIO;
269 aSelectionMgr->selectedObjects(aListIO);
270 SALOME_ListIteratorOfListIO anIter(aListIO);
273 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
276 TObjectInfo anObjectInfo = GetObjectByEntry(aStudy, anIO->getEntry());
277 if(anObjectInfo.mySObject){
278 TSelectionItem aSelectionItem;
279 aSelectionItem.myObjectInfo = anObjectInfo;
280 aSelectionItem.myIO = anIO;
281 aSelectionInfo.push_back(aSelectionItem);
284 anIter.Next(); // MULTIPR fixed
287 return aSelectionInfo;
290 //----------------------------------------------------------------------------
292 GetObjectByEntry(const SalomeApp_Study* theStudy,
293 const std::string& theEntry)
295 TObjectInfo anObjectInfo;
296 if(!theStudy || theEntry == "")
299 _PTR(Study) aStudy = GetCStudy(theStudy);
300 if(_PTR(SObject) aSObject = aStudy->FindObjectID(theEntry)){
301 anObjectInfo.mySObject = aSObject;
302 CORBA::Object_var anObject = ClientSObjectToObject(aSObject);
303 if(VISU::Base_i* aBase = GetServantInterface<VISU::Base_i>(anObject))
304 anObjectInfo.myBase = aBase;
311 //----------------------------------------------------------------------------
313 GetPrs3dToModify(const SalomeApp_Module* theModule,
316 if (CheckLock(GetCStudy(GetAppStudy(theModule)), GetDesktop(theModule)))
319 return GetPrs3dFromBase(theBase);
322 //----------------------------------------------------------------------------
324 GetPrs3dFromBase(Base_i* theBase)
326 if(theBase && theBase->GetType() == VISU::TCOLOREDPRS3DHOLDER){
327 CORBA::Object_var anObject = theBase->_this();
328 VISU::ColoredPrs3dHolder_var aHolder = VISU::ColoredPrs3dHolder::_narrow(anObject);
329 VISU::Prs3d_var aPrs3d = aHolder->GetDevice();
330 return VISU::GetServantInterface<VISU::Prs3d_i>(aPrs3d);
332 return dynamic_cast<VISU::Prs3d_i*>(theBase);
336 //----------------------------------------------------------------------------
338 GetPrs3dSelectionInfo(const SalomeApp_Module* theModule,
339 VISU::Prs3d_i*& thePrs3d,
340 SVTK_ViewWindow*& theViewWindow,
341 VISU_Actor*& thenActor)
343 VISU::TSelectionInfo aSelectionInfo = VISU::GetSelectedObjects(theModule);
344 if(aSelectionInfo.empty())
347 VISU::TSelectionItem aSelectionItem = aSelectionInfo.front();
348 thePrs3d = GetPrs3dFromBase(aSelectionItem.myObjectInfo.myBase);
352 theViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
356 thenActor = FindActor(theViewWindow, thePrs3d);
364 //----------------------------------------------------------------------------
366 Add(LightApp_SelectionMgr* theSelectionMgr,
367 const Handle(SALOME_InteractiveObject)& theIO)
369 SALOME_ListIO aListIO;
370 theSelectionMgr->selectedObjects(aListIO);
371 aListIO.Append(theIO);
372 theSelectionMgr->setSelectedObjects(aListIO);
375 //------------------------------------------------------------
377 Remove(LightApp_SelectionMgr* theSelectionMgr,
378 const Handle(SALOME_InteractiveObject)& theIO)
380 if (theIO.IsNull()) return;
381 SALOME_ListIO aListIO, aNewListIO;
382 theSelectionMgr->selectedObjects(aListIO);
383 SALOME_ListIteratorOfListIO anIter (aListIO);
384 for (; anIter.More(); anIter.Next()) {
385 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
386 if (!anIO->isSame(theIO)) {
387 aNewListIO.Append(theIO);
390 theSelectionMgr->setSelectedObjects(aNewListIO);
394 * \brief Check, if the object can be deleted
396 * \param theEntry - entry of the object to check
397 * \param theModule - is used to access Study and VISU_Gen
398 * \retval bool - returns TRUE if the object is removable
401 IsRemovable (const std::string theEntry,
402 const SalomeApp_Module* theModule)
404 // asv : if selected object is a Save Point object selected in object browser - return false
405 if ( QString( theEntry.c_str() ).startsWith( QObject::tr( "SAVE_POINT_DEF_NAME" ) ) )
408 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
410 _PTR(SObject) aSObject = aStudy->FindObjectID(theEntry);
411 VISU::Storable::TRestoringMap pMap;
413 CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(aSObject);
414 if (!CORBA::is_nil(aCORBAObject)) {
415 VISU::RemovableObject_var aRemovableObj = VISU::RemovableObject::_narrow(aCORBAObject);
416 if (CORBA::is_nil(aRemovableObj)) {
417 // Not removable CORBA object
421 // Can be removed, if lays directly under VISU
422 // (first sub-level) or is a child of such an object
423 string aNAME, aVisuNAME = GetVisuGen(theModule)->ComponentDataType();
424 _PTR(GenericAttribute) anAttr;
425 _PTR(AttributeString) aComment;
427 _PTR(SObject) aRefSObject;
428 if (aSObject->ReferencedObject(aRefSObject)) {
429 // It can be a reference on curve, published under a container. IPAL 20317
430 VISU::TObjectInfo aRefObjectInfo = GetObjectByEntry(GetAppStudy(theModule), aRefSObject->GetID());
431 VISU::Base_i* aRefBase = aRefObjectInfo.myBase;
432 if( (aRefBase && aRefBase->GetType() == VISU::TCURVE) || (aRefBase && aRefBase->GetType() == VISU::TMESH) )
436 bool isUnderVISU = false;
437 _PTR(SObject) aFatherSObject = aSObject->GetFather();
438 if (aFatherSObject->FindAttribute(anAttr, "AttributeName")) {
439 // mkr : 24.11.2006 : use AttributeName and module title for correct "Delete"
440 // popup item displaying in object browser popup
441 _PTR(AttributeName) aComment (anAttr);
442 aNAME = aComment->Value();
443 QString aVisuTITLE = theModule->getApp()->moduleTitle(aVisuNAME.c_str());
444 if (!aVisuTITLE.compare(aNAME.c_str())) {
449 // Not directly under VISU component, check father
450 aCORBAObject = VISU::ClientSObjectToObject(aFatherSObject);
451 if (!CORBA::is_nil(aCORBAObject)) {
457 aFatherSObject = aFatherSObject->GetFather();
458 if (aFatherSObject->FindAttribute(anAttr, "AttributeString")) {
459 _PTR(AttributeString) aComment (anAttr);
460 aNAME = aComment->Value();
461 if (aNAME == aVisuNAME) {
466 // Father is not directly under VISU component
476 * \brief Check, if "Delete" popup-menu can be put on current selection
478 * \param theModule - is used to access SelectionManager, Study and VISU_Gen
479 * \retval bool - returns TRUE if all currently selected objects are removable
482 IsRemovableSelected (const SalomeApp_Module* theModule)
484 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
485 SALOME_ListIO aListIO;
486 aSelectionMgr->selectedObjects(aListIO);
488 if (aListIO.Extent() < 1)
491 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
492 if (!aStudy) return false;
494 SALOME_ListIteratorOfListIO anIter (aListIO);
495 for (; anIter.More(); anIter.Next()) {
496 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
497 if (anIO->hasEntry()) {
498 if (!IsRemovable(anIO->getEntry(), theModule))
505 //------------------------------------------------------------
507 DeleteSObject(VisuGUI* theModule,
508 _PTR(Study) theStudy,
509 _PTR(SObject) theSObject)
511 _PTR(ChildIterator) aChildIter = theStudy->NewChildIterator(theSObject);
512 for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
513 _PTR(SObject) aSObject = aChildIter->Value();
514 TObjectInfo anObjectInfo = GetObjectByEntry(GetAppStudy(theModule), aSObject->GetID());
515 ErasePrs(theModule, anObjectInfo.myBase, /*repaint_view_window = */false);
518 TObjectInfo anObjectInfo = GetObjectByEntry(GetAppStudy(theModule), theSObject->GetID());
519 if(anObjectInfo.myBase){
520 ErasePrs(theModule, anObjectInfo.myBase, /*repaint_view_window = */true);
522 CORBA::Object_var anObject = ClientSObjectToObject(theSObject);
523 VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObject);
524 if (!CORBA::is_nil(aRemovableObject)) {
525 aRemovableObject->RemoveFromStudy();
528 // Remove aSObject together with all its sub-objects
529 VISU::RemoveFromStudy(theSObject,
530 false, // remove not only IOR attribute, but Object With Children
531 false); // not UnRegister() sub-objects
535 //------------------------------------------------------------
537 DeletePrs3d(VisuGUI* theModule,
538 VISU::Prs3d_i* thePrs)
543 if (CheckLock(GetCStudy(GetAppStudy(theModule)),GetDesktop(theModule)))
546 if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule))
547 RemoveScalarBarPosition(theModule, aViewWindow, thePrs);
549 if(VISU::ColoredPrs3d_i* aColoredPrs3d = dynamic_cast<VISU::ColoredPrs3d_i*>(thePrs)){
550 std::string anEntry = aColoredPrs3d->GetHolderEntry();
552 VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(GetAppStudy(theModule), anEntry);
553 if(VISU::Base_i* aBase = anObjectInfo.myBase){
554 if(aBase->GetType() == VISU::TCOLOREDPRS3DHOLDER){
555 CORBA::Object_var anObject = aBase->_this();
556 VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObject);
557 aRemovableObject->RemoveFromStudy();
564 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* anActor = NULL;
782 if (!thePrs || !theViewWindow)
785 SalomeApp_Application *anApp = dynamic_cast<SalomeApp_Application*>(theModule->application());
789 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
795 QApplication::setOverrideCursor( Qt::WaitCursor );
797 if ((anActor = thePrs->CreateActor())) {
798 theViewWindow->AddActor(anActor);
800 if(anActor->hasIO() && anActor->getIO()->hasEntry())
801 aStudy->setVisibilityState(anActor->getIO()->getEntry(), Qtx::ShownState);
803 } catch(std::exception& exc) {
804 SUIT_MessageBox::warning
805 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
806 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()) );
808 QApplication::restoreOverrideCursor();
813 //------------------------------------------------------------
815 RepaintViewWindows (const SalomeApp_Module* theModule,
816 const Handle(SALOME_InteractiveObject)& theIObject)
818 TViewWindows aViewWindows;
819 if (SalomeApp_Application* anApp = theModule->getApp()) {
820 ViewManagerList aViewManagerList;
821 anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
822 QList<SUIT_ViewManager*>::Iterator anIter = aViewManagerList.begin();
823 while ( anIter != aViewManagerList.end() )
825 QVector<SUIT_ViewWindow*> aViews = (*anIter)->getViews();
826 for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
827 if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
828 if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
829 if (vw->isVisible(theIObject)) {
830 vw->getRenderer()->ResetCameraClippingRange();
832 vw->highlight(theIObject, true, true);
842 //------------------------------------------------------------
844 FindActor(const SalomeApp_Study* theStudy,
845 SVTK_ViewWindow* theViewWindow,
846 const QString& theEntry)
848 TObjectInfo anObjectInfo = GetObjectByEntry(theStudy, theEntry.toLatin1().data());
849 VISU::Prs3d_i* aPrs3d = GetPrs3dFromBase(anObjectInfo.myBase);
850 return FindActor(theViewWindow, aPrs3d);
853 //------------------------------------------------------------
855 FindActorBase(const SalomeApp_Study* theStudy,
856 SVTK_ViewWindow* theViewWindow,
857 const QString& theEntry)
859 TObjectInfo anObjectInfo = GetObjectByEntry(theStudy, theEntry.toLatin1().constData());
860 VISU::PointMap3d_i* aTable = dynamic_cast<VISU::PointMap3d_i*>(anObjectInfo.myBase);
861 return FindActorBase(theViewWindow, aTable);
864 //------------------------------------------------------------
866 RecreateActor (const SalomeApp_Module* theModule,
867 VISU::Prs3d_i* thePrs)
869 QApplication::setOverrideCursor(Qt::WaitCursor);
871 /* SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
872 CORBA::String_var anEntry = aSObject->GetID();*/
875 thePrs->UpdateActors();
876 } catch (std::runtime_error& exc) {
878 QApplication::restoreOverrideCursor();
879 SUIT_MessageBox::warning
880 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
881 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()) );
883 thePrs->RemoveActors();
886 QApplication::restoreOverrideCursor();
889 //------------------------------------------------------------
891 ComputeVisiblePropBounds(SVTK_ViewWindow* theViewWindow,
893 const char* theActorClassName)
895 vtkRenderer *aRen = theViewWindow->getRenderer();
896 VTK::ActorCollectionCopy aCopy(aRen->GetActors());
897 vtkActorCollection *anActColl = aCopy.GetActors();
900 int somethingVisible = false;
902 allBounds[0] = allBounds[2] = allBounds[4] = VTK_LARGE_FLOAT;
903 allBounds[1] = allBounds[3] = allBounds[5] = -VTK_LARGE_FLOAT;
904 // loop through all props
905 for (anActColl->InitTraversal(); (prop = anActColl->GetNextProp()); ) {
906 // if it's invisible, or has no geometry, we can skip the rest
907 if (prop->GetVisibility() && prop->IsA(theActorClassName)) {
908 bounds = prop->GetBounds();
909 // make sure we haven't got bogus bounds
910 if (bounds != NULL &&
911 bounds[0] > -VTK_LARGE_FLOAT && bounds[1] < VTK_LARGE_FLOAT &&
912 bounds[2] > -VTK_LARGE_FLOAT && bounds[3] < VTK_LARGE_FLOAT &&
913 bounds[4] > -VTK_LARGE_FLOAT && bounds[5] < VTK_LARGE_FLOAT)
915 somethingVisible = true;
916 if (bounds[0] < allBounds[0]) allBounds[0] = bounds[0];
917 if (bounds[1] > allBounds[1]) allBounds[1] = bounds[1];
918 if (bounds[2] < allBounds[2]) allBounds[2] = bounds[2];
919 if (bounds[3] > allBounds[3]) allBounds[3] = bounds[3];
920 if (bounds[4] < allBounds[4]) allBounds[4] = bounds[4];
921 if (bounds[5] > allBounds[5]) allBounds[5] = bounds[5];
925 return somethingVisible;
928 //------------------------------------------------------------
929 void SetFitAll(SVTK_ViewWindow* theViewWindow)
931 static double PRECISION = 0.000001;
932 static double DEVIATION = 600;
934 if (!ComputeVisiblePropBounds(theViewWindow, XYZ_Bnd)) return;
936 double absX = XYZ_Bnd[1] - XYZ_Bnd[0];
937 double absY = XYZ_Bnd[3] - XYZ_Bnd[2];
938 double absZ = XYZ_Bnd[5] - XYZ_Bnd[4];
940 enum CameraOrient {e3D, eFront, eLeft, eTop};
941 CameraOrient aCameraOrient = e3D;
942 if (absX <= PRECISION) aCameraOrient = eFront;
944 if (absY <= PRECISION) aCameraOrient = eLeft;
946 if (absZ <= PRECISION) aCameraOrient = eTop;
948 // all the three dimensions exceeds precision
949 double dev_abs_XY = absX / absY;
950 double dev_abs_YZ = absY / absZ;
951 double dev_abs_XZ = absX / absZ;
952 if (dev_abs_XY >= DEVIATION || 1./dev_abs_YZ >= DEVIATION)
953 aCameraOrient = eLeft;
955 if (1./dev_abs_XY >= DEVIATION || 1./dev_abs_XZ >= DEVIATION)
956 aCameraOrient = eFront;
958 if (dev_abs_XZ >= DEVIATION || dev_abs_YZ >= DEVIATION)
959 aCameraOrient = eTop;
966 switch (aCameraOrient) {
967 case eFront: theViewWindow->onFrontView(); break;
968 case eLeft: theViewWindow->onLeftView(); break;
969 case eTop: theViewWindow->onTopView(); break;
970 case e3D: theViewWindow->onResetView(); break;
972 theViewWindow->getRenderer()->ResetCameraClippingRange();
973 theViewWindow->onFitAll();
976 //************************************************************
980 GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate)
982 if(SalomeApp_Application* anApp = theModule->getApp()){
983 if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){
984 return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
990 //------------------------------------------------------------
992 PlotTable(const SalomeApp_Module* theModule,
993 VISU::Table_i* table,
996 SalomeApp_Study* aStudy = GetAppStudy( theModule );
1000 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
1003 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1007 // implementation moved to VISU_I package (see VISU_Tools.h)
1008 VISU::PlotTable( aStudy, aPlot, table, theDisplaying );
1011 //------------------------------------------------------------
1013 PlotCurve(const SalomeApp_Module* theModule,
1014 VISU::Curve_i* theCurve,
1017 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1020 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1024 // implementation moved to VISU_I package (see VISU_Tools.h)
1025 VISU::PlotCurve( aPlot, theCurve, theDisplaying );
1028 //------------------------------------------------------------
1030 PlotRemoveCurve(const SalomeApp_Module* theModule,
1031 VISU::Curve_i* pCrv)
1033 // implementation moved to VISU_I package (see VISU_Tools.h)
1034 VISU::PlotRemoveCurve( theModule->getApp(), pCrv );
1037 //------------------------------------------------------------
1039 PlotContainer(const SalomeApp_Module* theModule,
1040 VISU::Container_i* container,
1043 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1046 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1050 // implementation moved to VISU_I package (see VISU_Tools.h)
1051 VISU::PlotContainer( aPlot, container, theDisplaying );
1054 //------------------------------------------------------------
1056 CreatePlot(SalomeApp_Module* theModule,
1057 _PTR(SObject) theTableSO)
1059 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1062 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1066 VISU::VISU_Gen_i* aVisuGen = VISU::GetVisuGen( theModule );
1068 // implementation moved to VISU_I package (see VISU_Tools.h)
1069 VISU::CreatePlot( aVisuGen, aPlot, theTableSO );
1072 //************************************************************
1075 CreateMesh(VisuGUI* theModule,
1076 const Handle(SALOME_InteractiveObject)& theIO,
1077 SVTK_ViewWindow* theViewWindow)
1079 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
1080 //if (CheckLock(aStudy))
1083 _PTR(SObject) aResultSObj = aStudy->FindObjectID(theIO->getEntry());
1086 VISU::Result_var aResult;
1087 VISU::Result_i* pResult = CheckResult(theModule, aResultSObj, aResult);
1088 if (pResult == NULL)
1091 Storable::TRestoringMap aMap = Storable::GetStorableMap(aResultSObj);
1095 CORBA::Object_var aMesh;
1096 string aComment = Storable::FindValue(aMap,"myComment").toLatin1().data();
1097 string aMeshName = Storable::FindValue(aMap,"myMeshName").toLatin1().data();
1102 if (aComment == "ENTITY") {
1103 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myId").toInt();
1104 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity))
1105 aMesh = GetVisuGen(theModule)->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
1106 } else if (aComment == "FAMILY") {
1107 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myEntityId").toInt();
1108 string aFamilyName = Storable::FindValue(aMap,"myName").toLatin1().data();
1109 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()))
1110 aMesh = GetVisuGen(theModule)->FamilyMeshOnEntity
1111 (aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
1112 } else if (aComment == "GROUP") {
1113 string aGroupName = Storable::FindValue(aMap,"myName").toLatin1().data();
1114 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str()))
1115 aMesh = GetVisuGen(theModule)->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
1119 MESSAGE("VisuGUI::CreateMesh() - CREATE MESH");
1123 //QApplication::restoreOverrideCursor();
1124 VISU::Mesh_i* pPresent = NULL;
1125 if (!CORBA::is_nil(aMesh))
1126 pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
1127 if (pPresent == NULL) {
1128 SUIT_MessageBox::warning (GetDesktop(theModule),
1129 QObject::tr("WRN_VISU"),
1130 QObject::tr("ERR_CANT_BUILD_PRESENTATION") );
1134 if (theViewWindow) {
1140 if(GetResourceMgr()->booleanValue("VISU","display_only",false)){
1141 const VisuGUI* av = dynamic_cast<const VisuGUI*>(theModule);
1142 if(av)(const_cast<VisuGUI*>(av))->OnEraseAll();
1144 PublishMeshInView(theModule, pPresent, theViewWindow);
1145 if(GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false)){
1146 SetFitAll(theViewWindow);
1150 MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
1153 } catch (std::runtime_error& exc) {
1155 SUIT_MessageBox::warning(GetDesktop(theModule), QObject::tr("WRN_VISU"),
1156 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()) );
1160 UpdateObjBrowser(theModule, false, aResultSObj);
1162 theModule->application()->putInfo(QObject::tr("INF_DONE"));
1163 // Make "Save" button active
1164 theModule->getApp()->updateActions();
1168 // ========================================================================================
1169 // GetPrs3dList: find list of presentations for the given object
1170 // ========================================================================================
1171 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1172 const Handle(SALOME_InteractiveObject)& theIO,
1175 std::vector<VISU::Prs3d_i*> aList;
1176 if (!theIO.IsNull() && theIO->hasEntry()) {
1177 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1178 _PTR(SObject) aSObject = aCStudy->FindObjectID(theIO->getEntry());
1179 aList = GetPrs3dList(theModule, aSObject, theGP);
1184 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1185 _PTR(SObject) theObject,
1188 std::vector<VISU::Prs3d_i*> aList; int k = 0;
1192 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1194 CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(theObject);
1195 if (!CORBA::is_nil(aCORBAObject)) {
1196 VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
1197 if (!CORBA::is_nil(aVisuObj)) {
1198 VISU::VISUType aType = aVisuObj->GetType();
1200 case VISU::TGAUSSPOINTS:
1201 if ( !theGP ) break;
1202 case VISU::TSCALARMAP:
1203 case VISU::TISOSURFACES:
1204 case VISU::TDEFORMEDSHAPE:
1205 case VISU::TCUTPLANES:
1206 case VISU::TCUTLINES:
1207 case VISU::TCUTSEGMENT:
1208 case VISU::TVECTORS:
1209 case VISU::TSTREAMLINES:
1211 case VISU::TSCALARMAPONDEFORMEDSHAPE:
1212 case VISU::TDEFORMEDSHAPEANDSCALARMAP:
1215 PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1216 if (aServant.in()) {
1217 VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
1219 aList[k] = aPrsObject;
1226 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1227 _PTR(SObject) aTimeStamp;
1228 anIter->Next(); // First is reference on support
1229 for (; anIter->More(); anIter->Next()) {
1230 aTimeStamp = anIter->Value();
1231 if (!aTimeStamp) continue;
1232 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1233 if (!aSubList.empty()) {
1234 int n = aSubList.size();
1236 for (int i = 0; i < n; i++) {
1237 aList[k] = aSubList[i];
1244 case VISU::TCOLOREDPRS3DHOLDER:
1246 PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1247 if (aServant.in()) {
1248 VISU::ColoredPrs3dHolder_i* aPrsHolderObject = dynamic_cast<VISU::ColoredPrs3dHolder_i*>(aServant.in());
1249 if( aPrsHolderObject ) {
1250 VISU::Prs3d_i* aPrsObject = aPrsHolderObject->GetPrs3dDevice();
1252 aList[k] = aPrsObject;
1260 VISU::VISUType aType = VISU::Storable::SObject2Type(theObject);
1262 case VISU::TFIELD: {
1263 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1264 _PTR(SObject) aTimeStamp;
1265 anIter->Next(); // First is reference on support
1266 for (; anIter->More(); anIter->Next()) {
1267 aTimeStamp = anIter->Value();
1268 if (!aTimeStamp) continue;
1269 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1270 if (!aSubList.empty()) {
1271 int n = aSubList.size();
1273 for (int i = 0; i < n; i++) {
1274 aList[k] = aSubList[i];
1281 case VISU::TTIMESTAMP: {
1282 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1284 for (; anIter->More(); anIter->Next()) {
1285 aPrs = anIter->Value();
1286 if (!aPrs) continue;
1287 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
1288 if (!aSubList.empty()) {
1289 int n = aSubList.size();
1291 for (int i = 0; i < n; i++) {
1292 aList[k] = aSubList[i];
1303 //------------------------------------------------------------
1304 int GetFreePositionOfDefaultScalarBar(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow)
1307 std::set<int> aIndexes;
1308 TViewToPrs3d aMap = theModule->getScalarBarsMap();
1309 TViewToPrs3d::const_iterator aViewToPrsIter = aMap.find(theViewWindow);
1310 if (aViewToPrsIter != aMap.end()) {
1311 TSetPrs3d::const_iterator aPrsIter = (aViewToPrsIter->second).begin();
1312 for (; aPrsIter != (aViewToPrsIter->second).end(); aPrsIter++) {
1313 aIndexes.insert((*aPrsIter).second);
1316 std::set<int>::const_iterator aIter = aIndexes.begin();
1317 for (int i = 1,length = aIndexes.size(); i <= length; i++) {
1318 std::set<int>::const_iterator aIter = aIndexes.find(i);
1319 if (aIter == aIndexes.end()) { minIndx = i; break; }
1320 else minIndx = i + 1;
1325 //------------------------------------------------------------
1326 void AddScalarBarPosition (VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1327 VISU::Prs3d_i* thePrs3d, int pos)
1329 TViewToPrs3d& aMap = theModule->getScalarBarsMap();
1330 TPrs3dToInd aPair; aPair.first = thePrs3d; aPair.second = pos;
1331 aMap[theViewWindow].insert(aPair);
1334 //------------------------------------------------------------
1335 void RemoveScalarBarPosition(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1336 VISU::Prs3d_i* thePrs3d)
1338 TViewToPrs3d& aMap = theModule->getScalarBarsMap();
1339 TSetPrs3d::iterator aIter = aMap[theViewWindow].begin();
1340 for (; aIter != aMap[theViewWindow].end(); aIter++)
1341 if ((*aIter).first == thePrs3d) {
1342 aMap[theViewWindow].erase(*aIter);
1346 //------------------------------------------------------------
1347 bool getClippingPlanesFolder(_PTR(Study) theStudy, _PTR(SObject)& theSObject)
1349 _PTR(SComponent) aVisuSO = theStudy->FindComponent("VISU");
1350 if (!aVisuSO) return false;
1351 _PTR(SObject) aFolder = theStudy->FindObject(CLIP_PLANES_FOLDER);
1353 _PTR(StudyBuilder) aBuilder = theStudy->NewBuilder();
1354 aFolder = aBuilder->NewObject(aVisuSO);
1356 _PTR(GenericAttribute) anAttr;
1357 anAttr = aBuilder->FindOrCreateAttribute(aFolder,"AttributeName");
1358 _PTR(AttributeName) aName(anAttr);
1359 aName->SetValue(CLIP_PLANES_FOLDER);
1361 theSObject = aFolder;
1365 //------------------------------------------------------------
1366 void initSpinBox( SalomeApp_IntSpinBox* sb,
1371 sb->setAcceptNames( false );
1372 sb->setRange( bottom, top );
1373 sb->setSingleStep( step );
1376 //------------------------------------------------------------
1377 void initSpinBox( SalomeApp_DoubleSpinBox* sb,
1378 const double& bottom,
1381 const char* quantity )
1383 // Obtain precision from preferences
1384 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1385 int precision = resMgr->integerValue( "VISU", quantity, 3 );
1387 sb->setPrecision ( precision );
1388 sb->setDecimals ( qAbs(precision) );
1389 sb->setRange ( bottom, top );
1390 sb->setSingleStep ( step );
1391 sb->setDefaultValue( bottom );
1392 sb->setAcceptNames ( false );
1394 // Add a hint for the user saying how to tune precision
1395 QString userPropName = QObject::tr( QString( "VISU_PREF_%1" ).arg( quantity ).toLatin1().constData() );
1396 sb->setProperty( "validity_tune_hint",
1397 QVariant( QObject::tr( "VISU_PRECISION_HINT" ).arg( userPropName ) ) );