1 package org.simantics.proconf.g3d.shapeeditor.tools;
\r
3 import java.util.ArrayList;
\r
4 import java.util.Collection;
\r
5 import java.util.List;
\r
7 import org.eclipse.jface.action.IMenuManager;
\r
8 import org.eclipse.jface.action.IToolBarManager;
\r
9 import org.eclipse.jface.dialogs.InputDialog;
\r
10 import org.eclipse.jface.dialogs.MessageDialog;
\r
11 import org.eclipse.swt.SWT;
\r
12 import org.eclipse.swt.events.SelectionAdapter;
\r
13 import org.eclipse.swt.events.SelectionEvent;
\r
14 import org.eclipse.swt.graphics.Rectangle;
\r
15 import org.eclipse.swt.layout.FillLayout;
\r
16 import org.eclipse.swt.layout.FormAttachment;
\r
17 import org.eclipse.swt.layout.FormData;
\r
18 import org.eclipse.swt.layout.FormLayout;
\r
19 import org.eclipse.swt.layout.GridData;
\r
20 import org.eclipse.swt.layout.GridLayout;
\r
21 import org.eclipse.swt.widgets.Button;
\r
22 import org.eclipse.swt.widgets.Composite;
\r
23 import org.eclipse.swt.widgets.Event;
\r
24 import org.eclipse.swt.widgets.Label;
\r
25 import org.eclipse.swt.widgets.Listener;
\r
26 import org.eclipse.swt.widgets.Sash;
\r
27 import org.eclipse.swt.widgets.Tree;
\r
28 import org.eclipse.ui.forms.IFormColors;
\r
29 import org.eclipse.ui.forms.events.ExpansionAdapter;
\r
30 import org.eclipse.ui.forms.events.ExpansionEvent;
\r
31 import org.eclipse.ui.forms.widgets.FormToolkit;
\r
32 import org.eclipse.ui.forms.widgets.ScrolledForm;
\r
33 import org.eclipse.ui.forms.widgets.Section;
\r
34 import org.simantics.db.Graph;
\r
35 import org.simantics.db.GraphRequestAdapter;
\r
36 import org.simantics.db.GraphRequestStatus;
\r
37 import org.simantics.db.Resource;
\r
38 import org.simantics.equation.stubs.SecondOrderScalarPolynomial;
\r
39 import org.simantics.animation.stubs.Animation;
\r
40 import org.simantics.animation.stubs.Interpolator;
\r
41 import org.simantics.layer0.utils.EntityFactory;
\r
42 import org.simantics.layer0.utils.IEntity;
\r
43 import org.simantics.layer0.utils.ResourceDebugUtils;
\r
44 import org.simantics.proconf.browsing.GraphExplorer;
\r
45 import org.simantics.proconf.browsing.GraphExplorerInputFactory;
\r
46 import org.simantics.proconf.browsing.views.PropertyTable;
\r
47 import org.simantics.proconf.g3d.actions.ContextAction;
\r
48 import org.simantics.proconf.g3d.base.EditorContribution;
\r
49 import org.simantics.proconf.g3d.base.ThreeDimensionalEditorBase;
\r
50 import org.simantics.proconf.g3d.common.StructuredResourceSelection;
\r
51 import org.simantics.proconf.g3d.shapeeditor.ShapeEditorResources;
\r
52 import org.simantics.proconf.g3d.shapeeditor.common.ViewpointGenerator;
\r
53 import org.simantics.proconf.g3d.shapeeditor.views.ShapeEditorBase;
\r
54 import org.simantics.proconf.g3d.stubs.G3DModel;
\r
55 import org.simantics.proconf.g3d.tools.OESelectionListener;
\r
56 import org.simantics.proconf.g3d.tools.PropertyTree;
\r
57 import org.simantics.utils.ui.jface.BaseSelectionProvider;
\r
60 public class ParameterizationContribution implements EditorContribution {
\r
62 private ShapeEditorBase parent;
\r
63 private List<ContextAction> actions = new ArrayList<ContextAction>();
\r
64 private Composite sideComposite;
\r
68 public ParameterizationContribution(ThreeDimensionalEditorBase parent) {
\r
69 this.parent = (ShapeEditorBase) parent;
\r
73 public void createControl(final Composite parentComposite) {
\r
74 FormLayout flayout = new FormLayout();
\r
75 parentComposite.setLayout(flayout);
\r
76 sash = new Sash(parentComposite,SWT.VERTICAL);
\r
78 sideComposite = new Composite(parentComposite,SWT.BORDER);
\r
79 FormData data = new FormData();
\r
80 data.top = new FormAttachment(0, 0);
\r
81 data.left = new FormAttachment(0, 0);
\r
82 data.right = new FormAttachment(sash, 0, SWT.LEFT);
\r
83 data.bottom = new FormAttachment(100,0);
\r
84 this.parent.getRenderingComposite().setLayoutData(data);
\r
85 sideComposite.setLayout(new FillLayout(SWT.VERTICAL));
\r
86 data = new FormData();
\r
87 data.top = new FormAttachment(0, 0);
\r
88 data.bottom = new FormAttachment(100,0);
\r
89 data.right = new FormAttachment(100,0);
\r
90 data.left = new FormAttachment(sash,0,SWT.RIGHT);
\r
91 sideComposite.setLayoutData(data);
\r
93 final int limit = 20, percent = 50;
\r
94 final FormData sashData = new FormData();
\r
95 sashData.left = new FormAttachment (percent, 0);
\r
96 sashData.top = new FormAttachment(0, 0);
\r
97 sashData.bottom = new FormAttachment(100,0);
\r
99 sash.setLayoutData (sashData);
\r
100 sash.addListener (SWT.Selection, new Listener () {
\r
101 public void handleEvent (Event e) {
\r
102 Rectangle sashRect = sash.getBounds ();
\r
103 Rectangle shellRect = parentComposite.getClientArea ();
\r
104 int right = shellRect.width - sashRect.width - limit;
\r
105 e.x = Math.max (Math.min (e.x, right), limit);
\r
106 if (e.x != sashRect.x) {
\r
107 sashData.left = new FormAttachment (0, e.x);
\r
108 parentComposite.layout ();
\r
112 createForm(sideComposite);
\r
114 hierarchyExplorer.setInput(parent.getSessionContext(),GraphExplorerInputFactory.clone(hierarchyExplorer.getInput())
\r
115 .input(parent.getModelResource())
\r
116 .viewpoint(ViewpointGenerator.createObjectStructureViewpoint())
\r
119 // parameterExplorer.setInput(parent.getSessionContext(),GraphExplorerInputFactory.clone(parameterExplorer.getInput())
\r
120 // .input(parent.getModelResource())
\r
121 // .viewpoint(ViewpointGenerator.createObjectSizingParameterViewpoint(ShapeEditorResources.g3dResource.HasSizingParameter))
\r
123 parameterTable.setSession(parent.getSession());
\r
124 parameterTable.setInput(new StructuredResourceSelection(parent.getModelResource()));
\r
129 public void disposeControl() {
\r
130 sideComposite.dispose();
\r
136 public void dispose() {
\r
141 public void fillContextMenu(Graph graph, IMenuManager manager,
\r
142 StructuredResourceSelection selection) {
\r
147 public void fillLocalPullDown(IMenuManager manager) {
\r
152 public void fillLocalToolBar(IToolBarManager manager) {
\r
157 public Collection<ContextAction> getActions() {
\r
162 public String getName() {
\r
163 return "Parameterization";
\r
167 public void initialize(Graph graph) {
\r
172 public void run() {
\r
176 private ScrolledForm form;
\r
177 private BaseSelectionProvider defaultInputSelectionProvider = new BaseSelectionProvider();
\r
178 protected FormToolkit toolkit;
\r
182 private void createForm(Composite parent) {
\r
183 toolkit = new FormToolkit(parent.getDisplay());
\r
184 form = getToolkit().createScrolledForm(parent);
\r
186 GridLayout layout = new GridLayout(2, false);
\r
187 form.getBody().setLayout(layout);
\r
188 form.getBody().setLayoutData(
\r
189 new GridData(GridData.FILL, GridData.FILL, true, true));
\r
191 // By default make this ViewPart use a default ISelectionProvider
\r
192 // that will offer the viewparts input resource as its selection.
\r
193 // The Resource is wrapped into a ResourceSelection object.
\r
194 // Any widgets created in createWidgets may override the default
\r
195 // selection provider.
\r
196 //getEditorSite().setSelectionProvider(defaultInputSelectionProvider);
\r
198 beforeCreateWidgets();
\r
203 form.setText(getFormText());
\r
205 // Finally Set the default selection which will have an effect only
\r
206 // if nothing in createWidgets has overridden the default selection
\r
208 // ISelection s = ISelectionUtils
\r
209 // .createSelection(new StructuredResourceSelection(
\r
210 // getInputResource()));
\r
211 // defaultInputSelectionProvider.setSelection(s);
\r
215 public ScrolledForm getActiveForm() {
\r
219 protected Composite getBody() {
\r
220 return form.getBody();
\r
223 public Composite newGridSection(int formColumns, int childColumns,
\r
224 boolean equalWidth, boolean grabVertical, String text,
\r
225 String description) {
\r
226 return newGridSection(getBody(), formColumns, childColumns, equalWidth,
\r
227 grabVertical, text, description);
\r
230 public Composite newGridSection(Composite parent, int formColumns,
\r
231 int childColumns, boolean equalWidth, boolean grabVertical,
\r
232 String text, String description) {
\r
233 FormToolkit toolkit = getToolkit();
\r
235 Section section = toolkit.createSection(parent, Section.DESCRIPTION
\r
236 | Section.TWISTIE | Section.TITLE_BAR | Section.EXPANDED);
\r
237 section.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true,
\r
238 grabVertical, formColumns, 1));
\r
239 section.addExpansionListener(new ExpansionAdapter() {
\r
240 public void expansionStateChanged(ExpansionEvent e) {
\r
241 //System.out.println("SinglePageTypeEditor: expansionStateChanged " + e);
\r
245 section.setText(text);
\r
246 section.setDescription(description);
\r
247 Composite sectionClient = toolkit.createComposite(section);
\r
248 sectionClient.setLayout(new GridLayout(childColumns, equalWidth));
\r
249 sectionClient.setLayoutData(new GridData());
\r
250 section.setClient(sectionClient);
\r
251 return sectionClient;
\r
254 public FormToolkit getToolkit() {
\r
258 public void reflow(boolean flushCache) {
\r
259 //System.out.println("FormTypeEditorBase.reflow(" + flushCache + ")");
\r
260 getActiveForm().reflow(flushCache);
\r
263 protected void beforeCreateWidgets() {
\r
266 // private TrackedText modelName = null;
\r
267 StructuredResourceSelection hierarchySelection = new StructuredResourceSelection();
\r
268 StructuredResourceSelection parameterSelection = new StructuredResourceSelection();
\r
269 //GraphExplorer parameterExplorer;
\r
270 PropertyTable parameterTable;
\r
271 GraphExplorer hierarchyExplorer;
\r
272 Button deleteParameterButton;
\r
273 Button clearButton;
\r
274 PropertyTree propertiesTree;
\r
275 Button generateButton;
\r
277 Button overrideButton;
\r
279 protected String getFormText() {
\r
280 return "Parameterization Editor";
\r
283 protected void createWidgets() {
\r
284 createModelPropertiesGroup(newGridSection(2, 1, false, false, "Model Properties",
\r
285 "Basic properties for this viewpoint"));
\r
286 createParametrizationGroup(newGridSection(2, 1, false, false, "Parameterization",
\r
287 "Create parameterization for selected shapes"));
\r
288 //getSite().setSelectionProvider(this);
\r
291 private void createParametrizationGroup(Composite parent) {
\r
292 toolkit.paintBordersFor(parent);
\r
293 toolkit.setBorderStyle(SWT.BORDER);
\r
295 overrideButton = toolkit.createButton(parent, "Overwrite previous parameterizations", SWT.CHECK);
\r
296 overrideButton.addSelectionListener(new SelectionAdapter() {
\r
297 public void widgetSelected(SelectionEvent e) {
\r
298 askButton.setEnabled(overrideButton.getSelection());
\r
304 askButton = toolkit.createButton(parent, "Ask before overwriting", SWT.CHECK);
\r
305 askButton.addSelectionListener(new SelectionAdapter() {
\r
306 public void widgetSelected(SelectionEvent e) {
\r
311 askButton.setEnabled(false);
\r
313 generateButton = toolkit.createButton(parent, "Generate linear parameterization", SWT.PUSH);
\r
314 generateButton.addSelectionListener(new SelectionAdapter() {
\r
315 public void widgetSelected(SelectionEvent e) {
\r
316 generateMappings();
\r
320 generateButton.setEnabled(false);
\r
325 private void createModelPropertiesGroup(final Composite parent) {
\r
327 toolkit.paintBordersFor(parent);
\r
328 toolkit.setBorderStyle(SWT.BORDER);
\r
330 GridData gridData1 = new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1);
\r
334 Label parameterLabel = toolkit.createLabel(parent, "Parameters:");
\r
335 parameterLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
\r
336 parameterLabel.setLayoutData(gridData1);
\r
338 // parameterExplorer = new GraphExplorer(parent, SWT.SINGLE); //new OntologyExplorer("ParameterExplorer", this, getInput("ParameterExplorer", model.getId()));
\r
339 // parameterExplorer.getViewer().addPostSelectionChangedListener(new OESelectionListener() {
\r
341 // protected void resourceSelectionUpdated(StructuredResourceSelection sel) {
\r
342 // parameterSelection = sel;
\r
343 // if (parameterSelection.size() == 0) {
\r
344 // deleteParameterButton.setEnabled(false);
\r
345 // clearButton.setEnabled(false);
\r
347 // deleteParameterButton.setEnabled(true);
\r
348 // clearButton.setEnabled(true);
\r
350 // updateGenerateButtonStatus();
\r
354 // Tree oe = parameterExplorer.getTree();
\r
355 // toolkit.adapt(oe, true, true);
\r
357 parameterTable = new PropertyTable(parent,SWT.NONE);
\r
358 parameterTable.getViewer().addPostSelectionChangedListener(new OESelectionListener() {
\r
360 protected void resourceSelectionUpdated(StructuredResourceSelection sel) {
\r
361 parameterSelection = sel;
\r
362 if (parameterSelection.size() == 0) {
\r
363 deleteParameterButton.setEnabled(false);
\r
364 clearButton.setEnabled(false);
\r
366 deleteParameterButton.setEnabled(true);
\r
367 clearButton.setEnabled(true);
\r
369 updateGenerateButtonStatus();
\r
374 GridData gd3 = new GridData(GridData.FILL, GridData.FILL, true, true,1,1);
\r
375 gd3.heightHint = 50;
\r
376 //oe.setLayoutData(gd3);
\r
378 parameterTable.setLayoutData(gd3);
\r
380 // Buttons to add and remove parameters
\r
381 toolkit.createLabel(parent, "");
\r
382 Composite buttons = toolkit.createComposite(parent);
\r
384 buttons.setLayout(new FillLayout(SWT.HORIZONTAL));
\r
385 Button newParameterButton = toolkit.createButton(buttons, "New Parameter", SWT.PUSH);
\r
386 newParameterButton.addSelectionListener(new SelectionAdapter() {
\r
387 public void widgetSelected(SelectionEvent e) {
\r
388 InputDialog dialog = new InputDialog(ParameterizationContribution.this.parent.getRenderingComposite().getShell(),"New Parameter","Enter parameter's name","new parameter",null);
\r
389 if (dialog.open() == InputDialog.CANCEL)
\r
391 final String name = dialog.getValue();
\r
392 if (name.length() < 1)
\r
393 return; // TODO : show error
\r
395 ParameterizationContribution.this.parent.getSession().asyncWrite(new GraphRequestAdapter() {
\r
396 public GraphRequestStatus perform(Graph g) throws Exception {
\r
397 //fi.vtt.simantics.layer0.stubs.Double parameter = DoubleFactory.createDefault(g);
\r
398 //getModel(g).addStatement(ShapeEditorResources.g3dResource.HasSizingParameter, parameter);
\r
399 //parameter.setValue(new double[]{1.0});
\r
400 //parameter.setName(name);
\r
401 Resource parameter = ParameterizationContribution.this.parent.getModel(g).addRelatedScalarDouble(ShapeEditorResources.g3dResource.HasSizingParameter, 1.0).getResource();
\r
402 IEntity thing = EntityFactory.create(g,parameter);
\r
403 thing.setName(name);
\r
404 return GraphRequestStatus.transactionComplete();
\r
411 deleteParameterButton = toolkit.createButton(buttons, "Delete Parameter", SWT.PUSH);
\r
412 deleteParameterButton.addSelectionListener(new SelectionAdapter() {
\r
413 public void widgetSelected(SelectionEvent e) {
\r
414 //StructuredResourceSelection s = (StructuredResourceSelection)parameterScheme.getSelection();
\r
415 final StructuredResourceSelection s = parameterSelection;
\r
418 // we'll have to start write transaction, since we may have to change the graph
\r
419 ParameterizationContribution.this.parent.getSession().asyncWrite(new GraphRequestAdapter() {
\r
421 IEntity selectedParameter;
\r
422 public GraphRequestStatus perform(Graph g) throws Exception {
\r
423 selectedParameter = EntityFactory.create(g,s.getSelectionList().get(0));
\r
425 Collection<IEntity> parameters = selectedParameter.getRelatedObjects(ShapeEditorResources.g3dResource.HasSizingParameter);
\r
426 if (parameters.size() > 0) {
\r
427 final MessageDialog dialog = new MessageDialog(ParameterizationContribution.this.parent.getRenderingComposite().getShell(),"Deleting a parameter",null,"Parameter is in use, doe you wan't to remove it?",MessageDialog.QUESTION,new String[]{"OK","Cancel"},1);
\r
428 parent.getDisplay().syncExec(new Runnable() {
\r
430 public void run() {
\r
431 proceed = (dialog.open() != 1);
\r
435 ParameterizationContribution.this.parent.getModel(g).removeStatement(ShapeEditorResources.g3dResource.HasSizingParameter,selectedParameter);
\r
439 return GraphRequestStatus.transactionComplete();
\r
444 deleteParameterButton.setEnabled(false);
\r
446 clearButton = toolkit.createButton(buttons, "Clear Parameter", SWT.PUSH);
\r
447 clearButton.addSelectionListener(new SelectionAdapter() {
\r
448 public void widgetSelected(SelectionEvent e) {
\r
449 final StructuredResourceSelection s = parameterSelection;
\r
452 ParameterizationContribution.this.parent.getSession().asyncWrite(new GraphRequestAdapter() {
\r
455 public GraphRequestStatus perform(Graph g) throws Exception {
\r
456 IEntity selectedParameter = EntityFactory.create(g,s.getSelectionList().get(0));
\r
457 Collection<IEntity> equations = selectedParameter.getRelatedObjects(ShapeEditorResources.equationResource.HasTarget);
\r
458 final String name = selectedParameter.getName();
\r
459 if (equations.size() > 0) {
\r
460 final MessageDialog dialog = new MessageDialog(ParameterizationContribution.this.parent.getRenderingComposite().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
461 parent.getDisplay().syncExec(new Runnable() {
\r
462 public void run() {
\r
463 proceed = (dialog.open() != 1);
\r
467 for (IEntity eq : equations) {
\r
468 eq.removeRelatedStatements(ShapeEditorResources.equationResource.HasSource);
\r
469 eq.removeRelatedStatements(ShapeEditorResources.equationResource.HasTarget);
\r
471 return GraphRequestStatus.transactionComplete();
\r
474 return GraphRequestStatus.transactionCancel();
\r
481 clearButton.setEnabled(false);
\r
483 Label hierarchyLabel = toolkit.createLabel(parent, "Model Hierarchy:");
\r
484 hierarchyLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
\r
485 hierarchyLabel.setLayoutData(gridData1);
\r
487 hierarchyExplorer = new GraphExplorer(parent,SWT.MULTI); //new OntologyExplorer("HierarchyExplorer", this, getInput("HierarchyExplorer", model.getId()));
\r
488 Tree oeh = hierarchyExplorer.getTree();//hierarchyExplorer.getControl(parent, 1, OntologyExplorer.OntologyTree, SWT.MULTI);
\r
489 toolkit.adapt(oeh, true, true);
\r
491 GridData gd4 = new GridData(GridData.FILL, GridData.FILL, true, true,1,1);
\r
492 gd4.heightHint = 200;
\r
493 oeh.setLayoutData(gd4);
\r
494 hierarchyExplorer.getViewer().addPostSelectionChangedListener(new OESelectionListener() {
\r
496 protected void resourceSelectionUpdated(StructuredResourceSelection sel) {
\r
497 hierarchySelection = sel;
\r
498 updatePropertiesTable();
\r
499 updateGenerateButtonStatus();
\r
502 private void updatePropertiesTable() {
\r
503 propertiesTree.setProperties(hierarchySelection);
\r
509 Label propertiesLabel = toolkit.createLabel(parent, "Available properties:");
\r
510 propertiesLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
\r
511 propertiesLabel.setLayoutData(gridData1);
\r
513 //propertiesTable = toolkit.createTable(parent, SWT.MULTI);
\r
514 Tree tree = toolkit.createTree(parent, SWT.MULTI);
\r
515 propertiesTree = new PropertyTree(tree,ParameterizationContribution.this.parent.getSession());
\r
517 GridData gd5 = new GridData(GridData.FILL, GridData.FILL, true, true,1,1);
\r
518 gd5.heightHint = 200;
\r
519 //propertiesTable.setLayoutData(gd5);
\r
520 tree.setLayoutData(gd5);
\r
521 tree.addSelectionListener(new SelectionAdapter() {
\r
524 public void widgetSelected(SelectionEvent e) {
\r
525 updateGenerateButtonStatus();
\r
533 private void updateGenerateButtonStatus() {
\r
534 if (parameterSelection.size() == 0) {
\r
535 generateButton.setEnabled(false);
\r
538 if (hierarchySelection.size() == 0) {
\r
539 generateButton.setEnabled(false);
\r
542 if (propertiesTree.getTree().getSelection().length == 0) {
\r
543 generateButton.setEnabled(false);
\r
546 generateButton.setEnabled(true);
\r
549 List<Resource> res;
\r
551 private void generateMappings() {
\r
552 final StructuredResourceSelection selectedShapes = hierarchySelection;
\r
553 final StructuredResourceSelection selectedParameter = parameterSelection;
\r
555 final boolean override = overrideButton.getSelection();
\r
556 final boolean ask = askButton.getSelection();
\r
557 //TreeItem[] selectedProperties = propertiesTree.getTree().getSelection();
\r
559 assert (selectedParameter.size() == 1);
\r
560 assert (selectedShapes.size() > 0);
\r
561 //assert(selectedProperties.length > 0);
\r
562 parent.getSession().asyncWrite(new GraphRequestAdapter() {
\r
564 public GraphRequestStatus perform(Graph g) throws Exception {
\r
565 //fi.vtt.simantics.layer0.stubs.Double parameter = DoubleFactory.create(g,selectedParameter.getSelectionList().get(0));
\r
566 IEntity parameter = EntityFactory.create(g,selectedParameter.getSelectionList().get(0));
\r
567 Collection<IEntity> prop = parameter.getRelatedObjects(ShapeEditorResources.g3dResource.HasDefaultDoubleValue);
\r
568 //fi.vtt.simantics.layer0.stubs.Double defaultValue;
\r
569 double value = g.getScalarDouble(parameter.getResource());
\r
570 if (prop.size() == 0) {
\r
571 //defaultValue = DoubleFactory.createDefault(g);
\r
572 //parameter.addStatement(ShapeEditorResources.g3dResource.HasDefaultDoubleValue, defaultValue);
\r
573 parameter.addRelatedScalarDouble(ShapeEditorResources.g3dResource.HasDefaultDoubleValue, value);
\r
575 //defaultValue = DoubleFactory.create(prop.iterator().next());
\r
576 g.setScalarDouble(prop.iterator().next().getResource(),value);
\r
578 //defaultValue.setValue(parameter.getValue());
\r
579 final Graph graph = g;
\r
580 parent.getRenderingComposite().getDisplay().syncExec(new Runnable() {
\r
581 public void run() {
\r
582 res = propertiesTree.findLeafPropertyInstances(graph, selectedShapes.getSelectionList());
\r
587 double refValue = parameter.toProperty().getScalarDouble();
\r
588 ArrayList<Resource> mappedProperties = new ArrayList<Resource>();
\r
590 for (Resource r : res) {
\r
591 IEntity propertyThing = EntityFactory.create(g,r);
\r
592 assert (propertyThing.isInstanceOf(g.getBuiltins().Double));
\r
593 final String name = ResourceDebugUtils.getReadableNameForEntity(propertyThing);
\r
594 double rb = propertyThing.toProperty().getScalarDouble();
\r
595 System.out.println("Mapping to " + name + " " + rb);
\r
596 Collection<IEntity> equations = propertyThing.getRelatedObjects(ShapeEditorResources.equationResource.HasSource);
\r
597 if (equations.size() != 0) {
\r
598 mappedProperties.add(propertyThing.getResource());
\r
600 System.out.println("Override");
\r
601 boolean over = true;
\r
603 IEntity t = propertyThing;
\r
604 while (t.isInstanceOf(g.getBuiltins().Property)) {
\r
605 Collection<IEntity> ts = t.getRelatedObjects(g.getBuiltins().PropertyOf);
\r
606 // FIXME : traverse all possible routes
\r
607 t = ts.iterator().next();
\r
609 //StructuredResourceSelection selection = new StructuredResourceSelection(t.getResource());
\r
610 // TODO : do the selection!
\r
611 //hierarchyScheme.setSelection(selection);
\r
612 //fireSelectionChanged();
\r
613 MessageDialog dialog = new MessageDialog(ParameterizationContribution.this.parent.getRenderingComposite().getShell(),
\r
614 "Override mapping",
\r
616 "Override mapping to property of highlighted shape?",
\r
617 MessageDialog.QUESTION, new String[] {
\r
618 "Yes","No", "Cancel" }, 0);
\r
619 int i = dialog.open();
\r
621 return GraphRequestStatus.transactionCancel();
\r
628 if (equations.size() != 1) {
\r
629 throw new RuntimeException("One property can have only one euquation as source function.");
\r
631 IEntity equation = equations.iterator().next();
\r
632 if (!equation.isInstanceOf(ShapeEditorResources.equationResource.SecondOrderScalarPolynomial)) {
\r
633 throw new RuntimeException("Only Second order scalar polynomials are supported");
\r
635 SecondOrderScalarPolynomial s = new SecondOrderScalarPolynomial(equation);
\r
636 s.setA(new double[]{0.0});
\r
637 s.setB(new double[]{rb / refValue});
\r
638 s.setC(new double[]{0.0});
\r
641 } else { //override
\r
643 SecondOrderScalarPolynomial s = SecondOrderScalarPolynomial.createDefault(g);
\r
644 s.setA(new double[]{0.0});
\r
645 s.setB(new double[]{rb / refValue});
\r
646 s.setC(new double[]{0.0});
\r
648 // these relations have been instantiated, but addStatements won't delete them so we have to delete them manually.
\r
649 s.removeRelatedStatements(ShapeEditorResources.equationResource.HasTarget);
\r
650 s.removeRelatedStatements(ShapeEditorResources.equationResource.HasSource);
\r
652 parameter.addStatement(ShapeEditorResources.equationResource.HasTarget, s);
\r
654 s.addStatement(ShapeEditorResources.equationResource.HasTarget, propertyThing);
\r
655 mappedProperties.add(propertyThing.getResource());
\r
659 G3DModel model = parent.getModel(g);
\r
660 Collection<Animation> animations = model.getAnimation();
\r
661 for (Animation animation : animations) {
\r
662 Collection<Interpolator> interpolators = animation.getInterpolator();
\r
663 for (Interpolator interpolator : interpolators) {
\r
664 IEntity target = interpolator.getTarget();
\r
665 for (Resource property : mappedProperties) {
\r
666 if (target.getResource().equals(property)) {
\r
667 ShapeEditorResources.curveBuilder.createDefault(interpolator);
\r
672 return GraphRequestStatus.transactionComplete();
\r