-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuilder.c
4269 lines (3786 loc) · 122 KB
/
builder.c
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "xvt.h" /* standard XVT header */
#include "noddy.h" /* resource constants for this program */
#include "nodInc.h"
#include "status.h"
#include "titles.h"
#define DEBUG(X) X
#define DEBUG2(X)
#define MENU1_ROWS NUM_MENU_OPTIONS
#define MENU1_COLS 1
#define MENU2_ROWS 6
#define MENU2_COLS 3
#define MENU3_ROWS 1
#define MENU3_COLS NUM_MENU_OPTIONS
#define NUM_MENU_OPTIONS 14 /* num options in floating menu */
char *commandLine = 0;
static int menuItems[NUM_MENU_OPTIONS] = {
POINTER_ICON,
STRATIGRAPHY_ICON,
FOLD_ICON,
FAULT_ICON,
UNCONFORMITY_ICON,
SHEAR_ICON,
DYKE_ICON,
PLUG_ICON,
STRAIN_ICON,
TILT_ICON,
FOLIATION_ICON,
LINEATION_ICON,
IMPORT_ICON,
STOP_ICON };
static RCT menuItemPositions[NUM_MENU_OPTIONS];
static char *statusBarProps[] = {
"TASK_WIN Status Bar", /* title */
/* Property List */
"DEBUG=FALSE",
"DEFAULT_TEXT=\"Status Bar\"",
"FIELD_OFFSET=16",
"FILL_COLOR=LTGRAY",
"FONTSIZE=12",
"LEFT_OFFSET=8",
"PLAIN=FALSE",
"TASK_WIN=TRUE",
"TEXT_COLOR=BLACK",
/* ACE Instance Data */
"AUTOSIZED",
NULL /* NULL-terminate the array */
};
static int numStatusBarProps = 11;
WINDOW statusBar = NULL_WIN;
extern double **topographyMap;
extern int TopoCol, TopoRow;
extern BOOLEAN processingLongJob;
extern int batchExecution;
extern WINDOW_INFO batchWindowInfo;
extern ANOMIMAGE_DATA *gravityReferenceData, *magneticsReferenceData;
extern WINDOW currentPreviewWindow;
static WINDOW menuWindow = NULL_WIN;
static WINDOW historyWindow = NULL_WIN;
static BOOLEAN creatingObject = FALSE;
static FILE_SPEC currentFileName;
/* ************************ */
/* Buffers for Undo Command */
#define DELETE_UNDO_POSITONS -1
/* linked list of object + data of delete objects */
static OBJECT *lastRemovedObjects = (OBJECT *) NULL;
/* array pointers to objects in the linked list that were last added */
static int numLastAddedObjects = 0;
static OBJECT **lastAddedObjects = (OBJECT **) NULL;
/* linked list of the objects (with no data) showing last positions */
static OBJECT *lastObjectPositions = (OBJECT *) NULL;
/*
All drawing, selecting, etc., is in terms of logical coordinates.
Following macros convert between logical and physical coordinates.
*/
#define X_LOG_TO_PHYS(wip, x) ((x) - wip->origin.h)
#define Y_LOG_TO_PHYS(wip, y) ((y) - wip->origin.v)
#define X_PHYS_TO_LOG(wip, x) ((x) + wip->origin.h)
#define Y_PHYS_TO_LOG(wip, y) ((y) + wip->origin.v)
/*
Geometrical constants.
*/
#define PAGE_WIDTH 2000 /* width of page in pixels */
#define PAGE_HEIGHT 4000 /* height of page in pixels */
#define PAGE_INCR 25 /* "line" increment for scrolling */
#define MIN_SIZE 20 /* min. size for object */
#define MIN_MOVE 4 /* min. distance for moves */
/*
Prototypes and declarations for static functions.
*/
#if XVT_CC_PROTO
int checkOverlap (WINDOW, RCT, OBJECT *);
int pointBetweenObjects (WINDOW, PNT, OBJECT **, OBJECT **);
int makeRoomBetweenObjects (WINDOW, OBJECT **, OBJECT **, OBJECT **,
BOOLEAN, int *, int *);
static int validateStructure (WINDOW, RCT, OBJECTS, BOOLEAN);
void reorderObjects (WINDOW);
OBJECT * addObject (WINDOW, OBJECTS, RCT, char *, BOOLEAN);
void deleteSelectedObjects (WINDOW, BOOLEAN);
void deleteObject (WINDOW, OBJECT *);
int freeImportEventMemory (IMPORT_OPTIONS *);
int freeProfileEventMemory (OBJECT *);
static void obj_update(WINDOW);
static void obj_select(OBJECT *, BOOLEAN);
static void obj_select_enclosed(WINDOW, RCT *);
static void obj_draw_selection(OBJECT *, BOOLEAN);
static OBJECT *findObject (WINDOW, PNT);
static void obj_clear_selections(WINDOW);
static RCT *obj_bound_selected(WINDOW);
static int objMove(OBJECT *, int, int);
static int objMoveSelected(WINDOW, int, int);
static void setObjectBound (OBJECT *, RCT *);
static RCT *phys_rect(WINDOW, RCT *);
static void log_draw_rect(WINDOW, RCT *);
static void log_draw_oval(WINDOW, RCT *);
static void log_draw_roundrect(WINDOW, RCT *, int, int);
static void drawCenteredText(WINDOW, int, int, char *, int);
static void drawIcon_log (WINDOW, RCT *, int);
static void drawIcon (WINDOW, RCT *, int);
static BOOLEAN log_needs_update(WINDOW, RCT *);
static void log_set_clip(WINDOW, RCT *);
void log_invalidate_rect(WINDOW, RCT *);
/* ####################### General Utility Functions ######################## */
WINDOW createPreviewWindow (WINDOW, WINDOW);
WINDOW createEventWindow (OBJECT *);
WINDOW createPositionedWindow (int, WINDOW, int, int, EVENT_MASK, EVENT_HANDLER, long, RCT *);
WINDOW createCenteredWindow (int, WINDOW, EVENT_MASK, EVENT_HANDLER, long);
WINDOW createCenteredDialog (int, EVENT_MASK, EVENT_HANDLER, long);
void tidyObjects (WINDOW);
void copyUndoPositions (WINDOW_INFO *, int);
void copyUndoAdditions (OBJECT *, int);
void copyUndoDeletions (OBJECT *, int);
int undoChanges (WINDOW);
OBJECT *nthObject (WINDOW, int);
int totalObjects (WINDOW);
int countObjects (WINDOW);
int sizeofOptions (OBJECTS);
WINDOW getEventDrawingWindow ();
WINDOW getFloatingMenuWindow ();
void gridCorrectRect (RCT *grid_rctp, RCT *rctp);
static void normalizeRect (RCT *, RCT *);
static void yToRow (WINDOW, int, int *);
static void xToColumn (WINDOW, int, int *);
static void rowToY (WINDOW, int, int *, int *);
static void columnToX (WINDOW, int, int *, int *);
void editObjectParams (OBJECT *);
static void createObject(WINDOW, RCT);
static BOOLEAN moveObject(WINDOW, OBJECT *, PNT, PNT, int);
static void drawArrowBetween (WINDOW win, OBJECT *, OBJECT *);
static void drawObjectLinks (WINDOW win);
static void rubberRect (WINDOW, RCT *);
static void shift_view(WINDOW, int, int, PNT *);
static void autoscroll(WINDOW, EVENT *);
BOOLEAN doMouse(WINDOW, EVENT *);
static void updateDrawingWindow (WINDOW);
void updateFloatingMenu (WINDOW, OBJECT *, TOOL);
int setFloatingMenuShape (WINDOW, int, int);
int getFloatingMenuShape (WINDOW, int *, int *);
static void setCurrentObject (WINDOW, MENU_TAG);
static void doScroll (WINDOW, EVENT *);
static void scroll_sync(WINDOW);
static void setupWindow(WINDOW);
void setCurrentFileName (FILE_SPEC *);
void getCurrentFileName (FILE_SPEC *);
long windowEventHandler (WINDOW, EVENT *);
static long menuEventHandler (WINDOW, EVENT *);
void selectAllObjects ();
WINDOW_INFO *get_win_info(WINDOW win);
#else
int checkOverlap ();
int pointBetweenObjects ();
int makeRoomBetweenObjects ();
static int validateStructure ();
void reorderObjects ();
OBJECT * addObject ();
void deleteSelectedObjects ();
void deleteObject ();
int freeImportEventMemory ();
int freeProfileEventMemory ();
static void obj_update();
static void obj_select();
static void obj_select_enclosed();
static void obj_draw_selection();
static OBJECT *findObject ();
static void obj_clear_selections();
static RCT *obj_bound_selected();
static int objMove();
static int objMoveSelected();
static void setObjectBound ();
static RCT *phys_rect();
static void log_draw_rect();
static void log_draw_oval();
static void log_draw_roundrect();
static void drawCenteredText();
static void drawIcon_log ();
static void drawIcon ();
static BOOLEAN log_needs_update();
static void log_set_clip();
void log_invalidate_rect();
/* ####################### General Utility Functions ######################## */
WINDOW createPreviewWindow ();
WINDOW createEventWindow ();
WINDOW createPositionedWindow ();
WINDOW createCenteredWindow ();
WINDOW createCenteredDialog ();
void tidyObjects ();
void copyUndoPositions ();
void copyUndoAdditions ();
void copyUndoDeletions ();
int undoChanges ();
OBJECT *nthObject ();
int totalObjects ();
int countObjects ();
int sizeofOptions ();
WINDOW getEventDrawingWindow ();
WINDOW getFloatingMenuWindow ();
void gridCorrectRect ();
static void normalizeRect ();
static void yToRow ();
static void xToColumn ();
static void rowToY ();
static void columnToX ();
void editObjectParams ();
static void createObject();
static BOOLEAN moveObject();
static void drawArrowBetween ();
static void drawObjectLinks ();
static void rubberRect();
static void shift_view();
static void autoscroll();
BOOLEAN doMouse();
static void updateDrawingWindow ();
void updateFloatingMenu ();
int setFloatingMenuShape ();
int getFloatingMenuShape ();
static void setCurrentObject ();
static void doScroll ();
static void scroll_sync();
static void setupWindow();
void setCurrentFileName ();
void getCurrentFileName ();
long windowEventHandler ();
static long menuEventHandler ();
void selectAllObjects ();
WINDOW_INFO *get_win_info();
#endif
/*
** Following group of functions (obj_*) manipulate objects with access
** to the internals of the OBJECT data structure.
*/
/*
Function to set the bounds and handles of an object.
*/
static void
#if XVT_CC_PROTO
setObjectBound (OBJECT *p, RCT *bound)
#else
setObjectBound (p, bound)
register OBJECT *p;
RCT *bound;
#endif
{
p->bound = *bound;
}
/*
Function to draw (or clear) selection handles.
*/
static void
#if XVT_CC_PROTO
obj_draw_selection(OBJECT *p, BOOLEAN selected)
#else
obj_draw_selection(p, selected)
register OBJECT *p;
BOOLEAN selected;
#endif
{
DRAW_CTOOLS t;
RCT boundingRectangle;
if (!selected)
{
log_invalidate_rect (historyWindow, &(p->bound));
return;
}
xvt_app_get_default_ctools(&t);
t.mode = M_COPY;
t.pen.width = 2;
t.pen.pat = PAT_SOLID;
t.pen.color = COLOR_RED;
t.brush.pat = PAT_HOLLOW;
xvt_dwin_set_draw_ctools(historyWindow, &t);
/* draw a bounding rectangle around the selected object */
boundingRectangle.top = p->bound.top;
boundingRectangle.left = p->bound.left;
boundingRectangle.bottom = p->bound.bottom;
boundingRectangle.right = p->bound.right;
log_draw_rect(historyWindow, &boundingRectangle);
}
/*
Function to select or deselect an object.
*/
static void
#if XVT_CC_PROTO
obj_select(OBJECT *p, BOOLEAN select)
#else
obj_select(p, select)
register OBJECT *p;
BOOLEAN select;
#endif
{
if (p->selected != select) {
obj_draw_selection(p, select);
p->selected = select;
}
}
/*
Function to select all objects
*/
void
#if XVT_CC_PROTO
selectAllObjects ()
#else
selectAllObjects ()
#endif
{
OBJECT *object;
WINDOW eventDrawWindow = getEventDrawingWindow ();
WINDOW_INFO *wip;
wip = get_win_info(eventDrawWindow);
for (object = wip->head; object != NULL; object = object->next)
obj_select (object, TRUE);
}
/*
Get pointer to window info data
*/
WINDOW_INFO *
#if XVT_CC_PROTO
get_win_info(WINDOW win)
#else
get_win_info(win)
WINDOW win;
#endif
{
WINDOW_INFO *wip;
if (batchExecution)
return (&batchWindowInfo);
if (win)
wip = (WINDOW_INFO *) xvt_vobj_get_data(win);
else
wip = (WINDOW_INFO *) NULL;
return wip;
}
/*
Function to select objects enclosed by a given rectangle. If the rectangle
pointer is NULL, all objects are selected.
*/
static void
#if XVT_CC_PROTO
obj_select_enclosed(WINDOW win, RCT *rctp)
#else
obj_select_enclosed(win, rctp)
WINDOW win;
RCT *rctp;
#endif
{
WINDOW_INFO *wip = get_win_info(win);
register OBJECT *p;
for (p = wip->head; p != NULL; p = p->next)
if (rctp == NULL || (p->bound.left >= rctp->left &&
p->bound.top >= rctp->top && p->bound.right <= rctp->right &&
p->bound.bottom <= rctp->bottom))
obj_select(p, TRUE);
}
/*
Function to deselect all selected object.
*/
static void
#if XVT_CC_PROTO
obj_clear_selections(WINDOW win)
#else
obj_clear_selections(win)
WINDOW win;
#endif
{
WINDOW_INFO *wip = get_win_info(win);
register OBJECT *p;
for (p = wip->head; p != NULL; p = p->next)
if (p->selected) {
obj_draw_selection(p, FALSE);
p->selected = FALSE;
}
}
/*
Function to determine bounding box that encloses all selected objects.
*/
static RCT *
#if XVT_CC_PROTO
obj_bound_selected(WINDOW win)
#else
obj_bound_selected(win)
WINDOW win;
#endif
{
WINDOW_INFO *wip = get_win_info(win);
register OBJECT *p;
static RCT rct;
BOOLEAN first = TRUE;
for (p = wip->head; p != NULL; p = p->next)
if (p->selected) {
if (first) {
first = FALSE;
rct = p->bound;
}
rct.left = MIN(rct.left, p->bound.left);
rct.top = MIN(rct.top, p->bound.top);
rct.right = MAX(rct.right, p->bound.right);
rct.bottom = MAX(rct.bottom, p->bound.bottom);
}
return(&rct); /* may be empty rect */
}
/*
Function to reorder the objects in the list according to their position
*/
int
#if XVT_CC_PROTO
checkOverlap (WINDOW win, RCT bound, OBJECT *p)
#else
checkOverlap (win, bound, p)
WINDOW win;
RCT bound;
OBJECT *p;
#endif
{
WINDOW_INFO *wip = get_win_info(win);
register OBJECT *current;
int overlap = FALSE;
for (current = wip->head; current != NULL; current = current->next)
{
if (p != current)
{
if (!(p && p->selected && current->selected))
{
if ((bound.left == current->bound.left)
&& (bound.right == current->bound.right)
&& (bound.top == current->bound.top)
&& (bound.bottom == current->bound.bottom))
{
overlap = TRUE;
break;
}
}
}
}
if (overlap)
{
if (batchExecution)
fprintf (stderr, "You cannot place an object on top of an existing object");
else
xvt_dm_post_error("You cannot place an object on top of an existing object");
}
return (overlap);
}
/* ======================================================================
FUNCTION makeRoomBetweenObjects
DESCRIPTION
make enough room between object1, and object 2 to be able
to place objectIgnore or the current selection (depending on
the value of selected)
CHANGED
The spacing of the icons
offsetX, offsetY - the new offsets needed to place the object(s) into
the space provided.
RETURNED
0 - if no room needed to be made
1 - if room was made
(or atleast the closest position to it)
====================================================================== */
int
#if XVT_CC_PROTO
makeRoomBetweenObjects (WINDOW win, OBJECT **object1, OBJECT **object2,
OBJECT **objectIgnore, BOOLEAN selected,
int *offsetX, int *offsetY)
#else
makeRoomBetweenObjects (win, object1, object2, objectIgnore, selected,
offsetX, offsetY)
WINDOW win;
OBJECT **object1, **object2, **objectIgnore;
BOOLEAN selected;
int *offsetX, *offsetY;
#endif
{
int sameRow;
int spaceNeededX = 0, spaceNeededY = 0;
int actualSpaceX = 0, actualSpaceY = 0;
PNT topLeftStart, topLeftEnd;
RCT selectionBound;
int spaceAdded = FALSE;
OBJECT *p;
if (((*object1)->row == (*object2)->row) && ((*object1)->row == 1))
sameRow = TRUE;
else if ((*object1)->column == (*object2)->column)
sameRow = FALSE;
else
return (spaceAdded); /* should never happen as cannot be between them */
/* we need to make room for whatever is being placed to fit */
if (sameRow)
{ /* everything needs to be shifted in the X direction after object2 */
if (selected)
{
selectionBound = *obj_bound_selected (win);
spaceNeededX = (selectionBound.right - selectionBound.left)
+ (GRID_WIDTH - ICON_SIZE)*2;
topLeftStart.v = selectionBound.top;
topLeftStart.h = selectionBound.left;
}
else
{
spaceNeededX = GRID_WIDTH + (GRID_WIDTH - ICON_SIZE);
if (objectIgnore)
{
topLeftStart.v = (*objectIgnore)->bound.top;
topLeftStart.h = (*objectIgnore)->bound.left;
}
}
topLeftEnd.v = (short) ((*object1)->bound.top);
topLeftEnd.h = (short) ((*object1)->bound.left + GRID_WIDTH);
actualSpaceX = (*object2)->bound.left - (*object1)->bound.right;
/* move everything along in X direction */
if (actualSpaceX < spaceNeededX)
{
for (p = *object2; p != NULL; p = p->next)
{
if (objectIgnore)
{
/* only offset ones not involved in the actual move */
if (((!selected) && (p != *objectIgnore))
|| ((selected) && (!(p->selected))))
{
p->bound.left += spaceNeededX - actualSpaceX;
p->bound.right += spaceNeededX - actualSpaceX;
gridCorrectRect (&(p->bound), &(p->bound));
setObjectBound (p, &(p->bound));
spaceAdded = TRUE;
}
}
else
{
/* only offset ones not involved in the actual move */
if ((!selected) || ((selected) && (!(p->selected))))
{
p->bound.left += spaceNeededX - actualSpaceX;
p->bound.right += spaceNeededX - actualSpaceX;
gridCorrectRect (&(p->bound), &(p->bound));
setObjectBound (p, &(p->bound));
spaceAdded = TRUE;
}
}
}
}
}
else /* same Column */
{ /* everything in this column needs to be shifted in the Y direction */
if (selected)
{
selectionBound = *obj_bound_selected (win);
spaceNeededY = (selectionBound.bottom - selectionBound.top)
+ (GRID_HEIGHT - ICON_SIZE)*2;
topLeftStart.v = selectionBound.top;
topLeftStart.h = selectionBound.left;
}
else
{
spaceNeededY = GRID_HEIGHT + (GRID_HEIGHT - ICON_SIZE);
if (objectIgnore)
{
topLeftStart.v = (*objectIgnore)->bound.top;
topLeftStart.h = (*objectIgnore)->bound.left;
}
}
topLeftEnd.v = (*object1)->bound.top + GRID_HEIGHT;
topLeftEnd.h = (*object1)->bound.left;
/* in a selection object1 and object2 may not be int he same
** column as the top left corner so the offset will need to be
** offset by the position of the movement within the selection */
if (selected && objectIgnore)
{
topLeftEnd.v += selectionBound.top - (*objectIgnore)->bound.top;
topLeftEnd.h += selectionBound.left - (*objectIgnore)->bound.left;
}
actualSpaceY = (*object2)->bound.top - (*object1)->bound.bottom;
/* move everything in same column along in Y direction */
if (actualSpaceY < spaceNeededY)
{
for (p = *object2; (p != NULL) && (p->column == (*object2)->column);
p = p->next)
{
if (objectIgnore)
{
/* only offset ones not involved in the actual move */
if (((!selected) && (p != *objectIgnore))
|| ((selected) && (!(p->selected))))
{
p->bound.top += spaceNeededY - actualSpaceY;
p->bound.bottom += spaceNeededY - actualSpaceY;
gridCorrectRect (&(p->bound), &(p->bound));
setObjectBound (p, &(p->bound));
spaceAdded = TRUE;
}
}
else
{
/* only offset ones not involved in the actual move */
if ((!selected) || ((selected) && (!(p->selected))))
{
p->bound.top += spaceNeededY - actualSpaceY;
p->bound.bottom += spaceNeededY - actualSpaceY;
gridCorrectRect (&(p->bound), &(p->bound));
setObjectBound (p, &(p->bound));
spaceAdded = TRUE;
}
}
}
}
}
/* only assign the offsets if we have made space
** and the pointers are not NULL */
if (spaceAdded && offsetX && offsetY)
{
*offsetX = topLeftEnd.h - topLeftStart.h;
*offsetY = topLeftEnd.v - topLeftStart.v;
}
return (spaceAdded);
}
/*
Check to see if a point is between to objects
*/
int
#if XVT_CC_PROTO
pointBetweenObjects (WINDOW win, PNT point, OBJECT **object1, OBJECT **object2)
#else
pointBetweenObjects (win, point, object1, object2)
WINDOW win;
PNT point;
OBJECT **object1, **object2;
#endif
{
int betweenObjects = FALSE;
WINDOW_INFO *wip = get_win_info(win);
OBJECT *p, *next;
int allDone = FALSE;
/* check the horizontal connections first */
for (p = wip->head; (p != NULL) && (p->next != NULL); )
{
next = p->next;
/* skip over the ones in columns */
while (p->bound.left == next->bound.left)
{
if (next->next)
next = next->next;
else
{
allDone = TRUE;
break;
}
}
if (allDone)
break;
/* check to see if point is between these two */
if ((point.v > p->bound.top) && (point.v < p->bound.bottom) &&
(point.h > p->bound.right) && (point.h < next->bound.left))
{
betweenObjects = TRUE;
*object1 = p;
*object2 = next;
return (betweenObjects);
}
p = next;
}
/* now draw in the vertical connections */
for (p = wip->head; (p != NULL) && (p->next != NULL); p = p->next)
{
if (p->bound.left == p->next->bound.left)
{
/* check to see if point is between these two */
if ((point.h > p->bound.left) && (point.h < p->bound.right) &&
(point.v > p->bound.bottom) && (point.v < p->next->bound.top))
{
betweenObjects = TRUE;
*object1 = p;
*object2 = p->next;
return (betweenObjects);
}
}
}
return (betweenObjects);
}
/*
Function to make sure that a valid noddy structure will be producted
*/
static int
#if XVT_CC_PROTO
validateStructure (WINDOW win, RCT pos, OBJECTS object, BOOLEAN creating)
#else
validateStructure (win, pos, object, creating)
WINDOW win;
RCT pos;
OBJECTS object;
BOOLEAN creating;
#endif
{
WINDOW_INFO *wip = get_win_info(win);
register OBJECT *current;
int validOrder = TRUE;
int validObject = TRUE;
current = wip->head;
if ((current != NULL) && (current->shape == STRATIGRAPHY)
&& (object == STRATIGRAPHY))
{
/* we can only have 1 stratigraphy */
if (creating)
validObject = FALSE;
else
{ /* also cannot move the stratigraphy down lower than the top line **
** or further right than the right edge of events */
for (current = wip->head->next;
current != NULL; current = current->next)
{
if (pos.left > current->bound.left)
{
validOrder = FALSE;
break;
}
if (pos.top > current->bound.top)
{
validOrder = FALSE;
break;
}
}
}
}
/* decide if the current head is the one to check or
** the item being created or moved */
current = wip->head;
if ((current != NULL) &&
((current->bound.left < pos.left) ||
((current->bound.left == pos.left)
&& (current->bound.top < pos.top))))
{ /* current is the first item */
if (current->shape != STRATIGRAPHY)
validOrder = FALSE;
}
else /* the new one is going to be first */
{
if (object != STRATIGRAPHY)
validOrder = FALSE;
}
/* make sure the first one is always a statrigraphy */
if (!validOrder)
{
if (batchExecution)
fprintf (stderr, "A Stratigraphy must always come first");
else
xvt_dm_post_error("A Stratigraphy must always come first");
}
/* make sure there is only one stratigraphy */
if (!validObject)
{
if (batchExecution)
fprintf (stderr, "You may only have one Stratigraphy");
else
xvt_dm_post_error("You may only have one Stratigraphy");
}
if ((!validOrder) || (!validObject))
return (0);
else
return (1);
}
/*
Function to reorder the objects in the list according to their position
*/
void
#if XVT_CC_PROTO
reorderObjects (WINDOW win)
#else
reorderObjects (win)
WINDOW win;
#endif
{
WINDOW_INFO *wip = get_win_info(win);
register OBJECT *first, *current;
register OBJECT *startNewList = NULL, *newList;
register OBJECT *beforeFirst, *beforeCurrent;
int row, column, difference;
/* no list to order so just exit */
if (wip->head == NULL)
return;
/* Dont order anything with an invisable event in the history */
for (current = wip->head; current; current = current->next)
if (!current->drawEvent)
return;
while (wip->head != NULL)
{
/* assume first element is the smallest */
for (first = wip->head, current = first->next,
beforeFirst = NULL, beforeCurrent = first;
current != NULL;
beforeCurrent = current, current = current->next)
{
/* we are ordering from left to right */
if (current->bound.left < first->bound.left)
{
first = current;
beforeFirst = beforeCurrent;
}
else if (current->bound.left == first->bound.left)
{ /* when in the same X position the top one takes precedence */
if (current->bound.top < first->bound.top)
{
first = current;
beforeFirst = beforeCurrent;
}
}
}
if (startNewList == NULL)
{
/* remove element from wip list */
if (beforeFirst == NULL)
wip->head = first->next;
else
beforeFirst->next = first->next;
/* add it to our new list */
startNewList = first; /* initialise the new list to this first one */
newList = first; /* the end of the list is the same as the start */
}
else
{
/* remove element from wip list */
if (beforeFirst == NULL)
wip->head = first->next;
else
beforeFirst->next = first->next;
/* add it to our new list */
newList->next = first; /* append next smallest to end of new list */
newList = first; /* keep newList pointing to last element in list */
}
}
newList->next = NULL; /* the last appended is the last in the list */
wip->head = startNewList; /* make the wip list use our sorted one */
/* make sure the Row and column fields are right */
row = 1; column = 1;
for (current = wip->head; current != NULL; current = current->next)
{
current->row = row;
current->column = column;
/* make sure that the top layer is always in a line */
if (current->row == 1)
{
if (current->bound.top != wip->head->bound.top)
{
difference = wip->head->bound.top - current->bound.top;
current->bound.top += difference;
current->bound.bottom += difference;
setObjectBound (current, ¤t->bound);
}
}
if ((current->next)
&& (current->bound.left == current->next->bound.left))
{
row++; /* next one is a row down in this column */
}
else /* moving to the next column and therefore to the top of a row */
{
row = 1;
column++;
}
}
}
/*
Function to add an object to a window's list.
*/
OBJECT *
#if XVT_CC_PROTO
addObject (WINDOW win, OBJECTS shape, RCT bound, char *name, BOOLEAN selected)
#else
addObject (win, shape, bound, name, selected)
WINDOW win;
OBJECTS shape;
RCT bound;
char *name;
BOOLEAN selected;
#endif
{
WINDOW_INFO *wip = get_win_info(win);
register OBJECT *p;
char *optionsStructure;
static int count;
char buf[50];
/* malloc the basic structure */
p = (OBJECT *) xvt_mem_alloc(sizeof(OBJECT));
xvt_errmsg_sig_if(!(p != NULL), NULL_WIN, SEV_FATAL, ERR_ASSERT_4,"107",
107, "addObject: Out of memory.");
memset((char *)p, 0, sizeof(OBJECT));
/* malloc the options structure */
switch (shape)
{
case STRATIGRAPHY:
optionsStructure = (char *) xvt_mem_zalloc(sizeof (STRATIGRAPHY_OPTIONS));
xvt_errmsg_sig_if(!(optionsStructure != NULL), NULL_WIN, SEV_FATAL, ERR_ASSERT_4,"107",
107, "addObject: Out of memory for Options.");
break;
case FOLD: