1 // Copyright (C) 2007-2010 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 // GEOM OBJECT : interactive object for Geometry entities visualization
24 // File : GEOM_AssemblyBuilder.cxx
25 // Author : Christophe ATTANASIO
30 \class GEOM_AssemblyBuilder GEOM_AssemblyBuilder.h
34 #include "GEOM_AssemblyBuilder.h"
35 #include "GEOM_Actor.h"
37 #include <OCC2VTK_Tools.h>
39 #include <SUIT_Session.h>
40 #include <SUIT_ResourceMgr.h>
42 #include <vtkProperty.h>
43 #include <vtkAssembly.h>
44 #include <vtkActorCollection.h>
46 // Open CASCADE Includes
47 #include <TopExp_Explorer.hxx>
48 #include <BRep_Tool.hxx>
49 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
51 #include <TopoDS_Iterator.hxx>
56 #include "utilities.h"
58 void GEOM_AssemblyBuilder::InitProperties(vtkProperty* IsoProp,
59 vtkProperty* FaceProp,
60 vtkProperty* EdgeFProp,
61 vtkProperty* EdgeSProp,
62 vtkProperty* EdgeIProp,
63 vtkProperty* VertexProp,
64 vtkProperty* IsoPVProp,
65 vtkProperty* EdgePVProp,
66 vtkProperty* VertexPVProp)
68 // Shading like default OCC material
69 FaceProp->SetRepresentationToSurface();
70 FaceProp->SetInterpolationToGouraud();
71 FaceProp->SetAmbient(1.0);
72 FaceProp->SetDiffuse(1.0);
73 FaceProp->SetSpecular(0.4);
74 FaceProp->SetAmbientColor(0.329412, 0.223529, 0.027451);
75 FaceProp->SetDiffuseColor(0.780392, 0.568627, 0.113725);
76 FaceProp->SetSpecularColor(0.992157, 0.941176, 0.807843);
78 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
82 aColor = aResMgr->colorValue( "Geometry", "isos_color", QColor( int(0.5*255), int(0.5*255), int(0.5*255) ) );
83 float red = aColor.red()/255.0;
84 float green = aColor.green()/255.0;
85 float blue = aColor.blue()/255.0;
86 IsoProp->SetRepresentationToWireframe();
87 IsoProp->SetAmbientColor(red, green, blue);
88 IsoProp->SetDiffuseColor(red, green, blue);
89 IsoProp->SetSpecularColor(red, green, blue);
92 IsoPVProp->SetRepresentationToWireframe();
93 IsoPVProp->SetAmbientColor(0, 1, 1);
94 IsoPVProp->SetDiffuseColor(0, 1, 1);
95 IsoPVProp->SetSpecularColor(0, 1, 1);
97 // Wireframe for shared edge
98 aColor = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
99 red = aColor.red()/255.0;
100 green = aColor.green()/255.0;
101 blue = aColor.blue()/255.0;
102 EdgeSProp->SetRepresentationToWireframe();
103 EdgeSProp->SetAmbientColor(red, green, blue);
104 EdgeSProp->SetDiffuseColor(red, green, blue);
105 EdgeSProp->SetSpecularColor(red, green, blue);
107 // Wireframe for free edge
108 aColor = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
109 red = aColor.red()/255.0;
110 green = aColor.green()/255.0;
111 blue = aColor.blue()/255.0;
112 EdgeFProp->SetRepresentationToWireframe();
113 EdgeFProp->SetAmbientColor(red, green, blue);
114 EdgeFProp->SetDiffuseColor(red, green, blue);
115 EdgeFProp->SetSpecularColor(red, green, blue);
117 // Wireframe for isolated edge
118 aColor = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
119 red = aColor.red()/255.0;
120 green = aColor.green()/255.0;
121 blue = aColor.blue()/255.0;
122 EdgeIProp->SetRepresentationToWireframe();
123 EdgeIProp->SetAmbientColor(red, green, blue);
124 EdgeIProp->SetDiffuseColor(red, green, blue);
126 // Wireframe for Preview edge
127 EdgePVProp->SetRepresentationToWireframe();
128 EdgePVProp->SetAmbientColor(1, 1, 0);
129 EdgePVProp->SetDiffuseColor(1, 1, 0);
130 EdgePVProp->SetSpecularColor(1, 1, 0);
132 // Wireframe for vertex
133 aColor = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
134 red = aColor.red()/255.0;
135 green = aColor.green()/255.0;
136 blue = aColor.blue()/255.0;
137 VertexProp->SetRepresentationToWireframe();
138 VertexProp->SetAmbientColor(red, green, blue);
139 VertexProp->SetDiffuseColor(red, green, blue);
140 VertexProp->SetSpecularColor(red, green, blue);
142 // Wireframe for vertex
143 VertexPVProp->SetRepresentationToWireframe();
144 VertexPVProp->SetAmbientColor(0, 1, 1);
145 VertexPVProp->SetDiffuseColor(0, 1, 1);
146 VertexPVProp->SetSpecularColor(0, 1, 1);
150 vtkActorCollection* GEOM_AssemblyBuilder::BuildActors(const TopoDS_Shape& myShape,
151 Standard_Real deflection,
152 Standard_Integer mode,
153 Standard_Boolean forced,
154 Standard_Boolean isVector)
157 vtkProperty* IsoProp = vtkProperty::New();
158 vtkProperty* FaceProp = vtkProperty::New();
159 vtkProperty* EdgeFProp = vtkProperty::New();
160 vtkProperty* EdgeSProp = vtkProperty::New();
161 vtkProperty* EdgeIProp = vtkProperty::New();
162 vtkProperty* VertexProp = vtkProperty::New();
163 vtkProperty* IsoPVProp = vtkProperty::New();
164 vtkProperty* EdgePVProp = vtkProperty::New();
165 vtkProperty* VertexPVProp = vtkProperty::New();
166 InitProperties(IsoProp,FaceProp,EdgeFProp,EdgeSProp,EdgeIProp,VertexProp,IsoPVProp,EdgePVProp,VertexPVProp);
169 vtkActorCollection* AISActors = vtkActorCollection::New();
170 GEOM::MeshShape(myShape,deflection,forced);
171 GEOM_Actor* aGeomActor = GEOM_Actor::New();
172 aGeomActor->SetShape(myShape,(float)deflection,false,isVector);
173 AISActors->AddItem(aGeomActor);
175 aGeomActor->Delete();
178 if(myShape.ShapeType() == TopAbs_COMPOUND) {
179 TopoDS_Iterator anItr(myShape);
180 for(; anItr.More(); anItr.Next()) {
181 vtkActorCollection* theActors =
182 GEOM_AssemblyBuilder::BuildActors(anItr.Value(), deflection, mode, forced);
183 theActors->InitTraversal();
184 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
185 while(!(anActor==NULL)) {
186 AISActors->AddItem(anActor);
187 anActor = (vtkActor*)theActors->GetNextActor();
191 // Create graphics properties
193 vtkProperty* IsoProp = vtkProperty::New();
194 vtkProperty* FaceProp = vtkProperty::New();
195 vtkProperty* EdgeFProp = vtkProperty::New();
196 vtkProperty* EdgeSProp = vtkProperty::New();
197 vtkProperty* EdgeIProp = vtkProperty::New();
198 vtkProperty* VertexProp = vtkProperty::New();
200 vtkProperty* IsoPVProp = vtkProperty::New();
201 vtkProperty* EdgePVProp = vtkProperty::New();
202 vtkProperty* VertexPVProp = vtkProperty::New();
204 InitProperties(IsoProp,FaceProp,EdgeFProp,EdgeSProp,EdgeIProp,VertexProp,IsoPVProp,EdgePVProp,VertexPVProp);
206 MeshShape(myShape,deflection,forced);
208 if ( myShape.ShapeType() <= 4 && myShape.ShapeType() != TopAbs_COMPOUND) {
211 // look if edges are free or shared
212 TopTools_IndexedDataMapOfShapeListOfShape edgemap;
213 TopExp::MapShapesAndAncestors(myShape,TopAbs_EDGE,TopAbs_FACE,edgemap);
217 for (ex.Init(myShape, TopAbs_FACE); ex.More(); ex.Next()) {
219 GEOM_Actor* FaceActor = GEOM_Actor::New();
220 FaceActor->SetShadingProperty(FaceProp);
221 FaceActor->SetWireframeProperty(IsoProp);
223 FaceActor->SetPreviewProperty(IsoPVProp);
225 FaceActor->setInputShape(ex.Current(),deflection,mode);
227 AISActors->AddItem(FaceActor);
230 for (ex2.Init(ex.Current(), TopAbs_EDGE); ex2.More(); ex2.Next()) {
231 const TopoDS_Edge& aEdge = TopoDS::Edge(ex2.Current());
233 if (BRep_Tool::Degenerated(aEdge)) {
237 // compute the number of faces
238 Standard_Integer nbf = edgemap.FindFromKey(ex2.Current()).Extent();
239 GEOM_Actor* EdgeActor = GEOM_Actor::New();
240 EdgeActor->SubShapeOn();
241 EdgeActor->setInputShape(ex2.Current(),deflection,mode);
245 case 0 : // isolated edge
247 EdgeActor->SetShadingProperty(EdgeIProp);
248 EdgeActor->SetWireframeProperty(EdgeIProp);
252 case 1 :// edge in only one face
254 EdgeActor->SetShadingProperty(EdgeFProp);
255 EdgeActor->SetWireframeProperty(EdgeFProp);
259 default : // edge shared by at least two faces
261 EdgeActor->SetShadingProperty(EdgeSProp);
262 EdgeActor->SetWireframeProperty(EdgeSProp);
266 EdgeActor->SetPreviewProperty(EdgePVProp);
267 AISActors->AddItem(EdgeActor);
270 } else if ( myShape.ShapeType() == TopAbs_WIRE ) { // WIRE Actor
272 for (ex.Init(myShape, TopAbs_EDGE); ex.More(); ex.Next()) {
273 const TopoDS_Edge& aEdge = TopoDS::Edge(ex.Current());
275 if (BRep_Tool::Degenerated(aEdge)) {
279 GEOM_Actor* EdgeActor = GEOM_Actor::New();
280 EdgeActor->setInputShape(ex.Current(),deflection,mode);
281 EdgeActor->SetShadingProperty(EdgeIProp);
282 EdgeActor->SetWireframeProperty(EdgeIProp);
283 EdgeActor->SetPreviewProperty(EdgePVProp);
285 AISActors->AddItem(EdgeActor);
287 } else if ( myShape.ShapeType() == TopAbs_EDGE ) { // EDGE Actor
288 GEOM_Actor* EdgeActor = GEOM_Actor::New();
289 EdgeActor->setInputShape(myShape,deflection,mode,isVector);
290 EdgeActor->SetShadingProperty(EdgeIProp);
291 EdgeActor->SetWireframeProperty(EdgeIProp);
292 EdgeActor->SetPreviewProperty(EdgePVProp);
294 AISActors->AddItem(EdgeActor);
295 } else if ( myShape.ShapeType() == TopAbs_VERTEX ) { // VERTEX Actor
296 GEOM_Actor* VertexActor = GEOM_Actor::New();
297 VertexActor->setInputShape(myShape,deflection,mode);
298 VertexActor->SetShadingProperty(VertexProp);
299 VertexActor->SetWireframeProperty(VertexProp);
300 VertexActor->SetPreviewProperty(VertexPVProp);
302 AISActors->AddItem(VertexActor);
314 //-------------------------------------------------------------
316 //-------------------------------------------------------------
317 vtkAssembly* GEOM_AssemblyBuilder::BuildAssembly(const TopoDS_Shape& myShape,
318 Standard_Real deflection,
319 Standard_Integer mode,
320 Standard_Boolean forced)
322 // Create a new vtkAssembly
324 vtkAssembly* myVTKShape = vtkAssembly::New();
326 // Create graphics properties
328 vtkProperty* IsoProp = vtkProperty::New();
329 vtkProperty* FaceProp = vtkProperty::New();
330 vtkProperty* EdgeFProp = vtkProperty::New();
331 vtkProperty* EdgeSProp = vtkProperty::New();
332 vtkProperty* EdgeIProp = vtkProperty::New();
333 vtkProperty* VertexProp = vtkProperty::New();
334 vtkProperty* EdgePVProp = vtkProperty::New();
335 vtkProperty* VertexPVProp = vtkProperty::New();
336 vtkProperty* IsoPVProp = vtkProperty::New();
338 InitProperties(IsoProp,FaceProp,EdgeFProp,EdgeSProp,EdgeIProp,VertexProp,IsoPVProp,EdgePVProp,VertexPVProp);
340 MeshShape(myShape,deflection,forced);
345 // look if edges are free or shared
346 TopTools_IndexedDataMapOfShapeListOfShape edgemap;
347 TopExp::MapShapesAndAncestors(myShape,TopAbs_EDGE,TopAbs_FACE,edgemap);
351 for (ex.Init(myShape, TopAbs_FACE); ex.More(); ex.Next()) {
352 //const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
354 GEOM_Actor* FaceActor = GEOM_Actor::New();
355 FaceActor->SetShadingProperty(FaceProp);
356 FaceActor->SetWireframeProperty(IsoProp);
358 vtkAssembly* myFaceAssembly = vtkAssembly::New();
361 FaceActor->setInputShape(ex.Current(),deflection,mode);
362 myFaceAssembly->AddPart(FaceActor);
365 for (ex2.Init(ex.Current(), TopAbs_EDGE); ex2.More(); ex2.Next()) {
366 const TopoDS_Edge& aEdge = TopoDS::Edge(ex2.Current());
368 if (BRep_Tool::Degenerated(aEdge)) {
373 // compute the number of faces
374 Standard_Integer nbf = edgemap.FindFromKey(ex2.Current()).Extent();
375 GEOM_Actor* EdgeActor = GEOM_Actor::New();
378 case 0 : // isolated edge
380 EdgeActor->SetShadingProperty(EdgeIProp);
381 EdgeActor->SetWireframeProperty(EdgeIProp);
385 case 1 :// edge in only one face
387 EdgeActor->SetShadingProperty(EdgeFProp);
388 EdgeActor->SetWireframeProperty(EdgeFProp);
392 default : // edge shared by at least two faces
394 EdgeActor->SetShadingProperty(EdgeSProp);
395 EdgeActor->SetWireframeProperty(EdgeSProp);
399 EdgeActor->setInputShape(ex2.Current(),deflection,mode);
400 myFaceAssembly->AddPart(EdgeActor);
402 myVTKShape->AddPart(myFaceAssembly);
411 //-------------------------------------------------------------
412 // CHANGE SPECIFIC DISPLAY MODE
413 //-------------------------------------------------------------
414 void GEOM_AssemblyBuilder::SwitchDisplayMode(vtkAssembly* aOCCAssembly)
418 void GEOM_AssemblyBuilder::SwitchDisplayMode(vtkActorCollection* aOCCAssembly)
422 //-------------------------------------------------------------
424 //-------------------------------------------------------------
426 void GEOM_AssemblyBuilder::DisplayErase(vtkAssembly* mySALOMEAssembly)
431 void GEOM_AssemblyBuilder::DisplayErase(vtkActorCollection* mySALOMEActors)