1 // Created on: 1994-10-07
2 // Created by: Yves FRICAUD
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <BRepMAT2d_BisectingLocus.hxx>
19 #include <BRepMAT2d_DataMapOfShapeSequenceOfBasicElt.hxx>
20 #include <BRepMAT2d_Explorer.hxx>
21 #include <BRepMAT2d_LinkTopoBilo.hxx>
22 #include <BRepTools_WireExplorer.hxx>
23 #include <Geom2d_CartesianPoint.hxx>
24 #include <Geom2d_Curve.hxx>
25 #include <Geom2d_Geometry.hxx>
26 #include <gp_Pnt2d.hxx>
27 #include <MAT_BasicElt.hxx>
28 #include <MAT_Graph.hxx>
29 #include <MAT_SequenceOfBasicElt.hxx>
30 #include <Precision.hxx>
31 #include <Standard_ConstructionError.hxx>
32 #include <Standard_Type.hxx>
33 #include <TColGeom2d_SequenceOfCurve.hxx>
34 #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
35 #include <TColStd_DataMapOfIntegerInteger.hxx>
38 #include <TopExp_Explorer.hxx>
40 #include <TopoDS_Shape.hxx>
41 #include <TopoDS_Vertex.hxx>
42 #include <TopoDS_Wire.hxx>
43 #include <TopTools_SequenceOfShape.hxx>
45 //=======================================================================
46 //function : BRepMAT2d_LinkTopoBilo
48 //=======================================================================
49 BRepMAT2d_LinkTopoBilo::BRepMAT2d_LinkTopoBilo()
54 //=======================================================================
55 //function : BRepMAT2d_LinkTopoBilo
57 //=======================================================================
59 BRepMAT2d_LinkTopoBilo::BRepMAT2d_LinkTopoBilo(
60 const BRepMAT2d_Explorer& Explo,
61 const BRepMAT2d_BisectingLocus& BiLo)
67 //=======================================================================
70 //=======================================================================
72 void BRepMAT2d_LinkTopoBilo::Perform(const BRepMAT2d_Explorer& Explo,
73 const BRepMAT2d_BisectingLocus& BiLo)
78 TopoDS_Shape S = Explo.Shape();
79 Standard_Integer IndContour = 1;
81 if (S.ShapeType() == TopAbs_FACE) {
82 TopExp_Explorer Exp (S,TopAbs_WIRE);
85 LinkToWire(TopoDS::Wire (Exp.Current()),Explo,IndContour,BiLo);
91 throw Standard_ConstructionError("BRepMAT2d_LinkTopoBilo::Perform");
97 //=======================================================================
100 //=======================================================================
102 void BRepMAT2d_LinkTopoBilo::Init(const TopoDS_Shape& S)
104 isEmpty = Standard_False;
106 if (myMap.IsBound(S)) myKey = S; else isEmpty = Standard_True;
110 //=======================================================================
113 //=======================================================================
115 Standard_Boolean BRepMAT2d_LinkTopoBilo::More()
117 if (isEmpty) return Standard_False;
118 return (current <= myMap(myKey).Length());
122 //=======================================================================
125 //=======================================================================
127 void BRepMAT2d_LinkTopoBilo::Next()
133 //=======================================================================
136 //=======================================================================
138 Handle(MAT_BasicElt) BRepMAT2d_LinkTopoBilo::Value() const
140 return myMap(myKey).Value(current);
143 //=======================================================================
144 //function : GeneratingShape
146 //=======================================================================
148 TopoDS_Shape BRepMAT2d_LinkTopoBilo::GeneratingShape
149 (const Handle(MAT_BasicElt)& BE) const
151 return myBEShape(BE);
154 static void LinkToContour(const BRepMAT2d_Explorer& Explo,
155 const Standard_Integer IndC,
156 const BRepMAT2d_BisectingLocus& BiLo,
157 TColStd_DataMapOfIntegerInteger& Link);
159 //=======================================================================
160 //function : LinkToWire
162 //=======================================================================
164 void BRepMAT2d_LinkTopoBilo::LinkToWire(const TopoDS_Wire& W,
165 const BRepMAT2d_Explorer& Explo,
166 const Standard_Integer IndC,
167 const BRepMAT2d_BisectingLocus& BiLo)
169 BRepTools_WireExplorer TheExp (W);
173 Handle(MAT_BasicElt) BE;
174 Handle(Standard_Type) Type;
175 TopTools_SequenceOfShape TopoSeq;
176 MAT_SequenceOfBasicElt EmptySeq;
178 TColStd_DataMapIteratorOfDataMapOfIntegerInteger Ite;
179 TColStd_DataMapOfIntegerInteger LinkBECont;
182 for (;TheExp.More();TheExp.Next()) {
183 TopoSeq.Append(TheExp.Current());
186 //-----------------------------------------------------
187 // Construction Links BasicElt => Curve of contour IndC.
188 //-----------------------------------------------------
189 LinkToContour(Explo,IndC,BiLo,LinkBECont);
192 //---------------------------------------------------------------
193 // Iteration on BasicElts. The associated index is the same for
194 // the curves of the contour and the edges. .
195 //---------------------------------------------------------------
196 for (Ite.Initialize(LinkBECont); Ite.More(); Ite.Next()) {
197 BE = BiLo.Graph()->BasicElt(Ite.Key());
198 Type = BiLo.GeomElt(BE)->DynamicType();
200 S = TopoSeq.Value(Abs(KC));
202 if (Type == STANDARD_TYPE(Geom2d_CartesianPoint)) {
203 if (S.Orientation() == TopAbs_REVERSED) {
204 TopExp::Vertices(TopoDS::Edge(S),VL,VF);
207 TopExp::Vertices(TopoDS::Edge(S),VF,VL);
209 if (KC > 0) S = VL; else S = VF;
211 if (!myMap.IsBound(S)) {
212 myMap.Bind(S,EmptySeq);
217 myBEShape.Bind(BE, S.Oriented(TopAbs::Reverse(S.Orientation())));
219 myBEShape.Bind(BE, S);
224 //=======================================================================
225 //function : LinkToContour
226 //purpose : Association to each basicElt of the curre of the initial
227 // contour from which it comes.
228 //=======================================================================
230 void LinkToContour (const BRepMAT2d_Explorer& Explo,
231 const Standard_Integer IndC,
232 const BRepMAT2d_BisectingLocus& BiLo,
233 TColStd_DataMapOfIntegerInteger& Link)
235 Handle (MAT_BasicElt) BE;
236 Handle (Geom2d_Geometry) GeomBE;
237 Handle (Standard_Type) Type;
238 Standard_Boolean DirectSense = Standard_True;
239 Standard_Boolean LastPoint = Standard_False;
240 Standard_Integer NbSect,ISect;
242 //---------------------------------------------------
243 // NbSect : number of sections on the current curve.
244 // ISect : Counter on sections.
245 //---------------------------------------------------
247 const TColGeom2d_SequenceOfCurve& Cont = Explo.Contour(IndC);
249 //------------------------------------------------------------------
250 //Initialization of the explorer on the first curve of the contour.
251 //------------------------------------------------------------------
252 Standard_Integer IndOnCont = 1;
253 Standard_Integer PrecIndOnCont = -1;
254 NbSect = BiLo.NumberOfSections(IndC,1);
257 //------------------------------------------------------------------
258 // Parsing of base elements associated to contour IndC.
259 // Rq : the base elements are ordered.
260 //------------------------------------------------------------------
261 for (Standard_Integer i = 1; i <= BiLo.NumberOfElts(IndC); i++) {
263 BE = BiLo.BasicElt(IndC,i);
264 GeomBE = BiLo.GeomElt (BE);
265 Type = GeomBE->DynamicType();
267 if (Type != STANDARD_TYPE(Geom2d_CartesianPoint)) {
269 //----------------------------------------------------------------
270 // The base element is a curve associated with the current curve.
271 //----------------------------------------------------------------
273 Link.Bind(BE->Index(), IndOnCont);
276 Link.Bind(BE->Index(), -IndOnCont);
280 //-----------------------------------------------------------------
281 // The base element is a point associated with the previous curve.
282 //-----------------------------------------------------------------
283 if (DirectSense || LastPoint) {
284 Link.Bind(BE->Index(), PrecIndOnCont);
287 Link.Bind(BE->Index(), -PrecIndOnCont);
291 PrecIndOnCont = IndOnCont;
292 //----------------------------------------------------------------------
293 // Passage to the next curve in Explo, when all parts
294 // of curves corresponding to the initial curve have been parsed.
295 //---------------------------------------------------------------------
296 if (Type != STANDARD_TYPE(Geom2d_CartesianPoint) && ISect == NbSect) {
297 if (IndOnCont < Cont.Length() && DirectSense) {
299 NbSect = BiLo.NumberOfSections(IndC,IndOnCont);
303 //-----------------------------------------------------
304 // For open lines restart in the other direction.
305 //-----------------------------------------------------
308 if (IndOnCont != 0) NbSect = BiLo.NumberOfSections(IndC,IndOnCont);
309 LastPoint = Standard_False;
312 LastPoint = Standard_True;
315 DirectSense = Standard_False;