0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / StepToTopoDS / StepToTopoDS_TranslateShell.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 //:   gka 09.04.99: S4136: improving tolerance management
18
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>
31 #include <TopoDS.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>
37
38 // ============================================================================
39 // Method  : StepToTopoDS_TranslateShell::StepToTopoDS_TranslateShell
40 // Purpose : Empty Constructor
41 // ============================================================================
42 StepToTopoDS_TranslateShell::StepToTopoDS_TranslateShell()
43 : myError(StepToTopoDS_TranslateShellOther)
44 {
45   done = Standard_False;
46 }
47
48 // ============================================================================
49 // Method  : Init
50 // Purpose : Init with a ConnectedFaceSet and a Tool
51 // ============================================================================
52
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)
59 {
60   //bug15697
61   if(CFS.IsNull())
62     return;
63   
64   if (!aTool.IsBound(CFS)) {
65
66     BRep_Builder B;
67     Handle(Transfer_TransientProcess) TP = aTool.TransientProcess();
68
69     Standard_Integer NbFc = CFS->NbCfsFaces();
70     TopoDS_Shell Sh;
71     B.MakeShell(Sh);
72     TopoDS_Face F;
73     TopoDS_Shape S;
74     Handle(StepShape_Face) StepFace;
75
76     StepToTopoDS_TranslateFace myTranFace;
77     myTranFace.SetPrecision(Precision()); //gka
78     myTranFace.SetMaxTol(MaxTol());
79
80     Message_ProgressScope PS ( theProgress, "Face", NbFc);
81     for (Standard_Integer i = 1; i <= NbFc && PS.More(); i++, PS.Next()) {
82 #ifdef OCCT_DEBUG
83       std::cout << "Processing Face : " << i << std::endl;
84 #endif
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();
92           F = TopoDS::Face(S);
93           B.Add(Sh, F);
94         }
95         else { // Warning only + add FaceSurface file Identifier
96           TP->AddWarning(theFS, " a Face from Shell not mapped to TopoDS");
97         }
98       }
99       else { // Warning : add identifier
100         TP->AddWarning(StepFace, " Face is not of FaceSurface Type; not mapped to TopoDS");
101       }
102     }
103     Sh.Closed (BRep_Tool::IsClosed (Sh));
104     myResult = Sh;
105     aTool.Bind(CFS, myResult);
106     myError  = StepToTopoDS_TranslateShellDone;
107     done     = Standard_True;
108   }
109   else {
110     myResult = TopoDS::Shell(aTool.Find(CFS));
111     myError  = StepToTopoDS_TranslateShellDone;
112     done     = Standard_True;
113   }
114 }
115
116 // ============================================================================
117 // Method  : Init
118 // Purpose : Init with a ConnectedFaceSet and a Tool
119 // ============================================================================
120
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)
128 {
129   if (theTSh.IsNull())
130     return;
131
132   BRep_Builder aB;
133   TopoDS_Shell aSh;
134
135   Standard_Integer aNb = theTSh->NbItems();
136   Message_ProgressScope aPS(theProgress, "Face", theTSh->HasTopologicalLink() ? aNb + 1 : aNb);
137
138   Handle(Transfer_TransientProcess) aTP = theTool.TransientProcess();
139
140   if (theTSh->HasTopologicalLink()) 
141   {
142     Handle(TransferBRep_ShapeBinder) aBinder
143       = Handle(TransferBRep_ShapeBinder)::DownCast(aTP->Find(theTSh->TopologicalLink()));
144     if (!aBinder.IsNull()) 
145     {
146       aSh = aBinder->Shell();
147       theHasGeom = Standard_True;
148     }
149   }
150
151   Standard_Boolean aNewShell = Standard_False;
152   if (aSh.IsNull()) 
153   {
154     aB.MakeShell(aSh);
155     aNewShell = Standard_True;
156     theHasGeom = Standard_False;
157   }
158
159   StepToTopoDS_TranslateFace aTranTF;
160   aTranTF.SetPrecision(Precision());
161   aTranTF.SetMaxTol(MaxTol());
162
163   for (Standard_Integer i = 1; i <= aNb && aPS.More(); i++, aPS.Next()) 
164   {
165 #ifdef OCCT_DEBUG
166     std::cout << "Processing Face : " << i << std::endl;
167 #endif
168     Handle(StepVisual_TessellatedStructuredItem) anItem = theTSh->ItemsValue(i);
169     if (anItem->IsKind(STANDARD_TYPE(StepVisual_TessellatedFace))) 
170     {
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()) 
175       {
176         if (aNewShell) 
177         {
178           aB.Add(aSh, TopoDS::Face(aTranTF.Value()));
179         }
180         theHasGeom &= aHasFaceGeom;
181       }
182       else 
183       {
184         aTP->AddWarning(anItem, " Triangulated face if not mapped to TopoDS");
185       }
186     }
187     else 
188     {
189       aTP->AddWarning(anItem, " Face is not of TriangulatedFace Type; not mapped to TopoDS");
190     }
191   }
192
193   aSh.Closed(BRep_Tool::IsClosed(aSh));
194   myResult = aSh;
195   myError = StepToTopoDS_TranslateShellDone;
196   done = Standard_True;
197 }
198
199 // ============================================================================
200 // Method  : Value
201 // Purpose : Return the mapped Shape
202 // ============================================================================
203
204 const TopoDS_Shape& StepToTopoDS_TranslateShell::Value() const 
205 {
206   StdFail_NotDone_Raise_if (!done, "StepToTopoDS_TranslateShell::Value() - no result");
207   return myResult;
208 }
209
210 // ============================================================================
211 // Method  : Error
212 // Purpose : Return the TranslateShell Error code
213 // ============================================================================
214
215 StepToTopoDS_TranslateShellError StepToTopoDS_TranslateShell::Error() const
216 {
217   return myError;
218 }
219