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