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

https://github.com/clothbot/Alliance-VLSI-CAD-System · C · 515 lines · 301 code · 102 blank · 112 comment · 45 complexity · 189a6ad1df64b808988b426ad2ab047d 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 : XSCH |
  30. | |
  31. | File : Cursor.c |
  32. | |
  33. | Authors : Jacomme Ludovic |
  34. | |
  35. | Date : 01.06.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 "mlo.h"
  50. # include "XSB.h"
  51. # include "XMX.h"
  52. # include "XMX_grid.h"
  53. # include "XMX_cursor.h"
  54. /*------------------------------------------------------------\
  55. | |
  56. | Constants |
  57. | |
  58. \------------------------------------------------------------*/
  59. /*------------------------------------------------------------\
  60. | |
  61. | Types |
  62. | |
  63. \------------------------------------------------------------*/
  64. /*------------------------------------------------------------\
  65. | |
  66. | Variables |
  67. | |
  68. \------------------------------------------------------------*/
  69. /*------------------------------------------------------------\
  70. | |
  71. | Buffer |
  72. | |
  73. \------------------------------------------------------------*/
  74. static char XschCursorBuffer[ XSCH_MAX_CURSOR_BUFFER ];
  75. /*------------------------------------------------------------\
  76. | |
  77. | Coordinates |
  78. | |
  79. \------------------------------------------------------------*/
  80. Position XschCursorX = 0;
  81. Position XschCursorY = 0;
  82. Position XschCursorSaveX = 0;
  83. Position XschCursorSaveY = 0;
  84. int XschCursorSaved = XSCH_FALSE;
  85. int XschCursorInside = XSCH_FALSE;
  86. int XschCursorType = XSCH_INPUT_HALF_BOX;
  87. long XschUnitCursorX = 0;
  88. long XschUnitCursorY = 0;
  89. long XschPixelCursorX = 0;
  90. long XschPixelCursorY = 0;
  91. long XschUnitCursorSaveX[ 2 ] = { 0, 0 };
  92. long XschUnitCursorSaveY[ 2 ] = { 0, 0 };
  93. int XschCursorIndex = 0;
  94. /*------------------------------------------------------------\
  95. | |
  96. | Functions |
  97. | |
  98. \------------------------------------------------------------*/
  99. /*------------------------------------------------------------\
  100. | |
  101. | XschComputeCursor |
  102. | |
  103. \------------------------------------------------------------*/
  104. void XschComputeCursor( X, Y )
  105. Position X;
  106. Position Y;
  107. {
  108. autbegin();
  109. Y = XschGraphicDy - Y;
  110. XschUnitCursorX = X + XschPixelGridX;
  111. XschUnitCursorY = Y + XschPixelGridY;
  112. if ( XschUnitCursorX < 0 )
  113. {
  114. XschUnitCursorX = ((float)(XschUnitCursorX) / XschUnitGridStep) - 0.5 ;
  115. }
  116. else
  117. {
  118. XschUnitCursorX = ((float)(XschUnitCursorX) / XschUnitGridStep) + 0.5 ;
  119. }
  120. if ( XschUnitCursorY < 0 )
  121. {
  122. XschUnitCursorY = ((float)(XschUnitCursorY) / XschUnitGridStep) - 0.5 ;
  123. }
  124. else
  125. {
  126. XschUnitCursorY = ((float)(XschUnitCursorY) / XschUnitGridStep) + 0.5 ;
  127. }
  128. XschPixelCursorX = ((float)(XschUnitCursorX) * XschUnitGridStep);
  129. XschPixelCursorY = ((float)(XschUnitCursorY) * XschUnitGridStep);
  130. XschCursorX = XschPixelCursorX - XschPixelGridX;
  131. XschCursorY = XschPixelCursorY - XschPixelGridY;
  132. XschCursorY = XschGraphicDy - XschCursorY;
  133. autend();
  134. }
  135. /*------------------------------------------------------------\
  136. | |
  137. | XschDisplayCoordinates |
  138. | |
  139. \------------------------------------------------------------*/
  140. void XschDisplayCoordinates()
  141. {
  142. autbegin();
  143. sprintf( XschCursorBuffer, "%ld", XschUnitCursorX );
  144. XschDisplayMessage( XSCH_MESSAGE_X, XschCursorBuffer );
  145. sprintf( XschCursorBuffer, "%ld", XschUnitCursorY );
  146. XschDisplayMessage( XSCH_MESSAGE_Y, XschCursorBuffer );
  147. sprintf( XschCursorBuffer, "%ld", XschUnitCursorX - XschUnitCursorSaveX[0] );
  148. XschDisplayMessage( XSCH_MESSAGE_DX, XschCursorBuffer );
  149. sprintf( XschCursorBuffer, "%ld", XschUnitCursorY - XschUnitCursorSaveY[0] );
  150. XschDisplayMessage( XSCH_MESSAGE_DY, XschCursorBuffer );
  151. autend();
  152. }
  153. /*------------------------------------------------------------\
  154. | |
  155. | XschPointCursor |
  156. | |
  157. \------------------------------------------------------------*/
  158. void XschPointCursor()
  159. {
  160. autbegin();
  161. XschUndisplayCursor();
  162. XschUnitCursorSaveX[ XschCursorIndex ] = XschUnitCursorX;
  163. XschUnitCursorSaveY[ XschCursorIndex ] = XschUnitCursorY;
  164. XschCursorIndex = XschCursorIndex + 1;
  165. XschDisplayCursor();
  166. autend();
  167. }
  168. /*------------------------------------------------------------\
  169. | |
  170. | XschResetCursor |
  171. | |
  172. \------------------------------------------------------------*/
  173. void XschResetCursor()
  174. {
  175. autbegin();
  176. XschUndisplayCursor();
  177. XschCursorIndex = XschCursorIndex - 1;
  178. XschDisplayCursor();
  179. autend();
  180. }
  181. /*------------------------------------------------------------\
  182. | |
  183. | XschChangeCursor |
  184. | |
  185. \------------------------------------------------------------*/
  186. void XschChangeCursorType( ArrayX, ArrayY, Index, Type )
  187. long *ArrayX;
  188. long *ArrayY;
  189. int Index;
  190. int Type;
  191. {
  192. autbegin();
  193. XschUndisplayCursor();
  194. XschCursorType = Type;
  195. XschCursorIndex = Index;
  196. if ( Index != 0 )
  197. {
  198. XschUnitCursorSaveX[ 0 ] = ArrayX[0];
  199. XschUnitCursorSaveY[ 0 ] = ArrayY[0];
  200. XschUnitCursorSaveX[ 1 ] = ArrayX[1];
  201. XschUnitCursorSaveY[ 1 ] = ArrayY[1];
  202. }
  203. XschDisplayCursor();
  204. autend();
  205. }
  206. /*------------------------------------------------------------\
  207. | |
  208. | XschDrawCursor |
  209. | |
  210. \------------------------------------------------------------*/
  211. void XschDrawCursor()
  212. {
  213. long X1;
  214. long Y1;
  215. long X2;
  216. long Y2;
  217. long DeltaX;
  218. long DeltaY;
  219. long Swap;
  220. int DrawLine;
  221. autbegin();
  222. XDrawLine( XschGraphicDisplay,
  223. XtWindow( XschGraphicWindow ),
  224. XschXorGC,
  225. XschCursorSaveX - XSCH_CURSOR_SIZE,
  226. XschCursorSaveY - XSCH_CURSOR_SIZE,
  227. XschCursorSaveX + XSCH_CURSOR_SIZE,
  228. XschCursorSaveY + XSCH_CURSOR_SIZE );
  229. XDrawLine( XschGraphicDisplay,
  230. XtWindow( XschGraphicWindow ),
  231. XschXorGC,
  232. XschCursorSaveX - XSCH_CURSOR_SIZE,
  233. XschCursorSaveY + XSCH_CURSOR_SIZE,
  234. XschCursorSaveX + XSCH_CURSOR_SIZE,
  235. XschCursorSaveY - XSCH_CURSOR_SIZE );
  236. if ( XschCursorIndex > 0 )
  237. {
  238. X1 = (float)(XschUnitCursorSaveX[0]) * XschUnitGridStep;
  239. Y1 = (float)(XschUnitCursorSaveY[0]) * XschUnitGridStep;
  240. X1 = X1 - XschPixelGridX;
  241. Y1 = Y1 - XschPixelGridY;
  242. Y1 = XschGraphicDy - Y1;
  243. if ( XschCursorIndex == 1 )
  244. {
  245. X2 = XschCursorSaveX;
  246. Y2 = XschCursorSaveY;
  247. }
  248. else
  249. {
  250. X2 = (float)(XschUnitCursorSaveX[1]) * XschUnitGridStep;
  251. Y2 = (float)(XschUnitCursorSaveY[1]) * XschUnitGridStep;
  252. X2 = X2 - XschPixelGridX;
  253. Y2 = Y2 - XschPixelGridY;
  254. Y2 = XschGraphicDy - Y2;
  255. }
  256. switch( XschCursorType )
  257. {
  258. case XSCH_INPUT_POINT :
  259. break;
  260. case XSCH_INPUT_LINE :
  261. XDrawLine( XschGraphicDisplay,
  262. XtWindow( XschGraphicWindow ),
  263. XschXorGC,
  264. X1, Y1, X2, Y2 );
  265. break;
  266. case XSCH_INPUT_HALF_BOX :
  267. XDrawLine( XschGraphicDisplay,
  268. XtWindow( XschGraphicWindow ),
  269. XschXorGC,
  270. X1, Y1, X2, Y1 );
  271. XDrawLine( XschGraphicDisplay,
  272. XtWindow( XschGraphicWindow ),
  273. XschXorGC,
  274. X2, Y1, X2, Y2 );
  275. break;
  276. case XSCH_INPUT_ORTHO :
  277. case XSCH_INPUT_SORTHO :
  278. case XSCH_INPUT_LSTRING :
  279. DeltaX = X2 - X1; if ( DeltaX < 0 ) DeltaX = - DeltaX;
  280. DeltaY = Y2 - Y1; if ( DeltaY < 0 ) DeltaY = - DeltaY;
  281. if ( DeltaX > DeltaY )
  282. {
  283. Y2 = Y1;
  284. if ( X1 > X2 ) { Swap = X1; X1 = X2; X2 = Swap; }
  285. if ( X1 < 0 ) X1 = 0;
  286. if ( X2 > XschGraphicDx ) X2 = XschGraphicDx;
  287. if ( ( X1 < X2 ) &&
  288. ( Y1 >= 0 ) &&
  289. ( Y1 <= XschGraphicDy ) )
  290. {
  291. XDrawLine( XschGraphicDisplay,
  292. XtWindow( XschGraphicWindow ),
  293. XschXorGC,
  294. X1, Y1, X2, Y2 );
  295. }
  296. }
  297. else
  298. {
  299. X2 = X1;
  300. if ( Y1 > Y2 ) { Swap = Y1; Y1 = Y2; Y2 = Swap; }
  301. if ( Y1 < 0 ) Y1 = 0;
  302. if ( Y2 > XschGraphicDy ) Y2 = XschGraphicDy;
  303. if ( ( Y1 < Y2 ) &&
  304. ( X1 >= 0 ) &&
  305. ( X1 <= XschGraphicDx ) )
  306. {
  307. XDrawLine( XschGraphicDisplay,
  308. XtWindow( XschGraphicWindow ),
  309. XschXorGC,
  310. X1, Y1, X2, Y2 );
  311. }
  312. }
  313. break;
  314. case XSCH_INPUT_BOX :
  315. if ( X1 > X2 ) { Swap = X1; X1 = X2; X2 = Swap; }
  316. if ( Y1 > Y2 ) { Swap = Y1; Y1 = Y2; Y2 = Swap; }
  317. DrawLine = 0;
  318. if ( X1 < 0 ) { X1 = 0; DrawLine |= XSCH_WEST; }
  319. if ( X2 > XschGraphicDx ) { X2 = XschGraphicDx; DrawLine |= XSCH_EAST; }
  320. if ( Y1 < 0 ) { Y1 = 0; DrawLine |= XSCH_SOUTH; }
  321. if ( Y2 > XschGraphicDy ) { Y2 = XschGraphicDy; DrawLine |= XSCH_NORTH; }
  322. if ( DrawLine == 0 )
  323. {
  324. XDrawRectangle( XschGraphicDisplay,
  325. XtWindow( XschGraphicWindow ),
  326. XschXorGC,
  327. X1, Y1,
  328. X2 - X1, Y2 - Y1 );
  329. }
  330. else
  331. {
  332. if ( ( DrawLine & XSCH_WEST ) == 0 )
  333. {
  334. XDrawLine( XschGraphicDisplay,
  335. XtWindow( XschGraphicWindow ),
  336. XschXorGC,
  337. X1, Y2,
  338. X1, Y1 );
  339. }
  340. if ( ( DrawLine & XSCH_EAST ) == 0 )
  341. {
  342. XDrawLine( XschGraphicDisplay,
  343. XtWindow( XschGraphicWindow ),
  344. XschXorGC,
  345. X2, Y2,
  346. X2, Y1 );
  347. }
  348. if ( ( DrawLine & XSCH_SOUTH ) == 0 )
  349. {
  350. XDrawLine( XschGraphicDisplay,
  351. XtWindow( XschGraphicWindow ),
  352. XschXorGC,
  353. X1, Y1,
  354. X2, Y1 );
  355. }
  356. if ( ( DrawLine & XSCH_NORTH ) == 0 )
  357. {
  358. XDrawLine( XschGraphicDisplay,
  359. XtWindow( XschGraphicWindow ),
  360. XschXorGC,
  361. X1, Y2,
  362. X2, Y2 );
  363. }
  364. }
  365. break;
  366. }
  367. }
  368. autend();
  369. }
  370. /*------------------------------------------------------------\
  371. | |
  372. | XschUndisplayCursor |
  373. | |
  374. \------------------------------------------------------------*/
  375. void XschUndisplayCursor()
  376. {
  377. autbegin();
  378. if ( XschCursorInside == XSCH_TRUE )
  379. {
  380. if ( XschCursorSaved == XSCH_TRUE )
  381. {
  382. XschDrawCursor();
  383. }
  384. XschCursorSaved = XSCH_FALSE;
  385. }
  386. autend();
  387. }
  388. /*------------------------------------------------------------\
  389. | |
  390. | XschDisplayCursor |
  391. | |
  392. \------------------------------------------------------------*/
  393. void XschDisplayCursor()
  394. {
  395. autbegin();
  396. if ( XschCursorInside == XSCH_TRUE )
  397. {
  398. if ( XschCursorSaved == XSCH_TRUE )
  399. {
  400. XschDrawCursor();
  401. XschCursorSaved = XSCH_FALSE;
  402. }
  403. if ( ( XschCursorY >= 0 ) &&
  404. ( XschCursorX <= (Position)XschGraphicDx ) )
  405. {
  406. XschCursorSaveX = XschCursorX;
  407. XschCursorSaveY = XschCursorY;
  408. XschDrawCursor();
  409. XschCursorSaved = XSCH_TRUE;
  410. }
  411. }
  412. autend();
  413. }