From: <bma...@us...> - 2008-11-14 14:50:27
|
Revision: 4218 http://fudaa.svn.sourceforge.net/fudaa/?rev=4218&view=rev Author: bmarchan Date: 2008-11-14 14:50:16 +0000 (Fri, 14 Nov 2008) Log Message: ----------- D?\195?\169placement des classes de lecture Mascaret de mascaret -> marscaret.io. Modified Paths: -------------- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/sig/wizard/FSigFileLoaderMascaret.java Added Paths: ----------- branches/FudaaModeleur_TC1Bis/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/io/ branches/FudaaModeleur_TC1Bis/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/io/MascaretFileFormat.java branches/FudaaModeleur_TC1Bis/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/io/MascaretReader.java Removed 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 Property Changed: ---------------- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/sig/wizard/FSigFileLoaderMascaret.java Deleted: 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 2008-11-14 14:43:52 UTC (rev 4217) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/MascaretFileFormat.java 2008-11-14 14:50:16 UTC (rev 4218) @@ -1,38 +0,0 @@ -/* - * @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; - } - -} Deleted: 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 2008-11-14 14:43:52 UTC (rev 4217) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/MascaretReader.java 2008-11-14 14:50:16 UTC (rev 4218) @@ -1,307 +0,0 @@ -/* - * @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 abscisseCurvilingeAxeHydraulique; - public List<Double> coordCurviligneProfil=new ArrayList<Double>(); - // Info sp\xE9cifique 2D - public List<double[]> coordXYTraceProfil=new ArrayList<double[]>(); - public double[] coordIntersectionAxeHydraulique; - 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&&coordIntersectionAxeHydraulique==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||coordIntersectionAxeHydraulique!=null&&coordIntersectionAxeHydraulique.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()&&abscisseCurvilingeAxeHydraulique>=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 - &&coordIntersectionAxeHydraulique.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; - } - - /** - * @return 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.abscisseCurvilingeAxeHydraulique=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 hydraulique - if (token!=null&&token.equals("AXE")) - profil.coordIntersectionAxeHydraulique=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 profils 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 hydraulique \\ - CoordinateArraySequence coordSeq=new CoordinateArraySequence(profils_.size()); - for (int i=0; i<profils_.size(); i++) { - coordSeq.setOrdinate(i, 0, profils_.get(i).coordIntersectionAxeHydraulique[0]); - coordSeq.setOrdinate(i, 1, profils_.get(i).coordIntersectionAxeHydraulique[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 profil, aucun axe hydraulique 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) { - } - } - -} Copied: branches/FudaaModeleur_TC1Bis/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/io/MascaretFileFormat.java (from rev 4216, branches/FudaaModeleur_TC1Bis/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/MascaretFileFormat.java) =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/io/MascaretFileFormat.java (rev 0) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/io/MascaretFileFormat.java 2008-11-14 14:50:16 UTC (rev 4218) @@ -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.io; + +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/io/MascaretFileFormat.java ___________________________________________________________________ Added: svn:keywords + Date Revision Author URL Id Added: svn:mergeinfo + /branches/Br_FudaaModeleur_TF/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/MascaretFileFormat.java:3445-3850 /branches/FudaaModeleur_TC1/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/MascaretFileFormat.java:3861-3891 Added: svn:eol-style + native Copied: branches/FudaaModeleur_TC1Bis/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/io/MascaretReader.java (from rev 4217, branches/FudaaModeleur_TC1Bis/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/MascaretReader.java) =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/io/MascaretReader.java (rev 0) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/io/MascaretReader.java 2008-11-14 14:50:16 UTC (rev 4218) @@ -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.io; + +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 abscisseCurvilingeAxeHydraulique; + public List<Double> coordCurviligneProfil=new ArrayList<Double>(); + // Info sp\xE9cifique 2D + public List<double[]> coordXYTraceProfil=new ArrayList<double[]>(); + public double[] coordIntersectionAxeHydraulique; + 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&&coordIntersectionAxeHydraulique==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||coordIntersectionAxeHydraulique!=null&&coordIntersectionAxeHydraulique.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()&&abscisseCurvilingeAxeHydraulique>=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 + &&coordIntersectionAxeHydraulique.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; + } + + /** + * @return 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.abscisseCurvilingeAxeHydraulique=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 hydraulique + if (token!=null&&token.equals("AXE")) + profil.coordIntersectionAxeHydraulique=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 profils 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 hydraulique \\ + CoordinateArraySequence coordSeq=new CoordinateArraySequence(profils_.size()); + for (int i=0; i<profils_.size(); i++) { + coordSeq.setOrdinate(i, 0, profils_.get(i).coordIntersectionAxeHydraulique[0]); + coordSeq.setOrdinate(i, 1, profils_.get(i).coordIntersectionAxeHydraulique[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 profil, aucun axe hydraulique 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/io/MascaretReader.java ___________________________________________________________________ Added: svn:keywords + Date Revision Author URL Id Added: svn:mergeinfo + /branches/Br_FudaaModeleur_TF/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/MascaretReader.java:3445-3850 /branches/FudaaModeleur_TC1/fudaa_devel/dodico/src/org/fudaa/dodico/mascaret/MascaretReader.java:3861-3891 Added: svn:eol-style + native Modified: 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 2008-11-14 14:43:52 UTC (rev 4217) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/sig/wizard/FSigFileLoaderMascaret.java 2008-11-14 14:50:16 UTC (rev 4218) @@ -16,7 +16,7 @@ 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 org.fudaa.dodico.mascaret.io.MascaretFileFormat; import com.memoire.bu.BuFileFilter; Property changes on: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/sig/wizard/FSigFileLoaderMascaret.java ___________________________________________________________________ Modified: svn:keywords - Id + Date Revision Author URL Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |