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 gui;
19
20 import javax.swing.*;
21 import java.awt.*;
22 import j3d.*;
23 import j3d.utilities.*;
24
25 import java.awt.event.*;
26
27 import javax.swing.event.*;
28 import javax.swing.filechooser.FileFilter;
29 import javax.swing.tree.*;
30
31 import java.text.ParseException;
32 import java.util.*;
33
34 import javax.swing.table.*;
35
36 import com.stevesoft.pat.*;
37
38 import java.io.*;
39 /**
40 * Insert the type's description here.
41 *
42 * @author: Yuriy Mikhaylovskiy & Jonas Forssell
43 */
44
45 public class PreProcessor extends JPanel {
46 public static final String ver = "Pre Processor";
47 private String path;
48 private String CONTROLS_RUN_FROM = "0.0";
49 private String CONTROLS_RUN_TO = "1.0";
50 private String CONTROLS_RUN_STEP = "";
51 private String CONTROLS_PRINT_STEP = "0.01";
52 private String CONTROLS_PRINT_TRACKER_STEP = "";
53 private String[] graphicsmode = {"WIREFRAME","SURFACE","SOLID"};
54 public Hashtable MatDB = new Hashtable();
55 public Hashtable ConstDB = new Hashtable();
56 public Hashtable LoadDB = new Hashtable();
57 public Properties ConfDB = new Properties();
58 private int id_color = 0;
59 private String[] MatHdr = {"Name","Color","Type","Description"};
60 private String[] LoadHdr = {"Name","Color","Description"};
61 private TableModel MatModel = new AbstractTableModel() {
62 public int getColumnCount() { return 4; }
63 public int getRowCount() { return MatDB.size(); }
64 public Object getValueAt(int row, int col){
65 int i=0;
66 for(Enumeration en = MatDB.keys(); en.hasMoreElements();){
67 String key = en.nextElement()+"";
68 Material mat = (Material)MatDB.get(key);
69 if(i==row){
70 if(col==0)return key;
71 else if(col==1) return "";
72 else if(col==2) return mat.type;
73 else if(col==3) return mat.description;
74 else return "";
75 }
76 i++;
77 }
78 return "";
79 }
80 public String getColumnName(int col) {return MatHdr[col];}
81 public boolean isCellEditable(int row, int col) { if(col==3 || col==1)return true; else return false;}
82 public void setValueAt(Object aValue, int row, int col) {
83 Material mat = (Material)MatDB.get(getValueAt(row,0));
84 if(col==1)mat.color=(Color)aValue;
85 if(col==3)mat.description=aValue+"";
86 }
87 public Class getColumnClass(int c) {return getValueAt(0, c).getClass();}
88 };
89 private TableModel ConstModel = new AbstractTableModel() {
90 public int getColumnCount() { return 4; }
91 public int getRowCount() { return ConstDB.size(); }
92 public Object getValueAt(int row, int col){
93 int i=0;
94 for(Enumeration en = ConstDB.keys(); en.hasMoreElements();){
95 String key = en.nextElement()+"";
96 Constraints con = (Constraints)ConstDB.get(key);
97 if(i==row){
98 if(col==0)return key;
99 else if(col==1) return "";
100 else if(col==2) return con.type;
101 else if(col==3) return con.description;
102 else return "";
103 }
104 i++;
105 }
106 return "";
107 }
108 public String getColumnName(int col) {return MatHdr[col];}
109 public boolean isCellEditable(int row, int col) { if(col==3 || col==1)return true; else return false;}
110 public void setValueAt(Object aValue, int row, int col) {
111 Constraints con = (Constraints)ConstDB.get(getValueAt(row,0));
112 if(col==1)con.color=(Color)aValue;
113 if(col==3)con.description=aValue+"";
114 }
115 public Class getColumnClass(int c) {return getValueAt(0, c).getClass();}
116 };
117 private TableModel LoadModel = new AbstractTableModel() {
118 public int getColumnCount() { return 3; }
119 public int getRowCount() { return LoadDB.size(); }
120 public Object getValueAt(int row, int col){
121 int i=0;
122 for(Enumeration en = LoadDB.keys(); en.hasMoreElements();){
123 String key = en.nextElement()+"";
124 Loads ld = (Loads)LoadDB.get(key);
125 if(i==row){
126 if(col==0)return key;
127 else if(col==1) return "";
128 else if(col==2) return ld.description;
129 else return "";
130 }
131 i++;
132 }
133 return "";
134 }
135 public String getColumnName(int col) {return LoadHdr[col];}
136 public boolean isCellEditable(int row, int col) { if(col==2 || col==1)return true; else return false;}
137 public void setValueAt(Object aValue, int row, int col) {
138 Loads ld = (Loads)LoadDB.get(getValueAt(row,0));
139 if(col==1)ld.color=(Color)aValue;
140 if(col==2)ld.description=aValue+"";
141 }
142 public Class getColumnClass(int c) {return getValueAt(0, c).getClass();}
143 };
144
145 private JTable MatTable = new JTable(MatModel){
146 public TableCellRenderer getCellRenderer(int row, int column) {
147 if(column == 1) {
148 DefaultTableCellRenderer render = new DefaultTableCellRenderer();
149 render.setBackground(((Material)MatDB.get(getValueAt(row,0))).color);
150 render.setForeground(((Material)MatDB.get(getValueAt(row,0))).color);
151 return render;
152 }else return super.getCellRenderer(row, column);
153 }
154 public TableCellEditor getCellEditor(int row, int column) {
155 if(column == 1) {
156 Color cl = JColorChooser.showDialog(this,"Pick a Color",((Material)MatDB.get(getValueAt(row,0))).color);
157 if(cl!=null)((Material)MatDB.get(getValueAt(row,0))).color=cl;
158 }
159 return super.getCellEditor(row, column);
160 }
161 };
162 private JTable ConstTable = new JTable(ConstModel){
163 public TableCellRenderer getCellRenderer(int row, int column) {
164 if(column == 1) {
165 DefaultTableCellRenderer render = new DefaultTableCellRenderer();
166 render.setBackground(((Constraints)ConstDB.get(getValueAt(row,0))).color);
167 render.setForeground(((Constraints)ConstDB.get(getValueAt(row,0))).color);
168 return render;
169 }else return super.getCellRenderer(row, column);
170 }
171 public TableCellEditor getCellEditor(int row, int column) {
172 if(column == 1) {
173 Color cl = JColorChooser.showDialog(this,"Pick a Color",((Constraints)ConstDB.get(getValueAt(row,0))).color);
174 if(cl!=null)((Constraints)ConstDB.get(getValueAt(row,0))).color=cl;
175 }
176 return super.getCellEditor(row, column);
177 }
178 };
179 private JTable LoadTable = new JTable(LoadModel){
180 public TableCellRenderer getCellRenderer(int row, int column) {
181 if(column == 1) {
182 DefaultTableCellRenderer render = new DefaultTableCellRenderer();
183 render.setBackground(((Loads)LoadDB.get(getValueAt(row,0))).color);
184 render.setForeground(((Loads)LoadDB.get(getValueAt(row,0))).color);
185 return render;
186 }else return super.getCellRenderer(row, column);
187 }
188 public TableCellEditor getCellEditor(int row, int column) {
189 if(column == 1) {
190 Color cl = JColorChooser.showDialog(this,"Pick a Color",((Loads)LoadDB.get(getValueAt(row,0))).color);
191 if(cl!=null)((Loads)LoadDB.get(getValueAt(row,0))).color=cl;
192 }
193 return super.getCellEditor(row, column);
194 }
195 };
196
197 ImageIcon img_new = new ImageIcon(PreProcessor.class.getResource("new.gif"));
198 ImageIcon img_open = new ImageIcon(PreProcessor.class.getResource("open.gif"));
199 ImageIcon img_save = new ImageIcon(PreProcessor.class.getResource("save.gif"));
200 ImageIcon img_list = new ImageIcon(PreProcessor.class.getResource("list.gif"));
201 ImageIcon img_add = new ImageIcon(PreProcessor.class.getResource("add.gif"));
202 ImageIcon img_groupadd = new ImageIcon(PreProcessor.class.getResource("groupadd.png"));
203
204 ImageIcon img_zoomin = new ImageIcon(PreProcessor.class.getResource("zoomin.gif"));
205 ImageIcon img_zoomout = new ImageIcon(PreProcessor.class.getResource("zoomout.gif"));
206 ImageIcon img_zoomall = new ImageIcon(PreProcessor.class.getResource("zooma.gif"));
207 ImageIcon img_center = new ImageIcon(PreProcessor.class.getResource("center.png"));
208 ImageIcon img_show = new ImageIcon(PreProcessor.class.getResource("show.png"));
209 ImageIcon img_hide = new ImageIcon(PreProcessor.class.getResource("hide.png"));
210 ImageIcon img_view_top = new ImageIcon(PreProcessor.class.getResource("view_top.gif"));
211 ImageIcon img_view_bottom = new ImageIcon(PreProcessor.class.getResource("view_bottom.gif"));
212 ImageIcon img_view_left = new ImageIcon(PreProcessor.class.getResource("view_left.gif"));
213 ImageIcon img_view_right = new ImageIcon(PreProcessor.class.getResource("view_right.gif"));
214 ImageIcon img_view_front = new ImageIcon(PreProcessor.class.getResource("view_front.gif"));
215 ImageIcon img_view_back = new ImageIcon(PreProcessor.class.getResource("view_back.gif"));
216 ImageIcon img_view_sw = new ImageIcon(PreProcessor.class.getResource("view_sw.gif"));
217 ImageIcon img_view_se = new ImageIcon(PreProcessor.class.getResource("view_se.gif"));
218 ImageIcon img_view_ne = new ImageIcon(PreProcessor.class.getResource("view_ne.gif"));
219 ImageIcon img_view_nw = new ImageIcon(PreProcessor.class.getResource("view_nw.gif"));
220 ImageIcon img_config = new ImageIcon(PreProcessor.class.getResource("config.gif"));
221 ImageIcon img_build = new ImageIcon(PreProcessor.class.getResource("build.png"));
222
223 ImageIcon img_point = new ImageIcon(PreProcessor.class.getResource("node.png"));
224 ImageIcon img_arc = new ImageIcon(PreProcessor.class.getResource("arc.png"));
225 ImageIcon img_nurbcurve = new ImageIcon(PreProcessor.class.getResource("nurbcurve.gif"));
226
227 ImageIcon img_surf_dir = new ImageIcon(PreProcessor.class.getResource("surf_dir.gif"));
228 ImageIcon img_surf_rev = new ImageIcon(PreProcessor.class.getResource("surf_rev.gif"));
229 ImageIcon img_surf_rule = new ImageIcon(PreProcessor.class.getResource("surf_rule.gif"));
230 ImageIcon img_surf_nurb = new ImageIcon(PreProcessor.class.getResource("surf_nurb.gif"));
231 ImageIcon img_surf_bil = new ImageIcon(PreProcessor.class.getResource("surf_bil.png"));
232
233 ImageIcon img_border = new ImageIcon(PreProcessor.class.getResource("border.png"));
234 ImageIcon img_intersect = new ImageIcon(PreProcessor.class.getResource("intersect.png"));
235 ImageIcon img_project = new ImageIcon(PreProcessor.class.getResource("project.png"));
236 ImageIcon img_break = new ImageIcon(PreProcessor.class.getResource("break.png"));
237
238 ImageIcon img_node = new ImageIcon(PreProcessor.class.getResource("node.png"));
239 ImageIcon img_beam = new ImageIcon(PreProcessor.class.getResource("beam.png"));
240 ImageIcon img_spring = new ImageIcon(PreProcessor.class.getResource("spring.gif"));
241 ImageIcon img_triangle = new ImageIcon(PreProcessor.class.getResource("triangle.png"));
242 ImageIcon img_quad = new ImageIcon(PreProcessor.class.getResource("quad.png"));
243 ImageIcon img_solid_iso_4 = new ImageIcon(PreProcessor.class.getResource("solid_iso_4.gif"));
244 ImageIcon img_solid_iso_6 = new ImageIcon(PreProcessor.class.getResource("solid_iso_6.gif"));
245 ImageIcon img_material = new ImageIcon(PreProcessor.class.getResource("material.gif"));
246 ImageIcon img_thickness = new ImageIcon(PreProcessor.class.getResource("thickness.png"));
247
248 ImageIcon img_erase = new ImageIcon(PreProcessor.class.getResource("erase.gif"));
249 ImageIcon img_move = new ImageIcon(PreProcessor.class.getResource("move.gif"));
250 ImageIcon img_rotate = new ImageIcon(PreProcessor.class.getResource("rotate.gif"));
251 ImageIcon img_scale = new ImageIcon(PreProcessor.class.getResource("scale.gif"));
252 ImageIcon img_transform = new ImageIcon(PreProcessor.class.getResource("transform.gif"));
253 ImageIcon img_properties = new ImageIcon(PreProcessor.class.getResource("properties.gif"));
254 ImageIcon img_duplicate = new ImageIcon(PreProcessor.class.getResource("duplicate.png"));
255
256 ImageIcon img_constraints = new ImageIcon(PreProcessor.class.getResource("constraints.gif"));
257 ImageIcon img_loads = new ImageIcon(PreProcessor.class.getResource("loads.gif"));
258
259 ImageIcon img_grid = new ImageIcon(PreProcessor.class.getResource("grid.gif"));
260
261 BorderLayout borderLayout1 = new BorderLayout();
262 JSplitPane jSplitPane1 = new JSplitPane();
263 JPanel PanelInspector = new JPanel();
264 private Canvas3D J3D;
265 JToolBar jToolBar1 = new JToolBar();
266 JButton b_new = new JButton();
267 JButton b_open = new JButton();
268 JButton b_save = new JButton();
269 JButton b_groupadd = new JButton();
270
271 JPanel jPanel1 = new JPanel();
272 GridLayout gridLayout1 = new GridLayout();
273 JLabel coordinates = new JLabel();
274 JToolBar jToolBar2 = new JToolBar();
275 JToolBar jToolBar3 = new JToolBar();
276 BorderLayout borderLayout2 = new BorderLayout();
277 ButtonGroup CommandGroup = new ButtonGroup();
278 JPanel jPanel5 = new JPanel();
279 JPanel jPanel6 = new JPanel();
280 JButton b_zoomin = new JButton();
281 JButton b_zoomout = new JButton();
282 JButton b_zoomall = new JButton();
283 JButton b_center = new JButton();
284 JButton b_showhide = new JButton();
285 JButton b_viewtop = new JButton();
286 JButton b_viewleft = new JButton();
287 JButton b_viewsw = new JButton();
288 JButton b_viewne = new JButton();
289 JButton b_viewse = new JButton();
290 JButton b_viewbottom = new JButton();
291 JButton b_viewright = new JButton();
292 JButton b_viewnw = new JButton();
293 JButton b_viewfront = new JButton();
294 JButton b_viewback = new JButton();
295 JButton b_build = new JButton();
296
297 BorderLayout borderLayout4 = new BorderLayout();
298 JTabbedPane jTabbedPane2 = new JTabbedPane();
299 JToolBar jToolBar6 = new JToolBar();
300 JToolBar jToolBar5 = new JToolBar();
301 JButton b_point = new JButton();
302 JButton b_erase = new JButton();
303 JButton b_duplicate = new JButton();
304 JButton b_move = new JButton();
305 JButton b_rotate = new JButton();
306 JComboBox cb_graphicsmode = new JComboBox(graphicsmode);
307 JButton b_del = new JButton();
308 JToolBar jToolBar4 = new JToolBar();
309 JScrollPane jScrollPane1 = new JScrollPane();
310 JTree Tree = new JTree();
311 JButton b_scale = new JButton();
312 JButton b_node = new JButton();
313 JButton b_element2 = new JButton();
314 JButton b_element3 = new JButton();
315 JButton b_element4 = new JButton();
316 private JButton b_config = new JButton();
317 private JPanel p_cmd = new JPanel();
318 private JButton b_element8 = new JButton();
319 private JButton b_surf_dir = new JButton();
320 private JButton b_surf_rev = new JButton();
321 private JButton b_surf_rule = new JButton();
322 private JButton b_nurbcurve = new JButton();
323 private JButton b_surf_bil = new JButton();
324
325 private JButton b_border = new JButton();
326 private JButton b_intersect = new JButton();
327 private JButton b_project = new JButton();
328 private JButton b_break = new JButton();
329
330 private JButton b_arc = new JButton();
331 private JButton b_material = new JButton();
332 private JButton b_constraints = new JButton();
333 private JButton b_loads = new JButton();
334 JCheckBox cb_node_0 = new JCheckBox("Nodes",true);
335 JCheckBox cb_node = new JCheckBox("Nodes label",false);
336 JCheckBox cb_element = new JCheckBox("Elements label",false);
337 JCheckBox cb_constraints = new JCheckBox("Constraints",true);
338 JCheckBox cb_loads = new JCheckBox("Loads",true);
339 JCheckBox cb_trackers = new JCheckBox("Trackers",true);
340 JCheckBox cb_materials = new JCheckBox("Materials",true);
341 private JButton b_setmaterial = new JButton();
342 private JButton b_setthickness = new JButton();
343 private JButton c_setconstraints = new JButton();
344 private JButton b_setloads = new JButton();
345 private JButton b_transform = new JButton();
346 private JButton b_surf_nurb = new JButton();
347 private JButton b_grid = new JButton();
348 private JButton b_properties = new JButton();
349 private JButton b_element3s = new JButton();
350
351 public _Object edit_panel;
352 private boolean block = false;
353 private boolean show = true;
354 private JButton b_element4s = new JButton();
355
PreProcessor(boolean ogl)356 public PreProcessor(boolean ogl) {
357 try { jbInit(ogl); } catch(Exception e) { e.printStackTrace(); }
358 }
exit()359 public void exit(){
360 save_loads();
361 save_materials();
362 save_constraints();
363 System.out.println("PreProcessor finalize.");
364 }
jbInit(boolean openGL)365 private void jbInit(boolean openGL) throws Exception {
366 J3D = CanvasFactory.getCanvas(this,openGL);
367 load_materials();
368 load_constraints();
369 load_loads();
370 load_configuration();
371 MatTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
372 MatTable.getColumnModel().getColumn(3).setPreferredWidth(500);
373 ConstTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
374 ConstTable.getColumnModel().getColumn(3).setPreferredWidth(500);
375 LoadTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
376 LoadTable.getColumnModel().getColumn(2).setPreferredWidth(500);
377 this.setLayout(borderLayout1);
378 jSplitPane1.setMinimumSize(new Dimension(0, 0));
379 jSplitPane1.setPreferredSize(new Dimension(0, 0));
380 jSplitPane1.setLastDividerLocation(220);
381 jSplitPane1.setOneTouchExpandable(true);
382 PanelInspector.setMinimumSize(new Dimension(0, 0));
383 PanelInspector.setPreferredSize(new Dimension(0, 0));
384 PanelInspector.setLayout(borderLayout2);
385
386 b_new.setToolTipText("New");
387 b_new.setIcon(img_new);
388 b_new.addActionListener(new java.awt.event.ActionListener() {
389 public void actionPerformed(ActionEvent e) {
390 J3D.remove_all();
391 p_cmd.removeAll();
392 p_cmd.validate();
393 PanelInspector.validate();
394 }
395 });
396 b_open.setToolTipText("Open .impact models or add .stl, .in models to current model");
397 b_open.setIcon(img_open);
398 b_open.addActionListener(new java.awt.event.ActionListener() {
399 public void actionPerformed(ActionEvent e) {
400 try {
401 b_open_actionPerformed(e);
402 } catch(Exception e1) {error(e1);}
403 }
404 });
405 b_save.setToolTipText("Save complete model (.impact) or model for solver (.in)");
406 b_save.setIcon(img_save);
407 b_save.addActionListener(new java.awt.event.ActionListener() {
408 public void actionPerformed(ActionEvent e) {
409 b_save_actionPerformed(e);
410 }
411 });
412 b_groupadd.setToolTipText("Add a new group");
413 b_groupadd.setActionCommand("Groupadd");
414 b_groupadd.setIcon(img_groupadd);
415 b_groupadd.addActionListener(new java.awt.event.ActionListener() {
416 public void actionPerformed(ActionEvent e) {
417 command(e);
418 }
419 });
420 b_build.setToolTipText("Rebuild model");
421 b_build.setIcon(img_build);
422 b_build.addActionListener(new java.awt.event.ActionListener() {
423 public void actionPerformed(ActionEvent e) {
424 J3D.rebuild();
425 }
426 });
427 jPanel1.setLayout(gridLayout1);
428 gridLayout1.setColumns(3);
429 jToolBar1.setFloatable(false);
430 b_zoomin.setToolTipText("Zoom in");
431 b_zoomin.setIcon(img_zoomin);
432 b_zoomin.addActionListener(new java.awt.event.ActionListener() {
433 public void actionPerformed(ActionEvent e) {
434 b_zoomin_actionPerformed(e);
435 }
436 });
437 b_zoomout.setToolTipText("Zoom out");
438 b_zoomout.setIcon(img_zoomout);
439 b_zoomout.addActionListener(new java.awt.event.ActionListener() {
440 public void actionPerformed(ActionEvent e) {
441 b_zoomout_actionPerformed(e);
442 }
443 });
444 b_zoomall.setToolTipText("Zoom all");
445 b_zoomall.setIcon(img_zoomall);
446 b_zoomall.addActionListener(new java.awt.event.ActionListener() {
447 public void actionPerformed(ActionEvent e) {
448 b_zoomall_actionPerformed(e);
449 }
450 });
451 b_center.setToolTipText("Set the selected object to center of rotation");
452 b_center.setIcon(img_center);
453 b_center.addActionListener(new java.awt.event.ActionListener() {
454 public void actionPerformed(ActionEvent e) {
455 J3D.setCenterOfRotation();
456 }
457 });
458 b_showhide.setToolTipText("Hides or shows the selected objects. Press this without anything selected to switch view");
459 b_showhide.setIcon(img_hide);
460 b_showhide.addActionListener(new java.awt.event.ActionListener() {
461 public void actionPerformed(ActionEvent e) {
462 show = J3D.showhide();
463
464 if (show) b_showhide.setIcon(img_hide);
465 else b_showhide.setIcon(img_show);
466
467 }
468 });
469 b_viewtop.setToolTipText("Top View");
470 b_viewtop.setIcon(img_view_top);
471 b_viewtop.addActionListener(new java.awt.event.ActionListener() {
472 public void actionPerformed(ActionEvent e) {
473 b_viewtop_actionPerformed(e);
474 }
475 });
476 b_viewbottom.setToolTipText("Bottom View");
477 b_viewbottom.setIcon(img_view_bottom);
478 b_viewbottom.addActionListener(new java.awt.event.ActionListener() {
479 public void actionPerformed(ActionEvent e) {
480 b_viewbottom_actionPerformed(e);
481 }
482 });
483 b_viewleft.setToolTipText("Left View");
484 b_viewleft.setIcon(img_view_left);
485 b_viewleft.addActionListener(new java.awt.event.ActionListener() {
486 public void actionPerformed(ActionEvent e) {
487 b_viewleft_actionPerformed(e);
488 }
489 });
490 b_viewright.setToolTipText("Right View");
491 b_viewright.setIcon(img_view_right);
492 b_viewright.addActionListener(new java.awt.event.ActionListener() {
493 public void actionPerformed(ActionEvent e) {
494 b_viewright_actionPerformed(e);
495 }
496 });
497 b_viewsw.setToolTipText("SW Isometric View");
498 b_viewsw.setIcon(img_view_sw);
499 b_viewsw.addActionListener(new java.awt.event.ActionListener() {
500 public void actionPerformed(ActionEvent e) {
501 b_viewsw_actionPerformed(e);
502 }
503 });
504 b_viewse.setToolTipText("SE Isometric View");
505 b_viewse.setIcon(img_view_se);
506 b_viewse.addActionListener(new java.awt.event.ActionListener() {
507 public void actionPerformed(ActionEvent e) {
508 b_viewse_actionPerformed(e);
509 }
510 });
511 b_viewne.setToolTipText("NE Isometric View");
512 b_viewne.setIcon(img_view_ne);
513 b_viewne.addActionListener(new java.awt.event.ActionListener() {
514 public void actionPerformed(ActionEvent e) {
515 b_viewne_actionPerformed(e);
516 }
517 });
518 b_viewnw.setToolTipText("NW Isometric View");
519 b_viewnw.setIcon(img_view_nw);
520 b_viewnw.addActionListener(new java.awt.event.ActionListener() {
521 public void actionPerformed(ActionEvent e) {
522 b_viewnw_actionPerformed(e);
523 }
524 });
525 b_viewfront.setToolTipText("Front View");
526 b_viewfront.setIcon(img_view_front);
527 b_viewfront.addActionListener(new java.awt.event.ActionListener() {
528 public void actionPerformed(ActionEvent e) {
529 b_viewfront_actionPerformed(e);
530 }
531 });
532 b_viewback.setToolTipText("Back View");
533 b_viewback.setIcon(img_view_back);
534 b_viewback.addActionListener(new java.awt.event.ActionListener() {
535 public void actionPerformed(ActionEvent e) {
536 b_viewback_actionPerformed(e);
537 }
538 });
539 jPanel5.setLayout(borderLayout4);
540 coordinates.setText(" ");
541 jToolBar6.setFloatable(false);
542 jToolBar5.setFloatable(false);
543 b_point.setToolTipText("Point");
544 b_point.setActionCommand("Point");
545 b_point.setIcon(img_point);
546 b_point.addActionListener(new java.awt.event.ActionListener() {
547 public void actionPerformed(ActionEvent e) {
548 command(e);
549 }
550 });
551 b_erase.setToolTipText("Erase");
552 b_erase.setActionCommand("Erase");
553 b_erase.setIcon(img_erase);
554 b_erase.addActionListener(new java.awt.event.ActionListener() {
555 public void actionPerformed(ActionEvent e) {
556 resetselect();
557 J3D.removeSelectedObjects3D();
558 }
559 });
560 b_move.setToolTipText("Move");
561 b_move.setActionCommand("Move");
562 b_move.setIcon(img_move);
563 b_move.addActionListener(new java.awt.event.ActionListener() {
564 public void actionPerformed(ActionEvent e) {
565 command(e);
566 }
567 });
568 b_rotate.setToolTipText("Rotate");
569 b_rotate.setActionCommand("Rotate");
570 b_rotate.setIcon(img_rotate);
571 b_rotate.addActionListener(new java.awt.event.ActionListener() {
572 public void actionPerformed(ActionEvent e) {
573 command(e);
574 }
575 });
576 cb_graphicsmode.setPreferredSize(new Dimension(25, 21));
577 cb_graphicsmode.setToolTipText("Graphics mode");
578 cb_graphicsmode.setSelectedIndex(1);
579 J3D.setGRAPHICSMODE(Canvas3D.GRAPHICSMODE_SURFACE);
580 cb_graphicsmode.addItemListener(new java.awt.event.ItemListener() {
581 public void itemStateChanged(ItemEvent e) {
582 cb_graphicsmode_itemStateChanged(e);
583 }
584 });
585 b_del.setToolTipText("Erase");
586 b_del.setActionCommand("Erase");
587 b_del.setIcon(img_erase);
588 b_del.addActionListener(new java.awt.event.ActionListener() {
589 public void actionPerformed(ActionEvent e) {
590 resetselect();
591 J3D.removeSelectedObjects3D();
592 }
593 });
594 jToolBar4.setFloatable(false);
595
596 Tree.setModel(J3D.getTree3d());
597 Tree.setRootVisible(false);
598 Tree.setShowsRootHandles(true);
599 Tree.addMouseListener(new MouseAdapter(){
600 public void mouseClicked(MouseEvent e){
601 showEditPanel(e);
602 }
603 });
604 Tree.addTreeSelectionListener(new TreeSelectionListener() {
605 public void valueChanged(TreeSelectionEvent e) {
606 if (!block)
607 treeSelectionChanged();
608 }
609 });
610 Tree.addKeyListener(new KeyAdapter() {
611 public void keyReleased(KeyEvent e) {
612 int c = e.getKeyCode();
613 if (c == KeyEvent.VK_DELETE) {
614 resetselect();
615 J3D.removeSelectedObjects3D();
616 }
617 }
618 });
619
620 b_scale.setToolTipText("Scale");
621 b_scale.setActionCommand("Scale");
622 b_scale.setIcon(img_scale);
623 b_scale.addActionListener(new java.awt.event.ActionListener() {
624 public void actionPerformed(ActionEvent e) {
625 command(e);
626 }
627 });
628 b_node.setToolTipText("Node");
629 b_node.setActionCommand("Node");
630 b_node.setIcon(img_node);
631 b_node.addActionListener(new ActionListener() {
632 public void actionPerformed(ActionEvent e) {
633 command(e);
634 }
635 });
636 b_element2.setToolTipText("Elements with 2 nodes");
637 b_element2.setActionCommand("Element2");
638 b_element2.setIcon(img_beam);
639 b_element2.addActionListener(new java.awt.event.ActionListener() {
640 public void actionPerformed(ActionEvent e) {
641 command(e);
642 }
643 });
644 b_element3.setToolTipText("Elements with 3 nodes");
645 b_element3.setActionCommand("Element3");
646 b_element3.setIcon(img_triangle);
647 b_element3.addActionListener(new java.awt.event.ActionListener() {
648 public void actionPerformed(ActionEvent e) {
649 command(e);
650 }
651 });
652 b_element4.setToolTipText("Elements with 4 nodes");
653 b_element4.setActionCommand("Element4");
654 b_element4.setIcon(img_quad);
655 b_element4.addActionListener(new java.awt.event.ActionListener() {
656 public void actionPerformed(ActionEvent e) {
657 command(e);
658 }
659 });
660 b_config.setToolTipText("Properties");
661 b_config.setIcon(img_config);
662 b_config.addActionListener(new java.awt.event.ActionListener() {
663 public void actionPerformed(ActionEvent e) {
664 b_config_actionPerformed(e);
665 }
666 });
667 b_element8.setToolTipText("Elements with 8 nodes");
668 b_element8.setActionCommand("Element8");
669 b_element8.setIcon(img_solid_iso_6);
670 b_element8.addActionListener(new java.awt.event.ActionListener() {
671 public void actionPerformed(ActionEvent e) {
672 command(e);
673 }
674 });
675 b_surf_dir.setToolTipText("Tabulated surface from a path curve and a direction");
676 b_surf_dir.setActionCommand("SurfDir");
677 b_surf_dir.setIcon(img_surf_dir);
678 b_surf_dir.addActionListener(new java.awt.event.ActionListener() {
679 public void actionPerformed(ActionEvent e) {
680 command(e);
681 }
682 });
683 b_surf_rev.setToolTipText("Revolved surface about a selected axis");
684 b_surf_rev.setActionCommand("SurfRev");
685 b_surf_rev.setIcon(img_surf_rev);
686 b_surf_rev.addActionListener(new java.awt.event.ActionListener() {
687 public void actionPerformed(ActionEvent e) {
688 command(e);
689 }
690 });
691 b_surf_rule.setToolTipText("Ruled surface between curves");
692 b_surf_rule.setActionCommand("SurfRul");
693 b_surf_rule.setIcon(img_surf_rule);
694 b_surf_rule.addActionListener(new java.awt.event.ActionListener() {
695 public void actionPerformed(ActionEvent e) {
696 command(e);
697 }
698 });
699 b_surf_bil.setToolTipText("Bilinear surface between edge points");
700 b_surf_bil.setActionCommand("SurfBil");
701 b_surf_bil.setIcon(img_surf_bil);
702 b_surf_bil.addActionListener(new java.awt.event.ActionListener() {
703 public void actionPerformed(ActionEvent e) {
704 command(e);
705 }
706 });
707
708 b_border.setToolTipText("Extract border curves from surfaces or end points from curves. Select object and then press this button");
709 b_border.setActionCommand("Border");
710 b_border.setIcon(img_border);
711 b_border.addActionListener(new java.awt.event.ActionListener() {
712 public void actionPerformed(ActionEvent e) {
713 command(e);
714 }
715 });
716
717 b_intersect.setToolTipText("Intersect two objects and generate resulting point or curve. Just select two objects and then press this button");
718 b_intersect.setActionCommand("Intersect");
719 b_intersect.setIcon(img_intersect);
720 b_intersect.addActionListener(new java.awt.event.ActionListener() {
721 public void actionPerformed(ActionEvent e) {
722 command(e);
723 }
724 });
725
726 b_project.setToolTipText("Project one object onto another object generating a resulting point or curve. Just select two objects and then press this button");
727 b_project.setActionCommand("Project");
728 b_project.setIcon(img_project);
729 b_project.addActionListener(new java.awt.event.ActionListener() {
730 public void actionPerformed(ActionEvent e) {
731 command(e);
732 }
733 });
734
735 b_break.setToolTipText("Break a curve using another object. Just select the curve and object and then press this button");
736 b_break.setActionCommand("Break");
737 b_break.setIcon(img_break);
738 b_break.addActionListener(new java.awt.event.ActionListener() {
739 public void actionPerformed(ActionEvent e) {
740 command(e);
741 }
742 });
743
744 b_arc.setToolTipText("Arc");
745 b_arc.setActionCommand("Arc");
746 b_arc.setIcon(img_arc);
747 b_arc.addActionListener(new java.awt.event.ActionListener() {
748 public void actionPerformed(ActionEvent e) {
749 command(e);
750 }
751 });
752 b_nurbcurve.setToolTipText("Spline");
753 b_nurbcurve.setActionCommand("Spline");
754 b_nurbcurve.setIcon(img_nurbcurve);
755 b_nurbcurve.addActionListener(new java.awt.event.ActionListener() {
756 public void actionPerformed(ActionEvent e) {
757 command(e);
758 }
759 });
760 b_material.setToolTipText("Materials");
761 b_material.setActionCommand("Material");
762 b_material.setIcon(img_material);
763 b_material.addActionListener(new ActionListener() {
764 public void actionPerformed(ActionEvent e) {
765 b_material_actionPerformed(e);
766 }
767 });
768 b_constraints.setToolTipText("Constraints");
769 b_constraints.setActionCommand("Constraints");
770 b_constraints.setIcon(img_constraints);
771 b_constraints.addActionListener(new java.awt.event.ActionListener() {
772 public void actionPerformed(ActionEvent e) {
773 b_constraints_actionPerformed(e);
774 }
775 });
776 b_loads.setToolTipText("Loads");
777 b_loads.setActionCommand("Loads");
778 b_loads.setIcon(img_loads);
779 b_loads.addActionListener(new java.awt.event.ActionListener() {
780 public void actionPerformed(ActionEvent e) {
781 b_loads_actionPerformed(e);
782 }
783 });
784 b_setmaterial.setToolTipText("Material for ...");
785 b_setmaterial.setActionCommand("SetMaterial");
786 b_setmaterial.setIcon(img_material);
787 b_setmaterial.addActionListener(new java.awt.event.ActionListener() {
788 public void actionPerformed(ActionEvent e) {
789 command(e);
790 }
791 });
792 b_setthickness.setToolTipText("Set thickness for ...");
793 b_setthickness.setActionCommand("SetThickness");
794 b_setthickness.setIcon(img_thickness);
795 b_setthickness.addActionListener(new java.awt.event.ActionListener() {
796 public void actionPerformed(ActionEvent e) {
797 command(e);
798 }
799 });
800 c_setconstraints.setToolTipText("Constraints for ...");
801 c_setconstraints.setActionCommand("SetConstraints");
802 c_setconstraints.setIcon(img_constraints);
803 c_setconstraints.addActionListener(new java.awt.event.ActionListener() {
804 public void actionPerformed(ActionEvent e) {
805 command(e);
806 }
807 });
808 b_setloads.setToolTipText("Loads for ...");
809 b_setloads.setActionCommand("SetLoads");
810 b_setloads.setIcon(img_loads);
811 b_setloads.addActionListener(new java.awt.event.ActionListener() {
812 public void actionPerformed(ActionEvent e) {
813 command(e);
814 }
815 });
816 b_transform.setToolTipText("Transform 4X4");
817 b_transform.setActionCommand("Transform");
818 b_transform.setIcon(img_transform);
819 b_transform.addActionListener(new java.awt.event.ActionListener() {
820 public void actionPerformed(ActionEvent e) {
821 command(e);
822 }
823 });
824 b_surf_nurb.setIcon(img_surf_nurb);
825 b_surf_nurb.addActionListener(new java.awt.event.ActionListener() {
826 public void actionPerformed(ActionEvent e) {
827 command(e);
828 }
829 });
830 b_surf_nurb.setToolTipText("Surface from edge curves");
831 b_surf_nurb.setActionCommand("SurfNurb");
832 b_grid.setToolTipText("Grid");
833 b_grid.setActionCommand("Grid");
834 b_grid.setIcon(img_grid);
835 b_grid.addActionListener(new java.awt.event.ActionListener() {
836 public void actionPerformed(ActionEvent e) {
837 command(e);
838 }
839 });
840 b_properties.addActionListener(new java.awt.event.ActionListener() {
841 public void actionPerformed(ActionEvent e) {
842 command(e);
843 }
844 });
845 b_properties.setIcon(img_properties);
846 b_properties.setActionCommand("Properties");
847 b_properties.setToolTipText("Properties");
848 b_duplicate.addActionListener(new java.awt.event.ActionListener() {
849 public void actionPerformed(ActionEvent e) {
850 J3D.duplicate();
851 }
852 });
853 b_duplicate.setIcon(img_duplicate);
854 b_duplicate.setActionCommand("Duplicate");
855 b_duplicate.setToolTipText("Duplicate");
856 b_element3s.setToolTipText("Element Spring");
857 b_element3s.setActionCommand("Element3s");
858 b_element3s.setIcon(img_spring);
859 b_element4s.setToolTipText("Solid elements with 4 nodes");
860 b_element4s.setActionCommand("Element4s");
861 b_element4s.setIcon(img_solid_iso_4);
862 b_element4s.addActionListener(new java.awt.event.ActionListener() {
863 public void actionPerformed(ActionEvent e) {
864 command(e);
865 }
866 });
867
868 this.add(jSplitPane1, BorderLayout.CENTER);
869 jSplitPane1.add(PanelInspector, JSplitPane.TOP);
870 PanelInspector.add(jToolBar4, BorderLayout.NORTH);
871 jToolBar4.add(cb_graphicsmode);
872 PanelInspector.add(jScrollPane1, BorderLayout.CENTER);
873 PanelInspector.add(p_cmd, BorderLayout.SOUTH);
874 jScrollPane1.getViewport().add(Tree);
875
876 jPanel6.setLayout(new BorderLayout());
877 if (J3D instanceof Canvas3DGL)
878 jPanel6.add((Canvas3DGL)J3D, BorderLayout.CENTER);
879 else
880 jPanel6.add((JPanel)J3D, BorderLayout.CENTER);
881
882 jPanel5.add(jPanel6, BorderLayout.CENTER);
883
884 jPanel5.add(jTabbedPane2, BorderLayout.NORTH);
885
886 jTabbedPane2.add(jToolBar5, "Draw");
887 jToolBar5.add(b_point, null);
888 jToolBar5.add(b_nurbcurve, null);
889 jToolBar5.add(b_arc, null);
890 jToolBar5.addSeparator();
891 jToolBar5.add(b_surf_dir, null);
892 jToolBar5.add(b_surf_rev, null);
893 jToolBar5.add(b_surf_rule, null);
894 jToolBar5.add(b_surf_nurb, null);
895 jToolBar5.add(b_surf_bil, null);
896 jToolBar5.addSeparator();
897 jToolBar5.add(b_border, null);
898 jToolBar5.add(b_intersect, null);
899 jToolBar5.add(b_project, null);
900 jToolBar5.add(b_break, null);
901 jToolBar5.addSeparator();
902 jToolBar5.add(b_node, null);
903 jToolBar5.add(b_element2, null);
904 jToolBar5.add(b_element3s, null);
905 jToolBar5.add(b_element3, null);
906 jToolBar5.add(b_element4, null);
907 jToolBar5.add(b_element4s, null);
908 jToolBar5.add(b_element8, null);
909
910 jTabbedPane2.add(jToolBar6, "Modify");
911 jToolBar6.add(b_duplicate,null);
912 jToolBar6.add(b_erase, null);
913 jToolBar6.add(b_move, null);
914 jToolBar6.add(b_rotate, null);
915 jToolBar6.add(b_scale, null);
916 jToolBar6.add(b_transform, null);
917 jToolBar6.addSeparator();
918 jToolBar6.add(b_setmaterial, null);
919 jToolBar6.add(b_setthickness, null);
920 jToolBar6.add(c_setconstraints, null);
921 jToolBar6.add(b_setloads, null);
922 jToolBar6.addSeparator();
923 jToolBar6.add(b_grid, null);
924 jSplitPane1.add(jPanel5, JSplitPane.BOTTOM);
925
926 this.add(jToolBar1, BorderLayout.NORTH);
927 jToolBar1.add(b_new, null);
928 jToolBar1.add(b_open, null);
929 jToolBar1.add(b_save, null);
930 jToolBar1.addSeparator();
931 jToolBar1.add(b_groupadd, null);
932 jToolBar1.add(b_build, null);
933 jToolBar1.addSeparator();
934 jToolBar1.add(b_showhide, null);
935 jToolBar1.add(b_zoomin, null);
936 jToolBar1.add(b_zoomout, null);
937 jToolBar1.add(b_zoomall, null);
938 jToolBar1.add(b_center,null);
939 jToolBar1.addSeparator();
940 jToolBar1.add(b_viewtop, null);
941 jToolBar1.add(b_viewbottom, null);
942 jToolBar1.add(b_viewleft, null);
943 jToolBar1.add(b_viewright, null);
944 jToolBar1.add(b_viewfront, null);
945 jToolBar1.add(b_viewback, null);
946 jToolBar1.add(b_viewsw, null);
947 jToolBar1.add(b_viewse, null);
948 jToolBar1.add(b_viewne, null);
949 jToolBar1.add(b_viewnw, null);
950 jToolBar1.addSeparator();
951 jToolBar1.add(b_config, null);
952 jToolBar1.addSeparator();
953 jToolBar1.add(b_material, null);
954 jToolBar1.add(b_constraints, null);
955 jToolBar1.add(b_loads, null);
956
957 this.add(jPanel1, BorderLayout.SOUTH);
958 jPanel1.add(coordinates, null);
959 jPanel1.add(jToolBar3, null);
960 jPanel1.add(jToolBar2, null);
961 jSplitPane1.setDividerLocation(220);
962 //J3D.coodinates=coordinates;
963 }
964
965
getFrame(Component component)966 public static Frame getFrame(Component component){
967 for(; component != null && !(component instanceof Frame); component = component.getParent());
968 return (Frame)component;
969 }
970
setVisible(boolean v)971 public void setVisible(boolean v){
972 super.setVisible(v);
973
974 if (J3D instanceof Canvas3DGL)
975 J3D.setVisible(v);
976 }
977
978
error(Object st)979 public void error(Object st){
980 JOptionPane.showMessageDialog(this,"Error: "+st,"Error!",JOptionPane.ERROR_MESSAGE);
981 if(st instanceof Exception) ((Exception)st).printStackTrace(); else System.out.println("Error: "+st);
982 }
983
cb_graphicsmode_itemStateChanged(ItemEvent e)984 void cb_graphicsmode_itemStateChanged(ItemEvent e) {
985 J3D.setGRAPHICSMODE((byte)cb_graphicsmode.getSelectedIndex());
986 if(cb_graphicsmode.getSelectedIndex()==0)cb_materials.setSelected(false); else cb_materials.setSelected(true);
987 J3D.repaint();
988 }
989
b_zoomin_actionPerformed(ActionEvent e)990 void b_zoomin_actionPerformed(ActionEvent e) {
991 J3D.view_scale(1.2f);
992 }
993
b_zoomout_actionPerformed(ActionEvent e)994 void b_zoomout_actionPerformed(ActionEvent e) {
995 J3D.view_scale(0.8f);
996 }
997
b_zoomall_actionPerformed(ActionEvent e)998 void b_zoomall_actionPerformed(ActionEvent e) {
999 J3D.view_all();
1000 }
1001
b_viewtop_actionPerformed(ActionEvent e)1002 void b_viewtop_actionPerformed(ActionEvent e) {
1003 J3D.view_top();
1004 }
1005
b_viewsw_actionPerformed(ActionEvent e)1006 void b_viewsw_actionPerformed(ActionEvent e) {
1007 J3D.view_sw();
1008 }
1009
b_viewse_actionPerformed(ActionEvent e)1010 void b_viewse_actionPerformed(ActionEvent e) {
1011 J3D.view_se();
1012 }
1013
b_viewne_actionPerformed(ActionEvent e)1014 void b_viewne_actionPerformed(ActionEvent e) {
1015 J3D.view_ne();
1016 }
1017
b_viewnw_actionPerformed(ActionEvent e)1018 void b_viewnw_actionPerformed(ActionEvent e) {
1019 J3D.view_nw();
1020 }
1021
b_viewbottom_actionPerformed(ActionEvent e)1022 void b_viewbottom_actionPerformed(ActionEvent e) {
1023 J3D.view_bottom();
1024 }
1025
b_viewleft_actionPerformed(ActionEvent e)1026 void b_viewleft_actionPerformed(ActionEvent e) {
1027 J3D.view_left();
1028 }
1029
b_viewright_actionPerformed(ActionEvent e)1030 void b_viewright_actionPerformed(ActionEvent e) {
1031 J3D.view_right();
1032 }
1033
b_viewfront_actionPerformed(ActionEvent e)1034 void b_viewfront_actionPerformed(ActionEvent e) {
1035 J3D.view_front();
1036 }
1037
b_viewback_actionPerformed(ActionEvent e)1038 void b_viewback_actionPerformed(ActionEvent e) {
1039 J3D.view_back();
1040 }
1041
command(ActionEvent e)1042 void command(ActionEvent e) {
1043 p_cmd.removeAll();
1044 int w = p_cmd.getWidth();
1045 String st_cmd = ""+e.getActionCommand();
1046 if(st_cmd.equalsIgnoreCase("GROUPADD")) {
1047 _Group g = new _GroupUserDefined(true, true);
1048 p_cmd.add(g.getEditPanel(J3D,this),BorderLayout.CENTER);
1049 g.requestFocus();
1050 }
1051 else if(st_cmd.equalsIgnoreCase("POINT")) {
1052 _Point t = new _Point(true);
1053 p_cmd.add(t.getEditPanel(J3D,this),BorderLayout.CENTER);
1054 t.requestFocus();
1055 }
1056 else if(st_cmd.equalsIgnoreCase("NODE")) {
1057 edit_panel = new _Node(true);
1058 p_cmd.add(edit_panel.getEditPanel(J3D,this),BorderLayout.CENTER);
1059 edit_panel.requestFocus();
1060 }
1061 else if(st_cmd.equalsIgnoreCase("ELEMENT8")) {
1062 edit_panel = new _Element8(true);
1063 p_cmd.add(edit_panel.getEditPanel(J3D,this),BorderLayout.CENTER);
1064 edit_panel.requestFocus();
1065 }
1066
1067 else if(st_cmd.equalsIgnoreCase("ELEMENT4S")) {
1068 edit_panel = new _Element4(true,Canvas3D.MESH_Solid_Iso_4);
1069 p_cmd.add(edit_panel.getEditPanel(J3D,this),BorderLayout.CENTER);
1070 edit_panel.requestFocus();
1071 }
1072 else if(st_cmd.equalsIgnoreCase("ELEMENT4")) {
1073 edit_panel = new _Element4(true,Canvas3D.MESH_Shell_BT_4);
1074 p_cmd.add(edit_panel.getEditPanel(J3D,this),BorderLayout.CENTER);
1075 edit_panel.requestFocus();
1076 }
1077
1078 else if(st_cmd.equalsIgnoreCase("ELEMENT3")) {
1079 edit_panel = new _Element3(true);
1080 p_cmd.add(edit_panel.getEditPanel(J3D,this),BorderLayout.CENTER);
1081 edit_panel.requestFocus();
1082 }
1083 else if(st_cmd.equalsIgnoreCase("ELEMENT2")) {
1084 edit_panel = new _Element2(true);
1085 p_cmd.add(edit_panel.getEditPanel(J3D,this),BorderLayout.CENTER);
1086 edit_panel.requestFocus();
1087 }
1088 else if(st_cmd.equalsIgnoreCase("MOVE"))p_cmd.add(new PreProcessor_Move(J3D,this),BorderLayout.CENTER);
1089 else if(st_cmd.equalsIgnoreCase("ROTATE"))p_cmd.add(new PreProcessor_Rotate(J3D,this),BorderLayout.CENTER);
1090 else if(st_cmd.equalsIgnoreCase("SCALE"))p_cmd.add(new PreProcessor_Scale(J3D,this),BorderLayout.CENTER);
1091 else if(st_cmd.equalsIgnoreCase("TRANSFORM"))p_cmd.add(new PreProcessor_Transform(J3D),BorderLayout.CENTER);
1092 else if(st_cmd.equalsIgnoreCase("ARC")) {
1093 edit_panel = new _Arc(true, J3D);
1094 p_cmd.add(edit_panel.getEditPanel(J3D,this),BorderLayout.CENTER);
1095 edit_panel.requestFocus();
1096 }
1097 else if(st_cmd.equalsIgnoreCase("SPLINE")) {
1098 edit_panel = new _Spline(true, J3D);
1099 p_cmd.add(edit_panel.getEditPanel(J3D,this),BorderLayout.CENTER);
1100 edit_panel.requestFocus();
1101 }
1102 else if(st_cmd.equalsIgnoreCase("SURFDIR")) {
1103 edit_panel = new _SurfDir(true, J3D);
1104 p_cmd.add(edit_panel.getEditPanel(J3D,this),BorderLayout.CENTER);
1105 edit_panel.requestFocus();
1106 }
1107 else if(st_cmd.equalsIgnoreCase("SURFREV")) {
1108 edit_panel = new _SurfRev(true, J3D);
1109 p_cmd.add(edit_panel.getEditPanel(J3D,this),BorderLayout.CENTER);
1110 edit_panel.requestFocus();
1111 }
1112 else if(st_cmd.equalsIgnoreCase("SURFRUL")){
1113 edit_panel = new _SurfRul(true, J3D);
1114 p_cmd.add(edit_panel.getEditPanel(J3D,this),BorderLayout.CENTER);
1115 edit_panel.requestFocus();
1116 }
1117 else if(st_cmd.equalsIgnoreCase("SURFNURB")){
1118 edit_panel = new _SurfFill(true, J3D);
1119 p_cmd.add(edit_panel.getEditPanel(J3D,this),BorderLayout.CENTER);
1120 edit_panel.requestFocus();
1121 }
1122 else if(st_cmd.equalsIgnoreCase("SURFBIL")){
1123 edit_panel = new _SurfBil(true, J3D);
1124 p_cmd.add(edit_panel.getEditPanel(J3D,this),BorderLayout.CENTER);
1125 edit_panel.requestFocus();
1126 }
1127 else if(st_cmd.equalsIgnoreCase("BORDER")){
1128 J3D.addBorderObjects();
1129 }
1130 else if(st_cmd.equalsIgnoreCase("INTERSECT")){
1131 try {
1132 J3D.intersectObjects();
1133 } catch (IllegalStateException ise) {
1134 error(ise);
1135 }
1136 }
1137 else if(st_cmd.equalsIgnoreCase("PROJECT")){
1138 try {
1139 J3D.projectObjects();
1140 } catch (IllegalStateException ise) {
1141 error(ise);
1142 }
1143 }
1144 else if(st_cmd.equalsIgnoreCase("BREAK")){
1145 try {
1146 J3D.breakObjects();
1147 } catch (IllegalStateException ise) {
1148 error(ise);
1149 }
1150 }
1151 else if(st_cmd.equalsIgnoreCase("PROPERTIES"))showEditPanel();
1152 else if(st_cmd.equalsIgnoreCase("SETCONSTRAINTS"))p_cmd.add(new PreProcessor_SetConstraints(J3D,this),BorderLayout.CENTER);
1153 else if(st_cmd.equalsIgnoreCase("SETLOADS"))p_cmd.add(new PreProcessor_SetLoads(J3D,this),BorderLayout.CENTER);
1154 else if(st_cmd.equalsIgnoreCase("SETMATERIAL"))p_cmd.add(new PreProcessor_SetMaterial(J3D,this),BorderLayout.CENTER);
1155 else if(st_cmd.equalsIgnoreCase("SETTHICKNESS"))p_cmd.add(new PreProcessor_SetThickness(J3D,this),BorderLayout.CENTER);
1156 else if(st_cmd.equalsIgnoreCase("GRID"))p_cmd.add(new PreProcessor_Grid(J3D),BorderLayout.CENTER);
1157 p_cmd.validate();
1158 PanelInspector.validate();
1159 }
1160
1161
b_save_actionPerformed(ActionEvent e)1162 void b_save_actionPerformed(ActionEvent e) {
1163
1164 FileFilter f1 = new FileFilter() {
1165 public boolean accept(File f) {
1166 if (f.isDirectory()) return true;
1167 return f.getName().toLowerCase().endsWith(".impact");
1168 }
1169
1170 public String getDescription() {
1171 return "Complete preprocessor model (.impact)";
1172 }
1173 };
1174
1175 FileFilter f2 = new FileFilter() {
1176 public boolean accept(File f) {
1177 if (f.isDirectory()) return true;
1178 return f.getName().toLowerCase().endsWith(".in");
1179 }
1180
1181 public String getDescription() {
1182 return "Indata model for solver (.in)";
1183 }
1184 };
1185
1186 try {
1187 JFileChooser fd = new JFileChooser(ConfDB.getProperty("Filepath"));
1188 fd.setSize(350,200);
1189 fd.addChoosableFileFilter(f1);
1190 fd.addChoosableFileFilter(f2);
1191
1192 int choise = fd.showSaveDialog(this);
1193
1194 if(choise == JFileChooser.APPROVE_OPTION && fd.getSelectedFile()!=null){
1195 String st = fd.getSelectedFile().getAbsolutePath();
1196
1197 if (fd.getFileFilter().equals(f1)) {
1198 if(!st.toLowerCase().endsWith(".impact"))st+=".impact";
1199
1200 File f = new File(st);
1201 f.delete();
1202 try {
1203 FileOutputStream ostream = new FileOutputStream(st);
1204 ObjectOutputStream p = new ObjectOutputStream(ostream);
1205 p.writeObject(MatDB);
1206 p.writeObject(ConstDB);
1207 p.writeObject(LoadDB);
1208 p.writeObject(J3D.getVMatrix3D());
1209 _Object[] arr_obj = J3D.getAllObjects3D();
1210 for(int i=0; i<arr_obj.length; i++){
1211 p.writeObject(arr_obj[i]);
1212 }
1213 p.flush();
1214 ostream.flush();
1215 ostream.close();
1216 }catch(Exception ie) { error(ie); }
1217 path=st;
1218 }
1219
1220 else
1221 if (fd.getFileFilter().equals(f2)) {
1222 saveSolverModel(st);
1223 }
1224 }
1225
1226 // Update configuration file with path
1227 if (fd.getSelectedFile() != null) {
1228 ConfDB.setProperty("Filepath", fd.getSelectedFile().getAbsolutePath());
1229 save_configuration();
1230 header(fd.getSelectedFile().getAbsolutePath());
1231 }
1232
1233 } catch(Exception e1) {error(e1);}
1234 }
1235
b_open_actionPerformed(ActionEvent e)1236 void b_open_actionPerformed(ActionEvent e) throws IOException {
1237 FileFilter f1 = new FileFilter() {
1238 public boolean accept(File f) {
1239 if (f.isDirectory()) return true;
1240 return f.getName().toLowerCase().endsWith(".stl");
1241 }
1242
1243 public String getDescription() {
1244 return "Add STL surface (.stl)";
1245 }
1246 };
1247
1248 FileFilter f2 = new FileFilter() {
1249 public boolean accept(File f) {
1250 if (f.isDirectory()) return true;
1251 if (f.getName().toLowerCase().endsWith(".in")) return true;
1252 return false;
1253 }
1254
1255 public String getDescription() {
1256 return "Add impact model (.in) to current model";
1257 }
1258 };
1259
1260 FileFilter f3 = new FileFilter() {
1261 public boolean accept(File f) {
1262 if (f.isDirectory()) return true;
1263 if (f.getName().toLowerCase().endsWith(".nas") || f.getName().toLowerCase().endsWith(".nastran") || f.getName().toLowerCase().endsWith(".bdf")) return true;
1264 return false;
1265 }
1266
1267 public String getDescription() {
1268 return "Add nastran model (.nas, .nastran, .bdf) to current model";
1269 }
1270 };
1271
1272 FileFilter f4 = new FileFilter() {
1273 public boolean accept(File f) {
1274 if (f.isDirectory()) return true;
1275 if (f.getName().toLowerCase().endsWith(".msh")) return true;
1276 return false;
1277 }
1278
1279 public String getDescription() {
1280 return "Add Gmsh model (.msh) to current model";
1281 }
1282 };
1283
1284 FileFilter f5 = new FileFilter() {
1285 public boolean accept(File f) {
1286 if (f.isDirectory()) return true;
1287 if (f.getName().toLowerCase().endsWith(".unv")) return true;
1288 return false;
1289 }
1290
1291 public String getDescription() {
1292 return "Add UNV model (.unv) to current model";
1293 }
1294 };
1295
1296
1297 JFileChooser fd = new JFileChooser(ConfDB.getProperty("Filepath"));
1298 fd.setSize(350,200);
1299 fd.addChoosableFileFilter(f1);
1300 fd.addChoosableFileFilter(f2);
1301 fd.addChoosableFileFilter(f3);
1302 fd.addChoosableFileFilter(f4);
1303 fd.addChoosableFileFilter(f5);
1304
1305 fd.setFileFilter(f2);
1306
1307 try {
1308
1309 int choise = fd.showOpenDialog(this);
1310
1311 if(choise == JFileChooser.APPROVE_OPTION && fd.getSelectedFile()!=null){
1312 String st = fd.getSelectedFile().getAbsolutePath();
1313
1314 if (fd.getFileFilter().equals(f1)){
1315 edit_panel = new _Stl(st);
1316 J3D.add3D(edit_panel);
1317 p_cmd.removeAll();
1318 p_cmd.add(edit_panel.getEditPanel(J3D,this),BorderLayout.CENTER);
1319 edit_panel.requestFocus();
1320 PanelInspector.validate();
1321 J3D.tree_reset();
1322 J3D.view_reset();
1323 J3D.view_all();
1324 }
1325 else if (fd.getFileFilter().equals(f2)) {
1326 this.readIN(st);
1327 J3D.tree_reset();
1328 J3D.view_reset();
1329 J3D.view_all();
1330 }
1331 else if (fd.getFileFilter().equals(f3)) {
1332 this.readNastran(st);
1333 J3D.tree_reset();
1334 J3D.view_reset();
1335 J3D.view_all();
1336 }
1337 else if (fd.getFileFilter().equals(f4)) {
1338 this.readGmsh(st);
1339 J3D.tree_reset();
1340 J3D.view_reset();
1341 J3D.view_all();
1342 }
1343 else if (fd.getFileFilter().equals(f5)) {
1344 this.readUNV(st);
1345 J3D.tree_reset();
1346 J3D.view_reset();
1347 J3D.view_all();
1348 }
1349 }
1350
1351 if (fd.getSelectedFile() != null) {
1352 ConfDB.setProperty("Filepath", fd.getSelectedFile().getAbsolutePath());
1353 save_configuration();
1354 header(fd.getSelectedFile().getName());
1355 }
1356
1357 } catch(Exception e1) {error(e1);}
1358 }
1359
getColorLine(int cl)1360 public Color getColorLine(int cl){
1361 int i = (int)(cl-Math.round(cl/10)*10);
1362 if(i==0)return Color.black;
1363 else if(i==1)return Color.gray;
1364 else if(i==2)return Color.cyan;
1365 else if(i==3)return Color.blue;
1366 else if(i==4)return Color.green;
1367 else if(i==5)return Color.magenta;
1368 else if(i==6)return Color.orange;
1369 else if(i==7)return Color.pink;
1370 else if(i==8)return Color.red;
1371 else return Color.yellow;
1372 }
1373
b_material_actionPerformed(ActionEvent e)1374 void b_material_actionPerformed(ActionEvent e) {
1375 JPanel p = new JPanel(new BorderLayout());
1376 JPanel p1 = new JPanel();
1377 JButton m_new = new JButton("New");
1378 m_new.addActionListener(new ActionListener() {
1379 public void actionPerformed(ActionEvent e) {
1380 JPanel p2 = new JPanel(new VerticalFlowLayout());
1381 JPanel p3 = new JPanel(new BorderLayout());
1382 JPanel p4 = new JPanel(new BorderLayout());
1383 JPanel p5 = new JPanel(new BorderLayout());
1384 JPanel p6 = new JPanel(new BorderLayout());
1385 String[] st = {"Elastic","Elastoplastic","ThermoElastoplastic","Spring"};
1386 JComboBox cb_type = new JComboBox(st);
1387 JTextField tf_name = new JTextField("mat"+id_color);
1388 JTextField tf_disc = new JTextField();
1389 JButton b_col = new JButton();
1390 b_col.addActionListener(new java.awt.event.ActionListener() {
1391 public void actionPerformed(ActionEvent e) {
1392 Color cl = JColorChooser.showDialog(getFrame(PanelInspector),"Pick a Color",getColorLine(id_color));
1393 if(cl!=null)((JButton)e.getSource()).setBackground(cl);
1394 }
1395 });
1396 b_col.setBackground(getColorLine(id_color));
1397 p2.add(p3);
1398 p3.add(new JLabel("Type of material"), BorderLayout.WEST);
1399 p3.add(cb_type, BorderLayout.CENTER);
1400 p2.add(p4);
1401 p4.add(new JLabel("Name"), BorderLayout.WEST);
1402 p4.add(tf_name, BorderLayout.CENTER);
1403 p2.add(p5, null);
1404 p5.add(new JLabel("Description"), BorderLayout.WEST);
1405 p5.add(tf_disc, BorderLayout.CENTER);
1406 p2.add(p6);
1407 p6.add(new JLabel("Color"), BorderLayout.WEST);
1408 p6.add(b_col, BorderLayout.CENTER);
1409 int result = JOptionPane.showOptionDialog(getFrame(PanelInspector),p2,"New Material",JOptionPane.YES_NO_OPTION,JOptionPane.PLAIN_MESSAGE,null,null,null);
1410 if(result!=0) return;
1411 id_color++;
1412 Material mat = new Material();
1413 mat.name=tf_name.getText();
1414 mat.type=cb_type.getSelectedItem()+"";
1415 mat.color=b_col.getBackground();
1416 mat.description=tf_disc.getText();
1417 MatDB.put(tf_name.getText(),mat);
1418 MatTable.revalidate();
1419 }
1420 });
1421 JButton m_del = new JButton("Delete");
1422 m_del.addActionListener(new ActionListener() {
1423 public void actionPerformed(ActionEvent e) {
1424 int[] sel = MatTable.getSelectedRows();
1425 String[] sel_st = new String[sel.length];
1426 for(int i=0; i<sel.length; i++){
1427 sel_st[i]=MatTable.getValueAt(sel[i],0)+"";
1428 }
1429 for(int i=0; i<sel.length; i++){
1430 MatDB.remove(sel_st[i]);
1431 }
1432 MatTable.revalidate();
1433 }
1434 });
1435 JScrollPane spl = new JScrollPane();
1436 p.add(spl, BorderLayout.CENTER);
1437 p.add(p1, BorderLayout.NORTH);
1438 p1.add(m_new);
1439 p1.add(m_del);
1440 spl.getViewport().add(MatTable);
1441 JOptionPane.showMessageDialog(getFrame(PanelInspector), p, "Material", JOptionPane.PLAIN_MESSAGE);
1442 //if(result!=0) load_materials(); else save_materials();
1443 }
1444
load_configuration()1445 private void load_configuration() {
1446 FileInputStream fin = null;
1447 try {
1448 ConfDB.clear();
1449 fin = new FileInputStream("Pre.conf");
1450 ConfDB.load(fin);
1451 fin.close();
1452 } catch (IOException e) {
1453 error(e); }
1454 }
1455
load_materials()1456 public void load_materials(){
1457 try{
1458 MatDB.clear();
1459 RandomAccessFile fin = new RandomAccessFile("Material.properties","r");
1460 String st;
1461 while((st=fin.readLine())!=null){
1462 Material mat = new Material();
1463 mat.type = st;
1464 mat.name = fin.readLine();
1465 mat.description = fin.readLine();
1466 StringTokenizer stt = new StringTokenizer(fin.readLine());
1467 mat.color = new Color(Integer.parseInt(stt.nextToken()),Integer.parseInt(stt.nextToken()),Integer.parseInt(stt.nextToken()));
1468 MatDB.put(mat.name,mat);
1469 }
1470 fin.close();
1471 }catch(Exception ex){error(ex);}
1472 }
1473
load_constraints()1474 public void load_constraints(){
1475 try{
1476 ConstDB.clear();
1477 RandomAccessFile fin = new RandomAccessFile("Constraints.properties","r");
1478 String st;
1479 while((st=fin.readLine())!=null){
1480 Constraints con = new Constraints();
1481 con.type = st;
1482 con.name = fin.readLine();
1483 con.description = fin.readLine();
1484 StringTokenizer stt = new StringTokenizer(fin.readLine());
1485 con.color = new Color(Integer.parseInt(stt.nextToken()),Integer.parseInt(stt.nextToken()),Integer.parseInt(stt.nextToken()));
1486 ConstDB.put(con.name,con);
1487 }
1488 fin.close();
1489 }catch(Exception ex){error(ex);}
1490 }
1491
load_loads()1492 public void load_loads(){
1493 try{
1494 LoadDB.clear();
1495 RandomAccessFile fin = new RandomAccessFile("Loads.properties","r");
1496 String st;
1497 while((st=fin.readLine())!=null){
1498 Loads ld = new Loads();
1499 ld.name = st;
1500 ld.description = fin.readLine();
1501 StringTokenizer stt = new StringTokenizer(fin.readLine());
1502 ld.color = new Color(Integer.parseInt(stt.nextToken()),Integer.parseInt(stt.nextToken()),Integer.parseInt(stt.nextToken()));
1503 LoadDB.put(ld.name,ld);
1504 }
1505 fin.close();
1506 }catch(Exception ex){error(ex);}
1507 }
1508
save_configuration()1509 private void save_configuration() {
1510 FileOutputStream fout;
1511 try {
1512 fout = new FileOutputStream("Pre.conf");
1513 ConfDB.store(fout, "Configuration file for Impact Preprocessor");
1514 fout.close();
1515 } catch (IOException e) {
1516 error(e); }
1517 }
1518
save_materials()1519 public void save_materials(){
1520 try{
1521 File f = new File("Material.properties");
1522 f.delete();
1523 RandomAccessFile fout = new RandomAccessFile(f,"rw");
1524 for(Enumeration en = MatDB.keys(); en.hasMoreElements();){
1525 String key = en.nextElement()+"";
1526 Material mat = (Material)MatDB.get(key);
1527 fout.writeBytes(mat.type+"\n");
1528 fout.writeBytes(mat.name+"\n");
1529 fout.writeBytes(mat.description+"\n");
1530 fout.writeBytes(mat.color.getRed()+" "+mat.color.getGreen()+" "+mat.color.getBlue()+"\n");
1531 }
1532 fout.close();
1533 J3D.tree_reset();
1534 J3D.view_reset();
1535 }catch(Exception ex){error(ex);}
1536 }
1537
save_constraints()1538 public void save_constraints(){
1539 try{
1540 File f = new File("Constraints.properties");
1541 f.delete();
1542 RandomAccessFile fout = new RandomAccessFile(f,"rw");
1543 for(Enumeration en = ConstDB.keys(); en.hasMoreElements();){
1544 String key = en.nextElement()+"";
1545 Constraints con = (Constraints)ConstDB.get(key);
1546 fout.writeBytes(con.type+"\n");
1547 fout.writeBytes(con.name+"\n");
1548 fout.writeBytes(con.description+"\n");
1549 fout.writeBytes(con.color.getRed()+" "+con.color.getGreen()+" "+con.color.getBlue()+"\n");
1550 }
1551 fout.close();
1552 J3D.tree_reset();
1553 J3D.view_reset();
1554 }catch(Exception ex){error(ex);}
1555 }
1556
save_loads()1557 public void save_loads(){
1558 try{
1559 File f = new File("Loads.properties");
1560 f.delete();
1561 RandomAccessFile fout = new RandomAccessFile(f,"rw");
1562 for(Enumeration en = LoadDB.keys(); en.hasMoreElements();){
1563 String key = en.nextElement()+"";
1564 Loads ld = (Loads)LoadDB.get(key);
1565 fout.writeBytes(ld.name+"\n");
1566 fout.writeBytes(ld.description+"\n");
1567 fout.writeBytes(ld.color.getRed()+" "+ld.color.getGreen()+" "+ld.color.getBlue()+"\n");
1568 }
1569 fout.close();
1570 J3D.tree_reset();
1571 J3D.view_reset();
1572 }catch(Exception ex){error(ex);}
1573 }
1574
1575
b_config_actionPerformed(ActionEvent e)1576 void b_config_actionPerformed(ActionEvent e) {
1577 JTabbedPane p = new JTabbedPane();
1578 JPanel p1 = new JPanel(new VerticalFlowLayout());
1579 JPanel p2 = new JPanel(new VerticalFlowLayout());
1580 JPanel p3 = new JPanel(new FlowLayout(FlowLayout.LEFT));
1581 JPanel p4 = new JPanel(new FlowLayout(FlowLayout.LEFT));
1582 JPanel p5 = new JPanel(new FlowLayout(FlowLayout.LEFT));
1583 p1.add(cb_node_0);
1584 p1.add(cb_node);
1585 p1.add(cb_element);
1586 p1.add(cb_constraints);
1587 p1.add(cb_loads);
1588 p1.add(cb_trackers);
1589 p1.add(cb_materials);
1590 p2.add(p3);
1591 p2.add(p4);
1592 p2.add(p5);
1593 p.add("Controls",p2);
1594 p.add("Show",p1);
1595 JTextField tf_CONTROLS_RUN_FROM = new JTextField(CONTROLS_RUN_FROM,5);
1596 JTextField tf_CONTROLS_RUN_TO = new JTextField(CONTROLS_RUN_TO,5);
1597 JTextField tf_CONTROLS_RUN_STEP = new JTextField(CONTROLS_RUN_STEP,5);
1598 JTextField tf_CONTROLS_PRINT_STEP = new JTextField(CONTROLS_PRINT_STEP,5);
1599 JTextField tf_CONTROLS_PRINT_TRACKER_STEP = new JTextField(CONTROLS_PRINT_TRACKER_STEP,5);
1600 p3.add(new JLabel("Run from"));
1601 p3.add(tf_CONTROLS_RUN_FROM);
1602 p3.add(new JLabel("to"));
1603 p3.add(tf_CONTROLS_RUN_TO);
1604 p3.add(new JLabel("step"));
1605 p3.add(tf_CONTROLS_RUN_STEP);
1606 p4.add(new JLabel("Print every"));
1607 p4.add(tf_CONTROLS_PRINT_STEP);
1608 p4.add(new JLabel("step"));
1609 p5.add(new JLabel("Print tracker every"));
1610 p5.add(tf_CONTROLS_PRINT_TRACKER_STEP);
1611 p5.add(new JLabel("step"));
1612 JOptionPane.showMessageDialog(this,p,"Properties",JOptionPane.PLAIN_MESSAGE,null);
1613 if(cb_node_0.isSelected())J3D.setPOINTSIZE(4); else J3D.setPOINTSIZE(0);
1614 J3D.setSHOW_ID_NODE(cb_node.isSelected());
1615 J3D.setSHOW_ID_ELEMENT(cb_element.isSelected());
1616 J3D.setSHOW_ID_CONSTRAINTS(cb_constraints.isSelected());
1617 J3D.setSHOW_ID_LOADS(cb_loads.isSelected());
1618 J3D.setSHOW_ID_TRACKERS(cb_trackers.isSelected());
1619 if(!cb_materials.isSelected()){
1620 cb_graphicsmode.setSelectedIndex(0);
1621 }else cb_graphicsmode.setSelectedIndex(1);
1622 CONTROLS_RUN_FROM=tf_CONTROLS_RUN_FROM.getText();
1623 CONTROLS_RUN_TO=tf_CONTROLS_RUN_TO.getText();
1624 CONTROLS_RUN_STEP=tf_CONTROLS_RUN_STEP.getText();
1625 CONTROLS_PRINT_STEP=tf_CONTROLS_PRINT_STEP.getText();
1626 CONTROLS_PRINT_TRACKER_STEP=tf_CONTROLS_PRINT_TRACKER_STEP.getText();
1627 J3D.view_reset();
1628 J3D.tree_reset();
1629 }
1630
b_constraints_actionPerformed(ActionEvent e)1631 void b_constraints_actionPerformed(ActionEvent e) {
1632 JPanel p = new JPanel(new BorderLayout());
1633 JPanel p1 = new JPanel();
1634 JButton m_new = new JButton("New");
1635 m_new.addActionListener(new ActionListener() {
1636 public void actionPerformed(ActionEvent e) {
1637 JPanel p2 = new JPanel(new VerticalFlowLayout());
1638 JPanel p3 = new JPanel(new BorderLayout());
1639 JPanel p4 = new JPanel(new BorderLayout());
1640 JPanel p5 = new JPanel(new BorderLayout());
1641 JPanel p6 = new JPanel(new BorderLayout());
1642 String[] st = {"Boundary_Condition","Rigid_Body"};
1643 JComboBox cb_type = new JComboBox(st);
1644 JTextField tf_name = new JTextField("Fixed"+id_color);
1645 JTextField tf_disc = new JTextField();
1646 JButton b_col = new JButton();
1647 b_col.addActionListener(new java.awt.event.ActionListener() {
1648 public void actionPerformed(ActionEvent e) {
1649 Color cl = JColorChooser.showDialog(getFrame(PanelInspector),"Pick a Color",getColorLine(id_color));
1650 if(cl!=null)((JButton)e.getSource()).setBackground(cl);
1651 }
1652 });
1653 b_col.setBackground(getColorLine(id_color));
1654 p2.add(p3);
1655 p3.add(new JLabel("Type of constraint"), BorderLayout.WEST);
1656 p3.add(cb_type, BorderLayout.CENTER);
1657 p2.add(p4);
1658 p4.add(new JLabel("Name"), BorderLayout.WEST);
1659 p4.add(tf_name, BorderLayout.CENTER);
1660 p2.add(p5, null);
1661 p5.add(new JLabel("Description"), BorderLayout.WEST);
1662 p5.add(tf_disc, BorderLayout.CENTER);
1663 p2.add(p6);
1664 p6.add(new JLabel("Color"), BorderLayout.WEST);
1665 p6.add(b_col, BorderLayout.CENTER);
1666 int result = JOptionPane.showOptionDialog(getFrame(PanelInspector),p2,"New Constraints",JOptionPane.YES_NO_OPTION,JOptionPane.PLAIN_MESSAGE,null,null,null);
1667 if(result!=0) return;
1668 id_color++;
1669 Constraints con = new Constraints();
1670 con.name=tf_name.getText();
1671 con.type=cb_type.getSelectedItem()+"";
1672 con.color=b_col.getBackground();
1673 con.description=tf_disc.getText();
1674 ConstDB.put(tf_name.getText(),con);
1675 ConstTable.revalidate();
1676 }
1677 });
1678 JButton m_del = new JButton("Delete");
1679 m_del.addActionListener(new ActionListener() {
1680 public void actionPerformed(ActionEvent e) {
1681 int[] sel = ConstTable.getSelectedRows();
1682 String[] sel_st = new String[sel.length];
1683 for(int i=0; i<sel.length; i++){
1684 sel_st[i]=ConstTable.getValueAt(sel[i],0)+"";
1685 }
1686 for(int i=0; i<sel.length; i++){
1687 ConstDB.remove(sel_st[i]);
1688 }
1689 ConstTable.revalidate();
1690 }
1691 });
1692 JScrollPane spl = new JScrollPane();
1693 p.add(spl, BorderLayout.CENTER);
1694 p.add(p1, BorderLayout.NORTH);
1695 p1.add(m_new);
1696 p1.add(m_del);
1697 spl.getViewport().add(ConstTable);
1698 JOptionPane.showMessageDialog(getFrame(PanelInspector), p, "Constraints",JOptionPane.PLAIN_MESSAGE);
1699 //if(result!=0) load_constraints(); else save_constraints();
1700 }
1701
b_loads_actionPerformed(ActionEvent e)1702 void b_loads_actionPerformed(ActionEvent e) {
1703 JPanel p = new JPanel(new BorderLayout());
1704 JPanel p1 = new JPanel();
1705 JButton m_new = new JButton("New");
1706 m_new.addActionListener(new ActionListener() {
1707 public void actionPerformed(ActionEvent e) {
1708 JPanel p2 = new JPanel(new VerticalFlowLayout());
1709 JPanel p3 = new JPanel(new BorderLayout());
1710 JPanel p4 = new JPanel(new BorderLayout());
1711 JPanel p5 = new JPanel(new BorderLayout());
1712 JPanel p6 = new JPanel(new BorderLayout());
1713 //String[] st = {"Boundary_Condition","Rigid_Body"};
1714 //JComboBox cb_type = new JComboBox(st);
1715 JTextField tf_name = new JTextField("Force"+id_color);
1716 JTextField tf_disc = new JTextField();
1717 JButton b_col = new JButton();
1718 b_col.addActionListener(new java.awt.event.ActionListener() {
1719 public void actionPerformed(ActionEvent e) {
1720 Color cl = JColorChooser.showDialog(getFrame(PanelInspector),"Pick a Color",getColorLine(id_color));
1721 if(cl!=null)((JButton)e.getSource()).setBackground(cl);
1722 }
1723 });
1724 b_col.setBackground(getColorLine(id_color));
1725 p2.add(p3);
1726 //p3.add(new JLabel("Type of constraint"), BorderLayout.WEST);
1727 //p3.add(cb_type, BorderLayout.CENTER);
1728 p2.add(p4);
1729 p4.add(new JLabel("Name"), BorderLayout.WEST);
1730 p4.add(tf_name, BorderLayout.CENTER);
1731 p2.add(p5, null);
1732 p5.add(new JLabel("Description"), BorderLayout.WEST);
1733 p5.add(tf_disc, BorderLayout.CENTER);
1734 p2.add(p6);
1735 p6.add(new JLabel("Color"), BorderLayout.WEST);
1736 p6.add(b_col, BorderLayout.CENTER);
1737 int result = JOptionPane.showOptionDialog(getFrame(PanelInspector),p2,"New Loads",JOptionPane.YES_NO_OPTION,JOptionPane.PLAIN_MESSAGE,null,null,null);
1738 if(result!=0) return;
1739 id_color++;
1740 Loads ld = new Loads();
1741 ld.name=tf_name.getText();
1742 ld.color=b_col.getBackground();
1743 ld.description=tf_disc.getText();
1744 LoadDB.put(tf_name.getText(),ld);
1745 LoadTable.revalidate();
1746 }
1747 });
1748 JButton m_del = new JButton("Delete");
1749 m_del.addActionListener(new ActionListener() {
1750 public void actionPerformed(ActionEvent e) {
1751 int[] sel = LoadTable.getSelectedRows();
1752 String[] sel_st = new String[sel.length];
1753 for(int i=0; i<sel.length; i++){
1754 sel_st[i]=LoadTable.getValueAt(sel[i],0)+"";
1755 }
1756 for(int i=0; i<sel.length; i++){
1757 LoadDB.remove(sel_st[i]);
1758 }
1759 LoadTable.revalidate();
1760 }
1761 });
1762 JScrollPane spl = new JScrollPane();
1763 p.add(spl, BorderLayout.CENTER);
1764 p.add(p1, BorderLayout.NORTH);
1765 p1.add(m_new);
1766 p1.add(m_del);
1767 spl.getViewport().add(LoadTable);
1768 JOptionPane.showMessageDialog(getFrame(PanelInspector), p, "Loads", JOptionPane.PLAIN_MESSAGE);
1769 //if(result!=0) load_loads(); else save_loads();
1770 }
1771
showEditPanel(MouseEvent e)1772 public void showEditPanel(MouseEvent e) {
1773 if(e.getClickCount()==2){
1774 TreePath tp = Tree.getSelectionPath();
1775 if(tp==null)return;
1776 Object[] obj = tp.getPath();
1777 for(int j=0; j<obj.length; j++){
1778 Object uobj = ((DefaultMutableTreeNode)obj[j]).getUserObject();
1779 if(uobj instanceof _Object){
1780 p_cmd.removeAll();
1781 edit_panel = (_Object)uobj;
1782 p_cmd.add(edit_panel.getEditPanel(J3D,this),BorderLayout.CENTER);
1783 p_cmd.validate();
1784 PanelInspector.validate();
1785 }
1786 }
1787 }
1788 }
1789
showEditPanel()1790 public void showEditPanel() {
1791 TreePath tp = Tree.getSelectionPath();
1792 if(tp==null)return;
1793 Object[] obj = tp.getPath();
1794 for(int j=0; j<obj.length; j++){
1795 Object uobj = ((DefaultMutableTreeNode)obj[j]).getUserObject();
1796 if(uobj instanceof _Object){
1797 p_cmd.removeAll();
1798 p_cmd.add(((_Object)uobj).getEditPanel(J3D,this),BorderLayout.CENTER);
1799 p_cmd.validate();
1800 PanelInspector.validate();
1801 }
1802 }
1803 }
1804
clearEditPanel()1805 public void clearEditPanel() {
1806 p_cmd.removeAll();
1807 p_cmd.validate();
1808 PanelInspector.validate();
1809 Tree.requestFocus();
1810 }
1811
resetselect()1812 public void resetselect() {
1813 TreePath[] tp = Tree.getSelectionPaths();
1814 if(tp==null)return;
1815 J3D.clearSelectOnAllObjects3D();
1816 for(int i=0; i<tp.length; i++){
1817 DefaultMutableTreeNode tn = (DefaultMutableTreeNode)tp[i].getLastPathComponent();
1818 Object obj = tn.getUserObject();
1819 if(obj instanceof _Object) ((_Object)obj).setSelected(true);
1820 }
1821 }
1822
1823
mergeNodes(float merge_distance)1824 private void mergeNodes(float merge_distance) {
1825 float dist;
1826 _Node[] narr = J3D.getAllNodes3D();
1827
1828 // Set up references and Id:s
1829 for (int i=0; i < narr.length; i++) {
1830 narr[i].setMergedReference(narr[i]);
1831 }
1832
1833 // Merge nodes to common node with lowerst master type
1834 merge_distance = merge_distance * merge_distance;
1835 for (int i = 0; i < narr.length; i++)
1836 for (int j=i+1; j < narr.length; j++) {
1837
1838 dist = (narr[i].x - narr[j].x)*(narr[i].x - narr[j].x) + (narr[i].y - narr[j].y)*(narr[i].y - narr[j].y) + (narr[i].z - narr[j].z)*(narr[i].z - narr[j].z);
1839
1840 if (dist <= merge_distance)
1841 if (narr[j].getMergedReference().getMaster_type() < narr[i].getMergedReference().getMaster_type())
1842 narr[i].setMergedReference(narr[j].getMergedReference());
1843 else
1844 narr[j].setMergedReference(narr[i].getMergedReference());
1845 }
1846
1847 // Replace all instances in the database
1848 for (int i=0; i < narr.length; i++)
1849 if (narr[i].getMergedReference() != narr[i])
1850 J3D.replaceAllInstancesOf(narr[i],narr[i].getMergedReference());
1851
1852 }
1853
1854
1855
saveSolverModel(String file_in)1856 private void saveSolverModel(String file_in) {
1857 _Node[] narr;
1858 _Object[] earr;
1859 _Group[] garr;
1860 _Geometry[] geoarr;
1861 String st;
1862
1863 if(!file_in.endsWith(".in"))file_in+=".in";
1864
1865 StringBuffer st_model = new StringBuffer("# Created Impact "+ver+"\n# "+new Date()+"\n\nCONTROLS\nrun from "+CONTROLS_RUN_FROM+" to "+CONTROLS_RUN_TO+(CONTROLS_RUN_STEP.trim().length()!=0?" step "+CONTROLS_RUN_STEP:"")+"\nprint every "+CONTROLS_PRINT_STEP+" step\n"+(CONTROLS_PRINT_TRACKER_STEP.trim().length()!=0?"Print TRACKER every "+CONTROLS_PRINT_TRACKER_STEP+" step":"")+"\n\n");
1866 StringBuffer st_nodes = new StringBuffer("");
1867
1868 StringBuffer st_elements = new StringBuffer("");
1869 StringBuffer st_elements_Rod_2=new StringBuffer("ELEMENTS OF TYPE Rod_2\n");
1870 StringBuffer st_elements_Beam_2=new StringBuffer("ELEMENTS OF TYPE Beam_2\n");
1871 StringBuffer st_elements_Beam_Spring_2=new StringBuffer("ELEMENTS OF TYPE Beam_Spring_2\n");
1872 StringBuffer st_elements_Contact_Line=new StringBuffer("ELEMENTS OF TYPE Contact_Line\n");
1873 StringBuffer st_elements_Contact_Triangle=new StringBuffer("ELEMENTS OF TYPE Contact_Triangle\n");
1874 StringBuffer st_elements_Shell_C0_3=new StringBuffer("ELEMENTS OF TYPE Shell_C0_3\n");
1875 StringBuffer st_elements_Shell_BT_4=new StringBuffer("ELEMENTS OF TYPE Shell_BT_4\n");
1876 StringBuffer st_elements_Solid_Iso_4=new StringBuffer("ELEMENTS OF TYPE Solid_Iso_4\n");
1877 StringBuffer st_elements_Solid_Iso_6=new StringBuffer("ELEMENTS OF TYPE Solid_Iso_6\n");
1878
1879 StringBuffer st_geometry = new StringBuffer("");
1880 StringBuffer geo_Point = new StringBuffer("GEOMETRY OF TYPE Point\n");
1881 StringBuffer geo_Spline = new StringBuffer("GEOMETRY OF TYPE Spline\n");
1882 StringBuffer geo_Arc = new StringBuffer("GEOMETRY OF TYPE Arc\n");
1883 StringBuffer geo_SurfBil = new StringBuffer("GEOMETRY OF TYPE SurfBil\n");
1884 StringBuffer geo_SurfDir = new StringBuffer("GEOMETRY OF TYPE SurfDir\n");
1885 StringBuffer geo_SurfFill = new StringBuffer("GEOMETRY OF TYPE SurfFill\n");
1886 StringBuffer geo_SurfRev = new StringBuffer("GEOMETRY OF TYPE SurfRev\n");
1887 StringBuffer geo_SurfRul = new StringBuffer("GEOMETRY OF TYPE SurfRul\n");
1888
1889
1890 String s = JOptionPane.showInputDialog("Enter node merge distance\nor select Cancel to prevent merging",new Float(J3D.getNODE_MERGE_TOLERANCE()));
1891
1892 // Merge the nodes
1893 if(s != null)
1894 this.mergeNodes(Float.parseFloat(s));
1895
1896 // Initialize
1897 narr = J3D.getAllNodes3D();
1898 earr = J3D.getAllElements3D();
1899 garr = J3D.getAllGroups3D();
1900 geoarr = J3D.getAllGeometry3D();
1901
1902 // Create printout of nodes
1903 headerMessage("Printing Nodes");
1904 if (narr.length > 0)
1905 st_nodes.append("NODES\n");
1906 for(int i=0; i<narr.length; i++)
1907 st_nodes.append(narr[i].writeObject()+"\n");
1908
1909 // Create printout of elements
1910 headerMessage("Printing elements");
1911 for(int j=0; j<earr.length; j++){
1912 if(earr[j] instanceof _Element2 && ((_Element2)earr[j]).msh_type == Canvas3D.MESH_Beam_2) st_elements_Beam_2.append(((_Element2)earr[j]).writeObject()+"\n");
1913 else
1914 if(earr[j] instanceof _Element2 && ((_Element2)earr[j]).msh_type == Canvas3D.MESH_Contact_Line) st_elements_Contact_Line.append(((_Element2)earr[j]).writeObject()+"\n");
1915 else
1916 if(earr[j] instanceof _Element2 && ((_Element2)earr[j]).msh_type == Canvas3D.MESH_Rod_2) st_elements_Rod_2.append(((_Element2)earr[j]).writeObject()+"\n");
1917 else
1918 if(earr[j] instanceof _Element3 && ((_Element3)earr[j]).msh_type==Canvas3D.MESH_Contact_Triangle) st_elements_Contact_Triangle.append(((_Element3)earr[j]).writeObject()+"\n");
1919 else
1920 if(earr[j] instanceof _Element3 && ((_Element3)earr[j]).msh_type==Canvas3D.MESH_Shell_C0_3) st_elements_Shell_C0_3.append(((_Element3)earr[j]).writeObject()+"\n");
1921 else
1922 if(earr[j] instanceof _Element4 && ((_Element4)earr[j]).msh_type==Canvas3D.MESH_Shell_BT_4) st_elements_Shell_BT_4.append(((_Element4)earr[j]).writeObject()+"\n");
1923 else
1924 if(earr[j] instanceof _Element4 && ((_Element4)earr[j]).msh_type==Canvas3D.MESH_Solid_Iso_4) st_elements_Solid_Iso_4.append(((_Element4)earr[j]).writeObject()+"\n");
1925 else
1926 if(earr[j] instanceof _Element8) st_elements_Solid_Iso_6.append(((_Element8)earr[j]).writeObject()+"\n");
1927 }
1928
1929 st_elements.append((st_elements_Rod_2.length()>23?st_elements_Rod_2.toString()+"\n\n":"")
1930 +(st_elements_Beam_2.length()>24?st_elements_Beam_2.toString()+"\n\n":"")
1931 +(st_elements_Beam_Spring_2.length()>31?st_elements_Beam_Spring_2.toString()+"\n\n":"")
1932 +(st_elements_Contact_Line.length()>30?st_elements_Contact_Line.toString()+"\n\n":"")
1933 +(st_elements_Contact_Triangle.length()>34?st_elements_Contact_Triangle.toString()+"\n\n":"")
1934 +(st_elements_Shell_C0_3.length()>28?st_elements_Shell_C0_3.toString()+"\n\n":"")
1935 +(st_elements_Shell_BT_4.length()>28?st_elements_Shell_BT_4.toString()+"\n\n":"")
1936 +(st_elements_Solid_Iso_4.length()>29?st_elements_Solid_Iso_4.toString()+"\n\n":"")
1937 +(st_elements_Solid_Iso_6.length()>29?st_elements_Solid_Iso_6.toString():""));
1938
1939 // Create printout of geometry
1940 headerMessage("Printing geometry");
1941 for(int j=0; j<geoarr.length; j++){
1942 if(geoarr[j] instanceof _Point) geo_Point.append(geoarr[j].writeObject()+"\n");
1943 else
1944 if(geoarr[j] instanceof _Arc) geo_Arc.append(geoarr[j].writeObject()+"\n");
1945 else
1946 if(geoarr[j] instanceof _Spline) geo_Spline.append(geoarr[j].writeObject()+"\n");
1947 else
1948 if(geoarr[j] instanceof _SurfBil) geo_SurfBil.append(geoarr[j].writeObject()+"\n");
1949 else
1950 if(geoarr[j] instanceof _SurfDir) geo_SurfDir.append(geoarr[j].writeObject()+"\n");
1951 else
1952 if(geoarr[j] instanceof _SurfFill) geo_SurfFill.append(geoarr[j].writeObject()+"\n");
1953 else
1954 if(geoarr[j] instanceof _SurfRev) geo_SurfRev.append(geoarr[j].writeObject()+"\n");
1955 else
1956 if(geoarr[j] instanceof _SurfRul) geo_SurfRul.append(geoarr[j].writeObject()+"\n");
1957
1958 }
1959
1960 st_geometry.append((geo_Point.length()>25?geo_Point.toString()+"\n\n":"")
1961 +(geo_Arc.length()>25?geo_Arc.toString()+"\n\n":"")
1962 +(geo_Spline.length()>25?geo_Spline.toString()+"\n\n":"")
1963 +(geo_SurfBil.length()>25?geo_SurfBil.toString()+"\n\n":"")
1964 +(geo_SurfDir.length()>25?geo_SurfDir.toString()+"\n\n":"")
1965 +(geo_SurfFill.length()>26?geo_SurfFill.toString()+"\n\n":"")
1966 +(geo_SurfRev.length()>25?geo_SurfRev.toString()+"\n\n":"")
1967 +(geo_SurfRul.length()>25?geo_SurfRul.toString()+"\n\n":""));
1968
1969
1970
1971 headerMessage("Printing materials");
1972 for(Enumeration en = MatDB.keys(); en.hasMoreElements();){
1973 String key = en.nextElement()+"";
1974 Material mat = (Material)MatDB.get(key);
1975 st = "MATERIALS OF TYPE "+mat.type+"\n"+mat.name+" "+mat.description+"\n\n";
1976 if(st_elements.indexOf("Material = "+mat.name)!=-1) st_model.append(st);
1977 }
1978
1979 headerMessage("Printing constraints");
1980 for(Enumeration en = ConstDB.keys(); en.hasMoreElements();){
1981 String key = en.nextElement()+"";
1982 Constraints con = (Constraints)ConstDB.get(key);
1983 st = "CONSTRAINTS OF TYPE "+con.type+"\n"+con.name+" "+con.description+"\n\n";
1984 if(st_nodes.indexOf("Constraint = "+con.name)!=-1)st_model.append(st);
1985 }
1986
1987 headerMessage("Printing loads");
1988 for(Enumeration en = LoadDB.keys(); en.hasMoreElements();){
1989 String key = en.nextElement()+"";
1990 Loads ld = (Loads)LoadDB.get(key);
1991 st = "LOADS "+"\n"+ld.name+" "+ld.description+"\n\n";
1992 if(st_nodes.indexOf("Load = "+ld.name)!=-1 || st_elements.indexOf("Load = "+ld.name)!=-1)st_model.append(st);
1993 }
1994
1995 headerMessage("Printing Groups");
1996 boolean firsttime = true;
1997
1998 for(int i=3; i<garr.length; i++){
1999 // Only print groups that are user defined
2000 if (garr[i] instanceof _GroupUserDefined) {
2001 if (firsttime) {
2002 st_model.append("GROUPS");
2003 firsttime = false;
2004 }
2005 st_model.append(garr[i].writeObject());
2006 }
2007 }
2008
2009 st_model.append("\n\n");
2010
2011 st_model.append(st_geometry.toString() + "\n\n" + st_nodes.toString()+"\n\n" + st_elements.toString());
2012
2013 headerMessage("Writing file");
2014 try{
2015 File f = new File(file_in);
2016 f.delete();
2017 RandomAccessFile fout = new RandomAccessFile(f,"rw");
2018 fout.writeBytes(st_model.toString());
2019 fout.close();
2020 }catch(Exception ex){error(ex);}
2021
2022 headerMessage(null);
2023 }
2024
2025
2026 /**
2027 * This method goes through the Canvas 3D view and checks with _Objects that
2028 * are selected. If an object is found, all occurances of this object in the
2029 * tree is selected.
2030 *
2031 * A block variable is set during this update to avoid triggering of the
2032 * SelectionChanged event for each change.
2033 *
2034 */
2035
rescanTree()2036 public void rescanTree() {
2037 Object obj;
2038 TreePath tp = Tree.getPathForRow(0);
2039 Vector tps = new Vector();
2040 TreePath[] ftps;
2041
2042 if (tp == null) return;
2043
2044 DefaultMutableTreeNode tn = (DefaultMutableTreeNode)tp.getPathComponent(0);
2045 Enumeration en = tn.depthFirstEnumeration();
2046
2047 block = true;
2048
2049 while (en.hasMoreElements()) {
2050 tn = (DefaultMutableTreeNode)en.nextElement();
2051 obj = tn.getUserObject();
2052 if(obj instanceof _Object)
2053 if (((_Object)obj).isSelected()) {
2054 tps.add(new TreePath(tn.getPath()));
2055 }
2056 }
2057
2058 ftps = new TreePath[tps.size()];
2059
2060
2061 for (int i=0; i < ftps.length; i++) {
2062 ftps[i] = (TreePath)tps.elementAt(i);
2063 }
2064
2065 Tree.setExpandsSelectedPaths(false);
2066
2067 Tree.addSelectionPaths(ftps);
2068
2069 block = false;
2070
2071 Tree.repaint();
2072 }
2073
2074 /**
2075 *
2076 * This method goes through the tree and checks which nodes that have
2077 * been selected. If a node is selected, the corresponding _Object is
2078 * set as selected in the canvas3D view.
2079 * Finally, the view is redrawn.
2080 *
2081 * @param e TreeSelectionEvent
2082 */
2083
treeSelectionChanged()2084 public void treeSelectionChanged() {
2085 J3D.clearSelectOnAllObjects3D();
2086 TreePath[] tp = Tree.getSelectionPaths();
2087 if(tp==null)return;
2088 for(int i=0; i<tp.length; i++){
2089 DefaultMutableTreeNode tn = (DefaultMutableTreeNode)tp[i].getLastPathComponent();
2090 Object obj = tn.getUserObject();
2091 int count = 0;
2092 if(obj instanceof _Object){ ((_Object)obj).setSelected(true); count++; }
2093 /*
2094 int lev = tn.getLevel();
2095 while((tn=tn.getNextNode())!=null && lev<tn.getLevel()){
2096 obj = tn.getUserObject();
2097 if(obj instanceof _Object){ ((_Object)obj).Select(tp[i]+""); count++; }
2098 }
2099 */
2100 if(count==0){
2101 obj = ((DefaultMutableTreeNode)tp[i].getParentPath().getLastPathComponent()).getUserObject();
2102 if(obj instanceof _Object) ((_Object)obj).setSelected(true);
2103 }
2104 }
2105 J3D.view_reset();
2106 }
2107
clearTree()2108 public void clearTree() {
2109 Tree.clearSelection();
2110 }
2111
headerMessage(String m)2112 public void headerMessage(String m) {
2113 Frame f = getFrame(this);
2114 String s = f.getTitle();
2115 if(m==null)m = ImpactGUI.ver;
2116 String s1 = s.substring(0,s.lastIndexOf("]")+1);
2117 f.setTitle(s1+" " + m);
2118
2119 }
2120
headerMessage(String m, float progress)2121 public void headerMessage(String m, float progress) {
2122 Frame f = getFrame(this);
2123 String s = f.getTitle();
2124 String p = ">>>>>>>>>>";
2125 String e = "----------|";
2126 progress *= 10.0;
2127 String s1 = s.substring(0,s.lastIndexOf("]")+1);
2128 f.setTitle(s1+" " + m + "|" + p.substring(0,(int)progress) + e.substring((int)progress,11));
2129
2130 }
2131
2132
2133
header(String m)2134 public void header(String m) {
2135 Frame f = getFrame(this);
2136 String s = f.getTitle();
2137
2138 String s1 = s.substring(0,s.indexOf("[PRE:")+6);
2139 String s2 = s.substring(s.indexOf("[PRO:"), s.length());
2140 f.setTitle(s1+m+"] "+s2);
2141 }
2142
requestAction()2143 public void requestAction() {
2144 if (edit_panel != null)
2145 edit_panel.requestAction();
2146 }
2147
2148 /**
2149 * Reads a Gmsh version 2 mesh file and generates elements and nodes in the preprocessor
2150 *
2151 * @param filename
2152 */
readGmsh(String filename)2153 public void readGmsh(String filename) throws FileNotFoundException, IOException, ParseException {
2154
2155 // Define regexp patterns for the data to import
2156 Regex Element = new Regex("^([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*([0-9]+)?\\s*$");
2157
2158 Regex Node = new Regex("^([0-9]+)\\s+([-+]?[0-9]+[.]?[0-9]*([eE][-+]?[0-9]+)?)\\s+([-+]?[0-9]+[.]?[0-9]*([eE][-+]?[0-9]+)?)\\s+([-+]?[0-9]+[.]?[0-9]*([eE][-+]?[0-9]+)?)\\s*$");
2159 Regex NrOf = new Regex("^\\s*([0-9]+)\\s*$");
2160
2161 Regex RNodes = new Regex("^\\s*\\$Nodes\\s*$");
2162 Regex RElem = new Regex("^\\s*\\$Elements\\s*$");
2163
2164 String str;
2165 _Node n;;
2166 Hashtable nodes = new Hashtable();
2167 int nr_of_nodes, i;
2168 int linenr = 0;
2169 int nr_of_elements = 0;
2170 String[] nn = new String[30];
2171 _Element el;
2172
2173 BufferedReader br = new BufferedReader(new FileReader(filename));
2174
2175 // Speed up the parsing
2176 Node.optimize();
2177 Element.optimize();
2178
2179 // Define group
2180 _Group g = new _Group(false, true);
2181 g.setName(filename);
2182 J3D.add3D(g);
2183
2184 _Group g_n = new _Group(false, false);
2185 g_n.setName("Node");
2186 J3D.add3D(g_n);
2187
2188 _Group g_e = new _Group(false, false);
2189 g_e.setName("Elem");
2190 J3D.add3D(g_e);
2191
2192 g.addToGroup(g_n);
2193 g.addToGroup(g_e);
2194
2195
2196 // Start parsing
2197 while (!RNodes.search(str = br.readLine())) linenr++;
2198
2199 // Start reading nodes
2200 str = br.readLine();
2201 linenr++;
2202
2203 if (NrOf.search(str)) nr_of_nodes = Integer.parseInt(NrOf.stringMatched(1));
2204 else throw new ParseException("No number of nodes found in Gmsh file:" + filename,linenr);
2205
2206 i = 0;
2207 while (Node.search(str = br.readLine())) {
2208
2209 linenr++;
2210 n = new _Node(Float.parseFloat(Node.stringMatched(2)),Float.parseFloat(Node.stringMatched(4)),Float.parseFloat(Node.stringMatched(6)));
2211 nodes.put(Node.stringMatched(1),n); //Nodenr, nodeobject
2212 g_n.addToGroup(n);
2213 J3D.add3D(n);
2214 headerMessage("Reading Nodes ",(float)i++/(float)nr_of_nodes);
2215
2216 }
2217
2218 // Read elements
2219 while (!RElem.search(str = br.readLine())) linenr++;
2220
2221 str = br.readLine();
2222 linenr++;
2223
2224 if (NrOf.search(str)) nr_of_elements = Integer.parseInt(NrOf.stringMatched(1));
2225 else throw new ParseException("No number of elements found in Gmsh file:" + filename,linenr);
2226
2227 i = 0;
2228 while (Element.search(str = br.readLine())) {
2229
2230 linenr++;
2231 headerMessage("Reading Elements ",(float)i++/(float)nr_of_elements);
2232
2233 switch(Integer.parseInt(Element.stringMatched(2))) {
2234
2235 case 1:
2236 nn[0] = Element.stringMatched(Integer.parseInt(Element.stringMatched(3))+4);
2237 nn[1] = Element.stringMatched(Integer.parseInt(Element.stringMatched(3))+5);
2238 if (nn[0] == null || nn[1] == null)
2239 throw new ParseException("No node number for element:" + Element.stringMatched(1),linenr);
2240 // Generate element
2241 el = new _Element2((_Node)nodes.get(nn[0]), (_Node)nodes.get(nn[1]));
2242 g_e.addToGroup(el);
2243 J3D.add3D(el);
2244 break;
2245
2246 case 2:
2247 nn[0] = Element.stringMatched(Integer.parseInt(Element.stringMatched(3))+4);
2248 nn[1] = Element.stringMatched(Integer.parseInt(Element.stringMatched(3))+5);
2249 nn[2] = Element.stringMatched(Integer.parseInt(Element.stringMatched(3))+6);
2250 if (nn[0] == null || nn[1] == null || nn[2] == null)
2251 throw new ParseException("No node number for element:" + Element.stringMatched(1),linenr);
2252 // Generate element
2253 el = new _Element3((_Node)nodes.get(nn[0]), (_Node)nodes.get(nn[1]), (_Node)nodes.get(nn[2]));
2254 g_e.addToGroup(el);
2255 J3D.add3D(el);
2256 break;
2257
2258 case 3:
2259 nn[0] = Element.stringMatched(Integer.parseInt(Element.stringMatched(3))+4);
2260 nn[1] = Element.stringMatched(Integer.parseInt(Element.stringMatched(3))+5);
2261 nn[2] = Element.stringMatched(Integer.parseInt(Element.stringMatched(3))+6);
2262 nn[3] = Element.stringMatched(Integer.parseInt(Element.stringMatched(3))+7);
2263 if (nn[0] == null || nn[1] == null || nn[2] == null || nn[3] == null)
2264 throw new ParseException("No node number for element:" + Element.stringMatched(1),linenr);
2265 // Generate element
2266 el = new _Element4((_Node)nodes.get(nn[0]), (_Node)nodes.get(nn[1]),(_Node)nodes.get(nn[2]), (_Node)nodes.get(nn[3]),Canvas3D.MESH_Shell_BT_4);
2267 g_e.addToGroup(el);
2268 J3D.add3D(el);
2269 break;
2270
2271 case 4:
2272 nn[0] = Element.stringMatched(Integer.parseInt(Element.stringMatched(3))+4);
2273 nn[1] = Element.stringMatched(Integer.parseInt(Element.stringMatched(3))+5);
2274 nn[2] = Element.stringMatched(Integer.parseInt(Element.stringMatched(3))+6);
2275 nn[3] = Element.stringMatched(Integer.parseInt(Element.stringMatched(3))+7);
2276 if (nn[0] == null || nn[1] == null || nn[2] == null || nn[3] == null)
2277 throw new ParseException("No node number for element:" + Element.stringMatched(1),linenr);
2278 // Generate element
2279 el = new _Element4((_Node)nodes.get(nn[0]), (_Node)nodes.get(nn[1]),(_Node)nodes.get(nn[2]), (_Node)nodes.get(nn[3]),Canvas3D.MESH_Solid_Iso_4);
2280 g_e.addToGroup(el);
2281 J3D.add3D(el);
2282 break;
2283
2284 case 5:
2285 for (int j=0; j<7; j++) {
2286 nn[j] = Element.stringMatched(Integer.parseInt(Element.stringMatched(3))+j+4);
2287 if (nn[j] == null)
2288 throw new ParseException("No node number for element:" + Element.stringMatched(1),linenr);
2289 }
2290 // Generate element
2291 el = new _Element8((_Node)nodes.get(nn[0]), (_Node)nodes.get(nn[1]),(_Node)nodes.get(nn[2]), (_Node)nodes.get(nn[3]), (_Node)nodes.get(nn[4]), (_Node)nodes.get(nn[5]),(_Node)nodes.get(nn[6]), (_Node)nodes.get(nn[7]));
2292 g_e.addToGroup(el);
2293 J3D.add3D(el);
2294 break;
2295
2296 case 6: // 6-node prism
2297 for (int j=0; j<5; j++) {
2298 nn[j] = Element.stringMatched(Integer.parseInt(Element.stringMatched(3))+j+4);
2299 if (nn[j] == null)
2300 throw new ParseException("No node number for element:" + Element.stringMatched(1),linenr);
2301 }
2302 // Generate element
2303 el = new _Element8((_Node)nodes.get(nn[0]), (_Node)nodes.get(nn[1]),(_Node)nodes.get(nn[2]), (_Node)nodes.get(nn[2]), (_Node)nodes.get(nn[3]), (_Node)nodes.get(nn[4]),(_Node)nodes.get(nn[5]), (_Node)nodes.get(nn[5]));
2304 g_e.addToGroup(el);
2305 J3D.add3D(el);
2306 break;
2307
2308 case 7: // 5-node pyramid
2309 for (int j=0; j<4; j++) {
2310 nn[j] = Element.stringMatched(Integer.parseInt(Element.stringMatched(3))+j+4);
2311 if (nn[j] == null)
2312 throw new ParseException("No node number for element:" + Element.stringMatched(1),linenr);
2313 }
2314 // Generate element
2315 el = new _Element8((_Node)nodes.get(nn[0]), (_Node)nodes.get(nn[1]),(_Node)nodes.get(nn[2]), (_Node)nodes.get(nn[3]), (_Node)nodes.get(nn[4]), (_Node)nodes.get(nn[4]),(_Node)nodes.get(nn[4]), (_Node)nodes.get(nn[4]));
2316 g_e.addToGroup(el);
2317 J3D.add3D(el);
2318 break;
2319
2320 case 8: // 3-node second order line
2321 break;
2322
2323 case 9: // 6-node second order triangle
2324 break;
2325
2326 case 10: // 9-node second order quadrangle
2327 break;
2328
2329 case 11: // 10-node second order tetrahedron
2330 break;
2331
2332 case 12: // 27-node second order hedahedron
2333 break;
2334
2335 case 13: // 18-node second order prism
2336 break;
2337
2338 case 14: // 14-node second order pyramid
2339 break;
2340
2341 case 15: // 1-node Point
2342 break;
2343
2344 case 16: // 8-node second order quadrangle
2345 break;
2346
2347 case 17: // 20-node second order hexahedron
2348 break;
2349
2350 case 18: // 15-node second order
2351 break;
2352
2353 case 19: // 13-node second order pyramid
2354 break;
2355
2356 default:
2357 throw new ParseException("Unsupported element type in Gmsh file:" + filename, linenr);
2358
2359 }
2360
2361 }
2362
2363 // Finished, now close
2364
2365 headerMessage("File Read Successfully");
2366 br.close();
2367
2368 }
2369 /**
2370 * Reads a Gmsh version 2 mesh file and generates elements and nodes in the preprocessor
2371 *
2372 * @param filename
2373 */
readNastran(String filename)2374 public void readNastran(String filename) throws FileNotFoundException, IOException, ParseException {
2375
2376 // Define regexp patterns for the data to import
2377 Regex GRID = new Regex("^GRID ([0-9 ]{8})([0-9 ]{8})([+\\-0-9.eE ]{8})([+\\-0-9.eE ]{8})([+\\-0-9.eE ]{1,8})([0-9 ]{1,8})?([0-9eE ]{1,8})? *$");
2378 Regex GRIDS1 = new Regex("^GRID\\* ([0-9 ]{16})([0-9 ]{16})([+\\-0-9.eE ]{16})([+\\-0-9.eE ]{1,16}) *$");
2379 Regex GRIDS2 = new Regex("^\\* ([+\\-0-9.eE ]{1,16})([0-9 ]{1,16})?([0-9eE ]{1,16})? *$");
2380 Regex FGRID = new Regex("^GRID\\*,([0-9 ]+),([0-9 ]+),([-+]?[0-9]+[.]?[0-9]*(?:[eE][-+]?[0-9]+)?),([-+]?[0-9]+[.]?[0-9]*(?:[eE][-+]?[0-9]+)?),([-+]?[0-9]+[.]?[0-9]*(?:[eE][-+]?[0-9]+)?),([0-9 ]+)?,?([0-9 ]{8})? *");
2381
2382 Regex CBAR = new Regex("^CBAR ([0-9 ]{8})([0-9 ]{8})([0-9 ]{8})([0-9 ]{1,8})([+\\-0-9. eE]{1,8})?([+\\-0-9. eE]{1,8})?([+\\-0-9. eE]{1,8})? *$");
2383 Regex CTRIA3 = new Regex("^CTRIA3 ([0-9 ]{8})([0-9 ]{8})([0-9 ]{8})([0-9 ]{8})([0-9 ]{1,8})([+\\-0-9. eE]{8})?([0-9 ]{8})?([+\\-0-9. eE]{8})? *$");
2384 Regex CQUAD4 = new Regex("^CQUAD4 ([0-9 ]{8})([0-9 ]{8})([0-9 ]{8})([0-9 ]{8})([0-9 ]{8})([0-9 ]{1,8})([+\\-0-9. eE]{8})?([0-9 ]{8})?([+\\-0-9. eE]{8})? *$");
2385 Regex CTETRA = new Regex("^CTETRA ([0-9 ]{8})([0-9 ]{8})([0-9 ]{8})([0-9 ]{8})([0-9 ]{8})([0-9 ]{1,8})([+\\-0-9. eE]{8})?([0-9 ]{8})?([+\\-0-9. eE]{8})? *$");
2386 Regex CHEXA1 = new Regex("^CHEXA ([0-9 ]{8})([0-9 ]{8})([0-9 ]{8})([0-9 ]{8})([0-9 ]{8})([0-9 ]{8})([0-9 ]{8})([0-9 ]{1,8}).*$");
2387 Regex CHEXA2 = new Regex("^........([0-9 ]{8})([0-9 ]{1,8})([+\\-0-9. eE]{8})?([0-9 ]{8})?([+\\-0-9. eE]{8})? *$");
2388 Regex CPENTA = new Regex("^CPENTA ([0-9 ]{8})([0-9 ]{8})([0-9 ]{8})([0-9 ]{8})([0-9 ]{8})([0-9 ]{8})([0-9 ]{8})([0-9 ]{1,8})[ +]*$");
2389
2390 Regex TO_ENG = new Regex("( *[-+][0-9.]*)([-+])","${1}E${2}");
2391
2392 String str;
2393 _Node n;
2394 Hashtable nodes = new Hashtable();
2395 int i;
2396 int linenr = 0;
2397 String[] nn = new String[30];
2398 _Node[] nod = new _Node[16];
2399 _Element el;
2400
2401 BufferedReader br = new BufferedReader(new FileReader(filename));
2402
2403 // Speed up the parsing
2404 GRID.optimize();
2405 GRIDS1.optimize();
2406 GRIDS2.optimize();
2407 FGRID.optimize();
2408 CBAR.optimize();
2409 CTRIA3.optimize();
2410 CQUAD4.optimize();
2411 CTETRA.optimize();
2412 CHEXA1.optimize();
2413 CHEXA2.optimize();
2414 CPENTA.optimize();
2415
2416 // Define group
2417 _Group g = new _Group(false, true);
2418 g.setName(filename);
2419 J3D.add3D(g);
2420
2421 _Group g_n = new _Group(false, false);
2422 g_n.setName("Node");
2423 J3D.add3D(g_n);
2424
2425 _Group g_e = new _Group(false, false);
2426 g_e.setName("Elem");
2427 J3D.add3D(g_e);
2428
2429 g.addToGroup(g_n);
2430 g.addToGroup(g_e);
2431
2432
2433 // Start reading nodes
2434 i = 0;
2435 while ((str = br.readLine()) != null) {
2436
2437 if (GRID.search(str)) {
2438 linenr++;
2439 n = new _Node(Float.parseFloat(TO_ENG.replaceAllFrom(GRID.stringMatched(3),2)),Float.parseFloat(TO_ENG.replaceAllFrom(GRID.stringMatched(4),2)),Float.parseFloat(TO_ENG.replaceAllFrom(GRID.stringMatched(5),2)));
2440 nodes.put(GRID.stringMatched(1).trim(),n); //Nodenr, nodeobject
2441 g_n.addToGroup(n);
2442 J3D.add3D(n);
2443 headerMessage("Reading Node: " + i++);
2444 }
2445 else
2446 if (GRIDS1.search(str)) {
2447 linenr++;
2448 float x,y,z;
2449 x = Float.parseFloat(TO_ENG.replaceAll(GRIDS1.stringMatched(3)));
2450 y = Float.parseFloat(TO_ENG.replaceAll(GRIDS1.stringMatched(4)));
2451 if (!GRIDS2.search(str = br.readLine()))
2452 throw new ParseException("No second line found for GRID*:" + CHEXA1.stringMatched(1),linenr);
2453 z = Float.parseFloat(TO_ENG.replaceAll(GRIDS2.stringMatched(1)));
2454 n = new _Node(x,y,z);
2455 nodes.put(GRIDS1.stringMatched(1).trim(),n); //Nodenr, nodeobject
2456 g_n.addToGroup(n);
2457 J3D.add3D(n);
2458 headerMessage("Reading Node: " + i++);
2459 }
2460 else
2461 if (FGRID.search(str)) {
2462 linenr++;
2463 n = new _Node(Float.parseFloat(TO_ENG.replaceAll(FGRID.stringMatched(3))),Float.parseFloat(TO_ENG.replaceAll(FGRID.stringMatched(4))),Float.parseFloat(TO_ENG.replaceAll(FGRID.stringMatched(5))));
2464 nodes.put(FGRID.stringMatched(1).trim(),n); //Nodenr, nodeobject
2465 g_n.addToGroup(n);
2466 J3D.add3D(n);
2467 headerMessage("Reading Node: " + i++);
2468 }
2469
2470 }
2471
2472 br.close();
2473
2474
2475 // Now, read the elements
2476 br = new BufferedReader(new FileReader(filename));
2477 linenr = 0;
2478 i=0;
2479
2480 while ((str = br.readLine()) != null) {
2481 linenr++;
2482
2483 if (CBAR.search(str)) {
2484 for (int j=0; j<2; j++) {
2485 nn[j] = CBAR.stringMatched(j+3).trim();
2486 if (nn[j] == null)
2487 throw new ParseException("No node number for element:" + CBAR.stringMatched(1),linenr);
2488 nod[j] = (_Node)nodes.get(nn[j]);
2489 if (nod[j] == null)
2490 throw new ParseException("No matching node found for element:" + CBAR.stringMatched(1),linenr);
2491 }
2492
2493 // Generate element
2494 el = new _Element2(nod[0], nod[1]);
2495 g_e.addToGroup(el);
2496 J3D.add3D(el);
2497 headerMessage("Reading CBAR: " + i++);
2498 }
2499 else
2500 if (CTRIA3.search(str)) {
2501 for (int j=0; j<3; j++) {
2502 nn[j] = CTRIA3.stringMatched(j+3).trim();
2503 if (nn[j] == null)
2504 throw new ParseException("No node number for element:" + CTRIA3.stringMatched(1),linenr);
2505 nod[j] = (_Node)nodes.get(nn[j]);
2506 if (nod[j] == null)
2507 throw new ParseException("No matching node found for element:" + CTRIA3.stringMatched(1),linenr);
2508 }
2509
2510 // Generate element
2511 el = new _Element3(nod[0], nod[1], nod[2]);
2512 g_e.addToGroup(el);
2513 J3D.add3D(el);
2514 headerMessage("Reading CTRIA3: " + i++);
2515 }
2516 else
2517 if (CQUAD4.search(str)) {
2518 for (int j=0; j<4; j++) {
2519 nn[j] = CQUAD4.stringMatched(j+3).trim();
2520 if (nn[j] == null)
2521 throw new ParseException("No node number for element:" + CQUAD4.stringMatched(1),linenr);
2522 nod[j] = (_Node)nodes.get(nn[j]);
2523 if (nod[j] == null)
2524 throw new ParseException("No matching node found for element:" + CQUAD4.stringMatched(1),linenr);
2525 }
2526
2527 // Generate element
2528 el = new _Element4(nod[0], nod[1], nod[2], nod[3], Canvas3D.MESH_Shell_BT_4);
2529 g_e.addToGroup(el);
2530 J3D.add3D(el);
2531 headerMessage("Reading CQUAD4: " + i++);
2532 }
2533 else
2534 if (CTETRA.search(str)) {
2535 for (int j=0; j<4; j++) {
2536 nn[j] = CTETRA.stringMatched(j+3).trim();
2537 if (nn[j] == null)
2538 throw new ParseException("No node number for element:" + CTETRA.stringMatched(1),linenr);
2539 nod[j] = (_Node)nodes.get(nn[j]);
2540 if (nod[j] == null)
2541 throw new ParseException("No matching node found for element:" + CTETRA.stringMatched(1),linenr);
2542 }
2543
2544 // Generate element
2545 el = new _Element4(nod[0], nod[1], nod[2], nod[3], Canvas3D.MESH_Solid_Iso_4);
2546 g_e.addToGroup(el);
2547 J3D.add3D(el);
2548 headerMessage("Reading CTETRA: " + i++);
2549 }
2550 else
2551 if (CHEXA1.search(str)) {
2552 for (int j=0; j<6; j++) {
2553 nn[j] = CHEXA1.stringMatched(j+3).trim();
2554 if (nn[j] == null)
2555 throw new ParseException("No node number for element:" + CHEXA1.stringMatched(1),linenr);
2556 nod[j] = (_Node)nodes.get(nn[j]);
2557 if (nod[j] == null)
2558 throw new ParseException("No matching node "+nn[j]+" found for element:" + CHEXA1.stringMatched(1),linenr);
2559 }
2560
2561 if (!CHEXA2.search(str = br.readLine()))
2562 throw new ParseException("No last two nodes found for element:" + CHEXA1.stringMatched(1),linenr);
2563 for (int j=6; j<8; j++) {
2564 nn[j] = CHEXA2.stringMatched(j-5).trim();
2565 if (nn[j] == null)
2566 throw new ParseException("No node number for element:" + CHEXA1.stringMatched(1),linenr);
2567 nod[j] = (_Node)nodes.get(nn[j]);
2568 if (nod[j] == null)
2569 throw new ParseException("No matching node "+nn[j]+" found for element:" + CHEXA1.stringMatched(1),linenr);
2570 }
2571
2572 // Generate element
2573 el = new _Element8(nod[0], nod[1], nod[2], nod[3], nod[4], nod[5], nod[6], nod[7]);
2574 g_e.addToGroup(el);
2575 J3D.add3D(el);
2576 headerMessage("Reading CHEXA: " + i++);
2577 }
2578 else
2579 if (CPENTA.search(str)) {
2580 for (int j=0; j<6; j++) {
2581 nn[j] = CPENTA.stringMatched(j+3).trim();
2582 if (nn[j] == null)
2583 throw new ParseException("No node number for element:" + CPENTA.stringMatched(1),linenr);
2584 nod[j] = (_Node)nodes.get(nn[j]);
2585 if (nod[j] == null)
2586 throw new ParseException("No matching node "+nn[j]+" found for element:" + CPENTA.stringMatched(1),linenr);
2587 }
2588
2589 // Generate element
2590 el = new _Element8(nod[0], nod[1], nod[2], nod[2], nod[3], nod[4], nod[5], nod[5]);
2591 g_e.addToGroup(el);
2592 J3D.add3D(el);
2593 headerMessage("Reading CPENTA: " + i++);
2594 }
2595 }
2596
2597 headerMessage("File Read Successfully");
2598 br.close();
2599
2600 }
2601 /**
2602 * Reads a Gmsh version 2 mesh file and generates elements and nodes in the preprocessor
2603 *
2604 * @param filename
2605 */
readUNV(String filename)2606 public void readUNV(String filename) throws FileNotFoundException, IOException, ParseException {
2607
2608 // Define regexp patterns for the data to import
2609
2610 Regex SETNODES = new Regex("^\\s*2411\\s*$");
2611 Regex SETELEMENTS = new Regex("^\\s*2412\\s*$");
2612 Regex END = new Regex("^\\s*-1\\s*$");
2613
2614 Regex NODE1 = new Regex("^([+\\-0-9 ]{10})([+\\-0-9 ]{10})([+\\-0-9 ]{10})([+\\-0-9 ]{1,10})\\s*$");
2615 Regex NODE2 = new Regex("^([+\\-0-9.eED ]{25})([+\\-0-9.eED ]{25})([+\\-0-9.eED ]{1,25})\\s*$");
2616
2617 Regex ELEMENT1 = new Regex("^([0-9 ]{10})([0-9 ]{10})([0-9 ]{10})([0-9 ]{10})([0-9 ]{10})([0-9 ]{10})\\s*$");
2618 Regex ELEMENT2 = new Regex("^([0-9 ]{10})([0-9 ]{10})([0-9 ]{10})?([0-9 ]{10})?([0-9 ]{10})?([0-9 ]{10})?([0-9 ]{10})?([0-9 ]{10})?\\s*$");
2619
2620 Regex TO_ENG = new Regex("D","E");
2621
2622 String str;
2623 _Node n;
2624 Hashtable nodes = new Hashtable();
2625 int i, eltype, nnodes;
2626 boolean inblock = false;
2627 int linenr = 0;
2628 String[] nn = new String[30];
2629 _Node[] nod = new _Node[16];
2630 String elname;
2631 _Object o;
2632
2633 BufferedReader br = new BufferedReader(new FileReader(filename));
2634
2635 // Speed up the parsing
2636 SETNODES.optimize();
2637 SETELEMENTS.optimize();
2638 END.optimize();
2639 NODE1.optimize();
2640 NODE2.optimize();
2641 ELEMENT1.optimize();
2642 ELEMENT2.optimize();
2643
2644 // Define group
2645 _Group g = new _Group(false, true);
2646 g.setName(filename);
2647 J3D.add3D(g);
2648
2649 _Group g_n = new _Group(false, false);
2650 g_n.setName("Node");
2651 J3D.add3D(g_n);
2652
2653 _Group g_e = new _Group(false, false);
2654 g_e.setName("Elem");
2655 J3D.add3D(g_e);
2656
2657 g.addToGroup(g_n);
2658 g.addToGroup(g_e);
2659
2660 // Start reading nodes
2661 i = 0;
2662 inblock = false;
2663
2664 while ((str = br.readLine()) != null) {
2665 linenr++;
2666
2667 if (SETNODES.search(str)) inblock = true;
2668 if (END.search(str)) inblock = false;
2669
2670 if (inblock) {
2671
2672 if (NODE1.search(str))
2673 nn[0] = NODE1.stringMatched(1).trim();
2674
2675 if (NODE2.search(str)) {
2676 n = new _Node(Float.parseFloat(TO_ENG.replaceAll(NODE2.stringMatched(1))),Float.parseFloat(TO_ENG.replaceAll(NODE2.stringMatched(2))),Float.parseFloat(TO_ENG.replaceAll(NODE2.stringMatched(3))));
2677 nodes.put(nn[0],n); //Nodenr, nodeobject
2678 g_n.addToGroup(n);
2679 J3D.add3D(n);
2680 headerMessage("Reading Node: " + i++);
2681 }
2682
2683 }
2684 }
2685 br.close();
2686
2687 // Now, read the elements
2688 br = new BufferedReader(new FileReader(filename));
2689 linenr = 0;
2690 i=0;
2691 nnodes = 0;
2692 elname = "";
2693 eltype = 0;
2694
2695 while ((str = br.readLine()) != null) {
2696 linenr++;
2697
2698 if (SETELEMENTS.search(str)) inblock = true;
2699 if (END.search(str)) inblock = false;
2700
2701 if (inblock) {
2702
2703 if (ELEMENT1.search(str)) {
2704 elname = ELEMENT1.stringMatched(1).trim();
2705 eltype = Integer.parseInt(ELEMENT1.stringMatched(2).trim());
2706 nnodes = Integer.parseInt(ELEMENT1.stringMatched(6).trim());
2707 str = br.readLine();
2708 }
2709
2710 if (ELEMENT2.search(str) && eltype < 41) // Skip one line for beam and rod elements
2711 str = br.readLine();
2712
2713 if (nnodes > 8)
2714 throw new ParseException("Impact does not support higher order elements. Error at element:" + elname, linenr);
2715
2716 if (ELEMENT2.search(str) && nnodes <= 8) {
2717 for (int j=0; j<nnodes; j++) {
2718 nn[j] = ELEMENT2.stringMatched(j+1).trim();
2719 if (nn[j] == null)
2720 throw new ParseException("No node number for element:" + elname, linenr);
2721 nod[j] = (_Node)nodes.get(nn[j]);
2722 if (nod[j] == null)
2723 throw new ParseException("No matching node found for element:" + elname, linenr);
2724 }
2725
2726 // Generate element
2727
2728 switch(eltype) {
2729
2730 case 11:
2731 o = new _Element2(nod[0], nod[1]);
2732 J3D.add3D(o);
2733 g_e.addToGroup(o);
2734 headerMessage("Reading BAR: " + i++);
2735 break;
2736
2737 case 31:
2738 o = new _Element2(nod[0], nod[1]);
2739 J3D.add3D(o);
2740 g_e.addToGroup(o);
2741 headerMessage("Reading PIPE: " + i++);
2742 break;
2743
2744 case 41:
2745 o = new _Element3(nod[0], nod[1], nod[2]);
2746 J3D.add3D(o);
2747 g_e.addToGroup(o);
2748 headerMessage("Reading TRIA: " + i++);
2749 break;
2750
2751 case 51:
2752 o = new _Element3(nod[0], nod[1], nod[2]);
2753 J3D.add3D(o);
2754 g_e.addToGroup(o);
2755 headerMessage("Reading TRIA: " + i++);
2756 break;
2757
2758 case 61:
2759 o = new _Element3(nod[0], nod[1], nod[2]);
2760 J3D.add3D(o);
2761 g_e.addToGroup(o);
2762 headerMessage("Reading TRIA: " + i++);
2763 break;
2764
2765 case 74:
2766 o = new _Element3(nod[0], nod[1], nod[2]);
2767 J3D.add3D(o);
2768 g_e.addToGroup(o);
2769 headerMessage("Reading TRIA: " + i++);
2770 break;
2771
2772 case 91:
2773 o = new _Element3(nod[0], nod[1], nod[2]);
2774 J3D.add3D(o);
2775 g_e.addToGroup(o);
2776 headerMessage("Reading TRIA: " + i++);
2777 break;
2778
2779 case 44:
2780 o = new _Element4(nod[0], nod[1], nod[2], nod[3], Canvas3D.MESH_Shell_BT_4);
2781 J3D.add3D(o);
2782 g_e.addToGroup(o);
2783 headerMessage("Reading QUAD: " + i++);
2784 break;
2785
2786 case 54:
2787 o = new _Element4(nod[0], nod[1], nod[2], nod[3], Canvas3D.MESH_Shell_BT_4);
2788 J3D.add3D(o);
2789 g_e.addToGroup(o);
2790 headerMessage("Reading QUAD: " + i++);
2791 break;
2792
2793 case 64:
2794 o = new _Element4(nod[0], nod[1], nod[2], nod[3], Canvas3D.MESH_Shell_BT_4);
2795 J3D.add3D(o);
2796 g_e.addToGroup(o);
2797 headerMessage("Reading QUAD: " + i++);
2798 break;
2799
2800 case 84:
2801 o = new _Element4(nod[0], nod[1], nod[2], nod[3], Canvas3D.MESH_Shell_BT_4);
2802 J3D.add3D(o);
2803 g_e.addToGroup(o);
2804 headerMessage("Reading QUAD: " + i++);
2805 break;
2806
2807 case 94:
2808 o = new _Element4(nod[0], nod[1], nod[2], nod[3], Canvas3D.MESH_Shell_BT_4);
2809 J3D.add3D(o);
2810 g_e.addToGroup(o);
2811 headerMessage("Reading QUAD: " + i++);
2812 break;
2813
2814 case 111:
2815 o = new _Element4(nod[0], nod[1], nod[2], nod[3], Canvas3D.MESH_Solid_Iso_4);
2816 J3D.add3D(o);
2817 g_e.addToGroup(o);
2818 headerMessage("Reading TETRA: " + i++);
2819 break;
2820
2821 case 112:
2822 o = new _Element8(nod[0], nod[1], nod[2], nod[2], nod[3], nod[4], nod[5], nod[5]);
2823 J3D.add3D(o);
2824 g_e.addToGroup(o);
2825 headerMessage("Reading WEDGE: " + i++);
2826 break;
2827
2828 case 115:
2829 o = new _Element8(nod[0], nod[1], nod[2], nod[3], nod[4], nod[5], nod[6], nod[7]);
2830 J3D.add3D(o);
2831 g_e.addToGroup(o);
2832 headerMessage("Reading BRICK: " + i++);
2833 break;
2834
2835 }
2836
2837 }
2838 }
2839 }
2840
2841 headerMessage("File Read Successfully");
2842 br.close();
2843 }
2844
readIN(String filename)2845 public void readIN(String filename) throws FileNotFoundException, IOException, ParseException {
2846 Hashtable NDB = new Hashtable();
2847 Hashtable EDB = new Hashtable();
2848 Hashtable GDB = new Hashtable();
2849 Hashtable GRDB = new Hashtable();
2850 Hashtable MatDB = new Hashtable();
2851 Hashtable ConstDB = new Hashtable();
2852 Hashtable LoadDB = new Hashtable();
2853 String file_src;
2854 String ContpolsDB="",TrackersDB="";
2855 String st;
2856 boolean inblock = false;
2857
2858 // Define group
2859 _Group g = new _Group(false, true);
2860 g.setName(filename);
2861 J3D.add3D(g);
2862
2863 _Group g_n = new _Group(false, false);
2864 g_n.setName("Node");
2865 J3D.add3D(g_n);
2866
2867 _Group g_e = new _Group(false, false);
2868 g_e.setName("Elem");
2869 J3D.add3D(g_e);
2870
2871 _Group g_g = new _Group(false, false);
2872 g_g.setName("Geo");
2873 J3D.add3D(g_g);
2874
2875 g.addToGroup(g_n);
2876 g.addToGroup(g_e);
2877 g.addToGroup(g_g);
2878
2879 // Start parsing
2880 RandomAccessFile in = new RandomAccessFile(filename, "r");
2881 byte[] b = new byte[(int)in.length()];
2882 in.read(b,0,(int)in.length());
2883 file_src = new String(b);
2884
2885 file_src = file_src.replaceAll("\t"," ");
2886
2887 // CONTROLS
2888 StringTokenizer stt = new StringTokenizer(file_src,"\n");
2889 while (stt.hasMoreTokens()) {
2890 st = stt.nextToken().trim().toUpperCase();
2891 if(st.startsWith("CONTROLS")){
2892 ContpolsDB = st+"\n";
2893 while (stt.hasMoreTokens()) {
2894 st = stt.nextToken().trim().toUpperCase();
2895 if(st.startsWith("#") || st.length()==0)continue;
2896 if(st.startsWith("GROUPS") || st.startsWith("NODES") || st.startsWith("ELEMENTS") || st.startsWith("MATERIALS") || st.startsWith("TRACKERS") || st.indexOf("BOUNDARY_CONDITION")!=-1 || st.indexOf("RIGID_BODY")!=-1 || st.indexOf("LOADS")!=-1)break;
2897 ContpolsDB += st+"\n";
2898 }
2899 }
2900 }
2901
2902 // TRACKERS
2903 stt = new StringTokenizer(file_src,"\n");
2904 while (stt.hasMoreTokens()) {
2905 st = stt.nextToken().trim().toUpperCase();
2906 if(st.startsWith("TRACKERS")){
2907 TrackersDB = st+"\n";
2908 while (stt.hasMoreTokens()) {
2909 st = stt.nextToken().trim().toUpperCase();
2910 if(st.startsWith("#") || st.length()==0)continue;
2911 if(st.startsWith("GROUPS") || st.startsWith("NODES") || st.startsWith("ELEMENTS") || st.startsWith("CONTROLS") || st.startsWith("MATERIALS") || st.indexOf("BOUNDARY_CONDITION")!=-1 || st.indexOf("RIGID_BODY")!=-1 || st.indexOf("LOADS")!=-1)break;
2912 TrackersDB += st+"\n";
2913 }
2914 }
2915
2916 // Material
2917 stt = new StringTokenizer(file_src,"\n");
2918 while (stt.hasMoreTokens()) {
2919 st = stt.nextToken().trim().toUpperCase();
2920 if(st.startsWith("MATERIALS")){
2921 String mat_type=null;
2922 if(st.indexOf("ELASTIC")!=-1){
2923 mat_type = "ELASTIC";
2924 }else if(st.indexOf("ELASTOPLASTIC")!=-1){
2925 mat_type = "ELASTOPLASTIC";
2926 }else if(st.indexOf("THERMOELASTOPLASTIC")!=-1){
2927 mat_type = "THERMOELASTOPLASTIC";
2928 }else if(st.indexOf("SPRING")!=-1){
2929 mat_type = "SPRING";
2930 }
2931 while (stt.hasMoreTokens()) {
2932 st = stt.nextToken().trim().toUpperCase();
2933 if(st.startsWith("#") || st.length()==0 || st.startsWith("MATERIALS"))continue;
2934 if(st.startsWith("GROUPS") || st.startsWith("NODES") || st.startsWith("ELEMENTS") || st.startsWith("CONTROLS") || st.startsWith("TRACKERS") || st.indexOf("BOUNDARY_CONDITION")!=-1 || st.indexOf("RIGID_BODY")!=-1 || st.indexOf("LOADS")!=-1)break;
2935 StringTokenizer stt1 = new StringTokenizer(st," =\t");
2936 String mat_name = stt1.nextToken();
2937 String mat_discription = st.substring(mat_name.length());
2938 Material mat = new Material();
2939 mat.color=Color.gray;
2940 mat.description=mat_discription;
2941 mat.name=mat_name;
2942 mat.type=mat_type;
2943 if(!MatDB.containsKey(mat.name)) MatDB.put(mat.name,mat);
2944 }
2945 }
2946 }
2947
2948 // Constraints
2949 stt = new StringTokenizer(file_src,"\n");
2950 while (stt.hasMoreTokens()) {
2951 st = stt.nextToken().trim().toUpperCase();
2952 if(st.startsWith("CONSTRAINTS")){
2953 String constr_type=null;
2954 if(st.indexOf("BOUNDARY_CONDITION")!=-1){
2955 constr_type = "BOUNDARY_CONDITION";
2956 }else if(st.indexOf("RIGID_BODY")!=-1){
2957 constr_type = "RIGID_BODY";
2958 }
2959 while (stt.hasMoreTokens()) {
2960 st = stt.nextToken().trim().toUpperCase();
2961 if(st.startsWith("#") || st.length()==0 || st.startsWith("CONSTRAINTS"))continue;
2962 if(st.startsWith("GROUPS") || st.startsWith("NODES") || st.startsWith("ELEMENTS") || st.startsWith("CONTROLS") || st.startsWith("TRACKERS") || st.startsWith("MATERIALS") || st.indexOf("LOADS")!=-1)break;
2963 StringTokenizer stt1 = new StringTokenizer(st," =\t");
2964 String constr_name = stt1.nextToken();
2965 String constr_discription = st.substring(constr_name.length());
2966 Constraints constr = new Constraints();
2967 constr.color=Color.red;
2968 constr.description=constr_discription;
2969 constr.name=constr_name;
2970 constr.type=constr_type;
2971 if(!ConstDB.containsKey(constr.name)) ConstDB.put(constr.name,constr);
2972 }
2973 }
2974 }
2975
2976 // Loads
2977 stt = new StringTokenizer(file_src,"\n");
2978 while (stt.hasMoreTokens()) {
2979 st = stt.nextToken().trim().toUpperCase();
2980 if(st.startsWith("LOADS")){
2981 while (stt.hasMoreTokens()) {
2982 st = stt.nextToken().trim().toUpperCase();
2983 if(st.startsWith("#") || st.length()==0 || st.startsWith("LOADS"))continue;
2984 if(st.startsWith("GROUPS") || st.startsWith("NODES") || st.startsWith("ELEMENTS") || st.startsWith("CONTROLS") || st.startsWith("TRACKERS") || st.startsWith("MATERIALS") || st.indexOf("BOUNDARY_CONDITION")!=-1 || st.indexOf("RIGID_BODY")!=-1)break;
2985 StringTokenizer stt1 = new StringTokenizer(st," =\t");
2986 String load_name = stt1.nextToken();
2987 String load_discription = st.substring(load_name.length());
2988 Loads load = new Loads();
2989 load.color=Color.blue;
2990 load.description=load_discription;
2991 load.name=load_name;
2992 if(!LoadDB.containsKey(load.name)) LoadDB.put(load.name,load);
2993 }
2994 }
2995 }
2996
2997 // NODES
2998 stt = new StringTokenizer(file_src,"\n");
2999 while (stt.hasMoreTokens()) {
3000 st = stt.nextToken().trim().toUpperCase();
3001 if(st.equals("NODES")){
3002 while (stt.hasMoreTokens()) {
3003 st = stt.nextToken().trim().toUpperCase();
3004 if(st.startsWith("GROUPS") || st.startsWith("LOADS") || st.startsWith("ELEMENTS") || st.startsWith("CONTROLS") || st.startsWith("TRACKERS") || st.startsWith("MATERIALS") || st.indexOf("BOUNDARY_CONDITION")!=-1 || st.indexOf("RIGID_BODY")!=-1)break;
3005 if(st.startsWith("#") || st.length()==0)continue;
3006 StringTokenizer stt1 = new StringTokenizer(st," =XYZ\t");
3007 String key = stt1.nextToken();
3008 _Node nd = new _Node(Float.parseFloat(stt1.nextToken()),Float.parseFloat(stt1.nextToken()),Float.parseFloat(stt1.nextToken()));
3009 nd.set_Id(key);
3010
3011 if(st.indexOf("CONSTRAINT")!=-1){
3012 String st1 = st.substring(st.indexOf("CONSTRAINT")+10);
3013 stt1 = new StringTokenizer(st1," \t");
3014 stt1.nextToken();
3015 nd.constraint = (Constraints)ConstDB.get(stt1.nextToken());
3016 }
3017 if(st.indexOf("LOAD")!=-1){
3018 String st1 = st.substring(st.indexOf("LOAD")+4);
3019 stt1 = new StringTokenizer(st1," \t");
3020 stt1.nextToken();
3021 nd.load = (Loads)LoadDB.get(stt1.nextToken());
3022 }
3023 NDB.put(key,nd);
3024 }
3025 }
3026 }
3027
3028 // ELEMENTS
3029 stt = new StringTokenizer(file_src,"\n");
3030 while (stt.hasMoreTokens()) {
3031 st = stt.nextToken().trim().toUpperCase();
3032 if(st.startsWith("ELEMENTS")){
3033 String el_msh_name=null;
3034 int el_msh_type=-1;
3035 if(st.indexOf("BEAM_2")!=-1){
3036 el_msh_name = "Beam_2";
3037 el_msh_type = Canvas3D.MESH_Beam_2;
3038 }else if(st.indexOf("CONTACT_TRIANGLE")!=-1){
3039 el_msh_name = "Contact_Triangle";
3040 el_msh_type = Canvas3D.MESH_Contact_Triangle;
3041 }else if(st.indexOf("CONTACT_LINE")!=-1){
3042 el_msh_name = "Contact_Line";
3043 el_msh_type = Canvas3D.MESH_Contact_Line;
3044 }else if(st.indexOf("ROD_2")!=-1){
3045 el_msh_name = "Rod_2";
3046 el_msh_type = Canvas3D.MESH_Rod_2;
3047 }else if(st.indexOf("BEAM_SPRING_2")!=-1){
3048 el_msh_name = "Beam_Spring_2";
3049 el_msh_type = Canvas3D.MESH_Beam_Spring_2;
3050 }else if(st.indexOf("SHELL_BT_4")!=-1){
3051 el_msh_name = "Shell_BT_4";
3052 el_msh_type = Canvas3D.MESH_Shell_BT_4;
3053 }else if(st.indexOf("SHELL_C0_3")!=-1){
3054 el_msh_name = "Shell_C0_3";
3055 el_msh_type = Canvas3D.MESH_Shell_C0_3;
3056 }else if(st.indexOf("SOLID_ISO_4")!=-1){
3057 el_msh_name = "Solid_Iso_4";
3058 el_msh_type = Canvas3D.MESH_Solid_Iso_4;
3059 }else if(st.indexOf("SOLID_ISO_6")!=-1){
3060 el_msh_name = "Solid_Iso_6";
3061 el_msh_type = Canvas3D.MESH_Solid_Iso_6;
3062 }
3063
3064 while (stt.hasMoreTokens()) {
3065 st = stt.nextToken().trim().toUpperCase();
3066 if(st.startsWith("#") || st.length()==0)continue;
3067 if(st.startsWith("ELEMENTS")){
3068 el_msh_name=null;
3069 el_msh_type=-1;
3070 if(st.indexOf("BEAM_2")!=-1){
3071 el_msh_name = "Beam_2";
3072 el_msh_type = Canvas3D.MESH_Beam_2;
3073 }else if(st.indexOf("CONTACT_TRIANGLE")!=-1){
3074 el_msh_name = "Contact_Triangle";
3075 el_msh_type = Canvas3D.MESH_Contact_Triangle;
3076 }else if(st.indexOf("CONTACT_LINE")!=-1){
3077 el_msh_name = "Contact_Line";
3078 el_msh_type = Canvas3D.MESH_Contact_Line;
3079 }else if(st.indexOf("ROD_2")!=-1){
3080 el_msh_name = "Rod_2";
3081 el_msh_type = Canvas3D.MESH_Rod_2;
3082 }else if(st.indexOf("BEAM_SPRING_2")!=-1){
3083 el_msh_name = "Beam_Spring_2";
3084 el_msh_type = Canvas3D.MESH_Beam_Spring_2;
3085 }else if(st.indexOf("SHELL_BT_4")!=-1){
3086 el_msh_name = "Shell_BT_4";
3087 el_msh_type = Canvas3D.MESH_Shell_BT_4;
3088 }else if(st.indexOf("SHELL_C0_3")!=-1){
3089 el_msh_name = "Shell_C0_3";
3090 el_msh_type = Canvas3D.MESH_Shell_C0_3;
3091 }else if(st.indexOf("SOLID_ISO_4")!=-1){
3092 el_msh_name = "Solid_Iso_4";
3093 el_msh_type = Canvas3D.MESH_Solid_Iso_4;
3094 }else if(st.indexOf("SOLID_ISO_6")!=-1){
3095 el_msh_name = "Solid_Iso_6";
3096 el_msh_type = Canvas3D.MESH_Solid_Iso_6;
3097 }
3098 continue;
3099 }
3100
3101 if(st.startsWith("GROUPS") || st.startsWith("NODES") || st.startsWith("CONTROLS") || st.startsWith("TRACKERS") || st.startsWith("MATERIALS") || st.indexOf("BOUNDARY_CONDITION")!=-1 || st.indexOf("RIGID_BODY")!=-1 || st.indexOf("LOADS")!=-1)break;
3102 StringTokenizer stt1 = new StringTokenizer(st,"[]");
3103 String key = stt1.nextToken();
3104 key = new StringTokenizer(key," \t").nextToken();
3105 String st_nd = stt1.nextToken();
3106 String st_load = stt1.nextToken();
3107 StringTokenizer stt2 = new StringTokenizer(st_nd,", \t");
3108 int[] arr = new int[stt2.countTokens()];
3109 int i=0;
3110 while (stt2.hasMoreTokens()){
3111 arr[i]=Integer.parseInt(stt2.nextToken());
3112 i++;
3113 }
3114 _Object el=null;
3115 if(el_msh_type == Canvas3D.MESH_Rod_2){
3116 el = new _Element2((_Node)NDB.get(arr[0]+""),(_Node)NDB.get(arr[1]+""),el_msh_type,(Material)MatDB.get(getValue(st_load,"MATERIAL")),java.lang.Float.parseFloat(getValue(st_load,"D")));
3117 ((_Element2)el).readObject(st_load);
3118 }else if(el_msh_type == Canvas3D.MESH_Contact_Triangle){
3119 Material mat = new Material();
3120 mat.color = Color.gray;
3121 mat.name = "null";
3122 MatDB.put(mat.name,mat);
3123 el = new _Element3((_Node)NDB.get(arr[0]+""),(_Node)NDB.get(arr[1]+""),(_Node)NDB.get(arr[2]+""),el_msh_type,mat,java.lang.Float.parseFloat(getValue(st_load,"T")));
3124 ((_Element3)el).readObject(st_load, LoadDB);
3125 }else if(el_msh_type == Canvas3D.MESH_Contact_Line){
3126 Material mat = new Material();
3127 mat.color = Color.gray;
3128 mat.name = "null";
3129 MatDB.put(mat.name,mat);
3130 el = new _Element2((_Node)NDB.get(arr[0]+""),(_Node)NDB.get(arr[1]+""),el_msh_type,mat,java.lang.Float.parseFloat(getValue(st_load,"D")));
3131 ((_Element2)el).readObject(st_load);
3132 }else if(el_msh_type == Canvas3D.MESH_Beam_2){
3133 el = new _Element2((_Node)NDB.get(arr[0]+""),(_Node)NDB.get(arr[1]+""),el_msh_type,(Material)MatDB.get(getValue(st_load,"MATERIAL")),java.lang.Float.parseFloat(getValue(st_load,"D")));
3134 ((_Element2)el).readObject(st_load);
3135 }else if(el_msh_type == Canvas3D.MESH_Beam_Spring_2){
3136 //---------------------------------
3137 }else if(el_msh_type == Canvas3D.MESH_Shell_BT_4){
3138 el = new _Element4((_Node)NDB.get(arr[0]+""),(_Node)NDB.get(arr[1]+""),(_Node)NDB.get(arr[2]+""),(_Node)NDB.get(arr[3]+""),el_msh_type,(Material)MatDB.get(getValue(st_load,"MATERIAL")),java.lang.Float.parseFloat(getValue(st_load,"T")));
3139 ((_Element4)el).readObject(st_load, LoadDB);
3140 }else if(el_msh_type == Canvas3D.MESH_Solid_Iso_4){
3141 el = new _Element4((_Node)NDB.get(arr[0]+""),(_Node)NDB.get(arr[1]+""),(_Node)NDB.get(arr[2]+""),(_Node)NDB.get(arr[3]+""),el_msh_type,(Material)MatDB.get(getValue(st_load,"MATERIAL")),0);
3142 try{ ((_Element4)el).NIP = new Integer(getValue(st_load,"NIP")); }catch(Exception e1){}
3143 }else if(el_msh_type == Canvas3D.MESH_Shell_C0_3){
3144 el = new _Element3((_Node)NDB.get(arr[0]+""),(_Node)NDB.get(arr[1]+""),(_Node)NDB.get(arr[2]+""),el_msh_type,(Material)MatDB.get(getValue(st_load,"MATERIAL")),java.lang.Float.parseFloat(getValue(st_load,"T")));
3145 ((_Element3)el).readObject(st_load, LoadDB);
3146 }else if(el_msh_type == Canvas3D.MESH_Solid_Iso_6){
3147 el = new _Element8((_Node)NDB.get(arr[0]+""),(_Node)NDB.get(arr[1]+""),(_Node)NDB.get(arr[2]+""),(_Node)NDB.get(arr[3]+""),(_Node)NDB.get(arr[4]+""),(_Node)NDB.get(arr[5]+""),(_Node)NDB.get(arr[6]+""),(_Node)NDB.get(arr[7]+""),(Material)MatDB.get(getValue(st_load,"MATERIAL")));
3148 ((_Element8)el).readObject(st_load);
3149 }
3150
3151 if(el!=null){
3152 el.set_Id(key);
3153 EDB.put(key,el);
3154 }
3155 }
3156 }
3157 }
3158 }
3159
3160 // GEOMETRY
3161
3162 // POINTS
3163 inblock = false;
3164 String geom = new String();
3165 Regex gtype = new Regex("^(?i) *GEOMETRY *OF *TYPE *POINT *$");
3166 Regex token = new Regex("^(?i) *[0-9]+");
3167 _Geometry geo;
3168
3169 gtype.optimize();
3170
3171 stt = new StringTokenizer(file_src,"\n");
3172 while (stt.hasMoreTokens()) {
3173 st = stt.nextToken();
3174
3175 block_one:
3176 if (inblock) {
3177
3178 if (st.startsWith("NODES") || st.startsWith("GEOMETRY") || st.startsWith("GROUPS") || st.startsWith("LOADS") || st.startsWith("ELEMENTS") || st.startsWith("CONTROLS") || st.startsWith("TRACKERS") || st.startsWith("MATERIALS") || st.indexOf("BOUNDARY_CONDITION")!=-1 || st.indexOf("RIGID_BODY")!=-1) {
3179 inblock = false;
3180 break block_one;
3181 }
3182
3183 if (!token.search(st))
3184 continue;
3185
3186 geo = new _Point(false);
3187 ((_Point)geo).readObject(st);
3188 GDB.put(geo.get_Id(), geo);
3189 J3D.add3D(geo);
3190
3191 } // end inblock
3192
3193 if (gtype.search(st)) {
3194 inblock = true;
3195 }
3196 } // End while geometry block
3197
3198
3199
3200 // CURVES
3201 inblock = false;
3202 geom = new String();
3203 gtype = new Regex("^(?i) *GEOMETRY *OF *TYPE *(ARC|SPLINE) *$");
3204
3205 gtype.optimize();
3206
3207 stt = new StringTokenizer(file_src,"\n");
3208 while (stt.hasMoreTokens()) {
3209 st = stt.nextToken();
3210
3211 block_two:
3212 if (inblock) {
3213
3214 if (st.startsWith("NODES") || st.startsWith("GEOMETRY") || st.startsWith("GROUPS") || st.startsWith("LOADS") || st.startsWith("ELEMENTS") || st.startsWith("CONTROLS") || st.startsWith("TRACKERS") || st.startsWith("MATERIALS") || st.indexOf("BOUNDARY_CONDITION")!=-1 || st.indexOf("RIGID_BODY")!=-1) {
3215 inblock = false;
3216 break block_two;
3217 }
3218
3219 if (!token.search(st))
3220 continue;
3221
3222 if (geom.equals("SPLINE")) {
3223 geo = new _Spline(false, J3D);
3224 ((_Spline)geo).readObject(st,GDB);
3225 GDB.put(geo.get_Id(), geo);
3226 J3D.add3D(geo);
3227 }
3228
3229 if (geom.equals("ARC")) {
3230 geo = new _Arc(false, J3D);
3231 ((_Arc)geo).readObject(st,GDB);
3232 GDB.put(geo.get_Id(), geo);
3233 J3D.add3D(geo);
3234 }
3235
3236 } // end inblock
3237
3238 if (gtype.search(st)) {
3239 inblock = true;
3240 geom = gtype.stringMatched(1).toUpperCase();
3241 }
3242 } // End while geometry block
3243
3244
3245 // SURFACES
3246 inblock = false;
3247 geom = new String();
3248 gtype = new Regex("^(?i) *GEOMETRY *OF *TYPE *(SURFBIL|SURFDIR|SURFFILL|SURFREV|SURFRUL) *$");
3249
3250 gtype.optimize();
3251
3252 stt = new StringTokenizer(file_src,"\n");
3253 while (stt.hasMoreTokens()) {
3254 st = stt.nextToken();
3255
3256 block_three:
3257 if (inblock) {
3258
3259 if (st.startsWith("NODES") || st.startsWith("GEOMETRY") || st.startsWith("GROUPS") || st.startsWith("LOADS") || st.startsWith("ELEMENTS") || st.startsWith("CONTROLS") || st.startsWith("TRACKERS") || st.startsWith("MATERIALS") || st.indexOf("BOUNDARY_CONDITION")!=-1 || st.indexOf("RIGID_BODY")!=-1) {
3260 inblock = false;
3261 break block_three;
3262 }
3263
3264 if (!token.search(st))
3265 continue;
3266
3267 if (geom.equals("SURFBIL")) {
3268 geo = new _SurfBil(false, J3D);
3269 ((_SurfBil)geo).readObject(st, GDB);
3270 GDB.put(geo.get_Id(), geo);
3271 J3D.add3D(geo);
3272 }
3273
3274 if (geom.equals("SURFDIR")) {
3275 geo = new _SurfDir(false, J3D);
3276 ((_SurfDir)geo).readObject(st, GDB);
3277 GDB.put(geo.get_Id(), geo);
3278 J3D.add3D(geo);
3279 }
3280
3281 if (geom.equals("SURFFILL")) {
3282 geo = new _SurfFill(false, J3D);
3283 ((_SurfFill)geo).readObject(st, GDB);
3284 GDB.put(geo.get_Id(), geo);
3285 J3D.add3D(geo);
3286 }
3287
3288 if (geom.equals("SURFREV")) {
3289 geo = new _SurfRev(false, J3D);
3290 ((_SurfRev)geo).readObject(st, GDB);
3291 GDB.put(geo.get_Id(), geo);
3292 J3D.add3D(geo);
3293 }
3294
3295 if (geom.equals("SURFRUL")) {
3296 geo = new _SurfRul(false, J3D);
3297 ((_SurfRul)geo).readObject(st, GDB);
3298 GDB.put(geo.get_Id(), geo);
3299 J3D.add3D(geo);
3300 }
3301
3302
3303 } // end inblock
3304
3305 if (gtype.search(st)) {
3306 inblock = true;
3307 geom = gtype.stringMatched(1).toUpperCase();
3308 }
3309 } // End while geometry block
3310
3311
3312 // GROUPS
3313 Regex Group1 = new Regex("^(?i) *([0-9]+) *NAME *= *([a-zA-Z\\/.0-9_]*)");
3314 _Group ng;
3315
3316 // Groups defined in two passes
3317 for (int i=0; i<2 ; i++) {
3318 inblock = false;
3319 stt = new StringTokenizer(file_src,"\n");
3320
3321 while (stt.hasMoreTokens()) {
3322 st = stt.nextToken().trim().toUpperCase();
3323
3324 if(st.startsWith("GROUPS")) inblock = true;
3325 if(st.startsWith("NODES") || st.startsWith("LOADS") || st.startsWith("ELEMENTS") || st.startsWith("CONTROLS") || st.startsWith("TRACKERS") || st.startsWith("MATERIALS") || st.indexOf("BOUNDARY_CONDITION")!=-1 || st.indexOf("RIGID_BODY")!=-1) inblock=false;
3326
3327 if(inblock)
3328 if (Group1.search(st)) {
3329 // Make a new group
3330 if (i==0)
3331 ng = new _GroupUserDefined(false, true);
3332 else
3333 ng = (_Group)GRDB.get(Group1.stringMatched(1)); // Get group defined in first pass
3334
3335 ng.readObject((i==0),st,NDB,EDB,GDB,GRDB);
3336
3337 if (i==0) {
3338 GRDB.put(ng.get_Id(), ng); // Key is Id defined in file
3339 J3D.add3D(ng); // This will set a new Id
3340 }
3341 }
3342 }
3343 }
3344
3345 // Finally, feed the database
3346
3347 Object q;
3348 Iterator it = NDB.keySet().iterator();
3349 while (it.hasNext()) {
3350 J3D.add3D((_Node)NDB.get(q = it.next()));
3351 g_n.addToGroup((_Node)NDB.get(q));
3352 }
3353
3354 it = EDB.keySet().iterator();
3355 while (it.hasNext()) {
3356 J3D.add3D((_Element)EDB.get(q = it.next()));
3357 g_e.addToGroup((_Element)EDB.get(q));
3358 }
3359
3360 it = GDB.keySet().iterator();
3361 while (it.hasNext()) {
3362 g_g.addToGroup((_Geometry)GDB.get(it.next()));
3363 }
3364
3365 }
3366
getValue(String src, String key)3367 private String getValue(String src, String key){
3368 key = " "+key+" ";
3369 if(src.indexOf(key)==-1)return null;
3370 src=src.substring(src.indexOf(key)+key.length());
3371 StringTokenizer stt = new StringTokenizer(src," =\t\n");
3372 return stt.nextToken();
3373 }
3374
3375
3376 }