PartDesign/Gui: enhance the TaskFeaturePick with new cotegory of sketches: notInBody

Also add option tp show already used sketches and fix some spacing.
This commit is contained in:
Alexander Golubev 2015-07-20 22:59:37 +03:00 committed by Stefan Tröger
parent ffc6cc2f23
commit 4590305921
4 changed files with 127 additions and 51 deletions

View File

@ -941,12 +941,22 @@ void finishFeature(const Gui::Command* cmd, const std::string& FeatName, const b
for (std::vector<App::DocumentObject*>::iterator s = sketches.begin(); s != sketches.end(); s++) {
// Check whether this plane belongs to the active body
if (pcActiveBody && !pcActiveBody->hasFeature(*s)) {
if(pcActivePart && pcActivePart->hasObject(*s, true))
status.push_back(PartDesignGui::TaskFeaturePick::otherBody);
else
if (!pcActiveBody) {
// We work in the old style outside any body
if (PartDesign::Body::findBodyOf (*s)) {
status.push_back(PartDesignGui::TaskFeaturePick::otherPart);
++validSketches;
continue;
}
} else if (!pcActiveBody->hasFeature(*s)) {
// Check whether this plane belongs to the active body
if(pcActivePart && pcActivePart->hasObject(*s, true)) {
status.push_back(PartDesignGui::TaskFeaturePick::otherBody);
} else if (PartDesign::Body::findBodyOf(*s)) {
status.push_back(PartDesignGui::TaskFeaturePick::otherPart);
} else {
status.push_back(PartDesignGui::TaskFeaturePick::notInBody);
}
++validSketches;
continue;
@ -1056,8 +1066,13 @@ void prepareSketchBased(Gui::Command* cmd, const std::string& which,
//if there is a sketch selected which is from annother body or part we need to bring up the
//pick task dialog to decide how those are handled
bool ext = std::find(status.begin(), status.end(), PartDesignGui::TaskFeaturePick::otherBody) != status.end();
ext |= std::find(status.begin(), status.end(), PartDesignGui::TaskFeaturePick::otherPart) != status.end();
bool ext = std::find_if( status.begin(), status.end(),
[] (const PartDesignGui::TaskFeaturePick::featureStatus& s) {
return s == PartDesignGui::TaskFeaturePick::otherBody ||
s == PartDesignGui::TaskFeaturePick::otherPart ||
s == PartDesignGui::TaskFeaturePick::notInBody;
}
) != status.end();
// If there is more than one selection/possibility, show dialog and let user pick sketch
if ((bNoSketchWasSelected && validSketches > 1) ||

View File

@ -42,6 +42,7 @@
#include "TaskFeaturePick.h"
#include "Workbench.h"
#include <Mod/PartDesign/App/Body.h>
#include <Mod/Sketcher/App/SketchObject.h>
using namespace PartDesignGui;
@ -54,6 +55,7 @@ const QString TaskFeaturePick::getFeatureStatusString(const featureStatus st)
case isUsed: return tr("Sketch already used by other feature");
case otherBody: return tr("Belongs to another body");
case otherPart: return tr("Belongs to another part");
case notInBody: return tr("Doesn't belongs to any body");
case basePlane: return tr("Base plane");
case afterTip: return tr("Feature is located after the tip feature");
}
@ -71,6 +73,7 @@ TaskFeaturePick::TaskFeaturePick(std::vector<App::DocumentObject*>& objects,
proxy = new QWidget(this);
ui->setupUi(proxy);
connect(ui->checkUsed, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool)));
connect(ui->checkOtherBody, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool)));
connect(ui->bodyRadioIndependent, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool)));
connect(ui->bodyRadioXRef, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool)));
@ -78,6 +81,9 @@ TaskFeaturePick::TaskFeaturePick(std::vector<App::DocumentObject*>& objects,
connect(ui->partRadioIndependent, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool)));
connect(ui->partRadioDependent, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool)));
connect(ui->partRadioXRef, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool)));
connect(ui->checkNoBody, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool)));
connect(ui->nobodyRadioIndependent, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool)));
connect(ui->nobodyRadioXRef, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool)));
auto guidoc = Gui::Application::Instance->activeDocument();
auto origin_obj = App::GetApplication().getActiveDocument()->getObjectsOfType<App::Origin>();
@ -130,9 +136,11 @@ void TaskFeaturePick::updateList()
switch (*st) {
case validFeature: item->setHidden(false); break;
case invalidShape: item->setHidden(true); break;
case isUsed: item->setHidden(!ui->checkUsed->isChecked()); break;
case noWire: item->setHidden(true); break;
case otherBody: item->setHidden(ui->checkOtherBody->isChecked() ? false : true); break;
case otherPart: item->setHidden(ui->checkOtherPart->isChecked() ? false : true); break;
case otherBody: item->setHidden(!ui->checkOtherBody->isChecked()); break;
case otherPart: item->setHidden(!ui->checkOtherPart->isChecked()); break;
case notInBody: item->setHidden(!ui->checkNoBody->isChecked()); break;
case basePlane: item->setHidden(false); break;
case afterTip: item->setHidden(true); break;
}
@ -171,7 +179,6 @@ std::vector<App::DocumentObject*> TaskFeaturePick::getFeatures() {
std::vector<App::DocumentObject*> TaskFeaturePick::buildFeatures() {
int index = 0;
std::vector<App::DocumentObject*> result;
auto activeBody = PartDesignGui::getBody(false);
@ -193,10 +200,10 @@ std::vector<App::DocumentObject*> TaskFeaturePick::buildFeatures() {
auto copy = makeCopy(obj, true);
activeBody->addFeature(copy);
result.push_back(copy);
}
else
} else {
result.push_back(obj);
}
}
else if(*st == otherPart) {
if(!ui->partRadioXRef->isChecked()) {
@ -212,6 +219,19 @@ std::vector<App::DocumentObject*> TaskFeaturePick::buildFeatures() {
}
else
result.push_back(obj);
} else if(*st == notInBody) {
if(ui->bodyRadioIndependent->isChecked()) {
auto copy = makeCopy(obj, true);
activeBody->addFeature(copy);
// doesn't supposed to get here anything but sketch but to be on the safe side better to check
if (copy->getTypeId().isDerivedFrom(Sketcher::SketchObject::getClassTypeId())) {
Sketcher::SketchObject *sketch = static_cast<Sketcher::SketchObject*>(copy);
Workbench::fixSketchSupport(sketch);
}
result.push_back(copy);
}
else
result.push_back(obj);
}
else
result.push_back(obj);
@ -295,6 +315,7 @@ void TaskFeaturePick::showExternal(bool val) {
ui->checkOtherBody->setChecked(val);
ui->checkOtherPart->setChecked(val);
ui->checkNoBody->setChecked(val);
updateList();
}

View File

@ -47,6 +47,7 @@ public:
isUsed,
otherBody,
otherPart,
notInBody,
basePlane,
afterTip
};

View File

@ -7,16 +7,23 @@
<x>0</x>
<y>0</y>
<width>388</width>
<height>479</height>
<height>493</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QListWidget" name="listWidget"/>
</item>
<item>
<widget class="QCheckBox" name="checkUsed">
<property name="text">
<string>Allow used features</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="checkOtherBody">
<property name="title">
@ -91,6 +98,38 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="checkNoBody">
<property name="title">
<string>Allow features not belong to any body</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QRadioButton" name="nobodyRadioIndependent">
<property name="text">
<string>Make independent copy (recommended)</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="nobodyRadioXRef">
<property name="text">
<string>Create cross-reference</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>