b311480e |
1 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
2 | // |
3 | // The content of this file is subject to the Open CASCADE Technology Public |
4 | // License Version 6.5 (the "License"). You may not use the content of this file |
5 | // except in compliance with the License. Please obtain a copy of the License |
6 | // at http://www.opencascade.org and read it completely before using this file. |
7 | // |
8 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
9 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
10 | // |
11 | // The Original Code and all software distributed under the License is |
12 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
13 | // Initial Developer hereby disclaims all such warranties, including without |
14 | // limitation, any warranties of merchantability, fitness for a particular |
15 | // purpose or non-infringement. Please see the License for the specific terms |
16 | // and conditions governing the rights and limitations under the License. |
17 | |
7fd59977 |
18 | #include <STEPControl_Writer.ixx> |
19 | #include <STEPControl_Controller.hxx> |
20 | #include <STEPControl_ActorWrite.hxx> |
21 | #include <XSControl_TransferWriter.hxx> |
22 | #include <Interface_InterfaceModel.hxx> |
23 | #include <Interface_Macros.hxx> |
24 | #include <Message_ProgressIndicator.hxx> |
25 | #include <TopExp_Explorer.hxx> |
26 | #include <Transfer_FinderProcess.hxx> |
27 | |
28 | |
29 | //======================================================================= |
30 | //function : STEPControl_Writer |
31 | //purpose : |
32 | //======================================================================= |
33 | |
34 | STEPControl_Writer::STEPControl_Writer () |
35 | { |
36 | STEPControl_Controller::Init(); |
37 | SetWS (new XSControl_WorkSession); |
38 | } |
39 | |
40 | |
41 | //======================================================================= |
42 | //function : STEPControl_Writer |
43 | |
44 | //purpose : |
45 | //======================================================================= |
46 | |
47 | STEPControl_Writer::STEPControl_Writer |
48 | (const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch) |
49 | { |
50 | STEPControl_Controller::Init(); |
51 | SetWS (WS,scratch); |
52 | } |
53 | |
54 | |
55 | //======================================================================= |
56 | //function : SetWS |
57 | |
58 | //purpose : |
59 | //======================================================================= |
60 | |
61 | void STEPControl_Writer::SetWS(const Handle(XSControl_WorkSession)& WS, |
62 | const Standard_Boolean scratch) |
63 | { |
64 | thesession = WS; |
65 | thesession->SelectNorm("STEP"); |
66 | thesession->InitTransferReader(0); |
67 | Handle(StepData_StepModel) model = Model (scratch); |
68 | } |
69 | |
70 | |
71 | //======================================================================= |
72 | //function : WS |
73 | //purpose : |
74 | //======================================================================= |
75 | |
76 | Handle(XSControl_WorkSession) STEPControl_Writer::WS () const |
77 | { |
78 | return thesession; |
79 | } |
80 | |
81 | |
82 | //======================================================================= |
83 | //function : Model |
84 | //purpose : |
85 | //======================================================================= |
86 | |
87 | Handle(StepData_StepModel) STEPControl_Writer::Model |
88 | (const Standard_Boolean newone) |
89 | { |
90 | DeclareAndCast(StepData_StepModel,model,thesession->Model()); |
91 | if (newone || model.IsNull()) |
92 | model = GetCasted(StepData_StepModel,thesession->NewModel()); |
93 | return model; |
94 | } |
95 | |
96 | |
97 | //======================================================================= |
98 | //function : SetTolerance |
99 | //purpose : |
100 | //======================================================================= |
101 | |
102 | void STEPControl_Writer::SetTolerance (const Standard_Real Tol) |
103 | { |
104 | DeclareAndCast(STEPControl_ActorWrite,act,WS()->NormAdaptor()->ActorWrite()); |
105 | if (!act.IsNull()) act->SetTolerance (Tol); |
106 | } |
107 | |
108 | |
109 | //======================================================================= |
110 | //function : UnsetTolerance |
111 | //purpose : |
112 | //======================================================================= |
113 | |
114 | void STEPControl_Writer::UnsetTolerance () |
115 | { |
116 | SetTolerance (-1.); |
117 | } |
118 | |
119 | |
120 | //======================================================================= |
121 | //function : Transfer |
122 | //purpose : |
123 | //======================================================================= |
124 | |
125 | IFSelect_ReturnStatus STEPControl_Writer::Transfer |
126 | (const TopoDS_Shape& sh, const STEPControl_StepModelType mode, |
127 | const Standard_Boolean compgraph) |
128 | { |
129 | Standard_Integer mws = -1; |
130 | switch (mode) { |
131 | case STEPControl_AsIs : mws = 0; break; |
132 | case STEPControl_FacetedBrep : mws = 1; break; |
133 | case STEPControl_ShellBasedSurfaceModel : mws = 2; break; |
134 | case STEPControl_ManifoldSolidBrep : mws = 3; break; |
135 | case STEPControl_GeometricCurveSet : mws = 4; break; |
136 | default : break; |
137 | } |
138 | if (mws < 0) return IFSelect_RetError; // cas non reconnu |
139 | thesession->SetModeWriteShape (mws); |
140 | |
141 | // for progress indicator. |
142 | Handle(Message_ProgressIndicator) progress = |
143 | WS()->TransferWriter()->FinderProcess()->GetProgress(); |
144 | if ( ! progress.IsNull() ) { |
145 | Standard_Integer nbfaces=0; |
146 | for( TopExp_Explorer exp(sh, TopAbs_FACE); exp.More(); exp.Next()) nbfaces++; |
147 | progress->SetScale ( "Face", 0, nbfaces, 1 ); |
148 | progress->Show(); |
149 | } |
150 | |
151 | return thesession->TransferWriteShape(sh,compgraph); |
152 | } |
153 | |
154 | |
155 | //======================================================================= |
156 | //function : Write |
157 | //purpose : |
158 | //======================================================================= |
159 | |
160 | IFSelect_ReturnStatus STEPControl_Writer::Write (const Standard_CString filename) |
161 | { |
162 | return thesession->SendAll(filename); |
163 | } |
164 | |
165 | |
166 | //======================================================================= |
167 | //function : PrintStatsTransfer |
168 | //purpose : |
169 | //======================================================================= |
170 | |
171 | void STEPControl_Writer::PrintStatsTransfer |
172 | (const Standard_Integer what, const Standard_Integer mode) const |
173 | { |
174 | thesession->TransferWriter()->PrintStats (what,mode); |
175 | } |