Merge pull request #12589 from NomAnor/pd-trans-body

Add a new mode to PD patterns that will transform the base feature's shape instead of the tool shapes
This commit is contained in:
Chris Hennes
2024-06-03 10:46:33 -05:00
committed by GitHub
12 changed files with 580 additions and 485 deletions

View File

@@ -1981,22 +1981,7 @@ void prepareTransformed(PartDesign::Body *pcActiveBody, Gui::Command* cmd, const
{
std::string FeatName = cmd->getUniqueObjectName(which.c_str(), pcActiveBody);
auto accepter = [=](std::vector<App::DocumentObject*> features) -> bool {
if (features.empty())
return false;
return true;
};
auto worker = [=](std::vector<App::DocumentObject*> features) {
std::stringstream str;
str << cmd->getObjectCmd(FeatName.c_str(), pcActiveBody->getDocument()) << ".Originals = [";
for (auto feature : features) {
str << cmd->getObjectCmd(feature) << ",";
}
str << "]";
std::string msg("Make ");
msg += which;
Gui::Command::openCommand(msg.c_str());
@@ -2004,10 +1989,21 @@ void prepareTransformed(PartDesign::Body *pcActiveBody, Gui::Command* cmd, const
// FIXME: There seems to be kind of a race condition here, leading to sporadic errors like
// Exception (Thu Sep 6 11:52:01 2012): 'App.Document' object has no attribute 'Mirrored'
Gui::Command::updateActive(); // Helps to ensure that the object already exists when the next command comes up
Gui::Command::doCommand(Gui::Command::Doc, str.str().c_str());
auto Feat = pcActiveBody->getDocument()->getObject(FeatName.c_str());
if (features.empty()) {
FCMD_OBJ_CMD(Feat, "TransformMode = \"Transform body\"");
} else {
std::stringstream str;
str << "Originals = [";
for (auto feature : features) {
str << cmd->getObjectCmd(feature) << ",";
}
str << "]";
FCMD_OBJ_CMD(Feat, str.str().c_str());
}
// TODO What is this function supposed to do? (2015-08-05, Fat-Zer)
func(Feat, features);
@@ -2017,44 +2013,7 @@ void prepareTransformed(PartDesign::Body *pcActiveBody, Gui::Command* cmd, const
};
// Get a valid original from the user
// First check selections
std::vector<App::DocumentObject*> features = cmd->getSelection().getObjectsOfType(PartDesign::Feature::getClassTypeId());
// Next create a list of all eligible objects
if (features.empty()) {
features = cmd->getDocument()->getObjectsOfType(PartDesign::Feature::getClassTypeId());
// If there is more than one selected or eligible object, show dialog and let user pick one
if (features.size() > 1) {
std::vector<PartDesignGui::TaskFeaturePick::featureStatus> status;
for (unsigned i = 0; i < features.size(); i++)
status.push_back(PartDesignGui::TaskFeaturePick::validFeature);
Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
PartDesignGui::TaskDlgFeaturePick* pickDlg = qobject_cast<PartDesignGui::TaskDlgFeaturePick*>(dlg);
if (dlg && !pickDlg) {
QMessageBox msgBox;
msgBox.setText(QObject::tr("A dialog is already open in the task panel"));
msgBox.setInformativeText(QObject::tr("Do you want to close this dialog?"));
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::Yes);
int ret = msgBox.exec();
if (ret == QMessageBox::Yes)
Gui::Control().closeDialog();
else
return;
}
if (dlg)
Gui::Control().closeDialog();
Gui::Selection().clearSelection();
Gui::Control().showDialog(new PartDesignGui::TaskDlgFeaturePick(features, status, accepter, worker, false));
return;
} else if (features.empty()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"),
QObject::tr("Please create a feature first."));
return;
}
}
PartDesign::Body* activeBody = PartDesignGui::getBody(true);
for (auto feature : features) {
@@ -2103,24 +2062,17 @@ void CmdPartDesignMirrored::activated(int iMsg)
return;
Gui::Command* cmd = this;
auto worker = [cmd](App::DocumentObject *Feat, std::vector<App::DocumentObject*> features) {
if (features.empty())
return;
auto worker = [cmd, pcActiveBody](App::DocumentObject *Feat, std::vector<App::DocumentObject*> features) {
bool direction = false;
if (features.front()->isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) {
Part::Part2DObject *sketch = (static_cast<PartDesign::ProfileBased*>(features.front()))->getVerifiedSketch(/* silent =*/ true);
if (!features.empty() && features.front()->isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) {
Part::Part2DObject* sketch = (static_cast<PartDesign::ProfileBased*>(features.front()))->getVerifiedSketch(/* silent =*/ true);
if (sketch) {
FCMD_OBJ_CMD(Feat,"MirrorPlane = ("<<getObjectCmd(sketch)<<", ['V_Axis'])");
direction = true;
}
}
if (!direction) {
auto body = static_cast<PartDesign::Body*>(Part::BodyBase::findBodyOf(features.front()));
if (body) {
FCMD_OBJ_CMD(Feat,"MirrorPlane = ("<<getObjectCmd(body->getOrigin()->getXY())<<", [''])");
}
FCMD_OBJ_CMD(Feat,"MirrorPlane = ("<<getObjectCmd(pcActiveBody->getOrigin()->getXY())<<", [''])");
}
finishTransformed(cmd, Feat);
@@ -2165,13 +2117,9 @@ void CmdPartDesignLinearPattern::activated(int iMsg)
return;
Gui::Command* cmd = this;
auto worker = [cmd](App::DocumentObject *Feat, std::vector<App::DocumentObject*> features) {
if (!Feat || features.empty())
return;
auto worker = [cmd, pcActiveBody](App::DocumentObject *Feat, std::vector<App::DocumentObject*> features) {
bool direction = false;
if (features.front()->isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) {
if (!features.empty() && features.front()->isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) {
Part::Part2DObject *sketch = (static_cast<PartDesign::ProfileBased*>(features.front()))->getVerifiedSketch(/* silent =*/ true);
if (sketch) {
FCMD_OBJ_CMD(Feat,"Direction = ("<<Gui::Command::getObjectCmd(sketch)<<", ['H_Axis'])");
@@ -2179,10 +2127,7 @@ void CmdPartDesignLinearPattern::activated(int iMsg)
}
}
if (!direction) {
auto body = static_cast<PartDesign::Body*>(Part::BodyBase::findBodyOf(features.front()));
if (body) {
FCMD_OBJ_CMD(Feat,"Direction = ("<<Gui::Command::getObjectCmd(body->getOrigin()->getX())<<",[''])");
}
FCMD_OBJ_CMD(Feat,"Direction = ("<<Gui::Command::getObjectCmd(pcActiveBody->getOrigin()->getX())<<",[''])");
}
FCMD_OBJ_CMD(Feat,"Length = 100");
FCMD_OBJ_CMD(Feat,"Occurrences = 2");
@@ -2229,13 +2174,10 @@ void CmdPartDesignPolarPattern::activated(int iMsg)
return;
Gui::Command* cmd = this;
auto worker = [cmd](App::DocumentObject *Feat, std::vector<App::DocumentObject*> features) {
if (!Feat || features.empty())
return;
auto worker = [cmd, pcActiveBody](App::DocumentObject *Feat, std::vector<App::DocumentObject*> features) {
bool direction = false;
if (features.front()->isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) {
if (!features.empty() && features.front()->isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) {
Part::Part2DObject *sketch = (static_cast<PartDesign::ProfileBased*>(features.front()))->getVerifiedSketch(/* silent =*/ true);
if (sketch) {
FCMD_OBJ_CMD(Feat,"Axis = ("<<Gui::Command::getObjectCmd(sketch)<<",['N_Axis'])");
@@ -2243,10 +2185,7 @@ void CmdPartDesignPolarPattern::activated(int iMsg)
}
}
if (!direction) {
auto body = static_cast<PartDesign::Body*>(Part::BodyBase::findBodyOf(features.front()));
if (body) {
FCMD_OBJ_CMD(Feat,"Axis = ("<<Gui::Command::getObjectCmd(body->getOrigin()->getZ())<<",[''])");
}
FCMD_OBJ_CMD(Feat,"Axis = ("<<Gui::Command::getObjectCmd(pcActiveBody->getOrigin()->getZ())<<",[''])");
}
FCMD_OBJ_CMD(Feat,"Angle = 360");
@@ -2293,11 +2232,7 @@ void CmdPartDesignScaled::activated(int iMsg)
return;
Gui::Command* cmd = this;
auto worker = [cmd](App::DocumentObject *Feat, std::vector<App::DocumentObject*> features) {
if (!Feat || features.empty())
return;
auto worker = [cmd](App::DocumentObject *Feat, std::vector<App::DocumentObject*> /*features*/) {
FCMD_OBJ_CMD(Feat,"Factor = 2");
FCMD_OBJ_CMD(Feat,"Occurrences = 2");
@@ -2411,11 +2346,7 @@ void CmdPartDesignMultiTransform::activated(int iMsg)
} else {
Gui::Command* cmd = this;
auto worker = [cmd, pcActiveBody](App::DocumentObject *Feat, std::vector<App::DocumentObject*> features) {
if (!Feat || features.empty())
return;
auto worker = [cmd, pcActiveBody](App::DocumentObject *Feat, std::vector<App::DocumentObject*> /*features*/) {
// Make sure the user isn't presented with an empty screen because no transformations are defined yet...
App::DocumentObject* prevSolid = pcActiveBody->Tip.getValue();
if (prevSolid) {

View File

@@ -120,8 +120,33 @@ void TaskTransformedParameters::setupUI()
// Get the feature data
auto pcTransformed = static_cast<PartDesign::Transformed*>(getObject());
std::vector<App::DocumentObject*> originals = pcTransformed->Originals.getValues();
using Mode = PartDesign::Transformed::Mode;
ui->buttonGroupMode->setId(ui->radioTransformBody, static_cast<int>(Mode::TransformBody));
ui->buttonGroupMode->setId(ui->radioTransformToolShapes, static_cast<int>(Mode::TransformToolShapes));
connect(ui->buttonGroupMode,
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
qOverload<int>(&QButtonGroup::buttonClicked),
#else
&QButtonGroup::idClicked,
#endif
this,
&TaskTransformedParameters::onModeChanged);
auto const mode = static_cast<Mode>(pcTransformed->TransformMode.getValue());
ui->groupFeatureList->setEnabled(mode == Mode::TransformToolShapes);
switch (mode) {
case Mode::TransformBody:
ui->radioTransformBody->setChecked(true);
break;
case Mode::TransformToolShapes:
ui->radioTransformToolShapes->setChecked(true);
break;
}
std::vector<App::DocumentObject*> originals = pcTransformed->Originals.getValues();
// Fill data into dialog elements
for (auto obj : originals) {
if (obj) {
@@ -272,6 +297,26 @@ bool TaskTransformedParameters::isEnabledTransaction() const
return enableTransaction;
}
void TaskTransformedParameters::onModeChanged(int mode_id)
{
if (mode_id < 0) {
return;
}
auto pcTransformed = static_cast<PartDesign::Transformed*>(getObject());
pcTransformed->TransformMode.setValue(mode_id);
using Mode = PartDesign::Transformed::Mode;
Mode const mode = static_cast<Mode>(mode_id);
ui->groupFeatureList->setEnabled(mode == Mode::TransformToolShapes);
if (mode == Mode::TransformBody) {
ui->listWidgetFeatures->clear();
}
setupTransaction();
recomputeFeature();
}
void TaskTransformedParameters::onButtonAddFeature(bool checked)
{
if (checked) {

View File

@@ -228,6 +228,7 @@ private Q_SLOTS:
void onButtonRemoveFeature(bool checked);
void onFeatureDeleted();
void indexesMoved();
void onModeChanged(int mode_id);
private:
/** Setup the parameter UI.

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>262</width>
<height>207</height>
<width>297</width>
<height>248</height>
</rect>
</property>
<property name="windowTitle">
@@ -15,43 +15,102 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="buttonAddFeature">
<property name="text">
<string>Add feature</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonRemoveFeature">
<property name="text">
<string>Remove feature</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
<widget class="QWidget" name="widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QRadioButton" name="radioTransformBody">
<property name="text">
<string>Transform body</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroupMode</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioTransformToolShapes">
<property name="text">
<string>Transform tool shapes</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroupMode</string>
</attribute>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QListWidget" name="listWidgetFeatures">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>120</height>
</size>
</property>
<property name="toolTip">
<string>List can be reordered by dragging</string>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::InternalMove</enum>
</property>
<widget class="QWidget" name="groupFeatureList" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="buttonAddFeature">
<property name="text">
<string>Add feature</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonRemoveFeature">
<property name="text">
<string>Remove feature</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QListWidget" name="listWidgetFeatures">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>120</height>
</size>
</property>
<property name="toolTip">
<string>List can be reordered by dragging</string>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::InternalMove</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
@@ -70,6 +129,8 @@
</layout>
</widget>
<tabstops>
<tabstop>radioTransformBody</tabstop>
<tabstop>radioTransformToolShapes</tabstop>
<tabstop>buttonAddFeature</tabstop>
<tabstop>buttonRemoveFeature</tabstop>
<tabstop>listWidgetFeatures</tabstop>
@@ -77,4 +138,7 @@
</tabstops>
<resources/>
<connections/>
<buttongroups>
<buttongroup name="buttonGroupMode"/>
</buttongroups>
</ui>