diff --git a/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/StatechartEditorController.cpp b/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/StatechartEditorController.cpp index 5407f4cb19bf0b92c96a33f16dea71fd2da2bb8b..9a828da8cf44d4eb433b16454976665295b91e50 100644 --- a/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/StatechartEditorController.cpp +++ b/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/StatechartEditorController.cpp @@ -23,23 +23,7 @@ */ #include "StatechartEditorController.h" -#include "view/StatechartEditorMainWindow.h" -#include <ArmarXGui/gui-plugins/StatechartViewerPlugin/view/StateTabWidget.h> - -#include "model/StateTreeModel.h" -#include "io/GroupXmlReader.h" -#include "io/GroupXmlWriter.h" -#include "view/dialogs/EditStatechartGroupDialog.h" -#include "view/dialogs/StatechartEditorSettingsDialog.h" -#include <ArmarXGui/libraries/ArmarXGuiBase/widgets/TipDialog.h> - -#include "../StatechartViewerPlugin/view/StatechartView.h" -#include "../StatechartViewerPlugin/view/StateItem.h" -#include <ArmarXCore/core/system/ArmarXDataPath.h> -#include <ArmarXCore/core/application/Application.h> -#include <ArmarXCore/interface/statechart/RemoteStateOffererIce.h> - -#include <IceUtil/UUID.h> +#include <filesystem> #include <QCoreApplication> #include <QInputDialog> @@ -47,9 +31,25 @@ #include <QMessageBox> #include <QTimer> +#include <IceUtil/UUID.h> + #include <SimoxUtility/algorithm/string/string_tools.h> -#include <filesystem> +#include <ArmarXCore/core/application/Application.h> +#include <ArmarXCore/core/system/ArmarXDataPath.h> +#include <ArmarXCore/interface/statechart/RemoteStateOffererIce.h> + +#include <ArmarXGui/gui-plugins/StatechartViewerPlugin/view/StateTabWidget.h> +#include <ArmarXGui/libraries/ArmarXGuiBase/widgets/TipDialog.h> + +#include "../StatechartViewerPlugin/view/StateItem.h" +#include "../StatechartViewerPlugin/view/StatechartView.h" +#include "io/GroupXmlReader.h" +#include "io/GroupXmlWriter.h" +#include "model/StateTreeModel.h" +#include "view/StatechartEditorMainWindow.h" +#include "view/dialogs/EditStatechartGroupDialog.h" +#include "view/dialogs/StatechartEditorSettingsDialog.h" namespace armarx { @@ -64,17 +64,15 @@ namespace armarx QSettings s("KIT", "ArmarXStatechartEditor"); config.lockRemoteStates = s.value("lockRemoteStates", true).toBool(); config.searchPaths = s.value("searchPaths").toStringList(); - - } - StatechartEditorController::~StatechartEditorController() { storeAutoSaveSettings(); } - void StatechartEditorController::storeAutoSaveSettings() + void + StatechartEditorController::storeAutoSaveSettings() { ARMARX_INFO << "Updating auto-storage config"; QSettings s("KIT", "ArmarXStatechartEditor"); @@ -82,7 +80,8 @@ namespace armarx s.setValue("searchPaths", config.searchPaths); } - QStringList StatechartEditorController::findAllStatechartGroupDefinitions(const QString& basePath) + QStringList + StatechartEditorController::findAllStatechartGroupDefinitions(const QString& basePath) { QStringList result; if (basePath.isEmpty()) @@ -94,7 +93,8 @@ namespace armarx int i = 0; for (std::filesystem::recursive_directory_iterator end, dir(basePath.toUtf8().data()); - dir != end && getState() < eManagedIceObjectExiting; ++dir, i++) + dir != end && getState() < eManagedIceObjectExiting; + ++dir, i++) { std::string path(dir->path().c_str()); // search for all statechart group xml files @@ -125,24 +125,28 @@ namespace armarx return result; } - void StatechartEditorController::onInitComponent() + void + StatechartEditorController::onInitComponent() { packageTool.reset(new ArmarXPackageToolInterface()); - } - void StatechartEditorController::onConnectComponent() + void + StatechartEditorController::onConnectComponent() { QTimer::singleShot(0, this, SLOT(initWidget())); stateWatcher = new StateWatcher(); - getArmarXManager()->addObject(stateWatcher, "StateWatcher" + IceUtil::generateUUID(), false); + getArmarXManager()->addObject( + stateWatcher, "StateWatcher" + IceUtil::generateUUID(), false); } - void StatechartEditorController::onDisconnectComponent() + void + StatechartEditorController::onDisconnectComponent() { } - void StatechartEditorController::onExitComponent() + void + StatechartEditorController::onExitComponent() { if (executionStatusTask) { @@ -150,7 +154,8 @@ namespace armarx } } - void StatechartEditorController::loadSettings(QSettings* settings) + void + StatechartEditorController::loadSettings(QSettings* settings) { // searchPaths = settings->value("paths").toStringList(); // int size = settings->beginReadArray("groups"); @@ -162,12 +167,14 @@ namespace armarx // settings->endArray(); if (!profiles) { - profiles = StatechartProfiles::ReadProfileFiles(Application::getInstance()->getDefaultPackageNames()); + profiles = StatechartProfiles::ReadProfileFiles( + Application::getInstance()->getDefaultPackageNames()); } if (settings->contains("selectedProfile")) { - config.selectedProfile = profiles->getProfileByName(settings->value("selectedProfile").toString().toStdString()); + config.selectedProfile = profiles->getProfileByName( + settings->value("selectedProfile").toString().toStdString()); } else if (getConfigDialog(getWidget())->exec() == QDialog::Accepted) { @@ -181,7 +188,8 @@ namespace armarx config.openAllStatesWasSelected = settings->value("openAllStatesSelected", false).toBool(); } - void StatechartEditorController::saveSettings(QSettings* settings) + void + StatechartEditorController::saveSettings(QSettings* settings) { // settings->setValue("paths", searchPaths); // if(treeController) @@ -200,22 +208,25 @@ namespace armarx if (config.selectedProfile) { - settings->setValue("selectedProfile", QString::fromStdString(config.selectedProfile->getName())); + settings->setValue("selectedProfile", + QString::fromStdString(config.selectedProfile->getName())); } settings->setValue("openAllStatesSelected", config.openAllStatesWasSelected); - } - - void StatechartEditorController::treeviewGroupsDoubleClicked(QModelIndex index) + void + StatechartEditorController::treeviewGroupsDoubleClicked(QModelIndex index) { StateTreeNodePtr node = treeController->getNode(index); if (node && node->getState()) { int index = editor->getStateTabWidget()->getStateTab(node->getState()); - getTipDialog()->showMessage("You can move states by holding the SHIFT + left click button. You can move the scene by holding ALT + move mouse.", "State Interaction"); + getTipDialog()->showMessage( + "You can move states by holding the SHIFT + left click button. You can move the " + "scene by holding ALT + move mouse.", + "State Interaction"); if (index < 0) { @@ -226,15 +237,16 @@ namespace armarx editor->getStateTabWidget()->setCurrentIndex(index); } } - } - void StatechartEditorController::requestSave() + void + StatechartEditorController::requestSave() { treeController->saveAll(); } - void StatechartEditorController::onStateTabChanged(int index) + void + StatechartEditorController::onStateTabChanged(int index) { StatechartView* view = editor->getUI()->stateTabWidget->stateview(index); @@ -246,19 +258,33 @@ namespace armarx } } - void StatechartEditorController::showNewStatechartGroupDialog() + void + StatechartEditorController::showNewStatechartGroupDialog() { QList<QString> selectedProxies; // enable statechart context generation for new groups by default - EditStatechartGroupDialog d(EditStatechartGroupDialog::NewGroup, "", packageTool, variantInfo, selectedProxies, true, profiles); + EditStatechartGroupDialog d(EditStatechartGroupDialog::NewGroup, + "", + packageTool, + variantInfo, + selectedProxies, + true, + profiles); if (d.exec() == QDialog::Accepted) { - StatechartGroupPtr g = treeController->addNewGroup(d.getGroupName(), d.getGroupPath(), d.getGroupDescription(), d.getPackageName(), d.getProxies(), d.contextGenerationEnabled(), d.getConfigurations()); + StatechartGroupPtr g = treeController->addNewGroup(d.getGroupName(), + d.getGroupPath(), + d.getGroupDescription(), + d.getPackageName(), + d.getProxies(), + d.contextGenerationEnabled(), + d.getConfigurations()); } } - void StatechartEditorController::showStatechartEditorSettingsDialog() + void + StatechartEditorController::showStatechartEditorSettingsDialog() { StatechartEditorSettingsDialog d; d.setPaths(config.searchPaths); @@ -280,7 +306,8 @@ namespace armarx } } - void StatechartEditorController::openStatechartGroups(QStringList groups) + void + StatechartEditorController::openStatechartGroups(QStringList groups) { editor->getUI()->treeViewProgressBar->show(); editor->getUI()->treeViewProgressBar->setMaximum(groups.size()); @@ -295,7 +322,8 @@ namespace armarx editor->getUI()->treeViewProgressBar->hide(); } - void StatechartEditorController::searchAndOpenPaths(QStringList paths) + void + StatechartEditorController::searchAndOpenPaths(QStringList paths) { paths.removeDuplicates(); QStringList groups; @@ -306,18 +334,22 @@ namespace armarx openStatechartGroups(groups); } - - void StatechartEditorController::connectToView(int tabIndex) + void + StatechartEditorController::connectToView(int tabIndex) { StatechartView* view = editor->getUI()->stateTabWidget->currentStateview(); if (view) { - connect(view, SIGNAL(selectedStateChanged(statechartmodel::StateInstancePtr)), this, SLOT(showStateCode(statechartmodel::StateInstancePtr))); + connect(view, + SIGNAL(selectedStateChanged(statechartmodel::StateInstancePtr)), + this, + SLOT(showStateCode(statechartmodel::StateInstancePtr))); } } - void StatechartEditorController::showStateCode(statechartmodel::StateInstancePtr stateInstance) + void + StatechartEditorController::showStateCode(statechartmodel::StateInstancePtr stateInstance) { if (stateInstance && stateInstance->getStateClass()) { @@ -329,10 +361,10 @@ namespace armarx showCodeFileContent(QString::fromStdString(filePath)); } } - } - void StatechartEditorController::showCodeFileContent(const QString& path) + void + StatechartEditorController::showCodeFileContent(const QString& path) { watcher->removePath(path); std::string fileContent; @@ -352,45 +384,46 @@ namespace armarx cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, line); editor->getUI()->textEditCppCode->setText(QString::fromUtf8(fileContent.c_str())); editor->getUI()->textEditCppCode->setTextCursor(cursor); - } - - void StatechartEditorController::showOnEnterFunction() + void + StatechartEditorController::showOnEnterFunction() { editor->getUI()->textEditCppCode->find("::CreateInstance("); editor->getUI()->textEditCppCode->find("::onEnter()", QTextDocument::FindBackward); } - void StatechartEditorController::showRunFunction() + void + StatechartEditorController::showRunFunction() { editor->getUI()->textEditCppCode->find("::CreateInstance("); editor->getUI()->textEditCppCode->find("::run()", QTextDocument::FindBackward); - } - void StatechartEditorController::showOnBreakFunction() + void + StatechartEditorController::showOnBreakFunction() { editor->getUI()->textEditCppCode->find("::CreateInstance("); editor->getUI()->textEditCppCode->find("::onBreak()", QTextDocument::FindBackward); - } - void StatechartEditorController::showOnExitFunction() + void + StatechartEditorController::showOnExitFunction() { editor->getUI()->textEditCppCode->find("::CreateInstance("); editor->getUI()->textEditCppCode->find("::onExit()", QTextDocument::FindBackward); - } - void StatechartEditorController::openSelectedState() + void + StatechartEditorController::openSelectedState() { statechartmodel::StatePtr state; if (editor->getUI()->stateTabWidget->currentStateview()) { - auto selection = editor->getUI()->stateTabWidget->currentStateview()->getScene()->selectedItems(); + auto selection = + editor->getUI()->stateTabWidget->currentStateview()->getScene()->selectedItems(); for (QGraphicsItem* item : selection) { @@ -407,10 +440,8 @@ namespace armarx break; } } - } } - } if (state) @@ -426,30 +457,35 @@ namespace armarx { showMessageBox("No state with a StateClass is selected"); } - } - void StatechartEditorController::closeAllTabs() + void + StatechartEditorController::closeAllTabs() { editor->getStateTabWidget()->clear(); } - void StatechartEditorController::executeOpenedState(bool) + void + StatechartEditorController::executeOpenedState(bool) { StatechartView* view = editor->getUI()->stateTabWidget->currentStateview(); if (!executedOpenedGroup) { if (view) { - auto node = treeController->getNodeByState(view->getStateInstance()->getStateClass()); + auto node = + treeController->getNodeByState(view->getStateInstance()->getStateClass()); if (node) { if (node->isPublic()) { - treeController->executeGroupWithDependencies(node->getGroup(), view->getStateInstance()->getStateClass()->getStateName()); + treeController->executeGroupWithDependencies( + node->getGroup(), + view->getStateInstance()->getStateClass()->getStateName()); executedOpenedGroup = node->getGroup(); editor->getUI()->toolButtonRunState->setIcon(QIcon(":/icons/delete.ico")); - editor->getUI()->toolButtonRunState->setToolTip("Stop the Statechart Group"); + editor->getUI()->toolButtonRunState->setToolTip( + "Stop the Statechart Group"); editor->getUI()->toolButtonWatchStateExecution->setEnabled(false); editor->getUI()->labelExecutionState->setVisible(true); alreadyWatchingState = false; @@ -457,13 +493,20 @@ namespace armarx } else { - QMessageBox::warning(editor, "Execution not possible", "You can only execute public state. Right-click on the state in the tree view on the left and select 'Public State'."); + QMessageBox::warning( + editor, + "Execution not possible", + "You can only execute public state. Right-click on the state in the " + "tree view on the left and select 'Public State'."); } } } else { - QMessageBox::warning(editor, "Execution not possible", "You need to open a state before executing it with this button."); + QMessageBox::warning( + editor, + "Execution not possible", + "You need to open a state before executing it with this button."); } } else @@ -482,8 +525,8 @@ namespace armarx { view->getScene()->clearActiveSubstates(); } - std::function<void(StateItem* state)> unsubscriptionLamba; - unsubscriptionLamba = [&](StateItem * state) + std::function<void(StateItem * state)> unsubscriptionLamba; + unsubscriptionLamba = [&](StateItem* state) { stateWatcher->unsubscribeState(state); for (auto stateInstance : state->getSubstateItems()) @@ -496,18 +539,22 @@ namespace armarx }; unsubscriptionLamba(view->getScene()->getTopLevelStateItem()); } - } - void StatechartEditorController::updateExecutionButtonStatus() + void + StatechartEditorController::updateExecutionButtonStatus() { bool changeToWaiting = false; QString labelText = ""; if (executedOpenedGroup) { - std::string proxyName = executedOpenedGroup->getName().toStdString() + "StateComponentAppManager"; - std::string objName = config.selectedProfile->getName() + executedOpenedGroup->getName().toStdString() + "RemoteStateOfferer"; - ArmarXManagerInterfacePrx stateComponentProxy = getProxy<ArmarXManagerInterfacePrx>(proxyName, false, "", false); + std::string proxyName = + executedOpenedGroup->getName().toStdString() + "StateComponentAppManager"; + std::string objName = config.selectedProfile->getName() + + executedOpenedGroup->getName().toStdString() + + "RemoteStateOfferer"; + ArmarXManagerInterfacePrx stateComponentProxy = + getProxy<ArmarXManagerInterfacePrx>(proxyName, false, "", false); try { if (getArmarXManager()->getIceManager()->isObjectReachable(objName)) @@ -520,7 +567,8 @@ namespace armarx if (state != eManagedIceObjectStarted) { Ice::StringSeq deps; - for (auto elem : stateComponentProxy->getObjectConnectivity(objName).dependencies) + for (auto elem : + stateComponentProxy->getObjectConnectivity(objName).dependencies) { ManagedIceObjectDependencyBasePtr dep = elem.second; if (!dep->getResolved()) @@ -536,7 +584,8 @@ namespace armarx } } } - labelText = "Waiting for dependencies: " + QString::fromStdString(simox::alg::join(deps, ", ")); + labelText = "Waiting for dependencies: " + + QString::fromStdString(simox::alg::join(deps, ", ")); changeToWaiting = true; } } @@ -561,28 +610,37 @@ namespace armarx if (!changeToWaiting) { labelText = "Statechart group is running"; - if (editor->getUI()->toolButtonWatchStateExecution->isChecked() && !alreadyWatchingState) + if (editor->getUI()->toolButtonWatchStateExecution->isChecked() && + !alreadyWatchingState) { watchState(objName); } } } - QMetaObject::invokeMethod(editor->getUI()->labelExecutionState, "setText", Qt::QueuedConnection, Q_ARG(QString, labelText)); + QMetaObject::invokeMethod(editor->getUI()->labelExecutionState, + "setText", + Qt::QueuedConnection, + Q_ARG(QString, labelText)); // editor->getUI()->labelExecutionState->setText(labelText); - } - void StatechartEditorController::watchState(const std::string& objName) + void + StatechartEditorController::watchState(const std::string& objName) { - RemoteStateOffererInterfacePrx statechartHandler = getProxy<RemoteStateOffererInterfacePrx>(objName, false, "", false); + RemoteStateOffererInterfacePrx statechartHandler = + getProxy<RemoteStateOffererInterfacePrx>(objName, false, "", false); // ARMARX_INFO << deactivateSpam(4) << "getting proxy for " << objName; StatechartView* view = editor->getUI()->stateTabWidget->currentStateview(); if (view) { - std::string globalStateName = "TopLevel->" + view->getStateInstance()->getStateClass()->getStateName().toStdString(); - QMap<QString, StateInstanceData> instanceData = view->getScene()->getStateInstanceData(); + std::string globalStateName = + "TopLevel->" + + view->getStateInstance()->getStateClass()->getStateName().toStdString(); + QMap<QString, StateInstanceData> instanceData = + view->getScene()->getStateInstanceData(); auto toplevelPathString = view->getScene()->getTopLevelStateItem()->getFullStatePath(); - auto asyncResult = statechartHandler->begin_getStatechartInstanceByGlobalIdStr(globalStateName); + auto asyncResult = + statechartHandler->begin_getStatechartInstanceByGlobalIdStr(globalStateName); while (!asyncResult->isCompleted()) { if (getState() >= eManagedIceObjectExiting) @@ -592,7 +650,8 @@ namespace armarx usleep(10000); // qApp->processEvents(); } - armarx::StateIceBasePtr stateptr = statechartHandler->end_getStatechartInstanceByGlobalIdStr(asyncResult); + armarx::StateIceBasePtr stateptr = + statechartHandler->end_getStatechartInstanceByGlobalIdStr(asyncResult); if (!stateptr) { // ARMARX_WARNING_S << deactivateSpam(4) << "Could not find state with name " << globalStateName; @@ -601,16 +660,19 @@ namespace armarx { - std::function<void(StateIceBasePtr iceState, StateItem* state)> subscriptionLamba; - subscriptionLamba = [&](StateIceBasePtr iceState, StateItem * state) + std::function<void(StateIceBasePtr iceState, StateItem * state)> subscriptionLamba; + subscriptionLamba = [&](StateIceBasePtr iceState, StateItem* state) { stateWatcher->subscribeToState(iceState, state); size_t i = 0; for (auto stateInstance : state->getSubstateItems()) { - if (stateInstance->getStateInstance()->getStateClass() && iceState->subStateList.size() > i) + if (stateInstance->getStateInstance()->getStateClass() && + iceState->subStateList.size() > i) { - subscriptionLamba(StateIceBasePtr::dynamicCast(iceState->subStateList.at(i)), stateInstance); + subscriptionLamba( + StateIceBasePtr::dynamicCast(iceState->subStateList.at(i)), + stateInstance); } i++; } @@ -622,7 +684,8 @@ namespace armarx } } - QPointer<QWidget> StatechartEditorController::getWidget() + QPointer<QWidget> + StatechartEditorController::getWidget() { if (!editor) { @@ -633,83 +696,182 @@ namespace armarx return qobject_cast<QWidget*>(editor); } - void StatechartEditorController::initWidget() + void + StatechartEditorController::initWidget() { getWidget()->setFocusPolicy(Qt::WheelFocus); ARMARX_INFO << "selectedProfile: " << config.selectedProfile->getFullName(); ARMARX_INFO << "profile packages: " << config.selectedProfile->getAllPackages(); - variantInfo = VariantInfo::ReadInfoFiles({"ArmarXCore"}, true, false); // read core variantinfo file in case the root profile is selected - for (auto p : config.selectedProfile->getAllPackages()) + variantInfo = VariantInfo::ReadInfoFiles( + {"ArmarXCore"}, + true, + false); // read core variantinfo file in case the root profile is selected + for (const auto& eventuallyNamespacedPackage : config.selectedProfile->getAllPackages()) { - variantInfo = VariantInfo::ReadInfoFilesRecursive(p, "", true, variantInfo); + variantInfo = VariantInfo::ReadInfoFilesRecursive( + eventuallyNamespacedPackage, "", true, variantInfo); } editor->setCommunicator(getIceManager()->getCommunicator()); editor->setVariantInfo(variantInfo); editor->setCurrentProfile(config.selectedProfile); - editor->getUI()->toolBarViewControl->addWidget(new QLabel(QString::fromStdString("Selected Profile: " + config.selectedProfile->getFullName()))); - editor->getUI()->toolBarViewControl->insertWidget(editor->getUI()->actionEdit_State_Properties, new QLabel("Active State:")); + editor->getUI()->toolBarViewControl->addWidget(new QLabel( + QString::fromStdString("Selected Profile: " + config.selectedProfile->getFullName()))); + editor->getUI()->toolBarViewControl->insertWidget( + editor->getUI()->actionEdit_State_Properties, new QLabel("Active State:")); QList<QVariant> header; header.push_back(QString("TEST")); - treeController.reset(new StateTreeController(getIceManager()->getCommunicator(), variantInfo, header, editor->getUI()->treeViewGroups, editor->getUI()->lineEditStateSearch, packageTool, profiles, config.selectedProfile, this)); + treeController.reset(new StateTreeController(getIceManager()->getCommunicator(), + variantInfo, + header, + editor->getUI()->treeViewGroups, + editor->getUI()->lineEditStateSearch, + packageTool, + profiles, + config.selectedProfile, + this)); QStringList searchPaths; if (config.openAllStatesWasSelected) { - for (std::string package : config.selectedProfile->getAllPackages()) + for (std::string eventuallyNamespacedPackage : config.selectedProfile->getAllPackages()) { - for (const auto& includePath : CMakePackageFinder(package).getIncludePathList()) + // check for namespaced package + const auto elements = simox::alg::split(eventuallyNamespacedPackage, "::"); + ARMARX_IMPORTANT << VAROUT(elements); + + const std::string cmakePackageName = + simox::alg::replace_all(eventuallyNamespacedPackage, "::", "_"); + + for (const auto& includePath : + CMakePackageFinder(cmakePackageName).getIncludePathList()) { - std::filesystem::path packageStatechartPath(includePath.c_str()); - packageStatechartPath /= package; - packageStatechartPath /= "statecharts"; + ARMARX_IMPORTANT << VAROUT(includePath); - if (std::filesystem::exists(packageStatechartPath) - && !std::filesystem::exists(packageStatechartPath / "cmake_install.cmake")) // do not add the build dir + if (elements.size() == 1) // standard packages { - ARMARX_VERBOSE << "Adding statechart search path: " << packageStatechartPath.string(); - searchPaths.push_back(packageStatechartPath.c_str()); + std::filesystem::path packageStatechartPath(includePath.c_str()); + packageStatechartPath /= cmakePackageName; + packageStatechartPath /= "statecharts"; + + if (std::filesystem::exists(packageStatechartPath) && + !std::filesystem::exists( + packageStatechartPath / + "cmake_install.cmake")) // do not add the build dir + { + ARMARX_VERBOSE << "Adding statechart search path: " + << packageStatechartPath.string(); + searchPaths.push_back(packageStatechartPath.c_str()); + } + } + + if (elements.size() == 2) // special handling of namespaced packages + { + std::filesystem::path packageStatechartPathArmarXPackage( + includePath.c_str()); + + packageStatechartPathArmarXPackage /= elements.at(0); + packageStatechartPathArmarXPackage /= elements.at(1); + packageStatechartPathArmarXPackage /= "statecharts"; + + ARMARX_IMPORTANT << VAROUT(packageStatechartPathArmarXPackage); + + if (std::filesystem::exists(packageStatechartPathArmarXPackage) && + !std::filesystem::exists( + packageStatechartPathArmarXPackage / + "cmake_install.cmake")) // do not add the build dir + { + ARMARX_IMPORTANT << "Adding statechart search path: " + << packageStatechartPathArmarXPackage.string(); + searchPaths.push_back(packageStatechartPathArmarXPackage.c_str()); + } } } } - } config.searchPaths.removeDuplicates(); - - - connect(editor->getUI()->actionNew_State_Definition, SIGNAL(triggered()), treeController.get(), SLOT(onNewStateDefinition())); - connect(editor->getUI()->actionDelete_State_Definition, SIGNAL(triggered()), treeController.get(), SLOT(onDeleteNode())); - connect(editor->getUI()->treeViewGroups, SIGNAL(doubleClicked(QModelIndex)), SLOT(treeviewGroupsDoubleClicked(QModelIndex))); + connect(editor->getUI()->actionNew_State_Definition, + SIGNAL(triggered()), + treeController.get(), + SLOT(onNewStateDefinition())); + connect(editor->getUI()->actionDelete_State_Definition, + SIGNAL(triggered()), + treeController.get(), + SLOT(onDeleteNode())); + connect(editor->getUI()->treeViewGroups, + SIGNAL(doubleClicked(QModelIndex)), + SLOT(treeviewGroupsDoubleClicked(QModelIndex))); connect(editor->getUI()->actionSave_State, SIGNAL(triggered()), SLOT(requestSave())); - connect(editor->getUI()->stateTabWidget, SIGNAL(currentChanged(int)), SLOT(onStateTabChanged(int))); - connect(editor->getUI()->actionNew_Statechart_Group, SIGNAL(triggered()), this, SLOT(showNewStatechartGroupDialog())); - connect(editor->getUI()->actionOpenStatechartGroup, SIGNAL(triggered()), treeController.get(), SLOT(onOpenGroup())); - connect(editor->getUI()->actionSettings, SIGNAL(triggered()), this, SLOT(showStatechartEditorSettingsDialog())); - connect(editor->getUI()->toolButtonRunState, SIGNAL(clicked(bool)), this, SLOT(executeOpenedState(bool))); + connect(editor->getUI()->stateTabWidget, + SIGNAL(currentChanged(int)), + SLOT(onStateTabChanged(int))); + connect(editor->getUI()->actionNew_Statechart_Group, + SIGNAL(triggered()), + this, + SLOT(showNewStatechartGroupDialog())); + connect(editor->getUI()->actionOpenStatechartGroup, + SIGNAL(triggered()), + treeController.get(), + SLOT(onOpenGroup())); + connect(editor->getUI()->actionSettings, + SIGNAL(triggered()), + this, + SLOT(showStatechartEditorSettingsDialog())); + connect(editor->getUI()->toolButtonRunState, + SIGNAL(clicked(bool)), + this, + SLOT(executeOpenedState(bool))); connect(treeController.get(), SIGNAL(closeAllTabsRequested()), this, SLOT(closeAllTabs())); // setup plugin specific shortcuts - editor->getUI()->actionOpenStatechartGroup->setShortcutContext(Qt::WidgetWithChildrenShortcut); + editor->getUI()->actionOpenStatechartGroup->setShortcutContext( + Qt::WidgetWithChildrenShortcut); editor->getUI()->actionOpenStatechartGroup->setShortcut(tr("Ctrl+O")); getWidget()->addAction(editor->getUI()->actionOpenStatechartGroup); - stateEditorController.reset(new StateEditorController(editor, treeController, getIceManager()->getCommunicator(), variantInfo, config.selectedProfile, getTipDialog())); + stateEditorController.reset(new StateEditorController(editor, + treeController, + getIceManager()->getCommunicator(), + variantInfo, + config.selectedProfile, + getTipDialog())); stateEditorController->setLockRemoteStatesByDefault(config.lockRemoteStates); - connect(editor->getUI()->stateTabWidget, SIGNAL(currentChanged(int)), this, SLOT(connectToView(int)), Qt::UniqueConnection); - connect(editor->getUI()->radioOnEnter, SIGNAL(clicked()), this, SLOT(showOnEnterFunction()), Qt::UniqueConnection); - connect(editor->getUI()->radioOnBreak, SIGNAL(clicked()), this, SLOT(showOnBreakFunction()), Qt::UniqueConnection); - connect(editor->getUI()->radioRun, SIGNAL(clicked()), this, SLOT(showRunFunction()), Qt::UniqueConnection); - connect(editor->getUI()->radioOnExit, SIGNAL(clicked()), this, SLOT(showOnExitFunction()), Qt::UniqueConnection); - - - connect(editor->getUI()->btnOpenCppCode, SIGNAL(clicked()), this, SLOT(openSelectedState())); + connect(editor->getUI()->stateTabWidget, + SIGNAL(currentChanged(int)), + this, + SLOT(connectToView(int)), + Qt::UniqueConnection); + connect(editor->getUI()->radioOnEnter, + SIGNAL(clicked()), + this, + SLOT(showOnEnterFunction()), + Qt::UniqueConnection); + connect(editor->getUI()->radioOnBreak, + SIGNAL(clicked()), + this, + SLOT(showOnBreakFunction()), + Qt::UniqueConnection); + connect(editor->getUI()->radioRun, + SIGNAL(clicked()), + this, + SLOT(showRunFunction()), + Qt::UniqueConnection); + connect(editor->getUI()->radioOnExit, + SIGNAL(clicked()), + this, + SLOT(showOnExitFunction()), + Qt::UniqueConnection); + + + connect( + editor->getUI()->btnOpenCppCode, SIGNAL(clicked()), this, SLOT(openSelectedState())); watcher = new QFileSystemWatcher(editor); connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(showCodeFileContent(QString))); @@ -718,31 +880,36 @@ namespace armarx // OpenStatechartGroups(config.groupsToLoad); // config.groupsToLoad.clear(); treeController->collapseAll(); - executionStatusTask = new PeriodicTask<StatechartEditorController>(this, &StatechartEditorController::updateExecutionButtonStatus, 300); + executionStatusTask = new PeriodicTask<StatechartEditorController>( + this, &StatechartEditorController::updateExecutionButtonStatus, 300); } - - - bool StatechartEditorController::onClose() + bool + StatechartEditorController::onClose() { // QSettings s("KIT", "ArmarXStatechartEditor"); // saveSettings(&s); return ArmarXComponentWidgetController::onClose(); } - void StatechartEditorController::configured() + void + StatechartEditorController::configured() { - StatechartEditorConfigDialog* dialog = qobject_cast<StatechartEditorConfigDialog*>(getConfigDialog(getWidget())); + StatechartEditorConfigDialog* dialog = + qobject_cast<StatechartEditorConfigDialog*>(getConfigDialog(getWidget())); config.selectedProfile = dialog->getSelectedProfile(); config.openAllStatesWasSelected = dialog->openAllStatesIsSelected(); } -} -QPointer<QDialog> armarx::StatechartEditorController::getConfigDialog(QWidget* parent) +} // namespace armarx + +QPointer<QDialog> +armarx::StatechartEditorController::getConfigDialog(QWidget* parent) { if (!dialog) { - profiles = StatechartProfiles::ReadProfileFiles(Application::getInstance()->getDefaultPackageNames()); + profiles = StatechartProfiles::ReadProfileFiles( + Application::getInstance()->getDefaultPackageNames()); dialog = new StatechartEditorConfigDialog(profiles, parent); } diff --git a/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/io/GroupXmlReader.cpp b/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/io/GroupXmlReader.cpp index d98c15203ad2ca43c9589b00cabf2ab4110b2960..d0e3571d955570121db85224c0d01a741ef7ad12 100644 --- a/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/io/GroupXmlReader.cpp +++ b/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/io/GroupXmlReader.cpp @@ -23,35 +23,37 @@ */ #include "GroupXmlReader.h" -#include <ArmarXCore/core/exceptions/local/FileIOException.h> +#include <filesystem> +#include <fstream> +#include <stdexcept> +#include <streambuf> +#include <string> + +#include <boost/regex.hpp> #include <QFile> #include <QFileInfo> #include <QTextStream> -#include <filesystem> -#include <boost/regex.hpp> - -#include <string> -#include <fstream> -#include <streambuf> -#include <stdexcept> +#include <ArmarXCore/core/exceptions/local/FileIOException.h> using namespace armarx; using namespace rapidxml; - GuiStatechartGroupXmlReader::GuiStatechartGroupXmlReader() { } -StatechartGroupPtr GuiStatechartGroupXmlReader::ReadXml(QString groupDefinitionFile, StateTreeNodePtr virtualRoot) +StatechartGroupPtr +GuiStatechartGroupXmlReader::ReadXml(QString groupDefinitionFile, StateTreeNodePtr virtualRoot) { - RapidXmlReaderPtr wrapper = RapidXmlReader::FromFile(std::string(groupDefinitionFile.toUtf8().data())); + RapidXmlReaderPtr wrapper = + RapidXmlReader::FromFile(std::string(groupDefinitionFile.toUtf8().data())); RapidXmlReaderNode xmlGroupNode = wrapper->getRoot("StatechartGroup"); QString name = QString::fromUtf8(xmlGroupNode.attribute_value("name").c_str()); - QString description = QString::fromUtf8(xmlGroupNode.first_node_value_or_default("Description", "").c_str()); + QString description = + QString::fromUtf8(xmlGroupNode.first_node_value_or_default("Description", "").c_str()); QString packageName = QString::fromUtf8(xmlGroupNode.attribute_value("package").c_str()); QString displayName = name; @@ -59,13 +61,14 @@ StatechartGroupPtr GuiStatechartGroupXmlReader::ReadXml(QString groupDefinitionF boost::match_results<std::string::const_iterator> match; std::filesystem::path groupPath(groupDefinitionFile.toUtf8().data()); const std::string groupPathStr(groupPath.parent_path().c_str()); - StatechartGroup::WriteAccess writable = QFileInfo(QString::fromStdString(groupPath.string())).permissions() & QFile::WriteUser ? StatechartGroup::eWritable : StatechartGroup::eReadOnly; + StatechartGroup::WriteAccess writable = + QFileInfo(QString::fromStdString(groupPath.string())).permissions() & QFile::WriteUser + ? StatechartGroup::eWritable + : StatechartGroup::eReadOnly; - if (boost::regex_search(groupPathStr.begin(), groupPathStr.end(), match, projectNameRegex)) - { - displayName += QString(" [%1]").arg(QString::fromStdString(std::string(match[1].first, match[1].second))); - } + + displayName += QString(" [%1]").arg(packageName); QList<QString> proxies; @@ -82,18 +85,28 @@ StatechartGroupPtr GuiStatechartGroupXmlReader::ReadXml(QString groupDefinitionF statechartGroupConfigurations[profileName] = configuration; } - bool generateContext = xmlGroupNode.attribute_as_optional_bool("generateContext", "true", "false", false); - - StatechartGroupPtr group(new StatechartGroup(groupDefinitionFile, QString::fromUtf8(groupPath.parent_path().c_str()), name, description, packageName, - proxies, generateContext, statechartGroupConfigurations, writable)); - StateTreeNodePtr rootNode(new StateTreeNode(displayName, "", StateTreeNode::Group, virtualRoot, group, false)); + bool generateContext = + xmlGroupNode.attribute_as_optional_bool("generateContext", "true", "false", false); + + StatechartGroupPtr group(new StatechartGroup(groupDefinitionFile, + QString::fromUtf8(groupPath.parent_path().c_str()), + name, + description, + packageName, + proxies, + generateContext, + statechartGroupConfigurations, + writable)); + StateTreeNodePtr rootNode( + new StateTreeNode(displayName, "", StateTreeNode::Group, virtualRoot, group, false)); ReadChildren(xmlGroupNode, rootNode, group); group->setRootNode(rootNode); ARMARX_LOG_S << "Reading done: " << groupDefinitionFile.toStdString() << flush; return group; } -QString GuiStatechartGroupXmlReader::ReadFileContents(QString path) +QString +GuiStatechartGroupXmlReader::ReadFileContents(QString path) { QFile f(path); @@ -106,14 +119,16 @@ QString GuiStatechartGroupXmlReader::ReadFileContents(QString path) return in.readAll(); } - - -void GuiStatechartGroupXmlReader::ReadChildren(RapidXmlReaderNode xmlNode, StateTreeNodePtr parentNode, StatechartGroupPtr group) +void +GuiStatechartGroupXmlReader::ReadChildren(RapidXmlReaderNode xmlNode, + StateTreeNodePtr parentNode, + StatechartGroupPtr group) { for (RapidXmlReaderNode xmlFolderNode : xmlNode.nodes("Folder")) { QString basename = QString::fromUtf8(xmlFolderNode.attribute_value("basename").c_str()); - StateTreeNodePtr folderNode(new StateTreeNode(basename, basename, StateTreeNode::Folder, parentNode, group, false)); + StateTreeNodePtr folderNode( + new StateTreeNode(basename, basename, StateTreeNode::Folder, parentNode, group, false)); parentNode->appendChild(folderNode); ReadChildren(xmlFolderNode, folderNode, group); } @@ -121,9 +136,10 @@ void GuiStatechartGroupXmlReader::ReadChildren(RapidXmlReaderNode xmlNode, State for (RapidXmlReaderNode xmlStateNode : xmlNode.nodes("State")) { QString filename = QString::fromUtf8(xmlStateNode.attribute_value("filename").c_str()); - bool stateIsPublic = xmlStateNode.attribute_as_optional_bool("visibility", "public", "private", false); - StateTreeNodePtr stateNode(new StateTreeNode(filename, filename, StateTreeNode::State, parentNode, group, stateIsPublic)); + bool stateIsPublic = + xmlStateNode.attribute_as_optional_bool("visibility", "public", "private", false); + StateTreeNodePtr stateNode(new StateTreeNode( + filename, filename, StateTreeNode::State, parentNode, group, stateIsPublic)); parentNode->appendChild(stateNode); } } - diff --git a/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/model/StatechartGroup.cpp b/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/model/StatechartGroup.cpp index bb70158f51c6b07f5ef9c6dcd9087abddcfcac4c..4651dab65db867b00374fda3125251b424b3134e 100644 --- a/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/model/StatechartGroup.cpp +++ b/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/model/StatechartGroup.cpp @@ -151,4 +151,3 @@ StatechartGroup::WriteAccess StatechartGroup::getWriteAccess() { return writable; } - diff --git a/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/view/dialogs/StatechartEditorSettingsDialog.cpp b/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/view/dialogs/StatechartEditorSettingsDialog.cpp index 62f742e3e567117d4fd43f53aaf3d85d1722d043..4a526cfc121ff28dc5ae293157afa7199b81d5c8 100644 --- a/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/view/dialogs/StatechartEditorSettingsDialog.cpp +++ b/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/view/dialogs/StatechartEditorSettingsDialog.cpp @@ -21,19 +21,19 @@ */ #include "StatechartEditorSettingsDialog.h" -#include <ArmarXGui/gui-plugins/StatechartEditorPlugin/view/dialogs/ui_StatechartEditorSettingsDialog.h> #include <QFileDialog> #include <QtGui> #include <ArmarXCore/core/system/ArmarXDataPath.h> +#include <ArmarXGui/gui-plugins/StatechartEditorPlugin/view/dialogs/ui_StatechartEditorSettingsDialog.h> + namespace armarx { StatechartEditorSettingsDialog::StatechartEditorSettingsDialog(QWidget* parent) : - QDialog(parent), - ui(new Ui::StatechartEditorSettingsDialog) + QDialog(parent), ui(new Ui::StatechartEditorSettingsDialog) { ui->setupUi(this); connect(ui->btnAddPath, SIGNAL(clicked()), this, SLOT(selectNewPath())); @@ -44,27 +44,32 @@ namespace armarx delete ui; } - QStringList StatechartEditorSettingsDialog::getPaths() const + QStringList + StatechartEditorSettingsDialog::getPaths() const { return ui->textEditSearchPaths->toPlainText().split(";"); } - void StatechartEditorSettingsDialog::setRemoteStatesLocked(bool locked) + void + StatechartEditorSettingsDialog::setRemoteStatesLocked(bool locked) { ui->cbLockRemoteStates->setChecked(locked); } - bool StatechartEditorSettingsDialog::getRemoteStatesLocked() const + bool + StatechartEditorSettingsDialog::getRemoteStatesLocked() const { return ui->cbLockRemoteStates->isChecked(); } - void StatechartEditorSettingsDialog::setPaths(QStringList paths) + void + StatechartEditorSettingsDialog::setPaths(QStringList paths) { ui->textEditSearchPaths->setText(paths.join(";")); } - void StatechartEditorSettingsDialog::selectNewPath() + void + StatechartEditorSettingsDialog::selectNewPath() { QFileDialog selectFolder(this, "Select new search folder"); // selectFolder.setOption(QFileDialog::ShowDirsOnly, true); @@ -72,8 +77,10 @@ namespace armarx selectFolder.setOption(QFileDialog::HideNameFilterDetails, false); selectFolder.setFileMode(QFileDialog::Directory); QList<QUrl> urls; - urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::HomeLocation)) - << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation)); + urls << QUrl::fromLocalFile( + QDesktopServices::storageLocation(QDesktopServices::HomeLocation)) + << QUrl::fromLocalFile( + QDesktopServices::storageLocation(QDesktopServices::DesktopLocation)); if (!ArmarXDataPath::getHomePath().empty()) { @@ -90,11 +97,10 @@ namespace armarx } else { - ui->textEditSearchPaths->setText(ui->textEditSearchPaths->toPlainText() + ";\n" + *selectFolder.selectedFiles().begin()); + ui->textEditSearchPaths->setText(ui->textEditSearchPaths->toPlainText() + ";\n" + + *selectFolder.selectedFiles().begin()); } - - } } -} +} // namespace armarx diff --git a/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/view/dialogs/StatechartEditorSettingsDialog.ui b/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/view/dialogs/StatechartEditorSettingsDialog.ui index 8a48ba43dcc5de70512c4f9c046f1d371358b7ad..a279ce921b043f0a8786d64f61995f6cefaacd90 100644 --- a/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/view/dialogs/StatechartEditorSettingsDialog.ui +++ b/source/ArmarXGui/gui-plugins/StatechartEditorPlugin/view/dialogs/StatechartEditorSettingsDialog.ui @@ -6,7 +6,7 @@ <rect> <x>0</x> <y>0</y> - <width>552</width> + <width>723</width> <height>245</height> </rect> </property> @@ -37,7 +37,7 @@ <item row="0" column="0" colspan="2"> <widget class="QLabel" name="label"> <property name="text"> - <string>Statechart Groups Search Paths (Semi-Colon seperated)</string> + <string>Statechart Groups Search Paths (Semicolon seperated, relative to workspace root)</string> </property> </widget> </item>