1 /*------------------------------------------------------------\
2 | |
3 | This file is part of the Alliance CAD System Copyright |
4 | (C) Laboratoire LIP6 - D�partement ASIM Universite P&M Curie|
5 | |
6 | Home page : http://www-asim.lip6.fr/alliance/ |
7 | E-mail : mailto:alliance-users@asim.lip6.fr |
8 | |
9 | This progam is free software; you can redistribute it |
10 | and/or modify it under the terms of the GNU General Public |
11 | License as published by the Free Software Foundation; |
12 | either version 2 of the License, or (at your option) any |
13 | later version. |
14 | |
15 | Alliance VLSI CAD System is distributed in the hope that |
16 | it will be useful, but WITHOUT ANY WARRANTY; |
17 | without even the implied warranty of MERCHANTABILITY or |
18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
19 | Public License for more details. |
20 | |
21 | You should have received a copy of the GNU General Public |
22 | License along with the GNU C Library; see the file COPYING. |
23 | If not, write to the Free Software Foundation, Inc., |
24 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
25 | |
26 \------------------------------------------------------------*/
27
28 /*------------------------------------------------------------\
29 | |
30 | Tool : XPAT |
31 | |
32 | File : View.c |
33 | |
34 | Authors : Jacomme Ludovic |
35 | |
36 | Date : 04.12.96 |
37 | |
38 \------------------------------------------------------------*/
39 /*------------------------------------------------------------\
40 | |
41 | Include Files |
42 | |
43 \------------------------------------------------------------*/
44
45 # include <stdio.h>
46 # include <Xm/Xm.h>
47
48 # include "mut.h"
49 # include "aut.h"
50 # include "pat.h"
51 # include "XSB.h"
52 # include "XPT.h"
53 # include "XTB.h"
54 # include "XMX.h"
55 # include "XMV.h"
56
57 # include "XMV_view.h"
58 # include "XMX_grid.h"
59
60 /*------------------------------------------------------------\
61 | |
62 | Constants |
63 | |
64 \------------------------------------------------------------*/
65 /*------------------------------------------------------------\
66 | |
67 | Types |
68 | |
69 \------------------------------------------------------------*/
70 /*------------------------------------------------------------\
71 | |
72 | Variables |
73 | |
74 \------------------------------------------------------------*/
75
76 xpatzoom *XpatHeadZoom = (xpatzoom *)NULL;
77
78 int XpatPercentZoom = XPAT_PERCENT_ZOOM;
79 int XpatPercentMoveX = XPAT_PERCENT_MOVE;
80 int XpatPercentMoveY = XPAT_PERCENT_MOVE;
81
82 /*------------------------------------------------------------\
83 | |
84 | Menu |
85 | |
86 \------------------------------------------------------------*/
87 /*------------------------------------------------------------\
88 | |
89 | Functions |
90 | |
91 \------------------------------------------------------------*/
92 /*------------------------------------------------------------\
93 | |
94 | XpatAllocZoom |
95 | |
96 \------------------------------------------------------------*/
97
XpatAllocZoom()98 xpatzoom *XpatAllocZoom ()
99
100 {
101 return ( (xpatzoom *) autalloc( sizeof ( xpatzoom ), 1));
102 }
103
104 /*------------------------------------------------------------\
105 | |
106 | XpatFreeZoom |
107 | |
108 \------------------------------------------------------------*/
109
XpatFreeZoom(FreeZoom)110 void XpatFreeZoom ( FreeZoom )
111
112 xpatzoom *FreeZoom;
113
114 {
115 autfree( (char *)FreeZoom, sizeof(FreeZoom) );
116 }
117
118 /*------------------------------------------------------------\
119 | |
120 | XpatAddZoom |
121 | |
122 \------------------------------------------------------------*/
123
XpatAddZoom()124 void XpatAddZoom ()
125
126 {
127 xpatzoom *XpatZoom;
128
129 autbegin();
130
131 XpatZoom = XpatAllocZoom ();
132 XpatZoom->X = XpatUnitGridX;
133 XpatZoom->Y = XpatUnitGridY;
134 XpatZoom->DX = XpatUnitGridDx;
135 XpatZoom->DY = XpatUnitGridDy;
136 XpatZoom->NEXT = XpatHeadZoom;
137 XpatHeadZoom = XpatZoom;
138
139 autend();
140 }
141
142 /*------------------------------------------------------------\
143 | |
144 | XpatDelZoom |
145 | |
146 \------------------------------------------------------------*/
147
XpatDelZoom()148 char XpatDelZoom()
149
150 {
151 xpatzoom *XpatZoom;
152
153 if ( XpatHeadZoom != (xpatzoom *) NULL )
154 {
155 autbegin();
156
157 XpatZoom = XpatHeadZoom;
158 XpatHeadZoom = XpatHeadZoom->NEXT;
159 XpatFreeZoom( XpatZoom );
160
161 autend();
162 return( XPAT_TRUE );
163 }
164
165 return( XPAT_FALSE );
166 }
167
168 /*------------------------------------------------------------\
169 | |
170 | XpatInitializeZoom |
171 | |
172 \------------------------------------------------------------*/
173
XpatInitializeZoom()174 void XpatInitializeZoom()
175
176 {
177 autbegin();
178
179 while( XpatDelZoom() != XPAT_FALSE );
180
181 if ( XpatComputeBound() == XPAT_FALSE )
182 {
183 XpatInitializeUnitGrid();
184 }
185 else
186 {
187 XpatZoomFit();
188
189 while( XpatDelZoom() != XPAT_FALSE );
190 }
191
192 XpatComputeAndDisplayMap();
193
194 autend();
195 }
196
197 /*------------------------------------------------------------\
198 | |
199 | XpatZoomUndo |
200 | |
201 \------------------------------------------------------------*/
202
XpatZoomUndo()203 void XpatZoomUndo()
204
205 {
206 autbegin();
207
208 if ( XpatHeadZoom == (xpatzoom *)NULL )
209 {
210 XpatErrorMessage( XpatMainWindow, "No previous zoom !" );
211 }
212 else
213 {
214 XpatSetMouseCursor( XpatGraphicWindow, XPAT_WATCH_CURSOR );
215
216 XpatUnitGridX = XpatHeadZoom->X;
217 XpatUnitGridY = XpatHeadZoom->Y;
218 XpatUnitGridDx = XpatHeadZoom->DX;
219 XpatUnitGridDy = XpatHeadZoom->DY;
220
221 XpatComputeUnitGrid();
222 XpatComputeAndDisplayMap();
223
224 XpatDisplayFigure( 0, 0,
225 XpatGraphicDx, XpatGraphicDy );
226
227 XpatRefreshGraphicWindow( 0, 0,
228 XpatGraphicDx, XpatGraphicDy);
229
230 XpatSetMouseCursor( XpatGraphicWindow, XPAT_NORMAL_CURSOR );
231
232 XpatDelZoom();
233 }
234
235 autend();
236 }
237
238 /*------------------------------------------------------------\
239 | |
240 | XpatZoomRight |
241 | |
242 \------------------------------------------------------------*/
243
XpatZoomRight()244 void XpatZoomRight()
245
246 {
247 long Delta;
248 long Offset;
249 long XpatOldPixelGridX;
250
251 autbegin();
252
253 XpatSetMouseCursor( XpatGraphicWindow, XPAT_WATCH_CURSOR );
254
255 Delta = ( XpatPercentMoveX * XpatUnitGridDx ) / 100;
256
257 if ( Delta == 0 ) Delta = 1;
258
259 XpatUnitGridX = XpatUnitGridX + Delta;
260 XpatOldPixelGridX = XpatPixelGridX;
261 XpatPixelGridX = (float)(XpatUnitGridX) * XpatUnitGridStep;
262 Offset = XpatPixelGridX - XpatOldPixelGridX;
263
264 XCopyArea( XpatGraphicDisplay,
265 XpatGraphicPixmap,
266 XpatGraphicPixmap,
267 XpatBackgroundGC,
268 Offset, 0,
269 XpatGraphicDx - Offset,
270 XpatGraphicDy,
271 0, 0
272 );
273
274 XpatComputeAndDisplayMap();
275 XpatDisplayFigure( XpatGraphicDx - Offset, 0,
276 XpatGraphicDx, XpatGraphicDy );
277 XpatRefreshGraphicWindow( 0, 0,
278 XpatGraphicDx, XpatGraphicDy);
279
280 XpatSetMouseCursor( XpatGraphicWindow, XPAT_NORMAL_CURSOR );
281
282 autend();
283 }
284
285 /*------------------------------------------------------------\
286 | |
287 | XpatZoomLeft |
288 | |
289 \------------------------------------------------------------*/
290
XpatZoomLeft()291 void XpatZoomLeft()
292
293 {
294 long Delta;
295 long Offset;
296 long XpatOldPixelGridX;
297
298 autbegin();
299
300 XpatSetMouseCursor( XpatGraphicWindow, XPAT_WATCH_CURSOR );
301
302 Delta = ( XpatPercentMoveX * XpatUnitGridDx ) / 100;
303
304 if ( Delta == 0 ) Delta = 1;
305
306 XpatUnitGridX = XpatUnitGridX - Delta;
307 XpatOldPixelGridX = XpatPixelGridX;
308 XpatPixelGridX = (float)(XpatUnitGridX) * XpatUnitGridStep;
309 Offset = XpatOldPixelGridX - XpatPixelGridX;
310
311 XCopyArea( XpatGraphicDisplay,
312 XpatGraphicPixmap,
313 XpatGraphicPixmap,
314 XpatBackgroundGC,
315 0, 0,
316 XpatGraphicDx - Offset,
317 XpatGraphicDy,
318 Offset, 0
319 );
320
321 XpatComputeAndDisplayMap();
322 XpatDisplayFigure( 0, 0, Offset, XpatGraphicDy );
323 XpatRefreshGraphicWindow( 0, 0, XpatGraphicDx, XpatGraphicDy);
324
325 XpatSetMouseCursor( XpatGraphicWindow, XPAT_NORMAL_CURSOR );
326
327 autend();
328 }
329
330 /*------------------------------------------------------------\
331 | |
332 | XpatZoomDown |
333 | |
334 \------------------------------------------------------------*/
335
XpatZoomDown()336 void XpatZoomDown()
337
338 {
339 long Delta;
340 long Offset;
341 long XpatOldPixelGridY;
342
343 autbegin();
344
345 XpatSetMouseCursor( XpatGraphicWindow, XPAT_WATCH_CURSOR );
346
347 Delta = ( XpatPercentMoveY * XpatUnitGridDy ) / 100;
348
349 if ( Delta == 0 ) Delta = 1;
350
351 XpatUnitGridY = XpatUnitGridY - Delta;
352 XpatOldPixelGridY = XpatPixelGridY;
353 XpatPixelGridY = (float)(XpatUnitGridY) * XpatUnitGridStep;
354 Offset = XpatOldPixelGridY - XpatPixelGridY;
355
356 XCopyArea( XpatGraphicDisplay,
357 XpatGraphicPixmap,
358 XpatGraphicPixmap,
359 XpatBackgroundGC,
360 0, Offset,
361 XpatGraphicDx,
362 XpatGraphicDy - Offset,
363 0, 0
364 );
365
366 XpatComputeAndDisplayMap();
367 XpatDisplayFigure( 0, 0, XpatGraphicDx, Offset );
368 XpatRefreshGraphicWindow( 0, 0, XpatGraphicDx, XpatGraphicDy);
369
370 XpatSetMouseCursor( XpatGraphicWindow, XPAT_NORMAL_CURSOR );
371
372 autend();
373 }
374
375 /*------------------------------------------------------------\
376 | |
377 | XpatZoomUp |
378 | |
379 \------------------------------------------------------------*/
380
XpatZoomUp()381 void XpatZoomUp()
382
383 {
384 long Delta;
385 long Offset;
386 long XpatOldPixelGridY;
387
388 autbegin();
389
390 XpatSetMouseCursor( XpatGraphicWindow, XPAT_WATCH_CURSOR );
391
392 Delta = ( XpatPercentMoveY * XpatUnitGridDy ) / 100;
393
394 if ( Delta == 0 ) Delta = 1;
395
396 XpatUnitGridY = XpatUnitGridY + Delta;
397 XpatOldPixelGridY = XpatPixelGridY;
398 XpatPixelGridY = (float)(XpatUnitGridY) * XpatUnitGridStep;
399 Offset = XpatPixelGridY - XpatOldPixelGridY;
400
401 XCopyArea( XpatGraphicDisplay,
402 XpatGraphicPixmap,
403 XpatGraphicPixmap,
404 XpatBackgroundGC,
405 0, 0,
406 XpatGraphicDx,
407 XpatGraphicDy - Offset,
408 0, Offset
409 );
410
411 XpatComputeAndDisplayMap();
412 XpatDisplayFigure( 0, XpatGraphicDy - Offset,
413 XpatGraphicDx, XpatGraphicDy );
414 XpatRefreshGraphicWindow( 0, 0, XpatGraphicDx, XpatGraphicDy);
415
416 XpatSetMouseCursor( XpatGraphicWindow, XPAT_NORMAL_CURSOR );
417
418 autend();
419 }
420
421 /*------------------------------------------------------------\
422 | |
423 | XpatZoomMore |
424 | |
425 \------------------------------------------------------------*/
426
XpatZoomMore()427 void XpatZoomMore()
428
429 {
430 long DeltaX;
431 long DeltaY;
432
433 autbegin();
434
435 XpatSetMouseCursor( XpatGraphicWindow, XPAT_WATCH_CURSOR );
436
437 DeltaX = ( XpatPercentZoom * XpatUnitGridDx ) / 100;
438 DeltaY = ( XpatPercentZoom * XpatUnitGridDy ) / 100;
439
440 if ( ( DeltaX >= 2 ) &&
441 ( DeltaY >= 2 ) )
442 {
443 XpatAddZoom();
444
445 XpatUnitGridX = XpatUnitGridX + (DeltaX >> 1);
446 XpatUnitGridY = XpatUnitGridY + (DeltaY >> 1);
447 XpatUnitGridDx = XpatUnitGridDx - DeltaX;
448 XpatUnitGridDy = XpatUnitGridDy - DeltaY;
449
450 XpatComputeUnitGrid();
451 XpatComputeAndDisplayMap();
452 XpatDisplayFigure( 0, 0, XpatGraphicDx, XpatGraphicDy );
453 XpatRefreshGraphicWindow( 0, 0, XpatGraphicDx, XpatGraphicDy );
454 }
455
456 XpatSetMouseCursor( XpatGraphicWindow, XPAT_NORMAL_CURSOR );
457
458 autend();
459 }
460
461 /*------------------------------------------------------------\
462 | |
463 | XpatZoomLess |
464 | |
465 \------------------------------------------------------------*/
466
XpatZoomLess()467 void XpatZoomLess()
468
469 {
470 long DeltaX;
471 long DeltaY;
472
473 autbegin();
474
475 XpatSetMouseCursor( XpatGraphicWindow, XPAT_WATCH_CURSOR );
476
477 DeltaX = 100 * XpatUnitGridDx / ( 100 - XpatPercentZoom );
478 DeltaY = 100 * XpatUnitGridDy / ( 100 - XpatPercentZoom );
479
480 XpatAddZoom();
481
482 XpatUnitGridX = XpatUnitGridX - ((DeltaX - XpatUnitGridDx) >> 1);
483 XpatUnitGridY = XpatUnitGridY - ((DeltaY - XpatUnitGridDy) >> 1);
484 XpatUnitGridDx = DeltaX;
485 XpatUnitGridDy = DeltaY;
486
487 XpatComputeUnitGrid();
488 XpatComputeAndDisplayMap();
489 XpatDisplayFigure( 0, 0, XpatGraphicDx, XpatGraphicDy );
490 XpatRefreshGraphicWindow( 0, 0, XpatGraphicDx, XpatGraphicDy );
491
492 XpatSetMouseCursor( XpatGraphicWindow, XPAT_NORMAL_CURSOR );
493
494 autend();
495 }
496
497 /*------------------------------------------------------------\
498 | |
499 | XpatZoomFit |
500 | |
501 \------------------------------------------------------------*/
502
XpatZoomFit()503 void XpatZoomFit()
504
505 {
506 long DeltaX;
507 long DeltaY;
508 long Delta;
509
510 autbegin();
511
512 XpatSetMouseCursor( XpatGraphicWindow, XPAT_WATCH_CURSOR );
513
514 if ( XpatComputeBound() == XPAT_FALSE )
515 {
516 XpatErrorMessage( XpatMainWindow, "No element to display !" );
517 }
518 else
519 {
520 XpatAddZoom();
521
522 XpatUnitGridX = 0;
523 XpatUnitGridY = ( XpatBoundYmin / XPAT_UNIT ) - 1;
524 XpatUnitGridDx = 1;
525 XpatUnitGridDy = XpatBoundYmax / XPAT_UNIT;
526 XpatUnitGridDx = XpatUnitGridDx - XpatUnitGridX + 1;
527 XpatUnitGridDy = XpatUnitGridDy - XpatUnitGridY + 1;
528
529 XpatComputeUnitGrid();
530
531 DeltaX = 5 * XpatUnitGridDx / 4;
532 DeltaY = 5 * XpatUnitGridDy / 4;
533
534 XpatUnitGridX = XpatUnitGridX - ((DeltaX - XpatUnitGridDx) >> 1);
535 XpatUnitGridY = XpatUnitGridY - ((DeltaY - XpatUnitGridDy) >> 1);
536 XpatUnitGridDx = DeltaX;
537 XpatUnitGridDy = DeltaY;
538
539 XpatComputeUnitGrid();
540
541 Delta = ( 3 * XpatUnitGridDx ) / 10;
542
543 if ( Delta == 0 ) Delta = 1;
544
545 XpatUnitGridX = XpatUnitGridX - Delta;
546 XpatPixelGridX = (float)(XpatUnitGridX) * XpatUnitGridStep;
547
548 XpatComputeUnitGrid();
549 XpatComputeAndDisplayMap();
550 XpatDisplayFigure( 0, 0, XpatGraphicDx, XpatGraphicDy );
551 XpatRefreshGraphicWindow( 0, 0, XpatGraphicDx, XpatGraphicDy );
552 }
553
554 XpatSetMouseCursor( XpatGraphicWindow, XPAT_NORMAL_CURSOR );
555
556 autend();
557 }
558
559 /*------------------------------------------------------------\
560 | |
561 | XpatZoomCenter |
562 | |
563 \------------------------------------------------------------*/
564
XpatZoomCenter(UnitX,UnitY)565 void XpatZoomCenter( UnitX, UnitY )
566
567 long UnitX;
568 long UnitY;
569 {
570 autbegin();
571
572 XpatSetMouseCursor( XpatGraphicWindow, XPAT_WATCH_CURSOR );
573
574 XpatUnitGridX = UnitX - ( XpatUnitGridDx >> 1 );
575 XpatUnitGridY = UnitY - ( XpatUnitGridDy >> 1 );
576
577 XpatComputeUnitGrid();
578 XpatComputeAndDisplayMap();
579 XpatDisplayFigure( 0, 0, XpatGraphicDx, XpatGraphicDy );
580 XpatRefreshGraphicWindow( 0, 0, XpatGraphicDx, XpatGraphicDy );
581
582 XpatSetMouseCursor( XpatGraphicWindow, XPAT_NORMAL_CURSOR );
583
584 autend();
585 }
586
587 /*------------------------------------------------------------\
588 | |
589 | XpatZoomIn |
590 | |
591 \------------------------------------------------------------*/
592
XpatZoomIn(UnitX1,UnitY1,UnitX2,UnitY2)593 void XpatZoomIn( UnitX1, UnitY1, UnitX2, UnitY2 )
594
595 long UnitX1;
596 long UnitY1;
597 long UnitX2;
598 long UnitY2;
599 {
600 long Swap;
601
602 autbegin();
603
604 if ( ( UnitX1 != UnitX2 ) &&
605 ( UnitY1 != UnitY2 ) )
606 {
607 if ( UnitX1 > UnitX2 )
608 {
609 Swap = UnitX1; UnitX1 = UnitX2; UnitX2 = Swap;
610 }
611
612 if ( UnitY1 > UnitY2 )
613 {
614 Swap = UnitY1; UnitY1 = UnitY2; UnitY2 = Swap;
615 }
616
617 XpatSetMouseCursor( XpatGraphicWindow, XPAT_WATCH_CURSOR );
618
619 XpatAddZoom();
620
621 XpatUnitGridX = UnitX1;
622 XpatUnitGridY = UnitY1;
623 XpatUnitGridDx = UnitX2 - UnitX1;
624 XpatUnitGridDy = UnitY2 - UnitY1;
625
626 XpatComputeUnitGrid();
627 XpatComputeAndDisplayMap();
628 XpatDisplayFigure( 0, 0, XpatGraphicDx, XpatGraphicDy );
629 XpatRefreshGraphicWindow( 0, 0, XpatGraphicDx, XpatGraphicDy );
630
631 XpatSetMouseCursor( XpatGraphicWindow, XPAT_NORMAL_CURSOR );
632 }
633
634 autend();
635 }
636
637 /*------------------------------------------------------------\
638 | |
639 | XpatZoomPan |
640 | |
641 \------------------------------------------------------------*/
642
XpatZoomPan(UnitX1,UnitY1,UnitX2,UnitY2)643 void XpatZoomPan( UnitX1, UnitY1, UnitX2, UnitY2 )
644
645 long UnitX1;
646 long UnitY1;
647 long UnitX2;
648 long UnitY2;
649 {
650 if ( ( UnitX1 != UnitX2 ) ||
651 ( UnitY1 != UnitY2 ) )
652 {
653 autbegin();
654
655 XpatSetMouseCursor( XpatGraphicWindow, XPAT_WATCH_CURSOR );
656
657 XpatUnitGridX = XpatUnitGridX + ( UnitX1 - UnitX2 );
658 XpatUnitGridY = XpatUnitGridY + ( UnitY1 - UnitY2 );
659
660 XpatComputeUnitGrid();
661 XpatComputeAndDisplayMap();
662 XpatDisplayFigure( 0, 0, XpatGraphicDx, XpatGraphicDy );
663 XpatRefreshGraphicWindow( 0, 0, XpatGraphicDx, XpatGraphicDy );
664
665 XpatSetMouseCursor( XpatGraphicWindow, XPAT_NORMAL_CURSOR );
666
667 autend();
668 }
669 }
670
671 /*------------------------------------------------------------\
672 | |
673 | XpatZoomRefresh |
674 | |
675 \------------------------------------------------------------*/
676
XpatZoomRefresh()677 void XpatZoomRefresh()
678
679 {
680 autbegin();
681
682 XpatSetMouseCursor( XpatGraphicWindow, XPAT_WATCH_CURSOR );
683
684 XpatDisplayFigure( 0, 0, XpatGraphicDx, XpatGraphicDy );
685 XpatRefreshGraphicWindow( 0, 0, XpatGraphicDx, XpatGraphicDy );
686
687 XpatSetMouseCursor( XpatGraphicWindow, XPAT_NORMAL_CURSOR );
688
689 autend();
690 }
691
692 /*------------------------------------------------------------\
693 | |
694 | XpatReScale |
695 | |
696 \------------------------------------------------------------*/
697
XpatReScale(Less)698 void XpatReScale( Less )
699
700 int Less;
701 {
702 double Ratio;
703
704 autbegin();
705
706 Ratio = XpatReScaleFigure( Less );
707
708 XpatBoundYmin *= Ratio;
709 XpatBoundYmax *= Ratio;
710
711 XpatUnitGridY *= Ratio;
712 XpatUnitGridDx = 1;
713 XpatUnitGridDy *= Ratio;
714
715 if ( XpatUnitGridX < 0 ) XpatUnitGridX *= Ratio;
716
717 XpatComputeUnitGrid();
718 XpatComputeAndDisplayMap();
719 XpatZoomRefresh();
720
721 autend();
722 }
723