--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007- VTT Technical Research Centre of Finland.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.proconf.g3d.shapeeditor.views;\r
+\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.List;\r
+\r
+import org.eclipse.jface.dialogs.InputDialog;\r
+import org.eclipse.jface.dialogs.MessageDialog;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.SelectionAdapter;\r
+import org.eclipse.swt.events.SelectionEvent;\r
+import org.eclipse.swt.layout.FillLayout;\r
+import org.eclipse.swt.layout.GridData;\r
+import org.eclipse.swt.widgets.Button;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Label;\r
+import org.eclipse.swt.widgets.Text;\r
+import org.eclipse.swt.widgets.Tree;\r
+import org.eclipse.ui.forms.IFormColors;\r
+import org.simantics.proconf.g3d.csg.stubs.CSGModel;\r
+import org.simantics.db.Graph;\r
+import org.simantics.db.GraphRequestAdapter;\r
+import org.simantics.db.GraphRequestStatus;\r
+import org.simantics.db.Resource;\r
+import org.simantics.equation.stubs.SecondOrderScalarPolynomial;\r
+import org.simantics.animation.stubs.Animation;\r
+import org.simantics.animation.stubs.Interpolator;\r
+import org.simantics.layer0.utils.ResourceDebugUtils;\r
+import org.simantics.layer0.utils.IEntity;\r
+import org.simantics.layer0.utils.EntityFactory;\r
+import org.simantics.proconf.browsing.GraphExplorer;\r
+import org.simantics.proconf.browsing.GraphExplorerInputFactory;\r
+import org.simantics.proconf.g3d.common.StructuredResourceSelection;\r
+import org.simantics.proconf.g3d.shapeeditor.ShapeEditorResources;\r
+import org.simantics.proconf.g3d.shapeeditor.common.ViewpointGenerator;\r
+import org.simantics.proconf.g3d.tools.OESelectionListener;\r
+import org.simantics.proconf.g3d.tools.PropertyTree;\r
+import org.simantics.proconf.g3d.views.SinglePageResourceEditor;\r
+import org.simantics.utils.ui.widgets.TrackedModifyEvent;\r
+import org.simantics.utils.ui.widgets.TrackedModifyListener;\r
+import org.simantics.utils.ui.widgets.TrackedText;\r
+\r
+\r
+public class ParameterizationEditor extends SinglePageResourceEditor { //implements ISelectionProvider{\r
+ \r
+ //ParameterizedCSGModel model;\r
+ Resource modelResource;\r
+ private TrackedText modelName = null;\r
+ StructuredResourceSelection hierarchySelection = new StructuredResourceSelection();\r
+ StructuredResourceSelection parameterSelection = new StructuredResourceSelection();\r
+ GraphExplorer parameterExplorer;\r
+ GraphExplorer hierarchyExplorer;\r
+ Button deleteParameterButton;\r
+ Button clearButton;\r
+ PropertyTree propertiesTree;\r
+ Button generateButton;\r
+ Button askButton;\r
+ Button overrideButton;\r
+ Composite parent;\r
+ \r
+ \r
+ @Override\r
+ protected String getFormText() {\r
+ return "Parameterization Editor";\r
+ }\r
+\r
+// @Override\r
+// protected void beforeCreateWidgets() {\r
+// if (!(getInputResource().isInstanceOf(GlobalIdMap.get(CSGModelingOntologyMapping.PARAMETERIZED_CSG_MODEL))))\r
+// throw new RuntimeException("Trying to open resource that is not paramaterized CSG model");\r
+// model = ParameterizedCSGModelFactory.create(getInputResource());\r
+// }\r
+ \r
+ \r
+\r
+ @Override\r
+ protected void createWidgets() {\r
+ createModelPropertiesGroup(newGridSection(2, 2, false, false, "Model Properties",\r
+ "Basic properties for this viewpoint"));\r
+ createParametrizationGroup(newGridSection(2, 2, false, false, "Parameterization",\r
+ "Create parameterization for selected shapes"));\r
+ //getSite().setSelectionProvider(this);\r
+ }\r
+\r
+ @Override\r
+ public void reload(Graph graph) {\r
+ modelResource = getInputResource();\r
+ parent.getDisplay().asyncExec(new Runnable() {\r
+ @Override\r
+ public void run() {\r
+ reload();\r
+ } \r
+ });\r
+\r
+ }\r
+ \r
+ public void reload() {\r
+\r
+ hierarchyExplorer.setInput(getSessionContext(),GraphExplorerInputFactory.clone(hierarchyExplorer.getInput())\r
+ .input(modelResource)\r
+ .viewpoint(ViewpointGenerator.createObjectStructureViewpoint())\r
+ .toInput());\r
+\r
+ parameterExplorer.setInput(getSessionContext(),GraphExplorerInputFactory.clone(parameterExplorer.getInput())\r
+ .input(modelResource)\r
+ .viewpoint(ViewpointGenerator.createObjectSizingParameterViewpoint(ShapeEditorResources.g3dResource.HasSizingParameter))\r
+ .toInput());\r
+\r
+ }\r
+ \r
+ private void createParametrizationGroup(Composite parent) {\r
+ toolkit.paintBordersFor(parent);\r
+ toolkit.setBorderStyle(SWT.BORDER);\r
+ \r
+ overrideButton = toolkit.createButton(parent, "Overwrite previous parameterizations", SWT.CHECK);\r
+ overrideButton.addSelectionListener(new SelectionAdapter() {\r
+ public void widgetSelected(SelectionEvent e) {\r
+ askButton.setEnabled(overrideButton.getSelection());\r
+ \r
+ }\r
+ });\r
+\r
+ \r
+ askButton = toolkit.createButton(parent, "Ask before overwriting", SWT.CHECK);\r
+ askButton.addSelectionListener(new SelectionAdapter() {\r
+ public void widgetSelected(SelectionEvent e) {\r
+ \r
+ \r
+ }\r
+ });\r
+ askButton.setEnabled(false);\r
+ \r
+ generateButton = toolkit.createButton(parent, "Generate linear parameterization", SWT.PUSH);\r
+ generateButton.addSelectionListener(new SelectionAdapter() {\r
+ public void widgetSelected(SelectionEvent e) {\r
+ generateMappings();\r
+ \r
+ }\r
+ });\r
+ generateButton.setEnabled(false);\r
+ \r
+ \r
+ }\r
+ \r
+ private CSGModel getModel(Graph graph) {\r
+ return new CSGModel(graph, modelResource);\r
+ }\r
+ \r
+ private void createModelPropertiesGroup(Composite p) {\r
+ parent = p;\r
+ toolkit.paintBordersFor(parent);\r
+ toolkit.setBorderStyle(SWT.BORDER);\r
+ \r
+ GridData gridData1 = new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1);\r
+ GridData gridData2 = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);\r
+\r
+ // Name\r
+ Label l1 = toolkit.createLabel(parent, "Name:");\r
+ l1.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));\r
+ Text text = toolkit.createText(parent, "TODO: Insert model's name here", SWT.SINGLE);\r
+ GridData textLayout = new GridData(GridData.FILL, GridData.FILL, true, true);\r
+ text.setLayoutData(textLayout);\r
+ modelName = new TrackedText(text);\r
+ modelName.addModifyListener(new TrackedModifyListener(){\r
+ @Override\r
+ public void modifyText(TrackedModifyEvent e) {\r
+ final String name = e.getText();\r
+ getSession().asyncWrite(new GraphRequestAdapter() {\r
+ @Override\r
+ public GraphRequestStatus perform(Graph g) throws Exception {\r
+ getModel(g).setName(name);\r
+ return GraphRequestStatus.transactionComplete();\r
+ }\r
+ });\r
+ }\r
+ });\r
+ \r
+ l1.setLayoutData(gridData1);\r
+ text.setLayoutData(gridData2);\r
+ \r
+ \r
+ // Parameters\r
+ Label parameterLabel = toolkit.createLabel(parent, "Parameters:");\r
+ parameterLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));\r
+ parameterLabel.setLayoutData(gridData1);\r
+ \r
+ parameterExplorer = new GraphExplorer(parent, SWT.SINGLE); //new OntologyExplorer("ParameterExplorer", this, getInput("ParameterExplorer", model.getId()));\r
+ parameterExplorer.getViewer().addPostSelectionChangedListener(new OESelectionListener() {\r
+\r
+ protected void resourceSelectionUpdated(StructuredResourceSelection sel) {\r
+ parameterSelection = sel;\r
+ if (parameterSelection.size() == 0) {\r
+ deleteParameterButton.setEnabled(false);\r
+ clearButton.setEnabled(false);\r
+ } else {\r
+ deleteParameterButton.setEnabled(true);\r
+ clearButton.setEnabled(true);\r
+ }\r
+ updateGenerateButtonStatus();\r
+ }\r
+ \r
+ });\r
+ Tree oe = parameterExplorer.getTree();\r
+ toolkit.adapt(oe, true, true);\r
+ GridData gd3 = new GridData(GridData.FILL, GridData.FILL, true, true,1,1);\r
+ gd3.heightHint = 50;\r
+ oe.setLayoutData(gd3);\r
+// parameterExplorer.init(getLastMemento(), ViewpointUtils.getModelledHandler(parameterExplorer.getGraph(), Builtins.DefaultViewpointId), null, ViewLabelProviderDecorationSettings.DEFAULT, new MenuAboutToShowAction(), new NullAdditionAction(), false);\r
+// parameterScheme = new ParameterSelectionScheme(parameterExplorer);\r
+// parameterExplorer.setSelectionScheme(parameterScheme);\r
+ \r
+ // Buttons to add and remove parameters\r
+ toolkit.createLabel(parent, "");\r
+ Composite buttons = toolkit.createComposite(parent);\r
+\r
+ buttons.setLayout(new FillLayout(SWT.HORIZONTAL));\r
+ Button newParameterButton = toolkit.createButton(buttons, "New Parameter", SWT.PUSH);\r
+ newParameterButton.addSelectionListener(new SelectionAdapter() {\r
+ public void widgetSelected(SelectionEvent e) {\r
+ InputDialog dialog = new InputDialog(ParameterizationEditor.this.getSite().getShell(),"New Parameter","Enter parameter's name","new parameter",null);\r
+ if (dialog.open() == InputDialog.CANCEL)\r
+ return;\r
+ final String name = dialog.getValue();\r
+ if (name.length() < 1) \r
+ return; // TODO : show error\r
+ \r
+ getSession().asyncWrite(new GraphRequestAdapter() {\r
+ public GraphRequestStatus perform(Graph g) throws Exception {\r
+ //fi.vtt.simantics.layer0.stubs.Double parameter = DoubleFactory.createDefault(g);\r
+ //getModel(g).addStatement(ShapeEditorResources.g3dResource.HasSizingParameter, parameter);\r
+ //parameter.setValue(new double[]{1.0});\r
+ //parameter.setName(name);\r
+ Resource parameter = getModel(g).addRelatedScalarDouble(ShapeEditorResources.g3dResource.HasSizingParameter, 1.0).getResource();\r
+ IEntity thing = EntityFactory.create(g,parameter);\r
+ thing.setName(name);\r
+ return GraphRequestStatus.transactionComplete();\r
+ };\r
+ });\r
+ \r
+ \r
+ }\r
+ });\r
+ deleteParameterButton = toolkit.createButton(buttons, "Delete Parameter", SWT.PUSH);\r
+ deleteParameterButton.addSelectionListener(new SelectionAdapter() {\r
+ public void widgetSelected(SelectionEvent e) {\r
+ //StructuredResourceSelection s = (StructuredResourceSelection)parameterScheme.getSelection();\r
+ final StructuredResourceSelection s = parameterSelection;\r
+ if (s.size() != 1)\r
+ return;\r
+ // we'll have to start write transaction, since we may have to change the graph\r
+ getSession().asyncWrite(new GraphRequestAdapter() {\r
+ boolean proceed;\r
+ IEntity selectedParameter;\r
+ public GraphRequestStatus perform(Graph g) throws Exception {\r
+ selectedParameter = EntityFactory.create(g,s.getSelectionList().get(0));\r
+ \r
+ Collection<IEntity> parameters = selectedParameter.getRelatedObjects(ShapeEditorResources.g3dResource.HasSizingParameter);\r
+ if (parameters.size() > 0) {\r
+ final MessageDialog dialog = new MessageDialog(ParameterizationEditor.this.getSite().getShell(),"Deleting a parameter",null,"Parameter is in use, doe you wan't to remove it?",MessageDialog.QUESTION,new String[]{"OK","Cancel"},1);\r
+ parent.getDisplay().syncExec(new Runnable() {\r
+ @Override\r
+ public void run() {\r
+ proceed = (dialog.open() != 1);\r
+ }\r
+ });\r
+ if (proceed) {\r
+ getModel(g).removeStatement(ShapeEditorResources.g3dResource.HasSizingParameter,selectedParameter);\r
+ }\r
+ }\r
+ \r
+ return GraphRequestStatus.transactionComplete();\r
+ }\r
+ });\r
+ }\r
+ });\r
+ deleteParameterButton.setEnabled(false);\r
+ \r
+ clearButton = toolkit.createButton(buttons, "Clear Parameter", SWT.PUSH);\r
+ clearButton.addSelectionListener(new SelectionAdapter() {\r
+ public void widgetSelected(SelectionEvent e) {\r
+ final StructuredResourceSelection s = parameterSelection;\r
+ if (s.size() != 1)\r
+ return;\r
+ getSession().asyncWrite(new GraphRequestAdapter() {\r
+ boolean proceed;\r
+ @Override\r
+ public GraphRequestStatus perform(Graph g) throws Exception {\r
+ IEntity selectedParameter = EntityFactory.create(g,s.getSelectionList().get(0));\r
+ Collection<IEntity> equations = selectedParameter.getRelatedObjects(ShapeEditorResources.equationResource.HasTarget);\r
+ final String name = selectedParameter.getName();\r
+ if (equations.size() > 0) {\r
+ final MessageDialog dialog = new MessageDialog(ParameterizationEditor.this.getSite().getShell(),"Clearing a parameter",null,"Do you wan't to clear parameterization for "+ name + " ?\nIt has " + equations.size() + " mappings.",MessageDialog.QUESTION,new String[]{"OK","Cancel"},1); \r
+ parent.getDisplay().syncExec(new Runnable() {\r
+ public void run() {\r
+ proceed = (dialog.open() != 1);\r
+ };\r
+ });\r
+ if (proceed) {\r
+ for (IEntity eq : equations) {\r
+ eq.removeRelatedStatements(ShapeEditorResources.equationResource.HasSource);\r
+ eq.removeRelatedStatements(ShapeEditorResources.equationResource.HasTarget);\r
+ }\r
+ return GraphRequestStatus.transactionComplete();\r
+ }\r
+ }\r
+ return GraphRequestStatus.transactionCancel();\r
+ }\r
+ });\r
+ \r
+ \r
+ }\r
+ });\r
+ clearButton.setEnabled(false);\r
+ \r
+ Label hierarchyLabel = toolkit.createLabel(parent, "Model Hierarchy:");\r
+ hierarchyLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));\r
+ hierarchyLabel.setLayoutData(gridData1);\r
+ \r
+ hierarchyExplorer = new GraphExplorer(parent,SWT.MULTI); //new OntologyExplorer("HierarchyExplorer", this, getInput("HierarchyExplorer", model.getId()));\r
+ Tree oeh = hierarchyExplorer.getTree();//hierarchyExplorer.getControl(parent, 1, OntologyExplorer.OntologyTree, SWT.MULTI);\r
+ toolkit.adapt(oeh, true, true);\r
+ \r
+ GridData gd4 = new GridData(GridData.FILL, GridData.FILL, true, true,1,1);\r
+ gd4.heightHint = 200;\r
+ oeh.setLayoutData(gd4);\r
+ hierarchyExplorer.getViewer().addPostSelectionChangedListener(new OESelectionListener() {\r
+\r
+ protected void resourceSelectionUpdated(StructuredResourceSelection sel) {\r
+ hierarchySelection = sel;\r
+ updatePropertiesTable();\r
+ updateGenerateButtonStatus();\r
+ }\r
+ \r
+ private void updatePropertiesTable() {\r
+ propertiesTree.setProperties(hierarchySelection);\r
+ \r
+ }\r
+ \r
+ });\r
+ //hierarchyExplorer.init(getLastMemento(), ViewpointUtils.getModelledHandler(hierarchyExplorer.getGraph(), CSGModelingOntologyMapping.CSG_MODEL_HIERARCHY_VIEWPOINT), null, ViewLabelProviderDecorationSettings.DEFAULT, new MenuAboutToShowAction(), new NullAdditionAction(), false);\r
+// hierarchyScheme = new HierarchySelectionScheme(hierarchyExplorer);\r
+// hierarchyExplorer.setSelectionScheme(hierarchyScheme);\r
+// hierarchyExplorer.hookPageSelection(this);\r
+ Label propertiesLabel = toolkit.createLabel(parent, "Available properties:");\r
+ propertiesLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));\r
+ propertiesLabel.setLayoutData(gridData1); \r
+ \r
+ //propertiesTable = toolkit.createTable(parent, SWT.MULTI);\r
+ Tree tree = toolkit.createTree(parent, SWT.MULTI);\r
+ propertiesTree = new PropertyTree(tree,getSession());\r
+ //\r
+ GridData gd5 = new GridData(GridData.FILL, GridData.FILL, true, true,1,1);\r
+ gd5.heightHint = 200;\r
+ //propertiesTable.setLayoutData(gd5);\r
+ tree.setLayoutData(gd5);\r
+ tree.addSelectionListener(new SelectionAdapter() {\r
+\r
+ @Override\r
+ public void widgetSelected(SelectionEvent e) {\r
+ updateGenerateButtonStatus();\r
+ }\r
+ \r
+ });\r
+\r
+ \r
+ }\r
+ \r
+// private class ParameterSelectionScheme extends AbstractSelectionScheme {\r
+// \r
+// public ParameterSelectionScheme(OntologyExplorer explorer) {\r
+// super(explorer);\r
+// }\r
+//\r
+// @Override\r
+// protected Resource getResourceForSelection(TreeNode selected) {\r
+// Resource resource = explorer.getCoreResource(selected);\r
+// System.out.println("Parameter Tree Selection : " + resource.getId());\r
+// return resource;\r
+// }\r
+//\r
+// @Override\r
+// protected void resourceSelectionUpdated() {\r
+// if (selection.size() == 0) {\r
+// deleteParameterButton.setEnabled(false);\r
+// clearButton.setEnabled(false);\r
+// } else {\r
+// deleteParameterButton.setEnabled(true);\r
+// clearButton.setEnabled(true);\r
+// }\r
+// updateGenerateButtonStatus();\r
+// }\r
+// }\r
+// \r
+// private class HierarchySelectionScheme extends AbstractSelectionScheme {\r
+//\r
+// public HierarchySelectionScheme(OntologyExplorer explorer) {\r
+// super(explorer);\r
+// }\r
+// \r
+// @Override\r
+// protected Resource getResourceForSelection(TreeNode selected) {\r
+// Resource resource = explorer.getCoreResource(selected);\r
+// System.out.println("Hierarchy Tree Selection : " + resource.getId());\r
+// return resource;\r
+// }\r
+// \r
+// @Override\r
+// protected void resourceSelectionUpdated() {\r
+// updatePropertiesTable();\r
+// updateGenerateButtonStatus();\r
+// }\r
+//\r
+// private void updatePropertiesTable() {\r
+// propertiesTree.setProperties(selection);\r
+// \r
+// }\r
+// \r
+// }\r
+ \r
+// private boolean contains(Resource list[], Resource value) {\r
+// for (int i = 0; i < list.length; i++) {\r
+// if (list[i].equals(value))\r
+// return true;\r
+// }\r
+// return false;\r
+// }\r
+ \r
+ private void updateGenerateButtonStatus() {\r
+ if (parameterSelection.size() == 0) {\r
+ generateButton.setEnabled(false);\r
+ return;\r
+ }\r
+ if (hierarchySelection.size() == 0) {\r
+ generateButton.setEnabled(false);\r
+ return;\r
+ }\r
+ if (propertiesTree.getTree().getSelection().length == 0) {\r
+ generateButton.setEnabled(false);\r
+ return;\r
+ }\r
+ generateButton.setEnabled(true);\r
+ }\r
+ \r
+ List<Resource> res;\r
+ \r
+ private void generateMappings() {\r
+ final StructuredResourceSelection selectedShapes = hierarchySelection;\r
+ final StructuredResourceSelection selectedParameter = parameterSelection;\r
+ \r
+ final boolean override = overrideButton.getSelection();\r
+ final boolean ask = askButton.getSelection();\r
+ //TreeItem[] selectedProperties = propertiesTree.getTree().getSelection();\r
+ \r
+ assert (selectedParameter.size() == 1);\r
+ assert (selectedShapes.size() > 0);\r
+ //assert(selectedProperties.length > 0);\r
+ getSession().asyncWrite(new GraphRequestAdapter() {\r
+ @Override\r
+ public GraphRequestStatus perform(Graph g) throws Exception {\r
+ //fi.vtt.simantics.layer0.stubs.Double parameter = DoubleFactory.create(g,selectedParameter.getSelectionList().get(0));\r
+ IEntity parameter = EntityFactory.create(g,selectedParameter.getSelectionList().get(0));\r
+ Collection<IEntity> prop = parameter.getRelatedObjects(ShapeEditorResources.g3dResource.HasDefaultDoubleValue);\r
+ //fi.vtt.simantics.layer0.stubs.Double defaultValue;\r
+ double value = g.getScalarDouble(parameter.getResource());\r
+ if (prop.size() == 0) {\r
+ //defaultValue = DoubleFactory.createDefault(g);\r
+ //parameter.addStatement(ShapeEditorResources.g3dResource.HasDefaultDoubleValue, defaultValue);\r
+ parameter.addRelatedScalarDouble(ShapeEditorResources.g3dResource.HasDefaultDoubleValue, value);\r
+ } else {\r
+ //defaultValue = DoubleFactory.create(prop.iterator().next());\r
+ g.setScalarDouble(prop.iterator().next().getResource(),value);\r
+ }\r
+ //defaultValue.setValue(parameter.getValue());\r
+ final Graph graph = g;\r
+ parent.getDisplay().syncExec(new Runnable() {\r
+ public void run() {\r
+ res = propertiesTree.findLeafPropertyInstances(graph, selectedShapes.getSelectionList());\r
+ };\r
+ });\r
+ \r
+ \r
+ double refValue = parameter.toProperty().getScalarDouble();\r
+ ArrayList<Resource> mappedProperties = new ArrayList<Resource>();\r
+ \r
+ for (Resource r : res) {\r
+ IEntity propertyThing = EntityFactory.create(g,r);\r
+ assert (propertyThing.isInstanceOf(g.getBuiltins().Double));\r
+ final String name = ResourceDebugUtils.getReadableNameForEntity(propertyThing);\r
+ double rb = propertyThing.toProperty().getScalarDouble();\r
+ System.out.println("Mapping to " + name + " " + rb);\r
+ Collection<IEntity> equations = propertyThing.getRelatedObjects(ShapeEditorResources.equationResource.HasSource);\r
+ if (equations.size() != 0) {\r
+ mappedProperties.add(propertyThing.getResource());\r
+ if (override) {\r
+ System.out.println("Override");\r
+ boolean over = true;\r
+ if (ask) {\r
+ IEntity t = propertyThing;\r
+ while (t.isInstanceOf(g.getBuiltins().Property)) {\r
+ Collection<IEntity> ts = t.getRelatedObjects(g.getBuiltins().PropertyOf);\r
+ // FIXME : traverse all possible routes\r
+ t = ts.iterator().next();\r
+ }\r
+ //StructuredResourceSelection selection = new StructuredResourceSelection(t.getResource());\r
+ // TODO : do the selection!\r
+ //hierarchyScheme.setSelection(selection);\r
+ //fireSelectionChanged();\r
+ MessageDialog dialog = new MessageDialog(ParameterizationEditor.this.getSite().getShell(),\r
+ "Override mapping",\r
+ null,\r
+ "Override mapping to property of highlighted shape?",\r
+ MessageDialog.QUESTION, new String[] {\r
+ "Yes","No", "Cancel" }, 0);\r
+ int i = dialog.open();\r
+ if (i == 2)\r
+ return GraphRequestStatus.transactionCancel();\r
+ over = (i == 0);\r
+ }\r
+ if (over) {\r
+ \r
+ }\r
+ } else {\r
+ if (equations.size() != 1) {\r
+ throw new RuntimeException("One property can have only one euquation as source function.");\r
+ }\r
+ IEntity equation = equations.iterator().next();\r
+ if (!equation.isInstanceOf(ShapeEditorResources.equationResource.SecondOrderScalarPolynomial)) {\r
+ throw new RuntimeException("Only Second order scalar polynomials are supported");\r
+ }\r
+ SecondOrderScalarPolynomial s = new SecondOrderScalarPolynomial(equation);\r
+ s.setA(new double[]{0.0});\r
+ s.setB(new double[]{rb / refValue});\r
+ s.setC(new double[]{0.0});\r
+ \r
+ }\r
+ } else { //override\r
+ // create relation\r
+ SecondOrderScalarPolynomial s = SecondOrderScalarPolynomial.createDefault(g);\r
+ s.setA(new double[]{0.0});\r
+ s.setB(new double[]{rb / refValue});\r
+ s.setC(new double[]{0.0});\r
+ \r
+ // FIXME : these relations have been instantiated, but addStatements won't delete them so we have to delete them manually.\r
+ s.removeRelatedStatements(ShapeEditorResources.equationResource.HasTarget);\r
+ s.removeRelatedStatements(ShapeEditorResources.equationResource.HasSource);\r
+ \r
+ parameter.addStatement(ShapeEditorResources.equationResource.HasTarget, s);\r
+ \r
+ s.addStatement(ShapeEditorResources.equationResource.HasTarget, propertyThing);\r
+ mappedProperties.add(propertyThing.getResource());\r
+ }\r
+ \r
+ }\r
+ CSGModel model = getModel(g);\r
+ Collection<Animation> animations = model.getAnimation();\r
+ for (Animation animation : animations) {\r
+ Collection<Interpolator> interpolators = animation.getInterpolator();\r
+ for (Interpolator interpolator : interpolators) {\r
+ IEntity target = interpolator.getTarget();\r
+ for (Resource property : mappedProperties) {\r
+ if (target.getResource().equals(property)) {\r
+ ShapeEditorResources.curveBuilder.createDefault(interpolator);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ return GraphRequestStatus.transactionComplete();\r
+ }\r
+ });\r
+\r
+\r
+\r
+ }\r
+ \r
+}\r
+\r