1 // Copyright (C) 2007-2008 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
22 // VISU VISUGUI : GUI of VISU component
23 // File : VisuGUI_Tools.cxx
24 // Author : Sergey Anikin
27 #include "VisuGUI_ViewTools.h"
29 #include "VISU_Actor.h"
31 #include "SVTK_ViewModel.h"
32 #include "SVTK_ViewWindow.h"
34 #include <SUIT_Desktop.h>
38 //----------------------------------------------------------------------------
40 PublishInView(VisuGUI* theModule,
42 SVTK_ViewWindow* theViewWindow,
46 QApplication::setOverrideCursor( Qt::WaitCursor );
48 if (VISU_Actor* anActor = thePrs->CreateActor()) {
49 theViewWindow->AddActor(anActor);
51 theViewWindow->highlight(anActor->getIO(),true);
52 theViewWindow->getRenderer()->ResetCameraClippingRange();
53 theViewWindow->Repaint();
54 QApplication::restoreOverrideCursor();
57 } catch(std::exception& exc) {
58 thePrs->RemoveActors();
60 QApplication::restoreOverrideCursor();
62 SUIT_MessageBox::warning
63 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
64 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()));
71 //---------------------------------------------------------------
73 UpdateViewer(VisuGUI* theModule,
74 VISU::Prs3d_i* thePrs,
76 const bool theIsHighlight)
78 if (SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule)) {
79 vtkRenderer *aRen = aViewWindow->getRenderer();
80 VTK::ActorCollectionCopy aCopy(aRen->GetActors());
81 vtkActorCollection *anActColl = aCopy.GetActors();
82 anActColl->InitTraversal();
83 VISU_Actor* aResActor = NULL;
85 while (vtkActor *anAct = anActColl->GetNextActor()) {
86 if (VISU_Actor* anActor = dynamic_cast<VISU_Actor*>(anAct)) {
87 if (VISU::Prs3d_i* aPrs3d = anActor->GetPrs3d()) {
88 if (thePrs == aPrs3d) {
91 thePrs->UpdateActors();
92 aResActor->VisibilityOn();
93 } catch (std::runtime_error& exc) {
94 thePrs->RemoveActors();
98 SUIT_MessageBox::warning
99 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
100 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()) );
102 } else if (theDispOnly) {
103 anActor->VisibilityOff();
105 } else if (theDispOnly && anActor->GetVisibility()) {
106 anActor->VisibilityOff();
111 if (theIsHighlight && isOk)
112 aViewWindow->highlight(aResActor->getIO(), true);
113 aViewWindow->getRenderer()->ResetCameraClippingRange();
114 aViewWindow->Repaint();
117 return PublishInView(theModule, thePrs, aViewWindow, theIsHighlight);
123 //---------------------------------------------------------------
125 ErasePrs3d(VisuGUI* theModule,
126 VISU::Prs3d_i* thePrs,
129 if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule)){
130 if(VISU_Actor* anActor = FindActor(aViewWindow, thePrs)){
131 anActor->VisibilityOff();
133 aViewWindow->Repaint();
138 //----------------------------------------------------------------------------
140 ErasePrs(VisuGUI* theModule,
147 switch (theBase->GetType()) {
149 if (VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(theBase))
150 PlotCurve(theModule, aCurve, VISU::eErase );
153 case VISU::TCONTAINER: {
154 if (VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(theBase))
155 PlotContainer(theModule, aContainer, VISU::eErase );
159 if (VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(theBase))
160 PlotTable(theModule, aTable, VISU::eErase );
163 case VISU::TPOINTMAP3D: {
164 if (VISU::PointMap3d_i* aTable3d = dynamic_cast<VISU::PointMap3d_i*>(theBase)) {
165 if (SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule)) {
166 if(VISU_ActorBase* anActor = FindActorBase(aViewWindow, aTable3d)){
167 anActor->VisibilityOff();
169 aViewWindow->Repaint();
172 if (VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(theBase))
173 PlotTable(theModule, aTable, VISU::eErase );
179 if(VISU::Prs3d_i* aPrs3d = VISU::GetPrs3dFromBase(theBase)){
180 if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule)){
181 RemoveScalarBarPosition(theModule, aViewWindow, aPrs3d);
182 ErasePrs3d(theModule, aPrs3d, theDoRepaint);