[PD] fix several hole thread issues

- actually use specified thread depth, fixes issue reported here: https://github.com/FreeCAD/FreeCAD/pull/4274#issuecomment-997787744
- fixes 2 UI enabling issues
- the thread depth cannot be longer than the hole depth
- the hole cannot be deeper than the through-all depth
This commit is contained in:
Uwe
2021-12-21 02:48:38 +01:00
parent f429a3630e
commit 9770449be7
2 changed files with 72 additions and 35 deletions

View File

@@ -995,25 +995,41 @@ double Hole::getThreadPitch()
void Hole::updateThreadDepthParam()
{
std::string method(DepthType.getValueAsString());
double drillDepth;
if ( method == "Dimension" ) {
drillDepth = Depth.getValue();
} else if ( method == "ThroughAll" ) {
drillDepth = getThroughAllLength();
} else {
std::string ThreadMethod(ThreadDepthType.getValueAsString());
std::string HoleDepth(DepthType.getValueAsString());
if (HoleDepth == "Dimension") {
if (ThreadMethod == "Hole Depth") {
ThreadDepth.setValue(Depth.getValue());
}
else if (ThreadMethod == "Dimension") {
// the thread cannot be longer than the hole depth
if (ThreadDepth.getValue() > Depth.getValue())
ThreadDepth.setValue(Depth.getValue());
else
ThreadDepth.setValue(ThreadDepth.getValue());
}
else if (ThreadMethod == "Tapped (DIN76)") {
ThreadDepth.setValue(Depth.getValue() - getThreadRunout());
}
else {
throw Base::RuntimeError("Unsupported thread depth type \n");
}
}
else if (HoleDepth == "ThroughAll") {
if (ThreadMethod != "Dimension") {
ThreadDepth.setValue(getThroughAllLength());
}
else {
// the thread cannot be longer than the hole depth
if (ThreadDepth.getValue() > getThroughAllLength())
ThreadDepth.setValue(getThroughAllLength());
else
ThreadDepth.setValue(ThreadDepth.getValue());
}
}
else {
throw Base::RuntimeError("Unsupported depth type \n");
}
if ( std::string(ThreadDepthType.getValueAsString()) == "Tapped (DIN76)" ) {
ThreadDepth.setValue(Depth.getValue() - getThreadRunout());
} else { // hole depth
ThreadDepth.setValue(Depth.getValue());
}
if ( method == "ThroughAll" ) {
ThreadDepth.setValue(drillDepth);
}
}
void Hole::updateDiameterParam()
@@ -1439,24 +1455,39 @@ void Hole::onChanged(const App::Property *prop)
updateHoleCutParams();
}
else if (prop == &DepthType) {
Depth.setReadOnly((std::string(DepthType.getValueAsString()) != "Dimension"));
DrillPoint.setReadOnly((std::string(DepthType.getValueAsString()) != "Dimension"));
DrillPointAngle.setReadOnly((std::string(DepthType.getValueAsString()) != "Dimension"));
DrillForDepth.setReadOnly((std::string(DepthType.getValueAsString()) != "Dimension"));
std::string DepthMode(DepthType.getValueAsString());
Depth.setReadOnly(DepthMode != "Dimension");
DrillPoint.setReadOnly(DepthMode != "Dimension");
DrillPointAngle.setReadOnly(DepthMode != "Dimension");
DrillForDepth.setReadOnly(DepthMode != "Dimension");
if (DepthMode != "Dimension") {
// if through all, set the depth accordingly
Depth.setValue(getThroughAllLength());
// the thread depth is not dimension, it is the same as the hole depth
ThreadDepth.setValue(getThroughAllLength());
}
updateThreadDepthParam();
}
else if (prop == &Depth) {
if (std::string(ThreadDepthType.getValueAsString()) != "Dimension") {
// the depth cannot be greater than the through-all length
if (Depth.getValue() > getThroughAllLength())
Depth.setValue(getThroughAllLength());
if (std::string(ThreadDepthType.getValueAsString()) != "Dimension")
updateDiameterParam(); // make sure diameter and pitch are updated.
updateThreadDepthParam();
}
// update the thread in every case
updateThreadDepthParam();
}
else if (prop == &ThreadDepthType) {
updateThreadDepthParam();
ThreadDepth.setReadOnly(Threaded.getValue() && std::string(ThreadDepthType.getValueAsString()) != "Dimension");
ThreadDepth.setReadOnly(Threaded.getValue()
&& std::string(ThreadDepthType.getValueAsString()) != "Dimension");
}
else if (prop == &ThreadDepth) {
// Nothing else needs to be updated on ThreadDepth change
// the thread depth cannot be greater than the hole depth
if (ThreadDepth.getValue() > Depth.getValue())
ThreadDepth.setValue(Depth.getValue());
}
else if (prop == &UseCustomThreadClearance) {
updateDiameterParam();
@@ -1872,20 +1903,22 @@ App::DocumentObjectExecReturn *Hole::execute(void)
double threadDepth = ThreadDepth.getValue();
double helixLength = threadDepth + P/2;
std::string threadDepthMethod(ThreadDepthType.getValueAsString());
if ( threadDepthMethod != "Dimension" ) {
if (threadDepthMethod != "Dimension") {
std::string depthMethod(DepthType.getValueAsString());
if ( depthMethod == "ThroughAll" ) {
if (depthMethod == "ThroughAll") {
threadDepth = length;
ThreadDepth.setValue(threadDepth);
helixLength = threadDepth + 2*P;
} else if ( threadDepthMethod == "Tapped (DIN76)" ) {
helixLength = threadDepth + 2 * P;
}
else if (threadDepthMethod == "Tapped (DIN76)") {
threadDepth = Depth.getValue() - getThreadRunout();
ThreadDepth.setValue(threadDepth);
helixLength = threadDepth + P/2;
} else { // Hole depth
helixLength = threadDepth + P / 2;
}
else { // Hole depth
threadDepth = Depth.getValue();
ThreadDepth.setValue(threadDepth);
helixLength = threadDepth + P/8;
helixLength = threadDepth + P / 8;
}
}
TopoDS_Shape helix = TopoShape().makeLongHelix(P, helixLength, D / 2, 0.0, leftHanded);

View File

@@ -180,8 +180,10 @@ TaskHoleParameters::TaskHoleParameters(ViewProviderHole *HoleView, QWidget *pare
ui->UpdateView->setChecked(false);
ui->UpdateView->setEnabled(ui->ModelThread->isChecked());
ui->Depth->setEnabled(std::string(pcHole->DepthType.getValueAsString()) == "Dimension");
ui->ThreadDepthType->setEnabled(ui->Threaded->isChecked() && ui->ModelThread->isChecked());
ui->ThreadDepth->setEnabled(ui->Threaded->isChecked() && ui->ModelThread->isChecked() && std::string(pcHole->ThreadDepthType.getValueAsString()) == "Dimension");
ui->ThreadDepth->setEnabled(ui->Threaded->isChecked() && ui->ModelThread->isChecked()
&& std::string(pcHole->ThreadDepthType.getValueAsString()) == "Dimension");
connect(ui->Threaded, SIGNAL(clicked(bool)), this, SLOT(threadedChanged()));
connect(ui->ThreadType, SIGNAL(currentIndexChanged(int)), this, SLOT(threadTypeChanged(int)));
@@ -457,13 +459,15 @@ void TaskHoleParameters::depthChanged(int index)
ui->DrillPointAngle->setEnabled(true);
ui->DrillForDepth->setEnabled(true);
}
else {
else { // through all
ui->drillPointFlat->setEnabled(false);
ui->drillPointAngled->setEnabled(false);
ui->DrillPointAngle->setEnabled(false);
ui->DrillForDepth->setEnabled(false);
}
recomputeFeature();
// enabling must be handled after recompute
ui->ThreadDepth->setEnabled(std::string(pcHole->ThreadDepthType.getValueAsString()) == "Dimension");
}
void TaskHoleParameters::depthValueChanged(double value)