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