+ Gui for Pocket and Revolution

git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5059 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
jriegel
2011-10-24 20:10:59 +00:00
parent 45e5b4135d
commit aaf5f08d8e
14 changed files with 449 additions and 110 deletions

View File

@@ -28,6 +28,8 @@
#include "ui_TaskRevolutionParameters.h"
#include "TaskRevolutionParameters.h"
#include <App/Application.h>
#include <App/Document.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/BitmapFactory.h>
@@ -36,6 +38,8 @@
#include <Base/Console.h>
#include <Gui/Selection.h>
#include <Gui/Command.h>
#include <Mod/PartDesign/App/FeatureRevolution.h>
#include <Mod/Sketcher/App/SketchObject.h>
using namespace PartDesignGui;
@@ -43,8 +47,8 @@ using namespace Gui;
/* TRANSLATOR PartDesignGui::TaskRevolutionParameters */
TaskRevolutionParameters::TaskRevolutionParameters(QWidget *parent)
: TaskBox(Gui::BitmapFactory().pixmap("document-new"),tr("TaskRevolutionParameters"),true, parent)
TaskRevolutionParameters::TaskRevolutionParameters(ViewProviderRevolution *RevolutionView,QWidget *parent)
: TaskBox(Gui::BitmapFactory().pixmap("PartDesign_Revolution"),tr("Revolution parameters"),true, parent),RevolutionView(RevolutionView)
{
// we need a separate container widget to add all controls to
proxy = new QWidget(this);
@@ -52,15 +56,63 @@ TaskRevolutionParameters::TaskRevolutionParameters(QWidget *parent)
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);
connect(ui->doubleSpinBox, SIGNAL(valueChanged(double)),
this, SLOT(onAngleChanged(double)));
connect(ui->axis, SIGNAL(activated(int)),
this, SLOT(onAxisChanged(int)));
this->groupLayout()->addWidget(proxy);
Gui::Selection().Attach(this);
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(RevolutionView->getObject());
double l = pcRevolution->Angle.getValue();
Base::Vector3f Ax = pcRevolution->Axis.getValue();
ui->doubleSpinBox->setValue(l);
if(Ax.y > 0)
ui->axis->setCurrentIndex(0);
else
ui->axis->setCurrentIndex(1);
setFocus ();
}
void TaskRevolutionParameters::onAngleChanged(double len)
{
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(RevolutionView->getObject());
pcRevolution->Angle.setValue((float)len);
pcRevolution->getDocument()->recomputeFeature(pcRevolution);
}
void TaskRevolutionParameters::onAxisChanged(int num)
{
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(RevolutionView->getObject());
if(num == 0)
pcRevolution->Axis.setValue(Base::Vector3f(0,1,0));
else
pcRevolution->Axis.setValue(Base::Vector3f(1,0,0));
pcRevolution->getDocument()->recomputeFeature(pcRevolution);
}
double TaskRevolutionParameters::getAngle(void) const
{
return ui->doubleSpinBox->value();
}
Base::Vector3f TaskRevolutionParameters::getAxis(void) const
{
if( ui->axis->currentIndex() == 0)
return Base::Vector3f(0,1,0);
else
return Base::Vector3f(1,0,0);
}
TaskRevolutionParameters::~TaskRevolutionParameters()
{
delete ui;
Gui::Selection().Detach(this);
}
void TaskRevolutionParameters::changeEvent(QEvent *e)
@@ -71,18 +123,6 @@ void TaskRevolutionParameters::changeEvent(QEvent *e)
}
}
/// @cond DOXERR
void TaskRevolutionParameters::OnChange(Gui::SelectionSingleton::SubjectType &rCaller,
Gui::SelectionSingleton::MessageType Reason)
{
if (Reason.Type == SelectionChanges::AddSelection ||
Reason.Type == SelectionChanges::RmvSelection ||
Reason.Type == SelectionChanges::SetSelection ||
Reason.Type == SelectionChanges::ClrSelection) {
}
}
/// @endcond
//**************************************************************************
//**************************************************************************
// TaskDialog
@@ -92,7 +132,7 @@ TaskDlgRevolutionParameters::TaskDlgRevolutionParameters(ViewProviderRevolution
: TaskDialog(),RevolutionView(RevolutionView)
{
assert(RevolutionView);
parameter = new TaskRevolutionParameters();
parameter = new TaskRevolutionParameters(RevolutionView);
Content.push_back(parameter);
}
@@ -107,7 +147,7 @@ TaskDlgRevolutionParameters::~TaskDlgRevolutionParameters()
void TaskDlgRevolutionParameters::open()
{
}
void TaskDlgRevolutionParameters::clicked(int)
@@ -117,25 +157,48 @@ void TaskDlgRevolutionParameters::clicked(int)
bool TaskDlgRevolutionParameters::accept()
{
return true;
}
std::string name = RevolutionView->getObject()->getNameInDocument();
bool TaskDlgRevolutionParameters::reject()
{
Gui::Command::openCommand("Revolution changed");
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
//Gui::Command::openCommand("Revolution changed");
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Angle = %f",name.c_str(),parameter->getAngle());
Base::Vector3f axis = parameter->getAxis();
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Axis = FreeCAD.Vector(%f,%f,%f)",name.c_str(),axis.x,axis.y,axis.z);
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
return true;
}
void TaskDlgRevolutionParameters::helpRequested()
bool TaskDlgRevolutionParameters::reject()
{
// get the support and Sketch
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(RevolutionView->getObject());
Sketcher::SketchObject *pcSketch;
App::DocumentObject *pcSupport;
if (pcRevolution->Sketch.getValue()) {
pcSketch = static_cast<Sketcher::SketchObject*>(pcRevolution->Sketch.getValue());
pcSupport = pcSketch->Support.getValue();
}
// role back the done things
Gui::Command::abortCommand();
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
// if abort command deleted the object the support is visible again
if (!Gui::Application::Instance->getViewProvider(pcRevolution)) {
if (pcSketch && Gui::Application::Instance->getViewProvider(pcSketch))
Gui::Application::Instance->getViewProvider(pcSketch)->show();
if (pcSupport && Gui::Application::Instance->getViewProvider(pcSupport))
Gui::Application::Instance->getViewProvider(pcSupport)->show();
}
//Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
//Gui::Command::commitCommand();
return true;
}
#include "moc_TaskRevolutionParameters.cpp"