1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <Interface_Check.hxx>
16 #include <Interface_EntityIterator.hxx>
17 #include <Interface_ShareTool.hxx>
18 #include <Precision.hxx>
19 #include <RWStepShape_RWEdgeCurve.hxx>
20 #include <StepData_StepReaderData.hxx>
21 #include <StepData_StepWriter.hxx>
22 #include <StepGeom_CartesianPoint.hxx>
23 #include <StepGeom_Curve.hxx>
24 #include <StepShape_EdgeCurve.hxx>
25 #include <StepShape_EdgeLoop.hxx>
26 #include <StepShape_FaceBound.hxx>
27 #include <StepShape_OrientedEdge.hxx>
28 #include <StepShape_Vertex.hxx>
29 #include <StepShape_VertexPoint.hxx>
31 RWStepShape_RWEdgeCurve::RWStepShape_RWEdgeCurve () {}
33 void RWStepShape_RWEdgeCurve::ReadStep
34 (const Handle(StepData_StepReaderData)& data,
35 const Standard_Integer num,
36 Handle(Interface_Check)& ach,
37 const Handle(StepShape_EdgeCurve)& ent) const
41 // --- Number of Parameter Control ---
43 if (!data->CheckNbParams(num,5,ach,"edge_curve")) return;
45 // --- inherited field : name ---
47 Handle(TCollection_HAsciiString) aName;
48 data->ReadString (num,1,"name",ach,aName);
50 // --- inherited field : edgeStart ---
52 Handle(StepShape_Vertex) aEdgeStart;
53 data->ReadEntity(num, 2,"edge_start", ach, STANDARD_TYPE(StepShape_Vertex), aEdgeStart);
55 // --- inherited field : edgeEnd ---
57 Handle(StepShape_Vertex) aEdgeEnd;
58 data->ReadEntity(num, 3,"edge_end", ach, STANDARD_TYPE(StepShape_Vertex), aEdgeEnd);
60 // --- own field : edgeGeometry ---
62 Handle(StepGeom_Curve) aEdgeGeometry;
63 data->ReadEntity(num, 4,"edge_geometry", ach, STANDARD_TYPE(StepGeom_Curve), aEdgeGeometry);
65 // --- own field : sameSense ---
67 Standard_Boolean aSameSense;
68 data->ReadBoolean (num,5,"same_sense",ach,aSameSense);
70 //--- Initialisation of the read entity ---
73 ent->Init(aName, aEdgeStart, aEdgeEnd, aEdgeGeometry, aSameSense);
77 void RWStepShape_RWEdgeCurve::WriteStep
78 (StepData_StepWriter& SW,
79 const Handle(StepShape_EdgeCurve)& ent) const
82 // --- inherited field name ---
86 // --- inherited field edgeStart ---
88 SW.Send(ent->EdgeStart());
90 // --- inherited field edgeEnd ---
92 SW.Send(ent->EdgeEnd());
94 // --- own field : edgeGeometry ---
96 SW.Send(ent->EdgeGeometry());
98 // --- own field : sameSense ---
100 SW.SendBoolean(ent->SameSense());
104 void RWStepShape_RWEdgeCurve::Share(const Handle(StepShape_EdgeCurve)& ent, Interface_EntityIterator& iter) const
107 iter.GetOneItem(ent->EdgeStart());
110 iter.GetOneItem(ent->EdgeEnd());
113 iter.GetOneItem(ent->EdgeGeometry());
118 void RWStepShape_RWEdgeCurve::Check
119 (const Handle(StepShape_EdgeCurve)& ent,
120 const Interface_ShareTool& aShto,
121 Handle(Interface_Check)& ach) const
123 // std::cout << "------ calling CheckEdgeCurve ------" << std::endl;
125 Handle(StepShape_OrientedEdge) theOE1, theOE2;
126 Handle(StepShape_FaceBound) theFOB1, theFOB2;
127 //Handle(StepShape_FaceSurface) theFS1, theFS2;
129 Standard_Boolean theOEOri1 = Standard_True;
130 Standard_Boolean theOEOri2 = Standard_True;
131 Standard_Boolean theFBOri1 = Standard_True;
132 Standard_Boolean theFBOri2 = Standard_True;
133 //Standard_Boolean theFSOri1 = Standard_True;
134 //Standard_Boolean theFSOri2 = Standard_True;
135 Standard_Boolean Cumulated1, Cumulated2;
137 // 1- First Vertex != LastVertex but First VertexPoint == Last VertexPoint
138 // Remark : time comsuming process but useful !
139 // If this append, we can drop one of the two vertices and replace it
140 // everywhere it is referenced. Side effect : tolerance problem !!!
142 Handle(StepShape_VertexPoint) StartVertex =
143 Handle(StepShape_VertexPoint)::DownCast(ent->EdgeStart());
144 Handle(StepShape_VertexPoint) EndVertex =
145 Handle(StepShape_VertexPoint)::DownCast(ent->EdgeEnd());
147 if (StartVertex != EndVertex) {
149 Handle(StepGeom_CartesianPoint) StartPoint =
150 Handle(StepGeom_CartesianPoint)::DownCast(StartVertex->VertexGeometry());
151 Handle(StepGeom_CartesianPoint) EndPoint =
152 Handle(StepGeom_CartesianPoint)::DownCast(EndVertex->VertexGeometry());
154 // it can also be a degenerated pcurve
156 if (!StartPoint.IsNull() && !EndPoint.IsNull()) {
157 Standard_Real Dist = Sqrt
158 ((StartPoint->CoordinatesValue(1) - EndPoint->CoordinatesValue(1)) *
159 (StartPoint->CoordinatesValue(1) - EndPoint->CoordinatesValue(1)) +
160 (StartPoint->CoordinatesValue(2) - EndPoint->CoordinatesValue(2)) *
161 (StartPoint->CoordinatesValue(2) - EndPoint->CoordinatesValue(2)) +
162 (StartPoint->CoordinatesValue(3) - EndPoint->CoordinatesValue(3)) *
163 (StartPoint->CoordinatesValue(3) - EndPoint->CoordinatesValue(3)));
164 if (Dist < Precision::Confusion() ) {
165 ach->AddWarning("Two instances of Vertex have equal (within uncertainty) coordinates");
170 // 2- Two-Manifold Topology
172 Standard_Boolean sharEC = aShto.IsShared(ent);
173 Standard_Integer nbRef;
175 ach->AddFail("ERROR: EdgeCurve not referenced");
178 Interface_EntityIterator myShRef = aShto.Sharings(ent);
179 myShRef.SelectType (STANDARD_TYPE(StepShape_OrientedEdge),Standard_True);
180 nbRef = myShRef.NbEntities();
182 theOE1 = Handle(StepShape_OrientedEdge)::DownCast(myShRef.Value());
183 theOEOri1 = theOE1->Orientation();
185 theOE2 = Handle(StepShape_OrientedEdge)::DownCast(myShRef.Value());
186 theOEOri2 = theOE2->Orientation();
188 // get the FaceBound orientation for theOE1
190 Standard_Boolean sharOE1 = aShto.IsShared(theOE1);
193 std::cout << "OrientedEdge1 not shared" <<std::endl;
197 myShRef = aShto.Sharings(theOE1);
198 myShRef.SelectType (STANDARD_TYPE(StepShape_EdgeLoop),Standard_True);
199 nbRef = myShRef.NbEntities();
202 Handle(StepShape_EdgeLoop) theEL1 =
203 Handle(StepShape_EdgeLoop)::DownCast(myShRef.Value());
204 Standard_Boolean sharEL1 = aShto.IsShared(theEL1);
207 std::cout << "EdgeLoop1 not shared" <<std::endl;
211 myShRef = aShto.Sharings(theEL1);
212 myShRef.SelectType (STANDARD_TYPE(StepShape_FaceBound),Standard_True);
216 myShRef.NbEntities();
218 theFOB1 = Handle(StepShape_FaceBound)::DownCast(myShRef.Value());
219 if (!theFOB1.IsNull()) {
220 theFBOri1 = theFOB1->Orientation();
224 std::cout << "EdgeLoop not referenced by FaceBound" << std::endl;
232 std::cout << "OrientedEdge not referenced" << std::endl;
236 if (aShto.NbTypedSharings(theOE1,
237 STANDARD_TYPE(StepShape_EdgeLoop)) > 1) {
239 std::cout << "OrientedEdge referenced more than once" << std::endl;
246 // get the FaceBound orientation for theOE2
248 Standard_Boolean sharOE2 = aShto.IsShared(theOE2);
251 std::cout << "OrientedEdge2 not shared" <<std::endl;
255 myShRef = aShto.Sharings(theOE2);
257 // Standard_Integer nbRef =
259 // unused myShRef.NbEntities();
261 Handle(StepShape_EdgeLoop) theEL2 =
262 Handle(StepShape_EdgeLoop)::DownCast(myShRef.Value());
263 Standard_Boolean sharEL2 = aShto.IsShared(theEL2);
266 std::cout << "EdgeLoop2 not shared" <<std::endl;
270 myShRef = aShto.Sharings(theEL2);
271 // unused Standard_Integer nbRef = myShRef.NbEntities();
273 theFOB2 = Handle(StepShape_FaceBound)::DownCast(myShRef.Value());
274 if (!theFOB2.IsNull()) {
275 theFBOri2 = theFOB2->Orientation();
279 std::cout << "EdgeLoop not referenced by FaceBound" << std::endl;
285 // "cumulate" the FaceBound and the OrientedEdge orientation
287 Cumulated1 = theFBOri1 ^ theOEOri1;
288 Cumulated2 = theFBOri2 ^ theOEOri2;
290 // the orientation of the OrientedEdges must be opposite
292 if (Cumulated1 == Cumulated2) {
293 ach->AddFail("ERROR: non 2-manifold topology");