Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1954ae
commit 1973efa
Showing
4 changed files
with
314 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>Form</class> | ||
<widget class="QWidget" name="Form"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>350</width> | ||
<height>500</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Mesh group</string> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<item> | ||
<widget class="QGroupBox" name="groupBox_3"> | ||
<property name="maximumSize"> | ||
<size> | ||
<width>16777215</width> | ||
<height>1677215</height> | ||
</size> | ||
</property> | ||
<property name="title"> | ||
<string>Identifier used for mesh export</string> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout_5"> | ||
<item> | ||
<layout class="QFormLayout" name="formLayout_1"> | ||
<property name="fieldGrowthPolicy"> | ||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum> | ||
</property> | ||
<item row="1" column="0"> | ||
<widget class="QRadioButton" name="rb_name"> | ||
<property name="text"> | ||
<string>Name</string> | ||
</property> | ||
<property name="checked"> | ||
<bool>true</bool> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="1" column="1"> | ||
<widget class="QRadioButton" name="rb_label"> | ||
<property name="text"> | ||
<string>Label</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</item> | ||
</layout> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QGroupBox" name="groupBox_1"> | ||
<property name="title"> | ||
<string>References</string> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout_2"> | ||
<item> | ||
<widget class="QPushButton" name="pushButton_Reference"> | ||
<property name="text"> | ||
<string>Add reference</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QListWidget" name="list_References"/> | ||
</item> | ||
<item> | ||
<layout class="QGridLayout" name="gridLayout"> | ||
<item row="0" column="2"> | ||
<widget class="QRadioButton" name="rb_solid"> | ||
<property name="text"> | ||
<string>Solid</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="0" column="1"> | ||
<widget class="QRadioButton" name="rb_standard"> | ||
<property name="text"> | ||
<string>Face, Edge, Vertex</string> | ||
</property> | ||
<property name="checked"> | ||
<bool>true</bool> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="0" column="0"> | ||
<widget class="QLabel" name="l_label_text_5"> | ||
<property name="text"> | ||
<string><html><head/><body><p>Selection</p></body></html></string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</item> | ||
</layout> | ||
</widget> | ||
</item> | ||
<item> | ||
<spacer name="verticalSpacer_2"> | ||
<property name="orientation"> | ||
<enum>Qt::Vertical</enum> | ||
</property> | ||
<property name="sizeHint" stdset="0"> | ||
<size> | ||
<width>20</width> | ||
<height>40</height> | ||
</size> | ||
</property> | ||
</spacer> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |
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,190 @@ | ||
# *************************************************************************** | ||
# * * | ||
# * Copyright (c) 2016 - Bernd Hahnebach <bernd@bimstatik.org> * | ||
# * * | ||
# * 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__ = "_TaskPanelFemMeshGroup" | ||
__author__ = "Bernd Hahnebach" | ||
__url__ = "http://www.freecadweb.org" | ||
|
||
## @package TaskPanelFemMeshGroup | ||
# \ingroup FEM | ||
|
||
import FreeCAD | ||
import FreeCADGui | ||
from PySide import QtGui | ||
from PySide import QtCore | ||
|
||
|
||
class _TaskPanelFemMeshGroup: | ||
'''The TaskPanel for editing References property of FemMeshGroup objects''' | ||
def __init__(self, obj): | ||
FreeCADGui.Selection.clearSelection() | ||
self.sel_server = None | ||
self.obj = obj | ||
self.selection_mode_solid = False | ||
self.selection_mode_std_print_message = "Select Faces, Edges and Vertices by single click on them to add them to the list." | ||
self.selection_mode_solid_print_message = "Select Solids by single click on a Face or Edge which belongs to the Solid, to add the Solid to the list." | ||
|
||
self.form = FreeCADGui.PySideUic.loadUi(FreeCAD.getHomePath() + "Mod/Fem/TaskPanelFemMeshGroup.ui") | ||
QtCore.QObject.connect(self.form.rb_name, QtCore.SIGNAL("toggled(bool)"), self.choose_exportidentifier_name) | ||
QtCore.QObject.connect(self.form.rb_label, QtCore.SIGNAL("toggled(bool)"), self.choose_exportidentifier_label) | ||
QtCore.QObject.connect(self.form.rb_standard, QtCore.SIGNAL("toggled(bool)"), self.choose_selection_mode_standard) | ||
QtCore.QObject.connect(self.form.rb_solid, QtCore.SIGNAL("toggled(bool)"), self.choose_selection_mode_solid) | ||
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.get_meshgroup_props() | ||
self.update() | ||
|
||
def accept(self): | ||
self.set_meshgroup_props() | ||
if self.sel_server: | ||
FreeCADGui.Selection.removeObserver(self.sel_server) | ||
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 get_meshgroup_props(self): | ||
self.use_label = self.obj.UseLabel | ||
self.references = [] | ||
if self.obj.References: | ||
self.tuplereferences = self.obj.References | ||
self.get_references() | ||
|
||
def set_meshgroup_props(self): | ||
self.obj.References = self.references | ||
self.obj.UseLabel = self.use_label | ||
|
||
def update(self): | ||
'fills the widgets' | ||
self.form.rb_name.setChecked(not self.use_label) | ||
self.form.rb_label.setChecked(self.use_label) | ||
self.rebuild_list_References() | ||
|
||
def choose_exportidentifier_name(self, state): | ||
self.use_label = not state | ||
|
||
def choose_exportidentifier_label(self, state): | ||
self.use_label = state | ||
|
||
def choose_selection_mode_standard(self, state): | ||
self.selection_mode_solid = not state | ||
if self.sel_server and not self.selection_mode_solid: | ||
print(self.selection_mode_std_print_message) | ||
|
||
def choose_selection_mode_solid(self, state): | ||
self.selection_mode_solid = state | ||
if self.sel_server and self.selection_mode_solid: | ||
print(self.selection_mode_solid_print_message) | ||
|
||
def get_references(self): | ||
for ref in self.tuplereferences: | ||
for elem in ref[1]: | ||
self.references.append((ref[0], elem)) | ||
|
||
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 | ||
if self.selection_mode_solid: # print message on button click | ||
print_message = self.selection_mode_solid_print_message | ||
else: | ||
print_message = self.selection_mode_std_print_message | ||
import FemSelectionObserver | ||
self.sel_server = FemSelectionObserver.FemSelectionObserver(self.selectionParser, print_message) | ||
|
||
def selectionParser(self, selection): | ||
print('selection: ', selection[0].Shape.ShapeType, ' ', selection[0].Name, ' ', selection[1]) | ||
if hasattr(selection[0], "Shape") and selection[1]: | ||
elt = selection[0].Shape.getElement(selection[1]) | ||
if self.selection_mode_solid: | ||
# in solid selection mode use edges and faces for selection of a solid | ||
solid_to_add = None | ||
if elt.ShapeType == 'Edge': | ||
found_edge = False | ||
for i, s in enumerate(selection[0].Shape.Solids): | ||
for e in s.Edges: | ||
if elt.isSame(e): | ||
if not found_edge: | ||
solid_to_add = str(i + 1) | ||
else: | ||
FreeCAD.Console.PrintMessage('Edge belongs to more than one solid\n') | ||
solid_to_add = None | ||
found_edge = True | ||
elif elt.ShapeType == 'Face': | ||
found_face = False | ||
for i, s in enumerate(selection[0].Shape.Solids): | ||
for e in s.Faces: | ||
if elt.isSame(e): | ||
if not found_face: | ||
solid_to_add = str(i + 1) | ||
else: | ||
FreeCAD.Console.PrintMessage('Face belongs to more than one solid\n') | ||
solid_to_add = None | ||
found_edge = True | ||
if solid_to_add: | ||
selection = (selection[0], 'Solid' + solid_to_add) | ||
print('selection element changed to Solid: ', selection[0].Shape.ShapeType, ' ', selection[0].Name, ' ', selection[1]) | ||
else: | ||
return | ||
if selection not in self.references: | ||
self.references.append(selection) | ||
self.rebuild_list_References() | ||
else: | ||
FreeCAD.Console.PrintMessage(selection[0].Name + ' --> ' + selection[1] + ' is in reference list already!\n') | ||
|
||
def rebuild_list_References(self): | ||
self.form.list_References.clear() | ||
items = [] | ||
for ref in self.references: | ||
item_name = ref[0].Name + ':' + ref[1] | ||
items.append(item_name) | ||
for listItemName in sorted(items): | ||
self.form.list_References.addItem(listItemName) |