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"
31 #include "VISU_Gen_i.hh"
32 #include "VISU_Prs3d_i.hh"
33 #include "VISU_Result_i.hh"
34 #include "VISU_Table_i.hh"
35 #include "VISU_Mesh_i.hh"
36 #include "VISU_ViewManager_i.hh"
38 #include "VISU_Actor.h"
39 #include "VISU_ScalarMapAct.h"
41 #include "SalomeApp_Module.h"
42 #include "SalomeApp_Study.h"
43 #include "SalomeApp_Application.h"
44 #include "LightApp_SelectionMgr.h"
46 #include "SALOME_ListIO.hxx"
47 #include "SALOME_ListIteratorOfListIO.hxx"
49 #include "SVTK_ViewWindow.h"
50 #include "SVTK_ViewModel.h"
51 #include "SVTK_Functor.h"
53 #include "VTKViewer_Algorithm.h"
55 #include "SPlot2d_ViewModel.h"
56 #include "Plot2d_ViewFrame.h"
58 #include "SUIT_Session.h"
59 #include "SUIT_MessageBox.h"
61 #include <vtkRenderer.h>
62 #include <vtkActorCollection.h>
65 //=============================================================================
69 GetDesktop(const CAM_Module* theModule)
71 return theModule->application()->desktop();
74 LightApp_SelectionMgr*
75 GetSelectionMgr(const SalomeApp_Module* theModule)
77 return theModule->getApp()->selectionMgr();
81 GetAppStudy(const CAM_Module* theModule)
84 dynamic_cast<SalomeApp_Study*>(theModule->application()->activeStudy());
88 GetCStudy(const SalomeApp_Study* theStudy)
90 return theStudy->studyDS();
94 IsStudyLocked( _PTR(Study) theStudy )
97 return theStudy->GetProperties()->IsLocked();
102 CheckLock( _PTR(Study) theStudy )
104 if(IsStudyLocked(theStudy))
106 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
107 (SUIT_Session::session()->activeApplication());
110 SUIT_MessageBox::warn1(anApp->desktop(),
111 QObject::tr("WRN_VISU_WARNING"),
112 QObject::tr("WRN_STUDY_LOCKED"),
113 QObject::tr("BUT_OK"));
121 GetVisuGen(const CAM_Module* theModule)
123 static VISU_Gen_i* aGen = NULL;
125 SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
126 Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","VISU");
127 VISU_Gen_var aVISU = VISU_Gen::_narrow(aComponent);
128 if(!CORBA::is_nil(aVISU)){
129 aGen = VISU_Gen_i::GetVisuGenImpl();
130 aGen->SetCurrentStudy(GetDSStudy(GetCStudy(GetAppStudy(theModule))));
134 throw std::runtime_error(QObject::tr("ERR_CANT_FIND_VISU_COMPONENT").latin1());
138 SALOME_MED::MED_Gen_var
141 static SALOME_MED::MED_Gen_var aGen;
142 if(CORBA::is_nil(aGen)){
143 SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
144 Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","MED");
145 aGen = SALOME_MED::MED_Gen::_narrow(aComponent);
147 if(CORBA::is_nil(aGen))
148 throw std::runtime_error(QObject::tr("ERR_CANT_FIND_MED_COMPONENT").latin1());
153 VISU::Storable::TRestoringMap getMapOfValue (_PTR(SObject) theSObject)
155 VISU::Storable::TRestoringMap aMap;
157 _PTR(GenericAttribute) anAttr;
158 if (theSObject->FindAttribute(anAttr, "AttributeComment")) {
159 _PTR(AttributeComment) aComment (anAttr);
160 std::string aValue = aComment->Value();
161 QString aString (aValue.c_str());
162 VISU::Storable::StrToMap(aString, aMap);
168 QString getValue (_PTR(SObject) theSObject, QString theKey)
171 VISU::Storable::TRestoringMap aMap = getMapOfValue(theSObject);
173 aStr = VISU::Storable::FindValue(aMap, theKey.latin1());
177 //------------------------------------------------------------
180 GetSelectedObj(const SalomeApp_Study* theStudy,
181 const QString& theEntry,
182 VISU::Storable::TRestoringMap* theMap)
184 if (!theStudy || theEntry.isEmpty())
185 return CORBA::Object::_nil();
187 _PTR(Study) aStudy = GetCStudy(theStudy);
188 _PTR(SObject) aSObject = aStudy->FindObjectID(theEntry.latin1());
190 _PTR(GenericAttribute) anAttr;
191 if (theMap && aSObject->FindAttribute(anAttr,"AttributeComment")) {
192 _PTR(AttributeComment) aComment (anAttr);
193 std::string aValue = aComment->Value();
194 QString aString (aValue.c_str());
195 VISU::Storable::StrToMap(aString, *theMap);
197 return VISU::ClientSObjectToObject(aSObject);
199 return CORBA::Object::_nil();
203 GetSelectedObj(const SalomeApp_Module* theModule,
204 Handle(SALOME_InteractiveObject)* theIO,
205 VISU::Storable::TRestoringMap* theMap)
207 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
208 SALOME_ListIO aListIO;
209 aSelectionMgr->selectedObjects(aListIO);
210 SALOME_ListIteratorOfListIO anIter(aListIO);
212 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
216 return GetSelectedObj( GetAppStudy(theModule), anIO->getEntry(), theMap );
218 return CORBA::Object::_nil();
222 GetPrsToModify(const SalomeApp_Module* theModule,
223 Handle(SALOME_InteractiveObject)* theIO,
224 VISU::Storable::TRestoringMap* theMap)
226 if (CheckLock(GetCStudy(GetAppStudy(theModule))))
229 CORBA::Object_var anObject = GetSelectedObj(theModule, theIO);
230 if (CORBA::is_nil(anObject))
233 PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
237 return dynamic_cast<VISU::Prs3d_i*>(aServant.in());
241 Add(LightApp_SelectionMgr* theSelectionMgr,
242 const Handle(SALOME_InteractiveObject)& theIO)
244 SALOME_ListIO aListIO;
245 theSelectionMgr->selectedObjects(aListIO);
246 aListIO.Append(theIO);
247 theSelectionMgr->setSelectedObjects(aListIO);
251 Remove(LightApp_SelectionMgr* theSelectionMgr,
252 const Handle(SALOME_InteractiveObject)& theIO)
254 if (theIO.IsNull()) return;
255 SALOME_ListIO aListIO, aNewListIO;
256 theSelectionMgr->selectedObjects(aListIO);
257 SALOME_ListIteratorOfListIO anIter (aListIO);
258 for (; anIter.More(); anIter.Next()) {
259 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
260 if (!anIO->isSame(theIO)) {
261 aNewListIO.Append(theIO);
264 theSelectionMgr->setSelectedObjects(aNewListIO);
268 * \brief Check, if "Delete" popup-menu can be put on current selection
270 * \param theModule - is used to access SelectionManager, Study and VISU_Gen
271 * \retval bool - returns TRUE if all currently selected objects are removable
274 IsRemovableSelected (const SalomeApp_Module* theModule)
276 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
277 SALOME_ListIO aListIO;
278 aSelectionMgr->selectedObjects(aListIO);
280 if (aListIO.Extent() < 1)
283 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
284 if (!aStudy) return false;
286 // In some cases single selection can have its own popup-menu item for deletion
287 /*if (aListIO.Extent() == 1) {
288 Handle(SALOME_InteractiveObject) anIO = aListIO.First();
289 _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry());
291 VISU::VISUType aType = (VISU::VISUType)getValue(aSObject, "myType").toInt();
292 if (aType == VISU::TVIEW3D) {
293 return false; // special case
298 SALOME_ListIteratorOfListIO anIter (aListIO);
299 for (; anIter.More(); anIter.Next()) {
300 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
301 if (anIO->hasEntry()) {
302 _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry());
303 VISU::Storable::TRestoringMap pMap;
305 CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(aSObject);
306 if (!CORBA::is_nil(aCORBAObject)) {
307 VISU::RemovableObject_var aRemovableObj = VISU::RemovableObject::_narrow(aCORBAObject);
308 if (CORBA::is_nil(aRemovableObj)) {
309 // Not removable CORBA object
313 // Can be removed, if lays directly under VISU
314 // (first sub-level) or is a child of such an object
315 string aNAME, aVisuNAME = GetVisuGen(theModule)->ComponentDataType();
316 _PTR(GenericAttribute) anAttr;
317 _PTR(AttributeComment) aComment;
319 bool isUnderVISU = false;
320 _PTR(SObject) aFatherSObject = aSObject->GetFather();
321 if (aFatherSObject->FindAttribute(anAttr, "AttributeComment")) {
322 _PTR(AttributeComment) aComment (anAttr);
323 aNAME = aComment->Value();
324 if (aNAME == aVisuNAME) {
329 // Not directly under VISU component, check father
330 aCORBAObject = VISU::ClientSObjectToObject(aFatherSObject);
331 if (!CORBA::is_nil(aCORBAObject)) {
337 aFatherSObject = aFatherSObject->GetFather();
338 if (aFatherSObject->FindAttribute(anAttr, "AttributeComment")) {
339 _PTR(AttributeComment) aComment (anAttr);
340 aNAME = aComment->Value();
341 if (aNAME == aVisuNAME) {
346 // Father is not directly under VISU component
357 //************************************************************
361 ErasePrs (const SalomeApp_Module* theModule,
362 CORBA::Object_ptr theObject, bool theUpdate)
364 if (!CORBA::is_nil(theObject)) {
365 VISU::Base_var aBase = VISU::Base::_narrow(theObject);
366 if (CORBA::is_nil(aBase)) return;
367 VISU::VISUType aType = aBase->GetType();
371 if (VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aBase).in()))
372 PlotCurve(theModule, aCurve, VISU::eErase );
375 case VISU::TCONTAINER:
377 if (VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aBase).in()))
378 PlotContainer(theModule, aContainer, VISU::eErase );
383 if (VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aBase).in()))
384 PlotTable(theModule, aTable, VISU::eErase );
389 if (VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(aBase).in())) {
390 ErasePrs3d(theModule, aPrsObject);
392 if (SVTK_ViewWindow* vw = GetViewWindow(theModule))
402 DeleteSObject (SalomeApp_Module* theModule,
403 _PTR(Study) theStudy,
404 _PTR(SObject) theSObject)
406 SalomeApp_Study* study = GetAppStudy( theModule );
408 _PTR(ChildIterator) aChildIter = theStudy->NewChildIterator(theSObject);
409 for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
410 _PTR(SObject) aChildSObject = aChildIter->Value();
412 CORBA::Object_var aChildObj = VISU::ClientSObjectToObject(aChildSObject);
413 ErasePrs(theModule, aChildObj);
416 CORBA::Object_var anObj = VISU::ClientSObjectToObject(theSObject);
417 if (!CORBA::is_nil(anObj)) {
418 ErasePrs(theModule, anObj);
420 VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObj);
421 if (!CORBA::is_nil(aRemovableObject)) {
422 aRemovableObject->RemoveFromStudy();
425 // Remove aSObject together with all its sub-objects
427 VISU::RemoveFromStudy(theSObject,
428 false, // remove not only IOR attribute, but Object With Children
429 false); // not Destroy() sub-objects
434 DeletePrs3d(SalomeApp_Module* theModule,
435 VISU::Prs3d_i* thePrs,
436 const Handle(SALOME_InteractiveObject)& theIO)
440 if (CheckLock(GetCStudy(GetAppStudy(theModule))))
442 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
443 CORBA::String_var anEntry = aSObject->GetID();
444 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
445 Remove(aSelectionMgr,theIO);
446 TViewWindows aViewWindows = GetViews(theModule);
447 for(int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++){
448 SVTK_ViewWindow* aView = aViewWindows[i];
449 if(VISU_Actor* anActor = FindActor(aView,anEntry.in())){
450 aView->RemoveActor(anActor);
454 thePrs->RemoveFromStudy();
458 ErasePrs3d(const SalomeApp_Module* theModule,
459 VISU::Prs3d_i* thePrs)
461 if ( SVTK_ViewWindow* vw = GetViewWindow( theModule ) ){
462 VISU_Actor* anVISUActor = FindActor( vw, thePrs );
464 anVISUActor->VisibilityOff();
469 //************************************************************
470 // Presentation management
473 ChangeRepresentation (const SalomeApp_Module* theModule,
474 VISU::PresentationType theType)
476 SUIT_ViewWindow* aView = GetActiveView(theModule, SVTK_Viewer::Type());
478 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( aView );
482 Handle(SALOME_InteractiveObject) anIO;
483 CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
484 if (CORBA::is_nil(anObject)) return;
486 VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
487 if (CORBA::is_nil(aVisuObj)) return;
489 PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
490 if (!aServant.in()) return;
492 VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
494 if (VISU_Actor* anActor = GetActor(aPrs3d, vw)) {
497 if (anActor->IsShrunk())
500 anActor->SetShrink();
503 if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
504 aMesh->SetPresentationType(theType);
505 RecreateActor(theModule, aMesh);
507 anActor->SetRepresentation(theType);
516 SetShading ( const SalomeApp_Module* theModule,
519 SUIT_ViewWindow* aView = GetActiveView(theModule, SVTK_Viewer::Type());
521 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( aView );
525 Handle(SALOME_InteractiveObject) anIO;
526 CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
527 if (CORBA::is_nil(anObject)) return;
529 VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
530 if (CORBA::is_nil(aVisuObj)) return;
532 PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
533 if (!aServant.in()) return;
535 VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
537 if (VISU_Actor* anActor = GetActor(aPrs3d, vw)) {
538 if ( VISU_ScalarMapAct* aScalarMapActor = dynamic_cast<VISU_ScalarMapAct*>(anActor) )
539 aScalarMapActor->SetShading( theOn );
545 //************************************************************
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 _PTR(SObject) aSObj = theSource->GetFather();
580 aSObj = aSObj->GetFather();
584 aSObj = aSObj->GetFather();
588 CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
589 if (CORBA::is_nil(anObject)) {
590 aSObj = aSObj->GetFather();
593 anObject = VISU::ClientSObjectToObject(aSObj);
596 if (CORBA::is_nil(anObject))
599 theResult = VISU::Result::_narrow(anObject);
600 VISU::Result_i* pResult = dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
602 SUIT_MessageBox::warn1(GetDesktop(theModule),
603 QObject::tr("WRN_VISU"),
604 QObject::tr("WRN_NO_AVAILABLE_DATA"),
605 QObject::tr("BUT_OK"));
609 //************************************************************
612 SUIT_ViewWindow* GetActiveView(const SalomeApp_Module* theModule, QString theType)
614 if(SalomeApp_Application* anApp = theModule->getApp()){
615 if(SUIT_ViewManager* aViewManager = anApp->activeViewManager()){
616 if (!theType.isNull()) {
617 if (aViewManager->getType() != theType)
620 return aViewManager->getActiveView();
626 //************************************************************
630 GetViews(const SalomeApp_Module* theModule)
632 TViewWindows aViewWindows;
633 if(SalomeApp_Application* anApp = theModule->getApp()){
634 ViewManagerList aViewManagerList;
635 anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
636 QPtrListIterator<SUIT_ViewManager> anIter(aViewManagerList);
637 while(SUIT_ViewManager* aViewManager = anIter.current()){
638 QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
639 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
640 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
641 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
642 aViewWindows.push_back(aView);
651 GetViewWindow( const SalomeApp_Module* theModule, const bool theCreate )
653 if (SalomeApp_Application* anApp = theModule->getApp())
655 SVTK_ViewWindow* wnd = dynamic_cast<SVTK_ViewWindow*>(anApp->desktop()->activeWindow());
660 SUIT_ViewManager* aViewManager = anApp->getViewManager( SVTK_Viewer::Type(), theCreate );
661 return dynamic_cast<SVTK_ViewWindow*>( aViewManager->getActiveView() );
668 GetViewWindow(const SalomeApp_Module* theModule, const bool theCreate )
670 if(SalomeApp_Application* anApp = theModule->getApp()){
671 if(SUIT_ViewManager* aViewManager = anApp->getViewManager( SVTK_Viewer::Type(), theCreate )){
672 if(SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()){
673 return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
684 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
685 (SUIT_Session::session()->activeApplication());
687 if (SUIT_ViewManager* aViewManager = anApp->activeViewManager()) {
688 if (aViewManager->getType() == SVTK_Viewer::Type()) {
689 if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
690 return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
699 PublishInView(const SalomeApp_Module* theModule,
700 VISU::Prs3d_i* thePrs)
702 VISU_Actor* aActor = NULL;
705 if(SVTK_ViewWindow* aView = GetViewWindow(theModule)){
706 QApplication::setOverrideCursor( Qt::waitCursor );
708 if(aActor = thePrs->CreateActor())
709 aView->AddActor(aActor);
710 }catch(std::exception& exc){
711 SUIT_MessageBox::warn1(GetDesktop(theModule),
712 QObject::tr("WRN_VISU"),
713 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()),
714 QObject::tr("BUT_OK"));
716 QApplication::restoreOverrideCursor();
722 UpdateViewer(const SalomeApp_Module* theModule,
723 VISU::Prs3d_i* thePrs,
726 SVTK_ViewWindow* vw = GetViewWindow( theModule );
727 if (!vw) return NULL;
729 vtkRenderer *aRen = vw->getRenderer();
730 vtkActorCollection *anActColl = aRen->GetActors();
733 VISU_Actor* anVISUActor = NULL;
734 VISU_Actor* aResActor = NULL;
735 for(anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ){
736 if(!SALOME_Actor::SafeDownCast(anActor))
738 if(anActor->IsA("VISU_Actor")){
739 anVISUActor = VISU_Actor::SafeDownCast(anActor);
740 VISU::Prs3d_i* aPrs = anVISUActor->GetPrs3d();
741 if(aPrs == NULL) continue;
742 if (thePrs == aPrs) {
743 aResActor = anVISUActor->GetParent();
745 thePrs->UpdateActor(aResActor);
746 aResActor->VisibilityOn();
747 } catch (std::runtime_error& ex) {
748 aResActor->VisibilityOff();
750 SUIT_MessageBox::warn1(GetDesktop(theModule), QObject::tr("WRN_VISU"),
751 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(ex.what()),
752 QObject::tr("BUT_OK"));
754 } else if (theDispOnly) {
755 anVISUActor->GetParent()->VisibilityOff();
758 } else if (theDispOnly && anActor->GetVisibility()) {
759 anActor->VisibilityOff();
766 //anVISUActor = PublishInView( theModule, thePrs );
771 RepaintViewWindows (const SalomeApp_Module* theModule,
772 const Handle(SALOME_InteractiveObject)& theIObject)
774 TViewWindows aViewWindows;
775 if (SalomeApp_Application* anApp = theModule->getApp()) {
776 ViewManagerList aViewManagerList;
777 anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
778 QPtrListIterator<SUIT_ViewManager> anIter (aViewManagerList);
779 while (SUIT_ViewManager* aViewManager = anIter.current()) {
780 QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
781 for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
782 if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
783 if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
784 if (vw->isVisible(theIObject)) {
785 vw->getRenderer()->ResetCameraClippingRange();
787 vw->highlight(theIObject, true, true);
798 FindActor(SVTK_ViewWindow* theViewWindow,
799 const char* theEntry)
802 if(vtkRenderer* aRenderer = theViewWindow->getRenderer()){
803 if(vtkActorCollection* aCollection = aRenderer->GetActors()){
804 if(VISU_Actor* anActor = Find<VISU_Actor>(aCollection,TIsSameEntry<VISU_Actor>(theEntry))){
805 return anActor->GetParent();
813 FindActor(SVTK_ViewWindow* theViewWindow,
814 VISU::Prs3d_i* thePrs)
816 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
817 CORBA::String_var anEntry = aSObject->GetID();
818 return FindActor(theViewWindow,anEntry.in());
822 RecreateActor (const SalomeApp_Module* theModule,
823 VISU::Prs3d_i* thePrs)
825 QApplication::setOverrideCursor(Qt::waitCursor);
826 bool isPublished = false;
828 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
829 CORBA::String_var anEntry = aSObject->GetID();
834 TViewWindows aViewWindows = GetViews(theModule);
835 for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
836 SVTK_ViewWindow* aView = aViewWindows[i];
837 if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
839 thePrs->UpdateActor(anActor);
842 } catch (std::runtime_error& ex) {
844 QApplication::restoreOverrideCursor();
845 SUIT_MessageBox::warn1 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
846 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(ex.what()),
847 QObject::tr("BUT_OK"));
849 TViewWindows aViewWindows = GetViews(theModule);
850 for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
851 SVTK_ViewWindow* aView = aViewWindows[i];
852 if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
853 aView->RemoveActor(anActor);
859 QApplication::restoreOverrideCursor();
862 PublishInView(theModule, thePrs);
865 static bool ComputeVisiblePropBounds(SVTK_ViewWindow* theViewWindow,
867 const char* theActorClassName = "VISU_Actor")
869 vtkRenderer *aRen = theViewWindow->getRenderer();
870 vtkActorCollection *anActColl = aRen->GetActors();
873 int somethingVisible = false;
875 allBounds[0] = allBounds[2] = allBounds[4] = VTK_LARGE_FLOAT;
876 allBounds[1] = allBounds[3] = allBounds[5] = -VTK_LARGE_FLOAT;
877 // loop through all props
878 for (anActColl->InitTraversal(); (prop = anActColl->GetNextProp()); ) {
879 // if it's invisible, or has no geometry, we can skip the rest
880 if (prop->GetVisibility() && prop->IsA(theActorClassName)) {
881 bounds = prop->GetBounds();
882 // make sure we haven't got bogus bounds
883 if (bounds != NULL &&
884 bounds[0] > -VTK_LARGE_FLOAT && bounds[1] < VTK_LARGE_FLOAT &&
885 bounds[2] > -VTK_LARGE_FLOAT && bounds[3] < VTK_LARGE_FLOAT &&
886 bounds[4] > -VTK_LARGE_FLOAT && bounds[5] < VTK_LARGE_FLOAT)
888 somethingVisible = true;
889 if (bounds[0] < allBounds[0]) allBounds[0] = bounds[0];
890 if (bounds[1] > allBounds[1]) allBounds[1] = bounds[1];
891 if (bounds[2] < allBounds[2]) allBounds[2] = bounds[2];
892 if (bounds[3] > allBounds[3]) allBounds[3] = bounds[3];
893 if (bounds[4] < allBounds[4]) allBounds[4] = bounds[4];
894 if (bounds[5] > allBounds[5]) allBounds[5] = bounds[5];
898 return somethingVisible;
901 void SetFitAll(SVTK_ViewWindow* theViewWindow)
903 static float PRECISION = 0.000001;
904 static float DEVIATION = 600;
906 if (!ComputeVisiblePropBounds(theViewWindow, XYZ_Bnd)) return;
908 float absX = XYZ_Bnd[1] - XYZ_Bnd[0];
909 float absY = XYZ_Bnd[3] - XYZ_Bnd[2];
910 float absZ = XYZ_Bnd[5] - XYZ_Bnd[4];
912 enum CameraOrient {e3D, eFront, eLeft, eTop};
913 CameraOrient aCameraOrient = e3D;
914 if (absX <= PRECISION) aCameraOrient = eFront;
916 if (absY <= PRECISION) aCameraOrient = eLeft;
918 if (absZ <= PRECISION) aCameraOrient = eTop;
920 // all the three dimensions exceeds precision
921 float dev_abs_XY = absX / absY;
922 float dev_abs_YZ = absY / absZ;
923 float dev_abs_XZ = absX / absZ;
924 if (dev_abs_XY >= DEVIATION || 1./dev_abs_YZ >= DEVIATION)
925 aCameraOrient = eLeft;
927 if (1./dev_abs_XY >= DEVIATION || 1./dev_abs_XZ >= DEVIATION)
928 aCameraOrient = eFront;
930 if (dev_abs_XZ >= DEVIATION || dev_abs_YZ >= DEVIATION)
931 aCameraOrient = eTop;
938 switch (aCameraOrient) {
939 case eFront: theViewWindow->onFrontView(); break;
940 case eLeft: theViewWindow->onLeftView(); break;
941 case eTop: theViewWindow->onTopView(); break;
942 case e3D: theViewWindow->onResetView(); break;
944 theViewWindow->getRenderer()->ResetCameraClippingRange();
945 theViewWindow->onFitAll();
948 //************************************************************
952 GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate)
954 if(SalomeApp_Application* anApp = theModule->getApp()){
955 if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){
956 return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
962 // Internal function used by several public functions below
964 UpdateCurve(VISU::Curve_i* theCurve,
965 Plot2d_ViewFrame* aPlot,
966 SPlot2d_Curve* plotCurve,
969 if ( theDisplaying == VISU::eErase ) {
970 if ( plotCurve && aPlot )
971 aPlot->eraseCurve( plotCurve, false );
973 else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
975 plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() );
976 //plotCurve->setVerTitle( ( theCurve->GetVerTitle().c_str() ) );
977 plotCurve->setVerTitle( theCurve->GetName() );
978 plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() );
979 plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() );
982 int nbPoints = theCurve->GetData( xList, yList );
983 if ( nbPoints > 0 && xList && yList ) {
984 plotCurve->setData( xList, yList, nbPoints );
986 if ( !theCurve->IsAuto() ) {
987 plotCurve->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
988 plotCurve->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() );
989 SALOMEDS::Color color = theCurve->GetColor();
990 plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
992 plotCurve->setAutoAssign( theCurve->IsAuto() );
994 aPlot->displayCurve( plotCurve, false );
997 Plot2d_Curve* crv = theCurve->CreatePresentation();
1000 aPlot->displayCurve( crv, false );
1001 theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
1002 theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
1003 SALOMEDS::Color newColor;
1004 newColor.R = crv->getColor().red()/255.;
1005 newColor.G = crv->getColor().green()/255.;
1006 newColor.B = crv->getColor().blue()/255.;
1007 theCurve->SetColor( newColor );
1008 crv->setAutoAssign( theCurve->IsAuto() );
1015 PlotTable(const SalomeApp_Module* theModule,
1016 VISU::Table_i* table,
1019 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
1022 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1026 if ( theDisplaying == VISU::eDisplayOnly )
1028 QList<Plot2d_Curve> clist;
1029 aPlot->getCurves( clist );
1030 _PTR(Study) aStudy = GetCStudy( GetAppStudy( theModule ) );
1031 _PTR(SObject) TableSO = aStudy->FindObjectID( table->GetEntry().latin1() );
1033 _PTR(ChildIterator) Iter = aStudy->NewChildIterator( TableSO );
1034 for ( ; Iter->More(); Iter->Next() ) {
1035 CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
1036 if( !CORBA::is_nil( childObject ) ) {
1037 CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
1038 if( !CORBA::is_nil( aCurve ) ) {
1039 VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
1040 SPlot2d_Curve* plotCurve = 0;
1041 SPlot2d_Curve* tmpCurve;
1042 for ( int i = 0; i < clist.count(); i++ ) {
1043 tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
1044 if (tmpCurve && tmpCurve->hasIO() &&
1045 !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
1046 plotCurve = tmpCurve;
1051 UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
1053 if ( theDisplaying == VISU::eErase && plotCurve ) {
1054 clist.remove( plotCurve );
1064 PlotCurve(const SalomeApp_Module* theModule,
1065 VISU::Curve_i* theCurve,
1068 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1071 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1075 // if ( theDisplaying == VISU::eDisplayOnly )
1076 // aPlot->EraseAll();
1077 QList<Plot2d_Curve> clist;
1078 aPlot->getCurves( clist );
1079 SPlot2d_Curve* plotCurve = 0;
1080 SPlot2d_Curve* tmpCurve;
1081 for (int i = 0; i < clist.count(); i++) {
1082 tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
1083 if (tmpCurve && tmpCurve->hasIO() &&
1084 !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
1085 plotCurve = tmpCurve;
1086 } else if (theDisplaying == VISU::eDisplayOnly) {
1087 aPlot->eraseCurve(clist.at(i));
1091 UpdateCurve(theCurve, aPlot, plotCurve, theDisplaying);
1097 PlotContainer(const SalomeApp_Module* theModule,
1098 VISU::Container_i* container,
1101 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1104 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1108 if ( theDisplaying == VISU::eDisplayOnly )
1110 QList<Plot2d_Curve> clist;
1111 aPlot->getCurves( clist );
1112 if ( container->GetNbCurves() > 0 ) {
1113 int nbCurves = container->GetNbCurves();
1114 for ( int k = 1; k <= nbCurves; k++ ) {
1115 VISU::Curve_i* theCurve = container->GetCurve( k );
1116 if ( theCurve && theCurve->IsValid() ) {
1117 SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>
1118 (aView->getCurveByIO(new SALOME_InteractiveObject (theCurve->GetEntry(), "", "")));
1120 UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
1122 if ( plotCurve && theDisplaying == VISU::eErase ) {
1123 clist.remove( plotCurve );
1132 CreatePlot(SalomeApp_Module* theModule,
1133 _PTR(SObject) theTableSO)
1135 if ( IsSObjectTable(theTableSO) ) {
1136 CORBA::Object_var aTable = VISU::ClientSObjectToObject(theTableSO);
1137 CORBA::Object_var aContainer = GetVisuGen( theModule )->CreateContainer();
1138 if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) {
1139 VISU::Table_i* pTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
1140 VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aContainer).in());
1142 if ( pContainer && pTable ) {
1143 for ( int i = 2; i <= pTable->GetNbRows(); i++ ) {
1144 CORBA::Object_var aNewCurve = GetVisuGen( theModule )->CreateCurve( pTable->_this(), 1, i );
1145 if( !CORBA::is_nil( aNewCurve ) ) {
1146 VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aNewCurve).in() );
1148 pContainer->AddCurve( pCrv->_this() );
1152 PlotContainer( theModule, pContainer, VISU::eDisplay );
1158 //************************************************************
1161 void CreateMesh (const SalomeApp_Module* theModule,
1162 const Handle(SALOME_InteractiveObject)& theIO)
1164 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
1165 //if (CheckLock(aStudy))
1168 _PTR(SObject) aResultSObj = aStudy->FindObjectID(theIO->getEntry());
1171 VISU::Result_var aResult;
1172 VISU::Result_i* pResult = CheckResult(theModule, aResultSObj, aResult);
1173 if (pResult == NULL)
1176 Storable::TRestoringMap aMap = getMapOfValue(aResultSObj);
1178 string aComment = Storable::FindValue(aMap,"myComment",&isExist).latin1();
1182 CORBA::Object_var aMesh;
1183 string aMeshName = Storable::FindValue(aMap,"myMeshName").latin1();
1188 if (aComment == "ENTITY") {
1189 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myId").toInt();
1190 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity))
1191 aMesh = GetVisuGen(theModule)->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
1192 } else if (aComment == "FAMILY") {
1193 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myEntityId").toInt();
1194 string aFamilyName = Storable::FindValue(aMap,"myName").latin1();
1195 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()))
1196 aMesh = GetVisuGen(theModule)->FamilyMeshOnEntity
1197 (aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
1198 } else if (aComment == "GROUP") {
1199 string aGroupName = Storable::FindValue(aMap,"myName").latin1();
1200 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str()))
1201 aMesh = GetVisuGen(theModule)->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
1205 MESSAGE("VisuGUI::CreateMesh() - CREATE MESH");
1209 QApplication::restoreOverrideCursor();
1210 VISU::Mesh_i* pPresent = NULL;
1211 if (!CORBA::is_nil(aMesh))
1212 pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
1213 if (pPresent == NULL) {
1214 SUIT_MessageBox::warn1 (GetDesktop(theModule),
1215 QObject::tr("WRN_VISU"),
1216 QObject::tr("ERR_CANT_BUILD_PRESENTATION"),
1217 QObject::tr("BUT_OK"));
1221 if (SVTK_ViewWindow* aView = GetViewWindow(theModule)) {
1227 PublishInView(theModule, pPresent);
1228 //aView->onFitAll();
1232 MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
1235 theModule->application()->putInfo(QObject::tr("INF_DONE"));
1236 // Make "Save" button active
1237 theModule->getApp()->updateActions();
1238 } catch (std::runtime_error& exc) {
1240 SUIT_MessageBox::warn1 (GetDesktop(theModule),
1241 QObject::tr("WRN_VISU"),
1242 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()),
1243 QObject::tr("BUT_OK"));
1248 // ========================================================================================
1249 // GetPrs3dList: find list of presentations for the given object
1250 // ========================================================================================
1251 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1252 const Handle(SALOME_InteractiveObject)& theIO)
1254 std::vector<VISU::Prs3d_i*> aList;
1255 if (!theIO.IsNull() && theIO->hasEntry()) {
1256 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1257 _PTR(SObject) aSObject = aCStudy->FindObjectID(theIO->getEntry());
1258 aList = GetPrs3dList(theModule, aSObject);
1263 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1264 _PTR(SObject) theObject)
1266 std::vector<VISU::Prs3d_i*> aList; int k = 0;
1270 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1272 CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(theObject);
1273 if (!CORBA::is_nil(aCORBAObject)) {
1274 VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
1275 if (!CORBA::is_nil(aVisuObj)) {
1276 VISU::VISUType aType = aVisuObj->GetType();
1278 case VISU::TSCALARMAP:
1279 case VISU::TISOSURFACE:
1280 case VISU::TDEFORMEDSHAPE:
1281 case VISU::TCUTPLANES:
1282 case VISU::TCUTLINES:
1283 case VISU::TVECTORS:
1284 case VISU::TSTREAMLINES:
1287 PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1288 if (aServant.in()) {
1289 VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
1291 aList[k] = aPrsObject;
1298 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1299 _PTR(SObject) aTimeStamp;
1300 anIter->Next(); // First is reference on support
1301 for (; anIter->More(); anIter->Next()) {
1302 aTimeStamp = anIter->Value();
1303 if (!aTimeStamp) continue;
1304 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1305 if (!aSubList.empty()) {
1306 int n = aSubList.size();
1308 for (int i = 0; i < n; i++) {
1309 aList[k] = aSubList[i];
1319 _PTR(GenericAttribute) anAttr;
1320 if (theObject->FindAttribute(anAttr, "AttributeComment")) {
1321 _PTR(AttributeComment) aComment (anAttr);
1322 string aComm = aComment->Value();
1323 QString strIn (aComm.c_str());
1324 VISU::Storable::TRestoringMap pMap;
1325 VISU::Storable::StrToMap(strIn, pMap);
1327 VISU::VISUType aType =
1328 (VISU::VISUType)VISU::Storable::FindValue(pMap,"myType",&isExist).toInt();
1333 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1334 _PTR(SObject) aTimeStamp;
1335 anIter->Next(); // First is reference on support
1336 for (; anIter->More(); anIter->Next()) {
1337 aTimeStamp = anIter->Value();
1338 if (!aTimeStamp) continue;
1339 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1340 if (!aSubList.empty()) {
1341 int n = aSubList.size();
1343 for (int i = 0; i < n; i++) {
1344 aList[k] = aSubList[i];
1351 case VISU::TTIMESTAMP:
1353 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1355 for (; anIter->More(); anIter->Next()) {
1356 aPrs = anIter->Value();
1357 if (!aPrs) continue;
1358 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
1359 if (!aSubList.empty()) {
1360 int n = aSubList.size();
1362 for (int i = 0; i < n; i++) {
1363 aList[k] = aSubList[i];