1 /*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program 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 General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 /*******************************************************************************
21 * Includes
22 ******************************************************************************/
23 #include "boarddesignrulesdialog.h"
24
25 #include "ui_boarddesignrulesdialog.h"
26
27 #include <QtCore>
28
29 /*******************************************************************************
30 * Namespace
31 ******************************************************************************/
32 namespace librepcb {
33
34 /*******************************************************************************
35 * Constructors / Destructor
36 ******************************************************************************/
37
BoardDesignRulesDialog(const BoardDesignRules & rules,const LengthUnit & lengthUnit,const QString & settingsPrefix,QWidget * parent)38 BoardDesignRulesDialog::BoardDesignRulesDialog(const BoardDesignRules& rules,
39 const LengthUnit& lengthUnit,
40 const QString& settingsPrefix,
41 QWidget* parent)
42 : QDialog(parent), mUi(new Ui::BoardDesignRulesDialog), mDesignRules(rules) {
43 mUi->setupUi(this);
44 mUi->edtStopMaskClrRatio->setSingleStep(5.0); // [%]
45 mUi->edtStopMaskClrMin->configure(lengthUnit,
46 LengthEditBase::Steps::generic(),
47 settingsPrefix % "/stopmask_clearance_min");
48 mUi->edtStopMaskClrMax->configure(lengthUnit,
49 LengthEditBase::Steps::generic(),
50 settingsPrefix % "/stopmask_clearance_max");
51 mUi->edtStopMaskMaxViaDia->configure(
52 lengthUnit, LengthEditBase::Steps::generic(),
53 settingsPrefix % "/stopmask_max_via_diameter");
54 mUi->edtCreamMaskClrRatio->setSingleStep(5.0); // [%]
55 mUi->edtCreamMaskClrMin->configure(
56 lengthUnit, LengthEditBase::Steps::generic(),
57 settingsPrefix % "/creammask_clearance_min");
58 mUi->edtCreamMaskClrMax->configure(
59 lengthUnit, LengthEditBase::Steps::generic(),
60 settingsPrefix % "/creammask_clearance_max");
61 mUi->edtRestringPadsRatio->setSingleStep(5.0); // [%]
62 mUi->edtRestringPadsMin->configure(lengthUnit,
63 LengthEditBase::Steps::generic(),
64 settingsPrefix % "/restring_pads_min");
65 mUi->edtRestringPadsMax->configure(lengthUnit,
66 LengthEditBase::Steps::generic(),
67 settingsPrefix % "/restring_pads_max");
68 mUi->edtRestringViasRatio->setSingleStep(5.0); // [%]
69 mUi->edtRestringViasMin->configure(lengthUnit,
70 LengthEditBase::Steps::generic(),
71 settingsPrefix % "/restring_vias_min");
72 mUi->edtRestringViasMax->configure(lengthUnit,
73 LengthEditBase::Steps::generic(),
74 settingsPrefix % "/restring_vias_max");
75
76 updateWidgets();
77
78 // set focus to name so the user can immediately start typing to change it
79 mUi->edtName->setFocus();
80 }
81
~BoardDesignRulesDialog()82 BoardDesignRulesDialog::~BoardDesignRulesDialog() {
83 delete mUi;
84 mUi = nullptr;
85 }
86
87 /*******************************************************************************
88 * Private Slots
89 ******************************************************************************/
90
on_buttonBox_clicked(QAbstractButton * button)91 void BoardDesignRulesDialog::on_buttonBox_clicked(QAbstractButton* button) {
92 switch (mUi->buttonBox->buttonRole(button)) {
93 case QDialogButtonBox::ApplyRole:
94 case QDialogButtonBox::AcceptRole:
95 applyRules();
96 emit rulesChanged(mDesignRules);
97 break;
98
99 case QDialogButtonBox::ResetRole:
100 mDesignRules.restoreDefaults();
101 updateWidgets();
102 emit rulesChanged(mDesignRules);
103 break;
104
105 default:
106 break;
107 }
108 }
109
110 /*******************************************************************************
111 * Private Methods
112 ******************************************************************************/
113
updateWidgets()114 void BoardDesignRulesDialog::updateWidgets() noexcept {
115 // general attributes
116 mUi->edtName->setText(*mDesignRules.getName());
117 mUi->txtDescription->setPlainText(mDesignRules.getDescription());
118 // stop mask
119 mUi->edtStopMaskClrRatio->setValue(mDesignRules.getStopMaskClearanceRatio());
120 mUi->edtStopMaskClrMin->setValue(mDesignRules.getStopMaskClearanceMin());
121 mUi->edtStopMaskClrMax->setValue(mDesignRules.getStopMaskClearanceMax());
122 mUi->edtStopMaskMaxViaDia->setValue(mDesignRules.getStopMaskMaxViaDiameter());
123 // cream mask
124 mUi->edtCreamMaskClrRatio->setValue(
125 mDesignRules.getCreamMaskClearanceRatio());
126 mUi->edtCreamMaskClrMin->setValue(mDesignRules.getCreamMaskClearanceMin());
127 mUi->edtCreamMaskClrMax->setValue(mDesignRules.getCreamMaskClearanceMax());
128 // restring
129 mUi->edtRestringPadsRatio->setValue(mDesignRules.getRestringPadRatio());
130 mUi->edtRestringPadsMin->setValue(mDesignRules.getRestringPadMin());
131 mUi->edtRestringPadsMax->setValue(mDesignRules.getRestringPadMax());
132 mUi->edtRestringViasRatio->setValue(mDesignRules.getRestringViaRatio());
133 mUi->edtRestringViasMin->setValue(mDesignRules.getRestringViaMin());
134 mUi->edtRestringViasMax->setValue(mDesignRules.getRestringViaMax());
135 }
136
applyRules()137 void BoardDesignRulesDialog::applyRules() noexcept {
138 try {
139 // general attributes
140 mDesignRules.setName(ElementName(mUi->edtName->text())); // can throw
141 mDesignRules.setDescription(mUi->txtDescription->toPlainText());
142 // stop mask
143 mDesignRules.setStopMaskClearanceRatio(
144 mUi->edtStopMaskClrRatio->getValue());
145 mDesignRules.setStopMaskClearanceBounds(
146 mUi->edtStopMaskClrMin->getValue(),
147 mUi->edtStopMaskClrMax->getValue()); // can throw
148 mDesignRules.setStopMaskMaxViaDiameter(
149 mUi->edtStopMaskMaxViaDia->getValue());
150 // cream mask
151 mDesignRules.setCreamMaskClearanceRatio(
152 mUi->edtCreamMaskClrRatio->getValue());
153 mDesignRules.setCreamMaskClearanceBounds(
154 mUi->edtCreamMaskClrMin->getValue(),
155 mUi->edtCreamMaskClrMax->getValue()); // can throw
156 // restring
157 mDesignRules.setRestringPadRatio(mUi->edtRestringPadsRatio->getValue());
158 mDesignRules.setRestringPadBounds(
159 mUi->edtRestringPadsMin->getValue(),
160 mUi->edtRestringPadsMax->getValue()); // can throw
161 mDesignRules.setRestringViaRatio(mUi->edtRestringViasRatio->getValue());
162 mDesignRules.setRestringViaBounds(
163 mUi->edtRestringViasMin->getValue(),
164 mUi->edtRestringViasMax->getValue()); // can throw
165 } catch (const Exception& e) {
166 QMessageBox::warning(this, tr("Could not apply settings"), e.getMsg());
167 }
168 }
169
170 /*******************************************************************************
171 * End of File
172 ******************************************************************************/
173
174 } // namespace librepcb
175