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