1 /*******************************************************************************
\r
2 * Copyright (c) 2007- VTT Technical Research Centre of Finland.
\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
9 * VTT Technical Research Centre of Finland - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package org.simantics.proconf.g3d.shapeeditor.tools;
\r
13 import java.util.ArrayList;
\r
14 import java.util.Collection;
\r
15 import java.util.List;
\r
17 import org.eclipse.jface.action.IMenuManager;
\r
18 import org.eclipse.jface.action.IToolBarManager;
\r
19 import org.eclipse.jface.dialogs.InputDialog;
\r
20 import org.eclipse.jface.dialogs.MessageDialog;
\r
21 import org.eclipse.swt.SWT;
\r
22 import org.eclipse.swt.events.SelectionAdapter;
\r
23 import org.eclipse.swt.events.SelectionEvent;
\r
24 import org.eclipse.swt.graphics.Rectangle;
\r
25 import org.eclipse.swt.layout.FillLayout;
\r
26 import org.eclipse.swt.layout.FormAttachment;
\r
27 import org.eclipse.swt.layout.FormData;
\r
28 import org.eclipse.swt.layout.FormLayout;
\r
29 import org.eclipse.swt.layout.GridData;
\r
30 import org.eclipse.swt.layout.GridLayout;
\r
31 import org.eclipse.swt.widgets.Button;
\r
32 import org.eclipse.swt.widgets.Composite;
\r
33 import org.eclipse.swt.widgets.Event;
\r
34 import org.eclipse.swt.widgets.Label;
\r
35 import org.eclipse.swt.widgets.Listener;
\r
36 import org.eclipse.swt.widgets.Sash;
\r
37 import org.eclipse.swt.widgets.Tree;
\r
38 import org.eclipse.ui.forms.IFormColors;
\r
39 import org.eclipse.ui.forms.events.ExpansionAdapter;
\r
40 import org.eclipse.ui.forms.events.ExpansionEvent;
\r
41 import org.eclipse.ui.forms.widgets.FormToolkit;
\r
42 import org.eclipse.ui.forms.widgets.ScrolledForm;
\r
43 import org.eclipse.ui.forms.widgets.Section;
\r
44 import org.simantics.db.Graph;
\r
45 import org.simantics.db.GraphRequestAdapter;
\r
46 import org.simantics.db.GraphRequestStatus;
\r
47 import org.simantics.db.Resource;
\r
48 import org.simantics.equation.stubs.SecondOrderScalarPolynomial;
\r
49 import org.simantics.animation.stubs.Animation;
\r
50 import org.simantics.animation.stubs.Interpolator;
\r
51 import org.simantics.layer0.utils.EntityFactory;
\r
52 import org.simantics.layer0.utils.IEntity;
\r
53 import org.simantics.layer0.utils.ResourceDebugUtils;
\r
54 import org.simantics.proconf.browsing.GraphExplorer;
\r
55 import org.simantics.proconf.browsing.GraphExplorerInputFactory;
\r
56 import org.simantics.proconf.browsing.views.PropertyTable;
\r
57 import org.simantics.proconf.g3d.actions.ContextAction;
\r
58 import org.simantics.proconf.g3d.base.EditorContribution;
\r
59 import org.simantics.proconf.g3d.base.ThreeDimensionalEditorBase;
\r
60 import org.simantics.proconf.g3d.common.StructuredResourceSelection;
\r
61 import org.simantics.proconf.g3d.shapeeditor.ShapeEditorResources;
\r
62 import org.simantics.proconf.g3d.shapeeditor.common.ViewpointGenerator;
\r
63 import org.simantics.proconf.g3d.shapeeditor.views.ShapeEditorBase;
\r
64 import org.simantics.proconf.g3d.stubs.G3DModel;
\r
65 import org.simantics.proconf.g3d.tools.OESelectionListener;
\r
66 import org.simantics.proconf.g3d.tools.PropertyTree;
\r
67 import org.simantics.utils.ui.jface.BaseSelectionProvider;
\r
70 public class ParameterizationContribution implements EditorContribution {
\r
72 private ShapeEditorBase parent;
\r
73 private List<ContextAction> actions = new ArrayList<ContextAction>();
\r
74 private Composite sideComposite;
\r
78 public ParameterizationContribution(ThreeDimensionalEditorBase parent) {
\r
79 this.parent = (ShapeEditorBase) parent;
\r
83 public void createControl(final Composite parentComposite) {
\r
84 FormLayout flayout = new FormLayout();
\r
85 parentComposite.setLayout(flayout);
\r
86 sash = new Sash(parentComposite,SWT.VERTICAL);
\r
88 sideComposite = new Composite(parentComposite,SWT.BORDER);
\r
89 FormData data = new FormData();
\r
90 data.top = new FormAttachment(0, 0);
\r
91 data.left = new FormAttachment(0, 0);
\r
92 data.right = new FormAttachment(sash, 0, SWT.LEFT);
\r
93 data.bottom = new FormAttachment(100,0);
\r
94 this.parent.getRenderingComposite().setLayoutData(data);
\r
95 sideComposite.setLayout(new FillLayout(SWT.VERTICAL));
\r
96 data = new FormData();
\r
97 data.top = new FormAttachment(0, 0);
\r
98 data.bottom = new FormAttachment(100,0);
\r
99 data.right = new FormAttachment(100,0);
\r
100 data.left = new FormAttachment(sash,0,SWT.RIGHT);
\r
101 sideComposite.setLayoutData(data);
\r
103 final int limit = 20, percent = 50;
\r
104 final FormData sashData = new FormData();
\r
105 sashData.left = new FormAttachment (percent, 0);
\r
106 sashData.top = new FormAttachment(0, 0);
\r
107 sashData.bottom = new FormAttachment(100,0);
\r
109 sash.setLayoutData (sashData);
\r
110 sash.addListener (SWT.Selection, new Listener () {
\r
111 public void handleEvent (Event e) {
\r
112 Rectangle sashRect = sash.getBounds ();
\r
113 Rectangle shellRect = parentComposite.getClientArea ();
\r
114 int right = shellRect.width - sashRect.width - limit;
\r
115 e.x = Math.max (Math.min (e.x, right), limit);
\r
116 if (e.x != sashRect.x) {
\r
117 sashData.left = new FormAttachment (0, e.x);
\r
118 parentComposite.layout ();
\r
122 createForm(sideComposite);
\r
124 hierarchyExplorer.setInput(parent.getSessionContext(),GraphExplorerInputFactory.clone(hierarchyExplorer.getInput())
\r
125 .input(parent.getModelResource())
\r
126 .viewpoint(ViewpointGenerator.createObjectStructureViewpoint())
\r
129 // parameterExplorer.setInput(parent.getSessionContext(),GraphExplorerInputFactory.clone(parameterExplorer.getInput())
\r
130 // .input(parent.getModelResource())
\r
131 // .viewpoint(ViewpointGenerator.createObjectSizingParameterViewpoint(ShapeEditorResources.g3dResource.HasSizingParameter))
\r
133 parameterTable.setSession(parent.getSession());
\r
134 parameterTable.setInput(new StructuredResourceSelection(parent.getModelResource()));
\r
139 public void disposeControl() {
\r
140 sideComposite.dispose();
\r
146 public void dispose() {
\r
151 public void fillContextMenu(Graph graph, IMenuManager manager,
\r
152 StructuredResourceSelection selection) {
\r
157 public void fillLocalPullDown(IMenuManager manager) {
\r
162 public void fillLocalToolBar(IToolBarManager manager) {
\r
167 public Collection<ContextAction> getActions() {
\r
172 public String getName() {
\r
173 return "Parameterization";
\r
177 public void initialize(Graph graph) {
\r
182 public void run() {
\r
186 private ScrolledForm form;
\r
187 private BaseSelectionProvider defaultInputSelectionProvider = new BaseSelectionProvider();
\r
188 protected FormToolkit toolkit;
\r
192 private void createForm(Composite parent) {
\r
193 toolkit = new FormToolkit(parent.getDisplay());
\r
194 form = getToolkit().createScrolledForm(parent);
\r
196 GridLayout layout = new GridLayout(2, false);
\r
197 form.getBody().setLayout(layout);
\r
198 form.getBody().setLayoutData(
\r
199 new GridData(GridData.FILL, GridData.FILL, true, true));
\r
201 // By default make this ViewPart use a default ISelectionProvider
\r
202 // that will offer the viewparts input resource as its selection.
\r
203 // The Resource is wrapped into a ResourceSelection object.
\r
204 // Any widgets created in createWidgets may override the default
\r
205 // selection provider.
\r
206 //getEditorSite().setSelectionProvider(defaultInputSelectionProvider);
\r
208 beforeCreateWidgets();
\r
213 form.setText(getFormText());
\r
215 // Finally Set the default selection which will have an effect only
\r
216 // if nothing in createWidgets has overridden the default selection
\r
218 // ISelection s = ISelectionUtils
\r
219 // .createSelection(new StructuredResourceSelection(
\r
220 // getInputResource()));
\r
221 // defaultInputSelectionProvider.setSelection(s);
\r
225 public ScrolledForm getActiveForm() {
\r
229 protected Composite getBody() {
\r
230 return form.getBody();
\r
233 public Composite newGridSection(int formColumns, int childColumns,
\r
234 boolean equalWidth, boolean grabVertical, String text,
\r
235 String description) {
\r
236 return newGridSection(getBody(), formColumns, childColumns, equalWidth,
\r
237 grabVertical, text, description);
\r
240 public Composite newGridSection(Composite parent, int formColumns,
\r
241 int childColumns, boolean equalWidth, boolean grabVertical,
\r
242 String text, String description) {
\r
243 FormToolkit toolkit = getToolkit();
\r
245 Section section = toolkit.createSection(parent, Section.DESCRIPTION
\r
246 | Section.TWISTIE | Section.TITLE_BAR | Section.EXPANDED);
\r
247 section.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true,
\r
248 grabVertical, formColumns, 1));
\r
249 section.addExpansionListener(new ExpansionAdapter() {
\r
250 public void expansionStateChanged(ExpansionEvent e) {
\r
251 //System.out.println("SinglePageTypeEditor: expansionStateChanged " + e);
\r
255 section.setText(text);
\r
256 section.setDescription(description);
\r
257 Composite sectionClient = toolkit.createComposite(section);
\r
258 sectionClient.setLayout(new GridLayout(childColumns, equalWidth));
\r
259 sectionClient.setLayoutData(new GridData());
\r
260 section.setClient(sectionClient);
\r
261 return sectionClient;
\r
264 public FormToolkit getToolkit() {
\r
268 public void reflow(boolean flushCache) {
\r
269 //System.out.println("FormTypeEditorBase.reflow(" + flushCache + ")");
\r
270 getActiveForm().reflow(flushCache);
\r
273 protected void beforeCreateWidgets() {
\r
276 // private TrackedText modelName = null;
\r
277 StructuredResourceSelection hierarchySelection = new StructuredResourceSelection();
\r
278 StructuredResourceSelection parameterSelection = new StructuredResourceSelection();
\r
279 //GraphExplorer parameterExplorer;
\r
280 PropertyTable parameterTable;
\r
281 GraphExplorer hierarchyExplorer;
\r
282 Button deleteParameterButton;
\r
283 Button clearButton;
\r
284 PropertyTree propertiesTree;
\r
285 Button generateButton;
\r
287 Button overrideButton;
\r
289 protected String getFormText() {
\r
290 return "Parameterization Editor";
\r
293 protected void createWidgets() {
\r
294 createModelPropertiesGroup(newGridSection(2, 1, false, false, "Model Properties",
\r
295 "Basic properties for this viewpoint"));
\r
296 createParametrizationGroup(newGridSection(2, 1, false, false, "Parameterization",
\r
297 "Create parameterization for selected shapes"));
\r
298 //getSite().setSelectionProvider(this);
\r
301 private void createParametrizationGroup(Composite parent) {
\r
302 toolkit.paintBordersFor(parent);
\r
303 toolkit.setBorderStyle(SWT.BORDER);
\r
305 overrideButton = toolkit.createButton(parent, "Overwrite previous parameterizations", SWT.CHECK);
\r
306 overrideButton.addSelectionListener(new SelectionAdapter() {
\r
307 public void widgetSelected(SelectionEvent e) {
\r
308 askButton.setEnabled(overrideButton.getSelection());
\r
314 askButton = toolkit.createButton(parent, "Ask before overwriting", SWT.CHECK);
\r
315 askButton.addSelectionListener(new SelectionAdapter() {
\r
316 public void widgetSelected(SelectionEvent e) {
\r
321 askButton.setEnabled(false);
\r
323 generateButton = toolkit.createButton(parent, "Generate linear parameterization", SWT.PUSH);
\r
324 generateButton.addSelectionListener(new SelectionAdapter() {
\r
325 public void widgetSelected(SelectionEvent e) {
\r
326 generateMappings();
\r
330 generateButton.setEnabled(false);
\r
335 private void createModelPropertiesGroup(final Composite parent) {
\r
337 toolkit.paintBordersFor(parent);
\r
338 toolkit.setBorderStyle(SWT.BORDER);
\r
340 GridData gridData1 = new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1);
\r
344 Label parameterLabel = toolkit.createLabel(parent, "Parameters:");
\r
345 parameterLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
\r
346 parameterLabel.setLayoutData(gridData1);
\r
348 // parameterExplorer = new GraphExplorer(parent, SWT.SINGLE); //new OntologyExplorer("ParameterExplorer", this, getInput("ParameterExplorer", model.getId()));
\r
349 // parameterExplorer.getViewer().addPostSelectionChangedListener(new OESelectionListener() {
\r
351 // protected void resourceSelectionUpdated(StructuredResourceSelection sel) {
\r
352 // parameterSelection = sel;
\r
353 // if (parameterSelection.size() == 0) {
\r
354 // deleteParameterButton.setEnabled(false);
\r
355 // clearButton.setEnabled(false);
\r
357 // deleteParameterButton.setEnabled(true);
\r
358 // clearButton.setEnabled(true);
\r
360 // updateGenerateButtonStatus();
\r
364 // Tree oe = parameterExplorer.getTree();
\r
365 // toolkit.adapt(oe, true, true);
\r
367 parameterTable = new PropertyTable(parent,SWT.NONE);
\r
368 parameterTable.getViewer().addPostSelectionChangedListener(new OESelectionListener() {
\r
370 protected void resourceSelectionUpdated(StructuredResourceSelection sel) {
\r
371 parameterSelection = sel;
\r
372 if (parameterSelection.size() == 0) {
\r
373 deleteParameterButton.setEnabled(false);
\r
374 clearButton.setEnabled(false);
\r
376 deleteParameterButton.setEnabled(true);
\r
377 clearButton.setEnabled(true);
\r
379 updateGenerateButtonStatus();
\r
384 GridData gd3 = new GridData(GridData.FILL, GridData.FILL, true, true,1,1);
\r
385 gd3.heightHint = 50;
\r
386 //oe.setLayoutData(gd3);
\r
388 parameterTable.setLayoutData(gd3);
\r
390 // Buttons to add and remove parameters
\r
391 toolkit.createLabel(parent, "");
\r
392 Composite buttons = toolkit.createComposite(parent);
\r
394 buttons.setLayout(new FillLayout(SWT.HORIZONTAL));
\r
395 Button newParameterButton = toolkit.createButton(buttons, "New Parameter", SWT.PUSH);
\r
396 newParameterButton.addSelectionListener(new SelectionAdapter() {
\r
397 public void widgetSelected(SelectionEvent e) {
\r
398 InputDialog dialog = new InputDialog(ParameterizationContribution.this.parent.getRenderingComposite().getShell(),"New Parameter","Enter parameter's name","new parameter",null);
\r
399 if (dialog.open() == InputDialog.CANCEL)
\r
401 final String name = dialog.getValue();
\r
402 if (name.length() < 1)
\r
403 return; // TODO : show error
\r
405 ParameterizationContribution.this.parent.getSession().asyncWrite(new GraphRequestAdapter() {
\r
406 public GraphRequestStatus perform(Graph g) throws Exception {
\r
407 //fi.vtt.simantics.layer0.stubs.Double parameter = DoubleFactory.createDefault(g);
\r
408 //getModel(g).addStatement(ShapeEditorResources.g3dResource.HasSizingParameter, parameter);
\r
409 //parameter.setValue(new double[]{1.0});
\r
410 //parameter.setName(name);
\r
411 Resource parameter = ParameterizationContribution.this.parent.getModel(g).addRelatedScalarDouble(ShapeEditorResources.g3dResource.HasSizingParameter, 1.0).getResource();
\r
412 IEntity thing = EntityFactory.create(g,parameter);
\r
413 thing.setName(name);
\r
414 return GraphRequestStatus.transactionComplete();
\r
421 deleteParameterButton = toolkit.createButton(buttons, "Delete Parameter", SWT.PUSH);
\r
422 deleteParameterButton.addSelectionListener(new SelectionAdapter() {
\r
423 public void widgetSelected(SelectionEvent e) {
\r
424 //StructuredResourceSelection s = (StructuredResourceSelection)parameterScheme.getSelection();
\r
425 final StructuredResourceSelection s = parameterSelection;
\r
428 // we'll have to start write transaction, since we may have to change the graph
\r
429 ParameterizationContribution.this.parent.getSession().asyncWrite(new GraphRequestAdapter() {
\r
431 IEntity selectedParameter;
\r
432 public GraphRequestStatus perform(Graph g) throws Exception {
\r
433 selectedParameter = EntityFactory.create(g,s.getSelectionList().get(0));
\r
435 Collection<IEntity> parameters = selectedParameter.getRelatedObjects(ShapeEditorResources.g3dResource.HasSizingParameter);
\r
436 if (parameters.size() > 0) {
\r
437 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
438 parent.getDisplay().syncExec(new Runnable() {
\r
440 public void run() {
\r
441 proceed = (dialog.open() != 1);
\r
445 ParameterizationContribution.this.parent.getModel(g).removeStatement(ShapeEditorResources.g3dResource.HasSizingParameter,selectedParameter);
\r
449 return GraphRequestStatus.transactionComplete();
\r
454 deleteParameterButton.setEnabled(false);
\r
456 clearButton = toolkit.createButton(buttons, "Clear Parameter", SWT.PUSH);
\r
457 clearButton.addSelectionListener(new SelectionAdapter() {
\r
458 public void widgetSelected(SelectionEvent e) {
\r
459 final StructuredResourceSelection s = parameterSelection;
\r
462 ParameterizationContribution.this.parent.getSession().asyncWrite(new GraphRequestAdapter() {
\r
465 public GraphRequestStatus perform(Graph g) throws Exception {
\r
466 IEntity selectedParameter = EntityFactory.create(g,s.getSelectionList().get(0));
\r
467 Collection<IEntity> equations = selectedParameter.getRelatedObjects(ShapeEditorResources.equationResource.HasTarget);
\r
468 final String name = selectedParameter.getName();
\r
469 if (equations.size() > 0) {
\r
470 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
471 parent.getDisplay().syncExec(new Runnable() {
\r
472 public void run() {
\r
473 proceed = (dialog.open() != 1);
\r
477 for (IEntity eq : equations) {
\r
478 eq.removeRelatedStatements(ShapeEditorResources.equationResource.HasSource);
\r
479 eq.removeRelatedStatements(ShapeEditorResources.equationResource.HasTarget);
\r
481 return GraphRequestStatus.transactionComplete();
\r
484 return GraphRequestStatus.transactionCancel();
\r
491 clearButton.setEnabled(false);
\r
493 Label hierarchyLabel = toolkit.createLabel(parent, "Model Hierarchy:");
\r
494 hierarchyLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
\r
495 hierarchyLabel.setLayoutData(gridData1);
\r
497 hierarchyExplorer = new GraphExplorer(parent,SWT.MULTI); //new OntologyExplorer("HierarchyExplorer", this, getInput("HierarchyExplorer", model.getId()));
\r
498 Tree oeh = hierarchyExplorer.getTree();//hierarchyExplorer.getControl(parent, 1, OntologyExplorer.OntologyTree, SWT.MULTI);
\r
499 toolkit.adapt(oeh, true, true);
\r
501 GridData gd4 = new GridData(GridData.FILL, GridData.FILL, true, true,1,1);
\r
502 gd4.heightHint = 200;
\r
503 oeh.setLayoutData(gd4);
\r
504 hierarchyExplorer.getViewer().addPostSelectionChangedListener(new OESelectionListener() {
\r
506 protected void resourceSelectionUpdated(StructuredResourceSelection sel) {
\r
507 hierarchySelection = sel;
\r
508 updatePropertiesTable();
\r
509 updateGenerateButtonStatus();
\r
512 private void updatePropertiesTable() {
\r
513 propertiesTree.setProperties(hierarchySelection);
\r
519 Label propertiesLabel = toolkit.createLabel(parent, "Available properties:");
\r
520 propertiesLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
\r
521 propertiesLabel.setLayoutData(gridData1);
\r
523 //propertiesTable = toolkit.createTable(parent, SWT.MULTI);
\r
524 Tree tree = toolkit.createTree(parent, SWT.MULTI);
\r
525 propertiesTree = new PropertyTree(tree,ParameterizationContribution.this.parent.getSession());
\r
527 GridData gd5 = new GridData(GridData.FILL, GridData.FILL, true, true,1,1);
\r
528 gd5.heightHint = 200;
\r
529 //propertiesTable.setLayoutData(gd5);
\r
530 tree.setLayoutData(gd5);
\r
531 tree.addSelectionListener(new SelectionAdapter() {
\r
534 public void widgetSelected(SelectionEvent e) {
\r
535 updateGenerateButtonStatus();
\r
543 private void updateGenerateButtonStatus() {
\r
544 if (parameterSelection.size() == 0) {
\r
545 generateButton.setEnabled(false);
\r
548 if (hierarchySelection.size() == 0) {
\r
549 generateButton.setEnabled(false);
\r
552 if (propertiesTree.getTree().getSelection().length == 0) {
\r
553 generateButton.setEnabled(false);
\r
556 generateButton.setEnabled(true);
\r
559 List<Resource> res;
\r
561 private void generateMappings() {
\r
562 final StructuredResourceSelection selectedShapes = hierarchySelection;
\r
563 final StructuredResourceSelection selectedParameter = parameterSelection;
\r
565 final boolean override = overrideButton.getSelection();
\r
566 final boolean ask = askButton.getSelection();
\r
567 //TreeItem[] selectedProperties = propertiesTree.getTree().getSelection();
\r
569 assert (selectedParameter.size() == 1);
\r
570 assert (selectedShapes.size() > 0);
\r
571 //assert(selectedProperties.length > 0);
\r
572 parent.getSession().asyncWrite(new GraphRequestAdapter() {
\r
574 public GraphRequestStatus perform(Graph g) throws Exception {
\r
575 //fi.vtt.simantics.layer0.stubs.Double parameter = DoubleFactory.create(g,selectedParameter.getSelectionList().get(0));
\r
576 IEntity parameter = EntityFactory.create(g,selectedParameter.getSelectionList().get(0));
\r
577 Collection<IEntity> prop = parameter.getRelatedObjects(ShapeEditorResources.g3dResource.HasDefaultDoubleValue);
\r
578 //fi.vtt.simantics.layer0.stubs.Double defaultValue;
\r
579 double value = g.getScalarDouble(parameter.getResource());
\r
580 if (prop.size() == 0) {
\r
581 //defaultValue = DoubleFactory.createDefault(g);
\r
582 //parameter.addStatement(ShapeEditorResources.g3dResource.HasDefaultDoubleValue, defaultValue);
\r
583 parameter.addRelatedScalarDouble(ShapeEditorResources.g3dResource.HasDefaultDoubleValue, value);
\r
585 //defaultValue = DoubleFactory.create(prop.iterator().next());
\r
586 g.setScalarDouble(prop.iterator().next().getResource(),value);
\r
588 //defaultValue.setValue(parameter.getValue());
\r
589 final Graph graph = g;
\r
590 parent.getRenderingComposite().getDisplay().syncExec(new Runnable() {
\r
591 public void run() {
\r
592 res = propertiesTree.findLeafPropertyInstances(graph, selectedShapes.getSelectionList());
\r
597 double refValue = parameter.toProperty().getScalarDouble();
\r
598 ArrayList<Resource> mappedProperties = new ArrayList<Resource>();
\r
600 for (Resource r : res) {
\r
601 IEntity propertyThing = EntityFactory.create(g,r);
\r
602 assert (propertyThing.isInstanceOf(g.getBuiltins().Double));
\r
603 final String name = ResourceDebugUtils.getReadableNameForEntity(propertyThing);
\r
604 double rb = propertyThing.toProperty().getScalarDouble();
\r
605 System.out.println("Mapping to " + name + " " + rb);
\r
606 Collection<IEntity> equations = propertyThing.getRelatedObjects(ShapeEditorResources.equationResource.HasSource);
\r
607 if (equations.size() != 0) {
\r
608 mappedProperties.add(propertyThing.getResource());
\r
610 System.out.println("Override");
\r
611 boolean over = true;
\r
613 IEntity t = propertyThing;
\r
614 while (t.isInstanceOf(g.getBuiltins().Property)) {
\r
615 Collection<IEntity> ts = t.getRelatedObjects(g.getBuiltins().PropertyOf);
\r
616 // FIXME : traverse all possible routes
\r
617 t = ts.iterator().next();
\r
619 //StructuredResourceSelection selection = new StructuredResourceSelection(t.getResource());
\r
620 // TODO : do the selection!
\r
621 //hierarchyScheme.setSelection(selection);
\r
622 //fireSelectionChanged();
\r
623 MessageDialog dialog = new MessageDialog(ParameterizationContribution.this.parent.getRenderingComposite().getShell(),
\r
624 "Override mapping",
\r
626 "Override mapping to property of highlighted shape?",
\r
627 MessageDialog.QUESTION, new String[] {
\r
628 "Yes","No", "Cancel" }, 0);
\r
629 int i = dialog.open();
\r
631 return GraphRequestStatus.transactionCancel();
\r
638 if (equations.size() != 1) {
\r
639 throw new RuntimeException("One property can have only one euquation as source function.");
\r
641 IEntity equation = equations.iterator().next();
\r
642 if (!equation.isInstanceOf(ShapeEditorResources.equationResource.SecondOrderScalarPolynomial)) {
\r
643 throw new RuntimeException("Only Second order scalar polynomials are supported");
\r
645 SecondOrderScalarPolynomial s = new SecondOrderScalarPolynomial(equation);
\r
646 s.setA(new double[]{0.0});
\r
647 s.setB(new double[]{rb / refValue});
\r
648 s.setC(new double[]{0.0});
\r
651 } else { //override
\r
653 SecondOrderScalarPolynomial s = SecondOrderScalarPolynomial.createDefault(g);
\r
654 s.setA(new double[]{0.0});
\r
655 s.setB(new double[]{rb / refValue});
\r
656 s.setC(new double[]{0.0});
\r
658 // these relations have been instantiated, but addStatements won't delete them so we have to delete them manually.
\r
659 s.removeRelatedStatements(ShapeEditorResources.equationResource.HasTarget);
\r
660 s.removeRelatedStatements(ShapeEditorResources.equationResource.HasSource);
\r
662 parameter.addStatement(ShapeEditorResources.equationResource.HasTarget, s);
\r
664 s.addStatement(ShapeEditorResources.equationResource.HasTarget, propertyThing);
\r
665 mappedProperties.add(propertyThing.getResource());
\r
669 G3DModel model = parent.getModel(g);
\r
670 Collection<Animation> animations = model.getAnimation();
\r
671 for (Animation animation : animations) {
\r
672 Collection<Interpolator> interpolators = animation.getInterpolator();
\r
673 for (Interpolator interpolator : interpolators) {
\r
674 IEntity target = interpolator.getTarget();
\r
675 for (Resource property : mappedProperties) {
\r
676 if (target.getResource().equals(property)) {
\r
677 ShapeEditorResources.curveBuilder.createDefault(interpolator);
\r
682 return GraphRequestStatus.transactionComplete();
\r