Commit | Line | Data |
---|---|---|
7fd59977 | 1 | // File: BRepMAT2d_LinkTopoBilo.cxx |
2 | // Created: Fri Oct 7 16:50:40 1994 | |
3 | // Author: Yves FRICAUD | |
4 | // <yfr@nonox> | |
5 | ||
6 | ||
7 | #include <BRepMAT2d_LinkTopoBilo.ixx> | |
8 | #include <TopAbs.hxx> | |
9 | #include <TopExp_Explorer.hxx> | |
10 | #include <TopExp.hxx> | |
11 | #include <TopoDS_Shape.hxx> | |
12 | #include <TopoDS.hxx> | |
13 | #include <TopoDS_Vertex.hxx> | |
14 | #include <TopTools_SequenceOfShape.hxx> | |
15 | #include <Standard_Type.hxx> | |
16 | #include <Geom2d_Geometry.hxx> | |
17 | #include <Geom2d_Curve.hxx> | |
18 | #include <Geom2d_CartesianPoint.hxx> | |
19 | #include <TColGeom2d_SequenceOfCurve.hxx> | |
20 | #include <MAT_Graph.hxx> | |
21 | #include <MAT_BasicElt.hxx> | |
22 | #include <BRepTools_WireExplorer.hxx> | |
23 | #include <BRepMAT2d_SequenceOfBasicElt.hxx> | |
24 | #include <BRepMAT2d_DataMapOfShapeSequenceOfBasicElt.hxx> | |
25 | #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx> | |
26 | #include <TColStd_DataMapOfIntegerInteger.hxx> | |
27 | #include <Precision.hxx> | |
28 | #include <gp_Pnt2d.hxx> | |
29 | ||
30 | ||
31 | //======================================================================= | |
32 | //function : BRepMAT2d_LinkTopoBilo | |
33 | //purpose : | |
34 | //======================================================================= | |
35 | ||
36 | BRepMAT2d_LinkTopoBilo::BRepMAT2d_LinkTopoBilo() | |
37 | { | |
38 | } | |
39 | ||
40 | ||
41 | //======================================================================= | |
42 | //function : BRepMAT2d_LinkTopoBilo | |
43 | //purpose : | |
44 | //======================================================================= | |
45 | ||
46 | BRepMAT2d_LinkTopoBilo::BRepMAT2d_LinkTopoBilo( | |
47 | const BRepMAT2d_Explorer& Explo, | |
48 | const BRepMAT2d_BisectingLocus& BiLo) | |
49 | { | |
50 | Perform (Explo,BiLo); | |
51 | } | |
52 | ||
53 | ||
54 | //======================================================================= | |
55 | //function : Perform | |
56 | //purpose : | |
57 | //======================================================================= | |
58 | ||
59 | void BRepMAT2d_LinkTopoBilo::Perform(const BRepMAT2d_Explorer& Explo, | |
60 | const BRepMAT2d_BisectingLocus& BiLo) | |
61 | { | |
62 | myMap.Clear(); | |
63 | myBEShape.Clear(); | |
64 | ||
65 | TopoDS_Shape S = Explo.Shape(); | |
66 | Standard_Integer IndContour = 1; | |
67 | ||
68 | if (S.ShapeType() == TopAbs_FACE) { | |
69 | TopExp_Explorer Exp (S,TopAbs_WIRE); | |
70 | ||
71 | while (Exp.More()) { | |
72 | LinkToWire(TopoDS::Wire (Exp.Current()),Explo,IndContour,BiLo); | |
73 | Exp.Next(); | |
74 | IndContour++; | |
75 | } | |
76 | } | |
77 | else { | |
78 | Standard_ConstructionError::Raise("BRepMAT2d_LinkTopoBilo::Perform"); | |
79 | } | |
80 | ||
81 | } | |
82 | ||
83 | ||
84 | //======================================================================= | |
85 | //function : Init | |
86 | //purpose : | |
87 | //======================================================================= | |
88 | ||
89 | void BRepMAT2d_LinkTopoBilo::Init(const TopoDS_Shape& S) | |
90 | { | |
91 | isEmpty = Standard_False; | |
92 | current = 1; | |
93 | if (myMap.IsBound(S)) myKey = S; else isEmpty = Standard_True; | |
94 | } | |
95 | ||
96 | ||
97 | //======================================================================= | |
98 | //function : More | |
99 | //purpose : | |
100 | //======================================================================= | |
101 | ||
102 | Standard_Boolean BRepMAT2d_LinkTopoBilo::More() | |
103 | { | |
104 | if (isEmpty) return Standard_False; | |
105 | return (current <= myMap(myKey).Length()); | |
106 | } | |
107 | ||
108 | ||
109 | //======================================================================= | |
110 | //function : Next | |
111 | //purpose : | |
112 | //======================================================================= | |
113 | ||
114 | void BRepMAT2d_LinkTopoBilo::Next() | |
115 | { | |
116 | current++; | |
117 | } | |
118 | ||
119 | ||
120 | //======================================================================= | |
121 | //function : Value | |
122 | //purpose : | |
123 | //======================================================================= | |
124 | ||
125 | Handle(MAT_BasicElt) BRepMAT2d_LinkTopoBilo::Value() const | |
126 | { | |
127 | return myMap(myKey).Value(current); | |
128 | } | |
129 | ||
130 | //======================================================================= | |
131 | //function : GeneratingShape | |
132 | //purpose : | |
133 | //======================================================================= | |
134 | ||
135 | TopoDS_Shape BRepMAT2d_LinkTopoBilo::GeneratingShape | |
136 | (const Handle(MAT_BasicElt)& BE) const | |
137 | { | |
138 | return myBEShape(BE); | |
139 | } | |
140 | ||
141 | static void LinkToContour(const BRepMAT2d_Explorer& Explo, | |
142 | const Standard_Integer IndC, | |
143 | const BRepMAT2d_BisectingLocus& BiLo, | |
144 | TColStd_DataMapOfIntegerInteger& Link); | |
145 | ||
146 | //======================================================================= | |
147 | //function : LinkToWire | |
148 | //purpose : | |
149 | //======================================================================= | |
150 | ||
151 | void BRepMAT2d_LinkTopoBilo::LinkToWire(const TopoDS_Wire& W, | |
152 | const BRepMAT2d_Explorer& Explo, | |
153 | const Standard_Integer IndC, | |
154 | const BRepMAT2d_BisectingLocus& BiLo) | |
155 | { | |
156 | BRepTools_WireExplorer TheExp (W); | |
157 | Standard_Integer KC; | |
158 | TopoDS_Vertex VF,VL; | |
159 | TopoDS_Shape S; | |
160 | Handle(MAT_BasicElt) BE; | |
161 | Handle(Standard_Type) Type; | |
162 | TopTools_SequenceOfShape TopoSeq; | |
163 | BRepMAT2d_SequenceOfBasicElt EmptySeq; | |
164 | ||
165 | TColStd_DataMapIteratorOfDataMapOfIntegerInteger Ite; | |
166 | TColStd_DataMapOfIntegerInteger LinkBECont; | |
167 | ||
168 | ||
169 | for (;TheExp.More();TheExp.Next()) { | |
170 | TopoSeq.Append(TheExp.Current()); | |
171 | } | |
172 | ||
173 | //----------------------------------------------------- | |
0d969553 | 174 | // Construction Links BasicElt => Curve of contour IndC. |
7fd59977 | 175 | //----------------------------------------------------- |
176 | LinkToContour(Explo,IndC,BiLo,LinkBECont); | |
177 | ||
178 | ||
179 | //--------------------------------------------------------------- | |
0d969553 Y |
180 | // Iteration on BasicElts. The associated index is the same for |
181 | // the curves of the contour and the edges. . | |
7fd59977 | 182 | //--------------------------------------------------------------- |
183 | for (Ite.Initialize(LinkBECont); Ite.More(); Ite.Next()) { | |
184 | BE = BiLo.Graph()->BasicElt(Ite.Key()); | |
185 | Type = BiLo.GeomElt(BE)->DynamicType(); | |
186 | KC = Ite.Value(); | |
187 | S = TopoSeq.Value(Abs(KC)); | |
188 | ||
189 | if (Type == STANDARD_TYPE(Geom2d_CartesianPoint)) { | |
190 | if (S.Orientation() == TopAbs_REVERSED) { | |
191 | TopExp::Vertices(TopoDS::Edge(S),VL,VF); | |
192 | } | |
193 | else { | |
194 | TopExp::Vertices(TopoDS::Edge(S),VF,VL); | |
195 | } | |
196 | if (KC > 0) S = VL; else S = VF; | |
197 | } | |
198 | if (!myMap.IsBound(S)) { | |
199 | myMap.Bind(S,EmptySeq); | |
200 | } | |
201 | myMap(S).Append(BE); | |
202 | ||
203 | if (KC < 0) | |
204 | myBEShape.Bind(BE, S.Oriented(TopAbs::Reverse(S.Orientation()))); | |
205 | else | |
206 | myBEShape.Bind(BE, S); | |
207 | } | |
208 | } | |
209 | ||
210 | ||
211 | //======================================================================= | |
212 | //function : LinkToContour | |
0d969553 Y |
213 | //purpose : Association to each basicElt of the curre of the initial |
214 | // contour from which it comes. | |
7fd59977 | 215 | //======================================================================= |
216 | ||
217 | void LinkToContour (const BRepMAT2d_Explorer& Explo, | |
218 | const Standard_Integer IndC, | |
219 | const BRepMAT2d_BisectingLocus& BiLo, | |
220 | TColStd_DataMapOfIntegerInteger& Link) | |
221 | { | |
222 | Handle (MAT_BasicElt) BE; | |
223 | Handle (Geom2d_Geometry) GeomBE; | |
224 | Handle (Standard_Type) Type; | |
225 | Standard_Boolean DirectSense = Standard_True; | |
226 | Standard_Boolean LastPoint = Standard_False; | |
227 | Standard_Integer NbSect,ISect; | |
228 | ||
229 | //--------------------------------------------------- | |
0d969553 Y |
230 | // NbSect : number of sections on the current curve. |
231 | // ISect : Counter on sections. | |
7fd59977 | 232 | //--------------------------------------------------- |
233 | ||
234 | const TColGeom2d_SequenceOfCurve& Cont = Explo.Contour(IndC); | |
235 | ||
236 | //------------------------------------------------------------------ | |
0d969553 | 237 | //Initialization of the explorer on the first curve of the contour. |
7fd59977 | 238 | //------------------------------------------------------------------ |
239 | Standard_Integer IndOnCont = 1; | |
240 | Standard_Integer PrecIndOnCont = -1; | |
241 | NbSect = BiLo.NumberOfSections(IndC,1); | |
242 | ISect = 0; | |
243 | ||
244 | //------------------------------------------------------------------ | |
0d969553 Y |
245 | // Parsing of base elements associated to contour IndC. |
246 | // Rq : the base elements are ordered. | |
7fd59977 | 247 | //------------------------------------------------------------------ |
248 | for (Standard_Integer i = 1; i <= BiLo.NumberOfElts(IndC); i++) { | |
249 | ||
250 | BE = BiLo.BasicElt(IndC,i); | |
251 | GeomBE = BiLo.GeomElt (BE); | |
252 | Type = GeomBE->DynamicType(); | |
253 | ||
254 | if (Type != STANDARD_TYPE(Geom2d_CartesianPoint)) { | |
255 | ISect++; | |
0d969553 Y |
256 | //---------------------------------------------------------------- |
257 | // The base element is a curve associated with the current curve. | |
258 | //---------------------------------------------------------------- | |
7fd59977 | 259 | if (DirectSense) { |
260 | Link.Bind(BE->Index(), IndOnCont); | |
261 | } | |
262 | else { | |
263 | Link.Bind(BE->Index(), -IndOnCont); | |
264 | } | |
265 | } | |
266 | else { | |
0d969553 Y |
267 | //----------------------------------------------------------------- |
268 | // The base element is a point associated with the previous curve. | |
269 | //----------------------------------------------------------------- | |
7fd59977 | 270 | if (DirectSense || LastPoint) { |
271 | Link.Bind(BE->Index(), PrecIndOnCont); | |
272 | } | |
273 | else { | |
274 | Link.Bind(BE->Index(), -PrecIndOnCont); | |
275 | } | |
276 | } | |
277 | ||
278 | PrecIndOnCont = IndOnCont; | |
279 | //---------------------------------------------------------------------- | |
0d969553 Y |
280 | // Passage to the next curve in Explo, when all parts |
281 | // of curves corresponding to the initial curve have been parsed. | |
7fd59977 | 282 | //--------------------------------------------------------------------- |
283 | if (Type != STANDARD_TYPE(Geom2d_CartesianPoint) && ISect == NbSect) { | |
284 | if (IndOnCont < Cont.Length() && DirectSense) { | |
285 | IndOnCont++; | |
286 | NbSect = BiLo.NumberOfSections(IndC,IndOnCont); | |
287 | ISect = 0; | |
288 | } | |
289 | else { | |
290 | //----------------------------------------------------- | |
0d969553 | 291 | // For open lines restart in the other direction. |
7fd59977 | 292 | //----------------------------------------------------- |
293 | if (!DirectSense) { | |
294 | IndOnCont--; | |
295 | if (IndOnCont != 0) NbSect = BiLo.NumberOfSections(IndC,IndOnCont); | |
296 | LastPoint = Standard_False; | |
297 | } | |
298 | else { | |
299 | LastPoint = Standard_True; | |
300 | } | |
301 | ISect = 0; | |
302 | DirectSense = Standard_False; | |
303 | } | |
304 | } | |
305 | } | |
306 | } |