RobotVisualizationWidget.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 */
25
27
29
30using namespace armarx;
31
33 QWidget* viewerWidget,
34 RobotVisualizationPtr viewer) :
35 QSplitter(parent)
36{
37 //this->setOpaqueResize(true);
38 //initialize Attriutes
39 this->selectedViewer = 0;
40 this->viewer = viewer;
41 this->viewerWidget = viewerWidget;
42 viewerWidget->setObjectName("0");
43 this->childrenCounter = 1;
44 this->leftSplitter = new QSplitter(Qt::Orientation::Vertical, this);
45 this->rightSplitter = new QSplitter(Qt::Orientation::Vertical, this);
46 this->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
47
48 //Add callback for viewer selection from Main-Application
49 QObject::connect(QApplication::instance(),
50 SIGNAL(focusChanged(QWidget*, QWidget*)),
51 this,
52 SLOT(activeWidgetChanged(QWidget*, QWidget*)));
53
54 //Add original viewer to this widget
55 viewerWidget->setFocusPolicy(Qt::FocusPolicy::WheelFocus);
56 this->leftSplitter->addWidget(viewerWidget);
57}
58
63
64void
66{
67 if (childrenCounter < 4)
68 {
69 QWidget* parent = new QWidget();
70 clones.push_back(viewer->reproduce(parent));
71 parent->setObjectName(QString::fromStdString(std::to_string(childrenCounter)));
72 parent->setFocusPolicy(Qt::FocusPolicy::WheelFocus);
73 cloneWidgets.push_back(parent);
74
75 if (childrenCounter == 0)
76 {
77 leftSplitter->addWidget(parent);
78 }
79 //Remove Viewer Left of original Viewer
80 else if (childrenCounter == 1)
81 {
82 rightSplitter->addWidget(parent);
83 }
84 //Add new Viewer in the lower right corner
85 else if (childrenCounter == 2)
86 {
87 rightSplitter->addWidget(parent);
88 }
89 //Add new Viewer in the lower left corner
90 else if (childrenCounter == 3)
91 {
92 leftSplitter->addWidget(parent);
93 }
94 childrenCounter++;
95 }
96}
97
98void
100{
101 //Remove Viewer Left of original Viewer
102 if (childrenCounter == 2)
103 {
104 if (rightSplitter->children().at(0))
105 {
106 cloneWidgets.pop_back();
107 clones.pop_back();
108 rightSplitter->children().at(0)->~QObject();
109 childrenCounter--;
110 }
111 }
112 //Remove Viewer in the lower right corner
113 else if (childrenCounter == 3)
114 {
115 if (rightSplitter->children().at(1))
116 {
117 cloneWidgets.pop_back();
118 clones.pop_back();
119 rightSplitter->children().at(0)->~QObject();
120 childrenCounter--;
121 }
122 }
123 //Remove Viewer in lower left corner
124 else if (childrenCounter == 4)
125 {
126 if (leftSplitter->children().at(1))
127 {
128 cloneWidgets.pop_back();
129 clones.pop_back();
130 leftSplitter->children().at(0)->~QObject();
131 childrenCounter--;
132 }
133 }
134 if (selectedViewer == childrenCounter)
135 {
136 selectedViewer--;
137 }
138}
139
140void
142 Eigen::Vector3f pointAtA,
143 Eigen::Vector3f pointAtB)
144{
145 if (selectedViewer == 0)
146 {
147 viewer->setCamera(position, pointAtA, pointAtB);
148 }
149 else
150 {
151 ARMARX_INFO << std::to_string(selectedViewer);
152 RobotVisualizationPtr clone = clones[selectedViewer - 1];
153 clone->setCamera(position, pointAtA, pointAtB);
154 }
155}
156
157void
158RobotVisualizationWidget::activeWidgetChanged(QWidget* old, QWidget* now)
159{
160 if (!now)
161 {
162 return;
163 }
164 /*for (int i = 0; i < 2; i++)
165 {
166 ARMARX_WARNING << now->objectName().toStdString() + "..." + std::to_string(i);
167 now = now->nextInFocusChain();
168 }*/
169
170 if (now == viewerWidget ||
171 (now->parentWidget() && now->parentWidget()->parentWidget() &&
172 now->parentWidget()->parentWidget()->parentWidget() &&
173 now->parentWidget()->parentWidget()->parentWidget() == viewerWidget))
174 {
175 selectedViewer = 0;
176 }
177 int j = 1;
178 for (QWidget* clone : cloneWidgets)
179 {
180 if (now == clone || (now->parentWidget() && now->parentWidget()->parentWidget() &&
181 now->parentWidget()->parentWidget()->parentWidget() &&
182 now->parentWidget()->parentWidget()->parentWidget() == clone))
183 {
184 this->selectedViewer = j;
185 return;
186 }
187 j++;
188 }
189 /*std::string s = now->nextInFocusChain()->objectName().toStdString();
190 ARMARX_WARNING << s + "NEXT";
191 ARMARX_WARNING << now->objectName().toStdString() + "NOW";
192 ARMARX_WARNING << now->parentWidget()->parentWidget()->parentWidget()->objectName().toStdString() + "PARENT";
193 for (int i = 0; i < childrenCounter; i++)
194 {
195 if (s.length() >= 15)
196 {
197 std::string number = s.substr(15);
198 if (std::to_string(i) == number)
199 {
200 this->selectedViewer = i;
201 return;
202 }
203 }
204 }*/
205}
void addWidget()
addWidget adds a new View by reproducing the original viewer
void removeWidget()
removeWidget removes a view from this Widget
RobotVisualizationWidget(QWidget *parent=0, QWidget *viewerWidget=0, RobotVisualizationPtr viewer=0)
Constructor.
void setCameraOfFocused(Eigen::Vector3f position, Eigen::Vector3f pointAtA, Eigen::Vector3f pointAtB)
setCameraOfFocused sets the camera of the viewer that is currently focused (the viewer that was last ...
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< RobotVisualization > RobotVisualizationPtr