b311480e |
1 | // Created on: 1994-11-25 |
2 | // Created by: Frederic MAUPAS |
3 | // Copyright (c) 1994-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 | // |
973c2be1 |
8 | // This library is free software; you can redistribute it and / or modify it |
9 | // under the terms of the GNU Lesser General Public 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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | #include <TopoDSToStep_Builder.ixx> |
18 | |
19 | #include <TopoDSToStep_Tool.hxx> |
20 | |
21 | #include <TopoDSToStep_MakeStepFace.hxx> |
22 | |
23 | #include <StepShape_ConnectedFaceSet.hxx> |
24 | #include <StepShape_HArray1OfFace.hxx> |
25 | #include <StepShape_ClosedShell.hxx> |
26 | #include <StepShape_OpenShell.hxx> |
27 | #include <StepShape_FaceSurface.hxx> |
28 | |
29 | #include <TopoDS.hxx> |
30 | #include <TopoDS_Shell.hxx> |
31 | #include <TopoDS_Face.hxx> |
32 | |
33 | #include <TopExp_Explorer.hxx> |
34 | |
35 | #include <TColStd_SequenceOfTransient.hxx> |
36 | #include <TransferBRep_ShapeMapper.hxx> |
37 | #include <TCollection_HAsciiString.hxx> |
38 | |
39 | #include <Message_ProgressIndicator.hxx> |
40 | |
41 | // ============================================================================ |
42 | // Method : TopoDSToStep_Builder::TopoDSToStep_Builder |
43 | // Purpose : |
44 | // ============================================================================ |
45 | |
46 | TopoDSToStep_Builder::TopoDSToStep_Builder() |
47 | { |
48 | done = Standard_False; |
49 | } |
50 | |
51 | // ============================================================================ |
52 | // Method : TopoDSToStep_Builder::TopoDSToStep_Builder |
53 | // Purpose : |
54 | // ============================================================================ |
55 | |
56 | TopoDSToStep_Builder::TopoDSToStep_Builder |
57 | (const TopoDS_Shape& aShape, |
58 | TopoDSToStep_Tool& aTool, const Handle(Transfer_FinderProcess)& FP) |
59 | { |
60 | done = Standard_False; |
61 | Init(aShape, aTool, FP); |
62 | } |
63 | |
64 | // ============================================================================ |
65 | // Method : TopoDSToStep_Builder::Init |
66 | // Purpose : |
67 | // ============================================================================ |
68 | |
69 | void TopoDSToStep_Builder::Init(const TopoDS_Shape& aShape, |
70 | TopoDSToStep_Tool& myTool, |
71 | const Handle(Transfer_FinderProcess)& FP) |
72 | { |
73 | |
74 | if (myTool.IsBound(aShape)) { |
75 | myError = TopoDSToStep_BuilderDone; |
76 | done = Standard_True; |
77 | myResult = myTool.Find(aShape); |
78 | return; |
79 | } |
80 | |
81 | Handle(Message_ProgressIndicator) progress = FP->GetProgress(); |
82 | |
83 | switch (aShape.ShapeType()) |
84 | { |
85 | case TopAbs_SHELL: |
86 | { |
87 | TopoDS_Shell myShell = TopoDS::Shell(aShape); |
88 | myTool.SetCurrentShell(myShell); |
89 | |
90 | Handle(StepShape_FaceSurface) FS; |
91 | Handle(StepShape_TopologicalRepresentationItem) Fpms; |
92 | TColStd_SequenceOfTransient mySeq; |
93 | |
94 | // const TopoDS_Shell ForwardShell = |
95 | // TopoDS::Shell(myShell.Oriented(TopAbs_FORWARD)); |
96 | |
97 | // TopExp_Explorer myExp(ForwardShell, TopAbs_FACE); |
98 | // CKY 9-DEC-1997 (PRO9824 et consorts) |
99 | // Pour passer les orientations : ELLES SONT DONNEES EN RELATIF |
100 | // Donc, pour SHELL, on doit l ecrire en direct en STEP (pas le choix) |
101 | // -> il faut repercuter en dessous, donc explorer le Shell TEL QUEL |
102 | // Pour FACE WIRE, d une part on ECRIT SON ORIENTATION relative au contenant |
103 | // (puisqu on peut), d autre part on EXPLORE EN FORWARD : ainsi les |
104 | // orientations des sous-shapes sont relatives a leur contenant immediat |
105 | // et la recombinaison en lecture est sans malice |
106 | // Il reste ici et la du code relatif a "en Faceted on combine differemment" |
107 | // -> reste encore du menage a faire |
108 | |
109 | |
110 | |
111 | TopExp_Explorer myExp(myShell, TopAbs_FACE); |
112 | |
113 | TopoDSToStep_MakeStepFace MkFace; |
114 | |
115 | for (;myExp.More();myExp.Next()) { |
116 | |
117 | const TopoDS_Face Face = TopoDS::Face(myExp.Current()); |
118 | |
119 | MkFace.Init(Face, myTool, FP); |
120 | |
121 | if (MkFace.IsDone()) { |
122 | FS = Handle(StepShape_FaceSurface)::DownCast(MkFace.Value()); |
123 | Fpms = FS; |
124 | mySeq.Append(Fpms); |
125 | } |
126 | else { |
127 | // MakeFace Error Handling : warning only |
128 | // cout << "Warning : one Face has not been mapped" << endl; |
129 | // Handle(TransferBRep_ShapeMapper) errShape = |
130 | // new TransferBRep_ShapeMapper(Face); |
131 | // FP->AddWarning(errShape, " a Face from a Shell has not been mapped"); |
132 | } |
133 | if (!progress.IsNull()) progress->Increment(); |
134 | } |
135 | |
136 | Standard_Integer nbFaces = mySeq.Length(); |
137 | if ( nbFaces >= 1) { |
138 | Handle(StepShape_HArray1OfFace) aSet = |
139 | new StepShape_HArray1OfFace(1,nbFaces); |
140 | for (Standard_Integer i=1; i<=nbFaces; i++ ) { |
141 | aSet->SetValue(i, Handle(StepShape_Face)::DownCast(mySeq.Value(i))); |
142 | } |
143 | Handle(StepShape_ConnectedFaceSet) CFSpms; |
144 | if (myShell.Closed()) |
145 | CFSpms = new StepShape_ClosedShell(); |
146 | else |
147 | CFSpms = new StepShape_OpenShell(); |
148 | Handle(TCollection_HAsciiString) aName = |
149 | new TCollection_HAsciiString(""); |
150 | CFSpms->Init(aName, aSet); |
151 | |
152 | // -------------------------------------------------------------- |
153 | // To add later : if not facetted context & shell is reversed |
154 | // then shall create an oriented_shell with |
155 | // orientation flag to false. |
156 | // -------------------------------------------------------------- |
157 | |
158 | myTool.Bind(aShape, CFSpms); |
159 | myResult = CFSpms; |
160 | done = Standard_True; |
161 | } |
162 | else { |
163 | // Builder Error handling; |
164 | myError = TopoDSToStep_NoFaceMapped; |
165 | done = Standard_False; |
166 | } |
167 | break; |
168 | } |
169 | |
170 | case TopAbs_FACE: |
171 | { |
172 | const TopoDS_Face Face = TopoDS::Face(aShape); |
173 | |
174 | Handle(StepShape_FaceSurface) FS; |
175 | Handle(StepShape_TopologicalRepresentationItem) Fpms; |
176 | |
177 | TopoDSToStep_MakeStepFace MkFace(Face, myTool, FP); |
178 | |
179 | if (MkFace.IsDone()) { |
180 | FS = Handle(StepShape_FaceSurface)::DownCast(MkFace.Value()); |
181 | Fpms = FS; |
182 | myResult = Fpms; |
183 | myError = TopoDSToStep_BuilderDone; |
184 | done = Standard_True; |
185 | } |
186 | else { |
187 | // MakeFace Error Handling : Face not Mapped |
188 | myError = TopoDSToStep_BuilderOther; |
189 | // Handle(TransferBRep_ShapeMapper) errShape = |
190 | // new TransferBRep_ShapeMapper(Face); |
191 | // FP->AddWarning(errShape, " the Face has not been mapped"); |
192 | done = Standard_False; |
193 | } |
194 | if (!progress.IsNull()) progress->Increment(); |
195 | break; |
196 | } |
197 | default: break; |
198 | } |
199 | } |
200 | |
201 | // ============================================================================ |
202 | // Method : TopoDSToStep_Builder::Value |
203 | // Purpose : |
204 | // ============================================================================ |
205 | |
206 | const Handle(StepShape_TopologicalRepresentationItem)& |
207 | TopoDSToStep_Builder::Value() const |
208 | { |
209 | StdFail_NotDone_Raise_if(!done,""); |
210 | return myResult; |
211 | } |
212 | |
213 | // ============================================================================ |
214 | // Method : TopoDSToStep_Builder::Error |
215 | // Purpose : |
216 | // ============================================================================ |
217 | |
218 | TopoDSToStep_BuilderError TopoDSToStep_Builder::Error() const |
219 | { |
220 | return myError; |
221 | } |
222 | |