0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / STEPControl / STEPControl_Writer.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 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
973c2be1 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.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
148820b2 14#include <STEPControl_Writer.hxx>
42cf5bc1 15
7fd59977 16#include <Interface_InterfaceModel.hxx>
17#include <Interface_Macros.hxx>
42cf5bc1 18#include <STEPControl_ActorWrite.hxx>
19#include <STEPControl_Controller.hxx>
b9fbc699 20#include <StepData_ConfParameters.hxx>
42cf5bc1 21#include <StepData_StepModel.hxx>
3e06b706 22#include <StepData_Protocol.hxx>
23#include <StepData_StepWriter.hxx>
24#include <TopExp_Explorer.hxx>
42cf5bc1 25#include <TopoDS_Shape.hxx>
da80ff68 26#include <XSAlgo.hxx>
27#include <XSAlgo_AlgoContainer.hxx>
42cf5bc1 28#include <XSControl_WorkSession.hxx>
da80ff68 29#include <UnitsMethods.hxx>
7fd59977 30
31//=======================================================================
32//function : STEPControl_Writer
33//purpose :
34//=======================================================================
7fd59977 35STEPControl_Writer::STEPControl_Writer ()
36{
37 STEPControl_Controller::Init();
38 SetWS (new XSControl_WorkSession);
39}
40
41
42//=======================================================================
43//function : STEPControl_Writer
44
45//purpose :
46//=======================================================================
47
48STEPControl_Writer::STEPControl_Writer
49 (const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch)
50{
51 STEPControl_Controller::Init();
52 SetWS (WS,scratch);
53}
54
55
56//=======================================================================
57//function : SetWS
58
59//purpose :
60//=======================================================================
61
62void STEPControl_Writer::SetWS(const Handle(XSControl_WorkSession)& WS,
63 const Standard_Boolean scratch)
64{
65 thesession = WS;
66 thesession->SelectNorm("STEP");
67 thesession->InitTransferReader(0);
68 Handle(StepData_StepModel) model = Model (scratch);
69}
70
71
72//=======================================================================
73//function : WS
74//purpose :
75//=======================================================================
76
77Handle(XSControl_WorkSession) STEPControl_Writer::WS () const
78{
79 return thesession;
80}
81
82
83//=======================================================================
84//function : Model
85//purpose :
86//=======================================================================
87
88Handle(StepData_StepModel) STEPControl_Writer::Model
89 (const Standard_Boolean newone)
90{
91 DeclareAndCast(StepData_StepModel,model,thesession->Model());
92 if (newone || model.IsNull())
93 model = GetCasted(StepData_StepModel,thesession->NewModel());
94 return model;
95}
96
97
98//=======================================================================
99//function : SetTolerance
100//purpose :
101//=======================================================================
102
103void STEPControl_Writer::SetTolerance (const Standard_Real Tol)
104{
105 DeclareAndCast(STEPControl_ActorWrite,act,WS()->NormAdaptor()->ActorWrite());
106 if (!act.IsNull()) act->SetTolerance (Tol);
107}
108
109
110//=======================================================================
111//function : UnsetTolerance
112//purpose :
113//=======================================================================
114
115void STEPControl_Writer::UnsetTolerance ()
116{
117 SetTolerance (-1.);
118}
119
120
121//=======================================================================
122//function : Transfer
123//purpose :
124//=======================================================================
125
126IFSelect_ReturnStatus STEPControl_Writer::Transfer
7e785937 127 (const TopoDS_Shape& sh,
128 const STEPControl_StepModelType mode,
129 const Standard_Boolean compgraph,
130 const Message_ProgressRange& theProgress)
b9fbc699 131{
132 Handle(StepData_StepModel) aStepModel = Handle(StepData_StepModel)::DownCast(thesession->Model());
133 if (!aStepModel.IsNull())
134 {
135 aStepModel->InternalParameters.InitFromStatic();
136 }
137 return Transfer(sh, mode, aStepModel->InternalParameters, compgraph, theProgress);
138}
139
140IFSelect_ReturnStatus STEPControl_Writer::Transfer
141 (const TopoDS_Shape& sh,
142 const STEPControl_StepModelType mode,
143 const StepData_ConfParameters& theParams,
144 const Standard_Boolean compgraph,
145 const Message_ProgressRange& theProgress)
7fd59977 146{
147 Standard_Integer mws = -1;
148 switch (mode) {
149 case STEPControl_AsIs : mws = 0; break;
150 case STEPControl_FacetedBrep : mws = 1; break;
151 case STEPControl_ShellBasedSurfaceModel : mws = 2; break;
152 case STEPControl_ManifoldSolidBrep : mws = 3; break;
153 case STEPControl_GeometricCurveSet : mws = 4; break;
154 default : break;
155 }
156 if (mws < 0) return IFSelect_RetError; // cas non reconnu
7f56eba8 157 thesession->TransferWriter()->SetTransferMode (mws);
da80ff68 158 if (!Model()->IsInitializedUnit())
159 {
160 XSAlgo::AlgoContainer()->PrepareForTransfer(); // update unit info
161 Model()->SetLocalLengthUnit(UnitsMethods::GetCasCadeLengthUnit());
162 }
b9fbc699 163 if (!thesession->Model().IsNull())
164 {
165 Handle(StepData_StepModel)::DownCast(thesession->Model())->InternalParameters = theParams;
166 }
167 Handle(STEPControl_ActorWrite) ActWrite =
168 Handle(STEPControl_ActorWrite)::DownCast(WS()->NormAdaptor()->ActorWrite());
169 ActWrite->SetGroupMode(Handle(StepData_StepModel)::DownCast(thesession->Model())->InternalParameters.WriteAssembly);
7e785937 170 return thesession->TransferWriteShape(sh, compgraph, theProgress);
7fd59977 171}
172
173
174//=======================================================================
175//function : Write
3e06b706 176//purpose :
7fd59977 177//=======================================================================
3e06b706 178IFSelect_ReturnStatus STEPControl_Writer::Write (const Standard_CString theFileName)
7fd59977 179{
3e06b706 180 return thesession->SendAll (theFileName);
7fd59977 181}
182
3e06b706 183//=======================================================================
184//function : WriteStream
185//purpose :
186//=======================================================================
187IFSelect_ReturnStatus STEPControl_Writer::WriteStream (std::ostream& theOStream)
188{
189 Handle(StepData_StepModel) aModel = Model();
190 if (aModel.IsNull())
191 {
192 return IFSelect_RetFail;
193 }
194
195 Handle(StepData_Protocol) aProtocol = Handle(StepData_Protocol)::DownCast (aModel->Protocol());
196 if (aProtocol.IsNull())
197 {
198 return IFSelect_RetFail;
199 }
200
201 StepData_StepWriter aWriter (aModel);
202 aWriter.SendModel (aProtocol);
203 return aWriter.Print (theOStream)
204 ? IFSelect_RetDone
205 : IFSelect_RetFail;
206}
7fd59977 207
208//=======================================================================
209//function : PrintStatsTransfer
210//purpose :
211//=======================================================================
212
213void STEPControl_Writer::PrintStatsTransfer
214 (const Standard_Integer what, const Standard_Integer mode) const
215{
216 thesession->TransferWriter()->PrintStats (what,mode);
217}