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 
30 
31 #include <QString>
32 #include <QMap>
33 
40 
41 #include "StatechartGroupMapping.h"
42 
43 namespace armarx
44 {
45  class GroupCloner;
46  using GroupClonerPtr = std::shared_ptr<GroupCloner>;
47 
49  {
50 
51  public:
52 
53  GroupCloner(const std::weak_ptr<StateTreeModel>& treeModel, const ArmarXPackageToolInterfacePtr& packageTool);
54  std::optional<StatechartGroupMapping> cloneGroupsTo(
55  const QVector<QPair<StatechartGroupPtr, QString>>& groupsNames,
56  const QString& packageDir,
58  bool createNewUUIDs = true);
59 
60  QVector<StatechartGroupPtr> getGroupDependencies(const StatechartGroupPtr& group, bool includeSelf = false);
61  QVector<StatechartGroupPtr> getMappedGroups(const StatechartGroupMapping& mapping);
62 
63  template<typename Function>
64  static void ProcessXMLFile(RapidXmlReaderNode source, RapidXmlWriterNode target, const Function& processorFunction)
65  {
66  for (const auto& pair : source.get_all_attributes())
67  {
68  std::string valueToStore = processorFunction(source.name(), pair.first, pair.second);
69  target.append_attribute(pair.first, valueToStore);
70  }
71 
72  for (RapidXmlReaderNode node : source.nodes())
73  {
74  if (node.type() == rapidxml::node_data)
75  {
76  target.append_data_node(node.value());
77  }
78  else if (node.type() == rapidxml::node_element)
79  {
80  ProcessXMLFile(node, target.append_node(node.name()), processorFunction);
81  }
82  else
83  {
84  throw LocalException("Unsupported node type.");
85  }
86  }
87  }
88 
89  static QVector<StatechartGroupPtr> GetGroupsFromStates(const StateTreeModelPtr& treeModel, const QVector<statechartmodel::StatePtr>& states);
90  static bool RemoveDir(const QString& dirName);
91  static void RegexReplaceFile(const QString& srcFilePath, const QString& tgtFilePath, const QVector<QPair<QRegExp, QString>>& replaceList);
92 
93  private:
94  static bool CopyRecursively(const QString& srcPath, const QString& tgtParentDirPath);
95 
96  std::weak_ptr<StateTreeModel> treeModel;
98 
99  void registerGroups(const QVector<StatechartGroupPtr>& groups, const StatechartGroupMapping& mapping, const QString& packageDir);
100  bool cloneGroupTo(const StatechartGroupPtr& group, const QString& newGroupFolder, const StatechartGroupMapping& mapping);
101  };
102 }
103 
armarx::StateTreeModelPtr
std::shared_ptr< StateTreeModel > StateTreeModelPtr
Definition: StateTreeModel.h:44
rapidxml::node_data
@ node_data
A data node. Name is empty. Value contains data text.
Definition: rapidxml.hpp:148
armarx::GroupCloner::getMappedGroups
QVector< StatechartGroupPtr > getMappedGroups(const StatechartGroupMapping &mapping)
Definition: GroupCloner.cpp:62
armarx::ArmarXPackageToolInterfacePtr
std::shared_ptr< ArmarXPackageToolInterface > ArmarXPackageToolInterfacePtr
Definition: ArmarXPackageToolInterface.h:55
rapidxml::node_element
@ node_element
An element node. Name contains element name. Value contains text of first data node.
Definition: rapidxml.hpp:147
boost::target
Vertex target(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:688
RapidXmlWriter.h
armarx::GroupCloner::GetGroupsFromStates
static QVector< StatechartGroupPtr > GetGroupsFromStates(const StateTreeModelPtr &treeModel, const QVector< statechartmodel::StatePtr > &states)
Definition: GroupCloner.cpp:415
armarx::GroupCloner::ProcessXMLFile
static void ProcessXMLFile(RapidXmlReaderNode source, RapidXmlWriterNode target, const Function &processorFunction)
Definition: GroupCloner.h:64
armarx::GroupCloner
Definition: GroupCloner.h:48
armarx::GroupClonerPtr
std::shared_ptr< GroupCloner > GroupClonerPtr
Definition: GroupCloner.h:46
armarx::GroupCloner::RegexReplaceFile
static void RegexReplaceFile(const QString &srcFilePath, const QString &tgtFilePath, const QVector< QPair< QRegExp, QString >> &replaceList)
Definition: GroupCloner.cpp:499
armarx::StatechartGroupMapping
Definition: StatechartGroupMapping.h:34
ArmarXPackageToolInterface.h
armarx::GroupCloner::GroupCloner
GroupCloner(const std::weak_ptr< StateTreeModel > &treeModel, const ArmarXPackageToolInterfacePtr &packageTool)
Definition: GroupCloner.cpp:37
armarx::GroupCloner::getGroupDependencies
QVector< StatechartGroupPtr > getGroupDependencies(const StatechartGroupPtr &group, bool includeSelf=false)
Definition: GroupCloner.cpp:44
armarx::GroupCloner::RemoveDir
static bool RemoveDir(const QString &dirName)
Definition: GroupCloner.cpp:511
armarx::GroupCloner::cloneGroupsTo
std::optional< StatechartGroupMapping > cloneGroupsTo(const QVector< QPair< StatechartGroupPtr, QString >> &groupsNames, const QString &packageDir, const StatechartGroupMapping &mapping=StatechartGroupMapping(), bool createNewUUIDs=true)
Definition: GroupCloner.cpp:83
StatechartGroup.h
StateTreeModel.h
armarx::RapidXmlReaderNode
Definition: RapidXmlReader.h:68
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:681
GroupXmlWriter.h
armarx::StatechartGroupPtr
std::shared_ptr< StatechartGroup > StatechartGroupPtr
Definition: StatechartGroupDefs.h:34
StatechartGroupMapping.h
RapidXmlReader.h
GroupXmlReader.h
StateTreeNode.h
armarx::RapidXmlWriterNode
Definition: RapidXmlWriter.h:34
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28