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

https://github.com/clothbot/Alliance-VLSI-CAD-System · C · 310 lines · 168 code · 50 blank · 92 comment · 21 complexity · 0fbf4f7642957ea19136891a6d668814 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 : XVPN |
  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 XvpnUnitGridStep;
  71. long XvpnUnitGridX;
  72. long XvpnUnitGridY;
  73. long XvpnUnitGridDx;
  74. long XvpnUnitGridDy;
  75. long XvpnPixelGridX;
  76. long XvpnPixelGridY;
  77. /*------------------------------------------------------------\
  78. | |
  79. | User Unit Grid |
  80. | |
  81. \------------------------------------------------------------*/
  82. long XvpnUnitUserGridDx;
  83. long XvpnUnitUserGridDy;
  84. short XvpnUnitUserGrid;
  85. /*------------------------------------------------------------\
  86. | |
  87. | Functions |
  88. | |
  89. \------------------------------------------------------------*/
  90. /*------------------------------------------------------------\
  91. | |
  92. | XvpnInitializeUnitGrid |
  93. | |
  94. \------------------------------------------------------------*/
  95. void XvpnInitializeUnitGrid()
  96. {
  97. autbegin();
  98. XvpnUnitGridX = XVPN_DEFAULT_GRID_X;
  99. XvpnUnitGridY = XVPN_DEFAULT_GRID_Y;
  100. XvpnUnitGridDx = XVPN_DEFAULT_GRID_DX;
  101. XvpnUnitGridDy = XVPN_DEFAULT_GRID_DY;
  102. XvpnUnitUserGridDx = 4;
  103. XvpnUnitUserGridDy = 4;
  104. XvpnUnitUserGrid = XVPN_FALSE;
  105. XvpnComputeUnitGrid();
  106. autend();
  107. }
  108. /*------------------------------------------------------------\
  109. | |
  110. | XvpnComputeUnitGrid |
  111. | |
  112. \------------------------------------------------------------*/
  113. void XvpnComputeUnitGrid()
  114. {
  115. float StepX;
  116. float StepY;
  117. autbegin();
  118. StepX = (float)(XvpnGraphicDx) / (float)(XvpnUnitGridDx);
  119. StepY = (float)(XvpnGraphicDy) / (float)(XvpnUnitGridDy);
  120. if ( StepX < StepY )
  121. {
  122. XvpnUnitGridStep = StepX;
  123. XvpnUnitGridDy = 1 + ( XvpnGraphicDy / StepX );
  124. }
  125. else
  126. {
  127. XvpnUnitGridStep = StepY;
  128. XvpnUnitGridDx = 1 + ( XvpnGraphicDx / StepY );
  129. }
  130. XvpnPixelGridX = (float)(XvpnUnitGridX) * XvpnUnitGridStep;
  131. XvpnPixelGridY = (float)(XvpnUnitGridY) * XvpnUnitGridStep;
  132. autend();
  133. }
  134. /*------------------------------------------------------------\
  135. | |
  136. | XvpnResizeUnitGrid |
  137. | |
  138. \------------------------------------------------------------*/
  139. void XvpnResizeUnitGrid()
  140. {
  141. autbegin();
  142. XvpnUnitGridDx = 1 + ( XvpnGraphicDx / XvpnUnitGridStep );
  143. XvpnUnitGridDy = 1 + ( XvpnGraphicDy / XvpnUnitGridStep );
  144. autend();
  145. }
  146. /*------------------------------------------------------------\
  147. | |
  148. | XvpnDisplayUnitGrid |
  149. | |
  150. \------------------------------------------------------------*/
  151. short XvpnDisplayUnitGrid( 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. short UserGrid;
  166. short UnitGrid;
  167. float Check;
  168. autbegin();
  169. if ( XvpnUnitGridStep < XVPN_LOWER_GRID_STEP )
  170. {
  171. UnitGrid = 0;
  172. }
  173. else
  174. {
  175. UnitGrid = 1;
  176. }
  177. if ( XvpnUnitUserGrid == 1 )
  178. {
  179. if ( XvpnUnitUserGridDx > XvpnUnitUserGridDy )
  180. {
  181. Check = ( XVPN_LOWER_GRID_STEP * 2 / XvpnUnitUserGridDy );
  182. }
  183. else
  184. {
  185. Check = ( XVPN_LOWER_GRID_STEP * 2 / XvpnUnitUserGridDy );
  186. }
  187. if ( XvpnUnitGridStep < 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( XVPN_FALSE );
  199. }
  200. MaxGridX = XvpnUnitGridX + XvpnUnitGridDx;
  201. MaxGridY = XvpnUnitGridY + XvpnUnitGridDy;
  202. if ( UnitGrid )
  203. {
  204. for ( X = XvpnUnitGridX; X < MaxGridX; X = X + 1 )
  205. {
  206. PixelX = ((float)(X) * XvpnUnitGridStep);
  207. PixelX = PixelX - XvpnPixelGridX;
  208. if ( ( PixelX <= GraphicX2 ) &&
  209. ( PixelX >= GraphicX1 ) )
  210. for ( Y = XvpnUnitGridY; Y < MaxGridY; Y = Y + 1 )
  211. {
  212. PixelY = ((float)(Y) * XvpnUnitGridStep);
  213. PixelY = PixelY - XvpnPixelGridY;
  214. PixelY = XvpnGraphicDy - PixelY;
  215. if ( ( PixelY <= GraphicY2 ) &&
  216. ( PixelY >= GraphicY1 ) )
  217. {
  218. XDrawPoint( XvpnGraphicDisplay,
  219. XtWindow( XvpnGraphicWindow ),
  220. XvpnGridGC,
  221. PixelX, PixelY );
  222. }
  223. }
  224. }
  225. }
  226. if ( UserGrid )
  227. {
  228. Xmin = ( XvpnUnitGridX / XvpnUnitUserGridDx ) * XvpnUnitUserGridDx;
  229. Ymin = ( XvpnUnitGridY / XvpnUnitUserGridDy ) * XvpnUnitUserGridDy;
  230. for ( X = Xmin; X < MaxGridX ; X = X + XvpnUnitUserGridDx )
  231. {
  232. PixelX = ((float)(X) * XvpnUnitGridStep);
  233. PixelX = PixelX - XvpnPixelGridX;
  234. if ( ( PixelX <= GraphicX2 ) &&
  235. ( PixelX >= GraphicX1 ) )
  236. for ( Y = Ymin; Y < MaxGridY; Y = Y + XvpnUnitUserGridDy )
  237. {
  238. PixelY = ((float)(Y) * XvpnUnitGridStep);
  239. PixelY = PixelY - XvpnPixelGridY;
  240. PixelY = XvpnGraphicDy - PixelY;
  241. if ( ( PixelY <= GraphicY2 ) &&
  242. ( PixelY >= GraphicY1 ) )
  243. {
  244. XDrawLine( XvpnGraphicDisplay,
  245. XtWindow( XvpnGraphicWindow ),
  246. XvpnGridGC,
  247. PixelX - 2, PixelY,
  248. PixelX + 2, PixelY );
  249. XDrawLine( XvpnGraphicDisplay,
  250. XtWindow( XvpnGraphicWindow ),
  251. XvpnGridGC,
  252. PixelX, PixelY + 2,
  253. PixelX, PixelY - 2 );
  254. }
  255. }
  256. }
  257. }
  258. autend();
  259. return( XVPN_TRUE );
  260. }