+ path selection on sweep panel
This commit is contained in:
parent
a2243e9fb5
commit
0874bfac75
|
@ -24,8 +24,11 @@
|
|||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <QEventLoop>
|
||||
# include <QMessageBox>
|
||||
# include <QTextStream>
|
||||
# include <BRepBuilderAPI_MakeWire.hxx>
|
||||
# include <TopoDS.hxx>
|
||||
#endif
|
||||
|
||||
#include "ui_TaskSweep.h"
|
||||
|
@ -52,6 +55,8 @@ class SweepWidget::Private
|
|||
{
|
||||
public:
|
||||
Ui_TaskSweep ui;
|
||||
QEventLoop loop;
|
||||
QString buttonText;
|
||||
std::string document;
|
||||
Private()
|
||||
{
|
||||
|
@ -59,6 +64,22 @@ public:
|
|||
~Private()
|
||||
{
|
||||
}
|
||||
|
||||
class EdgeSelection : public Gui::SelectionFilterGate
|
||||
{
|
||||
public:
|
||||
EdgeSelection()
|
||||
: Gui::SelectionFilterGate((Gui::SelectionFilter*)0)
|
||||
{
|
||||
}
|
||||
bool allow(App::Document*pDoc, App::DocumentObject*pObj, const char*sSubName)
|
||||
{
|
||||
if (!sSubName || sSubName[0] == '\0')
|
||||
return false;
|
||||
std::string element(sSubName);
|
||||
return element.substr(0,4) == "Edge";
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/* TRANSLATOR PartGui::SweepWidget */
|
||||
|
@ -72,6 +93,7 @@ SweepWidget::SweepWidget(QWidget* parent)
|
|||
d->ui.setupUi(this);
|
||||
d->ui.selector->setAvailableLabel(tr("Vertex/Edge/Wire/Face"));
|
||||
d->ui.selector->setSelectedLabel(tr("Sweep"));
|
||||
d->ui.labelPath->clear();
|
||||
|
||||
connect(d->ui.selector->availableTreeWidget(), SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
|
||||
this, SLOT(onCurrentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)));
|
||||
|
@ -117,32 +139,61 @@ void SweepWidget::findShapes()
|
|||
}
|
||||
}
|
||||
|
||||
bool SweepWidget::isPathValid(const Gui::SelectionObject& sel) const
|
||||
{
|
||||
const App::DocumentObject* path = sel.getObject();
|
||||
if (!(path && path->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())))
|
||||
return false;
|
||||
const std::vector<std::string>& sub = sel.getSubNames();
|
||||
|
||||
|
||||
TopoDS_Shape pathShape;
|
||||
const Part::TopoShape& shape = static_cast<const Part::Feature*>(path)->Shape.getValue();
|
||||
if (!sub.empty()) {
|
||||
try {
|
||||
BRepBuilderAPI_MakeWire mkWire;
|
||||
for (std::vector<std::string>::const_iterator it = sub.begin(); it != sub.end(); ++it) {
|
||||
TopoDS_Shape subshape = shape.getSubShape(it->c_str());
|
||||
mkWire.Add(TopoDS::Edge(subshape));
|
||||
}
|
||||
pathShape = mkWire.Wire();
|
||||
}
|
||||
catch (...) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (shape._Shape.ShapeType() == TopAbs_EDGE) {
|
||||
pathShape = shape._Shape;
|
||||
}
|
||||
else if (shape._Shape.ShapeType() == TopAbs_WIRE) {
|
||||
BRepBuilderAPI_MakeWire mkWire(TopoDS::Wire(shape._Shape));
|
||||
pathShape = mkWire.Wire();
|
||||
}
|
||||
|
||||
return (!pathShape.IsNull());
|
||||
}
|
||||
|
||||
bool SweepWidget::accept()
|
||||
{
|
||||
if (d->loop.isRunning())
|
||||
return false;
|
||||
Gui::SelectionFilter edgeFilter ("SELECT Part::Feature SUBELEMENT Edge COUNT 1..");
|
||||
Gui::SelectionFilter partFilter ("SELECT Part::Feature COUNT 1");
|
||||
bool matchEdge = edgeFilter.match();
|
||||
bool matchPart = partFilter.match();
|
||||
if (!matchEdge && !matchPart) {
|
||||
QMessageBox::critical(this, tr("Sweep path"), tr("Select an edge or wire you want to sweep along."));
|
||||
QMessageBox::critical(this, tr("Sweep path"), tr("Select one or more connected edges you want to sweep along."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// get the selected object
|
||||
std::string selection;
|
||||
std::string spineObject, spineLabel;
|
||||
if (matchEdge) {
|
||||
const std::vector<Gui::SelectionObject>& result = edgeFilter.Result[0];
|
||||
selection = result.front().getAsPropertyLinkSubString();
|
||||
spineObject = result.front().getFeatName();
|
||||
spineLabel = result.front().getObject()->Label.getValue();
|
||||
}
|
||||
else {
|
||||
const std::vector<Gui::SelectionObject>& result = partFilter.Result[0];
|
||||
selection = result.front().getAsPropertyLinkSubString();
|
||||
spineObject = result.front().getFeatName();
|
||||
spineLabel = result.front().getObject()->Label.getValue();
|
||||
}
|
||||
const std::vector<Gui::SelectionObject>& result = matchEdge
|
||||
? edgeFilter.Result[0] : partFilter.Result[0];
|
||||
selection = result.front().getAsPropertyLinkSubString();
|
||||
spineObject = result.front().getFeatName();
|
||||
spineLabel = result.front().getObject()->Label.getValue();
|
||||
|
||||
QString list, solid, frenet;
|
||||
if (d->ui.checkSolid->isChecked())
|
||||
|
@ -211,6 +262,8 @@ bool SweepWidget::accept()
|
|||
|
||||
bool SweepWidget::reject()
|
||||
{
|
||||
if (d->loop.isRunning())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -226,6 +279,54 @@ void SweepWidget::onCurrentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem
|
|||
}
|
||||
}
|
||||
|
||||
void SweepWidget::on_buttonPath_clicked()
|
||||
{
|
||||
if (!d->loop.isRunning()) {
|
||||
QList<QWidget*> c = this->findChildren<QWidget*>();
|
||||
for (QList<QWidget*>::iterator it = c.begin(); it != c.end(); ++it)
|
||||
(*it)->setEnabled(false);
|
||||
d->buttonText = d->ui.buttonPath->text();
|
||||
d->ui.buttonPath->setText(tr("Done"));
|
||||
d->ui.buttonPath->setEnabled(true);
|
||||
d->ui.labelPath->setText(tr("Select one or more connected edges in the 3d view and press 'Done'"));
|
||||
d->ui.labelPath->setEnabled(true);
|
||||
|
||||
Gui::Selection().clearSelection();
|
||||
Gui::Selection().addSelectionGate(new Private::EdgeSelection());
|
||||
d->loop.exec();
|
||||
}
|
||||
else {
|
||||
QList<QWidget*> c = this->findChildren<QWidget*>();
|
||||
for (QList<QWidget*>::iterator it = c.begin(); it != c.end(); ++it)
|
||||
(*it)->setEnabled(true);
|
||||
d->ui.buttonPath->setText(d->buttonText);
|
||||
d->ui.labelPath->clear();
|
||||
Gui::Selection().rmvSelectionGate();
|
||||
d->loop.quit();
|
||||
|
||||
Gui::SelectionFilter edgeFilter ("SELECT Part::Feature SUBELEMENT Edge COUNT 1..");
|
||||
Gui::SelectionFilter partFilter ("SELECT Part::Feature COUNT 1");
|
||||
bool matchEdge = edgeFilter.match();
|
||||
bool matchPart = partFilter.match();
|
||||
if (matchEdge) {
|
||||
// check if path is valid
|
||||
const std::vector<Gui::SelectionObject>& result = edgeFilter.Result[0];
|
||||
if (!isPathValid(result.front())) {
|
||||
QMessageBox::critical(this, tr("Sweep path"), tr("The selected sweep path is invalid."));
|
||||
Gui::Selection().clearSelection();
|
||||
}
|
||||
}
|
||||
else if (matchPart) {
|
||||
// check if path is valid
|
||||
const std::vector<Gui::SelectionObject>& result = partFilter.Result[0];
|
||||
if (!isPathValid(result.front())) {
|
||||
QMessageBox::critical(this, tr("Sweep path"), tr("The selected sweep path is invalid."));
|
||||
Gui::Selection().clearSelection();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SweepWidget::changeEvent(QEvent *e)
|
||||
{
|
||||
QWidget::changeEvent(e);
|
||||
|
|
|
@ -29,6 +29,9 @@
|
|||
|
||||
class QTreeWidgetItem;
|
||||
|
||||
namespace Gui {
|
||||
class SelectionObject;
|
||||
}
|
||||
namespace PartGui {
|
||||
|
||||
class SweepWidget : public QWidget
|
||||
|
@ -44,10 +47,12 @@ public:
|
|||
|
||||
private Q_SLOTS:
|
||||
void onCurrentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*);
|
||||
void on_buttonPath_clicked();
|
||||
|
||||
private:
|
||||
void changeEvent(QEvent *e);
|
||||
void findShapes();
|
||||
bool isPathValid(const Gui::SelectionObject& sel) const;
|
||||
|
||||
private:
|
||||
class Private;
|
||||
|
|
|
@ -6,25 +6,70 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>336</width>
|
||||
<height>326</height>
|
||||
<width>333</width>
|
||||
<height>434</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Sweep</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" colspan="3">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Select one or more profiles and select an edge or wire
|
||||
in the 3D view for the sweep path.</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="3">
|
||||
<widget class="Gui::ActionSelector" name="selector"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QPushButton" name="buttonPath">
|
||||
<property name="text">
|
||||
<string>Sweep Path</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="2">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>224</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="3">
|
||||
<widget class="QLabel" name="labelPath">
|
||||
<property name="text">
|
||||
<string notr="true">TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QCheckBox" name="checkSolid">
|
||||
<property name="text">
|
||||
<string>Create solid</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<item row="4" column="1">
|
||||
<widget class="QCheckBox" name="checkFrenet">
|
||||
<property name="text">
|
||||
<string>Frenet</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
|
@ -37,24 +82,6 @@
|
|||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QCheckBox" name="checkFrenet">
|
||||
<property name="text">
|
||||
<string>Frenet</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="3">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Select one or more profiles and select an edge or wire
|
||||
in the 3D view for the sweep path.</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
|
|
Loading…
Reference in New Issue
Block a user