Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 260900 Details for
Bug 441352
Add support for polygon-based node shapes (DOT Editor and DOT Graph View)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Add Xtext editor support for polygon/record based node shapes
441352-Add-xtexteditor-support-for-node-shapes.patch (text/plain), 38.34 KB, created by
Tamas Miklossy
on 2016-04-12 13:53:17 EDT
(
hide
)
Description:
Add Xtext editor support for polygon/record based node shapes
Filename:
MIME Type:
Creator:
Tamas Miklossy
Created:
2016-04-12 13:53:17 EDT
Size:
38.34 KB
patch
obsolete
>diff --git a/org.eclipse.gef4.dot.tests/resources/nodeshapes_polygon_based.dot b/org.eclipse.gef4.dot.tests/resources/nodeshapes_polygon_based.dot >new file mode 100644 >index 0000000..52dc463 >--- /dev/null >+++ b/org.eclipse.gef4.dot.tests/resources/nodeshapes_polygon_based.dot >@@ -0,0 +1,85 @@ >+/******************************************************************************* >+ * Copyright (c) 2016 itemis AG and others. >+ * >+ * 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: >+ * Tamas Miklossy (itemis AG) - Initial text (bug #441352) >+ *******************************************************************************/ >+ >+/* >+ * The PolygonBasedNodeShapes graph represents the different polygon based node shapes >+ * that an be used as valid values for the shape node attribute. >+ */ >+graph PolygonBasedNodeShapes { >+ rankdir=TB >+ 1[shape=box] >+ >+ /* If shape="polygon", the attributes sides, skew and distortion are also used.*/ >+ 2[shape=polygon sides=5, skew=0, distortion=0] >+ 3[shape=ellipse] >+ 4[shape=oval] >+ 5[shape=circle] >+ 6[shape=point] >+ 7[shape=egg] >+ 8[shape=triangle] >+ 9[shape=plaintext] >+ >+ /* >+ * The node shape=plain requires also the label attribute to be set, otherwise it will be rendered >+ * as a box shape with the following warning: "Warning: using box for unknown shape plain." >+ */ >+ 10[shape=plain label=PLAIN_LABEL] >+ 11[shape=diamond] >+ 12[shape=trapezium] >+ 13[shape=parallelogram] >+ 14[shape=house] >+ 15[shape=pentagon] >+ 16[shape=hexagon] >+ 17[shape=septagon] >+ 18[shape=octagon] >+ 19[shape=doublecircle] >+ 20[shape=doubleoctagon] >+ 21[shape=tripleoctagon] >+ 22[shape=invtriangle] >+ 23[shape=invtrapezium] >+ 24[shape=invhouse] >+ 25[shape=Mdiamond] >+ 26[shape=Msquare] >+ 27[shape=Mcircle] >+ 28[shape=rect] >+ 29[shape=rectangle] >+ 30[shape=square] >+ 31[shape=star] >+ 32[shape=none] >+ 33[shape=underline] >+ 34[shape=cylinder] >+ 35[shape=note] >+ 36[shape=tab] >+ 37[shape=folder] >+ 38[shape=box3d] >+ 39[shape=component] >+ 40[shape=promoter] >+ 41[shape=cds] >+ 42[shape=terminator] >+ 43[shape=utr] >+ 44[shape=primersite] >+ 45[shape=restrictionsite] >+ 46[shape=fivepoverhang] >+ 47[shape=threepoverhang] >+ 48[shape=noverhang] >+ 49[shape=assembly] >+ 50[shape=signature] >+ 51[shape=insulator] >+ 52[shape=ribosite] >+ 53[shape=rnastab] >+ 54[shape=proteasesite] >+ 55[shape=proteinstab] >+ 56[shape=rpromoter] >+ 57[shape=rarrow] >+ 58[shape=larrow] >+ 59[shape=lpromoter] >+} >\ No newline at end of file >diff --git a/org.eclipse.gef4.dot.tests/src/org/eclipse/gef4/dot/tests/DotParserTests.java b/org.eclipse.gef4.dot.tests/src/org/eclipse/gef4/dot/tests/DotParserTests.java >index a295b06..0a33e0c 100644 >--- a/org.eclipse.gef4.dot.tests/src/org/eclipse/gef4/dot/tests/DotParserTests.java >+++ b/org.eclipse.gef4.dot.tests/src/org/eclipse/gef4/dot/tests/DotParserTests.java >@@ -7,7 +7,8 @@ > * http://www.eclipse.org/legal/epl-v10.html > * > * Contributors: >- * Tamas Miklossy (itemis AG) - initial implementation (bug #477980) >+ * Tamas Miklossy (itemis AG) - initial implementation (bug #477980) >+ * - Add support for polygon-based node shapes (bug #441352) > * > *******************************************************************************/ > package org.eclipse.gef4.dot.tests; >@@ -64,6 +65,11 @@ > testFile("arrowshapes_invalid_modifiers.dot"); > } > >+ @Test >+ public void testPolygonBasedNodeShapes() { >+ testFile("nodeshapes_polygon_based.dot"); >+ } >+ > private void testFile(String fileName) { > String fileContents = DotFileUtils > .read(new File(DotTestUtils.RESOURCES_TESTS + fileName)); >diff --git a/org.eclipse.gef4.dot.tests/src/org/eclipse/gef4/dot/tests/DotValidatorTests.java b/org.eclipse.gef4.dot.tests/src/org/eclipse/gef4/dot/tests/DotValidatorTests.java >index 20511aa..e5a8d2f 100644 >--- a/org.eclipse.gef4.dot.tests/src/org/eclipse/gef4/dot/tests/DotValidatorTests.java >+++ b/org.eclipse.gef4.dot.tests/src/org/eclipse/gef4/dot/tests/DotValidatorTests.java >@@ -8,6 +8,7 @@ > * > * Contributors: > * Tamas Miklossy (itemis AG) - initial implementation (bug #477980) >+ * - Add support for polygon-based node shapes (bug #441352) > * > *******************************************************************************/ > >@@ -212,6 +213,76 @@ > Assert.assertEquals(1, validationTestHelper.validate(dotAst).size()); > } > >+ @Test >+ public void testWrongNodeDistortion() throws Exception { >+ String text = "graph { 1[distortion=foo] 2[distortion=\"-100.0001\"]}"; >+ >+ DotAst dotAst = parserHelper.parse(text); >+ >+ validationTestHelper.assertError(dotAst, >+ DotPackage.eINSTANCE.getAttribute(), >+ DotAttributes.DISTORTION__N, >+ "The value 'foo' is not a syntactically correct double: For input string: \"foo\"."); >+ >+ validationTestHelper.assertError(dotAst, >+ DotPackage.eINSTANCE.getAttribute(), >+ DotAttributes.DISTORTION__N, >+ "The double value '-100.0001' is not semantically correct: Value may not be smaller than -100.0"); >+ >+ // verify that this is the only reported issue >+ Assert.assertEquals(2, validationTestHelper.validate(dotAst).size()); >+ } >+ >+ @Test >+ public void testWrongNodeShape() throws Exception { >+ String text = "graph { 1[shape=foo] }"; >+ >+ DotAst dotAst = parserHelper.parse(text); >+ >+ validationTestHelper.assertError(dotAst, >+ DotPackage.eINSTANCE.getAttribute(), DotAttributes.SHAPE__N, >+ "The value 'foo' is not a syntactically correct shape: Mismatched character 'o' expecting 'l'."); >+ >+ // verify that this is the only reported issue >+ Assert.assertEquals(1, validationTestHelper.validate(dotAst).size()); >+ } >+ >+ @Test >+ public void testWrongNodeSides() throws Exception { >+ String text = "graph { 1[sides=foo] 2[sides=\"-1\"]}"; >+ >+ DotAst dotAst = parserHelper.parse(text); >+ >+ validationTestHelper.assertError(dotAst, >+ DotPackage.eINSTANCE.getAttribute(), DotAttributes.SIDES__N, >+ "The value 'foo' is not a syntactically correct int: For input string: \"foo\"."); >+ >+ validationTestHelper.assertError(dotAst, >+ DotPackage.eINSTANCE.getAttribute(), DotAttributes.SIDES__N, >+ "The int value '-1' is not semantically correct: Value may not be smaller than 0."); >+ >+ // verify that this is the only reported issue >+ Assert.assertEquals(2, validationTestHelper.validate(dotAst).size()); >+ } >+ >+ @Test >+ public void testWrongNodeSkew() throws Exception { >+ String text = "graph { 1[skew=foo] 2[skew=\"-100.1\"]}"; >+ >+ DotAst dotAst = parserHelper.parse(text); >+ >+ validationTestHelper.assertError(dotAst, >+ DotPackage.eINSTANCE.getAttribute(), DotAttributes.SKEW__N, >+ "The value 'foo' is not a syntactically correct double: For input string: \"foo\"."); >+ >+ validationTestHelper.assertError(dotAst, >+ DotPackage.eINSTANCE.getAttribute(), DotAttributes.SKEW__N, >+ "The double value '-100.1' is not semantically correct: Value may not be smaller than -100.0"); >+ >+ // verify that this is the only reported issue >+ Assert.assertEquals(2, validationTestHelper.validate(dotAst).size()); >+ } >+ > private DotAst parse(String fileName) { > DotAst dotAst = null; > String fileContents = DotFileUtils >diff --git a/org.eclipse.gef4.dot.ui/src/org/eclipse/gef4/dot/internal/parser/ui/DotShapeUiModule.java b/org.eclipse.gef4.dot.ui/src/org/eclipse/gef4/dot/internal/parser/ui/DotShapeUiModule.java >new file mode 100644 >index 0000000..981f414 >--- /dev/null >+++ b/org.eclipse.gef4.dot.ui/src/org/eclipse/gef4/dot/internal/parser/ui/DotShapeUiModule.java >@@ -0,0 +1,15 @@ >+/* >+ * generated by Xtext >+ */ >+package org.eclipse.gef4.dot.internal.parser.ui; >+ >+import org.eclipse.ui.plugin.AbstractUIPlugin; >+ >+/** >+ * Use this class to register components to be used within the IDE. >+ */ >+public class DotShapeUiModule extends org.eclipse.gef4.dot.internal.parser.ui.AbstractDotShapeUiModule { >+ public DotShapeUiModule(AbstractUIPlugin plugin) { >+ super(plugin); >+ } >+} >diff --git a/org.eclipse.gef4.dot/META-INF/MANIFEST.MF b/org.eclipse.gef4.dot/META-INF/MANIFEST.MF >index c1eb90b..6f4a5d7 100644 >--- a/org.eclipse.gef4.dot/META-INF/MANIFEST.MF >+++ b/org.eclipse.gef4.dot/META-INF/MANIFEST.MF >@@ -24,7 +24,6 @@ > org.eclipse.gef4.dot.internal.parser.arrowtype.util;x-friends:="org.eclipse.gef4.dot.tests,org.eclipse.gef4.dot.ui", > org.eclipse.gef4.dot.internal.parser.conversion;x-friends:="org.eclipse.gef4.dot.tests,org.eclipse.gef4.dot.ui", > org.eclipse.gef4.dot.internal.parser.dir;x-friends:="org.eclipse.gef4.dot.tests,org.eclipse.gef4.dot.ui", >- org.eclipse.gef4.dot.internal.parser.rankdir;x-friends:="org.eclipse.gef4.dot.tests,org.eclipse.gef4.dot.ui", > org.eclipse.gef4.dot.internal.parser.dot;x-friends:="org.eclipse.gef4.dot.tests,org.eclipse.gef4.dot.ui", > org.eclipse.gef4.dot.internal.parser.dot.impl;x-friends:="org.eclipse.gef4.dot.tests,org.eclipse.gef4.dot.ui", > org.eclipse.gef4.dot.internal.parser.dot.util;x-friends:="org.eclipse.gef4.dot.tests,org.eclipse.gef4.dot.ui", >@@ -35,9 +34,13 @@ > org.eclipse.gef4.dot.internal.parser.point;x-friends:="org.eclipse.gef4.dot.tests,org.eclipse.gef4.dot.ui", > org.eclipse.gef4.dot.internal.parser.point.impl;x-friends:="org.eclipse.gef4.dot.tests,org.eclipse.gef4.dot.ui", > org.eclipse.gef4.dot.internal.parser.point.util;x-friends:="org.eclipse.gef4.dot.tests,org.eclipse.gef4.dot.ui", >+ org.eclipse.gef4.dot.internal.parser.rankdir;x-friends:="org.eclipse.gef4.dot.tests,org.eclipse.gef4.dot.ui", > org.eclipse.gef4.dot.internal.parser.scoping;x-friends:="org.eclipse.gef4.dot.tests,org.eclipse.gef4.dot.ui", > org.eclipse.gef4.dot.internal.parser.serializer;x-friends:="org.eclipse.gef4.dot.tests,org.eclipse.gef4.dot.ui", > org.eclipse.gef4.dot.internal.parser.services;x-friends:="org.eclipse.gef4.dot.tests,org.eclipse.gef4.dot.ui", >+ org.eclipse.gef4.dot.internal.parser.shape;x-friends:="org.eclipse.gef4.dot.tests,org.eclipse.gef4.dot.ui", >+ org.eclipse.gef4.dot.internal.parser.shape.impl;x-friends:="org.eclipse.gef4.dot.tests,org.eclipse.gef4.dot.ui", >+ org.eclipse.gef4.dot.internal.parser.shape.util;x-friends:="org.eclipse.gef4.dot.tests,org.eclipse.gef4.dot.ui", > org.eclipse.gef4.dot.internal.parser.splinetype;x-friends:="org.eclipse.gef4.dot.tests,org.eclipse.gef4.dot.ui", > org.eclipse.gef4.dot.internal.parser.splinetype.impl;x-friends:="org.eclipse.gef4.dot.tests,org.eclipse.gef4.dot.ui", > org.eclipse.gef4.dot.internal.parser.splinetype.util;x-friends:="org.eclipse.gef4.dot.tests,org.eclipse.gef4.dot.ui", >diff --git a/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/DotAttributes.java b/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/DotAttributes.java >index 83640de..01f0273 100644 >--- a/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/DotAttributes.java >+++ b/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/DotAttributes.java >@@ -10,6 +10,7 @@ > * Matthias Wienand (itemis AG) - initial API and implementation > * Alexander NyÃen (itemis AG) - initial API and implementation > * Tamas Miklossy (itemis AG) - Add support for arrowType edge decorations (bug #477980) >+ * - Add support for polygon-based node shapes (bug #441352) > * > *******************************************************************************/ > package org.eclipse.gef4.dot.internal; >@@ -28,6 +29,7 @@ > import org.eclipse.gef4.dot.internal.parser.dot.GraphType; > import org.eclipse.gef4.dot.internal.parser.point.Point; > import org.eclipse.gef4.dot.internal.parser.rankdir.Rankdir; >+import org.eclipse.gef4.dot.internal.parser.shape.Shape; > import org.eclipse.gef4.dot.internal.parser.splinetype.SplineType; > import org.eclipse.gef4.dot.internal.parser.validation.DotJavaValidator; > import org.eclipse.gef4.dot.internal.parser.validation.DotJavaValidator.AttributeContext; >@@ -102,6 +104,11 @@ > * Specifies the 'dir' attribute of an edge. > */ > public static final String DIR__E = "dir"; >+ >+ /** >+ * Specifies the 'distortion' attribute of a node. >+ */ >+ public static final String DISTORTION__N = "distortion"; > > /** > * Specifies the 'forceLabels' attribute of a graph. >@@ -217,6 +224,21 @@ > * which is used for laying out the graph. > */ > public static final String RANKDIR__G = "rankdir"; >+ >+ /** >+ * Specifies the 'shape' attribute of a node. >+ */ >+ public static final String SHAPE__N = "shape"; >+ >+ /** >+ * Specifies the 'sides' attribute of a node. >+ */ >+ public static final String SIDES__N = "sides"; >+ >+ /** >+ * Specifies the 'skew' attribute of a node. >+ */ >+ public static final String SKEW__N = "skew"; > > /** > * Specifies the name of the 'splines' attribute. It is used to control how >@@ -430,8 +452,7 @@ > * > * @param edge > * The {@link Edge} for which to return the value of the >- * {@link #ARROWSIZE__E} property, parsed as an {@link ArrowType} >- * . >+ * {@link #ARROWSIZE__E} property, parsed as a {@link Double} . > * > * @return The value of the {@link #ARROWSIZE__E} property of the given > * {@link Edge}. >@@ -499,6 +520,36 @@ > public static DirType getDirParsed(Edge edge) { > return DotLanguageSupport.parseAttributeValue( > DotLanguageSupport.DIRTYPE_PARSER, getDir(edge)); >+ } >+ >+ /** >+ * Returns the value of the {@link #DISTORTION__N} property of the given >+ * {@link Node}. >+ * >+ * @param node >+ * The {@link Node} for which to return the value of the >+ * {@link #DISTORTION__N} property. >+ * @return The value of the {@link #DISTORTION__N} property of the given >+ * {@link Node}. >+ */ >+ public static String getDistortion(Node node) { >+ return (String) node.attributesProperty().get(DISTORTION__N); >+ } >+ >+ /** >+ * Returns the (parsed) value of the {@link #DISTORTION__N} property of the >+ * given {@link Node}. >+ * >+ * @param node >+ * The {@link Node} for which to return the value of the >+ * {@link #DISTORTION__N} property, parsed as a {@link Double} . >+ * >+ * @return The value of the {@link #DISTORTION__N} property of the given >+ * {@link Node}. >+ */ >+ public static Double getDistortionParsed(Node node) { >+ return DotLanguageSupport.parseAttributeValue( >+ DotLanguageSupport.DOUBLE_PARSER, getDistortion(node)); > } > > /** >@@ -860,6 +911,95 @@ > } > > /** >+ * Returns the value of the {@link #SHAPE__N} property of the given >+ * {@link Node}. >+ * >+ * @param node >+ * The {@link Node} for which to return the value of the >+ * {@link #SHAPE__N} property. >+ * @return The value of the {@link #SHAPE__N} property of the given >+ * {@link Node}. >+ */ >+ public static String getShape(Node node) { >+ return (String) node.attributesProperty().get(SHAPE__N); >+ } >+ >+ /** >+ * Returns the (parsed) value of the {@link #SHAPE__N} property of the given >+ * {@link Node}. >+ * >+ * @param node >+ * The {@link Node} for which to return the value of the >+ * {@link #SHAPE__N} property, parsed as an {@link Shape} . >+ * @return The value of the {@link #SHAPE__N} property of the given >+ * {@link Node}. >+ */ >+ public static Shape getShapeParsed(Node node) { >+ return DotLanguageSupport.parseAttributeValue( >+ DotLanguageSupport.SHAPE_PARSER, getShape(node)); >+ } >+ >+ /** >+ * Returns the value of the {@link #SIDES__N} property of the given >+ * {@link Node}. >+ * >+ * @param node >+ * The {@link Node} for which to return the value of the >+ * {@link #SIDES__N} property. >+ * @return The value of the {@link #SIDES__N} property of the given >+ * {@link Node}. >+ */ >+ public static String getSides(Node node) { >+ return (String) node.attributesProperty().get(SIDES__N); >+ } >+ >+ /** >+ * Returns the (parsed) value of the {@link #SIDES__N} property of the given >+ * {@link Node}. >+ * >+ * @param node >+ * The {@link Node} for which to return the value of the >+ * {@link #SIDES__N} property, parsed as a {@link Integer} . >+ * >+ * @return The value of the {@link #SIDES__N} property of the given >+ * {@link Node}. >+ */ >+ public static Integer getSidesParsed(Node node) { >+ return DotLanguageSupport.parseAttributeValue( >+ DotLanguageSupport.INT_PARSER, getSides(node)); >+ } >+ >+ /** >+ * Returns the value of the {@link #SKEW__N} property of the given >+ * {@link Node}. >+ * >+ * @param node >+ * The {@link Node} for which to return the value of the >+ * {@link #SKEW__N} property. >+ * @return The value of the {@link #SKEW__N} property of the given >+ * {@link Node}. >+ */ >+ public static String getSkew(Node node) { >+ return (String) node.attributesProperty().get(SKEW__N); >+ } >+ >+ /** >+ * Returns the (parsed) value of the {@link #SKEW__N} property of the given >+ * {@link Node}. >+ * >+ * @param node >+ * The {@link Node} for which to return the value of the >+ * {@link #SKEW__N} property, parsed as a {@link Double} . >+ * >+ * @return The value of the {@link #SKEW__N} property of the given >+ * {@link Node}. >+ */ >+ public static Double getSkewParsed(Node node) { >+ return DotLanguageSupport.parseAttributeValue( >+ DotLanguageSupport.DOUBLE_PARSER, getSkew(node)); >+ } >+ >+ /** > * Returns the value of the {@link #SPLINES__G} attribute of the given > * {@link Graph}. > * >@@ -1193,6 +1333,35 @@ > */ > public static void setDirParsed(Edge edge, DirType dirParsed) { > setDir(edge, dirParsed.toString()); >+ } >+ >+ /** >+ * Sets the {@link #DISTORTION__N} property of the given {@link Node} to the >+ * given <i>distortion</i> value. >+ * >+ * @param node >+ * The {@link Node} for which to change the value of the >+ * {@link #DISTORTION__N} property. >+ * @param distortion >+ * The new value for the {@link #DISTORTION__N} property. >+ */ >+ public static void setDistortion(Node node, String distortion) { >+ validate(AttributeContext.NODE, DISTORTION__N, distortion); >+ node.attributesProperty().put(DISTORTION__N, distortion); >+ } >+ >+ /** >+ * Sets the {@link #DISTORTION__N} property of the given {@link Node} to the >+ * given <i>distortion</i> value. >+ * >+ * @param node >+ * The {@link Node} for which to change the value of the >+ * {@link #DISTORTION__N} property. >+ * @param distortionParsed >+ * The new value for the {@link #DISTORTION__N} property. >+ */ >+ public static void setDistortionParsed(Node node, Double distortionParsed) { >+ setSkew(node, distortionParsed.toString()); > } > > /** >@@ -1537,6 +1706,94 @@ > } > > /** >+ * Sets the {@link #SIDES__N} property of the given {@link Node} to the >+ * given <i>sides</i> value. >+ * >+ * @param node >+ * The {@link Node} for which to change the value of the >+ * {@link #SIDES__N} property. >+ * @param sides >+ * The new value for the {@link #SIDES__N} property. >+ */ >+ public static void setSides(Node node, String sides) { >+ validate(AttributeContext.NODE, SIDES__N, sides); >+ node.attributesProperty().put(SIDES__N, sides); >+ } >+ >+ /** >+ * Sets the {@link #SIDES__N} property of the given {@link Node} to the >+ * given <i>sides</i> value. >+ * >+ * @param node >+ * The {@link Node} for which to change the value of the >+ * {@link #SIDES__N} property. >+ * @param sidesParsed >+ * The new value for the {@link #SIDES__N} property. >+ */ >+ public static void setSidesParsed(Node node, Integer sidesParsed) { >+ setSides(node, sidesParsed.toString()); >+ } >+ >+ /** >+ * Sets the {@link #SHAPE__N} property of the given {@link Node} to the >+ * given <i>shape</i> value. >+ * >+ * @param node >+ * The {@link Node} for which to change the value of the >+ * {@link #SHAPE__N} property. >+ * @param shape >+ * The new value for the {@link #SHAPE__N} property. >+ */ >+ public static void setShape(Node node, String shape) { >+ validate(AttributeContext.NODE, SHAPE__N, shape); >+ node.attributesProperty().put(SHAPE__N, shape); >+ } >+ >+ /** >+ * Sets the {@link #SHAPE__N} property of the given {@link Node} to the >+ * given <i>shape</i> value. >+ * >+ * @param node >+ * The {@link Node} for which to change the value of the >+ * {@link #SHAPE__N} property. >+ * @param shapeParsed >+ * The new value for the {@link #SHAPE__N} property. >+ */ >+ public static void setShapeParsed(Node node, Shape shapeParsed) { >+ setShape(node, >+ serialize(DotLanguageSupport.SHAPE_SERIALIZER, shapeParsed)); >+ } >+ >+ /** >+ * Sets the {@link #SKEW__N} property of the given {@link Node} to the given >+ * <i>skew</i> value. >+ * >+ * @param node >+ * The {@link Node} for which to change the value of the >+ * {@link #SKEW__N} property. >+ * @param skew >+ * The new value for the {@link #SKEW__N} property. >+ */ >+ public static void setSkew(Node node, String skew) { >+ validate(AttributeContext.NODE, SKEW__N, skew); >+ node.attributesProperty().put(SKEW__N, skew); >+ } >+ >+ /** >+ * Sets the {@link #SKEW__N} property of the given {@link Node} to the given >+ * <i>skew</i> value. >+ * >+ * @param node >+ * The {@link Node} for which to change the value of the >+ * {@link #SKEW__N} property. >+ * @param skewParsed >+ * The new value for the {@link #SKEW__N} property. >+ */ >+ public static void setSkewParsed(Node node, Double skewParsed) { >+ setSkew(node, skewParsed.toString()); >+ } >+ >+ /** > * Sets the {@link #SPLINES__G} attribute of the given {@link Graph} to the > * given value. > * >diff --git a/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/DotInterpreter.java b/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/DotInterpreter.java >index bd210fc..ab64aae 100644 >--- a/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/DotInterpreter.java >+++ b/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/DotInterpreter.java >@@ -10,6 +10,7 @@ > * Fabian Steeg - initial API and implementation (bug #277380) > * Alexander NyÃen (itemis AG) - several refactorings and additions (bugs #487081, #489793) > * Tamas Miklossy (itemis AG) - support for arrowType edge decorations (bug #477980) >+ * - support for polygon-based node shapes (bug #441352) > * > *******************************************************************************/ > >@@ -216,6 +217,13 @@ > // name (from grammar definition, not attribute) > Node node = node(escaped(nodeStmt.getNode().getName())); > >+ // distortion >+ String distortion = getAttributeValue(nodeStmt, >+ DotAttributes.DISTORTION__N); >+ if (distortion != null) { >+ DotAttributes.setDistortion(node, distortion); >+ } >+ > // id > String id = getAttributeValue(nodeStmt, DotAttributes.ID__GNE); > if (id != null) { >@@ -257,6 +265,24 @@ > if (height != null) { > DotAttributes.setHeight(node, height); > } >+ >+ // shape >+ String shape = getAttributeValue(nodeStmt, DotAttributes.SHAPE__N); >+ if (shape != null) { >+ DotAttributes.setShape(node, shape); >+ } >+ >+ // sides >+ String sides = getAttributeValue(nodeStmt, DotAttributes.SIDES__N); >+ if (sides != null) { >+ DotAttributes.setSides(node, sides); >+ } >+ >+ // skew >+ String skew = getAttributeValue(nodeStmt, DotAttributes.SKEW__N); >+ if (skew != null) { >+ DotAttributes.setSkew(node, skew); >+ } > return super.caseNodeStmt(nodeStmt); > } > >diff --git a/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/DotLanguageSupport.java b/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/DotLanguageSupport.java >index a354556..4424906 100644 >--- a/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/DotLanguageSupport.java >+++ b/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/DotLanguageSupport.java >@@ -8,6 +8,7 @@ > * > * Contributors: > * Alexander NyÃen (itemis AG) - initial API and implementation >+ * Tamas Miklossy (itemis AG) - Add support for polygon-based node shapes (bug #441352) > * > *******************************************************************************/ > package org.eclipse.gef4.dot.internal; >@@ -20,14 +21,17 @@ > import org.eclipse.emf.common.util.Diagnostic; > import org.eclipse.gef4.dot.internal.parser.DotArrowTypeStandaloneSetup; > import org.eclipse.gef4.dot.internal.parser.DotPointStandaloneSetup; >+import org.eclipse.gef4.dot.internal.parser.DotShapeStandaloneSetup; > import org.eclipse.gef4.dot.internal.parser.DotSplineTypeStandaloneSetup; > import org.eclipse.gef4.dot.internal.parser.dir.DirType; > import org.eclipse.gef4.dot.internal.parser.parser.antlr.DotArrowTypeParser; > import org.eclipse.gef4.dot.internal.parser.parser.antlr.DotPointParser; >+import org.eclipse.gef4.dot.internal.parser.parser.antlr.DotShapeParser; > import org.eclipse.gef4.dot.internal.parser.parser.antlr.DotSplineTypeParser; > import org.eclipse.gef4.dot.internal.parser.rankdir.Rankdir; > import org.eclipse.gef4.dot.internal.parser.validation.DotArrowTypeJavaValidator; > import org.eclipse.gef4.dot.internal.parser.validation.DotPointJavaValidator; >+import org.eclipse.gef4.dot.internal.parser.validation.DotShapeJavaValidator; > import org.eclipse.gef4.dot.internal.parser.validation.DotSplineTypeJavaValidator; > import org.eclipse.xtext.parser.IParseResult; > import org.eclipse.xtext.parser.IParser; >@@ -255,6 +259,29 @@ > } > }; > >+ /** >+ * A parser used to parse DOT int values. >+ */ >+ public static IPrimitiveValueParser<Integer> INT_PARSER = new IPrimitiveValueParser<Integer>() { >+ >+ @Override >+ public IPrimitiveValueParseResult<Integer> parse(String rawValue) { >+ if (rawValue == null) { >+ return null; >+ } >+ try { >+ int parsedValue = Integer.parseInt(rawValue); >+ return new PrimitiveValueParseResultImpl<>( >+ new Integer(parsedValue)); >+ } catch (NumberFormatException exception) { >+ return new PrimitiveValueParseResultImpl<>(Collections >+ .<Diagnostic> singletonList(new BasicDiagnostic( >+ Diagnostic.ERROR, rawValue, -1, >+ exception.getMessage(), new Object[] {}))); >+ } >+ } >+ }; >+ > private static final Injector arrowTypeInjector = new DotArrowTypeStandaloneSetup() > .createInjectorAndDoEMFRegistration(); > >@@ -298,6 +325,28 @@ > public static final DotPointJavaValidator POINT_VALIDATOR = pointInjector > .getInstance(DotPointJavaValidator.class); > >+ private static final Injector shapeInjector = new DotShapeStandaloneSetup() >+ .createInjectorAndDoEMFRegistration(); >+ >+ /** >+ * The validator for shape attribute values. >+ */ >+ // TODO: move to dotjavaValidator >+ public static final DotShapeJavaValidator SHAPE_VALIDATOR = shapeInjector >+ .getInstance(DotShapeJavaValidator.class); >+ >+ /** >+ * The parser for shape attribute values. >+ */ >+ public static final DotShapeParser SHAPE_PARSER = shapeInjector >+ .getInstance(DotShapeParser.class); >+ >+ /** >+ * The serializer for shape attribute values. >+ */ >+ public static final ISerializer SHAPE_SERIALIZER = shapeInjector >+ .getInstance(ISerializer.class); >+ > private static final Injector splineTypeInjector = new DotSplineTypeStandaloneSetup() > .createInjectorAndDoEMFRegistration(); > >diff --git a/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/parser/DotShape.xtext b/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/parser/DotShape.xtext >new file mode 100644 >index 0000000..d7d9f82 >--- /dev/null >+++ b/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/parser/DotShape.xtext >@@ -0,0 +1,35 @@ >+/******************************************************************************* >+ * Copyright (c) 2016 itemis AG and others. >+ * >+ * 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: >+ * Tamas Miklossy (itemis AG) - initial API and implementation (bug #441352) >+ * >+ *******************************************************************************/ >+grammar org.eclipse.gef4.dot.internal.parser.DotShape >+ >+generate shape "http://www.eclipse.org/gef4/dot/internal/parser/DotShape" >+import "http://www.eclipse.org/emf/2002/Ecore" as ecore >+ >+Shape: >+ shape = (PolygonBasedShape | RecordBasedShape); >+ >+PolygonBasedShape: >+ shape = PolygonBasedNodeShape; >+ >+RecordBasedShape: >+ shape = RecordBasedNodeShape; >+ >+enum PolygonBasedNodeShape: >+ box | polygon | ellipse | oval | circle | point | egg | triangle | plaintext | plain | diamond | trapezium | parallelogram | house | >+ pentagon | hexagon | septagon | octagon | doublecircle | doubleoctagon | tripleoctagon | invtriangle | invtrapezium | invhouse | >+ Mdiamond | Msquare | Mcircle | rect | rectangle | square | star | none | underline | cylinder | note | tab | folder | box3d | >+ component | promoter | cds | terminator | utr | primersite | restrictionsite | fivepoverhang | threepoverhang | noverhang | >+ assembly |signature | insulator | ribosite | rnastab | proteasesite | proteinstab | rpromoter | rarrow | larrow | lpromoter; >+ >+enum RecordBasedNodeShape: >+ record | Mrecord; >\ No newline at end of file >diff --git a/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/parser/DotShapeRuntimeModule.java b/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/parser/DotShapeRuntimeModule.java >new file mode 100644 >index 0000000..3dc83a8 >--- /dev/null >+++ b/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/parser/DotShapeRuntimeModule.java >@@ -0,0 +1,11 @@ >+/* >+ * generated by Xtext >+ */ >+package org.eclipse.gef4.dot.internal.parser; >+ >+/** >+ * Use this class to register components to be used at runtime / without the Equinox extension registry. >+ */ >+public class DotShapeRuntimeModule extends org.eclipse.gef4.dot.internal.parser.AbstractDotShapeRuntimeModule { >+ >+} >diff --git a/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/parser/DotShapeStandaloneSetup.java b/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/parser/DotShapeStandaloneSetup.java >new file mode 100644 >index 0000000..f377679 >--- /dev/null >+++ b/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/parser/DotShapeStandaloneSetup.java >@@ -0,0 +1,16 @@ >+/* >+ * generated by Xtext >+ */ >+package org.eclipse.gef4.dot.internal.parser; >+ >+/** >+ * Initialization support for running Xtext languages >+ * without equinox extension registry >+ */ >+public class DotShapeStandaloneSetup extends DotShapeStandaloneSetupGenerated{ >+ >+ public static void doSetup() { >+ new DotShapeStandaloneSetup().createInjectorAndDoEMFRegistration(); >+ } >+} >+ >diff --git a/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/parser/GenerateDot.mwe2 b/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/parser/GenerateDot.mwe2 >index 564baf2..c6d0d2e 100644 >--- a/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/parser/GenerateDot.mwe2 >+++ b/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/parser/GenerateDot.mwe2 >@@ -11,6 +11,7 @@ > * integration of attribute grammars > * Tamas Miklossy - support for junit test plugin generation > * - support for formatter API generation >+ * - integration of shape attribute grammar > *******************************************************************************/ > module org.eclipse.gef4.dot.internal.parser.Dot > >@@ -202,5 +203,36 @@ > // generates junit test support classes into Generator#pathTestProject > fragment = junit.Junit4Fragment auto-inject {} > } >+ language = auto-inject { >+ uri = "platform:/resource/${projectName}/src/org/eclipse/gef4/dot/internal/parser/DotShape.xtext"// Java API to access grammar elements (required by several other fragments) >+ fileExtensions = "dot_shape" >+ fragment = grammarAccess.GrammarAccessFragment auto-inject {} >+ >+ // a custom ResourceFactory for use with EMF >+ fragment = resourceFactory.ResourceFactoryFragment auto-inject {} >+ >+ // generates Java API for the generated EPackages >+ fragment = ecore.EMFGeneratorFragment auto-inject { >+ // has to be explicitly set for headless execution (Tycho) >+ javaModelDirectory = "/${projectName}/src-gen" >+ } >+ >+ // Java-based validator >+ fragment = validation.JavaValidatorFragment auto-inject {} >+ >+ // formatter API >+ fragment = formatting.FormatterFragment auto-inject {} >+ >+ // serializer 2.0 >+ fragment = serializer.SerializerFragment auto-inject { >+ generateStub = false >+ } >+ >+ // The antlr parser generator fragment >+ fragment = parser.antlr.XtextAntlrGeneratorFragment auto-inject {} >+ >+ // generates junit test support classes into Generator#pathTestProject >+ fragment = junit.Junit4Fragment auto-inject {} >+ } > } > } >diff --git a/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/parser/formatting/DotShapeFormatter.java b/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/parser/formatting/DotShapeFormatter.java >new file mode 100644 >index 0000000..f02e118 >--- /dev/null >+++ b/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/parser/formatting/DotShapeFormatter.java >@@ -0,0 +1,47 @@ >+/******************************************************************************* >+ * Copyright (c) 2016 itemis AG and others. >+ * >+ * 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: >+ * Tamas Miklossy (itemis AG) - initial implementation >+ * >+ *******************************************************************************/ >+ >+/* >+ * generated by Xtext >+ */ >+package org.eclipse.gef4.dot.internal.parser.formatting; >+ >+import org.eclipse.gef4.dot.internal.parser.services.DotShapeGrammarAccess; >+import org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter; >+import org.eclipse.xtext.formatting.impl.FormattingConfig; >+ >+import com.google.inject.Inject; >+ >+/** >+ * This class contains custom formatting declarations. >+ * >+ * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html# >+ * formatting on how and when to use it. >+ * >+ * Also see {@link org.eclipse.xtext.xtext.XtextFormattingTokenSerializer} as an >+ * example >+ */ >+public class DotShapeFormatter extends AbstractDeclarativeFormatter { >+ >+ @Inject >+ private DotShapeGrammarAccess grammarAccess; >+ >+ @Override >+ protected void configureFormatting(FormattingConfig c) { >+ // It's usually a good idea to activate the following three statements. >+ // They will add and preserve newlines around comments >+ // c.setLinewrap(0, 1, 2).before(grammarAccess.getSL_COMMENTRule()); >+ // c.setLinewrap(0, 1, 2).before(grammarAccess.getML_COMMENTRule()); >+ // c.setLinewrap(0, 1, 1).after(grammarAccess.getML_COMMENTRule()); >+ } >+} >diff --git a/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/parser/validation/DotJavaValidator.java b/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/parser/validation/DotJavaValidator.java >index e5310e0..4aef78c 100644 >--- a/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/parser/validation/DotJavaValidator.java >+++ b/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/parser/validation/DotJavaValidator.java >@@ -51,6 +51,7 @@ > import org.eclipse.gef4.dot.internal.parser.dot.NodeStmt; > import org.eclipse.gef4.dot.internal.parser.dot.Subgraph; > import org.eclipse.gef4.dot.internal.parser.point.PointPackage; >+import org.eclipse.gef4.dot.internal.parser.shape.ShapePackage; > import org.eclipse.gef4.dot.internal.parser.splinetype.SplinetypePackage; > import org.eclipse.xtext.nodemodel.INode; > import org.eclipse.xtext.parser.IParseResult; >@@ -207,6 +208,17 @@ > unquotedValue, SplinetypePackage.Literals.SPLINE_TYPE, > "splineType"); > } >+ } else if (DotAttributes.SHAPE__N.equals(name)) { >+ // validate shape using delegate parser and validator >+ return validateObjectAttributeValue(DotLanguageSupport.SHAPE_PARSER, >+ DotLanguageSupport.SHAPE_VALIDATOR, name, unquotedValue, >+ ShapePackage.Literals.SHAPE, "shape"); >+ } else if (DotAttributes.SIDES__N.equals(name)) { >+ return validateIntAttributeValue(name, unquotedValue, 0); >+ } else if (DotAttributes.SKEW__N.equals(name)) { >+ return validateDoubleAttributeValue(name, unquotedValue, -100.0); >+ } else if (DotAttributes.DISTORTION__N.equals(name)) { >+ return validateDoubleAttributeValue(name, unquotedValue, -100.0); > } else if (DotAttributes.ARROWSIZE__E.equals(name)) { > return validateDoubleAttributeValue(name, unquotedValue, 0.0); > } else if (DotAttributes.WIDTH__N.equals(name)) { >@@ -444,6 +456,31 @@ > } > } > >+ private List<Diagnostic> validateIntAttributeValue( >+ final String attributeName, String attributeValue, int minValue) { >+ // parse value >+ IPrimitiveValueParseResult<Integer> parseResult = DotLanguageSupport.INT_PARSER >+ .parse(attributeValue); >+ if (parseResult.hasSyntaxErrors()) { >+ return Collections.<Diagnostic> singletonList( >+ createSyntacticAttributeValueProblem(attributeValue, "int", >+ getFormattedSyntaxErrorMessages(parseResult), >+ attributeName)); >+ } else { >+ // validate value >+ if (parseResult.getParsedValue().intValue() < minValue) { >+ return Collections >+ .<Diagnostic> singletonList( >+ createSemanticAttributeValueProblem( >+ Diagnostic.ERROR, attributeValue, "int", >+ "Value may not be smaller than " >+ + minValue + ".", >+ attributeName)); >+ } >+ return Collections.emptyList(); >+ } >+ } >+ > private String getFormattedValues(Set<String> values) { > StringBuilder sb = new StringBuilder(); > for (String value : new TreeSet<>(values)) { >diff --git a/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/parser/validation/DotShapeJavaValidator.java b/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/parser/validation/DotShapeJavaValidator.java >new file mode 100644 >index 0000000..6747d9a >--- /dev/null >+++ b/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/parser/validation/DotShapeJavaValidator.java >@@ -0,0 +1,19 @@ >+/* >+ * generated by Xtext >+ */ >+package org.eclipse.gef4.dot.internal.parser.validation; >+ >+/** >+ * This class contains custom validation rules. >+ * >+ * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation >+ */ >+public class DotShapeJavaValidator extends org.eclipse.gef4.dot.internal.parser.validation.AbstractDotShapeJavaValidator { >+ >+// @Check >+// public void checkGreetingStartsWithCapital(Greeting greeting) { >+// if (!Character.isUpperCase(greeting.getName().charAt(0))) { >+// warning("Name should start with a capital", MyDslPackage.Literals.GREETING__NAME); >+// } >+// } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
nyssen
:
iplog+
Actions:
View
|
Diff
Attachments on
bug 441352
:
260865
| 260900