From: Tuukka Lehtonen Date: Tue, 7 Feb 2017 14:11:00 +0000 (+0200) Subject: Remove all dependencies on javax.vecmath. X-Git-Tag: v1.28.0~71 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F31%2F331%2F5;p=simantics%2Fplatform.git Remove all dependencies on javax.vecmath. Apache Commons Math3 library can be used to replace the functionality. The only downside is that Math3 is over 10 times larger than the old vecmath library (180kB vs. >2MB). Also removed javax.vecmath entirely from platform external dependencies. refs #7023 Change-Id: I4b9a3cf25567552b0cc1f35e07615baeaa982269 --- diff --git a/bundles/org.simantics.diagram/META-INF/MANIFEST.MF b/bundles/org.simantics.diagram/META-INF/MANIFEST.MF index 1ff8d39e0..758aa4869 100644 --- a/bundles/org.simantics.diagram/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.diagram/META-INF/MANIFEST.MF @@ -13,7 +13,7 @@ Require-Bundle: org.simantics.utils.thread.swt, org.simantics.db.layer0;bundle-version="[1.0.0,2.0.0)", org.simantics.structural2;bundle-version="1.0.0", org.simantics.basicexpression;bundle-version="1.0.0", - javax.vecmath;bundle-version="1.0.0", + org.apache.commons.math3;bundle-version="3.6.1", org.simantics.layer0;bundle-version="1.0.0", org.simantics.diagram.ontology;bundle-version="1.0.0";visibility:=reexport, org.simantics.structural.ontology;bundle-version="1.0.0", diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/MonitorClass.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/MonitorClass.java index 339f180e8..c62422d4a 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/MonitorClass.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/MonitorClass.java @@ -25,8 +25,7 @@ import java.awt.geom.Rectangle2D; import java.util.EnumSet; import java.util.Map; -import javax.vecmath.Vector2d; - +import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; import org.simantics.db.layer0.variable.RVI; import org.simantics.g2d.diagram.IDiagram; import org.simantics.g2d.element.ElementClass; @@ -680,11 +679,9 @@ public class MonitorClass { return Double.NaN; double angrad = Math.toRadians(angle); - Vector2d forcedAxis = new Vector2d(Math.cos(angrad), Math.sin(angrad)); - Vector2d x = new Vector2d(tr.getScaleX(), tr.getShearX()); - forcedAxis.normalize(); - x.normalize(); - double cosa = forcedAxis.dot(x); + Vector2D forcedAxis = new Vector2D(Math.cos(angrad), Math.sin(angrad)); + Vector2D x = new Vector2D(tr.getScaleX(), tr.getShearX()).normalize(); + double cosa = forcedAxis.dotProduct(x); double delta = Math.acos(cosa); return delta; } diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/flag/RouteGraphConnectionSplitter.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/flag/RouteGraphConnectionSplitter.java index 759efbe56..3f1076b5d 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/flag/RouteGraphConnectionSplitter.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/flag/RouteGraphConnectionSplitter.java @@ -7,9 +7,6 @@ import java.awt.geom.Point2D; import java.util.ArrayList; import java.util.Collection; -import javax.vecmath.Tuple2d; -import javax.vecmath.Vector2d; - import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; @@ -247,18 +244,18 @@ public class RouteGraphConnectionSplitter { String commonLabel = scheme.generateLabel(graph, diagram); // Create flags and connect both disconnected ends to them. - Vector2d pos1, pos2; + Point2D pos1, pos2; double theta; double flagDist = 3.0; if(isHorizontal) { theta = 0.0; - pos1 = new Vector2d(isectX-flagDist, isectY); - pos2 = new Vector2d(isectX+flagDist, isectY); + pos1 = new Point2D.Double(isectX-flagDist, isectY); + pos2 = new Point2D.Double(isectX+flagDist, isectY); } else { theta = Math.PI*0.5; - pos1 = new Vector2d(isectX, isectY-flagDist); - pos2 = new Vector2d(isectX, isectY+flagDist); + pos1 = new Point2D.Double(isectX, isectY-flagDist); + pos2 = new Point2D.Double(isectX, isectY+flagDist); } // Chooses flag directions @@ -398,8 +395,8 @@ public class RouteGraphConnectionSplitter { } } - private AffineTransform getFlagTransform(Tuple2d pos, double theta) { - AffineTransform at = AffineTransform.getTranslateInstance(pos.x, pos.y); + private AffineTransform getFlagTransform(Point2D pos, double theta) { + AffineTransform at = AffineTransform.getTranslateInstance(pos.getX(), pos.getY()); at.rotate(theta); return at; } diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/flag/Splitter.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/flag/Splitter.java index 57c1a64e3..a5220f99c 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/flag/Splitter.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/flag/Splitter.java @@ -8,9 +8,7 @@ import java.util.Deque; import java.util.HashSet; import java.util.Set; -import javax.vecmath.Tuple2d; -import javax.vecmath.Vector2d; - +import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; @@ -129,26 +127,19 @@ public class Splitter { // Calculate split position and edge line nearest intersection point // ab = normalize( vec(a -> b) ) // ap = vec(a -> split pos) - Vector2d ab = new Vector2d(nearestEdge.getX2() - nearestEdge.getX1(), nearestEdge.getY2() - nearestEdge.getY1()); - Vector2d ap = new Vector2d(splitCanvasPos.getX() - nearestEdge.getX1(), splitCanvasPos.getY() - nearestEdge.getY1()); - double theta = Math.atan2(ab.y, ab.x); - ab.normalize(); + Vector2D a = new Vector2D(nearestEdge.getX1(), nearestEdge.getY1()); + Vector2D ab = new Vector2D(nearestEdge.getX2() - nearestEdge.getX1(), nearestEdge.getY2() - nearestEdge.getY1()); + Vector2D ap = new Vector2D(splitCanvasPos.getX() - nearestEdge.getX1(), splitCanvasPos.getY() - nearestEdge.getY1()); + double theta = Math.atan2(ab.getY(), ab.getX()); + ab = ab.normalize(); // intersection = a + ab*(ap.ab) - Vector2d intersection = new Vector2d(ab); - intersection.scale(ap.dot(ab)); - intersection.add(new Vector2d(nearestEdge.getX1(), nearestEdge.getY1())); + Vector2D intersection = a.add( ab.scalarMultiply(ap.dotProduct(ab)) ); // Offset flag positions from the intersection point. - Vector2d pos1 = new Vector2d(intersection); - Vector2d pos2 = new Vector2d(intersection); - // TODO: improve logic for flag positioning, flags just move on the nearest line without boundaries - ab.normalize(); - ab.scale(5); - pos2.add(ab); - ab.negate(); - pos1.add(ab); + Vector2D pos1 = intersection.subtract(5, ab); + Vector2D pos2 = intersection.add(5, ab); FlagLabelingScheme scheme = DiagramFlagPreferences.getActiveFlagLabelingScheme(graph); String commonLabel = scheme.generateLabel(graph, diagram); @@ -168,8 +159,8 @@ public class Splitter { FlagUtil.join(graph, flag1, flag2); } - private AffineTransform getFlagTransform(Tuple2d pos, double theta) { - AffineTransform at = AffineTransform.getTranslateInstance(pos.x, pos.y); + private AffineTransform getFlagTransform(Vector2D pos, double theta) { + AffineTransform at = AffineTransform.getTranslateInstance(pos.getX(), pos.getY()); at.rotate(theta); return at; } diff --git a/bundles/org.simantics.g2d/META-INF/MANIFEST.MF b/bundles/org.simantics.g2d/META-INF/MANIFEST.MF index 20eb07a6b..f5ed551cc 100644 --- a/bundles/org.simantics.g2d/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.g2d/META-INF/MANIFEST.MF @@ -11,8 +11,8 @@ Require-Bundle: org.eclipse.core.runtime, org.simantics.utils.thread, org.simantics.utils.thread.swt, org.simantics.utils.ui;bundle-version="1.0.0", - javax.vecmath;bundle-version="1.0.0", org.apache.commons.collections;bundle-version="3.2.1", + org.apache.commons.math3, gnu.trove3;bundle-version="3.0.0", org.simantics.scenegraph;bundle-version="1.1.1";visibility:=reexport, org.simantics.threadlog;bundle-version="1.0.0";resolution:=optional, diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/MonitorClass.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/MonitorClass.java deleted file mode 100644 index 1f21ee86d..000000000 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/MonitorClass.java +++ /dev/null @@ -1,689 +0,0 @@ -///******************************************************************************* -// * Copyright (c) 2007, 2010 Association for Decentralized Information Management -// * in Industry THTH ry. -// * All rights reserved. This program and the accompanying materials -// * are made available under the terms of the Eclipse Public License v1.0 -// * which accompanies this distribution, and is available at -// * http://www.eclipse.org/legal/epl-v10.html -// * -// * Contributors: -// * VTT Technical Research Centre of Finland - initial API and implementation -// *******************************************************************************/ -//package org.simantics.g2d.elementclass; -// -//import java.awt.BasicStroke; -//import java.awt.Color; -//import java.awt.Font; -//import java.awt.FontMetrics; -//import java.awt.Graphics2D; -//import java.awt.Rectangle; -//import java.awt.Shape; -//import java.awt.event.ActionEvent; -//import java.awt.event.ActionListener; -//import java.awt.geom.AffineTransform; -//import java.awt.geom.Path2D; -//import java.awt.geom.Point2D; -//import java.awt.geom.Rectangle2D; -//import java.util.EnumSet; -//import java.util.Map; -// -//import javax.vecmath.Vector2d; -// -//import org.simantics.g2d.diagram.IDiagram; -//import org.simantics.g2d.element.ElementClass; -//import org.simantics.g2d.element.ElementHints; -//import org.simantics.g2d.element.ElementUtils; -//import org.simantics.g2d.element.IElement; -//import org.simantics.g2d.element.SceneGraphNodeKey; -//import org.simantics.g2d.element.handler.ElementHandler; -//import org.simantics.g2d.element.handler.FillColor; -//import org.simantics.g2d.element.handler.InternalSize; -//import org.simantics.g2d.element.handler.LifeCycle; -//import org.simantics.g2d.element.handler.Move; -//import org.simantics.g2d.element.handler.Outline; -//import org.simantics.g2d.element.handler.Rotate; -//import org.simantics.g2d.element.handler.Scale; -//import org.simantics.g2d.element.handler.SceneGraph; -//import org.simantics.g2d.element.handler.StaticSymbol; -//import org.simantics.g2d.element.handler.Text; -//import org.simantics.g2d.element.handler.TextEditor; -//import org.simantics.g2d.element.handler.Transform; -//import org.simantics.g2d.element.handler.TextEditor.Modifier; -//import org.simantics.g2d.element.handler.impl.BorderColorImpl; -//import org.simantics.g2d.element.handler.impl.FillColorImpl; -//import org.simantics.g2d.element.handler.impl.SimpleElementLayers; -//import org.simantics.g2d.element.handler.impl.StaticSymbolImpl; -//import org.simantics.g2d.element.handler.impl.TextColorImpl; -//import org.simantics.g2d.element.handler.impl.TextEditorImpl; -//import org.simantics.g2d.element.handler.impl.TextFontImpl; -//import org.simantics.g2d.element.handler.impl.TextImpl; -//import org.simantics.g2d.image.Image; -//import org.simantics.g2d.image.ProviderUtils; -//import org.simantics.g2d.image.impl.AbstractImage; -//import org.simantics.g2d.utils.Alignment; -//import org.simantics.scenegraph.Node; -//import org.simantics.scenegraph.g2d.G2DParentNode; -//import org.simantics.scenegraph.g2d.nodes.MonitorNode; -//import org.simantics.utils.datastructures.cache.IFactory; -//import org.simantics.utils.datastructures.cache.IProvider; -//import org.simantics.utils.datastructures.cache.ProvisionException; -//import org.simantics.utils.datastructures.hints.IHintContext.Key; -//import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; -//import org.simantics.utils.strings.format.MetricsFormat; -//import org.simantics.utils.strings.format.MetricsFormatList; -// -///** -// * @author Tuukka Lehtonen -// */ -//public class MonitorClass { -// -// static final Font FONT = Font.decode("Helvetica 12"); -// -// /** -// * Back-end specific object describing the monitored component. -// */ -// public static final Key KEY_MONITOR_COMPONENT = new KeyOf(Object.class, "MONITOR_COMPONENT"); -// -// /** -// * The valuation suffix string describing the monitored variable of the -// * component described by {@link #KEY_MONITOR_COMPONENT}. -// */ -// public static final Key KEY_MONITOR_SUFFIX = new KeyOf(String.class, "MONITOR_SUFFIX"); -// -// public static final Key KEY_MONITOR_SUBSTITUTIONS = new KeyOf(Map.class, "MONITOR_SUBSTITUTIONS"); -// public static final Key KEY_MONITOR_GC = new KeyOf(Graphics2D.class, "MONITOR_GC"); -// public static final Key KEY_MONITOR_HEIGHT = new KeyOf(Double.class, "MONITOR_HEIGHT"); -// public static final Key KEY_NUMBER_FORMAT = new KeyOf(MetricsFormat.class, "NUMBER_FORMAT"); -// public static final Key KEY_TOOLTIP_TEXT = new KeyOf(String.class, "TOOLTIP_TEXT"); -// -// /** -// * If this hint is defined, the monitor will force its x-axis to match this -// * angle. If this hint doesn't exist, the monitor will not force x-axis -// * orientation. -// */ -// public static final Key KEY_DIRECTION = new KeyOf(Double.class, "MONITOR_DIRECTION"); -// -// public static final Key KEY_BORDER_WIDTH = new KeyOf(Double.class, "MONITOR_BORDER"); -// -// public static final Key KEY_SG_NODE = new SceneGraphNodeKey(Node.class, "MONITOR_SG_NODE"); -// -// final static BasicStroke STROKE = new BasicStroke(1.0f); -// -// public final static Alignment DEFAULT_HORIZONTAL_ALIGN = Alignment.CENTER; -// public final static Alignment DEFAULT_VERTICAL_ALIGN = Alignment.CENTER; -// public final static MetricsFormat DEFAULT_NUMBER_FORMAT = MetricsFormatList.METRICS_DECIMAL; -// -// public final static Color DEFAULT_FILL_COLOR = new Color(224, 224, 224); -// public final static Color DEFAULT_BORDER_COLOR = Color.BLACK; -// -// public final static double DEFAULT_HORIZONTAL_MARGIN = 5.0; -// public final static double DEFAULT_VERTICAL_MARGIN = 2.5; -// -// static Alignment getHorizontalAlignment(IElement e) { -// return ElementUtils.getHintOrDefault(e, ElementHints.KEY_HORIZONTAL_ALIGN, DEFAULT_HORIZONTAL_ALIGN); -// } -// -// static Alignment getVerticalAlignment(IElement e) { -// return ElementUtils.getHintOrDefault(e, ElementHints.KEY_VERTICAL_ALIGN, DEFAULT_VERTICAL_ALIGN); -// } -// -// static MetricsFormat getNumberFormat(IElement e) { -// return ElementUtils.getHintOrDefault(e, KEY_NUMBER_FORMAT, DEFAULT_NUMBER_FORMAT); -// } -// -// static void setNumberFormat(IElement e, MetricsFormat f) { -// ElementUtils.setOrRemoveHint(e, KEY_NUMBER_FORMAT, f); -// } -// -// static double getHorizontalMargin(IElement e) { -// return DEFAULT_HORIZONTAL_MARGIN; -// } -// -// static double getVerticalMargin(IElement e) { -// return DEFAULT_VERTICAL_MARGIN; -// } -// -// static Font getFont(IElement e) { -// return ElementUtils.getHintOrDefault(e, ElementHints.KEY_FONT, FONT); -// } -// -// public static class MonitorHandlerImpl implements MonitorHandler { -// private static final long serialVersionUID = -4258875745321808416L; -// public static final MonitorHandler INSTANCE = new MonitorHandlerImpl(); -// } -// -// static class Initializer implements LifeCycle { -// private static final long serialVersionUID = 4404942036933073584L; -// -// IElement parentElement; -// Map substitutions; -// Object component; -// String suffix; -// boolean hack; -// -// Initializer(IElement parentElement, Map substitutions, Object component, String suffix, boolean hack) { -// this.parentElement = parentElement; -// this.substitutions = substitutions; -// this.component = component; -// this.suffix = suffix; -// this.hack = hack; -// } -// -// @Override -// public void onElementActivated(IDiagram d, IElement e) { -// -// if(!hack) { -// -// hack = true; -// -// Point2D parentPos = ElementUtils.getPos(parentElement); -// Point2D thisPos = ElementUtils.getPos(e); -// -// Move move = e.getElementClass().getSingleItem(Move.class); -// move.moveTo(e, thisPos.getX() - parentPos.getX(), thisPos.getY() - parentPos.getY()); -// -// } -// -// } -// @Override -// public void onElementCreated(IElement e) { -// if(parentElement != null) e.setHint(ElementHints.KEY_PARENT_ELEMENT, parentElement); -// if(substitutions != null) e.setHint(KEY_MONITOR_SUBSTITUTIONS, substitutions); -// if(component != null) e.setHint(KEY_MONITOR_COMPONENT, component); -// if(suffix != null) e.setHint(KEY_MONITOR_SUFFIX, suffix); -// -// e.setHint(KEY_DIRECTION, 0.0); -// e.setHint(KEY_NUMBER_FORMAT, DEFAULT_NUMBER_FORMAT); -// //e.setHint(KEY_HORIZONTAL_ALIGN, Alignment.LEADING); -// //e.setHint(KEY_VERTICAL_ALIGN, Alignment.LEADING); -// } -// @Override -// public void onElementDeactivated(IDiagram d, IElement e) { -// } -// @Override -// public void onElementDestroyed(IElement e) { -// } -// }; -// -// static String finalText(IElement e) { -// String text = e.getElementClass().getSingleItem(Text.class).getText(e); -// if (text == null) -// return null; -// return substitute(text, e); -// } -// -// public static String editText(IElement e) { -// return substitute("#v1", e); -// } -// -// private static String formValue(IElement e) { -// // TODO: consider using substitute -// Map substitutions = e.getHint(KEY_MONITOR_SUBSTITUTIONS); -// if (substitutions != null) { -// String value = substitutions.get("#v1"); -// if (substitutions.containsKey("#u1") && substitutions.get("#u1").length() > 0) { -// value += " " + substitutions.get("#u1"); -// } -// return value; -// } -// return null; -// } -// -// static String substitute(String text, IElement e) { -// Map substitutions = e.getHint(KEY_MONITOR_SUBSTITUTIONS); -// return substitute(text, substitutions); -// } -// -// static String substitute(String text, Map substitutions) { -// if (substitutions != null) { -// // TODO: slow as hell -// for(Map.Entry entry : substitutions.entrySet()) { -// if (entry.getValue() != null) { -// text = text.replace(entry.getKey(), entry.getValue()); -// } else { -// text = text.replace(entry.getKey(), ""); -// } -// } -// } -// return text; -// } -// -// public static void update(IElement e) { -// MonitorSGNode node = e.getElementClass().getSingleItem(MonitorSGNode.class); -// node.update(e); -// } -// -// public static void cleanup(IElement e) { -// MonitorSGNode node = e.getElementClass().getSingleItem(MonitorSGNode.class); -// node.cleanup(e); -// } -// -// static final Rectangle2D DEFAULT_BOX = new Rectangle2D.Double(0, 0, 0, 0); -// -// static Shape createMonitor(IElement e) { -// Alignment hAlign = getHorizontalAlignment(e); -// Alignment vAlign = getVerticalAlignment(e); -// double hMargin = getHorizontalMargin(e); -// double vMargin = getVerticalMargin(e); -// -// String text = finalText(e); -// if(text == null) { -// return align(hMargin, vMargin, hAlign, vAlign, DEFAULT_BOX); -// } -// -// Graphics2D g = e.getHint(KEY_MONITOR_GC); -// if(g == null) { -// return align(hMargin, vMargin, hAlign, vAlign, DEFAULT_BOX); -// } -// -// Font f = getFont(e); -// FontMetrics fm = g.getFontMetrics(f); -// Rectangle2D rect = fm.getStringBounds(text, g); -// -// return align(hMargin, vMargin, hAlign, vAlign, rect); -// } -// -// static Shape align(double hMargin, double vMargin, Alignment hAlign, Alignment vAlign, Rectangle2D rect) { -// //System.out.println("align: " + hMargin + ", " + vMargin + ", " + hAlign + ", " + vAlign + ": " + rect); -// double tx = align(hMargin, hAlign, rect.getMinX(), rect.getMaxX()); -// double ty = align(vMargin, vAlign, rect.getMinY(), rect.getMaxY()); -// //System.out.println(" translate: " + tx + " " + ty); -// double nw = rect.getWidth() + 2*hMargin; -// double nh = rect.getHeight() + 2*vMargin; -// return makePath(tx + rect.getMinX(), ty + rect.getMinY(), nw, nh); -// } -// -// static double align(double margin, Alignment align, double min, double max) { -// double s = max - min; -// switch (align) { -// case LEADING: -// return -min; -// case TRAILING: -// return -s - 2 * margin - min; -// case CENTER: -// return -0.5 * s - margin - min; -// default: -// return 0; -// } -// } -// -// static Path2D makePath(double x, double y, double w, double h) { -// Path2D path = new Path2D.Double(); -// path.moveTo(x, y); -// path.lineTo(x+w, y); -// path.lineTo(x+w, y+h); -// path.lineTo(x, y+h); -// path.closePath(); -// return path; -// } -// -// public static final Shape BOX_SHAPE = new Rectangle(-1, -1, 2, 2); -// -// public static class MonitorSGNode implements SceneGraph, InternalSize, Outline { -// private static final long serialVersionUID = -106278359626957687L; -// -// static final MonitorSGNode INSTANCE = new MonitorSGNode(); -// -// @Override -// public void init(final IElement e, final G2DParentNode parent) { -// // Create node if it doesn't exist yet -// MonitorNode node = (MonitorNode)e.getHint(KEY_SG_NODE); -// if(node == null || node.getBounds() == null || node.getParent() != parent) { -// node = parent.addNode(ElementUtils.generateNodeId(e), MonitorNode.class); -// e.setHint(KEY_SG_NODE, node); -// -// node.setActionListener(new ActionListener() { -// @Override -// public void actionPerformed(ActionEvent event) { -// TextEditor editor = e.getElementClass().getAtMostOneItemOfClass(TextEditor.class); -// if (editor != null) { -// Modifier modifier = editor.getModifier(e); -// if (modifier != null) { -// String newValue = event.getActionCommand(); -// String error = modifier.isValid(e, newValue); -// -// if (error == null) { -// // Only modify if the modification was not -// // cancelled and the value is valid. -// modifier.modify(e, newValue); -// } else { -// // TODO: show error somehow, possibly through status bar -// -// // Make sure that the monitor content gets -// // reset to its previous value. -// MonitorNode node = e.getHint(KEY_SG_NODE); -// if (node != null) -// node.setText(formValue(e)); -// } -// } -// } -// -//// final Text t = e.getElementClass().getAtMostOneItemOfClass(Text.class); -//// t.setText(e, event.getActionCommand()); // FIXME -// }}); -// node.setSize(50, 22); -// Double border_width = (Double)e.getHint(KEY_BORDER_WIDTH); -// if(border_width == null) border_width = 0.1; -// -// node.setBorderWidth(border_width); -// -// Rectangle2D bounds = (Rectangle2D)e.getHint(ElementHints.KEY_BOUNDS); -// if(bounds != null) node.setBounds(bounds); -// } -// update(e); -// } -// -// public void update(IElement e) { -// String value = null; -// -// final Text t = e.getElementClass().getAtMostOneItemOfClass(Text.class); -// assert(t != null); -// -// value = formValue(e); -// -// MonitorNode node = (MonitorNode) e.getHint(KEY_SG_NODE); -// if (node != null && value != null) { -// node.setText(value); -// Object component = e.getHint(KEY_MONITOR_COMPONENT); -// if (component != null) { -// node.setEditable(true); -// } else { -// node.setEditable(false); -// } -// -// // FIXME: set only if changed .. (but quickfix is not to clone) -// Font font = ElementUtils.getTextFont(e); -// if (node.getFont() != font) { // Don't update if we have a same object -// node.setFont(font); -// } -// Color color = ElementUtils.getTextColor(e); -// node.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha())); -// String tt = (String) e.getHint(KEY_TOOLTIP_TEXT); -// if (tt != null) -// node.setToolTipText(new String(tt)); -// } -// } -// -// @Override -// public void cleanup(IElement e) { -// MonitorNode node = (MonitorNode)e.removeHint(KEY_SG_NODE); -// if (node != null) -// node.remove(); -// } -// -// @Override -// public Rectangle2D getBounds(IElement e, Rectangle2D size) { -// Rectangle2D shape = new Rectangle2D.Double(0, 0, 0, 0); -// -// MonitorNode node = (MonitorNode)e.getHint(KEY_SG_NODE); -// if(node != null && node.getBounds() != null) { -// shape = node.getBounds().getBounds2D(); -// } -// -// if(size != null) size.setRect(shape); -// return shape; -// } -// -// @Override -// public Shape getElementShape(IElement e) { -// Shape shape = new Rectangle2D.Double(0, 0, 0, 0); -// -// MonitorNode node = (MonitorNode)e.getHint(KEY_SG_NODE); -// if(node != null && node.getBounds() != null) { -// shape = node.getBounds(); -// } -// -// return shape; -// } -// -// } -// -// public static class Transformer implements Transform, Move, Rotate, Scale, LifeCycle { -// -// private static final long serialVersionUID = -3704887325602085677L; -// -// public static final Transformer INSTANCE = new Transformer(null); -// -// Double aspectRatio; -// -// public Transformer() { -// this(null); -// } -// -// public Transformer(Double aspectRatio) { -// this.aspectRatio = aspectRatio; -// } -// -// @Override -// public Double getFixedAspectRatio(IElement e) { -// return aspectRatio; -// } -// -// @Override -// public Point2D getScale(IElement e) { -// AffineTransform at = e.getHint(ElementHints.KEY_TRANSFORM); -// return _getScale(at); -// } -// -// @Override -// public void setScale(IElement e, Point2D newScale) { -// // Doesn't work for monitors. -// Point2D oldScale = getScale(e); -// double sx = newScale.getX() / oldScale.getX(); -// double sy = newScale.getY() / oldScale.getY(); -// AffineTransform at = e.getHint(ElementHints.KEY_TRANSFORM); -// at = new AffineTransform(at); -// at.scale(sx, sy); -// e.setHint(ElementHints.KEY_TRANSFORM, at); -// } -// -// @Override -// public Point2D getMaximumScale(IElement e) { -// return null; -// } -// -// @Override -// public Point2D getMinimumScale(IElement e) { -// return null; -// } -// -// private static Point2D _getScale(AffineTransform at) { -// double m00 = at.getScaleX(); -// double m11 = at.getScaleY(); -// double m10 = at.getShearY(); -// double m01 = at.getShearX(); -// // Project unit vector to canvas -// double sx = Math.sqrt(m00 * m00 + m10 * m10); -// double sy = Math.sqrt(m01 * m01 + m11 * m11); -// return new Point2D.Double(sx, sy); -// } -// -// @Override -// public void rotate(IElement e, double theta, Point2D origin) { -// if (Double.isNaN(theta)) return; -// theta = Math.toDegrees(theta); -// Double angle = e.getHint(KEY_DIRECTION); -// double newAngle = angle != null ? angle+theta : theta; -// newAngle = Math.IEEEremainder(newAngle, 360.0); -// e.setHint(KEY_DIRECTION, newAngle); -// } -// -// @Override -// public double getAngle(IElement e) { -// Double angle = e.getHint(KEY_DIRECTION); -// return angle != null ? Math.toRadians(angle) : 0; -// } -// -// @Override -// public Point2D getPosition(IElement e) { -// AffineTransform at = e.getHint(ElementHints.KEY_TRANSFORM); -// Point2D p = new Point2D.Double(at.getTranslateX(), at.getTranslateY()); -// return p; -// } -// -// @Override -// public void moveTo(IElement e, double x, double y) { -// AffineTransform origAt = e.getHint(ElementHints.KEY_TRANSFORM); -// double oldX = origAt.getTranslateX(); -// double oldY = origAt.getTranslateY(); -// AffineTransform move = AffineTransform.getTranslateInstance(x-oldX, y-oldY); -// AffineTransform at2 = new AffineTransform(origAt); -// at2.preConcatenate(move); -// e.setHint(ElementHints.KEY_TRANSFORM, at2); -// } -// -// @Override -// public AffineTransform getTransform(IElement e) { -// AffineTransform at = e.getHint(ElementHints.KEY_TRANSFORM); -// -// IElement parentElement = e.getHint(ElementHints.KEY_PARENT_ELEMENT); -// if (parentElement == null) -// return at; -// -// Transform parentTransform = parentElement.getElementClass().getSingleItem(Transform.class); -// assert(parentTransform!=null); -// -// AffineTransform result = (AffineTransform)at.clone(); -// result.preConcatenate(parentTransform.getTransform(parentElement)); -// -// return result; -// } -// -// @Override -// public void setTransform(IElement e, AffineTransform at) { -// e.setHint(ElementHints.KEY_TRANSFORM, at.clone()); -// } -// -// @Override -// public void onElementActivated(IDiagram d, IElement e) { -// } -// -// @Override -// public void onElementCreated(IElement e) { -// e.setHint(ElementHints.KEY_TRANSFORM, new AffineTransform()); -// } -// -// @Override -// public void onElementDeactivated(IDiagram d, IElement e) { -// } -// -// @Override -// public void onElementDestroyed(IElement e) { -//// List nodeHandlers = e.getElementClass().getItemsByClass(SceneGraph.class); -//// for(SceneGraph n : nodeHandlers) { -//// System.out.println("element gone:"+e); -//// n.cleanup(e); -//// } -// } -// } -// -// static double getOrientationDelta(IElement e, AffineTransform tr) { -// Double angle = e.getHint(KEY_DIRECTION); -// if (angle == null || Double.isNaN(angle)) -// return Double.NaN; -// double angrad = Math.toRadians(angle); -// -// Vector2d forcedAxis = new Vector2d(Math.cos(angrad), Math.sin(angrad)); -// Vector2d x = new Vector2d(tr.getScaleX(), tr.getShearX()); -// forcedAxis.normalize(); -// x.normalize(); -// double cosa = forcedAxis.dot(x); -// double delta = Math.acos(cosa); -// return delta; -// } -// -// static class MonitorImageFactory implements IFactory { -// private double staticScaleX = 1, staticScaleY = 1; -// -// public MonitorImageFactory(double staticScaleX, double staticScaleY) { -// this.staticScaleX = staticScaleX; -// this.staticScaleY = staticScaleY; -// } -// -// @Override -// public Image get() throws ProvisionException { -// return new AbstractImage() { -// Shape path = align(DEFAULT_HORIZONTAL_MARGIN, DEFAULT_VERTICAL_MARGIN, DEFAULT_HORIZONTAL_ALIGN, DEFAULT_VERTICAL_ALIGN, -// new Rectangle2D.Double(0, 0, 50*staticScaleX, 22*staticScaleY)); -// -// @Override -// public Rectangle2D getBounds() { -// return path.getBounds2D(); -// } -// -// @Override -// public EnumSet getFeatures() { -// return EnumSet.of(Feature.Vector); -// } -// -// @Override -// public Shape getOutline() { -// return path; -// } -// -// @Override -// public Node init(G2DParentNode parent) { -// MonitorNode node = parent.getOrCreateNode(""+hashCode(), MonitorNode.class); -// node.setText(""); -// node.setSize(50, 22); -// node.setBorderWidth(1); -// node.setText("Drop Me"); -// node.setTransform(AffineTransform.getScaleInstance(staticScaleX, staticScaleY)); -// return node; -// } -// }; -// } -// } -// -// static final IProvider MONITOR_IMAGE = -// ProviderUtils.reference( -// ProviderUtils.cache( -// ProviderUtils.rasterize( -// new MonitorImageFactory(0.5, 0.5) -// ))); -// -// static final StaticSymbol MONITOR_SYMBOL = new StaticSymbolImpl( MONITOR_IMAGE.get() ); -// -// static final FillColor FILL_COLOR = new FillColorImpl(DEFAULT_FILL_COLOR); -// -// public static final ElementClass MONITOR_CLASS = -// ElementClass.compile( -// MonitorHandlerImpl.INSTANCE, -// Transformer.INSTANCE, -// BorderColorImpl.BLACK, -// FILL_COLOR, -// MonitorSGNode.INSTANCE, -// TextImpl.INSTANCE, -// TextEditorImpl.INSTANCE, -// TextFontImpl.DEFAULT, -// TextColorImpl.BLACK, -// SimpleElementLayers.INSTANCE, -// MONITOR_SYMBOL -// ); -// -// // staticScale{X,Y} define the scale of the static monitor image -// public static ElementClass create(IElement parentElement, Map substitutions, Object component, String suffix, double staticScaleX, double staticScaleY, ElementHandler... extraHandlers) { -// // Bit of a hack to be able to define the scale -// IProvider staticMonitorSymbolProvider = ProviderUtils.reference( -// ProviderUtils.cache( -// ProviderUtils -// .rasterize( -// new MonitorImageFactory(staticScaleX, staticScaleY)))); -// StaticSymbol staticMonitorSymbol = new StaticSymbolImpl( staticMonitorSymbolProvider.get() ); -// return ElementClass.compile( -// new Initializer(parentElement, substitutions, component, suffix, parentElement != null ? false : true), -// MonitorHandlerImpl.INSTANCE, -// Transformer.INSTANCE, -// BorderColorImpl.BLACK, -// FILL_COLOR, -// MonitorSGNode.INSTANCE, -// TextImpl.INSTANCE, -// TextEditorImpl.INSTANCE, -// TextFontImpl.DEFAULT, -// TextColorImpl.BLACK, -// SimpleElementLayers.INSTANCE, -// staticMonitorSymbol -// ).newClassWith(extraHandlers); -// } -// -//} diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/wheel/RotatorHandler.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/wheel/RotatorHandler.java index 01d60e58f..f364f5040 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/wheel/RotatorHandler.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/wheel/RotatorHandler.java @@ -14,9 +14,8 @@ package org.simantics.g2d.elementclass.wheel; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; -import javax.vecmath.Vector2d; -import javax.vecmath.Vector3d; - +import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; +import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; import org.simantics.g2d.canvas.ICanvasContext; import org.simantics.g2d.diagram.IDiagram; import org.simantics.g2d.element.ElementHints; @@ -52,7 +51,7 @@ public class RotatorHandler extends AbstractGrabbable implements HandleMouseEven public static final RotatorHandler INSTANCE = new RotatorHandler(); - public static final double STRAY_DISTANCE = 1000; + public static final double STRAY_DISTANCE = 1000; public double initial_friction = 0.20; public double initial_grab_friction = 0.99; @@ -63,8 +62,8 @@ public class RotatorHandler extends AbstractGrabbable implements HandleMouseEven /** Angular velocity, canvas specific variable */ public static final Key KEY_ANG_VEL = new KeyOf(Double.class); /** Minimum number of pointers */ - public static final Key KEY_MIN_POINTERS = new KeyOf(Integer.class); - public static final Key KEY_GRAB_FRICTION = new KeyOf(Double.class); + public static final Key KEY_MIN_POINTERS = new KeyOf(Integer.class); + public static final Key KEY_GRAB_FRICTION = new KeyOf(Double.class); public static final Key KEY_FRICTION = new KeyOf(Double.class); public static final Key KEY_FACTOR = new KeyOf(Double.class); @@ -75,50 +74,46 @@ public class RotatorHandler extends AbstractGrabbable implements HandleMouseEven @Override protected void onDrag(GrabInfo gi, ICanvasContext ctx) { IElement e = gi.e; - Point2D origo = getOrigo(e, null); + Point2D origo = getOrigo(e, null); Point2D prevPos = gi.prevPosElement; Point2D p = gi.dragPosElement; - // ---- Wheel is held! ---- + // ---- Wheel is held! ---- // position vector 0 - Vector2d p0 = new Vector2d(prevPos.getX(), prevPos.getY()); + Vector2D p0 = new Vector2D(prevPos.getX(), prevPos.getY()); // position vector 1 - Vector2d p1 = new Vector2d(p.getX(), p.getY()); + Vector2D p1 = new Vector2D(p.getX(), p.getY()); // motion vector - Vector2d f = new Vector2d(p1); - f.sub(p0); + Vector2D f = p1.subtract(p0); // no movement - if (f.length()==0) return; + if (f.getNormSq()==0) return; // -- We are holding the wheel and we have moved the pointer -- // vector from origo to mouse - Vector2d odp0 = new Vector2d(p0.x - origo.getX(), p0.y - origo.getY()); - Vector2d odp1 = new Vector2d(p1.x - origo.getX(), p1.y - origo.getY()); + Vector2D odp0 = new Vector2D(p0.getX() - origo.getX(), p0.getY() - origo.getY()); + Vector2D odp1 = new Vector2D(p1.getX() - origo.getX(), p1.getY() - origo.getY()); // convert motion into tangential and normal vectors // normal vector of the motion - Vector2d fn = new Vector2d(odp0); - fn.scale( f.dot(odp0) / odp0.lengthSquared() ); + Vector2D fn = odp0.scalarMultiply( f.dotProduct(odp0) / odp0.getNormSq() ); // tangential vector of the motion - Vector2d ft = new Vector2d(f); - ft.sub(fn); + Vector2D ft = f.subtract(fn); // momentum - Vector3d r = new Vector3d(odp0.x, odp0.y, 0); - Vector3d F = new Vector3d(ft.x, ft.y, 0); - Vector3d M = new Vector3d(); - M.cross(r, F); + Vector3D r = new Vector3D(odp0.getX(), odp0.getY(), 0); + Vector3D F = new Vector3D(ft.getX(), ft.getY(), 0); + Vector3D M = r.crossProduct(F); if (!isGrabbed(e, ctx)) return; // Turn the wheel - double deltaAngle = odp0.angle(odp1); - if (M.z<0) deltaAngle *= -1; + double deltaAngle = Vector2D.angle(odp0, odp1); + if (M.getZ()<0) deltaAngle *= -1; double deltaAngularVelocity = deltaAngle * 20; setAngVel(e, getAngVel(e)+deltaAngularVelocity); deltaAngle *= 0.297; - modifyValue(e, ctx, deltaAngle); + modifyValue(e, ctx, deltaAngle); } @Override @@ -172,7 +167,7 @@ public class RotatorHandler extends AbstractGrabbable implements HandleMouseEven double dt = ((double)deltaTime)/1000; angVel *= Math.pow(1-f, dt); setAngVel(e, angVel); - ctx.getContentContext().setDirty(); + ctx.getContentContext().setDirty(); } @Override @@ -262,11 +257,11 @@ public class RotatorHandler extends AbstractGrabbable implements HandleMouseEven public void setAngVel(IElement e, double value) { - e.setHint(KEY_ANG_VEL, value); + e.setHint(KEY_ANG_VEL, value); } public boolean isGrabbed(IElement e, ICanvasContext ctx) { - return (getGrabCount(e, ctx)>=getMinPointers(e)) || !isEnabled(e); + return (getGrabCount(e, ctx)>=getMinPointers(e)) || !isEnabled(e); } public boolean isMoving(IElement e) { @@ -286,8 +281,6 @@ public class RotatorHandler extends AbstractGrabbable implements HandleMouseEven public boolean isMoveable(IElement e) { return true; - } + } - - } diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/wheel/WheelClass.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/wheel/WheelClass.java index a36315698..f23f742cd 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/wheel/WheelClass.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/wheel/WheelClass.java @@ -22,15 +22,13 @@ import org.simantics.g2d.image.DefaultImages; */ public class WheelClass { - public static final ElementClass WHEEL = - ElementClass.compile( - // Pick missing - DefaultTransform.INSTANCE, - new RotatorHandler(), - new PaintableSymbolHandler(DefaultImages.WHEEL), - Stateful.ENABLED_BY_DEFAULT - ); - + public static final ElementClass WHEEL = + ElementClass.compile( + // Pick missing + DefaultTransform.INSTANCE, + new RotatorHandler(), + new PaintableSymbolHandler(DefaultImages.WHEEL), + Stateful.ENABLED_BY_DEFAULT + ); - } diff --git a/bundles/org.simantics.modeling.ui/META-INF/MANIFEST.MF b/bundles/org.simantics.modeling.ui/META-INF/MANIFEST.MF index f396a5815..a84c13f5f 100644 --- a/bundles/org.simantics.modeling.ui/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.modeling.ui/META-INF/MANIFEST.MF @@ -13,7 +13,7 @@ Require-Bundle: org.simantics.project;bundle-version="1.0.0", org.simantics.modeling;bundle-version="1.0.0";visibility:=reexport, org.simantics.utils.thread.swt;bundle-version="1.0.0", org.simantics.simulation;bundle-version="1.0.0", - javax.vecmath;bundle-version="1.5.2", + org.apache.commons.math3;bundle-version="3.6.1", org.simantics.browsing.ui.platform;bundle-version="1.0.0";visibility:=reexport, org.simantics.structural.ui;bundle-version="1.0.0", org.eclipse.ui.forms;bundle-version="3.4.1", diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/SliderClass.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/SliderClass.java index 03edf6577..60f28f17b 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/SliderClass.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/SliderClass.java @@ -22,8 +22,8 @@ import java.util.Collection; import java.util.EnumSet; import javax.swing.JSlider; -import javax.vecmath.Vector2d; +import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; import org.simantics.g2d.diagram.IDiagram; import org.simantics.g2d.element.ElementClass; import org.simantics.g2d.element.ElementHints; @@ -383,11 +383,9 @@ public class SliderClass { return Double.NaN; double angrad = Math.toRadians(angle); - Vector2d forcedAxis = new Vector2d(Math.cos(angrad), Math.sin(angrad)); - Vector2d x = new Vector2d(tr.getScaleX(), tr.getShearX()); - forcedAxis.normalize(); - x.normalize(); - double cosa = forcedAxis.dot(x); + Vector2D forcedAxis = new Vector2D(Math.cos(angrad), Math.sin(angrad)); + Vector2D x = new Vector2D(tr.getScaleX(), tr.getShearX()).normalize(); + double cosa = forcedAxis.dotProduct(x); double delta = Math.acos(cosa); return delta; } diff --git a/features/org.simantics.g2d.feature/feature.xml b/features/org.simantics.g2d.feature/feature.xml index 791613f1c..e54ed961d 100644 --- a/features/org.simantics.g2d.feature/feature.xml +++ b/features/org.simantics.g2d.feature/feature.xml @@ -194,7 +194,7 @@ unpack="false"/> ${itext.version.actual} - - javax.vecmath:vecmath:1.5.2 - false - true - - javax.vecmath - - org.mozilla:rhino:1.7.7.1 true - net.java.dev.jna:jna:4.2.2 + net.java.dev.jna:jna:4.3.0 true - net.java.dev.jna:jna-platform:4.2.2 + net.java.dev.jna:jna-platform:4.3.0 true