Warnings on vc14 were eliminated
[occt.git] / src / StepAP209 / StepAP209_Construct.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
15 #include <HeaderSection_FileDescription.hxx>
16 #include <HeaderSection_FileName.hxx>
17 #include <HeaderSection_FileSchema.hxx>
18 #include <Interface_EntityIterator.hxx>
19 #include <Interface_HArray1OfHAsciiString.hxx>
20 #include <OSD_Process.hxx>
21 #include <Quantity_Date.hxx>
22 #include <StepAP203_CcDesignApproval.hxx>
23 #include <StepAP203_CcDesignDateAndTimeAssignment.hxx>
24 #include <StepAP203_CcDesignPersonAndOrganizationAssignment.hxx>
25 #include <StepAP203_CcDesignSecurityClassification.hxx>
26 #include <StepAP203_HArray1OfApprovedItem.hxx>
27 #include <StepAP203_HArray1OfClassifiedItem.hxx>
28 #include <StepAP203_HArray1OfDateTimeItem.hxx>
29 #include <StepAP203_HArray1OfPersonOrganizationItem.hxx>
30 #include <StepAP209_Construct.hxx>
31 #include <StepAP214_AppliedApprovalAssignment.hxx>
32 #include <StepAP214_AppliedDateAndTimeAssignment.hxx>
33 #include <StepAP214_AppliedPersonAndOrganizationAssignment.hxx>
34 #include <StepAP214_AppliedSecurityClassificationAssignment.hxx>
35 #include <StepAP214_ApprovalItem.hxx>
36 #include <StepAP214_DateAndTimeItem.hxx>
37 #include <StepAP214_HArray1OfApprovalItem.hxx>
38 #include <StepAP214_HArray1OfDateAndTimeItem.hxx>
39 #include <StepAP214_HArray1OfPersonAndOrganizationItem.hxx>
40 #include <StepAP214_HArray1OfSecurityClassificationItem.hxx>
41 #include <StepAP214_PersonAndOrganizationItem.hxx>
42 #include <StepAP214_SecurityClassificationItem.hxx>
43 #include <StepBasic_ApplicationContext.hxx>
44 #include <StepBasic_ApplicationProtocolDefinition.hxx>
45 #include <StepBasic_Approval.hxx>
46 #include <StepBasic_ApprovalDateTime.hxx>
47 #include <StepBasic_ApprovalPersonOrganization.hxx>
48 #include <StepBasic_ApprovalRole.hxx>
49 #include <StepBasic_ApprovalStatus.hxx>
50 #include <StepBasic_CalendarDate.hxx>
51 #include <StepBasic_CoordinatedUniversalTimeOffset.hxx>
52 #include <StepBasic_DateAndTime.hxx>
53 #include <StepBasic_DateTimeRole.hxx>
54 #include <StepBasic_DateTimeSelect.hxx>
55 #include <StepBasic_DesignContext.hxx>
56 #include <StepBasic_DimensionalExponents.hxx>
57 #include <StepBasic_HArray1OfNamedUnit.hxx>
58 #include <StepBasic_HArray1OfProduct.hxx>
59 #include <StepBasic_HArray1OfProductContext.hxx>
60 #include <StepBasic_HArray1OfUncertaintyMeasureWithUnit.hxx>
61 #include <StepBasic_LocalTime.hxx>
62 #include <StepBasic_MechanicalContext.hxx>
63 #include <StepBasic_Organization.hxx>
64 #include <StepBasic_Person.hxx>
65 #include <StepBasic_PersonAndOrganization.hxx>
66 #include <StepBasic_PersonAndOrganizationRole.hxx>
67 #include <StepBasic_PersonOrganizationSelect.hxx>
68 #include <StepBasic_Product.hxx>
69 #include <StepBasic_ProductCategory.hxx>
70 #include <StepBasic_ProductCategoryRelationship.hxx>
71 #include <StepBasic_ProductContext.hxx>
72 #include <StepBasic_ProductDefinition.hxx>
73 #include <StepBasic_ProductDefinitionContext.hxx>
74 #include <StepBasic_ProductDefinitionFormation.hxx>
75 #include <StepBasic_ProductDefinitionFormationRelationship.hxx>
76 #include <StepBasic_ProductRelatedProductCategory.hxx>
77 #include <StepBasic_SecurityClassification.hxx>
78 #include <StepBasic_SecurityClassificationLevel.hxx>
79 #include <StepBasic_SiUnitAndMassUnit.hxx>
80 #include <StepBasic_SiUnitAndThermodynamicTemperatureUnit.hxx>
81 #include <StepBasic_SiUnitAndTimeUnit.hxx>
82 #include <StepData_StepModel.hxx>
83 #include <StepElement_AnalysisItemWithinRepresentation.hxx>
84 #include <StepElement_ElementMaterial.hxx>
85 #include <StepFEA_CoordinateSystemType.hxx>
86 #include <StepFEA_Curve3dElementProperty.hxx>
87 #include <StepFEA_Curve3dElementRepresentation.hxx>
88 #include <StepFEA_CurveElementIntervalConstant.hxx>
89 #include <StepFEA_ElementGeometricRelationship.hxx>
90 #include <StepFEA_ElementRepresentation.hxx>
91 #include <StepFEA_FeaAxis2Placement3d.hxx>
92 #include <StepFEA_FeaModel.hxx>
93 #include <StepFEA_FeaModel3d.hxx>
94 #include <StepFEA_FeaModelDefinition.hxx>
95 #include <StepFEA_HArray1OfCurveElementInterval.hxx>
96 #include <StepFEA_Surface3dElementRepresentation.hxx>
97 #include <StepFEA_Volume3dElementRepresentation.hxx>
98 #include <StepGeom_CartesianPoint.hxx>
99 #include <StepGeom_Direction.hxx>
100 #include <StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext.hxx>
101 #include <StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx.hxx>
102 #include <StepRepr_GlobalUncertaintyAssignedContext.hxx>
103 #include <StepRepr_GlobalUnitAssignedContext.hxx>
104 #include <StepRepr_HArray1OfRepresentationItem.hxx>
105 #include <StepRepr_ProductDefinitionShape.hxx>
106 #include <StepRepr_PropertyDefinitionRepresentation.hxx>
107 #include <StepRepr_RepresentationItem.hxx>
108 #include <StepRepr_ShapeRepresentationRelationship.hxx>
109 #include <StepRepr_StructuralResponseProperty.hxx>
110 #include <StepRepr_StructuralResponsePropertyDefinitionRepresentation.hxx>
111 #include <StepShape_ShapeDefinitionRepresentation.hxx>
112 #include <StepShape_ShapeRepresentation.hxx>
113 #include <TCollection_HAsciiString.hxx>
114 #include <TColStd_HArray1OfAsciiString.hxx>
115 #include <TColStd_HArray1OfReal.hxx>
116 #include <XSControl_WorkSession.hxx>
117
118 //#include <.hxx>
119 //=======================================================================
120 //function : StepAP209_Construct
121 //purpose  : 
122 //=======================================================================
123 StepAP209_Construct::StepAP209_Construct () 
124 {
125 }
126      
127 //=======================================================================
128 //function : StepAP209_Construct
129 //purpose  : 
130 //=======================================================================
131
132 StepAP209_Construct::StepAP209_Construct (const Handle(XSControl_WorkSession) &WS)
133      : STEPConstruct_Tool ( WS )
134 {
135 }
136
137 //=======================================================================
138 //function : Init
139 //purpose  : 
140 //=======================================================================
141
142 Standard_Boolean StepAP209_Construct::Init (const Handle(XSControl_WorkSession) &WS)
143 {
144   return SetWS ( WS );
145 }
146
147
148 //=======================================================================
149 //function : IsDesing
150 //purpose  : 
151 //=======================================================================
152
153 Standard_Boolean StepAP209_Construct::IsDesing (const Handle(StepBasic_ProductDefinitionFormation) &PDF) const
154 {
155   Interface_EntityIterator subs = Graph().Sharings(PDF);
156   for (subs.Start(); subs.More(); subs.Next()) {
157     Handle(StepBasic_ProductDefinitionFormationRelationship) PDFR = 
158       Handle(StepBasic_ProductDefinitionFormationRelationship)::DownCast(subs.Value());
159     if(PDFR.IsNull()) continue;
160     if ( PDF == PDFR->RelatingProductDefinitionFormation() ) return Standard_True;
161   }
162   return Standard_False;
163 }
164
165
166 //=======================================================================
167 //function : IsAnalys
168 //purpose  : 
169 //=======================================================================
170
171 Standard_Boolean StepAP209_Construct::IsAnalys (const Handle(StepBasic_ProductDefinitionFormation) &PDF) const
172 {
173   Interface_EntityIterator subs = Graph().Sharings(PDF);
174   for (subs.Start(); subs.More(); subs.Next()) {
175     Handle(StepBasic_ProductDefinitionFormationRelationship) PDFR = 
176       Handle(StepBasic_ProductDefinitionFormationRelationship)::DownCast(subs.Value());
177     if(PDFR.IsNull()) continue;
178     if ( PDF == PDFR->RelatedProductDefinitionFormation() ) return Standard_True;
179   }
180   return Standard_False;
181 }
182
183
184 //=======================================================================
185 //function : GetElementMaterial
186 //purpose  : 
187 //=======================================================================
188
189 Handle(StepElement_HSequenceOfElementMaterial) StepAP209_Construct::GetElementMaterial() const
190 {
191   Handle(StepElement_HSequenceOfElementMaterial) aSequence =
192     new StepElement_HSequenceOfElementMaterial;
193   Handle(Interface_InterfaceModel) model = Model();
194   Standard_Integer nb = model->NbEntities();
195   for(Standard_Integer i=1; i<=nb; i++) {
196     Handle(Standard_Transient) anEntity = model->Value(i);
197     if(anEntity->IsKind(STANDARD_TYPE(StepElement_ElementMaterial))) {
198       Handle(StepElement_ElementMaterial) anElement =
199         Handle(StepElement_ElementMaterial)::DownCast(anEntity);
200       aSequence->Append(anElement);
201     }
202   }
203   return aSequence;
204 }
205
206
207 //=======================================================================
208 //function : GetElemGeomRelat
209 //purpose  : 
210 //=======================================================================
211
212 Handle(StepFEA_HSequenceOfElementGeometricRelationship) StepAP209_Construct::GetElemGeomRelat() const
213 {
214   Handle(StepFEA_HSequenceOfElementGeometricRelationship) aSequence =
215     new StepFEA_HSequenceOfElementGeometricRelationship;
216   Handle(Interface_InterfaceModel) model = Model();
217   Standard_Integer nb = model->NbEntities();
218   for(Standard_Integer i=1; i<=nb; i++) {
219     Handle(Standard_Transient) anEntity = model->Value(i);
220     if(anEntity->IsKind(STANDARD_TYPE(StepFEA_ElementGeometricRelationship))) {
221       Handle(StepFEA_ElementGeometricRelationship) EGR =
222         Handle(StepFEA_ElementGeometricRelationship)::DownCast(anEntity);
223       aSequence->Append(EGR);
224     }
225   }
226   return aSequence;
227 }
228
229
230 //=======================================================================
231 //function : GetShReprForElem
232 //purpose  : 
233 //=======================================================================
234
235 Handle(StepShape_ShapeRepresentation) StepAP209_Construct::GetShReprForElem
236        (const Handle(StepFEA_ElementRepresentation) &ElemRepr) const
237 {
238   Handle(StepShape_ShapeRepresentation) SR;
239   if(ElemRepr.IsNull()) return SR;
240   Interface_EntityIterator subs = Graph().Sharings(ElemRepr);
241   for (subs.Start(); subs.More() && SR.IsNull() ; subs.Next()) {
242     Handle(StepFEA_ElementGeometricRelationship) EGR =
243       Handle(StepFEA_ElementGeometricRelationship)::DownCast(subs.Value());
244     if(EGR.IsNull()) continue;
245     Handle(StepElement_AnalysisItemWithinRepresentation) AIWR = EGR->Item();
246     if(AIWR.IsNull()) continue;
247     Handle(StepRepr_Representation) Repr = AIWR->Rep();
248     if(Repr.IsNull()) continue;
249     SR = Handle(StepShape_ShapeRepresentation)::DownCast(Repr);
250   }
251   return SR;
252 }
253
254
255
256 //     methods for getting fea_model
257
258
259 //=======================================================================
260 //function : FeaModel
261 //purpose  : 
262 //=======================================================================
263
264 Handle(StepFEA_FeaModel) StepAP209_Construct::FeaModel (const Handle(StepBasic_Product) &Prod) const
265 {
266   Handle(StepFEA_FeaModel) FM;
267   if(Prod.IsNull()) return FM;
268   Interface_EntityIterator subs = Graph().Sharings(Prod);
269   for (subs.Start(); subs.More() && FM.IsNull() ; subs.Next()) {
270     Handle(StepBasic_ProductDefinitionFormation) PDF =
271       Handle(StepBasic_ProductDefinitionFormation)::DownCast(subs.Value());
272     if ( PDF.IsNull() ) continue;
273     FM = FeaModel(PDF);
274   }
275   return FM;
276 }
277
278
279 //=======================================================================
280 //function : FeaModel
281 //purpose  : 
282 //=======================================================================
283
284 Handle(StepFEA_FeaModel) StepAP209_Construct::FeaModel (const Handle(StepBasic_ProductDefinition) &PD) const
285 {
286   //Handle(Interface_InterfaceModel) model = Model();
287   //Standard_Integer nb = model->NbEntities();
288   Handle(StepFEA_FeaModel) FM;
289   if(PD.IsNull()) return FM;
290   Interface_EntityIterator subs = Graph().Shareds(PD);
291   for (subs.Start(); subs.More() && FM.IsNull() ; subs.Next()) {
292     Handle(StepBasic_ProductDefinitionFormation) PDF =
293       Handle(StepBasic_ProductDefinitionFormation)::DownCast(subs.Value());
294     if ( PDF.IsNull() ) continue;
295     FM = FeaModel(PDF);
296   }
297   return FM;
298 }
299
300
301 //=======================================================================
302 //function : FeaModel
303 //purpose  : 
304 //=======================================================================
305
306 Handle(StepFEA_FeaModel) StepAP209_Construct::FeaModel (const Handle(StepBasic_ProductDefinitionFormation) &PDF) const
307 {
308   Handle(StepFEA_FeaModel) FM;
309   if(PDF.IsNull()) return FM;
310   Handle(StepBasic_ProductDefinitionFormation) PDF2;
311   Interface_EntityIterator subs = Graph().Sharings(PDF);
312   for (subs.Start(); subs.More(); subs.Next()) {
313     Handle(StepBasic_ProductDefinitionFormationRelationship) PDFR = 
314       Handle(StepBasic_ProductDefinitionFormationRelationship)::DownCast(subs.Value());
315     if(PDFR.IsNull()) continue;
316     PDF2 = PDFR->RelatedProductDefinitionFormation();
317   }
318   if(PDF2.IsNull() ) return FM;
319   subs = Graph().Sharings(PDF2);
320   for (subs.Start(); subs.More() && FM.IsNull() ; subs.Next()) {
321     Handle(StepBasic_ProductDefinition) PD =
322       Handle(StepBasic_ProductDefinition)::DownCast(subs.Value());
323     if(PD.IsNull()) continue;
324     Interface_EntityIterator subs2 = Graph().Sharings(PD);
325     for (subs2.Start(); subs2.More() && FM.IsNull() ; subs2.Next()) {
326       Handle(StepRepr_ProductDefinitionShape) PDS =
327         Handle(StepRepr_ProductDefinitionShape)::DownCast(subs2.Value());
328       if(PDS.IsNull()) continue;
329       FM = FeaModel(PDS);
330     }
331   }
332   return FM;
333 }
334
335
336 //=======================================================================
337 //function : FeaModel
338 //purpose  : 
339 //=======================================================================
340
341 Handle(StepFEA_FeaModel) StepAP209_Construct::FeaModel (const Handle(StepRepr_ProductDefinitionShape)& PDS) const
342 {
343   Handle(StepFEA_FeaModel) FM;
344   Interface_EntityIterator subs = Graph().Sharings(PDS);
345   for (subs.Start(); subs.More() && FM.IsNull() ; subs.Next()) {
346     Handle(StepFEA_FeaModelDefinition) FMD = Handle(StepFEA_FeaModelDefinition)::DownCast(subs.Value());
347     if(FMD.IsNull()) continue;
348     Interface_EntityIterator subs2 = Graph().Sharings(FMD);
349     for (subs2.Start(); subs2.More() && FM.IsNull() ; subs2.Next()) {
350       //ENTITY structural_response_property - SUBTYPE OF (property_definition);
351       Handle(StepRepr_StructuralResponseProperty) SRP = 
352         Handle(StepRepr_StructuralResponseProperty)::DownCast(subs2.Value());
353       if(SRP.IsNull()) continue;
354       Interface_EntityIterator subs3 = Graph().Sharings(SRP);
355       for (subs3.Start(); subs3.More() && FM.IsNull() ; subs3.Next()) {
356         //ENTITY structural_response_property_definition_representation -
357         //SUBTYPE OF (property_definition_representation);
358         Handle(StepRepr_StructuralResponsePropertyDefinitionRepresentation) SRPDR = 
359           Handle(StepRepr_StructuralResponsePropertyDefinitionRepresentation)::DownCast(subs3.Value());
360         if(SRPDR.IsNull()) continue;
361         Handle(StepRepr_Representation) Repr = SRPDR->UsedRepresentation();
362         if ( Repr.IsNull() ) continue;
363         if (Repr->IsKind(STANDARD_TYPE(StepFEA_FeaModel)))
364           FM = Handle(StepFEA_FeaModel)::DownCast(Repr);
365       }
366     }
367   }
368   return FM;
369 }
370
371
372 //=======================================================================
373 //function : GetFeaAxis2Placement3D
374 //purpose  : 
375 //=======================================================================
376
377 Handle(StepFEA_FeaAxis2Placement3d) StepAP209_Construct::GetFeaAxis2Placement3d
378        (const Handle(StepFEA_FeaModel)& theFeaModel) const 
379 {
380   Handle(StepFEA_FeaAxis2Placement3d) FA2P3D = new StepFEA_FeaAxis2Placement3d;
381   if(theFeaModel.IsNull()) return FA2P3D;
382   Interface_EntityIterator subs = Graph().Shareds(theFeaModel);
383   for (subs.Start(); subs.More(); subs.Next()) {
384     FA2P3D =  Handle(StepFEA_FeaAxis2Placement3d)::DownCast(subs.Value());
385     if(FA2P3D.IsNull()) continue;
386     return FA2P3D;
387   }
388   return FA2P3D;
389 }
390
391
392 //     methods for getting idealized_analysis_shape
393
394
395 //=======================================================================
396 //function : IdealShape
397 //purpose  : 
398 //=======================================================================
399
400 Handle(StepShape_ShapeRepresentation) StepAP209_Construct::IdealShape (const Handle(StepBasic_Product) &Prod) const
401 {
402   Handle(StepShape_ShapeRepresentation) SR;
403   if(Prod.IsNull()) return SR;
404   Interface_EntityIterator subs = Graph().Sharings(Prod);
405   for (subs.Start(); subs.More() && SR.IsNull() ; subs.Next()) {
406     Handle(StepBasic_ProductDefinitionFormation) PDF =
407       Handle(StepBasic_ProductDefinitionFormation)::DownCast(subs.Value());
408     if ( PDF.IsNull() ) continue;
409     SR = IdealShape(PDF);
410   }
411   return SR;
412 }
413
414
415 //=======================================================================
416 //function : IdealShape
417 //purpose  : 
418 //=======================================================================
419
420 Handle(StepShape_ShapeRepresentation) StepAP209_Construct::IdealShape (const Handle(StepBasic_ProductDefinition) &PD) const
421 {
422   Handle(StepShape_ShapeRepresentation) SR;
423   if(PD.IsNull()) return SR;
424   Interface_EntityIterator subs = Graph().Shareds(PD);
425   for (subs.Start(); subs.More() && SR.IsNull() ; subs.Next()) {
426     Handle(StepBasic_ProductDefinitionFormation) PDF =
427       Handle(StepBasic_ProductDefinitionFormation)::DownCast(subs.Value());
428     if ( PDF.IsNull() ) continue;
429     SR = IdealShape(PDF);
430   }
431   return SR;
432 }
433
434
435 //=======================================================================
436 //function : IdealShape
437 //purpose  : 
438 //=======================================================================
439
440 Handle(StepShape_ShapeRepresentation) StepAP209_Construct::IdealShape (const Handle(StepBasic_ProductDefinitionFormation) &PDF) const
441 {
442   Handle(StepShape_ShapeRepresentation) SR;
443   if(PDF.IsNull()) return SR;
444   Handle(StepBasic_ProductDefinitionFormation) PDF2;
445   Interface_EntityIterator subs = Graph().Sharings(PDF);
446   for (subs.Start(); subs.More(); subs.Next()) {
447     Handle(StepBasic_ProductDefinitionFormationRelationship) PDFR = 
448       Handle(StepBasic_ProductDefinitionFormationRelationship)::DownCast(subs.Value());
449     if(PDFR.IsNull()) continue;
450     PDF2 = PDFR->RelatedProductDefinitionFormation();
451   }
452   if(PDF2.IsNull() ) return SR;
453   subs = Graph().Sharings(PDF2);
454   for (subs.Start(); subs.More() && SR.IsNull() ; subs.Next()) {
455     Handle(StepBasic_ProductDefinition) PD =
456       Handle(StepBasic_ProductDefinition)::DownCast(subs.Value());
457     if(PD.IsNull()) continue;
458     Interface_EntityIterator subs2 = Graph().Sharings(PD);
459     for (subs2.Start(); subs2.More() && SR.IsNull() ; subs2.Next()) {
460       Handle(StepRepr_ProductDefinitionShape) PDS =
461         Handle(StepRepr_ProductDefinitionShape)::DownCast(subs2.Value());
462       if(PDS.IsNull()) continue;
463       SR = IdealShape(PDS);
464     }
465   }
466   return SR;
467 }
468
469
470 //=======================================================================
471 //function : IdealShape
472 //purpose  : 
473 //=======================================================================
474
475 Handle(StepShape_ShapeRepresentation) StepAP209_Construct::IdealShape (const Handle(StepRepr_ProductDefinitionShape)& PDS) const
476 {
477   Handle(StepShape_ShapeRepresentation) SR;
478   Interface_EntityIterator subs = Graph().Sharings(PDS);
479   for (subs.Start(); subs.More() && SR.IsNull() ; subs.Next()) {
480     Handle(StepShape_ShapeDefinitionRepresentation) SDR =
481       Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
482     if(SDR.IsNull()) continue;
483     SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation());
484   }
485   return SR;
486 }
487
488
489 //     methods for getting nominal_design_shape
490
491
492 //=======================================================================
493 //function : NominShape
494 //purpose  : 
495 //=======================================================================
496
497 Handle(StepShape_ShapeRepresentation) StepAP209_Construct::NominShape (const Handle(StepBasic_Product) &Prod) const
498 {
499   Handle(StepShape_ShapeRepresentation) SR;
500   if(Prod.IsNull()) return SR;
501   Interface_EntityIterator subs = Graph().Sharings(Prod);
502   for (subs.Start(); subs.More() && SR.IsNull() ; subs.Next()) {
503     Handle(StepBasic_ProductDefinitionFormation) PDF =
504       Handle(StepBasic_ProductDefinitionFormation)::DownCast(subs.Value());
505     if ( PDF.IsNull() ) continue;
506     SR = NominShape(PDF);
507   }
508   return SR;
509 }
510
511
512 //=======================================================================
513 //function : NominShape
514 //purpose  : 
515 //=======================================================================
516
517 Handle(StepShape_ShapeRepresentation) StepAP209_Construct::NominShape (const Handle(StepBasic_ProductDefinitionFormation) &PDF) const
518 {
519   Handle(StepShape_ShapeRepresentation) SR;
520   if(PDF.IsNull()) return SR;
521   Handle(StepBasic_ProductDefinitionFormation) PDF2;
522   Interface_EntityIterator subs = Graph().Sharings(PDF);
523   for (subs.Start(); subs.More(); subs.Next()) {
524     Handle(StepBasic_ProductDefinitionFormationRelationship) PDFR = 
525       Handle(StepBasic_ProductDefinitionFormationRelationship)::DownCast(subs.Value());
526     if(PDFR.IsNull()) continue;
527     PDF2 = PDFR->RelatingProductDefinitionFormation();
528   }
529   if(PDF2.IsNull() ) return SR;
530   subs = Graph().Sharings(PDF2);
531   for (subs.Start(); subs.More() && SR.IsNull() ; subs.Next()) {
532     Handle(StepBasic_ProductDefinition) PD =
533       Handle(StepBasic_ProductDefinition)::DownCast(subs.Value());
534     if(PD.IsNull()) continue;
535     Interface_EntityIterator subs2 = Graph().Sharings(PD);
536     for (subs2.Start(); subs2.More() && SR.IsNull() ; subs2.Next()) {
537       Handle(StepRepr_ProductDefinitionShape) PDS =
538         Handle(StepRepr_ProductDefinitionShape)::DownCast(subs2.Value());
539       if(PDS.IsNull()) continue;
540       Interface_EntityIterator subs3 = Graph().Sharings(PDS);
541       for (subs3.Start(); subs3.More() && SR.IsNull() ; subs3.Next()) {
542         Handle(StepShape_ShapeDefinitionRepresentation) SDR =
543           Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs3.Value());
544         if(SDR.IsNull()) continue;
545         SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation());
546       }
547     }
548   }
549   return SR;
550 }
551
552
553
554 //=======================================================================
555 //function : GetElements1D
556 //purpose  : 
557 //=======================================================================
558
559 Handle(StepFEA_HSequenceOfElementRepresentation) StepAP209_Construct::GetElements1D
560        (const Handle(StepFEA_FeaModel)& theFeaModel) const 
561 {
562   return GetFeaElements(theFeaModel,STANDARD_TYPE(StepFEA_Curve3dElementRepresentation));
563 }
564
565
566 //=======================================================================
567 //function : GetElements2D
568 //purpose  : 
569 //=======================================================================
570
571 Handle(StepFEA_HSequenceOfElementRepresentation) StepAP209_Construct::GetElements2D
572        (const Handle(StepFEA_FeaModel)& theFeaModel) const 
573 {
574   return GetFeaElements(theFeaModel,STANDARD_TYPE(StepFEA_Surface3dElementRepresentation));
575 }
576
577
578 //=======================================================================
579 //function : GetElements3D
580 //purpose  : 
581 //=======================================================================
582
583 Handle(StepFEA_HSequenceOfElementRepresentation) StepAP209_Construct::GetElements3D
584        (const Handle(StepFEA_FeaModel)& theFeaModel) const 
585 {
586   return GetFeaElements(theFeaModel,STANDARD_TYPE(StepFEA_Volume3dElementRepresentation));
587 }
588
589
590 //=======================================================================
591 //function : GetFeaElements
592 //purpose  : 
593 //=======================================================================
594
595 Handle(StepFEA_HSequenceOfElementRepresentation) StepAP209_Construct::GetFeaElements
596        (const Handle(StepFEA_FeaModel)& theFeaModel,
597         const Handle(Standard_Type)& theType) const
598 {
599   Handle(StepFEA_HSequenceOfElementRepresentation) aSequence;
600   if( !theType->SubType(STANDARD_TYPE(StepFEA_ElementRepresentation)))
601     return aSequence;
602   
603   Interface_EntityIterator anIter = Graph().Sharings(theFeaModel);
604   anIter.Start();
605   if(anIter.More())
606     aSequence = new StepFEA_HSequenceOfElementRepresentation;
607   
608   for (; anIter.More(); anIter.Next()) {
609     Handle(Standard_Transient) anEntity = anIter.Value();
610     if(anEntity->IsKind(theType)) {
611       Handle(StepFEA_ElementRepresentation) anElement =
612         Handle(StepFEA_ElementRepresentation)::DownCast(anEntity);
613       aSequence->Append(anElement);
614     }
615   }
616   return aSequence;
617
618 }
619
620
621 //=======================================================================
622 //function : GetFeaElements
623 //purpose  : 
624 //=======================================================================
625
626 Handle(StepElement_HSequenceOfCurveElementSectionDefinition) StepAP209_Construct::GetCurElemSection
627        (const Handle(StepFEA_Curve3dElementRepresentation)& ElemRepr) const
628 {
629   Handle(StepElement_HSequenceOfCurveElementSectionDefinition) aSequence =
630     new StepElement_HSequenceOfCurveElementSectionDefinition;
631   if(ElemRepr.IsNull()) return aSequence;
632   
633   Handle(StepFEA_Curve3dElementProperty) C3dEP = ElemRepr->Property();
634   if(C3dEP.IsNull()) return aSequence;
635
636   Handle(StepFEA_HArray1OfCurveElementInterval) ACEI = C3dEP->IntervalDefinitions();
637   if(ACEI.IsNull()) return aSequence;
638
639   for(Standard_Integer i=1; i<=ACEI->Length(); i++) {
640     Handle(StepFEA_CurveElementIntervalConstant) CEIC =
641       Handle(StepFEA_CurveElementIntervalConstant)::DownCast(ACEI->Value(i));
642     if(CEIC.IsNull()) continue;
643     aSequence->Append(CEIC->Section());
644   }
645   return aSequence;
646 }
647
648
649 //=======================================================================
650 //function : CreateAnalysStructure
651 //purpose  : 
652 //=======================================================================
653
654 Standard_Boolean StepAP209_Construct::CreateAnalysStructure (const Handle(StepBasic_Product) &Prod) const
655 {
656   if(Prod.IsNull()) return Standard_False;
657   Interface_EntityIterator subs = Graph().Sharings(Prod);
658   Handle(StepBasic_ProductDefinitionFormation) PDF;
659   for (subs.Start(); subs.More() && PDF.IsNull() ; subs.Next()) {
660     PDF = Handle(StepBasic_ProductDefinitionFormation)::DownCast(subs.Value());
661     if(PDF.IsNull()) continue;
662   }
663   if(PDF.IsNull()) return Standard_False;
664   //if( IsDesing(PDF) || IsAnalys(PDF) ) return Standard_False;
665
666   // find nominal_design_shape:
667   Handle(StepShape_ShapeRepresentation) SR;
668   Handle(StepBasic_ProductDefinition) PD;
669   subs = Graph().Sharings(PDF);
670   for (subs.Start(); subs.More() && SR.IsNull() ; subs.Next()) {
671     PD = Handle(StepBasic_ProductDefinition)::DownCast(subs.Value());
672     if(PD.IsNull()) continue;
673     Interface_EntityIterator subs2 = Graph().Sharings(PD);
674     for (subs2.Start(); subs2.More() && SR.IsNull() ; subs2.Next()) {
675       Handle(StepRepr_ProductDefinitionShape) PDS =
676         Handle(StepRepr_ProductDefinitionShape)::DownCast(subs2.Value());
677       if(PDS.IsNull()) continue;
678       Interface_EntityIterator subs3 = Graph().Sharings(PDS);
679       for (subs3.Start(); subs3.More() && SR.IsNull() ; subs3.Next()) {
680         Handle(StepShape_ShapeDefinitionRepresentation) SDR =
681           Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs3.Value());
682         if(SDR.IsNull()) continue;
683         SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation());
684       }
685     }
686   }
687   if(SR.IsNull()) return Standard_False; // no nominal_design_shape
688   
689   // create structure:
690   ReplaceCcDesingToApplied();
691   Handle(StepData_StepModel) smodel = Handle(StepData_StepModel)::DownCast(Model());
692
693   // replace existing contexts for using AP209
694   Handle(StepBasic_ProductContext) OldProdCtx = Prod->FrameOfReferenceValue(1);
695   if(!OldProdCtx.IsNull()) {
696     Handle(StepBasic_ProductContext) ProdCtx = new StepBasic_ProductContext;
697     ProdCtx->Init(OldProdCtx->Name(),
698                   OldProdCtx->FrameOfReference(),
699                   OldProdCtx->DisciplineType());
700     smodel->ReplaceEntity(smodel->Number(OldProdCtx),ProdCtx);
701     smodel->SetIdentLabel(ProdCtx, smodel->Number(ProdCtx));
702     Handle(StepBasic_HArray1OfProductContext) HAPC = Prod->FrameOfReference();
703     HAPC->SetValue(1,ProdCtx);
704     Prod->SetFrameOfReference(HAPC);
705   }
706   Handle(StepBasic_ProductDefinitionContext) OldPDCtx = PD->FrameOfReference();
707   if(!OldPDCtx.IsNull()) {
708     Handle(StepBasic_ProductDefinitionContext) PDCtx = new StepBasic_ProductDefinitionContext;
709     PDCtx->Init(OldPDCtx->Name(),
710                 OldPDCtx->FrameOfReference(),
711                 OldPDCtx->LifeCycleStage());
712     smodel->ReplaceEntity(smodel->Number(OldPDCtx),PDCtx);
713     smodel->SetIdentLabel(PDCtx, smodel->Number(PDCtx));
714     PD->SetFrameOfReference(PDCtx);
715   }
716
717   // add idealized_analys_shape:
718   Handle(StepShape_ShapeRepresentation) AnaSR = new StepShape_ShapeRepresentation;
719   Handle(StepRepr_RepresentationItem) RI = new StepRepr_RepresentationItem;
720   RI = SR->ItemsValue(1);
721   smodel->AddWithRefs(RI); // add new representation_item
722   smodel->SetIdentLabel(RI, smodel->Number(RI));
723   Handle(StepRepr_HArray1OfRepresentationItem) ARI = new StepRepr_HArray1OfRepresentationItem(1,1);
724   ARI->SetValue(1,RI);
725   AnaSR->Init(new TCollection_HAsciiString("idealized_analysis_shape"),
726               ARI, SR->ContextOfItems());
727   smodel->AddWithRefs(AnaSR); // add idealized_analys_shape
728   smodel->SetIdentLabel(AnaSR, smodel->Number(AnaSR));
729   
730   // add product:
731   Handle(StepBasic_Product) AnaProd = new StepBasic_Product;
732   AnaProd->Init(new TCollection_HAsciiString(""), new TCollection_HAsciiString("analysis"),
733                 new TCollection_HAsciiString("analysis product"), Prod->FrameOfReference());
734   smodel->AddWithRefs(AnaProd);
735   smodel->SetIdentLabel(AnaProd, smodel->Number(AnaProd));
736
737   // add product_definition_formation:
738   Handle(StepBasic_ProductDefinitionFormation) AnaPDF =
739     new StepBasic_ProductDefinitionFormation;
740   AnaPDF->Init(new TCollection_HAsciiString(""),
741                new TCollection_HAsciiString("analysis version"), AnaProd);
742   smodel->AddWithRefs(AnaPDF);
743   smodel->SetIdentLabel(AnaPDF, smodel->Number(AnaPDF));
744
745   // add product_definition_formation_relationship:
746   Handle(StepBasic_ProductDefinitionFormationRelationship) PDFR =
747     new StepBasic_ProductDefinitionFormationRelationship;
748   PDFR->Init(new TCollection_HAsciiString(""),
749              new TCollection_HAsciiString("analysis design version relationship"),
750              new TCollection_HAsciiString(""), PDF, AnaPDF);
751   smodel->AddWithRefs(PDFR);
752   smodel->SetIdentLabel(PDFR, smodel->Number(PDFR));
753
754   // add product_definition:
755   Handle(StepBasic_ProductDefinition) AnaPD = new StepBasic_ProductDefinition;
756   Handle(StepBasic_ProductDefinitionContext) AnaPDC =
757     new StepBasic_ProductDefinitionContext;
758   Handle(StepBasic_ApplicationContext) AC = Prod->FrameOfReferenceValue(1)->FrameOfReference();
759   AnaPDC->Init(new TCollection_HAsciiString("analysis"), AC,
760                new TCollection_HAsciiString("analysis") );
761   smodel->AddWithRefs(AnaPDC); // add new product_definition_context
762   smodel->SetIdentLabel(AnaPDC, smodel->Number(AnaPDC));
763   AnaPD->Init(new TCollection_HAsciiString("analysis"), 
764               new TCollection_HAsciiString("analysis discipline product definition"),
765               AnaPDF, AnaPDC);
766   smodel->AddWithRefs(AnaPD); // add new product_definition
767   smodel->SetIdentLabel(AnaPD, smodel->Number(AnaPD));
768
769   // add product_definition_shape:
770   Handle(StepRepr_ProductDefinitionShape) AnaPDS = new StepRepr_ProductDefinitionShape;
771   StepRepr_CharacterizedDefinition ChDef;
772   ChDef.SetValue(AnaPD);
773   AnaPDS->Init(new TCollection_HAsciiString(""), Standard_True,
774                new TCollection_HAsciiString("analysis shape"), ChDef);
775   smodel->AddWithRefs(AnaPDS);
776   smodel->SetIdentLabel(AnaPDS, smodel->Number(AnaPDS));
777
778   // add shape_definition_representation:
779   Handle(StepShape_ShapeDefinitionRepresentation) AnaSDR = new StepShape_ShapeDefinitionRepresentation;
780   StepRepr_RepresentedDefinition RepDef;
781   RepDef.SetValue(AnaPDS);
782   AnaSDR->Init(RepDef, AnaSR);
783   smodel->AddWithRefs(AnaSDR);
784   smodel->SetIdentLabel(AnaSDR, smodel->Number(AnaSDR));
785
786   // add shape_representation_relationship:
787   Handle(StepRepr_ShapeRepresentationRelationship) SRR =
788     new StepRepr_ShapeRepresentationRelationship;
789   SRR->Init(new TCollection_HAsciiString("basis"), new TCollection_HAsciiString(""), AnaSR, SR);
790   smodel->AddWithRefs(SRR);
791   smodel->SetIdentLabel(SRR, smodel->Number(SRR));
792
793   CreateAddingEntities(AnaPD);
794
795
796   WS()->ComputeGraph(Standard_True);
797   WS()->ComputeCheck(Standard_True);
798
799   return Standard_True;
800 }
801
802
803 //=======================================================================
804 //function : CreateFeaStructure
805 //purpose  : 
806 //=======================================================================
807
808 Standard_Boolean StepAP209_Construct::CreateFeaStructure (const Handle(StepBasic_Product) &Prod) const
809 {
810   if(Prod.IsNull()) {
811 #ifdef OCCT_DEBUG
812     cout<<"Prod.IsNull()"<<endl;
813 #endif
814     return Standard_False;
815   }
816   Handle(StepShape_ShapeRepresentation) AnaSR = IdealShape(Prod);
817   if(AnaSR.IsNull()) {
818 #ifdef OCCT_DEBUG
819     cout<<"AnaSR.IsNull()"<<endl;
820 #endif
821     return Standard_False;
822   }
823   Handle(StepRepr_ProductDefinitionShape) AnaPDS;
824   Interface_EntityIterator subs = Graph().Sharings(AnaSR);
825   for (subs.Start(); subs.More() && AnaPDS.IsNull(); subs.Next()) {
826     Handle(StepShape_ShapeDefinitionRepresentation) SDR =
827       Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
828     if ( SDR.IsNull() ) continue;
829     AnaPDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(SDR->Definition().Value());
830   }
831
832   //Handle(Interface_InterfaceModel) model = Model();
833   Handle(StepData_StepModel) smodel = Handle(StepData_StepModel)::DownCast(Model());
834
835   // add fea_model_definition
836   Handle(StepFEA_FeaModelDefinition) FMD = new StepFEA_FeaModelDefinition;
837   FMD->Init(new TCollection_HAsciiString("FEA_MODEL"),
838             new TCollection_HAsciiString("FEA_MODEL"), AnaPDS, StepData_LFalse);
839   smodel->AddWithRefs(FMD);
840   smodel->SetIdentLabel(FMD, smodel->Number(FMD));
841
842   // add fea_axis2_placement_3d
843   Handle(StepFEA_FeaAxis2Placement3d) FA2P3D = new StepFEA_FeaAxis2Placement3d;
844   Handle(StepGeom_CartesianPoint) SGCP = new StepGeom_CartesianPoint;
845   SGCP->Init3D(new TCollection_HAsciiString(""), 0., 0., 0.);
846   Handle(TColStd_HArray1OfReal) ArrTmp = new TColStd_HArray1OfReal(1,3);
847   ArrTmp->SetValue(1,0.);
848   ArrTmp->SetValue(2,0.);
849   ArrTmp->SetValue(3,1.);
850   Handle(StepGeom_Direction) SGD1 = new StepGeom_Direction;
851   SGD1->Init(new TCollection_HAsciiString(""), ArrTmp);
852   ArrTmp->SetValue(1,1.);
853   ArrTmp->SetValue(2,0.);
854   ArrTmp->SetValue(3,0.);
855   Handle(StepGeom_Direction) SGD2 = new StepGeom_Direction;
856   SGD2->Init(new TCollection_HAsciiString(""), ArrTmp);
857   FA2P3D->Init(new TCollection_HAsciiString("FEA_BASIC_COORD_SYSTEM"),
858                SGCP, Standard_True, SGD1, Standard_True, SGD2, StepFEA_Cartesian,
859                new TCollection_HAsciiString("FEA_BASIC_COORD_SYSTEM"));
860   smodel->AddWithRefs(FA2P3D);
861   smodel->SetIdentLabel(FA2P3D, smodel->Number(FA2P3D));
862
863   // create context for fea_model
864   Handle(StepShape_ShapeRepresentation) NS = NominShape(Prod);
865   Handle(StepRepr_RepresentationContext) RC = NS->ContextOfItems();
866   Handle(StepGeom_GeometricRepresentationContext) GeoCtx;
867   Handle(StepBasic_HArray1OfNamedUnit) OldHANU;
868   if(RC->IsKind(STANDARD_TYPE(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx))) {
869     Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx) GeoUnitCtxNS =
870       Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx)::DownCast(RC);
871     GeoCtx = GeoUnitCtxNS->GeometricRepresentationContext();
872     OldHANU = GeoUnitCtxNS->GlobalUnitAssignedContext()->Units();
873   }
874   if(RC->IsKind(STANDARD_TYPE(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext))) {
875     Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext) GeoUnitCtxNS =
876       Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext)::DownCast(RC);
877     GeoCtx = GeoUnitCtxNS->GeometricRepresentationContext();
878     OldHANU = GeoUnitCtxNS->GlobalUnitAssignedContext()->Units();
879   }
880   Handle(StepBasic_HArray1OfNamedUnit) NewHANU = new StepBasic_HArray1OfNamedUnit(1,OldHANU->Length()+3);
881   for(Standard_Integer i=1; i<=OldHANU->Length(); i++)
882     NewHANU->SetValue(i,OldHANU->Value(i));
883   // create SiUnitAndTimeUnit
884   Handle(StepBasic_SiUnitAndTimeUnit) SUTU = new StepBasic_SiUnitAndTimeUnit;
885   SUTU->Init(Standard_False,StepBasic_spExa,StepBasic_sunSecond);
886   smodel->AddWithRefs(SUTU);
887   smodel->SetIdentLabel(SUTU, smodel->Number(SUTU));
888   NewHANU->SetValue(OldHANU->Length()+1,SUTU);
889   //create SiUnitAndMassUnit
890   Handle(StepBasic_SiUnitAndMassUnit) SUMU = new StepBasic_SiUnitAndMassUnit;
891   SUMU->Init(Standard_True,StepBasic_spKilo,StepBasic_sunGram);
892   smodel->AddWithRefs(SUMU);
893   smodel->SetIdentLabel(SUMU, smodel->Number(SUMU));
894   NewHANU->SetValue(OldHANU->Length()+2,SUMU);
895   // create SiUnitAndThermodynamicTemperatureUnit
896   Handle(StepBasic_SiUnitAndThermodynamicTemperatureUnit) SUTTU =
897     new StepBasic_SiUnitAndThermodynamicTemperatureUnit;
898   SUTTU->Init(Standard_False,StepBasic_spExa,StepBasic_sunDegreeCelsius);
899   smodel->AddWithRefs(SUTTU);
900   smodel->SetIdentLabel(SUTTU, smodel->Number(SUTTU));
901   NewHANU->SetValue(OldHANU->Length()+3,SUTTU);
902   
903   Handle(StepRepr_GlobalUnitAssignedContext) NewUnitCtx = new StepRepr_GlobalUnitAssignedContext;
904   NewUnitCtx->Init(new TCollection_HAsciiString(""), new TCollection_HAsciiString(""),NewHANU);
905   Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext) NewGeoCtx =
906     new StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext;
907   NewGeoCtx->Init(new TCollection_HAsciiString("REP_CONTEXT_FEA"),
908                   new TCollection_HAsciiString("3D"), GeoCtx, NewUnitCtx);
909   smodel->AddWithRefs(NewGeoCtx);
910   smodel->SetIdentLabel(NewGeoCtx, smodel->Number(NewGeoCtx));
911
912   // create fea_model_3d
913   Handle(StepFEA_FeaModel3d) FM = new StepFEA_FeaModel3d;
914   FM->SetName(new TCollection_HAsciiString("FEA_MODEL"));
915   Handle(StepRepr_HArray1OfRepresentationItem) HARI = 
916     new StepRepr_HArray1OfRepresentationItem(1,1);
917   HARI->SetValue(1,FA2P3D);
918   Handle(TColStd_HArray1OfAsciiString) HAAS = new TColStd_HArray1OfAsciiString(1,1);
919   HAAS->SetValue(1,"FEA_SOLVER");
920   FM->Init(new TCollection_HAsciiString("FEA_MODEL"), HARI,
921            NewGeoCtx, new TCollection_HAsciiString(""),
922            HAAS, new TCollection_HAsciiString("ANALYSIS_MODEL"),
923            new TCollection_HAsciiString("LINEAR_STATIC"));
924   smodel->AddWithRefs(FM);
925   smodel->SetIdentLabel(FM, smodel->Number(FM));
926
927   // add structural_response_property
928   Handle(StepRepr_StructuralResponseProperty) SRP =
929     new StepRepr_StructuralResponseProperty;
930   StepRepr_CharacterizedDefinition ChDef2;
931   ChDef2.SetValue(FMD);
932   SRP->Init(new TCollection_HAsciiString("STRUCT_RESP_PROP"), Standard_True,
933             new TCollection_HAsciiString("STRUCTURAL_RESPONSE_PROPERTY"),ChDef2);
934   smodel->AddWithRefs(SRP);
935   smodel->SetIdentLabel(SRP, smodel->Number(SRP));
936
937   // add structural_response_property_definition_representation
938   Handle(StepRepr_StructuralResponsePropertyDefinitionRepresentation) SRPDR =
939     new StepRepr_StructuralResponsePropertyDefinitionRepresentation;
940   StepRepr_RepresentedDefinition RepDef2;
941   RepDef2.SetValue(SRP);
942   SRPDR->Init(RepDef2,FM);
943   smodel->AddWithRefs(SRPDR);
944   smodel->SetIdentLabel(SRPDR, smodel->Number(SRPDR));
945
946   WS()->ComputeGraph(Standard_True);
947   WS()->ComputeCheck(Standard_True);
948
949   return Standard_True;
950 }
951
952
953 //=======================================================================
954 //function : ReplaceCcDesingToApplied
955 //purpose  : Put into model entities Applied... for AP209 instead of
956 //           entities CcDesing... from AP203
957 //=======================================================================
958
959 Standard_Boolean StepAP209_Construct::ReplaceCcDesingToApplied() const
960 {
961   Handle(StepData_StepModel) smodel = Handle(StepData_StepModel)::DownCast(Model());
962   Standard_Integer nb = smodel->NbEntities();
963   for(Standard_Integer i=1; i<=nb; i++) {
964     Handle(Standard_Transient) anEntity = smodel->Value(i);
965     if(anEntity->IsKind(STANDARD_TYPE(StepAP203_CcDesignApproval))) {
966       Handle(StepAP203_CcDesignApproval) ent = Handle(StepAP203_CcDesignApproval)::DownCast(anEntity);
967       Handle(StepAP214_AppliedApprovalAssignment) nent = new StepAP214_AppliedApprovalAssignment;
968       Handle(StepAP203_HArray1OfApprovedItem) HAAI203 = ent->Items();
969       Handle(StepAP214_HArray1OfApprovalItem) HAAI214 =
970         new StepAP214_HArray1OfApprovalItem(1,HAAI203->Length());
971       for(Standard_Integer j=1; j<=HAAI203->Length(); j++) {
972         StepAP214_ApprovalItem AI214;
973         AI214.SetValue(HAAI203->Value(j).Value());
974         HAAI214->SetValue(j,AI214);
975       }
976       nent->Init(ent->AssignedApproval(), HAAI214);
977       smodel->ReplaceEntity(i,nent);
978       smodel->SetIdentLabel(nent, smodel->Number(nent));
979     }
980     else if(anEntity->IsKind(STANDARD_TYPE(StepAP203_CcDesignPersonAndOrganizationAssignment))) {
981       Handle(StepAP203_CcDesignPersonAndOrganizationAssignment) ent =
982         Handle(StepAP203_CcDesignPersonAndOrganizationAssignment)::DownCast(anEntity);
983       Handle(StepAP214_AppliedPersonAndOrganizationAssignment) nent =
984         new StepAP214_AppliedPersonAndOrganizationAssignment;
985       Handle(StepAP203_HArray1OfPersonOrganizationItem) HAPOI203 = ent->Items();
986       Handle(StepAP214_HArray1OfPersonAndOrganizationItem) HAPOI214 =
987         new StepAP214_HArray1OfPersonAndOrganizationItem(1,HAPOI203->Length());
988       for(Standard_Integer j=1; j<=HAPOI203->Length(); j++) {
989         StepAP214_PersonAndOrganizationItem POI214;
990         POI214.SetValue(HAPOI203->Value(j).Value());
991         HAPOI214->SetValue(j,POI214);
992       }
993       nent->Init(ent->AssignedPersonAndOrganization(), ent->Role(), HAPOI214);
994       smodel->ReplaceEntity(i,nent);
995       smodel->SetIdentLabel(nent, smodel->Number(nent));
996     }
997     else if(anEntity->IsKind(STANDARD_TYPE(StepAP203_CcDesignDateAndTimeAssignment))) {
998       Handle(StepAP203_CcDesignDateAndTimeAssignment) ent =
999         Handle(StepAP203_CcDesignDateAndTimeAssignment)::DownCast(anEntity);
1000       Handle(StepAP214_AppliedDateAndTimeAssignment) nent = new StepAP214_AppliedDateAndTimeAssignment;
1001       Handle(StepAP203_HArray1OfDateTimeItem) HADTI203 = ent->Items();
1002       Handle(StepAP214_HArray1OfDateAndTimeItem) HADTI214 =
1003         new StepAP214_HArray1OfDateAndTimeItem(1,HADTI203->Length());
1004       for(Standard_Integer j=1; j<=HADTI203->Length(); j++) {
1005         StepAP214_DateAndTimeItem DTI214;
1006         DTI214.SetValue(HADTI203->Value(j).Value());
1007         HADTI214->SetValue(j,DTI214);
1008       }
1009       nent->Init(ent->AssignedDateAndTime(), ent->Role(), HADTI214);
1010       smodel->ReplaceEntity(i,nent);
1011       smodel->SetIdentLabel(nent, smodel->Number(nent));
1012     }
1013     else if(anEntity->IsKind(STANDARD_TYPE(StepAP203_CcDesignSecurityClassification))) {
1014       Handle(StepAP203_CcDesignSecurityClassification) ent =
1015         Handle(StepAP203_CcDesignSecurityClassification)::DownCast(anEntity);
1016       Handle(StepAP214_AppliedSecurityClassificationAssignment) nent =
1017         new StepAP214_AppliedSecurityClassificationAssignment;
1018       Handle(StepAP203_HArray1OfClassifiedItem) HACI203 = ent->Items();
1019       Handle(StepAP214_HArray1OfSecurityClassificationItem) HASCI214 =
1020         new StepAP214_HArray1OfSecurityClassificationItem(1,HACI203->Length());
1021       for(Standard_Integer j=1; j<=HACI203->Length(); j++) {
1022         StepAP214_SecurityClassificationItem SCI214;
1023         SCI214.SetValue(HACI203->Value(j).Value());
1024         HASCI214->SetValue(j,SCI214);
1025       }
1026       nent->Init(ent->AssignedSecurityClassification(), HASCI214);
1027       smodel->ReplaceEntity(i,nent);
1028       smodel->SetIdentLabel(nent, smodel->Number(nent));
1029     }
1030   }
1031
1032   return Standard_True;
1033 }
1034
1035
1036 //=======================================================================
1037 //function : CreateAddingEntities
1038 //purpose  : create approval.. , date.. , time.. , person.. and
1039 //           organization.. entities for analysis structure
1040 //=======================================================================
1041
1042 Standard_Boolean StepAP209_Construct::CreateAddingEntities
1043   (const Handle(StepBasic_ProductDefinition) &AnaPD) const
1044 {
1045   Handle(StepData_StepModel) smodel = Handle(StepData_StepModel)::DownCast(Model());
1046   Handle(StepBasic_ProductDefinitionFormation) AnaPDF = AnaPD->Formation();
1047   Handle(StepBasic_Product) AnaProd = AnaPDF->OfProduct();
1048
1049   Handle(StepBasic_ApprovalStatus) AS = new StepBasic_ApprovalStatus;
1050   AS->Init(new TCollection_HAsciiString("approved"));
1051   smodel->AddEntity(AS);
1052   smodel->SetIdentLabel(AS, smodel->Number(AS));
1053   Handle(StepBasic_Approval) Appr = new StepBasic_Approval;
1054   Appr->Init(AS, new TCollection_HAsciiString("approved"));
1055   smodel->AddWithRefs(Appr);
1056   smodel->SetIdentLabel(Appr, smodel->Number(Appr));
1057
1058   Handle(StepBasic_SecurityClassificationLevel) SCL = new StepBasic_SecurityClassificationLevel;
1059   SCL->Init(new TCollection_HAsciiString("unclassified"));
1060   smodel->AddEntity(SCL);
1061   smodel->SetIdentLabel(SCL, smodel->Number(SCL));
1062   Handle(StepBasic_SecurityClassification) SC = new StepBasic_SecurityClassification;
1063   SC->Init(new TCollection_HAsciiString(""), new TCollection_HAsciiString(""), SCL);
1064   smodel->AddWithRefs(SC);
1065   smodel->SetIdentLabel(SC, smodel->Number(SC));
1066
1067   Handle(StepAP214_AppliedApprovalAssignment) AAA = new StepAP214_AppliedApprovalAssignment;
1068   Handle(StepAP214_HArray1OfApprovalItem) HAAI = new StepAP214_HArray1OfApprovalItem(1,3);
1069   StepAP214_ApprovalItem AI1;
1070   AI1.SetValue(AnaPD);
1071   HAAI->SetValue(1,AI1);
1072   StepAP214_ApprovalItem AI2;
1073   AI2.SetValue(AnaPDF);
1074   HAAI->SetValue(2,AI2);
1075   StepAP214_ApprovalItem AI3;
1076   AI3.SetValue(SC);
1077   HAAI->SetValue(3,AI3);
1078   AAA->Init(Appr, HAAI);
1079   smodel->AddWithRefs(AAA);
1080   smodel->SetIdentLabel(AAA, smodel->Number(AAA));
1081
1082   Handle(StepAP214_AppliedSecurityClassificationAssignment) ASCA =
1083     new StepAP214_AppliedSecurityClassificationAssignment;
1084   Handle(StepAP214_HArray1OfSecurityClassificationItem) HASCI =
1085     new StepAP214_HArray1OfSecurityClassificationItem(1,1);
1086   StepAP214_SecurityClassificationItem SCI;
1087   SCI.SetValue(AnaPDF);
1088   HASCI->SetValue(1,SCI);
1089   ASCA->Init(SC,HASCI);
1090   smodel->AddWithRefs(ASCA);
1091   smodel->SetIdentLabel(ASCA, smodel->Number(ASCA));
1092
1093   OSD_Process sys;
1094   Quantity_Date date = sys.SystemDate ();
1095
1096   Handle(StepBasic_CalendarDate) CDate = new StepBasic_CalendarDate;
1097   CDate->Init(date.Year(), date.Day(), date.Month());
1098   smodel->AddEntity(CDate);
1099   smodel->SetIdentLabel(CDate, smodel->Number(CDate));
1100   Handle(StepBasic_CoordinatedUniversalTimeOffset) CUTO = new StepBasic_CoordinatedUniversalTimeOffset;
1101   CUTO->Init(0, Standard_True, 0, StepBasic_aobAhead);
1102   smodel->AddEntity(CUTO);
1103   smodel->SetIdentLabel(CUTO, smodel->Number(CUTO));
1104   Handle(StepBasic_LocalTime) LT = new StepBasic_LocalTime;
1105   LT->Init(date.Hour(), Standard_True, date.Minute(), Standard_True,
1106            (Standard_Real)date.Second(), CUTO);
1107   smodel->AddWithRefs(LT);
1108   smodel->SetIdentLabel(LT, smodel->Number(LT));
1109   Handle(StepBasic_DateAndTime) DAT = new StepBasic_DateAndTime;
1110   DAT->Init(CDate,LT);
1111   smodel->AddWithRefs(DAT);
1112   smodel->SetIdentLabel(DAT, smodel->Number(DAT));
1113
1114   Handle(StepBasic_DateTimeRole) DTR = new StepBasic_DateTimeRole;
1115   DTR->Init(new TCollection_HAsciiString("classification_date"));
1116   smodel->AddEntity(DTR);
1117   smodel->SetIdentLabel(DTR, smodel->Number(DTR));
1118   Handle(StepAP214_AppliedDateAndTimeAssignment) ADTA = new StepAP214_AppliedDateAndTimeAssignment;
1119   Handle(StepAP214_HArray1OfDateAndTimeItem) HADTI = new StepAP214_HArray1OfDateAndTimeItem(1,1);
1120   StepAP214_DateAndTimeItem DTI1;
1121   DTI1.SetValue(SC);
1122   HADTI->SetValue(1,DTI1);
1123   ADTA->Init(DAT,DTR,HADTI);
1124   smodel->AddWithRefs(ADTA);
1125   smodel->SetIdentLabel(ADTA, smodel->Number(ADTA));
1126
1127   DTR = new StepBasic_DateTimeRole;
1128   DTR->Init(new TCollection_HAsciiString("creation_date"));
1129   smodel->AddEntity(DTR);
1130   smodel->SetIdentLabel(DTR, smodel->Number(DTR));
1131   ADTA = new StepAP214_AppliedDateAndTimeAssignment;
1132   HADTI = new StepAP214_HArray1OfDateAndTimeItem(1,1);
1133   StepAP214_DateAndTimeItem DTI2;
1134   DTI2.SetValue(AnaPD);
1135   HADTI->SetValue(1,DTI2);
1136   ADTA->Init(DAT,DTR,HADTI);
1137   smodel->AddWithRefs(ADTA);
1138   smodel->SetIdentLabel(ADTA, smodel->Number(ADTA));
1139
1140   Handle(StepBasic_ApprovalDateTime) ADT = new StepBasic_ApprovalDateTime;
1141   StepBasic_DateTimeSelect DTS;
1142   DTS.SetValue(DAT);
1143   ADT->Init(DTS,Appr);
1144   smodel->AddWithRefs(ADT);
1145   smodel->SetIdentLabel(ADT, smodel->Number(ADT));
1146
1147   Handle(StepBasic_Person) Pers = new StepBasic_Person;
1148   Handle(Interface_HArray1OfHAsciiString) HAHAS = new Interface_HArray1OfHAsciiString(1,1);
1149   HAHAS->SetValue(1,new TCollection_HAsciiString(""));
1150   Pers->Init(new TCollection_HAsciiString("1"), Standard_True,
1151              new TCollection_HAsciiString("last_name"), Standard_True,
1152              new TCollection_HAsciiString("first_name"), Standard_True,
1153              HAHAS, Standard_True, HAHAS, Standard_True, HAHAS);
1154   smodel->AddEntity(Pers);
1155   smodel->SetIdentLabel(Pers, smodel->Number(Pers));
1156   Handle(StepBasic_Organization) Org = new StepBasic_Organization;
1157   Org->Init(Standard_True, new TCollection_HAsciiString("1"),
1158             new TCollection_HAsciiString("organisation"),
1159             new TCollection_HAsciiString("organisation_description"));
1160   smodel->AddEntity(Org);
1161   smodel->SetIdentLabel(Org, smodel->Number(Org));
1162   Handle(StepBasic_PersonAndOrganization) PO = new StepBasic_PersonAndOrganization;
1163   PO->Init(Pers,Org);
1164   smodel->AddWithRefs(PO);
1165   smodel->SetIdentLabel(PO, smodel->Number(PO));
1166
1167   Handle(StepBasic_PersonAndOrganizationRole) POR = new StepBasic_PersonAndOrganizationRole;
1168   POR->Init(new TCollection_HAsciiString("analysis_owner"));
1169   smodel->AddEntity(POR);
1170   smodel->SetIdentLabel(POR, smodel->Number(POR));
1171   Handle(StepAP214_AppliedPersonAndOrganizationAssignment) APOA =
1172     new StepAP214_AppliedPersonAndOrganizationAssignment;
1173   Handle(StepAP214_HArray1OfPersonAndOrganizationItem) HAPOI =
1174     new StepAP214_HArray1OfPersonAndOrganizationItem(1,1);
1175   StepAP214_PersonAndOrganizationItem POI1;
1176   POI1.SetValue(AnaProd);
1177   HAPOI->SetValue(1,POI1);
1178   APOA->Init(PO,POR,HAPOI);
1179   smodel->AddWithRefs(APOA);
1180   smodel->SetIdentLabel(APOA, smodel->Number(APOA));
1181
1182   POR = new StepBasic_PersonAndOrganizationRole;
1183   POR->Init(new TCollection_HAsciiString("creator"));
1184   smodel->AddEntity(POR);
1185   smodel->SetIdentLabel(POR, smodel->Number(POR));
1186   APOA = new StepAP214_AppliedPersonAndOrganizationAssignment;
1187   HAPOI = new StepAP214_HArray1OfPersonAndOrganizationItem(1,1);
1188   StepAP214_PersonAndOrganizationItem POI2;
1189   POI2.SetValue(AnaPD);
1190   HAPOI->SetValue(1,POI2);
1191   APOA->Init(PO,POR,HAPOI);
1192   smodel->AddWithRefs(APOA);
1193   smodel->SetIdentLabel(APOA, smodel->Number(APOA));
1194
1195   POR = new StepBasic_PersonAndOrganizationRole;
1196   POR->Init(new TCollection_HAsciiString("analysis_owner"));
1197   smodel->AddEntity(POR);
1198   smodel->SetIdentLabel(POR, smodel->Number(POR));
1199   APOA = new StepAP214_AppliedPersonAndOrganizationAssignment;
1200   HAPOI = new StepAP214_HArray1OfPersonAndOrganizationItem(1,1);
1201   StepAP214_PersonAndOrganizationItem POI3;
1202   POI3.SetValue(AnaPD);
1203   HAPOI->SetValue(1,POI3);
1204   APOA->Init(PO,POR,HAPOI);
1205   smodel->AddWithRefs(APOA);
1206   smodel->SetIdentLabel(APOA, smodel->Number(APOA));
1207
1208   POR = new StepBasic_PersonAndOrganizationRole;
1209   POR->Init(new TCollection_HAsciiString("classification_officer"));
1210   smodel->AddEntity(POR);
1211   smodel->SetIdentLabel(POR, smodel->Number(POR));
1212   APOA = new StepAP214_AppliedPersonAndOrganizationAssignment;
1213   HAPOI = new StepAP214_HArray1OfPersonAndOrganizationItem(1,1);
1214   StepAP214_PersonAndOrganizationItem POI4;
1215   POI4.SetValue(SC);
1216   HAPOI->SetValue(1,POI4);
1217   APOA->Init(PO,POR,HAPOI);
1218   smodel->AddWithRefs(APOA);
1219   smodel->SetIdentLabel(APOA, smodel->Number(APOA));
1220
1221   POR = new StepBasic_PersonAndOrganizationRole;
1222   POR->Init(new TCollection_HAsciiString("creator"));
1223   smodel->AddEntity(POR);
1224   smodel->SetIdentLabel(POR, smodel->Number(POR));
1225   APOA = new StepAP214_AppliedPersonAndOrganizationAssignment;
1226   HAPOI = new StepAP214_HArray1OfPersonAndOrganizationItem(1,1);
1227   StepAP214_PersonAndOrganizationItem POI5;
1228   POI5.SetValue(AnaPDF);
1229   HAPOI->SetValue(1,POI5);
1230   APOA->Init(PO,POR,HAPOI);
1231   smodel->AddWithRefs(APOA);
1232   smodel->SetIdentLabel(APOA, smodel->Number(APOA));
1233
1234   Handle(StepBasic_ApprovalRole) AR = new StepBasic_ApprovalRole;
1235   AR->Init(new TCollection_HAsciiString("approver"));
1236   smodel->AddEntity(AR);
1237   smodel->SetIdentLabel(AR, smodel->Number(AR));
1238   Handle(StepBasic_ApprovalPersonOrganization) APO = new StepBasic_ApprovalPersonOrganization;
1239   StepBasic_PersonOrganizationSelect POS;
1240   POS.SetValue(PO);
1241   APO->Init(POS,Appr,AR);
1242   smodel->AddWithRefs(APO);
1243   smodel->SetIdentLabel(APO, smodel->Number(APO));
1244
1245
1246   return Standard_True;
1247 }
1248
1249
1250 //=======================================================================
1251 //function : CreateAP203Structure
1252 //purpose  : 
1253 //=======================================================================
1254
1255 Handle(StepData_StepModel) StepAP209_Construct::CreateAP203Structure() const
1256 {
1257   Handle(StepData_StepModel) smodel = Handle(StepData_StepModel)::DownCast(Model());
1258   Handle(StepData_StepModel) nmodel;// = new StepData_StepModel;
1259   if(smodel.IsNull()) return nmodel;
1260   //nmodel->SetProtocol(smodel->Protocol());
1261   Handle(StepBasic_ProductDefinitionFormation) PDF;
1262   Handle(StepBasic_ProductDefinition) PD;
1263   Handle(StepRepr_ProductDefinitionShape) PDS;
1264   Handle(StepShape_ShapeDefinitionRepresentation) SDR;
1265   Standard_Integer nb = smodel->NbEntities();
1266   for(Standard_Integer i=1; i<=nb; i++) {
1267     if(smodel->Value(i)->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation))) {
1268       SDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(smodel->Value(i));
1269       PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(SDR->Definition().Value());
1270       if(PDS.IsNull()) continue;
1271       PD = Handle(StepBasic_ProductDefinition)::DownCast(PDS->Definition().Value());
1272       if(PD.IsNull()) continue;
1273       Handle(StepBasic_ProductDefinitionFormation) PDF1 = PD->Formation();
1274       if(IsDesing(PDF1)) {
1275         PDF = PDF1;
1276         i = nb;
1277       }
1278     }
1279   }
1280   if(PDF.IsNull()) return nmodel;
1281   nmodel = new StepData_StepModel;
1282   nmodel->SetProtocol(smodel->Protocol());
1283   
1284   Handle(StepBasic_Product) Prod = PDF->OfProduct();
1285   nmodel->AddWithRefs(Prod);
1286
1287   // adding categories:
1288   Handle(StepBasic_HArray1OfProduct) HAProd = new StepBasic_HArray1OfProduct(1,1);
1289   HAProd->SetValue(1,Prod);
1290   Handle(StepBasic_ProductRelatedProductCategory) PRPC = new StepBasic_ProductRelatedProductCategory;
1291   PRPC->Init(new TCollection_HAsciiString("design"),
1292              Standard_True, Prod->Name(), HAProd); // may be Prod->Description() - ???
1293   nmodel->AddEntity(PRPC);
1294   Handle(StepBasic_ProductCategory) PCat = new StepBasic_ProductCategory;
1295   PCat->Init(new TCollection_HAsciiString("part"),
1296              Standard_True, Prod->Name()); // may be Prod->Description() - ???
1297   nmodel->AddEntity(PCat);
1298   //nmodel->SetIdentLabel(PCat, smodel->Number(PCat));
1299   Handle(StepBasic_ProductCategoryRelationship) PCR = new StepBasic_ProductCategoryRelationship;
1300   PCR->Init(new TCollection_HAsciiString(""), Standard_True, 
1301             Prod->Name(), PCat, PRPC); // may be Prod->Description() - ???
1302   nmodel->AddWithRefs(PCR);
1303
1304   nmodel->AddWithRefs(PDF);
1305   nmodel->AddWithRefs(PD);
1306
1307   // replacing contexts:
1308   Handle(StepBasic_ApplicationContext) ApplCtx;
1309   Handle(StepBasic_ProductContext) ProdCtx = Prod->FrameOfReferenceValue(1);
1310   if(!ProdCtx.IsNull()) {
1311     Handle(StepBasic_MechanicalContext) MechCtx = new StepBasic_MechanicalContext;
1312     MechCtx->Init(ProdCtx->Name(), ProdCtx->FrameOfReference(),
1313                   ProdCtx->DisciplineType());
1314     nmodel->ReplaceEntity(nmodel->Number(ProdCtx),MechCtx);
1315     Handle(StepBasic_HArray1OfProductContext) HAPC = new StepBasic_HArray1OfProductContext(1,1);
1316     HAPC->SetValue(1,MechCtx);
1317     Prod->SetFrameOfReference(HAPC);
1318     ApplCtx = MechCtx->FrameOfReference();
1319   }
1320   Handle(StepBasic_ProductDefinitionContext) PDCtx = PD->FrameOfReference();
1321   if(!PDCtx.IsNull()) {
1322     Handle(StepBasic_DesignContext) DesCtx = new StepBasic_DesignContext;
1323     DesCtx->Init(PDCtx->Name(), PDCtx->FrameOfReference(),
1324                  PDCtx->LifeCycleStage());
1325     nmodel->ReplaceEntity(nmodel->Number(PDCtx),DesCtx);
1326     PD->SetFrameOfReference(DesCtx);
1327     ApplCtx = DesCtx->FrameOfReference();
1328   }
1329   if(!ApplCtx.IsNull()) {
1330     Handle(StepBasic_ApplicationProtocolDefinition) APD;
1331     Interface_EntityIterator subs = Graph().Sharings(ApplCtx);
1332     for (subs.Start(); subs.More() && APD.IsNull(); subs.Next()) {
1333       APD = Handle(StepBasic_ApplicationProtocolDefinition)::DownCast(subs.Value());
1334       if(APD.IsNull()) continue;
1335       nmodel->AddWithRefs(APD);
1336     }
1337   }
1338
1339   CreateAdding203Entities(PD,nmodel);
1340             
1341   // adding geometry part
1342   nmodel->AddWithRefs(SDR);
1343
1344   // adding DimensionalExponents
1345   Handle(StepBasic_DimensionalExponents) DimExp = new StepBasic_DimensionalExponents;
1346   DimExp->Init(1.,0.,0.,0.,0.,0.,0.);
1347   nmodel->AddWithRefs(DimExp);
1348   DimExp = new StepBasic_DimensionalExponents;
1349   DimExp->Init(0.,0.,0.,0.,0.,0.,0.);
1350   nmodel->AddWithRefs(DimExp);
1351
1352   // writing HeaderSection
1353   nmodel->ClearHeader();
1354   Handle(HeaderSection_FileName) FN = Handle(HeaderSection_FileName)::
1355     DownCast(smodel->HeaderEntity(STANDARD_TYPE(HeaderSection_FileName)));
1356   if(!FN.IsNull()) {
1357     FN->SetPreprocessorVersion(new TCollection_HAsciiString("AP209 -> SDRB Convertor"));
1358     nmodel->AddHeaderEntity(FN);
1359   }
1360   Handle(HeaderSection_FileSchema) FS = Handle(HeaderSection_FileSchema)::
1361     DownCast(smodel->HeaderEntity(STANDARD_TYPE(HeaderSection_FileSchema)));
1362   if(!FS.IsNull())
1363     nmodel->AddHeaderEntity(FS);
1364   Handle(HeaderSection_FileDescription) FD = Handle(HeaderSection_FileDescription)::
1365     DownCast(smodel->HeaderEntity(STANDARD_TYPE(HeaderSection_FileDescription)));
1366   if(!FD.IsNull()) {
1367     Handle(Interface_HArray1OfHAsciiString) HAAS = new Interface_HArray1OfHAsciiString(1,1);
1368     HAAS->SetValue(1,new TCollection_HAsciiString("STEP AP203 file generated from STEP AP209"));
1369     FD->SetDescription(HAAS);
1370     nmodel->AddHeaderEntity(FD);
1371   }
1372
1373 //  WS()->SetModel(nmodel);
1374
1375   return nmodel;
1376 }
1377
1378
1379 //=======================================================================
1380 //function : CreateAdding203Entities
1381 //purpose  : create approval.. , date.. , time.. , person.. and
1382 //           organization.. entities for analysis structure
1383 //=======================================================================
1384
1385 Standard_Boolean StepAP209_Construct::CreateAdding203Entities
1386   (const Handle(StepBasic_ProductDefinition) &PD,
1387    Handle(StepData_StepModel) &aModel) const
1388 {
1389   Handle(StepData_StepModel) smodel = Handle(StepData_StepModel)::DownCast(Model());
1390   Handle(StepBasic_ProductDefinitionFormation) PDF = PD->Formation();
1391   Handle(StepBasic_Product) Prod = PDF->OfProduct();
1392
1393   // create SecurityClassification
1394   Handle(StepBasic_SecurityClassification) SC;
1395   Interface_EntityIterator subs = Graph().Sharings(PDF);
1396   for (subs.Start(); subs.More() && SC.IsNull(); subs.Next()) {
1397     Handle(StepAP214_AppliedSecurityClassificationAssignment) ASCA =
1398       Handle(StepAP214_AppliedSecurityClassificationAssignment)::DownCast(subs.Value());
1399     if(ASCA.IsNull()) continue;
1400     SC = ASCA->AssignedSecurityClassification();
1401   }
1402   if(SC.IsNull()) {
1403     // create new
1404     Handle(StepBasic_SecurityClassificationLevel) SCL = new StepBasic_SecurityClassificationLevel;
1405     SCL->Init(new TCollection_HAsciiString("unclassified"));
1406     SC = new StepBasic_SecurityClassification;
1407     SC->Init(new TCollection_HAsciiString(""), new TCollection_HAsciiString(""), SCL);
1408   }
1409   aModel->AddWithRefs(SC);
1410   Handle(StepAP203_CcDesignSecurityClassification) DSC =
1411     new StepAP203_CcDesignSecurityClassification;
1412   Handle(StepAP203_HArray1OfClassifiedItem) HACI = new StepAP203_HArray1OfClassifiedItem(1,1);
1413   StepAP203_ClassifiedItem CI;
1414   CI.SetValue(PDF);
1415   HACI->SetValue(1,CI);
1416   DSC->Init(SC,HACI);
1417   aModel->AddWithRefs(DSC);
1418
1419   // create CcDesignApproval
1420   Handle(StepBasic_DateAndTime) DT; 
1421   subs = Graph().Sharings(PD);
1422   for (subs.Start(); subs.More(); subs.Next()) {
1423     Handle(StepAP214_AppliedApprovalAssignment) AAA =
1424       Handle(StepAP214_AppliedApprovalAssignment)::DownCast(subs.Value());
1425     if(!AAA.IsNull()) {
1426       Handle(StepAP214_HArray1OfApprovalItem) HAAI214 = AAA->Items();
1427       Handle(StepAP203_HArray1OfApprovedItem) HAAI =
1428         new StepAP203_HArray1OfApprovedItem(1,HAAI214->Length());
1429       for(Standard_Integer i=1; i<=HAAI214->Length(); i++) {
1430         StepAP203_ApprovedItem AI;
1431         AI.SetValue(AAA->ItemsValue(i).Value());
1432         HAAI->SetValue(i,AI);
1433       }
1434       Handle(StepAP203_CcDesignApproval) DA = new StepAP203_CcDesignApproval;
1435       DA->Init(AAA->AssignedApproval(),HAAI);
1436       aModel->AddWithRefs(DA);
1437       // find ApprovalDateTime for Approval
1438       Interface_EntityIterator subs2 = Graph().Sharings(AAA->AssignedApproval());
1439       for (subs2.Start(); subs2.More(); subs2.Next()) {
1440         Handle(StepBasic_ApprovalDateTime) ADT =
1441           Handle(StepBasic_ApprovalDateTime)::DownCast(subs2.Value());
1442         if(ADT.IsNull()) continue;
1443         aModel->AddWithRefs(ADT);
1444         Handle(StepBasic_DateAndTime) DT1 =
1445           Handle(StepBasic_DateAndTime)::DownCast(ADT->DateTime().Value());
1446         if(DT1.IsNull()) continue;
1447         DT = DT1;
1448       }
1449     }
1450   }
1451   subs = Graph().Sharings(PDF);
1452   for (subs.Start(); subs.More(); subs.Next()) {
1453     Handle(StepAP214_AppliedApprovalAssignment) AAA =
1454       Handle(StepAP214_AppliedApprovalAssignment)::DownCast(subs.Value());
1455     if(!AAA.IsNull()) {
1456       Handle(StepAP214_HArray1OfApprovalItem) HAAI214 = AAA->Items();
1457       Handle(StepAP203_HArray1OfApprovedItem) HAAI =
1458         new StepAP203_HArray1OfApprovedItem(1,HAAI214->Length());
1459       for(Standard_Integer i=1; i<=HAAI214->Length(); i++) {
1460         StepAP203_ApprovedItem AI;
1461         AI.SetValue(AAA->ItemsValue(i).Value());
1462         HAAI->SetValue(i,AI);
1463       }
1464       Handle(StepAP203_CcDesignApproval) DA = new StepAP203_CcDesignApproval;
1465       DA->Init(AAA->AssignedApproval(),HAAI);
1466       aModel->AddWithRefs(DA);
1467       // find ApprovalDateTime for Approval
1468       Interface_EntityIterator subs2 = Graph().Sharings(AAA->AssignedApproval());
1469       for (subs2.Start(); subs2.More(); subs2.Next()) {
1470         Handle(StepBasic_ApprovalDateTime) ADT =
1471           Handle(StepBasic_ApprovalDateTime)::DownCast(subs2.Value());
1472         if(ADT.IsNull()) continue;
1473         aModel->AddWithRefs(ADT);
1474         Handle(StepBasic_DateAndTime) DT1 =
1475           Handle(StepBasic_DateAndTime)::DownCast(ADT->DateTime().Value());
1476         if(DT1.IsNull()) continue;
1477         DT = DT1;
1478       }
1479     }
1480   }
1481   subs = Graph().Sharings(SC);
1482   for (subs.Start(); subs.More(); subs.Next()) {
1483     Handle(StepAP214_AppliedApprovalAssignment) AAA =
1484       Handle(StepAP214_AppliedApprovalAssignment)::DownCast(subs.Value());
1485     if(!AAA.IsNull()) {
1486       Handle(StepAP214_HArray1OfApprovalItem) HAAI214 = AAA->Items();
1487       Handle(StepAP203_HArray1OfApprovedItem) HAAI =
1488         new StepAP203_HArray1OfApprovedItem(1,HAAI214->Length());
1489       for(Standard_Integer i=1; i<=HAAI214->Length(); i++) {
1490         StepAP203_ApprovedItem AI;
1491         AI.SetValue(AAA->ItemsValue(i).Value());
1492         HAAI->SetValue(i,AI);
1493       }
1494       Handle(StepAP203_CcDesignApproval) DA = new StepAP203_CcDesignApproval;
1495       DA->Init(AAA->AssignedApproval(),HAAI);
1496       aModel->AddWithRefs(DA);
1497       // find ApprovalDateTime for Approval
1498       Interface_EntityIterator subs2 = Graph().Sharings(AAA->AssignedApproval());
1499       for (subs2.Start(); subs2.More(); subs2.Next()) {
1500         Handle(StepBasic_ApprovalDateTime) ADT =
1501           Handle(StepBasic_ApprovalDateTime)::DownCast(subs2.Value());
1502         if(ADT.IsNull()) continue;
1503         aModel->AddWithRefs(ADT);
1504         Handle(StepBasic_DateAndTime) DT1 =
1505           Handle(StepBasic_DateAndTime)::DownCast(ADT->DateTime().Value());
1506         if(DT1.IsNull()) continue;
1507         DT = DT1;
1508       }
1509     }
1510   }
1511
1512   if(aModel->Number(DT)>0) {
1513     // create CcDesignDateAndTimeAssignment
1514     subs = Graph().Sharings(DT);
1515     for (subs.Start(); subs.More(); subs.Next()) {
1516       Handle(StepAP214_AppliedDateAndTimeAssignment)ADTA =
1517         Handle(StepAP214_AppliedDateAndTimeAssignment)::DownCast(subs.Value());
1518       if(ADTA.IsNull()) continue;
1519       Handle(StepAP214_HArray1OfDateAndTimeItem) HADTI214 = ADTA->Items();
1520       Handle(StepAP203_HArray1OfDateTimeItem) HADTI =
1521         new StepAP203_HArray1OfDateTimeItem(1,HADTI214->Length());
1522       for(Standard_Integer i=1; i<=HADTI214->Length(); i++) {
1523         StepAP203_DateTimeItem DTI;
1524         DTI.SetValue(ADTA->ItemsValue(i).Value());
1525         HADTI->SetValue(i,DTI);
1526       }
1527       Handle(StepAP203_CcDesignDateAndTimeAssignment) DDTA =
1528         new StepAP203_CcDesignDateAndTimeAssignment;
1529       DDTA->Init(DT, ADTA->Role(), HADTI);
1530       aModel->AddWithRefs(DDTA);
1531     }
1532   }
1533
1534   // create Person.. and Organization.. entities
1535   subs = Graph().Sharings(Prod);
1536   for (subs.Start(); subs.More(); subs.Next()) {
1537     Handle(StepAP214_AppliedPersonAndOrganizationAssignment) APOA =
1538       Handle(StepAP214_AppliedPersonAndOrganizationAssignment)::DownCast(subs.Value());
1539     if(APOA.IsNull()) continue;
1540     Handle(StepAP214_HArray1OfPersonAndOrganizationItem) HAPOI214 = APOA->Items();
1541     Handle(StepAP203_HArray1OfPersonOrganizationItem) HAPOI =
1542       new StepAP203_HArray1OfPersonOrganizationItem(1,HAPOI214->Length());
1543     for(Standard_Integer i=1; i<=HAPOI214->Length(); i++) {
1544       StepAP203_PersonOrganizationItem POI;
1545       POI.SetValue(HAPOI214->Value(i).Value());
1546       HAPOI->SetValue(i,POI);
1547     }
1548     Handle(StepAP203_CcDesignPersonAndOrganizationAssignment) DPOA =
1549       new StepAP203_CcDesignPersonAndOrganizationAssignment;
1550     DPOA->Init(APOA->AssignedPersonAndOrganization(), APOA->Role(), HAPOI);
1551     aModel->AddWithRefs(DPOA);
1552   }
1553   subs = Graph().Sharings(PD);
1554   for (subs.Start(); subs.More(); subs.Next()) {
1555     Handle(StepAP214_AppliedPersonAndOrganizationAssignment) APOA =
1556       Handle(StepAP214_AppliedPersonAndOrganizationAssignment)::DownCast(subs.Value());
1557     if(APOA.IsNull()) continue;
1558     Handle(StepAP214_HArray1OfPersonAndOrganizationItem) HAPOI214 = APOA->Items();
1559     Handle(StepAP203_HArray1OfPersonOrganizationItem) HAPOI =
1560       new StepAP203_HArray1OfPersonOrganizationItem(1,HAPOI214->Length());
1561     for(Standard_Integer i=1; i<=HAPOI214->Length(); i++) {
1562       StepAP203_PersonOrganizationItem POI;
1563       POI.SetValue(HAPOI214->Value(i).Value());
1564       HAPOI->SetValue(i,POI);
1565     }
1566     Handle(StepAP203_CcDesignPersonAndOrganizationAssignment) DPOA =
1567       new StepAP203_CcDesignPersonAndOrganizationAssignment;
1568     DPOA->Init(APOA->AssignedPersonAndOrganization(), APOA->Role(), HAPOI);
1569     aModel->AddWithRefs(DPOA);
1570   }
1571   subs = Graph().Sharings(PDF);
1572   for (subs.Start(); subs.More(); subs.Next()) {
1573     Handle(StepAP214_AppliedPersonAndOrganizationAssignment) APOA =
1574       Handle(StepAP214_AppliedPersonAndOrganizationAssignment)::DownCast(subs.Value());
1575     if(APOA.IsNull()) continue;
1576     Handle(StepAP214_HArray1OfPersonAndOrganizationItem) HAPOI214 = APOA->Items();
1577     Handle(StepAP203_HArray1OfPersonOrganizationItem) HAPOI =
1578       new StepAP203_HArray1OfPersonOrganizationItem(1,HAPOI214->Length());
1579     for(Standard_Integer i=1; i<=HAPOI214->Length(); i++) {
1580       StepAP203_PersonOrganizationItem POI;
1581       POI.SetValue(HAPOI214->Value(i).Value());
1582       HAPOI->SetValue(i,POI);
1583     }
1584     Handle(StepAP203_CcDesignPersonAndOrganizationAssignment) DPOA =
1585       new StepAP203_CcDesignPersonAndOrganizationAssignment;
1586     DPOA->Init(APOA->AssignedPersonAndOrganization(), APOA->Role(), HAPOI);
1587     aModel->AddWithRefs(DPOA);
1588   }
1589   subs = Graph().Sharings(SC);
1590   for (subs.Start(); subs.More(); subs.Next()) {
1591     Handle(StepAP214_AppliedPersonAndOrganizationAssignment) APOA =
1592       Handle(StepAP214_AppliedPersonAndOrganizationAssignment)::DownCast(subs.Value());
1593     if(APOA.IsNull()) continue;
1594     Handle(StepAP214_HArray1OfPersonAndOrganizationItem) HAPOI214 = APOA->Items();
1595     Handle(StepAP203_HArray1OfPersonOrganizationItem) HAPOI =
1596       new StepAP203_HArray1OfPersonOrganizationItem(1,HAPOI214->Length());
1597     for(Standard_Integer i=1; i<=HAPOI214->Length(); i++) {
1598       StepAP203_PersonOrganizationItem POI;
1599       POI.SetValue(HAPOI214->Value(i).Value());
1600       HAPOI->SetValue(i,POI);
1601     }
1602     Handle(StepAP203_CcDesignPersonAndOrganizationAssignment) DPOA =
1603       new StepAP203_CcDesignPersonAndOrganizationAssignment;
1604     DPOA->Init(APOA->AssignedPersonAndOrganization(), APOA->Role(), HAPOI);
1605     aModel->AddWithRefs(DPOA);
1606   }
1607   
1608   return Standard_True;
1609 }
1610