File size: 9,922 Bytes
985c397 | 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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | // SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2022 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include <Interface_Static.hxx>
#include "ImportExportSettings.h"
#include <Mod/Part/App/IGES/ImportExportSettings.h>
#include <Mod/Part/App/STEP/ImportExportSettings.h>
#include <App/Application.h>
namespace Part
{
namespace OCAF
{
void ImportExportSettings::initialize()
{
// set the user-defined settings
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/Part");
initGeneral(hGrp);
initSTEP(hGrp);
initIGES(hGrp);
}
void ImportExportSettings::initGeneral(Base::Reference<ParameterGrp> hGrp)
{
// General
Base::Reference<ParameterGrp> hGenGrp = hGrp->GetGroup("General");
// http://www.opencascade.org/org/forum/thread_20801/
// read.surfacecurve.mode:
// A preference for the computation of curves in an entity which has both 2D and 3D
// representation. Each TopoDS_Edge in TopoDS_Face must have a 3D and 2D curve that references
// the surface. If both 2D and 3D representation of the entity are present, the computation of
// these curves depends on the following values of parameter: 0: "Default" - no preference, both
// curves are taken 3: "3DUse_Preferred" - 3D curves are used to rebuild 2D ones Additional
// modes for IGES
// 2: "2DUse_Preferred" - the 2D is used to rebuild the 3D in case of their inconsistency
// -2: "2DUse_Forced" - the 2D is always used to rebuild the 3D (even if 2D is present in the
// file) -3: "3DUse_Forced" - the 3D is always used to rebuild the 2D (even if 2D is present in
// the file)
int readsurfacecurve = hGenGrp->GetInt("ReadSurfaceCurveMode", 0);
Interface_Static::SetIVal("read.surfacecurve.mode", readsurfacecurve);
// write.surfacecurve.mode (STEP-only):
// This parameter indicates whether parametric curves (curves in parametric space of surface)
// should be written into the STEP file. This parameter can be set to Off in order to minimize
// the size of the resulting STEP file. Off (0) : writes STEP files without pcurves. This mode
// decreases the size of the resulting file. On (1) : (default) writes pcurves to STEP file
int writesurfacecurve = hGenGrp->GetInt("WriteSurfaceCurveMode", 0);
Interface_Static::SetIVal("write.surfacecurve.mode", writesurfacecurve);
}
void ImportExportSettings::initIGES(Base::Reference<ParameterGrp> hGrp)
{
// IGES handling
Base::Reference<ParameterGrp> hIgesGrp = hGrp->GetGroup("IGES");
int value = Interface_Static::IVal("write.iges.brep.mode");
bool brep = hIgesGrp->GetBool("BrepMode", value > 0);
Interface_Static::SetIVal("write.iges.brep.mode", brep ? 1 : 0);
Interface_Static::SetCVal("write.iges.header.company", hIgesGrp->GetASCII("Company").c_str());
Interface_Static::SetCVal("write.iges.header.author", hIgesGrp->GetASCII("Author").c_str());
Interface_Static::SetCVal(
"write.iges.header.product",
hIgesGrp->GetASCII("Product", Interface_Static::CVal("write.iges.header.product")).c_str()
);
int unitIges = hIgesGrp->GetInt("Unit", 0);
switch (unitIges) {
case 1:
Interface_Static::SetCVal("write.iges.unit", "M");
break;
case 2:
Interface_Static::SetCVal("write.iges.unit", "INCH");
break;
default:
Interface_Static::SetCVal("write.iges.unit", "MM");
break;
}
}
void ImportExportSettings::setImportCodePage(int cpIndex)
{
pGroup->SetInt("ImportCodePage", cpIndex);
}
Resource_FormatType ImportExportSettings::getImportCodePage() const
{
Resource_FormatType result {};
long codePageIndex = pGroup->GetInt("ImportCodePage", 0L);
long i = 0L;
for (const auto& codePageIt : codePageList) {
if (i == codePageIndex) {
result = codePageIt.codePage;
break;
}
i++;
}
return result;
}
std::list<ImportExportSettings::CodePage> ImportExportSettings::getCodePageList() const
{
return codePageList;
}
void ImportExportSettings::initSTEP(Base::Reference<ParameterGrp> hGrp)
{
// STEP handling
Base::Reference<ParameterGrp> hStepGrp = hGrp->GetGroup("STEP");
int unitStep = hStepGrp->GetInt("Unit", 0);
switch (unitStep) {
case 1:
Interface_Static::SetCVal("write.step.unit", "M");
break;
case 2:
Interface_Static::SetCVal("write.step.unit", "INCH");
break;
default:
Interface_Static::SetCVal("write.step.unit", "MM");
break;
}
std::string ap = hStepGrp->GetASCII("Scheme", Interface_Static::CVal("write.step.schema"));
Interface_Static::SetCVal("write.step.schema", ap.c_str());
Interface_Static::SetCVal(
"write.step.product.name",
hStepGrp->GetASCII("Product", Interface_Static::CVal("write.step.product.name")).c_str()
);
}
ImportExportSettings::ImportExportSettings()
{
pGroup = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/Import"
);
}
STEP::ImportExportSettingsPtr ImportExportSettings::getSTEPSettings() const
{
if (!step) {
step = std::make_shared<STEP::ImportExportSettings>();
}
return step;
}
IGES::ImportExportSettingsPtr ImportExportSettings::getIGESSettings() const
{
if (!iges) {
iges = std::make_shared<IGES::ImportExportSettings>();
}
return iges;
}
void ImportExportSettings::setReadShapeCompoundMode(bool on)
{
auto grp = pGroup->GetGroup("hSTEP");
grp->SetBool("ReadShapeCompoundMode", on);
}
bool ImportExportSettings::getReadShapeCompoundMode() const
{
auto grp = pGroup->GetGroup("hSTEP");
return grp->GetBool("ReadShapeCompoundMode", false);
}
void ImportExportSettings::setExportHiddenObject(bool on)
{
pGroup->SetBool("ExportHiddenObject", on);
}
bool ImportExportSettings::getExportHiddenObject() const
{
return pGroup->GetBool("ExportHiddenObject", true);
}
void ImportExportSettings::setImportHiddenObject(bool on)
{
pGroup->SetBool("ImportHiddenObject", on);
}
bool ImportExportSettings::getImportHiddenObject() const
{
return pGroup->GetBool("ImportHiddenObject", true);
}
void ImportExportSettings::setExportLegacy(bool on)
{
pGroup->SetBool("ExportLegacy", on);
}
bool ImportExportSettings::getExportLegacy() const
{
return pGroup->GetBool("ExportLegacy", false);
}
void ImportExportSettings::setExportKeepPlacement(bool on)
{
pGroup->SetBool("ExportKeepPlacement", on);
}
bool ImportExportSettings::getExportKeepPlacement() const
{
return pGroup->GetBool("ExportKeepPlacement", false);
}
void ImportExportSettings::setUseLinkGroup(bool on)
{
pGroup->SetBool("UseLinkGroup", on);
}
bool ImportExportSettings::getUseLinkGroup() const
{
return pGroup->GetBool("UseLinkGroup", false);
}
void ImportExportSettings::setUseBaseName(bool on)
{
pGroup->SetBool("UseBaseName", on);
}
bool ImportExportSettings::getUseBaseName() const
{
return pGroup->GetBool("UseBaseName", true);
}
void ImportExportSettings::setReduceObjects(bool on)
{
pGroup->SetBool("ReduceObjects", on);
}
bool ImportExportSettings::getReduceObjects() const
{
return pGroup->GetBool("ReduceObjects", false);
}
void ImportExportSettings::setExpandCompound(bool on)
{
pGroup->SetBool("ExpandCompound", on);
}
bool ImportExportSettings::getExpandCompound() const
{
return pGroup->GetBool("ExpandCompound", false);
}
void ImportExportSettings::setShowProgress(bool on)
{
pGroup->SetBool("ShowProgress", on);
}
bool ImportExportSettings::getShowProgress() const
{
return pGroup->GetBool("ShowProgress", true);
}
void ImportExportSettings::setImportMode(ImportExportSettings::ImportMode mode)
{
pGroup->SetInt("ImportMode", static_cast<long>(mode));
}
ImportExportSettings::ImportMode ImportExportSettings::getImportMode() const
{
return static_cast<ImportExportSettings::ImportMode>(pGroup->GetInt("ImportMode", 0));
}
} // namespace OCAF
} // namespace Part
|