use of maspack.properties.HasProperties in project artisynth_core by artisynth.
the class MeshThicken method actionPerformed.
public void actionPerformed(ActionEvent evt) {
String cmd = evt.getActionCommand();
if (cmd.equals("Load mesh ...")) {
if (myMeshFile != null) {
myMeshChooser.setSelectedFile(myMeshFile);
}
int retVal = myMeshChooser.showOpenDialog(this);
if (retVal == JFileChooser.APPROVE_OPTION) {
File file = myMeshChooser.getSelectedFile();
try {
loadMesh(file, /*vertexSkip=*/
1);
} catch (Exception e) {
showError("Can't load mesh", e);
}
}
} else if (cmd.equals("Save mesh")) {
saveMesh(myMeshFile);
} else if (cmd.equals("Save mesh as ...")) {
if (myMeshFile != null) {
myMeshChooser.setSelectedFile(myMeshFile);
}
int retVal = myMeshChooser.showSaveDialog(this);
if (retVal == JFileChooser.APPROVE_OPTION) {
File file = myMeshChooser.getSelectedFile();
if (!file.exists() || confirmOverwrite(file)) {
try {
saveMesh(file);
} catch (Exception e) {
showError("Can't save mesh", e);
}
}
}
} else if (cmd.equals("Clear regions")) {
clearRegions();
} else if (cmd.equals("Load regions ...")) {
if (myRegionFile != null) {
myRegionChooser.setSelectedFile(myRegionFile);
}
int retVal = myRegionChooser.showOpenDialog(this);
if (retVal == JFileChooser.APPROVE_OPTION) {
File file = myRegionChooser.getSelectedFile();
try {
loadRegions(file);
} catch (Exception e) {
showError("Can't load regions", e);
}
}
} else if (cmd.equals("Save regions")) {
saveRegions(myRegionFile);
} else if (cmd.equals("Save regions as ...")) {
if (myRegionFile != null) {
myRegionChooser.setSelectedFile(myRegionFile);
}
int retVal = myRegionChooser.showSaveDialog(this);
if (retVal == JFileChooser.APPROVE_OPTION) {
File file = myRegionChooser.getSelectedFile();
if (!file.exists() || confirmOverwrite(file)) {
try {
saveRegions(file);
} catch (Exception e) {
showError("Can't save regions", e);
}
}
}
} else if (cmd.equals("Grow")) {
PolygonalMesh pmesh = (PolygonalMesh) myMesh;
applyGrowth(pmesh, myGrowLength);
} else if (cmd.equals("Remesh")) {
PolygonalMesh pmesh = (PolygonalMesh) myMesh;
applyRemesh(pmesh, myRemeshRes);
} else if (cmd.equals("Thicken")) {
for (Region region : myRegions) {
applyThickening(region, myMesh, region.getThickening());
}
} else if (cmd.equals("Unthicken")) {
for (Region region : myRegions) {
applyThickening(region, myMesh, -region.getUnthickening());
}
} else if (cmd.equals("Reverse thicken")) {
for (Region region : myRegions) {
applyThickening(region, myMesh, -region.getThickening());
}
} else if (cmd.equals("Reverse unthicken")) {
for (Region region : myRegions) {
applyThickening(region, myMesh, region.getUnthickening());
}
} else if (cmd.equals("Smooth")) {
PolygonalMesh pmesh = (PolygonalMesh) myMesh;
LaplacianSmoother.smooth(pmesh, mySmoothingCount, mySmoothingLambda, mySmoothingMu);
pmesh.notifyVertexPositionsModified();
viewer.rerender();
} else if (cmd.equals("Hide all regions")) {
for (Region region : myRegions) {
region.setVisible(false);
}
viewer.rerender();
} else if (cmd.equals("Hide regions")) {
for (Region region : getSelectedRegions()) {
region.setVisible(false);
}
viewer.rerender();
} else if (cmd.equals("Show all regions")) {
for (Region region : myRegions) {
region.setVisible(true);
}
viewer.rerender();
} else if (cmd.equals("Edit MeshThicken properties ...")) {
ArrayList<HasProperties> list = new ArrayList<HasProperties>();
list.add(this);
PropertyDialog dialog = PropertyDialog.createDialog("MeshThicken properties", list, "OK Cancel", viewer.getCanvas().getComponent(), myRerenderListener);
if (dialog != null) {
dialog.setVisible(true);
}
} else if (cmd.equals("Edit region properties ...")) {
PropertyDialog dialog = PropertyDialog.createDialog("Region properties", getSelectedRegions(), "OK Cancel", viewer.getCanvas().getComponent(), myRerenderListener);
if (dialog != null) {
dialog.setVisible(true);
}
} else if (cmd.equals("Edit mesh render properties ...")) {
PropertyDialog dialog = new PropertyDialog("Edit render props", new RenderPropsPanel(PropertyUtils.createProperties(myMesh.getRenderProps())), "Done");
dialog.locateRight(this);
dialog.addGlobalValueChangeListener(myRerenderListener);
dialog.setVisible(true);
} else if (cmd.equals("Quit")) {
System.exit(0);
} else {
super.actionPerformed(evt);
}
}
use of maspack.properties.HasProperties in project artisynth_core by artisynth.
the class AddComponentAgent method setComponentType.
/**
* Called whenever the specific class type of the components being added by
* this agent is changed.
*/
public void setComponentType(Class type) {
if (type == myComponentType) {
return;
}
myComponentType = type;
if (myPrototype != null) {
setProperties(myPrototype, myPrototype);
}
myPrototype = getPrototypeComponent(type);
if (myPrototype != null) {
myHostList = new HostList(new HasProperties[] { myPrototype });
myPropTree = myHostList.commonProperties(null, false);
// remove properties which are to be excluded
String[] excludedPropNames = getExcludedPropNames(type);
for (int i = 0; i < excludedPropNames.length; i++) {
myPropTree.removeDescendant(excludedPropNames[i]);
}
myHostList.saveBackupValues(myPropTree);
myHostList.getCommonValues(myPropTree, /* live= */
true);
if (myPropertyPanelIdx != -1) {
myDefaultProps = EditingProperty.createProperties(myPropTree, myHostList, /* isLive= */
true);
LinkedList<Property> basicProps = getBasicProps(type, myDefaultProps);
if (basicProps.size() > 0) {
LinkedList<Property> extraProps = new LinkedList<Property>();
extraProps.addAll(myDefaultProps);
extraProps.removeAll(basicProps);
myPropertyPanel = new ExpandablePropertyPanel(basicProps, extraProps);
} else {
myPropertyPanel = new PropertyPanel(myDefaultProps);
}
if (myPropertyPanelBorderTitle != null) {
String title = myPropertyPanelBorderTitle;
if (title.indexOf("TYPE") != -1) {
title = title.replaceAll("TYPE", (String) myTypeSelector.getValue());
}
myPropertyPanel.setBorder(GuiUtils.createTitledPanelBorder(title));
}
resetDefaultProperties();
myPropertyPanel.updateWidgetValues(/* updateFromSource= */
false);
myPropertyPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
myContentPane.removeWidget(myPropertyPanelIdx);
myContentPane.addWidget(myPropertyPanel, myPropertyPanelIdx);
myContentPane.validate();
// myContentPane.resetLabelAlignment();
if (myDisplay.isVisible()) {
myDisplay.pack();
}
}
}
}
use of maspack.properties.HasProperties in project artisynth_core by artisynth.
the class ComponentPropertyField method setValueFromPropertySelector.
private void setValueFromPropertySelector() {
if (!myPropertyMask) {
String propName = (String) myPropertySelector.getValue();
HasProperties host = getHost();
if (propName.equals(nullString)) {
Object value = getValueForHost();
System.out.println("new value");
updateValueAndDisplay(value);
return;
}
if (host == null) {
throw new InternalErrorException("Current property host is null");
}
Property prop = host.getProperty(propName);
if (prop == null) {
throw new InternalErrorException("Current property host does not contain property " + propName);
}
updateValueAndDisplay(prop);
}
}
Aggregations