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 "SalomeApp_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 SalomeApp_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 SalomeApp_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(SalomeApp_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(SalomeApp_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 SalomeApp_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 );
396 study->deleteReferencesTo( theSObject );
398 _PTR(ChildIterator) aChildIter = theStudy->NewChildIterator(theSObject);
399 for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
400 _PTR(SObject) aChildSObject = aChildIter->Value();
401 study->deleteReferencesTo( aChildSObject );
402 CORBA::Object_var aChildObj = VISU::ClientSObjectToObject(aChildSObject);
403 ErasePrs(theModule, aChildObj);
406 CORBA::Object_var anObj = VISU::ClientSObjectToObject(theSObject);
407 if (!CORBA::is_nil(anObj)) {
408 ErasePrs(theModule, anObj);
410 VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObj);
411 if (!CORBA::is_nil(aRemovableObject)) {
412 aRemovableObject->RemoveFromStudy();
415 // Remove aSObject together with all its sub-objects
417 VISU::RemoveFromStudy(theSObject,
418 false, // remove not only IOR attribute, but Object With Children
419 false); // not Destroy() sub-objects
424 DeletePrs3d(SalomeApp_Module* theModule,
425 VISU::Prs3d_i* thePrs,
426 const Handle(SALOME_InteractiveObject)& theIO)
430 if (CheckLock(GetCStudy(GetAppStudy(theModule))))
432 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
433 CORBA::String_var anEntry = aSObject->GetID();
434 SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
435 Remove(aSelectionMgr,theIO);
436 TViewWindows aViewWindows = GetViews(theModule);
437 for(int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++){
438 SVTK_ViewWindow* aView = aViewWindows[i];
439 if(VISU_Actor* anActor = FindActor(aView,anEntry.in())){
440 aView->RemoveActor(anActor);
444 thePrs->RemoveFromStudy();
448 ErasePrs3d(const SalomeApp_Module* theModule,
449 VISU::Prs3d_i* thePrs)
451 if ( SVTK_ViewWindow* vw = GetViewWindow( theModule ) ){
452 VISU_Actor* anVISUActor = FindActor( vw, thePrs );
454 anVISUActor->VisibilityOff();
459 //************************************************************
460 // Presentation management
463 ChangeRepresentation (const SalomeApp_Module* theModule,
464 VISU::PresentationType theType)
466 SUIT_ViewWindow* aView = GetActiveView(theModule, SVTK_Viewer::Type());
468 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( aView );
472 Handle(SALOME_InteractiveObject) anIO;
473 CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
474 if (CORBA::is_nil(anObject)) return;
476 VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
477 if (CORBA::is_nil(aVisuObj)) return;
479 PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
480 if (!aServant.in()) return;
482 VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
484 if (VISU_Actor* anActor = GetActor(aPrs3d, vw)) {
487 if (anActor->IsShrunk())
490 anActor->SetShrink();
493 if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
494 aMesh->SetPresentationType(theType);
495 RecreateActor(theModule, aMesh);
497 anActor->SetRepresentation(theType);
506 SetShading ( const SalomeApp_Module* theModule,
509 SUIT_ViewWindow* aView = GetActiveView(theModule, SVTK_Viewer::Type());
511 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( aView );
515 Handle(SALOME_InteractiveObject) anIO;
516 CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
517 if (CORBA::is_nil(anObject)) return;
519 VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
520 if (CORBA::is_nil(aVisuObj)) return;
522 PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
523 if (!aServant.in()) return;
525 VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
527 if (VISU_Actor* anActor = GetActor(aPrs3d, vw)) {
528 if ( VISU_ScalarMapAct* aScalarMapActor = dynamic_cast<VISU_ScalarMapAct*>(anActor) )
529 aScalarMapActor->SetShading( theOn );
535 //************************************************************
539 CheckTimeStamp(const SalomeApp_Module* theModule,
540 _PTR(SObject)& theSObject,
541 Handle(SALOME_InteractiveObject)* theIO)
543 Handle(SALOME_InteractiveObject) anIO;
544 CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
547 if (!anIO.IsNull() && anIO->hasEntry()){
548 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
549 theSObject = aStudy->FindObjectID(anIO->getEntry());
550 QString aValue = getValue(theSObject,"myType");
551 if (aValue.toInt() == int(VISU::TTIMESTAMP))
554 SUIT_MessageBox::warn1(GetDesktop(theModule),
555 QObject::tr("WRN_VISU"),
556 QObject::tr("WRN_NO_AVAILABLE_DATA"),
557 QObject::tr("BUT_OK") );
562 CheckResult(const SalomeApp_Module* theModule,
563 _PTR(SObject) theSource,
564 VISU::Result_var& theResult)
566 _PTR(SObject) aSObj = theSource->GetFather();
570 aSObj = aSObj->GetFather();
574 aSObj = aSObj->GetFather();
578 CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
579 if (CORBA::is_nil(anObject)) {
580 aSObj = aSObj->GetFather();
583 anObject = VISU::ClientSObjectToObject(aSObj);
586 if (CORBA::is_nil(anObject))
589 theResult = VISU::Result::_narrow(anObject);
590 VISU::Result_i* pResult = dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
592 SUIT_MessageBox::warn1(GetDesktop(theModule),
593 QObject::tr("WRN_VISU"),
594 QObject::tr("WRN_NO_AVAILABLE_DATA"),
595 QObject::tr("BUT_OK"));
599 //************************************************************
602 SUIT_ViewWindow* GetActiveView(const SalomeApp_Module* theModule, QString theType)
604 if(SalomeApp_Application* anApp = theModule->getApp()){
605 if(SUIT_ViewManager* aViewManager = anApp->activeViewManager()){
606 if (!theType.isNull()) {
607 if (aViewManager->getType() != theType)
610 return aViewManager->getActiveView();
616 //************************************************************
620 GetViews(const SalomeApp_Module* theModule)
622 TViewWindows aViewWindows;
623 if(SalomeApp_Application* anApp = theModule->getApp()){
624 ViewManagerList aViewManagerList;
625 anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
626 QPtrListIterator<SUIT_ViewManager> anIter(aViewManagerList);
627 while(SUIT_ViewManager* aViewManager = anIter.current()){
628 QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
629 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
630 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
631 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
632 aViewWindows.push_back(aView);
641 GetViewWindow(const SalomeApp_Module* theModule, const bool theCreate )
643 if(SalomeApp_Application* anApp = theModule->getApp()){
644 if(SUIT_ViewManager* aViewManager = anApp->getViewManager( SVTK_Viewer::Type(), theCreate )){
645 if(SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()){
646 return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
657 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
658 (SUIT_Session::session()->activeApplication());
660 if (SUIT_ViewManager* aViewManager = anApp->activeViewManager()) {
661 if (aViewManager->getType() == SVTK_Viewer::Type()) {
662 if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
663 return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
672 PublishInView(const SalomeApp_Module* theModule,
673 VISU::Prs3d_i* thePrs)
675 VISU_Actor* aActor = NULL;
678 if(SVTK_ViewWindow* aView = GetViewWindow(theModule)){
679 QApplication::setOverrideCursor( Qt::waitCursor );
681 if(aActor = thePrs->CreateActor())
682 aView->AddActor(aActor);
683 }catch(std::exception& exc){
684 SUIT_MessageBox::warn1(GetDesktop(theModule),
685 QObject::tr("WRN_VISU"),
686 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()),
687 QObject::tr("BUT_OK"));
689 QApplication::restoreOverrideCursor();
695 UpdateViewer(const SalomeApp_Module* theModule,
696 VISU::Prs3d_i* thePrs,
699 SVTK_ViewWindow* vw = GetViewWindow( theModule );
700 if (!vw) return NULL;
702 vtkRenderer *aRen = vw->getRenderer();
703 vtkActorCollection *anActColl = aRen->GetActors();
706 VISU_Actor* anVISUActor = NULL;
707 VISU_Actor* aResActor = NULL;
708 for(anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ){
709 if(!SALOME_Actor::SafeDownCast(anActor))
711 if(anActor->IsA("VISU_Actor")){
712 anVISUActor = VISU_Actor::SafeDownCast(anActor);
713 VISU::Prs3d_i* aPrs = anVISUActor->GetPrs3d();
714 if(aPrs == NULL) continue;
715 if (thePrs == aPrs) {
716 aResActor = anVISUActor->GetParent();
717 thePrs->UpdateActor(aResActor);
718 aResActor->VisibilityOn();
720 } else if (theDispOnly) {
721 anVISUActor->GetParent()->VisibilityOff();
724 } else if (theDispOnly && anActor->GetVisibility()) {
725 anActor->VisibilityOff();
732 anVISUActor = PublishInView( theModule, thePrs );
737 RepaintViewWindows (const SalomeApp_Module* theModule,
738 const Handle(SALOME_InteractiveObject)& theIObject)
740 TViewWindows aViewWindows;
741 if (SalomeApp_Application* anApp = theModule->getApp()) {
742 ViewManagerList aViewManagerList;
743 anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
744 QPtrListIterator<SUIT_ViewManager> anIter (aViewManagerList);
745 while (SUIT_ViewManager* aViewManager = anIter.current()) {
746 QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
747 for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
748 if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
749 if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
750 if (vw->isVisible(theIObject)) {
751 vw->getRenderer()->ResetCameraClippingRange();
753 vw->highlight(theIObject, true, true);
764 FindActor(SVTK_ViewWindow* theViewWindow,
765 const char* theEntry)
768 if(vtkRenderer* aRenderer = theViewWindow->getRenderer()){
769 if(vtkActorCollection* aCollection = aRenderer->GetActors()){
770 if(VISU_Actor* anActor = Find<VISU_Actor>(aCollection,TIsSameEntry<VISU_Actor>(theEntry))){
771 return anActor->GetParent();
779 FindActor(SVTK_ViewWindow* theViewWindow,
780 VISU::Prs3d_i* thePrs)
782 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
783 CORBA::String_var anEntry = aSObject->GetID();
784 return FindActor(theViewWindow,anEntry.in());
788 RecreateActor (const SalomeApp_Module* theModule,
789 VISU::Prs3d_i* thePrs)
791 QApplication::setOverrideCursor(Qt::waitCursor);
792 bool isPublished = false;
794 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
795 CORBA::String_var anEntry = aSObject->GetID();
800 TViewWindows aViewWindows = GetViews(theModule);
801 for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
802 SVTK_ViewWindow* aView = aViewWindows[i];
803 if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
805 thePrs->UpdateActor(anActor);
808 } catch (std::runtime_error& ex) {
810 QApplication::restoreOverrideCursor();
811 SUIT_MessageBox::warn1 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
812 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(ex.what()),
813 QObject::tr("BUT_OK"));
815 TViewWindows aViewWindows = GetViews(theModule);
816 for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
817 SVTK_ViewWindow* aView = aViewWindows[i];
818 if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
819 aView->RemoveActor(anActor);
825 QApplication::restoreOverrideCursor();
828 PublishInView(theModule, thePrs);
831 static bool ComputeVisiblePropBounds(SVTK_ViewWindow* theViewWindow,
833 const char* theActorClassName = "VISU_Actor")
835 vtkRenderer *aRen = theViewWindow->getRenderer();
836 vtkActorCollection *anActColl = aRen->GetActors();
839 int somethingVisible = false;
841 allBounds[0] = allBounds[2] = allBounds[4] = VTK_LARGE_FLOAT;
842 allBounds[1] = allBounds[3] = allBounds[5] = -VTK_LARGE_FLOAT;
843 // loop through all props
844 for (anActColl->InitTraversal(); (prop = anActColl->GetNextProp()); ) {
845 // if it's invisible, or has no geometry, we can skip the rest
846 if (prop->GetVisibility() && prop->IsA(theActorClassName)) {
847 bounds = prop->GetBounds();
848 // make sure we haven't got bogus bounds
849 if (bounds != NULL &&
850 bounds[0] > -VTK_LARGE_FLOAT && bounds[1] < VTK_LARGE_FLOAT &&
851 bounds[2] > -VTK_LARGE_FLOAT && bounds[3] < VTK_LARGE_FLOAT &&
852 bounds[4] > -VTK_LARGE_FLOAT && bounds[5] < VTK_LARGE_FLOAT)
854 somethingVisible = true;
855 if (bounds[0] < allBounds[0]) allBounds[0] = bounds[0];
856 if (bounds[1] > allBounds[1]) allBounds[1] = bounds[1];
857 if (bounds[2] < allBounds[2]) allBounds[2] = bounds[2];
858 if (bounds[3] > allBounds[3]) allBounds[3] = bounds[3];
859 if (bounds[4] < allBounds[4]) allBounds[4] = bounds[4];
860 if (bounds[5] > allBounds[5]) allBounds[5] = bounds[5];
864 return somethingVisible;
867 void SetFitAll(SVTK_ViewWindow* theViewWindow)
869 static float PRECISION = 0.000001;
870 static float DEVIATION = 600;
872 if (!ComputeVisiblePropBounds(theViewWindow, XYZ_Bnd)) return;
874 float absX = XYZ_Bnd[1] - XYZ_Bnd[0];
875 float absY = XYZ_Bnd[3] - XYZ_Bnd[2];
876 float absZ = XYZ_Bnd[5] - XYZ_Bnd[4];
878 enum CameraOrient {e3D, eFront, eLeft, eTop};
879 CameraOrient aCameraOrient = e3D;
880 if (absX <= PRECISION) aCameraOrient = eFront;
882 if (absY <= PRECISION) aCameraOrient = eLeft;
884 if (absZ <= PRECISION) aCameraOrient = eTop;
886 // all the three dimensions exceeds precision
887 float dev_abs_XY = absX / absY;
888 float dev_abs_YZ = absY / absZ;
889 float dev_abs_XZ = absX / absZ;
890 if (dev_abs_XY >= DEVIATION || 1./dev_abs_YZ >= DEVIATION)
891 aCameraOrient = eLeft;
893 if (1./dev_abs_XY >= DEVIATION || 1./dev_abs_XZ >= DEVIATION)
894 aCameraOrient = eFront;
896 if (dev_abs_XZ >= DEVIATION || dev_abs_YZ >= DEVIATION)
897 aCameraOrient = eTop;
904 switch (aCameraOrient) {
905 case eFront: theViewWindow->onFrontView(); break;
906 case eLeft: theViewWindow->onLeftView(); break;
907 case eTop: theViewWindow->onTopView(); break;
908 case e3D: theViewWindow->onResetView(); break;
910 theViewWindow->getRenderer()->ResetCameraClippingRange();
911 theViewWindow->onFitAll();
914 //************************************************************
918 GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate)
920 if(SalomeApp_Application* anApp = theModule->getApp()){
921 if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){
922 return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
928 // Internal function used by several public functions below
930 UpdateCurve(VISU::Curve_i* theCurve,
931 Plot2d_ViewFrame* aPlot,
932 SPlot2d_Curve* plotCurve,
935 if ( theDisplaying == VISU::eErase ) {
937 aPlot->eraseCurve( plotCurve, false );
939 else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
941 plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() );
942 //plotCurve->setVerTitle( ( theCurve->GetVerTitle().c_str() ) );
943 plotCurve->setVerTitle( theCurve->GetName() );
944 plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() );
945 plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() );
948 int nbPoints = theCurve->GetData( xList, yList );
949 if ( nbPoints > 0 && xList && yList ) {
950 plotCurve->setData( xList, yList, nbPoints );
952 if ( !theCurve->IsAuto() ) {
953 plotCurve->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
954 plotCurve->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() );
955 SALOMEDS::Color color = theCurve->GetColor();
956 plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
958 plotCurve->setAutoAssign( theCurve->IsAuto() );
959 aPlot->displayCurve( plotCurve, false );
962 Plot2d_Curve* crv = theCurve->CreatePresentation();
964 aPlot->displayCurve( crv, false );
965 theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
966 theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
967 SALOMEDS::Color newColor;
968 newColor.R = crv->getColor().red()/255.;
969 newColor.G = crv->getColor().green()/255.;
970 newColor.B = crv->getColor().blue()/255.;
971 theCurve->SetColor( newColor );
972 crv->setAutoAssign( theCurve->IsAuto() );
979 PlotTable(const SalomeApp_Module* theModule,
980 VISU::Table_i* table,
983 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
986 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
990 if ( theDisplaying == VISU::eDisplayOnly )
992 QList<Plot2d_Curve> clist;
993 aPlot->getCurves( clist );
994 _PTR(Study) aStudy = GetCStudy( GetAppStudy( theModule ) );
995 _PTR(SObject) TableSO = aStudy->FindObjectID( table->GetEntry().latin1() );
997 _PTR(ChildIterator) Iter = aStudy->NewChildIterator( TableSO );
998 for ( ; Iter->More(); Iter->Next() ) {
999 CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
1000 if( !CORBA::is_nil( childObject ) ) {
1001 CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
1002 if( !CORBA::is_nil( aCurve ) ) {
1003 VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
1004 SPlot2d_Curve* plotCurve = 0;
1005 SPlot2d_Curve* tmpCurve;
1006 for ( int i = 0; i < clist.count(); i++ ) {
1007 tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
1008 if (tmpCurve && tmpCurve->hasIO() &&
1009 !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
1010 plotCurve = tmpCurve;
1015 UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
1017 if ( theDisplaying == VISU::eErase && plotCurve ) {
1018 clist.remove( plotCurve );
1028 PlotCurve(const SalomeApp_Module* theModule,
1029 VISU::Curve_i* theCurve,
1032 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1035 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1039 // if ( theDisplaying == VISU::eDisplayOnly )
1040 // aPlot->EraseAll();
1041 QList<Plot2d_Curve> clist;
1042 aPlot->getCurves( clist );
1043 SPlot2d_Curve* plotCurve = 0;
1044 SPlot2d_Curve* tmpCurve;
1045 for (int i = 0; i < clist.count(); i++) {
1046 tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
1047 if (tmpCurve && tmpCurve->hasIO() &&
1048 !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
1049 plotCurve = tmpCurve;
1050 } else if (theDisplaying == VISU::eDisplayOnly) {
1051 aPlot->eraseCurve(clist.at(i));
1055 UpdateCurve(theCurve, aPlot, plotCurve, theDisplaying);
1061 PlotContainer(const SalomeApp_Module* theModule,
1062 VISU::Container_i* container,
1065 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1068 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1072 if ( theDisplaying == VISU::eDisplayOnly )
1074 QList<Plot2d_Curve> clist;
1075 aPlot->getCurves( clist );
1076 if ( container->GetNbCurves() > 0 ) {
1077 int nbCurves = container->GetNbCurves();
1078 for ( int k = 1; k <= nbCurves; k++ ) {
1079 VISU::Curve_i* theCurve = container->GetCurve( k );
1080 if ( theCurve && theCurve->IsValid() ) {
1081 SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>
1082 (aView->getCurveByIO(new SALOME_InteractiveObject (theCurve->GetEntry(), "", "")));
1084 UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
1086 if ( plotCurve && theDisplaying == VISU::eErase ) {
1087 clist.remove( plotCurve );
1096 CreatePlot(SalomeApp_Module* theModule,
1097 _PTR(SObject) theTableSO)
1099 if ( IsSObjectTable(theTableSO) ) {
1100 CORBA::Object_var aTable = VISU::ClientSObjectToObject(theTableSO);
1101 CORBA::Object_var aContainer = GetVisuGen( theModule )->CreateContainer();
1102 if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) {
1103 VISU::Table_i* pTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
1104 VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aContainer).in());
1106 if ( pContainer && pTable ) {
1107 for ( int i = 2; i <= pTable->GetNbRows(); i++ ) {
1108 CORBA::Object_var aNewCurve = GetVisuGen( theModule )->CreateCurve( pTable->_this(), 1, i );
1109 if( !CORBA::is_nil( aNewCurve ) ) {
1110 VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aNewCurve).in() );
1112 pContainer->AddCurve( pCrv->_this() );
1116 PlotContainer( theModule, pContainer, VISU::eDisplay );
1122 //************************************************************
1125 void CreateMesh (const SalomeApp_Module* theModule,
1126 const Handle(SALOME_InteractiveObject)& theIO)
1128 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
1129 //if (CheckLock(aStudy))
1132 _PTR(SObject) aResultSObj = aStudy->FindObjectID(theIO->getEntry());
1135 VISU::Result_var aResult;
1136 VISU::Result_i* pResult = CheckResult(theModule, aResultSObj, aResult);
1137 if (pResult == NULL)
1140 Storable::TRestoringMap aMap = getMapOfValue(aResultSObj);
1142 string aComment = Storable::FindValue(aMap,"myComment",&isExist).latin1();
1146 CORBA::Object_var aMesh;
1147 string aMeshName = Storable::FindValue(aMap,"myMeshName").latin1();
1152 if (aComment == "ENTITY") {
1153 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myId").toInt();
1154 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity))
1155 aMesh = GetVisuGen(theModule)->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
1156 } else if (aComment == "FAMILY") {
1157 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myEntityId").toInt();
1158 string aFamilyName = Storable::FindValue(aMap,"myName").latin1();
1159 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()))
1160 aMesh = GetVisuGen(theModule)->FamilyMeshOnEntity
1161 (aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
1162 } else if (aComment == "GROUP") {
1163 string aGroupName = Storable::FindValue(aMap,"myName").latin1();
1164 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str()))
1165 aMesh = GetVisuGen(theModule)->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
1169 MESSAGE("VisuGUI::CreateMesh() - CREATE MESH");
1173 QApplication::restoreOverrideCursor();
1174 VISU::Mesh_i* pPresent = NULL;
1175 if (!CORBA::is_nil(aMesh))
1176 pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
1177 if (pPresent == NULL) {
1178 SUIT_MessageBox::warn1 (GetDesktop(theModule),
1179 QObject::tr("WRN_VISU"),
1180 QObject::tr("ERR_CANT_BUILD_PRESENTATION"),
1181 QObject::tr("BUT_OK"));
1185 if (SVTK_ViewWindow* aView = GetViewWindow(theModule)) {
1191 PublishInView(theModule, pPresent);
1192 //aView->onFitAll();
1196 MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
1199 theModule->application()->putInfo(QObject::tr("INF_DONE"));
1200 // Make "Save" button active
1201 theModule->getApp()->updateActions();
1202 } catch (std::runtime_error& exc) {
1204 SUIT_MessageBox::warn1 (GetDesktop(theModule),
1205 QObject::tr("WRN_VISU"),
1206 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()),
1207 QObject::tr("BUT_OK"));
1212 // ========================================================================================
1213 // GetPrs3dList: find list of presentations for the given object
1214 // ========================================================================================
1215 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1216 const Handle(SALOME_InteractiveObject)& theIO)
1218 std::vector<VISU::Prs3d_i*> aList;
1219 if (!theIO.IsNull() && theIO->hasEntry()) {
1220 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1221 _PTR(SObject) aSObject = aCStudy->FindObjectID(theIO->getEntry());
1222 aList = GetPrs3dList(theModule, aSObject);
1227 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1228 _PTR(SObject) theObject)
1230 std::vector<VISU::Prs3d_i*> aList; int k = 0;
1234 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1236 CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(theObject);
1237 if (!CORBA::is_nil(aCORBAObject)) {
1238 VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
1239 if (!CORBA::is_nil(aVisuObj)) {
1240 VISU::VISUType aType = aVisuObj->GetType();
1242 case VISU::TSCALARMAP:
1243 case VISU::TISOSURFACE:
1244 case VISU::TDEFORMEDSHAPE:
1245 case VISU::TCUTPLANES:
1246 case VISU::TCUTLINES:
1247 case VISU::TVECTORS:
1248 case VISU::TSTREAMLINES:
1251 PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1252 if (aServant.in()) {
1253 VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
1255 aList[k] = aPrsObject;
1262 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1263 _PTR(SObject) aTimeStamp;
1264 anIter->Next(); // First is reference on support
1265 for (; anIter->More(); anIter->Next()) {
1266 aTimeStamp = anIter->Value();
1267 if (!aTimeStamp) continue;
1268 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1269 if (!aSubList.empty()) {
1270 int n = aSubList.size();
1272 for (int i = 0; i < n; i++) {
1273 aList[k] = aSubList[i];
1283 _PTR(GenericAttribute) anAttr;
1284 if (theObject->FindAttribute(anAttr, "AttributeComment")) {
1285 _PTR(AttributeComment) aComment (anAttr);
1286 string aComm = aComment->Value();
1287 QString strIn (aComm.c_str());
1288 VISU::Storable::TRestoringMap pMap;
1289 VISU::Storable::StrToMap(strIn, pMap);
1291 VISU::VISUType aType =
1292 (VISU::VISUType)VISU::Storable::FindValue(pMap,"myType",&isExist).toInt();
1297 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1298 _PTR(SObject) aTimeStamp;
1299 anIter->Next(); // First is reference on support
1300 for (; anIter->More(); anIter->Next()) {
1301 aTimeStamp = anIter->Value();
1302 if (!aTimeStamp) continue;
1303 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1304 if (!aSubList.empty()) {
1305 int n = aSubList.size();
1307 for (int i = 0; i < n; i++) {
1308 aList[k] = aSubList[i];
1315 case VISU::TTIMESTAMP:
1317 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1319 for (; anIter->More(); anIter->Next()) {
1320 aPrs = anIter->Value();
1321 if (!aPrs) continue;
1322 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
1323 if (!aSubList.empty()) {
1324 int n = aSubList.size();
1326 for (int i = 0; i < n; i++) {
1327 aList[k] = aSubList[i];