1 // Created on: 1993-09-20
2 // Created by: Martine LANGLOIS
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 // :j4 16.03.99 gka S4134
18 // abv 18.11.99 renamed from StepPDR_ContextTool
19 #include <STEPConstruct_ContextTool.ixx>
20 #include <StepData_StepModel.hxx>
22 #include <Interface_Macros.hxx>
24 #include <StepBasic_ProductDefinition.hxx>
25 //#include <StepBasic_ProductDefinitionContext.hxx>
26 #include <StepBasic_ProductDefinitionFormation.hxx>
27 #include <StepBasic_Product.hxx>
28 #include <StepBasic_ProductContext.hxx>
29 #include <StepBasic_HArray1OfProductContext.hxx>
30 #include <StepBasic_ApplicationContext.hxx>
31 #include <StepBasic_ApplicationProtocolDefinition.hxx>
32 #include <StepRepr_PropertyDefinition.hxx>
34 #include <StepBasic_HArray1OfProduct.hxx>
35 #include <StepBasic_ProductType.hxx> //:i3
36 #include <Interface_Static.hxx> //:j4
37 #include <GeomToStep_MakeAxis2Placement3d.hxx>
38 #include <StepBasic_ProductRelatedProductCategory.hxx>
42 //=======================================================================
43 //function : STEPConstruct_ContextTool
45 //=======================================================================
47 STEPConstruct_ContextTool::STEPConstruct_ContextTool ()
51 //=======================================================================
52 //function : STEPConstruct_ContextTool
54 //=======================================================================
56 STEPConstruct_ContextTool::STEPConstruct_ContextTool (const Handle(StepData_StepModel)& aStepModel)
61 //=======================================================================
64 //=======================================================================
66 void STEPConstruct_ContextTool::SetModel (const Handle(StepData_StepModel)& aStepModel)
68 theAPD.Nullify(); //thePRPC.Nullify();
70 Standard_Integer i, nb = aStepModel->NbEntities();
71 for(i = 1; i<=nb && theAPD.IsNull(); i ++) {
72 Handle(Standard_Transient) ent = aStepModel->Value(i);
73 if (ent->IsKind(STANDARD_TYPE(StepBasic_ApplicationProtocolDefinition))) {
74 if (theAPD.IsNull()) theAPD = GetCasted(StepBasic_ApplicationProtocolDefinition, ent);
76 //if (ent->IsKind(STANDARD_TYPE(StepBasic_ProductRelatedProductCategory))) {
77 // if (thePRPC.IsNull()) thePRPC = GetCasted(StepBasic_ProductRelatedProductCategory, ent);
82 //=======================================================================
85 //=======================================================================
87 Handle(StepBasic_ApplicationProtocolDefinition) STEPConstruct_ContextTool::GetAPD()
92 //=======================================================================
95 //=======================================================================
97 void STEPConstruct_ContextTool::AddAPD (const Standard_Boolean enforce)
99 Standard_Boolean noapd = theAPD.IsNull();
100 if (noapd || enforce) theAPD = new StepBasic_ApplicationProtocolDefinition;
102 switch (Interface_Static::IVal("write.step.schema")) { //j4
105 theAPD->SetApplicationProtocolYear (1997);
106 theAPD->SetStatus (new TCollection_HAsciiString("committee draft"));
107 theAPD->SetApplicationInterpretedModelSchemaName
108 (new TCollection_HAsciiString("automotive_design"));
111 theAPD->SetApplicationProtocolYear (1998);
112 theAPD->SetStatus (new TCollection_HAsciiString("draft international standard"));
113 theAPD->SetApplicationInterpretedModelSchemaName
114 (new TCollection_HAsciiString("automotive_design"));
117 theAPD->SetApplicationProtocolYear (1994);
118 theAPD->SetStatus (new TCollection_HAsciiString("international standard"));
119 theAPD->SetApplicationInterpretedModelSchemaName
120 (new TCollection_HAsciiString("config_control_design"));
123 case 4: theAPD->SetApplicationProtocolYear (2000);
124 theAPD->SetStatus (new TCollection_HAsciiString("international standard"));
125 theAPD->SetApplicationInterpretedModelSchemaName
126 (new TCollection_HAsciiString("automotive_design"));
130 if (theAPD->Application().IsNull())
131 theAPD->SetApplication (new StepBasic_ApplicationContext);
132 Handle(TCollection_HAsciiString) appl;
133 switch (Interface_Static::IVal("write.step.schema")) { //j4
136 case 2: appl = new TCollection_HAsciiString ( "core data for automotive mechanical design processes" );
138 case 3: appl = new TCollection_HAsciiString ( "configuration controlled 3D designs of mechanical parts and assemblies" );
141 theAPD->Application()->SetApplication ( appl );
142 // if (noapd || enforce) aStepModel->AddWithRefs (theAPD);
145 //=======================================================================
148 //=======================================================================
150 Standard_Boolean STEPConstruct_ContextTool::IsAP203 () const
152 if ( theAPD.IsNull() ) return Standard_False;
153 Handle(TCollection_HAsciiString) schema = theAPD->ApplicationInterpretedModelSchemaName();
154 if ( schema.IsNull() ) return Standard_False;
155 TCollection_AsciiString sch = schema->String();
157 return sch == "config_control_design";
160 //=======================================================================
163 //=======================================================================
165 Standard_Boolean STEPConstruct_ContextTool::IsAP214 () const
167 if ( theAPD.IsNull() ) return Standard_False;
168 Handle(TCollection_HAsciiString) schema = theAPD->ApplicationInterpretedModelSchemaName();
169 if ( schema.IsNull() ) return Standard_False;
170 TCollection_AsciiString sch = schema->String();
172 return sch == "automotive_design";
175 // ================================================================
176 // Data Section : Basic Product Information (level S1)
179 // ================================================================
181 //=======================================================================
182 //function : GetACstatus
184 //=======================================================================
186 Handle(TCollection_HAsciiString) STEPConstruct_ContextTool::GetACstatus()
188 if (GetAPD().IsNull()) return new TCollection_HAsciiString("");
189 return GetAPD()->Status();
192 //=======================================================================
193 //function : GetACschemaName
195 //=======================================================================
197 Handle(TCollection_HAsciiString) STEPConstruct_ContextTool::GetACschemaName()
199 if (GetAPD().IsNull()) return new TCollection_HAsciiString("");
200 return GetAPD()->ApplicationInterpretedModelSchemaName();
203 //=======================================================================
204 //function : GetACyear
206 //=======================================================================
208 Standard_Integer STEPConstruct_ContextTool::GetACyear()
210 return (GetAPD().IsNull() ? 1998 :
211 GetAPD()->ApplicationProtocolYear());
215 //=======================================================================
216 //function : GetACapplication
218 //=======================================================================
220 Handle(TCollection_HAsciiString) STEPConstruct_ContextTool::GetACapplication()
222 return GetPDC()->Formation()->OfProduct()->FrameOfReferenceValue(1)
223 ->FrameOfReference()->Application();
227 //=======================================================================
228 //function : GetACname
230 //=======================================================================
232 Handle(TCollection_HAsciiString) STEPConstruct_ContextTool::GetACname()
234 if (GetAPD().IsNull()) return new TCollection_HAsciiString("");
235 if (GetAPD()->Application().IsNull()) return new TCollection_HAsciiString("");
236 return GetAPD()->Application()->Application();
239 //=======================================================================
240 //function : SetACstatus
242 //=======================================================================
244 void STEPConstruct_ContextTool::SetACstatus (const Handle(TCollection_HAsciiString)& status)
246 if (GetAPD().IsNull()) return;
247 GetAPD()->SetStatus(status);
250 //=======================================================================
251 //function : SetACschemaName
253 //=======================================================================
255 void STEPConstruct_ContextTool::SetACschemaName (const Handle(TCollection_HAsciiString)& schemaName)
257 if (GetAPD().IsNull()) return;
258 GetAPD()->SetApplicationInterpretedModelSchemaName(schemaName);
261 //=======================================================================
262 //function : SetACyear
264 //=======================================================================
266 void STEPConstruct_ContextTool::SetACyear (const Standard_Integer year)
268 if (GetAPD().IsNull()) return;
269 GetAPD()->SetApplicationProtocolYear(year);
272 //=======================================================================
273 //function : SetACname
275 //=======================================================================
277 void STEPConstruct_ContextTool::SetACname (const Handle(TCollection_HAsciiString)& name)
279 if (GetAPD().IsNull()) return;
280 if (GetAPD()->Application().IsNull()) GetAPD()->SetApplication
281 (new StepBasic_ApplicationContext);
282 GetAPD()->Application()->SetApplication (name);
286 //=======================================================================
287 //function : SetACapplication
289 //=======================================================================
291 void STEPConstruct_ContextTool::SetACapplication (const Handle(TCollection_HAsciiString)& application)
293 GetPDC()->Formation()->OfProduct()->FrameOfReferenceValue(1)
294 ->FrameOfReference()->SetApplication(application);
299 // --------------------------------
300 // Product Related Product Category
301 // --------------------------------
305 //=======================================================================
308 //=======================================================================
310 Handle(StepBasic_ProductRelatedProductCategory) STEPConstruct_ContextTool::GetPRPC()
315 //=======================================================================
318 //=======================================================================
320 void STEPConstruct_ContextTool::AddPRPC (const Standard_Boolean enforce)
322 Standard_Boolean noprpc = thePRPC.IsNull();
323 if (noprpc || enforce) {
324 //:i3 abv 1 Sep 98: ProSTEP TR9: generate PRODUCT_TYPE (derived) instead of PRPC
325 switch (Interface_Static::IVal("write.step.schema")) { //j4
328 thePRPC = new StepBasic_ProductType;
329 thePRPC->SetName (new TCollection_HAsciiString("part"));
333 thePRPC = new StepBasic_ProductRelatedProductCategory;
334 thePRPC->SetName (new TCollection_HAsciiString("part"));
337 thePRPC = new StepBasic_ProductRelatedProductCategory;
338 thePRPC->SetName (new TCollection_HAsciiString("detail")); // !!!!! or "assembly"
341 thePRPC->UnSetDescription(); //:i3
343 // if (noprpc || enforce) aStepModel->AddWithRefs(thePRPC);
346 //=======================================================================
347 //function : SetPRPCName
349 //=======================================================================
351 void STEPConstruct_ContextTool::SetPRPCName(const Handle(TCollection_HAsciiString)& aName)
353 GetPRPC()->SetName(aName);
356 //=======================================================================
357 //function : GetPRPCName
359 //=======================================================================
361 Handle(TCollection_HAsciiString) STEPConstruct_ContextTool::GetPRPCName()
363 if (GetPRPC().IsNull()) return new TCollection_HAsciiString("");
364 return GetPRPC()->Name();
367 //=======================================================================
368 //function : SetPRPCDescription
370 //=======================================================================
372 void STEPConstruct_ContextTool::SetPRPCDescription (const Handle(TCollection_HAsciiString)& aDescription)
374 Handle(StepBasic_ProductRelatedProductCategory) aPRPC = GetPRPC();
375 aPRPC->SetDescription(aDescription);
376 // aPRPC->HasDescription(Standard_True);
379 //=======================================================================
380 //function : GetPRPCDescription
382 //=======================================================================
384 Handle(TCollection_HAsciiString) STEPConstruct_ContextTool::GetPRPCDescription()
386 Handle(StepBasic_ProductRelatedProductCategory) aPRPC = GetPRPC();
387 if (!aPRPC.IsNull() && aPRPC->HasDescription())
388 return aPRPC->Description();
390 return new TCollection_HAsciiString("");
394 // ================================================================
396 // Settings from an already done SDR (see SDRtool)
398 // ================================================================
400 void STEPConstruct_ContextTool::SetSDR (const Handle(StepShape_ShapeDefinitionRepresentation)& sdr)
402 // SDR partage des choses avec le contexte ... On raccroche les wagons
403 Handle(StepBasic_Product) theProduct =
404 sdr->Definition()->Definition().ProductDefinition()->Formation()->OfProduct();
405 Handle(StepBasic_ApplicationContext) theAppli =
406 theProduct->FrameOfReferenceValue(1)->FrameOfReference();
407 Handle(StepBasic_HArray1OfProduct) ProdList =
408 new StepBasic_HArray1OfProduct(1,1);
409 ProdList->SetValue(1,theProduct);
410 thePRPC->SetProducts (ProdList);
411 theAPD->SetApplication (theAppli);
415 //=======================================================================
416 //function : GetDefaultAxis
418 //=======================================================================
420 Handle(StepGeom_Axis2Placement3d) STEPConstruct_ContextTool::GetDefaultAxis ()
422 if ( myAxis.IsNull() ) {
423 GeomToStep_MakeAxis2Placement3d mkax;
424 myAxis = mkax.Value();
429 //=======================================================================
430 //function : AP203Context
432 //=======================================================================
434 STEPConstruct_AP203Context &STEPConstruct_ContextTool::AP203Context ()
439 //=======================================================================
442 //=======================================================================
444 Standard_Integer STEPConstruct_ContextTool::Level () const
446 return myLevel.Length();
449 //=======================================================================
450 //function : NextLevel
452 //=======================================================================
454 void STEPConstruct_ContextTool::NextLevel ()
456 myLevel.Append ( 1 );
459 //=======================================================================
460 //function : PrevLevel
462 //=======================================================================
464 void STEPConstruct_ContextTool::PrevLevel ()
466 if ( myLevel.Length() >0 ) myLevel.Remove ( myLevel.Length() );
469 //=======================================================================
470 //function : SetLevel
472 //=======================================================================
474 void STEPConstruct_ContextTool::SetLevel (const Standard_Integer lev)
476 if ( lev < myLevel.Length() ) {
477 while ( lev < myLevel.Length() && myLevel.Length() >0 )
478 myLevel.Remove ( myLevel.Length() );
481 while ( myLevel.Length() < lev ) myLevel.Append ( 1 );
485 //=======================================================================
488 //=======================================================================
490 Standard_Integer STEPConstruct_ContextTool::Index () const
492 return ( myLevel.Length() >0 ? myLevel.Last() : 0 );
495 //=======================================================================
496 //function : NextIndex
498 //=======================================================================
500 void STEPConstruct_ContextTool::NextIndex ()
502 if ( myLevel.Length() >0 )
503 myLevel.SetValue ( myLevel.Length(), myLevel.Last() + 1 );
506 //=======================================================================
507 //function : PrevIndex
509 //=======================================================================
511 void STEPConstruct_ContextTool::PrevIndex ()
513 if ( myLevel.Length() >0 )
514 myLevel.SetValue ( myLevel.Length(), myLevel.Last() - 1 );
517 //=======================================================================
518 //function : SetIndex
520 //=======================================================================
522 void STEPConstruct_ContextTool::SetIndex (const Standard_Integer ind)
524 if ( myLevel.Length() >0 )
525 myLevel.SetValue ( myLevel.Length(), ind );
528 //=======================================================================
529 //function : GetProductName
531 //=======================================================================
533 Handle(TCollection_HAsciiString) STEPConstruct_ContextTool::GetProductName () const
535 Handle(TCollection_HAsciiString) PdtName;
536 if (Interface_Static::IsSet("write.step.product.name"))
537 PdtName = new TCollection_HAsciiString(Interface_Static::CVal("write.step.product.name"));
538 else PdtName = new TCollection_HAsciiString("Product");
540 for ( Standard_Integer i=1; i <= myLevel.Length(); i++ ) {
541 PdtName->AssignCat ((char*)( i >1 ? "." : " " ));
543 sprintf ( buf, "%d", myLevel.Value(i) );
544 PdtName->AssignCat ( buf );
550 //=======================================================================
551 //function : GetRootsForPart
553 //=======================================================================
555 Handle(TColStd_HSequenceOfTransient) STEPConstruct_ContextTool::GetRootsForPart (const STEPConstruct_Part &SDRTool)
557 Handle(TColStd_HSequenceOfTransient) seq = new TColStd_HSequenceOfTransient;
559 seq->Append ( SDRTool.SDRValue() );
560 // seq->Append ( GetAPD() );
562 if ( ! SDRTool.PRPC().IsNull() ) seq->Append ( SDRTool.PRPC() );
564 // for AP203, add required product management data
565 if ( Interface_Static::IVal("write.step.schema") == 3 ) {
566 theAP203.Init ( SDRTool );
567 seq->Append (theAP203.GetProductCategoryRelationship());
568 seq->Append (theAP203.GetCreator());
569 seq->Append (theAP203.GetDesignOwner());
570 seq->Append (theAP203.GetDesignSupplier());
571 seq->Append (theAP203.GetClassificationOfficer());
572 seq->Append (theAP203.GetSecurity());
573 seq->Append (theAP203.GetCreationDate());
574 seq->Append (theAP203.GetClassificationDate());
575 seq->Append (theAP203.GetApproval());
576 seq->Append (theAP203.GetApprover());
577 seq->Append (theAP203.GetApprovalDateTime());
583 //=======================================================================
584 //function : GetRootsForAssemblyLink
586 //=======================================================================
588 Handle(TColStd_HSequenceOfTransient) STEPConstruct_ContextTool::GetRootsForAssemblyLink (const STEPConstruct_Assembly &assembly)
590 Handle(TColStd_HSequenceOfTransient) seq = new TColStd_HSequenceOfTransient;
592 seq->Append ( assembly.ItemValue() );
594 // for AP203, write required product management data
595 if ( Interface_Static::IVal("write.step.schema") == 3 ) {
596 theAP203.Init ( assembly.GetNAUO() );
597 seq->Append (theAP203.GetSecurity());
598 seq->Append (theAP203.GetClassificationOfficer());
599 seq->Append (theAP203.GetClassificationDate());
600 seq->Append (theAP203.GetApproval());
601 seq->Append (theAP203.GetApprover());
602 seq->Append (theAP203.GetApprovalDateTime());