summaryrefslogtreecommitdiff
path: root/src/STEPConstruct/STEPConstruct_ContextTool.cxx
blob: a4cf32f870b4e09f59c7fffbc19cbfbad8fa1bbb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
// File:	STEPConstruct_ContextTool.cxx
// Created:	Mon Sep 20 12:23:40 1993
// Author:	Martine LANGLOIS
//		<mla@ecolox>
// :j4 16.03.99 gka S4134
// abv 18.11.99 renamed from StepPDR_ContextTool
#include <STEPConstruct_ContextTool.ixx>
#include <StepData_StepModel.hxx>

#include <Interface_Macros.hxx>

#include <StepBasic_ProductDefinition.hxx>
//#include <StepBasic_ProductDefinitionContext.hxx>
#include <StepBasic_ProductDefinitionFormation.hxx>
#include <StepBasic_Product.hxx>
#include <StepBasic_ProductContext.hxx>
#include <StepBasic_HArray1OfProductContext.hxx>
#include <StepBasic_ApplicationContext.hxx>
#include <StepBasic_ApplicationProtocolDefinition.hxx>
#include <StepRepr_PropertyDefinition.hxx>

#include <StepBasic_HArray1OfProduct.hxx>
#include <StepBasic_ProductType.hxx> //:i3
#include <Interface_Static.hxx> //:j4
#include <GeomToStep_MakeAxis2Placement3d.hxx>

#include "stdio.h"

//=======================================================================
//function : STEPConstruct_ContextTool
//purpose  :
//=======================================================================

STEPConstruct_ContextTool::STEPConstruct_ContextTool ()
{
}

//=======================================================================
//function : STEPConstruct_ContextTool
//purpose  :
//=======================================================================

STEPConstruct_ContextTool::STEPConstruct_ContextTool (const Handle(StepData_StepModel)& aStepModel)
{
  SetModel(aStepModel);
}

//=======================================================================
//function : SetModel
//purpose  :
//=======================================================================

void STEPConstruct_ContextTool::SetModel (const Handle(StepData_StepModel)& aStepModel)
{
  theAPD.Nullify();  //thePRPC.Nullify();

  Standard_Integer i, nb = aStepModel->NbEntities();
  for(i = 1; i<=nb && theAPD.IsNull(); i ++) {
    Handle(Standard_Transient) ent = aStepModel->Value(i);
    if (ent->IsKind(STANDARD_TYPE(StepBasic_ApplicationProtocolDefinition))) {
      if (theAPD.IsNull())  theAPD  = GetCasted(StepBasic_ApplicationProtocolDefinition, ent);
    }
    //if (ent->IsKind(STANDARD_TYPE(StepBasic_ProductRelatedProductCategory))) {
    //  if (thePRPC.IsNull()) thePRPC = GetCasted(StepBasic_ProductRelatedProductCategory, ent);
    //}
  }
}

//=======================================================================
//function : GetAPD
//purpose  :
//=======================================================================

Handle(StepBasic_ApplicationProtocolDefinition)  STEPConstruct_ContextTool::GetAPD()
{
  return theAPD;
}

//=======================================================================
//function : AddAPD
//purpose  :
//=======================================================================

void STEPConstruct_ContextTool::AddAPD (const Standard_Boolean enforce)
{
  Standard_Boolean noapd = theAPD.IsNull();
  if (noapd || enforce) theAPD  = new StepBasic_ApplicationProtocolDefinition;

  switch (Interface_Static::IVal("write.step.schema")) { //j4
  default:
  case 1:
    theAPD->SetApplicationProtocolYear (1997);
    theAPD->SetStatus (new TCollection_HAsciiString("committee draft"));
    theAPD->SetApplicationInterpretedModelSchemaName
      (new TCollection_HAsciiString("automotive_design"));
    break;
  case 2:
    theAPD->SetApplicationProtocolYear (1998);
    theAPD->SetStatus (new TCollection_HAsciiString("draft international standard"));
    theAPD->SetApplicationInterpretedModelSchemaName
      (new TCollection_HAsciiString("automotive_design"));
    break;
  case 3:
    theAPD->SetApplicationProtocolYear (1994);
    theAPD->SetStatus (new TCollection_HAsciiString("international standard"));
    theAPD->SetApplicationInterpretedModelSchemaName
      (new TCollection_HAsciiString("config_control_design"));
    break;
    
  case 4: theAPD->SetApplicationProtocolYear (2000);
    theAPD->SetStatus (new TCollection_HAsciiString("international standard"));
    theAPD->SetApplicationInterpretedModelSchemaName
      (new TCollection_HAsciiString("automotive_design"));
    break;
  }

  if (theAPD->Application().IsNull())
    theAPD->SetApplication (new StepBasic_ApplicationContext);
  Handle(TCollection_HAsciiString) appl;
  switch (Interface_Static::IVal("write.step.schema")) { //j4
  default:
  case 1:
  case 2: appl = new TCollection_HAsciiString ( "core data for automotive mechanical design processes" );
          break;
  case 3: appl = new TCollection_HAsciiString ( "configuration controlled 3D designs of mechanical parts and assemblies" );
          break;
  }
  theAPD->Application()->SetApplication ( appl );
//  if (noapd || enforce) aStepModel->AddWithRefs (theAPD);
}

//=======================================================================
//function : IsAP203
//purpose  : 
//=======================================================================

Standard_Boolean STEPConstruct_ContextTool::IsAP203 () const
{
  if ( theAPD.IsNull() ) return Standard_False;
  Handle(TCollection_HAsciiString) schema = theAPD->ApplicationInterpretedModelSchemaName();
  if ( schema.IsNull() ) return Standard_False;
  TCollection_AsciiString sch = schema->String();
  sch.LowerCase();
  return sch == "config_control_design";
}

//=======================================================================
//function : IsAP214
//purpose  : 
//=======================================================================

Standard_Boolean STEPConstruct_ContextTool::IsAP214 () const
{
  if ( theAPD.IsNull() ) return Standard_False;
  Handle(TCollection_HAsciiString) schema = theAPD->ApplicationInterpretedModelSchemaName();
  if ( schema.IsNull() ) return Standard_False;
  TCollection_AsciiString sch = schema->String();
  sch.LowerCase();
  return sch == "automotive_design";
}

// ================================================================
// Data Section : Basic Product Information (level S1)
//                   * Get methods
//                   * Set methods
// ================================================================

//=======================================================================
//function : GetACstatus
//purpose  :
//=======================================================================

Handle(TCollection_HAsciiString)  STEPConstruct_ContextTool::GetACstatus()
{
  if (GetAPD().IsNull()) return new TCollection_HAsciiString("");
  return GetAPD()->Status();
}

//=======================================================================
//function : GetACschemaName
//purpose  :
//=======================================================================

Handle(TCollection_HAsciiString)  STEPConstruct_ContextTool::GetACschemaName()
{
  if (GetAPD().IsNull()) return new TCollection_HAsciiString("");
  return  GetAPD()->ApplicationInterpretedModelSchemaName();
}

//=======================================================================
//function : GetACyear
//purpose  :
//=======================================================================

Standard_Integer  STEPConstruct_ContextTool::GetACyear()
{
  return (GetAPD().IsNull() ? 1998 :
	  GetAPD()->ApplicationProtocolYear());
}

/*
//=======================================================================
//function : GetACapplication
//purpose  :
//=======================================================================

Handle(TCollection_HAsciiString)  STEPConstruct_ContextTool::GetACapplication()
{
  return GetPDC()->Formation()->OfProduct()->FrameOfReferenceValue(1)
    ->FrameOfReference()->Application();
}
*/

//=======================================================================
//function : GetACname
//purpose  :
//=======================================================================

Handle(TCollection_HAsciiString)  STEPConstruct_ContextTool::GetACname()
{
  if (GetAPD().IsNull()) return new TCollection_HAsciiString("");
  if (GetAPD()->Application().IsNull()) return new TCollection_HAsciiString("");
  return GetAPD()->Application()->Application();
}

//=======================================================================
//function : SetACstatus
//purpose  :
//=======================================================================

void STEPConstruct_ContextTool::SetACstatus (const Handle(TCollection_HAsciiString)& status)
{
  if (GetAPD().IsNull()) return;
  GetAPD()->SetStatus(status);
}

//=======================================================================
//function : SetACschemaName
//purpose  :
//=======================================================================

void STEPConstruct_ContextTool::SetACschemaName (const Handle(TCollection_HAsciiString)& schemaName)
{
  if (GetAPD().IsNull()) return;
  GetAPD()->SetApplicationInterpretedModelSchemaName(schemaName);
}

//=======================================================================
//function : SetACyear
//purpose  :
//=======================================================================

void STEPConstruct_ContextTool::SetACyear (const Standard_Integer year)
{
  if (GetAPD().IsNull()) return;
  GetAPD()->SetApplicationProtocolYear(year);
}

//=======================================================================
//function : SetACname
//purpose  :
//=======================================================================

void STEPConstruct_ContextTool::SetACname (const Handle(TCollection_HAsciiString)& name)
{
  if (GetAPD().IsNull()) return;
  if (GetAPD()->Application().IsNull()) GetAPD()->SetApplication
    (new StepBasic_ApplicationContext);
  GetAPD()->Application()->SetApplication (name);
}

/*
//=======================================================================
//function : SetACapplication
//purpose  :
//=======================================================================

void STEPConstruct_ContextTool::SetACapplication (const Handle(TCollection_HAsciiString)& application)
{
  GetPDC()->Formation()->OfProduct()->FrameOfReferenceValue(1)
    ->FrameOfReference()->SetApplication(application);

}
*/

// --------------------------------
// Product Related Product Category
// --------------------------------

/*

//=======================================================================
//function : GetPRPC
//purpose  :
//=======================================================================

Handle(StepBasic_ProductRelatedProductCategory) STEPConstruct_ContextTool::GetPRPC()
{
  return thePRPC;
}

//=======================================================================
//function : AddPRPC
//purpose  :
//=======================================================================

void STEPConstruct_ContextTool::AddPRPC (const Standard_Boolean enforce)
{
  Standard_Boolean noprpc = thePRPC.IsNull();
  if (noprpc || enforce) {
    //:i3 abv 1 Sep 98: ProSTEP TR9: generate PRODUCT_TYPE (derived) instead of PRPC
    switch (Interface_Static::IVal("write.step.schema")) { //j4
    default:
    case 1:
      thePRPC = new StepBasic_ProductType;
      thePRPC->SetName (new TCollection_HAsciiString("part"));
      break;
    case 4:
    case 2:
      thePRPC = new StepBasic_ProductRelatedProductCategory;
      thePRPC->SetName (new TCollection_HAsciiString("part"));
      break;
    case 3:
      thePRPC = new StepBasic_ProductRelatedProductCategory;
      thePRPC->SetName (new TCollection_HAsciiString("detail")); // !!!!! or "assembly"
      break;
    }
    thePRPC->UnSetDescription(); //:i3
  }
//  if (noprpc || enforce) aStepModel->AddWithRefs(thePRPC);
}

//=======================================================================
//function : SetPRPCName
//purpose  :
//=======================================================================

void STEPConstruct_ContextTool::SetPRPCName(const Handle(TCollection_HAsciiString)& aName)
{
  GetPRPC()->SetName(aName);
}

//=======================================================================
//function : GetPRPCName
//purpose  :
//=======================================================================

Handle(TCollection_HAsciiString)  STEPConstruct_ContextTool::GetPRPCName()
{
  if (GetPRPC().IsNull()) return new TCollection_HAsciiString("");
  return GetPRPC()->Name();
}

//=======================================================================
//function : SetPRPCDescription
//purpose  :
//=======================================================================

void STEPConstruct_ContextTool::SetPRPCDescription (const Handle(TCollection_HAsciiString)& aDescription)
{
  Handle(StepBasic_ProductRelatedProductCategory) aPRPC = GetPRPC();
  aPRPC->SetDescription(aDescription);
//  aPRPC->HasDescription(Standard_True);
}

//=======================================================================
//function : GetPRPCDescription
//purpose  :
//=======================================================================

Handle(TCollection_HAsciiString) STEPConstruct_ContextTool::GetPRPCDescription()
{
  Handle(StepBasic_ProductRelatedProductCategory) aPRPC = GetPRPC();
  if (!aPRPC.IsNull() && aPRPC->HasDescription())
    return aPRPC->Description();
  else {
    return new TCollection_HAsciiString("");
  }
}

// ================================================================
//
// Settings from an already done SDR (see SDRtool)
//
// ================================================================

void STEPConstruct_ContextTool::SetSDR (const Handle(StepShape_ShapeDefinitionRepresentation)& sdr)
{
//  SDR partage des choses avec le contexte ... On raccroche les wagons
  Handle(StepBasic_Product) theProduct =
    sdr->Definition()->Definition().ProductDefinition()->Formation()->OfProduct();
  Handle(StepBasic_ApplicationContext) theAppli =
    theProduct->FrameOfReferenceValue(1)->FrameOfReference();
  Handle(StepBasic_HArray1OfProduct) ProdList =
    new StepBasic_HArray1OfProduct(1,1);
  ProdList->SetValue(1,theProduct);
  thePRPC->SetProducts (ProdList);
  theAPD->SetApplication (theAppli);
}
*/

//=======================================================================
//function : GetDefaultAxis
//purpose  :
//=======================================================================

Handle(StepGeom_Axis2Placement3d) STEPConstruct_ContextTool::GetDefaultAxis ()
{
  if ( myAxis.IsNull() ) {
    GeomToStep_MakeAxis2Placement3d mkax;
    myAxis = mkax.Value();
  }
  return myAxis;
}

//=======================================================================
//function : AP203Context
//purpose  :
//=======================================================================

STEPConstruct_AP203Context &STEPConstruct_ContextTool::AP203Context ()
{
  return theAP203;
}

//=======================================================================
//function : Level
//purpose  :
//=======================================================================

Standard_Integer STEPConstruct_ContextTool::Level () const
{
  return myLevel.Length();
}

//=======================================================================
//function : NextLevel
//purpose  :
//=======================================================================

void STEPConstruct_ContextTool::NextLevel ()
{
  myLevel.Append ( 1 );
}

//=======================================================================
//function : PrevLevel
//purpose  :
//=======================================================================

void STEPConstruct_ContextTool::PrevLevel ()
{
  if ( myLevel.Length() >0 ) myLevel.Remove ( myLevel.Length() );
}

//=======================================================================
//function : SetLevel
//purpose  :
//=======================================================================

void STEPConstruct_ContextTool::SetLevel (const Standard_Integer lev)
{
  if ( lev < myLevel.Length() ) {
    while ( lev < myLevel.Length() && myLevel.Length() >0 )
      myLevel.Remove ( myLevel.Length() );
  }
  else {
    while ( myLevel.Length() < lev ) myLevel.Append ( 1 );
  }
}

//=======================================================================
//function : Index
//purpose  :
//=======================================================================

Standard_Integer STEPConstruct_ContextTool::Index () const
{
  return ( myLevel.Length() >0 ? myLevel.Last() : 0 );
}

//=======================================================================
//function : NextIndex
//purpose  :
//=======================================================================

void STEPConstruct_ContextTool::NextIndex ()
{
  if ( myLevel.Length() >0 )
    myLevel.SetValue ( myLevel.Length(), myLevel.Last() + 1 );
}

//=======================================================================
//function : PrevIndex
//purpose  :
//=======================================================================

void STEPConstruct_ContextTool::PrevIndex ()
{
  if ( myLevel.Length() >0 )
    myLevel.SetValue ( myLevel.Length(), myLevel.Last() - 1 );
}

//=======================================================================
//function : SetIndex
//purpose  :
//=======================================================================

void STEPConstruct_ContextTool::SetIndex (const Standard_Integer ind)
{
  if ( myLevel.Length() >0 )
    myLevel.SetValue ( myLevel.Length(), ind );
}

//=======================================================================
//function : GetProductName
//purpose  :
//=======================================================================

Handle(TCollection_HAsciiString) STEPConstruct_ContextTool::GetProductName () const
{
  Handle(TCollection_HAsciiString) PdtName;
  if (Interface_Static::IsSet("write.step.product.name"))
    PdtName = new TCollection_HAsciiString(Interface_Static::CVal("write.step.product.name"));
  else PdtName = new TCollection_HAsciiString("Product");

  for ( Standard_Integer i=1; i <= myLevel.Length(); i++ ) {
    PdtName->AssignCat ((char*)( i >1 ? "." : " " ));
    char buf[100];
    sprintf ( buf, "%d", myLevel.Value(i) );
    PdtName->AssignCat ( buf );
  }

  return PdtName;
}

//=======================================================================
//function : GetRootsForPart
//purpose  : 
//=======================================================================

Handle(TColStd_HSequenceOfTransient) STEPConstruct_ContextTool::GetRootsForPart (const STEPConstruct_Part &SDRTool)
{
  Handle(TColStd_HSequenceOfTransient) seq = new TColStd_HSequenceOfTransient;

  seq->Append ( SDRTool.SDRValue() );
//  seq->Append ( GetAPD() );

  if ( ! SDRTool.PRPC().IsNull() ) seq->Append ( SDRTool.PRPC() );

  // for AP203, add required product management data
  if ( Interface_Static::IVal("write.step.schema") == 3 ) {
    theAP203.Init ( SDRTool );
    seq->Append (theAP203.GetProductCategoryRelationship());
    seq->Append (theAP203.GetCreator());
    seq->Append (theAP203.GetDesignOwner());
    seq->Append (theAP203.GetDesignSupplier());
    seq->Append (theAP203.GetClassificationOfficer());
    seq->Append (theAP203.GetSecurity());
    seq->Append (theAP203.GetCreationDate());
    seq->Append (theAP203.GetClassificationDate());
    seq->Append (theAP203.GetApproval());
    seq->Append (theAP203.GetApprover());
    seq->Append (theAP203.GetApprovalDateTime());
  }

  return seq;
}

//=======================================================================
//function : GetRootsForAssemblyLink
//purpose  : 
//=======================================================================

Handle(TColStd_HSequenceOfTransient) STEPConstruct_ContextTool::GetRootsForAssemblyLink (const STEPConstruct_Assembly &assembly)
{
  Handle(TColStd_HSequenceOfTransient) seq = new TColStd_HSequenceOfTransient;

  seq->Append ( assembly.ItemValue() );
  
  // for AP203, write required product management data
  if ( Interface_Static::IVal("write.step.schema") == 3 ) {
    theAP203.Init ( assembly.GetNAUO() );
    seq->Append (theAP203.GetSecurity());
    seq->Append (theAP203.GetClassificationOfficer());
    seq->Append (theAP203.GetClassificationDate());
    seq->Append (theAP203.GetApproval());
    seq->Append (theAP203.GetApprover());
    seq->Append (theAP203.GetApprovalDateTime());
  }

  return seq;
}