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