use of artisynth.core.modelbase.ModelComponent in project artisynth_core by artisynth.
the class Main method computeDraggerToWorld.
protected double computeDraggerToWorld(RigidTransform3d TDW, List<ModelComponent> draggables, Dragger3dBase dragger) {
double radius = 0;
if (dragger != null) {
TDW.set(dragger.getDraggerToWorld());
}
HasCoordinateFrame singleCompWithFrame = null;
if (draggables.size() == 1 && draggables.get(0) instanceof HasCoordinateFrame) {
singleCompWithFrame = (HasCoordinateFrame) draggables.get(0);
}
Point3d pmin = null;
Point3d pmax = null;
if (dragger == null || singleCompWithFrame == null) {
// need to compute bounds if there is no dragger (to determine
// radius), or if there is no single component with a frame (to
// determine the transform).
pmin = new Point3d(inf, inf, inf);
pmax = new Point3d(-inf, -inf, -inf);
for (ModelComponent c : draggables) {
((Renderable) c).updateBounds(pmin, pmax);
}
radius = pmin.distance(pmax);
}
if (singleCompWithFrame != null) {
singleCompWithFrame.getPose(TDW);
if (dragger == null && getInitDraggersInWorldCoords()) {
TDW.R.setIdentity();
}
} else {
TDW.p.add(pmin, pmax);
TDW.p.scale(0.5);
}
return radius;
}
use of artisynth.core.modelbase.ModelComponent 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.modelbase.ModelComponent in project artisynth_core by artisynth.
the class MenuBarHandler method getApplicationMenuItems.
ArrayList<Object> getApplicationMenuItems(RootModel root) {
ArrayList<Object> items = new ArrayList<Object>();
boolean hasItems = false;
hasItems |= addMenuItems(items, root);
for (int i = 0; i < root.numComponents(); i++) {
ModelComponent comp0 = root.get(i);
if (comp0 instanceof HasMenuItems) {
hasItems |= addMenuItems(items, (HasMenuItems) comp0);
}
if (comp0 instanceof CompositeComponent) {
CompositeComponent ccomp = (CompositeComponent) comp0;
for (int j = 0; j < ccomp.numComponents(); j++) {
ModelComponent comp1 = ccomp.get(j);
if (comp1 instanceof HasMenuItems) {
hasItems |= addMenuItems(items, (HasMenuItems) comp1);
}
}
}
}
return hasItems ? items : null;
}
use of artisynth.core.modelbase.ModelComponent in project artisynth_core by artisynth.
the class GenericKeyHandler method setSelectionToSelectionParent.
private void setSelectionToSelectionParent() {
ModelComponent c = mySelectionManager.getLastSelected();
if (c != null && c.getParent() != null) {
mySelectionManager.clearSelections();
mySelectionManager.addSelected(c.getParent());
}
}
use of artisynth.core.modelbase.ModelComponent in project artisynth_core by artisynth.
the class FemModel3d method copy.
@Override
public FemModel3d copy(int flags, Map<ModelComponent, ModelComponent> copyMap) {
if (copyMap == null) {
copyMap = new HashMap<ModelComponent, ModelComponent>();
flags = CopyableComponent.COPY_REFERENCES;
}
FemModel3d fem = (FemModel3d) super.copy(flags, copyMap);
// fem.myFrame was created in super.copy(), but we redo this
// so as to create an exact copy of the orginal frame
FemModelFrame newFrame = myFrame.copy(flags, copyMap);
newFrame.setName(myFrame.getName());
copyMap.put(myFrame, newFrame);
fem.myFrame = newFrame;
if (myFrameConstraint != null) {
fem.attachFrame(myFrame.getPose());
} else {
fem.attachFrame(null);
}
fem.myFrameRelativeP = myFrameRelativeP;
for (FemNode3d n : myNodes) {
FemNode3d newn = n.copy(flags, copyMap);
newn.setName(n.getName());
copyMap.put(n, newn);
fem.myNodes.addNumbered(newn, n.getNumber());
fem.myNodes.setRenderProps(myNodes.getRenderProps());
}
for (FemElement3d e : myElements) {
FemElement3d newe = e.copy(flags, copyMap);
newe.setName(e.getName());
copyMap.put(e, newe);
fem.myElements.addNumbered(newe, e.getNumber());
fem.myElements.setRenderProps(myElements.getRenderProps());
}
for (FemMarker m : myMarkers) {
FemMarker newm = m.copy(flags, copyMap);
newm.setName(m.getName());
fem.myMarkers.addNumbered(newm, m.getNumber());
fem.myMarkers.setRenderProps(myMarkers.getRenderProps());
}
for (DynamicAttachment a : myAttachments) {
DynamicAttachment newa = a.copy(flags, copyMap);
newa.setName(a.getName());
fem.myAttachments.addNumbered(newa, a.getNumber());
}
fem.ansysElemProps = new HashMap<FemElement3d, int[]>();
for (Map.Entry<FemElement3d, int[]> ent : ansysElemProps.entrySet()) {
FemElement3d newe = (FemElement3d) copyMap.get(ent.getKey());
int[] props = ArraySupport.copy(ent.getValue());
fem.ansysElemProps.put(newe, props);
}
for (int i = 0; i < myMeshList.size(); i++) {
FemMeshComp mc = myMeshList.get(i);
FemMeshComp newFmc = mc.copy(flags, copyMap);
if (i == 0) {
fem.myMeshList.addFixed(newFmc);
} else {
fem.addMeshComp(newFmc);
}
// do this this since addMesh sets collidability by default
newFmc.setCollidable(mc.getCollidable());
}
fem.myAutoGenerateSurface = myAutoGenerateSurface;
fem.mySurfaceMeshValid = mySurfaceMeshValid;
fem.myInternalSurfaceMeshComp = null;
fem.setElementWidgetSizeMode(myElementWidgetSizeMode);
if (myElementWidgetSizeMode == PropertyMode.Explicit) {
fem.setElementWidgetSize(myElementWidgetSize);
}
fem.clearCachedData(null);
fem.myAABBTree = null;
fem.myBVTreeValid = false;
fem.mySolveMatrixFile = null;
fem.myNumIncompressConstraints = 0;
fem.myHardIncompUpdateTime = -1;
fem.myComputeNodalStress = myComputeNodalStress;
fem.myComputeNodalStrain = myComputeNodalStrain;
fem.myHardIncompMethod = myHardIncompMethod;
fem.myHardIncompMethodValidP = myHardIncompMethodValidP;
fem.mySoftIncompMethod = mySoftIncompMethod;
fem.mySoftIncompMethodValidP = mySoftIncompMethodValidP;
fem.myNodalIncompBlocksAllocatedP = false;
fem.myNodalIncompConstraintsAllocatedP = false;
fem.myPressures = new VectorNd(MAX_PRESSURE_VALS);
fem.myKp = new double[MAX_PRESSURE_VALS];
fem.myNodalConstraints = new Vector3d[MAX_NODAL_INCOMP_NODES];
for (int i = 0; i < MAX_NODAL_INCOMP_NODES; i++) {
fem.myNodalConstraints[i] = new Vector3d();
}
return fem;
}
Aggregations