use of artisynth.core.workspace.RootModel in project artisynth_core by artisynth.
the class Main method createRootModel.
protected RootModel createRootModel(Class<?> demoClass, String modelName, String[] args) {
// reset in case previous model set this to false:
ModelComponentBase.enforceUniqueNames = true;
if (args == null) {
args = new String[0];
}
try {
RootModel newRoot = null;
Method method = demoClass.getMethod("build", String[].class);
if (demoClass == RootModel.class || method.getDeclaringClass() != RootModel.class) {
// System.out.println (
// "constructing model with build method ...");
Constructor<?> constructor = demoClass.getConstructor();
newRoot = (RootModel) constructor.newInstance();
newRoot.setName(modelName);
newRoot.setMainViewer(myViewer);
newRoot.build(args);
} else {
System.out.println("constructing model with legacy constructor method ...");
Constructor<?> constructor = demoClass.getConstructor(String.class);
newRoot = (RootModel) constructor.newInstance(modelName);
}
return newRoot;
} catch (Exception e) {
myErrMsg = " class " + demoClass.getName() + " cannot be instantiated";
if (e.getMessage() != null) {
myErrMsg += ": \n" + e.getMessage();
}
e.printStackTrace();
return null;
}
}
use of artisynth.core.workspace.RootModel in project artisynth_core by artisynth.
the class Main method setMaxStep.
public void setMaxStep(double sec) {
if (myMaxStep != sec) {
doSetMaxStep(sec);
RootModel root = getRootModel();
if (root != null) {
root.setMaxStepSize(myMaxStep);
}
}
}
use of artisynth.core.workspace.RootModel in project artisynth_core by artisynth.
the class Main method loadModelFile.
public boolean loadModelFile(File file) throws IOException {
// the Jython console.
if (myViewer != null && !SwingUtilities.isEventDispatchThread()) {
LoadModelFileRunner runner = new LoadModelFileRunner(file);
if (!runInSwing(runner)) {
return false;
} else {
return runner.getStatus();
}
}
RootModel newRoot = null;
clearRootModel();
ReaderTokenizer rtok = ArtisynthIO.newReaderTokenizer(file);
if (rtok.nextToken() == ReaderTokenizer.TT_WORD) {
try {
newRoot = (RootModel) ClassAliases.newInstance(rtok.sval, RootModel.class);
myModelFile = file;
} catch (Exception e) {
e.printStackTrace();
}
if (newRoot == null) {
throw new IOException("cannot create instance of " + rtok.sval);
}
} else {
rtok.pushBack();
newRoot = new RootModel();
}
// getWorkspace().getWayPoints().clear();
long t0 = System.nanoTime();
ScanWriteUtils.scanfull(rtok, newRoot, newRoot);
long t1 = System.nanoTime();
System.out.println("File scan time: " + ((t1 - t0) * 1e-9) + " sec");
System.out.println("File size: " + file.length());
// System.out.println ("queue size=" + ModelComponentBase.scanQueueSize());
rtok.close();
String modelName = newRoot.getName();
if (modelName == null) {
// use file name with extension stripped off
modelName = file.getName();
int dotIdx = modelName.indexOf('.');
if (dotIdx != -1) {
modelName = modelName.substring(0, dotIdx);
}
}
setRootModel(newRoot, modelName, null);
return true;
}
use of artisynth.core.workspace.RootModel in project artisynth_core by artisynth.
the class Main method componentChanged.
public void componentChanged(ComponentChangeEvent e) {
if (e.getCode() == ComponentChangeEvent.Code.STRUCTURE_CHANGED || e.getCode() == ComponentChangeEvent.Code.DYNAMIC_ACTIVITY_CHANGED) {
boolean invalidateWaypoints = false;
RootModel root = getRootModel();
ModelComponent c = e.getComponent();
if (myFrame != null && c != null && (c == root || c.getParent() == root)) {
updateApplicationMenuPresent(root);
}
if (root != null) {
invalidateWaypoints = changeAffectsWaypoints(root, e);
if (invalidateWaypoints) {
root.getWayPoints().invalidateAfterTime(0);
}
}
if (myTimeline != null) {
if (root != null && c == root.getWayPoints()) {
myTimeline.requestUpdateWidgets();
} else {
// update timeline display regardless
myTimeline.requestUpdateDisplay();
}
}
if (e.getCode() == ComponentChangeEvent.Code.STRUCTURE_CHANGED) {
if (c != null && c instanceof CompositeComponent && myFrame != null) {
myFrame.getNavPanel().updateStructure(c);
if (root != null && (c == root.getInputProbes() || c == root.getOutputProbes())) {
myTimeline.updateProbes(root);
}
}
if (!getScheduler().isPlaying()) {
rerender();
}
}
// if (invalidateWaypoints) && !myScheduler.isPlaying()) {
if (invalidateWaypoints) {
myScheduler.invalidateInitialState();
}
} else if (e.getCode() == ComponentChangeEvent.Code.NAME_CHANGED) {
ModelComponent c = e.getComponent();
if (myFrame != null) {
if (c.getParent() != null) {
myFrame.getNavPanel().updateStructure(c.getParent());
} else {
myFrame.getNavPanel().updateStructure(c);
}
}
} else if (e.getCode() == ComponentChangeEvent.Code.PROPERTY_CHANGED) {
PropertyChangeEvent pe = (PropertyChangeEvent) e;
ModelComponent c = e.getComponent();
if (c == getRootModel()) {
if (pe.getPropertyName().equals("maxStepSize")) {
doSetMaxStep(getRootModel().getMaxStepSize());
} else if (pe.getPropertyName().equals("defaultViewOrientation")) {
if (myViewerManager != null) {
myViewerManager.resetViewers(getDefaultViewOrientation(getRootModel()));
}
}
} else if (pe.getPropertyName().startsWith("navpanel")) {
if (myFrame != null) {
myFrame.getNavPanel().updateStructure(e.getComponent());
}
}
} else if (e.getCode() == ComponentChangeEvent.Code.GEOMETRY_CHANGED) {
// myTimeline.requestUpdateDisplay();
if (!getScheduler().isPlaying()) {
rerender();
}
}
}
use of artisynth.core.workspace.RootModel in project artisynth_core by artisynth.
the class Main method saveModelFile.
public void saveModelFile(File file, String fmtStr) throws IOException {
RootModel root = getRootModel();
if (root != null) {
IndentingPrintWriter pw = ArtisynthIO.newIndentingPrintWriter(file);
if (!root.getClass().isAssignableFrom(RootModel.class)) {
pw.println(ClassAliases.getAliasOrName(root.getClass()));
}
root.write(pw, new NumberFormat(fmtStr), root);
pw.close();
}
}
Aggregations