Search in sources :

Example 11 with HasProperties

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);
    }
}
Also used : PropertyDialog(maspack.widgets.PropertyDialog) RenderPropsPanel(maspack.widgets.RenderPropsPanel) ArrayList(java.util.ArrayList) HasProperties(maspack.properties.HasProperties) File(java.io.File) PolygonalMesh(maspack.geometry.PolygonalMesh) IOException(java.io.IOException)

Example 12 with HasProperties

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();
            }
        }
    }
}
Also used : HasProperties(maspack.properties.HasProperties) ExpandablePropertyPanel(maspack.widgets.ExpandablePropertyPanel) HostList(maspack.properties.HostList) EditingProperty(maspack.properties.EditingProperty) Property(maspack.properties.Property) LinkedList(java.util.LinkedList) ExpandablePropertyPanel(maspack.widgets.ExpandablePropertyPanel) PropertyPanel(maspack.widgets.PropertyPanel)

Example 13 with HasProperties

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);
    }
}
Also used : HasProperties(maspack.properties.HasProperties) InternalErrorException(maspack.util.InternalErrorException) CompositeProperty(maspack.properties.CompositeProperty) Property(maspack.properties.Property)

Aggregations

HasProperties (maspack.properties.HasProperties)13 LinkedList (java.util.LinkedList)4 HostList (maspack.properties.HostList)4 Property (maspack.properties.Property)4 PropertyInfo (maspack.properties.PropertyInfo)4 InternalErrorException (maspack.util.InternalErrorException)3 ModelComponent (artisynth.core.modelbase.ModelComponent)2 ArrayList (java.util.ArrayList)2 CompositeProperty (maspack.properties.CompositeProperty)2 PropertyDialog (maspack.widgets.PropertyDialog)2 RenderableComponent (artisynth.core.modelbase.RenderableComponent)1 Traceable (artisynth.core.modelbase.Traceable)1 IsRenderableHolder (artisynth.core.renderables.IsRenderableHolder)1 PullController (artisynth.core.workspace.PullController)1 Point (java.awt.Point)1 Window (java.awt.Window)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 File (java.io.File)1 IOException (java.io.IOException)1