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
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"
50 #include "SalomeApp_IntSpinBox.h"
51 #include "SalomeApp_DoubleSpinBox.h"
53 #include "LightApp_DataObject.h"
54 #include "LightApp_SelectionMgr.h"
57 //#include "OB_Browser.h"
59 #include "SALOME_ListIO.hxx"
60 #include "SALOME_ListIteratorOfListIO.hxx"
62 #include "SVTK_ViewWindow.h"
63 #include "SVTK_Functor.h"
65 #include "VTKViewer_Algorithm.h"
67 #include "SPlot2d_ViewModel.h"
68 #include "Plot2d_ViewFrame.h"
69 #include "Plot2d_ViewManager.h"
71 #include "SUIT_Session.h"
72 #include "SUIT_MessageBox.h"
73 #include "SUIT_Desktop.h"
74 #include "SUIT_ViewWindow.h"
75 #include "SUIT_ResourceMgr.h"
77 #include "CAM_DataModel.h"
79 #include <vtkRenderer.h>
80 #include <vtkActorCollection.h>
84 #include <QDoubleSpinBox>
89 //=============================================================================
92 //------------------------------------------------------------
94 GetDesktop(const CAM_Module* theModule)
96 return theModule && theModule->application() ? theModule->application()->desktop() : 0;
99 //------------------------------------------------------------
100 LightApp_SelectionMgr*
101 GetSelectionMgr(const SalomeApp_Module* theModule)
103 return theModule && theModule->getApp() ? theModule->getApp()->selectionMgr() : 0;
106 //------------------------------------------------------------
108 GetAppStudy(const CAM_Module* theModule)
110 return theModule && theModule->application() ?
111 dynamic_cast<SalomeApp_Study*>(theModule->application()->activeStudy()) : 0;
114 //------------------------------------------------------------
116 GetCStudy(const SalomeApp_Study* theStudy)
118 return theStudy ? theStudy->studyDS() : _PTR(Study)();
121 //------------------------------------------------------------
123 IsStudyLocked( _PTR(Study) theStudy )
125 return theStudy ? theStudy->GetProperties()->IsLocked() : true;
128 //------------------------------------------------------------
130 CheckLock( _PTR(Study) theStudy,
133 if(IsStudyLocked(theStudy)){
134 SUIT_MessageBox::warning(theWidget,
135 QObject::tr("WRN_VISU_WARNING"),
136 QObject::tr("WRN_STUDY_LOCKED") );
142 //------------------------------------------------------------
144 runAndWait( QDialog* dlg, const bool modal )
146 VisuGUI_DialogRunner r( dlg );
147 return r.run( modal );
150 //------------------------------------------------------------
152 FindDataObject(SUIT_DataObject* theDataObject,
153 const QString& theEntry,
156 int aLevel = theDataObject->level() + 2;
157 QString aSourceEntry = theEntry.section(':',0,aLevel);
158 DataObjectList aList;
159 theDataObject->children(aList);
160 DataObjectList::Iterator aDataObjectIter = aList.begin();
161 while( aDataObjectIter!= aList.end() ) {
162 if(LightApp_DataObject* aChildDataObject = dynamic_cast<LightApp_DataObject*>(*aDataObjectIter)){
163 QString anEntry = aChildDataObject->entry();
164 QString aCurrentEntry = anEntry.section(':',0,aLevel);
165 if(aSourceEntry == aCurrentEntry){
166 if(theLevel == aLevel){
167 return aChildDataObject;
169 return FindDataObject(aChildDataObject,theEntry,theLevel);
178 //------------------------------------------------------------
180 FindDataObject(CAM_Module* theModule,
181 _PTR(SObject) theSObject)
183 CAM_DataModel* aDataModel = theModule->dataModel();
184 CAM_DataObject* aRootDataObject = aDataModel->root();
185 if(_PTR(SComponent) aComponent = theSObject)
186 return dynamic_cast<LightApp_DataObject*>(aRootDataObject);
188 int aLevel = theSObject->Depth();
189 std::string anEntry = theSObject->GetID();
190 return FindDataObject(aRootDataObject,anEntry.c_str(),aLevel);
193 //------------------------------------------------------------
195 UpdateObjBrowser(SalomeApp_Module* theModule,
196 bool theIsUpdateDataModel,
197 _PTR(SObject) theSObject)
199 LightApp_DataObject* aDataObject = NULL;
201 aDataObject = FindDataObject(theModule,theSObject);
203 theModule->updateObjBrowser(theIsUpdateDataModel,aDataObject);
204 theModule->getApp()->updateActions();
207 //------------------------------------------------------------
209 IsSObjectTable( _PTR(SObject) theSObject )
212 _PTR(GenericAttribute) anAttr;
213 if (theSObject->FindAttribute( anAttr, "AttributeTableOfInteger" ))
215 if (theSObject->FindAttribute( anAttr, "AttributeTableOfReal" ))
221 //------------------------------------------------------------
223 GetVisuGen(const CAM_Module* theModule)
225 static VISU_Gen_i* aGen = 0;
227 SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
228 Engines::EngineComponent_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","VISU");
229 VISU_Gen_var aVISU = VISU_Gen::_narrow(aComponent);
230 if(!CORBA::is_nil(aVISU))
231 aGen = VISU_Gen_i::GetVisuGenImpl();
235 aGen->SetCurrentStudy(GetDSStudy(GetCStudy(GetAppStudy(theModule))));
237 throw std::runtime_error(QObject::tr("ERR_CANT_FIND_VISU_COMPONENT").toLatin1().data());
241 //------------------------------------------------------------
242 SALOME_MED::MED_Gen_var
245 static SALOME_MED::MED_Gen_var aGen;
246 if(CORBA::is_nil(aGen)){
247 SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
248 Engines::EngineComponent_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","MED");
249 aGen = SALOME_MED::MED_Gen::_narrow(aComponent);
251 if(CORBA::is_nil(aGen))
252 throw std::runtime_error(QObject::tr("ERR_CANT_FIND_MED_COMPONENT").toLatin1().data());
257 //----------------------------------------------------------------------------
260 GetSelectedObjects(const SalomeApp_Module* theModule)
262 TSelectionInfo aSelectionInfo;
263 const SalomeApp_Study* aStudy = GetAppStudy(theModule);
264 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
265 if ( aStudy && aSelectionMgr ) {
266 SALOME_ListIO aListIO;
267 aSelectionMgr->selectedObjects(aListIO);
268 SALOME_ListIteratorOfListIO anIter(aListIO);
271 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
274 TObjectInfo anObjectInfo = GetObjectByEntry(aStudy, anIO->getEntry());
275 if(anObjectInfo.mySObject){
276 TSelectionItem aSelectionItem;
277 aSelectionItem.myObjectInfo = anObjectInfo;
278 aSelectionItem.myIO = anIO;
279 aSelectionInfo.push_back(aSelectionItem);
282 anIter.Next(); // MULTIPR fixed
285 return aSelectionInfo;
288 //----------------------------------------------------------------------------
290 GetObjectByEntry(const SalomeApp_Study* theStudy,
291 const std::string& theEntry)
293 TObjectInfo anObjectInfo;
294 if(!theStudy || theEntry == "")
297 _PTR(Study) aStudy = GetCStudy(theStudy);
298 if(_PTR(SObject) aSObject = aStudy->FindObjectID(theEntry)){
299 anObjectInfo.mySObject = aSObject;
300 CORBA::Object_var anObject = ClientSObjectToObject(aSObject);
301 if(VISU::Base_i* aBase = GetServantInterface<VISU::Base_i>(anObject))
302 anObjectInfo.myBase = aBase;
309 //----------------------------------------------------------------------------
311 GetPrs3dToModify(const SalomeApp_Module* theModule,
314 if (CheckLock(GetCStudy(GetAppStudy(theModule)), GetDesktop(theModule)))
317 return GetPrs3dFromBase(theBase);
320 //----------------------------------------------------------------------------
322 GetPrs3dFromBase(Base_i* theBase)
324 if(theBase && theBase->GetType() == VISU::TCOLOREDPRS3DHOLDER){
325 CORBA::Object_var anObject = theBase->_this();
326 VISU::ColoredPrs3dHolder_var aHolder = VISU::ColoredPrs3dHolder::_narrow(anObject);
327 VISU::Prs3d_var aPrs3d = aHolder->GetDevice();
328 return VISU::GetServantInterface<VISU::Prs3d_i>(aPrs3d);
330 return dynamic_cast<VISU::Prs3d_i*>(theBase);
334 //----------------------------------------------------------------------------
336 GetPrs3dSelectionInfo(const SalomeApp_Module* theModule,
337 VISU::Prs3d_i*& thePrs3d,
338 SVTK_ViewWindow*& theViewWindow,
339 VISU_Actor*& thenActor)
341 VISU::TSelectionInfo aSelectionInfo = VISU::GetSelectedObjects(theModule);
342 if(aSelectionInfo.empty())
345 VISU::TSelectionItem aSelectionItem = aSelectionInfo.front();
346 thePrs3d = GetPrs3dFromBase(aSelectionItem.myObjectInfo.myBase);
350 theViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
354 thenActor = FindActor(theViewWindow, thePrs3d);
362 //----------------------------------------------------------------------------
364 Add(LightApp_SelectionMgr* theSelectionMgr,
365 const Handle(SALOME_InteractiveObject)& theIO)
367 SALOME_ListIO aListIO;
368 theSelectionMgr->selectedObjects(aListIO);
369 aListIO.Append(theIO);
370 theSelectionMgr->setSelectedObjects(aListIO);
373 //------------------------------------------------------------
375 Remove(LightApp_SelectionMgr* theSelectionMgr,
376 const Handle(SALOME_InteractiveObject)& theIO)
378 if (theIO.IsNull()) return;
379 SALOME_ListIO aListIO, aNewListIO;
380 theSelectionMgr->selectedObjects(aListIO);
381 SALOME_ListIteratorOfListIO anIter (aListIO);
382 for (; anIter.More(); anIter.Next()) {
383 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
384 if (!anIO->isSame(theIO)) {
385 aNewListIO.Append(theIO);
388 theSelectionMgr->setSelectedObjects(aNewListIO);
392 * \brief Check, if the object can be deleted
394 * \param theEntry - entry of the object to check
395 * \param theModule - is used to access Study and VISU_Gen
396 * \retval bool - returns TRUE if the object is removable
399 IsRemovable (const std::string theEntry,
400 const SalomeApp_Module* theModule)
402 // asv : if selected object is a Save Point object selected in object browser - return false
403 if ( QString( theEntry.c_str() ).startsWith( QObject::tr( "SAVE_POINT_DEF_NAME" ) ) )
406 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
408 _PTR(SObject) aSObject = aStudy->FindObjectID(theEntry);
409 VISU::Storable::TRestoringMap pMap;
411 CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(aSObject);
412 if (!CORBA::is_nil(aCORBAObject)) {
413 VISU::RemovableObject_var aRemovableObj = VISU::RemovableObject::_narrow(aCORBAObject);
414 if (CORBA::is_nil(aRemovableObj)) {
415 // Not removable CORBA object
419 // Can be removed, if lays directly under VISU
420 // (first sub-level) or is a child of such an object
421 string aNAME, aVisuNAME = GetVisuGen(theModule)->ComponentDataType();
422 _PTR(GenericAttribute) anAttr;
423 _PTR(AttributeString) aComment;
425 _PTR(SObject) aRefSObject;
426 if (aSObject->ReferencedObject(aRefSObject)) {
427 // It can be a reference on curve, published under a container. IPAL 20317
428 VISU::TObjectInfo aRefObjectInfo = GetObjectByEntry(GetAppStudy(theModule), aRefSObject->GetID());
429 VISU::Base_i* aRefBase = aRefObjectInfo.myBase;
430 if( (aRefBase && aRefBase->GetType() == VISU::TCURVE) || (aRefBase && aRefBase->GetType() == VISU::TMESH) )
434 bool isUnderVISU = false;
435 _PTR(SObject) aFatherSObject = aSObject->GetFather();
436 if (aFatherSObject->FindAttribute(anAttr, "AttributeName")) {
437 // mkr : 24.11.2006 : use AttributeName and module title for correct "Delete"
438 // popup item displaying in object browser popup
439 _PTR(AttributeName) aComment (anAttr);
440 aNAME = aComment->Value();
441 QString aVisuTITLE = theModule->getApp()->moduleTitle(aVisuNAME.c_str());
442 if (!aVisuTITLE.compare(aNAME.c_str())) {
447 // Not directly under VISU component, check father
448 aCORBAObject = VISU::ClientSObjectToObject(aFatherSObject);
449 if (!CORBA::is_nil(aCORBAObject)) {
455 aFatherSObject = aFatherSObject->GetFather();
456 if (aFatherSObject->FindAttribute(anAttr, "AttributeString")) {
457 _PTR(AttributeString) aComment (anAttr);
458 aNAME = aComment->Value();
459 if (aNAME == aVisuNAME) {
464 // Father is not directly under VISU component
474 * \brief Check, if "Delete" popup-menu can be put on current selection
476 * \param theModule - is used to access SelectionManager, Study and VISU_Gen
477 * \retval bool - returns TRUE if all currently selected objects are removable
480 IsRemovableSelected (const SalomeApp_Module* theModule)
482 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
483 SALOME_ListIO aListIO;
484 aSelectionMgr->selectedObjects(aListIO);
486 if (aListIO.Extent() < 1)
489 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
490 if (!aStudy) return false;
492 SALOME_ListIteratorOfListIO anIter (aListIO);
493 for (; anIter.More(); anIter.Next()) {
494 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
495 if (anIO->hasEntry()) {
496 if (!IsRemovable(anIO->getEntry(), theModule))
503 //------------------------------------------------------------
505 DeleteSObject(VisuGUI* theModule,
506 _PTR(Study) theStudy,
507 _PTR(SObject) theSObject)
509 _PTR(ChildIterator) aChildIter = theStudy->NewChildIterator(theSObject);
510 for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
511 _PTR(SObject) aSObject = aChildIter->Value();
512 TObjectInfo anObjectInfo = GetObjectByEntry(GetAppStudy(theModule), aSObject->GetID());
513 ErasePrs(theModule, anObjectInfo.myBase, /*repaint_view_window = */false);
516 TObjectInfo anObjectInfo = GetObjectByEntry(GetAppStudy(theModule), theSObject->GetID());
517 if(anObjectInfo.myBase){
518 ErasePrs(theModule, anObjectInfo.myBase, /*repaint_view_window = */true);
520 CORBA::Object_var anObject = ClientSObjectToObject(theSObject);
521 VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObject);
522 if (!CORBA::is_nil(aRemovableObject)) {
523 aRemovableObject->RemoveFromStudy();
526 // Remove aSObject together with all its sub-objects
527 VISU::RemoveFromStudy(theSObject,
528 false, // remove not only IOR attribute, but Object With Children
529 false); // not UnRegister() sub-objects
533 //------------------------------------------------------------
535 DeletePrs3d(VisuGUI* theModule,
536 VISU::Prs3d_i* thePrs)
541 if (CheckLock(GetCStudy(GetAppStudy(theModule)),GetDesktop(theModule)))
544 if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule))
545 RemoveScalarBarPosition(theModule, aViewWindow, thePrs);
547 if(VISU::ColoredPrs3d_i* aColoredPrs3d = dynamic_cast<VISU::ColoredPrs3d_i*>(thePrs)){
548 std::string anEntry = aColoredPrs3d->GetHolderEntry();
550 VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(GetAppStudy(theModule), anEntry);
551 if(VISU::Base_i* aBase = anObjectInfo.myBase){
552 if(aBase->GetType() == VISU::TCOLOREDPRS3DHOLDER){
553 CORBA::Object_var anObject = aBase->_this();
554 VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObject);
555 aRemovableObject->RemoveFromStudy();
562 thePrs->RemoveFromStudy();
565 //------------------------------------------------------------
566 // Presentation management
568 ChangeRepresentation (const SalomeApp_Module* theModule,
569 VISU::PresentationType theType)
571 TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
572 if(aSelectionInfo.empty())
575 VISU::Prs3d_i* aPrs3d;
576 VISU::PointMap3d_i* aTable;
578 VISU_ActorBase* anActorBase;
580 TSelectionItem aSelectionItem = aSelectionInfo.front();
581 aPrs3d = GetPrs3dFromBase(aSelectionItem.myObjectInfo.myBase);
583 aTable = dynamic_cast<VISU::PointMap3d_i*>(aSelectionItem.myObjectInfo.myBase);
588 SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
593 anActor = FindActor(aViewWindow, aPrs3d);
597 anActorBase = VISU::FindActorBase(aViewWindow, aTable);
606 if (anActor->IsShrunk()) {
611 anActor->SetShrink();
614 if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
615 aMesh->SetShrink(toShrink);
618 if (anActorBase->IsShrunk())
619 anActorBase->UnShrink();
621 anActorBase->SetShrink();
626 if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
627 aMesh->SetPresentationType(theType);
628 RecreateActor(theModule, aMesh);
630 anActor->SetRepresentation(theType);
634 anActorBase->SetRepresentation(theType);
637 aViewWindow->Repaint();
641 void ChangeQuadratic2DRepresentation (const SalomeApp_Module* theModule,
642 VISU::Quadratic2DPresentationType theType)
644 TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
645 if(aSelectionInfo.empty())
648 TSelectionItem aSelectionItem = aSelectionInfo.front();
650 VISU::Prs3d_i* aPrs3d = GetPrs3dFromBase(aSelectionItem.myObjectInfo.myBase);
652 SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
654 if(!aPrs3d || !aViewWindow)
657 VISU_Actor *anActor = FindActor(aViewWindow, aPrs3d);
661 if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
662 aMesh->SetQuadratic2DPresentationType(theType);
663 RecreateActor(theModule, aMesh);
667 anActor->SetQuadratic2DRepresentation(VISU_Actor::eLines);
670 anActor->SetQuadratic2DRepresentation(VISU_Actor::eArcs);
678 //------------------------------------------------------------
680 SetShading ( const SalomeApp_Module* theModule,
683 TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
684 if(aSelectionInfo.empty())
687 TSelectionItem aSelectionItem = GetSelectedObjects(theModule).front();
688 VISU::Prs3d_i* aPrs3d = GetPrs3dFromBase(aSelectionItem.myObjectInfo.myBase);
692 SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
696 VISU_Actor* anActor = FindActor(aViewWindow, aPrs3d);
700 if(VISU_ScalarMapAct* aScalarMapActor = dynamic_cast<VISU_ScalarMapAct*>(anActor)){
701 aScalarMapActor->SetShading(theOn);
702 aViewWindow->Repaint();
706 //------------------------------------------------------------
709 CheckTimeStamp(const SalomeApp_Module* theModule,
710 _PTR(SObject)& theSObject,
711 Handle(SALOME_InteractiveObject)& theIO,
712 ColoredPrs3d_i::EPublishInStudyMode& thePublishInStudyMode)
714 TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
715 if(!aSelectionInfo.empty()){
716 TSelectionItem aSelectionItem = aSelectionInfo.front();
717 theIO = aSelectionItem.myIO;
718 theSObject = aSelectionItem.myObjectInfo.mySObject;
719 VISU::VISUType aType = VISU::Storable::SObject2Type(theSObject);
720 if (VISU::TTIMESTAMP == aType){
721 thePublishInStudyMode = ColoredPrs3d_i::EPublishUnderTimeStamp;
724 if (VISU::TFIELD == aType){
725 thePublishInStudyMode = ColoredPrs3d_i::EPublishIndependently;
726 if(theSObject->FindSubObject(2,theSObject))
730 SUIT_MessageBox::warning(GetDesktop(theModule),
731 QObject::tr("WRN_VISU"),
732 QObject::tr("WRN_NO_AVAILABLE_DATA") );
736 //------------------------------------------------------------
738 CheckResult(const SalomeApp_Module* theModule,
739 _PTR(SObject) theSource,
740 VISU::Result_var& theResult)
742 if(theSource->Depth() < 3) // Bug of SALOMEDS : can\t get father from root object
745 _PTR(SObject) aSObj = theSource->GetFather();
749 aSObj = aSObj->GetFather();
753 aSObj = aSObj->GetFather();
757 CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
758 if (CORBA::is_nil(anObject)) {
759 aSObj = aSObj->GetFather();
762 anObject = VISU::ClientSObjectToObject(aSObj);
765 if (CORBA::is_nil(anObject))
768 theResult = VISU::Result::_narrow(anObject);
769 return dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
772 //------------------------------------------------------------
775 PublishMeshInView(const SalomeApp_Module* theModule,
776 VISU::Prs3d_i* thePrs,
777 SVTK_ViewWindow* theViewWindow)
779 VISU_Actor* anActor = NULL;
780 if (!thePrs || !theViewWindow)
783 SalomeApp_Application *anApp = dynamic_cast<SalomeApp_Application*>(theModule->application());
787 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
793 QApplication::setOverrideCursor( Qt::WaitCursor );
795 if ((anActor = thePrs->CreateActor())) {
796 theViewWindow->AddActor(anActor);
798 if(anActor->hasIO() && anActor->getIO()->hasEntry())
799 aStudy->setVisibilityState(anActor->getIO()->getEntry(), Qtx::ShownState);
801 } catch(std::exception& exc) {
802 SUIT_MessageBox::warning
803 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
804 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()) );
806 QApplication::restoreOverrideCursor();
811 //------------------------------------------------------------
813 RepaintViewWindows (const SalomeApp_Module* theModule,
814 const Handle(SALOME_InteractiveObject)& theIObject)
816 TViewWindows aViewWindows;
817 if (SalomeApp_Application* anApp = theModule->getApp()) {
818 ViewManagerList aViewManagerList;
819 anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
820 QList<SUIT_ViewManager*>::Iterator anIter = aViewManagerList.begin();
821 while ( anIter != aViewManagerList.end() )
823 QVector<SUIT_ViewWindow*> aViews = (*anIter)->getViews();
824 for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
825 if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
826 if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
827 if (vw->isVisible(theIObject)) {
828 vw->getRenderer()->ResetCameraClippingRange();
830 vw->highlight(theIObject, true, true);
840 //------------------------------------------------------------
842 FindActor(const SalomeApp_Study* theStudy,
843 SVTK_ViewWindow* theViewWindow,
844 const QString& theEntry)
846 TObjectInfo anObjectInfo = GetObjectByEntry(theStudy, theEntry.toLatin1().data());
847 VISU::Prs3d_i* aPrs3d = GetPrs3dFromBase(anObjectInfo.myBase);
848 return FindActor(theViewWindow, aPrs3d);
851 //------------------------------------------------------------
853 FindActorBase(const SalomeApp_Study* theStudy,
854 SVTK_ViewWindow* theViewWindow,
855 const QString& theEntry)
857 TObjectInfo anObjectInfo = GetObjectByEntry(theStudy, theEntry.toLatin1().constData());
858 VISU::PointMap3d_i* aTable = dynamic_cast<VISU::PointMap3d_i*>(anObjectInfo.myBase);
859 return FindActorBase(theViewWindow, aTable);
862 //------------------------------------------------------------
864 RecreateActor (const SalomeApp_Module* theModule,
865 VISU::Prs3d_i* thePrs)
867 QApplication::setOverrideCursor(Qt::WaitCursor);
869 /* SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
870 CORBA::String_var anEntry = aSObject->GetID();*/
873 thePrs->UpdateActors();
874 } catch (std::runtime_error& exc) {
876 QApplication::restoreOverrideCursor();
877 SUIT_MessageBox::warning
878 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
879 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()) );
881 thePrs->RemoveActors();
884 QApplication::restoreOverrideCursor();
887 //------------------------------------------------------------
889 ComputeVisiblePropBounds(SVTK_ViewWindow* theViewWindow,
890 vtkFloatingPointType allBounds[6],
891 const char* theActorClassName)
893 vtkRenderer *aRen = theViewWindow->getRenderer();
894 VTK::ActorCollectionCopy aCopy(aRen->GetActors());
895 vtkActorCollection *anActColl = aCopy.GetActors();
897 vtkFloatingPointType *bounds;
898 int somethingVisible = false;
900 allBounds[0] = allBounds[2] = allBounds[4] = VTK_LARGE_FLOAT;
901 allBounds[1] = allBounds[3] = allBounds[5] = -VTK_LARGE_FLOAT;
902 // loop through all props
903 for (anActColl->InitTraversal(); (prop = anActColl->GetNextProp()); ) {
904 // if it's invisible, or has no geometry, we can skip the rest
905 if (prop->GetVisibility() && prop->IsA(theActorClassName)) {
906 bounds = prop->GetBounds();
907 // make sure we haven't got bogus bounds
908 if (bounds != NULL &&
909 bounds[0] > -VTK_LARGE_FLOAT && bounds[1] < VTK_LARGE_FLOAT &&
910 bounds[2] > -VTK_LARGE_FLOAT && bounds[3] < VTK_LARGE_FLOAT &&
911 bounds[4] > -VTK_LARGE_FLOAT && bounds[5] < VTK_LARGE_FLOAT)
913 somethingVisible = true;
914 if (bounds[0] < allBounds[0]) allBounds[0] = bounds[0];
915 if (bounds[1] > allBounds[1]) allBounds[1] = bounds[1];
916 if (bounds[2] < allBounds[2]) allBounds[2] = bounds[2];
917 if (bounds[3] > allBounds[3]) allBounds[3] = bounds[3];
918 if (bounds[4] < allBounds[4]) allBounds[4] = bounds[4];
919 if (bounds[5] > allBounds[5]) allBounds[5] = bounds[5];
923 return somethingVisible;
926 //------------------------------------------------------------
927 void SetFitAll(SVTK_ViewWindow* theViewWindow)
929 static vtkFloatingPointType PRECISION = 0.000001;
930 static vtkFloatingPointType DEVIATION = 600;
931 vtkFloatingPointType XYZ_Bnd[6];
932 if (!ComputeVisiblePropBounds(theViewWindow, XYZ_Bnd)) return;
934 vtkFloatingPointType absX = XYZ_Bnd[1] - XYZ_Bnd[0];
935 vtkFloatingPointType absY = XYZ_Bnd[3] - XYZ_Bnd[2];
936 vtkFloatingPointType absZ = XYZ_Bnd[5] - XYZ_Bnd[4];
938 enum CameraOrient {e3D, eFront, eLeft, eTop};
939 CameraOrient aCameraOrient = e3D;
940 if (absX <= PRECISION) aCameraOrient = eFront;
942 if (absY <= PRECISION) aCameraOrient = eLeft;
944 if (absZ <= PRECISION) aCameraOrient = eTop;
946 // all the three dimensions exceeds precision
947 vtkFloatingPointType dev_abs_XY = absX / absY;
948 vtkFloatingPointType dev_abs_YZ = absY / absZ;
949 vtkFloatingPointType dev_abs_XZ = absX / absZ;
950 if (dev_abs_XY >= DEVIATION || 1./dev_abs_YZ >= DEVIATION)
951 aCameraOrient = eLeft;
953 if (1./dev_abs_XY >= DEVIATION || 1./dev_abs_XZ >= DEVIATION)
954 aCameraOrient = eFront;
956 if (dev_abs_XZ >= DEVIATION || dev_abs_YZ >= DEVIATION)
957 aCameraOrient = eTop;
964 switch (aCameraOrient) {
965 case eFront: theViewWindow->onFrontView(); break;
966 case eLeft: theViewWindow->onLeftView(); break;
967 case eTop: theViewWindow->onTopView(); break;
968 case e3D: theViewWindow->onResetView(); break;
970 theViewWindow->getRenderer()->ResetCameraClippingRange();
971 theViewWindow->onFitAll();
974 //************************************************************
978 GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate)
980 if(SalomeApp_Application* anApp = theModule->getApp()){
981 if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){
982 return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
988 //------------------------------------------------------------
990 PlotTable(const SalomeApp_Module* theModule,
991 VISU::Table_i* table,
994 SalomeApp_Study* aStudy = GetAppStudy( theModule );
998 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
1001 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1005 // implementation moved to VISU_I package (see VISU_Tools.h)
1006 VISU::PlotTable( aStudy, aPlot, table, theDisplaying );
1009 //------------------------------------------------------------
1011 PlotCurve(const SalomeApp_Module* theModule,
1012 VISU::Curve_i* theCurve,
1015 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1018 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1022 // implementation moved to VISU_I package (see VISU_Tools.h)
1023 VISU::PlotCurve( aPlot, theCurve, theDisplaying );
1026 //------------------------------------------------------------
1028 PlotRemoveCurve(const SalomeApp_Module* theModule,
1029 VISU::Curve_i* pCrv)
1031 // implementation moved to VISU_I package (see VISU_Tools.h)
1032 VISU::PlotRemoveCurve( theModule->getApp(), pCrv );
1035 //------------------------------------------------------------
1037 PlotContainer(const SalomeApp_Module* theModule,
1038 VISU::Container_i* container,
1041 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1044 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1048 // implementation moved to VISU_I package (see VISU_Tools.h)
1049 VISU::PlotContainer( aPlot, container, theDisplaying );
1052 //------------------------------------------------------------
1054 CreatePlot(SalomeApp_Module* theModule,
1055 _PTR(SObject) theTableSO)
1057 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1060 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1064 VISU::VISU_Gen_i* aVisuGen = VISU::GetVisuGen( theModule );
1066 // implementation moved to VISU_I package (see VISU_Tools.h)
1067 VISU::CreatePlot( aVisuGen, aPlot, theTableSO );
1070 //************************************************************
1073 CreateMesh(VisuGUI* theModule,
1074 const Handle(SALOME_InteractiveObject)& theIO,
1075 SVTK_ViewWindow* theViewWindow)
1077 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
1078 //if (CheckLock(aStudy))
1081 _PTR(SObject) aResultSObj = aStudy->FindObjectID(theIO->getEntry());
1084 VISU::Result_var aResult;
1085 VISU::Result_i* pResult = CheckResult(theModule, aResultSObj, aResult);
1086 if (pResult == NULL)
1089 Storable::TRestoringMap aMap = Storable::GetStorableMap(aResultSObj);
1093 CORBA::Object_var aMesh;
1094 string aComment = Storable::FindValue(aMap,"myComment").toLatin1().data();
1095 string aMeshName = Storable::FindValue(aMap,"myMeshName").toLatin1().data();
1100 if (aComment == "ENTITY") {
1101 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myId").toInt();
1102 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity))
1103 aMesh = GetVisuGen(theModule)->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
1104 } else if (aComment == "FAMILY") {
1105 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myEntityId").toInt();
1106 string aFamilyName = Storable::FindValue(aMap,"myName").toLatin1().data();
1107 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()))
1108 aMesh = GetVisuGen(theModule)->FamilyMeshOnEntity
1109 (aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
1110 } else if (aComment == "GROUP") {
1111 string aGroupName = Storable::FindValue(aMap,"myName").toLatin1().data();
1112 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str()))
1113 aMesh = GetVisuGen(theModule)->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
1117 MESSAGE("VisuGUI::CreateMesh() - CREATE MESH");
1121 //QApplication::restoreOverrideCursor();
1122 VISU::Mesh_i* pPresent = NULL;
1123 if (!CORBA::is_nil(aMesh))
1124 pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
1125 if (pPresent == NULL) {
1126 SUIT_MessageBox::warning (GetDesktop(theModule),
1127 QObject::tr("WRN_VISU"),
1128 QObject::tr("ERR_CANT_BUILD_PRESENTATION") );
1132 if (theViewWindow) {
1138 if(GetResourceMgr()->booleanValue("VISU","display_only",false)){
1139 const VisuGUI* av = dynamic_cast<const VisuGUI*>(theModule);
1140 if(av)(const_cast<VisuGUI*>(av))->OnEraseAll();
1142 PublishMeshInView(theModule, pPresent, theViewWindow);
1143 if(GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false)){
1144 SetFitAll(theViewWindow);
1148 MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
1151 } catch (std::runtime_error& exc) {
1153 SUIT_MessageBox::warning(GetDesktop(theModule), QObject::tr("WRN_VISU"),
1154 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()) );
1158 UpdateObjBrowser(theModule, false, aResultSObj);
1160 theModule->application()->putInfo(QObject::tr("INF_DONE"));
1161 // Make "Save" button active
1162 theModule->getApp()->updateActions();
1166 // ========================================================================================
1167 // GetPrs3dList: find list of presentations for the given object
1168 // ========================================================================================
1169 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1170 const Handle(SALOME_InteractiveObject)& theIO,
1173 std::vector<VISU::Prs3d_i*> aList;
1174 if (!theIO.IsNull() && theIO->hasEntry()) {
1175 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1176 _PTR(SObject) aSObject = aCStudy->FindObjectID(theIO->getEntry());
1177 aList = GetPrs3dList(theModule, aSObject, theGP);
1182 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1183 _PTR(SObject) theObject,
1186 std::vector<VISU::Prs3d_i*> aList; int k = 0;
1190 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1192 CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(theObject);
1193 if (!CORBA::is_nil(aCORBAObject)) {
1194 VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
1195 if (!CORBA::is_nil(aVisuObj)) {
1196 VISU::VISUType aType = aVisuObj->GetType();
1198 case VISU::TGAUSSPOINTS:
1199 if ( !theGP ) break;
1200 case VISU::TSCALARMAP:
1201 case VISU::TISOSURFACES:
1202 case VISU::TDEFORMEDSHAPE:
1203 case VISU::TCUTPLANES:
1204 case VISU::TCUTLINES:
1205 case VISU::TCUTSEGMENT:
1206 case VISU::TVECTORS:
1207 case VISU::TSTREAMLINES:
1209 case VISU::TSCALARMAPONDEFORMEDSHAPE:
1210 case VISU::TDEFORMEDSHAPEANDSCALARMAP:
1213 PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1214 if (aServant.in()) {
1215 VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
1217 aList[k] = aPrsObject;
1224 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1225 _PTR(SObject) aTimeStamp;
1226 anIter->Next(); // First is reference on support
1227 for (; anIter->More(); anIter->Next()) {
1228 aTimeStamp = anIter->Value();
1229 if (!aTimeStamp) continue;
1230 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1231 if (!aSubList.empty()) {
1232 int n = aSubList.size();
1234 for (int i = 0; i < n; i++) {
1235 aList[k] = aSubList[i];
1242 case VISU::TCOLOREDPRS3DHOLDER:
1244 PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1245 if (aServant.in()) {
1246 VISU::ColoredPrs3dHolder_i* aPrsHolderObject = dynamic_cast<VISU::ColoredPrs3dHolder_i*>(aServant.in());
1247 if( aPrsHolderObject ) {
1248 VISU::Prs3d_i* aPrsObject = aPrsHolderObject->GetPrs3dDevice();
1250 aList[k] = aPrsObject;
1258 VISU::VISUType aType = VISU::Storable::SObject2Type(theObject);
1260 case VISU::TFIELD: {
1261 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1262 _PTR(SObject) aTimeStamp;
1263 anIter->Next(); // First is reference on support
1264 for (; anIter->More(); anIter->Next()) {
1265 aTimeStamp = anIter->Value();
1266 if (!aTimeStamp) continue;
1267 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1268 if (!aSubList.empty()) {
1269 int n = aSubList.size();
1271 for (int i = 0; i < n; i++) {
1272 aList[k] = aSubList[i];
1279 case VISU::TTIMESTAMP: {
1280 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1282 for (; anIter->More(); anIter->Next()) {
1283 aPrs = anIter->Value();
1284 if (!aPrs) continue;
1285 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
1286 if (!aSubList.empty()) {
1287 int n = aSubList.size();
1289 for (int i = 0; i < n; i++) {
1290 aList[k] = aSubList[i];
1301 //------------------------------------------------------------
1302 int GetFreePositionOfDefaultScalarBar(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow)
1305 std::set<int> aIndexes;
1306 TViewToPrs3d aMap = theModule->getScalarBarsMap();
1307 TViewToPrs3d::const_iterator aViewToPrsIter = aMap.find(theViewWindow);
1308 if (aViewToPrsIter != aMap.end()) {
1309 TSetPrs3d::const_iterator aPrsIter = (aViewToPrsIter->second).begin();
1310 for (; aPrsIter != (aViewToPrsIter->second).end(); aPrsIter++) {
1311 aIndexes.insert((*aPrsIter).second);
1314 std::set<int>::const_iterator aIter = aIndexes.begin();
1315 for (int i = 1,length = aIndexes.size(); i <= length; i++) {
1316 std::set<int>::const_iterator aIter = aIndexes.find(i);
1317 if (aIter == aIndexes.end()) { minIndx = i; break; }
1318 else minIndx = i + 1;
1323 //------------------------------------------------------------
1324 void AddScalarBarPosition (VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1325 VISU::Prs3d_i* thePrs3d, int pos)
1327 TViewToPrs3d& aMap = theModule->getScalarBarsMap();
1328 TPrs3dToInd aPair; aPair.first = thePrs3d; aPair.second = pos;
1329 aMap[theViewWindow].insert(aPair);
1332 //------------------------------------------------------------
1333 void RemoveScalarBarPosition(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1334 VISU::Prs3d_i* thePrs3d)
1336 TViewToPrs3d& aMap = theModule->getScalarBarsMap();
1337 TSetPrs3d::iterator aIter = aMap[theViewWindow].begin();
1338 for (; aIter != aMap[theViewWindow].end(); aIter++)
1339 if ((*aIter).first == thePrs3d) {
1340 aMap[theViewWindow].erase(*aIter);
1344 //------------------------------------------------------------
1345 bool getClippingPlanesFolder(_PTR(Study) theStudy, _PTR(SObject)& theSObject)
1347 _PTR(SComponent) aVisuSO = theStudy->FindComponent("VISU");
1348 if (!aVisuSO) return false;
1349 _PTR(SObject) aFolder = theStudy->FindObject(CLIP_PLANES_FOLDER);
1351 _PTR(StudyBuilder) aBuilder = theStudy->NewBuilder();
1352 aFolder = aBuilder->NewObject(aVisuSO);
1354 _PTR(GenericAttribute) anAttr;
1355 anAttr = aBuilder->FindOrCreateAttribute(aFolder,"AttributeName");
1356 _PTR(AttributeName) aName(anAttr);
1357 aName->SetValue(CLIP_PLANES_FOLDER);
1359 theSObject = aFolder;
1363 //------------------------------------------------------------
1364 void initSpinBox( SalomeApp_IntSpinBox* sb,
1369 sb->setAcceptNames( false );
1370 sb->setRange( bottom, top );
1371 sb->setSingleStep( step );
1374 //------------------------------------------------------------
1375 void initSpinBox( SalomeApp_DoubleSpinBox* sb,
1376 const double& bottom,
1379 const char* quantity )
1381 // Obtain precision from preferences
1382 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1383 int precision = resMgr->integerValue( "VISU", quantity, 3 );
1385 sb->setPrecision ( precision );
1386 sb->setDecimals ( qAbs(precision) );
1387 sb->setRange ( bottom, top );
1388 sb->setSingleStep ( step );
1389 sb->setDefaultValue( bottom );
1390 sb->setAcceptNames ( false );
1392 // Add a hint for the user saying how to tune precision
1393 QString userPropName = QObject::tr( QString( "VISU_PREF_%1" ).arg( quantity ).toLatin1().constData() );
1394 sb->setProperty( "validity_tune_hint",
1395 QVariant( QObject::tr( "VISU_PRECISION_HINT" ).arg( userPropName ) ) );