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