77153b5112118a74bf2d69698a553638b5d116ae
[occt.git] / src / STEPControl / STEPControl_Writer.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #include <STEPControl_Writer.hxx>
15
16 #include <Interface_InterfaceModel.hxx>
17 #include <Interface_Macros.hxx>
18 #include <STEPControl_ActorWrite.hxx>
19 #include <STEPControl_Controller.hxx>
20 #include <StepData_StepModel.hxx>
21 #include <TopExp_Explorer.hxx>
22 #include <TopoDS_Shape.hxx>
23 #include <Transfer_FinderProcess.hxx>
24 #include <XSControl_TransferWriter.hxx>
25 #include <XSControl_WorkSession.hxx>
26
27 //=======================================================================
28 //function : STEPControl_Writer
29 //purpose  : 
30 //=======================================================================
31 STEPControl_Writer::STEPControl_Writer ()
32 {
33   STEPControl_Controller::Init();
34   SetWS (new XSControl_WorkSession);
35 }
36
37
38 //=======================================================================
39 //function : STEPControl_Writer
40
41 //purpose  : 
42 //=======================================================================
43
44 STEPControl_Writer::STEPControl_Writer
45   (const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch)
46 {
47   STEPControl_Controller::Init();
48   SetWS (WS,scratch);
49 }
50
51
52 //=======================================================================
53 //function : SetWS
54
55 //purpose  : 
56 //=======================================================================
57
58 void STEPControl_Writer::SetWS(const Handle(XSControl_WorkSession)& WS,
59                                const Standard_Boolean scratch)
60 {
61   thesession = WS;
62   thesession->SelectNorm("STEP");
63   thesession->InitTransferReader(0);
64   Handle(StepData_StepModel) model = Model (scratch);
65 }
66
67
68 //=======================================================================
69 //function : WS
70 //purpose  : 
71 //=======================================================================
72
73 Handle(XSControl_WorkSession) STEPControl_Writer::WS () const
74 {
75   return thesession;
76 }
77
78
79 //=======================================================================
80 //function : Model
81 //purpose  : 
82 //=======================================================================
83
84 Handle(StepData_StepModel) STEPControl_Writer::Model
85        (const Standard_Boolean newone)
86 {
87   DeclareAndCast(StepData_StepModel,model,thesession->Model());
88   if (newone || model.IsNull())
89     model = GetCasted(StepData_StepModel,thesession->NewModel());
90   return model;
91 }
92
93
94 //=======================================================================
95 //function : SetTolerance
96 //purpose  : 
97 //=======================================================================
98
99 void STEPControl_Writer::SetTolerance (const Standard_Real Tol)
100 {
101   DeclareAndCast(STEPControl_ActorWrite,act,WS()->NormAdaptor()->ActorWrite());
102   if (!act.IsNull()) act->SetTolerance (Tol);
103 }
104
105
106 //=======================================================================
107 //function : UnsetTolerance
108 //purpose  : 
109 //=======================================================================
110
111 void STEPControl_Writer::UnsetTolerance ()
112 {
113   SetTolerance (-1.);
114 }
115
116
117 //=======================================================================
118 //function : Transfer
119 //purpose  : 
120 //=======================================================================
121
122 IFSelect_ReturnStatus STEPControl_Writer::Transfer
123   (const TopoDS_Shape& sh,
124    const STEPControl_StepModelType mode,
125    const Standard_Boolean compgraph,
126    const Message_ProgressRange& theProgress)
127 {
128   Standard_Integer mws = -1;
129   switch (mode) {
130     case STEPControl_AsIs :                   mws = 0;  break;
131     case STEPControl_FacetedBrep :            mws = 1;  break;
132     case STEPControl_ShellBasedSurfaceModel : mws = 2;  break;
133     case STEPControl_ManifoldSolidBrep :      mws = 3;  break;
134     case STEPControl_GeometricCurveSet :      mws = 4;  break;
135     default : break;
136   }
137   if (mws < 0) return IFSelect_RetError;    // cas non reconnu
138   thesession->TransferWriter()->SetTransferMode (mws);
139
140   return thesession->TransferWriteShape(sh, compgraph, theProgress);
141 }
142
143
144 //=======================================================================
145 //function : Write
146 //purpose  : 
147 //=======================================================================
148
149 IFSelect_ReturnStatus STEPControl_Writer::Write (const Standard_CString filename)
150 {
151   return thesession->SendAll(filename);
152 }
153
154
155 //=======================================================================
156 //function : PrintStatsTransfer
157 //purpose  : 
158 //=======================================================================
159
160 void STEPControl_Writer::PrintStatsTransfer
161   (const Standard_Integer what, const Standard_Integer mode) const
162 {
163   thesession->TransferWriter()->PrintStats (what,mode);
164 }