0029915: Porting to VC 2017 : Regressions in Modeling Algorithms on VC 2017
[occt.git] / src / APIHeaderSection / APIHeaderSection_MakeHeader.cxx
1 // Created on: 1993-08-12
2 // Created by: Frederic MAUPAS
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 //#58 rln 28.12.98 STEP header fields (NOTE: more parameterization is necessary)
18 //pdn 11.01.99 including <stdio.h> for compilation on NT
19
20 #include <APIHeaderSection_MakeHeader.hxx>
21 #include <HeaderSection_FileDescription.hxx>
22 #include <HeaderSection_FileName.hxx>
23 #include <HeaderSection_FileSchema.hxx>
24 #include <Interface_EntityIterator.hxx>
25 #include <Interface_HArray1OfHAsciiString.hxx>
26 #include <Interface_Macros.hxx>
27 #include <Interface_MSG.hxx>
28 #include <Interface_Protocol.hxx>
29 #include <Interface_Version.hxx>
30 #include <StepData_Protocol.hxx>
31 #include <StepData_StepModel.hxx>
32 #include <TCollection_HAsciiString.hxx>
33
34 #include <stdio.h>
35 // This is a generic header for any STEP sheme
36 static Handle(TCollection_HAsciiString) nulstr;
37 static Handle(Interface_HArray1OfHAsciiString) nularr;
38
39 APIHeaderSection_MakeHeader::APIHeaderSection_MakeHeader
40   (const Handle(StepData_StepModel)& model)
41 {
42   done = Standard_True;
43   if (model->HasHeaderEntity (STANDARD_TYPE(HeaderSection_FileName))) {
44     fn = GetCasted(HeaderSection_FileName,
45                    model->HeaderEntity(STANDARD_TYPE(HeaderSection_FileName)));
46   }
47   else done = Standard_False;
48   if (model->HasHeaderEntity (STANDARD_TYPE(HeaderSection_FileSchema))) {
49     fs = GetCasted(HeaderSection_FileSchema,
50                    model->HeaderEntity(STANDARD_TYPE(HeaderSection_FileSchema)));
51   }
52   else done = Standard_False;
53   if (model->HasHeaderEntity (STANDARD_TYPE(HeaderSection_FileDescription))) {
54     fd = GetCasted(HeaderSection_FileDescription,
55                    model->HeaderEntity(STANDARD_TYPE(HeaderSection_FileDescription)));
56   }
57   else done = Standard_False;
58 }
59
60 APIHeaderSection_MakeHeader::APIHeaderSection_MakeHeader
61   (const Standard_Integer shapetype)
62 {
63   switch(shapetype) {
64     case 1 : Init ("Open CASCADE Facetted BRep Model");       break;
65     case 2 : Init ("Open CASCADE Face Based Surface Model");  break;
66     case 3 : Init ("Open CASCADE Shell Based Surface Model"); break;
67     case 4 : Init ("Open CASCADE Manifold Solid Brep Model"); break;
68     default: Init ("Open CASCADE Shape Model");               break;
69   }
70 }
71
72 void  APIHeaderSection_MakeHeader::Init (const Standard_CString nameval)
73 {
74   done = Standard_True;
75   
76   // - File Name
77   char timestamp[50];
78   
79   if (fn.IsNull()) fn = new HeaderSection_FileName;
80   Handle(TCollection_HAsciiString) name = new TCollection_HAsciiString(nameval);
81   fn->SetName(name);
82   Interface_MSG::TDate (timestamp,0,0,0,0,0,1,"C:%4.4d-%2.2d-%2.2dT%2.2d:%2.2d:%2.2d");  // actually
83   Handle(TCollection_HAsciiString) tst = 
84     new TCollection_HAsciiString(timestamp);
85   fn->SetTimeStamp(tst);
86   Handle(Interface_HArray1OfHAsciiString) authors = 
87     new Interface_HArray1OfHAsciiString(1,1);
88   Handle(TCollection_HAsciiString) a1 = 
89     new TCollection_HAsciiString("Author");
90   authors->SetValue(1,a1);
91   fn->SetAuthor(authors);
92   Handle(Interface_HArray1OfHAsciiString) org = 
93     new Interface_HArray1OfHAsciiString(1,1);
94   Handle(TCollection_HAsciiString) org1 = 
95     new TCollection_HAsciiString("Open CASCADE");
96   org->SetValue(1,org1);
97   fn->SetOrganization(org);
98   
99   char procver[80];
100   sprintf (procver, XSTEP_PROCESSOR_VERSION, "STEP");
101   Handle(TCollection_HAsciiString) pv = new TCollection_HAsciiString (procver);
102   //Handle(TCollection_HAsciiString) pv = 
103   //new TCollection_HAsciiString(XSTEP_VERSION);
104   fn->SetPreprocessorVersion(pv);
105   
106   Handle(TCollection_HAsciiString) sys = 
107     new TCollection_HAsciiString(XSTEP_SYSTEM_VERSION);//#58 rln
108   fn->SetOriginatingSystem(sys);
109   Handle(TCollection_HAsciiString) auth = 
110     new TCollection_HAsciiString("Unknown");
111   fn->SetAuthorisation(auth);
112   
113   // - File Description 
114   
115   if (fd.IsNull()) fd = new HeaderSection_FileDescription;
116   Handle(Interface_HArray1OfHAsciiString) descr =
117     new Interface_HArray1OfHAsciiString(1,1);
118   Handle(TCollection_HAsciiString) descr1 = 
119     new TCollection_HAsciiString("Open CASCADE Model");
120   descr->SetValue(1,descr1);
121   fd->SetDescription(descr);
122   Handle(TCollection_HAsciiString) il = 
123     new TCollection_HAsciiString("2;1");
124   fd->SetImplementationLevel(il);
125
126   // - File Schema
127
128   if (fs.IsNull()) fs  = new HeaderSection_FileSchema;
129   Handle(Interface_HArray1OfHAsciiString) schid =
130     new Interface_HArray1OfHAsciiString(1,1);
131   Handle(TCollection_HAsciiString) schid1 = 
132     new TCollection_HAsciiString("");
133   schid->SetValue(1,schid1);
134   fs->SetSchemaIdentifiers(schid);
135
136 }
137
138 Standard_Boolean APIHeaderSection_MakeHeader::IsDone() const
139 {
140   return done;
141 }
142
143 void APIHeaderSection_MakeHeader::Apply
144   (const Handle(StepData_StepModel)& model) const
145 {
146   Interface_EntityIterator header = model->Header();
147   if (HasFd() && !model->HasHeaderEntity (STANDARD_TYPE(HeaderSection_FileDescription)))
148     header.AddItem(fd);
149   if (HasFn() && !model->HasHeaderEntity (STANDARD_TYPE(HeaderSection_FileName)))
150     header.AddItem(fn);
151   if (HasFs() && !model->HasHeaderEntity (STANDARD_TYPE(HeaderSection_FileSchema))) {
152
153 // Schema defined? If not take it from the protocole
154     Handle(TCollection_HAsciiString) sch;
155     Handle(Interface_HArray1OfHAsciiString) schid = fs->SchemaIdentifiers();
156     if (!schid.IsNull()) sch = schid->Value(1);
157     else {
158       schid = new Interface_HArray1OfHAsciiString(1,1);
159       fs->SetSchemaIdentifiers(schid);
160     }
161     if (!sch.IsNull()) { if (sch->Length() < 2) sch.Nullify(); } // not defined
162     if (sch.IsNull()) {
163       Handle(StepData_Protocol) stepro = Handle(StepData_Protocol)::DownCast
164         ( model->Protocol());
165       if (!stepro.IsNull()) sch = new TCollection_HAsciiString
166         (stepro->SchemaName());
167       if (!sch.IsNull()) schid->SetValue (1,sch);
168     }
169     header.AddItem(fs);
170   }
171   model->ClearHeader();
172   for (header.Start(); header.More(); header.Next())
173     model->AddHeaderEntity(header.Value());
174 }
175
176
177 // ========
178 // FileName
179 // ========
180
181 Handle(StepData_StepModel)  APIHeaderSection_MakeHeader::NewModel
182   (const Handle(Interface_Protocol)& protocol) const
183 {
184   Handle(StepData_StepModel) stepmodel = new StepData_StepModel;
185   stepmodel->SetProtocol (protocol);
186
187       // - Make Header information
188
189   Apply(stepmodel);
190   return stepmodel;
191 }
192
193 //   ########        Individual Queries / Actions        ########
194
195 // ========
196 // FileName
197 // ========
198
199 Standard_Boolean APIHeaderSection_MakeHeader::HasFn() const
200 {  return (!fn.IsNull());  }
201
202 Handle(HeaderSection_FileName) APIHeaderSection_MakeHeader::FnValue() const
203 {
204   return fn;
205 }
206
207 /*
208 void APIHeaderSection_MakeHeader::SetNameFromShapeType(const Standard_Integer shapetype)
209 {
210   Handle(TCollection_HAsciiString) name;
211   switch(shapetype) 
212     {
213     case 1: // face_based_surface_model
214       name = new TCollection_HAsciiString
215         ("Euclid Face Based Surface Model");
216       break;
217     case 2: // manifold_solid_brep
218       name = new TCollection_HAsciiString 
219         ("Euclid Manifold Solid Brep Model");
220       break;
221     case 3: // facetted_brep
222       name = new TCollection_HAsciiString
223         ("Euclid Facetted Brep Model");
224       break;
225     default : // others ?
226       name = new TCollection_HAsciiString
227         ("Euclid Shape Model");
228       break;
229     }
230   SetName(aName);
231 }
232 */
233
234 void APIHeaderSection_MakeHeader::SetName(const Handle(TCollection_HAsciiString)& aName)
235 {
236         if (!fn.IsNull()) fn->SetName(aName);
237 }
238
239 Handle(TCollection_HAsciiString) APIHeaderSection_MakeHeader::Name() const
240 {
241         return (fn.IsNull() ? nulstr : fn->Name());
242 }
243
244 void APIHeaderSection_MakeHeader::SetTimeStamp(const Handle(TCollection_HAsciiString)& aTimeStamp)
245 {
246         if (!fn.IsNull()) fn->SetTimeStamp(aTimeStamp);
247 }
248
249 Handle(TCollection_HAsciiString) APIHeaderSection_MakeHeader::TimeStamp() const
250 {
251         return (fn.IsNull() ? nulstr : fn->TimeStamp());
252 }
253
254 void APIHeaderSection_MakeHeader::SetAuthor(const Handle(Interface_HArray1OfHAsciiString)& aAuthor)
255 {
256         if (!fn.IsNull()) fn->SetAuthor(aAuthor);
257 }
258
259 void APIHeaderSection_MakeHeader::SetAuthorValue(const Standard_Integer num, const Handle(TCollection_HAsciiString)& aAuthor)
260 {
261   if (fn.IsNull()) return;
262   Handle(Interface_HArray1OfHAsciiString) li = fn->Author();
263   if (num >= li->Lower() && num <= li->Upper()) li->SetValue(num,aAuthor);
264 }
265
266 Handle(Interface_HArray1OfHAsciiString) APIHeaderSection_MakeHeader::Author() const
267 {
268         return (fn.IsNull() ? nularr : fn->Author());
269 }
270
271 Handle(TCollection_HAsciiString) APIHeaderSection_MakeHeader::AuthorValue(const Standard_Integer num) const
272 {
273         return (fn.IsNull() ? nulstr : fn->AuthorValue(num));
274 }
275
276 Standard_Integer APIHeaderSection_MakeHeader::NbAuthor () const
277 {
278         return (fn.IsNull() ? 0 : fn->NbAuthor());
279 }
280
281 void APIHeaderSection_MakeHeader::SetOrganization(const Handle(Interface_HArray1OfHAsciiString)& aOrganization)
282 {
283         if (!fn.IsNull()) fn->SetOrganization(aOrganization);
284 }
285
286 void APIHeaderSection_MakeHeader::SetOrganizationValue(const Standard_Integer num, const Handle(TCollection_HAsciiString)& aOrgan)
287 {
288   if (fn.IsNull()) return;
289   Handle(Interface_HArray1OfHAsciiString) li = fn->Organization();
290   if (num >= li->Lower() && num <= li->Upper()) li->SetValue(num,aOrgan);
291 }
292
293 Handle(Interface_HArray1OfHAsciiString) APIHeaderSection_MakeHeader::Organization() const
294 {
295         return (fn.IsNull() ? nularr : fn->Organization());
296 }
297
298 Handle(TCollection_HAsciiString) APIHeaderSection_MakeHeader::OrganizationValue(const Standard_Integer num) const
299 {
300         return (fn.IsNull() ? nulstr : fn->OrganizationValue(num));
301 }
302
303 Standard_Integer APIHeaderSection_MakeHeader::NbOrganization () const
304 {
305         return (fn.IsNull() ? 0 : fn->NbOrganization());
306 }
307
308 void APIHeaderSection_MakeHeader::SetPreprocessorVersion(const Handle(TCollection_HAsciiString)& aPreprocessorVersion)
309 {
310         if (!fn.IsNull()) fn->SetPreprocessorVersion(aPreprocessorVersion);
311 }
312
313 Handle(TCollection_HAsciiString) APIHeaderSection_MakeHeader::PreprocessorVersion() const
314 {
315         return (fn.IsNull() ? nulstr : fn->PreprocessorVersion());
316 }
317
318 void APIHeaderSection_MakeHeader::SetOriginatingSystem(const Handle(TCollection_HAsciiString)& aOriginatingSystem)
319 {
320         if (!fn.IsNull()) fn->SetOriginatingSystem(aOriginatingSystem);
321 }
322
323 Handle(TCollection_HAsciiString) APIHeaderSection_MakeHeader::OriginatingSystem() const
324 {
325         return (fn.IsNull() ? nulstr : fn->OriginatingSystem());
326 }
327
328 void APIHeaderSection_MakeHeader::SetAuthorisation(const Handle(TCollection_HAsciiString)& aAuthorisation)
329 {
330         if (!fn.IsNull()) fn->SetAuthorisation(aAuthorisation);
331 }
332
333 Handle(TCollection_HAsciiString) APIHeaderSection_MakeHeader::Authorisation() const
334 {
335         return (fn.IsNull() ? nulstr : fn->Authorisation());
336 }
337
338 // ===========
339 // File Schema
340 // ===========
341
342 Standard_Boolean APIHeaderSection_MakeHeader::HasFs() const
343 {  return (!fs.IsNull());  }
344
345 Handle(HeaderSection_FileSchema) APIHeaderSection_MakeHeader::FsValue() const
346 {
347   return fs;
348 }
349
350 void APIHeaderSection_MakeHeader::SetSchemaIdentifiers(const Handle(Interface_HArray1OfHAsciiString)& aSchemaIdentifiers)
351 {
352         if (!fs.IsNull()) fs->SetSchemaIdentifiers(aSchemaIdentifiers);
353 }
354
355 void APIHeaderSection_MakeHeader::SetSchemaIdentifiersValue(const Standard_Integer num, const Handle(TCollection_HAsciiString)& aSchem)
356 {
357   if (fs.IsNull()) return;
358   Handle(Interface_HArray1OfHAsciiString) li = fs->SchemaIdentifiers();
359   if (num >= li->Lower() && num <= li->Upper()) li->SetValue(num,aSchem);
360 }
361
362 Handle(Interface_HArray1OfHAsciiString) APIHeaderSection_MakeHeader::SchemaIdentifiers() const
363 {
364         return (fs.IsNull() ? nularr : fs->SchemaIdentifiers());
365 }
366
367 Handle(TCollection_HAsciiString) APIHeaderSection_MakeHeader::SchemaIdentifiersValue(const Standard_Integer num) const
368 {
369         return (fs.IsNull() ? nulstr : fs->SchemaIdentifiersValue(num));
370 }
371
372 Standard_Integer APIHeaderSection_MakeHeader::NbSchemaIdentifiers () const
373 {
374         return (fs.IsNull() ? 0 : fs->NbSchemaIdentifiers());
375 }
376
377 //=======================================================================
378 //function : AddSchemaIdentifier
379 //purpose  : 
380 //=======================================================================
381
382 void APIHeaderSection_MakeHeader::AddSchemaIdentifier(const Handle(TCollection_HAsciiString)& aSchem)
383 {
384   if ( fs.IsNull() ) fs = new HeaderSection_FileSchema;
385   Handle(Interface_HArray1OfHAsciiString) idents = fs->SchemaIdentifiers();
386
387   // check that requested subschema is already in the list
388   Standard_Integer i;
389   for ( i=1; ! idents.IsNull() && i <= idents->Length(); i++ ) {
390     if ( aSchem->IsSameString ( idents->Value(i) ) ) return;
391   }
392   
393   // add a subshema
394   Handle(Interface_HArray1OfHAsciiString) ids = 
395     new Interface_HArray1OfHAsciiString ( 1, ( idents.IsNull() ? 1 : idents->Length() + 1 ) );
396   for ( i=1; ! idents.IsNull() && i <= idents->Length(); i++ ) {
397     ids->SetValue ( i, idents->Value(i) );
398   }
399   ids->SetValue ( i, aSchem );
400   
401   fs->SetSchemaIdentifiers ( ids );
402 }
403
404 // ================
405 // File Description
406 // ================
407
408 Standard_Boolean APIHeaderSection_MakeHeader::HasFd() const
409 {  return (!fd.IsNull());  }
410
411 Handle(HeaderSection_FileDescription) APIHeaderSection_MakeHeader::FdValue() const
412 {
413   return fd;
414 }
415
416 void APIHeaderSection_MakeHeader::SetDescription(const Handle(Interface_HArray1OfHAsciiString)& aDescription)
417 {
418         if (!fs.IsNull()) fd->SetDescription(aDescription);
419 }
420
421 void APIHeaderSection_MakeHeader::SetDescriptionValue(const Standard_Integer num, const Handle(TCollection_HAsciiString)& aDescr)
422 {
423   if (fd.IsNull()) return;
424   Handle(Interface_HArray1OfHAsciiString) li = fd->Description();
425   if (num >= li->Lower() && num <= li->Upper()) li->SetValue(num,aDescr);
426 }
427
428 Handle(Interface_HArray1OfHAsciiString) APIHeaderSection_MakeHeader::Description() const
429 {
430         return (fd.IsNull() ? nularr : fd->Description());
431 }
432
433 Handle(TCollection_HAsciiString) APIHeaderSection_MakeHeader::DescriptionValue(const Standard_Integer num) const
434 {
435         return (fd.IsNull() ? nulstr : fd->DescriptionValue(num));
436 }
437
438 Standard_Integer APIHeaderSection_MakeHeader::NbDescription () const
439 {
440         return (fd.IsNull() ? 0 : fd->NbDescription());
441 }
442
443 void APIHeaderSection_MakeHeader::SetImplementationLevel(const Handle(TCollection_HAsciiString)& aImplementationLevel)
444 {
445         if (!fd.IsNull()) fd->SetImplementationLevel(aImplementationLevel);
446 }
447
448 Handle(TCollection_HAsciiString) APIHeaderSection_MakeHeader::ImplementationLevel() const
449 {
450         return (fd.IsNull() ? nulstr : fd->ImplementationLevel());
451 }