#include <stdio.h>

#include "Relief.h"
#include "coordonn.h"
#include "FileType.h"
#include "dxf.h"

#define UNREFERENCED_PARAMETER(P) (P)

/* ************************************************************************ */

void fillpolyDXF(FILE *texte,int type_valeurs,int n,double *p,coord_3D *normale,char *rl) {
  UNREFERENCED_PARAMETER(normale);
  UNREFERENCED_PARAMETER(n);
  sauvegarde_facette_DXF_4(texte,(double) p[0],(double) p[1],(double) p[2],(double) p[3],(double) p[4],(double) p[5],(double) p[6],(double) p[7],(double) p[8],(double) p[9],(double) p[10],(double) p[11],type_valeurs,rl) ;
}
/* ------------------------------------------------------------------------ */
void ecrit_entete_DXF(FILE *texte,char *rl) {
  fprintf(texte,"0%sSECTION%s2%sENTITIES%s",rl,rl,rl,rl) ;
}
/* ------------------------------------------------------------------------ */
void ecrit_fin_DXF(FILE *texte,char *rl) {
  fprintf(texte,"0%sENDSEC%s0%sEOF%s",rl,rl,rl,rl) ;
}
/* ------------------------------------------------------------------------ */
void sauvegarde_facette_DXF_3(FILE *texte,double x1,double z1,double y1,double x2,double z2,double y2,double x3,double z3,double y3,int type_valeurs,char *rl)
  { switch ( type_valeurs ) {
      case FileType::ENTIERS :
        fprintf(texte,"0%s3DFACE%s8%sSV3D%s",rl,rl,rl,rl) ;
        fprintf(texte,"10%s%d%s20%s%d%s30%s%d%s",rl,(int) x1,rl,rl,(int) y1,rl,rl,(int) z1,rl) ;
        fprintf(texte,"11%s%d%s21%s%d%s31%s%d%s",rl,(int) x2,rl,rl,(int) y2,rl,rl,(int) z2,rl) ;
        fprintf(texte,"12%s%d%s22%s%d%s32%s%d%s",rl,(int) x3,rl,rl,(int) y3,rl,rl,(int) z3,rl) ;
        fprintf(texte,"13%s%d%s23%s%d%s33%s%d%s",rl,(int) x3,rl,rl,(int) y3,rl,rl,(int) z3,rl) ;
        break ;
      case FileType::REELS :
        fprintf(texte,"0%s3DFACE%s8%sSV3D%s",rl,rl,rl,rl) ;
        fprintf(texte,"10%s%lf%s20%s%lf%s30%s%lf%s",rl,x1,rl,rl,y1,rl,rl,z1,rl) ;
        fprintf(texte,"11%s%lf%s21%s%lf%s31%s%lf%s",rl,x2,rl,rl,y2,rl,rl,z2,rl) ;
        fprintf(texte,"12%s%lf%s22%s%lf%s32%s%lf%s",rl,x3,rl,rl,y3,rl,rl,z3,rl) ;
        fprintf(texte,"13%s%lf%s23%s%lf%s33%s%lf%s",rl,x3,rl,rl,y3,rl,rl,z3,rl) ; }
}
/* ------------------------------------------------------------------------ */
void sauvegarde_facette_DXF_4(FILE *texte,double x1,double z1,double y1,double x2,double z2,double y2,double x3,double z3,double y3,double x4,double z4,double y4,int type_valeurs,char *rl)
  { switch ( type_valeurs ) {
      case FileType::ENTIERS :
        fprintf(texte,"0%s3DFACE%s8%sSV3D%s",rl,rl,rl,rl) ;
        fprintf(texte,"10%s%d%s20%s%d%s30%s%d%s",rl,(int) x1,rl,rl,(int) y1,rl,rl,(int) z1,rl) ;
        fprintf(texte,"11%s%d%s21%s%d%s31%s%d%s",rl,(int) x2,rl,rl,(int) y2,rl,rl,(int) z2,rl) ;
        fprintf(texte,"12%s%d%s22%s%d%s32%s%d%s",rl,(int) x3,rl,rl,(int) y3,rl,rl,(int) z3,rl) ;
        fprintf(texte,"13%s%d%s23%s%d%s33%s%d%s",rl,(int) x4,rl,rl,(int) y4,rl,rl,(int) z4,rl) ;
        break ;
      case FileType::REELS :
        fprintf(texte,"0%s3DFACE%s8%sSV3D%s",rl,rl,rl,rl) ;
        fprintf(texte,"10%s%lf%s20%s%lf%s30%s%lf%s",rl,x1,rl,rl,y1,rl,rl,z1,rl) ;
        fprintf(texte,"11%s%lf%s21%s%lf%s31%s%lf%s",rl,x2,rl,rl,y2,rl,rl,z2,rl) ;
        fprintf(texte,"12%s%lf%s22%s%lf%s32%s%lf%s",rl,x3,rl,rl,y3,rl,rl,z3,rl) ;
        fprintf(texte,"13%s%lf%s23%s%lf%s33%s%lf%s",rl,x4,rl,rl,y4,rl,rl,z4,rl) ; }
}
/* ------------------------------------------------------------------------ */
void debut_facette_DXF(FILE *texte,int type_valeurs,char *rl)
  { switch ( type_valeurs ) {
      case FileType::ENTIERS :
        fprintf(texte,"0%s3DFACE%s8%sSV3D%s",rl,rl,rl,rl) ;
        break ;
      case FileType::REELS :
        fprintf(texte,"0%s3DFACE%s8%sSV3D%s",rl,rl,rl,rl) ; }
}
/* ------------------------------------------------------------------------ */
void sommet_facette_DXF(FILE *texte,double x1,double z1,double y1,int n,int type_valeurs,char *rl)
  { char sn1[8],sn2[8],sn3[8] ;
    sprintf(sn1,"%d",10+n) ;
    sprintf(sn2,"%d",20+n) ;
    sprintf(sn3,"%d",30+n) ;
    switch ( type_valeurs ) {
      case FileType::ENTIERS :
        fprintf(texte,"%s%s%d%s%s%s%d%s%s%s%d%s",sn1,rl,(int) x1,rl,sn2,rl,(int) y1,rl,sn3,rl,(int) z1,rl) ;
        break ;
      case FileType::REELS :
        fprintf(texte,"%s%s%lf%s%s%s%lf%s%s%s%lf%s",sn1,rl,x1,rl,sn2,rl,y1,rl,sn3,rl,z1,rl) ; }
}

/* ************************************************************************ */
