Files
create/src/Mod/Draft/draftguitools/gui_subelements.py
vocx-fc e3da572072 Draft: add modules of draftguitools to the proper Doxygen group
This includes `gui_annotationstyleeditor`, `gui_arcs`, `gui_array_simple`,
`gui_arrays`, `gui_base`, `gui_base_original`, `gui_beziers`,
`gui_circles`, `gui_circulararray`, `gui_clone`, `gui_circulararray`,
`gui_clone`, `gui_dimension_ops`, `gui_dimensions`, `gui_downgrade`,
`gui_draft2sketch`, `gui_drawing`, `gui_edit`, `gui_edit_arch_objects`,
`gui_edit_draft_objects`, `gui_edit_part_objects`, `gui_edit_sketcher_objects`,
`gui_ellipses`, `gui_facebinders`, `gui_fillets`, `gui_grid`,
`gui_groups`, `gui_heal`, `gui_join`, `gui_labels`, `gui_line_add_delete`,
`gui_lineops`, `gui_lines`, `gui_lineslope`, `gui_mirror`,
`gui_move`, `gui_offset`, `gui_orthoarray`, `gui_patharray`,
`gui_planeproxy`, `gui_pointarray`, `gui_points`, `gui_polararray`,
`gui_polygons`, `gui_rectangles`, `gui_rotate`, `gui_scale`,
`gui_selectplane`, `gui_shape2dview`, `gui_shapestrings`, `gui_snapper`,
`gui_snaps`, `gui_splines`, `gui_split`, `gui_stretch`, `gui_styles`,
`gui_subeleemnts`, `gui_texts`, `gui_togglemodes`, `gui_tools_utils`,
`gui_trackers`, `gui_trimex`, `gui_upgrade`, `gui_wire2spline`.

These are added to the `draftguitools` Doxygen group
so that the functions and classes contained in each module
are listed appropriately in the automatically generated
documentation.
2020-07-17 13:01:45 +02:00

167 lines
7.0 KiB
Python

# ***************************************************************************
# * (c) 2009 Yorik van Havre <yorik@uncreated.net> *
# * (c) 2010 Ken Cline <cline@frii.com> *
# * (c) 2020 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
# * *
# * This file is part of the FreeCAD CAx development system. *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * FreeCAD is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with FreeCAD; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
"""Provides GUI tools to highlight subelements of objects.
The highlighting can be used to manipulate shapes with other tools
such as Move, Rotate, and Scale.
"""
## @package gui_subelements
# \ingroup draftguitools
# \brief Provides GUI tools to highlight subelements of objects.
## \addtogroup draftguitools
# @{
import pivy.coin as coin
from PySide.QtCore import QT_TRANSLATE_NOOP
import FreeCADGui as Gui
import draftguitools.gui_base_original as gui_base_original
import draftguitools.gui_tool_utils as gui_tool_utils
from draftutils.messages import _msg
from draftutils.translate import translate, _tr
class SubelementHighlight(gui_base_original.Modifier):
"""Gui Command for the SubelementHighlight tool."""
def __init__(self):
self.is_running = False
self.editable_objects = []
self.original_view_settings = {}
def GetResources(self):
"""Set icon, menu and tooltip."""
_menu = "Subelement highlight"
_tip = ("Highlight the subelements "
"of the selected objects, "
"so that they can then be edited "
"with the move, rotate, and scale tools.")
return {'Pixmap': 'Draft_SubelementHighlight',
'Accel': "H, S",
'MenuText': QT_TRANSLATE_NOOP("Draft_SubelementHighlight",
_menu),
'ToolTip': QT_TRANSLATE_NOOP("Draft_SubelementHighlight",
_tip)}
def Activated(self):
"""Execute when the command is called."""
if self.is_running:
return self.finish()
self.is_running = True
super(SubelementHighlight, self).Activated(name=_tr("Subelement highlight"))
self.get_selection()
def proceed(self):
"""Continue with the command."""
self.remove_view_callback()
self.get_editable_objects_from_selection()
if not self.editable_objects:
return self.finish()
self.call = self.view.addEventCallback("SoEvent", self.action)
self.highlight_editable_objects()
def finish(self):
"""Terminate the operation.
Re-initialize by running __init__ again at the end.
"""
super(SubelementHighlight, self).finish()
self.remove_view_callback()
self.restore_editable_objects_graphics()
self.__init__()
def action(self, event):
"""Handle the 3D scene events.
This is installed as an EventCallback in the Inventor view.
Parameters
----------
event: dict
Dictionary with strings that indicates the type of event received
from the 3D view.
"""
if event["Type"] == "SoKeyboardEvent" and event["Key"] == "ESCAPE":
self.finish()
def get_selection(self):
"""Get the selection."""
if not Gui.Selection.getSelection() and self.ui:
_msg(translate("draft", "Select an object to edit"))
self.call = self.view.addEventCallback("SoEvent",
gui_tool_utils.selectObject)
else:
self.proceed()
def remove_view_callback(self):
"""Remove the installed callback if it exists."""
if self.call:
self.view.removeEventCallback("SoEvent", self.call)
def get_editable_objects_from_selection(self):
"""Get editable Draft objects for the selection."""
for obj in Gui.Selection.getSelection():
if obj.isDerivedFrom("Part::Part2DObject"):
self.editable_objects.append(obj)
elif (hasattr(obj, "Base")
and obj.Base.isDerivedFrom("Part::Part2DObject")):
self.editable_objects.append(obj.Base)
def highlight_editable_objects(self):
"""Highlight editable Draft objects from the selection."""
for obj in self.editable_objects:
self.original_view_settings[obj.Name] = {
'Visibility': obj.ViewObject.Visibility,
'PointSize': obj.ViewObject.PointSize,
'PointColor': obj.ViewObject.PointColor,
'LineColor': obj.ViewObject.LineColor}
obj.ViewObject.Visibility = True
obj.ViewObject.PointSize = 10
obj.ViewObject.PointColor = (1.0, 0.0, 0.0)
obj.ViewObject.LineColor = (1.0, 0.0, 0.0)
xray = coin.SoAnnotation()
xray.addChild(obj.ViewObject.RootNode.getChild(2).getChild(0))
xray.setName("xray")
obj.ViewObject.RootNode.addChild(xray)
def restore_editable_objects_graphics(self):
"""Restore the editable objects' appearance."""
for obj in self.editable_objects:
try:
for attribute, value in self.original_view_settings[obj.Name].items():
vobj = obj.ViewObject
setattr(vobj, attribute, value)
vobj.RootNode.removeChild(vobj.RootNode.getByName("xray"))
except Exception:
# This can occur if objects have had graph changing operations
pass
Gui.addCommand('Draft_SubelementHighlight', SubelementHighlight())
## @}