GroupCloner.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package
19 * @author
20 * @date
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24#pragma once
25
26#include <memory>
27
28#include <QMap>
29#include <QString>
30
34
40
42
43namespace armarx
44{
45 class GroupCloner;
46 using GroupClonerPtr = std::shared_ptr<GroupCloner>;
47
49 {
50
51 public:
52 GroupCloner(const std::weak_ptr<StateTreeModel>& treeModel,
53 const ArmarXPackageToolInterfacePtr& packageTool);
54 std::optional<StatechartGroupMapping>
55 cloneGroupsTo(const QVector<QPair<StatechartGroupPtr, QString>>& groupsNames,
56 const QString& packageDir,
58 bool createNewUUIDs = true);
59
60 QVector<StatechartGroupPtr> getGroupDependencies(const StatechartGroupPtr& group,
61 bool includeSelf = false);
62 QVector<StatechartGroupPtr> getMappedGroups(const StatechartGroupMapping& mapping);
63
64 template <typename Function>
65 static void
67 RapidXmlWriterNode target,
68 const Function& processorFunction)
69 {
70 for (const auto& pair : source.get_all_attributes())
71 {
72 std::string valueToStore =
73 processorFunction(source.name(), pair.first, pair.second);
74 target.append_attribute(pair.first, valueToStore);
75 }
76
77 for (RapidXmlReaderNode node : source.nodes())
78 {
79 if (node.type() == rapidxml::node_data)
80 {
81 target.append_data_node(node.value());
82 }
83 else if (node.type() == rapidxml::node_element)
84 {
85 ProcessXMLFile(node, target.append_node(node.name()), processorFunction);
86 }
87 else
88 {
89 throw LocalException("Unsupported node type.");
90 }
91 }
92 }
93
94 static QVector<StatechartGroupPtr>
96 const QVector<statechartmodel::StatePtr>& states);
97 static bool RemoveDir(const QString& dirName);
98 static void RegexReplaceFile(const QString& srcFilePath,
99 const QString& tgtFilePath,
100 const QVector<QPair<QRegExp, QString>>& replaceList);
101
102 private:
103 static bool CopyRecursively(const QString& srcPath, const QString& tgtParentDirPath);
104
105 std::weak_ptr<StateTreeModel> treeModel;
107
108 void registerGroups(const QVector<StatechartGroupPtr>& groups,
109 const StatechartGroupMapping& mapping,
110 const QString& packageDir);
111 bool cloneGroupTo(const StatechartGroupPtr& group,
112 const QString& newGroupFolder,
113 const StatechartGroupMapping& mapping);
114 };
115} // namespace armarx
static void ProcessXMLFile(RapidXmlReaderNode source, RapidXmlWriterNode target, const Function &processorFunction)
Definition GroupCloner.h:66
static void RegexReplaceFile(const QString &srcFilePath, const QString &tgtFilePath, const QVector< QPair< QRegExp, QString > > &replaceList)
GroupCloner(const std::weak_ptr< StateTreeModel > &treeModel, const ArmarXPackageToolInterfacePtr &packageTool)
static QVector< StatechartGroupPtr > GetGroupsFromStates(const StateTreeModelPtr &treeModel, const QVector< statechartmodel::StatePtr > &states)
QVector< StatechartGroupPtr > getMappedGroups(const StatechartGroupMapping &mapping)
std::optional< StatechartGroupMapping > cloneGroupsTo(const QVector< QPair< StatechartGroupPtr, QString > > &groupsNames, const QString &packageDir, const StatechartGroupMapping &mapping=StatechartGroupMapping(), bool createNewUUIDs=true)
static bool RemoveDir(const QString &dirName)
QVector< StatechartGroupPtr > getGroupDependencies(const StatechartGroupPtr &group, bool includeSelf=false)
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< StatechartGroup > StatechartGroupPtr
std::shared_ptr< StateTreeModel > StateTreeModelPtr
std::shared_ptr< GroupCloner > GroupClonerPtr
Definition GroupCloner.h:46
std::shared_ptr< ArmarXPackageToolInterface > ArmarXPackageToolInterfacePtr
@ node_data
A data node. Name is empty. Value contains data text.
Definition rapidxml.hpp:152
@ node_element
An element node. Name contains element name. Value contains text of first data node.
Definition rapidxml.hpp:151