From c41216a939a3e3d8fbcddd1cd68ce4fe0bf34132 Mon Sep 17 00:00:00 2001 From: sudo-panda Date: Mon, 29 Apr 2019 14:02:13 +0530 Subject: [PATCH 1/3] Add dialog in import process to enable selective import of states to add #91 --- .../gui/dialogs/selectstatesdialog.py | 87 +++++++++++++++++++ src/visualstates/gui/visualstates.py | 5 ++ 2 files changed, 92 insertions(+) create mode 100644 src/visualstates/gui/dialogs/selectstatesdialog.py diff --git a/src/visualstates/gui/dialogs/selectstatesdialog.py b/src/visualstates/gui/dialogs/selectstatesdialog.py new file mode 100644 index 00000000..2a99503d --- /dev/null +++ b/src/visualstates/gui/dialogs/selectstatesdialog.py @@ -0,0 +1,87 @@ +''' + Copyright (C) 1997-2018 JDERobot Developers Team + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + 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 General Public License + along with this program; if not, see . + + Authors : Baidyanath Kundu (kundubaidya99@gmail.com) + + ''' + +import sys +from PyQt5.QtWidgets import QDialog, \ + QPushButton, QTreeWidget, \ + QApplication, QGridLayout, \ + QTreeWidgetItem, QLabel +from PyQt5.QtCore import pyqtSignal, \ + Qt + +class SelectStatesDialog(QDialog): + fileChanged = pyqtSignal(list) + + def __init__(self, name, file): + super(QDialog, self).__init__() + self.setWindowTitle(name) + self.setFixedSize(400, 600) + self.file = file + self.list = [] + + self.drawWindow() + + def drawWindow(self): + gridLayout = QGridLayout() + + gridLayout.addWidget(QLabel("Select States"), 0, 0) + + self.treeWidget = QTreeWidget(self) + gridLayout.addWidget(self.treeWidget, 1, 0) + headerItem = QTreeWidgetItem() + headerItem.setText(0, "Name") + self.treeWidget.setHeaderItem(headerItem) + self.loadStates(self.treeWidget, self.file[0]) + + self.button = QPushButton(self) + self.button.setText("Ok") + gridLayout.addWidget(self.button, 2, 0, alignment=Qt.AlignRight) + self.button.clicked.connect(self.buttonClicked) + + self.setLayout(gridLayout) + + def loadStates(self, parentItem, parentState): + for child in parentState.getChildren(): + if type(parentItem) == QTreeWidgetItem: + parentItem.setFlags(parentItem.flags() | Qt.ItemIsTristate) + item = QTreeWidgetItem(parentItem) + item.setText(0, child.name) + item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) + item.setCheckState(0, Qt.Checked) + if len(self.list) < child.id: + self.list.extend([None] * (child.id - len(self.list))) + self.list[child.id - 1] = item + self.loadStates(item, child) + + def removeStates(self, parentState): + for child in parentState.getChildren(): + if self.list[child.id - 1].checkState(0) == Qt.Unchecked: + parentState.removeChild(child) + else: + self.removeStates(child) + + def buttonClicked(self, event): + self.removeStates(self.file[0]) + self.close() + +if __name__ == '__main__': + app = QApplication(sys.argv) + dialog = SelectStatesDialog('Select States', ['hmm']) + dialog.exec_() \ No newline at end of file diff --git a/src/visualstates/gui/visualstates.py b/src/visualstates/gui/visualstates.py index af260972..d7709b85 100644 --- a/src/visualstates/gui/visualstates.py +++ b/src/visualstates/gui/visualstates.py @@ -27,6 +27,7 @@ from .dialogs.namespacedialog import NamespaceDialog from .dialogs.librariesdialog import LibrariesDialog from .dialogs.rosconfigdialog import RosConfigDialog +from .dialogs.selectstatesdialog import SelectStatesDialog from ..configs.rosconfig import RosConfig from ..generators.cpprosgenerator import CppRosGenerator from ..generators.pythonrosgenerator import PythonRosGenerator @@ -264,6 +265,10 @@ def importAction(self): for childState in file[0].getChildren(): childState.setInitial(False) + selectStates = SelectStatesDialog('Import VisualStates File', file) + if not selectStates.exec_(): + file = selectStates.file + # Update importing Namespaces importedState, self.config, self.libraries, self.globalNamespace = self.importManager.updateAuxiliaryData(file, self) self.treeModel.loadFromRoot(importedState, self.activeState) From c336c2f14ea71ade5821a74ed9aa0db6ae270c63 Mon Sep 17 00:00:00 2001 From: sudo-panda Date: Wed, 8 May 2019 23:10:50 +0530 Subject: [PATCH 2/3] Rectify removal of child states by adding them to a list to be removed later --- src/visualstates/gui/dialogs/selectstatesdialog.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/visualstates/gui/dialogs/selectstatesdialog.py b/src/visualstates/gui/dialogs/selectstatesdialog.py index 2a99503d..5691da83 100644 --- a/src/visualstates/gui/dialogs/selectstatesdialog.py +++ b/src/visualstates/gui/dialogs/selectstatesdialog.py @@ -71,11 +71,14 @@ def loadStates(self, parentItem, parentState): self.loadStates(item, child) def removeStates(self, parentState): + remList = [] for child in parentState.getChildren(): if self.list[child.id - 1].checkState(0) == Qt.Unchecked: - parentState.removeChild(child) + remList.append(child) else: self.removeStates(child) + for child in remList: + parentState.removeChild(child) def buttonClicked(self, event): self.removeStates(self.file[0]) From 4bf8898adc13b3d0f9084064a216ca9ec454bd2a Mon Sep 17 00:00:00 2001 From: sudo-panda Date: Tue, 4 Jun 2019 19:13:06 +0530 Subject: [PATCH 3/3] Remove transitions that point to removed states --- src/visualstates/gui/dialogs/selectstatesdialog.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/visualstates/gui/dialogs/selectstatesdialog.py b/src/visualstates/gui/dialogs/selectstatesdialog.py index 5691da83..224c284d 100644 --- a/src/visualstates/gui/dialogs/selectstatesdialog.py +++ b/src/visualstates/gui/dialogs/selectstatesdialog.py @@ -78,6 +78,8 @@ def removeStates(self, parentState): else: self.removeStates(child) for child in remList: + for transition in child.getDestTransitions(): + transition.origin.removeOriginTransition(transition) parentState.removeChild(child) def buttonClicked(self, event):