Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable to create group from other groups #42

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions mapclientplugins/scaffoldcreator/model/scaffoldcreatormodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,29 @@ def setCurrentAnnotationGroupByName(self, annotationGroupName):
annotationGroup = findAnnotationGroupByName(self.getAnnotationGroups(), annotationGroupName)
self.setCurrentAnnotationGroup(annotationGroup)

def addGroupToCurrentAnnotationGroup(self, annotationGroup):
"""
Set annotationGroup as current and replace the selection with its objects.
:param annotationGroup: AnnotationGroup to select.
"""
fieldmodule = self._region.getFieldmodule()
with ChangeManager(fieldmodule):
scene = self._region.getScene()
selectionGroup = get_scene_selection_group(scene)
if annotationGroup:
if not selectionGroup:
selectionGroup = create_scene_selection_group(scene)
group = annotationGroup.getGroup()
group_add_group_elements(selectionGroup, group, group_get_highest_dimension(group))
else:
if selectionGroup:
selectionGroup.clear()
scene.setSelectionField(Field())

def addGroupToCurrentAnnotationGroupByName(self, annotationGroupName):
annotationGroup = findAnnotationGroupByName(self.getAnnotationGroups(), annotationGroupName)
self.addGroupToCurrentAnnotationGroup(annotationGroup)

def _setScaffoldType(self, scaffoldType):
if len(self._scaffoldPackages) == 1:
# root scaffoldPackage
Expand Down
96 changes: 96 additions & 0 deletions mapclientplugins/scaffoldcreator/qt/creategroupdialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CreateGroupDialog</class>
<widget class="QDialog" name="CreateGroupDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>461</width>
<height>325</height>
</rect>
</property>
<property name="windowTitle">
<string>Create Group Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="configGroupBox">
<property name="title">
<string/>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<!-- <item row="0" column="1">
<widget class="QComboBox" name="annotationGroup_comboBox"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label0">
<property name="text">
<string>Group: </string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="delete_button">
<property name="text">
<string>Delete</string>
</property>
</widget>
</item> -->
<item row="1" column="1">
<widget class="QListWidget" name="selectedGroup_listWidget"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>CreateGroupDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>CreateGroupDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
51 changes: 51 additions & 0 deletions mapclientplugins/scaffoldcreator/view/creategroupdialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from PySide2 import QtCore, QtWidgets
from mapclientplugins.scaffoldcreator.view.ui_creategroupdialog import Ui_CreateGroupDialog

class CreateGroupDialog(QtWidgets.QDialog):
"""
CreateGroup dialog to present the user with the options to create group.
"""

def __init__(self, grouplist, parent=None):
QtWidgets.QDialog.__init__(self, parent)

self._ui = Ui_CreateGroupDialog()
self._ui.setupUi(self)

self._groupList = grouplist
self._selectedGroupList = []
self._parent = parent

self._makeConnections()

def _makeConnections(self):
# self._parent._refreshComboBoxNames(
# self._ui.annotationGroup_comboBox,
# ['-'] + [annotationGroup.getName() for annotationGroup in self._groupList],
# '-')
self._buildSelectedGroupList()


def _buildSelectedGroupList(self):
"""
Fill the group list widget with the list of groups
"""
if self._ui.selectedGroup_listWidget is not None:
self._ui.selectedGroup_listWidget.clear() # Must clear or holds on to steps references
for group in self._groupList:
item = QtWidgets.QListWidgetItem(group.getName())
item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)
item.setCheckState(QtCore.Qt.Unchecked)
self._ui.selectedGroup_listWidget.addItem(item)

def getSelectedGroupList(self):
for index in range(self._ui.selectedGroup_listWidget.count()):
if self._ui.selectedGroup_listWidget.item(index).checkState() == QtCore.Qt.Checked:
self._selectedGroupList.append(self._ui.selectedGroup_listWidget.item(index).text())
return self._selectedGroupList

def accept(self):
"""
Override the accept method
"""
QtWidgets.QDialog.accept(self)
15 changes: 14 additions & 1 deletion mapclientplugins/scaffoldcreator/view/scaffoldcreatorwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from mapclientplugins.scaffoldcreator.view.ui_scaffoldcreatorwidget import Ui_ScaffoldCreatorWidget
from mapclientplugins.scaffoldcreator.view.functionoptionsdialog import FunctionOptionsDialog
from mapclientplugins.scaffoldcreator.view.creategroupdialog import CreateGroupDialog
from opencmiss.maths.vectorops import dot, magnitude, mult, normalize, sub
from opencmiss.utils.zinc.field import fieldIsManagedCoordinates
from scaffoldmaker.scaffoldpackage import ScaffoldPackage
Expand Down Expand Up @@ -275,6 +276,18 @@ def _annotationGroupChanged(self, index):
self._refreshCurrentAnnotationGroupSettings()

def _annotationGroupNewButtonClicked(self):
reply = QtWidgets.QMessageBox.question(
self, 'Confirm action',
'Add other groups?',
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No)
if reply == QtWidgets.QMessageBox.Yes:
groupList = []
annotationGroups = self._scaffold_model.getAnnotationGroups()
dlg = CreateGroupDialog(annotationGroups, self)
if dlg.exec_():
groupList = dlg.getSelectedGroupList()
for i in groupList:
self._scaffold_model.addGroupToCurrentAnnotationGroupByName(i)
self._scaffold_model.createUserAnnotationGroup()
self._refreshAnnotationGroups()
self._refreshCurrentAnnotationGroupSettings()
Expand All @@ -297,7 +310,7 @@ def _annotationGroupRedefineButtonClicked(self):

def _annotationGroupDeleteButtonClicked(self):
annotationGroup = self._scaffold_model.getCurrentAnnotationGroup()
if annotationGroup:
if annotationGroup:
reply = QtWidgets.QMessageBox.question(
self, 'Confirm action',
'Delete annotation group \'' + annotationGroup.getName() + '\'?',
Expand Down
55 changes: 55 additions & 0 deletions mapclientplugins/scaffoldcreator/view/ui_creategroupdialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file 'creategroupdialog.ui'
##
## Created by: Qt User Interface Compiler version 5.15.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *


class Ui_CreateGroupDialog(object):
def setupUi(self, CreateGroupDialog):
if not CreateGroupDialog.objectName():
CreateGroupDialog.setObjectName(u"CreateGroupDialog")
CreateGroupDialog.resize(461, 325)
self.gridLayout = QGridLayout(CreateGroupDialog)
self.gridLayout.setObjectName(u"gridLayout")
self.buttonBox = QDialogButtonBox(CreateGroupDialog)
self.buttonBox.setObjectName(u"buttonBox")
self.buttonBox.setOrientation(Qt.Horizontal)
self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok)

self.gridLayout.addWidget(self.buttonBox, 2, 0, 1, 1)

self.configGroupBox = QGroupBox(CreateGroupDialog)
self.configGroupBox.setObjectName(u"configGroupBox")
self.formLayout = QFormLayout(self.configGroupBox)
self.formLayout.setObjectName(u"formLayout")
self.formLayout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)
self.selectedGroup_listWidget = QListWidget(self.configGroupBox)
self.selectedGroup_listWidget.setObjectName(u"selectedGroup_listWidget")

self.formLayout.setWidget(1, QFormLayout.FieldRole, self.selectedGroup_listWidget)


self.gridLayout.addWidget(self.configGroupBox, 1, 0, 1, 1)


self.retranslateUi(CreateGroupDialog)
self.buttonBox.accepted.connect(CreateGroupDialog.accept)
self.buttonBox.rejected.connect(CreateGroupDialog.reject)

QMetaObject.connectSlotsByName(CreateGroupDialog)
# setupUi

def retranslateUi(self, CreateGroupDialog):
CreateGroupDialog.setWindowTitle(QCoreApplication.translate("CreateGroupDialog", u"Create Group Dialog", None))
self.configGroupBox.setTitle("")
# retranslateUi