IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

program qui utlise quick graph


Sujet :

C#

  1. #1
    Membre du Club
    Inscrit en
    Juin 2010
    Messages
    151
    Détails du profil
    Informations forums :
    Inscription : Juin 2010
    Messages : 151
    Points : 43
    Points
    43
    Par défaut program qui utlise quick graph
    salut je cherche un programme qui utlise quick graph pour lire des data à partir d'un fichier texte et afficher le graphe (edges,nodes)avec gestion automatique des layout...aussi jai téléchargé l'outils quick graph en un .rar mais je ne sait pas comment l'installer??

  2. #2
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 442
    Points
    4 442
    Par défaut quickgraph,msglee
    bonjour
    Pour la visualisation graphique tu dois egalement comme dit dans le site codeplex telecharger MS GLEE gratuit (controle graphique) sur le site microsoft suivant :
    http://research.microsoft.com/en-us/...5/default.aspx

    Pour l'utilisation de QuickGraph je peux te donner des exemples d'utilisation des algo graphes (plus court chemin,floyd-wrashall,djiskra ..).
    Pour l'integration du controle MS GLEE avec QuickGraph egalement
    mais mais ....en vb.net (pas grande difference avec c# ).
    A toi de voir....

  3. #3
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 442
    Points
    4 442
    Par défaut quickgraph,msglee
    rebonjour
    je viens de lire ta reponse .Laisse de cote les sources .
    Dezippe simplement les binaries (si tu as telecharge les binaries ) dans un dossier de travail mettons- QuickGraph - pour pouvoir les referencer par la suite puisque c'est une API .
    Pour MS GLEE c'est une API egalement mais avec un setup ,tu l'installes dans un dossier de travail mettons- MS GLEE -pour pouvoir le referencer par la suite puisque c'est aussi API .
    A propos une API s'installe simplement en la copiant dans un dossier.

    A propos egalement QuickGraph ne dispose pas d'aide .Seul le forum de codeplex donnes quelques exemples .
    J'attends ta reaction....
    Bon code...

  4. #4
    Membre du Club
    Inscrit en
    Juin 2010
    Messages
    151
    Détails du profil
    Informations forums :
    Inscription : Juin 2010
    Messages : 151
    Points : 43
    Points
    43
    Par défaut
    rebonjour MABROUKI,
    en fait pour le MSGLEE jai pas trouvé un lien de téléchargement du setup deja le lien que tu m'a donné est mort aparament :\
    pour le quick graph bon jai dézipé le fichier et jai fait comme tu m'a dit mais ma question est:comment je vais utlisé cette API apres dans mon code?c'est à dire est ce que je l'appelle avec un include?et dans ce cas j'ecris include quoi?.excuse moi peut etre mes questions semblent banales

  5. #5
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 442
    Points
    4 442
    Par défaut Utilisation lib quickgraph et controle ms glee
    rebonjour
    voici le lien MS GLEE directement sur google:
    http://www.google.fr/url?sa=t&source...BsjJIP_w3Y95qw

    Et voici un exemple de code en c# que j'ai retranscrit de vb.net pour toi.
    c'est une appli qui lit un fichier texte delimite (ci-joint) ,execute sur le graphe decrit dans le fichier l'algo BreadFirstSeach classique(exploration en largeur d'abord) et l'affiche dans controle GViewer :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
     
    // 1 -AJOUTER REFERENCE DANS DOSSIER QuickGraph à:
    //- QuickGraph.dll.dll
    //- QuickGraph.Data.dll
    //- QuickGraph.Glee.dll
    //
    // 2 -AJOUTER REFERENCE DANS DANS DOSSIER du controle MS GLEE:
    //- Microsoft.GLEE.dll
    //- Microsoft.GLEE.Drawing.dll
    //- Microsoft.GLEE.GraphViewerGDI.dll
    // 3-BOITE À OUTILS ->CHOISIR ELEMENTS->PARCOURIR dossier MS GLEE
    // &  SELECTIONNER FICHIER Microsoft.GLEE.GraphViewerGDI.dll
    // 4-AJOUTER LES CONTROLES Bouton,un OpenDialog et un TextBox et GViewer
    // 
    // 5-NB: j'ai utilise la fonction utilitaire toute prete  Microsoft.VisualBasic.FileIO.TextFieldParser 
    // qui permet de parser un fichier texte delimited avec un delimter au choix.   
    // libre à vous d'utiliser d'autres API si possible en C#
    //
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Globalization;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    //AJOUTER UNE REFERENCE AU FICHIER Microsoft.VisualBasic.dll
    using Microsoft.VisualBasic;
    //USINGS DE  QUICKGRAPH
    using QuickGraph;
    using  QuickGraph.Algorithms;
    // USING DE  QUICKGRAPH POUR LIAISON AVEC  MS GLEE 
    using QuickGraph.Glee;
     
    //USINGS MICROSOFT MS GLEE
    using Microsoft.Glee;
    using Microsoft.Glee.Drawing;
    using Microsoft.Glee.Splines;
    using P = Microsoft.Glee.Splines.Point;
     
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            // VARIABLES POUR LIRE CLASSE ARC ET LISTE ARCS
            //---------------------------------------------
            public Arc monArc = new Arc();
            public List<Arc> lstArcs = new List<Arc>();
     
            //DESCRIPTION DU GRAPHE
            //---------------------
            // GRAPHE D'ADJACENCE SIMPLE TYPE QuickGraph
            AdjacencyGraph<string, Edge<string>> monGraph;
            // ARC  DU GRAPHE
            QuickGraph.Edge<string> arcGraphe;
            //"COUT ARC"  DE TYPE DICTIONNAIRE (ARCGRAPH,LONGUEUR)
            public Dictionary<Edge<string>, Double> coutArc = new Dictionary<Edge<string>, Double>();
     
     
            //EXPLORATION DU GRAPHE
            //--------------------
            // ALGORITHME TYPE "BFS"
            QuickGraph.Algorithms.Search.BreadthFirstSearchAlgorithm<string, QuickGraph.Edge<string>> monBFS;
            //"SOMMET OBSERVATEUR" (CHEMIN D'EXPLORATION SOMMET)
            QuickGraph.Algorithms.Observers.VertexPredecessorRecorderObserver<string, QuickGraph.Edge<String>> predecessorObserverSommet;
            //"ARC OBSERVATEUR" (CHEMIN D'EXPLORATION ARC)
            QuickGraph.Algorithms.Observers.EdgeRecorderObserver<string, QuickGraph.Edge<String>> predecessorObserverArc;
            //"OBSERVATEUR DISTANCE" (LONGUEUR DU CHEMIN EXPLORE)
            QuickGraph.Algorithms.Observers.VertexDistanceRecorderObserver<string, QuickGraph.Edge<string>> distObserver;
     
            //VISUALISATION GRAPHIQUE
            //-----------------------
            //"GRAPHE VISUEL"  TYPE MS GLEE
            Microsoft.Glee.Drawing.Graph grapheVisuel;
            public Form1()
            {
                InitializeComponent();
            }
            //'obtient le nom de fichier texte contenant les donnees du graphe
            private void btnFichierArcs_Click(object sender, EventArgs e)
            {
     
                string nomFichierArcs = "";
                OpenFileDialog dlgOuvreFichier = new OpenFileDialog();
                dlgOuvreFichier.Filter = "Fichier Arcs(*.txt)|*.txt";
                if (dlgOuvreFichier.ShowDialog() == DialogResult.OK)
                {
     
                    nomFichierArcs = dlgOuvreFichier.SafeFileName;
                    if (nomFichierArcs == null)
                    {
     
                        MessageBox.Show("entrer un nom de fichier svp...");
                        return;
                    }
                    LitFichierGraphe(nomFichierArcs,monArc,lstArcs);
                    AfficheGraphe();
     
                }
            }
     
            //Cree le Graphe & l'affiche  avec le controle Gviewer ( lib MS GLEE )  
            private void AfficheGraphe()
            {
            //Peuple  le "graphe" à partir des donnes arcs
            monGraph = new AdjacencyGraph<string, QuickGraph.Edge<string>>();
            coutArc = new Dictionary<Edge<string>, double>(monGraph.EdgeCount);
            Peupler_Graphe(monGraph);
     
            //Initialise  Algo BFS 
            monBFS = new QuickGraph.Algorithms.Search.BreadthFirstSearchAlgorithm<string, QuickGraph.Edge<string>>(monGraph);
            predecessorObserverSommet=new  QuickGraph.Algorithms.Observers.VertexPredecessorRecorderObserver<string, QuickGraph.Edge<String>>();
            predecessorObserverSommet.Attach(monBFS);
            predecessorObserverArc = new QuickGraph.Algorithms.Observers.EdgeRecorderObserver<string, QuickGraph.Edge<String>>();
            predecessorObserverArc.Attach(monBFS);
            distObserver = new QuickGraph.Algorithms.Observers.VertexDistanceRecorderObserver<string, QuickGraph.Edge<string>>(QuickGraph.Algorithms.AlgorithmExtensions.GetIndexer(coutArc));
            distObserver.Attach(monBFS);
            //Execute Algo "BFS" avec  noeud "SOURCE" comme racine
            monBFS.Compute("SOURCE");
            //Liaison avec le controle graphe GVIEWER MS GLEE se fait 
            //avec la classe "populator de QuickGraph" comme suit:
     
            QuickGraph.Glee.GleeGraphPopulator<string, QuickGraph.Edge<string>>
            populator = QuickGraph.Glee.GleeGraphExtensions.CreateGleePopulator(monGraph);
     
            //2 Hooks (abonnements) aux evenements populator_NodeAdded & populator_EdgeAdded pour personnaliser l'affichage des Noeuds et Arcs du graphe
                try
                {
                    populator.NodeAdded += new QuickGraph.Glee.GleeVertexNodeEventHandler<string>(populator_NodeAdded);
                    populator.EdgeAdded += new QuickGraph.Glee.GleeEdgeEventHandler<string, Edge<string>>(populator_EdgeAdded);
                    populator.Compute();
                }
                finally
                {
                    populator.NodeAdded += new QuickGraph.Glee.GleeVertexNodeEventHandler<string>(populator_NodeAdded);
                    populator.EdgeAdded += new QuickGraph.Glee.GleeEdgeEventHandler<string, Edge<string>>(populator_EdgeAdded);
                }
            //Obtient un graphe visuel  pour  MS GLEE
            grapheVisuel = populator.VisitedGraph.ToGleeGraph(populator_NodeAdded, populator_EdgeAdded);
     
            //Ajuste le controle Gviewer
            //active options  Sauvegarde & Scroll
            GViewer1.SaveButtonVisible = true;
            GViewer1.AutoScroll = true;
     
            //Affiche le "graphe visuel" dans Gviewer
            GViewer1.Graph = grapheVisuel;
     
            //Affiche en plus une simple liste des Noeuds et Arcs 
            //du Chemin BFS dans TextBox1
            AfficheCheminGraphVisite();
     
     
            }
            // PROC :Peupler_Graphe
            // QUI VA AJOUTER LES ARCS LUS DANS LA SIMPLE liste lstArcs
            // À LA STRUCTURE Graphe monGraphe 
            private void Peupler_Graphe(AdjacencyGraph<string, Edge<string>> GrapheCourant)
            { 
                foreach(Arc elem  in lstArcs)
                {
                //Ajoute Sommets et Arcs au graphe
                arcGraphe = new QuickGraph.Edge<string>(elem.premNoeud, elem.deuxNoeud);
                GrapheCourant.AddVerticesAndEdge(arcGraphe);
                //Ajoute "cout arc" au Dictionnaire "coutArc" associe (ici des distances entre arcs)
                coutArc.Add(arcGraphe,elem.Longueur);
                }
            }
            // HANDLER : populator_NodeAdded
             private void populator_NodeAdded(object  sender, QuickGraph.Glee.GleeVertexEventArgs<string> e)
            {
                 // changer ici l'aparence des Vertex (noeuds  "graphiques" de ms GLEE) 
                Microsoft.Glee.Drawing.Style NoeudStyle = new Microsoft.Glee.Drawing.Style();
                NoeudStyle = Microsoft.Glee.Drawing.Style.Rounded;
                Microsoft.Glee.Drawing.Node noeudGlee   = e.Node;
                string nomNoeud  = e.Vertex;
                if (nomNoeud == "SOURCE")
                {
                    noeudGlee.Attr.Color = Microsoft.Glee.Drawing.Color.Black;
                    noeudGlee.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Yellow;
                    noeudGlee.Attr.LineWidth = 2;
                    noeudGlee.Attr.Shape = Microsoft.Glee.Drawing.Shape.Box;
                    noeudGlee.Attr.AddStyle(NoeudStyle);
                    noeudGlee.Attr.FontName = "VERDANA";
                    noeudGlee.Attr.Fontcolor = Microsoft.Glee.Drawing.Color.Red;
                    noeudGlee.Attr.FontName = "Arial";
                    noeudGlee.Attr.Fontsize = 10;
                    noeudGlee.Attr.Label = "Racine: " + nomNoeud;
                }
                else
                {
                    noeudGlee.Attr.Color = Microsoft.Glee.Drawing.Color.Black;
                    noeudGlee.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.GreenYellow;
                    noeudGlee.Attr.LineWidth = 1;
                    noeudGlee.Attr.Shape = Microsoft.Glee.Drawing.Shape.Box;
                    noeudGlee.Attr.AddStyle(NoeudStyle);
                    noeudGlee.Attr.Fontcolor = Microsoft.Glee.Drawing.Color.Black;
                    noeudGlee.Attr.FontName = "Times New Roman";
                    noeudGlee.Attr.Fontsize = 8;
                    noeudGlee.Attr.Label = nomNoeud;
                }
     
             }
             // HANDLER : populator_EdgeAdded
            private void populator_EdgeAdded(object  sender, QuickGraph.Glee.GleeEdgeEventArgs<string, Edge<string>> e)
             {
             // changer ici l'aparence des Edges (arcs "graphiques" de ms GLEE) 
             // du premier arc au dernier
                int numOrderVisite;
                Microsoft.Glee.Drawing.Style arcStyle;
                Microsoft.Glee.Drawing.Edge arcGlee = e.GEdge;
     
                arcGlee.Attr.Color = Microsoft.Glee.Drawing.Color.Blue;
                arcGlee.Attr.LineWidth = 1;
                arcStyle = Microsoft.Glee.Drawing.Style.Dashed;
                arcGlee.Attr.AddStyle(arcStyle);
                arcGlee.Attr.FontName = "Verdana";
                arcGlee.Attr.Fontsize = 8;
                arcGlee.Attr.Fontcolor = Microsoft.Glee.Drawing.Color.Red;
                arcGlee.Attr.Label = "non visite";
                //si  un arc dans  liste de predecessorObserverArc 
                //changer sa couleur("arc dans arbre BFS explore")
     
                if (predecessorObserverArc.Edges.Contains(e.Edge))
                {
                    numOrderVisite = predecessorObserverArc.Edges.IndexOf(e.Edge) + 1;
                    arcGlee.Attr.Color = Microsoft.Glee.Drawing.Color.Black;
                    arcGlee.Attr.ClearStyles();
                    arcStyle = Microsoft.Glee.Drawing.Style.Solid;
                    arcGlee.Attr.AddStyle(arcStyle);
                    arcGlee.Attr.LineWidth = 3;
                    double cout = 0.0;
                    coutArc.TryGetValue(e.Edge, out  cout);
                    double totalDist = 0.0;
                    distObserver.Distances.TryGetValue(e.Edge.Target, out totalDist);
                    arcGlee.Attr.Label = "cout arc :" + cout.ToString() + Environment.NewLine;
                    arcGlee.Attr.Label = arcGlee.Attr.Label + " ordre visite:" + numOrderVisite.ToString() +
                    " distance :" + totalDist.ToString();
                }
     
             }
            //PROC  : AfficheCheminGraphVisite 
            //LISTE LES ARCS VISITES DANS UN TEXTBOX
            private void   AfficheCheminGraphVisite()
            {
            //comptage des  noeuds et arcs du "graphe visite" 
                this.textBox1.ForeColor =System.Drawing.Color.DarkOliveGreen;
                this.textBox1.Font = new Font("Courier New", 10, FontStyle.Bold);
                this.textBox1.Text = "nombre Noeuds :" + (predecessorObserverSommet.VertexPredecessors.Count + 1).ToString() + Environment.NewLine;
                this.textBox1.Text = textBox1.Text + "nombre Arcs :" + (predecessorObserverArc.Edges.Count).ToString() + Environment.NewLine;
            //Affiche  Liste  des "arcs visites ordonnes"
            foreach ( QuickGraph.Edge<string> cheminArc  in predecessorObserverArc.Edges)
                {
                    double totalDist = 0.0;
                    distObserver.Distances.TryGetValue(cheminArc.Target, out totalDist);
                    this.textBox1.Text = textBox1.Text + cheminArc.Source + " -" + cheminArc.Target + " - " + totalDist.ToString() + Environment.NewLine; 
                }
     
           }
     
            //PROC  : LitFichierGraphe
            //LIT LE FICHIER TEXTE ET CHARGE DONNEES GRAPHE
            private void LitFichierGraphe( string nomFichierArcs,Arc monArc,List<Arc> lstArcs )
            {
                Microsoft.VisualBasic.FileIO.TextFieldParser MyReader = new
                Microsoft.VisualBasic.FileIO.TextFieldParser(nomFichierArcs);
                try
                {
                    MyReader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited;
                    MyReader.SetDelimiters(";");
                    string[] currentRow ;
                    while (!MyReader.EndOfData)
                    {
                        try
                        {
                            currentRow = MyReader.ReadFields();
                            monArc = new Arc();
                            for (int i=0 ;i<currentRow.Count();i++ )
                            {
                                switch (i)
                                {
                                    case 0:
                                        monArc.premNoeud=currentRow[i];
                                        break;
                                    case 1:
                                        monArc.deuxNoeud = currentRow[i];
                                        break;
                                    case 2:
                                        monArc.Longueur = double.Parse(currentRow[i]);
                                        break;
                                    default:
                                        break;
                                }
                                lstArcs.Add(monArc);
                            }
                        }
     
                        catch (Microsoft.VisualBasic.FileIO.MalformedLineException ex)
                        {
                              MessageBox.Show("Line " + ex.Message + "is not valid and will be skipped.") ;
                        }
                    }
                }
                finally
                {
                    if (MyReader != null)
                      ((IDisposable)MyReader).Dispose();
                }
            }
        }
    }
     
    //
    // CLASSE ARC MAPPE SUR LE FICHIER VILLES.TXT
    // POUR LIRE ET STOCKER LES DONNEES DANS UNE LISTE 
    // AVANT DE LES LIRE DANS L'API QuickGraph CAR ELLE 
    // NE DISPOSE PAS DE METHODE DE LECTURE ET ECRITURE DIRECTE 
    //
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
     
    namespace WindowsFormsApplication1
    {
        public class Arc
        {
            public String premNoeud ;
            public String deuxNoeud ;
            public Double Longueur ;
            public Arc()
            {
                this.premNoeud = "";
                this.deuxNoeud = "";
                this.Longueur = 0.0;
            }
        }
    }
    Nota Bene : la librairie QuickGraph utilise est la version 3.5
    Sur le forum tous les exemples sont bien traites par des gens de codeplex et en plus en C# et moi j'ai du tout refaire en vb.net.

    bon code....

  6. #6
    Membre du Club
    Inscrit en
    Juin 2010
    Messages
    151
    Détails du profil
    Informations forums :
    Inscription : Juin 2010
    Messages : 151
    Points : 43
    Points
    43
    Par défaut QUick graph 3.5 lien de téléchargement
    salut Mabrouki jai visité le site http://http://quickgraph.codeplex.co...ses/view/55262 et j ai pas trouvé un lien de téléchargement de quick graph v 3.5 si tu as un lien merci de me le transmettre

  7. #7
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 442
    Points
    4 442
    Par défaut quickgraph pour net framework 3.5
    bonjour massaab
    c'est un lapsus ,excuse moi je voulais dire la version binary pour Net FrameWork 3.5 ce qui permet la programmation avec WPF.
    Parce qu' il existe egalement une version CodePlex pour Net FrameWork 2.0 pour les WinForms & une version pour SilverLight.

    lien direct page codeplex:
    http://quickgraph.codeplex.com/releases/view/20160


    lien google:http://www.google.fr/url?sa=t&source...Usk8YYrelJa08w
    bon code....

  8. #8
    Membre du Club
    Inscrit en
    Juin 2010
    Messages
    151
    Détails du profil
    Informations forums :
    Inscription : Juin 2010
    Messages : 151
    Points : 43
    Points
    43
    Par défaut sample GLLEE
    Salut mabrouki

    Vraiment j'aimerais te remercier pour ton aide
    J'ai installé MS GLEE et lorsque j'ai vu les samples qu'il contient j'ai trouvé un exemple qui me convient vraiment. C'est l'interface qui affiche un graphe et permet de faire le zoom et tout.
    C'est bon exemple et sa m'aide énormément sauf que il faut que je lise les nodes à partir d'un fichier texte et non pas directement comme c'est fait dans l'exemple.
    Alors je me demandais si tu pourrais m'aider à faire ce changement

    Merci

  9. #9
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 442
    Points
    4 442
    Par défaut lecture et affichage graphe par MS GLEE
    Bonjour Masmeta
    Voici un exemple de code d'utilisation de MS GLEE consistant à lire les arcs à partir du meme fichier texte (villes.txt) et à les afficher simplent sur le controle GVIEWER:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
     
    //MS GLEE DISPOSE EGALEMENT D'UNE STRUCTURE GRAPHE PROPRE 
    //COMME CELLE DE QUICKGRAPHE MAIS DEDIE UNIQUEMENT AU STOCKAGE
    //EN MEMOIRE DES DONNEES GRAPHES (arc,noeud source,noeud destination,attributs de dessin)
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    //AJOUTER UNE REFERENCE AU FICHIER Microsoft.VisualBasic.dll
    using Microsoft.VisualBasic;
    //USINGS MICROSOFT MS GLEE
    using OD=Microsoft.Glee.Drawing;
     
    namespace WinTestGLEE
    {
        public partial class Form1 : Form
        {
     
            // VARIABLES POUR LIRE CLASSE ARC ET LISTE ARCS
            //---------------------------------------------
            public Arc monArc = new Arc();
            public List<Arc> lstArcs = new List<Arc>();
            // VARIABLES HOMOLOGUES DANS LE GRAPHE MS GLEE
            //-------------------------------------------------
            public OD.Graph objGraphe;
            public OD.Edge objArc ;
            public OD.Node objNode  ;
     
            public Form1()
            {
                InitializeComponent();
            }
     
            //'obtient le nom de fichier texte contenant les donnees du graphe
            private void btnFichierArcs_Click(object sender, EventArgs e)
            {
     
                string nomFichierArcs = "";
                OpenFileDialog dlgOuvreFichier = new OpenFileDialog();
                dlgOuvreFichier.Filter = "Fichier Arcs(*.txt)|*.txt";
                if (dlgOuvreFichier.ShowDialog() == DialogResult.OK)
                {
     
                    nomFichierArcs = dlgOuvreFichier.SafeFileName;
                    if (nomFichierArcs == null)
                    {
                        MessageBox.Show("entrer un nom de fichier svp...");
                        return;
                    }
                    //Lit les donnees dans lstArcs
                    LitFichierGraphe(nomFichierArcs, monArc, lstArcs);
                    //Genere le Graphe GLEE à partir de lstArcs
                    objGraphe = GenereGrapheGlee();
                    //AFFICHE le Graphe GLEE
                    AfficheGrapheGlee(objGraphe);
                }
            }
            //PROC GENERE  Graphe GLEE
            private OD.Graph GenereGrapheGlee()
            {
                //idGraph identifie le graphe si on en charge plusieurs.
                string idGraph = "01";
                objGraphe = new OD.Graph("Masmeta", idGraph);
                OD.ArrowStyle styleFleche;
                styleFleche=OD.ArrowStyle.Normal;
     
                foreach (Arc elem in lstArcs)
                {
                    objArc=(OD.Edge)  objGraphe.AddEdge(elem.premNoeud, elem.deuxNoeud);
                    //attributs dessin de cet arc
                    objArc.Attr.Color = OD.Color.Blue;
                    objArc.Attr.LineWidth = 2;
                    objArc.Attr.Weight = 5;
                    //attributs dessin des nodes source et destination
                    objArc.SourceNode.Attr.Shape =OD.Shape.Box;
                    objArc.SourceNode.Attr.Label = elem.premNoeud;
                    objArc.SourceNode.Attr.Fontcolor = OD.Color.Yellow;
                    objArc.SourceNode.Attr.Fillcolor = OD.Color.YellowGreen;
                    objArc.TargetNode.Attr.Shape = OD.Shape.Box;
                    objArc.TargetNode.Attr.Label = elem.deuxNoeud;
                    objArc.SourceNode.Attr.Fontcolor = OD.Color.Yellow; 
                    objArc.TargetNode.Attr.Fillcolor = OD.Color.YellowGreen;
                }
                return objGraphe;
            }
             //PROC GENERE  Graphe GLEE
            private void AfficheGrapheGlee(OD.Graph objGraphe)
            {
                gViewer1.Graph = objGraphe; 
            }
            //PROC  : LitFichierGraphe
            //LIT LE FICHIER TEXTE ET CHARGE DONNEES GRAPHE
            private void LitFichierGraphe( string nomFichierArcs,Arc monArc,List<Arc> lstArcs )
            {
                Microsoft.VisualBasic.FileIO.TextFieldParser MyReader = new
                Microsoft.VisualBasic.FileIO.TextFieldParser(nomFichierArcs);
                try
                {
                    MyReader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited;
                    MyReader.SetDelimiters(";");
                    string[] currentRow ;
                    while (!MyReader.EndOfData)
                    {
                        try
                        {
                            currentRow = MyReader.ReadFields();
                            monArc = new Arc();
                            for (int i=0 ;i<currentRow.Count();i++ )
                            {
                                switch (i)
                                {
                                    case 0:
                                        monArc.premNoeud=currentRow[i];
                                        break;
                                    case 1:
                                        monArc.deuxNoeud = currentRow[i];
                                        break;
                                    case 2:
                                        monArc.Longueur = double.Parse(currentRow[i]);
                                        break;
                                    default:
                                        break;
                                }
                             }
                            //CETT LIGNE SE TROUVE ICI 
                            //RECTIFIE LA DANS LA PROC DU 1ER POST (mal place)  
                            lstArcs.Add(monArc);
                        }
     
                        catch (Microsoft.VisualBasic.FileIO.MalformedLineException ex)
                        {
                              MessageBox.Show("Line " + ex.Message + "is not valid and will be skipped.") ;
                        }
                    }
                }
                finally
                {
                    if (MyReader != null)
                      ((IDisposable)MyReader).Dispose();
                }
            }
     
        }
    }
    nb:j'utilise toujours Microsoft.VisualBasic.FileIO.TextFieldParser pour des raisons de commodite car en c# il faut reinventer la roue pour lire un fichier texte .csv.
    bon code....

  10. #10
    Membre du Club
    Inscrit en
    Juin 2010
    Messages
    151
    Détails du profil
    Informations forums :
    Inscription : Juin 2010
    Messages : 151
    Points : 43
    Points
    43
    Par défaut
    merci Mabrouki,jai une question débile:pour pouvoir générer le exe de ce code il fallait d'abord creer un projet sur vs (j'ai vs2008).Je me plante dans quel type de projet je doit creer visual c# windows form application,WPF appli...

  11. #11
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 442
    Points
    4 442
    Par défaut WindowsFormsApplication
    bonjour
    un simple projet WindowsFormsApplication.
    bon code...

Discussions similaires

  1. [Dev-Pascal] Problème avec l'unité Graph (2 fenêtres et ReadKey qui ne fonctionne pas)
    Par Van der Elst dans le forum Autres IDE
    Réponses: 10
    Dernier message: 01/06/2006, 07h49
  2. Utlisation d'image pour les <li> qui ne marche pas
    Par Death83 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 2
    Dernier message: 05/11/2005, 17h37

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo