FreeCAD

Форк
0
/
DlgExportStep.cpp 
245 строк · 8.2 Кб
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

25
#ifndef _PreComp_
26
# include <QCheckBox>
27
# include <QDialogButtonBox>
28
# include <QRegularExpression>
29
# include <QRegularExpressionValidator>
30
# include <QVBoxLayout>
31
# include <Interface_Static.hxx>
32
#endif
33

34
#include <App/Application.h>
35
#include <Base/Parameter.h>
36
#include <Mod/Part/App/OCAF/ImportExportSettings.h>
37
#include <Mod/Part/App/STEP/ImportExportSettings.h>
38

39
#include "DlgExportStep.h"
40
#include "ui_DlgExportStep.h"
41
#include "ui_DlgExportHeaderStep.h"
42

43

44
using namespace PartGui;
45

46
DlgExportStep::DlgExportStep(QWidget* parent)
47
  : PreferencePage(parent)
48
  , ui(new Ui_DlgExportStep)
49
{
50
    ui->setupUi(this);
51

52
    ui->comboBoxSchema->setItemData(0, QByteArray("AP203"));
53
    ui->comboBoxSchema->setItemData(1, QByteArray("AP214CD"));
54
    ui->comboBoxSchema->setItemData(2, QByteArray("AP214DIS"));
55
    ui->comboBoxSchema->setItemData(3, QByteArray("AP214IS"));
56
    ui->comboBoxSchema->setItemData(4, QByteArray("AP242DIS"));
57

58
    // https://tracker.dev.opencascade.org/view.php?id=25654
59
    ui->checkBoxPcurves->setToolTip(tr("This parameter indicates whether parametric curves (curves in parametric space of surface)\n"
60
                                       "should be written into the STEP file. This parameter can be set to off in order to minimize\n"
61
                                       "the size of the resulting STEP file."));
62

63
    Part::OCAF::ImportExportSettings settings;
64
    ui->checkBoxExportHiddenObj->setChecked(settings.getExportHiddenObject());
65
    ui->checkBoxExportLegacy->setChecked(settings.getExportLegacy());
66
    ui->checkBoxKeepPlacement->setChecked(settings.getExportKeepPlacement());
67
}
68

69
/**
70
 *  Destroys the object and frees any allocated resources
71
 */
72
DlgExportStep::~DlgExportStep() = default;
73

74
void DlgExportStep::saveSettings()
75
{
76
    // General
77
    Part::STEP::ImportExportSettings settings;
78
    settings.setWriteSurfaceCurveMode(ui->checkBoxPcurves->isChecked());
79

80
    // STEP
81
    int unit = ui->comboBoxUnits->currentIndex();
82
    settings.setUnit(static_cast<Part::Interface::Unit>(unit));
83

84
    // scheme
85
    // possible values: AP203, AP214CD (1996), AP214DIS (1998), AP214IS (2002), AP242DIS
86
    QByteArray schema = ui->comboBoxSchema->itemData(ui->comboBoxSchema->currentIndex()).toByteArray();
87
    settings.setScheme(schema);
88

89
    // (h)STEP of Import module
90
    ui->checkBoxExportHiddenObj->onSave();
91
    ui->checkBoxExportLegacy->onSave();
92
    ui->checkBoxKeepPlacement->onSave();
93
}
94

95
void DlgExportStep::loadSettings()
96
{
97
    // General
98
    Part::STEP::ImportExportSettings settings;
99
    ui->checkBoxPcurves->setChecked(settings.getWriteSurfaceCurveMode());
100

101
    // STEP
102
    ui->comboBoxUnits->setCurrentIndex(static_cast<int>(settings.getUnit()));
103

104
    // scheme
105
    QByteArray ap(settings.getScheme().c_str());
106
    int index = ui->comboBoxSchema->findData(QVariant(ap));
107
    if (index >= 0)
108
        ui->comboBoxSchema->setCurrentIndex(index);
109

110
    // (h)STEP of Import module
111
    ui->checkBoxExportHiddenObj->onRestore();
112
    ui->checkBoxExportLegacy->onRestore();
113
    ui->checkBoxKeepPlacement->onRestore();
114
}
115

116
StepSettings DlgExportStep::getSettings() const
117
{
118
    StepSettings set;
119
    set.exportLegacy = ui->checkBoxExportLegacy->isChecked();
120
    set.exportHidden = ui->checkBoxExportHiddenObj->isChecked();
121
    set.keepPlacement = ui->checkBoxKeepPlacement->isChecked();
122
    return set;
123
}
124

125
/**
126
 * Sets the strings of the subwidgets using the current language.
127
 */
128
void DlgExportStep::changeEvent(QEvent *e)
129
{
130
    if (e->type() == QEvent::LanguageChange) {
131
        ui->retranslateUi(this);
132
    }
133
    else {
134
        QWidget::changeEvent(e);
135
    }
136
}
137

138
// ----------------------------------------------------------------------------
139

140
DlgExportHeaderStep::DlgExportHeaderStep(QWidget* parent)
141
  : PreferencePage(parent)
142
  , ui(new Ui_DlgExportHeaderStep)
143
{
144
    ui->setupUi(this);
145

146
    ui->lineEditProduct->setReadOnly(true);
147

148
    QRegularExpression rx;
149
    rx.setPattern(QString::fromLatin1("[\\x00-\\x7F]+"));
150
    QRegularExpressionValidator* companyValidator = new QRegularExpressionValidator(ui->lineEditCompany);
151
    companyValidator->setRegularExpression(rx);
152
    ui->lineEditCompany->setValidator(companyValidator);
153
    QRegularExpressionValidator* authorValidator = new QRegularExpressionValidator(ui->lineEditAuthor);
154
    authorValidator->setRegularExpression(rx);
155
    ui->lineEditAuthor->setValidator(authorValidator);
156
}
157

158
DlgExportHeaderStep::~DlgExportHeaderStep() = default;
159

160
void DlgExportHeaderStep::saveSettings()
161
{
162
    Part::STEP::ImportExportSettings settings;
163

164
    // header info
165
    settings.setCompany(ui->lineEditCompany->text().toLatin1());
166
    settings.setAuthor(ui->lineEditAuthor->text().toLatin1());
167
}
168

169
void DlgExportHeaderStep::loadSettings()
170
{
171
    Part::STEP::ImportExportSettings settings;
172

173
    // header info
174
    ui->lineEditCompany->setText(QString::fromStdString(settings.getCompany()));
175
    ui->lineEditAuthor->setText(QString::fromStdString(settings.getAuthor()));
176
    ui->lineEditProduct->setText(QString::fromStdString(settings.getProductName()));
177
}
178

179
/**
180
 * Sets the strings of the subwidgets using the current language.
181
 */
182
void DlgExportHeaderStep::changeEvent(QEvent *e)
183
{
184
    if (e->type() == QEvent::LanguageChange) {
185
        ui->retranslateUi(this);
186
    }
187
    else {
188
        QWidget::changeEvent(e);
189
    }
190
}
191

192
// ----------------------------------------------------------------------------
193

194
TaskExportStep::TaskExportStep(QWidget* parent)
195
  : QDialog(parent)
196
  , ui(new DlgExportStep(this))
197
{
198
    QApplication::setOverrideCursor(Qt::ArrowCursor);
199

200
    ui->loadSettings();
201
    setWindowTitle(ui->windowTitle());
202

203
    QVBoxLayout* layout = new QVBoxLayout(this);
204
    layout->addWidget(ui.get());
205
    setLayout(layout);
206

207
    showThis = new QCheckBox(this);
208
    showThis->setText(tr("Don't show this dialog again"));
209
    layout->addWidget(showThis);
210

211
    QDialogButtonBox* buttonBox = new QDialogButtonBox(this);
212
    buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
213
    layout->addWidget(buttonBox);
214

215
    connect(buttonBox, &QDialogButtonBox::accepted, this, &TaskExportStep::accept);
216
    connect(buttonBox, &QDialogButtonBox::rejected, this, &TaskExportStep::reject);
217
}
218

219
TaskExportStep::~TaskExportStep()
220
{
221
    QApplication::restoreOverrideCursor();
222
}
223

224
void TaskExportStep::accept()
225
{
226
    QDialog::accept();
227
    ui->saveSettings();
228

229
    Part::STEP::ImportExportSettings settings;
230
    settings.setVisibleExportDialog(!showThis->isChecked());
231
}
232

233
bool TaskExportStep::showDialog() const
234
{
235
    Part::STEP::ImportExportSettings settings;
236
    return settings.isVisibleExportDialog();
237
}
238

239
StepSettings TaskExportStep::getSettings() const
240
{
241
    return ui->getSettings();
242
}
243

244

245
#include "moc_DlgExportStep.cpp"
246

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

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

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

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