From fe4a402b0457875feba8ca8791a278307cffbe17 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Wed, 9 Nov 2022 15:23:00 -0500 Subject: [PATCH] [TD]simplify section hatch file handling --- src/Mod/TechDraw/App/DrawViewSection.cpp | 121 +++++------------------ src/Mod/TechDraw/App/DrawViewSection.h | 2 - src/Mod/TechDraw/Gui/TaskHatch.cpp | 2 +- 3 files changed, 26 insertions(+), 99 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawViewSection.cpp b/src/Mod/TechDraw/App/DrawViewSection.cpp index afa86bd7c6..ccd7a2f872 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.cpp +++ b/src/Mod/TechDraw/App/DrawViewSection.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * Copyright (c) 2002 Jürgen Riegel * * Copyright (c) 2013 Luke Parry * - * Copyright (c) 2016 WandererFan * + * Copyright (c) 2016, 2022 WandererFan * * * * This file is part of the FreeCAD CAx development system. * * * @@ -220,21 +220,11 @@ void DrawViewSection::onChanged(const App::Property* prop) makeLineSets(); } } else if (prop == &FileHatchPattern) { - if (!FileHatchPattern.isEmpty()) { - Base::FileInfo fi(FileHatchPattern.getValue()); - if (fi.isReadable()) { - replaceSvgIncluded(FileHatchPattern.getValue()); - } - } + replaceSvgIncluded(FileHatchPattern.getValue()); } else if (prop == &FileGeomPattern) { - if (!FileGeomPattern.isEmpty()) { - Base::FileInfo fi(FileGeomPattern.getValue()); - if (fi.isReadable()) { - replacePatIncluded(FileGeomPattern.getValue()); - } - } - } else if (prop == &FileGeomPattern || - prop == &NameGeomPattern ) { + replacePatIncluded(FileGeomPattern.getValue()); + makeLineSets(); + } else if (prop == &NameGeomPattern ) { makeLineSets(); } @@ -995,27 +985,6 @@ void DrawViewSection::unsetupObject() void DrawViewSection::onDocumentRestored() { -// Base::Console().Message("DVS::onDocumentRestored()\n"); - if (SvgIncluded.isEmpty()) { - if (!FileHatchPattern.isEmpty()) { - std::string svgFileName = FileHatchPattern.getValue(); - Base::FileInfo tfi(svgFileName); - if (tfi.isReadable()) { - setupSvgIncluded(); - } - } - } - - if (PatIncluded.isEmpty()) { - if (!FileGeomPattern.isEmpty()) { - std::string patFileName = FileGeomPattern.getValue(); - Base::FileInfo tfi(patFileName); - if (tfi.isReadable()) { - setupPatIncluded(); - } - } - } - makeLineSets(); DrawViewPart::onDocumentRestored(); } @@ -1023,8 +992,8 @@ void DrawViewSection::onDocumentRestored() void DrawViewSection::setupObject() { //by this point DVS should have a name and belong to a document - setupSvgIncluded(); - setupPatIncluded(); + replaceSvgIncluded(FileHatchPattern.getValue()); + replacePatIncluded(FileGeomPattern.getValue()); DrawViewPart::setupObject(); } @@ -1057,73 +1026,33 @@ void DrawViewSection::makeLineSets(void) } } -void DrawViewSection::setupSvgIncluded(void) -{ -// Base::Console().Message("DVS::setupSvgIncluded()\n"); - App::Document* doc = getDocument(); - std::string special = getNameInDocument(); - special += "SvgHatch.svg"; - std::string dir = doc->TransientDir.getValue(); - std::string svgName = dir + special; - - //first time - std::string svgInclude = SvgIncluded.getValue(); - if (svgInclude.empty()) { - DrawUtil::copyFile(std::string(), svgName); - SvgIncluded.setValue(svgName.c_str()); - } - - std::string svgFile = FileHatchPattern.getValue(); - if (!svgFile.empty()) { - std::string exchName = SvgIncluded.getExchangeTempFile(); - DrawUtil::copyFile(svgFile, exchName); - SvgIncluded.setValue(exchName.c_str(), special.c_str()); - } -} - -void DrawViewSection::setupPatIncluded() -{ -// Base::Console().Message("DVS::setupPatIncluded()\n"); - App::Document* doc = getDocument(); - std::string special = getNameInDocument(); - special += "PatHatch.pat"; - std::string dir = doc->TransientDir.getValue(); - std::string patName = dir + special; - std::string patProp = PatIncluded.getValue(); - if (patProp.empty()) { - DrawUtil::copyFile(std::string(), patName); - PatIncluded.setValue(patName.c_str()); - } - - if (!FileGeomPattern.isEmpty()) { - std::string exchName = PatIncluded.getExchangeTempFile(); - DrawUtil::copyFile(FileGeomPattern.getValue(), exchName); - PatIncluded.setValue(exchName.c_str(), special.c_str()); - } -} - -//this could probably always use FileHatchPattern as input? void DrawViewSection::replaceSvgIncluded(std::string newSvgFile) { -// Base::Console().Message("DVS::replaceSvgHatch(%s)\n", newSvgFile.c_str()); - if (SvgIncluded.isEmpty()) { - setupSvgIncluded(); +// Base::Console().Message("DVS::replaceSvgIncluded(%s)\n", newSvgFile.c_str()); + if (newSvgFile.empty()) { + return; + } + + Base::FileInfo tfi(newSvgFile); + if (tfi.isReadable()) { + SvgIncluded.setValue(newSvgFile.c_str()); } else { - std::string tempName = SvgIncluded.getExchangeTempFile(); - DrawUtil::copyFile(newSvgFile, tempName); - SvgIncluded.setValue(tempName.c_str()); + throw Base::RuntimeError("Could not read the new Svg file"); } } void DrawViewSection::replacePatIncluded(std::string newPatFile) { -// Base::Console().Message("DVS::replacePatHatch(%s)\n", newPatFile.c_str()); - if (PatIncluded.isEmpty()) { - setupPatIncluded(); +// Base::Console().Message("DVS::replacePatIncluded(%s)\n", newPatFile.c_str()); + if (newPatFile.empty()) { + return; + } + + Base::FileInfo tfi(newPatFile); + if (tfi.isReadable()) { + PatIncluded.setValue(newPatFile.c_str()); } else { - std::string tempName = PatIncluded.getExchangeTempFile(); - DrawUtil::copyFile(newPatFile, tempName); - PatIncluded.setValue(tempName.c_str()); + throw Base::RuntimeError("Could not read the new Pat file"); } } diff --git a/src/Mod/TechDraw/App/DrawViewSection.h b/src/Mod/TechDraw/App/DrawViewSection.h index 00896d230a..e2ba17bbbc 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.h +++ b/src/Mod/TechDraw/App/DrawViewSection.h @@ -164,8 +164,6 @@ protected: void onDocumentRestored() override; void setupObject() override; - void setupSvgIncluded(); - void setupPatIncluded(); void replaceSvgIncluded(std::string newSvgFile); void replacePatIncluded(std::string newPatFile); diff --git a/src/Mod/TechDraw/Gui/TaskHatch.cpp b/src/Mod/TechDraw/Gui/TaskHatch.cpp index 97af11c843..92dea1314e 100644 --- a/src/Mod/TechDraw/Gui/TaskHatch.cpp +++ b/src/Mod/TechDraw/Gui/TaskHatch.cpp @@ -208,7 +208,7 @@ void TaskHatch::createHatch() void TaskHatch::updateHatch() { - Base::Console().Message("TH::updateHatch()\n"); +// Base::Console().Message("TH::updateHatch()\n"); std::string FeatName = m_hatch->getNameInDocument(); Command::openCommand(QT_TRANSLATE_NOOP("Command", "Update Hatch"));