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 );
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 VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(aChildObj);
403 if( !CORBA::is_nil( aRemovableObject ) )
404 study->deleteReferencesTo( aChildSObject );
405 ErasePrs(theModule, aChildObj);
408 CORBA::Object_var anObj = VISU::ClientSObjectToObject(theSObject);
409 if (!CORBA::is_nil(anObj)) {
410 ErasePrs(theModule, anObj);
412 VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObj);
413 if (!CORBA::is_nil(aRemovableObject)) {
414 study->deleteReferencesTo( theSObject );
415 aRemovableObject->RemoveFromStudy();
418 // Remove aSObject together with all its sub-objects
420 VISU::RemoveFromStudy(theSObject,
421 false, // remove not only IOR attribute, but Object With Children
422 false); // not Destroy() sub-objects
427 DeletePrs3d(SalomeApp_Module* theModule,
428 VISU::Prs3d_i* thePrs,
429 const Handle(SALOME_InteractiveObject)& theIO)
433 if (CheckLock(GetCStudy(GetAppStudy(theModule))))
435 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
436 CORBA::String_var anEntry = aSObject->GetID();
437 SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
438 Remove(aSelectionMgr,theIO);
439 TViewWindows aViewWindows = GetViews(theModule);
440 for(int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++){
441 SVTK_ViewWindow* aView = aViewWindows[i];
442 if(VISU_Actor* anActor = FindActor(aView,anEntry.in())){
443 aView->RemoveActor(anActor);
447 thePrs->RemoveFromStudy();
451 ErasePrs3d(const SalomeApp_Module* theModule,
452 VISU::Prs3d_i* thePrs)
454 if ( SVTK_ViewWindow* vw = GetViewWindow( theModule ) ){
455 VISU_Actor* anVISUActor = FindActor( vw, thePrs );
457 anVISUActor->VisibilityOff();
462 //************************************************************
463 // Presentation management
466 ChangeRepresentation (const SalomeApp_Module* theModule,
467 VISU::PresentationType theType)
469 SUIT_ViewWindow* aView = GetActiveView(theModule, SVTK_Viewer::Type());
471 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( aView );
475 Handle(SALOME_InteractiveObject) anIO;
476 CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
477 if (CORBA::is_nil(anObject)) return;
479 VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
480 if (CORBA::is_nil(aVisuObj)) return;
482 PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
483 if (!aServant.in()) return;
485 VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
487 if (VISU_Actor* anActor = GetActor(aPrs3d, vw)) {
490 if (anActor->IsShrunk())
493 anActor->SetShrink();
496 if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
497 aMesh->SetPresentationType(theType);
498 RecreateActor(theModule, aMesh);
500 anActor->SetRepresentation(theType);
509 SetShading ( const SalomeApp_Module* theModule,
512 SUIT_ViewWindow* aView = GetActiveView(theModule, SVTK_Viewer::Type());
514 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( aView );
518 Handle(SALOME_InteractiveObject) anIO;
519 CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
520 if (CORBA::is_nil(anObject)) return;
522 VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
523 if (CORBA::is_nil(aVisuObj)) return;
525 PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
526 if (!aServant.in()) return;
528 VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
530 if (VISU_Actor* anActor = GetActor(aPrs3d, vw)) {
531 if ( VISU_ScalarMapAct* aScalarMapActor = dynamic_cast<VISU_ScalarMapAct*>(anActor) )
532 aScalarMapActor->SetShading( theOn );
538 //************************************************************
542 CheckTimeStamp(const SalomeApp_Module* theModule,
543 _PTR(SObject)& theSObject,
544 Handle(SALOME_InteractiveObject)* theIO)
546 Handle(SALOME_InteractiveObject) anIO;
547 CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
550 if (!anIO.IsNull() && anIO->hasEntry()){
551 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
552 theSObject = aStudy->FindObjectID(anIO->getEntry());
553 QString aValue = getValue(theSObject,"myType");
554 if (aValue.toInt() == int(VISU::TTIMESTAMP))
557 SUIT_MessageBox::warn1(GetDesktop(theModule),
558 QObject::tr("WRN_VISU"),
559 QObject::tr("WRN_NO_AVAILABLE_DATA"),
560 QObject::tr("BUT_OK") );
565 CheckResult(const SalomeApp_Module* theModule,
566 _PTR(SObject) theSource,
567 VISU::Result_var& theResult)
569 _PTR(SObject) aSObj = theSource->GetFather();
573 aSObj = aSObj->GetFather();
577 aSObj = aSObj->GetFather();
581 CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
582 if (CORBA::is_nil(anObject)) {
583 aSObj = aSObj->GetFather();
586 anObject = VISU::ClientSObjectToObject(aSObj);
589 if (CORBA::is_nil(anObject))
592 theResult = VISU::Result::_narrow(anObject);
593 VISU::Result_i* pResult = dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
595 SUIT_MessageBox::warn1(GetDesktop(theModule),
596 QObject::tr("WRN_VISU"),
597 QObject::tr("WRN_NO_AVAILABLE_DATA"),
598 QObject::tr("BUT_OK"));
602 //************************************************************
605 SUIT_ViewWindow* GetActiveView(const SalomeApp_Module* theModule, QString theType)
607 if(SalomeApp_Application* anApp = theModule->getApp()){
608 if(SUIT_ViewManager* aViewManager = anApp->activeViewManager()){
609 if (!theType.isNull()) {
610 if (aViewManager->getType() != theType)
613 return aViewManager->getActiveView();
619 //************************************************************
623 GetViews(const SalomeApp_Module* theModule)
625 TViewWindows aViewWindows;
626 if(SalomeApp_Application* anApp = theModule->getApp()){
627 ViewManagerList aViewManagerList;
628 anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
629 QPtrListIterator<SUIT_ViewManager> anIter(aViewManagerList);
630 while(SUIT_ViewManager* aViewManager = anIter.current()){
631 QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
632 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
633 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
634 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
635 aViewWindows.push_back(aView);
644 GetViewWindow(const SalomeApp_Module* theModule, const bool theCreate )
646 if(SalomeApp_Application* anApp = theModule->getApp()){
647 if(SUIT_ViewManager* aViewManager = anApp->getViewManager( SVTK_Viewer::Type(), theCreate )){
648 if(SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()){
649 return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
660 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
661 (SUIT_Session::session()->activeApplication());
663 if (SUIT_ViewManager* aViewManager = anApp->activeViewManager()) {
664 if (aViewManager->getType() == SVTK_Viewer::Type()) {
665 if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
666 return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
675 PublishInView(const SalomeApp_Module* theModule,
676 VISU::Prs3d_i* thePrs)
678 VISU_Actor* aActor = NULL;
681 if(SVTK_ViewWindow* aView = GetViewWindow(theModule)){
682 QApplication::setOverrideCursor( Qt::waitCursor );
684 if(aActor = thePrs->CreateActor())
685 aView->AddActor(aActor);
686 }catch(std::exception& exc){
687 SUIT_MessageBox::warn1(GetDesktop(theModule),
688 QObject::tr("WRN_VISU"),
689 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()),
690 QObject::tr("BUT_OK"));
692 QApplication::restoreOverrideCursor();
698 UpdateViewer(const SalomeApp_Module* theModule,
699 VISU::Prs3d_i* thePrs,
702 SVTK_ViewWindow* vw = GetViewWindow( theModule );
703 if (!vw) return NULL;
705 vtkRenderer *aRen = vw->getRenderer();
706 vtkActorCollection *anActColl = aRen->GetActors();
709 VISU_Actor* anVISUActor = NULL;
710 VISU_Actor* aResActor = NULL;
711 for(anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ){
712 if(!SALOME_Actor::SafeDownCast(anActor))
714 if(anActor->IsA("VISU_Actor")){
715 anVISUActor = VISU_Actor::SafeDownCast(anActor);
716 VISU::Prs3d_i* aPrs = anVISUActor->GetPrs3d();
717 if(aPrs == NULL) continue;
718 if (thePrs == aPrs) {
719 aResActor = anVISUActor->GetParent();
721 thePrs->UpdateActor(aResActor);
722 aResActor->VisibilityOn();
723 } catch (std::runtime_error& ex) {
724 aResActor->VisibilityOff();
726 SUIT_MessageBox::warn1(GetDesktop(theModule), QObject::tr("WRN_VISU"),
727 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(ex.what()),
728 QObject::tr("BUT_OK"));
730 } else if (theDispOnly) {
731 anVISUActor->GetParent()->VisibilityOff();
734 } else if (theDispOnly && anActor->GetVisibility()) {
735 anActor->VisibilityOff();
742 //anVISUActor = PublishInView( theModule, thePrs );
747 RepaintViewWindows (const SalomeApp_Module* theModule,
748 const Handle(SALOME_InteractiveObject)& theIObject)
750 TViewWindows aViewWindows;
751 if (SalomeApp_Application* anApp = theModule->getApp()) {
752 ViewManagerList aViewManagerList;
753 anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
754 QPtrListIterator<SUIT_ViewManager> anIter (aViewManagerList);
755 while (SUIT_ViewManager* aViewManager = anIter.current()) {
756 QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
757 for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
758 if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
759 if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
760 if (vw->isVisible(theIObject)) {
761 vw->getRenderer()->ResetCameraClippingRange();
763 vw->highlight(theIObject, true, true);
774 FindActor(SVTK_ViewWindow* theViewWindow,
775 const char* theEntry)
778 if(vtkRenderer* aRenderer = theViewWindow->getRenderer()){
779 if(vtkActorCollection* aCollection = aRenderer->GetActors()){
780 if(VISU_Actor* anActor = Find<VISU_Actor>(aCollection,TIsSameEntry<VISU_Actor>(theEntry))){
781 return anActor->GetParent();
789 FindActor(SVTK_ViewWindow* theViewWindow,
790 VISU::Prs3d_i* thePrs)
792 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
793 CORBA::String_var anEntry = aSObject->GetID();
794 return FindActor(theViewWindow,anEntry.in());
798 RecreateActor (const SalomeApp_Module* theModule,
799 VISU::Prs3d_i* thePrs)
801 QApplication::setOverrideCursor(Qt::waitCursor);
802 bool isPublished = false;
804 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
805 CORBA::String_var anEntry = aSObject->GetID();
810 TViewWindows aViewWindows = GetViews(theModule);
811 for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
812 SVTK_ViewWindow* aView = aViewWindows[i];
813 if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
815 thePrs->UpdateActor(anActor);
818 } catch (std::runtime_error& ex) {
820 QApplication::restoreOverrideCursor();
821 SUIT_MessageBox::warn1 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
822 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(ex.what()),
823 QObject::tr("BUT_OK"));
825 TViewWindows aViewWindows = GetViews(theModule);
826 for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
827 SVTK_ViewWindow* aView = aViewWindows[i];
828 if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
829 aView->RemoveActor(anActor);
835 QApplication::restoreOverrideCursor();
838 PublishInView(theModule, thePrs);
841 static bool ComputeVisiblePropBounds(SVTK_ViewWindow* theViewWindow,
843 const char* theActorClassName = "VISU_Actor")
845 vtkRenderer *aRen = theViewWindow->getRenderer();
846 vtkActorCollection *anActColl = aRen->GetActors();
849 int somethingVisible = false;
851 allBounds[0] = allBounds[2] = allBounds[4] = VTK_LARGE_FLOAT;
852 allBounds[1] = allBounds[3] = allBounds[5] = -VTK_LARGE_FLOAT;
853 // loop through all props
854 for (anActColl->InitTraversal(); (prop = anActColl->GetNextProp()); ) {
855 // if it's invisible, or has no geometry, we can skip the rest
856 if (prop->GetVisibility() && prop->IsA(theActorClassName)) {
857 bounds = prop->GetBounds();
858 // make sure we haven't got bogus bounds
859 if (bounds != NULL &&
860 bounds[0] > -VTK_LARGE_FLOAT && bounds[1] < VTK_LARGE_FLOAT &&
861 bounds[2] > -VTK_LARGE_FLOAT && bounds[3] < VTK_LARGE_FLOAT &&
862 bounds[4] > -VTK_LARGE_FLOAT && bounds[5] < VTK_LARGE_FLOAT)
864 somethingVisible = true;
865 if (bounds[0] < allBounds[0]) allBounds[0] = bounds[0];
866 if (bounds[1] > allBounds[1]) allBounds[1] = bounds[1];
867 if (bounds[2] < allBounds[2]) allBounds[2] = bounds[2];
868 if (bounds[3] > allBounds[3]) allBounds[3] = bounds[3];
869 if (bounds[4] < allBounds[4]) allBounds[4] = bounds[4];
870 if (bounds[5] > allBounds[5]) allBounds[5] = bounds[5];
874 return somethingVisible;
877 void SetFitAll(SVTK_ViewWindow* theViewWindow)
879 static float PRECISION = 0.000001;
880 static float DEVIATION = 600;
882 if (!ComputeVisiblePropBounds(theViewWindow, XYZ_Bnd)) return;
884 float absX = XYZ_Bnd[1] - XYZ_Bnd[0];
885 float absY = XYZ_Bnd[3] - XYZ_Bnd[2];
886 float absZ = XYZ_Bnd[5] - XYZ_Bnd[4];
888 enum CameraOrient {e3D, eFront, eLeft, eTop};
889 CameraOrient aCameraOrient = e3D;
890 if (absX <= PRECISION) aCameraOrient = eFront;
892 if (absY <= PRECISION) aCameraOrient = eLeft;
894 if (absZ <= PRECISION) aCameraOrient = eTop;
896 // all the three dimensions exceeds precision
897 float dev_abs_XY = absX / absY;
898 float dev_abs_YZ = absY / absZ;
899 float dev_abs_XZ = absX / absZ;
900 if (dev_abs_XY >= DEVIATION || 1./dev_abs_YZ >= DEVIATION)
901 aCameraOrient = eLeft;
903 if (1./dev_abs_XY >= DEVIATION || 1./dev_abs_XZ >= DEVIATION)
904 aCameraOrient = eFront;
906 if (dev_abs_XZ >= DEVIATION || dev_abs_YZ >= DEVIATION)
907 aCameraOrient = eTop;
914 switch (aCameraOrient) {
915 case eFront: theViewWindow->onFrontView(); break;
916 case eLeft: theViewWindow->onLeftView(); break;
917 case eTop: theViewWindow->onTopView(); break;
918 case e3D: theViewWindow->onResetView(); break;
920 theViewWindow->getRenderer()->ResetCameraClippingRange();
921 theViewWindow->onFitAll();
924 //************************************************************
928 GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate)
930 if(SalomeApp_Application* anApp = theModule->getApp()){
931 if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){
932 return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
938 // Internal function used by several public functions below
940 UpdateCurve(VISU::Curve_i* theCurve,
941 Plot2d_ViewFrame* aPlot,
942 SPlot2d_Curve* plotCurve,
945 if ( theDisplaying == VISU::eErase ) {
947 aPlot->eraseCurve( plotCurve, false );
949 else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
951 plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() );
952 //plotCurve->setVerTitle( ( theCurve->GetVerTitle().c_str() ) );
953 plotCurve->setVerTitle( theCurve->GetName() );
954 plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() );
955 plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() );
958 int nbPoints = theCurve->GetData( xList, yList );
959 if ( nbPoints > 0 && xList && yList ) {
960 plotCurve->setData( xList, yList, nbPoints );
962 if ( !theCurve->IsAuto() ) {
963 plotCurve->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
964 plotCurve->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() );
965 SALOMEDS::Color color = theCurve->GetColor();
966 plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
968 plotCurve->setAutoAssign( theCurve->IsAuto() );
969 aPlot->displayCurve( plotCurve, false );
972 Plot2d_Curve* crv = theCurve->CreatePresentation();
974 aPlot->displayCurve( crv, false );
975 theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
976 theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
977 SALOMEDS::Color newColor;
978 newColor.R = crv->getColor().red()/255.;
979 newColor.G = crv->getColor().green()/255.;
980 newColor.B = crv->getColor().blue()/255.;
981 theCurve->SetColor( newColor );
982 crv->setAutoAssign( theCurve->IsAuto() );
989 PlotTable(const SalomeApp_Module* theModule,
990 VISU::Table_i* table,
993 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
996 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1000 if ( theDisplaying == VISU::eDisplayOnly )
1002 QList<Plot2d_Curve> clist;
1003 aPlot->getCurves( clist );
1004 _PTR(Study) aStudy = GetCStudy( GetAppStudy( theModule ) );
1005 _PTR(SObject) TableSO = aStudy->FindObjectID( table->GetEntry().latin1() );
1007 _PTR(ChildIterator) Iter = aStudy->NewChildIterator( TableSO );
1008 for ( ; Iter->More(); Iter->Next() ) {
1009 CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
1010 if( !CORBA::is_nil( childObject ) ) {
1011 CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
1012 if( !CORBA::is_nil( aCurve ) ) {
1013 VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
1014 SPlot2d_Curve* plotCurve = 0;
1015 SPlot2d_Curve* tmpCurve;
1016 for ( int i = 0; i < clist.count(); i++ ) {
1017 tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
1018 if (tmpCurve && tmpCurve->hasIO() &&
1019 !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
1020 plotCurve = tmpCurve;
1025 UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
1027 if ( theDisplaying == VISU::eErase && plotCurve ) {
1028 clist.remove( plotCurve );
1038 PlotCurve(const SalomeApp_Module* theModule,
1039 VISU::Curve_i* theCurve,
1042 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1045 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1049 // if ( theDisplaying == VISU::eDisplayOnly )
1050 // aPlot->EraseAll();
1051 QList<Plot2d_Curve> clist;
1052 aPlot->getCurves( clist );
1053 SPlot2d_Curve* plotCurve = 0;
1054 SPlot2d_Curve* tmpCurve;
1055 for (int i = 0; i < clist.count(); i++) {
1056 tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
1057 if (tmpCurve && tmpCurve->hasIO() &&
1058 !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
1059 plotCurve = tmpCurve;
1060 } else if (theDisplaying == VISU::eDisplayOnly) {
1061 aPlot->eraseCurve(clist.at(i));
1065 UpdateCurve(theCurve, aPlot, plotCurve, theDisplaying);
1071 PlotContainer(const SalomeApp_Module* theModule,
1072 VISU::Container_i* container,
1075 SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1078 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1082 if ( theDisplaying == VISU::eDisplayOnly )
1084 QList<Plot2d_Curve> clist;
1085 aPlot->getCurves( clist );
1086 if ( container->GetNbCurves() > 0 ) {
1087 int nbCurves = container->GetNbCurves();
1088 for ( int k = 1; k <= nbCurves; k++ ) {
1089 VISU::Curve_i* theCurve = container->GetCurve( k );
1090 if ( theCurve && theCurve->IsValid() ) {
1091 SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>
1092 (aView->getCurveByIO(new SALOME_InteractiveObject (theCurve->GetEntry(), "", "")));
1094 UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
1096 if ( plotCurve && theDisplaying == VISU::eErase ) {
1097 clist.remove( plotCurve );
1106 CreatePlot(SalomeApp_Module* theModule,
1107 _PTR(SObject) theTableSO)
1109 if ( IsSObjectTable(theTableSO) ) {
1110 CORBA::Object_var aTable = VISU::ClientSObjectToObject(theTableSO);
1111 CORBA::Object_var aContainer = GetVisuGen( theModule )->CreateContainer();
1112 if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) {
1113 VISU::Table_i* pTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
1114 VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aContainer).in());
1116 if ( pContainer && pTable ) {
1117 for ( int i = 2; i <= pTable->GetNbRows(); i++ ) {
1118 CORBA::Object_var aNewCurve = GetVisuGen( theModule )->CreateCurve( pTable->_this(), 1, i );
1119 if( !CORBA::is_nil( aNewCurve ) ) {
1120 VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aNewCurve).in() );
1122 pContainer->AddCurve( pCrv->_this() );
1126 PlotContainer( theModule, pContainer, VISU::eDisplay );
1132 //************************************************************
1135 void CreateMesh (const SalomeApp_Module* theModule,
1136 const Handle(SALOME_InteractiveObject)& theIO)
1138 _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
1139 //if (CheckLock(aStudy))
1142 _PTR(SObject) aResultSObj = aStudy->FindObjectID(theIO->getEntry());
1145 VISU::Result_var aResult;
1146 VISU::Result_i* pResult = CheckResult(theModule, aResultSObj, aResult);
1147 if (pResult == NULL)
1150 Storable::TRestoringMap aMap = getMapOfValue(aResultSObj);
1152 string aComment = Storable::FindValue(aMap,"myComment",&isExist).latin1();
1156 CORBA::Object_var aMesh;
1157 string aMeshName = Storable::FindValue(aMap,"myMeshName").latin1();
1162 if (aComment == "ENTITY") {
1163 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myId").toInt();
1164 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity))
1165 aMesh = GetVisuGen(theModule)->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
1166 } else if (aComment == "FAMILY") {
1167 VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myEntityId").toInt();
1168 string aFamilyName = Storable::FindValue(aMap,"myName").latin1();
1169 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()))
1170 aMesh = GetVisuGen(theModule)->FamilyMeshOnEntity
1171 (aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
1172 } else if (aComment == "GROUP") {
1173 string aGroupName = Storable::FindValue(aMap,"myName").latin1();
1174 if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str()))
1175 aMesh = GetVisuGen(theModule)->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
1179 MESSAGE("VisuGUI::CreateMesh() - CREATE MESH");
1183 QApplication::restoreOverrideCursor();
1184 VISU::Mesh_i* pPresent = NULL;
1185 if (!CORBA::is_nil(aMesh))
1186 pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
1187 if (pPresent == NULL) {
1188 SUIT_MessageBox::warn1 (GetDesktop(theModule),
1189 QObject::tr("WRN_VISU"),
1190 QObject::tr("ERR_CANT_BUILD_PRESENTATION"),
1191 QObject::tr("BUT_OK"));
1195 if (SVTK_ViewWindow* aView = GetViewWindow(theModule)) {
1201 PublishInView(theModule, pPresent);
1202 //aView->onFitAll();
1206 MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
1209 theModule->application()->putInfo(QObject::tr("INF_DONE"));
1210 // Make "Save" button active
1211 theModule->getApp()->updateActions();
1212 } catch (std::runtime_error& exc) {
1214 SUIT_MessageBox::warn1 (GetDesktop(theModule),
1215 QObject::tr("WRN_VISU"),
1216 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()),
1217 QObject::tr("BUT_OK"));
1222 // ========================================================================================
1223 // GetPrs3dList: find list of presentations for the given object
1224 // ========================================================================================
1225 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1226 const Handle(SALOME_InteractiveObject)& theIO)
1228 std::vector<VISU::Prs3d_i*> aList;
1229 if (!theIO.IsNull() && theIO->hasEntry()) {
1230 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1231 _PTR(SObject) aSObject = aCStudy->FindObjectID(theIO->getEntry());
1232 aList = GetPrs3dList(theModule, aSObject);
1237 std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1238 _PTR(SObject) theObject)
1240 std::vector<VISU::Prs3d_i*> aList; int k = 0;
1244 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1246 CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(theObject);
1247 if (!CORBA::is_nil(aCORBAObject)) {
1248 VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
1249 if (!CORBA::is_nil(aVisuObj)) {
1250 VISU::VISUType aType = aVisuObj->GetType();
1252 case VISU::TSCALARMAP:
1253 case VISU::TISOSURFACE:
1254 case VISU::TDEFORMEDSHAPE:
1255 case VISU::TCUTPLANES:
1256 case VISU::TCUTLINES:
1257 case VISU::TVECTORS:
1258 case VISU::TSTREAMLINES:
1261 PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1262 if (aServant.in()) {
1263 VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
1265 aList[k] = aPrsObject;
1272 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1273 _PTR(SObject) aTimeStamp;
1274 anIter->Next(); // First is reference on support
1275 for (; anIter->More(); anIter->Next()) {
1276 aTimeStamp = anIter->Value();
1277 if (!aTimeStamp) continue;
1278 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1279 if (!aSubList.empty()) {
1280 int n = aSubList.size();
1282 for (int i = 0; i < n; i++) {
1283 aList[k] = aSubList[i];
1293 _PTR(GenericAttribute) anAttr;
1294 if (theObject->FindAttribute(anAttr, "AttributeComment")) {
1295 _PTR(AttributeComment) aComment (anAttr);
1296 string aComm = aComment->Value();
1297 QString strIn (aComm.c_str());
1298 VISU::Storable::TRestoringMap pMap;
1299 VISU::Storable::StrToMap(strIn, pMap);
1301 VISU::VISUType aType =
1302 (VISU::VISUType)VISU::Storable::FindValue(pMap,"myType",&isExist).toInt();
1307 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1308 _PTR(SObject) aTimeStamp;
1309 anIter->Next(); // First is reference on support
1310 for (; anIter->More(); anIter->Next()) {
1311 aTimeStamp = anIter->Value();
1312 if (!aTimeStamp) continue;
1313 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1314 if (!aSubList.empty()) {
1315 int n = aSubList.size();
1317 for (int i = 0; i < n; i++) {
1318 aList[k] = aSubList[i];
1325 case VISU::TTIMESTAMP:
1327 _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1329 for (; anIter->More(); anIter->Next()) {
1330 aPrs = anIter->Value();
1331 if (!aPrs) continue;
1332 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
1333 if (!aSubList.empty()) {
1334 int n = aSubList.size();
1336 for (int i = 0; i < n; i++) {
1337 aList[k] = aSubList[i];