/alliance-5.0/graal/src/GMX_cursor.c

https://github.com/clothbot/Alliance-VLSI-CAD-System · C · 534 lines · 317 code · 105 blank · 112 comment · 45 complexity · e7b452d19244da3a03bb9f077db9631c 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 : GRAAL |
  30. | |
  31. | File : Cursor.c |
  32. | |
  33. | Author : Jacomme Ludovic |
  34. | |
  35. | Date : 28.03.95 |
  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 "mph.h"
  49. # include "rds.h"
  50. # include "rpr.h"
  51. # include "GSB.h"
  52. # include "GMX.h"
  53. # include "GMX_view.h"
  54. # include "GMX_grid.h"
  55. # include "GMX_cursor.h"
  56. /*------------------------------------------------------------\
  57. | |
  58. | Constants |
  59. | |
  60. \------------------------------------------------------------*/
  61. /*------------------------------------------------------------\
  62. | |
  63. | Types |
  64. | |
  65. \------------------------------------------------------------*/
  66. /*------------------------------------------------------------\
  67. | |
  68. | Variables |
  69. | |
  70. \------------------------------------------------------------*/
  71. /*------------------------------------------------------------\
  72. | |
  73. | Buffer |
  74. | |
  75. \------------------------------------------------------------*/
  76. static char GraalCursorBuffer[ GRAAL_MAX_CURSOR_BUFFER ];
  77. /*------------------------------------------------------------\
  78. | |
  79. | Coordinates |
  80. | |
  81. \------------------------------------------------------------*/
  82. Position GraalCursorX = 0;
  83. Position GraalCursorY = 0;
  84. Position GraalCursorSaveX = 0;
  85. Position GraalCursorSaveY = 0;
  86. char GraalCursorSaved = GRAAL_FALSE;
  87. char GraalCursorInside = GRAAL_FALSE;
  88. char GraalCursorType = GRAAL_INPUT_HALF_BOX;
  89. long GraalLambdaCursorX = 0;
  90. long GraalLambdaCursorY = 0;
  91. long GraalPixelCursorX = 0;
  92. long GraalPixelCursorY = 0;
  93. long GraalLambdaCursorSaveX[ 2 ] = { 0, 0 };
  94. long GraalLambdaCursorSaveY[ 2 ] = { 0, 0 };
  95. char GraalCursorIndex = 0;
  96. /*------------------------------------------------------------\
  97. | |
  98. | Functions |
  99. | |
  100. \------------------------------------------------------------*/
  101. /*------------------------------------------------------------\
  102. | |
  103. | GraalComputeCursor |
  104. | |
  105. \------------------------------------------------------------*/
  106. void GraalComputeCursor( X, Y )
  107. Position X;
  108. Position Y;
  109. {
  110. rdsbegin();
  111. Y = GraalGraphicDy - Y;
  112. GraalLambdaCursorX = X + GraalPixelGridX;
  113. GraalLambdaCursorY = Y + GraalPixelGridY;
  114. if ( GraalLambdaCursorX < 0 )
  115. {
  116. GraalLambdaCursorX = ((float)(GraalLambdaCursorX) / GraalLambdaGridStep) - 0.5 ;
  117. }
  118. else
  119. {
  120. GraalLambdaCursorX = ((float)(GraalLambdaCursorX) / GraalLambdaGridStep) + 0.5 ;
  121. }
  122. if ( GraalLambdaCursorY < 0 )
  123. {
  124. GraalLambdaCursorY = ((float)(GraalLambdaCursorY) / GraalLambdaGridStep) - 0.5 ;
  125. }
  126. else
  127. {
  128. GraalLambdaCursorY = ((float)(GraalLambdaCursorY) / GraalLambdaGridStep) + 0.5 ;
  129. }
  130. GraalPixelCursorX = ((float)(GraalLambdaCursorX) * GraalLambdaGridStep);
  131. GraalPixelCursorY = ((float)(GraalLambdaCursorY) * GraalLambdaGridStep);
  132. GraalCursorX = GraalPixelCursorX - GraalPixelGridX;
  133. GraalCursorY = GraalPixelCursorY - GraalPixelGridY;
  134. GraalCursorY = GraalGraphicDy - GraalCursorY;
  135. rdsend();
  136. }
  137. /*------------------------------------------------------------\
  138. | |
  139. | GraalDisplayCoordinates |
  140. | |
  141. \------------------------------------------------------------*/
  142. void GraalDisplayCoordinates()
  143. {
  144. rdsbegin();
  145. sprintf( GraalCursorBuffer, "%.2f", (float)GraalLambdaCursorX / (float)GRAAL_SCALE );
  146. GraalDisplayMessage( GRAAL_MESSAGE_X, GraalCursorBuffer );
  147. sprintf( GraalCursorBuffer, "%.2f", (float)GraalLambdaCursorY / (float)GRAAL_SCALE );
  148. GraalDisplayMessage( GRAAL_MESSAGE_Y, GraalCursorBuffer );
  149. sprintf( GraalCursorBuffer, "%.2f",
  150. (float)( GraalLambdaCursorX - GraalLambdaCursorSaveX[0] ) / (float)GRAAL_SCALE );
  151. GraalDisplayMessage( GRAAL_MESSAGE_DX, GraalCursorBuffer );
  152. sprintf( GraalCursorBuffer, "%.2f",
  153. (float)( GraalLambdaCursorY - GraalLambdaCursorSaveY[0] ) / (float)GRAAL_SCALE );
  154. GraalDisplayMessage( GRAAL_MESSAGE_DY, GraalCursorBuffer );
  155. rdsend();
  156. }
  157. /*------------------------------------------------------------\
  158. | |
  159. | GraalPointCursor |
  160. | |
  161. \------------------------------------------------------------*/
  162. void GraalPointCursor()
  163. {
  164. rdsbegin();
  165. GraalUndisplayCursor();
  166. GraalLambdaCursorSaveX[ GraalCursorIndex ] = GraalLambdaCursorX;
  167. GraalLambdaCursorSaveY[ GraalCursorIndex ] = GraalLambdaCursorY;
  168. GraalCursorIndex = GraalCursorIndex + 1;
  169. GraalDisplayCursor();
  170. rdsend();
  171. }
  172. /*------------------------------------------------------------\
  173. | |
  174. | GraalResetCursor |
  175. | |
  176. \------------------------------------------------------------*/
  177. void GraalResetCursor()
  178. {
  179. rdsbegin();
  180. GraalUndisplayCursor();
  181. GraalCursorIndex = GraalCursorIndex - 1;
  182. GraalDisplayCursor();
  183. rdsend();
  184. }
  185. /*------------------------------------------------------------\
  186. | |
  187. | GraalChangeCursor |
  188. | |
  189. \------------------------------------------------------------*/
  190. void GraalChangeCursorType( ArrayX, ArrayY, Index, Type )
  191. long *ArrayX;
  192. long *ArrayY;
  193. char Index;
  194. char Type;
  195. {
  196. rdsbegin();
  197. GraalUndisplayCursor();
  198. GraalCursorType = Type;
  199. GraalCursorIndex = Index;
  200. if ( Index != 0 )
  201. {
  202. GraalLambdaCursorSaveX[ 0 ] = ArrayX[0];
  203. GraalLambdaCursorSaveY[ 0 ] = ArrayY[0];
  204. GraalLambdaCursorSaveX[ 1 ] = ArrayX[1];
  205. GraalLambdaCursorSaveY[ 1 ] = ArrayY[1];
  206. }
  207. GraalDisplayCursor();
  208. rdsend();
  209. }
  210. /*------------------------------------------------------------\
  211. | |
  212. | GraalDrawCursor |
  213. | |
  214. \------------------------------------------------------------*/
  215. void GraalDrawCursor()
  216. {
  217. long X1;
  218. long Y1;
  219. long X2;
  220. long Y2;
  221. long DeltaX;
  222. long DeltaY;
  223. long Swap;
  224. char DrawLine;
  225. rdsbegin();
  226. XDrawLine( GraalGraphicDisplay,
  227. XtWindow( GraalGraphicWindow ),
  228. GraalXorGC,
  229. GraalCursorSaveX - GRAAL_CURSOR_SIZE,
  230. GraalCursorSaveY - GRAAL_CURSOR_SIZE,
  231. GraalCursorSaveX + GRAAL_CURSOR_SIZE,
  232. GraalCursorSaveY + GRAAL_CURSOR_SIZE );
  233. XDrawLine( GraalGraphicDisplay,
  234. XtWindow( GraalGraphicWindow ),
  235. GraalXorGC,
  236. GraalCursorSaveX - GRAAL_CURSOR_SIZE,
  237. GraalCursorSaveY + GRAAL_CURSOR_SIZE,
  238. GraalCursorSaveX + GRAAL_CURSOR_SIZE,
  239. GraalCursorSaveY - GRAAL_CURSOR_SIZE );
  240. if ( GraalCursorIndex > 0 )
  241. {
  242. X1 = (float)(GraalLambdaCursorSaveX[0]) * GraalLambdaGridStep;
  243. Y1 = (float)(GraalLambdaCursorSaveY[0]) * GraalLambdaGridStep;
  244. X1 = X1 - GraalPixelGridX;
  245. Y1 = Y1 - GraalPixelGridY;
  246. Y1 = GraalGraphicDy - Y1;
  247. if ( GraalCursorIndex == 1 )
  248. {
  249. X2 = GraalCursorSaveX;
  250. Y2 = GraalCursorSaveY;
  251. }
  252. else
  253. {
  254. X2 = (float)(GraalLambdaCursorSaveX[1]) * GraalLambdaGridStep;
  255. Y2 = (float)(GraalLambdaCursorSaveY[1]) * GraalLambdaGridStep;
  256. X2 = X2 - GraalPixelGridX;
  257. Y2 = Y2 - GraalPixelGridY;
  258. Y2 = GraalGraphicDy - Y2;
  259. }
  260. switch( GraalCursorType )
  261. {
  262. case GRAAL_INPUT_POINT :
  263. break;
  264. case GRAAL_INPUT_LINE :
  265. XDrawLine( GraalGraphicDisplay,
  266. XtWindow( GraalGraphicWindow ),
  267. GraalXorGC,
  268. X1, Y1, X2, Y2 );
  269. break;
  270. case GRAAL_INPUT_HALF_BOX :
  271. XDrawLine( GraalGraphicDisplay,
  272. XtWindow( GraalGraphicWindow ),
  273. GraalXorGC,
  274. X1, Y1, X2, Y1 );
  275. XDrawLine( GraalGraphicDisplay,
  276. XtWindow( GraalGraphicWindow ),
  277. GraalXorGC,
  278. X2, Y1, X2, Y2 );
  279. break;
  280. case GRAAL_INPUT_ORTHO :
  281. case GRAAL_INPUT_SORTHO :
  282. case GRAAL_INPUT_LSTRING :
  283. DeltaX = X2 - X1; if ( DeltaX < 0 ) DeltaX = - DeltaX;
  284. DeltaY = Y2 - Y1; if ( DeltaY < 0 ) DeltaY = - DeltaY;
  285. if ( DeltaX > DeltaY )
  286. {
  287. Y2 = Y1;
  288. if ( X1 > X2 ) { Swap = X1; X1 = X2; X2 = Swap; }
  289. if ( X1 < 0 ) X1 = 0;
  290. if ( X2 > GraalGraphicDx ) X2 = GraalGraphicDx;
  291. if ( ( X1 < X2 ) &&
  292. ( Y1 >= 0 ) &&
  293. ( Y1 <= GraalGraphicDy ) )
  294. {
  295. XDrawLine( GraalGraphicDisplay,
  296. XtWindow( GraalGraphicWindow ),
  297. GraalXorGC,
  298. X1, Y1, X2, Y2 );
  299. }
  300. }
  301. else
  302. {
  303. X2 = X1;
  304. if ( Y1 > Y2 ) { Swap = Y1; Y1 = Y2; Y2 = Swap; }
  305. if ( Y1 < 0 ) Y1 = 0;
  306. if ( Y2 > GraalGraphicDy ) Y2 = GraalGraphicDy;
  307. if ( ( Y1 < Y2 ) &&
  308. ( X1 >= 0 ) &&
  309. ( X1 <= GraalGraphicDx ) )
  310. {
  311. XDrawLine( GraalGraphicDisplay,
  312. XtWindow( GraalGraphicWindow ),
  313. GraalXorGC,
  314. X1, Y1, X2, Y2 );
  315. }
  316. }
  317. break;
  318. case GRAAL_INPUT_BOX :
  319. if ( X1 > X2 ) { Swap = X1; X1 = X2; X2 = Swap; }
  320. if ( Y1 > Y2 ) { Swap = Y1; Y1 = Y2; Y2 = Swap; }
  321. DrawLine = 0;
  322. if ( X1 < 0 )
  323. {
  324. X1 = 0; DrawLine |= GRAAL_WEST_MASK;
  325. }
  326. if ( X2 > GraalGraphicDx )
  327. {
  328. X2 = GraalGraphicDx; DrawLine |= GRAAL_EAST_MASK;
  329. }
  330. if ( Y1 < 0 )
  331. {
  332. Y1 = 0; DrawLine |= GRAAL_SOUTH_MASK;
  333. }
  334. if ( Y2 > GraalGraphicDy )
  335. {
  336. Y2 = GraalGraphicDy; DrawLine |= GRAAL_NORTH_MASK;
  337. }
  338. if ( DrawLine == 0 )
  339. {
  340. XDrawRectangle( GraalGraphicDisplay,
  341. XtWindow( GraalGraphicWindow ),
  342. GraalXorGC,
  343. X1, Y1,
  344. X2 - X1, Y2 - Y1 );
  345. }
  346. else
  347. {
  348. if ( ( DrawLine & GRAAL_WEST_MASK ) == 0 )
  349. {
  350. XDrawLine( GraalGraphicDisplay,
  351. XtWindow( GraalGraphicWindow ),
  352. GraalXorGC,
  353. X1, Y2,
  354. X1, Y1 );
  355. }
  356. if ( ( DrawLine & GRAAL_EAST_MASK ) == 0 )
  357. {
  358. XDrawLine( GraalGraphicDisplay,
  359. XtWindow( GraalGraphicWindow ),
  360. GraalXorGC,
  361. X2, Y2,
  362. X2, Y1 );
  363. }
  364. if ( ( DrawLine & GRAAL_SOUTH_MASK ) == 0 )
  365. {
  366. XDrawLine( GraalGraphicDisplay,
  367. XtWindow( GraalGraphicWindow ),
  368. GraalXorGC,
  369. X1, Y1,
  370. X2, Y1 );
  371. }
  372. if ( ( DrawLine & GRAAL_NORTH_MASK ) == 0 )
  373. {
  374. XDrawLine( GraalGraphicDisplay,
  375. XtWindow( GraalGraphicWindow ),
  376. GraalXorGC,
  377. X1, Y2,
  378. X2, Y2 );
  379. }
  380. }
  381. break;
  382. }
  383. }
  384. rdsend();
  385. }
  386. /*------------------------------------------------------------\
  387. | |
  388. | GraalUndisplayCursor |
  389. | |
  390. \------------------------------------------------------------*/
  391. void GraalUndisplayCursor()
  392. {
  393. rdsbegin();
  394. if ( GraalCursorInside == GRAAL_TRUE )
  395. {
  396. if ( GraalCursorSaved == GRAAL_TRUE )
  397. {
  398. GraalDrawCursor();
  399. }
  400. GraalCursorSaved = GRAAL_FALSE;
  401. }
  402. rdsend();
  403. }
  404. /*------------------------------------------------------------\
  405. | |
  406. | GraalDisplayCursor |
  407. | |
  408. \------------------------------------------------------------*/
  409. void GraalDisplayCursor()
  410. {
  411. rdsbegin();
  412. if ( GraalCursorInside == GRAAL_TRUE )
  413. {
  414. if ( GraalCursorSaved == GRAAL_TRUE )
  415. {
  416. GraalDrawCursor();
  417. GraalCursorSaved = GRAAL_FALSE;
  418. }
  419. if ( ( GraalCursorY >= 0 ) &&
  420. ( GraalCursorX <= GraalGraphicDx ) )
  421. {
  422. GraalCursorSaveX = GraalCursorX;
  423. GraalCursorSaveY = GraalCursorY;
  424. GraalDrawCursor();
  425. GraalCursorSaved = GRAAL_TRUE;
  426. }
  427. }
  428. rdsend();
  429. }