b311480e |
1 | // Created on: 1999-09-09 |
2 | // Created by: Andrey BETENEV |
3 | // Copyright (c) 1999-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. |
7fd59977 |
16 | |
7fd59977 |
17 | |
42cf5bc1 |
18 | #include <APIHeaderSection_MakeHeader.hxx> |
19 | #include <gp_Pnt.hxx> |
20 | #include <Interface_EntityIterator.hxx> |
7fd59977 |
21 | #include <Interface_Macros.hxx> |
22 | #include <Interface_Static.hxx> |
42cf5bc1 |
23 | #include <Message.hxx> |
24 | #include <Message_Messenger.hxx> |
25 | #include <StepBasic_DerivedUnit.hxx> |
26 | #include <StepBasic_DerivedUnitElement.hxx> |
27 | #include <StepBasic_HArray1OfDerivedUnitElement.hxx> |
28 | #include <StepBasic_MeasureValueMember.hxx> |
29 | #include <StepBasic_MeasureWithUnit.hxx> |
30 | #include <StepBasic_ProductDefinition.hxx> |
31 | #include <StepBasic_SiUnitAndAreaUnit.hxx> |
32 | #include <StepBasic_SiUnitAndLengthUnit.hxx> |
33 | #include <StepBasic_Unit.hxx> |
34 | #include <STEPConstruct.hxx> |
35 | #include <STEPConstruct_UnitContext.hxx> |
36 | #include <STEPConstruct_ValidationProps.hxx> |
37 | #include <StepData_StepModel.hxx> |
7fd59977 |
38 | #include <StepGeom_CartesianPoint.hxx> |
42cf5bc1 |
39 | #include <StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext.hxx> |
7fd59977 |
40 | #include <StepGeom_GeometricRepresentationItem.hxx> |
41 | #include <StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx.hxx> |
7fd59977 |
42 | #include <StepRepr_CharacterizedDefinition.hxx> |
42cf5bc1 |
43 | #include <StepRepr_GlobalUnitAssignedContext.hxx> |
7fd59977 |
44 | #include <StepRepr_HArray1OfRepresentationItem.hxx> |
45 | #include <StepRepr_MeasureRepresentationItem.hxx> |
ec357c5c |
46 | #include <StepRepr_NextAssemblyUsageOccurrence.hxx> |
ec357c5c |
47 | #include <StepRepr_ProductDefinitionShape.hxx> |
42cf5bc1 |
48 | #include <StepRepr_PropertyDefinition.hxx> |
49 | #include <StepRepr_PropertyDefinitionRepresentation.hxx> |
50 | #include <StepRepr_RepresentationContext.hxx> |
51 | #include <StepRepr_RepresentationItem.hxx> |
ec357c5c |
52 | #include <StepRepr_RepresentationRelationship.hxx> |
42cf5bc1 |
53 | #include <StepRepr_ShapeAspect.hxx> |
54 | #include <StepRepr_ShapeRepresentationRelationship.hxx> |
55 | #include <StepShape_ContextDependentShapeRepresentation.hxx> |
56 | #include <StepShape_ShapeDefinitionRepresentation.hxx> |
57 | #include <StepShape_ShapeRepresentation.hxx> |
58 | #include <TCollection_HAsciiString.hxx> |
59 | #include <TopLoc_Location.hxx> |
42cf5bc1 |
60 | #include <TopoDS_Shape.hxx> |
61 | #include <Transfer_Binder.hxx> |
62 | #include <Transfer_SimpleBinderOfTransient.hxx> |
63 | #include <TransferBRep.hxx> |
64 | #include <TransferBRep_ShapeMapper.hxx> |
65 | #include <XSControl_TransferReader.hxx> |
66 | #include <XSControl_TransferWriter.hxx> |
67 | #include <XSControl_WorkSession.hxx> |
7fd59977 |
68 | |
69 | //======================================================================= |
70 | //function : STEPConstruct_ValidationProps |
71 | //purpose : |
72 | //======================================================================= |
7fd59977 |
73 | STEPConstruct_ValidationProps::STEPConstruct_ValidationProps () |
74 | { |
75 | } |
76 | |
77 | //======================================================================= |
78 | //function : STEPConstruct_ValidationProps |
79 | //purpose : |
80 | //======================================================================= |
81 | |
82 | STEPConstruct_ValidationProps::STEPConstruct_ValidationProps (const Handle(XSControl_WorkSession) &WS) |
83 | : STEPConstruct_Tool(WS) |
84 | { |
85 | } |
86 | |
87 | //======================================================================= |
88 | //function : Init |
89 | //purpose : |
90 | //======================================================================= |
91 | |
92 | Standard_Boolean STEPConstruct_ValidationProps::Init (const Handle(XSControl_WorkSession) &WS) |
93 | { |
94 | return SetWS ( WS ); |
95 | } |
96 | |
97 | //======================================================================= |
98 | //function : TransientResult CORRECTED |
99 | //purpose : |
100 | //======================================================================= |
101 | |
102 | static Handle(Transfer_SimpleBinderOfTransient) TransientResult (const Handle(Standard_Transient)& res) |
103 | { |
104 | Handle(Transfer_SimpleBinderOfTransient) binder; |
105 | if (res.IsNull()) return binder; |
106 | binder = new Transfer_SimpleBinderOfTransient; |
107 | binder->SetResult (res); |
108 | return binder; |
109 | } |
110 | |
111 | //======================================================================= |
112 | //function : FindTarget |
113 | //purpose : |
114 | //======================================================================= |
115 | |
116 | Standard_Boolean STEPConstruct_ValidationProps::FindTarget (const TopoDS_Shape &Shape, |
117 | StepRepr_CharacterizedDefinition &target, |
118 | Handle(StepRepr_RepresentationContext) &Context, |
119 | const Standard_Boolean instance) |
120 | { |
121 | // find the target STEP entity corresponding to a shape |
122 | Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FinderProcess(), Shape ); |
123 | Handle(Transfer_Binder) binder = FinderProcess()->Find ( mapper ); |
124 | |
7fd59977 |
125 | // if requested, try to find instance of assembly |
126 | if ( instance ) { |
127 | /* |
128 | Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO; |
129 | Standard_Boolean found = myAssemblyPD.IsNull()? |
130 | FinderProcess()->FindTypedTransient (mapper,STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence), NAUO) : |
131 | STEPConstruct::FindNAUO (binder,myAssemblyPD,NAUO); |
132 | if ( found ) { |
133 | //skl find CDSR using NAUO: |
134 | Handle(StepShape_ContextDependentShapeRepresentation) CDSR |
135 | Interface_EntityIterator subs1 = graph.Sharings(NAUO); |
136 | for (subs1.Start(); subs1.More(); subs1.Next()) { |
137 | Handle(StepRepr_ProductDefinitionShape) PDS = |
138 | Handle(StepRepr_ProductDefinitionShape)::DownCast(subs1.Value()); |
139 | if(PDS.IsNull()) continue; |
140 | //IsPDS=Standard_True; |
141 | Interface_EntityIterator subs2 = graph.Sharings(PDS); |
142 | for (subs2.Start(); CDSR.IsNull() && subs2.More(); subs2.Next()) { |
143 | CDSR = Handle(StepShape_ContextDependentShapeRepresentation)::DownCast(subs2.Value()); |
144 | } |
145 | } |
146 | if(!CDSR.IsNull()) { |
147 | target.SetValue ( CDSR->RepresentedProductRelation() ); |
148 | Context = CDSR->RepresentationRelation()->Rep2()->ContextOfItems(); |
149 | } |
0797d9d3 |
150 | #ifdef OCCT_DEBUG |
7fd59977 |
151 | else cout << "INSTANCE: CDRS from NAUO NOT found" << endl; |
152 | #endif |
153 | } |
0797d9d3 |
154 | #ifdef OCCT_DEBUG |
7fd59977 |
155 | else cout << "INSTANCE: NAUO NOT found" << endl; |
156 | #endif |
157 | */ |
158 | } |
159 | |
160 | // for Compounds, search for SDR |
161 | else if ( Shape.ShapeType() == TopAbs_COMPOUND ) { |
162 | Handle(StepBasic_ProductDefinition) ProdDef; |
163 | if ( FinderProcess()->FindTypedTransient (mapper,STANDARD_TYPE(StepBasic_ProductDefinition), ProdDef) ) { |
164 | Handle(StepRepr_ProductDefinitionShape) PDS; |
165 | Interface_EntityIterator subs1 = Graph().Sharings(ProdDef); |
166 | for (subs1.Start(); PDS.IsNull() && subs1.More(); subs1.Next()) { |
167 | PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(subs1.Value()); |
168 | } |
169 | target.SetValue ( PDS ); |
0797d9d3 |
170 | #ifdef OCCT_DEBUG |
7fd59977 |
171 | // cout << "COMPOUND: SDR found: " << sdr->DynamicType()->Name() << endl; |
172 | #endif |
173 | } |
174 | else { |
0797d9d3 |
175 | #ifdef OCCT_DEBUG |
7fd59977 |
176 | cout << "COMPOUND: ProdDef NOT found" << endl; |
177 | #endif |
178 | Handle(StepShape_ShapeRepresentation) SR; |
179 | if(FinderProcess()->FindTypedTransient(mapper,STANDARD_TYPE(StepShape_ShapeRepresentation),SR)) { |
180 | Handle(StepRepr_ProductDefinitionShape) PDS; |
181 | Interface_EntityIterator subs1 = Graph().Sharings(SR); |
182 | for (subs1.Start(); PDS.IsNull() && subs1.More(); subs1.Next()) { |
183 | Handle(StepShape_ShapeDefinitionRepresentation) SDR = |
184 | Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs1.Value()); |
185 | if(SDR.IsNull()) continue; |
186 | PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(SDR->Definition().PropertyDefinition()); |
187 | } |
188 | if(PDS.IsNull()) { |
189 | subs1 = Graph().Sharings(SR); |
190 | for (subs1.Start(); PDS.IsNull() && subs1.More(); subs1.Next()) { |
191 | Handle(StepRepr_RepresentationRelationship) RR = |
192 | Handle(StepRepr_RepresentationRelationship)::DownCast(subs1.Value()); |
193 | if(RR.IsNull()) continue; |
194 | Handle(StepShape_ShapeRepresentation) SR1; |
195 | if(RR->Rep1()==SR) |
196 | SR1 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep2()); |
197 | else SR1 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep1()); |
198 | if(!SR1.IsNull()) { |
199 | Interface_EntityIterator subs2 = Graph().Sharings(SR1); |
200 | for (subs2.Start(); PDS.IsNull() && subs2.More(); subs2.Next()) { |
201 | Handle(StepShape_ShapeDefinitionRepresentation) SDR = |
202 | Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs2.Value()); |
203 | if(SDR.IsNull()) continue; |
204 | PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(SDR->Definition().PropertyDefinition()); |
205 | } |
206 | } |
207 | } |
208 | } |
209 | if(!PDS.IsNull()) { |
210 | target.SetValue(PDS); |
211 | Context = SR->ContextOfItems(); |
212 | } |
213 | } |
214 | } |
215 | } |
216 | |
217 | // for others, search for GEOMETRIC_REPRESENTATION_ITEM |
218 | else { |
219 | Handle(StepGeom_GeometricRepresentationItem) item; |
220 | if ( FinderProcess()->FindTypedTransient (mapper,STANDARD_TYPE(StepGeom_GeometricRepresentationItem), item) ) { |
0797d9d3 |
221 | #ifdef OCCT_DEBUG |
7fd59977 |
222 | // cout << Shape.TShape()->DynamicType()->Name() << ": GeomRepItem found: " << item->DynamicType()->Name() << endl; |
223 | #endif |
224 | // find PDS (GRI <- SR <- SDR -> PDS) |
225 | Handle(StepRepr_ProductDefinitionShape) PDS; |
226 | Interface_EntityIterator subs = Graph().Sharings(item); |
227 | for (subs.Start(); PDS.IsNull() && subs.More(); subs.Next()) { |
0797d9d3 |
228 | #ifdef OCCT_DEBUG |
7fd59977 |
229 | // cout << "Parsing back refs: found " << subs.Value()->DynamicType()->Name() << endl; |
230 | #endif |
231 | if ( ! subs.Value()->IsKind(STANDARD_TYPE(StepShape_ShapeRepresentation)) ) continue; |
232 | Handle(StepShape_ShapeRepresentation) sr = |
233 | Handle(StepShape_ShapeRepresentation)::DownCast ( subs.Value() ); |
234 | Context = sr->ContextOfItems(); |
235 | Interface_EntityIterator sub2 = Graph().Sharings(subs.Value()); |
236 | for (sub2.Start(); sub2.More(); sub2.Next()) { |
237 | if ( ! sub2.Value()->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation)) ) continue; |
238 | Handle(StepShape_ShapeDefinitionRepresentation) sdr = |
239 | Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(sub2.Value()); |
240 | PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast ( sdr->Definition().PropertyDefinition() ); |
241 | } |
242 | } |
243 | if ( ! PDS.IsNull() ) { |
244 | // find SHAPE_ASPECT or create it with all associated info if not yet exists |
245 | Handle(StepRepr_ShapeAspect) aspect; |
246 | Handle(Transfer_Binder) bbb = binder; |
247 | while ( ! bbb.IsNull() ) { |
248 | Handle(Transfer_SimpleBinderOfTransient) bx = |
249 | Handle(Transfer_SimpleBinderOfTransient)::DownCast ( bbb ); |
250 | if ( ! bx.IsNull() ) { |
251 | Handle(StepRepr_ShapeAspect) asp = |
252 | Handle(StepRepr_ShapeAspect)::DownCast ( bx->Result() ); |
253 | if ( ! asp.IsNull() && asp->OfShape() == PDS ) { |
254 | aspect = asp; |
255 | break; |
256 | } |
257 | } |
258 | bbb = bbb->NextResult(); |
259 | } |
260 | if ( aspect.IsNull() ) { |
261 | // if ( ! FinderProcess()->FindTypedTransient (mapper,STANDARD_TYPE(StepRepr_ShapeAspect), aspect ) || |
262 | // aspect->OfShape() != PDS ) |
0797d9d3 |
263 | #ifdef OCCT_DEBUG |
7fd59977 |
264 | cout << Shape.TShape()->DynamicType()->Name() << ": SHAPE_ASPECT NOT found, creating" << endl; |
265 | #endif |
266 | // create aspect and all related data |
267 | Handle(TCollection_HAsciiString) AspectName = new TCollection_HAsciiString ( "" ); |
268 | Handle(TCollection_HAsciiString) AspectDescr = new TCollection_HAsciiString ( "" ); |
269 | aspect = new StepRepr_ShapeAspect; |
270 | aspect->Init ( AspectName, AspectDescr, PDS, StepData_LFalse ); |
271 | |
272 | StepRepr_CharacterizedDefinition SA; |
273 | SA.SetValue ( aspect ); |
274 | |
275 | Handle(TCollection_HAsciiString) PropDefName = |
276 | new TCollection_HAsciiString ( "shape with specific properties" ); |
277 | Handle(TCollection_HAsciiString) PropDefDescr = new TCollection_HAsciiString ( "properties for subshape" ); |
278 | Handle(StepRepr_PropertyDefinition) propdef = new StepRepr_PropertyDefinition; |
279 | propdef->Init ( PropDefName, Standard_True, PropDefDescr, SA ); |
280 | |
281 | Handle(TCollection_HAsciiString) SRName = new TCollection_HAsciiString ( "" ); |
282 | Handle(StepShape_ShapeRepresentation) SR = new StepShape_ShapeRepresentation; |
283 | Handle(StepRepr_HArray1OfRepresentationItem) SRItems = new StepRepr_HArray1OfRepresentationItem ( 1, 1 ); |
284 | SRItems->SetValue ( 1, item ); |
285 | SR->Init ( SRName, SRItems, Context ); |
286 | |
287 | Handle(StepShape_ShapeDefinitionRepresentation) SDR = new StepShape_ShapeDefinitionRepresentation; |
288 | StepRepr_RepresentedDefinition RD; |
289 | RD.SetValue ( propdef ); |
290 | SDR->Init ( RD, SR ); |
291 | |
292 | // record SHAPE_ASPECT in the map |
293 | binder->AddResult ( TransientResult ( aspect ) ); |
294 | |
295 | // add SDR and all the data into model |
296 | Model()->AddWithRefs ( SDR ); |
297 | } |
298 | // SHAPE_ASPECT found, but we also need context: FIND IT !!!! |
299 | else { |
0797d9d3 |
300 | #ifdef OCCT_DEBUG |
7fd59977 |
301 | cout << Shape.TShape()->DynamicType()->Name() << ": SHAPE_ASPECT found" << endl; |
302 | #endif |
303 | Handle(StepRepr_ProductDefinitionShape) aPDS = aspect->OfShape(); |
304 | Interface_EntityIterator asubs = Graph().Sharings(aPDS); |
305 | for (asubs.Start(); Context.IsNull() && asubs.More(); asubs.Next()) { |
306 | if ( ! asubs.Value()->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation)) ) continue; |
307 | Handle(StepShape_ShapeDefinitionRepresentation) sdr = |
308 | Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(asubs.Value()); |
309 | Context = sdr->UsedRepresentation()->ContextOfItems(); |
310 | } |
311 | } |
312 | |
313 | if ( ! aspect.IsNull() ) target.SetValue ( aspect ); |
314 | } |
0797d9d3 |
315 | #ifdef OCCT_DEBUG |
7fd59977 |
316 | else cout << Shape.TShape()->DynamicType()->Name() << ": PDS NOT found, fail to create SHAPE_ASPECT" << endl; |
317 | #endif |
318 | } |
0797d9d3 |
319 | #ifdef OCCT_DEBUG |
7fd59977 |
320 | else cout << Shape.TShape()->DynamicType()->Name() << ": GeomRepItem NOT found" << endl; |
321 | #endif |
322 | } |
323 | |
324 | |
325 | // if target not found and shape has location, try the same shape without location |
326 | return ! target.IsNull(); |
327 | } |
328 | |
329 | //======================================================================= |
330 | //function : AddProp CORRECTED |
331 | //purpose : |
332 | //======================================================================= |
333 | |
334 | Standard_Boolean STEPConstruct_ValidationProps::AddProp (const StepRepr_CharacterizedDefinition &target, |
335 | const Handle(StepRepr_RepresentationContext) &Context, |
336 | const Handle(StepRepr_RepresentationItem) &Prop, |
337 | const Standard_CString Descr) |
338 | { |
339 | // FINALLY, create a structure of 5 entities describing a link between a shape and its property |
340 | Handle(TCollection_HAsciiString) PropDefName = |
341 | new TCollection_HAsciiString ( "geometric_validation_property" ); |
342 | Handle(TCollection_HAsciiString) PropDefDescr = new TCollection_HAsciiString ( Descr ); |
343 | Handle(StepRepr_PropertyDefinition) propdef = new StepRepr_PropertyDefinition; |
344 | propdef->Init ( PropDefName, Standard_True, PropDefDescr, target ); |
345 | |
346 | Handle(TCollection_HAsciiString) SRName = new TCollection_HAsciiString ( Descr ); |
347 | Handle(StepRepr_Representation) rep = new StepRepr_Representation; |
348 | Handle(StepRepr_HArray1OfRepresentationItem) SRItems = new StepRepr_HArray1OfRepresentationItem ( 1, 1 ); |
349 | SRItems->SetValue ( 1, Prop ); |
350 | rep->Init ( SRName, SRItems, Context ); |
351 | |
352 | Handle(StepRepr_PropertyDefinitionRepresentation) PrDR = new StepRepr_PropertyDefinitionRepresentation; |
353 | StepRepr_RepresentedDefinition RD; |
354 | RD.SetValue ( propdef ); |
355 | PrDR->Init ( RD, rep ); |
356 | |
357 | // record SDR in order to have it written to the file |
358 | Model()->AddWithRefs ( PrDR ); |
359 | |
360 | // for AP203, add subschema name |
361 | if ( Interface_Static::IVal("write.step.schema") ==3 ) { |
362 | APIHeaderSection_MakeHeader mkHdr ( Handle(StepData_StepModel)::DownCast ( Model() ) ); |
363 | Handle(TCollection_HAsciiString) subSchema = |
364 | new TCollection_HAsciiString ( "GEOMETRIC_VALIDATION_PROPERTIES_MIM" ); |
365 | mkHdr.AddSchemaIdentifier ( subSchema ); |
366 | } |
367 | |
368 | return Standard_True; |
369 | } |
370 | |
371 | //======================================================================= |
372 | //function : AddProp CORRECTED |
373 | //purpose : |
374 | //======================================================================= |
375 | |
376 | Standard_Boolean STEPConstruct_ValidationProps::AddProp (const TopoDS_Shape &Shape, |
377 | const Handle(StepRepr_RepresentationItem) &Prop, |
378 | const Standard_CString Descr, |
379 | const Standard_Boolean instance) |
380 | { |
381 | StepRepr_CharacterizedDefinition target; |
382 | Handle(StepRepr_RepresentationContext) Context; |
383 | if ( ! FindTarget ( Shape, target, Context, instance ) ) return Standard_False; |
384 | return AddProp ( target, Context, Prop, Descr ); |
385 | } |
386 | |
387 | //======================================================================= |
388 | //function : AddVolume CORRECTED |
389 | //purpose : |
390 | //======================================================================= |
391 | |
392 | Standard_Boolean STEPConstruct_ValidationProps::AddVolume (const TopoDS_Shape &Shape, |
393 | const Standard_Real Vol) |
394 | { |
395 | Handle(StepBasic_MeasureValueMember) Val = new StepBasic_MeasureValueMember; |
396 | Val->SetReal ( Vol ); |
397 | //Val->SetName ( "solid volume" ); |
398 | Val->SetName ( "VOLUME_MEASURE"); |
399 | |
400 | // for volume unit, either take existing or create a new |
401 | if ( volUnit.DerivedUnit().IsNull() ) { |
402 | Handle(StepBasic_SiUnitAndLengthUnit) MM = new StepBasic_SiUnitAndLengthUnit; |
403 | MM->Init ( Standard_True, StepBasic_spMilli, StepBasic_sunMetre ); |
404 | |
405 | Handle(StepBasic_DerivedUnitElement) DUE = new StepBasic_DerivedUnitElement; |
406 | DUE->Init ( MM, 3. ); |
407 | |
408 | Handle(StepBasic_HArray1OfDerivedUnitElement) DUElems = |
409 | new StepBasic_HArray1OfDerivedUnitElement ( 1, 1 ); |
410 | DUElems->SetValue ( 1, DUE ); |
411 | |
412 | Handle(StepBasic_DerivedUnit) DU = new StepBasic_DerivedUnit; |
413 | DU->Init ( DUElems ); |
414 | |
415 | volUnit.SetValue ( DU ); |
416 | } |
417 | |
418 | Handle(TCollection_HAsciiString) MRIName = new TCollection_HAsciiString ( "volume measure" ); |
419 | Handle(StepRepr_MeasureRepresentationItem) MRI = new StepRepr_MeasureRepresentationItem; |
420 | MRI->Init ( MRIName, Val, volUnit ); |
421 | |
422 | return AddProp ( Shape, MRI, "volume" ); |
423 | } |
424 | |
425 | //======================================================================= |
426 | //function : AddArea CORRECTED |
427 | //purpose : |
428 | //======================================================================= |
429 | |
430 | Standard_Boolean STEPConstruct_ValidationProps::AddArea (const TopoDS_Shape &Shape, |
431 | const Standard_Real Area) |
432 | { |
433 | Handle(StepBasic_MeasureValueMember) Val = new StepBasic_MeasureValueMember; |
434 | Val->SetReal ( Area ); |
435 | //Val->SetName ( "surface area" ); |
436 | Val->SetName ( "AREA_MEASURE" ); |
437 | |
438 | // for area unit, either take existing or create a new |
439 | if ( areaUnit.DerivedUnit().IsNull() ) { |
440 | Handle(StepBasic_SiUnitAndLengthUnit) MM = new StepBasic_SiUnitAndLengthUnit; |
441 | MM->Init ( Standard_True, StepBasic_spMilli, StepBasic_sunMetre ); |
442 | |
443 | Handle(StepBasic_DerivedUnitElement) DUE = new StepBasic_DerivedUnitElement; |
444 | DUE->Init ( MM, 2. ); |
445 | |
446 | Handle(StepBasic_HArray1OfDerivedUnitElement) DUElems = |
447 | new StepBasic_HArray1OfDerivedUnitElement ( 1, 1 ); |
448 | DUElems->SetValue ( 1, DUE ); |
449 | |
450 | Handle(StepBasic_DerivedUnit) DU = new StepBasic_DerivedUnit; |
451 | DU->Init ( DUElems ); |
452 | |
453 | areaUnit.SetValue ( DU ); |
454 | } |
455 | |
456 | Handle(TCollection_HAsciiString) MRIName = new TCollection_HAsciiString ( "surface area measure" ); |
457 | Handle(StepRepr_MeasureRepresentationItem) MRI = new StepRepr_MeasureRepresentationItem; |
458 | MRI->Init ( MRIName, Val, areaUnit ); |
459 | |
460 | return AddProp ( Shape, MRI, "surface area" ); |
461 | } |
462 | |
463 | //======================================================================= |
464 | //function : AddCentroid CORRECTED |
465 | //purpose : |
466 | //======================================================================= |
467 | |
468 | Standard_Boolean STEPConstruct_ValidationProps::AddCentroid (const TopoDS_Shape &Shape, |
469 | const gp_Pnt &Pnt, |
470 | const Standard_Boolean instance) |
471 | { |
472 | Handle(TCollection_HAsciiString) CPName = new TCollection_HAsciiString ( "centre point" ); |
473 | Handle(StepGeom_CartesianPoint) CP = new StepGeom_CartesianPoint; |
474 | CP->Init3D ( CPName, Pnt.X(), Pnt.Y(), Pnt.Z() ); |
475 | |
476 | return AddProp ( Shape, CP, "centroid", instance ); |
477 | } |
478 | |
479 | //======================================================================= |
480 | //function : LoadProps CORRECTED |
481 | //purpose : |
482 | //======================================================================= |
483 | |
484 | Standard_Boolean STEPConstruct_ValidationProps::LoadProps (TColStd_SequenceOfTransient &seq) const |
485 | { |
486 | // parse on PropertyDefinitionRepresentations |
487 | Standard_Integer nb = Model()->NbEntities(); |
488 | Handle(Standard_Type) tPDR = STANDARD_TYPE(StepRepr_PropertyDefinitionRepresentation); |
489 | for (Standard_Integer i = 1; i <= nb; i ++) { |
490 | Handle(Standard_Transient) enti = Model()->Value(i); |
491 | if ( ! enti->IsKind (tPDR) ) continue; |
492 | |
493 | Handle(StepRepr_PropertyDefinitionRepresentation) PDR = |
494 | Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast ( enti ); |
495 | |
496 | // check that PDR is for validation props |
497 | Handle(StepRepr_PropertyDefinition) PD = PDR->Definition().PropertyDefinition(); |
498 | if ( PD.IsNull() || PD->Name().IsNull() |
499 | || PD->Name()->String() != "geometric_validation_property" ) |
500 | continue; |
501 | |
502 | seq.Append ( PDR ); |
503 | } |
504 | return seq.Length() >0; |
505 | } |
506 | |
507 | //======================================================================= |
508 | //function : GetPropPD CORRECTED |
509 | //purpose : |
510 | //======================================================================= |
511 | |
512 | Handle(StepBasic_ProductDefinition) STEPConstruct_ValidationProps::GetPropPD (const Handle(StepRepr_PropertyDefinition) &PD) const |
513 | { |
514 | StepRepr_CharacterizedDefinition CD = PD->Definition(); |
515 | |
516 | // detect target entity of valprop |
517 | Handle(StepBasic_ProductDefinition) ProdDef; |
518 | Handle(StepRepr_PropertyDefinition) PDS = CD.ProductDefinitionShape(); |
519 | if ( PDS.IsNull() ) { |
520 | Handle(StepRepr_ShapeAspect) SA = CD.ShapeAspect(); |
521 | if ( SA.IsNull() ) { |
0797d9d3 |
522 | #ifdef OCCT_DEBUG |
7fd59977 |
523 | Handle(Message_Messenger) sout = Message::DefaultMessenger(); |
524 | sout << "Error: Cannot find target entity (SA) for geometric_validation_property "; |
525 | Model()->PrintLabel ( PD, sout ); |
526 | sout << endl; |
527 | #endif |
528 | return ProdDef; |
529 | } |
530 | Interface_EntityIterator subs = Graph().Sharings(SA); |
531 | for (subs.Start(); subs.More(); subs.Next()) { |
532 | PDS = Handle(StepRepr_PropertyDefinition)::DownCast ( subs.Value() ); |
533 | if ( PDS.IsNull() ) return ProdDef; |
534 | Interface_EntityIterator subs1 = Graph().Shareds(PDS); |
535 | for (subs1.Start(); ProdDef.IsNull() && subs1.More(); subs1.Next()) { |
536 | ProdDef = Handle(StepBasic_ProductDefinition)::DownCast ( subs1.Value() ); |
537 | } |
538 | } |
539 | } |
540 | else { |
541 | Interface_EntityIterator subs = Graph().Shareds(PDS); |
542 | for (subs.Start(); ProdDef.IsNull() && subs.More(); subs.Next()) { |
543 | ProdDef = Handle(StepBasic_ProductDefinition)::DownCast ( subs.Value() ); |
544 | } |
545 | } |
0797d9d3 |
546 | #ifdef OCCT_DEBUG |
7fd59977 |
547 | if ( ProdDef.IsNull() ) { |
548 | Handle(Message_Messenger) sout = Message::DefaultMessenger(); |
549 | sout << "Error: Cannot find target entity (SDR) for geometric_validation_property "; |
550 | Model()->PrintLabel ( PD, sout ); |
551 | sout << endl; |
552 | } |
553 | #endif |
554 | return ProdDef; |
555 | } |
556 | |
557 | //======================================================================= |
558 | //function : GetPropCDSR CORRECTED |
559 | //purpose : |
560 | //======================================================================= |
561 | |
562 | Handle(StepRepr_NextAssemblyUsageOccurrence) STEPConstruct_ValidationProps::GetPropNAUO (const Handle(StepRepr_PropertyDefinition) &PD) const |
563 | { |
564 | StepRepr_CharacterizedDefinition CD = PD->Definition(); |
565 | |
566 | // detect target entity of valprop |
567 | Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO; |
568 | Handle(StepRepr_PropertyDefinition) PDS = CD.ProductDefinitionShape(); |
569 | if ( PDS.IsNull() ) return NAUO; // not found |
570 | Interface_EntityIterator subs = Graph().Shareds(PDS); |
571 | for (subs.Start(); NAUO.IsNull() && subs.More(); subs.Next()) { |
572 | NAUO = Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast ( subs.Value() ); |
573 | } |
574 | return NAUO; |
575 | } |
576 | |
577 | //======================================================================= |
578 | //function : GetPropShape CORRECTED |
579 | //purpose : |
580 | //======================================================================= |
581 | |
582 | TopoDS_Shape STEPConstruct_ValidationProps::GetPropShape (const Handle(StepBasic_ProductDefinition) &ProdDef) const |
583 | { |
584 | // find target shape |
585 | TopoDS_Shape S; |
586 | Handle(Transfer_Binder) binder = TransientProcess()->Find(ProdDef); |
587 | if ( ! binder.IsNull() && binder->HasResult() ) { |
588 | S = TransferBRep::ShapeResult ( TransientProcess(), binder ); |
589 | } |
590 | //if ( S.IsNull() ) { // for subshape (via shape_aspect) |
591 | // Handle(StepRepr_Representation) rep = SDR->UsedRepresentation(); |
592 | // for ( Standard_Integer j=1; S.IsNull() && j <= rep->NbItems(); j++ ) { |
593 | // binder = TransientProcess()->Find(rep->ItemsValue(j)); |
594 | // if ( ! binder.IsNull() && binder->HasResult() ) { |
595 | // S = TransferBRep::ShapeResult ( TransientProcess(), binder ); |
596 | // } |
597 | // } |
598 | //} |
0797d9d3 |
599 | #ifdef OCCT_DEBUG |
7fd59977 |
600 | if ( S.IsNull() ) { |
601 | Handle(Message_Messenger) sout = Message::DefaultMessenger(); |
602 | sout << "Warning: Entity "; |
603 | Model()->PrintLabel ( ProdDef, sout ); |
604 | sout << " is not mapped to shape" << endl; |
605 | } |
606 | #endif |
607 | return S; |
608 | } |
609 | |
610 | //======================================================================= |
611 | //function : GetPropShape CORRECTED |
612 | //purpose : |
613 | //======================================================================= |
614 | |
615 | TopoDS_Shape STEPConstruct_ValidationProps::GetPropShape (const Handle(StepRepr_PropertyDefinition) &PD) const |
616 | { |
617 | Handle(StepBasic_ProductDefinition) ProdDef = GetPropPD ( PD ); |
618 | TopoDS_Shape S; |
619 | if ( ! ProdDef.IsNull() ) S = GetPropShape ( ProdDef ); |
620 | return S; |
621 | } |
622 | |
623 | //======================================================================= |
624 | //function : GetPropReal |
625 | //purpose : |
626 | //======================================================================= |
627 | |
628 | Standard_Boolean STEPConstruct_ValidationProps::GetPropReal (const Handle(StepRepr_RepresentationItem) &item, |
629 | Standard_Real &Val, Standard_Boolean &isArea) const |
630 | { |
631 | // decode volume & area |
632 | if ( ! item->IsKind(STANDARD_TYPE(StepRepr_MeasureRepresentationItem)) ) |
633 | return Standard_False; |
634 | |
635 | Handle(StepRepr_MeasureRepresentationItem) mri = |
636 | Handle(StepRepr_MeasureRepresentationItem)::DownCast ( item ); |
637 | |
638 | Handle(StepBasic_MeasureWithUnit) M = mri->Measure(); |
639 | TCollection_AsciiString Name = M->ValueComponentMember()->Name(); |
640 | StepBasic_Unit Unit = M->UnitComponent(); |
641 | |
642 | Standard_Real scale = 1.; |
643 | Handle(StepBasic_DerivedUnit) DU = Unit.DerivedUnit(); |
644 | if ( ! DU.IsNull() ) { |
645 | for(Standard_Integer ind = 1; ind <= DU->NbElements(); ind++) { |
646 | Handle(StepBasic_DerivedUnitElement) DUE = DU->ElementsValue(ind); |
647 | Standard_Real exp = DUE->Exponent(); |
648 | Handle(StepBasic_NamedUnit) NU = DUE->Unit(); |
649 | STEPConstruct_UnitContext unit; |
650 | unit.ComputeFactors(NU); |
651 | if(unit.LengthDone()) { |
652 | Standard_Real lengthFactor = unit.LengthFactor(); |
653 | scale *= pow(lengthFactor,exp); |
654 | } |
655 | } |
656 | } |
657 | else { |
658 | Handle(StepBasic_NamedUnit) NU = Unit.NamedUnit(); |
659 | if(!NU.IsNull()) { |
660 | STEPConstruct_UnitContext unit; |
661 | unit.ComputeFactors(NU); |
662 | if(unit.AreaDone()) |
663 | scale = unit.AreaFactor(); |
664 | if(unit.VolumeDone()) |
665 | scale = unit.VolumeFactor(); |
666 | } |
667 | } |
668 | |
669 | Val = M->ValueComponent() * scale; |
670 | |
671 | if ( Name == "AREA_MEASURE" ) isArea = Standard_True; |
672 | else if ( Name == "VOLUME_MEASURE" ) isArea = Standard_False; |
673 | else { |
0797d9d3 |
674 | #ifdef OCCT_DEBUG |
1c29294e |
675 | cout << "Warning: Measure " << Model()->StringLabel ( M )->String() << " is neither area not volume" << endl; |
7fd59977 |
676 | #endif |
677 | return Standard_False; |
678 | } |
679 | return Standard_True; |
680 | } |
681 | |
682 | //======================================================================= |
683 | //function : GetPropPnt |
684 | //purpose : |
685 | //======================================================================= |
686 | |
687 | Standard_Boolean STEPConstruct_ValidationProps::GetPropPnt (const Handle(StepRepr_RepresentationItem) &item, |
688 | const Handle(StepRepr_RepresentationContext) &Context, |
689 | gp_Pnt &Pnt) const |
690 | { |
691 | // centroid |
692 | if ( ! item->IsKind(STANDARD_TYPE(StepGeom_CartesianPoint)) ) |
693 | return Standard_False; |
694 | |
695 | Handle(StepGeom_CartesianPoint) P = Handle(StepGeom_CartesianPoint)::DownCast ( item ); |
696 | if ( P.IsNull() || P->NbCoordinates() != 3 ) { |
0797d9d3 |
697 | #ifdef OCCT_DEBUG |
1c29294e |
698 | cout << "Warning: Point " << Model()->StringLabel ( P )->String() << " is not valid for centroid" << endl; |
7fd59977 |
699 | #endif |
700 | return Standard_False;; |
701 | } |
702 | |
703 | gp_Pnt pos ( P->CoordinatesValue(1), P->CoordinatesValue(2), P->CoordinatesValue(3) ); |
704 | |
705 | // scale according to units |
706 | if ( ! Context.IsNull() ) { |
707 | Handle(StepRepr_GlobalUnitAssignedContext) theGUAC; |
708 | if (Context->IsKind(STANDARD_TYPE(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext))) { |
709 | DeclareAndCast(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext, theGRCAGAUC,Context); |
710 | theGUAC = theGRCAGAUC->GlobalUnitAssignedContext(); |
711 | } |
712 | else if (Context->IsKind(STANDARD_TYPE(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx))) { |
713 | DeclareAndCast(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx, |
714 | theGRCAGAUC,Context); |
715 | theGUAC = theGRCAGAUC->GlobalUnitAssignedContext(); |
716 | } |
717 | if ( ! theGUAC.IsNull() ) { |
718 | STEPConstruct_UnitContext UnitTool; |
719 | UnitTool.ComputeFactors(theGUAC); |
720 | gp_Pnt zero(0,0,0); |
721 | pos.Scale ( zero, UnitTool.LengthFactor() ); |
722 | } |
723 | } |
724 | Pnt = pos; |
725 | |
726 | return Standard_True; |
727 | } |
728 | |
729 | //======================================================================= |
730 | //function : SetAssemblyShape CORRECTED |
731 | //purpose : |
732 | //======================================================================= |
733 | |
734 | void STEPConstruct_ValidationProps::SetAssemblyShape (const TopoDS_Shape& shape) |
735 | { |
736 | Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper(FinderProcess(),shape); |
737 | FinderProcess()->FindTypedTransient(mapper,STANDARD_TYPE(StepBasic_ProductDefinition),myAssemblyPD); |
738 | } |