1 //:k3 abv 25.11.98 rp1sd.stp
2 //:n4 abv 11.02.99 S4132: recognition of GeometricSet (instead of GeometricCurveSet)
3 // gka 05.04.99 S4136: eliminate parameter lastpreci
4 //gka,abv 14.04.99 S4136: maintain unit context, precision and maxtolerance values
5 #include <STEPControl_ActorRead.ixx>
6 #include <OSD_Timer.hxx>
8 // #include <Interface_InterfaceModel.hxx> // pour mise au point
10 #include <StepShape_ShapeDefinitionRepresentation.hxx>
11 #include <StepShape_ShapeRepresentation.hxx>
12 #include <StepShape_FacetedBrepAndBrepWithVoids.hxx>
13 #include <StepShape_FacetedBrep.hxx>
14 #include <StepShape_ShellBasedSurfaceModel.hxx>
15 #include <StepShape_ManifoldSolidBrep.hxx>
16 #include <StepShape_BrepWithVoids.hxx>
17 #include <StepShape_GeometricSet.hxx>
20 #include <StepRepr_MappedItem.hxx>
21 #include <StepGeom_Axis2Placement3d.hxx>
22 #include <StepRepr_RepresentationMap.hxx>
23 #include <StepToTopoDS_MakeTransformed.hxx>
26 #include <StepShape_FaceSurface.hxx>
27 #include <StepToTopoDS_Tool.hxx>
28 #include <StepToTopoDS_DataMapOfTRI.hxx>
29 #include <StepToTopoDS_TranslateFace.hxx>
32 #include <StepRepr_RepresentationContext.hxx>
33 #include <StepRepr_GlobalUnitAssignedContext.hxx>
34 #include <StepRepr_GlobalUncertaintyAssignedContext.hxx>
35 //#include <StepBasic_UncertaintyMeasureWithUnit.hxx>
36 #include <StepBasic_ProductRelatedProductCategory.hxx>
37 #include <StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext.hxx>
38 #include <StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx.hxx>
40 #include <STEPConstruct_UnitContext.hxx>
41 #include <UnitsMethods.hxx>
43 // Representation Relationship & cie
44 #include <Interface_Graph.hxx>
45 #include <Interface_EntityIterator.hxx>
46 #include <TransferBRep.hxx>
47 #include <StepShape_ContextDependentShapeRepresentation.hxx>
48 #include <StepRepr_ShapeRepresentationRelationship.hxx>
49 #include <StepRepr_ShapeRepresentationRelationshipWithTransformation.hxx>
50 #include <StepRepr_Transformation.hxx>
51 #include <StepRepr_ItemDefinedTransformation.hxx>
53 #include <BRep_Builder.hxx>
54 #include <StepToTopoDS_Builder.hxx>
55 #include <TopoDS_Compound.hxx>
56 #include <TopoDS_Shape.hxx>
58 #include <TransferBRep_ShapeBinder.hxx>
60 #include <Interface_Static.hxx>
61 #include <Interface_Macros.hxx>
62 #include <Interface_InterfaceModel.hxx>
64 #include <StepBasic_ProductDefinition.hxx>
65 #include <StepRepr_ProductDefinitionShape.hxx>
66 #include <StepRepr_NextAssemblyUsageOccurrence.hxx>
67 #include <STEPConstruct_Assembly.hxx>
68 #include <Precision.hxx>
69 #include <StepToGeom_MakeTransformation3d.hxx>
70 #include <StepToGeom_MakeAxis2Placement.hxx>
71 #include <Geom_Axis2Placement.hxx>
73 #include <StepRepr_ShapeAspect.hxx>
75 #include <XSAlgo_AlgoContainer.hxx>
76 #include <StepShape_EdgeBasedWireframeModel.hxx>
77 #include <StepShape_FaceBasedSurfaceModel.hxx>
79 #include <StepShape_AdvancedBrepShapeRepresentation.hxx>
80 #include <StepShape_FacetedBrepShapeRepresentation.hxx>
81 #include <StepShape_ManifoldSurfaceShapeRepresentation.hxx>
82 #include <StepShape_EdgeBasedWireframeShapeRepresentation.hxx>
83 #include <StepShape_GeometricallyBoundedSurfaceShapeRepresentation.hxx>
84 #include <StepShape_GeometricallyBoundedWireframeShapeRepresentation.hxx>
86 #include <TColStd_HSequenceOfTransient.hxx>
87 #include <Message_ProgressSentry.hxx>
88 #include <Message_Messenger.hxx>
89 #include <StepRepr_HSequenceOfRepresentationItem.hxx>
90 #include <StepBasic_ProductDefinition.hxx>
91 #include <Standard_Failure.hxx>
92 #include <Standard_ErrorHandler.hxx>
93 #include <StepDimTol_DatumFeature.hxx>
94 #include <StepDimTol_GeometricTolerance.hxx>
95 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol.hxx>
97 // For non-manifold topology processing (ssv; 12.11.2010)
98 #include <StepShape_NonManifoldSurfaceShapeRepresentation.hxx>
99 #include <StepRepr_HArray1OfRepresentationItem.hxx>
100 #include <TopTools_MapOfShape.hxx>
101 #include <TopTools_ListOfShape.hxx>
102 #include <TopoDS_Iterator.hxx>
103 #include <TopTools_ListIteratorOfListOfShape.hxx>
104 #include <TopoDS_Solid.hxx>
105 #include <BRepCheck_Shell.hxx>
106 #include <BRepCheck_Status.hxx>
107 #include <TopoDS.hxx>
108 #include <TopoDS_Shell.hxx>
109 #include <TopoDS_Face.hxx>
110 #include <TopExp_Explorer.hxx>
111 #include <StepData_StepModel.hxx>
112 #include <HeaderSection_FileName.hxx>
116 // ============================================================================
117 // Function: DumpWhatIs
118 // Purpose: Use it in DEB mode to dump your shapes
119 // ============================================================================
121 static void DumpWhatIs(const TopoDS_Shape& S) {
123 TopTools_MapOfShape aMapOfShape;
125 TopTools_ListOfShape aListOfShape;
126 aListOfShape.Append(S);
127 TopTools_ListIteratorOfListOfShape itL(aListOfShape);
128 Standard_Integer nbSolids = 0,
136 for( ; itL.More(); itL.Next() ) {
137 TopoDS_Iterator it( itL.Value() );
138 for ( ; it.More(); it.Next() ) {
139 TopoDS_Shape aSubShape = it.Value();
140 if ( !aMapOfShape.Add(aSubShape) )
142 aListOfShape.Append(aSubShape);
143 if (aSubShape.ShapeType() == TopAbs_SOLID)
145 if (aSubShape.ShapeType() == TopAbs_SHELL) {
146 if ( !aSubShape.Closed() )
150 if (aSubShape.ShapeType() == TopAbs_FACE)
152 if (aSubShape.ShapeType() == TopAbs_WIRE)
154 if (aSubShape.ShapeType() == TopAbs_EDGE)
156 if (aSubShape.ShapeType() == TopAbs_VERTEX)
161 cout << "//What is?// NB SOLIDS: " << nbSolids << endl;
162 cout << "//What is?// NB SHELLS: " << nbShells << endl;
163 cout << "//What is?// OPEN SHELLS: " << nbOpenShells << endl;
164 cout << "//What is?// CLOSED SHELLS: " << nbShells - nbOpenShells << endl;
165 cout << "//What is?// NB FACES: " << nbFaces << endl;
166 cout << "//What is?// NB WIRES: " << nbWires << endl;
167 cout << "//What is?// NB EDGES: " << nbEdges << endl;
168 cout << "//What is?// NB VERTEXES: " << nbVertexes << endl;
172 // ============================================================================
173 // Method : STEPControl_ActorRead::STEPControl_ActorRead ()
174 // Purpose : Empty constructor
175 // ============================================================================
177 STEPControl_ActorRead::STEPControl_ActorRead() {}
179 // ============================================================================
180 // Method : STEPControl_ActorRead::Recognize
181 // Purpose : tells if an entity is valid for transfer by this Actor
182 // ============================================================================
184 Standard_Boolean STEPControl_ActorRead::Recognize
185 (const Handle(Standard_Transient)& start)
187 if (start.IsNull()) return Standard_False;
189 if (start->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition))) return Standard_True;
191 if (start->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence))) return Standard_True;
193 TCollection_AsciiString aProdMode = Interface_Static::CVal("read.step.product.mode");
194 if(!aProdMode.IsEqual("ON"))
195 if(start->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation))) return Standard_True;
197 DeclareAndCast(StepShape_ShapeRepresentation,sr,start);
199 Standard_Integer i,nb = sr->NbItems();
200 for (i = 1; i <= nb; i ++) {
201 if (Recognize (sr->ItemsValue(i)) ) return Standard_True;
203 return Standard_False;
206 if (start->IsKind(STANDARD_TYPE(StepShape_FacetedBrep))) return Standard_True;
207 if (start->IsKind(STANDARD_TYPE(StepShape_BrepWithVoids))) return Standard_True;
208 if (start->IsKind(STANDARD_TYPE(StepShape_ManifoldSolidBrep))) return Standard_True;
209 if (start->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel))) return Standard_True;
210 if (start->IsKind(STANDARD_TYPE(StepShape_FacetedBrepAndBrepWithVoids))) return Standard_True;
211 if (start->IsKind(STANDARD_TYPE(StepShape_GeometricSet))) return Standard_True;
212 if (start->IsKind(STANDARD_TYPE(StepRepr_MappedItem))) return Standard_True;
213 if (start->IsKind(STANDARD_TYPE(StepShape_FaceSurface))) return Standard_True;
214 if (start->IsKind(STANDARD_TYPE(StepShape_EdgeBasedWireframeModel))) return Standard_True;
215 if (start->IsKind(STANDARD_TYPE(StepShape_FaceBasedSurfaceModel))) return Standard_True;
218 // REPRESENTATION_RELATIONSHIP et consorts : on regarde le contenu ...
219 // On prend WithTransformation ou non ...
221 if (start->IsKind (STANDARD_TYPE(StepRepr_ShapeRepresentationRelationship))) {
222 DeclareAndCast(StepRepr_ShapeRepresentationRelationship,und,start);
224 // On prend son contenu
226 if (Recognize(und->Rep1()) || Recognize(und->Rep2())) return Standard_True;
227 return Standard_False;
230 if (start->IsKind(STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation))) {
231 // DeclareAndCast(StepShape_ContextDependentShapeRepresentation,CDSR,start);
232 // return Recognize (CDSR->RepresentationRelation());
233 return Standard_True;
234 // on fait le pari que, si ce n est pas transferable tel quel,
235 // des CDSR implicitement references le sont ...
236 // Sinon cette entite n aurait pas grand sens ...
239 return Standard_False;
243 // ============================================================================
244 // Method : STEPControl_ActorRead::Transfer
245 // Purpose : recursive method that acces to the root entities and start the
247 // ============================================================================
249 Handle(Transfer_Binder) STEPControl_ActorRead::Transfer
250 (const Handle(Standard_Transient)& start,
251 const Handle(Transfer_TransientProcess)& TP)
253 // [BEGIN] Get version of preprocessor (to detect I-Deas case) (ssv; 23.11.2010)
254 Handle(StepData_StepModel) aStepModel = Handle(StepData_StepModel)::DownCast ( TP->Model() );
255 Interface_EntityIterator anEntIt = aStepModel->Header();
256 for ( anEntIt.Start(); anEntIt.More(); anEntIt.Next() ) {
257 DeclareAndCast( HeaderSection_FileName, aFileNameEntity, anEntIt.Value() );
258 if ( !aFileNameEntity.IsNull() ) {
259 Handle(TCollection_HAsciiString) aPPVersion = aFileNameEntity->PreprocessorVersion();
261 cout << "Preprocessor version detected: " << aPPVersion->ToCString() << endl;
263 Standard_Integer anIDeasResult = aPPVersion->Search("I-DEAS");
264 if (anIDeasResult != -1) {
266 cout << "Recognized as I-DEAS STP" << endl;
268 myNMTool.SetIDEASCase(Standard_True);
272 // [END] Get version of preprocessor (to detect I-Deas case) (ssv; 23.11.2010)
273 return TransferShape (start,TP);
277 // ============================================================================
278 // auxiliary function : ApplyTransformation
279 // ============================================================================
280 static void ApplyTransformation (TopoDS_Shape& shape, const gp_Trsf &Trsf)
282 if ( Trsf.Form() == gp_Identity ) return;
283 TopLoc_Location theLoc ( Trsf );
288 // ============================================================================
289 // auxiliary function : FindContext
290 // ============================================================================
291 static Handle(StepRepr_Representation) FindContext (const Handle(Standard_Transient) &start,
292 const Handle(Transfer_TransientProcess) &TP,
293 const Standard_Integer level=10 )
295 Handle(StepRepr_Representation) rep;
296 const Interface_Graph& graph = TP->Graph();
297 Interface_EntityIterator subs = graph.Sharings(start);
298 for (subs.Start(); subs.More() && rep.IsNull(); subs.Next()) {
299 rep = Handle(StepRepr_Representation)::DownCast(subs.Value());
300 if ( rep.IsNull() && level >0 ) rep = FindContext ( subs.Value(), TP, level-1 );
305 //=======================================================================
306 //function : FindShapeReprType
307 //purpose : Returns integer corresponding to the type of the representation
308 // as defined in read.step.shape.repr_level parameter
309 //=======================================================================
311 static Standard_Integer FindShapeReprType (const Handle(Standard_Transient) &start)
313 if(start->IsKind(STANDARD_TYPE(StepShape_AdvancedBrepShapeRepresentation)))
315 if(start->IsKind(STANDARD_TYPE(StepShape_ManifoldSurfaceShapeRepresentation)))
317 if(start->IsKind(STANDARD_TYPE(StepShape_GeometricallyBoundedSurfaceShapeRepresentation)))
319 if(start->IsKind(STANDARD_TYPE(StepShape_FacetedBrepShapeRepresentation)))
321 if(start->IsKind(STANDARD_TYPE(StepShape_EdgeBasedWireframeShapeRepresentation)))
323 if(start->IsKind(STANDARD_TYPE(StepShape_GeometricallyBoundedWireframeShapeRepresentation)))
328 //=======================================================================
329 //function : getListSDR
330 //purpose : Get SDRs assigned to ShapeAspect, which may potentially
331 // correspond to hybrid models in AP203 before 1998
332 //=======================================================================
334 static void getListSDR(const Handle(StepRepr_ShapeAspect)& sa,
335 Handle(TColStd_HSequenceOfTransient)& listSDR,
336 const Handle(Transfer_TransientProcess)& TP)
338 const Interface_Graph& graph = TP->Graph();
340 // check whether this ShapeAspect is used in G&DT, and if yes, ignore it
341 if(sa->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature))) return;
342 Interface_EntityIterator subs5 = graph.Sharings(sa);
343 for (subs5.Start(); subs5.More(); subs5.Next()) {
344 if(subs5.Value()->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
348 // reiterate by referred entities and take all SDRs; note that SDRs that
349 // refer to sub-shapes of main SDR will be filtered out further during translation
350 subs5 = graph.Sharings(sa);
351 for (subs5.Start(); subs5.More() ; subs5.Next()) {
352 Handle(StepRepr_PropertyDefinition) propd =
353 Handle(StepRepr_PropertyDefinition)::DownCast(subs5.Value());
354 if(propd.IsNull()) continue;
355 Interface_EntityIterator subs6 = graph.Sharings(propd);
356 for (subs6.Start(); subs6.More() ; subs6.Next()) {
357 Handle(StepShape_ShapeDefinitionRepresentation) sdr =
358 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs6.Value());
359 if ( ! sdr.IsNull() )
360 listSDR->Append(sdr);
365 //=======================================================================
367 //purpose : Find all SDRs related to given PDS
368 //=======================================================================
370 static void getSDR(const Handle(StepRepr_ProductDefinitionShape)& PDS,
371 Handle(TColStd_HSequenceOfTransient)& listSDR,
372 Handle(TColStd_HSequenceOfTransient)& listSDRAspect,
373 const Handle(Transfer_TransientProcess)& TP)
375 // Flag indicating preferred shape representation type, to be chosen if
376 // several different representations are attached to the same shape
377 Standard_Integer delta = 100;
378 Standard_Integer ICS = Interface_Static::IVal("read.step.shape.repr");
379 Standard_Integer nbSDR0 = listSDR->Length();
381 // Iterate by entities referring PDS
382 const Interface_Graph& graph = TP->Graph();
383 Handle(StepShape_ShapeDefinitionRepresentation) NeedSDR;
384 Interface_EntityIterator subs4 = graph.Sharings(PDS);
385 for (subs4.Start(); subs4.More(); subs4.Next()) {
387 // Directly assigned SDR
388 Handle(StepShape_ShapeDefinitionRepresentation) sdr =
389 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs4.Value());
390 if ( ! sdr.IsNull() ) {
391 Handle(StepRepr_Representation) rep = sdr->UsedRepresentation();
393 if ( !rep.IsNull()) {
394 // if specific representation type is preferred, choose the
395 // representations of the closest type
396 if ( ICS == 1 ) // translate all SDRs
397 listSDR->Append(sdr);
399 Standard_Integer iDiff = Abs ( FindShapeReprType(rep) - ICS );
400 // if more suitable representation is found, drop previous if any selected
401 if( iDiff < delta ) {
402 while ( listSDR->Length() > nbSDR0 )
403 listSDR->Remove(listSDR->Length());
406 // take all representations of preferred or closest type
407 if ( iDiff <= delta )
408 listSDR->Append(sdr);
414 // SDRs assigned via ShapeAspect; may correspond to hybrid model in AP203 before 1998
415 Handle(StepRepr_ShapeAspect) sa =
416 Handle(StepRepr_ShapeAspect)::DownCast(subs4.Value());
417 if ( ! sa.IsNull() ) {
418 getListSDR(sa,listSDRAspect,TP);
425 //=======================================================================
426 //function : TransferEntity
428 //=======================================================================
429 Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(const Handle(StepBasic_ProductDefinition)& PD,
430 const Handle(Transfer_TransientProcess)& TP)
433 Handle(Message_Messenger) sout = TP->Messenger();
434 Handle(TransferBRep_ShapeBinder) shbinder;
436 TopoDS_Compound Cund;
437 TopoDS_Shape Result1;
439 B.MakeCompound (Cund);
441 // Find subcomponents of assembly (NAUO)
442 // and definitions of shape of the current product (SDR)
443 Handle(TColStd_HSequenceOfTransient) listSDR = new TColStd_HSequenceOfTransient;
444 Handle(TColStd_HSequenceOfTransient) listNAUO = new TColStd_HSequenceOfTransient;
445 Handle(TColStd_HSequenceOfTransient) listSDRAspect = new TColStd_HSequenceOfTransient;
446 const Interface_Graph& graph = TP->Graph();
447 Interface_EntityIterator subs3 = graph.Sharings(PD);
448 for (subs3.Start(); subs3.More() ; subs3.Next()) {
449 // PDS is used to find shape definitions attached to this product
450 Handle(StepRepr_ProductDefinitionShape) PDS =
451 Handle(StepRepr_ProductDefinitionShape)::DownCast(subs3.Value());
452 if ( ! PDS.IsNull() ) {
453 getSDR(PDS,listSDR,listSDRAspect,TP);
456 // NAUO is used to find sub-assemblies
457 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
458 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs3.Value());
459 if ( ! NAUO.IsNull() ) {
460 if ( PD == NAUO->RelatingProductDefinition() )
461 listNAUO->Append(NAUO);
466 // Flag indicating whether SDRs associated with the product`s main SDR
467 // by SRRs (which correspond to hybrid model representation in AP203 since 1998)
468 // should be taken into account
469 Standard_Integer readSRR = Interface_Static::IVal("read.step.shape.relationship");
471 // Flag indicating whether SDRs associated with the product`s main SDR
472 // by SAs (which correspond to hybrid model representation in AP203 before 1998)
473 // should be taken into account
474 Standard_Integer readSA = Interface_Static::IVal("read.step.shape.aspect");
476 listSDRAspect->Clear();
478 // remember number of normal SDRs (not those found via ShapeAspect)
479 // and merge both lists in one
480 Standard_Integer nbNotAspect = listSDR->Length();
481 listSDR->Append(listSDRAspect);
483 // Flag indicating level of reading assemblies: only structure (3),
484 // structure with shapes of final parts (2), or everything, including shapes
485 // possibly attached directly to intermediate assemblies (1)
486 // Special mode (4) is used to translate shape attached to this product only,
487 // ignoring sub-assemblies if any
488 Standard_Integer readAssembly = Interface_Static::IVal("read.step.assembly.level");
489 if ( readAssembly ==3 || ( readAssembly ==2 && listNAUO->Length() >0 ) )
491 else if ( readAssembly == 4 )
494 Standard_Integer nbEnt = listSDR->Length() + listNAUO->Length();
498 // common progress indicator for translation of own shapes and sub-assemblies
499 Message_ProgressSentry PS ( TP->GetProgress(), "Part", 0, nbEnt, 1 );
500 Standard_Integer nbComponents=0, nbShapes=0;
502 // translate sub-assemblies
503 for ( Standard_Integer nbNauo =1; nbNauo <= listNAUO->Length() && PS.More(); nbNauo++, PS.Next()) {
504 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
505 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(listNAUO->Value(nbNauo));
508 if (TP->TraceLevel() > 1)
509 sout<<" -- Actor : Ent.n0 "<<TP->Model()->Number(PD)<<" -> Shared Ent.no"<<TP->Model()->Number(NAUO)<<endl;
511 Handle(Transfer_Binder) binder;
512 if (!TP->IsBound(NAUO)) binder = TransferEntity(NAUO,TP);
513 else binder = TP->Find(NAUO);
515 TopoDS_Shape theResult = TransferBRep::ShapeResult (binder);
516 if (!theResult.IsNull()) {
518 B.Add(Cund, theResult);
523 // translate shapes assigned directly
524 for(Standard_Integer i=1; i <= listSDR->Length() && PS.More(); i++, PS.Next()) {
525 Handle(StepShape_ShapeDefinitionRepresentation) sdr =
526 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(listSDR->Value(i));
527 Handle(StepShape_ShapeRepresentation) rep = Handle(StepShape_ShapeRepresentation)::DownCast(sdr->UsedRepresentation());
531 // translate SDR representation
532 Standard_Boolean isBound = Standard_True;
533 Handle(Transfer_Binder) binder = TP->Find(rep);
535 binder = TransferEntity(rep,TP,isBound);
537 // if SDR is obtained from ShapeAspect and representation items have already been tramnslated,
538 // this means that that ShapeAspect is used to refer to sub-shape of the main shape
539 // (e.g. for validation properties), and we do not need to translate it actually;
540 // otherwise it is considered as part of hybrid representation in AP203 before 1998
541 if ( i > nbNotAspect && isBound)
544 // record shape resulting from translation
545 TopoDS_Shape theResult;
546 if ( ! binder.IsNull() ) {
547 theResult = TransferBRep::ShapeResult (binder);
548 if (!theResult.IsNull()) {
550 B.Add(Cund, theResult);
555 // translate possible shapes related by SRRs, which corresponds to
556 // way of writing hybrid models in AP203 since 1998, and AP209
557 // Note that both AP203 and AP209 allow main representation to be non-empty
558 if ( readSRR && /*theResult.IsNull() &&*/ i <= nbNotAspect) {
559 Interface_EntityIterator subs1 = graph.Sharings(rep);
560 Handle(Standard_Type) tSRR = STANDARD_TYPE(StepRepr_ShapeRepresentationRelationship);
561 for (subs1.Start(); subs1.More(); subs1.Next()) {
562 Handle(Standard_Transient) anitem = subs1.Value();
563 if ( anitem->DynamicType() != tSRR ) continue;
564 Handle(StepRepr_ShapeRepresentationRelationship) SRR =
565 Handle(StepRepr_ShapeRepresentationRelationship)::DownCast(anitem);
566 Standard_Integer nbrep = ( rep == SRR->Rep1() ? 2 : 1 );
567 binder = TransferEntity(SRR, TP, nbrep);
568 if ( ! binder.IsNull() ) {
569 theResult = TransferBRep::ShapeResult (binder);
571 B.Add(Cund, theResult);
578 // make a warning if both own shape and sub-assemblies are present
579 if ( nbShapes >0 && nbComponents > 0 )
580 TP->AddWarning ( PD, "Product has both sub-assemblies and directly assigned shape" );
582 // if only single shape is read, add it as it is; otherwise add compound
583 if( nbShapes == 1 && nbComponents == 0 )
584 shbinder = new TransferBRep_ShapeBinder (Result1);
586 shbinder = new TransferBRep_ShapeBinder (Cund);
588 //TP->Unbind( PD ); //:j3: unbind start (let it be bound by TransferProcess)
589 TP->Bind(PD, shbinder);
593 //=======================================================================
594 //function : TransferEntity
596 //=======================================================================
598 Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(const Handle(StepRepr_NextAssemblyUsageOccurrence)& NAUO ,
599 const Handle(Transfer_TransientProcess)& TP)
601 Handle(TransferBRep_ShapeBinder) shbinder;
602 Handle(StepBasic_ProductDefinition) PD;
603 const Interface_Graph& graph = TP->Graph();
605 Standard_Boolean iatrsf=Standard_False, SRRReversed=Standard_False, IsDepend=Standard_False;
606 Handle(StepRepr_ShapeRepresentationRelationship) SRR;
607 Interface_EntityIterator subs1 = graph.Sharings(NAUO);
608 for (subs1.Start(); subs1.More(); subs1.Next()) {
609 Handle(StepRepr_ProductDefinitionShape) PDS =
610 Handle(StepRepr_ProductDefinitionShape)::DownCast(subs1.Value());
611 if(PDS.IsNull()) continue;
612 //IsPDS=Standard_True;
613 Interface_EntityIterator subs2 = graph.Sharings(PDS);
614 for (subs2.Start(); subs2.More(); subs2.Next()) {
615 Handle(StepShape_ContextDependentShapeRepresentation) CDSR =
616 Handle(StepShape_ContextDependentShapeRepresentation)::DownCast(subs2.Value());
617 if (CDSR.IsNull()) continue;
618 IsDepend=Standard_True;
619 Handle(StepRepr_RepresentationRelationship) RR = CDSR->RepresentationRelation();
620 if (RR.IsNull()) continue;
621 SRRReversed = STEPConstruct_Assembly::CheckSRRReversesNAUO ( TP->Model(), CDSR );
622 Handle(StepRepr_Representation) rep = ( SRRReversed ? RR->Rep2() : RR->Rep1() );
623 iatrsf = ComputeSRRWT ( RR, TP, Trsf );
624 // find real ProductDefinition used rep
625 Interface_EntityIterator subs3 = TP->Graph().Sharings(rep);
626 for (subs3.Start(); subs3.More(); subs3.Next()) {
627 if ( subs3.Value()->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation))) {
628 DeclareAndCast(StepShape_ShapeDefinitionRepresentation,SDR,subs3.Value());
629 Handle(StepRepr_ProductDefinitionShape) PDS1 =
630 Handle(StepRepr_ProductDefinitionShape)::DownCast(SDR->Definition().PropertyDefinition());
631 //Handle(StepRepr_PropertyDefinition) PD = SDR->Definition().PropertyDefinition();
632 if(PDS1.IsNull()) continue;
633 Interface_EntityIterator subs4 = graph.Shareds(PDS1);
634 for (subs4.Start(); subs4.More(); subs4.Next()) {
635 Handle(StepBasic_ProductDefinition) PD1 =
636 Handle(StepBasic_ProductDefinition)::DownCast(subs4.Value());
637 if(PD1.IsNull()) continue;
641 else if(subs3.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeRepresentationRelationship))) {
642 SRR = Handle(StepRepr_ShapeRepresentationRelationship)::DownCast(subs3.Value());
648 Handle(Transfer_Binder) binder;
649 TopoDS_Shape theResult;
655 binder = TP->Find(PD);
656 if ( binder.IsNull() ) binder = TransferEntity(PD,TP);
657 theResult = TransferBRep::ShapeResult(binder);
658 if (!theResult.IsNull()) {
660 if ( SRRReversed ) ApplyTransformation ( theResult, Trsf.Inverted() );
661 else ApplyTransformation ( theResult, Trsf );
663 shbinder = new TransferBRep_ShapeBinder (theResult);
667 if ( theResult.IsNull() && !SRR.IsNull() ) {
668 binder = TP->Find(SRR);
669 if ( binder.IsNull() ) {
670 binder = TransferEntity(SRR,TP);
671 theResult = TransferBRep::ShapeResult (binder);
672 if (!theResult.IsNull())
673 shbinder = new TransferBRep_ShapeBinder (theResult);
678 TP->Bind(NAUO, shbinder);
682 //=======================================================================
683 //function : TransferEntity
685 //=======================================================================
687 Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(const Handle(StepShape_ShapeRepresentation)& sr,
688 const Handle(Transfer_TransientProcess)& TP,
689 Standard_Boolean& isBound)
691 Handle(TransferBRep_ShapeBinder) shbinder;
694 isBound = Standard_False;
695 Standard_Integer i,nb = sr->NbItems();
696 // Used in XSAlgo::AlgoContainer()->ProcessShape (ssv; 13.11.2010)
697 Standard_Integer nbTPitems = TP->NbMapped();
698 Handle(Message_Messenger) sout = TP->Messenger();
700 if (TP->TraceLevel() > 2)
701 sout<<" -- Actor : case ShapeRepr. NbItems="<<nb<<endl;
704 // Compute unit convertion factors and geometric Accuracy
705 Handle(StepRepr_Representation) oldSRContext = mySRContext; //:S4136
709 TopoDS_Compound comp;
710 B.MakeCompound (comp);
711 TopoDS_Shape OneResult;
712 Standard_Integer nsh = 0;
713 Message_ProgressSentry PS ( TP->GetProgress(), "Sub-assembly", 0, nb, 1 );
715 // [BEGIN] Proceed with non-manifold topology (ssv; 12.11.2010)
716 Standard_Boolean isNMMode = Interface_Static::IVal("read.step.nonmanifold");
717 Standard_Boolean isManifold = Standard_True;
718 if ( isNMMode && sr->IsKind(STANDARD_TYPE(StepShape_NonManifoldSurfaceShapeRepresentation)) ) {
719 isManifold = Standard_False;
721 Standard_Integer NMSSRItemsLen = sr->Items()->Length();
722 cout << "NMSSR with " << NMSSRItemsLen << " items detected" << endl;
725 // Special processing for I-DEAS STP case (ssv; 15.11.2010)
727 Standard_Integer isIDeasMode = Interface_Static::IVal("read.step.ideas");
728 if (isNMMode && myNMTool.IsIDEASCase() && isIDeasMode) {
729 isManifold = Standard_False;
731 cout << "I-DEAS post processing for non-manifold topology ENABLED" << endl;
735 else if ( myNMTool.IsIDEASCase() )
736 cout << "I-DEAS post processing for non-manifold topology DISABLED" << endl;
740 // Don't use NM tool in manifold cases (ssv; 24.11.2010)
741 myNMTool.SetActive(!isManifold && isNMMode);
742 // [END] Proceed with non-manifold topology (ssv; 12.11.2010)
744 for (i = 1; i <= nb && PS.More(); i ++,PS.Next()) {
745 //for (i = 1; i <= nb ; i ++) {
747 if (TP->TraceLevel() > 2)
748 sout<<" -- Actor, shape_representation.item n0. "<<i<<endl;
750 Handle(StepRepr_RepresentationItem) anitem = sr->ItemsValue(i);
751 Handle(Transfer_Binder) binder;
752 if (!TP->IsBound(anitem)) {
753 binder = TransferShape(anitem, TP, isManifold);
756 isBound = Standard_True;
757 binder = TP->Find(anitem);
759 TopoDS_Shape theResult = TransferBRep::ShapeResult (binder);
760 if (!theResult.IsNull()) {
761 OneResult = theResult;
762 B.Add(comp, theResult);
767 // [BEGIN] Proceed with non-manifold topology (ssv; 12.11.2010)
769 Handle(Standard_Transient) info;
770 // IMPORTANT: any fixing on non-manifold topology must be done after the shape is transferred from STEP
771 TopoDS_Shape fixedResult =
772 XSAlgo::AlgoContainer()->ProcessShape(comp, myPrecision, myMaxTol,
773 "read.step.resource.name",
774 "read.step.sequence", info);
775 XSAlgo::AlgoContainer()->MergeTransferInfo(TP, info, nbTPitems);
777 BRep_Builder brepBuilder;
779 // [BEGIN] Try to close OPEN Shells in I-DEAS case (ssv; 17.11.2010)
780 if ( myNMTool.IsIDEASCase() ) {
782 // ==========================================================
783 // For each Shell (always OPEN in I-DEAS case) find all
784 // the possibilities to close it with adjacent non-manifold
785 // Shells which are stored separately in I-DEAS-like STP
786 // ==========================================================
788 TopTools_IndexedDataMapOfShapeListOfShape shellClosingsMap;
789 // Find possible closings for each shell
790 this->computeIDEASClosings(comp, shellClosingsMap);
792 // Make compound to store closed Shells
793 TopoDS_Compound compWithClosings;
794 brepBuilder.MakeCompound(compWithClosings);
796 // Attempt to close Shells one-by-one
797 for (Standard_Integer i = 1; i <= shellClosingsMap.Extent(); i++) {
798 TopoDS_Shell adjustedShell = this->closeIDEASShell( TopoDS::Shell( shellClosingsMap.FindKey(i) ),
799 shellClosingsMap.FindFromIndex(i) );
800 brepBuilder.Add(compWithClosings, adjustedShell);
802 // Put not suspected open Shells as they are (updated 23.11.2010)
803 TopExp_Explorer allShellsExp(comp, TopAbs_SHELL);
804 for ( ; allShellsExp.More(); allShellsExp.Next() ) {
805 TopoDS_Shape aCurrentShell = allShellsExp.Current();
806 if ( !myNMTool.IsPureNMShell(aCurrentShell) && !shellClosingsMap.Contains(aCurrentShell) )
807 brepBuilder.Add(compWithClosings, aCurrentShell);
811 comp = compWithClosings;
814 // [END] Try to close OPEN Shells in I-DEAS case (ssv; 17.11.2010)
816 // [BEGIN] Reconstruct Solids from Closed Shells (ssv; 15.11.2010)
817 TopoDS_Compound reconstComp;
818 brepBuilder.MakeCompound(reconstComp);
820 TopoDS_Iterator it(comp);
821 for ( ; it.More(); it.Next() ) {
822 TopoDS_Shape aSubShape = it.Value();
823 if ( aSubShape.ShapeType() == TopAbs_SHELL && aSubShape.Closed() ) {
824 TopoDS_Solid nextSolid;
825 brepBuilder.MakeSolid(nextSolid);
826 brepBuilder.Add(nextSolid, aSubShape);
827 brepBuilder.Add(reconstComp, nextSolid);
829 else if (aSubShape.ShapeType() == TopAbs_SHELL)
830 brepBuilder.Add(reconstComp, aSubShape);
834 // [END] Reconstruct Solids from Closed Shells (ssv; 15.11.2010)
837 // Bind the resulting shape
838 if (nsh == 0) shbinder.Nullify();
839 else if (nsh == 1) shbinder = new TransferBRep_ShapeBinder (OneResult);
840 else shbinder = new TransferBRep_ShapeBinder (comp);
841 PrepareUnits ( oldSRContext, TP ); //:S4136
842 TP->Bind(sr, shbinder);
852 //=======================================================================
853 //function : TransferEntity
855 //=======================================================================
857 Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(const Handle(StepShape_ContextDependentShapeRepresentation)& CDSR,
858 const Handle(Transfer_TransientProcess)& TP)
860 Handle(TransferBRep_ShapeBinder) shbinder;
861 //:j2: treat SRRs here in order to compare them with NAUO
862 Handle(StepRepr_ShapeRepresentationRelationship) SRR = CDSR->RepresentationRelation();
863 //DeclareAndCast(StepRepr_RepresentationRelationship,SRR,CDSR->RepresentationRelation());
864 if ( SRR.IsNull() ) return shbinder;
866 Standard_Boolean SRRReversed = STEPConstruct_Assembly::CheckSRRReversesNAUO ( TP->Model(), CDSR );
867 Handle(StepRepr_Representation) rep1 = ( SRRReversed ? SRR->Rep2() : SRR->Rep1() );
868 Handle(StepShape_ShapeRepresentation) rep = Handle(StepShape_ShapeRepresentation)::DownCast(rep1);
871 TP->AddWarning ( SRR, "SRR reverses relation defined by NAUO; NAUO definition is taken" );
873 TopoDS_Shape theResult;
876 Standard_Boolean iatrsf = ComputeSRRWT ( SRR, TP, Trsf );
877 /* Delete this part does not work gka
878 // use SDR for reading rep in order to handle subassemblies
879 Interface_EntityIterator subs = TP->Graph().Sharings(rep);
880 Standard_Integer nbitem=0;
881 for (subs.Start(); subs.More(); subs.Next()) nbitem++;
882 Message_ProgressSentry PS ( TP->GetProgress(), "Shape", 0, nbitem, 1 );
884 for (subs.Start(); subs.More() && PS.More() ; subs.Next(),PS.Next()) {
885 if ( subs.Value()->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation))) {
886 DeclareAndCast(StepShape_ShapeDefinitionRepresentation,SDR,subs.Value());
888 if (TP->TraceLevel() > 1)
889 sout<<" -- Actor : Ent.n0 "<<TP->Model()->Number(CDSR)<<" -> Sharing Ent.no"<<TP->Model()->Number(SDR)<<endl;
892 binder = TP->Find ( SDR );
893 if ( binder.IsNull() ) binder = TransferEntity(SDR,TP);
894 theResult = TransferBRep::ShapeResult (binder);
898 //if ( theResult.IsNull() && ! subs.More() ) {
899 Handle(Transfer_Binder) binder;
900 Standard_Boolean isBound = Standard_False;
901 if (!TP->IsBound(rep)) binder = TransferEntity(rep,TP,isBound);
902 else binder = TP->Find(rep);
903 theResult = TransferBRep::ShapeResult (binder);
906 if ( ! theResult.IsNull() ) {
908 if ( SRRReversed ) ApplyTransformation ( theResult, Trsf.Inverted() );
909 else ApplyTransformation ( theResult, Trsf );
911 shbinder = new TransferBRep_ShapeBinder (theResult);
913 else shbinder.Nullify();
914 TP->Bind(CDSR, shbinder);
918 //=======================================================================
919 //function : TransferEntity
921 //=======================================================================
923 Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(const Handle(StepRepr_ShapeRepresentationRelationship)& und,
924 const Handle(Transfer_TransientProcess)& TP,
925 const Standard_Integer nbrep)
927 // REPRESENTATION_RELATIONSHIP et la famille
928 Handle(TransferBRep_ShapeBinder) shbinder;
930 if (und.IsNull()) return shbinder;
932 // On prend son contenu : Rep1 ou Rep2 , that is the question
933 // on prend les 2. Mais quoi faire des axes
935 TopoDS_Compound Cund;
936 TopoDS_Shape OneResult;
938 B.MakeCompound (Cund);
939 Standard_Integer nsh = 0;
942 Standard_Boolean iatrsf = ComputeSRRWT ( und, TP, Trsf );
944 // Transfert : que faut-il prendre au juste ?
946 for (Standard_Integer i = 1; i <= 2; i ++) {
947 if(nbrep && nbrep != i)
949 Handle(StepRepr_Representation) anitemt;
950 if (i == 1) anitemt = und->Rep1();
951 if (i == 2) anitemt = und->Rep2();
952 Handle(StepShape_ShapeRepresentation) anitem = Handle(StepShape_ShapeRepresentation)::DownCast(anitemt);
953 Handle(Transfer_Binder) binder;
954 Standard_Boolean isBound = Standard_False;
955 if (!TP->IsBound(anitem)) binder = TransferEntity(anitem,TP,isBound);//TP->Transferring(anitem);
956 else binder = TP->Find(anitem);
957 TopoDS_Shape theResult = TransferBRep::ShapeResult (binder);
958 if (!theResult.IsNull()) {
959 OneResult = theResult;
960 B.Add(Cund, theResult);
965 // La Transformation : selon les cas
967 // Appliquer la transformation
970 if (nsh == 1) ApplyTransformation ( OneResult, Trsf );
971 else if (nsh > 1) ApplyTransformation ( Cund, Trsf );
973 if (nsh == 0) shbinder.Nullify();
974 else if (nsh == 1) shbinder = new TransferBRep_ShapeBinder (OneResult);
975 else shbinder = new TransferBRep_ShapeBinder (Cund);
976 TP->Bind(und, shbinder);
981 //=======================================================================
984 //=======================================================================
985 //=======================================================================
986 //function : IsNeedRepresentation
988 //=======================================================================
990 static Standard_Boolean IsNeedRepresentation(const Handle(StepRepr_ShapeAspect)& sa,
991 const Handle(StepRepr_Representation)&repA ,
992 const Handle(Transfer_TransientProcess)& TP)
994 Standard_Boolean IsSDRaspect=Standard_True;
995 Handle(StepRepr_ProductDefinitionShape) PDSA = sa->OfShape();
996 const Interface_Graph& graph = TP->Graph();
997 Interface_EntityIterator subs7 = graph.Sharings(PDSA);
998 for (subs7.Start(); ! PDSA.IsNull() && subs7.More(); subs7.Next()) {
999 Handle(StepShape_ShapeDefinitionRepresentation) sdrA =
1000 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs7.Value());
1001 if ( sdrA.IsNull() ) continue;
1002 // abv 23 Feb 00: use iterator to take into account AP203 hybrid models
1003 Interface_EntityIterator subs8 = graph.Shareds(sdrA);
1004 for (subs8.Start(); subs8.More(); subs8.Next()) {
1005 Handle(StepRepr_Representation) rep2 =
1006 Handle(StepRepr_Representation)::DownCast ( subs8.Value() );
1007 if ( rep2.IsNull() ) {
1008 Handle(StepRepr_ShapeRepresentationRelationship) SRR =
1009 Handle(StepRepr_ShapeRepresentationRelationship)::DownCast ( subs8.Value() );
1010 if ( SRR.IsNull() ) continue;
1011 rep2 = ( sdrA->UsedRepresentation() == SRR->Rep1() ? SRR->Rep2() : SRR->Rep1() );
1013 Standard_Integer i, j; // svv Jan 11 2000 : porting on DEC
1014 for ( i=1; i <= repA->NbItems(); i++ ) {
1015 Handle(StepRepr_RepresentationItem) it = repA->ItemsValue(i);
1016 for ( j=1; j <= rep2->NbItems(); j++ )
1017 if ( it == rep2->ItemsValue(j) ) break;
1018 if ( j > rep2->NbItems() ) break;
1020 if ( i > repA->NbItems() ) IsSDRaspect=Standard_False;
1025 //=======================================================================
1028 //=======================================================================
1030 Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::OldWay(const Handle(Standard_Transient)& start,
1031 const Handle(Transfer_TransientProcess)& TP)
1033 Handle(Message_Messenger) sout = TP->Messenger();
1034 const Interface_Graph& graph = TP->Graph();
1035 Handle(TransferBRep_ShapeBinder) shbinder;
1036 DeclareAndCast(StepShape_ShapeDefinitionRepresentation,sdr,start);
1037 Handle(StepRepr_Representation) rep = sdr->UsedRepresentation();
1039 // abv 7 Oct 99: TRJ2: skip SDRs used only for defining SHAPE_ASPECT (validation properties)
1040 // BUT ONLY if they have representation duplicated with other SDR,
1041 // (SHAPE_ASPECT also used by some systems to define geometry)
1042 Handle(StepRepr_PropertyDefinition) PD = sdr->Definition().PropertyDefinition();
1043 if ( ! PD.IsNull() ) {
1044 Handle(StepRepr_ShapeAspect) SA = PD->Definition().ShapeAspect();
1045 if ( ! SA.IsNull() ) {
1046 if(!IsNeedRepresentation(SA,rep,TP))
1052 if (TP->TraceLevel() > 2)
1053 sout<<" -- Actor : case shape_definition_representation."<<endl;
1055 Handle(Transfer_Binder) binder = TP->Find(rep);
1056 if (binder.IsNull()) binder = TP->Transferring(rep);
1057 //:j2 if (!binder.IsNull()) return binder;
1059 // SDR designant des CDSR (lien implicite, via la UsedRepr)
1061 TopoDS_Compound Cund;
1062 TopoDS_Shape OneResult;
1064 B.MakeCompound (Cund);
1065 Standard_Integer nsh = 0;
1068 shbinder = new TransferBRep_ShapeBinder;
1069 TP->Bind ( start, shbinder ); //:j3 abv 23 Oct 98: rp1sd.stp: bind something to protect against loops
1070 if (!binder.IsNull()) {
1071 TopoDS_Shape theResult = TransferBRep::ShapeResult (binder);
1072 if (!theResult.IsNull()) {
1073 OneResult = theResult;
1074 B.Add(Cund, theResult);
1076 shbinder->SetResult (theResult);
1080 // process subcomponents of assembly (CDSR) and hybrid models (SRR)
1081 Interface_EntityIterator subs = graph.Shareds(start);
1082 Handle(Standard_Type) tCDSR = STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation);
1083 Handle(Standard_Type) tSRR = STANDARD_TYPE(StepRepr_ShapeRepresentationRelationship);
1084 Standard_Integer nbitem=0;
1085 for (subs.Start();subs.More();subs.Next()) nbitem++;
1086 Message_ProgressSentry PS ( TP->GetProgress(), "Sub", 0, nbitem, 1 );
1087 for (subs.Start(); subs.More() && PS.More(); subs.Next() ,PS.Next()) {
1088 Handle(Standard_Transient) anitem = subs.Value();
1089 if ( anitem->DynamicType() != tCDSR && anitem->DynamicType() != tSRR ) continue;
1090 // DeclareAndCast(StepShape_ContextDependentShapeRepresentation,anitem,subs.Value());
1091 // if (anitem.IsNull()) continue;
1093 if (TP->TraceLevel() > 1)
1094 sout<<" -- Actor : Ent.n0 "<<TP->Model()->Number(start)<<" -> Shared Ent.no"<<TP->Model()->Number(anitem)<<endl;
1097 if (!TP->IsBound(anitem)) binder = TP->Transferring(anitem);
1098 else binder = TP->Find(anitem);
1099 TopoDS_Shape theResult = TransferBRep::ShapeResult (binder);
1100 if (!theResult.IsNull()) {
1101 OneResult = theResult;
1102 B.Add(Cund, theResult);
1103 nsh += 2; //abv 11.10.00: 2 instead of 1 in order to keep assembly structure
1107 if (nsh == 0) shbinder = new TransferBRep_ShapeBinder (Cund);//shbinder.Nullify();
1108 else if (nsh == 1) shbinder = new TransferBRep_ShapeBinder (OneResult);
1109 else shbinder = new TransferBRep_ShapeBinder (Cund);
1110 TP->Unbind( start ); //:j3: unbind start (let it be bound by TransferProcess)
1114 //=======================================================================
1115 //function : TransferEntity
1117 //=======================================================================
1119 Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(const Handle(StepGeom_GeometricRepresentationItem)& start,
1120 const Handle(Transfer_TransientProcess)& TP,
1121 const Standard_Boolean isManifold)
1123 Handle(Message_Messenger) sout = TP->Messenger();
1124 Handle(TransferBRep_ShapeBinder) shbinder;
1125 Standard_Boolean found = Standard_False;
1126 StepToTopoDS_Builder myShapeBuilder;
1127 TopoDS_Shape mappedShape;
1128 Standard_Integer nbTPitems = TP->NbMapped();
1131 if (TP->TraceLevel() > 2)
1132 sout << "Begin transfer STEP -> CASCADE, Type "
1133 << start->DynamicType()->Name() << endl;
1138 Handle(StepRepr_Representation) oldSRContext = mySRContext;
1139 if ( mySRContext.IsNull() ) { // if no context, try to find it (ex: r0701_ug.stp #4790)
1140 Handle(StepRepr_Representation) context = FindContext ( start, TP );
1141 if ( context.IsNull() ) {
1142 TP->AddWarning ( start, "Entity with no unit context; default units taken" );
1145 else PrepareUnits ( context, TP );
1147 myShapeBuilder.SetPrecision(myPrecision);
1148 myShapeBuilder.SetMaxTol(myMaxTol);
1151 if (start->IsKind(STANDARD_TYPE(StepShape_FacetedBrep))) {
1152 myShapeBuilder.Init(GetCasted(StepShape_FacetedBrep, start), TP);
1153 found = Standard_True;
1155 else if (start->IsKind(STANDARD_TYPE(StepShape_BrepWithVoids))) {
1156 myShapeBuilder.Init(GetCasted(StepShape_BrepWithVoids, start), TP);
1157 found = Standard_True;
1159 else if (start->IsKind(STANDARD_TYPE(StepShape_ManifoldSolidBrep))) {
1160 myShapeBuilder.Init(GetCasted(StepShape_ManifoldSolidBrep, start), TP);
1161 found = Standard_True;
1163 else if (start->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel))) {
1164 myShapeBuilder.Init(GetCasted(StepShape_ShellBasedSurfaceModel, start), TP, myNMTool);
1165 found = Standard_True;
1167 else if (start->IsKind(STANDARD_TYPE(StepShape_FacetedBrepAndBrepWithVoids))) {
1168 myShapeBuilder.Init(GetCasted(StepShape_FacetedBrepAndBrepWithVoids, start), TP);
1169 found = Standard_True;
1171 else if (start->IsKind(STANDARD_TYPE(StepShape_GeometricSet))) {
1172 myShapeBuilder.Init(GetCasted(StepShape_GeometricSet, start), TP);
1173 found = Standard_True;
1175 else if (start->IsKind(STANDARD_TYPE(StepShape_EdgeBasedWireframeModel))) {
1176 myShapeBuilder.Init(GetCasted(StepShape_EdgeBasedWireframeModel, start), TP);
1177 found = Standard_True;
1179 else if (start->IsKind(STANDARD_TYPE(StepShape_FaceBasedSurfaceModel))) {
1180 myShapeBuilder.Init(GetCasted(StepShape_FaceBasedSurfaceModel, start), TP);
1181 found = Standard_True;
1184 catch(Standard_Failure) {
1185 TP->AddFail(start,"Exeption is raised. Entity was not translated.");
1186 TP->Bind(start, shbinder);
1190 if (found && myShapeBuilder.IsDone()) {
1191 mappedShape = myShapeBuilder.Value();
1192 // Apply ShapeFix (on manifold shapes only. Non-manifold topology is processed separately: ssv; 13.11.2010)
1194 Handle(Standard_Transient) info;
1196 XSAlgo::AlgoContainer()->ProcessShape(mappedShape, myPrecision, myMaxTol,
1197 "read.step.resource.name",
1198 "read.step.sequence", info);
1199 XSAlgo::AlgoContainer()->MergeTransferInfo(TP, info, nbTPitems);
1202 found = !mappedShape.IsNull();
1203 if (found && shbinder.IsNull()) shbinder = new TransferBRep_ShapeBinder (mappedShape);
1206 if (TP->TraceLevel() > 2)
1207 sout<<"End transfer STEP -> CASCADE :" << (found ? "OK" : " : no result")<<endl;
1208 if (TP->TraceLevel() > 2)
1211 if ( oldSRContext.IsNull() && ! mySRContext.IsNull() ) //:S4136
1212 PrepareUnits ( oldSRContext, TP );
1213 TP->Bind(start, shbinder);
1218 //=======================================================================
1219 //function : TransferEntity
1221 //=======================================================================
1223 Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(const Handle(StepRepr_MappedItem)& mapit,
1224 const Handle(Transfer_TransientProcess)& TP)
1226 Handle(TransferBRep_ShapeBinder) shbinder;
1228 // --------------------------------------------------------------
1229 // On se trouve ici dans un contexte " d'assemblage geometrique "
1231 // --------------------------------------------------------------
1233 //:S4136: abv 20 Apr 99: as1ug.stp: MAPPED_ITEM transformation computed
1234 // taking into account units of origin and target SHAPE_REPRESENTATIONs
1236 // La Shape, et la mise en position
1237 Handle(StepShape_ShapeRepresentation) maprep = Handle(StepShape_ShapeRepresentation)::
1238 DownCast(mapit->MappingSource()->MappedRepresentation());
1239 //Handle(StepRepr_Representation) maprep = mapit->MappingSource()->MappedRepresentation();
1240 Standard_Boolean isBound = Standard_False;
1241 Handle(Transfer_Binder) binder = TP->Find(maprep);
1242 if (binder.IsNull()) binder = TransferEntity(maprep,TP,isBound);
1243 shbinder = Handle(TransferBRep_ShapeBinder)::DownCast(binder);
1244 if (shbinder.IsNull()) TP->AddWarning(mapit,"No Shape Produced");
1246 TopoDS_Shape mappedShape = shbinder->Result();
1247 if ( ! mappedShape.IsNull() ) {
1249 // Positionnement : 2 formules
1250 // 1/ Ax2 dans Source et comme Target : passage de Source a Target
1251 // 2/ CartesianOperator3d comme Target : on applique
1254 Standard_Boolean ok = Standard_False;
1256 Handle(StepGeom_CartesianTransformationOperator3d) CartOp =
1257 Handle(StepGeom_CartesianTransformationOperator3d)::DownCast(mapit->MappingTarget());
1258 if ( ! CartOp.IsNull() ) {
1259 ok = StepToGeom_MakeTransformation3d::Convert( CartOp, Trsf );
1262 Handle(StepGeom_Axis2Placement3d) Origin =
1263 Handle(StepGeom_Axis2Placement3d)::DownCast(mapit->MappingSource()->MappingOrigin());
1264 Handle(StepGeom_Axis2Placement3d) Target =
1265 Handle(StepGeom_Axis2Placement3d)::DownCast(mapit->MappingTarget());
1266 if ( ! Origin.IsNull() && ! Target.IsNull() ) {
1268 Handle(StepRepr_Representation) rep = mySRContext; // NOTE: copy of handle !
1269 ComputeTransformation ( Origin, Target, maprep, rep, TP, Trsf );
1274 if ( ok ) ApplyTransformation ( mappedShape, Trsf );
1275 else TP->AddWarning (mapit,"Mapped Item, case not recognized, location ignored");
1277 shbinder = new TransferBRep_ShapeBinder (mappedShape);
1280 TP->Bind(mapit, shbinder);
1283 //=======================================================================
1284 //function : TransferEntity
1286 //=======================================================================
1288 Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(const Handle(StepShape_FaceSurface)& fs,
1289 const Handle(Transfer_TransientProcess)& TP)
1292 // Cas bien utile meme si non reconnu explicitement
1293 Handle(TransferBRep_ShapeBinder) sb;
1294 Standard_Integer nbTPitems = TP->NbMapped();
1298 StepToTopoDS_Tool myTool;
1299 StepToTopoDS_DataMapOfTRI aMap;
1301 myTool.Init(aMap, TP);
1302 StepToTopoDS_TranslateFace myTF;
1303 myTF.SetPrecision(myPrecision);
1304 myTF.SetMaxTol(myMaxTol);
1306 // Non-manifold topology is not processed here (ssv; 15.11.2010)
1307 StepToTopoDS_NMTool dummyNMTool;
1308 myTF.Init (fs, myTool, dummyNMTool);
1309 Handle(StepRepr_Representation) oldSRContext = mySRContext;
1310 if ( mySRContext.IsNull() ) { // if no context, try to find it (ex: r0701_ug.stp #4790)
1311 Handle(StepRepr_Representation) context = FindContext ( fs, TP );
1312 if ( context.IsNull() ) {
1313 TP->AddWarning ( fs, "Entity with no unit context; default units taken" );
1316 else PrepareUnits ( context, TP );
1320 Handle(Transfer_Binder) binder = TP->Find (fs);
1321 sb = Handle(TransferBRep_ShapeBinder)::DownCast ( binder );
1322 if ( ! sb.IsNull() && ! sb->Result().IsNull() ) {
1323 TopoDS_Shape S = sb->Result();
1325 Handle(Standard_Transient) info;
1326 TopoDS_Shape shape = XSAlgo::AlgoContainer()->ProcessShape( S, myPrecision, myMaxTol,
1327 "read.step.resource.name",
1328 "read.step.sequence", info );
1329 // TopoDS_Shape shape = XSAlgo::AlgoContainer()->PerformFixShape( S, TP, myPrecision, myMaxTol );
1331 sb->SetResult ( shape );
1333 XSAlgo::AlgoContainer()->MergeTransferInfo(TP, info, nbTPitems);
1337 if ( oldSRContext.IsNull() && ! mySRContext.IsNull() ) //:S4136
1338 PrepareUnits ( oldSRContext, TP );
1340 return sb; // TP->Find (start);
1342 catch(Standard_Failure)
1344 TP->AddFail(fs,"Exeption is raised. Entity was not translated.");
1350 //=======================================================================
1351 //function : TransferShape
1353 //=======================================================================
1355 Handle(Transfer_Binder) STEPControl_ActorRead::TransferShape(const Handle(Standard_Transient)& start,
1356 const Handle(Transfer_TransientProcess)& TP,
1357 const Standard_Boolean isManifold)
1359 if (start.IsNull()) return NullResult();
1360 XSAlgo::AlgoContainer()->PrepareForTransfer();
1362 // myContext.SetModel ( Handle(StepData_StepModel)::DownCast ( TP->Model() ) ); // for asking IsAP203?
1364 Handle(Message_Messenger) sout = TP->Messenger();
1366 // POUR MISE AU POINT, a supprimer ensuite
1367 // sout<<"STEP->Shape, ent n0 "<<TP->Model()->Number(start)<<" Level="<<TP->NestingLevel()<<endl;
1368 if (TP->TraceLevel() > 1)
1369 sout<<" -- Actor : Transfer Ent.n0 "<<TP->Model()->Number(start)<<" Type "<<start->DynamicType()->Name()<<endl;
1372 Handle(TransferBRep_ShapeBinder) shbinder;
1375 // Product Definition Entities
1376 // They should be treated with Design Manager
1377 // case ShapeDefinitionRepresentation if ProductMode != ON
1378 TCollection_AsciiString aProdMode = Interface_Static::CVal("read.step.product.mode");
1379 if(!aProdMode.IsEqual("ON") &&
1380 start->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation)))
1381 shbinder = OldWay(start,TP);
1384 else if(start->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition))) {
1385 Handle(StepBasic_ProductDefinition) PD =
1386 Handle(StepBasic_ProductDefinition)::DownCast(start);
1387 shbinder = TransferEntity(PD,TP);
1390 // NextAssemblyUsageOccurrence
1391 else if (start->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence))) {
1392 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
1393 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(start);
1394 shbinder = TransferEntity(NAUO,TP);
1398 // Shape Representation
1399 else if (start->IsKind(STANDARD_TYPE(StepShape_ShapeRepresentation))) {
1400 DeclareAndCast(StepShape_ShapeRepresentation,sr,start);
1401 Standard_Boolean isBound = Standard_False;
1402 shbinder = TransferEntity(sr,TP,isBound);
1405 // --------------------------------------------------------------
1406 // On se trouve ici aussi dans un contexte " d'assemblage geometrique "
1407 // - ShapeRepresentationRelationship + Transformation ou non
1408 // --------------------------------------------------------------
1410 else if (start->IsKind(STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation))) {
1411 DeclareAndCast(StepShape_ContextDependentShapeRepresentation,CDSR,start);
1412 shbinder = TransferEntity(CDSR,TP);
1415 else if (start->IsKind (STANDARD_TYPE(StepRepr_ShapeRepresentationRelationship)) ) {
1416 // REPRESENTATION_RELATIONSHIP et la famille
1418 DeclareAndCast(StepRepr_ShapeRepresentationRelationship,und,start);
1419 shbinder = TransferEntity(und,TP);
1422 else if (start->IsKind (STANDARD_TYPE(StepGeom_GeometricRepresentationItem)) ) {
1423 // Here starts the entity to be treated : Shape Representation Subtype
1424 // It can be also other Root entities
1425 DeclareAndCast(StepGeom_GeometricRepresentationItem,git,start);
1426 shbinder = TransferEntity(git, TP, isManifold);
1428 else if (start->IsKind(STANDARD_TYPE(StepRepr_MappedItem))) {
1429 DeclareAndCast(StepRepr_MappedItem,mapit,start);
1430 shbinder= TransferEntity(mapit,TP);
1432 else if (start->IsKind(STANDARD_TYPE(StepShape_FaceSurface))) {
1433 DeclareAndCast(StepShape_FaceSurface,fs,start);
1434 shbinder = TransferEntity(fs,TP);
1437 // if (!shbinder.IsNull()) TP->Bind(start,binder);
1441 // ============================================================================
1442 // Method : STEPControl_ActorRead::PrepareUnits
1443 // Purpose : Set the unit conversion factors
1444 // ============================================================================
1446 void STEPControl_ActorRead::PrepareUnits(const Handle(StepRepr_Representation)& rep,
1447 const Handle(Transfer_TransientProcess)& TP)
1451 Standard_Integer stat1, stat2 = 0; // sera alimente par STEPControl_Unit
1452 // DeclareAndCast(StepShape_ShapeRepresentation,sr,start);
1454 // TP->AddWarning(sr,"Not a ShapeRepresentation, default unit taken");
1459 // Get Units Applied to this model
1460 Handle(StepRepr_RepresentationContext) theRepCont = rep->ContextOfItems();
1461 if (theRepCont.IsNull()) {
1462 TP->AddWarning(rep,"Bad RepresentationContext, default unit taken");
1467 // --------------------------------------------------
1468 // Complex ENTITY : GeometricRepresentationContext &&
1469 // GlobalUnitAssignedContext
1470 // --------------------------------------------------
1472 STEPConstruct_UnitContext myUnit;
1473 Handle(StepRepr_GlobalUnitAssignedContext) theGUAC;
1474 Handle(StepRepr_GlobalUncertaintyAssignedContext) aTol;
1476 if (theRepCont->IsKind(STANDARD_TYPE(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext))) {
1477 DeclareAndCast(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext, theGRCAGAUC,theRepCont);
1478 theGUAC = theGRCAGAUC->GlobalUnitAssignedContext();
1479 // TP->AddWarning(theRepCont,"No Length Uncertainty, last defined one is taken");
1482 // ----------------------------------------------------
1483 // Complex ENTITY : GeometricRepresentationContext &&
1484 // GlobalUnitAssignedContext &&
1485 // GlobalUncertaintyAssignedContext
1486 // ----------------------------------------------------
1488 if (theRepCont->IsKind(STANDARD_TYPE(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx))) {
1489 DeclareAndCast(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx,
1490 theGRCAGAUC,theRepCont);
1491 theGUAC = theGRCAGAUC->GlobalUnitAssignedContext();
1492 aTol = theGRCAGAUC->GlobalUncertaintyAssignedContext();
1496 // ----------------------------------------------------
1497 // Decoding and Setting the Values
1498 // ----------------------------------------------------
1500 if (!theGUAC.IsNull()) {
1501 stat1 = myUnit.ComputeFactors(theGUAC);
1502 Standard_Integer anglemode = Interface_Static::IVal("step.angleunit.mode");
1503 Standard_Real angleFactor = ( anglemode == 0 ? myUnit.PlaneAngleFactor() :
1504 anglemode == 1 ? 1. : PI/180. );
1505 UnitsMethods::InitializeFactors(myUnit.LengthFactor(),
1507 myUnit.SolidAngleFactor());
1508 if (stat1 != 0) TP->AddWarning (theRepCont,myUnit.StatusMessage(stat1));
1511 if (!aTol.IsNull()) {
1512 stat2 = myUnit.ComputeTolerance (aTol);
1513 if (stat2 != 0) TP->AddWarning (theRepCont,myUnit.StatusMessage(stat2));
1516 // myPrecision = Precision::Confusion();
1517 if (Interface_Static::IVal("read.precision.mode") == 1) //:i1 gka S4136 05.04.99
1518 myPrecision = Interface_Static::RVal("read.precision.val");
1519 else if (myUnit.HasUncertainty())
1520 myPrecision = myUnit.Uncertainty() * myUnit.LengthFactor();
1522 TP->AddWarning(theRepCont,"No Length Uncertainty, value of read.precision.val is taken");
1523 myPrecision = Interface_Static::RVal("read.precision.val");
1525 myMaxTol = Max ( myPrecision, Interface_Static::RVal("read.maxprecision.val") );
1526 // Assign uncertainty
1527 // Interface_Static::SetRVal("lastpreci",UpdatedValue);
1529 if (TP->TraceLevel() > 1)
1530 TP->Messenger() <<" Cc1ToTopoDS : Length Unit = "<<myUnit.LengthFactor()<<" Tolerance CASCADE = "<<myPrecision<<endl;
1534 //=======================================================================
1535 //function : ResetUnits
1537 //=======================================================================
1539 void STEPControl_ActorRead::ResetUnits ()
1541 UnitsMethods::InitializeFactors ( 1, 1, 1 );
1542 myPrecision = Interface_Static::RVal("read.precision.val");
1543 myMaxTol = Max ( myPrecision, Interface_Static::RVal("read.maxprecision.val") );
1546 //=======================================================================
1547 //function : ComputeTransformation
1549 //=======================================================================
1551 //:S4136 abv 20 Apr 99: as1ug.stp: compute transformation taking units into account
1552 Standard_Boolean STEPControl_ActorRead::ComputeTransformation (const Handle(StepGeom_Axis2Placement3d) &Origin,
1553 const Handle(StepGeom_Axis2Placement3d) &Target,
1554 const Handle(StepRepr_Representation) &OrigContext,
1555 const Handle(StepRepr_Representation) &TargContext,
1556 const Handle(Transfer_TransientProcess) &TP,
1559 Trsf = gp_Trsf(); // reinit
1560 if ( Origin.IsNull() || Target.IsNull() ) return Standard_False;
1562 //:abv 31.10.01: TEST_MCI_2.step: check that Ax1 and Ax2 belong to
1563 // corresponding reps and fix case of inversion error
1564 Handle(StepGeom_Axis2Placement3d) org = Origin;
1565 Handle(StepGeom_Axis2Placement3d) trg = Target;
1566 Standard_Integer code1=0, code2=0, i;
1567 for ( i=1; code1 != 1 && i <= OrigContext->NbItems(); i++ ) {
1568 if ( OrigContext->ItemsValue(i) == org ) code1 = 1;
1569 else if ( OrigContext->ItemsValue(i) == trg ) code1 = -1;
1571 for ( i=1; code2 != 1 && i <= TargContext->NbItems(); i++ ) {
1572 if ( TargContext->ItemsValue(i) == org ) code2 = -1;
1573 else if ( TargContext->ItemsValue(i) == trg ) code2 = 1;
1575 if ( code1 != 1 && code2 != 1 ) {
1576 if ( code1 == -1 && code2 == -1 ) {
1577 Handle(StepGeom_Axis2Placement3d) swp = org; org = trg; trg = swp;
1578 TP->AddWarning ( org, "Axis placements are swapped in SRRWT; corrected" );
1581 TP->AddWarning ( ( code1 == 1 ? trg : org ),
1582 "Axis placement used by SRRWT does not belong to corresponding representation" );
1586 // translate axis_placements taking units into account
1587 Handle(StepRepr_Representation) oldSRContext = mySRContext;
1588 if ( OrigContext != oldSRContext ) PrepareUnits(OrigContext,TP);
1589 Handle(Geom_Axis2Placement) theOrig;
1590 StepToGeom_MakeAxis2Placement::Convert(org,theOrig);
1591 if ( TargContext != OrigContext ) PrepareUnits(TargContext,TP);
1592 Handle(Geom_Axis2Placement) theTarg;
1593 StepToGeom_MakeAxis2Placement::Convert(trg,theTarg);
1594 if ( oldSRContext != TargContext ) PrepareUnits(oldSRContext,TP);
1596 gp_Ax3 ax3Orig(theOrig->Ax2());
1597 gp_Ax3 ax3Targ(theTarg->Ax2());
1598 //ax3Orig - defines CS for component(always is equal to (0 0 0 ))(related product from NAUO)
1599 //ax3Targ - defines place of component in assemby CS (relating product
1600 // ne pas se tromper de sens !
1604 gp_Ax3 anAxis(gp_Pnt(0.,0.,0.), gp::DZ(), gp::DX());;
1605 aTrsf2.SetTransformation(anAxis,ax3Orig);
1607 aTrsf3.SetTransformation(ax3Targ,anAxis);
1609 Trsf = aTrsf3 * aTrsf2;
1611 return Trsf.Form() != gp_Identity;
1614 //=======================================================================
1615 //function : ReadSRRWT
1617 //=======================================================================
1619 //:j2 abv 22 Oct 98: auxiliary function: reading transformation from SRRWT
1620 Standard_Boolean STEPControl_ActorRead::ComputeSRRWT (const Handle(StepRepr_RepresentationRelationship) &SRR,
1621 const Handle(Transfer_TransientProcess) &TP,
1624 Trsf = gp_Trsf(); // init
1626 DeclareAndCast(StepRepr_ShapeRepresentationRelationshipWithTransformation,srwt,SRR);
1627 if ( srwt.IsNull() ) return Standard_False;
1629 StepRepr_Transformation SelectTrans = srwt->TransformationOperator();
1631 // cartesian transformation
1632 Handle(StepGeom_CartesianTransformationOperator3d) CartOp =
1633 Handle(StepGeom_CartesianTransformationOperator3d)::DownCast(SelectTrans.Value());
1634 if ( ! CartOp.IsNull() ) {
1635 // reset units (by Rep2 - ?)
1636 Handle(StepRepr_Representation) oldSRContext = mySRContext;
1637 if ( SRR->Rep2() != oldSRContext ) PrepareUnits(SRR->Rep2(),TP);
1638 StepToGeom_MakeTransformation3d::Convert( CartOp, Trsf );
1639 if ( SRR->Rep2() != oldSRContext ) PrepareUnits(oldSRContext,TP);
1640 return Trsf.Form() != gp_Identity;
1643 // item-defined transformation
1644 Handle(StepRepr_ItemDefinedTransformation) ItemDef =
1645 SelectTrans.ItemDefinedTransformation();
1646 if ( ItemDef.IsNull() ) return Standard_False;
1648 Handle(StepGeom_Axis2Placement3d) Ax1 =
1649 Handle(StepGeom_Axis2Placement3d)::DownCast(ItemDef->TransformItem1());
1650 Handle(StepGeom_Axis2Placement3d) Ax2 =
1651 Handle(StepGeom_Axis2Placement3d)::DownCast(ItemDef->TransformItem2());
1652 if ( Ax1.IsNull() || Ax2.IsNull() ) return Standard_False;
1653 return ComputeTransformation ( Ax1, Ax2, SRR->Rep1(), SRR->Rep2(), TP, Trsf);
1656 //=======================================================================
1657 // Method : closeIDEASShell
1658 // Purpose : Attempts to close the passed Shell with the passed closing
1659 // Shells. Cuts redundant Faces from the closing Shells if any
1660 //=======================================================================
1662 TopoDS_Shell STEPControl_ActorRead::closeIDEASShell(const TopoDS_Shell& shell,
1663 const TopTools_ListOfShape& closingShells) {
1665 // Make Shell to provide closeness adjustments
1666 TopoDS_Shell result;
1667 BRep_Builder brepBuilder;
1668 brepBuilder.MakeShell(result);
1670 // Firstly, add all existing faces to the new Shell
1671 TopExp_Explorer currentFExp(shell, TopAbs_FACE);
1672 for ( ; currentFExp.More(); currentFExp.Next() ) {
1673 TopoDS_Face currentFace = TopoDS::Face( currentFExp.Current() );
1674 brepBuilder.Add(result, currentFace);
1677 TopTools_ListIteratorOfListOfShape itL(closingShells);
1678 TopTools_ListOfShape closingFaces;
1680 // Then add the closing faces
1681 for ( ; itL.More(); itL.Next() ) {
1682 TopoDS_Shape currentClosing = itL.Value();
1683 TopExp_Explorer faceExp(currentClosing, TopAbs_FACE);
1685 for ( ; faceExp.More(); faceExp.Next() ) {
1686 TopoDS_Face currentFace = TopoDS::Face( faceExp.Current() );
1687 brepBuilder.Add(result, currentFace);
1688 // Store each added closing face for subsequent processing
1689 closingFaces.Append(currentFace);
1693 // Check if the result is closed
1694 BRepCheck_Shell checker( TopoDS::Shell(result) );
1695 BRepCheck_Status checkStatus = checker.Closed();
1696 if (checkStatus == BRepCheck_NoError)
1697 result.Closed(Standard_True);
1699 return shell; // Cannot close this shell, skip it so...
1701 // Try to remove redundant Faces
1702 for ( itL.Initialize(closingFaces); itL.More(); itL.Next() ) {
1703 TopoDS_Face currentFace = TopoDS::Face( itL.Value() );
1704 // Remove face to see if Shell is still closed
1705 brepBuilder.Remove(result, currentFace);
1706 BRepCheck_Shell subChecker( TopoDS::Shell(result) );
1707 BRepCheck_Status subCheckStatus = subChecker.Closed();
1708 // If Shell becomes open, just put the deleted face back
1709 if (subCheckStatus != BRepCheck_NoError)
1710 brepBuilder.Add(result, currentFace);
1713 cout << "Redundant closing face detected: REMOVED from shell";
1722 //=======================================================================
1723 // Method : computeIDEASClosings
1724 // Purpose : For each Shell from the compound passed (comp), find all
1725 // non-manifold adjacent Shells and put the results into
1726 // the passed map (shellClosingMap)
1727 //=======================================================================
1729 void STEPControl_ActorRead::computeIDEASClosings(const TopoDS_Compound& comp,
1730 TopTools_IndexedDataMapOfShapeListOfShape& shellClosingsMap) {
1731 TopExp_Explorer shellExpA(comp, TopAbs_SHELL);
1733 for ( ; shellExpA.More(); shellExpA.Next() ) {
1734 TopoDS_Shape shellA = shellExpA.Current();
1735 TopExp_Explorer shellExpB(comp, TopAbs_SHELL);
1736 TopTools_ListOfShape closingShells;
1738 for ( ; shellExpB.More(); shellExpB.Next() ) {
1739 TopoDS_Shape shellB = shellExpB.Current();
1740 if ( shellA.IsSame(shellB) )
1742 // Check whether ShellB is non-manifold and adjacent to ShellA.
1743 // If so, ShellA has a chance to be closed with ShellB
1744 if ( myNMTool.IsSuspectedAsClosing(shellA, shellB) )
1745 closingShells.Append(shellB);
1748 if ( !closingShells.IsEmpty() )
1749 shellClosingsMap.Add(shellA, closingShells);