FreeCAD

Форк
0
/
ImportExportSettings.cpp 
286 строк · 9.5 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2022 Werner Mayer <wmayer[at]users.sourceforge.net>     *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
6
 *   This library is free software; you can redistribute it and/or         *
7
 *   modify it under the terms of the GNU Library General Public           *
8
 *   License as published by the Free Software Foundation; either          *
9
 *   version 2 of the License, or (at your option) any later version.      *
10
 *                                                                         *
11
 *   This library  is distributed in the hope that it will be useful,      *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 *   GNU Library General Public License for more details.                  *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU Library General Public     *
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24
#ifndef _PreComp_
25
#include <Interface_Static.hxx>
26
#endif
27

28
#include "ImportExportSettings.h"
29
#include <Mod/Part/App/IGES/ImportExportSettings.h>
30
#include <Mod/Part/App/STEP/ImportExportSettings.h>
31
#include <App/Application.h>
32

33

34
namespace Part {
35
namespace OCAF {
36

37
void ImportExportSettings::initialize()
38
{
39
    // set the user-defined settings
40
    Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
41
        .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Part");
42
    initGeneral(hGrp);
43
    initSTEP(hGrp);
44
    initIGES(hGrp);
45
}
46

47
void ImportExportSettings::initGeneral(Base::Reference<ParameterGrp> hGrp)
48
{
49
    // General
50
    Base::Reference<ParameterGrp> hGenGrp = hGrp->GetGroup("General");
51
    // http://www.opencascade.org/org/forum/thread_20801/
52
    // read.surfacecurve.mode:
53
    // A preference for the computation of curves in an entity which has both 2D and 3D representation.
54
    // Each TopoDS_Edge in TopoDS_Face must have a 3D and 2D curve that references the surface.
55
    // If both 2D and 3D representation of the entity are present, the computation of these curves depends on
56
    // the following values of parameter:
57
    // 0: "Default" - no preference, both curves are taken
58
    // 3: "3DUse_Preferred" - 3D curves are used to rebuild 2D ones
59
    // Additional modes for IGES
60
    //  2: "2DUse_Preferred" - the 2D is used to rebuild the 3D in case of their inconsistency
61
    // -2: "2DUse_Forced" - the 2D is always used to rebuild the 3D (even if 2D is present in the file)
62
    // -3: "3DUse_Forced" - the 3D is always used to rebuild the 2D (even if 2D is present in the file)
63
    int readsurfacecurve = hGenGrp->GetInt("ReadSurfaceCurveMode", 0);
64
    Interface_Static::SetIVal("read.surfacecurve.mode", readsurfacecurve);
65

66
    // write.surfacecurve.mode (STEP-only):
67
    // This parameter indicates whether parametric curves (curves in parametric space of surface) should be
68
    // written into the STEP file. This parameter can be set to Off in order to minimize the size of the resulting
69
    // STEP file.
70
    // Off (0) : writes STEP files without pcurves. This mode decreases the size of the resulting file.
71
    // On (1) : (default) writes pcurves to STEP file
72
    int writesurfacecurve = hGenGrp->GetInt("WriteSurfaceCurveMode", 0);
73
    Interface_Static::SetIVal("write.surfacecurve.mode", writesurfacecurve);
74
}
75

76
void ImportExportSettings::initIGES(Base::Reference<ParameterGrp> hGrp)
77
{
78
    //IGES handling
79
    Base::Reference<ParameterGrp> hIgesGrp = hGrp->GetGroup("IGES");
80
    int value = Interface_Static::IVal("write.iges.brep.mode");
81
    bool brep = hIgesGrp->GetBool("BrepMode", value > 0);
82
    Interface_Static::SetIVal("write.iges.brep.mode",brep ? 1 : 0);
83
    Interface_Static::SetCVal("write.iges.header.company", hIgesGrp->GetASCII("Company").c_str());
84
    Interface_Static::SetCVal("write.iges.header.author", hIgesGrp->GetASCII("Author").c_str());
85
    Interface_Static::SetCVal("write.iges.header.product", hIgesGrp->GetASCII("Product",
86
       Interface_Static::CVal("write.iges.header.product")).c_str());
87

88
    int unitIges = hIgesGrp->GetInt("Unit", 0);
89
    switch (unitIges) {
90
        case 1:
91
            Interface_Static::SetCVal("write.iges.unit","M");
92
            break;
93
        case 2:
94
            Interface_Static::SetCVal("write.iges.unit","INCH");
95
            break;
96
        default:
97
            Interface_Static::SetCVal("write.iges.unit","MM");
98
            break;
99
    }
100
}
101

102
void ImportExportSettings::setImportCodePage(int cpIndex)
103
{
104
    pGroup->SetInt("ImportCodePage", cpIndex);
105
}
106

107
Resource_FormatType ImportExportSettings::getImportCodePage() const
108
{
109
    Resource_FormatType result {};
110
    long codePageIndex = pGroup->GetInt("ImportCodePage", 0L);
111
    long i = 0L;
112
    for (const auto& codePageIt : codePageList) {
113
        if (i == codePageIndex) {
114
            result = codePageIt.codePage;
115
            break;
116
        }
117
        i++;
118
    }
119
    return result;
120
}
121

122
std::list<ImportExportSettings::CodePage> ImportExportSettings::getCodePageList() const
123
{
124
    return codePageList;
125
}
126

127
void ImportExportSettings::initSTEP(Base::Reference<ParameterGrp> hGrp)
128
{
129
    //STEP handling
130
    Base::Reference<ParameterGrp> hStepGrp = hGrp->GetGroup("STEP");
131
    int unitStep = hStepGrp->GetInt("Unit", 0);
132
    switch (unitStep) {
133
        case 1:
134
            Interface_Static::SetCVal("write.step.unit","M");
135
            break;
136
        case 2:
137
            Interface_Static::SetCVal("write.step.unit","INCH");
138
            break;
139
        default:
140
            Interface_Static::SetCVal("write.step.unit","MM");
141
            break;
142
    }
143

144
    std::string ap = hStepGrp->GetASCII("Scheme", Interface_Static::CVal("write.step.schema"));
145
    Interface_Static::SetCVal("write.step.schema", ap.c_str());
146
    Interface_Static::SetCVal("write.step.product.name", hStepGrp->GetASCII("Product",
147
       Interface_Static::CVal("write.step.product.name")).c_str());
148
}
149

150
ImportExportSettings::ImportExportSettings()
151
{
152
    pGroup = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Import");
153
}
154

155
STEP::ImportExportSettingsPtr ImportExportSettings::getSTEPSettings() const
156
{
157
    if (!step) {
158
        step = std::make_shared<STEP::ImportExportSettings>();
159
    }
160

161
    return step;
162
}
163

164
IGES::ImportExportSettingsPtr ImportExportSettings::getIGESSettings() const
165
{
166
    if (!iges) {
167
        iges = std::make_shared<IGES::ImportExportSettings>();
168
    }
169

170
    return iges;
171
}
172

173
void ImportExportSettings::setReadShapeCompoundMode(bool on)
174
{
175
    auto grp = pGroup->GetGroup("hSTEP");
176
    grp->SetBool("ReadShapeCompoundMode", on);
177
}
178

179
bool ImportExportSettings::getReadShapeCompoundMode() const
180
{
181
    auto grp = pGroup->GetGroup("hSTEP");
182
    return grp->GetBool("ReadShapeCompoundMode", false);
183
}
184

185
void ImportExportSettings::setExportHiddenObject(bool on)
186
{
187
    pGroup->SetBool("ExportHiddenObject", on);
188
}
189

190
bool ImportExportSettings::getExportHiddenObject() const
191
{
192
    return pGroup->GetBool("ExportHiddenObject", true);
193
}
194

195
void ImportExportSettings::setImportHiddenObject(bool on)
196
{
197
    pGroup->SetBool("ImportHiddenObject", on);
198
}
199

200
bool ImportExportSettings::getImportHiddenObject() const
201
{
202
    return pGroup->GetBool("ImportHiddenObject", true);
203
}
204

205
void ImportExportSettings::setExportLegacy(bool on)
206
{
207
    pGroup->SetBool("ExportLegacy", on);
208
}
209

210
bool ImportExportSettings::getExportLegacy() const
211
{
212
    return pGroup->GetBool("ExportLegacy", false);
213
}
214

215
void ImportExportSettings::setExportKeepPlacement(bool on)
216
{
217
    pGroup->SetBool("ExportKeepPlacement", on);
218
}
219

220
bool ImportExportSettings::getExportKeepPlacement() const
221
{
222
    return pGroup->GetBool("ExportKeepPlacement", false);
223
}
224

225
void ImportExportSettings::setUseLinkGroup(bool on)
226
{
227
    pGroup->SetBool("UseLinkGroup", on);
228
}
229

230
bool ImportExportSettings::getUseLinkGroup() const
231
{
232
    return pGroup->GetBool("UseLinkGroup", false);
233
}
234

235
void ImportExportSettings::setUseBaseName(bool on)
236
{
237
    pGroup->SetBool("UseBaseName", on);
238
}
239

240
bool ImportExportSettings::getUseBaseName() const
241
{
242
    return pGroup->GetBool("UseBaseName", true);
243
}
244

245
void ImportExportSettings::setReduceObjects(bool on)
246
{
247
    pGroup->SetBool("ReduceObjects", on);
248
}
249

250
bool ImportExportSettings::getReduceObjects() const
251
{
252
    return pGroup->GetBool("ReduceObjects", false);
253
}
254

255
void ImportExportSettings::setExpandCompound(bool on)
256
{
257
    pGroup->SetBool("ExpandCompound", on);
258
}
259

260
bool ImportExportSettings::getExpandCompound() const
261
{
262
    return pGroup->GetBool("ExpandCompound", false);
263
}
264

265
void ImportExportSettings::setShowProgress(bool on)
266
{
267
    pGroup->SetBool("ShowProgress", on);
268
}
269

270
bool ImportExportSettings::getShowProgress() const
271
{
272
    return pGroup->GetBool("ShowProgress", true);
273
}
274

275
void ImportExportSettings::setImportMode(ImportExportSettings::ImportMode mode)
276
{
277
    pGroup->SetInt("ImportMode", static_cast<long>(mode));
278
}
279

280
ImportExportSettings::ImportMode ImportExportSettings::getImportMode() const
281
{
282
    return static_cast<ImportExportSettings::ImportMode>(pGroup->GetInt("ImportMode", 0));
283
}
284

285
} // namespace OCAF
286
} // namespace Part
287

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.