use of cbit.vcell.geometry.ControlPointCurve in project vcell by virtualcell.
the class CurveEditorTool method move.
/**
* Insert the method's description here.
* Creation date: (7/17/2003 5:59:43 PM)
* @param dx double
* @param dy double
*/
private boolean move(double xDelta, double yDelta, CurveSelectionInfo csi, int normalAxis, boolean bAdjustToSlice) {
//
double maxDistance = 0;
ControlPointCurve cpc = (ControlPointCurve) csi.getCurve();
Coordinate[] newCPArr = new Coordinate[cpc.getControlPointCount()];
Coordinate[] oldCPArr = new Coordinate[cpc.getControlPointCount()];
//
for (int i = 0; i < cpc.getControlPointCount(); i += 1) {
//
double xCoord = Coordinate.convertAxisFromStandardXYZToNormal(cpc.getControlPoint(i), Coordinate.X_AXIS, normalAxis);
double yCoord = Coordinate.convertAxisFromStandardXYZToNormal(cpc.getControlPoint(i), Coordinate.Y_AXIS, normalAxis);
double zCoord;
if (bAdjustToSlice) {
zCoord = Coordinate.convertAxisFromStandardXYZToNormal(getWorldCoordinateCalculator().getWorldCoordinateFromUnitized2D(0, 0), Coordinate.Z_AXIS, normalAxis);
} else {
zCoord = Coordinate.convertAxisFromStandardXYZToNormal(cpc.getControlPoint(i), Coordinate.Z_AXIS, normalAxis);
}
//
Coordinate oldCoord = Coordinate.convertCoordinateFromNormalToStandardXYZ(xCoord, yCoord, zCoord, normalAxis);
Coordinate newCoord = Coordinate.convertCoordinateFromNormalToStandardXYZ(xCoord + xDelta, yCoord + yDelta, zCoord, normalAxis);
//
Coordinate snapOldCoord = getWorldCoordinateCalculator().snapWorldCoordinate(oldCoord);
Coordinate snapNewCoord = getWorldCoordinateCalculator().snapWorldCoordinate(newCoord);
double nextDistance = Math.abs(snapOldCoord.distanceTo(snapNewCoord));
if (nextDistance > maxDistance) {
maxDistance = nextDistance;
}
oldCPArr[i] = snapOldCoord;
newCPArr[i] = snapNewCoord;
}
//
// Check if all controlpoints moved the same (some may be at edge)
//
boolean bAllSame = true;
for (int i = 0; i < newCPArr.length; i += 1) {
double nextDistance = Math.abs(oldCPArr[i].distanceTo(newCPArr[i]));
double dDelta = (maxDistance - nextDistance) / maxDistance;
if (dDelta > 1e-8) {
bAllSame = false;
break;
}
}
if (!bAllSame && (csi.getType() == CurveSelectionInfo.TYPE_CURVE)) {
return false;
}
//
for (int i = 0; i < cpc.getControlPointCount(); i += 1) {
if (csi.getType() == CurveSelectionInfo.TYPE_CONTROL_POINT) {
if (csi.getControlPoint() == i) {
cpc.setControlPoint(i, newCPArr[i]);
}
} else if (csi.getType() == CurveSelectionInfo.TYPE_CURVE) {
cpc.setControlPoint(i, newCPArr[i]);
}
}
return true;
}
use of cbit.vcell.geometry.ControlPointCurve in project vcell by virtualcell.
the class CurveEditorTool method mouseDragged.
/**
* This method was created in VisualAge.
* @param event java.awt.event.MouseEvent
*/
public void mouseDragged(MouseEvent event) {
if (!getProperlyConfigured() || !getCurveRenderer().getSelectionValid()) {
return;
}
if (getTool() != TOOL_SELECT) {
// Prevents spurious coordinate changes with other tools
return;
}
CurveSelectionInfo csi = getCurveRenderer().getSelection();
if (csi != null) {
if (csi.getType() == CurveSelectionInfo.TYPE_SEGMENT || csi.getType() == CurveSelectionInfo.TYPE_U) {
// extend the selection
CurveSelectionInfo csiExtended = getCurveRenderer().extend(getWorldCoordinateValue(event.getPoint()));
if (csiExtended != null) {
getCurveRenderer().setSelection(csiExtended);
}
} else {
// move the selection
if (lastSnappedWorldCoord != null) {
// getCurveRenderer().move(event.getPoint().x - lastPoint.x, event.getPoint().y - lastPoint.y);
if (csi.getCurve() instanceof ControlPointCurve && getCurveRenderer().getRenderPropertyEditable(csi.getCurve())) {
Coordinate currentSnappedWorldCoord = getWorldCoordinateCalculator().snapWorldCoordinate(getWorldCoordinateValue(event.getPoint()));
if (!lastSnappedWorldCoord.compareEqual(currentSnappedWorldCoord)) {
double xDelta = Coordinate.convertAxisFromStandardXYZToNormal(currentSnappedWorldCoord, Coordinate.X_AXIS, getCurveRenderer().getNormalAxis()) - Coordinate.convertAxisFromStandardXYZToNormal(lastSnappedWorldCoord, Coordinate.X_AXIS, getCurveRenderer().getNormalAxis());
double yDelta = Coordinate.convertAxisFromStandardXYZToNormal(currentSnappedWorldCoord, Coordinate.Y_AXIS, getCurveRenderer().getNormalAxis()) - Coordinate.convertAxisFromStandardXYZToNormal(lastSnappedWorldCoord, Coordinate.Y_AXIS, getCurveRenderer().getNormalAxis());
if (move(xDelta, yDelta, csi, getCurveRenderer().getNormalAxis(), event.isControlDown())) {
lastSnappedWorldCoord = currentSnappedWorldCoord;
}
}
} else {
lastSnappedWorldCoord = getWorldCoordinateCalculator().snapWorldCoordinate(getWorldCoordinateValue(event.getPoint()));
}
}
}
getVcellDrawable().repaint();
}
}
use of cbit.vcell.geometry.ControlPointCurve in project vcell by virtualcell.
the class CurveTable method decodeCurve.
/**
* Insert the method's description here.
* Creation date: (7/28/00 6:02:38 PM)
* @return java.awt.Shape
* @param pathIterator byte[]
*/
public static cbit.vcell.geometry.Curve decodeCurve(String encodedShape) throws Exception {
cbit.vcell.geometry.Curve rCurve = null;
try {
org.vcell.util.CommentStringTokenizer st = new org.vcell.util.CommentStringTokenizer(encodedShape);
String curveType = st.nextToken();
Class classType = Class.forName(curveType);
Object oCurve = classType.newInstance();
String curveClosed = st.nextToken();
if (oCurve instanceof ControlPointCurve) {
cbit.vcell.geometry.ControlPointCurve cpc = (cbit.vcell.geometry.ControlPointCurve) oCurve;
int cpCount = new Integer(st.nextToken()).intValue();
for (int c = 0; c < cpCount; c += 1) {
double x = new Double(st.nextToken()).doubleValue();
double y = new Double(st.nextToken()).doubleValue();
double z = new Double(st.nextToken()).doubleValue();
cpc.appendControlPoint(new Coordinate(x, y, z));
}
rCurve = cpc;
}
if (rCurve == null) {
throw new RuntimeException("Couldn't decode curve " + curveType);
}
rCurve.setClosed(curveClosed.equals("Closed"));
} catch (Throwable e) {
throw new Exception(e.toString());
}
return rCurve;
}
use of cbit.vcell.geometry.ControlPointCurve in project vcell by virtualcell.
the class CurveEditorTool method mousePressed.
/**
* This method was created in VisualAge.
* @param event MouseEvent
*/
public void mousePressed(MouseEvent event) {
if (!getProperlyConfigured()) {
return;
}
if ((event.getModifiers() & event.BUTTON3_MASK) != 0) {
setTool(TOOL_SELECT);
return;
}
if (getTool() == TOOL_ADDCP) {
if (getCurveRenderer().getSelection() != null && getCurveRenderer().getSelection().getCurve() instanceof ControlPointCurve && ((ControlPointCurve) getCurveRenderer().getSelection().getCurve()).isControlPointAddable()) {
((ControlPointCurve) (getCurveRenderer().getSelection().getCurve())).insertControlPoint(getWorldCoordinateCalculator().snapWorldCoordinate(getWorldCoordinateValue(event.getPoint())), getCurveRenderer().getSelection().getControlPoint());
}
getVcellDrawable().repaint();
} else if (getTool() == TOOL_LINE || getTool() == TOOL_SPLINE || getTool() == TOOL_POINT) {
CurveSelectionInfo selectedCSI = getCurveRenderer().getSelection();
if (selectedCSI == null || getTool() == TOOL_POINT) {
boolean wasFromCVP = false;
if (getCurveValueProvider() != null && getCurveValueProvider().providesInitalCurve(getTool(), getWorldCoordinateValue(event.getPoint()))) {
// Returns null if curve shouldn't be started at this point
selectedCSI = getCurveValueProvider().getInitalCurveSelection(getTool(), getWorldCoordinateValue(event.getPoint()));
wasFromCVP = true;
} else if (getTool() == TOOL_LINE) {
selectedCSI = new CurveSelectionInfo(new PolyLine());
} else if (getTool() == TOOL_SPLINE) {
selectedCSI = new CurveSelectionInfo(new Spline());
} else if (getTool() == TOOL_POINT) {
selectedCSI = new CurveSelectionInfo(new SinglePoint());
}
if (selectedCSI != null) {
if (getCurveValueProvider() != null) {
getCurveValueProvider().setDescription(selectedCSI.getCurve());
}
getCurveRenderer().addCurve(selectedCSI.getCurve());
getCurveRenderer().renderPropertySubSelectionType(selectedCSI.getCurve(), CurveRenderer.SUBSELECTION_CONTROL_POINT);
getCurveRenderer().renderPropertyEditable(selectedCSI.getCurve(), (!wasFromCVP ? true : false));
}
}
//
if (selectedCSI != null && selectedCSI.getCurve() instanceof ControlPointCurve && (getCurveValueProvider() == null || !getCurveValueProvider().providesInitalCurve(getTool(), getWorldCoordinateValue(event.getPoint())) || getCurveValueProvider().isAddControlPointOK(getTool(), getWorldCoordinateValue(event.getPoint()), selectedCSI.getCurve()))) {
if ((!(selectedCSI.getCurve() instanceof CurveSelectionCurve)) && getCurveValueProvider().isAddControlPointOK(getTool(), getWorldCoordinateCalculator().snapWorldCoordinate(getWorldCoordinateValue(event.getPoint())), selectedCSI.getCurve())) {
((ControlPointCurve) (selectedCSI.getCurve())).appendControlPoint(getWorldCoordinateCalculator().snapWorldCoordinate(getWorldCoordinateValue(event.getPoint())));
} else if (getCurveValueProvider().isAddControlPointOK(getTool(), getWorldCoordinateValue(event.getPoint()), selectedCSI.getCurve())) {
try {
if (selectedCSI.getCurve() instanceof CurveSelectionCurve) {
ControlPointCurve targetCurve = (ControlPointCurve) (((CurveSelectionCurve) selectedCSI.getCurve()).getSourceCurveSelectionInfo().getCurve());
double dist = targetCurve.getDistanceTo(getWorldCoordinateValue(event.getPoint()));
int segmentIndex = targetCurve.pickSegment(getWorldCoordinateValue(event.getPoint()), dist * 1.1);
Coordinate[] coordArr = targetCurve.getSampledCurve().getControlPointsForSegment(segmentIndex);
Coordinate middleCoord = new Coordinate((coordArr[0].getX() + coordArr[1].getX()) / 2, (coordArr[0].getY() + coordArr[1].getY()) / 2, (coordArr[0].getZ() + coordArr[1].getZ()) / 2);
((ControlPointCurve) (selectedCSI.getCurve())).appendControlPoint(getWorldCoordinateCalculator().snapWorldCoordinateFace(middleCoord));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
if (selectedCSI != null && !selectedCSI.getCurve().isValid()) {
int subSel = getCurveRenderer().getRenderPropertySubSelectionType(selectedCSI.getCurve());
boolean bEdit = getCurveRenderer().getRenderPropertyEditable(selectedCSI.getCurve());
getCurveRenderer().setSelection(null);
getCurveRenderer().addCurve(selectedCSI.getCurve());
getCurveRenderer().renderPropertyEditable(selectedCSI.getCurve(), bEdit);
getCurveRenderer().renderPropertySubSelectionType(selectedCSI.getCurve(), subSel);
}
getCurveRenderer().setSelection(selectedCSI);
if (getCurveValueProvider() != null && selectedCSI != null && selectedCSI.getCurve().isValid()) {
getCurveValueProvider().curveAdded(selectedCSI.getCurve());
}
getVcellDrawable().repaint();
} else if (getTool() == TOOL_SELECT) {
CurveSelectionInfo invalidCSI = null;
if (getCurveRenderer().getSelection() != null && !getCurveRenderer().getSelection().getCurve().isValid()) {
invalidCSI = getCurveRenderer().getSelection();
}
//
lastSnappedWorldCoord = getWorldCoordinateCalculator().snapWorldCoordinate(getWorldCoordinateValue(event.getPoint()));
CurveSelectionInfo csi = getCurveRenderer().pick(getWorldCoordinateValue(event.getPoint()));
if (csi != null && getCurveRenderer().getRenderPropertySelectable(csi.getCurve())) {
getCurveRenderer().setSelection(csi);
} else {
getCurveRenderer().selectNothing();
}
//
if (getCurveValueProvider() != null) {
if (invalidCSI != null) {
getCurveValueProvider().curveRemoved(invalidCSI.getCurve());
} else {
getCurveValueProvider().curveAdded(null);
}
}
//
getVcellDrawable().repaint();
}
//
}
use of cbit.vcell.geometry.ControlPointCurve in project vcell by virtualcell.
the class CurveEditorTool method step.
/**
* Insert the method's description here.
* Creation date: (10/14/00 3:53:50 PM)
*/
private void step(KeyEvent event) {
if (getCurveRenderer() == null || getCurveRenderer().getSelection() == null || !(getCurveRenderer().getSelection().getCurve() instanceof ControlPointCurve)) {
return;
}
Coordinate wd = getCurveRenderer().getWorldDelta();
double xDelta = Coordinate.convertAxisFromStandardXYZToNormal(wd, Coordinate.X_AXIS, getCurveRenderer().getNormalAxis());
double yDelta = Coordinate.convertAxisFromStandardXYZToNormal(wd, Coordinate.Y_AXIS, getCurveRenderer().getNormalAxis());
int multiplier = event.isShiftDown() ? 10 : 1;
double dx = 0;
double dy = 0;
switch(event.getKeyCode()) {
case KeyEvent.VK_UP:
dy = -multiplier * yDelta;
break;
case KeyEvent.VK_DOWN:
dy = multiplier * yDelta;
break;
case KeyEvent.VK_LEFT:
dx = -multiplier * xDelta;
break;
case KeyEvent.VK_RIGHT:
dx = multiplier * xDelta;
break;
}
ControlPointCurve cpc = (ControlPointCurve) getCurveRenderer().getSelection().getCurve();
move(dx, dy, getCurveRenderer().getSelection(), getCurveRenderer().getNormalAxis(), event.isControlDown());
}
Aggregations