1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
| package ihm;
import io.Export;
import io.Import;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutionException;
import javax.swing.JOptionPane;
import delaunay.Graph;
import delaunay.Pnt;
import delaunay.Triangle;
import delaunay.Triangulation;
import delaunay.TriangulationDansContour;
public class ActionCalculerDelaunay implements ActionListener {
private Fenetre fenetre ;
public ActionCalculerDelaunay(Fenetre fenetre) {
this.fenetre = fenetre ;
}
@Override
public void actionPerformed(ActionEvent e) {
String pathEntree = fenetre.getPanSommet().getPath();
String pathSortie = fenetre.getPanSortieDelaunay().getPath();
String pathContour = fenetre.getPanContour().getPath();
boolean ignorerPremiereLigneSommets = fenetre.getPanSommet().isCoche() ;
boolean ignorerPremiereLigneContour = fenetre.getPanContour().isCoche() ;
boolean importOk = false ;
if (pathEntree.equals("")){
JOptionPane.showMessageDialog(fenetre, "Vous n'avez pas choisi un fichier de sommets !","Erreur",JOptionPane.ERROR_MESSAGE);
}else {
if (pathSortie.equals("")){
JOptionPane.showMessageDialog(fenetre, "Vous n'avez pas choisi un fichier de sortie pour la triangulation !","Erreur",JOptionPane.ERROR_MESSAGE);
}else {
List<Pnt> sommets ;
List<List<Pnt>> contour ;
try {
if (pathContour.equals("")){
sommets = Import.ImportSommets(pathEntree,ignorerPremiereLigneSommets);
CalculerDelaunay calc = new CalculerDelaunay(sommets);
calc.addPropertyChangeListener(new PropertyChangeProgressBar(fenetre.getProgressBar()));
calc.execute();
Export.ecrireTriangulation(calc.get(), pathSortie);
importOk = true ;
}else {
sommets = Import.ImportSommets(pathEntree,ignorerPremiereLigneSommets);
try {
contour = Import.ImportContour(pathContour,ignorerPremiereLigneContour);
Triangulation t = new Triangulation(sommets);
int i = 0 ;
for (Pnt point : sommets ){
t.delaunayPlace(point);
}
Graph<Triangle> result = TriangulationDansContour.enleverTrianglesContours(t.getListeTriangle(), contour);
Export.ecrireTriangulation(result.nodeSet(), pathSortie);
importOk = true ;
}
catch (FileNotFoundException fi){
JOptionPane.showMessageDialog(fenetre, "Le fichier de contour sélectionné en entrée n'existe pas !","Erreur",JOptionPane.ERROR_MESSAGE);
}
catch (NumberFormatException f) {
JOptionPane.showMessageDialog(fenetre, "Le fichier de contour que vous avez soumis en entrée n'est pas au bon format","Erreur",JOptionPane.ERROR_MESSAGE);
}
}
}
catch (FileNotFoundException f) {
JOptionPane.showMessageDialog(fenetre, "Le fichier de sommets sélectionné en entrée n'existe pas !","Erreur",JOptionPane.ERROR_MESSAGE);
f.printStackTrace();
}
catch (NumberFormatException f) {
JOptionPane.showMessageDialog(fenetre, "Le fichier de sommets que vous avez soumis en entrée n'est pas au bon format","Erreur",JOptionPane.ERROR_MESSAGE);
}
catch (IOException f) {
JOptionPane.showMessageDialog(fenetre, "Problème d'entrée/sortie","Erreur",JOptionPane.ERROR_MESSAGE);
} catch (InterruptedException f) {
// TODO Auto-generated catch block
f.printStackTrace();
} catch (ExecutionException f) {
// TODO Auto-generated catch block
f.printStackTrace();
}
if (importOk) {
}
}
}
}
} |
Partager