summaryrefslogtreecommitdiff
path: root/src/RWHeaderSection/RWHeaderSection_ReadWriteModule.cxx
blob: d3ce2ee1035287b077ec323574eb4735a81cd006 (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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include <RWHeaderSection_ReadWriteModule.ixx>
#include <Interface_ReaderLib.hxx>
#include <StepData_WriterLib.hxx>
#include <HeaderSection_Protocol.hxx>
#include <Interface_Macros.hxx>
#include <Interface_ParamType.hxx>


#include <HeaderSection_FileName.hxx>
#include <HeaderSection_FileDescription.hxx>
#include <HeaderSection_FileSchema.hxx>

#include <StepData_UndefinedEntity.hxx>


#include <RWHeaderSection_RWFileName.hxx>
#include <RWHeaderSection_RWFileDescription.hxx>
#include <RWHeaderSection_RWFileSchema.hxx>

	// -- General Declarations (Recognize, StepType) ---

static TCollection_AsciiString PasReco("");    // neutralise StartEntity de SW
static TCollection_AsciiString Reco_FileName ("FILE_NAME");
static TCollection_AsciiString Reco_FileDescription ("FILE_DESCRIPTION");
static TCollection_AsciiString Reco_FileSchema ("FILE_SCHEMA");

	// -- Definition of the libraries --

RWHeaderSection_ReadWriteModule::RWHeaderSection_ReadWriteModule ()
{
	Handle(HeaderSection_Protocol) protocol = new HeaderSection_Protocol;
	StepData_WriterLib::SetGlobal(this,protocol);
	Interface_ReaderLib::SetGlobal(this,protocol);
}

	// --- Case Recognition ---

Standard_Integer RWHeaderSection_ReadWriteModule::CaseStep
	(const TCollection_AsciiString& key) const
{
	if (key.IsEqual(Reco_FileName)) return 1;
	if (key.IsEqual(Reco_FileDescription)) return 2;
	if (key.IsEqual(Reco_FileSchema)) return 3;
return 0;
}

	// --- External Mapping Case Recognition ---

Standard_Integer RWHeaderSection_ReadWriteModule::CaseStep
	(const TColStd_SequenceOfAsciiString& types) const
{

#ifdef DEB
  Standard_Integer NbComp = types.Length();
  if (NbComp < 2) {
    cout << "Plex Instance illegal " << endl;
  }
#endif
  return 0;
}


	// --- External Mapping Recognition ---

Standard_Boolean RWHeaderSection_ReadWriteModule::IsComplex
	(const Standard_Integer CN) const
{
	return Standard_False;
}



const TCollection_AsciiString& RWHeaderSection_ReadWriteModule::StepType
	(const Standard_Integer CN) const
{
	switch (CN) {
	  case 1 : return Reco_FileName;
	  case 2 : return Reco_FileDescription;
	  case 3 : return Reco_FileSchema;
	  default : return PasReco;
	}
}

	// -- Reading of a file --

void RWHeaderSection_ReadWriteModule::ReadStep
	(const Standard_Integer CN,
	 const Handle(StepData_StepReaderData)& data,
	 const Standard_Integer num,
	 Handle(Interface_Check)& ach,
	 const Handle(Standard_Transient)&ent) const
{
	if (CN == 0) return;
	switch (CN) {
	  case 1 : 
	    {
	      DeclareAndCast(HeaderSection_FileName, anent, ent);
	      RWHeaderSection_RWFileName tool;
	      if (anent.IsNull()) ach->AddFail("Type Mismatch on FileName");
	      else tool.ReadStep (data,num,ach,anent);
	    }

	    break;
	  case 2 : 
	    {
	      DeclareAndCast(HeaderSection_FileDescription, anent, ent);
	      RWHeaderSection_RWFileDescription tool;
	      if (anent.IsNull()) ach->AddFail("Type Mismatch on FileDescription");
	      else tool.ReadStep (data,num,ach,anent);
	    }

	    break;
	  case 3 : 
	    {
	      DeclareAndCast(HeaderSection_FileSchema, anent, ent);
	      RWHeaderSection_RWFileSchema tool;
	      if (anent.IsNull()) ach->AddFail("Type Mismatch on FileSchema");
	      else tool.ReadStep (data,num,ach,anent);
	    }

	    break;
	  case 4 : 
	    {
	      DeclareAndCast(StepData_UndefinedEntity,und,ent);
	      if (und.IsNull()) ach->AddFail
		("# Entity neither Recognized nor set as UndefinedEntity from StepData #");
	      else und->ReadRecord(data,num,ach);
	    }

	    break;
	  default : ach->AddFail("Type Mismatch when reading - Entity");
	}

return;}

	// -- Writing of a file --

void RWHeaderSection_ReadWriteModule::WriteStep
	(const Standard_Integer CN,
	 StepData_StepWriter& SW,
	 const Handle(Standard_Transient)&ent) const
{
	if (CN == 0) return;
	switch (CN) {
	  case 1 : 
	    {
	      DeclareAndCast(HeaderSection_FileName, anent, ent);
	      RWHeaderSection_RWFileName tool;
	      if (anent.IsNull()) return; 
	      else tool.WriteStep (SW,anent);
	    }

	    break;
	  case 2 : 
	    {
	      DeclareAndCast(HeaderSection_FileDescription, anent, ent);
	      RWHeaderSection_RWFileDescription tool;
	      if (anent.IsNull()) return; 
	      else tool.WriteStep (SW,anent);
	    }

	    break;
	  case 3 : 
	    {
	      DeclareAndCast(HeaderSection_FileSchema, anent, ent);
	      RWHeaderSection_RWFileSchema tool;
	      if (anent.IsNull()) return; 
	      else tool.WriteStep (SW,anent);
	    }

	    break;
	  case 4 : 
	    {
	      DeclareAndCast(StepData_UndefinedEntity,und,ent);
	      if (und.IsNull()) break;
//  Parentheses gerees par StepWriter lui-meme
//   car en recevant le type PasReco, StepWriter ne l'affiche pas,
//   mais il gere les parentheses comme si de rien n etait
	      if (und->IsComplex())   SW.StartComplex();
	      und->WriteParams(SW);
	      if (und->IsComplex())   SW.EndComplex();
	    }

	    break;
	  default : return;
	}
}