Make project relevant to Mechatronics
[ipdf/code.git] / src / main.cpp
1 #include "main.h"
2 #include <unistd.h> // Because we can.
3
4 int main(int argc, char ** argv)
5 {       
6         #ifndef __STDC_IEC_559__
7         Warn("__STDC_IEC_559__ not defined. IEEE 754 floating point not fully supported.\n");
8         #endif
9
10
11         Debug("Compiled with REAL = %d => \"%s\" sizeof(Real) == %d bytes", REAL, g_real_name[REAL], sizeof(Real));
12
13         Document doc;
14         srand(time(NULL));
15
16         enum {OUTPUT_TO_BMP, LOOP} mode = LOOP;
17         
18         
19         Colour c(0,0,0,1);
20         const char * input_bmp = NULL;
21         const char * output_bmp = NULL;
22         const char * input_filename = NULL;
23         float b[4] = {0,0,1,1};
24
25         int i = 0;
26         while (++i < argc)
27         {
28                 if (argv[i][0] != '-')
29                 {
30                         input_filename = argv[i];
31                         continue;               
32                 }
33                 switch (argv[i][1])
34                 {
35                         case 'o':
36                                 mode = OUTPUT_TO_BMP;
37                                 if (++i >= argc)
38                                         Fatal("No input argument following -o switch");
39                                 input_bmp = argv[i];
40                                 if (++i >= argc)
41                                         Fatal("No output argument following -o switch");
42                                 output_bmp = argv[i];
43
44                                 break;
45                         case 'c':
46                         {
47                                 Debug("Reading paint colour");
48                                 for (int j = 1; j <= 4; ++j)
49                                 {
50                                         if (i+j >= argc)
51                                                 Fatal("No %d colour component following -c switch", j);
52                                         char * e;
53                                         float * comp = (j == 1) ? (&c.r) : ((j == 2) ? (&c.g) : ((j == 3) ? (&c.b) : &(c.a)));
54                                         *comp = strtof(argv[i+j], &e);
55                                         if (*e != '\0')
56                                                 Fatal("Colour component %d not a valid float", j); 
57                                 }
58                                 i += 4;
59                                 break;
60                         }
61                         case 'b':
62                         {
63                                 Debug("Reading view bounds");
64                                 for (int j = 1; j <= 4; ++j)
65                                 {
66                                         if (i+j >= argc)
67                                                 Fatal("No %d bounds component following -b switch", j);
68                                         char * e;
69                                         b[j-1] = strtof(argv[i+j], &e);
70                                         if (*e != '\0')
71                                                 Fatal("Bounds component %d not a valid float", j); 
72                                 }
73                                 i += 4;
74                                 break;
75                         }
76                 }       
77         }
78
79         if (input_filename != NULL)
80         {
81                 doc.LoadSVG(input_filename, Rect(0,0,Real(1)/Real(800),Real(1)/Real(600)));
82         }
83         else 
84         {
85                 //doc.AddBezier(Bezier(0,0, 1,0.5, 0.5,1, 1,1));
86                 doc.AddText("The quick brown\nfox jumps over\nthe lazy dog",0.1,0,0.5);
87                 //doc.AddBezier(Bezier(0,0,0,0.1,0,0.1,0,0.1));
88         }
89         Debug("Start!");
90         Rect bounds(b[0],b[1],b[2],b[3]);
91
92         if (mode == LOOP)
93                 MainLoop(doc, bounds, c);
94         else if (mode == OUTPUT_TO_BMP)
95                 OverlayBMP(doc, input_bmp, output_bmp, bounds, c);
96         return 0;
97 }

UCC git Repository :: git.ucc.asn.au