diff --git a/src/Mod/TechDraw/App/DrawGeomHatch.cpp b/src/Mod/TechDraw/App/DrawGeomHatch.cpp index e77f7e4e2a..cc3a59d104 100644 --- a/src/Mod/TechDraw/App/DrawGeomHatch.cpp +++ b/src/Mod/TechDraw/App/DrawGeomHatch.cpp @@ -93,17 +93,17 @@ DrawGeomHatch::DrawGeomHatch(void) ADD_PROPERTY_TYPE(Source,(0),vgroup,(App::PropertyType)(App::Prop_None),"The View + Face to be crosshatched"); Source.setScope(App::LinkScope::Global); - ADD_PROPERTY_TYPE(FilePattern ,(""),vgroup,App::Prop_None,"The crosshatch pattern file for this area"); + ADD_PROPERTY_TYPE(FilePattern ,(prefGeomHatchFile()),vgroup,App::Prop_None,"The crosshatch pattern file for this area"); ADD_PROPERTY_TYPE(PatIncluded, (""), vgroup,App::Prop_None, "Embedded Pat hatch file. System use only."); // n/a to end users - ADD_PROPERTY_TYPE(NamePattern,(""),vgroup,App::Prop_None,"The name of the pattern"); + ADD_PROPERTY_TYPE(NamePattern,(prefGeomHatchName()),vgroup,App::Prop_None,"The name of the pattern"); ADD_PROPERTY_TYPE(ScalePattern,(1.0),vgroup,App::Prop_None,"GeomHatch pattern size adjustment"); ScalePattern.setConstraints(&scaleRange); m_saveFile = ""; m_saveName = ""; - getParameters(); +// getParameters(); std::string patFilter("pat files (*.pat *.PAT);;All files (*)"); FilePattern.setFilter(patFilter); @@ -544,7 +544,7 @@ void DrawGeomHatch::replacePatIncluded(std::string newPatFile) setupPatIncluded(); } else { std::string tempName = PatIncluded.getExchangeTempFile(); - copyFile(newPatFile, tempName); + DrawUtil::copyFile(newPatFile, tempName); PatIncluded.setValue(tempName.c_str()); } } @@ -585,31 +585,17 @@ void DrawGeomHatch::setupPatIncluded(void) std::string patName = dir + special; if (PatIncluded.isEmpty()) { - copyFile(std::string(), patName); + DrawUtil::copyFile(std::string(), patName); PatIncluded.setValue(patName.c_str()); } if (!FilePattern.isEmpty()) { std::string exchName = PatIncluded.getExchangeTempFile(); - copyFile(FilePattern.getValue(), exchName); + DrawUtil::copyFile(FilePattern.getValue(), exchName); PatIncluded.setValue(exchName.c_str(), special.c_str()); } } -//TODO: replace with FileInfo copy -//copy whole text file from inSpec to outSpec -void DrawGeomHatch::copyFile(std::string inSpec, std::string outSpec) -{ -// Base::Console().Message("DGH::copyFile(%s, %s)\n", inSpec.c_str(), outSpec.c_str()); - if (inSpec.empty()) { - std::ofstream dst(outSpec); //make an empty file - } else { - std::ifstream src(inSpec); - std::ofstream dst(outSpec); - dst << src.rdbuf(); - } -} - void DrawGeomHatch::unsetupObject(void) { // Base::Console().Message("DGH::unsetupObject() - status: %lu removing: %d \n", getStatus(), isRemoving()); @@ -621,6 +607,26 @@ void DrawGeomHatch::unsetupObject(void) App::DocumentObject::unsetupObject(); } +std::string DrawGeomHatch::prefGeomHatchFile(void) +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/PAT"); + + std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/PAT/"; + std::string defaultFileName = defaultDir + "FCPAT.pat"; + std::string result = hGrp->GetASCII("FilePattern", defaultFileName.c_str()); + return result; +} + +std::string DrawGeomHatch::prefGeomHatchName() +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/PAT"); + std::string defaultNamePattern = "Diamond"; + std::string result = hGrp->GetASCII("NamePattern",defaultNamePattern.c_str()); + return result; +} + // Python Drawing feature --------------------------------------------------------- diff --git a/src/Mod/TechDraw/App/DrawGeomHatch.h b/src/Mod/TechDraw/App/DrawGeomHatch.h index 87995fe10e..cf722400b1 100644 --- a/src/Mod/TechDraw/App/DrawGeomHatch.h +++ b/src/Mod/TechDraw/App/DrawGeomHatch.h @@ -78,13 +78,14 @@ public: static TopoDS_Edge makeLine(Base::Vector3d s, Base::Vector3d e); static std::vector getDecodedSpecsFromFile(std::string fileSpec, std::string myPattern); static TopoDS_Face extractFace(DrawViewPart* source, int iface ); + static std::string prefGeomHatchFile(void); + static std::string prefGeomHatchName(); protected: virtual void onDocumentRestored() override; virtual void setupObject() override; void setupPatIncluded(void); void replacePatIncluded(std::string newPatFile); - void copyFile(std::string inSpec, std::string outSpec); void makeLineSets(void); diff --git a/src/Mod/TechDraw/App/DrawHatch.cpp b/src/Mod/TechDraw/App/DrawHatch.cpp index 559bd4928c..e9d9011199 100644 --- a/src/Mod/TechDraw/App/DrawHatch.cpp +++ b/src/Mod/TechDraw/App/DrawHatch.cpp @@ -62,31 +62,14 @@ DrawHatch::DrawHatch(void) 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 ,(""),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 DirProjection.setStatus(App::Property::ReadOnly,true); - 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 + "simple.svg"; - QString patternFileName = QString::fromStdString(hGrp->GetASCII("FileHatch",defaultFileName.c_str())); - if (patternFileName.isEmpty()) { - patternFileName = QString::fromStdString(defaultFileName); - } - QFileInfo tfi(patternFileName); - if (tfi.isReadable()) { - HatchPattern.setValue(patternFileName.toUtf8().constData()); - } - std::string svgFilter("Svg files (*.svg *.SVG);;All files (*)"); HatchPattern.setFilter(svgFilter); - -// SvgIncluded.setStatus(App::Property::ReadOnly,true); - } DrawHatch::~DrawHatch() @@ -213,7 +196,7 @@ void DrawHatch::replaceSvgIncluded(std::string newSvgFile) setupSvgIncluded(); } else { std::string tempName = SvgIncluded.getExchangeTempFile(); - copyFile(newSvgFile, tempName); + DrawUtil::copyFile(newSvgFile, tempName); SvgIncluded.setValue(tempName.c_str()); } } @@ -256,30 +239,17 @@ void DrawHatch::setupSvgIncluded(void) std::string svgName = dir + special; if (SvgIncluded.isEmpty()) { - copyFile(std::string(), svgName); + DrawUtil::copyFile(std::string(), svgName); SvgIncluded.setValue(svgName.c_str()); } if (!HatchPattern.isEmpty()) { std::string exchName = SvgIncluded.getExchangeTempFile(); - copyFile(HatchPattern.getValue(), exchName); + DrawUtil::copyFile(HatchPattern.getValue(), exchName); SvgIncluded.setValue(exchName.c_str(), special.c_str()); } } -//copy whole text file from inSpec to outSpec -void DrawHatch::copyFile(std::string inSpec, std::string outSpec) -{ -// Base::Console().Message("DH::copyFile(%s, %s)\n", inSpec.c_str(), outSpec.c_str()); - if (inSpec.empty()) { - std::ofstream dst(outSpec); //make an empty file - } else { - std::ifstream src(inSpec); - std::ofstream dst(outSpec); - dst << src.rdbuf(); - } -} - void DrawHatch::unsetupObject(void) { // Base::Console().Message("DH::unsetupObject() - status: %lu removing: %d \n", getStatus(), isRemoving()); @@ -291,6 +261,17 @@ void DrawHatch::unsetupObject(void) App::DocumentObject::unsetupObject(); } +//standard preference getter +std::string DrawHatch::prefSvgHatch(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 + "simple.svg"; + std::string result = hGrp->GetASCII("FileHatch",defaultFileName.c_str()); + return result; +} // Python Drawing feature --------------------------------------------------------- diff --git a/src/Mod/TechDraw/App/DrawHatch.h b/src/Mod/TechDraw/App/DrawHatch.h index 9b3ea010c6..e789c6b0f4 100644 --- a/src/Mod/TechDraw/App/DrawHatch.h +++ b/src/Mod/TechDraw/App/DrawHatch.h @@ -61,7 +61,7 @@ public: bool removeSub(int i); bool empty(void); static bool faceIsHatched(int i,std::vector hatchObjs); - + static std::string prefSvgHatch(void); protected: void onChanged(const App::Property* prop) override; @@ -69,7 +69,6 @@ protected: virtual void setupObject() override; void setupSvgIncluded(void); void replaceSvgIncluded(std::string newSvgFile); - void copyFile(std::string inSpec, std::string outSpec); private: diff --git a/src/Mod/TechDraw/App/DrawUtil.cpp b/src/Mod/TechDraw/App/DrawUtil.cpp index 648fb071c1..786daaf79b 100644 --- a/src/Mod/TechDraw/App/DrawUtil.cpp +++ b/src/Mod/TechDraw/App/DrawUtil.cpp @@ -1063,6 +1063,25 @@ void DrawUtil::findCircularArcRectangleIntersections(const Base::Vector2d &circl rectangle, intersections); } +//copy whole text file from inSpec to outSpec +//create empty outSpec file if inSpec +void DrawUtil::copyFile(std::string inSpec, std::string outSpec) +{ +// Base::Console().Message("DU::copyFile(%s, %s)\n", inSpec.c_str(), outSpec.c_str()); + if (inSpec.empty()) { + std::ofstream output(outSpec); + return; + } + Base::FileInfo fi(inSpec); + if (fi.isReadable()) { + bool rc = fi.copyTo(outSpec.c_str()); + if (!rc) { + Base::Console().Message("DU::copyFile - failed - in: %s out:%s\n", inSpec.c_str(), outSpec.c_str()); + } + } +} + + //============================ // various debugging routines. void DrawUtil::dumpVertexes(const char* text, const TopoDS_Shape& s) diff --git a/src/Mod/TechDraw/App/DrawUtil.h b/src/Mod/TechDraw/App/DrawUtil.h index 1c9901de61..8b9f66c92a 100644 --- a/src/Mod/TechDraw/App/DrawUtil.h +++ b/src/Mod/TechDraw/App/DrawUtil.h @@ -156,6 +156,7 @@ class TechDrawExport DrawUtil { double arcBaseAngle, double arcRotation, const Base::BoundBox2d &rectangle, std::vector &intersections); + static void copyFile(std::string inSpec, std::string outSpec); //debugging routines static void dumpVertexes(const char* text, const TopoDS_Shape& s); diff --git a/src/Mod/TechDraw/App/DrawViewSection.cpp b/src/Mod/TechDraw/App/DrawViewSection.cpp index 8f389a61b0..286ae99af1 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.cpp +++ b/src/Mod/TechDraw/App/DrawViewSection.cpp @@ -87,6 +87,7 @@ #include "DrawProjGroupItem.h" #include "DrawProjectSplit.h" #include "DrawGeomHatch.h" +#include "DrawHatch.h" #include "DrawViewSection.h" using namespace TechDraw; @@ -128,13 +129,16 @@ DrawViewSection::DrawViewSection() CutSurfaceDisplay.setEnums(CutSurfaceEnums); ADD_PROPERTY_TYPE(CutSurfaceDisplay,((long)2),fgroup, App::Prop_None, "Appearance of Cut Surface"); - ADD_PROPERTY_TYPE(FileHatchPattern ,(""),fgroup,App::Prop_None,"The hatch pattern file for the cut surface"); - ADD_PROPERTY_TYPE(FileGeomPattern ,(""),fgroup,App::Prop_None,"The PAT pattern file for geometric hatching"); + +//initialize these to defaults + ADD_PROPERTY_TYPE(FileHatchPattern ,(DrawHatch::prefSvgHatch()),fgroup,App::Prop_None,"The hatch pattern file for the cut surface"); + ADD_PROPERTY_TYPE(FileGeomPattern ,(DrawGeomHatch::prefGeomHatchFile()),fgroup,App::Prop_None,"The PAT pattern file for geometric hatching"); + ADD_PROPERTY_TYPE(SvgIncluded ,(""),fgroup,App::Prop_None, "Embedded Svg hatch file. System use only."); // n/a to end users ADD_PROPERTY_TYPE(PatIncluded ,(""),fgroup,App::Prop_None, "Embedded Pat pattern file. System use only."); // n/a to end users - ADD_PROPERTY_TYPE(NameGeomPattern ,(""),fgroup,App::Prop_None,"The pattern name for geometric hatching"); + ADD_PROPERTY_TYPE(NameGeomPattern ,(DrawGeomHatch::prefGeomHatchName()),fgroup,App::Prop_None,"The pattern name for geometric hatching"); ADD_PROPERTY_TYPE(HatchScale,(1.0),fgroup,App::Prop_None,"Hatch pattern size adjustment"); getParameters(); @@ -254,7 +258,7 @@ void DrawViewSection::replaceSvgIncluded(std::string newSvgFile) setupSvgIncluded(); } else { std::string tempName = SvgIncluded.getExchangeTempFile(); - copyFile(newSvgFile, tempName); + DrawUtil::copyFile(newSvgFile, tempName); SvgIncluded.setValue(tempName.c_str()); } } @@ -266,7 +270,7 @@ void DrawViewSection::replacePatIncluded(std::string newPatFile) setupPatIncluded(); } else { std::string tempName = PatIncluded.getExchangeTempFile(); - copyFile(newPatFile, tempName); + DrawUtil::copyFile(newPatFile, tempName); PatIncluded.setValue(tempName.c_str()); } } @@ -863,45 +867,10 @@ TechDraw::DrawProjGroupItem* DrawViewSection::getBaseDPGI() const return baseDPGI; } -//copy whole text file from inSpec to outSpec -void DrawViewSection::copyFile(std::string inSpec, std::string outSpec) -{ -// Base::Console().Message("DVS::copyFile(%s, %s)\n", inSpec.c_str(), outSpec.c_str()); - if (inSpec.empty()) { - std::ofstream dst(outSpec); //make an empty file - } else { - std::ifstream src(inSpec); - std::ofstream dst(outSpec); - dst << src.rdbuf(); - } -} - void DrawViewSection::getParameters() { // Base::Console().Message("DVS::getParameters()\n"); - 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 + "simple.svg"; - std::string patternFileName = hGrp->GetASCII("FileHatch",defaultFileName.c_str()); - Base::FileInfo tfi(patternFileName); - if (tfi.isReadable()) { - FileHatchPattern.setValue(patternFileName); - } - - defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/PAT/"; - defaultFileName = defaultDir + "FCPAT.pat"; - patternFileName = hGrp->GetASCII("FilePattern",defaultFileName.c_str()); - Base::FileInfo tfi2(patternFileName); - if (tfi2.isReadable()) { - FileGeomPattern.setValue(patternFileName); - } - - std::string patternName = hGrp->GetASCII("PatternName","Diamond"); - NameGeomPattern.setValue(patternName); - - hGrp = App::GetApplication().GetUserParameter() + Base::ReferencehGrp = App::GetApplication().GetUserParameter() .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/General"); bool fuseFirst = hGrp->GetBool("SectionFuseFirst", false); @@ -960,15 +929,18 @@ void DrawViewSection::setupSvgIncluded(void) special += "SvgHatch.svg"; std::string dir = doc->TransientDir.getValue(); std::string svgName = dir + special; - - if (SvgIncluded.isEmpty()) { - copyFile(std::string(), svgName); + + //first time + std::string svgInclude = SvgIncluded.getValue(); + if (svgInclude.empty()) { + DrawUtil::copyFile(std::string(), svgName); SvgIncluded.setValue(svgName.c_str()); } - if (!FileHatchPattern.isEmpty()) { + std::string svgFile = FileHatchPattern.getValue(); + if (!svgFile.empty()) { std::string exchName = SvgIncluded.getExchangeTempFile(); - copyFile(FileHatchPattern.getValue(), exchName); + DrawUtil::copyFile(svgFile, exchName); SvgIncluded.setValue(exchName.c_str(), special.c_str()); } } @@ -981,14 +953,15 @@ void DrawViewSection::setupPatIncluded(void) special += "PatHatch.pat"; std::string dir = doc->TransientDir.getValue(); std::string patName = dir + special; - if (PatIncluded.isEmpty()) { - copyFile(std::string(), patName); + 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(); - copyFile(FileGeomPattern.getValue(), exchName); + DrawUtil::copyFile(FileGeomPattern.getValue(), exchName); PatIncluded.setValue(exchName.c_str(), special.c_str()); } } diff --git a/src/Mod/TechDraw/App/DrawViewSection.h b/src/Mod/TechDraw/App/DrawViewSection.h index 5664803d1b..d459b47019 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.h +++ b/src/Mod/TechDraw/App/DrawViewSection.h @@ -133,9 +133,6 @@ protected: TopoDS_Shape m_cutShape; - void copyFile(std::string inSpec, std::string outSpec); - - virtual void onDocumentRestored() override; virtual void setupObject() override; void setupSvgIncluded(void);