X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fquery%2FConnectionVisualsRequest.java;h=619e913f041c5554f9082e98893cb800b8edf6d0;hb=e3f46ffc9d4a6930adc83ebb8e6730f19708cc94;hp=1f80520e9d87a5d67825a396f8944e2ecc71b3bd;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/query/ConnectionVisualsRequest.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/query/ConnectionVisualsRequest.java index 1f80520e9..619e913f0 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/query/ConnectionVisualsRequest.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/query/ConnectionVisualsRequest.java @@ -1,69 +1,72 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 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: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.diagram.query; - -import java.awt.Stroke; - -import org.simantics.databoard.Bindings; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.ResourceRead; -import org.simantics.db.exception.DatabaseException; -import org.simantics.diagram.G2DUtils; -import org.simantics.diagram.connection.ConnectionVisuals; -import org.simantics.diagram.stubs.G2DResource; -import org.simantics.g2d.element.handler.EdgeVisuals.StrokeType; - -/** - * @author Tuukka Lehtonen - */ -public class ConnectionVisualsRequest extends ResourceRead { - - G2DResource g2d; - - public ConnectionVisualsRequest(Resource connectionType) { - super(connectionType); - assert connectionType != null; - } - - @Override - public ConnectionVisuals perform(ReadGraph g) throws DatabaseException { - g2d = G2DResource.getInstance(g); - Resource structuralConnectionType = resource; - - // Load edge visual aspects - Resource c = g.getPossibleObject(structuralConnectionType, g2d.HasColor); - float[] color = null; - if (c != null) { - float[] col = g.getPossibleValue(c, Bindings.FLOAT_ARRAY); - if (col != null && col.length >= 3) { - color = col; - } - } - - StrokeType strokeType = toStrokeType(g.getPossibleObject(structuralConnectionType, g2d.HasStrokeType)); - Stroke stroke = G2DUtils.getStroke(g, g.getPossibleObject(structuralConnectionType, g2d.HasStroke)); - - return new ConnectionVisuals(color, strokeType, stroke); - } - - StrokeType toStrokeType(Resource strokeType) { - if (strokeType != null) { - if (strokeType.equals(g2d.StrokeType_Scaling)) - return StrokeType.Absolute; - if (strokeType.equals(g2d.StrokeType_Nonscaling)) - return StrokeType.Relative; - } - return null; - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 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: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.diagram.query; + +import java.awt.Stroke; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ResourceRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.G2DUtils; +import org.simantics.diagram.connection.ConnectionVisuals; +import org.simantics.diagram.stubs.G2DResource; +import org.simantics.g2d.element.handler.EdgeVisuals.StrokeType; + +/** + * @author Tuukka Lehtonen + */ +public class ConnectionVisualsRequest extends ResourceRead { + + G2DResource g2d; + + public ConnectionVisualsRequest(Resource connectionType) { + super(connectionType); + assert connectionType != null; + } + + @Override + public ConnectionVisuals perform(ReadGraph g) throws DatabaseException { + g2d = G2DResource.getInstance(g); + Resource structuralConnectionType = resource; + + // Load edge visual aspects + Resource c = g.getPossibleObject(structuralConnectionType, g2d.HasColor); + float[] color = null; + if (c != null) { + float[] col = g.getPossibleValue(c, Bindings.FLOAT_ARRAY); + if (col != null && col.length >= 3) { + color = col; + } + } + + StrokeType strokeType = toStrokeType(g.getPossibleObject(structuralConnectionType, g2d.HasStrokeType)); + Stroke stroke = G2DUtils.getStroke(g, g.getPossibleObject(structuralConnectionType, g2d.HasStroke)); + Double branchPointRadius = g.getPossibleRelatedValue(structuralConnectionType, g2d.HasBranchPointRadius, Bindings.DOUBLE); + Double rounding = g.getPossibleRelatedValue(structuralConnectionType, g2d.HasRounding, Bindings.DOUBLE); + Double offset = g.getPossibleRelatedValue(structuralConnectionType, g2d.HasOffset, Bindings.DOUBLE); + + return new ConnectionVisuals(color, strokeType, stroke, branchPointRadius, rounding, offset); + } + + StrokeType toStrokeType(Resource strokeType) { + if (strokeType != null) { + if (strokeType.equals(g2d.StrokeType_Scaling)) + return StrokeType.Absolute; + if (strokeType.equals(g2d.StrokeType_Nonscaling)) + return StrokeType.Relative; + } + return null; + } + +}