From 24d87ccdb32927a46b3c5c7fbe345c44a95def68 Mon Sep 17 00:00:00 2001 From: carlopav Date: Sat, 25 Apr 2020 16:35:04 +0200 Subject: [PATCH] Draft: split Point from Draft.py . --- src/Mod/Draft/CMakeLists.txt | 3 + src/Mod/Draft/Draft.py | 82 ++-------------- src/Mod/Draft/draftmake/make_point.py | 96 +++++++++++++++++++ src/Mod/Draft/draftobjects/point.py | 77 +++++++++++++++ .../Draft/draftviewproviders/view_point.py | 55 +++++++++++ 5 files changed, 239 insertions(+), 74 deletions(-) create mode 100644 src/Mod/Draft/draftmake/make_point.py create mode 100644 src/Mod/Draft/draftobjects/point.py create mode 100644 src/Mod/Draft/draftviewproviders/view_point.py diff --git a/src/Mod/Draft/CMakeLists.txt b/src/Mod/Draft/CMakeLists.txt index 1fab94dc21..d2b43fe0a1 100644 --- a/src/Mod/Draft/CMakeLists.txt +++ b/src/Mod/Draft/CMakeLists.txt @@ -70,6 +70,7 @@ SET(Draft_make_functions draftmake/make_clone.py draftmake/make_line.py draftmake/make_polygon.py + draftmake/make_point.py draftmake/make_rectangle.py draftmake/make_wire.py ) @@ -88,6 +89,7 @@ SET(Draft_objects draftobjects/draft_annotation.py draftobjects/label.py draftobjects/dimension.py + draftobjects/point.py draftobjects/polygon.py draftobjects/rectangle.py draftobjects/text.py @@ -105,6 +107,7 @@ SET(Draft_view_providers draftviewproviders/view_draft_annotation.py draftviewproviders/view_label.py draftviewproviders/view_dimension.py + draftviewproviders/view_point.py draftviewproviders/view_rectangle.py draftviewproviders/view_text.py draftviewproviders/view_wire.py diff --git a/src/Mod/Draft/Draft.py b/src/Mod/Draft/Draft.py index 4c2fd579d9..7c831085fd 100644 --- a/src/Mod/Draft/Draft.py +++ b/src/Mod/Draft/Draft.py @@ -235,6 +235,14 @@ if FreeCAD.GuiUp: from draftviewproviders.view_clone import ViewProviderClone from draftviewproviders.view_clone import _ViewProviderClone +# point +from draftmake.make_point import make_point, makePoint +from draftobjects.point import Point, _Point +if FreeCAD.GuiUp: + from draftviewproviders.view_point import ViewProviderPoint + from draftviewproviders.view_point import _ViewProviderPoint + + #--------------------------------------------------------------------------- # Draft annotation objects #--------------------------------------------------------------------------- @@ -1872,42 +1880,6 @@ def makeSketch(objectslist,autoconstraints=False,addTo=None, return nobj -def makePoint(X=0, Y=0, Z=0,color=None,name = "Point", point_size= 5): - """ makePoint(x,y,z ,[color(r,g,b),point_size]) or - makePoint(Vector,color(r,g,b),point_size]) - - creates a Point in the current document. - example usage: - p1 = makePoint() - p1.ViewObject.Visibility= False # make it invisible - p1.ViewObject.Visibility= True # make it visible - p1 = makePoint(-1,0,0) #make a point at -1,0,0 - p1 = makePoint(1,0,0,(1,0,0)) # color = red - p1.X = 1 #move it in x - p1.ViewObject.PointColor =(0.0,0.0,1.0) #change the color-make sure values are floats - """ - if not FreeCAD.ActiveDocument: - FreeCAD.Console.PrintError("No active document. Aborting\n") - return - obj=FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) - if isinstance(X,FreeCAD.Vector): - Z = X.z - Y = X.y - X = X.x - _Point(obj,X,Y,Z) - obj.X = X - obj.Y = Y - obj.Z = Z - if gui: - _ViewProviderPoint(obj.ViewObject) - if hasattr(FreeCADGui,"draftToolBar") and (not color): - color = FreeCADGui.draftToolBar.getDefaultColor('ui') - obj.ViewObject.PointColor = (float(color[0]), float(color[1]), float(color[2])) - obj.ViewObject.PointSize = point_size - obj.ViewObject.Visibility = True - select(obj) - - return obj - def makeShapeString(String,FontFile,Size = 100,Tracking = 0): """ShapeString(Text,FontFile,Height,Track): Turns a text string into a Compound Shape""" @@ -3643,44 +3615,6 @@ class _PointArray(_DraftObject): FreeCAD.Console.PrintError(translate("draft","No point found\n")) obj.Shape = obj.Base.Shape.copy() -class _Point(_DraftObject): - """The Draft Point object""" - def __init__(self, obj,x=0,y=0,z=0): - _DraftObject.__init__(self,obj,"Point") - obj.addProperty("App::PropertyDistance","X","Draft",QT_TRANSLATE_NOOP("App::Property","X Location")).X = x - obj.addProperty("App::PropertyDistance","Y","Draft",QT_TRANSLATE_NOOP("App::Property","Y Location")).Y = y - obj.addProperty("App::PropertyDistance","Z","Draft",QT_TRANSLATE_NOOP("App::Property","Z Location")).Z = z - mode = 2 - obj.setEditorMode('Placement',mode) - - def execute(self, obj): - import Part - shape = Part.Vertex(Vector(0,0,0)) - obj.Shape = shape - obj.Placement.Base = FreeCAD.Vector(obj.X.Value,obj.Y.Value,obj.Z.Value) - -class _ViewProviderPoint(_ViewProviderDraft): - """A viewprovider for the Draft Point object""" - def __init__(self, obj): - _ViewProviderDraft.__init__(self,obj) - - def onChanged(self, vobj, prop): - mode = 2 - vobj.setEditorMode('LineColor',mode) - vobj.setEditorMode('LineWidth',mode) - vobj.setEditorMode('BoundingBox',mode) - vobj.setEditorMode('Deviation',mode) - vobj.setEditorMode('DiffuseColor',mode) - vobj.setEditorMode('DisplayMode',mode) - vobj.setEditorMode('Lighting',mode) - vobj.setEditorMode('LineMaterial',mode) - vobj.setEditorMode('ShapeColor',mode) - vobj.setEditorMode('ShapeMaterial',mode) - vobj.setEditorMode('Transparency',mode) - - def getIcon(self): - return ":/icons/Draft_Dot.svg" - class _ViewProviderDraftArray(_ViewProviderDraft): """a view provider that displays a Array icon instead of a Draft icon""" diff --git a/src/Mod/Draft/draftmake/make_point.py b/src/Mod/Draft/draftmake/make_point.py new file mode 100644 index 0000000000..2654734207 --- /dev/null +++ b/src/Mod/Draft/draftmake/make_point.py @@ -0,0 +1,96 @@ +# *************************************************************************** +# * Copyright (c) 2009, 2010 Yorik van Havre * +# * Copyright (c) 2009, 2010 Ken Cline * +# * Copyright (c) 2020 FreeCAD Developers * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program 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 program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** +"""This module provides the code for Draft make_point function. +""" +## @package make_point +# \ingroup DRAFT +# \brief This module provides the code for Draft make_point function. + +import FreeCAD as App + +from draftutils.gui_utils import format_object +from draftutils.gui_utils import select + +from draftobjects.point import Point +if App.GuiUp: + import FreeCADGui as Gui + from draftviewproviders.view_point import ViewProviderPoint + + +def make_point(X=0, Y=0, Z=0, color=None, name = "Point", point_size= 5): + """ makePoint(x,y,z ,[color(r,g,b),point_size]) or + makePoint(Vector,color(r,g,b),point_size]) - + + Creates a Draft Point in the current document. + + Parameters + ---------- + X : + float -> X coordinate of the point + Base.Vector -> Ignore Y and Z coordinates and create the point + from the vector. + + Y : float + Y coordinate of the point + + Z : float + Z coordinate of the point + + color : (R, G, B) + Point color as RGB + example to create a colored point: + make_point(0,0,0,(1,0,0)) # color = red + example to change the color, make sure values are floats: + p1.ViewObject.PointColor =(0.0,0.0,1.0) + """ + if not App.ActiveDocument: + App.Console.PrintError("No active document. Aborting\n") + return + + obj = App.ActiveDocument.addObject("Part::FeaturePython", name) + + if isinstance(X, App.Vector): + Z = X.z + Y = X.y + X = X.x + + Point(obj, X, Y, Z) + + # TODO: Check if this is a repetition: + obj.X = X + obj.Y = Y + obj.Z = Z + + if App.GuiUp: + ViewProviderPoint(obj.ViewObject) + if hasattr(Gui,"draftToolBar") and (not color): + color = Gui.draftToolBar.getDefaultColor('ui') + obj.ViewObject.PointColor = (float(color[0]), float(color[1]), float(color[2])) + obj.ViewObject.PointSize = point_size + obj.ViewObject.Visibility = True + select(obj) + + return obj + + +makePoint = make_point \ No newline at end of file diff --git a/src/Mod/Draft/draftobjects/point.py b/src/Mod/Draft/draftobjects/point.py new file mode 100644 index 0000000000..d73cd4afb4 --- /dev/null +++ b/src/Mod/Draft/draftobjects/point.py @@ -0,0 +1,77 @@ +# *************************************************************************** +# * Copyright (c) 2009, 2010 Yorik van Havre * +# * Copyright (c) 2009, 2010 Ken Cline * +# * Copyright (c) 2020 FreeCAD Developers * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program 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 program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** +"""This module provides the object code for Draft Point. +""" +## @package point +# \ingroup DRAFT +# \brief This module provides the object code for Draft Point. + +import math + +import FreeCAD as App + +from PySide.QtCore import QT_TRANSLATE_NOOP + +from draftutils.utils import get_param + +from draftobjects.base import DraftObject + + +class Point(DraftObject): + """The Draft Point object. + """ + def __init__(self, obj, x=0, y=0, z=0): + super(Point, self).__init__(obj, "Point") + + obj.addProperty("App::PropertyDistance", + "X", + "Draft", + QT_TRANSLATE_NOOP("App::Property","X Location")) + + obj.addProperty("App::PropertyDistance", + "Y", + "Draft", + QT_TRANSLATE_NOOP("App::Property","Y Location")) + + obj.addProperty("App::PropertyDistance", + "Z", + "Draft", + QT_TRANSLATE_NOOP("App::Property","Z Location")) + + obj.X = x + obj.Y = y + obj.Z = z + + mode = 2 + obj.setEditorMode('Placement',mode) + + def execute(self, obj): + import Part + shape = Part.Vertex(App.Vector(0, 0, 0)) + obj.Shape = shape + obj.Placement.Base = App.Vector(obj.X.Value, + obj.Y.Value, + obj.Z.Value) + + +_Point = Point \ No newline at end of file diff --git a/src/Mod/Draft/draftviewproviders/view_point.py b/src/Mod/Draft/draftviewproviders/view_point.py new file mode 100644 index 0000000000..c75ed1f18e --- /dev/null +++ b/src/Mod/Draft/draftviewproviders/view_point.py @@ -0,0 +1,55 @@ +# *************************************************************************** +# * Copyright (c) 2009, 2010 Yorik van Havre * +# * Copyright (c) 2009, 2010 Ken Cline * +# * Copyright (c) 2019 Eliud Cabrera Castillo * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program 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 program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** +"""This module provides the view provider code for Draft Point. +""" +## @package view_point +# \ingroup DRAFT +# \brief This module provides the view provider code for Draft Point. + +from draftviewproviders.view_base import ViewProviderDraft + + +class ViewProviderPoint(ViewProviderDraft): + """A viewprovider for the Draft Point object""" + def __init__(self, obj): + super(ViewProviderPoint, self).__init__(obj) + + def onChanged(self, vobj, prop): + mode = 2 + vobj.setEditorMode('LineColor', mode) + vobj.setEditorMode('LineWidth', mode) + vobj.setEditorMode('BoundingBox', mode) + vobj.setEditorMode('Deviation', mode) + vobj.setEditorMode('DiffuseColor', mode) + vobj.setEditorMode('DisplayMode', mode) + vobj.setEditorMode('Lighting', mode) + vobj.setEditorMode('LineMaterial', mode) + vobj.setEditorMode('ShapeColor', mode) + vobj.setEditorMode('ShapeMaterial', mode) + vobj.setEditorMode('Transparency', mode) + + def getIcon(self): + return ":/icons/Draft_Dot.svg" + + +_ViewProviderPoint = ViewProviderPoint \ No newline at end of file