File indexing completed on 2024-04-21 03:40:41
0001 /************************************************************************************* 0002 * Copyright (C) 2010-2012 by Percy Camilo T. Aucahuasi <percy.camilo.ta@gmail.com> * 0003 * Copyright (C) 2007 by Abderrahman Taha: Basic OpenGL calls like scene, lights * 0004 * and mouse behaviour taken from K3DSurf * 0005 * * 0006 * This program is free software; you can redistribute it and/or * 0007 * modify it under the terms of the GNU General Public License * 0008 * as published by the Free Software Foundation; either version 2 * 0009 * of the License, or (at your option) any later version. * 0010 * * 0011 * This program is distributed in the hope that it will be useful, * 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0014 * GNU General Public License for more details. * 0015 * * 0016 * You should have received a copy of the GNU General Public License * 0017 * along with this program; if not, write to the Free Software * 0018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 0019 *************************************************************************************/ 0020 0021 #include "plotsview3d.h" 0022 #include <analitzaplot/plotsmodel.h> 0023 #include <analitzaplot/surface.h> 0024 #include <analitzaplot/spacecurve.h> 0025 #include <QVector3D> 0026 #include <QItemSelectionModel> 0027 #include <QVector> 0028 #include <QDebug> 0029 0030 using namespace Analitza; 0031 0032 PlotsView3D::PlotsView3D(QWidget *parent) 0033 : QGLWidget(parent), m_selection(0), old_x(-1), old_y(-1) 0034 { 0035 setFocusPolicy(Qt::ClickFocus); 0036 } 0037 0038 PlotsView3D::~PlotsView3D() 0039 {} 0040 0041 void PlotsView3D::setSelectionModel(QItemSelectionModel* selection) 0042 { 0043 Q_ASSERT(selection); 0044 0045 m_selection = selection; 0046 // connect(m_selection,SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(forceRepaint())); 0047 } 0048 0049 void PlotsView3D::resetView() 0050 { 0051 //TODO remove qglviewer 0052 // setSceneCenter(qglviewer::Vec(0.f,0.f,0.f)); 0053 0054 // camera()->setUpVector(qglviewer::Vec(-1,-1,1), false); 0055 // camera()->setPosition(qglviewer::Vec(7,7,7)); 0056 // camera()->lookAt(qglviewer::Vec(0,0,0)); 0057 // camera()->setRevolveAroundPoint(qglviewer::Vec(0,0,0)); 0058 } 0059 0060 void PlotsView3D::addFuncs(const QModelIndex & parent, int start, int end) 0061 { 0062 updatePlots(parent, start, end); 0063 } 0064 0065 void PlotsView3D::removeFuncs(const QModelIndex & parent, int start, int end) 0066 { 0067 updatePlots(parent, start, end); 0068 } 0069 0070 //NOTE 0071 //si hay un cambio aki es desetvisible (que no es necesario configurar en el plotitem) o es del 0072 //setinterval (que si es necesario configurarlo en el plotitem) 0073 //el enfoque es: si hay un cambio borro el displaylist y lo genero de nuevo (no lo genero si el item no es visible) 0074 //TODO cache para exp e interval ... pues del resto es solo cuestion de update 0075 void PlotsView3D::updateFuncs(const QModelIndex& start, const QModelIndex& end) 0076 { 0077 updatePlots(QModelIndex(), start.row(), end.row()); 0078 } 0079 0080 void PlotsView3D::paintGL() 0081 { 0082 drawPlots(); 0083 } 0084 0085 void PlotsView3D::initializeGL() 0086 { 0087 initGL(); 0088 } 0089 0090 void PlotsView3D::resizeGL(int newwidth, int newheight) 0091 { 0092 setViewport(QRectF(0,0,newwidth,newheight)); 0093 } 0094 0095 void PlotsView3D::mousePressEvent(QMouseEvent *e) 0096 { 0097 buttons = e->buttons(); 0098 0099 old_y = e->y(); 0100 old_x = e->x(); 0101 CartesianAxis axis = selectAxisArrow(e->x(), e->y()); 0102 showAxisArrowHint(axis); 0103 0104 if (isRotationFixed() && axis != InvalidAxis) { 0105 fixRotation(QVector3D()); 0106 hideAxisHint(); 0107 } else switch (axis) 0108 { 0109 case XAxis: 0110 fixRotation(QVector3D(1,0,0)); 0111 break; 0112 case YAxis: 0113 fixRotation(QVector3D(0,1,0)); 0114 break; 0115 case ZAxis: 0116 fixRotation(QVector3D(0,0,1)); 0117 break; 0118 case InvalidAxis: 0119 break; 0120 } 0121 0122 } 0123 0124 void PlotsView3D::modelChanged() 0125 { 0126 // if (model()) { 0127 // disconnect(model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(updateFuncs(QModelIndex,QModelIndex))); 0128 // disconnect(model(), SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(addFuncs(QModelIndex,int,int))); 0129 // disconnect(model(), SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(removeFuncs(QModelIndex,int,int))); 0130 // } 0131 0132 // for (int i = 0; i < model()->rowCount(); ++i) { 0133 // if (itemAt(i)) { 0134 // glDeleteLists(m_displayLists[itemAt(i)], 1); 0135 // addFuncs(QModelIndex(), 0, model()->rowCount()-1); 0136 // } 0137 // } 0138 0139 connect(model(), &QAbstractItemModel::dataChanged, this, &PlotsView3D::updateFuncs); 0140 connect(model(), &QAbstractItemModel::rowsInserted, this, &PlotsView3D::addFuncs); 0141 connect(model(), &QAbstractItemModel::rowsRemoved, this, &PlotsView3D::removeFuncs); 0142 0143 update(); 0144 } 0145 0146 void PlotsView3D::renderGL() 0147 { 0148 update(); 0149 } 0150 0151 void PlotsView3D::wheelEvent(QWheelEvent* ev) 0152 { 0153 scale(1.f-ev->delta()/1000.f); 0154 } 0155 0156 void PlotsView3D::mouseMoveEvent(QMouseEvent *e) 0157 { 0158 //TODO translate with middle btn 0159 // Rotational function : 0160 if(buttons & Qt::LeftButton) 0161 rotate(old_x - e->x(), old_y - e->y()); 0162 0163 old_y = e->y(); 0164 old_x = e->x(); 0165 } 0166 0167 void PlotsView3D::keyPressEvent(QKeyEvent* ev) 0168 { 0169 switch(ev->key()) { 0170 case Qt::Key_S: 0171 scale(1.1); 0172 break; 0173 case Qt::Key_W: 0174 scale(0.9); 0175 break; 0176 case Qt::Key_Left: 0177 rotate(-10, 0); 0178 break; 0179 case Qt::Key_Right: 0180 rotate(10, 0); 0181 break; 0182 case Qt::Key_Up: 0183 rotate(0, -10); 0184 break; 0185 case Qt::Key_Down: 0186 rotate(0, 10); 0187 break; 0188 } 0189 } 0190 0191 #include "moc_plotsview3d.cpp"