summaryrefslogtreecommitdiff
path: root/src/RWStepShape/RWStepShape_RWFaceBound.cxx
blob: 2b900f3a795a1ea94f89dc4d0e7b38cdcfdea001 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168

#include <RWStepShape_RWFaceBound.ixx>
#include <StepShape_Loop.hxx>
#include <StepShape_EdgeLoop.hxx>
#include <StepShape_OrientedEdge.hxx>
#include <StepShape_Edge.hxx>


#include <Interface_EntityIterator.hxx>


#include <StepShape_FaceBound.hxx>


RWStepShape_RWFaceBound::RWStepShape_RWFaceBound () {}

void RWStepShape_RWFaceBound::ReadStep
	(const Handle(StepData_StepReaderData)& data,
	 const Standard_Integer num,
	 Handle(Interface_Check)& ach,
	 const Handle(StepShape_FaceBound)& ent) const
{


	// --- Number of Parameter Control ---

	if (!data->CheckNbParams(num,3,ach,"face_bound")) return;

	// --- inherited field : name ---

	Handle(TCollection_HAsciiString) aName;
	//szv#4:S4163:12Mar99 `Standard_Boolean stat1 =` not needed
	data->ReadString (num,1,"name",ach,aName);

	// --- own field : bound ---

	Handle(StepShape_Loop) aBound;
	//szv#4:S4163:12Mar99 `Standard_Boolean stat2 =` not needed
	data->ReadEntity(num, 2,"bound", ach, STANDARD_TYPE(StepShape_Loop), aBound);

	// --- own field : orientation ---

	Standard_Boolean aOrientation;
	//szv#4:S4163:12Mar99 `Standard_Boolean stat3 =` not needed
	data->ReadBoolean (num,3,"orientation",ach,aOrientation);

	//--- Initialisation of the read entity ---


	ent->Init(aName, aBound, aOrientation);
}


void RWStepShape_RWFaceBound::WriteStep
	(StepData_StepWriter& SW,
	 const Handle(StepShape_FaceBound)& ent) const
{

	// --- inherited field name ---

	SW.Send(ent->Name());

	// --- own field : bound ---

	SW.Send(ent->Bound());

	// --- own field : orientation ---

	SW.SendBoolean(ent->Orientation());
}


void RWStepShape_RWFaceBound::Share(const Handle(StepShape_FaceBound)& ent, Interface_EntityIterator& iter) const
{

	iter.GetOneItem(ent->Bound());
}



void RWStepShape_RWFaceBound::Check
  (const Handle(StepShape_FaceBound)& ent,
   const Interface_ShareTool& aShto,
   Handle(Interface_Check)& ach) const
{
  Standard_Boolean theFBOri2 = Standard_True;
  Standard_Boolean theFBOri1 = ent->Orientation();
  Handle(StepShape_EdgeLoop) theEL1 =
    Handle(StepShape_EdgeLoop)::DownCast(ent->Bound());
  if (!theEL1.IsNull()) {
    Standard_Integer nbEdg = theEL1->NbEdgeList();
    for(Standard_Integer i=1; i<=nbEdg; i++) {
      Handle(StepShape_OrientedEdge) theOE1 = theEL1->EdgeListValue(i);
      Handle(StepShape_Edge) theEdg1 = theOE1->EdgeElement();
      Interface_EntityIterator myShRef = aShto.Sharings(theEdg1);
      myShRef.SelectType (STANDARD_TYPE(StepShape_OrientedEdge),Standard_True);
      Standard_Integer nbRef = myShRef.NbEntities();
      if(nbRef == 1) {
	//      ach.AddWarning("EdgeCurve only once referenced");
      }
      else if (nbRef ==2) {
	Handle(StepShape_OrientedEdge) theOE2;
	Handle(StepShape_OrientedEdge) refOE1 = 
	  Handle(StepShape_OrientedEdge)::DownCast(myShRef.Value());
	myShRef.Next();
	Handle(StepShape_OrientedEdge) refOE2 = 
	  Handle(StepShape_OrientedEdge)::DownCast(myShRef.Value());
	if(theOE1 == refOE1) theOE2 = refOE2;
	else if(theOE1 == refOE2) theOE2 = refOE1;
	
	// get the FaceBound orientation for theOE2
	
	Standard_Boolean sharOE2 = aShto.IsShared(theOE2);
	if(!sharOE2){
#ifdef DEB
	  cout << "OrientedEdge2 not shared" <<endl;
#endif
	}
	else {
	  myShRef = aShto.Sharings(theOE2);
	  myShRef.SelectType (STANDARD_TYPE(StepShape_EdgeLoop),Standard_True);
	  myShRef.Start();
	  Handle(StepShape_EdgeLoop) theEL2 =
	    Handle(StepShape_EdgeLoop)::DownCast(myShRef.Value());
	  Standard_Boolean sharEL2 = aShto.IsShared(theEL2);
	  if(!sharEL2){
#ifdef DEB
	    cout << "EdgeLoop2 not shared" <<endl;
#endif
	  }
	  else {
	    myShRef = aShto.Sharings(theEL2);
	    myShRef.SelectType (STANDARD_TYPE(StepShape_FaceBound),Standard_True);
	    myShRef.Start();
	    Handle(StepShape_FaceBound) theFB2 =
	      Handle(StepShape_FaceBound)::DownCast(myShRef.Value());
	    if (!theFB2.IsNull()) {
	      theFBOri2 = theFB2->Orientation();
	    }
	    else {
#ifdef DEB
	      cout << "EdgeLoop not referenced by FaceBound" << endl;
#endif
	    }
	  }
	}
	
	// "cumulate" the FaceBound orientation with the OrientedEdge orientation
	
	Standard_Boolean theOEOri1 =
	  theFBOri1 ? theOE1->Orientation() : !(theOE1->Orientation());
	Standard_Boolean theOEOri2 =
	  theFBOri2 ? theOE2->Orientation() : !(theOE2->Orientation());
	
	// the orientation of the OrientedEdges must be opposite
	
	if(theOEOri1 == theOEOri2) {
	  ach->AddFail("ERROR: non 2-manifold topology");
	} 
      } //end if(nbRef == 2)
    } //end for(i=1; i<=nbEdg; ...)
  } //end if(!theEL1.IsNull)
  else {
#ifdef DEB
    cout << "no EdgeLoop in FaceBound" << endl;
#endif
  }
}