Search in sources :

Example 1 with ModelComponent

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;
}
Also used : HasCoordinateFrame(artisynth.core.modelbase.HasCoordinateFrame) Renderable(maspack.render.Renderable) ModelComponent(artisynth.core.modelbase.ModelComponent) Point3d(maspack.matrix.Point3d)

Example 2 with ModelComponent

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();
        }
    }
}
Also used : PropertyChangeEvent(artisynth.core.modelbase.PropertyChangeEvent) RootModel(artisynth.core.workspace.RootModel) ModelComponent(artisynth.core.modelbase.ModelComponent) CompositeComponent(artisynth.core.modelbase.CompositeComponent)

Example 3 with ModelComponent

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;
}
Also used : HasMenuItems(artisynth.core.modelbase.HasMenuItems) ModelComponent(artisynth.core.modelbase.ModelComponent) ArrayList(java.util.ArrayList) CompositeComponent(artisynth.core.modelbase.CompositeComponent)

Example 4 with ModelComponent

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());
    }
}
Also used : ModelComponent(artisynth.core.modelbase.ModelComponent)

Example 5 with ModelComponent

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;
}
Also used : DynamicAttachment(artisynth.core.mechmodels.DynamicAttachment) Point(artisynth.core.mechmodels.Point) ModelComponent(artisynth.core.modelbase.ModelComponent) Vector3d(maspack.matrix.Vector3d) VectorNd(maspack.matrix.VectorNd) Map(java.util.Map) HueColorMap(maspack.render.color.HueColorMap) HashMap(java.util.HashMap)

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