0026854: Use -Wextra with GCC
[occt.git] / src / STEPCAFControl / STEPCAFControl_Reader.cxx
CommitLineData
b311480e 1// Created on: 2000-08-15
2// Created by: Andrey BETENEV
973c2be1 3// Copyright (c) 2000-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
7fd59977 16
42cf5bc1 17#include <BRep_Builder.hxx>
18#include <Interface_EntityIterator.hxx>
7fd59977 19#include <Interface_InterfaceModel.hxx>
1c9d3225 20#include <StepData_StepModel.hxx>
21#include <HeaderSection_FileSchema.hxx>
42cf5bc1 22#include <Interface_Static.hxx>
23#include <NCollection_DataMap.hxx>
24#include <OSD_Path.hxx>
25#include <Quantity_Color.hxx>
26#include <StepAP214_AppliedExternalIdentificationAssignment.hxx>
27#include <StepBasic_ConversionBasedUnitAndLengthUnit.hxx>
1c9d3225 28#include <StepBasic_ConversionBasedUnitAndPlaneAngleUnit.hxx>
42cf5bc1 29#include <StepBasic_ConversionBasedUnitAndMassUnit.hxx>
30#include <StepBasic_DerivedUnit.hxx>
31#include <StepBasic_DerivedUnitElement.hxx>
32#include <StepBasic_MeasureValueMember.hxx>
33#include <StepBasic_MeasureWithUnit.hxx>
34#include <StepBasic_NamedUnit.hxx>
7fd59977 35#include <StepBasic_Product.hxx>
36#include <StepBasic_ProductDefinition.hxx>
7fd59977 37#include <StepBasic_ProductDefinitionFormation.hxx>
42cf5bc1 38#include <StepBasic_ProductDefinitionRelationship.hxx>
39#include <StepBasic_SiUnit.hxx>
40#include <StepBasic_Unit.hxx>
41#include <STEPCAFControl_Controller.hxx>
42#include <STEPCAFControl_DataMapIteratorOfDataMapOfShapePD.hxx>
43#include <STEPCAFControl_DataMapOfPDExternFile.hxx>
44#include <STEPCAFControl_DataMapOfSDRExternFile.hxx>
45#include <STEPCAFControl_DataMapOfShapePD.hxx>
46#include <STEPCAFControl_DictionaryOfExternFile.hxx>
47#include <STEPCAFControl_ExternFile.hxx>
48#include <STEPCAFControl_Reader.hxx>
7fd59977 49#include <STEPConstruct.hxx>
42cf5bc1 50#include <STEPConstruct_Assembly.hxx>
7fd59977 51#include <STEPConstruct_ExternRefs.hxx>
42cf5bc1 52#include <STEPConstruct_Styles.hxx>
53#include <STEPConstruct_Tool.hxx>
7fd59977 54#include <STEPConstruct_UnitContext.hxx>
7fd59977 55#include <STEPConstruct_ValidationProps.hxx>
42cf5bc1 56#include <STEPControl_Reader.hxx>
1c9d3225 57#include <StepGeom_GeometricRepresentationItem.hxx>
58#include <StepGeom_Axis2Placement3d.hxx>
59#include <StepGeom_Direction.hxx>
42cf5bc1 60#include <StepDimTol_AngularityTolerance.hxx>
61#include <StepDimTol_CircularRunoutTolerance.hxx>
62#include <StepDimTol_CoaxialityTolerance.hxx>
63#include <StepDimTol_ConcentricityTolerance.hxx>
64#include <StepDimTol_CylindricityTolerance.hxx>
65#include <StepDimTol_Datum.hxx>
66#include <StepDimTol_DatumFeature.hxx>
67#include <StepDimTol_DatumReference.hxx>
1c9d3225 68#include <StepDimTol_DatumReferenceElement.hxx>
69#include <StepDimTol_DatumReferenceCompartment.hxx>
70#include <StepDimTol_DatumSystem.hxx>
42cf5bc1 71#include <StepDimTol_FlatnessTolerance.hxx>
72#include <StepDimTol_GeometricTolerance.hxx>
73#include <StepDimTol_GeometricToleranceWithDatumReference.hxx>
74#include <StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol.hxx>
1c9d3225 75#include <StepDimTol_GeoTolAndGeoTolWthDatRef.hxx>
42cf5bc1 76#include <StepDimTol_HArray1OfDatumReference.hxx>
77#include <StepDimTol_LineProfileTolerance.hxx>
78#include <StepDimTol_ModifiedGeometricTolerance.hxx>
79#include <StepDimTol_ParallelismTolerance.hxx>
80#include <StepDimTol_PerpendicularityTolerance.hxx>
81#include <StepDimTol_PositionTolerance.hxx>
1c9d3225 82#include <StepDimTol_ProjectedZoneDefinition.hxx>
42cf5bc1 83#include <StepDimTol_RoundnessTolerance.hxx>
1c9d3225 84#include <StepDimTol_RunoutZoneDefinition.hxx>
42cf5bc1 85#include <StepDimTol_StraightnessTolerance.hxx>
86#include <StepDimTol_SurfaceProfileTolerance.hxx>
87#include <StepDimTol_SymmetryTolerance.hxx>
1c9d3225 88#include <StepDimTol_ToleranceZone.hxx>
89#include <StepDimTol_ToleranceZoneForm.hxx>
42cf5bc1 90#include <StepDimTol_TotalRunoutTolerance.hxx>
1c9d3225 91#include <StepDimTol_GeometricToleranceWithModifiers.hxx>
92#include <StepDimTol_HArray1OfGeometricToleranceModifier.hxx>
93#include <StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod.hxx>
94#include <StepDimTol_GeoTolAndGeoTolWthMod.hxx>
95#include <StepDimTol_GeometricToleranceWithMaximumTolerance.hxx>
96#include <StepDimTol_PlacedDatumTargetFeature.hxx>
42cf5bc1 97#include <StepRepr_AssemblyComponentUsage.hxx>
98#include <StepRepr_CharacterizedDefinition.hxx>
1c9d3225 99#include <StepRepr_CompoundRepresentationItem.hxx>
42cf5bc1 100#include <StepRepr_DescriptiveRepresentationItem.hxx>
101#include <StepRepr_HArray1OfRepresentationItem.hxx>
102#include <StepRepr_MeasureRepresentationItem.hxx>
103#include <StepRepr_NextAssemblyUsageOccurrence.hxx>
104#include <StepRepr_ProductDefinitionShape.hxx>
105#include <StepRepr_PropertyDefinition.hxx>
106#include <StepRepr_PropertyDefinitionRepresentation.hxx>
7fd59977 107#include <StepRepr_Representation.hxx>
42cf5bc1 108#include <StepRepr_RepresentationItem.hxx>
1c9d3225 109#include <StepRepr_HArray1OfRepresentationItem.hxx>
42cf5bc1 110#include <StepRepr_RepresentationRelationship.hxx>
111#include <StepRepr_RepresentedDefinition.hxx>
112#include <StepRepr_ReprItemAndLengthMeasureWithUnit.hxx>
1c9d3225 113#include <StepRepr_ReprItemAndPlaneAngleMeasureWithUnit.hxx>
42cf5bc1 114#include <StepRepr_SequenceOfRepresentationItem.hxx>
115#include <StepRepr_ShapeAspect.hxx>
1c9d3225 116#include <StepRepr_CompositeShapeAspect.hxx>
117#include <StepRepr_AllAroundShapeAspect.hxx>
118#include <StepRepr_CompShAspAndDatumFeatAndShAsp.hxx>
42cf5bc1 119#include <StepRepr_ShapeAspectRelationship.hxx>
7fd59977 120#include <StepRepr_ShapeRepresentationRelationship.hxx>
42cf5bc1 121#include <StepRepr_SpecifiedHigherUsageOccurrence.hxx>
122#include <StepRepr_ValueRange.hxx>
1c9d3225 123#include <StepRepr_FeatureForDatumTargetRelationship.hxx>
42cf5bc1 124#include <StepShape_AdvancedFace.hxx>
1c9d3225 125#include <StepShape_AdvancedBrepShapeRepresentation.hxx>
126#include <StepShape_AngleRelator.hxx>
127#include <StepShape_AngularSize.hxx>
128#include <StepShape_AngularLocation.hxx>
42cf5bc1 129#include <StepShape_ClosedShell.hxx>
130#include <StepShape_ConnectedFaceSet.hxx>
131#include <StepShape_ContextDependentShapeRepresentation.hxx>
1c9d3225 132#include <StepRepr_CompGroupShAspAndCompShAspAndDatumFeatAndShAsp.hxx>
133#include <StepRepr_CompShAspAndDatumFeatAndShAsp.hxx>
42cf5bc1 134#include <StepShape_DimensionalCharacteristicRepresentation.hxx>
1c9d3225 135#include <StepShape_DimensionalSizeWithPath.hxx>
136#include <StepShape_DimensionalLocationWithPath.hxx>
137#include <StepShape_ShapeDimensionRepresentationItem.hxx>
138#include <StepShape_ShapeRepresentationWithParameters.hxx>
139#include <StepShape_HArray1OfShapeDimensionRepresentationItem.hxx>
42cf5bc1 140#include <StepShape_DimensionalSize.hxx>
1c9d3225 141#include <StepShape_DimensionalLocation.hxx>
42cf5bc1 142#include <StepShape_EdgeCurve.hxx>
143#include <StepShape_EdgeLoop.hxx>
144#include <StepShape_GeometricSet.hxx>
145#include <StepShape_HArray1OfFace.hxx>
146#include <StepShape_HArray1OfFaceBound.hxx>
147#include <StepShape_HArray1OfOrientedEdge.hxx>
148#include <StepShape_HArray1OfShell.hxx>
1c9d3225 149#include <StepShape_LimitsAndFits.hxx>
42cf5bc1 150#include <StepShape_Loop.hxx>
151#include <StepShape_ManifoldSolidBrep.hxx>
1c9d3225 152#include <StepShape_PlusMinusTolerance.hxx>
153#include <StepShape_QualifiedRepresentationItem.hxx>
42cf5bc1 154#include <StepShape_OpenShell.hxx>
155#include <StepShape_ShapeDefinitionRepresentation.hxx>
156#include <StepShape_ShapeDimensionRepresentation.hxx>
157#include <StepShape_ShapeRepresentation.hxx>
158#include <StepShape_ShellBasedSurfaceModel.hxx>
159#include <StepShape_SolidModel.hxx>
1c9d3225 160#include <StepShape_ToleranceMethodDefinition.hxx>
161#include <StepShape_ToleranceValue.hxx>
162#include <StepShape_ValueFormatTypeQualifier.hxx>
42cf5bc1 163#include <StepShape_Vertex.hxx>
7fd59977 164#include <StepVisual_Invisibility.hxx>
42cf5bc1 165#include <StepVisual_LayeredItem.hxx>
166#include <StepVisual_PresentationLayerAssignment.hxx>
167#include <StepVisual_PresentationStyleByContext.hxx>
168#include <StepVisual_StyleContextSelect.hxx>
169#include <StepVisual_StyledItem.hxx>
1c9d3225 170#include <StepShape_TypeQualifier.hxx>
42cf5bc1 171#include <TCollection_AsciiString.hxx>
172#include <TCollection_HAsciiString.hxx>
173#include <TColStd_HArray1OfReal.hxx>
174#include <TColStd_HArray1OfTransient.hxx>
175#include <TColStd_HSequenceOfTransient.hxx>
176#include <TColStd_IndexedDataMapOfTransientTransient.hxx>
177#include <TColStd_MapIteratorOfMapOfTransient.hxx>
178#include <TColStd_MapOfTransient.hxx>
7fd59977 179#include <TColStd_SequenceOfHAsciiString.hxx>
42cf5bc1 180#include <TDataStd_Name.hxx>
7fd59977 181#include <TDataStd_TreeNode.hxx>
42cf5bc1 182#include <TDataStd_UAttribute.hxx>
183#include <TDF_Label.hxx>
184#include <TDF_Tool.hxx>
185#include <TDocStd_Document.hxx>
7fd59977 186#include <TNaming_NamedShape.hxx>
1c9d3225 187#include <TopoDS.hxx>
42cf5bc1 188#include <TopoDS_Compound.hxx>
189#include <TopoDS_Iterator.hxx>
190#include <TopoDS_Shape.hxx>
191#include <TopTools_ListIteratorOfListOfShape.hxx>
192#include <TopTools_ListOfShape.hxx>
193#include <TopTools_MapOfShape.hxx>
194#include <Transfer_Binder.hxx>
195#include <Transfer_TransientProcess.hxx>
196#include <TransferBRep.hxx>
197#include <XCAFDoc.hxx>
198#include <XCAFDoc_Area.hxx>
199#include <XCAFDoc_Centroid.hxx>
200#include <XCAFDoc_ColorTool.hxx>
201#include <XCAFDoc_DataMapOfShapeLabel.hxx>
202#include <XCAFDoc_DimTolTool.hxx>
1c9d3225 203#include <XCAFDoc_Dimension.hxx>
204#include <XCAFDoc_Datum.hxx>
205#include <XCAFDoc_GeomTolerance.hxx>
42cf5bc1 206#include <XCAFDoc_DocumentTool.hxx>
7fd59977 207#include <XCAFDoc_GraphNode.hxx>
42cf5bc1 208#include <XCAFDoc_LayerTool.hxx>
209#include <XCAFDoc_MaterialTool.hxx>
210#include <XCAFDoc_ShapeTool.hxx>
211#include <XCAFDoc_Volume.hxx>
1c9d3225 212#include <XCAFDimTolObjects_DimensionModifiersSequence.hxx>
213#include <XCAFDimTolObjects_GeomToleranceType.hxx>
214#include <XCAFDimTolObjects_DimensionObject.hxx>
215#include <XCAFDimTolObjects_GeomToleranceObject.hxx>
216#include <XCAFDimTolObjects_DatumObject.hxx>
42cf5bc1 217#include <XSControl_TransferReader.hxx>
218#include <XSControl_WorkSession.hxx>
1c9d3225 219#include <StepAP242_GeometricItemSpecificUsage.hxx>
220#include <StepGeom_CartesianPoint.hxx>
221#include <STEPConstruct_GDTProperty.hxx>
7fd59977 222// skl 21.08.2003 for reading G&DT
7fd59977 223//#include <StepRepr_CompoundItemDefinition.hxx>
224//#include <StepRepr_CompoundItemDefinitionMember.hxx>
7fd59977 225//#include <StepBasic_ConversionBasedUnit.hxx>
7fd59977 226//#include <TDataStd_Real.hxx>
227//#include <TDataStd_Constraint.hxx>
228//#include <TDataStd_ConstraintEnum.hxx>
229//#include <TNaming_Tool.hxx>
230//#include <AIS_InteractiveObject.hxx>
231//#include <TPrsStd_ConstraintTools.hxx>
232//#include <AIS_DiameterDimension.hxx>
233//#include <TPrsStd_Position.hxx>
234//#include <TPrsStd_AISPresentation.hxx>
235//#include <TNaming_Builder.hxx>
0797d9d3 236#ifdef OCCT_DEBUG
02a0b964 237//! Converts address of the passed shape (TShape) to string.
238//! \param theShape [in] Shape to dump.
239//! \return corresponding string.
240TCollection_AsciiString AddrToString(const TopoDS_Shape& theShape)
241{
242 std::string anAddrStr;
243 std::ostringstream ost;
1c29294e 244 ost << theShape.TShape().get();
02a0b964 245 anAddrStr = ost.str();
246
247 TCollection_AsciiString aStr =
248 TCollection_AsciiString("[").Cat( anAddrStr.c_str() ).Cat("]");
249
250 return aStr;
251}
252#endif
253
254//=======================================================================
255//function : IsEqual
256//purpose : global function to check equality of topological shapes
257//=======================================================================
258
259inline Standard_Boolean IsEqual(const TopoDS_Shape& theShape1,
260 const TopoDS_Shape& theShape2)
261{
262 return theShape1.IsEqual(theShape2);
263}
7fd59977 264
02a0b964 265//=======================================================================
266//function : AllocateSubLabel
267//purpose :
268//=======================================================================
269
270static TDF_Label AllocateSubLabel(TDF_Label& theRoot)
271{
272 return TDF_TagSource::NewChild(theRoot);
273}
7fd59977 274
275//=======================================================================
276//function : STEPCAFControl_Reader
277//purpose :
278//=======================================================================
279
280STEPCAFControl_Reader::STEPCAFControl_Reader ():
281 myColorMode( Standard_True ),
282 myNameMode ( Standard_True ),
283 myLayerMode( Standard_True ),
284 myPropsMode( Standard_True ),
c24d4017 285 mySHUOMode ( Standard_False ),
7fd59977 286 myGDTMode ( Standard_True ),
287 myMatMode ( Standard_True )
288{
289 STEPCAFControl_Controller::Init();
290 myFiles = new STEPCAFControl_DictionaryOfExternFile;
291}
292
293
294//=======================================================================
295//function : STEPCAFControl_Reader
296//purpose :
297//=======================================================================
298
299STEPCAFControl_Reader::STEPCAFControl_Reader (const Handle(XSControl_WorkSession)& WS,
02a0b964 300 const Standard_Boolean scratch) :
7fd59977 301 myColorMode( Standard_True ),
302 myNameMode ( Standard_True ),
303 myLayerMode( Standard_True ),
304 myPropsMode( Standard_True ),
c24d4017 305 mySHUOMode ( Standard_False ),
7fd59977 306 myGDTMode ( Standard_True ),
307 myMatMode ( Standard_True )
308{
309 STEPCAFControl_Controller::Init();
310 Init ( WS, scratch );
311}
312
313
314//=======================================================================
315//function : Init
316//purpose :
317//=======================================================================
318
319void STEPCAFControl_Reader::Init (const Handle(XSControl_WorkSession)& WS,
320 const Standard_Boolean scratch)
321{
322// necessary only in Writer, to set good actor: WS->SelectNorm ( "STEP" );
323 myReader.SetWS (WS,scratch);
324 myFiles = new STEPCAFControl_DictionaryOfExternFile;
325}
326
327
328//=======================================================================
329//function : ReadFile
330//purpose :
331//=======================================================================
332
333IFSelect_ReturnStatus STEPCAFControl_Reader::ReadFile (const Standard_CString filename)
334{
335 return myReader.ReadFile ( filename );
336}
337
338
339//=======================================================================
340//function : NbRootsForTransfer
341//purpose :
342//=======================================================================
343
344Standard_Integer STEPCAFControl_Reader::NbRootsForTransfer ()
345{
346 return myReader.NbRootsForTransfer();
347}
348
349
350//=======================================================================
351//function : TransferOneRoot
352//purpose :
353//=======================================================================
354
355Standard_Boolean STEPCAFControl_Reader::TransferOneRoot (const Standard_Integer num,
356 Handle(TDocStd_Document) &doc)
357{
358 TDF_LabelSequence Lseq;
359 return Transfer ( myReader, num, doc, Lseq );
360}
361
362
363//=======================================================================
364//function : Transfer
365//purpose :
366//=======================================================================
367
368Standard_Boolean STEPCAFControl_Reader::Transfer (Handle(TDocStd_Document) &doc)
369{
370 TDF_LabelSequence Lseq;
371 return Transfer ( myReader, 0, doc, Lseq );
372}
373
374
375//=======================================================================
376//function : Perform
377//purpose :
378//=======================================================================
379
380Standard_Boolean STEPCAFControl_Reader::Perform (const Standard_CString filename,
381 Handle(TDocStd_Document) &doc)
382{
383 if ( ReadFile ( filename ) != IFSelect_RetDone ) return Standard_False;
384 return Transfer ( doc );
385}
386
387
388//=======================================================================
389//function : Perform
390//purpose :
391//=======================================================================
392
393Standard_Boolean STEPCAFControl_Reader::Perform (const TCollection_AsciiString &filename,
394 Handle(TDocStd_Document) &doc)
395{
396 if ( ReadFile ( filename.ToCString() ) != IFSelect_RetDone ) return Standard_False;
397 return Transfer ( doc );
398}
399
400
401//=======================================================================
402//function : ExternFiles
403//purpose :
404//=======================================================================
405
406const Handle(STEPCAFControl_DictionaryOfExternFile) &STEPCAFControl_Reader::ExternFiles () const
407{
408 return myFiles;
409}
410
411
412//=======================================================================
413//function : ExternFile
414//purpose :
415//=======================================================================
416
417Standard_Boolean STEPCAFControl_Reader::ExternFile (const Standard_CString name,
418 Handle(STEPCAFControl_ExternFile) &ef) const
419{
420 ef.Nullify();
421 if ( myFiles.IsNull() || ! myFiles->HasItem ( name ) )
422 return Standard_False;
423 ef = myFiles->Item ( name );
424 return Standard_True;
425}
426
427
428//=======================================================================
429//function : Reader
430//purpose :
431//=======================================================================
432
433STEPControl_Reader &STEPCAFControl_Reader::ChangeReader ()
434{
435 return myReader;
436}
437
438
439//=======================================================================
440//function : Reader
441//purpose :
442//=======================================================================
443
444const STEPControl_Reader &STEPCAFControl_Reader::Reader () const
445{
446 return myReader;
447}
448
449
450//=======================================================================
451//function : FillShapesMap
452//purpose : auxiliary: fill a map by all compounds and their components
453//=======================================================================
454
455static void FillShapesMap (const TopoDS_Shape &S, TopTools_MapOfShape &map)
456{
457 TopoDS_Shape S0 = S;
458 TopLoc_Location loc;
459 S0.Location ( loc );
460 map.Add ( S0 );
461 if ( S.ShapeType() != TopAbs_COMPOUND ) return;
462 for ( TopoDS_Iterator it(S); it.More(); it.Next() )
463 FillShapesMap ( it.Value(), map );
464}
465
466
467//=======================================================================
468//function : Transfer
469//purpose : basic working method
470//=======================================================================
471
472Standard_Boolean STEPCAFControl_Reader::Transfer (STEPControl_Reader &reader,
473 const Standard_Integer nroot,
474 Handle(TDocStd_Document) &doc,
475 TDF_LabelSequence &Lseq,
476 const Standard_Boolean asOne)
477{
478 reader.ClearShapes();
479 Standard_Integer i;
480
481 // Read all shapes
482 Standard_Integer num = reader.NbRootsForTransfer();
483 if ( num <=0 ) return Standard_False;
484 if ( nroot ) {
485 if ( nroot > num ) return Standard_False;
44d7c408 486 reader.TransferOneRoot ( nroot );
7fd59977 487 }
488 else {
489 for ( i=1; i <= num; i++ ) reader.TransferOneRoot ( i );
490 }
491 num = reader.NbShapes();
492 if ( num <=0 ) return Standard_False;
493
494 // Fill a map of (top-level) shapes resulting from that transfer
495 // Only these shapes will be considered further
496 TopTools_MapOfShape ShapesMap, NewShapesMap;
497 for ( i=1; i <= num; i++ ) FillShapesMap ( reader.Shape(i), ShapesMap );
498
499 // Collect information on shapes originating from SDRs
500 // this will be used to distinguish compounds representing assemblies
501 // from the ones representing hybrid models and shape sets
502 STEPCAFControl_DataMapOfShapePD ShapePDMap;
503 STEPCAFControl_DataMapOfPDExternFile PDFileMap;
504 Handle(Interface_InterfaceModel) Model = reader.Model();
505 Handle(Transfer_TransientProcess) TP = reader.WS()->TransferReader()->TransientProcess();
506 Standard_Integer nb = Model->NbEntities();
507
508 Handle(TColStd_HSequenceOfTransient) SeqPDS = new TColStd_HSequenceOfTransient;
509
510 for (i = 1; i <= nb; i ++) {
511 Handle(Standard_Transient) enti = Model->Value(i);
512 if(enti->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape))) {
513 // sequence for acceleration ReadMaterials
514 SeqPDS->Append(enti);
515 }
516 if ( enti->IsKind ( STANDARD_TYPE(StepBasic_ProductDefinition ) ) ) {
517 Handle(StepBasic_ProductDefinition) PD =
518 Handle(StepBasic_ProductDefinition)::DownCast(enti);
519 Standard_Integer index = TP->MapIndex(PD);
520 if ( index >0 ) {
521 Handle(Transfer_Binder) binder = TP->MapItem (index);
522 TopoDS_Shape S = TransferBRep::ShapeResult(binder);
523 if ( ! S.IsNull() && ShapesMap.Contains(S) ) {
524 NewShapesMap.Add(S);
525 ShapePDMap.Bind ( S, PD );
526 Handle(STEPCAFControl_ExternFile) EF;
527 PDFileMap.Bind ( PD, EF );
528 }
529 }
530 }
531 if ( enti->IsKind ( STANDARD_TYPE(StepShape_ShapeRepresentation) ) ) {
532 Standard_Integer index = TP->MapIndex(enti);
533 if ( index >0 ) {
534 Handle(Transfer_Binder) binder = TP->MapItem (index);
535 TopoDS_Shape S = TransferBRep::ShapeResult(binder);
536 if ( ! S.IsNull() && ShapesMap.Contains(S) )
537 NewShapesMap.Add(S);
538 }
539 }
540 }
541
542 // get directory name of the main file
543 OSD_Path mainfile ( reader.WS()->LoadedFile() );
544 mainfile.SetName ( "" );
545 mainfile.SetExtension ( "" );
546 TCollection_AsciiString dpath;
547 mainfile.SystemName ( dpath );
548
549 // Load external references (only for relevant SDRs)
550 // and fill map SDR -> extern file
551 STEPConstruct_ExternRefs ExtRefs ( reader.WS() );
552 ExtRefs.LoadExternRefs();
553 for ( i=1; i <= ExtRefs.NbExternRefs(); i++ ) {
554 // check extern ref format
555 Handle(TCollection_HAsciiString) format = ExtRefs.Format(i);
556 if ( ! format.IsNull() ) {
557 static Handle(TCollection_HAsciiString) ap203 = new TCollection_HAsciiString ( "STEP AP203" );
558 static Handle(TCollection_HAsciiString) ap214 = new TCollection_HAsciiString ( "STEP AP214" );
559 if ( ! format->IsSameString ( ap203, Standard_False ) &&
560 ! format->IsSameString ( ap214, Standard_False ) ) {
0797d9d3 561#ifdef OCCT_DEBUG
7fd59977 562 cout << "Warning: STEPCAFControl_Reader::Transfer: Extern document is neither STEP AP203 nor AP214" << endl;
563#else
564 continue;
565#endif
566 }
567 }
0797d9d3 568#ifdef OCCT_DEBUG
7fd59977 569 else cout << "Warning: STEPCAFControl_Reader::Transfer: Extern document format not defined" << endl;
570#endif
571
572 // get and check filename of the current extern ref
573 const Standard_CString filename = ExtRefs.FileName(i);
574
0797d9d3 575#ifdef OCCT_DEBUG
aefdc31b 576 cout<<"filename="<<filename<<endl;
83a86948 577#endif
7fd59977 578
579 if ( ! filename || ! filename[0] ) {
0797d9d3 580#ifdef OCCT_DEBUG
7fd59977 581 cout << "Warning: STEPCAFControl_Reader::Transfer: Extern reference file name is empty" << endl;
582#endif
583 continue; // not a valid extern ref
584 }
585
586 // compute true path to the extern file
587 TCollection_AsciiString fullname = OSD_Path::AbsolutePath ( dpath, filename );
588 if ( fullname.Length() <= 0 ) fullname = filename;
589
590/*
591 char fullname[1024];
592 char *mainfile = reader.WS()->LoadedFile();
593 if ( ! mainfile ) mainfile = "";
594 Standard_Integer slash = 0;
595 for ( Standard_Integer k=0; mainfile[k]; k++ )
596 if ( mainfile[k] == '/' ) slash = k;
597 strncpy ( fullname, mainfile, slash );
598 sprintf ( &fullname[slash], "%s%s", ( mainfile[0] ? "/" : "" ), filename );
599*/
600
601 // get and check PD associated with the current extern ref
602 Handle(StepBasic_ProductDefinition) PD = ExtRefs.ProdDef(i);
603 if ( PD.IsNull() ) continue; // not a valid extern ref
604 if ( ! PDFileMap.IsBound ( PD ) ) continue; // this PD is not concerned by current transfer
605
606 // read extern file (or use existing data) and record its data
607 Handle(STEPCAFControl_ExternFile) EF =
608 ReadExternFile ( filename, fullname.ToCString(), doc );
609 PDFileMap.Bind ( PD, EF );
610 }
611
612 // and insert them to the document
613 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( doc->Main() );
614 if ( STool.IsNull() ) return Standard_False;
615 XCAFDoc_DataMapOfShapeLabel map;
616 if ( asOne )
617 Lseq.Append ( AddShape ( reader.OneShape(), STool, NewShapesMap, ShapePDMap, PDFileMap, map ) );
618 else {
619 for ( i=1; i <= num; i++ ) {
620 Lseq.Append ( AddShape ( reader.Shape(i), STool, NewShapesMap, ShapePDMap, PDFileMap, map ) );
621 }
622 }
623
624 // read colors
625 if ( GetColorMode() )
626 ReadColors ( reader.WS(), doc, PDFileMap, map );
627
628 // read names
629 if ( GetNameMode() )
630 ReadNames ( reader.WS(), doc, PDFileMap, map );
631
632 // read validation props
633 if ( GetPropsMode() )
634 ReadValProps ( reader.WS(), doc, PDFileMap, map );
635
636 // read layers
637 if ( GetLayerMode() )
638 ReadLayers ( reader.WS(), doc );
639
640 // read SHUO entities from STEP model
641 if ( GetSHUOMode() )
642 ReadSHUOs ( reader.WS(), doc, PDFileMap, map );
643
644 // read GDT entities from STEP model
645 if(GetGDTMode())
646 ReadGDTs(reader.WS(),doc);
647
648 // read Material entities from STEP model
649 if(GetMatMode())
650 ReadMaterials(reader.WS(),doc,SeqPDS);
651
02a0b964 652 // Expand resulting CAF structure for sub-shapes (optionally with their
653 // names) if requested
654 ExpandSubShapes(STool, map, ShapePDMap);
655
7fd59977 656 return Standard_True;
657}
658
659//=======================================================================
660//function : AddShape
661//purpose :
662//=======================================================================
663
664TDF_Label STEPCAFControl_Reader::AddShape (const TopoDS_Shape &S,
665 const Handle(XCAFDoc_ShapeTool) &STool,
666 const TopTools_MapOfShape &NewShapesMap,
667 const STEPCAFControl_DataMapOfShapePD &ShapePDMap,
668 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
669 XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
670{
671 // if shape has already been mapped, just return corresponding label
672 if ( ShapeLabelMap.IsBound ( S ) ) {
673 return ShapeLabelMap.Find ( S );
674 }
675
676 // if shape is located, create instance
677 if ( ! S.Location().IsIdentity() ) {
678 TopoDS_Shape S0 = S;
679 TopLoc_Location loc;
680 S0.Location ( loc );
681 AddShape ( S0, STool, NewShapesMap, ShapePDMap, PDFileMap, ShapeLabelMap );
682 TDF_Label L = STool->AddShape ( S, Standard_False ); // should create reference
683 ShapeLabelMap.Bind ( S, L );
684 return L;
685 }
686
687 // if shape is not compound, simple add it
688 if ( S.ShapeType() != TopAbs_COMPOUND ) {
689 TDF_Label L = STool->AddShape ( S, Standard_False );
690 ShapeLabelMap.Bind ( S, L );
691 return L;
692 }
693
694 // for compounds, compute number of subshapes and check whether this is assembly
695 Standard_Boolean isAssembly = Standard_False;
696 Standard_Integer nbComponents = 0;
697 TopoDS_Iterator it;
698 for ( it.Initialize(S); it.More(); it.Next(), nbComponents++ ) {
699 TopoDS_Shape Sub0 = it.Value();
700 TopLoc_Location loc;
701 Sub0.Location ( loc );
702 if ( NewShapesMap.Contains ( Sub0 ) ) isAssembly = Standard_True;
703 }
704
705// if(nbComponents>0) isAssembly = Standard_True;
706
707 // check whether it has associated external ref
708 TColStd_SequenceOfHAsciiString SHAS;
709 if ( ShapePDMap.IsBound ( S ) && PDFileMap.IsBound ( ShapePDMap.Find(S) ) ) {
710 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find ( ShapePDMap.Find(S) );
711 if ( ! EF.IsNull() ) {
712 // (store information on extern refs in the document)
713 SHAS.Append(EF->GetName());
714 // if yes, just return corresponding label
715 if ( ! EF->GetLabel().IsNull() ) {
716 // but if components >0, ignore extern ref!
717 if ( nbComponents <=0 ) {
718 ShapeLabelMap.Bind ( S, EF->GetLabel() );
719 STool->SetExternRefs(EF->GetLabel(),SHAS);
720 return EF->GetLabel();
721 }
722 }
0797d9d3 723#ifdef OCCT_DEBUG
7fd59977 724 if ( ! EF->GetLabel().IsNull() )
725 cout << "Warning: STEPCAFControl_Reader::AddShape: Non-empty shape with external ref; ref is ignored" << endl;
726 else if ( nbComponents <=0 )
727 cout << "Warning: STEPCAFControl_Reader::AddShape: Result of reading extern ref is Null" << endl;
728#endif
729 }
730 }
731
732 // add compound either as a whole,
733 if ( ! isAssembly ) {
734 TDF_Label L = STool->AddShape ( S, Standard_False );
735 if ( SHAS.Length() >0 ) STool->SetExternRefs(L,SHAS);
736 ShapeLabelMap.Bind ( S, L );
737 return L;
738 }
739
740 // or as assembly, component-by-component
741 TDF_Label L = STool->NewShape();
742 for ( it.Initialize(S); it.More(); it.Next(), nbComponents++ ) {
743 TopoDS_Shape Sub0 = it.Value();
744 TopLoc_Location loc;
745 Sub0.Location ( loc );
746 TDF_Label subL = AddShape ( Sub0, STool, NewShapesMap, ShapePDMap, PDFileMap, ShapeLabelMap );
747 if ( ! subL.IsNull() ) {
748 STool->AddComponent ( L, subL, it.Value().Location() );
749 }
750 }
751 if ( SHAS.Length() >0 ) STool->SetExternRefs(L,SHAS);
752 ShapeLabelMap.Bind ( S, L );
753 //STool->SetShape ( L, S ); // it is necessary for assemblies OCC1747 // commemted by skl for OCC2941
754
755 return L;
756}
757
758//=======================================================================
759//function : ReadExternFile
760//purpose :
761//=======================================================================
762
763Handle(STEPCAFControl_ExternFile) STEPCAFControl_Reader::ReadExternFile (const Standard_CString file,
764 const Standard_CString fullname,
765 Handle(TDocStd_Document)& doc)
766{
767 // if the file is already read, associate it with SDR
768 if ( myFiles->HasItem ( file, Standard_True ) ) {
769 return myFiles->Item ( file );
770 }
771
0797d9d3 772#ifdef OCCT_DEBUG
7fd59977 773 cout << "Reading extern file: " << fullname << endl;
774#endif
775
776 // create new WorkSession and Reader
777 Handle(XSControl_WorkSession) newWS = new XSControl_WorkSession;
778 newWS->SelectNorm ( "STEP" );
779 STEPControl_Reader sr ( newWS, Standard_False );
780
781 // start to fill the resulting ExternFile structure
782 Handle(STEPCAFControl_ExternFile) EF = new STEPCAFControl_ExternFile;
783 EF->SetWS ( newWS );
784 EF->SetName ( new TCollection_HAsciiString ( file ) );
785
786 // read file
787 EF->SetLoadStatus ( sr.ReadFile ( fullname ) );
788
789 // transfer in single-result mode
790 if ( EF->GetLoadStatus() == IFSelect_RetDone ) {
791 TDF_LabelSequence labels;
792 EF->SetTransferStatus ( Transfer ( sr, 0, doc, labels, Standard_True ) );
793 if ( labels.Length() >0 ) EF->SetLabel ( labels.Value(1) );
794 }
795
796 // add read file to dictionary
797 myFiles->SetItem ( file, EF );
798
799 return EF;
800}
801
802
803//=======================================================================
804//function : SetColorToSubshape
805//purpose : auxilary
806//=======================================================================
807static void SetColorToSubshape(const Handle(XCAFDoc_ColorTool) & CTool,
808 const TopoDS_Shape & S,
809 const Quantity_Color& col,
810 const XCAFDoc_ColorType type)
811{
812 for (TopoDS_Iterator it(S); it.More(); it.Next())
813 if (! CTool->SetColor( it.Value(), col, type)) break;
814}
815
816
817//=======================================================================
818//function : findStyledSR
819//purpose : auxilary
820//=======================================================================
821static void findStyledSR (const Handle(StepVisual_StyledItem) &style,
822 Handle(StepShape_ShapeRepresentation)& aSR)
823{
824 // search Shape Represenatation for component styled item
825 for ( Standard_Integer j=1; j <= style->NbStyles(); j++ ) {
826 Handle(StepVisual_PresentationStyleByContext) PSA =
827 Handle(StepVisual_PresentationStyleByContext)::DownCast(style->StylesValue ( j ));
828 if ( PSA.IsNull() )
829 continue;
830 StepVisual_StyleContextSelect aStyleCntxSlct = PSA->StyleContext();
831 Handle(StepShape_ShapeRepresentation) aCurrentSR =
832 Handle(StepShape_ShapeRepresentation)::DownCast(aStyleCntxSlct.Representation());
833 if ( aCurrentSR.IsNull() )
834 continue;
835 aSR = aCurrentSR;
836 break;
837 }
838}
839
840
841//=======================================================================
842//function : ReadColors
843//purpose :
844//=======================================================================
845
846Standard_Boolean STEPCAFControl_Reader::ReadColors (const Handle(XSControl_WorkSession) &WS,
847 Handle(TDocStd_Document)& Doc,
848 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
849 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
850{
851 STEPConstruct_Styles Styles ( WS );
852 if ( ! Styles.LoadStyles() ) {
0797d9d3 853#ifdef OCCT_DEBUG
7fd59977 854 cout << "Warning: no styles are found in the model" << endl;
855#endif
856 return Standard_False;
857 }
858 // searching for invisible items in the model
859 Handle(TColStd_HSequenceOfTransient) aHSeqOfInvisStyle = new TColStd_HSequenceOfTransient;
860 Styles.LoadInvisStyles( aHSeqOfInvisStyle );
861
862 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( Doc->Main() );
863 if ( CTool.IsNull() ) return Standard_False;
864
865 // parse and search for color attributes
866 Standard_Integer nb = Styles.NbStyles();
867 for ( Standard_Integer i=1; i <= nb; i++ ) {
868 Handle(StepVisual_StyledItem) style = Styles.Style ( i );
869 if ( style.IsNull() ) continue;
870
871 Standard_Boolean IsVisible = Standard_True;
872 // check the visibility of styled item.
873 for (Standard_Integer si = 1; si <= aHSeqOfInvisStyle->Length(); si++ ) {
874 if ( style != aHSeqOfInvisStyle->Value( si ) )
875 continue;
876 // found that current style is invisible.
7fd59977 877 IsVisible = Standard_False;
878 break;
879 }
880
881 Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol;
882 // check if it is component style
883 Standard_Boolean IsComponent = Standard_False;
884 if ( ! Styles.GetColors ( style, SurfCol, BoundCol, CurveCol, IsComponent ) && IsVisible )
885 continue;
886
887 // find shape
888 TopoDS_Shape S = STEPConstruct::FindShape ( Styles.TransientProcess(), style->Item() );
889 Standard_Boolean isSkipSHUOstyle = Standard_False;
890 // take shape with real location.
891 while ( IsComponent ) {
892 // take SR of NAUO
893 Handle(StepShape_ShapeRepresentation) aSR;
894 findStyledSR( style, aSR );
895 // search for SR along model
896 if (aSR.IsNull())
897 break;
898// Handle(Interface_InterfaceModel) Model = WS->Model();
899 Handle(XSControl_TransferReader) TR = WS->TransferReader();
900 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
901 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings( aSR );
902 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
903 for (subs.Start(); subs.More(); subs.Next()) {
904 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
905 if ( aSDR.IsNull() )
906 continue;
907 StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition();
908 Handle(StepRepr_ProductDefinitionShape) PDS =
909 Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition());
910 if ( PDS.IsNull() )
911 continue;
912 StepRepr_CharacterizedDefinition aCharDef = PDS->Definition();
913
914 Handle(StepRepr_AssemblyComponentUsage) ACU =
915 Handle(StepRepr_AssemblyComponentUsage)::DownCast(aCharDef.ProductDefinitionRelationship());
916 // PTV 10.02.2003 skip styled item that refer to SHUO
917 if (ACU->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) {
918 isSkipSHUOstyle = Standard_True;
919 break;
920 }
921 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
922 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(ACU);
923 if ( NAUO.IsNull() )
924 continue;
925
926 TopoDS_Shape aSh;
927 // PTV 10.02.2003 to find component of assembly CORRECTLY
928 STEPConstruct_Tool Tool( WS );
929 TDF_Label aShLab = FindInstance ( NAUO, CTool->ShapeTool(), Tool, PDFileMap, ShapeLabelMap );
930 aSh = CTool->ShapeTool()->GetShape(aShLab);
931// Handle(Transfer_Binder) binder = TP->Find(NAUO);
932// if ( binder.IsNull() || ! binder->HasResult() )
933// continue;
934// aSh = TransferBRep::ShapeResult ( TP, binder );
935 if (!aSh.IsNull()) {
936 S = aSh;
937 break;
938 }
939 }
940 break;
941 }
942 if (isSkipSHUOstyle)
943 continue; // skip styled item which refer to SHUO
944
36f35343 945 if ( S.IsNull() )
7fd59977 946 continue;
7fd59977 947
948 if ( ! SurfCol.IsNull() ) {
949 Quantity_Color col;
950 Styles.DecodeColor ( SurfCol, col );
951 if ( ! CTool->SetColor ( S, col, XCAFDoc_ColorSurf ))
952 SetColorToSubshape( CTool, S, col, XCAFDoc_ColorSurf );
953 }
954 if ( ! BoundCol.IsNull() ) {
955 Quantity_Color col;
956 Styles.DecodeColor ( BoundCol, col );
957 if ( ! CTool->SetColor ( S, col, XCAFDoc_ColorCurv ))
958 SetColorToSubshape( CTool, S, col, XCAFDoc_ColorCurv );
959 }
960 if ( ! CurveCol.IsNull() ) {
961 Quantity_Color col;
962 Styles.DecodeColor ( CurveCol, col );
963 if ( ! CTool->SetColor ( S, col, XCAFDoc_ColorCurv ))
964 SetColorToSubshape( CTool, S, col, XCAFDoc_ColorCurv );
965 }
966 if ( !IsVisible ) {
967 // sets the invisibility for shape.
968 TDF_Label aInvL;
969 if ( CTool->ShapeTool()->Search( S, aInvL ) )
970 CTool->SetVisibility( aInvL, Standard_False );
971 }
972 }
973 CTool->ReverseChainsOfTreeNodes();
974 return Standard_True;
975}
976
977//=======================================================================
978//function : GetLabelFromPD
979//purpose :
980//=======================================================================
981
982static TDF_Label GetLabelFromPD (const Handle(StepBasic_ProductDefinition) &PD,
983 const Handle(XCAFDoc_ShapeTool) &STool,
984 const Handle(Transfer_TransientProcess) &TP,
985 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
986 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
987{
988 TDF_Label L;
989 if ( PDFileMap.IsBound ( PD ) ) {
990 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find ( PD );
991 if ( ! EF.IsNull() ) {
992 L = EF->GetLabel();
993 if ( ! L.IsNull() ) return L;
994 }
995 }
996
997 TopoDS_Shape S;
998 Handle(Transfer_Binder) binder = TP->Find(PD);
999 if ( binder.IsNull() || ! binder->HasResult() ) return L;
1000 S = TransferBRep::ShapeResult ( TP, binder );
1001 if ( S.IsNull() ) return L;
1002
1003 if ( S.IsNull() ) return L;
1004 if ( ShapeLabelMap.IsBound ( S ) )
1005 L = ShapeLabelMap.Find ( S );
1006 if ( L.IsNull() )
1007 STool->Search ( S, L, Standard_True, Standard_True, Standard_False );
1008 return L;
1009}
1010
1011//=======================================================================
1012//function : FindInstance
1013//purpose :
1014//=======================================================================
1015
1016TDF_Label STEPCAFControl_Reader::FindInstance (const Handle(StepRepr_NextAssemblyUsageOccurrence) &NAUO,
1017 const Handle(XCAFDoc_ShapeTool) &STool,
1018 const STEPConstruct_Tool &Tool,
1019 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1020 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1021{
1022 TDF_Label L;
1023
1024 // get shape resulting from CDSR (in fact, only location is interesting)
1025 Handle(Transfer_TransientProcess) TP = Tool.TransientProcess();
1026 Handle(Transfer_Binder) binder = TP->Find(NAUO);
1027 if ( binder.IsNull() || ! binder->HasResult() ) {
0797d9d3 1028#ifdef OCCT_DEBUG
7fd59977 1029 cout << "Error: STEPCAFControl_Reader::FindInstance: NAUO is not mapped to shape" << endl;
1030#endif
1031 return L;
1032 }
1033
1034 TopoDS_Shape S = TransferBRep::ShapeResult ( TP, binder );
1035 if ( S.IsNull() ) {
0797d9d3 1036#ifdef OCCT_DEBUG
7fd59977 1037 cout << "Error: STEPCAFControl_Reader::FindInstance: NAUO is not mapped to shape" << endl;
1038#endif
1039 return L;
1040 }
1041
1042 // find component`s original label
1043 Handle(StepBasic_ProductDefinition) PD = NAUO->RelatedProductDefinition();
1044 if ( PD.IsNull() ) return L;
1045 TDF_Label Lref = GetLabelFromPD ( PD, STool, TP, PDFileMap, ShapeLabelMap );
1046 if ( Lref.IsNull() ) return L;
1047
1048 // find main shape (assembly) label
1049 PD.Nullify();
1050 PD = NAUO->RelatingProductDefinition();
1051 if ( PD.IsNull() ) return L;
1052 TDF_Label L0 = GetLabelFromPD ( PD, STool, TP, PDFileMap, ShapeLabelMap );
1053 if ( L0.IsNull() ) return L;
1054
1055 // if CDSR and NAUO are reversed, swap labels
1056 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1057 Interface_EntityIterator subs1 = Tool.Graph().Sharings(NAUO);
1058 for (subs1.Start(); subs1.More(); subs1.Next()) {
1059 Handle(StepRepr_ProductDefinitionShape) PDS =
1060 Handle(StepRepr_ProductDefinitionShape)::DownCast(subs1.Value());
1061 if(PDS.IsNull()) continue;
1062 Interface_EntityIterator subs2 = Tool.Graph().Sharings(PDS);
1063 for (subs2.Start(); subs2.More(); subs2.Next()) {
1064 Handle(StepShape_ContextDependentShapeRepresentation) CDSRtmp =
1065 Handle(StepShape_ContextDependentShapeRepresentation)::DownCast(subs2.Value());
1066 if (CDSRtmp.IsNull()) continue;
1067 CDSR = CDSRtmp;
1068 }
1069 }
1070 if (CDSR.IsNull()) return L;
1071// if ( STEPConstruct_Assembly::CheckSRRReversesNAUO ( Tool.Model(), CDSR ) ) {
1072// TDF_Label Lsw = L0; L0 = Lref; Lref = Lsw;
1073// }
1074
1075 // iterate on components to find proper one
1076 TDF_LabelSequence seq;
1077 XCAFDoc_ShapeTool::GetComponents ( L0, seq );
1078 for ( Standard_Integer k=1; L.IsNull() && k <= seq.Length(); k++ ) {
1079 TDF_Label Lcomp = seq(k), Lref2;
1080 if ( XCAFDoc_ShapeTool::GetReferredShape ( Lcomp, Lref2 ) &&
1081 Lref2 == Lref &&
1082 S.Location() == XCAFDoc_ShapeTool::GetLocation ( Lcomp ) )
1083 L = Lcomp;
1084 }
1085
1086 return L;
1087}
1088
1089//=======================================================================
1090//function : ReadNames
1091//purpose :
1092//=======================================================================
1093
1094Standard_Boolean STEPCAFControl_Reader::ReadNames (const Handle(XSControl_WorkSession) &WS,
9c3cce7a 1095 Handle(TDocStd_Document)& Doc,
1096 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1097 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
7fd59977 1098{
1099 // get starting data
1100 Handle(Interface_InterfaceModel) Model = WS->Model();
1101 Handle(XSControl_TransferReader) TR = WS->TransferReader();
1102 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1103 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
1104 if ( STool.IsNull() ) return Standard_False;
1105 STEPConstruct_Tool Tool ( WS );
1106
1107 // iterate on model to find all SDRs and CDSRs
1108 Standard_Integer nb = Model->NbEntities();
1109 Handle(Standard_Type) tNAUO = STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence);
1110 Handle(Standard_Type) tPD = STANDARD_TYPE(StepBasic_ProductDefinition);
1111 Handle(TCollection_HAsciiString) name;
1112 TDF_Label L;
1113 for (Standard_Integer i = 1; i <= nb; i++) {
1114 Handle(Standard_Transient) enti = Model->Value(i);
1115
1116 // get description of NAUO
1117 if ( enti->DynamicType() == tNAUO ) {
1118 L.Nullify();
1119 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
9c3cce7a 1120 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(enti);
7fd59977 1121 if(NAUO.IsNull()) continue;
1122 Interface_EntityIterator subs = WS->Graph().Sharings(NAUO);
1123 for (subs.Start(); subs.More(); subs.Next()) {
1124 Handle(StepRepr_ProductDefinitionShape) PDS =
1125 Handle(StepRepr_ProductDefinitionShape)::DownCast(subs.Value());
1126 if(PDS.IsNull()) continue;
1127 Handle(StepBasic_ProductDefinitionRelationship) PDR = PDS->Definition().ProductDefinitionRelationship();
1128 if ( PDR.IsNull() ) continue;
1129 if ( PDR->HasDescription() &&
1130 PDR->Description()->Length() >0 ) name = PDR->Description();
ab4a5554 1131 else if ( !PDR->Name().IsNull() && PDR->Name()->Length() >0 ) name = PDR->Name();
1132 else if ( !PDR->Id().IsNull()) name = PDR->Id();
1133 else name = new TCollection_HAsciiString;
7fd59977 1134 }
1135 // find proper label
1136 L = FindInstance ( NAUO, STool, Tool, PDFileMap, ShapeLabelMap );
1137 if ( L.IsNull() ) continue;
1138 TCollection_ExtendedString str ( name->String() );
1139 TDataStd_Name::Set ( L, str );
1140 }
1141
1142 // for PD get name of associated product
1143 if ( enti->DynamicType() == tPD ) {
1144 L.Nullify();
1145 Handle(StepBasic_ProductDefinition) PD =
9c3cce7a 1146 Handle(StepBasic_ProductDefinition)::DownCast(enti);
7fd59977 1147 if(PD.IsNull()) continue;
9c3cce7a 1148 Handle(StepBasic_Product) Prod = (!PD->Formation().IsNull() ? PD->Formation()->OfProduct() : NULL);
1149 if (Prod.IsNull())
1150 name = new TCollection_HAsciiString;
1151 else if (!Prod->Name().IsNull() && Prod->Name()->UsefullLength() > 0)
1152 name = Prod->Name();
1153 else if (!Prod->Id().IsNull())
1154 name = Prod->Id();
1155 else
1156 name = new TCollection_HAsciiString;
7fd59977 1157 L = GetLabelFromPD ( PD, STool, TP, PDFileMap, ShapeLabelMap );
1158 if ( L.IsNull() ) continue;
1159 TCollection_ExtendedString str ( name->String() );
1160 TDataStd_Name::Set ( L, str );
1161 }
1162 // set a name to the document
1163 //TCollection_ExtendedString str ( name->String() );
1164 //TDataStd_Name::Set ( L, str );
1165 }
1166
1167 return Standard_True;
1168}
1169
1170//=======================================================================
1171//function : GetLabelFromPD
1172//purpose :
1173//=======================================================================
1174
1175static TDF_Label GetLabelFromPD (const Handle(StepBasic_ProductDefinition) &PD,
1176 const Handle(XCAFDoc_ShapeTool) &STool,
1177 const STEPConstruct_ValidationProps &Props,
1178 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1179 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1180{
1181 TDF_Label L;
1182 if ( PDFileMap.IsBound ( PD ) ) {
1183 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find ( PD );
1184 if ( ! EF.IsNull() ) {
1185 L = EF->GetLabel();
1186 if ( ! L.IsNull() ) return L;
1187 }
1188 }
1189 TopoDS_Shape S = Props.GetPropShape ( PD );
1190 if ( S.IsNull() ) return L;
1191 if ( ShapeLabelMap.IsBound ( S ) )
1192 L = ShapeLabelMap.Find ( S );
1193 if ( L.IsNull() )
1194 STool->Search ( S, L, Standard_True, Standard_True, Standard_False );
1195 return L;
1196}
1197
1198//=======================================================================
1199//function : ReadValProps
1200//purpose :
1201//=======================================================================
1202
1203Standard_Boolean STEPCAFControl_Reader::ReadValProps (const Handle(XSControl_WorkSession) &WS,
1204 Handle(TDocStd_Document)& Doc,
1205 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1206 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
1207{
1208 // get starting data
1209 Handle(Interface_InterfaceModel) Model = WS->Model();
1210 Handle(XSControl_TransferReader) TR = WS->TransferReader();
1211 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1212 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
1213 if ( STool.IsNull() ) return Standard_False;
1214
1215 // load props from the STEP model
1216 TColStd_SequenceOfTransient props;
1217 STEPConstruct_ValidationProps Props ( WS );
1218 if ( ! Props.LoadProps ( props ) ) {
0797d9d3 1219#ifdef OCCT_DEBUG
7fd59977 1220 cout << "Warning: no validation props found in the model" << endl;
1221#endif
1222 return Standard_False;
1223 }
1224
1225 // interpret props one by one
1226 for (Standard_Integer i = 1; i <= props.Length(); i ++) {
1227 Handle(StepRepr_PropertyDefinitionRepresentation) PDR =
1228 Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast ( props.Value(i) );
1229 if ( PDR.IsNull() ) continue;
1230
1231 TDF_Label L;
1232
1233 Handle(StepRepr_PropertyDefinition) PD = PDR->Definition().PropertyDefinition();
1234 Interface_EntityIterator subs = Props.Graph().Shareds(PD);
1235 for (subs.Start(); L.IsNull() && subs.More(); subs.Next()) {
1236 if ( subs.Value()->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape)) ) {
1237 Handle(StepRepr_ProductDefinitionShape) PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(subs.Value());
1238 if(PDS.IsNull()) continue;
1239 // find corresponding NAUO
1240 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO;
1241 Interface_EntityIterator subs1 = Props.Graph().Shareds(PDS);
1242 for (subs1.Start(); NAUO.IsNull() && subs1.More(); subs1.Next()) {
1243 if ( subs1.Value()->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence)) )
1244 NAUO = Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs1.Value());
1245 }
1246 if ( !NAUO.IsNull() ) {
1247 L = FindInstance ( NAUO, STool, WS, PDFileMap, ShapeLabelMap );
1248 if ( L.IsNull() ) continue;
1249 }
1250 else {
1251 // find corresponding ProductDefinition:
1252 Handle(StepBasic_ProductDefinition) ProdDef;
1253 Interface_EntityIterator subsPDS = Props.Graph().Shareds(PDS);
1254 for (subsPDS.Start(); ProdDef.IsNull() && subsPDS.More(); subsPDS.Next()) {
1255 if ( subsPDS.Value()->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition)) )
1256 ProdDef = Handle(StepBasic_ProductDefinition)::DownCast(subsPDS.Value());
1257 }
1258 if ( ProdDef.IsNull() ) continue;
1259 L = GetLabelFromPD ( ProdDef, STool, Props, PDFileMap, ShapeLabelMap );
1260 }
1261 }
1262
1263 if ( subs.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect)) ) {
1264 Handle(StepRepr_ShapeAspect) SA = Handle(StepRepr_ShapeAspect)::DownCast(subs.Value());
1265 if(SA.IsNull()) continue;
1266 // find ShapeRepresentation
1267 Handle(StepShape_ShapeRepresentation) SR;
1268 Interface_EntityIterator subs1 = Props.Graph().Sharings(SA);
1269 for(subs1.Start(); subs1.More() && SR.IsNull(); subs1.Next()) {
1270 Handle(StepRepr_PropertyDefinition) PropD1 =
1271 Handle(StepRepr_PropertyDefinition)::DownCast(subs1.Value());
1272 if(PropD1.IsNull()) continue;
1273 Interface_EntityIterator subs2 = Props.Graph().Sharings(PropD1);
1274 for(subs2.Start(); subs2.More() && SR.IsNull(); subs2.Next()) {
1275 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
1276 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs2.Value());
1277 if(SDR.IsNull()) continue;
1278 SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation());
1279 }
1280 }
1281 if(SR.IsNull()) continue;
1282 Handle(Transfer_Binder) binder;
1283 for(Standard_Integer ir=1; ir<=SR->NbItems() && binder.IsNull(); ir++) {
1284 if(SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_SolidModel))) {
1285 Handle(StepShape_SolidModel) SM =
1286 Handle(StepShape_SolidModel)::DownCast(SR->ItemsValue(ir));
1287 binder = TP->Find(SM);
1288 }
1289 else if(SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel))) {
1290 Handle(StepShape_ShellBasedSurfaceModel) SBSM =
1291 Handle(StepShape_ShellBasedSurfaceModel)::DownCast(SR->ItemsValue(ir));
1292 binder = TP->Find(SBSM);
1293 }
1294 else if(SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_GeometricSet))) {
1295 Handle(StepShape_GeometricSet) GS =
1296 Handle(StepShape_GeometricSet)::DownCast(SR->ItemsValue(ir));
1297 binder = TP->Find(GS);
1298 }
1299 }
1300 if ( binder.IsNull() || ! binder->HasResult() ) continue;
1301 TopoDS_Shape S;
1302 S = TransferBRep::ShapeResult ( TP, binder );
1303 if(S.IsNull()) continue;
1304 if ( ShapeLabelMap.IsBound ( S ) )
1305 L = ShapeLabelMap.Find ( S );
1306 if ( L.IsNull() )
1307 STool->Search ( S, L, Standard_True, Standard_True, Standard_True );
1308 }
1309 }
1310
1311 if(L.IsNull()) continue;
1312
1313 // decode validation properties
1314 Handle(StepRepr_Representation) rep = PDR->UsedRepresentation();
1315 for ( Standard_Integer j=1; j <= rep->NbItems(); j++ ) {
1316 Handle(StepRepr_RepresentationItem) ent = rep->ItemsValue(j);
1317 Standard_Boolean isArea;
1318 Standard_Real val;
1319 gp_Pnt pos;
1320 if ( Props.GetPropReal ( ent, val, isArea ) ) {
1321 if ( isArea ) XCAFDoc_Area::Set ( L, val );
1322 else XCAFDoc_Volume::Set ( L, val );
1323 }
1324 else if ( Props.GetPropPnt ( ent, rep->ContextOfItems(), pos ) ) {
1325 XCAFDoc_Centroid::Set ( L, pos );
1326 }
1327 }
1328 }
1329 return Standard_True;
1330}
1331
1332//=======================================================================
1333//function : ReadLayers
1334//purpose :
1335//=======================================================================
1336
1337Standard_Boolean STEPCAFControl_Reader::ReadLayers (const Handle(XSControl_WorkSession) &WS,
1338 Handle(TDocStd_Document)& Doc) const
1339{
1340 Handle(Interface_InterfaceModel) Model = WS->Model();
1341 Handle(XSControl_TransferReader) TR = WS->TransferReader();
1342 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1343 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
1344 if ( STool.IsNull() ) return Standard_False;
1345 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool( Doc->Main() );
1346 if ( LTool.IsNull() ) return Standard_False;
1347
1348 Handle(Standard_Type) tSVPLA = STANDARD_TYPE(StepVisual_PresentationLayerAssignment);
1349 Standard_Integer nb = Model->NbEntities();
1350 Handle(TCollection_HAsciiString) name;
1351
1352 for (Standard_Integer i = 1; i <= nb; i ++) {
1353 Handle(Standard_Transient) enti = Model->Value(i);
1354 if ( ! enti->IsKind ( tSVPLA ) ) continue;
1355 Handle(StepVisual_PresentationLayerAssignment) SVPLA =
1356 Handle(StepVisual_PresentationLayerAssignment)::DownCast(enti);
1357
1358 Handle(TCollection_HAsciiString) descr = SVPLA->Description();
1359 Handle(TCollection_HAsciiString) hName = SVPLA->Name();
1360 TCollection_ExtendedString aLayerName ( hName->String() );
1361
1362 // find a target shape and its label in the document
1363 for (Standard_Integer j = 1; j <= SVPLA->NbAssignedItems(); j++ ) {
1364 StepVisual_LayeredItem LI = SVPLA->AssignedItemsValue(j);
1365 Handle(Transfer_Binder) binder = TP->Find( LI.Value() );
1366 if ( binder.IsNull() || ! binder->HasResult() ) continue;
1367
1368 TopoDS_Shape S = TransferBRep::ShapeResult ( TP, binder );
1369 if ( S.IsNull() ) continue;
1370
1371 TDF_Label shL;
1372 if ( ! STool->Search ( S, shL, Standard_True, Standard_True, Standard_True ) ) continue;
1373 LTool->SetLayer ( shL, aLayerName );
1374 }
1375
1376 // check invisibility
1377 Interface_EntityIterator subs = WS->Graph().Sharings(SVPLA);
1378 for (subs.Start(); subs.More(); subs.Next()) {
1379 if ( ! subs.Value()->IsKind(STANDARD_TYPE(StepVisual_Invisibility)) ) continue;
0797d9d3 1380#ifdef OCCT_DEBUG
7fd59977 1381 cout<< "\tLayer \"" << aLayerName << "\" is invisible"<<endl;
1382#endif
1383 //TDF_Label InvLayerLab = LTool->FindLayer(aLayerName);
1384 TDF_Label InvLayerLab = LTool->AddLayer(aLayerName); //skl for OCC3926
1385 Handle(TDataStd_UAttribute) aUAttr;
1386 aUAttr->Set( InvLayerLab, XCAFDoc::InvisibleGUID() );
1387 }
1388 }
1389 return Standard_True;
1390}
1391
1392//=======================================================================
1393//function : ReadSHUOs
1394//purpose :
1395//=======================================================================
1396
1397static Standard_Boolean findNextSHUOlevel (const Handle(XSControl_WorkSession) &WS,
1398 const Handle(StepRepr_SpecifiedHigherUsageOccurrence)& SHUO,
1399 const Handle(XCAFDoc_ShapeTool)& STool,
1400 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1401 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap,
1402 TDF_LabelSequence& aLabels)
1403{
1404 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings(SHUO);
1405 Handle(StepRepr_SpecifiedHigherUsageOccurrence) subSHUO;
1406 for (subs.Start(); subs.More(); subs.Next()) {
1407 if (subs.Value()->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) {
1408 subSHUO = Handle(StepRepr_SpecifiedHigherUsageOccurrence)::DownCast(subs.Value());
1409 break;
1410 }
1411 }
1412 if (subSHUO.IsNull())
1413 return Standard_False;
1414
1415 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO =
1416 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subSHUO->NextUsage());
1417 if (NUNAUO.IsNull())
1418 return Standard_False;
1419// Handle(Interface_InterfaceModel) Model = WS->Model();
1420// Handle(XSControl_TransferReader) TR = WS->TransferReader();
1421// Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1422// Handle(Transfer_Binder) binder = TP->Find(NUNAUO);
1423// if ( binder.IsNull() || ! binder->HasResult() )
1424// return Standard_False;
1425// TopoDS_Shape NUSh = TransferBRep::ShapeResult ( TP, binder );
1426 // get label of NAUO next level
1427 TDF_Label NULab;
1428 STEPConstruct_Tool Tool( WS );
1429 NULab = STEPCAFControl_Reader::FindInstance ( NUNAUO, STool, Tool, PDFileMap, ShapeLabelMap );
1430// STool->Search(NUSh, NUlab);
1431 if (NULab.IsNull())
1432 return Standard_False;
1433 aLabels.Append( NULab );
1434 // and check by recurse.
1435 findNextSHUOlevel( WS, subSHUO, STool, PDFileMap, ShapeLabelMap, aLabels );
1436 return Standard_True;
1437}
1438
1439
1440//=======================================================================
1441//function : setSHUOintoDoc
1442//purpose : auxilary
1443//=======================================================================
1444static TDF_Label setSHUOintoDoc (const Handle(XSControl_WorkSession) &WS,
1445 const Handle(StepRepr_SpecifiedHigherUsageOccurrence)& SHUO,
1446 const Handle(XCAFDoc_ShapeTool)& STool,
1447 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1448 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1449{
1450 TDF_Label aMainLabel;
1451 // get upper usage NAUO from SHUO.
1452 Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO =
1453 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(SHUO->UpperUsage());
1454 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO =
1455 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(SHUO->NextUsage());
1456 if ( UUNAUO.IsNull() || NUNAUO.IsNull() ) {
0797d9d3 1457#ifdef OCCT_DEBUG
7fd59977 1458 cout << "Warning: " << __FILE__ <<": Upper_usage or Next_usage of styled SHUO is null. Skip it" << endl;
1459#endif
1460 return aMainLabel;
1461 }
1462// Handle(Interface_InterfaceModel) Model = WS->Model();
1463// Handle(XSControl_TransferReader) TR = WS->TransferReader();
1464// Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1465// TopoDS_Shape UUSh, NUSh;
1466// Handle(Transfer_Binder) binder = TP->Find(UUNAUO);
1467// if ( binder.IsNull() || ! binder->HasResult() )
1468// return aMainLabel;
1469// UUSh = TransferBRep::ShapeResult ( TP, binder );
1470// binder = TP->Find(NUNAUO);
1471// if ( binder.IsNull() || ! binder->HasResult() )
1472// return aMainLabel;
1473// NUSh = TransferBRep::ShapeResult ( TP, binder );
1474
1475 // get first labels for first SHUO attribute
1476 TDF_Label UULab, NULab;
1477 STEPConstruct_Tool Tool( WS );
1478 UULab = STEPCAFControl_Reader::FindInstance ( UUNAUO, STool, Tool, PDFileMap, ShapeLabelMap );
1479 NULab = STEPCAFControl_Reader::FindInstance ( NUNAUO, STool, Tool, PDFileMap, ShapeLabelMap );
1480
1481// STool->Search(UUSh, UULab);
1482// STool->Search(NUSh, NULab);
1483 if (UULab.IsNull() || NULab.IsNull()) return aMainLabel;
1484 //create sequence fo labels to set SHUO structure into the document
1485 TDF_LabelSequence ShuoLabels;
1486 ShuoLabels.Append( UULab );
1487 ShuoLabels.Append( NULab );
1488 // add all other labels of sub SHUO entities
1489 findNextSHUOlevel( WS, SHUO, STool, PDFileMap, ShapeLabelMap, ShuoLabels );
1490 // last accord for SHUO
1491 Handle(XCAFDoc_GraphNode) anSHUOAttr;
1492 if ( STool->SetSHUO( ShuoLabels, anSHUOAttr ) )
1493 aMainLabel = anSHUOAttr->Label();
1494
1495 return aMainLabel;
1496}
1497
1498
1499//=======================================================================
1500//function : ReadSHUOs
1501//purpose :
1502//=======================================================================
1503
1504Standard_Boolean STEPCAFControl_Reader::ReadSHUOs (const Handle(XSControl_WorkSession) &WS,
1505 Handle(TDocStd_Document)& Doc,
1506 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1507 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
1508{
1509 // the big part code duplication from ReadColors.
1510 // It is possible to share this code functionality, just to decide how ???
1511 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( Doc->Main() );
1512 Handle(XCAFDoc_ShapeTool) STool = CTool->ShapeTool();
1513
1514 STEPConstruct_Styles Styles ( WS );
1515 if ( ! Styles.LoadStyles() ) {
0797d9d3 1516#ifdef OCCT_DEBUG
7fd59977 1517 cout << "Warning: no styles are found in the model" << endl;
1518#endif
1519 return Standard_False;
1520 }
1521 // searching for invisible items in the model
1522 Handle(TColStd_HSequenceOfTransient) aHSeqOfInvisStyle = new TColStd_HSequenceOfTransient;
1523 Styles.LoadInvisStyles( aHSeqOfInvisStyle );
1524 // parse and search for color attributes
1525 Standard_Integer nb = Styles.NbStyles();
1526 for ( Standard_Integer i=1; i <= nb; i++ ) {
1527 Handle(StepVisual_StyledItem) style = Styles.Style ( i );
1528 if ( style.IsNull() ) continue;
1529
1530 Standard_Boolean IsVisible = Standard_True;
1531 // check the visibility of styled item.
1532 for (Standard_Integer si = 1; si <= aHSeqOfInvisStyle->Length(); si++ ) {
1533 if ( style != aHSeqOfInvisStyle->Value( si ) )
1534 continue;
1535 // found that current style is invisible.
0797d9d3 1536#ifdef OCCT_DEBUG
7fd59977 1537 cout << "Warning: item No " << i << "(" << style->Item()->DynamicType()->Name() << ") is invisible" << endl;
1538#endif
1539 IsVisible = Standard_False;
1540 break;
1541 }
1542
1543 Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol;
1544 // check if it is component style
1545 Standard_Boolean IsComponent = Standard_False;
1546 if ( ! Styles.GetColors ( style, SurfCol, BoundCol, CurveCol, IsComponent ) && IsVisible )
1547 continue;
1548 if (!IsComponent)
1549 continue;
1550 Handle(StepShape_ShapeRepresentation) aSR;
1551 findStyledSR( style, aSR );
1552 // search for SR along model
1553 if ( aSR.IsNull() )
1554 continue;
1555 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings( aSR );
1556 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
1557 for (subs.Start(); subs.More(); subs.Next()) {
1558 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
1559 if ( aSDR.IsNull() )
1560 continue;
1561 StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition();
1562 Handle(StepRepr_ProductDefinitionShape) PDS =
1563 Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition());
1564 if ( PDS.IsNull() )
1565 continue;
1566 StepRepr_CharacterizedDefinition aCharDef = PDS->Definition();
1567 Handle(StepRepr_SpecifiedHigherUsageOccurrence) SHUO =
1568 Handle(StepRepr_SpecifiedHigherUsageOccurrence)::DownCast(aCharDef.ProductDefinitionRelationship());
1569 if ( SHUO.IsNull() )
1570 continue;
1571
1572 // set the SHUO structure to the document
1573 TDF_Label aLabelForStyle = setSHUOintoDoc( WS, SHUO, STool, PDFileMap, ShapeLabelMap );
1574 if ( aLabelForStyle.IsNull() ) {
0797d9d3 1575#ifdef OCCT_DEBUG
7fd59977 1576 cout << "Warning: " << __FILE__ <<": coudnot create SHUO structure in the document" << endl;
1577#endif
1578 continue;
1579 }
1580 // now set the style to the SHUO main label.
1581 if ( ! SurfCol.IsNull() ) {
1582 Quantity_Color col;
1583 Styles.DecodeColor ( SurfCol, col );
1584 CTool->SetColor ( aLabelForStyle, col, XCAFDoc_ColorSurf );
1585 }
1586 if ( ! BoundCol.IsNull() ) {
1587 Quantity_Color col;
1588 Styles.DecodeColor ( BoundCol, col );
1589 CTool->SetColor ( aLabelForStyle, col, XCAFDoc_ColorCurv );
1590 }
1591 if ( ! CurveCol.IsNull() ) {
1592 Quantity_Color col;
1593 Styles.DecodeColor ( CurveCol, col );
1594 CTool->SetColor ( aLabelForStyle, col, XCAFDoc_ColorCurv );
1595 }
1596 if ( !IsVisible )
1597 // sets the invisibility for shape.
1598 CTool->SetVisibility( aLabelForStyle, Standard_False );
1599
1600 } // end search SHUO by SDR
1601 } // end iterates on styles
1602
1603 return Standard_True;
1604}
1605
1606
1607//=======================================================================
1608//function : GetLengthConversionFactor
1609//purpose :
1610//=======================================================================
1611static Standard_Boolean GetLengthConversionFactor(Handle(StepBasic_NamedUnit)& NU,
1612 Standard_Real& afact)
1613{
1614 afact=1.;
1615 if( !NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit)) ) return Standard_False;
1616 Handle(StepBasic_ConversionBasedUnitAndLengthUnit) CBULU =
1617 Handle(StepBasic_ConversionBasedUnitAndLengthUnit)::DownCast(NU);
1618 Handle(StepBasic_MeasureWithUnit) MWUCBU = CBULU->ConversionFactor();
1619 afact = MWUCBU->ValueComponent();
1620 StepBasic_Unit anUnit2 = MWUCBU->UnitComponent();
1621 if(anUnit2.CaseNum(anUnit2.Value())==1) {
1622 Handle(StepBasic_NamedUnit) NU2 = anUnit2.NamedUnit();
1623 if(NU2->IsKind(STANDARD_TYPE(StepBasic_SiUnit))) {
1624 Handle(StepBasic_SiUnit) SU = Handle(StepBasic_SiUnit)::DownCast(NU2);
1625 if(SU->Name()==StepBasic_sunMetre) {
1626 if(SU->HasPrefix())
1c9d3225 1627 afact *= STEPConstruct_UnitContext::ConvertSiPrefix (SU->Prefix());
1628 // convert m to mm
1629 afact *= 1000.;
7fd59977 1630 }
1631 }
1632 }
1633 return Standard_True;
1634}
1635
1636
1c9d3225 1637//=======================================================================
1638//function : GetAngleConversionFactor
1639//purpose :
1640//=======================================================================
1641static Standard_Boolean GetAngleConversionFactor(Handle(StepBasic_NamedUnit)& NU,
1642 Standard_Real& afact)
1643{
1644 afact=1.;
1645 if( !NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndPlaneAngleUnit)) ) return Standard_False;
1646 Handle(StepBasic_ConversionBasedUnitAndPlaneAngleUnit) CBULU =
1647 Handle(StepBasic_ConversionBasedUnitAndPlaneAngleUnit)::DownCast(NU);
1648 Handle(StepBasic_MeasureWithUnit) MWUCBU = CBULU->ConversionFactor();
1649 afact = MWUCBU->ValueComponent();
1650 StepBasic_Unit anUnit2 = MWUCBU->UnitComponent();
1651 if(anUnit2.CaseNum(anUnit2.Value())==1) {
1652 Handle(StepBasic_NamedUnit) NU2 = anUnit2.NamedUnit();
1653 if(NU2->IsKind(STANDARD_TYPE(StepBasic_SiUnit))) {
1654 Handle(StepBasic_SiUnit) SU = Handle(StepBasic_SiUnit)::DownCast(NU2);
1655 if(SU->Name()==StepBasic_sunRadian) {
1656 if(SU->HasPrefix())
1657 afact *= STEPConstruct_UnitContext::ConvertSiPrefix (SU->Prefix());
1658 // convert radian to deg
1659 afact *= 180/M_PI;
1660 }
1661 }
1662 }
1663 return Standard_True;
1664}
1665
7fd59977 1666//=======================================================================
1667//function : GetMassConversionFactor
1668//purpose :
1669//=======================================================================
1670static Standard_Boolean GetMassConversionFactor(Handle(StepBasic_NamedUnit)& NU,
1671 Standard_Real& afact)
1672{
1673 afact=1.;
1674 if( !NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit)) ) return Standard_False;
1675 Handle(StepBasic_ConversionBasedUnitAndMassUnit) CBUMU =
1676 Handle(StepBasic_ConversionBasedUnitAndMassUnit)::DownCast(NU);
1677 Handle(StepBasic_MeasureWithUnit) MWUCBU = CBUMU->ConversionFactor();
1678 afact = MWUCBU->ValueComponent();
1679 StepBasic_Unit anUnit2 = MWUCBU->UnitComponent();
1680 if(anUnit2.CaseNum(anUnit2.Value())==1) {
1681 Handle(StepBasic_NamedUnit) NU2 = anUnit2.NamedUnit();
1682 if(NU2->IsKind(STANDARD_TYPE(StepBasic_SiUnit))) {
1683 Handle(StepBasic_SiUnit) SU = Handle(StepBasic_SiUnit)::DownCast(NU2);
1684 if(SU->Name()==StepBasic_sunGram) {
1685 if(SU->HasPrefix())
1c9d3225 1686 afact *= STEPConstruct_UnitContext::ConvertSiPrefix (SU->Prefix());
7fd59977 1687 }
1688 }
1689 }
1690 return Standard_True;
1691}
1692
1693
1694//=======================================================================
1695//function : ReadDatums
1696//purpose : auxilary
1697//=======================================================================
1698static Standard_Boolean ReadDatums(const Handle(XCAFDoc_ShapeTool) &STool,
1699 const Handle(XCAFDoc_DimTolTool) &DGTTool,
1700 const Interface_Graph &graph,
1701 Handle(Transfer_TransientProcess) &TP,
1702 const TDF_Label TolerL,
1703 const Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR)
1704{
1705 if(GTWDR.IsNull()) return Standard_False;
1706 Handle(StepDimTol_HArray1OfDatumReference) HADR = GTWDR->DatumSystem();
1707 if(HADR.IsNull()) return Standard_False;
1708 for(Standard_Integer idr=1; idr<=HADR->Length(); idr++) {
1709 Handle(StepDimTol_DatumReference) DR = HADR->Value(idr);
1710 Handle(StepDimTol_Datum) aDatum = DR->ReferencedDatum();
1711 if(aDatum.IsNull()) continue;
1712 Interface_EntityIterator subs4 = graph.Sharings(aDatum);
1713 for(subs4.Start(); subs4.More(); subs4.Next()) {
1714 Handle(StepRepr_ShapeAspectRelationship) SAR =
1715 Handle(StepRepr_ShapeAspectRelationship)::DownCast(subs4.Value());
1716 if(SAR.IsNull()) continue;
1717 Handle(StepDimTol_DatumFeature) DF =
1718 Handle(StepDimTol_DatumFeature)::DownCast(SAR->RelatingShapeAspect());
1719 if(DF.IsNull()) continue;
1720 Interface_EntityIterator subs5 = graph.Sharings(DF);
1721 Handle(StepRepr_PropertyDefinition) PropDef;
1722 for(subs5.Start(); subs5.More() && PropDef.IsNull(); subs5.Next()) {
1723 PropDef = Handle(StepRepr_PropertyDefinition)::DownCast(subs5.Value());
1724 }
1725 if(PropDef.IsNull()) continue;
1726 Handle(StepShape_AdvancedFace) AF;
1727 subs5 = graph.Sharings(PropDef);
1728 for(subs5.Start(); subs5.More(); subs5.Next()) {
1729 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
1730 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs5.Value());
1731 if(!SDR.IsNull()) {
1732 Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation();
1733 if( !Repr.IsNull() && Repr->NbItems()>0 ) {
1734 Handle(StepRepr_RepresentationItem) RI = Repr->ItemsValue(1);
1735 AF = Handle(StepShape_AdvancedFace)::DownCast(RI);
1736 }
1737 }
1738 }
1739 if(AF.IsNull()) return Standard_False;
1740 Standard_Integer index = TP->MapIndex(AF);
1741 TopoDS_Shape aSh;
1742 if(index >0) {
1743 Handle(Transfer_Binder) binder = TP->MapItem(index);
1744 aSh = TransferBRep::ShapeResult(binder);
1745 }
1746 if(aSh.IsNull()) continue;
1747 TDF_Label shL;
1748 if( !STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
1749 DGTTool->SetDatum(shL,TolerL,PropDef->Name(),PropDef->Description(),aDatum->Identification());
1750 }
1751 }
1752 return Standard_True;
1753}
1754
1755
1756//=======================================================================
1c9d3225 1757//function : setDatumToXCAF
7fd59977 1758//purpose :
1759//=======================================================================
1c9d3225 1760static Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
1761 const TDF_Label theGDTL,
1762 const Standard_Integer thePositionCounter,
1763 const XCAFDimTolObjects_DatumModifiersSequence& aXCAFModifiers,
1764 const XCAFDimTolObjects_DatumModifWithValue aXCAFModifWithVal,
1765 const Standard_Real aModifValue,
1766 const Handle(TDocStd_Document)& theDoc,
1767 const Handle(XSControl_WorkSession)& theWS)
7fd59977 1768{
1c9d3225 1769 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( theDoc->Main() );
1770 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool( theDoc->Main() );
1771 Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
1772 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
1773 const Interface_Graph& aGraph = aTP->Graph();
1774 Handle(XCAFDoc_Datum) aDat;
1775 TDF_Label aShL;
1776 Standard_Boolean aRefShapeIsFound = Standard_False;
1777 Standard_Boolean aFirstStep = Standard_True;
1778 Interface_EntityIterator anIterD = aGraph.Sharings(theDat);
1779 for(anIterD.Start(); anIterD.More(); anIterD.Next()) {
1780 Handle(StepRepr_ShapeAspectRelationship) aSAR =
1781 Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIterD.Value());
1782 if(aSAR.IsNull()) continue;
1783
1784 Handle(StepRepr_ShapeAspect) aSA = aSAR->RelatingShapeAspect();
1785 if (aSA.IsNull()) continue;
1786 Handle(StepAP242_GeometricItemSpecificUsage) aPGISU;
1787 if(aSA->IsKind(STANDARD_TYPE(StepRepr_CompShAspAndDatumFeatAndShAsp)))
1788 {
1789 //processing for complex entity
1790 Interface_EntityIterator anIterC = aGraph.Sharings(aSA);
1791 for(anIterC.Start(); anIterC.More(); anIterC.Next()) {
1792 Handle(StepRepr_ShapeAspectRelationship) SAR =
1793 Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIterC.Value());
1794 if(SAR.IsNull()) continue;
1795 Handle(StepRepr_ShapeAspect) aS =
1796 Handle(StepRepr_ShapeAspect)::DownCast(SAR->RelatedShapeAspect());
1797 if(aS.IsNull()) continue;
1798 Interface_EntityIterator anIterSA = aGraph.Sharings(aS);
1799 for(anIterSA.Start(); anIterSA.More() && aPGISU.IsNull(); anIterSA.Next()) {
1800 aPGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterSA.Value());
1801 }
1802 if(!aPGISU.IsNull()){
1803 aSA = aS;
1804 break;
1805 }
7fd59977 1806 }
1c9d3225 1807 }
1808 else if(aSA->IsKind(STANDARD_TYPE(StepDimTol_PlacedDatumTargetFeature)))
1809 {
1810 //processing for datum target
1811 Interface_EntityIterator anIterDTF = aGraph.Shareds(aSA);
1812 for(anIterDTF.Start(); anIterDTF.More(); anIterDTF.Next()) {
1813 if(anIterDTF.Value()->IsKind(STANDARD_TYPE(StepRepr_FeatureForDatumTargetRelationship)))
1814 {
1815 Interface_EntityIterator anIterFFD = aGraph.Shareds(anIterDTF.Value());
1816 for(anIterFFD.Start(); anIterFFD.More(); anIterFFD.Next()) {
1817 if(anIterFFD.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect)))
1818 {
1819 aSA = Handle(StepRepr_ShapeAspect)::DownCast(anIterFFD.Value());
1820 }
7fd59977 1821 }
1822 }
1823 }
1c9d3225 1824 }
1825 if (aSA.IsNull()) continue;
1826 Interface_EntityIterator anIterDSWP = aGraph.Sharings(aSA);
1827 for(anIterDSWP.Start(); anIterDSWP.More() && aPGISU.IsNull(); anIterDSWP.Next()) {
1828 aPGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterDSWP.Value());
1829 }
1830 if(aPGISU.IsNull()) continue;
1831 // get representation item
1832 Handle(StepRepr_RepresentationItem) aRI;
1833 for(Standard_Integer i = 1 ; i <= aPGISU->NbIdentifiedItem() && aRI.IsNull(); i++)
1834 {
1835 aRI = Handle(StepRepr_RepresentationItem)::DownCast(aPGISU->IdentifiedItemValue(i));
1836 }
1837 if(aRI.IsNull()) continue;
1838 Standard_Integer index = aTP->MapIndex(aRI);
1839 TopoDS_Shape aSh;
1840 if(index >0) {
1841 Handle(Transfer_Binder) binder = aTP->MapItem(index);
1842 aSh = TransferBRep::ShapeResult(binder);
1843 }
1844 if(aSh.IsNull()) continue;
1845 if( !aSTool->Search(aSh, aShL, Standard_True, Standard_True, Standard_True) ) continue;
1846 Handle(TDataStd_TreeNode) aNode;
1847 if(aFirstStep && aShL.FindAttribute(XCAFDoc::DatumRefGUID(),aNode) && aNode->HasFirst() &&
1848 aNode->First()->Label().FindAttribute(XCAFDoc_Datum::GetID(),aDat))
1849 {
1850 //if datums already attached, not need add datum target
1851 aRefShapeIsFound = Standard_True;
1852 }
1853 aFirstStep = Standard_False;
1854 Handle(XCAFDimTolObjects_DatumObject) aDatObj;
1855 if(aSA->IsKind(STANDARD_TYPE(StepDimTol_PlacedDatumTargetFeature)))
1856 {
1857 if(!aRefShapeIsFound)
1858 {
1859 //if datum targers not yet added
1860 TDF_Label aDatL = aDGTTool->AddDatum();
1861 aDat = XCAFDoc_Datum::Set(aDatL);
1862 aDGTTool->SetDatum(aShL, aDatL);
1863 aDatObj = aDat->GetObject();
1864 aDatObj->SetName(theDat->Identification());
1865 aDatObj->IsDatumTarget(Standard_True);
1866 XCAFDimTolObjects_DatumTargetType aType;
1867 if(STEPConstruct_GDTProperty::GetDatumTargetType(aSA->Description(),aType))
1868 {
1869 aDatObj->SetDatumTargetType(aType);
1870 if(aType == XCAFDimTolObjects_DatumTargetType_Area)
1871 {
1872 Interface_EntityIterator anIterDTF = aGraph.Shareds(aSA);
1873 for(anIterDTF.Start(); anIterDTF.More(); anIterDTF.Next()) {
1874 if(anIterDTF.Value()->IsKind(STANDARD_TYPE(StepAP242_GeometricItemSpecificUsage)))
1875 {
1876 Handle(StepAP242_GeometricItemSpecificUsage) aGISU
1877 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterDSWP.Value());
1878 Handle(StepRepr_RepresentationItem) aRI;
1879 if(aPGISU->NbIdentifiedItem() > 0) {
1880 aRI = Handle(StepRepr_RepresentationItem)::DownCast(aPGISU->IdentifiedItemValue(1));
1881 }
1882 if(aRI.IsNull()) continue;
1883 Standard_Integer index = aTP->MapIndex(aRI);
1884 TopoDS_Shape aSh;
1885 if(index >0) {
1886 Handle(Transfer_Binder) binder = aTP->MapItem(index);
1887 aSh = TransferBRep::ShapeResult(binder);
1888 aDatObj->SetDatumTarget(aSh);
1889 }
1890 }
1891 }
1892 }
1893 else
1894 {
1895 Interface_EntityIterator anIterDTF = aGraph.Shareds(aSA);
1896 for(anIterDTF.Start(); anIterDTF.More(); anIterDTF.Next()) {
1897 if(anIterDTF.Value()->IsKind(STANDARD_TYPE(StepRepr_PropertyDefinition)))
1898 {
1899 Interface_EntityIterator anIterPD = aGraph.Shareds(anIterDTF.Value());
1900 for(anIterPD.Start(); anIterPD.More(); anIterPD.Next()) {
1901 if(anIterPD.Value()->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation)))
1902 {
1903 Interface_EntityIterator anIterSDR = aGraph.Sharings(anIterPD.Value());
1904 for(anIterSDR.Start(); anIterSDR.More(); anIterSDR.Next()) {
1905 if(anIterSDR.Value()->IsKind(STANDARD_TYPE(StepShape_ShapeRepresentationWithParameters)))
1906 {
1907 Handle(StepShape_ShapeRepresentationWithParameters) aSRWP
1908 = Handle(StepShape_ShapeRepresentationWithParameters)::DownCast(anIterSDR.Value());
1909 for(Standard_Integer r = aSRWP->Items()->Lower(); r <= aSRWP->Items()->Upper(); r++)
1910 {
1911 if(aSRWP->ItemsValue(r)->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
1912 {
1913 Handle(StepGeom_Axis2Placement3d) anAx
1914 = Handle(StepGeom_Axis2Placement3d)::DownCast(aSRWP->ItemsValue(r));
1915 Handle(TColStd_HArray1OfReal) aDirArr = anAx->Axis()->DirectionRatios();
1916 Handle(TColStd_HArray1OfReal) aDirRArr = anAx->RefDirection()->DirectionRatios();
1917 Handle(TColStd_HArray1OfReal) aLocArr = anAx->Location()->Coordinates();
1918 gp_Dir aDir;
1919 gp_Dir aDirR;
1920 gp_Pnt aPnt;
1921 if(!aDirArr.IsNull() && aDirArr->Length() > 2 &&
1922 !aDirRArr.IsNull() && aDirRArr->Length() > 2 &&
1923 !aLocArr.IsNull() && aLocArr->Length() > 2)
1924 {
1925 aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower()+1, aDirArr->Lower()+2);
1926 aDirR.SetCoord(aDirRArr->Lower(), aDirRArr->Lower()+1, aDirRArr->Lower()+2);
1927 aPnt.SetCoord(aLocArr->Lower(), aLocArr->Lower()+1, aLocArr->Lower()+2);
1928 gp_Ax2 anA(aPnt, aDir, aDirR);
1929 aDatObj->SetDatumTargetAxis(anA);
1930 }
1931 }
1932 else if(aSRWP->ItemsValue(r)->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit)))
1933 {
1934 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) aM =
1935 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(aSRWP->ItemsValue(r));
1936 Standard_Real aVal = aM->GetMeasureWithUnit()->ValueComponent();
1937 StepBasic_Unit anUnit = aM->GetMeasureWithUnit()->UnitComponent();
1938 Standard_Real aFact=1.;
1939 if(anUnit.IsNull()) continue;
1940 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
1941 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
1942 if(GetLengthConversionFactor(NU,aFact)) aVal=aVal*aFact;
1943 if(aM->Name()->String().IsEqual("target length") ||
1944 aM->Name()->String().IsEqual("target diameter"))
1945 aDatObj->SetDatumTargetLength(aVal);
1946 else
1947 aDatObj->SetDatumTargetWidth(aVal);
1948 }
1949 }
1950 }
7fd59977 1951 }
1952 }
1c9d3225 1953 }
1954 }
1955 }
1956 }
1957 }
1958 }
1959 }
1960 else
1961 {
1962 //processing for darum feature
1963 TDF_Label aDatL = aDGTTool->AddDatum();
1964 aDat = XCAFDoc_Datum::Set(aDatL);
1965 aDGTTool->SetDatum(aShL, aDatL);
1966 aDatObj = aDat->GetObject();
1967 aDatObj->SetName(theDat->Identification());
1968 aDatObj->SetPosition (thePositionCounter);
1969 if(!aXCAFModifiers.IsEmpty())
1970 aDatObj->SetModifiers(aXCAFModifiers);
1971 if (aXCAFModifWithVal != XCAFDimTolObjects_DatumModifWithValue_None)
1972 aDatObj->SetModifierWithValue(aXCAFModifWithVal, aModifValue);
1973 aDGTTool->SetDatumToGeomTol(aDatL, theGDTL);
1974 }
1975 if(!aDatObj.IsNull())
1976 aDat->SetObject(aDatObj);
1977 }
1978 return !aDat.IsNull();
1979}
1980
1981
1982//=======================================================================
1983//function : ReadDatums
1984//purpose : auxilary
1985//=======================================================================
1986static Standard_Boolean readDatumsAP242(const Handle(Standard_Transient)& theEnt,
1987 const TDF_Label theGDTL,
1988 const Handle(TDocStd_Document)& theDoc,
1989 const Handle(XSControl_WorkSession)& theWS)
1990{
1991 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( theDoc->Main() );
1992 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool( theDoc->Main() );
1993 Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
1994 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
1995 const Interface_Graph& aGraph = aTP->Graph();
1996
1997 Interface_EntityIterator anIter = aGraph.Shareds(theEnt);
1998 for(anIter.Start(); anIter.More(); anIter.Next()) {
1999 Handle(Standard_Transient) anAtr = anIter.Value();
2000 if(anAtr->IsKind(STANDARD_TYPE(StepDimTol_DatumSystem)))
2001 {
2002 Standard_Integer aPositionCounter = 0;//position on frame
2003 Handle(StepDimTol_DatumSystem) aDS = Handle(StepDimTol_DatumSystem)::DownCast(anAtr);
2004 Interface_EntityIterator anIterDS = aGraph.Sharings(aDS);
2005 for(anIterDS.Start(); anIterDS.More(); anIterDS.Next()) {
2006 Handle(Standard_Transient) anAtrDS = anIterDS.Value();
2007 if(anAtrDS->IsKind(STANDARD_TYPE(StepAP242_GeometricItemSpecificUsage)))
2008 {
2009 //get axis
2010 Handle(StepAP242_GeometricItemSpecificUsage)aAxGISUI
2011 = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anAtrDS);
2012 if (aAxGISUI->IdentifiedItemValue(1)->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
2013 {
2014 Handle(StepGeom_Axis2Placement3d) anAx
2015 = Handle(StepGeom_Axis2Placement3d)::DownCast(aAxGISUI->IdentifiedItemValue(1));
2016 Handle(XCAFDoc_GeomTolerance) aTol;
2017 if(theGDTL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aTol))
2018 {
2019 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aTol->GetObject();
2020 Handle(TColStd_HArray1OfReal) aDirArr = anAx->Axis()->DirectionRatios();
2021 Handle(TColStd_HArray1OfReal) aDirRArr = anAx->RefDirection()->DirectionRatios();
2022 Handle(TColStd_HArray1OfReal) aLocArr = anAx->Location()->Coordinates();
2023 gp_Dir aDir;
2024 gp_Dir aDirR;
2025 gp_Pnt aPnt;
2026 if(!aDirArr.IsNull() && aDirArr->Length() > 2 &&
2027 !aDirRArr.IsNull() && aDirRArr->Length() > 2 &&
2028 !aLocArr.IsNull() && aLocArr->Length() > 2)
2029 {
2030 aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower()+1, aDirArr->Lower()+2);
2031 aDirR.SetCoord(aDirRArr->Lower(), aDirRArr->Lower()+1, aDirRArr->Lower()+2);
2032 aPnt.SetCoord(aLocArr->Lower(), aLocArr->Lower()+1, aLocArr->Lower()+2);
2033 gp_Ax2 anA(aPnt, aDir, aDirR);
2034 anObj->SetAxis(anA);
2035 aTol->SetObject(anObj);
2036 }
2037 }
2038 }
2039 }
2040 }
2041 if (aDS->NbConstituents() > 0)
2042 {
2043 //get datum feature and datum target from datum system
2044 Handle(StepDimTol_HArray1OfDatumReferenceCompartment) aDRCA = aDS->Constituents();
2045 if(!aDRCA.IsNull())
2046 {
2047 for(Standard_Integer i = aDRCA->Lower(); i <= aDRCA->Upper(); i++)
2048 {
2049 Handle(StepDimTol_DatumReferenceCompartment) aDRC
2050 = Handle(StepDimTol_DatumReferenceCompartment)::DownCast(aDRCA->Value(i));
2051 //gete modifiers
2052 Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModif = aDRC->Modifiers();
2053 XCAFDimTolObjects_DatumModifiersSequence aXCAFModifiers;
2054 XCAFDimTolObjects_DatumModifWithValue aXCAFModifWithVal = XCAFDimTolObjects_DatumModifWithValue_None;
2055 Standard_Real aModifValue = 0;
2056 if(!aModif.IsNull())
2057 {
2058 for(Standard_Integer m = aModif->Lower(); m <= aModif->Upper(); m++)
2059 {
2060 if(aModif->Value(m).CaseNumber() == 2)
2061 aXCAFModifiers.Append(
2062 (XCAFDimTolObjects_DatumSingleModif)aModif->Value(m).
2063 SimpleDatumReferenceModifierMember()->Value());
2064 else if (aModif->Value(m).CaseNumber() == 1)
2065 {
2066 aXCAFModifWithVal = (XCAFDimTolObjects_DatumModifWithValue)(aModif->Value(m).DatumReferenceModifierWithValue()->ModifierType() + 1);
2067 Standard_Real aVal = aModif->Value(m).DatumReferenceModifierWithValue()->ModifierValue()->ValueComponent();
2068 StepBasic_Unit anUnit = aModif->Value(m).DatumReferenceModifierWithValue()->ModifierValue()->UnitComponent();
2069 Standard_Real aFact=1.;
2070 if(anUnit.IsNull()) continue;
2071 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2072 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2073 if(GetLengthConversionFactor(NU,aFact)) aVal=aVal*aFact;
2074 aModifValue = aVal;
2075 }
2076 }
2077 }
2078 aPositionCounter++;
2079 Interface_EntityIterator anIterDRC = aGraph.Shareds(aDRC);
2080 for(anIterDRC.Start(); anIterDRC.More(); anIterDRC.Next()) {
2081
2082 if(anIterDRC.Value()->IsKind(STANDARD_TYPE(StepDimTol_Datum)))
2083 {
2084 Handle(StepDimTol_Datum) aD = Handle(StepDimTol_Datum)::DownCast(anIterDRC.Value());
2085 setDatumToXCAF(aD, theGDTL, aPositionCounter, aXCAFModifiers, aXCAFModifWithVal, aModifValue,theDoc, theWS);
2086 }
2087 else if(anIterDRC.Value()->IsKind(STANDARD_TYPE(StepDimTol_DatumReferenceElement)))
2088 {
2089 Handle(StepDimTol_DatumReferenceElement) aDRE
2090 = Handle(StepDimTol_DatumReferenceElement)::DownCast(anIterDRC.Value());
2091 //get modifiers from group of datums
2092 Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModifE = aDRE->Modifiers();
2093 if(!aModifE.IsNull())
2094 {
2095 for(Standard_Integer k = aModifE->Lower(); k <= aModifE->Upper(); k++)
2096 {
2097 if(aModifE->Value(k).CaseNumber() == 1)
2098 aXCAFModifiers.Append(
2099 (XCAFDimTolObjects_DatumSingleModif)aModifE->Value(k).
2100 SimpleDatumReferenceModifierMember()->Value());
2101 else if (aModifE->Value(k).CaseNumber() == 2)
2102 {
2103 aXCAFModifWithVal = (XCAFDimTolObjects_DatumModifWithValue)(aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierType() + 1);
2104 Standard_Real aVal = aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierValue()->ValueComponent();
2105 StepBasic_Unit anUnit = aModifE->Value(k).DatumReferenceModifierWithValue()->ModifierValue()->UnitComponent();
2106 Standard_Real aFact=1.;
7fd59977 2107 if(anUnit.IsNull()) continue;
2108 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2109 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
1c9d3225 2110 if(GetLengthConversionFactor(NU,aFact)) aVal=aVal*aFact;
2111 aModifValue = aVal;
7fd59977 2112 }
2113 }
2114 }
1c9d3225 2115 Interface_EntityIterator anIterDRE = aGraph.Shareds(aDRE);
2116 for(anIterDRE.Start(); anIterDRE.More(); anIterDRE.Next()) {
2117 if(anIterDRE.Value()->IsKind(STANDARD_TYPE(StepDimTol_Datum)))
2118 {
2119 Handle(StepDimTol_Datum) aD = Handle(StepDimTol_Datum)::DownCast(anIterDRE.Value());
2120 setDatumToXCAF(aD, theGDTL, aPositionCounter, aXCAFModifiers, aXCAFModifWithVal, aModifValue,theDoc, theWS);
2121 }
2122 }
7fd59977 2123 }
2124 }
2125 }
1c9d3225 2126 }
2127 }
2128 }
2129 }
2130 return Standard_True;
2131}
2132
2133//=======================================================================
2134//function : craeteGeomTolObjectInXCAF
2135//purpose :
2136//=======================================================================
2137static TDF_Label createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt,
2138 const Handle(TDocStd_Document)& theDoc,
2139 const Handle(XSControl_WorkSession)& theWS)
2140{
2141 TDF_Label aGDTL;
2142 if(!theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) &&
2143 !theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) &&
2144 !theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
2145 {
2146 return aGDTL;
2147 }
2148
2149 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( theDoc->Main() );
2150 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool( theDoc->Main() );
2151 Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
2152 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
2153 const Interface_Graph& aGraph = aTP->Graph();
2154 Standard_Boolean isAllAround = Standard_False;
2155 Standard_Boolean isAllOver = Standard_False;
2156
2157 // find RepresentationItem for current Ent
2158 NCollection_Sequence<Handle(Standard_Transient)> aSeqRI1, aSeqRI2;
2159
2160 Interface_EntityIterator anIter = aGraph.Shareds(theEnt);
2161 for(anIter.Start(); anIter.More(); anIter.Next()) {
2162 Handle(Standard_Transient) anAtr = anIter.Value();
2163 NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSAs;
2164 if(anAtr->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape)))
2165 {
2166 //if associating tolerances with part (All-Over)
2167 Interface_EntityIterator anIterSDR = aGraph.Sharings(anAtr);
2168 for(anIterSDR.Start(); anIterSDR.More(); anIterSDR.Next())
2169 {
2170 Handle(Standard_Transient) anAtrSDR = anIterSDR.Value();
2171 if(anAtrSDR->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation)))
2172 {
2173 isAllOver = Standard_True;
2174 Interface_EntityIterator anIterABSR = aGraph.Shareds(anAtrSDR);
2175 for(anIterABSR.Start(); anIterABSR.More(); anIterABSR.Next())
2176 {
2177 Handle(Standard_Transient) anAtrABSR = anIterABSR.Value();
2178 if(anAtrABSR->IsKind(STANDARD_TYPE(StepShape_AdvancedBrepShapeRepresentation)))
2179 {
2180 aSeqRI1.Append(anAtrABSR);
2181 }
7fd59977 2182 }
7fd59977 2183 }
1c9d3225 2184 }
2185 }
2186 else if(anAtr->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
2187 anAtr->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)))
2188 {
2189 //if tolerance attached to dimension
2190 Interface_EntityIterator anIterDim = aGraph.Shareds(anAtr);
2191 for(anIterDim.Start(); anIterDim.More(); anIterDim.Next())
2192 {
2193 Handle(Standard_Transient) anAtrDim = anIterDim.Value();
2194 if(anAtrDim->IsKind(STANDARD_TYPE(StepRepr_CompositeShapeAspect)) ||
2195 anAtrDim->IsKind(STANDARD_TYPE(StepRepr_CompShAspAndDatumFeatAndShAsp)))
2196 {
2197 Interface_EntityIterator anIterCSA = aGraph.Sharings(anAtrDim);
2198 for(anIterCSA.Start(); anIterCSA.More(); anIterCSA.Next()) {
2199 if (anIterCSA.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspectRelationship))){
2200 Interface_EntityIterator anIterSAR = aGraph.Shareds(anIterCSA.Value());
2201 for(anIterSAR.Start(); anIterSAR.More(); anIterSAR.Next()) {
2202 if (anIterSAR.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect))){
2203 aSAs.Append(Handle(StepRepr_ShapeAspect)::DownCast(anIterSAR.Value()));
2204 }
2205 }
2206 }
7fd59977 2207 }
1c9d3225 2208 }
2209 else if(anAtrDim->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect)))
2210 {
2211 aSAs.Append( Handle(StepRepr_ShapeAspect)::DownCast(anAtrDim));
2212 }
2213 }
2214 }
2215 else if(anAtr->IsKind(STANDARD_TYPE(StepRepr_CompositeShapeAspect)) ||
2216 anAtr->IsKind(STANDARD_TYPE(StepRepr_CompShAspAndDatumFeatAndShAsp)))
2217 {
2218 //processing for composite entity
2219 Handle(Standard_Transient) anAtrTmp = anAtr;
2220 if(anAtr->IsKind(STANDARD_TYPE(StepRepr_AllAroundShapeAspect)))
2221 {
2222 // if applyed AllAround Modifier
2223 isAllAround = Standard_True;
2224 Interface_EntityIterator anIterAASA = aGraph.Sharings(anAtrTmp);
2225 for(anIterAASA.Start(); anIterAASA.More(); anIterAASA.Next()) {
2226 if (anIterAASA.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspectRelationship))){
2227 Interface_EntityIterator anIterSAR = aGraph.Shareds(anIterAASA.Value());
2228 for(anIterSAR.Start(); anIterSAR.More(); anIterSAR.Next()) {
2229 if ((anIterSAR.Value()->IsKind(STANDARD_TYPE(StepRepr_CompositeShapeAspect)) ||
2230 anIterSAR.Value()->IsKind(STANDARD_TYPE(StepRepr_CompShAspAndDatumFeatAndShAsp))) &&
2231 anAtrTmp != anIterSAR.Value()){
2232 anAtrTmp = anIterSAR.Value();
2233 break;
2234 }
7fd59977 2235 }
1c9d3225 2236 }
2237 }
2238 }
2239 Interface_EntityIterator anIterCSA = aGraph.Sharings(anAtrTmp);
2240 for(anIterCSA.Start(); anIterCSA.More(); anIterCSA.Next()) {
2241 if (anIterCSA.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspectRelationship))){
2242 Interface_EntityIterator anIterSAR = aGraph.Shareds(anIterCSA.Value());
2243 for(anIterSAR.Start(); anIterSAR.More(); anIterSAR.Next()) {
2244 if (anIterSAR.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect))){
2245 aSAs.Append(Handle(StepRepr_ShapeAspect)::DownCast(anIterSAR.Value()));
7fd59977 2246 }
2247 }
1c9d3225 2248 }
2249 }
2250 }
2251 else if(anAtr->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect)))
2252 {
2253 //default
2254 aSAs.Append( Handle(StepRepr_ShapeAspect)::DownCast(anAtr));
2255 }
2256 if(!aSAs.IsEmpty())
2257 {
2258 //get representation items
2259 NCollection_Sequence<Handle(Standard_Transient)> aSeqRI;
2260 for(Standard_Integer i = aSAs.Lower(); i <= aSAs.Upper(); i++)
2261 {
2262 Interface_EntityIterator anIterSA = aGraph.Sharings(aSAs.Value(i));
2263 Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
2264 Handle(StepRepr_PropertyDefinition) PropD;
2265 for(anIterSA.Start(); anIterSA.More() && aGISU.IsNull() && PropD.IsNull(); anIterSA.Next()) {
2266 aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterSA.Value());
2267 PropD = Handle(StepRepr_PropertyDefinition)::DownCast(anIterSA.Value());
2268 }
2269 if(!PropD.IsNull())//for old version
2270 {
2271 Handle(StepRepr_RepresentationItem) RI;
2272 Interface_EntityIterator subs4 = aGraph.Sharings(PropD);
2273 for(subs4.Start(); subs4.More(); subs4.Next()) {
2274 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
2275 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs4.Value());
2276 if(!SDR.IsNull()) {
2277 Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation();
2278 if( !Repr.IsNull() && Repr->NbItems()>0 ) {
2279 RI = Repr->ItemsValue(1);
2280 }
2281 }
7fd59977 2282 }
1c9d3225 2283 if(RI.IsNull()) continue;
2284
2285 if(theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) {
2286 // read dimensions
2287 Handle(StepShape_EdgeCurve) EC = Handle(StepShape_EdgeCurve)::DownCast(RI);
2288 if(EC.IsNull()) continue;
2289 Handle(TCollection_HAsciiString) aName;
2290 Handle(StepShape_DimensionalSize) DimSize =
2291 Handle(StepShape_DimensionalSize)::DownCast(theEnt);
2292 Standard_Real dim1=-1.,dim2=-1.;
2293 subs4 = aGraph.Sharings(DimSize);
2294 for(subs4.Start(); subs4.More(); subs4.Next()) {
2295 Handle(StepShape_DimensionalCharacteristicRepresentation) DimCharR =
2296 Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(subs4.Value());
2297 if(!DimCharR.IsNull()) {
2298 Handle(StepShape_ShapeDimensionRepresentation) SDimR = DimCharR->Representation();
2299 if(!SDimR.IsNull() && SDimR->NbItems()>0) {
2300 Handle(StepRepr_RepresentationItem) aRI = SDimR->ItemsValue(1);
2301 Handle(StepRepr_ValueRange) VR = Handle(StepRepr_ValueRange)::DownCast(aRI);
2302 if(!VR.IsNull()) {
2303 aName = VR->Name();
2304 //StepRepr_CompoundItemDefinition CID = VR->ItemElement();
2305 //if(CID.IsNull()) continue;
2306 //Handle(StepRepr_CompoundItemDefinitionMember) CIDM =
2307 // Handle(StepRepr_CompoundItemDefinitionMember)::DownCast(CID.Value());
2308 //if(CIDM.IsNull()) continue;
2309 //if(CIDM->ArrTransient().IsNull()) continue;
2310 //Handle(StepRepr_HArray1OfRepresentationItem) HARI;
2311 //if(CID.CaseMem(CIDM)==1)
2312 // HARI = CID.ListRepresentationItem();
2313 //if(CID.CaseMem(CIDM)==2)
2314 // HARI = CID.SetRepresentationItem();
2315 Handle(StepRepr_HArray1OfRepresentationItem) HARI = VR->ItemElement();
2316 if(HARI.IsNull()) continue;
2317 if(HARI->Length()>0) {
2318 Handle(StepRepr_RepresentationItem) RI1 =
2319 Handle(StepRepr_RepresentationItem)::DownCast(HARI->Value(1));
2320 if(RI1.IsNull()) continue;
2321 if(RI1->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
2322 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU =
2323 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI1);
2324 dim1 = RILMWU->GetMeasureWithUnit()->ValueComponent();
2325 StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent();
2326 Standard_Real afact=1.;
2327 if(anUnit.IsNull()) continue;
2328 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2329 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2330 if(GetLengthConversionFactor(NU,afact)) dim1=dim1*afact;
2331 }
2332 }
2333 if(HARI->Length()>1) {
2334 Handle(StepRepr_RepresentationItem) RI2 =
2335 Handle(StepRepr_RepresentationItem)::DownCast(HARI->Value(2));
2336 if(RI2.IsNull()) continue;
2337 if(RI2->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
2338 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU =
2339 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI2);
2340 dim2 = RILMWU->GetMeasureWithUnit()->ValueComponent();
2341 StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent();
2342 Standard_Real afact=1.;
2343 if(anUnit.IsNull()) continue;
2344 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2345 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2346 if(GetLengthConversionFactor(NU,afact)) dim2 = dim2*afact;
2347 }
2348 }
2349 }
2350 }
2351 }
2352 }
2353 if(dim1<0) continue;
2354 if(dim2<0) dim2=dim1;
2355 //cout<<"DimensionalSize: dim1="<<dim1<<" dim2="<<dim2<<endl;
2356 // now we know edge_curve and value range therefore
2357 // we can create corresponding D&GT labels
2358 Standard_Integer index = aTP->MapIndex(EC);
2359 TopoDS_Shape aSh;
2360 if(index >0) {
2361 Handle(Transfer_Binder) binder = aTP->MapItem(index);
2362 aSh = TransferBRep::ShapeResult(binder);
2363 }
2364 if(aSh.IsNull()) continue;
2365 TDF_Label shL;
2366 if( !aSTool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
2367 Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(1,2);
2368 arr->SetValue(1,dim1);
2369 arr->SetValue(2,dim2);
2370 aDGTTool->SetDimTol(shL,1,arr,aName,DimSize->Name());
7fd59977 2371 }
1c9d3225 2372 // read tolerances and datums
2373 else if(theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
2374 Handle(StepDimTol_GeometricTolerance) GT =
2375 Handle(StepDimTol_GeometricTolerance)::DownCast(theEnt);
2376 // read common data for tolerance
2377 //Standard_Real dim = GT->Magnitude()->ValueComponent();
2378 Handle (StepBasic_MeasureWithUnit) dim3 = GT->Magnitude();
2379 if(dim3.IsNull()) continue;
2380 Standard_Real dim = dim3->ValueComponent();
2381 StepBasic_Unit anUnit = GT->Magnitude()->UnitComponent();
2382 Standard_Real afact=1.;
2383 if(anUnit.IsNull()) continue;
2384 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2385 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2386 if(GetLengthConversionFactor(NU,afact)) dim = dim*afact;
2387 //cout<<"GeometricTolerance: Magnitude = "<<dim<<endl;
2388 Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(1,1);
2389 arr->SetValue(1,dim);
2390 Handle(TCollection_HAsciiString) aName = GT->Name();
2391 Handle(TCollection_HAsciiString) aDescription = GT->Description();
2392 Handle(StepShape_AdvancedFace) AF = Handle(StepShape_AdvancedFace)::DownCast(RI);
2393 if(AF.IsNull()) continue;
2394 Standard_Integer index = aTP->MapIndex(AF);
2395 TopoDS_Shape aSh;
2396 if(index >0) {
2397 Handle(Transfer_Binder) binder = aTP->MapItem(index);
2398 aSh = TransferBRep::ShapeResult(binder);
2399 }
2400 if(aSh.IsNull()) continue;
2401 TDF_Label shL;
2402 if( !aSTool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
2403 // read specific data for tolerance
2404 if(GT->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol))) {
2405 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol) GTComplex =
2406 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol)::DownCast(theEnt);
2407 Standard_Integer kind=20;
2408 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
2409 GTComplex->GetModifiedGeometricTolerance();
2410 if(!MGT.IsNull()) {
2411 kind = kind + MGT->Modifier()+1;
2412 }
2413 TDF_Label TolerL = aDGTTool->SetDimTol(shL,kind,arr,aName,aDescription);
2414 // translate datums connected with this tolerance
2415 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
2416 GTComplex->GetGeometricToleranceWithDatumReference();
2417 if(!GTWDR.IsNull()) {
2418 ReadDatums(aSTool,aDGTTool,aGraph,aTP,TolerL,GTWDR);
2419 }
2420 }
2421 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithDatumReference))) {
2422 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
2423 Handle(StepDimTol_GeometricToleranceWithDatumReference)::DownCast(theEnt);
2424 if(GTWDR.IsNull()) continue;
2425 Standard_Integer kind = 0;
2426 if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_AngularityTolerance))) kind = 24;
2427 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_CircularRunoutTolerance))) kind = 25;
2428 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_CoaxialityTolerance))) kind = 26;
2429 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_ConcentricityTolerance))) kind = 27;
2430 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_ParallelismTolerance))) kind = 28;
2431 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_PerpendicularityTolerance))) kind = 29;
2432 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_SymmetryTolerance))) kind = 30;
2433 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_TotalRunoutTolerance))) kind = 31;
2434 //cout<<"GTWDR: kind="<<kind<<endl;
2435 TDF_Label TolerL = aDGTTool->SetDimTol(shL,kind,arr,aName,aDescription);
2436 ReadDatums(aSTool,aDGTTool,aGraph,aTP,TolerL,GTWDR);
2437 }
2438 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_ModifiedGeometricTolerance))) {
2439 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
2440 Handle(StepDimTol_ModifiedGeometricTolerance)::DownCast(theEnt);
2441 Standard_Integer kind = 35 + MGT->Modifier();
2442 aDGTTool->SetDimTol(shL,kind,arr,aName,aDescription);
2443 }
2444 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_CylindricityTolerance))) {
2445 aDGTTool->SetDimTol(shL,38,arr,aName,aDescription);
2446 }
2447 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_FlatnessTolerance))) {
2448 aDGTTool->SetDimTol(shL,39,arr,aName,aDescription);
2449 }
2450 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_LineProfileTolerance))) {
2451 aDGTTool->SetDimTol(shL,40,arr,aName,aDescription);
2452 }
2453 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_PositionTolerance))) {
2454 aDGTTool->SetDimTol(shL,41,arr,aName,aDescription);
2455 }
2456 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_RoundnessTolerance))) {
2457 aDGTTool->SetDimTol(shL,42,arr,aName,aDescription);
2458 }
2459 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_StraightnessTolerance))) {
2460 aDGTTool->SetDimTol(shL,43,arr,aName,aDescription);
2461 }
2462 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_SurfaceProfileTolerance))) {
2463 aDGTTool->SetDimTol(shL,44,arr,aName,aDescription);
2464 }
7fd59977 2465 }
1c9d3225 2466 }
2467 else
2468 {
2469 if(aGISU.IsNull()) continue;
2470 if(aGISU->NbIdentifiedItem() > 0) {
2471 aSeqRI.Append(aGISU->IdentifiedItemValue(1));
7fd59977 2472 }
1c9d3225 2473 }
2474 }
2475 if(!aSeqRI.IsEmpty())
2476 {
2477 if(aSeqRI1.IsEmpty())
2478 aSeqRI1 = aSeqRI;
2479 else
2480 aSeqRI2 = aSeqRI;
2481 }
2482 }
2483 }
2484 if(aSeqRI1.IsEmpty()) return aGDTL;
2485
2486 TDF_LabelSequence aShLS1, aShLS2;
2487
2488 for(Standard_Integer i = aSeqRI1.Lower(); i <= aSeqRI1.Upper() ;i++)
2489 {
2490 Standard_Integer anIndex = aTP->MapIndex(aSeqRI1.Value(i));
2491 TopoDS_Shape aSh;
2492 if(anIndex >0) {
2493 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
2494 aSh = TransferBRep::ShapeResult(aBinder);
2495 }
2496 if(!aSh.IsNull())
2497 {
2498 TDF_Label aShL;
2499 aSTool->Search(aSh, aShL, Standard_True, Standard_True, Standard_True);
2500 aShLS1.Append(aShL);
2501 }
2502 }
2503 if (!aSeqRI2.IsEmpty())
2504 {
2505 //for dimensional location
2506 for(Standard_Integer i = aSeqRI2.Lower(); i <= aSeqRI2.Upper() ;i++)
2507 {
2508 Standard_Integer anIndex = aTP->MapIndex(aSeqRI2.Value(i));
2509 TopoDS_Shape aSh;
2510 if(anIndex >0) {
2511 Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
2512 aSh = TransferBRep::ShapeResult(aBinder);
2513 }
2514 if(!aSh.IsNull())
2515 {
2516 TDF_Label aShL;
2517 aSTool->Search(aSh, aShL, Standard_True, Standard_True, Standard_True);
2518 aShLS2.Append(aShL);
2519 }
2520 }
2521 }
2522
2523 if(!aShLS1.IsEmpty())
2524 {
2525 // add to XCAF
2526 if(!theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
2527 {
2528 aGDTL = aDGTTool->AddDimension();
2529 Handle(XCAFDoc_Dimension) aDim = XCAFDoc_Dimension::Set(aGDTL);
2530 TCollection_AsciiString aStr("DGT:Dimensional_");
2531 if(theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)))
2532 {
2533 aStr.AssignCat("Size");
2534 }
2535 else if(theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)))
2536 {
2537 aStr.AssignCat("Location");
2538 }
2539 TDataStd_Name::Set(aGDTL, aStr);
2540
2541 if(!aShLS2.IsEmpty())
2542 {
2543 aDGTTool->SetDimension(aShLS1, aShLS2, aGDTL);
2544 }
2545 else
2546 {
2547 TDF_LabelSequence aEmptySeq;
2548 aDGTTool->SetDimension(aShLS1, aEmptySeq, aGDTL);
2549 }
2550 }
2551 else
2552 {
2553 aGDTL = aDGTTool->AddGeomTolerance();
2554 Handle(XCAFDoc_GeomTolerance) aGTol = XCAFDoc_GeomTolerance::Set(aGDTL);
2555 TCollection_AsciiString aStr("DGT:GeomTolerance");
2556 TDataStd_Name::Set(aGDTL, aStr);
2557 aDGTTool->SetGeomTolerance(aShLS1, aGDTL);
2558 Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGTol->GetObject();
2559 if(isAllAround)
2560 anObj->AddModifier(XCAFDimTolObjects_GeomToleranceModif_All_Around);
2561 else if(isAllOver)
2562 anObj->AddModifier(XCAFDimTolObjects_GeomToleranceModif_All_Over);
2563 aGTol->SetObject(anObj);
2564 }
2565 readDatumsAP242(theEnt, aGDTL, theDoc, theWS);
2566 }
2567 return aGDTL;
2568}
2569
2570//=======================================================================
2571//function : setDimObjectToXCAF
2572//purpose :
2573//=======================================================================
2574static void setDimObjectToXCAF(const Handle(Standard_Transient)& theEnt,
2575 const TDF_Label& aDimL,
2576 const Handle(TDocStd_Document)& theDoc,
2577 const Handle(XSControl_WorkSession)& theWS)
2578{
2579 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( theDoc->Main() );
2580 Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool( theDoc->Main() );
2581 Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
2582 Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
2583 const Interface_Graph& aGraph = aTP->Graph();
2584 Handle(XCAFDimTolObjects_DimensionObject) aDimObj;
2585 if(!theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) &&
2586 !theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)))
2587 return;
2588
2589 Handle(StepShape_DimensionalSize) aDimSize =
2590 Handle(StepShape_DimensionalSize)::DownCast(theEnt);
2591 Handle(StepShape_DimensionalLocation) aDimLocation =
2592 Handle(StepShape_DimensionalLocation)::DownCast(theEnt);
2593
2594 Standard_Real aDim1=-1.,aDim2=-1.,aDim3=-1.;
2595 Handle(StepShape_TypeQualifier) aTQ;
2596 Handle(StepShape_ValueFormatTypeQualifier) aVFTQ;
2597 Handle(StepShape_ToleranceValue) aTV;
2598 Handle(StepShape_LimitsAndFits) aLAF;
2599 Handle(StepRepr_CompoundRepresentationItem) aCRI;
2600 Handle(StepGeom_Axis2Placement3d) anAP;
2601
2602 Interface_EntityIterator anIterDim;
2603 if(!aDimSize.IsNull())
2604 {
2605 anIterDim = aGraph.Sharings(aDimSize);
2606 }
2607 else
2608 {
2609 anIterDim = aGraph.Sharings(aDimLocation);
2610 }
2611 for(anIterDim.Start(); anIterDim.More(); anIterDim.Next()) {
2612 Handle(StepShape_DimensionalCharacteristicRepresentation) aDCR =
2613 Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(anIterDim.Value());
2614 Handle(StepShape_PlusMinusTolerance) aPMT =
2615 Handle(StepShape_PlusMinusTolerance)::DownCast(anIterDim.Value());
2616 if(!aDCR.IsNull()) {
2617 Handle(StepShape_ShapeDimensionRepresentation) aSDR = aDCR->Representation();
2618 if(!aSDR.IsNull()) {
2619 Handle(StepRepr_HArray1OfRepresentationItem) aHARI = aSDR->Items();
2620
2621 if(!aHARI.IsNull())
2622 {
2623 for(Standard_Integer nr = aHARI->Lower(); nr <= aHARI->Upper(); nr++)
2624 {
2625 Handle(StepRepr_RepresentationItem) aDRI =
2626 Handle(StepRepr_RepresentationItem)::DownCast(aHARI->Value(nr));
2627 if(aDRI.IsNull()) continue;
2628
2629 if(aDRI->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
2630 //get values
2631 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) aRILMWU =
2632 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(aDRI);
2633 Standard_Real aVal = aRILMWU->GetMeasureWithUnit()->ValueComponent();
2634 StepBasic_Unit anUnit = aRILMWU->GetMeasureWithUnit()->UnitComponent();
2635 Standard_Real aFact=1.;
2636 if(anUnit.IsNull()) continue;
2637 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2638 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2639 if(GetLengthConversionFactor(NU,aFact)) aVal=aVal*aFact;
2640 if(aDim2 > 0)
2641 {
2642 if(aDim1 > aDim2)
2643 {
2644 Standard_Real aTmp = aDim1;
2645 aDim1 = aDim2;
2646 aDim2 = aTmp;
2647 }
2648 if(aVal < aDim1)
2649 aDim1 = aVal;
2650 else if(aVal > aDim2)
2651 aDim2 = aVal;
2652 }
2653 else if(aDim1 > 0)
2654 {
2655 if (aVal > aDim1)
2656 aDim2 = aVal;
2657 else
2658 {
2659 aDim2 = aDim1;
2660 aDim1 = aVal;
2661 }
2662 }
2663 else
2664 aDim1 = aVal;
2665 }
2666 else if(aDRI->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndPlaneAngleMeasureWithUnit))) {
2667 //get values
2668 Handle(StepRepr_ReprItemAndPlaneAngleMeasureWithUnit) aRIPAMWU =
2669 Handle(StepRepr_ReprItemAndPlaneAngleMeasureWithUnit)::DownCast(aDRI);
2670 Standard_Real aVal = aRIPAMWU->GetMeasureWithUnit()->ValueComponent();
2671 StepBasic_Unit anUnit = aRIPAMWU->GetMeasureWithUnit()->UnitComponent();
2672 Standard_Real aFact=1.;
2673 if(anUnit.IsNull()) continue;
2674 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2675 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2676 if(GetAngleConversionFactor(NU,aFact)) aVal=aVal*aFact;
2677 if(aDim2 > 0)
2678 {
2679 if(aDim1 > aDim2)
2680 {
2681 Standard_Real aTmp = aDim1;
2682 aDim1 = aDim2;
2683 aDim2 = aTmp;
2684 }
2685 if(aVal < aDim1)
2686 aDim1 = aVal;
2687 else if(aVal > aDim2)
2688 aDim2 = aVal;
2689 }
2690 else if(aDim1 > 0)
2691 {
2692 if (aVal > aDim1)
2693 aDim2 = aVal;
2694 else
2695 {
2696 aDim2 = aDim1;
2697 aDim1 = aVal;
2698 }
2699 }
2700 else
2701 aDim1 = aVal;
2702 }
2703 else if(aDRI->IsKind(STANDARD_TYPE(StepShape_QualifiedRepresentationItem))) {
2704 //get qualifier
2705 Handle(StepShape_QualifiedRepresentationItem) aQRI =
2706 Handle(StepShape_QualifiedRepresentationItem)::DownCast(aDRI);
2707 for(Standard_Integer l = 1; l <= aQRI->NbQualifiers(); l++)
2708 {
2709 aTQ = aQRI->Qualifiers()->Value(l).TypeQualifier();
2710 aVFTQ = aQRI->Qualifiers()->Value(l).ValueFormatTypeQualifier();
2711 }
2712 }
2713 else if(aDRI->IsKind(STANDARD_TYPE(StepRepr_CompoundRepresentationItem))) {
2714 aCRI = Handle(StepRepr_CompoundRepresentationItem)::DownCast(aDRI);
2715 }
2716 else if(aDRI->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
2717 {
2718 anAP = Handle(StepGeom_Axis2Placement3d)::DownCast(aDRI);
2719 }
7fd59977 2720 }
1c9d3225 2721 }
2722 }
2723 }
2724 else if (!aPMT.IsNull())
2725 {
2726 StepShape_ToleranceMethodDefinition aTMD = aPMT->Range();
2727 if(aPMT.IsNull()) continue;
2728 if(aTMD.CaseNumber() == 1)
2729 //! 1 -> ToleranceValue from StepShape
2730 //! 2 -> LimitsAndFits from StepShape
2731 {
2732 //plus minus tolerance
2733 aTV = aTMD.ToleranceValue();
2734 if (aTV.IsNull()) continue;
2735
2736 Standard_Real aVal = aTV->UpperBound()->ValueComponent();
2737 StepBasic_Unit anUnit = aTV->UpperBound()->UnitComponent();
2738 Standard_Real aFact=1.;
2739 if(anUnit.IsNull()) continue;
2740 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2741 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
2742 if(GetLengthConversionFactor(NU,aFact)) aVal=aVal*aFact;
2743 aDim3 = aVal;
2744
2745 aVal = aTV->LowerBound()->ValueComponent();
2746 anUnit = aTV->LowerBound()->UnitComponent();
2747 aFact=1.;
2748 if(anUnit.IsNull()) continue;
2749 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
2750 NU = anUnit.NamedUnit();
2751 if(GetLengthConversionFactor(NU,aFact)) aVal=aVal*aFact;
2752 aDim2 = Abs(aVal);
2753 }
2754 else
2755 {
2756 // calss of tolerance
2757 aLAF = aTMD.LimitsAndFits();
2758 }
2759 }
2760 }
2761
2762 if(aDim1<0) return;
2763
2764 aDimObj = new XCAFDimTolObjects_DimensionObject();
2765 if(aDim2 < 0)
2766 aDimObj->SetValue(aDim1);
2767 else if (aDim3 < 0)
2768 {
2769 Handle(TColStd_HArray1OfReal) anArr = new TColStd_HArray1OfReal(1,2);
2770 anArr->SetValue(1,aDim1);
2771 anArr->SetValue(2,aDim2);
2772 aDimObj->SetValues(anArr);
2773 }
2774 else
2775 {
2776 Handle(TColStd_HArray1OfReal) anArr = new TColStd_HArray1OfReal(1,3);
2777 anArr->SetValue(1,aDim1);
2778 anArr->SetValue(2,aDim2);
2779 anArr->SetValue(3,aDim3);
2780 aDimObj->SetValues(anArr);
2781 }
2782 if(!aTQ.IsNull())
2783 {
2784 XCAFDimTolObjects_DimensionQualifier aQ;
2785 if (STEPConstruct_GDTProperty::GetDimQualifierType(aTQ->Name(), aQ))
2786 {
2787 aDimObj->SetQualifier(aQ);
2788 }
2789 }
2790
2791 if (!aVFTQ.IsNull())
2792 {
2793