#include <stdio.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include "Axis3P.h" 
#include "ThreedeeP.h"
#include "Plot3P.h"

void CallbackDummy(w, clos, call_data)
     Widget w;
     caddr_t clos, call_data;
     
{
  printf("Called dummy callback");
}

static Boolean defaultAxesShown[] = {True, True, False, False, True, False, 
			       False, False, True, False, True, False};

static Arg targs[] = {
  {XtNtitle, (XtArgVal)"duh"},
  {XtNtitlePosX, (XtArgVal) CENTER},
  {XtNtitlePosY, (XtArgVal) TOP},
  {XtNautoScale, (XtArgVal)True},
  {XtNmarginWidth, (XtArgVal)10},
  {XtNmarginHeight, (XtArgVal)5},
  {XtNdownShear, (XtArgVal)(PI/6)},
  {XtNleftShear, (XtArgVal)(PI/3)},
  {XtNxmin, (XtArgVal)-100},
  {XtNxmax, (XtArgVal)100},
  {XtNymin, (XtArgVal)-5},
  {XtNymax, (XtArgVal)2},
  {XtNzmin, (XtArgVal)3},
  {XtNzmax, (XtArgVal)39},
};

static double z1pts[] = { -10.0, -2.5, -1.3, 4.0, 5.1, 12.2, 20.6, 27.7, 30.0};
static double y1pts[] = { 0.0, 7.5, 9.5, -15.4, 16.3, 22.0, 3.8, 10.0, 17.08};
static double x1pts[] = { 1.0, 2.0, 3.0, 1.0, 2.0, 3.0, 1.0, 2.0, 3.0};
static double x2pts[] = {-40.0, -30.0, -20.0, -10.0, 0.0, 10.0, 20.0, 
			   30.0, 40.0, 50.0}; 
static double y2pts[] = {2.2, 3.0, 4.0, 5.5, 6.8,-5.0, 0.0,5.0, 10.0, 15.0};
static double z2pts[] = {0.0, 1.0, 0.0, 2.0, 0.0, 3.0, 2.6, 2.0, 2.2, 0.0}; 



main(argc, argv)
     int argc;
     char *argv[];
{
  Widget toplevel;
  AtThreedeeWidget threedee; 
  AtPlot3Widget plot1, plot2;
  int i, j, II, JJ;
  Arg arglist[50];
  XYZ **datap1, **datap2;
  Surface p1, p2;

  static Arg shellargs[] = {
    {XtNsaveUnder, (XtArgVal)TRUE},
    {XtNtransient, (XtArgVal)TRUE},
    {XtNiconName, (XtArgVal)"3D"}
  };
  printf("XtVersion = %d\n", XtVersion);
  
  printf("1\n");
  toplevel = XtInitialize("main", "3D", NULL, 0, &argc, argv);
  printf("2\n");
  XtSetValues(toplevel, shellargs, XtNumber(shellargs));
  printf("3\n");

  i = 0;

/*  XtSetArg(arglist[0], XtNaxesShown, defaultAxesShown);
  printf("4\n");
  i = 1;  
  XtSetArg(arglist[i], XtNtitle, targs[i].value); i++;
  XtSetArg(arglist[i], XtNtitlePosX, targs[i].value); i++;
  XtSetArg(arglist[i], XtNtitlePosY, targs[i].value); i++;
  XtSetArg(arglist[i], XtNautoScale, targs[i].value); i++;
  XtSetArg(arglist[i], XtNmarginWidth, targs[i].value); i++;
  XtSetArg(arglist[i], XtNmarginHeight, targs[i].value); i++;
  XtSetArg(arglist[i], XtNdownShear, targs[i].value); i++;
  XtSetArg(arglist[i], XtNxmin, targs[i].value); i++;
  XtSetArg(arglist[i], XtNxmax, targs[i].value); i++;
  XtSetArg(arglist[i], XtNymin, targs[i].value); i++;
  XtSetArg(arglist[i], XtNymax, targs[i].value); i++;
  XtSetArg(arglist[i], XtNzmin, targs[i].value); i++;
  XtSetArg(arglist[i], XtNzmax, targs[i].value); i++;
  */
  printf("5\n");

  threedee = (AtThreedeeWidget)XtCreateWidget("threedee", 
						     atThreedeeWidgetClass, 
						     toplevel, 
						     (ArgList)arglist, i);
  printf("5+\n");
  XtManageChild(threedee);
  printf("6\n");

  XtAddCallback(threedee, XtNcallback, CallbackDummy, (caddr_t)toplevel);

  printf("7\n");
/*

#define II 3
#define JJ 3
  
  datap1 = (XYZ **)malloc(sizeof(XYZ *) * II);
  for(i = 0; i < II; i++) { 
    datap1[i] = (XYZ *)malloc(sizeof(XYZ) * JJ);
    for(j = 0; j < JJ; j++) {

      datap1[i][j].x = x1pts[i * JJ + j];
      datap1[i][j].y = y1pts[i * JJ + j];
      datap1[i][j].z = z1pts[i * JJ + j];
    }
  }
  
#undef II
#undef JJ
  
#define II 2
#define JJ 5
  
  datap2 = (XYZ **)malloc(sizeof(XYZ *) * II);
  for(i = 0; i < II; i++) { 
    datap2[i] = (XYZ *)malloc(sizeof(XYZ) * JJ);
    for(j = 0; j < JJ; j++) {

      datap2[i][j].x = x2pts[i * JJ + j];
      datap2[i][j].y = y2pts[i * JJ + j];
      datap2[i][j].z = z2pts[i * JJ + j];
    }
  }
  
#undef II
#undef JJ
  
  
  p1 = MakeSurfaceWithData(3, 3, datap1);
  p2 = MakeSurfaceWithData(2, 5, datap2);
  
  XtSetArg(arglist[0], XtNplotSurface, p1);
  plot1 = (AtPlot3Widget)XtCreateManagedWidget("plot3", 
  atPlot3WidgetClass, threedee,
				arglist, 1);
  
  XtSetArg(arglist[0], XtNplotSurface, p2);
  plot2 = (AtPlot3Widget)XtCreateManagedWidget("plot3", 
  atPlot3WidgetClass, threedee,
				arglist, 1);
*/  
  XtRealizeWidget(toplevel);
  XtMainLoop();
}
