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