FreeCAD
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
28The 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# @{
36from PySide.QtCore import QT_TRANSLATE_NOOP37
38import FreeCADGui as Gui39import Draft_rc40import draftguitools.gui_base_original as gui_base_original41
42from draftutils.messages import _err43from draftutils.translate import translate44
45# The module is used to prevent complaints from code checkers (flake8)
46True if Draft_rc.__name__ else False47
48
49class PointArray(gui_base_original.Modifier):50"""Gui Command for the Point array tool.51
52Parameters
53----------
54use_link: bool, optional
55It defaults to `False`. If it is `True`, the created object
56will be a `Point link array`.
57"""
58
59def __init__(self, use_link=False):60super(PointArray, self).__init__()61self.use_link = use_link62
63def GetResources(self):64"""Set icon, menu and tooltip."""65
66return {'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
70def Activated(self, name="Point array"):71"""Execute when the command is called."""72super(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 currently75# 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()89self.proceed()90
91def proceed(self):92"""Proceed with the command if one object was selected."""93sel = Gui.Selection.getSelectionEx()94if len(sel) != 2:95_err(translate("draft","Please select exactly two objects, the base object and the point object, before calling this command."))96else:97base_object = sel[0].Object98point_object = sel[1].Object99extra = None100
101Gui.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()"]113self.commit(translate("draft","Point array"), _cmd_list)114
115# Commit the transaction and execute the commands116# through the parent class117self.finish()118
119
120Gui.addCommand('Draft_PointArray', PointArray())121
122class PointLinkArray(PointArray):123"""Gui Command for the PointLinkArray tool based on the PointArray tool."""124
125def __init__(self):126super(PointLinkArray, self).__init__(use_link=True)127
128def GetResources(self):129"""Set icon, menu and tooltip."""130
131return {'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
135def Activated(self):136"""Execute when the command is called."""137super(PointLinkArray, self).Activated(name="Point link array")138
139
140Gui.addCommand('Draft_PointLinkArray', PointLinkArray())141
142## @}
143