Annotation styles for Draft

A forum dedicated to the Draft, Arch and BIM workbenches development.
carlopav
Posts: 1570
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Annotation styles for Draft

Postby carlopav » Tue Mar 10, 2020 3:36 pm

I was thinking about annotations: the properties for label, text, dimensions, are set in preferences, but many times while drafting the user needs to switch froma a text style to another.
So I was thinking about creating a dimension style property, something like Assembly 4 variables, where we can store the dimension style properties. When user duble click it, it set's the annotation parameters according to stored values, so next created annotation will match its properties.
What do you think?
follow my experiments on BIM modelling for architecture design
fc_tofu
Posts: 654
Joined: Sun Jan 05, 2020 4:56 pm

Re: Annotation styles for Draft

Postby fc_tofu » Tue Mar 10, 2020 6:38 pm

carlopav wrote:
Tue Mar 10, 2020 3:36 pm
I was thinking about annotations: the properties for label, text, dimensions, are set in preferences, but many times while drafting the user needs to switch froma a text style to another.
So I was thinking about creating a dimension style property, something like Assembly 4 variables, where we can store the dimension style properties. When user duble click it, it set's the annotation parameters according to stored values, so next created annotation will match its properties.
What do you think?
Generally, I think we need something like Blender "Startup File" or Rhino "Document Properties" in template.
Some settings are better to be saved in project file (user doc) than in app pref (FreeCAD way).
And startup file/template is the place to store default values of doc-related settings.
User avatar
Roy_043
Posts: 2081
Joined: Thu Dec 27, 2018 12:28 pm

Re: Annotation styles for Draft

Postby Roy_043 » Tue Mar 10, 2020 6:53 pm

carlopav wrote:
Tue Mar 10, 2020 3:36 pm
so next created annotation will match its properties.
I think there should be a permanent link between the style and the annotation object. Changing the style should update all objects created with that style.

You could consider something similar to a Draft_VisGroup, where the group controls the properties of the nested elements. This could maybe even become a more generic thing: Std_PropGroup?
carlopav
Posts: 1570
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: Annotation styles for Draft

Postby carlopav » Tue Mar 10, 2020 7:55 pm

@fc_tofu
I was thinking about an object exactly because I think annotation style should be saved inside the document.

@roy
I agree we could have a style property in annotations object. But I don't like the style to be a container. We can eventually imagine a command to apply the changed style to all the linked dimensions without having to see them grouped in the tree... Isn't it?
follow my experiments on BIM modelling for architecture design
User avatar
Roy_043
Posts: 2081
Joined: Thu Dec 27, 2018 12:28 pm

Re: Annotation styles for Draft

Postby Roy_043 » Tue Mar 10, 2020 9:11 pm

I agree, not having to group the elements would be more flexible.
carlopav
Posts: 1570
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: Annotation styles for Draft

Postby carlopav » Thu Mar 12, 2020 3:01 pm

Perhaps could be something like this:

Code: Select all

def makeDimensionStyle(existing_dimension = None):
    """
	
    """
    if not FreeCAD.ActiveDocument:
        FreeCAD.Console.PrintError("No active document. Aborting\n")
        return
    obj = FreeCAD.ActiveDocument.addObject("App::FeaturePython","DimensionStyle")
    ViewProviderDraftDimensionStyle(obj.ViewObject, existing_dimension)
    if gui:
        formatObject(obj)
        select(obj)
    return obj


class ViewProviderDraftDimensionStyle(_ViewProviderDraft):
    def __init__(self, obj, existing_dimension = None): 
        param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
        annotation_scale = param.GetFloat("DraftAnnotationScale", 1.0)

        # annotation properties
        obj.addProperty("App::PropertyFloat","ScaleMultiplier",
                        "Annotation",QT_TRANSLATE_NOOP("App::Property",
                        "Dimension size overall multiplier")
                        ).ScaleMultiplier = 1 / annotation_scale

        # text properties
        obj.addProperty("App::PropertyFont","FontName",
                        "Text",QT_TRANSLATE_NOOP("App::Property","Font name")
                        ).FontName = getParam("textfont","")

        obj.addProperty("App::PropertyLength","FontSize",
                        "Text",QT_TRANSLATE_NOOP("App::Property","Font size")
                        ).FontSize = getParam("textheight",0.20)

        obj.addProperty("App::PropertyLength","TextSpacing",
                        "Text",QT_TRANSLATE_NOOP("App::Property",
                        "The spacing between the text and the dimension line")
                        ).TextSpacing = getParam("dimspacing",0.05)

        obj.addProperty("App::PropertyBool","FlipText",
                        "Text",QT_TRANSLATE_NOOP("App::Property",
                        "Rotate the dimension text 180 degrees")
                        )

        obj.addProperty("App::PropertyVectorDistance","TextPosition",
                        "Text",QT_TRANSLATE_NOOP("App::Property",
                        "The position of the text. Leave (0,0,0) for automatic position")
                        )

        obj.addProperty("App::PropertyString","Override",
                        "Text",QT_TRANSLATE_NOOP("App::Property",
                        "Text override. Use $dim to insert the dimension length")
                        )

        # units properties
        obj.addProperty("App::PropertyInteger","Decimals",
                        "Units",QT_TRANSLATE_NOOP("App::Property",
                        "The number of decimals to show")
                        ).Decimals = getParam("dimPrecision",2)

        obj.addProperty("App::PropertyBool","ShowUnit",
                        "Units",QT_TRANSLATE_NOOP("App::Property",
                        "Show the unit suffix")
                        ).ShowUnit = getParam("showUnit",True)

        obj.addProperty("App::PropertyString","UnitOverride",
                        "Units",QT_TRANSLATE_NOOP("App::Property",
                        "A unit to express the measurement. Leave blank for system default")
                        )

        # graphics properties
        obj.addProperty("App::PropertyFloat","LineWidth",
                        "Graphics",QT_TRANSLATE_NOOP("App::Property","Line width")
                        )

        obj.addProperty("App::PropertyColor","LineColor",
                        "Graphics",QT_TRANSLATE_NOOP("App::Property","Line color")
                        )

        obj.addProperty("App::PropertyLength","ArrowSize",
                        "Graphics",QT_TRANSLATE_NOOP("App::Property","Arrow size")
                        ).ArrowSize = getParam("arrowsize",0.1)

        obj.addProperty("App::PropertyEnumeration","ArrowType",
                        "Graphics",QT_TRANSLATE_NOOP("App::Property","Arrow type")
                        ).ArrowType = arrowtypes
        obj.ArrowType = arrowtypes[getParam("dimsymbol",0)]

        obj.addProperty("App::PropertyBool","FlipArrows",
                        "Graphics",QT_TRANSLATE_NOOP("App::Property",
                        "Rotate the dimension arrows 180 degrees")
                        )

        obj.addProperty("App::PropertyDistance","DimOvershoot",
                        "Graphics",QT_TRANSLATE_NOOP("App::Property",
                        "The distance the dimension line is extended past the extension lines")
                        ).DimOvershoot = getParam("dimovershoot",0)  

        obj.addProperty("App::PropertyDistance","ExtLines",
                        "Graphics",QT_TRANSLATE_NOOP("App::Property",
                        "Length of the extension lines")
                        ).ExtLines = getParam("extlines",0.3)

        obj.addProperty("App::PropertyDistance","ExtOvershoot",
                        "Graphics",QT_TRANSLATE_NOOP("App::Property",
                        "Length of the extension line above the dimension line")
                        ).ExtOvershoot = getParam("extovershoot",0)

        obj.addProperty("App::PropertyBool","ShowLine",
                        "Graphics",QT_TRANSLATE_NOOP("App::Property",
                        "Shows the dimension line and arrows")
                        ).ShowLine = True

        if existing_dimension:
            vobj = existing_dimension.ViewObject
            obj.ScaleMultiplier = vobj.ScaleMultiplier
            obj.FontSize = vobj.FontSize
            obj.TextSpacing = vobj.TextSpacing
            obj.FontName = vobj.FontName
            obj.ArrowSize = vobj.ArrowSize
            obj.ArrowType = vobj.ArrowType
            obj.ArrowType = vobj.ArrowType
            obj.ExtLines = vobj.ExtLines
            obj.DimOvershoot = vobj.DimOvershoot
            obj.ExtOvershoot = vobj.ExtOvershoot
            obj.Decimals = vobj.Decimals
            obj.ShowUnit = vobj.ShowUnit
            obj.ShowLine = vobj.ShowLine
            
        _ViewProviderDraft.__init__(self,obj)

    def doubleClicked(self,vobj):
        print("set current style")

    def setupContextMenu(self,vobj,menu):
        from PySide import QtCore,QtGui
        action1 = QtGui.QAction(QtGui.QIcon(":/icons/Draft_Edit.svg"),"Set current",menu)
        QtCore.QObject.connect(action1,QtCore.SIGNAL("triggered()"),self.set_current)
        menu.addAction(action1)
        action2 = QtGui.QAction(QtGui.QIcon(":/icons/Draft_Edit.svg"),"Apply",menu)
        QtCore.QObject.connect(action2,QtCore.SIGNAL("triggered()"),self.apply_to_related_dimensions)
        menu.addAction(action2)
        action3 = QtGui.QAction(QtGui.QIcon(":/icons/Draft_Edit.svg"),"Apply and override",menu)
        QtCore.QObject.connect(action3,QtCore.SIGNAL("triggered()"),self.override_related_dimensions)
        menu.addAction(action3)
    
    def set_current(self):
        """
        Sets the current dimension style as default for new created dimensions
        """
        pass

    def apply_to_related_dimensions(self):
        """
        Apply the style to the related dimensions
        """
        pass

    def override_related_dimensions(self):
        """
        Apply the style to the related dimensions and override eventually changed settings
        """
        pass
follow my experiments on BIM modelling for architecture design
carlopav
Posts: 1570
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: Annotation styles for Draft

Postby carlopav » Thu Mar 12, 2020 6:34 pm

I made a short recognitions of Draft parameters regarding annotations:

Code: Select all

        vobj properties         type                        parameter               type
        ----------------------------------------------------------------------------------
        vobj.ScaleMultiplier"   App::PropertyFloat          "DraftAnnotationScale"  Float

        vobj.FontName           App::PropertyFont           "textfont"              Text
        vobj.FontSize           App::PropertyLength         "textheight"            Float
        vobj.TextSpacing        App::PropertyLength         "dimspacing"            Float

        vobj.Decimals           App::PropertyInteger        "dimPrecision"          Integer
        vobj.ShowUnit           App::PropertyBool
        vobj.UnitOverride       App::PropertyString

        vobj.LineWidth          App::PropertyFloat
        vobj.LineColor          App::PropertyColor
        vobj.ArrowSize          App::PropertyLength         "arrowsize"             Float
        vobj.ArrowType          App::PropertyEnumeration    "dimsymbol"             Integer
        vobj.FlipArrows         App::PropertyBool
        vobj.DimOvershoot       App::PropertyDistance       "dimovershoot"          Float
        vobj.ExtLines           App::PropertyDistance       "extlines"              Float
        vobj.ExtOvershoot       App::PropertyDistance       "extovershoot"          Float
        vobj.ShowLine           App::PropertyBool
Several properties are not stored in preferences, and would be useful:
ShowLine, ShowUnit, LineWidth, LineColor

What about placing new dimension parameters in a dedicated folder "User parameter:BaseApp/Preferences/Mod/Draft/Annotations"?
follow my experiments on BIM modelling for architecture design
carlopav
Posts: 1570
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: Annotation styles for Draft

Postby carlopav » Thu Mar 12, 2020 9:37 pm

a small mockup:
dimStyles.gif
dimStyles.gif (296.26 KiB) Viewed 1102 times
EDIT: this is the draft commit https://github.com/FreeCAD/FreeCAD/comm ... df229168dc

EDIT2: this would be the first step: the second would be to add a string property to the dimension object to link it to the DimensionStyle Label?
follow my experiments on BIM modelling for architecture design
vocx
Posts: 5206
Joined: Thu Oct 18, 2018 9:18 pm

Re: Annotation styles for Draft

Postby vocx » Fri Mar 13, 2020 6:22 am

carlopav wrote:
Thu Mar 12, 2020 9:37 pm
...
EDIT: this is the draft commit https://github.com/FreeCAD/FreeCAD/comm ... df229168dc
...
Tons of comments from me in that commit.

By the way, I now think we need an extra directory to put the "make_functions".

Code: Select all

draftmake/  # all those functions to make objects
draftobjects/  # the proxy classes that really define the properties of the objects
draftviewproviders/  # the corresponding view provider classes for the above objects
draftguitools/  # the GuiCommands (buttons, menus)
drafttaskpanels/  # the task panel code for the GuiCommands
The idea is that a make_function imports the appropriate classes from draftobjects/ and draftviewproviders/.

Code: Select all

# Inside draftmake/make_someobject.py

import FreeCAD as App
from draftobjects.someobject import SomeObject
from draftviewproviders.view_someobject import ViewProviderSomeObject

def make_some_object(arg1, arg2, ...):
    obj = App.ActiveDocument.addObject("App::FeaturePython", "SomeObject")
    SomeObject(obj)
    if App.GuiUp:
        ViewProviderSomeObject(obj.ViewObject)
I think this is what makes the most sense, and would result in neatly organized code.

I will try to do this for the new array commands, but that will take some time because there are still many pull requests pending.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
carlopav
Posts: 1570
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: Annotation styles for Draft

Postby carlopav » Fri Mar 13, 2020 7:33 am

Wow, thanks so much for reviewing. I agree to every comment, some changes were already planned but I wanted to setup a prototype before refining the code.
So, code apart, you would agree on a style object for annotations to be guarded in the document?
And what about adding more parameters to handle also dimensions color, lineweight and preferred unit?

EDIT: I was thinkig about a style group, something like the (high detested :twisted: ) new layer object to keep all the properties tidy:

Code: Select all

Draft Styles
	|---- Objects
	|	|---- Construction
	|	|---- Section
	|	|---- View
	|	|---- Hidden
	|---- Annotation Styles
		|---- Dimensions Styles
		|	|---- DimensionsStyles1
		|	|---- DimensionsStyles2
		|	|---- DimensionsStyles3
		|---- Label Styles
		|	|---- Room Labels
		|---- Text Styles
			|---- Bold
			|---- Romans
		
EDIT:
vocx wrote:
Fri Mar 13, 2020 6:22 am
By the way, I now think we need an extra directory to put the "make_functions".
+1, since we are splitting, let's split to the end

EDIT3: https://github.com/carlopav/FreeCAD/com ... ed276e2b24 this is the updated commit with the cleanup. I still want to add the changes to the dimension object to be able to point to the style, and then we can think about merging it into the PR of Draft Annotation Scales.
follow my experiments on BIM modelling for architecture design