1 // Created on: 1994-11-25
2 // Created by: Frederic MAUPAS
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Message_ProgressIndicator.hxx>
19 #include <StdFail_NotDone.hxx>
20 #include <StepShape_ClosedShell.hxx>
21 #include <StepShape_ConnectedFaceSet.hxx>
22 #include <StepShape_Face.hxx>
23 #include <StepShape_FaceSurface.hxx>
24 #include <StepShape_HArray1OfFace.hxx>
25 #include <StepShape_OpenShell.hxx>
26 #include <StepShape_TopologicalRepresentationItem.hxx>
27 #include <TCollection_HAsciiString.hxx>
28 #include <TColStd_SequenceOfTransient.hxx>
29 #include <TopExp_Explorer.hxx>
31 #include <TopoDS_Face.hxx>
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>
38 #include <TransferBRep_ShapeMapper.hxx>
40 // ============================================================================
41 // Method : TopoDSToStep_Builder::TopoDSToStep_Builder
43 // ============================================================================
44 TopoDSToStep_Builder::TopoDSToStep_Builder()
46 done = Standard_False;
49 // ============================================================================
50 // Method : TopoDSToStep_Builder::TopoDSToStep_Builder
52 // ============================================================================
54 TopoDSToStep_Builder::TopoDSToStep_Builder
55 (const TopoDS_Shape& aShape,
56 TopoDSToStep_Tool& aTool, const Handle(Transfer_FinderProcess)& FP)
58 done = Standard_False;
59 Init(aShape, aTool, FP);
62 // ============================================================================
63 // Method : TopoDSToStep_Builder::Init
65 // ============================================================================
67 void TopoDSToStep_Builder::Init(const TopoDS_Shape& aShape,
68 TopoDSToStep_Tool& myTool,
69 const Handle(Transfer_FinderProcess)& FP)
72 if (myTool.IsBound(aShape)) {
73 myError = TopoDSToStep_BuilderDone;
75 myResult = myTool.Find(aShape);
79 Handle(Message_ProgressIndicator) progress = FP->GetProgress();
81 switch (aShape.ShapeType())
85 TopoDS_Shell myShell = TopoDS::Shell(aShape);
86 myTool.SetCurrentShell(myShell);
88 Handle(StepShape_FaceSurface) FS;
89 Handle(StepShape_TopologicalRepresentationItem) Fpms;
90 TColStd_SequenceOfTransient mySeq;
92 // const TopoDS_Shell ForwardShell =
93 // TopoDS::Shell(myShell.Oriented(TopAbs_FORWARD));
95 // TopExp_Explorer myExp(ForwardShell, TopAbs_FACE);
96 // CKY 9-DEC-1997 (PRO9824 et consorts)
97 // Pour passer les orientations : ELLES SONT DONNEES EN RELATIF
98 // Donc, pour SHELL, on doit l ecrire en direct en STEP (pas le choix)
99 // -> il faut repercuter en dessous, donc explorer le Shell TEL QUEL
100 // Pour FACE WIRE, d une part on ECRIT SON ORIENTATION relative au contenant
101 // (puisqu on peut), d autre part on EXPLORE EN FORWARD : ainsi les
102 // orientations des sous-shapes sont relatives a leur contenant immediat
103 // et la recombinaison en lecture est sans malice
104 // Il reste ici et la du code relatif a "en Faceted on combine differemment"
105 // -> reste encore du menage a faire
109 TopExp_Explorer myExp(myShell, TopAbs_FACE);
111 TopoDSToStep_MakeStepFace MkFace;
113 for (;myExp.More();myExp.Next()) {
115 const TopoDS_Face Face = TopoDS::Face(myExp.Current());
117 MkFace.Init(Face, myTool, FP);
119 if (MkFace.IsDone()) {
120 FS = Handle(StepShape_FaceSurface)::DownCast(MkFace.Value());
125 // MakeFace Error Handling : warning only
126 // cout << "Warning : one Face has not been mapped" << endl;
127 // Handle(TransferBRep_ShapeMapper) errShape =
128 // new TransferBRep_ShapeMapper(Face);
129 // FP->AddWarning(errShape, " a Face from a Shell has not been mapped");
131 if (!progress.IsNull()) progress->Increment();
134 Standard_Integer nbFaces = mySeq.Length();
136 Handle(StepShape_HArray1OfFace) aSet =
137 new StepShape_HArray1OfFace(1,nbFaces);
138 for (Standard_Integer i=1; i<=nbFaces; i++ ) {
139 aSet->SetValue(i, Handle(StepShape_Face)::DownCast(mySeq.Value(i)));
141 Handle(StepShape_ConnectedFaceSet) CFSpms;
142 if (myShell.Closed())
143 CFSpms = new StepShape_ClosedShell();
145 CFSpms = new StepShape_OpenShell();
146 Handle(TCollection_HAsciiString) aName =
147 new TCollection_HAsciiString("");
148 CFSpms->Init(aName, aSet);
150 // --------------------------------------------------------------
151 // To add later : if not facetted context & shell is reversed
152 // then shall create an oriented_shell with
153 // orientation flag to false.
154 // --------------------------------------------------------------
156 myTool.Bind(aShape, CFSpms);
158 done = Standard_True;
161 // Builder Error handling;
162 myError = TopoDSToStep_NoFaceMapped;
163 done = Standard_False;
170 const TopoDS_Face Face = TopoDS::Face(aShape);
172 Handle(StepShape_FaceSurface) FS;
173 Handle(StepShape_TopologicalRepresentationItem) Fpms;
175 TopoDSToStep_MakeStepFace MkFace(Face, myTool, FP);
177 if (MkFace.IsDone()) {
178 FS = Handle(StepShape_FaceSurface)::DownCast(MkFace.Value());
181 myError = TopoDSToStep_BuilderDone;
182 done = Standard_True;
185 // MakeFace Error Handling : Face not Mapped
186 myError = TopoDSToStep_BuilderOther;
187 // Handle(TransferBRep_ShapeMapper) errShape =
188 // new TransferBRep_ShapeMapper(Face);
189 // FP->AddWarning(errShape, " the Face has not been mapped");
190 done = Standard_False;
192 if (!progress.IsNull()) progress->Increment();
199 // ============================================================================
200 // Method : TopoDSToStep_Builder::Value
202 // ============================================================================
204 const Handle(StepShape_TopologicalRepresentationItem)&
205 TopoDSToStep_Builder::Value() const
207 StdFail_NotDone_Raise_if(!done,"");
211 // ============================================================================
212 // Method : TopoDSToStep_Builder::Error
214 // ============================================================================
216 TopoDSToStep_BuilderError TopoDSToStep_Builder::Error() const