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