]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_ViewTools.cxx
Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/visu.git] / src / VISUGUI / VisuGUI_ViewTools.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  VISU VISUGUI : GUI of VISU component
23 //  File   : VisuGUI_Tools.cxx
24 //  Author : Sergey Anikin
25 //  Module : VISU
26 //
27 #include "VisuGUI_ViewTools.h"
28
29 #include "VISU_Actor.h"
30
31 #include "SVTK_ViewModel.h"
32 #include "SVTK_ViewWindow.h"
33
34 #include <SUIT_Desktop.h>
35
36 namespace VISU 
37 {
38   //----------------------------------------------------------------------------
39   VISU_Actor*
40   PublishInView(VisuGUI* theModule,
41                 Prs3d_i* thePrs,
42                 SVTK_ViewWindow* theViewWindow,
43                 bool theIsHighlight)
44   {
45     if (theViewWindow) {
46       QApplication::setOverrideCursor( Qt::WaitCursor );
47       try {
48         if (VISU_Actor* anActor = thePrs->CreateActor()) {
49           theViewWindow->AddActor(anActor);
50           if (theIsHighlight)
51             theViewWindow->highlight(anActor->getIO(),true);
52           theViewWindow->getRenderer()->ResetCameraClippingRange();
53           theViewWindow->Repaint();
54           QApplication::restoreOverrideCursor();
55           return anActor;
56         }
57       } catch(std::exception& exc) {
58         thePrs->RemoveActors();
59
60         QApplication::restoreOverrideCursor();
61         INFOS(exc.what());
62         SUIT_MessageBox::warning
63           (GetDesktop(theModule), QObject::tr("WRN_VISU"),
64            QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()));
65       }
66     }
67     return NULL;
68   }
69
70
71   //---------------------------------------------------------------
72   VISU_Actor*
73   UpdateViewer(VisuGUI* theModule,
74                VISU::Prs3d_i* thePrs,
75                bool theDispOnly,
76                const bool theIsHighlight)
77   {
78     if (SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule)) {
79       vtkRenderer *aRen = aViewWindow->getRenderer();
80       vtkActorCollection *anActColl = aRen->GetActors();
81       anActColl->InitTraversal();
82       VISU_Actor* aResActor = NULL;
83       bool isOk = true;
84       while (vtkActor *anAct = anActColl->GetNextActor()) {
85         if (VISU_Actor* anActor = dynamic_cast<VISU_Actor*>(anAct)) {
86           if (VISU::Prs3d_i* aPrs3d = anActor->GetPrs3d()) {
87             if (thePrs == aPrs3d) {
88               try {
89                 aResActor = anActor;
90                 thePrs->UpdateActors();
91                 aResActor->VisibilityOn();
92               } catch (std::runtime_error& exc) {
93                 thePrs->RemoveActors();
94                 isOk = false;
95
96                 INFOS(exc.what());
97                 SUIT_MessageBox::warning
98                   (GetDesktop(theModule), QObject::tr("WRN_VISU"),
99                    QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()) );
100               }
101             } else if (theDispOnly) {
102               anActor->VisibilityOff();
103             }
104           } else if (theDispOnly && anActor->GetVisibility()) {
105             anActor->VisibilityOff();
106           }
107         }
108       }
109       if (aResActor) {
110         if (theIsHighlight && isOk)
111           aViewWindow->highlight(aResActor->getIO(), true);
112         aViewWindow->getRenderer()->ResetCameraClippingRange();
113         aViewWindow->Repaint();
114         return aResActor;
115       }
116       return PublishInView(theModule, thePrs, aViewWindow, theIsHighlight);
117     }
118     return NULL;
119   }
120
121
122   //---------------------------------------------------------------
123   void
124   ErasePrs3d(VisuGUI* theModule,
125              VISU::Prs3d_i* thePrs,
126              bool theDoRepaint)
127   {
128     if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule)){
129       if(VISU_Actor* anActor = FindActor(aViewWindow, thePrs)){
130         anActor->VisibilityOff();
131         if(theDoRepaint)
132           aViewWindow->Repaint();
133       }
134     }
135   }
136
137   //----------------------------------------------------------------------------
138   void
139   ErasePrs(VisuGUI* theModule,
140            Base_i* theBase, 
141            bool theDoRepaint)
142   {
143     if(!theBase)
144       return;
145
146     switch (theBase->GetType()) {
147     case VISU::TCURVE: {
148       if (VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(theBase))
149         PlotCurve(theModule, aCurve, VISU::eErase );
150       break;
151     }
152     case VISU::TCONTAINER: {
153       if (VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(theBase))
154         PlotContainer(theModule, aContainer, VISU::eErase );
155       break;
156     }
157     case VISU::TTABLE: {
158       if (VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(theBase))
159         PlotTable(theModule, aTable, VISU::eErase );
160       break;
161     }
162     case VISU::TPOINTMAP3D: {
163       if (VISU::PointMap3d_i* aTable3d = dynamic_cast<VISU::PointMap3d_i*>(theBase)) {
164         if (SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule)) {
165           if(VISU_ActorBase* anActor = FindActorBase(aViewWindow, aTable3d)){
166             anActor->VisibilityOff();
167             if(theDoRepaint)
168             aViewWindow->Repaint();
169           }
170         } else {
171           if (VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(theBase))
172             PlotTable(theModule, aTable, VISU::eErase );
173         }
174       }
175       break;
176     }
177     default: {
178       if(VISU::Prs3d_i* aPrs3d = VISU::GetPrs3dFromBase(theBase)){
179         if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule)){
180           RemoveScalarBarPosition(theModule, aViewWindow, aPrs3d);
181           ErasePrs3d(theModule, aPrs3d, theDoRepaint);
182         }
183       }
184     }} // switch (aType)
185   }
186
187 }