0029029: Exception Raised with no Result during reading file 2033zsh1_1.stp
[occt.git] / src / STEPControl / STEPControl_ActorRead.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14//:k3 abv 25.11.98 rp1sd.stp
15//:n4 abv 11.02.99 S4132: recognition of GeometricSet (instead of GeometricCurveSet)
16// gka 05.04.99 S4136: eliminate parameter lastpreci
17//gka,abv 14.04.99 S4136: maintain unit context, precision and maxtolerance values
7fd59977 18
42cf5bc1 19#include <BRep_Builder.hxx>
20#include <BRepCheck_Shell.hxx>
21#include <BRepCheck_Status.hxx>
22#include <Geom_Axis2Placement.hxx>
23#include <gp_Ax3.hxx>
24#include <gp_Trsf.hxx>
25#include <HeaderSection_FileName.hxx>
26#include <Interface_EntityIterator.hxx>
27#include <Interface_Graph.hxx>
28#include <Interface_InterfaceModel.hxx>
29#include <Interface_Macros.hxx>
30#include <Interface_Static.hxx>
31#include <Message_Messenger.hxx>
32#include <Message_ProgressSentry.hxx>
33#include <OSD_Timer.hxx>
34#include <Precision.hxx>
35#include <Standard_ErrorHandler.hxx>
36#include <Standard_Failure.hxx>
37#include <Standard_Transient.hxx>
38#include <Standard_Type.hxx>
39#include <StepBasic_ProductDefinition.hxx>
7fd59977 40#include <StepBasic_ProductRelatedProductCategory.hxx>
42cf5bc1 41#include <STEPConstruct_Assembly.hxx>
42#include <STEPConstruct_UnitContext.hxx>
43#include <STEPControl_ActorRead.hxx>
44#include <StepData_StepModel.hxx>
45#include <StepDimTol_DatumFeature.hxx>
46#include <StepDimTol_GeometricTolerance.hxx>
47#include <StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol.hxx>
48#include <StepGeom_Axis2Placement3d.hxx>
49#include <StepGeom_CartesianTransformationOperator3d.hxx>
2bc6f715 50#include <StepGeom_Direction.hxx>
7fd59977 51#include <StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext.hxx>
42cf5bc1 52#include <StepGeom_GeometricRepresentationItem.hxx>
7fd59977 53#include <StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx.hxx>
42cf5bc1 54#include <StepRepr_GlobalUncertaintyAssignedContext.hxx>
55#include <StepRepr_GlobalUnitAssignedContext.hxx>
56#include <StepRepr_HArray1OfRepresentationItem.hxx>
57#include <StepRepr_HSequenceOfRepresentationItem.hxx>
7fd59977 58#include <StepRepr_ItemDefinedTransformation.hxx>
42cf5bc1 59#include <StepRepr_MappedItem.hxx>
7fd59977 60#include <StepRepr_NextAssemblyUsageOccurrence.hxx>
42cf5bc1 61#include <StepRepr_ProductDefinitionShape.hxx>
62#include <StepRepr_PropertyDefinition.hxx>
63#include <StepRepr_Representation.hxx>
64#include <StepRepr_RepresentationContext.hxx>
65#include <StepRepr_RepresentationMap.hxx>
66#include <StepRepr_RepresentationRelationship.hxx>
7fd59977 67#include <StepRepr_ShapeAspect.hxx>
42cf5bc1 68#include <StepRepr_ShapeRepresentationRelationship.hxx>
69#include <StepRepr_ShapeRepresentationRelationshipWithTransformation.hxx>
70#include <StepRepr_Transformation.hxx>
71#include <StepShape_AdvancedBrepShapeRepresentation.hxx>
72#include <StepShape_BrepWithVoids.hxx>
73#include <StepShape_ContextDependentShapeRepresentation.hxx>
7fd59977 74#include <StepShape_EdgeBasedWireframeModel.hxx>
42cf5bc1 75#include <StepShape_EdgeBasedWireframeShapeRepresentation.hxx>
7fd59977 76#include <StepShape_FaceBasedSurfaceModel.hxx>
42cf5bc1 77#include <StepShape_FaceSurface.hxx>
78#include <StepShape_FacetedBrep.hxx>
79#include <StepShape_FacetedBrepAndBrepWithVoids.hxx>
7fd59977 80#include <StepShape_FacetedBrepShapeRepresentation.hxx>
7fd59977 81#include <StepShape_GeometricallyBoundedSurfaceShapeRepresentation.hxx>
82#include <StepShape_GeometricallyBoundedWireframeShapeRepresentation.hxx>
42cf5bc1 83#include <StepShape_GeometricSet.hxx>
84#include <StepShape_ManifoldSolidBrep.hxx>
85#include <StepShape_ManifoldSurfaceShapeRepresentation.hxx>
7fd59977 86#include <StepShape_NonManifoldSurfaceShapeRepresentation.hxx>
42cf5bc1 87#include <StepShape_ShapeDefinitionRepresentation.hxx>
88#include <StepShape_ShapeRepresentation.hxx>
89#include <StepShape_ShellBasedSurfaceModel.hxx>
caaeed1b 90#include <StepToGeom.hxx>
42cf5bc1 91#include <StepToTopoDS_Builder.hxx>
92#include <StepToTopoDS_DataMapOfTRI.hxx>
93#include <StepToTopoDS_MakeTransformed.hxx>
94#include <StepToTopoDS_Tool.hxx>
95#include <StepToTopoDS_TranslateFace.hxx>
96#include <TColStd_HSequenceOfTransient.hxx>
97#include <TopExp_Explorer.hxx>
7fd59977 98#include <TopoDS.hxx>
42cf5bc1 99#include <TopoDS_Compound.hxx>
7fd59977 100#include <TopoDS_Face.hxx>
42cf5bc1 101#include <TopoDS_Iterator.hxx>
102#include <TopoDS_Shape.hxx>
103#include <TopoDS_Shell.hxx>
104#include <TopoDS_Solid.hxx>
105#include <TopTools_ListIteratorOfListOfShape.hxx>
106#include <TopTools_ListOfShape.hxx>
107#include <TopTools_MapOfShape.hxx>
108#include <Transfer_Binder.hxx>
109#include <Transfer_TransientProcess.hxx>
110#include <TransferBRep.hxx>
111#include <TransferBRep_ShapeBinder.hxx>
112#include <UnitsMethods.hxx>
113#include <XSAlgo.hxx>
114#include <XSAlgo_AlgoContainer.hxx>
7fd59977 115
92efcf78 116IMPLEMENT_STANDARD_RTTIEXT(STEPControl_ActorRead,Transfer_ActorOfTransientProcess)
117
42cf5bc1 118// #include <Interface_InterfaceModel.hxx> // pour mise au point
119// MappedItem :
120// FaceSurface :
121// Unites :
122//#include <StepBasic_UncertaintyMeasureWithUnit.hxx>
123// Representation Relationship & cie
124// For non-manifold topology processing (ssv; 12.11.2010)
7fd59977 125#define TRANSLOG
126
127// ============================================================================
128// Function: DumpWhatIs
0797d9d3 129// Purpose: Use it in debug mode to dump your shapes
7fd59977 130// ============================================================================
131
0797d9d3 132#ifdef OCCT_DEBUG
7fd59977 133static void DumpWhatIs(const TopoDS_Shape& S) {
134
135 TopTools_MapOfShape aMapOfShape;
136 aMapOfShape.Add(S);
137 TopTools_ListOfShape aListOfShape;
138 aListOfShape.Append(S);
139 TopTools_ListIteratorOfListOfShape itL(aListOfShape);
140 Standard_Integer nbSolids = 0,
141 nbShells = 0,
142 nbOpenShells = 0,
143 nbFaces = 0,
144 nbWires = 0,
145 nbEdges = 0,
bd05fabf
S
146 nbVertexes = 0,
147 nbCompounds = 0;
148
149 if (S.ShapeType() == TopAbs_COMPOUND)
150 nbCompounds++;
7fd59977 151
152 for( ; itL.More(); itL.Next() ) {
153 TopoDS_Iterator it( itL.Value() );
154 for ( ; it.More(); it.Next() ) {
155 TopoDS_Shape aSubShape = it.Value();
156 if ( !aMapOfShape.Add(aSubShape) )
157 continue;
158 aListOfShape.Append(aSubShape);
bd05fabf
S
159 if (aSubShape.ShapeType() == TopAbs_COMPOUND)
160 nbCompounds++;
7fd59977 161 if (aSubShape.ShapeType() == TopAbs_SOLID)
162 nbSolids++;
163 if (aSubShape.ShapeType() == TopAbs_SHELL) {
164 if ( !aSubShape.Closed() )
165 nbOpenShells++;
166 nbShells++;
167 }
168 if (aSubShape.ShapeType() == TopAbs_FACE)
169 nbFaces++;
170 if (aSubShape.ShapeType() == TopAbs_WIRE)
171 nbWires++;
172 if (aSubShape.ShapeType() == TopAbs_EDGE)
173 nbEdges++;
174 if (aSubShape.ShapeType() == TopAbs_VERTEX)
175 nbVertexes++;
176 }
177 }
498ce76b 178
bd05fabf 179 cout << "//What is?// NB COMPOUNDS: " << nbCompounds << endl;
7fd59977 180 cout << "//What is?// NB SOLIDS: " << nbSolids << endl;
181 cout << "//What is?// NB SHELLS: " << nbShells << endl;
182 cout << "//What is?// OPEN SHELLS: " << nbOpenShells << endl;
183 cout << "//What is?// CLOSED SHELLS: " << nbShells - nbOpenShells << endl;
184 cout << "//What is?// NB FACES: " << nbFaces << endl;
185 cout << "//What is?// NB WIRES: " << nbWires << endl;
186 cout << "//What is?// NB EDGES: " << nbEdges << endl;
187 cout << "//What is?// NB VERTEXES: " << nbVertexes << endl;
7fd59977 188}
498ce76b 189#endif
7fd59977 190
bd05fabf
S
191namespace {
192 // Set global var to inform outer methods that current representation item is non-manifold.
193 // The better way is to pass this information via binder or via TopoDS_Shape itself, however,
194 // this is very specific info to do so...
195 Standard_Boolean NM_DETECTED = Standard_False;
a3f6f591 196}
bd05fabf 197
7fd59977 198// ============================================================================
199// Method : STEPControl_ActorRead::STEPControl_ActorRead ()
200// Purpose : Empty constructor
201// ============================================================================
202
203STEPControl_ActorRead::STEPControl_ActorRead() {}
204
205// ============================================================================
206// Method : STEPControl_ActorRead::Recognize
207// Purpose : tells if an entity is valid for transfer by this Actor
208// ============================================================================
209
210Standard_Boolean STEPControl_ActorRead::Recognize
211 (const Handle(Standard_Transient)& start)
212{
213 if (start.IsNull()) return Standard_False;
214
215 if (start->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition))) return Standard_True;
216
217 if (start->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence))) return Standard_True;
218
219 TCollection_AsciiString aProdMode = Interface_Static::CVal("read.step.product.mode");
220 if(!aProdMode.IsEqual("ON"))
221 if(start->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation))) return Standard_True;
222
223 DeclareAndCast(StepShape_ShapeRepresentation,sr,start);
224 if (!sr.IsNull()) {
225 Standard_Integer i,nb = sr->NbItems();
226 for (i = 1; i <= nb; i ++) {
227 if (Recognize (sr->ItemsValue(i)) ) return Standard_True;
228 }
229 return Standard_False;
230 }
231
232 if (start->IsKind(STANDARD_TYPE(StepShape_FacetedBrep))) return Standard_True;
233 if (start->IsKind(STANDARD_TYPE(StepShape_BrepWithVoids))) return Standard_True;
234 if (start->IsKind(STANDARD_TYPE(StepShape_ManifoldSolidBrep))) return Standard_True;
235 if (start->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel))) return Standard_True;
236 if (start->IsKind(STANDARD_TYPE(StepShape_FacetedBrepAndBrepWithVoids))) return Standard_True;
237 if (start->IsKind(STANDARD_TYPE(StepShape_GeometricSet))) return Standard_True;
238 if (start->IsKind(STANDARD_TYPE(StepRepr_MappedItem))) return Standard_True;
239 if (start->IsKind(STANDARD_TYPE(StepShape_FaceSurface))) return Standard_True;
240 if (start->IsKind(STANDARD_TYPE(StepShape_EdgeBasedWireframeModel))) return Standard_True;
241 if (start->IsKind(STANDARD_TYPE(StepShape_FaceBasedSurfaceModel))) return Standard_True;
242
243
244// REPRESENTATION_RELATIONSHIP et consorts : on regarde le contenu ...
245// On prend WithTransformation ou non ...
246
247 if (start->IsKind (STANDARD_TYPE(StepRepr_ShapeRepresentationRelationship))) {
248 DeclareAndCast(StepRepr_ShapeRepresentationRelationship,und,start);
249
250// On prend son contenu
251
252 if (Recognize(und->Rep1()) || Recognize(und->Rep2())) return Standard_True;
253 return Standard_False;
254 }
255
256 if (start->IsKind(STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation))) {
7fd59977 257 return Standard_True;
258 // on fait le pari que, si ce n est pas transferable tel quel,
259 // des CDSR implicitement references le sont ...
260 // Sinon cette entite n aurait pas grand sens ...
261 }
262
263 return Standard_False;
264}
265
266
267// ============================================================================
268// Method : STEPControl_ActorRead::Transfer
269// Purpose : recursive method that acces to the root entities and start the
270// mapping
271// ============================================================================
272
273Handle(Transfer_Binder) STEPControl_ActorRead::Transfer
274(const Handle(Standard_Transient)& start,
275 const Handle(Transfer_TransientProcess)& TP)
276{
277 // [BEGIN] Get version of preprocessor (to detect I-Deas case) (ssv; 23.11.2010)
278 Handle(StepData_StepModel) aStepModel = Handle(StepData_StepModel)::DownCast ( TP->Model() );
279 Interface_EntityIterator anEntIt = aStepModel->Header();
280 for ( anEntIt.Start(); anEntIt.More(); anEntIt.Next() ) {
281 DeclareAndCast( HeaderSection_FileName, aFileNameEntity, anEntIt.Value() );
282 if ( !aFileNameEntity.IsNull() ) {
283 Handle(TCollection_HAsciiString) aPPVersion = aFileNameEntity->PreprocessorVersion();
d6320495 284 if(aPPVersion.IsNull())
285 continue;
0797d9d3 286 #ifdef OCCT_DEBUG
7fd59977 287 cout << "Preprocessor version detected: " << aPPVersion->ToCString() << endl;
288 #endif
289 Standard_Integer anIDeasResult = aPPVersion->Search("I-DEAS");
290 if (anIDeasResult != -1) {
0797d9d3 291 #ifdef OCCT_DEBUG
7fd59977 292 cout << "Recognized as I-DEAS STP" << endl;
293 #endif
294 myNMTool.SetIDEASCase(Standard_True);
295 }
296 }
297 }
298 // [END] Get version of preprocessor (to detect I-Deas case) (ssv; 23.11.2010)
299 return TransferShape (start,TP);
300}
301
302
303// ============================================================================
304// auxiliary function : ApplyTransformation
305// ============================================================================
306static void ApplyTransformation (TopoDS_Shape& shape, const gp_Trsf &Trsf)
307{
308 if ( Trsf.Form() == gp_Identity ) return;
309 TopLoc_Location theLoc ( Trsf );
310 shape.Move (theLoc);
311}
312
313
314// ============================================================================
315// auxiliary function : FindContext
316// ============================================================================
317static Handle(StepRepr_Representation) FindContext (const Handle(Standard_Transient) &start,
318 const Handle(Transfer_TransientProcess) &TP,
319 const Standard_Integer level=10 )
320{
321 Handle(StepRepr_Representation) rep;
322 const Interface_Graph& graph = TP->Graph();
323 Interface_EntityIterator subs = graph.Sharings(start);
324 for (subs.Start(); subs.More() && rep.IsNull(); subs.Next()) {
325 rep = Handle(StepRepr_Representation)::DownCast(subs.Value());
326 if ( rep.IsNull() && level >0 ) rep = FindContext ( subs.Value(), TP, level-1 );
327 }
328 return rep;
329}
330
331//=======================================================================
332//function : FindShapeReprType
333//purpose : Returns integer corresponding to the type of the representation
334// as defined in read.step.shape.repr_level parameter
335//=======================================================================
336
337static Standard_Integer FindShapeReprType (const Handle(Standard_Transient) &start)
338{
339 if(start->IsKind(STANDARD_TYPE(StepShape_AdvancedBrepShapeRepresentation)))
340 return 2;
341 if(start->IsKind(STANDARD_TYPE(StepShape_ManifoldSurfaceShapeRepresentation)))
342 return 3;
343 if(start->IsKind(STANDARD_TYPE(StepShape_GeometricallyBoundedSurfaceShapeRepresentation)))
344 return 4;
345 if(start->IsKind(STANDARD_TYPE(StepShape_FacetedBrepShapeRepresentation)))
346 return 5;
347 if(start->IsKind(STANDARD_TYPE(StepShape_EdgeBasedWireframeShapeRepresentation)))
348 return 6;
349 if(start->IsKind(STANDARD_TYPE(StepShape_GeometricallyBoundedWireframeShapeRepresentation)))
350 return 7;
351 return 8;
352}
353
354//=======================================================================
355//function : getListSDR
356//purpose : Get SDRs assigned to ShapeAspect, which may potentially
357// correspond to hybrid models in AP203 before 1998
358//=======================================================================
359
360static void getListSDR(const Handle(StepRepr_ShapeAspect)& sa,
361 Handle(TColStd_HSequenceOfTransient)& listSDR,
362 const Handle(Transfer_TransientProcess)& TP)
363{
364 const Interface_Graph& graph = TP->Graph();
365
366 // check whether this ShapeAspect is used in G&DT, and if yes, ignore it
367 if(sa->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature))) return;
368 Interface_EntityIterator subs5 = graph.Sharings(sa);
369 for (subs5.Start(); subs5.More(); subs5.Next()) {
370 if(subs5.Value()->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
371 return;
372 }
373
374 // reiterate by referred entities and take all SDRs; note that SDRs that
375 // refer to sub-shapes of main SDR will be filtered out further during translation
376 subs5 = graph.Sharings(sa);
377 for (subs5.Start(); subs5.More() ; subs5.Next()) {
378 Handle(StepRepr_PropertyDefinition) propd =
379 Handle(StepRepr_PropertyDefinition)::DownCast(subs5.Value());
380 if(propd.IsNull()) continue;
381 Interface_EntityIterator subs6 = graph.Sharings(propd);
382 for (subs6.Start(); subs6.More() ; subs6.Next()) {
383 Handle(StepShape_ShapeDefinitionRepresentation) sdr =
384 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs6.Value());
385 if ( ! sdr.IsNull() )
386 listSDR->Append(sdr);
387 }
388 }
389}
390
391//=======================================================================
392//function : getSDR
393//purpose : Find all SDRs related to given PDS
394//=======================================================================
395
396static void getSDR(const Handle(StepRepr_ProductDefinitionShape)& PDS,
397 Handle(TColStd_HSequenceOfTransient)& listSDR,
bedd79c4 398 Handle(TColStd_HSequenceOfTransient)& listNAUO,
7fd59977 399 Handle(TColStd_HSequenceOfTransient)& listSDRAspect,
400 const Handle(Transfer_TransientProcess)& TP)
401{
402 // Flag indicating preferred shape representation type, to be chosen if
403 // several different representations are attached to the same shape
404 Standard_Integer delta = 100;
405 Standard_Integer ICS = Interface_Static::IVal("read.step.shape.repr");
406 Standard_Integer nbSDR0 = listSDR->Length();
407
408 // Iterate by entities referring PDS
409 const Interface_Graph& graph = TP->Graph();
410 Handle(StepShape_ShapeDefinitionRepresentation) NeedSDR;
411 Interface_EntityIterator subs4 = graph.Sharings(PDS);
412 for (subs4.Start(); subs4.More(); subs4.Next()) {
413
414 // Directly assigned SDR
415 Handle(StepShape_ShapeDefinitionRepresentation) sdr =
416 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs4.Value());
417 if ( ! sdr.IsNull() ) {
418 Handle(StepRepr_Representation) rep = sdr->UsedRepresentation();
419
420 if ( !rep.IsNull()) {
421 // if specific representation type is preferred, choose the
422 // representations of the closest type
423 if ( ICS == 1 ) // translate all SDRs
424 listSDR->Append(sdr);
425 else {
426 Standard_Integer iDiff = Abs ( FindShapeReprType(rep) - ICS );
427 // if more suitable representation is found, drop previous if any selected
428 if( iDiff < delta ) {
429 while ( listSDR->Length() > nbSDR0 )
430 listSDR->Remove(listSDR->Length());
431 delta = iDiff;
432 }
433 // take all representations of preferred or closest type
434 if ( iDiff <= delta )
435 listSDR->Append(sdr);
436 }
437 }
438 continue;
439 }
440
441 // SDRs assigned via ShapeAspect; may correspond to hybrid model in AP203 before 1998
442 Handle(StepRepr_ShapeAspect) sa =
443 Handle(StepRepr_ShapeAspect)::DownCast(subs4.Value());
444 if ( ! sa.IsNull() ) {
445 getListSDR(sa,listSDRAspect,TP);
446 continue;
447 }
bedd79c4 448
449 // NAUO is used to find sub-assemblies
450 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
451 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs4.Value());
452 if ( ! NAUO.IsNull() ) {
453 if ( PDS->Definition().ProductDefinition() == NAUO->RelatingProductDefinition() )
454 listNAUO->Append(NAUO);
455 continue;
456 }
7fd59977 457 }
458}
459
460
461//=======================================================================
462//function : TransferEntity
463//purpose :
464//=======================================================================
465 Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(const Handle(StepBasic_ProductDefinition)& PD,
466 const Handle(Transfer_TransientProcess)& TP)
467
468{
469 Handle(Message_Messenger) sout = TP->Messenger();
470 Handle(TransferBRep_ShapeBinder) shbinder;
471
472 TopoDS_Compound Cund;
473 TopoDS_Shape Result1;
474 BRep_Builder B;
475 B.MakeCompound (Cund);
476
477 // Find subcomponents of assembly (NAUO)
478 // and definitions of shape of the current product (SDR)
479 Handle(TColStd_HSequenceOfTransient) listSDR = new TColStd_HSequenceOfTransient;
480 Handle(TColStd_HSequenceOfTransient) listNAUO = new TColStd_HSequenceOfTransient;
481 Handle(TColStd_HSequenceOfTransient) listSDRAspect = new TColStd_HSequenceOfTransient;
482 const Interface_Graph& graph = TP->Graph();
483 Interface_EntityIterator subs3 = graph.Sharings(PD);
484 for (subs3.Start(); subs3.More() ; subs3.Next()) {
485 // PDS is used to find shape definitions attached to this product
486 Handle(StepRepr_ProductDefinitionShape) PDS =
487 Handle(StepRepr_ProductDefinitionShape)::DownCast(subs3.Value());
488 if ( ! PDS.IsNull() ) {
bedd79c4 489 getSDR(PDS,listSDR,listNAUO,listSDRAspect,TP);
7fd59977 490 continue;
491 }
492 // NAUO is used to find sub-assemblies
493 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
494 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs3.Value());
495 if ( ! NAUO.IsNull() ) {
496 if ( PD == NAUO->RelatingProductDefinition() )
497 listNAUO->Append(NAUO);
498 continue;
499 }
500 }
501
502 // Flag indicating whether SDRs associated with the product`s main SDR
503 // by SRRs (which correspond to hybrid model representation in AP203 since 1998)
504 // should be taken into account
505 Standard_Integer readSRR = Interface_Static::IVal("read.step.shape.relationship");
506
507 // Flag indicating whether SDRs associated with the product`s main SDR
508 // by SAs (which correspond to hybrid model representation in AP203 before 1998)
509 // should be taken into account
510 Standard_Integer readSA = Interface_Static::IVal("read.step.shape.aspect");
511 if ( ! readSA )
512 listSDRAspect->Clear();
513
514 // remember number of normal SDRs (not those found via ShapeAspect)
515 // and merge both lists in one
516 Standard_Integer nbNotAspect = listSDR->Length();
517 listSDR->Append(listSDRAspect);
518
519 // Flag indicating level of reading assemblies: only structure (3),
520 // structure with shapes of final parts (2), or everything, including shapes
521 // possibly attached directly to intermediate assemblies (1)
522 // Special mode (4) is used to translate shape attached to this product only,
523 // ignoring sub-assemblies if any
524 Standard_Integer readAssembly = Interface_Static::IVal("read.step.assembly.level");
525 if ( readAssembly ==3 || ( readAssembly ==2 && listNAUO->Length() >0 ) )
526 listSDR->Clear();
527 else if ( readAssembly == 4 )
528 listNAUO->Clear();
529
530 Standard_Integer nbEnt = listSDR->Length() + listNAUO->Length();
531 if ( nbEnt <=0 )
532 return shbinder;
533
534 // common progress indicator for translation of own shapes and sub-assemblies
535 Message_ProgressSentry PS ( TP->GetProgress(), "Part", 0, nbEnt, 1 );
536 Standard_Integer nbComponents=0, nbShapes=0;
537
538 // translate sub-assemblies
539 for ( Standard_Integer nbNauo =1; nbNauo <= listNAUO->Length() && PS.More(); nbNauo++, PS.Next()) {
540 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
541 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(listNAUO->Value(nbNauo));
542
543#ifdef TRANSLOG
544 if (TP->TraceLevel() > 1)
545 sout<<" -- Actor : Ent.n0 "<<TP->Model()->Number(PD)<<" -> Shared Ent.no"<<TP->Model()->Number(NAUO)<<endl;
546#endif
547 Handle(Transfer_Binder) binder;
548 if (!TP->IsBound(NAUO)) binder = TransferEntity(NAUO,TP);
549 else binder = TP->Find(NAUO);
550
551 TopoDS_Shape theResult = TransferBRep::ShapeResult (binder);
552 if (!theResult.IsNull()) {
553 Result1 = theResult;
bd05fabf
S
554 // [BEGIN] ssv: OCCT#22436: extra compound in NMSSR case
555 if (NM_DETECTED && Result1.ShapeType() == TopAbs_COMPOUND)
556 {
557 TopoDS_Iterator it(Result1);
558 for ( ; it.More(); it.Next() )
559 {
560 TopoDS_Shape aSubShape = it.Value();
561 B.Add(Cund, aSubShape);
562 }
563 }
564 else
565 B.Add(Cund, theResult);
566 // [END] ssv: OCCT#22436: extra compound in NMSSR case
7fd59977 567 nbComponents++;
568 }
569 }
570
571 // translate shapes assigned directly
572 for(Standard_Integer i=1; i <= listSDR->Length() && PS.More(); i++, PS.Next()) {
573 Handle(StepShape_ShapeDefinitionRepresentation) sdr =
574 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(listSDR->Value(i));
575 Handle(StepShape_ShapeRepresentation) rep = Handle(StepShape_ShapeRepresentation)::DownCast(sdr->UsedRepresentation());
576 if ( rep.IsNull() )
577 continue;
578
579 // translate SDR representation
580 Standard_Boolean isBound = Standard_True;
581 Handle(Transfer_Binder) binder = TP->Find(rep);
582 if (binder.IsNull())
583 binder = TransferEntity(rep,TP,isBound);
584
585 // if SDR is obtained from ShapeAspect and representation items have already been tramnslated,
586 // this means that that ShapeAspect is used to refer to sub-shape of the main shape
587 // (e.g. for validation properties), and we do not need to translate it actually;
588 // otherwise it is considered as part of hybrid representation in AP203 before 1998
589 if ( i > nbNotAspect && isBound)
590 continue;
591
592 // record shape resulting from translation
593 TopoDS_Shape theResult;
594 if ( ! binder.IsNull() ) {
595 theResult = TransferBRep::ShapeResult (binder);
596 if (!theResult.IsNull()) {
597 Result1 = theResult;
bd05fabf
S
598 // [BEGIN] ssv: OCCT#22436: extra compound in NMSSR case
599 if (NM_DETECTED && Result1.ShapeType() == TopAbs_COMPOUND)
600 {
601 TopoDS_Iterator it(Result1);
602 for ( ; it.More(); it.Next() )
603 {
604 TopoDS_Shape aSubShape = it.Value();
605 B.Add(Cund, aSubShape);
606 }
607 }
608 else
609 B.Add(Cund, theResult);
610 // [END] ssv: OCCT#22436: extra compound in NMSSR case
7fd59977 611 nbShapes++;
612 }
613 }
614
615 // translate possible shapes related by SRRs, which corresponds to
616 // way of writing hybrid models in AP203 since 1998, and AP209
617 // Note that both AP203 and AP209 allow main representation to be non-empty
618 if ( readSRR && /*theResult.IsNull() &&*/ i <= nbNotAspect) {
619 Interface_EntityIterator subs1 = graph.Sharings(rep);
620 Handle(Standard_Type) tSRR = STANDARD_TYPE(StepRepr_ShapeRepresentationRelationship);
621 for (subs1.Start(); subs1.More(); subs1.Next()) {
622 Handle(Standard_Transient) anitem = subs1.Value();
623 if ( anitem->DynamicType() != tSRR ) continue;
624 Handle(StepRepr_ShapeRepresentationRelationship) SRR =
625 Handle(StepRepr_ShapeRepresentationRelationship)::DownCast(anitem);
626 Standard_Integer nbrep = ( rep == SRR->Rep1() ? 2 : 1 );
627 binder = TransferEntity(SRR, TP, nbrep);
628 if ( ! binder.IsNull() ) {
629 theResult = TransferBRep::ShapeResult (binder);
630 Result1 = theResult;
631 B.Add(Cund, theResult);
632 nbShapes++;
633 }
634 }
635 }
636 }
637
638 // make a warning if both own shape and sub-assemblies are present
639 if ( nbShapes >0 && nbComponents > 0 )
640 TP->AddWarning ( PD, "Product has both sub-assemblies and directly assigned shape" );
641
642 // if only single shape is read, add it as it is; otherwise add compound
643 if( nbShapes == 1 && nbComponents == 0 )
644 shbinder = new TransferBRep_ShapeBinder (Result1);
645 else
646 shbinder = new TransferBRep_ShapeBinder (Cund);
647
648 //TP->Unbind( PD ); //:j3: unbind start (let it be bound by TransferProcess)
649 TP->Bind(PD, shbinder);
650 return shbinder;
651}
652
653//=======================================================================
654//function : TransferEntity
655//purpose :
656//=======================================================================
657
658Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(const Handle(StepRepr_NextAssemblyUsageOccurrence)& NAUO ,
659 const Handle(Transfer_TransientProcess)& TP)
660{
661 Handle(TransferBRep_ShapeBinder) shbinder;
662 Handle(StepBasic_ProductDefinition) PD;
663 const Interface_Graph& graph = TP->Graph();
664 gp_Trsf Trsf;
665 Standard_Boolean iatrsf=Standard_False, SRRReversed=Standard_False, IsDepend=Standard_False;
666 Handle(StepRepr_ShapeRepresentationRelationship) SRR;
667 Interface_EntityIterator subs1 = graph.Sharings(NAUO);
668 for (subs1.Start(); subs1.More(); subs1.Next()) {
669 Handle(StepRepr_ProductDefinitionShape) PDS =
670 Handle(StepRepr_ProductDefinitionShape)::DownCast(subs1.Value());
671 if(PDS.IsNull()) continue;
7fd59977 672 Interface_EntityIterator subs2 = graph.Sharings(PDS);
673 for (subs2.Start(); subs2.More(); subs2.Next()) {
674 Handle(StepShape_ContextDependentShapeRepresentation) CDSR =
675 Handle(StepShape_ContextDependentShapeRepresentation)::DownCast(subs2.Value());
676 if (CDSR.IsNull()) continue;
677 IsDepend=Standard_True;
678 Handle(StepRepr_RepresentationRelationship) RR = CDSR->RepresentationRelation();
679 if (RR.IsNull()) continue;
9bba178d 680 SRRReversed = STEPConstruct_Assembly::CheckSRRReversesNAUO ( graph, CDSR );
7fd59977 681 Handle(StepRepr_Representation) rep = ( SRRReversed ? RR->Rep2() : RR->Rep1() );
2c25cc04 682 if(rep.IsNull())
683 continue;
7fd59977 684 iatrsf = ComputeSRRWT ( RR, TP, Trsf );
685 // find real ProductDefinition used rep
686 Interface_EntityIterator subs3 = TP->Graph().Sharings(rep);
687 for (subs3.Start(); subs3.More(); subs3.Next()) {
688 if ( subs3.Value()->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation))) {
689 DeclareAndCast(StepShape_ShapeDefinitionRepresentation,SDR,subs3.Value());
690 Handle(StepRepr_ProductDefinitionShape) PDS1 =
691 Handle(StepRepr_ProductDefinitionShape)::DownCast(SDR->Definition().PropertyDefinition());
7fd59977 692 if(PDS1.IsNull()) continue;
693 Interface_EntityIterator subs4 = graph.Shareds(PDS1);
694 for (subs4.Start(); subs4.More(); subs4.Next()) {
695 Handle(StepBasic_ProductDefinition) PD1 =
696 Handle(StepBasic_ProductDefinition)::DownCast(subs4.Value());
697 if(PD1.IsNull()) continue;
698 PD=PD1;
699 }
700 }
701 else if(subs3.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeRepresentationRelationship))) {
702 SRR = Handle(StepRepr_ShapeRepresentationRelationship)::DownCast(subs3.Value());
703 }
704 }
705 }
706 }
707
708 Handle(Transfer_Binder) binder;
709 TopoDS_Shape theResult;
710 shbinder.Nullify();
711
712 if(IsDepend) {
713
714 if(!PD.IsNull()) {
715 binder = TP->Find(PD);
716 if ( binder.IsNull() ) binder = TransferEntity(PD,TP);
717 theResult = TransferBRep::ShapeResult(binder);
718 if (!theResult.IsNull()) {
719 if (iatrsf) {
720 if ( SRRReversed ) ApplyTransformation ( theResult, Trsf.Inverted() );
721 else ApplyTransformation ( theResult, Trsf );
722 }
723 shbinder = new TransferBRep_ShapeBinder (theResult);
724 }
725 }
726
727 if ( theResult.IsNull() && !SRR.IsNull() ) {
728 binder = TP->Find(SRR);
729 if ( binder.IsNull() ) {
730 binder = TransferEntity(SRR,TP);
731 theResult = TransferBRep::ShapeResult (binder);
732 if (!theResult.IsNull())
733 shbinder = new TransferBRep_ShapeBinder (theResult);
734 }
735 }
736
737 }
738 TP->Bind(NAUO, shbinder);
739 return shbinder;
740
741}
742//=======================================================================
743//function : TransferEntity
744//purpose :
745//=======================================================================
746
747Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(const Handle(StepShape_ShapeRepresentation)& sr,
748 const Handle(Transfer_TransientProcess)& TP,
749 Standard_Boolean& isBound)
750{
bd05fabf 751 NM_DETECTED = Standard_False;
7fd59977 752 Handle(TransferBRep_ShapeBinder) shbinder;
753 if(!Recognize(sr))
754 return shbinder;
755 isBound = Standard_False;
51740958 756 Standard_Integer nb = sr->NbItems();
7fd59977 757 // Used in XSAlgo::AlgoContainer()->ProcessShape (ssv; 13.11.2010)
758 Standard_Integer nbTPitems = TP->NbMapped();
759 Handle(Message_Messenger) sout = TP->Messenger();
760 #ifdef TRANSLOG
761 if (TP->TraceLevel() > 2)
762 sout<<" -- Actor : case ShapeRepr. NbItems="<<nb<<endl;
763 #endif
764
765 // Compute unit convertion factors and geometric Accuracy
766 Handle(StepRepr_Representation) oldSRContext = mySRContext; //:S4136
767 PrepareUnits(sr,TP);
768
769 BRep_Builder B;
770 TopoDS_Compound comp;
771 B.MakeCompound (comp);
772 TopoDS_Shape OneResult;
773 Standard_Integer nsh = 0;
774 Message_ProgressSentry PS ( TP->GetProgress(), "Sub-assembly", 0, nb, 1 );
775
776 // [BEGIN] Proceed with non-manifold topology (ssv; 12.11.2010)
dde68833 777 Standard_Boolean isNMMode = Interface_Static::IVal("read.step.nonmanifold") != 0;
7fd59977 778 Standard_Boolean isManifold = Standard_True;
779 if ( isNMMode && sr->IsKind(STANDARD_TYPE(StepShape_NonManifoldSurfaceShapeRepresentation)) ) {
780 isManifold = Standard_False;
bd05fabf 781 NM_DETECTED = Standard_True;
0797d9d3 782 #ifdef OCCT_DEBUG
7fd59977 783 Standard_Integer NMSSRItemsLen = sr->Items()->Length();
784 cout << "NMSSR with " << NMSSRItemsLen << " items detected" << endl;
785 #endif
786 }
787 // Special processing for I-DEAS STP case (ssv; 15.11.2010)
788 else {
789 Standard_Integer isIDeasMode = Interface_Static::IVal("read.step.ideas");
790 if (isNMMode && myNMTool.IsIDEASCase() && isIDeasMode) {
791 isManifold = Standard_False;
bd05fabf 792 NM_DETECTED = Standard_True;
0797d9d3 793 #ifdef OCCT_DEBUG
7fd59977 794 cout << "I-DEAS post processing for non-manifold topology ENABLED" << endl;
795 #endif
796 }
0797d9d3 797 #ifdef OCCT_DEBUG
7fd59977 798 else if ( myNMTool.IsIDEASCase() )
799 cout << "I-DEAS post processing for non-manifold topology DISABLED" << endl;
800 #endif
801 }
802 myNMTool.CleanUp();
803 // Don't use NM tool in manifold cases (ssv; 24.11.2010)
804 myNMTool.SetActive(!isManifold && isNMMode);
805 // [END] Proceed with non-manifold topology (ssv; 12.11.2010)
806
51740958 807 for (Standard_Integer i = 1; i <= nb && PS.More(); i ++,PS.Next()) {
7fd59977 808 //for (i = 1; i <= nb ; i ++) {
809 #ifdef TRANSLOG
810 if (TP->TraceLevel() > 2)
811 sout<<" -- Actor, shape_representation.item n0. "<<i<<endl;
812 #endif
813 Handle(StepRepr_RepresentationItem) anitem = sr->ItemsValue(i);
814 Handle(Transfer_Binder) binder;
815 if (!TP->IsBound(anitem)) {
816 binder = TransferShape(anitem, TP, isManifold);
817 }
818 else {
819 isBound = Standard_True;
820 binder = TP->Find(anitem);
821 }
822 TopoDS_Shape theResult = TransferBRep::ShapeResult (binder);
823 if (!theResult.IsNull()) {
824 OneResult = theResult;
825 B.Add(comp, theResult);
826 nsh ++;
827 }
828 }
2bc6f715 829
7fd59977 830 // [BEGIN] Proceed with non-manifold topology (ssv; 12.11.2010)
831 if (!isManifold) {
2bc6f715 832
7fd59977 833 Handle(Standard_Transient) info;
834 // IMPORTANT: any fixing on non-manifold topology must be done after the shape is transferred from STEP
835 TopoDS_Shape fixedResult =
b485ee79
KD
836 XSAlgo::AlgoContainer()->ProcessShape( comp, myPrecision, myMaxTol,
837 "read.step.resource.name",
838 "read.step.sequence", info,
2bc6f715 839 TP->GetProgress(), Standard_True);
7fd59977 840 XSAlgo::AlgoContainer()->MergeTransferInfo(TP, info, nbTPitems);
841
2bc6f715 842 if (fixedResult.ShapeType() == TopAbs_COMPOUND)
843 {
844 comp = TopoDS::Compound(fixedResult);
845 }
846 else
847 {
848 comp.Nullify();
849 B.MakeCompound(comp);
850 B.Add(comp, fixedResult);
851 }
852
7fd59977 853 BRep_Builder brepBuilder;
854
855 // [BEGIN] Try to close OPEN Shells in I-DEAS case (ssv; 17.11.2010)
856 if ( myNMTool.IsIDEASCase() ) {
857
858 // ==========================================================
859 // For each Shell (always OPEN in I-DEAS case) find all
860 // the possibilities to close it with adjacent non-manifold
861 // Shells which are stored separately in I-DEAS-like STP
862 // ==========================================================
863
864 TopTools_IndexedDataMapOfShapeListOfShape shellClosingsMap;
865 // Find possible closings for each shell
866 this->computeIDEASClosings(comp, shellClosingsMap);
867
868 // Make compound to store closed Shells
869 TopoDS_Compound compWithClosings;
870 brepBuilder.MakeCompound(compWithClosings);
51740958 871
7fd59977 872 // Attempt to close Shells one-by-one
873 for (Standard_Integer i = 1; i <= shellClosingsMap.Extent(); i++) {
874 TopoDS_Shell adjustedShell = this->closeIDEASShell( TopoDS::Shell( shellClosingsMap.FindKey(i) ),
875 shellClosingsMap.FindFromIndex(i) );
876 brepBuilder.Add(compWithClosings, adjustedShell);
877 }
878 // Put not suspected open Shells as they are (updated 23.11.2010)
879 TopExp_Explorer allShellsExp(comp, TopAbs_SHELL);
880 for ( ; allShellsExp.More(); allShellsExp.Next() ) {
881 TopoDS_Shape aCurrentShell = allShellsExp.Current();
882 if ( !myNMTool.IsPureNMShell(aCurrentShell) && !shellClosingsMap.Contains(aCurrentShell) )
883 brepBuilder.Add(compWithClosings, aCurrentShell);
884 }
63c71e2f 885 comp = compWithClosings;
7fd59977 886 }
887 // [END] Try to close OPEN Shells in I-DEAS case (ssv; 17.11.2010)
888
889 // [BEGIN] Reconstruct Solids from Closed Shells (ssv; 15.11.2010)
890 TopoDS_Compound reconstComp;
891 brepBuilder.MakeCompound(reconstComp);
2bc6f715 892 TopExp_Explorer exp(comp, TopAbs_SHELL);
893 for (; exp.More(); exp.Next())
894 {
895 TopoDS_Shape aSubShape = exp.Current();
896 if (aSubShape.ShapeType() == TopAbs_SHELL && aSubShape.Closed()) {
897 TopoDS_Solid nextSolid;
898 brepBuilder.MakeSolid(nextSolid);
899 brepBuilder.Add(nextSolid, aSubShape);
900 brepBuilder.Add(reconstComp, nextSolid);
901 }
902 else if (aSubShape.ShapeType() == TopAbs_SHELL)
903 brepBuilder.Add(reconstComp, aSubShape);
7fd59977 904 }
7fd59977 905 comp = reconstComp;
906 // [END] Reconstruct Solids from Closed Shells (ssv; 15.11.2010)
907 }
908
909 // Bind the resulting shape
910 if (nsh == 0) shbinder.Nullify();
911 else if (nsh == 1) shbinder = new TransferBRep_ShapeBinder (OneResult);
912 else shbinder = new TransferBRep_ShapeBinder (comp);
2bc6f715 913
7fd59977 914 PrepareUnits ( oldSRContext, TP ); //:S4136
915 TP->Bind(sr, shbinder);
916
917
0797d9d3 918 #ifdef OCCT_DEBUG
7fd59977 919 DumpWhatIs(comp);
920 #endif
921
922 return shbinder;
923
924}
925//=======================================================================
926//function : TransferEntity
927//purpose :
928//=======================================================================
929
930Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(const Handle(StepShape_ContextDependentShapeRepresentation)& CDSR,
931 const Handle(Transfer_TransientProcess)& TP)
932{
933 Handle(TransferBRep_ShapeBinder) shbinder;
934 //:j2: treat SRRs here in order to compare them with NAUO
935 Handle(StepRepr_ShapeRepresentationRelationship) SRR = CDSR->RepresentationRelation();
7fd59977 936 if ( SRR.IsNull() ) return shbinder;
937
9bba178d 938 Standard_Boolean SRRReversed = STEPConstruct_Assembly::CheckSRRReversesNAUO ( TP->Graph(), CDSR );
7fd59977 939 Handle(StepRepr_Representation) rep1 = ( SRRReversed ? SRR->Rep2() : SRR->Rep1() );
940 Handle(StepShape_ShapeRepresentation) rep = Handle(StepShape_ShapeRepresentation)::DownCast(rep1);
941
942 if ( SRRReversed )
943 TP->AddWarning ( SRR, "SRR reverses relation defined by NAUO; NAUO definition is taken" );
944
945 TopoDS_Shape theResult;
946
947 gp_Trsf Trsf;
948 Standard_Boolean iatrsf = ComputeSRRWT ( SRR, TP, Trsf );
7fd59977 949
7fd59977 950 Handle(Transfer_Binder) binder;
951 Standard_Boolean isBound = Standard_False;
952 if (!TP->IsBound(rep)) binder = TransferEntity(rep,TP,isBound);
953 else binder = TP->Find(rep);
954 theResult = TransferBRep::ShapeResult (binder);
7fd59977 955
956 if ( ! theResult.IsNull() ) {
957 if ( iatrsf ) {
958 if ( SRRReversed ) ApplyTransformation ( theResult, Trsf.Inverted() );
959 else ApplyTransformation ( theResult, Trsf );
960 }
961 shbinder = new TransferBRep_ShapeBinder (theResult);
962 }
963 else shbinder.Nullify();
964 TP->Bind(CDSR, shbinder);
965 return shbinder;
966
967}
968//=======================================================================
969//function : TransferEntity
970//purpose :
971//=======================================================================
972
973Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(const Handle(StepRepr_ShapeRepresentationRelationship)& und,
974 const Handle(Transfer_TransientProcess)& TP,
975 const Standard_Integer nbrep)
976{
977 // REPRESENTATION_RELATIONSHIP et la famille
978 Handle(TransferBRep_ShapeBinder) shbinder;
979
980 if (und.IsNull()) return shbinder;
981
982 // On prend son contenu : Rep1 ou Rep2 , that is the question
983 // on prend les 2. Mais quoi faire des axes
984
985 TopoDS_Compound Cund;
986 TopoDS_Shape OneResult;
987 BRep_Builder B;
988 B.MakeCompound (Cund);
989 Standard_Integer nsh = 0;
990
991 gp_Trsf Trsf;
992 Standard_Boolean iatrsf = ComputeSRRWT ( und, TP, Trsf );
993
994 // Transfert : que faut-il prendre au juste ?
995
996 for (Standard_Integer i = 1; i <= 2; i ++) {
997 if(nbrep && nbrep != i)
998 continue;
999 Handle(StepRepr_Representation) anitemt;
1000 if (i == 1) anitemt = und->Rep1();
1001 if (i == 2) anitemt = und->Rep2();
1002 Handle(StepShape_ShapeRepresentation) anitem = Handle(StepShape_ShapeRepresentation)::DownCast(anitemt);
1003 Handle(Transfer_Binder) binder;
1004 Standard_Boolean isBound = Standard_False;
63c71e2f 1005 if (!TP->IsBound(anitem)) binder = TransferEntity(anitem,TP,isBound);
7fd59977 1006 else binder = TP->Find(anitem);
1007 TopoDS_Shape theResult = TransferBRep::ShapeResult (binder);
1008 if (!theResult.IsNull()) {
1009 OneResult = theResult;
1010 B.Add(Cund, theResult);
1011 nsh ++;
1012 }
1013 }
1014
1015 // La Transformation : selon les cas
1016
1017 // Appliquer la transformation
1018
1019 if (iatrsf) {
1020 if (nsh == 1) ApplyTransformation ( OneResult, Trsf );
1021 else if (nsh > 1) ApplyTransformation ( Cund, Trsf );
1022 }
1023 if (nsh == 0) shbinder.Nullify();
1024 else if (nsh == 1) shbinder = new TransferBRep_ShapeBinder (OneResult);
1025 else shbinder = new TransferBRep_ShapeBinder (Cund);
1026 TP->Bind(und, shbinder);
1027 return shbinder;
1028
1029}
1030
7fd59977 1031//=======================================================================
1032//function : IsNeedRepresentation
1033//purpose :
1034//=======================================================================
1035
1036static Standard_Boolean IsNeedRepresentation(const Handle(StepRepr_ShapeAspect)& sa,
1037 const Handle(StepRepr_Representation)&repA ,
1038 const Handle(Transfer_TransientProcess)& TP)
1039{
1040 Standard_Boolean IsSDRaspect=Standard_True;
1041 Handle(StepRepr_ProductDefinitionShape) PDSA = sa->OfShape();
1042 const Interface_Graph& graph = TP->Graph();
1043 Interface_EntityIterator subs7 = graph.Sharings(PDSA);
1044 for (subs7.Start(); ! PDSA.IsNull() && subs7.More(); subs7.Next()) {
1045 Handle(StepShape_ShapeDefinitionRepresentation) sdrA =
1046 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs7.Value());
1047 if ( sdrA.IsNull() ) continue;
1048 // abv 23 Feb 00: use iterator to take into account AP203 hybrid models
1049 Interface_EntityIterator subs8 = graph.Shareds(sdrA);
1050 for (subs8.Start(); subs8.More(); subs8.Next()) {
1051 Handle(StepRepr_Representation) rep2 =
1052 Handle(StepRepr_Representation)::DownCast ( subs8.Value() );
1053 if ( rep2.IsNull() ) {
1054 Handle(StepRepr_ShapeRepresentationRelationship) SRR =
1055 Handle(StepRepr_ShapeRepresentationRelationship)::DownCast ( subs8.Value() );
1056 if ( SRR.IsNull() ) continue;
1057 rep2 = ( sdrA->UsedRepresentation() == SRR->Rep1() ? SRR->Rep2() : SRR->Rep1() );
1058 }
1059 Standard_Integer i, j; // svv Jan 11 2000 : porting on DEC
1060 for ( i=1; i <= repA->NbItems(); i++ ) {
1061 Handle(StepRepr_RepresentationItem) it = repA->ItemsValue(i);
1062 for ( j=1; j <= rep2->NbItems(); j++ )
1063 if ( it == rep2->ItemsValue(j) ) break;
1064 if ( j > rep2->NbItems() ) break;
1065 }
1066 if ( i > repA->NbItems() ) IsSDRaspect=Standard_False;
1067 }
1068 }
1069 return IsSDRaspect;
1070}
1071//=======================================================================
1072//function : OldWay
1073//purpose :
1074//=======================================================================
1075
1076Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::OldWay(const Handle(Standard_Transient)& start,
1077 const Handle(Transfer_TransientProcess)& TP)
1078{
1079 Handle(Message_Messenger) sout = TP->Messenger();
1080 const Interface_Graph& graph = TP->Graph();
1081 Handle(TransferBRep_ShapeBinder) shbinder;
1082 DeclareAndCast(StepShape_ShapeDefinitionRepresentation,sdr,start);
1083 Handle(StepRepr_Representation) rep = sdr->UsedRepresentation();
1084
1085 // abv 7 Oct 99: TRJ2: skip SDRs used only for defining SHAPE_ASPECT (validation properties)
1086 // BUT ONLY if they have representation duplicated with other SDR,
1087 // (SHAPE_ASPECT also used by some systems to define geometry)
1088 Handle(StepRepr_PropertyDefinition) PD = sdr->Definition().PropertyDefinition();
1089 if ( ! PD.IsNull() ) {
1090 Handle(StepRepr_ShapeAspect) SA = PD->Definition().ShapeAspect();
1091 if ( ! SA.IsNull() ) {
1092 if(!IsNeedRepresentation(SA,rep,TP))
1093 return shbinder;
1094 }
1095 }
1096
1097#ifdef TRANSLOG
1098 if (TP->TraceLevel() > 2)
1099 sout<<" -- Actor : case shape_definition_representation."<<endl;
1100#endif
1101 Handle(Transfer_Binder) binder = TP->Find(rep);
1102 if (binder.IsNull()) binder = TP->Transferring(rep);
1103//:j2 if (!binder.IsNull()) return binder;
1104
1105// SDR designant des CDSR (lien implicite, via la UsedRepr)
1106
1107 TopoDS_Compound Cund;
1108 TopoDS_Shape OneResult;
1109 BRep_Builder B;
1110 B.MakeCompound (Cund);
1111 Standard_Integer nsh = 0;
1112
1113 //:j2
1114 shbinder = new TransferBRep_ShapeBinder;
1115 TP->Bind ( start, shbinder ); //:j3 abv 23 Oct 98: rp1sd.stp: bind something to protect against loops
1116 if (!binder.IsNull()) {
1117 TopoDS_Shape theResult = TransferBRep::ShapeResult (binder);
1118 if (!theResult.IsNull()) {
1119 OneResult = theResult;
1120 B.Add(Cund, theResult);
1121 nsh ++;
1122 shbinder->SetResult (theResult);
1123 }
1124 }
1125
1126 // process subcomponents of assembly (CDSR) and hybrid models (SRR)
1127 Interface_EntityIterator subs = graph.Shareds(start);
1128 Handle(Standard_Type) tCDSR = STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation);
1129 Handle(Standard_Type) tSRR = STANDARD_TYPE(StepRepr_ShapeRepresentationRelationship);
1130 Standard_Integer nbitem=0;
1131 for (subs.Start();subs.More();subs.Next()) nbitem++;
1132 Message_ProgressSentry PS ( TP->GetProgress(), "Sub", 0, nbitem, 1 );
1133 for (subs.Start(); subs.More() && PS.More(); subs.Next() ,PS.Next()) {
1134 Handle(Standard_Transient) anitem = subs.Value();
1135 if ( anitem->DynamicType() != tCDSR && anitem->DynamicType() != tSRR ) continue;
1136// DeclareAndCast(StepShape_ContextDependentShapeRepresentation,anitem,subs.Value());
1137// if (anitem.IsNull()) continue;
1138#ifdef TRANSLOG
1139 if (TP->TraceLevel() > 1)
1140 sout<<" -- Actor : Ent.n0 "<<TP->Model()->Number(start)<<" -> Shared Ent.no"<<TP->Model()->Number(anitem)<<endl;
1141#endif
1142
1143 if (!TP->IsBound(anitem)) binder = TP->Transferring(anitem);
1144 else binder = TP->Find(anitem);
1145 TopoDS_Shape theResult = TransferBRep::ShapeResult (binder);
1146 if (!theResult.IsNull()) {
1147 OneResult = theResult;
1148 B.Add(Cund, theResult);
1149 nsh += 2; //abv 11.10.00: 2 instead of 1 in order to keep assembly structure
1150 }
1151 }
1152
1153 if (nsh == 0) shbinder = new TransferBRep_ShapeBinder (Cund);//shbinder.Nullify();
1154 else if (nsh == 1) shbinder = new TransferBRep_ShapeBinder (OneResult);
1155 else shbinder = new TransferBRep_ShapeBinder (Cund);
1156 TP->Unbind( start ); //:j3: unbind start (let it be bound by TransferProcess)
1157 return shbinder;
1158}
1159
1160//=======================================================================
1161//function : TransferEntity
1162//purpose :
1163//=======================================================================
1164
1165Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(const Handle(StepGeom_GeometricRepresentationItem)& start,
1166 const Handle(Transfer_TransientProcess)& TP,
1167 const Standard_Boolean isManifold)
1168{
1169 Handle(Message_Messenger) sout = TP->Messenger();
1170 Handle(TransferBRep_ShapeBinder) shbinder;
1171 Standard_Boolean found = Standard_False;
1172 StepToTopoDS_Builder myShapeBuilder;
1173 TopoDS_Shape mappedShape;
1174 Standard_Integer nbTPitems = TP->NbMapped();
1175#ifdef TRANSLOG
1176 OSD_Timer chrono;
1177 if (TP->TraceLevel() > 2)
1178 sout << "Begin transfer STEP -> CASCADE, Type "
1179 << start->DynamicType()->Name() << endl;
1180 chrono.Start();
1181#endif
1182
1183 //:S4136
1184 Handle(StepRepr_Representation) oldSRContext = mySRContext;
1185 if ( mySRContext.IsNull() ) { // if no context, try to find it (ex: r0701_ug.stp #4790)
1186 Handle(StepRepr_Representation) context = FindContext ( start, TP );
1187 if ( context.IsNull() ) {
1188 TP->AddWarning ( start, "Entity with no unit context; default units taken" );
1189 ResetUnits();
1190 }
1191 else PrepareUnits ( context, TP );
1192 }
1193 myShapeBuilder.SetPrecision(myPrecision);
1194 myShapeBuilder.SetMaxTol(myMaxTol);
b485ee79
KD
1195
1196 // Start progress scope (no need to check if progress exists -- it is safe)
1197 Message_ProgressSentry aPSentry(TP->GetProgress(), "Transfer stage", 0, 2, 1);
1198
7fd59977 1199 try {
1200 OCC_CATCH_SIGNALS
1201 if (start->IsKind(STANDARD_TYPE(StepShape_FacetedBrep))) {
1202 myShapeBuilder.Init(GetCasted(StepShape_FacetedBrep, start), TP);
1203 found = Standard_True;
1204 }
1205 else if (start->IsKind(STANDARD_TYPE(StepShape_BrepWithVoids))) {
1206 myShapeBuilder.Init(GetCasted(StepShape_BrepWithVoids, start), TP);
1207 found = Standard_True;
1208 }
1209 else if (start->IsKind(STANDARD_TYPE(StepShape_ManifoldSolidBrep))) {
1210 myShapeBuilder.Init(GetCasted(StepShape_ManifoldSolidBrep, start), TP);
1211 found = Standard_True;
1212 }
1213 else if (start->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel))) {
1214 myShapeBuilder.Init(GetCasted(StepShape_ShellBasedSurfaceModel, start), TP, myNMTool);
1215 found = Standard_True;
1216 }
1217 else if (start->IsKind(STANDARD_TYPE(StepShape_FacetedBrepAndBrepWithVoids))) {
1218 myShapeBuilder.Init(GetCasted(StepShape_FacetedBrepAndBrepWithVoids, start), TP);
1219 found = Standard_True;
1220 }
1221 else if (start->IsKind(STANDARD_TYPE(StepShape_GeometricSet))) {
38deba5d 1222 myShapeBuilder.Init(GetCasted(StepShape_GeometricSet, start), TP, this, isManifold);
7fd59977 1223 found = Standard_True;
1224 }
1225 else if (start->IsKind(STANDARD_TYPE(StepShape_EdgeBasedWireframeModel))) {
1226 myShapeBuilder.Init(GetCasted(StepShape_EdgeBasedWireframeModel, start), TP);
1227 found = Standard_True;
1228 }
1229 else if (start->IsKind(STANDARD_TYPE(StepShape_FaceBasedSurfaceModel))) {
1230 myShapeBuilder.Init(GetCasted(StepShape_FaceBasedSurfaceModel, start), TP);
1231 found = Standard_True;
1232 }
1233}
1234 catch(Standard_Failure) {
1235 TP->AddFail(start,"Exeption is raised. Entity was not translated.");
1236 TP->Bind(start, shbinder);
1237 return shbinder;
1238 }
b485ee79
KD
1239
1240 aPSentry.Next();
7fd59977 1241
1242 if (found && myShapeBuilder.IsDone()) {
1243 mappedShape = myShapeBuilder.Value();
1244 // Apply ShapeFix (on manifold shapes only. Non-manifold topology is processed separately: ssv; 13.11.2010)
1245 if (isManifold) {
1246 Handle(Standard_Transient) info;
1247 mappedShape =
b485ee79
KD
1248 XSAlgo::AlgoContainer()->ProcessShape( mappedShape, myPrecision, myMaxTol,
1249 "read.step.resource.name",
1250 "read.step.sequence", info,
1251 TP->GetProgress() );
7fd59977 1252 XSAlgo::AlgoContainer()->MergeTransferInfo(TP, info, nbTPitems);
1253 }
1254 }
1255 found = !mappedShape.IsNull();
1256 if (found && shbinder.IsNull()) shbinder = new TransferBRep_ShapeBinder (mappedShape);
1257#ifdef TRANSLOG
1258 chrono.Stop();
1259 if (TP->TraceLevel() > 2)
1260 sout<<"End transfer STEP -> CASCADE :" << (found ? "OK" : " : no result")<<endl;
1261 if (TP->TraceLevel() > 2)
1262 chrono.Show();
1263#endif
1264 if ( oldSRContext.IsNull() && ! mySRContext.IsNull() ) //:S4136
1265 PrepareUnits ( oldSRContext, TP );
1266 TP->Bind(start, shbinder);
1267 return shbinder;
1268}
1269
1270
1271//=======================================================================
1272//function : TransferEntity
1273//purpose :
1274//=======================================================================
1275
1276Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(const Handle(StepRepr_MappedItem)& mapit,
1277 const Handle(Transfer_TransientProcess)& TP)
1278{
1279 Handle(TransferBRep_ShapeBinder) shbinder;
1280
1281 // --------------------------------------------------------------
1282 // On se trouve ici dans un contexte " d'assemblage geometrique "
1283 // - MappedItem
1284 // --------------------------------------------------------------
1285
1286 //:S4136: abv 20 Apr 99: as1ug.stp: MAPPED_ITEM transformation computed
1287 // taking into account units of origin and target SHAPE_REPRESENTATIONs
1288
1289 // La Shape, et la mise en position
1290 Handle(StepShape_ShapeRepresentation) maprep = Handle(StepShape_ShapeRepresentation)::
1291 DownCast(mapit->MappingSource()->MappedRepresentation());
7fd59977 1292 Standard_Boolean isBound = Standard_False;
1293 Handle(Transfer_Binder) binder = TP->Find(maprep);
1294 if (binder.IsNull()) binder = TransferEntity(maprep,TP,isBound);
1295 shbinder = Handle(TransferBRep_ShapeBinder)::DownCast(binder);
1296 if (shbinder.IsNull()) TP->AddWarning(mapit,"No Shape Produced");
1297 else {
1298 TopoDS_Shape mappedShape = shbinder->Result();
1299 if ( ! mappedShape.IsNull() ) {
1300
1301 // Positionnement : 2 formules
1302 // 1/ Ax2 dans Source et comme Target : passage de Source a Target
1303 // 2/ CartesianOperator3d comme Target : on applique
1304
1305 gp_Trsf Trsf;
1306 Standard_Boolean ok = Standard_False;
1307
1308 Handle(StepGeom_CartesianTransformationOperator3d) CartOp =
1309 Handle(StepGeom_CartesianTransformationOperator3d)::DownCast(mapit->MappingTarget());
1310 if ( ! CartOp.IsNull() ) {
caaeed1b 1311 ok = StepToGeom::MakeTransformation3d (CartOp, Trsf);
7fd59977 1312 }
1313 else {
1314 Handle(StepGeom_Axis2Placement3d) Origin =
1315 Handle(StepGeom_Axis2Placement3d)::DownCast(mapit->MappingSource()->MappingOrigin());
1316 Handle(StepGeom_Axis2Placement3d) Target =
1317 Handle(StepGeom_Axis2Placement3d)::DownCast(mapit->MappingTarget());
1318 if ( ! Origin.IsNull() && ! Target.IsNull() ) {
1319 ok = Standard_True;
1320 Handle(StepRepr_Representation) rep = mySRContext; // NOTE: copy of handle !
1321 ComputeTransformation ( Origin, Target, maprep, rep, TP, Trsf );
1322 ok = Standard_True;
1323 }
1324 }
1325
1326 if ( ok ) ApplyTransformation ( mappedShape, Trsf );
1327 else TP->AddWarning (mapit,"Mapped Item, case not recognized, location ignored");
1328
1329 shbinder = new TransferBRep_ShapeBinder (mappedShape);
1330 }
1331 }
1332 TP->Bind(mapit, shbinder);
1333 return shbinder;
1334}
1335//=======================================================================
1336//function : TransferEntity
1337//purpose :
1338//=======================================================================
1339
1340Handle(TransferBRep_ShapeBinder) STEPControl_ActorRead::TransferEntity(const Handle(StepShape_FaceSurface)& fs,
1341 const Handle(Transfer_TransientProcess)& TP)
1342{
1343
1344 // Cas bien utile meme si non reconnu explicitement
1345 Handle(TransferBRep_ShapeBinder) sb;
1346 Standard_Integer nbTPitems = TP->NbMapped();
1347 try {
1348 OCC_CATCH_SIGNALS
1349
63c71e2f 1350 StepToTopoDS_Tool myTool;
1351 StepToTopoDS_DataMapOfTRI aMap;
1352
1353 myTool.Init(aMap, TP);
1354 StepToTopoDS_TranslateFace myTF;
1355 myTF.SetPrecision(myPrecision);
1356 myTF.SetMaxTol(myMaxTol);
1357
1358 // Non-manifold topology is not processed here (ssv; 15.11.2010)
1359 StepToTopoDS_NMTool dummyNMTool;
1360 myTF.Init(fs, myTool, dummyNMTool);
1361 Handle(StepRepr_Representation) oldSRContext = mySRContext;
1362 if (mySRContext.IsNull()) { // if no context, try to find it (ex: r0701_ug.stp #4790)
1363 Handle(StepRepr_Representation) context = FindContext(fs, TP);
1364 if (context.IsNull()) {
1365 TP->AddWarning(fs, "Entity with no unit context; default units taken");
1366 ResetUnits();
1367 }
1368 else PrepareUnits(context, TP);
7fd59977 1369 }
7fd59977 1370
63c71e2f 1371 // Apply ShapeFix
1372 Handle(Transfer_Binder) binder = TP->Find(fs);
1373 sb = Handle(TransferBRep_ShapeBinder)::DownCast(binder);
1374 if (!sb.IsNull() && !sb->Result().IsNull()) {
1375 TopoDS_Shape S = sb->Result();
1376
1377 Handle(Standard_Transient) info;
1378 TopoDS_Shape shape = XSAlgo::AlgoContainer()->ProcessShape(S, myPrecision, myMaxTol,
1379 "read.step.resource.name",
1380 "read.step.sequence", info,
1381 TP->GetProgress());
1382 // TopoDS_Shape shape = XSAlgo::AlgoContainer()->PerformFixShape( S, TP, myPrecision, myMaxTol );
1383 if (shape != S)
1384 sb->SetResult(shape);
1385
1386 XSAlgo::AlgoContainer()->MergeTransferInfo(TP, info, nbTPitems);
1387 }
1388
1389
1390 if (oldSRContext.IsNull() && !mySRContext.IsNull()) //:S4136
1391 PrepareUnits(oldSRContext, TP);
1392 TP->Bind(fs, sb);
1393 return sb; // TP->Find (start);
1394 }
7fd59977 1395 catch(Standard_Failure)
1396 {
1397 TP->AddFail(fs,"Exeption is raised. Entity was not translated.");
1398 sb.Nullify();
1399 TP->Bind(fs, sb);
1400 return sb;
1401 }
1402}
1403//=======================================================================
1404//function : TransferShape
1405//purpose :
1406//=======================================================================
1407
1408Handle(Transfer_Binder) STEPControl_ActorRead::TransferShape(const Handle(Standard_Transient)& start,
1409 const Handle(Transfer_TransientProcess)& TP,
1410 const Standard_Boolean isManifold)
1411{
1412 if (start.IsNull()) return NullResult();
1413 XSAlgo::AlgoContainer()->PrepareForTransfer();
1414
7fd59977 1415 Handle(Message_Messenger) sout = TP->Messenger();
1416#ifdef TRANSLOG
1417// POUR MISE AU POINT, a supprimer ensuite
7fd59977 1418 if (TP->TraceLevel() > 1)
1419 sout<<" -- Actor : Transfer Ent.n0 "<<TP->Model()->Number(start)<<" Type "<<start->DynamicType()->Name()<<endl;
1420#endif
1421
1422 Handle(TransferBRep_ShapeBinder) shbinder;
1423
1424
1425 // Product Definition Entities
1426 // They should be treated with Design Manager
1427 // case ShapeDefinitionRepresentation if ProductMode != ON
1428 TCollection_AsciiString aProdMode = Interface_Static::CVal("read.step.product.mode");
1429 if(!aProdMode.IsEqual("ON") &&
1430 start->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation)))
1431 shbinder = OldWay(start,TP);
1432 //skl
1433
63c71e2f 1434 else if (start->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition))) {
1435 Handle(StepBasic_ProductDefinition) PD =
7fd59977 1436 Handle(StepBasic_ProductDefinition)::DownCast(start);
63c71e2f 1437 shbinder = TransferEntity(PD, TP);
7fd59977 1438 }
1439
1440 // NextAssemblyUsageOccurrence
1441 else if (start->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence))) {
63c71e2f 1442 Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
7fd59977 1443 Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(start);
63c71e2f 1444 shbinder = TransferEntity(NAUO, TP);
7fd59977 1445 }
1446 //end skl
1447
1448 // Shape Representation
1449 else if (start->IsKind(STANDARD_TYPE(StepShape_ShapeRepresentation))) {
1450 DeclareAndCast(StepShape_ShapeRepresentation,sr,start);
1451 Standard_Boolean isBound = Standard_False;
1452 shbinder = TransferEntity(sr,TP,isBound);
1453 }
1454
1455 // --------------------------------------------------------------
1456 // On se trouve ici aussi dans un contexte " d'assemblage geometrique "
1457 // - ShapeRepresentationRelationship + Transformation ou non
1458 // --------------------------------------------------------------
1459
1460 else if (start->IsKind(STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation))) {
1461 DeclareAndCast(StepShape_ContextDependentShapeRepresentation,CDSR,start);
1462 shbinder = TransferEntity(CDSR,TP);
1463 }
1464
1465 else if (start->IsKind (STANDARD_TYPE(StepRepr_ShapeRepresentationRelationship)) ) {
1466 // REPRESENTATION_RELATIONSHIP et la famille
1467
1468 DeclareAndCast(StepRepr_ShapeRepresentationRelationship,und,start);
1469 shbinder = TransferEntity(und,TP);
1470 }
1471
1472 else if (start->IsKind (STANDARD_TYPE(StepGeom_GeometricRepresentationItem)) ) {
1473 // Here starts the entity to be treated : Shape Representation Subtype
1474 // It can be also other Root entities
1475 DeclareAndCast(StepGeom_GeometricRepresentationItem,git,start);
1476 shbinder = TransferEntity(git, TP, isManifold);
1477 }
1478 else if (start->IsKind(STANDARD_TYPE(StepRepr_MappedItem))) {
1479 DeclareAndCast(StepRepr_MappedItem,mapit,start);
1480 shbinder= TransferEntity(mapit,TP);
1481 }
1482 else if (start->IsKind(STANDARD_TYPE(StepShape_FaceSurface))) {
1483 DeclareAndCast(StepShape_FaceSurface,fs,start);
1484 shbinder = TransferEntity(fs,TP);
1485 }
1486
1487// if (!shbinder.IsNull()) TP->Bind(start,binder);
1488
1489 return shbinder;
1490}
1491// ============================================================================
1492// Method : STEPControl_ActorRead::PrepareUnits
1493// Purpose : Set the unit conversion factors
1494// ============================================================================
1495
1496void STEPControl_ActorRead::PrepareUnits(const Handle(StepRepr_Representation)& rep,
1497 const Handle(Transfer_TransientProcess)& TP)
1498{
1499 mySRContext = rep;
1500
1501 Standard_Integer stat1, stat2 = 0; // sera alimente par STEPControl_Unit
7fd59977 1502 if (rep.IsNull()) {
7fd59977 1503 ResetUnits();
1504 return;
1505 }
1506
1507 // Get Units Applied to this model
1508 Handle(StepRepr_RepresentationContext) theRepCont = rep->ContextOfItems();
1509 if (theRepCont.IsNull()) {
1510 TP->AddWarning(rep,"Bad RepresentationContext, default unit taken");
1511 ResetUnits();
1512 return;
1513 }
1514
1515 // --------------------------------------------------
1516 // Complex ENTITY : GeometricRepresentationContext &&
1517 // GlobalUnitAssignedContext
1518 // --------------------------------------------------
1519
1520 STEPConstruct_UnitContext myUnit;
1521 Handle(StepRepr_GlobalUnitAssignedContext) theGUAC;
1522 Handle(StepRepr_GlobalUncertaintyAssignedContext) aTol;
1523
1524 if (theRepCont->IsKind(STANDARD_TYPE(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext))) {
1525 DeclareAndCast(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext, theGRCAGAUC,theRepCont);
1526 theGUAC = theGRCAGAUC->GlobalUnitAssignedContext();
7fd59977 1527 }
1528
1529 // ----------------------------------------------------
1530 // Complex ENTITY : GeometricRepresentationContext &&
1531 // GlobalUnitAssignedContext &&
1532 // GlobalUncertaintyAssignedContext
1533 // ----------------------------------------------------
1534
1535 if (theRepCont->IsKind(STANDARD_TYPE(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx))) {
1536 DeclareAndCast(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx,
1537 theGRCAGAUC,theRepCont);
1538 theGUAC = theGRCAGAUC->GlobalUnitAssignedContext();
1539 aTol = theGRCAGAUC->GlobalUncertaintyAssignedContext();
1540 }
1541
1542
1543 // ----------------------------------------------------
1544 // Decoding and Setting the Values
1545 // ----------------------------------------------------
1546
1547 if (!theGUAC.IsNull()) {
1548 stat1 = myUnit.ComputeFactors(theGUAC);
1549 Standard_Integer anglemode = Interface_Static::IVal("step.angleunit.mode");
1550 Standard_Real angleFactor = ( anglemode == 0 ? myUnit.PlaneAngleFactor() :
c6541a0c 1551 anglemode == 1 ? 1. : M_PI/180. );
7fd59977 1552 UnitsMethods::InitializeFactors(myUnit.LengthFactor(),
1553 angleFactor,
1554 myUnit.SolidAngleFactor());
1555 if (stat1 != 0) TP->AddWarning (theRepCont,myUnit.StatusMessage(stat1));
1556 }
1557
1558 if (!aTol.IsNull()) {
1559 stat2 = myUnit.ComputeTolerance (aTol);
1560 if (stat2 != 0) TP->AddWarning (theRepCont,myUnit.StatusMessage(stat2));
1561 }
1562
1563// myPrecision = Precision::Confusion();
1564 if (Interface_Static::IVal("read.precision.mode") == 1) //:i1 gka S4136 05.04.99
1565 myPrecision = Interface_Static::RVal("read.precision.val");
1566 else if (myUnit.HasUncertainty())
1567 myPrecision = myUnit.Uncertainty() * myUnit.LengthFactor();
1568 else {
1569 TP->AddWarning(theRepCont,"No Length Uncertainty, value of read.precision.val is taken");
1570 myPrecision = Interface_Static::RVal("read.precision.val");
1571 }
1572 myMaxTol = Max ( myPrecision, Interface_Static::RVal("read.maxprecision.val") );
1573 // Assign uncertainty
7fd59977 1574#ifdef TRANSLOG
1575 if (TP->TraceLevel() > 1)
1576 TP->Messenger() <<" Cc1ToTopoDS : Length Unit = "<<myUnit.LengthFactor()<<" Tolerance CASCADE = "<<myPrecision<<endl;
1577#endif
1578}
1579
1580//=======================================================================
1581//function : ResetUnits
1582//purpose :
1583//=======================================================================
1584
1585void STEPControl_ActorRead::ResetUnits ()
1586{
1587 UnitsMethods::InitializeFactors ( 1, 1, 1 );
1588 myPrecision = Interface_Static::RVal("read.precision.val");
1589 myMaxTol = Max ( myPrecision, Interface_Static::RVal("read.maxprecision.val") );
1590}
1591
1592//=======================================================================
1593//function : ComputeTransformation
1594//purpose :
1595//=======================================================================
1596
1597//:S4136 abv 20 Apr 99: as1ug.stp: compute transformation taking units into account
1598Standard_Boolean STEPControl_ActorRead::ComputeTransformation (const Handle(StepGeom_Axis2Placement3d) &Origin,
1599 const Handle(StepGeom_Axis2Placement3d) &Target,
1600 const Handle(StepRepr_Representation) &OrigContext,
1601 const Handle(StepRepr_Representation) &TargContext,
1602 const Handle(Transfer_TransientProcess) &TP,
1603 gp_Trsf &Trsf)
1604{
1605 Trsf = gp_Trsf(); // reinit
1606 if ( Origin.IsNull() || Target.IsNull() ) return Standard_False;
1607
1608 //:abv 31.10.01: TEST_MCI_2.step: check that Ax1 and Ax2 belong to
1609 // corresponding reps and fix case of inversion error
1610 Handle(StepGeom_Axis2Placement3d) org = Origin;
1611 Handle(StepGeom_Axis2Placement3d) trg = Target;
1612 Standard_Integer code1=0, code2=0, i;
1613 for ( i=1; code1 != 1 && i <= OrigContext->NbItems(); i++ ) {
1614 if ( OrigContext->ItemsValue(i) == org ) code1 = 1;
1615 else if ( OrigContext->ItemsValue(i) == trg ) code1 = -1;
1616 }
1617 for ( i=1; code2 != 1 && i <= TargContext->NbItems(); i++ ) {
1618 if ( TargContext->ItemsValue(i) == org ) code2 = -1;
1619 else if ( TargContext->ItemsValue(i) == trg ) code2 = 1;
1620 }
1621 if ( code1 != 1 && code2 != 1 ) {
1622 if ( code1 == -1 && code2 == -1 ) {
1623 Handle(StepGeom_Axis2Placement3d) swp = org; org = trg; trg = swp;
1624 TP->AddWarning ( org, "Axis placements are swapped in SRRWT; corrected" );
1625 }
1626 else {
1627 TP->AddWarning ( ( code1 == 1 ? trg : org ),
1628 "Axis placement used by SRRWT does not belong to corresponding representation" );
1629 }
1630 }
1631
1632 // translate axis_placements taking units into account
1633 Handle(StepRepr_Representation) oldSRContext = mySRContext;
1634 if ( OrigContext != oldSRContext ) PrepareUnits(OrigContext,TP);
caaeed1b 1635 Handle(Geom_Axis2Placement) theOrig = StepToGeom::MakeAxis2Placement (org);
7fd59977 1636 if ( TargContext != OrigContext ) PrepareUnits(TargContext,TP);
caaeed1b 1637 Handle(Geom_Axis2Placement) theTarg = StepToGeom::MakeAxis2Placement (trg);
7fd59977 1638 if ( oldSRContext != TargContext ) PrepareUnits(oldSRContext,TP);
bd05fabf 1639
7fd59977 1640 gp_Ax3 ax3Orig(theOrig->Ax2());
1641 gp_Ax3 ax3Targ(theTarg->Ax2());
d2a98d71 1642
bd05fabf
S
1643 // ne pas se tromper de sens !
1644 Trsf.SetTransformation(ax3Targ, ax3Orig);
7fd59977 1645 return Trsf.Form() != gp_Identity;
1646}
1647
1648//=======================================================================
1649//function : ReadSRRWT
1650//purpose :
1651//=======================================================================
1652
1653//:j2 abv 22 Oct 98: auxiliary function: reading transformation from SRRWT
1654Standard_Boolean STEPControl_ActorRead::ComputeSRRWT (const Handle(StepRepr_RepresentationRelationship) &SRR,
1655 const Handle(Transfer_TransientProcess) &TP,
1656 gp_Trsf &Trsf)
1657{
1658 Trsf = gp_Trsf(); // init
1659
1660 DeclareAndCast(StepRepr_ShapeRepresentationRelationshipWithTransformation,srwt,SRR);
1661 if ( srwt.IsNull() ) return Standard_False;
1662
1663 StepRepr_Transformation SelectTrans = srwt->TransformationOperator();
1664
1665 // cartesian transformation
1666 Handle(StepGeom_CartesianTransformationOperator3d) CartOp =
1667 Handle(StepGeom_CartesianTransformationOperator3d)::DownCast(SelectTrans.Value());
1668 if ( ! CartOp.IsNull() ) {
1669 // reset units (by Rep2 - ?)
1670 Handle(StepRepr_Representation) oldSRContext = mySRContext;
1671 if ( SRR->Rep2() != oldSRContext ) PrepareUnits(SRR->Rep2(),TP);
caaeed1b 1672 StepToGeom::MakeTransformation3d (CartOp, Trsf);
7fd59977 1673 if ( SRR->Rep2() != oldSRContext ) PrepareUnits(oldSRContext,TP);
1674 return Trsf.Form() != gp_Identity;
1675 }
1676
1677 // item-defined transformation
1678 Handle(StepRepr_ItemDefinedTransformation) ItemDef =
1679 SelectTrans.ItemDefinedTransformation();
1680 if ( ItemDef.IsNull() ) return Standard_False;
1681
1682 Handle(StepGeom_Axis2Placement3d) Ax1 =
1683 Handle(StepGeom_Axis2Placement3d)::DownCast(ItemDef->TransformItem1());
1684 Handle(StepGeom_Axis2Placement3d) Ax2 =
1685 Handle(StepGeom_Axis2Placement3d)::DownCast(ItemDef->TransformItem2());
1686 if ( Ax1.IsNull() || Ax2.IsNull() ) return Standard_False;
1687 return ComputeTransformation ( Ax1, Ax2, SRR->Rep1(), SRR->Rep2(), TP, Trsf);
1688}
1689
1690//=======================================================================
1691// Method : closeIDEASShell
1692// Purpose : Attempts to close the passed Shell with the passed closing
1693// Shells. Cuts redundant Faces from the closing Shells if any
1694//=======================================================================
1695
1696TopoDS_Shell STEPControl_ActorRead::closeIDEASShell(const TopoDS_Shell& shell,
1697 const TopTools_ListOfShape& closingShells) {
1698
1699 // Make Shell to provide closeness adjustments
1700 TopoDS_Shell result;
1701 BRep_Builder brepBuilder;
1702 brepBuilder.MakeShell(result);
1703
1704 // Firstly, add all existing faces to the new Shell
1705 TopExp_Explorer currentFExp(shell, TopAbs_FACE);
1706 for ( ; currentFExp.More(); currentFExp.Next() ) {
1707 TopoDS_Face currentFace = TopoDS::Face( currentFExp.Current() );
1708 brepBuilder.Add(result, currentFace);
1709 }
1710
1711 TopTools_ListIteratorOfListOfShape itL(closingShells);
1712 TopTools_ListOfShape closingFaces;
1713
1714 // Then add the closing faces
1715 for ( ; itL.More(); itL.Next() ) {
1716 TopoDS_Shape currentClosing = itL.Value();
1717 TopExp_Explorer faceExp(currentClosing, TopAbs_FACE);
1718
1719 for ( ; faceExp.More(); faceExp.Next() ) {
1720 TopoDS_Face currentFace = TopoDS::Face( faceExp.Current() );
1721 brepBuilder.Add(result, currentFace);
1722 // Store each added closing face for subsequent processing
1723 closingFaces.Append(currentFace);
1724 }
1725 }
1726
1727 // Check if the result is closed
1728 BRepCheck_Shell checker( TopoDS::Shell(result) );
1729 BRepCheck_Status checkStatus = checker.Closed();
1730 if (checkStatus == BRepCheck_NoError)
1731 result.Closed(Standard_True);
1732 else
1733 return shell; // Cannot close this shell, skip it so...
1734
1735 // Try to remove redundant Faces
1736 for ( itL.Initialize(closingFaces); itL.More(); itL.Next() ) {
1737 TopoDS_Face currentFace = TopoDS::Face( itL.Value() );
1738 // Remove face to see if Shell is still closed
1739 brepBuilder.Remove(result, currentFace);
1740 BRepCheck_Shell subChecker( TopoDS::Shell(result) );
1741 BRepCheck_Status subCheckStatus = subChecker.Closed();
1742 // If Shell becomes open, just put the deleted face back
1743 if (subCheckStatus != BRepCheck_NoError)
1744 brepBuilder.Add(result, currentFace);
1745 else {
0797d9d3 1746 #ifdef OCCT_DEBUG
7fd59977 1747 cout << "Redundant closing face detected: REMOVED from shell";
1748 #endif
1749 }
1750 }
1751
1752 return result;
1753
1754}
1755
1756//=======================================================================
1757// Method : computeIDEASClosings
1758// Purpose : For each Shell from the compound passed (comp), find all
1759// non-manifold adjacent Shells and put the results into
1760// the passed map (shellClosingMap)
1761//=======================================================================
1762
1763void STEPControl_ActorRead::computeIDEASClosings(const TopoDS_Compound& comp,
1764 TopTools_IndexedDataMapOfShapeListOfShape& shellClosingsMap) {
1765 TopExp_Explorer shellExpA(comp, TopAbs_SHELL);
1766
1767 for ( ; shellExpA.More(); shellExpA.Next() ) {
1768 TopoDS_Shape shellA = shellExpA.Current();
1769 TopExp_Explorer shellExpB(comp, TopAbs_SHELL);
1770 TopTools_ListOfShape closingShells;
1771
1772 for ( ; shellExpB.More(); shellExpB.Next() ) {
1773 TopoDS_Shape shellB = shellExpB.Current();
1774 if ( shellA.IsSame(shellB) )
1775 continue;
1776 // Check whether ShellB is non-manifold and adjacent to ShellA.
1777 // If so, ShellA has a chance to be closed with ShellB
1778 if ( myNMTool.IsSuspectedAsClosing(shellA, shellB) )
1779 closingShells.Append(shellB);
1780 }
1781
1782 if ( !closingShells.IsEmpty() )
1783 shellClosingsMap.Add(shellA, closingShells);
1784 }
7fd59977 1785}