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 "Layout.h"
25 #include "LayoutWorkerCreator.h"
26 
28 
29 #include <utility>
30 
31 
33  : QObject()
34 {
35  // aginit();
36  ARMARX_INFO_S << "Graphviz initialized";
37  qRegisterMetaType<MediatorPtr>("MediatorPtr");
38  qRegisterMetaType<LockableGraphPtr>("LockableGraphPtr");
39 
40  graphvizContext = gvContext();
41 }
42 
43 void armarx::LayoutWorkerCreator::createWorker(armarx::MediatorPtr mediator, size_t id, QString name)
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(), SIGNAL(mediatorDeleted()),
51  worker.get(), SLOT(stateDeleted()), Qt::QueuedConnection);
52 
53  if (!correctConnect)
54  {
55  ARMARX_ERROR_S << "Signal mediatorDeleted of mediator " << mediator->getID() << " was not successfully connected "
56  << "to slot stateDeleted of worker " << id;
57  }
58 
59  correctConnect = connect(mediator.get(), SIGNAL(layout(bool)),
60  worker.get(), SLOT(layout(bool)), Qt::QueuedConnection);
61 
62  if (!correctConnect)
63  {
64  ARMARX_ERROR_S << "Signal layout of mediator " << mediator->getID() << " was not successfully connected "
65  << "to slot layout of worker " << id;
66  }
67 
68  correctConnect = connect(worker.get(), SIGNAL(buildGraph(LockableGraphPtr)),
69  mediator.get(), SLOT(buildUpGraph(LockableGraphPtr)), Qt::QueuedConnection);
70 
71  if (!correctConnect)
72  {
73  ARMARX_ERROR_S << "Signal buildGraph of worker " << id << " was not successfully connected "
74  << "to slot buildUpGraph of mediator " << mediator->getID();
75  }
76 
77  correctConnect = connect(worker.get(), SIGNAL(layoutingFinished()),
78  mediator.get(), SLOT(workerFinishedLayouting()), Qt::QueuedConnection);
79 
80  if (!correctConnect)
81  {
82  ARMARX_ERROR_S << "Signal layoutingFinished of worker " << id << " was not successfully connected "
83  << "to slot workerFinishedLayouting of mediator " << mediator->getID();
84  }
85 
86  //worker und WorkerCreator verbinden
87  correctConnect = connect(worker.get(), SIGNAL(deleteMe(size_t)),
88  this, SLOT(deleteWorker(size_t)), Qt::QueuedConnection);
89 
90  if (!correctConnect)
91  {
92  ARMARX_ERROR_S << "Signal deleteMe of worker " << id << " was not successfully connected "
93  << "to slot deleteWorker of workerCreator";
94  }
95 
96  correctConnect = connect(this, SIGNAL(connectedWorkerAndMediator(size_t)),
97  worker.get(), SLOT(isConnected(size_t)), Qt::QueuedConnection);
98 
99  if (!correctConnect)
100  {
101  ARMARX_ERROR_S << "Signal connectedWorkerAndMediator of workerCreator was not successfully connected "
102  << "to slot isConnected of worker " << id;
103  }
104 
105  //causes the associated mediator to build up the graph and to let himself be scheduled
106  emit connectedWorkerAndMediator(id);
107 
108  workers.insert(std::pair<size_t, LayoutWorkerPtr>(id, std::move(worker)));
109 }
110 
112 {
113  workers.erase(id);
114 }
115 
117 {
118  workers.clear();
119 }
armarx::LayoutWorker
Definition: LayoutWorker.h:34
armarx::LockableGraphPtr
std::shared_ptr< LockableGraph > LockableGraphPtr
Definition: Layout.h:64
armarx::LayoutWorkerPtr
std::unique_ptr< LayoutWorker > LayoutWorkerPtr
Definition: LayoutWorkerCreator.h:38
LayoutWorkerCreator.h
Layout.h
ARMARX_ERROR_S
#define ARMARX_ERROR_S
Definition: Logging.h:209
armarx::LayoutWorkerCreator::createWorker
void createWorker(MediatorPtr mediator, size_t id, QString name)
createWorker Create worker with given id and connect it to mediator via signals and slots.
Definition: LayoutWorkerCreator.cpp:43
armarx::LayoutWorkerCreator::deleteWorkers
void deleteWorkers()
deleteWorkers Calls the destructor of every worker.
Definition: LayoutWorkerCreator.cpp:116
armarx::MediatorPtr
std::shared_ptr< StateModelLayoutMediator > MediatorPtr
Definition: LayoutController.h:41
armarx::LayoutWorkerCreator::deleteWorker
void deleteWorker(size_t id)
deleteWorker Calls the destructor of the worker with the given id.
Definition: LayoutWorkerCreator.cpp:111
armarx::LayoutWorkerCreator::LayoutWorkerCreator
LayoutWorkerCreator()
Definition: LayoutWorkerCreator.cpp:32
ARMARX_INFO_S
#define ARMARX_INFO_S
Definition: Logging.h:195
Logging.h