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