Skip to content

Commit

Permalink
[TD] Use PropertyLength for LineWidths
Browse files Browse the repository at this point in the history
- contributed by @uwe

- also assure that the LineStyle is restricted to the range 0-5

fix another conversion routine mistake
  • Loading branch information
donovaly authored and WandererFan committed Jan 27, 2020
1 parent 0e015da commit 338774d
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 28 deletions.
22 changes: 16 additions & 6 deletions src/Mod/TechDraw/Gui/ViewProviderBalloon.cpp
Expand Up @@ -71,17 +71,15 @@ ViewProviderBalloon::ViewProviderBalloon()
hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions");
double fontSize = hGrp->GetFloat("FontSize", QGIView::DefaultFontSizeInMM);
ADD_PROPERTY_TYPE(Font ,(fontName.c_str()),group,App::Prop_None, "The name of the font to use");
ADD_PROPERTY_TYPE(Fontsize,(fontSize) ,group,(App::PropertyType)(App::Prop_None),"Dimension text size in units");


ADD_PROPERTY_TYPE(Font,(fontName.c_str()),group,App::Prop_None, "The name of the font to use");
ADD_PROPERTY_TYPE(Fontsize,(fontSize),group,(App::PropertyType)(App::Prop_None),"Dimension text size in units");

hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Decorations");
std::string lgName = hGrp->GetASCII("LineGroup","FC 0.70mm");
auto lg = TechDraw::LineGroup::lineGroupFactory(lgName);
double weight = lg->getWeight("Thin");
delete lg; //Coverity CID 174670
ADD_PROPERTY_TYPE(LineWidth,(weight) ,group,(App::PropertyType)(App::Prop_None),"Dimension line weight");

ADD_PROPERTY_TYPE(LineWidth,(weight),group,(App::PropertyType)(App::Prop_None),"Balloon line width");

hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions");
Expand Down Expand Up @@ -170,3 +168,15 @@ TechDraw::DrawViewBalloon* ViewProviderBalloon::getViewObject() const
{
return dynamic_cast<TechDraw::DrawViewBalloon*>(pcObject);
}

void ViewProviderBalloon::handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property *prop)
// transforms properties that had been changed
{
// property LineWidth had the App::PropertyFloat and was changed to App::PropertyLength
if (prop == &LineWidth && strcmp(TypeName, "App::PropertyFloat") == 0) {
App::PropertyFloat LineWidthProperty;
// restore the PropertyFloat to be able to set its value
LineWidthProperty.Restore(reader);
LineWidth.setValue(LineWidthProperty.getValue());
}
}
13 changes: 8 additions & 5 deletions src/Mod/TechDraw/Gui/ViewProviderBalloon.h
Expand Up @@ -45,11 +45,10 @@ class TechDrawGuiExport ViewProviderBalloon : public ViewProviderDrawingView
/// destructor
virtual ~ViewProviderBalloon();

App::PropertyFont Font;
App::PropertyLength Fontsize;
App::PropertyFloat LineWidth;
App::PropertyColor Color;

App::PropertyFont Font;
App::PropertyLength Fontsize;
App::PropertyLength LineWidth;
App::PropertyColor Color;

virtual void attach(App::DocumentObject *);
virtual void setDisplayMode(const char* ModeName);
Expand All @@ -63,6 +62,10 @@ class TechDrawGuiExport ViewProviderBalloon : public ViewProviderDrawingView
virtual bool doubleClicked(void);

virtual TechDraw::DrawViewBalloon* getViewObject() const;

protected:
virtual void handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property * prop);

};

} // namespace TechDrawGui
Expand Down
14 changes: 13 additions & 1 deletion src/Mod/TechDraw/Gui/ViewProviderDimension.cpp
Expand Up @@ -67,7 +67,7 @@ ViewProviderDimension::ViewProviderDimension()
ADD_PROPERTY_TYPE(Fontsize, (prefFontSize()), group, (App::PropertyType)(App::Prop_None),
"Dimension text size in units");
ADD_PROPERTY_TYPE(LineWidth, (prefWeight()), group, (App::PropertyType)(App::Prop_None),
"Dimension line weight");
"Dimension line width");
ADD_PROPERTY_TYPE(Color,(prefColor()),group,App::Prop_None,"The color of the Dimension");
ADD_PROPERTY_TYPE(StandardAndStyle, (prefStandardAndStyle()), group, App::Prop_None,
"Specifies the standard according to which this dimension is drawn");
Expand Down Expand Up @@ -203,3 +203,15 @@ int ViewProviderDimension::prefStandardAndStyle() const
int standardStyle = hGrp->GetInt("StandardAndStyle", STD_STYLE_ISO_ORIENTED);
return standardStyle;
}

void ViewProviderDimension::handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property *prop)
// transforms properties that had been changed
{
// property LineWidth had the App::PropertyFloat and was changed to App::PropertyLength
if (prop == &LineWidth && strcmp(TypeName, "App::PropertyFloat") == 0) {
App::PropertyFloat LineWidthProperty;
// restore the PropertyFloat to be able to set its value
LineWidthProperty.Restore(reader);
LineWidth.setValue(LineWidthProperty.getValue());
}
}
14 changes: 8 additions & 6 deletions src/Mod/TechDraw/Gui/ViewProviderDimension.h
@@ -1,5 +1,5 @@
/***************************************************************************
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
* Copyright (c) 2012 Luke Parry <l.parry@warwick.ac.uk> *
* *
* This file is part of the FreeCAD CAx development system. *
Expand Down Expand Up @@ -44,10 +44,10 @@ class TechDrawGuiExport ViewProviderDimension : public ViewProviderDrawingView
/// destructor
virtual ~ViewProviderDimension();

App::PropertyFont Font;
App::PropertyLength Fontsize;
App::PropertyFloat LineWidth;
App::PropertyColor Color;
App::PropertyFont Font;
App::PropertyLength Fontsize;
App::PropertyLength LineWidth;
App::PropertyColor Color;

static const int STD_STYLE_ISO_ORIENTED = 0;
static const int STD_STYLE_ISO_REFERENCING = 1;
Expand Down Expand Up @@ -81,8 +81,10 @@ class TechDrawGuiExport ViewProviderDimension : public ViewProviderDrawingView
double prefWeight() const;
int prefStandardAndStyle() const;

private:
protected:
virtual void handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property * prop);

private:
static const char *StandardAndStyleEnums[];
static const char *RenderingExtentEnums[];

Expand Down
28 changes: 26 additions & 2 deletions src/Mod/TechDraw/Gui/ViewProviderLeader.cpp
Expand Up @@ -59,6 +59,9 @@

using namespace TechDrawGui;

// there are only 5 line styles
App::PropertyIntegerConstraint::Constraints ViewProviderLeader::LineStyleRange = { 0, 5, 1 };

PROPERTY_SOURCE(TechDrawGui::ViewProviderLeader, TechDrawGui::ViewProviderDrawingView)

//**************************************************************************
Expand All @@ -70,9 +73,11 @@ ViewProviderLeader::ViewProviderLeader()

static const char *group = "Line Format";

ADD_PROPERTY_TYPE(LineWidth,(getDefLineWeight()) ,group,(App::PropertyType)(App::Prop_None),"Line weight");
ADD_PROPERTY_TYPE(LineStyle,(1) ,group,(App::PropertyType)(App::Prop_None),"Line style");
ADD_PROPERTY_TYPE(LineWidth,(getDefLineWeight()),group,(App::PropertyType)(App::Prop_None),"Line width");
ADD_PROPERTY_TYPE(LineStyle,(1),group,(App::PropertyType)(App::Prop_None),"Line style");
ADD_PROPERTY_TYPE(Color,(getDefLineColor()),group,App::Prop_None,"The color of the Markup");

LineStyle.setConstraints(&LineStyleRange);
}

ViewProviderLeader::~ViewProviderLeader()
Expand Down Expand Up @@ -204,4 +209,23 @@ App::Color ViewProviderLeader::getDefLineColor(void)
return result;
}

void ViewProviderLeader::handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property *prop)
// transforms properties that had been changed
{
// property LineWidth had the App::PropertyFloat and was changed to App::PropertyLength
if (prop == &LineWidth && strcmp(TypeName, "App::PropertyFloat") == 0) {
App::PropertyFloat LineWidthProperty;
// restore the PropertyFloat to be able to set its value
LineWidthProperty.Restore(reader);
LineWidth.setValue(LineWidthProperty.getValue());
}

// property LineStyle had the App::PropertyInteger and was changed to App::PropertyIntegerConstraint
if (prop == &LineStyle && strcmp(TypeName, "App::PropertyInteger") == 0) {
App::PropertyInteger LineStyleProperty;
// restore the PropertyInteger to be able to set its value
LineStyleProperty.Restore(reader);
LineStyle.setValue(LineStyleProperty.getValue());
}
}

11 changes: 8 additions & 3 deletions src/Mod/TechDraw/Gui/ViewProviderLeader.h
Expand Up @@ -48,9 +48,9 @@ class TechDrawGuiExport ViewProviderLeader : public ViewProviderDrawingView
/// destructor
virtual ~ViewProviderLeader();

App::PropertyFloat LineWidth;
App::PropertyInteger LineStyle;
App::PropertyColor Color;
App::PropertyLength LineWidth;
App::PropertyIntegerConstraint LineStyle;
App::PropertyColor Color;

virtual void attach(App::DocumentObject *);
/* virtual void setDisplayMode(const char* ModeName);*/
Expand All @@ -70,6 +70,11 @@ class TechDrawGuiExport ViewProviderLeader : public ViewProviderDrawingView
protected:
double getDefLineWeight(void);
App::Color getDefLineColor(void);
virtual void handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property * prop);

private:
static App::PropertyIntegerConstraint::Constraints LineStyleRange;

};

} // namespace TechDrawGui
Expand Down
28 changes: 26 additions & 2 deletions src/Mod/TechDraw/Gui/ViewProviderRichAnno.cpp
Expand Up @@ -57,6 +57,9 @@

using namespace TechDrawGui;

// there are only 5 frame line styles
App::PropertyIntegerConstraint::Constraints ViewProviderRichAnno::LineStyleRange = {0, 5, 1};

PROPERTY_SOURCE(TechDrawGui::ViewProviderRichAnno, TechDrawGui::ViewProviderDrawingView)

//**************************************************************************
Expand All @@ -68,9 +71,11 @@ ViewProviderRichAnno::ViewProviderRichAnno()

static const char *group = "Frame Format";

ADD_PROPERTY_TYPE(LineWidth,(getDefLineWeight()), group,(App::PropertyType)(App::Prop_None),"Frame line weight");
ADD_PROPERTY_TYPE(LineStyle,(1), group,(App::PropertyType)(App::Prop_None),"Frame line style");
ADD_PROPERTY_TYPE(LineWidth,(getDefLineWeight()), group,(App::PropertyType)(App::Prop_None),"Frame line width");
ADD_PROPERTY_TYPE(LineStyle,(1),group,(App::PropertyType)(App::Prop_None),"Frame line style");
ADD_PROPERTY_TYPE(LineColor,(getDefLineColor()),group,App::Prop_None,"The color of the frame");

LineStyle.setConstraints(&LineStyleRange);
}

ViewProviderRichAnno::~ViewProviderRichAnno()
Expand Down Expand Up @@ -175,4 +180,23 @@ double ViewProviderRichAnno::getDefLineWeight(void)
return result;
}

void ViewProviderRichAnno::handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property *prop)
// transforms properties that had been changed
{
// property LineWidth had the App::PropertyFloat and was changed to App::PropertyLength
if (prop == &LineWidth && strcmp(TypeName, "App::PropertyFloat") == 0) {
App::PropertyFloat LineWidthProperty;
// restore the PropertyFloat to be able to set its value
LineWidthProperty.Restore(reader);
LineWidth.setValue(LineWidthProperty.getValue());
}

// property LineStyle had the App::PropertyInteger and was changed to App::PropertyIntegerConstraint
if (prop == &LineStyle && strcmp(TypeName, "App::PropertyInteger") == 0) {
App::PropertyInteger LineStyleProperty;
// restore the PropertyInteger to be able to set its value
LineStyleProperty.Restore(reader);
LineStyle.setValue(LineStyleProperty.getValue());
}
}

10 changes: 7 additions & 3 deletions src/Mod/TechDraw/Gui/ViewProviderRichAnno.h
Expand Up @@ -47,9 +47,9 @@ class TechDrawGuiExport ViewProviderRichAnno : public ViewProviderDrawingView
/// destructor
virtual ~ViewProviderRichAnno();

App::PropertyFloat LineWidth;
App::PropertyInteger LineStyle;
App::PropertyColor LineColor;
App::PropertyLength LineWidth;
App::PropertyIntegerConstraint LineStyle;
App::PropertyColor LineColor;

virtual void attach(App::DocumentObject *);
virtual bool useNewSelectionModel(void) const {return false;}
Expand All @@ -67,6 +67,10 @@ class TechDrawGuiExport ViewProviderRichAnno : public ViewProviderDrawingView
std::string getDefFont(void);
double getDefFontSize(void);
double getDefLineWeight(void);
virtual void handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property * prop);

private:
static App::PropertyIntegerConstraint::Constraints LineStyleRange;


};
Expand Down

0 comments on commit 338774d

Please sign in to comment.