0024428: Implementation of LGPL license
[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//
973c2be1 5// This library is free software; you can redistribute it and / or modify it
6// under the terms of the GNU Lesser General Public 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.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14#include <STEPControl_Writer.ixx>
15#include <STEPControl_Controller.hxx>
16#include <STEPControl_ActorWrite.hxx>
17#include <XSControl_TransferWriter.hxx>
18#include <Interface_InterfaceModel.hxx>
19#include <Interface_Macros.hxx>
20#include <Message_ProgressIndicator.hxx>
21#include <TopExp_Explorer.hxx>
22#include <Transfer_FinderProcess.hxx>
23
24
25//=======================================================================
26//function : STEPControl_Writer
27//purpose :
28//=======================================================================
29
30STEPControl_Writer::STEPControl_Writer ()
31{
32 STEPControl_Controller::Init();
33 SetWS (new XSControl_WorkSession);
34}
35
36
37//=======================================================================
38//function : STEPControl_Writer
39
40//purpose :
41//=======================================================================
42
43STEPControl_Writer::STEPControl_Writer
44 (const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch)
45{
46 STEPControl_Controller::Init();
47 SetWS (WS,scratch);
48}
49
50
51//=======================================================================
52//function : SetWS
53
54//purpose :
55//=======================================================================
56
57void STEPControl_Writer::SetWS(const Handle(XSControl_WorkSession)& WS,
58 const Standard_Boolean scratch)
59{
60 thesession = WS;
61 thesession->SelectNorm("STEP");
62 thesession->InitTransferReader(0);
63 Handle(StepData_StepModel) model = Model (scratch);
64}
65
66
67//=======================================================================
68//function : WS
69//purpose :
70//=======================================================================
71
72Handle(XSControl_WorkSession) STEPControl_Writer::WS () const
73{
74 return thesession;
75}
76
77
78//=======================================================================
79//function : Model
80//purpose :
81//=======================================================================
82
83Handle(StepData_StepModel) STEPControl_Writer::Model
84 (const Standard_Boolean newone)
85{
86 DeclareAndCast(StepData_StepModel,model,thesession->Model());
87 if (newone || model.IsNull())
88 model = GetCasted(StepData_StepModel,thesession->NewModel());
89 return model;
90}
91
92
93//=======================================================================
94//function : SetTolerance
95//purpose :
96//=======================================================================
97
98void STEPControl_Writer::SetTolerance (const Standard_Real Tol)
99{
100 DeclareAndCast(STEPControl_ActorWrite,act,WS()->NormAdaptor()->ActorWrite());
101 if (!act.IsNull()) act->SetTolerance (Tol);
102}
103
104
105//=======================================================================
106//function : UnsetTolerance
107//purpose :
108//=======================================================================
109
110void STEPControl_Writer::UnsetTolerance ()
111{
112 SetTolerance (-1.);
113}
114
115
116//=======================================================================
117//function : Transfer
118//purpose :
119//=======================================================================
120
121IFSelect_ReturnStatus STEPControl_Writer::Transfer
122 (const TopoDS_Shape& sh, const STEPControl_StepModelType mode,
123 const Standard_Boolean compgraph)
124{
125 Standard_Integer mws = -1;
126 switch (mode) {
127 case STEPControl_AsIs : mws = 0; break;
128 case STEPControl_FacetedBrep : mws = 1; break;
129 case STEPControl_ShellBasedSurfaceModel : mws = 2; break;
130 case STEPControl_ManifoldSolidBrep : mws = 3; break;
131 case STEPControl_GeometricCurveSet : mws = 4; break;
132 default : break;
133 }
134 if (mws < 0) return IFSelect_RetError; // cas non reconnu
135 thesession->SetModeWriteShape (mws);
136
137 // for progress indicator.
138 Handle(Message_ProgressIndicator) progress =
139 WS()->TransferWriter()->FinderProcess()->GetProgress();
140 if ( ! progress.IsNull() ) {
141 Standard_Integer nbfaces=0;
142 for( TopExp_Explorer exp(sh, TopAbs_FACE); exp.More(); exp.Next()) nbfaces++;
143 progress->SetScale ( "Face", 0, nbfaces, 1 );
144 progress->Show();
145 }
146
147 return thesession->TransferWriteShape(sh,compgraph);
148}
149
150
151//=======================================================================
152//function : Write
153//purpose :
154//=======================================================================
155
156IFSelect_ReturnStatus STEPControl_Writer::Write (const Standard_CString filename)
157{
158 return thesession->SendAll(filename);
159}
160
161
162//=======================================================================
163//function : PrintStatsTransfer
164//purpose :
165//=======================================================================
166
167void STEPControl_Writer::PrintStatsTransfer
168 (const Standard_Integer what, const Standard_Integer mode) const
169{
170 thesession->TransferWriter()->PrintStats (what,mode);
171}