/alliance-5.0/xpat/src/XMX_cursor.c

https://github.com/clothbot/Alliance-VLSI-CAD-System · C · 575 lines · 353 code · 110 blank · 112 comment · 53 complexity · ffc933e731fd9f2ad2279ece9f60d0a9 MD5 · raw file

  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. | 675 Mass Ave, Cambridge, MA 02139, USA. |
  25. | |
  26. \------------------------------------------------------------*/
  27. /*------------------------------------------------------------\
  28. | |
  29. | Tool : XPAT |
  30. | |
  31. | File : Cursor.c |
  32. | |
  33. | Authors : Jacomme Ludovic |
  34. | |
  35. | Date : 04.12.96 |
  36. | |
  37. \------------------------------------------------------------*/
  38. /*------------------------------------------------------------\
  39. | |
  40. | Include Files |
  41. | |
  42. \------------------------------------------------------------*/
  43. # include <stdio.h>
  44. # include <X11/Intrinsic.h>
  45. # include <X11/StringDefs.h>
  46. # include <Xm/Xm.h>
  47. # include "mut.h"
  48. # include "aut.h"
  49. # include "pat.h"
  50. # include "XSB.h"
  51. # include "XPT.h"
  52. # include "XMX.h"
  53. # include "XMX_grid.h"
  54. # include "XMX_cursor.h"
  55. /*------------------------------------------------------------\
  56. | |
  57. | Constants |
  58. | |
  59. \------------------------------------------------------------*/
  60. /*------------------------------------------------------------\
  61. | |
  62. | Types |
  63. | |
  64. \------------------------------------------------------------*/
  65. /*------------------------------------------------------------\
  66. | |
  67. | Variables |
  68. | |
  69. \------------------------------------------------------------*/
  70. /*------------------------------------------------------------\
  71. | |
  72. | Buffer |
  73. | |
  74. \------------------------------------------------------------*/
  75. static char XpatCursorBuffer[ XPAT_MAX_CURSOR_BUFFER ];
  76. char *XpatTimeUnit[ PAT_TU__MS + 1 ] =
  77. {
  78. "vu",
  79. "fs",
  80. "ps",
  81. "ns",
  82. "us",
  83. "ms"
  84. };
  85. /*------------------------------------------------------------\
  86. | |
  87. | Coordinates |
  88. | |
  89. \------------------------------------------------------------*/
  90. Position XpatCursorX = 0;
  91. Position XpatCursorY = 0;
  92. Position XpatCursorSaveX = 0;
  93. Position XpatCursorSaveY = 0;
  94. char XpatCursorSaved = XPAT_FALSE;
  95. char XpatCursorInside = XPAT_FALSE;
  96. char XpatCursorType = XPAT_INPUT_HALF_BOX;
  97. long XpatUnitCursorX = 0;
  98. long XpatUnitCursorY = 0;
  99. long XpatPixelCursorX = 0;
  100. long XpatPixelCursorY = 0;
  101. long XpatUnitCursorSaveX[ 2 ] = { 0, 0 };
  102. long XpatUnitCursorSaveY[ 2 ] = { 0, 0 };
  103. char XpatCursorIndex = 0;
  104. /*------------------------------------------------------------\
  105. | |
  106. | Functions |
  107. | |
  108. \------------------------------------------------------------*/
  109. /*------------------------------------------------------------\
  110. | |
  111. | XpatComputeCursor |
  112. | |
  113. \------------------------------------------------------------*/
  114. void XpatComputeCursor( X, Y )
  115. Position X;
  116. Position Y;
  117. {
  118. autbegin();
  119. Y = XpatGraphicDy - Y;
  120. XpatUnitCursorX = X + XpatPixelGridX;
  121. XpatUnitCursorY = Y + XpatPixelGridY;
  122. if ( XpatUnitCursorX < 0 )
  123. {
  124. XpatUnitCursorX = ((float)(XpatUnitCursorX) / XpatUnitGridStep) - 0.5 ;
  125. }
  126. else
  127. {
  128. XpatUnitCursorX = ((float)(XpatUnitCursorX) / XpatUnitGridStep) + 0.5 ;
  129. }
  130. if ( XpatUnitCursorY < 0 )
  131. {
  132. XpatUnitCursorY = ((float)(XpatUnitCursorY) / XpatUnitGridStep) - 0.5 ;
  133. }
  134. else
  135. {
  136. XpatUnitCursorY = ((float)(XpatUnitCursorY) / XpatUnitGridStep) + 0.5 ;
  137. }
  138. XpatPixelCursorX = ((float)(XpatUnitCursorX) * XpatUnitGridStep);
  139. XpatPixelCursorY = ((float)(XpatUnitCursorY) * XpatUnitGridStep);
  140. XpatCursorX = XpatPixelCursorX - XpatPixelGridX;
  141. XpatCursorY = XpatPixelCursorY - XpatPixelGridY;
  142. XpatCursorY = XpatGraphicDy - XpatCursorY;
  143. autend();
  144. }
  145. /*------------------------------------------------------------\
  146. | |
  147. | XpatDisplayCoordinates |
  148. | |
  149. \------------------------------------------------------------*/
  150. void XpatDisplayCoordinates()
  151. {
  152. char **NameArray;
  153. long NumberIO;
  154. char *NameX;
  155. char *NameY;
  156. int Unit;
  157. long X;
  158. long Y;
  159. long Dx;
  160. long Dy;
  161. long TimeDelta;
  162. autbegin();
  163. X = XpatUnitCursorX / XPAT_PATTERN_STEP_X;
  164. Y = XpatUnitCursorY / XPAT_PATTERN_STEP_Y;
  165. Dx = X - ( XpatUnitCursorSaveX[0] / XPAT_PATTERN_STEP_X );
  166. Dy = Y - ( XpatUnitCursorSaveX[1] / XPAT_PATTERN_STEP_Y );
  167. NameX = (char *)0;
  168. NameY = (char *)0;
  169. if ( XpatFigurePat != (patfig_list *)0 )
  170. {
  171. NameArray = XpatFigurePat->IO_NAME_ARRAY;
  172. NumberIO = XpatFigurePat->IO_NUMBER;
  173. if ( ( Y < NumberIO ) &&
  174. ( Y >= 0 ) )
  175. {
  176. NameY = NameArray[ Y ];;
  177. }
  178. }
  179. if ( NameY == (char *)0 ) XpatCursorBuffer[ 0 ] = '\0';
  180. else sprintf( XpatCursorBuffer, "%s", NameY );
  181. XpatDisplayMessage( XPAT_MESSAGE_Y, XpatCursorBuffer );
  182. if ( XpatFigurePat != (patfig_list *)0 )
  183. {
  184. Unit = XpatFigurePat->TIME_UNIT;
  185. TimeDelta = XpatFigurePat->TIME_DELTA;
  186. }
  187. else
  188. {
  189. Unit = 0;
  190. TimeDelta = 1;
  191. }
  192. sprintf( XpatCursorBuffer, "%ld %s", X * TimeDelta, XpatTimeUnit[ Unit ] );
  193. XpatDisplayMessage( XPAT_MESSAGE_X, XpatCursorBuffer );
  194. sprintf( XpatCursorBuffer, "%ld %s", Dx * TimeDelta, XpatTimeUnit[ Unit ] );
  195. XpatDisplayMessage( XPAT_MESSAGE_DX, XpatCursorBuffer );
  196. autend();
  197. }
  198. /*------------------------------------------------------------\
  199. | |
  200. | XpatPointCursor |
  201. | |
  202. \------------------------------------------------------------*/
  203. void XpatPointCursor()
  204. {
  205. autbegin();
  206. XpatUndisplayCursor();
  207. XpatUnitCursorSaveX[ XpatCursorIndex ] = XpatUnitCursorX;
  208. XpatUnitCursorSaveY[ XpatCursorIndex ] = XpatUnitCursorY;
  209. XpatCursorIndex = XpatCursorIndex + 1;
  210. XpatDisplayCursor();
  211. autend();
  212. }
  213. /*------------------------------------------------------------\
  214. | |
  215. | XpatResetCursor |
  216. | |
  217. \------------------------------------------------------------*/
  218. void XpatResetCursor()
  219. {
  220. autbegin();
  221. XpatUndisplayCursor();
  222. XpatCursorIndex = XpatCursorIndex - 1;
  223. XpatDisplayCursor();
  224. autend();
  225. }
  226. /*------------------------------------------------------------\
  227. | |
  228. | XpatChangeCursor |
  229. | |
  230. \------------------------------------------------------------*/
  231. void XpatChangeCursorType( ArrayX, ArrayY, Index, Type )
  232. long *ArrayX;
  233. long *ArrayY;
  234. char Index;
  235. char Type;
  236. {
  237. autbegin();
  238. XpatUndisplayCursor();
  239. XpatCursorType = Type;
  240. XpatCursorIndex = Index;
  241. if ( Index != 0 )
  242. {
  243. XpatUnitCursorSaveX[ 0 ] = ArrayX[0];
  244. XpatUnitCursorSaveY[ 0 ] = ArrayY[0];
  245. XpatUnitCursorSaveX[ 1 ] = ArrayX[1];
  246. XpatUnitCursorSaveY[ 1 ] = ArrayY[1];
  247. }
  248. XpatDisplayCursor();
  249. autend();
  250. }
  251. /*------------------------------------------------------------\
  252. | |
  253. | XpatDrawCursor |
  254. | |
  255. \------------------------------------------------------------*/
  256. void XpatDrawCursor()
  257. {
  258. long X1;
  259. long Y1;
  260. long X2;
  261. long Y2;
  262. long DeltaX;
  263. long DeltaY;
  264. long Swap;
  265. char DrawLine;
  266. autbegin();
  267. XDrawLine( XpatGraphicDisplay,
  268. XtWindow( XpatGraphicWindow ),
  269. XpatXorGC,
  270. XpatCursorSaveX - XPAT_CURSOR_SIZE,
  271. XpatCursorSaveY - XPAT_CURSOR_SIZE,
  272. XpatCursorSaveX + XPAT_CURSOR_SIZE,
  273. XpatCursorSaveY + XPAT_CURSOR_SIZE );
  274. XDrawLine( XpatGraphicDisplay,
  275. XtWindow( XpatGraphicWindow ),
  276. XpatXorGC,
  277. XpatCursorSaveX - XPAT_CURSOR_SIZE,
  278. XpatCursorSaveY + XPAT_CURSOR_SIZE,
  279. XpatCursorSaveX + XPAT_CURSOR_SIZE,
  280. XpatCursorSaveY - XPAT_CURSOR_SIZE );
  281. if ( XpatCursorIndex > 0 )
  282. {
  283. X1 = (float)(XpatUnitCursorSaveX[0]) * XpatUnitGridStep;
  284. Y1 = (float)(XpatUnitCursorSaveY[0]) * XpatUnitGridStep;
  285. X1 = X1 - XpatPixelGridX;
  286. Y1 = Y1 - XpatPixelGridY;
  287. Y1 = XpatGraphicDy - Y1;
  288. if ( XpatCursorIndex == 1 )
  289. {
  290. X2 = XpatCursorSaveX;
  291. Y2 = XpatCursorSaveY;
  292. }
  293. else
  294. {
  295. X2 = (float)(XpatUnitCursorSaveX[1]) * XpatUnitGridStep;
  296. Y2 = (float)(XpatUnitCursorSaveY[1]) * XpatUnitGridStep;
  297. X2 = X2 - XpatPixelGridX;
  298. Y2 = Y2 - XpatPixelGridY;
  299. Y2 = XpatGraphicDy - Y2;
  300. }
  301. switch( XpatCursorType )
  302. {
  303. case XPAT_INPUT_POINT :
  304. break;
  305. case XPAT_INPUT_LINE :
  306. XDrawLine( XpatGraphicDisplay,
  307. XtWindow( XpatGraphicWindow ),
  308. XpatXorGC,
  309. X1, Y1, X2, Y2 );
  310. break;
  311. case XPAT_INPUT_HALF_BOX :
  312. XDrawLine( XpatGraphicDisplay,
  313. XtWindow( XpatGraphicWindow ),
  314. XpatXorGC,
  315. X1, Y1, X2, Y1 );
  316. XDrawLine( XpatGraphicDisplay,
  317. XtWindow( XpatGraphicWindow ),
  318. XpatXorGC,
  319. X2, 0, X2, XpatGraphicDy );
  320. break;
  321. case XPAT_INPUT_ORTHO :
  322. case XPAT_INPUT_SORTHO :
  323. case XPAT_INPUT_LSTRING :
  324. DeltaX = X2 - X1; if ( DeltaX < 0 ) DeltaX = - DeltaX;
  325. DeltaY = Y2 - Y1; if ( DeltaY < 0 ) DeltaY = - DeltaY;
  326. if ( DeltaX > DeltaY )
  327. {
  328. Y2 = Y1;
  329. if ( X1 > X2 ) { Swap = X1; X1 = X2; X2 = Swap; }
  330. if ( X1 < 0 ) X1 = 0;
  331. if ( X2 > XpatGraphicDx ) X2 = XpatGraphicDx;
  332. if ( ( X1 < X2 ) &&
  333. ( Y1 >= 0 ) &&
  334. ( Y1 <= XpatGraphicDy ) )
  335. {
  336. XDrawLine( XpatGraphicDisplay,
  337. XtWindow( XpatGraphicWindow ),
  338. XpatXorGC,
  339. X1, Y1, X2, Y2 );
  340. }
  341. }
  342. else
  343. {
  344. X2 = X1;
  345. if ( Y1 > Y2 ) { Swap = Y1; Y1 = Y2; Y2 = Swap; }
  346. if ( Y1 < 0 ) Y1 = 0;
  347. if ( Y2 > XpatGraphicDy ) Y2 = XpatGraphicDy;
  348. if ( ( Y1 < Y2 ) &&
  349. ( X1 >= 0 ) &&
  350. ( X1 <= XpatGraphicDx ) )
  351. {
  352. XDrawLine( XpatGraphicDisplay,
  353. XtWindow( XpatGraphicWindow ),
  354. XpatXorGC,
  355. X1, Y1, X2, Y2 );
  356. }
  357. }
  358. break;
  359. case XPAT_INPUT_BOX :
  360. if ( X1 > X2 ) { Swap = X1; X1 = X2; X2 = Swap; }
  361. if ( Y1 > Y2 ) { Swap = Y1; Y1 = Y2; Y2 = Swap; }
  362. DrawLine = 0;
  363. if ( X1 < 0 ) { X1 = 0; DrawLine |= XPAT_WEST; }
  364. if ( X2 > XpatGraphicDx ) { X2 = XpatGraphicDx; DrawLine |= XPAT_EAST; }
  365. if ( Y1 < 0 ) { Y1 = 0; DrawLine |= XPAT_SOUTH; }
  366. if ( Y2 > XpatGraphicDy ) { Y2 = XpatGraphicDy; DrawLine |= XPAT_NORTH; }
  367. if ( DrawLine == 0 )
  368. {
  369. XDrawRectangle( XpatGraphicDisplay,
  370. XtWindow( XpatGraphicWindow ),
  371. XpatXorGC,
  372. X1, Y1,
  373. X2 - X1, Y2 - Y1 );
  374. }
  375. else
  376. {
  377. if ( ( DrawLine & XPAT_WEST ) == 0 )
  378. {
  379. XDrawLine( XpatGraphicDisplay,
  380. XtWindow( XpatGraphicWindow ),
  381. XpatXorGC,
  382. X1, Y2,
  383. X1, Y1 );
  384. }
  385. if ( ( DrawLine & XPAT_EAST ) == 0 )
  386. {
  387. XDrawLine( XpatGraphicDisplay,
  388. XtWindow( XpatGraphicWindow ),
  389. XpatXorGC,
  390. X2, Y2,
  391. X2, Y1 );
  392. }
  393. if ( ( DrawLine & XPAT_SOUTH ) == 0 )
  394. {
  395. XDrawLine( XpatGraphicDisplay,
  396. XtWindow( XpatGraphicWindow ),
  397. XpatXorGC,
  398. X1, Y1,
  399. X2, Y1 );
  400. }
  401. if ( ( DrawLine & XPAT_NORTH ) == 0 )
  402. {
  403. XDrawLine( XpatGraphicDisplay,
  404. XtWindow( XpatGraphicWindow ),
  405. XpatXorGC,
  406. X1, Y2,
  407. X2, Y2 );
  408. }
  409. }
  410. break;
  411. }
  412. }
  413. else
  414. {
  415. XDrawLine( XpatGraphicDisplay,
  416. XtWindow( XpatGraphicWindow ),
  417. XpatXorGC,
  418. XpatCursorSaveX, 0, XpatCursorSaveX, XpatGraphicDy );
  419. }
  420. autend();
  421. }
  422. /*------------------------------------------------------------\
  423. | |
  424. | XpatUndisplayCursor |
  425. | |
  426. \------------------------------------------------------------*/
  427. void XpatUndisplayCursor()
  428. {
  429. autbegin();
  430. if ( XpatCursorInside == XPAT_TRUE )
  431. {
  432. if ( XpatCursorSaved == XPAT_TRUE )
  433. {
  434. XpatDrawCursor();
  435. }
  436. XpatCursorSaved = XPAT_FALSE;
  437. }
  438. autend();
  439. }
  440. /*------------------------------------------------------------\
  441. | |
  442. | XpatDisplayCursor |
  443. | |
  444. \------------------------------------------------------------*/
  445. void XpatDisplayCursor()
  446. {
  447. autbegin();
  448. if ( XpatCursorInside == XPAT_TRUE )
  449. {
  450. if ( XpatCursorSaved == XPAT_TRUE )
  451. {
  452. XpatDrawCursor();
  453. XpatCursorSaved = XPAT_FALSE;
  454. }
  455. if ( ( XpatCursorY >= 0 ) &&
  456. ( XpatCursorX <= XpatGraphicDx ) )
  457. {
  458. XpatCursorSaveX = XpatCursorX;
  459. XpatCursorSaveY = XpatCursorY;
  460. XpatDrawCursor();
  461. XpatCursorSaved = XPAT_TRUE;
  462. }
  463. }
  464. autend();
  465. }