From 9726ad3f4a1eef7645d90dd9289ee265c4c439e9 Mon Sep 17 00:00:00 2001 From: donovaly Date: Fri, 12 Jun 2020 03:04:28 +0200 Subject: [PATCH] [TD] add dialog for hatches as discussed in the forum, the hatch feature misses a dialog. So here it is. The code is more or less just the one of the existing GeomHatch dialog --- src/Mod/TechDraw/App/DrawHatch.cpp | 10 +- src/Mod/TechDraw/Gui/CMakeLists.txt | 10 +- src/Mod/TechDraw/Gui/CommandDecorate.cpp | 15 +- src/Mod/TechDraw/Gui/TaskHatch.cpp | 218 +++++++++++++++++++++ src/Mod/TechDraw/Gui/TaskHatch.h | 127 ++++++++++++ src/Mod/TechDraw/Gui/TaskHatch.ui | 163 +++++++++++++++ src/Mod/TechDraw/Gui/ViewProviderHatch.cpp | 42 ++++ src/Mod/TechDraw/Gui/ViewProviderHatch.h | 3 + 8 files changed, 579 insertions(+), 9 deletions(-) create mode 100644 src/Mod/TechDraw/Gui/TaskHatch.cpp create mode 100644 src/Mod/TechDraw/Gui/TaskHatch.h create mode 100644 src/Mod/TechDraw/Gui/TaskHatch.ui diff --git a/src/Mod/TechDraw/App/DrawHatch.cpp b/src/Mod/TechDraw/App/DrawHatch.cpp index 27b1677c7a..70c8f0e7ff 100644 --- a/src/Mod/TechDraw/App/DrawHatch.cpp +++ b/src/Mod/TechDraw/App/DrawHatch.cpp @@ -59,16 +59,16 @@ DrawHatch::DrawHatch(void) { static const char *vgroup = "Hatch"; - ADD_PROPERTY_TYPE(DirProjection ,(0,0,1.0) ,vgroup,App::Prop_None,"Projection direction when Hatch was defined"); //sb RO? - ADD_PROPERTY_TYPE(Source,(0),vgroup,(App::PropertyType)(App::Prop_None),"The View + Face to be hatched"); + ADD_PROPERTY_TYPE(DirProjection, (0,0,1.0), vgroup, App::Prop_None, "Projection direction when Hatch was defined"); //sb RO? + ADD_PROPERTY_TYPE(Source, (0), vgroup, (App::PropertyType)(App::Prop_None), "The View + Face to be hatched"); Source.setScope(App::LinkScope::Global); - ADD_PROPERTY_TYPE(HatchPattern ,(prefSvgHatch()),vgroup,App::Prop_None,"The hatch pattern file for this area"); + ADD_PROPERTY_TYPE(HatchPattern, (prefSvgHatch()), vgroup, App::Prop_None, "The hatch pattern file for this area"); ADD_PROPERTY_TYPE(SvgIncluded, (""), vgroup,App::Prop_None, - "Embedded Svg hatch file. System use only."); // n/a to end users + "Embedded SVG hatch file. System use only."); // n/a to end users DirProjection.setStatus(App::Property::ReadOnly,true); - std::string svgFilter("Svg files (*.svg *.SVG);;All files (*)"); + std::string svgFilter("SVG files (*.svg *.SVG);;All files (*)"); HatchPattern.setFilter(svgFilter); } diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index b48f31d31b..9ffdbfd6de 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -55,6 +55,7 @@ set(TechDrawGui_MOC_HDRS DlgTemplateField.h TaskSectionView.h TaskGeomHatch.h + TaskHatch.h TaskLeaderLine.h TaskRichAnno.h TaskCosVertex.h @@ -98,6 +99,7 @@ set(TechDrawGui_UIC_SRCS DlgTemplateField.ui TaskSectionView.ui TaskGeomHatch.ui + TaskHatch.ui TaskLeaderLine.ui TaskRichAnno.ui mrichtextedit.ui @@ -185,6 +187,9 @@ SET(TechDrawGui_SRCS TaskGeomHatch.ui TaskGeomHatch.cpp TaskGeomHatch.h + TaskHatch.ui + TaskHatch.cpp + TaskHatch.h TaskLeaderLine.ui TaskLeaderLine.cpp TaskLeaderLine.h @@ -347,10 +352,10 @@ SET(TechDrawGuiViewProvider_SRCS ViewProviderSpreadsheet.h ViewProviderViewClip.cpp ViewProviderViewClip.h - ViewProviderHatch.cpp - ViewProviderHatch.h ViewProviderGeomHatch.cpp ViewProviderGeomHatch.h + ViewProviderHatch.cpp + ViewProviderHatch.h ViewProviderImage.cpp ViewProviderImage.h ViewProviderLeader.cpp @@ -375,6 +380,7 @@ SET(TechDrawGuiTaskDlgs_SRCS TaskLinkDim.ui TaskSectionView.ui TaskGeomHatch.ui + TaskHatch.ui TaskLeaderLine.ui TaskRichAnno.ui TaskCosVertex.ui diff --git a/src/Mod/TechDraw/Gui/CommandDecorate.cpp b/src/Mod/TechDraw/Gui/CommandDecorate.cpp index a815249f6e..82e2b7036e 100644 --- a/src/Mod/TechDraw/Gui/CommandDecorate.cpp +++ b/src/Mod/TechDraw/Gui/CommandDecorate.cpp @@ -59,9 +59,11 @@ #include "DrawGuiUtil.h" #include "MDIViewPage.h" #include "TaskGeomHatch.h" +#include "TaskHatch.h" //#include "TaskLeaderLine.h" //#include "TaskRichAnno.h" #include "ViewProviderGeomHatch.h" +#include "ViewProviderHatch.h" #include "ViewProviderPage.h" using namespace TechDrawGui; @@ -281,9 +283,19 @@ void CmdTechDrawHatch::activated(int iMsg) auto hatch( static_cast(getDocument()->getObject(FeatName.c_str())) ); hatch->Source.setValue(partFeat, subNames); + Gui::ViewProvider* vp = Gui::Application::Instance->getDocument(getDocument())->getViewProvider(hatch); + TechDrawGui::ViewProviderHatch* hvp = dynamic_cast(vp); + if (!hvp) { + Base::Console().Log("ERROR - CommandDecorate - Hatch has no ViewProvider\n"); + return; + } + //should this be: doCommand(Doc,"App..Feat..Source = [(App...%s,%s),(App..%s,%s),...]",objs[0]->getNameInDocument(),subs[0],...); //seems very unwieldy + // dialog to fill in hatch values + Gui::Control().showDialog(new TaskDlgHatch(hatch, hvp, true)); + commitCommand(); //Horrible hack to force Tree update ??still required?? @@ -353,8 +365,7 @@ void CmdTechDrawGeometricHatch::activated(int iMsg) } // dialog to fill in hatch values - Gui::Control().showDialog(new TaskDlgGeomHatch(geomhatch,hvp,true)); - + Gui::Control().showDialog(new TaskDlgGeomHatch(geomhatch, hvp, true)); commitCommand(); diff --git a/src/Mod/TechDraw/Gui/TaskHatch.cpp b/src/Mod/TechDraw/Gui/TaskHatch.cpp new file mode 100644 index 0000000000..532feb9c2f --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskHatch.cpp @@ -0,0 +1,218 @@ +/*************************************************************************** + * Copyright (c) 2020 FreeCAD Developers * + * Author: Uwe Stöhr * + * * + * 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 +#endif // #ifndef _PreComp_ + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include "ViewProviderHatch.h" +#include "TaskHatch.h" +#include + +using namespace Gui; +using namespace TechDraw; +using namespace TechDrawGui; + +TaskHatch::TaskHatch(TechDraw::DrawHatch* inHatch, TechDrawGui::ViewProviderHatch* inVp, bool mode) : + ui(new Ui_TaskHatch), + m_hatch(inHatch), + m_Vp(inVp), + m_createMode(mode) +{ + ui->setupUi(this); + connect(ui->fcFile, SIGNAL(fileNameSelected( const QString & )), this, SLOT(onFileChanged(void))); + + m_source = m_hatch->Source.getValue(); + getParameters(); + initUi(); +} + +TaskHatch::~TaskHatch() +{ + delete ui; +} + +void TaskHatch::initUi() +{ + ui->fcFile->setFileName(QString::fromUtf8(m_file.data(), m_file.size())); + ui->sbScale->setValue(m_scale); + ui->sbScale->setSingleStep(0.1); + connect(ui->sbScale, SIGNAL(valueChanged(double)), this, SLOT(onScaleChanged())); + ui->ccColor->setColor(m_color.asValue()); + connect(ui->ccColor, SIGNAL(changed()), this, SLOT(onColorChanged())); +} + +//move values from screen to DocObjs +void TaskHatch::updateValues() +{ + m_file = (ui->fcFile->fileName()).toUtf8().constData(); + m_hatch->HatchPattern.setValue(m_file); + m_scale = ui->sbScale->value().getValue(); + m_Vp->HatchScale.setValue(m_scale); + m_color.setValue(ui->ccColor->color()); + m_Vp->HatchColor.setValue(m_color); +} + +QStringList TaskHatch::listToQ(std::vector in) +{ + QStringList result; + for (auto& s: in) { + QString qs = QString::fromUtf8(s.data(), s.size()); + result.append(qs); + } + return result; +} + +void TaskHatch::onFileChanged(void) +{ + m_file = ui->fcFile->fileName().toUtf8().constData(); + m_hatch->HatchPattern.setValue(m_file); + m_source->getDocument()->recompute(); +} + +bool TaskHatch::accept() +{ + updateValues(); + Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()"); + m_source->touch(); + m_source->getDocument()->recompute(); + return true; +} + +void TaskHatch::onScaleChanged() +{ + m_Vp->HatchScale.setValue(ui->sbScale->value().getValue()); + m_source->getDocument()->recompute(); +} + +void TaskHatch::onColorChanged() +{ + App::Color ac; + ac.setValue(ui->ccColor->color()); + m_Vp->HatchColor.setValue(ac); + m_source->getDocument()->recompute(); +} + +bool TaskHatch::reject() +{ + if (getCreateMode()) { + std::string HatchName = m_hatch->getNameInDocument(); + Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().removeObject('%s')",HatchName.c_str()); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); + m_source->touch(); + m_source->getDocument()->recompute(); + } else { + m_hatch->HatchPattern.setValue(m_origFile); + m_Vp->HatchScale.setValue(m_origScale); + m_Vp->HatchColor.setValue(m_origColor); + } + return false; +} + +void TaskHatch::getParameters() +{ + m_file = m_hatch->HatchPattern.getValue(); + m_scale = m_Vp->HatchScale.getValue(); + m_color = m_Vp->HatchColor.getValue(); + if (!getCreateMode()) { + m_origFile = m_hatch->HatchPattern.getValue(); + m_origScale = m_Vp->HatchScale.getValue(); + m_origColor = m_Vp->HatchColor.getValue(); + } +} + +void TaskHatch::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::LanguageChange) { + ui->retranslateUi(this); + } +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +TaskDlgHatch::TaskDlgHatch(TechDraw::DrawHatch* inHatch, TechDrawGui::ViewProviderHatch* inVp, bool mode) : + TaskDialog(), + viewProvider(nullptr) +{ + widget = new TaskHatch(inHatch, inVp, mode); + taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("TechDraw_Tree_View"), + widget->windowTitle(), true, 0); + taskbox->groupLayout()->addWidget(widget); + Content.push_back(taskbox); +} + +TaskDlgHatch::~TaskDlgHatch() +{ +} + +void TaskDlgHatch::setCreateMode(bool b) +{ + widget->setCreateMode(b); +} + +void TaskDlgHatch::update() +{ + //widget->updateTask(); +} + +//==== calls from the TaskView =============================================================== +void TaskDlgHatch::open() +{ +} + +void TaskDlgHatch::clicked(int i) +{ + Q_UNUSED(i); +} + +bool TaskDlgHatch::accept() +{ + widget->accept(); + return true; +} + +bool TaskDlgHatch::reject() +{ + widget->reject(); + return true; +} + +#include diff --git a/src/Mod/TechDraw/Gui/TaskHatch.h b/src/Mod/TechDraw/Gui/TaskHatch.h new file mode 100644 index 0000000000..e541f0ff9c --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskHatch.h @@ -0,0 +1,127 @@ +/*************************************************************************** + * Copyright (c) 2020 FreeCAD Developers * + * Author: Uwe Stöhr * + * * + * 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 * + * * + ***************************************************************************/ + +#ifndef GUI_TASKVIEW_TASKHATCH_H +#define GUI_TASKVIEW_TASKHATCH_H + +#include +#include +#include + +#include +#include + + +class Ui_TaskHatch; + +namespace App +{ +class DocumentObject; +} + +namespace TechDrawGui +{ +class ViewProviderHatch; + +class TaskHatch : public QWidget +{ + Q_OBJECT + +public: + TaskHatch(TechDraw::DrawHatch* inHatch,TechDrawGui::ViewProviderHatch* inVp, bool mode); + ~TaskHatch(); + +public: + virtual bool accept(); + virtual bool reject(); + void setCreateMode(bool b) { m_createMode = b;} + bool getCreateMode() { return m_createMode; } + +protected Q_SLOTS: + void onFileChanged(void); + +protected: + void changeEvent(QEvent *e); + void initUi(); +// bool resetUi(); + void updateValues(); + void getParameters(); + QStringList listToQ(std::vector in); + +private Q_SLOTS: + void onScaleChanged(); + void onColorChanged(); + +private: + Ui_TaskHatch * ui; + TechDraw::DrawHatch* m_hatch; + TechDrawGui::ViewProviderHatch* m_Vp; + App::DocumentObject* m_source; + std::string m_file; + double m_scale; + App::Color m_color; + std::string m_origFile; + double m_origScale; + App::Color m_origColor; + + bool m_createMode; + +}; + +class TaskDlgHatch : public Gui::TaskView::TaskDialog +{ + Q_OBJECT + +public: + TaskDlgHatch(TechDraw::DrawHatch* inHatch,TechDrawGui::ViewProviderHatch* inVp, bool mode); + ~TaskDlgHatch(); + const ViewProviderHatch * getViewProvider() const { return viewProvider; } + +public: + /// is called the TaskView when the dialog is opened + virtual void open(); + /// is called by the framework if an button is clicked which has no accept or reject role + virtual void clicked(int); + /// is called by the framework if the dialog is accepted (Ok) + virtual bool accept(); + /// 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() { return;} + virtual bool isAllowedAlterDocument(void) const + { return false; } + void setCreateMode(bool b); + + void update(); + +protected: + const ViewProviderHatch *viewProvider; + +private: + TaskHatch * widget; + Gui::TaskView::TaskBox* taskbox; +}; + +} //namespace TechDrawGui + +#endif // #ifndef GUI_TASKVIEW_TASKHATCH_H diff --git a/src/Mod/TechDraw/Gui/TaskHatch.ui b/src/Mod/TechDraw/Gui/TaskHatch.ui new file mode 100644 index 0000000000..bf309de485 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskHatch.ui @@ -0,0 +1,163 @@ + + + TechDrawGui::TaskHatch + + + + 0 + 0 + 342 + 135 + + + + + 0 + 0 + + + + + 250 + 0 + + + + Apply Hatch to Face + + + + + + + 0 + 0 + + + + Define your pattern + + + + + + + + + 0 + 0 + + + + The PAT file containing your pattern + + + + + + + Pattern File + + + + + + + + + + + + 0 + 22 + + + + Color of pattern lines + + + + + + + Line Color + + + + + + + + 0 + 22 + + + + Enlarges/shrinks the pattern + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + false + + + 0.001000000000000 + + + 0.100000000000000 + + + 1.000000000000000 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Pattern Scale + + + + + + + + + + + + + Gui::FileChooser + QWidget +
Gui/FileDialog.h
+
+ + Gui::QuantitySpinBox + QWidget +
Gui/QuantitySpinBox.h
+
+ + Gui::ColorButton + QPushButton +
Gui/Widgets.h
+
+
+ + + + +
diff --git a/src/Mod/TechDraw/Gui/ViewProviderHatch.cpp b/src/Mod/TechDraw/Gui/ViewProviderHatch.cpp index 1085e0f6c7..09aeba1fd8 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderHatch.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderHatch.cpp @@ -37,9 +37,12 @@ #include #include #include +#include #include #include + +#include "TaskHatch.h" #include "ViewProviderHatch.h" using namespace TechDrawGui; @@ -93,6 +96,45 @@ std::vector ViewProviderHatch::getDisplayModes(void) const return StrList; } +bool ViewProviderHatch::setEdit(int ModNum) +{ + Q_UNUSED(ModNum); + Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); + TaskDlgHatch *projDlg = qobject_cast(dlg); + if (projDlg && (projDlg->getViewProvider() != this)) + projDlg = 0; // somebody left task panel open + + // clear the selection (convenience) + Gui::Selection().clearSelection(); + + // start the edit dialog + if (projDlg) { + projDlg->setCreateMode(false); + Gui::Control().showDialog(projDlg); + } + else { + Gui::Control().showDialog(new TaskDlgHatch(getViewObject(), this, false)); + } + + return true; +} + +void ViewProviderHatch::unsetEdit(int ModNum) +{ + if (ModNum == ViewProvider::Default) { + Gui::Control().closeDialog(); + } + else { + ViewProviderDocumentObject::unsetEdit(ModNum); + } +} + +bool ViewProviderHatch::doubleClicked(void) +{ + setEdit(0); + return true; +} + void ViewProviderHatch::onChanged(const App::Property* prop) { if ((prop == &HatchScale) || diff --git a/src/Mod/TechDraw/Gui/ViewProviderHatch.h b/src/Mod/TechDraw/Gui/ViewProviderHatch.h index 83d24984aa..07062c0107 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderHatch.h +++ b/src/Mod/TechDraw/Gui/ViewProviderHatch.h @@ -53,6 +53,9 @@ public: /// returns a list of all possible modes virtual std::vector getDisplayModes(void) const override; virtual void onChanged(const App::Property* prop) override; + virtual bool setEdit(int ModNum) override; + virtual void unsetEdit(int ModNum) override; + virtual bool doubleClicked(void) override; virtual void updateData(const App::Property*) override; virtual bool canDelete(App::DocumentObject* obj) const override;