use of artisynth.core.driver.Main in project artisynth_core by artisynth.
the class ControlPanel method actionPerformed.
public void actionPerformed(ActionEvent e) {
String actionCmd = e.getActionCommand();
if (actionCmd.equals("add widget")) {
myPanel.actionPerformed(e);
} else if (actionCmd.equals("set name")) {
WidgetDialog dialog = WidgetDialog.createDialog(myFrame, "set name", "Set");
StringField widget = new StringField("name:", getName(), 20);
widget.addValueCheckListener(new ValueCheckListener() {
public Object validateValue(ValueChangeEvent e, StringHolder errMsg) {
String name = (String) e.getValue();
if (name != null && name.length() == 0) {
return null;
}
errMsg.value = ModelComponentBase.checkName(name, null);
if (errMsg.value != null) {
return Property.IllegalValue;
} else {
return name;
}
}
});
dialog.addWidget(widget);
GuiUtils.locateVertically(dialog, myFrame, GuiUtils.BELOW);
GuiUtils.locateHorizontally(dialog, myFrame, GuiUtils.CENTER);
dialog.setVisible(true);
if (dialog.getReturnValue() == OptionPanel.OK_OPTION) {
String name = (String) widget.getValue();
setName(name);
}
} else if (actionCmd.equals("save as ...")) {
Main main = Main.getMain();
RootModel root = main.getRootModel();
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(main.getModelDirectory());
int retVal = chooser.showSaveDialog(myFrame);
if (retVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
try {
ComponentUtils.saveComponent(file, this, new NumberFormat("%.6g"), root);
} catch (Exception ex) {
JOptionPane.showMessageDialog(myFrame, "Error saving file: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
main.setModelDirectory(chooser.getCurrentDirectory());
}
} else if (actionCmd.equals("merge panel")) {
Main main = Main.getMain();
main.getRootModel().mergeControlPanel(true, this);
} else if (actionCmd.equals("separate panel")) {
Main main = Main.getMain();
main.getRootModel().mergeControlPanel(false, this);
} else {
throw new InternalErrorException("Unknown action: " + actionCmd);
}
}
use of artisynth.core.driver.Main in project artisynth_core by artisynth.
the class EditorUtils method saveComponent.
public static void saveComponent(ModelComponent comp) {
Main main = Main.getMain();
JFrame frame = main.getMainFrame();
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(main.getModelDirectory());
int retVal = chooser.showSaveDialog(frame);
if (retVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
try {
ModelComponent ancestor = ComponentUtils.nearestEncapsulatingAncestor(comp);
if (ancestor == null) {
ancestor = comp;
}
ComponentUtils.saveComponent(file, comp, new NumberFormat("%.8g"), ancestor);
} catch (Exception ex) {
ex.printStackTrace();
showError(frame, "Error saving file: " + ex.getMessage());
}
main.setModelDirectory(chooser.getCurrentDirectory());
}
}
use of artisynth.core.driver.Main in project artisynth_core by artisynth.
the class InverseManager method isInversePanelVisible.
public static boolean isInversePanelVisible() {
Main main = Main.getMain();
ControlPanel inversePanel = main.getInverseManager().inverseControlPanel;
return (inversePanel != null);
}
use of artisynth.core.driver.Main in project artisynth_core by artisynth.
the class EditorUtils method saveMesh.
public static void saveMesh(MeshBase mesh, AffineTransform3dBase X) {
Main main = Main.getMain();
JFrame frame = main.getMainFrame();
if (mesh == null) {
showError(frame, "Component does not have a mesh");
return;
}
if (X != null) {
mesh = mesh.copy();
mesh.transform(X);
}
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(main.getModelDirectory());
int retVal = chooser.showSaveDialog(frame);
if (retVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
try {
if (mesh instanceof PolygonalMesh) {
GenericMeshWriter writer = new GenericMeshWriter(file);
writer.writeMesh(mesh);
writer.close();
} else {
PrintWriter pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream(file)));
mesh.write(pw, "%.8g");
pw.close();
}
} catch (Exception ex) {
ex.printStackTrace();
showError(frame, "Error saving file: " + ex.getMessage());
}
main.setModelDirectory(chooser.getCurrentDirectory());
}
}
use of artisynth.core.driver.Main in project artisynth_core by artisynth.
the class EditorUtils method saveMeshAsAnsysFile.
public static void saveMeshAsAnsysFile(final FemModel3d model) {
final Main main = Main.getMain();
JFrame frame = main.getMainFrame();
final JDialog saveOptions = new JDialog(frame, "Save As Ansys File");
LabeledComponentPanel savePanel = new LabeledComponentPanel();
savePanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 8));
final StringField dirField = new StringField("Output folder", main.getModelDirectory().getAbsolutePath(), 20);
dirField.setStretchable(true);
dirField.getTextField().setEditable(false);
final JButton browseButton = new JButton("Change");
browseButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent a_evt) {
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(main.getModelDirectory());
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if (chooser.showSaveDialog(browseButton) == JFileChooser.APPROVE_OPTION) {
dirField.setValue(chooser.getSelectedFile().getAbsolutePath());
}
}
});
browseButton.setMargin(new Insets(3, 3, 3, 3));
GuiUtils.setFixedSize(browseButton, new Dimension(80, 25));
dirField.add(browseButton);
savePanel.addWidget(dirField);
final StringField nodeField = new StringField("Node file name", "mesh.node", 10);
nodeField.setStretchable(true);
savePanel.addWidget(nodeField);
final StringField elemField = new StringField("Element file name", "mesh.elem", 10);
elemField.setStretchable(true);
savePanel.addWidget(elemField);
final JCheckBox elemType = new JCheckBox("Use custom type values for different elements");
savePanel.addWidget(elemType);
LabeledComponentPanel elemTypePanel = new LabeledComponentPanel();
elemTypePanel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0));
final IntegerField tetField = new IntegerField("Tets (4 node)", 1);
tetField.getTextField().setEditable(false);
elemTypePanel.addWidget(tetField);
final IntegerField quadtetField = new IntegerField("Quadtets (10 node)", 1);
quadtetField.getTextField().setEditable(false);
elemTypePanel.addWidget(quadtetField);
final IntegerField wedgeField = new IntegerField("Wedges", 1);
wedgeField.getTextField().setEditable(false);
elemTypePanel.addWidget(wedgeField);
final IntegerField hexField = new IntegerField("Hexs (8 node)", 1);
hexField.getTextField().setEditable(false);
elemTypePanel.addWidget(hexField);
final IntegerField quadhexField = new IntegerField("Quadhexs (20 node)", 1);
quadhexField.getTextField().setEditable(false);
elemTypePanel.addWidget(quadhexField);
savePanel.addWidget(elemTypePanel);
elemType.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent a_evt) {
if (elemType.isSelected()) {
tetField.getTextField().setEditable(true);
quadtetField.getTextField().setEditable(true);
wedgeField.getTextField().setEditable(true);
hexField.getTextField().setEditable(true);
quadhexField.getTextField().setEditable(true);
} else {
tetField.getTextField().setEditable(false);
quadtetField.getTextField().setEditable(false);
wedgeField.getTextField().setEditable(false);
hexField.getTextField().setEditable(false);
quadhexField.getTextField().setEditable(false);
}
}
});
OptionPanel dialogOptions = new OptionPanel("Save Cancel", new ActionListener() {
public void actionPerformed(ActionEvent a_evt) {
if (a_evt.getActionCommand().equals("Save")) {
File directory = new File(dirField.getStringValue());
File nodeFile = new File(directory, nodeField.getStringValue());
File elemFile = new File(directory, elemField.getStringValue());
AnsysWriter.writeNodeFile(model, nodeFile.getAbsolutePath());
AnsysWriter.writeElemFile(model, elemFile.getAbsolutePath());
}
saveOptions.dispose();
}
});
GuiUtils.setFixedSize(dialogOptions.getButton("Save"), new Dimension(80, 25));
GuiUtils.setFixedSize(dialogOptions.getButton("Cancel"), new Dimension(80, 25));
dialogOptions.setBorder(BorderFactory.createEmptyBorder(0, 0, 8, 0));
savePanel.addWidget(dialogOptions);
saveOptions.getContentPane().add(savePanel);
saveOptions.pack();
saveOptions.setMinimumSize(saveOptions.getPreferredSize());
saveOptions.setVisible(true);
}
Aggregations