b311480e |
1 | // Created on: 1993-07-23 |
2 | // Created by: Martine LANGLOIS |
3 | // Copyright (c) 1993-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
42cf5bc1 |
17 | |
18 | #include <BRepClass3d.hxx> |
7fd59977 |
19 | #include <MoniTool_DataMapOfShapeTransient.hxx> |
42cf5bc1 |
20 | #include <StdFail_NotDone.hxx> |
7fd59977 |
21 | #include <StepShape_ClosedShell.hxx> |
42cf5bc1 |
22 | #include <StepShape_FacetedBrepAndBrepWithVoids.hxx> |
7fd59977 |
23 | #include <StepShape_HArray1OfOrientedClosedShell.hxx> |
42cf5bc1 |
24 | #include <StepShape_OrientedClosedShell.hxx> |
25 | #include <StepShape_TopologicalRepresentationItem.hxx> |
26 | #include <TCollection_HAsciiString.hxx> |
27 | #include <TColStd_SequenceOfTransient.hxx> |
28 | #include <TopoDS.hxx> |
7fd59977 |
29 | #include <TopoDS_Iterator.hxx> |
30 | #include <TopoDS_Shell.hxx> |
42cf5bc1 |
31 | #include <TopoDS_Solid.hxx> |
32 | #include <TopoDSToStep.hxx> |
33 | #include <TopoDSToStep_Builder.hxx> |
34 | #include <TopoDSToStep_MakeFacetedBrepAndBrepWithVoids.hxx> |
35 | #include <TopoDSToStep_Tool.hxx> |
7fd59977 |
36 | #include <Transfer_FinderProcess.hxx> |
37 | #include <TransferBRep_ShapeMapper.hxx> |
7fd59977 |
38 | |
39 | //============================================================================= |
40 | // Create a FacetedBrepAndBrepWithVoids of StepShape from a Solid of TopoDS |
41 | // containing more than one closed shell |
42 | //============================================================================= |
7fd59977 |
43 | TopoDSToStep_MakeFacetedBrepAndBrepWithVoids:: |
44 | TopoDSToStep_MakeFacetedBrepAndBrepWithVoids(const TopoDS_Solid& aSolid, |
45 | const Handle(Transfer_FinderProcess)& FP) |
46 | { |
47 | done = Standard_False; |
48 | TopoDS_Iterator It; |
49 | MoniTool_DataMapOfShapeTransient aMap; |
50 | TColStd_SequenceOfTransient S; |
51 | TopoDS_Shell aOutShell; |
52 | |
53 | Handle(StepShape_TopologicalRepresentationItem) aItem; |
54 | Handle(StepShape_ClosedShell) aOuter, aCShell; |
55 | Handle(StepShape_OrientedClosedShell) aOCShell; |
56 | Handle(StepShape_HArray1OfOrientedClosedShell) aVoids; |
57 | |
2f0109b7 |
58 | aOutShell = BRepClass3d::OuterShell(aSolid); |
7fd59977 |
59 | |
60 | TopoDSToStep_Builder StepB; |
61 | TopoDSToStep_Tool aTool; |
62 | |
63 | if (!aOutShell.IsNull()) { |
64 | It.Initialize(aSolid); |
65 | for ( ; It.More(); It.Next() ) { |
66 | if (It.Value().ShapeType() == TopAbs_SHELL) { |
67 | TopoDS_Shell CurrentShell = TopoDS::Shell(It.Value()); |
68 | if (It.Value().Closed()) { |
69 | |
70 | aTool.Init(aMap, Standard_False); |
71 | StepB.Init(CurrentShell, aTool, FP); |
72 | TopoDSToStep::AddResult ( FP, aTool ); |
73 | |
74 | if (StepB.IsDone()) { |
75 | aCShell = Handle(StepShape_ClosedShell)::DownCast(StepB.Value()); |
76 | if ( aOutShell.IsEqual(It.Value()) ) |
77 | aOuter = aCShell; |
78 | else |
79 | S.Append(aCShell); |
80 | } |
81 | else { |
82 | Handle(TransferBRep_ShapeMapper) errShape = |
83 | new TransferBRep_ShapeMapper(CurrentShell); |
84 | FP->AddWarning(errShape," Shell from Solid not mapped to FacetedBrepAndBrepWithVoids"); |
85 | } |
86 | } |
87 | else { |
88 | done = Standard_False; |
89 | Handle(TransferBRep_ShapeMapper) errShape = |
90 | new TransferBRep_ShapeMapper(CurrentShell); |
91 | FP->AddWarning(errShape," Shell from Solid not closed; not mapped to FacetedBrepAndBrepWithVoids"); |
92 | } |
93 | } |
94 | } |
95 | } |
96 | Standard_Integer N = S.Length(); |
97 | if ( N>=1 ) { |
98 | aVoids = new StepShape_HArray1OfOrientedClosedShell(1,N); |
99 | Handle(TCollection_HAsciiString) aName = |
100 | new TCollection_HAsciiString(""); |
101 | for ( Standard_Integer i=1; i<=N; i++ ) { |
102 | aOCShell = new StepShape_OrientedClosedShell(); |
103 | aOCShell->Init(aName, Handle(StepShape_ClosedShell)::DownCast(S.Value(i)), |
104 | Standard_True); |
105 | aVoids->SetValue(i, aOCShell); |
106 | } |
107 | theFacetedBrepAndBrepWithVoids = |
108 | new StepShape_FacetedBrepAndBrepWithVoids(); |
109 | theFacetedBrepAndBrepWithVoids->Init(aName, aOuter, aVoids); |
110 | done = Standard_True; |
111 | } |
112 | else { |
113 | done = Standard_False; |
114 | Handle(TransferBRep_ShapeMapper) errShape = |
115 | new TransferBRep_ShapeMapper(aSolid); |
116 | FP->AddWarning(errShape," Solid contains no Shell to be mapped to FacetedBrepAndBrepWithVoids"); |
117 | } |
118 | } |
119 | |
120 | //============================================================================= |
121 | // renvoi des valeurs |
122 | //============================================================================= |
123 | |
124 | const Handle(StepShape_FacetedBrepAndBrepWithVoids) & |
125 | TopoDSToStep_MakeFacetedBrepAndBrepWithVoids::Value() const |
126 | { |
2d2b3d53 |
127 | StdFail_NotDone_Raise_if (!done, "TopoDSToStep_MakeFacetedBrepAndBrepWithVoids::Value() - no result"); |
7fd59977 |
128 | return theFacetedBrepAndBrepWithVoids; |
129 | } |