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()
45 : myError(TopoDSToStep_BuilderOther)
47 done = Standard_False;
50 // ============================================================================
51 // Method : TopoDSToStep_Builder::TopoDSToStep_Builder
53 // ============================================================================
55 TopoDSToStep_Builder::TopoDSToStep_Builder
56 (const TopoDS_Shape& aShape,
57 TopoDSToStep_Tool& aTool, const Handle(Transfer_FinderProcess)& FP)
59 done = Standard_False;
60 Init(aShape, aTool, FP);
63 // ============================================================================
64 // Method : TopoDSToStep_Builder::Init
66 // ============================================================================
68 void TopoDSToStep_Builder::Init(const TopoDS_Shape& aShape,
69 TopoDSToStep_Tool& myTool,
70 const Handle(Transfer_FinderProcess)& FP)
73 if (myTool.IsBound(aShape)) {
74 myError = TopoDSToStep_BuilderDone;
76 myResult = myTool.Find(aShape);
80 Handle(Message_ProgressIndicator) progress = FP->GetProgress();
82 switch (aShape.ShapeType())
86 TopoDS_Shell myShell = TopoDS::Shell(aShape);
87 myTool.SetCurrentShell(myShell);
89 Handle(StepShape_FaceSurface) FS;
90 Handle(StepShape_TopologicalRepresentationItem) Fpms;
91 TColStd_SequenceOfTransient mySeq;
93 // const TopoDS_Shell ForwardShell =
94 // TopoDS::Shell(myShell.Oriented(TopAbs_FORWARD));
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
110 TopExp_Explorer myExp(myShell, TopAbs_FACE);
112 TopoDSToStep_MakeStepFace MkFace;
114 for (;myExp.More();myExp.Next()) {
116 const TopoDS_Face Face = TopoDS::Face(myExp.Current());
118 MkFace.Init(Face, myTool, FP);
120 if (MkFace.IsDone()) {
121 FS = Handle(StepShape_FaceSurface)::DownCast(MkFace.Value());
126 // MakeFace Error Handling : warning only
127 // std::cout << "Warning : one Face has not been mapped" << std::endl;
128 // Handle(TransferBRep_ShapeMapper) errShape =
129 // new TransferBRep_ShapeMapper(Face);
130 // FP->AddWarning(errShape, " a Face from a Shell has not been mapped");
132 if (!progress.IsNull()) progress->Increment();
135 Standard_Integer nbFaces = mySeq.Length();
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)));
142 Handle(StepShape_ConnectedFaceSet) CFSpms;
143 if (myShell.Closed())
144 CFSpms = new StepShape_ClosedShell();
146 CFSpms = new StepShape_OpenShell();
147 Handle(TCollection_HAsciiString) aName =
148 new TCollection_HAsciiString("");
149 CFSpms->Init(aName, aSet);
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 // --------------------------------------------------------------
157 myTool.Bind(aShape, CFSpms);
159 done = Standard_True;
162 // Builder Error handling;
163 myError = TopoDSToStep_NoFaceMapped;
164 done = Standard_False;
171 const TopoDS_Face Face = TopoDS::Face(aShape);
173 Handle(StepShape_FaceSurface) FS;
174 Handle(StepShape_TopologicalRepresentationItem) Fpms;
176 TopoDSToStep_MakeStepFace MkFace(Face, myTool, FP);
178 if (MkFace.IsDone()) {
179 FS = Handle(StepShape_FaceSurface)::DownCast(MkFace.Value());
182 myError = TopoDSToStep_BuilderDone;
183 done = Standard_True;
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;
193 if (!progress.IsNull()) progress->Increment();
200 // ============================================================================
201 // Method : TopoDSToStep_Builder::Value
203 // ============================================================================
205 const Handle(StepShape_TopologicalRepresentationItem)&
206 TopoDSToStep_Builder::Value() const
208 StdFail_NotDone_Raise_if (!done, "TopoDSToStep_Builder::Value() - no result");
212 // ============================================================================
213 // Method : TopoDSToStep_Builder::Error
215 // ============================================================================
217 TopoDSToStep_BuilderError TopoDSToStep_Builder::Error() const