diff --git a/src/Mod/Draft/Draft.py b/src/Mod/Draft/Draft.py index 6c5145049a..f8360a0aa0 100644 --- a/src/Mod/Draft/Draft.py +++ b/src/Mod/Draft/Draft.py @@ -92,7 +92,8 @@ from draftutils.utils import (string_encode_coin, get_rgb, getrgb, argb_to_rgba, - rgba_to_argb) + rgba_to_argb, + get_rgba_tuple) from draftfunctions.svg import (get_svg, getSVG) diff --git a/src/Mod/Draft/draftguitools/gui_snapper.py b/src/Mod/Draft/draftguitools/gui_snapper.py index f6233b3211..925253f81b 100644 --- a/src/Mod/Draft/draftguitools/gui_snapper.py +++ b/src/Mod/Draft/draftguitools/gui_snapper.py @@ -329,7 +329,7 @@ class Snapper: fp = self.cstr(lastpoint, constrain, point) if self.trackLine and lastpoint and (not noTracker): self.trackLine.p2(fp) - self.trackLine.color.rgb = Gui.draftToolBar.getDefaultColor("line") + self.trackLine.setColor() self.trackLine.on() # Set the arch point tracking if lastpoint: @@ -499,7 +499,7 @@ class Snapper: fp = self.cstr(lastpoint, constrain, winner[2]) if self.trackLine and lastpoint: self.trackLine.p2(fp) - self.trackLine.color.rgb = Gui.draftToolBar.getDefaultColor("line") + self.trackLine.setColor() self.trackLine.on() # set the cursor self.setCursor(winner[1]) @@ -559,7 +559,7 @@ class Snapper: if self.extLine: self.extLine.p1(tsnap[0]) self.extLine.p2(tsnap[2]) - self.extLine.color.rgb = Gui.draftToolBar.getDefaultColor("line") + self.extLine.setColor() self.extLine.on() self.setCursor(tsnap[1]) return tsnap[2], eline @@ -573,7 +573,7 @@ class Snapper: self.tracker.on() if self.extLine: self.extLine.p2(tsnap[2]) - self.extLine.color.rgb = Gui.draftToolBar.getDefaultColor("line") + self.extLine.setColor() self.extLine.on() self.setCursor(tsnap[1]) return tsnap[2], eline @@ -587,7 +587,7 @@ class Snapper: self.tracker.on() if self.extLine: self.extLine.p2(tsnap[2]) - self.extLine.color.rgb = Gui.draftToolBar.getDefaultColor("line") + self.extLine.setColor() self.extLine.on() self.setCursor(tsnap[1]) return tsnap[2], eline @@ -623,13 +623,9 @@ class Snapper: self.tracker.setMarker(self.mk['extension']) self.tracker.on() if self.extLine: - if self.snapStyle: - dv = np.sub(p0) - self.extLine.p1(p0.add(dv.multiply(0.5))) - else: - self.extLine.p1(p0) + self.extLine.p1(p0) self.extLine.p2(np) - self.extLine.color.rgb = Gui.draftToolBar.getDefaultColor("line") + self.extLine.setColor() self.extLine.on() self.setCursor('extension') ne = Part.LineSegment(p0,np).toShape() @@ -681,14 +677,10 @@ class Snapper: p0 = self.lastExtensions[1].Vertexes[0].Point else: p0 = self.lastExtensions[0].Vertexes[0].Point - if self.snapStyle: - dv = p.sub(p0) - self.extLine2.p1(p0.add(dv.multiply(0.5))) - else: - self.extLine2.p1(p0) + self.extLine2.p1(p0) self.extLine2.p2(p) self.extLine.p2(p) - self.extLine.color.rgb = Gui.draftToolBar.getDefaultColor("line") + self.extLine.setColor() self.extLine2.on() return p return None @@ -1283,10 +1275,7 @@ class Snapper: # setup trackers if needed if not self.constrainLine: - if self.snapStyle: - self.constrainLine = trackers.lineTracker(scolor=Gui.draftToolBar.getDefaultColor("snap")) - else: - self.constrainLine = trackers.lineTracker(dotted=True) + self.constrainLine = trackers.lineTracker(dotted=True) # setting basepoint if not basepoint: @@ -1612,13 +1601,8 @@ class Snapper: self.grid.show_during_command = True self.tracker = trackers.snapTracker() self.trackLine = trackers.lineTracker() - if self.snapStyle: - c = Gui.draftToolBar.getDefaultColor("snap") - self.extLine = trackers.lineTracker(scolor=c) - self.extLine2 = trackers.lineTracker(scolor=c) - else: - self.extLine = trackers.lineTracker(dotted=True) - self.extLine2 = trackers.lineTracker(dotted=True) + self.extLine = trackers.lineTracker(dotted=True) + self.extLine2 = trackers.lineTracker(dotted=True) self.radiusTracker = trackers.radiusTracker() self.dim1 = trackers.archDimTracker(mode=2) self.dim2 = trackers.archDimTracker(mode=3) @@ -1652,7 +1636,7 @@ class Snapper: if self.spoint and self.spoint not in self.holdPoints: if self.holdTracker: self.holdTracker.addCoords(self.spoint) - self.holdTracker.color.rgb = Gui.draftToolBar.getDefaultColor("line") + self.holdTracker.setColor() self.holdTracker.on() self.holdPoints.append(self.spoint) diff --git a/src/Mod/Draft/draftguitools/gui_trackers.py b/src/Mod/Draft/draftguitools/gui_trackers.py index fb9a08aa6e..016996b441 100644 --- a/src/Mod/Draft/draftguitools/gui_trackers.py +++ b/src/Mod/Draft/draftguitools/gui_trackers.py @@ -44,6 +44,7 @@ import Draft import DraftVecUtils from FreeCAD import Vector +from draftutils import utils from draftutils.todo import ToDo from draftutils.messages import _msg @@ -62,7 +63,6 @@ class Tracker: import DraftGeomUtils self.ontop = ontop self.color = coin.SoBaseColor() - self.color.rgb = scolor or FreeCADGui.draftToolBar.getDefaultColor("line") drawstyle = coin.SoDrawStyle() if swidth: drawstyle.lineWidth = swidth @@ -78,6 +78,7 @@ class Tracker: self.switch.setName(name) self.switch.addChild(node) self.switch.whichChild = -1 + self.setColor(scolor) self.Visible = False ToDo.delay(self._insertSwitch, self.switch) @@ -140,6 +141,18 @@ class Tracker: sg.removeChild(self.switch) sg.insertChild(self.switch, 0) + def setColor(self, color=None): + """Set the color.""" + if color is not None: + self.color.rgb = color + elif hasattr(FreeCAD, "activeDraftCommand") \ + and FreeCAD.activeDraftCommand is not None \ + and FreeCAD.activeDraftCommand.featureName in ("Dimension", "Label", "Text"): + color = utils.get_rgba_tuple(utils.get_param("DefaultAnnoLineColor", 255))[:3] + self.color.rgb = color + else: + self.color.rgb = FreeCADGui.draftToolBar.getDefaultColor("line") + def _get_wp(self): return FreeCAD.DraftWorkingPlane @@ -696,7 +709,7 @@ class ghostTracker(Tracker): self.children.append(rootsep) super().__init__(dotted, scolor, swidth, children=self.children, name="ghostTracker") - self.setColor() + self.setColor(scolor) def setColor(self, color=None): """Set the color.""" diff --git a/src/Mod/Draft/draftutils/gui_utils.py b/src/Mod/Draft/draftutils/gui_utils.py index 36c02b8d02..2625ce6004 100644 --- a/src/Mod/Draft/draftutils/gui_utils.py +++ b/src/Mod/Draft/draftutils/gui_utils.py @@ -436,94 +436,73 @@ def get_diffuse_color(objs): def format_object(target, origin=None): - """Apply visual properties from the Draft toolbar or another object. + """Apply visual properties to an object. - This function only works if the graphical interface is available - as the visual properties are attributes of the view provider - (`obj.ViewObject`). + This function only works if the graphical interface is available. + + If construction mode is active the `origin` argument is ignored. + The `target` is then placed in the construction group and the `constr` + color is applied to its applicable color properties: + `TextColor`, `PointColor`, `LineColor`, and `ShapeColor`. Parameters ---------- target: App::DocumentObject - Any type of scripted object. - - This object will adopt the applicable visual properties, - `FontSize`, `TextColor`, `LineWidth`, `PointColor`, `LineColor`, - and `ShapeColor`, defined in the Draft toolbar - (`Gui.draftToolBar`) or will adopt - the properties from the `origin` object. - - The `target` is also placed in the construction group - if the construction mode in the Draft toolbar is active. origin: App::DocumentObject, optional - It defaults to `None`. - If it exists, it will provide the visual properties to assign - to `target`, with the exception of `BoundingBox`, `Proxy`, - `RootNode` and `Visibility`. + Defaults to `None`. + If construction mode is not active, its visual properties are assigned + to `target`, with the exception of `BoundingBox`, `Proxy`, `RootNode` + and `Visibility`. """ if not target: return - obrep = target.ViewObject - if not obrep: + if not App.GuiUp: return - ui = None - if App.GuiUp: - if hasattr(Gui, "draftToolBar"): - ui = Gui.draftToolBar - if ui: + if not hasattr(Gui, "draftToolBar"): + return + if not hasattr(target, 'ViewObject'): + return + obrep = target.ViewObject + if Gui.draftToolBar.isConstructionMode(): doc = App.ActiveDocument - if ui.isConstructionMode(): - lcol = fcol = ui.getDefaultColor("constr") - tcol = lcol - fcol = lcol - grp = doc.getObject("Draft_Construction") - if not grp: - grp = doc.addObject("App::DocumentObjectGroup", "Draft_Construction") - grp.Label = utils.get_param("constructiongroupname", "Construction") - grp.addObject(target) - if hasattr(obrep, "Transparency"): - obrep.Transparency = 80 - else: - lcol = ui.getDefaultColor("line") - tcol = ui.getDefaultColor("text") - fcol = ui.getDefaultColor("face") - lcol = (float(lcol[0]), float(lcol[1]), float(lcol[2]), 0.0) - tcol = (float(tcol[0]), float(tcol[1]), float(tcol[2]), 0.0) - fcol = (float(fcol[0]), float(fcol[1]), float(fcol[2]), 0.0) - lw = utils.getParam("linewidth",2) - if not origin or not hasattr(origin, 'ViewObject'): - if "TextColor" in obrep.PropertiesList: - obrep.TextColor = tcol - if "LineWidth" in obrep.PropertiesList: - obrep.LineWidth = lw - if "PointColor" in obrep.PropertiesList: - obrep.PointColor = lcol - if "LineColor" in obrep.PropertiesList: - obrep.LineColor = lcol - if "ShapeColor" in obrep.PropertiesList: - obrep.ShapeColor = fcol - else: - matchrep = origin.ViewObject - for p in matchrep.PropertiesList: - if p not in ("DisplayMode", "BoundingBox", - "Proxy", "RootNode", "Visibility"): - if p in obrep.PropertiesList: - if not obrep.getEditorMode(p): - if hasattr(getattr(matchrep, p), "Value"): - val = getattr(matchrep, p).Value - else: - val = getattr(matchrep, p) - try: - setattr(obrep, p, val) - except Exception: - pass - if matchrep.DisplayMode in obrep.listDisplayModes(): - obrep.DisplayMode = matchrep.DisplayMode - if hasattr(obrep, "DiffuseColor"): - difcol = get_diffuse_color(origin) - if difcol: - obrep.DiffuseColor = difcol + col = Gui.draftToolBar.getDefaultColor("constr") + (0.0,) + grp = doc.getObject("Draft_Construction") + if not grp: + grp = doc.addObject("App::DocumentObjectGroup", "Draft_Construction") + grp.Label = utils.get_param("constructiongroupname", "Construction") + grp.addObject(target) + if "TextColor" in obrep.PropertiesList: + obrep.TextColor = col + if "PointColor" in obrep.PropertiesList: + obrep.PointColor = col + if "LineColor" in obrep.PropertiesList: + obrep.LineColor = col + if "ShapeColor" in obrep.PropertiesList: + obrep.ShapeColor = col + if hasattr(obrep, "Transparency"): + obrep.Transparency = 80 + elif origin and hasattr(origin, 'ViewObject'): + matchrep = origin.ViewObject + for p in matchrep.PropertiesList: + if p not in ("DisplayMode", "BoundingBox", + "Proxy", "RootNode", "Visibility"): + if p in obrep.PropertiesList: + if not obrep.getEditorMode(p): + if hasattr(getattr(matchrep, p), "Value"): + val = getattr(matchrep, p).Value + else: + val = getattr(matchrep, p) + try: + setattr(obrep, p, val) + except Exception: + pass + if matchrep.DisplayMode in obrep.listDisplayModes(): + obrep.DisplayMode = matchrep.DisplayMode + if hasattr(obrep, "DiffuseColor"): + difcol = get_diffuse_color(origin) + if difcol: + obrep.DiffuseColor = difcol formatObject = format_object diff --git a/src/Mod/Draft/draftutils/utils.py b/src/Mod/Draft/draftutils/utils.py index 285f0faa15..4b3580cd01 100644 --- a/src/Mod/Draft/draftutils/utils.py +++ b/src/Mod/Draft/draftutils/utils.py @@ -58,28 +58,27 @@ arrowtypes = ARROW_TYPES def get_default_annotation_style(): - param_draft = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft") - param_view = App.ParamGet("User parameter:BaseApp/Preferences/View") - anno_scale = param_draft.GetFloat("DraftAnnotationScale", 1) + param = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft") + anno_scale = param.GetFloat("DraftAnnotationScale", 1) scale_mult = 1 / anno_scale if anno_scale > 0 else 1 return { - "ArrowSize": ("float", param_draft.GetFloat("arrowsize", 20)), - "ArrowType": ("index", param_draft.GetInt("dimsymbol", 0)), - "Decimals": ("int", param_draft.GetInt("dimPrecision", 2)), - "DimOvershoot": ("float", param_draft.GetFloat("dimovershoot", 20)), - "ExtLines": ("float", param_draft.GetFloat("extlines", 300)), - "ExtOvershoot": ("float", param_draft.GetFloat("extovershoot", 20)), - "FontName": ("font", param_draft.GetString("textfont", "Sans")), - "FontSize": ("float", param_draft.GetFloat("textheight", 100)), - "LineColor": ("color", param_view.GetUnsigned("DefaultShapeLineColor", 255)), - "LineSpacing": ("float", param_draft.GetFloat("LineSpacing", 1)), - "LineWidth": ("int", param_view.GetInt("DefaultShapeLineWidth", 1)), + "ArrowSize": ("float", param.GetFloat("arrowsize", 20)), + "ArrowType": ("index", param.GetInt("dimsymbol", 0)), + "Decimals": ("int", param.GetInt("dimPrecision", 2)), + "DimOvershoot": ("float", param.GetFloat("dimovershoot", 20)), + "ExtLines": ("float", param.GetFloat("extlines", 300)), + "ExtOvershoot": ("float", param.GetFloat("extovershoot", 20)), + "FontName": ("font", param.GetString("textfont", "Sans")), + "FontSize": ("float", param.GetFloat("textheight", 100)), + "LineColor": ("color", param.GetUnsigned("DefaultAnnoLineColor", 255)), + "LineSpacing": ("float", param.GetFloat("LineSpacing", 1)), + "LineWidth": ("int", param.GetInt("DefaultAnnoLineWidth", 1)), "ScaleMultiplier": ("float", scale_mult), - "ShowLine": ("bool", param_draft.GetBool("DimShowLine", True)), - "ShowUnit": ("bool", param_draft.GetBool("showUnit", True)), - "TextColor": ("color", param_draft.GetUnsigned("DefaultTextColor", 255)), - "TextSpacing": ("float", param_draft.GetFloat("dimspacing", 20)), - "UnitOverride": ("str", param_draft.GetString("overrideUnit", "")), + "ShowLine": ("bool", param.GetBool("DimShowLine", True)), + "ShowUnit": ("bool", param.GetBool("showUnit", True)), + "TextColor": ("color", param.GetUnsigned("DefaultTextColor", 255)), + "TextSpacing": ("float", param.GetFloat("dimspacing", 20)), + "UnitOverride": ("str", param.GetString("overrideUnit", "")), } @@ -173,7 +172,8 @@ def get_param_type(param): "precision", "defaultWP", "snapRange", "gridEvery", "linewidth", "modconstrain", "modsnap", "maxSnapEdges", "modalt", "HatchPatternResolution", - "snapStyle", "DefaultAnnoDisplayMode", "gridSize", "gridTransparency"): + "snapStyle", "DefaultAnnoDisplayMode", "DefaultAnnoLineWidth", + "gridSize", "gridTransparency"): return "int" elif param in ("constructiongroupname", "textfont", "patternFile", "snapModes", @@ -192,8 +192,8 @@ def get_param_type(param): "DiscretizeEllipses", "showUnit", "coloredGridAxes", "Draft_array_fuse", "Draft_array_Link", "gridBorder"): return "bool" - elif param in ("color", "constructioncolor", - "snapcolor", "gridColor"): + elif param in ("color", "constructioncolor", "snapcolor", + "gridColor", "DefaultTextColor", "DefaultAnnoLineColor"): return "unsigned" else: return None @@ -832,6 +832,27 @@ def rgba_to_argb(color): return ((color & 0xFFFFFF00) >> 8) + ((color & 0xFF) << 24) +def get_rgba_tuple(color, typ=1.0): + """Return an RGBA tuple. + + Parameters + ---------- + color: int + RGBA integer. + typ: any float (default = 1.0) or int (use 255) + If float the values in the returned tuple are in the 0.0-1.0 range. + Else the values are in the 0-255 range. + """ + color = ((color >> 24) & 0xFF, + (color >> 16) & 0xFF, + (color >> 8) & 0xFF, + color & 0xFF) + if type(typ) == float: + return tuple([x / 255.0 for x in color]) + else: + return color + + def filter_objects_for_modifiers(objects, isCopied=False): filteredObjects = [] for obj in objects: diff --git a/src/Mod/Draft/draftviewproviders/view_dimension.py b/src/Mod/Draft/draftviewproviders/view_dimension.py index 83b9a7a271..7813d6968b 100644 --- a/src/Mod/Draft/draftviewproviders/view_dimension.py +++ b/src/Mod/Draft/draftviewproviders/view_dimension.py @@ -358,6 +358,7 @@ class ViewProviderLinearDimension(ViewProviderDimensionBase): self.onChanged(vobj, "DimOvershoot") self.onChanged(vobj, "ExtOvershoot") self.onChanged(vobj, "ShowLine") + self.onChanged(vobj, "LineWidth") def updateData(self, obj, prop): """Execute when a property from the Proxy class is changed. diff --git a/src/Mod/Draft/draftviewproviders/view_draft_annotation.py b/src/Mod/Draft/draftviewproviders/view_draft_annotation.py index 6b985ae3e6..886e1aa895 100644 --- a/src/Mod/Draft/draftviewproviders/view_draft_annotation.py +++ b/src/Mod/Draft/draftviewproviders/view_draft_annotation.py @@ -141,6 +141,7 @@ class ViewProviderDraftAnnotation(object): "TextColor", "Text", _tip) + vobj.TextColor = utils.get_param("DefaultTextColor", 255) & 0xFFFFFF00 def set_units_properties(self, vobj, properties): return @@ -153,6 +154,7 @@ class ViewProviderDraftAnnotation(object): "LineWidth", "Graphics", _tip) + vobj.LineWidth = utils.get_param("DefaultAnnoLineWidth", 2) if "LineColor" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "Line color") @@ -160,6 +162,7 @@ class ViewProviderDraftAnnotation(object): "LineColor", "Graphics", _tip) + vobj.LineColor = utils.get_param("DefaultAnnoLineColor", 255) & 0xFFFFFF00 def dumps(self): """Return a tuple of objects to save or None."""