FreeCAD
85 строк · 4.0 Кб
1# ***************************************************************************
2# * (c) 2009, 2010 Yorik van Havre <yorik@uncreated.net> *
3# * (c) 2009, 2010 Ken Cline <cline@frii.com> *
4# * (c) 2020 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
5# * *
6# * This file is part of the FreeCAD CAx development system. *
7# * *
8# * This program is free software; you can redistribute it and/or modify *
9# * it under the terms of the GNU Lesser General Public License (LGPL) *
10# * as published by the Free Software Foundation; either version 2 of *
11# * the License, or (at your option) any later version. *
12# * for detail see the LICENCE text file. *
13# * *
14# * FreeCAD is distributed in the hope that it will be useful, *
15# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17# * GNU Library General Public License for more details. *
18# * *
19# * You should have received a copy of the GNU Library General Public *
20# * License along with FreeCAD; if not, write to the Free Software *
21# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
22# * USA *
23# * *
24# ***************************************************************************
25"""Provides GUI tools to modify dimension objects.
26
27For example, a tool to flip the direction of the text in the dimension
28as the normal is sometimes not correctly calculated automatically.
29"""
30## @package gui_dimension_ops
31# \ingroup draftguitools
32# \brief Provides GUI tools to modify dimension objects.
33
34## \addtogroup draftguitools
35# @{
36from PySide.QtCore import QT_TRANSLATE_NOOP37
38import FreeCADGui as Gui39import draftutils.utils as utils40import draftguitools.gui_base as gui_base41
42from draftutils.translate import translate43
44
45class FlipDimension(gui_base.GuiCommandNeedsSelection):46"""The Draft FlipDimension command definition.47
48Flip the normal direction of the selected dimensions.
49
50It inherits `GuiCommandNeedsSelection` to set up the document
51and other behavior. See this class for more information.
52"""
53
54def __init__(self):55super(Draft_FlipDimension, self).__init__(name=translate("draft","Flip dimension"))56
57def GetResources(self):58"""Set icon, menu and tooltip."""59
60return {'Pixmap': 'Draft_FlipDimension',61'MenuText': QT_TRANSLATE_NOOP("Draft_FlipDimension",62"Flip dimension"),63'ToolTip': QT_TRANSLATE_NOOP("Draft_FlipDimension",64"Flip the normal direction of the selected dimensions (linear, radial, angular).\nIf other objects are selected they are ignored.")}65
66def Activated(self):67"""Execute when the command is called."""68super(Draft_FlipDimension, self).Activated()69
70for o in Gui.Selection.getSelection():71if utils.get_type(o) in ("Dimension",72"LinearDimension", "AngularDimension"):73self.doc.openTransaction("Flip dimension")74_cmd = "App.activeDocument()." + o.Name + ".Normal"75_cmd += " = "76_cmd += "App.activeDocument()." + o.Name + ".Normal.negative()"77Gui.doCommand(_cmd)78self.doc.commitTransaction()79self.doc.recompute()80
81
82Draft_FlipDimension = FlipDimension83Gui.addCommand('Draft_FlipDimension', FlipDimension())84
85## @}
86