OCC22238 Bug during step file importation
[occt.git] / src / STEPControl / STEPControl_ActorRead.cxx
CommitLineData
7fd59977 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>
7
8// #include <Interface_InterfaceModel.hxx> // pour mise au point
9
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>
18
19// MappedItem :
20#include <StepRepr_MappedItem.hxx>
21#include <StepGeom_Axis2Placement3d.hxx>
22#include <StepRepr_RepresentationMap.hxx>
23#include <StepToTopoDS_MakeTransformed.hxx>
24
25// FaceSurface :
26#include <StepShape_FaceSurface.hxx>
27#include <StepToTopoDS_Tool.hxx>
28#include <StepToTopoDS_DataMapOfTRI.hxx>
29#include <StepToTopoDS_TranslateFace.hxx>
30
31// Unites :
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>
39
40#include <STEPConstruct_UnitContext.hxx>
41#include <UnitsMethods.hxx>
42
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>
52
53#include <BRep_Builder.hxx>
54#include <StepToTopoDS_Builder.hxx>
55#include <TopoDS_Compound.hxx>
56#include <TopoDS_Shape.hxx>
57
58#include <TransferBRep_ShapeBinder.hxx>
59
60#include <Interface_Static.hxx>
61#include <Interface_Macros.hxx>
62#include <Interface_InterfaceModel.hxx>
63
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>
72#include <gp_Ax3.hxx>
73#include <StepRepr_ShapeAspect.hxx>
74#include <XSAlgo.hxx>
75#include <XSAlgo_AlgoContainer.hxx>
76#include <StepShape_EdgeBasedWireframeModel.hxx>
77#include <StepShape_FaceBasedSurfaceModel.hxx>
78
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>
85
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>
96
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>
113
114#define TRANSLOG
115
116// ============================================================================
117// Function: DumpWhatIs
118// Purpose: Use it in DEB mode to dump your shapes
119// ============================================================================
120
121static void DumpWhatIs(const TopoDS_Shape& S) {
122
123 TopTools_MapOfShape aMapOfShape;
124 aMapOfShape.Add(S);
125 TopTools_ListOfShape aListOfShape;
126 aListOfShape.Append(S);
127 TopTools_ListIteratorOfListOfShape itL(aListOfShape);
128 Standard_Integer nbSolids = 0,
129 nbShells = 0,
130 nbOpenShells = 0,
131 nbFaces = 0,
132 nbWires = 0,
133 nbEdges = 0,
134 nbVertexes = 0;
135
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) )
141 continue;
142 aListOfShape.Append(aSubShape);
143 if (aSubShape.ShapeType() == TopAbs_SOLID)
144 nbSolids++;
145 if (aSubShape.ShapeType() == TopAbs_SHELL) {
146 if ( !aSubShape.Closed() )
147 nbOpenShells++;
148 nbShells++;
149 }
150 if (aSubShape.ShapeType() == TopAbs_FACE)
151 nbFaces++;
152 if (aSubShape.ShapeType() == TopAbs_WIRE)
153 nbWires++;
154 if (aSubShape.ShapeType() == TopAbs_EDGE)
155 nbEdges++;
156 if (aSubShape.ShapeType() == TopAbs_VERTEX)
157 nbVertexes++;
158 }
159 }
160 #ifdef DEB
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;
169 #endif
170}
171
172// ============================================================================
173// Method : STEPControl_ActorRead::STEPControl_ActorRead ()
174// Purpose : Empty constructor
175// ============================================================================
176
177STEPControl_ActorRead::STEPControl_ActorRead() {}
178
179// ============================================================================
180// Method : STEPControl_ActorRead::Recognize
181// Purpose : tells if an entity is valid for transfer by this Actor
182// ============================================================================
183
184Standard_Boolean STEPControl_ActorRead::Recognize
185 (const Handle(Standard_Transient)& start)
186{
187 if (start.IsNull()) return Standard_False;
188
189 if (start->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition))) return Standard_True;
190
191 if (start->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence))) return Standard_True;
192
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;
196
197 DeclareAndCast(StepShape_ShapeRepresentation,sr,start);
198 if (!sr.IsNull()) {
199 Standard_Integer i,nb = sr->NbItems();
200 for (i = 1; i <= nb; i ++) {
201 if (Recognize (sr->ItemsValue(i)) ) return Standard_True;
202 }
203 return Standard_False;
204 }
205
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;
216
217
218// REPRESENTATION_RELATIONSHIP et consorts : on regarde le contenu ...
219// On prend WithTransformation ou non ...
220
221 if (start->IsKind (STANDARD_TYPE(StepRepr_ShapeRepresentationRelationship))) {
222 DeclareAndCast(StepRepr_ShapeRepresentationRelationship,und,start);
223
224// On prend son contenu
225
226 if (Recognize(und->Rep1()) || Recognize(und->Rep2())) return Standard_True;
227 return Standard_False;
228 }
229
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 ...
237 }
238
239 return Standard_False;
240}
241
242
243// ============================================================================
244// Method : STEPControl_ActorRead::Transfer
245// Purpose : recursive method that acces to the root entities and start the
246// mapping
247// ============================================================================
248
249Handle(Transfer_Binder) STEPControl_ActorRead::Transfer
250(const Handle(Standard_Transient)& start,
251 const Handle(Transfer_TransientProcess)& TP)
252{
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();
260 #ifdef DEB
261 cout << "Preprocessor version detected: " << aPPVersion->ToCString() << endl;
262 #endif
263 Standard_Integer anIDeasResult = aPPVersion->Search("I-DEAS");
264 if (anIDeasResult != -1) {
265 #ifdef DEB
266 cout << "Recognized as I-DEAS STP" << endl;
267 #endif
268 myNMTool.SetIDEASCase(Standard_True);
269 }
270 }
271 }
272 // [END] Get version of preprocessor (to detect I-Deas case) (ssv; 23.11.2010)
273 return TransferShape (start,TP);
274}
275
276
277// ============================================================================
278// auxiliary function : ApplyTransformation
279// ============================================================================
280static void ApplyTransformation (TopoDS_Shape& shape, const gp_Trsf &Trsf)
281{
282 if ( Trsf.Form() == gp_Identity ) return;
283 TopLoc_Location theLoc ( Trsf );
284 shape.Move (theLoc);
285}
286
287
288// ============================================================================
289// auxiliary function : FindContext
290// ============================================================================
291static Handle(StepRepr_Representation) FindContext (const Handle(Standard_Transient) &start,
292 const Handle(Transfer_TransientProcess) &TP,
293 const Standard_Integer level=10 )
294{
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 );
301 }
302 return rep;
303}
304
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//=======================================================================
310
311static Standard_Integer FindShapeReprType (const Handle(Standard_Transient) &start)
312{
313 if(start->IsKind(STANDARD_TYPE(StepShape_AdvancedBrepShapeRepresentation)))
314 return 2;
315 if(start->IsKind(STANDARD_TYPE(StepShape_ManifoldSurfaceShapeRepresentation)))
316 return 3;
317 if(start->IsKind(STANDARD_TYPE(StepShape_GeometricallyBoundedSurfaceShapeRepresentation)))
318 return 4;
319 if(start->IsKind(STANDARD_TYPE(StepShape_FacetedBrepShapeRepresentation)))
320 return 5;
321 if(start->IsKind(STANDARD_TYPE(StepShape_EdgeBasedWireframeShapeRepresentation)))
322 return 6;
323 if(start->IsKind(STANDARD_TYPE(StepShape_GeometricallyBoundedWireframeShapeRepresentation)))
324 return 7;
325 return 8;
326}
327
328//=======================================================================
329//function : getListSDR
330//purpose : Get SDRs assigned to ShapeAspect, which may potentially
331// correspond to hybrid models in AP203 before 1998
332//=======================================================================
333
334static void getListSDR(const Handle(StepRepr_ShapeAspect)& sa,
335 Handle(TColStd_HSequenceOfTransient)& listSDR,
336 const Handle(Transfer_TransientProcess)& TP)
337{
338 const Interface_Graph& graph = TP->Graph();
339
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)))
345 return;
346 }
347
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);
361 }
362 }
363}
364
365//=======================================================================
366//function : getSDR
367//purpose : Find all SDRs related to given PDS
368//=======================================================================
369
370static void getSDR(const Handle(StepRepr_ProductDefinitionShape)& PDS,
371 Handle(TColStd_HSequenceOfTransient)& listSDR,
372 Handle(TColStd_HSequenceOfTransient)& listSDRAspect,
373 const Handle(Transfer_TransientProcess)& TP)
374{
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();
380
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()) {
386
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();
392
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);
398 else {
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());
404 delta = iDiff;
405 }
406 // take all representations of preferred or closest type
407 if ( iDiff <= delta )
408 listSDR->Append(sdr);
409 }
410 }
411 continue;
412 }
413
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);
419 continue;
420 }
421 }
422}
423
424
425//=======================================================================
426//function : TransferEntity
427//purpose :
428//=======================================================================
429 Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(const Handle(StepBasic_ProductDefinition)& PD,
430 const Handle(Transfer_TransientProcess)& TP)
431
432{
433 Handle(Message_Messenger) sout = TP->Messenger();
434 Handle(TransferBRep_ShapeBinder) shbinder;
435
436 TopoDS_Compound Cund;
437 TopoDS_Shape Result1;
438 BRep_Builder B;
439 B.MakeCompound (Cund);
440
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);
454 continue;
455 }
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);
462 continue;
463 }
464 }
465
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");
470
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");
475 if ( ! readSA )
476 listSDRAspect->Clear();
477
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);
482
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 ) )
490 listSDR->Clear();
491 else if ( readAssembly == 4 )
492 listNAUO->Clear();
493
494 Standard_Integer nbEnt = listSDR->Length() + listNAUO->Length();
495 if ( nbEnt <=0 )
496 return shbinder;
497
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;
501
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));
506
507#ifdef TRANSLOG
508 if (TP->TraceLevel() > 1)
509 sout<<" -- Actor : Ent.n0 "<<TP->Model()->Number(PD)<<" -> Shared Ent.no"<<TP->Model()->Number(NAUO)<<endl;
510#endif
511 Handle(Transfer_Binder) binder;
512 if (!TP->IsBound(NAUO)) binder = TransferEntity(NAUO,TP);
513 else binder = TP->Find(NAUO);
514
515 TopoDS_Shape theResult = TransferBRep::ShapeResult (binder);
516 if (!theResult.IsNull()) {
517 Result1 = theResult;
518 B.Add(Cund, theResult);
519 nbComponents++;
520 }
521 }
522
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());
528 if ( rep.IsNull() )
529 continue;
530
531 // translate SDR representation
532 Standard_Boolean isBound = Standard_True;
533 Handle(Transfer_Binder) binder = TP->Find(rep);
534 if (binder.IsNull())
535 binder = TransferEntity(rep,TP,isBound);
536
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)
542 continue;
543
544 // record shape resulting from translation
545 TopoDS_Shape theResult;
546 if ( ! binder.IsNull() ) {
547 theResult = TransferBRep::ShapeResult (binder);
548 if (!theResult.IsNull()) {
549 Result1 = theResult;
550 B.Add(Cund, theResult);
551 nbShapes++;
552 }
553 }
554
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);
570 Result1 = theResult;
571 B.Add(Cund, theResult);
572 nbShapes++;
573 }
574 }
575 }
576 }
577
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" );
581
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);
585 else
586 shbinder = new TransferBRep_ShapeBinder (Cund);
587
588 //TP->Unbind( PD ); //:j3: unbind start (let it be bound by TransferProcess)
589 TP->Bind(PD, shbinder);
590 return shbinder;
591}
592
593//=======================================================================
594//function : TransferEntity
595//purpose :
596//=======================================================================
597
598Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(const Handle(StepRepr_NextAssemblyUsageOccurrence)& NAUO ,
599 const Handle(Transfer_TransientProcess)& TP)
600{
601 Handle(TransferBRep_ShapeBinder) shbinder;
602 Handle(StepBasic_ProductDefinition) PD;
603 const Interface_Graph& graph = TP->Graph();
604 gp_Trsf Trsf;
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;
638 PD=PD1;
639 }
640 }
641 else if(subs3.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeRepresentationRelationship))) {
642 SRR = Handle(StepRepr_ShapeRepresentationRelationship)::DownCast(subs3.Value());
643 }
644 }
645 }
646 }
647
648 Handle(Transfer_Binder) binder;
649 TopoDS_Shape theResult;
650 shbinder.Nullify();
651
652 if(IsDepend) {
653
654 if(!PD.IsNull()) {
655 binder = TP->Find(PD);
656 if ( binder.IsNull() ) binder = TransferEntity(PD,TP);
657 theResult = TransferBRep::ShapeResult(binder);
658 if (!theResult.IsNull()) {
659 if (iatrsf) {
660 if ( SRRReversed ) ApplyTransformation ( theResult, Trsf.Inverted() );
661 else ApplyTransformation ( theResult, Trsf );
662 }
663 shbinder = new TransferBRep_ShapeBinder (theResult);
664 }
665 }
666
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);
674 }
675 }
676
677 }
678 TP->Bind(NAUO, shbinder);
679 return shbinder;
680
681}
682//=======================================================================
683//function : TransferEntity
684//purpose :
685//=======================================================================
686
687Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(const Handle(StepShape_ShapeRepresentation)& sr,
688 const Handle(Transfer_TransientProcess)& TP,
689 Standard_Boolean& isBound)
690{
691 Handle(TransferBRep_ShapeBinder) shbinder;
692 if(!Recognize(sr))
693 return 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();
699 #ifdef TRANSLOG
700 if (TP->TraceLevel() > 2)
701 sout<<" -- Actor : case ShapeRepr. NbItems="<<nb<<endl;
702 #endif
703
704 // Compute unit convertion factors and geometric Accuracy
705 Handle(StepRepr_Representation) oldSRContext = mySRContext; //:S4136
706 PrepareUnits(sr,TP);
707
708 BRep_Builder B;
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 );
714
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;
720 #ifdef DEB
721 Standard_Integer NMSSRItemsLen = sr->Items()->Length();
722 cout << "NMSSR with " << NMSSRItemsLen << " items detected" << endl;
723 #endif
724 }
725 // Special processing for I-DEAS STP case (ssv; 15.11.2010)
726 else {
727 Standard_Integer isIDeasMode = Interface_Static::IVal("read.step.ideas");
728 if (isNMMode && myNMTool.IsIDEASCase() && isIDeasMode) {
729 isManifold = Standard_False;
730 #ifdef DEB
731 cout << "I-DEAS post processing for non-manifold topology ENABLED" << endl;
732 #endif
733 }
734 #ifdef DEB
735 else if ( myNMTool.IsIDEASCase() )
736 cout << "I-DEAS post processing for non-manifold topology DISABLED" << endl;
737 #endif
738 }
739 myNMTool.CleanUp();
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)
743
744 for (i = 1; i <= nb && PS.More(); i ++,PS.Next()) {
745 //for (i = 1; i <= nb ; i ++) {
746 #ifdef TRANSLOG
747 if (TP->TraceLevel() > 2)
748 sout<<" -- Actor, shape_representation.item n0. "<<i<<endl;
749 #endif
750 Handle(StepRepr_RepresentationItem) anitem = sr->ItemsValue(i);
751 Handle(Transfer_Binder) binder;
752 if (!TP->IsBound(anitem)) {
753 binder = TransferShape(anitem, TP, isManifold);
754 }
755 else {
756 isBound = Standard_True;
757 binder = TP->Find(anitem);
758 }
759 TopoDS_Shape theResult = TransferBRep::ShapeResult (binder);
760 if (!theResult.IsNull()) {
761 OneResult = theResult;
762 B.Add(comp, theResult);
763 nsh ++;
764 }
765 }
766
767 // [BEGIN] Proceed with non-manifold topology (ssv; 12.11.2010)
768 if (!isManifold) {
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);
776
777 BRep_Builder brepBuilder;
778
779 // [BEGIN] Try to close OPEN Shells in I-DEAS case (ssv; 17.11.2010)
780 if ( myNMTool.IsIDEASCase() ) {
781
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 // ==========================================================
787
788 TopTools_IndexedDataMapOfShapeListOfShape shellClosingsMap;
789 // Find possible closings for each shell
790 this->computeIDEASClosings(comp, shellClosingsMap);
791
792 // Make compound to store closed Shells
793 TopoDS_Compound compWithClosings;
794 brepBuilder.MakeCompound(compWithClosings);
795
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);
801 }
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);
808 }
809
810
811 comp = compWithClosings;
812
813 }
814 // [END] Try to close OPEN Shells in I-DEAS case (ssv; 17.11.2010)
815
816 // [BEGIN] Reconstruct Solids from Closed Shells (ssv; 15.11.2010)
817 TopoDS_Compound reconstComp;
818 brepBuilder.MakeCompound(reconstComp);
819
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);
828 }
829 else if (aSubShape.ShapeType() == TopAbs_SHELL)
830 brepBuilder.Add(reconstComp, aSubShape);
831 }
832
833 comp = reconstComp;
834 // [END] Reconstruct Solids from Closed Shells (ssv; 15.11.2010)
835 }
836
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);
843
844
845 #ifdef DEB
846 DumpWhatIs(comp);
847 #endif
848
849 return shbinder;
850
851}
852//=======================================================================
853//function : TransferEntity
854//purpose :
855//=======================================================================
856
857Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(const Handle(StepShape_ContextDependentShapeRepresentation)& CDSR,
858 const Handle(Transfer_TransientProcess)& TP)
859{
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;
865
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);
869
870 if ( SRRReversed )
871 TP->AddWarning ( SRR, "SRR reverses relation defined by NAUO; NAUO definition is taken" );
872
873 TopoDS_Shape theResult;
874
875 gp_Trsf Trsf;
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 );
883
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());
887#ifdef TRANSLOG
888 if (TP->TraceLevel() > 1)
889 sout<<" -- Actor : Ent.n0 "<<TP->Model()->Number(CDSR)<<" -> Sharing Ent.no"<<TP->Model()->Number(SDR)<<endl;
890#endif
891
892 binder = TP->Find ( SDR );
893 if ( binder.IsNull() ) binder = TransferEntity(SDR,TP);
894 theResult = TransferBRep::ShapeResult (binder);
895 break;
896 }
897 }*/
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);
904 //}
905
906 if ( ! theResult.IsNull() ) {
907 if ( iatrsf ) {
908 if ( SRRReversed ) ApplyTransformation ( theResult, Trsf.Inverted() );
909 else ApplyTransformation ( theResult, Trsf );
910 }
911 shbinder = new TransferBRep_ShapeBinder (theResult);
912 }
913 else shbinder.Nullify();
914 TP->Bind(CDSR, shbinder);
915 return shbinder;
916
917}
918//=======================================================================
919//function : TransferEntity
920//purpose :
921//=======================================================================
922
923Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(const Handle(StepRepr_ShapeRepresentationRelationship)& und,
924 const Handle(Transfer_TransientProcess)& TP,
925 const Standard_Integer nbrep)
926{
927 // REPRESENTATION_RELATIONSHIP et la famille
928 Handle(TransferBRep_ShapeBinder) shbinder;
929
930 if (und.IsNull()) return shbinder;
931
932 // On prend son contenu : Rep1 ou Rep2 , that is the question
933 // on prend les 2. Mais quoi faire des axes
934
935 TopoDS_Compound Cund;
936 TopoDS_Shape OneResult;
937 BRep_Builder B;
938 B.MakeCompound (Cund);
939 Standard_Integer nsh = 0;
940
941 gp_Trsf Trsf;
942 Standard_Boolean iatrsf = ComputeSRRWT ( und, TP, Trsf );
943
944 // Transfert : que faut-il prendre au juste ?
945
946 for (Standard_Integer i = 1; i <= 2; i ++) {
947 if(nbrep && nbrep != i)
948 continue;
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);
961 nsh ++;
962 }
963 }
964
965 // La Transformation : selon les cas
966
967 // Appliquer la transformation
968
969 if (iatrsf) {
970 if (nsh == 1) ApplyTransformation ( OneResult, Trsf );
971 else if (nsh > 1) ApplyTransformation ( Cund, Trsf );
972 }
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);
977 return shbinder;
978
979}
980
981//=======================================================================
982//function : OldWay
983//purpose :
984//=======================================================================
985//=======================================================================
986//function : IsNeedRepresentation
987//purpose :
988//=======================================================================
989
990static Standard_Boolean IsNeedRepresentation(const Handle(StepRepr_ShapeAspect)& sa,
991 const Handle(StepRepr_Representation)&repA ,
992 const Handle(Transfer_TransientProcess)& TP)
993{
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() );
1012 }
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;
1019 }
1020 if ( i > repA->NbItems() ) IsSDRaspect=Standard_False;
1021 }
1022 }
1023 return IsSDRaspect;
1024}
1025//=======================================================================
1026//function : OldWay
1027//purpose :
1028//=======================================================================
1029
1030Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::OldWay(const Handle(Standard_Transient)& start,
1031 const Handle(Transfer_TransientProcess)& TP)
1032{
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();
1038
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))
1047 return shbinder;
1048 }
1049 }
1050
1051#ifdef TRANSLOG
1052 if (TP->TraceLevel() > 2)
1053 sout<<" -- Actor : case shape_definition_representation."<<endl;
1054#endif
1055 Handle(Transfer_Binder) binder = TP->Find(rep);
1056 if (binder.IsNull()) binder = TP->Transferring(rep);
1057//:j2 if (!binder.IsNull()) return binder;
1058
1059// SDR designant des CDSR (lien implicite, via la UsedRepr)
1060
1061 TopoDS_Compound Cund;
1062 TopoDS_Shape OneResult;
1063 BRep_Builder B;
1064 B.MakeCompound (Cund);
1065 Standard_Integer nsh = 0;
1066
1067 //:j2
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);
1075 nsh ++;
1076 shbinder->SetResult (theResult);
1077 }
1078 }
1079
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;
1092#ifdef TRANSLOG
1093 if (TP->TraceLevel() > 1)
1094 sout<<" -- Actor : Ent.n0 "<<TP->Model()->Number(start)<<" -> Shared Ent.no"<<TP->Model()->Number(anitem)<<endl;
1095#endif
1096
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
1104 }
1105 }
1106
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)
1111 return shbinder;
1112}
1113
1114//=======================================================================
1115//function : TransferEntity
1116//purpose :
1117//=======================================================================
1118
1119Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(const Handle(StepGeom_GeometricRepresentationItem)& start,
1120 const Handle(Transfer_TransientProcess)& TP,
1121 const Standard_Boolean isManifold)
1122{
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();
1129#ifdef TRANSLOG
1130 OSD_Timer chrono;
1131 if (TP->TraceLevel() > 2)
1132 sout << "Begin transfer STEP -> CASCADE, Type "
1133 << start->DynamicType()->Name() << endl;
1134 chrono.Start();
1135#endif
1136
1137 //:S4136
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" );
1143 ResetUnits();
1144 }
1145 else PrepareUnits ( context, TP );
1146 }
1147 myShapeBuilder.SetPrecision(myPrecision);
1148 myShapeBuilder.SetMaxTol(myMaxTol);
1149 try {
1150 OCC_CATCH_SIGNALS
1151 if (start->IsKind(STANDARD_TYPE(StepShape_FacetedBrep))) {
1152 myShapeBuilder.Init(GetCasted(StepShape_FacetedBrep, start), TP);
1153 found = Standard_True;
1154 }
1155 else if (start->IsKind(STANDARD_TYPE(StepShape_BrepWithVoids))) {
1156 myShapeBuilder.Init(GetCasted(StepShape_BrepWithVoids, start), TP);
1157 found = Standard_True;
1158 }
1159 else if (start->IsKind(STANDARD_TYPE(StepShape_ManifoldSolidBrep))) {
1160 myShapeBuilder.Init(GetCasted(StepShape_ManifoldSolidBrep, start), TP);
1161 found = Standard_True;
1162 }
1163 else if (start->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel))) {
1164 myShapeBuilder.Init(GetCasted(StepShape_ShellBasedSurfaceModel, start), TP, myNMTool);
1165 found = Standard_True;
1166 }
1167 else if (start->IsKind(STANDARD_TYPE(StepShape_FacetedBrepAndBrepWithVoids))) {
1168 myShapeBuilder.Init(GetCasted(StepShape_FacetedBrepAndBrepWithVoids, start), TP);
1169 found = Standard_True;
1170 }
1171 else if (start->IsKind(STANDARD_TYPE(StepShape_GeometricSet))) {
1172 myShapeBuilder.Init(GetCasted(StepShape_GeometricSet, start), TP);
1173 found = Standard_True;
1174 }
1175 else if (start->IsKind(STANDARD_TYPE(StepShape_EdgeBasedWireframeModel))) {
1176 myShapeBuilder.Init(GetCasted(StepShape_EdgeBasedWireframeModel, start), TP);
1177 found = Standard_True;
1178 }
1179 else if (start->IsKind(STANDARD_TYPE(StepShape_FaceBasedSurfaceModel))) {
1180 myShapeBuilder.Init(GetCasted(StepShape_FaceBasedSurfaceModel, start), TP);
1181 found = Standard_True;
1182 }
1183}
1184 catch(Standard_Failure) {
1185 TP->AddFail(start,"Exeption is raised. Entity was not translated.");
1186 TP->Bind(start, shbinder);
1187 return shbinder;
1188 }
1189
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)
1193 if (isManifold) {
1194 Handle(Standard_Transient) info;
1195 mappedShape =
1196 XSAlgo::AlgoContainer()->ProcessShape(mappedShape, myPrecision, myMaxTol,
1197 "read.step.resource.name",
1198 "read.step.sequence", info);
1199 XSAlgo::AlgoContainer()->MergeTransferInfo(TP, info, nbTPitems);
1200 }
1201 }
1202 found = !mappedShape.IsNull();
1203 if (found && shbinder.IsNull()) shbinder = new TransferBRep_ShapeBinder (mappedShape);
1204#ifdef TRANSLOG
1205 chrono.Stop();
1206 if (TP->TraceLevel() > 2)
1207 sout<<"End transfer STEP -> CASCADE :" << (found ? "OK" : " : no result")<<endl;
1208 if (TP->TraceLevel() > 2)
1209 chrono.Show();
1210#endif
1211 if ( oldSRContext.IsNull() && ! mySRContext.IsNull() ) //:S4136
1212 PrepareUnits ( oldSRContext, TP );
1213 TP->Bind(start, shbinder);
1214 return shbinder;
1215}
1216
1217
1218//=======================================================================
1219//function : TransferEntity
1220//purpose :
1221//=======================================================================
1222
1223Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(const Handle(StepRepr_MappedItem)& mapit,
1224 const Handle(Transfer_TransientProcess)& TP)
1225{
1226 Handle(TransferBRep_ShapeBinder) shbinder;
1227
1228 // --------------------------------------------------------------
1229 // On se trouve ici dans un contexte " d'assemblage geometrique "
1230 // - MappedItem
1231 // --------------------------------------------------------------
1232
1233 //:S4136: abv 20 Apr 99: as1ug.stp: MAPPED_ITEM transformation computed
1234 // taking into account units of origin and target SHAPE_REPRESENTATIONs
1235
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");
1245 else {
1246 TopoDS_Shape mappedShape = shbinder->Result();
1247 if ( ! mappedShape.IsNull() ) {
1248
1249 // Positionnement : 2 formules
1250 // 1/ Ax2 dans Source et comme Target : passage de Source a Target
1251 // 2/ CartesianOperator3d comme Target : on applique
1252
1253 gp_Trsf Trsf;
1254 Standard_Boolean ok = Standard_False;
1255
1256 Handle(StepGeom_CartesianTransformationOperator3d) CartOp =
1257 Handle(StepGeom_CartesianTransformationOperator3d)::DownCast(mapit->MappingTarget());
1258 if ( ! CartOp.IsNull() ) {
1259 ok = StepToGeom_MakeTransformation3d::Convert( CartOp, Trsf );
1260 }
1261 else {
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() ) {
1267 ok = Standard_True;
1268 Handle(StepRepr_Representation) rep = mySRContext; // NOTE: copy of handle !
1269 ComputeTransformation ( Origin, Target, maprep, rep, TP, Trsf );
1270 ok = Standard_True;
1271 }
1272 }
1273
1274 if ( ok ) ApplyTransformation ( mappedShape, Trsf );
1275 else TP->AddWarning (mapit,"Mapped Item, case not recognized, location ignored");
1276
1277 shbinder = new TransferBRep_ShapeBinder (mappedShape);
1278 }
1279 }
1280 TP->Bind(mapit, shbinder);
1281 return shbinder;
1282}
1283//=======================================================================
1284//function : TransferEntity
1285//purpose :
1286//=======================================================================
1287
1288Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(const Handle(StepShape_FaceSurface)& fs,
1289 const Handle(Transfer_TransientProcess)& TP)
1290{
1291
1292 // Cas bien utile meme si non reconnu explicitement
1293 Handle(TransferBRep_ShapeBinder) sb;
1294 Standard_Integer nbTPitems = TP->NbMapped();
1295 try {
1296 OCC_CATCH_SIGNALS
1297
1298 StepToTopoDS_Tool myTool;
1299 StepToTopoDS_DataMapOfTRI aMap;
1300
1301 myTool.Init(aMap, TP);
1302 StepToTopoDS_TranslateFace myTF;
1303 myTF.SetPrecision(myPrecision);
1304 myTF.SetMaxTol(myMaxTol);
1305
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" );
1314 ResetUnits();
1315 }
1316 else PrepareUnits ( context, TP );
1317 }
1318
1319 // Apply ShapeFix
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();
1324
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 );
1330 if ( shape != S )
1331 sb->SetResult ( shape );
1332
1333 XSAlgo::AlgoContainer()->MergeTransferInfo(TP, info, nbTPitems);
1334 }
1335
1336
1337 if ( oldSRContext.IsNull() && ! mySRContext.IsNull() ) //:S4136
1338 PrepareUnits ( oldSRContext, TP );
1339 TP->Bind(fs, sb);
1340 return sb; // TP->Find (start);
1341}
1342 catch(Standard_Failure)
1343 {
1344 TP->AddFail(fs,"Exeption is raised. Entity was not translated.");
1345 sb.Nullify();
1346 TP->Bind(fs, sb);
1347 return sb;
1348 }
1349}
1350//=======================================================================
1351//function : TransferShape
1352//purpose :
1353//=======================================================================
1354
1355Handle(Transfer_Binder) STEPControl_ActorRead::TransferShape(const Handle(Standard_Transient)& start,
1356 const Handle(Transfer_TransientProcess)& TP,
1357 const Standard_Boolean isManifold)
1358{
1359 if (start.IsNull()) return NullResult();
1360 XSAlgo::AlgoContainer()->PrepareForTransfer();
1361
1362// myContext.SetModel ( Handle(StepData_StepModel)::DownCast ( TP->Model() ) ); // for asking IsAP203?
1363
1364 Handle(Message_Messenger) sout = TP->Messenger();
1365#ifdef TRANSLOG
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;
1370#endif
1371
1372 Handle(TransferBRep_ShapeBinder) shbinder;
1373
1374
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);
1382 //skl
1383
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);
1388 }
1389
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);
1395 }
1396 //end skl
1397
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);
1403 }
1404
1405 // --------------------------------------------------------------
1406 // On se trouve ici aussi dans un contexte " d'assemblage geometrique "
1407 // - ShapeRepresentationRelationship + Transformation ou non
1408 // --------------------------------------------------------------
1409
1410 else if (start->IsKind(STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation))) {
1411 DeclareAndCast(StepShape_ContextDependentShapeRepresentation,CDSR,start);
1412 shbinder = TransferEntity(CDSR,TP);
1413 }
1414
1415 else if (start->IsKind (STANDARD_TYPE(StepRepr_ShapeRepresentationRelationship)) ) {
1416 // REPRESENTATION_RELATIONSHIP et la famille
1417
1418 DeclareAndCast(StepRepr_ShapeRepresentationRelationship,und,start);
1419 shbinder = TransferEntity(und,TP);
1420 }
1421
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);
1427 }
1428 else if (start->IsKind(STANDARD_TYPE(StepRepr_MappedItem))) {
1429 DeclareAndCast(StepRepr_MappedItem,mapit,start);
1430 shbinder= TransferEntity(mapit,TP);
1431 }
1432 else if (start->IsKind(STANDARD_TYPE(StepShape_FaceSurface))) {
1433 DeclareAndCast(StepShape_FaceSurface,fs,start);
1434 shbinder = TransferEntity(fs,TP);
1435 }
1436
1437// if (!shbinder.IsNull()) TP->Bind(start,binder);
1438
1439 return shbinder;
1440}
1441// ============================================================================
1442// Method : STEPControl_ActorRead::PrepareUnits
1443// Purpose : Set the unit conversion factors
1444// ============================================================================
1445
1446void STEPControl_ActorRead::PrepareUnits(const Handle(StepRepr_Representation)& rep,
1447 const Handle(Transfer_TransientProcess)& TP)
1448{
1449 mySRContext = rep;
1450
1451 Standard_Integer stat1, stat2 = 0; // sera alimente par STEPControl_Unit
1452// DeclareAndCast(StepShape_ShapeRepresentation,sr,start);
1453 if (rep.IsNull()) {
1454// TP->AddWarning(sr,"Not a ShapeRepresentation, default unit taken");
1455 ResetUnits();
1456 return;
1457 }
1458
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");
1463 ResetUnits();
1464 return;
1465 }
1466
1467 // --------------------------------------------------
1468 // Complex ENTITY : GeometricRepresentationContext &&
1469 // GlobalUnitAssignedContext
1470 // --------------------------------------------------
1471
1472 STEPConstruct_UnitContext myUnit;
1473 Handle(StepRepr_GlobalUnitAssignedContext) theGUAC;
1474 Handle(StepRepr_GlobalUncertaintyAssignedContext) aTol;
1475
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");
1480 }
1481
1482 // ----------------------------------------------------
1483 // Complex ENTITY : GeometricRepresentationContext &&
1484 // GlobalUnitAssignedContext &&
1485 // GlobalUncertaintyAssignedContext
1486 // ----------------------------------------------------
1487
1488 if (theRepCont->IsKind(STANDARD_TYPE(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx))) {
1489 DeclareAndCast(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx,
1490 theGRCAGAUC,theRepCont);
1491 theGUAC = theGRCAGAUC->GlobalUnitAssignedContext();
1492 aTol = theGRCAGAUC->GlobalUncertaintyAssignedContext();
1493 }
1494
1495
1496 // ----------------------------------------------------
1497 // Decoding and Setting the Values
1498 // ----------------------------------------------------
1499
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(),
1506 angleFactor,
1507 myUnit.SolidAngleFactor());
1508 if (stat1 != 0) TP->AddWarning (theRepCont,myUnit.StatusMessage(stat1));
1509 }
1510
1511 if (!aTol.IsNull()) {
1512 stat2 = myUnit.ComputeTolerance (aTol);
1513 if (stat2 != 0) TP->AddWarning (theRepCont,myUnit.StatusMessage(stat2));
1514 }
1515
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();
1521 else {
1522 TP->AddWarning(theRepCont,"No Length Uncertainty, value of read.precision.val is taken");
1523 myPrecision = Interface_Static::RVal("read.precision.val");
1524 }
1525 myMaxTol = Max ( myPrecision, Interface_Static::RVal("read.maxprecision.val") );
1526 // Assign uncertainty
1527// Interface_Static::SetRVal("lastpreci",UpdatedValue);
1528#ifdef TRANSLOG
1529 if (TP->TraceLevel() > 1)
1530 TP->Messenger() <<" Cc1ToTopoDS : Length Unit = "<<myUnit.LengthFactor()<<" Tolerance CASCADE = "<<myPrecision<<endl;
1531#endif
1532}
1533
1534//=======================================================================
1535//function : ResetUnits
1536//purpose :
1537//=======================================================================
1538
1539void STEPControl_ActorRead::ResetUnits ()
1540{
1541 UnitsMethods::InitializeFactors ( 1, 1, 1 );
1542 myPrecision = Interface_Static::RVal("read.precision.val");
1543 myMaxTol = Max ( myPrecision, Interface_Static::RVal("read.maxprecision.val") );
1544}
1545
1546//=======================================================================
1547//function : ComputeTransformation
1548//purpose :
1549//=======================================================================
1550
1551//:S4136 abv 20 Apr 99: as1ug.stp: compute transformation taking units into account
1552Standard_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,
1557 gp_Trsf &Trsf)
1558{
1559 Trsf = gp_Trsf(); // reinit
1560 if ( Origin.IsNull() || Target.IsNull() ) return Standard_False;
1561
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;
1570 }
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;
1574 }
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" );
1579 }
1580 else {
1581 TP->AddWarning ( ( code1 == 1 ? trg : org ),
1582 "Axis placement used by SRRWT does not belong to corresponding representation" );
1583 }
1584 }
1585
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);
d2a98d71 1595
7fd59977 1596 gp_Ax3 ax3Orig(theOrig->Ax2());
1597 gp_Ax3 ax3Targ(theTarg->Ax2());
d2a98d71
G
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
7fd59977 1600 // ne pas se tromper de sens !
d2a98d71
G
1601
1602
1603 gp_Trsf aTrsf2;
1604 gp_Ax3 anAxis(gp_Pnt(0.,0.,0.), gp::DZ(), gp::DX());;
1605 aTrsf2.SetTransformation(anAxis,ax3Orig);
1606 gp_Trsf aTrsf3;
1607 aTrsf3.SetTransformation(ax3Targ,anAxis);
1608
1609 Trsf = aTrsf3 * aTrsf2;
1610
7fd59977 1611 return Trsf.Form() != gp_Identity;
1612}
1613
1614//=======================================================================
1615//function : ReadSRRWT
1616//purpose :
1617//=======================================================================
1618
1619//:j2 abv 22 Oct 98: auxiliary function: reading transformation from SRRWT
1620Standard_Boolean STEPControl_ActorRead::ComputeSRRWT (const Handle(StepRepr_RepresentationRelationship) &SRR,
1621 const Handle(Transfer_TransientProcess) &TP,
1622 gp_Trsf &Trsf)
1623{
1624 Trsf = gp_Trsf(); // init
1625
1626 DeclareAndCast(StepRepr_ShapeRepresentationRelationshipWithTransformation,srwt,SRR);
1627 if ( srwt.IsNull() ) return Standard_False;
1628
1629 StepRepr_Transformation SelectTrans = srwt->TransformationOperator();
1630
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;
1641 }
1642
1643 // item-defined transformation
1644 Handle(StepRepr_ItemDefinedTransformation) ItemDef =
1645 SelectTrans.ItemDefinedTransformation();
1646 if ( ItemDef.IsNull() ) return Standard_False;
1647
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);
1654}
1655
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//=======================================================================
1661
1662TopoDS_Shell STEPControl_ActorRead::closeIDEASShell(const TopoDS_Shell& shell,
1663 const TopTools_ListOfShape& closingShells) {
1664
1665 // Make Shell to provide closeness adjustments
1666 TopoDS_Shell result;
1667 BRep_Builder brepBuilder;
1668 brepBuilder.MakeShell(result);
1669
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);
1675 }
1676
1677 TopTools_ListIteratorOfListOfShape itL(closingShells);
1678 TopTools_ListOfShape closingFaces;
1679
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);
1684
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);
1690 }
1691 }
1692
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);
1698 else
1699 return shell; // Cannot close this shell, skip it so...
1700
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);
1711 else {
1712 #ifdef DEB
1713 cout << "Redundant closing face detected: REMOVED from shell";
1714 #endif
1715 }
1716 }
1717
1718 return result;
1719
1720}
1721
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//=======================================================================
1728
1729void STEPControl_ActorRead::computeIDEASClosings(const TopoDS_Compound& comp,
1730 TopTools_IndexedDataMapOfShapeListOfShape& shellClosingsMap) {
1731 TopExp_Explorer shellExpA(comp, TopAbs_SHELL);
1732
1733 for ( ; shellExpA.More(); shellExpA.Next() ) {
1734 TopoDS_Shape shellA = shellExpA.Current();
1735 TopExp_Explorer shellExpB(comp, TopAbs_SHELL);
1736 TopTools_ListOfShape closingShells;
1737
1738 for ( ; shellExpB.More(); shellExpB.Next() ) {
1739 TopoDS_Shape shellB = shellExpB.Current();
1740 if ( shellA.IsSame(shellB) )
1741 continue;
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);
1746 }
1747
1748 if ( !closingShells.IsEmpty() )
1749 shellClosingsMap.Add(shellA, closingShells);
1750 }
1751
1752}