From aaf5f08d8ebab2183321cbb52673b3b6882af6e4 Mon Sep 17 00:00:00 2001 From: jriegel Date: Mon, 24 Oct 2011 20:10:59 +0000 Subject: [PATCH] + Gui for Pocket and Revolution git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5059 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d --- src/Mod/PartDesign/App/FeaturePad.cpp | 11 +- src/Mod/PartDesign/App/FeaturePocket.cpp | 14 ++- src/Mod/PartDesign/App/FeatureRevolution.cpp | 22 +++- src/Mod/PartDesign/Gui/Command.cpp | 14 +-- .../PartDesign/Gui/TaskPocketParameters.cpp | 97 +++++++++++---- src/Mod/PartDesign/Gui/TaskPocketParameters.h | 17 +-- .../PartDesign/Gui/TaskPocketParameters.ui | 14 +-- .../Gui/TaskRevolutionParameters.cpp | 115 ++++++++++++++---- .../PartDesign/Gui/TaskRevolutionParameters.h | 17 +-- .../Gui/TaskRevolutionParameters.ui | 46 ++++++- src/Mod/PartDesign/Gui/ViewProviderPocket.cpp | 88 +++++++++++++- src/Mod/PartDesign/Gui/ViewProviderPocket.h | 8 ++ .../PartDesign/Gui/ViewProviderRevolution.cpp | 87 ++++++++++++- .../PartDesign/Gui/ViewProviderRevolution.h | 9 ++ 14 files changed, 449 insertions(+), 110 deletions(-) diff --git a/src/Mod/PartDesign/App/FeaturePad.cpp b/src/Mod/PartDesign/App/FeaturePad.cpp index 52f8965aa..64d3215bc 100644 --- a/src/Mod/PartDesign/App/FeaturePad.cpp +++ b/src/Mod/PartDesign/App/FeaturePad.cpp @@ -115,14 +115,10 @@ App::DocumentObjectExecReturn *Pad::execute(void) SupportObject = static_cast(SupportLink); -#if 0 - //TopoDS_Wire theWire = TopoDS::Wire(shape); - //TopoDS_Face aFace = BRepBuilderAPI_MakeFace(theWire); -#else TopoDS_Shape aFace = makeFace(wires); if (aFace.IsNull()) return new App::DocumentObjectExecReturn("Creating a face from sketch failed"); -#endif + // lengthen the vector SketchOrientationVector *= Length.getValue(); @@ -159,14 +155,11 @@ App::DocumentObjectExecReturn *Pad::execute(void) // get the first TopoDS_Solid solRes = TopoDS::Solid(anExplorer.Current()); - //TopoDS_Solid solRes = TopoDS::Solid(result); // lets check if the result is a solid - //if (result.ShapeType() != TopAbs_SOLID) - // return new App::DocumentObjectExecReturn("Resulting shape is not a solid"); if (solRes.IsNull()) return new App::DocumentObjectExecReturn("Resulting shape is not a solid"); this->Shape.setValue(solRes); - //this->Shape.setValue(result); + } else return new App::DocumentObjectExecReturn("Support is not a solid"); diff --git a/src/Mod/PartDesign/App/FeaturePocket.cpp b/src/Mod/PartDesign/App/FeaturePocket.cpp index 61526306d..b48e01704 100644 --- a/src/Mod/PartDesign/App/FeaturePocket.cpp +++ b/src/Mod/PartDesign/App/FeaturePocket.cpp @@ -37,6 +37,7 @@ # include # include # include +# include # include # include #endif @@ -138,7 +139,18 @@ App::DocumentObjectExecReturn *Pocket::execute(void) // Let's check if the fusion has been successful if (!mkCut.IsDone()) return new App::DocumentObjectExecReturn("Cut with support failed"); - this->Shape.setValue(mkCut.Shape()); + + // we have to get the solids (fuse create seldomly compounds) + TopExp_Explorer anExplorer; + anExplorer.Init(mkCut.Shape(),TopAbs_SOLID); + + TopoDS_Solid solRes = TopoDS::Solid(anExplorer.Current()); + + if (solRes.IsNull()) + return new App::DocumentObjectExecReturn("Resulting shape is not a solid"); + this->Shape.setValue(solRes); + + //this->Shape.setValue(mkCut.Shape()); } else{ return new App::DocumentObjectExecReturn("Cannot create a tool out of sketch with no support"); diff --git a/src/Mod/PartDesign/App/FeatureRevolution.cpp b/src/Mod/PartDesign/App/FeatureRevolution.cpp index 20f9a6980..6365b1c76 100644 --- a/src/Mod/PartDesign/App/FeatureRevolution.cpp +++ b/src/Mod/PartDesign/App/FeatureRevolution.cpp @@ -93,11 +93,27 @@ App::DocumentObjectExecReturn *Revolution::execute(void) } if (wires.empty()) // there can be several wires return new App::DocumentObjectExecReturn("Linked shape object is not a wire"); - - Base::Vector3f b = Base.getValue(); +#if 0 + App::DocumentObject* support = sketch->Support.getValue(); + Base::Placement placement = sketch->Placement.getValue(); + Base::Vector3d axis(0,1,0); + placement.getRotation().multVec(axis, axis); + Base::BoundBox3d bbox = sketch->Shape.getBoundingBox(); + bbox.Enlarge(0.1); + Base::Vector3d base(bbox.MaxX, bbox.MaxY, bbox.MaxZ); +#endif + // get the Sketch plane + Base::Placement SketchPos = static_cast(link)->Placement.getValue(); + Base::Rotation SketchOrientation = SketchPos.getRotation(); + // get rvolve axis Base::Vector3f v = Axis.getValue(); + Base::Vector3d SketchOrientationVector(v.x,v.y,v.z); + SketchOrientation.multVec(SketchOrientationVector,SketchOrientationVector); + + + Base::Vector3f b(0,0,0); gp_Pnt pnt(b.x,b.y,b.z); - gp_Dir dir(v.x,v.y,v.z); + gp_Dir dir(SketchOrientationVector.x,SketchOrientationVector.y,SketchOrientationVector.z); // get the support of the Sketch if any App::DocumentObject* SupportLink = static_cast(link)->Support.getValue(); diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index b59382205..3452aa51e 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -227,7 +227,7 @@ void CmdPartDesignPocket::activated(int iMsg) doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",sketch->getNameInDocument()); doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",support->getNameInDocument()); } - commitCommand(); + doCommand(Gui,"Gui.activeDocument().setEdit('%s',2)",FeatName.c_str()); copyVisual(FeatName.c_str(), "ShapeColor", support->getNameInDocument()); copyVisual(FeatName.c_str(), "LineColor", support->getNameInDocument()); @@ -289,18 +289,11 @@ void CmdPartDesignRevolution::activated(int iMsg) } App::DocumentObject* support = sketch->Support.getValue(); - Base::Placement placement = sketch->Placement.getValue(); - Base::Vector3d axis(0,1,0); - placement.getRotation().multVec(axis, axis); - Base::BoundBox3d bbox = sketch->Shape.getBoundingBox(); - bbox.Enlarge(0.1); - Base::Vector3d base(bbox.MaxX, bbox.MaxY, bbox.MaxZ); openCommand("Make Revolution"); doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Revolution\",\"%s\")",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Sketch = App.activeDocument().%s",FeatName.c_str(),sketch->getNameInDocument()); - doCommand(Doc,"App.activeDocument().%s.Base = App.Vector(%f,%f,%f)",FeatName.c_str(), base.x, base.y, base.z); - doCommand(Doc,"App.activeDocument().%s.Axis = App.Vector(%f,%f,%f)",FeatName.c_str(), axis.x, axis.y, axis.z); + doCommand(Doc,"App.activeDocument().%s.Axis = App.Vector(0,1,0)",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Angle = 360.0",FeatName.c_str()); updateActive(); if (isActiveObjectValid()) { @@ -308,8 +301,7 @@ void CmdPartDesignRevolution::activated(int iMsg) if (support) doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",support->getNameInDocument()); } - commitCommand(); - adjustCameraPosition(); + doCommand(Gui,"Gui.activeDocument().setEdit('%s',2)",FeatName.c_str()); if (support) { copyVisual(FeatName.c_str(), "ShapeColor", support->getNameInDocument()); diff --git a/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp b/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp index 4b62240d2..1cc071113 100644 --- a/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp @@ -28,6 +28,8 @@ #include "ui_TaskPocketParameters.h" #include "TaskPocketParameters.h" +#include +#include #include #include #include @@ -36,6 +38,8 @@ #include #include #include +#include +#include using namespace PartDesignGui; @@ -43,8 +47,8 @@ using namespace Gui; /* TRANSLATOR PartDesignGui::TaskPocketParameters */ -TaskPocketParameters::TaskPocketParameters(QWidget *parent) - : TaskBox(Gui::BitmapFactory().pixmap("document-new"),tr("TaskPocketParameters"),true, parent) +TaskPocketParameters::TaskPocketParameters(ViewProviderPocket *PocketView,QWidget *parent) + : TaskBox(Gui::BitmapFactory().pixmap("PartDesign_Pocket"),tr("Pocket parameters"),true, parent),PocketView(PocketView) { // we need a separate container widget to add all controls to proxy = new QWidget(this); @@ -52,15 +56,47 @@ TaskPocketParameters::TaskPocketParameters(QWidget *parent) ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); + connect(ui->doubleSpinBox, SIGNAL(valueChanged(double)), + this, SLOT(onLengthChanged(double))); + this->groupLayout()->addWidget(proxy); - Gui::Selection().Attach(this); + PartDesign::Pocket* pcPocket = static_cast(PocketView->getObject()); + double l = pcPocket->Length.getValue(); + + ui->doubleSpinBox->setValue(l); + ui->doubleSpinBox->selectAll(); + + //// check if the sketch has support + //Sketcher::SketchObject *pcSketch; + //if (pcPocket->Sketch.getValue()) { + // pcSketch = static_cast(pcPocket->Sketch.getValue()); + // if (pcSketch->Support.getValue()) + // // in case of sketch with support, reverse makes no sense (goes into the part) + // ui->checkBoxReversed->setEnabled(0); + // else + // ui->checkBoxReversed->setChecked(reversed); + //} + + setFocus (); } +void TaskPocketParameters::onLengthChanged(double len) +{ + PartDesign::Pocket* pcPocket = static_cast(PocketView->getObject()); + pcPocket->Length.setValue((float)len); + pcPocket->getDocument()->recomputeFeature(pcPocket); +} + +double TaskPocketParameters::getLength(void) const +{ + return ui->doubleSpinBox->value(); +} + + TaskPocketParameters::~TaskPocketParameters() { delete ui; - Gui::Selection().Detach(this); } void TaskPocketParameters::changeEvent(QEvent *e) @@ -71,18 +107,6 @@ void TaskPocketParameters::changeEvent(QEvent *e) } } -/// @cond DOXERR -void TaskPocketParameters::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 +116,7 @@ TaskDlgPocketParameters::TaskDlgPocketParameters(ViewProviderPocket *PocketView) : TaskDialog(),PocketView(PocketView) { assert(PocketView); - parameter = new TaskPocketParameters(); + parameter = new TaskPocketParameters(PocketView); Content.push_back(parameter); } @@ -107,7 +131,7 @@ TaskDlgPocketParameters::~TaskDlgPocketParameters() void TaskDlgPocketParameters::open() { - + } void TaskDlgPocketParameters::clicked(int) @@ -117,25 +141,46 @@ void TaskDlgPocketParameters::clicked(int) bool TaskDlgPocketParameters::accept() { - return true; -} + std::string name = PocketView->getObject()->getNameInDocument(); -bool TaskDlgPocketParameters::reject() -{ - Gui::Command::openCommand("Pocket changed"); - Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); + //Gui::Command::openCommand("Pocket changed"); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Length = %f",name.c_str(),parameter->getLength()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()"); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); Gui::Command::commitCommand(); return true; } -void TaskDlgPocketParameters::helpRequested() +bool TaskDlgPocketParameters::reject() { + // get the support and Sketch + PartDesign::Pocket* pcPocket = static_cast(PocketView->getObject()); + Sketcher::SketchObject *pcSketch; + App::DocumentObject *pcSupport; + if (pcPocket->Sketch.getValue()) { + pcSketch = static_cast(pcPocket->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(pcPocket)) { + 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_TaskPocketParameters.cpp" diff --git a/src/Mod/PartDesign/Gui/TaskPocketParameters.h b/src/Mod/PartDesign/Gui/TaskPocketParameters.h index 92202d460..077a9ef0c 100644 --- a/src/Mod/PartDesign/Gui/TaskPocketParameters.h +++ b/src/Mod/PartDesign/Gui/TaskPocketParameters.h @@ -19,7 +19,7 @@ * Suite 330, Boston, MA 02111-1307, USA * * * ***************************************************************************/ - + #ifndef GUI_TASKVIEW_TaskPocketParameters_H #define GUI_TASKVIEW_TaskPocketParameters_H @@ -44,18 +44,18 @@ namespace PartDesignGui { -class TaskPocketParameters : public Gui::TaskView::TaskBox, public Gui::SelectionSingleton::ObserverType +class TaskPocketParameters : public Gui::TaskView::TaskBox { Q_OBJECT public: - TaskPocketParameters(QWidget *parent = 0); + TaskPocketParameters(ViewProviderPocket *PocketView,QWidget *parent = 0); ~TaskPocketParameters(); - /// Observer message from the Selection - void OnChange(Gui::SelectionSingleton::SubjectType &rCaller, - Gui::SelectionSingleton::MessageType Reason); + + double getLength(void) const; private Q_SLOTS: + void onLengthChanged(double); protected: void changeEvent(QEvent *e); @@ -65,6 +65,7 @@ private: private: QWidget* proxy; Ui_TaskPocketParameters* ui; + ViewProviderPocket *PocketView; }; /// simulation dialog for the TaskView @@ -79,6 +80,7 @@ public: ViewProviderPocket* getPocketView() const { return PocketView; } + public: /// is called the TaskView when the dialog is opened virtual void open(); @@ -89,13 +91,12 @@ public: /// is called by the framework if the dialog is rejected (Cancel) virtual bool reject(); /// is called by the framework if the user presses the help button - virtual void helpRequested(); virtual bool isAllowedAlterDocument(void) const { return false; } /// returns for Close and Help button virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const - { return QDialogButtonBox::Close|QDialogButtonBox::Help; } + { return QDialogButtonBox::Ok|QDialogButtonBox::Cancel; } protected: ViewProviderPocket *PocketView; diff --git a/src/Mod/PartDesign/Gui/TaskPocketParameters.ui b/src/Mod/PartDesign/Gui/TaskPocketParameters.ui index 2c83620b8..34c8979a1 100644 --- a/src/Mod/PartDesign/Gui/TaskPocketParameters.ui +++ b/src/Mod/PartDesign/Gui/TaskPocketParameters.ui @@ -7,7 +7,7 @@ 0 0 137 - 116 + 68 @@ -30,16 +30,6 @@ Dimension - - - Up to last - - - - - Up to first - - @@ -49,7 +39,7 @@ - Size: + Length diff --git a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp index df5333af0..add807f7a 100644 --- a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp @@ -28,6 +28,8 @@ #include "ui_TaskRevolutionParameters.h" #include "TaskRevolutionParameters.h" +#include +#include #include #include #include @@ -36,6 +38,8 @@ #include #include #include +#include +#include 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(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(RevolutionView->getObject()); + pcRevolution->Angle.setValue((float)len); + pcRevolution->getDocument()->recomputeFeature(pcRevolution); +} + +void TaskRevolutionParameters::onAxisChanged(int num) +{ + PartDesign::Revolution* pcRevolution = static_cast(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(RevolutionView->getObject()); + Sketcher::SketchObject *pcSketch; + App::DocumentObject *pcSupport; + if (pcRevolution->Sketch.getValue()) { + pcSketch = static_cast(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" diff --git a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.h b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.h index 9d76b6953..3cbd595bd 100644 --- a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.h +++ b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.h @@ -44,18 +44,20 @@ namespace PartDesignGui { -class TaskRevolutionParameters : public Gui::TaskView::TaskBox, public Gui::SelectionSingleton::ObserverType +class TaskRevolutionParameters : public Gui::TaskView::TaskBox { Q_OBJECT public: - TaskRevolutionParameters(QWidget *parent = 0); + TaskRevolutionParameters(ViewProviderRevolution *RevolutionView,QWidget *parent = 0); ~TaskRevolutionParameters(); - /// Observer message from the Selection - void OnChange(Gui::SelectionSingleton::SubjectType &rCaller, - Gui::SelectionSingleton::MessageType Reason); + + Base::Vector3f getAxis (void) const; + double getAngle(void) const; private Q_SLOTS: + void onAngleChanged(double); + void onAxisChanged(int); protected: void changeEvent(QEvent *e); @@ -65,6 +67,7 @@ private: private: QWidget* proxy; Ui_TaskRevolutionParameters* ui; + ViewProviderRevolution *RevolutionView; }; /// simulation dialog for the TaskView @@ -79,6 +82,7 @@ public: ViewProviderRevolution* getRevolutionView() const { return RevolutionView; } + public: /// is called the TaskView when the dialog is opened virtual void open(); @@ -89,13 +93,12 @@ public: /// is called by the framework if the dialog is rejected (Cancel) virtual bool reject(); /// is called by the framework if the user presses the help button - virtual void helpRequested(); virtual bool isAllowedAlterDocument(void) const { return false; } /// returns for Close and Help button virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const - { return QDialogButtonBox::Close|QDialogButtonBox::Help; } + { return QDialogButtonBox::Ok|QDialogButtonBox::Cancel; } protected: ViewProviderRevolution *RevolutionView; diff --git a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.ui b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.ui index ee261f3ac..aed4c1e66 100644 --- a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.ui +++ b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.ui @@ -6,8 +6,8 @@ 0 0 - 136 - 58 + 182 + 68 @@ -15,7 +15,32 @@ - + + + + + Axis: + + + + + + + + Vertical + + + + + Horizontal + + + + + + + + @@ -24,7 +49,20 @@ - + + + 1 + + + 360.000000000000000 + + + 10.000000000000000 + + + 360.000000000000000 + + diff --git a/src/Mod/PartDesign/Gui/ViewProviderPocket.cpp b/src/Mod/PartDesign/Gui/ViewProviderPocket.cpp index 8786cfae1..62aa0442e 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderPocket.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderPocket.cpp @@ -27,7 +27,13 @@ #endif #include "ViewProviderPocket.h" -#include +#include "TaskPocketParameters.h" +#include +#include +#include +#include +#include + using namespace PartDesignGui; @@ -44,9 +50,87 @@ ViewProviderPocket::~ViewProviderPocket() std::vector ViewProviderPocket::claimChildren(void)const { std::vector temp; - temp.push_back(static_cast(getObject())->Sketch.getValue()); + temp.push_back(static_cast(getObject())->Sketch.getValue()); return temp; } +void ViewProviderPocket::setupContextMenu(QMenu* menu, QObject* receiver, const char* member) +{ + QAction* act; + act = menu->addAction(QObject::tr("Edit pocket"), receiver, member); + act->setData(QVariant((int)ViewProvider::Default)); + act = menu->addAction(QObject::tr("Transform"), receiver, member); + act->setData(QVariant((int)ViewProvider::Transform)); +} + +bool ViewProviderPocket::setEdit(int ModNum) +{ + // When double-clicking on the item for this pad the + // object unsets and sets its edit mode without closing + // the task panel + Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); + TaskDlgPocketParameters *padDlg = qobject_cast(dlg); + if (padDlg && padDlg->getPocketView() != this) + padDlg = 0; // another pad left open its task panel + if (dlg && !padDlg) { + QMessageBox msgBox; + msgBox.setText(QObject::tr("A dialog is already open in the task panel")); + msgBox.setInformativeText(QObject::tr("Do you want to close this dialog?")); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::Yes); + int ret = msgBox.exec(); + if (ret == QMessageBox::Yes) + Gui::Control().closeDialog(); + else + return false; + } + + // clear the selection (convenience) + Gui::Selection().clearSelection(); + if(ModNum == 1) + Gui::Command::openCommand("Change pocket parameters"); + + // start the edit dialog + if (padDlg) + Gui::Control().showDialog(padDlg); + else + Gui::Control().showDialog(new TaskDlgPocketParameters(this)); + + return true; +} + +void ViewProviderPocket::unsetEdit(int ModNum) +{ + if (ModNum == ViewProvider::Default) { + // and update the pad + //getSketchObject()->getDocument()->recompute(); + + // when pressing ESC make sure to close the dialog + Gui::Control().closeDialog(); + } + else { + PartGui::ViewProviderPart::unsetEdit(ModNum); + } +} + +bool ViewProviderPocket::onDelete(const std::vector &) +{ + // get the support and Sketch + PartDesign::Pocket* pcPocket = static_cast(getObject()); + Sketcher::SketchObject *pcSketch; + App::DocumentObject *pcSupport; + if (pcPocket->Sketch.getValue()){ + pcSketch = static_cast(pcPocket->Sketch.getValue()); + pcSupport = pcSketch->Support.getValue(); + } + + // if abort command deleted the object the support is visible again + 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(); + + return true; +} diff --git a/src/Mod/PartDesign/Gui/ViewProviderPocket.h b/src/Mod/PartDesign/Gui/ViewProviderPocket.h index 06804d81a..8e03072e4 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderPocket.h +++ b/src/Mod/PartDesign/Gui/ViewProviderPocket.h @@ -41,6 +41,14 @@ public: /// grouping handling std::vector claimChildren(void)const; + void setupContextMenu(QMenu*, QObject*, const char*); + + virtual bool onDelete(const std::vector &); + +protected: + virtual bool setEdit(int ModNum); + virtual void unsetEdit(int ModNum); + }; diff --git a/src/Mod/PartDesign/Gui/ViewProviderRevolution.cpp b/src/Mod/PartDesign/Gui/ViewProviderRevolution.cpp index d22dd1319..e2e5a5442 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderRevolution.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderRevolution.cpp @@ -26,8 +26,14 @@ #ifndef _PreComp_ #endif -#include "ViewProviderRevolution.h" #include +#include +#include +#include +#include + +#include "ViewProviderRevolution.h" +#include "TaskRevolutionParameters.h" using namespace PartDesignGui; @@ -49,4 +55,83 @@ std::vector ViewProviderRevolution::claimChildren(void)con return temp; } +void ViewProviderRevolution::setupContextMenu(QMenu* menu, QObject* receiver, const char* member) +{ + QAction* act; + act = menu->addAction(QObject::tr("Edit revolution"), receiver, member); + act->setData(QVariant((int)ViewProvider::Default)); + act = menu->addAction(QObject::tr("Transform"), receiver, member); + act->setData(QVariant((int)ViewProvider::Transform)); +} + +bool ViewProviderRevolution::setEdit(int ModNum) +{ + // When double-clicking on the item for this pad the + // object unsets and sets its edit mode without closing + // the task panel + Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); + TaskDlgRevolutionParameters *padDlg = qobject_cast(dlg); + if (padDlg && padDlg->getRevolutionView() != this) + padDlg = 0; // another pad left open its task panel + if (dlg && !padDlg) { + QMessageBox msgBox; + msgBox.setText(QObject::tr("A dialog is already open in the task panel")); + msgBox.setInformativeText(QObject::tr("Do you want to close this dialog?")); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::Yes); + int ret = msgBox.exec(); + if (ret == QMessageBox::Yes) + Gui::Control().closeDialog(); + else + return false; + } + + // clear the selection (convenience) + Gui::Selection().clearSelection(); + if(ModNum == 1) + Gui::Command::openCommand("Change revolution parameters"); + + // start the edit dialog + if (padDlg) + Gui::Control().showDialog(padDlg); + else + Gui::Control().showDialog(new TaskDlgRevolutionParameters(this)); + + return true; +} + +void ViewProviderRevolution::unsetEdit(int ModNum) +{ + if (ModNum == ViewProvider::Default) { + // and update the pad + //getSketchObject()->getDocument()->recompute(); + + // when pressing ESC make sure to close the dialog + Gui::Control().closeDialog(); + } + else { + PartGui::ViewProviderPart::unsetEdit(ModNum); + } +} + +bool ViewProviderRevolution::onDelete(const std::vector &) +{ + // get the support and Sketch + PartDesign::Revolution* pcRevolution = static_cast(getObject()); + Sketcher::SketchObject *pcSketch; + App::DocumentObject *pcSupport; + if (pcRevolution->Sketch.getValue()){ + pcSketch = static_cast(pcRevolution->Sketch.getValue()); + pcSupport = pcSketch->Support.getValue(); + } + + // if abort command deleted the object the support is visible again + 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(); + + return true; +} + diff --git a/src/Mod/PartDesign/Gui/ViewProviderRevolution.h b/src/Mod/PartDesign/Gui/ViewProviderRevolution.h index 42bf70856..faad403d5 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderRevolution.h +++ b/src/Mod/PartDesign/Gui/ViewProviderRevolution.h @@ -41,6 +41,15 @@ public: /// grouping handling std::vector claimChildren(void)const; + + void setupContextMenu(QMenu*, QObject*, const char*); + + virtual bool onDelete(const std::vector &); + +protected: + virtual bool setEdit(int ModNum); + virtual void unsetEdit(int ModNum); + };