1 // Created on: 1994-11-25
2 // Created by: Frederic MAUPAS
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
23 #include <TopoDSToStep_Builder.ixx>
25 #include <TopoDSToStep_Tool.hxx>
27 #include <TopoDSToStep_MakeStepFace.hxx>
29 #include <StepShape_ConnectedFaceSet.hxx>
30 #include <StepShape_HArray1OfFace.hxx>
31 #include <StepShape_ClosedShell.hxx>
32 #include <StepShape_OpenShell.hxx>
33 #include <StepShape_FaceSurface.hxx>
36 #include <TopoDS_Shell.hxx>
37 #include <TopoDS_Face.hxx>
39 #include <TopExp_Explorer.hxx>
41 #include <TColStd_SequenceOfTransient.hxx>
42 #include <TransferBRep_ShapeMapper.hxx>
43 #include <TCollection_HAsciiString.hxx>
45 #include <Message_ProgressIndicator.hxx>
47 // ============================================================================
48 // Method : TopoDSToStep_Builder::TopoDSToStep_Builder
50 // ============================================================================
52 TopoDSToStep_Builder::TopoDSToStep_Builder()
54 done = Standard_False;
57 // ============================================================================
58 // Method : TopoDSToStep_Builder::TopoDSToStep_Builder
60 // ============================================================================
62 TopoDSToStep_Builder::TopoDSToStep_Builder
63 (const TopoDS_Shape& aShape,
64 TopoDSToStep_Tool& aTool, const Handle(Transfer_FinderProcess)& FP)
66 done = Standard_False;
67 Init(aShape, aTool, FP);
70 // ============================================================================
71 // Method : TopoDSToStep_Builder::Init
73 // ============================================================================
75 void TopoDSToStep_Builder::Init(const TopoDS_Shape& aShape,
76 TopoDSToStep_Tool& myTool,
77 const Handle(Transfer_FinderProcess)& FP)
80 if (myTool.IsBound(aShape)) {
81 myError = TopoDSToStep_BuilderDone;
83 myResult = myTool.Find(aShape);
87 Handle(Message_ProgressIndicator) progress = FP->GetProgress();
89 switch (aShape.ShapeType())
93 TopoDS_Shell myShell = TopoDS::Shell(aShape);
94 myTool.SetCurrentShell(myShell);
96 Handle(StepShape_FaceSurface) FS;
97 Handle(StepShape_TopologicalRepresentationItem) Fpms;
98 TColStd_SequenceOfTransient mySeq;
100 // const TopoDS_Shell ForwardShell =
101 // TopoDS::Shell(myShell.Oriented(TopAbs_FORWARD));
103 // TopExp_Explorer myExp(ForwardShell, TopAbs_FACE);
104 // CKY 9-DEC-1997 (PRO9824 et consorts)
105 // Pour passer les orientations : ELLES SONT DONNEES EN RELATIF
106 // Donc, pour SHELL, on doit l ecrire en direct en STEP (pas le choix)
107 // -> il faut repercuter en dessous, donc explorer le Shell TEL QUEL
108 // Pour FACE WIRE, d une part on ECRIT SON ORIENTATION relative au contenant
109 // (puisqu on peut), d autre part on EXPLORE EN FORWARD : ainsi les
110 // orientations des sous-shapes sont relatives a leur contenant immediat
111 // et la recombinaison en lecture est sans malice
112 // Il reste ici et la du code relatif a "en Faceted on combine differemment"
113 // -> reste encore du menage a faire
117 TopExp_Explorer myExp(myShell, TopAbs_FACE);
119 TopoDSToStep_MakeStepFace MkFace;
121 for (;myExp.More();myExp.Next()) {
123 const TopoDS_Face Face = TopoDS::Face(myExp.Current());
125 MkFace.Init(Face, myTool, FP);
127 if (MkFace.IsDone()) {
128 FS = Handle(StepShape_FaceSurface)::DownCast(MkFace.Value());
133 // MakeFace Error Handling : warning only
134 // cout << "Warning : one Face has not been mapped" << endl;
135 // Handle(TransferBRep_ShapeMapper) errShape =
136 // new TransferBRep_ShapeMapper(Face);
137 // FP->AddWarning(errShape, " a Face from a Shell has not been mapped");
139 if (!progress.IsNull()) progress->Increment();
142 Standard_Integer nbFaces = mySeq.Length();
144 Handle(StepShape_HArray1OfFace) aSet =
145 new StepShape_HArray1OfFace(1,nbFaces);
146 for (Standard_Integer i=1; i<=nbFaces; i++ ) {
147 aSet->SetValue(i, Handle(StepShape_Face)::DownCast(mySeq.Value(i)));
149 Handle(StepShape_ConnectedFaceSet) CFSpms;
150 if (myShell.Closed())
151 CFSpms = new StepShape_ClosedShell();
153 CFSpms = new StepShape_OpenShell();
154 Handle(TCollection_HAsciiString) aName =
155 new TCollection_HAsciiString("");
156 CFSpms->Init(aName, aSet);
158 // --------------------------------------------------------------
159 // To add later : if not facetted context & shell is reversed
160 // then shall create an oriented_shell with
161 // orientation flag to false.
162 // --------------------------------------------------------------
164 myTool.Bind(aShape, CFSpms);
166 done = Standard_True;
169 // Builder Error handling;
170 myError = TopoDSToStep_NoFaceMapped;
171 done = Standard_False;
178 const TopoDS_Face Face = TopoDS::Face(aShape);
180 Handle(StepShape_FaceSurface) FS;
181 Handle(StepShape_TopologicalRepresentationItem) Fpms;
183 TopoDSToStep_MakeStepFace MkFace(Face, myTool, FP);
185 if (MkFace.IsDone()) {
186 FS = Handle(StepShape_FaceSurface)::DownCast(MkFace.Value());
189 myError = TopoDSToStep_BuilderDone;
190 done = Standard_True;
193 // MakeFace Error Handling : Face not Mapped
194 myError = TopoDSToStep_BuilderOther;
195 // Handle(TransferBRep_ShapeMapper) errShape =
196 // new TransferBRep_ShapeMapper(Face);
197 // FP->AddWarning(errShape, " the Face has not been mapped");
198 done = Standard_False;
200 if (!progress.IsNull()) progress->Increment();
207 // ============================================================================
208 // Method : TopoDSToStep_Builder::Value
210 // ============================================================================
212 const Handle(StepShape_TopologicalRepresentationItem)&
213 TopoDSToStep_Builder::Value() const
215 StdFail_NotDone_Raise_if(!done,"");
219 // ============================================================================
220 // Method : TopoDSToStep_Builder::Error
222 // ============================================================================
224 TopoDSToStep_BuilderError TopoDSToStep_Builder::Error() const