0025748: Parallel version of progress indicator
[occt.git] / src / TopoDSToStep / TopoDSToStep_Builder.cxx
CommitLineData
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
7e785937 18#include <Message_ProgressScope.hxx>
42cf5bc1 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 44TopoDSToStep_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
55TopoDSToStep_Builder::TopoDSToStep_Builder
56(const TopoDS_Shape& aShape,
7e785937 57 TopoDSToStep_Tool& aTool,
58 const Handle(Transfer_FinderProcess)& FP,
59 const Message_ProgressRange& theProgress)
7fd59977 60{
61 done = Standard_False;
7e785937 62 Init(aShape, aTool, FP, theProgress);
7fd59977 63}
64
65// ============================================================================
66// Method : TopoDSToStep_Builder::Init
67// Purpose :
68// ============================================================================
69
70void TopoDSToStep_Builder::Init(const TopoDS_Shape& aShape,
71 TopoDSToStep_Tool& myTool,
7e785937 72 const Handle(Transfer_FinderProcess)& FP,
73 const Message_ProgressRange& theProgress)
7fd59977 74{
75
76 if (myTool.IsBound(aShape)) {
77 myError = TopoDSToStep_BuilderDone;
78 done = Standard_True;
79 myResult = myTool.Find(aShape);
80 return;
81 }
82
7fd59977 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
7e785937 111 TopExp_Explorer anExp;
7fd59977 112
113 TopoDSToStep_MakeStepFace MkFace;
114
7e785937 115 Standard_Integer nbshapes = 0;
116 for (anExp.Init(myShell, TopAbs_FACE); anExp.More(); anExp.Next())
117 nbshapes++;
118 Message_ProgressScope aPS(theProgress, NULL, nbshapes);
119 for (anExp.Init(myShell, TopAbs_FACE); anExp.More() && aPS.More(); anExp.Next(), aPS.Next())
120 {
121 const TopoDS_Face Face = TopoDS::Face(anExp.Current());
7fd59977 122
7e785937 123 MkFace.Init(Face, myTool, FP);
7fd59977 124
125 if (MkFace.IsDone()) {
126 FS = Handle(StepShape_FaceSurface)::DownCast(MkFace.Value());
127 Fpms = FS;
128 mySeq.Append(Fpms);
129 }
130 else {
131 // MakeFace Error Handling : warning only
04232180 132// std::cout << "Warning : one Face has not been mapped" << std::endl;
7fd59977 133// Handle(TransferBRep_ShapeMapper) errShape =
134// new TransferBRep_ShapeMapper(Face);
135// FP->AddWarning(errShape, " a Face from a Shell has not been mapped");
136 }
7fd59977 137 }
7e785937 138 if (!aPS.More())
139 return;
7fd59977 140
141 Standard_Integer nbFaces = mySeq.Length();
142 if ( nbFaces >= 1) {
143 Handle(StepShape_HArray1OfFace) aSet =
144 new StepShape_HArray1OfFace(1,nbFaces);
145 for (Standard_Integer i=1; i<=nbFaces; i++ ) {
146 aSet->SetValue(i, Handle(StepShape_Face)::DownCast(mySeq.Value(i)));
147 }
148 Handle(StepShape_ConnectedFaceSet) CFSpms;
149 if (myShell.Closed())
150 CFSpms = new StepShape_ClosedShell();
151 else
152 CFSpms = new StepShape_OpenShell();
153 Handle(TCollection_HAsciiString) aName =
154 new TCollection_HAsciiString("");
155 CFSpms->Init(aName, aSet);
156
157 // --------------------------------------------------------------
158 // To add later : if not facetted context & shell is reversed
159 // then shall create an oriented_shell with
160 // orientation flag to false.
161 // --------------------------------------------------------------
162
163 myTool.Bind(aShape, CFSpms);
164 myResult = CFSpms;
165 done = Standard_True;
166 }
167 else {
168 // Builder Error handling;
169 myError = TopoDSToStep_NoFaceMapped;
170 done = Standard_False;
171 }
172 break;
173 }
174
175 case TopAbs_FACE:
176 {
177 const TopoDS_Face Face = TopoDS::Face(aShape);
178
179 Handle(StepShape_FaceSurface) FS;
180 Handle(StepShape_TopologicalRepresentationItem) Fpms;
181
182 TopoDSToStep_MakeStepFace MkFace(Face, myTool, FP);
183
184 if (MkFace.IsDone()) {
185 FS = Handle(StepShape_FaceSurface)::DownCast(MkFace.Value());
186 Fpms = FS;
187 myResult = Fpms;
188 myError = TopoDSToStep_BuilderDone;
189 done = Standard_True;
190 }
191 else {
192 // MakeFace Error Handling : Face not Mapped
193 myError = TopoDSToStep_BuilderOther;
194// Handle(TransferBRep_ShapeMapper) errShape =
195// new TransferBRep_ShapeMapper(Face);
196// FP->AddWarning(errShape, " the Face has not been mapped");
197 done = Standard_False;
198 }
7fd59977 199 break;
200 }
201 default: break;
202 }
203}
204
205// ============================================================================
206// Method : TopoDSToStep_Builder::Value
207// Purpose :
208// ============================================================================
209
210const Handle(StepShape_TopologicalRepresentationItem)&
211TopoDSToStep_Builder::Value() const
212{
2d2b3d53 213 StdFail_NotDone_Raise_if (!done, "TopoDSToStep_Builder::Value() - no result");
7fd59977 214 return myResult;
215}
216
217// ============================================================================
218// Method : TopoDSToStep_Builder::Error
219// Purpose :
220// ============================================================================
221
222TopoDSToStep_BuilderError TopoDSToStep_Builder::Error() const
223{
224 return myError;
225}
226