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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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"
64 #include "SUIT_Session.h"
65 #include "SUIT_MessageBox.h"
67 #include <vtkRenderer.h>
68 #include <vtkActorCollection.h>
71 //=============================================================================
75 GetDesktop(const CAM_Module* theModule)
77 return theModule->application()->desktop();
80 LightApp_SelectionMgr*
81 GetSelectionMgr(const SalomeApp_Module* theModule)
83 return theModule->getApp()->selectionMgr();
87 GetAppStudy(const CAM_Module* theModule)
90 dynamic_cast<SalomeApp_Study*>(theModule->application()->activeStudy());
94 GetCStudy(const SalomeApp_Study* theStudy)
96 return theStudy->studyDS();
100 IsStudyLocked( _PTR(Study) theStudy )
103 return theStudy->GetProperties()->IsLocked();
108 CheckLock( _PTR(Study) theStudy,
111 if(IsStudyLocked(theStudy)){
112 SUIT_MessageBox::warn1(theWidget,
113 QObject::tr("WRN_VISU_WARNING"),
114 QObject::tr("WRN_STUDY_LOCKED"),
115 QObject::tr("BUT_OK"));
122 FindDataObject(SUIT_DataObject* theDataObject,
123 const QString& theEntry,
126 int aLevel = theDataObject->level() + 2;
127 QString aSourceEntry = theEntry.section(':',0,aLevel);
128 DataObjectList aList;
129 theDataObject->children(aList);
130 DataObjectListIterator aDataObjectIter(aList);
131 while(SUIT_DataObject* aDataObject = aDataObjectIter.current()){
132 if(LightApp_DataObject* aChildDataObject = dynamic_cast<LightApp_DataObject*>(aDataObject)){
133 QString anEntry = aChildDataObject->entry();
134 QString aCurrentEntry = anEntry.section(':',0,aLevel);
135 if(aSourceEntry == aCurrentEntry){
136 if(theLevel == aLevel){
137 return aChildDataObject;
139 return FindDataObject(aChildDataObject,theEntry,theLevel);
149 FindDataObject(CAM_Module* theModule,
150 _PTR(SObject) theSObject)
152 CAM_DataModel* aDataModel = theModule->dataModel();
153 CAM_DataObject* aRootDataObject = aDataModel->root();
154 if(_PTR(SComponent) aComponent = theSObject)
155 return dynamic_cast<LightApp_DataObject*>(aRootDataObject);
157 int aLevel = theSObject->Depth();
158 std::string anEntry = theSObject->GetID();
159 return FindDataObject(aRootDataObject,anEntry.c_str(),aLevel);
163 UpdateObjBrowser(SalomeApp_Module* theModule,
164 bool theIsUpdateDataModel,
165 _PTR(SObject) theSObject)
167 LightApp_DataObject* aDataObject = NULL;
169 aDataObject = FindDataObject(theModule,theSObject);
171 theModule->updateObjBrowser(theIsUpdateDataModel,aDataObject);
172 theModule->getApp()->updateActions();
176 IsSObjectTable( _PTR(SObject) theSObject )
179 _PTR(GenericAttribute) anAttr;
180 if (theSObject->FindAttribute( anAttr, "AttributeTableOfInteger" ))
182 if (theSObject->FindAttribute( anAttr, "AttributeTableOfReal" ))
189 GetVisuGen(const CAM_Module* theModule)
191 static VISU_Gen_i* aGen = NULL;
193 SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
194 Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","VISU");
195 VISU_Gen_var aVISU = VISU_Gen::_narrow(aComponent);
196 if(!CORBA::is_nil(aVISU)){
197 aGen = VISU_Gen_i::GetVisuGenImpl();
198 aGen->SetCurrentStudy(GetDSStudy(GetCStudy(GetAppStudy(theModule))));
202 throw std::runtime_error(QObject::tr("ERR_CANT_FIND_VISU_COMPONENT").latin1());
206 SALOME_MED::MED_Gen_var
209 static SALOME_MED::MED_Gen_var aGen;
210 if(CORBA::is_nil(aGen)){
211 SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
212 Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","MED");
213 aGen = SALOME_MED::MED_Gen::_narrow(aComponent);
215 if(CORBA::is_nil(aGen))
216 throw std::runtime_error(QObject::tr("ERR_CANT_FIND_MED_COMPONENT").latin1());
221 VISU::Storable::TRestoringMap getMapOfValue (_PTR(SObject) theSObject)
223 VISU::Storable::TRestoringMap aMap;
225 _PTR(GenericAttribute) anAttr;
226 if (theSObject->FindAttribute(anAttr, "AttributeComment")) {
227 _PTR(AttributeComment) aComment (anAttr);
228 std::string aValue = aComment->Value();
229 QString aString (aValue.c_str());
230 VISU::Storable::StrToMap(aString, aMap);
236 QString getValue (_PTR(SObject) theSObject, QString theKey)
239 VISU::Storable::TRestoringMap aMap = getMapOfValue(theSObject);
241 aStr = VISU::Storable::FindValue(aMap, theKey.latin1());
245 //------------------------------------------------------------
248 GetSelectedObj(const SalomeApp_Study* theStudy,
249 const QString& theEntry,
250 VISU::Storable::TRestoringMap* theMap)
252 if (!theStudy || theEntry.isEmpty())
253 return CORBA::Object::_nil();
255 _PTR(Study) aStudy = GetCStudy(theStudy);
256 _PTR(SObject) aSObject = aStudy->FindObjectID(theEntry.latin1());
258 _PTR(GenericAttribute) anAttr;
259 if (theMap && aSObject->FindAttribute(anAttr,"AttributeComment")) {
260 _PTR(AttributeComment) aComment (anAttr);
261 std::string aValue = aComment->Value();
262 QString aString (aValue.c_str());
263 VISU::Storable::StrToMap(aString, *theMap);
265 return VISU::ClientSObjectToObject(aSObject);
267 return CORBA::Object::_nil();
271 GetSelectedObj(const SalomeApp_Module* theModule,
272 Handle(SALOME_InteractiveObject)* theIO,
273 VISU::Storable::TRestoringMap* theMap)
275 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
276 SALOME_ListIO aListIO;
277 aSelectionMgr->selectedObjects(aListIO);
278 SALOME_ListIteratorOfListIO anIter(aListIO);
280 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
284 return GetSelectedObj( GetAppStudy(theModule), anIO->getEntry(), theMap );
286 return CORBA::Object::_nil();
290 GetPrsToModify(const SalomeApp_Module* theModule,
291 Handle(SALOME_InteractiveObject)* theIO,
292 VISU::Storable::TRestoringMap* theMap)
294 if (CheckLock(GetCStudy(GetAppStudy(theModule)),GetDesktop(theModule)))
297 CORBA::Object_var anObject = GetSelectedObj(theModule, theIO);
298 if (CORBA::is_nil(anObject))
301 PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
305 return dynamic_cast<VISU::Prs3d_i*>(aServant.in());
309 Add(LightApp_SelectionMgr* theSelectionMgr,
310 const Handle(SALOME_InteractiveObject)& theIO)
312 SALOME_ListIO aListIO;
313 theSelectionMgr->selectedObjects(aListIO);
314 aListIO.Append(theIO);
315 theSelectionMgr->setSelectedObjects(aListIO);
319 Remove(LightApp_SelectionMgr* theSelectionMgr,
320 const Handle(SALOME_InteractiveObject)& theIO)
322 if (theIO.IsNull()) return;
323 SALOME_ListIO aListIO, aNewListIO;
324 theSelectionMgr->selectedObjects(aListIO);
325 SALOME_ListIteratorOfListIO anIter (aListIO);
326 for (; anIter.More(); anIter.Next()) {
327 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
328 if (!anIO->isSame(theIO)) {
329 aNewListIO.Append(theIO);
332 theSelectionMgr->setSelectedObjects(aNewListIO);
336 * \brief Check, if "Delete" popup-menu can be put on current selection
338 * \param theModule - is used to access SelectionManager, Study and VISU_Gen
339 * \retval bool - returns TRUE if all currently selected objects are removable
342 IsRemovableSelected (const SalomeApp_Module* theModule)
344 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
345 SALOME_ListIO aListIO;
346 aSelectionMgr->selectedObjects(aListIO);
348 if (aListIO.Extent() < 1)
351 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
352 if (!aStudy) return false;
354 // In some cases single selection can have its own popup-menu item for deletion
355 /*if (aListIO.Extent() == 1) {
356 Handle(SALOME_InteractiveObject) anIO = aListIO.First();
357 _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry());
359 VISU::VISUType aType = (VISU::VISUType)getValue(aSObject, "myType").toInt();
360 if (aType == VISU::TVIEW3D) {
361 return false; // special case
366 SALOME_ListIteratorOfListIO anIter (aListIO);
367 for (; anIter.More(); anIter.Next()) {
368 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
369 if (anIO->hasEntry()) {
371 // asv : if selected object is a Save Point object selected in object browser - return false
372 if ( QString( anIO->getEntry() ).startsWith( QObject::tr( "SAVE_POINT_DEF_NAME" ) ) )
375 _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry());
376 VISU::Storable::TRestoringMap pMap;
378 CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(aSObject);
379 if (!CORBA::is_nil(aCORBAObject)) {
380 VISU::RemovableObject_var aRemovableObj = VISU::RemovableObject::_narrow(aCORBAObject);
381 if (CORBA::is_nil(aRemovableObj)) {
382 // Not removable CORBA object
386 // Can be removed, if lays directly under VISU
387 // (first sub-level) or is a child of such an object
388 string aNAME, aVisuNAME = GetVisuGen(theModule)->ComponentDataType();
389 _PTR(GenericAttribute) anAttr;
390 _PTR(AttributeComment) aComment;
392 bool isUnderVISU = false;
393 _PTR(SObject) aFatherSObject = aSObject->GetFather();
394 if (aFatherSObject->FindAttribute(anAttr, "AttributeComment")) {
395 _PTR(AttributeComment) aComment (anAttr);
396 aNAME = aComment->Value();
397 if (aNAME == aVisuNAME) {
402 // Not directly under VISU component, check father
403 aCORBAObject = VISU::ClientSObjectToObject(aFatherSObject);
404 if (!CORBA::is_nil(aCORBAObject)) {
410 aFatherSObject = aFatherSObject->GetFather();
411 if (aFatherSObject->FindAttribute(anAttr, "AttributeComment")) {
412 _PTR(AttributeComment) aComment (anAttr);
413 aNAME = aComment->Value();
414 if (aNAME == aVisuNAME) {
419 // Father is not directly under VISU component
431 DeleteSObject(VisuGUI* theModule,
432 _PTR(Study) theStudy,
433 _PTR(SObject) theSObject)
435 _PTR(ChildIterator) aChildIter = theStudy->NewChildIterator(theSObject);
436 for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
437 _PTR(SObject) aChildSObject = aChildIter->Value();
438 CORBA::Object_var aChildObj = VISU::ClientSObjectToObject(aChildSObject);
439 ErasePrs(theModule, aChildObj, /*repaint_view_window = */false);
442 CORBA::Object_var anObj = VISU::ClientSObjectToObject(theSObject);
443 if (!CORBA::is_nil(anObj)) {
444 ErasePrs(theModule, anObj, /*repaint_view_window = */true);
446 VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObj);
447 if (!CORBA::is_nil(aRemovableObject)) {
448 aRemovableObject->RemoveFromStudy();
451 // Remove aSObject together with all its sub-objects
453 VISU::RemoveFromStudy(theSObject,
454 false, // remove not only IOR attribute, but Object With Children
455 false); // not Destroy() sub-objects
460 DeletePrs3d(VisuGUI* theModule,
461 VISU::Prs3d_i* thePrs,
462 const Handle(SALOME_InteractiveObject)& theIO)
466 if (CheckLock(GetCStudy(GetAppStudy(theModule)),GetDesktop(theModule)))
469 SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
470 RemoveScalarBarPosition(theModule, vw, thePrs);
472 thePrs->RemoveFromStudy();
475 // Presentation management
478 ChangeRepresentation (const SalomeApp_Module* theModule,
479 VISU::PresentationType theType)
481 SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
485 Handle(SALOME_InteractiveObject) anIO;
486 CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
487 if (CORBA::is_nil(anObject)) return;
489 VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
490 if (CORBA::is_nil(aVisuObj)) return;
492 PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
493 if (!aServant.in()) return;
495 VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
497 if (VISU_Actor* anActor = GetActor(aPrs3d, vw)) {
500 if (anActor->IsShrunk())
503 anActor->SetShrink();
506 if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
507 aMesh->SetPresentationType(theType);
508 RecreateActor(theModule, aMesh);
510 anActor->SetRepresentation(theType);
519 SetShading ( const SalomeApp_Module* theModule,
522 SVTK_ViewWindow* vw = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
526 Handle(SALOME_InteractiveObject) anIO;
527 CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
528 if (CORBA::is_nil(anObject)) return;
530 VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
531 if (CORBA::is_nil(aVisuObj)) return;
533 PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
534 if (!aServant.in()) return;
536 VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
538 if (VISU_Actor* anActor = GetActor(aPrs3d, vw)) {
539 if ( VISU_ScalarMapAct* aScalarMapActor = dynamic_cast<VISU_ScalarMapAct*>(anActor) )
540 aScalarMapActor->SetShading( theOn );
549 CheckTimeStamp(const SalomeApp_Module* theModule,
550 _PTR(SObject)& theSObject,
551 Handle(SALOME_InteractiveObject)* theIO)
553 Handle(SALOME_InteractiveObject) anIO;
554 CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
557 if (!anIO.IsNull() && anIO->hasEntry()){
558 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
559 theSObject = aStudy->FindObjectID(anIO->getEntry());
560 QString aValue = getValue(theSObject,"myType");
561 if (aValue.toInt() == int(VISU::TTIMESTAMP))
564 SUIT_MessageBox::warn1(GetDesktop(theModule),
565 QObject::tr("WRN_VISU"),
566 QObject::tr("WRN_NO_AVAILABLE_DATA"),
567 QObject::tr("BUT_OK") );
572 CheckResult(const SalomeApp_Module* theModule,
573 _PTR(SObject) theSource,
574 VISU::Result_var& theResult)
576 if(theSource->Depth() < 3) // Bug of SALOMEDS : can\t get father from root object
579 _PTR(SObject) aSObj = theSource->GetFather();
583 aSObj = aSObj->GetFather();
587 aSObj = aSObj->GetFather();
591 CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
592 if (CORBA::is_nil(anObject)) {
593 aSObj = aSObj->GetFather();
596 anObject = VISU::ClientSObjectToObject(aSObj);
599 if (CORBA::is_nil(anObject))
602 theResult = VISU::Result::_narrow(anObject);
603 return dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
609 PublishMeshInView(const SalomeApp_Module* theModule,
610 VISU::Prs3d_i* thePrs,
611 SVTK_ViewWindow* theViewWindow)
613 VISU_Actor* aActor = NULL;
614 if (!thePrs || !theViewWindow)
617 QApplication::setOverrideCursor( Qt::waitCursor );
619 if (aActor = thePrs->CreateActor())
620 theViewWindow->AddActor(aActor);
621 } catch(std::exception& exc) {
622 SUIT_MessageBox::warn1
623 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
624 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()),
625 QObject::tr("BUT_OK"));
627 QApplication::restoreOverrideCursor();
633 RepaintViewWindows (const SalomeApp_Module* theModule,
634 const Handle(SALOME_InteractiveObject)& theIObject)
636 TViewWindows aViewWindows;
637 if (SalomeApp_Application* anApp = theModule->getApp()) {
638 ViewManagerList aViewManagerList;
639 anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
640 QPtrListIterator<SUIT_ViewManager> anIter (aViewManagerList);
641 while (SUIT_ViewManager* aViewManager = anIter.current()) {
642 QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
643 for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
644 if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
645 if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
646 if (vw->isVisible(theIObject)) {
647 vw->getRenderer()->ResetCameraClippingRange();
649 vw->highlight(theIObject, true, true);
660 FindActor(SVTK_ViewWindow* theViewWindow,
661 const char* theEntry)
663 using namespace SVTK;
664 if(vtkRenderer* aRenderer = theViewWindow->getRenderer()){
665 if(vtkActorCollection* aCollection = aRenderer->GetActors()){
666 if(VISU_Actor* anActor = Find<VISU_Actor>(aCollection,TIsSameEntry<VISU_Actor>(theEntry))){
675 FindActor(SVTK_ViewWindow* theViewWindow,
676 VISU::Prs3d_i* thePrs)
678 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
679 CORBA::String_var anEntry = aSObject->GetID();
680 return FindActor(theViewWindow,anEntry.in());
684 RecreateActor (const SalomeApp_Module* theModule,
685 VISU::Prs3d_i* thePrs)
687 QApplication::setOverrideCursor(Qt::waitCursor);
689 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
690 CORBA::String_var anEntry = aSObject->GetID();
693 thePrs->UpdateActors();
694 } catch (std::runtime_error& exc) {
696 QApplication::restoreOverrideCursor();
697 SUIT_MessageBox::warn1
698 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
699 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()),
700 QObject::tr("BUT_OK"));
702 thePrs->RemoveActors();
705 QApplication::restoreOverrideCursor();
708 static bool ComputeVisiblePropBounds(SVTK_ViewWindow* theViewWindow,
710 const char* theActorClassName = "VISU_Actor")
712 vtkRenderer *aRen = theViewWindow->getRenderer();
713 vtkActorCollection *anActColl = aRen->GetActors();
716 int somethingVisible = false;
718 allBounds[0] = allBounds[2] = allBounds[4] = VTK_LARGE_FLOAT;
719 allBounds[1] = allBounds[3] = allBounds[5] = -VTK_LARGE_FLOAT;
720 // loop through all props
721 for (anActColl->InitTraversal(); (prop = anActColl->GetNextProp()); ) {
722 // if it's invisible, or has no geometry, we can skip the rest
723 if (prop->GetVisibility() && prop->IsA(theActorClassName)) {
724 bounds = prop->GetBounds();
725 // make sure we haven't got bogus bounds
726 if (bounds != NULL &&
727 bounds[0] > -VTK_LARGE_FLOAT && bounds[1] < VTK_LARGE_FLOAT &&
728 bounds[2] > -VTK_LARGE_FLOAT && bounds[3] < VTK_LARGE_FLOAT &&
729 bounds[4] > -VTK_LARGE_FLOAT && bounds[5] < VTK_LARGE_FLOAT)
731 somethingVisible = true;
732 if (bounds[0] < allBounds[0]) allBounds[0] = bounds[0];
733 if (bounds[1] > allBounds[1]) allBounds[1] = bounds[1];
734 if (bounds[2] < allBounds[2]) allBounds[2] = bounds[2];
735 if (bounds[3] > allBounds[3]) allBounds[3] = bounds[3];
736 if (bounds[4] < allBounds[4]) allBounds[4] = bounds[4];
737 if (bounds[5] > allBounds[5]) allBounds[5] = bounds[5];
741 return somethingVisible;
744 void SetFitAll(SVTK_ViewWindow* theViewWindow)
746 static float PRECISION = 0.000001;
747 static float DEVIATION = 600;
749 if (!ComputeVisiblePropBounds(theViewWindow, XYZ_Bnd)) return;
751 float absX = XYZ_Bnd[1] - XYZ_Bnd[0];
752 float absY = XYZ_Bnd[3] - XYZ_Bnd[2];
753 float absZ = XYZ_Bnd[5] - XYZ_Bnd[4];
755 enum CameraOrient {e3D, eFront, eLeft, eTop};
756 CameraOrient aCameraOrient = e3D;
757 if (absX <= PRECISION) aCameraOrient = eFront;
759 if (absY <= PRECISION) aCameraOrient = eLeft;
761 if (absZ <= PRECISION) aCameraOrient = eTop;
763 // all the three dimensions exceeds precision
764 float dev_abs_XY = absX / absY;
765 float dev_abs_YZ = absY / absZ;
766 float dev_abs_XZ = absX / absZ;
767 if (dev_abs_XY >= DEVIATION || 1./dev_abs_YZ >= DEVIATION)
768 aCameraOrient = eLeft;
770 if (1./dev_abs_XY >= DEVIATION || 1./dev_abs_XZ >= DEVIATION)
771 aCameraOrient = eFront;
773 if (dev_abs_XZ >= DEVIATION || dev_abs_YZ >= DEVIATION)
774 aCameraOrient = eTop;
781 switch (aCameraOrient) {
782 case eFront: theViewWindow->onFrontView(); break;
783 case eLeft: theViewWindow->onLeftView(); break;
784 case eTop: theViewWindow->onTopView(); break;
785 case e3D: theViewWindow->onResetView(); break;
787 theViewWindow->getRenderer()->ResetCameraClippingRange();
788 theViewWindow->onFitAll();
791 //************************************************************
795 GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate)
797 if(SalomeApp_Application* anApp = theModule->getApp()){
798 if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){
799 return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
805 // Internal function used by several public functions below
807 UpdateCurve(VISU::Curve_i* theCurve,
808 Plot2d_ViewFrame* aPlot,
809 SPlot2d_Curve* plotCurve,
812 if ( theDisplaying == VISU::eErase ) {
813 if ( plotCurve && aPlot )
814 aPlot->eraseCurve( plotCurve, false );
816 else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
818 plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() );
819 //plotCurve->setVerTitle( ( theCurve->GetVerTitle().c_str() ) );
820 plotCurve->setVerTitle( theCurve->GetName() );
821 plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() );
822 plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() );
825 int nbPoints = theCurve->GetData( xList, yList );
826 if ( nbPoints > 0 && xList && yList ) {
827 plotCurve->setData( xList, yList, nbPoints );
829 if ( !theCurve->IsAuto() ) {
830 plotCurve->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
831 plotCurve->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() );
832 SALOMEDS::Color color = theCurve->GetColor();
833 plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
835 plotCurve->setAutoAssign( theCurve->IsAuto() );
837 aPlot->displayCurve( plotCurve, false );
840 Plot2d_Curve* crv = theCurve->CreatePresentation();
843 aPlot->displayCurve( crv, false );
844 theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
845 theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
846 SALOMEDS::Color newColor;
847 newColor.R = crv->getColor().red()/255.;
848 newColor.G = crv->getColor().green()/255.;
849 newColor.B = crv->getColor().blue()/255.;
850 theCurve->SetColor( newColor );
851 crv->setAutoAssign( theCurve->IsAuto() );
858 PlotTable(const SalomeApp_Module* theModule,
859 VISU::Table_i* table,
862 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
865 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
869 if ( theDisplaying == VISU::eDisplayOnly )
871 QList<Plot2d_Curve> clist;
872 aPlot->getCurves( clist );
873 _PTR(Study) aStudy = GetCStudy( GetAppStudy( theModule ) );
874 _PTR(SObject) TableSO = aStudy->FindObjectID( table->GetEntry().latin1() );
876 _PTR(ChildIterator) Iter = aStudy->NewChildIterator( TableSO );
877 for ( ; Iter->More(); Iter->Next() ) {
878 CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
879 if( !CORBA::is_nil( childObject ) ) {
880 CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
881 if( !CORBA::is_nil( aCurve ) ) {
882 VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
883 SPlot2d_Curve* plotCurve = 0;
884 SPlot2d_Curve* tmpCurve;
885 for ( int i = 0; i < clist.count(); i++ ) {
886 tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
887 if (tmpCurve && tmpCurve->hasIO() &&
888 !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
889 plotCurve = tmpCurve;
894 UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
896 if ( theDisplaying == VISU::eErase && plotCurve ) {
897 clist.remove( plotCurve );
907 PlotCurve(const SalomeApp_Module* theModule,
908 VISU::Curve_i* theCurve,
911 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
914 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
918 // if ( theDisplaying == VISU::eDisplayOnly )
919 // aPlot->EraseAll();
920 QList<Plot2d_Curve> clist;
921 aPlot->getCurves( clist );
922 SPlot2d_Curve* plotCurve = 0;
923 SPlot2d_Curve* tmpCurve;
924 for (int i = 0; i < clist.count(); i++) {
925 tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
926 if (tmpCurve && tmpCurve->hasIO() &&
927 !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
928 plotCurve = tmpCurve;
929 } else if (theDisplaying == VISU::eDisplayOnly) {
930 aPlot->eraseCurve(clist.at(i));
934 UpdateCurve(theCurve, aPlot, plotCurve, theDisplaying);
940 PlotContainer(const SalomeApp_Module* theModule,
941 VISU::Container_i* container,
944 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
947 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
951 if ( theDisplaying == VISU::eDisplayOnly )
953 QList<Plot2d_Curve> clist;
954 aPlot->getCurves( clist );
955 if ( container->GetNbCurves() > 0 ) {
956 int nbCurves = container->GetNbCurves();
957 for ( int k = 1; k <= nbCurves; k++ ) {
958 VISU::Curve_i* theCurve = container->GetCurve( k );
959 if ( theCurve && theCurve->IsValid() ) {
960 SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>
961 (aView->getCurveByIO(new SALOME_InteractiveObject (theCurve->GetEntry(), "", "")));
963 UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
965 if ( plotCurve && theDisplaying == VISU::eErase ) {
966 clist.remove( plotCurve );
975 CreatePlot(SalomeApp_Module* theModule,
976 _PTR(SObject) theTableSO)
978 if ( IsSObjectTable(theTableSO) ) {
979 CORBA::Object_var aTable = VISU::ClientSObjectToObject(theTableSO);
980 CORBA::Object_var aContainer = GetVisuGen( theModule )->CreateContainer();
981 if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) {
982 VISU::Table_i* pTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
983 VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aContainer).in());
985 if ( pContainer && pTable ) {
986 for ( int i = 2; i <= pTable->GetNbRows(); i++ ) {
987 CORBA::Object_var aNewCurve = GetVisuGen( theModule )->CreateCurve( pTable->_this(), 1, i );
988 if( !CORBA::is_nil( aNewCurve ) ) {
989 VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aNewCurve).in() );
991 pContainer->AddCurve( pCrv->_this() );
995 PlotContainer( theModule, pContainer, VISU::eDisplay );
997 QString anEntry = pContainer->GetEntry();
998 _PTR(Study) aStudy = theTableSO->GetStudy();
999 _PTR(SObject) aContainerSO = aStudy->FindObjectID(anEntry.latin1());
1000 _PTR(SObject) aParentSO = aContainerSO->GetFather();
1001 UpdateObjBrowser(theModule,true,aParentSO);
1007 //************************************************************
1010 void CreateMesh (const SalomeApp_Module* theModule,
1011 const Handle(SALOME_InteractiveObject)& theIO,
1012 SVTK_ViewWindow* theViewWindow)
1014 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
1015 //if (CheckLock(aStudy))
1018 _PTR(SObject) aResultSObj = aStudy->FindObjectID(theIO->getEntry());
1021 VISU::Result_var aResult;
1022 VISU::Result_i* pResult = CheckResult(theModule, aResultSObj, aResult);
1023 if (pResult == NULL)
1026 Storable::TRestoringMap aMap = getMapOfValue(aResultSObj);
1028 string aComment = Storable::FindValue(aMap,"myComment",&isExist).latin1();
1032 CORBA::Object_var aMesh;
1033 string aMeshName = Storable::FindValue(aMap,"myMeshName").latin1();
1038 if (aComment == "ENTITY") {
1039 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myId").toInt();
1040 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity))
1041 aMesh = GetVisuGen(theModule)->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
1042 } else if (aComment == "FAMILY") {
1043 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myEntityId").toInt();
1044 string aFamilyName = Storable::FindValue(aMap,"myName").latin1();
1045 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()))
1046 aMesh = GetVisuGen(theModule)->FamilyMeshOnEntity
1047 (aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
1048 } else if (aComment == "GROUP") {
1049 string aGroupName = Storable::FindValue(aMap,"myName").latin1();
1050 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str()))
1051 aMesh = GetVisuGen(theModule)->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
1055 MESSAGE("VisuGUI::CreateMesh() - CREATE MESH");
1059 //QApplication::restoreOverrideCursor();
1060 VISU::Mesh_i* pPresent = NULL;
1061 if (!CORBA::is_nil(aMesh))
1062 pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
1063 if (pPresent == NULL) {
1064 SUIT_MessageBox::warn1 (GetDesktop(theModule),
1065 QObject::tr("WRN_VISU"),
1066 QObject::tr("ERR_CANT_BUILD_PRESENTATION"),
1067 QObject::tr("BUT_OK"));
1071 if (theViewWindow) {
1077 PublishMeshInView(theModule, pPresent, theViewWindow);
1078 SetFitAll(theViewWindow);
1081 MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
1084 } catch (std::runtime_error& exc) {
1086 SUIT_MessageBox::warn1
1087 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
1088 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()),
1089 QObject::tr("BUT_OK"));
1093 theModule->application()->putInfo(QObject::tr("INF_DONE"));
1094 // Make "Save" button active
1095 theModule->getApp()->updateActions();
1098 // ========================================================================================
1099 // GetPrs3dList: find list of presentations for the given object
1100 // ========================================================================================
1101 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1102 const Handle(SALOME_InteractiveObject)& theIO)
1104 std::vector<VISU::Prs3d_i*> aList;
1105 if (!theIO.IsNull() && theIO->hasEntry()) {
1106 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1107 _PTR(SObject) aSObject = aCStudy->FindObjectID(theIO->getEntry());
1108 aList = GetPrs3dList(theModule, aSObject);
1113 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1114 _PTR(SObject) theObject)
1116 std::vector<VISU::Prs3d_i*> aList; int k = 0;
1120 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1122 CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(theObject);
1123 if (!CORBA::is_nil(aCORBAObject)) {
1124 VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
1125 if (!CORBA::is_nil(aVisuObj)) {
1126 VISU::VISUType aType = aVisuObj->GetType();
1128 case VISU::TSCALARMAP:
1129 case VISU::TISOSURFACE:
1130 case VISU::TDEFORMEDSHAPE:
1131 case VISU::TCUTPLANES:
1132 case VISU::TCUTLINES:
1133 case VISU::TVECTORS:
1134 case VISU::TSTREAMLINES:
1136 case VISU::TSCALARMAPONDEFORMEDSHAPE:
1138 PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1139 if (aServant.in()) {
1140 VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
1142 aList[k] = aPrsObject;
1149 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1150 _PTR(SObject) aTimeStamp;
1151 anIter->Next(); // First is reference on support
1152 for (; anIter->More(); anIter->Next()) {
1153 aTimeStamp = anIter->Value();
1154 if (!aTimeStamp) continue;
1155 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1156 if (!aSubList.empty()) {
1157 int n = aSubList.size();
1159 for (int i = 0; i < n; i++) {
1160 aList[k] = aSubList[i];
1170 _PTR(GenericAttribute) anAttr;
1171 if (theObject->FindAttribute(anAttr, "AttributeComment")) {
1172 _PTR(AttributeComment) aComment (anAttr);
1173 string aComm = aComment->Value();
1174 QString strIn (aComm.c_str());
1175 VISU::Storable::TRestoringMap pMap;
1176 VISU::Storable::StrToMap(strIn, pMap);
1178 VISU::VISUType aType =
1179 (VISU::VISUType)VISU::Storable::FindValue(pMap,"myType",&isExist).toInt();
1184 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1185 _PTR(SObject) aTimeStamp;
1186 anIter->Next(); // First is reference on support
1187 for (; anIter->More(); anIter->Next()) {
1188 aTimeStamp = anIter->Value();
1189 if (!aTimeStamp) continue;
1190 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1191 if (!aSubList.empty()) {
1192 int n = aSubList.size();
1194 for (int i = 0; i < n; i++) {
1195 aList[k] = aSubList[i];
1202 case VISU::TTIMESTAMP:
1204 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1206 for (; anIter->More(); anIter->Next()) {
1207 aPrs = anIter->Value();
1208 if (!aPrs) continue;
1209 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
1210 if (!aSubList.empty()) {
1211 int n = aSubList.size();
1213 for (int i = 0; i < n; i++) {
1214 aList[k] = aSubList[i];
1228 int GetFreePositionOfDefaultScalarBar(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow)
1231 std::set<int> aIndexes;
1232 TViewToPrs3d aMap = theModule->getScalarBarsMap();
1233 TViewToPrs3d::const_iterator aViewToPrsIter = aMap.find(theViewWindow);
1234 if (aViewToPrsIter != aMap.end()) {
1235 TSetPrs3d::const_iterator aPrsIter = (aViewToPrsIter->second).begin();
1236 for (; aPrsIter != (aViewToPrsIter->second).end(); aPrsIter++) {
1237 aIndexes.insert((*aPrsIter).second);
1240 std::set<int>::const_iterator aIter = aIndexes.begin();
1241 for (int i = 1,length = aIndexes.size(); i <= length; i++) {
1242 std::set<int>::const_iterator aIter = aIndexes.find(i);
1243 if (aIter == aIndexes.end()) { minIndx = i; break; }
1244 else minIndx = i + 1;
1249 void AddScalarBarPosition (VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1250 VISU::Prs3d_i* thePrs3d, int pos)
1252 TViewToPrs3d& aMap = theModule->myScalarBarsMap;
1253 TPrs3dToInd aPair; aPair.first = thePrs3d; aPair.second = pos;
1254 aMap[theViewWindow].insert(aPair);
1257 void RemoveScalarBarPosition(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1258 VISU::Prs3d_i* thePrs3d)
1260 TViewToPrs3d& aMap = theModule->myScalarBarsMap;
1261 TSetPrs3d::iterator aIter = aMap[theViewWindow].begin();
1262 for (; aIter != aMap[theViewWindow].end(); aIter++)
1263 if ((*aIter).first == thePrs3d) {
1264 aMap[theViewWindow].erase(*aIter);