0023022: This is desirable to access OpenGl extensions and core API (1.2+) in one...
[occt.git] / src / RWStepShape / RWStepShape_RWEdgeCurve.cxx
CommitLineData
7fd59977 1#include <RWStepShape_RWEdgeCurve.ixx>
2#include <StepGeom_Curve.hxx>
3#include <StepShape_Vertex.hxx>
4#include <StepShape_OrientedEdge.hxx>
5#include <StepShape_FaceBound.hxx>
6#include <StepShape_VertexPoint.hxx>
7#include <StepGeom_CartesianPoint.hxx>
8
9#include <Interface_EntityIterator.hxx>
10#include <StepShape_EdgeCurve.hxx>
11#include <StepShape_EdgeLoop.hxx>
12
13#include <Precision.hxx>
14
15
16RWStepShape_RWEdgeCurve::RWStepShape_RWEdgeCurve () {}
17
18void RWStepShape_RWEdgeCurve::ReadStep
19 (const Handle(StepData_StepReaderData)& data,
20 const Standard_Integer num,
21 Handle(Interface_Check)& ach,
22 const Handle(StepShape_EdgeCurve)& ent) const
23{
24
25
26 // --- Number of Parameter Control ---
27
28 if (!data->CheckNbParams(num,5,ach,"edge_curve")) return;
29
30 // --- inherited field : name ---
31
32 Handle(TCollection_HAsciiString) aName;
33 data->ReadString (num,1,"name",ach,aName);
34
35 // --- inherited field : edgeStart ---
36
37 Handle(StepShape_Vertex) aEdgeStart;
38 data->ReadEntity(num, 2,"edge_start", ach, STANDARD_TYPE(StepShape_Vertex), aEdgeStart);
39
40 // --- inherited field : edgeEnd ---
41
42 Handle(StepShape_Vertex) aEdgeEnd;
43 data->ReadEntity(num, 3,"edge_end", ach, STANDARD_TYPE(StepShape_Vertex), aEdgeEnd);
44
45 // --- own field : edgeGeometry ---
46
47 Handle(StepGeom_Curve) aEdgeGeometry;
48 data->ReadEntity(num, 4,"edge_geometry", ach, STANDARD_TYPE(StepGeom_Curve), aEdgeGeometry);
49
50 // --- own field : sameSense ---
51
52 Standard_Boolean aSameSense;
53 data->ReadBoolean (num,5,"same_sense",ach,aSameSense);
54
55 //--- Initialisation of the read entity ---
56
57
58 ent->Init(aName, aEdgeStart, aEdgeEnd, aEdgeGeometry, aSameSense);
59}
60
61
62void RWStepShape_RWEdgeCurve::WriteStep
63 (StepData_StepWriter& SW,
64 const Handle(StepShape_EdgeCurve)& ent) const
65{
66
67 // --- inherited field name ---
68
69 SW.Send(ent->Name());
70
71 // --- inherited field edgeStart ---
72
73 SW.Send(ent->EdgeStart());
74
75 // --- inherited field edgeEnd ---
76
77 SW.Send(ent->EdgeEnd());
78
79 // --- own field : edgeGeometry ---
80
81 SW.Send(ent->EdgeGeometry());
82
83 // --- own field : sameSense ---
84
85 SW.SendBoolean(ent->SameSense());
86}
87
88
89void RWStepShape_RWEdgeCurve::Share(const Handle(StepShape_EdgeCurve)& ent, Interface_EntityIterator& iter) const
90{
91
92 iter.GetOneItem(ent->EdgeStart());
93
94
95 iter.GetOneItem(ent->EdgeEnd());
96
97
98 iter.GetOneItem(ent->EdgeGeometry());
99}
100
101
102
103void RWStepShape_RWEdgeCurve::Check
104 (const Handle(StepShape_EdgeCurve)& ent,
105 const Interface_ShareTool& aShto,
106 Handle(Interface_Check)& ach) const
107{
108// cout << "------ calling CheckEdgeCurve ------" << endl;
109
110 Handle(StepShape_OrientedEdge) theOE1, theOE2;
111 Handle(StepShape_FaceBound) theFOB1, theFOB2;
112 //Handle(StepShape_FaceSurface) theFS1, theFS2;
113
114 Standard_Boolean theOEOri1 = Standard_True;
115 Standard_Boolean theOEOri2 = Standard_True;
116 Standard_Boolean theFBOri1 = Standard_True;
117 Standard_Boolean theFBOri2 = Standard_True;
118 //Standard_Boolean theFSOri1 = Standard_True;
119 //Standard_Boolean theFSOri2 = Standard_True;
120 Standard_Boolean Cumulated1, Cumulated2;
121
122 // 1- First Vertex != LastVertex but First VertexPoint == Last VertexPoint
123 // Remark : time comsuming process but useful !
124 // If this append, we can drop one of the two vertices and replace it
125 // everywhere it is referenced. Side effect : tolerance problem !!!
126
127 Handle(StepShape_VertexPoint) StartVertex =
128 Handle(StepShape_VertexPoint)::DownCast(ent->EdgeStart());
129 Handle(StepShape_VertexPoint) EndVertex =
130 Handle(StepShape_VertexPoint)::DownCast(ent->EdgeEnd());
131
132 if (StartVertex != EndVertex) {
133
134 Handle(StepGeom_CartesianPoint) StartPoint =
135 Handle(StepGeom_CartesianPoint)::DownCast(StartVertex->VertexGeometry());
136 Handle(StepGeom_CartesianPoint) EndPoint =
137 Handle(StepGeom_CartesianPoint)::DownCast(EndVertex->VertexGeometry());
138
139 // it can also be a degenerated pcurve
140
141 if (!StartPoint.IsNull() && !EndPoint.IsNull()) {
142 Standard_Real Dist = Sqrt
143 ((StartPoint->CoordinatesValue(1) - EndPoint->CoordinatesValue(1)) *
144 (StartPoint->CoordinatesValue(1) - EndPoint->CoordinatesValue(1)) +
145 (StartPoint->CoordinatesValue(2) - EndPoint->CoordinatesValue(2)) *
146 (StartPoint->CoordinatesValue(2) - EndPoint->CoordinatesValue(2)) +
147 (StartPoint->CoordinatesValue(3) - EndPoint->CoordinatesValue(3)) *
148 (StartPoint->CoordinatesValue(3) - EndPoint->CoordinatesValue(3)));
149 if (Dist < Precision::Confusion() ) {
150 ach->AddWarning("Two instances of Vertex have equal (within uncertainty) coordinates");
151 }
152 }
153 }
154
155 // 2- Two-Manifold Topology
156
157 Standard_Boolean sharEC = aShto.IsShared(ent);
158 Standard_Integer nbRef;
159 if(!sharEC){
160 ach->AddFail("ERROR: EdgeCurve not referenced");
161 }
162 else {
163 Interface_EntityIterator myShRef = aShto.Sharings(ent);
164 myShRef.SelectType (STANDARD_TYPE(StepShape_OrientedEdge),Standard_True);
165 nbRef = myShRef.NbEntities();
166 if (nbRef ==2) {
167 theOE1 = Handle(StepShape_OrientedEdge)::DownCast(myShRef.Value());
168 theOEOri1 = theOE1->Orientation();
169 myShRef.Next();
170 theOE2 = Handle(StepShape_OrientedEdge)::DownCast(myShRef.Value());
171 theOEOri2 = theOE2->Orientation();
172
173 // get the FaceBound orientation for theOE1
174
175 Standard_Boolean sharOE1 = aShto.IsShared(theOE1);
176 if(!sharOE1){
177#ifdef DEB
178 cout << "OrientedEdge1 not shared" <<endl;
179#endif
180 }
181 else {
182 myShRef = aShto.Sharings(theOE1);
183 myShRef.SelectType (STANDARD_TYPE(StepShape_EdgeLoop),Standard_True);
184 nbRef = myShRef.NbEntities();
185 if (nbRef == 1) {
186 myShRef.Start();
187 Handle(StepShape_EdgeLoop) theEL1 =
188 Handle(StepShape_EdgeLoop)::DownCast(myShRef.Value());
189 Standard_Boolean sharEL1 = aShto.IsShared(theEL1);
190 if(!sharEL1) {
191#ifdef DEB
192 cout << "EdgeLoop1 not shared" <<endl;
193#endif
194 }
195 else {
196 myShRef = aShto.Sharings(theEL1);
197 myShRef.SelectType (STANDARD_TYPE(StepShape_FaceBound),Standard_True);
198#ifdef DEB
199 nbRef =
200#endif
201 myShRef.NbEntities();
202 myShRef.Start();
203 theFOB1 = Handle(StepShape_FaceBound)::DownCast(myShRef.Value());
204 if (!theFOB1.IsNull()) {
205 theFBOri1 = theFOB1->Orientation();
206 }
207 else {
208#ifdef DEB
209 cout << "EdgeLoop not referenced by FaceBound" << endl;
210#endif
211 }
212 }
213 }
214 else {
215 if (nbRef == 0) {
216#ifdef DEB
217 cout << "OrientedEdge not referenced" << endl;
218#endif
219 }
220 else {
221 if (aShto.NbTypedSharings(theOE1,
222 STANDARD_TYPE(StepShape_EdgeLoop)) > 1) {
223#ifdef DEB
224 cout << "OrientedEdge referenced more than once" << endl;
225#endif
226 }
227 }
228 }
229 }
230
231 // get the FaceBound orientation for theOE2
232
233 Standard_Boolean sharOE2 = aShto.IsShared(theOE2);
234 if(!sharOE2){
235#ifdef DEB
236 cout << "OrientedEdge2 not shared" <<endl;
237#endif
238 }
239 else {
240 myShRef = aShto.Sharings(theOE2);
241#ifdef DEB
242// Standard_Integer nbRef =
243#endif
244// unused myShRef.NbEntities();
245 myShRef.Start();
246 Handle(StepShape_EdgeLoop) theEL2 =
247 Handle(StepShape_EdgeLoop)::DownCast(myShRef.Value());
248 Standard_Boolean sharEL2 = aShto.IsShared(theEL2);
249 if(!sharEL2){
250#ifdef DEB
251 cout << "EdgeLoop2 not shared" <<endl;
252#endif
253 }
254 else {
255 myShRef = aShto.Sharings(theEL2);
256 // unused Standard_Integer nbRef = myShRef.NbEntities();
257 myShRef.Start();
258 theFOB2 = Handle(StepShape_FaceBound)::DownCast(myShRef.Value());
259 if (!theFOB2.IsNull()) {
260 theFBOri2 = theFOB2->Orientation();
261 }
262 else {
263#ifdef DEB
264 cout << "EdgeLoop not referenced by FaceBound" << endl;
265#endif
266 }
267 }
268 }
269
270 // "cumulate" the FaceBound and the OrientedEdge orientation
271
272 Cumulated1 = theFBOri1 ^ theOEOri1;
273 Cumulated2 = theFBOri2 ^ theOEOri2;
274
275 // the orientation of the OrientedEdges must be opposite
276
277 if (Cumulated1 == Cumulated2) {
278 ach->AddFail("ERROR: non 2-manifold topology");
279 }
280 }
281 }
282}
283