summaryrefslogtreecommitdiff
path: root/src/LocOpe/LocOpe_GluedShape.cxx
blob: f0e55c41fce4ddaf8fd4b04117048d7cdc6eb1f4 (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
// File:	LocOpe_GluedShape.cxx
// Created:	Tue Jan 30 13:53:01 1996
// Author:	Jacques GOUSSARD
//		<jag@bravox>


#include <LocOpe_GluedShape.ixx>

#include <TopExp_Explorer.hxx>
#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
#include <TopTools_MapOfShape.hxx>
#include <TopTools_MapIteratorOfMapOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>

#include <TopoDS.hxx>
#include <TopExp.hxx>

#include <Standard_ConstructionError.hxx>

//=======================================================================
//function : LocOpe_GluedShape
//purpose  : 
//=======================================================================

LocOpe_GluedShape::LocOpe_GluedShape ()
{}


//=======================================================================
//function : LocOpe_GluedShape
//purpose  : 
//=======================================================================

LocOpe_GluedShape::LocOpe_GluedShape(const TopoDS_Shape& S) :
   myShape(S)
{}
  

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

void LocOpe_GluedShape::Init(const TopoDS_Shape& S)
{
  myShape = S;
  myMap.Clear();
  myGShape.Clear();
  myList.Clear();
  myGEdges.Clear();
}


//=======================================================================
//function : GlueOnFace
//purpose  : 
//=======================================================================

void LocOpe_GluedShape::GlueOnFace(const TopoDS_Face& F)
{
//  for (TopExp_Explorer exp(myShape,TopAbs_FACE); exp.More();exp.Next()) {
  TopExp_Explorer exp(myShape,TopAbs_FACE) ;
  for ( ; exp.More();exp.Next()) {
    if (exp.Current().IsSame(F)) {
      break;
    }
  }
  if (!exp.More()) {
    Standard_ConstructionError::Raise();
  }
  myMap.Add(exp.Current()); // bonne orientation
}


//=======================================================================
//function : MapEdgeAndVertices
//purpose  : 
//=======================================================================

void LocOpe_GluedShape::MapEdgeAndVertices()
{
  if (!myGShape.IsEmpty()) {
    return;
  }


  // Edges et faces generes

  TopTools_IndexedDataMapOfShapeListOfShape theMapEF;
  TopExp::MapShapesAndAncestors(myShape,TopAbs_EDGE, TopAbs_FACE, theMapEF);

  TopTools_MapOfShape mapdone;
  TopTools_MapIteratorOfMapOfShape itm(myMap);
  TopTools_ListIteratorOfListOfShape itl;
  TopExp_Explorer exp,exp2,exp3;

  for (; itm.More(); itm.Next()) {
    const TopoDS_Face& fac = TopoDS::Face(itm.Key());
    for (exp.Init(fac,TopAbs_EDGE); exp.More(); exp.Next()) {
      const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
      if (mapdone.Contains(edg)) {
	continue;
      }
      // Est-ce un edge de connexite entre les faces collees
      if (theMapEF.FindFromKey(edg).Extent() != 2) {
	Standard_ConstructionError::Raise();
      }
      for (itl.Initialize(theMapEF.FindFromKey(edg)); itl.More(); itl.Next()) {
	if (!myMap.Contains(itl.Value())) {
	  break;
	}
      }

      if (itl.More()) {
//	myGEdges.Append(edg);
	myGEdges.Append(edg.Reversed());
	myGShape.Bind(edg,itl.Value()); // voir orientation, 
	                              //mais devrait etre bon
      }

      mapdone.Add(edg);
    }
  }

  for (itl.Initialize(myGEdges); itl.More(); itl.Next()) {
    const TopoDS_Edge& edg = TopoDS::Edge(itl.Value());
    for (exp.Init(edg,TopAbs_VERTEX); exp.More(); exp.Next()) {
      const TopoDS_Vertex& vtx = TopoDS::Vertex(exp.Current());
      if (myGShape.IsBound(vtx)) {
	continue;
      }
      for (exp2.Init(myGShape(edg),TopAbs_EDGE);exp2.More();exp2.Next()) {
	if (exp2.Current().IsSame(edg)) {
	  continue;
	}
	for (exp3.Init(exp2.Current(),TopAbs_VERTEX); 
	     exp3.More(); exp3.Next()) {
	  if (exp3.Current().IsSame(vtx)) {
	    if (myGShape.IsBound(exp2.Current())) {
	      myGShape.Bind(vtx,TopoDS_Edge());
	    }
	    else {
	      myGShape.Bind(vtx,exp2.Current());
	    }
	    break;
	  }
	}
	if (exp3.More()) {
	  break;
	}
      }
    }
  }

  // liste de faces

  for (exp.Init(myShape,TopAbs_FACE); exp.More(); exp.Next()) {
    if (!myMap.Contains(exp.Current())) {
      myList.Append(exp.Current());
    }
  }
}




//=======================================================================
//function : GeneratingEdges
//purpose  : 
//=======================================================================

const TopTools_ListOfShape& LocOpe_GluedShape::GeneratingEdges()
{
  if (myGShape.IsEmpty()) {
    MapEdgeAndVertices();
  }
  return myGEdges;
}


//=======================================================================
//function : Generated
//purpose  : 
//=======================================================================

TopoDS_Edge LocOpe_GluedShape::Generated(const TopoDS_Vertex& V)
{
  if (myGShape.IsEmpty()) {
    MapEdgeAndVertices();
  }
  return TopoDS::Edge(myGShape(V));
}


//=======================================================================
//function : Generated
//purpose  : 
//=======================================================================

TopoDS_Face LocOpe_GluedShape::Generated(const TopoDS_Edge& E)
{
  if (myGShape.IsEmpty()) {
    MapEdgeAndVertices();
  }
  return TopoDS::Face(myGShape(E));
}


//=======================================================================
//function : OrientedFaces
//purpose  : 
//=======================================================================

const TopTools_ListOfShape& LocOpe_GluedShape::OrientedFaces()
{
  if (myGShape.IsEmpty()) {
    MapEdgeAndVertices();
  }
  return myList;
}