X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.template2d.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Ftemplate2d%2Fui%2Ffunction%2FTranslateFlag.java;h=467695a6dedfb4d25ce8f8de0b312c7b346047fe;hb=4348580eb03f16ae6766dbdf60e64d7b553768bc;hp=aa32cb8d75a067427d18a558a91c789193232898;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/function/TranslateFlag.java b/bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/function/TranslateFlag.java index aa32cb8d7..467695a6d 100644 --- a/bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/function/TranslateFlag.java +++ b/bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/function/TranslateFlag.java @@ -1,107 +1,107 @@ -/******************************************************************************* - * Copyright (c) 2012 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.modeling.template2d.ui.function; - -import java.awt.geom.AffineTransform; -import java.awt.geom.Point2D; -import java.util.Arrays; -import java.util.Map; - -public class TranslateFlag { - public static final float lineWidth = 0.3F; - private FlagInfo flagInfo = null; - private Map tables = null; - private double[] transform = null; - private double gridSize = 0.0; - - public TranslateFlag(FlagInfo flagInfo, Map tables, double[] transform, double gridSize){ - this.flagInfo = flagInfo; - this.tables = tables; - this.transform = transform; - this.gridSize = gridSize; - } - - public double[] perform(){ - // flag transforming - FlagTableInfo table = tables.get(flagInfo.flagTableName); - if (table == null) - return this.transform; - -// Double x = table.getPosition().getX()+((table.getAlignment()==TemplateInfo.ALIGN_RIGHT)?table.getWidth():0.0); -// Double y = table.getPosition().getY()+table.getRowHeigth()*(flagInfo.getSlotTableRowIndex())-2.0F+TemplateInfo.BASELINE_VERTICAL_OFFSET*table.getRowHeigth(); -// double[] copy = Arrays.copyOf(transform, transform.length); -// copy[4] = x; -// copy[5] = y; -// return copy; - - - //double yy = table.getRowHeigth()*(flagInfo.getSlotTableRowIndex())-2.0F+TemplateInfo.BASELINE_VERTICAL_OFFSET*table.getRowHeigth(); - double[] tableTrans = table.getTransform(); - double scale = tableTrans[3]; - double scaledRowHeigth = scale*table.getRowHeight(); - - // move to coordinate system of parent of iotable - double rowMiddleY = tableTrans[5]+(flagInfo.flagTableRowIndex+0.5F)*scaledRowHeigth; - if (gridSize != 0.0) { - double modulo = rowMiddleY%gridSize; - int count =(int) (rowMiddleY/gridSize); - double gridOnRow = (modulo > (gridSize/2))?gridSize*(1+count):gridSize*count; - double diff = (gridOnRow > rowMiddleY)? gridOnRow - rowMiddleY:rowMiddleY-gridOnRow; - if (diff < (scaledRowHeigth/2)) - rowMiddleY = gridOnRow; - } - // move back to iotable coordinate system - rowMiddleY = (rowMiddleY-tableTrans[5])/scale; - -// double yy = 0.0; -// yy = (flagInfo.getSlotTableRowIndex()+0.5F)*table.getRowHeigth()-lineWidth/2; -// double yy2 = 0.0; -// -// // calculate flag position if it is snap to grid -// if (gridSize != 0.0) { -// double modulo = yy%gridSize; -// int count =(int) (yy/gridSize); -// yy2 = ((yy%gridSize) > (gridSize/2))?gridSize*(1+ (int)(yy/gridSize))-lineWidth/2:gridSize*(int)(yy/gridSize)-lineWidth/2; -// } -// -// // check that the nearist grid layes on current row -// if (yy2-yy < table.getRowHeigth()/2) -// yy = yy2; - - double xx = ((table.getAlignment()==DrawingTemplateInfo.ALIGN_RIGHT)?table.getWidth():0.0); - - AffineTransform trans = new AffineTransform(new double[]{tableTrans[0],tableTrans[1],tableTrans[2],tableTrans[3],0.0,0.0}); - Point2D point = new Point2D.Double(xx, rowMiddleY); - trans.transform(point, point); - - double[] copy = Arrays.copyOf(transform, transform.length); - copy[4] = tableTrans[4] + point.getX(); - copy[5] = tableTrans[5] + point.getY(); - return copy; -// Double x = table.getTransform()[4]+; -// Double y = table.getTransform()[5]+; -// -// double[] copy = Arrays.copyOf(transform, transform.length); -// copy[4] = x;//transform[4]; -// copy[5] = y; -// return copy; - -// Session session = Simantics.peekSession(); -// if (session == null) -// return; -// session.asyncRequest(new WriteRequest(){ -// @Override -// public void perform(WriteGraph g) throws DatabaseException { -// TranslateElement.absolute(flagInfo.getFlag(), position).perform(g); -// }}); - } -} +/******************************************************************************* + * Copyright (c) 2012 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.modeling.template2d.ui.function; + +import java.awt.geom.AffineTransform; +import java.awt.geom.Point2D; +import java.util.Arrays; +import java.util.Map; + +public class TranslateFlag { + public static final float lineWidth = 0.3F; + private FlagInfo flagInfo = null; + private Map tables = null; + private double[] transform = null; + private double gridSize = 0.0; + + public TranslateFlag(FlagInfo flagInfo, Map tables, double[] transform, double gridSize){ + this.flagInfo = flagInfo; + this.tables = tables; + this.transform = transform; + this.gridSize = gridSize; + } + + public double[] perform(){ + // flag transforming + FlagTableInfo table = tables.get(flagInfo.flagTableName); + if (table == null) + return this.transform; + +// Double x = table.getPosition().getX()+((table.getAlignment()==TemplateInfo.ALIGN_RIGHT)?table.getWidth():0.0); +// Double y = table.getPosition().getY()+table.getRowHeigth()*(flagInfo.getSlotTableRowIndex())-2.0F+TemplateInfo.BASELINE_VERTICAL_OFFSET*table.getRowHeigth(); +// double[] copy = Arrays.copyOf(transform, transform.length); +// copy[4] = x; +// copy[5] = y; +// return copy; + + + //double yy = table.getRowHeigth()*(flagInfo.getSlotTableRowIndex())-2.0F+TemplateInfo.BASELINE_VERTICAL_OFFSET*table.getRowHeigth(); + double[] tableTrans = table.getTransform(); + double scale = tableTrans[3]; + double scaledRowHeigth = scale*table.getRowHeight(); + + // move to coordinate system of parent of iotable + double rowMiddleY = tableTrans[5]+(flagInfo.flagTableRowIndex+0.5F)*scaledRowHeigth; + if (gridSize != 0.0) { + double modulo = rowMiddleY%gridSize; + int count =(int) (rowMiddleY/gridSize); + double gridOnRow = (modulo > (gridSize/2))?gridSize*(1+count):gridSize*count; + double diff = (gridOnRow > rowMiddleY)? gridOnRow - rowMiddleY:rowMiddleY-gridOnRow; + if (diff < (scaledRowHeigth/2)) + rowMiddleY = gridOnRow; + } + // move back to iotable coordinate system + rowMiddleY = (rowMiddleY-tableTrans[5])/scale; + +// double yy = 0.0; +// yy = (flagInfo.getSlotTableRowIndex()+0.5F)*table.getRowHeigth()-lineWidth/2; +// double yy2 = 0.0; +// +// // calculate flag position if it is snap to grid +// if (gridSize != 0.0) { +// double modulo = yy%gridSize; +// int count =(int) (yy/gridSize); +// yy2 = ((yy%gridSize) > (gridSize/2))?gridSize*(1+ (int)(yy/gridSize))-lineWidth/2:gridSize*(int)(yy/gridSize)-lineWidth/2; +// } +// +// // check that the nearist grid layes on current row +// if (yy2-yy < table.getRowHeigth()/2) +// yy = yy2; + + double xx = ((table.getAlignment()==DrawingTemplateInfo.ALIGN_RIGHT)?table.getWidth():0.0); + + AffineTransform trans = new AffineTransform(new double[]{tableTrans[0],tableTrans[1],tableTrans[2],tableTrans[3],0.0,0.0}); + Point2D point = new Point2D.Double(xx, rowMiddleY); + trans.transform(point, point); + + double[] copy = Arrays.copyOf(transform, transform.length); + copy[4] = tableTrans[4] + point.getX(); + copy[5] = tableTrans[5] + point.getY(); + return copy; +// Double x = table.getTransform()[4]+; +// Double y = table.getTransform()[5]+; +// +// double[] copy = Arrays.copyOf(transform, transform.length); +// copy[4] = x;//transform[4]; +// copy[5] = y; +// return copy; + +// Session session = Simantics.peekSession(); +// if (session == null) +// return; +// session.asyncRequest(new WriteRequest(){ +// @Override +// public void perform(WriteGraph g) throws DatabaseException { +// TranslateElement.absolute(flagInfo.getFlag(), position).perform(g); +// }}); + } +}