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 
15 #include <Interface_Check.hxx>
16 #include <Interface_EntityIterator.hxx>
17 #include <Interface_ShareTool.hxx>
18 #include <RWStepShape_RWEdgeLoop.hxx>
19 #include <StepData_StepReaderData.hxx>
20 #include <StepData_StepWriter.hxx>
21 #include <StepShape_EdgeLoop.hxx>
22 #include <StepShape_HArray1OfOrientedEdge.hxx>
23 #include <StepShape_OrientedEdge.hxx>
24 
RWStepShape_RWEdgeLoop()25 RWStepShape_RWEdgeLoop::RWStepShape_RWEdgeLoop () {}
26 
ReadStep(const Handle (StepData_StepReaderData)& data,const Standard_Integer num,Handle (Interface_Check)& ach,const Handle (StepShape_EdgeLoop)& ent) const27 void RWStepShape_RWEdgeLoop::ReadStep
28 (const Handle(StepData_StepReaderData)& data,
29  const Standard_Integer num,
30  Handle(Interface_Check)& ach,
31  const Handle(StepShape_EdgeLoop)& ent) const
32 {
33 
34 
35   // --- Number of Parameter Control ---
36 
37   if (!data->CheckNbParams(num,2,ach,"edge_loop")) return;
38 
39   // --- inherited field : name ---
40 
41   Handle(TCollection_HAsciiString) aName;
42   //szv#4:S4163:12Mar99 `Standard_Boolean stat0 =` not needed
43   data->ReadString (num,1,"name",ach,aName);
44 
45   // --- own field : edgeList ---
46 
47   Handle(StepShape_HArray1OfOrientedEdge) aEdgeList;
48   Handle(StepShape_OrientedEdge) anent;
49   Standard_Integer nsub1;
50   if (data->ReadSubList (num,2,"edge_list",ach,nsub1)) {
51     Standard_Integer nb1 = data->NbParams(nsub1);
52     aEdgeList = new StepShape_HArray1OfOrientedEdge (1, nb1);
53     for (Standard_Integer i1 = 1; i1 <= nb1; i1 ++) {
54       //szv#4:S4163:12Mar99 `Standard_Boolean stat1 =` not needed
55       if (data->ReadEntity (nsub1, i1,"oriented_edge", ach, STANDARD_TYPE(StepShape_OrientedEdge), anent))
56 	aEdgeList->SetValue(i1, anent);
57     }
58   }
59 
60   //--- Initialisation of the read entity ---
61 
62   ent->Init(aName, aEdgeList);
63 }
64 
65 
WriteStep(StepData_StepWriter & SW,const Handle (StepShape_EdgeLoop)& ent) const66 void RWStepShape_RWEdgeLoop::WriteStep
67 	(StepData_StepWriter& SW,
68 	 const Handle(StepShape_EdgeLoop)& ent) const
69 {
70 
71   // --- inherited field name ---
72 
73   SW.Send(ent->Name());
74 
75   // --- own field : edgeList ---
76 
77   SW.OpenSub();
78   for (Standard_Integer i1 = 1;  i1 <= ent->NbEdgeList();  i1 ++) {
79     SW.Send(ent->EdgeListValue(i1));
80   }
81   SW.CloseSub();
82 }
83 
84 // ============================================================================
85 // Method : Share
86 // ============================================================================
87 
Share(const Handle (StepShape_EdgeLoop)& ent,Interface_EntityIterator & iter) const88 void RWStepShape_RWEdgeLoop::Share(const Handle(StepShape_EdgeLoop)& ent, Interface_EntityIterator& iter) const
89 {
90 
91 	Standard_Integer nbElem1 = ent->NbEdgeList();
92 	for (Standard_Integer is1=1; is1<=nbElem1; is1 ++) {
93 	  iter.GetOneItem(ent->EdgeListValue(is1));
94 	}
95 
96 }
97 
98 
99 
Check(const Handle (StepShape_EdgeLoop)& ent,const Interface_ShareTool &,Handle (Interface_Check)& ach) const100 void RWStepShape_RWEdgeLoop::Check
101   (const Handle(StepShape_EdgeLoop)& ent,
102    const Interface_ShareTool& ,
103    Handle(Interface_Check)& ach) const
104 {
105 //  std::cout << "------ calling CheckEdgeLoop ------" << std::endl;
106   Standard_Boolean headToTail = Standard_True;
107   //Standard_Boolean noIdentVtx = Standard_True; //szv#4:S4163:12Mar99 unused
108   Standard_Integer nbEdg = ent->NbEdgeList();
109   Handle(StepShape_OrientedEdge) theOE = ent->EdgeListValue(1);
110   Handle(StepShape_Vertex) theVxFrst = theOE->EdgeStart();
111   Handle(StepShape_Vertex) theVxLst  = theOE->EdgeEnd();
112   if((nbEdg == 1) && (theVxFrst != theVxLst)){
113     ach->AddFail("Edge loop composed of single Edge : Start and End Vertex of edge are not identical");
114   }
115   for(Standard_Integer i = 2; i <= nbEdg; i++)
116     {
117       theOE     = ent->EdgeListValue(i);
118       Handle(StepShape_Vertex) theVxStrt = theOE->EdgeStart();
119       if(theVxStrt != theVxLst){
120 	headToTail = Standard_False;
121       }
122       theVxLst = theOE->EdgeEnd();
123       if(theVxStrt == theVxLst){
124 	ach->AddWarning("One edge_curve contains identical vertices");
125       }
126     }
127   if(theVxFrst != theVxLst){
128     headToTail = Standard_False;
129   }
130   if(!headToTail) {
131     ach->AddFail("Error : Path does not head to tail");
132   }
133 }
134