973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
7fd59977 |
14 | //:k8 abv 06.01.99: TR10: writing unique names for NAUOs |
15 | // :j4 16.03.99 gka S4134 |
16 | // abv 18.11.99 renamed from StepPDR_MakeItem |
17 | #include <STEPConstruct_Assembly.ixx> |
18 | |
19 | #include <TCollection_HAsciiString.hxx> |
20 | |
21 | // ProductDefinition (pour Relationship) |
22 | #include <StepBasic_ProductDefinition.hxx> |
23 | #include <StepBasic_DesignContext.hxx> |
24 | #include <StepBasic_ProductDefinitionFormationWithSpecifiedSource.hxx> |
25 | |
26 | #include <StepBasic_Product.hxx> |
27 | #include <StepBasic_HArray1OfProductContext.hxx> |
28 | #include <StepBasic_MechanicalContext.hxx> |
29 | #include <StepBasic_ApplicationContext.hxx> |
30 | |
31 | // ContextDependentShapeRepresentation qui contient la Relationship |
32 | #include <StepRepr_NextAssemblyUsageOccurrence.hxx> |
33 | #include <StepRepr_ProductDefinitionShape.hxx> |
34 | #include <StepRepr_CharacterizedDefinition.hxx> |
35 | #include <StepShape_ContextDependentShapeRepresentation.hxx> |
36 | |
37 | // Relationship |
38 | #include <StepRepr_ShapeRepresentationRelationshipWithTransformation.hxx> |
39 | #include <StepRepr_HArray1OfRepresentationItem.hxx> |
40 | #include <StepRepr_RepresentationContext.hxx> |
41 | #include <StepShape_ShapeRepresentation.hxx> |
42 | |
43 | #include <StepRepr_ItemDefinedTransformation.hxx> |
44 | #include <StepRepr_Transformation.hxx> |
45 | |
46 | //======================================================================= |
47 | //function : STEPConstruct_Assembly |
48 | //purpose : |
49 | //======================================================================= |
50 | |
51 | STEPConstruct_Assembly::STEPConstruct_Assembly () |
52 | { |
53 | } |
54 | |
55 | //======================================================================= |
56 | //function : Init |
57 | //purpose : |
58 | //======================================================================= |
59 | |
60 | void STEPConstruct_Assembly::Init (const Handle(StepShape_ShapeDefinitionRepresentation)& aSDR, |
61 | const Handle(StepShape_ShapeDefinitionRepresentation)& SDR0, |
62 | const Handle(StepGeom_Axis2Placement3d)& Ax0, |
63 | const Handle(StepGeom_Axis2Placement3d)& AxLoc) |
64 | { |
65 | thesdr = aSDR; |
66 | thesdr0 = SDR0; |
67 | thesr = Handle(StepShape_ShapeRepresentation)::DownCast(aSDR->UsedRepresentation()); |
68 | thesr0 = Handle(StepShape_ShapeRepresentation)::DownCast(SDR0->UsedRepresentation()); |
69 | theval.Nullify(); |
70 | theax0 = Ax0; |
71 | theloc = AxLoc; |
72 | } |
73 | |
74 | //======================================================================= |
75 | //function : MakeMappedItem |
76 | //purpose : |
77 | //======================================================================= |
78 | |
79 | //void STEPConstruct_Assembly::MakeMappedItem () |
80 | //{ |
81 | // not yet implemented |
82 | //} |
83 | |
84 | //======================================================================= |
85 | //function : MakeRelationship |
86 | //purpose : |
87 | //======================================================================= |
88 | |
89 | void STEPConstruct_Assembly::MakeRelationship () |
90 | { |
91 | // get PDs for assembly (sdr0) and component (sdr) |
92 | Handle(StepBasic_ProductDefinition) PDED = |
93 | thesdr->Definition().PropertyDefinition()->Definition().ProductDefinition(); |
94 | Handle(StepBasic_ProductDefinition) PDING = |
95 | thesdr0->Definition().PropertyDefinition()->Definition().ProductDefinition(); |
96 | |
97 | // create NAUO |
98 | //:k8 abv 06 Jan 99: TR10: writing unique names for NAUOs !!!!! |
99 | Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO = |
100 | new StepRepr_NextAssemblyUsageOccurrence; |
101 | static Standard_Integer id = 0; |
102 | Handle(TCollection_HAsciiString) ocid = new TCollection_HAsciiString(++id); |
103 | Handle(TCollection_HAsciiString) ocname = new TCollection_HAsciiString(""); |
104 | Handle(TCollection_HAsciiString) ocdesc = new TCollection_HAsciiString(""); |
105 | Handle(TCollection_HAsciiString) refdes; // reste nulle |
106 | NAUO->Init (ocid,ocname,Standard_True,ocdesc,PDING,PDED,Standard_False,refdes); |
107 | |
108 | // create PDS for link CDSR->PDS->NAUO |
109 | Handle(StepRepr_ProductDefinitionShape) PDS = |
110 | new StepRepr_ProductDefinitionShape; |
111 | Handle(TCollection_HAsciiString) pdsname = new TCollection_HAsciiString("Placement"); |
112 | Handle(TCollection_HAsciiString) pdsdesc = new TCollection_HAsciiString("Placement of an item"); |
113 | StepRepr_CharacterizedDefinition CD; |
114 | CD.SetValue(NAUO); |
115 | PDS->Init (pdsname,Standard_True,pdsdesc,CD); |
116 | |
117 | // create transformation |
118 | Handle(StepRepr_ItemDefinedTransformation) ItemDef = |
119 | new StepRepr_ItemDefinedTransformation; |
120 | Handle(TCollection_HAsciiString) idname = new TCollection_HAsciiString(""); |
121 | Handle(TCollection_HAsciiString) idescr = new TCollection_HAsciiString(""); |
122 | ItemDef->Init (idname,idescr,theax0,theloc); |
123 | |
124 | // create SRRWT |
125 | Handle(StepRepr_ShapeRepresentationRelationshipWithTransformation) SRRWT = |
126 | new StepRepr_ShapeRepresentationRelationshipWithTransformation; |
127 | Handle(TCollection_HAsciiString) stname = new TCollection_HAsciiString(""); |
128 | Handle(TCollection_HAsciiString) stescr = new TCollection_HAsciiString(""); |
129 | StepRepr_Transformation StepTrans; |
130 | StepTrans.SetValue (ItemDef); |
131 | SRRWT->Init (stname,stescr,thesr,thesr0,StepTrans); |
132 | |
133 | // create CDSR (final result, root) |
134 | Handle(StepShape_ContextDependentShapeRepresentation) CDSR = |
135 | new StepShape_ContextDependentShapeRepresentation; |
136 | CDSR->Init (SRRWT,PDS); |
137 | |
138 | theval = CDSR; |
139 | } |
140 | |
141 | //======================================================================= |
142 | //function : ItemValue |
143 | //purpose : |
144 | //======================================================================= |
145 | |
146 | Handle(Standard_Transient) STEPConstruct_Assembly::ItemValue () const |
147 | { |
148 | if (theval.IsNull()) return thesr; |
149 | return theval; |
150 | } |
151 | |
152 | //======================================================================= |
153 | //function : ItemLocation |
154 | //purpose : |
155 | //======================================================================= |
156 | |
157 | Handle(StepGeom_Axis2Placement3d) STEPConstruct_Assembly::ItemLocation () const |
158 | { |
159 | return theloc; |
160 | } |
161 | |
162 | //======================================================================= |
163 | //function : GetNAUO |
164 | //purpose : |
165 | //======================================================================= |
166 | |
167 | Handle(StepRepr_NextAssemblyUsageOccurrence) STEPConstruct_Assembly::GetNAUO () const |
168 | { |
169 | Handle(StepShape_ContextDependentShapeRepresentation) CDSR = |
170 | Handle(StepShape_ContextDependentShapeRepresentation)::DownCast ( ItemValue() ); |
171 | if ( ! CDSR.IsNull() ) { |
172 | Handle(StepBasic_ProductDefinitionRelationship) PDR = |
173 | CDSR->RepresentedProductRelation()->Definition().ProductDefinitionRelationship(); |
174 | return Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast ( PDR ); |
175 | } |
176 | return 0; |
177 | } |
178 | |
179 | //======================================================================= |
180 | //function : CheckSRRReversesNAUO |
181 | //purpose : |
182 | //======================================================================= |
183 | |
184 | Standard_Boolean STEPConstruct_Assembly::CheckSRRReversesNAUO(const Handle(Interface_InterfaceModel) &Model, |
185 | const Handle(StepShape_ContextDependentShapeRepresentation) &CDSR) |
186 | { |
187 | Handle(StepRepr_NextAssemblyUsageOccurrence) nauo = |
188 | Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast |
189 | ( CDSR->RepresentedProductRelation()->Definition().ProductDefinitionRelationship() ); |
190 | if ( nauo.IsNull() ) { |
0797d9d3 |
191 | #ifdef OCCT_DEBUG |
7fd59977 |
192 | cout << "Warning: No NAUO found in CDSR !" << endl; |
193 | #endif |
194 | return Standard_False; |
195 | } |
196 | |
197 | Handle(StepBasic_ProductDefinition) pd1, pd2; |
198 | Handle(StepRepr_Representation) rep1 = CDSR->RepresentationRelation()->Rep1(); |
199 | Handle(StepRepr_Representation) rep2 = CDSR->RepresentationRelation()->Rep2(); |
200 | |
201 | // find SDRs corresponding to Rep1 and Rep2 and remember their PDs |
202 | Handle(Standard_Type) tSDR = STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation); |
203 | Standard_Integer nb = Model->NbEntities(); |
204 | for (Standard_Integer i = 1; i <= nb; i ++) { |
205 | Handle(Standard_Transient) enti = Model->Value(i); |
206 | if (enti->DynamicType() == tSDR) { |
207 | Handle(StepShape_ShapeDefinitionRepresentation) SDR = |
208 | Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(enti); |
209 | if ( SDR->UsedRepresentation() == rep1 ) |
210 | pd1 = SDR->Definition().PropertyDefinition()->Definition().ProductDefinition(); |
211 | if ( SDR->UsedRepresentation() == rep2 ) |
212 | pd2 = SDR->Definition().PropertyDefinition()->Definition().ProductDefinition(); |
213 | } |
214 | } |
215 | |
216 | // checks.. |
217 | |
218 | if ( pd1 == nauo->RelatedProductDefinition() && // OK |
219 | pd2 == nauo->RelatingProductDefinition() ) return Standard_False; |
220 | |
221 | if ( pd2 == nauo->RelatedProductDefinition() && // Reversed |
222 | pd1 == nauo->RelatingProductDefinition() ) { |
223 | return Standard_True; |
224 | } |
225 | |
0797d9d3 |
226 | #ifdef OCCT_DEBUG |
7fd59977 |
227 | cout << "Warning: SRR and NAUO are incompatible" << endl; |
228 | // cout << "NAUO = " << Model->StringLabel(nauo)->ToCString() << |
229 | // ",\tCDSR = " << Model->StringLabel(CDSR)->ToCString() << endl; |
230 | // cout << "Rep1 = " << Model->StringLabel(rep1)->ToCString() << |
231 | // ",\tRep2 = " << Model->StringLabel(rep2)->ToCString() << endl; |
232 | // cout << "PD1 = " << Model->StringLabel(pd1)->ToCString() << |
233 | // ",\tPD2 = " << Model->StringLabel(pd2)->ToCString() << endl; |
234 | // cout << "Rel1 = " << Model->StringLabel(nauo->RelatingProductDefinition())->ToCString() << |
235 | // ",\tRel2 = " << Model->StringLabel(nauo->RelatedProductDefinition())->ToCString() << endl; |
236 | #endif |
237 | |
238 | if ( pd2 == nauo->RelatedProductDefinition() || //:k3 abv 25 Nov 98: rp1sd.stp - bad assemblies |
239 | pd1 == nauo->RelatingProductDefinition() ) { |
240 | return Standard_True; |
241 | } |
242 | |
243 | return Standard_False; |
244 | } |