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

https://github.com/clothbot/Alliance-VLSI-CAD-System · C · 514 lines · 300 code · 102 blank · 112 comment · 45 complexity · e5df8543325ea9f3a9e14cf957df795e 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 support : mailto:alliance-support@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 : XGRA |
  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 "XSB.h"
  50. # include "XMX.h"
  51. # include "XMX_grid.h"
  52. # include "XMX_cursor.h"
  53. /*------------------------------------------------------------\
  54. | |
  55. | Constants |
  56. | |
  57. \------------------------------------------------------------*/
  58. /*------------------------------------------------------------\
  59. | |
  60. | Types |
  61. | |
  62. \------------------------------------------------------------*/
  63. /*------------------------------------------------------------\
  64. | |
  65. | Variables |
  66. | |
  67. \------------------------------------------------------------*/
  68. /*------------------------------------------------------------\
  69. | |
  70. | Buffer |
  71. | |
  72. \------------------------------------------------------------*/
  73. static char XgraCursorBuffer[ XGRA_MAX_CURSOR_BUFFER ];
  74. /*------------------------------------------------------------\
  75. | |
  76. | Coordinates |
  77. | |
  78. \------------------------------------------------------------*/
  79. Position XgraCursorX = 0;
  80. Position XgraCursorY = 0;
  81. Position XgraCursorSaveX = 0;
  82. Position XgraCursorSaveY = 0;
  83. char XgraCursorSaved = XGRA_FALSE;
  84. char XgraCursorInside = XGRA_FALSE;
  85. char XgraCursorType = XGRA_INPUT_HALF_BOX;
  86. long XgraUnitCursorX = 0;
  87. long XgraUnitCursorY = 0;
  88. long XgraPixelCursorX = 0;
  89. long XgraPixelCursorY = 0;
  90. long XgraUnitCursorSaveX[ 2 ] = { 0, 0 };
  91. long XgraUnitCursorSaveY[ 2 ] = { 0, 0 };
  92. char XgraCursorIndex = 0;
  93. /*------------------------------------------------------------\
  94. | |
  95. | Functions |
  96. | |
  97. \------------------------------------------------------------*/
  98. /*------------------------------------------------------------\
  99. | |
  100. | XgraComputeCursor |
  101. | |
  102. \------------------------------------------------------------*/
  103. void XgraComputeCursor( X, Y )
  104. Position X;
  105. Position Y;
  106. {
  107. autbegin();
  108. Y = XgraGraphicDy - Y;
  109. XgraUnitCursorX = X + XgraPixelGridX;
  110. XgraUnitCursorY = Y + XgraPixelGridY;
  111. if ( XgraUnitCursorX < 0 )
  112. {
  113. XgraUnitCursorX = ((float)(XgraUnitCursorX) / XgraUnitGridStep) - 0.5 ;
  114. }
  115. else
  116. {
  117. XgraUnitCursorX = ((float)(XgraUnitCursorX) / XgraUnitGridStep) + 0.5 ;
  118. }
  119. if ( XgraUnitCursorY < 0 )
  120. {
  121. XgraUnitCursorY = ((float)(XgraUnitCursorY) / XgraUnitGridStep) - 0.5 ;
  122. }
  123. else
  124. {
  125. XgraUnitCursorY = ((float)(XgraUnitCursorY) / XgraUnitGridStep) + 0.5 ;
  126. }
  127. XgraPixelCursorX = ((float)(XgraUnitCursorX) * XgraUnitGridStep);
  128. XgraPixelCursorY = ((float)(XgraUnitCursorY) * XgraUnitGridStep);
  129. XgraCursorX = XgraPixelCursorX - XgraPixelGridX;
  130. XgraCursorY = XgraPixelCursorY - XgraPixelGridY;
  131. XgraCursorY = XgraGraphicDy - XgraCursorY;
  132. autend();
  133. }
  134. /*------------------------------------------------------------\
  135. | |
  136. | XgraDisplayCoordinates |
  137. | |
  138. \------------------------------------------------------------*/
  139. void XgraDisplayCoordinates()
  140. {
  141. autbegin();
  142. sprintf( XgraCursorBuffer, "%d", XgraUnitCursorX );
  143. XgraDisplayMessage( XGRA_MESSAGE_X, XgraCursorBuffer );
  144. sprintf( XgraCursorBuffer, "%d", XgraUnitCursorY );
  145. XgraDisplayMessage( XGRA_MESSAGE_Y, XgraCursorBuffer );
  146. sprintf( XgraCursorBuffer, "%d", XgraUnitCursorX - XgraUnitCursorSaveX[0] );
  147. XgraDisplayMessage( XGRA_MESSAGE_DX, XgraCursorBuffer );
  148. sprintf( XgraCursorBuffer, "%d", XgraUnitCursorY - XgraUnitCursorSaveY[0] );
  149. XgraDisplayMessage( XGRA_MESSAGE_DY, XgraCursorBuffer );
  150. autend();
  151. }
  152. /*------------------------------------------------------------\
  153. | |
  154. | XgraPointCursor |
  155. | |
  156. \------------------------------------------------------------*/
  157. void XgraPointCursor()
  158. {
  159. autbegin();
  160. XgraUndisplayCursor();
  161. XgraUnitCursorSaveX[ XgraCursorIndex ] = XgraUnitCursorX;
  162. XgraUnitCursorSaveY[ XgraCursorIndex ] = XgraUnitCursorY;
  163. XgraCursorIndex = XgraCursorIndex + 1;
  164. XgraDisplayCursor();
  165. autend();
  166. }
  167. /*------------------------------------------------------------\
  168. | |
  169. | XgraResetCursor |
  170. | |
  171. \------------------------------------------------------------*/
  172. void XgraResetCursor()
  173. {
  174. autbegin();
  175. XgraUndisplayCursor();
  176. XgraCursorIndex = XgraCursorIndex - 1;
  177. XgraDisplayCursor();
  178. autend();
  179. }
  180. /*------------------------------------------------------------\
  181. | |
  182. | XgraChangeCursor |
  183. | |
  184. \------------------------------------------------------------*/
  185. void XgraChangeCursorType( ArrayX, ArrayY, Index, Type )
  186. long *ArrayX;
  187. long *ArrayY;
  188. char Index;
  189. char Type;
  190. {
  191. autbegin();
  192. XgraUndisplayCursor();
  193. XgraCursorType = Type;
  194. XgraCursorIndex = Index;
  195. if ( Index != 0 )
  196. {
  197. XgraUnitCursorSaveX[ 0 ] = ArrayX[0];
  198. XgraUnitCursorSaveY[ 0 ] = ArrayY[0];
  199. XgraUnitCursorSaveX[ 1 ] = ArrayX[1];
  200. XgraUnitCursorSaveY[ 1 ] = ArrayY[1];
  201. }
  202. XgraDisplayCursor();
  203. autend();
  204. }
  205. /*------------------------------------------------------------\
  206. | |
  207. | XgraDrawCursor |
  208. | |
  209. \------------------------------------------------------------*/
  210. void XgraDrawCursor()
  211. {
  212. long X1;
  213. long Y1;
  214. long X2;
  215. long Y2;
  216. long DeltaX;
  217. long DeltaY;
  218. long Swap;
  219. char DrawLine;
  220. autbegin();
  221. XDrawLine( XgraGraphicDisplay,
  222. XtWindow( XgraGraphicWindow ),
  223. XgraXorGC,
  224. XgraCursorSaveX - XGRA_CURSOR_SIZE,
  225. XgraCursorSaveY - XGRA_CURSOR_SIZE,
  226. XgraCursorSaveX + XGRA_CURSOR_SIZE,
  227. XgraCursorSaveY + XGRA_CURSOR_SIZE );
  228. XDrawLine( XgraGraphicDisplay,
  229. XtWindow( XgraGraphicWindow ),
  230. XgraXorGC,
  231. XgraCursorSaveX - XGRA_CURSOR_SIZE,
  232. XgraCursorSaveY + XGRA_CURSOR_SIZE,
  233. XgraCursorSaveX + XGRA_CURSOR_SIZE,
  234. XgraCursorSaveY - XGRA_CURSOR_SIZE );
  235. if ( XgraCursorIndex > 0 )
  236. {
  237. X1 = (float)(XgraUnitCursorSaveX[0]) * XgraUnitGridStep;
  238. Y1 = (float)(XgraUnitCursorSaveY[0]) * XgraUnitGridStep;
  239. X1 = X1 - XgraPixelGridX;
  240. Y1 = Y1 - XgraPixelGridY;
  241. Y1 = XgraGraphicDy - Y1;
  242. if ( XgraCursorIndex == 1 )
  243. {
  244. X2 = XgraCursorSaveX;
  245. Y2 = XgraCursorSaveY;
  246. }
  247. else
  248. {
  249. X2 = (float)(XgraUnitCursorSaveX[1]) * XgraUnitGridStep;
  250. Y2 = (float)(XgraUnitCursorSaveY[1]) * XgraUnitGridStep;
  251. X2 = X2 - XgraPixelGridX;
  252. Y2 = Y2 - XgraPixelGridY;
  253. Y2 = XgraGraphicDy - Y2;
  254. }
  255. switch( XgraCursorType )
  256. {
  257. case XGRA_INPUT_POINT :
  258. break;
  259. case XGRA_INPUT_LINE :
  260. XDrawLine( XgraGraphicDisplay,
  261. XtWindow( XgraGraphicWindow ),
  262. XgraXorGC,
  263. X1, Y1, X2, Y2 );
  264. break;
  265. case XGRA_INPUT_HALF_BOX :
  266. XDrawLine( XgraGraphicDisplay,
  267. XtWindow( XgraGraphicWindow ),
  268. XgraXorGC,
  269. X1, Y1, X2, Y1 );
  270. XDrawLine( XgraGraphicDisplay,
  271. XtWindow( XgraGraphicWindow ),
  272. XgraXorGC,
  273. X2, Y1, X2, Y2 );
  274. break;
  275. case XGRA_INPUT_ORTHO :
  276. case XGRA_INPUT_SORTHO :
  277. case XGRA_INPUT_LSTRING :
  278. DeltaX = X2 - X1; if ( DeltaX < 0 ) DeltaX = - DeltaX;
  279. DeltaY = Y2 - Y1; if ( DeltaY < 0 ) DeltaY = - DeltaY;
  280. if ( DeltaX > DeltaY )
  281. {
  282. Y2 = Y1;
  283. if ( X1 > X2 ) { Swap = X1; X1 = X2; X2 = Swap; }
  284. if ( X1 < 0 ) X1 = 0;
  285. if ( X2 > XgraGraphicDx ) X2 = XgraGraphicDx;
  286. if ( ( X1 < X2 ) &&
  287. ( Y1 >= 0 ) &&
  288. ( Y1 <= XgraGraphicDy ) )
  289. {
  290. XDrawLine( XgraGraphicDisplay,
  291. XtWindow( XgraGraphicWindow ),
  292. XgraXorGC,
  293. X1, Y1, X2, Y2 );
  294. }
  295. }
  296. else
  297. {
  298. X2 = X1;
  299. if ( Y1 > Y2 ) { Swap = Y1; Y1 = Y2; Y2 = Swap; }
  300. if ( Y1 < 0 ) Y1 = 0;
  301. if ( Y2 > XgraGraphicDy ) Y2 = XgraGraphicDy;
  302. if ( ( Y1 < Y2 ) &&
  303. ( X1 >= 0 ) &&
  304. ( X1 <= XgraGraphicDx ) )
  305. {
  306. XDrawLine( XgraGraphicDisplay,
  307. XtWindow( XgraGraphicWindow ),
  308. XgraXorGC,
  309. X1, Y1, X2, Y2 );
  310. }
  311. }
  312. break;
  313. case XGRA_INPUT_BOX :
  314. if ( X1 > X2 ) { Swap = X1; X1 = X2; X2 = Swap; }
  315. if ( Y1 > Y2 ) { Swap = Y1; Y1 = Y2; Y2 = Swap; }
  316. DrawLine = 0;
  317. if ( X1 < 0 ) { X1 = 0; DrawLine |= XGRA_WEST; }
  318. if ( X2 > XgraGraphicDx ) { X2 = XgraGraphicDx; DrawLine |= XGRA_EAST; }
  319. if ( Y1 < 0 ) { Y1 = 0; DrawLine |= XGRA_SOUTH; }
  320. if ( Y2 > XgraGraphicDy ) { Y2 = XgraGraphicDy; DrawLine |= XGRA_NORTH; }
  321. if ( DrawLine == 0 )
  322. {
  323. XDrawRectangle( XgraGraphicDisplay,
  324. XtWindow( XgraGraphicWindow ),
  325. XgraXorGC,
  326. X1, Y1,
  327. X2 - X1, Y2 - Y1 );
  328. }
  329. else
  330. {
  331. if ( ( DrawLine & XGRA_WEST ) == 0 )
  332. {
  333. XDrawLine( XgraGraphicDisplay,
  334. XtWindow( XgraGraphicWindow ),
  335. XgraXorGC,
  336. X1, Y2,
  337. X1, Y1 );
  338. }
  339. if ( ( DrawLine & XGRA_EAST ) == 0 )
  340. {
  341. XDrawLine( XgraGraphicDisplay,
  342. XtWindow( XgraGraphicWindow ),
  343. XgraXorGC,
  344. X2, Y2,
  345. X2, Y1 );
  346. }
  347. if ( ( DrawLine & XGRA_SOUTH ) == 0 )
  348. {
  349. XDrawLine( XgraGraphicDisplay,
  350. XtWindow( XgraGraphicWindow ),
  351. XgraXorGC,
  352. X1, Y1,
  353. X2, Y1 );
  354. }
  355. if ( ( DrawLine & XGRA_NORTH ) == 0 )
  356. {
  357. XDrawLine( XgraGraphicDisplay,
  358. XtWindow( XgraGraphicWindow ),
  359. XgraXorGC,
  360. X1, Y2,
  361. X2, Y2 );
  362. }
  363. }
  364. break;
  365. }
  366. }
  367. autend();
  368. }
  369. /*------------------------------------------------------------\
  370. | |
  371. | XgraUndisplayCursor |
  372. | |
  373. \------------------------------------------------------------*/
  374. void XgraUndisplayCursor()
  375. {
  376. autbegin();
  377. if ( XgraCursorInside == XGRA_TRUE )
  378. {
  379. if ( XgraCursorSaved == XGRA_TRUE )
  380. {
  381. XgraDrawCursor();
  382. }
  383. XgraCursorSaved = XGRA_FALSE;
  384. }
  385. autend();
  386. }
  387. /*------------------------------------------------------------\
  388. | |
  389. | XgraDisplayCursor |
  390. | |
  391. \------------------------------------------------------------*/
  392. void XgraDisplayCursor()
  393. {
  394. autbegin();
  395. if ( XgraCursorInside == XGRA_TRUE )
  396. {
  397. if ( XgraCursorSaved == XGRA_TRUE )
  398. {
  399. XgraDrawCursor();
  400. XgraCursorSaved = XGRA_FALSE;
  401. }
  402. if ( ( XgraCursorY >= 0 ) &&
  403. ( XgraCursorX <= XgraGraphicDx ) )
  404. {
  405. XgraCursorSaveX = XgraCursorX;
  406. XgraCursorSaveY = XgraCursorY;
  407. XgraDrawCursor();
  408. XgraCursorSaved = XGRA_TRUE;
  409. }
  410. }
  411. autend();
  412. }