Skip to content
Snippets Groups Projects
Commit 8234b2cb authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

fix memory leak (models were never cleared!) + cleanup formatting

parent 8d56eee8
Branches
Tags
No related merge requests found
...@@ -25,17 +25,16 @@ static jobject gCallbackObject = NULL; ...@@ -25,17 +25,16 @@ static jobject gCallbackObject = NULL;
class MobileMessage : public GmshMessage class MobileMessage : public GmshMessage
{ {
private:
public: public:
MobileMessage(){} MobileMessage(){}
~MobileMessage(){} ~MobileMessage(){}
void operator()(std::string level, std::string message) void operator()(std::string level, std::string message)
{ {
if(level == "Error") if(level == "Error"){
{
LOGE("Error:\t%s", message.c_str()); LOGE("Error:\t%s", message.c_str());
JNIEnv *env; JNIEnv *env;
if(gJavaVM->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK || !gCallbackObject || (gJavaVM->AttachCurrentThread(&env, NULL)) < 0) return; if(gJavaVM->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK ||
!gCallbackObject || (gJavaVM->AttachCurrentThread(&env, NULL)) < 0) return;
jstring jstr = env->NewStringUTF(message.c_str()); jstring jstr = env->NewStringUTF(message.c_str());
jclass jClass = env->FindClass("org/geuz/onelab/Gmsh"); jclass jClass = env->FindClass("org/geuz/onelab/Gmsh");
if(jClass == 0) if(jClass == 0)
...@@ -48,10 +47,10 @@ class MobileMessage : public GmshMessage ...@@ -48,10 +47,10 @@ class MobileMessage : public GmshMessage
env->DeleteLocalRef(jClass); env->DeleteLocalRef(jClass);
return; return;
} }
else if(level == "Progress") else if(level == "Progress"){
{
JNIEnv *env; JNIEnv *env;
if(gJavaVM->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK || !gCallbackObject || (gJavaVM->AttachCurrentThread(&env, NULL)) < 0) return; if(gJavaVM->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK ||
!gCallbackObject || (gJavaVM->AttachCurrentThread(&env, NULL)) < 0) return;
jstring jstr = env->NewStringUTF(message.c_str()); jstring jstr = env->NewStringUTF(message.c_str());
jclass jClass = env->FindClass("org/geuz/onelab/Gmsh"); jclass jClass = env->FindClass("org/geuz/onelab/Gmsh");
if(jClass == 0) if(jClass == 0)
...@@ -64,8 +63,7 @@ class MobileMessage : public GmshMessage ...@@ -64,8 +63,7 @@ class MobileMessage : public GmshMessage
env->DeleteLocalRef(jClass); env->DeleteLocalRef(jClass);
return; return;
} }
else if(level == "RequestRender") else if(level == "RequestRender"){
{
requestRender(); requestRender();
return; return;
} }
...@@ -76,7 +74,8 @@ class MobileMessage : public GmshMessage ...@@ -76,7 +74,8 @@ class MobileMessage : public GmshMessage
void requestRender() void requestRender()
{ {
JNIEnv *env; JNIEnv *env;
if(gJavaVM->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK || !gCallbackObject || (gJavaVM->AttachCurrentThread(&env, NULL)) < 0) return; if(gJavaVM->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK ||
!gCallbackObject || (gJavaVM->AttachCurrentThread(&env, NULL)) < 0) return;
jclass jClass = env->FindClass("org/geuz/onelab/Gmsh"); jclass jClass = env->FindClass("org/geuz/onelab/Gmsh");
if(jClass == 0) if(jClass == 0)
return; return;
...@@ -87,15 +86,18 @@ void requestRender() ...@@ -87,15 +86,18 @@ void requestRender()
env->DeleteLocalRef(jClass); env->DeleteLocalRef(jClass);
} }
void getBitmapFromString(const char *text, int textsize, unsigned char **map, int *height, int *width, int *realWidth) void getBitmapFromString(const char *text, int textsize, unsigned char **map,
int *height, int *width, int *realWidth)
{ {
JNIEnv *env; JNIEnv *env;
if(gJavaVM->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK || !gCallbackObject || (gJavaVM->AttachCurrentThread(&env, NULL)) < 0) return; if(gJavaVM->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK ||
!gCallbackObject || (gJavaVM->AttachCurrentThread(&env, NULL)) < 0) return;
jclass jClass = env->FindClass("org/geuz/onelab/StringTexture"); jclass jClass = env->FindClass("org/geuz/onelab/StringTexture");
if(jClass == 0) if(jClass == 0)
return; return;
jstring jtext = env->NewStringUTF(text); jstring jtext = env->NewStringUTF(text);
jmethodID mid = env->GetStaticMethodID(jClass, "getHeightFromString", "(Ljava/lang/String;I)I"); jmethodID mid = env->GetStaticMethodID(jClass, "getHeightFromString",
"(Ljava/lang/String;I)I");
*height = env->CallIntMethod(gCallbackObject, mid, jtext, textsize); *height = env->CallIntMethod(gCallbackObject, mid, jtext, textsize);
mid = env->GetStaticMethodID(jClass, "getWidthFromString", "(Ljava/lang/String;I)I"); mid = env->GetStaticMethodID(jClass, "getWidthFromString", "(Ljava/lang/String;I)I");
*width =env->CallIntMethod(gCallbackObject, mid, jtext, textsize); *width =env->CallIntMethod(gCallbackObject, mid, jtext, textsize);
...@@ -113,7 +115,8 @@ void getBitmapFromString(const char *text, int textsize, unsigned char **map, in ...@@ -113,7 +115,8 @@ void getBitmapFromString(const char *text, int textsize, unsigned char **map, in
} }
extern "C" { extern "C" {
JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) { JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved)
{
gJavaVM = vm; gJavaVM = vm;
return JNI_VERSION_1_6; return JNI_VERSION_1_6;
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <OpenGLES/ES1/glext.h> #include <OpenGLES/ES1/glext.h>
#include <Gmsh/Gmsh.h> #include <Gmsh/Gmsh.h>
#include <Gmsh/OpenFile.h>
#include <Gmsh/GModel.h> #include <Gmsh/GModel.h>
#include <Gmsh/MElement.h> #include <Gmsh/MElement.h>
#include <Gmsh/VertexArray.h> #include <Gmsh/VertexArray.h>
...@@ -28,6 +29,7 @@ ...@@ -28,6 +29,7 @@
#include <GLES/glext.h> #include <GLES/glext.h>
#include <gmsh/Gmsh.h> #include <gmsh/Gmsh.h>
#include <gmsh/OpenFile.h>
#include <gmsh/GModel.h> #include <gmsh/GModel.h>
#include <gmsh/MElement.h> #include <gmsh/MElement.h>
#include <gmsh/VertexArray.h> #include <gmsh/VertexArray.h>
...@@ -64,10 +66,11 @@ drawContext::drawContext(bool isRetina) ...@@ -64,10 +66,11 @@ drawContext::drawContext(bool isRetina)
_fillMesh = false; _fillMesh = false;
_gradiant = true; _gradiant = true;
_fontFactor = (isRetina)?2:1; _fontFactor = isRetina ? 2 : 1;
} }
static void checkGlError(const char* op) { static void checkGlError(const char* op)
{
for (GLint error = glGetError(); error; error = glGetError()) for (GLint error = glGetError(); error; error = glGetError())
Msg::Error("%s: glError (0x%x)",op,error); Msg::Error("%s: glError (0x%x)",op,error);
} }
...@@ -75,37 +78,41 @@ static void checkGlError(const char* op) { ...@@ -75,37 +78,41 @@ static void checkGlError(const char* op) {
void drawContext::load(std::string filename) void drawContext::load(std::string filename)
{ {
if(locked) return; if(locked) return;
// clear previous GModel, onelab datas and PView
GModel::list.clear(); // delete all models and post-processing views
PView::list.clear(); ClearProject();
// reset onelab database
onelab::server::instance()->clear(); onelab::server::instance()->clear();
// open the file with Gmsh // open the file with Gmsh
GmshOpenProject(filename); OpenProject(filename);
// reset openGL view // reset openGL view
this->eventHandler(10); this->eventHandler(10);
// run getdp without parameter // run onelab clients to populate the database
onelab_cb("check"); onelab_cb("check");
// to allow the first run // mark all parameters as changed to force complete first run
onelab::server::instance()->setChanged(true, "Gmsh"); onelab::server::instance()->setChanged(true, "Gmsh");
onelab::server::instance()->setChanged(true, "GetDP"); onelab::server::instance()->setChanged(true, "GetDP");
} }
void drawContext::eventHandler(int event, float x, float y) void drawContext::eventHandler(int event, float x, float y)
{ {
this->_current.set(this->_scale, this->_translate, this->_right, this->_left, this->_bottom, this->_top, this->_width, this->_height, x, y); this->_current.set(this->_scale, this->_translate, this->_right, this->_left,
this->_bottom, this->_top, this->_width, this->_height, x, y);
double xx[3] = {1.,0.,0.}; double xx[3] = {1.,0.,0.};
double yy[3] = {0.,1.,0.}; double yy[3] = {0.,1.,0.};
double q[4]; double q[4];
switch(event) switch(event){
{
case 0: // finger(s) press the screen case 0: // finger(s) press the screen
// in this case x and y represent the start point // in this case x and y represent the start point
this->_start.set(this->_scale, this->_translate, this->_right, this->_left, this->_bottom, this->_top, this->_width, this->_height, x, y); this->_start.set(this->_scale, this->_translate, this->_right, this->_left,
this->_previous.set(this->_scale, this->_translate, this->_right, this->_left, this->_bottom, this->_top, this->_width, this->_height, x, y); this->_bottom, this->_top, this->_width, this->_height, x, y);
this->_previous.set(this->_scale, this->_translate, this->_right, this->_left,
this->_bottom, this->_top, this->_width, this->_height, x, y);
break; break;
case 1: // finger move (translate) case 1: // finger move (translate)
// in this case x and y represent the current point // in this case x and y represent the current point
...@@ -114,7 +121,8 @@ void drawContext::eventHandler(int event, float x, float y) ...@@ -114,7 +121,8 @@ void drawContext::eventHandler(int event, float x, float y)
_translate[2] = 0.; _translate[2] = 0.;
break; break;
case 2: // fingers move (scale) case 2: // fingers move (scale)
// in this case we don't care about previous and current position, x represent the scale // in this case we don't care about previous and current position, x
// represent the scale
this->_scale[0] = this->_scale[1] = this->_scale[2] = x; this->_scale[0] = this->_scale[1] = this->_scale[2] = x;
this->_start.recenter(this->_scale, this->_translate); this->_start.recenter(this->_scale, this->_translate);
break; break;
...@@ -125,7 +133,7 @@ void drawContext::eventHandler(int event, float x, float y) ...@@ -125,7 +133,7 @@ void drawContext::eventHandler(int event, float x, float y)
(this->_height - 2. * this->_current.win[1]) / this->_height); (this->_height - 2. * this->_current.win[1]) / this->_height);
break; break;
case 4: // release the finger(s) case 4: // release the finger(s)
// Do nothink ? // Do nothing ?
break; break;
case 5: // X view case 5: // X view
axis_to_quat(xx, M_PI/2, q); axis_to_quat(xx, M_PI/2, q);
...@@ -146,7 +154,8 @@ void drawContext::eventHandler(int event, float x, float y) ...@@ -146,7 +154,8 @@ void drawContext::eventHandler(int event, float x, float y)
} }
break; break;
} }
this->_previous.set(this->_scale, this->_translate, this->_right, this->_left, this->_bottom, this->_top, this->_width, this->_height, x, y); this->_previous.set(this->_scale, this->_translate, this->_right, this->_left,
this->_bottom, this->_top, this->_width, this->_height, x, y);
} }
void drawContext::setQuaternion(double q0, double q1, double q2, double q3) void drawContext::setQuaternion(double q0, double q1, double q2, double q3)
...@@ -174,7 +183,8 @@ void drawContext::buildRotationMatrix() ...@@ -174,7 +183,8 @@ void drawContext::buildRotationMatrix()
void drawContext::OrthofFromGModel() void drawContext::OrthofFromGModel()
{ {
SBoundingBox3d bb = GModel::current()->bounds(); SBoundingBox3d bb = GModel::current()->bounds();
double ratio = (double)(this->_width ? this->_width : 1.) / (double)(this->_height ? this->_height : 1.); double ratio = (double)(this->_width ? this->_width : 1.) /
(double)(this->_height ? this->_height : 1.);
double bbRation = (bb.max().x() - bb.min().x()) / (bb.max().y() - bb.min().y()); double bbRation = (bb.max().x() - bb.min().x()) / (bb.max().y() - bb.min().y());
double xmin = -ratio, xmax = ratio, ymin = -1., ymax = 1.; double xmin = -ratio, xmax = ratio, ymin = -1., ymax = 1.;
if(bbRation < 1) { if(bbRation < 1) {
...@@ -195,7 +205,9 @@ void drawContext::OrthofFromGModel() ...@@ -195,7 +205,9 @@ void drawContext::OrthofFromGModel()
ymin -= (ymax - ymin) / 5.; ymin -= (ymax - ymin) / 5.;
// clipping // clipping
double zmax = std::max(std::max(std::max(fabs(bb.min().z()), fabs(bb.max().z())), std::max(fabs(bb.min().x()), fabs(bb.max().x()))), std::max(fabs(bb.min().y()), fabs(bb.max().y()))); double zmax = std::max(std::max(std::max(fabs(bb.min().z()), fabs(bb.max().z())),
std::max(fabs(bb.min().x()), fabs(bb.max().x()))),
std::max(fabs(bb.min().y()), fabs(bb.max().y())));
double clip = zmax * 1.5; double clip = zmax * 1.5;
GLint matrixMode; GLint matrixMode;
...@@ -302,12 +314,16 @@ void drawVector(double x, double y, double z, double dx, double dy, double dz) ...@@ -302,12 +314,16 @@ void drawVector(double x, double y, double z, double dx, double dy, double dz)
GLfloat arrow[] = { GLfloat arrow[] = {
(GLfloat)(x + dx), (GLfloat)(y + dy), (GLfloat)(z + dz), (GLfloat)(x + dx), (GLfloat)(y + dy), (GLfloat)(z + dz),
(GLfloat)(x + f1 * dx + b * (t[0])), (GLfloat)(y + f1 * dy + b * (t[1])), (GLfloat)(z + f1 * dz + b * (t[2])), (GLfloat)(x + f1 * dx + b * (t[0])), (GLfloat)(y + f1 * dy + b * (t[1])),
(GLfloat)(x + f1 * dx + b * (-t[0])), (GLfloat)(y + f1 * dy + b * (-t[1])), (GLfloat)(z + f1 * dz + b * (-t[2])), (GLfloat)(z + f1 * dz + b * (t[2])),
(GLfloat)(x + f1 * dx + b * (-t[0])), (GLfloat)(y + f1 * dy + b * (-t[1])),
(GLfloat)(z + f1 * dz + b * (-t[2])),
(GLfloat)(x + dx), (GLfloat)(y + dy), (GLfloat)(z + dz), (GLfloat)(x + dx), (GLfloat)(y + dy), (GLfloat)(z + dz),
(GLfloat)(x + f1 * dx + b * (-u[0])), (GLfloat)(y + f1 * dy + b * (-u[1])), (GLfloat)(z + f1 * dz + b * (-u[2])), (GLfloat)(x + f1 * dx + b * (-u[0])), (GLfloat)(y + f1 * dy + b * (-u[1])),
(GLfloat)(x + f1 * dx + b * (u[0])), (GLfloat)(y + f1 * dy + b * (u[1])), (GLfloat)(z + f1 * dz + b * (u[2])), (GLfloat)(z + f1 * dz + b * (-u[2])),
(GLfloat)(x + f1 * dx + b * (u[0])), (GLfloat)(y + f1 * dy + b * (u[1])),
(GLfloat)(z + f1 * dz + b * (u[2])),
}; };
glVertexPointer(3, GL_FLOAT, 0, arrow); glVertexPointer(3, GL_FLOAT, 0, arrow);
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
...@@ -315,7 +331,6 @@ void drawVector(double x, double y, double z, double dx, double dy, double dz) ...@@ -315,7 +331,6 @@ void drawVector(double x, double y, double z, double dx, double dy, double dz)
glDrawArrays(GL_TRIANGLES, 0, 6); glDrawArrays(GL_TRIANGLES, 0, 6);
glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);
glDisable(GL_LINE_SMOOTH); glDisable(GL_LINE_SMOOTH);
} }
void drawContext::drawVectorArray(PViewOptions *opt, VertexArray *va) void drawContext::drawVectorArray(PViewOptions *opt, VertexArray *va)
...@@ -327,8 +342,7 @@ void drawContext::drawVectorArray(PViewOptions *opt, VertexArray *va) ...@@ -327,8 +342,7 @@ void drawContext::drawVectorArray(PViewOptions *opt, VertexArray *va)
float *v = va->getVertexArray(3 * (i + 1)); float *v = va->getVertexArray(3 * (i + 1));
double l = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); double l = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
double lmax = opt->tmpMax; double lmax = opt->tmpMax;
if((l && opt->vectorType) && lmax) if((l && opt->vectorType) && lmax){
{
double scale = (opt->arrowSizeMax - opt->arrowSizeMin) / lmax; double scale = (opt->arrowSizeMax - opt->arrowSizeMin) / lmax;
if(opt->arrowSizeMin && l) scale += opt->arrowSizeMin / l; if(opt->arrowSizeMin && l) scale += opt->arrowSizeMin / l;
double dx = scale * v[0]; double dx = scale * v[0];
...@@ -336,8 +350,7 @@ void drawContext::drawVectorArray(PViewOptions *opt, VertexArray *va) ...@@ -336,8 +350,7 @@ void drawContext::drawVectorArray(PViewOptions *opt, VertexArray *va)
double dz = scale * v[2]; double dz = scale * v[2];
GLubyte *color = (GLubyte *)va->getColorArray(4 * i); GLubyte *color = (GLubyte *)va->getColorArray(4 * i);
glColor4ub(*(color), *(color+1), *(color+2), *(color+3)); glColor4ub(*(color), *(color+1), *(color+2), *(color+3));
if(fabs(dx) > 1. || fabs(dy) > 1. || fabs(dz) > 1.) if(fabs(dx) > 1. || fabs(dy) > 1. || fabs(dz) > 1.){
{
double d = (this->_right - this->_left) / this->_width / _scale[0]; double d = (this->_right - this->_left) / this->_width / _scale[0];
dx *= d; dy *= d; dz *= d; dx *= d; dy *= d; dz *= d;
double x = s[0], y = s[1], z = s[2]; double x = s[0], y = s[1], z = s[2];
...@@ -387,13 +400,17 @@ void drawContext::drawScale() ...@@ -387,13 +400,17 @@ void drawContext::drawScale()
std::vector<GLfloat> vertex(opt->nbIso*3*4); std::vector<GLfloat> vertex(opt->nbIso*3*4);
std::vector<GLubyte> color(opt->nbIso*4*4); std::vector<GLubyte> color(opt->nbIso*4*4);
for(int i = 0; i < opt->nbIso; i++){ for(int i = 0; i < opt->nbIso; i++){
if(opt->intervalsType == PViewOptions::Discrete || opt->intervalsType == PViewOptions::Numeric) if(opt->intervalsType == PViewOptions::Discrete ||
{ opt->intervalsType == PViewOptions::Numeric){
unsigned int col = opt->getColor(i, opt->nbIso); unsigned int col = opt->getColor(i, opt->nbIso);
color[i*4*4+0] = color[i*4*4+4] = color[i*4*4+8] = color[i*4*4+12] = (GLubyte)CTX::instance()->unpackRed(col); color[i*4*4+0] = color[i*4*4+4] = color[i*4*4+8] = color[i*4*4+12] =
color[i*4*4+1] = color[i*4*4+5] = color[i*4*4+9] = color[i*4*4+13] = (GLubyte)CTX::instance()->unpackGreen(col); (GLubyte)CTX::instance()->unpackRed(col);
color[i*4*4+2] = color[i*4*4+6] = color[i*4*4+10] = color[i*4*4+14] = (GLubyte)CTX::instance()->unpackBlue(col); color[i*4*4+1] = color[i*4*4+5] = color[i*4*4+9] = color[i*4*4+13] =
color[i*4*4+3] = color[i*4*4+7] = color[i*4*4+11] = color[i*4*4+15] = (GLubyte)CTX::instance()->unpackAlpha(col); (GLubyte)CTX::instance()->unpackGreen(col);
color[i*4*4+2] = color[i*4*4+6] = color[i*4*4+10] = color[i*4*4+14] =
(GLubyte)CTX::instance()->unpackBlue(col);
color[i*4*4+3] = color[i*4*4+7] = color[i*4*4+11] = color[i*4*4+15] =
(GLubyte)CTX::instance()->unpackAlpha(col);
vertex[i*3*4+0] = xmin + i * box; vertex[i*3*4+0] = xmin + i * box;
vertex[i*3*4+1] = ymin; vertex[i*3*4+1] = ymin;
vertex[i*3*4+2] = 0.; vertex[i*3*4+2] = 0.;
...@@ -407,8 +424,7 @@ void drawContext::drawScale() ...@@ -407,8 +424,7 @@ void drawContext::drawScale()
vertex[i*3*4+10] = ymin + dh; vertex[i*3*4+10] = ymin + dh;
vertex[i*3*4+11] = 0.; vertex[i*3*4+11] = 0.;
} }
else if(opt->intervalsType == PViewOptions::Continuous) else if(opt->intervalsType == PViewOptions::Continuous){
{
double dv = (opt->tmpMax - opt->tmpMin) / (opt->nbIso ? opt->nbIso : 1); double dv = (opt->tmpMax - opt->tmpMin) / (opt->nbIso ? opt->nbIso : 1);
double v1 = opt->tmpMin + i * dv; double v1 = opt->tmpMin + i * dv;
unsigned int col1 = opt->getColor(v1, opt->tmpMin, opt->tmpMax, true); unsigned int col1 = opt->getColor(v1, opt->tmpMin, opt->tmpMax, true);
...@@ -435,13 +451,16 @@ void drawContext::drawScale() ...@@ -435,13 +451,16 @@ void drawContext::drawScale()
vertex[i*3*4+10] = ymin + dh; vertex[i*3*4+10] = ymin + dh;
vertex[i*3*4+11] = 0.; vertex[i*3*4+11] = 0.;
} }
else else{
{
unsigned int col = opt->getColor(i, opt->nbIso); unsigned int col = opt->getColor(i, opt->nbIso);
color[i*4*4+0] = color[i*4*4+4] = color[i*4*4+8] = color[i*4*4+12] = (GLubyte)CTX::instance()->unpackRed(col); color[i*4*4+0] = color[i*4*4+4] = color[i*4*4+8] = color[i*4*4+12] =
color[i*4*4+1] = color[i*4*4+5] = color[i*4*4+9] = color[i*4*4+13] = (GLubyte)CTX::instance()->unpackGreen(col); (GLubyte)CTX::instance()->unpackRed(col);
color[i*4*4+2] = color[i*4*4+6] = color[i*4*4+10] = color[i*4*4+14] = (GLubyte)CTX::instance()->unpackBlue(col); color[i*4*4+1] = color[i*4*4+5] = color[i*4*4+9] = color[i*4*4+13] =
color[i*4*4+3] = color[i*4*4+7] = color[i*4*4+11] = color[i*4*4+15] = (GLubyte)CTX::instance()->unpackAlpha(col); (GLubyte)CTX::instance()->unpackGreen(col);
color[i*4*4+2] = color[i*4*4+6] = color[i*4*4+10] = color[i*4*4+14] =
(GLubyte)CTX::instance()->unpackBlue(col);
color[i*4*4+3] = color[i*4*4+7] = color[i*4*4+11] = color[i*4*4+15] =
(GLubyte)CTX::instance()->unpackAlpha(col);
vertex[i*3*4+0] = xmin + i * box; vertex[i*3*4+0] = xmin + i * box;
vertex[i*3*4+1] = ymin; vertex[i*3*4+1] = ymin;
vertex[i*3*4+2] = 0.; vertex[i*3*4+2] = 0.;
...@@ -461,7 +480,9 @@ void drawContext::drawScale() ...@@ -461,7 +480,9 @@ void drawContext::drawScale()
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, &color[0]); glColorPointer(4, GL_UNSIGNED_BYTE, 0, &color[0]);
glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_COLOR_ARRAY);
if(opt->intervalsType == PViewOptions::Discrete || opt->intervalsType == PViewOptions::Numeric || opt->intervalsType == PViewOptions::Continuous) if(opt->intervalsType == PViewOptions::Discrete ||
opt->intervalsType == PViewOptions::Numeric ||
opt->intervalsType == PViewOptions::Continuous)
glDrawArrays(GL_TRIANGLE_STRIP, 0, opt->nbIso*4); glDrawArrays(GL_TRIANGLE_STRIP, 0, opt->nbIso*4);
else else
glDrawArrays(GL_LINES, 0, opt->nbIso*4); glDrawArrays(GL_LINES, 0, opt->nbIso*4);
...@@ -483,14 +504,16 @@ void drawContext::drawScale() ...@@ -483,14 +504,16 @@ void drawContext::drawScale()
sprintf(label, "%s", data->getName().c_str()); sprintf(label, "%s", data->getName().c_str());
} }
drawString lbl(label, 20*_fontFactor); drawString lbl(label, 20*_fontFactor);
lbl.draw(xmin+width/2, ymin+ 2.5*dh, 0., _width/(_right-_left), _height/(_top-_bottom)); lbl.draw(xmin+width/2, ymin+ 2.5*dh, 0.,
_width/(_right-_left), _height/(_top-_bottom));
drawString val(data->getName().c_str(), 14*_fontFactor); drawString val(data->getName().c_str(), 14*_fontFactor);
for(int i = 0; i < 3; i++) { for(int i = 0; i < 3; i++) {
double v = opt->getScaleValue(i, 3, opt->tmpMin, opt->tmpMax); double v = opt->getScaleValue(i, 3, opt->tmpMin, opt->tmpMax);
sprintf(label, opt->format.c_str(), v); sprintf(label, opt->format.c_str(), v);
val.setText(label); val.setText(label);
val.draw(xmin+i*width/2, ymin+ 1.1*dh, 0., _width/(_right-_left), _height/(_top-_bottom)); val.draw(xmin+i*width/2, ymin+ 1.1*dh, 0.,
_width/(_right-_left), _height/(_top-_bottom));
} }
nPview++; nPview++;
} }
...@@ -557,8 +580,7 @@ void drawContext::drawView() ...@@ -557,8 +580,7 @@ void drawContext::drawView()
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
// fill the background // fill the background
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if(_gradiant) if(_gradiant){
{
glPushMatrix(); glPushMatrix();
glLoadIdentity(); glLoadIdentity();
const GLfloat squareVertices[] = { const GLfloat squareVertices[] = {
...@@ -590,7 +612,6 @@ void drawContext::drawView() ...@@ -590,7 +612,6 @@ void drawContext::drawView()
this->buildRotationMatrix(); this->buildRotationMatrix();
glMultMatrixf(_rotatef); glMultMatrixf(_rotatef);
checkGlError("Initialize position"); checkGlError("Initialize position");
// //
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
this->drawMesh(); this->drawMesh();
...@@ -612,8 +633,7 @@ std::vector<std::string> commandToVector(const std::string cmd) ...@@ -612,8 +633,7 @@ std::vector<std::string> commandToVector(const std::string cmd)
{ {
std::vector<std::string> ret; std::vector<std::string> ret;
int pos=0, last=0; int pos=0, last=0;
while((pos = cmd.find("-", last+1)) != std::string::npos) while((pos = cmd.find("-", last+1)) != std::string::npos){
{
ret.push_back(cmd.substr(last,pos-1-last)); ret.push_back(cmd.substr(last,pos-1-last));
last = pos; last = pos;
} }
...@@ -669,21 +689,25 @@ int onelab_cb(std::string action) ...@@ -669,21 +689,25 @@ int onelab_cb(std::string action)
o.setNeverChanged(true); o.setNeverChanged(true);
onelab::server::instance()->set(o); onelab::server::instance()->set(o);
if(action == "compute" && (onelab::server::instance()->getChanged("Gmsh") || onelab::server::instance()->getChanged("GetDP"))){ if(action == "compute" && (onelab::server::instance()->getChanged("Gmsh") ||
onelab::server::instance()->getChanged("GetDP"))){
std::string filename = GModel::current()->getFileName(); std::string filename = GModel::current()->getFileName();
std::vector<std::string> args; std::vector<std::string> args;
args.push_back("getdp"); args.push_back("getdp");
std::vector<onelab::string> onelabArgs; std::vector<onelab::string> onelabArgs;
onelab::server::instance()->get(onelabArgs, "GetDP/1ModelName"); onelab::server::instance()->get(onelabArgs, "GetDP/1ModelName");
args.push_back((onelabArgs.empty())? SplitFileName(filename)[0] + SplitFileName(filename)[1] : onelabArgs[0].getValue()); args.push_back((onelabArgs.empty())? SplitFileName(filename)[0] +
SplitFileName(filename)[1] : onelabArgs[0].getValue());
onelab::server::instance()->get(onelabArgs, "GetDP/9ComputeCommand"); onelab::server::instance()->get(onelabArgs, "GetDP/9ComputeCommand");
std::vector<std::string> compute = commandToVector((onelabArgs.empty())? "" : onelabArgs[0].getValue().c_str()); std::vector<std::string> compute = commandToVector((onelabArgs.empty())? "" :
onelabArgs[0].getValue().c_str());
args.insert( args.end(), compute.begin(), compute.end() ); args.insert( args.end(), compute.begin(), compute.end() );
args.push_back("-onelab"); args.push_back("-onelab");
args.push_back("GetDP"); args.push_back("GetDP");
GetDP(args, onelab::server::instance()); GetDP(args, onelab::server::instance());
} }
if(action == "check" && (onelab::server::instance()->getChanged("Gmsh") || onelab::server::instance()->getChanged("GetDP"))){ if(action == "check" && (onelab::server::instance()->getChanged("Gmsh") ||
onelab::server::instance()->getChanged("GetDP"))){
std::string filename = GModel::current()->getFileName(); std::string filename = GModel::current()->getFileName();
std::vector<std::string> args; std::vector<std::string> args;
args.push_back("getdp"); args.push_back("getdp");
...@@ -695,14 +719,16 @@ int onelab_cb(std::string action) ...@@ -695,14 +719,16 @@ int onelab_cb(std::string action)
args.push_back("GetDP"); args.push_back("GetDP");
GetDP(args, onelab::server::instance()); GetDP(args, onelab::server::instance());
} }
} while(action == "compute" && !onelabStop && (onelabUtils::incrementLoop("3") || onelabUtils::incrementLoop("2") || onelabUtils::incrementLoop("1"))); } while(action == "compute" && !onelabStop && (onelabUtils::incrementLoop("3") ||
onelabUtils::incrementLoop("2") ||
onelabUtils::incrementLoop("1")));
locked = false; locked = false;
return redraw; return redraw;
} }
int number_of_animation() { int number_of_animation()
{
int ret = 0; int ret = 0;
for(unsigned int i = 0; i < PView::list.size(); i++){ for(unsigned int i = 0; i < PView::list.size(); i++){
PView * p = PView::list[i]; PView * p = PView::list[i];
...@@ -714,7 +740,8 @@ int number_of_animation() { ...@@ -714,7 +740,8 @@ int number_of_animation() {
return ret; return ret;
} }
void set_animation(int step) { void set_animation(int step)
{
for(unsigned int i = 0; i < PView::list.size(); i++){ for(unsigned int i = 0; i < PView::list.size(); i++){
PView * p = PView::list[i]; PView * p = PView::list[i];
if(p->getOptions()->visible){ if(p->getOptions()->visible){
...@@ -724,7 +751,8 @@ void set_animation(int step) { ...@@ -724,7 +751,8 @@ void set_animation(int step) {
} }
} }
int animation_next() { int animation_next()
{
int ret = 0; int ret = 0;
for(unsigned int i = 0; i < PView::list.size(); i++){ for(unsigned int i = 0; i < PView::list.size(); i++){
PView * p = PView::list[i]; PView * p = PView::list[i];
...@@ -740,7 +768,9 @@ int animation_next() { ...@@ -740,7 +768,9 @@ int animation_next() {
} }
return ret; return ret;
} }
int animation_prev() {
int animation_prev()
{
int ret = 0; int ret = 0;
for(unsigned int i = 0; i < PView::list.size(); i++){ for(unsigned int i = 0; i < PView::list.size(); i++){
PView * p = PView::list[i]; PView * p = PView::list[i];
......
...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
#include "movePosition.h" #include "movePosition.h"
void drawArray(VertexArray *va, int type, bool useColorArray=false, bool useNormalArray=false); void drawArray(VertexArray *va, int type, bool useColorArray=false,
bool useNormalArray=false);
int onelab_cb(std::string); int onelab_cb(std::string);
int animation_next(); int animation_next();
int animation_prev(); int animation_prev();
...@@ -42,7 +43,6 @@ private: ...@@ -42,7 +43,6 @@ private:
void OrthofFromGModel(void); void OrthofFromGModel(void);
void drawPView(PView *p); void drawPView(PView *p);
void drawVectorArray(PViewOptions *opt, VertexArray *va); void drawVectorArray(PViewOptions *opt, VertexArray *va);
public: public:
drawContext(bool isRetina=false); drawContext(bool isRetina=false);
~drawContext(){} ~drawContext(){}
......
...@@ -41,6 +41,7 @@ void drawGeomVertex(GVertex *v) ...@@ -41,6 +41,7 @@ void drawGeomVertex(GVertex *v)
glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);
glPointSize(1); glPointSize(1);
} }
void drawGeomEdge(GEdge *e) void drawGeomEdge(GEdge *e)
{ {
if(!e->getVisibility()) return; if(!e->getVisibility()) return;
...@@ -74,10 +75,12 @@ void drawGeomEdge(GEdge *e) ...@@ -74,10 +75,12 @@ void drawGeomEdge(GEdge *e)
glDisable(GL_LINE_SMOOTH); glDisable(GL_LINE_SMOOTH);
glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);
} }
void drawGeomFace(GFace *f) void drawGeomFace(GFace *f)
{ {
// TODO // TODO
} }
void drawContext::drawGeom() void drawContext::drawGeom()
{ {
for(unsigned int i=0; i<GModel::list.size(); i++) { for(unsigned int i=0; i<GModel::list.size(); i++) {
...@@ -85,12 +88,11 @@ void drawContext::drawGeom() ...@@ -85,12 +88,11 @@ void drawContext::drawGeom()
if(!m->getVisibility()) continue; if(!m->getVisibility()) continue;
if(CTX::instance()->geom.points || CTX::instance()->geom.pointsNum) if(CTX::instance()->geom.points || CTX::instance()->geom.pointsNum)
std::for_each(m->firstVertex(), m->lastVertex(), drawGeomVertex); std::for_each(m->firstVertex(), m->lastVertex(), drawGeomVertex);
if(CTX::instance()->geom.lines || CTX::instance()->geom.linesNum || CTX::instance()->geom.tangents) if(CTX::instance()->geom.lines || CTX::instance()->geom.linesNum ||
CTX::instance()->geom.tangents)
std::for_each(m->firstEdge(), m->lastEdge(), drawGeomEdge); std::for_each(m->firstEdge(), m->lastEdge(), drawGeomEdge);
if(CTX::instance()->geom.surfaces || CTX::instance()->geom.surfacesNum || CTX::instance()->geom.normals) if(CTX::instance()->geom.surfaces || CTX::instance()->geom.surfacesNum ||
CTX::instance()->geom.normals)
std::for_each(m->firstFace(), m->lastFace(), drawGeomFace); std::for_each(m->firstFace(), m->lastFace(), drawGeomFace);
} }
} }
...@@ -42,7 +42,8 @@ void drawMeshVertex(GVertex *e) ...@@ -42,7 +42,8 @@ void drawMeshVertex(GVertex *e)
MVertex *v = e->mesh_vertices[i]; MVertex *v = e->mesh_vertices[i];
if(!v->getVisibility()) continue; if(!v->getVisibility()) continue;
unsigned int col; unsigned int col;
if(CTX::instance()->mesh.colorCarousel == 0 || CTX::instance()->mesh.volumesFaces || CTX::instance()->mesh.surfacesFaces) { if(CTX::instance()->mesh.colorCarousel == 0 ||
CTX::instance()->mesh.volumesFaces || CTX::instance()->mesh.surfacesFaces) {
if(v->getPolynomialOrder() > 1) if(v->getPolynomialOrder() > 1)
col = CTX::instance()->color.mesh.vertexSup; col = CTX::instance()->color.mesh.vertexSup;
else else
...@@ -66,6 +67,7 @@ void drawMeshVertex(GVertex *e) ...@@ -66,6 +67,7 @@ void drawMeshVertex(GVertex *e)
glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_COLOR_ARRAY);
} }
void drawMeshEdge(GEdge *e) void drawMeshEdge(GEdge *e)
{ {
if(!e->getVisibility()) { if(!e->getVisibility()) {
...@@ -78,6 +80,7 @@ void drawMeshEdge(GEdge *e) ...@@ -78,6 +80,7 @@ void drawMeshEdge(GEdge *e)
glLineWidth(CTX::instance()->mesh.lineWidth); glLineWidth(CTX::instance()->mesh.lineWidth);
drawArray(e->va_lines, GL_LINES, true); drawArray(e->va_lines, GL_LINES, true);
} }
void drawMeshFace(GFace *f) void drawMeshFace(GFace *f)
{ {
if(!f->getVisibility()) { if(!f->getVisibility()) {
...@@ -119,5 +122,3 @@ void drawContext::drawMesh() ...@@ -119,5 +122,3 @@ void drawContext::drawMesh()
} }
CTX::instance()->mesh.changed = 0; CTX::instance()->mesh.changed = 0;
} }
...@@ -27,7 +27,8 @@ drawString::drawString(std::string text, int size, float color[4]) ...@@ -27,7 +27,8 @@ drawString::drawString(std::string text, int size, float color[4])
void drawString::setText(std::string text) void drawString::setText(std::string text)
{ {
this->_text = text; this->_text = text;
getBitmapFromString(this->_text.c_str(), _size, &this->_map, &this->_height, &this->_width, &this->_realWidth); getBitmapFromString(this->_text.c_str(), _size, &this->_map,
&this->_height, &this->_width, &this->_realWidth);
} }
void drawString::setColor(float color[4]) void drawString::setColor(float color[4])
...@@ -45,12 +46,14 @@ void drawString::setColor(float r, float g, float b, float a) ...@@ -45,12 +46,14 @@ void drawString::setColor(float r, float g, float b, float a)
_color[2] = b; _color[2] = b;
_color[3] = a; _color[3] = a;
} }
void drawString::draw(float x, float y, float z, float w, float h, bool center) void drawString::draw(float x, float y, float z, float w, float h, bool center)
{ {
GLuint textureId; GLuint textureId;
glGenTextures(1, &textureId); glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId); glBindTexture(GL_TEXTURE_2D, textureId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, _width, _height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, _map); glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, _width, _height, 0,
GL_ALPHA, GL_UNSIGNED_BYTE, _map);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glColor4f(_color[0], _color[1], _color[2], _color[3]); glColor4f(_color[0], _color[1], _color[2], _color[3]);
if(center) if(center)
......
//
// iosGModel.cpp
// Onelab
//
// Created by Maxime Graulich on 05/08/13.
// Copyright (c) 2013 Maxime Graulich. All rights reserved.
//
#include "iosGModel.h" #include "iosGModel.h"
static void * objc; static void * objc;
void getBitmapFromString(const char *text, int textsize, unsigned char **map, int *height, int *width, int *realWidth) void getBitmapFromString(const char *text, int textsize, unsigned char **map,
int *height, int *width, int *realWidth)
{ {
getBitmap(objc, text, textsize, map, height, width, realWidth); getBitmap(objc, text, textsize, map, height, width, realWidth);
} }
......
//
// iosGModel.h
// Onelab
//
// Created by Maxime Graulich on 07/05/13.
// Copyright (c) 2013 Maxime Graulich. All rights reserved.
//
#ifndef __Onelab__iosGModel__ #ifndef __Onelab__iosGModel__
#define __Onelab__iosGModel__ #define __Onelab__iosGModel__
...@@ -15,8 +7,10 @@ ...@@ -15,8 +7,10 @@
#include <Gmsh/GmshMessage.h> #include <Gmsh/GmshMessage.h>
void messageFromCpp (void *self, std::string level, std::string msg); void messageFromCpp (void *self, std::string level, std::string msg);
void getBitmap(void *self, const char *text, int textsize, unsigned char **map, int *height, int *width, int *realWidth=NULL); void getBitmap(void *self, const char *text, int textsize, unsigned char **map,
void getBitmapFromString(const char *text, int textsize, unsigned char **map, int *height, int *width, int *realWidth=NULL); int *height, int *width, int *realWidth=NULL);
void getBitmapFromString(const char *text, int textsize, unsigned char **map,
int *height, int *width, int *realWidth=NULL);
void setObjCBridge(void *objcObject); void setObjCBridge(void *objcObject);
class MobileMessage : GmshMessage class MobileMessage : GmshMessage
...@@ -32,4 +26,4 @@ public: ...@@ -32,4 +26,4 @@ public:
} }
}; };
#endif /* defined(__Onelab__iosGModel__) */ #endif
#ifndef _MOVE_POSITION_H_
#define _MOVE_POSITION_H_
class movePosition { class movePosition {
public: public:
float win[3]; // window coordinates float win[3]; // window coordinates
...@@ -18,7 +21,8 @@ class movePosition { ...@@ -18,7 +21,8 @@ class movePosition {
t[i] = instance.t[i]; t[i] = instance.t[i];
} }
} }
void set(float scale[3], float translate[3], float vxmax, float vxmin, float vymin, float vymax, int width, int height, int x, int y) void set(float scale[3], float translate[3], float vxmax, float vxmin,
float vymin, float vymax, int width, int height, int x, int y)
{ {
for(int i = 0; i < 3; i++){ for(int i = 0; i < 3; i++){
s[i] = scale[i]; s[i] = scale[i];
...@@ -43,3 +47,4 @@ class movePosition { ...@@ -43,3 +47,4 @@ class movePosition {
} }
}; };
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment