Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attacher: add general purpose editor UI (python)
Added as PartGui.AttachmentEditor, and Part_EditAttachment gui command
- Loading branch information
Showing
12 changed files
with
1,378 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#/*************************************************************************** | ||
# * Copyright (c) Victor Titov (DeepSOIC) * | ||
# * (vv.titov@gmail.com) 2016 * | ||
# * * | ||
# * 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 | ||
from PySide import QtCore | ||
|
||
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 transation 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 {'MenuText': QtCore.QT_TRANSLATE_NOOP("AttachmentEditor","Attachment..."), | ||
'Accel': "", | ||
'ToolTip': QtCore.QT_TRANSLATE_NOOP("AttachmentEditor","Edit attachment of 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(err.message) | ||
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: | ||
global command_instance | ||
import FreeCADGui as Gui | ||
command_instance = CommandEditAttachment() | ||
Gui.addCommand('Part_EditAttachment', command_instance) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#/*************************************************************************** | ||
# * Copyright (c) Victor Titov (DeepSOIC) * | ||
# * (vv.titov@gmail.com) 2016 * | ||
# * * | ||
# * 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 * | ||
# * * | ||
# ***************************************************************************/ | ||
|
||
import FreeCAD as App | ||
|
||
def getAllDependencies(feat): | ||
'''getAllDependencies(feat): gets all features feat depends on, directly or indirectly. | ||
Returns a list, with deepest dependencies last. feat is not included in the list, except | ||
if the feature depends on itself (dependency loop).''' | ||
list_traversing_now = [feat] | ||
set_of_deps = set() | ||
list_of_deps = [] | ||
|
||
while len(list_traversing_now) > 0: | ||
list_to_be_traversed_next = [] | ||
for feat in list_traversing_now: | ||
for dep in feat.OutList: | ||
if not (dep in set_of_deps): | ||
set_of_deps.add(dep) | ||
list_of_deps.append(dep) | ||
list_to_be_traversed_next.append(dep) | ||
|
||
list_traversing_now = list_to_be_traversed_next | ||
|
||
return list_of_deps | ||
|
||
def getAllDependent(feat): | ||
'''getAllDependent(feat): gets all features that depend on feat, directly or indirectly. | ||
Returns a list, with deepest dependencies last. feat is not included in the list, except | ||
if the feature depends on itself (dependency loop).''' | ||
list_traversing_now = [feat] | ||
set_of_deps = set() | ||
list_of_deps = [] | ||
|
||
while len(list_traversing_now) > 0: | ||
list_to_be_traversed_next = [] | ||
for feat in list_traversing_now: | ||
for dep in feat.InList: | ||
if not (dep in set_of_deps): | ||
set_of_deps.add(dep) | ||
list_of_deps.append(dep) | ||
list_to_be_traversed_next.append(dep) | ||
|
||
list_traversing_now = list_to_be_traversed_next | ||
|
||
return list_of_deps | ||
|
||
def isContainer(obj): | ||
'''isContainer(obj): returns True if obj is an object container, such as | ||
Group, Part, Body. The important characterisic of an object being a | ||
container is its action on visibility of linked objects. E.g. a | ||
Part::Compound is not a group, because it does not affect visibility | ||
of originals. Documents are considered containers, too.''' | ||
|
||
if obj.isDerivedFrom("App::DocumentObjectGroup"): | ||
return True | ||
if obj.isDerivedFrom("PartDesign::Body"): | ||
return True | ||
if obj.isDerivedFrom("App::Origin"): | ||
return True | ||
if obj.isDerivedFrom('App::Document'): | ||
return True |
Oops, something went wrong.