1 // Created on: 1995-01-03
2 // Created by: Frederic MAUPAS
3 // Copyright (c) 1995-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.
17 //: gka 09.04.99: S4136: improving tolerance management
19 #include <BRep_Builder.hxx>
20 #include <Message_ProgressScope.hxx>
21 #include <StdFail_NotDone.hxx>
22 #include <StepData_Factors.hxx>
23 #include <StepShape_ConnectedFaceSet.hxx>
24 #include <StepShape_FaceSurface.hxx>
25 #include <StepToTopoDS_NMTool.hxx>
26 #include <StepToTopoDS_Tool.hxx>
27 #include <StepToTopoDS_TranslateFace.hxx>
28 #include <StepToTopoDS_TranslateShell.hxx>
29 #include <StepVisual_TessellatedShell.hxx>
30 #include <StepVisual_TriangulatedFace.hxx>
32 #include <TopoDS_Face.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <TopoDS_Shell.hxx>
35 #include <Transfer_TransientProcess.hxx>
36 #include <TransferBRep_ShapeBinder.hxx>
38 // ============================================================================
39 // Method : StepToTopoDS_TranslateShell::StepToTopoDS_TranslateShell
40 // Purpose : Empty Constructor
41 // ============================================================================
42 StepToTopoDS_TranslateShell::StepToTopoDS_TranslateShell()
43 : myError(StepToTopoDS_TranslateShellOther)
45 done = Standard_False;
48 // ============================================================================
50 // Purpose : Init with a ConnectedFaceSet and a Tool
51 // ============================================================================
53 void StepToTopoDS_TranslateShell::Init
54 (const Handle(StepShape_ConnectedFaceSet)& CFS,
55 StepToTopoDS_Tool& aTool,
56 StepToTopoDS_NMTool& NMTool,
57 const StepData_Factors& theLocalFactors,
58 const Message_ProgressRange& theProgress)
64 if (!aTool.IsBound(CFS)) {
67 Handle(Transfer_TransientProcess) TP = aTool.TransientProcess();
69 Standard_Integer NbFc = CFS->NbCfsFaces();
74 Handle(StepShape_Face) StepFace;
76 StepToTopoDS_TranslateFace myTranFace;
77 myTranFace.SetPrecision(Precision()); //gka
78 myTranFace.SetMaxTol(MaxTol());
80 Message_ProgressScope PS ( theProgress, "Face", NbFc);
81 for (Standard_Integer i = 1; i <= NbFc && PS.More(); i++, PS.Next()) {
83 std::cout << "Processing Face : " << i << std::endl;
85 StepFace = CFS->CfsFacesValue(i);
86 Handle(StepShape_FaceSurface) theFS =
87 Handle(StepShape_FaceSurface)::DownCast(StepFace);
88 if (!theFS.IsNull()) {
89 myTranFace.Init(theFS, aTool, NMTool, theLocalFactors);
90 if (myTranFace.IsDone()) {
91 S = myTranFace.Value();
95 else { // Warning only + add FaceSurface file Identifier
96 TP->AddWarning(theFS, " a Face from Shell not mapped to TopoDS");
99 else { // Warning : add identifier
100 TP->AddWarning(StepFace, " Face is not of FaceSurface Type; not mapped to TopoDS");
103 Sh.Closed (BRep_Tool::IsClosed (Sh));
105 aTool.Bind(CFS, myResult);
106 myError = StepToTopoDS_TranslateShellDone;
107 done = Standard_True;
110 myResult = TopoDS::Shell(aTool.Find(CFS));
111 myError = StepToTopoDS_TranslateShellDone;
112 done = Standard_True;
116 // ============================================================================
118 // Purpose : Init with a ConnectedFaceSet and a Tool
119 // ============================================================================
121 void StepToTopoDS_TranslateShell::Init(const Handle(StepVisual_TessellatedShell)& theTSh,
122 StepToTopoDS_Tool& theTool,
123 StepToTopoDS_NMTool& theNMTool,
124 const Standard_Boolean theReadTessellatedWhenNoBRepOnly,
125 Standard_Boolean& theHasGeom,
126 const StepData_Factors& theLocalFactors,
127 const Message_ProgressRange& theProgress)
135 Standard_Integer aNb = theTSh->NbItems();
136 Message_ProgressScope aPS(theProgress, "Face", theTSh->HasTopologicalLink() ? aNb + 1 : aNb);
138 Handle(Transfer_TransientProcess) aTP = theTool.TransientProcess();
140 if (theTSh->HasTopologicalLink())
142 Handle(TransferBRep_ShapeBinder) aBinder
143 = Handle(TransferBRep_ShapeBinder)::DownCast(aTP->Find(theTSh->TopologicalLink()));
144 if (!aBinder.IsNull())
146 aSh = aBinder->Shell();
147 theHasGeom = Standard_True;
151 Standard_Boolean aNewShell = Standard_False;
155 aNewShell = Standard_True;
156 theHasGeom = Standard_False;
159 StepToTopoDS_TranslateFace aTranTF;
160 aTranTF.SetPrecision(Precision());
161 aTranTF.SetMaxTol(MaxTol());
163 for (Standard_Integer i = 1; i <= aNb && aPS.More(); i++, aPS.Next())
166 std::cout << "Processing Face : " << i << std::endl;
168 Handle(StepVisual_TessellatedStructuredItem) anItem = theTSh->ItemsValue(i);
169 if (anItem->IsKind(STANDARD_TYPE(StepVisual_TessellatedFace)))
171 Handle(StepVisual_TessellatedFace) aTFace = Handle(StepVisual_TessellatedFace)::DownCast(anItem);
172 Standard_Boolean aHasFaceGeom = Standard_False;
173 aTranTF.Init(aTFace, theTool, theNMTool, theReadTessellatedWhenNoBRepOnly, aHasFaceGeom, theLocalFactors);
174 if (aTranTF.IsDone())
178 aB.Add(aSh, TopoDS::Face(aTranTF.Value()));
180 theHasGeom &= aHasFaceGeom;
184 aTP->AddWarning(anItem, " Triangulated face if not mapped to TopoDS");
189 aTP->AddWarning(anItem, " Face is not of TriangulatedFace Type; not mapped to TopoDS");
193 aSh.Closed(BRep_Tool::IsClosed(aSh));
195 myError = StepToTopoDS_TranslateShellDone;
196 done = Standard_True;
199 // ============================================================================
201 // Purpose : Return the mapped Shape
202 // ============================================================================
204 const TopoDS_Shape& StepToTopoDS_TranslateShell::Value() const
206 StdFail_NotDone_Raise_if (!done, "StepToTopoDS_TranslateShell::Value() - no result");
210 // ============================================================================
212 // Purpose : Return the TranslateShell Error code
213 // ============================================================================
215 StepToTopoDS_TranslateShellError StepToTopoDS_TranslateShell::Error() const