Пример #1
0
        private void DessinObjets_MouseUp(object sender, MouseEventArgs e)
        {
            if (this.Bounds.Contains((e.Location)))
            {
                if (dessinTrait)
                {
                    if (noeudCourant != null)
                    {
                        #region Création d'une arête
                        Point pointInModel = ScreenToModel(e.Location);
                        Noeud fin = TrouveNoeudCourant(pointInModel);
                        Action subAction = null;
                        if (fin == null)
                        {
                            fin = NoeudParDéfaut(pointInModel, Option.Type_schéma);
                            subAction = new Action(Type_Action.Créer, new List<object>() { fin });
                        }
                        Trait trait = null;
                        Trait trait_1 = null;
                        if (fin != null)
                        {
                            switch (Option.Type_schéma)
                            {
                                case TypeSchéma.Graphe:
                                    trait = new Trait(noeudCourant, fin, option.Couleur_Lien, option.Épaisseur_Lien);
                                    break;
                                case TypeSchéma.Relationnel:
                                    trait = new Contrainte(noeudCourant, fin, option.Couleur_Lien, option.Épaisseur_Lien);                  
                                    EditionContrainte pa = new EditionContrainte((Contrainte)trait, (Relation)noeudCourant, (Relation)fin);
                                    pa.ShowDialog();
                                    break;
                                case TypeSchéma.EntitéAssociation:
                                    
                                    if (noeudCourant.GetType() != typeof(Association) && fin.GetType() != typeof(Association))
                                    {
                                        Point pos = new Point(Math.Abs(noeudCourant.Position.X + fin.Position.X)/2, Math.Abs(noeudCourant.Position.Y + fin.Position.Y)/2);
                                        Association asso = new Association(pos, new Size(8, 8), option.Couleur_Lien, option.Épaisseur_Lien, (Entité)noeudCourant, (Entité)fin);

                                        trait = new Lien(noeudCourant, asso, option.Couleur_Lien, option.Épaisseur_Lien);
                                        trait_1 = new Lien(asso, fin, option.Couleur_Lien, option.Épaisseur_Lien);

                                        asso.LienSource = (Lien)trait;
                                        asso.LienDestination = (Lien)trait_1;

                                        EditionAssociation eA = new EditionAssociation(asso);

                                        if (eA.ShowDialog() == DialogResult.OK)
                                        {
                                            noeuds.Add(asso);
                                        }
                                        else
                                        {
                                            trait = null; //si on clique sur annuler, on ne veut plus ajouter le lien
                                            trait_1 = null;
                                        }
                                    }
                                    break;
                            }
                        }
                        if (trait_1 != null)
                        {
                            traits.Add(trait_1);
                            Action action = new Action(Type_Action.Créer, new List<object>() { trait_1 });
                            PushUndo(action);
                            if (subAction != null)
                                action.AddSubAction(subAction);
                        }
                        if (trait != null)
                        {
                            traits.Add(trait);
                            Action action = new Action(Type_Action.Créer, new List<object>() { trait });
                            PushUndo(action);
                            if (subAction != null)
                                action.AddSubAction(subAction);
                        }
                        pointCourant = Point.Empty;
                        Refresh();
                        dessinTrait = false;
                        #endregion
                    }
                }
                else
                {
                    #region Déplacement
                    Point pointInModel = ScreenToModel(e.Location);
                    if (Déplacement_Simple)
                    {
                        #region Mode modification
                        if (noeudCourant != null)
                        {
                            noeudCourant.Déplace(pointInModel);
                            PushUndo(new Action(Type_Action.Déplacer, new List<object>() { noeudCourant, origineDéplacement, pointInModel }));
                        }
                        #endregion
                    }
                    else
                    {
                        if (sélection != Rectangle.Empty)
                        {
                            if (DéplacementMultipleEncours)
                            {
                                #region Déplacement_Bloc
                                Action act = new Action(Type_Action.EnBloc, new List<object>());
                                foreach (Noeud n in noeuds)
                                {
                                    if (n.IsSelected)
                                    {
                                        Point offset = new Point(e.Location.X - StartBlockMovement.X, e.Location.Y - StartBlockMovement.Y);
                                        n.DéplaceVers(offset);
                                        Point offsetGlobal = new Point(e.Location.X - origineDéplacement.X, e.Location.Y - origineDéplacement.Y);
                                        Action ac = new Action(Type_Action.EnBloc, new List<object>() { n, offsetGlobal });
                                        act.AddSubAction(ac);
                                    }
                                }
                                PushUndo(act);
                                annulerToolStripMenuItem.Enabled = true;
                                sélection = new Rectangle(sélection.X + e.Location.X - StartBlockMovement.X, sélection.Y + e.Location.Y - StartBlockMovement.Y, sélection.Width, sélection.Height);
                                StartBlockMovement = e.Location;
                                #endregion
                            }
                            else
                            {
                            }
                        }
                    }
                    #endregion
                }
                Déplacement_Simple = false;
            }
            else
            {
                pointCourant = Point.Empty;
                Refresh();
            }
        }
Пример #2
0
 private void Supprime(Trait trait)
 {
     trait.Supprime();
     //traits.Remove(trait);
 }
Пример #3
0
 private void DessinObjets_MouseDown(object sender, MouseEventArgs e)
 {
     #region Mode sélection multiple activé
     if (sélection != Rectangle.Empty)
     {
         if (sélection.Contains(e.Location))
         {
             DéplacementMultipleEncours = true;
             StartBlockMovement = e.Location;
             origineDéplacement = e.Location;
             return;
         }
         else
         {
             sélection = Rectangle.Empty;
             DéplacementMultipleEncours = false;
         }
     }
     #endregion
     #region Recherche éléments courant
     Point pointInModel = ScreenToModel(e.Location);
     // Vérifier que le point convient
     if (!Screen.PrimaryScreen.Bounds.Contains(e.Location))
         return;
     noeudCourant = TrouveNoeudCourant(pointInModel);
     traitCourant = TrouveTraitCourant(e.Location);
     #endregion
     if (e.Button == MouseButtons.Right)
     {
         #region Bouton droit
         if (noeudCourant != null)
         {
             List<string> libellés = new List<string>() { "Supprimer", "_", "Modifier" };
             switch (noeudCourant.GetType().Name)
             {
                 case "Noeud":
                     break;
                 case "Relation":
                     libellés.Add("Editer la relation");
                     break;
                 case "Entité":
                     libellés.Add("Editer l'entité");
                     break;
                 case "Association":
                     libellés.Add("Editer l'association");
                     break;
             }
             ContextMenuStrip cm = new ContextMenuStrip();
             foreach (string t in libellés)
             {
                 if (t == "_")
                     cm.Items.Add(new ToolStripSeparator());
                 else
                 {
                     ToolStripMenuItem suppr = new ToolStripMenuItem(t);
                     suppr.Click += new EventHandler(traitementMenu_Click);
                     cm.Items.Add(suppr);
                 }
             }
             System.Diagnostics.Trace.WriteLine(noeudCourant);
             cm.Show(this, e.Location);
         }
         else if (traitCourant != null)
         {
             switch (traitCourant.GetType().Name)
             {
                 case "Contrainte":
                     EditionContrainte co = new EditionContrainte((Contrainte)traitCourant, (Relation)traitCourant.Source, (Relation)traitCourant.Destination);
                     co.ShowDialog();
                     break;
                 case "Lien":
                     EditionLien eL = new EditionLien((Lien)traitCourant);
                     eL.ShowDialog();
                     break;
                 default:
                     Parametres pa = new Parametres(traitCourant, false);
                     pa.ShowDialog();
                     break;
             }
             Refresh();
         }
         else
         {
             Parametres pa = new Parametres(this.option, useCustomDialog);
             pa.ShowDialog();
             Refresh();
         }
         #endregion
     }
     else if (e.Button == MouseButtons.Left)
     {
         #region Bouton gauche
         if (déplacement.Checked)
         {
             if (noeudCourant != null)
             {
                 #region Déplacement Simple
                 Déplacement_Simple = true;
                 origineDéplacement = pointInModel;
                 StartBlockMovement = e.Location;
                 #endregion
             }
             else
             {
                 #region Déplacement multiple
                 if (sélection != Rectangle.Empty)
                 {
                     if (sélection.Contains(e.Location))
                     {
                         selectedNodes = new List<Noeud>();
                     }
                 }
                 else
                 {
                     sélection = new Rectangle(e.Location, new Size(0, 0));
                     selectedNodes = new List<Noeud>();
                 }
                 #endregion
             }
         }
         else
         {
             #region mode dessin
             if (noeudCourant == null)
             {
                 Noeud nouv = null;
                 nouv = NoeudParDéfaut(pointInModel, Option.Type_schéma);
                 if (nouv != null)
                 {
                     PushUndo(new Action(Type_Action.Créer, new List<object>() { nouv }));
                 }
             }
             else
             { dessinTrait = true; }
             #endregion
         }
         Refresh();
         #endregion
     }
 }