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))
105 throw std::runtime_error(QObject::tr("WRN_STUDY_LOCKED").latin1());
110 GetVisuGen(const CAM_Module* theModule)
112 static VISU_Gen_i* aGen = NULL;
114 SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
115 Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","VISU");
116 VISU_Gen_var aVISU = VISU_Gen::_narrow(aComponent);
117 if(!CORBA::is_nil(aVISU)){
118 aGen = VISU_Gen_i::GetVisuGenImpl();
119 aGen->SetCurrentStudy(GetDSStudy(GetCStudy(GetAppStudy(theModule))));
123 throw std::runtime_error(QObject::tr("ERR_CANT_FIND_VISU_COMPONENT").latin1());
127 SALOME_MED::MED_Gen_var
130 static SALOME_MED::MED_Gen_var aGen;
131 if(CORBA::is_nil(aGen)){
132 SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
133 Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","MED");
134 aGen = SALOME_MED::MED_Gen::_narrow(aComponent);
136 if(CORBA::is_nil(aGen))
137 throw std::runtime_error(QObject::tr("ERR_CANT_FIND_MED_COMPONENT").latin1());
142 VISU::Storable::TRestoringMap getMapOfValue (_PTR(SObject) theSObject)
144 VISU::Storable::TRestoringMap aMap;
146 _PTR(GenericAttribute) anAttr;
147 if (theSObject->FindAttribute(anAttr, "AttributeComment")) {
148 _PTR(AttributeComment) aComment (anAttr);
149 std::string aValue = aComment->Value();
150 QString aString (aValue.c_str());
151 VISU::Storable::StrToMap(aString, aMap);
157 QString getValue (_PTR(SObject) theSObject, QString theKey)
160 VISU::Storable::TRestoringMap aMap = getMapOfValue(theSObject);
162 aStr = VISU::Storable::FindValue(aMap, theKey.latin1());
166 //------------------------------------------------------------
169 GetSelectedObj(const SalomeApp_Study* theStudy,
170 const QString& theEntry,
171 VISU::Storable::TRestoringMap* theMap)
173 if (!theStudy || theEntry.isEmpty())
174 return CORBA::Object::_nil();
176 _PTR(Study) aStudy = GetCStudy(theStudy);
177 _PTR(SObject) aSObject = aStudy->FindObjectID(theEntry.latin1());
179 _PTR(GenericAttribute) anAttr;
180 if (theMap && aSObject->FindAttribute(anAttr,"AttributeComment")) {
181 _PTR(AttributeComment) aComment (anAttr);
182 std::string aValue = aComment->Value();
183 QString aString (aValue.c_str());
184 VISU::Storable::StrToMap(aString, *theMap);
186 return VISU::ClientSObjectToObject(aSObject);
188 return CORBA::Object::_nil();
192 GetSelectedObj(const SalomeApp_Module* theModule,
193 Handle(SALOME_InteractiveObject)* theIO,
194 VISU::Storable::TRestoringMap* theMap)
196 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
197 SALOME_ListIO aListIO;
198 aSelectionMgr->selectedObjects(aListIO);
199 SALOME_ListIteratorOfListIO anIter(aListIO);
201 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
205 return GetSelectedObj( GetAppStudy(theModule), anIO->getEntry(), theMap );
207 return CORBA::Object::_nil();
211 GetPrsToModify(const SalomeApp_Module* theModule,
212 Handle(SALOME_InteractiveObject)* theIO,
213 VISU::Storable::TRestoringMap* theMap)
215 if (CheckLock(GetCStudy(GetAppStudy(theModule))))
218 CORBA::Object_var anObject = GetSelectedObj(theModule, theIO);
219 if (CORBA::is_nil(anObject))
222 PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
226 return dynamic_cast<VISU::Prs3d_i*>(aServant.in());
230 Add(LightApp_SelectionMgr* theSelectionMgr,
231 const Handle(SALOME_InteractiveObject)& theIO)
233 SALOME_ListIO aListIO;
234 theSelectionMgr->selectedObjects(aListIO);
235 aListIO.Append(theIO);
236 theSelectionMgr->setSelectedObjects(aListIO);
240 Remove(LightApp_SelectionMgr* theSelectionMgr,
241 const Handle(SALOME_InteractiveObject)& theIO)
243 if (theIO.IsNull()) return;
244 SALOME_ListIO aListIO, aNewListIO;
245 theSelectionMgr->selectedObjects(aListIO);
246 SALOME_ListIteratorOfListIO anIter (aListIO);
247 for (; anIter.More(); anIter.Next()) {
248 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
249 if (!anIO->isSame(theIO)) {
250 aNewListIO.Append(theIO);
253 theSelectionMgr->setSelectedObjects(aNewListIO);
257 * \brief Check, if "Delete" popup-menu can be put on current selection
259 * \param theModule - is used to access SelectionManager, Study and VISU_Gen
260 * \retval bool - returns TRUE if all currently selected objects are removable
263 IsRemovableSelected (const SalomeApp_Module* theModule)
265 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
266 SALOME_ListIO aListIO;
267 aSelectionMgr->selectedObjects(aListIO);
269 if (aListIO.Extent() < 1)
272 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
273 if (!aStudy) return false;
275 // In some cases single selection can have its own popup-menu item for deletion
276 /*if (aListIO.Extent() == 1) {
277 Handle(SALOME_InteractiveObject) anIO = aListIO.First();
278 _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry());
280 VISU::VISUType aType = (VISU::VISUType)getValue(aSObject, "myType").toInt();
281 if (aType == VISU::TVIEW3D) {
282 return false; // special case
287 SALOME_ListIteratorOfListIO anIter (aListIO);
288 for (; anIter.More(); anIter.Next()) {
289 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
290 if (anIO->hasEntry()) {
291 _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry());
292 VISU::Storable::TRestoringMap pMap;
294 CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(aSObject);
295 if (!CORBA::is_nil(aCORBAObject)) {
296 VISU::RemovableObject_var aRemovableObj = VISU::RemovableObject::_narrow(aCORBAObject);
297 if (CORBA::is_nil(aRemovableObj)) {
298 // Not removable CORBA object
302 // Can be removed, if lays directly under VISU
303 // (first sub-level) or is a child of such an object
304 string aNAME, aVisuNAME = GetVisuGen(theModule)->ComponentDataType();
305 _PTR(GenericAttribute) anAttr;
306 _PTR(AttributeComment) aComment;
308 bool isUnderVISU = false;
309 _PTR(SObject) aFatherSObject = aSObject->GetFather();
310 if (aFatherSObject->FindAttribute(anAttr, "AttributeComment")) {
311 _PTR(AttributeComment) aComment (anAttr);
312 aNAME = aComment->Value();
313 if (aNAME == aVisuNAME) {
318 // Not directly under VISU component, check father
319 aCORBAObject = VISU::ClientSObjectToObject(aFatherSObject);
320 if (!CORBA::is_nil(aCORBAObject)) {
326 aFatherSObject = aFatherSObject->GetFather();
327 if (aFatherSObject->FindAttribute(anAttr, "AttributeComment")) {
328 _PTR(AttributeComment) aComment (anAttr);
329 aNAME = aComment->Value();
330 if (aNAME == aVisuNAME) {
335 // Father is not directly under VISU component
346 //************************************************************
350 ErasePrs (const SalomeApp_Module* theModule,
351 CORBA::Object_ptr theObject, bool theUpdate)
353 if (!CORBA::is_nil(theObject)) {
354 VISU::Base_var aBase = VISU::Base::_narrow(theObject);
355 if (CORBA::is_nil(aBase)) return;
356 VISU::VISUType aType = aBase->GetType();
360 if (VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aBase).in()))
361 PlotCurve(theModule, aCurve, VISU::eErase );
364 case VISU::TCONTAINER:
366 if (VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aBase).in()))
367 PlotContainer(theModule, aContainer, VISU::eErase );
372 if (VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aBase).in()))
373 PlotTable(theModule, aTable, VISU::eErase );
378 if (VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(aBase).in())) {
379 ErasePrs3d(theModule, aPrsObject);
381 if (SVTK_ViewWindow* vw = GetViewWindow(theModule))
391 DeleteSObject (SalomeApp_Module* theModule,
392 _PTR(Study) theStudy,
393 _PTR(SObject) theSObject)
395 SalomeApp_Study* study = GetAppStudy( theModule );
397 _PTR(ChildIterator) aChildIter = theStudy->NewChildIterator(theSObject);
398 for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
399 _PTR(SObject) aChildSObject = aChildIter->Value();
401 CORBA::Object_var aChildObj = VISU::ClientSObjectToObject(aChildSObject);
402 ErasePrs(theModule, aChildObj);
405 CORBA::Object_var anObj = VISU::ClientSObjectToObject(theSObject);
406 if (!CORBA::is_nil(anObj)) {
407 ErasePrs(theModule, anObj);
409 VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObj);
410 if (!CORBA::is_nil(aRemovableObject)) {
411 aRemovableObject->RemoveFromStudy();
414 // Remove aSObject together with all its sub-objects
416 VISU::RemoveFromStudy(theSObject,
417 false, // remove not only IOR attribute, but Object With Children
418 false); // not Destroy() sub-objects
423 DeletePrs3d(SalomeApp_Module* theModule,
424 VISU::Prs3d_i* thePrs,
425 const Handle(SALOME_InteractiveObject)& theIO)
429 if (CheckLock(GetCStudy(GetAppStudy(theModule))))
431 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
432 CORBA::String_var anEntry = aSObject->GetID();
433 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
434 Remove(aSelectionMgr,theIO);
435 TViewWindows aViewWindows = GetViews(theModule);
436 for(int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++){
437 SVTK_ViewWindow* aView = aViewWindows[i];
438 if(VISU_Actor* anActor = FindActor(aView,anEntry.in())){
439 aView->RemoveActor(anActor);
443 thePrs->RemoveFromStudy();
447 ErasePrs3d(const SalomeApp_Module* theModule,
448 VISU::Prs3d_i* thePrs)
450 if ( SVTK_ViewWindow* vw = GetViewWindow( theModule ) ){
451 VISU_Actor* anVISUActor = FindActor( vw, thePrs );
453 anVISUActor->VisibilityOff();
458 //************************************************************
459 // Presentation management
462 ChangeRepresentation (const SalomeApp_Module* theModule,
463 VISU::PresentationType theType)
465 SUIT_ViewWindow* aView = GetActiveView(theModule, SVTK_Viewer::Type());
467 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( aView );
471 Handle(SALOME_InteractiveObject) anIO;
472 CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
473 if (CORBA::is_nil(anObject)) return;
475 VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
476 if (CORBA::is_nil(aVisuObj)) return;
478 PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
479 if (!aServant.in()) return;
481 VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
483 if (VISU_Actor* anActor = GetActor(aPrs3d, vw)) {
486 if (anActor->IsShrunk())
489 anActor->SetShrink();
492 if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
493 aMesh->SetPresentationType(theType);
494 RecreateActor(theModule, aMesh);
496 anActor->SetRepresentation(theType);
505 SetShading ( const SalomeApp_Module* theModule,
508 SUIT_ViewWindow* aView = GetActiveView(theModule, SVTK_Viewer::Type());
510 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( aView );
514 Handle(SALOME_InteractiveObject) anIO;
515 CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
516 if (CORBA::is_nil(anObject)) return;
518 VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
519 if (CORBA::is_nil(aVisuObj)) return;
521 PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
522 if (!aServant.in()) return;
524 VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
526 if (VISU_Actor* anActor = GetActor(aPrs3d, vw)) {
527 if ( VISU_ScalarMapAct* aScalarMapActor = dynamic_cast<VISU_ScalarMapAct*>(anActor) )
528 aScalarMapActor->SetShading( theOn );
534 //************************************************************
538 CheckTimeStamp(const SalomeApp_Module* theModule,
539 _PTR(SObject)& theSObject,
540 Handle(SALOME_InteractiveObject)* theIO)
542 Handle(SALOME_InteractiveObject) anIO;
543 CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
546 if (!anIO.IsNull() && anIO->hasEntry()){
547 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
548 theSObject = aStudy->FindObjectID(anIO->getEntry());
549 QString aValue = getValue(theSObject,"myType");
550 if (aValue.toInt() == int(VISU::TTIMESTAMP))
553 SUIT_MessageBox::warn1(GetDesktop(theModule),
554 QObject::tr("WRN_VISU"),
555 QObject::tr("WRN_NO_AVAILABLE_DATA"),
556 QObject::tr("BUT_OK") );
561 CheckResult(const SalomeApp_Module* theModule,
562 _PTR(SObject) theSource,
563 VISU::Result_var& theResult)
565 _PTR(SObject) aSObj = theSource->GetFather();
569 aSObj = aSObj->GetFather();
573 aSObj = aSObj->GetFather();
577 CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
578 if (CORBA::is_nil(anObject)) {
579 aSObj = aSObj->GetFather();
582 anObject = VISU::ClientSObjectToObject(aSObj);
585 if (CORBA::is_nil(anObject))
588 theResult = VISU::Result::_narrow(anObject);
589 VISU::Result_i* pResult = dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
591 SUIT_MessageBox::warn1(GetDesktop(theModule),
592 QObject::tr("WRN_VISU"),
593 QObject::tr("WRN_NO_AVAILABLE_DATA"),
594 QObject::tr("BUT_OK"));
598 //************************************************************
601 SUIT_ViewWindow* GetActiveView(const SalomeApp_Module* theModule, QString theType)
603 if(SalomeApp_Application* anApp = theModule->getApp()){
604 if(SUIT_ViewManager* aViewManager = anApp->activeViewManager()){
605 if (!theType.isNull()) {
606 if (aViewManager->getType() != theType)
609 return aViewManager->getActiveView();
615 //************************************************************
619 GetViews(const SalomeApp_Module* theModule)
621 TViewWindows aViewWindows;
622 if(SalomeApp_Application* anApp = theModule->getApp()){
623 ViewManagerList aViewManagerList;
624 anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
625 QPtrListIterator<SUIT_ViewManager> anIter(aViewManagerList);
626 while(SUIT_ViewManager* aViewManager = anIter.current()){
627 QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
628 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
629 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
630 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
631 aViewWindows.push_back(aView);
640 GetViewWindow( const SalomeApp_Module* theModule, const bool theCreate )
642 if (SalomeApp_Application* anApp = theModule->getApp())
644 SVTK_ViewWindow* wnd = dynamic_cast<SVTK_ViewWindow*>(anApp->desktop()->activeWindow());
649 SUIT_ViewManager* aViewManager = anApp->getViewManager( SVTK_Viewer::Type(), theCreate );
650 return dynamic_cast<SVTK_ViewWindow*>( aViewManager->getActiveView() );
657 GetViewWindow(const SalomeApp_Module* theModule, const bool theCreate )
659 if(SalomeApp_Application* anApp = theModule->getApp()){
660 if(SUIT_ViewManager* aViewManager = anApp->getViewManager( SVTK_Viewer::Type(), theCreate )){
661 if(SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()){
662 return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
673 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
674 (SUIT_Session::session()->activeApplication());
676 if (SUIT_ViewManager* aViewManager = anApp->activeViewManager()) {
677 if (aViewManager->getType() == SVTK_Viewer::Type()) {
678 if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
679 return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
688 PublishInView(const SalomeApp_Module* theModule,
689 VISU::Prs3d_i* thePrs)
691 VISU_Actor* aActor = NULL;
694 if(SVTK_ViewWindow* aView = GetViewWindow(theModule)){
695 QApplication::setOverrideCursor( Qt::waitCursor );
697 if(aActor = thePrs->CreateActor())
698 aView->AddActor(aActor);
699 }catch(std::exception& exc){
700 SUIT_MessageBox::warn1(GetDesktop(theModule),
701 QObject::tr("WRN_VISU"),
702 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()),
703 QObject::tr("BUT_OK"));
705 QApplication::restoreOverrideCursor();
711 UpdateViewer(const SalomeApp_Module* theModule,
712 VISU::Prs3d_i* thePrs,
715 SVTK_ViewWindow* vw = GetViewWindow( theModule );
716 if (!vw) return NULL;
718 vtkRenderer *aRen = vw->getRenderer();
719 vtkActorCollection *anActColl = aRen->GetActors();
722 VISU_Actor* anVISUActor = NULL;
723 VISU_Actor* aResActor = NULL;
724 for(anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ){
725 if(!SALOME_Actor::SafeDownCast(anActor))
727 if(anActor->IsA("VISU_Actor")){
728 anVISUActor = VISU_Actor::SafeDownCast(anActor);
729 VISU::Prs3d_i* aPrs = anVISUActor->GetPrs3d();
730 if(aPrs == NULL) continue;
731 if (thePrs == aPrs) {
732 aResActor = anVISUActor->GetParent();
734 thePrs->UpdateActor(aResActor);
735 aResActor->VisibilityOn();
736 } catch (std::runtime_error& ex) {
737 aResActor->VisibilityOff();
739 SUIT_MessageBox::warn1(GetDesktop(theModule), QObject::tr("WRN_VISU"),
740 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(ex.what()),
741 QObject::tr("BUT_OK"));
743 } else if (theDispOnly) {
744 anVISUActor->GetParent()->VisibilityOff();
747 } else if (theDispOnly && anActor->GetVisibility()) {
748 anActor->VisibilityOff();
755 //anVISUActor = PublishInView( theModule, thePrs );
760 RepaintViewWindows (const SalomeApp_Module* theModule,
761 const Handle(SALOME_InteractiveObject)& theIObject)
763 TViewWindows aViewWindows;
764 if (SalomeApp_Application* anApp = theModule->getApp()) {
765 ViewManagerList aViewManagerList;
766 anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
767 QPtrListIterator<SUIT_ViewManager> anIter (aViewManagerList);
768 while (SUIT_ViewManager* aViewManager = anIter.current()) {
769 QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
770 for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
771 if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
772 if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
773 if (vw->isVisible(theIObject)) {
774 vw->getRenderer()->ResetCameraClippingRange();
776 vw->highlight(theIObject, true, true);
787 FindActor(SVTK_ViewWindow* theViewWindow,
788 const char* theEntry)
791 if(vtkRenderer* aRenderer = theViewWindow->getRenderer()){
792 if(vtkActorCollection* aCollection = aRenderer->GetActors()){
793 if(VISU_Actor* anActor = Find<VISU_Actor>(aCollection,TIsSameEntry<VISU_Actor>(theEntry))){
794 return anActor->GetParent();
802 FindActor(SVTK_ViewWindow* theViewWindow,
803 VISU::Prs3d_i* thePrs)
805 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
806 CORBA::String_var anEntry = aSObject->GetID();
807 return FindActor(theViewWindow,anEntry.in());
811 RecreateActor (const SalomeApp_Module* theModule,
812 VISU::Prs3d_i* thePrs)
814 QApplication::setOverrideCursor(Qt::waitCursor);
815 bool isPublished = false;
817 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
818 CORBA::String_var anEntry = aSObject->GetID();
823 TViewWindows aViewWindows = GetViews(theModule);
824 for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
825 SVTK_ViewWindow* aView = aViewWindows[i];
826 if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
828 thePrs->UpdateActor(anActor);
831 } catch (std::runtime_error& ex) {
833 QApplication::restoreOverrideCursor();
834 SUIT_MessageBox::warn1 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
835 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(ex.what()),
836 QObject::tr("BUT_OK"));
838 TViewWindows aViewWindows = GetViews(theModule);
839 for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
840 SVTK_ViewWindow* aView = aViewWindows[i];
841 if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
842 aView->RemoveActor(anActor);
848 QApplication::restoreOverrideCursor();
851 PublishInView(theModule, thePrs);
854 static bool ComputeVisiblePropBounds(SVTK_ViewWindow* theViewWindow,
856 const char* theActorClassName = "VISU_Actor")
858 vtkRenderer *aRen = theViewWindow->getRenderer();
859 vtkActorCollection *anActColl = aRen->GetActors();
862 int somethingVisible = false;
864 allBounds[0] = allBounds[2] = allBounds[4] = VTK_LARGE_FLOAT;
865 allBounds[1] = allBounds[3] = allBounds[5] = -VTK_LARGE_FLOAT;
866 // loop through all props
867 for (anActColl->InitTraversal(); (prop = anActColl->GetNextProp()); ) {
868 // if it's invisible, or has no geometry, we can skip the rest
869 if (prop->GetVisibility() && prop->IsA(theActorClassName)) {
870 bounds = prop->GetBounds();
871 // make sure we haven't got bogus bounds
872 if (bounds != NULL &&
873 bounds[0] > -VTK_LARGE_FLOAT && bounds[1] < VTK_LARGE_FLOAT &&
874 bounds[2] > -VTK_LARGE_FLOAT && bounds[3] < VTK_LARGE_FLOAT &&
875 bounds[4] > -VTK_LARGE_FLOAT && bounds[5] < VTK_LARGE_FLOAT)
877 somethingVisible = true;
878 if (bounds[0] < allBounds[0]) allBounds[0] = bounds[0];
879 if (bounds[1] > allBounds[1]) allBounds[1] = bounds[1];
880 if (bounds[2] < allBounds[2]) allBounds[2] = bounds[2];
881 if (bounds[3] > allBounds[3]) allBounds[3] = bounds[3];
882 if (bounds[4] < allBounds[4]) allBounds[4] = bounds[4];
883 if (bounds[5] > allBounds[5]) allBounds[5] = bounds[5];
887 return somethingVisible;
890 void SetFitAll(SVTK_ViewWindow* theViewWindow)
892 static float PRECISION = 0.000001;
893 static float DEVIATION = 600;
895 if (!ComputeVisiblePropBounds(theViewWindow, XYZ_Bnd)) return;
897 float absX = XYZ_Bnd[1] - XYZ_Bnd[0];
898 float absY = XYZ_Bnd[3] - XYZ_Bnd[2];
899 float absZ = XYZ_Bnd[5] - XYZ_Bnd[4];
901 enum CameraOrient {e3D, eFront, eLeft, eTop};
902 CameraOrient aCameraOrient = e3D;
903 if (absX <= PRECISION) aCameraOrient = eFront;
905 if (absY <= PRECISION) aCameraOrient = eLeft;
907 if (absZ <= PRECISION) aCameraOrient = eTop;
909 // all the three dimensions exceeds precision
910 float dev_abs_XY = absX / absY;
911 float dev_abs_YZ = absY / absZ;
912 float dev_abs_XZ = absX / absZ;
913 if (dev_abs_XY >= DEVIATION || 1./dev_abs_YZ >= DEVIATION)
914 aCameraOrient = eLeft;
916 if (1./dev_abs_XY >= DEVIATION || 1./dev_abs_XZ >= DEVIATION)
917 aCameraOrient = eFront;
919 if (dev_abs_XZ >= DEVIATION || dev_abs_YZ >= DEVIATION)
920 aCameraOrient = eTop;
927 switch (aCameraOrient) {
928 case eFront: theViewWindow->onFrontView(); break;
929 case eLeft: theViewWindow->onLeftView(); break;
930 case eTop: theViewWindow->onTopView(); break;
931 case e3D: theViewWindow->onResetView(); break;
933 theViewWindow->getRenderer()->ResetCameraClippingRange();
934 theViewWindow->onFitAll();
937 //************************************************************
941 GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate)
943 if(SalomeApp_Application* anApp = theModule->getApp()){
944 if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){
945 return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
951 // Internal function used by several public functions below
953 UpdateCurve(VISU::Curve_i* theCurve,
954 Plot2d_ViewFrame* aPlot,
955 SPlot2d_Curve* plotCurve,
958 if ( theDisplaying == VISU::eErase ) {
959 if ( plotCurve && aPlot )
960 aPlot->eraseCurve( plotCurve, false );
962 else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
964 plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() );
965 //plotCurve->setVerTitle( ( theCurve->GetVerTitle().c_str() ) );
966 plotCurve->setVerTitle( theCurve->GetName() );
967 plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() );
968 plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() );
971 int nbPoints = theCurve->GetData( xList, yList );
972 if ( nbPoints > 0 && xList && yList ) {
973 plotCurve->setData( xList, yList, nbPoints );
975 if ( !theCurve->IsAuto() ) {
976 plotCurve->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
977 plotCurve->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() );
978 SALOMEDS::Color color = theCurve->GetColor();
979 plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
981 plotCurve->setAutoAssign( theCurve->IsAuto() );
983 aPlot->displayCurve( plotCurve, false );
986 Plot2d_Curve* crv = theCurve->CreatePresentation();
989 aPlot->displayCurve( crv, false );
990 theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
991 theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
992 SALOMEDS::Color newColor;
993 newColor.R = crv->getColor().red()/255.;
994 newColor.G = crv->getColor().green()/255.;
995 newColor.B = crv->getColor().blue()/255.;
996 theCurve->SetColor( newColor );
997 crv->setAutoAssign( theCurve->IsAuto() );
1004 PlotTable(const SalomeApp_Module* theModule,
1005 VISU::Table_i* table,
1008 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
1011 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1015 if ( theDisplaying == VISU::eDisplayOnly )
1017 QList<Plot2d_Curve> clist;
1018 aPlot->getCurves( clist );
1019 _PTR(Study) aStudy = GetCStudy( GetAppStudy( theModule ) );
1020 _PTR(SObject) TableSO = aStudy->FindObjectID( table->GetEntry().latin1() );
1022 _PTR(ChildIterator) Iter = aStudy->NewChildIterator( TableSO );
1023 for ( ; Iter->More(); Iter->Next() ) {
1024 CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
1025 if( !CORBA::is_nil( childObject ) ) {
1026 CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
1027 if( !CORBA::is_nil( aCurve ) ) {
1028 VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
1029 SPlot2d_Curve* plotCurve = 0;
1030 SPlot2d_Curve* tmpCurve;
1031 for ( int i = 0; i < clist.count(); i++ ) {
1032 tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
1033 if (tmpCurve && tmpCurve->hasIO() &&
1034 !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
1035 plotCurve = tmpCurve;
1040 UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
1042 if ( theDisplaying == VISU::eErase && plotCurve ) {
1043 clist.remove( plotCurve );
1053 PlotCurve(const SalomeApp_Module* theModule,
1054 VISU::Curve_i* theCurve,
1057 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1060 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1064 // if ( theDisplaying == VISU::eDisplayOnly )
1065 // aPlot->EraseAll();
1066 QList<Plot2d_Curve> clist;
1067 aPlot->getCurves( clist );
1068 SPlot2d_Curve* plotCurve = 0;
1069 SPlot2d_Curve* tmpCurve;
1070 for (int i = 0; i < clist.count(); i++) {
1071 tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
1072 if (tmpCurve && tmpCurve->hasIO() &&
1073 !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
1074 plotCurve = tmpCurve;
1075 } else if (theDisplaying == VISU::eDisplayOnly) {
1076 aPlot->eraseCurve(clist.at(i));
1080 UpdateCurve(theCurve, aPlot, plotCurve, theDisplaying);
1086 PlotContainer(const SalomeApp_Module* theModule,
1087 VISU::Container_i* container,
1090 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1093 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1097 if ( theDisplaying == VISU::eDisplayOnly )
1099 QList<Plot2d_Curve> clist;
1100 aPlot->getCurves( clist );
1101 if ( container->GetNbCurves() > 0 ) {
1102 int nbCurves = container->GetNbCurves();
1103 for ( int k = 1; k <= nbCurves; k++ ) {
1104 VISU::Curve_i* theCurve = container->GetCurve( k );
1105 if ( theCurve && theCurve->IsValid() ) {
1106 SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>
1107 (aView->getCurveByIO(new SALOME_InteractiveObject (theCurve->GetEntry(), "", "")));
1109 UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
1111 if ( plotCurve && theDisplaying == VISU::eErase ) {
1112 clist.remove( plotCurve );
1121 CreatePlot(SalomeApp_Module* theModule,
1122 _PTR(SObject) theTableSO)
1124 if ( IsSObjectTable(theTableSO) ) {
1125 CORBA::Object_var aTable = VISU::ClientSObjectToObject(theTableSO);
1126 CORBA::Object_var aContainer = GetVisuGen( theModule )->CreateContainer();
1127 if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) {
1128 VISU::Table_i* pTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
1129 VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aContainer).in());
1131 if ( pContainer && pTable ) {
1132 for ( int i = 2; i <= pTable->GetNbRows(); i++ ) {
1133 CORBA::Object_var aNewCurve = GetVisuGen( theModule )->CreateCurve( pTable->_this(), 1, i );
1134 if( !CORBA::is_nil( aNewCurve ) ) {
1135 VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aNewCurve).in() );
1137 pContainer->AddCurve( pCrv->_this() );
1141 PlotContainer( theModule, pContainer, VISU::eDisplay );
1147 //************************************************************
1150 void CreateMesh (const SalomeApp_Module* theModule,
1151 const Handle(SALOME_InteractiveObject)& theIO)
1153 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
1154 //if (CheckLock(aStudy))
1157 _PTR(SObject) aResultSObj = aStudy->FindObjectID(theIO->getEntry());
1160 VISU::Result_var aResult;
1161 VISU::Result_i* pResult = CheckResult(theModule, aResultSObj, aResult);
1162 if (pResult == NULL)
1165 Storable::TRestoringMap aMap = getMapOfValue(aResultSObj);
1167 string aComment = Storable::FindValue(aMap,"myComment",&isExist).latin1();
1171 CORBA::Object_var aMesh;
1172 string aMeshName = Storable::FindValue(aMap,"myMeshName").latin1();
1177 if (aComment == "ENTITY") {
1178 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myId").toInt();
1179 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity))
1180 aMesh = GetVisuGen(theModule)->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
1181 } else if (aComment == "FAMILY") {
1182 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myEntityId").toInt();
1183 string aFamilyName = Storable::FindValue(aMap,"myName").latin1();
1184 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()))
1185 aMesh = GetVisuGen(theModule)->FamilyMeshOnEntity
1186 (aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
1187 } else if (aComment == "GROUP") {
1188 string aGroupName = Storable::FindValue(aMap,"myName").latin1();
1189 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str()))
1190 aMesh = GetVisuGen(theModule)->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
1194 MESSAGE("VisuGUI::CreateMesh() - CREATE MESH");
1198 QApplication::restoreOverrideCursor();
1199 VISU::Mesh_i* pPresent = NULL;
1200 if (!CORBA::is_nil(aMesh))
1201 pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
1202 if (pPresent == NULL) {
1203 SUIT_MessageBox::warn1 (GetDesktop(theModule),
1204 QObject::tr("WRN_VISU"),
1205 QObject::tr("ERR_CANT_BUILD_PRESENTATION"),
1206 QObject::tr("BUT_OK"));
1210 if (SVTK_ViewWindow* aView = GetViewWindow(theModule)) {
1216 PublishInView(theModule, pPresent);
1217 //aView->onFitAll();
1221 MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
1224 theModule->application()->putInfo(QObject::tr("INF_DONE"));
1225 // Make "Save" button active
1226 theModule->getApp()->updateActions();
1227 } catch (std::runtime_error& exc) {
1229 SUIT_MessageBox::warn1 (GetDesktop(theModule),
1230 QObject::tr("WRN_VISU"),
1231 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()),
1232 QObject::tr("BUT_OK"));
1237 // ========================================================================================
1238 // GetPrs3dList: find list of presentations for the given object
1239 // ========================================================================================
1240 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1241 const Handle(SALOME_InteractiveObject)& theIO)
1243 std::vector<VISU::Prs3d_i*> aList;
1244 if (!theIO.IsNull() && theIO->hasEntry()) {
1245 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1246 _PTR(SObject) aSObject = aCStudy->FindObjectID(theIO->getEntry());
1247 aList = GetPrs3dList(theModule, aSObject);
1252 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1253 _PTR(SObject) theObject)
1255 std::vector<VISU::Prs3d_i*> aList; int k = 0;
1259 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1261 CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(theObject);
1262 if (!CORBA::is_nil(aCORBAObject)) {
1263 VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
1264 if (!CORBA::is_nil(aVisuObj)) {
1265 VISU::VISUType aType = aVisuObj->GetType();
1267 case VISU::TSCALARMAP:
1268 case VISU::TISOSURFACE:
1269 case VISU::TDEFORMEDSHAPE:
1270 case VISU::TCUTPLANES:
1271 case VISU::TCUTLINES:
1272 case VISU::TVECTORS:
1273 case VISU::TSTREAMLINES:
1276 PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1277 if (aServant.in()) {
1278 VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
1280 aList[k] = aPrsObject;
1287 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1288 _PTR(SObject) aTimeStamp;
1289 anIter->Next(); // First is reference on support
1290 for (; anIter->More(); anIter->Next()) {
1291 aTimeStamp = anIter->Value();
1292 if (!aTimeStamp) continue;
1293 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1294 if (!aSubList.empty()) {
1295 int n = aSubList.size();
1297 for (int i = 0; i < n; i++) {
1298 aList[k] = aSubList[i];
1308 _PTR(GenericAttribute) anAttr;
1309 if (theObject->FindAttribute(anAttr, "AttributeComment")) {
1310 _PTR(AttributeComment) aComment (anAttr);
1311 string aComm = aComment->Value();
1312 QString strIn (aComm.c_str());
1313 VISU::Storable::TRestoringMap pMap;
1314 VISU::Storable::StrToMap(strIn, pMap);
1316 VISU::VISUType aType =
1317 (VISU::VISUType)VISU::Storable::FindValue(pMap,"myType",&isExist).toInt();
1322 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1323 _PTR(SObject) aTimeStamp;
1324 anIter->Next(); // First is reference on support
1325 for (; anIter->More(); anIter->Next()) {
1326 aTimeStamp = anIter->Value();
1327 if (!aTimeStamp) continue;
1328 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1329 if (!aSubList.empty()) {
1330 int n = aSubList.size();
1332 for (int i = 0; i < n; i++) {
1333 aList[k] = aSubList[i];
1340 case VISU::TTIMESTAMP:
1342 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1344 for (; anIter->More(); anIter->Next()) {
1345 aPrs = anIter->Value();
1346 if (!aPrs) continue;
1347 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
1348 if (!aSubList.empty()) {
1349 int n = aSubList.size();
1351 for (int i = 0; i < n; i++) {
1352 aList[k] = aSubList[i];