From ec46265bc36643265ddd3cee5c9379caa016e012 Mon Sep 17 00:00:00 2001 From: donovaly Date: Sun, 27 Sep 2020 05:28:18 +0200 Subject: [PATCH] [PD] initialize hole dialog properly as described in https://forum.freecadweb.org/viewtopic.php?f=3&t=50611, the task dialog should just read out the parameters on initialization and not invoke automatically change actions. This PR also fixes a bug that opening a document with a cheesehead hole leads to an error about an invalid index. The reason is that we access the hole cut type before we set its enums. Thus initialize the cut type with all possible enums since, if necessary, the reduced enum set will be set later on parsing the file. --- src/Mod/PartDesign/Gui/TaskHoleParameters.cpp | 60 ++++++++++++++++--- 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/src/Mod/PartDesign/Gui/TaskHoleParameters.cpp b/src/Mod/PartDesign/Gui/TaskHoleParameters.cpp index 89bee4eae9..991ac75dc0 100644 --- a/src/Mod/PartDesign/Gui/TaskHoleParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskHoleParameters.cpp @@ -76,6 +76,56 @@ TaskHoleParameters::TaskHoleParameters(ViewProviderHole *HoleView, QWidget *pare ui->ThreadType->addItem(tr("UTS fine profile"), QByteArray("UTS")); ui->ThreadType->addItem(tr("UTS extra fine profile"), QByteArray("UTS")); + // read values from the hole properties + PartDesign::Hole* pcHole = static_cast(vp->getObject()); + ui->Threaded->setChecked(pcHole->Threaded.getValue()); + ui->ModelActualThread->setChecked(pcHole->ModelActualThread.getValue()); + ui->ThreadPitch->setValue(pcHole->ThreadPitch.getValue()); + ui->ThreadAngle->setValue(pcHole->ThreadAngle.getValue()); + ui->ThreadCutOffInner->setValue(pcHole->ThreadCutOffInner.getValue()); + ui->ThreadCutOffOuter->setValue(pcHole->ThreadCutOffOuter.getValue()); + ui->ThreadType->setCurrentIndex(pcHole->ThreadType.getValue()); + ui->ThreadSize->clear(); + const char** cursor = pcHole->ThreadSize.getEnums(); + while (*cursor) { + ui->ThreadSize->addItem(tr(*cursor)); + ++cursor; + } + ui->ThreadSize->setCurrentIndex(pcHole->ThreadSize.getValue()); + ui->ThreadClass->clear(); + cursor = pcHole->ThreadClass.getEnums(); + while (*cursor) { + ui->ThreadClass->addItem(tr(*cursor)); + ++cursor; + } + ui->ThreadClass->setCurrentIndex(pcHole->ThreadClass.getValue()); + ui->ThreadFit->setCurrentIndex(pcHole->ThreadFit.getValue()); + ui->Diameter->setValue(pcHole->Diameter.getValue()); + if (pcHole->ThreadDirection.getValue() == 0L) + ui->directionRightHand->setChecked(true); + else + ui->directionLeftHand->setChecked(true); + ui->HoleCutType->clear(); + cursor = pcHole->HoleCutType.getEnums(); + while (*cursor) { + ui->HoleCutType->addItem(QString::fromLatin1(*cursor)); + ++cursor; + } + ui->HoleCutType->setCurrentIndex(pcHole->HoleCutType.getValue()); + ui->HoleCutDiameter->setValue(pcHole->HoleCutDiameter.getValue()); + ui->HoleCutDepth->setValue(pcHole->HoleCutDepth.getValue()); + ui->HoleCutCountersinkAngle->setValue(pcHole->HoleCutCountersinkAngle.getValue()); + ui->DepthType->setCurrentIndex(pcHole->DepthType.getValue()); + ui->Depth->setValue(pcHole->Depth.getValue()); + if (pcHole->DrillPoint.getValue() == 0L) + ui->drillPointFlat->setChecked(true); + else + ui->drillPointAngled->setChecked(true); + ui->DrillPointAngle->setValue(pcHole->DrillPointAngle.getValue()); + ui->Tapered->setChecked(pcHole->ModelActualThread.getValue()); + ui->TaperedAngle->setValue(pcHole->TaperedAngle.getValue()); + ui->Reversed->setChecked(pcHole->Reversed.getValue()); + connect(ui->Threaded, SIGNAL(clicked(bool)), this, SLOT(threadedChanged())); connect(ui->ThreadType, SIGNAL(currentIndexChanged(int)), this, SLOT(threadTypeChanged(int))); connect(ui->ModelActualThread, SIGNAL(clicked(bool)), this, SLOT(modelActualThreadChanged())); @@ -102,14 +152,6 @@ TaskHoleParameters::TaskHoleParameters(ViewProviderHole *HoleView, QWidget *pare connect(ui->Reversed, SIGNAL(clicked(bool)), this, SLOT(reversedChanged())); connect(ui->TaperedAngle, SIGNAL(valueChanged(double)), this, SLOT(taperedAngleChanged(double))); - PartDesign::Hole* pcHole = static_cast(vp->getObject()); - - pcHole->updateProps(); - - ui->Reversed->blockSignals(true); - ui->Reversed->setChecked(pcHole->Reversed.getValue()); - ui->Reversed->blockSignals(false); - vp->show(); ui->ThreadPitch->bind(pcHole->ThreadPitch); @@ -475,7 +517,7 @@ void TaskHoleParameters::changedObject(const App::Document&, const App::Property ui->ThreadSize->blockSignals(true); ui->ThreadSize->clear(); - const char ** cursor = pcHole->ThreadSize.getEnums(); + const char** cursor = pcHole->ThreadSize.getEnums(); while (*cursor) { ui->ThreadSize->addItem(QString::fromLatin1(*cursor)); ++cursor;