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