0023403: Crash when parsing an expression with lexical error
[occt.git] / src / STEPCAFControl / STEPCAFControl_Reader.cxx
CommitLineData
b311480e 1// Created on: 2000-08-15
2// Created by: Andrey BETENEV
3// Copyright (c) 2000-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20
21#include <STEPCAFControl_Reader.ixx>
22
23#include <Quantity_Color.hxx>
24#include <TCollection_HAsciiString.hxx>
25#include <TopoDS_Shape.hxx>
26#include <TopoDS_Iterator.hxx>
27#include <TopTools_MapOfShape.hxx>
28#include <TopoDS_Compound.hxx>
29
30#include <Transfer_TransientProcess.hxx>
31#include <TransferBRep.hxx>
32#include <Transfer_Binder.hxx>
33#include <Interface_InterfaceModel.hxx>
34#include <XSControl_TransferReader.hxx>
35
36#include <StepBasic_Product.hxx>
37#include <StepBasic_ProductDefinition.hxx>
38#include <StepBasic_ProductDefinitionRelationship.hxx>
39#include <StepBasic_ProductDefinitionFormation.hxx>
40#include <StepShape_ContextDependentShapeRepresentation.hxx>
41#include <StepShape_ShapeDefinitionRepresentation.hxx>
42#include <StepShape_ShapeDefinitionRepresentation.hxx>
43#include <StepRepr_ProductDefinitionShape.hxx>
44#include <StepRepr_PropertyDefinition.hxx>
45#include <StepRepr_ShapeAspect.hxx>
46#include <StepRepr_MeasureRepresentationItem.hxx>
47#include <StepRepr_DescriptiveRepresentationItem.hxx>
48#include <StepVisual_StyledItem.hxx>
49#include <StepAP214_AppliedExternalIdentificationAssignment.hxx>
50
51#include <STEPConstruct.hxx>
52#include <STEPConstruct_Styles.hxx>
53#include <STEPConstruct_ExternRefs.hxx>
54#include <STEPConstruct_UnitContext.hxx>
55#include <STEPCAFControl_Controller.hxx>
56#include <STEPCAFControl_DataMapOfSDRExternFile.hxx>
57
58#include <TDataStd_Name.hxx>
59#include <TDF_Label.hxx>
60#include <XCAFDoc_ColorTool.hxx>
61#include <XCAFDoc_ShapeTool.hxx>
62#include <XCAFDoc_DocumentTool.hxx>
63#include <XCAFDoc_DimTolTool.hxx>
64#include <XCAFDoc_MaterialTool.hxx>
65#include <XCAFDoc_DataMapOfShapeLabel.hxx>
66#include <STEPConstruct_ValidationProps.hxx>
67#include <StepRepr_Representation.hxx>
68#include <XCAFDoc_Area.hxx>
69#include <XCAFDoc_Volume.hxx>
70#include <XCAFDoc_Centroid.hxx>
71#include <StepVisual_PresentationLayerAssignment.hxx>
72#include <TColStd_HSequenceOfTransient.hxx>
73#include <StepVisual_LayeredItem.hxx>
74#include <XCAFDoc_LayerTool.hxx>
75#include <Interface_EntityIterator.hxx>
76#include <StepRepr_ShapeRepresentationRelationship.hxx>
77#include <STEPConstruct_Assembly.hxx>
78#include <TDF_Tool.hxx>
79#include <StepVisual_Invisibility.hxx>
80#include <TDataStd_UAttribute.hxx>
81#include <XCAFDoc.hxx>
82#include <OSD_Path.hxx>
83#include <TColStd_SequenceOfHAsciiString.hxx>
84
85#include <TDataStd_TreeNode.hxx>
86#include <TNaming_NamedShape.hxx>
87#include <BRep_Builder.hxx>
88
89#include <STEPCAFControl_DataMapOfShapePD.hxx>
90#include <STEPCAFControl_DataMapOfPDExternFile.hxx>
91#include <StepVisual_PresentationStyleByContext.hxx>
92#include <StepVisual_StyleContextSelect.hxx>
93#include <StepRepr_RepresentedDefinition.hxx>
94#include <StepRepr_CharacterizedDefinition.hxx>
95#include <StepRepr_SpecifiedHigherUsageOccurrence.hxx>
96#include <XCAFDoc_GraphNode.hxx>
97#include <STEPCAFControl_Reader.hxx>
98
99// skl 21.08.2003 for reading G&DT
100#include <StepShape_DimensionalSize.hxx>
101#include <StepDimTol_GeometricTolerance.hxx>
102#include <StepShape_EdgeCurve.hxx>
103#include <StepShape_DimensionalCharacteristicRepresentation.hxx>
104#include <StepShape_ShapeDimensionRepresentation.hxx>
105#include <StepRepr_ValueRange.hxx>
106#include <StepRepr_ReprItemAndLengthMeasureWithUnit.hxx>
107#include <StepBasic_MeasureWithUnit.hxx>
108#include <StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol.hxx>
109#include <StepDimTol_ModifiedGeometricTolerance.hxx>
110#include <StepDimTol_GeometricToleranceWithDatumReference.hxx>
111//#include <StepRepr_CompoundItemDefinition.hxx>
112//#include <StepRepr_CompoundItemDefinitionMember.hxx>
113#include <TColStd_HArray1OfTransient.hxx>
114#include <StepRepr_HArray1OfRepresentationItem.hxx>
115#include <TColStd_IndexedDataMapOfTransientTransient.hxx>
116//#include <StepBasic_ConversionBasedUnit.hxx>
117#include <StepBasic_Unit.hxx>
118#include <StepBasic_NamedUnit.hxx>
119#include <StepBasic_SiUnit.hxx>
120#include <StepBasic_ConversionBasedUnitAndLengthUnit.hxx>
121#include <StepBasic_ConversionBasedUnitAndMassUnit.hxx>
122#include <StepBasic_DerivedUnit.hxx>
123#include <StepBasic_DerivedUnitElement.hxx>
124#include <StepBasic_MeasureValueMember.hxx>
125
126//#include <TDataStd_Real.hxx>
127//#include <TDataStd_Constraint.hxx>
128//#include <TDataStd_ConstraintEnum.hxx>
129//#include <TNaming_Tool.hxx>
130//#include <AIS_InteractiveObject.hxx>
131//#include <TPrsStd_ConstraintTools.hxx>
132//#include <AIS_DiameterDimension.hxx>
133//#include <TPrsStd_Position.hxx>
134//#include <TPrsStd_AISPresentation.hxx>
135//#include <TNaming_Builder.hxx>
136#include <TColStd_HArray1OfReal.hxx>
137#include <StepShape_AdvancedFace.hxx>
138#include <StepDimTol_HArray1OfDatumReference.hxx>
139#include <StepDimTol_DatumReference.hxx>
140#include <StepDimTol_Datum.hxx>
141#include <StepDimTol_DatumFeature.hxx>
142#include <StepRepr_ShapeAspectRelationship.hxx>
143
144#include <StepDimTol_AngularityTolerance.hxx>
145#include <StepDimTol_CircularRunoutTolerance.hxx>
146#include <StepDimTol_CoaxialityTolerance.hxx>
147#include <StepDimTol_ConcentricityTolerance.hxx>
148#include <StepDimTol_ParallelismTolerance.hxx>
149#include <StepDimTol_PerpendicularityTolerance.hxx>
150#include <StepDimTol_SymmetryTolerance.hxx>
151#include <StepDimTol_TotalRunoutTolerance.hxx>
152#include <StepDimTol_CylindricityTolerance.hxx>
153#include <StepDimTol_FlatnessTolerance.hxx>
154#include <StepDimTol_LineProfileTolerance.hxx>
155#include <StepDimTol_PositionTolerance.hxx>
156#include <StepDimTol_RoundnessTolerance.hxx>
157#include <StepDimTol_StraightnessTolerance.hxx>
158#include <StepDimTol_SurfaceProfileTolerance.hxx>
159
160#include <StepShape_SolidModel.hxx>
161#include <StepShape_ShellBasedSurfaceModel.hxx>
162#include <StepShape_GeometricSet.hxx>
1d2b1ccb 163#include <StepBasic_ProductDefinition.hxx>
7fd59977 164
165//#include <BRepTools.hxx>
166
167
168//=======================================================================
169//function : STEPCAFControl_Reader
170//purpose :
171//=======================================================================
172
173STEPCAFControl_Reader::STEPCAFControl_Reader ():
174 myColorMode( Standard_True ),
175 myNameMode ( Standard_True ),
176 myLayerMode( Standard_True ),
177 myPropsMode( Standard_True ),
178 myGDTMode ( Standard_True ),
179 myMatMode ( Standard_True )
180{
181 STEPCAFControl_Controller::Init();
182 myFiles = new STEPCAFControl_DictionaryOfExternFile;
183}
184
185
186//=======================================================================
187//function : STEPCAFControl_Reader
188//purpose :
189//=======================================================================
190
191STEPCAFControl_Reader::STEPCAFControl_Reader (const Handle(XSControl_WorkSession)& WS,
192 const Standard_Boolean scratch) :
193 myColorMode( Standard_True ),
194 myNameMode ( Standard_True ),
195 myLayerMode( Standard_True ),
196 myPropsMode( Standard_True ),
197 myGDTMode ( Standard_True ),
198 myMatMode ( Standard_True )
199{
200 STEPCAFControl_Controller::Init();
201 Init ( WS, scratch );
202}
203
204
205//=======================================================================
206//function : Init
207//purpose :
208//=======================================================================
209
210void STEPCAFControl_Reader::Init (const Handle(XSControl_WorkSession)& WS,
211 const Standard_Boolean scratch)
212{
213// necessary only in Writer, to set good actor: WS->SelectNorm ( "STEP" );
214 myReader.SetWS (WS,scratch);
215 myFiles = new STEPCAFControl_DictionaryOfExternFile;
216}
217
218
219//=======================================================================
220//function : ReadFile
221//purpose :
222//=======================================================================
223
224IFSelect_ReturnStatus STEPCAFControl_Reader::ReadFile (const Standard_CString filename)
225{
226 return myReader.ReadFile ( filename );
227}
228
229
230//=======================================================================
231//function : NbRootsForTransfer
232//purpose :
233//=======================================================================
234
235Standard_Integer STEPCAFControl_Reader::NbRootsForTransfer ()
236{
237 return myReader.NbRootsForTransfer();
238}
239
240
241//=======================================================================
242//function : TransferOneRoot
243//purpose :
244//=======================================================================
245
246Standard_Boolean STEPCAFControl_Reader::TransferOneRoot (const Standard_Integer num,
247 Handle(TDocStd_Document) &doc)
248{
249 TDF_LabelSequence Lseq;
250 return Transfer ( myReader, num, doc, Lseq );
251}
252
253
254//=======================================================================
255//function : Transfer
256//purpose :
257//=======================================================================
258
259Standard_Boolean STEPCAFControl_Reader::Transfer (Handle(TDocStd_Document) &doc)
260{
261 TDF_LabelSequence Lseq;
262 return Transfer ( myReader, 0, doc, Lseq );
263}
264
265
266//=======================================================================
267//function : Perform
268//purpose :
269//=======================================================================
270
271Standard_Boolean STEPCAFControl_Reader::Perform (const Standard_CString filename,
272 Handle(TDocStd_Document) &doc)
273{
274 if ( ReadFile ( filename ) != IFSelect_RetDone ) return Standard_False;
275 return Transfer ( doc );
276}
277
278
279//=======================================================================
280//function : Perform
281//purpose :
282//=======================================================================
283
284Standard_Boolean STEPCAFControl_Reader::Perform (const TCollection_AsciiString &filename,
285 Handle(TDocStd_Document) &doc)
286{
287 if ( ReadFile ( filename.ToCString() ) != IFSelect_RetDone ) return Standard_False;
288 return Transfer ( doc );
289}
290
291
292//=======================================================================
293//function : ExternFiles
294//purpose :
295//=======================================================================
296
297const Handle(STEPCAFControl_DictionaryOfExternFile) &STEPCAFControl_Reader::ExternFiles () const
298{
299 return myFiles;
300}
301
302
303//=======================================================================
304//function : ExternFile
305//purpose :
306//=======================================================================
307
308Standard_Boolean STEPCAFControl_Reader::ExternFile (const Standard_CString name,
309 Handle(STEPCAFControl_ExternFile) &ef) const
310{
311 ef.Nullify();
312 if ( myFiles.IsNull() || ! myFiles->HasItem ( name ) )
313 return Standard_False;
314 ef = myFiles->Item ( name );
315 return Standard_True;
316}
317
318
319//=======================================================================
320//function : Reader
321//purpose :
322//=======================================================================
323
324STEPControl_Reader &STEPCAFControl_Reader::ChangeReader ()
325{
326 return myReader;
327}
328
329
330//=======================================================================
331//function : Reader
332//purpose :
333//=======================================================================
334
335const STEPControl_Reader &STEPCAFControl_Reader::Reader () const
336{
337 return myReader;
338}
339
340
341//=======================================================================
342//function : FillShapesMap
343//purpose : auxiliary: fill a map by all compounds and their components
344//=======================================================================
345
346static void FillShapesMap (const TopoDS_Shape &S, TopTools_MapOfShape &map)
347{
348 TopoDS_Shape S0 = S;
349 TopLoc_Location loc;
350 S0.Location ( loc );
351 map.Add ( S0 );
352 if ( S.ShapeType() != TopAbs_COMPOUND ) return;
353 for ( TopoDS_Iterator it(S); it.More(); it.Next() )
354 FillShapesMap ( it.Value(), map );
355}
356
357
358//=======================================================================
359//function : Transfer
360//purpose : basic working method
361//=======================================================================
362
363Standard_Boolean STEPCAFControl_Reader::Transfer (STEPControl_Reader &reader,
364 const Standard_Integer nroot,
365 Handle(TDocStd_Document) &doc,
366 TDF_LabelSequence &Lseq,
367 const Standard_Boolean asOne)
368{
369 reader.ClearShapes();
370 Standard_Integer i;
371
372 // Read all shapes
373 Standard_Integer num = reader.NbRootsForTransfer();
374 if ( num <=0 ) return Standard_False;
375 if ( nroot ) {
376 if ( nroot > num ) return Standard_False;
377 reader.TransferOneRoot ( num );
378 }
379 else {
380 for ( i=1; i <= num; i++ ) reader.TransferOneRoot ( i );
381 }
382 num = reader.NbShapes();
383 if ( num <=0 ) return Standard_False;
384
385 // Fill a map of (top-level) shapes resulting from that transfer
386 // Only these shapes will be considered further
387 TopTools_MapOfShape ShapesMap, NewShapesMap;
388 for ( i=1; i <= num; i++ ) FillShapesMap ( reader.Shape(i), ShapesMap );
389
390 // Collect information on shapes originating from SDRs
391 // this will be used to distinguish compounds representing assemblies
392 // from the ones representing hybrid models and shape sets
393 STEPCAFControl_DataMapOfShapePD ShapePDMap;
394 STEPCAFControl_DataMapOfPDExternFile PDFileMap;
395 Handle(Interface_InterfaceModel) Model = reader.Model();
396 Handle(Transfer_TransientProcess) TP = reader.WS()->TransferReader()->TransientProcess();
397 Standard_Integer nb = Model->NbEntities();
398
399 Handle(TColStd_HSequenceOfTransient) SeqPDS = new TColStd_HSequenceOfTransient;
400
401 for (i = 1; i <= nb; i ++) {
402 Handle(Standard_Transient) enti = Model->Value(i);
403 if(enti->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape))) {
404 // sequence for acceleration ReadMaterials
405 SeqPDS->Append(enti);
406 }
407 if ( enti->IsKind ( STANDARD_TYPE(StepBasic_ProductDefinition ) ) ) {
408 Handle(StepBasic_ProductDefinition) PD =
409 Handle(StepBasic_ProductDefinition)::DownCast(enti);
410 Standard_Integer index = TP->MapIndex(PD);
411 if ( index >0 ) {
412 Handle(Transfer_Binder) binder = TP->MapItem (index);
413 TopoDS_Shape S = TransferBRep::ShapeResult(binder);
414 if ( ! S.IsNull() && ShapesMap.Contains(S) ) {
415 NewShapesMap.Add(S);
416 ShapePDMap.Bind ( S, PD );
417 Handle(STEPCAFControl_ExternFile) EF;
418 PDFileMap.Bind ( PD, EF );
419 }
420 }
421 }
422 if ( enti->IsKind ( STANDARD_TYPE(StepShape_ShapeRepresentation) ) ) {
423 Standard_Integer index = TP->MapIndex(enti);
424 if ( index >0 ) {
425 Handle(Transfer_Binder) binder = TP->MapItem (index);
426 TopoDS_Shape S = TransferBRep::ShapeResult(binder);
427 if ( ! S.IsNull() && ShapesMap.Contains(S) )
428 NewShapesMap.Add(S);
429 }
430 }
431 }
432
433 // get directory name of the main file
434 OSD_Path mainfile ( reader.WS()->LoadedFile() );
435 mainfile.SetName ( "" );
436 mainfile.SetExtension ( "" );
437 TCollection_AsciiString dpath;
438 mainfile.SystemName ( dpath );
439
440 // Load external references (only for relevant SDRs)
441 // and fill map SDR -> extern file
442 STEPConstruct_ExternRefs ExtRefs ( reader.WS() );
443 ExtRefs.LoadExternRefs();
444 for ( i=1; i <= ExtRefs.NbExternRefs(); i++ ) {
445 // check extern ref format
446 Handle(TCollection_HAsciiString) format = ExtRefs.Format(i);
447 if ( ! format.IsNull() ) {
448 static Handle(TCollection_HAsciiString) ap203 = new TCollection_HAsciiString ( "STEP AP203" );
449 static Handle(TCollection_HAsciiString) ap214 = new TCollection_HAsciiString ( "STEP AP214" );
450 if ( ! format->IsSameString ( ap203, Standard_False ) &&
451 ! format->IsSameString ( ap214, Standard_False ) ) {
452#ifdef DEB
453 cout << "Warning: STEPCAFControl_Reader::Transfer: Extern document is neither STEP AP203 nor AP214" << endl;
454#else
455 continue;
456#endif
457 }
458 }
459#ifdef DEB
460 else cout << "Warning: STEPCAFControl_Reader::Transfer: Extern document format not defined" << endl;
461#endif
462
463 // get and check filename of the current extern ref
464 const Standard_CString filename = ExtRefs.FileName(i);
465
466cout<<"filename="<<filename<<endl;
467
468 if ( ! filename || ! filename[0] ) {
469#ifdef DEB
470 cout << "Warning: STEPCAFControl_Reader::Transfer: Extern reference file name is empty" << endl;
471#endif
472 continue; // not a valid extern ref
473 }
474
475 // compute true path to the extern file
476 TCollection_AsciiString fullname = OSD_Path::AbsolutePath ( dpath, filename );
477 if ( fullname.Length() <= 0 ) fullname = filename;
478
479/*
480 char fullname[1024];
481 char *mainfile = reader.WS()->LoadedFile();
482 if ( ! mainfile ) mainfile = "";
483 Standard_Integer slash = 0;
484 for ( Standard_Integer k=0; mainfile[k]; k++ )
485 if ( mainfile[k] == '/' ) slash = k;
486 strncpy ( fullname, mainfile, slash );
487 sprintf ( &fullname[slash], "%s%s", ( mainfile[0] ? "/" : "" ), filename );
488*/
489
490 // get and check PD associated with the current extern ref
491 Handle(StepBasic_ProductDefinition) PD = ExtRefs.ProdDef(i);
492 if ( PD.IsNull() ) continue; // not a valid extern ref
493 if ( ! PDFileMap.IsBound ( PD ) ) continue; // this PD is not concerned by current transfer
494
495 // read extern file (or use existing data) and record its data
496 Handle(STEPCAFControl_ExternFile) EF =
497 ReadExternFile ( filename, fullname.ToCString(), doc );
498 PDFileMap.Bind ( PD, EF );
499 }
500
501 // and insert them to the document
502 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( doc->Main() );
503 if ( STool.IsNull() ) return Standard_False;
504 XCAFDoc_DataMapOfShapeLabel map;
505 if ( asOne )
506 Lseq.Append ( AddShape ( reader.OneShape(), STool, NewShapesMap, ShapePDMap, PDFileMap, map ) );
507 else {
508 for ( i=1; i <= num; i++ ) {
509 Lseq.Append ( AddShape ( reader.Shape(i), STool, NewShapesMap, ShapePDMap, PDFileMap, map ) );
510 }
511 }
512
513 // read colors
514 if ( GetColorMode() )
515 ReadColors ( reader.WS(), doc, PDFileMap, map );
516
517 // read names
518 if ( GetNameMode() )
519 ReadNames ( reader.WS(), doc, PDFileMap, map );
520
521 // read validation props
522 if ( GetPropsMode() )
523 ReadValProps ( reader.WS(), doc, PDFileMap, map );
524
525 // read layers
526 if ( GetLayerMode() )
527 ReadLayers ( reader.WS(), doc );
528
529 // read SHUO entities from STEP model
530 if ( GetSHUOMode() )
531 ReadSHUOs ( reader.WS(), doc, PDFileMap, map );
532
533 // read GDT entities from STEP model
534 if(GetGDTMode())
535 ReadGDTs(reader.WS(),doc);
536
537 // read Material entities from STEP model
538 if(GetMatMode())
539 ReadMaterials(reader.WS(),doc,SeqPDS);
540
541 // cout << "Ready !!" << endl;
542
543 return Standard_True;
544}
545
546//=======================================================================
547//function : AddShape
548//purpose :
549//=======================================================================
550
551TDF_Label STEPCAFControl_Reader::AddShape (const TopoDS_Shape &S,
552 const Handle(XCAFDoc_ShapeTool) &STool,
553 const TopTools_MapOfShape &NewShapesMap,
554 const STEPCAFControl_DataMapOfShapePD &ShapePDMap,
555 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
556 XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
557{
558 // if shape has already been mapped, just return corresponding label
559 if ( ShapeLabelMap.IsBound ( S ) ) {
560 return ShapeLabelMap.Find ( S );
561 }
562
563 // if shape is located, create instance
564 if ( ! S.Location().IsIdentity() ) {
565 TopoDS_Shape S0 = S;
566 TopLoc_Location loc;
567 S0.Location ( loc );
568 AddShape ( S0, STool, NewShapesMap, ShapePDMap, PDFileMap, ShapeLabelMap );
569 TDF_Label L = STool->AddShape ( S, Standard_False ); // should create reference
570 ShapeLabelMap.Bind ( S, L );
571 return L;
572 }
573
574 // if shape is not compound, simple add it
575 if ( S.ShapeType() != TopAbs_COMPOUND ) {
576 TDF_Label L = STool->AddShape ( S, Standard_False );
577 ShapeLabelMap.Bind ( S, L );
578 return L;
579 }
580
581 // for compounds, compute number of subshapes and check whether this is assembly
582 Standard_Boolean isAssembly = Standard_False;
583 Standard_Integer nbComponents = 0;
584 TopoDS_Iterator it;
585 for ( it.Initialize(S); it.More(); it.Next(), nbComponents++ ) {
586 TopoDS_Shape Sub0 = it.Value();
587 TopLoc_Location loc;
588 Sub0.Location ( loc );
589 if ( NewShapesMap.Contains ( Sub0 ) ) isAssembly = Standard_True;
590 }
591
592// if(nbComponents>0) isAssembly = Standard_True;
593
594 // check whether it has associated external ref
595 TColStd_SequenceOfHAsciiString SHAS;
596 if ( ShapePDMap.IsBound ( S ) && PDFileMap.IsBound ( ShapePDMap.Find(S) ) ) {
597 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find ( ShapePDMap.Find(S) );
598 if ( ! EF.IsNull() ) {
599 // (store information on extern refs in the document)
600 SHAS.Append(EF->GetName());
601 // if yes, just return corresponding label
602 if ( ! EF->GetLabel().IsNull() ) {
603 // but if components >0, ignore extern ref!
604 if ( nbComponents <=0 ) {
605 ShapeLabelMap.Bind ( S, EF->GetLabel() );
606 STool->SetExternRefs(EF->GetLabel(),SHAS);
607 return EF->GetLabel();
608 }
609 }
610#ifdef DEB
611 if ( ! EF->GetLabel().IsNull() )
612 cout << "Warning: STEPCAFControl_Reader::AddShape: Non-empty shape with external ref; ref is ignored" << endl;
613 else if ( nbComponents <=0 )
614 cout << "Warning: STEPCAFControl_Reader::AddShape: Result of reading extern ref is Null" << endl;
615#endif
616 }
617 }
618
619 // add compound either as a whole,
620 if ( ! isAssembly ) {
621 TDF_Label L = STool->AddShape ( S, Standard_False );
622 if ( SHAS.Length() >0 ) STool->SetExternRefs(L,SHAS);
623 ShapeLabelMap.Bind ( S, L );
624 return L;
625 }
626
627 // or as assembly, component-by-component
628 TDF_Label L = STool->NewShape();
629 for ( it.Initialize(S); it.More(); it.Next(), nbComponents++ ) {
630 TopoDS_Shape Sub0 = it.Value();
631 TopLoc_Location loc;
632 Sub0.Location ( loc );
633 TDF_Label subL = AddShape ( Sub0, STool, NewShapesMap, ShapePDMap, PDFileMap, ShapeLabelMap );
634 if ( ! subL.IsNull() ) {
635 STool->AddComponent ( L, subL, it.Value().Location() );
636 }
637 }
638 if ( SHAS.Length() >0 ) STool->SetExternRefs(L,SHAS);
639 ShapeLabelMap.Bind ( S, L );
640 //STool->SetShape ( L, S ); // it is necessary for assemblies OCC1747 // commemted by skl for OCC2941
641
642 return L;
643}
644
645//=======================================================================
646//function : ReadExternFile
647//purpose :
648//=======================================================================
649
650Handle(STEPCAFControl_ExternFile) STEPCAFControl_Reader::ReadExternFile (const Standard_CString file,
651 const Standard_CString fullname,
652 Handle(TDocStd_Document)& doc)
653{
654 // if the file is already read, associate it with SDR
655 if ( myFiles->HasItem ( file, Standard_True ) ) {
656 return myFiles->Item ( file );
657 }
658
659#ifdef DEB
660 cout << "Reading extern file: " << fullname << endl;
661#endif
662
663 // create new WorkSession and Reader
664 Handle(XSControl_WorkSession) newWS = new XSControl_WorkSession;
665 newWS->SelectNorm ( "STEP" );
666 STEPControl_Reader sr ( newWS, Standard_False );
667
668 // start to fill the resulting ExternFile structure
669 Handle(STEPCAFControl_ExternFile) EF = new STEPCAFControl_ExternFile;
670 EF->SetWS ( newWS );
671 EF->SetName ( new TCollection_HAsciiString ( file ) );
672
673 // read file
674 EF->SetLoadStatus ( sr.ReadFile ( fullname ) );
675
676 // transfer in single-result mode
677 if ( EF->GetLoadStatus() == IFSelect_RetDone ) {
678 TDF_LabelSequence labels;
679 EF->SetTransferStatus ( Transfer ( sr, 0, doc, labels, Standard_True ) );
680 if ( labels.Length() >0 ) EF->SetLabel ( labels.Value(1) );
681 }
682
683 // add read file to dictionary
684 myFiles->SetItem ( file, EF );
685
686 return EF;
687}
688
689
690//=======================================================================
691//function : SetColorToSubshape
692//purpose : auxilary
693//=======================================================================
694static void SetColorToSubshape(const Handle(XCAFDoc_ColorTool) & CTool,
695 const TopoDS_Shape & S,
696 const Quantity_Color& col,
697 const XCAFDoc_ColorType type)
698{
699 for (TopoDS_Iterator it(S); it.More(); it.Next())
700 if (! CTool->SetColor( it.Value(), col, type)) break;
701}
702
703
704//=======================================================================
705//function : findStyledSR
706//purpose : auxilary
707//=======================================================================
708static void findStyledSR (const Handle(StepVisual_StyledItem) &style,
709 Handle(StepShape_ShapeRepresentation)& aSR)
710{
711 // search Shape Represenatation for component styled item
712 for ( Standard_Integer j=1; j <= style->NbStyles(); j++ ) {
713 Handle(StepVisual_PresentationStyleByContext) PSA =
714 Handle(StepVisual_PresentationStyleByContext)::DownCast(style->StylesValue ( j ));
715 if ( PSA.IsNull() )
716 continue;
717 StepVisual_StyleContextSelect aStyleCntxSlct = PSA->StyleContext();
718 Handle(StepShape_ShapeRepresentation) aCurrentSR =
719 Handle(StepShape_ShapeRepresentation)::DownCast(aStyleCntxSlct.Representation());
720 if ( aCurrentSR.IsNull() )
721 continue;
722 aSR = aCurrentSR;
723 break;
724 }
725}
726
727
728//=======================================================================
729//function : ReadColors
730//purpose :
731//=======================================================================
732
733Standard_Boolean STEPCAFControl_Reader::ReadColors (const Handle(XSControl_WorkSession) &WS,
734 Handle(TDocStd_Document)& Doc,
735 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
736 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
737{
738 STEPConstruct_Styles Styles ( WS );
739 if ( ! Styles.LoadStyles() ) {
740#ifdef DEB
741 cout << "Warning: no styles are found in the model" << endl;
742#endif
743 return Standard_False;
744 }
745 // searching for invisible items in the model
746 Handle(TColStd_HSequenceOfTransient) aHSeqOfInvisStyle = new TColStd_HSequenceOfTransient;
747 Styles.LoadInvisStyles( aHSeqOfInvisStyle );
748
749 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( Doc->Main() );
750 if ( CTool.IsNull() ) return Standard_False;
751
752 // parse and search for color attributes
753 Standard_Integer nb = Styles.NbStyles();
754 for ( Standard_Integer i=1; i <= nb; i++ ) {
755 Handle(StepVisual_StyledItem) style = Styles.Style ( i );
756 if ( style.IsNull() ) continue;
757
758 Standard_Boolean IsVisible = Standard_True;
759 // check the visibility of styled item.
760 for (Standard_Integer si = 1; si <= aHSeqOfInvisStyle->Length(); si++ ) {
761 if ( style != aHSeqOfInvisStyle->Value( si ) )
762 continue;
763 // found that current style is invisible.
7fd59977 764 IsVisible = Standard_False;
765 break;
766 }
767
768 Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol;
769 // check if it is component style
770 Standard_Boolean IsComponent = Standard_False;
771 if ( ! Styles.GetColors ( style, SurfCol, BoundCol, CurveCol, IsComponent ) && IsVisible )
772 continue;
773
774 // find shape
775 TopoDS_Shape S = STEPConstruct::FindShape ( Styles.TransientProcess(), style->Item() );
776 Standard_Boolean isSkipSHUOstyle = Standard_False;
777 // take shape with real location.
778 while ( IsComponent ) {
779 // take SR of NAUO
780 Handle(StepShape_ShapeRepresentation) aSR;
781 findStyledSR( style, aSR );
782 // search for SR along model
783 if (aSR.IsNull())
784 break;
785// Handle(Interface_InterfaceModel) Model = WS->Model();
786 Handle(XSControl_TransferReader) TR = WS->TransferReader();
787 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
788 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings( aSR );
789 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
790 for (subs.Start(); subs.More(); subs.Next()) {
791 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
792 if ( aSDR.IsNull() )
793 continue;
794 StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition();
795 Handle(StepRepr_ProductDefinitionShape) PDS =
796 Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition());
797 if ( PDS.IsNull() )
798 continue;
799 StepRepr_CharacterizedDefinition aCharDef = PDS->Definition();
800
801 Handle(StepRepr_AssemblyComponentUsage) ACU =
802 Handle(StepRepr_AssemblyComponentUsage)::DownCast(aCharDef.ProductDefinitionRelationship());
803 // PTV 10.02.2003 skip styled item that refer to SHUO
804 if (ACU->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) {
805 isSkipSHUOstyle = Standard_True;
806 break;
807 }
808 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
809 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(ACU);
810 if ( NAUO.IsNull() )
811 continue;
812
813 TopoDS_Shape aSh;
814 // PTV 10.02.2003 to find component of assembly CORRECTLY
815 STEPConstruct_Tool Tool( WS );
816 TDF_Label aShLab = FindInstance ( NAUO, CTool->ShapeTool(), Tool, PDFileMap, ShapeLabelMap );
817 aSh = CTool->ShapeTool()->GetShape(aShLab);
818// Handle(Transfer_Binder) binder = TP->Find(NAUO);
819// if ( binder.IsNull() || ! binder->HasResult() )
820// continue;
821// aSh = TransferBRep::ShapeResult ( TP, binder );
822 if (!aSh.IsNull()) {
823 S = aSh;
824 break;
825 }
826 }
827 break;
828 }
829 if (isSkipSHUOstyle)
830 continue; // skip styled item which refer to SHUO
831
36f35343 832 if ( S.IsNull() )
7fd59977 833 continue;
7fd59977 834
835 if ( ! SurfCol.IsNull() ) {
836 Quantity_Color col;
837 Styles.DecodeColor ( SurfCol, col );
838 if ( ! CTool->SetColor ( S, col, XCAFDoc_ColorSurf ))
839 SetColorToSubshape( CTool, S, col, XCAFDoc_ColorSurf );
840 }
841 if ( ! BoundCol.IsNull() ) {
842 Quantity_Color col;
843 Styles.DecodeColor ( BoundCol, col );
844 if ( ! CTool->SetColor ( S, col, XCAFDoc_ColorCurv ))
845 SetColorToSubshape( CTool, S, col, XCAFDoc_ColorCurv );
846 }
847 if ( ! CurveCol.IsNull() ) {
848 Quantity_Color col;
849 Styles.DecodeColor ( CurveCol, col );
850 if ( ! CTool->SetColor ( S, col, XCAFDoc_ColorCurv ))
851 SetColorToSubshape( CTool, S, col, XCAFDoc_ColorCurv );
852 }
853 if ( !IsVisible ) {
854 // sets the invisibility for shape.
855 TDF_Label aInvL;
856 if ( CTool->ShapeTool()->Search( S, aInvL ) )
857 CTool->SetVisibility( aInvL, Standard_False );
858 }
859 }
860 CTool->ReverseChainsOfTreeNodes();
861 return Standard_True;
862}
863
864//=======================================================================
865//function : GetLabelFromPD
866//purpose :
867//=======================================================================
868
869static TDF_Label GetLabelFromPD (const Handle(StepBasic_ProductDefinition) &PD,
870 const Handle(XCAFDoc_ShapeTool) &STool,
871 const Handle(Transfer_TransientProcess) &TP,
872 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
873 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
874{
875 TDF_Label L;
876 if ( PDFileMap.IsBound ( PD ) ) {
877 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find ( PD );
878 if ( ! EF.IsNull() ) {
879 L = EF->GetLabel();
880 if ( ! L.IsNull() ) return L;
881 }
882 }
883
884 TopoDS_Shape S;
885 Handle(Transfer_Binder) binder = TP->Find(PD);
886 if ( binder.IsNull() || ! binder->HasResult() ) return L;
887 S = TransferBRep::ShapeResult ( TP, binder );
888 if ( S.IsNull() ) return L;
889
890 if ( S.IsNull() ) return L;
891 if ( ShapeLabelMap.IsBound ( S ) )
892 L = ShapeLabelMap.Find ( S );
893 if ( L.IsNull() )
894 STool->Search ( S, L, Standard_True, Standard_True, Standard_False );
895 return L;
896}
897
898//=======================================================================
899//function : FindInstance
900//purpose :
901//=======================================================================
902
903TDF_Label STEPCAFControl_Reader::FindInstance (const Handle(StepRepr_NextAssemblyUsageOccurrence) &NAUO,
904 const Handle(XCAFDoc_ShapeTool) &STool,
905 const STEPConstruct_Tool &Tool,
906 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
907 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
908{
909 TDF_Label L;
910
911 // get shape resulting from CDSR (in fact, only location is interesting)
912 Handle(Transfer_TransientProcess) TP = Tool.TransientProcess();
913 Handle(Transfer_Binder) binder = TP->Find(NAUO);
914 if ( binder.IsNull() || ! binder->HasResult() ) {
915#ifdef DEB
916 cout << "Error: STEPCAFControl_Reader::FindInstance: NAUO is not mapped to shape" << endl;
917#endif
918 return L;
919 }
920
921 TopoDS_Shape S = TransferBRep::ShapeResult ( TP, binder );
922 if ( S.IsNull() ) {
923#ifdef DEB
924 cout << "Error: STEPCAFControl_Reader::FindInstance: NAUO is not mapped to shape" << endl;
925#endif
926 return L;
927 }
928
929 // find component`s original label
930 Handle(StepBasic_ProductDefinition) PD = NAUO->RelatedProductDefinition();
931 if ( PD.IsNull() ) return L;
932 TDF_Label Lref = GetLabelFromPD ( PD, STool, TP, PDFileMap, ShapeLabelMap );
933 if ( Lref.IsNull() ) return L;
934
935 // find main shape (assembly) label
936 PD.Nullify();
937 PD = NAUO->RelatingProductDefinition();
938 if ( PD.IsNull() ) return L;
939 TDF_Label L0 = GetLabelFromPD ( PD, STool, TP, PDFileMap, ShapeLabelMap );
940 if ( L0.IsNull() ) return L;
941
942 // if CDSR and NAUO are reversed, swap labels
943 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
944 Interface_EntityIterator subs1 = Tool.Graph().Sharings(NAUO);
945 for (subs1.Start(); subs1.More(); subs1.Next()) {
946 Handle(StepRepr_ProductDefinitionShape) PDS =
947 Handle(StepRepr_ProductDefinitionShape)::DownCast(subs1.Value());
948 if(PDS.IsNull()) continue;
949 Interface_EntityIterator subs2 = Tool.Graph().Sharings(PDS);
950 for (subs2.Start(); subs2.More(); subs2.Next()) {
951 Handle(StepShape_ContextDependentShapeRepresentation) CDSRtmp =
952 Handle(StepShape_ContextDependentShapeRepresentation)::DownCast(subs2.Value());
953 if (CDSRtmp.IsNull()) continue;
954 CDSR = CDSRtmp;
955 }
956 }
957 if (CDSR.IsNull()) return L;
958// if ( STEPConstruct_Assembly::CheckSRRReversesNAUO ( Tool.Model(), CDSR ) ) {
959// TDF_Label Lsw = L0; L0 = Lref; Lref = Lsw;
960// }
961
962 // iterate on components to find proper one
963 TDF_LabelSequence seq;
964 XCAFDoc_ShapeTool::GetComponents ( L0, seq );
965 for ( Standard_Integer k=1; L.IsNull() && k <= seq.Length(); k++ ) {
966 TDF_Label Lcomp = seq(k), Lref2;
967 if ( XCAFDoc_ShapeTool::GetReferredShape ( Lcomp, Lref2 ) &&
968 Lref2 == Lref &&
969 S.Location() == XCAFDoc_ShapeTool::GetLocation ( Lcomp ) )
970 L = Lcomp;
971 }
972
973 return L;
974}
975
976//=======================================================================
977//function : ReadNames
978//purpose :
979//=======================================================================
980
981Standard_Boolean STEPCAFControl_Reader::ReadNames (const Handle(XSControl_WorkSession) &WS,
982 Handle(TDocStd_Document)& Doc,
983 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
984 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
985{
986 // get starting data
987 Handle(Interface_InterfaceModel) Model = WS->Model();
988 Handle(XSControl_TransferReader) TR = WS->TransferReader();
989 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
990 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
991 if ( STool.IsNull() ) return Standard_False;
992 STEPConstruct_Tool Tool ( WS );
993
994 // iterate on model to find all SDRs and CDSRs
995 Standard_Integer nb = Model->NbEntities();
996 Handle(Standard_Type) tNAUO = STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence);
997 Handle(Standard_Type) tPD = STANDARD_TYPE(StepBasic_ProductDefinition);
998 Handle(TCollection_HAsciiString) name;
999 TDF_Label L;
1000 for (Standard_Integer i = 1; i <= nb; i++) {
1001 Handle(Standard_Transient) enti = Model->Value(i);
1002
1003 // get description of NAUO
1004 if ( enti->DynamicType() == tNAUO ) {
1005 L.Nullify();
1006 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
1007 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(enti);
1008 if(NAUO.IsNull()) continue;
1009 Interface_EntityIterator subs = WS->Graph().Sharings(NAUO);
1010 for (subs.Start(); subs.More(); subs.Next()) {
1011 Handle(StepRepr_ProductDefinitionShape) PDS =
1012 Handle(StepRepr_ProductDefinitionShape)::DownCast(subs.Value());
1013 if(PDS.IsNull()) continue;
1014 Handle(StepBasic_ProductDefinitionRelationship) PDR = PDS->Definition().ProductDefinitionRelationship();
1015 if ( PDR.IsNull() ) continue;
1016 if ( PDR->HasDescription() &&
1017 PDR->Description()->Length() >0 ) name = PDR->Description();
1018 else if ( PDR->Name()->Length() >0 ) name = PDR->Name();
1019 else name = PDR->Id();
1020 }
1021 // find proper label
1022 L = FindInstance ( NAUO, STool, Tool, PDFileMap, ShapeLabelMap );
1023 if ( L.IsNull() ) continue;
1024 TCollection_ExtendedString str ( name->String() );
1025 TDataStd_Name::Set ( L, str );
1026 }
1027
1028 // for PD get name of associated product
1029 if ( enti->DynamicType() == tPD ) {
1030 L.Nullify();
1031 Handle(StepBasic_ProductDefinition) PD =
1032 Handle(StepBasic_ProductDefinition)::DownCast(enti);
1033 if(PD.IsNull()) continue;
1034 Handle(StepBasic_Product) Prod = PD->Formation()->OfProduct();
1035 if(Prod->Name()->UsefullLength()>0) name = Prod->Name();
1036 else name = Prod->Id();
1037 L = GetLabelFromPD ( PD, STool, TP, PDFileMap, ShapeLabelMap );
1038 if ( L.IsNull() ) continue;
1039 TCollection_ExtendedString str ( name->String() );
1040 TDataStd_Name::Set ( L, str );
1041 }
1042 // set a name to the document
1043 //TCollection_ExtendedString str ( name->String() );
1044 //TDataStd_Name::Set ( L, str );
1045 }
1046
1047 return Standard_True;
1048}
1049
1050//=======================================================================
1051//function : GetLabelFromPD
1052//purpose :
1053//=======================================================================
1054
1055static TDF_Label GetLabelFromPD (const Handle(StepBasic_ProductDefinition) &PD,
1056 const Handle(XCAFDoc_ShapeTool) &STool,
1057 const STEPConstruct_ValidationProps &Props,
1058 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1059 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1060{
1061 TDF_Label L;
1062 if ( PDFileMap.IsBound ( PD ) ) {
1063 Handle(STEPCAFControl_ExternFile) EF = PDFileMap.Find ( PD );
1064 if ( ! EF.IsNull() ) {
1065 L = EF->GetLabel();
1066 if ( ! L.IsNull() ) return L;
1067 }
1068 }
1069 TopoDS_Shape S = Props.GetPropShape ( PD );
1070 if ( S.IsNull() ) return L;
1071 if ( ShapeLabelMap.IsBound ( S ) )
1072 L = ShapeLabelMap.Find ( S );
1073 if ( L.IsNull() )
1074 STool->Search ( S, L, Standard_True, Standard_True, Standard_False );
1075 return L;
1076}
1077
1078//=======================================================================
1079//function : ReadValProps
1080//purpose :
1081//=======================================================================
1082
1083Standard_Boolean STEPCAFControl_Reader::ReadValProps (const Handle(XSControl_WorkSession) &WS,
1084 Handle(TDocStd_Document)& Doc,
1085 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1086 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
1087{
1088 // get starting data
1089 Handle(Interface_InterfaceModel) Model = WS->Model();
1090 Handle(XSControl_TransferReader) TR = WS->TransferReader();
1091 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1092 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
1093 if ( STool.IsNull() ) return Standard_False;
1094
1095 // load props from the STEP model
1096 TColStd_SequenceOfTransient props;
1097 STEPConstruct_ValidationProps Props ( WS );
1098 if ( ! Props.LoadProps ( props ) ) {
1099#ifdef DEB
1100 cout << "Warning: no validation props found in the model" << endl;
1101#endif
1102 return Standard_False;
1103 }
1104
1105 // interpret props one by one
1106 for (Standard_Integer i = 1; i <= props.Length(); i ++) {
1107 Handle(StepRepr_PropertyDefinitionRepresentation) PDR =
1108 Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast ( props.Value(i) );
1109 if ( PDR.IsNull() ) continue;
1110
1111 TDF_Label L;
1112
1113 Handle(StepRepr_PropertyDefinition) PD = PDR->Definition().PropertyDefinition();
1114 Interface_EntityIterator subs = Props.Graph().Shareds(PD);
1115 for (subs.Start(); L.IsNull() && subs.More(); subs.Next()) {
1116 if ( subs.Value()->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape)) ) {
1117 Handle(StepRepr_ProductDefinitionShape) PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(subs.Value());
1118 if(PDS.IsNull()) continue;
1119 // find corresponding NAUO
1120 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO;
1121 Interface_EntityIterator subs1 = Props.Graph().Shareds(PDS);
1122 for (subs1.Start(); NAUO.IsNull() && subs1.More(); subs1.Next()) {
1123 if ( subs1.Value()->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence)) )
1124 NAUO = Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs1.Value());
1125 }
1126 if ( !NAUO.IsNull() ) {
1127 L = FindInstance ( NAUO, STool, WS, PDFileMap, ShapeLabelMap );
1128 if ( L.IsNull() ) continue;
1129 }
1130 else {
1131 // find corresponding ProductDefinition:
1132 Handle(StepBasic_ProductDefinition) ProdDef;
1133 Interface_EntityIterator subsPDS = Props.Graph().Shareds(PDS);
1134 for (subsPDS.Start(); ProdDef.IsNull() && subsPDS.More(); subsPDS.Next()) {
1135 if ( subsPDS.Value()->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition)) )
1136 ProdDef = Handle(StepBasic_ProductDefinition)::DownCast(subsPDS.Value());
1137 }
1138 if ( ProdDef.IsNull() ) continue;
1139 L = GetLabelFromPD ( ProdDef, STool, Props, PDFileMap, ShapeLabelMap );
1140 }
1141 }
1142
1143 if ( subs.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect)) ) {
1144 Handle(StepRepr_ShapeAspect) SA = Handle(StepRepr_ShapeAspect)::DownCast(subs.Value());
1145 if(SA.IsNull()) continue;
1146 // find ShapeRepresentation
1147 Handle(StepShape_ShapeRepresentation) SR;
1148 Interface_EntityIterator subs1 = Props.Graph().Sharings(SA);
1149 for(subs1.Start(); subs1.More() && SR.IsNull(); subs1.Next()) {
1150 Handle(StepRepr_PropertyDefinition) PropD1 =
1151 Handle(StepRepr_PropertyDefinition)::DownCast(subs1.Value());
1152 if(PropD1.IsNull()) continue;
1153 Interface_EntityIterator subs2 = Props.Graph().Sharings(PropD1);
1154 for(subs2.Start(); subs2.More() && SR.IsNull(); subs2.Next()) {
1155 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
1156 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs2.Value());
1157 if(SDR.IsNull()) continue;
1158 SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation());
1159 }
1160 }
1161 if(SR.IsNull()) continue;
1162 Handle(Transfer_Binder) binder;
1163 for(Standard_Integer ir=1; ir<=SR->NbItems() && binder.IsNull(); ir++) {
1164 if(SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_SolidModel))) {
1165 Handle(StepShape_SolidModel) SM =
1166 Handle(StepShape_SolidModel)::DownCast(SR->ItemsValue(ir));
1167 binder = TP->Find(SM);
1168 }
1169 else if(SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel))) {
1170 Handle(StepShape_ShellBasedSurfaceModel) SBSM =
1171 Handle(StepShape_ShellBasedSurfaceModel)::DownCast(SR->ItemsValue(ir));
1172 binder = TP->Find(SBSM);
1173 }
1174 else if(SR->ItemsValue(ir)->IsKind(STANDARD_TYPE(StepShape_GeometricSet))) {
1175 Handle(StepShape_GeometricSet) GS =
1176 Handle(StepShape_GeometricSet)::DownCast(SR->ItemsValue(ir));
1177 binder = TP->Find(GS);
1178 }
1179 }
1180 if ( binder.IsNull() || ! binder->HasResult() ) continue;
1181 TopoDS_Shape S;
1182 S = TransferBRep::ShapeResult ( TP, binder );
1183 if(S.IsNull()) continue;
1184 if ( ShapeLabelMap.IsBound ( S ) )
1185 L = ShapeLabelMap.Find ( S );
1186 if ( L.IsNull() )
1187 STool->Search ( S, L, Standard_True, Standard_True, Standard_True );
1188 }
1189 }
1190
1191 if(L.IsNull()) continue;
1192
1193 // decode validation properties
1194 Handle(StepRepr_Representation) rep = PDR->UsedRepresentation();
1195 for ( Standard_Integer j=1; j <= rep->NbItems(); j++ ) {
1196 Handle(StepRepr_RepresentationItem) ent = rep->ItemsValue(j);
1197 Standard_Boolean isArea;
1198 Standard_Real val;
1199 gp_Pnt pos;
1200 if ( Props.GetPropReal ( ent, val, isArea ) ) {
1201 if ( isArea ) XCAFDoc_Area::Set ( L, val );
1202 else XCAFDoc_Volume::Set ( L, val );
1203 }
1204 else if ( Props.GetPropPnt ( ent, rep->ContextOfItems(), pos ) ) {
1205 XCAFDoc_Centroid::Set ( L, pos );
1206 }
1207 }
1208 }
1209 return Standard_True;
1210}
1211
1212//=======================================================================
1213//function : ReadLayers
1214//purpose :
1215//=======================================================================
1216
1217Standard_Boolean STEPCAFControl_Reader::ReadLayers (const Handle(XSControl_WorkSession) &WS,
1218 Handle(TDocStd_Document)& Doc) const
1219{
1220 Handle(Interface_InterfaceModel) Model = WS->Model();
1221 Handle(XSControl_TransferReader) TR = WS->TransferReader();
1222 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1223 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
1224 if ( STool.IsNull() ) return Standard_False;
1225 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool( Doc->Main() );
1226 if ( LTool.IsNull() ) return Standard_False;
1227
1228 Handle(Standard_Type) tSVPLA = STANDARD_TYPE(StepVisual_PresentationLayerAssignment);
1229 Standard_Integer nb = Model->NbEntities();
1230 Handle(TCollection_HAsciiString) name;
1231
1232 for (Standard_Integer i = 1; i <= nb; i ++) {
1233 Handle(Standard_Transient) enti = Model->Value(i);
1234 if ( ! enti->IsKind ( tSVPLA ) ) continue;
1235 Handle(StepVisual_PresentationLayerAssignment) SVPLA =
1236 Handle(StepVisual_PresentationLayerAssignment)::DownCast(enti);
1237
1238 Handle(TCollection_HAsciiString) descr = SVPLA->Description();
1239 Handle(TCollection_HAsciiString) hName = SVPLA->Name();
1240 TCollection_ExtendedString aLayerName ( hName->String() );
1241
1242 // find a target shape and its label in the document
1243 for (Standard_Integer j = 1; j <= SVPLA->NbAssignedItems(); j++ ) {
1244 StepVisual_LayeredItem LI = SVPLA->AssignedItemsValue(j);
1245 Handle(Transfer_Binder) binder = TP->Find( LI.Value() );
1246 if ( binder.IsNull() || ! binder->HasResult() ) continue;
1247
1248 TopoDS_Shape S = TransferBRep::ShapeResult ( TP, binder );
1249 if ( S.IsNull() ) continue;
1250
1251 TDF_Label shL;
1252 if ( ! STool->Search ( S, shL, Standard_True, Standard_True, Standard_True ) ) continue;
1253 LTool->SetLayer ( shL, aLayerName );
1254 }
1255
1256 // check invisibility
1257 Interface_EntityIterator subs = WS->Graph().Sharings(SVPLA);
1258 for (subs.Start(); subs.More(); subs.Next()) {
1259 if ( ! subs.Value()->IsKind(STANDARD_TYPE(StepVisual_Invisibility)) ) continue;
1260#ifdef DEB
1261 cout<< "\tLayer \"" << aLayerName << "\" is invisible"<<endl;
1262#endif
1263 //TDF_Label InvLayerLab = LTool->FindLayer(aLayerName);
1264 TDF_Label InvLayerLab = LTool->AddLayer(aLayerName); //skl for OCC3926
1265 Handle(TDataStd_UAttribute) aUAttr;
1266 aUAttr->Set( InvLayerLab, XCAFDoc::InvisibleGUID() );
1267 }
1268 }
1269 return Standard_True;
1270}
1271
1272//=======================================================================
1273//function : ReadSHUOs
1274//purpose :
1275//=======================================================================
1276
1277static Standard_Boolean findNextSHUOlevel (const Handle(XSControl_WorkSession) &WS,
1278 const Handle(StepRepr_SpecifiedHigherUsageOccurrence)& SHUO,
1279 const Handle(XCAFDoc_ShapeTool)& STool,
1280 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1281 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap,
1282 TDF_LabelSequence& aLabels)
1283{
1284 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings(SHUO);
1285 Handle(StepRepr_SpecifiedHigherUsageOccurrence) subSHUO;
1286 for (subs.Start(); subs.More(); subs.Next()) {
1287 if (subs.Value()->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) {
1288 subSHUO = Handle(StepRepr_SpecifiedHigherUsageOccurrence)::DownCast(subs.Value());
1289 break;
1290 }
1291 }
1292 if (subSHUO.IsNull())
1293 return Standard_False;
1294
1295 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO =
1296 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subSHUO->NextUsage());
1297 if (NUNAUO.IsNull())
1298 return Standard_False;
1299// Handle(Interface_InterfaceModel) Model = WS->Model();
1300// Handle(XSControl_TransferReader) TR = WS->TransferReader();
1301// Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1302// Handle(Transfer_Binder) binder = TP->Find(NUNAUO);
1303// if ( binder.IsNull() || ! binder->HasResult() )
1304// return Standard_False;
1305// TopoDS_Shape NUSh = TransferBRep::ShapeResult ( TP, binder );
1306 // get label of NAUO next level
1307 TDF_Label NULab;
1308 STEPConstruct_Tool Tool( WS );
1309 NULab = STEPCAFControl_Reader::FindInstance ( NUNAUO, STool, Tool, PDFileMap, ShapeLabelMap );
1310// STool->Search(NUSh, NUlab);
1311 if (NULab.IsNull())
1312 return Standard_False;
1313 aLabels.Append( NULab );
1314 // and check by recurse.
1315 findNextSHUOlevel( WS, subSHUO, STool, PDFileMap, ShapeLabelMap, aLabels );
1316 return Standard_True;
1317}
1318
1319
1320//=======================================================================
1321//function : setSHUOintoDoc
1322//purpose : auxilary
1323//=======================================================================
1324static TDF_Label setSHUOintoDoc (const Handle(XSControl_WorkSession) &WS,
1325 const Handle(StepRepr_SpecifiedHigherUsageOccurrence)& SHUO,
1326 const Handle(XCAFDoc_ShapeTool)& STool,
1327 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1328 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap)
1329{
1330 TDF_Label aMainLabel;
1331 // get upper usage NAUO from SHUO.
1332 Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO =
1333 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(SHUO->UpperUsage());
1334 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO =
1335 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(SHUO->NextUsage());
1336 if ( UUNAUO.IsNull() || NUNAUO.IsNull() ) {
1337#ifdef DEB
1338 cout << "Warning: " << __FILE__ <<": Upper_usage or Next_usage of styled SHUO is null. Skip it" << endl;
1339#endif
1340 return aMainLabel;
1341 }
1342// Handle(Interface_InterfaceModel) Model = WS->Model();
1343// Handle(XSControl_TransferReader) TR = WS->TransferReader();
1344// Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1345// TopoDS_Shape UUSh, NUSh;
1346// Handle(Transfer_Binder) binder = TP->Find(UUNAUO);
1347// if ( binder.IsNull() || ! binder->HasResult() )
1348// return aMainLabel;
1349// UUSh = TransferBRep::ShapeResult ( TP, binder );
1350// binder = TP->Find(NUNAUO);
1351// if ( binder.IsNull() || ! binder->HasResult() )
1352// return aMainLabel;
1353// NUSh = TransferBRep::ShapeResult ( TP, binder );
1354
1355 // get first labels for first SHUO attribute
1356 TDF_Label UULab, NULab;
1357 STEPConstruct_Tool Tool( WS );
1358 UULab = STEPCAFControl_Reader::FindInstance ( UUNAUO, STool, Tool, PDFileMap, ShapeLabelMap );
1359 NULab = STEPCAFControl_Reader::FindInstance ( NUNAUO, STool, Tool, PDFileMap, ShapeLabelMap );
1360
1361// STool->Search(UUSh, UULab);
1362// STool->Search(NUSh, NULab);
1363 if (UULab.IsNull() || NULab.IsNull()) return aMainLabel;
1364 //create sequence fo labels to set SHUO structure into the document
1365 TDF_LabelSequence ShuoLabels;
1366 ShuoLabels.Append( UULab );
1367 ShuoLabels.Append( NULab );
1368 // add all other labels of sub SHUO entities
1369 findNextSHUOlevel( WS, SHUO, STool, PDFileMap, ShapeLabelMap, ShuoLabels );
1370 // last accord for SHUO
1371 Handle(XCAFDoc_GraphNode) anSHUOAttr;
1372 if ( STool->SetSHUO( ShuoLabels, anSHUOAttr ) )
1373 aMainLabel = anSHUOAttr->Label();
1374
1375 return aMainLabel;
1376}
1377
1378
1379//=======================================================================
1380//function : ReadSHUOs
1381//purpose :
1382//=======================================================================
1383
1384Standard_Boolean STEPCAFControl_Reader::ReadSHUOs (const Handle(XSControl_WorkSession) &WS,
1385 Handle(TDocStd_Document)& Doc,
1386 const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
1387 const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
1388{
1389 // the big part code duplication from ReadColors.
1390 // It is possible to share this code functionality, just to decide how ???
1391 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( Doc->Main() );
1392 Handle(XCAFDoc_ShapeTool) STool = CTool->ShapeTool();
1393
1394 STEPConstruct_Styles Styles ( WS );
1395 if ( ! Styles.LoadStyles() ) {
1396#ifdef DEB
1397 cout << "Warning: no styles are found in the model" << endl;
1398#endif
1399 return Standard_False;
1400 }
1401 // searching for invisible items in the model
1402 Handle(TColStd_HSequenceOfTransient) aHSeqOfInvisStyle = new TColStd_HSequenceOfTransient;
1403 Styles.LoadInvisStyles( aHSeqOfInvisStyle );
1404 // parse and search for color attributes
1405 Standard_Integer nb = Styles.NbStyles();
1406 for ( Standard_Integer i=1; i <= nb; i++ ) {
1407 Handle(StepVisual_StyledItem) style = Styles.Style ( i );
1408 if ( style.IsNull() ) continue;
1409
1410 Standard_Boolean IsVisible = Standard_True;
1411 // check the visibility of styled item.
1412 for (Standard_Integer si = 1; si <= aHSeqOfInvisStyle->Length(); si++ ) {
1413 if ( style != aHSeqOfInvisStyle->Value( si ) )
1414 continue;
1415 // found that current style is invisible.
1416#ifdef DEB
1417 cout << "Warning: item No " << i << "(" << style->Item()->DynamicType()->Name() << ") is invisible" << endl;
1418#endif
1419 IsVisible = Standard_False;
1420 break;
1421 }
1422
1423 Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol;
1424 // check if it is component style
1425 Standard_Boolean IsComponent = Standard_False;
1426 if ( ! Styles.GetColors ( style, SurfCol, BoundCol, CurveCol, IsComponent ) && IsVisible )
1427 continue;
1428 if (!IsComponent)
1429 continue;
1430 Handle(StepShape_ShapeRepresentation) aSR;
1431 findStyledSR( style, aSR );
1432 // search for SR along model
1433 if ( aSR.IsNull() )
1434 continue;
1435 Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings( aSR );
1436 Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
1437 for (subs.Start(); subs.More(); subs.Next()) {
1438 aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
1439 if ( aSDR.IsNull() )
1440 continue;
1441 StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition();
1442 Handle(StepRepr_ProductDefinitionShape) PDS =
1443 Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition());
1444 if ( PDS.IsNull() )
1445 continue;
1446 StepRepr_CharacterizedDefinition aCharDef = PDS->Definition();
1447 Handle(StepRepr_SpecifiedHigherUsageOccurrence) SHUO =
1448 Handle(StepRepr_SpecifiedHigherUsageOccurrence)::DownCast(aCharDef.ProductDefinitionRelationship());
1449 if ( SHUO.IsNull() )
1450 continue;
1451
1452 // set the SHUO structure to the document
1453 TDF_Label aLabelForStyle = setSHUOintoDoc( WS, SHUO, STool, PDFileMap, ShapeLabelMap );
1454 if ( aLabelForStyle.IsNull() ) {
1455#ifdef DEB
1456 cout << "Warning: " << __FILE__ <<": coudnot create SHUO structure in the document" << endl;
1457#endif
1458 continue;
1459 }
1460 // now set the style to the SHUO main label.
1461 if ( ! SurfCol.IsNull() ) {
1462 Quantity_Color col;
1463 Styles.DecodeColor ( SurfCol, col );
1464 CTool->SetColor ( aLabelForStyle, col, XCAFDoc_ColorSurf );
1465 }
1466 if ( ! BoundCol.IsNull() ) {
1467 Quantity_Color col;
1468 Styles.DecodeColor ( BoundCol, col );
1469 CTool->SetColor ( aLabelForStyle, col, XCAFDoc_ColorCurv );
1470 }
1471 if ( ! CurveCol.IsNull() ) {
1472 Quantity_Color col;
1473 Styles.DecodeColor ( CurveCol, col );
1474 CTool->SetColor ( aLabelForStyle, col, XCAFDoc_ColorCurv );
1475 }
1476 if ( !IsVisible )
1477 // sets the invisibility for shape.
1478 CTool->SetVisibility( aLabelForStyle, Standard_False );
1479
1480 } // end search SHUO by SDR
1481 } // end iterates on styles
1482
1483 return Standard_True;
1484}
1485
1486
1487//=======================================================================
1488//function : GetLengthConversionFactor
1489//purpose :
1490//=======================================================================
1491static Standard_Boolean GetLengthConversionFactor(Handle(StepBasic_NamedUnit)& NU,
1492 Standard_Real& afact)
1493{
1494 afact=1.;
1495 if( !NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit)) ) return Standard_False;
1496 Handle(StepBasic_ConversionBasedUnitAndLengthUnit) CBULU =
1497 Handle(StepBasic_ConversionBasedUnitAndLengthUnit)::DownCast(NU);
1498 Handle(StepBasic_MeasureWithUnit) MWUCBU = CBULU->ConversionFactor();
1499 afact = MWUCBU->ValueComponent();
1500 StepBasic_Unit anUnit2 = MWUCBU->UnitComponent();
1501 if(anUnit2.CaseNum(anUnit2.Value())==1) {
1502 Handle(StepBasic_NamedUnit) NU2 = anUnit2.NamedUnit();
1503 if(NU2->IsKind(STANDARD_TYPE(StepBasic_SiUnit))) {
1504 Handle(StepBasic_SiUnit) SU = Handle(StepBasic_SiUnit)::DownCast(NU2);
1505 if(SU->Name()==StepBasic_sunMetre) {
1506 if(SU->HasPrefix())
1507 afact *= STEPConstruct_UnitContext::ConvertSiPrefix (SU->Prefix());
1508 // convert m to mm
1509 afact *= 1000.;
1510 }
1511 }
1512 }
1513 return Standard_True;
1514}
1515
1516
1517//=======================================================================
1518//function : GetMassConversionFactor
1519//purpose :
1520//=======================================================================
1521static Standard_Boolean GetMassConversionFactor(Handle(StepBasic_NamedUnit)& NU,
1522 Standard_Real& afact)
1523{
1524 afact=1.;
1525 if( !NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit)) ) return Standard_False;
1526 Handle(StepBasic_ConversionBasedUnitAndMassUnit) CBUMU =
1527 Handle(StepBasic_ConversionBasedUnitAndMassUnit)::DownCast(NU);
1528 Handle(StepBasic_MeasureWithUnit) MWUCBU = CBUMU->ConversionFactor();
1529 afact = MWUCBU->ValueComponent();
1530 StepBasic_Unit anUnit2 = MWUCBU->UnitComponent();
1531 if(anUnit2.CaseNum(anUnit2.Value())==1) {
1532 Handle(StepBasic_NamedUnit) NU2 = anUnit2.NamedUnit();
1533 if(NU2->IsKind(STANDARD_TYPE(StepBasic_SiUnit))) {
1534 Handle(StepBasic_SiUnit) SU = Handle(StepBasic_SiUnit)::DownCast(NU2);
1535 if(SU->Name()==StepBasic_sunGram) {
1536 if(SU->HasPrefix())
1537 afact *= STEPConstruct_UnitContext::ConvertSiPrefix (SU->Prefix());
1538 }
1539 }
1540 }
1541 return Standard_True;
1542}
1543
1544
1545//=======================================================================
1546//function : ReadDatums
1547//purpose : auxilary
1548//=======================================================================
1549static Standard_Boolean ReadDatums(const Handle(XCAFDoc_ShapeTool) &STool,
1550 const Handle(XCAFDoc_DimTolTool) &DGTTool,
1551 const Interface_Graph &graph,
1552 Handle(Transfer_TransientProcess) &TP,
1553 const TDF_Label TolerL,
1554 const Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR)
1555{
1556 if(GTWDR.IsNull()) return Standard_False;
1557 Handle(StepDimTol_HArray1OfDatumReference) HADR = GTWDR->DatumSystem();
1558 if(HADR.IsNull()) return Standard_False;
1559 for(Standard_Integer idr=1; idr<=HADR->Length(); idr++) {
1560 Handle(StepDimTol_DatumReference) DR = HADR->Value(idr);
1561 Handle(StepDimTol_Datum) aDatum = DR->ReferencedDatum();
1562 if(aDatum.IsNull()) continue;
1563 Interface_EntityIterator subs4 = graph.Sharings(aDatum);
1564 for(subs4.Start(); subs4.More(); subs4.Next()) {
1565 Handle(StepRepr_ShapeAspectRelationship) SAR =
1566 Handle(StepRepr_ShapeAspectRelationship)::DownCast(subs4.Value());
1567 if(SAR.IsNull()) continue;
1568 Handle(StepDimTol_DatumFeature) DF =
1569 Handle(StepDimTol_DatumFeature)::DownCast(SAR->RelatingShapeAspect());
1570 if(DF.IsNull()) continue;
1571 Interface_EntityIterator subs5 = graph.Sharings(DF);
1572 Handle(StepRepr_PropertyDefinition) PropDef;
1573 for(subs5.Start(); subs5.More() && PropDef.IsNull(); subs5.Next()) {
1574 PropDef = Handle(StepRepr_PropertyDefinition)::DownCast(subs5.Value());
1575 }
1576 if(PropDef.IsNull()) continue;
1577 Handle(StepShape_AdvancedFace) AF;
1578 subs5 = graph.Sharings(PropDef);
1579 for(subs5.Start(); subs5.More(); subs5.Next()) {
1580 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
1581 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs5.Value());
1582 if(!SDR.IsNull()) {
1583 Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation();
1584 if( !Repr.IsNull() && Repr->NbItems()>0 ) {
1585 Handle(StepRepr_RepresentationItem) RI = Repr->ItemsValue(1);
1586 AF = Handle(StepShape_AdvancedFace)::DownCast(RI);
1587 }
1588 }
1589 }
1590 if(AF.IsNull()) return Standard_False;
1591 Standard_Integer index = TP->MapIndex(AF);
1592 TopoDS_Shape aSh;
1593 if(index >0) {
1594 Handle(Transfer_Binder) binder = TP->MapItem(index);
1595 aSh = TransferBRep::ShapeResult(binder);
1596 }
1597 if(aSh.IsNull()) continue;
1598 TDF_Label shL;
1599 if( !STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
1600 DGTTool->SetDatum(shL,TolerL,PropDef->Name(),PropDef->Description(),aDatum->Identification());
1601 }
1602 }
1603 return Standard_True;
1604}
1605
1606
1607//=======================================================================
1608//function : ReadGDTs
1609//purpose :
1610//=======================================================================
1611
1612Standard_Boolean STEPCAFControl_Reader::ReadGDTs(const Handle(XSControl_WorkSession) &WS,
1613 Handle(TDocStd_Document)& Doc) const
1614{
1615 Handle(Interface_InterfaceModel) Model = WS->Model();
1616 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
1617 Handle(XSControl_TransferReader) TR = WS->TransferReader();
1618 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1619 Handle(XCAFDoc_DimTolTool) DGTTool = XCAFDoc_DocumentTool::DimTolTool( Doc->Main() );
1620 if ( DGTTool.IsNull() ) return Standard_False;
1621
1622 Standard_Integer nb = Model->NbEntities();
1623 const Interface_Graph& graph = TP->Graph();
1624 for(Standard_Integer i=1; i<=nb; i++) {
1625 Handle(Standard_Transient) ent = Model->Value(i);
1626 if(ent->IsKind(STANDARD_TYPE(StepRepr_ShapeAspect))) {
1627 Handle(StepRepr_ShapeAspect) SA = Handle(StepRepr_ShapeAspect)::DownCast(ent);
1628 // find RepresentationItem for current ShapeAspect
1629 Handle(StepRepr_RepresentationItem) RI;
1630 Handle(StepRepr_PropertyDefinition) PropD;
1631 Interface_EntityIterator subs3 = graph.Sharings(SA);
1632 for(subs3.Start(); subs3.More() && PropD.IsNull(); subs3.Next()) {
1633 PropD = Handle(StepRepr_PropertyDefinition)::DownCast(subs3.Value());
1634 }
1635 if(PropD.IsNull()) continue;
1636 Interface_EntityIterator subs4 = graph.Sharings(PropD);
1637 for(subs4.Start(); subs4.More(); subs4.Next()) {
1638 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
1639 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs4.Value());
1640 if(!SDR.IsNull()) {
1641 Handle(StepRepr_Representation) Repr = SDR->UsedRepresentation();
1642 if( !Repr.IsNull() && Repr->NbItems()>0 ) {
1643 RI = Repr->ItemsValue(1);
1644 }
1645 }
1646 }
1647 if(RI.IsNull()) continue;
1648 // read DGT entities:
1649 subs3 = graph.Sharings(SA);
1650 for(subs3.Start(); subs3.More(); subs3.Next()) {
1651 if(subs3.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) {
1652 // read dimensions
1653 Handle(StepShape_EdgeCurve) EC = Handle(StepShape_EdgeCurve)::DownCast(RI);
1654 if(EC.IsNull()) continue;
1655 Handle(TCollection_HAsciiString) aName;
1656 Handle(StepShape_DimensionalSize) DimSize =
1657 Handle(StepShape_DimensionalSize)::DownCast(subs3.Value());
1658 Standard_Real dim1=-1.,dim2=-1.;
1659 subs4 = graph.Sharings(DimSize);
1660 for(subs4.Start(); subs4.More(); subs4.Next()) {
1661 Handle(StepShape_DimensionalCharacteristicRepresentation) DimCharR =
1662 Handle(StepShape_DimensionalCharacteristicRepresentation)::DownCast(subs4.Value());
1663 if(!DimCharR.IsNull()) {
1664 Handle(StepShape_ShapeDimensionRepresentation) SDimR = DimCharR->Representation();
1665 if(!SDimR.IsNull() && SDimR->NbItems()>0) {
1666 Handle(StepRepr_RepresentationItem) RI = SDimR->ItemsValue(1);
1667 Handle(StepRepr_ValueRange) VR = Handle(StepRepr_ValueRange)::DownCast(RI);
1668 if(!VR.IsNull()) {
1669 aName = VR->Name();
1670 //StepRepr_CompoundItemDefinition CID = VR->ItemElement();
1671 //if(CID.IsNull()) continue;
1672 //Handle(StepRepr_CompoundItemDefinitionMember) CIDM =
1673 // Handle(StepRepr_CompoundItemDefinitionMember)::DownCast(CID.Value());
1674 //if(CIDM.IsNull()) continue;
1675 //if(CIDM->ArrTransient().IsNull()) continue;
1676 //Handle(StepRepr_HArray1OfRepresentationItem) HARI;
1677 //if(CID.CaseMem(CIDM)==1)
1678 // HARI = CID.ListRepresentationItem();
1679 //if(CID.CaseMem(CIDM)==2)
1680 // HARI = CID.SetRepresentationItem();
1681 Handle(StepRepr_HArray1OfRepresentationItem) HARI = VR->ItemElement();
1682 if(HARI.IsNull()) continue;
1683 if(HARI->Length()>0) {
1684 Handle(StepRepr_RepresentationItem) RI1 =
1685 Handle(StepRepr_RepresentationItem)::DownCast(HARI->Value(1));
1686 if(RI1.IsNull()) continue;
1687 if(RI1->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
1688 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU =
1689 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI1);
1690 dim1 = RILMWU->GetMeasureWithUnit()->ValueComponent();
1691 StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent();
1692 Standard_Real afact=1.;
1693 if(anUnit.IsNull()) continue;
1694 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
1695 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
1696 if(GetLengthConversionFactor(NU,afact)) dim1=dim1*afact;
1697 }
1698 }
1699 if(HARI->Length()>1) {
1700 Handle(StepRepr_RepresentationItem) RI2 =
1701 Handle(StepRepr_RepresentationItem)::DownCast(HARI->Value(2));
1702 if(RI2.IsNull()) continue;
1703 if(RI2->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit))) {
1704 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMWU =
1705 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(RI2);
1706 dim2 = RILMWU->GetMeasureWithUnit()->ValueComponent();
1707 StepBasic_Unit anUnit = RILMWU->GetMeasureWithUnit()->UnitComponent();
1708 Standard_Real afact=1.;
1709 if(anUnit.IsNull()) continue;
1710 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
1711 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
1712 if(GetLengthConversionFactor(NU,afact)) dim2 = dim2*afact;
1713 }
1714 }
1715 }
1716 }
1717 }
1718 }
1719 if(dim1<0) continue;
1720 if(dim2<0) dim2=dim1;
1721 //cout<<"DimensionalSize: dim1="<<dim1<<" dim2="<<dim2<<endl;
1722 // now we know edge_curve and value range therefore
1723 // we can create corresponding D&GT labels
1724 Standard_Integer index = TP->MapIndex(EC);
1725 TopoDS_Shape aSh;
1726 if(index >0) {
1727 Handle(Transfer_Binder) binder = TP->MapItem(index);
1728 aSh = TransferBRep::ShapeResult(binder);
1729 }
1730 if(aSh.IsNull()) continue;
1731 TDF_Label shL;
1732 if( !STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
1733 Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(1,2);
1734 arr->SetValue(1,dim1);
1735 arr->SetValue(2,dim2);
1736 DGTTool->SetDimTol(shL,1,arr,aName,DimSize->Name());
1737 }
1738 // read tolerances and datums
1739 else if(subs3.Value()->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
1740 Handle(StepDimTol_GeometricTolerance) GT =
1741 Handle(StepDimTol_GeometricTolerance)::DownCast(subs3.Value());
1742 // read common data for tolerance
1743 //Standard_Real dim = GT->Magnitude()->ValueComponent();
1744 Handle (StepBasic_MeasureWithUnit) dim3 = GT->Magnitude();
1745 if(dim3.IsNull()) continue;
1746 Standard_Real dim = dim3->ValueComponent();
1747 StepBasic_Unit anUnit = GT->Magnitude()->UnitComponent();
1748 Standard_Real afact=1.;
1749 if(anUnit.IsNull()) continue;
1750 if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
1751 Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
1752 if(GetLengthConversionFactor(NU,afact)) dim = dim*afact;
1753 //cout<<"GeometricTolerance: Magnitude = "<<dim<<endl;
1754 Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(1,1);
1755 arr->SetValue(1,dim);
1756 Handle(TCollection_HAsciiString) aName = GT->Name();
1757 Handle(TCollection_HAsciiString) aDescription = GT->Description();
1758 Handle(StepShape_AdvancedFace) AF = Handle(StepShape_AdvancedFace)::DownCast(RI);
1759 if(AF.IsNull()) continue;
1760 Standard_Integer index = TP->MapIndex(AF);
1761 TopoDS_Shape aSh;
1762 if(index >0) {
1763 Handle(Transfer_Binder) binder = TP->MapItem(index);
1764 aSh = TransferBRep::ShapeResult(binder);
1765 }
1766 if(aSh.IsNull()) continue;
1767 TDF_Label shL;
1768 if( !STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
1769 // read specific data for tolerance
1770 if(GT->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol))) {
1771 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol) GTComplex =
1772 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol)::DownCast(subs3.Value());
1773 Standard_Integer kind=20;
1774 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
1775 GTComplex->GetModifiedGeometricTolerance();
1776 if(!MGT.IsNull()) {
1777 kind = kind + MGT->Modifier()+1;
1778 }
1779 TDF_Label TolerL = DGTTool->SetDimTol(shL,kind,arr,aName,aDescription);
1780 // translate datums connected with this tolerance
1781 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
1782 GTComplex->GetGeometricToleranceWithDatumReference();
1783 if(!GTWDR.IsNull()) {
1784 ReadDatums(STool,DGTTool,graph,TP,TolerL,GTWDR);
1785 }
1786 }
1787 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_GeometricToleranceWithDatumReference))) {
1788 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
1789 Handle(StepDimTol_GeometricToleranceWithDatumReference)::DownCast(subs3.Value());
1790 if(GTWDR.IsNull()) continue;
1791 Standard_Integer kind = 0;
1792 if (GTWDR->IsKind(STANDARD_TYPE(StepDimTol_AngularityTolerance))) kind = 24;
1793 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_CircularRunoutTolerance))) kind = 25;
1794 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_CoaxialityTolerance))) kind = 26;
1795 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_ConcentricityTolerance))) kind = 27;
1796 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_ParallelismTolerance))) kind = 28;
1797 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_PerpendicularityTolerance))) kind = 29;
1798 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_SymmetryTolerance))) kind = 30;
1799 else if(GTWDR->IsKind(STANDARD_TYPE(StepDimTol_TotalRunoutTolerance))) kind = 31;
1800 //cout<<"GTWDR: kind="<<kind<<endl;
1801 TDF_Label TolerL = DGTTool->SetDimTol(shL,kind,arr,aName,aDescription);
1802 ReadDatums(STool,DGTTool,graph,TP,TolerL,GTWDR);
1803 }
1804 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_ModifiedGeometricTolerance))) {
1805 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
1806 Handle(StepDimTol_ModifiedGeometricTolerance)::DownCast(subs3.Value());
1807 Standard_Integer kind = 35 + MGT->Modifier();
1808 DGTTool->SetDimTol(shL,kind,arr,aName,aDescription);
1809 }
1810 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_CylindricityTolerance))) {
1811 DGTTool->SetDimTol(shL,38,arr,aName,aDescription);
1812 }
1813 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_FlatnessTolerance))) {
1814 DGTTool->SetDimTol(shL,39,arr,aName,aDescription);
1815 }
1816 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_LineProfileTolerance))) {
1817 DGTTool->SetDimTol(shL,40,arr,aName,aDescription);
1818 }
1819 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_PositionTolerance))) {
1820 DGTTool->SetDimTol(shL,41,arr,aName,aDescription);
1821 }
1822 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_RoundnessTolerance))) {
1823 DGTTool->SetDimTol(shL,42,arr,aName,aDescription);
1824 }
1825 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_StraightnessTolerance))) {
1826 DGTTool->SetDimTol(shL,43,arr,aName,aDescription);
1827 }
1828 else if(GT->IsKind(STANDARD_TYPE(StepDimTol_SurfaceProfileTolerance))) {
1829 DGTTool->SetDimTol(shL,44,arr,aName,aDescription);
1830 }
1831 }
1832 }
1833 }
1834 }
1835
1836 return Standard_True;
1837}
1838
1839
1840//=======================================================================
1841//function : FindSolidForPDS
1842//purpose : auxilary
1843//=======================================================================
1844
1845static Handle(StepShape_SolidModel) FindSolidForPDS(const Handle(StepRepr_ProductDefinitionShape) &PDS,
1846 const Interface_Graph &graph)
1847{
1848 Handle(StepShape_SolidModel) SM;
1849 Interface_EntityIterator subs = graph.Sharings(PDS);
1850 Handle(StepShape_ShapeRepresentation) SR;
1851 for(subs.Start(); subs.More() && SM.IsNull(); subs.Next()) {
1852 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
1853 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
1854 if(SDR.IsNull()) continue;
1855 SR = Handle(StepShape_ShapeRepresentation)::DownCast(SDR->UsedRepresentation());
1856 if(SR.IsNull()) continue;
1857 for(Standard_Integer i=1; i<=SR->NbItems() && SM.IsNull(); i++) {
1858 SM = Handle(StepShape_SolidModel)::DownCast(SR->ItemsValue(i));
1859 }
1860 if(SM.IsNull()) {
1861 Interface_EntityIterator subs1 = graph.Sharings(SR);
1862 for(subs1.Start(); subs1.More() && SM.IsNull(); subs1.Next()) {
1863 Handle(StepRepr_RepresentationRelationship) RR =
1864 Handle(StepRepr_RepresentationRelationship)::DownCast(subs1.Value());
1865 if(RR.IsNull()) continue;
1866 Handle(StepShape_ShapeRepresentation) SR2;
1867 if(RR->Rep1()==SR) SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep2());
1868 else SR2 = Handle(StepShape_ShapeRepresentation)::DownCast(RR->Rep1());
1869 if(SR2.IsNull()) continue;
1870 for(Standard_Integer i2=1; i2<=SR2->NbItems() && SM.IsNull(); i2++) {
1871 SM = Handle(StepShape_SolidModel)::DownCast(SR2->ItemsValue(i2));
1872 }
1873 }
1874 }
1875 }
1876 return SM;
1877}
1878
1879
1880//=======================================================================
1881//function : ReadMaterials
1882//purpose :
1883//=======================================================================
1884
1885Standard_Boolean STEPCAFControl_Reader::ReadMaterials(const Handle(XSControl_WorkSession) &WS,
1886 Handle(TDocStd_Document)& Doc,
1887 const Handle(TColStd_HSequenceOfTransient) &SeqPDS) const
1888{
1889 Handle(Interface_InterfaceModel) Model = WS->Model();
1890 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( Doc->Main() );
1891 Handle(XSControl_TransferReader) TR = WS->TransferReader();
1892 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
1893 Handle(XCAFDoc_MaterialTool) MatTool = XCAFDoc_DocumentTool::MaterialTool( Doc->Main() );
1894 if(MatTool.IsNull()) return Standard_False;
1895
1896 const Interface_Graph& graph = TP->Graph();
1897 for(Standard_Integer i=1; i<=SeqPDS->Length(); i++) {
1898 Handle(StepRepr_ProductDefinitionShape) PDS =
1899 Handle(StepRepr_ProductDefinitionShape)::DownCast(SeqPDS->Value(i));
1d2b1ccb
G
1900 if(PDS.IsNull())
1901 continue;
1902 Handle(StepBasic_ProductDefinition) aProdDef = PDS->Definition().ProductDefinition();
1903 if(aProdDef.IsNull())
1904 continue;
7fd59977 1905 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString("");
1906 Handle(TCollection_HAsciiString) aDescription = new TCollection_HAsciiString("");
1907 Handle(TCollection_HAsciiString) aDensName = new TCollection_HAsciiString("");
1908 Handle(TCollection_HAsciiString) aDensValType = new TCollection_HAsciiString("");
1909 Standard_Real aDensity=0;
1d2b1ccb 1910 Interface_EntityIterator subs = graph.Sharings( aProdDef);
7fd59977 1911 for(subs.Start(); subs.More(); subs.Next()) {
1912 Handle(StepRepr_PropertyDefinition) PropD =
1913 Handle(StepRepr_PropertyDefinition)::DownCast(subs.Value());
1914 if(PropD.IsNull()) continue;
1915 Interface_EntityIterator subs1 = graph.Sharings(PropD);
1916 for(subs1.Start(); subs1.More(); subs1.Next()) {
1917 Handle(StepRepr_PropertyDefinitionRepresentation) PDR =
1918 Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast(subs1.Value());
1919 if(PDR.IsNull()) continue;
1920 Handle(StepRepr_Representation) Repr = PDR->UsedRepresentation();
1921 if(Repr.IsNull()) continue;
1922 Standard_Integer ir;
1923 for(ir=1; ir<=Repr->NbItems(); ir++) {
1924 Handle(StepRepr_RepresentationItem) RI = Repr->ItemsValue(ir);
1925 if(RI.IsNull()) continue;
1926 if(RI->IsKind(STANDARD_TYPE(StepRepr_DescriptiveRepresentationItem))) {
1927 // find name and description for material
1928 Handle(StepRepr_DescriptiveRepresentationItem) DRI =
1929 Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(RI);
1930 aName = DRI->Name();
87073a10 1931
7fd59977 1932 aDescription = DRI->Description();
87073a10 1933 if(aName.IsNull())
1934 aName = aDescription;
7fd59977 1935 }
1936 if(RI->IsKind(STANDARD_TYPE(StepRepr_MeasureRepresentationItem))) {
1937 // try to find density for material
1938 Handle(StepRepr_MeasureRepresentationItem) MRI =
1939 Handle(StepRepr_MeasureRepresentationItem)::DownCast(RI);
1940 aDensity = MRI->Measure()->ValueComponent();
1941 aDensName = MRI->Name();
1942 aDensValType = new TCollection_HAsciiString(MRI->Measure()->ValueComponentMember()->Name());
1943 StepBasic_Unit aUnit = MRI->Measure()->UnitComponent();
1944 if(!aUnit.IsNull()) {
1945 Handle(StepBasic_DerivedUnit) DU = aUnit.DerivedUnit();
1946 if(DU.IsNull()) continue;
1947 for(Standard_Integer idu=1; idu<=DU->NbElements(); idu++) {
1948 Handle(StepBasic_DerivedUnitElement) DUE = DU->ElementsValue(idu);
1949 Handle(StepBasic_NamedUnit) NU = DUE->Unit();
1950 Standard_Real afact=1.;
1951 if(NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit))) {
1952 if(GetLengthConversionFactor(NU,afact)) aDensity = aDensity/(afact*afact*afact);
1953 // transfer length value for Density from millimeter to santimeter
1954 // in order to result density has dimension gram/(sm*sm*sm)
1955 aDensity = aDensity*1000.;
1956 }
1957 if(NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit))) {
1958 if(GetMassConversionFactor(NU,afact)) aDensity=aDensity*afact;
1959 }
1960 }
1961 }
1962 }
1963 }
1964 }
1965 }
87073a10 1966
1967 if( aName.IsNull() || aName->Length()==0 )
1968 continue;
7fd59977 1969 // find shape label amd create Material link
1970 TopoDS_Shape aSh;
1971 Handle(StepShape_SolidModel) SM = FindSolidForPDS(PDS,graph);
1972 if(!SM.IsNull()) {
1973 Standard_Integer index = TP->MapIndex(SM);
1974 if(index >0) {
1975 Handle(Transfer_Binder) binder = TP->MapItem(index);
1976 if(!binder.IsNull())
1977 aSh = TransferBRep::ShapeResult(binder);
1978 }
1979 }
1980 if(aSh.IsNull()) continue;
1981 TDF_Label shL;
1982 if( !STool->Search(aSh, shL, Standard_True, Standard_True, Standard_True) ) continue;
1983 MatTool->SetMaterial(shL,aName,aDescription,aDensity,aDensName,aDensValType);
1984 }
1985
1986 return Standard_True;
1987}
1988
1989
1990//=======================================================================
1991//function : SetColorMode
1992//purpose :
1993//=======================================================================
1994
1995void STEPCAFControl_Reader::SetColorMode (const Standard_Boolean colormode)
1996{
1997 myColorMode = colormode;
1998}
1999
2000//=======================================================================
2001//function : GetColorMode
2002//purpose :
2003//=======================================================================
2004
2005Standard_Boolean STEPCAFControl_Reader::GetColorMode () const
2006{
2007 return myColorMode;
2008}
2009
2010//=======================================================================
2011//function : SetNameMode
2012//purpose :
2013//=======================================================================
2014
2015void STEPCAFControl_Reader::SetNameMode (const Standard_Boolean namemode)
2016{
2017 myNameMode = namemode;
2018}
2019
2020//=======================================================================
2021//function : GetNameMode
2022//purpose :
2023//=======================================================================
2024
2025Standard_Boolean STEPCAFControl_Reader::GetNameMode () const
2026{
2027 return myNameMode;
2028}
2029
2030//=======================================================================
2031//function : SetLayerMode
2032//purpose :
2033//=======================================================================
2034
2035void STEPCAFControl_Reader::SetLayerMode (const Standard_Boolean layermode)
2036{
2037 myLayerMode = layermode;
2038}
2039
2040//=======================================================================
2041//function : GetLayerMode
2042//purpose :
2043//=======================================================================
2044
2045Standard_Boolean STEPCAFControl_Reader::GetLayerMode () const
2046{
2047 return myLayerMode;
2048}
2049
2050//=======================================================================
2051//function : SetPropsMode
2052//purpose :
2053//=======================================================================
2054
2055void STEPCAFControl_Reader::SetPropsMode (const Standard_Boolean propsmode)
2056{
2057 myPropsMode = propsmode;
2058}
2059
2060//=======================================================================
2061//function : GetPropsMode
2062//purpose :
2063//=======================================================================
2064
2065Standard_Boolean STEPCAFControl_Reader::GetPropsMode () const
2066{
2067 return myPropsMode;
2068}
2069
2070//=======================================================================
2071//function : SetSHUOMode
2072//purpose :
2073//=======================================================================
2074
2075void STEPCAFControl_Reader::SetSHUOMode (const Standard_Boolean mode)
2076{
2077 mySHUOMode = mode;
2078}
2079
2080//=======================================================================
2081//function : GetSHUOMode
2082//purpose :
2083//=======================================================================
2084
2085Standard_Boolean STEPCAFControl_Reader::GetSHUOMode () const
2086{
2087 return mySHUOMode;
2088}
2089
2090//=======================================================================
2091//function : SetGDTMode
2092//purpose :
2093//=======================================================================
2094
2095void STEPCAFControl_Reader::SetGDTMode (const Standard_Boolean gdtmode)
2096{
2097 myGDTMode = gdtmode;
2098}
2099
2100//=======================================================================
2101//function : GetGDTMode
2102//purpose :
2103//=======================================================================
2104
2105Standard_Boolean STEPCAFControl_Reader::GetGDTMode () const
2106{
2107 return myGDTMode;
2108}
2109
2110
2111//=======================================================================
2112//function : SetMatMode
2113//purpose :
2114//=======================================================================
2115
2116void STEPCAFControl_Reader::SetMatMode (const Standard_Boolean matmode)
2117{
2118 myMatMode = matmode;
2119}
2120
2121//=======================================================================
2122//function : GetMatMode
2123//purpose :
2124//=======================================================================
2125
2126Standard_Boolean STEPCAFControl_Reader::GetMatMode () const
2127{
2128 return myMatMode;
2129}