1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 //:k8 abv 6 Jan 99: unique names for PRODUCTs
15 //:k9 abv 6 Jan 99: TR10: eliminating duplicated APPLICATION_CONTEXT entities
16 //abv,gka 05.04.99: S4136: change parameters and update units
17 // PTV 22.08.2002 OCC609 transfer solo vertices into step file.
18 // PTV 16.09.2002 OCC725 transfer compound of vertices into one geometrical curve set.
19 #include <STEPControl_ActorWrite.ixx>
20 #include <STEPControl_StepModelType.hxx>
23 #include <Transfer_SimpleBinderOfTransient.hxx>
25 #include <GeomToStep_MakeAxis2Placement3d.hxx>
26 #include <StepGeom_Axis2Placement3d.hxx>
28 #include <STEPConstruct_Part.hxx>
29 #include <STEPConstruct_Assembly.hxx>
30 #include <STEPConstruct_ContextTool.hxx>
31 #include <STEPConstruct_UnitContext.hxx>
34 #include <TopoDSToStep.hxx>
35 #include <TopoDSToStep_Builder.hxx>
36 #include <TopoDSToStep_FacetedTool.hxx>
37 #include <TopoDSToStep_Tool.hxx>
38 #include <TopoDSToStep_MakeManifoldSolidBrep.hxx>
39 #include <TopoDSToStep_MakeBrepWithVoids.hxx>
40 #include <TopoDSToStep_MakeFacetedBrep.hxx>
41 #include <TopoDSToStep_MakeFacetedBrepAndBrepWithVoids.hxx>
42 #include <TopoDSToStep_MakeGeometricCurveSet.hxx>
43 #include <TopoDSToStep_MakeShellBasedSurfaceModel.hxx>
46 #include <TopoDS_Shape.hxx>
47 #include <TopoDS_Solid.hxx>
48 #include <Geom_Surface.hxx>
49 #include <Geom_Plane.hxx>
50 #include <Geom_Curve.hxx>
51 #include <Geom_Line.hxx>
53 #include <StepShape_ShapeDefinitionRepresentation.hxx>
54 #include <StepShape_FacetedBrepAndBrepWithVoids.hxx>
55 #include <StepShape_FacetedBrep.hxx>
56 #include <StepShape_GeometricCurveSet.hxx>
57 #include <StepShape_ShellBasedSurfaceModel.hxx>
58 #include <StepShape_ManifoldSolidBrep.hxx>
59 #include <StepShape_BrepWithVoids.hxx>
60 #include <StepRepr_HArray1OfRepresentationItem.hxx>
61 #include <StepBasic_HArray1OfProduct.hxx>
62 #include <StepRepr_GlobalUnitAssignedContext.hxx>
63 #include <StepShape_AdvancedBrepShapeRepresentation.hxx>
64 #include <StepShape_FacetedBrepShapeRepresentation.hxx>
65 #include <StepShape_TopologicalRepresentationItem.hxx>
66 #include <StepShape_ManifoldSurfaceShapeRepresentation.hxx>
67 #include <StepShape_GeometricallyBoundedWireframeShapeRepresentation.hxx>
68 #include <StepBasic_ApplicationProtocolDefinition.hxx>
69 #include <StepRepr_PropertyDefinition.hxx>
71 #include <TopExp_Explorer.hxx>
72 #include <TColStd_HSequenceOfTransient.hxx>
73 #include <TCollection_HAsciiString.hxx>
75 #include <Transfer_TransientProcess.hxx>
76 #include <Transfer_Binder.hxx>
77 #include <Transfer_Finder.hxx>
78 #include <Transfer_FinderProcess.hxx>
79 #include <TransferBRep_ShapeMapper.hxx>
80 #include <TransferBRep.hxx>
81 #include <OSD_Timer.hxx>
83 #include <ShapeExtend_Explorer.hxx>
84 #include <ShapeAnalysis_ShapeTolerance.hxx>
85 #include <Interface_MSG.hxx>
86 #include <Interface_Static.hxx>
88 #include <Interface_Macros.hxx>
89 #include <TopTools_HSequenceOfShape.hxx>
91 #include <BRep_Tool.hxx>
92 #include <TopoDS_Iterator.hxx> //:d6
93 #include <UnitsMethods.hxx>
94 #include <STEPConstruct_AP203Context.hxx>
95 #include <BRepTools_Modifier.hxx>
98 #include <XSAlgo_AlgoContainer.hxx>
99 #include <StepRepr_ShapeRepresentationRelationship.hxx>
100 #include <Transfer_SequenceOfBinder.hxx>
102 #include <TopoDSToStep_MakeStepVertex.hxx>
103 #include <StepShape_VertexPoint.hxx>
104 #include <MoniTool_DataMapOfShapeTransient.hxx>
105 #include <StepShape_HArray1OfGeometricSetSelect.hxx>
106 #include <StepShape_GeometricSetSelect.hxx>
107 #include <TopoDS_Compound.hxx>
108 #include <BRep_Builder.hxx>
110 // Non-manifold topology processing (ssv; 10.11.2010)
111 #include <StepShape_NonManifoldSurfaceShapeRepresentation.hxx>
112 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
113 #include <TopTools_ListOfShape.hxx>
114 #include <TopExp.hxx>
115 #include <TopTools_MapOfShape.hxx>
116 #include <TopTools_ListIteratorOfListOfShape.hxx>
117 #include <StepShape_ShapeRepresentation.hxx>
118 #include <StepData_StepModel.hxx>
120 // ============================================================================
121 // Function: DumpWhatIs
122 // Purpose: Use it in debug mode to dump your shapes
123 // ============================================================================
126 static void DumpWhatIs(const TopoDS_Shape& S) {
128 TopTools_MapOfShape aMapOfShape;
130 TopTools_ListOfShape aListOfShape;
131 aListOfShape.Append(S);
132 TopTools_ListIteratorOfListOfShape itL(aListOfShape);
133 Standard_Integer nbSolids = 0,
141 for( ; itL.More(); itL.Next() ) {
142 TopoDS_Iterator it( itL.Value() );
143 for ( ; it.More(); it.Next() ) {
144 TopoDS_Shape aSubShape = it.Value();
145 if ( !aMapOfShape.Add(aSubShape) )
147 aListOfShape.Append(aSubShape);
148 if (aSubShape.ShapeType() == TopAbs_SOLID)
150 if (aSubShape.ShapeType() == TopAbs_SHELL) {
151 if ( !aSubShape.Closed() )
155 if (aSubShape.ShapeType() == TopAbs_FACE)
157 if (aSubShape.ShapeType() == TopAbs_WIRE)
159 if (aSubShape.ShapeType() == TopAbs_EDGE)
161 if (aSubShape.ShapeType() == TopAbs_VERTEX)
166 cout << "//What is?// NB SOLIDS: " << nbSolids << endl;
167 cout << "//What is?// NB SHELLS: " << nbShells << endl;
168 cout << "//What is?// OPEN SHELLS: " << nbOpenShells << endl;
169 cout << "//What is?// CLOSED SHELLS: " << nbShells - nbOpenShells << endl;
170 cout << "//What is?// NB FACES: " << nbFaces << endl;
171 cout << "//What is?// NB WIRES: " << nbWires << endl;
172 cout << "//What is?// NB EDGES: " << nbEdges << endl;
173 cout << "//What is?// NB VERTEXES: " << nbVertexes << endl;
177 //=======================================================================
178 // Function : IsManifoldShape
179 // Purpose : Used to define whether the passed shape has manifold
181 //=======================================================================
183 static Standard_Boolean IsManifoldShape(const TopoDS_Shape& theShape) {
185 Standard_Boolean aResult = Standard_True;
187 // Do not check nested Compounds
188 TopoDS_Compound aDirectShapes;
189 BRep_Builder aBrepBuilder;
190 aBrepBuilder.MakeCompound(aDirectShapes);
192 TopoDS_Iterator anIt(theShape);
193 for ( ; anIt.More(); anIt.Next() ) {
194 TopoDS_Shape aDirectChild = anIt.Value();
195 if (aDirectChild.ShapeType() != TopAbs_COMPOUND)
196 aBrepBuilder.Add(aDirectShapes, aDirectChild);
200 DumpWhatIs(aDirectShapes);
203 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
204 TopExp::MapShapesAndAncestors(aDirectShapes, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces);
206 Standard_Integer aNbEdges = aMapEdgeFaces.Extent();
208 cout << "Checking whether the topology passed is manifold..." << endl;
212 for (Standard_Integer i = 1; i <= aNbEdges; i++) {
213 TopoDS_Edge aCurrentEdge = TopoDS::Edge( aMapEdgeFaces.FindKey(i) );
214 if ( !BRep_Tool::Degenerated(aCurrentEdge) ) {
215 Standard_Integer aNbAncestors = aMapEdgeFaces.FindFromIndex(i).Extent();
216 if (aNbAncestors > 2) {
217 aResult = Standard_False;
224 cout << "Check result: "
225 << (aResult ? "TRUE" : "FALSE") << endl;
231 //=======================================================================
232 //function : STEPControl_ActorWrite
234 //=======================================================================
236 STEPControl_ActorWrite::STEPControl_ActorWrite ()
237 : mygroup (0) , mytoler (-1.)
239 SetMode(STEPControl_ShellBasedSurfaceModel);
242 //=======================================================================
243 //method: getNMSSRForGroup
244 //purpose: allows to get NMSSR (NON_MANIFOLD_SURFACE_SHAPE_REPRESENTATION)
245 // STEP's entity for the group of shells (!) passed
246 //=======================================================================
248 Handle(StepShape_NonManifoldSurfaceShapeRepresentation) STEPControl_ActorWrite::getNMSSRForGroup(const Handle(TopTools_HSequenceOfShape)& shapeGroup,
249 const Handle(Transfer_FinderProcess)& FP,
250 Standard_Boolean& isNMSSRCreated) const
252 Handle(StepShape_NonManifoldSurfaceShapeRepresentation) aResult;
254 if ( !shapeGroup.IsNull() ) {
255 for (Standard_Integer i = 1; i <= shapeGroup->Length(); i++) {
256 TopoDS_Shape aCurrentShape = shapeGroup->Value(i);
257 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper(FP, aCurrentShape);
258 if ( FP->FindTypedTransient(mapper, STANDARD_TYPE(StepShape_NonManifoldSurfaceShapeRepresentation), aResult) )
263 if ( aResult.IsNull() ) {
265 cout << "\nNew NMSSR created" << endl;
267 aResult = new StepShape_NonManifoldSurfaceShapeRepresentation;
268 isNMSSRCreated = Standard_True;
271 cout << "\nExisting NMSSR is used" << endl;
273 isNMSSRCreated = Standard_False;
280 //=======================================================================
283 //=======================================================================
285 void STEPControl_ActorWrite::SetMode (const STEPControl_StepModelType M)
288 case STEPControl_AsIs : ModeTrans() = 0; break;
289 case STEPControl_ManifoldSolidBrep : ModeTrans() = 3; break;
290 case STEPControl_BrepWithVoids : ModeTrans() = 5; break;
291 case STEPControl_FacetedBrep : ModeTrans() = 1; break;
292 case STEPControl_FacetedBrepAndBrepWithVoids : ModeTrans() = 6; break;
293 case STEPControl_ShellBasedSurfaceModel : ModeTrans() = 2;
294 case STEPControl_GeometricCurveSet : ModeTrans() = 4;
295 case STEPControl_Hybrid : ModeTrans() = 0; break; // PAS IMPLEMENTE !!
300 //=======================================================================
303 //=======================================================================
305 STEPControl_StepModelType STEPControl_ActorWrite::Mode () const
307 switch (themodetrans) {
308 case 0 : return STEPControl_AsIs;
309 case 1 : return STEPControl_FacetedBrep;
310 case 2 : return STEPControl_ShellBasedSurfaceModel;
311 case 3 : return STEPControl_ManifoldSolidBrep;
312 case 4 : return STEPControl_GeometricCurveSet;
313 case 5 : return STEPControl_BrepWithVoids;
314 case 6 : return STEPControl_FacetedBrepAndBrepWithVoids;
317 return STEPControl_AsIs;
320 //=======================================================================
321 //function : SetGroupMode
323 //=======================================================================
325 void STEPControl_ActorWrite::SetGroupMode (const Standard_Integer mode)
327 if (mode >= 0) mygroup = mode;
330 //=======================================================================
331 //function : GroupMode
333 //=======================================================================
335 Standard_Integer STEPControl_ActorWrite::GroupMode () const
340 //=======================================================================
341 //function : SetTolerance
343 //=======================================================================
345 void STEPControl_ActorWrite::SetTolerance (const Standard_Real Tol)
350 //=======================================================================
351 //function : Recognize
352 // ATTENTION, Recognize doit s aligner sur ce que Transfer sait faire
354 //=======================================================================
356 Standard_Boolean STEPControl_ActorWrite::Recognize (const Handle(Transfer_Finder)& start)
358 STEPControl_StepModelType mymode = Mode();
359 Handle(TransferBRep_ShapeMapper) mapper = Handle(TransferBRep_ShapeMapper)::DownCast(start);
360 if (mapper.IsNull()) return Standard_False;
361 if (mymode == STEPControl_AsIs) return Standard_True;
363 Standard_Boolean yasolid = Standard_False, yashell = Standard_False,
364 yaface = Standard_False;
366 TopoDS_Shape theShape, aShape;
367 // theShape = TopoDSToStep::DirectFaces(mapper->Value());
368 theShape = mapper->Value(); // pour une reconnaissance c est bien assez
370 if (theShape.ShapeType() == TopAbs_COMPOUND) {
372 TopExp_Explorer SolidExp, ShellExp, FaceExp;
374 for (SolidExp.Init(theShape, TopAbs_SOLID);
375 SolidExp.More();SolidExp.Next()) yasolid = Standard_True;
376 for (ShellExp.Init(theShape, TopAbs_SHELL, TopAbs_SOLID);
377 ShellExp.More();ShellExp.Next()) yashell = Standard_True;
378 for (FaceExp.Init(theShape, TopAbs_FACE, TopAbs_SHELL);
379 FaceExp.More();FaceExp.Next()) yaface = Standard_True;
381 else if (theShape.ShapeType() == TopAbs_SOLID) yasolid = Standard_True;
382 else if (theShape.ShapeType() == TopAbs_SHELL) yashell = Standard_True;
383 else if (theShape.ShapeType() == TopAbs_FACE) yaface = Standard_True;
384 else if (mymode != STEPControl_GeometricCurveSet) return Standard_False;
387 // Faceted : il est OBLIGATOIRE d avoir des surfaces support Plane et des
388 // courbes 3D Line (pcurves ignorees)
390 if (mymode == STEPControl_FacetedBrep || mymode == STEPControl_FacetedBrepAndBrepWithVoids) {
391 for (TopExp_Explorer ffac(theShape,TopAbs_FACE); ffac.More(); ffac.Next()) {
392 const TopoDS_Face& F = TopoDS::Face (ffac.Current());
393 TopLoc_Location locbid;
394 Handle(Geom_Surface) surf = BRep_Tool::Surface (F,locbid);
395 if (surf.IsNull() || !surf->IsKind(STANDARD_TYPE(Geom_Plane)) ) return Standard_False;
397 for (TopExp_Explorer fedg(theShape,TopAbs_EDGE); fedg.More(); fedg.Next()) {
398 const TopoDS_Edge& E = TopoDS::Edge (fedg.Current());
399 TopLoc_Location locbid; Standard_Real first,last;
400 Handle(Geom_Curve) curv = BRep_Tool::Curve (E,locbid,first,last);
401 if (curv.IsNull() || !curv->IsKind(STANDARD_TYPE(Geom_Line)) ) return Standard_False;
406 case STEPControl_ManifoldSolidBrep: return (yasolid || yashell);
407 case STEPControl_BrepWithVoids:
408 case STEPControl_FacetedBrep:
409 case STEPControl_FacetedBrepAndBrepWithVoids: return yasolid;
410 case STEPControl_ShellBasedSurfaceModel:
411 return (yasolid || yashell || yaface);
412 case STEPControl_GeometricCurveSet: return Standard_True; // tout OK
415 return Standard_False;
419 // ######## MAKE PRODUCT DATA + CONTEXT ########
421 //=======================================================================
422 //function : Transfer
424 //=======================================================================
426 Handle(Transfer_Binder) STEPControl_ActorWrite::Transfer (const Handle(Transfer_Finder)& start,
427 const Handle(Transfer_FinderProcess)& FP)
429 XSAlgo::AlgoContainer()->PrepareForTransfer();
431 Handle(TransferBRep_ShapeMapper) mapper = Handle(TransferBRep_ShapeMapper)::DownCast(start);
433 if (mapper.IsNull()) return NullResult();
434 TopoDS_Shape shape = mapper->Value();
437 Handle(StepData_StepModel) model = Handle(StepData_StepModel)::DownCast ( FP->Model() );
438 if ( ! model.IsNull() ) myContext.SetModel ( model ); //: abv 04.11.00: take APD from model
439 myContext.AddAPD ( Standard_False ); // update APD
440 myContext.SetLevel ( 1 ); // set assembly level to 1 (to ensure)
442 //:S4136: init UnitsMethods to reset angle unit factors (see TopoDSToStep)
443 Standard_Real lFactor = UnitsMethods::GetLengthFactorValue ( Interface_Static::IVal ( "write.step.unit" ) );
444 lFactor /= UnitsMethods::GetCasCadeLengthUnit();
445 Standard_Integer anglemode = Interface_Static::IVal("step.angleunit.mode");
446 UnitsMethods::InitializeFactors ( lFactor, ( anglemode <= 1 ? 1. : M_PI/180. ), 1. );
449 STEPConstruct_Part SDRTool;
450 SDRTool.MakeSDR ( 0, myContext.GetProductName(), myContext.GetAPD()->Application() );
451 Handle(StepShape_ShapeDefinitionRepresentation) sdr = SDRTool.SDRValue();
454 Handle(Transfer_Binder) resbind = TransferShape (mapper,sdr,FP);
456 // Handle(StepShape_ShapeRepresentation) resultat;
457 // FP->GetTypedTransient (resbind,STANDARD_TYPE(StepShape_ShapeRepresentation),resultat);
458 // sdr->SetUsedRepresentation (resultat);
460 // create binder with all root entities produced from shape
461 Handle(TColStd_HSequenceOfTransient) roots = myContext.GetRootsForPart ( SDRTool );
462 Handle(Transfer_Binder) resprod = TransientResult ( myContext.GetAPD() );
463 for ( Standard_Integer i=1; i <= roots->Length(); i++ )
464 resprod->AddResult ( TransientResult ( roots->Value(i) ) );
465 resprod->AddResult(resbind);
468 //FP->Bind (mapper,resprod);
469 myContext.NextIndex();
473 //==========================================
475 static Standard_Real UsedTolerance (const Standard_Real mytoler,
476 const TopoDS_Shape& theShape)
479 // COMPUTING 3D TOLERANCE
480 // Either from Session, or Computed (Least,Average, or Greatest)
481 // Then given to TopoDSToStep_Tool
483 Standard_Real Tol = mytoler;
484 Standard_Integer tolmod = Interface_Static::IVal("write.precision.mode");
485 if (Tol <= 0 && tolmod == 2) Tol =
486 Interface_Static::RVal("write.precision.val");
488 ShapeAnalysis_ShapeTolerance stu;
489 Tol = stu.Tolerance (theShape,tolmod);
490 // Par defaut, on prend une tolerance moyenne, on elimine les aberrations
491 Tol = Interface_MSG::Intervalled (Tol * 1.5); // arrondi a 1 2 5 ...
493 if (Tol == 0) Tol = 1.e-07; // minimum ...
498 //=======================================================================
499 //function : IsAssembly
501 //=======================================================================
502 // if GroupMode is >1 downgrades all compounds having single subshape to that
505 Standard_Boolean STEPControl_ActorWrite::IsAssembly (TopoDS_Shape &S) const
507 if ( ! GroupMode() || S.ShapeType() != TopAbs_COMPOUND ) return Standard_False;
508 // PTV 16.09.2002 OCC725 for storing compound of vertices
509 if (Interface_Static::IVal("write.step.vertex.mode") == 0) {//bug 23950
510 if (S.ShapeType() == TopAbs_COMPOUND ) {
511 Standard_Boolean IsOnlyVertices = Standard_True;
512 TopoDS_Iterator anItr( S );
513 for ( ; anItr.More(); anItr.Next() ) {
514 if ( anItr.Value().ShapeType() != TopAbs_VERTEX ) {
515 IsOnlyVertices = Standard_False;
519 if ( IsOnlyVertices )
520 return Standard_False;
523 if ( GroupMode() ==1 ) return Standard_True;
524 TopoDS_Iterator it ( S );
525 if ( ! it.More() ) return Standard_False;
526 TopoDS_Shape shape = it.Value();
528 if ( it.More() ) return Standard_True;
530 return IsAssembly ( S );
533 //=======================================================================
534 //function : TransferShape
536 //=======================================================================
539 static void UpdateMap (const TopoDS_Shape &shape,
540 BRepTools_Modifier &M1,
541 BRepTools_Modifier &M2,
542 const Handle(Transfer_FinderProcess) &FinderProcess)
544 TopoDS_Shape S = M1.ModifiedShape ( shape );
545 S = M2.ModifiedShape ( S );
546 if ( S == shape ) return;
548 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FinderProcess, S );
549 Handle(Transfer_Binder) binder = FinderProcess->Find ( mapper );
550 if ( ! binder.IsNull() ) {
551 mapper = TransferBRep::ShapeMapper ( FinderProcess, shape );
552 FinderProcess->Bind ( mapper, binder );
555 for ( TopoDS_Iterator it(shape); it.More(); it.Next() )
556 UpdateMap ( it.Value(), M1, M2, FinderProcess );
560 // PTV 16.09.2002 added for transfering vertices.
561 static Standard_Boolean transferVertex (const Handle(Transfer_FinderProcess)& FP,
562 Handle(StepShape_HArray1OfGeometricSetSelect)& aGSS,
563 const TopoDS_Shape& aShVrtx,
564 const Standard_Integer theNum)
566 Standard_Boolean IsDone = Standard_False;
567 MoniTool_DataMapOfShapeTransient aMap;
568 TopoDSToStep_Tool aTool(aMap, Standard_True);
569 TopoDSToStep_MakeStepVertex aMkVrtx ( TopoDS::Vertex(aShVrtx), aTool, FP );
571 if (!aMkVrtx.IsDone())
574 Handle(StepShape_VertexPoint) aVP =
575 Handle(StepShape_VertexPoint)::DownCast(aTool.Find(aShVrtx));
579 StepShape_GeometricSetSelect select;
580 select.SetValue(aVP->VertexGeometry());
581 // add current result
582 aGSS->SetValue( theNum, select );
583 IsDone = Standard_True;
588 Handle(Transfer_Binder) STEPControl_ActorWrite::TransferShape (const Handle(Transfer_Finder)& start,
589 const Handle(StepShape_ShapeDefinitionRepresentation)& SDR0,
590 const Handle(Transfer_FinderProcess)& FP,
591 const Handle(TopTools_HSequenceOfShape)& shapeGroup,
592 const Standard_Boolean isManifold)
594 STEPControl_StepModelType mymode = Mode();
595 Handle(TransferBRep_ShapeMapper) mapper = Handle(TransferBRep_ShapeMapper)::DownCast(start);
596 Handle(Transfer_Binder) binder;
598 // Indicates whether to use an exising NMSSR to write items to (ss; 13.11.2010)
599 Standard_Boolean useExistingNMSSR = Standard_False;
601 if (mapper.IsNull()) return binder;
602 TopoDS_Shape theShape = mapper->Value();
604 if (theShape.IsNull()) return binder;
606 // INDIVIDUAL SHAPE ALREADY TRANSFERRED : RETURN IT !
607 binder = FP->Find(start);
608 if (!binder.IsNull()) { if (!binder->HasResult()) binder.Nullify(); }
609 if (!binder.IsNull()) {
610 //:abv 20.05.02: writing box & face from it (shared) in one compound
611 // as assembly - while face already translated, it should be
612 // re-translated to break sharing
614 cout << "Warning: STEPControl_ActorWrite::TransferShape(): shape already translated" << endl;
619 // MODE ASSEMBLY : if Compound, (sub-)assembly
620 if ( IsAssembly(theShape) )
621 return TransferCompound(start, SDR0, FP);
623 // [BEGIN] Separate manifold topology from non-manifold in group mode 0 (ssv; 18.11.2010)
624 Standard_Boolean isNMMode = Interface_Static::IVal("write.step.nonmanifold");
625 Handle(Transfer_Binder) aNMBinder;
626 if (isNMMode && !GroupMode() && theShape.ShapeType() == TopAbs_COMPOUND) {
627 TopoDS_Compound aNMCompound;
628 TopoDS_Compound aManifoldCompound;
629 BRep_Builder brepBuilder;
631 // Create empty Compounds
632 brepBuilder.MakeCompound(aManifoldCompound);
633 brepBuilder.MakeCompound(aNMCompound);
635 // Indicates whether there is only non-manifold topology detected
636 // (there is no manifold topology found in the Compound passed)
637 Standard_Boolean isOnlyNonManifold = Standard_False;
639 // Find a Compound containing non-manifold topology.
640 // NOTE: only one such Compound must exist in the entire Compound passed
641 if ( !IsManifoldShape(theShape) ) {
642 aNMCompound = TopoDS::Compound(theShape);
643 isOnlyNonManifold = Standard_True;
646 TopTools_ListOfShape aListOfShapes;
647 TopTools_ListOfShape aListOfManifoldShapes;
648 aListOfShapes.Append(theShape);
650 TopTools_ListIteratorOfListOfShape itL(aListOfShapes);
651 for ( ; itL.More(); itL.Next() ) {
652 TopoDS_Shape aParentShape = itL.Value();
653 TopoDS_Iterator it(aParentShape);
654 for ( ; it.More(); it.Next() ) {
655 TopoDS_Shape aSubShape = it.Value();
656 if (aSubShape.ShapeType() == TopAbs_COMPOUND && !IsManifoldShape(aSubShape) )
657 aNMCompound = TopoDS::Compound(aSubShape);
658 else if (aSubShape.ShapeType() == TopAbs_COMPOUND)
659 aListOfShapes.Append(aSubShape);
661 aListOfManifoldShapes.Append(aSubShape);
665 // Group manifold topology together.
666 // NOTE: there is no sense that initial Compound structure was lost as
667 // group mode is set to 0 (no Assemblies are mapped)
668 for ( itL.Initialize(aListOfManifoldShapes); itL.More(); itL.Next() ) {
669 TopoDS_Shape aCurrentManiShape = itL.Value();
670 brepBuilder.Add(aManifoldCompound, aCurrentManiShape);
675 // Process only manifold topology in the current TransferShape invocation.
676 // Invoke TransferShape for non-manifold topology separately (see below)
677 theShape = aManifoldCompound;
679 // List of items to transfer
680 Handle(TopTools_HSequenceOfShape) RepItemSeq = new TopTools_HSequenceOfShape();
681 // Non-manifold group to pass into TransferShape with each shape from RepItemSeq
682 Handle(TopTools_HSequenceOfShape) NonManifoldGroup = new TopTools_HSequenceOfShape();
684 // Transfer Solids to closed Shells. Prepare RepItemSeq & NonManifoldGroup
685 for ( TopoDS_Iterator iter(aNMCompound); iter.More(); iter.Next() ) {
686 TopoDS_Shape aSubShape = iter.Value();
687 if (aSubShape.ShapeType() == TopAbs_SOLID) {
688 for ( TopoDS_Iterator aSubIter(aSubShape); aSubIter.More(); aSubIter.Next() ) {
689 TopoDS_Shell aSubShell = TopoDS::Shell( aSubIter.Value() );
690 aSubShell.Closed(Standard_True);
691 RepItemSeq->Append(aSubShell);
692 NonManifoldGroup->Append(aSubShell);
695 else if (!isManifold && (aSubShape.ShapeType() == TopAbs_SHELL) ) {
696 RepItemSeq->Append(aSubShape);
697 NonManifoldGroup->Append(aSubShape);
700 RepItemSeq->Append( iter.Value() );
703 Standard_Integer aNMItemsNb = RepItemSeq->Length();
705 // In case of pure manifold topology do nothing; theShape is processed as usual (see below)
706 if (aNMItemsNb > 0) {
708 // Prepare SDR for non-manifold group. This SDR will be linked to NMSSR by means
709 // of TransferShape invocation. SDR is not created if there is no any manifold
710 // topology in the passed Compound. If topology is pure non-manifold, SDR0 (passed)
712 Handle(StepShape_ShapeDefinitionRepresentation) sdr;
713 if (isOnlyNonManifold)
716 STEPConstruct_Part SDRTool;
717 SDRTool.MakeSDR( 0, myContext.GetProductName(), myContext.GetAPD()->Application() );
718 sdr = SDRTool.SDRValue();
721 aNMBinder = TransientResult(sdr);
723 // Complete SDR with shape representations.
724 // NOTE: aNMBinder is connected now with this SDR. It will be added to the resulting
725 // binder in the end of this invocation of TransferShape
726 for (Standard_Integer i = 1; i <= aNMItemsNb; i++) {
727 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper( FP, RepItemSeq->Value(i) );
728 TransferShape(mapper, sdr, FP, NonManifoldGroup, Standard_False);
731 // Nothing else needed for pure non-manifold topology, return
732 if (isOnlyNonManifold)
738 // [END] Separate manifold topology from non-manifold in group mode 0 (ssv; 18.11.2010)
740 // create a list of items to translate
741 Handle(TopTools_HSequenceOfShape) RepItemSeq = new TopTools_HSequenceOfShape();
743 Standard_Boolean isSeparateVertices =
744 Interface_Static::IVal("write.step.vertex.mode") == 0;//bug 23950
745 // PTV 16.09.2002 OCC725 separate shape from solo vertices.
746 Standard_Boolean isOnlyVertices = Standard_False;
747 if (theShape.ShapeType() == TopAbs_COMPOUND) {
748 Standard_Integer countVrtx = 0;
749 Standard_Integer countSh = 0;
750 TopoDS_Compound aNewShape, aCompOfVrtx;
752 aB.MakeCompound(aNewShape);
753 aB.MakeCompound(aCompOfVrtx);
754 TopoDS_Iterator anCompIt(theShape);
755 if (isSeparateVertices) {
756 for (; anCompIt.More(); anCompIt.Next()) {
757 TopoDS_Shape aCurSh = anCompIt.Value();
758 if (aCurSh.ShapeType() != TopAbs_VERTEX) {
759 aB.Add(aNewShape, aCurSh);
763 aB.Add(aCompOfVrtx, aCurSh);
767 // replace the shapes
769 theShape = aNewShape;
771 RepItemSeq->Append(aCompOfVrtx);
773 isOnlyVertices = Standard_True;
777 if (theShape.ShapeType() == TopAbs_COMPOUND) {
778 TopExp_Explorer SolidExp, ShellExp, FaceExp;
779 if (mymode != STEPControl_GeometricCurveSet) {
780 for (SolidExp.Init(theShape, TopAbs_SOLID);
781 SolidExp.More();SolidExp.Next()) {
782 RepItemSeq->Append(TopoDS::Solid(SolidExp.Current()));
784 for (ShellExp.Init(theShape, TopAbs_SHELL, TopAbs_SOLID);
785 ShellExp.More();ShellExp.Next()) {
786 RepItemSeq->Append(TopoDS::Shell(ShellExp.Current()));
789 for (FaceExp.Init(theShape, TopAbs_FACE, TopAbs_SHELL);
790 FaceExp.More();FaceExp.Next()) {
791 RepItemSeq->Append(TopoDS::Face(FaceExp.Current()));
796 RepItemSeq->Append(theShape); //:j1
798 if(mymode == STEPControl_AsIs) {
799 TopExp_Explorer WireExp, EdgeExp;
800 for (WireExp.Init(theShape, TopAbs_WIRE, TopAbs_FACE);
801 WireExp.More();WireExp.Next())
802 RepItemSeq->Append(TopoDS::Wire(WireExp.Current()));
803 for (EdgeExp.Init(theShape, TopAbs_EDGE, TopAbs_WIRE);
804 EdgeExp.More();EdgeExp.Next())
805 RepItemSeq->Append(TopoDS::Edge(EdgeExp.Current()));
809 else if (theShape.ShapeType() == TopAbs_SOLID) {
810 RepItemSeq->Append(TopoDS::Solid(theShape));
812 else if (theShape.ShapeType() == TopAbs_SHELL) {
813 RepItemSeq->Append(TopoDS::Shell(theShape));
815 else if (theShape.ShapeType() == TopAbs_FACE) {
816 RepItemSeq->Append(TopoDS::Face(theShape));
818 else if (theShape.ShapeType() == TopAbs_COMPSOLID) {
819 FP->AddWarning(start,"NonManifold COMPSOLID was translated like a set of SOLIDs");
820 if ( GroupMode() > 0)
821 return TransferCompound(start, SDR0, FP);
823 TopExp_Explorer SolidExp;
824 for (SolidExp.Init(theShape, TopAbs_SOLID);
825 SolidExp.More();SolidExp.Next()) {
826 RepItemSeq->Append(TopoDS::Solid(SolidExp.Current()));
831 else if (mymode != STEPControl_GeometricCurveSet && mymode != STEPControl_AsIs) {
832 FP->AddFail(start,"The Shape is not a SOLID, nor a SHELL, nor a FACE");
835 else RepItemSeq->Append (theShape);
837 // COMPUTING 3D TOLERANCE
838 // Either from Session, or Computed (Least,Average, or Greatest)
839 // Then given to TopoDSToStep_Tool
840 Standard_Real Tol = UsedTolerance (mytoler,theShape);
842 // Create a STEP-Entity for each TopoDS_Shape
843 // according to the current StepModelMode
845 Standard_Integer nbs = RepItemSeq->Length();
846 Handle(TColStd_HSequenceOfTransient) ItemSeq =
847 new TColStd_HSequenceOfTransient();
849 //ptv 10.11.00: allow to write empty Compound: if (GroupMode() >0)
850 ItemSeq->Append (myContext.GetDefaultAxis());
851 STEPControl_StepModelType trmode = mymode;
852 for (Standard_Integer i = 1; i <= nbs; i++) {
853 TopoDS_Shape xShape = RepItemSeq->Value(i);
855 if(mymode == STEPControl_AsIs) {
856 switch(xShape.ShapeType()) {
857 case TopAbs_SOLID : trmode = STEPControl_ManifoldSolidBrep;break;
858 case TopAbs_SHELL : trmode = STEPControl_ShellBasedSurfaceModel; break;
859 case TopAbs_FACE : trmode = STEPControl_ShellBasedSurfaceModel;break;
860 default : trmode =STEPControl_GeometricCurveSet; break;
863 //:abv 24Jan99 CAX-IF TRJ3: expanded Shape Processing
864 // TopoDS_Shape aShape = xShape;
865 // eliminate conical surfaces with negative semiangles
866 // Handle(TopoDSToStep_ConicalSurfModif) CSM = new TopoDSToStep_ConicalSurfModif();
867 // BRepTools_Modifier CSMT(aShape,CSM);
868 // if ( CSMT.IsDone() ) aShape = CSMT.ModifiedShape ( aShape );
869 // // eliminate indirect elementary surfaces
870 // Handle(TopoDSToStep_DirectModification) DM = new TopoDSToStep_DirectModification();
871 // BRepTools_Modifier DMT(aShape,DM);
872 // if ( DMT.IsDone() ) aShape = DMT.ModifiedShape ( aShape );
873 //// aShape = TopoDSToStep::DirectFaces(xShape);
874 Handle(Standard_Transient) info;
875 Standard_Real maxTol = Interface_Static::RVal("read.maxprecision.val");
877 // Fix only manifold shapes, do nothing with non-manifold topology as it is processed separately (ssv; 13.11.2010)
880 aShape = XSAlgo::AlgoContainer()->ProcessShape(xShape, Tol, maxTol,
881 "write.step.resource.name",
882 "write.step.sequence", info,
887 // create a STEP entity corresponding to shape
888 Handle(StepGeom_GeometricRepresentationItem) item;
891 case STEPControl_ManifoldSolidBrep:
893 if (aShape.ShapeType() == TopAbs_SOLID) {
894 TopoDS_Solid aSolid = TopoDS::Solid(aShape);
896 //:d6 abv 13 Mar 98: if solid has more than 1 shell,
897 // try to treat it as solid with voids
898 Standard_Integer nbShells = 0;
899 for ( TopoDS_Iterator It ( aSolid ); It.More(); It.Next() )
900 if (It.Value().ShapeType() == TopAbs_SHELL) nbShells++;
902 TopoDSToStep_MakeBrepWithVoids MkBRepWithVoids(aSolid,FP);
903 MkBRepWithVoids.Tolerance() = Tol;
904 if (MkBRepWithVoids.IsDone()) {
905 item = MkBRepWithVoids.Value();
907 else nbShells = 1; //smth went wrong; let it will be just Manifold
909 if ( nbShells ==1 ) {
911 TopoDSToStep_MakeManifoldSolidBrep MkManifoldSolidBrep(aSolid,FP);
912 MkManifoldSolidBrep.Tolerance() = Tol;
913 if (MkManifoldSolidBrep.IsDone()) {
914 item = MkManifoldSolidBrep.Value();
918 else if (aShape.ShapeType() == TopAbs_SHELL) {
919 TopoDS_Shell aShell = TopoDS::Shell(aShape);
920 TopoDSToStep_MakeManifoldSolidBrep MkManifoldSolidBrep(aShell,FP);
921 MkManifoldSolidBrep.Tolerance() = Tol;
922 if (MkManifoldSolidBrep.IsDone()) {
923 item = MkManifoldSolidBrep.Value();
928 case STEPControl_BrepWithVoids:
930 if (aShape.ShapeType() == TopAbs_SOLID) {
931 TopoDS_Solid aSolid = TopoDS::Solid(aShape);
932 TopoDSToStep_MakeBrepWithVoids MkBRepWithVoids(aSolid,FP);
933 MkBRepWithVoids.Tolerance() = Tol;
934 if (MkBRepWithVoids.IsDone()) {
935 item = MkBRepWithVoids.Value();
940 case STEPControl_FacetedBrep:
942 TopoDSToStep_FacetedError facErr = TopoDSToStep_FacetedTool::CheckTopoDSShape(aShape);
943 if (facErr != TopoDSToStep_FacetedDone) {
944 FP->AddFail(start,"Error in Faceted Shape from TopoDS");
945 if (facErr == TopoDSToStep_SurfaceNotPlane) {
946 FP->AddFail(start,"-- The TopoDS_Face is not plane");
948 else if (facErr == TopoDSToStep_PCurveNotLinear) {
949 FP->AddFail(start,"-- The Face contains non linear PCurves");
953 if (aShape.ShapeType() == TopAbs_SOLID) {
954 TopoDS_Solid aSolid = TopoDS::Solid(aShape);
955 TopoDSToStep_MakeFacetedBrep MkFacetedBrep(aSolid,FP);
956 MkFacetedBrep.Tolerance() = Tol;
957 if (MkFacetedBrep.IsDone()) {
958 item = MkFacetedBrep.Value();
963 case STEPControl_FacetedBrepAndBrepWithVoids:
965 TopoDSToStep_FacetedError facErr = TopoDSToStep_FacetedTool::CheckTopoDSShape(aShape);
966 if (facErr != TopoDSToStep_FacetedDone) {
967 FP->AddFail(start,"Error in Faceted Shape from TopoDS");
968 if (facErr == TopoDSToStep_SurfaceNotPlane) {
969 FP->AddFail(start,"-- The TopoDS_Face is not plane");
971 else if (facErr == TopoDSToStep_PCurveNotLinear) {
972 FP->AddFail(start,"-- The Face contains non linear PCurves");
976 if (aShape.ShapeType() == TopAbs_SOLID) {
977 TopoDS_Solid aSolid = TopoDS::Solid(aShape);
978 TopoDSToStep_MakeFacetedBrepAndBrepWithVoids
979 MkFacetedBrepAndBrepWithVoids(aSolid,FP);
980 MkFacetedBrepAndBrepWithVoids.Tolerance() = Tol;
981 if (MkFacetedBrepAndBrepWithVoids.IsDone()) {
982 item = MkFacetedBrepAndBrepWithVoids.Value();
987 case STEPControl_ShellBasedSurfaceModel:
989 if (aShape.ShapeType() == TopAbs_SOLID) {
990 TopoDS_Solid aSolid = TopoDS::Solid(aShape);
991 TopoDSToStep_MakeShellBasedSurfaceModel
992 MkShellBasedSurfaceModel(aSolid, FP);
993 MkShellBasedSurfaceModel.Tolerance() = Tol;
994 if (MkShellBasedSurfaceModel.IsDone()) {
995 item = MkShellBasedSurfaceModel.Value();
998 else if (aShape.ShapeType() == TopAbs_SHELL) {
999 TopoDS_Shell aShell = TopoDS::Shell(aShape);
1000 // Non-manifold topology is stored via NMSSR containing series of SBSM (ssv; 13.11.2010)
1001 TopoDSToStep_MakeShellBasedSurfaceModel MkShellBasedSurfaceModel(aShell, FP);
1002 MkShellBasedSurfaceModel.Tolerance() = Tol;
1003 if (MkShellBasedSurfaceModel.IsDone()) {
1004 item = MkShellBasedSurfaceModel.Value();
1007 else if (aShape.ShapeType() == TopAbs_FACE) {
1008 TopoDS_Face aFace = TopoDS::Face(aShape);
1009 TopoDSToStep_MakeShellBasedSurfaceModel
1010 MkShellBasedSurfaceModel(aFace, FP);
1011 MkShellBasedSurfaceModel.Tolerance() = Tol;
1012 if (MkShellBasedSurfaceModel.IsDone()) {
1013 item = MkShellBasedSurfaceModel.Value();
1018 case STEPControl_GeometricCurveSet:
1020 TopoDSToStep_MakeGeometricCurveSet MkGeometricCurveSet(aShape,FP);
1021 MkGeometricCurveSet.Tolerance() = Tol;
1022 if (MkGeometricCurveSet.IsDone()) {
1023 item = MkGeometricCurveSet.Value();
1025 // PTV 22.08.2002 OCC609 ------------------------- begin --------------------
1026 // modified by PTV 16.09.2002 OCC725
1027 else if (aShape.ShapeType() == TopAbs_COMPOUND ||
1028 aShape.ShapeType() == TopAbs_VERTEX) {
1029 // it is compund with solo vertices.
1030 Standard_Integer aNbVrtx = 0;
1031 Standard_Integer curNb = 0;
1032 TopExp_Explorer anExp (aShape, TopAbs_VERTEX);
1033 for ( ; anExp.More(); anExp.Next() ) {
1034 if ( anExp.Current().ShapeType() != TopAbs_VERTEX )
1039 // create new geometric curve set for all vertices
1040 Handle(StepShape_HArray1OfGeometricSetSelect) aGSS =
1041 new StepShape_HArray1OfGeometricSetSelect(1,aNbVrtx);
1042 Handle(TCollection_HAsciiString) empty = new TCollection_HAsciiString("");
1043 Handle(StepShape_GeometricCurveSet) aGCSet =
1044 new StepShape_GeometricCurveSet;
1045 aGCSet->SetName(empty);
1046 // iterates on compound with vertices and trances each vertex
1047 for ( anExp.ReInit() ; anExp.More(); anExp.Next() ) {
1048 TopoDS_Shape aVertex = anExp.Current();
1049 if ( aVertex.ShapeType() != TopAbs_VERTEX )
1052 transferVertex (FP, aGSS, aVertex, curNb);
1053 } // end of iteration on compound with vertices.
1054 aGCSet->SetElements(aGSS);
1056 } // end of check that number of vertices is not null
1058 // PTV 22.08.2002 OCC609------------------------- end --------------------
1063 if ( item.IsNull() ) continue;
1065 // add resulting item to the FP
1066 ItemSeq->Append(item);
1067 Handle(TransferBRep_ShapeMapper) submapper;
1068 if ( xShape.IsSame ( mapper->Value() ) )
1069 submapper = Handle(TransferBRep_ShapeMapper)::DownCast ( start );
1070 if ( submapper.IsNull() ) submapper = TransferBRep::ShapeMapper (FP,xShape);
1071 Handle(Transfer_Binder) subbind = FP->Find ( submapper );
1072 if ( subbind.IsNull() ) {
1073 subbind = TransientResult ( item );
1074 FP->Bind ( submapper, subbind );
1076 else subbind->AddResult ( TransientResult ( item ) );
1078 //:abv 24Jan99 CAX-IF TRJ3: Update FinderProcess map to take into account shape processing
1079 // UpdateMap ( xShape, CSMT, DMT, FP );
1080 XSAlgo::AlgoContainer()->MergeTransferInfo(FP, info);
1083 // - Make Shape Representation
1084 Standard_Integer nCc1 = ItemSeq->Length();
1086 FP->AddFail(start,"The Shape has not the appropriate type");
1089 Handle(StepShape_ShapeRepresentation) shapeRep;
1090 if ( theShape.ShapeType() == TopAbs_SHAPE ) { // for external references
1091 shapeRep = new StepShape_ShapeRepresentation;
1095 case STEPControl_ManifoldSolidBrep:
1096 shapeRep = new StepShape_AdvancedBrepShapeRepresentation;
1098 case STEPControl_FacetedBrep:
1099 shapeRep = new StepShape_FacetedBrepShapeRepresentation;
1101 // NOTE: STEPControl_AsIs mode is normally used to transfer non-manifold topology.
1102 // However, as ShellBasedSurfaceModel is used in non-manifold processing
1103 // internally, STEPControl_ShellBasedSurfaceModel is also adjusted to
1104 // be able to work with non-manifold cases
1105 case STEPControl_ShellBasedSurfaceModel:
1107 shapeRep = new StepShape_ManifoldSurfaceShapeRepresentation;
1109 Standard_Boolean isNewNMSSRCreated;
1110 shapeRep = this->getNMSSRForGroup(shapeGroup, FP, isNewNMSSRCreated);
1111 useExistingNMSSR = !isNewNMSSRCreated;
1114 case STEPControl_GeometricCurveSet:
1115 shapeRep = new StepShape_GeometricallyBoundedWireframeShapeRepresentation;
1117 case STEPControl_AsIs :
1120 if(trmode == STEPControl_ManifoldSolidBrep)
1121 shapeRep = new StepShape_AdvancedBrepShapeRepresentation;
1122 else if(trmode == STEPControl_ShellBasedSurfaceModel)
1123 // Process non-manifold topology separately (ssv; 13.11.2010)
1125 shapeRep = new StepShape_ManifoldSurfaceShapeRepresentation;
1127 Standard_Boolean isNewNMSSRCreated;
1128 shapeRep = this->getNMSSRForGroup(shapeGroup, FP, isNewNMSSRCreated);
1129 useExistingNMSSR = !isNewNMSSRCreated;
1131 else if(trmode == STEPControl_GeometricCurveSet)
1132 shapeRep = new StepShape_GeometricallyBoundedWireframeShapeRepresentation;
1133 else if(trmode ==STEPControl_FacetedBrep)
1134 shapeRep = new StepShape_FacetedBrepShapeRepresentation;
1136 else shapeRep = new StepShape_ShapeRepresentation;
1142 if(shapeRep.IsNull()) {
1143 Handle(Transfer_Binder) resb;
1147 Handle(StepRepr_HArray1OfRepresentationItem) items =
1148 new StepRepr_HArray1OfRepresentationItem(1,nCc1);
1150 for (Standard_Integer rep = 1; rep <= nCc1; rep++) {
1151 Handle(StepRepr_RepresentationItem) repit =
1152 GetCasted(StepRepr_RepresentationItem, ItemSeq->Value(rep));
1153 items->SetValue(rep,repit);
1155 Standard_Integer ap = Interface_Static::IVal("write.step.schema");
1156 Transfer_SequenceOfBinder aSeqBindRelation;
1157 if(ap == 3 && nbs > 1) {
1158 Standard_Integer j = 1;
1159 if(items->Value(j)->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d))) {
1160 Handle(StepRepr_HArray1OfRepresentationItem) axis =
1161 new StepRepr_HArray1OfRepresentationItem(1,1);
1162 axis->SetValue(1,items->Value(j++));
1163 shapeRep->SetItems(axis);
1165 for (; j <= items->Length(); j++) {
1167 Handle(StepShape_ShapeRepresentation) ShapeRepr1;
1168 if(items->Value(j)->IsKind(STANDARD_TYPE(StepShape_ManifoldSolidBrep)))
1169 ShapeRepr1 = new StepShape_AdvancedBrepShapeRepresentation;
1170 else if(items->Value(j)->IsKind(STANDARD_TYPE(StepShape_ShellBasedSurfaceModel)))
1171 ShapeRepr1 = new StepShape_ManifoldSurfaceShapeRepresentation;
1172 else if(items->Value(j)->IsKind(STANDARD_TYPE(StepShape_GeometricCurveSet)))
1173 ShapeRepr1 = new StepShape_GeometricallyBoundedWireframeShapeRepresentation;
1174 else if (items->Value(j)->IsKind(STANDARD_TYPE(StepShape_FacetedBrep)))
1175 ShapeRepr1 = new StepShape_FacetedBrepShapeRepresentation;
1176 else ShapeRepr1 = new StepShape_ShapeRepresentation;
1178 Handle(StepRepr_HArray1OfRepresentationItem) repr1 = new StepRepr_HArray1OfRepresentationItem(1,2);
1179 repr1->SetValue(1,myContext.GetDefaultAxis());
1180 repr1->SetValue(2,items->Value(j));
1181 ShapeRepr1->SetItems(repr1);
1182 STEPConstruct_UnitContext mk1;
1184 ShapeRepr1->SetContextOfItems(mk1.Value()); // la tolerance, voir au debut
1185 ShapeRepr1->SetName (new TCollection_HAsciiString(""));
1187 Handle(StepRepr_ShapeRepresentationRelationship) aShapeRel = new StepRepr_ShapeRepresentationRelationship;
1188 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString("");
1189 Handle(TCollection_HAsciiString) aDescr = new TCollection_HAsciiString("");
1190 aShapeRel->SetName(aName);
1191 aShapeRel->SetDescription(aDescr);
1192 aShapeRel->SetRep2(shapeRep);
1193 aShapeRel->SetRep1(ShapeRepr1);
1195 aSeqBindRelation.Append(TransientResult (aShapeRel));
1199 if (!useExistingNMSSR)
1200 shapeRep->SetItems(items);
1202 // Add new representation item to the NMSSR's existing collection (ssv; 13.11.2010)
1203 Handle(StepRepr_HArray1OfRepresentationItem) oldItems = shapeRep->Items();
1204 Handle(StepRepr_HArray1OfRepresentationItem) newItems =
1205 new StepRepr_HArray1OfRepresentationItem(1, oldItems->Length() + 1);
1206 Standard_Integer el = 1;
1207 for (Standard_Integer i = 1; i <= oldItems->Length(); i++)
1208 newItems->SetValue( el++, oldItems->Value(i) );
1209 newItems->SetValue( el, items->Value( items->Length() ) );
1210 shapeRep->SetItems(newItems);
1214 // init representation
1215 STEPConstruct_UnitContext mk;
1217 shapeRep->SetContextOfItems(mk.Value()); // la tolerance, voir au debut
1218 shapeRep->SetName (new TCollection_HAsciiString(""));
1220 // Create SDR (only once for non-manifold group)
1221 if (!useExistingNMSSR) {
1222 SDR0->SetUsedRepresentation (shapeRep);
1223 // create binder for SR and attach to it binder for RepItem (if exists)
1224 Handle(Transfer_Binder) resbind = TransientResult(shapeRep);
1225 binder = FP->Find(start);
1226 if ( ! binder.IsNull() ) {
1227 resbind->AddResult ( binder );
1228 FP->Rebind(start,resbind);
1229 //binder->AddResult ( resbind );
1232 for(Standard_Integer k = 1; k <= aSeqBindRelation.Length(); k++)
1233 resbind->AddResult(aSeqBindRelation.Value(k));
1235 // Add SDR for non-manifold topology in group mode 0 (ssv; 18.11.2010)
1236 if ( !aNMBinder.IsNull() )
1237 resbind->AddResult(aNMBinder);
1240 } else return FP->Find(start);
1244 //=======================================================================
1245 //function : TransferCompound
1246 // #### TRANSFER COMPOUND AS (SUB-)ASSEMBLY
1248 //=======================================================================
1250 Handle(Transfer_Binder) STEPControl_ActorWrite::TransferCompound (const Handle(Transfer_Finder)& start,
1251 const Handle(StepShape_ShapeDefinitionRepresentation)& SDR0,
1252 const Handle(Transfer_FinderProcess)& FP)
1254 Handle(TransferBRep_ShapeMapper) mapper = Handle(TransferBRep_ShapeMapper)::DownCast(start);
1255 Handle(Transfer_Binder) binder;
1256 if (mapper.IsNull()) return binder;
1257 TopoDS_Shape theShape = mapper->Value();
1259 // Inspect non-manifold topology case (ssv; 10.11.2010)
1260 Standard_Boolean isNMMode = Interface_Static::IVal("write.step.nonmanifold");
1261 Standard_Boolean isManifold;
1263 isManifold = IsManifoldShape(theShape);
1265 isManifold = Standard_True;
1267 // get a sequence of components (subshapes)
1268 Handle(TopTools_HSequenceOfShape) RepItemSeq = new TopTools_HSequenceOfShape();
1269 // Prepare a collection for non-manifold group of shapes
1270 Handle(TopTools_HSequenceOfShape) NonManifoldGroup = new TopTools_HSequenceOfShape();
1271 Standard_Boolean isSeparateVertices =
1272 (Interface_Static::IVal("write.step.vertex.mode") == 0);//bug 23950
1273 // PTV OCC725 17.09.2002 -- begin --
1274 Standard_Integer nbFreeVrtx = 0;
1275 TopoDS_Compound aCompOfVrtx;
1277 aB.MakeCompound(aCompOfVrtx);
1281 cout << "Exploding Solids to Shells if any..." << endl;
1284 for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) {
1285 TopoDS_Shape aSubShape = iter.Value();
1286 if (aSubShape.ShapeType() != TopAbs_VERTEX || !isSeparateVertices) {
1288 // Store non-manifold topology as shells (ssv; 10.11.2010)
1289 if (!isManifold && aSubShape.ShapeType() == TopAbs_SOLID) {
1290 for ( TopoDS_Iterator aSubIter(aSubShape); aSubIter.More(); aSubIter.Next() ) {
1291 TopoDS_Shell aSubShell = TopoDS::Shell( aSubIter.Value() );
1292 aSubShell.Closed(Standard_True);
1293 RepItemSeq->Append(aSubShell);
1294 NonManifoldGroup->Append(aSubShell);
1297 else if (!isManifold && (aSubShape.ShapeType() == TopAbs_SHELL) ) {
1298 RepItemSeq->Append(aSubShape);
1299 NonManifoldGroup->Append(aSubShape);
1302 RepItemSeq->Append(aSubShape);
1306 aB.Add(aCompOfVrtx, iter.Value());
1310 RepItemSeq->Append (aCompOfVrtx);
1312 // PTV OCC725 17.09.2002 -- end --
1314 // Constitution : liste d axes, le premier est l origine, les suivants : 1
1316 Handle(StepShape_ShapeRepresentation) shapeRep =
1317 Handle(StepShape_ShapeRepresentation)::DownCast(SDR0->UsedRepresentation());
1318 if ( shapeRep.IsNull() ) {
1319 shapeRep = new StepShape_ShapeRepresentation;
1320 SDR0->SetUsedRepresentation(shapeRep); // to be used by MakeItem
1322 binder = TransientResult(SDR0); // set SDR as first item in order to be found first (but not SDR of subshape!)
1323 binder->AddResult ( TransientResult(shapeRep) );
1325 // translate components
1326 Standard_Integer i, nbs = RepItemSeq->Length();
1327 Handle(TColStd_HSequenceOfTransient) ItemSeq = new TColStd_HSequenceOfTransient();
1328 ItemSeq->Append (myContext.GetDefaultAxis());
1329 myContext.NextLevel();
1330 for ( i = 1; i <= nbs; i ++) {
1331 Handle(TransferBRep_ShapeMapper) subs = TransferBRep::ShapeMapper (FP,RepItemSeq->Value(i));
1332 Handle(StepGeom_Axis2Placement3d) AX1;
1334 Handle(Transfer_Binder) bnd = TransferSubShape(subs, SDR0, AX1, FP, NonManifoldGroup, isManifold);
1336 if (!AX1.IsNull()) ItemSeq->Append (AX1);
1337 // copy binders so as to have all roots in upper binder, but do not conflict
1338 while ( !bnd.IsNull() ) {
1339 Handle(Transfer_SimpleBinderOfTransient) bx =
1340 Handle(Transfer_SimpleBinderOfTransient)::DownCast(bnd);
1341 if ( !bx.IsNull() ) {
1342 // Single SDR is created for a non-manifold group (ssv: 12.11.2010)
1343 if (!isManifold && i > 1)
1346 binder->AddResult( TransientResult( bx->Result() ) );
1348 bnd = bnd->NextResult();
1351 myContext.PrevLevel();
1353 Standard_Integer nsub = ItemSeq->Length();
1354 Handle(StepRepr_HArray1OfRepresentationItem) items =
1355 new StepRepr_HArray1OfRepresentationItem(1,nsub);
1357 // initialize representation
1358 for (Standard_Integer rep = 1; rep <= nsub; rep++)
1359 items->SetValue(rep,GetCasted(StepRepr_RepresentationItem, ItemSeq->Value(rep)));
1360 shapeRep->SetItems(items);
1361 Standard_Real Tol = UsedTolerance (mytoler,theShape);
1362 STEPConstruct_UnitContext mk;
1364 shapeRep->SetContextOfItems(mk.Value()); // la tolerance, voir au debut
1365 shapeRep->SetName (new TCollection_HAsciiString(""));
1368 // SDR0->SetUsedRepresentation (shapeRep);
1373 //=======================================================================
1374 //function : TransferSubShape
1376 //=======================================================================
1378 Handle(Transfer_Binder) STEPControl_ActorWrite::TransferSubShape (const Handle(Transfer_Finder)& start,
1379 const Handle(StepShape_ShapeDefinitionRepresentation)& SDR0,
1380 Handle(StepGeom_Axis2Placement3d)& AX1,
1381 const Handle(Transfer_FinderProcess)& FP,
1382 const Handle(TopTools_HSequenceOfShape)& shapeGroup,
1383 const Standard_Boolean isManifold)
1385 Handle(TransferBRep_ShapeMapper) mapper = Handle(TransferBRep_ShapeMapper)::DownCast(start);
1386 if (mapper.IsNull()) return NullResult();
1387 TopoDS_Shape shape = mapper->Value();
1389 // SHAPE EN POSITION VENANT D UN ASSEMBLAGE
1390 // Il faut alors distinguer la transformation de la shape meme
1391 // laquelle est consideree a l origine, puis transferee
1392 // A part, un item decrivant une occurence en position est cree
1393 // SINON, la shape est prise et transferee telle quelle
1394 TopoDS_Shape sh0 = shape;
1396 if ( GroupMode() >0) {
1397 TopLoc_Location shloc = shape.Location();
1398 aLoc = shloc.Transformation();
1399 TopLoc_Location shident;
1400 sh0.Location (shident);
1401 mapper = TransferBRep::ShapeMapper(FP,sh0);
1402 mapper->SameAttributes (start);
1405 Handle(Transfer_Binder) resbind = FP->Find(mapper);
1406 Handle(StepShape_ShapeDefinitionRepresentation) sdr;
1407 // Handle(StepShape_ShapeRepresentation) resultat;
1408 STEPConstruct_Part SDRTool;
1410 // Already SDR and SR available : take them as are
1411 Standard_Boolean iasdr = FP->GetTypedTransient
1412 (resbind,STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation),sdr);
1413 if ( iasdr ) SDRTool.ReadSDR ( sdr );
1415 SDRTool.MakeSDR ( 0, myContext.GetProductName(), myContext.GetAPD()->Application() );
1416 sdr = SDRTool.SDRValue();
1418 // resultat = GetCasted(StepShape_ShapeRepresentation,sdr->UsedRepresentation());
1420 // if shape itself not yet translated, do it now
1421 //:abv 20.05.02: see comment in TransferShape(): added "! iasdr ||"
1422 Handle(Transfer_Binder) resprod = TransientResult(sdr); //KA - OCC7141(skl 10.11.2004)
1423 if ( ! iasdr || resbind.IsNull() ) {
1424 resbind = TransferShape(mapper, sdr, FP, shapeGroup, isManifold);
1425 Handle(Transfer_Binder) oldbind = FP->Find ( mapper );
1426 if ( ! oldbind.IsNull() && !resbind.IsNull()) resbind->AddResult ( oldbind );
1427 FP->Bind (mapper,resbind);
1428 resprod=resbind; //KA - OCC7141(skl 10.11.2004)
1430 if (resprod.IsNull())
1433 // A new resbind may have been produced
1434 // DeclareAndCast(Transfer_SimpleBinderOfTransient,restrans,resbind);
1435 // if (restrans.IsNull()) return resbind;
1436 // FP->GetTypedTransient (resbind,STANDARD_TYPE(StepShape_ShapeRepresentation),resultat);
1437 // sdr->SetUsedRepresentation(resultat); // to be used by MakeItem
1439 // make location for assembly placement
1440 GeomToStep_MakeAxis2Placement3d mkax (aLoc);
1441 Handle(StepGeom_Axis2Placement3d) AxLoc = mkax.Value();
1444 // create assembly structures (CDSR, NAUO etc.)
1445 STEPConstruct_Assembly mkitem;
1446 mkitem.Init (sdr,SDR0,myContext.GetDefaultAxis(),AxLoc);
1447 mkitem.MakeRelationship ();
1448 Handle(TColStd_HSequenceOfTransient) roots = myContext.GetRootsForAssemblyLink ( mkitem );
1450 // add roots corresponding to assembly and product structures to binder
1451 //Handle(Transfer_Binder) resprod = resbind; //KA - OCC7141(skl 10.11.2004)
1452 //KA: we need only the current subshape in resprod, since the binder is copied
1453 // in Transfershape which calls Transfersubshape [ OCC7141(skl 10.11.2004) ]
1455 resprod->AddResult ( TransientResult ( SDRTool.SDRValue() ) );
1456 resbind->AddResult ( TransientResult ( SDRTool.SDRValue() ) ); //KA - OCC7141(skl 10.11.2004)
1457 roots->Append ( myContext.GetRootsForPart ( SDRTool ) );
1459 for ( Standard_Integer i=1; i <= roots->Length(); i++ ) {
1460 resprod->AddResult ( TransientResult ( roots->Value(i) ) );
1461 resbind->AddResult ( TransientResult ( roots->Value(i) ) ); //KA - OCC7141(skl 10.11.2004)
1463 myContext.NextIndex();
1465 //FP->Bind (mapper,resprod); //KA - OCC7141(skl 10.11.2004)
1467 // abv 16.10.00: bind CDSR (et al) to located shape in order to be able to track instances
1468 if ( mapper != start ) {
1469 Handle(Transfer_Binder) bnd = FP->Find ( start );
1470 for ( Standard_Integer j=1; j <= roots->Length(); j++ )
1471 if ( bnd.IsNull() ) bnd = TransientResult ( roots->Value(j) );
1472 else bnd->AddResult ( TransientResult ( roots->Value(j) ) );
1473 FP->Bind ( start, bnd );