|
From: <le...@us...> - 2007-01-14 16:11:20
|
Revision: 168
http://svn.sourceforge.net/qcell/?rev=168&view=rev
Author: lessm
Date: 2007-01-14 08:11:11 -0800 (Sun, 14 Jan 2007)
Log Message:
-----------
- 3D view have select mode
- 3D view have multiselect mode
Modified Paths:
--------------
trunk/qcell/baseheaders/Renderer.h
trunk/qcell/basesources/Renderer.cpp
trunk/qcell/basesources/simulationwindow.cpp
Modified: trunk/qcell/baseheaders/Renderer.h
===================================================================
--- trunk/qcell/baseheaders/Renderer.h 2007-01-14 14:47:03 UTC (rev 167)
+++ trunk/qcell/baseheaders/Renderer.h 2007-01-14 16:11:11 UTC (rev 168)
@@ -14,6 +14,8 @@
#include <QPixmap>
#include <QChar>
+#define SELECT_BUFFER_SIZE 64000
+
struct SYMBOL
{
bool hide;
@@ -43,21 +45,42 @@
GLuint generateBox(void);
void generateGreed(void);
+ int cursor_x, cursor_y;
+
QImage render1D(void);
QImage render2D(int zval=0);
QImage render3D(void);
CalculationData storage;
+ Qt::MouseButtons mouseButtons;
+ bool selectionMode;
+ GLuint numberOfSelectetObject;
+ GLuint selectBuffer[SELECT_BUFFER_SIZE];
+ QVector<int> selectetObjects;
+
+ int selectRect[4];
+ bool showSelectRect;
+
protected:
void initializeGL();
void paintGL();
void resizeGL(int width, int height);
+ virtual void mousePressEvent(QMouseEvent * event);
+ virtual void mouseReleaseEvent(QMouseEvent * event);
+ virtual void mouseMoveEvent(QMouseEvent * event);
+ virtual void wheelEvent(QWheelEvent * event);
+ void executeSelect(int x, int y, int width=1, int height=1);
+
public:
Renderer(QWidget *parent);
~Renderer();
+
+ void selectOne(int x, int y);
+ void multiSelect(int x, int y, int width, int height);
+ void drawRect(int x1, int y1, int x2, int y2);
/*
void setDataType(baseDataTypes::DATA_TYPES type = baseDataTypes::CHAR);
@@ -67,7 +90,7 @@
bool resizeData(int x, int y, int z, int t, char *dataPointer=NULL, bool foreignDataPointer=0);
bool resizeData(QVector<int> newSize, char *dataPointer=NULL, bool foreignDataPointer=0);
*/
- void render(void);
+ void render(bool renderGreed=1);
QImage renderToQImage(int zplane=-1);
void renderToPixmap(QPixmap *pixmap, int zval);
bool setSymbolColor(int index, QColor color);
@@ -92,8 +115,8 @@
CalculationData * getStorage(void);
- void setOrtoPerspective(void);
- void setRealPerspective(void);
+ void setOrtoPerspective(bool noClear=1);
+ void setRealPerspective(bool noClear=1);
protected slots:
void resizeDataEvent(void);
Modified: trunk/qcell/basesources/Renderer.cpp
===================================================================
--- trunk/qcell/basesources/Renderer.cpp 2007-01-14 14:47:03 UTC (rev 167)
+++ trunk/qcell/basesources/Renderer.cpp 2007-01-14 16:11:11 UTC (rev 168)
@@ -246,20 +246,116 @@
glRotatef(rotation[2], 0.0f, 0.0f, 1.0f);
render();
+ if(showSelectRect)
+ drawRect(selectRect[0], selectRect[1], selectRect[2], selectRect[3]);
}
- void Renderer::resizeGL(int width, int height)
- {
+void Renderer::resizeGL(int width, int height)
+{
glViewport(0, 0, width, height);
-
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
if(corectPerspective)
setRealPerspective();
else
- setOrtoPerspective();
+ setOrtoPerspective();
+}
-
- }
+void Renderer::mousePressEvent(QMouseEvent * event)
+{
+ mouseButtons = event->buttons();
+ cursor_x = event->x();
+ cursor_y = event->y();
+}
+void Renderer::mouseReleaseEvent(QMouseEvent * event)
+{
+ if(showSelectRect)
+ {
+ multiSelect(abs((selectRect[0] + selectRect[2])/2), abs((selectRect[1] + selectRect[3])/2), abs(selectRect[0] - selectRect[2]), abs(selectRect[1] - selectRect[3]));
+ }
+ else
+ if(mouseButtons==Qt::LeftButton)
+ {
+ selectOne(event->x(), event->y());
+ }
+ showSelectRect = 0;
+ repaint();
+}
+
+void Renderer::mouseMoveEvent(QMouseEvent * event)
+{
+ showSelectRect = 0;
+ if(event->buttons()==(Qt::LeftButton | Qt::RightButton))
+ {
+ rotateX((float)(event->y() - cursor_y)/2.0f);
+ rotateY((float)(event->x() - cursor_x)/2.0f);
+ cursor_x = event->x();
+ cursor_y = event->y();
+ }
+ else
+ if(event->buttons()==Qt::RightButton)
+ {
+ translateX((float)(event->x() - cursor_x)/10.0f);
+ translateY((float)(cursor_y - event->y())/10.0f);
+ cursor_x = event->x();
+ cursor_y = event->y();
+ }
+ else
+ if(event->buttons()==Qt::LeftButton)
+ {
+ selectRect[0] = cursor_x;
+ selectRect[1] = cursor_y;
+ selectRect[2] = event->x();
+ selectRect[3] = event->y();
+ showSelectRect = 1;
+
+ }
+ updateGL();
+}
+
+void Renderer::wheelEvent(QWheelEvent * event)
+{
+ translateZ((float)event->delta()/100.0f);
+ updateGL();
+}
+
+ void Renderer::executeSelect(int x, int y, int width, int height)
+{
+ GLint viewport[4];
+ glSelectBuffer(SELECT_BUFFER_SIZE, selectBuffer);
+ glRenderMode(GL_SELECT);
+ glInitNames();
+ glPushName(0);
+ selectionMode = 1;
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+
+ glGetIntegerv(GL_VIEWPORT, viewport);
+
+ gluPickMatrix((GLdouble)x, (GLdouble)(viewport[3]-y), width, height, viewport);
+
+ if(corectPerspective)
+ setRealPerspective();
+ else
+ setOrtoPerspective();
+ glMatrixMode(GL_MODELVIEW);
+ render(0);
+
+ numberOfSelectetObject = glRenderMode(GL_RENDER);
+
+ selectionMode = 0;
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ if(corectPerspective)
+ setRealPerspective();
+ else
+ setOrtoPerspective();
+}
+
+
+
Renderer::Renderer(QWidget *parent) : QGLWidget(parent)
{
discretValues = 1;
@@ -284,7 +380,13 @@
greed = 0;
corectPerspective = 1;
+
connect(&storage, SIGNAL(dataResized()), SLOT(resizeDataEvent()));
+
+ selectionMode = 0;
+ numberOfSelectetObject = 0;
+ selectetObjects.clear();
+ showSelectRect = 0;
}
Renderer::~Renderer()
@@ -307,6 +409,81 @@
delete imageBuffer;
imageBuffer = NULL;
}
+
+void Renderer::selectOne(int x, int y)
+{
+ unsigned int minVal = 0xffffffff;
+ int minValIndex = -1;
+ executeSelect(x, y, 1, 1);
+ selectetObjects.clear();
+ for(unsigned int i=0;i<numberOfSelectetObject * 4; i+=4)
+ {
+ if(minVal>selectBuffer[i + 1])
+ {
+ minVal = selectBuffer[i + 1];
+ minValIndex = selectBuffer[i + 3];
+ }
+ }
+ if(minValIndex!=1)
+ {
+ selectetObjects<<minValIndex;
+ updateGL();
+ }
+}
+
+void Renderer::multiSelect(int x, int y, int width, int height)
+{
+ executeSelect(x, y, width, height);
+ selectetObjects.clear();
+ for(unsigned int i=0;i<numberOfSelectetObject * 4; i+=4)
+ selectetObjects<<selectBuffer[i + 3];
+
+ if(numberOfSelectetObject>0)
+ updateGL();
+}
+void Renderer::drawRect(int x1, int y1, int x2, int y2)
+{
+ GLint viewport[4];
+ glDisable(GL_LIGHTING);
+ glDisable(GL_DEPTH_TEST);
+ glGetIntegerv(GL_VIEWPORT, viewport);
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glLoadIdentity();
+
+
+ gluOrtho2D(0, viewport[2], viewport[3], 0);
+
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
+
+ glColor3f(0.0f, 1.0f, 0.0f);
+
+ glBegin(GL_LINE_LOOP);
+ glVertex2i(x1, y1);
+ glVertex2i(x2, y1);
+ glVertex2i(x2, y2);
+ glVertex2i(x1, y2);
+ glVertex2i(x1, y1);
+ glEnd();
+
+ /*
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ if(corectPerspective)
+ setRealPerspective();
+ else
+ setOrtoPerspective();
+ */
+ glEnable(GL_DEPTH_TEST);
+ glEnable(GL_LIGHTING);
+ glPopMatrix();
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+}
+
/*
void Renderer::setDataType(baseDataTypes::DATA_TYPES type)
{
@@ -424,13 +601,18 @@
return 0;
}
*/
-void Renderer::render(void)
+void Renderer::render(bool renderGreed)
{
int counter = 0, index;
+ bool selectTest;
float mx = -(float)storage.getSizeX(), my = -(float)storage.getSizeY(), mz = -(float)storage.getSizeZ();
- glDisable(GL_LIGHTING);
- glCallList(greed);
- glEnable(GL_LIGHTING);
+ if(renderGreed)
+ {
+ glDisable(GL_LIGHTING);
+ glCallList(greed);
+ glEnable(GL_LIGHTING);
+ }
+ SYMBOL symbol;
for(int z=0;z<storage.getSizeZ();++z)
{
for(int y=storage.getSizeY();y>0;--y)
@@ -438,18 +620,69 @@
for(int x=0;x<storage.getSizeX();++x)
{
- index = storage.getValueAt_i(counter++);
+ index = storage.getValueAt_i(counter);
if(index>=symbolsMap.size())
index = symbolsMap.size() - 1;
+
+ symbol = symbolsMap[index];
+
if(!(symbolsMap[index].hide))
{
+ if(selectionMode)
+ glLoadName(counter);
+
glPushMatrix();
glTranslatef(mx + (float)x * 2.0f , my + (float)y * 2.0f, mz + (float)z * 2.0f);
- glMaterialfv(GL_FRONT, GL_DIFFUSE, symbolsMap[index].floatColorDiffuse);
- glMaterialfv(GL_FRONT, GL_SPECULAR, symbolsMap[index].floatColorSpectacular);
- glCallList(primitives[symbolsMap[index].primitiveID]);
+
+ glMaterialfv(GL_FRONT, GL_DIFFUSE, symbol.floatColorDiffuse);
+ glMaterialfv(GL_FRONT, GL_SPECULAR, symbol.floatColorSpectacular);
+
+ selectTest = 0;
+ /*
+ if(!selectionMode)
+ {
+ if(selectetObjects.contains(counter))
+ {
+ glEnable(GL_NORMALIZE);
+ glPushMatrix();
+ glScalef(0.8f, 0.8f, 0.8f);
+ glEnable(GL_COLOR_MATERIAL);
+ glDisable(GL_LIGHTING);
+ glPolygonMode(GL_FRONT, GL_LINE);
+ glColor3b((char)symbol.textColor.red(), (char)symbol.textColor.green(), (char)symbol.textColor.blue());
+ glCallList(primitives[symbol.primitiveID]);
+ glPolygonMode(GL_FRONT, GL_FILL);
+ glEnable(GL_LIGHTING);
+ glDisable(GL_COLOR_MATERIAL);
+ glPopMatrix();
+ glDisable(GL_NORMALIZE);
+ selectTest = 1;
+ }
+ }*/
+
+ if(!selectionMode)
+ {
+ if(selectetObjects.contains(counter))
+ {
+ glPolygonMode(GL_FRONT, GL_LINE);
+ glCallList(primitives[symbol.primitiveID]);
+ glPolygonMode(GL_FRONT, GL_FILL);
+ glEnable(GL_NORMALIZE);
+ glPushMatrix();
+ glScalef(0.8f, 0.8f, 0.8f);
+ glCallList(primitives[symbol.primitiveID]);
+ glPopMatrix();
+ glDisable(GL_NORMALIZE);
+ }
+ else
+ glCallList(primitives[symbol.primitiveID]);
+ }
+ else
+ glCallList(primitives[symbol.primitiveID]);
+
glPopMatrix();
}
+ ++counter;
}
}
}
@@ -635,20 +868,22 @@
setOrtoPerspective();
}
-void Renderer::setOrtoPerspective(void)
+void Renderer::setOrtoPerspective(bool noClear)
{
float aspect = (float)width()/(float)height();
glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
+ if(!noClear)
+ glLoadIdentity();
glOrtho((-(double)storage.getSizeX() - 20.0) * aspect, ((double)storage.getSizeX() + 20.0) * aspect, -(double)storage.getSizeY() - 20.0 , (double)storage.getSizeY() + 20.0, 0.0, 500.0);
glMatrixMode(GL_MODELVIEW);
corectPerspective = 0;
}
-void Renderer::setRealPerspective(void)
+void Renderer::setRealPerspective(bool noClear)
{
glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
+ if(!noClear)
+ glLoadIdentity();
gluPerspective(75.0f, (GLdouble)width() / (GLdouble)height(), 0.1f, 500.0f);
glMatrixMode(GL_MODELVIEW);
corectPerspective = 1;
Modified: trunk/qcell/basesources/simulationwindow.cpp
===================================================================
--- trunk/qcell/basesources/simulationwindow.cpp 2007-01-14 14:47:03 UTC (rev 167)
+++ trunk/qcell/basesources/simulationwindow.cpp 2007-01-14 16:11:11 UTC (rev 168)
@@ -2,6 +2,7 @@
void simulationWindow::mouseMoveEvent(QMouseEvent * event)
{
+ /*
if(ui.view3D->isVisible())
{
if(event->buttons()==(Qt::LeftButton | Qt::RightButton))
@@ -21,16 +22,11 @@
cursor_y = event->y();
renderer->updateGL();
}
+ */
}
void simulationWindow::wheelEvent(QWheelEvent * event)
{
- if(ui.view3D->isVisible())
- {
- renderer->translateZ((float)event->delta()/100.0f);
- renderer->updateGL();
- }
-
if(ui.view2DGraph->isVisible())
{
//if(ui.view2DGraph->isVisible())
@@ -73,11 +69,8 @@
void simulationWindow::mousePressEvent(QMouseEvent * event)
{
- //if(ui.view3D->isVisible())
- //{
- cursor_x = event->x();
- cursor_y = event->y();
- //}
+ cursor_x = event->x();
+ cursor_y = event->y();
}
void simulationWindow::resizeEvent(QResizeEvent * event)
@@ -122,6 +115,7 @@
else
view3DTools->hide();
+
if(ui.view2D->isVisible())
{
view2DTextTools->show();
@@ -624,11 +618,17 @@
switch(renderer->getStorage()->getDimension())
{
case 1:
- update1DTable();
- update1DTableMem();
+ if(ui.view3D->isVisible())
+ {
+ update1DTable();
+ update1DTableMem();
+ }
+ else
+ table1DUpdateRequest = 1;
break;
case 3:
- renderer->repaint();
+ if(ui.view3D->isVisible())
+ renderer->repaint();
case 2:
if(ui.view2D->isVisible())
@@ -777,11 +777,11 @@
switch(mode)
{
case 0:
- renderer->setRealPerspective();
+ renderer->setRealPerspective(0);
renderer->repaint();
break;
case 1:
- renderer->setOrtoPerspective();
+ renderer->setOrtoPerspective(0);
renderer->repaint();
break;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|