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;
}
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;
}
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);
}
}
}
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();
}
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;
}
}
Aggregations