0024157: Parallelization of assembly part of BO
[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-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 #include <TopoDSToStep_MakeShellBasedSurfaceModel.ixx>
23 #include <TopoDSToStep.hxx>
24 #include <TopoDSToStep_Builder.hxx>
25 #include <TopoDSToStep_Tool.hxx>
26 #include <MoniTool_DataMapOfShapeTransient.hxx>
27 #include <StepShape_Shell.hxx>
28 #include <StepShape_OpenShell.hxx>
29 #include <StepShape_ClosedShell.hxx>
30 #include <StepShape_TopologicalRepresentationItem.hxx>
31 #include <StepShape_ConnectedFaceSet.hxx>
32 #include <StepShape_OpenShell.hxx>
33 #include <StepShape_ClosedShell.hxx>
34 #include <StepShape_FaceSurface.hxx>
35 #include <StepShape_HArray1OfShell.hxx>
36 #include <StepShape_HArray1OfFace.hxx>
37
38 #include <TopoDS.hxx>
39 #include <TopoDS_Iterator.hxx>
40
41 #include <TColStd_SequenceOfTransient.hxx>
42 #include <StdFail_NotDone.hxx>
43 #include <Transfer_FinderProcess.hxx>
44 #include <TransferBRep_ShapeMapper.hxx>
45 #include <TCollection_HAsciiString.hxx>
46
47 //=============================================================================
48 // Create a ShellBasedSurfaceModel of StepShape from a Face of TopoDS
49 //=============================================================================
50
51 TopoDSToStep_MakeShellBasedSurfaceModel::
52   TopoDSToStep_MakeShellBasedSurfaceModel(const TopoDS_Face& aFace,
53                                           const Handle(Transfer_FinderProcess)& FP)
54 {
55   done = Standard_False;
56   MoniTool_DataMapOfShapeTransient aMap;
57
58   TopoDSToStep_Tool    aTool(aMap, Standard_False);
59   TopoDSToStep_Builder StepB(aFace, aTool, FP);
60
61   TopoDSToStep::AddResult ( FP, aTool );
62
63   if (StepB.IsDone()) {
64     Handle(StepShape_FaceSurface) aFS =
65       Handle(StepShape_FaceSurface)::DownCast(StepB.Value());
66     StepShape_Shell aShellSelect;
67     Handle(StepShape_OpenShell) aOpenShell 
68       = new StepShape_OpenShell();
69     Handle(StepShape_HArray1OfFace) aCfsFaces =
70       new StepShape_HArray1OfFace(1,1);
71     aCfsFaces->SetValue(1,aFS);
72     Handle(TCollection_HAsciiString) aName = 
73       new TCollection_HAsciiString("");
74     aOpenShell->Init(aName, aCfsFaces);
75     aShellSelect.SetValue(aOpenShell);
76     Handle(StepShape_HArray1OfShell) aSbsmFaces =
77       new StepShape_HArray1OfShell(1,1);
78     aSbsmFaces->SetValue(1, aShellSelect);
79     theShellBasedSurfaceModel = new StepShape_ShellBasedSurfaceModel();
80     theShellBasedSurfaceModel->Init(aName, aSbsmFaces);
81     done = Standard_True;
82   }
83   else {
84     done = Standard_False;
85     Handle(TransferBRep_ShapeMapper) errShape =
86       new TransferBRep_ShapeMapper(aFace);
87     FP->AddWarning(errShape, " Single Face not mapped to ShellBasedSurfaceModel");
88   }
89 }
90
91 //=============================================================================
92 // Create a ShellBasedSurfaceModel of StepShape from a Shell of TopoDS
93 //=============================================================================
94
95 TopoDSToStep_MakeShellBasedSurfaceModel::
96   TopoDSToStep_MakeShellBasedSurfaceModel(const TopoDS_Shell& aShell,
97                                           const Handle(Transfer_FinderProcess)& FP)
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);
108   //TopoDSToStep::AddResult ( FP, aTool );
109
110   if (StepB.IsDone()) {
111     aSbsmBoundary = new StepShape_HArray1OfShell(1,1);
112     if (aShell.Closed()) {
113       aClosedShell = Handle(StepShape_ClosedShell)::DownCast(StepB.Value());
114       aShellSelect.SetValue(aClosedShell);
115     }
116     else {
117       aOpenShell = Handle(StepShape_OpenShell)::DownCast(StepB.Value());
118       aShellSelect.SetValue(aOpenShell);
119     }
120     aSbsmBoundary->SetValue(1,aShellSelect);
121     theShellBasedSurfaceModel = new StepShape_ShellBasedSurfaceModel();
122     Handle(TCollection_HAsciiString) aName = 
123       new TCollection_HAsciiString("");
124     theShellBasedSurfaceModel->Init(aName, aSbsmBoundary);
125     
126     // bind SBSM
127     TopoDSToStep::AddResult(FP,aShell,theShellBasedSurfaceModel);
128     done = Standard_True;
129   }
130   else {
131     done = Standard_False;
132     Handle(TransferBRep_ShapeMapper) errShape =
133       new TransferBRep_ShapeMapper(aShell);
134     FP->AddWarning(errShape, " Shell not mapped to ShellBasedSurfaceModel");
135   }
136   
137   TopoDSToStep::AddResult ( FP, aTool );
138 }
139
140 //=============================================================================
141 // Create a ShellBasedSurfaceModel of StepShape from a Solid of TopoDS
142 //=============================================================================
143
144 TopoDSToStep_MakeShellBasedSurfaceModel::
145   TopoDSToStep_MakeShellBasedSurfaceModel(const TopoDS_Solid& aSolid,
146                                     const Handle(Transfer_FinderProcess)& FP)
147 {
148   done = Standard_False;
149   StepShape_Shell                  aShellSelect;
150   Handle(StepShape_HArray1OfShell) aSbsmBoundary;
151   Handle(StepShape_OpenShell)      aOpenShell;
152   Handle(StepShape_ClosedShell)    aClosedShell;
153   TopoDS_Iterator              It;
154   TopoDS_Shell                 aShell;
155   MoniTool_DataMapOfShapeTransient   aMap;
156   TColStd_SequenceOfTransient  S;
157   
158   It.Initialize(aSolid);
159   for (; It.More(); It.Next() ) {
160     if (It.Value().ShapeType() == TopAbs_SHELL) {
161       aShell = TopoDS::Shell(It.Value());
162
163       TopoDSToStep_Tool    aTool(aMap, Standard_False);
164       TopoDSToStep_Builder StepB(aShell, aTool, FP);
165       TopoDSToStep::AddResult ( FP, aTool );
166
167       if (StepB.IsDone()) {
168         S.Append(StepB.Value());
169       }
170       else {
171         Handle(TransferBRep_ShapeMapper) errShape =
172           new TransferBRep_ShapeMapper(aShell);
173         FP->AddWarning(errShape," Shell from Solid not mapped to ShellBasedSurfaceModel");
174       }
175     }
176   }
177   Standard_Integer N = S.Length();
178   if ( N >= 1) {
179     aSbsmBoundary = new StepShape_HArray1OfShell(1,N);
180     for (Standard_Integer i=1; i<=N; i++) {
181       aOpenShell = Handle(StepShape_OpenShell)::DownCast(S.Value(i));
182       if (!aOpenShell.IsNull()) {
183         aShellSelect.SetValue(aOpenShell);
184       }
185       else {
186         aClosedShell = Handle(StepShape_ClosedShell)::DownCast(S.Value(i));
187         aShellSelect.SetValue(aClosedShell);
188       }
189       aSbsmBoundary->SetValue(i,aShellSelect);
190     }
191     
192     theShellBasedSurfaceModel = new StepShape_ShellBasedSurfaceModel();
193     Handle(TCollection_HAsciiString) aName = 
194       new TCollection_HAsciiString("");
195     theShellBasedSurfaceModel->Init(aName,aSbsmBoundary);
196     done = Standard_True;
197   }
198   else {
199     done = Standard_False;
200     Handle(TransferBRep_ShapeMapper) errShape =
201       new TransferBRep_ShapeMapper(aSolid);
202     FP->AddWarning(errShape," Solid contains no Shell to be mapped to ShellBasedSurfaceModel");
203   }
204 }
205
206 //=============================================================================
207 // renvoi des valeurs
208 //=============================================================================
209
210 const Handle(StepShape_ShellBasedSurfaceModel) &
211       TopoDSToStep_MakeShellBasedSurfaceModel::Value() const
212 {
213   StdFail_NotDone_Raise_if(!done,"");
214   return theShellBasedSurfaceModel;
215 }