diff --git a/src/Mod/TechDraw/App/DrawHatch.cpp b/src/Mod/TechDraw/App/DrawHatch.cpp index 354ed64316..4e68af8700 100644 --- a/src/Mod/TechDraw/App/DrawHatch.cpp +++ b/src/Mod/TechDraw/App/DrawHatch.cpp @@ -43,9 +43,9 @@ #include #include +#include "Preferences.h" #include "DrawViewPart.h" #include "DrawUtil.h" -#include "Preferences.h" #include "DrawHatch.h" #include // generated from DrawHatchPy.xml @@ -65,8 +65,7 @@ DrawHatch::DrawHatch(void) 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 - - std::string svgFilter("SVG files (*.svg *.SVG);;All files (*)"); + std::string svgFilter("SVG files (*.svg *.SVG);;Bitmap files(*.jpg *.jpeg *.png *.bmp);;All files (*)"); HatchPattern.setFilter(svgFilter); } @@ -84,13 +83,27 @@ void DrawHatch::onChanged(const App::Property* prop) if ((prop == &HatchPattern) && (doc != nullptr) ) { if (!HatchPattern.isEmpty()) { - replaceSvgIncluded(HatchPattern.getValue()); + replaceFileIncluded(HatchPattern.getValue()); } } } App::DocumentObject::onChanged(prop); } +short DrawHatch::mustExecute() const +{ + short result = 0; + if (!isRestoring()) { + result = (Source.isTouched() || + HatchPattern.isTouched()); + } + + if (result) { + return result; + } + return App::DocumentObject::mustExecute(); +} + App::DocumentObjectExecReturn *DrawHatch::execute(void) { DrawViewPart* parent = getSourceView(); @@ -187,11 +200,11 @@ bool DrawHatch::empty(void) return sourceNames.empty(); } -void DrawHatch::replaceSvgIncluded(std::string newSvgFile) +void DrawHatch::replaceFileIncluded(std::string newSvgFile) { // Base::Console().Message("DH::replaceSvgHatch(%s)\n", newSvgFile.c_str()); if (SvgIncluded.isEmpty()) { - setupSvgIncluded(); + setupFileIncluded(); } else { std::string tempName = SvgIncluded.getExchangeTempFile(); DrawUtil::copyFile(newSvgFile, tempName); @@ -211,28 +224,29 @@ void DrawHatch::onDocumentRestored() Base::FileInfo tfi(svgFileName); if (tfi.isReadable()) { if (SvgIncluded.isEmpty()) { - setupSvgIncluded(); + setupFileIncluded(); } } } } + App::DocumentObject::onDocumentRestored(); } void DrawHatch::setupObject() { //by this point DH should have a name and belong to a document - setupSvgIncluded(); + setupFileIncluded(); App::DocumentObject::setupObject(); } -void DrawHatch::setupSvgIncluded(void) +void DrawHatch::setupFileIncluded(void) { -// Base::Console().Message("DH::setupSvgIncluded()\n"); +// Base::Console().Message("DH::setupFileIncluded()\n"); App::Document* doc = getDocument(); std::string special = getNameInDocument(); - special += "SvgHatch.svg"; + special += "Hatch.fill"; std::string dir = doc->TransientDir.getValue(); std::string svgName = dir + special; @@ -259,6 +273,34 @@ void DrawHatch::unsetupObject(void) App::DocumentObject::unsetupObject(); } +bool DrawHatch::isSvgHatch(void) const +{ + bool result = false; + Base::FileInfo fi(HatchPattern.getValue()); + if ((fi.extension() == "svg") || + (fi.extension() == "SVG")) { + result = true; + } + return result; +} + +bool DrawHatch::isBitmapHatch(void) const +{ + bool result = false; + Base::FileInfo fi(HatchPattern.getValue()); + if ((fi.extension() == "bmp") || + (fi.extension() == "BMP") || + (fi.extension() == "png") || + (fi.extension() == "PNG") || + (fi.extension() == "jpg") || + (fi.extension() == "JPG") || + (fi.extension() == "jpeg") || + (fi.extension() == "JPEG") ) { + result = true; + } + return result; +} + //standard preference getters std::string DrawHatch::prefSvgHatch(void) { @@ -274,7 +316,6 @@ App::Color DrawHatch::prefSvgHatchColor(void) return fcColor; } - // Python Drawing feature --------------------------------------------------------- namespace App { diff --git a/src/Mod/TechDraw/App/DrawHatch.h b/src/Mod/TechDraw/App/DrawHatch.h index c7986e6a98..c17da8eec6 100644 --- a/src/Mod/TechDraw/App/DrawHatch.h +++ b/src/Mod/TechDraw/App/DrawHatch.h @@ -23,11 +23,16 @@ #ifndef _TechDraw_DrawHatch_h_ #define _TechDraw_DrawHatch_h_ +#include + #include #include #include #include +namespace App { +class Color; +} namespace TechDraw { @@ -46,6 +51,7 @@ public: App::PropertyFileIncluded SvgIncluded; virtual App::DocumentObjectExecReturn *execute(void) override; + virtual short mustExecute() const override; virtual const char* getViewProviderName(void) const override { return "TechDrawGui::ViewProviderHatch"; @@ -64,12 +70,15 @@ public: static std::string prefSvgHatch(void); static App::Color prefSvgHatchColor(void); + bool isSvgHatch(void) const; + bool isBitmapHatch(void) const; + protected: void onChanged(const App::Property* prop) override; virtual void onDocumentRestored() override; virtual void setupObject() override; - void setupSvgIncluded(void); - void replaceSvgIncluded(std::string newSvgFile); + void setupFileIncluded(void); + void replaceFileIncluded(std::string newSvgFile); private: diff --git a/src/Mod/TechDraw/App/Preferences.cpp b/src/Mod/TechDraw/App/Preferences.cpp index e917bd06c3..0b4181cc9e 100644 --- a/src/Mod/TechDraw/App/Preferences.cpp +++ b/src/Mod/TechDraw/App/Preferences.cpp @@ -302,3 +302,20 @@ std::string Preferences::patFile() } return result; } + +std::string Preferences::bitmapFill(void) +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Files"); + + std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/Patterns/"; + std::string defaultFileName = defaultDir + "default.png"; + std::string prefBitmapFile = hGrp->GetASCII("BitmapFill", defaultFileName.c_str()); + std::string result = prefBitmapFile; + Base::FileInfo fi(result); + if (!fi.isReadable()) { + result = defaultFileName; + Base::Console().Warning("Bitmap Fill File: %s is not readable\n", prefBitmapFile.c_str()); + } + return result; +} diff --git a/src/Mod/TechDraw/App/Preferences.h b/src/Mod/TechDraw/App/Preferences.h index eb2489ec5d..d8c73d49f9 100644 --- a/src/Mod/TechDraw/App/Preferences.h +++ b/src/Mod/TechDraw/App/Preferences.h @@ -73,7 +73,7 @@ static int mattingStyle(); static std::string svgFile(); static std::string patFile(); - +static std::string bitmapFill(void); }; } //end namespace TechDraw diff --git a/src/Mod/TechDraw/Gui/CommandDecorate.cpp b/src/Mod/TechDraw/Gui/CommandDecorate.cpp index a3babadf23..bcf1c58f80 100644 --- a/src/Mod/TechDraw/Gui/CommandDecorate.cpp +++ b/src/Mod/TechDraw/Gui/CommandDecorate.cpp @@ -132,8 +132,8 @@ void CmdTechDrawHatch::activated(int iMsg) } } - openCommand(QT_TRANSLATE_NOOP("Command", "Create Hatch")); if (removeOld) { + openCommand(QT_TRANSLATE_NOOP("Command", "Remove old Hatch")); std::vector > toRemove; for (auto& h: hatchObjs) { //all the hatch objects for selected DVP std::vector hatchSubs = h->Source.getSubValues(); @@ -154,33 +154,11 @@ void CmdTechDrawHatch::activated(int iMsg) doCommand(Doc,"App.activeDocument().removeObject('%s')",r.second->getNameInDocument()); } } + commitCommand(); } - std::string FeatName = getUniqueObjectName("Hatch"); - std::stringstream featLabel; - featLabel << FeatName << "F" << - TechDraw::DrawUtil::getIndexFromName(subNames.at(0)); //use 1st face# for label - - doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawHatch','%s')",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Label = '%s'",FeatName.c_str(),featLabel.str().c_str()); - - 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(); + Gui::Control().showDialog(new TaskDlgHatch(partFeat, subNames)); //Horrible hack to force Tree update ??still required?? //WF: yes. ViewProvider will not claim children without this! @@ -189,7 +167,6 @@ void CmdTechDrawHatch::activated(int iMsg) getDocument()->recompute(); } - bool CmdTechDrawHatch::isActive(void) { bool havePage = DrawGuiUtil::needPage(this); diff --git a/src/Mod/TechDraw/Gui/QGIFace.cpp b/src/Mod/TechDraw/Gui/QGIFace.cpp index 2705621e46..fb85e72780 100644 --- a/src/Mod/TechDraw/Gui/QGIFace.cpp +++ b/src/Mod/TechDraw/Gui/QGIFace.cpp @@ -136,41 +136,28 @@ void QGIFace::draw() } m_image->hide(); m_rect->hide(); - } else if ((m_mode == FromFile) || - (m_mode == SvgFill) || - (m_mode == BitmapFill)) { - QFileInfo hfi(QString::fromUtf8(m_fileSpec.data(),m_fileSpec.size())); - if (hfi.isReadable()) { - QString ext = hfi.suffix(); - if (ext.toUpper() == QString::fromUtf8("SVG")) { - setFillMode(SvgFill); - m_brush.setTexture(QPixmap()); - m_styleNormal = m_styleDef; - m_fillStyleCurrent = m_styleNormal; - loadSvgHatch(m_fileSpec); - if (m_hideSvgTiles) { - //bitmap hatch doesn't need clipping - setFlag(QGraphicsItem::ItemClipsChildrenToShape,false); - buildPixHatch(); - m_rect->hide(); - m_image->show(); - } else { - //SVG tiles need to be clipped - setFlag(QGraphicsItem::ItemClipsChildrenToShape,true); - buildSvgHatch(); - m_image->hide(); - m_rect->show(); - } - } else if ((ext.toUpper() == QString::fromUtf8("JPG")) || - (ext.toUpper() == QString::fromUtf8("PNG")) || - (ext.toUpper() == QString::fromUtf8("JPEG")) || - (ext.toUpper() == QString::fromUtf8("BMP")) ) { - setFillMode(BitmapFill); - m_fillStyleCurrent = Qt::TexturePattern; - m_texture = textureFromBitmap(m_fileSpec); - m_brush.setTexture(m_texture); - } + } else if (m_mode == SvgFill) { + m_brush.setTexture(QPixmap()); + m_styleNormal = m_styleDef; + m_fillStyleCurrent = m_styleNormal; + loadSvgHatch(m_fileSpec); + if (m_hideSvgTiles) { + //bitmap hatch doesn't need clipping + setFlag(QGraphicsItem::ItemClipsChildrenToShape,false); + buildPixHatch(); + m_rect->hide(); + m_image->show(); + } else { + //SVG tiles need to be clipped + setFlag(QGraphicsItem::ItemClipsChildrenToShape,true); + buildSvgHatch(); + m_image->hide(); + m_rect->show(); } + } else if (m_mode == BitmapFill) { + m_fillStyleCurrent = Qt::TexturePattern; + m_texture = textureFromBitmap(m_fileSpec); + m_brush.setTexture(m_texture); } else if (m_mode == PlainFill) { setFill(m_colNormalFill, m_styleNormal); m_image->hide(); @@ -197,12 +184,14 @@ void QGIFace::setPrettyNormal() { void QGIFace::setPrettyPre() { // Base::Console().Message("QGIF::setPrettyPre()\n"); + m_fillStyleCurrent = Qt::SolidPattern; m_brush.setTexture(QPixmap()); QGIPrimPath::setPrettyPre(); } void QGIFace::setPrettySel() { // Base::Console().Message("QGIF::setPrettySel()\n"); + m_fillStyleCurrent = Qt::SolidPattern; m_brush.setTexture(QPixmap()); QGIPrimPath::setPrettySel(); } @@ -699,13 +688,15 @@ void QGIFace::hideSvg(bool b) QPixmap QGIFace::textureFromBitmap(std::string fileSpec) { QPixmap pix; - QString qs = QString::fromUtf8(fileSpec.data(),fileSpec.size()); - QFileInfo ffi(qs); - if (ffi.isReadable()) { - QImage img = QImage(qs); - img = img.scaled(Rez::guiX(m_fillScale),Rez::guiX(m_fillScale)); - pix = QPixmap::fromImage(img); + + QString qfs(QString::fromUtf8(fileSpec.data(),fileSpec.size())); + QFile f(qfs); + if (!f.open(QFile::ReadOnly)) { + Base::Console().Error("QGIFace could not read %s\n",fileSpec.c_str()); + return pix; } + QByteArray bytes = f.readAll(); + pix.loadFromData(bytes); return pix; } diff --git a/src/Mod/TechDraw/Gui/QGIFace.h b/src/Mod/TechDraw/Gui/QGIFace.h index 33776a23f0..e5da739e35 100644 --- a/src/Mod/TechDraw/Gui/QGIFace.h +++ b/src/Mod/TechDraw/Gui/QGIFace.h @@ -23,11 +23,16 @@ #ifndef DRAWINGGUI_QGRAPHICSITEMFACE_H #define DRAWINGGUI_QGRAPHICSITEMFACE_H -#include +#include #include +#include +#include +#include #include +#include #include +#include #include "QGIPrimPath.h" diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.cpp b/src/Mod/TechDraw/Gui/QGIViewPart.cpp index aa61c9ce21..0e68eaabb2 100644 --- a/src/Mod/TechDraw/Gui/QGIViewPart.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewPart.cpp @@ -476,7 +476,6 @@ void QGIViewPart::drawViewPart() QGIFace* newFace = drawFace(*fit,i); newFace->isHatched(false); newFace->setFillMode(QGIFace::PlainFill); -// newFace->setFill(QColor(Qt::red), Qt::SolidPattern); //this overrides the QGIF defaults TechDraw::DrawHatch* fHatch = faceIsHatched(i,hatchObjs); TechDraw::DrawGeomHatch* fGeom = faceIsGeomHatched(i,geomObjs); if (fGeom) { @@ -504,24 +503,30 @@ void QGIViewPart::drawViewPart() } } } else if (fHatch) { - if (!fHatch->SvgIncluded.isEmpty()) { - if (getExporting()) { - newFace->hideSvg(true); - } else { - newFace->hideSvg(false); - } - newFace->isHatched(true); - newFace->setFillMode(QGIFace::SvgFill); - newFace->setHatchFile(fHatch->SvgIncluded.getValue()); - Gui::ViewProvider* gvp = QGIView::getViewProvider(fHatch); - ViewProviderHatch* hatchVp = dynamic_cast(gvp); - if (hatchVp != nullptr) { - double hatchScale = hatchVp->HatchScale.getValue(); - if (hatchScale > 0.0) { - newFace->setHatchScale(hatchVp->HatchScale.getValue()); + if (fHatch->isSvgHatch()) { + if (!fHatch->SvgIncluded.isEmpty()) { + if (getExporting()) { + newFace->hideSvg(true); + } else { + newFace->hideSvg(false); + } + newFace->isHatched(true); + newFace->setFillMode(QGIFace::SvgFill); + newFace->setHatchFile(fHatch->SvgIncluded.getValue()); + Gui::ViewProvider* gvp = QGIView::getViewProvider(fHatch); + ViewProviderHatch* hatchVp = dynamic_cast(gvp); + if (hatchVp != nullptr) { + double hatchScale = hatchVp->HatchScale.getValue(); + if (hatchScale > 0.0) { + newFace->setHatchScale(hatchVp->HatchScale.getValue()); + } + newFace->setHatchColor(hatchVp->HatchColor.getValue()); } - newFace->setHatchColor(hatchVp->HatchColor.getValue()); } + } else { //bitmap hatch + newFace->isHatched(true); + newFace->setFillMode(QGIFace::BitmapFill); + newFace->setHatchFile(fHatch->SvgIncluded.getValue()); } } bool drawEdges = prefFaceEdges(); diff --git a/src/Mod/TechDraw/Gui/TaskHatch.cpp b/src/Mod/TechDraw/Gui/TaskHatch.cpp index a5fc0e25da..24bb98d715 100644 --- a/src/Mod/TechDraw/Gui/TaskHatch.cpp +++ b/src/Mod/TechDraw/Gui/TaskHatch.cpp @@ -28,6 +28,7 @@ #endif // #ifndef _PreComp_ #include +#include #include #include @@ -43,8 +44,10 @@ #include #include +#include #include +#include "PreferencesGui.h" #include "ViewProviderHatch.h" #include "TaskHatch.h" #include @@ -53,113 +56,192 @@ using namespace Gui; using namespace TechDraw; using namespace TechDrawGui; -TaskHatch::TaskHatch(TechDraw::DrawHatch* inHatch, TechDrawGui::ViewProviderHatch* inVp, bool mode) : +//ctor for creation +TaskHatch::TaskHatch(TechDraw::DrawViewPart* inDvp, std::vector subs) : ui(new Ui_TaskHatch), - m_hatch(inHatch), - m_Vp(inVp), - m_createMode(mode) + m_hatch(nullptr), + m_dvp(inDvp), + m_subs(subs) { ui->setupUi(this); - connect(ui->fcFile, SIGNAL(fileNameSelected( const QString & )), this, SLOT(onFileChanged(void))); - m_source = m_hatch->Source.getValue(); - getParameters(); - initUi(); + connect(ui->fcFile, SIGNAL(fileNameSelected(QString)), this, SLOT(onFileChanged())); + connect(ui->sbScale, SIGNAL(valueChanged(double)), this, SLOT(onScaleChanged())); + connect(ui->ccColor, SIGNAL(changed()), this, SLOT(onColorChanged())); + + setUiPrimary(); } +//ctor for edit +TaskHatch::TaskHatch(TechDrawGui::ViewProviderHatch* inVp) : + ui(new Ui_TaskHatch), + m_vp(inVp) +{ +// Base::Console().Message("TH::TH() - edit\n"); + ui->setupUi(this); + m_hatch = m_vp->getViewObject(); + App::DocumentObject* obj = m_hatch->Source.getValue(); + m_dvp = static_cast(obj); + + connect(ui->fcFile, SIGNAL(fileNameSelected(QString)), this, SLOT(onFileChanged())); + connect(ui->sbScale, SIGNAL(valueChanged(double)), this, SLOT(onScaleChanged())); + connect(ui->ccColor, SIGNAL(changed()), this, SLOT(onColorChanged())); + + saveHatchState(); + setUiEdit(); +} TaskHatch::~TaskHatch() { } -void TaskHatch::initUi() +void TaskHatch::setUiPrimary() { - ui->fcFile->setFileName(QString::fromUtf8(m_file.data(), m_file.size())); - ui->sbScale->setValue(m_scale); + setWindowTitle(QObject::tr("Create Face Hatch")); + ui->fcFile->setFileName(Base::Tools::fromStdString(DrawHatch::prefSvgHatch())); + ui->fcFile->setFilter(QString::fromUtf8( + "SVG files (*.svg *.SVG);;Bitmap files(*.jpg *.jpeg *.png *.bmp);;All files (*)")); + ui->sbScale->setValue(1.0); 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())); + ui->ccColor->setColor(TechDraw::DrawHatch::prefSvgHatchColor().asValue()); } -//move values from screen to DocObjs -void TaskHatch::updateValues() +void TaskHatch::setUiEdit() { - 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); + setWindowTitle(QObject::tr("Edit Face Hatch")); + ui->fcFile->setFileName(Base::Tools::fromStdString(m_saveFile)); + ui->fcFile->setFilter(QString::fromUtf8( + "SVG files (*.svg *.SVG);;Bitmap files(*.jpg *.jpeg *.png *.bmp);;All files (*)")); + ui->sbScale->setValue(m_saveScale); + ui->sbScale->setSingleStep(0.1); + ui->ccColor->setColor(m_saveColor.asValue()); } -QStringList TaskHatch::listToQ(std::vector in) +void TaskHatch::saveHatchState() { - QStringList result; - for (auto& s: in) { - QString qs = QString::fromUtf8(s.data(), s.size()); - result.append(qs); + m_saveFile = m_hatch->HatchPattern.getValue(); + m_saveScale = m_vp->HatchScale.getValue(); + m_saveColor = m_vp->HatchColor.getValue(); +} + +//restore the start conditions +void TaskHatch::restoreHatchState() +{ +// Base::Console().Message("TH::restoreHatchState()\n"); + if (m_hatch != nullptr) { + m_hatch->HatchPattern.setValue(m_saveFile); + m_vp->HatchScale.setValue(m_saveScale); + m_vp->HatchColor.setValue(m_saveColor); } - 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; + m_file = Base::Tools::toStdString(ui->fcFile->fileName()); + apply(); } void TaskHatch::onScaleChanged() { - m_Vp->HatchScale.setValue(ui->sbScale->value().getValue()); - m_source->getDocument()->recompute(); + m_scale = ui->sbScale->value().getValue(); + apply(); } void TaskHatch::onColorChanged() { + m_color.setValue(ui->ccColor->color()); + apply(); +} + +void TaskHatch::apply(bool forceUpdate) +{ + Q_UNUSED(forceUpdate) +// Base::Console().Message("TH::apply() - m_hatch: %X\n", m_hatch); + if (m_hatch == nullptr) { + createHatch(); + } + if (m_hatch != nullptr) { + updateHatch(); + } + + if (m_dvp != nullptr) { + //only need requestPaint to hatch the face +// m_dvp->requestPaint(); + //need a recompute in order to claimChildren in tree + m_dvp->recomputeFeature(); + } +} + +void TaskHatch::createHatch() +{ +// Base::Console().Message("TH::createHatch()\n"); + App::Document* doc = m_dvp->getDocument(); + std::string FeatName = doc->getUniqueObjectName("Hatch"); + std::stringstream featLabel; + featLabel << FeatName << "F" << + TechDraw::DrawUtil::getIndexFromName(m_subs.at(0)); //use 1st face# for label + + Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Hatch")); + + Command::doCommand(Command::Doc,"App.activeDocument().addObject('TechDraw::DrawHatch','%s')",FeatName.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.Label = '%s'",FeatName.c_str(),featLabel.str().c_str()); + + m_hatch = static_cast(doc->getObject(FeatName.c_str())); + m_hatch->Source.setValue(m_dvp, m_subs); + + Command::doCommand(Command::Doc,"App.activeDocument().%s.HatchPattern = '%s'", + FeatName.c_str(), + Base::Tools::toStdString(ui->fcFile->fileName()).c_str()); + + //view provider properties + Gui::ViewProvider* vp = Gui::Application::Instance->getDocument(doc)->getViewProvider(m_hatch); + m_vp = dynamic_cast(vp); + if (m_vp) { + App::Color ac; + ac.setValue(ui->ccColor->color()); + m_vp->HatchColor.setValue(ac); + m_vp->HatchScale.setValue(ui->sbScale->value().getValue()); + } else { + Base::Console().Error("TaskHatch - Hatch has no ViewProvider\n"); + } + Command::commitCommand(); +} + +void TaskHatch::updateHatch() +{ +// Base::Console().Message("TH::updateHatch()\n"); + std::string FeatName = m_hatch->getNameInDocument(); + + Command::openCommand(QT_TRANSLATE_NOOP("Command", "Update Hatch")); + + Command::doCommand(Command::Doc,"App.activeDocument().%s.HatchPattern = '%s'", + FeatName.c_str(), + Base::Tools::toStdString(ui->fcFile->fileName()).c_str()); + App::Color ac; ac.setValue(ui->ccColor->color()); - m_Vp->HatchColor.setValue(ac); - m_source->getDocument()->recompute(); + m_vp->HatchColor.setValue(ac); + m_vp->HatchScale.setValue(ui->sbScale->value().getValue()); + Command::commitCommand(); +} + +bool TaskHatch::accept() +{ +// Base::Console().Message("TH::accept()\n"); + apply(true); + + Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()"); + + return true; } 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); - } +// Base::Console().Message("TH::reject()\n"); + restoreHatchState(); + Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()"); 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) { @@ -168,13 +250,22 @@ void TaskHatch::changeEvent(QEvent *e) } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -TaskDlgHatch::TaskDlgHatch(TechDraw::DrawHatch* inHatch, TechDrawGui::ViewProviderHatch* inVp, bool mode) : - TaskDialog(), - viewProvider(nullptr) +TaskDlgHatch::TaskDlgHatch(TechDraw::DrawViewPart* inDvp, std::vector subs) : + TaskDialog() { - widget = new TaskHatch(inHatch, inVp, mode); - taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("TechDraw_TreeView"), - widget->windowTitle(), true, nullptr); + widget = new TaskHatch(inDvp, subs); + taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("TechDraw_TreeHatch"), + widget->windowTitle(), true, 0); + taskbox->groupLayout()->addWidget(widget); + Content.push_back(taskbox); +} + +TaskDlgHatch::TaskDlgHatch(TechDrawGui::ViewProviderHatch* inVp) : + TaskDialog() +{ + widget = new TaskHatch(inVp); + taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("TechDraw_TreeHatch"), + widget->windowTitle(), true, 0); taskbox->groupLayout()->addWidget(widget); Content.push_back(taskbox); } @@ -183,11 +274,6 @@ TaskDlgHatch::~TaskDlgHatch() { } -void TaskDlgHatch::setCreateMode(bool b) -{ - widget->setCreateMode(b); -} - void TaskDlgHatch::update() { //widget->updateTask(); diff --git a/src/Mod/TechDraw/Gui/TaskHatch.h b/src/Mod/TechDraw/Gui/TaskHatch.h index 986f507d73..716aed3434 100644 --- a/src/Mod/TechDraw/Gui/TaskHatch.h +++ b/src/Mod/TechDraw/Gui/TaskHatch.h @@ -24,23 +24,23 @@ #ifndef GUI_TASKVIEW_TASKHATCH_H #define GUI_TASKVIEW_TASKHATCH_H +#include #include #include +#include +#include + + +class Ui_TaskHatch; namespace App { class DocumentObject; } -namespace TechDraw -{ -class DrawHatch; -} - namespace TechDrawGui { -class Ui_TaskHatch; class ViewProviderHatch; class TaskHatch : public QWidget @@ -48,43 +48,47 @@ class TaskHatch : public QWidget Q_OBJECT public: - TaskHatch(TechDraw::DrawHatch* inHatch,TechDrawGui::ViewProviderHatch* inVp, bool mode); + TaskHatch(TechDraw::DrawViewPart* inDvp, std::vector subs); + TaskHatch(TechDrawGui::ViewProviderHatch* inVp); ~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); + void onScaleChanged(); + void onColorChanged(); protected: void changeEvent(QEvent *e); - void initUi(); -// bool resetUi(); - void updateValues(); - void getParameters(); - QStringList listToQ(std::vector in); + void apply(bool forceUpdate = false); -private Q_SLOTS: - void onScaleChanged(); - void onColorChanged(); + void createHatch(void); + void updateHatch(void); + + void setUiPrimary(); + void setUiEdit(); + + void saveHatchState(); + void restoreHatchState(); + void getParameters(); private: std::unique_ptr ui; TechDraw::DrawHatch* m_hatch; - TechDrawGui::ViewProviderHatch* m_Vp; - App::DocumentObject* m_source; + TechDrawGui::ViewProviderHatch* m_vp; + TechDraw::DrawViewPart* m_dvp; + std::vector m_subs; 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; + std::string m_saveFile; + double m_saveScale; + App::Color m_saveColor; + std::vector m_saveSubs; }; @@ -93,9 +97,9 @@ class TaskDlgHatch : public Gui::TaskView::TaskDialog Q_OBJECT public: - TaskDlgHatch(TechDraw::DrawHatch* inHatch,TechDrawGui::ViewProviderHatch* inVp, bool mode); + TaskDlgHatch(TechDraw::DrawViewPart* inDvp, std::vector subs); + TaskDlgHatch(TechDrawGui::ViewProviderHatch* inVp); ~TaskDlgHatch(); - const ViewProviderHatch * getViewProvider() const { return viewProvider; } public: /// is called the TaskView when the dialog is opened @@ -110,12 +114,10 @@ public: virtual void helpRequested() { return;} virtual bool isAllowedAlterDocument(void) const { return false; } - void setCreateMode(bool b); void update(); protected: - const ViewProviderHatch *viewProvider; private: TaskHatch * widget; diff --git a/src/Mod/TechDraw/Gui/TaskHatch.ui b/src/Mod/TechDraw/Gui/TaskHatch.ui index 8062f60cd3..97b7d39d44 100644 --- a/src/Mod/TechDraw/Gui/TaskHatch.ui +++ b/src/Mod/TechDraw/Gui/TaskHatch.ui @@ -6,8 +6,8 @@ 0 0 - 342 - 135 + 398 + 148 @@ -34,20 +34,16 @@ 0 + + Select an Svg or Bitmap file + - Define your pattern + Pattern Parameters - - - - - Pattern File - - - - + + @@ -56,44 +52,56 @@ - The PAT file containing your pattern + Choose an Svg or Bitmap file as a pattern - + + + + Pattern File + + + + - - - - - Pattern Scale + + + + + + 0 + 0 + - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - 0 - 22 + 26 - Enlarges/shrinks the pattern + Color of pattern lines (Svg Only) + + + + + + + + 0 + 0 + + + + + 0 + 26 + + + + Enlarges/shrinks the pattern (Svg Only) Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -112,27 +120,21 @@ + + + + Svg Pattern Scale + + + - Line Color + Svg Line Color - - - - - 0 - 22 - - - - Color of pattern lines - - - - + diff --git a/src/Mod/TechDraw/Gui/ViewProviderHatch.cpp b/src/Mod/TechDraw/Gui/ViewProviderHatch.cpp index 3e7289da34..74f16f7eb6 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderHatch.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderHatch.cpp @@ -92,24 +92,17 @@ std::vector ViewProviderHatch::getDisplayModes(void) const 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 = nullptr; // 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); + if (ModNum == ViewProvider::Default ) { + if (Gui::Control().activeDialog()) { //TaskPanel already open! + return false; + } + // clear the selection (convenience) + Gui::Selection().clearSelection(); + Gui::Control().showDialog(new TaskDlgHatch(this)); + return true; + } else { + return Gui::ViewProviderDocumentObject::setEdit(ModNum); } - else { - Gui::Control().showDialog(new TaskDlgHatch(getViewObject(), this, false)); - } - return true; } diff --git a/src/Mod/TechDraw/Gui/ViewProviderHatch.h b/src/Mod/TechDraw/Gui/ViewProviderHatch.h index cbe9947d3f..dfa04bb505 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderHatch.h +++ b/src/Mod/TechDraw/Gui/ViewProviderHatch.h @@ -25,6 +25,8 @@ #ifndef DRAWINGGUI_VIEWPROVIDERHATCH_H #define DRAWINGGUI_VIEWPROVIDERHATCH_H +#include + #include namespace TechDraw{ diff --git a/src/Mod/TechDraw/Patterns/default.png b/src/Mod/TechDraw/Patterns/default.png new file mode 100644 index 0000000000..ecb8b6cf5a Binary files /dev/null and b/src/Mod/TechDraw/Patterns/default.png differ