Search in sources :

Example 41 with ModelComponent

use of artisynth.core.modelbase.ModelComponent in project artisynth_core by artisynth.

the class MuscleElementDesc method render.

public void render(Renderer renderer, RenderProps props, int flags) {
    double widgetSize = 0;
    double directionLength = 0;
    ModelComponent gparent = getGrandParent();
    DirectionRenderType renderType = DirectionRenderType.ELEMENT;
    if (gparent instanceof MuscleBundle) {
        MuscleBundle bundle = (MuscleBundle) gparent;
        widgetSize = bundle.getElementWidgetSize();
        directionLength = bundle.getDirectionRenderLen();
        renderType = bundle.getDirectionRenderType();
    }
    if (widgetSize != 0) {
        Shading savedShading = renderer.setPropsShading(props);
        if (myWidgetColor != null) {
            renderer.setFaceColoring(props, myWidgetColor, isSelected());
        } else {
            renderer.setFaceColoring(props, isSelected());
        }
        myElement.renderWidget(renderer, widgetSize, props);
        renderer.setShading(savedShading);
    }
    if (directionLength > 0) {
        Matrix3d F = new Matrix3d();
        Vector3d dir = new Vector3d();
        float[] coords0 = new float[3];
        float[] coords1 = new float[3];
        renderDirection(renderer, props, coords0, coords1, F, dir, directionLength, renderType);
    }
}
Also used : SymmetricMatrix3d(maspack.matrix.SymmetricMatrix3d) Matrix3d(maspack.matrix.Matrix3d) ModelComponent(artisynth.core.modelbase.ModelComponent) DirectionRenderType(artisynth.core.femmodels.MuscleBundle.DirectionRenderType) Vector3d(maspack.matrix.Vector3d) Shading(maspack.render.Renderer.Shading)

Example 42 with ModelComponent

use of artisynth.core.modelbase.ModelComponent in project artisynth_core by artisynth.

the class MuscleElementDescList method dorender.

private void dorender(Renderer renderer, int flags, boolean selected) {
    // This code is taken mostly verbatim from FemElement3dList.
    // Should find a way to avoid duplicate code ...
    boolean selecting = renderer.isSelecting();
    double directionLength = 0;
    ModelComponent parent = getParent();
    MuscleBundle.DirectionRenderType renderType = MuscleBundle.DirectionRenderType.ELEMENT;
    if (parent instanceof MuscleBundle) {
        MuscleBundle bundle = (MuscleBundle) parent;
        directionLength = bundle.getDirectionRenderLen();
        renderType = bundle.getDirectionRenderType();
    }
    if (directionLength > 0) {
        renderDirections(renderer, directionLength, renderType, selected);
    }
}
Also used : DirectionRenderType(artisynth.core.femmodels.MuscleBundle.DirectionRenderType) ModelComponent(artisynth.core.modelbase.ModelComponent)

Example 43 with ModelComponent

use of artisynth.core.modelbase.ModelComponent in project artisynth_core by artisynth.

the class PropertyWidgetDialog method valueChange.

public void valueChange(ValueChangeEvent e) {
    if (e.getSource() == myPropField) {
        PropertyInfo info = myPropField.getPropertyInfo();
        ModelComponent comp = myPropField.getModelComponent();
        if (info != null && PropertyWidget.canCreateWithSlider(info)) {
            mySliderSelector.setEnabledAll(true);
            mySliderSelector.setValue(true);
            updateRange(comp, info);
        } else {
            mySliderSelector.setValue(false);
            mySliderSelector.setEnabledAll(false);
        }
        if (info != null && comp != null) {
            myOKButton.setEnabled(true);
            myLabelTextField.setEnabledAll(true);
            myLabelTextField.setValue(info.getName());
        } else {
            myOKButton.setEnabled(false);
            myLabelTextField.setEnabledAll(false);
            myLabelTextField.setValue(null);
        }
    } else if (e.getSource() == mySliderSelector) {
        boolean sliderChoosen = (Boolean) mySliderSelector.getValue();
        myRangeField.setEnabledAll(sliderChoosen);
    }
}
Also used : ModelComponent(artisynth.core.modelbase.ModelComponent) PropertyInfo(maspack.properties.PropertyInfo)

Example 44 with ModelComponent

use of artisynth.core.modelbase.ModelComponent in project artisynth_core by artisynth.

the class PropertyWidgetDialog method createWidget.

public LabeledComponentBase createWidget() {
    if (getModelComponent() == null || getPropertyInfo() == null) {
        throw new IllegalStateException("component and/or property not set");
    }
    LabeledComponentBase widget;
    ModelComponent comp = getModelComponent();
    String propPath = getPropertyPath();
    Property prop = comp.getProperty(propPath);
    if (prop == null) {
        throw new InternalErrorException("property '" + propPath + "' not found for component " + comp.getClass());
    }
    if (CompositeProperty.class.isAssignableFrom(prop.getInfo().getValueClass())) {
        // replace prop with an EditingProperty, since
        // CompositePropertyWidgets only work properly with those
        prop = createEditingProperty(prop);
    }
    if (isSliderSelected()) {
        widget = PropertyWidget.create(prop, getSliderMinimum(), getSliderMaximum());
    } else {
        widget = PropertyWidget.create(prop);
    }
    String labelText = myLabelTextField.getStringValue();
    widget.setLabelText(labelText);
    if (!myLabelFontColorSelector.valueIsNull()) {
        widget.setLabelFontColor(myLabelFontColorSelector.getColor());
    }
    if (!myBackgroundColorSelector.valueIsNull()) {
        widget.setBackgroundColor(myBackgroundColorSelector.getColor());
    }
    return widget;
}
Also used : ModelComponent(artisynth.core.modelbase.ModelComponent) LabeledComponentBase(maspack.widgets.LabeledComponentBase) InternalErrorException(maspack.util.InternalErrorException) CompositeProperty(maspack.properties.CompositeProperty) EditingProperty(maspack.properties.EditingProperty) Property(maspack.properties.Property)

Example 45 with ModelComponent

use of artisynth.core.modelbase.ModelComponent in project artisynth_core by artisynth.

the class SelectableComponentPanel method mapWidgetToComponent.

public void mapWidgetToComponent(JComponent widget, ModelComponent comp) {
    if (getComponentIndex(widget) == -1) {
        throw new IllegalArgumentException("Widget " + widget + " not present in panel");
    }
    if (comp == null) {
        ModelComponent oldComp = myWidgetComponentMap.remove(widget);
        if (oldComp != null) {
            myComponentWidgetMap.remove(oldComp);
        }
    } else {
        myWidgetComponentMap.put(widget, comp);
        myComponentWidgetMap.put(comp, widget);
    }
}
Also used : ModelComponent(artisynth.core.modelbase.ModelComponent)

Aggregations

ModelComponent (artisynth.core.modelbase.ModelComponent)53 RootModel (artisynth.core.workspace.RootModel)9 Property (maspack.properties.Property)8 CompositeComponent (artisynth.core.modelbase.CompositeComponent)5 ArrayList (java.util.ArrayList)5 Point (artisynth.core.mechmodels.Point)4 Renderable (maspack.render.Renderable)4 InternalErrorException (maspack.util.InternalErrorException)4 HasCoordinateFrame (artisynth.core.modelbase.HasCoordinateFrame)3 Traceable (artisynth.core.modelbase.Traceable)3 WayPoint (artisynth.core.probes.WayPoint)3 Point (java.awt.Point)3 LinkedList (java.util.LinkedList)3 CompositeProperty (maspack.properties.CompositeProperty)3 FractionRenderType (artisynth.core.femmodels.AuxMaterialBundle.FractionRenderType)2 FemModel3d (artisynth.core.femmodels.FemModel3d)2 HexElement (artisynth.core.femmodels.HexElement)2 DirectionRenderType (artisynth.core.femmodels.MuscleBundle.DirectionRenderType)2 RemoveComponentsCommand (artisynth.core.gui.editorManager.RemoveComponentsCommand)2 ExcitationComponent (artisynth.core.mechmodels.ExcitationComponent)2