From: <bma...@us...> - 2008-08-12 10:56:04
|
Revision: 3777 http://fudaa.svn.sourceforge.net/fudaa/?rev=3777&view=rev Author: bmarchan Date: 2008-08-12 10:56:13 +0000 (Tue, 12 Aug 2008) Log Message: ----------- Un calque pour afficher tout type de g?\195?\169om?\195?\169tries. Added Paths: ----------- branches/Br_FudaaModeleur_TF/fudaa_devel/ebli/src/org/fudaa/ebli/calque/ZCalqueGeometry.java Added: branches/Br_FudaaModeleur_TF/fudaa_devel/ebli/src/org/fudaa/ebli/calque/ZCalqueGeometry.java =================================================================== --- branches/Br_FudaaModeleur_TF/fudaa_devel/ebli/src/org/fudaa/ebli/calque/ZCalqueGeometry.java (rev 0) +++ branches/Br_FudaaModeleur_TF/fudaa_devel/ebli/src/org/fudaa/ebli/calque/ZCalqueGeometry.java 2008-08-12 10:56:13 UTC (rev 3777) @@ -0,0 +1,868 @@ +/* + * @creation 31 mars 2005 + * @modification $Date: 2008-04-01 17:05:16 $ + * @license GNU General Public License 2 + * @copyright (c)1998-2001 CETMEF 2 bd Gambetta F-60231 Compiegne + * @mail de...@fu... + */ +package org.fudaa.ebli.calque; + +import gnu.trove.TIntArrayList; +import gnu.trove.TIntObjectIterator; +import gnu.trove.TObjectIntHashMap; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; + +import org.nfunk.jep.Variable; + +import com.memoire.fu.FuLog; +import com.vividsolutions.jts.algorithm.SIRtreePointInRing; +import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jts.geom.CoordinateSequence; +import com.vividsolutions.jts.geom.Envelope; +import com.vividsolutions.jts.geom.Geometry; +import com.vividsolutions.jts.geom.LineString; +import com.vividsolutions.jts.geom.LinearRing; + +import org.fudaa.ctulu.CtuluExpr; +import org.fudaa.ctulu.CtuluLib; +import org.fudaa.ctulu.CtuluLibArray; +import org.fudaa.ctulu.CtuluListSelection; +import org.fudaa.ctulu.CtuluListSelectionInterface; +import org.fudaa.ctulu.gis.GISAttributeInterface; +import org.fudaa.ctulu.gis.GISCoordinateSequenceContainerInterface; +import org.fudaa.ctulu.gis.GISGeometryFactory; +import org.fudaa.ctulu.gis.GISLib; +import org.fudaa.ctulu.gis.GISZoneCollection; + +import org.fudaa.ebli.calque.find.CalqueFindExpression; +import org.fudaa.ebli.commun.EbliLib; +import org.fudaa.ebli.commun.EbliListeSelectionMulti; +import org.fudaa.ebli.commun.EbliListeSelectionMultiInterface; +import org.fudaa.ebli.commun.EbliSelectionMode; +import org.fudaa.ebli.commun.EbliSelectionState; +import org.fudaa.ebli.commun.EbliUIProperties; +import org.fudaa.ebli.find.EbliFindExpressionContainerInterface; +import org.fudaa.ebli.geometrie.GrBoite; +import org.fudaa.ebli.geometrie.GrMorphisme; +import org.fudaa.ebli.geometrie.GrPoint; +import org.fudaa.ebli.trace.TraceIcon; +import org.fudaa.ebli.trace.TraceIconModel; +import org.fudaa.ebli.trace.TraceLigne; +import org.fudaa.ebli.trace.TraceLigneModel; + +/** + * Un calque g\xE9rant des g\xE9om\xE9tries quelconques, \xE0 un niveau global ou atomique.<p> + * Le niveau atomique des g\xE9om\xE9tries est le niveau sommet. Le calque s'appuie sur un mod\xE8le + * {@link ZModeleGeometry}. + * + * @author Bertrand Marchand + * @version $Id: ZCalqueMultiPoint.java,v 1.1.2.2 2008-04-01 17:05:16 bmarchan Exp $ + */ +public class ZCalqueGeometry extends ZCalqueAffichageDonneesLineAbstract { + + /** + * @author Fred Deniger + * @version $Id: ZCalqueMultiPoint.java,v 1.1.2.2 2008-04-01 17:05:16 bmarchan Exp $ + */ + private class VariableNonAtomicFindExpression extends CalqueFindExpression { + + TObjectIntHashMap varAtt_; + + public VariableNonAtomicFindExpression() { + super(ZCalqueGeometry.this.modeleDonnees()); + } + + public void initialiseExpr(final CtuluExpr _expr) { + super.initialiseExpr(_expr); + final GISZoneCollection coll = ((ZModeleGeom) super.data_).getGeomData(); + final int nb = coll.getNbAttributes(); + if (nb > 0) { + if (varAtt_ == null) { + varAtt_ = new TObjectIntHashMap(nb); + } else { + varAtt_.clear(); + } + for (int i = 0; i < nb; i++) { + final GISAttributeInterface att = coll.getAttribute(i); + if (!att.isAtomicValue() && Number.class.isAssignableFrom(att.getDataClass())) { + varAtt_.put(_expr.addVar(att.getName(), att.getLongName()), i); + } + } + } + + } + + public void majVariable(final int _idx, final Variable[] _varToUpdate) { + super.majVariable(_idx, _varToUpdate); + if (varAtt_ != null && !CtuluLibArray.isEmpty(_varToUpdate)) { + final GISZoneCollection coll = ((ZModeleGeom) super.data_).getGeomData(); + for (int i = _varToUpdate.length - 1; i >= 0; i--) { + if (varAtt_.containsKey(_varToUpdate[i])) { + _varToUpdate[i].setValue(CtuluLib.getDouble(((Number) coll.getDataModel(varAtt_.get(_varToUpdate[i])) + .getObjectValueAt(_idx)).doubleValue())); + } + } + } + } + + } + + /** true si edition de sommets */ + transient private boolean isAtomicMode_; + + protected ZModeleGeometry modele_; + + /** La selection a utilise dans le mode selection sommets */ + protected EbliListeSelectionMulti selectionMulti_; + + + /** + * Le seul constructeur, avec le mod\xE8le. + * @param _modele le modele du calque + */ + public ZCalqueGeometry(final ZModeleGeometry _modele) { + modele_ = _modele; + iconModel_ = new TraceIconModel(TraceIcon.CARRE_PLEIN, 2, Color.BLACK); + } + + protected EbliListeSelectionMulti creeSelectionMutli() { + return new EbliListeSelectionMulti(modeleDonnees().getNombre() / 2); + } + + protected void initTrace(final TraceIconModel _icon, final int _idxPoly) { + _icon.updateData(getIconModel(0)); + if (isAttenue()) { + _icon.setCouleur(EbliLib.getAlphaColor(attenueCouleur(_icon.getCouleur()), alpha_)); + } else if (EbliLib.isAlphaChanged(alpha_)) { + _icon.setCouleur(EbliLib.getAlphaColor(_icon.getCouleur(), alpha_)); + } + } + + protected void initTrace(final TraceLigneModel _ligne, final int _idxGeom) { + final int idx = modele_.isGeometryFermee(_idxGeom) ? 0 : 1; + _ligne.updateData(getLineModel(idx)); + if (isAttenue()) { + _ligne.setCouleur(EbliLib.getAlphaColor(attenueCouleur(_ligne.getCouleur()), alpha_)); + } else if (EbliLib.isAlphaChanged(alpha_)) { + _ligne.setCouleur(EbliLib.getAlphaColor(_ligne.getCouleur(), alpha_)); + } + } + + protected void paintSelectionMulti(final Graphics _g, final ZSelectionTrace _trace, final GrMorphisme _versEcran, + final GrBoite _clipReel) { + if ((isRapide()) || (isSelectionEmpty())) { + return; + } + final GrBoite clip = _clipReel; + if (!getDomaine().intersectXY(clip)) { + return; + } + Color cs = _trace.getColor(); + if (isAttenue()) { + cs = attenueCouleur(cs); + } + _g.setColor(cs); + final TraceIcon ic = _trace.getIconeInterne(); + final TIntObjectIterator it = selectionMulti_.getIterator(); + final GrPoint p = new GrPoint(); + final GrMorphisme versEcran = _versEcran; + for (int i = selectionMulti_.getNbListSelected(); i-- > 0;) { + it.advance(); + final CtuluListSelectionInterface s = (CtuluListSelectionInterface) it.value(); + if (!s.isEmpty()) { + final int idxPoly = it.key(); + final int min = s.getMinIndex(); + for (int j = s.getMaxIndex(); j >= min; j--) { + if (s.isSelected(j)) { + modele_.point(p, idxPoly, j); + if (clip.contientXY(p)) { + p.autoApplique(versEcran); + ic.paintIconCentre(this, _g, p.x_, p.y_); + } + } + } + } + } + } + + public boolean changeSelection(final GrPoint _pt, final int _tolerancePixel, final int _action) { + if (isAtomicMode_) { + final EbliListeSelectionMulti l = selectionMulti(_pt, _tolerancePixel); + changeSelectionMulti(l, _action); + if ((l == null) || (l.isEmpty())) { + return false; + } + return true; + } + return super.changeSelection(_pt, _tolerancePixel, _action); + } + + public boolean changeSelection(final LinearRing _poly, final int _action, final int _mode) { + if (isAtomicMode_) { + final EbliListeSelectionMulti l = selectionMulti(_poly); + changeSelectionMulti(l, _action); + if ((l == null) || (l.isEmpty())) { + return false; + } + return true; + } + return super.changeSelection(_poly, _action, _mode); + } + + private void changeSelectionMulti(final EbliListeSelectionMulti _s, final int _action) { + // Si la selection de modif est nulle, seule l'action de remplacement + // est concernee. + if (selectionMulti_ == null) { + selectionMulti_ = creeSelectionMutli(); + } + boolean sentEvent = false; + switch (_action) { + case EbliSelectionState.ACTION_ADD: + sentEvent = selectionMulti_.add(_s); + break; + case EbliSelectionState.ACTION_DEL: + sentEvent = selectionMulti_.remove(_s); + break; + case EbliSelectionState.ACTION_XOR: + sentEvent = selectionMulti_.xor(_s); + break; + case EbliSelectionState.ACTION_REPLACE: + selectionMulti_.setSelection(_s); + sentEvent = true; + break; + default: + break; + } + if (sentEvent) { + fireSelectionEvent(); + } + } + + public void clearSelection() { + // dans le mode edition de noeuds + if (isAtomicMode_) { + if (selectionMulti_ != null && !selectionMulti_.isEmpty()) { + + selectionMulti_.clear(); + fireSelectionEvent(); + } + } else { + super.clearSelection(); + } + } + + public EbliFindExpressionContainerInterface getExpressionContainer() { + if (isAtomicMode_) { + return new CalqueFindExpression(modele_); + } + return new VariableNonAtomicFindExpression(); + } + + public EbliListeSelectionMultiInterface getLayerSelectionMulti() { + return selectionMulti_; + } + + public int getNbSelected() { + if (isSelectionEmpty()) { + return 0; + } + if (isAtomicMode_) { + return selectionMulti_.getNbListSelected(); + } + return super.getNbSelected(); + } + + public int[] getSelectedIndex() { + if (isSelectionEmpty()) { + return null; + } + if (isAtomicMode_) { + return selectionMulti_.getIdxSelected(); + } + return super.getSelectedIndex(); + } + + public int[] getSelectedObjectInTable() { + if (isSelectionEmpty()) { + return null; + } + if (!isAtomicMode_) { + return super.getSelectedObjectInTable(); + } + final EbliListeSelectionMultiInterface multi = getLayerSelectionMulti(); + int nb = 0; + // 20 points par lignes + final TIntArrayList list = new TIntArrayList(modele_.getNombre() * 20); + final int nbLigne = modele_.getNombre(); + for (int i = 0; i < nbLigne; i++) { + final CtuluListSelectionInterface sel = multi.getSelection(i); + if (sel != null) { + final int max = sel.getMaxIndex(); + for (int j = sel.getMinIndex(); j <= max; j++) { + if (sel.isSelected(j)) { + list.add(nb + j); + } + } + + } + nb += modele_.getNbPointForGeometry(i); + } + + return list.toNativeArray(); + } + + public GrBoite getDomaineOnSelected() { + if (isSelectionEmpty()) { + return null; + } + final Envelope env = new Envelope(); + if (isAtomicMode_) { + final EbliListeSelectionMultiInterface multi = getLayerSelectionMulti(); + final TIntObjectIterator it = multi.getIterator(); + for (int i = multi.getNbListSelected(); i-- > 0;) { + it.advance(); + final CtuluListSelectionInterface atomSel = (CtuluListSelectionInterface) it.value(); + final Geometry g = (Geometry) modele_.getGeomData().getGeometry(it.key()); + final int max = atomSel.getMaxIndex(); + for (int j = atomSel.getMinIndex(); j <= max; j++) { + if (atomSel.isSelected(j)) { + env.expandToInclude(g.getCoordinates()[j]); + } + } + } + + } else { + final CtuluListSelectionInterface sel = getLayerSelection(); + final int max = sel.getMaxIndex(); + for (int i = sel.getMinIndex(); i <= max; i++) { + if (sel.isSelected(i)) { + env.expandToInclude(modele_.getGeomData().getGeometry(i).getEnvelopeInternal()); + } + } + } + final GrBoite r = new GrBoite(); + r.ajuste(env.getMaxX(), env.getMaxY(), 0); + r.ajuste(env.getMinX(), env.getMinY(), 0); + return r; + } + + public void initFrom(final EbliUIProperties _p) { + if (_p != null) { + super.initFrom(_p); + if (_p.isDefined("calqueGIS.ligneModel")) { + setLineModel(0, (TraceLigneModel) _p.get("calqueGIS.ligneModel")); + } + } + } + + public void inverseSelection() { + if (!isAtomicMode_) { + super.inverseSelection(); + return; + } + if (isSelectionEmpty()) { + return; + } + for (int i = modele_.getNombre() - 1; i >= 0; i--) { + final CtuluListSelection s = selectionMulti_.get(i); + if (s != null) { + s.inverse(modele_.getNbPointForGeometry(i)); + } + } + fireSelectionEvent(); + } + + /** + * @return true si on est dans le mode edition de noeuds + */ + public boolean isAtomicMode() { + return isAtomicMode_; + } + + public boolean isPaletteModifiable() { + return false; + } + + /** + * Indique si la s\xE9lection est vide. + * @return true Si aucun objet ni aucun point en mode atomique selectionn\xE9. + */ + public boolean isSelectionEmpty() { + return isAtomicMode_ ? selectionMulti_ == null ? true : selectionMulti_.isEmpty() : super.isSelectionEmpty(); + } + + public boolean isTitleModifiable() { + return true; + } + + /** + * @param _modele Modele + */ + public void modele(final ZModeleGeometry _modele) { + if (modele_ != _modele) { + final ZModeleGeometry vp = modele_; + modele_ = _modele; + firePropertyChange("modele", vp, modele_); + } + } + + public ZModeleDonnees modeleDonnees() { + return modele_; + } + + /** + * @param _g + */ + public void paintDonnees(final Graphics2D _g, final GrMorphisme _versEcran, final GrMorphisme _versReel, + final GrBoite _clipReel) { + if ((modele_ == null) || (modele_.getNombre() <= 0)) { + return; + } + final GrBoite clip = _clipReel; + final GrMorphisme versEcran = _versEcran; + final int nombre = modele_.getNombre(); + + final TraceIconModel iconeModel = iconModel_ == null ? null : new TraceIconModel(iconModel_); + + final TraceIcon icone; + if (isRapide()) { + icone=new TraceIcon(TraceIcon.CARRE,2,iconeModel.getCouleur()); + } + else + icone = iconeModel == null ? null : new TraceIcon(iconeModel); + + final TraceLigne tl; + if (isRapide()) + tl=new TraceLigne(TraceLigne.LISSE,1,ligneModel_.getCouleur()); + else + tl= ligneModel_.buildCopy(); + + final GrBoite bPoly = new GrBoite(); + bPoly.o_ = new GrPoint(); + bPoly.e_ = new GrPoint(); + + // on part de la fin : comme ca la premiere ligne apparait au-dessus + for (int i = nombre - 1; i >= 0; i--) { + if (!modele_.isGeometryReliee(i)) + continue; + + // il n'y a pas de points pour cette g\xE9om\xE9trie + final int nbPoints=modele_.getNbPointForGeometry(i); + if (nbPoints <= 0) + continue; + + modele_.getDomaineForGeometry(i, bPoly); + // Si la boite du polygone n'est pas dans la boite d'affichage on passe + if (bPoly.intersectionXY(clip) == null) { + continue; + } + + final GrPoint ptOri = new GrPoint(); + modele_.point(ptOri, i, nbPoints - 1); + ptOri.autoApplique(versEcran); + + if (!isRapide()) initTrace(ligneModel_, i); + final GrPoint ptDest = new GrPoint(); + for (int j = nbPoints - 2; j >= 0; j--) { + // le point de dest est initialise + modele_.point(ptDest, i, j); + ptDest.autoApplique(versEcran); + tl.dessineTrait(_g, ptOri.x_, ptOri.y_, ptDest.x_, ptDest.y_); + ptOri.initialiseAvec(ptDest); + } + if (modele_.isGeometryFermee(i)) { + modele_.point(ptOri, i, nbPoints - 1); + ptOri.autoApplique(versEcran); + tl.dessineTrait(_g, ptOri.x_, ptOri.y_, ptDest.x_, ptDest.y_); + } + modele_.point(ptOri, i, nbPoints - 1); + ptOri.autoApplique(versEcran); + } + + // on trace les icones apres pour qu'ils soient dessin\xE9s au-dessus des lignes. + if (icone != null) { + for (int i = nombre - 1; i >= 0; i--) { + // il n'y a pas de points pour cette ligne + if (modele_.getNbPointForGeometry(i) <= 0) { + continue; + } + modele_.getDomaineForGeometry(i, bPoly); + // Si la boite du polygone n'est pas dans la boite d'affichage on passe + if (bPoly.intersectionXY(clip) == null) { + continue; + } + final int nbPoints = modele_.getNbPointForGeometry(i); + if (nbPoints <= 0) { + continue; + } + if (!isRapide()) initTrace(iconeModel, i); + final GrPoint ptDest = new GrPoint(); + for (int j = nbPoints - 1; j >= 0; j--) { + // le point de dest est initialise + modele_.point(ptDest, i, j); + if (!_clipReel.contientXY(ptDest)) { + continue; + } + ptDest.autoApplique(versEcran); + icone.paintIconCentre(this, _g, ptDest.x_, ptDest.y_); + } + } + } + } + + public void paintSelection(final Graphics2D _g, final ZSelectionTrace _trace, final GrMorphisme _versEcran, + final GrBoite _clipReel) { + if (isSelectionEmpty()) return; + + if (isAtomicMode_) { + CtuluListSelection containers=new CtuluListSelection(selectionMulti_.getIdxSelection()); + paintSelectionSimple(_g, _trace, _versEcran, _clipReel, containers); + paintSelectionMulti(_g, _trace, _versEcran, _clipReel); + } else { + paintSelectionSimple(_g, _trace, _versEcran, _clipReel, selection_); + } + } + + public void paintSelectionSimple(final Graphics _g, final ZSelectionTrace _trace, final GrMorphisme _versEcran, + final GrBoite _clipReel, CtuluListSelection _containers) { + if ((isRapide()) || (isSelectionEmpty())) { + return; + } + final GrBoite clip = _clipReel; + if (getDomaine() == null || !getDomaine().intersectXY(clip)) { + return; + } + final GrMorphisme versEcran = _versEcran; + Color cs = _trace.getColor(); + if (isAttenue()) { + cs = attenueCouleur(cs); + } + _g.setColor(cs); + final TraceLigne tlSelection = _trace.getLigne(); + final TraceIcon ic = _trace.getIcone(); + final int nb = Math.min(_containers.getMaxIndex(), modele_.getNombre() - 1); + + final GrBoite btGeom = new GrBoite(); + btGeom.e_ = new GrPoint(); + btGeom.o_ = new GrPoint(); + for (int i = nb; i >= 0; i--) { + if (!_containers.isSelected(i)) { + continue; + } + modele_.getDomaineForGeometry(i, btGeom); + // Si la boite de la geometrie n'est pas dans la boite d'affichage on passe + if (btGeom.intersectionXY(clip) == null) { + continue; + } + + final int nbPoints = modele_.getNbPointForGeometry(i); + boolean bferm=modele_.isGeometryFermee(i); + boolean breli=modele_.isGeometryReliee(i); + + final GrPoint ptOri = new GrPoint(); + modele_.point(ptOri, i, nbPoints - 1); + ptOri.autoApplique(versEcran); + ic.paintIconCentre(this, _g, ptOri.x_, ptOri.y_); + final GrPoint ptDest = new GrPoint(); + for (int j = nbPoints - 2; j >= 0; j--) { + // le point de dest est initialise + modele_.point(ptDest, i, j); + ptDest.autoApplique(versEcran); + ic.paintIconCentre(this, _g, ptDest.x_, ptDest.y_); + if (breli) + tlSelection.dessineTrait((Graphics2D) _g, ptOri.x_, ptOri.y_, ptDest.x_, ptDest.y_); + ptOri.initialiseAvec(ptDest); + } + if (bferm) { + modele_.point(ptOri, i, nbPoints - 1); + ptOri.autoApplique(versEcran); + if (breli) + tlSelection.dessineTrait((Graphics2D) _g, ptOri.x_, ptOri.y_, ptDest.x_, ptDest.y_); + } + } + } + + public void selectAll() { + if (!isVisible()) return; + + if (!isAtomicMode_) { + super.selectAll(); + return; + } + if (selectionMulti_ == null) { + selectionMulti_ = creeSelectionMutli(); + } + for (int i = modele_.getNombre() - 1; i >= 0; i--) { + CtuluListSelection s = selectionMulti_.get(i); + if (s == null) { + s = new CtuluListSelection(modele_.getNbPointForGeometry(i)); + selectionMulti_.set(i, s); + } + s.setSelectionInterval(0, modele_.getNbPointForGeometry(i) - 1); + } + fireSelectionEvent(); + } + + public CtuluListSelection selection(final GrPoint _pt, final int _tolerance) { + if (modele_.getNombre() == 0) { + return null; + } + final GrBoite bClip = getDomaine(); + if (bClip == null) { + return null; + } + final double distanceReel = GrMorphisme.convertDistanceXY(getVersReel(), _tolerance); + if ((!bClip.contientXY(_pt)) && (bClip.distanceXY(_pt) > distanceReel)) { + return null; + } + + final GrPoint pt=new GrPoint(); + final GrBoite bPoly = new GrBoite(new GrPoint(), new GrPoint()); + for (int i = modele_.getNombre() - 1; i >= 0; i--) { + modele_.getDomaineForGeometry(i, bPoly); + if (bPoly.contientXY(_pt)||bPoly.distanceXY(_pt)<distanceReel) { + for (int j=modele_.getNbPointForGeometry(i)-1; j>=0; j--) { + modele_.point(pt, i, j); + if (pt.distanceXY(_pt)<distanceReel) { + final CtuluListSelection r=new CtuluListSelection(1); + r.setSelectionInterval(i, i); + return r; + } + } + } + } + return null; + } + + public CtuluListSelection selection(final LinearRing _poly, final int _mode) { + if (modele_.getNombre() == 0 || !isVisible()) { + return null; + } + final Envelope polyEnv = _poly.getEnvelopeInternal(); + final GrBoite domaineBoite = getDomaine(); + final Envelope domaine = new Envelope(domaineBoite.e_.x_, domaineBoite.o_.x_, domaineBoite.e_.y_, + domaineBoite.o_.y_); + // si l'envelop du polygone n'intersect pas le domaine, il n'y a pas de + // selection + if (!polyEnv.intersects(domaine)) { + return null; + } + + final SIRtreePointInRing tester = new SIRtreePointInRing(_poly); + final Coordinate c = new Coordinate(); + final CtuluListSelection r = creeSelection(); + final GrPoint p = new GrPoint(); + final GrBoite bPoly = new GrBoite(new GrPoint(), new GrPoint()); + for (int i = modeleDonnees().getNombre() - 1; i >= 0; i--) { + modele_.getDomaineForGeometry(i, bPoly); + // si le poly est dans dans le poly de selection + boolean selected = false; + if (_mode == EbliSelectionMode.MODE_ALL) { + if (polyEnv.contains(bPoly.e_.x_, bPoly.e_.y_) && polyEnv.contains(bPoly.o_.x_, bPoly.o_.y_)) { + selected = true; + for (int j = modele_.getNbPointForGeometry(i) - 1; (j >= 0) && selected; j--) { + modele_.point(p, i, j); + c.x = p.x_; + c.y = p.y_; + if (!tester.isInside(c)) { + selected = false; + } + } + } + } else if (_mode == EbliSelectionMode.MODE_ONE) { + if (polyEnv.intersects(bPoly.getEnv())) { + for (int j = modele_.getNbPointForGeometry(i) - 1; (j >= 0) && !selected; j--) { + modele_.point(p, i, j); + c.x = p.x_; + c.y = p.y_; + if (GISLib.isSelectedEnv(c, _poly, polyEnv, tester)) { + selected = true; + } + } + } + + } else if (_mode == EbliSelectionMode.MODE_CENTER) { + final CoordinateSequence coordinateSequence = modele_.getGeomData().getCoordinateSequence(i); + c.x = GISLib.getMoyX(coordinateSequence); + c.y = GISLib.getMoyY(coordinateSequence); + selected = GISLib.isSelectedEnv(c, _poly, polyEnv, tester); + + } + if (selected) { + r.add(i); + } + } + if (r.isEmpty()) { + return null; + } + return r; + } + + /** + * Renvoie la liste des objets selectionnees pour le point <code>_pt</code> avec pour tolerance + * <code>_tolerance</code>. + * + * @param _pt + * @param _tolerance + * @return la liste des indexs selectionnes (ou null si aucune selection) + */ + public EbliListeSelectionMulti selectionMulti(final GrPoint _pt, final int _tolerance) { + final GrMorphisme versReel = getVersReel(); + GrBoite bClip = getDomaine(); + if (bClip == null || (!bClip.contientXY(_pt)) && (bClip.distanceXY(_pt) > _tolerance)) { + return null; + } + final double distanceReel = GrMorphisme.convertDistanceXY(versReel, _tolerance); + bClip = getClipReel(getGraphics()); + final GrPoint p = new GrPoint(); + final GrBoite btLigne = new GrBoite(); + for (int i = modele_.getNombre() - 1; i >= 0; i--) { + modele_.getDomaineForGeometry(i, btLigne); + if (btLigne.contientXY(_pt) || btLigne.distanceXY(_pt) < distanceReel) { + for (int j = modele_.getNbPointForGeometry(i) - 1; j >= 0; j--) { + modele_.point(p, i, j); + if (bClip.contientXY(p) && (p.distanceXY(_pt) < distanceReel)) { + final EbliListeSelectionMulti r = new EbliListeSelectionMulti(1); + r.set(i, j); + return r; + } + } + } + } + return null; + } + + public EbliListeSelectionMulti selectionMulti(final LinearRing _poly) { + if (modele_.getNombre() == 0 || !isVisible()) { + return null; + } + final Envelope polyEnv = _poly.getEnvelopeInternal(); + final GrBoite domaineBoite = getDomaine(); + final Envelope domaine = new Envelope(domaineBoite.e_.x_, domaineBoite.o_.x_, domaineBoite.e_.y_, + domaineBoite.o_.y_); + // si l'envelop du polygone n'intersect pas le domaine, il n'y a pas de + // selection + if (!polyEnv.intersects(domaine)) { + return null; + } + final EbliListeSelectionMulti r = creeSelectionMutli(); + final GrPoint p = new GrPoint(); + final SIRtreePointInRing tester = new SIRtreePointInRing(_poly); + final Coordinate c = new Coordinate(); + for (int i = modele_.getNombre() - 1; i >= 0; i--) { + CtuluListSelection l = null; + final int nbPt = modele_.getNbPointForGeometry(i); + for (int j = nbPt - 1; j >= 0; j--) { + modele_.point(p, i, j); + c.x = p.x_; + c.y = p.y_; + if ((polyEnv.contains(c)) && (tester.isInside(c))) { + if (l == null) { + l = new CtuluListSelection(nbPt); + } + l.add(j); + } + } + if (l != null) { + r.set(i, l); + } + } + if (r.isEmpty()) { + return null; + } + return r; + } + + /** + * D\xE9finit que les modifications d'objets auront lieu en mode atomique. + * @param _new true : Modifications en mode atomique. + * @return true si l'appel a produit un changement de mode. + */ + public boolean setAtomicMode(final boolean _new) { + if (_new != isAtomicMode_) { + isAtomicMode_ = _new; + firePropertyChange("mode", !isAtomicMode_, isAtomicMode_); + clearSelection(); + return true; + } + return false; + } + + public boolean setSelection(final int[] _idx) { + if (!isAtomicMode_) { + return super.setSelection(_idx); + } + // TODO : Traitement a faire si on est en mode atomique. + FuLog.warning("EBL:ZCalqueLigneBrisee.setSelection() can't be called in atomic mode"); + return false; + } + + public boolean setTitle(final String _title) { + final boolean r = super.setTitle(_title); + if (r && modele_ != null && modele_.getGeomData() != null) { + modele_.getGeomData().setTitle(_title, null); + } + return r; + } + + private LineString createLineFromSelection(final int _i, final CtuluListSelectionInterface _selection, final int _nbSelected) { + final GISCoordinateSequenceContainerInterface geom = (GISCoordinateSequenceContainerInterface) modele_.getGeomData().getGeometry(_i); + final Coordinate[] cs = new Coordinate[_nbSelected]; + final int[] idx = _selection.getSelectedIndex(); + for (int j = 0; j < _nbSelected; j++) { + cs[j] = geom.getCoordinateSequence().getCoordinate(idx[j]); + } + return GISGeometryFactory.INSTANCE.createLineString(cs); + } + + public LineString getSelectedLine() { + if (isSelectionEmpty()) { + return null; + } + // en mode normal (pas de vertex selectionne), on renvoie la ligne s\xE9lectionn\xE9e + if (!isAtomicMode()) { +// return getLayerSelection().getNbSelectedIndex() == 1 ? (LineString) modele_.getGeomData().getGeometry( +// getLayerSelection().getMaxIndex()) : null; + throw new UnsupportedOperationException("Can't create line from vertices"); + } + // mode vertex + final EbliListeSelectionMultiInterface select = getLayerSelectionMulti(); + // mode vertex + // la selection se situe dans la meme ligne + if (select.getNbListSelected() == 1) { + final int i = select.getIdxSelected()[0]; + final CtuluListSelectionInterface selection = select.getSelection(i); + final int nbSelected = selection.getNbSelectedIndex(); + // deux sommets s\xE9lectionn\xE9s: on choisit la ligne en les 2 sommets + if (nbSelected == 2) { + return createLineFromSelection(i, selection, nbSelected); + + } else if (nbSelected >= 2) { + final int nbPointForLigne = modele_.getNbPointForGeometry(i); + final int[] res = CtuluListSelection.isSelectionContiguous(select.getSelection(i), nbPointForLigne); + if (res == null) { + return null; + } + // selection normale + if (res[0] < res[1]) { + return createLineFromSelection(i, selection, nbSelected); + } + } + } else if (select.getNbListSelected() == 2) { + final int[] idx = select.getIdxSelected(); + final CtuluListSelectionInterface selection1 = select.getSelection(idx[0]); + final CtuluListSelectionInterface selection2 = select.getSelection(idx[1]); + if (selection1.getNbSelectedIndex() == 1 && selection2.getNbSelectedIndex() == 1) { + final Coordinate[] cs = new Coordinate[2]; + cs[0] = ((Geometry)modele_.getGeomData().getGeometry(idx[0])).getCoordinates()[selection1.getMaxIndex()]; + cs[1] = ((Geometry)modele_.getGeomData().getGeometry(idx[1])).getCoordinates()[selection2.getMaxIndex()]; + return GISGeometryFactory.INSTANCE.createLineString(cs); + } + } + return null; + } + +} Property changes on: branches/Br_FudaaModeleur_TF/fudaa_devel/ebli/src/org/fudaa/ebli/calque/ZCalqueGeometry.java ___________________________________________________________________ Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |