| /******************************************************************************* |
| * 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.bindings.impl; |
| |
| import java.util.Map; |
| |
| import org.eclipse.apogy.common.emf.ApogyCommonEMFPackage; |
| import org.eclipse.apogy.common.emf.FeatureNodeAdapter; |
| import org.eclipse.apogy.common.math.Matrix4x4; |
| import org.eclipse.apogy.common.topology.Node; |
| import org.eclipse.apogy.common.topology.TransformNode; |
| import org.eclipse.apogy.common.topology.bindings.AbstractTopologyBinding; |
| import org.eclipse.apogy.common.topology.bindings.TransformMatrixBinding; |
| import org.eclipse.emf.common.notify.Adapter; |
| import org.eclipse.emf.common.notify.Notification; |
| import org.eclipse.emf.common.notify.impl.AdapterImpl; |
| import org.eclipse.emf.ecore.util.EcoreUtil; |
| |
| public class TransformMatrixBindingCustomImpl extends TransformMatrixBindingImpl { |
| |
| @Override |
| public AbstractTopologyBinding clone(Map<Node, Node> originalToCopyNodeMap) { |
| TransformMatrixBinding transformCopy = EcoreUtil.copy(this); |
| transformCopy.setTransformNode((TransformNode) originalToCopyNodeMap.get(this.getTransformNode())); |
| return transformCopy; |
| } |
| |
| @Override |
| public void bind() { |
| super.bind(); |
| } |
| |
| @Override |
| public Class<?> getSupportedFeatureType() { |
| return Matrix4x4.class; |
| } |
| |
| @Override |
| protected Adapter getAdapter() { |
| if (this.adapter == null) { |
| this.adapter = new AdapterImpl() { |
| @Override |
| public void notifyChanged(Notification notification) { |
| if (notification.getFeatureID( |
| FeatureNodeAdapter.class) == ApogyCommonEMFPackage.FEATURE_NODE_ADAPTER__CURRENT_VALUE) { |
| if (notification.getOldValue() instanceof Matrix4x4) { |
| Matrix4x4 oldMatrix = (Matrix4x4) notification.getOldValue(); |
| oldMatrix.eAdapters().remove(getAdapter()); |
| } |
| |
| valueChanged(notification.getNewValue()); |
| |
| if (notification.getNewValue() instanceof Matrix4x4) { |
| Matrix4x4 newMatrix = (Matrix4x4) notification.getNewValue(); |
| newMatrix.eAdapters().add(getAdapter()); |
| } |
| } else if (notification.getNotifier() instanceof Matrix4x4) { |
| valueChanged(notification.getNotifier()); |
| } |
| } |
| }; |
| } |
| |
| return this.adapter; |
| } |
| |
| @Override |
| protected void valueChanged(Object newValue) { |
| if (newValue instanceof Matrix4x4) { |
| applyValue((Matrix4x4) newValue); |
| } |
| } |
| |
| private void applyValue(final Matrix4x4 matrix4x4) { |
| getTransformNode().setTransformation(matrix4x4.asMatrix4d()); |
| } |
| } // TransformMatrixBindingImpl |