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