blob: 5e607806d7dbc3810cf0f719868553c00b28b89c [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:
<<<<<<< HEAD
* Pierre Allard - initial API and implementation
* Regent L'Archeveque
*
=======
* Pierre Allard,
* Regent L'Archeveque - initial API and implementation
*
>>>>>>> refs/heads/eclipse_pa
* SPDX-License-Identifier: EPL-1.0
*
*******************************************************************************/
package org.eclipse.apogy.common.geometry.data3d.xyz.ui.adapters;
import java.io.IOException;
import org.eclipse.apogy.common.geometry.data3d.CartesianCoordinatesSet;
import org.eclipse.apogy.common.geometry.data3d.Data3DIO;
import org.eclipse.apogy.common.topology.ApogyCommonTopologyFacade;
import org.eclipse.apogy.common.topology.ApogyCommonTopologyFactory;
import org.eclipse.apogy.common.topology.ContentNode;
import org.eclipse.apogy.common.topology.GroupNode;
import org.eclipse.apogy.common.topology.ui.ApogyCommonTopologyUIFactory;
import org.eclipse.apogy.common.topology.ui.GraphicsContext;
import org.eclipse.apogy.common.topology.ui.GraphicsContextAdapter;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class GraphicsContextXYZAdapter implements GraphicsContextAdapter {
private static final Logger Logger = LoggerFactory.getLogger(GraphicsContextXYZAdapter.class);
public static final String SUPPORTED_EXTENSION = "xyz";
@Override
public boolean isAdapterFor(Object obj) {
boolean ok = false;
// We respond to IFile selection ending with SUPPORTED_EXTENSION
if (obj instanceof IFile) {
IFile file = (IFile) obj;
ok = file.getName().endsWith("." + SUPPORTED_EXTENSION);
}
return ok;
}
public GraphicsContextXYZAdapter() {
}
@SuppressWarnings("unused")
@Override
public GraphicsContext getAdapter(Object obj, Object context) {
GraphicsContext ctx = null;
if (isAdapterFor(obj)) {
IProgressMonitor monitor = new NullProgressMonitor();
if (context instanceof IProgressMonitor) {
monitor = (IProgressMonitor) context;
}
IFile file = (IFile) obj;
try {
CartesianCoordinatesSet points = Data3DIO.INSTANCE.loadXYZ(file.getLocation().toOSString());
GroupNode root = ApogyCommonTopologyFactory.eINSTANCE.createAggregateGroupNode();
ContentNode<CartesianCoordinatesSet> content = ApogyCommonTopologyFacade.INSTANCE
.createContentNode(points);
root.getChildren().add(content);
ctx = ApogyCommonTopologyUIFactory.eINSTANCE.createGraphicsContext();
ctx.setTopology(root);
} catch (IOException e) {
Logger.error(e.getMessage(), e);
}
}
return ctx;
}
@Override
public Class<?> getAdaptedClass() {
return IFile.class;
}
}