1 package devisor2.foundation.elements; 2 3 4 import java.util.*; 5 import java.awt.*; 6 import java.awt.geom.*; 7 import java.io.*; 8 9 import devisor2.grid.options.*; 10 import devisor2.foundation.*; 11 import devisor2.grid.backend.*; 12 13 /** 14 * The class Cell provides a superior ground class for 15 * the cells which defines the discrete domain. 16 * This class is abstract and must be derived. 17 * Basically, a Cell is a container for some faces (or in 2D edges) which are 18 * defined via the cornering nodes. As always, there are additional properties 19 * like numbering, material constants etc. 20 * 21 * @see Quad 22 * @see Tri 23 * @see Line 24 * @see Macro 25 * 26 * @author Dominik Goeddeke, Christian Becker 27 */ 28 29 public abstract class Cell extends GridItem implements java.io.Serializable 30 { 31 32 /** 33 * Number of the cell 34 */ 35 protected int number; 36 37 /** 38 * Material number of the cell (UCD) 39 */ 40 protected int material_number; 41 42 /** 43 * Number of the cell 44 */ 45 protected int level; 46 47 /** 48 * Marker of the cell 49 */ 50 protected int marker; 51 52 53 /** 54 * parameters of the cell 55 */ 56 protected int[] parameters; 57 58 /** 59 * Array for the neighbourhood, updated by updateCellNeighbours() 60 * should contain cells. 61 */ 62 protected Cell[] neighbours; 63 64 /** 65 * Array for the children, 66 * should contain cells. 67 */ 68 protected Cell[] children; 69 70 /** 71 * parent Cell 72 */ 73 protected Cell parent; 74 75 /** 76 * Values stored in the cell. 77 */ 78 protected double [] values; 79 80 /** 81 * parameters of the cell 82 */ 83 protected int parallelblock; 84 85 /** 86 * parameters of the cell 87 */ 88 protected int matrixblock; 89 90 /** 91 * nodes of this cell, updated by updateCellNodes() 92 */ 93 protected Node[] nodes; 94 95 setParallelBlock(int i)96 public void setParallelBlock(int i) 97 { 98 parallelblock=i; 99 } 100 101 getParallelBlock()102 public int getParallelBlock() 103 { 104 return parallelblock; 105 } 106 107 setMatrixBlock(int i)108 public void setMatrixBlock(int i) 109 { 110 matrixblock=i; 111 } 112 113 getMatrixBlock()114 public int getMatrixBlock() 115 { 116 return matrixblock; 117 } 118 119 120 /** 121 * Empty Constructor. 122 * Sets the number to 0. 123 */ Cell()124 public Cell() 125 { 126 super (); 127 level = 0; 128 number = 0; 129 material_number = 0; 130 marker=0; 131 matrixblock=1; 132 parallelblock=1; 133 neighbours = null; 134 parent = null; 135 children = null; 136 } 137 138 139 /** 140 * Sets the number of the cell to i. 141 */ Cell( int i )142 Cell( int i ) 143 { 144 super (); 145 level = 0; 146 number = i; 147 material_number = 0; 148 matrixblock=1; 149 parallelblock=1; 150 marker = 0; 151 neighbours = null; 152 parent = null; 153 children = null; 154 } 155 156 157 /** 158 * Defines the length of the array of values in the cell 159 */ defValue(int i)160 public void defValue(int i) 161 { 162 if (i>0) 163 values = new double[i]; 164 } 165 166 167 /** 168 * Sets the ith value to val. 169 */ setValue(int i, double val)170 public void setValue(int i, double val) 171 { 172 values[i] = val; 173 } 174 175 176 /** 177 * Returns the ith value. 178 */ getValue(int i)179 public double getValue(int i) 180 { 181 return values[i]; 182 } 183 184 isRect()185 public boolean isRect() 186 { 187 188 double v1x=nodes[3].getCoord(0)-nodes[0].getCoord(0); 189 double v1y=nodes[3].getCoord(1)-nodes[0].getCoord(1); 190 191 double v2x=nodes[1].getCoord(0)-nodes[0].getCoord(0); 192 double v2y=nodes[1].getCoord(1)-nodes[0].getCoord(1); 193 194 double dskala=v1x*v2x+v1y*v2y; 195 196 197 v1x=nodes[3].getCoord(0)-nodes[2].getCoord(0); 198 v1y=nodes[3].getCoord(1)-nodes[2].getCoord(1); 199 200 v2x=nodes[1].getCoord(0)-nodes[2].getCoord(0); 201 v2y=nodes[1].getCoord(1)-nodes[2].getCoord(1); 202 203 double dskalb=v1x*v2x+v1y*v2y; 204 205 return ((Math.abs(dskala)<1E-12) && (Math.abs(dskalb)<1E-12)); 206 207 } 208 209 210 /** 211 * Returns the average of the ith value 212 * of the nodes defining this cell. 213 */ getNodeAverageValue(int index)214 public double getNodeAverageValue(int index) 215 { 216 int npt = getNPT(); 217 double value = 0.; 218 for (int i=0; i<npt; i++) 219 { 220 value += nodes[i].getValue(index); 221 } 222 value /= (double)(npt); 223 return value; 224 } 225 226 227 /** 228 * Returns the marker of the cell. 229 */ getMarker()230 public int getMarker() 231 { 232 return marker; 233 } 234 235 236 /** 237 * sets the marker of the cell. 238 * @param m marker value 239 */ setMarker(int m)240 public void setMarker(int m) 241 { 242 marker=m; 243 } 244 245 246 /** 247 * Returns the level of the cell. 248 */ getLevel()249 public int getLevel() 250 { 251 return level; 252 } 253 254 255 /** 256 * sets the level of the cell. 257 * @param m level value 258 */ setLevel(int m)259 public void setLevel(int m) 260 { 261 level=m; 262 } 263 264 265 /** 266 * Sets the number of the cell to i. 267 */ setNumber( int i )268 public void setNumber( int i ) 269 { 270 number = i; 271 } 272 getParent()273 public Cell getParent () 274 { 275 return parent; 276 } 277 getNeighbours()278 public Cell[] getNeighbours () 279 { 280 return neighbours; 281 } 282 getChildren()283 public Cell[] getChildren () 284 { 285 return children; 286 } 287 getNodes()288 public Node[] getNodes () 289 { 290 return nodes; 291 } 292 293 294 /** 295 * gets the number of the cell. 296 */ getNumber( )297 public int getNumber( ) 298 { 299 return number ; 300 } 301 302 /** 303 * updates the Node array of this cell 304 * @return the nodes of this cell in order of faces/edges 305 */ updateCellNodes()306 public abstract Node[] updateCellNodes(); 307 308 309 /** 310 * updates the neighbours of this cell 311 */ updateCellNeighbours()312 public abstract Cell[] updateCellNeighbours(); 313 314 315 /** 316 * Draws the perimeter of the cell. 317 */ draw(Graphics g)318 public abstract void draw(Graphics g); 319 getNPT()320 public abstract int getNPT(); 321 322 323 /** 324 * Draws the cell filled with its color. 325 */ fill(Graphics g)326 public abstract void fill(Graphics g); 327 328 329 /** 330 * Is the item inside a given rectangular area? 331 * All in WORLD COORDINATES!!! 332 * 333 * @param topleft - the topleft corner of the rectangle 334 * @param bottomright - the bottom right corner of the rectangle 335 * @return true if the item is completely inside the rectangle 336 */ isInside(int[] topleft, int[] bottomright)337 public abstract boolean isInside (int[] topleft, int[] bottomright); 338 339 /** 340 * Determines if the item has been hit by a click on the grid 341 * ALL IN SCREEN COORDINATES to avoid the snap mechanism 342 * 343 * @param x,y - coordinates of the event point where the click 344 * occurred 345 * @return true if the item has been hit 346 */ isHit(int x, int y)347 public abstract boolean isHit (int x, int y); 348 getPerimeter()349 public abstract Rectangle getPerimeter(); 350 performTransformation(GridTransformation trafo)351 public abstract void performTransformation (GridTransformation trafo); 352 353 354 355 } 356