0025133: TKOpenGl - Crash on closing a view containing presentations with capping
[occt.git] / src / STEPConstruct / STEPConstruct_Part.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 //:k8 abv 6 Jan 99: unique names for PRODUCT_DEFINITION_FORMATIONs
15 //:k9 abv 6 Jan 99: TR10: eliminating duplicated APPLICATION_CONTEXT entities
16 //:j4 gka 16.03.99 S4134
17 //    abv 20.11.99 renamed from StepPDR_SDRtool
18 #include <STEPConstruct_Part.ixx>
19 #include <TCollection_HAsciiString.hxx>
20 #include <Interface_Static.hxx>
21
22 #include <StepBasic_ProductDefinition.hxx>
23 #include <StepBasic_ProductDefinitionContext.hxx>
24 #include <StepBasic_ProductDefinitionFormation.hxx>
25 #include <StepBasic_ProductDefinitionFormationWithSpecifiedSource.hxx>
26 #include <StepBasic_Product.hxx>
27 #include <StepBasic_DesignContext.hxx>
28 #include <StepBasic_ProductContext.hxx>
29 #include <StepBasic_MechanicalContext.hxx>
30 #include <StepBasic_HArray1OfProductContext.hxx>
31 #include <StepBasic_ApplicationContext.hxx>
32 #include <StepBasic_ProductType.hxx>
33 #include <StepBasic_HArray1OfProduct.hxx>
34 #include <StepRepr_ProductDefinitionShape.hxx>
35 #include <StepShape_ShapeRepresentation.hxx>
36 #include <StepShape_ShapeDefinitionRepresentation.hxx>
37
38 // ------------------------------
39 // Modification a faire : 
40 // ApplicationProtocolDefinition status
41 // ApplicationProtocolDefinition year
42 // ApplicationProtocolDefinition schema_name
43 // ces information ne sont plus accessibles en parcourant le graphe a partir
44 // du ShapeDefinitionRepresentation.
45 // Elles se trouvent dans Cc1 au niveau d`une entite racine !
46 // ------------------------------
47
48 //=======================================================================
49 //function : STEPConstruct_Part
50 //purpose  : 
51 //=======================================================================
52
53 STEPConstruct_Part::STEPConstruct_Part() 
54 {
55   myDone = Standard_False;
56 }
57
58 //=======================================================================
59 //function : MakeSDR
60 //purpose  : 
61 //=======================================================================
62
63 void STEPConstruct_Part::MakeSDR(const Handle(StepShape_ShapeRepresentation)& SR,
64                                  const Handle(TCollection_HAsciiString)& aName,
65                                  const Handle(StepBasic_ApplicationContext)& AC)
66 {
67   // get current schema
68   Standard_Integer schema = Interface_Static::IVal("write.step.schema");
69   
70   // create PC
71   Handle(StepBasic_ProductContext) PC;
72   switch (schema) {
73   default :
74   case 1: PC = new StepBasic_MechanicalContext;
75           break;
76   case 4:
77   case 2: PC = new StepBasic_ProductContext;
78           break;
79   case 3: PC = new StepBasic_MechanicalContext; 
80           break;
81   }
82   Handle(TCollection_HAsciiString) PCname = new TCollection_HAsciiString("");
83   Handle(TCollection_HAsciiString) PCdisciplineType = 
84     new TCollection_HAsciiString("mechanical");
85   PC->Init(PCname, AC, PCdisciplineType);
86   
87   // create product
88   Handle(StepBasic_Product) P = new StepBasic_Product;
89   Handle(StepBasic_HArray1OfProductContext) PCs = new StepBasic_HArray1OfProductContext(1,1);  
90   PCs->SetValue(1,PC);
91   Handle(TCollection_HAsciiString) Pdescription = new TCollection_HAsciiString("");
92   P->Init(aName, aName, Pdescription, PCs);
93
94   // create PDF
95   Handle(StepBasic_ProductDefinitionFormation) PDF;
96   switch (schema) {
97   default:
98   case 1: 
99   case 2: PDF = new StepBasic_ProductDefinitionFormation;
100           break;
101   case 3: PDF = new StepBasic_ProductDefinitionFormationWithSpecifiedSource;
102           Handle(StepBasic_ProductDefinitionFormationWithSpecifiedSource)::DownCast(PDF)->
103             SetMakeOrBuy(StepBasic_sNotKnown);
104           break;
105   }
106   Handle(TCollection_HAsciiString) PDFName = new TCollection_HAsciiString("");
107   Handle(TCollection_HAsciiString) PDFdescription = new TCollection_HAsciiString("");
108   PDF->Init(PDFName, PDFdescription, P);
109
110   // create PDC, depending on current schema
111   Handle(StepBasic_ProductDefinitionContext) PDC;
112   Handle(TCollection_HAsciiString) PDCname;
113   switch (schema) {
114   default:
115   case 1: 
116   case 2: PDC = new StepBasic_ProductDefinitionContext;
117           PDCname = new TCollection_HAsciiString ("part definition");
118           break;
119   case 3: PDC = new StepBasic_DesignContext;
120           PDCname = new TCollection_HAsciiString("");
121           break;
122   }
123   Handle(TCollection_HAsciiString) PDClifeCycleStage = new TCollection_HAsciiString("design");
124   PDC->Init(PDCname, AC, PDClifeCycleStage);
125
126   // create PD
127   Handle(StepBasic_ProductDefinition) PD = new StepBasic_ProductDefinition;
128   Handle(TCollection_HAsciiString) PDId = new TCollection_HAsciiString("design");
129   Handle(TCollection_HAsciiString) PDdescription = new TCollection_HAsciiString("");
130   PD->Init(PDId, PDdescription, PDF, PDC);
131
132   // create PDS
133   Handle(StepRepr_ProductDefinitionShape) PDS = new StepRepr_ProductDefinitionShape;
134   Handle(TCollection_HAsciiString) PDSname = new TCollection_HAsciiString("");
135   Handle(TCollection_HAsciiString) PDSdescription = new TCollection_HAsciiString("");
136   StepRepr_CharacterizedDefinition CD;
137   CD.SetValue(PD);
138   PDS->Init(PDSname, Standard_True, PDSdescription, CD);
139
140   // finally, create SDR
141   mySDR  = new StepShape_ShapeDefinitionRepresentation;
142   StepRepr_RepresentedDefinition RD;
143   RD.SetValue ( PDS );
144   mySDR->Init(RD, SR);
145
146   // and an associated PRPC
147   Handle(TCollection_HAsciiString) PRPCName;
148   switch (Interface_Static::IVal("write.step.schema")) {
149   default:
150   case 1: 
151     myPRPC = new StepBasic_ProductType; 
152     PRPCName = new TCollection_HAsciiString("part") ;
153     break;
154   case 4:
155   case 2: 
156     myPRPC = new StepBasic_ProductRelatedProductCategory; 
157     PRPCName = new TCollection_HAsciiString("part");
158     break;
159   case 3: 
160     myPRPC = new StepBasic_ProductRelatedProductCategory; 
161     PRPCName = new TCollection_HAsciiString("detail"); // !!!!! or "assembly"
162     break;
163   }
164   Handle(StepBasic_HArray1OfProduct) PRPCproducts = new StepBasic_HArray1OfProduct(1,1);  
165   PRPCproducts->SetValue(1,P);
166   myPRPC->Init ( PRPCName, Standard_False, 0, PRPCproducts );
167   
168   myDone = Standard_True;
169 }
170
171 //=======================================================================
172 //function : ReadSDR
173 //purpose  : 
174 //=======================================================================
175
176 void STEPConstruct_Part::ReadSDR(const Handle(StepShape_ShapeDefinitionRepresentation)& aShape)
177 {
178   mySDR = aShape;
179   myDone = ( ! mySDR.IsNull() );
180 }
181
182 //=======================================================================
183 //function : IsDone
184 //purpose  : 
185 //=======================================================================
186
187 Standard_Boolean STEPConstruct_Part::IsDone() const
188 {
189   return myDone;
190 }
191
192 //=======================================================================
193 //function : SDRValue
194 //purpose  : 
195 //=======================================================================
196
197 Handle(StepShape_ShapeDefinitionRepresentation) STEPConstruct_Part::SDRValue() const
198 {
199   return mySDR;
200 }
201
202 //=======================================================================
203 //function : SRValue
204 //purpose  : 
205 //=======================================================================
206
207 Handle(StepShape_ShapeRepresentation) STEPConstruct_Part::SRValue() const
208 {
209   if ( ! myDone ) return 0;
210   return Handle(StepShape_ShapeRepresentation)::DownCast(mySDR->UsedRepresentation());
211 }
212
213 //=======================================================================
214 //function : PCname
215 //purpose  : 
216 //=======================================================================
217
218 Handle(TCollection_HAsciiString) STEPConstruct_Part::PCname() const
219 {
220   return mySDR->Definition().PropertyDefinition()
221               ->Definition().ProductDefinition()
222                 ->Formation()
223                   ->OfProduct()
224                     ->FrameOfReferenceValue(1)
225                       ->Name();
226 }
227
228 //=======================================================================
229 //function : PC
230 //purpose  : 
231 //=======================================================================
232
233 Handle(StepBasic_ProductContext) STEPConstruct_Part::PC() const
234 {
235   return mySDR->Definition().PropertyDefinition()
236               ->Definition().ProductDefinition()
237                 ->Formation()
238                   ->OfProduct()
239                     ->FrameOfReferenceValue(1);
240 }
241
242 //=======================================================================
243 //function : PCdisciplineType
244 //purpose  : 
245 //=======================================================================
246
247 Handle(TCollection_HAsciiString) STEPConstruct_Part::PCdisciplineType() const
248 {
249   return mySDR->Definition().PropertyDefinition()
250               ->Definition().ProductDefinition()
251                 ->Formation()
252                   ->OfProduct()
253                     ->FrameOfReferenceValue(1)
254                       ->DisciplineType();
255
256 }
257
258 //=======================================================================
259 //function : SetPCname
260 //purpose  : 
261 //=======================================================================
262
263 void STEPConstruct_Part::SetPCname(const Handle(TCollection_HAsciiString)& name)
264 {
265   mySDR->Definition().PropertyDefinition()
266        ->Definition().ProductDefinition()
267           ->Formation()
268             ->OfProduct()
269               ->FrameOfReferenceValue(1)
270                 ->SetName(name); 
271 }
272
273 //=======================================================================
274 //function : SetPCdisciplineType
275 //purpose  : 
276 //=======================================================================
277
278 void STEPConstruct_Part::SetPCdisciplineType(const Handle(TCollection_HAsciiString)& label)
279 {
280   mySDR->Definition().PropertyDefinition()
281        ->Definition().ProductDefinition()
282           ->Formation()
283             ->OfProduct()
284               ->FrameOfReferenceValue(1)
285                 ->SetDisciplineType(label);
286 }
287
288 //=======================================================================
289 //function : AC
290 //purpose  : 
291 //=======================================================================
292
293 Handle(StepBasic_ApplicationContext) STEPConstruct_Part::AC() const
294 {
295   return mySDR->Definition().PropertyDefinition()
296               ->Definition().ProductDefinition()
297                 ->Formation()
298                   ->OfProduct()
299                     ->FrameOfReferenceValue(1)
300                       ->FrameOfReference();
301 }
302
303 //=======================================================================
304 //function : ACapplication
305 //purpose  : 
306 //=======================================================================
307
308 Handle(TCollection_HAsciiString) STEPConstruct_Part::ACapplication() const
309 {
310   return mySDR->Definition().PropertyDefinition()
311               ->Definition().ProductDefinition()
312                 ->Formation()
313                   ->OfProduct()
314                     ->FrameOfReferenceValue(1)
315                       ->FrameOfReference()
316                         ->Application(); 
317 }
318
319 //=======================================================================
320 //function : SetACapplication
321 //purpose  : 
322 //=======================================================================
323
324 void STEPConstruct_Part::SetACapplication(const Handle(TCollection_HAsciiString)& text)
325 {
326   mySDR->Definition().PropertyDefinition()
327        ->Definition().ProductDefinition()
328           ->Formation()
329             ->OfProduct()
330               ->FrameOfReferenceValue(1)
331                 ->FrameOfReference()
332                   ->SetApplication(text);
333
334 }
335
336 //=======================================================================
337 //function : PDC
338 //purpose  : 
339 //=======================================================================
340
341 Handle(StepBasic_ProductDefinitionContext) STEPConstruct_Part::PDC() const
342 {
343   return mySDR->Definition().PropertyDefinition()
344               ->Definition().ProductDefinition()
345                 ->FrameOfReference();
346 }
347
348 //=======================================================================
349 //function : PDCname
350 //purpose  : 
351 //=======================================================================
352
353 Handle(TCollection_HAsciiString) STEPConstruct_Part::PDCname() const
354 {
355   return mySDR->Definition().PropertyDefinition()
356               ->Definition().ProductDefinition()
357                 ->FrameOfReference()
358                   ->Name();
359 }
360
361 //=======================================================================
362 //function : PDCstage
363 //purpose  : 
364 //=======================================================================
365
366 Handle(TCollection_HAsciiString) STEPConstruct_Part::PDCstage() const
367 {
368   return mySDR->Definition().PropertyDefinition()
369               ->Definition().ProductDefinition()
370                 ->FrameOfReference()
371                   ->LifeCycleStage();
372
373 }
374  
375 //=======================================================================
376 //function : SetPDCname
377 //purpose  : 
378 //=======================================================================
379
380 void STEPConstruct_Part::SetPDCname(const Handle(TCollection_HAsciiString)& label)
381 {
382   mySDR->Definition().PropertyDefinition()
383        ->Definition().ProductDefinition()
384           ->FrameOfReference()
385             ->SetName(label);
386 }
387
388 //=======================================================================
389 //function : SetPDCstage
390 //purpose  : 
391 //=======================================================================
392
393 void STEPConstruct_Part::SetPDCstage(const Handle(TCollection_HAsciiString)& label)
394 {
395   mySDR->Definition().PropertyDefinition()
396        ->Definition().ProductDefinition()
397           ->FrameOfReference()
398             ->SetLifeCycleStage(label);
399 }
400
401 //=======================================================================
402 //function : Product
403 //purpose  : 
404 //=======================================================================
405
406 Handle(StepBasic_Product) STEPConstruct_Part::Product() const
407 {
408   return mySDR->Definition().PropertyDefinition()
409               ->Definition().ProductDefinition()
410                 ->Formation()
411                   ->OfProduct();
412 }
413
414 //=======================================================================
415 //function : Pid
416 //purpose  : 
417 //=======================================================================
418
419 Handle(TCollection_HAsciiString) STEPConstruct_Part::Pid() const
420 {
421   return mySDR->Definition().PropertyDefinition()
422               ->Definition().ProductDefinition()
423                 ->Formation()
424                   ->OfProduct()
425                     ->Id();
426 }
427
428 //=======================================================================
429 //function : Pname
430 //purpose  : 
431 //=======================================================================
432
433 Handle(TCollection_HAsciiString) STEPConstruct_Part::Pname() const
434 {
435   return mySDR->Definition().PropertyDefinition()
436               ->Definition().ProductDefinition()
437                 ->Formation()
438                   ->OfProduct()
439                     ->Name();
440 }
441
442 //=======================================================================
443 //function : Pdescription
444 //purpose  : 
445 //=======================================================================
446
447 Handle(TCollection_HAsciiString) STEPConstruct_Part::Pdescription() const
448 {
449   return mySDR->Definition().PropertyDefinition()
450               ->Definition().ProductDefinition()
451                 ->Formation()
452                   ->OfProduct()
453                     ->Description();
454 }
455
456 //=======================================================================
457 //function : SetPid
458 //purpose  : 
459 //=======================================================================
460
461 void STEPConstruct_Part::SetPid(const Handle(TCollection_HAsciiString)& id)
462 {
463   mySDR->Definition().PropertyDefinition()
464        ->Definition().ProductDefinition()
465          ->Formation()
466            ->OfProduct()
467              ->SetId(id);
468 }
469
470 //=======================================================================
471 //function : SetPname
472 //purpose  : 
473 //=======================================================================
474
475 void STEPConstruct_Part::SetPname(const Handle(TCollection_HAsciiString)& label)
476 {
477   mySDR->Definition().PropertyDefinition()
478        ->Definition().ProductDefinition()
479          ->Formation()
480            ->OfProduct()
481              ->SetName(label);
482 }
483
484 //=======================================================================
485 //function : SetPdescription
486 //purpose  : 
487 //=======================================================================
488
489 void STEPConstruct_Part::SetPdescription(const Handle(TCollection_HAsciiString)& text)
490 {
491   mySDR->Definition().PropertyDefinition()
492        ->Definition().ProductDefinition()
493          ->Formation()
494            ->OfProduct()
495              ->SetDescription(text);
496
497 }
498
499 //=======================================================================
500 //function : PDF
501 //purpose  : 
502 //=======================================================================
503
504 Handle(StepBasic_ProductDefinitionFormation) STEPConstruct_Part::PDF() const
505 {
506   return mySDR->Definition().PropertyDefinition()
507               ->Definition().ProductDefinition()
508                 ->Formation();
509 }
510
511 //=======================================================================
512 //function : PDFid
513 //purpose  : 
514 //=======================================================================
515
516 Handle(TCollection_HAsciiString) STEPConstruct_Part::PDFid() const
517 {
518   return mySDR->Definition().PropertyDefinition()
519               ->Definition().ProductDefinition()
520                 ->Formation()
521                   ->Id();
522 }
523
524 //=======================================================================
525 //function : PDFdescription
526 //purpose  : 
527 //=======================================================================
528
529 Handle(TCollection_HAsciiString) STEPConstruct_Part::PDFdescription() const
530 {
531   return mySDR->Definition().PropertyDefinition()
532               ->Definition().ProductDefinition()
533                 ->Formation()
534                   ->Description();
535 }
536
537 //=======================================================================
538 //function : SetPDFid
539 //purpose  : 
540 //=======================================================================
541
542 void STEPConstruct_Part::SetPDFid(const Handle(TCollection_HAsciiString)& id)
543 {
544   mySDR->Definition().PropertyDefinition()
545        ->Definition().ProductDefinition()
546          ->Formation()
547            ->SetId(id);
548 }
549
550 //=======================================================================
551 //function : SetPDFdescription
552 //purpose  : 
553 //=======================================================================
554
555 void STEPConstruct_Part::SetPDFdescription(const Handle(TCollection_HAsciiString)& text)
556 {
557   mySDR->Definition().PropertyDefinition()
558        ->Definition().ProductDefinition()
559          ->Formation()
560            ->SetDescription(text);
561 }
562
563 //=======================================================================
564 //function : PDS
565 //purpose  : 
566 //=======================================================================
567
568 Handle(StepRepr_ProductDefinitionShape) STEPConstruct_Part::PDS() const
569 {
570   return Handle(StepRepr_ProductDefinitionShape)::DownCast ( mySDR->Definition().PropertyDefinition() );
571 }
572
573 //=======================================================================
574 //function : PDSname
575 //purpose  : 
576 //=======================================================================
577
578 Handle(TCollection_HAsciiString) STEPConstruct_Part::PDSname() const
579 {
580   return mySDR->Definition().PropertyDefinition()->Name();
581 }
582
583 //=======================================================================
584 //function : PDSdescription
585 //purpose  : 
586 //=======================================================================
587
588 Handle(TCollection_HAsciiString) STEPConstruct_Part::PDSdescription() const
589 {
590   return mySDR->Definition().PropertyDefinition()->Description();
591 }
592
593 //=======================================================================
594 //function : SetPDSname
595 //purpose  : 
596 //=======================================================================
597
598 void STEPConstruct_Part::SetPDSname(const Handle(TCollection_HAsciiString)& label)
599 {
600   mySDR->Definition().PropertyDefinition()->SetName(label);
601 }
602
603 //=======================================================================
604 //function : SetPDSdescription
605 //purpose  : 
606 //=======================================================================
607
608 void STEPConstruct_Part::SetPDSdescription(const Handle(TCollection_HAsciiString)& text)
609 {
610   mySDR->Definition().PropertyDefinition()->SetDescription(text);
611 }
612
613 //=======================================================================
614 //function : PD
615 //purpose  : 
616 //=======================================================================
617
618 Handle(StepBasic_ProductDefinition) STEPConstruct_Part::PD() const
619 {
620   return mySDR->Definition().PropertyDefinition()->Definition().ProductDefinition();
621 }
622
623 //=======================================================================
624 //function : PDdescription
625 //purpose  : 
626 //=======================================================================
627
628 Handle(TCollection_HAsciiString) STEPConstruct_Part::PDdescription() const
629 {
630   return mySDR->Definition().PropertyDefinition()
631               ->Definition().ProductDefinition()
632                 ->Description();
633 }
634
635 //=======================================================================
636 //function : SetPDdescription
637 //purpose  : 
638 //=======================================================================
639
640 // a modifier
641 void STEPConstruct_Part::SetPDdescription(const Handle(TCollection_HAsciiString) &text)
642 {
643   mySDR->Definition().PropertyDefinition()
644        ->Definition().ProductDefinition()
645          ->SetDescription(text);
646 }
647
648 //=======================================================================
649 //function : PRPC
650 //purpose  : 
651 //=======================================================================
652
653 Handle(StepBasic_ProductRelatedProductCategory) STEPConstruct_Part::PRPC () const
654 {
655   return myPRPC;
656 }
657
658 //=======================================================================
659 //function : PRPCname
660 //purpose  : 
661 //=======================================================================
662
663 Handle(TCollection_HAsciiString) STEPConstruct_Part::PRPCname () const
664 {
665   return myPRPC->Name();
666 }
667
668 //=======================================================================
669 //function : PRPCdescription
670 //purpose  : 
671 //=======================================================================
672
673 Handle(TCollection_HAsciiString) STEPConstruct_Part::PRPCdescription () const
674 {
675   return myPRPC->Description();
676 }
677
678 //=======================================================================
679 //function : SetPRPCname
680 //purpose  : 
681 //=======================================================================
682
683 void STEPConstruct_Part::SetPRPCname (const Handle(TCollection_HAsciiString) &text)
684 {
685   myPRPC->SetName ( text );
686 }
687
688 //=======================================================================
689 //function : SetPRPCdescription
690 //purpose  : 
691 //=======================================================================
692
693 void STEPConstruct_Part::SetPRPCdescription (const Handle(TCollection_HAsciiString) &text)
694 {
695   myPRPC->SetDescription ( text );
696 }
697