+ path selection on sweep panel
This commit is contained in:
parent
a2243e9fb5
commit
0874bfac75
|
@ -24,8 +24,11 @@
|
||||||
#include "PreCompiled.h"
|
#include "PreCompiled.h"
|
||||||
|
|
||||||
#ifndef _PreComp_
|
#ifndef _PreComp_
|
||||||
|
# include <QEventLoop>
|
||||||
# include <QMessageBox>
|
# include <QMessageBox>
|
||||||
# include <QTextStream>
|
# include <QTextStream>
|
||||||
|
# include <BRepBuilderAPI_MakeWire.hxx>
|
||||||
|
# include <TopoDS.hxx>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "ui_TaskSweep.h"
|
#include "ui_TaskSweep.h"
|
||||||
|
@ -52,6 +55,8 @@ class SweepWidget::Private
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Ui_TaskSweep ui;
|
Ui_TaskSweep ui;
|
||||||
|
QEventLoop loop;
|
||||||
|
QString buttonText;
|
||||||
std::string document;
|
std::string document;
|
||||||
Private()
|
Private()
|
||||||
{
|
{
|
||||||
|
@ -59,6 +64,22 @@ public:
|
||||||
~Private()
|
~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 */
|
/* TRANSLATOR PartGui::SweepWidget */
|
||||||
|
@ -72,6 +93,7 @@ SweepWidget::SweepWidget(QWidget* parent)
|
||||||
d->ui.setupUi(this);
|
d->ui.setupUi(this);
|
||||||
d->ui.selector->setAvailableLabel(tr("Vertex/Edge/Wire/Face"));
|
d->ui.selector->setAvailableLabel(tr("Vertex/Edge/Wire/Face"));
|
||||||
d->ui.selector->setSelectedLabel(tr("Sweep"));
|
d->ui.selector->setSelectedLabel(tr("Sweep"));
|
||||||
|
d->ui.labelPath->clear();
|
||||||
|
|
||||||
connect(d->ui.selector->availableTreeWidget(), SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
|
connect(d->ui.selector->availableTreeWidget(), SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
|
||||||
this, SLOT(onCurrentItemChanged(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()
|
bool SweepWidget::accept()
|
||||||
{
|
{
|
||||||
|
if (d->loop.isRunning())
|
||||||
|
return false;
|
||||||
Gui::SelectionFilter edgeFilter ("SELECT Part::Feature SUBELEMENT Edge COUNT 1..");
|
Gui::SelectionFilter edgeFilter ("SELECT Part::Feature SUBELEMENT Edge COUNT 1..");
|
||||||
Gui::SelectionFilter partFilter ("SELECT Part::Feature COUNT 1");
|
Gui::SelectionFilter partFilter ("SELECT Part::Feature COUNT 1");
|
||||||
bool matchEdge = edgeFilter.match();
|
bool matchEdge = edgeFilter.match();
|
||||||
bool matchPart = partFilter.match();
|
bool matchPart = partFilter.match();
|
||||||
if (!matchEdge && !matchPart) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the selected object
|
// get the selected object
|
||||||
std::string selection;
|
std::string selection;
|
||||||
std::string spineObject, spineLabel;
|
std::string spineObject, spineLabel;
|
||||||
if (matchEdge) {
|
const std::vector<Gui::SelectionObject>& result = matchEdge
|
||||||
const std::vector<Gui::SelectionObject>& result = edgeFilter.Result[0];
|
? edgeFilter.Result[0] : partFilter.Result[0];
|
||||||
selection = result.front().getAsPropertyLinkSubString();
|
selection = result.front().getAsPropertyLinkSubString();
|
||||||
spineObject = result.front().getFeatName();
|
spineObject = result.front().getFeatName();
|
||||||
spineLabel = result.front().getObject()->Label.getValue();
|
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString list, solid, frenet;
|
QString list, solid, frenet;
|
||||||
if (d->ui.checkSolid->isChecked())
|
if (d->ui.checkSolid->isChecked())
|
||||||
|
@ -211,6 +262,8 @@ bool SweepWidget::accept()
|
||||||
|
|
||||||
bool SweepWidget::reject()
|
bool SweepWidget::reject()
|
||||||
{
|
{
|
||||||
|
if (d->loop.isRunning())
|
||||||
|
return false;
|
||||||
return true;
|
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)
|
void SweepWidget::changeEvent(QEvent *e)
|
||||||
{
|
{
|
||||||
QWidget::changeEvent(e);
|
QWidget::changeEvent(e);
|
||||||
|
|
|
@ -29,6 +29,9 @@
|
||||||
|
|
||||||
class QTreeWidgetItem;
|
class QTreeWidgetItem;
|
||||||
|
|
||||||
|
namespace Gui {
|
||||||
|
class SelectionObject;
|
||||||
|
}
|
||||||
namespace PartGui {
|
namespace PartGui {
|
||||||
|
|
||||||
class SweepWidget : public QWidget
|
class SweepWidget : public QWidget
|
||||||
|
@ -44,10 +47,12 @@ public:
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void onCurrentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*);
|
void onCurrentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*);
|
||||||
|
void on_buttonPath_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void changeEvent(QEvent *e);
|
void changeEvent(QEvent *e);
|
||||||
void findShapes();
|
void findShapes();
|
||||||
|
bool isPathValid(const Gui::SelectionObject& sel) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class Private;
|
class Private;
|
||||||
|
|
|
@ -6,25 +6,70 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>336</width>
|
<width>333</width>
|
||||||
<height>326</height>
|
<height>434</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Sweep</string>
|
<string>Sweep</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<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">
|
<item row="1" column="0" colspan="3">
|
||||||
<widget class="Gui::ActionSelector" name="selector"/>
|
<widget class="Gui::ActionSelector" name="selector"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<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">
|
<widget class="QCheckBox" name="checkSolid">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Create solid</string>
|
<string>Create solid</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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">
|
<spacer name="horizontalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
|
@ -37,24 +82,6 @@
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user