FreeCAD

Форк
0
/
gui_pointarray.py 
142 строки · 6.1 Кб
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) 2018 Benjamin Alterauge (ageeye)                        *
5
# *   Copyright (c) 2020 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
6
# *                                                                         *
7
# *   This file is part of the FreeCAD CAx development system.              *
8
# *                                                                         *
9
# *   This program is free software; you can redistribute it and/or modify  *
10
# *   it under the terms of the GNU Lesser General Public License (LGPL)    *
11
# *   as published by the Free Software Foundation; either version 2 of     *
12
# *   the License, or (at your option) any later version.                   *
13
# *   for detail see the LICENCE text file.                                 *
14
# *                                                                         *
15
# *   This program is distributed in the hope that it will be useful,       *
16
# *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
17
# *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
18
# *   GNU Library General Public License for more details.                  *
19
# *                                                                         *
20
# *   You should have received a copy of the GNU Library General Public     *
21
# *   License along with this program; if not, write to the Free Software   *
22
# *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
23
# *   USA                                                                   *
24
# *                                                                         *
25
# ***************************************************************************
26
"""Provides GUI tools to create PointArray objects.
27

28
The copies will be created at the points of a point object.
29
"""
30
## @package gui_pointarray
31
# \ingroup draftguitools
32
# \brief Provides GUI tools to create PointArray objects.
33

34
## \addtogroup draftguitools
35
# @{
36
from PySide.QtCore import QT_TRANSLATE_NOOP
37

38
import FreeCADGui as Gui
39
import Draft_rc
40
import draftguitools.gui_base_original as gui_base_original
41

42
from draftutils.messages import _err
43
from draftutils.translate import translate
44

45
# The module is used to prevent complaints from code checkers (flake8)
46
True if Draft_rc.__name__ else False
47

48

49
class PointArray(gui_base_original.Modifier):
50
    """Gui Command for the Point array tool.
51

52
    Parameters
53
    ----------
54
    use_link: bool, optional
55
        It defaults to `False`. If it is `True`, the created object
56
        will be a `Point link array`.
57
    """
58

59
    def __init__(self, use_link=False):
60
        super(PointArray, self).__init__()
61
        self.use_link = use_link
62

63
    def GetResources(self):
64
        """Set icon, menu and tooltip."""
65

66
        return {'Pixmap': 'Draft_PointArray',
67
                'MenuText': QT_TRANSLATE_NOOP("Draft_PointArray", "Point array"),
68
                'ToolTip': QT_TRANSLATE_NOOP("Draft_PointArray", "Creates copies of the selected base object at the points of a point object.\nFirst select the base object, and then select the point object.")}
69

70
    def Activated(self, name="Point array"):
71
        """Execute when the command is called."""
72
        super(PointArray, self).Activated(name=name)
73
        # This was deactivated because it doesn't work correctly;
74
        # the selection needs to be made on two objects, but currently
75
        # it only selects one.
76

77
        # if not Gui.Selection.getSelectionEx():
78
        #     if self.ui:
79
        #         self.ui.selectUi()
80
        #         _msg(translate("draft",
81
        #                        "Please select exactly two objects, "
82
        #                        "the base object and the point object, "
83
        #                        "before calling this command."))
84
        #         self.call = \
85
        #             self.view.addEventCallback("SoEvent",
86
        #                                        gui_tool_utils.selectObject)
87
        # else:
88
        #     self.proceed()
89
        self.proceed()
90

91
    def proceed(self):
92
        """Proceed with the command if one object was selected."""
93
        sel = Gui.Selection.getSelectionEx()
94
        if len(sel) != 2:
95
            _err(translate("draft","Please select exactly two objects, the base object and the point object, before calling this command."))
96
        else:
97
            base_object = sel[0].Object
98
            point_object = sel[1].Object
99
            extra = None
100

101
            Gui.addModule('Draft')
102
            _cmd = "Draft.make_point_array"
103
            _cmd += "("
104
            _cmd += "App.ActiveDocument." + base_object.Name + ", "
105
            _cmd += "App.ActiveDocument." + point_object.Name + ", "
106
            _cmd += "extra=" + str(extra) + ", "
107
            _cmd += 'use_link=' + str(self.use_link)
108
            _cmd += ")"
109

110
            _cmd_list = ["_obj_ = " + _cmd,
111
                         "Draft.autogroup(_obj_)",
112
                         "App.ActiveDocument.recompute()"]
113
            self.commit(translate("draft","Point array"), _cmd_list)
114

115
        # Commit the transaction and execute the commands
116
        # through the parent class
117
        self.finish()
118

119

120
Gui.addCommand('Draft_PointArray', PointArray())
121

122
class PointLinkArray(PointArray):
123
    """Gui Command for the PointLinkArray tool based on the PointArray tool."""
124

125
    def __init__(self):
126
        super(PointLinkArray, self).__init__(use_link=True)
127

128
    def GetResources(self):
129
        """Set icon, menu and tooltip."""
130

131
        return {'Pixmap': 'Draft_PointLinkArray',
132
                'MenuText': QT_TRANSLATE_NOOP("Draft_PointLinkArray", "Point link array"),
133
                'ToolTip': QT_TRANSLATE_NOOP("Draft_PointLinkArray", "Like the PointArray tool, but creates a 'Point link array' instead.\nA 'Point link array' is more efficient when handling many copies.")}
134

135
    def Activated(self):
136
        """Execute when the command is called."""
137
        super(PointLinkArray, self).Activated(name="Point link array")
138

139

140
Gui.addCommand('Draft_PointLinkArray', PointLinkArray())
141

142
## @}
143

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

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

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

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