summaryrefslogtreecommitdiff
path: root/src/STEPControl/STEPControl_Writer.cxx
blob: 0bc049be79c180d24a868451df34a8373a1108e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <STEPControl_Writer.ixx>
#include <STEPControl_Controller.hxx>
#include <STEPControl_ActorWrite.hxx>
#include <XSControl_TransferWriter.hxx>
#include <Interface_InterfaceModel.hxx>
#include <Interface_Macros.hxx>
#include <Message_ProgressIndicator.hxx>
#include <TopExp_Explorer.hxx>
#include <Transfer_FinderProcess.hxx>


//=======================================================================
//function : STEPControl_Writer
//purpose  : 
//=======================================================================

STEPControl_Writer::STEPControl_Writer ()
{
  STEPControl_Controller::Init();
  SetWS (new XSControl_WorkSession);
}


//=======================================================================
//function : STEPControl_Writer

//purpose  : 
//=======================================================================

STEPControl_Writer::STEPControl_Writer
  (const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch)
{
  STEPControl_Controller::Init();
  SetWS (WS,scratch);
}


//=======================================================================
//function : SetWS

//purpose  : 
//=======================================================================

void STEPControl_Writer::SetWS(const Handle(XSControl_WorkSession)& WS,
                               const Standard_Boolean scratch)
{
  thesession = WS;
  thesession->SelectNorm("STEP");
  thesession->InitTransferReader(0);
  Handle(StepData_StepModel) model = Model (scratch);
}


//=======================================================================
//function : WS
//purpose  : 
//=======================================================================

Handle(XSControl_WorkSession) STEPControl_Writer::WS () const
{
  return thesession;
}


//=======================================================================
//function : Model
//purpose  : 
//=======================================================================

Handle(StepData_StepModel) STEPControl_Writer::Model
       (const Standard_Boolean newone)
{
  DeclareAndCast(StepData_StepModel,model,thesession->Model());
  if (newone || model.IsNull())
    model = GetCasted(StepData_StepModel,thesession->NewModel());
  return model;
}


//=======================================================================
//function : SetTolerance
//purpose  : 
//=======================================================================

void STEPControl_Writer::SetTolerance (const Standard_Real Tol)
{
  DeclareAndCast(STEPControl_ActorWrite,act,WS()->NormAdaptor()->ActorWrite());
  if (!act.IsNull()) act->SetTolerance (Tol);
}


//=======================================================================
//function : UnsetTolerance
//purpose  : 
//=======================================================================

void STEPControl_Writer::UnsetTolerance ()
{
  SetTolerance (-1.);
}


//=======================================================================
//function : Transfer
//purpose  : 
//=======================================================================

IFSelect_ReturnStatus STEPControl_Writer::Transfer
  (const TopoDS_Shape& sh, const STEPControl_StepModelType mode,
   const Standard_Boolean compgraph) 
{
  Standard_Integer mws = -1;
  switch (mode) {
    case STEPControl_AsIs :                   mws = 0;  break;
    case STEPControl_FacetedBrep :            mws = 1;  break;
    case STEPControl_ShellBasedSurfaceModel : mws = 2;  break;
    case STEPControl_ManifoldSolidBrep :      mws = 3;  break;
    case STEPControl_GeometricCurveSet :      mws = 4;  break;
    default : break;
  }
  if (mws < 0) return IFSelect_RetError;    // cas non reconnu
  thesession->SetModeWriteShape (mws);

  // for progress indicator.
  Handle(Message_ProgressIndicator) progress =
    WS()->TransferWriter()->FinderProcess()->GetProgress();
  if ( ! progress.IsNull() ) {
    Standard_Integer nbfaces=0;
    for( TopExp_Explorer exp(sh, TopAbs_FACE); exp.More(); exp.Next())  nbfaces++;
    progress->SetScale ( "Face", 0, nbfaces, 1 );
    progress->Show();
  }

  return thesession->TransferWriteShape(sh,compgraph);
}


//=======================================================================
//function : Write
//purpose  : 
//=======================================================================

IFSelect_ReturnStatus STEPControl_Writer::Write (const Standard_CString filename)
{
  return thesession->SendAll(filename);
}


//=======================================================================
//function : PrintStatsTransfer
//purpose  : 
//=======================================================================

void STEPControl_Writer::PrintStatsTransfer
  (const Standard_Integer what, const Standard_Integer mode) const
{
  thesession->TransferWriter()->PrintStats (what,mode);
}