PartDesign: Fillet, Chamfer, Draft, Thickness : Enable tool to start with no selection.
This commit is contained in:
@@ -103,8 +103,10 @@ TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp *DressUpView, Q
|
||||
connect(ui->listWidgetReferences, &QListWidget::itemDoubleClicked,
|
||||
this, &TaskChamferParameters::doubleClicked);
|
||||
|
||||
// the dialog can be called on a broken chamfer, then hide the chamfer
|
||||
hideOnError();
|
||||
if (strings.size() == 0)
|
||||
setSelectionMode(refSel);
|
||||
else
|
||||
hideOnError();
|
||||
}
|
||||
|
||||
void TaskChamferParameters::setUpUI(PartDesign::Chamfer* pcChamfer)
|
||||
@@ -152,40 +154,17 @@ void TaskChamferParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
|
||||
// executed when the user selected something in the CAD object
|
||||
// adds/deletes the selection accordingly
|
||||
|
||||
if (selectionMode == none)
|
||||
return;
|
||||
|
||||
if (msg.Type == Gui::SelectionChanges::AddSelection) {
|
||||
if (referenceSelected(msg)) {
|
||||
// Clear selection.
|
||||
Gui::Selection().clearSelection();
|
||||
|
||||
if (removeItemFromListWidget(ui->listWidgetReferences, msg.pSubName)) {
|
||||
// if there is only one item left, it cannot be deleted
|
||||
if (ui->listWidgetReferences->count() == 1) {
|
||||
deleteAction->setEnabled(false);
|
||||
deleteAction->setStatusTip(tr("There must be at least one item"));
|
||||
// we must also end the selection mode
|
||||
exitSelectionMode();
|
||||
clearButtons(none);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ui->listWidgetReferences->addItem(QString::fromStdString(msg.pSubName));
|
||||
// it might be the second one so we can enable the context menu
|
||||
if (ui->listWidgetReferences->count() > 1) {
|
||||
deleteAction->setEnabled(true);
|
||||
deleteAction->setStatusTip(QString());
|
||||
}
|
||||
}
|
||||
// highlight existing references for possible further selections
|
||||
DressUpView->highlightReferences(true);
|
||||
if (selectionMode == refSel) {
|
||||
referenceSelected(msg, ui->listWidgetReferences);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TaskChamferParameters::onCheckBoxUseAllEdgesToggled(bool checked)
|
||||
{
|
||||
if(checked)
|
||||
setSelectionMode(none);
|
||||
PartDesign::Chamfer* pcChamfer = static_cast<PartDesign::Chamfer*>(DressUpView->getObject());
|
||||
ui->buttonRefSel->setEnabled(!checked);
|
||||
ui->listWidgetReferences->setEnabled(!checked);
|
||||
@@ -193,60 +172,15 @@ void TaskChamferParameters::onCheckBoxUseAllEdgesToggled(bool checked)
|
||||
pcChamfer->getDocument()->recomputeFeature(pcChamfer);
|
||||
}
|
||||
|
||||
void TaskChamferParameters::clearButtons(const selectionModes notThis)
|
||||
void TaskChamferParameters::setButtons(const selectionModes mode)
|
||||
{
|
||||
if (notThis != refSel) ui->buttonRefSel->setChecked(false);
|
||||
DressUpView->highlightReferences(false);
|
||||
ui->buttonRefSel->setChecked(mode == refSel);
|
||||
ui->buttonRefSel->setText(mode == refSel ? tr("End selection") : tr("Start selection"));
|
||||
}
|
||||
|
||||
void TaskChamferParameters::onRefDeleted()
|
||||
{
|
||||
// assure we we are not in selection mode
|
||||
exitSelectionMode();
|
||||
clearButtons(none);
|
||||
// delete any selections since the reference(s) might be highlighted
|
||||
Gui::Selection().clearSelection();
|
||||
DressUpView->highlightReferences(false);
|
||||
|
||||
// get the list of items to be deleted
|
||||
QList<QListWidgetItem*> selectedList = ui->listWidgetReferences->selectedItems();
|
||||
|
||||
// if all items are selected, we must stop because one must be kept to avoid that the feature gets broken
|
||||
if (selectedList.count() == ui->listWidgetReferences->model()->rowCount()) {
|
||||
QMessageBox::warning(this, tr("Selection error"), tr("At least one item must be kept."));
|
||||
return;
|
||||
}
|
||||
|
||||
// get the chamfer object
|
||||
PartDesign::Chamfer* pcChamfer = static_cast<PartDesign::Chamfer*>(DressUpView->getObject());
|
||||
App::DocumentObject* base = pcChamfer->Base.getValue();
|
||||
// get all chamfer references
|
||||
std::vector<std::string> refs = pcChamfer->Base.getSubValues();
|
||||
setupTransaction();
|
||||
|
||||
// delete the selection backwards to assure the list index keeps valid for the deletion
|
||||
for (int i = selectedList.count() - 1; i > -1; i--) {
|
||||
// the ref index is the same as the listWidgetReferences index
|
||||
// so we can erase using the row number of the element to be deleted
|
||||
int rowNumber = ui->listWidgetReferences->row(selectedList.at(i));
|
||||
// erase the reference
|
||||
refs.erase(refs.begin() + rowNumber);
|
||||
// remove from the list
|
||||
ui->listWidgetReferences->model()->removeRow(rowNumber);
|
||||
}
|
||||
|
||||
// update the object
|
||||
pcChamfer->Base.setValue(base, refs);
|
||||
// recompute the feature
|
||||
pcChamfer->recomputeFeature();
|
||||
// hide the chamfer if there was a computation error
|
||||
hideOnError();
|
||||
|
||||
// if there is only one item left, it cannot be deleted
|
||||
if (ui->listWidgetReferences->count() == 1) {
|
||||
deleteAction->setEnabled(false);
|
||||
deleteAction->setStatusTip(tr("There must be at least one item"));
|
||||
}
|
||||
TaskDressUpParameters::deleteRef(ui->listWidgetReferences);
|
||||
}
|
||||
|
||||
void TaskChamferParameters::onAddAllEdges()
|
||||
@@ -256,6 +190,7 @@ void TaskChamferParameters::onAddAllEdges()
|
||||
|
||||
void TaskChamferParameters::onTypeChanged(int index)
|
||||
{
|
||||
setSelectionMode(none);
|
||||
PartDesign::Chamfer* pcChamfer = static_cast<PartDesign::Chamfer*>(DressUpView->getObject());
|
||||
pcChamfer->ChamferType.setValue(index);
|
||||
ui->stackedWidget->setCurrentIndex(index);
|
||||
@@ -267,6 +202,7 @@ void TaskChamferParameters::onTypeChanged(int index)
|
||||
|
||||
void TaskChamferParameters::onSizeChanged(double len)
|
||||
{
|
||||
setSelectionMode(none);
|
||||
PartDesign::Chamfer* pcChamfer = static_cast<PartDesign::Chamfer*>(DressUpView->getObject());
|
||||
setupTransaction();
|
||||
pcChamfer->Size.setValue(len);
|
||||
@@ -277,6 +213,7 @@ void TaskChamferParameters::onSizeChanged(double len)
|
||||
|
||||
void TaskChamferParameters::onSize2Changed(double len)
|
||||
{
|
||||
setSelectionMode(none);
|
||||
PartDesign::Chamfer* pcChamfer = static_cast<PartDesign::Chamfer*>(DressUpView->getObject());
|
||||
setupTransaction();
|
||||
pcChamfer->Size2.setValue(len);
|
||||
@@ -287,6 +224,7 @@ void TaskChamferParameters::onSize2Changed(double len)
|
||||
|
||||
void TaskChamferParameters::onAngleChanged(double angle)
|
||||
{
|
||||
setSelectionMode(none);
|
||||
PartDesign::Chamfer* pcChamfer = static_cast<PartDesign::Chamfer*>(DressUpView->getObject());
|
||||
setupTransaction();
|
||||
pcChamfer->Angle.setValue(angle);
|
||||
@@ -297,6 +235,7 @@ void TaskChamferParameters::onAngleChanged(double angle)
|
||||
|
||||
void TaskChamferParameters::onFlipDirection(bool flip)
|
||||
{
|
||||
setSelectionMode(none);
|
||||
PartDesign::Chamfer* pcChamfer = static_cast<PartDesign::Chamfer*>(DressUpView->getObject());
|
||||
setupTransaction();
|
||||
pcChamfer->FlipDirection.setValue(flip);
|
||||
|
||||
Reference in New Issue
Block a user