use of org.osate.ge.internal.GraphicalEditorException in project osate2 by osate.
the class DiagramElementLayoutUtil method findMidpoint.
private static Point findMidpoint(final List<Point> points) {
if (points.size() < 2) {
throw new IllegalArgumentException("At least two points must be specified");
}
final double totalLength = length(points);
double lengthToTarget = totalLength / 2.0;
for (int i = 1; i < points.size(); i++) {
final Point p1 = points.get(i - 1);
final Point p2 = points.get(i);
final double segmentLength = length(p1, p2);
if (lengthToTarget > segmentLength) {
lengthToTarget -= segmentLength;
} else {
final double frac = lengthToTarget / segmentLength;
return new Point(p1.x + (p2.x - p1.x) * frac, p1.y + (p2.y - p1.y) * frac);
}
}
throw new GraphicalEditorException("Unexpected case: midpoint not found");
}
use of org.osate.ge.internal.GraphicalEditorException in project osate2 by osate.
the class DiagramElementLayoutUtil method layout.
/**
* Performs a layout of the specified diagram nodes
* @param actionLabel description of the action
* @param editor the editor containing the diagram
* @param diagramNodes the nodes to layout. If null, the entire diagram will be laid out
* @param options the layout options
*/
public static void layout(final String actionLabel, final IEditorPart editor, final Collection<? extends DiagramNode> diagramNodes, final LayoutOptions options) {
if (!(editor instanceof InternalDiagramEditor)) {
throw new GraphicalEditorException("Editor must be an " + InternalDiagramEditor.class.getName());
}
final InternalDiagramEditor diagramEditor = ((InternalDiagramEditor) editor);
final LayoutInfoProvider layoutInfoProvider = Adapters.adapt(diagramEditor, LayoutInfoProvider.class);
layout(actionLabel, diagramEditor.getDiagram(), diagramNodes, layoutInfoProvider, options);
}
use of org.osate.ge.internal.GraphicalEditorException in project osate2 by osate.
the class LayoutDebugUtil method saveElkGraphToDebugProject.
/**
* When {@link #SAVE_GRAPH_ENABLED} is true, saves the ELK graph to a file in the {@link #MAGIC_PROJECT_NAME} project.
* @param g the graph to safe
* @param suffix an identifier to add to the name of the file.
*/
public static void saveElkGraphToDebugProject(final ElkNode g, final String suffix) {
if (SAVE_GRAPH_ENABLED) {
final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(MAGIC_PROJECT_NAME);
if (project != null && project.exists()) {
final URI uri = URI.createPlatformResourceURI(project.getFile("layout_graph_" + suffix + ".elkg").getFullPath().toString(), true);
// Save the resource
final ResourceSet rs = new ResourceSetImpl();
final Resource resource = rs.createResource(uri);
resource.getContents().add(g);
try {
resource.save(Collections.emptyMap());
} catch (IOException e) {
throw new GraphicalEditorException(e);
}
}
}
}
use of org.osate.ge.internal.GraphicalEditorException in project osate2 by osate.
the class DiagramSerialization method readMetaModelDiagram.
/**
* Loads the serialized diagram
* @param uri the URI specifying the location of the diagram file
* @return the serialized diagram
*/
public static org.osate.ge.diagram.Diagram readMetaModelDiagram(final URI uri) {
Objects.requireNonNull(uri, "uri must not be null");
// Load the resource
final ResourceSet rs = new ResourceSetImpl();
final Resource resource = rs.createResource(uri);
try {
resource.load(Collections.singletonMap(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, true));
if (resource.getContents().size() == 0 || !(resource.getContents().get(0) instanceof org.osate.ge.diagram.Diagram)) {
throw new GraphicalEditorException("Unable to load diagram.");
}
final org.osate.ge.diagram.Diagram mmDiagram = (org.osate.ge.diagram.Diagram) resource.getContents().get(0);
return mmDiagram;
} catch (final IOException e) {
throw new GraphicalEditorException(e);
}
}
use of org.osate.ge.internal.GraphicalEditorException in project osate2 by osate.
the class DiagramSerialization method write.
/**
* Serialized the specified runtime diagram and writes is to a file.
* @param project the project in which the diagram is contained.
* @param diagram the runtime diagram to serialize
* @param uri the URI specifying the file to which to write the serialized diagram
*/
public static void write(final IProject project, final AgeDiagram diagram, final URI uri) {
// Convert from the runtime format to the metamodel format which is stored
final org.osate.ge.diagram.Diagram mmDiagram = new Diagram();
mmDiagram.setFormatVersion(FORMAT_VERSION);
final org.osate.ge.diagram.DiagramConfiguration mmConfig = new org.osate.ge.diagram.DiagramConfiguration();
mmDiagram.setConfig(mmConfig);
// Populate the diagram configuration
final DiagramConfiguration config = diagram.getConfiguration();
mmConfig.setType(config.getDiagramType().getId());
mmConfig.setContext(config.getContextBoReference() == null ? null : config.getContextBoReference().toMetamodel());
mmConfig.setConnectionPrimaryLabelsVisible(config.getConnectionPrimaryLabelsVisible());
final org.osate.ge.diagram.AadlPropertiesSet enabledProperties = new org.osate.ge.diagram.AadlPropertiesSet();
mmConfig.setEnabledAadlProperties(enabledProperties);
for (final String enabledPropertyName : config.getEnabledAadlPropertyNames()) {
enabledProperties.getProperty().add(enabledPropertyName);
}
convertElementsToMetamodel(project, mmDiagram, diagram.getChildren());
// Save the resource
final ResourceSet rs = new ResourceSetImpl();
final Resource resource = rs.createResource(uri);
resource.getContents().add(mmDiagram);
try {
resource.save(Collections.emptyMap());
} catch (IOException e) {
throw new GraphicalEditorException(e);
}
}
Aggregations