0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / STEPConstruct / STEPConstruct_ContextTool.cxx
CommitLineData
b311480e 1// Created on: 1993-09-20
2// Created by: Martine LANGLOIS
3// Copyright (c) 1993-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
7fd59977 17// :j4 16.03.99 gka S4134
18// abv 18.11.99 renamed from StepPDR_ContextTool
7fd59977 19
42cf5bc1 20#include <GeomToStep_MakeAxis2Placement3d.hxx>
7fd59977 21#include <Interface_Macros.hxx>
42cf5bc1 22#include <Interface_Static.hxx>
23#include <StepAP203_CcDesignApproval.hxx>
24#include <StepAP203_CcDesignDateAndTimeAssignment.hxx>
25#include <StepAP203_CcDesignPersonAndOrganizationAssignment.hxx>
26#include <StepAP203_CcDesignSecurityClassification.hxx>
7fd59977 27#include <StepBasic_ApplicationContext.hxx>
28#include <StepBasic_ApplicationProtocolDefinition.hxx>
c04c30b3 29#include <StepBasic_ApprovalDateTime.hxx>
42cf5bc1 30#include <StepBasic_ApprovalPersonOrganization.hxx>
31#include <StepBasic_HArray1OfProduct.hxx>
32#include <StepBasic_HArray1OfProductContext.hxx>
33#include <StepBasic_Product.hxx>
c04c30b3 34#include <StepBasic_ProductCategoryRelationship.hxx>
42cf5bc1 35#include <StepBasic_ProductContext.hxx>
36#include <StepBasic_ProductDefinition.hxx>
37#include <StepBasic_ProductDefinitionFormation.hxx>
38#include <StepBasic_ProductRelatedProductCategory.hxx>
39#include <StepBasic_ProductType.hxx>
40#include <STEPConstruct_AP203Context.hxx>
41#include <STEPConstruct_Assembly.hxx>
42#include <STEPConstruct_ContextTool.hxx>
43#include <STEPConstruct_Part.hxx>
44#include <StepData_StepModel.hxx>
45#include <StepGeom_Axis2Placement3d.hxx>
5b111128 46#include <StepRepr_NextAssemblyUsageOccurrence.hxx>
42cf5bc1 47#include <StepRepr_PropertyDefinition.hxx>
c04c30b3 48#include <StepShape_ShapeDefinitionRepresentation.hxx>
42cf5bc1 49#include <TCollection_HAsciiString.hxx>
7fd59977 50
51#include "stdio.h"
42cf5bc1 52//#include <StepBasic_ProductDefinitionContext.hxx>
53//:i3
54//:j4
7fd59977 55//=======================================================================
56//function : STEPConstruct_ContextTool
57//purpose :
58//=======================================================================
7fd59977 59STEPConstruct_ContextTool::STEPConstruct_ContextTool ()
60{
61}
62
63//=======================================================================
64//function : STEPConstruct_ContextTool
65//purpose :
66//=======================================================================
67
68STEPConstruct_ContextTool::STEPConstruct_ContextTool (const Handle(StepData_StepModel)& aStepModel)
69{
70 SetModel(aStepModel);
71}
72
73//=======================================================================
74//function : SetModel
75//purpose :
76//=======================================================================
77
78void STEPConstruct_ContextTool::SetModel (const Handle(StepData_StepModel)& aStepModel)
79{
80 theAPD.Nullify(); //thePRPC.Nullify();
81
82 Standard_Integer i, nb = aStepModel->NbEntities();
83 for(i = 1; i<=nb && theAPD.IsNull(); i ++) {
84 Handle(Standard_Transient) ent = aStepModel->Value(i);
85 if (ent->IsKind(STANDARD_TYPE(StepBasic_ApplicationProtocolDefinition))) {
86 if (theAPD.IsNull()) theAPD = GetCasted(StepBasic_ApplicationProtocolDefinition, ent);
87 }
88 //if (ent->IsKind(STANDARD_TYPE(StepBasic_ProductRelatedProductCategory))) {
89 // if (thePRPC.IsNull()) thePRPC = GetCasted(StepBasic_ProductRelatedProductCategory, ent);
90 //}
91 }
92}
93
94//=======================================================================
95//function : GetAPD
96//purpose :
97//=======================================================================
98
99Handle(StepBasic_ApplicationProtocolDefinition) STEPConstruct_ContextTool::GetAPD()
100{
101 return theAPD;
102}
103
104//=======================================================================
105//function : AddAPD
106//purpose :
107//=======================================================================
108
109void STEPConstruct_ContextTool::AddAPD (const Standard_Boolean enforce)
110{
111 Standard_Boolean noapd = theAPD.IsNull();
112 if (noapd || enforce) theAPD = new StepBasic_ApplicationProtocolDefinition;
113
114 switch (Interface_Static::IVal("write.step.schema")) { //j4
115 default:
116 case 1:
117 theAPD->SetApplicationProtocolYear (1997);
118 theAPD->SetStatus (new TCollection_HAsciiString("committee draft"));
119 theAPD->SetApplicationInterpretedModelSchemaName
120 (new TCollection_HAsciiString("automotive_design"));
121 break;
122 case 2:
123 theAPD->SetApplicationProtocolYear (1998);
124 theAPD->SetStatus (new TCollection_HAsciiString("draft international standard"));
125 theAPD->SetApplicationInterpretedModelSchemaName
126 (new TCollection_HAsciiString("automotive_design"));
127 break;
128 case 3:
129 theAPD->SetApplicationProtocolYear (1994);
130 theAPD->SetStatus (new TCollection_HAsciiString("international standard"));
131 theAPD->SetApplicationInterpretedModelSchemaName
132 (new TCollection_HAsciiString("config_control_design"));
133 break;
134
135 case 4: theAPD->SetApplicationProtocolYear (2000);
136 theAPD->SetStatus (new TCollection_HAsciiString("international standard"));
137 theAPD->SetApplicationInterpretedModelSchemaName
138 (new TCollection_HAsciiString("automotive_design"));
139 break;
d658f275 140 case 5: theAPD->SetApplicationProtocolYear (2013);
141 theAPD->SetStatus (new TCollection_HAsciiString("international standard"));
142 theAPD->SetApplicationInterpretedModelSchemaName
143 (new TCollection_HAsciiString("ap242_managed_model_based_3d_engineering"));
144 break;
7fd59977 145 }
146
147 if (theAPD->Application().IsNull())
148 theAPD->SetApplication (new StepBasic_ApplicationContext);
149 Handle(TCollection_HAsciiString) appl;
150 switch (Interface_Static::IVal("write.step.schema")) { //j4
151 default:
152 case 1:
153 case 2: appl = new TCollection_HAsciiString ( "core data for automotive mechanical design processes" );
154 break;
155 case 3: appl = new TCollection_HAsciiString ( "configuration controlled 3D designs of mechanical parts and assemblies" );
156 break;
d658f275 157 case 5: appl = new TCollection_HAsciiString ( "Managed model based 3d engineering");
158 break;
7fd59977 159 }
160 theAPD->Application()->SetApplication ( appl );
161// if (noapd || enforce) aStepModel->AddWithRefs (theAPD);
162}
163
164//=======================================================================
165//function : IsAP203
166//purpose :
167//=======================================================================
168
169Standard_Boolean STEPConstruct_ContextTool::IsAP203 () const
170{
171 if ( theAPD.IsNull() ) return Standard_False;
172 Handle(TCollection_HAsciiString) schema = theAPD->ApplicationInterpretedModelSchemaName();
173 if ( schema.IsNull() ) return Standard_False;
174 TCollection_AsciiString sch = schema->String();
175 sch.LowerCase();
176 return sch == "config_control_design";
177}
178
179//=======================================================================
180//function : IsAP214
181//purpose :
182//=======================================================================
183
184Standard_Boolean STEPConstruct_ContextTool::IsAP214 () const
185{
186 if ( theAPD.IsNull() ) return Standard_False;
187 Handle(TCollection_HAsciiString) schema = theAPD->ApplicationInterpretedModelSchemaName();
188 if ( schema.IsNull() ) return Standard_False;
189 TCollection_AsciiString sch = schema->String();
190 sch.LowerCase();
191 return sch == "automotive_design";
192}
193
d658f275 194//=======================================================================
195//function : IsAP242
196//purpose :
197//=======================================================================
198
199Standard_Boolean STEPConstruct_ContextTool::IsAP242 () const
200{
201 if ( theAPD.IsNull() ) return Standard_False;
202 Handle(TCollection_HAsciiString) schema = theAPD->ApplicationInterpretedModelSchemaName();
203 if ( schema.IsNull() ) return Standard_False;
204 TCollection_AsciiString sch = schema->String();
205 sch.LowerCase();
206 return sch == "ap242_managed_model_based_3d_engineering";
207}
208
7fd59977 209// ================================================================
210// Data Section : Basic Product Information (level S1)
211// * Get methods
212// * Set methods
213// ================================================================
214
215//=======================================================================
216//function : GetACstatus
217//purpose :
218//=======================================================================
219
220Handle(TCollection_HAsciiString) STEPConstruct_ContextTool::GetACstatus()
221{
222 if (GetAPD().IsNull()) return new TCollection_HAsciiString("");
223 return GetAPD()->Status();
224}
225
226//=======================================================================
227//function : GetACschemaName
228//purpose :
229//=======================================================================
230
231Handle(TCollection_HAsciiString) STEPConstruct_ContextTool::GetACschemaName()
232{
233 if (GetAPD().IsNull()) return new TCollection_HAsciiString("");
234 return GetAPD()->ApplicationInterpretedModelSchemaName();
235}
236
237//=======================================================================
238//function : GetACyear
239//purpose :
240//=======================================================================
241
242Standard_Integer STEPConstruct_ContextTool::GetACyear()
243{
244 return (GetAPD().IsNull() ? 1998 :
245 GetAPD()->ApplicationProtocolYear());
246}
247
248/*
249//=======================================================================
250//function : GetACapplication
251//purpose :
252//=======================================================================
253
254Handle(TCollection_HAsciiString) STEPConstruct_ContextTool::GetACapplication()
255{
256 return GetPDC()->Formation()->OfProduct()->FrameOfReferenceValue(1)
257 ->FrameOfReference()->Application();
258}
259*/
260
261//=======================================================================
262//function : GetACname
263//purpose :
264//=======================================================================
265
266Handle(TCollection_HAsciiString) STEPConstruct_ContextTool::GetACname()
267{
268 if (GetAPD().IsNull()) return new TCollection_HAsciiString("");
269 if (GetAPD()->Application().IsNull()) return new TCollection_HAsciiString("");
270 return GetAPD()->Application()->Application();
271}
272
273//=======================================================================
274//function : SetACstatus
275//purpose :
276//=======================================================================
277
278void STEPConstruct_ContextTool::SetACstatus (const Handle(TCollection_HAsciiString)& status)
279{
280 if (GetAPD().IsNull()) return;
281 GetAPD()->SetStatus(status);
282}
283
284//=======================================================================
285//function : SetACschemaName
286//purpose :
287//=======================================================================
288
289void STEPConstruct_ContextTool::SetACschemaName (const Handle(TCollection_HAsciiString)& schemaName)
290{
291 if (GetAPD().IsNull()) return;
292 GetAPD()->SetApplicationInterpretedModelSchemaName(schemaName);
293}
294
295//=======================================================================
296//function : SetACyear
297//purpose :
298//=======================================================================
299
300void STEPConstruct_ContextTool::SetACyear (const Standard_Integer year)
301{
302 if (GetAPD().IsNull()) return;
303 GetAPD()->SetApplicationProtocolYear(year);
304}
305
306//=======================================================================
307//function : SetACname
308//purpose :
309//=======================================================================
310
311void STEPConstruct_ContextTool::SetACname (const Handle(TCollection_HAsciiString)& name)
312{
313 if (GetAPD().IsNull()) return;
314 if (GetAPD()->Application().IsNull()) GetAPD()->SetApplication
315 (new StepBasic_ApplicationContext);
316 GetAPD()->Application()->SetApplication (name);
317}
318
319/*
320//=======================================================================
321//function : SetACapplication
322//purpose :
323//=======================================================================
324
325void STEPConstruct_ContextTool::SetACapplication (const Handle(TCollection_HAsciiString)& application)
326{
327 GetPDC()->Formation()->OfProduct()->FrameOfReferenceValue(1)
328 ->FrameOfReference()->SetApplication(application);
329
330}
331*/
332
333// --------------------------------
334// Product Related Product Category
335// --------------------------------
336
337/*
338
339//=======================================================================
340//function : GetPRPC
341//purpose :
342//=======================================================================
343
344Handle(StepBasic_ProductRelatedProductCategory) STEPConstruct_ContextTool::GetPRPC()
345{
346 return thePRPC;
347}
348
349//=======================================================================
350//function : AddPRPC
351//purpose :
352//=======================================================================
353
354void STEPConstruct_ContextTool::AddPRPC (const Standard_Boolean enforce)
355{
356 Standard_Boolean noprpc = thePRPC.IsNull();
357 if (noprpc || enforce) {
358 //:i3 abv 1 Sep 98: ProSTEP TR9: generate PRODUCT_TYPE (derived) instead of PRPC
359 switch (Interface_Static::IVal("write.step.schema")) { //j4
360 default:
361 case 1:
362 thePRPC = new StepBasic_ProductType;
363 thePRPC->SetName (new TCollection_HAsciiString("part"));
364 break;
365 case 4:
366 case 2:
367 thePRPC = new StepBasic_ProductRelatedProductCategory;
368 thePRPC->SetName (new TCollection_HAsciiString("part"));
369 break;
370 case 3:
371 thePRPC = new StepBasic_ProductRelatedProductCategory;
372 thePRPC->SetName (new TCollection_HAsciiString("detail")); // !!!!! or "assembly"
373 break;
374 }
375 thePRPC->UnSetDescription(); //:i3
376 }
377// if (noprpc || enforce) aStepModel->AddWithRefs(thePRPC);
378}
379
380//=======================================================================
381//function : SetPRPCName
382//purpose :
383//=======================================================================
384
385void STEPConstruct_ContextTool::SetPRPCName(const Handle(TCollection_HAsciiString)& aName)
386{
387 GetPRPC()->SetName(aName);
388}
389
390//=======================================================================
391//function : GetPRPCName
392//purpose :
393//=======================================================================
394
395Handle(TCollection_HAsciiString) STEPConstruct_ContextTool::GetPRPCName()
396{
397 if (GetPRPC().IsNull()) return new TCollection_HAsciiString("");
398 return GetPRPC()->Name();
399}
400
401//=======================================================================
402//function : SetPRPCDescription
403//purpose :
404//=======================================================================
405
406void STEPConstruct_ContextTool::SetPRPCDescription (const Handle(TCollection_HAsciiString)& aDescription)
407{
408 Handle(StepBasic_ProductRelatedProductCategory) aPRPC = GetPRPC();
409 aPRPC->SetDescription(aDescription);
410// aPRPC->HasDescription(Standard_True);
411}
412
413//=======================================================================
414//function : GetPRPCDescription
415//purpose :
416//=======================================================================
417
418Handle(TCollection_HAsciiString) STEPConstruct_ContextTool::GetPRPCDescription()
419{
420 Handle(StepBasic_ProductRelatedProductCategory) aPRPC = GetPRPC();
421 if (!aPRPC.IsNull() && aPRPC->HasDescription())
422 return aPRPC->Description();
423 else {
424 return new TCollection_HAsciiString("");
425 }
426}
427
428// ================================================================
429//
430// Settings from an already done SDR (see SDRtool)
431//
432// ================================================================
433
434void STEPConstruct_ContextTool::SetSDR (const Handle(StepShape_ShapeDefinitionRepresentation)& sdr)
435{
436// SDR partage des choses avec le contexte ... On raccroche les wagons
437 Handle(StepBasic_Product) theProduct =
438 sdr->Definition()->Definition().ProductDefinition()->Formation()->OfProduct();
439 Handle(StepBasic_ApplicationContext) theAppli =
440 theProduct->FrameOfReferenceValue(1)->FrameOfReference();
441 Handle(StepBasic_HArray1OfProduct) ProdList =
442 new StepBasic_HArray1OfProduct(1,1);
443 ProdList->SetValue(1,theProduct);
444 thePRPC->SetProducts (ProdList);
445 theAPD->SetApplication (theAppli);
446}
447*/
448
449//=======================================================================
450//function : GetDefaultAxis
451//purpose :
452//=======================================================================
453
454Handle(StepGeom_Axis2Placement3d) STEPConstruct_ContextTool::GetDefaultAxis ()
455{
456 if ( myAxis.IsNull() ) {
457 GeomToStep_MakeAxis2Placement3d mkax;
458 myAxis = mkax.Value();
459 }
460 return myAxis;
461}
462
463//=======================================================================
464//function : AP203Context
465//purpose :
466//=======================================================================
467
468STEPConstruct_AP203Context &STEPConstruct_ContextTool::AP203Context ()
469{
470 return theAP203;
471}
472
473//=======================================================================
474//function : Level
475//purpose :
476//=======================================================================
477
478Standard_Integer STEPConstruct_ContextTool::Level () const
479{
480 return myLevel.Length();
481}
482
483//=======================================================================
484//function : NextLevel
485//purpose :
486//=======================================================================
487
488void STEPConstruct_ContextTool::NextLevel ()
489{
490 myLevel.Append ( 1 );
491}
492
493//=======================================================================
494//function : PrevLevel
495//purpose :
496//=======================================================================
497
498void STEPConstruct_ContextTool::PrevLevel ()
499{
500 if ( myLevel.Length() >0 ) myLevel.Remove ( myLevel.Length() );
501}
502
503//=======================================================================
504//function : SetLevel
505//purpose :
506//=======================================================================
507
508void STEPConstruct_ContextTool::SetLevel (const Standard_Integer lev)
509{
510 if ( lev < myLevel.Length() ) {
511 while ( lev < myLevel.Length() && myLevel.Length() >0 )
512 myLevel.Remove ( myLevel.Length() );
513 }
514 else {
515 while ( myLevel.Length() < lev ) myLevel.Append ( 1 );
516 }
517}
518
519//=======================================================================
520//function : Index
521//purpose :
522//=======================================================================
523
524Standard_Integer STEPConstruct_ContextTool::Index () const
525{
526 return ( myLevel.Length() >0 ? myLevel.Last() : 0 );
527}
528
529//=======================================================================
530//function : NextIndex
531//purpose :
532//=======================================================================
533
534void STEPConstruct_ContextTool::NextIndex ()
535{
536 if ( myLevel.Length() >0 )
537 myLevel.SetValue ( myLevel.Length(), myLevel.Last() + 1 );
538}
539
540//=======================================================================
541//function : PrevIndex
542//purpose :
543//=======================================================================
544
545void STEPConstruct_ContextTool::PrevIndex ()
546{
547 if ( myLevel.Length() >0 )
548 myLevel.SetValue ( myLevel.Length(), myLevel.Last() - 1 );
549}
550
551//=======================================================================
552//function : SetIndex
553//purpose :
554//=======================================================================
555
556void STEPConstruct_ContextTool::SetIndex (const Standard_Integer ind)
557{
558 if ( myLevel.Length() >0 )
559 myLevel.SetValue ( myLevel.Length(), ind );
560}
561
562//=======================================================================
563//function : GetProductName
564//purpose :
565//=======================================================================
566
567Handle(TCollection_HAsciiString) STEPConstruct_ContextTool::GetProductName () const
568{
569 Handle(TCollection_HAsciiString) PdtName;
570 if (Interface_Static::IsSet("write.step.product.name"))
571 PdtName = new TCollection_HAsciiString(Interface_Static::CVal("write.step.product.name"));
572 else PdtName = new TCollection_HAsciiString("Product");
573
574 for ( Standard_Integer i=1; i <= myLevel.Length(); i++ ) {
575 PdtName->AssignCat ((char*)( i >1 ? "." : " " ));
576 char buf[100];
577 sprintf ( buf, "%d", myLevel.Value(i) );
578 PdtName->AssignCat ( buf );
579 }
580
581 return PdtName;
582}
583
584//=======================================================================
585//function : GetRootsForPart
586//purpose :
587//=======================================================================
588
589Handle(TColStd_HSequenceOfTransient) STEPConstruct_ContextTool::GetRootsForPart (const STEPConstruct_Part &SDRTool)
590{
591 Handle(TColStd_HSequenceOfTransient) seq = new TColStd_HSequenceOfTransient;
592
593 seq->Append ( SDRTool.SDRValue() );
594// seq->Append ( GetAPD() );
595
596 if ( ! SDRTool.PRPC().IsNull() ) seq->Append ( SDRTool.PRPC() );
597
598 // for AP203, add required product management data
599 if ( Interface_Static::IVal("write.step.schema") == 3 ) {
600 theAP203.Init ( SDRTool );
601 seq->Append (theAP203.GetProductCategoryRelationship());
602 seq->Append (theAP203.GetCreator());
603 seq->Append (theAP203.GetDesignOwner());
604 seq->Append (theAP203.GetDesignSupplier());
605 seq->Append (theAP203.GetClassificationOfficer());
606 seq->Append (theAP203.GetSecurity());
607 seq->Append (theAP203.GetCreationDate());
608 seq->Append (theAP203.GetClassificationDate());
609 seq->Append (theAP203.GetApproval());
610 seq->Append (theAP203.GetApprover());
611 seq->Append (theAP203.GetApprovalDateTime());
612 }
613
614 return seq;
615}
616
617//=======================================================================
618//function : GetRootsForAssemblyLink
619//purpose :
620//=======================================================================
621
622Handle(TColStd_HSequenceOfTransient) STEPConstruct_ContextTool::GetRootsForAssemblyLink (const STEPConstruct_Assembly &assembly)
623{
624 Handle(TColStd_HSequenceOfTransient) seq = new TColStd_HSequenceOfTransient;
625
626 seq->Append ( assembly.ItemValue() );
627
628 // for AP203, write required product management data
629 if ( Interface_Static::IVal("write.step.schema") == 3 ) {
630 theAP203.Init ( assembly.GetNAUO() );
631 seq->Append (theAP203.GetSecurity());
632 seq->Append (theAP203.GetClassificationOfficer());
633 seq->Append (theAP203.GetClassificationDate());
634 seq->Append (theAP203.GetApproval());
635 seq->Append (theAP203.GetApprover());
636 seq->Append (theAP203.GetApprovalDateTime());
637 }
638
639 return seq;
640}
641
642
643
644
645