23
#include "PreCompiled.h"
30
#include <App/Application.h>
31
#include <Base/Console.h>
32
#include <Base/Interpreter.h>
33
#include <Gui/Command.h>
35
#include "SketcherSettings.h"
36
#include "ui_SketcherSettings.h"
37
#include "ui_SketcherSettingsAppearance.h"
38
#include "ui_SketcherSettingsDisplay.h"
39
#include "ui_SketcherSettingsGrid.h"
42
using namespace SketcherGui;
46
QList<int> getPenStyles()
49
styles << 0b1111111111111111
55
<< 0b1111111100111100;
59
const QVector<qreal> binaryPatternToDashPattern(int binaryPattern)
61
QVector<qreal> dashPattern;
63
bool isDash = (binaryPattern & 0x8000) != 0;
65
for (int i = 0; i < 16; ++i) {
66
bool currentBit = (binaryPattern & (0x8000 >> i)) != 0;
67
if (currentBit == isDash) {
72
count = (count % 2 == (isDash ? 0 : 1)) ? count + 1 : count;
78
count = (count % 2 == (isDash ? 0 : 1)) ? count + 1 : count;
81
if ((dashPattern.size() % 2) == 1) {
89
SketcherSettings::SketcherSettings(QWidget* parent)
90
: PreferencePage(parent)
91
, ui(new Ui_SketcherSettings)
99
SketcherSettings::~SketcherSettings()
104
void SketcherSettings::saveSettings()
107
ui->checkBoxAdvancedSolverTaskBox->onSave();
108
ui->checkBoxRecalculateInitialSolutionWhileDragging->onSave();
109
ui->checkBoxEnableEscape->onSave();
110
ui->checkBoxDisableShading->onSave();
111
ui->checkBoxNotifyConstraintSubstitutions->onSave();
112
ui->checkBoxAutoRemoveRedundants->onSave();
113
ui->checkBoxUnifiedCoincident->onSave();
114
ui->checkBoxHorVerAuto->onSave();
119
DimensionSeparateTools,
124
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
125
"User parameter:BaseApp/Preferences/Mod/Sketcher/dimensioning");
126
bool singleTool = true;
127
bool SeparatedTools = false;
128
int index = ui->dimensioningMode->currentIndex();
130
case DimensionSeparateTools:
132
SeparatedTools = true;
136
SeparatedTools = true;
139
hGrp->SetBool("SingleDimensioningTool", singleTool);
140
hGrp->SetBool("SeparatedDimensioningTools", SeparatedTools);
142
ui->radiusDiameterMode->setEnabled(index != 1);
146
DimensionAutoRadiusDiam,
151
bool Diameter = true;
153
index = ui->radiusDiameterMode->currentIndex();
155
case DimensionDiameter:
159
case DimensionRadius:
164
hGrp->SetBool("DimensioningDiameter", Diameter);
165
hGrp->SetBool("DimensioningRadius", Radius);
167
hGrp = App::GetApplication().GetParameterGroupByPath(
168
"User parameter:BaseApp/Preferences/Mod/Sketcher/Tools");
170
index = ui->ovpVisibility->currentIndex();
171
hGrp->SetInt("OnViewParameterVisibility", index);
176
void SketcherSettings::loadSettings()
179
ui->checkBoxAdvancedSolverTaskBox->onRestore();
180
ui->checkBoxRecalculateInitialSolutionWhileDragging->onRestore();
181
ui->checkBoxEnableEscape->onRestore();
182
ui->checkBoxDisableShading->onRestore();
183
ui->checkBoxNotifyConstraintSubstitutions->onRestore();
184
ui->checkBoxAutoRemoveRedundants->onRestore();
185
ui->checkBoxUnifiedCoincident->onRestore();
186
setProperty("checkBoxUnifiedCoincident", ui->checkBoxUnifiedCoincident->isChecked());
187
ui->checkBoxHorVerAuto->onRestore();
188
setProperty("checkBoxHorVerAuto", ui->checkBoxHorVerAuto->isChecked());
191
ui->dimensioningMode->clear();
192
ui->dimensioningMode->addItem(tr("Single tool"));
193
ui->dimensioningMode->addItem(tr("Separated tools"));
194
ui->dimensioningMode->addItem(tr("Both"));
196
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
197
"User parameter:BaseApp/Preferences/Mod/Sketcher/dimensioning");
198
bool singleTool = hGrp->GetBool("SingleDimensioningTool", true);
199
bool SeparatedTools = hGrp->GetBool("SeparatedDimensioningTools", false);
200
int index = SeparatedTools ? (singleTool ? 2 : 1) : 0;
201
ui->dimensioningMode->setCurrentIndex(index);
202
setProperty("dimensioningMode", index);
203
connect(ui->dimensioningMode,
204
QOverload<int>::of(&QComboBox::currentIndexChanged),
206
&SketcherSettings::dimensioningModeChanged);
208
ui->radiusDiameterMode->setEnabled(index != 1);
211
ui->radiusDiameterMode->clear();
212
ui->radiusDiameterMode->addItem(tr("Auto"));
213
ui->radiusDiameterMode->addItem(tr("Diameter"));
214
ui->radiusDiameterMode->addItem(tr("Radius"));
216
bool Diameter = hGrp->GetBool("DimensioningDiameter", true);
217
bool Radius = hGrp->GetBool("DimensioningRadius", true);
218
index = Diameter ? (Radius ? 0 : 1) : 2;
219
ui->radiusDiameterMode->setCurrentIndex(index);
221
hGrp = App::GetApplication().GetParameterGroupByPath(
222
"User parameter:BaseApp/Preferences/Mod/Sketcher/Tools");
223
ui->ovpVisibility->clear();
224
ui->ovpVisibility->addItem(tr("None"));
225
ui->ovpVisibility->addItem(tr("Dimensions only"));
226
ui->ovpVisibility->addItem(tr("Position and dimensions"));
228
index = hGrp->GetInt("OnViewParameterVisibility", 1);
229
ui->ovpVisibility->setCurrentIndex(index);
232
void SketcherSettings::dimensioningModeChanged(int index)
234
ui->radiusDiameterMode->setEnabled(index != 1);
237
void SketcherSettings::checkForRestart()
239
if (property("dimensioningMode").toInt() != ui->dimensioningMode->currentIndex()) {
240
SketcherSettings::requireRestart();
242
if (property("checkBoxUnifiedCoincident").toBool()
243
!= ui->checkBoxUnifiedCoincident->isChecked()) {
244
SketcherSettings::requireRestart();
246
if (property("checkBoxHorVerAuto").toBool() != ui->checkBoxHorVerAuto->isChecked()) {
247
SketcherSettings::requireRestart();
254
void SketcherSettings::changeEvent(QEvent* e)
256
if (e->type() == QEvent::LanguageChange) {
257
ui->retranslateUi(this);
260
QWidget::changeEvent(e);
264
void SketcherSettings::resetSettingsToDefaults()
266
ParameterGrp::handle hGrp;
268
hGrp = App::GetApplication().GetParameterGroupByPath(
269
"User parameter:BaseApp/Preferences/Mod/Sketcher/dimensioning");
271
hGrp->RemoveBool("SingleDimensioningTool");
272
hGrp->RemoveBool("SeparatedDimensioningTools");
275
hGrp->RemoveBool("DimensioningDiameter");
276
hGrp->RemoveBool("DimensioningRadius");
278
hGrp = App::GetApplication().GetParameterGroupByPath(
279
"User parameter:BaseApp/Preferences/Mod/Sketcher/Tools");
281
hGrp->RemoveInt("OnViewParameterVisibility");
284
PreferencePage::resetSettingsToDefaults();
289
SketcherSettingsGrid::SketcherSettingsGrid(QWidget* parent)
290
: PreferencePage(parent)
291
, ui(new Ui_SketcherSettingsGrid)
295
QList<int> styles = getPenStyles();
297
ui->gridLinePattern->setIconSize(QSize(80, 12));
298
ui->gridDivLinePattern->setIconSize(QSize(80, 12));
299
for (auto& style : styles) {
300
QPixmap px(ui->gridLinePattern->iconSize());
301
px.fill(Qt::transparent);
302
QBrush brush(Qt::black);
305
pen.setDashPattern(binaryPatternToDashPattern(style));
309
QPainter painter(&px);
311
double mid = ui->gridLinePattern->iconSize().height() / 2.0;
312
painter.drawLine(0, mid, ui->gridLinePattern->iconSize().width(), mid);
315
ui->gridLinePattern->addItem(QIcon(px), QString(), QVariant(style));
316
ui->gridDivLinePattern->addItem(QIcon(px), QString(), QVariant(style));
320
SketcherSettingsGrid::~SketcherSettingsGrid()
325
void SketcherSettingsGrid::saveSettings()
327
ui->checkBoxShowGrid->onSave();
328
ui->gridSize->onSave();
329
ui->checkBoxGridAuto->onSave();
330
ui->gridSizePixelThreshold->onSave();
331
ui->gridLineColor->onSave();
332
ui->gridDivLineColor->onSave();
333
ui->gridLineWidth->onSave();
334
ui->gridDivLineWidth->onSave();
335
ui->gridNumberSubdivision->onSave();
337
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
338
"User parameter:BaseApp/Preferences/Mod/Sketcher/General");
339
QVariant data = ui->gridLinePattern->itemData(ui->gridLinePattern->currentIndex());
340
int pattern = data.toInt();
341
hGrp->SetInt("GridLinePattern", pattern);
343
data = ui->gridDivLinePattern->itemData(ui->gridDivLinePattern->currentIndex());
344
pattern = data.toInt();
345
hGrp->SetInt("GridDivLinePattern", pattern);
348
void SketcherSettingsGrid::loadSettings()
350
ui->checkBoxShowGrid->onRestore();
351
ui->gridSize->onRestore();
352
ui->checkBoxGridAuto->onRestore();
353
ui->gridSizePixelThreshold->onRestore();
354
ui->gridLineColor->onRestore();
355
ui->gridDivLineColor->onRestore();
356
ui->gridLineWidth->onRestore();
357
ui->gridDivLineWidth->onRestore();
358
ui->gridNumberSubdivision->onRestore();
360
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
361
"User parameter:BaseApp/Preferences/Mod/Sketcher/General");
362
int pattern = hGrp->GetInt("GridLinePattern", 0b0000111100001111);
363
int index = ui->gridLinePattern->findData(QVariant(pattern));
367
ui->gridLinePattern->setCurrentIndex(index);
368
pattern = hGrp->GetInt("GridDivLinePattern", 0b1111111111111111);
369
index = ui->gridDivLinePattern->findData(QVariant(pattern));
373
ui->gridDivLinePattern->setCurrentIndex(index);
379
void SketcherSettingsGrid::changeEvent(QEvent* e)
381
if (e->type() == QEvent::LanguageChange) {
382
ui->retranslateUi(this);
385
QWidget::changeEvent(e);
391
SketcherSettingsDisplay::SketcherSettingsDisplay(QWidget* parent)
392
: PreferencePage(parent)
393
, ui(new Ui_SketcherSettingsDisplay)
397
connect(ui->btnTVApply,
398
&QPushButton::clicked,
400
&SketcherSettingsDisplay::onBtnTVApplyClicked);
406
SketcherSettingsDisplay::~SketcherSettingsDisplay()
411
void SketcherSettingsDisplay::saveSettings()
413
ui->EditSketcherFontSize->onSave();
414
ui->viewScalingFactor->onSave();
415
ui->SegmentsPerGeometry->onSave();
416
ui->dialogOnDistanceConstraint->onSave();
417
ui->continueMode->onSave();
418
ui->constraintMode->onSave();
419
ui->checkBoxHideUnits->onSave();
420
ui->checkBoxShowCursorCoords->onSave();
421
ui->checkBoxUseSystemDecimals->onSave();
422
ui->checkBoxShowDimensionalName->onSave();
423
ui->prefDimensionalStringFormat->onSave();
424
ui->checkBoxTVHideDependent->onSave();
425
ui->checkBoxTVShowLinks->onSave();
426
ui->checkBoxTVShowSupport->onSave();
427
ui->checkBoxTVRestoreCamera->onSave();
428
ui->checkBoxTVForceOrtho->onSave();
429
ui->checkBoxTVSectionView->onSave();
432
void SketcherSettingsDisplay::loadSettings()
434
ui->EditSketcherFontSize->onRestore();
435
ui->viewScalingFactor->onRestore();
436
ui->SegmentsPerGeometry->onRestore();
437
ui->dialogOnDistanceConstraint->onRestore();
438
ui->continueMode->onRestore();
439
ui->constraintMode->onRestore();
440
ui->checkBoxHideUnits->onRestore();
441
ui->checkBoxShowCursorCoords->onRestore();
442
ui->checkBoxUseSystemDecimals->onRestore();
443
ui->checkBoxShowDimensionalName->onRestore();
444
ui->prefDimensionalStringFormat->onRestore();
445
ui->checkBoxTVHideDependent->onRestore();
446
ui->checkBoxTVShowLinks->onRestore();
447
ui->checkBoxTVShowSupport->onRestore();
448
ui->checkBoxTVRestoreCamera->onRestore();
449
ui->checkBoxTVForceOrtho->onRestore();
450
this->ui->checkBoxTVForceOrtho->setEnabled(this->ui->checkBoxTVRestoreCamera->isChecked());
451
ui->checkBoxTVSectionView->onRestore();
457
void SketcherSettingsDisplay::changeEvent(QEvent* e)
459
if (e->type() == QEvent::LanguageChange) {
460
ui->retranslateUi(this);
463
QWidget::changeEvent(e);
467
void SketcherSettingsDisplay::onBtnTVApplyClicked(bool)
471
Gui::Command::doCommand(Gui::Command::Gui,
472
"for name,doc in App.listDocuments().items():\n"
473
" for sketch in doc.findObjects('Sketcher::SketchObject'):\n"
474
" sketch.ViewObject.HideDependent = %s\n"
475
" sketch.ViewObject.ShowLinks = %s\n"
476
" sketch.ViewObject.ShowSupport = %s\n"
477
" sketch.ViewObject.RestoreCamera = %s\n"
478
" sketch.ViewObject.ForceOrtho = %s\n"
479
" sketch.ViewObject.SectionView = %s\n",
480
this->ui->checkBoxTVHideDependent->isChecked() ? "True" : "False",
481
this->ui->checkBoxTVShowLinks->isChecked() ? "True" : "False",
482
this->ui->checkBoxTVShowSupport->isChecked() ? "True" : "False",
483
this->ui->checkBoxTVRestoreCamera->isChecked() ? "True" : "False",
484
this->ui->checkBoxTVForceOrtho->isChecked() ? "True" : "False",
485
this->ui->checkBoxTVSectionView->isChecked() ? "True" : "False");
487
catch (Base::PyException& e) {
488
Base::Console().DeveloperError("SketcherSettings", "error in onBtnTVApplyClicked:\n");
490
errMsg = QString::fromLatin1(e.what());
493
errMsg = tr("Unexpected C++ exception");
495
if (errMsg.length() > 0) {
496
QMessageBox::warning(this, tr("Sketcher"), errMsg);
503
SketcherSettingsAppearance::SketcherSettingsAppearance(QWidget* parent)
504
: PreferencePage(parent)
505
, ui(new Ui_SketcherSettingsAppearance)
509
QList<int> styles = getPenStyles();
511
ui->EdgePattern->setIconSize(QSize(70, 12));
512
ui->ConstructionPattern->setIconSize(QSize(70, 12));
513
ui->InternalPattern->setIconSize(QSize(70, 12));
514
ui->ExternalPattern->setIconSize(QSize(70, 12));
515
for (auto& style : styles) {
516
QPixmap px(ui->EdgePattern->iconSize());
517
px.fill(Qt::transparent);
518
QBrush brush(Qt::black);
520
pen.setDashPattern(binaryPatternToDashPattern(style));
524
QPainter painter(&px);
526
double mid = ui->EdgePattern->iconSize().height() / 2.0;
527
painter.drawLine(0, mid, ui->EdgePattern->iconSize().width(), mid);
530
ui->EdgePattern->addItem(QIcon(px), QString(), QVariant(style));
531
ui->ConstructionPattern->addItem(QIcon(px), QString(), QVariant(style));
532
ui->InternalPattern->addItem(QIcon(px), QString(), QVariant(style));
533
ui->ExternalPattern->addItem(QIcon(px), QString(), QVariant(style));
540
SketcherSettingsAppearance::~SketcherSettingsAppearance()
545
void SketcherSettingsAppearance::saveSettings()
548
ui->SketchEdgeColor->onSave();
549
ui->SketchVertexColor->onSave();
550
ui->EditedEdgeColor->onSave();
551
ui->ConstructionColor->onSave();
552
ui->ExternalColor->onSave();
553
ui->InvalidSketchColor->onSave();
554
ui->FullyConstrainedColor->onSave();
555
ui->InternalAlignedGeoColor->onSave();
556
ui->FullyConstraintElementColor->onSave();
557
ui->FullyConstraintConstructionElementColor->onSave();
558
ui->FullyConstraintInternalAlignmentColor->onSave();
560
ui->ConstrainedColor->onSave();
561
ui->NonDrivingConstraintColor->onSave();
562
ui->DatumColor->onSave();
563
ui->ExprBasedConstrDimColor->onSave();
564
ui->DeactivatedConstrDimColor->onSave();
566
ui->CursorTextColor->onSave();
567
ui->CursorCrosshairColor->onSave();
568
ui->CreateLineColor->onSave();
570
ui->EdgeWidth->onSave();
571
ui->ConstructionWidth->onSave();
572
ui->InternalWidth->onSave();
573
ui->ExternalWidth->onSave();
575
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
576
"User parameter:BaseApp/Preferences/Mod/Sketcher/View");
577
QVariant data = ui->EdgePattern->itemData(ui->EdgePattern->currentIndex());
578
int pattern = data.toInt();
579
hGrp->SetInt("EdgePattern", pattern);
581
data = ui->ConstructionPattern->itemData(ui->ConstructionPattern->currentIndex());
582
pattern = data.toInt();
583
hGrp->SetInt("ConstructionPattern", pattern);
585
data = ui->InternalPattern->itemData(ui->InternalPattern->currentIndex());
586
pattern = data.toInt();
587
hGrp->SetInt("InternalPattern", pattern);
589
data = ui->ExternalPattern->itemData(ui->ExternalPattern->currentIndex());
590
pattern = data.toInt();
591
hGrp->SetInt("ExternalPattern", pattern);
594
void SketcherSettingsAppearance::loadSettings()
597
ui->SketchEdgeColor->onRestore();
598
ui->SketchVertexColor->onRestore();
599
ui->EditedEdgeColor->onRestore();
600
ui->ConstructionColor->onRestore();
601
ui->ExternalColor->onRestore();
602
ui->InvalidSketchColor->onRestore();
603
ui->FullyConstrainedColor->onRestore();
604
ui->InternalAlignedGeoColor->onRestore();
605
ui->FullyConstraintElementColor->onRestore();
606
ui->FullyConstraintConstructionElementColor->onRestore();
607
ui->FullyConstraintInternalAlignmentColor->onRestore();
609
ui->ConstrainedColor->onRestore();
610
ui->NonDrivingConstraintColor->onRestore();
611
ui->DatumColor->onRestore();
612
ui->ExprBasedConstrDimColor->onRestore();
613
ui->DeactivatedConstrDimColor->onRestore();
615
ui->CursorTextColor->onRestore();
616
ui->CursorCrosshairColor->onRestore();
617
ui->CreateLineColor->onRestore();
619
ui->EdgeWidth->onRestore();
620
ui->ConstructionWidth->onRestore();
621
ui->InternalWidth->onRestore();
622
ui->ExternalWidth->onRestore();
624
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
625
"User parameter:BaseApp/Preferences/Mod/Sketcher/View");
626
int pattern = hGrp->GetInt("EdgePattern", 0b1111111111111111);
627
int index = ui->EdgePattern->findData(QVariant(pattern));
631
ui->EdgePattern->setCurrentIndex(index);
633
pattern = hGrp->GetInt("ConstructionPattern", 0b1111110011111100);
634
index = ui->ConstructionPattern->findData(QVariant(pattern));
638
ui->ConstructionPattern->setCurrentIndex(index);
640
pattern = hGrp->GetInt("InternalPattern", 0b1111110011111100);
641
index = ui->InternalPattern->findData(QVariant(pattern));
645
ui->InternalPattern->setCurrentIndex(index);
647
pattern = hGrp->GetInt("ExternalPattern", 0b1110010011100100);
648
index = ui->ExternalPattern->findData(QVariant(pattern));
652
ui->ExternalPattern->setCurrentIndex(index);
658
void SketcherSettingsAppearance::changeEvent(QEvent* e)
660
if (e->type() == QEvent::LanguageChange) {
661
ui->retranslateUi(this);
664
QWidget::changeEvent(e);
668
#include "moc_SketcherSettings.cpp"