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);
}
}
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();
}
}
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);
// }
}
}
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");
}
}
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);
}
}
}
Aggregations