1 // Created on: 1999-11-19
2 // Created by: Andrey BETENEV
3 // Copyright (c) 1999-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 #include <STEPConstruct_AP203Context.ixx>
23 # include <winsock2.h>
28 #include <OSD_Process.hxx>
29 #include <Quantity_Date.hxx>
31 #include <TCollection_HAsciiString.hxx>
32 #include <TColStd_SequenceOfAsciiString.hxx>
33 #include <Interface_HArray1OfHAsciiString.hxx>
35 #include <StepBasic_CalendarDate.hxx>
36 #include <StepBasic_LocalTime.hxx>
37 #include <StepBasic_ApprovalStatus.hxx>
38 #include <StepBasic_CoordinatedUniversalTimeOffset.hxx>
39 #include <StepBasic_AheadOrBehind.hxx>
40 #include <StepBasic_Person.hxx>
41 #include <StepBasic_Organization.hxx>
42 #include <StepBasic_SecurityClassification.hxx>
43 #include <StepAP203_HArray1OfPersonOrganizationItem.hxx>
44 #include <StepAP203_HArray1OfClassifiedItem.hxx>
45 #include <StepAP203_HArray1OfDateTimeItem.hxx>
46 #include <StepAP203_HArray1OfApprovedItem.hxx>
47 #include <StepBasic_ProductCategory.hxx>
49 //=======================================================================
50 //function : STEPConstruct_AP203Context
52 //=======================================================================
54 STEPConstruct_AP203Context::STEPConstruct_AP203Context ()
59 //=======================================================================
60 //function : DefaultApproval
62 //=======================================================================
64 Handle(StepBasic_Approval) STEPConstruct_AP203Context::DefaultApproval ()
66 if ( defApproval.IsNull() ) {
67 Handle(StepBasic_ApprovalStatus) aStatus = new StepBasic_ApprovalStatus;
68 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString ("not_yet_approved");
69 aStatus->Init ( aName );
71 Handle(TCollection_HAsciiString) aLevel = new TCollection_HAsciiString ("");
72 defApproval = new StepBasic_Approval;
73 defApproval->Init ( aStatus, aLevel );
78 //=======================================================================
79 //function : SetDefaultApproval
81 //=======================================================================
83 void STEPConstruct_AP203Context::SetDefaultApproval (const Handle(StepBasic_Approval) &app)
88 //=======================================================================
89 //function : DefaultDateAndTime
91 //=======================================================================
93 Handle(StepBasic_DateAndTime) STEPConstruct_AP203Context::DefaultDateAndTime ()
95 if ( defDateAndTime.IsNull() ) {
97 Quantity_Date date = sys.SystemDate ();
99 Handle(StepBasic_CalendarDate) aDate = new StepBasic_CalendarDate;
100 aDate->Init ( date.Year(), date.Day(), date.Month() );
102 Handle(StepBasic_CoordinatedUniversalTimeOffset) zone =
103 new StepBasic_CoordinatedUniversalTimeOffset;
104 Standard_Integer shift = Standard_Integer(timezone);
105 Standard_Integer shifth = abs ( shift ) / 3600;
106 Standard_Integer shiftm = ( abs ( shift ) - shifth * 3600 ) / 60;
107 StepBasic_AheadOrBehind sense = ( shift >0 ? StepBasic_aobBehind :
108 shift <0 ? StepBasic_aobAhead :
109 StepBasic_aobExact );
110 zone->Init ( shifth, ( shiftm != 0 ), shiftm, sense );
112 Handle(StepBasic_LocalTime) aTime = new StepBasic_LocalTime;
113 aTime->Init ( date.Hour(), Standard_True, date.Minute(), Standard_False, 0., zone );
115 defDateAndTime = new StepBasic_DateAndTime;
116 defDateAndTime->Init ( aDate, aTime );
118 return defDateAndTime;
121 //=======================================================================
122 //function : SetDefaultDateAndTime
124 //=======================================================================
126 void STEPConstruct_AP203Context::SetDefaultDateAndTime (const Handle(StepBasic_DateAndTime) &dt)
131 //=======================================================================
132 //function : DefaultPersonAndOrganization
134 //=======================================================================
136 Handle(StepBasic_PersonAndOrganization) STEPConstruct_AP203Context::DefaultPersonAndOrganization ()
138 if ( defPersonAndOrganization.IsNull() ) {
139 // get IP address as a unique id of organization
140 #ifdef WNT // adapted for NT which lacks gethostent()
143 gethostname ( hostname, 1020 );
144 hostname[1020] = '\0';
145 struct hostent *he = gethostbyname ( hostname );
146 #else // adapted for Sun2.5, which lacks definition of gethostname()
147 struct hostent *he = gethostent();
148 while ( he && he->h_name && (unsigned char)he->h_addr_list[0][0] == 127 )
151 Handle(TCollection_HAsciiString) orgId = new TCollection_HAsciiString ( "" );
152 if ( he && he->h_addr_list && he->h_length >0 ) {
154 unsigned i1 = (unsigned char)he->h_addr_list[0][0];
155 unsigned i2 = (unsigned char)he->h_addr_list[0][1];
156 unsigned i3 = (unsigned char)he->h_addr_list[0][2];
157 sprintf ( str, "IP%03u.%03u.%03u.000", i1, i2, i3 );
158 orgId->AssignCat ( str );
161 // create organization
162 Handle(StepBasic_Organization) aOrg = new StepBasic_Organization;
163 Handle(TCollection_HAsciiString) oName = new TCollection_HAsciiString ( "Unspecified" );
164 Handle(TCollection_HAsciiString) oDescr = new TCollection_HAsciiString ( "" );
165 aOrg->Init ( Standard_True, orgId, oName, oDescr );
167 // construct person`s name
169 Standard_CString usr = sys.UserName().ToCString();
170 #if !defined(_WIN32) && !defined(__ANDROID__)
172 struct passwd *pwd = getpwnam ( usr );
173 if ( pwd ) usr = pwd->pw_gecos;
175 else usr = "Unknown";
177 TCollection_AsciiString user ( usr );
178 Handle(TCollection_HAsciiString) fname = new TCollection_HAsciiString ("");
179 Handle(TCollection_HAsciiString) lname = new TCollection_HAsciiString ("");
180 Handle(Interface_HArray1OfHAsciiString) mname;
181 TColStd_SequenceOfAsciiString names;
182 Standard_Integer i; // svv Jan11 2000 : porting on DEC
184 TCollection_AsciiString token = user.Token ( " \t", i );
185 if ( ! token.Length() ) break;
186 names.Append ( token );
188 if ( names.Length() >0 ) fname->AssignCat ( names.Value(1).ToCString() );
189 if ( names.Length() >1 ) lname->AssignCat ( names.Value(names.Length()).ToCString() );
190 if ( names.Length() >2 ) {
191 mname = new Interface_HArray1OfHAsciiString ( 1, names.Length()-2 );
192 for ( i=2; i < names.Length(); i++ )
193 mname->SetValue ( i-1, new TCollection_HAsciiString ( names.Value(i) ) );
197 Handle(StepBasic_Person) aPerson = new StepBasic_Person;
198 Handle(TCollection_HAsciiString) uid = new TCollection_HAsciiString ( orgId );
199 uid->AssignCat ( "," );
200 uid->AssignCat ( TCollection_AsciiString ( sys.UserId() ).ToCString() );
201 Handle(Interface_HArray1OfHAsciiString) suffix, prefix;
202 aPerson->Init ( uid, Standard_True, lname, Standard_True, fname, ( ! mname.IsNull() ),
203 mname, Standard_False, suffix, Standard_False, prefix );
205 defPersonAndOrganization = new StepBasic_PersonAndOrganization;
206 defPersonAndOrganization->Init ( aPerson, aOrg );
208 return defPersonAndOrganization;
211 //=======================================================================
212 //function : SetDefaultPersonAndOrganization
214 //=======================================================================
216 void STEPConstruct_AP203Context::SetDefaultPersonAndOrganization (const Handle(StepBasic_PersonAndOrganization) &po)
218 defPersonAndOrganization = po;
221 //=======================================================================
222 //function : DefaultSecurityClassificationLevel
224 //=======================================================================
226 Handle(StepBasic_SecurityClassificationLevel) STEPConstruct_AP203Context::DefaultSecurityClassificationLevel ()
228 if ( defSecurityClassificationLevel.IsNull() ) {
229 defSecurityClassificationLevel = new StepBasic_SecurityClassificationLevel;
230 Handle(TCollection_HAsciiString) levName = new TCollection_HAsciiString ( "unclassified" );
231 defSecurityClassificationLevel->Init ( levName );
233 return defSecurityClassificationLevel;
236 //=======================================================================
237 //function : SetDefaultSecurityClassificationLevel
239 //=======================================================================
241 void STEPConstruct_AP203Context::SetDefaultSecurityClassificationLevel (const Handle(StepBasic_SecurityClassificationLevel) &scl)
243 defSecurityClassificationLevel = scl;
246 //=======================================================================
247 //function : RoleCreator
249 //=======================================================================
251 Handle(StepBasic_PersonAndOrganizationRole) STEPConstruct_AP203Context::RoleCreator () const
256 //=======================================================================
257 //function : RoleDesignOwner
259 //=======================================================================
261 Handle(StepBasic_PersonAndOrganizationRole) STEPConstruct_AP203Context::RoleDesignOwner () const
263 return roleDesignOwner;
266 //=======================================================================
267 //function : RoleDesignSupplier
269 //=======================================================================
271 Handle(StepBasic_PersonAndOrganizationRole) STEPConstruct_AP203Context::RoleDesignSupplier () const
273 return roleDesignSupplier;
276 //=======================================================================
277 //function : RoleClassificationOfficer
279 //=======================================================================
281 Handle(StepBasic_PersonAndOrganizationRole) STEPConstruct_AP203Context::RoleClassificationOfficer () const
283 return roleClassificationOfficer;
286 //=======================================================================
287 //function : RoleCreationDate
289 //=======================================================================
291 Handle(StepBasic_DateTimeRole) STEPConstruct_AP203Context::RoleCreationDate () const
293 return roleCreationDate;
296 //=======================================================================
297 //function : RoleClassificationDate
299 //=======================================================================
301 Handle(StepBasic_DateTimeRole) STEPConstruct_AP203Context::RoleClassificationDate () const
303 return roleClassificationDate;
306 //=======================================================================
307 //function : RoleApprover
309 //=======================================================================
311 Handle(StepBasic_ApprovalRole) STEPConstruct_AP203Context::RoleApprover () const
316 //=======================================================================
319 //=======================================================================
321 void STEPConstruct_AP203Context::Init (const Handle(StepShape_ShapeDefinitionRepresentation) &sdr)
324 STEPConstruct_Part SDRTool;
325 SDRTool.ReadSDR ( sdr );
326 InitPart ( SDRTool );
329 //=======================================================================
332 //=======================================================================
334 void STEPConstruct_AP203Context::Init (const STEPConstruct_Part &SDRTool)
337 InitPart ( SDRTool );
340 //=======================================================================
343 //=======================================================================
345 //void STEPConstruct_AP203Context::Init (const STEPConstruct_Part &SDRTool, const Handle(Interface_Model) &Model) {}
347 //=======================================================================
350 //=======================================================================
352 void STEPConstruct_AP203Context::Init (const Handle(StepRepr_NextAssemblyUsageOccurrence) &NAUO)
355 InitAssembly ( NAUO );
358 //=======================================================================
359 //function : GetCreator
361 //=======================================================================
363 Handle(StepAP203_CcDesignPersonAndOrganizationAssignment) STEPConstruct_AP203Context::GetCreator () const
368 //=======================================================================
369 //function : GetDesignOwner
371 //=======================================================================
373 Handle(StepAP203_CcDesignPersonAndOrganizationAssignment) STEPConstruct_AP203Context::GetDesignOwner () const
375 return myDesignOwner;
378 //=======================================================================
379 //function : GetDesignSupplier
381 //=======================================================================
383 Handle(StepAP203_CcDesignPersonAndOrganizationAssignment) STEPConstruct_AP203Context::GetDesignSupplier () const
385 return myDesignSupplier;
388 //=======================================================================
389 //function : GetClassificationOfficer
391 //=======================================================================
393 Handle(StepAP203_CcDesignPersonAndOrganizationAssignment) STEPConstruct_AP203Context::GetClassificationOfficer () const
395 return myClassificationOfficer;
398 //=======================================================================
399 //function : GetSecurity
401 //=======================================================================
403 Handle(StepAP203_CcDesignSecurityClassification) STEPConstruct_AP203Context::GetSecurity () const
408 //=======================================================================
409 //function : GetCreationDate
411 //=======================================================================
413 Handle(StepAP203_CcDesignDateAndTimeAssignment) STEPConstruct_AP203Context::GetCreationDate () const
415 return myCreationDate;
418 //=======================================================================
419 //function : GetClassificationDate
421 //=======================================================================
423 Handle(StepAP203_CcDesignDateAndTimeAssignment) STEPConstruct_AP203Context::GetClassificationDate () const
425 return myClassificationDate;
428 //=======================================================================
429 //function : GetApproval
431 //=======================================================================
433 Handle(StepAP203_CcDesignApproval) STEPConstruct_AP203Context::GetApproval () const
438 //=======================================================================
439 //function : GetApprover
441 //=======================================================================
443 Handle(StepBasic_ApprovalPersonOrganization) STEPConstruct_AP203Context::GetApprover () const
448 //=======================================================================
449 //function : GetApprovalDateTime
451 //=======================================================================
453 Handle(StepBasic_ApprovalDateTime) STEPConstruct_AP203Context::GetApprovalDateTime () const
455 return myApprovalDateTime;
458 //=======================================================================
459 //function : GetProductCategoryRelationship
461 //=======================================================================
463 Handle(StepBasic_ProductCategoryRelationship) STEPConstruct_AP203Context::GetProductCategoryRelationship () const
465 return myProductCategoryRelationship;
468 //=======================================================================
471 //=======================================================================
473 void STEPConstruct_AP203Context::Clear ()
476 myDesignOwner.Nullify();
477 myDesignSupplier.Nullify();
478 myClassificationOfficer.Nullify();
479 mySecurity.Nullify();
480 myCreationDate.Nullify();
481 myClassificationDate.Nullify();
482 myApproval.Nullify();
484 // myApprover.Nullify();
485 // myApprovalDateTime.Nullify();
487 myProductCategoryRelationship.Nullify();
490 //=======================================================================
491 //function : InitRoles
493 //=======================================================================
495 void STEPConstruct_AP203Context::InitRoles ()
497 roleCreator = new StepBasic_PersonAndOrganizationRole;
498 roleDesignOwner = new StepBasic_PersonAndOrganizationRole;
499 roleDesignSupplier = new StepBasic_PersonAndOrganizationRole;
500 roleClassificationOfficer = new StepBasic_PersonAndOrganizationRole;
501 roleCreationDate = new StepBasic_DateTimeRole;
502 roleClassificationDate = new StepBasic_DateTimeRole;
503 roleApprover = new StepBasic_ApprovalRole;
505 roleCreator->Init ( new TCollection_HAsciiString ( "creator" ) );
506 roleDesignOwner->Init ( new TCollection_HAsciiString ( "design_owner" ) );
507 roleDesignSupplier->Init ( new TCollection_HAsciiString ( "design_supplier" ) );
508 roleClassificationOfficer->Init ( new TCollection_HAsciiString ( "classification_officer" ) );
509 roleCreationDate->Init ( new TCollection_HAsciiString ( "creation_date" ) );
510 roleClassificationDate->Init ( new TCollection_HAsciiString ( "classification_date" ) );
511 roleApprover->Init ( new TCollection_HAsciiString ( "approver" ) );
514 //=======================================================================
515 //function : InitPart
517 //=======================================================================
519 void STEPConstruct_AP203Context::InitPart (const STEPConstruct_Part &SDRTool)
521 if ( myCreator.IsNull() ) {
522 myCreator = new StepAP203_CcDesignPersonAndOrganizationAssignment;
523 Handle(StepAP203_HArray1OfPersonOrganizationItem) items =
524 new StepAP203_HArray1OfPersonOrganizationItem (1, 2);
525 items->ChangeValue(1).SetValue ( SDRTool.PDF() );
526 items->ChangeValue(2).SetValue ( SDRTool.PD() );
527 myCreator->Init ( DefaultPersonAndOrganization(), RoleCreator(), items );
530 if ( myDesignOwner.IsNull() ) {
531 myDesignOwner = new StepAP203_CcDesignPersonAndOrganizationAssignment;
532 Handle(StepAP203_HArray1OfPersonOrganizationItem) items =
533 new StepAP203_HArray1OfPersonOrganizationItem (1, 1);
534 items->ChangeValue(1).SetValue ( SDRTool.Product() );
535 myDesignOwner->Init ( DefaultPersonAndOrganization(), RoleDesignOwner(), items );
538 if ( myDesignSupplier.IsNull() ) {
539 myDesignSupplier = new StepAP203_CcDesignPersonAndOrganizationAssignment;
540 Handle(StepAP203_HArray1OfPersonOrganizationItem) items =
541 new StepAP203_HArray1OfPersonOrganizationItem (1, 1);
542 items->ChangeValue(1).SetValue ( SDRTool.PDF() );
543 myDesignSupplier->Init ( DefaultPersonAndOrganization(), RoleDesignSupplier(), items );
546 if ( myCreationDate.IsNull() ) {
547 myCreationDate = new StepAP203_CcDesignDateAndTimeAssignment;
548 Handle(StepAP203_HArray1OfDateTimeItem) items =
549 new StepAP203_HArray1OfDateTimeItem (1, 1);
550 items->ChangeValue(1).SetValue ( SDRTool.PD() );
551 myCreationDate->Init ( DefaultDateAndTime(), RoleCreationDate(), items );
554 if ( mySecurity.IsNull() ) {
556 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString ( "" );
557 Handle(TCollection_HAsciiString) aPurpose = new TCollection_HAsciiString ( "" );
558 Handle(StepBasic_SecurityClassification) sc = new StepBasic_SecurityClassification;
559 sc->Init ( aName, aPurpose, DefaultSecurityClassificationLevel() );
561 mySecurity = new StepAP203_CcDesignSecurityClassification;
562 Handle(StepAP203_HArray1OfClassifiedItem) items =
563 new StepAP203_HArray1OfClassifiedItem (1, 1);
564 items->ChangeValue(1).SetValue ( SDRTool.PDF() );
565 mySecurity->Init ( sc, items );
567 InitSecurityRequisites();
569 if ( myApproval.IsNull() ) {
570 myApproval = new StepAP203_CcDesignApproval;
571 Handle(StepAP203_HArray1OfApprovedItem) items =
572 new StepAP203_HArray1OfApprovedItem (1, 3);
573 items->ChangeValue(1).SetValue ( SDRTool.PDF() );
574 items->ChangeValue(2).SetValue ( SDRTool.PD() );
575 items->ChangeValue(3).SetValue ( mySecurity->AssignedSecurityClassification() );
576 myApproval->Init ( DefaultApproval(), items );
578 InitApprovalRequisites();
580 if ( myProductCategoryRelationship.IsNull() ) {
581 Handle(StepBasic_ProductCategory) PC = new StepBasic_ProductCategory;
582 Handle(TCollection_HAsciiString) PCName = new TCollection_HAsciiString ( "part" );
583 PC->Init ( PCName, Standard_False, 0 );
585 myProductCategoryRelationship = new StepBasic_ProductCategoryRelationship;
586 Handle(TCollection_HAsciiString) PCRName = new TCollection_HAsciiString ( "" );
587 Handle(TCollection_HAsciiString) PCRDescr = new TCollection_HAsciiString ( "" );
588 myProductCategoryRelationship->Init ( PCRName, Standard_True, PCRDescr, PC, SDRTool.PRPC() );
592 //=======================================================================
593 //function : InitAssembly
595 //=======================================================================
597 void STEPConstruct_AP203Context::InitAssembly (const Handle(StepRepr_NextAssemblyUsageOccurrence) &NAUO)
599 if ( mySecurity.IsNull() ) {
601 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString ( "" );
602 Handle(TCollection_HAsciiString) aPurpose = new TCollection_HAsciiString ( "" );
603 Handle(StepBasic_SecurityClassification) sc = new StepBasic_SecurityClassification;
604 sc->Init ( aName, aPurpose, DefaultSecurityClassificationLevel() );
606 mySecurity = new StepAP203_CcDesignSecurityClassification;
607 Handle(StepAP203_HArray1OfClassifiedItem) items =
608 new StepAP203_HArray1OfClassifiedItem (1, 1);
609 items->ChangeValue(1).SetValue ( NAUO );
610 mySecurity->Init ( sc, items );
612 InitSecurityRequisites();
614 if ( myApproval.IsNull() ) {
615 myApproval = new StepAP203_CcDesignApproval;
616 Handle(StepAP203_HArray1OfApprovedItem) items =
617 new StepAP203_HArray1OfApprovedItem (1, 1);
618 items->ChangeValue(1).SetValue ( mySecurity->AssignedSecurityClassification() );
619 myApproval->Init ( DefaultApproval(), items );
621 InitApprovalRequisites();
624 //=======================================================================
625 //function : InitSecurityRequisites
627 //=======================================================================
629 void STEPConstruct_AP203Context::InitSecurityRequisites ()
631 if ( myClassificationOfficer.IsNull() ||
632 myClassificationOfficer->Items()->Value(1).Value() != mySecurity->AssignedSecurityClassification() ) {
633 myClassificationOfficer = new StepAP203_CcDesignPersonAndOrganizationAssignment;
634 Handle(StepAP203_HArray1OfPersonOrganizationItem) items =
635 new StepAP203_HArray1OfPersonOrganizationItem (1, 1);
636 items->ChangeValue(1).SetValue ( mySecurity->AssignedSecurityClassification() );
637 myClassificationOfficer->Init ( DefaultPersonAndOrganization(), RoleClassificationOfficer(), items );
640 if ( myClassificationDate.IsNull() ||
641 myClassificationDate->Items()->Value(1).Value() != mySecurity->AssignedSecurityClassification() ) {
642 myClassificationDate = new StepAP203_CcDesignDateAndTimeAssignment;
643 Handle(StepAP203_HArray1OfDateTimeItem) items =
644 new StepAP203_HArray1OfDateTimeItem (1, 1);
645 items->ChangeValue(1).SetValue ( mySecurity->AssignedSecurityClassification() );
646 myClassificationDate->Init ( DefaultDateAndTime(), RoleClassificationDate(), items );
650 //=======================================================================
651 //function : InitApprovalRequisites
653 //=======================================================================
655 void STEPConstruct_AP203Context::InitApprovalRequisites ()
657 if ( myApprover.IsNull() ||
658 myApprover->AuthorizedApproval() != myApproval->AssignedApproval() ) {
659 myApprover = new StepBasic_ApprovalPersonOrganization;
660 StepBasic_PersonOrganizationSelect po;
661 po.SetValue ( DefaultPersonAndOrganization() );
662 myApprover->Init ( po, myApproval->AssignedApproval(), RoleApprover() );
665 if ( myApprovalDateTime.IsNull() ||
666 myApprovalDateTime->DatedApproval() != myApproval->AssignedApproval() ) {
667 myApprovalDateTime = new StepBasic_ApprovalDateTime;
668 StepBasic_DateTimeSelect dt;
669 dt.SetValue ( DefaultDateAndTime() );
670 myApprovalDateTime->Init ( dt, myApproval->AssignedApproval() );