package bs.bs2d.gui.views;
import bs.bs2d.fea.TriMesh2D;
import bs.bs2d.gui.BSConstants;
import bs.bs2d.gui.BusyStateListener;
import bs.bs2d.gui.MainGUI;
import bs.bs2d.gui.plot.MeshPlotter;
import bs.bs2d.gui.plot.PlotPanel;
import bs.bs2d.io.MeshReader;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComponent;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
/**
*
* @author Djen
*/
public class LoadcaseView implements BSGUIView{
private static final String NAME = "Loadcase";
// gui
private final PlotPanel content;
private final LoadcaseViewControls controls;
private final JMenu[] menus;
private JCheckBoxMenuItem chkSolid;
private JCheckBoxMenuItem chkWire;
private JCheckBoxMenuItem chkNodes;
private JCheckBoxMenuItem chkEdges;
// data
private TriMesh2D mesh;
private MeshPlotter meshPlotter;
public LoadcaseView(){
content = new PlotPanel();
controls = new LoadcaseViewControls();
menus = buildMenus();
}
private JMenu[] buildMenus(){
JMenu[] ms = new JMenu[1];
JMenu m = new JMenu("View");
chkSolid = new JCheckBoxMenuItem("Solid Elements");
chkSolid.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
meshPlotter.setShowSolidElements(chkSolid.isSelected());
}
});
chkSolid.setSelected(true);
m.add(chkSolid);
chkWire = new JCheckBoxMenuItem("Wireframe");
chkWire.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
meshPlotter.setShowWireframe(chkWire.isSelected());
}
});
chkWire.setSelected(false);
m.add(chkWire);
m.addSeparator();
chkNodes = new JCheckBoxMenuItem("Show Nodes");
chkNodes.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
meshPlotter.setShowNodes(chkNodes.isSelected());
}
});
chkNodes.setSelected(true);
m.add(chkNodes);
chkEdges = new JCheckBoxMenuItem("Edge Nodes Only");
chkEdges.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
meshPlotter.setShowEdgeNodesOnly(chkEdges.isSelected());
}
});
chkEdges.setSelected(true);
m.add(chkEdges);
m.addSeparator();
JMenuItem mitResetView = new JMenuItem("Reset View");
mitResetView.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
content.resetView();
}
});
m.add(mitResetView);
ms[0] = m;
return ms;
}
@Override
public JComponent getContent() {
return content;
}
@Override
public JComponent getControls() {
return controls;
}
@Override
public JMenu[] getMenus() {
return menus;
}
@Override
public void init(Object data) {
if(data instanceof TriMesh2D){
mesh = (TriMesh2D) data;
meshPlotter = new MeshPlotter(mesh);
applyViewSettings();
content.setPlotObject(meshPlotter, true);
controls.init(meshPlotter);
} else if(MainGUI.DEBUG_LOADCASE) {
try {
mesh = MeshReader.readMesh(BSConstants.getTempFile("msh"));
meshPlotter = new MeshPlotter(mesh);
applyViewSettings();
content.setPlotObject(meshPlotter, true);
controls.init(meshPlotter);
} catch (Exception ex) {
System.err.println(ex);
}
} else if(data == null) {
mesh = null;
meshPlotter = null;
content.setPlotObject(null, true);
} else {
throw new IllegalArgumentException("Invalid Input data! "
+ "Input must be a mesh!");
}
}
private void applyViewSettings(){
meshPlotter.setShowSolidElements(chkSolid.isSelected());
meshPlotter.setShowWireframe(chkWire.isSelected());
meshPlotter.setShowNodes(chkNodes.isSelected());
meshPlotter.setShowEdgeNodesOnly(chkEdges.isSelected());
}
@Override
public Object getData() {
return new Object[]{mesh, controls.getBoundaryConditions()};
}
@Override
public String getName() {
return NAME;
}
@Override
public void setBusyStateListener(BusyStateListener bsl) {
// is not used
}
}