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