|
From: <bma...@us...> - 2011-11-30 13:57:33
|
Revision: 6735
http://fudaa.svn.sourceforge.net/fudaa/?rev=6735&view=rev
Author: bmarchan
Date: 2011-11-30 13:57:26 +0000 (Wed, 30 Nov 2011)
Log Message:
-----------
Fix GISZone : addAtomic et removeAtomics
Modified Paths:
--------------
trunk/framework/ctulu-gis/src/main/java/org/fudaa/ctulu/gis/GISZoneAttributeFactory.java
trunk/framework/ctulu-gis/src/main/java/org/fudaa/ctulu/gis/GISZoneCollection.java
trunk/framework/ctulu-gis/src/main/java/org/fudaa/ctulu/gis/GISZoneCollectionGeometry.java
trunk/framework/ctulu-gis/src/main/java/org/fudaa/ctulu/gis/GISZoneCollectionLigneBrisee.java
trunk/framework/ctulu-gis/src/main/java/org/fudaa/ctulu/gis/GISZoneCollectionMultiPoint.java
Modified: trunk/framework/ctulu-gis/src/main/java/org/fudaa/ctulu/gis/GISZoneAttributeFactory.java
===================================================================
--- trunk/framework/ctulu-gis/src/main/java/org/fudaa/ctulu/gis/GISZoneAttributeFactory.java 2011-11-30 13:33:42 UTC (rev 6734)
+++ trunk/framework/ctulu-gis/src/main/java/org/fudaa/ctulu/gis/GISZoneAttributeFactory.java 2011-11-30 13:57:26 UTC (rev 6735)
@@ -9,8 +9,8 @@
import java.util.Arrays;
+import com.vividsolutions.jts.geom.CoordinateSequence;
import com.vividsolutions.jts.geom.Geometry;
-import com.vividsolutions.jts.geom.LineString;
/**
* @author Fred Deniger
@@ -31,24 +31,7 @@
*/
public static GISReprojectInterpolateurI create1DInterpolateur(final GISAttributeInterface _att,
final GISCoordinateSequenceContainerInterface _src, final GISCoordinateSequenceContainerInterface _target, final GISAttributeModel _model) {
- final Class clazz = _att.getDataClass();
- if (clazz == Integer.class) {
- return new GISReprojectInterpolateur1DInteger(_src.getCoordinateSequence(), _target.getCoordinateSequence(),
- (GISAttributeModelIntegerInterface) _model);
- } else if (clazz == Double.class) {
- return new GISReprojectInterpolateur1DDouble(_src.getCoordinateSequence(), _target.getCoordinateSequence(),
- (GISAttributeModelDoubleInterface) _model);
- } else if (clazz == Boolean.class) {
- return new GISReprojectInterpolateur1DBoolean(_src.getCoordinateSequence(), _target.getCoordinateSequence(),
- (GISAttributeModelBooleanInterface) _model);
- } else if (clazz == Long.class) {
- return new GISReprojectInterpolateur1DLong(_src.getCoordinateSequence(), _target.getCoordinateSequence(),
- (GISAttributeModelLongInterface) _model);
- } else {
- return new GISReprojectInterpolateur1DObject(_src.getCoordinateSequence(), _target.getCoordinateSequence(),
- (GISAttributeModelObjectInterface) _model);
- }
-
+ return create1DInterpolateur(_att,_src.getCoordinateSequence(),_target.getCoordinateSequence(), _model);
}
/**
@@ -60,34 +43,33 @@
*/
public static GISReprojectInterpolateurI create1DInterpolateur(final GISAttributeInterface _att,
final Geometry _src, final Geometry _target, final GISAttributeModel _model) {
+ return create1DInterpolateur(_att,new GISCoordinateSequence(_src.getCoordinates()),new GISCoordinateSequence(_target.getCoordinates()), _model);
+ }
+
+ /**
+ * @param _att l'attribut
+ * @param _src la liste des points source
+ * @param _target la liste des points cible
+ * @param _model le model initial
+ * @return l'interpolateur 1d
+ */
+ public static GISReprojectInterpolateurI create1DInterpolateur(final GISAttributeInterface _att, final CoordinateSequence _src, final CoordinateSequence _target, final GISAttributeModel _model) {
final Class clazz = _att.getDataClass();
if (clazz == Integer.class) {
- return new GISReprojectInterpolateur1DInteger(
- new GISCoordinateSequence(_src.getCoordinates()),
- new GISCoordinateSequence(_target.getCoordinates()),
- (GISAttributeModelIntegerInterface) _model);
- } else if (clazz == Double.class) {
- return new GISReprojectInterpolateur1DDouble(
- new GISCoordinateSequence(_src.getCoordinates()),
- new GISCoordinateSequence(_target.getCoordinates()),
- (GISAttributeModelDoubleInterface) _model);
- } else if (clazz == Boolean.class) {
- return new GISReprojectInterpolateur1DBoolean(
- new GISCoordinateSequence(_src.getCoordinates()),
- new GISCoordinateSequence(_target.getCoordinates()),
- (GISAttributeModelBooleanInterface) _model);
- } else if (clazz == Long.class) {
- return new GISReprojectInterpolateur1DLong(
- new GISCoordinateSequence(_src.getCoordinates()),
- new GISCoordinateSequence(_target.getCoordinates()),
- (GISAttributeModelLongInterface) _model);
- } else {
- return new GISReprojectInterpolateur1DObject(
- new GISCoordinateSequence(_src.getCoordinates()),
- new GISCoordinateSequence(_target.getCoordinates()),
- (GISAttributeModelObjectInterface) _model);
+ return new GISReprojectInterpolateur1DInteger(_src, _target, (GISAttributeModelIntegerInterface) _model);
}
-
+ else if (clazz == Double.class) {
+ return new GISReprojectInterpolateur1DDouble(_src, _target, (GISAttributeModelDoubleInterface) _model);
+ }
+ else if (clazz == Boolean.class) {
+ return new GISReprojectInterpolateur1DBoolean(_src, _target, (GISAttributeModelBooleanInterface) _model);
+ }
+ else if (clazz == Long.class) {
+ return new GISReprojectInterpolateur1DLong(_src, _target, (GISAttributeModelLongInterface) _model);
+ }
+ else {
+ return new GISReprojectInterpolateur1DObject(_src, _target, (GISAttributeModelObjectInterface) _model);
+ }
}
public static GISAttributeModel createModelList(final GISAttributeInterface _att, final Object _valatt, final int _capacity,
Modified: trunk/framework/ctulu-gis/src/main/java/org/fudaa/ctulu/gis/GISZoneCollection.java
===================================================================
--- trunk/framework/ctulu-gis/src/main/java/org/fudaa/ctulu/gis/GISZoneCollection.java 2011-11-30 13:33:42 UTC (rev 6734)
+++ trunk/framework/ctulu-gis/src/main/java/org/fudaa/ctulu/gis/GISZoneCollection.java 2011-11-30 13:57:26 UTC (rev 6735)
@@ -269,7 +269,7 @@
* @param _geom La g\xE9om\xE9trie.
* @param _datas Les valeurs d'attributs, dans l'ordre.
* @param _cmd Le manager de commandes.
- * @return l'index de l'attribut cr\xE9e, -1 si rien n'est cr\xE9e
+ * @return l'index de la g\xE9om\xE9trie cr\xE9\xE9e, -1 si rien n'est cr\xE9e
*/
public abstract int addGeometry(Geometry _geom, Object[] _datas, CtuluCommandContainer _cmd);
Modified: trunk/framework/ctulu-gis/src/main/java/org/fudaa/ctulu/gis/GISZoneCollectionGeometry.java
===================================================================
--- trunk/framework/ctulu-gis/src/main/java/org/fudaa/ctulu/gis/GISZoneCollectionGeometry.java 2011-11-30 13:33:42 UTC (rev 6734)
+++ trunk/framework/ctulu-gis/src/main/java/org/fudaa/ctulu/gis/GISZoneCollectionGeometry.java 2011-11-30 13:57:26 UTC (rev 6735)
@@ -115,13 +115,14 @@
* @param _idxBefore L'indice du point juste avant. Si _idxBefore est \xE9gal \xE0 -1, le point est ajout\xE9 en d\xE9but de g\xE9om\xE9trie
* @param _x La coordonn\xE9e X du sommet ajout\xE9.
* @param _y La coordonn\xE9e Y du sommet ajout\xE9.
- * @param _cmd Le manager de commandes.
+ * @param _cmd Le manager de commandes.
+ * @return L'index du point ins\xE9r\xE9, ou -1 si non ins\xE9r\xE9.
*/
- public void addAtomic(final int _idxGeom, final int _idxBefore, final double _x, final double _y,
+ public int addAtomic(final int _idxGeom, final int _idxBefore, final double _x, final double _y,
final CtuluCommandContainer _cmd) {
if (!isGeomModifiable_) {
- return;
+ return -1;
}
Geometry geom = (Geometry)super.geometry_.getValueAt(_idxGeom);
final Coordinate[] oldcs = geom.getCoordinates();
@@ -137,12 +138,22 @@
cs[idx++] = new Coordinate(_x, _y, 0.);
}
}
+
+ // Polygone => La derni\xE8re coordonn\xE9e doit \xEAtre egale a la premiere
+ if (geom instanceof GISPolygone) {
+ cs[initSize]=cs[0];
+ }
geom = GISGeometryFactory.INSTANCE.createGeometry(geom.getClass(),cs);
- setGeometry(_idxGeom,geom, _cmd);
+ setGeometry(_idxGeom,geom, _cmd);
+
+ return _idxBefore+1;
}
/**
+ * Remplace une geometrie et modifie la valeur de ses attributs atomiques par interpolation
+ * si le nombre de sommets est diff\xE9rent de la geometrie initiale.
+ *
* @param _idx l'indice de la ligne a changer
* @param _geom la nouvelle ligne
* @param _cmd le receveur de commande
@@ -238,24 +249,25 @@
boolean r = true;
final Geometry old = (Geometry) getGeometry(_idxGeom);
int nbPt = old.getNumPoints();
-
+
// Raccourci si tous les sommets sont s\xE9lectionn\xE9s.
int nbSel=_sel.getNbSelectedIndex();
- if (nbSel==nbPt) {
+ if (nbSel==nbPt || (nbSel+1==nbPt && old instanceof GISPolygone)) {
removeGeometries(new int[]{_idxGeom}, _cmd);
return true;
- }
-
- // dans le cas polygone le dernier point n'est pas a considerer=premier point
- if (old instanceof GISPolygone) {
- nbPt--;
- }
+ }
+
// les nouvelles coordonnees.
final Coordinate[] newCs = new Coordinate[nbPt-nbSel];
// cette liste contient les indices a enlever : creee que si necessaire
// si des attributes atomics existent
final TIntArrayList idxToRemove = containsAtomicAttribute() ? new TIntArrayList(nbPt-nbSel) : null;
+ // dans le cas polygone le dernier point n'est pas a considerer=premier point
+ if (old instanceof GISPolygone) {
+ nbPt--;
+ }
+
// compteur tempo
int count = 0;
for (int idxPt = 0; idxPt < nbPt; idxPt++) {
@@ -268,6 +280,11 @@
// newCs[count++] = (Coordinate)old.getCoordinates()[idxPt].clone();
}
}
+
+ if (old instanceof GISPolygone) {
+ newCs[count]=newCs[0];
+ }
+
Geometry newGeom = null;
// Un polygone
Modified: trunk/framework/ctulu-gis/src/main/java/org/fudaa/ctulu/gis/GISZoneCollectionLigneBrisee.java
===================================================================
--- trunk/framework/ctulu-gis/src/main/java/org/fudaa/ctulu/gis/GISZoneCollectionLigneBrisee.java 2011-11-30 13:33:42 UTC (rev 6734)
+++ trunk/framework/ctulu-gis/src/main/java/org/fudaa/ctulu/gis/GISZoneCollectionLigneBrisee.java 2011-11-30 13:57:26 UTC (rev 6735)
@@ -11,27 +11,16 @@
*/
package org.fudaa.ctulu.gis;
-import gnu.trove.TIntArrayList;
-
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import java.util.Map;
-import com.memoire.fu.FuLog;
-import com.vividsolutions.jts.geom.Coordinate;
+import org.fudaa.ctulu.CtuluCommandContainer;
+
import com.vividsolutions.jts.geom.CoordinateSequence;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.LineString;
-import org.fudaa.ctulu.CtuluCommandComposite;
-import org.fudaa.ctulu.CtuluCommandCompositeInverse;
-import org.fudaa.ctulu.CtuluCommandContainer;
-import org.fudaa.ctulu.CtuluLib;
-import org.fudaa.ctulu.CtuluLibString;
-import org.fudaa.ctulu.CtuluListSelectionInterface;
-import org.fudaa.ctulu.CtuluUI;
-
/**
* @author Fred Deniger
* @version $Id: GISZoneCollectionLigneBrisee.java,v 1.20.6.4 2008-04-01 07:22:47 bmarchan Exp $
@@ -221,110 +210,4 @@
public Class getDataStoreClass() {
return LineString.class;
}
-
- /*
- * Surcharge, en attendant d'etre sur que la methode m\xE8re fonctionne dans tous les cas.
- */
- public boolean removeAtomics(final int _idxGeom, final CtuluListSelectionInterface _sel, final CtuluUI _ui,
- final CtuluCommandContainer _cmd) {
- if (_sel == null || _sel.isEmpty()) { return false; }
- boolean r = true;
- final LineString line = (LineString) getGeometry(_idxGeom);
- int nbPt = line.getCoordinateSequence().size();
-
- // Raccourci si tous les sommets sont s\xE9lectionn\xE9s.
- int nbSel=_sel.getNbSelectedIndex();
- if (nbSel==nbPt||(nbSel+1==nbPt&&(geometry_.getValueAt(_idxGeom) instanceof GISPolygone))) {
- removeGeometries(new int[]{_idxGeom}, _cmd);
- return true;
- }
-
- // les nouvelles coordonnees.
- final Coordinate[] newCs = new Coordinate[nbPt];
- // cette liste contient les indice a enlever : creee que si necessaire
- // si des attribute atomics existent
- final TIntArrayList idxToRemove = containsAtomicAttribute() ? new TIntArrayList(nbPt) : null;
- // dans le cas polygone le dernier point n'est pas a considerer=premier
- // point
- if (line/* .isClosed() */instanceof GISPolygone) {
- nbPt--;
- }
-
- // compteur tempo
- int count = 0;
- for (int idxPt = 0; idxPt < nbPt; idxPt++) {
- if (_sel.isSelected(idxPt)) {
- if (idxToRemove != null) {
- idxToRemove.add(idxPt);
- }
- } else {
- newCs[count++] = line.getCoordinateSequence().getCoordinateCopy(idxPt);
- }
- }
- LineString newString = null;
-
- // Un polygone
- if (line/* .isClosed() */instanceof GISPolygone) {
- if (count < 3) {
- r = false;
- if (_ui != null) {
- _ui.error(null, CtuluLib.getS("La ligne brisee doit contenir {0} points au moins", CtuluLibString.TROIS),
- false);
- }
-
- } else {
- newCs[count++] = newCs[0];
- final Coordinate[] coord = new Coordinate[count];
- System.arraycopy(newCs, 0, coord, 0, coord.length);
- newString = GISGeometryFactory.INSTANCE.createLinearRing(coord);
- newString.setUserData(line.getUserData());
- }
- }
-
- // Une polyligne
- else if (line instanceof GISPolyligne) {
- if (count < 2) {
- r = false;
- if (_ui != null) {
- _ui.error(null, CtuluLib.getS("La ligne brisee doit contenir {0} points au moins", CtuluLibString.DEUX),
- false);
- }
- if (FuLog.isTrace()) {
- FuLog.trace("EBLI: polylignes: not enough points");
- // message
- }
- } else {
- final Coordinate[] coord = new Coordinate[count];
- System.arraycopy(newCs, 0, coord, 0, coord.length);
- newString = GISGeometryFactory.INSTANCE.createLineString(coord);
- newString.setUserData(line.getUserData());
- }
- }
-
- if (r) {
- final CtuluCommandComposite cmp = new CtuluCommandCompositeInverse();
-
- // si des attributs atomics sont concerne
- if (idxToRemove != null && idxToRemove.size() > 0) {
- final int[] idx = idxToRemove.toNativeArray();
- Arrays.sort(idx);
- for (int i = getNbAttributes() - 1; i >= 0; i--) {
- // attribut atomic
- if (getAttribute(i).isAtomicValue()) {
- // dans ce cas on recupere le model contenant cet attribut
- final GISAttributeModel m = getModelListener(i);
- // on recupere le sous-model concerne par la modif de geometrie
- final GISAttributeModel atomicModel = (GISAttributeModel) m.getObjectValueAt(_idxGeom);
- // on le change
- m.setObject(_idxGeom, atomicModel.createSubModel(idx), cmp);
- }
- }
- }
- super.geometry_.setObject(_idxGeom, newString, cmp);
- if (_cmd != null) {
- _cmd.addCmd(cmp.getSimplify());
- }
- }
- return r;
- }
}
Modified: trunk/framework/ctulu-gis/src/main/java/org/fudaa/ctulu/gis/GISZoneCollectionMultiPoint.java
===================================================================
--- trunk/framework/ctulu-gis/src/main/java/org/fudaa/ctulu/gis/GISZoneCollectionMultiPoint.java 2011-11-30 13:33:42 UTC (rev 6734)
+++ trunk/framework/ctulu-gis/src/main/java/org/fudaa/ctulu/gis/GISZoneCollectionMultiPoint.java 2011-11-30 13:57:26 UTC (rev 6735)
@@ -64,23 +64,28 @@
}
/*
- * Le sommet est ajout\xE9 sans interpolation des valeurs atomiques.
+ * Surcharge pour sommet ajout\xE9 sans interpolation des valeurs atomiques.
*/
- public void addAtomic(final int _idxGeom, final int _idxBefore, final double _x, final double _y,
+ @Override
+ public int addAtomic(final int _idxGeom, final int _idxBefore, final double _x, final double _y,
final CtuluCommandContainer _cmd) {
if (!isGeomModifiable_) {
- return;
+ return -1;
}
Geometry geom = (Geometry)super.geometry_.getValueAt(_idxGeom);
final Coordinate[] oldcs = geom.getCoordinates();
final int initSize = oldcs.length;
+ if(_idxBefore<-1||_idxBefore>=initSize)
+ throw new IllegalArgumentException("L'index du point \xE0 ajouter doit appartenir \xE0 la g\xE9om\xE9trie.");
TIntIntHashMap newIdxOldIdx=new TIntIntHashMap(initSize);
final Coordinate[] cs = new Coordinate[initSize + 1];
int idx = 0;
- for (int i = 0; i < initSize; i++) {
- newIdxOldIdx.put(idx,i); // Pour les attributs
- cs[idx++] = (Coordinate)oldcs[i].clone();
+ for (int i = -1; i < initSize; i++) {
+ if (i>=0) {
+ newIdxOldIdx.put(idx,i); // Pour les attributs
+ cs[idx++] = (Coordinate)oldcs[i].clone();
+ }
if (i == _idxBefore) {
cs[idx++] = new Coordinate(_x, _y, 0);
}
@@ -106,6 +111,8 @@
if (_cmd!=null) {
_cmd.addCmd(cmp.getSimplify());
}
+
+ return _idxBefore+1;
}
public Class getDataStoreClass() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|