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 <RWStepShape_RWFaceBound.hxx>
19 #include <StepData_StepReaderData.hxx>
20 #include <StepData_StepWriter.hxx>
21 #include <StepShape_Edge.hxx>
22 #include <StepShape_EdgeLoop.hxx>
23 #include <StepShape_FaceBound.hxx>
24 #include <StepShape_Loop.hxx>
25 #include <StepShape_OrientedEdge.hxx>
27 RWStepShape_RWFaceBound::RWStepShape_RWFaceBound () {}
29 void RWStepShape_RWFaceBound::ReadStep
30 (const Handle(StepData_StepReaderData)& data,
31 const Standard_Integer num,
32 Handle(Interface_Check)& ach,
33 const Handle(StepShape_FaceBound)& ent) const
37 // --- Number of Parameter Control ---
39 if (!data->CheckNbParams(num,3,ach,"face_bound")) return;
41 // --- inherited field : name ---
43 Handle(TCollection_HAsciiString) aName;
44 //szv#4:S4163:12Mar99 `Standard_Boolean stat1 =` not needed
45 data->ReadString (num,1,"name",ach,aName);
47 // --- own field : bound ---
49 Handle(StepShape_Loop) aBound;
50 //szv#4:S4163:12Mar99 `Standard_Boolean stat2 =` not needed
51 data->ReadEntity(num, 2,"bound", ach, STANDARD_TYPE(StepShape_Loop), aBound);
53 // --- own field : orientation ---
55 Standard_Boolean aOrientation;
56 //szv#4:S4163:12Mar99 `Standard_Boolean stat3 =` not needed
57 data->ReadBoolean (num,3,"orientation",ach,aOrientation);
59 //--- Initialisation of the read entity ---
62 ent->Init(aName, aBound, aOrientation);
66 void RWStepShape_RWFaceBound::WriteStep
67 (StepData_StepWriter& SW,
68 const Handle(StepShape_FaceBound)& ent) const
71 // --- inherited field name ---
75 // --- own field : bound ---
77 SW.Send(ent->Bound());
79 // --- own field : orientation ---
81 SW.SendBoolean(ent->Orientation());
85 void RWStepShape_RWFaceBound::Share(const Handle(StepShape_FaceBound)& ent, Interface_EntityIterator& iter) const
88 iter.GetOneItem(ent->Bound());
93 void RWStepShape_RWFaceBound::Check
94 (const Handle(StepShape_FaceBound)& ent,
95 const Interface_ShareTool& aShto,
96 Handle(Interface_Check)& ach) const
98 Standard_Boolean theFBOri2 = Standard_True;
99 Standard_Boolean theFBOri1 = ent->Orientation();
100 Handle(StepShape_EdgeLoop) theEL1 =
101 Handle(StepShape_EdgeLoop)::DownCast(ent->Bound());
102 if (!theEL1.IsNull()) {
103 Standard_Integer nbEdg = theEL1->NbEdgeList();
104 for(Standard_Integer i=1; i<=nbEdg; i++) {
105 Handle(StepShape_OrientedEdge) theOE1 = theEL1->EdgeListValue(i);
106 Handle(StepShape_Edge) theEdg1 = theOE1->EdgeElement();
107 Interface_EntityIterator myShRef = aShto.Sharings(theEdg1);
108 myShRef.SelectType (STANDARD_TYPE(StepShape_OrientedEdge),Standard_True);
109 Standard_Integer nbRef = myShRef.NbEntities();
111 // ach.AddWarning("EdgeCurve only once referenced");
113 else if (nbRef ==2) {
114 Handle(StepShape_OrientedEdge) theOE2;
115 Handle(StepShape_OrientedEdge) refOE1 =
116 Handle(StepShape_OrientedEdge)::DownCast(myShRef.Value());
118 Handle(StepShape_OrientedEdge) refOE2 =
119 Handle(StepShape_OrientedEdge)::DownCast(myShRef.Value());
120 if(theOE1 == refOE1) theOE2 = refOE2;
121 else if(theOE1 == refOE2) theOE2 = refOE1;
123 // get the FaceBound orientation for theOE2
125 Standard_Boolean sharOE2 = aShto.IsShared(theOE2);
128 cout << "OrientedEdge2 not shared" <<endl;
132 myShRef = aShto.Sharings(theOE2);
133 myShRef.SelectType (STANDARD_TYPE(StepShape_EdgeLoop),Standard_True);
135 Handle(StepShape_EdgeLoop) theEL2 =
136 Handle(StepShape_EdgeLoop)::DownCast(myShRef.Value());
137 Standard_Boolean sharEL2 = aShto.IsShared(theEL2);
140 cout << "EdgeLoop2 not shared" <<endl;
144 myShRef = aShto.Sharings(theEL2);
145 myShRef.SelectType (STANDARD_TYPE(StepShape_FaceBound),Standard_True);
147 Handle(StepShape_FaceBound) theFB2 =
148 Handle(StepShape_FaceBound)::DownCast(myShRef.Value());
149 if (!theFB2.IsNull()) {
150 theFBOri2 = theFB2->Orientation();
154 cout << "EdgeLoop not referenced by FaceBound" << endl;
160 // "cumulate" the FaceBound orientation with the OrientedEdge orientation
162 Standard_Boolean theOEOri1 =
163 theFBOri1 ? theOE1->Orientation() : !(theOE1->Orientation());
164 Standard_Boolean theOEOri2 =
165 theFBOri2 ? theOE2->Orientation() : !(theOE2->Orientation());
167 // the orientation of the OrientedEdges must be opposite
169 if(theOEOri1 == theOEOri2) {
170 ach->AddFail("ERROR: non 2-manifold topology");
172 } //end if(nbRef == 2)
173 } //end for(i=1; i<=nbEdg; ...)
174 } //end if(!theEL1.IsNull)
177 cout << "no EdgeLoop in FaceBound" << endl;