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

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