blob: ba387203ab2129213924db03f127438d22bbf18a [file] [log] [blame]
/*******************************************************************************
* 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.core.environment.earth.surface.impl;
import javax.vecmath.Matrix4d;
import org.eclipse.apogy.common.topology.ApogyCommonTopologyFacade;
import org.eclipse.apogy.common.topology.INodeVisitor;
import org.eclipse.apogy.common.topology.Node;
import org.eclipse.apogy.common.topology.TransformNode;
import org.eclipse.apogy.core.environment.Worksite;
import org.eclipse.apogy.core.environment.earth.surface.ApogyEarthSurfaceEnvironmentPackage;
import org.eclipse.apogy.core.environment.earth.surface.EarthSurfaceWorksite;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
public class EarthSurfaceWorksiteNodeCustomImpl extends EarthSurfaceWorksiteNodeImpl {
private Adapter earthSurfaceWorksiteAdapter;
public TransformNode getSkyTransformNode() {
TransformNode transformNode = super.getSkyTransformNode();
if (transformNode == null) {
if (getWorksite() instanceof EarthSurfaceWorksite) {
EarthSurfaceWorksite earthSurfaceWorksite = (EarthSurfaceWorksite) getWorksite();
transformNode = ApogyCommonTopologyFacade.INSTANCE.createTransformNodeXYZ(0, 0, 0, 0, 0,
earthSurfaceWorksite.getXAxisAzimuth());
} else {
transformNode = ApogyCommonTopologyFacade.INSTANCE.createTransformNodeXYZ(0, 0, 0, 0, 0, 0);
}
transformNode.setNodeId("SKY_TRANSFORM");
transformNode.setDescription(
"Transform used to orient the sky to factor in the EarthSurfaceWorksite X Axis Azimuth.");
getChildren().add(transformNode);
// transformNode.setParent(this); // Should not have to this this explicitly.
setSkyTransformNode(transformNode);
}
return transformNode;
}
@Override
public void setWorksite(Worksite newWorksite) {
// Unregister from previous EarthSurfaceWorksite if applicable
if (getWorksite() instanceof EarthSurfaceWorksite) {
getWorksite().eAdapters().remove(getEarthSurfaceWorksiteAdapter());
}
super.setWorksite(newWorksite);
// Register to new EarthSurfaceWorksite if applicable
if (newWorksite instanceof EarthSurfaceWorksite) {
EarthSurfaceWorksite earthSurfaceWorksite = (EarthSurfaceWorksite) newWorksite;
earthSurfaceWorksite.eAdapters().add(getEarthSurfaceWorksiteAdapter());
updateSkyTransform(earthSurfaceWorksite.getXAxisAzimuth());
}
}
@Override
public void accept(INodeVisitor visitor) {
if (visitor.getType().isInstance(this)) {
visitor.visit(this);
}
// We do the same for all the children.
for (Node child : getChildren()) {
child.accept(visitor);
}
}
private void updateSkyTransform(double xAxisAzimuth) {
Matrix4d matrix = new Matrix4d();
matrix.setIdentity();
// Sky is rotated opposite of worksite relative to north.
matrix.rotZ(-xAxisAzimuth);
getSkyTransformNode().setTransformation(matrix);
}
private Adapter getEarthSurfaceWorksiteAdapter() {
if (this.earthSurfaceWorksiteAdapter == null) {
this.earthSurfaceWorksiteAdapter = new AdapterImpl() {
@Override
public void notifyChanged(Notification msg) {
if (msg.getFeatureID(
EarthSurfaceWorksite.class) == ApogyEarthSurfaceEnvironmentPackage.EARTH_SURFACE_WORKSITE__XAXIS_AZIMUTH) {
updateSkyTransform(msg.getNewDoubleValue());
}
}
};
}
return this.earthSurfaceWorksiteAdapter;
}
} // EarthSurfaceWorksiteNodeImpl