/*
* Copyright (C) 2011-2014 GeoForge Project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.geoforge.worldwind.render;
import gov.nasa.worldwind.WorldWind;
import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.geom.LatLon;
import gov.nasa.worldwind.geom.Position;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.List;
import java.util.Observer;
import java.util.logging.Logger;
import org.geoforge.lang.handler.IGfrHandlerLifeCycleObject;
import org.geoforge.lang.util.geography.GfrUtilDmsOperation;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.worldwind.handler.IGfrHandlerObjectRender;
import org.geoforge.worldwind.handler.IGfrHandlerWwdEarthObjectGeoforgeRenderableLayer;
/**
*
* @author Amadeus.Sowerby
*
* email: Amadeus.Sowerby_AT_gmail.com ... please remove "_AT_" from the above
* string to get the right email address
*/
abstract public class GfrRndSurfaceSegmentWiseYesAbs extends GfrDirectedPath implements
IGfrHandlerLifeCycleObject,
IGfrHandlerWwdEarthObjectGeoforgeRenderableLayer,
Observer,
IGfrHandlerObjectRender
{
// ----
// begin: instantiate logger for this class
final private static Logger _LOGGER_ = Logger.getLogger(GfrRndSurfaceSegmentWiseYesAbs.class.getName());
static
{
GfrRndSurfaceSegmentWiseYesAbs._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
}
// end: instantiate logger for this class
// ----
protected String _strId = null;
protected GfrRndSurfaceSegmentWiseYesAbs(
PropertyChangeListener lstShouldRedraw,
String strId,
String strName,
List<Position> lstPosition)
throws Exception
{
super(lstPosition);
this._strId = strId;
setNameThis(strName);
setEnabledTooltipThis();
if (lstShouldRedraw != null)
super.addPropertyChangeListener(lstShouldRedraw);
super.setVisible(true);
super.setAltitudeMode(WorldWind.CLAMP_TO_GROUND);
super.setFollowTerrain(true);
super.setPathType(AVKey.GREAT_CIRCLE);
}
@Override
public String getIdObjectGeoforgeWwdEarth()
{
return this._strId;
}
@Override
public Position getPositionBarycentricObjectGeoforgeWwdEarth() throws Exception
{
ArrayList<LatLon> altPos = new ArrayList<LatLon>();
for (LatLon llnCur : super.getPositions())
{
altPos.add(llnCur);
}
if (altPos.size() != 2)
{
String strSevere = "altPos.size() != 2, altPos.size()=" + altPos.size();
GfrRndSurfaceSegmentWiseYesAbs._LOGGER_.severe(strSevere);
throw new Exception(strSevere);
}
LatLon posBeg = altPos.get(0);
LatLon posEnd = altPos.get(1);
LatLon latLonMid = LatLon.interpolateGreatCircle(0.5, posBeg, posEnd);
return new Position(latLonMid, 0);
}
@Override
public boolean init()
{
try
{
setAttributesThis();
}
catch (Exception exc)
{
exc.printStackTrace();
String str = exc.getMessage();
GfrRndSurfaceSegmentWiseYesAbs._LOGGER_.severe(str);
return false;
}
return true;
}
@Override
public void destroy()
{
}
@Override
public double getCharacteristicDimensionObjectGeoforgeRenderableLayer() throws Exception
{
ArrayList<LatLon> altPos = new ArrayList<LatLon>();
for (LatLon location : super.getPositions())
{
altPos.add(location);
}
if (altPos.size() != 2)
throw new Exception("Unsupported segment size : " + altPos.size());
LatLon posBeg = altPos.get(0);
LatLon posEnd = altPos.get(1);
return GfrUtilDmsOperation.s_getDistanceFromRad(
posBeg.getLatitude().getRadians(),
posBeg.getLongitude().getRadians(),
posEnd.getLatitude().getRadians(),
posEnd.getLongitude().getRadians());
}
@Override
public void setNameThis(String strName)
{
super.setValue(gov.nasa.worldwind.avlist.AVKey.DISPLAY_NAME, strName);
super.setValue(GfrKeysRnd.STR_HAS_CONTEXTUAL_MENU, true); // always true
}
}