1
/***************************************************************************
2
* Copyright (c) 2022 Werner Mayer <wmayer[at]users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
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. *
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. *
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 *
21
***************************************************************************/
23
#include "PreCompiled.h"
25
#include <Interface_Static.hxx>
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>
37
void ImportExportSettings::initialize()
39
// set the user-defined settings
40
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
41
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Part");
47
void ImportExportSettings::initGeneral(Base::Reference<ParameterGrp> hGrp)
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);
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
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);
76
void ImportExportSettings::initIGES(Base::Reference<ParameterGrp> hGrp)
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());
88
int unitIges = hIgesGrp->GetInt("Unit", 0);
91
Interface_Static::SetCVal("write.iges.unit","M");
94
Interface_Static::SetCVal("write.iges.unit","INCH");
97
Interface_Static::SetCVal("write.iges.unit","MM");
102
void ImportExportSettings::setImportCodePage(int cpIndex)
104
pGroup->SetInt("ImportCodePage", cpIndex);
107
Resource_FormatType ImportExportSettings::getImportCodePage() const
109
Resource_FormatType result {};
110
long codePageIndex = pGroup->GetInt("ImportCodePage", 0L);
112
for (const auto& codePageIt : codePageList) {
113
if (i == codePageIndex) {
114
result = codePageIt.codePage;
122
std::list<ImportExportSettings::CodePage> ImportExportSettings::getCodePageList() const
127
void ImportExportSettings::initSTEP(Base::Reference<ParameterGrp> hGrp)
130
Base::Reference<ParameterGrp> hStepGrp = hGrp->GetGroup("STEP");
131
int unitStep = hStepGrp->GetInt("Unit", 0);
134
Interface_Static::SetCVal("write.step.unit","M");
137
Interface_Static::SetCVal("write.step.unit","INCH");
140
Interface_Static::SetCVal("write.step.unit","MM");
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());
150
ImportExportSettings::ImportExportSettings()
152
pGroup = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Import");
155
STEP::ImportExportSettingsPtr ImportExportSettings::getSTEPSettings() const
158
step = std::make_shared<STEP::ImportExportSettings>();
164
IGES::ImportExportSettingsPtr ImportExportSettings::getIGESSettings() const
167
iges = std::make_shared<IGES::ImportExportSettings>();
173
void ImportExportSettings::setReadShapeCompoundMode(bool on)
175
auto grp = pGroup->GetGroup("hSTEP");
176
grp->SetBool("ReadShapeCompoundMode", on);
179
bool ImportExportSettings::getReadShapeCompoundMode() const
181
auto grp = pGroup->GetGroup("hSTEP");
182
return grp->GetBool("ReadShapeCompoundMode", false);
185
void ImportExportSettings::setExportHiddenObject(bool on)
187
pGroup->SetBool("ExportHiddenObject", on);
190
bool ImportExportSettings::getExportHiddenObject() const
192
return pGroup->GetBool("ExportHiddenObject", true);
195
void ImportExportSettings::setImportHiddenObject(bool on)
197
pGroup->SetBool("ImportHiddenObject", on);
200
bool ImportExportSettings::getImportHiddenObject() const
202
return pGroup->GetBool("ImportHiddenObject", true);
205
void ImportExportSettings::setExportLegacy(bool on)
207
pGroup->SetBool("ExportLegacy", on);
210
bool ImportExportSettings::getExportLegacy() const
212
return pGroup->GetBool("ExportLegacy", false);
215
void ImportExportSettings::setExportKeepPlacement(bool on)
217
pGroup->SetBool("ExportKeepPlacement", on);
220
bool ImportExportSettings::getExportKeepPlacement() const
222
return pGroup->GetBool("ExportKeepPlacement", false);
225
void ImportExportSettings::setUseLinkGroup(bool on)
227
pGroup->SetBool("UseLinkGroup", on);
230
bool ImportExportSettings::getUseLinkGroup() const
232
return pGroup->GetBool("UseLinkGroup", false);
235
void ImportExportSettings::setUseBaseName(bool on)
237
pGroup->SetBool("UseBaseName", on);
240
bool ImportExportSettings::getUseBaseName() const
242
return pGroup->GetBool("UseBaseName", true);
245
void ImportExportSettings::setReduceObjects(bool on)
247
pGroup->SetBool("ReduceObjects", on);
250
bool ImportExportSettings::getReduceObjects() const
252
return pGroup->GetBool("ReduceObjects", false);
255
void ImportExportSettings::setExpandCompound(bool on)
257
pGroup->SetBool("ExpandCompound", on);
260
bool ImportExportSettings::getExpandCompound() const
262
return pGroup->GetBool("ExpandCompound", false);
265
void ImportExportSettings::setShowProgress(bool on)
267
pGroup->SetBool("ShowProgress", on);
270
bool ImportExportSettings::getShowProgress() const
272
return pGroup->GetBool("ShowProgress", true);
275
void ImportExportSettings::setImportMode(ImportExportSettings::ImportMode mode)
277
pGroup->SetInt("ImportMode", static_cast<long>(mode));
280
ImportExportSettings::ImportMode ImportExportSettings::getImportMode() const
282
return static_cast<ImportExportSettings::ImportMode>(pGroup->GetInt("ImportMode", 0));