From bb1507f2eaee879439d355bf6b052e16d0df1bff Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Mon, 26 Sep 2016 13:30:21 +0300 Subject: [PATCH] Sync git svn branch with SVN repository r33219. refs #6706 refs #6704 refs #6702 refs #6701 --- .../modeling/ui/pdf/PDFExportPage.java | 2 +- .../elaboration/subsumption/SubSolver.java | 2 +- .../org.simantics.scl.db/scl/Simantics/DB.scl | 26 ++- .../spreadsheet/graph/CellValueVisitor.java | 12 +- .../ui/color/ColorGradientComposite.java | 170 ++++++------------ 5 files changed, 96 insertions(+), 116 deletions(-) diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/pdf/PDFExportPage.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/pdf/PDFExportPage.java index ac6dd5d7c..8920decfe 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/pdf/PDFExportPage.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/pdf/PDFExportPage.java @@ -403,7 +403,7 @@ public class PDFExportPage extends WizardPage { exportLocationListener = new ModifyListener() { @Override public void modifyText(ModifyEvent e) { - System.out.println("export location changed by user"); + //System.out.println("export location changed by user"); exportLocationTouchedByUser = true; validatePage(); } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/subsumption/SubSolver.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/subsumption/SubSolver.java index 70adf524b..f9b5efc3b 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/subsumption/SubSolver.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/subsumption/SubSolver.java @@ -49,7 +49,7 @@ public class SubSolver { reduceChains(); propagateUpperBounds(); checkLowerBounds(); - errorFromUnsolvedEquations(); + //errorFromUnsolvedEquations(); //System.out.println("--"); //print(); } diff --git a/bundles/org.simantics.scl.db/scl/Simantics/DB.scl b/bundles/org.simantics.scl.db/scl/Simantics/DB.scl index ac50e3e73..023960678 100644 --- a/bundles/org.simantics.scl.db/scl/Simantics/DB.scl +++ b/bundles/org.simantics.scl.db/scl/Simantics/DB.scl @@ -455,4 +455,28 @@ lift2Write f x y = syncWrite (\_ -> f x y) @inline lift3Write :: (a -> b -> c -> d) -> (a -> b -> c -> d) -lift3Write f x y z = syncWrite (\_ -> f x y z) \ No newline at end of file +lift3Write f x y z = syncWrite (\_ -> f x y z) + +""" +Returns a child Browsable of the specified parent that has that is the child +of the specified parent with the specified name path. +""" +childWithPath :: Browsable a => a -> [String] -> a +childWithPath parent path = + foldl (\r name -> match possibleChild r name with + Just c -> c + Nothing -> fail ("Didn't find " + name + ".") + ) + parent path + +""" +Like `childWithPath` but returns Maybe a which will be `Nothing` if no child +was found. +""" +possibleChildWithPath :: Browsable a => a -> [String] -> Maybe a +possibleChildWithPath parent path = + foldl (\r name -> match r with + Just c -> possibleChild c name + Nothing -> Nothing + ) + (Just parent) path diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/CellValueVisitor.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/CellValueVisitor.java index 385af9938..022326248 100644 --- a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/CellValueVisitor.java +++ b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/CellValueVisitor.java @@ -189,7 +189,8 @@ public class CellValueVisitor implements AstValueVisitor { String rightString = (rightResult.toString()).toLowerCase(); if("<".equals(astRelation.op.trim())) return leftString.compareTo(rightString) < 0; else if(">".equals(astRelation.op.trim())) return leftString.compareTo(rightString) > 0; - else if("=".equals(astRelation.op.trim())) return leftString.compareTo(rightString) == 0; + // empty string should equal zero (TODO: this is a hack, the proper fix should be somewhere earlier so other cases would work as well) + else if("=".equals(astRelation.op.trim())) return leftString.compareTo(rightString) == 0 || emptyAndZero(leftString, rightString) || emptyAndZero(rightString, leftString); else if("<>".equals(astRelation.op.trim())) return leftString.compareTo(rightString) != 0 ; else if("<=".equals(astRelation.op.trim())) return leftString.compareTo(rightString) <= 0 ; else if(">=".equals(astRelation.op.trim())) return leftString.compareTo(rightString) >= 0 ; @@ -207,6 +208,15 @@ public class CellValueVisitor implements AstValueVisitor { } } + private static boolean emptyAndZero(String a, String b) { + try { + return a.isEmpty() && (Double.parseDouble(b) == 0); + } + catch (NumberFormatException e) { + return false; + } + } + Object leftValueWithPrefix(Object result, AstValue value, String prefix, boolean forceNumber) { if(result == null) { Object obj = value.accept(this); diff --git a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/color/ColorGradientComposite.java b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/color/ColorGradientComposite.java index 3b434942f..f8a52bc70 100644 --- a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/color/ColorGradientComposite.java +++ b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/color/ColorGradientComposite.java @@ -16,6 +16,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.CellEditor; @@ -28,6 +29,7 @@ import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TextCellEditor; import org.eclipse.jface.viewers.Viewer; @@ -37,14 +39,11 @@ import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.ColorDialog; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; @@ -64,7 +63,6 @@ public class ColorGradientComposite extends Composite implements ISelectionChang private ColorGradientCanvas gradientComposite; - //private Table table; private TableViewer viewer; private Button addButton; private Button editButton; @@ -74,24 +72,21 @@ public class ColorGradientComposite extends Composite implements ISelectionChang private int type = ColorGradient.RGB; private ArrayList values = new ArrayList(); - //private ArrayList images = new ArrayList(); - //private HashMap items = new HashMap(); private HashMap images = new HashMap(); - - public ColorGradientComposite(Composite parent, int style) { super(parent,style); - FormLayout layout = new FormLayout(); + GridLayout layout = new GridLayout(2,false); this.setLayout(layout); gradientComposite = new ColorGradientCanvas(this,SWT.HORIZONTAL); - Group typeComposite = new Group(this,SWT.NONE); - typeComposite.setText("Color interpolation type"); + + +// Group typeComposite = new Group(this,SWT.NONE); +// typeComposite.setText("Interpolation"); + Composite typeComposite = new Composite(this, SWT.NONE); - typeComposite.setLayout(new FillLayout(SWT.HORIZONTAL)); - Label rgbLabel = new Label(typeComposite,SWT.NONE); - rgbLabel.setText("RGB"); + typeComposite.setLayout(new GridLayout(1,false)); rgbButton = new Button(typeComposite,SWT.RADIO); rgbButton.setSelection(true); rgbButton.addSelectionListener(new SelectionListener() { @@ -105,8 +100,7 @@ public class ColorGradientComposite extends Composite implements ISelectionChang gradientComposite.setGradient(new ColorGradient(values,type)); } }); - Label hsvLabel = new Label(typeComposite,SWT.NONE); - hsvLabel.setText("HSV"); + rgbButton.setText("RGB"); hsvButton = new Button(typeComposite,SWT.RADIO); hsvButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { @@ -119,9 +113,11 @@ public class ColorGradientComposite extends Composite implements ISelectionChang gradientComposite.setGradient(new ColorGradient(values,type)); } }); + hsvButton.setText("HSV"); + viewer = new TableViewer(this,SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION); - //table = new Table(this,SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); final Table table = viewer.getTable(); + table.setLinesVisible(true); table.setHeaderVisible(true); @@ -130,7 +126,7 @@ public class ColorGradientComposite extends Composite implements ISelectionChang TableColumn column = new TableColumn(table,SWT.RIGHT); column.setText("Color"); - column.setWidth(40); + column.setWidth(60); column.setMoveable(false); column.setResizable(false); column = new TableColumn(table,SWT.LEFT); @@ -153,11 +149,9 @@ public class ColorGradientComposite extends Composite implements ISelectionChang viewer.setCellModifier(new TableCellEditorModifier()); - Composite buttonComposite = new Composite(this,SWT.NONE); - - - buttonComposite.setLayout(new FillLayout(SWT.HORIZONTAL)); + + buttonComposite.setLayout(new FillLayout(SWT.VERTICAL)); addButton = new Button(buttonComposite,SWT.PUSH); addButton.setText("Add new color"); @@ -174,10 +168,32 @@ public class ColorGradientComposite extends Composite implements ISelectionChang } else if (values.size() == 1) { value = 100.0; } else { - // FIXME : insert some logic here - value = 100.0 * Math.random(); + StructuredSelection selection = (StructuredSelection)viewer.getSelection(); + if (selection.size() == 1) { + // add new color next to the selection + ColorValue v = (ColorValue)selection.getFirstElement(); + int index = values.indexOf(v); + if (index == values.size() -1) { + index--; + } + value = (values.get(index+1).getValue()-values.get(index).getValue())*0.5; + value += values.get(index).getValue(); + } else { + // add new color to largest gap + int index = 0; + double r = 0.0; + for (int i = 0; i < values.size() -1; i++) { + double v1 = values.get(i).getValue(); + double v2 = values.get(i+1).getValue(); + double vr = v2 -v1; + if (vr > r) { + r=vr; + index = i; + } + } + value = values.get(index).getValue() + r *0.5; + } } - addColor(c,value); } } @@ -222,67 +238,21 @@ public class ColorGradientComposite extends Composite implements ISelectionChang }); removeButton.setEnabled(false); - FormData gradientData = new FormData(); - gradientData.top = new FormAttachment(0,0); - gradientData.left = new FormAttachment(0,0); - gradientData.right = new FormAttachment(100,0); - gradientData.height = 40; - gradientComposite.setLayoutData(gradientData); - - FormData typeData = new FormData(); - typeData.left = new FormAttachment(0,0); - typeData.right = new FormAttachment(100,0); - typeData.top = new FormAttachment(gradientComposite,0,SWT.BOTTOM); - typeData.height = 20; - typeComposite.setLayoutData(typeData); - - FormData buttonData = new FormData(); - buttonData.left = new FormAttachment(0,0); - buttonData.right = new FormAttachment(100,0); - buttonData.bottom = new FormAttachment(100,0); - buttonData.height = 30; - buttonComposite.setLayoutData(buttonData); + GridDataFactory.fillDefaults().span(1, 1).grab(true, false).align(SWT.FILL, SWT.CENTER).hint(SWT.DEFAULT, 32).applyTo(gradientComposite); + GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).hint(SWT.DEFAULT, 100).applyTo(table); + GridDataFactory.fillDefaults().grab(false, true).align(SWT.LEFT, SWT.FILL).applyTo(typeComposite); + GridDataFactory.fillDefaults().span(1, 1).grab(true, false).align(SWT.FILL, SWT.TOP).applyTo(buttonComposite); - FormData viewerData = new FormData(); - viewerData.top = new FormAttachment(typeComposite,0,SWT.BOTTOM); - viewerData.left = new FormAttachment(0,0); - viewerData.right = new FormAttachment(100,0); - viewerData.bottom = new FormAttachment(buttonComposite,0,SWT.TOP); - table.setLayoutData(viewerData); - - } - /* - private void addColorValueToTable(ColorValue value) { - TableItem item = new TableItem(table,SWT.NONE); - item.setText(Double.toString(value.getValue())); - Image image = ColorIconCreator.createImage(value.getColor(), 14); - item.setImage(image); - images.add(image); - items.put(item,value); - } - */ - /* - private void sortItems() { - for (Image i : images) - i.dispose(); - for (TableItem item : table.getItems()) - if(!item.isDisposed()) - item.dispose(); - items.clear(); - Collections.sort(values,new ColorValueComparator()); - for (ColorValue value : values) { - addColorValueToTable(value); - } } - */ + public void addColor(Color color, double value) { addColor(new ColorValue(color,value)); } public void addColor(ColorValue value) { values.add(value); - Image image = ColorIconCreator.createImage(value.getColor(), ICON_WIDTH, ICON_HEIGHT); + Image image = ColorIconCreator.createImage(value.getColor(), ICON_WIDTH, ICON_HEIGHT, SWT.BORDER); images.put(value,image); updateWidgets(); //viewer.refresh(true); @@ -294,36 +264,11 @@ public class ColorGradientComposite extends Composite implements ISelectionChang viewer.refresh(); } - /* - public void addColor(ColorValue value) { - values.add(value); - sortItems(); - // sortItem creates new menuitems, which makes selectedItem disposed - for (TableItem item : items.keySet() ) { - if (items.get(item) == value) { - gradientComposite.setGradient(new ColorGradient(values,type)); - return; - } - - } - gradientComposite.setGradient(new ColorGradient(values,type)); - } - */ + public ColorGradient getGradient() { return new ColorGradient(values,type); } - /* - public void dispose() { - for (Image i : images) - i.dispose(); - if (!table.isDisposed()) { - for (TableItem item : table.getItems()) - if(!item.isDisposed()) - item.dispose(); - table.dispose(); - } - } - */ + public void dispose() { for (Image i : images.values()) i.dispose(); @@ -338,15 +283,16 @@ public class ColorGradientComposite extends Composite implements ISelectionChang type = gradient.getType(); for (ColorValue value : gradient.getColorValues()) addColor(value); + if (type == ColorGradient.HSV) { + rgbButton.setSelection(false); + hsvButton.setSelection(true); + } else if (type == ColorGradient.RGB) { + hsvButton.setSelection(false); + rgbButton.setSelection(true); + } } - -// private org.eclipse.swt.graphics.Color getSWTColor(Color color){ -// org.eclipse.swt.graphics.Color swtColor = new org.eclipse.swt.graphics.Color(Display.getCurrent(), color.getR(), color.getG(), color.getB()); -// return swtColor; -// } - private RGB getRGB(Color color) { RGB rgb = new RGB(color.getR(),color.getG(),color.getB()); return rgb; @@ -377,7 +323,7 @@ public class ColorGradientComposite extends Composite implements ISelectionChang Color newColor = new Color(rgb.red,rgb.green,rgb.blue); ColorValue newCValue = new ColorValue(newColor,cValue.getValue()); values.add(newCValue); - Image newImage = ColorIconCreator.createImage(newColor, ICON_WIDTH, ICON_HEIGHT); + Image newImage = ColorIconCreator.createImage(newColor, ICON_WIDTH, ICON_HEIGHT, SWT.BORDER); images.put(newCValue,newImage); updateWidgets(); } -- 2.43.2