From 5d9954d3daa7dbd661f6ee4383125060287efd8b Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Thu, 5 Nov 2015 10:51:50 +0100 Subject: [PATCH] FEM: split FemShellThickness into separate modules --- src/Mod/Fem/App/CMakeLists.txt | 9 +- src/Mod/Fem/CMakeLists.txt | 9 +- src/Mod/Fem/FemShellThickness.py | 197 +----------------- src/Mod/Fem/InitGui.py | 2 +- src/Mod/Fem/_CommandFemShellThickness.py | 57 +++++ src/Mod/Fem/_FemShellThickness.py | 40 ++++ src/Mod/Fem/_FemShellThicknessTaskPanel.py | 130 ++++++++++++ src/Mod/Fem/_ViewProviderFemShellThickness.py | 80 +++++++ 8 files changed, 331 insertions(+), 193 deletions(-) create mode 100644 src/Mod/Fem/_CommandFemShellThickness.py create mode 100644 src/Mod/Fem/_FemShellThickness.py create mode 100644 src/Mod/Fem/_FemShellThicknessTaskPanel.py create mode 100644 src/Mod/Fem/_ViewProviderFemShellThickness.py diff --git a/src/Mod/Fem/App/CMakeLists.txt b/src/Mod/Fem/App/CMakeLists.txt index 7d602c2dd5bf..1d363beb7fb0 100755 --- a/src/Mod/Fem/App/CMakeLists.txt +++ b/src/Mod/Fem/App/CMakeLists.txt @@ -73,8 +73,6 @@ SET(FemScripts_SRCS ccxFrdReader.py ccxInpWriter.py TestFem.py - FemShellThickness.py - FemShellThickness.ui FemBeamSection.py FemBeamSection.ui FemTools.py @@ -94,6 +92,13 @@ SET(FemScripts_SRCS _CommandMechanicalJobControl.py _CommandFemFromShape.py _CommandNewMechanicalAnalysis.py + + _FemShellThickness.py + _ViewProviderFemShellThickness.py + FemShellThickness.py + _CommandFemShellThickness.py + _FemShellThicknessTaskPanel.py + FemShellThickness.ui ) #SOURCE_GROUP("Scripts" FILES ${FemScripts_SRCS}) diff --git a/src/Mod/Fem/CMakeLists.txt b/src/Mod/Fem/CMakeLists.txt index a739c50d04af..e7fa9a5f8c13 100755 --- a/src/Mod/Fem/CMakeLists.txt +++ b/src/Mod/Fem/CMakeLists.txt @@ -18,8 +18,6 @@ INSTALL( FemBeamSection.py FemBeamSection.ui FemExample.py - FemShellThickness.py - FemShellThickness.ui MechanicalAnalysis.py MechanicalMaterial.py MechanicalMaterial.ui @@ -36,6 +34,13 @@ INSTALL( _CommandMechanicalJobControl.py _CommandFemFromShape.py _CommandNewMechanicalAnalysis.py + + _FemShellThickness.py + _ViewProviderFemShellThickness.py + FemShellThickness.py + _CommandFemShellThickness.py + _FemShellThicknessTaskPanel.py + FemShellThickness.ui DESTINATION Mod/Fem ) diff --git a/src/Mod/Fem/FemShellThickness.py b/src/Mod/Fem/FemShellThickness.py index 28cb0796e1b8..62d19fab46f2 100644 --- a/src/Mod/Fem/FemShellThickness.py +++ b/src/Mod/Fem/FemShellThickness.py @@ -20,204 +20,25 @@ # * * # *************************************************************************** +__title__ = "FemShellThickness" +__author__ = "Bernd Hahnebach" +__url__ = "http://www.freecadweb.org" + + import FreeCAD if FreeCAD.GuiUp: import FreeCADGui import FemGui - from PySide import QtGui - from PySide import QtCore - from pivy import coin - - -__title__ = "FemShellThickness" -__author__ = "Bernd Hahnebach" -__url__ = "http://www.freecadweb.org" def makeFemShellThickness(thickness=20.0, name="ShellThickness"): '''makeFemShellThickness([thickness], [name]): creates an shellthickness object to define a plate thickness''' obj = FemGui.getActiveAnalysis().Document.addObject("Fem::FeaturePython", name) - _FemShellThickness(obj) + import _FemShellThickness + _FemShellThickness._FemShellThickness(obj) obj.Thickness = thickness if FreeCAD.GuiUp: - _ViewProviderFemShellThickness(obj.ViewObject) + import _ViewProviderFemShellThickness + _ViewProviderFemShellThickness._ViewProviderFemShellThickness(obj.ViewObject) return obj - - -class _CommandFemShellThickness: - "The Fem_ShellThickness command definition" - def GetResources(self): - return {'Pixmap': 'fem-shell-thickness', - 'MenuText': QtCore.QT_TRANSLATE_NOOP("Fem_ShellThickness", "FEM Shell Plate Thickness Definition ..."), - 'Accel': "C, S", - 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Fem_ShellThickness", "Creates a FEM Shell Thickness")} - - def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create FemShellThickness") - FreeCADGui.addModule("FemShellThickness") - FreeCADGui.doCommand("FemGui.getActiveAnalysis().Member = FemGui.getActiveAnalysis().Member + [FemShellThickness.makeFemShellThickness()]") - - def IsActive(self): - if FemGui.getActiveAnalysis(): - return True - else: - return False - - -class _FemShellThickness: - "The FemShellThickness object" - def __init__(self, obj): - obj.addProperty("App::PropertyLength", "Thickness", "ShellThickness", "set thickness of the shell elements") - obj.addProperty("App::PropertyLinkSubList", "References", "ShellThickness", "List of shell thickness shapes") - obj.Proxy = self - self.Type = "FemShellThickness" - - def execute(self, obj): - return - - -class _ViewProviderFemShellThickness: - "A View Provider for the FemShellThickness object" - def __init__(self, vobj): - vobj.Proxy = self - - def getIcon(self): - return ":/icons/fem-shell-thickness.svg" - - def attach(self, vobj): - self.ViewObject = vobj - self.Object = vobj.Object - self.standard = coin.SoGroup() - vobj.addDisplayMode(self.standard, "Standard") - - def getDisplayModes(self, obj): - return ["Standard"] - - def getDefaultDisplayMode(self): - return "Standard" - - def updateData(self, obj, prop): - return - - def onChanged(self, vobj, prop): - return - - def setEdit(self, vobj, mode=0): - taskd = _FemShellThicknessTaskPanel(self.Object) - taskd.obj = vobj.Object - # taskd.update() When is this needed ? - FreeCADGui.Control.showDialog(taskd) - return True - - def unsetEdit(self, vobj, mode=0): - FreeCADGui.Control.closeDialog() - return - - def doubleClicked(self, vobj): - self.setEdit(vobj) - - def __getstate__(self): - return None - - def __setstate__(self, state): - return None - - -class _FemShellThicknessTaskPanel: - '''The TaskPanel for editing References property of FemShellThickness objects''' - def __init__(self, obj): - FreeCADGui.Selection.clearSelection() - self.sel_server = None - self.obj = obj - self.references = self.obj.References - - self.form = FreeCADGui.PySideUic.loadUi(FreeCAD.getHomePath() + "Mod/Fem/FemShellThickness.ui") - QtCore.QObject.connect(self.form.pushButton_Reference, QtCore.SIGNAL("clicked()"), self.add_references) - self.form.list_References.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) - self.form.list_References.connect(self.form.list_References, QtCore.SIGNAL("customContextMenuRequested(QPoint)"), self.references_list_right_clicked) - - self.rebuild_list_References() - - def accept(self): - if self.sel_server: - FreeCADGui.Selection.removeObserver(self.sel_server) - self.obj.References = self.references - FreeCADGui.ActiveDocument.resetEdit() - FreeCAD.ActiveDocument.recompute() - return True - - def reject(self): - if self.sel_server: - FreeCADGui.Selection.removeObserver(self.sel_server) - FreeCADGui.ActiveDocument.resetEdit() - return True - - def references_list_right_clicked(self, QPos): - self.form.contextMenu = QtGui.QMenu() - menu_item = self.form.contextMenu.addAction("Remove Reference") - if not self.references: - menu_item.setDisabled(True) - self.form.connect(menu_item, QtCore.SIGNAL("triggered()"), self.remove_reference) - parentPosition = self.form.list_References.mapToGlobal(QtCore.QPoint(0, 0)) - self.form.contextMenu.move(parentPosition + QPos) - self.form.contextMenu.show() - - def remove_reference(self): - if not self.references: - return - currentItemName = str(self.form.list_References.currentItem().text()) - for ref in self.references: - refname_to_compare_listentry = ref[0].Name + ':' + ref[1] - if refname_to_compare_listentry == currentItemName: - self.references.remove(ref) - self.rebuild_list_References() - - def add_references(self): - '''Called if Button add_reference is triggered''' - # in constraints EditTaskPanel the selection is active as soon as the taskpanel is open - # here the addReference button EditTaskPanel has to be triggered to start selection mode - FreeCADGui.Selection.clearSelection() - # start SelectionObserver and parse the function to add the References to the widget - self.sel_server = ReferenceShapeSelectionObserver(self.selectionParser) - - def selectionParser(self, selection): - # print('selection: ', selection[0].Shape.ShapeType, ' ', selection[0].Name, ' ', selection[1]) - if hasattr(selection[0], "Shape"): - elt = selection[0].Shape.getElement(selection[1]) - if elt.ShapeType == 'Face': - if selection not in self.references: - self.references.append(selection) - self.rebuild_list_References() - else: - print(selection[0].Name, '-->', selection[1], ' is already in reference list!') - else: - print('Selection has no shape!') - - def rebuild_list_References(self): - self.form.list_References.clear() - items = [] - for i in self.references: - item_name = i[0].Name + ':' + i[1] - items.append(item_name) - for listItemName in sorted(items): - listItem = QtGui.QListWidgetItem(listItemName, self.form.list_References) # listItem = is needed - - -class ReferenceShapeSelectionObserver: - '''ReferenceShapeSelectionObserver - started on click button addReference''' - def __init__(self, parseSelectionFunction): - self.parseSelectionFunction = parseSelectionFunction - FreeCADGui.Selection.addObserver(self) - FreeCAD.Console.PrintMessage("Select Faces to add them to the list!\n") - - def addSelection(self, docName, objName, sub, pos): - selected_object = FreeCAD.getDocument(docName).getObject(objName) # get the obj objName - self.added_obj = (selected_object, sub) - if sub: # on doubleClick the solid is selected and sub will be empty - self.parseSelectionFunction(self.added_obj) - - -if FreeCAD.GuiUp: - FreeCADGui.addCommand('Fem_ShellThickness', _CommandFemShellThickness()) diff --git a/src/Mod/Fem/InitGui.py b/src/Mod/Fem/InitGui.py index c2925c4a949f..0ea604a4e388 100644 --- a/src/Mod/Fem/InitGui.py +++ b/src/Mod/Fem/InitGui.py @@ -48,11 +48,11 @@ def Initialize(self): import _CommandMechanicalJobControl import _CommandFemFromShape import _CommandNewMechanicalAnalysis + import _CommandFemShellThickness import MechanicalAnalysis import MechanicalMaterial import FemBeamSection - import FemShellThickness import subprocess from platform import system diff --git a/src/Mod/Fem/_CommandFemShellThickness.py b/src/Mod/Fem/_CommandFemShellThickness.py new file mode 100644 index 000000000000..1731b29287a4 --- /dev/null +++ b/src/Mod/Fem/_CommandFemShellThickness.py @@ -0,0 +1,57 @@ +# *************************************************************************** +# * * +# * Copyright (c) 2015 - Bernd Hahnebach * +# * * +# * 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. * +# * * +# * This program 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 program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** + +__title__ = "_CommandFemShellThickness" +__author__ = "Bernd Hahnebach" +__url__ = "http://www.freecadweb.org" + + +import FreeCAD + +if FreeCAD.GuiUp: + import FreeCADGui + import FemGui + from PySide import QtCore + + +class _CommandFemShellThickness: + "The Fem_ShellThickness command definition" + def GetResources(self): + return {'Pixmap': 'fem-shell-thickness', + 'MenuText': QtCore.QT_TRANSLATE_NOOP("Fem_ShellThickness", "FEM Shell Plate Thickness Definition ..."), + 'Accel': "C, S", + 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Fem_ShellThickness", "Creates a FEM Shell Thickness")} + + def Activated(self): + FreeCAD.ActiveDocument.openTransaction("Create FemShellThickness") + FreeCADGui.addModule("FemShellThickness") + FreeCADGui.doCommand("FemGui.getActiveAnalysis().Member = FemGui.getActiveAnalysis().Member + [FemShellThickness.makeFemShellThickness()]") + + def IsActive(self): + if FemGui.getActiveAnalysis(): + return True + else: + return False + + +if FreeCAD.GuiUp: + FreeCADGui.addCommand('Fem_ShellThickness', _CommandFemShellThickness()) diff --git a/src/Mod/Fem/_FemShellThickness.py b/src/Mod/Fem/_FemShellThickness.py new file mode 100644 index 000000000000..413a368396fa --- /dev/null +++ b/src/Mod/Fem/_FemShellThickness.py @@ -0,0 +1,40 @@ +# *************************************************************************** +# * * +# * Copyright (c) 2015 - Bernd Hahnebach * +# * * +# * 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. * +# * * +# * This program 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 program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** + +__title__ = "_FemShellThickness" +__author__ = "Bernd Hahnebach" +__url__ = "http://www.freecadweb.org" + + +import FreeCAD + + +class _FemShellThickness: + "The FemShellThickness object" + def __init__(self, obj): + obj.addProperty("App::PropertyLength", "Thickness", "ShellThickness", "set thickness of the shell elements") + obj.addProperty("App::PropertyLinkSubList", "References", "ShellThickness", "List of shell thickness shapes") + obj.Proxy = self + self.Type = "FemShellThickness" + + def execute(self, obj): + return diff --git a/src/Mod/Fem/_FemShellThicknessTaskPanel.py b/src/Mod/Fem/_FemShellThicknessTaskPanel.py new file mode 100644 index 000000000000..ee1eb08bd1df --- /dev/null +++ b/src/Mod/Fem/_FemShellThicknessTaskPanel.py @@ -0,0 +1,130 @@ +# *************************************************************************** +# * * +# * Copyright (c) 2015 - Bernd Hahnebach * +# * * +# * 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. * +# * * +# * This program 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 program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** + +__title__ = "_FemShellThicknessTaskPanel" +__author__ = "Bernd Hahnebach" +__url__ = "http://www.freecadweb.org" + + +import FreeCAD + +if FreeCAD.GuiUp: + import FreeCADGui + import FemGui + from PySide import QtGui + from PySide import QtCore + from pivy import coin + + +class _FemShellThicknessTaskPanel: + '''The TaskPanel for editing References property of FemShellThickness objects''' + def __init__(self, obj): + FreeCADGui.Selection.clearSelection() + self.sel_server = None + self.obj = obj + self.references = self.obj.References + + self.form = FreeCADGui.PySideUic.loadUi(FreeCAD.getHomePath() + "Mod/Fem/FemShellThickness.ui") + QtCore.QObject.connect(self.form.pushButton_Reference, QtCore.SIGNAL("clicked()"), self.add_references) + self.form.list_References.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) + self.form.list_References.connect(self.form.list_References, QtCore.SIGNAL("customContextMenuRequested(QPoint)"), self.references_list_right_clicked) + + self.rebuild_list_References() + + def accept(self): + if self.sel_server: + FreeCADGui.Selection.removeObserver(self.sel_server) + self.obj.References = self.references + FreeCADGui.ActiveDocument.resetEdit() + FreeCAD.ActiveDocument.recompute() + return True + + def reject(self): + if self.sel_server: + FreeCADGui.Selection.removeObserver(self.sel_server) + FreeCADGui.ActiveDocument.resetEdit() + return True + + def references_list_right_clicked(self, QPos): + self.form.contextMenu = QtGui.QMenu() + menu_item = self.form.contextMenu.addAction("Remove Reference") + if not self.references: + menu_item.setDisabled(True) + self.form.connect(menu_item, QtCore.SIGNAL("triggered()"), self.remove_reference) + parentPosition = self.form.list_References.mapToGlobal(QtCore.QPoint(0, 0)) + self.form.contextMenu.move(parentPosition + QPos) + self.form.contextMenu.show() + + def remove_reference(self): + if not self.references: + return + currentItemName = str(self.form.list_References.currentItem().text()) + for ref in self.references: + refname_to_compare_listentry = ref[0].Name + ':' + ref[1] + if refname_to_compare_listentry == currentItemName: + self.references.remove(ref) + self.rebuild_list_References() + + def add_references(self): + '''Called if Button add_reference is triggered''' + # in constraints EditTaskPanel the selection is active as soon as the taskpanel is open + # here the addReference button EditTaskPanel has to be triggered to start selection mode + FreeCADGui.Selection.clearSelection() + # start SelectionObserver and parse the function to add the References to the widget + self.sel_server = ReferenceShapeSelectionObserver(self.selectionParser) + + def selectionParser(self, selection): + # print('selection: ', selection[0].Shape.ShapeType, ' ', selection[0].Name, ' ', selection[1]) + if hasattr(selection[0], "Shape"): + elt = selection[0].Shape.getElement(selection[1]) + if elt.ShapeType == 'Face': + if selection not in self.references: + self.references.append(selection) + self.rebuild_list_References() + else: + print(selection[0].Name, '-->', selection[1], ' is already in reference list!') + else: + print('Selection has no shape!') + + def rebuild_list_References(self): + self.form.list_References.clear() + items = [] + for i in self.references: + item_name = i[0].Name + ':' + i[1] + items.append(item_name) + for listItemName in sorted(items): + listItem = QtGui.QListWidgetItem(listItemName, self.form.list_References) # listItem = is needed + + +class ReferenceShapeSelectionObserver: + '''ReferenceShapeSelectionObserver + started on click button addReference''' + def __init__(self, parseSelectionFunction): + self.parseSelectionFunction = parseSelectionFunction + FreeCADGui.Selection.addObserver(self) + FreeCAD.Console.PrintMessage("Select Faces to add them to the list!\n") + + def addSelection(self, docName, objName, sub, pos): + selected_object = FreeCAD.getDocument(docName).getObject(objName) # get the obj objName + self.added_obj = (selected_object, sub) + if sub: # on doubleClick the solid is selected and sub will be empty + self.parseSelectionFunction(self.added_obj) diff --git a/src/Mod/Fem/_ViewProviderFemShellThickness.py b/src/Mod/Fem/_ViewProviderFemShellThickness.py new file mode 100644 index 000000000000..7ea1f456e9cd --- /dev/null +++ b/src/Mod/Fem/_ViewProviderFemShellThickness.py @@ -0,0 +1,80 @@ +# *************************************************************************** +# * * +# * Copyright (c) 2015 - Bernd Hahnebach * +# * * +# * 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. * +# * * +# * This program 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 program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** + +__title__ = "_ViewProviderFemShellThickness" +__author__ = "Bernd Hahnebach" +__url__ = "http://www.freecadweb.org" + + +import FreeCAD + +if FreeCAD.GuiUp: + import FreeCADGui + import FemGui + from pivy import coin + + +class _ViewProviderFemShellThickness: + "A View Provider for the FemShellThickness object" + def __init__(self, vobj): + vobj.Proxy = self + + def getIcon(self): + return ":/icons/fem-shell-thickness.svg" + + def attach(self, vobj): + self.ViewObject = vobj + self.Object = vobj.Object + self.standard = coin.SoGroup() + vobj.addDisplayMode(self.standard, "Standard") + + def getDisplayModes(self, obj): + return ["Standard"] + + def getDefaultDisplayMode(self): + return "Standard" + + def updateData(self, obj, prop): + return + + def onChanged(self, vobj, prop): + return + + def setEdit(self, vobj, mode=0): + import _FemShellThicknessTaskPanel + taskd = _FemShellThicknessTaskPanel._FemShellThicknessTaskPanel(self.Object) + taskd.obj = vobj.Object + FreeCADGui.Control.showDialog(taskd) + return True + + def unsetEdit(self, vobj, mode=0): + FreeCADGui.Control.closeDialog() + return + + def doubleClicked(self, vobj): + self.setEdit(vobj) + + def __getstate__(self): + return None + + def __setstate__(self, state): + return None