FreeCAD

Форк
0
/
gui_edit_part_objects.py 
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
# @{
33
import FreeCAD as App
34
import DraftVecUtils
35

36
from draftguitools.gui_edit_base_object import GuiTools
37

38

39
class PartLineGuiTools(GuiTools):
40

41
    def __init__(self):
42
        pass
43

44
    def get_edit_points(self, obj):
45
        editpoints = []
46
        editpoints.append(App.Vector(obj.X1,obj.Y1,obj.Z1))
47
        editpoints.append(App.Vector(obj.X2,obj.Y2,obj.Z2))
48
        return editpoints
49

50
    def update_object_from_edit_points(self, obj, node_idx, v, alt_edit_mode=0):
51
        if node_idx == 0:
52
            obj.X1 = v.x
53
            obj.Y1 = v.y
54
            obj.Z1 = v.z
55
        elif node_idx == 1:
56
            obj.X2 = v.x
57
            obj.Y2 = v.y
58
            obj.Z2 = v.z
59

60

61
class PartBoxGuiTools(GuiTools):
62

63
    def __init__(self):
64
        pass
65

66
    def get_edit_points(self, obj):
67
        editpoints = []
68
        editpoints.append(App.Vector(0, 0, 0))
69
        editpoints.append(App.Vector(obj.Length, 0, 0))
70
        editpoints.append(App.Vector(0, obj.Width, 0))
71
        editpoints.append(App.Vector(0, 0, obj.Height))
72
        return editpoints
73

74
    def update_object_from_edit_points(self, obj, node_idx, v, alt_edit_mode=0):
75
        if node_idx == 0:
76
            obj.Placement.Base = obj.Placement.Base + v
77
        elif node_idx == 1:
78
            _vector = DraftVecUtils.project(v, App.Vector(1, 0, 0))
79
            obj.Length = _vector.Length
80
        elif node_idx == 2:
81
            _vector = DraftVecUtils.project(v, App.Vector(0, 1, 0))
82
            obj.Width = _vector.Length
83
        elif node_idx == 3:
84
            _vector = DraftVecUtils.project(v, App.Vector(0, 0, 1))
85
            obj.Height = _vector.Length
86

87

88
class PartCylinderGuiTools(GuiTools):
89

90
    def __init__(self):
91
        pass
92

93
    def get_edit_points(self, obj):
94
        editpoints = []
95
        editpoints.append(App.Vector(0, 0, 0))
96
        editpoints.append(App.Vector(obj.Radius, 0, 0))
97
        editpoints.append(App.Vector(0, 0, obj.Height))
98
        return editpoints
99

100
    def update_object_from_edit_points(self, obj, node_idx, v, alt_edit_mode=0):
101
        if node_idx == 0:
102
            obj.Placement.Base = obj.Placement.Base + v
103
        elif node_idx == 1:
104
            if v.Length > 0.0:
105
                obj.Radius = v.Length
106
        elif node_idx == 2:
107
            _vector = DraftVecUtils.project(v, App.Vector(0, 0, 1))
108
            obj.Height = _vector.Length
109

110

111
class PartConeGuiTools(GuiTools):
112

113
    def __init__(self):
114
        pass
115

116
    def get_edit_points(self, obj):
117
        editpoints = []
118
        editpoints.append(App.Vector(0, 0, 0))
119
        editpoints.append(App.Vector(obj.Radius1, 0, 0))
120
        editpoints.append(App.Vector(obj.Radius2, 0, obj.Height))
121
        editpoints.append(App.Vector(0, 0, obj.Height))
122
        return editpoints
123

124
    def update_object_from_edit_points(self, obj, node_idx, v, alt_edit_mode=0):
125
        if node_idx == 0:
126
            obj.Placement.Base = obj.Placement.Base + v
127
        elif node_idx == 1:
128
            obj.Radius1 = v.Length # TODO: Perhaps better to project on the face?
129
        elif node_idx == 2:
130
            v.z = 0
131
            obj.Radius2 = v.Length # TODO: Perhaps better to project on the face?
132
        elif node_idx == 3: # Height is last to have the priority on the radius
133
            _vector = DraftVecUtils.project(v, App.Vector(0, 0, 1))
134
            obj.Height = _vector.Length
135

136

137
class PartSphereGuiTools(GuiTools):
138

139
    def __init__(self):
140
        pass
141

142
    def get_edit_points(self, obj):
143
        editpoints = []
144
        editpoints.append(App.Vector(0, 0, 0))
145
        editpoints.append(App.Vector(obj.Radius, 0, 0))
146
        return editpoints
147

148
    def update_object_from_edit_points(self, obj, node_idx, v, alt_edit_mode=0):
149
        if node_idx == 0:
150
            obj.Placement.Base = obj.Placement.Base + v
151
        elif node_idx == 1:
152
            if v.Length > 0.0:
153
                obj.Radius = v.Length # TODO: Perhaps better to project on the face?
154

155
## @}
156

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.