File size: 4,818 Bytes
985c397 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | # SPDX-License-Identifier: LGPL-2.1-or-later
# ***************************************************************************
# * Copyright (c) 2016 Victor Titov (DeepSOIC) <vv.titov@gmail.com> *
# * *
# * This file is part of the FreeCAD CAx development system. *
# * *
# * This library is free software; you can redistribute it and/or *
# * modify it under the terms of the GNU Library General Public *
# * License as published by the Free Software Foundation; either *
# * version 2 of the License, or (at your option) any later version. *
# * *
# * This library 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 this library; see the file COPYING.LIB. If not, *
# * write to the Free Software Foundation, Inc., 59 Temple Place, *
# * Suite 330, Boston, MA 02111-1307, USA *
# * *
# ***************************************************************************/
from __future__ import absolute_import
import FreeCAD as App
try:
from PySide.QtCore import QT_TRANSLATE_NOOP
except ImportError:
def QT_TRANSLATE_NOOP(ctx, msg):
return msg
def editAttachment(
feature=None,
take_selection=False,
create_transaction=True,
callback_OK=None,
callback_Cancel=None,
callback_Apply=None,
):
"""Opens attachment editing dialog.
editAttachment(feature = None,
take_selection = False,
create_transaction = True,
callback_OK = None,
callback_Cancel = None,
callback_Apply = None)
feature: object to attach/modify. If None is supplied, the object is taken from
selection.
take_selection: if True, current selection is filled into first references (but only
if object to be attached doesn't have any references already)
create_transaction = if False, no undo transaction operations will be done by the
dialog (consequently, canceling the dialog will not reset the feature to original
state).
callback_OK: function to be called upon OK. Invoked after writing values to feature,
committing transaction and closing the dialog.
callback_Cancel: called after closing the dialog and aborting transaction.
callback_Apply: invoked after writing values to feature."""
import AttachmentEditor.TaskAttachmentEditor as TaskAttachmentEditor
global taskd # exposing to outside, for ease of debugging
if feature is None:
feature = Gui.Selection.getSelectionEx()[0].Object
try:
taskd = TaskAttachmentEditor.AttachmentEditorTaskPanel(
feature,
take_selection=take_selection,
create_transaction=create_transaction,
callback_OK=callback_OK,
callback_Cancel=callback_Cancel,
callback_Apply=callback_Apply,
)
Gui.Control.showDialog(taskd)
except TaskAttachmentEditor.CancelError:
pass
class CommandEditAttachment:
"Command to edit attachment"
def GetResources(self):
return {
"Pixmap": "Part_Attachment",
"MenuText": QT_TRANSLATE_NOOP("Part_EditAttachment", "Attachment"),
"Accel": "",
"ToolTip": QT_TRANSLATE_NOOP(
"Part_EditAttachment",
"Opens the attachment editor to change the attachment of the selected object",
),
}
def Activated(self):
try:
editAttachment()
except Exception as err:
from PySide import QtGui
mb = QtGui.QMessageBox()
mb.setIcon(mb.Icon.Warning)
mb.setText(str(err))
mb.setWindowTitle("Error")
mb.exec_()
def IsActive(self):
sel = Gui.Selection.getSelectionEx()
if len(sel) == 1:
if hasattr(sel[0].Object, "Placement"):
return True
return False
if App.GuiUp:
import FreeCADGui as Gui
command_instance = CommandEditAttachment()
Gui.addCommand("Part_EditAttachment", command_instance)
|