diff --git a/src/Mod/PartDesign/Gui/CMakeLists.txt b/src/Mod/PartDesign/Gui/CMakeLists.txt index 07d2bfe02..fb518372f 100644 --- a/src/Mod/PartDesign/Gui/CMakeLists.txt +++ b/src/Mod/PartDesign/Gui/CMakeLists.txt @@ -25,6 +25,7 @@ set(PartDesignGui_LIBS ) set(PartDesignGui_MOC_HDRS + FeaturePickDialog.h TaskPadParameters.h TaskPocketParameters.h TaskChamferParameters.h @@ -46,6 +47,7 @@ SOURCE_GROUP("Moc" FILES ${PartDesignGui_MOC_SRCS}) qt4_add_resources(PartDesignGui_SRCS Resources/PartDesign.qrc) set(PartDesignGui_UIC_SRCS + FeaturePickDialog.ui TaskPadParameters.ui TaskPocketParameters.ui TaskChamferParameters.ui @@ -95,6 +97,9 @@ SET(PartDesignGuiViewProvider_SRCS SOURCE_GROUP("ViewProvider" FILES ${PartDesignGuiViewProvider_SRCS}) SET(PartDesignGuiTaskDlgs_SRCS + FeaturePickDialog.ui + FeaturePickDialog.cpp + FeaturePickDialog.h TaskPadParameters.ui TaskPadParameters.cpp TaskPadParameters.h diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 39280f05f..81c3be306 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -52,6 +52,8 @@ using namespace std; +#include "FeaturePickDialog.h" + //=========================================================================== // Part_Pad //=========================================================================== @@ -717,14 +719,27 @@ CmdPartDesignMirrored::CmdPartDesignMirrored() void CmdPartDesignMirrored::activated(int iMsg) { - std::vector selection = getSelection().getSelectionEx(); - - if (selection.size() != 1 || - (!selection[0].isObjectTypeOf(PartDesign::Additive::getClassTypeId()) && - !selection[0].isObjectTypeOf(PartDesign::Subtractive::getClassTypeId()))) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select only one additive or subtractive feature, please.")); - return; + // Get a valid original from the user + // First check selections + std::vector features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId()); + std::vector subtractive = getSelection().getObjectsOfType(PartDesign::Subtractive::getClassTypeId()); + features.insert(features.end(), subtractive.begin(), subtractive.end()); + // Next create a list of all eligible objects + if (features.size() == 0) { + features = getDocument()->getObjectsOfType(PartDesign::Additive::getClassTypeId()); + subtractive = getDocument()->getObjectsOfType(PartDesign::Subtractive::getClassTypeId()); + features.insert(features.end(), subtractive.begin(), subtractive.end()); + if (features.size() == 0) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"), + QObject::tr("Please create a subtractive or additive feature first, please")); + return; + } + } + // If there is more than one selected or eligible object, show dialog and let user pick one + if (features.size() > 1) { + PartDesignGui::FeaturePickDialog Dlg(features); + if ((Dlg.exec() != QDialog::Accepted) || (features = Dlg.getFeatures()).empty()) + return; // Cancelled or nothing selected } std::string FeatName = getUniqueObjectName("Mirrored"); @@ -732,9 +747,9 @@ void CmdPartDesignMirrored::activated(int iMsg) std::stringstream str; std::vector tempSelNames; str << "App.activeDocument()." << FeatName << ".Originals = ["; - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){ - str << "App.activeDocument()." << it->getFeatName() << ","; - tempSelNames.push_back(it->getFeatName()); + for (std::vector::iterator it = features.begin(); it != features.end(); ++it){ + str << "App.activeDocument()." << (*it)->getNameInDocument() << ","; + tempSelNames.push_back((*it)->getNameInDocument()); } str << "]"; @@ -779,24 +794,38 @@ CmdPartDesignLinearPattern::CmdPartDesignLinearPattern() void CmdPartDesignLinearPattern::activated(int iMsg) { - std::vector selection = getSelection().getSelectionEx(); + // Get a valid original from the user + // First check selections + std::vector features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId()); + std::vector subtractive = getSelection().getObjectsOfType(PartDesign::Subtractive::getClassTypeId()); + features.insert(features.end(), subtractive.begin(), subtractive.end()); + // Next create a list of all eligible objects + if (features.size() == 0) { + features = getDocument()->getObjectsOfType(PartDesign::Additive::getClassTypeId()); + subtractive = getDocument()->getObjectsOfType(PartDesign::Subtractive::getClassTypeId()); + features.insert(features.end(), subtractive.begin(), subtractive.end()); + if (features.size() == 0) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"), + QObject::tr("Please create a subtractive or additive feature first, please")); + return; + } + } + // If there is more than one selected or eligible object, show dialog and let user pick one + if (features.size() > 1) { + PartDesignGui::FeaturePickDialog Dlg(features); + if ((Dlg.exec() != QDialog::Accepted) || (features = Dlg.getFeatures()).empty()) + return; // Cancelled or nothing selected + } - if (selection.size() != 1 || - (!selection[0].isObjectTypeOf(PartDesign::Additive::getClassTypeId()) && - !selection[0].isObjectTypeOf(PartDesign::Subtractive::getClassTypeId()))) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select only one additive or subtractive feature, please.")); - return; - } std::string FeatName = getUniqueObjectName("LinearPattern"); std::stringstream str; std::vector tempSelNames; str << "App.activeDocument()." << FeatName << ".Originals = ["; - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){ - str << "App.activeDocument()." << it->getFeatName() << ","; - tempSelNames.push_back(it->getFeatName()); + for (std::vector::iterator it = features.begin(); it != features.end(); ++it){ + str << "App.activeDocument()." << (*it)->getNameInDocument() << ","; + tempSelNames.push_back((*it)->getNameInDocument()); } str << "]"; @@ -841,14 +870,27 @@ CmdPartDesignPolarPattern::CmdPartDesignPolarPattern() void CmdPartDesignPolarPattern::activated(int iMsg) { - std::vector selection = getSelection().getSelectionEx(); - - if (selection.size() != 1 || - (!selection[0].isObjectTypeOf(PartDesign::Additive::getClassTypeId()) && - !selection[0].isObjectTypeOf(PartDesign::Subtractive::getClassTypeId()))) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select only one additive or subtractive feature, please.")); - return; + // Get a valid original from the user + // First check selections + std::vector features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId()); + std::vector subtractive = getSelection().getObjectsOfType(PartDesign::Subtractive::getClassTypeId()); + features.insert(features.end(), subtractive.begin(), subtractive.end()); + // Next create a list of all eligible objects + if (features.size() == 0) { + features = getDocument()->getObjectsOfType(PartDesign::Additive::getClassTypeId()); + subtractive = getDocument()->getObjectsOfType(PartDesign::Subtractive::getClassTypeId()); + features.insert(features.end(), subtractive.begin(), subtractive.end()); + if (features.size() == 0) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"), + QObject::tr("Please create a subtractive or additive feature first, please")); + return; + } + } + // If there is more than one selected or eligible object, show dialog and let user pick one + if (features.size() > 1) { + PartDesignGui::FeaturePickDialog Dlg(features); + if ((Dlg.exec() != QDialog::Accepted) || (features = Dlg.getFeatures()).empty()) + return; // Cancelled or nothing selected } std::string FeatName = getUniqueObjectName("PolarPattern"); @@ -856,9 +898,9 @@ void CmdPartDesignPolarPattern::activated(int iMsg) std::stringstream str; std::vector tempSelNames; str << "App.activeDocument()." << FeatName << ".Originals = ["; - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){ - str << "App.activeDocument()." << it->getFeatName() << ","; - tempSelNames.push_back(it->getFeatName()); + for (std::vector::iterator it = features.begin(); it != features.end(); ++it){ + str << "App.activeDocument()." << (*it)->getNameInDocument() << ","; + tempSelNames.push_back((*it)->getNameInDocument()); } str << "]"; @@ -903,14 +945,27 @@ CmdPartDesignScaled::CmdPartDesignScaled() void CmdPartDesignScaled::activated(int iMsg) { - std::vector selection = getSelection().getSelectionEx(); - - if (selection.size() != 1 || - (!selection[0].isObjectTypeOf(PartDesign::Additive::getClassTypeId()) && - !selection[0].isObjectTypeOf(PartDesign::Subtractive::getClassTypeId()))) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select only one additive or subtractive feature, please.")); - return; + // Get a valid original from the user + // First check selections + std::vector features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId()); + std::vector subtractive = getSelection().getObjectsOfType(PartDesign::Subtractive::getClassTypeId()); + features.insert(features.end(), subtractive.begin(), subtractive.end()); + // Next create a list of all eligible objects + if (features.size() == 0) { + features = getDocument()->getObjectsOfType(PartDesign::Additive::getClassTypeId()); + subtractive = getDocument()->getObjectsOfType(PartDesign::Subtractive::getClassTypeId()); + features.insert(features.end(), subtractive.begin(), subtractive.end()); + if (features.size() == 0) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"), + QObject::tr("Please create a subtractive or additive feature first, please")); + return; + } + } + // If there is more than one selected or eligible object, show dialog and let user pick one + if (features.size() > 1) { + PartDesignGui::FeaturePickDialog Dlg(features); + if ((Dlg.exec() != QDialog::Accepted) || (features = Dlg.getFeatures()).empty()) + return; // Cancelled or nothing selected } std::string FeatName = getUniqueObjectName("Scaled"); @@ -918,9 +973,9 @@ void CmdPartDesignScaled::activated(int iMsg) std::stringstream str; std::vector tempSelNames; str << "App.activeDocument()." << FeatName << ".Originals = ["; - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){ - str << "App.activeDocument()." << it->getFeatName() << ","; - tempSelNames.push_back(it->getFeatName()); + for (std::vector::iterator it = features.begin(); it != features.end(); ++it){ + str << "App.activeDocument()." << (*it)->getNameInDocument() << ","; + tempSelNames.push_back((*it)->getNameInDocument()); } str << "]"; @@ -964,14 +1019,27 @@ CmdPartDesignMultiTransform::CmdPartDesignMultiTransform() void CmdPartDesignMultiTransform::activated(int iMsg) { - std::vector selection = getSelection().getSelectionEx(); - - if (selection.size() != 1 || - (!selection[0].isObjectTypeOf(PartDesign::Additive::getClassTypeId()) && - !selection[0].isObjectTypeOf(PartDesign::Subtractive::getClassTypeId()))) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select only one additive or subtractive feature, please.")); - return; + // Get a valid original from the user + // First check selections + std::vector features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId()); + std::vector subtractive = getSelection().getObjectsOfType(PartDesign::Subtractive::getClassTypeId()); + features.insert(features.end(), subtractive.begin(), subtractive.end()); + // Next create a list of all eligible objects + if (features.size() == 0) { + features = getDocument()->getObjectsOfType(PartDesign::Additive::getClassTypeId()); + subtractive = getDocument()->getObjectsOfType(PartDesign::Subtractive::getClassTypeId()); + features.insert(features.end(), subtractive.begin(), subtractive.end()); + if (features.size() == 0) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"), + QObject::tr("Please create a subtractive or additive feature first, please")); + return; + } + } + // If there is more than one selected or eligible object, show dialog and let user pick one + if (features.size() > 1) { + PartDesignGui::FeaturePickDialog Dlg(features); + if ((Dlg.exec() != QDialog::Accepted) || (features = Dlg.getFeatures()).empty()) + return; // Cancelled or nothing selected } std::string FeatName = getUniqueObjectName("MultiTransform"); @@ -979,9 +1047,9 @@ void CmdPartDesignMultiTransform::activated(int iMsg) std::stringstream str; std::vector tempSelNames; str << "App.activeDocument()." << FeatName << ".Originals = ["; - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){ - str << "App.activeDocument()." << it->getFeatName() << ","; - tempSelNames.push_back(it->getFeatName()); + for (std::vector::iterator it = features.begin(); it != features.end(); ++it){ + str << "App.activeDocument()." << (*it)->getNameInDocument() << ","; + tempSelNames.push_back((*it)->getNameInDocument()); } str << "]"; diff --git a/src/Mod/PartDesign/Gui/FeaturePickDialog.cpp b/src/Mod/PartDesign/Gui/FeaturePickDialog.cpp new file mode 100644 index 000000000..2b95e6f83 --- /dev/null +++ b/src/Mod/PartDesign/Gui/FeaturePickDialog.cpp @@ -0,0 +1,75 @@ +/****************************************************************************** + * Copyright (c)2012 Jan Rheinlaender * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ******************************************************************************/ + +#include "PreCompiled.h" + +#ifndef _PreComp_ +# include +# include +# include +#endif + +#include +#include +#include +#include +#include + +#include "ui_FeaturePickDialog.h" +#include "FeaturePickDialog.h" + +using namespace PartDesignGui; + +FeaturePickDialog::FeaturePickDialog(std::vector& objects) + : QDialog(Gui::getMainWindow()), ui(new Ui_FeaturePickDialog) +{ + ui->setupUi(this); + for (std::vector::const_iterator o = objects.begin(); o != objects.end(); o++) + ui->listWidget->addItem(QString::fromAscii((*o)->getNameInDocument())); +} + +FeaturePickDialog::~FeaturePickDialog() +{ + +} + +std::vector FeaturePickDialog::getFeatures() { + std::vector result; + + for (std::vector::const_iterator s = features.begin(); s != features.end(); s++) + result.push_back(App::GetApplication().getActiveDocument()->getObject(s->toAscii().data())); + + return result; +} + + + +void FeaturePickDialog::accept() +{ + features.clear(); + QListIterator i(ui->listWidget->selectedItems()); + while (i.hasNext()) + features.push_back(i.next()->text()); + + QDialog::accept(); +} +#include "moc_FeaturePickDialog.cpp" diff --git a/src/Mod/PartDesign/Gui/FeaturePickDialog.h b/src/Mod/PartDesign/Gui/FeaturePickDialog.h new file mode 100644 index 000000000..c8569d2a2 --- /dev/null +++ b/src/Mod/PartDesign/Gui/FeaturePickDialog.h @@ -0,0 +1,55 @@ +/****************************************************************************** + * Copyright (c)2012 Jan Rheinlaender * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ******************************************************************************/ + +#ifndef PARTDESIGNGUI_FeaturePickDialog_H +#define PARTDESIGNGUI_FeaturePickDialog_H + +#include +#include +#include + +namespace PartDesignGui { + +class Ui_FeaturePickDialog; +class FeaturePickDialog : public QDialog +{ + Q_OBJECT + +public: + FeaturePickDialog(std::vector &objects); + ~FeaturePickDialog(); + + std::vector getFeatures(); + + void accept(); + +protected Q_SLOTS: + +private: + Ui_FeaturePickDialog* ui; + + std::vector features; +}; + +} + +#endif // PARTDESIGNGUI_FeaturePickDialog_H diff --git a/src/Mod/PartDesign/Gui/FeaturePickDialog.ui b/src/Mod/PartDesign/Gui/FeaturePickDialog.ui new file mode 100644 index 000000000..22e119385 --- /dev/null +++ b/src/Mod/PartDesign/Gui/FeaturePickDialog.ui @@ -0,0 +1,67 @@ + + + PartDesignGui::FeaturePickDialog + + + + 0 + 0 + 218 + 235 + + + + Choose feature + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + PartDesignGui::FeaturePickDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + PartDesignGui::FeaturePickDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +