7fd59977 |
1 | // File: TopoDSToStep_MakeShellBasedSurfaceModel.cxx |
2 | // Created: Fri Jun 24 13:32:06 1994 |
3 | // Author: Frederic MAUPAS |
4 | // <fma@nonox> |
5 | |
6 | #include <TopoDSToStep_MakeShellBasedSurfaceModel.ixx> |
7 | #include <TopoDSToStep.hxx> |
8 | #include <TopoDSToStep_Builder.hxx> |
9 | #include <TopoDSToStep_Tool.hxx> |
10 | #include <MoniTool_DataMapOfShapeTransient.hxx> |
11 | #include <StepShape_Shell.hxx> |
12 | #include <StepShape_OpenShell.hxx> |
13 | #include <StepShape_ClosedShell.hxx> |
14 | #include <StepShape_TopologicalRepresentationItem.hxx> |
15 | #include <StepShape_ConnectedFaceSet.hxx> |
16 | #include <StepShape_OpenShell.hxx> |
17 | #include <StepShape_ClosedShell.hxx> |
18 | #include <StepShape_FaceSurface.hxx> |
19 | #include <StepShape_HArray1OfShell.hxx> |
20 | #include <StepShape_HArray1OfFace.hxx> |
21 | |
22 | #include <TopoDS.hxx> |
23 | #include <TopoDS_Iterator.hxx> |
24 | |
25 | #include <TColStd_SequenceOfTransient.hxx> |
26 | #include <StdFail_NotDone.hxx> |
27 | #include <Transfer_FinderProcess.hxx> |
28 | #include <TransferBRep_ShapeMapper.hxx> |
29 | #include <TCollection_HAsciiString.hxx> |
30 | |
31 | //============================================================================= |
32 | // Create a ShellBasedSurfaceModel of StepShape from a Face of TopoDS |
33 | //============================================================================= |
34 | |
35 | TopoDSToStep_MakeShellBasedSurfaceModel:: |
36 | TopoDSToStep_MakeShellBasedSurfaceModel(const TopoDS_Face& aFace, |
37 | const Handle(Transfer_FinderProcess)& FP) |
38 | { |
39 | done = Standard_False; |
40 | MoniTool_DataMapOfShapeTransient aMap; |
41 | |
42 | TopoDSToStep_Tool aTool(aMap, Standard_False); |
43 | TopoDSToStep_Builder StepB(aFace, aTool, FP); |
44 | |
45 | TopoDSToStep::AddResult ( FP, aTool ); |
46 | |
47 | if (StepB.IsDone()) { |
48 | Handle(StepShape_FaceSurface) aFS = |
49 | Handle(StepShape_FaceSurface)::DownCast(StepB.Value()); |
50 | StepShape_Shell aShellSelect; |
51 | Handle(StepShape_OpenShell) aOpenShell |
52 | = new StepShape_OpenShell(); |
53 | Handle(StepShape_HArray1OfFace) aCfsFaces = |
54 | new StepShape_HArray1OfFace(1,1); |
55 | aCfsFaces->SetValue(1,aFS); |
56 | Handle(TCollection_HAsciiString) aName = |
57 | new TCollection_HAsciiString(""); |
58 | aOpenShell->Init(aName, aCfsFaces); |
59 | aShellSelect.SetValue(aOpenShell); |
60 | Handle(StepShape_HArray1OfShell) aSbsmFaces = |
61 | new StepShape_HArray1OfShell(1,1); |
62 | aSbsmFaces->SetValue(1, aShellSelect); |
63 | theShellBasedSurfaceModel = new StepShape_ShellBasedSurfaceModel(); |
64 | theShellBasedSurfaceModel->Init(aName, aSbsmFaces); |
65 | done = Standard_True; |
66 | } |
67 | else { |
68 | done = Standard_False; |
69 | Handle(TransferBRep_ShapeMapper) errShape = |
70 | new TransferBRep_ShapeMapper(aFace); |
71 | FP->AddWarning(errShape, " Single Face not mapped to ShellBasedSurfaceModel"); |
72 | } |
73 | } |
74 | |
75 | //============================================================================= |
76 | // Create a ShellBasedSurfaceModel of StepShape from a Shell of TopoDS |
77 | //============================================================================= |
78 | |
79 | TopoDSToStep_MakeShellBasedSurfaceModel:: |
80 | TopoDSToStep_MakeShellBasedSurfaceModel(const TopoDS_Shell& aShell, |
81 | const Handle(Transfer_FinderProcess)& FP) |
82 | { |
83 | done = Standard_False; |
84 | StepShape_Shell aShellSelect; |
85 | Handle(StepShape_HArray1OfShell) aSbsmBoundary; |
86 | Handle(StepShape_OpenShell) aOpenShell; |
87 | Handle(StepShape_ClosedShell) aClosedShell; |
88 | MoniTool_DataMapOfShapeTransient aMap; |
89 | |
90 | TopoDSToStep_Tool aTool(aMap, Standard_False); |
91 | TopoDSToStep_Builder StepB(aShell, aTool, FP); |
92 | //TopoDSToStep::AddResult ( FP, aTool ); |
93 | |
94 | if (StepB.IsDone()) { |
95 | aSbsmBoundary = new StepShape_HArray1OfShell(1,1); |
96 | if (aShell.Closed()) { |
97 | aClosedShell = Handle(StepShape_ClosedShell)::DownCast(StepB.Value()); |
98 | aShellSelect.SetValue(aClosedShell); |
99 | } |
100 | else { |
101 | aOpenShell = Handle(StepShape_OpenShell)::DownCast(StepB.Value()); |
102 | aShellSelect.SetValue(aOpenShell); |
103 | } |
104 | aSbsmBoundary->SetValue(1,aShellSelect); |
105 | theShellBasedSurfaceModel = new StepShape_ShellBasedSurfaceModel(); |
106 | Handle(TCollection_HAsciiString) aName = |
107 | new TCollection_HAsciiString(""); |
108 | theShellBasedSurfaceModel->Init(aName, aSbsmBoundary); |
109 | |
110 | // bind SBSM |
111 | TopoDSToStep::AddResult(FP,aShell,theShellBasedSurfaceModel); |
112 | done = Standard_True; |
113 | } |
114 | else { |
115 | done = Standard_False; |
116 | Handle(TransferBRep_ShapeMapper) errShape = |
117 | new TransferBRep_ShapeMapper(aShell); |
118 | FP->AddWarning(errShape, " Shell not mapped to ShellBasedSurfaceModel"); |
119 | } |
120 | |
121 | TopoDSToStep::AddResult ( FP, aTool ); |
122 | } |
123 | |
124 | //============================================================================= |
125 | // Create a ShellBasedSurfaceModel of StepShape from a Solid of TopoDS |
126 | //============================================================================= |
127 | |
128 | TopoDSToStep_MakeShellBasedSurfaceModel:: |
129 | TopoDSToStep_MakeShellBasedSurfaceModel(const TopoDS_Solid& aSolid, |
130 | const Handle(Transfer_FinderProcess)& FP) |
131 | { |
132 | done = Standard_False; |
133 | StepShape_Shell aShellSelect; |
134 | Handle(StepShape_HArray1OfShell) aSbsmBoundary; |
135 | Handle(StepShape_OpenShell) aOpenShell; |
136 | Handle(StepShape_ClosedShell) aClosedShell; |
137 | TopoDS_Iterator It; |
138 | TopoDS_Shell aShell; |
139 | MoniTool_DataMapOfShapeTransient aMap; |
140 | TColStd_SequenceOfTransient S; |
141 | |
142 | It.Initialize(aSolid); |
143 | for (; It.More(); It.Next() ) { |
144 | if (It.Value().ShapeType() == TopAbs_SHELL) { |
145 | aShell = TopoDS::Shell(It.Value()); |
146 | |
147 | TopoDSToStep_Tool aTool(aMap, Standard_False); |
148 | TopoDSToStep_Builder StepB(aShell, aTool, FP); |
149 | TopoDSToStep::AddResult ( FP, aTool ); |
150 | |
151 | if (StepB.IsDone()) { |
152 | S.Append(StepB.Value()); |
153 | } |
154 | else { |
155 | Handle(TransferBRep_ShapeMapper) errShape = |
156 | new TransferBRep_ShapeMapper(aShell); |
157 | FP->AddWarning(errShape," Shell from Solid not mapped to ShellBasedSurfaceModel"); |
158 | } |
159 | } |
160 | } |
161 | Standard_Integer N = S.Length(); |
162 | if ( N >= 1) { |
163 | aSbsmBoundary = new StepShape_HArray1OfShell(1,N); |
164 | for (Standard_Integer i=1; i<=N; i++) { |
165 | aOpenShell = Handle(StepShape_OpenShell)::DownCast(S.Value(i)); |
166 | if (!aOpenShell.IsNull()) { |
167 | aShellSelect.SetValue(aOpenShell); |
168 | } |
169 | else { |
170 | aClosedShell = Handle(StepShape_ClosedShell)::DownCast(S.Value(i)); |
171 | aShellSelect.SetValue(aClosedShell); |
172 | } |
173 | aSbsmBoundary->SetValue(i,aShellSelect); |
174 | } |
175 | |
176 | theShellBasedSurfaceModel = new StepShape_ShellBasedSurfaceModel(); |
177 | Handle(TCollection_HAsciiString) aName = |
178 | new TCollection_HAsciiString(""); |
179 | theShellBasedSurfaceModel->Init(aName,aSbsmBoundary); |
180 | done = Standard_True; |
181 | } |
182 | else { |
183 | done = Standard_False; |
184 | Handle(TransferBRep_ShapeMapper) errShape = |
185 | new TransferBRep_ShapeMapper(aSolid); |
186 | FP->AddWarning(errShape," Solid contains no Shell to be mapped to ShellBasedSurfaceModel"); |
187 | } |
188 | } |
189 | |
190 | //============================================================================= |
191 | // renvoi des valeurs |
192 | //============================================================================= |
193 | |
194 | const Handle(StepShape_ShellBasedSurfaceModel) & |
195 | TopoDSToStep_MakeShellBasedSurfaceModel::Value() const |
196 | { |
197 | StdFail_NotDone_Raise_if(!done,""); |
198 | return theShellBasedSurfaceModel; |
199 | } |