| /******************************************************************************* |
| * 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 - initial API and implementation |
| * |
| * SPDX-License-Identifier: EPL-1.0 |
| * |
| *******************************************************************************/ |
| package org.eclipse.apogy.addons.sensors.fov.bindings.impl; |
| |
| import java.util.Map; |
| |
| import org.eclipse.apogy.addons.sensors.fov.ApogyAddonsSensorsFOVPackage; |
| import org.eclipse.apogy.addons.sensors.fov.DistanceRange; |
| import org.eclipse.apogy.addons.sensors.fov.RectangularFrustrumFieldOfView; |
| import org.eclipse.apogy.addons.sensors.fov.bindings.RectangularFrustrumFieldOfViewBinding; |
| import org.eclipse.apogy.common.emf.ApogyCommonEMFPackage; |
| import org.eclipse.apogy.common.emf.FeatureNodeAdapter; |
| import org.eclipse.apogy.common.topology.Node; |
| import org.eclipse.apogy.common.topology.bindings.AbstractTopologyBinding; |
| 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 RectangularFrustrumFieldOfViewBindingCustomImpl extends RectangularFrustrumFieldOfViewBindingImpl { |
| |
| private AdapterImpl adapter; |
| |
| @Override |
| public AbstractTopologyBinding clone(Map<Node, Node> originalToCopyNodeMap) { |
| RectangularFrustrumFieldOfViewBinding fovBindingCopy = EcoreUtil.copy(this); |
| fovBindingCopy.setFov((RectangularFrustrumFieldOfView) originalToCopyNodeMap.get(this.getFov())); |
| return fovBindingCopy; |
| } |
| |
| @Override |
| public Class<?> getSupportedFeatureType() { |
| return RectangularFrustrumFieldOfView.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 RectangularFrustrumFieldOfView) { |
| RectangularFrustrumFieldOfView oldFOV = (RectangularFrustrumFieldOfView) notification |
| .getOldValue(); |
| oldFOV.eAdapters().remove(getAdapter()); |
| |
| if (oldFOV.getRange() != null) { |
| oldFOV.getRange().eAdapters().remove(getAdapter()); |
| } |
| } |
| |
| if (notification.getNewValue() instanceof RectangularFrustrumFieldOfView) { |
| RectangularFrustrumFieldOfView newFOV = (RectangularFrustrumFieldOfView) notification |
| .getNewValue(); |
| newFOV.eAdapters().add(getAdapter()); |
| |
| if (newFOV.getRange() != null) { |
| newFOV.getRange().eAdapters().add(getAdapter()); |
| } |
| |
| valueChanged(newFOV); |
| } |
| } else if (notification.getNotifier() instanceof RectangularFrustrumFieldOfView) { |
| if (notification.getFeatureID( |
| RectangularFrustrumFieldOfView.class) == ApogyAddonsSensorsFOVPackage.RECTANGULAR_FRUSTRUM_FIELD_OF_VIEW__RANGE) { |
| if (notification.getOldValue() instanceof DistanceRange) { |
| DistanceRange oldDistanceRange = (DistanceRange) notification.getOldValue(); |
| oldDistanceRange.eAdapters().remove(getAdapter()); |
| } |
| |
| if (notification.getNewValue() instanceof DistanceRange) { |
| DistanceRange newDistanceRange = (DistanceRange) notification.getNewValue(); |
| newDistanceRange.eAdapters().add(getAdapter()); |
| |
| // Update Distance Range. |
| updateDistanceRange(newDistanceRange); |
| } |
| } else if (notification.getFeatureID( |
| RectangularFrustrumFieldOfView.class) == ApogyAddonsSensorsFOVPackage.RECTANGULAR_FRUSTRUM_FIELD_OF_VIEW__HORIZONTAL_FIELD_OF_VIEW_ANGLE) { |
| updateHorizontalFieldOfViewAngle(notification.getNewDoubleValue()); |
| } else if (notification.getFeatureID( |
| RectangularFrustrumFieldOfView.class) == ApogyAddonsSensorsFOVPackage.RECTANGULAR_FRUSTRUM_FIELD_OF_VIEW__VERTICAL_FIELD_OF_VIEW_ANGLE) { |
| updateVerticalFieldOfViewAngle(notification.getNewDoubleValue()); |
| } |
| } else if (notification.getNotifier() instanceof DistanceRange) { |
| DistanceRange newDistanceRange = (DistanceRange) notification.getNotifier(); |
| |
| // Updates. |
| updateDistanceRange(newDistanceRange); |
| } |
| } |
| }; |
| } |
| |
| return this.adapter; |
| } |
| |
| private void updateHorizontalFieldOfViewAngle(double hfov) { |
| getFov().setHorizontalFieldOfViewAngle(hfov); |
| } |
| |
| private void updateVerticalFieldOfViewAngle(double vfov) { |
| getFov().setVerticalFieldOfViewAngle(vfov); |
| } |
| |
| private void updateDistanceRange(DistanceRange newDistanceRange) { |
| getFov().getRange().setMinimumDistance(newDistanceRange.getMinimumDistance()); |
| getFov().getRange().setMaximumDistance(newDistanceRange.getMaximumDistance()); |
| } |
| |
| @Override |
| protected void valueChanged(Object newValue) { |
| if (newValue instanceof RectangularFrustrumFieldOfView) { |
| // Just update everything. |
| RectangularFrustrumFieldOfView sourceFOV = (RectangularFrustrumFieldOfView) newValue; |
| |
| getFov().setDescription(sourceFOV.getDescription()); |
| |
| updateHorizontalFieldOfViewAngle(sourceFOV.getHorizontalFieldOfViewAngle()); |
| updateVerticalFieldOfViewAngle(sourceFOV.getVerticalFieldOfViewAngle()); |
| |
| if (sourceFOV.getRange() != null) { |
| updateDistanceRange(sourceFOV.getRange()); |
| } else { |
| getFov().setRange(null); |
| } |
| } |
| } |
| |
| } // RectangularFrustrumFieldOfViewBindingImpl |