diff --git a/src/Mod/TechDraw/App/CMakeLists.txt b/src/Mod/TechDraw/App/CMakeLists.txt index c2aac39361..fcd76aa48f 100644 --- a/src/Mod/TechDraw/App/CMakeLists.txt +++ b/src/Mod/TechDraw/App/CMakeLists.txt @@ -104,6 +104,8 @@ SET(TechDraw_SRCS EdgeWalker.h DrawProjectSplit.cpp DrawProjectSplit.h + LineGroup.cpp + LineGroup.h ) SET(Geometry_SRCS @@ -162,6 +164,10 @@ SET(TechDraw_PATFile PAT/FCPAT.pat ) +SET(TechDraw_LineGroupFile + LineGroup/LineGroup.csv +) + if(MSVC) #add_definitions(-D_PreComp_) #GET_MSVC_PRECOMPILED_SOURCE("PreCompiled.cpp" TechDrawCPP_SRCS ${TechDraw_SRCS} ${Draw_SRCS} ) @@ -192,6 +198,11 @@ fc_target_copy_resource(TechDraw ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/Mod/TechDraw ${TechDraw_PATFile}) +fc_target_copy_resource(TechDraw + ${CMAKE_SOURCE_DIR}/src/Mod/TechDraw + ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/Mod/TechDraw + ${TechDraw_LineGroupFile}) + SET_BIN_DIR(TechDraw TechDraw /Mod/TechDraw) SET_PYTHON_PREFIX_SUFFIX(TechDraw) diff --git a/src/Mod/TechDraw/App/DrawViewDimension.cpp b/src/Mod/TechDraw/App/DrawViewDimension.cpp index 6d59671e9b..317addbe7d 100644 --- a/src/Mod/TechDraw/App/DrawViewDimension.cpp +++ b/src/Mod/TechDraw/App/DrawViewDimension.cpp @@ -51,6 +51,7 @@ #include "DrawViewPart.h" #include "DrawViewDimension.h" #include "DrawUtil.h" +#include "LineGroup.h" #include // generated from DrawViewDimensionPy.xml @@ -91,7 +92,7 @@ DrawViewDimension::DrawViewDimension(void) std::string fontName = hGrp->GetASCII("LabelFont", "Sans"); hGrp = App::GetApplication().GetUserParameter() .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions"); - double fontSize = hGrp->GetFloat("FontSize", 4.0); + double fontSize = hGrp->GetFloat("FontSize", 3.5); ADD_PROPERTY_TYPE(References2D,(0,0),"",(App::PropertyType)(App::Prop_None),"Projected Geometry References"); ADD_PROPERTY_TYPE(References3D,(0,0),"",(App::PropertyType)(App::Prop_None),"3D Geometry References"); @@ -99,7 +100,12 @@ DrawViewDimension::DrawViewDimension(void) ADD_PROPERTY_TYPE(Fontsize,(fontSize) ,"Format",(App::PropertyType)(App::Prop_None),"Dimension text size in mm"); ADD_PROPERTY_TYPE(FormatSpec,(getDefaultFormatSpec().c_str()) , "Format",(App::PropertyType)(App::Prop_None),"Dimension Format"); - ADD_PROPERTY_TYPE(LineWidth,(0.5) ,"Format",(App::PropertyType)(App::Prop_None),"Dimension line weight"); + + hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Decorations"); + std::string lgName = hGrp->GetASCII("LineGroup","FC 0.70mm"); + auto lg = LineGroup::lineGroupFactory(lgName); + double weight = lg->getWeight("Graphic"); + ADD_PROPERTY_TYPE(LineWidth,(weight) ,"Format",(App::PropertyType)(App::Prop_None),"Dimension line weight"); //ADD_PROPERTY_TYPE(CentreLines,(0) ,"Format",(App::PropertyType)(App::Prop_None),"Arc Dimension Center Mark"); Type.setEnums(TypeEnums); //dimension type: length, radius etc diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index 096d85b969..5b6a556fb5 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -97,6 +97,7 @@ #include "DrawViewDetail.h" #include "DrawPage.h" #include "EdgeWalker.h" +#include "LineGroup.h" #include // generated from DrawViewPartPy.xml @@ -116,6 +117,7 @@ DrawViewPart::DrawViewPart(void) : geometryObject(0) { static const char *group = "Projection"; static const char *fgroup = "Format"; + static const char *lgroup = "Lines"; static const char *sgroup = "Show"; nowUnsetting = false; @@ -133,21 +135,33 @@ DrawViewPart::DrawViewPart(void) : geometryObject(0) ADD_PROPERTY_TYPE(SeamHidden ,(false),sgroup,App::Prop_None,"Hidden Seam lines on/off"); ADD_PROPERTY_TYPE(IsoHidden ,(false),sgroup,App::Prop_None,"Hidden Iso u,v lines on/off"); ADD_PROPERTY_TYPE(IsoCount ,(0),sgroup,App::Prop_None,"Number of isoparameters"); + + //default line weights + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Decorations"); + std::string lgName = hGrp->GetASCII("LineGroup","FC 0.70mm"); + auto lg = LineGroup::lineGroupFactory(lgName); + double weight = lg->getWeight("Thick"); + ADD_PROPERTY_TYPE(LineWidth,(weight),lgroup,App::Prop_None,"The thickness of visible lines"); + weight = lg->getWeight("Thin"); + ADD_PROPERTY_TYPE(HiddenWidth,(weight),lgroup,App::Prop_None,"The thickness of hidden lines, if enabled"); + weight = lg->getWeight("Graphic"); + ADD_PROPERTY_TYPE(IsoWidth,(weight),lgroup,App::Prop_None,"The thickness of isoparameter/center/section lines, if enabled"); + weight = lg->getWeight("Extra"); + ADD_PROPERTY_TYPE(ExtraWidth,(weight),lgroup,App::Prop_None,"The thickness of LineGroup Extra lines, if enabled"); + + ADD_PROPERTY_TYPE(HorizCenterLine ,(false),lgroup,App::Prop_None,"Show a horizontal centerline through view"); + ADD_PROPERTY_TYPE(VertCenterLine ,(false),lgroup,App::Prop_None,"Show a vertical centerline through view"); - ADD_PROPERTY_TYPE(LineWidth,(0.7f),fgroup,App::Prop_None,"The thickness of visible lines"); - ADD_PROPERTY_TYPE(HiddenWidth,(0.15),fgroup,App::Prop_None,"The thickness of hidden lines, if enabled"); - ADD_PROPERTY_TYPE(IsoWidth,(0.30),fgroup,App::Prop_None,"The thickness of UV isoparameter lines, if enabled"); ADD_PROPERTY_TYPE(ArcCenterMarks ,(true),sgroup,App::Prop_None,"Center marks on/off"); ADD_PROPERTY_TYPE(CenterScale,(2.0),fgroup,App::Prop_None,"Center mark size adjustment, if enabled"); - ADD_PROPERTY_TYPE(HorizCenterLine ,(false),sgroup,App::Prop_None,"Show a horizontal centerline through view"); - ADD_PROPERTY_TYPE(VertCenterLine ,(false),sgroup,App::Prop_None,"Show a vertical centerline through view"); //properties that affect Section Line ADD_PROPERTY_TYPE(ShowSectionLine ,(true) ,sgroup,App::Prop_None,"Show/hide section line if applicable"); geometryObject = nullptr; getRunControl(); - + delete lg; } DrawViewPart::~DrawViewPart() diff --git a/src/Mod/TechDraw/App/DrawViewPart.h b/src/Mod/TechDraw/App/DrawViewPart.h index b868d0712b..95e12b6ca9 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.h +++ b/src/Mod/TechDraw/App/DrawViewPart.h @@ -98,6 +98,7 @@ public: App::PropertyFloat LineWidth; App::PropertyFloat HiddenWidth; App::PropertyFloat IsoWidth; + App::PropertyFloat ExtraWidth; App::PropertyBool ArcCenterMarks; App::PropertyFloat CenterScale; App::PropertyBool HorizCenterLine; diff --git a/src/Mod/TechDraw/App/LineGroup.cpp b/src/Mod/TechDraw/App/LineGroup.cpp new file mode 100644 index 0000000000..46728ade64 --- /dev/null +++ b/src/Mod/TechDraw/App/LineGroup.cpp @@ -0,0 +1,196 @@ +/*************************************************************************** + * 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 +#include +#include +#endif + +#include +#include +#include + +#include "LineGroup.h" + +using namespace TechDraw; + +LineGroup::LineGroup() +{ + init(); +} + +LineGroup::LineGroup(std::string groupName) +{ + init(); + m_name = groupName; +} + + +LineGroup::~LineGroup() +{ +} + +void LineGroup::init(void) +{ + m_name = ""; + m_thin = 0.0; + m_graphic = 0.0; + m_thick = 0.0; + m_extra = 0.0; +} + +double LineGroup::getWeight(std::string s) +{ + double result = 0.55; + if (s == "Thin") { + result = m_thin; + } else if (s == "Graphic") { + result = m_graphic; + } else if (s == "Thick") { + result = m_thick; + } else if (s == "Extra") { + result = m_extra; + } + return result; +} + +void LineGroup::setWeight(std::string s, double weight) +{ + if (s == "Thin") { + m_thin = weight; + } else if (s == "Graphic") { + m_graphic = weight; + } else if (s == "Thick") { + m_thick = weight; + } else if (s == "Extra") { + m_extra = weight; + } +} + +void LineGroup::dump(char* title) +{ + Base::Console().Message( "DUMP: %s\n",title); + Base::Console().Message( "Name: %s\n", m_name.c_str()); + Base::Console().Message( "Thin: %.3f\n", m_thin); + Base::Console().Message( "Graphic: %.3f\n",m_graphic); + Base::Console().Message( "Thick: %.3f\n",m_thick); + Base::Console().Message( "Extra: %.3f\n",m_extra); +} + +//static support function: split comma separated string of values into vector of numbers +std::vector LineGroup::split(std::string line) +{ + std::vector result; + std::stringstream lineStream(line); + std::string cell; + bool nameCell = true; + + while(std::getline(lineStream,cell, ',')) + { + if (nameCell) { + nameCell = false; + continue; + } + try { + result.push_back(std::stod(cell)); + } + catch (const std::invalid_argument& ia) { + Base::Console().Warning("Invalid number in cell: %s (%s) \n",cell.c_str(),ia.what()); + result.push_back(0.0); + } + } + return result; +} + +//static support function: find group defn in file +std::string LineGroup::getRecordFromFile(std::string parmFile, std::string groupName) +{ + std::string record; + std::string lineSpec; + std::ifstream inFile; + inFile.open (parmFile, std::ifstream::in); + if(!inFile.is_open()) { + Base::Console().Message( "Cannot open input file: %s\n",parmFile.c_str()); + return record; + } + + bool groupFound = false; + while ( inFile.good() ){ + std::string line; + std::getline(inFile,line); + std::string nameTag = line.substr(0,1); + std::string foundName; + unsigned long int commaPos; + if ((nameTag == ";") || + (nameTag == " ") || + (line.empty()) ) { //is cr/lf empty? + continue; + } else if (nameTag == "*") { + commaPos = line.find(",",1); + if (commaPos != std::string::npos) { + foundName = line.substr(1,commaPos-1); + } else { + foundName = line.substr(1); + } + if (foundName == groupName) { + //this is our group + record = line; + groupFound = true; + break; + } + } + } //endwhile + if (!groupFound) { + Base::Console().Message("LineGroup - group: %s is not found\n", groupName.c_str()); + } + return record; +} + +//static LineGroup maker +LineGroup* LineGroup::lineGroupFactory(std::string groupName) +{ + LineGroup* lg = new LineGroup(groupName); + + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Files"); + + std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/LineGroup/"; + std::string defaultFileName = defaultDir + "LineGroup.csv"; + + std::string lgFileName = hGrp->GetASCII("LineGroupFile",defaultFileName.c_str()); + + std::string lgRecord = LineGroup::getRecordFromFile(lgFileName, groupName); + + std::vector values = LineGroup::split(lgRecord); + if (values.size() < 4) { + Base::Console().Message( "LineGroup::invalid entry in %s\n",groupName.c_str() ); + } else { + lg->setWeight("Thin",values[0]); + lg->setWeight("Graphic",values[1]); + lg->setWeight("Thick",values[2]); + lg->setWeight("Extra",values[3]); + } + return lg; +} diff --git a/src/Mod/TechDraw/App/LineGroup.h b/src/Mod/TechDraw/App/LineGroup.h new file mode 100644 index 0000000000..fc136f4bcc --- /dev/null +++ b/src/Mod/TechDraw/App/LineGroup.h @@ -0,0 +1,67 @@ +/*************************************************************************** + * 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 * + * * + ***************************************************************************/ + +//! LineGroup - Classes related to processing LineGroup definition CSV files + +#ifndef _TechDraw_LINEGROUP_H_ +#define _TechDraw_LINEGROUP_H_ + +#include +#include +#include +#include + +namespace TechDraw +{ + +class TechDrawExport LineGroup +{ +public: + LineGroup(); + LineGroup(std::string groupName); + ~LineGroup(); + double getWeight(std::string s); + void setWeight(std::string s, double weight); +// void setWeight(const char* s, double weight); + void dump(char* title); + + //static support function: split comma separated string of values into vector of numbers + static std::vector split(std::string line); + + //static support function: find group defn in file + static std::string getRecordFromFile(std::string parmFile, std::string groupName); + + //static LineGroup maker + static LineGroup* lineGroupFactory(std::string groupName); + +protected: + void init(void); + + std::string m_name; + double m_thin; + double m_graphic; + double m_thick; + double m_extra; +}; + +} +#endif diff --git a/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2.ui b/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2.ui index 7a6c07f4ac..e5d61a8c7a 100644 --- a/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2.ui +++ b/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2.ui @@ -7,7 +7,7 @@ 0 0 521 - 554 + 587 @@ -94,7 +94,7 @@ 1 - 4.000000000000000 + 3.500000000000000 FontSize @@ -254,7 +254,7 @@ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - 5.000000000000000 + 3.500000000000000 ArrowSize @@ -290,7 +290,7 @@ - + MattingStyle @@ -310,28 +310,28 @@ - + Section Line Style - + Center Line Style - + Matting Style - + @@ -348,7 +348,7 @@ - + 2 @@ -391,7 +391,7 @@ - + 2 @@ -434,21 +434,21 @@ - + Center Line Color - + Section Line Color - + @@ -465,7 +465,7 @@ - + Qt::Horizontal @@ -478,7 +478,7 @@ - + Default weight for GeomHatch lines @@ -488,7 +488,7 @@ - + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -504,6 +504,26 @@ + + + + Line Group + + + + + + + FC 0.70mm + + + LineGroup + + + /Mod/TechDraw/Decorations + + + diff --git a/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2Imp.cpp b/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2Imp.cpp index 14c5273007..d46779b1d4 100644 --- a/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2Imp.cpp +++ b/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2Imp.cpp @@ -56,6 +56,7 @@ void DlgPrefsTechDraw2Imp::saveSettings() cbGlobalDecimals->onSave(); sbAltDecimals->onSave(); dsbArrowSize->onSave(); + leLineGroup->onSave(); } void DlgPrefsTechDraw2Imp::loadSettings() @@ -73,6 +74,7 @@ void DlgPrefsTechDraw2Imp::loadSettings() cbGlobalDecimals->onRestore(); sbAltDecimals->onRestore(); dsbArrowSize->onRestore(); + leLineGroup->onRestore(); } /** diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.cpp b/src/Mod/TechDraw/Gui/QGIViewPart.cpp index 15e840fac0..8183bfcc28 100644 --- a/src/Mod/TechDraw/Gui/QGIViewPart.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewPart.cpp @@ -642,7 +642,7 @@ void QGIViewPart::drawSectionLine(TechDraw::DrawViewSection* viewSection, bool b yVal = sectionSpan / 2.0; } sectionLine->setBounds(-xVal,-yVal,xVal,yVal); - sectionLine->setWidth(Rez::guiX(viewPart->LineWidth.getValue())); //TODO: add fudge to make sectionLine thinner than reg lines? + sectionLine->setWidth(Rez::guiX(viewPart->IsoWidth.getValue())); sectionLine->setFont(m_font,Rez::guiX(6.0)); sectionLine->setZValue(ZVALUE::SECTIONLINE); sectionLine->setRotation(viewPart->Rotation.getValue()); @@ -673,7 +673,7 @@ void QGIViewPart::drawCenterLines(bool b) xVal = sectionSpan / 2.0; yVal = 0.0; centerLine->setBounds(-xVal,-yVal,xVal,yVal); - //centerLine->setWidth(viewPart->LineWidth.getValue()); + centerLine->setWidth(Rez::guiX(viewPart->IsoWidth.getValue())); centerLine->setZValue(ZVALUE::SECTIONLINE); centerLine->setRotation(viewPart->Rotation.getValue()); centerLine->draw(); @@ -686,7 +686,7 @@ void QGIViewPart::drawCenterLines(bool b) xVal = 0.0; yVal = sectionSpan / 2.0; centerLine->setBounds(-xVal,-yVal,xVal,yVal); - //centerLine->setWidth(viewPart->LineWidth.getValue()); + centerLine->setWidth(Rez::guiX(viewPart->IsoWidth.getValue())); centerLine->setZValue(ZVALUE::SECTIONLINE); centerLine->setRotation(viewPart->Rotation.getValue()); centerLine->draw(); @@ -714,7 +714,7 @@ void QGIViewPart::drawHighlight(TechDraw::DrawViewDetail* viewDetail, bool b) Base::Vector3d center = viewDetail->AnchorPoint.getValue() * viewPart->getScale(); double radius = viewDetail->Radius.getValue() * viewPart->getScale(); highlight->setBounds(center.x - radius, center.y + radius,center.x + radius, center.y - radius); - highlight->setWidth(Rez::guiX(viewPart->LineWidth.getValue())); + highlight->setWidth(Rez::guiX(viewPart->IsoWidth.getValue())); highlight->setFont(m_font,Rez::guiX(6.0)); highlight->setZValue(ZVALUE::HIGHLIGHT); highlight->draw(); diff --git a/src/Mod/TechDraw/LineGroup/LineGroup.csv b/src/Mod/TechDraw/LineGroup/LineGroup.csv new file mode 100644 index 0000000000..ca6d8b78f8 --- /dev/null +++ b/src/Mod/TechDraw/LineGroup/LineGroup.csv @@ -0,0 +1,15 @@ +;FreeCAD LineGroup Definitions +;Format: *GroupName,thin,graphic,thick,extra +;thin: hidden lines +;graphic: dimensions, centerlines +;thick: visible lines +;extra: not implemented + +*FC 0.25mm,0.13,0.18,0.25,0.50 +*FC 0.35mm,0.18,0.25,0.35,0.70 +*FC 0.50mm,0.25,0.35,0.50,1.0 +*FC 0.70mm,0.35,0.50,0.70,1.4 +*FC 1.00mm,0.50,0.70,1.00,2.00 + + +