diff --git a/src/Mod/TechDraw/App/DrawViewDimension.cpp b/src/Mod/TechDraw/App/DrawViewDimension.cpp
index 9d8cc36425..4bbce12ef8 100644
--- a/src/Mod/TechDraw/App/DrawViewDimension.cpp
+++ b/src/Mod/TechDraw/App/DrawViewDimension.cpp
@@ -42,6 +42,7 @@
#include
#include
#include
+#include
#include
#include
@@ -96,14 +97,15 @@ DrawViewDimension::DrawViewDimension(void)
ADD_PROPERTY_TYPE(References3D,(0,0),"",(App::PropertyType)(App::Prop_None),"3D Geometry References");
ADD_PROPERTY_TYPE(Font ,(fontName.c_str()),"Format",App::Prop_None, "The name of the font to use");
ADD_PROPERTY_TYPE(Fontsize,(fontSize) ,"Format",(App::PropertyType)(App::Prop_None),"Dimension text size in mm");
- ADD_PROPERTY_TYPE(FormatSpec,("%value%") ,"Format",(App::PropertyType)(App::Prop_None),"Dimension Format");
+ 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");
//ADD_PROPERTY_TYPE(CentreLines,(0) ,"Format",(App::PropertyType)(App::Prop_None),"Arc Dimension Center Mark");
Type.setEnums(TypeEnums); //dimension type: length, radius etc
ADD_PROPERTY(Type,((long)0));
MeasureType.setEnums(MeasureTypeEnums);
- ADD_PROPERTY(MeasureType, ((long)0)); //True or Projected measurement
+ ADD_PROPERTY(MeasureType, ((long)1)); //Projected (or True) measurement
//hide the properties the user can't edit in the property editor
@@ -193,7 +195,8 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void)
std::string DrawViewDimension::getFormatedValue()
{
- QString str = QString::fromUtf8(FormatSpec.getStrValue().data(),FormatSpec.getStrValue().size());
+ std::string result;
+ QString specStr = QString::fromUtf8(FormatSpec.getStrValue().data(),FormatSpec.getStrValue().size());
double val = std::abs(getDimValue());
Base::Quantity qVal;
@@ -204,31 +207,50 @@ std::string DrawViewDimension::getFormatedValue()
qVal.setUnit(Base::Unit::Length);
}
QString userStr = qVal.getUserString(); //this handles mm to inch/km/parsec etc and decimal positions
- QRegExp rx2(QString::fromUtf8("\\D*$"));
+ QRegExp rxUnits(QString::fromUtf8("\\D*$")); //any non digits at end of string
+
QString userVal = userStr;
- userVal.remove(rx2);
+ userVal.remove(rxUnits); //getUserString(defaultDecimals) without units
- QRegExp rx(QString::fromUtf8("%(\\w+)%")); //any word bracketed by %
- QStringList list;
+ QString userUnits;
int pos = 0;
+ if ((pos = rxUnits.indexIn(userStr, 0)) != -1) {
+ userUnits = rxUnits.cap(0); //entire capture - non numerics at end of userString
+ }
- while ((pos = rx.indexIn(str, pos)) != -1) {
- list << rx.cap(0);
- pos += rx.matchedLength();
+ std::string prefixSym = getPrefix(); //get Radius/Diameter/... symbol
+
+ //have dimensionVal, whole userString, val(userString), units(userString), prefixSymbol
+
+ //find the %x.y tag in FormatSpec
+ QRegExp rxFormat(QString::fromUtf8("%[0-9]*\\.[0-9]*[aefgAEFG]")); //printf double format spec
+ QString match;
+ QString specVal = Base::Tools::fromStdString("%.2f"); //sensible default
+ pos = 0;
+ if ((pos = rxFormat.indexIn(specStr, 0)) != -1) {
+ match = rxFormat.cap(0); //entire capture of rx
+ QString qs2;
+ specVal = qs2.sprintf(Base::Tools::toStdString(match).c_str(),val);
}
QString repl = userVal;
- if (showUnits()) {
- repl = userStr;
- }
-
- for(QStringList::const_iterator it = list.begin(); it != list.end(); ++it) {
- if(*it == QString::fromUtf8("%value%")){
- str.replace(*it,repl);
-// } else { //insert additional placeholder replacement logic here
+ if (useDecimals()) {
+ if (showUnits()) {
+ repl = userStr;
+ } else {
+ repl = userVal;
+ }
+ } else {
+ if (showUnits()) {
+ repl = specVal + userUnits;
+ } else {
+ repl = specVal;
}
}
- return str.toUtf8().constData();
+ repl = Base::Tools::fromStdString(getPrefix()) + repl;
+ specStr.replace(match,repl);
+
+ return specStr.toUtf8().constData();
}
@@ -251,26 +273,6 @@ double DrawViewDimension::getDimValue()
return result;
}
- if(Type.isValue("Distance")) {
- result = measurement->delta().Length();
- } else if(Type.isValue("DistanceX")){
- Base::Vector3d delta = measurement->delta();
- result = delta.x;
- } else if(Type.isValue("DistanceY")){
- Base::Vector3d delta = measurement->delta();
- result = delta.y;
- } else if(Type.isValue("DistanceZ")){
- Base::Vector3d delta = measurement->delta();
- result = delta.z;
- } else if(Type.isValue("Radius")){
- result = measurement->radius();
- } else if(Type.isValue("Diameter")){
- result = measurement->radius() * 2.0;
- } else if(Type.isValue("Angle")){
- result = measurement->angle();
- } else {
- throw Base::Exception("getDimValue() - Unknown Dimension Type (1)");
- }
} else {
// Projected Values
const std::vector &objects = References2D.getValues();
@@ -667,6 +669,56 @@ bool DrawViewDimension::showUnits() const
return result;
}
+bool DrawViewDimension::useDecimals() const
+{
+ bool result = false;
+ Base::Reference hGrp = App::GetApplication().GetUserParameter()
+ .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions");
+ result = hGrp->GetBool("UseGlobalDecimals", true);
+ return result;
+}
+
+std::string DrawViewDimension::getPrefix() const
+{
+ std::string result = "";
+ if(Type.isValue("Distance")) {
+ result = "";
+ } else if(Type.isValue("DistanceX")){
+ result = "";
+ } else if(Type.isValue("DistanceY")){
+ result = "";
+ } else if(Type.isValue("DistanceZ")){
+ result = "";
+ } else if(Type.isValue("Radius")){
+ result = "R";
+ } else if(Type.isValue("Diameter")){
+ Base::Reference hGrp = App::GetApplication().GetUserParameter()
+ .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions");
+ std::string diamSym = hGrp->GetASCII("DiameterSymbol","\xe2\x8c\x80");
+ result = diamSym;
+ } else if(Type.isValue("Angle")){
+ result = "";
+ }
+ return result;
+}
+
+std::string DrawViewDimension::getDefaultFormatSpec() const
+{
+ Base::Reference hGrp = App::GetApplication().GetUserParameter()
+ .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions");
+ QString format1 = Base::Tools::fromStdString("%.");
+ QString format2 = Base::Tools::fromStdString("f");
+ int precision;
+ if (useDecimals()) {
+ precision = Base::UnitsApi::getDecimals();
+ } else {
+ precision = hGrp->GetInt("AltDecimals", 2);
+ }
+ QString formatPrecision = QString::number(precision);
+ QString formatSpec = format1 + formatPrecision + format2;
+ return Base::Tools::toStdString(formatSpec);
+}
+
PyObject *DrawViewDimension::getPyObject(void)
{
if (PythonObject.is(Py::_None())) {
diff --git a/src/Mod/TechDraw/App/DrawViewDimension.h b/src/Mod/TechDraw/App/DrawViewDimension.h
index 13f5a92e68..0f434cc1b8 100644
--- a/src/Mod/TechDraw/App/DrawViewDimension.h
+++ b/src/Mod/TechDraw/App/DrawViewDimension.h
@@ -97,6 +97,9 @@ protected:
void onChanged(const App::Property* prop);
virtual void onDocumentRestored();
bool showUnits() const;
+ bool useDecimals() const;
+ std::string getPrefix() const;
+ std::string getDefaultFormatSpec() const;
protected:
Measure::Measurement *measurement;
diff --git a/src/Mod/TechDraw/Gui/CommandCreateDims.cpp b/src/Mod/TechDraw/Gui/CommandCreateDims.cpp
index f7158504b9..f5324cc3bb 100644
--- a/src/Mod/TechDraw/Gui/CommandCreateDims.cpp
+++ b/src/Mod/TechDraw/Gui/CommandCreateDims.cpp
@@ -202,20 +202,12 @@ void CmdTechDrawNewDimension::activated(int iMsg)
doCommand(Doc,"App.activeDocument().%s.Type = '%s'",FeatName.c_str()
,dimType.c_str());
- std::string contentStr;
- if (dimType == "Radius") {
- contentStr = "R%value%";
- }
- doCommand(Doc,"App.activeDocument().%s.FormatSpec = '%s'",FeatName.c_str()
- ,contentStr.c_str());
-
dim = dynamic_cast(getDocument()->getObject(FeatName.c_str()));
if (!dim) {
throw Base::Exception("CmdTechDrawNewDimension - dim not found\n");
}
dim->References2D.setValues(objs, subs);
- doCommand(Doc,"App.activeDocument().%s.MeasureType = 'Projected'",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
commitCommand();
@@ -295,7 +287,6 @@ void CmdTechDrawNewRadiusDimension::activated(int iMsg)
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDimension','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Type = '%s'",FeatName.c_str()
,"Radius");
- doCommand(Doc, "App.activeDocument().%s.FormatSpec = 'R%%value%%'", FeatName.c_str());
dim = dynamic_cast(getDocument()->getObject(FeatName.c_str()));
if (!dim) {
@@ -303,7 +294,6 @@ void CmdTechDrawNewRadiusDimension::activated(int iMsg)
}
dim->References2D.setValues(objs, subs);
- doCommand(Doc,"App.activeDocument().%s.MeasureType = 'Projected'",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
commitCommand();
@@ -380,20 +370,10 @@ void CmdTechDrawNewDiameterDimension::activated(int iMsg)
return;
}
- Base::Reference hGrp = App::GetApplication().GetUserParameter()
- .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions");
- std::string diamSym = hGrp->GetASCII("DiameterSymbol","\xe2\x8c\x80");
- diamSym = diamSym.substr (0,79); //coverity 156593
- const char * format = "%value%";
- char formatSpec[80];
- std::strcpy (formatSpec,diamSym.c_str());
- std::strcat (formatSpec,format);
-
openCommand("Create Dimension");
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDimension','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Type = '%s'",FeatName.c_str()
,"Diameter");
- doCommand(Doc, "App.activeDocument().%s.FormatSpec = '%s'", FeatName.c_str(),formatSpec);
dim = dynamic_cast(getDocument()->getObject(FeatName.c_str()));
if (!dim) {
@@ -401,7 +381,6 @@ void CmdTechDrawNewDiameterDimension::activated(int iMsg)
}
dim->References2D.setValues(objs, subs);
- doCommand(Doc,"App.activeDocument().%s.MeasureType = 'Projected'",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
commitCommand();
@@ -510,9 +489,6 @@ void CmdTechDrawNewLengthDimension::activated(int iMsg)
}
dim->References2D.setValues(objs, subs);
- doCommand(Doc, "App.activeDocument().%s.FormatSpec = '%%value%%'", FeatName.c_str());
-
- doCommand(Doc,"App.activeDocument().%s.MeasureType = 'Projected'",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
commitCommand();
@@ -621,9 +597,6 @@ void CmdTechDrawNewDistanceXDimension::activated(int iMsg)
}
dim->References2D.setValues(objs, subs);
- doCommand(Doc, "App.activeDocument().%s.FormatSpec = '%%value%%'", FeatName.c_str());
-
- doCommand(Doc,"App.activeDocument().%s.MeasureType = 'Projected'",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
commitCommand();
@@ -731,9 +704,6 @@ void CmdTechDrawNewDistanceYDimension::activated(int iMsg)
}
dim->References2D.setValues(objs, subs);
- doCommand(Doc, "App.activeDocument().%s.FormatSpec = '%%value%%'", FeatName.c_str());
-
- doCommand(Doc,"App.activeDocument().%s.MeasureType = 'Projected'",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
commitCommand();
@@ -821,7 +791,6 @@ void CmdTechDrawNewAngleDimension::activated(int iMsg)
}
dim->References2D.setValues(objs, subs);
- doCommand(Doc,"App.activeDocument().%s.MeasureType = 'Projected'",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
commitCommand();
diff --git a/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2.ui b/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2.ui
index 0e56034a06..1906b79297 100644
--- a/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2.ui
+++ b/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2.ui
@@ -7,7 +7,7 @@
0
0
521
- 463
+ 554
@@ -21,7 +21,30 @@
-
-
+
+
-
+
+
+ Arrow Style
+
+
+
+ -
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
+
+ 2
+
+
+ AltDecimals
+
+
+ /Mod/TechDraw/Dimensions
+
+
+
-
@@ -35,21 +58,21 @@
- -
+
-
Color
- -
+
-
Font Size
- -
+
-
Qt::Horizontal
@@ -62,7 +85,7 @@
- -
+
-
Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
@@ -81,7 +104,7 @@
- -
+
-
@@ -98,14 +121,14 @@
- -
+
-
Diameter Symbol
- -
+
-
@@ -126,6 +149,121 @@
+ -
+
+
+ Alternate Decimals
+
+
+
+ -
+
+
+ Use Global Decimals
+
+
+ true
+
+
+ UseGlobalDecimals
+
+
+ /Mod/TechDraw/Dimensions
+
+
+
+ -
+
+
+ Preferred arrowhead style
+
+
+ 0
+
+
+ 5
+
+
+ ArrowStyle
+
+
+ Mod/TechDraw/Dimensions
+
+
-
+
+ 0 - Filled Triangle
+
+
+
+ :/icons/arrowfilled.svg
+
+
+
+ -
+
+ 1 - Open Arrowhead
+
+
+
+ :/icons/arrowopen.svg
+
+
+
+ -
+
+ 2 - Tick
+
+
+
+ :/icons/arrowtick.svg
+
+
+
+ -
+
+ 3 - Dot
+
+
+
+ :/icons/arrowdot.svg
+
+
+
+ -
+
+ 4 - Open Circle
+
+
+
+ :/icons/arrowopendot.svg
+
+
+
+
+
+ -
+
+
+ Arrow Size
+
+
+
+ -
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
+
+ 5.000000000000000
+
+
+ ArrowSize
+
+
+ Mod/TechDraw/Dimensions
+
+
+
-
@@ -151,7 +289,7 @@
-
-
+
-
@@ -341,82 +479,6 @@
-
-
-
- Arrow Style
-
-
-
- -
-
-
- Preferred arrowhead style
-
-
- 0
-
-
- 5
-
-
- ArrowStyle
-
-
- Mod/TechDraw/Decorations
-
-
-
-
- 0 - Filled Triangle
-
-
-
- :/icons/arrowfilled.svg
-
-
-
- -
-
- 1 - Open Arrowhead
-
-
-
- :/icons/arrowopen.svg
-
-
-
- -
-
- 2 - Tick
-
-
-
- :/icons/arrowtick.svg
-
-
-
- -
-
- 3 - Dot
-
-
-
- :/icons/arrowdot.svg
-
-
-
- -
-
- 4 - Open Circle
-
-
-
- :/icons/arrowopendot.svg
-
-
-
-
-
- -
Default weight for GeomHatch lines
@@ -426,7 +488,7 @@
- -
+
-
Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
@@ -460,19 +522,6 @@
- -
-
-
- Qt::Vertical
-
-
-
- 20
- 40
-
-
-
-
@@ -481,6 +530,11 @@
QPushButton
+
+ Gui::PrefSpinBox
+ QSpinBox
+
+
Gui::PrefColorButton
Gui::ColorButton
diff --git a/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2Imp.cpp b/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2Imp.cpp
index b34d35526c..14c5273007 100644
--- a/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2Imp.cpp
+++ b/src/Mod/TechDraw/Gui/DlgPrefsTechDraw2Imp.cpp
@@ -53,6 +53,9 @@ void DlgPrefsTechDraw2Imp::saveSettings()
pcbSectionStyle->onSave();
colSectionLine->onSave();
pcbArrow->onSave();
+ cbGlobalDecimals->onSave();
+ sbAltDecimals->onSave();
+ dsbArrowSize->onSave();
}
void DlgPrefsTechDraw2Imp::loadSettings()
@@ -67,6 +70,9 @@ void DlgPrefsTechDraw2Imp::loadSettings()
pcbSectionStyle->onRestore();
colSectionLine->onRestore();
pcbArrow->onRestore();
+ cbGlobalDecimals->onRestore();
+ sbAltDecimals->onRestore();
+ dsbArrowSize->onRestore();
}
/**
diff --git a/src/Mod/TechDraw/Gui/QGIArrow.cpp b/src/Mod/TechDraw/Gui/QGIArrow.cpp
index 1d5037f120..0a6db47d00 100644
--- a/src/Mod/TechDraw/Gui/QGIArrow.cpp
+++ b/src/Mod/TechDraw/Gui/QGIArrow.cpp
@@ -154,11 +154,21 @@ QPainterPath QGIArrow::makeOpenDot(double length, double width, bool flipped)
int QGIArrow::getPrefArrowStyle()
{
Base::Reference hGrp = App::GetApplication().GetUserParameter().
- GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Decorations");
+ GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions");
int style = hGrp->GetInt("ArrowStyle", 0);
return style;
}
+double QGIArrow::getPrefArrowSize()
+{
+ Base::Reference hGrp = App::GetApplication().GetUserParameter().
+ GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions");
+ double style = hGrp->GetFloat("ArrowSize", 5.0);
+ return style;
+}
+
+
+
void QGIArrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QStyleOptionGraphicsItem myOption(*option);
diff --git a/src/Mod/TechDraw/Gui/QGIArrow.h b/src/Mod/TechDraw/Gui/QGIArrow.h
index f3f6764067..cfe1e2542c 100644
--- a/src/Mod/TechDraw/Gui/QGIArrow.h
+++ b/src/Mod/TechDraw/Gui/QGIArrow.h
@@ -50,6 +50,7 @@ public:
int getStyle() { return m_style; }
void setStyle(int s) { m_style = s; }
static int getPrefArrowStyle();
+ static double getPrefArrowSize();
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );
diff --git a/src/Mod/TechDraw/Gui/QGIViewDimension.cpp b/src/Mod/TechDraw/Gui/QGIViewDimension.cpp
index 4638c3458f..f23a4edf3e 100644
--- a/src/Mod/TechDraw/Gui/QGIViewDimension.cpp
+++ b/src/Mod/TechDraw/Gui/QGIViewDimension.cpp
@@ -612,9 +612,11 @@ void QGIViewDimension::draw()
datumLabel->setRotation((angle * 180 / M_PI) + angleOption);
aHead1->setStyle(QGIArrow::getPrefArrowStyle());
+ aHead1->setSize(QGIArrow::getPrefArrowSize());
aHead1->draw();
aHead2->flip(true);
aHead2->setStyle(QGIArrow::getPrefArrowStyle());
+ aHead2->setSize(QGIArrow::getPrefArrowSize());
aHead2->draw();
angle = atan2f(dir.y,dir.x);
float arrowAngle = angle * 180 / M_PI;
@@ -827,12 +829,12 @@ void QGIViewDimension::draw()
path.lineTo(arrow2Tip.x, arrow2Tip.y);
}
-
-
aHead1->setStyle(QGIArrow::getPrefArrowStyle());
+ aHead1->setSize(QGIArrow::getPrefArrowSize());
aHead1->draw();
aHead2->flip(true);
aHead2->setStyle(QGIArrow::getPrefArrowStyle());
+ aHead2->setSize(QGIArrow::getPrefArrowSize());
aHead2->draw();
float arAngle = atan2(dirDimLine.y, dirDimLine.x) * 180 / M_PI;
@@ -1062,6 +1064,7 @@ void QGIViewDimension::draw()
dimLines->setPath(dLinePath);
aHead1->setStyle(QGIArrow::getPrefArrowStyle());
+ aHead1->setSize(QGIArrow::getPrefArrowSize());
aHead1->draw();
Base::Vector3d ar1Pos = pointOnCurve;
@@ -1259,8 +1262,10 @@ void QGIViewDimension::draw()
aHead1->flip(true);
aHead1->setStyle(QGIArrow::getPrefArrowStyle());
+ aHead1->setSize(QGIArrow::getPrefArrowSize());
aHead1->draw();
aHead2->setStyle(QGIArrow::getPrefArrowStyle());
+ aHead2->setSize(QGIArrow::getPrefArrowSize());
aHead2->draw();
Base::Vector3d norm1 = p1-p0; //(-dir1.y, dir1.x, 0.);