1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2005 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
24 // File : VisuGUI_Tools.cxx
25 // Author : Sergey Anikin
29 #include "VisuGUI_Tools.h"
32 #include "VisuGUI_ViewTools.h"
34 #include "VISU_Gen_i.hh"
35 #include "VISU_Prs3d_i.hh"
36 #include "VISU_Result_i.hh"
37 #include "VISU_Table_i.hh"
38 #include "VISU_Mesh_i.hh"
39 #include "VISU_ViewManager_i.hh"
41 #include "VISU_Actor.h"
42 #include "VISU_ScalarMapAct.h"
44 #include "SalomeApp_Module.h"
45 #include "SalomeApp_Study.h"
46 #include "SalomeApp_Application.h"
48 #include "LightApp_DataObject.h"
49 #include "LightApp_SelectionMgr.h"
51 #include "OB_Browser.h"
53 #include "SALOME_ListIO.hxx"
54 #include "SALOME_ListIteratorOfListIO.hxx"
56 #include "SVTK_ViewWindow.h"
57 #include "SVTK_Functor.h"
59 #include "VTKViewer_Algorithm.h"
61 #include "SPlot2d_ViewModel.h"
62 #include "Plot2d_ViewFrame.h"
63 #include "Plot2d_ViewManager.h"
65 #include "SUIT_Session.h"
66 #include "SUIT_MessageBox.h"
68 #include <vtkRenderer.h>
69 #include <vtkActorCollection.h>
72 //=============================================================================
76 GetDesktop(const CAM_Module* theModule)
78 return theModule->application()->desktop();
81 LightApp_SelectionMgr*
82 GetSelectionMgr(const SalomeApp_Module* theModule)
84 return theModule->getApp()->selectionMgr();
88 GetAppStudy(const CAM_Module* theModule)
91 dynamic_cast<SalomeApp_Study*>(theModule->application()->activeStudy());
95 GetCStudy(const SalomeApp_Study* theStudy)
97 return theStudy->studyDS();
101 IsStudyLocked( _PTR(Study) theStudy )
104 return theStudy->GetProperties()->IsLocked();
109 CheckLock( _PTR(Study) theStudy,
112 if(IsStudyLocked(theStudy)){
113 SUIT_MessageBox::warn1(theWidget,
114 QObject::tr("WRN_VISU_WARNING"),
115 QObject::tr("WRN_STUDY_LOCKED"),
116 QObject::tr("BUT_OK"));
123 FindDataObject(SUIT_DataObject* theDataObject,
124 const QString& theEntry,
127 int aLevel = theDataObject->level() + 2;
128 QString aSourceEntry = theEntry.section(':',0,aLevel);
129 DataObjectList aList;
130 theDataObject->children(aList);
131 DataObjectListIterator aDataObjectIter(aList);
132 while(SUIT_DataObject* aDataObject = aDataObjectIter.current()){
133 if(LightApp_DataObject* aChildDataObject = dynamic_cast<LightApp_DataObject*>(aDataObject)){
134 QString anEntry = aChildDataObject->entry();
135 QString aCurrentEntry = anEntry.section(':',0,aLevel);
136 if(aSourceEntry == aCurrentEntry){
137 if(theLevel == aLevel){
138 return aChildDataObject;
140 return FindDataObject(aChildDataObject,theEntry,theLevel);
150 FindDataObject(CAM_Module* theModule,
151 _PTR(SObject) theSObject)
153 CAM_DataModel* aDataModel = theModule->dataModel();
154 CAM_DataObject* aRootDataObject = aDataModel->root();
155 if(_PTR(SComponent) aComponent = theSObject)
156 return dynamic_cast<LightApp_DataObject*>(aRootDataObject);
158 int aLevel = theSObject->Depth();
159 std::string anEntry = theSObject->GetID();
160 return FindDataObject(aRootDataObject,anEntry.c_str(),aLevel);
164 UpdateObjBrowser(SalomeApp_Module* theModule,
165 bool theIsUpdateDataModel,
166 _PTR(SObject) theSObject)
168 LightApp_DataObject* aDataObject = NULL;
170 aDataObject = FindDataObject(theModule,theSObject);
172 theModule->updateObjBrowser(theIsUpdateDataModel,aDataObject);
173 theModule->getApp()->updateActions();
177 IsSObjectTable( _PTR(SObject) theSObject )
180 _PTR(GenericAttribute) anAttr;
181 if (theSObject->FindAttribute( anAttr, "AttributeTableOfInteger" ))
183 if (theSObject->FindAttribute( anAttr, "AttributeTableOfReal" ))
190 GetVisuGen(const CAM_Module* theModule)
192 static VISU_Gen_i* aGen = NULL;
194 SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
195 Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","VISU");
196 VISU_Gen_var aVISU = VISU_Gen::_narrow(aComponent);
197 if(!CORBA::is_nil(aVISU)){
198 aGen = VISU_Gen_i::GetVisuGenImpl();
199 aGen->SetCurrentStudy(GetDSStudy(GetCStudy(GetAppStudy(theModule))));
203 throw std::runtime_error(QObject::tr("ERR_CANT_FIND_VISU_COMPONENT").latin1());
207 SALOME_MED::MED_Gen_var
210 static SALOME_MED::MED_Gen_var aGen;
211 if(CORBA::is_nil(aGen)){
212 SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
213 Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","MED");
214 aGen = SALOME_MED::MED_Gen::_narrow(aComponent);
216 if(CORBA::is_nil(aGen))
217 throw std::runtime_error(QObject::tr("ERR_CANT_FIND_MED_COMPONENT").latin1());
222 VISU::Storable::TRestoringMap getMapOfValue (_PTR(SObject) theSObject)
224 VISU::Storable::TRestoringMap aMap;
226 _PTR(GenericAttribute) anAttr;
227 if (theSObject->FindAttribute(anAttr, "AttributeComment")) {
228 _PTR(AttributeComment) aComment (anAttr);
229 std::string aValue = aComment->Value();
230 QString aString (aValue.c_str());
231 VISU::Storable::StrToMap(aString, aMap);
237 QString getValue (_PTR(SObject) theSObject, QString theKey)
240 VISU::Storable::TRestoringMap aMap = getMapOfValue(theSObject);
242 aStr = VISU::Storable::FindValue(aMap, theKey.latin1());
246 //------------------------------------------------------------
249 GetSelectedObj(const SalomeApp_Study* theStudy,
250 const QString& theEntry,
251 VISU::Storable::TRestoringMap* theMap)
253 if (!theStudy || theEntry.isEmpty())
254 return CORBA::Object::_nil();
256 _PTR(Study) aStudy = GetCStudy(theStudy);
257 _PTR(SObject) aSObject = aStudy->FindObjectID(theEntry.latin1());
259 _PTR(GenericAttribute) anAttr;
260 if (theMap && aSObject->FindAttribute(anAttr,"AttributeComment")) {
261 _PTR(AttributeComment) aComment (anAttr);
262 std::string aValue = aComment->Value();
263 QString aString (aValue.c_str());
264 VISU::Storable::StrToMap(aString, *theMap);
266 return VISU::ClientSObjectToObject(aSObject);
268 return CORBA::Object::_nil();
272 GetSelectedObj(const SalomeApp_Module* theModule,
273 Handle(SALOME_InteractiveObject)* theIO,
274 VISU::Storable::TRestoringMap* theMap)
276 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
277 SALOME_ListIO aListIO;
278 aSelectionMgr->selectedObjects(aListIO);
279 SALOME_ListIteratorOfListIO anIter(aListIO);
281 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
285 return GetSelectedObj( GetAppStudy(theModule), anIO->getEntry(), theMap );
287 return CORBA::Object::_nil();
291 GetPrsToModify(const SalomeApp_Module* theModule,
292 Handle(SALOME_InteractiveObject)* theIO,
293 VISU::Storable::TRestoringMap* theMap)
295 if (CheckLock(GetCStudy(GetAppStudy(theModule)),GetDesktop(theModule)))
298 CORBA::Object_var anObject = GetSelectedObj(theModule, theIO);
299 if (CORBA::is_nil(anObject))
302 PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
306 return dynamic_cast<VISU::Prs3d_i*>(aServant.in());
310 Add(LightApp_SelectionMgr* theSelectionMgr,
311 const Handle(SALOME_InteractiveObject)& theIO)
313 SALOME_ListIO aListIO;
314 theSelectionMgr->selectedObjects(aListIO);
315 aListIO.Append(theIO);
316 theSelectionMgr->setSelectedObjects(aListIO);
320 Remove(LightApp_SelectionMgr* theSelectionMgr,
321 const Handle(SALOME_InteractiveObject)& theIO)
323 if (theIO.IsNull()) return;
324 SALOME_ListIO aListIO, aNewListIO;
325 theSelectionMgr->selectedObjects(aListIO);
326 SALOME_ListIteratorOfListIO anIter (aListIO);
327 for (; anIter.More(); anIter.Next()) {
328 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
329 if (!anIO->isSame(theIO)) {
330 aNewListIO.Append(theIO);
333 theSelectionMgr->setSelectedObjects(aNewListIO);
337 * \brief Check, if "Delete" popup-menu can be put on current selection
339 * \param theModule - is used to access SelectionManager, Study and VISU_Gen
340 * \retval bool - returns TRUE if all currently selected objects are removable
343 IsRemovableSelected (const SalomeApp_Module* theModule)
345 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
346 SALOME_ListIO aListIO;
347 aSelectionMgr->selectedObjects(aListIO);
349 if (aListIO.Extent() < 1)
352 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
353 if (!aStudy) return false;
355 // In some cases single selection can have its own popup-menu item for deletion
356 /*if (aListIO.Extent() == 1) {
357 Handle(SALOME_InteractiveObject) anIO = aListIO.First();
358 _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry());
360 VISU::VISUType aType = (VISU::VISUType)getValue(aSObject, "myType").toInt();
361 if (aType == VISU::TVIEW3D) {
362 return false; // special case
367 SALOME_ListIteratorOfListIO anIter (aListIO);
368 for (; anIter.More(); anIter.Next()) {
369 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
370 if (anIO->hasEntry()) {
372 // asv : if selected object is a Save Point object selected in object browser - return false
373 if ( QString( anIO->getEntry() ).startsWith( QObject::tr( "SAVE_POINT_DEF_NAME" ) ) )
376 _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry());
377 VISU::Storable::TRestoringMap pMap;
379 CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(aSObject);
380 if (!CORBA::is_nil(aCORBAObject)) {
381 VISU::RemovableObject_var aRemovableObj = VISU::RemovableObject::_narrow(aCORBAObject);
382 if (CORBA::is_nil(aRemovableObj)) {
383 // Not removable CORBA object
387 // Can be removed, if lays directly under VISU
388 // (first sub-level) or is a child of such an object
389 string aNAME, aVisuNAME = GetVisuGen(theModule)->ComponentDataType();
390 _PTR(GenericAttribute) anAttr;
391 _PTR(AttributeComment) aComment;
393 bool isUnderVISU = false;
394 _PTR(SObject) aFatherSObject = aSObject->GetFather();
395 if (aFatherSObject->FindAttribute(anAttr, "AttributeComment")) {
396 _PTR(AttributeComment) aComment (anAttr);
397 aNAME = aComment->Value();
398 if (aNAME == aVisuNAME) {
403 // Not directly under VISU component, check father
404 aCORBAObject = VISU::ClientSObjectToObject(aFatherSObject);
405 if (!CORBA::is_nil(aCORBAObject)) {
411 aFatherSObject = aFatherSObject->GetFather();
412 if (aFatherSObject->FindAttribute(anAttr, "AttributeComment")) {
413 _PTR(AttributeComment) aComment (anAttr);
414 aNAME = aComment->Value();
415 if (aNAME == aVisuNAME) {
420 // Father is not directly under VISU component
432 DeleteSObject(VisuGUI* theModule,
433 _PTR(Study) theStudy,
434 _PTR(SObject) theSObject)
436 _PTR(ChildIterator) aChildIter = theStudy->NewChildIterator(theSObject);
437 for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
438 _PTR(SObject) aChildSObject = aChildIter->Value();
439 CORBA::Object_var aChildObj = VISU::ClientSObjectToObject(aChildSObject);
440 ErasePrs(theModule, aChildObj, /*repaint_view_window = */false);
443 CORBA::Object_var anObj = VISU::ClientSObjectToObject(theSObject);
444 if (!CORBA::is_nil(anObj)) {
445 ErasePrs(theModule, anObj, /*repaint_view_window = */true);
447 VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObj);
448 if (!CORBA::is_nil(aRemovableObject)) {
449 aRemovableObject->RemoveFromStudy();
452 // Remove aSObject together with all its sub-objects
454 VISU::RemoveFromStudy(theSObject,
455 false, // remove not only IOR attribute, but Object With Children
456 false); // not Destroy() sub-objects
461 DeletePrs3d(VisuGUI* theModule,
462 VISU::Prs3d_i* thePrs,
463 const Handle(SALOME_InteractiveObject)& theIO)
467 if (CheckLock(GetCStudy(GetAppStudy(theModule)),GetDesktop(theModule)))
470 SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
471 RemoveScalarBarPosition(theModule, vw, thePrs);
473 thePrs->RemoveFromStudy();
476 // Presentation management
479 ChangeRepresentation (const SalomeApp_Module* theModule,
480 VISU::PresentationType theType)
482 SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
486 Handle(SALOME_InteractiveObject) anIO;
487 CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
488 if (CORBA::is_nil(anObject)) return;
490 VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
491 if (CORBA::is_nil(aVisuObj)) return;
493 PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
494 if (!aServant.in()) return;
496 VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
498 if (VISU_Actor* anActor = GetActor(aPrs3d, vw)) {
501 if (anActor->IsShrunk())
504 anActor->SetShrink();
507 if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
508 aMesh->SetPresentationType(theType);
509 RecreateActor(theModule, aMesh);
511 anActor->SetRepresentation(theType);
520 SetShading ( const SalomeApp_Module* theModule,
523 SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
527 Handle(SALOME_InteractiveObject) anIO;
528 CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
529 if (CORBA::is_nil(anObject)) return;
531 VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
532 if (CORBA::is_nil(aVisuObj)) return;
534 PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
535 if (!aServant.in()) return;
537 VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
539 if (VISU_Actor* anActor = GetActor(aPrs3d, vw)) {
540 if ( VISU_ScalarMapAct* aScalarMapActor = dynamic_cast<VISU_ScalarMapAct*>(anActor) )
541 aScalarMapActor->SetShading( theOn );
550 CheckTimeStamp(const SalomeApp_Module* theModule,
551 _PTR(SObject)& theSObject,
552 Handle(SALOME_InteractiveObject)* theIO)
554 Handle(SALOME_InteractiveObject) anIO;
555 CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
558 if (!anIO.IsNull() && anIO->hasEntry()){
559 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
560 theSObject = aStudy->FindObjectID(anIO->getEntry());
561 QString aValue = getValue(theSObject,"myType");
562 if (aValue.toInt() == int(VISU::TTIMESTAMP))
565 SUIT_MessageBox::warn1(GetDesktop(theModule),
566 QObject::tr("WRN_VISU"),
567 QObject::tr("WRN_NO_AVAILABLE_DATA"),
568 QObject::tr("BUT_OK") );
573 CheckResult(const SalomeApp_Module* theModule,
574 _PTR(SObject) theSource,
575 VISU::Result_var& theResult)
577 if(theSource->Depth() < 3) // Bug of SALOMEDS : can\t get father from root object
580 _PTR(SObject) aSObj = theSource->GetFather();
584 aSObj = aSObj->GetFather();
588 aSObj = aSObj->GetFather();
592 CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
593 if (CORBA::is_nil(anObject)) {
594 aSObj = aSObj->GetFather();
597 anObject = VISU::ClientSObjectToObject(aSObj);
600 if (CORBA::is_nil(anObject))
603 theResult = VISU::Result::_narrow(anObject);
604 return dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
610 PublishMeshInView(const SalomeApp_Module* theModule,
611 VISU::Prs3d_i* thePrs,
612 SVTK_ViewWindow* theViewWindow)
614 VISU_Actor* aActor = NULL;
615 if (!thePrs || !theViewWindow)
618 QApplication::setOverrideCursor( Qt::waitCursor );
620 if ((aActor = thePrs->CreateActor()))
621 theViewWindow->AddActor(aActor);
622 } catch(std::exception& exc) {
623 SUIT_MessageBox::warn1
624 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
625 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()),
626 QObject::tr("BUT_OK"));
628 QApplication::restoreOverrideCursor();
634 RepaintViewWindows (const SalomeApp_Module* theModule,
635 const Handle(SALOME_InteractiveObject)& theIObject)
637 TViewWindows aViewWindows;
638 if (SalomeApp_Application* anApp = theModule->getApp()) {
639 ViewManagerList aViewManagerList;
640 anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
641 QPtrListIterator<SUIT_ViewManager> anIter (aViewManagerList);
642 while (SUIT_ViewManager* aViewManager = anIter.current()) {
643 QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
644 for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
645 if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
646 if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
647 if (vw->isVisible(theIObject)) {
648 vw->getRenderer()->ResetCameraClippingRange();
650 vw->highlight(theIObject, true, true);
661 FindActor(SVTK_ViewWindow* theViewWindow,
662 const char* theEntry)
664 using namespace SVTK;
665 if(vtkRenderer* aRenderer = theViewWindow->getRenderer()){
666 if(vtkActorCollection* aCollection = aRenderer->GetActors()){
667 if(VISU_Actor* anActor = Find<VISU_Actor>(aCollection,TIsSameEntry<VISU_Actor>(theEntry))){
676 FindActor(SVTK_ViewWindow* theViewWindow,
677 VISU::Prs3d_i* thePrs)
679 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
680 CORBA::String_var anEntry = aSObject->GetID();
681 return FindActor(theViewWindow,anEntry.in());
685 RecreateActor (const SalomeApp_Module* theModule,
686 VISU::Prs3d_i* thePrs)
688 QApplication::setOverrideCursor(Qt::waitCursor);
690 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
691 CORBA::String_var anEntry = aSObject->GetID();
694 thePrs->UpdateActors();
695 } catch (std::runtime_error& exc) {
697 QApplication::restoreOverrideCursor();
698 SUIT_MessageBox::warn1
699 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
700 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()),
701 QObject::tr("BUT_OK"));
703 thePrs->RemoveActors();
706 QApplication::restoreOverrideCursor();
711 ComputeVisiblePropBounds(SVTK_ViewWindow* theViewWindow,
712 vtkFloatingPointType allBounds[6],
713 const char* theActorClassName = "VISU_Actor")
715 vtkRenderer *aRen = theViewWindow->getRenderer();
716 vtkActorCollection *anActColl = aRen->GetActors();
718 vtkFloatingPointType *bounds;
719 int somethingVisible = false;
721 allBounds[0] = allBounds[2] = allBounds[4] = VTK_LARGE_FLOAT;
722 allBounds[1] = allBounds[3] = allBounds[5] = -VTK_LARGE_FLOAT;
723 // loop through all props
724 for (anActColl->InitTraversal(); (prop = anActColl->GetNextProp()); ) {
725 // if it's invisible, or has no geometry, we can skip the rest
726 if (prop->GetVisibility() && prop->IsA(theActorClassName)) {
727 bounds = prop->GetBounds();
728 // make sure we haven't got bogus bounds
729 if (bounds != NULL &&
730 bounds[0] > -VTK_LARGE_FLOAT && bounds[1] < VTK_LARGE_FLOAT &&
731 bounds[2] > -VTK_LARGE_FLOAT && bounds[3] < VTK_LARGE_FLOAT &&
732 bounds[4] > -VTK_LARGE_FLOAT && bounds[5] < VTK_LARGE_FLOAT)
734 somethingVisible = true;
735 if (bounds[0] < allBounds[0]) allBounds[0] = bounds[0];
736 if (bounds[1] > allBounds[1]) allBounds[1] = bounds[1];
737 if (bounds[2] < allBounds[2]) allBounds[2] = bounds[2];
738 if (bounds[3] > allBounds[3]) allBounds[3] = bounds[3];
739 if (bounds[4] < allBounds[4]) allBounds[4] = bounds[4];
740 if (bounds[5] > allBounds[5]) allBounds[5] = bounds[5];
744 return somethingVisible;
747 void SetFitAll(SVTK_ViewWindow* theViewWindow)
749 static vtkFloatingPointType PRECISION = 0.000001;
750 static vtkFloatingPointType DEVIATION = 600;
751 vtkFloatingPointType XYZ_Bnd[6];
752 if (!ComputeVisiblePropBounds(theViewWindow, XYZ_Bnd)) return;
754 vtkFloatingPointType absX = XYZ_Bnd[1] - XYZ_Bnd[0];
755 vtkFloatingPointType absY = XYZ_Bnd[3] - XYZ_Bnd[2];
756 vtkFloatingPointType absZ = XYZ_Bnd[5] - XYZ_Bnd[4];
758 enum CameraOrient {e3D, eFront, eLeft, eTop};
759 CameraOrient aCameraOrient = e3D;
760 if (absX <= PRECISION) aCameraOrient = eFront;
762 if (absY <= PRECISION) aCameraOrient = eLeft;
764 if (absZ <= PRECISION) aCameraOrient = eTop;
766 // all the three dimensions exceeds precision
767 vtkFloatingPointType dev_abs_XY = absX / absY;
768 vtkFloatingPointType dev_abs_YZ = absY / absZ;
769 vtkFloatingPointType dev_abs_XZ = absX / absZ;
770 if (dev_abs_XY >= DEVIATION || 1./dev_abs_YZ >= DEVIATION)
771 aCameraOrient = eLeft;
773 if (1./dev_abs_XY >= DEVIATION || 1./dev_abs_XZ >= DEVIATION)
774 aCameraOrient = eFront;
776 if (dev_abs_XZ >= DEVIATION || dev_abs_YZ >= DEVIATION)
777 aCameraOrient = eTop;
784 switch (aCameraOrient) {
785 case eFront: theViewWindow->onFrontView(); break;
786 case eLeft: theViewWindow->onLeftView(); break;
787 case eTop: theViewWindow->onTopView(); break;
788 case e3D: theViewWindow->onResetView(); break;
790 theViewWindow->getRenderer()->ResetCameraClippingRange();
791 theViewWindow->onFitAll();
794 //************************************************************
798 GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate)
800 if(SalomeApp_Application* anApp = theModule->getApp()){
801 if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){
802 return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
808 // Internal function used by several public functions below
810 UpdateCurve(VISU::Curve_i* theCurve,
811 Plot2d_ViewFrame* aPlot,
812 SPlot2d_Curve* plotCurve,
815 if ( theDisplaying == VISU::eErase ) {
816 if ( plotCurve && aPlot )
817 aPlot->eraseCurve( plotCurve, false );
819 else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
821 plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() );
822 //plotCurve->setVerTitle( ( theCurve->GetVerTitle().c_str() ) );
823 plotCurve->setVerTitle( theCurve->GetName() );
824 plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() );
825 plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() );
828 int nbPoints = theCurve->GetData( xList, yList );
829 if ( nbPoints > 0 && xList && yList ) {
830 plotCurve->setData( xList, yList, nbPoints );
832 if ( !theCurve->IsAuto() ) {
833 plotCurve->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
834 plotCurve->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() );
835 SALOMEDS::Color color = theCurve->GetColor();
836 plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
838 plotCurve->setAutoAssign( theCurve->IsAuto() );
840 aPlot->displayCurve( plotCurve, false );
843 Plot2d_Curve* crv = theCurve->CreatePresentation();
846 aPlot->displayCurve( crv, false );
847 theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
848 theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
849 SALOMEDS::Color newColor;
850 newColor.R = crv->getColor().red()/255.;
851 newColor.G = crv->getColor().green()/255.;
852 newColor.B = crv->getColor().blue()/255.;
853 theCurve->SetColor( newColor );
854 crv->setAutoAssign( theCurve->IsAuto() );
861 PlotTable(const SalomeApp_Module* theModule,
862 VISU::Table_i* table,
865 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
868 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
872 if ( theDisplaying == VISU::eDisplayOnly )
874 QList<Plot2d_Curve> clist;
875 aPlot->getCurves( clist );
876 _PTR(Study) aStudy = GetCStudy( GetAppStudy( theModule ) );
877 _PTR(SObject) TableSO = aStudy->FindObjectID( table->GetEntry().latin1() );
879 _PTR(ChildIterator) Iter = aStudy->NewChildIterator( TableSO );
880 for ( ; Iter->More(); Iter->Next() ) {
881 CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
882 if( !CORBA::is_nil( childObject ) ) {
883 CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
884 if( !CORBA::is_nil( aCurve ) ) {
885 VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
886 SPlot2d_Curve* plotCurve = 0;
887 SPlot2d_Curve* tmpCurve;
888 for ( int i = 0; i < clist.count(); i++ ) {
889 tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
890 if (tmpCurve && tmpCurve->hasIO() &&
891 !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
892 plotCurve = tmpCurve;
897 UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
899 if ( theDisplaying == VISU::eErase && plotCurve ) {
900 clist.remove( plotCurve );
910 PlotCurve(const SalomeApp_Module* theModule,
911 VISU::Curve_i* theCurve,
914 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
917 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
921 // if ( theDisplaying == VISU::eDisplayOnly )
922 // aPlot->EraseAll();
923 QList<Plot2d_Curve> clist;
924 aPlot->getCurves( clist );
925 SPlot2d_Curve* plotCurve = 0;
926 SPlot2d_Curve* tmpCurve;
927 for (int i = 0; i < clist.count(); i++) {
928 tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
929 if (tmpCurve && tmpCurve->hasIO() &&
930 !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
931 plotCurve = tmpCurve;
932 } else if (theDisplaying == VISU::eDisplayOnly) {
933 aPlot->eraseCurve(clist.at(i));
937 UpdateCurve(theCurve, aPlot, plotCurve, theDisplaying);
943 PlotRemoveCurve(const SalomeApp_Module* theModule,
946 QString anEntry = pCrv->GetEntry();
947 ViewManagerList pvm_list;
948 theModule->getApp()->viewManagers( SPlot2d_Viewer::Type(), pvm_list );
949 for( SUIT_ViewManager* mgr = pvm_list.first(); mgr; mgr = pvm_list.next() ){
950 Plot2d_ViewManager* pvm = dynamic_cast<Plot2d_ViewManager*>( mgr );
952 SPlot2d_Viewer* aSPlot2d = dynamic_cast<SPlot2d_Viewer*>( pvm->getViewModel() );
954 Plot2d_ViewFrame* aPlot = aSPlot2d->getActiveViewFrame();
956 QList<Plot2d_Curve> clist;
957 aPlot->getCurves( clist );
958 for (int i = 0; i < clist.count(); i++) {
959 if(SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i)))
960 if(plotCurve->hasIO() && (plotCurve->getIO()->getEntry() == anEntry))
961 aPlot->eraseCurve(clist.at(i));
970 PlotContainer(const SalomeApp_Module* theModule,
971 VISU::Container_i* container,
974 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
977 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
981 if ( theDisplaying == VISU::eDisplayOnly )
983 QList<Plot2d_Curve> clist;
984 aPlot->getCurves( clist );
985 if ( container->GetNbCurves() > 0 ) {
986 int nbCurves = container->GetNbCurves();
987 for ( int k = 1; k <= nbCurves; k++ ) {
988 VISU::Curve_i* theCurve = container->GetCurve( k );
989 if ( theCurve && theCurve->IsValid() ) {
990 SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>
991 (aView->getCurveByIO(new SALOME_InteractiveObject (theCurve->GetEntry(), "", "")));
993 UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
995 if ( plotCurve && theDisplaying == VISU::eErase ) {
996 clist.remove( plotCurve );
1005 CreatePlot(SalomeApp_Module* theModule,
1006 _PTR(SObject) theTableSO)
1008 if ( IsSObjectTable(theTableSO) ) {
1009 CORBA::Object_var aTable = VISU::ClientSObjectToObject(theTableSO);
1010 CORBA::Object_var aContainer = GetVisuGen( theModule )->CreateContainer();
1011 if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) {
1012 VISU::Table_i* pTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
1013 VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aContainer).in());
1015 if ( pContainer && pTable ) {
1016 for ( int i = 2; i <= pTable->GetNbRows(); i++ ) {
1017 CORBA::Object_var aNewCurve = GetVisuGen( theModule )->CreateCurve( pTable->_this(), 1, i );
1018 if( !CORBA::is_nil( aNewCurve ) ) {
1019 VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aNewCurve).in() );
1021 pContainer->AddCurve( pCrv->_this() );
1025 PlotContainer( theModule, pContainer, VISU::eDisplay );
1027 QString anEntry = pContainer->GetEntry();
1028 _PTR(Study) aStudy = theTableSO->GetStudy();
1029 _PTR(SObject) aContainerSO = aStudy->FindObjectID(anEntry.latin1());
1030 _PTR(SObject) aParentSO = aContainerSO->GetFather();
1031 UpdateObjBrowser(theModule,true,aParentSO);
1037 //************************************************************
1040 void CreateMesh (const SalomeApp_Module* theModule,
1041 const Handle(SALOME_InteractiveObject)& theIO,
1042 SVTK_ViewWindow* theViewWindow)
1044 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
1045 //if (CheckLock(aStudy))
1048 _PTR(SObject) aResultSObj = aStudy->FindObjectID(theIO->getEntry());
1051 VISU::Result_var aResult;
1052 VISU::Result_i* pResult = CheckResult(theModule, aResultSObj, aResult);
1053 if (pResult == NULL)
1056 Storable::TRestoringMap aMap = getMapOfValue(aResultSObj);
1058 string aComment = Storable::FindValue(aMap,"myComment",&isExist).latin1();
1062 CORBA::Object_var aMesh;
1063 string aMeshName = Storable::FindValue(aMap,"myMeshName").latin1();
1068 if (aComment == "ENTITY") {
1069 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myId").toInt();
1070 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity))
1071 aMesh = GetVisuGen(theModule)->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
1072 } else if (aComment == "FAMILY") {
1073 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myEntityId").toInt();
1074 string aFamilyName = Storable::FindValue(aMap,"myName").latin1();
1075 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()))
1076 aMesh = GetVisuGen(theModule)->FamilyMeshOnEntity
1077 (aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
1078 } else if (aComment == "GROUP") {
1079 string aGroupName = Storable::FindValue(aMap,"myName").latin1();
1080 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str()))
1081 aMesh = GetVisuGen(theModule)->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
1085 MESSAGE("VisuGUI::CreateMesh() - CREATE MESH");
1089 //QApplication::restoreOverrideCursor();
1090 VISU::Mesh_i* pPresent = NULL;
1091 if (!CORBA::is_nil(aMesh))
1092 pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
1093 if (pPresent == NULL) {
1094 SUIT_MessageBox::warn1 (GetDesktop(theModule),
1095 QObject::tr("WRN_VISU"),
1096 QObject::tr("ERR_CANT_BUILD_PRESENTATION"),
1097 QObject::tr("BUT_OK"));
1101 if (theViewWindow) {
1107 PublishMeshInView(theModule, pPresent, theViewWindow);
1108 SetFitAll(theViewWindow);
1111 MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
1114 } catch (std::runtime_error& exc) {
1116 SUIT_MessageBox::warn1
1117 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
1118 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()),
1119 QObject::tr("BUT_OK"));
1123 theModule->application()->putInfo(QObject::tr("INF_DONE"));
1124 // Make "Save" button active
1125 theModule->getApp()->updateActions();
1128 // ========================================================================================
1129 // GetPrs3dList: find list of presentations for the given object
1130 // ========================================================================================
1131 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1132 const Handle(SALOME_InteractiveObject)& theIO)
1134 std::vector<VISU::Prs3d_i*> aList;
1135 if (!theIO.IsNull() && theIO->hasEntry()) {
1136 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1137 _PTR(SObject) aSObject = aCStudy->FindObjectID(theIO->getEntry());
1138 aList = GetPrs3dList(theModule, aSObject);
1143 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1144 _PTR(SObject) theObject)
1146 std::vector<VISU::Prs3d_i*> aList; int k = 0;
1150 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1152 CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(theObject);
1153 if (!CORBA::is_nil(aCORBAObject)) {
1154 VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
1155 if (!CORBA::is_nil(aVisuObj)) {
1156 VISU::VISUType aType = aVisuObj->GetType();
1158 case VISU::TSCALARMAP:
1159 case VISU::TISOSURFACE:
1160 case VISU::TDEFORMEDSHAPE:
1161 case VISU::TCUTPLANES:
1162 case VISU::TCUTLINES:
1163 case VISU::TVECTORS:
1164 case VISU::TSTREAMLINES:
1166 case VISU::TSCALARMAPONDEFORMEDSHAPE:
1168 PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1169 if (aServant.in()) {
1170 VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
1172 aList[k] = aPrsObject;
1179 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1180 _PTR(SObject) aTimeStamp;
1181 anIter->Next(); // First is reference on support
1182 for (; anIter->More(); anIter->Next()) {
1183 aTimeStamp = anIter->Value();
1184 if (!aTimeStamp) continue;
1185 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1186 if (!aSubList.empty()) {
1187 int n = aSubList.size();
1189 for (int i = 0; i < n; i++) {
1190 aList[k] = aSubList[i];
1200 _PTR(GenericAttribute) anAttr;
1201 if (theObject->FindAttribute(anAttr, "AttributeComment")) {
1202 _PTR(AttributeComment) aComment (anAttr);
1203 string aComm = aComment->Value();
1204 QString strIn (aComm.c_str());
1205 VISU::Storable::TRestoringMap pMap;
1206 VISU::Storable::StrToMap(strIn, pMap);
1208 VISU::VISUType aType =
1209 (VISU::VISUType)VISU::Storable::FindValue(pMap,"myType",&isExist).toInt();
1214 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1215 _PTR(SObject) aTimeStamp;
1216 anIter->Next(); // First is reference on support
1217 for (; anIter->More(); anIter->Next()) {
1218 aTimeStamp = anIter->Value();
1219 if (!aTimeStamp) continue;
1220 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1221 if (!aSubList.empty()) {
1222 int n = aSubList.size();
1224 for (int i = 0; i < n; i++) {
1225 aList[k] = aSubList[i];
1232 case VISU::TTIMESTAMP:
1234 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1236 for (; anIter->More(); anIter->Next()) {
1237 aPrs = anIter->Value();
1238 if (!aPrs) continue;
1239 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
1240 if (!aSubList.empty()) {
1241 int n = aSubList.size();
1243 for (int i = 0; i < n; i++) {
1244 aList[k] = aSubList[i];
1258 int GetFreePositionOfDefaultScalarBar(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow)
1261 std::set<int> aIndexes;
1262 TViewToPrs3d aMap = theModule->getScalarBarsMap();
1263 TViewToPrs3d::const_iterator aViewToPrsIter = aMap.find(theViewWindow);
1264 if (aViewToPrsIter != aMap.end()) {
1265 TSetPrs3d::const_iterator aPrsIter = (aViewToPrsIter->second).begin();
1266 for (; aPrsIter != (aViewToPrsIter->second).end(); aPrsIter++) {
1267 aIndexes.insert((*aPrsIter).second);
1270 std::set<int>::const_iterator aIter = aIndexes.begin();
1271 for (int i = 1,length = aIndexes.size(); i <= length; i++) {
1272 std::set<int>::const_iterator aIter = aIndexes.find(i);
1273 if (aIter == aIndexes.end()) { minIndx = i; break; }
1274 else minIndx = i + 1;
1279 void AddScalarBarPosition (VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1280 VISU::Prs3d_i* thePrs3d, int pos)
1282 TViewToPrs3d& aMap = theModule->myScalarBarsMap;
1283 TPrs3dToInd aPair; aPair.first = thePrs3d; aPair.second = pos;
1284 aMap[theViewWindow].insert(aPair);
1287 void RemoveScalarBarPosition(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1288 VISU::Prs3d_i* thePrs3d)
1290 TViewToPrs3d& aMap = theModule->myScalarBarsMap;
1291 TSetPrs3d::iterator aIter = aMap[theViewWindow].begin();
1292 for (; aIter != aMap[theViewWindow].end(); aIter++)
1293 if ((*aIter).first == thePrs3d) {
1294 aMap[theViewWindow].erase(*aIter);