| /******************************************************************************* |
| * Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Pierre Allard, |
| * Regent L'Archeveque, |
| * Sebastien Gemme - initial API and implementation |
| * SPDX-License-Identifier: EPL-1.0 |
| * |
| *******************************************************************************/ |
| package org.eclipse.apogy.common.topology.addons.dynamics.ui.composites; |
| |
| import org.eclipse.apogy.common.math.Tuple3d; |
| import org.eclipse.apogy.common.math.ui.composites.Tuple3dComposite; |
| import org.eclipse.apogy.common.topology.addons.dynamics.ApogyCommonTopologyAddonsDynamicsPackage; |
| import org.eclipse.apogy.common.topology.addons.dynamics.KinematicState; |
| import org.eclipse.core.databinding.DataBindingContext; |
| import org.eclipse.emf.common.notify.Adapter; |
| import org.eclipse.emf.common.notify.impl.AdapterImpl; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.events.DisposeEvent; |
| import org.eclipse.swt.events.DisposeListener; |
| import org.eclipse.swt.layout.FillLayout; |
| import org.eclipse.swt.layout.GridData; |
| import org.eclipse.swt.layout.GridLayout; |
| import org.eclipse.swt.widgets.Composite; |
| import org.eclipse.swt.widgets.Display; |
| import org.eclipse.swt.widgets.Group; |
| |
| public class KinematicStateComposite extends Composite { |
| private final DataBindingContext m_bindingContext; |
| |
| private KinematicState ks; |
| |
| private Adapter kinematicStateAdapter; |
| |
| private final Tuple3dComposite tuple3dLinearVelocity; |
| |
| private final Tuple3dComposite tuple3dLinearAcceleration; |
| |
| private final Tuple3dComposite tuple3dOrientation; |
| |
| private final Tuple3dComposite tuple3dAngularVelocity; |
| |
| private final Tuple3dComposite tuple3dAngularAcceleration; |
| |
| private final Tuple3dComposite tuple3dPosition; |
| |
| /** |
| * Create the parentComposite. |
| * |
| * @param parent |
| * @param style |
| */ |
| public KinematicStateComposite(Composite parent, int style) { |
| super(parent, style); |
| setLayout(new GridLayout(2, true)); |
| |
| Group grpPosition = new Group(this, SWT.NONE); |
| grpPosition.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); |
| grpPosition.setText("Position"); |
| |
| Group grpOrientation = new Group(this, SWT.NONE); |
| grpOrientation.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); |
| grpOrientation.setText("Orientation"); |
| grpOrientation.setLayout(new FillLayout(SWT.HORIZONTAL)); |
| |
| this.tuple3dOrientation = new Tuple3dComposite(grpOrientation, SWT.FILL); |
| |
| Group grpLinearVelocity = new Group(this, SWT.NONE); |
| grpLinearVelocity.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); |
| grpLinearVelocity.setText("Linear Velocity"); |
| grpLinearVelocity.setLayout(new FillLayout(SWT.HORIZONTAL)); |
| |
| this.tuple3dLinearVelocity = new Tuple3dComposite(grpLinearVelocity, SWT.FILL); |
| |
| Group grpAngularVelocity = new Group(this, SWT.NONE); |
| grpAngularVelocity.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); |
| grpAngularVelocity.setText("Angular Velocity"); |
| grpAngularVelocity.setLayout(new FillLayout(SWT.HORIZONTAL)); |
| |
| this.tuple3dAngularVelocity = new Tuple3dComposite(grpAngularVelocity, SWT.FILL); |
| |
| Group grpLinearAcceleration = new Group(this, SWT.NONE); |
| grpLinearAcceleration.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); |
| grpLinearAcceleration.setText("Linear Acceleration"); |
| grpLinearAcceleration.setLayout(new FillLayout(SWT.HORIZONTAL)); |
| |
| this.tuple3dLinearAcceleration = new Tuple3dComposite(grpLinearAcceleration, SWT.NONE); |
| |
| Group grpAngularAcceleration = new Group(this, SWT.NONE); |
| grpAngularAcceleration.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); |
| grpAngularAcceleration.setText("Angular Acceleration"); |
| grpAngularAcceleration.setLayout(new FillLayout(SWT.HORIZONTAL)); |
| |
| this.tuple3dAngularAcceleration = new Tuple3dComposite(grpAngularAcceleration, SWT.FILL); |
| grpPosition.setLayout(new FillLayout(SWT.HORIZONTAL)); |
| |
| this.tuple3dPosition = new Tuple3dComposite(grpPosition, SWT.NONE); |
| this.m_bindingContext = initDataBindings(); |
| |
| // Dispose |
| addDisposeListener(new DisposeListener() { |
| @Override |
| public void widgetDisposed(DisposeEvent e) { |
| if (KinematicStateComposite.this.m_bindingContext != null) |
| KinematicStateComposite.this.m_bindingContext.dispose(); |
| } |
| }); |
| } |
| |
| public KinematicState getKinematicState() { |
| return this.ks; |
| } |
| |
| public void setKinematicState(KinematicState ks) { |
| if (this.ks != null) { |
| this.ks.eAdapters().remove(getKinematicStateAdapter()); |
| } |
| this.ks = ks; |
| |
| if (this.ks != null) { |
| this.tuple3dAngularAcceleration.setTuple3d(ks.getAngularAcceleration()); |
| this.tuple3dAngularVelocity.setTuple3d(ks.getAngularVelocity()); |
| this.tuple3dLinearAcceleration.setTuple3d(ks.getLinearAcceleration()); |
| this.tuple3dLinearVelocity.setTuple3d(ks.getLinearVelocity()); |
| this.tuple3dOrientation.setTuple3d(ks.getOrientation()); |
| this.tuple3dPosition.setTuple3d(ks.getPosition()); |
| this.ks.eAdapters().add(getKinematicStateAdapter()); |
| } |
| |
| } |
| |
| @Override |
| protected void checkSubclass() { |
| // Disable the check that prevents subclassing of SWT components |
| } |
| |
| protected DataBindingContext initDataBindings() { |
| DataBindingContext bindingContext = new DataBindingContext(); |
| // |
| return bindingContext; |
| } |
| |
| /** |
| * |
| * <dl> |
| * <dt>Name:</dt> |
| * <dd>getKinematicStateAdapter</dd> |
| * <dt>Description:</dt> |
| * <dd>returns the Adapter (listener) to kinematic state. This Adapter listens |
| * for changes in the different fields of {@link KinematicState} and sets the |
| * appropriate {@link Tuple3dComposite} accordingly.</dd> |
| * <dt>Pre-conditions:</dt> |
| * <dd> |
| * <ul> |
| * <li>None.</li> |
| * </ul> |
| * </dd> |
| * <dt>Post-conditions:</dt> |
| * <dd> |
| * <ul> |
| * <li>None.</li> |
| * </ul> |
| * </dd> |
| * </dl> |
| * |
| * @return the KinematicState Adapter. |
| */ |
| private Adapter getKinematicStateAdapter() { |
| if (this.kinematicStateAdapter == null) { |
| this.kinematicStateAdapter = new AdapterImpl() { |
| @Override |
| public void notifyChanged(org.eclipse.emf.common.notify.Notification msg) { |
| |
| int featureId = msg.getFeatureID(KinematicState.class); |
| |
| Tuple3d newValue = null; |
| Tuple3dComposite compositeToUpdate = null; |
| |
| switch (featureId) { |
| case ApogyCommonTopologyAddonsDynamicsPackage.KINEMATIC_STATE__POSITION: |
| newValue = (Tuple3d) msg.getNewValue(); |
| compositeToUpdate = KinematicStateComposite.this.tuple3dPosition; |
| break; |
| case ApogyCommonTopologyAddonsDynamicsPackage.KINEMATIC_STATE__ORIENTATION: |
| newValue = (Tuple3d) msg.getNewValue(); |
| compositeToUpdate = KinematicStateComposite.this.tuple3dOrientation; |
| break; |
| case ApogyCommonTopologyAddonsDynamicsPackage.KINEMATIC_STATE__ANGULAR_ACCELERATION: |
| newValue = (Tuple3d) msg.getNewValue(); |
| compositeToUpdate = KinematicStateComposite.this.tuple3dAngularAcceleration; |
| break; |
| case ApogyCommonTopologyAddonsDynamicsPackage.KINEMATIC_STATE__ANGULAR_VELOCITY: |
| newValue = (Tuple3d) msg.getNewValue(); |
| compositeToUpdate = KinematicStateComposite.this.tuple3dAngularVelocity; |
| break; |
| case ApogyCommonTopologyAddonsDynamicsPackage.KINEMATIC_STATE__LINEAR_ACCELERATION: |
| newValue = (Tuple3d) msg.getNewValue(); |
| compositeToUpdate = KinematicStateComposite.this.tuple3dLinearAcceleration; |
| break; |
| case ApogyCommonTopologyAddonsDynamicsPackage.KINEMATIC_STATE__LINEAR_VELOCITY: |
| newValue = (Tuple3d) msg.getNewValue(); |
| compositeToUpdate = KinematicStateComposite.this.tuple3dLinearVelocity; |
| break; |
| } |
| |
| if (compositeToUpdate != null) { |
| |
| final Tuple3dComposite fCompositeToUpdate = compositeToUpdate; |
| final Tuple3d fNewValue = newValue; |
| |
| Runnable run = new Runnable() { |
| @Override |
| public void run() { |
| fCompositeToUpdate.setTuple3d(fNewValue); |
| }; |
| }; |
| |
| Display.getDefault().asyncExec(run); |
| |
| } |
| |
| }; |
| }; |
| } |
| return this.kinematicStateAdapter; |
| } |
| } |