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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
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
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>
35 // This is a generic header for any STEP sheme
36 static Handle(TCollection_HAsciiString) nulstr;
37 static Handle(Interface_HArray1OfHAsciiString) nularr;
39 APIHeaderSection_MakeHeader::APIHeaderSection_MakeHeader
40 (const Handle(StepData_StepModel)& model)
43 if (model->HasHeaderEntity (STANDARD_TYPE(HeaderSection_FileName))) {
44 fn = GetCasted(HeaderSection_FileName,
45 model->HeaderEntity(STANDARD_TYPE(HeaderSection_FileName)));
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)));
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)));
57 else done = Standard_False;
60 APIHeaderSection_MakeHeader::APIHeaderSection_MakeHeader
61 (const Standard_Integer 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;
72 void APIHeaderSection_MakeHeader::Init (const Standard_CString nameval)
79 if (fn.IsNull()) fn = new HeaderSection_FileName;
80 Handle(TCollection_HAsciiString) name = new TCollection_HAsciiString(nameval);
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);
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);
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);
113 // - File Description
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);
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);
138 Standard_Boolean APIHeaderSection_MakeHeader::IsDone() const
143 void APIHeaderSection_MakeHeader::Apply
144 (const Handle(StepData_StepModel)& model) const
146 Interface_EntityIterator header = model->Header();
147 if (HasFd() && !model->HasHeaderEntity (STANDARD_TYPE(HeaderSection_FileDescription)))
149 if (HasFn() && !model->HasHeaderEntity (STANDARD_TYPE(HeaderSection_FileName)))
151 if (HasFs() && !model->HasHeaderEntity (STANDARD_TYPE(HeaderSection_FileSchema))) {
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);
158 schid = new Interface_HArray1OfHAsciiString(1,1);
159 fs->SetSchemaIdentifiers(schid);
161 if (!sch.IsNull()) { if (sch->Length() < 2) sch.Nullify(); } // not defined
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);
171 model->ClearHeader();
172 for (header.Start(); header.More(); header.Next())
173 model->AddHeaderEntity(header.Value());
181 Handle(StepData_StepModel) APIHeaderSection_MakeHeader::NewModel
182 (const Handle(Interface_Protocol)& protocol) const
184 Handle(StepData_StepModel) stepmodel = new StepData_StepModel;
185 stepmodel->SetProtocol (protocol);
187 // - Make Header information
193 // ######## Individual Queries / Actions ########
199 Standard_Boolean APIHeaderSection_MakeHeader::HasFn() const
200 { return (!fn.IsNull()); }
202 Handle(HeaderSection_FileName) APIHeaderSection_MakeHeader::FnValue() const
208 void APIHeaderSection_MakeHeader::SetNameFromShapeType(const Standard_Integer shapetype)
210 Handle(TCollection_HAsciiString) name;
213 case 1: // face_based_surface_model
214 name = new TCollection_HAsciiString
215 ("Euclid Face Based Surface Model");
217 case 2: // manifold_solid_brep
218 name = new TCollection_HAsciiString
219 ("Euclid Manifold Solid Brep Model");
221 case 3: // facetted_brep
222 name = new TCollection_HAsciiString
223 ("Euclid Facetted Brep Model");
225 default : // others ?
226 name = new TCollection_HAsciiString
227 ("Euclid Shape Model");
234 void APIHeaderSection_MakeHeader::SetName(const Handle(TCollection_HAsciiString)& aName)
236 if (!fn.IsNull()) fn->SetName(aName);
239 Handle(TCollection_HAsciiString) APIHeaderSection_MakeHeader::Name() const
241 return (fn.IsNull() ? nulstr : fn->Name());
244 void APIHeaderSection_MakeHeader::SetTimeStamp(const Handle(TCollection_HAsciiString)& aTimeStamp)
246 if (!fn.IsNull()) fn->SetTimeStamp(aTimeStamp);
249 Handle(TCollection_HAsciiString) APIHeaderSection_MakeHeader::TimeStamp() const
251 return (fn.IsNull() ? nulstr : fn->TimeStamp());
254 void APIHeaderSection_MakeHeader::SetAuthor(const Handle(Interface_HArray1OfHAsciiString)& aAuthor)
256 if (!fn.IsNull()) fn->SetAuthor(aAuthor);
259 void APIHeaderSection_MakeHeader::SetAuthorValue(const Standard_Integer num, const Handle(TCollection_HAsciiString)& aAuthor)
261 if (fn.IsNull()) return;
262 Handle(Interface_HArray1OfHAsciiString) li = fn->Author();
263 if (num >= li->Lower() && num <= li->Upper()) li->SetValue(num,aAuthor);
266 Handle(Interface_HArray1OfHAsciiString) APIHeaderSection_MakeHeader::Author() const
268 return (fn.IsNull() ? nularr : fn->Author());
271 Handle(TCollection_HAsciiString) APIHeaderSection_MakeHeader::AuthorValue(const Standard_Integer num) const
273 return (fn.IsNull() ? nulstr : fn->AuthorValue(num));
276 Standard_Integer APIHeaderSection_MakeHeader::NbAuthor () const
278 return (fn.IsNull() ? 0 : fn->NbAuthor());
281 void APIHeaderSection_MakeHeader::SetOrganization(const Handle(Interface_HArray1OfHAsciiString)& aOrganization)
283 if (!fn.IsNull()) fn->SetOrganization(aOrganization);
286 void APIHeaderSection_MakeHeader::SetOrganizationValue(const Standard_Integer num, const Handle(TCollection_HAsciiString)& aOrgan)
288 if (fn.IsNull()) return;
289 Handle(Interface_HArray1OfHAsciiString) li = fn->Organization();
290 if (num >= li->Lower() && num <= li->Upper()) li->SetValue(num,aOrgan);
293 Handle(Interface_HArray1OfHAsciiString) APIHeaderSection_MakeHeader::Organization() const
295 return (fn.IsNull() ? nularr : fn->Organization());
298 Handle(TCollection_HAsciiString) APIHeaderSection_MakeHeader::OrganizationValue(const Standard_Integer num) const
300 return (fn.IsNull() ? nulstr : fn->OrganizationValue(num));
303 Standard_Integer APIHeaderSection_MakeHeader::NbOrganization () const
305 return (fn.IsNull() ? 0 : fn->NbOrganization());
308 void APIHeaderSection_MakeHeader::SetPreprocessorVersion(const Handle(TCollection_HAsciiString)& aPreprocessorVersion)
310 if (!fn.IsNull()) fn->SetPreprocessorVersion(aPreprocessorVersion);
313 Handle(TCollection_HAsciiString) APIHeaderSection_MakeHeader::PreprocessorVersion() const
315 return (fn.IsNull() ? nulstr : fn->PreprocessorVersion());
318 void APIHeaderSection_MakeHeader::SetOriginatingSystem(const Handle(TCollection_HAsciiString)& aOriginatingSystem)
320 if (!fn.IsNull()) fn->SetOriginatingSystem(aOriginatingSystem);
323 Handle(TCollection_HAsciiString) APIHeaderSection_MakeHeader::OriginatingSystem() const
325 return (fn.IsNull() ? nulstr : fn->OriginatingSystem());
328 void APIHeaderSection_MakeHeader::SetAuthorisation(const Handle(TCollection_HAsciiString)& aAuthorisation)
330 if (!fn.IsNull()) fn->SetAuthorisation(aAuthorisation);
333 Handle(TCollection_HAsciiString) APIHeaderSection_MakeHeader::Authorisation() const
335 return (fn.IsNull() ? nulstr : fn->Authorisation());
342 Standard_Boolean APIHeaderSection_MakeHeader::HasFs() const
343 { return (!fs.IsNull()); }
345 Handle(HeaderSection_FileSchema) APIHeaderSection_MakeHeader::FsValue() const
350 void APIHeaderSection_MakeHeader::SetSchemaIdentifiers(const Handle(Interface_HArray1OfHAsciiString)& aSchemaIdentifiers)
352 if (!fs.IsNull()) fs->SetSchemaIdentifiers(aSchemaIdentifiers);
355 void APIHeaderSection_MakeHeader::SetSchemaIdentifiersValue(const Standard_Integer num, const Handle(TCollection_HAsciiString)& aSchem)
357 if (fs.IsNull()) return;
358 Handle(Interface_HArray1OfHAsciiString) li = fs->SchemaIdentifiers();
359 if (num >= li->Lower() && num <= li->Upper()) li->SetValue(num,aSchem);
362 Handle(Interface_HArray1OfHAsciiString) APIHeaderSection_MakeHeader::SchemaIdentifiers() const
364 return (fs.IsNull() ? nularr : fs->SchemaIdentifiers());
367 Handle(TCollection_HAsciiString) APIHeaderSection_MakeHeader::SchemaIdentifiersValue(const Standard_Integer num) const
369 return (fs.IsNull() ? nulstr : fs->SchemaIdentifiersValue(num));
372 Standard_Integer APIHeaderSection_MakeHeader::NbSchemaIdentifiers () const
374 return (fs.IsNull() ? 0 : fs->NbSchemaIdentifiers());
377 //=======================================================================
378 //function : AddSchemaIdentifier
380 //=======================================================================
382 void APIHeaderSection_MakeHeader::AddSchemaIdentifier(const Handle(TCollection_HAsciiString)& aSchem)
384 if ( fs.IsNull() ) fs = new HeaderSection_FileSchema;
385 Handle(Interface_HArray1OfHAsciiString) idents = fs->SchemaIdentifiers();
387 // check that requested subschema is already in the list
389 for ( i=1; ! idents.IsNull() && i <= idents->Length(); i++ ) {
390 if ( aSchem->IsSameString ( idents->Value(i) ) ) return;
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) );
399 ids->SetValue ( i, aSchem );
401 fs->SetSchemaIdentifiers ( ids );
408 Standard_Boolean APIHeaderSection_MakeHeader::HasFd() const
409 { return (!fd.IsNull()); }
411 Handle(HeaderSection_FileDescription) APIHeaderSection_MakeHeader::FdValue() const
416 void APIHeaderSection_MakeHeader::SetDescription(const Handle(Interface_HArray1OfHAsciiString)& aDescription)
418 if (!fs.IsNull()) fd->SetDescription(aDescription);
421 void APIHeaderSection_MakeHeader::SetDescriptionValue(const Standard_Integer num, const Handle(TCollection_HAsciiString)& aDescr)
423 if (fd.IsNull()) return;
424 Handle(Interface_HArray1OfHAsciiString) li = fd->Description();
425 if (num >= li->Lower() && num <= li->Upper()) li->SetValue(num,aDescr);
428 Handle(Interface_HArray1OfHAsciiString) APIHeaderSection_MakeHeader::Description() const
430 return (fd.IsNull() ? nularr : fd->Description());
433 Handle(TCollection_HAsciiString) APIHeaderSection_MakeHeader::DescriptionValue(const Standard_Integer num) const
435 return (fd.IsNull() ? nulstr : fd->DescriptionValue(num));
438 Standard_Integer APIHeaderSection_MakeHeader::NbDescription () const
440 return (fd.IsNull() ? 0 : fd->NbDescription());
443 void APIHeaderSection_MakeHeader::SetImplementationLevel(const Handle(TCollection_HAsciiString)& aImplementationLevel)
445 if (!fd.IsNull()) fd->SetImplementationLevel(aImplementationLevel);
448 Handle(TCollection_HAsciiString) APIHeaderSection_MakeHeader::ImplementationLevel() const
450 return (fd.IsNull() ? nulstr : fd->ImplementationLevel());