PartDesign: list original feature candidates for creation of transformed features if current selection is not valid

This commit is contained in:
jrheinlaender 2012-09-15 09:20:51 +02:00 committed by logari81
parent 2540a19a5d
commit 4679a10d5c
5 changed files with 325 additions and 55 deletions

View File

@ -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

View File

@ -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<Gui::SelectionObject> 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<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
std::vector<App::DocumentObject*> 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<std::string> tempSelNames;
str << "App.activeDocument()." << FeatName << ".Originals = [";
for (std::vector<Gui::SelectionObject>::iterator it = selection.begin(); it != selection.end(); ++it){
str << "App.activeDocument()." << it->getFeatName() << ",";
tempSelNames.push_back(it->getFeatName());
for (std::vector<App::DocumentObject*>::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<Gui::SelectionObject> selection = getSelection().getSelectionEx();
// Get a valid original from the user
// First check selections
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
std::vector<App::DocumentObject*> 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<std::string> tempSelNames;
str << "App.activeDocument()." << FeatName << ".Originals = [";
for (std::vector<Gui::SelectionObject>::iterator it = selection.begin(); it != selection.end(); ++it){
str << "App.activeDocument()." << it->getFeatName() << ",";
tempSelNames.push_back(it->getFeatName());
for (std::vector<App::DocumentObject*>::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<Gui::SelectionObject> 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<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
std::vector<App::DocumentObject*> 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<std::string> tempSelNames;
str << "App.activeDocument()." << FeatName << ".Originals = [";
for (std::vector<Gui::SelectionObject>::iterator it = selection.begin(); it != selection.end(); ++it){
str << "App.activeDocument()." << it->getFeatName() << ",";
tempSelNames.push_back(it->getFeatName());
for (std::vector<App::DocumentObject*>::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<Gui::SelectionObject> 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<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
std::vector<App::DocumentObject*> 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<std::string> tempSelNames;
str << "App.activeDocument()." << FeatName << ".Originals = [";
for (std::vector<Gui::SelectionObject>::iterator it = selection.begin(); it != selection.end(); ++it){
str << "App.activeDocument()." << it->getFeatName() << ",";
tempSelNames.push_back(it->getFeatName());
for (std::vector<App::DocumentObject*>::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<Gui::SelectionObject> 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<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
std::vector<App::DocumentObject*> 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<std::string> tempSelNames;
str << "App.activeDocument()." << FeatName << ".Originals = [";
for (std::vector<Gui::SelectionObject>::iterator it = selection.begin(); it != selection.end(); ++it){
str << "App.activeDocument()." << it->getFeatName() << ",";
tempSelNames.push_back(it->getFeatName());
for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back((*it)->getNameInDocument());
}
str << "]";

View File

@ -0,0 +1,75 @@
/******************************************************************************
* Copyright (c)2012 Jan Rheinlaender <jrheinlaender@users.sourceforge.net> *
* *
* 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 <QPixmap>
# include <QDialog>
# include <QListIterator>
#endif
#include <Gui/Application.h>
#include <Gui/BitmapFactory.h>
#include <Gui/MainWindow.h>
#include <App/Document.h>
#include <Base/Tools.h>
#include "ui_FeaturePickDialog.h"
#include "FeaturePickDialog.h"
using namespace PartDesignGui;
FeaturePickDialog::FeaturePickDialog(std::vector<App::DocumentObject*>& objects)
: QDialog(Gui::getMainWindow()), ui(new Ui_FeaturePickDialog)
{
ui->setupUi(this);
for (std::vector<App::DocumentObject*>::const_iterator o = objects.begin(); o != objects.end(); o++)
ui->listWidget->addItem(QString::fromAscii((*o)->getNameInDocument()));
}
FeaturePickDialog::~FeaturePickDialog()
{
}
std::vector<App::DocumentObject*> FeaturePickDialog::getFeatures() {
std::vector<App::DocumentObject*> result;
for (std::vector<QString>::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<QListWidgetItem*> i(ui->listWidget->selectedItems());
while (i.hasNext())
features.push_back(i.next()->text());
QDialog::accept();
}
#include "moc_FeaturePickDialog.cpp"

View File

@ -0,0 +1,55 @@
/******************************************************************************
* Copyright (c)2012 Jan Rheinlaender <jrheinlaender@users.sourceforge.net> *
* *
* 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 <QDialog>
#include <QString>
#include <App/DocumentObject.h>
namespace PartDesignGui {
class Ui_FeaturePickDialog;
class FeaturePickDialog : public QDialog
{
Q_OBJECT
public:
FeaturePickDialog(std::vector<App::DocumentObject*> &objects);
~FeaturePickDialog();
std::vector<App::DocumentObject*> getFeatures();
void accept();
protected Q_SLOTS:
private:
Ui_FeaturePickDialog* ui;
std::vector<QString> features;
};
}
#endif // PARTDESIGNGUI_FeaturePickDialog_H

View File

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PartDesignGui::FeaturePickDialog</class>
<widget class="QDialog" name="PartDesignGui::FeaturePickDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>218</width>
<height>235</height>
</rect>
</property>
<property name="windowTitle">
<string>Choose feature</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="listWidget"/>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>PartDesignGui::FeaturePickDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>PartDesignGui::FeaturePickDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>