0
|
1 |
#include <tcl.h>
|
|
2 |
#include <tk.h>
|
|
3 |
#include <stdlib.h>
|
|
4 |
#include <string.h>
|
|
5 |
#include "link.h"
|
|
6 |
#include "tcl_interface.h"
|
|
7 |
#include "stdio.h"
|
|
8 |
#include "Page.h"
|
|
9 |
|
|
10 |
extern Page* global_page;
|
|
11 |
extern Page* active_page;
|
|
12 |
extern Page* zoned_page;
|
|
13 |
|
|
14 |
extern Tcl_Interp* TCL_ip;
|
|
15 |
extern Tk_Window main_window;
|
|
16 |
extern double SCALE_FACTOR;
|
|
17 |
extern int DISPLAY_SPELLING_MISTAKES;
|
|
18 |
extern TclMode mode;
|
|
19 |
static int page_currently_open = 0;
|
|
20 |
|
|
21 |
Component * curCompSelected;
|
|
22 |
Component * prevCompSelected;
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
void scale(int& coordinate)
|
|
27 |
{
|
|
28 |
coordinate = (int)(coordinate * SCALE_FACTOR);
|
|
29 |
}
|
|
30 |
|
|
31 |
void scale(int& coordinate, double scaleFactor)
|
|
32 |
{
|
|
33 |
coordinate = (int)(coordinate * scaleFactor);
|
|
34 |
}
|
|
35 |
|
|
36 |
int error(char* s)
|
|
37 |
{
|
|
38 |
/* would like to make this take var num args */
|
|
39 |
printf("Error: %s", s);
|
|
40 |
}
|
|
41 |
|
|
42 |
int quit_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
43 |
{
|
|
44 |
printf("Thank you for using OCRchie.\n");
|
|
45 |
exit(0);
|
|
46 |
}
|
|
47 |
|
|
48 |
int get_linenum_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
49 |
{
|
|
50 |
// argv[1] - x coord argv[2] - y coord
|
|
51 |
global_page->get_linenum(atoi (argv[1]), atoi (argv[2]));
|
|
52 |
return TCL_OK;
|
|
53 |
}
|
|
54 |
|
|
55 |
int add_equation_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
56 |
{
|
|
57 |
// argv[1] starting line of equation, [2] startcol [3] endline [4] endcol
|
|
58 |
global_page->addEquation(atoi (argv[1]), atoi (argv[2]), atoi(argv[3]),
|
|
59 |
atoi(argv[4]));
|
|
60 |
return TCL_OK;
|
|
61 |
}
|
|
62 |
|
|
63 |
int delete_equation_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
64 |
{
|
|
65 |
global_page->deleteEquation(atoi(argv[1]), atoi(argv[2]));
|
|
66 |
return TCL_OK;
|
|
67 |
|
|
68 |
}
|
|
69 |
|
|
70 |
int auto_zone_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
71 |
{
|
|
72 |
((ZonedPage *) global_page)->autoZone(atoi(argv[1]), atoi(argv[2]));
|
|
73 |
return TCL_OK;
|
|
74 |
}
|
|
75 |
|
|
76 |
int add_zone_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
77 |
{
|
|
78 |
// first we need to unscale from scaled immage
|
|
79 |
int ulx = (int)(atof(argv[1])/ZONING_SCALE_FACTOR);
|
|
80 |
int uly = (int)(atof(argv[2])/ZONING_SCALE_FACTOR);
|
|
81 |
int lrx = (int)(atof(argv[3])/ZONING_SCALE_FACTOR);
|
|
82 |
int lry = (int)(atof(argv[4])/ZONING_SCALE_FACTOR);
|
|
83 |
|
|
84 |
Point ul = Point(ulx,uly);
|
|
85 |
Point lr = Point(lrx, lry);
|
|
86 |
|
|
87 |
if ( ul != lr)
|
|
88 |
{
|
|
89 |
Zone * newzone = new Zone(ul,lr);
|
|
90 |
newzone->buildPage((ZonedPage *) global_page);
|
|
91 |
((ZonedPage *)global_page)->zones()->Append(newzone);
|
|
92 |
}
|
|
93 |
|
|
94 |
return TCL_OK;
|
|
95 |
|
|
96 |
}
|
|
97 |
|
|
98 |
|
|
99 |
int remove_zone_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
100 |
{
|
|
101 |
int x = (int)(atof(argv[1])/ZONING_SCALE_FACTOR);
|
|
102 |
int y = (int)(atof(argv[2])/ZONING_SCALE_FACTOR);
|
|
103 |
|
|
104 |
Zones * z = ((ZonedPage *) global_page)->zones();
|
|
105 |
|
|
106 |
z->removeElement(z->findZone(x,y));
|
|
107 |
return TCL_OK;
|
|
108 |
}
|
|
109 |
|
|
110 |
int select_comp_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
111 |
{
|
|
112 |
prevCompSelected = curCompSelected;
|
|
113 |
//argv[1] is x coord argv[2] is y
|
|
114 |
curCompSelected = global_page->compAt(Point(atoi(argv[1]), atoi(argv[2])));
|
|
115 |
if (curCompSelected == NULL)
|
|
116 |
{
|
|
117 |
docommand("set validComponent 0");
|
|
118 |
}
|
|
119 |
else
|
|
120 |
{
|
|
121 |
docommand("set validComponent 1");
|
|
122 |
docommand("set curCompId %s",curCompSelected->fasciiId);
|
|
123 |
docommand("puts \"curCompId: $curCompId\"");
|
|
124 |
}
|
|
125 |
return TCL_OK;
|
|
126 |
}
|
|
127 |
|
|
128 |
int join_comp_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
129 |
{
|
|
130 |
if (prevCompSelected != NULL && curCompSelected != NULL &&
|
|
131 |
prevCompSelected != curCompSelected &&
|
|
132 |
global_page->get_linenum(prevCompSelected) ==
|
|
133 |
global_page->get_linenum(curCompSelected))
|
|
134 |
{
|
|
135 |
global_page->join(prevCompSelected,curCompSelected);
|
|
136 |
printf("Joined. cur %u prev %u \n", (long) curCompSelected,
|
|
137 |
(long) prevCompSelected);
|
|
138 |
|
|
139 |
prevCompSelected = NULL;
|
|
140 |
curCompSelected = NULL;
|
|
141 |
}
|
|
142 |
else
|
|
143 |
printf("not Joined. cur %u prev %u\n", (long) curCompSelected,
|
|
144 |
(long) prevCompSelected);
|
|
145 |
{
|
|
146 |
prevCompSelected = NULL;
|
|
147 |
curCompSelected = NULL;
|
|
148 |
}
|
|
149 |
|
|
150 |
return TCL_OK;
|
|
151 |
}
|
|
152 |
|
|
153 |
int learn_comp_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
154 |
|
|
155 |
{
|
|
156 |
learn(curCompSelected, argv[1], 256);
|
|
157 |
return TCL_OK;
|
|
158 |
}
|
|
159 |
int split_comp_horiz_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
160 |
{
|
|
161 |
global_page->thinnestHorizontalSplit(curCompSelected);
|
|
162 |
|
|
163 |
return TCL_OK;
|
|
164 |
}
|
|
165 |
|
|
166 |
int get_skew_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
167 |
{
|
|
168 |
get_skew(global_page->rmap());
|
|
169 |
return TCL_OK;
|
|
170 |
}
|
|
171 |
|
|
172 |
int deskew_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
173 |
{
|
|
174 |
if(DESKEW_METHOD != -1)
|
|
175 |
{
|
|
176 |
if(global_page->deskew(DESKEW_METHOD))
|
|
177 |
global_page->rmap()->display_intervals("black");
|
|
178 |
return TCL_OK;
|
|
179 |
}
|
|
180 |
else
|
|
181 |
return TCL_OK;
|
|
182 |
}
|
|
183 |
|
|
184 |
int display_intervals_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
185 |
{
|
|
186 |
if (ac == 1)
|
|
187 |
global_page->rmap()->display_intervals("black");
|
|
188 |
else
|
|
189 |
global_page->rmap()->display_intervals(argv[1], atof(argv[2]), "black");
|
|
190 |
return TCL_OK;
|
|
191 |
}
|
|
192 |
|
|
193 |
int page_open_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
194 |
{
|
|
195 |
mode = REGULAR;
|
|
196 |
if(ac != 2)
|
|
197 |
return TCL_ERROR;
|
|
198 |
printf("Opening %s\n", argv[1]);
|
|
199 |
if(page_currently_open == 1)
|
|
200 |
{
|
|
201 |
/* should print some message about closing the current one first */
|
|
202 |
return TCL_OK;
|
|
203 |
}
|
|
204 |
global_page = new ZonedPage;
|
|
205 |
if(global_page->readMap(argv[1]) != VALID)
|
|
206 |
interp->result = "0";
|
|
207 |
else
|
|
208 |
{
|
|
209 |
interp->result = "1";
|
|
210 |
}
|
|
211 |
active_page = global_page;
|
|
212 |
page_currently_open = 1;
|
|
213 |
return TCL_OK;
|
|
214 |
}
|
|
215 |
|
|
216 |
int zoned_page_open_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
217 |
{
|
|
218 |
mode = ZONING;
|
|
219 |
if(ac != 2)
|
|
220 |
return TCL_ERROR;
|
|
221 |
printf("Opening %s\n", argv[1]);
|
|
222 |
if(page_currently_open == 1)
|
|
223 |
{
|
|
224 |
/* should print some message about closing the current one first */
|
|
225 |
return TCL_OK;
|
|
226 |
}
|
|
227 |
global_page = new ZonedPage;
|
|
228 |
if(global_page->readMap(argv[1]) != VALID)
|
|
229 |
interp->result = "0";
|
|
230 |
else
|
|
231 |
{
|
|
232 |
interp->result = "1";
|
|
233 |
}
|
|
234 |
zoned_page = global_page;
|
|
235 |
page_currently_open = 1;
|
|
236 |
return TCL_OK;
|
|
237 |
}
|
|
238 |
|
|
239 |
|
|
240 |
int extract_comp_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
241 |
{
|
|
242 |
global_page->extractComponents(MinHorizSeparation);
|
|
243 |
return TCL_OK;
|
|
244 |
|
|
245 |
}
|
|
246 |
|
|
247 |
int get_page_height_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
248 |
{
|
|
249 |
sprintf(interp->result, "%d", global_page->get_height());
|
|
250 |
/* printf("Interpereter height = %s\n", interp->result); */
|
|
251 |
return TCL_OK;
|
|
252 |
}
|
|
253 |
|
|
254 |
int get_page_width_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
255 |
{
|
|
256 |
sprintf(interp->result, "%d", global_page->get_width());
|
|
257 |
/* printf("Interpereter width = %s\n", interp->result); */
|
|
258 |
return TCL_OK;
|
|
259 |
}
|
|
260 |
|
|
261 |
int zoom_in_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
262 |
{
|
|
263 |
if(ac == 1)
|
|
264 |
{
|
|
265 |
SCALE_FACTOR = SCALE_FACTOR * 2;
|
|
266 |
global_page->rmap()->display_intervals("black");
|
|
267 |
}
|
|
268 |
else
|
|
269 |
{
|
|
270 |
//argv[1] window argv[2] scalefactor
|
|
271 |
global_page->rmap()->display_intervals(argv[1], atof(argv[2]),"black");
|
|
272 |
}
|
|
273 |
return TCL_OK;
|
|
274 |
}
|
|
275 |
|
|
276 |
int zoom_out_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
277 |
{
|
|
278 |
if (ac == 1)
|
|
279 |
{
|
|
280 |
SCALE_FACTOR = SCALE_FACTOR * 0.5;
|
|
281 |
global_page->rmap()->display_intervals("black");
|
|
282 |
}
|
|
283 |
else
|
|
284 |
global_page->rmap()->display_intervals(argv[1], atof(argv[2]),"black");
|
|
285 |
|
|
286 |
return TCL_OK;
|
|
287 |
}
|
|
288 |
|
|
289 |
int deallocate_page_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
290 |
{
|
|
291 |
if(page_currently_open == 0)
|
|
292 |
return TCL_OK; /* don't do anything if their isn't anything open */
|
|
293 |
delete global_page;
|
|
294 |
page_currently_open = 0;
|
|
295 |
return TCL_OK;
|
|
296 |
}
|
|
297 |
|
|
298 |
int learn_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
299 |
{
|
|
300 |
// argv1 is tif argv2 is txt and argv3 is a bool for word synchronization
|
|
301 |
printf("Learning from %s and %s sych %d\n", argv[1], argv[2], atoi(argv[3]));
|
|
302 |
learn(argv[1], argv[2], atoi(argv[3]));
|
|
303 |
return TCL_OK;
|
|
304 |
}
|
|
305 |
|
|
306 |
int learn_page_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
307 |
{
|
|
308 |
// argv1 is txt and argv2 is a bool for word synchronization
|
|
309 |
printf("Learning from %s and %s sych %d\n", argv[1], argv[2], atoi(argv[3]));
|
|
310 |
learn(global_page, argv[1], atoi(argv[2]));
|
|
311 |
return TCL_OK;
|
|
312 |
}
|
|
313 |
|
|
314 |
int learn_data_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
315 |
{
|
|
316 |
printf("Learning data from %s\n", argv[1]);
|
|
317 |
readLearnedGroups(argv[1]);
|
|
318 |
return TCL_OK;
|
|
319 |
}
|
|
320 |
|
|
321 |
int write_word_pos_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
322 |
{
|
|
323 |
global_page->writeWordPos(argv[1]);
|
|
324 |
return TCL_OK;
|
|
325 |
}
|
|
326 |
|
|
327 |
int write_wordbox_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
328 |
{
|
|
329 |
// arguments are output file, x offset, y offset and WbxEquationsOnly variable
|
|
330 |
global_page->writeWordbox(argv[1], atoi(argv[2]), atoi(argv[3]), atoi(argv[4]));
|
|
331 |
return TCL_OK;
|
|
332 |
}
|
|
333 |
|
|
334 |
int write_equations_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
335 |
{
|
|
336 |
// arguments are output file, linenumber offset
|
|
337 |
global_page->writeEquations(argv[1], atoi(argv[2]));
|
|
338 |
return TCL_OK;
|
|
339 |
}
|
|
340 |
|
|
341 |
int write_learned_chars_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
342 |
{
|
|
343 |
writeLearnedGroups(argv[1]);
|
|
344 |
return TCL_OK;
|
|
345 |
}
|
|
346 |
|
|
347 |
int find_lines_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
348 |
{
|
|
349 |
deskew_cmd(clientData, interp, ac, argv);
|
|
350 |
/* printf("Calling setlines\n"); */
|
|
351 |
global_page->setLines();
|
|
352 |
return TCL_OK;
|
|
353 |
}
|
|
354 |
|
|
355 |
|
|
356 |
int recognize_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
357 |
|
|
358 |
{
|
|
359 |
/* just in case someone has left something sitting around */
|
|
360 |
docommand(".main_window.edit_window.text_part delete 1.0 end");
|
|
361 |
docommand("set COLORED_WORDS {}");
|
|
362 |
/* printf("Calling extractComponents\n"); */
|
|
363 |
if(global_page->components() == NULL)
|
|
364 |
global_page->extractComponents(MinHorizSeparation);
|
|
365 |
/* printf("Calling recognize\n"); */
|
|
366 |
global_page->recognize();
|
|
367 |
/* printf("Calling extractwords\n"); */
|
|
368 |
global_page->extractWords();
|
|
369 |
if(SPELLCHECK)
|
|
370 |
{
|
|
371 |
/* printf("Spellchecking\n"); */
|
|
372 |
global_page->spellcheck();
|
|
373 |
}
|
|
374 |
/* printf("Calling sendwordstotcl\n"); */
|
|
375 |
global_page->send_words_to_tcl();
|
|
376 |
return TCL_OK;
|
|
377 |
}
|
|
378 |
|
|
379 |
int find_lines_and_recognize_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
380 |
|
|
381 |
{
|
|
382 |
/* just in case someone has left something sitting around */
|
|
383 |
docommand(".main_window.edit_window.text_part delete 1.0 end");
|
|
384 |
docommand("set COLORED_WORDS {}");
|
|
385 |
/* printf("Calling deskew\n"); */
|
|
386 |
deskew_cmd(clientData, interp, ac, argv);
|
|
387 |
/* printf("Calling setlines\n"); */
|
|
388 |
global_page->setLines();
|
|
389 |
/* printf("Calling extractComponents\n"); */
|
|
390 |
global_page->extractComponents(MinHorizSeparation);
|
|
391 |
/* printf("Calling recognize\n"); */
|
|
392 |
global_page->recognize();
|
|
393 |
/* printf("Calling extractwords\n"); */
|
|
394 |
global_page->extractWords();
|
|
395 |
if(SPELLCHECK)
|
|
396 |
{
|
|
397 |
/* printf("Spellchecking\n"); */
|
|
398 |
global_page->spellcheck();
|
|
399 |
}
|
|
400 |
/* printf("Calling sendwordstotcl\n"); */
|
|
401 |
global_page->send_words_to_tcl();
|
|
402 |
return TCL_OK;
|
|
403 |
}
|
|
404 |
|
|
405 |
|
|
406 |
int switch_to_active_page_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
407 |
{
|
|
408 |
if (active_page != NULL)
|
|
409 |
global_page = active_page;
|
|
410 |
return TCL_OK;
|
|
411 |
}
|
|
412 |
|
|
413 |
int switch_to_zoned_page_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
414 |
{
|
|
415 |
if (zoned_page != NULL)
|
|
416 |
global_page = zoned_page;
|
|
417 |
return TCL_OK;
|
|
418 |
}
|
|
419 |
|
|
420 |
int set_active_page_cmd(ClientData clientData, Tcl_Interp *interp, int ac, char** argv)
|
|
421 |
{
|
|
422 |
|
|
423 |
int x = atoi(argv[1]);
|
|
424 |
int y = atoi(argv[2]);
|
|
425 |
active_page = ((ZonedPage *) zoned_page)->activate(x,y);
|
|
426 |
if (active_page != NULL)
|
|
427 |
{
|
|
428 |
docommand(".main_window.edit_window.text_part delete 1.0 end");
|
|
429 |
docommand("set COLORED_WORDS {}");
|
|
430 |
docommand("focus .main_window.display");
|
|
431 |
docommand("grab current .main_window.display");
|
|
432 |
global_page = active_page;
|
|
433 |
docommand("DISPLAY_INTERVALS .main_window.display.work_space $SCALE_FACTOR");
|
|
434 |
docommand("FIND_LINES");
|
|
435 |
docommand("grab release .main_window.display");
|
|
436 |
docommand("zone_message \"Active Zone at (%d,%d)\"", x, y);
|
|
437 |
}
|
|
438 |
else
|
|
439 |
{
|
|
440 |
docommand("zone_message \"No zone found here\"");
|
|
441 |
}
|
|
442 |
return TCL_OK;
|
|
443 |
|
|
444 |
}
|
|
445 |
|
|
446 |
|
|
447 |
static int
|
|
448 |
vdocommand1(char* s)
|
|
449 |
{
|
|
450 |
/* final function called to do a tcl docommand */
|
|
451 |
int code;
|
|
452 |
|
|
453 |
code = Tcl_Eval(TCL_ip, s);
|
|
454 |
if (code == TCL_ERROR)
|
|
455 |
error(TCL_ip->result);
|
|
456 |
return code;
|
|
457 |
}
|
|
458 |
|
|
459 |
void update()
|
|
460 |
{
|
|
461 |
Tk_DoOneEvent(TK_ALL_EVENTS);
|
|
462 |
}
|
|
463 |
|
|
464 |
static int
|
|
465 |
vdocommand(int record, char* fmt, va_list args)
|
|
466 |
{
|
|
467 |
/* helper for docommand */
|
|
468 |
char buf[4097];
|
|
469 |
int code;
|
|
470 |
|
|
471 |
vsprintf(buf, fmt, args);
|
|
472 |
if (strchr(buf, '\?'))
|
|
473 |
error("Huh?");
|
|
474 |
code = vdocommand1(buf);
|
|
475 |
return code;
|
|
476 |
}
|
|
477 |
|
|
478 |
|
|
479 |
int
|
|
480 |
docommand(char* fmt, ...)
|
|
481 |
{
|
|
482 |
/* do a tcl command, var number of args */
|
|
483 |
va_list args;
|
|
484 |
|
|
485 |
va_start(args, fmt);
|
|
486 |
vdocommand(0, fmt, args);
|
|
487 |
va_end(args);
|
|
488 |
}
|
|
489 |
|
|
490 |
static int
|
|
491 |
vset_status1(char* s)
|
|
492 |
{
|
|
493 |
/* final function called to do a tcl docommand */
|
|
494 |
int code;
|
|
495 |
|
|
496 |
code = Tcl_Eval(TCL_ip, s);
|
|
497 |
if (code == TCL_ERROR)
|
|
498 |
error(TCL_ip->result);
|
|
499 |
return code;
|
|
500 |
}
|
|
501 |
|
|
502 |
static int
|
|
503 |
vset_status(int record, char* fmt, va_list args)
|
|
504 |
{
|
|
505 |
/* helper for docommand */
|
|
506 |
char buf[4097];
|
|
507 |
char newbuf[4097];
|
|
508 |
int code;
|
|
509 |
|
|
510 |
vsprintf(buf, fmt, args);
|
|
511 |
sprintf(newbuf, ".main_window.button_bar.msg configure -text \"%s\"", buf);
|
|
512 |
if (strchr(buf, '\?'))
|
|
513 |
error("Huh?");
|
|
514 |
code = vset_status1(newbuf);
|
|
515 |
return code;
|
|
516 |
}
|
|
517 |
|
|
518 |
int set_status(char* fmt, ...)
|
|
519 |
{
|
|
520 |
va_list args;
|
|
521 |
|
|
522 |
va_start(args, fmt);
|
|
523 |
vset_status(0, fmt, args);
|
|
524 |
va_end(args);
|
|
525 |
docommand("update");
|
|
526 |
}
|
|
527 |
|
|
528 |
int mispelled(char* word)
|
|
529 |
{
|
|
530 |
int result = docommand("spellcheck %s", word);
|
|
531 |
/* printf("call to spellcheck %s returned %s\n", word, TCL_ip->result); */
|
|
532 |
if(!(strcmp("MISPELLED", TCL_ip->result)))
|
|
533 |
return 1;
|
|
534 |
else
|
|
535 |
return 0;
|
|
536 |
}
|
|
537 |
|
|
538 |
|
|
539 |
|
|
540 |
int initialize_interpreter()
|
|
541 |
{
|
|
542 |
TCL_ip = Tcl_CreateInterp();
|
|
543 |
Tcl_Init(TCL_ip);
|
|
544 |
|
|
545 |
}
|
|
546 |
|
|
547 |
|
|
548 |
int load_user_interface()
|
|
549 |
{
|
|
550 |
main_window = Tk_CreateMainWindow(TCL_ip, NULL, "OCRchie", "OCRchie");
|
|
551 |
Tk_Init(TCL_ip);
|
|
552 |
Tk_MapWindow(main_window);
|
|
553 |
docommand("source new_ui.tcl");
|
|
554 |
}
|
|
555 |
|
|
556 |
int initialize_command_procs()
|
|
557 |
{
|
|
558 |
Tcl_CreateCommand(TCL_ip, "page_open", page_open_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
559 |
Tcl_CreateCommand(TCL_ip, "zoned_page_open", zoned_page_open_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
560 |
Tcl_CreateCommand(TCL_ip, "EXTRACT_COMP", extract_comp_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
561 |
Tcl_CreateCommand(TCL_ip, "get_page_height", get_page_height_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
562 |
Tcl_CreateCommand(TCL_ip, "get_page_width", get_page_width_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
563 |
Tcl_CreateCommand(TCL_ip, "LEARN", learn_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
564 |
Tcl_CreateCommand(TCL_ip, "LEARN_PAGE", learn_page_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
565 |
Tcl_CreateCommand(TCL_ip, "LEARN_DATA", learn_data_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
566 |
Tcl_CreateCommand(TCL_ip, "WRITE_WORD_POS", write_word_pos_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
567 |
Tcl_CreateCommand(TCL_ip, "WRITE_WORDBOX", write_wordbox_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
568 |
Tcl_CreateCommand(TCL_ip, "WRITE_EQUATIONS", write_equations_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
569 |
|
|
570 |
Tcl_CreateCommand(TCL_ip, "WRITE_LEARNED_CHARS", write_learned_chars_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
571 |
Tcl_CreateCommand(TCL_ip, "FIND_LINES_AND_RECOGNIZE", find_lines_and_recognize_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
572 |
Tcl_CreateCommand(TCL_ip, "FIND_LINES", find_lines_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
573 |
Tcl_CreateCommand(TCL_ip, "RECOGNIZE", recognize_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
574 |
Tcl_CreateCommand(TCL_ip, "SELECT_COMP", select_comp_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
575 |
Tcl_CreateCommand(TCL_ip, "JOIN_COMP", join_comp_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
576 |
Tcl_CreateCommand(TCL_ip, "LEARN_COMP", learn_comp_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
577 |
|
|
578 |
Tcl_CreateCommand(TCL_ip, "SPLIT_COMP_HORIZ", split_comp_horiz_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
579 |
Tcl_CreateCommand(TCL_ip, "GET_SKEW", get_skew_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
580 |
Tcl_CreateCommand(TCL_ip, "DESKEW", deskew_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
581 |
Tcl_CreateCommand(TCL_ip, "DISPLAY_INTERVALS", display_intervals_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
582 |
Tcl_CreateCommand(TCL_ip, "QUIT", quit_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
583 |
Tcl_CreateCommand(TCL_ip, "ZOOM_IN", zoom_in_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
584 |
Tcl_CreateCommand(TCL_ip, "ZOOM_OUT", zoom_out_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
585 |
Tcl_CreateCommand(TCL_ip, "DEALLOCATE_PAGE", deallocate_page_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
586 |
Tcl_CreateCommand(TCL_ip, "GET_LINENUM",get_linenum_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
587 |
Tcl_CreateCommand(TCL_ip, "ADD_EQUATION",add_equation_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
588 |
Tcl_CreateCommand(TCL_ip, "DELETE_EQUATION",delete_equation_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
589 |
Tcl_CreateCommand(TCL_ip, "AUTO_ZONE",auto_zone_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
590 |
Tcl_CreateCommand(TCL_ip, "ADD_ZONE",add_zone_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
591 |
Tcl_CreateCommand(TCL_ip, "REMOVE_ZONE",remove_zone_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
592 |
|
|
593 |
Tcl_CreateCommand(TCL_ip, "SWITCH_TO_ACTIVE_PAGE",switch_to_active_page_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
594 |
Tcl_CreateCommand(TCL_ip, "SWITCH_TO_ZONED_PAGE",switch_to_zoned_page_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
595 |
|
|
596 |
Tcl_CreateCommand(TCL_ip, "SET_ACTIVE_PAGE",set_active_page_cmd, (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
|
|
597 |
|
|
598 |
|
|
599 |
printf("Done initializing new tcl commands\n");
|
|
600 |
}
|
|
601 |
|
|
602 |
int initialize_link_vars()
|
|
603 |
{
|
|
604 |
init_link_vars(); /* what a nice name */
|
|
605 |
docommand("source link_vars.tcl");
|
|
606 |
printf("Done initializing link variables\n");
|
|
607 |
}
|
|
608 |
|
|
609 |
|
|
610 |
|
|
611 |
|
|
612 |
|
|
613 |
|
|
614 |
|
|
615 |
|
|
616 |
|
|
617 |
|
|
618 |
|
|
619 |
|