b311480e |
1 | // Created on: 1999-11-05 |
2 | // Created by: Vladislav ROMASHKO |
3 | // Copyright (c) 1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
b311480e |
16 | |
7fd59977 |
17 | // Modified by vro, Thu Dec 21 10:34:49 2000 |
18 | // Modified by vro, Thu Dec 21 10:34:59 2000 |
19 | |
42cf5bc1 |
20 | #include <BRep_Tool.hxx> |
21 | #include <BRepPrimAPI_MakePrism.hxx> |
7fd59977 |
22 | #include <QANewBRepNaming_Loader.hxx> |
42cf5bc1 |
23 | #include <QANewBRepNaming_Prism.hxx> |
24 | #include <Standard_NullObject.hxx> |
25 | #include <TColStd_ListOfInteger.hxx> |
7fd59977 |
26 | #include <TDF_Label.hxx> |
27 | #include <TDF_TagSource.hxx> |
42cf5bc1 |
28 | #include <TNaming_Builder.hxx> |
7fd59977 |
29 | #include <TopExp.hxx> |
42cf5bc1 |
30 | #include <TopExp_Explorer.hxx> |
7fd59977 |
31 | #include <TopoDS.hxx> |
42cf5bc1 |
32 | #include <TopoDS_Iterator.hxx> |
33 | #include <TopoDS_Shape.hxx> |
34 | #include <TopTools_DataMapOfShapeShape.hxx> |
35 | #include <TopTools_IndexedMapOfShape.hxx> |
7fd59977 |
36 | |
0797d9d3 |
37 | #ifdef OCCT_DEBUG |
7fd59977 |
38 | #include <TDataStd_Name.hxx> |
39 | #endif |
40 | |
41 | //======================================================================= |
42 | //function : QANewBRepNaming_Prism |
43 | //purpose : |
44 | //======================================================================= |
45 | |
46 | QANewBRepNaming_Prism::QANewBRepNaming_Prism() {} |
47 | |
48 | //======================================================================= |
49 | //function : QANewBRepNaming_Prism |
50 | //purpose : |
51 | //======================================================================= |
52 | |
53 | QANewBRepNaming_Prism::QANewBRepNaming_Prism(const TDF_Label& Label):QANewBRepNaming_TopNaming(Label) {} |
54 | |
55 | //======================================================================= |
56 | //function : Init |
57 | //purpose : |
58 | //======================================================================= |
59 | |
60 | void QANewBRepNaming_Prism::Init(const TDF_Label& Label) { |
61 | if(Label.IsNull()) |
62 | Standard_NullObject::Raise("QANewBRepNaming_Prism::Init The Result label is Null ..."); |
63 | myResultLabel = Label; |
64 | } |
65 | |
66 | //======================================================================= |
67 | //function : Bottom |
68 | //purpose : |
69 | //======================================================================= |
70 | |
71 | TDF_Label QANewBRepNaming_Prism::Bottom() const { |
72 | const TDF_Label& L = ResultLabel().NewChild(); |
0797d9d3 |
73 | #ifdef OCCT_DEBUG |
7fd59977 |
74 | TDataStd_Name::Set(L, "Bottom"); |
75 | #endif |
76 | return L; |
77 | } |
78 | |
79 | //======================================================================= |
80 | //function : Top |
81 | //purpose : |
82 | //======================================================================= |
83 | |
84 | TDF_Label QANewBRepNaming_Prism::Top() const { |
85 | const TDF_Label& L = ResultLabel().NewChild(); |
0797d9d3 |
86 | #ifdef OCCT_DEBUG |
7fd59977 |
87 | TDataStd_Name::Set(L, "Top"); |
88 | #endif |
89 | return L; |
90 | } |
91 | |
92 | //======================================================================= |
93 | //function : Lateral |
94 | //purpose : |
95 | //======================================================================= |
96 | |
97 | TDF_Label QANewBRepNaming_Prism::Lateral() const { |
98 | const TDF_Label& L = ResultLabel().NewChild(); |
0797d9d3 |
99 | #ifdef OCCT_DEBUG |
7fd59977 |
100 | TDataStd_Name::Set(L, "Lateral"); |
101 | #endif |
102 | return L; |
103 | } |
104 | |
105 | //======================================================================= |
106 | //function : Degenerated |
107 | //purpose : |
108 | //======================================================================= |
109 | |
110 | TDF_Label QANewBRepNaming_Prism::Degenerated() const { |
111 | const TDF_Label& L = ResultLabel().NewChild(); |
0797d9d3 |
112 | #ifdef OCCT_DEBUG |
7fd59977 |
113 | TDataStd_Name::Set(L, "Degenerated"); |
114 | #endif |
115 | return L; |
116 | } |
117 | |
118 | //======================================================================= |
119 | //function : Dangle |
120 | //purpose : |
121 | //======================================================================= |
122 | |
123 | TDF_Label QANewBRepNaming_Prism::Dangle() const { |
124 | const TDF_Label& L = ResultLabel().NewChild(); |
0797d9d3 |
125 | #ifdef OCCT_DEBUG |
7fd59977 |
126 | TDataStd_Name::Set(L, "Dangle"); |
127 | #endif |
128 | return L; |
129 | } |
130 | |
131 | //======================================================================= |
132 | //function : Content |
133 | //purpose : |
134 | //======================================================================= |
135 | |
136 | TDF_Label QANewBRepNaming_Prism::Content() const { |
137 | const TDF_Label& L = ResultLabel().NewChild(); |
0797d9d3 |
138 | #ifdef OCCT_DEBUG |
7fd59977 |
139 | TDataStd_Name::Set(L, "Content"); |
140 | #endif |
141 | return L; |
142 | } |
143 | |
144 | //======================================================================= |
145 | //function : Load (Prism) |
146 | //purpose : |
147 | //======================================================================= |
148 | |
149 | void QANewBRepNaming_Prism::Load (BRepPrimAPI_MakePrism& mkPrism, |
150 | const TopoDS_Shape& basis) const |
151 | { |
152 | TopTools_DataMapOfShapeShape SubShapes; |
153 | for (TopExp_Explorer Exp(mkPrism.Shape(),TopAbs_FACE); Exp.More(); Exp.Next()) { |
154 | SubShapes.Bind(Exp.Current(),Exp.Current()); |
155 | } |
156 | Handle(TDF_TagSource) Tagger = TDF_TagSource::Set(ResultLabel()); |
157 | if (Tagger.IsNull()) return; |
158 | Tagger->Set(0); |
159 | |
160 | TNaming_Builder Builder (ResultLabel()); |
161 | Builder.Generated(basis, mkPrism.Shape()); //szy - 17.06.03 |
162 | |
163 | //Insert lateral face : Face from Edge |
164 | TNaming_Builder LateralFaceBuilder(Lateral()); |
165 | QANewBRepNaming_Loader::LoadAndOrientGeneratedShapes(mkPrism, basis, TopAbs_EDGE, |
166 | LateralFaceBuilder, SubShapes); |
167 | |
168 | Standard_Boolean makeTopBottom = Standard_True; |
169 | if (basis.ShapeType() == TopAbs_COMPOUND) { |
170 | TopoDS_Iterator itr(basis); |
171 | if (itr.More() && itr.Value().ShapeType() == TopAbs_WIRE) makeTopBottom = Standard_False; |
172 | } else if (basis.ShapeType() == TopAbs_WIRE || basis.ShapeType() == TopAbs_EDGE) { |
173 | makeTopBottom = Standard_False; |
174 | } |
175 | if (makeTopBottom) { |
176 | //Insert bottom face |
177 | TopoDS_Shape BottomFace = mkPrism.FirstShape(); |
178 | if (!BottomFace.IsNull()) { |
179 | if (BottomFace.ShapeType() != TopAbs_COMPOUND) { |
180 | TNaming_Builder BottomBuilder(Bottom()); |
181 | if (SubShapes.IsBound(BottomFace)) { |
182 | BottomFace = SubShapes(BottomFace); |
183 | } |
184 | BottomBuilder.Generated(BottomFace); |
185 | } else { |
186 | TopoDS_Iterator itr(BottomFace); |
187 | for (; itr.More(); itr.Next()) { |
188 | TNaming_Builder BottomBuilder(Bottom()); |
189 | BottomBuilder.Generated(itr.Value()); |
190 | } |
191 | } |
192 | } |
193 | |
194 | //Insert top face |
195 | TopoDS_Shape TopFace = mkPrism.LastShape(); |
196 | if (!TopFace.IsNull()) { |
197 | if (TopFace.ShapeType() != TopAbs_COMPOUND) { |
198 | TNaming_Builder TopBuilder(Top()); |
199 | if (SubShapes.IsBound(TopFace)) { |
200 | TopFace = SubShapes(TopFace); |
201 | } |
202 | TopBuilder.Generated(TopFace); |
203 | } else { |
204 | TopoDS_Iterator itr(TopFace); |
205 | for (; itr.More(); itr.Next()) { |
206 | TNaming_Builder TopBuilder(Top()); |
207 | TopBuilder.Generated(itr.Value()); |
208 | } |
209 | } |
210 | } |
211 | } |
212 | |
213 | // Insert dangle edges and vertices: |
214 | if (QANewBRepNaming_Loader::HasDangleShapes(mkPrism.Shape())) { |
215 | if (mkPrism.Shape().ShapeType() == TopAbs_COMPOUND) { |
216 | TopoDS_Iterator itr(mkPrism.Shape()); |
217 | for (; itr.More(); itr.Next()) { |
218 | QANewBRepNaming_Loader::LoadDangleShapes(itr.Value(), ResultLabel()); |
219 | } |
220 | } else { |
221 | QANewBRepNaming_Loader::LoadDangleShapes(mkPrism.Shape(), ResultLabel()); |
222 | } |
223 | } |
224 | |
225 | // Insert degenerated shapes: |
226 | TopTools_IndexedMapOfShape allEdges; |
227 | TopExp::MapShapes(mkPrism.Shape(), TopAbs_EDGE, allEdges); |
228 | Standard_Integer i = 1; |
229 | TColStd_ListOfInteger goodEdges; |
230 | for (; i <= allEdges.Extent(); i++) { |
231 | if (BRep_Tool::Degenerated(TopoDS::Edge(allEdges.FindKey(i)))) { |
232 | TNaming_Builder DegeneratedBuilder(Degenerated()); |
233 | DegeneratedBuilder.Generated(allEdges.FindKey(i)); |
234 | } |
235 | } |
236 | |
237 | // The content of the result: |
238 | if (mkPrism.Shape().ShapeType() == TopAbs_COMPOUND) { |
239 | TopoDS_Iterator itr(mkPrism.Shape()); |
240 | while (itr.More() && itr.Value().ShapeType() == TopAbs_SOLID) { |
241 | TNaming_Builder aContentBuilder(Content()); |
242 | aContentBuilder.Generated(itr.Value()); |
243 | itr.Next(); |
244 | } |
245 | } |
246 | } |
247 | |