PD: Add offset / overall length modes for LinearPattern
This commit adds support for two separate modes of defining distance between elements in PD's Linear Pattern. 1. Overall Length - which works exactly like it works before, 2. Spacing - which allows user to explicitly define distance (offset) between features.
This commit is contained in:
@@ -127,8 +127,12 @@ void TaskLinearPatternParameters::connectSignals()
|
||||
this, &TaskLinearPatternParameters::onDirectionChanged);
|
||||
connect(ui->checkReverse, &QCheckBox::toggled,
|
||||
this, &TaskLinearPatternParameters::onCheckReverse);
|
||||
connect(ui->comboMode, qOverload<int>(&QComboBox::activated),
|
||||
this, &TaskLinearPatternParameters::onModeChanged);
|
||||
connect(ui->spinLength, qOverload<double>(&Gui::QuantitySpinBox::valueChanged),
|
||||
this, &TaskLinearPatternParameters::onLength);
|
||||
connect(ui->spinOffset, qOverload<double>(&Gui::QuantitySpinBox::valueChanged),
|
||||
this, &TaskLinearPatternParameters::onOffset);
|
||||
connect(ui->spinOccurrences, &Gui::UIntSpinBox::unsignedChanged,
|
||||
this, &TaskLinearPatternParameters::onOccurrences);
|
||||
connect(ui->checkBoxUpdateView, &QCheckBox::toggled,
|
||||
@@ -153,16 +157,22 @@ void TaskLinearPatternParameters::setupUI()
|
||||
// ---------------------
|
||||
|
||||
ui->spinLength->bind(pcLinearPattern->Length);
|
||||
ui->spinOffset->bind(pcLinearPattern->Offset);
|
||||
ui->spinOccurrences->bind(pcLinearPattern->Occurrences);
|
||||
ui->spinOccurrences->setMaximum(pcLinearPattern->Occurrences.getMaximum());
|
||||
ui->spinOccurrences->setMinimum(pcLinearPattern->Occurrences.getMinimum());
|
||||
|
||||
ui->comboDirection->setEnabled(true);
|
||||
ui->checkReverse->setEnabled(true);
|
||||
ui->comboMode->setEnabled(true);
|
||||
ui->spinLength->blockSignals(true);
|
||||
ui->spinLength->setEnabled(true);
|
||||
ui->spinLength->setUnit(Base::Unit::Length);
|
||||
ui->spinLength->blockSignals(false);
|
||||
ui->spinOffset->blockSignals(true);
|
||||
ui->spinOffset->setEnabled(true);
|
||||
ui->spinOffset->setUnit(Base::Unit::Length);
|
||||
ui->spinOffset->blockSignals(false);
|
||||
ui->spinOccurrences->setEnabled(true);
|
||||
|
||||
dirLinks.setCombo(*(ui->comboDirection));
|
||||
@@ -187,6 +197,7 @@ void TaskLinearPatternParameters::setupUI()
|
||||
}
|
||||
}
|
||||
|
||||
adaptVisibilityToMode();
|
||||
updateUI();
|
||||
connectSignals();
|
||||
}
|
||||
@@ -198,9 +209,11 @@ void TaskLinearPatternParameters::updateUI()
|
||||
blockUpdate = true;
|
||||
|
||||
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
|
||||
PartDesign::LinearPatternMode mode = static_cast<PartDesign::LinearPatternMode>(pcLinearPattern->Mode.getValue());
|
||||
|
||||
bool reverse = pcLinearPattern->Reversed.getValue();
|
||||
double length = pcLinearPattern->Length.getValue();
|
||||
double offset = pcLinearPattern->Offset.getValue();
|
||||
unsigned occurrences = pcLinearPattern->Occurrences.getValue();
|
||||
|
||||
if (dirLinks.setCurrentLink(pcLinearPattern->Direction) == -1){
|
||||
@@ -210,15 +223,26 @@ void TaskLinearPatternParameters::updateUI()
|
||||
dirLinks.setCurrentLink(pcLinearPattern->Direction);
|
||||
}
|
||||
|
||||
// Note: These three lines would trigger onLength(), on Occurrences() and another updateUI() if we
|
||||
// didn't check for blockUpdate
|
||||
// Note: This block of code would trigger change signal handlers (e.g. onOccurrences())
|
||||
// and another updateUI() if we didn't check for blockUpdate
|
||||
ui->checkReverse->setChecked(reverse);
|
||||
ui->comboMode->setCurrentIndex((long)mode);
|
||||
ui->spinLength->setValue(length);
|
||||
ui->spinOffset->setValue(offset);
|
||||
ui->spinOccurrences->setValue(occurrences);
|
||||
|
||||
blockUpdate = false;
|
||||
}
|
||||
|
||||
void TaskLinearPatternParameters::adaptVisibilityToMode()
|
||||
{
|
||||
auto pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
|
||||
auto mode = static_cast<PartDesign::LinearPatternMode>(pcLinearPattern->Mode.getValue());
|
||||
|
||||
ui->lengthWrapper->setVisible(mode == PartDesign::LinearPatternMode::length);
|
||||
ui->offsetWrapper->setVisible(mode == PartDesign::LinearPatternMode::offset);
|
||||
}
|
||||
|
||||
void TaskLinearPatternParameters::onUpdateViewTimer()
|
||||
{
|
||||
setupTransaction();
|
||||
@@ -294,6 +318,18 @@ void TaskLinearPatternParameters::onCheckReverse(const bool on) {
|
||||
kickUpdateViewTimer();
|
||||
}
|
||||
|
||||
void TaskLinearPatternParameters::onModeChanged(const int mode) {
|
||||
if (blockUpdate)
|
||||
return;
|
||||
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
|
||||
pcLinearPattern->Mode.setValue(mode);
|
||||
|
||||
adaptVisibilityToMode();
|
||||
|
||||
exitSelectionMode();
|
||||
kickUpdateViewTimer();
|
||||
}
|
||||
|
||||
void TaskLinearPatternParameters::onLength(const double l) {
|
||||
if (blockUpdate)
|
||||
return;
|
||||
@@ -304,6 +340,16 @@ void TaskLinearPatternParameters::onLength(const double l) {
|
||||
kickUpdateViewTimer();
|
||||
}
|
||||
|
||||
void TaskLinearPatternParameters::onOffset(const double o) {
|
||||
if (blockUpdate)
|
||||
return;
|
||||
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
|
||||
pcLinearPattern->Offset.setValue(o);
|
||||
|
||||
exitSelectionMode();
|
||||
kickUpdateViewTimer();
|
||||
}
|
||||
|
||||
void TaskLinearPatternParameters::onOccurrences(const uint n) {
|
||||
if (blockUpdate)
|
||||
return;
|
||||
@@ -352,6 +398,7 @@ void TaskLinearPatternParameters::onUpdateView(bool on)
|
||||
pcLinearPattern->Direction.setValue(obj,directions);
|
||||
pcLinearPattern->Reversed.setValue(getReverse());
|
||||
pcLinearPattern->Length.setValue(getLength());
|
||||
pcLinearPattern->Offset.setValue(getOffset());
|
||||
pcLinearPattern->Occurrences.setValue(getOccurrences());
|
||||
|
||||
recomputeFeature();
|
||||
@@ -386,11 +433,21 @@ bool TaskLinearPatternParameters::getReverse() const
|
||||
return ui->checkReverse->isChecked();
|
||||
}
|
||||
|
||||
int TaskLinearPatternParameters::getMode() const
|
||||
{
|
||||
return ui->comboMode->currentIndex();
|
||||
}
|
||||
|
||||
double TaskLinearPatternParameters::getLength() const
|
||||
{
|
||||
return ui->spinLength->value().getValue();
|
||||
}
|
||||
|
||||
double TaskLinearPatternParameters::getOffset() const
|
||||
{
|
||||
return ui->spinOffset->value().getValue();
|
||||
}
|
||||
|
||||
unsigned TaskLinearPatternParameters::getOccurrences() const
|
||||
{
|
||||
return ui->spinOccurrences->value();
|
||||
@@ -436,6 +493,7 @@ void TaskLinearPatternParameters::apply()
|
||||
FCMD_OBJ_CMD(tobj,"Reversed = " << getReverse());
|
||||
|
||||
ui->spinLength->apply();
|
||||
ui->spinOffset->apply();
|
||||
ui->spinOccurrences->apply();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user