Salome HOME
sources v1.2c
[modules/visu.git] / src / OBJECT / VISU_MeshAct.cxx
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : VISU_MeshAct.cxx
25 //  Author : Laurent CORNABE with the help of Nicolas REJNERI
26 //  Module : VISU
27 //  $Header$
28
29 #include "VISU_MeshAct.h"
30 #include "SALOME_PassThroughFilter.h"
31
32 #include <vtkFeatureEdges.h>
33 #include <vtkDataSetMapper.h>
34 #include <vtkDataSet.h>
35
36 vtkStandardNewMacro(VISU_MeshAct);
37
38 VISU_MeshAct::VISU_MeshAct(){
39   mySurfaceActor = VISU_Actor::New();
40   mySurfaceActor->SetParent(this);
41   mySurfaceActor->GetProperty()->FrontfaceCullingOff();
42   mySurfaceActor->GetProperty()->BackfaceCullingOff();
43   mySurfaceActor->SetRepresentation(2); //SURFACE
44  
45   myEdgeActor = VISU_Actor::New();
46   myEdgeActor->SetParent(this);
47   myEdgeActor->PickableOff();
48   myEdgeActor->GetProperty()->FrontfaceCullingOff();
49   myEdgeActor->GetProperty()->BackfaceCullingOff();
50   myEdgeActor->SetRepresentation(1); //WIREFRAME
51  
52   myNodeActor = VISU_Actor::New();
53   myNodeActor->SetParent(this);
54   myNodeActor->PickableOff();
55   myNodeActor->GetProperty()->SetPointSize(SALOME_POINT_SIZE);
56   myNodeActor->GetProperty()->FrontfaceCullingOff();
57   myNodeActor->GetProperty()->BackfaceCullingOff();
58   myNodeActor->SetRepresentation(0); //POINT
59
60   SetRepresentation(2); //SURFACE
61 }
62
63 VISU_MeshAct::~VISU_MeshAct(){
64   mySurfaceActor->Delete();
65   myEdgeActor->Delete();
66   myNodeActor->Delete();
67 }
68
69 void VISU_MeshAct::setIO(const Handle(SALOME_InteractiveObject)& theIO){
70   mySurfaceActor->setIO(theIO);
71   myEdgeActor->setIO(theIO);
72   myNodeActor->setIO(theIO);
73 }
74
75 void VISU_MeshAct::SetPrs3d(VISU::Prs3d_i* thePrs3d){ 
76   if(thePrs3d){
77     VISU_Actor::SetPrs3d(thePrs3d);
78     mySurfaceActor->SetPrs3d(thePrs3d);
79     myEdgeActor->SetPrs3d(thePrs3d);
80     myNodeActor->SetPrs3d(thePrs3d);
81   }
82 }
83
84 void VISU_MeshAct::AddToRender(vtkRenderer* theRenderer){
85   theRenderer->AddActor(mySurfaceActor);
86   theRenderer->AddActor(myEdgeActor);
87   theRenderer->AddActor(myNodeActor);
88 }
89
90 void VISU_MeshAct::RemoveFromRender(vtkRenderer* theRenderer){
91   theRenderer->RemoveActor(mySurfaceActor);
92   theRenderer->RemoveActor(myEdgeActor);
93   theRenderer->RemoveActor(myNodeActor);
94 }
95
96 void VISU_MeshAct::SetPipeLine(VISU_PipeLine* thePipeLine) throw(std::runtime_error&){
97   VISU_Actor::SetPipeLine(thePipeLine);
98   mySurfaceActor->SetPipeLine(thePipeLine);
99   myEdgeActor->SetPipeLine(thePipeLine);
100   myNodeActor->SetPipeLine(thePipeLine);
101 }
102
103 void VISU_MeshAct::SetTransform(SALOME_Transform* theTransform){
104   mySurfaceActor->SetTransform(theTransform);
105   myEdgeActor->SetTransform(theTransform);
106   myNodeActor->SetTransform(theTransform);
107 }
108
109 void VISU_MeshAct::SetShrinkable(bool theIsShrinkable){
110   VISU_Actor::SetShrinkable(theIsShrinkable);
111   mySurfaceActor->SetShrinkable(theIsShrinkable);
112   myEdgeActor->SetShrinkable(theIsShrinkable);
113   myNodeActor->SetShrinkable(theIsShrinkable);
114 }
115
116 vtkProperty* VISU_MeshAct::GetProperty(){ 
117   mySurfaceActor->GetProperty();
118
119
120 void VISU_MeshAct::SetProperty(vtkProperty* theProperty){ 
121   mySurfaceActor->SetProperty(theProperty);
122 }
123
124 vtkProperty* VISU_MeshAct::GetEdgeProperty(){ 
125   myEdgeActor->GetProperty();
126
127
128 void VISU_MeshAct::SetEdgeProperty(vtkProperty* theProperty){ 
129   myEdgeActor->SetProperty(theProperty);
130 }
131
132 vtkProperty* VISU_MeshAct::GetNodeProperty(){ 
133   myNodeActor->GetProperty();
134
135
136 void VISU_MeshAct::SetNodeProperty(vtkProperty* theProperty){ 
137   myNodeActor->SetProperty(theProperty);
138 }
139
140 void VISU_MeshAct::SetLineWidth(float theLineWidth){
141   GetEdgeProperty()->SetLineWidth(theLineWidth);
142 }
143
144 float VISU_MeshAct::GetLineWidth(){
145   return GetEdgeProperty()->GetLineWidth();
146 }
147
148 void VISU_MeshAct::SetShrink(float theFactor){
149   VISU_Actor::SetShrink(theFactor);
150   mySurfaceActor->SetShrink(theFactor);
151   myEdgeActor->SetShrink(theFactor);
152   SetRepresentation(GetRepresentation());
153 }
154
155 void VISU_MeshAct::UnShrink(){
156   VISU_Actor::UnShrink();
157   mySurfaceActor->UnShrink();
158   myEdgeActor->UnShrink();
159   SetRepresentation(GetRepresentation());
160 }
161
162 void VISU_MeshAct::SetRepresentation(int theMode){
163   SALOME_Actor::SetRepresentation(theMode);
164   mySurfaceActor->VisibilityOff();
165   myEdgeActor->VisibilityOff();
166   myNodeActor->VisibilityOff();
167   switch(theMode){
168   case 0: //POINTS
169     myNodeActor->VisibilityOn();
170     break;
171   case 1: //WIREFRAME
172     myEdgeActor->VisibilityOn();
173     myEdgeActor->SetRepresentation(1);
174     break;
175   case 2: //SURFACE
176     mySurfaceActor->VisibilityOn();
177     break;
178   case 3: //INSIDEFRAME
179     myEdgeActor->VisibilityOn();
180     myEdgeActor->SetRepresentation(3);
181     break;
182   case 4: //SURFACEFRAME
183     myEdgeActor->VisibilityOn();
184     myEdgeActor->SetRepresentation(1);
185     mySurfaceActor->VisibilityOn();
186     break;
187   }
188 }
189
190 void VISU_MeshAct::SetVisibility(int theMode){
191   VISU_Actor::SetVisibility(theMode);
192   if(GetVisibility())
193     SetRepresentation(GetRepresentation());
194   else{
195     myNodeActor->VisibilityOff();
196     myEdgeActor->VisibilityOff();
197     mySurfaceActor->VisibilityOff();
198   }
199 }