PartDesign: Return to previous feature after edit
This commit is contained in:
@@ -108,14 +108,18 @@ bool ViewProvider::setEdit(int ModNum)
|
||||
msgBox.setInformativeText(QObject::tr("Close this dialog?"));
|
||||
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||
msgBox.setDefaultButton(QMessageBox::Yes);
|
||||
int ret = msgBox.exec();
|
||||
if (ret == QMessageBox::Yes) {
|
||||
|
||||
if (msgBox.exec() == QMessageBox::Yes) {
|
||||
Gui::Control().reject();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
previouslyShownViewProvider = dynamic_cast<ViewProvider*>(
|
||||
Gui::Application::Instance->getViewProvider(getBodyViewProvider()->getShownFeature())
|
||||
);
|
||||
|
||||
// clear the selection (convenience)
|
||||
Gui::Selection().clearSelection();
|
||||
|
||||
@@ -146,27 +150,21 @@ TaskDlgFeatureParameters *ViewProvider::getEditDialog() {
|
||||
void ViewProvider::unsetEdit(int ModNum)
|
||||
{
|
||||
// return to the WB we were in before editing the PartDesign feature
|
||||
if (!oldWb.empty())
|
||||
if (!oldWb.empty()) {
|
||||
Gui::Command::assureWorkbench(oldWb.c_str());
|
||||
}
|
||||
|
||||
// ensure that after edit we still show the same feature
|
||||
if (previouslyShownViewProvider) {
|
||||
previouslyShownViewProvider->show();
|
||||
}
|
||||
|
||||
if (ModNum == ViewProvider::Default) {
|
||||
// when pressing ESC make sure to close the dialog
|
||||
#if 0
|
||||
PartDesign::Body* activeBody = Gui::Application::Instance->activeView()->getActiveObject<PartDesign::Body*>(PDBODYKEY);
|
||||
#endif
|
||||
Gui::Control().closeDialog();
|
||||
#if 0
|
||||
if ((activeBody != NULL) && (oldTip != NULL)) {
|
||||
Gui::Selection().clearSelection();
|
||||
Gui::Selection().addSelection(oldTip->getDocument()->getName(), oldTip->getNameInDocument());
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"FreeCADGui.runCommand('PartDesign_MoveTip')");
|
||||
}
|
||||
#endif
|
||||
oldTip = nullptr;
|
||||
}
|
||||
else {
|
||||
PartGui::ViewProviderPart::unsetEdit(ModNum);
|
||||
oldTip = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,8 +91,8 @@ protected:
|
||||
virtual TaskDlgFeatureParameters *getEditDialog();
|
||||
|
||||
std::string oldWb;
|
||||
App::DocumentObject* oldTip{nullptr};
|
||||
bool isSetTipIcon{false};
|
||||
ViewProvider* previouslyShownViewProvider { nullptr };
|
||||
bool isSetTipIcon { false };
|
||||
};
|
||||
|
||||
using ViewProviderPython = Gui::ViewProviderFeaturePythonT<ViewProvider>;
|
||||
|
||||
@@ -330,15 +330,43 @@ void ViewProviderBody::setVisualBodyMode(bool bodymode) {
|
||||
}
|
||||
}
|
||||
|
||||
std::vector< std::string > ViewProviderBody::getDisplayModes() const {
|
||||
std::vector<std::string> ViewProviderBody::getDisplayModes() const
|
||||
{
|
||||
|
||||
//we get all display modes and remove the "Group" mode, as this is what we use for "Through"
|
||||
//body display mode
|
||||
std::vector< std::string > modes = ViewProviderPart::getDisplayModes();
|
||||
// we get all display modes and remove the "Group" mode, as this is what we use for "Through"
|
||||
// body display mode
|
||||
std::vector<std::string> modes = ViewProviderPart::getDisplayModes();
|
||||
modes.erase(modes.begin());
|
||||
return modes;
|
||||
}
|
||||
|
||||
PartDesign::Feature* ViewProviderBody::getShownFeature() const
|
||||
{
|
||||
auto body = static_cast<PartDesign::Body*>(getObject());
|
||||
auto features = body->Group.getValues();
|
||||
|
||||
for (auto feature : features) {
|
||||
if (!feature->isDerivedFrom<PartDesign::Feature>()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (feature->Visibility.getValue()) {
|
||||
return static_cast<PartDesign::Feature*>(feature);
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Gui::ViewProvider* ViewProviderBody::getShownViewProvider() const
|
||||
{
|
||||
if (const auto* feature = getShownFeature()) {
|
||||
return Gui::Application::Instance->getViewProvider(feature);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool ViewProviderBody::canDropObjects() const
|
||||
{
|
||||
// if the BaseFeature property is marked as hidden or read-only then
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <Mod/Part/Gui/ViewProvider.h>
|
||||
#include <Mod/PartDesign/PartDesignGlobal.h>
|
||||
#include <Mod/PartDesign/App/Feature.h>
|
||||
#include <Gui/ViewProviderOriginGroupExtension.h>
|
||||
#include <QCoreApplication>
|
||||
|
||||
@@ -78,6 +79,9 @@ public:
|
||||
*/
|
||||
SbBox3f getBoundBox ();
|
||||
|
||||
PartDesign::Feature* getShownFeature() const;
|
||||
ViewProvider* getShownViewProvider() const;
|
||||
|
||||
/** Check whether objects can be added to the view provider by drag and drop */
|
||||
bool canDropObjects() const override;
|
||||
/** Check whether the object can be dropped to the view provider by drag and drop */
|
||||
|
||||
Reference in New Issue
Block a user