b311480e |
1 | // Created on: 2000-08-15 |
2 | // Created by: Andrey BETENEV |
973c2be1 |
3 | // Copyright (c) 2000-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
42cf5bc1 |
16 | |
7fd59977 |
17 | #include <BRep_Builder.hxx> |
42cf5bc1 |
18 | #include <TColStd_HSequenceOfExtendedString.hxx> |
19 | #include <TDF_AttributeSequence.hxx> |
20 | #include <TDF_Label.hxx> |
21 | #include <TDF_LabelSequence.hxx> |
22 | #include <TopLoc_IndexedMapOfLocation.hxx> |
23 | #include <TopLoc_Location.hxx> |
7fd59977 |
24 | #include <TopoDS.hxx> |
25 | #include <TopoDS_Compound.hxx> |
42cf5bc1 |
26 | #include <TopoDS_Iterator.hxx> |
7fd59977 |
27 | #include <TopTools_SequenceOfShape.hxx> |
42cf5bc1 |
28 | #include <XCAFDoc_ColorTool.hxx> |
29 | #include <XCAFDoc_DocumentTool.hxx> |
7fd59977 |
30 | #include <XCAFDoc_GraphNode.hxx> |
42cf5bc1 |
31 | #include <XCAFDoc_LayerTool.hxx> |
32 | #include <XCAFDoc_ShapeTool.hxx> |
33 | #include <XCAFPrs.hxx> |
3ea0a91b |
34 | #include <XCAFPrs_Style.hxx> |
7fd59977 |
35 | |
36 | static Standard_Boolean viewnameMode = Standard_False; |
37 | |
38 | static Standard_Boolean getShapesOfSHUO (TopLoc_IndexedMapOfLocation& theaPrevLocMap, |
39 | const Handle(XCAFDoc_ShapeTool)& theSTool, |
40 | const TDF_Label& theSHUOlab, |
41 | TopTools_SequenceOfShape& theSHUOShapeSeq) |
42 | { |
43 | Handle(XCAFDoc_GraphNode) SHUO; |
44 | TDF_LabelSequence aLabSeq; |
45 | theSTool->GetSHUONextUsage( theSHUOlab, aLabSeq ); |
46 | if (aLabSeq.Length() >= 1) |
47 | for (Standard_Integer i = 1; i <= aLabSeq.Length(); i++) { |
48 | TDF_Label aSubCompL = aLabSeq.Value( i ); |
49 | TopLoc_Location compLoc = XCAFDoc_ShapeTool::GetLocation ( aSubCompL.Father() ); |
50 | // create new map of laocation (to not merge locations from different shapes) |
51 | TopLoc_IndexedMapOfLocation aNewPrevLocMap; |
52 | for (Standard_Integer m = 1; m <= theaPrevLocMap.Extent(); m++) |
53 | aNewPrevLocMap.Add( theaPrevLocMap.FindKey( m ) ); |
54 | aNewPrevLocMap.Add( compLoc ); |
55 | // got for the new sublocations and corresponding shape |
56 | getShapesOfSHUO( aNewPrevLocMap, theSTool, aSubCompL, theSHUOShapeSeq ); |
57 | } |
58 | else { |
59 | TopoDS_Shape aSHUO_NUSh = theSTool->GetShape ( theSHUOlab.Father() ); |
60 | if ( aSHUO_NUSh.IsNull() ) return Standard_False; |
61 | // cause got shape with location already. |
62 | TopLoc_Location nullLoc; |
63 | aSHUO_NUSh.Location ( nullLoc ); |
64 | // multiply the locations |
65 | Standard_Integer intMapLenght = theaPrevLocMap.Extent(); |
66 | if ( intMapLenght < 1 ) |
67 | return Standard_False; // should not be, but to avoid exception...? |
68 | TopLoc_Location SupcompLoc; |
69 | SupcompLoc = theaPrevLocMap.FindKey( intMapLenght ); |
70 | if (intMapLenght > 1) { |
71 | Standard_Integer l = intMapLenght - 1; |
72 | while (l >= 1) { |
73 | SupcompLoc = theaPrevLocMap.FindKey( l ).Multiplied( SupcompLoc ); |
74 | l--; |
75 | } |
76 | } |
77 | aSHUO_NUSh.Location( SupcompLoc ); |
78 | theSHUOShapeSeq.Append( aSHUO_NUSh ); |
79 | } |
80 | return (theSHUOShapeSeq.Length() > 0); |
81 | } |
82 | |
83 | //======================================================================= |
84 | //function : CollectStyleSettings |
85 | //purpose : |
86 | //======================================================================= |
87 | |
9c86076b |
88 | void XCAFPrs::CollectStyleSettings (const TDF_Label& theLabel, |
89 | const TopLoc_Location& theLoc, |
90 | XCAFPrs_DataMapOfShapeStyle& theSettings) |
7fd59977 |
91 | { |
7fd59977 |
92 | // for references, first collect colors of referred shape |
9c86076b |
93 | { |
94 | TDF_Label aLabelRef; |
95 | if (XCAFDoc_ShapeTool::GetReferredShape (theLabel, aLabelRef)) |
96 | { |
97 | TopLoc_Location aLocSub = theLoc.Multiplied (XCAFDoc_ShapeTool::GetLocation (theLabel)); |
98 | CollectStyleSettings (aLabelRef, aLocSub, theSettings); |
99 | } |
7fd59977 |
100 | } |
9c86076b |
101 | |
7fd59977 |
102 | // for assemblies, first collect colors defined in components |
9c86076b |
103 | { |
104 | TDF_LabelSequence aComponentLabSeq; |
105 | if (XCAFDoc_ShapeTool::GetComponents (theLabel, aComponentLabSeq) |
106 | && !aComponentLabSeq.IsEmpty()) |
107 | { |
108 | for (TDF_LabelSequence::Iterator aComponentIter (aComponentLabSeq); aComponentIter.More(); aComponentIter.Next()) |
109 | { |
110 | const TDF_Label& aComponentLab = aComponentIter.Value(); |
111 | CollectStyleSettings (aComponentLab, theLoc, theSettings); |
112 | } |
7fd59977 |
113 | } |
114 | } |
115 | |
9c86076b |
116 | // collect settings on subshapes |
117 | Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool(theLabel); |
118 | TDF_LabelSequence aLabSeq; |
119 | XCAFDoc_ShapeTool::GetSubShapes (theLabel, aLabSeq); |
120 | // and add the shape itself |
121 | aLabSeq.Append (theLabel); |
122 | for (TDF_LabelSequence::Iterator aLabIter (aLabSeq); aLabIter.More(); aLabIter.Next()) |
123 | { |
124 | const TDF_Label& aLabel = aLabIter.Value(); |
125 | XCAFPrs_Style aStyle; |
126 | |
127 | Standard_Boolean isVisible = aColorTool->IsVisible (aLabel); |
128 | if (isVisible) |
129 | { |
130 | Handle(XCAFDoc_LayerTool) aLayerTool = XCAFDoc_DocumentTool::LayerTool (aLabel); |
131 | Handle(TColStd_HSequenceOfExtendedString) aLayerNames = new TColStd_HSequenceOfExtendedString(); |
132 | aLayerTool->GetLayers (aLabel, aLayerNames); |
133 | Standard_Integer aNbHidden = 0; |
134 | for (TColStd_HSequenceOfExtendedString::Iterator aLayerIter (*aLayerNames); aLayerIter.More(); aLayerIter.Next()) |
135 | { |
136 | const TCollection_ExtendedString& aLayerName = aLayerIter.Value(); |
137 | if (!aLayerTool->IsVisible (aLayerTool->FindLayer (aLayerName))) |
138 | { |
139 | ++aNbHidden; |
140 | } |
141 | } |
142 | isVisible = aNbHidden == 0 |
143 | || aNbHidden != aLayerNames->Length(); |
7fd59977 |
144 | } |
9c86076b |
145 | |
146 | if (!isVisible) |
147 | { |
148 | aStyle.SetVisibility (Standard_False); |
7fd59977 |
149 | } |
9c86076b |
150 | else |
151 | { |
152 | Quantity_Color aColor; |
153 | if (aColorTool->GetColor (aLabel, XCAFDoc_ColorGen, aColor)) |
154 | { |
155 | aStyle.SetColorCurv (aColor); |
156 | aStyle.SetColorSurf (aColor); |
157 | } |
158 | if (aColorTool->GetColor (aLabel, XCAFDoc_ColorSurf, aColor)) |
159 | { |
160 | aStyle.SetColorSurf (aColor); |
161 | } |
162 | if (aColorTool->GetColor (aLabel, XCAFDoc_ColorCurv, aColor)) |
163 | { |
164 | aStyle.SetColorCurv (aColor); |
7fd59977 |
165 | } |
7fd59977 |
166 | } |
9c86076b |
167 | |
7fd59977 |
168 | // PTV try to set color from SHUO structure |
9c86076b |
169 | Handle(XCAFDoc_ShapeTool) aShapeTool = aColorTool->ShapeTool(); |
170 | if (aShapeTool->IsComponent (aLabel)) |
171 | { |
172 | TDF_AttributeSequence aShuoAttribSeq; |
173 | aShapeTool->GetAllComponentSHUO (aLabel, aShuoAttribSeq); |
174 | for (TDF_AttributeSequence::Iterator aShuoAttribIter (aShuoAttribSeq); aShuoAttribIter.More(); aShuoAttribIter.Next()) |
175 | { |
176 | Handle(XCAFDoc_GraphNode) aShuoNode = Handle(XCAFDoc_GraphNode)::DownCast (aShuoAttribIter.Value()); |
177 | if (aShuoNode.IsNull()) |
178 | { |
7fd59977 |
179 | continue; |
9c86076b |
180 | } |
7fd59977 |
181 | |
9c86076b |
182 | const TDF_Label aShuolab = aShuoNode->Label(); |
183 | { |
184 | TDF_LabelSequence aShuoLabSeq; |
185 | aShapeTool->GetSHUONextUsage (aShuolab, aShuoLabSeq); |
186 | if (aShuoLabSeq.IsEmpty()) |
187 | { |
188 | continue; |
7fd59977 |
189 | } |
7fd59977 |
190 | } |
9c86076b |
191 | |
192 | Quantity_Color aColor; |
193 | XCAFPrs_Style aShuoStyle; |
194 | if (!aColorTool->IsVisible (aShuolab)) |
195 | { |
196 | aShuoStyle.SetVisibility (Standard_False); |
197 | } |
198 | else |
199 | { |
200 | if (aColorTool->GetColor (aShuolab, XCAFDoc_ColorGen, aColor)) |
201 | { |
202 | aShuoStyle.SetColorCurv (aColor); |
203 | aShuoStyle.SetColorSurf (aColor); |
204 | } |
205 | if (aColorTool->GetColor (aShuolab, XCAFDoc_ColorSurf, aColor)) |
206 | { |
207 | aShuoStyle.SetColorSurf (aColor); |
208 | } |
209 | if (aColorTool->GetColor (aShuolab, XCAFDoc_ColorCurv, aColor)) |
210 | { |
211 | aShuoStyle.SetColorCurv (aColor); |
212 | } |
213 | } |
214 | if (!aShuoStyle.IsSetColorCurv() |
215 | && !aShuoStyle.IsSetColorSurf() |
216 | && aShuoStyle.IsVisible()) |
217 | { |
7fd59977 |
218 | continue; |
9c86076b |
219 | } |
220 | |
221 | // set style for all component from Next Usage Occurrence. |
222 | #ifdef OCCT_DEBUG |
7fd59977 |
223 | cout << "Set the style for SHUO next_usage-occurrance" << endl; |
9c86076b |
224 | #endif |
7fd59977 |
225 | /* |
226 | // may be work, but static it returns excess shapes. It is more faster to use OLD version. |
227 | // PTV 14.02.2003 NEW version using API of ShapeTool |
9c86076b |
228 | TopTools_SequenceOfShape aShuoShapeSeq; |
229 | aShapeTool->GetAllStyledComponents (aShuoNode, aShuoShapeSeq); |
230 | for (TopTools_SequenceOfShape::Iterator aShuoShapeIter (aShuoShapeSeq); aShuoShapeIter.More(); aShuoShapeIter.Next()) |
231 | { |
232 | const TopoDS_Shape& aShuoShape = aShuoShapeIter.Value(); |
233 | if (!aShuoShape.IsNull()) |
234 | theSettings.Bind (aShuoShape, aShuoStyle); |
235 | }*/ |
236 | // OLD version that was written before ShapeTool API, and it FASTER for presentation |
7fd59977 |
237 | // get TOP location of SHUO component |
9c86076b |
238 | TopLoc_Location compLoc = XCAFDoc_ShapeTool::GetLocation (aLabel); |
7fd59977 |
239 | TopLoc_IndexedMapOfLocation aPrevLocMap; |
9c86076b |
240 | // get previous set location |
241 | if (!theLoc.IsIdentity()) |
242 | { |
243 | aPrevLocMap.Add (theLoc); |
244 | } |
245 | aPrevLocMap.Add (compLoc); |
246 | |
7fd59977 |
247 | // get shapes of SHUO Next_Usage components |
9c86076b |
248 | TopTools_SequenceOfShape aShuoShapeSeq; |
249 | getShapesOfSHUO (aPrevLocMap, aShapeTool, aShuolab, aShuoShapeSeq); |
250 | for (TopTools_SequenceOfShape::Iterator aShuoShapeIter (aShuoShapeSeq); aShuoShapeIter.More(); aShuoShapeIter.Next()) |
251 | { |
252 | const TopoDS_Shape& aShuoShape = aShuoShapeIter.Value(); |
253 | theSettings.Bind (aShuoShape, aShuoStyle); |
7fd59977 |
254 | } |
255 | continue; |
256 | } |
257 | } |
9c86076b |
258 | |
259 | if (!aStyle.IsSetColorCurv() |
260 | && !aStyle.IsSetColorSurf() |
261 | && aStyle.IsVisible()) |
262 | { |
7fd59977 |
263 | continue; |
9c86076b |
264 | } |
265 | |
266 | TopoDS_Shape aSubshape = XCAFDoc_ShapeTool::GetShape (aLabel); |
267 | if (aSubshape.ShapeType() == TopAbs_COMPOUND) |
268 | { |
269 | const TopoDS_Iterator aShapeIter (aSubshape); |
270 | if (!aShapeIter.More()) |
271 | { |
272 | continue; |
273 | } |
274 | } |
275 | aSubshape.Move (theLoc); |
276 | theSettings.Bind (aSubshape, aStyle); |
7fd59977 |
277 | } |
278 | } |
279 | |
7fd59977 |
280 | //======================================================================= |
281 | //function : SetViewNameMode |
282 | //purpose : |
283 | //======================================================================= |
284 | |
285 | void XCAFPrs::SetViewNameMode(const Standard_Boolean aNameMode ) |
286 | { |
287 | viewnameMode = aNameMode; |
288 | } |
289 | |
290 | //======================================================================= |
291 | //function : GetViewNameMode |
292 | //purpose : |
293 | //======================================================================= |
294 | |
295 | Standard_Boolean XCAFPrs::GetViewNameMode() |
296 | { |
297 | return viewnameMode; |
298 | } |