-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLispCAD.cpp
255 lines (212 loc) · 7.46 KB
/
LispCAD.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
// generated by Fast Light User Interface Designer (fluid) version 1.0302
#include "LispCAD.h"
#include <iostream>
void add_line(cl_object x, cl_object y, cl_object x2, cl_object y2) {
ShapePoint a(ecl_to_double(x), ecl_to_double(y));
ShapePoint b(ecl_to_double(x2), ecl_to_double(y2));
Shape temp;
temp = Shape::shape_make_line(a, b, 255, 255, 255);
canvas->drawing_ptr->add_shape(temp);
canvas->redraw();
}
void add_circle(cl_object x, cl_object y, cl_object radius) {
ShapePoint a(ecl_to_double(x), ecl_to_double(y));
Shape temp;
temp = Shape::shape_make_circle(a, ecl_to_double(radius), 255, 255, 255);
canvas->drawing_ptr->add_shape(temp);
canvas->redraw();
}
void add_arc(cl_object start_x, cl_object start_y, cl_object end_x, cl_object end_y, cl_object angle, cl_object angle2) {
ShapePoint start_point(ecl_to_double(start_x), ecl_to_double(start_y));
ShapePoint end_point(ecl_to_double(end_x), ecl_to_double(end_y));
Shape temp;
double a = ecl_to_double(angle);
double a2 = ecl_to_double(angle2);
temp = Shape::shape_make_arc(start_point, end_point, a, a2,
255, 255, 255);
canvas->drawing_ptr->add_shape(temp);
canvas->redraw();
}
void test_CB(Fl_Widget* w, void* p) {
std::cout << "test_CB called!" << std::endl;
}
void commandline_CB(Fl_Widget* w, void* data) {
CommandLine* ptr = (CommandLine *)w;
if(ptr->repl_mode)
{
cl_safe_eval(c_string_to_object(ptr->value()), Cnil, Cnil);
ptr->value("");
}
else
{
ptr->readonly(true);
}
}
/**
// Prompt and grab string from commandline
*/
std::string commandline_get_string(const std::string& prompt, CommandLine *input) {
input->repl_mode = false;
// Lock some widgets here
// ...
Fl_Text_Buffer* buff = echo_area->buffer();
buff->text("");
echo_area->insert(prompt.c_str());
input->readonly(false);
input->activate();
input->value("");
// Now trap user in input
while(! input->readonly())
{
Fl::wait();
}
// Reactivate other groups here
// ...
std::string return_string = input->value();
// Reset prompt
buff->text("");
input->value("");
input->readonly(false);
input->repl_mode = true;
return return_string;
}
/**
// Request a string from user
*/
cl_object get_string(cl_object prompt) {
std::string val;
std::string string = "";
//get dimension
int j = prompt->string.dim;
//get pointer
ecl_character* selv = prompt->string.self;
//do simple pointer addition
for(int i=0;i<j;i++){
string += (*(selv+i));
}
val = commandline_get_string(std::string(string), mini_buffer);
val = "\"" + val + "\"";
return c_string_to_object(val.c_str());
}
cl_object get_int(cl_object prompt) {
std::string val;
std::string string = "";
//get dimension
int j = prompt->string.dim;
//get pointer
ecl_character* selv = prompt->string.self;
//do simple pointer addition
for(int i=0;i<j;i++){
string += (*(selv+i));
}
val = commandline_get_string(std::string(string), mini_buffer);
return ecl_make_int(std::atoi(val.c_str()));
}
cl_object get_double(cl_object prompt) {
std::string val;
std::string string = "";
//get dimension
int j = prompt->string.dim;
//get pointer
ecl_character* selv = prompt->string.self;
//do simple pointer addition
for(int i=0;i<j;i++){
string += (*(selv+i));
}
val = commandline_get_string(std::string(string), mini_buffer);
return ecl_make_double_float(std::atof(val.c_str()));
}
Fl_Double_Window *main_window=(Fl_Double_Window *)0;
CADCanvas *canvas=(CADCanvas *)0;
Fl_Text_Display *echo_area=(Fl_Text_Display *)0;
CommandLine *mini_buffer=(CommandLine *)0;
Fl_Menu_Bar *menu_bar=(Fl_Menu_Bar *)0;
static void cb_file_quit_item(Fl_Menu_*, void*) {
exit(0);
}
Fl_Menu_Item menu_menu_bar[] = {
{"File", 0, 0, 0, 64, FL_NORMAL_LABEL, 0, 14, 0},
{"New", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
{"Save", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
{"Save As", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
{"Quit", 0, (Fl_Callback*)cb_file_quit_item, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
{0,0,0,0,0,0,0,0,0},
{"Edit", 0, 0, 0, 64, FL_NORMAL_LABEL, 0, 14, 0},
{0,0,0,0,0,0,0,0,0},
{"Lisp", 0, 0, 0, 64, FL_NORMAL_LABEL, 0, 14, 0},
{"Refresh Scripts", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
{"REPL", 0, 0, (void*)(0), 0, FL_NORMAL_LABEL, 0, 14, 0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0}
};
Fl_Slider *pan_across=(Fl_Slider *)0;
Fl_Slider *pan_vert=(Fl_Slider *)0;
int main(int argc, char **argv) {
cl_boot(argc, argv);
atexit(cl_shutdown);
std::string loadpath="(load \"System/SYSTEM Scripts/Setup.lisp\")";
cl_safe_eval(c_string_to_object(loadpath.c_str()), Cnil, Cnil);
{ main_window = new Fl_Double_Window(800, 630, "LispCAD");
main_window->box(FL_UP_BOX);
{ canvas = new CADCanvas(0, 27, 780, 488, "CADCanvas");
canvas->box(FL_FLAT_BOX);
canvas->color(FL_FOREGROUND_COLOR);
canvas->selection_color(FL_BACKGROUND_COLOR);
canvas->labeltype(FL_NORMAL_LABEL);
canvas->labelfont(0);
canvas->labelsize(14);
canvas->labelcolor(FL_FOREGROUND_COLOR);
canvas->align(Fl_Align(FL_ALIGN_CENTER));
canvas->when(FL_WHEN_ENTER_KEY_ALWAYS);
Fl_Group::current()->resizable(canvas);
} // CADCanvas* canvas
{ echo_area = new Fl_Text_Display(5, 535, 790, 43);
echo_area->box(FL_FLAT_BOX);
echo_area->color(FL_LIGHT2);
echo_area->textcolor((Fl_Color)36);
echo_area->buffer(new Fl_Text_Buffer);
echo_area->scrollbar_width(12);
echo_area->wrap_mode(Fl_Text_Display::WRAP_AT_BOUNDS, 80);
} // Fl_Text_Display* echo_area
{ mini_buffer = new CommandLine(5, 580, 790, 25);
mini_buffer->box(FL_THIN_DOWN_BOX);
mini_buffer->color(FL_BACKGROUND2_COLOR);
mini_buffer->selection_color((Fl_Color)94);
mini_buffer->labeltype(FL_NORMAL_LABEL);
mini_buffer->labelfont(0);
mini_buffer->labelsize(14);
mini_buffer->labelcolor(FL_FOREGROUND_COLOR);
mini_buffer->textfont(4);
mini_buffer->callback((Fl_Callback*)commandline_CB);
mini_buffer->align(Fl_Align(FL_ALIGN_TOP_LEFT));
mini_buffer->when(FL_WHEN_ENTER_KEY_ALWAYS);
} // CommandLine* mini_buffer
{ menu_bar = new Fl_Menu_Bar(0, 0, 800, 26);
menu_bar->color(FL_LIGHT1);
menu_bar->menu(menu_menu_bar);
} // Fl_Menu_Bar* menu_bar
{ pan_across = new Fl_Slider(0, 514, 780, 19);
pan_across->type(5);
pan_across->color(FL_LIGHT1);
pan_across->selection_color((Fl_Color)94);
} // Fl_Slider* pan_across
{ pan_vert = new Fl_Slider(780, 24, 20, 491);
pan_vert->type(4);
pan_vert->selection_color((Fl_Color)94);
} // Fl_Slider* pan_vert
main_window->size_range(640, 480);
main_window->end();
} // Fl_Double_Window* main_window
// Connect mini_buffer to canvas
canvas->CommandLine_ptr = mini_buffer;
// Register ecl functions
cl_def_c_function(c_string_to_object("add-line"), cl_objectfn_fixed(add_line), 4);
cl_def_c_function(c_string_to_object("add-circle"), cl_objectfn_fixed(add_circle), 3);
cl_def_c_function(c_string_to_object("add-arc"), cl_objectfn_fixed(add_arc), 6);
cl_def_c_function(c_string_to_object("ask-string"), cl_objectfn_fixed(get_string), 1);
cl_def_c_function(c_string_to_object("ask-int"), cl_objectfn_fixed(get_int), 1);
cl_def_c_function(c_string_to_object("ask-double"), cl_objectfn_fixed(get_double), 1);
main_window->show();
main_window->show(argc, argv);
return Fl::run();
}