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 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) 1361 QStringList split = temp.split(QRegExp(
"[\\n\\s]"),QString::SkipEmptyParts);
1363 QStringList split = temp.split(QRegExp(
"[\\n\\s]"),Qt::SkipEmptyParts);
1370 if ( split.size() != 36 ) {
1371 std::cerr <<
"Unable to paste view ... wrong parameter count!! is" << split.size() << std::endl;
1378 m(0,0) = split[0].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1379 m(0,1) = split[1].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1380 m(0,2) = split[2].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1381 m(0,3) = split[3].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1382 m(1,0) = split[4].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1383 m(1,1) = split[5].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1384 m(1,2) = split[6].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1385 m(1,3) = split[7].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1386 m(2,0) = split[8].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1387 m(2,1) = split[9].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1388 m(2,2) = split[10].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1389 m(2,3) = split[11].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1390 m(3,0) = split[12].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1391 m(3,1) = split[13].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1392 m(3,2) = split[14].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1393 m(3,3) = split[15].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1394 p(0,0) = split[16].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1395 p(0,1) = split[17].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1396 p(0,2) = split[18].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1397 p(0,3) = split[19].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1398 p(1,0) = split[20].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1399 p(1,1) = split[21].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1400 p(1,2) = split[22].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1401 p(1,3) = split[23].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1402 p(2,0) = split[24].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1403 p(2,1) = split[25].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1404 p(2,2) = split[26].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1405 p(2,3) = split[27].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1406 p(3,0) = split[28].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1407 p(3,1) = split[29].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1408 p(3,2) = split[30].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1409 p(3,3) = split[31].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1411 w = split[32].toInt(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1412 h = split[33].toInt(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1413 pMode = split[34].toInt(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1414 orthoWidth_ = split[35].toDouble(&ok);
if ( !ok ) { std::cerr <<
"Error in decoding View!" << std::endl;
return false; }
1428 action_[
"PasteDropSize"]->isChecked() )
1431 glView_->setFixedSize(w,h);
1446 void QtBaseViewer::actionDrawMenu( QAction * _action )
1451 if (qApp->keyboardModifiers() & Qt::ShiftModifier)
1463 std::vector< QAction * >::iterator aIter, aEnd;
1465 aEnd = drawMenuActions_.end();
1466 for( aIter = drawMenuActions_.begin();
1471 (*aIter)->setChecked(
false );
1485 void QtBaseViewer::actionBackground()
1488 QColor backCol((
int)bc[0], (
int)bc[1], (
int)bc[2]);
1489 QColor c = QColorDialog::getColor(backCol,
this);
1490 if (c != backCol && c.isValid())
1492 ((
double) c.green()) / 255.0f,
1493 ((
double) c.blue()) / 255.0f,
1501 void QtBaseViewer::actionCopyView()
1504 QApplication::clipboard()->setText(view);
1511 void QtBaseViewer::actionPasteView()
1513 QString view; view=QApplication::clipboard()->text();
1521 void QtBaseViewer::actionPasteDropSize()
1528 void QtBaseViewer::actionSynchronize()
1535 void QtBaseViewer::actionSynchronize(
bool _enable)
1546 void QtBaseViewer::actionAnimation()
1553 void QtBaseViewer::actionAnimation(
bool _enable)
1560 void QtBaseViewer::actionBackfaceCulling()
1567 void QtBaseViewer::actionBackfaceCulling(
bool _enable)
1574 void QtBaseViewer::actionTwoSidedLighting()
1581 void QtBaseViewer::actionTwoSidedLighting(
bool _enable)
1589 void QtBaseViewer::updatePopupMenu()
1597 drawMenu_ =
new QMenu(
this );
1598 connect( drawMenu_, SIGNAL( aboutToHide() ),
1599 this, SLOT( hidePopupMenus() ) );
1603 QActionGroup * drawGroup =
new QActionGroup(
this );
1604 drawGroup->setExclusive(
false );
1605 connect( drawGroup, SIGNAL( triggered( QAction * ) ),
1606 this, SLOT( actionDrawMenu( QAction * ) ) );
1610 drawMenuActions_.clear();
1612 std::vector< SceneGraph::DrawModes::DrawMode > draw_mode_id;
1616 for (
unsigned int i = 0; i < draw_mode_id.size(); ++i )
1619 std::string descr =
id.description();
1621 QAction * action =
new QAction( descr.c_str(), drawGroup );
1622 action->setData( QVariant( quint64(
id.getIndex() ) ) );
1623 action->setCheckable(
true );
1625 drawMenuActions_.push_back( action );
1630 drawMenu_->addActions( drawGroup->actions() );
1637 funcMenu_=
new QMenu(
this );
1639 funcMenu_->addAction( action_[
"Background" ] );
1640 funcMenu_->addSeparator();
1641 funcMenu_->addAction( action_[
"Snapshot" ] );
1642 funcMenu_->addAction( action_[
"SnapshotName" ] );
1643 funcMenu_->addAction( action_[
"SnapshotSavesView" ] );
1644 funcMenu_->addSeparator();
1645 funcMenu_->addAction( action_[
"CopyView" ] );
1646 funcMenu_->addAction( action_[
"PasteView" ] );
1647 funcMenu_->addAction( action_[
"PasteDropSize" ] );
1648 funcMenu_->addSeparator();
1649 funcMenu_->addAction( action_[
"Synchronize" ] );
1650 funcMenu_->addSeparator();
1651 funcMenu_->addAction( action_[
"Animation" ] );
1652 funcMenu_->addAction( action_[
"BackfaceCulling" ] );
1653 funcMenu_->addAction( action_[
"TwoSidedLighting" ] );
1655 connect( funcMenu_, SIGNAL( aboutToHide() ),
1656 this, SLOT( hidePopupMenus() ) );
1666 void QtBaseViewer::hidePopupMenus()
1670 drawMenu_->blockSignals(
true);
1672 drawMenu_->blockSignals(
false);
1677 funcMenu_->blockSignals(
true);
1679 funcMenu_->blockSignals(
false);
1684 pickMenu_->blockSignals(
true);
1686 pickMenu_->blockSignals(
false);
1697 glstate_->
translate(_trans[0], _trans[1], _trans[2], MULT_FROM_LEFT);
1716 const Vec3d& _center)
1720 glstate_->
translate(-t[0], -t[1], -t[2], MULT_FROM_LEFT);
1721 glstate_->
rotate(_angle, _axis[0], _axis[1], _axis[2], MULT_FROM_LEFT);
1722 glstate_->
translate( t[0], t[1], t[2], MULT_FROM_LEFT);
1732 return glView_->width();
1735 return glView_->height();
1738 return glView_->size();
1741 return glView_->mapFromGlobal(_pos);
1745 return glView_->mapToGlobal(_pos);
1755 if (sceneGraphRoot_)
1757 if (!sceneGraphDialog_)
1766 connect(sceneGraphDialog_,
1772 sceneGraphDialog_->show();
1815 double dz=_dist*0.5/M_PI*scene_radius_*2.0;
1830 glBase_->setGeometry (rect);
1836 void QtBaseViewer::grabGLArea()
1838 glareaGrabbed_ =
true;
1840 glView_->setCursor(Qt::BlankCursor);
1841 glBase_->setCursor(Qt::BlankCursor);
1842 glView_->grabMouse();
1843 glView_->grabKeyboard();
1846 void QtBaseViewer::releaseGLArea()
1848 glareaGrabbed_ =
false;
1850 glView_->releaseMouse();
1851 glView_->releaseKeyboard();
1852 glView_->setCursor(Qt::ArrowCursor);
1853 glBase_->setCursor(Qt::ArrowCursor);
1865 QPoint cpos(QCursor::pos()), dpos, fpos, ppos;
1866 int offset = 10, dw, dh, fw, fh, pw, ph;
1867 int minx, maxx, miny, maxy;
1872 # define WIDTH width() 1873 # define HEIGHT height() 1875 # define WIDTH sizeHint().width() 1876 # define HEIGHT sizeHint().height() 1884 dw = drawMenu_->WIDTH;
1885 dh = drawMenu_->HEIGHT;
1886 dpos = cpos + QPoint(offset, offset);
1890 dpos = cpos; dw=dh=0;
1898 fw = funcMenu_->WIDTH;
1899 fh = funcMenu_->HEIGHT;
1900 fpos = cpos + QPoint(offset, -offset-fh);
1904 fpos = cpos; fw=fh=0;
1912 pw = pickMenu_->WIDTH;
1913 ph = pickMenu_->HEIGHT;
1914 ppos = cpos + QPoint(-offset-pw, -ph/2);
1918 ppos = cpos; pw=ph=0;
1924 minx = std::min(dpos.x(), std::min(fpos.x(), ppos.x()));
1925 maxx = std::max(dpos.x()+dw, std::max(fpos.x()+fw, ppos.x()+pw));
1926 miny = std::min(dpos.y(), std::min(fpos.y(), ppos.y()));
1927 maxy = std::max(dpos.y()+dh, std::max(fpos.y()+fh, ppos.y()+ph));
1934 else if (maxx >= qApp->desktop()->width())
1936 dx = qApp->desktop()->width() - maxx;
1943 else if (maxy >= qApp->desktop()->height())
1945 dy = qApp->desktop()->height() - maxy;
1949 dpos += QPoint(dx, dy);
1950 fpos += QPoint(dx, dy);
1951 ppos += QPoint(dx, dy);
1956 bool animate_menu = qApp->isEffectEnabled(Qt::UI_AnimateMenu);
1957 bool fade_menu = qApp->isEffectEnabled(Qt::UI_FadeMenu);
1958 if (animate_menu) qApp->setEffectEnabled(Qt::UI_AnimateMenu,
false);
1959 if (fade_menu) qApp->setEffectEnabled(Qt::UI_FadeMenu,
false);
1967 drawMenu_->popup(dpos);
1971 funcMenu_->popup(fpos);
1974 pickMenu_->popup(ppos);
1978 if (animate_menu) qApp->setEffectEnabled(Qt::UI_AnimateMenu,
true);
1979 if (fade_menu) qApp->setEffectEnabled(Qt::UI_FadeMenu,
true);
1993 if (_event->button() == Qt::RightButton && popupEnabled_)
1999 switch (actionMode_)
2002 if ((_event->modifiers() & Qt::ControlModifier))
2034 switch (actionMode_)
2061 switch ( actionMode_ )
2074 if ((_event->buttons() & (Qt::LeftButton | Qt::MidButton | Qt::RightButton))
2100 if (_event->button() != Qt::RightButton ||
2103 switch ( actionMode_ )
2127 isRotating_ =
false;
2136 switch ( actionMode_ )
2150 isRotating_ =
false;
2160 pickMenu_ =
new QMenu( 0 );
2161 connect( pickMenu_, SIGNAL( aboutToHide() ),
2162 this, SLOT( hidePopupMenus() ) );
2164 QActionGroup * ag =
new QActionGroup( pickMenu_ );
2165 ag->setExclusive(
true );
2167 for (
unsigned int i=0; i<
pick_modes_.size(); ++i) {
2174 pickMenu_->addSeparator();
2178 QAction * ac =
new QAction(
pick_modes_[i].name.c_str(), ag );
2179 ac->setData( QVariant( i ) );
2180 ac->setCheckable(
true );
2183 ac->setChecked(
true );
2185 pickMenu_->addAction( ac );
2189 connect( ag, SIGNAL( triggered( QAction * ) ),
2190 this, SLOT( actionPickMenu( QAction * ) ));
2196 void QtBaseViewer::actionPickMenu( QAction * _action )
2198 int _id = _action->data().toInt();
2216 glLayout_->removeWidget( buttonBar_ );
2230 glstate_->
translate(dir[0], dir[1], dir[2]);
2244 glstate_->
translate(dir[0], dir[1], dir[2]);
2258 glstate_->
translate(dir[0], dir[1], dir[2]);
2272 glstate_->
translate(dir[0], dir[1], dir[2]);
DrawModes::DrawMode drawModes() const
Get the collected draw modes.
const Vec3d & bbMax() const
Returns maximum point of the bounding box.
void rotate(Scalar angle, Scalar x, Scalar y, Scalar z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
void reset_modelview()
reset modelview matrix (load identity)
Vec3d viewing_direction() const
get viewing ray
void set_clear_color(const Vec4f &_col)
set background color
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking
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)
Namespace providing different geometric functions concerning angles.
bool containsAtomicDrawMode(const DrawMode &_atomicDrawMode) const
Check whether an Atomic DrawMode is active in this draw Mode.
VectorT< float, 4 > Vec4f
void identity()
setup an identity matrix
VectorT< T, 3 > transform_point(const VectorT< T, 3 > &_v) const
transform point (x',y',z',1) = M * (x,y,z,1)
void reset_projection()
reset projection matrix (load identity)
void set_modelview(const GLMatrixd &_m)
set modelview
void perspective(double _fovY, double _aspect, double _near_plane, double _far_plane)
perspective projection
Vec3d right() const
get right-vector w.r.t. camera coordinates
void set_msSinceLastRedraw(unsigned int _ms)
set time passed since last redraw in milliseconds
const GLMatrixd & inverse_modelview() const
get inverse modelview matrix
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
pick any of the prior targets (should be implemented for all nodes)
void ortho(double _left, double _right, double _bottom, double _top, double _near_plane, double _far_plane)
orthographic projection
std::vector< DrawMode > getAtomicDrawModes() const
Separates this drawMode into a list of all separate atomic draw modes.
DrawMode NONE
not a valid draw mode
void rotate(double _angle, double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
rotate around axis (_x, _y, _z) by _angle
const Vec3d & bbMin() const
Returns minimum point of the bounding box.
const GLMatrixd & modelview() const
get modelview matrix
void set_projection(const GLMatrixd &_m)
set projection
void set_twosided_lighting(bool _b)
set whether transparent or solid objects should be drawn
void setState()
set the whole stored gl state
static void drawBuffer(GLenum _mode)
replaces glDrawBuffer, supports locking
void lookAt(const Vec3d &_eye, const Vec3d &_center, const Vec3d &_up)
set camera by lookAt
const GLMatrixd & projection() const
get projection matrix
const Vec4f & clear_color() const
get background color
void translate(double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
translate by (_x, _y, _z)
void traverse(BaseNode *_node, Action &_action)
void initialize()
initialize all state variables (called by constructor)
VectorT< double, 3 > Vec3d