Search in sources :

Example 6 with AgeGefRuntimeException

use of org.osate.ge.gef.AgeGefRuntimeException in project osate2 by osate.

the class GefDiagramExportService method getExportNodes.

/**
 * Returns a list of nodes to export. The nodes will be in draw order.
 * @param diagram the diagram being export
 * @param exportRootDiagramNode the root node being exported.
 * @return the list of nodes to export.
 */
private static List<Node> getExportNodes(final GefAgeDiagram diagram, final DiagramNode exportRootDiagramNode) {
    // final GefAgeDiagram diagram,
    final Node exportRootSceneNode = diagram.getSceneNode(exportRootDiagramNode);
    if (exportRootSceneNode == null) {
        throw new AgeGefRuntimeException("Unable to find scene node for specified diagram node");
    }
    final List<Node> exportNodes = new ArrayList<>();
    addNonConnectionExportNodes(exportRootSceneNode, exportNodes);
    addConnectionExportNodes(diagram.getSceneNode(), exportRootSceneNode, exportNodes);
    return exportNodes;
}
Also used : BaseConnectionNode(org.osate.ge.gef.BaseConnectionNode) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) Node(javafx.scene.Node) ArrayList(java.util.ArrayList) AgeGefRuntimeException(org.osate.ge.gef.AgeGefRuntimeException)

Example 7 with AgeGefRuntimeException

use of org.osate.ge.gef.AgeGefRuntimeException in project osate2 by osate.

the class GefDiagramExportService method toAwt.

private static Path2D.Double toAwt(final Path p) {
    final Path2D.Double result = new Path2D.Double(p.getFillRule() == FillRule.EVEN_ODD ? Path2D.WIND_EVEN_ODD : Path2D.WIND_NON_ZERO, p.getElements().size());
    double lastX = 0;
    double lastY = 0;
    for (final PathElement e : p.getElements()) {
        if (e instanceof ClosePath) {
            result.closePath();
        } else if (e instanceof HLineTo) {
            final HLineTo el = (HLineTo) e;
            lastX = el.getX();
            result.lineTo(lastX, lastY);
        } else if (e instanceof VLineTo) {
            final VLineTo el = (VLineTo) e;
            lastY = el.getY();
            result.lineTo(lastX, lastY);
        } else if (e instanceof LineTo) {
            final LineTo el = (LineTo) e;
            lastX = el.getX();
            lastY = el.getY();
            result.lineTo(lastX, lastY);
        } else if (e instanceof MoveTo) {
            final MoveTo el = (MoveTo) e;
            lastX = el.getX();
            lastY = el.getY();
            result.moveTo(lastX, lastY);
        } else if (e instanceof CubicCurveTo) {
            final CubicCurveTo el = (CubicCurveTo) e;
            lastX = el.getX();
            lastY = el.getY();
            result.curveTo(el.getControlX1(), el.getControlY1(), el.getControlX2(), el.getControlY2(), lastX, lastY);
        } else if (e instanceof QuadCurveTo) {
            final QuadCurveTo el = (QuadCurveTo) e;
            lastX = el.getX();
            lastY = el.getY();
            result.quadTo(el.getControlX(), el.getControlY(), lastX, lastY);
        } else if (e instanceof ArcTo) {
            // If ArcTo is used it will need to be implemented.
            throw new AgeGefRuntimeException("Exporting ArcTo path segments is not supported.");
        } else {
            throw new AgeGefRuntimeException("Unexpected path element: " + e);
        }
    }
    return result;
}
Also used : LineTo(javafx.scene.shape.LineTo) VLineTo(javafx.scene.shape.VLineTo) HLineTo(javafx.scene.shape.HLineTo) ArcTo(javafx.scene.shape.ArcTo) VLineTo(javafx.scene.shape.VLineTo) Path2D(java.awt.geom.Path2D) CubicCurveTo(javafx.scene.shape.CubicCurveTo) ClosePath(javafx.scene.shape.ClosePath) PathElement(javafx.scene.shape.PathElement) MoveTo(javafx.scene.shape.MoveTo) QuadCurveTo(javafx.scene.shape.QuadCurveTo) HLineTo(javafx.scene.shape.HLineTo) AgeGefRuntimeException(org.osate.ge.gef.AgeGefRuntimeException)

Example 8 with AgeGefRuntimeException

use of org.osate.ge.gef.AgeGefRuntimeException in project osate2 by osate.

the class GefDiagramExportService method draw.

private static void draw(final List<Node> exportNodes, final Transform sceneToExportTransform, final double scaling, final Graphics2D g2d) {
    // Set rendering options
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    // Scale all drawing
    g2d.scale(scaling, scaling);
    for (final Node node : exportNodes) {
        // Create a new graphics object which uses the node's coordinate system
        final Graphics2D tg = (Graphics2D) g2d.create();
        final Transform nodeToDiagramTransform = sceneToExportTransform.createConcatenation(node.getLocalToSceneTransform());
        tg.transform(new AffineTransform(nodeToDiagramTransform.getMxx(), nodeToDiagramTransform.getMyx(), nodeToDiagramTransform.getMxy(), nodeToDiagramTransform.getMyy(), nodeToDiagramTransform.getTx(), nodeToDiagramTransform.getTy()));
        // Draw the node
        if (node instanceof Path) {
            final Path n = (Path) node;
            draw(toAwt(n), tg, toAwt(n.getFill()), toAwt(n.getStroke()), (float) n.getStrokeWidth(), n.getStrokeDashArray());
        } else if (node instanceof javafx.scene.shape.Rectangle) {
            final javafx.scene.shape.Rectangle n = (javafx.scene.shape.Rectangle) node;
            draw(toAwt(n), tg, toAwt(n.getFill()), toAwt(n.getStroke()), (float) n.getStrokeWidth(), n.getStrokeDashArray());
        } else if (node instanceof javafx.scene.shape.Circle) {
            final javafx.scene.shape.Circle n = (javafx.scene.shape.Circle) node;
            draw(toAwt(n), tg, toAwt(n.getFill()), toAwt(n.getStroke()), (float) n.getStrokeWidth(), n.getStrokeDashArray());
        } else if (node instanceof javafx.scene.shape.Ellipse) {
            final javafx.scene.shape.Ellipse n = (javafx.scene.shape.Ellipse) node;
            draw(toAwt(n), tg, toAwt(n.getFill()), toAwt(n.getStroke()), (float) n.getStrokeWidth(), n.getStrokeDashArray());
        } else if (node instanceof CubicCurve) {
            // Draw unfilled curve
            final CubicCurve n = (CubicCurve) node;
            draw(toAwt(n), tg, null, toAwt(n.getStroke()), (float) n.getStrokeWidth(), n.getStrokeDashArray());
        } else if (node instanceof Polygon) {
            final javafx.scene.shape.Polygon n = (javafx.scene.shape.Polygon) node;
            draw(toAwtPath(n.getPoints(), true), tg, toAwt(n.getFill()), toAwt(n.getStroke()), (float) n.getStrokeWidth(), n.getStrokeDashArray());
        } else if (node instanceof Polyline) {
            final javafx.scene.shape.Polyline n = (javafx.scene.shape.Polyline) node;
            // Draw unfilled polyline
            draw(toAwtPath(n.getPoints(), false), tg, null, toAwt(n.getStroke()), (float) n.getStrokeWidth(), n.getStrokeDashArray());
        } else if (node instanceof Text) {
            draw((Text) node, tg);
        } else if (node instanceof ImageView) {
            draw((ImageView) node, tg);
        } else if (node instanceof Region) {
            draw((Region) node, tg);
        } else {
            throw new AgeGefRuntimeException("Unexpected export node: " + node);
        }
    }
}
Also used : ClosePath(javafx.scene.shape.ClosePath) Path(javafx.scene.shape.Path) Circle(javafx.scene.shape.Circle) Ellipse(javafx.scene.shape.Ellipse) Ellipse(javafx.scene.shape.Ellipse) BaseConnectionNode(org.osate.ge.gef.BaseConnectionNode) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) Node(javafx.scene.Node) Rectangle(java.awt.Rectangle) Text(javafx.scene.text.Text) Polyline(javafx.scene.shape.Polyline) Graphics2D(java.awt.Graphics2D) SVGGraphics2D(org.apache.batik.svggen.SVGGraphics2D) CubicCurve(javafx.scene.shape.CubicCurve) Polyline(javafx.scene.shape.Polyline) AffineTransform(java.awt.geom.AffineTransform) Region(javafx.scene.layout.Region) ImageView(javafx.scene.image.ImageView) AgeGefRuntimeException(org.osate.ge.gef.AgeGefRuntimeException) Transform(javafx.scene.transform.Transform) AffineTransform(java.awt.geom.AffineTransform) Circle(javafx.scene.shape.Circle) Polygon(javafx.scene.shape.Polygon)

Example 9 with AgeGefRuntimeException

use of org.osate.ge.gef.AgeGefRuntimeException in project osate2 by osate.

the class AgeEditor method setInput.

@Override
protected void setInput(final IEditorInput input) {
    if (!(input instanceof IFileEditorInput)) {
        throw new AgeGefRuntimeException("Input must implement " + IFileEditorInput.class.getName());
    }
    super.setInput(input);
    final IFileEditorInput fileInput = (IFileEditorInput) input;
    this.diagramFile = fileInput.getFile();
    this.setPartName(this.diagramFile.getName());
    this.project = this.diagramFile.getProject();
}
Also used : IFileEditorInput(org.eclipse.ui.IFileEditorInput) AgeGefRuntimeException(org.osate.ge.gef.AgeGefRuntimeException)

Example 10 with AgeGefRuntimeException

use of org.osate.ge.gef.AgeGefRuntimeException in project osate2 by osate.

the class AgeEditor method doSave.

@Override
public void doSave(final IProgressMonitor monitor) {
    try {
        if (diagramFile == null) {
            throw new AgeGefRuntimeException("diagram file is null");
        }
        // Handle the diagram being read-only
        if (diagramFile.isReadOnly()) {
            final IStatus status = ResourcesPlugin.getWorkspace().validateEdit(new IFile[] { diagramFile }, getSite().getShell());
            if (status.matches(IStatus.CANCEL) || !status.isOK() || diagramFile.isReadOnly()) {
                Display.getDefault().syncExec(() -> monitor.setCanceled(true));
                // Display error message in a subset of cases
                if (!status.isOK()) {
                    StatusManager.getManager().handle(status, StatusManager.SHOW);
                } else if (diagramFile.isReadOnly()) {
                    StatusManager.getManager().handle(new Status(IStatus.ERROR, AgeGefUiPlugin.PLUGIN_ID, "Diagram is read-only"), StatusManager.SHOW);
                }
                return;
            }
        }
        // Save the file
        DiagramSerialization.write(getProject(), diagram, URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true));
        // Clear Ghosts
        diagramUpdater.clearGhosts();
        // Store current change number
        cleanDiagramChangeNumber = diagram.getCurrentChangeNumber();
        fireDirtyPropertyChangeEvent();
    } catch (final Exception e) {
        Status errorStatus = new Status(IStatus.ERROR, AgeGefUiPlugin.PLUGIN_ID, 0, e.getMessage(), e);
        Display.getDefault().asyncExec(() -> new ErrorDialog(Display.getDefault().getActiveShell(), "Error Saving Diagram", "Unable to save diagram.", errorStatus, IStatus.ERROR).open());
        throw e;
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IStatus(org.eclipse.core.runtime.IStatus) ErrorDialog(org.eclipse.jface.dialogs.ErrorDialog) AgeGefRuntimeException(org.osate.ge.gef.AgeGefRuntimeException) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) AgeGefRuntimeException(org.osate.ge.gef.AgeGefRuntimeException)

Aggregations

AgeGefRuntimeException (org.osate.ge.gef.AgeGefRuntimeException)10 BaseConnectionNode (org.osate.ge.gef.BaseConnectionNode)5 Node (javafx.scene.Node)3 FlowIndicatorNode (org.osate.ge.gef.FlowIndicatorNode)3 DiagramNode (org.osate.ge.internal.diagram.runtime.DiagramNode)3 ClosePath (javafx.scene.shape.ClosePath)2 Transform (javafx.scene.transform.Transform)2 CoreException (org.eclipse.core.runtime.CoreException)2 ConnectionNode (org.osate.ge.gef.ConnectionNode)2 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)2 Graphics2D (java.awt.Graphics2D)1 Rectangle (java.awt.Rectangle)1 AffineTransform (java.awt.geom.AffineTransform)1 Path2D (java.awt.geom.Path2D)1 ArrayList (java.util.ArrayList)1 Group (javafx.scene.Group)1 ImageView (javafx.scene.image.ImageView)1 Region (javafx.scene.layout.Region)1 ArcTo (javafx.scene.shape.ArcTo)1 Circle (javafx.scene.shape.Circle)1