>-- DIA.symbolCode <R L0.HasProperty : L0.FunctionalRelation
>-- DIA.symbolDropHandler ==> "[WorkbenchSelectionElement] -> <WriteGraph,Proc> ()" <R L0.HasProperty : L0.FunctionalRelation
// Parameters are id of edited element and new text.
- >-- DIA.DefinedElement.textEditor ==> "String -> String -> <Proc> ()" <R L0.HasProperty : DIA.DefinedElement.Parameter
+ >-- DIA.DefinedElement.textEditor ==> "SVGMeasurementContext -> String -> String -> <Proc> ()" <R L0.HasProperty : DIA.DefinedElement.Parameter
// This function gives initial text for the text editor. Parameter is the id of the edited element.
>-- DIA.DefinedElement.textEditorFullText ==> "String -> <Proc> String" <R L0.HasProperty : DIA.DefinedElement.Parameter
import "Simantics/Variables"
+include "Simantics/Diagram/SVGNode"
import "http://www.simantics.org/Diagram-2.2" as DIA
import "http://www.simantics.org/G2D-1.1" as G2D
--- /dev/null
+
+type BoundingBox = (Double,Double,Double,Double)
+
+importJava "org.simantics.diagram.elements.SVGMeasurementContext" where
+ data SVGMeasurementContext
+ getBoundingBox :: SVGMeasurementContext -> String -> <Proc> Maybe BoundingBox
+
+getBoundingBoxX :: BoundingBox -> Double
+getBoundingBoxX (x,_,_,_) = x
+
+getBoundingBoxY :: BoundingBox -> Double
+getBoundingBoxY (_,y,_,_) = y
+
+getBoundingBoxW :: BoundingBox -> Double
+getBoundingBoxW (_,_,w,_) = w
+
+getBoundingBoxH :: BoundingBox -> Double
+getBoundingBoxH (_,_,_,h) = h
+
+
+/*******************************************************************************
+ * Copyright (c) 2017 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:
+ * Semantum Oy - initial API and implementation
+ *******************************************************************************/
package org.simantics.diagram.elements;
import java.awt.geom.Point2D;
import org.simantics.scenegraph.g2d.events.MouseEvent.MouseClickEvent;
import org.simantics.scenegraph.g2d.nodes.SingleElementNode;
import org.simantics.scl.runtime.function.Function1;
-import org.simantics.scl.runtime.function.Function2;
+import org.simantics.scl.runtime.function.Function3;
+import org.simantics.scl.runtime.tuple.Tuple4;
import com.kitfox.svg.SVGDiagram;
import com.kitfox.svg.SVGElement;
private LinkedList<EditorState> editorState = null;
private int editorStateIndex = 0;
+ static class SVGMeasurementContextImpl implements SVGMeasurementContext {
+ private SVGNode node;
+ public SVGMeasurementContextImpl(SVGNode node) {
+ this.node = node;
+ }
+ @Override
+ public Tuple4 getBoundingBox(String id) {
+ try {
+ Rectangle2D rect = node.getElementBounds(id);
+ if(rect == null) return null;
+ return new Tuple4(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
+ } catch (SVGException e) {
+ return null;
+ }
+ }
+ }
+
EditorStateManager(SVGNode node) {
this.node = node;
}
SingleElementNode sne = node.getSingleElementNode();
if (sne != null) {
EditorState es = currentState();
- Function2<String,String,Object> editor = sne.getParameter("textEditor");
+ Function3<SVGMeasurementContext,String,String,Object> editor = sne.getParameter("textEditor");
if(editor != null) {
- editor.apply(es.base.textElementId, es.currentText);
+ editor.apply(new SVGMeasurementContextImpl(node), es.base.textElementId, es.currentText);
}
}
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2017 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:
+ * Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.diagram.elements;
+
+import org.simantics.scl.runtime.tuple.Tuple4;
+
+/**
+ * @author Antti Villberg
+ * @since 1.31.0
+ */
+public interface SVGMeasurementContext {
+ Tuple4 getBoundingBox(String id);
+}
import org.simantics.scl.runtime.function.Function2;
import org.simantics.utils.threads.AWTThread;
+import com.kitfox.svg.RenderableElement;
import com.kitfox.svg.SVGCache;
import com.kitfox.svg.SVGDiagram;
import com.kitfox.svg.SVGElement;
return ret;
}
+ public Rectangle2D getElementBounds(String id) throws SVGException {
+ SVGElement e = diagramCache.getElement(id);
+ if (e instanceof RenderableElement) {
+ return ((RenderableElement)e).getBoundingBox();
+ } else {
+ return null;
+ }
+ }
+
}