summaryrefslogtreecommitdiff
path: root/src/BRepMAT2d/BRepMAT2d_LinkTopoBilo.cxx
blob: 891efa36a52915c81732077d78c8fe23c154ef7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
// File:	BRepMAT2d_LinkTopoBilo.cxx
// Created:	Fri Oct  7 16:50:40 1994
// Author:	Yves FRICAUD
//		<yfr@nonox>


#include <BRepMAT2d_LinkTopoBilo.ixx>
#include <TopAbs.hxx>
#include <TopExp_Explorer.hxx>
#include <TopExp.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Vertex.hxx> 
#include <TopTools_SequenceOfShape.hxx>
#include <Standard_Type.hxx>
#include <Geom2d_Geometry.hxx>
#include <Geom2d_Curve.hxx>
#include <Geom2d_CartesianPoint.hxx>
#include <TColGeom2d_SequenceOfCurve.hxx>
#include <MAT_Graph.hxx>
#include <MAT_BasicElt.hxx>
#include <BRepTools_WireExplorer.hxx>
#include <BRepMAT2d_SequenceOfBasicElt.hxx>
#include <BRepMAT2d_DataMapOfShapeSequenceOfBasicElt.hxx>
#include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
#include <TColStd_DataMapOfIntegerInteger.hxx>
#include <Precision.hxx>
#include <gp_Pnt2d.hxx>


//=======================================================================
//function : BRepMAT2d_LinkTopoBilo
//purpose  : 
//=======================================================================

BRepMAT2d_LinkTopoBilo::BRepMAT2d_LinkTopoBilo()
{
}


//=======================================================================
//function : BRepMAT2d_LinkTopoBilo
//purpose  : 
//=======================================================================

BRepMAT2d_LinkTopoBilo::BRepMAT2d_LinkTopoBilo(
   const BRepMAT2d_Explorer&       Explo,
   const BRepMAT2d_BisectingLocus& BiLo)
{
  Perform (Explo,BiLo);
}


//=======================================================================
//function : Perform
//purpose  : 
//=======================================================================

void BRepMAT2d_LinkTopoBilo::Perform(const BRepMAT2d_Explorer&       Explo, 
				     const BRepMAT2d_BisectingLocus& BiLo)
{
  myMap.Clear();
  myBEShape.Clear();

  TopoDS_Shape     S          = Explo.Shape();
  Standard_Integer IndContour = 1;

  if (S.ShapeType() == TopAbs_FACE) {
    TopExp_Explorer  Exp (S,TopAbs_WIRE);
    
    while (Exp.More()) {
      LinkToWire(TopoDS::Wire (Exp.Current()),Explo,IndContour,BiLo);
      Exp.Next();
      IndContour++;
    }
  }
  else {
    Standard_ConstructionError::Raise("BRepMAT2d_LinkTopoBilo::Perform");
  }
  
}


//=======================================================================
//function : Init
//purpose  : 
//=======================================================================

void BRepMAT2d_LinkTopoBilo::Init(const TopoDS_Shape& S)
{
  isEmpty = Standard_False;
  current = 1;
  if (myMap.IsBound(S)) myKey = S; else isEmpty = Standard_True;
}


//=======================================================================
//function : More
//purpose  : 
//=======================================================================

Standard_Boolean  BRepMAT2d_LinkTopoBilo::More()
{
  if (isEmpty) return Standard_False;
  return (current <=  myMap(myKey).Length());
}


//=======================================================================
//function : Next
//purpose  : 
//=======================================================================

void BRepMAT2d_LinkTopoBilo::Next()
{
  current++;
}


//=======================================================================
//function : Value
//purpose  : 
//=======================================================================

Handle(MAT_BasicElt) BRepMAT2d_LinkTopoBilo::Value() const 
{
  return myMap(myKey).Value(current);
}

//=======================================================================
//function : GeneratingShape
//purpose  : 
//=======================================================================

TopoDS_Shape  BRepMAT2d_LinkTopoBilo::GeneratingShape
(const Handle(MAT_BasicElt)& BE) const
{
  return myBEShape(BE);
}

static void LinkToContour(const BRepMAT2d_Explorer&              Explo,
			  const Standard_Integer                 IndC,
			  const BRepMAT2d_BisectingLocus&        BiLo,
			        TColStd_DataMapOfIntegerInteger& Link);

//=======================================================================
//function : LinkToWire
//purpose  : 
//=======================================================================

void BRepMAT2d_LinkTopoBilo::LinkToWire(const TopoDS_Wire&              W,
					const BRepMAT2d_Explorer&       Explo, 
					const Standard_Integer          IndC,
					const BRepMAT2d_BisectingLocus& BiLo)
{
  BRepTools_WireExplorer       TheExp (W);
  Standard_Integer             KC;
  TopoDS_Vertex                VF,VL;
  TopoDS_Shape                 S;
  Handle(MAT_BasicElt)         BE;
  Handle(Standard_Type)        Type;
  TopTools_SequenceOfShape     TopoSeq;
  BRepMAT2d_SequenceOfBasicElt EmptySeq;

  TColStd_DataMapIteratorOfDataMapOfIntegerInteger Ite;
  TColStd_DataMapOfIntegerInteger LinkBECont;


  for (;TheExp.More();TheExp.Next()) {
    TopoSeq.Append(TheExp.Current());
  }
  
  //-----------------------------------------------------
  // Construction Liens BasicElt => Curve du contour IndC.
  //-----------------------------------------------------
  LinkToContour(Explo,IndC,BiLo,LinkBECont);
  

  //---------------------------------------------------------------
  // Iteration sur les BasicElts. L indice associe est le meme pour
  // les courbes du contour et les edges.               .
  //---------------------------------------------------------------
  for (Ite.Initialize(LinkBECont); Ite.More(); Ite.Next()) {
    BE     = BiLo.Graph()->BasicElt(Ite.Key());    
    Type   = BiLo.GeomElt(BE)->DynamicType();
    KC     = Ite.Value();
    S      = TopoSeq.Value(Abs(KC));

    if (Type == STANDARD_TYPE(Geom2d_CartesianPoint)) {
      if (S.Orientation() == TopAbs_REVERSED) {
	TopExp::Vertices(TopoDS::Edge(S),VL,VF);
      }
      else {
	TopExp::Vertices(TopoDS::Edge(S),VF,VL);
      }
      if (KC > 0) S = VL; else S = VF;
    }
    if (!myMap.IsBound(S)) {       
      myMap.Bind(S,EmptySeq);
    }
    myMap(S).Append(BE);

    if (KC < 0) 
      myBEShape.Bind(BE, S.Oriented(TopAbs::Reverse(S.Orientation())));
    else
      myBEShape.Bind(BE, S);
  }
}


//=======================================================================
//function : LinkToContour
//purpose  : Association a chaque basicElt de la courbe du contour initial
//           dont il provient.
//=======================================================================

void LinkToContour (const BRepMAT2d_Explorer&              Explo,
		    const Standard_Integer                 IndC,
		    const BRepMAT2d_BisectingLocus&        BiLo,
		    TColStd_DataMapOfIntegerInteger&       Link)
{
  Handle (MAT_BasicElt)    BE;
  Handle (Geom2d_Geometry) GeomBE;
  Handle (Standard_Type)   Type;
  Standard_Boolean         DirectSense   = Standard_True;
  Standard_Boolean         LastPoint     = Standard_False;
  Standard_Integer         NbSect,ISect;     

  //---------------------------------------------------
  // NbSect : nombre de sections sur la courbe courrant.
  // ISect  : Compteur sur les sections.
  //---------------------------------------------------

  const TColGeom2d_SequenceOfCurve&  Cont = Explo.Contour(IndC);
  
  //------------------------------------------------------------------
  //Initialisation de l explorateur sur la premiere courbe du contour.
  //------------------------------------------------------------------
  Standard_Integer         IndOnCont     =  1;   
  Standard_Integer         PrecIndOnCont = -1;
  NbSect = BiLo.NumberOfSections(IndC,1);
  ISect  = 0;

  //------------------------------------------------------------------
  // Parcours des elements de base associes au contour IndC.
  // Rq : les elements de base sont ordonnes.
  //------------------------------------------------------------------
  for (Standard_Integer i = 1; i <= BiLo.NumberOfElts(IndC); i++) {

    BE     = BiLo.BasicElt(IndC,i);
    GeomBE = BiLo.GeomElt (BE);
    Type   = GeomBE->DynamicType();

    if (Type != STANDARD_TYPE(Geom2d_CartesianPoint)) {
      ISect++;
      //--------------------------------------------------------------------
      // l element de base est une courbe on lui associe la courbe courante.
      //--------------------------------------------------------------------
      if (DirectSense) {
	Link.Bind(BE->Index(),  IndOnCont);
      }
      else {
	Link.Bind(BE->Index(), -IndOnCont);
      }
    }
    else {      
      //--------------------------------------------------------------------
      // l element de base est un point on lui associe la courbe precedente
      //--------------------------------------------------------------------
      if (DirectSense || LastPoint) {
	Link.Bind(BE->Index(),  PrecIndOnCont);
      }
      else {
	Link.Bind(BE->Index(), -PrecIndOnCont);
      }
    }

    PrecIndOnCont = IndOnCont;
    //----------------------------------------------------------------------
    // Passage a la courbe suivante dans Explo, lorsqu on a parcouru toutes
    // les portions de courbes correspondante a la courbe initiale.
    //---------------------------------------------------------------------
    if (Type != STANDARD_TYPE(Geom2d_CartesianPoint) && ISect == NbSect) {
      if (IndOnCont < Cont.Length() && DirectSense) {
	IndOnCont++;  
	NbSect = BiLo.NumberOfSections(IndC,IndOnCont);
	ISect  = 0;
      }
      else {
	//-----------------------------------------------------
	// Pour les lignes ouvertes on repart dans l autre sens.
	//-----------------------------------------------------
	if (!DirectSense) {
	  IndOnCont--;
	  if (IndOnCont != 0) NbSect = BiLo.NumberOfSections(IndC,IndOnCont);
	  LastPoint = Standard_False;
	}
	else {
	  LastPoint = Standard_True;
	}
	ISect       = 0;
	DirectSense = Standard_False;
      }
    }
  }
}