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

https://github.com/clothbot/Alliance-VLSI-CAD-System · C · 310 lines · 168 code · 50 blank · 92 comment · 21 complexity · b50d7b72ecf24bc3573a5f32afa3ab79 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 : Grid.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 <Xm/Xm.h>
  45. # include "mut.h"
  46. # include "aut.h"
  47. # include "XSB.h"
  48. # include "XMX.h"
  49. # include "XMX_grid.h"
  50. /*------------------------------------------------------------\
  51. | |
  52. | Constants |
  53. | |
  54. \------------------------------------------------------------*/
  55. /*------------------------------------------------------------\
  56. | |
  57. | Types |
  58. | |
  59. \------------------------------------------------------------*/
  60. /*------------------------------------------------------------\
  61. | |
  62. | Variables |
  63. | |
  64. \------------------------------------------------------------*/
  65. /*------------------------------------------------------------\
  66. | |
  67. | Unit Grid |
  68. | |
  69. \------------------------------------------------------------*/
  70. float XgraUnitGridStep;
  71. long XgraUnitGridX;
  72. long XgraUnitGridY;
  73. long XgraUnitGridDx;
  74. long XgraUnitGridDy;
  75. long XgraPixelGridX;
  76. long XgraPixelGridY;
  77. /*------------------------------------------------------------\
  78. | |
  79. | User Unit Grid |
  80. | |
  81. \------------------------------------------------------------*/
  82. long XgraUnitUserGridDx;
  83. long XgraUnitUserGridDy;
  84. char XgraUnitUserGrid;
  85. /*------------------------------------------------------------\
  86. | |
  87. | Functions |
  88. | |
  89. \------------------------------------------------------------*/
  90. /*------------------------------------------------------------\
  91. | |
  92. | XgraInitializeUnitGrid |
  93. | |
  94. \------------------------------------------------------------*/
  95. void XgraInitializeUnitGrid()
  96. {
  97. autbegin();
  98. XgraUnitGridX = XGRA_DEFAULT_GRID_X;
  99. XgraUnitGridY = XGRA_DEFAULT_GRID_Y;
  100. XgraUnitGridDx = XGRA_DEFAULT_GRID_DX;
  101. XgraUnitGridDy = XGRA_DEFAULT_GRID_DY;
  102. XgraUnitUserGridDx = 4;
  103. XgraUnitUserGridDy = 4;
  104. XgraUnitUserGrid = XGRA_FALSE;
  105. XgraComputeUnitGrid();
  106. autend();
  107. }
  108. /*------------------------------------------------------------\
  109. | |
  110. | XgraComputeUnitGrid |
  111. | |
  112. \------------------------------------------------------------*/
  113. void XgraComputeUnitGrid()
  114. {
  115. float StepX;
  116. float StepY;
  117. autbegin();
  118. StepX = (float)(XgraGraphicDx) / (float)(XgraUnitGridDx);
  119. StepY = (float)(XgraGraphicDy) / (float)(XgraUnitGridDy);
  120. if ( StepX < StepY )
  121. {
  122. XgraUnitGridStep = StepX;
  123. XgraUnitGridDy = 1 + ( XgraGraphicDy / StepX );
  124. }
  125. else
  126. {
  127. XgraUnitGridStep = StepY;
  128. XgraUnitGridDx = 1 + ( XgraGraphicDx / StepY );
  129. }
  130. XgraPixelGridX = (float)(XgraUnitGridX) * XgraUnitGridStep;
  131. XgraPixelGridY = (float)(XgraUnitGridY) * XgraUnitGridStep;
  132. autend();
  133. }
  134. /*------------------------------------------------------------\
  135. | |
  136. | XgraResizeUnitGrid |
  137. | |
  138. \------------------------------------------------------------*/
  139. void XgraResizeUnitGrid()
  140. {
  141. autbegin();
  142. XgraUnitGridDx = 1 + ( XgraGraphicDx / XgraUnitGridStep );
  143. XgraUnitGridDy = 1 + ( XgraGraphicDy / XgraUnitGridStep );
  144. autend();
  145. }
  146. /*------------------------------------------------------------\
  147. | |
  148. | XgraDisplayUnitGrid |
  149. | |
  150. \------------------------------------------------------------*/
  151. char XgraDisplayUnitGrid( GraphicX1, GraphicY1, GraphicX2, GraphicY2 )
  152. Dimension GraphicX1;
  153. Dimension GraphicY1;
  154. Dimension GraphicX2;
  155. Dimension GraphicY2;
  156. {
  157. long X;
  158. long Y;
  159. long MaxGridX;
  160. long MaxGridY;
  161. long PixelX;
  162. long PixelY;
  163. long Xmin;
  164. long Ymin;
  165. char UserGrid;
  166. char UnitGrid;
  167. float Check;
  168. autbegin();
  169. if ( XgraUnitGridStep < XGRA_LOWER_GRID_STEP )
  170. {
  171. UnitGrid = 0;
  172. }
  173. else
  174. {
  175. UnitGrid = 1;
  176. }
  177. if ( XgraUnitUserGrid == 1 )
  178. {
  179. if ( XgraUnitUserGridDx > XgraUnitUserGridDy )
  180. {
  181. Check = ( XGRA_LOWER_GRID_STEP * 2 / XgraUnitUserGridDy );
  182. }
  183. else
  184. {
  185. Check = ( XGRA_LOWER_GRID_STEP * 2 / XgraUnitUserGridDy );
  186. }
  187. if ( XgraUnitGridStep < Check ) UserGrid = 0;
  188. else UserGrid = 1;
  189. }
  190. else
  191. {
  192. UserGrid = 0;
  193. }
  194. if ( ( UserGrid == 0 ) &&
  195. ( UnitGrid == 0 ) )
  196. {
  197. autend();
  198. return( XGRA_FALSE );
  199. }
  200. MaxGridX = XgraUnitGridX + XgraUnitGridDx;
  201. MaxGridY = XgraUnitGridY + XgraUnitGridDy;
  202. if ( UnitGrid )
  203. {
  204. for ( X = XgraUnitGridX; X < MaxGridX; X = X + 1 )
  205. {
  206. PixelX = ((float)(X) * XgraUnitGridStep);
  207. PixelX = PixelX - XgraPixelGridX;
  208. if ( ( PixelX <= GraphicX2 ) &&
  209. ( PixelX >= GraphicX1 ) )
  210. for ( Y = XgraUnitGridY; Y < MaxGridY; Y = Y + 1 )
  211. {
  212. PixelY = ((float)(Y) * XgraUnitGridStep);
  213. PixelY = PixelY - XgraPixelGridY;
  214. PixelY = XgraGraphicDy - PixelY;
  215. if ( ( PixelY <= GraphicY2 ) &&
  216. ( PixelY >= GraphicY1 ) )
  217. {
  218. XDrawPoint( XgraGraphicDisplay,
  219. XtWindow( XgraGraphicWindow ),
  220. XgraGridGC,
  221. PixelX, PixelY );
  222. }
  223. }
  224. }
  225. }
  226. if ( UserGrid )
  227. {
  228. Xmin = ( XgraUnitGridX / XgraUnitUserGridDx ) * XgraUnitUserGridDx;
  229. Ymin = ( XgraUnitGridY / XgraUnitUserGridDy ) * XgraUnitUserGridDy;
  230. for ( X = Xmin; X < MaxGridX ; X = X + XgraUnitUserGridDx )
  231. {
  232. PixelX = ((float)(X) * XgraUnitGridStep);
  233. PixelX = PixelX - XgraPixelGridX;
  234. if ( ( PixelX <= GraphicX2 ) &&
  235. ( PixelX >= GraphicX1 ) )
  236. for ( Y = Ymin; Y < MaxGridY; Y = Y + XgraUnitUserGridDy )
  237. {
  238. PixelY = ((float)(Y) * XgraUnitGridStep);
  239. PixelY = PixelY - XgraPixelGridY;
  240. PixelY = XgraGraphicDy - PixelY;
  241. if ( ( PixelY <= GraphicY2 ) &&
  242. ( PixelY >= GraphicY1 ) )
  243. {
  244. XDrawLine( XgraGraphicDisplay,
  245. XtWindow( XgraGraphicWindow ),
  246. XgraGridGC,
  247. PixelX - 2, PixelY,
  248. PixelX + 2, PixelY );
  249. XDrawLine( XgraGraphicDisplay,
  250. XtWindow( XgraGraphicWindow ),
  251. XgraGridGC,
  252. PixelX, PixelY + 2,
  253. PixelX, PixelY - 2 );
  254. }
  255. }
  256. }
  257. }
  258. autend();
  259. return( XGRA_TRUE );
  260. }