FreeCAD
155 строк · 5.7 Кб
1# ***************************************************************************
2# * Copyright (c) 2019 Carlo Pavan <carlopav@gmail.com> *
3# * *
4# * This program is free software; you can redistribute it and/or modify *
5# * it under the terms of the GNU Lesser General Public License (LGPL) *
6# * as published by the Free Software Foundation; either version 2 of *
7# * the License, or (at your option) any later version. *
8# * for detail see the LICENCE text file. *
9# * *
10# * This program is distributed in the hope that it will be useful, *
11# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13# * GNU Library General Public License for more details. *
14# * *
15# * You should have received a copy of the GNU Library General Public *
16# * License along with this program; if not, write to the Free Software *
17# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
18# * USA *
19# * *
20# ***************************************************************************
21"""Provides support functions to edit Part objects."""
22## @package gui_edit_part_objects
23# \ingroup draftguitools
24# \brief Provides support functions to edit Part objects.
25
26__title__ = "FreeCAD Draft Edit Tool"
27__author__ = ("Yorik van Havre, Werner Mayer, Martin Burbaum, Ken Cline, "
28"Dmitry Chigrin, Carlo Pavan")
29__url__ = "https://www.freecad.org"
30
31## \addtogroup draftguitools
32# @{
33import FreeCAD as App
34import DraftVecUtils
35
36from draftguitools.gui_edit_base_object import GuiTools
37
38
39class PartLineGuiTools(GuiTools):
40
41def __init__(self):
42pass
43
44def get_edit_points(self, obj):
45editpoints = []
46editpoints.append(App.Vector(obj.X1,obj.Y1,obj.Z1))
47editpoints.append(App.Vector(obj.X2,obj.Y2,obj.Z2))
48return editpoints
49
50def update_object_from_edit_points(self, obj, node_idx, v, alt_edit_mode=0):
51if node_idx == 0:
52obj.X1 = v.x
53obj.Y1 = v.y
54obj.Z1 = v.z
55elif node_idx == 1:
56obj.X2 = v.x
57obj.Y2 = v.y
58obj.Z2 = v.z
59
60
61class PartBoxGuiTools(GuiTools):
62
63def __init__(self):
64pass
65
66def get_edit_points(self, obj):
67editpoints = []
68editpoints.append(App.Vector(0, 0, 0))
69editpoints.append(App.Vector(obj.Length, 0, 0))
70editpoints.append(App.Vector(0, obj.Width, 0))
71editpoints.append(App.Vector(0, 0, obj.Height))
72return editpoints
73
74def update_object_from_edit_points(self, obj, node_idx, v, alt_edit_mode=0):
75if node_idx == 0:
76obj.Placement.Base = obj.Placement.Base + v
77elif node_idx == 1:
78_vector = DraftVecUtils.project(v, App.Vector(1, 0, 0))
79obj.Length = _vector.Length
80elif node_idx == 2:
81_vector = DraftVecUtils.project(v, App.Vector(0, 1, 0))
82obj.Width = _vector.Length
83elif node_idx == 3:
84_vector = DraftVecUtils.project(v, App.Vector(0, 0, 1))
85obj.Height = _vector.Length
86
87
88class PartCylinderGuiTools(GuiTools):
89
90def __init__(self):
91pass
92
93def get_edit_points(self, obj):
94editpoints = []
95editpoints.append(App.Vector(0, 0, 0))
96editpoints.append(App.Vector(obj.Radius, 0, 0))
97editpoints.append(App.Vector(0, 0, obj.Height))
98return editpoints
99
100def update_object_from_edit_points(self, obj, node_idx, v, alt_edit_mode=0):
101if node_idx == 0:
102obj.Placement.Base = obj.Placement.Base + v
103elif node_idx == 1:
104if v.Length > 0.0:
105obj.Radius = v.Length
106elif node_idx == 2:
107_vector = DraftVecUtils.project(v, App.Vector(0, 0, 1))
108obj.Height = _vector.Length
109
110
111class PartConeGuiTools(GuiTools):
112
113def __init__(self):
114pass
115
116def get_edit_points(self, obj):
117editpoints = []
118editpoints.append(App.Vector(0, 0, 0))
119editpoints.append(App.Vector(obj.Radius1, 0, 0))
120editpoints.append(App.Vector(obj.Radius2, 0, obj.Height))
121editpoints.append(App.Vector(0, 0, obj.Height))
122return editpoints
123
124def update_object_from_edit_points(self, obj, node_idx, v, alt_edit_mode=0):
125if node_idx == 0:
126obj.Placement.Base = obj.Placement.Base + v
127elif node_idx == 1:
128obj.Radius1 = v.Length # TODO: Perhaps better to project on the face?
129elif node_idx == 2:
130v.z = 0
131obj.Radius2 = v.Length # TODO: Perhaps better to project on the face?
132elif node_idx == 3: # Height is last to have the priority on the radius
133_vector = DraftVecUtils.project(v, App.Vector(0, 0, 1))
134obj.Height = _vector.Length
135
136
137class PartSphereGuiTools(GuiTools):
138
139def __init__(self):
140pass
141
142def get_edit_points(self, obj):
143editpoints = []
144editpoints.append(App.Vector(0, 0, 0))
145editpoints.append(App.Vector(obj.Radius, 0, 0))
146return editpoints
147
148def update_object_from_edit_points(self, obj, node_idx, v, alt_edit_mode=0):
149if node_idx == 0:
150obj.Placement.Base = obj.Placement.Base + v
151elif node_idx == 1:
152if v.Length > 0.0:
153obj.Radius = v.Length # TODO: Perhaps better to project on the face?
154
155## @}
156