private void newEx() { l1.Enabled = l2.Enabled = l3.Enabled = l4.Enabled = true; string r1, r2, r3, r4; Repere.Show(); Repere.Controls.Clear(); Dessin.DonnerValeur(); Dessin.DonnerChoix(Dessin.AireRectangle.ToString(), out r1, out r2, out r3, out r4); Repere.CellPaint += tableLayoutPanel1_CellPaint; l1.Text = r1; l2.Text = r2; l3.Text = r3; l4.Text = r4; Label label1 = new Label(); Label label2 = new Label(); label1.Text = (Dessin.rectangleWidth.ToString()); label1.BackColor = Color.Transparent; label2.BackColor = Color.Transparent; label2.Text = (Dessin.rectangleHeight.ToString()); Repere.Controls.Add(label1, Dessin.initColumn + 1 + (Dessin.rectangleWidth) / 2, Dessin.initRow + Dessin.rectangleHeight + 1); Repere.Controls.Add(label2, Dessin.initColumn + Dessin.rectangleWidth + 1, Dessin.initRow + 1 + (Dessin.rectangleHeight) / 2); Repere.Refresh(); }
private void Form1_KeyUp(object sender, KeyEventArgs e) { if (TraceEnCours) { if (e.KeyValue == (int)Keys.Escape) { TraceEnCours = false; NbClic = 0; Dessin.RemoveAt(ItemEnCours--); pnlBoard.Refresh(); } else if (e.KeyValue == (int)Keys.Enter) { TracerDroit(ItemEnCours); TraceEnCours = false; NbClic = 0; } } if (e.KeyValue == (int)Keys.Delete) { Dessin.RemoveAll(t => t.EstSelectionne); ItemEnCours = Dessin.Count() - 1; NbClic = 0; pnlBoard.Refresh(); } Ajout = e.Control; }
private void pnlBoard_MouseDown(object sender, MouseEventArgs e) { var nbItemSelectionne = Dessin.Where(i => i.EstSelectionne).Count(); var itemEnCours = Dessin.Where(i => i.EstSelectionne && i is Trait && i.HitTest(e.Location)).FirstOrDefault(); if (nbItemSelectionne == 0 || itemEnCours == null) { return; } _maitre = itemEnCours; if (nbItemSelectionne == 1) { //Dimensionnement ? if (itemEnCours.SelectionnerExtremite(e.Location) != Constantes.PosRedim.Aucune) { RedimEnCours = itemEnCours.SelectionnerExtremite(e.Location); RedimensionnementAutorise = true; } //Déplacement else { _positionSouris = e.Location; DeplacementAutorise = true; } } else { //Déplacement _positionSouris = e.Location; DeplacementAutorise = true; } }
private void Form1_Load(object sender, EventArgs e) { initPicture(); ds = new Dessin(pictureDesign); ds.color_line = Brushes.White; ds.color_circle = Color.White; BtnHote.PerformClick(); }
private void btnNouveau_Click(object sender, EventArgs e) { Dessin.Clear(); ItemEnCours = -1; pnlBoard.Invalidate(); OutilEnCours = Outils.Main; }
public Properties(Dessin Des) { InitializeComponent(); NewDessin = Des; txtName.Text = NewDessin.Nom; txtPrice.Text = NewDessin.Cost.ToString(); txtDate.Text = NewDessin.DateCreation.ToShortDateString(); txtNbrePoints.Text = NewDessin.Coords.Count.ToString(); }
private void Dessin_Paint(object sender, PaintEventArgs e) { nPen.Width = 1; Canvas = Dessin.CreateGraphics(); Canvas.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; for (int i = 0; i < nline; i++) { DrawCanvas(); } }
public ControleurDessin(VuePlancheDessin vue) { this.vuePlancheDessin = vue; // TEST debut Dessin dessin = new Dessin(); Cercle cercle = new Cercle(100, 100, new Forme.Couleur(0, 0, 0)); dessin.ajouterForme(cercle); // TEST fin }
public static Dessin GenererDessin() { Dessin dessin = new Dessin(); dessin.AjouterForme( new Polygone(new List <Point2D>() { new Point2D() { X = -1, Y = -1 }, new Point2D() { X = 1, Y = -1 }, new Point2D() { X = 0, Y = 1 }, } ) ); dessin.AjouterForme( new Polygone(new List <Point2D>() { new Point2D() { X = 0, Y = 0 }, new Point2D() { X = 2, Y = 2 }, new Point2D() { X = 0, Y = 4 }, new Point2D() { X = -2, Y = -2 }, } ) ); dessin.AjouterForme(new Cercle(new Point2D() { X = 0, Y = 0 }, 5)); return(dessin); }
private void btnDraw_Click(object sender, EventArgs e) { //start_x = Dessin.Width * 2 / 3; //start_y = Dessin.Height * 2 / 3; length = int.Parse(txtLength.Text); angle = int.Parse(txtAngle.Text); increment = int.Parse(txtIncr.Text); nline = int.Parse(txtLines.Text); Dessin.Refresh(); }
private void btnSave_Click(object sender, EventArgs e) { bmp = new Bitmap(Dessin.Width, Dessin.Height); Graphics g = Graphics.FromImage(bmp); Rectangle rect = Dessin.RectangleToScreen(Dessin.ClientRectangle); g.CopyFromScreen(rect.Location, Point.Empty, Dessin.Size); string rnd = Path.GetRandomFileName(); bmp.Save(rnd.Substring(0, rnd.LastIndexOf(".")) + ".png"); }
public Dessin LireDepot() { IMapper mapper = CreerOutilConversionDTO2Entity(); string chaineJson = File.ReadAllText(this.m_nomFichier); JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }; DessinJSONDTO dessinDTO = JsonConvert.DeserializeObject <DessinJSONDTO>(chaineJson, settings); Dessin dessin = mapper.Map <Dessin>(dessinDTO); return(dessin); }
public void EnregistrerDessin(Dessin p_dessin) { // Méthode 2 : Bibliothèque automapper IMapper mapper = CreerOutilConversionEntity2DTO(); DessinJSONDTO dessinDTO = mapper.Map <DessinJSONDTO>(p_dessin); JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto, Formatting = Formatting.Indented }; string chaineJson = JsonConvert.SerializeObject(dessinDTO, settings); File.WriteAllText(this.m_nomFichier, chaineJson); }
public static Dessin GenererDessin() { Dessin dessin = new Dessin(); dessin.AjouterForme( new Polygone(new List <Point2D>() { new Point2D() { X = - 1, Y = - 1 }, new Point2D() { X = 1, Y = - 1 }, new Point2D() { X = 0, Y = 1 }, } ) ); dessin.AjouterForme( new Polygone(new List <Point2D>() { new Point2D() { X = 0, Y = 0 }, new Point2D() { X = 2, Y = 2 }, new Point2D() { X = 0, Y = 4 }, new Point2D() { X = - 2, Y = - 2 }, } ) ); dessin.AjouterForme(new Cercle(new Point2D() { X = 0, Y = 0 }, 5)); return dessin; }
public Dessin LireDepot() { IMapper mapper = CreerOutilConversionDTO2Entity(); string chaineJson = File.ReadAllText(this.m_nomFichier); JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }; DessinJSONDTO dessinDTO = JsonConvert.DeserializeObject <DessinJSONDTO>(chaineJson, settings); Dessin dessin = mapper.Map <Dessin>(dessinDTO); return dessin; }
public Dessin LireDepot() { IMapper mapper = CreerOutilConversionDTO2Entity(); XmlReader doc = XmlReader.Create(this.m_nomFichier); XmlSerializer xmlSerializer = new XmlSerializer(typeof(DessinFormatElementsDTO), new Type[] { typeof(PolygoneFormatElementsDTO), typeof(CercleFormatElementsDTO), }); DessinFormatElementsDTO dessinDTO = xmlSerializer.Deserialize(doc) as DessinFormatElementsDTO; Dessin dessin = mapper.Map <Dessin>(dessinDTO); return(dessin); }
private void TracerDroit(int pElement) { var dernierTrait = Dessin.ElementAt(pElement) as Trait; //Vertical if (dernierTrait.Fin.X > (dernierTrait.Depart.X - Constantes.MARGE_TRAIT_DROIT) && dernierTrait.Fin.X < (dernierTrait.Depart.X + Constantes.MARGE_TRAIT_DROIT)) { dernierTrait.Fin = new Point(dernierTrait.Depart.X, dernierTrait.Fin.Y); Cursor.Position = new Point(dernierTrait.Depart.X + EcartX, Cursor.Position.Y); } //Horizontal if (dernierTrait.Fin.Y < (dernierTrait.Depart.Y + Constantes.MARGE_TRAIT_DROIT) && dernierTrait.Fin.Y > (dernierTrait.Depart.Y - Constantes.MARGE_TRAIT_DROIT)) { dernierTrait.Fin = new Point(dernierTrait.Fin.X, dernierTrait.Depart.Y); Cursor.Position = new Point(Cursor.Position.X, dernierTrait.Depart.Y + EcartY); } pnlBoard.Invalidate(); //modif refresh to invalidate }
public Dessin LireDepot() { IMapper mapper = CreerOutilConversionDTO2Entity(); XmlReader doc = XmlReader.Create(this.m_nomFichier); XmlSerializer xmlSerializer = new XmlSerializer(typeof(DessinFormatElementsDTO), new Type[] { typeof(PolygoneFormatElementsDTO), typeof(CercleFormatElementsDTO), }); DessinFormatElementsDTO dessinDTO = xmlSerializer.Deserialize(doc) as DessinFormatElementsDTO; Dessin dessin = mapper.Map <Dessin>(dessinDTO); return dessin; }
static void Main(string[] args) { Dessin dessin = GenererDessin(); string nomFichier = "donnee"; //Path.GetTempFileName(); DepotDessin ddAttributs = new DepotDessinXMLFormatAttributs(nomFichier + "_attributs.xml"); ddAttributs.EnregistrerDessin(dessin); Dessin dessinLuAttributs = ddAttributs.LireDepot(); DepotDessin ddElements = new DepotDessinXMLFormatElements(nomFichier + "_elements.xml"); ddElements.EnregistrerDessin(dessin); Dessin dessinLuElement = ddElements.LireDepot(); DepotDessin ddJSON = new DepotDessinJSON(nomFichier + ".json"); ddJSON.EnregistrerDessin(dessin); Dessin dessinLuJSON = ddJSON.LireDepot(); }
// Fin gestionnaires d'événements // Cas d'exception, dans l'application d'edition avec vue non-rafraichissante on ne stocke pas le modele dans la vue // Generalement, on le fait on stocke le modele complet dans la vue public void afficherDessin(Dessin dessin) { foreach (Forme forme in dessin.listeFormes) // pas public, on passe par le get { switch (forme.type) { case Forme.TYPE_FORME.CERCLE: this.afficherCercle((Cercle)forme); break; case Forme.TYPE_FORME.CARRE: this.afficherCarre((Carre)forme); break; case Forme.TYPE_FORME.TRIANGLE: this.afficherTriangle((Triangle)forme); break; default: break; } } }
public bool UpdateDessin(Dessin dessin) { throw new NotImplementedException(); }
private void pnlBoard_Click(object sender, MouseEventArgs e) { #region Trace d'un trait if (OutilEnCours == Outils.Trait) { NbClic++; var trait = new Trait(string.Format("Trait{0}", Dessin.Where(i => i is Trait).Count() + 1), e.Location, new Point(), ((Couleur)cmbCouleur.SelectedItem).Valeur, (float)nudLargeur.Value); if (NbClic == 1) { TraceEnCours = true; } else { TraceEnCours = false; TracerDroit(ItemEnCours); var traitEnCours = Dessin.ElementAt(ItemEnCours) as Trait; trait.Depart = new Point(traitEnCours.Fin.X - (int)(nudLargeur.Value / 2), traitEnCours.Fin.Y); TraceEnCours = true; } Dessin.Add(trait); ItemEnCours++; } #endregion #region Selection if (OutilEnCours == Outils.Main && !DeplacementAutorise && !RedimensionnementAutorise) { foreach (var item in Dessin) { if (Ajout) { if (item.HitTest(e.Location)) { if (item.EstSelectionne) { item.EstSelectionne = false; item.CouleurLigne = ((Couleur)cmbCouleur.SelectedItem).Valeur; } else { item.EstSelectionne = true; item.CouleurLigne = Color.Red; } } } else { if (item.HitTest(e.Location)) { item.CouleurLigne = Color.Red; item.EstSelectionne = true; } else { item.CouleurLigne = ((Couleur)cmbCouleur.SelectedItem).Valeur; item.EstSelectionne = false; } } } pnlBoard.Invalidate(); } #endregion #region Trace Equipement if (OutilEnCours == Outils.Case) { var width = int.Parse(txtWidth.Text); var height = int.Parse(txtHeight.Text); var equipement = new Equipement( string.Format("Rectangle{0}", Dessin.Where(i => i is Equipement).Count() + 1), new Point(e.Location.X - (width / 2), e.Location.Y - (height / 2)), width, height, ((Couleur)cmbCouleur.SelectedItem).Valeur, (float)nudLargeur.Value ); Dessin.Add(equipement); ItemEnCours++; pnlBoard.Invalidate(); } #endregion }
public long AddDessin(Dessin dessin) { throw new NotImplementedException(); }
public void EnregistrerDessin(Dessin p_dessin) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = "\t"; using (XmlWriter doc = XmlWriter.Create(this.m_nomFichier, settings)) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(DessinFormatElementsDTO), new Type[] { typeof(PolygoneFormatElementsDTO), typeof(CercleFormatElementsDTO), }); // Transformation de Dession vers DessinDTO // Méthode 1 : Manuelle DessinFormatElementsDTO dessinDTO = new DessinFormatElementsDTO(); dessinDTO.Formes = new List <FormeFormatElementsDTO>(); foreach (Forme forme in p_dessin.Formes) { FormeFormatElementsDTO formeDTO = null; switch (forme) { case Polygone p: formeDTO = new PolygoneFormatElementsDTO() { Sommets = p.Sommets.Select(point2D => new Point2DFormatElementsDTO() { X = point2D.X, Y = point2D.Y }).ToList() }; break; case Cercle c: Point2D centre = c.Centre; formeDTO = new CercleFormatElementsDTO() { Centre = new Point2DFormatElementsDTO() { X = centre.X, Y = centre.Y }, Rayon = c.Rayon }; break; default: break; } dessinDTO.Formes.Add(formeDTO); } // Méthode 2 : Bibliothèque automapper //IMapper mapper = CreerOutilConversionEntity2DTO(); //DessinDTO dessinDTO = mapper.Map<DessinDTO>(p_dessin); doc.WriteStartDocument(); xmlSerializer.Serialize(doc, dessinDTO); doc.Close(); } }
private async void pnlBoard_Move(object sender, MouseEventArgs e) { UpdateUI(e.Location.X, e.Location.Y); await Task.Run(() => { #region TRACE if (TraceEnCours) { var item = Dessin.ElementAt(ItemEnCours) as Trait; item.Fin = e.Location; } #endregion #region DEPLACEMENT if (DeplacementAutorise) { // Valeur de déplacement int dx = e.Location.X - _positionSouris.X; int dy = e.Location.Y - _positionSouris.Y; // Nouvelle position souris _positionSouris = e.Location; // Déplace tous les élements selectionnés var items = Dessin.Where(i => i.EstSelectionne).ToList(); foreach (var item in items) { item.Translater(dx, dy); } } #endregion #region REDIMENSIONNEMENT if (RedimensionnementAutorise) { // Trait if (_maitre is Trait) { var item = _maitre as Trait; // Horizontal if (item.Depart.Y == item.Fin.Y) { if (RedimEnCours == Constantes.PosRedim.TraitDebut) { item.Depart = new Point(e.Location.X, item.Depart.Y); } else { item.Fin = new Point(e.Location.X, item.Fin.Y); } } //Trait vertical else { if (RedimEnCours == Constantes.PosRedim.TraitDebut) { item.Depart = new Point(item.Depart.X, e.Location.Y); } else { item.Fin = new Point(item.Fin.X, e.Location.Y); } } } // Equipement else { } } #endregion // Mise à jour de l'affichage pnlBoard.Invalidate(); }); }
/// <summary> /// Permet de sauvegarder dans fichier texte dans une matrice pour l'apprentissage automatique /// </summary> public int SauvegarderCoordonnees(List <CoordDessin> lstCoord) { if (_source == 0) { try { string sFichier = ConfigurationManager.AppSettings["FichierApprentissage"]; StreamWriter sw = new StreamWriter(new FileStream(sFichier, FileMode.Open, FileAccess.Write)); sw.WriteLine(CstApplication.NOMBRE_BITS_X * CstApplication.NOMBRE_BITS_Y); foreach (CoordDessin cd in lstCoord) { string sLigne = ""; foreach (bool bit in cd.BitArrayDessin) { sLigne += bit ? CstApplication.FAUX : CstApplication.VRAI; sLigne += "\t"; } sLigne += cd.Reponse; sw.WriteLine(sLigne); } sw.Close(); return(CstApplication.OK); } catch (Exception ex) { MessageBox.Show(ex.Message); return(CstApplication.ERREUR); } } else if (_source == 1) { try { using (Entities context = new Entities()) { foreach (CoordDessin cd in lstCoord) { string coordonner = ""; foreach (bool bit in cd.BitArrayDessin) { coordonner += bit ? 0 : 1; } var dessin = new Dessin() { Taille = CstApplication.NOMBRE_BITS_X * CstApplication.NOMBRE_BITS_Y, Charactère = cd.Reponse, Coordonnées = coordonner }; context.Dessin.Add(dessin); context.SaveChanges(); } return(CstApplication.OK); } } catch (Exception ex) { MessageBox.Show(ex.Message); return(CstApplication.ERREUR); } } return(CstApplication.ERREUR); }