From: <emm...@us...> - 2008-11-14 11:10:57
|
Revision: 4216 http://fudaa.svn.sourceforge.net/fudaa/?rev=4216&view=rev Author: emmanuel_martin Date: 2008-11-14 11:10:52 +0000 (Fri, 14 Nov 2008) Log Message: ----------- Tache #82 : "Import de fichier Mascaret avec r?\195?\169f?\195?\169rence 2D." Modified Paths: -------------- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/commun/impl/FudaaCommonImplementation.java branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/sig/wizard/FSigWizardFileMng.java Added Paths: ----------- branches/FudaaModeleur_TC1Bis/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/MascaretFileFormat.java branches/FudaaModeleur_TC1Bis/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/MascaretReader.java branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/sig/wizard/FSigFileLoaderMascaret.java Added: branches/FudaaModeleur_TC1Bis/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/MascaretFileFormat.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/MascaretFileFormat.java (rev 0) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/MascaretFileFormat.java 2008-11-14 11:10:52 UTC (rev 4216) @@ -0,0 +1,38 @@ +/* + * @creation 13 nov. 2008 + * @modification $Date:$ + * @license GNU General Public License 2 + * @copyright (c)1998-2008 CETMEF 2 bd Gambetta F-60231 Compiegne + * @mail fud...@li... + */ +package org.fudaa.dodico.mascaret; + +import org.fudaa.ctulu.fileformat.FileFormatUnique; +import org.fudaa.ctulu.fileformat.FileReadOperationAbstract; +import org.fudaa.ctulu.fileformat.FileWriteOperationAbstract; + +/** + * @author Emmanuel MARTIN + * @version $Id:$ + */ +public class MascaretFileFormat extends FileFormatUnique { + + public MascaretFileFormat() { + super(1); + } + + /* (non-Javadoc) + * @see org.fudaa.ctulu.fileformat.FileFormatVersionInterface#createReader() + */ + public FileReadOperationAbstract createReader() { + return new MascaretReader(); + } + + /* (non-Javadoc) + * @see org.fudaa.ctulu.fileformat.FileFormatVersionInterface#createWriter() + */ + public FileWriteOperationAbstract createWriter() { + return null; + } + +} Property changes on: branches/FudaaModeleur_TC1Bis/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/MascaretFileFormat.java ___________________________________________________________________ Added: svn:keywords + Id Added: svn:eol-style + native Added: branches/FudaaModeleur_TC1Bis/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/MascaretReader.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/MascaretReader.java (rev 0) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/MascaretReader.java 2008-11-14 11:10:52 UTC (rev 4216) @@ -0,0 +1,307 @@ +/* + * @creation 13 nov. 2008 + * @modification $Date:$ + * @license GNU General Public License 2 + * @copyright (c)1998-2008 CETMEF 2 bd Gambetta F-60231 Compiegne + * @mail fud...@li... + */ +package org.fudaa.dodico.mascaret; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.fudaa.ctulu.CtuluAnalyze; +import org.fudaa.ctulu.fileformat.FileReadOperationAbstract; +import org.fudaa.ctulu.fileformat.FortranInterface; +import org.fudaa.ctulu.gis.GISAttributeConstants; +import org.fudaa.ctulu.gis.GISAttributeInterface; +import org.fudaa.ctulu.gis.GISPolyligne; +import org.fudaa.ctulu.gis.GISZoneCollectionLigneBrisee; +import org.fudaa.dodico.commun.DodicoLib; + +import com.vividsolutions.jts.geom.impl.CoordinateArraySequence; + +/** + * Parser du format Mascaret. (versions 6.0 et pr\xE9c\xE9dentes) + * @author Emmanuel MARTIN + * @version $Id:$ + */ +public class MascaretReader extends FileReadOperationAbstract { + + /** + * Container des informations relative \xE0 un profil. + */ + private class Profil{ + public String nomBief; + public String nomProfil; + public List<Double> coordZ=new ArrayList<Double>(); // Bathy ou Topo + public List<Character> bathyOuTopo=new ArrayList<Character>(); // B ou T + // Info sp\xE9cifique 1D + public double abscisseCurvilingeAxeHydrolique; + public List<Double> coordCurviligneProfil=new ArrayList<Double>(); + // Info sp\xE9cifique 2D + public List<double[]> coordXYTraceProfil=new ArrayList<double[]>(); + public double[] coordIntersectionAxeHydrolique; + public List<double[]> coordXYProfil=new ArrayList<double[]>(); + + /** @return vrai si seul des informations 1d sont pr\xE9sentes. */ + public boolean is1d(){ + return coordCurviligneProfil.size()>0&&coordXYTraceProfil.size()==0&&coordIntersectionAxeHydrolique==null + &&coordXYProfil.size()==0; + } + + /** @return vrai si les informations 2d sont pr\xE9sentes. (les infos 1d peuvent \xEAtre \xE9galement pr\xE9sentes) */ + public boolean is2d(){ + return (coordXYTraceProfil.size()!=0||coordIntersectionAxeHydrolique!=null&&coordIntersectionAxeHydrolique.length!=0||coordXYProfil + .size()!=0); + } + + /** Check les attributs communs \xE0 1d et 2d. */ + private boolean checkCommon(){ + boolean check=nomBief.length()>0&&nomProfil.length()>0&&coordZ.size()>0&&bathyOuTopo.size()==coordZ.size(); + int i=-1; + // Verifi que bathyOuTopo ne comporte que B ou T + while(check&&++i<bathyOuTopo.size()) + check=bathyOuTopo.get(i).equals('T')||bathyOuTopo.get(i).equals('B'); + return check; + } + + /** @return vrai si les informations utile 1D sont compl\xE8tes et coh\xE9rentes. */ + public boolean check1D(){ + boolean check=checkCommon()&&abscisseCurvilingeAxeHydrolique>=0&&coordCurviligneProfil.size()==coordZ.size(); + int i=0; + // Verifi que l'ordre des coordonn\xE9es est croissant. + while(check&&++i<coordCurviligneProfil.size()) + check=coordCurviligneProfil.get(i-1)<=coordCurviligneProfil.get(i); + return check; + } + + /** @return vrai si les informations utile 2D sont compl\xE8tes et coh\xE9rentes. */ + public boolean check2D(){ + boolean check=checkCommon()&&coordXYTraceProfil.size()>=2&&coordXYTraceProfil.size()<=4 + &&coordIntersectionAxeHydrolique.length==2&&coordXYProfil.size()==coordZ.size(); + // Verification de la taille des coordonn\xE9es XY du profile + int i=-1; + while(check&&++i<coordXYProfil.size()) + check=coordXYProfil.get(i).length==2; + return check; + } + } + + /** Exception lev\xE9e quand une probl\xE8me est trouv\xE9 pendant le parsing. */ + private class ParseError extends Exception{ + public ParseError(String _message){ + super(_message); + } + } + + /** Le fichier \xE0 lire */ + private FileReader rawData_; + private String fileName_; + /** Les caract\xE8res de 's\xE9paration' */ + private char[] charSeparation_=new char[]{' ', '\t'}; + private char charSeparationNewLigne_='\n'; + /** Profiles extraits */ + List<Profil> profils_=new ArrayList<Profil>(); + + public MascaretReader() { + rawData_=null; + } + + /** + * Retourne vrai si _element est dans _tabElements + * @param _element + * @param _tabElements + * @return retourne vrai si _element est dans _tabElements + */ + private boolean in(final char _element, final char[] _tabElements){ + boolean found=false; + int i=-1; + while(!found&&++i<_tabElements.length) + found=_element==_tabElements[i]; + return found; + } + + /** + * @returnun token dont le caract\xE8re de s\xE9paration est le retour \xE0 la ligne. Null si rien \xE0 lire. + */ + private StringBuffer nextLineToken(){ + StringBuffer token=new StringBuffer(); + int currentRawChar; + try { + currentRawChar=rawData_.read(); + // Lecture du token : lecture tant qu'un caract\xE8re de s\xE9paration n'est pas + // trouv\xE9. + while (currentRawChar!=-1&&((char)currentRawChar)!=charSeparationNewLigne_) { + token.append((char)currentRawChar); + currentRawChar=rawData_.read(); + } + } + catch (IOException _exc) { + // Erreur dans un des rawData_.read() + _exc.printStackTrace(); + } + // Retour du token + return token.length()==0 ? null:token; + } + + /** + * Retourne le token suivant dans le flux (liste de caract\xE8re jusqu'au + * caract\xE8re de s\xE9paration suivant). + * @return le token ou null si il n'y en a pas. + */ + private String nextWordToken(StringBuffer _lineToken) { + StringBuffer token=new StringBuffer(); + // Elimination des caract\xE8res de s\xE9paration avant le token + while (_lineToken.length()>0&&in(_lineToken.charAt(0), charSeparation_)) + _lineToken.deleteCharAt(0); + // Lecture du token : lecture tant qu'un caract\xE8re de s\xE9paration n'est pas + // trouv\xE9. + while (_lineToken.length()>0&&!in(_lineToken.charAt(0), charSeparation_)) { + token.append(_lineToken.charAt(0)); + _lineToken.deleteCharAt(0); + } + // Retour du token + return token.toString().length()==0 ? null:token.toString(); + } + + /* (non-Javadoc) + * @see org.fudaa.ctulu.fileformat.FileReadOperationAbstract#internalRead() + */ + @Override + protected Object internalRead() { + try { + StringBuffer lineToken=nextLineToken(); + if(lineToken==null) + throw new ParseError(fileName_+DodicoLib.getS(" : le fichier est vide.")); + /* + * Boucle principale : une it\xE9ration par profil + */ + String token=nextWordToken(lineToken); + while (lineToken!=null&&token.equalsIgnoreCase("profil")) { + Profil profil=new Profil(); + + // Premi\xE8re ligne \\ + // Extraction des informations commune \xE0 1d et 2d + profil.nomBief=nextWordToken(lineToken); + profil.nomProfil=nextWordToken(lineToken); + profil.abscisseCurvilingeAxeHydrolique=Double.parseDouble(nextWordToken(lineToken)); + // Coordonn\xE9es de trace de profile : non pr\xE9sent dans les fichiers 1d + token=nextWordToken(lineToken); + while (token!=null&&!token.equals("AXE")) { + profil.coordXYTraceProfil.add(new double[]{Double.parseDouble(token), Double.parseDouble(nextWordToken(lineToken))}); + token=nextWordToken(lineToken); + } + // Coordonn\xE9e d'intersection du profile et de l'axe hydrolique + if (token!=null&&token.equals("AXE")) + profil.coordIntersectionAxeHydrolique=new double[]{Double.parseDouble(nextWordToken(lineToken)), + Double.parseDouble(nextWordToken(lineToken))}; + + // Lignes suivantes : coordonn\xE9es du profile \\ + lineToken=nextLineToken(); + while (lineToken!=null&&!(token=nextWordToken(lineToken)).equalsIgnoreCase("profil")) { + profil.coordCurviligneProfil.add(Double.parseDouble(token)); + profil.coordZ.add(Double.parseDouble(nextWordToken(lineToken))); + profil.bathyOuTopo.add(nextWordToken(lineToken).charAt(0)); + // Coordonn\xE9es XY : non pr\xE9sent dans les fichiers 1d + token=nextWordToken(lineToken); + if (token!=null) + profil.coordXYProfil.add(new double[]{Double.parseDouble(token), Double.parseDouble(nextWordToken(lineToken))}); + lineToken=nextLineToken(); + } + // Verification de la coh\xE9rance des informations + if (profil.is1d()) + throw new ParseError(fileName_+DodicoLib.getS(" : les profiles 1D ne sont pas g\xE9r\xE9s")); + else if (!(profil.is2d()&&profil.check2D())) + throw new ParseError(fileName_+DodicoLib.getS(" : le fichier source comporte des erreurs.")); + // Ajout du profile \xE0 la liste et traitement du profile suivant + profils_.add(profil); + } + // G\xE9n\xE9ration d'un GISZoneCollection avec les informations extraites et + // retour de celle-ci + return generateGIS(); + } + catch (ParseError _exc) { + analyze_.addFatalError(_exc.getMessage()); + } + catch (NumberFormatException _exc){ + analyze_.addFatalError(fileName_+DodicoLib.getS(" : le fichier source comporte des erreurs.")); + } + catch (NullPointerException _exc){ + analyze_.addFatalError(fileName_+DodicoLib.getS(" : le fichier source comporte des erreurs.")); + } + return null; + } + + private GISZoneCollectionLigneBrisee generateGIS(){ + progress_.setDesc(DodicoLib.getS("Lecture de ")+fileName_); + // Cr\xE9ation de la GISZoneCollectionLigneBrisee + GISZoneCollectionLigneBrisee zone=new GISZoneCollectionLigneBrisee(); + zone.setAttributes(new GISAttributeInterface[]{GISAttributeConstants.TITRE, GISAttributeConstants.NATURE}, null); + // G\xE9n\xE9ration des profiles et des traces de profiles \\ + for(int k=0;k<profils_.size();k++){ + progress_.setProgression((int)((float)k/profils_.size()*100)); + Profil profil=profils_.get(k); + CoordinateArraySequence coordSeq=new CoordinateArraySequence(profil.coordXYTraceProfil.size()); + // Trace profil + for(int i=0;i<profil.coordXYTraceProfil.size();i++){ + coordSeq.setOrdinate(i, 0, profil.coordXYTraceProfil.get(i)[0]); + coordSeq.setOrdinate(i, 1, profil.coordXYTraceProfil.get(i)[1]); + } + zone.addGeometry(new GISPolyligne(coordSeq), new Object[]{profil.nomProfil, GISAttributeConstants.ATT_NATURE_TP}, null); + // Profil + coordSeq=new CoordinateArraySequence(profil.coordXYProfil.size()); + for(int i=0;i<profil.coordXYProfil.size();i++){ + coordSeq.setOrdinate(i, 0, profil.coordXYProfil.get(i)[0]); + coordSeq.setOrdinate(i, 1, profil.coordXYProfil.get(i)[1]); + coordSeq.setOrdinate(i, 2, profil.coordZ.get(i)); + } + zone.addGeometry(new GISPolyligne(coordSeq), new Object[]{profil.nomProfil, GISAttributeConstants.ATT_NATURE_PF}, null); + } + if (profils_.size()>1) { + // G\xE9n\xE9ration de l'axe hydrolique \\ + CoordinateArraySequence coordSeq=new CoordinateArraySequence(profils_.size()); + for (int i=0; i<profils_.size(); i++) { + coordSeq.setOrdinate(i, 0, profils_.get(i).coordIntersectionAxeHydrolique[0]); + coordSeq.setOrdinate(i, 1, profils_.get(i).coordIntersectionAxeHydrolique[1]); + } + zone.addGeometry(new GISPolyligne(coordSeq), new Object[]{null, GISAttributeConstants.ATT_NATURE_AH}, null); + } + else + analyze_.addInfo(fileName_+DodicoLib.getS(" : le fichier ne comporte qu'un profile, aucun axe hydrolique ne sera g\xE9n\xE9r\xE9.")); + return zone; + } + + /* (non-Javadoc) + * @see org.fudaa.ctulu.fileformat.FileOperationAbstract#getFortranInterface() + */ + @Override + protected FortranInterface getFortranInterface() { + return new FortranInterface() { + public void close() throws IOException{ + if (rawData_ != null) + rawData_.close(); + } + }; + } + + /* (non-Javadoc) + * @see org.fudaa.ctulu.fileformat.FileOperationAbstract#setFile(java.io.File) + */ + @Override + public void setFile(File _f) { + fileName_=_f.getName(); + analyze_ = new CtuluAnalyze(); + analyze_.setResource(_f.getAbsolutePath()); + try { + rawData_=new FileReader(_f); + } + catch (FileNotFoundException _exc) { + } + } + +} Property changes on: branches/FudaaModeleur_TC1Bis/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/MascaretReader.java ___________________________________________________________________ Added: svn:keywords + Id Added: svn:eol-style + native Modified: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/commun/impl/FudaaCommonImplementation.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/commun/impl/FudaaCommonImplementation.java 2008-11-13 10:39:29 UTC (rev 4215) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/commun/impl/FudaaCommonImplementation.java 2008-11-14 11:10:52 UTC (rev 4216) @@ -979,9 +979,12 @@ } error(_analyze.getDesc(), deb, false); return true; - } else if (_analyze.containsErrors()) { + } else if (_analyze.containsErrors()) error(_analyze.getDesc(), CtuluAnalyze.getResume(_analyze.getErrorCanal(), 5), false); - } + else if (_analyze.containsInfos()) + message(FudaaLib.getS("Informations"), CtuluAnalyze.getResume(_analyze.getInfoCanal(), 20), false); + else if (_analyze.containsWarnings()) + warn(FudaaLib.getS("Attention"), CtuluAnalyze.getResume(_analyze.getWarnCanal(), 20), false); return false; } Added: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/sig/wizard/FSigFileLoaderMascaret.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/sig/wizard/FSigFileLoaderMascaret.java (rev 0) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/sig/wizard/FSigFileLoaderMascaret.java 2008-11-14 11:10:52 UTC (rev 4216) @@ -0,0 +1,78 @@ +/* + * @creation 13 nov. 2008 + * @modification $Date:$ + * @license GNU General Public License 2 + * @copyright (c)1998-2008 CETMEF 2 bd Gambetta F-60231 Compiegne + * @mail fud...@li... + */ +package org.fudaa.fudaa.sig.wizard; + +import java.io.File; + +import org.fudaa.ctulu.CtuluAnalyze; +import org.fudaa.ctulu.CtuluIOOperationSynthese; +import org.fudaa.ctulu.ProgressionInterface; +import org.fudaa.ctulu.gis.GISAttributeConstants; +import org.fudaa.ctulu.gis.GISDataModelAttributeAdapter; +import org.fudaa.ctulu.gis.GISLib; +import org.fudaa.ctulu.gis.GISZoneCollectionLigneBrisee; +import org.fudaa.dodico.mascaret.MascaretFileFormat; + +import com.memoire.bu.BuFileFilter; + +/** + * Loader des fichiers mascaret (extension : geomref). + * + * @author Emmanuel MARTIN + * @version $Id:$ + */ +public class FSigFileLoaderMascaret implements FSigFileLoaderI { + + private BuFileFilter filter_; + + public FSigFileLoaderMascaret(){ + filter_=new BuFileFilter(new String[]{"geo", "georef"}, "Fichier mascaret"); + } + + private FSigFileLoaderMascaret(final BuFileFilter _filter){ + filter_=_filter; + } + + /* (non-Javadoc) + * @see org.fudaa.fudaa.sig.wizard.FSigFileLoaderI#createNew() + */ + public FSigFileLoaderI createNew() { + return new FSigFileLoaderMascaret(filter_); + } + + /* (non-Javadoc) + * @see org.fudaa.fudaa.sig.wizard.FSigFileLoaderI#getFileFilter() + */ + public BuFileFilter getFileFilter() { + return filter_; + } + + /* (non-Javadoc) + * @see org.fudaa.fudaa.sig.wizard.FSigFileLoaderI#setInResult(org.fudaa.fudaa.sig.wizard.FSigFileLoadResult, java.io.File, java.lang.String, org.fudaa.ctulu.ProgressionInterface, org.fudaa.ctulu.CtuluAnalyze) + */ + public void setInResult(FSigFileLoadResult _r, File _f, String _origine, ProgressionInterface _prog, CtuluAnalyze _analyze) { + final CtuluIOOperationSynthese op=new MascaretFileFormat().read(_f, _prog); + // En cas d'erreur, fin d'import. + if(op.containsMessages()&&op.getAnalyze().containsFatalError()||op.getAnalyze().containsErrors()||op.getAnalyze().containsInfos()||op.getAnalyze().containsWarnings()) + _analyze.merge(op.getAnalyze()); + if(op.containsMessages()&&op.getAnalyze().containsFatalError()) + return; + + GISZoneCollectionLigneBrisee lines=(GISZoneCollectionLigneBrisee)op.getSource(); + _r.nbPointTotal_+=lines.getNumPoints(); + _r.nbPolylignes_+=lines.getNumGeometries(); + // Ajout de l'attribut ETAT_GEOM + _r.findOrCreateAttribute(GISAttributeConstants.ETAT_GEOM.getID(), String.class, false); + GISDataModelAttributeAdapter adapter = new GISDataModelAttributeAdapter(lines); + adapter.addAttribut(GISAttributeConstants.ETAT_GEOM, _origine); + // + _r.ligneModel_.add(adapter); + _r.addUsedAttributes(GISLib.getAttributeFrom(lines)); + } + +} Property changes on: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/sig/wizard/FSigFileLoaderMascaret.java ___________________________________________________________________ Added: svn:keywords + Id Added: svn:eol-style + native Modified: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/sig/wizard/FSigWizardFileMng.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/sig/wizard/FSigWizardFileMng.java 2008-11-13 10:39:29 UTC (rev 4215) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/sig/wizard/FSigWizardFileMng.java 2008-11-14 11:10:52 UTC (rev 4216) @@ -155,6 +155,8 @@ addLoader(r, fmtLoader, new FSigFileLoaderReflucadPRO()); // reflux solution addLoader(r, fmtLoader, new FSigFileLoaderRefluxRefondeResult()); + // Mascaret + addLoader(r, fmtLoader, new FSigFileLoaderMascaret()); // les maillages addGridList(r, fmtLoader); final BuFileFilter[] filters = new BuFileFilter[r.size()]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |