0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / BRepMAT2d / BRepMAT2d_BisectingLocus.cxx
CommitLineData
b311480e 1// Created on: 1993-07-13
2// Created by: Yves FRICAUD
3// Copyright (c) 1993-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
7fd59977 17
42cf5bc1 18#include <Bisector_Bisec.hxx>
19#include <BRepMAT2d_BisectingLocus.hxx>
20#include <BRepMAT2d_Explorer.hxx>
21#include <Geom2d_Geometry.hxx>
22#include <Geom2d_TrimmedCurve.hxx>
23#include <gp_Pnt2d.hxx>
24#include <MAT2d_BiInt.hxx>
25#include <MAT2d_Circuit.hxx>
26#include <MAT2d_CutCurve.hxx>
27#include <MAT2d_Mat2d.hxx>
28#include <MAT2d_SequenceOfSequenceOfGeometry.hxx>
29#include <MAT2d_Tool2d.hxx>
42cf5bc1 30#include <MAT_BasicElt.hxx>
42cf5bc1 31#include <MAT_DataMapOfIntegerBasicElt.hxx>
32#include <MAT_Graph.hxx>
33#include <MAT_ListOfBisector.hxx>
34#include <MAT_Node.hxx>
35#include <Precision.hxx>
42cf5bc1 36#include <TColGeom2d_SequenceOfGeometry.hxx>
92efcf78 37#include <Geom2d_Curve.hxx>
7fd59977 38
39static void CutSketch (MAT2d_SequenceOfSequenceOfGeometry& Figure,
40 MAT2d_DataMapOfBiIntInteger& NbSect);
41
42
43//=============================================================================
47cbf134 44//function : BRepMAT2d_BisectingLocus
7fd59977 45//purpose : Constructeur vide.
46//=============================================================================
47cbf134 47BRepMAT2d_BisectingLocus::BRepMAT2d_BisectingLocus()
d533dafb 48: isDone(Standard_False),
49 nbContours(0)
7fd59977 50{
51}
52
53
54//=============================================================================
55//function : Compute
56//purpose : Calcul de la carte des lieux bisecteurs sur le contour defini par
57// <anExplo>.
58//=============================================================================
6a442250 59void BRepMAT2d_BisectingLocus::Compute(BRepMAT2d_Explorer& anExplo,
60 const Standard_Integer IndexLine,
61 const MAT_Side aSide,
c19dd45e 62 const GeomAbs_JoinType aJoinType,
6a442250 63 const Standard_Boolean IsOpenResult)
7fd59977 64{
0e0f7a7c 65 MAT2d_Mat2d TheMAT( IsOpenResult );
7fd59977 66 Handle(MAT_ListOfBisector) TheRoots = new MAT_ListOfBisector();
67 MAT2d_SequenceOfSequenceOfGeometry Figure;
68 Standard_Integer i;
69
70 nbSect.Clear();
6b121e2b 71 theGraph = new MAT_Graph();
7fd59977 72 nbContours = anExplo.NumberOfContours();
6b121e2b 73 if (nbContours == 0)
74 {
75 return;
76 }
7fd59977 77
78 //---------------------------------
79 // Lecture des donnees de anExplo.
80 //---------------------------------
81 for (i = 1; i <= anExplo.NumberOfContours(); i++) {
82 TColGeom2d_SequenceOfGeometry Line;
83 Figure.Append(Line);
84 for (anExplo.Init(i); anExplo.More(); anExplo.Next()) {
85 Figure.ChangeValue(i).Append(anExplo.Value());
86 }
87 }
88
89 //-----------------------
90 // Decoupage des courbes.
91 //-----------------------
92 CutSketch(Figure,nbSect);
93
94 //----------------------------------------------------------
95 // Construction du circuit sur lequel est calcule la carte.
96 //----------------------------------------------------------
c19dd45e 97 Handle(MAT2d_Circuit) ACircuit = new MAT2d_Circuit(aJoinType, IsOpenResult);
7fd59977 98// Modified by Sergey KHROMOV - Wed Mar 6 17:43:47 2002 Begin
99// ACircuit->Perform(Figure,IndexLine,(aSide == MAT_Left));
100 ACircuit->Perform(Figure,anExplo.GetIsClosed(), IndexLine,(aSide == MAT_Left));
101// Modified by Sergey KHROMOV - Wed Mar 6 17:43:48 2002 End
102
103 // -----------------------
104 // Initialistion du Tool.
105 // -----------------------
106 theTool.Sense(aSide);
c19dd45e 107 theTool.SetJoinType(aJoinType);
7fd59977 108 theTool.InitItems(ACircuit);
109
110 // --------------------------------------------
111 // Initialisation et execution de l algorithme.
112 // --------------------------------------------
0e0f7a7c 113 if (IsOpenResult)
114 TheMAT.CreateMatOpen(theTool);
115 else
116 TheMAT.CreateMat(theTool);
7fd59977 117
118 isDone = TheMAT.IsDone(); if (!isDone) return;
119
120 // ----------------------------------------------------------------
121 // Recuperation du resultat de l algorithme et creation du graphe.
122 // ----------------------------------------------------------------
123 for (TheMAT.Init(); TheMAT.More(); TheMAT.Next()) {
124 TheRoots->BackAdd(TheMAT.Bisector());
125 }
126
7fd59977 127 theGraph->Perform(TheMAT.SemiInfinite(),
128 TheRoots,
129 theTool.NumberOfItems(),
130 TheMAT.NumberOfBisectors());
131
132 //-----------------------------------------------------------------------
133 // Fusion des elements de base doubles si plusieurs lignes dans Exploset.
134 //-----------------------------------------------------------------------
135 if (anExplo.NumberOfContours() > 1) {
136 MAT_DataMapOfIntegerBasicElt NewMap;
137 Standard_Integer IndexLast = 1;
138
139 //-----------------------------------------------------------------------
140 // Construction de NewMap dont les elements sont ordonnes suivant les
141 // lignes du contour et qui ne contient pas d element dupliques.
142 // em meme temps fusion des arcs dupliques et mise a jour des noeuds.
143 //-----------------------------------------------------------------------
144 for ( i = 1; i <= anExplo.NumberOfContours(); i++) {
145 RenumerationAndFusion(i,
146 theTool.Circuit()->LineLength(i),
147 IndexLast,
148 NewMap);
149 }
150
151 //-----------------------------------------------------------------------
152 // Chargement dans le graph de la nouvelle map.
153 // et compactage de la map des Arcs (ie Elimination des trous du a la
154 // fusion d arcs ).et de celle des Nodes.
155 //-----------------------------------------------------------------------
156 theGraph->ChangeBasicElts(NewMap);
157 theGraph->CompactArcs();
158 theGraph->CompactNodes();
159 }
160}
161
162//=============================================================================
163//function : RenumerationAndFusion
164//purpose :
165//=============================================================================
47cbf134 166void BRepMAT2d_BisectingLocus::RenumerationAndFusion
7fd59977 167 (const Standard_Integer ILine,
168 const Standard_Integer LengthLine,
169 Standard_Integer& IndexLast,
170 MAT_DataMapOfIntegerBasicElt& NewMap)
171{
172 Standard_Integer IndFirst;
173 Standard_Integer i,j;
174 Standard_Integer GeomIndexArc1,GeomIndexArc2,GeomIndexArc3,GeomIndexArc4;
175 Standard_Boolean MergeArc1,MergeArc2;
176
177 for ( i = 1; i <= LengthLine; i++) {
178 const TColStd_SequenceOfInteger& S = theTool.Circuit()->RefToEqui(ILine,i);
179
180 IndFirst = S.Value(1);
181 NewMap.Bind(IndexLast,theGraph->ChangeBasicElt(IndFirst));
182 IndexLast++;
183
184 for(j = 2; j <= S.Length(); j++){
185 theGraph->FusionOfBasicElts(IndFirst,
186 S.Value(j),
187 MergeArc1,
188 GeomIndexArc1,
189 GeomIndexArc2,
190 MergeArc2,
191 GeomIndexArc3,
192 GeomIndexArc4);
193 if(MergeArc1) {
194 theTool.BisecFusion(GeomIndexArc1,GeomIndexArc2);
195 }
196 if(MergeArc2) {
197 theTool.BisecFusion(GeomIndexArc3,GeomIndexArc4);
198 }
199 }
200 }
201}
202
203//=============================================================================
204//function : IsDone
205//Purpose :
206//=============================================================================
47cbf134 207Standard_Boolean BRepMAT2d_BisectingLocus::IsDone() const
7fd59977 208{
209 return isDone;
210}
211
212//=============================================================================
213//function : Graph
214//
215//=============================================================================
47cbf134 216Handle(MAT_Graph) BRepMAT2d_BisectingLocus::Graph() const
7fd59977 217{
218 return theGraph;
219}
220
221//=============================================================================
222//function : NumberOfContours
223//
224//=============================================================================
47cbf134 225Standard_Integer BRepMAT2d_BisectingLocus::NumberOfContours () const
7fd59977 226{
227 return nbContours;
228}
229
230//=============================================================================
231//function : NumberOfElts
232//
233//=============================================================================
47cbf134 234Standard_Integer BRepMAT2d_BisectingLocus::NumberOfElts
7fd59977 235 (const Standard_Integer IndLine) const
236{
237 return theTool.Circuit()->LineLength(IndLine);
238}
239
240//=============================================================================
241//function : NumberOfSect
242//
243//=============================================================================
47cbf134 244Standard_Integer BRepMAT2d_BisectingLocus::NumberOfSections
7fd59977 245(const Standard_Integer IndLine,
246 const Standard_Integer Index )
247 const
248{
249 MAT2d_BiInt B(IndLine,Index);
250 return nbSect(B);
251}
252
253//=============================================================================
254//function : BasicElt
255//
256//=============================================================================
47cbf134 257Handle(MAT_BasicElt) BRepMAT2d_BisectingLocus::BasicElt
7fd59977 258 (const Standard_Integer IndLine,
259 const Standard_Integer Index )
260 const
261{
262 Standard_Integer i;
263 Standard_Integer Ind = Index;
264
265 for (i = 1 ; i < IndLine ; i++){
266 Ind = Ind + theTool.Circuit()->LineLength(i);
267 }
268 return theGraph->BasicElt(Ind);
269}
270
271
272//=============================================================================
273//function : GeomBis
274//
275//=============================================================================
47cbf134 276Bisector_Bisec BRepMAT2d_BisectingLocus::GeomBis (const Handle(MAT_Arc)& anArc,
7fd59977 277 Standard_Boolean& Reverse)
278const
279{
280 Reverse = Standard_False;
281
5b111128 282 Handle(Geom2d_Curve) Bis (theTool.GeomBis(anArc->GeomIndex()).Value());
7fd59977 283
284 if (Bis->FirstParameter() <= -Precision::Infinite()) {
285 Reverse = Standard_True;
286 }
287 else if (Bis->LastParameter() < Precision::Infinite()) {
288 gp_Pnt2d PF = Bis->Value(Bis->FirstParameter());
289 gp_Pnt2d PL = Bis->Value(Bis->LastParameter());
290 gp_Pnt2d PNode = GeomElt(anArc->FirstNode());
291 if (PNode.SquareDistance(PF) > PNode.SquareDistance(PL))
292 Reverse = Standard_True;
293 }
294 return theTool.GeomBis(anArc->GeomIndex());
295}
296
297//=============================================================================
298//function : GeomElt
299//
300//=============================================================================
47cbf134 301Handle(Geom2d_Geometry) BRepMAT2d_BisectingLocus::GeomElt
7fd59977 302 (const Handle(MAT_BasicElt)& aBasicElt) const
303{
304 return theTool.GeomElt(aBasicElt->GeomIndex());
305}
306
307
308//=============================================================================
309//function : GeomElt
310//
311//=============================================================================
47cbf134 312gp_Pnt2d BRepMAT2d_BisectingLocus::GeomElt(const Handle(MAT_Node)& aNode) const
7fd59977 313{
314 return theTool.GeomPnt(aNode->GeomIndex());
315}
316
317
318//=============================================================================
319//function : CutSketch
320//
321//=============================================================================
322static void CutSketch (MAT2d_SequenceOfSequenceOfGeometry& Figure,
323 MAT2d_DataMapOfBiIntInteger& NbSect)
324{
325 MAT2d_CutCurve Cuter;
326 Standard_Integer i,j,k,ico;
327 Standard_Integer ICurveInit;
328 Standard_Integer NbSection;
329
330 for ( i = 1; i <= Figure.Length(); i++) {
331 TColGeom2d_SequenceOfGeometry& Contour = Figure.ChangeValue(i);
332 ICurveInit = 0;
333
334 for ( j = 1; j <= Contour.Length(); j++) {
335 ICurveInit++;
336 Cuter.Perform(Handle(Geom2d_Curve)::DownCast(Contour.ChangeValue(j)));
337 NbSection = 1;
338 if (!Cuter.UnModified()) {
339 ico = j;
340 NbSection = Cuter.NbCurves();
341 for ( k = 1; k <= NbSection; k++) {
342 Contour.InsertAfter(j,Cuter.Value(k));
343 j++;
344 }
345 Contour.Remove(ico);
346 j--;
347 }
348 MAT2d_BiInt B(i,ICurveInit);
349 NbSect.Bind(B,NbSection);
350 }
351 }
352}
353