FreeCAD
82 строки · 3.6 Кб
1# ***************************************************************************
2# * Copyright (c) 2009, 2010 Yorik van Havre <yorik@uncreated.net> *
3# * Copyright (c) 2009, 2010 Ken Cline <cline@frii.com> *
4# * Copyright (c) 2019, 2020 Carlo Pavan <carlopav@gmail.com> *
5# * *
6# * This program is free software; you can redistribute it and/or modify *
7# * it under the terms of the GNU Lesser General Public License (LGPL) *
8# * as published by the Free Software Foundation; either version 2 of *
9# * the License, or (at your option) any later version. *
10# * for detail see the LICENCE text file. *
11# * *
12# * This program is distributed in the hope that it will be useful, *
13# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15# * GNU Library General Public License for more details. *
16# * *
17# * You should have received a copy of the GNU Library General Public *
18# * License along with this program; if not, write to the Free Software *
19# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
20# * USA *
21# * *
22# ***************************************************************************
23"""Provides support functions to edit Sketch objects."""
24## @package gui_edit_sketcher_objects
25# \ingroup draftguitools
26# \brief Provides support functions to edit Sketch objects.
27
28__title__ = "FreeCAD Draft Edit Tool"29__author__ = ("Yorik van Havre, Werner Mayer, Martin Burbaum, Ken Cline, "30"Dmitry Chigrin, Carlo Pavan")31__url__ = "https://www.freecad.org"32
33## \addtogroup draftguitools
34# @{
35import FreeCAD as App36from draftutils.translate import translate37
38from draftguitools.gui_edit_base_object import GuiTools39
40
41class SketcherSketchObjectGuiTools(GuiTools):42
43def __init__(self):44pass45
46def get_edit_points(self, obj):47"""Return the list of edipoints for the given single line sketch.48(WallTrace)
490 : startpoint
501 : endpoint
51"""
52import Part53editpoints = []54if (obj.ConstraintCount == 055and obj.GeometryCount == 156and type(obj.Geometry[0]) == Part.LineSegment):57editpoints.append(obj.getPoint(0,1))58editpoints.append(obj.getPoint(0,2))59return editpoints60else:61_wrn = translate("draft", "Sketch is too complex to edit: "62"it is suggested to use sketcher default editor")63App.Console.PrintWarning(_wrn + "\n")64return None65
66def update_object_from_edit_points(self, obj, node_idx, v, alt_edit_mode=0):67"""Move a single line sketch vertex a certain displacement.68
69(single segment sketch object, node index as Int, App.Vector)
70move a single line sketch (WallTrace) vertex according to a given App.Vector
710 : startpoint
721 : endpoint
73"""
74line = obj.Geometry[0]75if node_idx == 0:76line.StartPoint = v77elif node_idx == 1:78line.EndPoint = v79obj.Geometry = [line]80obj.recompute()81
82## @}
83