0000248: make the revolve-axis selectable

This commit is contained in:
wmayer 2012-04-28 14:21:32 +02:00
parent 7067a1690e
commit f44a17a5a9
4 changed files with 106 additions and 16 deletions

View File

@ -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(),

View File

@ -24,7 +24,13 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QMessageBox>
# include <gp_Dir.hxx>
# include <gp_Lin.hxx>
# include <gp_Pnt.hxx>
# include <BRepAdaptor_Curve.hxx>
# include <TopExp_Explorer.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Edge.hxx>
#endif
#include "ui_DlgRevolution.h"
@ -40,16 +46,60 @@
#include <Gui/Utilities.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
#include <Mod/Part/App/Tools.h>
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<Part::Feature*>(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<Base::Vector3f>(filter->loc));
ui->setDirection(Base::convertTo<Base::Vector3f>(filter->dir));
}
}
}
// ---------------------------------------
TaskRevolution::TaskRevolution()

View File

@ -23,6 +23,7 @@
#ifndef PARTGUI_DLGREVOLUTION_H
#define PARTGUI_DLGREVOLUTION_H
#include <Gui/Selection.h>
#include <Gui/InputVector.h>
#include <Gui/TaskView/TaskDialog.h>
#include <Gui/TaskView/TaskView.h>
@ -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_DlgRevolution> Ui_RevolutionComp;
Ui_RevolutionComp* ui;
class EdgeSelection;
EdgeSelection* filter;
};
class TaskRevolution : public Gui::TaskView::TaskDialog

View File

@ -49,7 +49,7 @@
</widget>
</item>
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="baseZ"/>
<widget class="QDoubleSpinBox" name="zPos"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_5">
@ -62,7 +62,7 @@
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="baseY"/>
<widget class="QDoubleSpinBox" name="yPos"/>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="direction"/>
@ -88,7 +88,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="baseX"/>
<widget class="QDoubleSpinBox" name="xPos"/>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="angle">
@ -105,7 +105,7 @@
</item>
</layout>
</item>
<item row="1" column="1">
<item row="2" column="1">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -118,7 +118,7 @@
</property>
</spacer>
</item>
<item row="0" column="0" rowspan="3">
<item row="0" column="0" rowspan="4">
<widget class="QTreeWidget" name="treeWidget">
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
@ -136,14 +136,21 @@
</column>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="selectLine">
<property name="text">
<string>Select line in 3D view</string>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>treeWidget</tabstop>
<tabstop>angle</tabstop>
<tabstop>baseX</tabstop>
<tabstop>baseY</tabstop>
<tabstop>baseZ</tabstop>
<tabstop>xPos</tabstop>
<tabstop>yPos</tabstop>
<tabstop>zPos</tabstop>
<tabstop>direction</tabstop>
</tabstops>
<resources/>