Enhanced Pick dialog for PartDesign feature's sketches

This commit is contained in:
jrheinlaender
2013-03-30 14:33:06 +04:30
committed by Stefan Tröger
parent 2e4b91a2d7
commit fb85cd2899
9 changed files with 467 additions and 1598 deletions

View File

@@ -39,12 +39,51 @@
using namespace PartDesignGui;
FeaturePickDialog::FeaturePickDialog(std::vector<App::DocumentObject*>& objects)
const QString FeaturePickDialog::getFeatureStatusString(const featureStatus st)
{
switch (st) {
case validFeature: return tr("Valid");
case invalidShape: return tr("Invalid shape");
case noWire: return tr("No wire in sketch");
case isUsed: return tr("Sketch already used by other feature");
case otherBody: return tr("Sketch belongs to another Body feature");
}
return tr("");
}
FeaturePickDialog::FeaturePickDialog(std::vector<App::DocumentObject*>& objects,
const std::vector<featureStatus>& status)
: 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::fromLatin1((*o)->getNameInDocument()));
connect(ui->checkOtherBody, SIGNAL(toggled(bool)), this, SLOT(onCheckOtherBody(bool)));
connect(ui->checkOtherFeature, SIGNAL(toggled(bool)), this, SLOT(onCheckOtherFeature(bool)));
connect(ui->radioIndependent, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool)));
connect(ui->radioDependent, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool)));
connect(ui->radioXRef, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool)));
ui->checkOtherBody->setChecked(false);
ui->checkOtherBody->setEnabled(false); // TODO: implement
ui->checkOtherFeature->setChecked(false);
ui->checkOtherFeature->setEnabled(false); // TODO: implement
ui->radioIndependent->setChecked(true);
ui->radioIndependent->setEnabled(false);
// These are not implemented yet
ui->radioDependent->setEnabled(false);
ui->radioXRef->setEnabled(false);
std::vector<featureStatus>::const_iterator st = status.begin();
for (std::vector<App::DocumentObject*>::const_iterator o = objects.begin(); o != objects.end(); ++o) {
QListWidgetItem* item = new QListWidgetItem(QString::fromAscii((*o)->getNameInDocument()) +
QString::fromAscii(" (") + getFeatureStatusString(*st) + QString::fromAscii(")"));
ui->listWidget->addItem(item);
st++;
}
statuses = status;
updateList();
}
FeaturePickDialog::~FeaturePickDialog()
@@ -52,6 +91,50 @@ FeaturePickDialog::~FeaturePickDialog()
}
void FeaturePickDialog::updateList()
{
int index = 0;
for (std::vector<featureStatus>::const_iterator st = statuses.begin(); st != statuses.end(); st++) {
QListWidgetItem* item = ui->listWidget->item(index);
switch (*st) {
case validFeature: item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); break;
case invalidShape: item->setFlags(Qt::NoItemFlags); break;
case noWire: item->setFlags(Qt::NoItemFlags); break;
case isUsed: item->setFlags(ui->checkOtherFeature->isChecked() ? Qt::ItemIsSelectable | Qt::ItemIsEnabled : Qt::NoItemFlags); break;
case otherBody: item->setFlags(ui->checkOtherBody->isChecked() ? Qt::ItemIsSelectable | Qt::ItemIsEnabled : Qt::NoItemFlags); break;
}
index++;
}
}
void FeaturePickDialog::onCheckOtherFeature(bool checked)
{
ui->radioIndependent->setEnabled(checked);
// TODO: Not implemented yet
//ui->radioDependent->setEnabled(checked);
//ui->radioXRef->setEnabled(checked);
updateList();
}
void FeaturePickDialog::onCheckOtherBody(bool checked)
{
ui->radioIndependent->setEnabled(checked);
// TODO: Not implemented yet
//ui->radioDependent->setEnabled(checked);
//ui->radioXRef->setEnabled(checked);
updateList();
}
void FeaturePickDialog::onUpdate(bool)
{
updateList();
}
std::vector<App::DocumentObject*> FeaturePickDialog::getFeatures() {
std::vector<App::DocumentObject*> result;
@@ -67,8 +150,11 @@ void FeaturePickDialog::accept()
{
features.clear();
QListIterator<QListWidgetItem*> i(ui->listWidget->selectedItems());
while (i.hasNext())
features.push_back(i.next()->text());
while (i.hasNext()) {
QString t = i.next()->text();
t = t.left(t.indexOf(QString::fromAscii("(")) - 1);
features.push_back(t);
}
QDialog::accept();
}