From 65bd9da6d2175cebc6dbeb57c2987261e5a55dc3 Mon Sep 17 00:00:00 2001 From: balazs-bamer Date: Tue, 13 Jan 2015 14:49:55 +0100 Subject: [PATCH] fill type radio buttons - incomplete I tried to implement a dialog with fill type radio buttons, but no success yet. --- src/Mod/Surface/App/CMakeLists.txt | 1 + src/Mod/Surface/App/FeatureBSurf.h | 6 +- src/Mod/Surface/FillType.h | 9 ++ src/Mod/Surface/Gui/BSurf.cpp | 187 +++++++++++++++++++++++++++++ src/Mod/Surface/Gui/BSurf.h | 97 +++++++++++++++ src/Mod/Surface/Gui/BSurf.ui | 64 ++++++++++ src/Mod/Surface/Gui/CMakeLists.txt | 19 ++- src/Mod/Surface/Gui/Command.cpp | 3 + 8 files changed, 380 insertions(+), 6 deletions(-) create mode 100644 src/Mod/Surface/FillType.h create mode 100644 src/Mod/Surface/Gui/BSurf.cpp create mode 100644 src/Mod/Surface/Gui/BSurf.h create mode 100644 src/Mod/Surface/Gui/BSurf.ui diff --git a/src/Mod/Surface/App/CMakeLists.txt b/src/Mod/Surface/App/CMakeLists.txt index 8e6f0d43f0..3595c5e661 100644 --- a/src/Mod/Surface/App/CMakeLists.txt +++ b/src/Mod/Surface/App/CMakeLists.txt @@ -19,6 +19,7 @@ set(Surface_LIBS ) SET(Surface_SRCS + ../FillType.h AppSurface.cpp AppSurfacePy.cpp PreCompiled.cpp diff --git a/src/Mod/Surface/App/FeatureBSurf.h b/src/Mod/Surface/App/FeatureBSurf.h index 21d88e60ee..6b2cec7300 100644 --- a/src/Mod/Surface/App/FeatureBSurf.h +++ b/src/Mod/Surface/App/FeatureBSurf.h @@ -30,14 +30,12 @@ #include #include #include "Mod/Part/App/PartFeature.h" +#include "../FillType.h" namespace Surface { -enum filltype_t -{ -StretchStyle = 1, CoonsStyle, CurvedStyle -}; + class BSurf : public Part::Feature { diff --git a/src/Mod/Surface/FillType.h b/src/Mod/Surface/FillType.h new file mode 100644 index 0000000000..5c5ea40ab2 --- /dev/null +++ b/src/Mod/Surface/FillType.h @@ -0,0 +1,9 @@ +#ifndef SURFACE_FILLTYPE_H +#define SURFACE_FILLTYPE_H + +enum filltype_t +{ + StretchStyle = 1, CoonsStyle, CurvedStyle +}; + +#endif // SURAFCE_FILLTYPE_H diff --git a/src/Mod/Surface/Gui/BSurf.cpp b/src/Mod/Surface/Gui/BSurf.cpp new file mode 100644 index 0000000000..ab81001934 --- /dev/null +++ b/src/Mod/Surface/Gui/BSurf.cpp @@ -0,0 +1,187 @@ +/*************************************************************************** + * Copyright (c) 2015 Balázs Bámer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +#endif + +#include "BSurf.h" +#include +#include +#include +#include + +using namespace SurfaceGui; +//#undef CS_FUTURE // multi-threading causes some problems + +namespace SurfaceGui { + +class ViewProviderBSurf : public Gui::ViewProvider +{ +public: + ViewProviderBSurf() + { + /* coords = new SoCoordinate3(); + coords->ref(); + planes = new SoLineSet(); + planes->ref(); + SoBaseColor* color = new SoBaseColor(); + color->rgb.setValue(1.0f, 0.447059f, 0.337255f); + SoDrawStyle* style = new SoDrawStyle(); + style->lineWidth.setValue(2.0f); + this->pcRoot->addChild(color); + this->pcRoot->addChild(style); + this->pcRoot->addChild(coords); + this->pcRoot->addChild(planes);*/ + } + + ~ViewProviderBSurf() + { + } + + void updateData(const App::Property*) + { + } + + const char* getDefaultDisplayMode() const + { + return ""; + } + + std::vector getDisplayModes(void) const + { + return std::vector(); + } + +/* void setCoords(const std::vector& v) + { + }*/ + +private: +}; + +BSurf::BSurf(const Base::BoundBox3d& bb, QWidget* parent, Qt::WFlags fl) + : QDialog(parent, fl), bbox(bb) +{ + ui = new Ui_DlgBSurf(); + ui->setupUi(this); + vp = new ViewProviderBSurf(); +} + +/* + * Destroys the object and frees any allocated resources + */ +BSurf::~BSurf() +{ + // no need to delete child widgets, Qt does it all for us + delete ui; + delete vp; +} + +filltype_t BSurf::getFillType() const +{ + if (ui->fillType_stretch->isChecked()) + return StretchStyle; + else if (ui->fillType_coons->isChecked()) + return CoonsStyle; + else + return CurvedStyle; +} + +void BSurf::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::LanguageChange) { + ui->retranslateUi(this); + } + else { + QDialog::changeEvent(e); + } +} + +void BSurf::accept() +{ + apply(); + QDialog::accept(); +} + +void BSurf::apply() +{ + printf("apply\n"); + // std::vector obj = Gui::Selection(). + // getObjectsOfType(Part::Feature::getClassTypeId()); +//////////////// +} + +void BSurf::on_fillType_stretch_clicked() +{ +} + +void BSurf::on_fillType_coons_clicked() +{ +} + +void BSurf::on_fillType_curved_clicked() +{ +} + +// --------------------------------------- + +TaskBSurf::TaskBSurf(const Base::BoundBox3d& bb) +{ + widget = new BSurf(bb); + taskbox = new Gui::TaskView::TaskBox( + NULL, + widget->windowTitle(), true, 0); + taskbox->groupLayout()->addWidget(widget); + Content.push_back(taskbox); +} + +TaskBSurf::~TaskBSurf() +{ + // automatically deleted in the sub-class +} + +bool TaskBSurf::accept() +{ + widget->accept(); + return (widget->result() == QDialog::Accepted); +} + +void TaskBSurf::clicked(int id) +{ + if (id == QDialogButtonBox::Apply) { + widget->apply(); + } +} + +} +#include "moc_BSurf.cpp" diff --git a/src/Mod/Surface/Gui/BSurf.h b/src/Mod/Surface/Gui/BSurf.h new file mode 100644 index 0000000000..8f507182ef --- /dev/null +++ b/src/Mod/Surface/Gui/BSurf.h @@ -0,0 +1,97 @@ +/*************************************************************************** + * Copyright (c) 2015 Balázs Bámer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +// Part::CrossSections.* + +#ifndef SURFACE_GUI_BSURF_H +#define SURFACE_GUI_BSURF_H + +#include +#include +#include +#include +#include +#include "../FillType.h" +#include "ui_BSurf.h" + +namespace SurfaceGui +{ + class ViewProviderBSurf; + + class BSurf : public QDialog + { + Q_OBJECT + protected: + filltype_t fillType; + + public: + BSurf(const Base::BoundBox3d& bb, QWidget* parent = 0, Qt::WFlags fl = 0); + ~BSurf(); + void accept(); + void apply(); + + protected: + void changeEvent(QEvent *e); + + private Q_SLOTS: + void on_fillType_stretch_clicked(); + void on_fillType_coons_clicked(); + void on_fillType_curved_clicked(); + filltype_t getFillType() const; + +/* private: + std::vector getPlanes() const; + void calcPlane(Plane, double); + void calcPlanes(Plane); + void makePlanes(Plane, const std::vector&, double[4]); + Plane plane() const;*/ + + private: + Ui_DlgBSurf* ui; + Base::BoundBox3d bbox; + ViewProviderBSurf* vp; +// QPointer view; + }; + + class TaskBSurf : public Gui::TaskView::TaskDialog + { + Q_OBJECT + + public: + TaskBSurf(const Base::BoundBox3d& bb); + ~TaskBSurf(); + + public: + bool accept(); + void clicked(int id); + + virtual QDialogButtonBox::StandardButtons getStandardButtons() const + { return QDialogButtonBox::Ok | QDialogButtonBox::Apply | QDialogButtonBox::Cancel; } + + private: + BSurf* widget; + Gui::TaskView::TaskBox* taskbox; + }; + +} //namespace Surface + +#endif // SURFACE_GUI_BSURF_H diff --git a/src/Mod/Surface/Gui/BSurf.ui b/src/Mod/Surface/Gui/BSurf.ui new file mode 100644 index 0000000000..9d784942e7 --- /dev/null +++ b/src/Mod/Surface/Gui/BSurf.ui @@ -0,0 +1,64 @@ + + + SurfaceGui::DlgBSurf + + + + 0 + 0 + 277 + 144 + + + + + 0 + 0 + + + + Placement + + + + + + Fill type: + + + + 9 + + + 6 + + + + + Coons + + + + + + + Stretch + + + + + + + Curved + + + + + + + + + + + + diff --git a/src/Mod/Surface/Gui/CMakeLists.txt b/src/Mod/Surface/Gui/CMakeLists.txt index 036e2aa24f..d97fe8dc55 100644 --- a/src/Mod/Surface/Gui/CMakeLists.txt +++ b/src/Mod/Surface/Gui/CMakeLists.txt @@ -24,10 +24,25 @@ set(SurfaceGui_LIBS FreeCADGui ) -qt4_add_resources(Surface_QRC_SRCS Resources/Surface.qrc) +set(SurfaceGui_MOC_HDRS + BSurf.h +) +fc_wrap_cpp(SurfaceGui_MOC_SRCS ${SurfaceGui_MOC_HDRS}) +SOURCE_GROUP("Moc" FILES ${SurfaceGui_MOC_SRCS}) + +qt4_add_resources(SurfaceGui_QRC_SRCS Resources/Surface.qrc) + +SET(SurfaceGui_UIC_SRCS + BSurf.ui +) +qt4_wrap_ui(SurfaceGui_UIC_HDRS ${SurfaceGui_UIC_SRCS}) SET(SurfaceGui_SRCS - ${Surface_QRC_SRCS} + ${SurfaceGui_QRC_SRCS} + ${SurfaceGui_UIC_HDRS} + BSurf.cpp + BSurf.h + ../FillType.h AppSurfaceGui.cpp AppSurfaceGuiPy.cpp Command.cpp diff --git a/src/Mod/Surface/Gui/Command.cpp b/src/Mod/Surface/Gui/Command.cpp index 8272c9aec2..7303d4632f 100644 --- a/src/Mod/Surface/Gui/Command.cpp +++ b/src/Mod/Surface/Gui/Command.cpp @@ -240,6 +240,8 @@ CmdSurfaceBSpline::CmdSurfaceBSpline() void CmdSurfaceBSpline::activated(int iMsg) { +/* Gui::Dialog::TaskPlacement* plm = new Gui::Dialog::TaskPlacement(); + Gui::Control().showDialog(plm);*/ /*if (!isActive()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select 2, 3 or 4 curves, please.")); @@ -259,6 +261,7 @@ void CmdSurfaceBSpline::activated(int iMsg) openCommand("Create BSpline surface"); doCommand(Doc,"FreeCAD.ActiveDocument.addObject(\"Surface::BSplineSurf\",\"%s\")", FeatName.c_str()); doCommand(Doc, "FreeCAD.ActiveDocument.ActiveObject.filltype=1"); // TODO ask filltype from user and check it + doCommand(Doc, "Gui.ActiveDocument.setEdit('%s',0)", FeatName.c_str()); runCommand(Doc, bspListCmd.str().c_str()); updateActive(); commitCommand();