]> gerrit.simantics Code Review - simantics/3d.git/blob
07dc17cd955630db309fddcb511f1aeebada0427
[simantics/3d.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.\r
3  * All rights reserved. This program and the accompanying materials\r
4  * are made available under the terms of the Eclipse Public License v1.0\r
5  * which accompanies this distribution, and is available at\r
6  * http://www.eclipse.org/legal/epl-v10.html\r
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package org.simantics.proconf.g3d.shapeeditor.views;\r
12 \r
13 \r
14 import java.util.ArrayList;\r
15 import java.util.Collection;\r
16 import java.util.List;\r
17 \r
18 import org.eclipse.jface.dialogs.InputDialog;\r
19 import org.eclipse.jface.dialogs.MessageDialog;\r
20 import org.eclipse.swt.SWT;\r
21 import org.eclipse.swt.events.SelectionAdapter;\r
22 import org.eclipse.swt.events.SelectionEvent;\r
23 import org.eclipse.swt.layout.FillLayout;\r
24 import org.eclipse.swt.layout.GridData;\r
25 import org.eclipse.swt.widgets.Button;\r
26 import org.eclipse.swt.widgets.Composite;\r
27 import org.eclipse.swt.widgets.Label;\r
28 import org.eclipse.swt.widgets.Text;\r
29 import org.eclipse.swt.widgets.Tree;\r
30 import org.eclipse.ui.forms.IFormColors;\r
31 import org.simantics.proconf.g3d.csg.stubs.CSGModel;\r
32 import org.simantics.db.Graph;\r
33 import org.simantics.db.GraphRequestAdapter;\r
34 import org.simantics.db.GraphRequestStatus;\r
35 import org.simantics.db.Resource;\r
36 import org.simantics.equation.stubs.SecondOrderScalarPolynomial;\r
37 import org.simantics.g2d.stubs.anim.Animation;\r
38 import org.simantics.g2d.stubs.anim.Interpolator;\r
39 import org.simantics.layer0.utils.ResourceDebugUtils;\r
40 import org.simantics.layer0.utils.IEntity;\r
41 import org.simantics.layer0.utils.EntityFactory;\r
42 import org.simantics.proconf.browsing.GraphExplorer;\r
43 import org.simantics.proconf.browsing.GraphExplorerInputFactory;\r
44 import org.simantics.proconf.g3d.common.StructuredResourceSelection;\r
45 import org.simantics.proconf.g3d.shapeeditor.ShapeEditorResources;\r
46 import org.simantics.proconf.g3d.shapeeditor.common.ViewpointGenerator;\r
47 import org.simantics.proconf.g3d.tools.OESelectionListener;\r
48 import org.simantics.proconf.g3d.tools.PropertyTree;\r
49 import org.simantics.proconf.g3d.views.SinglePageResourceEditor;\r
50 import org.simantics.utils.ui.widgets.TrackedModifyEvent;\r
51 import org.simantics.utils.ui.widgets.TrackedModifyListener;\r
52 import org.simantics.utils.ui.widgets.TrackedText;\r
53 \r
54 \r
55 public class ParameterizationEditor extends SinglePageResourceEditor { //implements ISelectionProvider{\r
56     \r
57     //ParameterizedCSGModel model;\r
58         Resource modelResource;\r
59     private TrackedText modelName = null;\r
60     StructuredResourceSelection hierarchySelection = new StructuredResourceSelection();\r
61     StructuredResourceSelection parameterSelection = new StructuredResourceSelection();\r
62     GraphExplorer parameterExplorer;\r
63     GraphExplorer hierarchyExplorer;\r
64     Button deleteParameterButton;\r
65     Button clearButton;\r
66     PropertyTree propertiesTree;\r
67     Button generateButton;\r
68     Button askButton;\r
69     Button overrideButton;\r
70     Composite parent;\r
71     \r
72     \r
73     @Override\r
74     protected String getFormText() {\r
75         return "Parameterization Editor";\r
76     }\r
77 \r
78 //    @Override\r
79 //    protected void beforeCreateWidgets() {\r
80 //        if (!(getInputResource().isInstanceOf(GlobalIdMap.get(CSGModelingOntologyMapping.PARAMETERIZED_CSG_MODEL))))\r
81 //            throw new RuntimeException("Trying to open resource that is not paramaterized CSG model");\r
82 //        model = ParameterizedCSGModelFactory.create(getInputResource());\r
83 //    }\r
84     \r
85     \r
86 \r
87     @Override\r
88     protected void createWidgets() {\r
89         createModelPropertiesGroup(newGridSection(2, 2, false, false, "Model Properties",\r
90         "Basic properties for this viewpoint"));\r
91         createParametrizationGroup(newGridSection(2, 2, false, false, "Parameterization",\r
92         "Create parameterization for selected shapes"));\r
93         //getSite().setSelectionProvider(this);\r
94     }\r
95 \r
96     @Override\r
97     public void reload(Graph graph) {\r
98        modelResource = getInputResource();\r
99        parent.getDisplay().asyncExec(new Runnable() {\r
100          @Override\r
101         public void run() {\r
102                 reload();\r
103         }  \r
104        });\r
105 \r
106     }\r
107     \r
108     public void reload() {\r
109 \r
110             hierarchyExplorer.setInput(getSessionContext(),GraphExplorerInputFactory.clone(hierarchyExplorer.getInput())\r
111                     .input(modelResource)\r
112                     .viewpoint(ViewpointGenerator.createObjectStructureViewpoint())\r
113                     .toInput());\r
114 \r
115             parameterExplorer.setInput(getSessionContext(),GraphExplorerInputFactory.clone(parameterExplorer.getInput())\r
116                     .input(modelResource)\r
117                     .viewpoint(ViewpointGenerator.createObjectSizingParameterViewpoint(ShapeEditorResources.g3dResource.HasSizingParameter))\r
118                     .toInput());\r
119 \r
120     }\r
121     \r
122     private void createParametrizationGroup(Composite parent) {\r
123         toolkit.paintBordersFor(parent);\r
124         toolkit.setBorderStyle(SWT.BORDER);\r
125         \r
126         overrideButton = toolkit.createButton(parent, "Overwrite previous parameterizations", SWT.CHECK);\r
127         overrideButton.addSelectionListener(new SelectionAdapter() {\r
128             public void widgetSelected(SelectionEvent e) {\r
129                 askButton.setEnabled(overrideButton.getSelection());\r
130                 \r
131             }\r
132         });\r
133 \r
134         \r
135         askButton = toolkit.createButton(parent, "Ask before overwriting", SWT.CHECK);\r
136         askButton.addSelectionListener(new SelectionAdapter() {\r
137             public void widgetSelected(SelectionEvent e) {\r
138                 \r
139                 \r
140             }\r
141         });\r
142         askButton.setEnabled(false);\r
143         \r
144         generateButton = toolkit.createButton(parent, "Generate linear parameterization", SWT.PUSH);\r
145         generateButton.addSelectionListener(new SelectionAdapter() {\r
146             public void widgetSelected(SelectionEvent e) {\r
147                 generateMappings();\r
148                 \r
149             }\r
150         });\r
151         generateButton.setEnabled(false);\r
152         \r
153         \r
154     }\r
155     \r
156     private CSGModel getModel(Graph graph) {\r
157         return new CSGModel(graph, modelResource);\r
158     }\r
159     \r
160     private void createModelPropertiesGroup(Composite p) {\r
161         parent = p;\r
162         toolkit.paintBordersFor(parent);\r
163         toolkit.setBorderStyle(SWT.BORDER);\r
164         \r
165         GridData gridData1 = new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1);\r
166         GridData gridData2 = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);\r
167 \r
168         // Name\r
169         Label l1 = toolkit.createLabel(parent, "Name:");\r
170         l1.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));\r
171         Text text = toolkit.createText(parent, "TODO: Insert model's name here", SWT.SINGLE);\r
172         GridData textLayout = new GridData(GridData.FILL, GridData.FILL, true, true);\r
173         text.setLayoutData(textLayout);\r
174         modelName = new TrackedText(text);\r
175         modelName.addModifyListener(new TrackedModifyListener(){\r
176                 @Override\r
177                 public void modifyText(TrackedModifyEvent e) {\r
178                         final String name = e.getText();\r
179                         getSession().asyncWrite(new GraphRequestAdapter() {\r
180                                 @Override\r
181                                 public GraphRequestStatus perform(Graph g) throws Exception {\r
182                                         getModel(g).setName(name);\r
183                                         return GraphRequestStatus.transactionComplete();\r
184                                 }\r
185                         });\r
186                 }\r
187         });\r
188         \r
189         l1.setLayoutData(gridData1);\r
190         text.setLayoutData(gridData2);\r
191         \r
192         \r
193         // Parameters\r
194         Label parameterLabel = toolkit.createLabel(parent, "Parameters:");\r
195         parameterLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));\r
196         parameterLabel.setLayoutData(gridData1);\r
197         \r
198         parameterExplorer = new GraphExplorer(parent, SWT.SINGLE); //new OntologyExplorer("ParameterExplorer", this, getInput("ParameterExplorer", model.getId()));\r
199         parameterExplorer.getViewer().addPostSelectionChangedListener(new OESelectionListener() {\r
200 \r
201            protected void resourceSelectionUpdated(StructuredResourceSelection sel) {\r
202                    parameterSelection = sel;\r
203                if (parameterSelection.size() == 0) {\r
204                    deleteParameterButton.setEnabled(false);\r
205                    clearButton.setEnabled(false);\r
206                } else {\r
207                    deleteParameterButton.setEnabled(true);\r
208                    clearButton.setEnabled(true);\r
209                }\r
210                updateGenerateButtonStatus();\r
211            }\r
212                 \r
213         });\r
214         Tree oe = parameterExplorer.getTree();\r
215         toolkit.adapt(oe, true, true);\r
216         GridData gd3 = new GridData(GridData.FILL, GridData.FILL, true, true,1,1);\r
217         gd3.heightHint = 50;\r
218         oe.setLayoutData(gd3);\r
219 //        parameterExplorer.init(getLastMemento(), ViewpointUtils.getModelledHandler(parameterExplorer.getGraph(), Builtins.DefaultViewpointId), null, ViewLabelProviderDecorationSettings.DEFAULT, new MenuAboutToShowAction(), new NullAdditionAction(), false);\r
220 //        parameterScheme = new ParameterSelectionScheme(parameterExplorer);\r
221 //        parameterExplorer.setSelectionScheme(parameterScheme);\r
222         \r
223         // Buttons to add and remove parameters\r
224         toolkit.createLabel(parent, "");\r
225         Composite buttons = toolkit.createComposite(parent);\r
226 \r
227         buttons.setLayout(new FillLayout(SWT.HORIZONTAL));\r
228         Button newParameterButton = toolkit.createButton(buttons, "New Parameter", SWT.PUSH);\r
229         newParameterButton.addSelectionListener(new SelectionAdapter() {\r
230             public void widgetSelected(SelectionEvent e) {\r
231                 InputDialog dialog = new InputDialog(ParameterizationEditor.this.getSite().getShell(),"New Parameter","Enter parameter's name","new parameter",null);\r
232                 if (dialog.open() == InputDialog.CANCEL)\r
233                     return;\r
234                 final String name = dialog.getValue();\r
235                 if (name.length() < 1) \r
236                     return; // TODO : show error\r
237                 \r
238                 getSession().asyncWrite(new GraphRequestAdapter() {\r
239                         public GraphRequestStatus perform(Graph g) throws Exception {\r
240                                 //fi.vtt.simantics.layer0.stubs.Double parameter = DoubleFactory.createDefault(g);\r
241                         //getModel(g).addStatement(ShapeEditorResources.g3dResource.HasSizingParameter, parameter);\r
242                         //parameter.setValue(new double[]{1.0});\r
243                         //parameter.setName(name);\r
244                                 Resource parameter = getModel(g).addRelatedScalarDouble(ShapeEditorResources.g3dResource.HasSizingParameter, 1.0).getResource();\r
245                                 IEntity thing = EntityFactory.create(g,parameter);\r
246                                 thing.setName(name);\r
247                                 return GraphRequestStatus.transactionComplete();\r
248                         };\r
249                 });\r
250                     \r
251                 \r
252             }\r
253         });\r
254         deleteParameterButton = toolkit.createButton(buttons, "Delete Parameter", SWT.PUSH);\r
255         deleteParameterButton.addSelectionListener(new SelectionAdapter() {\r
256             public void widgetSelected(SelectionEvent e) {\r
257                 //StructuredResourceSelection s = (StructuredResourceSelection)parameterScheme.getSelection();\r
258                 final StructuredResourceSelection s = parameterSelection;\r
259                 if (s.size() != 1)\r
260                     return;\r
261                 // we'll have to start write transaction, since we may have to change the graph\r
262                 getSession().asyncWrite(new GraphRequestAdapter() {\r
263                         boolean proceed;\r
264                         IEntity selectedParameter;\r
265                         public GraphRequestStatus perform(Graph g) throws Exception {\r
266                                  selectedParameter = EntityFactory.create(g,s.getSelectionList().get(0));\r
267                                 \r
268                         Collection<IEntity> parameters = selectedParameter.getRelatedObjects(ShapeEditorResources.g3dResource.HasSizingParameter);\r
269                         if (parameters.size() > 0) {\r
270                             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
271                             parent.getDisplay().syncExec(new Runnable() {\r
272                                 @Override\r
273                                 public void run() {\r
274                                          proceed = (dialog.open() != 1);\r
275                                 }\r
276                             });\r
277                             if (proceed) {\r
278                                                 getModel(g).removeStatement(ShapeEditorResources.g3dResource.HasSizingParameter,selectedParameter);\r
279                                         }\r
280                         }\r
281                        \r
282                         return GraphRequestStatus.transactionComplete();\r
283                         }\r
284                 });\r
285             }\r
286         });\r
287         deleteParameterButton.setEnabled(false);\r
288         \r
289         clearButton = toolkit.createButton(buttons, "Clear Parameter", SWT.PUSH);\r
290         clearButton.addSelectionListener(new SelectionAdapter() {\r
291             public void widgetSelected(SelectionEvent e) {\r
292                 final StructuredResourceSelection s = parameterSelection;\r
293                 if (s.size() != 1)\r
294                     return;\r
295                 getSession().asyncWrite(new GraphRequestAdapter() {\r
296                         boolean proceed;\r
297                         @Override\r
298                         public GraphRequestStatus perform(Graph g) throws Exception {\r
299                                  IEntity selectedParameter = EntityFactory.create(g,s.getSelectionList().get(0));\r
300                          Collection<IEntity> equations = selectedParameter.getRelatedObjects(ShapeEditorResources.equationResource.HasTarget);\r
301                                  final String name = selectedParameter.getName();\r
302                                  if (equations.size() > 0) {\r
303                                          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
304                                          parent.getDisplay().syncExec(new Runnable() {\r
305                                                  public void run() {\r
306                                                          proceed = (dialog.open() != 1);\r
307                                                  };\r
308                                          });\r
309                                          if (proceed) {\r
310                                                  for (IEntity eq : equations) {\r
311                                                          eq.removeRelatedStatements(ShapeEditorResources.equationResource.HasSource);\r
312                                                          eq.removeRelatedStatements(ShapeEditorResources.equationResource.HasTarget);\r
313                                                  }\r
314                                                  return GraphRequestStatus.transactionComplete();\r
315                                          }\r
316                                  }\r
317                                  return GraphRequestStatus.transactionCancel();\r
318                         }\r
319                 });\r
320             \r
321                 \r
322             }\r
323         });\r
324         clearButton.setEnabled(false);\r
325         \r
326         Label hierarchyLabel = toolkit.createLabel(parent, "Model Hierarchy:");\r
327         hierarchyLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));\r
328         hierarchyLabel.setLayoutData(gridData1);\r
329         \r
330         hierarchyExplorer = new GraphExplorer(parent,SWT.MULTI); //new OntologyExplorer("HierarchyExplorer", this, getInput("HierarchyExplorer", model.getId()));\r
331         Tree oeh = hierarchyExplorer.getTree();//hierarchyExplorer.getControl(parent, 1, OntologyExplorer.OntologyTree, SWT.MULTI);\r
332         toolkit.adapt(oeh, true, true);\r
333         \r
334         GridData gd4 = new GridData(GridData.FILL, GridData.FILL, true, true,1,1);\r
335         gd4.heightHint = 200;\r
336         oeh.setLayoutData(gd4);\r
337         hierarchyExplorer.getViewer().addPostSelectionChangedListener(new OESelectionListener() {\r
338 \r
339           protected void resourceSelectionUpdated(StructuredResourceSelection sel) {\r
340                   hierarchySelection = sel;\r
341               updatePropertiesTable();\r
342               updateGenerateButtonStatus();\r
343           }\r
344   \r
345           private void updatePropertiesTable() {\r
346               propertiesTree.setProperties(hierarchySelection);\r
347               \r
348           }\r
349                 \r
350         });\r
351         //hierarchyExplorer.init(getLastMemento(), ViewpointUtils.getModelledHandler(hierarchyExplorer.getGraph(), CSGModelingOntologyMapping.CSG_MODEL_HIERARCHY_VIEWPOINT), null, ViewLabelProviderDecorationSettings.DEFAULT, new MenuAboutToShowAction(), new NullAdditionAction(), false);\r
352 //        hierarchyScheme = new HierarchySelectionScheme(hierarchyExplorer);\r
353 //        hierarchyExplorer.setSelectionScheme(hierarchyScheme);\r
354 //        hierarchyExplorer.hookPageSelection(this);\r
355         Label propertiesLabel = toolkit.createLabel(parent, "Available properties:");\r
356         propertiesLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));\r
357         propertiesLabel.setLayoutData(gridData1); \r
358         \r
359         //propertiesTable = toolkit.createTable(parent, SWT.MULTI);\r
360         Tree tree = toolkit.createTree(parent, SWT.MULTI);\r
361         propertiesTree = new PropertyTree(tree,getSession());\r
362         //\r
363         GridData gd5 = new GridData(GridData.FILL, GridData.FILL, true, true,1,1);\r
364         gd5.heightHint = 200;\r
365         //propertiesTable.setLayoutData(gd5);\r
366         tree.setLayoutData(gd5);\r
367         tree.addSelectionListener(new SelectionAdapter() {\r
368 \r
369             @Override\r
370             public void widgetSelected(SelectionEvent e) {\r
371                 updateGenerateButtonStatus();\r
372             }\r
373             \r
374         });\r
375 \r
376         \r
377     }\r
378     \r
379 //    private class ParameterSelectionScheme extends AbstractSelectionScheme {\r
380 //        \r
381 //        public ParameterSelectionScheme(OntologyExplorer explorer) {\r
382 //            super(explorer);\r
383 //        }\r
384 //\r
385 //        @Override\r
386 //        protected Resource getResourceForSelection(TreeNode selected) {\r
387 //            Resource resource = explorer.getCoreResource(selected);\r
388 //            System.out.println("Parameter Tree Selection : " + resource.getId());\r
389 //            return resource;\r
390 //        }\r
391 //\r
392 //        @Override\r
393 //        protected void resourceSelectionUpdated() {\r
394 //            if (selection.size() == 0) {\r
395 //                deleteParameterButton.setEnabled(false);\r
396 //                clearButton.setEnabled(false);\r
397 //            } else {\r
398 //                deleteParameterButton.setEnabled(true);\r
399 //                clearButton.setEnabled(true);\r
400 //            }\r
401 //            updateGenerateButtonStatus();\r
402 //        }\r
403 //    }\r
404 //    \r
405 //    private class HierarchySelectionScheme extends AbstractSelectionScheme {\r
406 //\r
407 //        public HierarchySelectionScheme(OntologyExplorer explorer) {\r
408 //            super(explorer);\r
409 //        }\r
410 //        \r
411 //        @Override\r
412 //        protected Resource getResourceForSelection(TreeNode selected) {\r
413 //            Resource resource = explorer.getCoreResource(selected);\r
414 //            System.out.println("Hierarchy Tree Selection : " + resource.getId());\r
415 //            return resource;\r
416 //        }\r
417 //        \r
418 //        @Override\r
419 //        protected void resourceSelectionUpdated() {\r
420 //            updatePropertiesTable();\r
421 //            updateGenerateButtonStatus();\r
422 //        }\r
423 //\r
424 //        private void updatePropertiesTable() {\r
425 //            propertiesTree.setProperties(selection);\r
426 //            \r
427 //        }\r
428 //        \r
429 //    }\r
430     \r
431 //    private boolean contains(Resource list[], Resource value) {\r
432 //        for (int i = 0; i < list.length; i++) {\r
433 //            if (list[i].equals(value))\r
434 //                return true;\r
435 //        }\r
436 //        return false;\r
437 //    }\r
438     \r
439     private void updateGenerateButtonStatus() {\r
440         if (parameterSelection.size() == 0) {\r
441             generateButton.setEnabled(false);\r
442             return;\r
443         }\r
444         if (hierarchySelection.size() == 0) {\r
445             generateButton.setEnabled(false);\r
446             return;\r
447         }\r
448         if (propertiesTree.getTree().getSelection().length == 0) {\r
449             generateButton.setEnabled(false);\r
450             return;\r
451         }\r
452         generateButton.setEnabled(true);\r
453     }\r
454     \r
455     List<Resource> res;\r
456     \r
457     private void generateMappings() {\r
458                 final StructuredResourceSelection selectedShapes = hierarchySelection;\r
459                 final StructuredResourceSelection selectedParameter = parameterSelection;\r
460                 \r
461                 final boolean override = overrideButton.getSelection();\r
462                 final boolean ask = askButton.getSelection();\r
463                 //TreeItem[] selectedProperties = propertiesTree.getTree().getSelection();\r
464                 \r
465                 assert (selectedParameter.size() == 1);\r
466                 assert (selectedShapes.size() > 0);\r
467                 //assert(selectedProperties.length > 0);\r
468                 getSession().asyncWrite(new GraphRequestAdapter() {\r
469                         @Override\r
470                         public GraphRequestStatus perform(Graph g) throws Exception {\r
471                                 //fi.vtt.simantics.layer0.stubs.Double parameter = DoubleFactory.create(g,selectedParameter.getSelectionList().get(0));\r
472                                 IEntity parameter = EntityFactory.create(g,selectedParameter.getSelectionList().get(0));\r
473                                 Collection<IEntity> prop = parameter.getRelatedObjects(ShapeEditorResources.g3dResource.HasDefaultDoubleValue);\r
474                                 //fi.vtt.simantics.layer0.stubs.Double defaultValue;\r
475                                 double value = g.getScalarDouble(parameter.getResource());\r
476                                 if (prop.size() == 0) {\r
477                                         //defaultValue = DoubleFactory.createDefault(g);\r
478                                         //parameter.addStatement(ShapeEditorResources.g3dResource.HasDefaultDoubleValue, defaultValue);\r
479                                         parameter.addRelatedScalarDouble(ShapeEditorResources.g3dResource.HasDefaultDoubleValue, value);\r
480                                 } else {\r
481                                         //defaultValue = DoubleFactory.create(prop.iterator().next());\r
482                                         g.setScalarDouble(prop.iterator().next().getResource(),value);\r
483                                 }\r
484                                 //defaultValue.setValue(parameter.getValue());\r
485                                 final Graph graph = g;\r
486                                 parent.getDisplay().syncExec(new Runnable() {\r
487                                         public void run() {\r
488                                                 res = propertiesTree.findLeafPropertyInstances(graph, selectedShapes.getSelectionList());\r
489                                         };\r
490                                 });\r
491                                  \r
492                                 \r
493                                 double refValue = parameter.toProperty().getScalarDouble();\r
494                                 ArrayList<Resource> mappedProperties = new ArrayList<Resource>();\r
495                                 \r
496                                 for (Resource r : res) {\r
497                                         IEntity propertyThing = EntityFactory.create(g,r);\r
498                                         assert (propertyThing.isInstanceOf(g.getBuiltins().Double));\r
499                                         final String name = ResourceDebugUtils.getReadableNameForEntity(propertyThing);\r
500                                         double rb = propertyThing.toProperty().getScalarDouble();\r
501                                         System.out.println("Mapping to " + name + " " + rb);\r
502                                         Collection<IEntity> equations = propertyThing.getRelatedObjects(ShapeEditorResources.equationResource.HasSource);\r
503                                         if (equations.size() != 0) {\r
504                                                 mappedProperties.add(propertyThing.getResource());\r
505                                                 if (override) {\r
506                                                         System.out.println("Override");\r
507                                                         boolean over = true;\r
508                                                         if (ask) {\r
509                                                                 IEntity t = propertyThing;\r
510                                                                 while (t.isInstanceOf(g.getBuiltins().Property)) {\r
511                                                                         Collection<IEntity> ts = t.getRelatedObjects(g.getBuiltins().PropertyOf);\r
512                                                                         // FIXME : traverse all possible routes\r
513                                                                         t = ts.iterator().next();\r
514                                                                 }\r
515                                                                 //StructuredResourceSelection selection = new StructuredResourceSelection(t.getResource());\r
516                                                                 // TODO : do the selection!\r
517                                                                 //hierarchyScheme.setSelection(selection);\r
518                                                                 //fireSelectionChanged();\r
519                                                                 MessageDialog dialog = new MessageDialog(ParameterizationEditor.this.getSite().getShell(),\r
520                                                                                 "Override mapping",\r
521                                                                                 null,\r
522                                                                                 "Override mapping to property of highlighted shape?",\r
523                                                                                 MessageDialog.QUESTION, new String[] {\r
524                                                                                                 "Yes","No", "Cancel" }, 0);\r
525                                                                 int i = dialog.open();\r
526                                                                 if (i == 2)\r
527                                                                         return GraphRequestStatus.transactionCancel();\r
528                                                                 over = (i == 0);\r
529                                                         }\r
530                                                         if (over) {\r
531                                                                 \r
532                                                         }\r
533                                                 } else {\r
534                                                         if (equations.size() != 1) {\r
535                                                                 throw new RuntimeException("One property can have only one euquation as source function.");\r
536                                                         }\r
537                                                         IEntity equation = equations.iterator().next();\r
538                                                         if (!equation.isInstanceOf(ShapeEditorResources.equationResource.SecondOrderScalarPolynomial)) {\r
539                                                                 throw new RuntimeException("Only Second order scalar polynomials are supported");\r
540                                                         }\r
541                                                         SecondOrderScalarPolynomial s = new SecondOrderScalarPolynomial(equation);\r
542                                                         s.setA(new double[]{0.0});\r
543                                                         s.setB(new double[]{rb / refValue});\r
544                                                         s.setC(new double[]{0.0});\r
545                                                                 \r
546                                                 }\r
547                                         } else { //override\r
548                                                 // create relation\r
549                                                 SecondOrderScalarPolynomial s = SecondOrderScalarPolynomial.createDefault(g);\r
550                                                 s.setA(new double[]{0.0});\r
551                                                 s.setB(new double[]{rb / refValue});\r
552                                                 s.setC(new double[]{0.0});\r
553                                                 \r
554                                                 // FIXME : these relations have been instantiated, but addStatements won't delete them so we have to delete them manually.\r
555                                                 s.removeRelatedStatements(ShapeEditorResources.equationResource.HasTarget);\r
556                                                 s.removeRelatedStatements(ShapeEditorResources.equationResource.HasSource);\r
557                                                 \r
558                                                 parameter.addStatement(ShapeEditorResources.equationResource.HasTarget, s);\r
559                                                 \r
560                                                 s.addStatement(ShapeEditorResources.equationResource.HasTarget, propertyThing);\r
561                                                 mappedProperties.add(propertyThing.getResource());\r
562                                         }\r
563                                         \r
564                                 }\r
565                                 CSGModel model = getModel(g);\r
566                                 Collection<Animation> animations = model.getAnimation();\r
567                                 for (Animation animation : animations) {\r
568                                         Collection<Interpolator> interpolators = animation.getInterpolator();\r
569                                         for (Interpolator interpolator : interpolators) {\r
570                                                 IEntity target = interpolator.getTarget();\r
571                                                 for (Resource property : mappedProperties) {\r
572                                                         if (target.getResource().equals(property)) {\r
573                                                                 ShapeEditorResources.curveBuilder.createDefault(interpolator);\r
574                                                         }\r
575                                                 }\r
576                                         }\r
577                                 }\r
578                                 return GraphRequestStatus.transactionComplete();\r
579                         }\r
580                 });\r
581 \r
582 \r
583 \r
584         }\r
585    \r
586 }\r
587 \r