1 /* 2 * This program is free software; you can redistribute it and/or 3 * modify it under the terms of the GNU General Public License as 4 * published by the Free Software Foundation; either version 2 of the 5 * License, or (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but 8 * WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOUSE. See the GNU 10 * General Public License for more details. 11 * 12 * You should have recieved a copy of the GNU General Public License 13 * along with this program; if not write to the Free Software 14 * Foundation, inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 15 * USA 16 */ 17 18 package run.writers; 19 20 import java.io.*; 21 22 import jp.sync.Barrier; 23 24 import run.Constraint; 25 import run.Controlset; 26 import run.Element; 27 import run.Load; 28 import run.Material; 29 import run.Node; 30 import run.RplVector; 31 import run.Writer; 32 33 34 /** 35 * Insert the type's description here. Creation date: (2001-10-31 00.44.39) 36 * 37 * @author: 38 */ 39 public class FembicWriter extends Writer { 40 private RplVector constraintlist; 41 private Controlset controlset; 42 private RplVector loadlist; 43 private RplVector materiallist; 44 45 46 /** 47 * FembicWriter constructor comment. 48 */ FembicWriter(RplVector nlist, RplVector elist)49 public FembicWriter(RplVector nlist, RplVector elist) { 50 super(nlist, elist); 51 } 52 FembicWriter(RplVector nlist, RplVector elist, Controlset cset, RplVector clist ,RplVector mlist, RplVector llist)53 public FembicWriter(RplVector nlist, RplVector elist, Controlset cset, RplVector clist ,RplVector mlist, RplVector llist) { 54 super(nlist, elist); 55 constraintlist = clist; 56 controlset = cset; 57 loadlist = llist; 58 materiallist = mlist; 59 } 60 61 62 /** 63 * Insert the method's description here. Creation date: (23/11/01 %T) 64 */ open()65 private void open() { 66 } 67 68 /** 69 * This method does any nessessary checking and initializations for the 70 * writer Creation date: (23/11/01 %T) 71 */ initialize()72 public void initialize() { 73 } 74 75 /** 76 * Insert the method's description here. Creation date: (07/11/01 %T) 77 */ write(String fname, double currtime)78 public void write(String fname, double currtime) throws java.io.IOException { 79 int i; 80 int j; 81 int k; 82 String type; 83 Element temp_element; 84 Node temp_node; 85 Load temp_load; 86 Constraint temp_constraint; 87 Material temp_material; 88 89 90 try { 91 92 // Open a file to write to 93 BufferedWriter bw = new BufferedWriter( new FileWriter(fname) ); 94 95 96 bw.write("# This file has been translated into Fembic format\n"); 97 bw.write("# by Impact acting as a translator. \n"); 98 bw.write("# \n"); 99 100 // Start by writing all the nodes 101 bw.write("\nNODES\n"); 102 103 for (k = 0; k < nodelist.size(); k++) { 104 105 temp_node = (Node) nodelist.elementAt(k); 106 107 if (temp_node.getNumber() >= 0) { 108 109 bw.write(temp_node.getNumber() + " \t"); 110 bw.write(" x = " + temp_node.getX_pos_orig() + " \t"); 111 bw.write(" y = " + temp_node.getY_pos_orig() + " \t"); 112 bw.write(" z = " + temp_node.getZ_pos_orig() + " \t"); 113 114 if (temp_node.getConstraint() != null) 115 bw.write(" constraint = " 116 + temp_node.getConstraint().getName() + "\t"); 117 118 if (temp_node.getLoad() != null) 119 bw.write(" load = " + temp_node.getLoad().getName() 120 + "\t"); 121 122 bw.write("\n"); 123 124 } 125 } 126 127 bw.write("\n"); 128 129 130 // Time to write all the elements. 131 // Loop through the element list and make each element of a new type 132 // write its header 133 134 for (i = 0; i < elementlist.size(); i++) { 135 temp_element = (Element) elementlist.elementAt(i); 136 137 if (! temp_element.isProcessed()) { 138 139 // We have found an unprocessed element. Print a subheader and then all data from elements of same type. 140 type = temp_element.getType(); 141 bw.write("\nELEMENTS OF TYPE " + type); 142 bw.write("\n"); 143 144 // Now, run through the array, print element data and try to find elements of the same type and mark as processed 145 146 for (j = i; j < elementlist.size(); j++) { 147 temp_element = (Element) elementlist.elementAt(j); 148 149 if ( 150 (temp_element.getType().equals(type)) && 151 ! temp_element.isProcessed() 152 ) { 153 bw.write(temp_element.print_Fembic(Element.MESH, 0)); 154 temp_element.setProcessed(true); 155 } 156 } 157 158 } 159 } 160 161 // Finished writing elements. Now set them as unprocessed. 162 for (k = 0; k < elementlist.size(); k++) { 163 ((Element) elementlist.elementAt(k)).setProcessed(false); 164 } 165 166 // Start by writing all the loads 167 168 if (loadlist.size() > 0) { 169 bw.write("\nLOADS\n"); 170 171 for (k = 0; k < loadlist.size(); k++) { 172 173 temp_load = (Load) loadlist.elementAt(k); 174 175 bw.write( temp_load.getName() + " \t" ); 176 bw.write( temp_load.print_Fembic(Element.MESH) + " \t" ); 177 178 } 179 180 bw.write("\n"); 181 } 182 183 // Time to write all the constraints. 184 // Loop through the constraint list and make each constraint of a new type write its header 185 186 if (constraintlist.size() > 0) 187 for (i = 0; i < constraintlist.size(); i++) { 188 temp_constraint = (Constraint) constraintlist.elementAt(i); 189 190 if (! temp_constraint.isProcessed()) { 191 192 // We have found an unprocessed element. Print a subheader and then all data from elements of same type. 193 type = temp_constraint.getType(); 194 bw.write("\nCONSTRAINTS OF TYPE " + type); 195 bw.write("\n"); 196 197 // Now, run through the array, print constraint data and try to find constraints of the same type and mark as processed 198 199 for (j = i; j < constraintlist.size(); j++) { 200 temp_constraint = (Constraint) constraintlist.elementAt(j); 201 202 if ( 203 (temp_constraint.getType().equals(type)) && 204 ! temp_constraint.isProcessed() 205 ) { 206 bw.write(temp_constraint.print_Fembic(Element.MESH)); 207 temp_constraint.setProcessed(true); 208 } 209 } 210 211 } 212 } 213 214 // Finished writing elements. Now set them as unprocessed. 215 for (k = 0; k < constraintlist.size(); k++) { 216 ((Constraint) constraintlist.elementAt(k)).setProcessed(false); 217 } 218 219 220 // Time to write all the materials. 221 // Loop through the material list and make each material of a new type write its header 222 223 for (i = 0; i < materiallist.size(); i++) { 224 temp_material = (Material) materiallist.elementAt(i); 225 226 if (! temp_material.isProcessed()) { 227 228 // We have found an unprocessed material. Print a subheader and then all data from materials of same type. 229 type = temp_material.getType(); 230 bw.write("\nMATERIALS OF TYPE " + type); 231 bw.write("\n"); 232 233 // Now, run through the array, print material data and try to find materials of the same type and mark as processed 234 235 for (j = i; j < materiallist.size(); j++) { 236 temp_material = (Material) materiallist.elementAt(j); 237 238 if ( 239 (temp_material.getType().equals(type)) && 240 ! temp_material.isProcessed() 241 ) { 242 bw.write(temp_material.print_Fembic(Element.MESH)); 243 temp_material.setProcessed(true); 244 } 245 } 246 247 } 248 } 249 250 // Finished writing materials. Now set them as unprocessed. 251 for (k = 0; k < materiallist.size(); k++) { 252 ((Material) materiallist.elementAt(k)).setProcessed(false); 253 } 254 255 256 257 // Write controlset 258 bw.write("\nCONTROLS\n"); 259 bw.write(controlset.print_Fembic(Element.MESH)); 260 261 262 // finished! flush and close. 263 bw.flush(); 264 bw.close(); 265 266 } catch (IOException ioe) { 267 System.out.println(ioe); 268 } 269 270 } 271 272 /** 273 * Dummy method. This will never happen. Used only for translator. 274 */ writeParallel(String fname, double time, int[] indicies, Barrier barrier, int client_nr, int nr_of_clients)275 public void writeParallel(String fname, double time, int[] indicies, Barrier barrier, int client_nr, int nr_of_clients) throws java.io.IOException { 276 277 } 278 279 280 /** 281 * This method checks that all mandatory parameters have been set 282 */ checkIndata()283 public void checkIndata() 284 throws IllegalArgumentException 285 { 286 } 287 } 288 289