1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // VISU VISUGUI : GUI of VISU component
24 // File : VisuGUI_Tools.cxx
25 // Author : Sergey Anikin
28 #include "VisuGUI_ViewTools.h"
30 #include "VISU_Actor.h"
32 #include "SVTK_ViewModel.h"
33 #include "SVTK_ViewWindow.h"
35 #include <VISU_Tools.h>
37 #include <SUIT_Desktop.h>
39 #include <SalomeApp_Study.h>
43 //----------------------------------------------------------------------------
45 PublishInView(VisuGUI* theModule,
47 SVTK_ViewWindow* theViewWindow,
51 QApplication::setOverrideCursor( Qt::WaitCursor );
53 if (VISU_Actor* anActor = thePrs->CreateActor()) {
54 theViewWindow->AddActor(anActor);
56 theViewWindow->highlight(anActor->getIO(),true);
57 theViewWindow->getRenderer()->ResetCameraClippingRange();
58 theViewWindow->Repaint();
59 QApplication::restoreOverrideCursor();
61 if(!thePrs->GetEntry().empty())
62 VISU::SetVisibilityState(thePrs->GetEntry(), Qtx::ShownState);
64 VISU::ColoredPrs3d_i* prs = dynamic_cast<VISU::ColoredPrs3d_i*>(thePrs);
65 if(prs && !prs->GetHolderEntry().empty()) {
66 VISU::SetVisibilityState(prs->GetHolderEntry(), Qtx::ShownState);
71 } catch(std::exception& exc) {
72 thePrs->RemoveActors();
74 QApplication::restoreOverrideCursor();
76 SUIT_MessageBox::warning
77 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
78 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()));
85 //---------------------------------------------------------------
87 UpdateViewer(VisuGUI* theModule,
88 VISU::Prs3d_i* thePrs,
90 const bool theIsHighlight)
92 if (SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule)) {
93 vtkRenderer *aRen = aViewWindow->getRenderer();
94 VTK::ActorCollectionCopy aCopy(aRen->GetActors());
95 vtkActorCollection *anActColl = aCopy.GetActors();
96 anActColl->InitTraversal();
97 VISU_Actor* aResActor = NULL;
99 while (vtkActor *anAct = anActColl->GetNextActor()) {
100 if (VISU_Actor* anActor = dynamic_cast<VISU_Actor*>(anAct)) {
101 if (VISU::Prs3d_i* aPrs3d = anActor->GetPrs3d()) {
102 if (thePrs == aPrs3d) {
105 thePrs->UpdateActors();
106 aResActor->VisibilityOn();
107 } catch (std::runtime_error& exc) {
108 thePrs->RemoveActors();
112 SUIT_MessageBox::warning
113 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
114 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()) );
116 } else if (theDispOnly) {
117 anActor->VisibilityOff();
119 } else if (theDispOnly && anActor->GetVisibility()) {
120 anActor->VisibilityOff();
125 if (theIsHighlight && isOk)
126 aViewWindow->highlight(aResActor->getIO(), true);
127 aViewWindow->getRenderer()->ResetCameraClippingRange();
128 aViewWindow->Repaint();
131 return PublishInView(theModule, thePrs, aViewWindow, theIsHighlight);
137 //---------------------------------------------------------------
139 ErasePrs3d(VisuGUI* theModule,
140 VISU::Prs3d_i* thePrs,
143 if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule)){
144 if(VISU_Actor* anActor = FindActor(aViewWindow, thePrs)){
145 anActor->VisibilityOff();
147 aViewWindow->Repaint();
152 //----------------------------------------------------------------------------
154 ErasePrs(VisuGUI* theModule,
161 bool updateState = true;
163 switch (theBase->GetType()) {
165 if (VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(theBase)) {
166 PlotCurve(theModule, aCurve, VISU::eErase );
171 case VISU::TCONTAINER: {
172 if (VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(theBase)) {
173 PlotContainer(theModule, aContainer, VISU::eErase );
179 if (VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(theBase)) {
180 PlotTable(theModule, aTable, VISU::eErase );
185 case VISU::TPOINTMAP3D: {
186 if (VISU::PointMap3d_i* aTable3d = dynamic_cast<VISU::PointMap3d_i*>(theBase)) {
187 if (SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule)) {
188 if(VISU_ActorBase* anActor = FindActorBase(aViewWindow, aTable3d)){
189 anActor->VisibilityOff();
191 aViewWindow->Repaint();
194 if (VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(theBase)) {
195 PlotTable(theModule, aTable, VISU::eErase );
203 if(VISU::Prs3d_i* aPrs3d = VISU::GetPrs3dFromBase(theBase)){
204 if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule)){
205 RemoveScalarBarPosition(theModule, aViewWindow, aPrs3d);
206 ErasePrs3d(theModule, aPrs3d, theDoRepaint);
211 /* Update visibility state */
213 if( RemovableObject_i* obj = dynamic_cast<RemovableObject_i*>(theBase)) {
214 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(theModule->application());
216 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
217 std::string entry = obj->GetEntry();
218 if(aStudy && !entry.empty())
219 aStudy->setVisibilityState(QString(entry.c_str()), Qtx::HiddenState);