| /******************************************************************************* |
| * 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.pose.impl; |
| |
| import org.eclipse.apogy.common.geometry.data3d.ApogyCommonGeometryData3DFactory; |
| import org.eclipse.apogy.common.geometry.data3d.CartesianPositionCoordinates; |
| import org.eclipse.apogy.common.math.Tuple3d; |
| import org.eclipse.apogy.common.topology.ApogyCommonTopologyPackage; |
| import org.eclipse.apogy.common.topology.PositionNode; |
| import org.eclipse.emf.common.notify.Adapter; |
| import org.eclipse.emf.common.notify.Notification; |
| import org.eclipse.emf.common.notify.impl.AdapterImpl; |
| |
| public class PositionSensorCustomImpl extends PositionSensorImpl { |
| |
| private Adapter positionAdapter = null; |
| |
| protected PositionSensorCustomImpl() { |
| super(); |
| |
| // Register listener to this node position to keep positionCoordinates updated. |
| eAdapters().add(getPositionAdapter()); |
| } |
| |
| @Override |
| public CartesianPositionCoordinates getPositionCoordinates() { |
| if (this.positionCoordinates == null) { |
| this.positionCoordinates = ApogyCommonGeometryData3DFactory.eINSTANCE.createCartesianPositionCoordinates(); |
| } |
| return this.positionCoordinates; |
| } |
| |
| /** |
| * Returns the adapter used to keep the positionCoordinates updated when the |
| * node position is changed. |
| * |
| * @return The adapter. |
| */ |
| private Adapter getPositionAdapter() { |
| if (this.positionAdapter == null) { |
| this.positionAdapter = new AdapterImpl() { |
| @Override |
| public void notifyChanged(Notification msg) { |
| if (msg.getFeatureID(PositionNode.class) == ApogyCommonTopologyPackage.POSITION_NODE__POSITION) { |
| // Updates the current Orientation data with the new values. |
| Tuple3d newPose = (Tuple3d) msg.getNewValue(); |
| |
| getPositionCoordinates().setX(newPose.getX()); |
| getPositionCoordinates().setY(newPose.getY()); |
| getPositionCoordinates().setZ(newPose.getZ()); |
| } |
| } |
| }; |
| } |
| return this.positionAdapter; |
| } |
| } // PositionSensorImpl |