ATLAS Offline Software
IVP13DChannelWidget.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // //
7 // Implementation of class IVP13DChannelWidget //
8 // //
9 // Author: Thomas Kittelmann <Thomas.Kittelmann@cern.ch> //
10 // //
11 // Initial version: April 2007 //
12 // //
14 
19 #include "VP1Base/VP1Msg.h"
20 
21 #include <QPixmap>
22 #include <QPainter>
23 #include <QBuffer>
24 #include <QByteArray>
25 
26 #include <Inventor/C/errors/debugerror.h>
27 #include "Inventor/Qt/SoQtRenderArea.h"
28 #include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
29 #include "Inventor/nodes/SoNode.h"
30 #include <Inventor/actions/SoLineHighlightRenderAction.h>
31 #include <iostream>
32 
34 public:
35 
36  // typedef std::vector<SoQtRenderArea*> RenderAreaList;
37  // std::vector<SoQtRenderArea*>::iterator it, itE;
38  typedef std::vector<VP1ExaminerViewer*> RenderAreaList;
40 
42 };
43 
44 //___________________________________________________
45 IVP13DChannelWidget::IVP13DChannelWidget(const QString & name, const QString & information, const QString & contact_info)
46 : IVP1ChannelWidget(name,information,contact_info), m_d(new Imp)
47 {
48  m_d->itE = m_d->renderareas.end();
49 
50 }
51 
52 //___________________________________________________
54 {
55  setUpdatesEnabled(false);
56  m_d->it = m_d->renderareas.begin();
57  for (;m_d->it!=m_d->itE;++(m_d->it)) {
58  // SoQtRenderArea* ra = *(m_d->it);
59  VP1ExaminerViewer* ra = *(m_d->it);
60  ra->setAutoRedraw(false);//extra
61  SoNode * root = ra->getSceneGraph();
62  root->ref();
63  ra->setSceneGraph(0);
64  // SoGLRenderAction * renderaction1 = ra->getGLRenderAction();
65  // SoGLRenderAction * renderaction2 = ra->getOverlayGLRenderAction();
66  SoLineHighlightRenderAction * trick = new SoLineHighlightRenderAction();
67  SoLineHighlightRenderAction * trick2 = new SoLineHighlightRenderAction();
68  ra->setGLRenderAction(trick);
69  ra->setOverlayGLRenderAction(trick2);
70  // ra->setGLRenderAction(0);
71  // ra->setOverlayGLRenderAction(0);
72  delete ra;
73  // delete renderaction1;
74  // delete renderaction2;
75  delete trick;
76  delete trick2;
77  root->unref();
78  }
79  delete m_d;
80 }
81 
82 //___________________________________________________
84 {
85  m_d->it = m_d->renderareas.begin();
86  for (;m_d->it!=m_d->itE;++(m_d->it)) {
87  (*(m_d->it))->setAutoRedraw(enable);
88  }
89  IVP1ChannelWidget::setUpdatesEnabled(enable);
90 }
91 
92 //___________________________________________________
93 //void IVP13DChannelWidget::registerRenderArea(SoQtRenderArea* ra)
95 {
96  if (!ra) {
97  message("Error - tried to register NULL render area!");
98  return;
99  }
100 
102 
103  m_d->renderareas.push_back(ra);
104  m_d->itE = m_d->renderareas.end();
105 
106  //To make sure that it is the actual 3D widget that gets focus when
107  //we e.g. click anywhere else in the widget where the render area is
108  //placed within:
109  if (ra->getParentWidget()&&ra->getWidget())
110  ra->getParentWidget()->setFocusProxy(ra->getWidget());
111 }
112 
113 //___________________________________________________
115 {
116  //Stop spinning and abort any ongoing animations:
117  m_d->it = m_d->renderareas.begin();
118  for (;m_d->it!=m_d->itE;++(m_d->it)) {
119  VP1ExaminerViewer* ra = *(m_d->it);
120  if (ra->getTypeId().isDerivedFrom(SoQtViewer::getClassTypeId())) {
121  VP1CameraHelper::abortAnyCurrentZoom(static_cast<SoQtViewer*>(ra)->getCamera());
122  if (ra->getTypeId().isDerivedFrom(SoQtExaminerViewer::getClassTypeId())) {
123  if (static_cast<SoQtExaminerViewer*>(ra)->isAnimating())
124  static_cast<SoQtExaminerViewer*>(ra)->stopAnimating();
125  }
126  }
127  }
128 }
129 
130 //_______________________________________________________
131 QPixmap IVP13DChannelWidget::getSnapshot(bool transp, int width, bool /*batch*/)
132 {
133  VP1Msg::messageVerbose("IVP13DChannelWidget::getSnapshot()");
134 
135  // TODO: check if transp and width can be used in this implementation of the method
136  VP1Msg::messageVerbose("(currently, we are not using the values - transp: "+QString::number(transp)+" - width: "+QString::number(width)+")");
137 
138  //Unfortunately, the renderer's areas does not render properly by a
139  //simple grabWidget. We remedy this the hard way...
140  // m_d->it = m_d->renderareas.begin();
141  // message("Have "+QString::number(m_d->renderareas.size())+" ras");
142  // for (;m_d->it!=m_d->itE;++(m_d->it)) {
143  // SoQtRenderArea* ra = *(m_d->it);
144  // if (ra->isDoubleBuffer()) message("doublebuffer");
145  // if (ra->isDrawToFrontBufferEnable()) message("isDrawToFrontBufferEnable");
146  // if (ra->isQuadBufferStereo()) message("isQuadBufferStereo");
147  // if (ra->getAccumulationBuffer()) message("getAccumulationBuffer");
148  // if (ra->isOverlayRender()) message("isOverlayRender");
149  // if (ra->isClearBeforeRender()) message("isClearBeforeRender");
150  // ra->render();
151  // }
152  // return QPixmap::grabWidget ( this );
153 
154  QPixmap pm(geometry().size());
155 
156  QPainter painter;
157  painter.begin(&pm);
158  painter.drawPixmap(0,0,this->grab ( ));
159 
160  m_d->it = m_d->renderareas.begin();
161  for (;m_d->it!=m_d->itE;++(m_d->it)) {
162  VP1ExaminerViewer* ra = *(m_d->it);
163  QWidget * ra_w = ra->getNormalWidget();
164  QPixmap pmra = VP1QtInventorUtils::renderToPixmap(ra, ra_w->geometry().width(),ra_w->geometry().height());
165  if (pmra.isNull()) {
166  message("Error rendering scene to QPixmap!");
167  return QPixmap();
168  }
169  QPoint pos = ra_w->mapTo( this, QPoint(0,0) );
170 
171  painter.drawPixmap(pos.x(),pos.y(),pmra);
172 
173  }
174  painter.end();
175 
176  return pm;
177 }
178 
179 //_______________________________________________________
181 {
182  // ===> Setup stream writing to a byteArray:
183  QByteArray byteArray;
184  QBuffer buffer(&byteArray);
185  buffer.open(QIODevice::WriteOnly);
186  QDataStream out(&buffer);
187 
188  // ===> Write Data:
189 
190  //Version & base state:
191  out << (qint32)1; //version
192  out << IVP1ChannelWidget::saveState();//Always include state info from the base class.
193 
194  // Data from this class:
195 
196  //Transparency types (version 0 saved as strings instead of ints):
197  QList<int> transptypes;
198  m_d->it = m_d->renderareas.begin();
199  for (;m_d->it!=m_d->itE;++(m_d->it))
200  transptypes << VP1QtInventorUtils::transparencyTypeToInt((*(m_d->it))->getTransparencyType());
201  out << transptypes;
202 
203  //For any render area that can be casted as an SoQtViewer, we store the camera type and parameters.
204  //SoQtViewer::toggleCameraType()
205  //todo...
206 
207  // ===> Finish up:
208  buffer.close();
209  return byteArray;
210 
211 }
212 
213 //_______________________________________________________
215 {
216  // ===> Setup stream for getting the contents of the byteArray:
217  QBuffer buffer(&ba);
218  buffer.open(QIODevice::ReadOnly);
219  QDataStream state(&buffer);
220  // ===> Check version and pass on state info to base class:
221  qint32 version;
222  state >> version;
223  if (version!=0&&version!=1) {
224  message("Warning: State data in .vp1 file is in wrong format - ignoring!");
225  return;
226  }
227 
228  QByteArray basestate;
229  state >> basestate;
231  // ===> Decode the state info:
232 
233  //Transparency types:
234  if (version==0) {
235  QStringList dummy;
236  state >> dummy;
237  } else {
238  QList<int> transptypes;
239  state >> transptypes;
240  if (transptypes.count()!=static_cast<int>(m_d->renderareas.size())) {
241  message("Warning: State data in .vp1 file is in wrong format - ignoring!");
242  buffer.close();
243  return;
244  }
245  m_d->it = m_d->renderareas.begin();
246  for (;m_d->it!=m_d->itE;++(m_d->it))
247  (*(m_d->it))->setTransparencyType(VP1QtInventorUtils::intToTransparencyType(transptypes.takeFirst()));
248  }
249 
250  //Camera angles:
251  //todo..
252 
253  // ===> Finish up:
254  buffer.close();
255 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
VP1Msg.h
IVP13DChannelWidget::Imp::RenderAreaList
std::vector< VP1ExaminerViewer * > RenderAreaList
Definition: IVP13DChannelWidget.cxx:38
VP1CameraHelper.h
IVP13DChannelWidget::IVP13DChannelWidget
IVP13DChannelWidget(const QString &name, const QString &information, const QString &contact_info)
Definition: IVP13DChannelWidget.cxx:45
VP1ExaminerViewer::setSceneGraph
virtual void setSceneGraph(SoNode *)
Definition: VP1ExaminerViewer.cxx:3115
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
IVP13DChannelWidget::saveState
virtual QByteArray saveState()
Definition: IVP13DChannelWidget.cxx:180
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
IVP13DChannelWidget::m_d
Imp * m_d
Definition: IVP13DChannelWidget.h:56
sendEI_SPB.root
root
Definition: sendEI_SPB.py:34
IVP13DChannelWidget.h
IVP13DChannelWidget::goingToNextEvent
virtual void goingToNextEvent()
Definition: IVP13DChannelWidget.cxx:114
IVP13DChannelWidget::Imp
Definition: IVP13DChannelWidget.cxx:33
VP1QtInventorUtils.h
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
IVP13DChannelWidget::Imp::it
std::vector< VP1ExaminerViewer * >::iterator it
Definition: IVP13DChannelWidget.cxx:39
createCoolChannelIdFile.buffer
buffer
Definition: createCoolChannelIdFile.py:12
VP1ExaminerViewer.h
IVP13DChannelWidget::restoreFromState
virtual void restoreFromState(QByteArray)
Definition: IVP13DChannelWidget.cxx:214
VP1CameraHelper::abortAnyCurrentZoom
static void abortAnyCurrentZoom(SoCamera *camera)
Definition: VP1CameraHelper.cxx:265
VP1ExaminerViewer::getSceneGraph
virtual SoNode * getSceneGraph()
Definition: VP1ExaminerViewer.cxx:3138
IVP13DChannelWidget::Imp::itE
std::vector< VP1ExaminerViewer * >::iterator itE
Definition: IVP13DChannelWidget.cxx:39
LArG4GenerateShowerLib.geometry
geometry
Definition: LArG4GenerateShowerLib.py:19
python.xAODType.dummy
dummy
Definition: xAODType.py:4
IVP1ChannelWidget::message
void message(QString)
IVP13DChannelWidget::Imp::renderareas
RenderAreaList renderareas
Definition: IVP13DChannelWidget.cxx:41
IVP13DChannelWidget::getSnapshot
virtual QPixmap getSnapshot(bool transp=false, int width=0, bool batch=false)
Definition: IVP13DChannelWidget.cxx:131
IVP1ChannelWidget
Definition: IVP1ChannelWidget.h:34
IVP1ChannelWidget::state
State state() const
Definition: IVP1ChannelWidget.cxx:102
IVP1ChannelWidget::restoreFromState
virtual void restoreFromState(QByteArray)
Definition: IVP1ChannelWidget.cxx:326
IVP1ChannelWidget::saveState
virtual QByteArray saveState()
Definition: IVP1ChannelWidget.cxx:320
python.selection.number
number
Definition: selection.py:20
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
VP1QtInventorUtils::transparencyTypeToInt
static int transparencyTypeToInt(SoGLRenderAction::TransparencyType)
Definition: VP1QtInventorUtils.cxx:665
VP1Msg::messageVerbose
static void messageVerbose(const QString &)
Definition: VP1Msg.cxx:84
IVP13DChannelWidget::registerRenderArea
void registerRenderArea(VP1ExaminerViewer *)
Definition: IVP13DChannelWidget.cxx:94
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
get_generator_info.version
version
Definition: get_generator_info.py:33
Base_Fragment.width
width
Definition: Sherpa_i/share/common/Base_Fragment.py:59
IVP13DChannelWidget::setUpdatesEnabled
void setUpdatesEnabled(bool enable)
Definition: IVP13DChannelWidget.cxx:83
VP1QtInventorUtils::intToTransparencyType
static SoGLRenderAction::TransparencyType intToTransparencyType(int)
Definition: VP1QtInventorUtils.cxx:685
VP1QtInventorUtils::renderToPixmap
static QPixmap renderToPixmap(VP1ExaminerViewer *ra, int pixels_x, int pixels_y, bool transparent_background=false, double actualRenderedSizeFact=1.0)
Definition: VP1QtInventorUtils.cxx:595
IVP13DChannelWidget::~IVP13DChannelWidget
virtual ~IVP13DChannelWidget()
Definition: IVP13DChannelWidget.cxx:53
VP1QtInventorUtils::ensureInitLineWidthAndPointSize
static void ensureInitLineWidthAndPointSize(SoQtRenderArea *)
Definition: VP1QtInventorUtils.cxx:1518
VP1ExaminerViewer
Definition: VP1ExaminerViewer.h:30