From: <bma...@us...> - 2009-06-10 20:59:21
|
Revision: 4868 http://fudaa.svn.sourceforge.net/fudaa/?rev=4868&view=rev Author: bmarchan Date: 2009-06-10 20:59:11 +0000 (Wed, 10 Jun 2009) Log Message: ----------- BugFix sur r?\195?\169ordonnancement X ou Y + test Junit sur Model2dLine Modified Paths: -------------- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/MdlSceneEditor.java branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/action/SceneOrganizePointAction.java branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/layer/MdlModel2dLine.java Added Paths: ----------- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/test/org/fudaa/fudaa/modeleur/layer/ branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/test/org/fudaa/fudaa/modeleur/layer/TestJModel2dLine.java Modified: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/MdlSceneEditor.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/MdlSceneEditor.java 2009-06-10 20:53:17 UTC (rev 4867) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/MdlSceneEditor.java 2009-06-10 20:59:11 UTC (rev 4868) @@ -10,7 +10,6 @@ import gnu.trove.TIntArrayList; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -24,7 +23,6 @@ import org.fudaa.ctulu.gis.GISAttributeInterface; import org.fudaa.ctulu.gis.GISAttributeModelDoubleArray; import org.fudaa.ctulu.gis.GISCoordinateSequenceContainerInterface; -import org.fudaa.ctulu.gis.GISCoordinateSequenceFactory; import org.fudaa.ctulu.gis.GISDataModel; import org.fudaa.ctulu.gis.GISDataModelFilterAdapter; import org.fudaa.ctulu.gis.GISDataModelMultiAdapter; @@ -410,60 +408,23 @@ /** * Sort the points of selected polylignes. This sorting is done on the - * _criterion. It can be 'x' or 'y'. + * _icoord. + * @param _icoord 0: x, 1: y. */ - public void organizePoint(String _criterion) { - /** This class contain needed data to sort points. */ - class DataPoint implements Comparable<DataPoint>{ - public Coordinate c; - private String criterion_; - public DataPoint(Coordinate coord, String _criterion) { - if(!_criterion.equals("x")&&!_criterion.equals("y")) - throw new IllegalArgumentException(FudaaLib.getS("Le crit\xE8re n'a pas \xE9t\xE9 reconnu.")); - criterion_=_criterion; - c=coord; - } - /** M\xE9thode pour utiliser les alorithmes de tris fournis par java. */ - public int compareTo(DataPoint o) { - if(criterion_.equals("x")) - return compareX(o); - else - return compareY(o); - } - public int compareX(DataPoint o) { - if (c.x<o.c.x) return -1; - else if (c.x==o.c.x) return 0; - else return 1; - } - public int compareY(DataPoint o) { - if (c.y<o.c.y) return -1; - else if (c.y==o.c.y) return 0; - else return 1; - } - } - CtuluCommandComposite cmd=new CtuluCommandComposite(FudaaLib.getS("R\xE9organisation de la g\xE9om\xE9trie")); - int[] geoms=getScene().getSelectionHelper().getSelectedIndexes(); - for (int i=0; i<geoms.length; i++) { + public void organizePoint(int _icoord) { + CtuluCommandComposite cmp=new CtuluCommandComposite(FudaaLib.getS("R\xE9organisation de la g\xE9om\xE9trie")); + int[] idxScenes=getScene().getSelectionHelper().getSelectedIndexes(); + for (int i=0; i<idxScenes.length; i++) { // Data retrieval - int idxGeom=getScene().sceneId2LayerId(geoms[i]); - ZCalqueAffichageDonneesInterface calque=getScene().getLayerForId(geoms[i]); - if (calque.modeleDonnees() instanceof ZModeleGeometry) { - GISZoneCollection zone=((ZModeleGeometry)calque.modeleDonnees()).getGeomData(); - CoordinateSequence seq=zone.getCoordinateSequence(idxGeom); - // Construction de la structure de tri - DataPoint[] points=new DataPoint[seq.size()]; - for(int j=0;j<points.length;j++) - points[j]=new DataPoint(seq.getCoordinate(j), _criterion); - Arrays.sort(points); - // R\xE9percution du tri - Coordinate[] coords=new Coordinate[points.length]; - for(int j=0;j<points.length;j++) - coords[j]=new Coordinate(points[j].c); - zone.setCoordinateSequence(idxGeom, new GISCoordinateSequenceFactory().create(coords), cmd); - } + int idxGeom=getScene().sceneId2LayerId(idxScenes[i]); + ZModeleDonnees mdld=getScene().getLayerForId(idxScenes[i]).modeleDonnees(); + + if (mdld instanceof MdlModel2dLine) + ((MdlModel2dLine)mdld).organizePoints(idxGeom, _icoord, cmp); } + if(getMng()!=null) - getMng().addCmd(cmd.getSimplify()); + getMng().addCmd(cmp.getSimplify()); } /** Modified: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/action/SceneOrganizePointAction.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/action/SceneOrganizePointAction.java 2009-06-10 20:53:17 UTC (rev 4867) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/action/SceneOrganizePointAction.java 2009-06-10 20:59:11 UTC (rev 4868) @@ -56,6 +56,6 @@ } public void actionPerformed(final ActionEvent _e) { - sceneEditor_.organizePoint(criterion_); + sceneEditor_.organizePoint(criterion_==x ? 0:1); } } Modified: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/layer/MdlModel2dLine.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/layer/MdlModel2dLine.java 2009-06-10 20:53:17 UTC (rev 4867) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/layer/MdlModel2dLine.java 2009-06-10 20:59:11 UTC (rev 4868) @@ -9,15 +9,19 @@ import gnu.trove.TIntArrayList; +import java.util.Arrays; + import org.fudaa.ctulu.CtuluCommandComposite; import org.fudaa.ctulu.CtuluCommandContainer; import org.fudaa.ctulu.CtuluListSelection; import org.fudaa.ctulu.CtuluListSelectionInterface; import org.fudaa.ctulu.CtuluNamedCommand; import org.fudaa.ctulu.gis.GISAttributeModel; +import org.fudaa.ctulu.gis.GISCoordinateSequenceFactory; import org.fudaa.ctulu.gis.GISGeometryFactory; import org.fudaa.ctulu.gis.GISLib; import org.fudaa.ctulu.gis.GISPolyligne; +import org.fudaa.ctulu.gis.GISZoneCollection; import org.fudaa.ctulu.gis.GISZoneCollectionLigneBrisee; import org.fudaa.ebli.calque.ZModelGeometryListener; import org.fudaa.ebli.calque.ZModelListener; @@ -216,4 +220,57 @@ }); } } + + /** + * Sort the points of selected polylignes. This sorting is done on the _icoord. + * @param _icoord 0: x, 1: y. + */ + public void organizePoints(int _idxGeom, int _icoord, CtuluCommandContainer _cmd) { + + /** This class contain needed data to sort points. */ + class SortableIndex implements Comparable<SortableIndex>{ + public double coord; + private int ind; + public SortableIndex(double _coord, int _ind) { + ind=_ind; + coord=_coord; + } + + public int compareTo(SortableIndex o) { + if (coord<o.coord) return -1; + else if (coord==o.coord) return 0; + else return 1; + } + } + + CtuluCommandComposite cmp=new CtuluCommandComposite(FudaaLib.getS("R\xE9organisation de la g\xE9om\xE9trie")); + + GISZoneCollection zone=getGeomData(); + CoordinateSequence oldseq=zone.getCoordinateSequence(_idxGeom); + // Construction de la structure de tri + SortableIndex[] points=new SortableIndex[oldseq.size()]; + for(int j=0;j<points.length;j++) + points[j]=new SortableIndex(oldseq.getOrdinate(j,_icoord), j); + Arrays.sort(points); + + // Remplacement de la g\xE9om\xE9trie r\xE9ordonn\xE9e. + Coordinate[] coords=new Coordinate[points.length]; + for(int j=0;j<points.length;j++) + coords[j]=oldseq.getCoordinateCopy(points[j].ind); + zone.setCoordinateSequence(_idxGeom, new GISCoordinateSequenceFactory().create(coords), cmp); + + // R\xE9ordonnancement des attributs atomiques. + for(int iatt=0;iatt<zone.getNbAttributes();iatt++) + if(zone.getAttribute(iatt).isAtomicValue()){ + GISAttributeModel oldvalues=(GISAttributeModel) zone.getDataModel(iatt).getObjectValueAt(_idxGeom); + GISAttributeModel newvalues=(GISAttributeModel)zone.getDataModel(iatt).getAttribute().createDataForGeom(oldvalues, oldvalues.getSize()); + for(int j=0;j<oldvalues.getSize();j++){ + newvalues.setObject(j,oldvalues.getObjectValueAt(points[j].ind), null); + } + zone.setAttributValue(iatt, _idxGeom,newvalues,cmp); + } + + if(_cmd!=null) + _cmd.addCmd(cmp.getSimplify()); + } } Added: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/test/org/fudaa/fudaa/modeleur/layer/TestJModel2dLine.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/test/org/fudaa/fudaa/modeleur/layer/TestJModel2dLine.java (rev 0) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/test/org/fudaa/fudaa/modeleur/layer/TestJModel2dLine.java 2009-06-10 20:59:11 UTC (rev 4868) @@ -0,0 +1,244 @@ +/* + * @creation 10 juin 2009 + * @modification $Date:$ + * @license GNU General Public License 2 + * @copyright (c)1998-2009 CETMEF 2 bd Gambetta F-60231 Compiegne + * @mail fud...@li... + */ +package org.fudaa.fudaa.modeleur.layer; + +import junit.framework.TestCase; + +import org.fudaa.ctulu.CtuluCommandManager; +import org.fudaa.ctulu.gis.GISAttributeConstants; +import org.fudaa.ctulu.gis.GISAttributeInterface; +import org.fudaa.ctulu.gis.GISAttributeModel; +import org.fudaa.ctulu.gis.GISGeometryFactory; +import org.fudaa.ctulu.gis.GISPolyligne; + +import com.vividsolutions.jts.geom.Coordinate; + +/** + * @author Bertrand Marchand + * @version $Id:$ + */ + +/** + * Pour tester un modele de lignes 2D. + * @author Bertrand Marchand + * @version $Id$ + */ +public class TestJModel2dLine extends TestCase { + + static final double[][] coords_={ + {752.8254,1021.2861, 513.0 }, + {742.6896,1021.5333, 513.0 }, + {732.5538,1021.7806, 513.0 }, + {722.418 ,1022.0278, 513.0 }, + {712.2822,1022.275 , 513.0 }, + {702.1464,1022.5222, 513.0 }, + {692.0107,1022.7694, 513.0 }, + {681.8749,1023.0166, 512.0 }, + {671.7391,1023.2638, 512.6667 }, + {671.7391,1023.2638, 512.6667 }, + {665.8059,1023.5935, 512.6667 }, + {665.8059,1023.5935, 513.3333 }, + {665.8059,1023.5935, 513.3333 }, + {656.9062,1024.0879, 513.3333 }, + {646.3434,1024.1628, 514.0 }, + {635.7806,1024.2377, 514.0 }, + {625.2179,1024.3126, 514.0 }, + {614.6551,1024.3875, 514.0 }, + {604.0923,1024.4625, 514.0 }, + {593.5295,1024.5374, 514.0 }, + {582.9667,1024.6123, 514.0 }, + {572.4039,1024.6872, 514.0 }, + {561.8411,1024.7621, 514.0 }, + {551.2783,1024.837 , 514.0 }, + {540.7155,1024.9119, 514.0 }, + {540.7155,1024.9119, 514.0 }, + {534.5191,1023.9461, 514.0 }, + {534.5191,1023.9461, 514.0 }, + {528.3226,1022.9803, 514.0 }, + {528.3226,1022.9803, 514.0 }, + {522.1262,1022.0144, 514.0 }, + {514.7445,1021.9455, 514.0 }, + {507.3628,1021.8765, 514.0 }, + {499.9811,1021.8075, 514.0 }, + {492.5993,1021.7385, 514.0 }, + {485.2176,1021.6695, 514.0 }, + {477.8359,1021.6005, 514.0 }, + {470.4542,1021.5315, 513.8333 }, + {463.0725,1021.4625, 513.6667 }, + {455.6908,1021.3936, 513.5 }, + {448.3091,1021.3246, 513.3333 }, + {440.9274,1021.2556, 513.1667 }, + {433.5456,1021.1866, 513.0 }, + {433.5456,1021.1866, 512.8333 }, + {427.4747,1021.1866, 512.6667 }, + {427.4747,1021.1866, 512.5 }, + {421.4038,1021.1866, 512.3333 }, + {421.4038,1021.1866, 512.1667 }, + {415.3328,1021.1866, 512.0 }, + {409.5378,1021.2901, 512.0 }, + {403.7428,1021.3936, 512.0 }, + {397.9479,1021.497 , 512.0 }, + {392.1529,1021.6005, 512.0 }, + {386.3579,1021.704 , 512.0 }, + {380.5629,1021.8075, 512.0 }, + {374.7679,1021.911 , 512.5 }, + {368.9729,1022.0144, 513.0 }, + {368.9729,1022.0144, 513.5 }, + {368.9729,1022.0144, 514.0 }, + {361.5222,1021.1866, 514.5 }, + {361.5222,1021.1866, 515.0 }, + {361.5222,1021.1866,515.5 }, + {354.0715,1020.3587,516.0 }, + {354.0715,1020.3587, 516.5 }, + {354.0715,1020.3587, 517.0 }, + {347.1727,1020.6347, 517.5 }, + {347.1727,1020.6347, 517.5 }, + {347.1727,1020.6347, 517.5 }, + {340.2739,1020.9106, 517.5 }, + {340.2739,1020.9106, 517.5 }, + {340.2739,1020.9106, 517.5 }, + {333.3751,1021.1866, 517.55 } + }; + + /** Le mod\xE8le */ + static MdlModel2dLine mdl; + /** Des labels pos\xE9s sur des coordonn\xE9es particuli\xE8res */ + static int[] indLabels; + /** Le manager de commandes. */ + static CtuluCommandManager mng; + + /** Initialisation du test */ + static { + mdl=new MdlModel2dLine(null); + + // Cr\xE9ation d'une polyligne. + Coordinate[] coords=new Coordinate[coords_.length]; + for (int i=0; i<coords.length; i++) { + coords[i]=new Coordinate(coords_[i][0],coords_[i][1],coords_[i][2]); + } + GISPolyligne pl=GISGeometryFactory.INSTANCE.createLineString(coords); + mdl.getGeomData().addGeometry(pl, null, null); + + // Ajout des attributs Z et Label + mdl.getGeomData().setAttributes(new GISAttributeInterface[]{GISAttributeConstants.BATHY, GISAttributeConstants.LABEL},null); + + // Pour initialiser le Z Attribute depuis le Z coordinate. + mdl.getGeomData().postImport(0); + + // Definition de 3 labels. + int iattLb=mdl.getGeomData().getIndiceOf(GISAttributeConstants.LABEL); + indLabels=new int[]{3,8,9}; + for (int i=0; i<indLabels.length; i++) { + ((GISAttributeModel)mdl.getGeomData().getValue(iattLb, 0)).setObject(indLabels[i],"Pt"+indLabels[i],null); + } + + // Le manager de undo/redo + mng=new CtuluCommandManager(); + } + + /** + * Teste l'inversion d'orientation d'une ligne. + * Le parcours est invers\xE9, les attributs doivent correspondre. + */ + public void testInvertOrientation() { + assertEquals(mdl.getNombre(),1); + int iattLb=mdl.getGeomData().getIndiceOf(GISAttributeConstants.LABEL); + + GISPolyligne pl=(GISPolyligne)mdl.getGeomData().getGeometry(0); + int ilast=pl.getNumPoints()-1; + double x1=pl.getCoordinateSequence().getX(2); + double y1=pl.getCoordinateSequence().getY(2); + String lb11=(String)((GISAttributeModel)mdl.getGeomData().getValue(iattLb, 0)).getObjectValueAt(3); + String lb12=(String)((GISAttributeModel)mdl.getGeomData().getValue(iattLb, 0)).getObjectValueAt(8); + String lb13=(String)((GISAttributeModel)mdl.getGeomData().getValue(iattLb, 0)).getObjectValueAt(9); + + mdl.invertOrientation(0,mng); + + pl=(GISPolyligne)mdl.getGeomData().getGeometry(0); + double x2=pl.getCoordinateSequence().getX(ilast-2); + double y2=pl.getCoordinateSequence().getY(ilast-2); + String lb21=(String)((GISAttributeModel)mdl.getGeomData().getValue(iattLb, 0)).getObjectValueAt(ilast-3); + String lb22=(String)((GISAttributeModel)mdl.getGeomData().getValue(iattLb, 0)).getObjectValueAt(ilast-8); + String lb23=(String)((GISAttributeModel)mdl.getGeomData().getValue(iattLb, 0)).getObjectValueAt(ilast-9); + + assertEquals(y1, y2,0); + assertEquals(x1, x2,0); + assertEquals(lb11, lb21); + assertEquals(lb12, lb22); + assertEquals(lb13, lb23); + + // Reset. + mng.undo(); + } + + /** + * Teste la r\xE9organisation d'une ligne suivant X. + * Le parcours est ordonn\xE9 croissant suivant X, les attributs doivent correspondre. + */ + public void testOrganizeX() { + int iattLb=mdl.getGeomData().getIndiceOf(GISAttributeConstants.LABEL); + + GISPolyligne pl=(GISPolyligne)mdl.getGeomData().getGeometry(0); + // La coordonn\xE9e et le label correspondant. + Coordinate c1=pl.getCoordinateSequence().getCoordinate(indLabels[0]); + String lb1=(String)((GISAttributeModel)mdl.getGeomData().getValue(iattLb, 0)).getObjectValueAt(indLabels[0]); + // Le label doit \xEAtre le bon (sinon peut \xEAtre le test pr\xE9cedent est invalide). + assertEquals(lb1, "Pt"+indLabels[0]); + + mdl.organizePoints(0,0,mng); + + pl=(GISPolyligne)mdl.getGeomData().getGeometry(0); + boolean found=false; + for (int i=0; i<pl.getNumPoints()-1; i++) { + // Les coordonn\xE9es doivent \xEAtre croissantes en X + assertTrue(pl.getCoordinateSequence().getX(i+1)>=pl.getCoordinateSequence().getX(i)); + if (pl.getCoordinateSequence().getCoordinate(i).equals2D(c1)) { + // Le label doit toujours correspondre \xE0 la coordonn\xE9e. + assertEquals(lb1,(String)((GISAttributeModel)mdl.getGeomData().getValue(iattLb, 0)).getObjectValueAt(i)); + found=true; + } + } + assertTrue(found); + + // Reset. + mng.undo(); + } + + /** + * Teste la r\xE9organisation d'une ligne suivant Y. + * Le parcours est ordonn\xE9 croissant suivant Y, les attributs doivent correspondre. + */ + public void testOrganizeY() { + int iattLb=mdl.getGeomData().getIndiceOf(GISAttributeConstants.LABEL); + + GISPolyligne pl=(GISPolyligne)mdl.getGeomData().getGeometry(0); + // La coordonn\xE9e et le label correspondant. + Coordinate c1=pl.getCoordinateSequence().getCoordinate(indLabels[0]); + String lb1=(String)((GISAttributeModel)mdl.getGeomData().getValue(iattLb, 0)).getObjectValueAt(indLabels[0]); + // Le label doit \xEAtre le bon (sinon peut \xEAtre le test pr\xE9cedent est invalide). + assertEquals(lb1, "Pt"+indLabels[0]); + + mdl.organizePoints(0,1,mng); + + pl=(GISPolyligne)mdl.getGeomData().getGeometry(0); + boolean found=false; + for (int i=0; i<pl.getNumPoints()-1; i++) { + // Les coordonn\xE9es doivent \xEAtre croissantes en Y + assertTrue(pl.getCoordinateSequence().getY(i+1)>=pl.getCoordinateSequence().getY(i)); + if (pl.getCoordinateSequence().getCoordinate(i).equals2D(c1)) { + // Le label doit toujours correspondre \xE0 la coordonn\xE9e. + assertEquals(lb1,(String)((GISAttributeModel)mdl.getGeomData().getValue(iattLb, 0)).getObjectValueAt(i)); + found=true; + } + } + assertTrue(found); + + // Reset. + mng.undo(); + } +} Property changes on: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/test/org/fudaa/fudaa/modeleur/layer/TestJModel2dLine.java ___________________________________________________________________ Added: svn:keywords + Id Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |