1 // Created on: 1994-06-24
2 // Created by: Frederic MAUPAS
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <MoniTool_DataMapOfShapeTransient.hxx>
19 #include <Message_ProgressScope.hxx>
20 #include <StdFail_NotDone.hxx>
21 #include <StepShape_ClosedShell.hxx>
22 #include <StepShape_ConnectedFaceSet.hxx>
23 #include <StepShape_FaceSurface.hxx>
24 #include <StepShape_HArray1OfFace.hxx>
25 #include <StepShape_HArray1OfShell.hxx>
26 #include <StepShape_OpenShell.hxx>
27 #include <StepShape_Shell.hxx>
28 #include <StepShape_ShellBasedSurfaceModel.hxx>
29 #include <StepShape_TopologicalRepresentationItem.hxx>
30 #include <TCollection_HAsciiString.hxx>
31 #include <TColStd_SequenceOfTransient.hxx>
32 #include <TopoDS.hxx>
33 #include <TopoDS_Face.hxx>
34 #include <TopoDS_Iterator.hxx>
35 #include <TopoDS_Shell.hxx>
36 #include <TopoDS_Solid.hxx>
37 #include <TopoDSToStep.hxx>
38 #include <TopoDSToStep_Builder.hxx>
39 #include <TopoDSToStep_MakeShellBasedSurfaceModel.hxx>
40 #include <TopoDSToStep_Tool.hxx>
41 #include <Transfer_FinderProcess.hxx>
42 #include <TransferBRep_ShapeMapper.hxx>
43
44 //=============================================================================
45 // Create a ShellBasedSurfaceModel of StepShape from a Face of TopoDS
46 //=============================================================================
47 TopoDSToStep_MakeShellBasedSurfaceModel::
TopoDSToStep_MakeShellBasedSurfaceModel(const TopoDS_Face & aFace,const Handle (Transfer_FinderProcess)& FP,const Message_ProgressRange & theProgress)48 TopoDSToStep_MakeShellBasedSurfaceModel(const TopoDS_Face& aFace,
49 const Handle(Transfer_FinderProcess)& FP,
50 const Message_ProgressRange& theProgress)
51 {
52 done = Standard_False;
53 MoniTool_DataMapOfShapeTransient aMap;
54
55 TopoDSToStep_Tool aTool(aMap, Standard_False);
56 TopoDSToStep_Builder StepB(aFace, aTool, FP, theProgress);
57 if (theProgress.UserBreak())
58 return;
59
60 TopoDSToStep::AddResult ( FP, aTool );
61
62 if (StepB.IsDone()) {
63 Handle(StepShape_FaceSurface) aFS =
64 Handle(StepShape_FaceSurface)::DownCast(StepB.Value());
65 StepShape_Shell aShellSelect;
66 Handle(StepShape_OpenShell) aOpenShell
67 = new StepShape_OpenShell();
68 Handle(StepShape_HArray1OfFace) aCfsFaces =
69 new StepShape_HArray1OfFace(1,1);
70 aCfsFaces->SetValue(1,aFS);
71 Handle(TCollection_HAsciiString) aName =
72 new TCollection_HAsciiString("");
73 aOpenShell->Init(aName, aCfsFaces);
74 aShellSelect.SetValue(aOpenShell);
75 Handle(StepShape_HArray1OfShell) aSbsmFaces =
76 new StepShape_HArray1OfShell(1,1);
77 aSbsmFaces->SetValue(1, aShellSelect);
78 theShellBasedSurfaceModel = new StepShape_ShellBasedSurfaceModel();
79 theShellBasedSurfaceModel->Init(aName, aSbsmFaces);
80 done = Standard_True;
81 }
82 else {
83 done = Standard_False;
84 Handle(TransferBRep_ShapeMapper) errShape =
85 new TransferBRep_ShapeMapper(aFace);
86 FP->AddWarning(errShape, " Single Face not mapped to ShellBasedSurfaceModel");
87 }
88 }
89
90 //=============================================================================
91 // Create a ShellBasedSurfaceModel of StepShape from a Shell of TopoDS
92 //=============================================================================
93
94 TopoDSToStep_MakeShellBasedSurfaceModel::
TopoDSToStep_MakeShellBasedSurfaceModel(const TopoDS_Shell & aShell,const Handle (Transfer_FinderProcess)& FP,const Message_ProgressRange & theProgress)95 TopoDSToStep_MakeShellBasedSurfaceModel(const TopoDS_Shell& aShell,
96 const Handle(Transfer_FinderProcess)& FP,
97 const Message_ProgressRange& theProgress)
98 {
99 done = Standard_False;
100 StepShape_Shell aShellSelect;
101 Handle(StepShape_HArray1OfShell) aSbsmBoundary;
102 Handle(StepShape_OpenShell) aOpenShell;
103 Handle(StepShape_ClosedShell) aClosedShell;
104 MoniTool_DataMapOfShapeTransient aMap;
105
106 TopoDSToStep_Tool aTool(aMap, Standard_False);
107 TopoDSToStep_Builder StepB(aShell, aTool, FP, theProgress);
108 if (theProgress.UserBreak())
109 return;
110 //TopoDSToStep::AddResult ( FP, aTool );
111
112 if (StepB.IsDone()) {
113 aSbsmBoundary = new StepShape_HArray1OfShell(1,1);
114 if (aShell.Closed()) {
115 aClosedShell = Handle(StepShape_ClosedShell)::DownCast(StepB.Value());
116 aShellSelect.SetValue(aClosedShell);
117 }
118 else {
119 aOpenShell = Handle(StepShape_OpenShell)::DownCast(StepB.Value());
120 aShellSelect.SetValue(aOpenShell);
121 }
122 aSbsmBoundary->SetValue(1,aShellSelect);
123 theShellBasedSurfaceModel = new StepShape_ShellBasedSurfaceModel();
124 Handle(TCollection_HAsciiString) aName =
125 new TCollection_HAsciiString("");
126 theShellBasedSurfaceModel->Init(aName, aSbsmBoundary);
127
128 // bind SBSM
129 TopoDSToStep::AddResult(FP,aShell,theShellBasedSurfaceModel);
130 done = Standard_True;
131 }
132 else {
133 done = Standard_False;
134 Handle(TransferBRep_ShapeMapper) errShape =
135 new TransferBRep_ShapeMapper(aShell);
136 FP->AddWarning(errShape, " Shell not mapped to ShellBasedSurfaceModel");
137 }
138
139 TopoDSToStep::AddResult ( FP, aTool );
140 }
141
142 //=============================================================================
143 // Create a ShellBasedSurfaceModel of StepShape from a Solid of TopoDS
144 //=============================================================================
145
146 TopoDSToStep_MakeShellBasedSurfaceModel::
TopoDSToStep_MakeShellBasedSurfaceModel(const TopoDS_Solid & aSolid,const Handle (Transfer_FinderProcess)& FP,const Message_ProgressRange & theProgress)147 TopoDSToStep_MakeShellBasedSurfaceModel(const TopoDS_Solid& aSolid,
148 const Handle(Transfer_FinderProcess)& FP,
149 const Message_ProgressRange& theProgress)
150 {
151 done = Standard_False;
152 StepShape_Shell aShellSelect;
153 Handle(StepShape_HArray1OfShell) aSbsmBoundary;
154 Handle(StepShape_OpenShell) aOpenShell;
155 Handle(StepShape_ClosedShell) aClosedShell;
156 TopoDS_Iterator It;
157 TopoDS_Shell aShell;
158 MoniTool_DataMapOfShapeTransient aMap;
159 TColStd_SequenceOfTransient S;
160
161 Standard_Integer nbshapes = 0;
162 for (It.Initialize(aSolid); It.More(); It.Next())
163 if (It.Value().ShapeType() == TopAbs_SHELL)
164 nbshapes++;
165 Message_ProgressScope aPS(theProgress, NULL, nbshapes);
166 for (It.Initialize(aSolid); It.More() && aPS.More(); It.Next())
167 {
168 if (It.Value().ShapeType() == TopAbs_SHELL) {
169 aShell = TopoDS::Shell(It.Value());
170
171 TopoDSToStep_Tool aTool(aMap, Standard_False);
172 TopoDSToStep_Builder StepB(aShell, aTool, FP, aPS.Next());
173 TopoDSToStep::AddResult ( FP, aTool );
174
175 if (StepB.IsDone()) {
176 S.Append(StepB.Value());
177 }
178 else {
179 Handle(TransferBRep_ShapeMapper) errShape =
180 new TransferBRep_ShapeMapper(aShell);
181 FP->AddWarning(errShape," Shell from Solid not mapped to ShellBasedSurfaceModel");
182 }
183 }
184 }
185 if (!aPS.More())
186 return;
187 Standard_Integer N = S.Length();
188 if ( N >= 1) {
189 aSbsmBoundary = new StepShape_HArray1OfShell(1,N);
190 for (Standard_Integer i=1; i<=N; i++) {
191 aOpenShell = Handle(StepShape_OpenShell)::DownCast(S.Value(i));
192 if (!aOpenShell.IsNull()) {
193 aShellSelect.SetValue(aOpenShell);
194 }
195 else {
196 aClosedShell = Handle(StepShape_ClosedShell)::DownCast(S.Value(i));
197 aShellSelect.SetValue(aClosedShell);
198 }
199 aSbsmBoundary->SetValue(i,aShellSelect);
200 }
201
202 theShellBasedSurfaceModel = new StepShape_ShellBasedSurfaceModel();
203 Handle(TCollection_HAsciiString) aName =
204 new TCollection_HAsciiString("");
205 theShellBasedSurfaceModel->Init(aName,aSbsmBoundary);
206 done = Standard_True;
207 }
208 else {
209 done = Standard_False;
210 Handle(TransferBRep_ShapeMapper) errShape =
211 new TransferBRep_ShapeMapper(aSolid);
212 FP->AddWarning(errShape," Solid contains no Shell to be mapped to ShellBasedSurfaceModel");
213 }
214 }
215
216 //=============================================================================
217 // renvoi des valeurs
218 //=============================================================================
219
Handle(StepShape_ShellBasedSurfaceModel)220 const Handle(StepShape_ShellBasedSurfaceModel) &
221 TopoDSToStep_MakeShellBasedSurfaceModel::Value() const
222 {
223 StdFail_NotDone_Raise_if (!done, "TopoDSToStep_MakeShellBasedSurfaceModel::Value() - no result");
224 return theShellBasedSurfaceModel;
225 }
226