LayoutWorkerCreator.cpp
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#include "LayoutWorkerCreator.h"
25
26#include <utility>
27
29
30#include "Layout.h"
31
33{
34 // aginit();
35 ARMARX_INFO_S << "Graphviz initialized";
36 qRegisterMetaType<MediatorPtr>("MediatorPtr");
37 qRegisterMetaType<LockableGraphPtr>("LockableGraphPtr");
38
39 graphvizContext = gvContext();
40}
41
42void
44{
45 LayoutWorkerPtr worker{new LayoutWorker(id, name, graphvizContext)};
46
47 //auch StateInstancePtr, TransitionCPtr etc. registrieren?
48
49 //mediator und worker verbinden
50 bool correctConnect = connect(mediator.get(),
51 SIGNAL(mediatorDeleted()),
52 worker.get(),
53 SLOT(stateDeleted()),
54 Qt::QueuedConnection);
55
56 if (!correctConnect)
57 {
58 ARMARX_ERROR_S << "Signal mediatorDeleted of mediator " << mediator->getID()
59 << " was not successfully connected "
60 << "to slot stateDeleted of worker " << id;
61 }
62
63 correctConnect = connect(mediator.get(),
64 SIGNAL(layout(bool)),
65 worker.get(),
66 SLOT(layout(bool)),
67 Qt::QueuedConnection);
68
69 if (!correctConnect)
70 {
71 ARMARX_ERROR_S << "Signal layout of mediator " << mediator->getID()
72 << " was not successfully connected "
73 << "to slot layout of worker " << id;
74 }
75
76 correctConnect = connect(worker.get(),
77 SIGNAL(buildGraph(LockableGraphPtr)),
78 mediator.get(),
79 SLOT(buildUpGraph(LockableGraphPtr)),
80 Qt::QueuedConnection);
81
82 if (!correctConnect)
83 {
84 ARMARX_ERROR_S << "Signal buildGraph of worker " << id << " was not successfully connected "
85 << "to slot buildUpGraph of mediator " << mediator->getID();
86 }
87
88 correctConnect = connect(worker.get(),
89 SIGNAL(layoutingFinished()),
90 mediator.get(),
91 SLOT(workerFinishedLayouting()),
92 Qt::QueuedConnection);
93
94 if (!correctConnect)
95 {
96 ARMARX_ERROR_S << "Signal layoutingFinished of worker " << id
97 << " was not successfully connected "
98 << "to slot workerFinishedLayouting of mediator " << mediator->getID();
99 }
100
101 //worker und WorkerCreator verbinden
102 correctConnect = connect(worker.get(),
103 SIGNAL(deleteMe(size_t)),
104 this,
105 SLOT(deleteWorker(size_t)),
106 Qt::QueuedConnection);
107
108 if (!correctConnect)
109 {
110 ARMARX_ERROR_S << "Signal deleteMe of worker " << id << " was not successfully connected "
111 << "to slot deleteWorker of workerCreator";
112 }
113
114 correctConnect = connect(this,
115 SIGNAL(connectedWorkerAndMediator(size_t)),
116 worker.get(),
117 SLOT(isConnected(size_t)),
118 Qt::QueuedConnection);
119
120 if (!correctConnect)
121 {
123 << "Signal connectedWorkerAndMediator of workerCreator was not successfully connected "
124 << "to slot isConnected of worker " << id;
125 }
126
127 //causes the associated mediator to build up the graph and to let himself be scheduled
129
130 workers.insert(std::pair<size_t, LayoutWorkerPtr>(id, std::move(worker)));
131}
132
133void
135{
136 workers.erase(id);
137}
138
139void
141{
142 workers.clear();
143}
void deleteWorkers()
deleteWorkers Calls the destructor of every worker.
void connectedWorkerAndMediator(size_t id)
connectedWorkerAndMediator Notifies that the worker's signals and slots are now connected to its medi...
void deleteWorker(size_t id)
deleteWorker Calls the destructor of the worker with the given id.
void createWorker(MediatorPtr mediator, size_t id, QString name)
createWorker Create worker with given id and connect it to mediator via signals and slots.
#define ARMARX_ERROR_S
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:216
#define ARMARX_INFO_S
Definition Logging.h:202
std::unique_ptr< LayoutWorker > LayoutWorkerPtr
std::shared_ptr< LockableGraph > LockableGraphPtr
Definition Layout.h:64
std::shared_ptr< StateModelLayoutMediator > MediatorPtr