Implement LineGroups for default weights
- Add ability to control default weight for visible, hidden and decorative lines from a configuration file. Diffent sets of defaults can be specified as a preference.
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
#include "DrawViewPart.h"
|
||||
#include "DrawViewDimension.h"
|
||||
#include "DrawUtil.h"
|
||||
#include "LineGroup.h"
|
||||
|
||||
|
||||
#include <Mod/TechDraw/App/DrawViewDimensionPy.h> // 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
|
||||
|
||||
@@ -97,6 +97,7 @@
|
||||
#include "DrawViewDetail.h"
|
||||
#include "DrawPage.h"
|
||||
#include "EdgeWalker.h"
|
||||
#include "LineGroup.h"
|
||||
|
||||
|
||||
#include <Mod/TechDraw/App/DrawViewPartPy.h> // 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<ParameterGrp> 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()
|
||||
|
||||
@@ -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;
|
||||
|
||||
196
src/Mod/TechDraw/App/LineGroup.cpp
Normal file
196
src/Mod/TechDraw/App/LineGroup.cpp
Normal file
@@ -0,0 +1,196 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2017 Wandererfan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* 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 <sstream>
|
||||
#include <iomanip>
|
||||
#include <stdexcept>
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
|
||||
#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<double> LineGroup::split(std::string line)
|
||||
{
|
||||
std::vector<double> 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<ParameterGrp> 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<double> 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;
|
||||
}
|
||||
67
src/Mod/TechDraw/App/LineGroup.h
Normal file
67
src/Mod/TechDraw/App/LineGroup.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2017 Wandererfan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* 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 <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
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<double> 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
|
||||
Reference in New Issue
Block a user