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 | |
16 | #include <XCAFPrs.ixx> |
17 | #include <XCAFDoc_ShapeTool.hxx> |
18 | #include <XCAFDoc_ColorTool.hxx> |
19 | #include <TDF_LabelSequence.hxx> |
20 | #include <TopoDS_Iterator.hxx> |
21 | #include <BRep_Builder.hxx> |
22 | #include <TopoDS.hxx> |
23 | #include <TopoDS_Compound.hxx> |
24 | #include <XCAFDoc_DocumentTool.hxx> |
25 | #include <TColStd_HSequenceOfExtendedString.hxx> |
26 | #include <XCAFDoc_LayerTool.hxx> |
27 | #include <TopTools_SequenceOfShape.hxx> |
28 | #include <TopLoc_IndexedMapOfLocation.hxx> |
29 | #include <TDF_AttributeSequence.hxx> |
30 | #include <XCAFDoc_GraphNode.hxx> |
3ea0a91b |
31 | #include <XCAFPrs_Style.hxx> |
7fd59977 |
32 | |
33 | static Standard_Boolean viewnameMode = Standard_False; |
34 | |
35 | static Standard_Boolean getShapesOfSHUO (TopLoc_IndexedMapOfLocation& theaPrevLocMap, |
36 | const Handle(XCAFDoc_ShapeTool)& theSTool, |
37 | const TDF_Label& theSHUOlab, |
38 | TopTools_SequenceOfShape& theSHUOShapeSeq) |
39 | { |
40 | Handle(XCAFDoc_GraphNode) SHUO; |
41 | TDF_LabelSequence aLabSeq; |
42 | theSTool->GetSHUONextUsage( theSHUOlab, aLabSeq ); |
43 | if (aLabSeq.Length() >= 1) |
44 | for (Standard_Integer i = 1; i <= aLabSeq.Length(); i++) { |
45 | TDF_Label aSubCompL = aLabSeq.Value( i ); |
46 | TopLoc_Location compLoc = XCAFDoc_ShapeTool::GetLocation ( aSubCompL.Father() ); |
47 | // create new map of laocation (to not merge locations from different shapes) |
48 | TopLoc_IndexedMapOfLocation aNewPrevLocMap; |
49 | for (Standard_Integer m = 1; m <= theaPrevLocMap.Extent(); m++) |
50 | aNewPrevLocMap.Add( theaPrevLocMap.FindKey( m ) ); |
51 | aNewPrevLocMap.Add( compLoc ); |
52 | // got for the new sublocations and corresponding shape |
53 | getShapesOfSHUO( aNewPrevLocMap, theSTool, aSubCompL, theSHUOShapeSeq ); |
54 | } |
55 | else { |
56 | TopoDS_Shape aSHUO_NUSh = theSTool->GetShape ( theSHUOlab.Father() ); |
57 | if ( aSHUO_NUSh.IsNull() ) return Standard_False; |
58 | // cause got shape with location already. |
59 | TopLoc_Location nullLoc; |
60 | aSHUO_NUSh.Location ( nullLoc ); |
61 | // multiply the locations |
62 | Standard_Integer intMapLenght = theaPrevLocMap.Extent(); |
63 | if ( intMapLenght < 1 ) |
64 | return Standard_False; // should not be, but to avoid exception...? |
65 | TopLoc_Location SupcompLoc; |
66 | SupcompLoc = theaPrevLocMap.FindKey( intMapLenght ); |
67 | if (intMapLenght > 1) { |
68 | Standard_Integer l = intMapLenght - 1; |
69 | while (l >= 1) { |
70 | SupcompLoc = theaPrevLocMap.FindKey( l ).Multiplied( SupcompLoc ); |
71 | l--; |
72 | } |
73 | } |
74 | aSHUO_NUSh.Location( SupcompLoc ); |
75 | theSHUOShapeSeq.Append( aSHUO_NUSh ); |
76 | } |
77 | return (theSHUOShapeSeq.Length() > 0); |
78 | } |
79 | |
80 | //======================================================================= |
81 | //function : CollectStyleSettings |
82 | //purpose : |
83 | //======================================================================= |
84 | |
85 | void XCAFPrs::CollectStyleSettings (const TDF_Label &L, |
86 | const TopLoc_Location &loc, |
87 | XCAFPrs_DataMapOfShapeStyle &settings) |
88 | { |
89 | Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( L ); |
90 | |
91 | // for references, first collect colors of referred shape |
92 | TDF_Label Lref; |
93 | if ( XCAFDoc_ShapeTool::GetReferredShape ( L, Lref ) ) { |
94 | TopLoc_Location locSub = loc.Multiplied ( XCAFDoc_ShapeTool::GetLocation ( L ) ); |
95 | CollectStyleSettings ( Lref, locSub, settings ); |
96 | } |
97 | |
98 | // for assemblies, first collect colors defined in components |
99 | TDF_LabelSequence seq; |
100 | if ( XCAFDoc_ShapeTool::GetComponents ( L, seq ) && seq.Length() >0 ) { |
101 | for ( Standard_Integer i = 1; i <= seq.Length(); i++ ) { |
102 | CollectStyleSettings ( seq.Value(i), loc, settings ); |
103 | } |
104 | } |
105 | |
106 | // collect settings on subshapes and the shape itself |
107 | seq.Clear(); |
108 | XCAFDoc_ShapeTool::GetSubShapes ( L, seq ); |
109 | seq.Append ( L ); |
110 | for ( Standard_Integer i = 1; i <= seq.Length(); i++ ) { |
111 | TDF_Label lab = seq.Value(i); |
112 | XCAFPrs_Style style; |
113 | Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool( lab ); |
114 | Handle(TColStd_HSequenceOfExtendedString) LayNames = new TColStd_HSequenceOfExtendedString; |
115 | |
116 | LTool->GetLayers(lab, LayNames); |
117 | Standard_Integer InVisCount = 0; |
118 | for ( Standard_Integer iL = 1; iL <= LayNames->Length(); iL++) { |
119 | if ( !LTool->IsVisible( LTool->FindLayer(LayNames->Value(iL)) ) ) InVisCount++; |
120 | } |
0ebaa4db |
121 | if ( (InVisCount >0 && InVisCount == LayNames->Length()) || |
7fd59977 |
122 | !CTool->IsVisible(lab) ) { |
123 | style.SetVisibility(Standard_False); |
124 | } |
125 | else { |
126 | Quantity_Color C; |
127 | if ( CTool->GetColor ( lab, XCAFDoc_ColorGen, C ) ) { |
128 | style.SetColorCurv ( C ); |
129 | style.SetColorSurf ( C ); |
130 | } |
131 | if ( CTool->GetColor ( lab, XCAFDoc_ColorSurf, C ) ) |
132 | style.SetColorSurf ( C ); |
133 | if ( CTool->GetColor ( lab, XCAFDoc_ColorCurv, C ) ) |
134 | style.SetColorCurv ( C ); |
135 | } |
136 | // PTV try to set color from SHUO structure |
137 | Handle(XCAFDoc_ShapeTool) STool = CTool->ShapeTool(); |
138 | Handle(XCAFDoc_GraphNode) SHUO; |
139 | TDF_AttributeSequence theSHUOAttrs; |
140 | if (STool->IsComponent( lab ) ) { |
141 | STool->GetAllComponentSHUO( lab, theSHUOAttrs ); |
142 | for (Standard_Integer shuoIndx = 1; shuoIndx <= theSHUOAttrs.Length(); shuoIndx++) { |
143 | SHUO = Handle(XCAFDoc_GraphNode)::DownCast(theSHUOAttrs.Value(shuoIndx)); |
144 | if ( SHUO.IsNull() ) |
145 | continue; |
146 | TDF_Label aSHUOlab = SHUO->Label(); |
147 | |
148 | TDF_LabelSequence aLabSeq; |
149 | STool->GetSHUONextUsage( aSHUOlab, aLabSeq ); |
150 | if (aLabSeq.Length() < 1 ) |
151 | continue; |
152 | |
153 | Quantity_Color C; |
154 | XCAFPrs_Style SHUOstyle; |
155 | if (!CTool->IsVisible( aSHUOlab ) ) |
156 | SHUOstyle.SetVisibility(Standard_False); |
157 | else { |
158 | if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorGen, C ) ) { |
159 | SHUOstyle.SetColorCurv ( C ); |
160 | SHUOstyle.SetColorSurf ( C ); |
161 | } |
162 | if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorSurf, C ) ) |
163 | SHUOstyle.SetColorSurf ( C ); |
164 | if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorCurv, C ) ) |
165 | SHUOstyle.SetColorCurv ( C ); |
166 | } |
167 | if ( !SHUOstyle.IsSetColorCurv() && |
168 | !SHUOstyle.IsSetColorSurf() && |
169 | SHUOstyle.IsVisible() ) |
170 | continue; |
171 | |
172 | // set style for all component from Next Usage Occurrence. |
0797d9d3 |
173 | #ifdef OCCT_DEBUG |
7fd59977 |
174 | cout << "Set the style for SHUO next_usage-occurrance" << endl; |
175 | #endif |
176 | /* |
177 | // may be work, but static it returns excess shapes. It is more faster to use OLD version. |
178 | // PTV 14.02.2003 NEW version using API of ShapeTool |
179 | TopTools_SequenceOfShape aSHUOShapeSeq; |
180 | STool->GetAllStyledComponents( SHUO, aSHUOShapeSeq ); |
181 | for (Standard_Integer si= 1; si <= aSHUOShapeSeq.Length(); si++) { |
182 | TopoDS_Shape aSHUOSh = aSHUOShapeSeq.Value(si); |
183 | if (!aSHUOSh.IsNull()) |
184 | settings.Bind ( aSHUOSh, SHUOstyle ); |
185 | } |
186 | */ |
187 | // OLD version that was written before ShapeTool API, and ti FASTER for presentation |
188 | // get TOP location of SHUO component |
189 | TopLoc_Location compLoc = XCAFDoc_ShapeTool::GetLocation ( lab ); |
190 | TopLoc_IndexedMapOfLocation aPrevLocMap; |
191 | // get previous setted location |
192 | if ( !loc.IsIdentity() ) |
193 | aPrevLocMap.Add( loc ); |
194 | |
195 | aPrevLocMap.Add( compLoc ); |
196 | TopTools_SequenceOfShape aSHUOShapeSeq; |
197 | // get shapes of SHUO Next_Usage components |
198 | getShapesOfSHUO( aPrevLocMap, STool, aSHUOlab, aSHUOShapeSeq ); |
199 | for (Standard_Integer n = 1; n <= aSHUOShapeSeq.Length(); n++ ) { |
200 | TopoDS_Shape aSHUOSh = aSHUOShapeSeq.Value( n ); |
201 | settings.Bind ( aSHUOSh, SHUOstyle ); |
202 | } |
203 | continue; |
204 | } |
205 | } |
206 | if ( !style.IsSetColorCurv() && |
207 | !style.IsSetColorSurf() && |
208 | style.IsVisible() ) |
209 | continue; |
210 | TopoDS_Shape sub = XCAFDoc_ShapeTool::GetShape ( lab ); |
211 | sub.Move ( loc ); |
212 | settings.Bind ( sub, style ); |
213 | } |
214 | } |
215 | |
7fd59977 |
216 | //======================================================================= |
217 | //function : SetViewNameMode |
218 | //purpose : |
219 | //======================================================================= |
220 | |
221 | void XCAFPrs::SetViewNameMode(const Standard_Boolean aNameMode ) |
222 | { |
223 | viewnameMode = aNameMode; |
224 | } |
225 | |
226 | //======================================================================= |
227 | //function : GetViewNameMode |
228 | //purpose : |
229 | //======================================================================= |
230 | |
231 | Standard_Boolean XCAFPrs::GetViewNameMode() |
232 | { |
233 | return viewnameMode; |
234 | } |