/*
* 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.builder;
import gov.nasa.worldwind.awt.WorldWindowGLCanvas;
import gov.nasa.worldwind.geom.LatLon;
import gov.nasa.worldwind.geom.Position;
import gov.nasa.worldwind.render.Polyline;
import java.util.ArrayList;
import org.geoforge.lang.util.geography.GfrUtilDmsOperation;
import org.geoforge.lang.util.number.GfrDouble;
import org.geoforge.worldwind.builder.editor.GfrEditorObjShpSegWiseTool;
import org.geoforge.worldwind.builder.editor.GfrEditorObjShpSegWiseToolController;
import org.geoforge.worldwind.builder.factory.GfrFactoryObjShpSegWiseYes;
/**
*
* @author Amadeus.Sowerby
*
* email: Amadeus.Sowerby_AT_gmail.com ... please remove "_AT_" from the above
* string to get the right email address
*/
public class GfrBldObjPikShpSegWiseYes extends GfrBldObjPikShpSegWiseAbs
{
final static private double _DBL_DISTANCE_MAX_ALLOWED_ = 20000d;
public GfrBldObjPikShpSegWiseYes(WorldWindowGLCanvas glcWwd)
{
super(glcWwd);
GfrEditorObjShpSegWiseTool measureTool = new GfrEditorObjShpSegWiseTool(super._glcWwd);
measureTool.setController(new GfrEditorObjShpSegWiseToolController());
super._epe = measureTool;
//new GfrEditorObjShpSegWiseCopyYes();
}
@Override
public Object getValue()
{
((GfrEditorObjShpSegWiseTool) super._epe).getPositions();
/*if(super._pey == null)
return (Object) null;
Polyline epn = (Polyline) this._pey.getRenderable();*/
ArrayList<Position> altPos = (ArrayList<Position>)((GfrEditorObjShpSegWiseTool) super._epe).getPositions();//epn.getPositions().iterator();
double dblDistance =
GfrUtilDmsOperation.s_getDistanceFromDeg(
altPos.get(0).getLatitude().getDegrees(),
altPos.get(0).getLongitude().getDegrees(),
altPos.get(1).getLatitude().getDegrees(),
altPos.get(1).getLongitude().getDegrees());
if(dblDistance <= _DBL_DISTANCE_MAX_ALLOWED_)
{
return altPos;
}
Position posBeg = altPos.get(0);
Position posEndCur = altPos.get(1);
while(Math.abs(dblDistance - _DBL_DISTANCE_MAX_ALLOWED_) >= GfrDouble.DBL_EPSILON_THREE_DIGITS)
{
double weight= _DBL_DISTANCE_MAX_ALLOWED_ /dblDistance;
posEndCur = Position.interpolateGreatCircle(weight, posBeg, posEndCur);
dblDistance =
GfrUtilDmsOperation.s_getDistanceFromDeg(
posBeg.getLatitude().getDegrees(),
posBeg.getLongitude().getDegrees(),
posEndCur.getLatitude().getDegrees(),
posEndCur.getLongitude().getDegrees());
}
altPos.set(1, posEndCur);
return altPos;
//return super._getValue(itr);
}
@Override
public void _createNewEntry()
{
((GfrEditorObjShpSegWiseTool) super._epe).setArmed(true);
Polyline polygon = GfrFactoryObjShpSegWiseYes.s_getInstance().create(
super._glcWwd,
super.isResizeNewShapesToViewport());
/*polygon.setColor(Color.yellow);
polygon.setLineWidth(2d);
polygon.setFollowTerrain(true);*/
ArrayList<Position> alt = (ArrayList<Position>) polygon.getPositions();
((GfrEditorObjShpSegWiseTool) super._epe).addControlPoint(alt.get(0));
((GfrEditorObjShpSegWiseTool) super._epe).addControlPoint(alt.get(1));
((GfrEditorObjShpSegWiseTool) super._epe).setArmed(false);
/*GfrEntryBltObjPikAbs pey = new GfrEntryBltObjPikShpSegWiseYes(polygon);
super._createNewEntry(pey);*/
}
@Override
protected void _clearEntry()
{
((GfrEditorObjShpSegWiseTool) super._epe).clear();
super._clearEntry();
}
}