Search in sources :

Example 11 with ModelComponent

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

the class InputNumericProbeEditor method setInputProbe.

// //
// // Called when a user adds an input property
// //
// public void addInputProbeProperty (int index, Property prop)
// {
// myProperties.set (index, prop);
// 
// NumericConverter conv = new NumericConverter(prop.get());
// String varname = getUniqueVariableName(INPUT_PREFIX);
// NumericProbeVariable var = new NumericProbeVariable(conv.getDimension());
// myVariables.put (varname, var);
// NumericProbeDriver driver = new NumericProbeDriver();
// driver.setExpression (varname, myVariables);
// myDrivers.set (index, driver);
// 
// AddVectorPane newVec = new AddVectorPane(this, varname);
// newVec.setDim(var.getDimension());
// addVectorGUI(newVec);
// super.updateGUI();
// }
private void setInputProbe() {
    ArrayList<String> variableNames = new ArrayList<String>();
    ArrayList<Integer> variableDims = new ArrayList<Integer>();
    for (Map.Entry<String, NumericProbeVariable> entry : myVariables.entrySet()) {
        variableNames.add(entry.getKey());
        variableDims.add(entry.getValue().getDimension());
        System.out.println(entry.getKey() + " -- " + entry.getValue());
    }
    int[] varDimsInt = new int[variableDims.size()];
    for (int i = 0; i < variableDims.size(); i++) {
        varDimsInt[i] = variableDims.get(i);
    // System.out.println("size of V="+variableDims.get(i));
    }
    NumericInputProbe probeToSet;
    if (oldProbe == null) {
        ModelComponent refComp = ComponentUtils.getPropertyComponent(myProperties.get(0));
        probeToSet = new NumericInputProbe(refComp);
    } else {
        probeToSet = oldProbe;
    }
    probeToSet.set(myProperties.toArray(new Property[0]), getDriverExpressions(), variableNames.toArray(new String[0]), varDimsInt);
    probeToSet.setStartTime(startTimeField.getDoubleValue());
    probeToSet.setStopTime(endTimeField.getDoubleValue());
    probeToSet.setScale(scaleField.getDoubleValue());
    probeToSet.setName(probeNameField.getStringValue());
    String attachedFilePath = attachedFileField.getStringValue();
    if (attachedFilePath != null) {
        if (attachedFilePath.equals("") || !attachedInputFileValid(attachedFilePath, null)) {
            attachedFilePath = null;
        }
    }
    if (attachedFilePath != null) {
        probeToSet.setAttachedFileName(attachedFilePath);
        try {
            probeToSet.load();
            ((Displayable) probeToSet).updateDisplays();
        } catch (IOException e) {
            System.err.println("Couldn't load probe ");
            e.printStackTrace();
            probeToSet.setAttachedFileName(null);
        }
    } else {
        probeToSet.setAttachedFileName(null);
        if (probeToSet.getNumericList().isEmpty()) {
            // add knots at beginning and end
            if (probeToSet.isSettable()) {
                probeToSet.setData(probeToSet.getStartTime());
                probeToSet.setData(probeToSet.getStopTime());
            } else {
                probeToSet.loadEmpty();
            }
        }
    }
    if (oldProbe == null) {
        AddComponentsCommand cmd = new AddComponentsCommand("add input probe", probeToSet, myMain.getRootModel().getInputProbes());
        myMain.getUndoManager().saveStateAndExecute(cmd);
    }
}
Also used : Displayable(artisynth.core.gui.Displayable) NumericProbeVariable(artisynth.core.probes.NumericProbeVariable) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AddComponentsCommand(artisynth.core.gui.editorManager.AddComponentsCommand) ModelComponent(artisynth.core.modelbase.ModelComponent) NumericInputProbe(artisynth.core.probes.NumericInputProbe) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Property(maspack.properties.Property)

Example 12 with ModelComponent

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

the class ControlPanel method updateReferences.

@Override
public void updateReferences(boolean undo, Deque<Object> undoInfo) {
    super.updateReferences(undo, undoInfo);
    boolean changed = false;
    if (undo) {
        Object obj;
        while ((obj = undoInfo.removeFirst()) != NULL_OBJ) {
            WidgetRemoveInfo info = (WidgetRemoveInfo) obj;
            myPanel.addPropertyWidget(info.myProp, info.myComp, info.myIdx);
            changed = true;
        }
    } else {
        // remove soft references which aren't in the hierarchy any more:
        ArrayList<WidgetRemoveInfo> removeList = new ArrayList<WidgetRemoveInfo>();
        for (int i = 0; i < myPanel.numWidgets(); i++) {
            if (myPanel.getWidget(i) instanceof LabeledComponentBase) {
                LabeledComponentBase widget = (LabeledComponentBase) myPanel.getWidget(i);
                Property prop = myPanel.getWidgetProperty(widget);
                if (prop instanceof GenericPropertyHandle) {
                    ModelComponent comp = ComponentUtils.getPropertyComponent(prop);
                    if (comp != null && !ComponentUtils.isConnected(this, comp)) {
                        removeList.add(new WidgetRemoveInfo(prop, widget, i));
                        changed = true;
                    }
                } else {
                // TODO - handle other cases
                }
            }
        }
        for (WidgetRemoveInfo info : removeList) {
            myPanel.removeWidget(info.myComp);
        }
        undoInfo.addAll(removeList);
        undoInfo.addLast(NULL_OBJ);
    }
    if (changed && myFrame != null) {
        myFrame.pack();
    }
}
Also used : ModelComponent(artisynth.core.modelbase.ModelComponent) LabeledComponentBase(maspack.widgets.LabeledComponentBase) GenericPropertyHandle(maspack.properties.GenericPropertyHandle) Property(maspack.properties.Property) EditingProperty(maspack.properties.EditingProperty) Point(java.awt.Point)

Example 13 with ModelComponent

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

the class ExcitationTargetAgent method selectionChanged.

public void selectionChanged(SelectionEvent e) {
    ModelComponent c = e.getLastAddedComponent();
    if (isValidTarget(c)) {
        ExcitationComponent ex = (ExcitationComponent) c;
        if (myState == State.SelectingExciters && ex != myExciter && myExciter.findTarget(ex) == -1) {
            myExciter.addTarget(ex, 1.0);
            DoubleField widget = createTargetWidget(ex, 1.0);
            myTargetPanel.addWidget(widget);
            myTargetPanel.mapWidgetToComponent(widget, ex);
            myTargetPanel.revalidate();
            myTargetPanel.repaint();
        }
    // else if (myExciter.findTarget(ex) != -1)
    // { mySelectedTargets.add (ex);
    // }
    }
}
Also used : ModelComponent(artisynth.core.modelbase.ModelComponent) ExcitationComponent(artisynth.core.mechmodels.ExcitationComponent) DoubleField(maspack.widgets.DoubleField)

Example 14 with ModelComponent

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

the class FemModel3dEditor method addActions.

public void addActions(EditActionMap actions, SelectionManager selManager) {
    LinkedList<ModelComponent> selection = selManager.getCurrentSelection();
    if (containsSingleSelection(selection, FemModel3d.class)) {
        FemModel3d model = (FemModel3d) selection.get(0);
        actions.add(this, "Add FemMarkers ...", EXCLUSIVE);
        actions.add(this, "Rebuild surface mesh");
        actions.add(this, "Add new surface mesh");
        actions.add(this, "Save surface mesh ...");
        actions.add(this, "Save mesh as Ansys file...");
        if (model.getGrandParent() instanceof MechModel) {
            actions.add(this, "Attach particles ...", EXCLUSIVE);
        }
    } else if (containsMultipleCommonParentSelection(selection, HexElement.class)) {
        actions.add(this, "Subdivide elements");
    }
    if (containsMultipleCommonParentSelection(selection, FemElement3d.class)) {
        actions.add(this, "Rebuild surface mesh for selected elements");
        actions.add(this, "Add new surface mesh for selected elements");
    }
}
Also used : HexElement(artisynth.core.femmodels.HexElement) MechModel(artisynth.core.mechmodels.MechModel) FemModel3d(artisynth.core.femmodels.FemModel3d) ModelComponent(artisynth.core.modelbase.ModelComponent)

Example 15 with ModelComponent

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

the class RigidBodyConnectorList method selectionChanged.

@Override
public void selectionChanged(SelectionEvent e) {
    ModelComponent c = e.getLastAddedComponent();
    if (myState == State.SelectingBodyA) {
        if (c instanceof RigidBody) {
            myBodyA = (RigidBody) c;
            setState(State.SelectingBodyB);
        }
    } else if (myState == State.SelectingBodyB) {
        if (c instanceof RigidBody) {
            myBodyB = (RigidBody) c;
            setState(State.SelectingLocation);
        }
    }
}
Also used : ModelComponent(artisynth.core.modelbase.ModelComponent) RigidBody(artisynth.core.mechmodels.RigidBody)

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