menus.c
来自「FreeFem++可以生成高质量的有限元网格。可以用于流体力学」· C语言 代码 · 共 1,182 行 · 第 1/3 页
C
1,182 行
#include "medit.h"#include "extern.h"#include "sproto.h"GLfloat altcoef=0.0;static int nbimg;extern int refitem,refmat,reftype,imstep,imreverse;extern int *pilmat,ipilmat;#define MAX_LST 128/* rebuild display lists */void doLists(pScene sc,pMesh mesh) { int k; /*default */ if ( ddebug ) printf("build display lists\n"); if ( !morphing ) glutSetCursor(GLUT_CURSOR_WAIT); for (k=0; k<MAX_LIST; k++) { if ( sc->dlist[k] ) glDeleteLists(sc->dlist[k],1); if ( sc->clist[k] ) glDeleteLists(sc->clist[k],1); sc->dlist[k] = sc->clist[k] = (GLuint)0; } /* poly lists */ sc->dlist[LTria] = listTria(sc,mesh); sc->dlist[LQuad] = listQuad(sc,mesh); if ( !mesh->nt && !mesh->nq ) { sc->dlist[LTets] = listTetra(sc,mesh,0); sc->dlist[LHexa] = listHexa(sc,mesh,0); } if ( sc->clip->active & C_VOL ) sc->clip->active |= C_REDO; glutSetCursor(GLUT_CURSOR_INHERIT); checkErrors();}/* build metric list */void doMapLists(pScene sc,pMesh mesh,int reset) { int k; /*default */ if ( !mesh->sol ) return; if ( ddebug ) printf("build map lists\n"); glutSetCursor(GLUT_CURSOR_WAIT); /* delete old lists */ if ( reset ) { for (k=0; k<MAX_LIST; k++) { if ( sc->mlist[k] ) glDeleteLists(sc->mlist[k],1); sc->mlist[k] = (GLuint)0; } } /* create map list */ if ( sc->mode & S_ALTITUDE ) { sc->mlist[LTria] = alt2dList(sc,mesh,LTria,sc->shrink,altcoef); sc->mlist[LQuad] = alt2dList(sc,mesh,LQuad,sc->shrink,altcoef); } else if ( sc->mode & S_MAP ) { if ( mesh->nt && !sc->mlist[LTria] ) sc->mlist[LTria] = listTriaMap(sc,mesh); if ( mesh->nq && !sc->mlist[LQuad] ) sc->mlist[LQuad] = listQuadMap(sc,mesh); if ( !mesh->nt && mesh->ntet && !sc->mlist[LTets] ) sc->mlist[LTets] = listTetraMap(sc,mesh,0); if ( !mesh->nq && mesh->nhex && !sc->mlist[LHexa] ) sc->mlist[LHexa] = listHexaMap(sc,mesh,0); } glutSetCursor(GLUT_CURSOR_INHERIT); checkErrors();}/* rebuild iso-values lists */void doIsoLists(pScene sc,pMesh mesh,int reset) { pPoint ppt; int k,kk,ret; /*default */ if ( ddebug ) printf("build iso lists\n"); glutSetCursor(GLUT_CURSOR_WAIT); /* delete old lists */ if ( reset ) { for (k=0; k<MAX_LIST; k++) { if ( sc->ilist[k] ) glDeleteLists(sc->ilist[k],1); if ( sc->vlist[k] ) glDeleteLists(sc->vlist[k],1); if ( sc->cplist ) glDeleteLists(sc->cplist,1); sc->ilist[k] = sc->vlist[k] = (GLuint)0; sc->cplist = (GLuint)0; } if ( sc->stream && sc->stream->nbstl ) { for (kk=0; kk<sc->stream->nbstl; kk++) { if ( sc->slist[kk] ) glDeleteLists(sc->slist[kk],1); sc->slist[kk] = (GLuint)0; } sc->slist = (GLuint)0; if ( reset < 2 ) sc->stream->nbstl = 0; for (k=1; k<=mesh->np; k++) { ppt = &mesh->point[k]; ppt->flag = 0; } } } /* iso-lines */ if ( sc->isotyp & S_ISOLINE ) { if ( mesh->nt && !sc->ilist[LTria] ) sc->ilist[LTria] = listTriaIso(sc,mesh); if ( mesh->nq && !sc->ilist[LQuad] ) sc->ilist[LQuad] = listQuadIso(sc,mesh); } /* iso-surfaces */ if ( sc->isotyp & S_ISOSURF ) { if ( mesh->ntet && !sc->ilist[LTets] ) sc->ilist[LTets] = listTetraIso(sc,mesh); } /* vector */ if ( sc->isotyp & S_VECTOR ) { if ( mesh->dim == 2 ) { if ( mesh->nt && !sc->vlist[LTria] ) sc->vlist[LTria] = listTria2dVector(mesh); if ( mesh->nq && !sc->vlist[LQuad] ) sc->vlist[LQuad] = listQuad2dVector(mesh); } else { if ( mesh->ntet+mesh->nhex == 0 ) { sc->vlist[LTria] = listTria3dVector(mesh); } else { if ( mesh->ntet && !sc->vlist[LTets] ) sc->vlist[LTets] = listClipTetraVector(mesh); else if ( mesh->nhex && !sc->vlist[LHexa] ) sc->vlist[LHexa] = listClipHexaVector(mesh); } } } /* streamlines */ if ( sc->isotyp & S_STREAML ) { if ( !mesh->adja || !sc->slist ) { sc->stream = createStream(sc,mesh); if ( !sc->stream ) sc->isotyp &= ~S_STREAML; } if ( sc->stream ) { if ( reftype == LPoint ) ret = streamRefPoint(sc,mesh); else if ( mesh->dim == 3 ) { if ( reftype == LTria ) ret = streamRefTria(sc,mesh); else if ( reftype == LQuad ) ret = streamRefQuad(sc,mesh); if ( sc->picklist ) glDeleteLists(sc->picklist,1); sc->picklist = 0; } } } /* critical points */ if ( sc->isotyp & S_CRITP ) { if ( mesh->dim == 2 ) if ( mesh->nt && !sc->cplist ) sc->cplist = listCritPoint(sc,mesh); } glutSetCursor(GLUT_CURSOR_INHERIT); checkErrors();}void resetLists(pScene sc,pMesh mesh) { int kk; for (kk=0; kk<MAX_LIST; kk++) { if ( sc->dlist[kk] ) glDeleteLists(sc->dlist[kk],1); if ( sc->mlist[kk] ) glDeleteLists(sc->mlist[kk],1); if ( sc->ilist[kk] ) glDeleteLists(sc->ilist[kk],1); if ( sc->clist[kk] ) glDeleteLists(sc->clist[kk],1); if ( sc->cmlist[kk] ) glDeleteLists(sc->cmlist[kk],1); if ( sc->vlist[kk] ) glDeleteLists(sc->vlist[kk],1); if ( sc->cplist ) glDeleteLists(sc->cplist,1); sc->dlist[kk] = sc->clist[kk] = sc->mlist[kk] = (GLuint)0; sc->ilist[kk] = sc->vlist[kk] = sc->cplist = (GLuint)0; } if ( sc->glist ) glDeleteLists(sc->glist,1); if ( sc->nlist ) glDeleteLists(sc->nlist,1); sc->glist = sc->nlist = (GLuint)0;}void keyFile(unsigned char key,int x,int y) { pScene sc; pMesh mesh; pTransform view; char *ptr,data[128]; ubyte post = FALSE,clipon; static int nfree = 0; /* default */ sc = cv.scene[currentScene()]; mesh = cv.mesh[sc->idmesh]; view = sc->view; switch(key) { case 'L': /* load prefs */ if ( parsop(sc,mesh) ) { refitem = reftype = 0; setupPalette(sc,mesh); initGrafix(sc,mesh); doLists(sc,mesh); if ( sc->mode & S_MAP ) doMapLists(sc,mesh,1); if ( sc->isotyp ) doIsoLists(sc,mesh,1); glClearColor(sc->par.back[0],sc->par.back[1],sc->par.back[2],sc->par.back[3]); post = GL_TRUE; } break; case 'W': /* save prefs */ saveMeditFile(mesh->name,sc); break; case 'R': /* reload mesh */ refitem = reftype = 0; if ( !meshUpdate(sc,mesh) ) exit(1); meshRef(sc,mesh); matSort(sc); setupPalette(sc,mesh); doLists(sc,mesh); if ( sc->mode & S_MAP ) doMapLists(sc,mesh,1); if ( sc->isotyp ) doIsoLists(sc,mesh,1); glClearColor(sc->par.back[0],sc->par.back[1],sc->par.back[2],sc->par.back[3]); post = GL_TRUE; break; case 'S': /* save mesh */ strcpy(data,mesh->name); ptr = (char*)strstr(data,".mesh"); if ( ptr ) *ptr = '\0'; sprintf(data,"%s.d.mesh",data); clipon = sc->clip->active & C_ON; if ( clipon ) clipVertices(mesh,sc,sc->clip); saveMesh(sc,mesh,data,clipon); break; case 'B': case 'C': case 'G': case 'H': /* hardcopy */ case 'T': strcpy(data,mesh->name); ptr = (char*)strstr(data,".mesh"); if ( ptr ) *ptr = '\0'; ptr = (char*)strstr(data,".gis"); if ( ptr ) *ptr = '\0'; if ( option != SEQUENCE ) { if ( key == 'H' ) nfree = filnum(data,nfree,"ppm"); else nfree = filnum(data,nfree,"ps"); if ( nfree == -1 ) break; sprintf(data,"%s.%.3d",data,nfree); } else sprintf(data,"%s.ppm",data); if (!saveimg ) glutSetCursor(GLUT_CURSOR_WAIT); if ( key == 'B' || key == 'C' || key == 'G' ) imgTiling(sc,data,key); else imgHard(sc,data,key); if ( animate && !(sc->persp->pmode & CAMERA) && ++nbimg > 179 ) { view->angle = 0.0; nbimg = 0; keyAnim('A',0,0); } if (!saveimg ) glutSetCursor(GLUT_CURSOR_INHERIT); break; case 's': /* softcopy */ sftcpy(sc,mesh); post = FALSE; break; } if ( post ) glutPostRedisplay();}void menuFile(int item) { keyFile((unsigned char)item,0,0);}void keyItem(unsigned char key,int x,int y) { pScene sc; pMesh mesh; pCube cube; ubyte post = TRUE; /* default */ sc = cv.scene[currentScene()]; mesh = cv.mesh[sc->idmesh]; cube = sc->cube; switch(key) { case 'A': /* draw axis */ sc->item ^= S_AXIS; break; case 'B': /* draw bounding box */ sc->item ^= S_BOX; break; case 'D': /*draw selection cube */ if ( cube->active & C_ON ) { cube->active &= ~(C_ON+C_EDIT); dumpCube(sc,mesh,cube); } else { cube->active |= C_ON; } break; case 'G': /* draw grid */ sc->item ^= S_GRID; break; case 'j': /* toggle info */ sc->type ^= S_DECO; break; case 'P': /* toggle point nums */ sc->item ^= S_NUMP; break; case 'F': /* toggle face nums */ sc->item ^= S_NUMF; break; case 'g': /* const. items */ if ( !sc->glist ) post = FALSE; sc->item ^= S_GEOM; break; case 'N': if ( mesh->nvn ) sc->type ^= S_NORMAL; else post = FALSE; break; case 'O': if ( mesh->nvn ) { sc->type ^= S_OPPOS; if ( sc->nlist ) { glDeleteLists(sc->nlist,1); sc->nlist = 0; } else post = FALSE; } else post = FALSE; break; } if ( post ) glutPostRedisplay();}void menuItem(int item) { keyItem((unsigned char)item,0,0);}void keyAnim(unsigned char key,int x,int y) { pScene sc; pMesh mesh; pClip clip; ubyte post = TRUE; char *ptr,base[256]; static int depart = -1; /* default */ sc = cv.scene[currentScene()]; mesh = cv.mesh[sc->idmesh]; clip = sc->clip; if ( depart == -1 ) depart = animdep; switch(key) { case 'A': /* switch animation */ if ( animate ) { sc->view->manim = GL_FALSE; clip->cliptr->manim = GL_FALSE; sc->view->angle = 0.0f; glutIdleFunc(NULL); } else { sc->view->manim = GL_TRUE; clip->cliptr->manim = GL_TRUE; if ( sc->persp->pmode == CAMERA )
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?