diff --git a/src/Gui/InputVector.h b/src/Gui/InputVector.h index b5c101251..bdb9036d9 100644 --- a/src/Gui/InputVector.h +++ b/src/Gui/InputVector.h @@ -275,6 +275,13 @@ public: } } + void setPosition(const Base::Vector3f& v) + { + this->xPos->setValue(v.x); + this->yPos->setValue(v.y); + this->zPos->setValue(v.z); + } + Base::Vector3f getPosition() const { return Base::Vector3f((float)this->xPos->value(), diff --git a/src/Mod/Part/Gui/DlgRevolution.cpp b/src/Mod/Part/Gui/DlgRevolution.cpp index 32af63d27..d0a04668d 100644 --- a/src/Mod/Part/Gui/DlgRevolution.cpp +++ b/src/Mod/Part/Gui/DlgRevolution.cpp @@ -24,7 +24,13 @@ #include "PreCompiled.h" #ifndef _PreComp_ # include +# include +# include +# include +# include # include +# include +# include #endif #include "ui_DlgRevolution.h" @@ -40,16 +46,60 @@ #include #include #include +#include using namespace PartGui; +class DlgRevolution::EdgeSelection : public Gui::SelectionFilterGate +{ +public: + gp_Pnt loc; + gp_Dir dir; + bool canSelect; + + EdgeSelection() + : Gui::SelectionFilterGate((Gui::SelectionFilter*)0) + { + } + bool allow(App::Document*pDoc, App::DocumentObject*pObj, const char*sSubName) + { + this->canSelect = false; + if (!pObj->isDerivedFrom(Part::Feature::getClassTypeId())) + return false; + if (!sSubName || sSubName[0] == '\0') + return false; + std::string element(sSubName); + if (element.substr(0,4) != "Edge") + return false; + Part::Feature* fea = static_cast(pObj); + try { + TopoDS_Shape sub = fea->Shape.getShape().getSubShape(sSubName); + if (!sub.IsNull() && sub.ShapeType() == TopAbs_EDGE) { + const TopoDS_Edge& edge = TopoDS::Edge(sub); + BRepAdaptor_Curve adapt(edge); + if (adapt.GetType() == GeomAbs_Line) { + gp_Lin line = adapt.Line(); + this->loc = line.Location(); + this->dir = line.Direction(); + this->canSelect = true; + return true; + } + } + } + catch (...) { + } + + return false; + } +}; + DlgRevolution::DlgRevolution(QWidget* parent, Qt::WFlags fl) - : Gui::LocationDialog(parent, fl) + : Gui::LocationDialog(parent, fl), filter(0) { ui = new Ui_RevolutionComp(this); - ui->baseX->setRange(-DBL_MAX,DBL_MAX); - ui->baseY->setRange(-DBL_MAX,DBL_MAX); - ui->baseZ->setRange(-DBL_MAX,DBL_MAX); + ui->xPos->setRange(-DBL_MAX,DBL_MAX); + ui->yPos->setRange(-DBL_MAX,DBL_MAX); + ui->zPos->setRange(-DBL_MAX,DBL_MAX); findShapes(); Gui::ItemViewSelection sel(ui->treeWidget); @@ -62,6 +112,7 @@ DlgRevolution::DlgRevolution(QWidget* parent, Qt::WFlags fl) DlgRevolution::~DlgRevolution() { // no need to delete child widgets, Qt does it all for us + Gui::Selection().rmvSelectionGate(); delete ui; } @@ -142,9 +193,9 @@ void DlgRevolution::accept() .arg(axis.x,0,'f',2) .arg(axis.y,0,'f',2) .arg(axis.z,0,'f',2) - .arg(ui->baseX->value(),0,'f',2) - .arg(ui->baseY->value(),0,'f',2) - .arg(ui->baseZ->value(),0,'f',2) + .arg(ui->xPos->value(),0,'f',2) + .arg(ui->yPos->value(),0,'f',2) + .arg(ui->zPos->value(),0,'f',2) .arg(ui->angle->value(),0,'f',2); Gui::Application::Instance->runPythonCode((const char*)code.toAscii()); QByteArray to = name.toAscii(); @@ -159,6 +210,24 @@ void DlgRevolution::accept() QDialog::accept(); } +void DlgRevolution::on_selectLine_clicked() +{ + if (!filter) { + filter = new EdgeSelection(); + Gui::Selection().addSelectionGate(filter); + } +} + +void DlgRevolution::onSelectionChanged(const Gui::SelectionChanges& msg) +{ + if (msg.Type == Gui::SelectionChanges::AddSelection) { + if (filter && filter->canSelect) { + ui->setPosition (Base::convertTo(filter->loc)); + ui->setDirection(Base::convertTo(filter->dir)); + } + } +} + // --------------------------------------- TaskRevolution::TaskRevolution() diff --git a/src/Mod/Part/Gui/DlgRevolution.h b/src/Mod/Part/Gui/DlgRevolution.h index 50359a474..8e4ebba50 100644 --- a/src/Mod/Part/Gui/DlgRevolution.h +++ b/src/Mod/Part/Gui/DlgRevolution.h @@ -23,6 +23,7 @@ #ifndef PARTGUI_DLGREVOLUTION_H #define PARTGUI_DLGREVOLUTION_H +#include #include #include #include @@ -30,7 +31,7 @@ namespace PartGui { class Ui_DlgRevolution; -class DlgRevolution : public Gui::LocationDialog +class DlgRevolution : public Gui::LocationDialog, public Gui::SelectionObserver { Q_OBJECT @@ -44,13 +45,19 @@ public: protected: void changeEvent(QEvent *e); +private Q_SLOTS: + void on_selectLine_clicked(); + private: void findShapes(); void directionActivated(int); + void onSelectionChanged(const Gui::SelectionChanges& msg); private: typedef Gui::LocationInterfaceComp Ui_RevolutionComp; Ui_RevolutionComp* ui; + class EdgeSelection; + EdgeSelection* filter; }; class TaskRevolution : public Gui::TaskView::TaskDialog diff --git a/src/Mod/Part/Gui/DlgRevolution.ui b/src/Mod/Part/Gui/DlgRevolution.ui index 2f5f694c9..6c5635118 100644 --- a/src/Mod/Part/Gui/DlgRevolution.ui +++ b/src/Mod/Part/Gui/DlgRevolution.ui @@ -49,7 +49,7 @@ - + @@ -62,7 +62,7 @@ - + @@ -88,7 +88,7 @@ - + @@ -105,7 +105,7 @@ - + Qt::Vertical @@ -118,7 +118,7 @@ - + QAbstractItemView::ExtendedSelection @@ -136,14 +136,21 @@ + + + + Select line in 3D view + + + treeWidget angle - baseX - baseY - baseZ + xPos + yPos + zPos direction