diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index 8fe24d3b2..7ce4ee9cf 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -36,6 +36,7 @@ set(TechDrawGui_MOC_HDRS TaskLinkDim.h DlgTemplateField.h TaskSectionView.h + TaskGeomHatch.h ) fc_wrap_cpp(TechDrawGui_MOC_SRCS ${TechDrawGui_MOC_HDRS}) @@ -54,6 +55,7 @@ set(TechDrawGui_UIC_SRCS TaskLinkDim.ui DlgTemplateField.ui TaskSectionView.ui + TaskGeomHatch.ui ) if(BUILD_QT5) @@ -92,6 +94,9 @@ SET(TechDrawGui_SRCS TaskSectionView.ui TaskSectionView.cpp TaskSectionView.h + TaskGeomHatch.ui + TaskGeomHatch.cpp + TaskGeomHatch.h DrawGuiUtil.cpp DrawGuiUtil.h Rez.cpp @@ -213,6 +218,7 @@ SET(TechDrawGuiTaskDlgs_SRCS TaskProjGroup.ui TaskLinkDim.ui TaskSectionView.ui + TaskGeomHatch.ui ) SOURCE_GROUP("TaskDialogs" FILES ${TechDrawGuiTaskDlgs_SRCS}) diff --git a/src/Mod/TechDraw/Gui/CommandDecorate.cpp b/src/Mod/TechDraw/Gui/CommandDecorate.cpp index 0a4fdbac5..2b38bdc87 100644 --- a/src/Mod/TechDraw/Gui/CommandDecorate.cpp +++ b/src/Mod/TechDraw/Gui/CommandDecorate.cpp @@ -56,6 +56,8 @@ #include "DrawGuiUtil.h" #include "MDIViewPage.h" +#include "TaskGeomHatch.h" +#include "ViewProviderGeomHatch.h" #include "ViewProviderPage.h" using namespace TechDrawGui; @@ -171,6 +173,13 @@ void CmdTechDrawNewGeomHatch::activated(int iMsg) auto geomhatch( static_cast(getDocument()->getObject(FeatName.c_str())) ); geomhatch->Source.setValue(objFeat, subNames); + Gui::ViewProvider* vp = Gui::Application::Instance->getDocument(getDocument())->getViewProvider(geomhatch); + TechDrawGui::ViewProviderGeomHatch* hvp = dynamic_cast(vp); +// if (!hvp) { + + // dialog to fill in hatch values + Gui::Control().showDialog(new TaskDlgGeomHatch(geomhatch,hvp)); + commitCommand(); diff --git a/src/Mod/TechDraw/Gui/TaskGeomHatch.cpp b/src/Mod/TechDraw/Gui/TaskGeomHatch.cpp new file mode 100644 index 000000000..cdf9b463b --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskGeomHatch.cpp @@ -0,0 +1,195 @@ +/*************************************************************************** + * Copyright (c) 2017 WandererFan * + * * + * 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 + +#include "ViewProviderGeomHatch.h" +#include "TaskGeomHatch.h" +#include + +using namespace Gui; +using namespace TechDraw; +using namespace TechDrawGui; + +TaskGeomHatch::TaskGeomHatch(TechDraw::DrawGeomHatch* inHatch,TechDrawGui::ViewProviderGeomHatch* inVp) : + ui(new Ui_TaskGeomHatch), + m_hatch(inHatch), + m_Vp(inVp) +{ + ui->setupUi(this); + connect(ui->fcFile, SIGNAL(fileNameSelected( const QString & )), this, SLOT(onFileChanged(void))); + + m_source = m_hatch->Source.getValue(); + getParameters(); + initUi(); +} + +TaskGeomHatch::~TaskGeomHatch() +{ + delete ui; +} + + +void TaskGeomHatch::initUi() +{ + ui->fcFile->setFileName(QString::fromUtf8(m_file.data(), m_file.size())); + std::vector names = HatchLine::getPatternList(m_file); + QStringList qsNames = listToQ(names); + ui->cbName->addItems(qsNames); + ui->sbScale->setValue(m_scale); + ui->sbWeight->setValue(m_weight); + ui->ccColor->setColor(m_color.asValue()); +} + +//move values from screen to DocObjs +void TaskGeomHatch::updateValues() +{ + m_file = (ui->fcFile->fileName()).toUtf8().constData(); + m_hatch->FilePattern.setValue(m_file); + QString cText = ui->cbName->currentText(); + m_name = cText.toUtf8().constData(); + m_hatch->NamePattern.setValue(m_name); + m_scale = ui->sbScale->value(); + m_hatch->ScalePattern.setValue(m_scale); + m_color.setValue(ui->ccColor->color()); + m_Vp->ColorPattern.setValue(m_color); + m_weight = ui->sbWeight->value(); + m_Vp->WeightPattern.setValue(m_weight); +} + +QStringList TaskGeomHatch::listToQ(std::vector in) +{ + QStringList result; + for (auto& s: in) { + QString qs = QString::fromUtf8(s.data(), s.size()); + result.append(qs); + } + return result; +} + +void TaskGeomHatch::onFileChanged(void) +{ + m_file = ui->fcFile->fileName().toUtf8().constData(); + std::vector names = HatchLine::getPatternList(m_file); + QStringList qsNames = listToQ(names); + ui->cbName->clear(); + ui->cbName->addItems(qsNames); +} + +bool TaskGeomHatch::accept() +{ + updateValues(); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); + return true; +} + +bool TaskGeomHatch::reject() +{ + 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(); + return false; +} + +void TaskGeomHatch::getParameters() +{ + m_file = m_hatch->FilePattern.getValue(); + m_name = m_hatch->NamePattern.getValue(); + m_scale = m_hatch->ScalePattern.getValue(); + m_color = m_Vp->ColorPattern.getValue(); + m_weight = m_Vp->WeightPattern.getValue(); +} + +void TaskGeomHatch::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::LanguageChange) { + ui->retranslateUi(this); + } +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +TaskDlgGeomHatch::TaskDlgGeomHatch(TechDraw::DrawGeomHatch* inHatch, TechDrawGui::ViewProviderGeomHatch* inVp) : + TaskDialog() +{ + widget = new TaskGeomHatch(inHatch,inVp); + taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("TechDraw_Tree_View"), + widget->windowTitle(), true, 0); + taskbox->groupLayout()->addWidget(widget); + Content.push_back(taskbox); +} + +TaskDlgGeomHatch::~TaskDlgGeomHatch() +{ +} + +void TaskDlgGeomHatch::update() +{ + //widget->updateTask(); +} + +//==== calls from the TaskView =============================================================== +void TaskDlgGeomHatch::open() +{ +} + +void TaskDlgGeomHatch::clicked(int i) +{ + Q_UNUSED(i); +} + +bool TaskDlgGeomHatch::accept() +{ + widget->accept(); + return true; +} + +bool TaskDlgGeomHatch::reject() +{ + widget->reject(); + return true; +} + +#include diff --git a/src/Mod/TechDraw/Gui/TaskGeomHatch.h b/src/Mod/TechDraw/Gui/TaskGeomHatch.h new file mode 100644 index 000000000..5d5f9ebf1 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskGeomHatch.h @@ -0,0 +1,116 @@ +/*************************************************************************** + * Copyright (c) 2017 WandererFan * + * * + * 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_TASKGEOMHATCH_H +#define GUI_TASKVIEW_TASKGEOMHATCH_H + +#include +#include +#include + +#include + +#include + + +class Ui_TaskGeomHatch; + +namespace App +{ +class DocumentObject; +} + + +namespace TechDrawGui +{ +class ViewProviderGeomHatch; + +class TaskGeomHatch : public QWidget +{ + Q_OBJECT + +public: + TaskGeomHatch(TechDraw::DrawGeomHatch* inHatch,TechDrawGui::ViewProviderGeomHatch* inVp); + ~TaskGeomHatch(); + +public: + virtual bool accept(); + virtual bool reject(); + +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: + Ui_TaskGeomHatch * ui; + TechDraw::DrawGeomHatch* m_hatch; + TechDrawGui::ViewProviderGeomHatch* m_Vp; + App::DocumentObject* m_source; + std::string m_file; + std::string m_name; + double m_scale; + double m_weight; + App::Color m_color; + +}; + +class TaskDlgGeomHatch : public Gui::TaskView::TaskDialog +{ + Q_OBJECT + +public: + TaskDlgGeomHatch(TechDraw::DrawGeomHatch* inHatch,TechDrawGui::ViewProviderGeomHatch* inVp); + ~TaskDlgGeomHatch(); + +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 update(); + +protected: + +private: + TaskGeomHatch * widget; + Gui::TaskView::TaskBox* taskbox; +}; + +} //namespace TechDrawGui + +#endif // #ifndef GUI_TASKVIEW_TASKGEOMHATCH_H diff --git a/src/Mod/TechDraw/Gui/TaskGeomHatch.ui b/src/Mod/TechDraw/Gui/TaskGeomHatch.ui new file mode 100644 index 000000000..b6c43474a --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskGeomHatch.ui @@ -0,0 +1,178 @@ + + + TechDrawGui::TaskGeomHatch + + + + 0 + 0 + 385 + 265 + + + + + 0 + 0 + + + + + 250 + 0 + + + + Apply Geometric Hatch to Face + + + + + + + 0 + 0 + + + + Define your pattern + + + + + + + + + 0 + 0 + + + + The PAT file containing your pattern + + + + + + + Pattern File + + + + + + + + + + + Pattern Name + + + + + + + Line Weight + + + + + + + Pattern Scale + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Line Color + + + + + + + Name of pattern within file + + + + + + + Color of pattern lines + + + + + + + Enlarges/shrinks the pattern + + + 1.000000000000000 + + + + + + + Thickness of lines within the pattern + + + 1.000000000000000 + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Gui::FileChooser + QWidget +
Gui/FileDialog.h
+
+ + Gui::ColorButton + QPushButton +
Gui/Widgets.h
+
+
+ + + + +