/* --------------------------------------------------------------------  */
/*                          CALCULIX                                     */
/*                   - GRAPHICAL INTERFACE -                             */
/*                                                                       */
/*     A 3-dimensional pre- and post-processor for finite elements       */
/*              Copyright (C) 1996 Klaus Wittig                          */
/*                                                                       */
/*     This program is free software; you can redistribute it and/or     */
/*     modify it under the terms of the GNU General Public License as    */
/*     published by the Free Software Foundation; either version 2 of    */
/*     the License, or (at your option) any later version.               */
/*                                                                       */
/*     This program is distributed in the hope that it will be useful,   */
/*     but WITHOUT ANY WARRANTY; without even the implied warranty of    */ 
/*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the      */
/*     GNU General Public License for more details.                      */
/*                                                                       */
/*     You should have received a copy of the GNU General Public License */
/*     along with this program; if not, write to the Free Software       */
/*     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.         */
/* --------------------------------------------------------------------  */

/* ALL function prototypes for the program "CalculiX GraphiX (cgx)" */

#include "extUtil.h"
#include "trackball.h"

/* 
choose "RGB_MODE 0" for best results if you are working on a sgi workstation or
if you are working on a linux system with 8-Bit color depth. In this case 
rendering is done in the index-mode. Otherwise stay with "RGB_MODE 1"
*/
#ifdef SGI_MIPS
  #define     INX_MODE    1
  #define     TEX_MODE    0
#else
  #define     INX_MODE    0
  #define     TEX_MODE    1
#endif

/* number of possible colors in texture mode */
#define     TEX_PIXELS  512

/* gamma lightens or darkens an image (Hcpy) */
#define     GAMMA       1.9     

/* factor for the geometric tolerance for merging and radial moving */
/* the line-space will be multiplied with this value to calculate the default */
/* geometric tolerance */
#define     GTOL        1.e-5    

/* amplification factor for the automatic merging of edge-points if a cad-file is read */
#define     GTOL_EDGES  2.e1


/* defaults for calcLineDiv() */
/* defines the minimum angle between sectors of a line in calcLineDiv() */
#define GTOL_COS_A 0.998      

/* defines the default maximum distance between nodes during automatic line division calculation */
/* GTOL_NODE_DIST * gtol = target distance between nodes (not exactly achieved) */
/* A line running from one end to the other end of the model would have a division of  GTOL*GTOL_NODE_DIST */ 
#define GTOL_NODE_DIST 1.e3

/* defines the default minimum element length/maximum element length */
#define     ELEM_LENGTH_RATIO 0.1

/* default line division for meshing */
#define     DEF_LINE_DIV 4      

/* meshing parameters for the unstructured tr3 mesher (mesh2d) */
#define     ALPHA    0.8
#define     BETA     0.8
#define     NADAPT   8

/* default length of one period of animation */
#define     MILLISECONDS_PER_PERIOD 1200 

/* default location of the help files, please insert the actual one */
#ifdef MTU
  #ifdef DEVEL
    #define     HELPFILE        {"/yaprod/yae55/IRIX/bin/cgx_doc/cgx.html",\
                             "/yaprod/yae55/IRIX/bin/ccx_doc/ccx.html"}
  #else
    #define     HELPFILE        {"/yaprod/cae/application/CalculiX/doc/cgx/cgx.html",\
                             "/yaprod/cae/application/CalculiX/doc/ccx/ccx.html"}
  #endif
#else
  #define     HELPFILE        {"/usr/local/CalculiX/cgx_1.5/doc/cgx/cgx.html",\
    "/usr/local/CalculiX/ccx_1.5/doc/ccx/ccx.html"}
#endif

/* html browser, change if necessary */
/* postscript viewer, change if necessary */
#ifdef MTU
  #define     BROWSER         {"firefox"}
  #define     PSVIEWER         {"gv"}
#else
/* #define     BROWSER         {"netscape"} */
  #define     BROWSER         {"mozilla"}
/* #define     PSVIEWER         {"ghostview"} */
  #define     PSVIEWER         {"gv"}
#endif

/* more parameters, better do not change them! */
#define     MINVALUE    -1.e9
#define     MAXVALUE     1.e9
#define     MAX_ANIM_STEPS  100
#define     INI_SCREEN      600
#define     INI_MENU_WIDTH  160
#define     INI_MENU_HEIGHT  60
#define     PS_DENSITY       107     /* basic-density to convert xwd to ps */
#define     Z_DEPTH          2.      /* edge length of the drawing cube */
#define     SET_COLS    8            /* no. of predefined colors (w,k,y,m,g,b,r) */
#define     BAS_COLS    3            /* basic colours: black, white, grey */
#define     PICK        1            /* lower nurbs-density during picking */
#define     PICK_LENGTH 5            /* default cursor-length during picking */
#define     MAX_LINE_DIV 99          /* maximum line division (cadfix restriction) */
#define     MIN_LINE_DIV 2           /* minimum line division used for the automatic division calculation */
#define     NURS_TOLERANCE 30
#define     NURS_TOLERANCE_PICK 80
#define     MAX_PARAM_PER_RECORD 20
#define     AUTOGROUP            -2  /* group number for visible elements */ 
#define     MAX_GROUPS           99999 /* maximum group number (limited by frd-format) */
#define     MAX_MATERIALS        99999 /* maximum material number (limited by frd-format) */
#define     GLUT_MENU_POINT_HEIGHT  18 /* seems to be always that value anyway(?) */
#define     GL_FEEDBACK_BUFF_SIZE 300000 /* size of the feedback buffer for nurbs-rendering */
#define     UV_STEPS        101  /* resolution of the uv-space of nurbs (triangulation ) */
#define     MIN_ANGLE_TRI3  0.999   /* badelems.c: S*S, alfa=acos(sqrt(MIN_ANGLE_TRI3)) */

/*
#define     GLUT_FONT      GLUT_BITMAP_8_BY_13
#define     GLUT_FONT      GLUT_BITMAP_9_BY_15
#define     GLUT_FONT      GLUT_BITMAP_TIMES_ROMAN_10
#define     GLUT_FONT      GLUT_BITMAP_HELVETICA_12
#define     GLUT_FONT      GLUT_BITMAP_HELVETICA_18
*/
#define     GLUT_FONT      GLUT_BITMAP_9_BY_15


#define  CMAP_CELLS_LIGHT  34             /* number of grey-values in the colormap */
#define  CMAP_DARKSHIFT     5             /* black-shift of the most bright color-cell */

/* fixed values necessary for the mesher, must not be changed */
#define  MAX_SURFS_PER_BODY   6
#define  MAX_EDGES_PER_SURF 4
#define  MAX_CORNERS_PER_BODY 8

/* for convenience fixed arrays are used in interactive functions, values can be changed */
#define  EDGES_PER_SURF 100
#define  CORNERS_PER_BODY 100
#define  SURFS_PER_BODY   100
#define  LINES_PER_EDGE  100

/* for programmer convenience a max-value of faces per element is given (sufficient for all types) */
#define  MAX_FACES_PER_ELEM 6


/* suppress the creation of nurbsobjects, only splines are made from nurb-lines */
#define NO_NURL 0
#define NO_NURS 0


/* special sets */
#define     FLPB          "-FLPB"   /* stores bodies which will be inverse oriented */ 
#define     NJBY          "-NJBY"   /*  */ 
#define     COPY          "-COPY"   /*  */
#define     MESH          "-MESH"   /*  */
#define     NOMESH        "-NOMESH" /*  */
#define     ZAP           "-ZAP"    /*  */
#define     MPC           "-MPC"    /*  */
#define     NOMPC         "-NOMPC"  /*  */
#define     NOEL          "-NOEL"   /*  */
#define     ORI           "-ORI"    /*  */
#define     DEP           "-DEP"    /* used for proj */
#define     IND           "-IND"    /* used for proj  */
#define     TMP           "-TMP"    /* temporary buffer for several purposes */
#define     HIGHLIGHT     "-HIGHL"  /* highlights identified entities */
#define     UORI          "-UORI"   /* save all unoriented items */
#define     BNUR          "-BNUR"   /* save all bad nurbs */
#define     BSUR          "-BSUR"   /* save all bad surfs */

typedef struct {
  unsigned char flpb[MAX_LINE_LENGTH];
  unsigned char njby[MAX_LINE_LENGTH];
  unsigned char copy[MAX_LINE_LENGTH];
  unsigned char mesh[MAX_LINE_LENGTH];
  unsigned char nomesh[MAX_LINE_LENGTH];
  unsigned char zap[MAX_LINE_LENGTH];
  unsigned char mpc[MAX_LINE_LENGTH];
  unsigned char nompc[MAX_LINE_LENGTH];
  unsigned char noel[MAX_LINE_LENGTH];
  unsigned char ori[MAX_LINE_LENGTH];
  unsigned char dep[MAX_LINE_LENGTH];
  unsigned char ind[MAX_LINE_LENGTH];
  unsigned char tmp[MAX_LINE_LENGTH];
  unsigned char highl[MAX_LINE_LENGTH];
  unsigned char uori[MAX_LINE_LENGTH];
  unsigned char bnur[MAX_LINE_LENGTH];
  unsigned char bsur[MAX_LINE_LENGTH];
} SpecialSet;

typedef struct {
  double r, g, b;
} Colours;


typedef struct {
  unsigned char n, e, p, l, c, s, b, L, S, se;
} Lchar;


typedef struct {
    double r;
    int i;
}Rsort;


typedef struct {
    char typ;
    int indx;
    int nr;
}CfdSurf;

int nurbl2seq(int nurlNr, const Nurbl *nurbl);
int getBias_fbd(int l, Lines *line);
void pre_bia( unsigned char *record);
void splitBiasDiv(int *ptrdiv, double *ptrbias);
int improveBadTr3(unsigned char *setname);
void printHash();
int write2foam(unsigned char *setname, int strings, unsigned char **string, Summen *anz, Nodes *node, Faces *face, Elements *e_enqire, Sets *set );
int readFoam(unsigned char *datin, Summen *anz, Nodes **nptr, Elements **eptr, Datasets **lptr, int ****fptr  );

/* writefbd.c */
int writefbd(unsigned char *setname, SumGeo *anz, Points *pnt, Lines *line, Lcmb *lcmb, Gsur *surf, Gbod *body, Nurbs *nurs, Sets *set );

/* XFunktions_mesa.h */
void calcOffset(void);
void getColormap(void);
void storeColors(int anz_col, int pix );

/* copyEntity.h */
int createCenterpnt( unsigned char *pkt1, unsigned char *pkt2, unsigned char *pkt3 );
int copy_set( int settrgt, unsigned char *trans, int setNr, int *dep_p, int *dep_l, int *dep_c, int *dep_s, int *dep_se);
void pre_swep( unsigned char *record );
void pre_copy( unsigned char *record );
int  body_( unsigned char *name, unsigned char *corner );

/* dataGeo.h */
void descalPoints ( int anz_p, Points *point, Scale *scale );
void scalPoints ( int anz_p,  Points *point, Scale *scale );
void descalSurfs ( int anz_s,  Gsur *surf, Scale *scale );
void scalSurfs ( int anz_s,  Gsur *surf, Scale *scale );
void getScaleValues( int anz_n, int anz_p, Points *point, Nodes *node, Scale *scale);

/* dataMesh */
void descalNodes ( int anz_n, Nodes *node, Scale *scale );
void scalNodes ( int anz_n, Nodes *node, Scale *scale );
void calcDatasets( int num_olc, Summen *anz, Nodes *node, Datasets *lcase );
void calcAnimation( GLuint list_animate_light, GLuint *list_animate, int anim_steps, double anim_faktor, int *anim_alfa, int halfperiode, int centerNode, Summen *anz, Nodes *n_anim, Nodes *node, Elements *e_enqire, Datasets *lcase, int lc, Scale *scale, unsigned char surfFlag );
void calcSequence( GLuint list_animate_light, GLuint *list_animate, int *seqLC, int seq_steps, double anim_faktor, int halfperiode, int centerNode, Summen *anz, Nodes *n_anim, Nodes *node, Elements *e_enqire, Datasets *lcase, int lc, Scale *scale);

/* defineEntity.h */
int hashAlias( SumAsci *sumAsci, unsigned char *name, int nr);
void operateAlias( unsigned char *name, unsigned char *type );
void delNod( int anzn, int *number );
int  nod( Summen *anz, Nodes **nptr, int flag, int nodnr, double x, double y, double z, int scalFlag );
void pre_nod( unsigned char *record);
void delElem( int anze, int *index );
int elem_define( int elnr, int type, int *node, int setFlag, int eattr );
int hashPoint( SumAsci *sumAsci, unsigned char *name, int nr);
int hashLine( SumAsci *sumAsci, unsigned char *name, int nr);
int hashLcmb( SumAsci *sumAsci, unsigned char *name, int nr);
int hashSurf( SumAsci *sumAsci, unsigned char *name, int nr);
int hashBody( SumAsci *sumAsci, unsigned char *name, int nr);
int hashSet( SumAsci *sumAsci, unsigned char *name, int nr);
void pre_elem( unsigned char *record);
void bak_delPnt( int anz, int *number );
void delPnt( int anz, int *number );
int  pnt( unsigned char *name, double x, double y, double z, int scalFlag );
void pre_pnt( unsigned char *record, int flag);
void delLine( int anz, int *number );
int line_i( unsigned char *name, int ip1, int ip2, int trk, int div, double bias, unsigned char type );
int  line_( unsigned char *name, unsigned char *p1, unsigned char *p2, unsigned char *trk, int div, double bias );
void pre_line( unsigned char *record, int addFlag);
void delLcmb( int anz, int *number );
int lcmb_i( unsigned char *name, int add, int anz_l, unsigned char  *ori, int *lin );
int  lcmb_( unsigned char *name, int add, int anz_l, unsigned char *ori, unsigned char *lin );
void pre_lcmb( unsigned char *record, int addFlag);
void bak_delSurf( int anz, int *number );
void delSurf( int anz, int *number );
int  surface_i( unsigned char *name, unsigned char ori, int blend, int anz_c, unsigned char *cori, int *edge, unsigned char *typ );
int  surface( unsigned char *name, unsigned char ori, unsigned char *blend, int anz_c, unsigned char *cori, unsigned char *corner );
void pre_gsur( unsigned char *record, int addFlag);
void pre_surf( unsigned char *record);
void bak_delBody( int anz, int *number );
void delBody( int anz, int *number );
int  gbod_i( unsigned char *name, int blend, int anz_c, unsigned char *cori, int *corner );
int  gbod( unsigned char *name, unsigned char *blend, int anz_c, unsigned char *cori, unsigned char *corner );
void pre_gbod( unsigned char *record, int addFlag);
void pre_body( unsigned char *record);
int  nurl( unsigned char *string, int addFlag );
void delNurs( int anz, int *number );
int hashNurs( SumAsci *sumAsci, unsigned char *name, int nr);
int  nurs( unsigned char *string, int addFlag );


/* dispLists.h */
void drawFaces_vector(  int lc, int ne, int *e, double v_factor, int num, int *name, Nodes *node, Faces *face );
void drawElements_vector( int lc, int ne, int *e, double v_factor, int num, int *name, Nodes *node, Elements *e_enqire );
void drawModelEdges( GLuint list_model_edges, int color, double width,
                     int numEdges, Nodes *node, Edges *edge );
void drawDispListEdges( GLuint list, int color, double width, unsigned char key );
void drawFaces_edge( int num, int *name, Nodes *node, Faces *face, int col, unsigned char type );
void drawElem_edge( int num, int *name, Nodes *node, Elements *e_enqire, int col, unsigned char type );
void drawDispList( GLuint list, unsigned char key, Nodes *node );





/*  extFunktions.h */
void help( void );
int compareInt(int *a, int *b);
int compareFloat(double *a, double *b);
int askGLError(unsigned char buffer[134]);
void defineColIndexes_light(void);
void defineColIndexes_load(void);
void defineColIndexes_set(void);
void defineColTextur_load(void);
void zoom(double xcur0, double ycur0, double xcur1, double ycur1);
void qzoom(void);
void center(double x, double y, double z);
void qcenter(int x, int y);
void rot_u(double a);
void rot_r(double a);
void rot_c(double a);
void rot_x(double a);
void rot_y(double a);
void rot_z(double a);
void pre_rot( unsigned char *record);
int transform( unsigned char *record, int anz_n, Nodes *node );
int calcLineDiv(Lines *line, int nr, Points *point, double gtol_cos_a, double lmax, double lmin);
int fillBlendedSurf(int nr);
void repNurl(int nr );
void repNurs(int nr );
void untrimNurs(int nr );
void repSurf(int nr );
void rep( int j );
void adjustNodes();


/* cgx.h */
#if INX_MODE
void nodalDataset( int entity_Nr, int lc, Summen *anz, Scale *scale, Nodes *node
		   , Datasets *lcase, double *value_n, int *colNr, int offset, int maxIndex, int steps );
#endif 
#if TEX_MODE
void nodalDataset( int entity_Nr, int lc, Summen *anz, Scale *scale, Nodes *node
		   , Datasets *lcase, double *value_n, double *colNr );
#endif 
void elementDataset( int auswahl, int lc, Summen *anz, Scale *scale, Datasets *lcase, int offset, int maxIndex, int steps );
void allocUtilityData(void);
void entryfunktion( int state );
void WindowState( int state );
void Mouse( int x, int y );
void MouseState( int button, int state, int x, int y );
void menu( int selection );
void createHardcopy( int selection );
void updateDispLists(void);
void ConfigureAndShowWindow_Light(void);
void ConfigureAndShowWindow_Load( void );
void ConfigureAndShowWindow_Sequence( void );
void ConfigureAndShowWindow_Vector( void );
int minus( unsigned char *record );
int  plot( unsigned char *record );
int  plus( unsigned char *record );
void changeAnimation( int selection );
void newTimePerPeriode( int selection );
void tuneAnimation( int selection );
void stepsAnimation( int selection );
void redraw(void);
void selectEntity( int selection );
void createDatasetEntries(void);
void selectDataset( int selection );
Nodes *addDispToCoordinates( Nodes *nodes);
void selectView( int selection );
void selectData( unsigned char *record);
void Keyboard( unsigned char gkey, int x, int y );
void moveModel(void);
void DrawGraficLoad( void );
void DrawGraficLight( void );
void DrawGraficAnimate( void );
void DrawGraficSequence( void );
void DrawGraficVector( void );
void DrawPickedItems(void);
void DrawAxes();
void iniDrawMenu(void);
void DrawMenuLoad( void );
void DrawMenuLight( void );
void DrawMenuAnimate( void );
void DrawMenuSet( void );
void reshape( int width, int height );
void initLightAndMaterial_rgb( void );
void initLightAndMaterial_index( void );

/* iniMeshData.h     */
void makeSurfaces(void);
void iniMeshData( unsigned char *datin, unsigned char *format );
void iniElements(Summen *anz, Elements *elem, int ***facebuf);

/* mergEntity.h */
int *findCloseEntity( unsigned char type, Nodes *node, Points *point, Rsort *rsort, int indx, int anz_n, double local_gtol);
int mergeNode( Rsort *rsort, int anz_n, int indx, double local_gtol, int lock );
int mergePnt( Rsort *rsort, int anz_p, int indx, double local_gtol, int lock );
int mergeLine( int indx, int lock );
int mergeLcmb( int indx );
int mergeSurf( int indx, double local_gtol );
int compareRsort(Rsort *a, Rsort *b);
void pre_merge( unsigned char *record );

/* orient.h */
int orientLcmb( int nr );
int orientSurf( int nr );
int ori7SidedBody( int nr, int **cp );
int ori6SidedBody( int nr, int **cp );
int ori5SidedBody( int nr, int **cp );
int orientBody( int nr );
void orientSet( unsigned char *record);

/* pickFunktions.h    */
int hitAction( GLuint *name, unsigned char *type, int x, int y );
int hitUndo( GLuint *name, unsigned char *type, int x, int y );
int pickstack( GLuint name );
int processHits( GLint hits, GLuint *buffer, unsigned char *type, unsigned char *mode, int x, int y );
void defineDiv( unsigned char gkey, int x, int y );
void pick( unsigned char gkey, int x, int y );
void goPicking( int x, int y, unsigned char *type );
void drawListsPick(void);
void qali(void);
void qbia(void);
void qnod(void);
void qcnt(void);
void qcut(void);
void qdis(void);
void qele(void);
void qenq(void);
void qflp(void);
void qdiv(void);
void qadd( unsigned char *record);
void qcyc( unsigned char *record);
void qdel( void );
void qrem( unsigned char *record);
void qpnt( unsigned char *record);
void qlin( unsigned char *record);
void qsur( unsigned char *record);
void qbod( unsigned char *record);
void qseq(void);
void qspl(void);
void moveNode(int n, int x, int y);
void movePoint(int p, int x, int y);
int createElem(int n);
int createPoint( int x, int y );
int createLine( unsigned char *pnt, int flag );
void convertLine( int line, int pickbuf );
int splitLine( int lin, int x, int y  );
void pre_align( int nr, int flag );
void pre_cut( int nr, int flag );
void moveModel(void);
void updateDispLists(void);
void flip( unsigned char *type, int indx);

/* sendSet.h  */
void sendSurfNormalen( unsigned char *setname, unsigned char *format, Summen *anz, Nodes *node, Elements *e_enqire, Datasets *lcase , Scale *scale );
void sendPressure( unsigned char *setname, unsigned char *format, Summen *anz, Nodes *node, Elements *e_enqire, unsigned char *value, unsigned char *val1 );
void sendFilm( unsigned char *setname, unsigned char *format, Summen *anz, Nodes *node, Elements *e_enqire, unsigned char *val1, unsigned char *val2, unsigned char *val3, unsigned char *val4 );
void sendRadiate( unsigned char *setname, unsigned char *format, Summen *anz, Nodes *node, Elements *e_enqire, unsigned char *val1, unsigned char *val2, unsigned char *val3, unsigned char *val4 );
void sendCflux( unsigned char *setname, unsigned char *format, Summen *anz, Nodes *node, Elements *e_enqire, unsigned char *value, unsigned char *val2 );
void sendDflux( unsigned char *setname, unsigned char *format, Summen *anz, Nodes *node, Elements *e_enqire, unsigned char *val1, unsigned char *val2 );
void sendSPC( unsigned char *setname, unsigned char *format, Summen *anz, Nodes *node, Elements *e_enqire, unsigned char *value, unsigned char *val2 );
void sendSPC( unsigned char *setname, unsigned char *format, Summen *anz, Nodes *node, Elements *e_enqire, unsigned char *value, unsigned char *val2 );
void sendSliders( unsigned char *setname, unsigned char *format, Summen *anz, Nodes *node, Elements *e_enqire, unsigned char *spcType );
void sendNames( unsigned char *setname, unsigned char *format, Summen *anz, Nodes *node, Elements *e_enqire );
void sendForce( unsigned char *setname, unsigned char *format, Summen *anz, Nodes *node, Elements *e_enqire, double *f );

/* setFunktions.h  */
void iniSetFunktions(void);
void drawNodes_plot( int num, int *name, Nodes *node , int col, unsigned char type);
void drawElements_plot( int num, int *name, Nodes *node, Elements *e_enqire, int col, unsigned char type, int pickflag );
void drawElemNodes_plot( int num, int *name, Nodes *node, Elements *e_enqire, int col, unsigned char type );
void drawFaces_plot( int num, int *name, Nodes *node, Faces *face, int col, unsigned char type, int pickflag );
void drawFaceNodes_plot( int num, int *name, Nodes *node, Faces *face, int col, unsigned char type );
void drawPoints_plot( int num, int *name, Points *point , int col, unsigned char type);
void drawLines_plot( int num, int *name, Lines *line , Points *point, int col, unsigned char type);
void drawSurfs_plot( int num, int *name, Gsur *surf, Lcmb *lcmb, Lines *line , Points *point, int col, unsigned char type);
void drawBodys_plot( int num, int *name, Gbod *body, Gsur *surf, Lcmb *lcmb, Lines *line , Points *point, int col, unsigned char type);
void drawNurl_plot( int num, int *name, int col, unsigned char type, int pickflag);
void drawNurs_plot( int num, int *name, int col, unsigned char type, int pickflag);
int getSetNr(unsigned char *setname);
int getAliasNr(unsigned char *name);
int getNodNr(Summen *anz,Nodes *node,int nodnr );
int getElemNr (int elnr );
int getE_enqNr (int elnr );
int getPntNr(unsigned char *name);
int getLineNr(unsigned char *name);
int getLcmbNr(unsigned char *name);
int getSurfNr(unsigned char *name);
int getBodyNr(unsigned char *name);
int getNurlNr(unsigned char *name);
int getNursNr(unsigned char *name);
int getIndex(int **ipnt, int n, int x0 );
void delSet( unsigned char *setname);
int seto( unsigned char *setname );
void setc( unsigned char *setname );
int pre_seta( unsigned char *setname, unsigned char *type, unsigned char *name);
int seta( int setNr, unsigned char *type, int number);
int setr( int setNr, unsigned char *type, int number);
void seqr( int setNr, int number);
void pre_del( unsigned char *record);
void pre_move( unsigned char *record);
void free_proj(double *nx, double *nrad, int *nmissed  );
void pre_proj( unsigned char *record);
void pre_proc( unsigned char *record);
int prnt(unsigned char *record);
int  zap(unsigned char *record);
void grpa( int *elemGroup, int nr, int setNr );
void mata( int *elemMat, int nr, int setNr );
unsigned char getLetter(int i);
int getFamName( int n, unsigned char *c );
int getNewName( unsigned char *name, unsigned char *type );
void pre_movie(unsigned char *string);
int commandoInterpreter( unsigned char *type, unsigned char *string, int na, int nb, FILE *handle1, int addFlag, int *flag );
void readfbd( unsigned char *datin, int addFlag );
void readfrdfile( unsigned char *datin, unsigned char *setname );
void pre_read( unsigned char *record );
void pre_elty( unsigned char *record );
void pre_mesh( unsigned char *record );
int completeSet( unsigned char *setname, unsigned char *type );
int sendTriangles(  unsigned char *setname );
int write2stl(unsigned char *datout, Summen *anz, Nodes *node, Elements *elem, Datasets *lcase );
int write2netgenEdges(unsigned char *datout, Summen *anz, Nodes *node, Elements *elem, Datasets *lcase );
void pre_write( unsigned char *record );
void senddata( unsigned char *setname, unsigned char *format, Summen *anz, Nodes *node, Elements *e_enqire, Datasets *lcase , Scale *scale, int complete, unsigned char **val );
void drawSets(int mode);

/* sendMpc.c */
void sendMpc( unsigned char *setname, unsigned char *format, Summen *anz, Nodes *node, Elements *e_enqire, unsigned char *rotation, double *vector  );
void cycmpc(int set1, int set2, unsigned char *format, unsigned char *value, unsigned char *corr);
void areampc(int set1, int set2, unsigned char *format, unsigned char *value, unsigned char *corr, int offset);
int calcCoefficients(  Nodes *node, int n0, CTri3 *ctri3, int  e, double *c);
double find_Tri3( Nodes *node, int n, CTri3 *ctri3, int e);
void corrNode(  Nodes *node, int n, CTri3 *ctri3, int  e, double g );
void createMPCs();

/* graph.c */
void plot2D(unsigned char type, int setNr );
void graph( unsigned char *record);

/* corrad.c */
void corrad( int setNr, double minradius);

/* badelems.c */
int calcBadElements(unsigned char *record);

/* write2tochnog.c */
int write2tochnog(unsigned char *datout, Summen *anz, Nodes *node, Elements *elem, Datasets *lcase );

/* readccx.c */
int readccx(unsigned char *datin, Summen *anz, Nodes **nptr, Elements **eptr, Datasets **lptr, int ****fptr );
int getFilePointer( int filesopen, FILE **openfile, unsigned char *rec_str);


double repairNurbs( Nurbs *nurbs, int nr, int deg, int dir);
int evalNurbs( Nurbs *nurbs, int nr, int sum_p, double *pnt_u, double *pnt_v, Points *pnt);
void projSurfToNurbs( Nurbs *nurbs, int nr, Gsur *surf, int snr, Nodes *node );
void projPntsToNurbs( Nurbs *nurbs, int nr, Sets *set, int setNr, Points *pnt);
void trimNurbs( Nurbs *nurbs, int nr, int patch, double);


/* fillBody2.c */
int  fillSurf_ab( int j, int umax, int vmax, int *n_uv, int amax, int bmax, int *n_ab, int offs1, int offs2, double *x, double *y, double *z );
int  fillSurf_ba2( int sur, int *div_l, int div_a, int div_b, int sa1, int sa2, int sb1, int sb2, int *n_uv, int *umax, int *vmax, int *n_ba, int *amax, int *bmax,  int *offs_sa1, int *offs_sa2, double *x, double *y, double *z, double *x_ba, double *y_ba, double *z_ba );
int fillBody2( int b_indx, int *srefp, int **div_l, int *unbalance, int **nabc, int *amax, int *bmax, int *cmax, int *offs_sa1, int *offs_sa2, int *msur, int *div_sa1, int *div_sa2 );


/* meshSet.c */
void cornerNodes( int vmax, int umax, int j, int *n_uv );
int  newCornerPositions( int n, int u,int v,int umax, int vmax, double *lx,double *ly,double *lz,
 double *x,double *y,double *z, int flag );
int  fillSurf( int j, int *n_uv, int umax, int vmax, double *x, double *y, double *z );
int  fillSurf2( int sur, int *div_l, int div_a, int div_b, int sa1, int sa2, int sb1, int sb2,
 int *n_uv, int *umax, int *vmax, int *n_ba, int *amax, int *bmax, int *offs_sa1, int *offs_sa2,
 double *x, double *y, double *z );
void edgeNodes( int vmax, int umax, int j, int *n_uv );
int  newEdgePositions( int n, int u,int v,int umax, int vmax, double *lx,double *ly,double *lz, double *x,double *y,double *z, int flag );

int meshPoints( int setNr );
int straightNodes( int j, int k, int d, double *pn );
int arcNodes( int j, int k, int d, double *pn );
int splineNodes( int j, int k, int d, double *pn );
int nurlNodes( int j, int k, int d, double *pn );
int meshLines( int setNr );
int newDivisions( int *div_l, int *div_a,int *div_b, int *sa1,int *sa2,int *sb1,int *sb2 );
int addTwoLines( int l1, unsigned char o1, unsigned char typ1, int l2, unsigned char o2, unsigned char typ2 );
int splitLineAtDivratio(int edge, int typ, double splitdiv, int *lnew, unsigned char  *typnew);
int mesh_tr3u(int nr );
int merge_nlocal( Rsort *rsort, Nodes *nlocal, Elements *ctri3, int anz_e, int anz_n, int indx, int lock, double tol );
int deleteFreeEdges(Nodes *node, int *snods, int anz_n, Elements *elems, int anz_e );
int mesh_tr3g( int s );
int meshSurfs( int setNr );
int fillBody( int b, int *srefp, int umax, int vmax, int wmax, int *n_uvw, double *x, double *y, double *z );
int getSurfDivs( int b, int s, int *div_l );
int meshImprover( int *etyp, int *nodes, int *elements, int *n_indx, int *n_ori, double **n_coord, int **e_nod, int *n_type, int **n_corner, int **s_div );
int bodyFrom5Surfs( int *b);
int bodyFrom7Surfs( int *b);
int meshBodys( int setNr );
void meshSet(unsigned char *setname, int blockFlag, int lonly, int projFlag, int meshoptFlag_length, int meshoptFlag_angle );


/* surfMesh.h */
int surfMesh(int *imax, int *jmax, double *x, double *y, double *z);

/*  bodyMesh2.h */
int bodyMesh2(int *wmax, int *vmax, int *umax, double *x, double *y, double * z);

/*  improveMesh.o */
int smooth_length( double *co, int *nk, int *kon, int *ne, int *iptr1, int *iptr2, int *nside, int *ineino, int *nkind, int *neigh, int *ndiv, double *pneigh, int *maxsumdiv, int *etyp, int *nori);
int smooth_angle( double *co, int *nk, int *kon, int *ne, int *iptr1, int *iptr2, int *nside, int *ineino, int *nkind, int *neigh, int *ndiv, double *pneigh, int *maxsumdiv, int *etyp, int *nori);
int smooth_midnodes( double *co, int *nk, int *kon, int *ne, int *iptr1, int *iptr2, int *nside, int *ineino, int *nkind, int *neigh, int *ndiv, double *pneigh, int *maxsumdiv, int *etyp, int *nori);

/* userFunction.c */
void userFunction(unsigned char *string, Summen *sum, Nodes **nptr, Elements **eptr, Datasets **lptr, Faces **fptr, Sets **sptr);

/* calcWeight.c */
#define real double
#define integer int

/* Subroutine */ int hexaeder_(integer *iel, integer *istat, real *x, real *y,
			       real *z__, real *v, real *xcg, real *ycg, real *zcg);
/* Subroutine */ int tetraeder_(integer *iel, integer *istat, real *x, real *y,
				real *z__, real *v, real *xcg, real *ycg, real *zcg);

/* badelems.c  */
int shape8h_(double *xi, double *et, double *ze, double *xl, double *xsj);
int shape20h_(double *xi, double *et, double *ze, double *xl, double *xsj);
int shape10tet_(double *xi, double *et, double *ze, double *xl, double *xsj);
int e_c3d__(double *xl,unsigned char *elty);
int calcBadElements(unsigned char *setname);
