summaryrefslogtreecommitdiff
path: root/src/RWStepShape/RWStepShape_RWEdgeCurve.cxx
blob: 7a569c0c59b100649db5fb666af6a81799ee0532 (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
#include <RWStepShape_RWEdgeCurve.ixx>
#include <StepGeom_Curve.hxx>
#include <StepShape_Vertex.hxx>
#include <StepShape_OrientedEdge.hxx>
#include <StepShape_FaceBound.hxx>
#include <StepShape_VertexPoint.hxx>
#include <StepGeom_CartesianPoint.hxx>

#include <Interface_EntityIterator.hxx>
#include <StepShape_EdgeCurve.hxx>
#include <StepShape_EdgeLoop.hxx>

#include <Precision.hxx>


RWStepShape_RWEdgeCurve::RWStepShape_RWEdgeCurve () {}

void RWStepShape_RWEdgeCurve::ReadStep
	(const Handle(StepData_StepReaderData)& data,
	 const Standard_Integer num,
	 Handle(Interface_Check)& ach,
	 const Handle(StepShape_EdgeCurve)& ent) const
{


	// --- Number of Parameter Control ---

	if (!data->CheckNbParams(num,5,ach,"edge_curve")) return;

	// --- inherited field : name ---

	Handle(TCollection_HAsciiString) aName;
	data->ReadString (num,1,"name",ach,aName);

	// --- inherited field : edgeStart ---

	Handle(StepShape_Vertex) aEdgeStart;
	data->ReadEntity(num, 2,"edge_start", ach, STANDARD_TYPE(StepShape_Vertex), aEdgeStart);

	// --- inherited field : edgeEnd ---

	Handle(StepShape_Vertex) aEdgeEnd;
	data->ReadEntity(num, 3,"edge_end", ach, STANDARD_TYPE(StepShape_Vertex), aEdgeEnd);

	// --- own field : edgeGeometry ---

	Handle(StepGeom_Curve) aEdgeGeometry;
	data->ReadEntity(num, 4,"edge_geometry", ach, STANDARD_TYPE(StepGeom_Curve), aEdgeGeometry);

	// --- own field : sameSense ---

	Standard_Boolean aSameSense;
	data->ReadBoolean (num,5,"same_sense",ach,aSameSense);

	//--- Initialisation of the read entity ---


	ent->Init(aName, aEdgeStart, aEdgeEnd, aEdgeGeometry, aSameSense);
}


void RWStepShape_RWEdgeCurve::WriteStep
	(StepData_StepWriter& SW,
	 const Handle(StepShape_EdgeCurve)& ent) const
{

	// --- inherited field name ---

	SW.Send(ent->Name());

	// --- inherited field edgeStart ---

	SW.Send(ent->EdgeStart());

	// --- inherited field edgeEnd ---

	SW.Send(ent->EdgeEnd());

	// --- own field : edgeGeometry ---

	SW.Send(ent->EdgeGeometry());

	// --- own field : sameSense ---

	SW.SendBoolean(ent->SameSense());
}


void RWStepShape_RWEdgeCurve::Share(const Handle(StepShape_EdgeCurve)& ent, Interface_EntityIterator& iter) const
{

	iter.GetOneItem(ent->EdgeStart());


	iter.GetOneItem(ent->EdgeEnd());


	iter.GetOneItem(ent->EdgeGeometry());
}



void RWStepShape_RWEdgeCurve::Check
  (const Handle(StepShape_EdgeCurve)& ent,
   const Interface_ShareTool& aShto,
   Handle(Interface_Check)& ach) const
{
//  cout << "------ calling CheckEdgeCurve ------" << endl;
  
  Handle(StepShape_OrientedEdge) theOE1, theOE2;
  Handle(StepShape_FaceBound)    theFOB1, theFOB2;
  //Handle(StepShape_FaceSurface)  theFS1, theFS2;

  Standard_Boolean theOEOri1 = Standard_True;
  Standard_Boolean theOEOri2 = Standard_True;
  Standard_Boolean theFBOri1 = Standard_True;
  Standard_Boolean theFBOri2 = Standard_True;
  //Standard_Boolean theFSOri1 = Standard_True;
  //Standard_Boolean theFSOri2 = Standard_True;
  Standard_Boolean Cumulated1, Cumulated2;

  // 1- First Vertex != LastVertex but First VertexPoint == Last VertexPoint
  // Remark : time comsuming process but useful !
  // If this append, we can drop one of the two vertices and replace it 
  // everywhere it is referenced. Side effect : tolerance problem !!!

  Handle(StepShape_VertexPoint) StartVertex = 
    Handle(StepShape_VertexPoint)::DownCast(ent->EdgeStart());
  Handle(StepShape_VertexPoint) EndVertex   = 
    Handle(StepShape_VertexPoint)::DownCast(ent->EdgeEnd());

  if (StartVertex != EndVertex) {

    Handle(StepGeom_CartesianPoint) StartPoint = 
      Handle(StepGeom_CartesianPoint)::DownCast(StartVertex->VertexGeometry());
    Handle(StepGeom_CartesianPoint) EndPoint   = 
      Handle(StepGeom_CartesianPoint)::DownCast(EndVertex->VertexGeometry());

    // it can also be a degenerated pcurve

    if (!StartPoint.IsNull() && !EndPoint.IsNull()) {
      Standard_Real Dist = Sqrt
	((StartPoint->CoordinatesValue(1) - EndPoint->CoordinatesValue(1)) *
	 (StartPoint->CoordinatesValue(1) - EndPoint->CoordinatesValue(1)) +
	 (StartPoint->CoordinatesValue(2) - EndPoint->CoordinatesValue(2)) *
	 (StartPoint->CoordinatesValue(2) - EndPoint->CoordinatesValue(2)) +
	 (StartPoint->CoordinatesValue(3) - EndPoint->CoordinatesValue(3)) *
	 (StartPoint->CoordinatesValue(3) - EndPoint->CoordinatesValue(3)));
      if (Dist < Precision::Confusion() ) {
	ach->AddWarning("Two instances of Vertex have equal (within uncertainty) coordinates");
      }
    }
  }
  
  // 2- Two-Manifold Topology

  Standard_Boolean sharEC = aShto.IsShared(ent);
  Standard_Integer nbRef;
  if(!sharEC){
    ach->AddFail("ERROR: EdgeCurve not referenced");
  }
  else {
    Interface_EntityIterator myShRef = aShto.Sharings(ent);
    myShRef.SelectType (STANDARD_TYPE(StepShape_OrientedEdge),Standard_True);
    nbRef = myShRef.NbEntities();
    if (nbRef ==2) {
      theOE1 = Handle(StepShape_OrientedEdge)::DownCast(myShRef.Value());
      theOEOri1 = theOE1->Orientation();
      myShRef.Next();
      theOE2 = Handle(StepShape_OrientedEdge)::DownCast(myShRef.Value());
      theOEOri2 = theOE2->Orientation();
      
      // get the FaceBound orientation for theOE1
      
      Standard_Boolean sharOE1 = aShto.IsShared(theOE1);
      if(!sharOE1){
#ifdef DEB
	cout << "OrientedEdge1 not shared" <<endl;
#endif
      }
      else {
	myShRef = aShto.Sharings(theOE1);
	myShRef.SelectType (STANDARD_TYPE(StepShape_EdgeLoop),Standard_True);
	nbRef = myShRef.NbEntities();
	if (nbRef == 1) {
	  myShRef.Start();
	  Handle(StepShape_EdgeLoop) theEL1 =
	    Handle(StepShape_EdgeLoop)::DownCast(myShRef.Value());
	  Standard_Boolean sharEL1 = aShto.IsShared(theEL1);
	  if(!sharEL1) {
#ifdef DEB
	    cout << "EdgeLoop1 not shared" <<endl;
#endif
	  }
	  else {
	    myShRef = aShto.Sharings(theEL1);
	    myShRef.SelectType (STANDARD_TYPE(StepShape_FaceBound),Standard_True);
#ifdef DEB
	    nbRef = 
#endif
	      myShRef.NbEntities();
	    myShRef.Start();
	    theFOB1 = Handle(StepShape_FaceBound)::DownCast(myShRef.Value());
	    if (!theFOB1.IsNull()) {
	      theFBOri1 = theFOB1->Orientation();
	    }
	    else {
#ifdef DEB
	      cout << "EdgeLoop not referenced by FaceBound" << endl;
#endif
	    }
	  }
	}
	else {
	  if (nbRef == 0) {
#ifdef DEB
	    cout << "OrientedEdge not referenced" << endl;
#endif
          }
	  else {
	    if (aShto.NbTypedSharings(theOE1,
				      STANDARD_TYPE(StepShape_EdgeLoop)) > 1) {
#ifdef DEB
	      cout << "OrientedEdge referenced more than once" << endl;
#endif
            }
          }
	}
      }

      // get the FaceBound orientation for theOE2

      Standard_Boolean sharOE2 = aShto.IsShared(theOE2);
      if(!sharOE2){
#ifdef DEB
	cout << "OrientedEdge2 not shared" <<endl;
#endif
      }
      else {
	myShRef = aShto.Sharings(theOE2);
#ifdef DEB
// 	Standard_Integer nbRef = 
#endif
// unused	  myShRef.NbEntities();	
	myShRef.Start();
	Handle(StepShape_EdgeLoop) theEL2 =
	  Handle(StepShape_EdgeLoop)::DownCast(myShRef.Value());
	Standard_Boolean sharEL2 = aShto.IsShared(theEL2);
	if(!sharEL2){
#ifdef DEB
	  cout << "EdgeLoop2 not shared" <<endl;
#endif
	}
	else {
	  myShRef = aShto.Sharings(theEL2);
          // unused Standard_Integer nbRef = myShRef.NbEntities();	
	  myShRef.Start();
	  theFOB2 = Handle(StepShape_FaceBound)::DownCast(myShRef.Value());
	  if (!theFOB2.IsNull()) {
	    theFBOri2 = theFOB2->Orientation();
	  }
	  else {
#ifdef DEB
	    cout << "EdgeLoop not referenced by FaceBound" << endl;
#endif
	  }
	}
      }
        
        // "cumulate" the FaceBound and the OrientedEdge orientation
        
        Cumulated1 = theFBOri1 ^ theOEOri1;
      Cumulated2 = theFBOri2 ^ theOEOri2;
      
      // the orientation of the OrientedEdges must be opposite
      
      if (Cumulated1 == Cumulated2) {
	ach->AddFail("ERROR: non 2-manifold topology");
      }
    }
  }
}