55 #include <ACG/GL/acg_glew.hh> 57 #include "QtBaseViewer.hh" 58 #include "QtGLGraphicsScene.hh" 59 #include "QtGLGraphicsView.hh" 60 #include "QtSceneGraphWidget.hh" 62 #include "../Scenegraph/SceneGraph.hh" 65 #include <QToolButton> 68 #include <QApplication> 69 #include <QPushButton> 71 #include <QColorDialog> 72 #include <QFileDialog> 75 #include <QDesktopWidget> 76 #include <QButtonGroup> 78 #include <QGraphicsWidget> 79 #include <QGraphicsGridLayout> 80 #include <QGraphicsProxyWidget> 86 #include "set_home.xpm" 87 #include "viewall.xpm" 91 #include "scenegraph.xpm" 95 #define homeIcon home_xpm 96 #define sethomeIcon set_home_xpm 97 #define moveIcon move_xpm 98 #define lightIcon light_xpm 99 #define questionIcon info_xpm 100 #define viewallIcon viewall_xpm 101 #define pickIcon pick_xpm 102 #define perspectiveIcon persp_xpm 103 #define orthoIcon ortho_xpm 104 #define sceneGraphIcon scenegraph_xpm 105 #define monoIcon mono_xpm 120 namespace QtWidgets {
125 static const char VIEW_MAGIC[] =
126 "ACG::QtWidgets::QGLViewerWidget encoded view";
133 QStatusBar *_statusBar,
134 const QGLFormat* _format,
139 glareaGrabbed_(false),
140 updateLocked_(false),
141 projectionUpdateLocked_(false),
143 sceneGraphDialog_(0),
145 privateStatusBar_(0),
146 disableKeyHandling_(false),
147 externalDrag_(false),
148 snapshotName_(
"snap.png"),
153 renderPicking_(false),
160 std::cerr <<
"This system has no OpenGL support.\n";
166 createWidgets(_format,_statusBar,_share);
193 backFaceCulling_ =
false;
194 twoSidedLighting_ =
false;
203 popupEnabled_ =
true;
227 for (
int i=6666; i<6676; ++i)
230 std::cout <<
"listen on port " << i <<
"\n";
244 action_.insert(
"Background",
new QAction(
"Background color",
this ) );
245 action_.insert(
"Snapshot",
new QAction(
"Snapshot",
this ) );
246 action_.insert(
"SnapshotName",
new QAction(
"Set snapshot name",
this ) );
247 action_.insert(
"SnapshotSavesView",
new QAction(
"Snapshot saves view",
this ) );
248 action_.insert(
"CopyView",
new QAction(
"Copy view",
this ) );
249 action_.insert(
"PasteView",
new QAction(
"Paste view",
this ) );
250 action_.insert(
"PasteDropSize",
new QAction(
"Paste/Drop effects size",
this ) );
251 action_.insert(
"Synchronize",
new QAction(
"Synchronize",
this ) );
252 action_.insert(
"Animation",
new QAction(
"Animation",
this ) );
253 action_.insert(
"BackfaceCulling",
new QAction(
"Backface culling",
this ) );
254 action_.insert(
"TwoSidedLighting",
new QAction(
"Two-sided lighting",
this ) );
256 connect( action_[
"Background"], SIGNAL( triggered() ),
257 this, SLOT( actionBackground() ) );
258 connect( action_[
"Snapshot"], SIGNAL( triggered() ),
260 connect( action_[
"SnapshotName"], SIGNAL( triggered() ),
262 connect( action_[
"SnapshotSavesView"], SIGNAL( triggered() ),
264 connect( action_[
"CopyView"], SIGNAL( triggered() ),
265 this, SLOT( actionCopyView() ) );
266 connect( action_[
"PasteView"], SIGNAL( triggered() ),
267 this, SLOT( actionPasteView() ) );
268 connect( action_[
"PasteDropSize"], SIGNAL( triggered() ),
269 this, SLOT( actionPasteDropSize() ) );
270 connect( action_[
"Synchronize"], SIGNAL( triggered() ),
271 this, SLOT( actionSynchronize() ) );
272 connect( action_[
"Animation"], SIGNAL( triggered() ),
273 this, SLOT( actionAnimation() ) );
274 connect( action_[
"BackfaceCulling"], SIGNAL( triggered() ),
275 this, SLOT( actionBackfaceCulling() ) );
276 connect( action_[
"TwoSidedLighting"], SIGNAL( triggered() ),
277 this, SLOT( actionTwoSidedLighting() ) );
279 action_[
"SnapshotSavesView"]->setCheckable(
true );
280 action_[
"PasteDropSize"]->setCheckable(
true );
281 action_[
"Synchronize"]->setCheckable(
true );
282 action_[
"Animation"]->setCheckable(
true );
283 action_[
"BackfaceCulling"]->setCheckable(
true );
284 action_[
"TwoSidedLighting"]->setCheckable(
true );
287 QSizePolicy sp = sizePolicy();
288 sp.setHorizontalPolicy( QSizePolicy::Expanding );
289 sp.setVerticalPolicy( QSizePolicy::Expanding );
290 sp.setHorizontalStretch( 1 );
291 sp.setVerticalStretch( 1 );
294 redrawTime_.start ();
304 delete privateStatusBar_;
307 delete sceneGraphDialog_;
317 QtBaseViewer::sizeHint()
const 319 return QSize( 600, 600 );
330 if (privateStatusBar_==0)
331 privateStatusBar_=
new QStatusBar(
this);
332 statusbar_=privateStatusBar_;
334 privateStatusBar_->show();
336 privateStatusBar_->hide();
355 else if (privateStatusBar_!=0)
356 privateStatusBar_->hide();
359 else buttonBar_->hide();
361 else pickButton_->hide();
363 else questionButton_->hide();
365 else wheelX_->hide();
367 else wheelY_->hide();
369 else wheelZ_->hide();
378 sceneGraphRoot_ = _root;
395 if ( ( bbmin[0] > bbmax[0] ) ||
396 ( bbmin[1] > bbmax[1] ) ||
397 ( bbmin[2] > bbmax[2] ) )
401 ( bbmax - bbmin ).norm() * 0.5 );
415 updateLocked_ =
true;
423 updateLocked_ =
false;
439 trackMouse_ = _track;
448 popupEnabled_ = _enable;
450 if ( popupEnabled_ ) {
451 glView_->setContextMenuPolicy( Qt::DefaultContextMenu );
453 glView_->setContextMenuPolicy( Qt::CustomContextMenu );
494 projectionButton_->setIcon( QPixmap(orthoIcon) );
496 projectionButton_->setIcon( QPixmap(perspectiveIcon) );
513 emit navigationModeChanged(
true );
515 emit navigationModeChanged(
false );
521 if( projectionUpdateLocked_ )
550 glstate_->
ortho( -orthoWidth_, orthoWidth_,
551 -orthoWidth_/aspect, orthoWidth_/aspect,
564 scene_center_ = trackball_center_ = _center;
567 scene_radius_ = trackball_radius_ = _radius;
569 orthoWidth_ = 2.0 * scene_radius_;
574 far_ = std::max(0.0002f * scene_radius_, -(c[2] - scene_radius_));
577 near_ = std::max(0.0001f * scene_radius_, -(c[2] + scene_radius_));
588 scene_center_ = trackball_center_ = _center;
597 ACG::Vec3d eye = scene_center_ - _dir*(3.0*scene_radius_);
620 moveButton_->setDown(
false);
621 lightButton_->setDown(
false);
622 pickButton_->setDown(
false);
623 questionButton_->setDown(
false);
628 if (_am != actionMode_)
630 lastActionMode_ = actionMode_;
639 glView_->setCursor(Qt::PointingHandCursor);
640 glBase_->setCursor(Qt::PointingHandCursor);
641 moveButton_->setDown(
true);
648 glView_->setCursor(Qt::PointingHandCursor);
649 glBase_->setCursor(Qt::PointingHandCursor);
650 lightButton_->setDown(
true);
657 glView_->setCursor(Qt::ArrowCursor);
658 glBase_->setCursor(Qt::ArrowCursor);
659 pickButton_->setDown(
true);
672 glView_->setCursor(Qt::WhatsThisCursor);
673 glBase_->setCursor(Qt::WhatsThisCursor);
674 questionButton_->setDown(
true);
697 switch ( faceOrientation_ = _ori ) {
699 glFrontFace( GL_CCW );
703 glFrontFace( GL_CW );
717 if (funcMenu_==0) updatePopupMenu();
718 if ( (backFaceCulling_ = _b) )
723 action_[
"BackfaceCulling"]->setChecked( backFaceCulling_ );
731 if (funcMenu_==0) updatePopupMenu();
733 action_[
"TwoSidedLighting"]->setChecked(twoSidedLighting_);
741 if (funcMenu_==0) updatePopupMenu();
743 action_[
"Animation"]->setChecked( animation_ );
755 switch(normalsMode_ = _mode)
794 void QtBaseViewer::drawScene()
807 far_ = std::max(0.0002f * scene_radius_, -(c[2] - scene_radius_));
810 near_ = std::max(0.0001f * scene_radius_, -(c[2] + scene_radius_));
820 if (
stereo_) drawScene_stereo();
821 else drawScene_mono();
825 frame_time_ = timer.elapsed();
832 void QtBaseViewer::drawScene_mono()
853 glClear(GL_DEPTH_BUFFER_BIT);
869 QtBaseViewer::drawScene_stereo()
871 double l, r, t, b, w, h, a, radians, wd2, ndfl;
877 radians = fovy_ * 0.5 / 180.0 * M_PI;
878 wd2 = near_ * tan(radians);
887 double offset2 = offset * ndfl;
892 glMatrixMode(GL_PROJECTION);
894 glFrustum(l+offset2, r+offset2, b, t, near_, far_);
895 glTranslatef(-offset, 0.0, 0.0);
896 glMatrixMode(GL_MODELVIEW);
898 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
903 glMatrixMode(GL_PROJECTION);
905 glFrustum(l-offset2, r-offset2, b, t, near_, far_);
906 glTranslatef(offset, 0.0, 0.0);
907 glMatrixMode(GL_MODELVIEW);
909 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
923 homeOrthoWidth_ = orthoWidth_;
924 home_center_ = trackball_center_;
925 home_radius_ = trackball_radius_;
932 glstate_->
set_modelview(home_modelview_, home_inverse_modelview_);
933 orthoWidth_ = homeOrthoWidth_;
934 trackball_center_ = home_center_;
935 trackball_radius_ = home_radius_;
955 -
Vec3d(0.0, 0.0, 3.0*scene_radius_ ));
957 orthoWidth_ = 1.1*scene_radius_;
959 if (aspect > 1.0) orthoWidth_ *= aspect;
977 unsigned int nodeIdx, targetIdx;
985 Vec3d t = hitPoint - eye;
986 Vec3d e = eye + t * (_move_back ? -0.5f : 0.5f);
987 flyTo(e, hitPoint, 300);
992 orthoWidth_ *= _move_back ? 2.0 : 0.5;
996 trackball_center_ = hitPoint;
1016 const Vec3d& _center,
1024 Vec3d view =(p-c).normalize();
1026 Vec3d axis = (z % -view).normalize();
1027 double angle = acos(std::max(-1.0,
1029 (z | view)))) / M_PI * 180.0;
1032 axis =
Vec3d(0,1,0);
1037 Vec3d trans ( -target[0],
1039 -target[2] - (_position-_center).norm() );
1044 unsigned int frames = (
unsigned int)(_time / frame_time_);
1045 if (frames > 1000) frames=1000;
1053 Vec3d t = trans / (double)frames;
1054 double a = angle / (double)frames;
1056 for (
unsigned int i=0; i<frames; ++i)
1059 if (fabs(a) > FLT_MIN)
1060 rotate(axis, a, _center);
1071 if (fabs(angle) > FLT_MIN)
1072 rotate(axis, angle, _center);
1078 trackball_center_ = _center;
1079 trackball_radius_ = std::max(scene_radius_,
1080 (_center-_position).norm()*0.9f);
1119 if (glstate_->compatibilityProfile())
1136 scene_center_ = trackball_center_ =
Vec3d( 0.0, 0.0, 0.0 );
1137 scene_radius_ = trackball_radius_ = 1.0;
1147 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
1148 glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
1149 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
1150 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1151 glPixelStorei(GL_PACK_ROW_LENGTH, 0);
1152 glPixelStorei(GL_PACK_SKIP_ROWS, 0);
1153 glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
1154 glPixelStorei(GL_PACK_ALIGNMENT, 1);
1173 glMatrixMode(GL_MODELVIEW);
1176 glMultMatrixd(light_matrix_.data());
1178 GLfloat pos[4], col[4];
1180 col[0] = col[1] = col[2] = 0.7f;
1181 pos[3] = col[3] = 0.0f;
1183 #define SET_LIGHT(i,x,y,z) { \ 1184 pos[0]=x; pos[1]=y; pos[2]=z; \ 1185 glLightfv(GL_LIGHT##i, GL_POSITION, pos); \ 1186 glLightfv(GL_LIGHT##i, GL_DIFFUSE, col); \ 1187 glLightfv(GL_LIGHT##i, GL_SPECULAR, col); \ 1188 ACG::GLState::enable(GL_LIGHT##i); \ 1191 SET_LIGHT(0, 0.0f, 0.0f, 1.0f);
1192 SET_LIGHT(1, -1.0f, 1.0f, 0.7f);
1193 SET_LIGHT(2, 1.0f, 1.0f, 0.7f);
1195 col[0] = col[1] = col[2] = 0.3f; col[3] = 1.0f;
1196 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, col);
1204 light_matrix_.
rotate(_angle, _axis[0], _axis[1], _axis[2], MULT_FROM_LEFT);
1214 static bool initialized =
false;
1233 scene_center_ = trackball_center_ =
Vec3d( 0.0, 0.0, 0.0 );
1234 scene_radius_ = trackball_radius_ = 1.0;
1242 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
1243 glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
1244 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
1245 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1246 glPixelStorei(GL_PACK_ROW_LENGTH, 0);
1247 glPixelStorei(GL_PACK_SKIP_ROWS, 0);
1248 glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
1249 glPixelStorei(GL_PACK_ALIGNMENT, 1);
1264 glPushAttrib (GL_ALL_ATTRIB_BITS);
1270 if (glstate_->compatibilityProfile())
1273 glMatrixMode(GL_PROJECTION);
1276 glMatrixMode(GL_MODELVIEW);
1289 glColor4f(1.0,0.0,0.0,1.0);
1293 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1302 glMatrixMode(GL_PROJECTION);
1330 _view += QString(VIEW_MAGIC) +
"\n";
1331 _view += QString::number(m(0,0)) +
" " + QString::number(m(0,1)) +
" " + QString::number(m(0,2)) +
" " + QString::number(m(0,3)) +
"\n";
1332 _view += QString::number(m(1,0)) +
" " + QString::number(m(1,1)) +
" " + QString::number(m(1,2)) +
" " + QString::number(m(1,3)) +
"\n";
1333 _view += QString::number(m(2,0)) +
" " + QString::number(m(2,1)) +
" " + QString::number(m(2,2)) +
" " + QString::number(m(2,3)) +
"\n";
1334 _view += QString::number(m(3,0)) +
" " + QString::number(m(3,1)) +
" " + QString::number(m(3,2)) +
" " + QString::number(m(3,3)) +
"\n";
1337 _view += QString::number(p(0,0)) +
" " + QString::number(p(0,1)) +
" " + QString::number(p(0,2)) +
" " + QString::number(p(0,3)) +
"\n";
1338 _view += QString::number(p(1,0)) +
" " + QString::number(p(1,1)) +
" " + QString::number(p(1,2)) +
" " + QString::number(p(1,3)) +
"\n";
1339 _view += QString::number(p(2,0)) +
" " + QString::number(p(2,1)) +
" " + QString::number(p(2,2)) +
" " + QString::number(p(2,3)) +
"\n";
1340 _view += QString::number(p(3,0)) +
" " + QString::number(p(3,1)) +
" " + QString::number(p(3,2)) +
" " + QString::number(p(3,3)) +
"\n";
1343 _view += QString::number(
glWidth()) +
" " + QString::number(
glHeight()) +
" " + QString::number(projectionMode_) +
" " + QString::number(orthoWidth_) +
"\n";
1352 if (_view.left(
sizeof(VIEW_MAGIC)-1) != QString(VIEW_MAGIC))
1356 QString temp = _view;
1357 temp.remove(0,
sizeof(VIEW_MAGIC));
1360 QStringList split = temp.split(QRegExp(
"[\\n\\s]"),QString::SkipEmptyParts);
1366 if ( split.size() != 36 ) {
1367 std::cerr <<
"Unable to paste view ... wrong parameter count!! is" << split.size() << std::endl;
1374 m(0,0) = split[0].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1375 m(0,1) = split[1].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1376 m(0,2) = split[2].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1377 m(0,3) = split[3].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1378 m(1,0) = split[4].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1379 m(1,1) = split[5].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1380 m(1,2) = split[6].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1381 m(1,3) = split[7].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1382 m(2,0) = split[8].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1383 m(2,1) = split[9].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1384 m(2,2) = split[10].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1385 m(2,3) = split[11].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1386 m(3,0) = split[12].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1387 m(3,1) = split[13].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1388 m(3,2) = split[14].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1389 m(3,3) = split[15].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1390 p(0,0) = split[16].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1391 p(0,1) = split[17].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1392 p(0,2) = split[18].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1393 p(0,3) = split[19].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1394 p(1,0) = split[20].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1395 p(1,1) = split[21].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1396 p(1,2) = split[22].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1397 p(1,3) = split[23].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1398 p(2,0) = split[24].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1399 p(2,1) = split[25].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1400 p(2,2) = split[26].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1401 p(2,3) = split[27].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1402 p(3,0) = split[28].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1403 p(3,1) = split[29].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1404 p(3,2) = split[30].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1405 p(3,3) = split[31].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1407 w = split[32].toInt(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1408 h = split[33].toInt(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1409 pMode = split[34].toInt(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1410 orthoWidth_ = split[35].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1424 action_[
"PasteDropSize"]->isChecked() )
1427 glView_->setFixedSize(w,h);
1442 void QtBaseViewer::actionDrawMenu( QAction * _action )
1447 if (qApp->keyboardModifiers() & Qt::ShiftModifier)
1459 std::vector< QAction * >::iterator aIter, aEnd;
1461 aEnd = drawMenuActions_.end();
1462 for( aIter = drawMenuActions_.begin();
1467 (*aIter)->setChecked(
false );
1481 void QtBaseViewer::actionBackground()
1484 QColor backCol((
int)bc[0], (
int)bc[1], (
int)bc[2]);
1485 QColor c = QColorDialog::getColor(backCol,
this);
1486 if (c != backCol && c.isValid())
1488 ((
double) c.green()) / 255.0f,
1489 ((
double) c.blue()) / 255.0f,
1497 void QtBaseViewer::actionCopyView()
1500 QApplication::clipboard()->setText(view);
1507 void QtBaseViewer::actionPasteView()
1509 QString view; view=QApplication::clipboard()->text();
1517 void QtBaseViewer::actionPasteDropSize()
1524 void QtBaseViewer::actionSynchronize()
1531 void QtBaseViewer::actionSynchronize(
bool _enable)
1542 void QtBaseViewer::actionAnimation()
1549 void QtBaseViewer::actionAnimation(
bool _enable)
1556 void QtBaseViewer::actionBackfaceCulling()
1563 void QtBaseViewer::actionBackfaceCulling(
bool _enable)
1570 void QtBaseViewer::actionTwoSidedLighting()
1577 void QtBaseViewer::actionTwoSidedLighting(
bool _enable)
1585 void QtBaseViewer::updatePopupMenu()
1593 drawMenu_ =
new QMenu(
this );
1594 connect( drawMenu_, SIGNAL( aboutToHide() ),
1595 this, SLOT( hidePopupMenus() ) );
1599 QActionGroup * drawGroup =
new QActionGroup(
this );
1600 drawGroup->setExclusive(
false );
1601 connect( drawGroup, SIGNAL( triggered( QAction * ) ),
1602 this, SLOT( actionDrawMenu( QAction * ) ) );
1606 drawMenuActions_.clear();
1608 std::vector< SceneGraph::DrawModes::DrawMode > draw_mode_id;
1612 for (
unsigned int i = 0; i < draw_mode_id.size(); ++i )
1615 std::string descr =
id.description();
1617 QAction * action =
new QAction( descr.c_str(), drawGroup );
1618 action->setData( QVariant( quint64(
id.getIndex() ) ) );
1619 action->setCheckable(
true );
1621 drawMenuActions_.push_back( action );
1626 drawMenu_->addActions( drawGroup->actions() );
1633 funcMenu_=
new QMenu(
this );
1635 funcMenu_->addAction( action_[
"Background" ] );
1636 funcMenu_->addSeparator();
1637 funcMenu_->addAction( action_[
"Snapshot" ] );
1638 funcMenu_->addAction( action_[
"SnapshotName" ] );
1639 funcMenu_->addAction( action_[
"SnapshotSavesView" ] );
1640 funcMenu_->addSeparator();
1641 funcMenu_->addAction( action_[
"CopyView" ] );
1642 funcMenu_->addAction( action_[
"PasteView" ] );
1643 funcMenu_->addAction( action_[
"PasteDropSize" ] );
1644 funcMenu_->addSeparator();
1645 funcMenu_->addAction( action_[
"Synchronize" ] );
1646 funcMenu_->addSeparator();
1647 funcMenu_->addAction( action_[
"Animation" ] );
1648 funcMenu_->addAction( action_[
"BackfaceCulling" ] );
1649 funcMenu_->addAction( action_[
"TwoSidedLighting" ] );
1651 connect( funcMenu_, SIGNAL( aboutToHide() ),
1652 this, SLOT( hidePopupMenus() ) );
1662 void QtBaseViewer::hidePopupMenus()
1666 drawMenu_->blockSignals(
true);
1668 drawMenu_->blockSignals(
false);
1673 funcMenu_->blockSignals(
true);
1675 funcMenu_->blockSignals(
false);
1680 pickMenu_->blockSignals(
true);
1682 pickMenu_->blockSignals(
false);
1693 glstate_->
translate(_trans[0], _trans[1], _trans[2], MULT_FROM_LEFT);
1712 const Vec3d& _center)
1716 glstate_->
translate(-t[0], -t[1], -t[2], MULT_FROM_LEFT);
1717 glstate_->
rotate(_angle, _axis[0], _axis[1], _axis[2], MULT_FROM_LEFT);
1718 glstate_->
translate( t[0], t[1], t[2], MULT_FROM_LEFT);
1728 return glView_->width();
1731 return glView_->height();
1734 return glView_->size();
1737 return glView_->mapFromGlobal(_pos);
1741 return glView_->mapToGlobal(_pos);
1751 if (sceneGraphRoot_)
1753 if (!sceneGraphDialog_)
1762 connect(sceneGraphDialog_,
1768 sceneGraphDialog_->show();
1811 double dz=_dist*0.5/M_PI*scene_radius_*2.0;
1826 glBase_->setGeometry (rect);
1832 void QtBaseViewer::grabGLArea()
1834 glareaGrabbed_ =
true;
1836 glView_->setCursor(Qt::BlankCursor);
1837 glBase_->setCursor(Qt::BlankCursor);
1838 glView_->grabMouse();
1839 glView_->grabKeyboard();
1842 void QtBaseViewer::releaseGLArea()
1844 glareaGrabbed_ =
false;
1846 glView_->releaseMouse();
1847 glView_->releaseKeyboard();
1848 glView_->setCursor(Qt::ArrowCursor);
1849 glBase_->setCursor(Qt::ArrowCursor);
1861 QPoint cpos(QCursor::pos()), dpos, fpos, ppos;
1862 int offset = 10, dw, dh, fw, fh, pw, ph;
1863 int minx, maxx, miny, maxy;
1868 # define WIDTH width() 1869 # define HEIGHT height() 1871 # define WIDTH sizeHint().width() 1872 # define HEIGHT sizeHint().height() 1880 dw = drawMenu_->WIDTH;
1881 dh = drawMenu_->HEIGHT;
1882 dpos = cpos + QPoint(offset, offset);
1886 dpos = cpos; dw=dh=0;
1894 fw = funcMenu_->WIDTH;
1895 fh = funcMenu_->HEIGHT;
1896 fpos = cpos + QPoint(offset, -offset-fh);
1900 fpos = cpos; fw=fh=0;
1908 pw = pickMenu_->WIDTH;
1909 ph = pickMenu_->HEIGHT;
1910 ppos = cpos + QPoint(-offset-pw, -ph/2);
1914 ppos = cpos; pw=ph=0;
1920 minx = std::min(dpos.x(), std::min(fpos.x(), ppos.x()));
1921 maxx = std::max(dpos.x()+dw, std::max(fpos.x()+fw, ppos.x()+pw));
1922 miny = std::min(dpos.y(), std::min(fpos.y(), ppos.y()));
1923 maxy = std::max(dpos.y()+dh, std::max(fpos.y()+fh, ppos.y()+ph));
1930 else if (maxx >= qApp->desktop()->width())
1932 dx = qApp->desktop()->width() - maxx;
1939 else if (maxy >= qApp->desktop()->height())
1941 dy = qApp->desktop()->height() - maxy;
1945 dpos += QPoint(dx, dy);
1946 fpos += QPoint(dx, dy);
1947 ppos += QPoint(dx, dy);
1952 bool animate_menu = qApp->isEffectEnabled(Qt::UI_AnimateMenu);
1953 bool fade_menu = qApp->isEffectEnabled(Qt::UI_FadeMenu);
1954 if (animate_menu) qApp->setEffectEnabled(Qt::UI_AnimateMenu,
false);
1955 if (fade_menu) qApp->setEffectEnabled(Qt::UI_FadeMenu,
false);
1963 drawMenu_->popup(dpos);
1967 funcMenu_->popup(fpos);
1970 pickMenu_->popup(ppos);
1974 if (animate_menu) qApp->setEffectEnabled(Qt::UI_AnimateMenu,
true);
1975 if (fade_menu) qApp->setEffectEnabled(Qt::UI_FadeMenu,
true);
1989 if (_event->button() == Qt::RightButton && popupEnabled_)
1995 switch (actionMode_)
1998 if ((_event->modifiers() & Qt::ControlModifier))
2030 switch (actionMode_)
2057 switch ( actionMode_ )
2070 if ((_event->buttons() & (Qt::LeftButton | Qt::MidButton | Qt::RightButton))
2096 if (_event->button() != Qt::RightButton ||
2099 switch ( actionMode_ )
2123 isRotating_ =
false;
2132 switch ( actionMode_ )
2146 isRotating_ =
false;
2156 pickMenu_ =
new QMenu( 0 );
2157 connect( pickMenu_, SIGNAL( aboutToHide() ),
2158 this, SLOT( hidePopupMenus() ) );
2160 QActionGroup * ag =
new QActionGroup( pickMenu_ );
2161 ag->setExclusive(
true );
2163 for (
unsigned int i=0; i<
pick_modes_.size(); ++i) {
2170 pickMenu_->addSeparator();
2174 QAction * ac =
new QAction(
pick_modes_[i].name.c_str(), ag );
2175 ac->setData( QVariant( i ) );
2176 ac->setCheckable(
true );
2179 ac->setChecked(
true );
2181 pickMenu_->addAction( ac );
2185 connect( ag, SIGNAL( triggered( QAction * ) ),
2186 this, SLOT( actionPickMenu( QAction * ) ));
2192 void QtBaseViewer::actionPickMenu( QAction * _action )
2194 int _id = _action->data().toInt();
2212 glLayout_->removeWidget( buttonBar_ );
2226 glstate_->
translate(dir[0], dir[1], dir[2]);
2240 glstate_->
translate(dir[0], dir[1], dir[2]);
2254 glstate_->
translate(dir[0], dir[1], dir[2]);
2268 glstate_->
translate(dir[0], dir[1], dir[2]);
virtual void viewMouseEvent(QMouseEvent *_event)=0
specialized viewer: hande mouse events
virtual void showSceneGraphDialog()
show scenegraph widget
bool synchronization()
synchronized with different viewer?
ProjectionMode
projection mode
QSize glSize() const
get size of QGLWIdget
FaceOrientation
orientation of the faces
Namespace providing different geometric functions concerning angles.
void translate(const Vec3d &trans)
translate the scene and update modelview matrix
unsigned int glWidth() const
get width of QGLWidget
Show wheel for rotation around y-axis (bottom)?
void signalSetView(const GLMatrixd &_modelview, const GLMatrixd &_inverse_modelview)
set view, used for synchronizing (cf. slotSetView())
Vec3d right() const
get right-vector w.r.t. camera coordinates
const GLMatrixd & inverse_modelview() const
get inverse modelview matrix
static double clip(double _angle)
void moveBack()
First person navigation: Move back.
virtual void toggleNavigationMode()
toggle navigation mode
virtual void lightMouseEvent(QMouseEvent *)
optional: hande mouse events to rotate light
GLState & glState()
get OpenGL state
virtual void setView(const GLMatrixd &_modelview, const GLMatrixd &_inverse_modelview)
set view, used for synchronizing
pick any of the prior targets (should be implemented for all nodes)
virtual void unlockUpdate()
Unlock display locked by updateLock().
double eyeDist_
Set eye distance for stereo.
void signalWheelEvent(QWheelEvent *, const std::string &)
Emitted in Pick mode. Uses pick mode.
virtual void slotNodeChanged(ACG::SceneGraph::BaseNode *_node)
connected to scenegraph widget
void startDragEvent(QMouseEvent *_event)
virtual void unlockAndUpdate()
virtual void glContextMenuEvent(QContextMenuEvent *_event)
handle mouse press events
void trackMouse(bool _track)
Enable/disable mouse tracking (move events with no button press)
void rotate_lights(Vec3d &_axis, double _angle)
rotete light sources
std::vector< PickMode > pick_modes_
Show pick button? Effect only if ShowToolBar!
void applyOptions(int _options)
Apply ORed Options _options.
void set_twosided_lighting(bool _b)
set whether transparent or solid objects should be drawn
virtual void startDrag()
drag & drop for modelview copying
const GLMatrixd & projection() const
get projection matrix
void reset_modelview()
reset modelview matrix (load identity)
VectorT< float, 4 > Vec4f
bool synchronized_
synchronized with different viewer?
virtual void slotWheelX(double _dAngle)
process signals from wheelX_
void actionSnapshotSavesView()
void translate(double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
translate by (_x, _y, _z)
bool isUpdateLocked() const
DrawModes::DrawMode drawModes() const
Get the collected draw modes.
void actionSnapshotName()
void encodeView(QString &_view)
convert current view to text representation
void signalMouseEvent(QMouseEvent *, const std::string &)
const Vec4f & clear_color() const
get background color
VectorT< T, 3 > transform_point(const VectorT< T, 3 > &_v) const
transform point (x',y',z',1) = M * (x,y,z,1)
static double deg(double _angle)
maps _angle from radiants to degrees (works also for clip()ped angles)
void sync_send(const GLMatrixd &_modelview, const GLMatrixd &_inverse_modelview)
synchronized with different viewer?
virtual void perspectiveProjection()
set perspective view (projectionMode(PERSPECTIVE_PROJECTION))
virtual void swapBuffers()
Swaps the screen contents with the off-screen buffer.
NavigationMode
Navigation mode.
Show wheel for rotation around x-axis (left)?
void strafeLeft()
First person navigation: Strafe left.
virtual void glMousePressEvent(QMouseEvent *_event)
handle mouse press events
void rotate(const Vec3d &axis, double angle)
rotate the scene (around its center) and update modelview matrix
virtual void toggleProjectionMode()
toggle projection mode
NormalsMode
Automatically normalize normals?
NormalsMode normalsMode() const
get treatment of normals
void perspective(double _fovY, double _aspect, double _near_plane, double _far_plane)
perspective projection
virtual void slotWheelZ(double _dist)
process signals from wheelZ_
NavigationMode navigationMode() const
get current navigation mode
virtual void viewAll()
view the whole scene
QToolBar * getToolBar()
Returns a pointer to the Toolbar.
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
void signalActionModeChanged(ACG::QtWidgets::QtBaseViewer::ActionMode _m)
action mode was changed
bool stereo_
Set eye distance for stereo.
void strafeRight()
First person navigation: Strafe Right.
void ortho(double _left, double _right, double _bottom, double _top, double _near_plane, double _far_plane)
orthographic projection
bool backFaceCulling() const
is backface culling enabled?
double focalDist_
Set eye distance for stereo.
void setSceneCenter(const ACG::Vec3d &_center)
static void drawBuffer(GLenum _mode)
replaces glDrawBuffer, supports locking
virtual void initializeGL()
initialize OpenGL states
void signalInitializeGL()
emitted when OpenGL stuff can be initialized
QPoint glMapFromGlobal(const QPoint &_pos) const
map global to glarea coords
void signalMouseEventIdentify(QMouseEvent *)
use provided normals as is
VectorT< double, 3 > Vec3d
void moveForward()
First person navigation: Move forward.
Show question button? Effect only if ShowToolBar!
DrawMode NONE
not a valid draw mode
const Vec3d & bbMin() const
Returns minimum point of the bounding box.
virtual void setHome()
set home position
void set_clear_color(const Vec4f &_col)
set background color
virtual void orthographicProjection()
set orthographic view (projectionMode(ORTHOGRAPHIC_PROJECTION))
virtual void glMouseWheelEvent(QWheelEvent *_event)
handle mouse wheel events
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking
std::vector< DrawMode > getAtomicDrawModes() const
Separates this drawMode into a list of all separate atomic draw modes.
void signalDrawScene(ACG::GLState *_state)
render callback
const std::string & pickMode() const
virtual void makeCurrent()
Makes this widget the current widget for OpenGL operations.
void signalNodeChanged(ACG::SceneGraph::BaseNode *_node)
scene graph has changed
void initModelviewMatrix()
initialize modelview matrix to identity
virtual void examineMode()
calls actionMode() with ExamineMode (cf. ActionMode)
QtBaseViewer(QWidget *_parent=0, const char *_name=0, QStatusBar *_statusBar=0, const QGLFormat *_format=0, const QtBaseViewer *_share=0, Options _options=DefaultOptions)
void viewport(int _left, int _bottom, int _width, int _height, int _glwidth=0, int _glheight=0)
set viewport (lower left corner, width, height, glcontext width, height)
Vec3d viewing_direction() const
get viewing ray
ActionMode
How to react on mouse events?
void viewChanged()
This signal is emitted whenever the view is changed by the user.
FaceOrientation faceOrientation() const
get face orientation
void updateProjectionMatrix()
updates projection matrix
counter clockwise (default)
QToolBar * removeToolBar()
Returns a pointer to the toolbar and removes it from the default position in the examiner widget...
void reset_projection()
reset projection matrix (load identity)
virtual void glMouseDoubleClickEvent(QMouseEvent *_event)
handle mouse double click events
QUdpSocket * socket_
socket used for synchronization
virtual void updateGL()
Redraw scene. Triggers paint event for updating the view (cf. drawNow()).
ProjectionMode projectionMode() const
get current projection mode
const GLMatrixd & modelview() const
get modelview matrix
Vec4f backgroundColor()
get background color
virtual void paintGL()
draw the scene. Triggered by updateGL().
ACG::SceneGraph::DrawModes::DrawMode drawMode()
get current draw mode
std::string pick_mode_name_
virtual void viewWheelEvent(QWheelEvent *_event)=0
specialized viewer: handle wheel events
bool skipNextSync_
Skips the next synch event.
void rotate(double _angle, double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
rotate around axis (_x, _y, _z) by _angle
virtual void glMouseReleaseEvent(QMouseEvent *_event)
handle mouse release events
void identity()
setup an identity matrix
void updatePickMenu()
update pick mode menu
void traverse(BaseNode *_node, Action &_action)
bool animation() const
Is animation enabled?
ACG::SceneGraph::PickTarget pickRendererMode_
unsigned int glHeight() const
get height of QGLWidget
void update_lights()
update light position
virtual void sceneRectChanged(const QRectF &rect)
process graphics scene size changes
virtual ~QtBaseViewer()
Destructor.
void viewingDirection(const ACG::Vec3d &_dir, const ACG::Vec3d &_up)
set the viewing direction
ActionMode actionMode() const
get action mode
void initialize()
initialize all state variables (called by constructor)
void set_modelview(const GLMatrixd &_m)
set modelview
virtual void home()
go to home pos
void enablePopupMenu(bool _enable)
Enable/disable right button draw mode menu (default: enabled)
void setScenePos(const ACG::Vec3d &_center, double _radius, const bool _setCenter=true)
void rotate(Scalar angle, Scalar x, Scalar y, Scalar z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
void signalPickModeChanged(const std::string &)
virtual void glMouseMoveEvent(QMouseEvent *_event)
handle mouse move events
void setState()
set the whole stored gl state
void setStatusBar(QStatusBar *_sb)
void set_msSinceLastRedraw(unsigned int _ms)
set time passed since last redraw in milliseconds
void setFovy(double _fovy)
set field of view y
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
bool containsAtomicDrawMode(const DrawMode &_atomicDrawMode) const
Check whether an Atomic DrawMode is active in this draw Mode.
bool decodeView(const QString &_view)
virtual void lockUpdate()
const Vec3d & bbMax() const
Returns maximum point of the bounding box.
void lookAt(const Vec3d &_eye, const Vec3d &_center, const Vec3d &_up)
set camera by lookAt
bool pick(SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, Vec3d *_hitPointPtr=0)
void set_projection(const GLMatrixd &_m)
set projection
QPoint glMapToGlobal(const QPoint &_pos) const
map glarea coords to global coords
bool add_sync_host(const QString &_name)
add host to synchronize with, given by its name
void signalSceneGraphChanged(ACG::SceneGraph::BaseNode *_root)
scene graph has changed
virtual void slotWheelY(double _dAngle)
process signals from wheelX_
virtual void setSynchronization(bool _b)
toggle global synchronization
virtual void resizeGL(int _w, int _h)
handle resize events
virtual void flyTo(const QPoint &_pos, bool _move_back)
Fly to. Get closer if _move_back=false, get more distant else.
SceneGraph::BaseNode * sceneGraph()
Returns: root node of scene graph.
bool twoSidedLighting() const
is 2-sided lighing enabled?