From: <emm...@us...> - 2009-02-12 17:10:09
|
Revision: 4459 http://fudaa.svn.sourceforge.net/fudaa/?rev=4459&view=rev Author: emmanuel_martin Date: 2009-02-12 17:10:04 +0000 (Thu, 12 Feb 2009) Log Message: ----------- Impl?\195?\169mentation partielle de la tache #178 (suite) Modified Paths: -------------- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/controller/ControllerBief.java branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/model/Bief.java branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/model/BiefSet.java branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/model/ProfilContainerAdapter.java branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/test/testModeleur1d/TestProfilContainerAdapter.java Added Paths: ----------- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/controller/BiefImporterFromModels.java branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/controller/BiefsImporterFromModeleur2d.java branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/controller/CancelException.java branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/model/UtilsBief1d.java branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/view/VueImportation.java Added: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/controller/BiefImporterFromModels.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/controller/BiefImporterFromModels.java (rev 0) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/controller/BiefImporterFromModels.java 2009-02-12 17:10:04 UTC (rev 4459) @@ -0,0 +1,574 @@ +/* + * @creation 11 f\xE9vr. 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.modeleur1d.controller; + +import org.fudaa.ctulu.gis.GISAttributeConstants; +import org.fudaa.ctulu.gis.GISAttributeInterface; +import org.fudaa.ctulu.gis.GISAttributeModel; +import org.fudaa.ctulu.gis.GISAttributeModelDoubleArray; +import org.fudaa.ctulu.gis.GISAttributeModelDoubleInterface; +import org.fudaa.ctulu.gis.GISAttributeModelIntegerList; +import org.fudaa.ctulu.gis.GISCoordinateSequenceContainerInterface; +import org.fudaa.ctulu.gis.GISCoordinateSequenceFactory; +import org.fudaa.ctulu.gis.GISLib; +import org.fudaa.ctulu.gis.GISPolyligne; +import org.fudaa.ctulu.gis.GISReprojectInterpolateur1DDouble; +import org.fudaa.ctulu.gis.GISZoneCollection; +import org.fudaa.ctulu.gis.GISZoneCollectionGeometry; +import org.fudaa.ctulu.gis.GISZoneCollectionLigneBrisee; +import org.fudaa.ebli.calque.ZModeleLigneBrisee; +import org.fudaa.fudaa.commun.FudaaLib; +import org.fudaa.fudaa.modeleur.layer.MdlModel1dAxe; +import org.fudaa.fudaa.modeleur.layer.MdlModel1dBank; +import org.fudaa.fudaa.modeleur.layer.MdlModel1dLimiteStockage; +import org.fudaa.fudaa.modeleur.layer.MdlModel2dConstraintLine; +import org.fudaa.fudaa.modeleur.layer.MdlModel2dDirectionLine; +import org.fudaa.fudaa.modeleur.layer.MdlModel2dProfile; +import org.fudaa.fudaa.modeleur.modeleur1d.model.Bief; +import org.fudaa.fudaa.modeleur.modeleur1d.model.UtilsBief1d; +import org.fudaa.fudaa.modeleur.modeleur1d.model.UtilsProfil1d; +import org.fudaa.fudaa.modeleur.modeleur1d.view.VueImportation; + +import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jts.geom.CoordinateSequence; +import com.vividsolutions.jts.geom.Geometry; + +/** + * Import un bief a partir d'un tableau de modeles. + * + * Cette classe est dans les controlleurs car elle peut instancier une vue pour + * demander \xE0 l'utilisateur certaines informations suppl\xE9mentaires. + * + * @author Emmanuel MARTIN + * @version $Id:$ + */ +public class BiefImporterFromModels { + + /** Le tableau de mod\xE8le tel que donn\xE9 \xE0 la construction de l'instance. */ + private ZModeleLigneBrisee[] models_; + // Les mod\xE8les en fonction de le contenu. Se sont les m\xEAmes que dans models_. + private ZModeleLigneBrisee axeHydraulique_; + private ZModeleLigneBrisee profils_; + private ZModeleLigneBrisee rives_; + private ZModeleLigneBrisee limitesStockages_; + private ZModeleLigneBrisee lignesDirectrices_; + private ZModeleLigneBrisee lignesContraints_; + + public BiefImporterFromModels(ZModeleLigneBrisee[] _models) { + if (_models==null) + throw new IllegalArgumentException(FudaaLib.getS("_models ne peut pas \xEAtre null.")); + models_=_models; + } + + /** + * @return le bief r\xE9sultant des mod\xE8les. + * @throws CancelException + */ + public Bief getBief() throws CancelException { + buildBief(); + Bief bief=new Bief(axeHydraulique_, lignesContraints_, lignesDirectrices_, limitesStockages_, profils_, rives_); + bief.enableSynchroniser(); + return bief; + } + + /** + * Construit les mod\xE8les. + * @throws CancelException + */ + private void buildBief() throws CancelException { + testAndValuateModels(); + // Valuation des attributs sp\xE9cifiques au 1d pour les profils \\ + GISZoneCollection zone=profils_.getGeomData(); + UtilsBief1d.normalizeProfilAttributes(zone); + normalizePKData(); + + int idxAttRiveGauche=zone.getIndiceOf(GISAttributeConstants.INTERSECTION_RIVE_GAUCHE); + int idxAttRiveDroite=zone.getIndiceOf(GISAttributeConstants.INTERSECTION_RIVE_DROITE); + int idxAttlsGauche=zone.getIndiceOf(GISAttributeConstants.INTERSECTION_LIMITE_STOCKAGE_GAUCHE); + int idxAttlsDroite=zone.getIndiceOf(GISAttributeConstants.INTERSECTION_LIMITE_STOCKAGE_DROITE); + int idxAttLignesDirectrices=zone.getIndiceOf(GISAttributeConstants.INTERSECTIONS_LIGNES_DIRECTRICES); + + UtilsBief1d.orderProfils(profils_, -1, null); + // Normalise le sens du profil \\ + for (int k=0; k<profils_.getNombre(); k++) { + Geometry profil=zone.getGeometry(k); + CoordinateSequence seqProfil=((GISCoordinateSequenceContainerInterface)profil).getCoordinateSequence(); + // Normalisation du sens (gauche/droite) du profil \\ + Coordinate interAxeProfil=seqProfil.getCoordinate(seqProfil.size()/2); + // Cr\xE9ation du vecteur contenant le sens de l'axe hydraulique + Coordinate vAxeH=null; + boolean noReorientation=false; + if (k>0) { + CoordinateSequence profilPrevious=zone.getCoordinateSequence(k-1); + Coordinate pointProfilPrevious=profilPrevious.getCoordinate(profilPrevious.size()/2); + vAxeH=new Coordinate(interAxeProfil.x-pointProfilPrevious.x, interAxeProfil.y-pointProfilPrevious.y, 0); + } + else if (k<profils_.getNombre()-1) { + CoordinateSequence profilPrevious=zone.getCoordinateSequence(k+1); + Coordinate pointProfilPrevious=profilPrevious.getCoordinate(profilPrevious.size()/2); + vAxeH=new Coordinate(pointProfilPrevious.x-interAxeProfil.x, pointProfilPrevious.y-interAxeProfil.y, 0); + } + else { + if (axeHydraulique_.getNombre()>0) { + Geometry axeHydraulique=(Geometry)axeHydraulique_.getObject(0); + CoordinateSequence seqAxeHydraulique=((GISCoordinateSequenceContainerInterface)axeHydraulique).getCoordinateSequence(); + // Normalisation du sens (gauche/droite) du profil \\ + Coordinate interAxeProfil2=profil.intersection(axeHydraulique).getCoordinate(); + // Cr\xE9ation du vecteur contenant le sens de l'axe hydraulique + int idxPrevious=UtilsProfil1d.getPreviousIndex(seqAxeHydraulique, interAxeProfil2); + int idxNext=UtilsProfil1d.getNextIndex(seqAxeHydraulique, interAxeProfil2); + if (idxPrevious!=-1) + vAxeH=new Coordinate(interAxeProfil2.x-seqAxeHydraulique.getCoordinate(idxPrevious).x, interAxeProfil2.y + -seqAxeHydraulique.getCoordinate(idxPrevious).y, 0); + else + vAxeH=new Coordinate(seqAxeHydraulique.getCoordinate(idxNext).x-interAxeProfil2.x, seqAxeHydraulique + .getCoordinate(idxNext).y + -interAxeProfil2.y, 0); + } + else + // Pas de r\xE9orientatin du profil dans ce cas l\xE0. + noReorientation=true; + } + // Cr\xE9ation du vecteur contenant le sens du profil + if (!noReorientation) { + Coordinate vProfilH; + int idxPrevious=UtilsProfil1d.getPreviousIndex(seqProfil, interAxeProfil); + int idxNext=UtilsProfil1d.getNextIndex(seqProfil, interAxeProfil); + if (idxPrevious!=-1) + vProfilH=new Coordinate(interAxeProfil.x-seqProfil.getCoordinate(idxPrevious).x, interAxeProfil.y + -seqProfil.getCoordinate(idxPrevious).y, 0); + else + vProfilH=new Coordinate(seqProfil.getCoordinate(idxNext).x-interAxeProfil.x, seqProfil.getCoordinate(idxNext).y + -interAxeProfil.y, 0); + // Inversion du sens du profil si besoin + double produitVectorielCoordZ=vAxeH.x*vProfilH.y-vAxeH.y*vProfilH.x; + if (produitVectorielCoordZ>0) { + inverseProfil(k); + profil=(Geometry)profils_.getGeomData().getGeometry(k); + seqProfil=((GISCoordinateSequenceContainerInterface)profil).getCoordinateSequence(); + } + } + } + // Cr\xE9ation des nouveaux points sur les profils \\ + for (int k=0; k<profils_.getNombre(); k++) { + // Ajout des points au profil si n\xE9c\xE9ssaire pour les intersections \\ + // Lignes de contraintes + for (int l=0; l<lignesContraints_.getNombre(); l++) + createPointIfNeededKeepZ(k, l, lignesContraints_); + // Rives + for (int l=0; l<rives_.getNombre(); l++) + createPointIfNeeded(k, (GISPolyligne)rives_.getObject(l)); + // Limites de stockages + for (int l=0; l<limitesStockages_.getNombre(); l++) + createPointIfNeeded(k, (GISPolyligne)limitesStockages_.getObject(l)); + // Lignes directrices + for (int l=0; l<lignesDirectrices_.getNombre(); l++) + createPointIfNeeded(k, (GISPolyligne)lignesDirectrices_.getObject(l)); + } + // Valuation des attributs simple d'intersection (rives et limites) \\ + for (int k=0; k<profils_.getNombre(); k++) { + CoordinateSequence seqProfil=zone.getCoordinateSequence(k); + double abscisseCurvIntersectionAxe; + if (axeHydraulique_.getNombre()>0) + abscisseCurvIntersectionAxe=UtilsProfil1d.abscisseCurviligne(seqProfil, axeHydraulique_.getGeomData() + .getCoordinateSequence(0)); + else + abscisseCurvIntersectionAxe=UtilsProfil1d.abscisseCurviligne(seqProfil, seqProfil.getCoordinate(seqProfil.size()-1))/2; + // Valuation des attributs avec les index des points des intersections \\ + // Rives + zone.setAttributValue(idxAttRiveGauche, k, 0, null); + zone.setAttributValue(idxAttRiveDroite, k, seqProfil.size()-1, null); + for (int l=0; l<rives_.getNombre(); l++) + valuateProfilIntersection(k, (Geometry)rives_.getObject(l), idxAttRiveGauche, idxAttRiveDroite, abscisseCurvIntersectionAxe); + // D\xE9tection des croisements zones de stockages droite et gauche \\ + // Limites de stockages + zone.setAttributValue(idxAttlsGauche, k, 0, null); + zone.setAttributValue(idxAttlsDroite, k, seqProfil.size()-1, null); + for (int l=0; l<limitesStockages_.getNombre(); l++) + valuateProfilIntersection(k, (Geometry)limitesStockages_.getObject(l), idxAttlsGauche, idxAttlsDroite, + abscisseCurvIntersectionAxe); + } + // Valuation des attributs composites d'intersection (lignes directrices) \\ + // Lignes directrices \\ + valuateProfilIntersection(idxAttLignesDirectrices); + + // Valuation des attributs sp\xE9cifique au 1d pour l'axe hydraulique \\ + UtilsBief1d.normalizeAxeHydrauliqueAttributes(axeHydraulique_.getGeomData()); + } + + /** + * Normalise les informations PK. + * @throws CancelException si l'imortation est annul\xE9e. + */ + private void normalizePKData() throws CancelException { + GISZoneCollection zone=profils_.getGeomData(); + int idxAttCommentaireHydraulique=zone.getIndiceOf(GISAttributeConstants.COMMENTAIRE_HYDRO); + // Vrai si les PK existes. + boolean attrIsCorrectlyValued=false; + // Vrai si les PK existe et correspond \xE0 l'axe hydraulique si il existe. + boolean attrMatchWithAxeHydraulique=false; + boolean presenceAxeHydraulique=axeHydraulique_.getNombre()>0; + if (idxAttCommentaireHydraulique!=-1) { + attrIsCorrectlyValued=true; + if(presenceAxeHydraulique) + attrMatchWithAxeHydraulique=true; + int i=-1; + while (attrIsCorrectlyValued&&++i<profils_.getNombre()) { + // V\xE9rification de la pr\xE9sence des donn\xE9es PK \\ + String CommHydrauValue=(String)profils_.getGeomData().getValue(idxAttCommentaireHydraulique, i); + attrIsCorrectlyValued=GISLib.isHydroCommentValued(CommHydrauValue, "PK"); + // V\xE9rification de la coh\xE9rence avec l'axe hydraulique \\ + if (presenceAxeHydraulique) { + double hydraoCommValue=GISLib.getHydroCommentDouble(CommHydrauValue, "PK"); + double absCurvValue=UtilsProfil1d.abscisseCurviligne(axeHydraulique_.getGeomData().getCoordinateSequence(0), profils_ + .getGeomData().getCoordinateSequence(i)); + if (absCurvValue==-1) + throw new IllegalArgumentException(FudaaLib + .getS("Au moins un des profils coupe plusieurs fois ou jamais l'axe hydraulique.")); + attrMatchWithAxeHydraulique=attrIsCorrectlyValued&&attrMatchWithAxeHydraulique + &&Math.abs(hydraoCommValue-absCurvValue)<0.0001; + } + } + } + if (idxAttCommentaireHydraulique==-1) + // Ajout de l'attribut COMMENTAIRE_HYDRO + if (idxAttCommentaireHydraulique==-1) { + GISAttributeInterface[] atts=new GISAttributeInterface[zone.getNbAttributes()+1]; + for (int k=0; k<zone.getNbAttributes(); k++) + atts[k]=zone.getAttribute(k); + atts[atts.length-1]=GISAttributeConstants.COMMENTAIRE_HYDRO; + zone.setAttributes(atts, null); + } + if (!attrIsCorrectlyValued) { + // Valuation de l'attribut, a partir de l'axe hydrau si il existe, 0 + // sinon. + idxAttCommentaireHydraulique=zone.getIndiceOf(GISAttributeConstants.COMMENTAIRE_HYDRO); + for (int k=0; k<zone.getNumGeometries(); k++) { + String comm=(String)profils_.getGeomData().getValue(idxAttCommentaireHydraulique, k); + if (!GISLib.isHydroCommentValued(comm, "PK")) + if (presenceAxeHydraulique) { + // Valuation avec le croisement avec l'axe hydraulique + double abscurv=UtilsProfil1d.abscisseCurviligne(axeHydraulique_.getGeomData().getCoordinateSequence(0), profils_ + .getGeomData().getCoordinateSequence(k)); + zone.setAttributValue(idxAttCommentaireHydraulique, k, GISLib.setHydroCommentDouble(comm, abscurv, "PK"), null); + } + else + // Valuation avec 0 + zone.setAttributValue(idxAttCommentaireHydraulique, k, GISLib.setHydroCommentDouble(comm, 0, "PK"), null); + } + attrMatchWithAxeHydraulique=true; + } + if (!attrMatchWithAxeHydraulique&&presenceAxeHydraulique) { + VueImportation vImport=new VueImportation(); + if (!vImport.run()) + throw new CancelException(FudaaLib.getS("L'importation a \xE9t\xE9 annul\xE9.")); + if (vImport.axeHydrauChosen()) { + // Ecrasement des anciennes valeurs de PK \\ + idxAttCommentaireHydraulique=zone.getIndiceOf(GISAttributeConstants.COMMENTAIRE_HYDRO); + for (int k=0; k<zone.getNumGeometries(); k++) { + String comm=(String)profils_.getGeomData().getValue(idxAttCommentaireHydraulique, k); + // Valuation avec le croisement avec l'axe hydraulique + double abscurv=UtilsProfil1d.abscisseCurviligne(axeHydraulique_.getGeomData().getCoordinateSequence(0), profils_ + .getGeomData().getCoordinateSequence(k)); + zone.setAttributValue(idxAttCommentaireHydraulique, k, GISLib.setHydroCommentDouble(comm, abscurv, "PK"), null); + } + } + else { + // Destruction de l'axe hydraulique \\ + int[] idxAH=new int[axeHydraulique_.getNombre()]; + for (int i=0; i<idxAH.length; i++) + idxAH[i]=i; + axeHydraulique_.getGeomData().removeGeometries(idxAH, null); + } + } + } + + /** + * Value les attributs priv\xE9s a partir du tableau de ZModeleLigneBrisee. + * + * @param _models + */ + private void testAndValuateModels() { + for (int i=0; i<models_.length; i++) { + if (models_[i]==null) + throw new IllegalArgumentException(FudaaLib.getS("Erreur programmation : _models ne doit pas contenir de valeurs null")); + if (models_[i].getGeomData()==null) + throw new IllegalArgumentException(FudaaLib.getS("Erreur programmation : Certain model n'ont pas de GSIZoneCollection.")); + if (!(models_[i].getGeomData() instanceof GISZoneCollectionLigneBrisee)) + throw new IllegalArgumentException(FudaaLib + .getS("Erreur programmation : Toutes les GISZone doivent \xEAtre des GISZoneCollectionLigneBrisee.")); + String nature=(String)models_[i].getGeomData().getFixedAttributValue(GISAttributeConstants.NATURE); + if (nature==null) + throw new IllegalArgumentException(FudaaLib.getS("Un des modeles ne contient pas l'attribut NATURE.")); + if (nature==GISAttributeConstants.ATT_NATURE_AH) + if (axeHydraulique_!=null) + throw new IllegalArgumentException(FudaaLib.getS("Plusieurs models d'axe hydrauliques sont donn\xE9es.")); + else + axeHydraulique_=models_[i]; + else if (nature==GISAttributeConstants.ATT_NATURE_LD) + if (lignesDirectrices_!=null) + throw new IllegalArgumentException(FudaaLib.getS("Plusieurs models de lignes directrices sont donn\xE9es.")); + else + lignesDirectrices_=models_[i]; + else if (nature==GISAttributeConstants.ATT_NATURE_LS) + if (limitesStockages_!=null) + throw new IllegalArgumentException(FudaaLib.getS("Plusieurs models de limites de stockage sont donn\xE9es.")); + else if (models_[i].getGeomData().getNbGeometries()>2) + throw new IllegalArgumentException(FudaaLib.getS("Il ne peut pas y avoir plus de 2 limites de stockages.")); + else + limitesStockages_=models_[i]; + else if (nature==GISAttributeConstants.ATT_NATURE_PF) + if (profils_!=null) + throw new IllegalArgumentException(FudaaLib.getS("Plusieurs models de profils sont donn\xE9es.")); + else + profils_=models_[i]; + else if (nature==GISAttributeConstants.ATT_NATURE_RV) + if (rives_!=null) + throw new IllegalArgumentException(FudaaLib.getS("Plusieurs models de rives sont donn\xE9es.")); + else if (models_[i].getGeomData().getNbGeometries()>2) + throw new IllegalArgumentException(FudaaLib.getS("Il ne peut pas y avoir plus de 2 rives.")); + else + rives_=models_[i]; + else if (nature==GISAttributeConstants.ATT_NATURE_LC) + if (lignesContraints_!=null) + throw new IllegalArgumentException(FudaaLib.getS("Plusieurs models de lignes de contraintes sont donn\xE9es.")); + else + lignesContraints_=models_[i]; + } + // Remplissage des models vides par des ZModeles vides + if (axeHydraulique_==null) + axeHydraulique_=new MdlModel1dAxe(null); + if (profils_==null) + profils_=new MdlModel2dProfile(null, null); + if (rives_==null) + rives_=new MdlModel1dBank(null, null); + if (limitesStockages_==null) + limitesStockages_=new MdlModel1dLimiteStockage(null, null); + if (lignesDirectrices_==null) + lignesDirectrices_=new MdlModel2dDirectionLine(null, null); + if (lignesContraints_==null) + lignesContraints_=new MdlModel2dConstraintLine(null, null); + } + + /** + * Inverse le sens du profil dont l'index est pass\xE9 en param\xE8tre. + */ + private void inverseProfil(int _idxProfil) { + GISZoneCollection zone=profils_.getGeomData(); + Coordinate[] coords=((Geometry)zone.getGeometry(_idxProfil)).getCoordinates(); + for (int l=0; l<coords.length/2; l++) { + // Inversion des coordonn\xE9es + Coordinate tmp=coords[l]; + coords[l]=coords[coords.length-1-l]; + coords[coords.length-1-l]=tmp; + // Inversion des attributs atomiques + for (int i=0; i<zone.getNbAttributes(); i++) + if (zone.getAttribute(i).isAtomicValue()) { + GISAttributeModel model=(GISAttributeModel)zone.getDataModel(i).getObjectValueAt(_idxProfil); + Object valueTmp=model.getObjectValueAt(l); + model.setObject(l, model.getObjectValueAt(coords.length-1-l), null); + model.setObject(l, valueTmp, null); + } + } + zone.setCoordinateSequence(_idxProfil, new GISCoordinateSequenceFactory().create(coords), null); + } + + /** + * Valuation des attributs *gauche et *droite des profils. + * + * @param _idxProfil + * l'index du profil concern\xE9. + * @param _ligne + * la ligne qui est sens\xE9 crois\xE9 le profil. + * @param _idxAttrGauche + * l'index de l'attribut gauche o\xF9 sera mit l'information en cas de + * croisement \xE0 gauche. + * @param _idxAttrDroite + * l'index de l'attribut gauche o\xF9 sera mit l'information en cas de + * croisement \xE0 droite. + * @param _absCurvAxeHydrau + * la valeur de l'abscisse curviligne de l'axe hydrau sur le profil. + */ + private void valuateProfilIntersection(int _idxProfil, Geometry _ligne, int _idxAttrGauche, int _idxAttrDroite, + double _absCurvAxeHydrau) { + Geometry inter=_ligne.intersection((Geometry)profils_.getObject(_idxProfil)); + if (inter.getNumPoints()==1) { + Coordinate coord=inter.getCoordinate(); + int idxIntersection=UtilsProfil1d.getIndex(profils_.getGeomData().getCoordinateSequence(_idxProfil), coord); + if (_absCurvAxeHydrau<UtilsProfil1d.abscisseCurviligne(profils_.getGeomData().getCoordinateSequence(_idxProfil), coord)) + profils_.getGeomData().setAttributValue(_idxAttrDroite, _idxProfil, idxIntersection, null); + else + profils_.getGeomData().setAttributValue(_idxAttrGauche, _idxProfil, idxIntersection, null); + } + } + + /** + * Valuation des attributs composites des profils, c'est \xE0 dire des attributs + * contenant plusieurs informations d'intersection sous forme d'une liste. + * + * @param _idxAttr + * l'index de l'attribut o\xF9 sera stock\xE9 les intersections + */ + private void valuateProfilIntersection(int _idxAttr) { + // Cr\xE9ation des listes + for (int k=0; k<profils_.getNombre(); k++) { + GISAttributeModelIntegerList attrModel=new GISAttributeModelIntegerList(0, + GISAttributeConstants.INTERSECTIONS_LIGNES_DIRECTRICES); + attrModel.setListener(profils_.getGeomData()); + profils_.getGeomData().setAttributValue(_idxAttr, k, attrModel, null); + } + // Valuation de l'attribut + int k=0; + int[] lstIntersectionTmp=new int[profils_.getNombre()]; + while (k<lignesDirectrices_.getNombre()) { + Geometry ligneD=(Geometry)lignesDirectrices_.getObject(k); + // Recherche des croisements avec les profils + for (int l=0; l<profils_.getNombre(); l++) { + Geometry profil=profils_.getGeomData().getGeometry(l); + CoordinateSequence seqProfil=((GISCoordinateSequenceContainerInterface)profil).getCoordinateSequence(); + Geometry inter=((Geometry)profils_.getObject(l)).intersection(ligneD); + if (inter.getNumPoints()==0) + lstIntersectionTmp[l]=-1; + else + lstIntersectionTmp[l]=UtilsProfil1d.getIndex(seqProfil, inter.getCoordinate()); + } + // Test si au moins un croisement existe + boolean ok=false; + int m=-1; + while (!ok&&++m<lstIntersectionTmp.length) + ok=lstIntersectionTmp[m]!=-1; + if (!ok) + // Suppression de la ligne directrice qui est inutile et pas + // incr\xE9mentation de k + lignesDirectrices_.getGeomData().removeGeometries(new int[]{k}, null); + else { + for (int l=0; l<profils_.getNombre(); l++) { + // R\xE9cup\xE9ration de la liste contenant les index + GISAttributeModelIntegerList lst=(GISAttributeModelIntegerList)profils_.getGeomData().getValue(_idxAttr, l); + if (lstIntersectionTmp[l]!=-1) + // Enregistrement de l'index + lst.add(lstIntersectionTmp[l]); + else { + // Place le permier ou le dernier index \\ + // Recherche d'un point avant + int idxTest=l; + while (idxTest>=0&&lstIntersectionTmp[idxTest]==-1) + idxTest--; + if (idxTest<0) { + // Recherche d'un point apr\xE8s + idxTest=l; + while (idxTest<lstIntersectionTmp.length&&lstIntersectionTmp[idxTest]==-1) + idxTest++; + } + // Extraction d'informations sur le profils et l'axe hydraulique + Geometry profil=profils_.getGeomData().getGeometry(idxTest); + CoordinateSequence seqProfil=((GISCoordinateSequenceContainerInterface)profil).getCoordinateSequence(); + int idxAxe; + if (axeHydraulique_.getNombre()==0) + idxAxe=seqProfil.size()/2; + else { + Coordinate intersection=profil.intersection((Geometry)axeHydraulique_.getObject(0)).getCoordinate(); + idxAxe=UtilsProfil1d.getPreviousIndex(seqProfil, intersection); + if (idxAxe==-1) + idxAxe=0; + } + // Enregistrement de l'index + if (lstIntersectionTmp[idxTest]<=idxAxe) + lst.add(0); + else + lst.add(profils_.getGeomData().getCoordinateSequence(l).size()-1); + } + } + k++; + } + } + } + + /** + * Cr\xE9e un point \xE0 l'intersection du profil indiqu\xE9 par _idxProfil et de + * _ligne. + */ + private void createPointIfNeeded(int _idxProfil, GISPolyligne _ligne) { + Geometry inter=_ligne.intersection((Geometry)profils_.getObject(_idxProfil)); + CoordinateSequence seq=profils_.getGeomData().getCoordinateSequence(_idxProfil); + if (inter.getNumPoints()==1) { + Coordinate coord=inter.getCoordinate(); + int previousIdx=UtilsProfil1d.getPreviousIndex(seq, coord); + int nextIdx=UtilsProfil1d.getNextIndex(seq, coord); + // Le point n'appartient pas au profil ou La coordonn\xE9e correspond d\xE9j\xE0 \xE0 + // un point + if (previousIdx!=-2&&nextIdx!=-2&&previousIdx+1!=nextIdx-1&&nextIdx!=-1&&previousIdx!=-1) + // La coordonn\xE9e correspond \xE0 aucun point connu + ((GISZoneCollectionGeometry)profils_.getGeomData()).addAtomic(_idxProfil, previousIdx, coord.x, coord.y, null); + } + } + + /** + * Cr\xE9e un point \xE0 l'intersection du profil indiqu\xE9 par _idxProfil et de + * _ligne. Le z du point cr\xE9e prendra la valeur z du point correspondant dans + * _ligne (interpol\xE9 si n\xE9c\xE9ssaire). + */ + private void createPointIfNeededKeepZ(int _idxProfil, int _idxLigne, ZModeleLigneBrisee _modelLigne) { + GISZoneCollection zoneLigne=_modelLigne.getGeomData(); + GISZoneCollection zoneProfil=profils_.getGeomData(); + GISPolyligne ligne=(GISPolyligne)zoneLigne.getGeometry(_idxLigne); + GISPolyligne profil=(GISPolyligne)zoneProfil.getGeometry(_idxProfil); + CoordinateSequence seqLigne=zoneLigne.getCoordinateSequence(_idxLigne); + CoordinateSequence seqProfil=zoneProfil.getCoordinateSequence(_idxProfil); + Geometry intersection=ligne.intersection(profil); + if (intersection.getNumPoints()==1) { + Coordinate coordIntersection=intersection.getCoordinate(); + int previousIdx=UtilsProfil1d.getPreviousIndex(seqProfil, coordIntersection); + int nextIdx=UtilsProfil1d.getNextIndex(seqProfil, coordIntersection); + // Le point n'appartient pas au profil ou La coordonn\xE9e correspond d\xE9j\xE0 \xE0 + // un point + if (previousIdx!=-2&&nextIdx!=-2&&previousIdx+1!=nextIdx-1&&nextIdx!=-1&&previousIdx!=-1) { + // La coordonn\xE9e correspond \xE0 aucun point connu + ((GISZoneCollectionGeometry)zoneProfil).addAtomic(_idxProfil, previousIdx, coordIntersection.x, coordIntersection.y, null); + seqProfil=zoneProfil.getCoordinateSequence(_idxProfil); + } + // Valuation du z par la valeur de la ligne si _zLigne \xE0 vrai + if (zoneLigne.getAttributeIsZ()!=null) { + int idxPProfil=UtilsProfil1d.getIndex(seqProfil, coordIntersection); + int idxPLigne=UtilsProfil1d.getIndex(seqLigne, coordIntersection); + GISAttributeModel modelZLigne=zoneLigne.getModel(zoneLigne.getAttributeIsZ()); + double z; + // Si l'attribut est global + if (!zoneLigne.getAttributeIsZ().isAtomicValue()) + z=(Double)modelZLigne.getObjectValueAt(_idxLigne); + // Le point existe dans la ligne + else if (idxPLigne!=-1) + z=(Double)((GISAttributeModel)modelZLigne.getObjectValueAt(_idxLigne)).getObjectValueAt(idxPLigne); + // Le point n'existe pas => interpole une valeur + else { + // Extraction des index pr\xE9c\xE9dent et suivant \\ + int idxPrevious=UtilsProfil1d.getPreviousIndex(seqLigne, coordIntersection); + if (idxPrevious==-1) + idxPrevious=0; + Coordinate previous=seqLigne.getCoordinate(idxPrevious); + int idxNext=UtilsProfil1d.getNextIndex(seqLigne, coordIntersection); + if (idxNext==-1) + idxNext=seqLigne.size()-1; + Coordinate next=seqLigne.getCoordinate(UtilsProfil1d.getNextIndex(seqLigne, coordIntersection)); + // Cr\xE9ation d'un model temporaire contenant les z \\ + double valZ1=(Double)((GISAttributeModel)modelZLigne.getObjectValueAt(_idxLigne)).getObjectValueAt(idxPrevious); + double valZ2=(Double)((GISAttributeModel)modelZLigne.getObjectValueAt(_idxLigne)).getObjectValueAt(idxNext); + GISAttributeModelDoubleInterface zModel=new GISAttributeModelDoubleArray(new double[]{valZ1, valZ2}, zoneLigne + .getAttributeIsZ()); + // Interpolation \\ + GISCoordinateSequenceFactory factory=new GISCoordinateSequenceFactory(); + z=new GISReprojectInterpolateur1DDouble(factory.create(new Coordinate[]{previous, next}), factory + .create(new Coordinate[]{previous, new Coordinate(coordIntersection.x, coordIntersection.y, 0), next}), zModel) + .interpol(1); + } + ((GISAttributeModel)zoneProfil.getModel(zoneProfil.getAttributeIsZ()).getObjectValueAt(_idxProfil)).setObject(idxPProfil, + z, null); + } + } + } +} Property changes on: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/controller/BiefImporterFromModels.java ___________________________________________________________________ Added: svn:keywords + Id Added: svn:eol-style + native Added: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/controller/BiefsImporterFromModeleur2d.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/controller/BiefsImporterFromModeleur2d.java (rev 0) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/controller/BiefsImporterFromModeleur2d.java 2009-02-12 17:10:04 UTC (rev 4459) @@ -0,0 +1,117 @@ +/* + * @creation 11 f\xE9vr. 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.modeleur1d.controller; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.fudaa.ebli.calque.BCalque; +import org.fudaa.ebli.calque.ZModeleLigneBrisee; +import org.fudaa.fudaa.commun.FudaaLib; +import org.fudaa.fudaa.modeleur.modeleur1d.model.Bief; +import org.fudaa.fudaa.sig.layer.FSigLayerLineEditable; + +/** + * Cette classe s'occupe de g\xE9rer l'importation de donn\xE9es depuis le modeleur 2d + * vers le modeleur 1d. Cette importation peut-\xEAtre faite bief par bief. Une + * hypoth\xE8se est prise dans cette classe : le calque pass\xE9 en param\xE8tre, de m\xEAme + * pour tous ses fils, ne sont pas modifi\xE9s \xE0 l'ext\xE9rieur de cette classe + * pendant toute la dur\xE9e de sa vie. + * + * @author Emmanuel MARTIN + * @version $Id:$ + */ +public class BiefsImporterFromModeleur2d { + + /** La racine de l'arbre du 2d contenant les biefs 2d. */ + private BCalque rootCalque_; + /** La liste de nom. */ + private Map<String, Integer> names_=new HashMap<String, Integer>(); + + /** + * + * @param _rootCalque + * @param _impl peut \xEAtre null. + */ + public BiefsImporterFromModeleur2d(BCalque _rootCalque) { + if (_rootCalque==null) + throw new IllegalArgumentException(FudaaLib.getS("_rootCalque ne doit pas \xEAtre null.")); + rootCalque_=_rootCalque; + // G\xE9n\xE9ration des noms \\ + /* + * Les noms g\xE9n\xE9r\xE9s ne sont pas n\xE9c\xE9ssairement les noms donn\xE9es dans le 2d. + * La diff\xE9rence apparait quand plusieurs biefs porte le m\xEAme nom. Dans ce + * cas le nom prend la forme : nuero#nom. + */ + BCalque[] calques=rootCalque_.getCalques(); + // Extraction pour chacun des calques de son titre \\ + for (int i=0; i<calques.length; i++) + if(names_.containsKey(calques[i].getTitle())) { + // Ajout d'un num\xE9ro \xE0 la fin du nom du calque \\ + int j=2; + while(names_.containsKey(calques[i].getTitle()+" #"+j+"#")) + j++; + names_.put(calques[i].getTitle()+" #"+j+"#", i); + } + else + // Ajout simple du nom \\ + names_.put(calques[i].getTitle(), i); + } + + /** + * Les noms retourn\xE9s ne sont pas n\xE9c\xE9ssairement les noms donn\xE9es dans le 2d. + * La diff\xE9rence apparait quand plusieurs biefs porte le m\xEAme nom. Dans ce cas + * le nom prend la forme : nuero#nom. + * + * @return un tableau de String contenant les noms des biefs importables. + */ + public String[] getBiefsNames() { + return names_.keySet().toArray(new String[0]); + } + + /** + * Import le bief d\xE9fini par _name. + * + * @param _name + * le nom du bief \xE0 importer + * @return le bief construit. + * @throws CancelException + * @throws IllegalArgumentException + * si _name ne correspond \xE0 aucun bief. + */ + public Bief importBief(String _name) throws CancelException { + if (!names_.containsKey(_name)) + throw new IllegalArgumentException(FudaaLib.getS(_name+" ne correspond a aucun bief.")); + // Extraction des modeles du bief selectionn\xE9. \\ + List<ZModeleLigneBrisee> modelsBief=new ArrayList<ZModeleLigneBrisee>(); + // Iteration sur chaque calque + BCalque[] sousCalques=rootCalque_.getCalques()[names_.get(_name)].getCalques(); + for (int j=0; j<sousCalques.length; j++) + if (sousCalques[j] instanceof FSigLayerLineEditable) + modelsBief.add(((FSigLayerLineEditable)sousCalques[j]).getModele()); + // Importation du bief \\ + return new BiefImporterFromModels(modelsBief.toArray(new ZModeleLigneBrisee[0])).getBief(); + } + + /** + * Importe tous les biefs disponibles. + * @return Map<String:NomDuBief, Bief:leBief> + */ + public Map<String, Bief> importAllBiefs() { + String[] names=getBiefsNames(); + Map<String, Bief> result=new HashMap<String, Bief>(); + for(String name: names) + try { + result.put(name, importBief(name)); + } + catch (CancelException _exc) { } + return result; + } +} Property changes on: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/controller/BiefsImporterFromModeleur2d.java ___________________________________________________________________ Added: svn:keywords + Id Added: svn:eol-style + native Added: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/controller/CancelException.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/controller/CancelException.java (rev 0) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/controller/CancelException.java 2009-02-12 17:10:04 UTC (rev 4459) @@ -0,0 +1,19 @@ +/* + * @creation 12 f\xE9vr. 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.modeleur1d.controller; + +/** + * Exception lev\xE9e quand quelque chose est annul\xE9 par l'utilisateur. + * @author Emmanuel MARTIN + * @version $Id:$ + */ +public class CancelException extends Exception { + public CancelException(String _message) { + super(_message); + } +} Property changes on: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/controller/CancelException.java ___________________________________________________________________ Added: svn:keywords + Id Added: svn:eol-style + native Modified: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/controller/ControllerBief.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/controller/ControllerBief.java 2009-02-11 13:54:26 UTC (rev 4458) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/controller/ControllerBief.java 2009-02-12 17:10:04 UTC (rev 4459) @@ -7,10 +7,9 @@ */ package org.fudaa.fudaa.modeleur.modeleur1d.controller; -import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; -import java.util.List; +import java.util.Map; import javax.swing.DefaultListSelectionModel; import javax.swing.event.ListSelectionListener; @@ -25,18 +24,17 @@ import org.fudaa.ctulu.gis.GISPolyligne; import org.fudaa.ctulu.gis.GISZoneCollection; import org.fudaa.ebli.calque.BCalque; -import org.fudaa.ebli.calque.ZModeleLigneBrisee; import org.fudaa.ebli.calque.edition.ZModeleLigneBriseeEditable; import org.fudaa.fudaa.commun.FudaaLib; import org.fudaa.fudaa.modeleur.modeleur1d.model.Bief; import org.fudaa.fudaa.modeleur.modeleur1d.model.BiefContainer; import org.fudaa.fudaa.modeleur.modeleur1d.model.BiefContainerAdapter; import org.fudaa.fudaa.modeleur.modeleur1d.model.BiefSet; +import org.fudaa.fudaa.modeleur.modeleur1d.model.UtilsBief1d; import org.fudaa.fudaa.modeleur.modeleur1d.model.UtilsProfil1d; import org.fudaa.fudaa.modeleur.modeleur1d.view.VueBief; import org.fudaa.fudaa.modeleur.modeleur1d.view.VueFusionBief; import org.fudaa.fudaa.modeleur.modeleur1d.view.VueModuleGestionBief; -import org.fudaa.fudaa.sig.layer.FSigLayerLineEditable; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.CoordinateSequence; @@ -97,7 +95,7 @@ * l'indice pass\xE9 en param\xE8tre (-1 si inutilis\xE9). */ public int orderProfils(int _idx, CtuluCommandContainer _cmd) { - return biefSet_.getBief(biefSelectionModel_.getSelectedName()).orderProfils(_idx, _cmd); + return UtilsBief1d.orderProfils(biefSet_.getBief(biefSelectionModel_.getSelectedName()).profils_, _idx, _cmd); } /** @@ -108,36 +106,16 @@ return; int selectedValue=biefSelectionModel_.getMinSelectionIndex(); // Suppression des biefs pr\xE9c\xE9dents - String[] names=biefSet_.getBiefNames(); - for(int i=0;i<names.length;i++) - biefSet_.removeBief(names[i], null); - BCalque[] calques=_rootCalque.getCalques(); - // It\xE9ration du chaque bief - StringBuilder errors=new StringBuilder(); - for (int i=0; i<calques.length; i++) { - BCalque calqueBief=calques[i]; - List<ZModeleLigneBrisee> modelsDuFutureBief=new ArrayList<ZModeleLigneBrisee>(); - // Iteration sur chaque calque - BCalque[] sousCalques=calqueBief.getCalques(); - for (int j=0; j<sousCalques.length; j++) - if (sousCalques[j] instanceof FSigLayerLineEditable) - modelsDuFutureBief.add(((FSigLayerLineEditable)sousCalques[j]).getModele()); - // Ajout du bief - try { - biefSet_.addBief(calqueBief.getTitle(), modelsDuFutureBief.toArray(new ZModeleLigneBrisee[0]), null); - } - catch (IllegalArgumentException _exp) { - errors.append(FudaaLib.getS("Bief \"")+calqueBief.getTitle()+"\" : "+_exp.getMessage()+"\n"); - } - } + biefSet_.removeAllBiefs(null); + // Importation + Map<String, Bief> biefs=new BiefsImporterFromModeleur2d(_rootCalque).importAllBiefs(); + for(Map.Entry<String, Bief> entry:biefs.entrySet()) + biefSet_.addBief(entry.getKey(), entry.getValue(), null); // Ajout d'une selection if(biefSet_.getNbBief()>selectedValue&&selectedValue!=-1) biefSelectionModel_.addSelectionInterval(selectedValue, selectedValue); else if(biefSet_.getNbBief()>0&&selectedValue==-1) biefSelectionModel_.addSelectionInterval(0, 0); - // Traitement des erreurs - if(errors.length()>0) - throw new IllegalArgumentException(errors.toString()); } /** @@ -225,211 +203,226 @@ * Fusion de deux biefs. */ public void fusionnerBiefs(int _idxBief1, int _idxBief2){ - // D\xE9termine quel bief est le premier et lequel est le second (curvilignement parlant) - double bief1BaseCurv=0; - double bief2BaseCurv=0; - { // Bloque r\xE9duisant artificiellement la port\xE9 des variables + try { + // D\xE9termine quel bief est le premier et lequel est le second + // (curvilignement parlant) + double bief1BaseCurv=0; + double bief2BaseCurv=0; + { // Bloque r\xE9duisant artificiellement la port\xE9 des variables + String name1=biefSet_.getBiefName(_idxBief1); + String name2=biefSet_.getBiefName(_idxBief2); + Bief bief1=biefSet_.getBief(name1); + Bief bief2=biefSet_.getBief(name2); + + // Verifications + if (bief1==null||bief2==null) + throw new IllegalArgumentException(FudaaLib.getS("Au moins un des index ne correspond pas \xE0 un bief.")); + if (bief1.lignesDirectrices_.getNombre()!=bief2.lignesDirectrices_.getNombre()) + throw new IllegalArgumentException(FudaaLib + .getS("Il doit y avoir le m\xEAme nombre de lignes directrices dans les deux biefs.")); + if (bief1.axeHydraulique_.getNombre()!=bief2.axeHydraulique_.getNombre()) + throw new IllegalArgumentException(FudaaLib.getS("Les deux biefs doivent avoir la m\xEAme pr\xE9sence d'axe hydraulique.")); + + GISZoneCollection zoneAxeHydrau1=bief1.axeHydraulique_.getGeomData(); + if (zoneAxeHydrau1.getNumGeometries()>0) + bief1BaseCurv=(Double)zoneAxeHydrau1.getValue(zoneAxeHydrau1.getIndiceOf(GISAttributeConstants.CURVILIGNE_DECALAGE), 0); + GISZoneCollection zoneAxeHydrau2=bief2.axeHydraulique_.getGeomData(); + if (zoneAxeHydrau2.getNumGeometries()>0) + bief2BaseCurv=(Double)zoneAxeHydrau2.getValue(zoneAxeHydrau2.getIndiceOf(GISAttributeConstants.CURVILIGNE_DECALAGE), 0); + + // Inversion des biefs si n\xE9c\xE9ssaire + if (bief1BaseCurv>bief2BaseCurv) { + int idxTmp=_idxBief1; + _idxBief1=_idxBief2; + _idxBief2=idxTmp; + double valTmp=bief1BaseCurv; + bief1BaseCurv=bief2BaseCurv; + bief2BaseCurv=valTmp; + } + } + { // Bloque r\xE9duisant artificiellement la port\xE9 des variables + String name1=biefSet_.getBiefName(_idxBief1); + String name2=biefSet_.getBiefName(_idxBief2); + double bief1MaxCurvBrut; + double bief2MaxCurvBrut; + if (biefSet_.getBief(name1).axeHydraulique_.getGeomData().getNumGeometries()>0) { + CoordinateSequence seqAxe1=biefSet_.getBief(name1).axeHydraulique_.getGeomData().getCoordinateSequence(0); + bief1MaxCurvBrut=UtilsProfil1d.abscisseCurviligne(seqAxe1, seqAxe1.getCoordinate(seqAxe1.size()-1)); + CoordinateSequence seqAxe2=biefSet_.getBief(name2).axeHydraulique_.getGeomData().getCoordinateSequence(0); + bief2MaxCurvBrut=UtilsProfil1d.abscisseCurviligne(seqAxe2, seqAxe2.getCoordinate(seqAxe2.size()-1)); + } + else { + GISZoneCollection zone1=biefSet_.getBief(name1).profils_.getGeomData(); + bief1MaxCurvBrut=Double.parseDouble(((String)zone1.getValue(zone1.getIndiceOf(GISAttributeConstants.COMMENTAIRE_HYDRO), + zone1.getNumGeometries()-1)).substring(3)); + GISZoneCollection zone2=biefSet_.getBief(name2).profils_.getGeomData(); + bief2MaxCurvBrut=Double.parseDouble(((String)zone2.getValue(zone2.getIndiceOf(GISAttributeConstants.COMMENTAIRE_HYDRO), + zone2.getNumGeometries()-1)).substring(3)); + } + + if (bief1BaseCurv+bief1MaxCurvBrut>bief2BaseCurv) { + VueFusionBief vueFusionBief=new VueFusionBief(controller1d_.getFormater(), name1, bief1BaseCurv, bief1MaxCurvBrut, name2, + bief2BaseCurv, bief2MaxCurvBrut); + if (!vueFusionBief.run()) + return; + bief1BaseCurv=vueFusionBief.getAbsCurvAxe1(); + bief2BaseCurv=vueFusionBief.getAbsCurvAxe2(); + } + + // Inversion des biefs si n\xE9c\xE9ssaire + if (bief1BaseCurv>bief2BaseCurv) { + int idxTmp=_idxBief1; + _idxBief1=_idxBief2; + _idxBief2=idxTmp; + double valTmp=bief1BaseCurv; + bief1BaseCurv=bief2BaseCurv; + bief2BaseCurv=valTmp; + } + } + String name1=biefSet_.getBiefName(_idxBief1); String name2=biefSet_.getBiefName(_idxBief2); Bief bief1=biefSet_.getBief(name1); Bief bief2=biefSet_.getBief(name2); - - // Verifications - if(bief1==null||bief2==null) - throw new IllegalArgumentException(FudaaLib.getS("Au moins un des index ne correspond pas \xE0 un bief.")); - if(bief1.lignesDirectrices_.getNombre()!=bief2.lignesDirectrices_.getNombre()) - throw new IllegalArgumentException(FudaaLib.getS("Il doit y avoir le m\xEAme nombre de lignes directrices dans les deux biefs.")); - if(bief1.axeHydraulique_.getNombre()!=bief2.axeHydraulique_.getNombre()) - throw new IllegalArgumentException(FudaaLib.getS("Les deux biefs doivent avoir la m\xEAme pr\xE9sence d'axe hydraulique.")); - + // Extraction/Cr\xE9ation des axes hydrauliques GISZoneCollection zoneAxeHydrau1=bief1.axeHydraulique_.getGeomData(); - if(zoneAxeHydrau1.getNumGeometries()>0) - bief1BaseCurv=(Double)zoneAxeHydrau1.getValue(zoneAxeHydrau1.getIndiceOf(GISAttributeConstants.CURVILIGNE_DECALAGE), 0); GISZoneCollection zoneAxeHydrau2=bief2.axeHydraulique_.getGeomData(); - if(zoneAxeHydrau2.getNumGeometries()>0) - bief2BaseCurv=(Double)zoneAxeHydrau2.getValue(zoneAxeHydrau2.getIndiceOf(GISAttributeConstants.CURVILIGNE_DECALAGE), 0); - - // Inversion des biefs si n\xE9c\xE9ssaire - if (bief1BaseCurv>bief2BaseCurv) { - int idxTmp=_idxBief1; - _idxBief1=_idxBief2; - _idxBief2=idxTmp; - double valTmp=bief1BaseCurv; - bief1BaseCurv=bief2BaseCurv; - bief2BaseCurv=valTmp; + CoordinateSequence seqAxeHydraulique1; + CoordinateSequence seqAxeHydraulique2; + boolean fakeAH=false; + if (zoneAxeHydrau1.getNbGeometries()==0) { + fakeAH=true; + // Construction d'un faux axe hydraulique + if (bief1.profils_.getNombre()>=2) { + CoordinateSequence prof1=bief1.profils_.getGeomData().getCoordinateSequence(0); + CoordinateSequence prof2=bief1.profils_.getGeomData().getCoordinateSequence(bief1.profils_.getNombre()-1); + seqAxeHydraulique1=new GISCoordinateSequenceFactory().create(new Coordinate[]{prof1.getCoordinate(prof1.size()/2), + prof2.getCoordinate(prof2.size()/2)}); + } + else if (bief1.profils_.getNombre()==1) { + CoordinateSequence prof1=bief1.profils_.getGeomData().getCoordinateSequence(0); + Coordinate coord1=prof1.getCoordinate(prof1.size()/2); + Coordinate coord2=new Coordinate(coord1.x-10, coord1.y-1, 0); + seqAxeHydraulique1=new GISCoordinateSequenceFactory().create(new Coordinate[]{coord1, coord2}); + } + else + return; + if (bief2.profils_.getNombre()>=2) { + CoordinateSequence prof1=bief2.profils_.getGeomData().getCoordinateSequence(0); + CoordinateSequence prof2=bief2.profils_.getGeomData().getCoordinateSequence(bief2.profils_.getNombre()-1); + seqAxeHydraulique2=new GISCoordinateSequenceFactory().create(new Coordinate[]{prof1.getCoordinate(prof1.size()/2), + prof2.getCoordinate(prof2.size()/2)}); + } + else if (bief2.profils_.getNombre()==1) { + CoordinateSequence prof1=bief2.profils_.getGeomData().getCoordinateSequence(0); + Coordinate coord1=prof1.getCoordinate(prof1.size()/2); + Coordinate coord2=new Coordinate(coord1.x-10, coord1.y-1, 0); + seqAxeHydraulique2=new GISCoordinateSequenceFactory().create(new Coordinate[]{coord1, coord2}); + } + else + return; } - } - { // Bloque r\xE9duisant artificiellement la port\xE9 des variables - String name1=biefSet_.getBiefName(_idxBief1); - String name2=biefSet_.getBiefName(_idxBief2); - double bief1MaxCurvBrut; - double bief2MaxCurvBrut; - if(biefSet_.getBief(name1).axeHydraulique_.getGeomData().getNumGeometries()>0) { - CoordinateSequence seqAxe1=biefSet_.getBief(name1).axeHydraulique_.getGeomData().getCoordinateSequence(0); - bief1MaxCurvBrut=UtilsProfil1d.abscisseCurviligne(seqAxe1, seqAxe1.getCoordinate(seqAxe1.size()-1)); - CoordinateSequence seqAxe2=biefSet_.getBief(name2).axeHydraulique_.getGeomData().getCoordinateSequence(0); - bief2MaxCurvBrut=UtilsProfil1d.abscisseCurviligne(seqAxe2, seqAxe2.getCoordinate(seqAxe2.size()-1)); - } else { - GISZoneCollection zone1=biefSet_.getBief(name1).profils_.getGeomData(); - bief1MaxCurvBrut=Double.parseDouble(((String) zone1.getValue(zone1.getIndiceOf(GISAttributeConstants.COMMENTAIRE_HYDRO), zone1.getNumGeometries()-1)).substring(3)); - GISZoneCollection zone2=biefSet_.getBief(name2).profils_.getGeomData(); - bief2MaxCurvBrut=Double.parseDouble(((String) zone2.getValue(zone2.getIndiceOf(GISAttributeConstants.COMMENTAIRE_HYDRO), zone2.getNumGeometries()-1)).substring(3)); + seqAxeHydraulique1=zoneAxeHydrau1.getCoordinateSequence(0); + seqAxeHydraulique2=zoneAxeHydrau2.getCoordinateSequence(0); } - - if(bief1BaseCurv+bief1MaxCurvBrut>bief2BaseCurv) { - VueFusionBief vueFusionBief=new VueFusionBief(controller1d_.getFormater(), name1, bief1BaseCurv, bief1MaxCurvBrut, name2, bief2BaseCurv, bief2MaxCurvBrut); - if(!vueFusionBief.run()) - return; - bief1BaseCurv=vueFusionBief.getAbsCurvAxe1(); - bief2BaseCurv=vueFusionBief.getAbsCurvAxe2(); + + Coordinate debutAxe2=UtilsProfil1d.getCoordinateXY(seqAxeHydraulique1, bief2BaseCurv-bief1BaseCurv); + Coordinate move=UtilsProfil1d.vec(seqAxeHydraulique2.getCoordinate(0), debutAxe2); + + // Construction du nouveau bief + Bief newBief=new Bief(); + String biefName=name1+"_"+name2; + int k=1; + while (biefSet_.getBief(biefName)!=null) + biefName=name1+"_"+name2+"#"+Integer.toString(++k); + // Racourcis + GISZoneCollection zoneAxeHydraulique=newBief.axeHydraulique_.getGeomData(); + GISZoneCollection zoneProfils=newBief.profils_.getGeomData(); + GISZoneCollection bief1ZoneProfil=bief1.profils_.getGeomData(); + GISZoneCollection bief2ZoneProfil=bief2.profils_.getGeomData(); + + // Ajout de g\xE9om\xE9tries au nouveau bief \\ + // Ajout des profils des biefs d'origines + int idxAttrComm=zoneProfils.getIndiceOf(GISAttributeConstants.COMMENTAIRE_HYDRO); + for (int i=0; i<bief1.profils_.getNombre(); i++) { + int idxGeom=zoneProfils.addGeometry(bief1ZoneProfil.getGeometry(i), UtilsProfil1d.getData(i, bief1ZoneProfil), null); + if (fakeAH) { + // Dans le cas de l'utilisation de l'attribut CommentaireHydro, on + // r\xE9percute le changement de baseCurv sur les valeurs de l'attribut + String comm=(String)zoneProfils.getValue(idxAttrComm, idxGeom); + double newPK=GISLib.getHydroCommentDouble(comm, "PK")+bief1BaseCurv; + String newValue=GISLib.setHydroCommentDouble(comm, newPK, "PK"); + zoneProfils.setAttributValue(idxAttrComm, idxGeom, newValue, null); + } } - - // Inversion des biefs si n\xE9c\xE9ssaire - if (bief1BaseCurv>bief2BaseCurv) { - int idxTmp=_idxBief1; - _idxBief1=_idxBief2; - _idxBief2=idxTmp; - double valTmp=bief1BaseCurv; - bief1BaseCurv=bief2BaseCurv; - bief2BaseCurv=valTmp; + for (int i=0; i<bief2.profils_.getNombre(); i++) { + int idxGeom=zoneProfils.addGeometry(bief2ZoneProfil.getGeometry(i), UtilsProfil1d.getData(i, bief2ZoneProfil), null); + if (fakeAH) { + // Dans le cas de l'utilisation de l'attribut CommentaireHydro, on + // r\xE9percute le changement de baseCurv sur les valeurs de l'attribut + String comm=(String)zoneProfils.getValue(idxAttrComm, idxGeom); + double newPK=GISLib.getHydroCommentDouble(comm, "PK")+bief2BaseCurv; + String newValue=GISLib.setHydroCommentDouble(comm, newPK, "PK"); + zoneProfils.setAttributValue(idxAttrComm, idxGeom, newValue, null); + } } - } - - String name1=biefSet_.getBiefName(_idxBief1); - String name2=biefSet_.getBiefName(_idxBief2); - Bief bief1=biefSet_.getBief(name1); - Bief bief2=biefSet_.getBief(name2); - // Extraction/Cr\xE9ation des axes hydrauliques - GISZoneCollection zoneAxeHydrau1=bief1.axeHydraulique_.getGeomData(); - GISZoneCollection zoneAxeHydrau2=bief2.axeHydraulique_.getGeomData(); - CoordinateSequence seqAxeHydraulique1; - CoordinateSequence seqAxeHydraulique2; - boolean fakeAH=false; - if(zoneAxeHydrau1.getNbGeometries()==0) { - fakeAH=true; - // Construction d'un faux axe hydraulique - if(bief1.profils_.getNombre()>=2) { - CoordinateSequence prof1=bief1.profils_.getGeomData().getCoordinateSequence(0); - CoordinateSequence prof2=bief1.profils_.getGeomData().getCoordinateSequence(bief1.profils_.getNombre()-1); - seqAxeHydraulique1=new GISCoordinateSequenceFactory().create(new Coordinate[]{prof1.getCoordinate(prof1.size()/2), prof2.getCoordinate(prof2.size()/2)}); + // Ajout de l'axe hydraulique du second bief (utile pour la translation) + if (!fakeAH) + zoneAxeHydraulique.addGeometry(zoneAxeHydrau2.getGeometry(0), UtilsProfil1d.getData(0, zoneAxeHydrau2), null); + + // Translation du second bief \\ + // Cr\xE9ation d'une selection contenant le second axe hydraulique + if (!fakeAH) { + BitSet bs=new BitSet(1); + bs.set(0); + CtuluListSelection selection=new CtuluListSelection(bs); + // Application de la translation sur le second axe hydraulique + ((ZModeleLigneBriseeEditable)newBief.axeHydraulique_).moveGlobal(selection, move.x, move.y, 0, null); } - else if(bief1.profils_.getNombre()==1) { - CoordinateSequence prof1=bief1.profils_.getGeomData().getCoordinateSequence(0); - Coordinate coord1=prof1.getCoordinate(prof1.size()/2); - Coordinate coord2=new Coordinate(coord1.x-10, coord1.y-1, 0); - seqAxeHydraulique1=new GISCoordinateSequenceFactory().create(new Coordinate[]{coord1, coord2}); - } - else - return; - if(bief2.profils_.getNombre()>=2) { - CoordinateSequence prof1=bief2.profils_.getGeomData().getCoordinateSequence(0); - CoordinateSequence prof2=bief2.profils_.getGeomData().getCoordinateSequence(bief2.profils_.getNombre()-1); - seqAxeHydraulique2=new GISCoordinateSequenceFactory().create(new Coordinate[]{prof1.getCoordinate(prof1.size()/2), prof2.getCoordinate(prof2.size()/2)}); - } - else if(bief2.profils_.getNombre()==1) { - CoordinateSequence prof1=bief2.profils_.getGeomData().getCoordinateSequence(0); - Coordinate coord1=prof1.getCoordinate(prof1.size()/2); - Coordinate coord2=new Coordinate(coord1.x-10, coord1.y-1, 0); - seqAxeHydraulique2=new GISCoordinateSequenceFactory().create(new Coordinate[]{coord1, coord2}); - } - else - return; - } - else { - seqAxeHydraulique1=zoneAxeHydrau1.getCoordinateSequence(0); - seqAxeHydraulique2=zoneAxeHydrau2.getCoordinateSequence(0); - } - - Coordinate debutAxe2=UtilsProfil1d.getCoordinateXY(seqAxeHydraulique1, bief2BaseCurv-bief1BaseCurv); - Coordinate move=UtilsProfil1d.vec(seqAxeHydraulique2.getCoordinate(0), debutAxe2); - - // Construction du nouveau bief - Bief newBief=new Bief(); - String biefName=name1+"_"+name2; - int k=1; - while(biefSet_.getBief(biefName)!=null) - biefName=name1+"_"+name2+"#"+Integer.toString(++k); - // Racourcis - GISZoneCollection zoneAxeHydraulique=newBief.axeHydraulique_.getGeomData(); - GISZoneCollection zoneProfils=newBief.profils_.getGeomData(); - GISZoneCollection bief1ZoneProfil=bief1.profils_.getGeomData(); - GISZoneCollection bief2ZoneProfil=bief2.profils_.getGeomData(); - - // Ajout de g\xE9om\xE9tries au nouveau bief \\ - // Ajout des profils des biefs d'origines - int idxAttrComm=zoneProfils.getIndiceOf(GISAttributeConstants.COMMENTAIRE_HYDRO); - for(int i=0;i<bief1.profils_.getNombre();i++) { - int idxGeom=zoneProfils.addGeometry(bief1ZoneProfil.getGeometry(i), UtilsProfil1d.getData(i, bief1ZoneProfil), null); - if (fakeAH) { - // Dans le cas de l'utilisation de l'attribut CommentaireHydro, on - // r\xE9percute le changement de baseCurv sur les valeurs de l'attribut - String comm=(String)zoneProfils.getValue(idxAttrComm, idxGeom); - double newPK=GISLib.getHydroCommentDouble(comm, "PK")+bief1BaseCurv; - String newValue=GISLib.setHydroCommentDouble(comm, newPK, "PK"); - zoneProfils.setAttributValue(idxAttrComm, i, newValue, null); - } - } - for(int i=0;i<bief2.profils_.getNombre();i++) { - int idxGeom=zoneProfils.addGeometry(bief2ZoneProfil.getGeometry(i), UtilsProfil1d.getData(i, bief2ZoneProfil), null); - if (fakeAH) { - // Dans le cas de l'utilisation de l'attribut CommentaireHydro, on - // r\xE9percute le changement de baseCurv sur les valeurs de l'attribut - String comm=(String)zoneProfils.getValue(idxAttrComm, idxGeom); - double newPK=GISLib.getHydroCommentDouble(comm, "PK")+bief1BaseCurv; - String newValue=GISLib.setHydroCommentDouble(comm, newPK, "PK"); - zoneProfils.setAttributValue(idxAttrComm, i, newValue, null); - } - } - // Ajout de l'axe hydraulique du second bief (utile pour la translation) - if(!fakeAH) - zoneAxeHydraulique.addGeometry(zoneAxeHydrau2.getGeometry(0), Utils... [truncated message content] |