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_ColoredPrs3dHolder_i.hh"
37 #include "VISU_Gen_i.hh"
38 #include "VISU_Prs3d_i.hh"
39 #include "VISU_Result_i.hh"
40 #include "VISU_Table_i.hh"
41 //#include "VISU_Mesh_i.hh"
42 #include "VISU_ViewManager_i.hh"
44 #include "VISU_Actor.h"
45 #include "VISU_ScalarMapAct.h"
47 #include "SalomeApp_Module.h"
48 #include "SalomeApp_Study.h"
49 #include "SalomeApp_Application.h"
51 #include "LightApp_DataObject.h"
52 #include "LightApp_SelectionMgr.h"
55 //#include "OB_Browser.h"
57 #include "SALOME_ListIO.hxx"
58 #include "SALOME_ListIteratorOfListIO.hxx"
60 #include "SVTK_ViewWindow.h"
61 #include "SVTK_Functor.h"
63 #include "VTKViewer_Algorithm.h"
65 #include "SPlot2d_ViewModel.h"
66 #include "Plot2d_ViewFrame.h"
67 #include "Plot2d_ViewManager.h"
69 #include "SUIT_Session.h"
70 #include "SUIT_MessageBox.h"
71 #include "SUIT_Desktop.h"
72 #include "SUIT_ViewWindow.h"
74 #include "CAM_DataModel.h"
76 #include <vtkRenderer.h>
77 #include <vtkActorCollection.h>
81 #include <QDoubleSpinBox>
85 //=============================================================================
88 //------------------------------------------------------------
90 GetDesktop(const CAM_Module* theModule)
92 return theModule && theModule->application() ? theModule->application()->desktop() : 0;
95 //------------------------------------------------------------
96 LightApp_SelectionMgr*
97 GetSelectionMgr(const SalomeApp_Module* theModule)
99 return theModule && theModule->getApp() ? theModule->getApp()->selectionMgr() : 0;
102 //------------------------------------------------------------
104 GetAppStudy(const CAM_Module* theModule)
106 return theModule && theModule->application() ?
107 dynamic_cast<SalomeApp_Study*>(theModule->application()->activeStudy()) : 0;
110 //------------------------------------------------------------
112 GetCStudy(const SalomeApp_Study* theStudy)
114 return theStudy ? theStudy->studyDS() : _PTR(Study)();
117 //------------------------------------------------------------
119 IsStudyLocked( _PTR(Study) theStudy )
121 return theStudy ? theStudy->GetProperties()->IsLocked() : true;
124 //------------------------------------------------------------
126 CheckLock( _PTR(Study) theStudy,
129 if(IsStudyLocked(theStudy)){
130 SUIT_MessageBox::warning(theWidget,
131 QObject::tr("WRN_VISU_WARNING"),
132 QObject::tr("WRN_STUDY_LOCKED") );
138 //------------------------------------------------------------
140 runAndWait( QDialog* dlg, const bool modal )
142 VisuGUI_DialogRunner r( dlg );
143 return r.run( modal );
146 //------------------------------------------------------------
148 FindDataObject(SUIT_DataObject* theDataObject,
149 const QString& theEntry,
152 int aLevel = theDataObject->level() + 2;
153 QString aSourceEntry = theEntry.section(':',0,aLevel);
154 DataObjectList aList;
155 theDataObject->children(aList);
156 DataObjectList::Iterator aDataObjectIter = aList.begin();
157 while( aDataObjectIter!= aList.end() ) {
158 if(LightApp_DataObject* aChildDataObject = dynamic_cast<LightApp_DataObject*>(*aDataObjectIter)){
159 QString anEntry = aChildDataObject->entry();
160 QString aCurrentEntry = anEntry.section(':',0,aLevel);
161 if(aSourceEntry == aCurrentEntry){
162 if(theLevel == aLevel){
163 return aChildDataObject;
165 return FindDataObject(aChildDataObject,theEntry,theLevel);
174 //------------------------------------------------------------
176 FindDataObject(CAM_Module* theModule,
177 _PTR(SObject) theSObject)
179 CAM_DataModel* aDataModel = theModule->dataModel();
180 CAM_DataObject* aRootDataObject = aDataModel->root();
181 if(_PTR(SComponent) aComponent = theSObject)
182 return dynamic_cast<LightApp_DataObject*>(aRootDataObject);
184 int aLevel = theSObject->Depth();
185 std::string anEntry = theSObject->GetID();
186 return FindDataObject(aRootDataObject,anEntry.c_str(),aLevel);
189 //------------------------------------------------------------
191 UpdateObjBrowser(SalomeApp_Module* theModule,
192 bool theIsUpdateDataModel,
193 _PTR(SObject) theSObject)
195 LightApp_DataObject* aDataObject = NULL;
197 aDataObject = FindDataObject(theModule,theSObject);
199 theModule->updateObjBrowser(theIsUpdateDataModel,aDataObject);
200 theModule->getApp()->updateActions();
203 //------------------------------------------------------------
205 IsSObjectTable( _PTR(SObject) theSObject )
208 _PTR(GenericAttribute) anAttr;
209 if (theSObject->FindAttribute( anAttr, "AttributeTableOfInteger" ))
211 if (theSObject->FindAttribute( anAttr, "AttributeTableOfReal" ))
217 //------------------------------------------------------------
219 GetVisuGen(const CAM_Module* theModule)
221 static VISU_Gen_i* aGen = 0;
223 SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
224 Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","VISU");
225 VISU_Gen_var aVISU = VISU_Gen::_narrow(aComponent);
226 if(!CORBA::is_nil(aVISU))
227 aGen = VISU_Gen_i::GetVisuGenImpl();
231 aGen->SetCurrentStudy(GetDSStudy(GetCStudy(GetAppStudy(theModule))));
233 throw std::runtime_error(QObject::tr("ERR_CANT_FIND_VISU_COMPONENT").toLatin1().data());
237 //------------------------------------------------------------
238 SALOME_MED::MED_Gen_var
241 static SALOME_MED::MED_Gen_var aGen;
242 if(CORBA::is_nil(aGen)){
243 SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
244 Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","MED");
245 aGen = SALOME_MED::MED_Gen::_narrow(aComponent);
247 if(CORBA::is_nil(aGen))
248 throw std::runtime_error(QObject::tr("ERR_CANT_FIND_MED_COMPONENT").toLatin1().data());
253 //----------------------------------------------------------------------------
256 GetSelectedObjects(const SalomeApp_Module* theModule)
258 TSelectionInfo aSelectionInfo;
259 const SalomeApp_Study* aStudy = GetAppStudy(theModule);
260 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
261 if ( aStudy && aSelectionMgr ) {
262 SALOME_ListIO aListIO;
263 aSelectionMgr->selectedObjects(aListIO);
264 SALOME_ListIteratorOfListIO anIter(aListIO);
267 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
270 TObjectInfo anObjectInfo = GetObjectByEntry(aStudy, anIO->getEntry());
271 if(anObjectInfo.mySObject){
272 TSelectionItem aSelectionItem;
273 aSelectionItem.myObjectInfo = anObjectInfo;
274 aSelectionItem.myIO = anIO;
275 aSelectionInfo.push_back(aSelectionItem);
278 anIter.Next(); // MULTIPR fixed
281 return aSelectionInfo;
284 //----------------------------------------------------------------------------
286 GetObjectByEntry(const SalomeApp_Study* theStudy,
287 const std::string& theEntry)
289 TObjectInfo anObjectInfo;
290 if(!theStudy || theEntry == "")
293 _PTR(Study) aStudy = GetCStudy(theStudy);
294 if(_PTR(SObject) aSObject = aStudy->FindObjectID(theEntry)){
295 anObjectInfo.mySObject = aSObject;
296 CORBA::Object_var anObject = ClientSObjectToObject(aSObject);
297 if(VISU::Base_i* aBase = GetServantInterface<VISU::Base_i>(anObject))
298 anObjectInfo.myBase = aBase;
305 //----------------------------------------------------------------------------
307 GetPrs3dToModify(const SalomeApp_Module* theModule,
310 if (CheckLock(GetCStudy(GetAppStudy(theModule)), GetDesktop(theModule)))
313 return GetPrs3dFromBase(theBase);
316 //----------------------------------------------------------------------------
318 GetPrs3dFromBase(Base_i* theBase)
320 if(theBase && theBase->GetType() == VISU::TCOLOREDPRS3DHOLDER){
321 CORBA::Object_var anObject = theBase->_this();
322 VISU::ColoredPrs3dHolder_var aHolder = VISU::ColoredPrs3dHolder::_narrow(anObject);
323 VISU::Prs3d_var aPrs3d = aHolder->GetDevice();
324 return VISU::GetServantInterface<VISU::Prs3d_i>(aPrs3d);
326 return dynamic_cast<VISU::Prs3d_i*>(theBase);
330 //----------------------------------------------------------------------------
332 GetPrs3dSelectionInfo(const SalomeApp_Module* theModule,
333 VISU::Prs3d_i*& thePrs3d,
334 SVTK_ViewWindow*& theViewWindow,
335 VISU_Actor*& thenActor)
337 VISU::TSelectionInfo aSelectionInfo = VISU::GetSelectedObjects(theModule);
338 if(aSelectionInfo.empty())
341 VISU::TSelectionItem aSelectionItem = aSelectionInfo.front();
342 thePrs3d = GetPrs3dFromBase(aSelectionItem.myObjectInfo.myBase);
346 theViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
350 thenActor = FindActor(theViewWindow, thePrs3d);
358 //----------------------------------------------------------------------------
360 Add(LightApp_SelectionMgr* theSelectionMgr,
361 const Handle(SALOME_InteractiveObject)& theIO)
363 SALOME_ListIO aListIO;
364 theSelectionMgr->selectedObjects(aListIO);
365 aListIO.Append(theIO);
366 theSelectionMgr->setSelectedObjects(aListIO);
369 //------------------------------------------------------------
371 Remove(LightApp_SelectionMgr* theSelectionMgr,
372 const Handle(SALOME_InteractiveObject)& theIO)
374 if (theIO.IsNull()) return;
375 SALOME_ListIO aListIO, aNewListIO;
376 theSelectionMgr->selectedObjects(aListIO);
377 SALOME_ListIteratorOfListIO anIter (aListIO);
378 for (; anIter.More(); anIter.Next()) {
379 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
380 if (!anIO->isSame(theIO)) {
381 aNewListIO.Append(theIO);
384 theSelectionMgr->setSelectedObjects(aNewListIO);
388 * \brief Check, if the object can be deleted
390 * \param theEntry - entry of the object to check
391 * \param theModule - is used to access Study and VISU_Gen
392 * \retval bool - returns TRUE if the object is removable
395 IsRemovable (const std::string theEntry,
396 const SalomeApp_Module* theModule)
398 // asv : if selected object is a Save Point object selected in object browser - return false
399 if ( QString( theEntry.c_str() ).startsWith( QObject::tr( "SAVE_POINT_DEF_NAME" ) ) )
402 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
404 _PTR(SObject) aSObject = aStudy->FindObjectID(theEntry);
405 VISU::Storable::TRestoringMap pMap;
407 CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(aSObject);
408 if (!CORBA::is_nil(aCORBAObject)) {
409 VISU::RemovableObject_var aRemovableObj = VISU::RemovableObject::_narrow(aCORBAObject);
410 if (CORBA::is_nil(aRemovableObj)) {
411 // Not removable CORBA object
415 // Can be removed, if lays directly under VISU
416 // (first sub-level) or is a child of such an object
417 string aNAME, aVisuNAME = GetVisuGen(theModule)->ComponentDataType();
418 _PTR(GenericAttribute) anAttr;
419 _PTR(AttributeString) aComment;
421 _PTR(SObject) aRefSObject;
422 if (aSObject->ReferencedObject(aRefSObject)) {
423 // It can be a reference on curve, published under a container. IPAL 20317
424 VISU::TObjectInfo aRefObjectInfo = GetObjectByEntry(GetAppStudy(theModule), aRefSObject->GetID());
425 VISU::Base_i* aRefBase = aRefObjectInfo.myBase;
426 if( (aRefBase && aRefBase->GetType() == VISU::TCURVE) || (aRefBase && aRefBase->GetType() == VISU::TMESH) )
430 bool isUnderVISU = false;
431 _PTR(SObject) aFatherSObject = aSObject->GetFather();
432 if (aFatherSObject->FindAttribute(anAttr, "AttributeName")) {
433 // mkr : 24.11.2006 : use AttributeName and module title for correct "Delete"
434 // popup item displaying in object browser popup
435 _PTR(AttributeName) aComment (anAttr);
436 aNAME = aComment->Value();
437 QString aVisuTITLE = theModule->getApp()->moduleTitle(aVisuNAME.c_str());
438 if (!aVisuTITLE.compare(aNAME.c_str())) {
443 // Not directly under VISU component, check father
444 aCORBAObject = VISU::ClientSObjectToObject(aFatherSObject);
445 if (!CORBA::is_nil(aCORBAObject)) {
451 aFatherSObject = aFatherSObject->GetFather();
452 if (aFatherSObject->FindAttribute(anAttr, "AttributeString")) {
453 _PTR(AttributeString) aComment (anAttr);
454 aNAME = aComment->Value();
455 if (aNAME == aVisuNAME) {
460 // Father is not directly under VISU component
470 * \brief Check, if "Delete" popup-menu can be put on current selection
472 * \param theModule - is used to access SelectionManager, Study and VISU_Gen
473 * \retval bool - returns TRUE if all currently selected objects are removable
476 IsRemovableSelected (const SalomeApp_Module* theModule)
478 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
479 SALOME_ListIO aListIO;
480 aSelectionMgr->selectedObjects(aListIO);
482 if (aListIO.Extent() < 1)
485 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
486 if (!aStudy) return false;
488 SALOME_ListIteratorOfListIO anIter (aListIO);
489 for (; anIter.More(); anIter.Next()) {
490 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
491 if (anIO->hasEntry()) {
492 if (!IsRemovable(anIO->getEntry(), theModule))
499 //------------------------------------------------------------
501 DeleteSObject(VisuGUI* theModule,
502 _PTR(Study) theStudy,
503 _PTR(SObject) theSObject)
505 _PTR(ChildIterator) aChildIter = theStudy->NewChildIterator(theSObject);
506 for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
507 _PTR(SObject) aSObject = aChildIter->Value();
508 TObjectInfo anObjectInfo = GetObjectByEntry(GetAppStudy(theModule), aSObject->GetID());
509 ErasePrs(theModule, anObjectInfo.myBase, /*repaint_view_window = */false);
512 TObjectInfo anObjectInfo = GetObjectByEntry(GetAppStudy(theModule), theSObject->GetID());
513 if(anObjectInfo.myBase){
514 ErasePrs(theModule, anObjectInfo.myBase, /*repaint_view_window = */true);
516 CORBA::Object_var anObject = ClientSObjectToObject(theSObject);
517 VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObject);
518 if (!CORBA::is_nil(aRemovableObject)) {
519 aRemovableObject->RemoveFromStudy();
522 // Remove aSObject together with all its sub-objects
523 VISU::RemoveFromStudy(theSObject,
524 false, // remove not only IOR attribute, but Object With Children
525 false); // not Destroy() sub-objects
529 //------------------------------------------------------------
531 DeletePrs3d(VisuGUI* theModule,
532 VISU::Prs3d_i* thePrs)
537 if (CheckLock(GetCStudy(GetAppStudy(theModule)),GetDesktop(theModule)))
540 if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule))
541 RemoveScalarBarPosition(theModule, aViewWindow, thePrs);
543 if(VISU::ColoredPrs3d_i* aColoredPrs3d = dynamic_cast<VISU::ColoredPrs3d_i*>(thePrs)){
544 std::string anEntry = aColoredPrs3d->GetHolderEntry();
546 VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(GetAppStudy(theModule), anEntry);
547 if(VISU::Base_i* aBase = anObjectInfo.myBase){
548 if(aBase->GetType() == VISU::TCOLOREDPRS3DHOLDER){
549 CORBA::Object_var anObject = aBase->_this();
550 VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObject);
551 aRemovableObject->RemoveFromStudy();
558 thePrs->RemoveFromStudy();
562 //------------------------------------------------------------
563 // Presentation management
565 ChangeRepresentation (const SalomeApp_Module* theModule,
566 VISU::PresentationType theType)
568 TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
569 if(aSelectionInfo.empty())
572 VISU::Prs3d_i* aPrs3d;
573 VISU::PointMap3d_i* aTable;
575 VISU_ActorBase* anActorBase;
577 TSelectionItem aSelectionItem = aSelectionInfo.front();
578 aPrs3d = GetPrs3dFromBase(aSelectionItem.myObjectInfo.myBase);
580 aTable = dynamic_cast<VISU::PointMap3d_i*>(aSelectionItem.myObjectInfo.myBase);
585 SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
590 anActor = FindActor(aViewWindow, aPrs3d);
594 anActorBase = VISU::FindActorBase(aViewWindow, aTable);
603 if (anActor->IsShrunk()) {
608 anActor->SetShrink();
611 if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
612 aMesh->SetShrink(toShrink);
615 if (anActorBase->IsShrunk())
616 anActorBase->UnShrink();
618 anActorBase->SetShrink();
623 if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
624 aMesh->SetPresentationType(theType);
625 RecreateActor(theModule, aMesh);
627 anActor->SetRepresentation(theType);
631 anActorBase->SetRepresentation(theType);
634 aViewWindow->Repaint();
638 void ChangeQuadratic2DRepresentation (const SalomeApp_Module* theModule,
639 VISU::Quadratic2DPresentationType theType)
641 TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
642 if(aSelectionInfo.empty())
645 TSelectionItem aSelectionItem = aSelectionInfo.front();
647 VISU::Prs3d_i* aPrs3d = GetPrs3dFromBase(aSelectionItem.myObjectInfo.myBase);
649 SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
651 if(!aPrs3d || !aViewWindow)
654 VISU_Actor *anActor = FindActor(aViewWindow, aPrs3d);
658 if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
659 aMesh->SetQuadratic2DPresentationType(theType);
660 RecreateActor(theModule, aMesh);
664 anActor->SetQuadratic2DRepresentation(VISU_Actor::eLines);
667 anActor->SetQuadratic2DRepresentation(VISU_Actor::eArcs);
675 //------------------------------------------------------------
677 SetShading ( const SalomeApp_Module* theModule,
680 TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
681 if(aSelectionInfo.empty())
684 TSelectionItem aSelectionItem = GetSelectedObjects(theModule).front();
685 VISU::Prs3d_i* aPrs3d = GetPrs3dFromBase(aSelectionItem.myObjectInfo.myBase);
689 SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
693 VISU_Actor* anActor = FindActor(aViewWindow, aPrs3d);
697 if(VISU_ScalarMapAct* aScalarMapActor = dynamic_cast<VISU_ScalarMapAct*>(anActor)){
698 aScalarMapActor->SetShading(theOn);
699 aViewWindow->Repaint();
703 //------------------------------------------------------------
706 CheckTimeStamp(const SalomeApp_Module* theModule,
707 _PTR(SObject)& theSObject,
708 Handle(SALOME_InteractiveObject)& theIO,
709 ColoredPrs3d_i::EPublishInStudyMode& thePublishInStudyMode)
711 TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
712 if(!aSelectionInfo.empty()){
713 TSelectionItem aSelectionItem = aSelectionInfo.front();
714 theIO = aSelectionItem.myIO;
715 theSObject = aSelectionItem.myObjectInfo.mySObject;
716 VISU::VISUType aType = VISU::Storable::SObject2Type(theSObject);
717 if (VISU::TTIMESTAMP == aType){
718 thePublishInStudyMode = ColoredPrs3d_i::EPublishUnderTimeStamp;
721 if (VISU::TFIELD == aType){
722 thePublishInStudyMode = ColoredPrs3d_i::EPublishIndependently;
723 if(theSObject->FindSubObject(2,theSObject))
727 SUIT_MessageBox::warning(GetDesktop(theModule),
728 QObject::tr("WRN_VISU"),
729 QObject::tr("WRN_NO_AVAILABLE_DATA") );
733 //------------------------------------------------------------
735 CheckResult(const SalomeApp_Module* theModule,
736 _PTR(SObject) theSource,
737 VISU::Result_var& theResult)
739 if(theSource->Depth() < 3) // Bug of SALOMEDS : can\t get father from root object
742 _PTR(SObject) aSObj = theSource->GetFather();
746 aSObj = aSObj->GetFather();
750 aSObj = aSObj->GetFather();
754 CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
755 if (CORBA::is_nil(anObject)) {
756 aSObj = aSObj->GetFather();
759 anObject = VISU::ClientSObjectToObject(aSObj);
762 if (CORBA::is_nil(anObject))
765 theResult = VISU::Result::_narrow(anObject);
766 return dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
769 //------------------------------------------------------------
772 PublishMeshInView(const SalomeApp_Module* theModule,
773 VISU::Prs3d_i* thePrs,
774 SVTK_ViewWindow* theViewWindow)
776 VISU_Actor* aActor = NULL;
777 if (!thePrs || !theViewWindow)
780 QApplication::setOverrideCursor( Qt::WaitCursor );
782 if ((aActor = thePrs->CreateActor()))
783 theViewWindow->AddActor(aActor);
784 } catch(std::exception& exc) {
785 SUIT_MessageBox::warning
786 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
787 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()) );
789 QApplication::restoreOverrideCursor();
794 //------------------------------------------------------------
796 RepaintViewWindows (const SalomeApp_Module* theModule,
797 const Handle(SALOME_InteractiveObject)& theIObject)
799 TViewWindows aViewWindows;
800 if (SalomeApp_Application* anApp = theModule->getApp()) {
801 ViewManagerList aViewManagerList;
802 anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
803 QList<SUIT_ViewManager*>::Iterator anIter = aViewManagerList.begin();
804 while ( anIter != aViewManagerList.end() )
806 QVector<SUIT_ViewWindow*> aViews = (*anIter)->getViews();
807 for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
808 if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
809 if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
810 if (vw->isVisible(theIObject)) {
811 vw->getRenderer()->ResetCameraClippingRange();
813 vw->highlight(theIObject, true, true);
823 //------------------------------------------------------------
825 FindActor(const SalomeApp_Study* theStudy,
826 SVTK_ViewWindow* theViewWindow,
827 const QString& theEntry)
829 TObjectInfo anObjectInfo = GetObjectByEntry(theStudy, theEntry.toLatin1().data());
830 VISU::Prs3d_i* aPrs3d = GetPrs3dFromBase(anObjectInfo.myBase);
831 return FindActor(theViewWindow, aPrs3d);
834 //------------------------------------------------------------
836 FindActorBase(const SalomeApp_Study* theStudy,
837 SVTK_ViewWindow* theViewWindow,
838 const QString& theEntry)
840 TObjectInfo anObjectInfo = GetObjectByEntry(theStudy, theEntry.toLatin1().constData());
841 VISU::PointMap3d_i* aTable = dynamic_cast<VISU::PointMap3d_i*>(anObjectInfo.myBase);
842 return FindActorBase(theViewWindow, aTable);
845 //------------------------------------------------------------
847 RecreateActor (const SalomeApp_Module* theModule,
848 VISU::Prs3d_i* thePrs)
850 QApplication::setOverrideCursor(Qt::WaitCursor);
852 /* SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
853 CORBA::String_var anEntry = aSObject->GetID();*/
856 thePrs->UpdateActors();
857 } catch (std::runtime_error& exc) {
859 QApplication::restoreOverrideCursor();
860 SUIT_MessageBox::warning
861 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
862 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()) );
864 thePrs->RemoveActors();
867 QApplication::restoreOverrideCursor();
870 //------------------------------------------------------------
872 ComputeVisiblePropBounds(SVTK_ViewWindow* theViewWindow,
873 vtkFloatingPointType allBounds[6],
874 const char* theActorClassName)
876 vtkRenderer *aRen = theViewWindow->getRenderer();
877 VTK::ActorCollectionCopy aCopy(aRen->GetActors());
878 vtkActorCollection *anActColl = aCopy.GetActors();
880 vtkFloatingPointType *bounds;
881 int somethingVisible = false;
883 allBounds[0] = allBounds[2] = allBounds[4] = VTK_LARGE_FLOAT;
884 allBounds[1] = allBounds[3] = allBounds[5] = -VTK_LARGE_FLOAT;
885 // loop through all props
886 for (anActColl->InitTraversal(); (prop = anActColl->GetNextProp()); ) {
887 // if it's invisible, or has no geometry, we can skip the rest
888 if (prop->GetVisibility() && prop->IsA(theActorClassName)) {
889 bounds = prop->GetBounds();
890 // make sure we haven't got bogus bounds
891 if (bounds != NULL &&
892 bounds[0] > -VTK_LARGE_FLOAT && bounds[1] < VTK_LARGE_FLOAT &&
893 bounds[2] > -VTK_LARGE_FLOAT && bounds[3] < VTK_LARGE_FLOAT &&
894 bounds[4] > -VTK_LARGE_FLOAT && bounds[5] < VTK_LARGE_FLOAT)
896 somethingVisible = true;
897 if (bounds[0] < allBounds[0]) allBounds[0] = bounds[0];
898 if (bounds[1] > allBounds[1]) allBounds[1] = bounds[1];
899 if (bounds[2] < allBounds[2]) allBounds[2] = bounds[2];
900 if (bounds[3] > allBounds[3]) allBounds[3] = bounds[3];
901 if (bounds[4] < allBounds[4]) allBounds[4] = bounds[4];
902 if (bounds[5] > allBounds[5]) allBounds[5] = bounds[5];
906 return somethingVisible;
909 //------------------------------------------------------------
910 void SetFitAll(SVTK_ViewWindow* theViewWindow)
912 static vtkFloatingPointType PRECISION = 0.000001;
913 static vtkFloatingPointType DEVIATION = 600;
914 vtkFloatingPointType XYZ_Bnd[6];
915 if (!ComputeVisiblePropBounds(theViewWindow, XYZ_Bnd)) return;
917 vtkFloatingPointType absX = XYZ_Bnd[1] - XYZ_Bnd[0];
918 vtkFloatingPointType absY = XYZ_Bnd[3] - XYZ_Bnd[2];
919 vtkFloatingPointType absZ = XYZ_Bnd[5] - XYZ_Bnd[4];
921 enum CameraOrient {e3D, eFront, eLeft, eTop};
922 CameraOrient aCameraOrient = e3D;
923 if (absX <= PRECISION) aCameraOrient = eFront;
925 if (absY <= PRECISION) aCameraOrient = eLeft;
927 if (absZ <= PRECISION) aCameraOrient = eTop;
929 // all the three dimensions exceeds precision
930 vtkFloatingPointType dev_abs_XY = absX / absY;
931 vtkFloatingPointType dev_abs_YZ = absY / absZ;
932 vtkFloatingPointType dev_abs_XZ = absX / absZ;
933 if (dev_abs_XY >= DEVIATION || 1./dev_abs_YZ >= DEVIATION)
934 aCameraOrient = eLeft;
936 if (1./dev_abs_XY >= DEVIATION || 1./dev_abs_XZ >= DEVIATION)
937 aCameraOrient = eFront;
939 if (dev_abs_XZ >= DEVIATION || dev_abs_YZ >= DEVIATION)
940 aCameraOrient = eTop;
947 switch (aCameraOrient) {
948 case eFront: theViewWindow->onFrontView(); break;
949 case eLeft: theViewWindow->onLeftView(); break;
950 case eTop: theViewWindow->onTopView(); break;
951 case e3D: theViewWindow->onResetView(); break;
953 theViewWindow->getRenderer()->ResetCameraClippingRange();
954 theViewWindow->onFitAll();
957 //************************************************************
961 GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate)
963 if(SalomeApp_Application* anApp = theModule->getApp()){
964 if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){
965 return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
971 //------------------------------------------------------------
973 PlotTable(const SalomeApp_Module* theModule,
974 VISU::Table_i* table,
977 SalomeApp_Study* aStudy = GetAppStudy( theModule );
981 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
984 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
988 // implementation moved to VISU_I package (see VISU_Tools.h)
989 VISU::PlotTable( aStudy, aPlot, table, theDisplaying );
992 //------------------------------------------------------------
994 PlotCurve(const SalomeApp_Module* theModule,
995 VISU::Curve_i* theCurve,
998 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1001 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1005 // implementation moved to VISU_I package (see VISU_Tools.h)
1006 VISU::PlotCurve( aPlot, theCurve, theDisplaying );
1009 //------------------------------------------------------------
1011 PlotRemoveCurve(const SalomeApp_Module* theModule,
1012 VISU::Curve_i* pCrv)
1014 // implementation moved to VISU_I package (see VISU_Tools.h)
1015 VISU::PlotRemoveCurve( theModule->getApp(), pCrv );
1018 //------------------------------------------------------------
1020 PlotContainer(const SalomeApp_Module* theModule,
1021 VISU::Container_i* container,
1024 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1027 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1031 // implementation moved to VISU_I package (see VISU_Tools.h)
1032 VISU::PlotContainer( aPlot, container, theDisplaying );
1035 //------------------------------------------------------------
1037 CreatePlot(SalomeApp_Module* theModule,
1038 _PTR(SObject) theTableSO)
1040 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1043 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1047 VISU::VISU_Gen_i* aVisuGen = VISU::GetVisuGen( theModule );
1049 // implementation moved to VISU_I package (see VISU_Tools.h)
1050 VISU::CreatePlot( aVisuGen, aPlot, theTableSO );
1053 //************************************************************
1056 CreateMesh(VisuGUI* theModule,
1057 const Handle(SALOME_InteractiveObject)& theIO,
1058 SVTK_ViewWindow* theViewWindow)
1060 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
1061 //if (CheckLock(aStudy))
1064 _PTR(SObject) aResultSObj = aStudy->FindObjectID(theIO->getEntry());
1067 VISU::Result_var aResult;
1068 VISU::Result_i* pResult = CheckResult(theModule, aResultSObj, aResult);
1069 if (pResult == NULL)
1072 Storable::TRestoringMap aMap = Storable::GetStorableMap(aResultSObj);
1076 CORBA::Object_var aMesh;
1077 string aComment = Storable::FindValue(aMap,"myComment").toLatin1().data();
1078 string aMeshName = Storable::FindValue(aMap,"myMeshName").toLatin1().data();
1083 if (aComment == "ENTITY") {
1084 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myId").toInt();
1085 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity))
1086 aMesh = GetVisuGen(theModule)->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
1087 } else if (aComment == "FAMILY") {
1088 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myEntityId").toInt();
1089 string aFamilyName = Storable::FindValue(aMap,"myName").toLatin1().data();
1090 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()))
1091 aMesh = GetVisuGen(theModule)->FamilyMeshOnEntity
1092 (aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
1093 } else if (aComment == "GROUP") {
1094 string aGroupName = Storable::FindValue(aMap,"myName").toLatin1().data();
1095 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str()))
1096 aMesh = GetVisuGen(theModule)->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
1100 MESSAGE("VisuGUI::CreateMesh() - CREATE MESH");
1104 //QApplication::restoreOverrideCursor();
1105 VISU::Mesh_i* pPresent = NULL;
1106 if (!CORBA::is_nil(aMesh))
1107 pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
1108 if (pPresent == NULL) {
1109 SUIT_MessageBox::warning (GetDesktop(theModule),
1110 QObject::tr("WRN_VISU"),
1111 QObject::tr("ERR_CANT_BUILD_PRESENTATION") );
1115 if (theViewWindow) {
1121 if(GetResourceMgr()->booleanValue("VISU","display_only",false)){
1122 const VisuGUI* av = dynamic_cast<const VisuGUI*>(theModule);
1123 if(av)(const_cast<VisuGUI*>(av))->OnEraseAll();
1125 PublishMeshInView(theModule, pPresent, theViewWindow);
1126 if(GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false)){
1127 SetFitAll(theViewWindow);
1131 MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
1134 } catch (std::runtime_error& exc) {
1136 SUIT_MessageBox::warning(GetDesktop(theModule), QObject::tr("WRN_VISU"),
1137 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()) );
1141 UpdateObjBrowser(theModule, false, aResultSObj);
1143 theModule->application()->putInfo(QObject::tr("INF_DONE"));
1144 // Make "Save" button active
1145 theModule->getApp()->updateActions();
1149 // ========================================================================================
1150 // GetPrs3dList: find list of presentations for the given object
1151 // ========================================================================================
1152 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1153 const Handle(SALOME_InteractiveObject)& theIO,
1156 std::vector<VISU::Prs3d_i*> aList;
1157 if (!theIO.IsNull() && theIO->hasEntry()) {
1158 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1159 _PTR(SObject) aSObject = aCStudy->FindObjectID(theIO->getEntry());
1160 aList = GetPrs3dList(theModule, aSObject, theGP);
1165 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1166 _PTR(SObject) theObject,
1169 std::vector<VISU::Prs3d_i*> aList; int k = 0;
1173 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1175 CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(theObject);
1176 if (!CORBA::is_nil(aCORBAObject)) {
1177 VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
1178 if (!CORBA::is_nil(aVisuObj)) {
1179 VISU::VISUType aType = aVisuObj->GetType();
1181 case VISU::TGAUSSPOINTS:
1182 if ( !theGP ) break;
1183 case VISU::TSCALARMAP:
1184 case VISU::TISOSURFACES:
1185 case VISU::TDEFORMEDSHAPE:
1186 case VISU::TCUTPLANES:
1187 case VISU::TCUTLINES:
1188 case VISU::TCUTSEGMENT:
1189 case VISU::TVECTORS:
1190 case VISU::TSTREAMLINES:
1192 case VISU::TSCALARMAPONDEFORMEDSHAPE:
1193 case VISU::TDEFORMEDSHAPEANDSCALARMAP:
1196 PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1197 if (aServant.in()) {
1198 VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
1200 aList[k] = aPrsObject;
1207 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1208 _PTR(SObject) aTimeStamp;
1209 anIter->Next(); // First is reference on support
1210 for (; anIter->More(); anIter->Next()) {
1211 aTimeStamp = anIter->Value();
1212 if (!aTimeStamp) continue;
1213 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1214 if (!aSubList.empty()) {
1215 int n = aSubList.size();
1217 for (int i = 0; i < n; i++) {
1218 aList[k] = aSubList[i];
1225 case VISU::TCOLOREDPRS3DHOLDER:
1227 PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1228 if (aServant.in()) {
1229 VISU::ColoredPrs3dHolder_i* aPrsHolderObject = dynamic_cast<VISU::ColoredPrs3dHolder_i*>(aServant.in());
1230 if( aPrsHolderObject ) {
1231 VISU::Prs3d_i* aPrsObject = aPrsHolderObject->GetPrs3dDevice();
1233 aList[k] = aPrsObject;
1241 VISU::VISUType aType = VISU::Storable::SObject2Type(theObject);
1243 case VISU::TFIELD: {
1244 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1245 _PTR(SObject) aTimeStamp;
1246 anIter->Next(); // First is reference on support
1247 for (; anIter->More(); anIter->Next()) {
1248 aTimeStamp = anIter->Value();
1249 if (!aTimeStamp) continue;
1250 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1251 if (!aSubList.empty()) {
1252 int n = aSubList.size();
1254 for (int i = 0; i < n; i++) {
1255 aList[k] = aSubList[i];
1262 case VISU::TTIMESTAMP: {
1263 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1265 for (; anIter->More(); anIter->Next()) {
1266 aPrs = anIter->Value();
1267 if (!aPrs) continue;
1268 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
1269 if (!aSubList.empty()) {
1270 int n = aSubList.size();
1272 for (int i = 0; i < n; i++) {
1273 aList[k] = aSubList[i];
1284 //------------------------------------------------------------
1285 int GetFreePositionOfDefaultScalarBar(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow)
1288 std::set<int> aIndexes;
1289 TViewToPrs3d aMap = theModule->getScalarBarsMap();
1290 TViewToPrs3d::const_iterator aViewToPrsIter = aMap.find(theViewWindow);
1291 if (aViewToPrsIter != aMap.end()) {
1292 TSetPrs3d::const_iterator aPrsIter = (aViewToPrsIter->second).begin();
1293 for (; aPrsIter != (aViewToPrsIter->second).end(); aPrsIter++) {
1294 aIndexes.insert((*aPrsIter).second);
1297 std::set<int>::const_iterator aIter = aIndexes.begin();
1298 for (int i = 1,length = aIndexes.size(); i <= length; i++) {
1299 std::set<int>::const_iterator aIter = aIndexes.find(i);
1300 if (aIter == aIndexes.end()) { minIndx = i; break; }
1301 else minIndx = i + 1;
1306 //------------------------------------------------------------
1307 void AddScalarBarPosition (VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1308 VISU::Prs3d_i* thePrs3d, int pos)
1310 TViewToPrs3d& aMap = theModule->getScalarBarsMap();
1311 TPrs3dToInd aPair; aPair.first = thePrs3d; aPair.second = pos;
1312 aMap[theViewWindow].insert(aPair);
1315 //------------------------------------------------------------
1316 void RemoveScalarBarPosition(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1317 VISU::Prs3d_i* thePrs3d)
1319 TViewToPrs3d& aMap = theModule->getScalarBarsMap();
1320 TSetPrs3d::iterator aIter = aMap[theViewWindow].begin();
1321 for (; aIter != aMap[theViewWindow].end(); aIter++)
1322 if ((*aIter).first == thePrs3d) {
1323 aMap[theViewWindow].erase(*aIter);
1327 //------------------------------------------------------------
1328 void initSpinBox( QSpinBox* spinBox,
1329 int min, int max, int step )
1331 spinBox->setRange( min, max );
1332 spinBox->setSingleStep( step );
1334 //------------------------------------------------------------
1335 void initSpinBox( QDoubleSpinBox* spinBox,
1336 double min, double max,
1337 double step, int decimals )
1339 spinBox->setRange( min, max );
1340 spinBox->setSingleStep( step );
1341 spinBox->setDecimals( decimals );
1343 //------------------------------------------------------------
1344 bool getClippingPlanesFolder(_PTR(Study) theStudy, _PTR(SObject)& theSObject)
1346 _PTR(SComponent) aVisuSO = theStudy->FindComponent("VISU");
1347 if (!aVisuSO) return false;
1348 _PTR(SObject) aFolder = theStudy->FindObject(CLIP_PLANES_FOLDER);
1350 _PTR(StudyBuilder) aBuilder = theStudy->NewBuilder();
1351 aFolder = aBuilder->NewObject(aVisuSO);
1353 _PTR(GenericAttribute) anAttr;
1354 anAttr = aBuilder->FindOrCreateAttribute(aFolder,"AttributeName");
1355 _PTR(AttributeName) aName(anAttr);
1356 aName->SetValue(CLIP_PLANES_FOLDER);
1358 theSObject = aFolder;