//----------------------------------------------- public CResultAErreur RefreshParametres() { CResultAErreur result = CResultAErreur.True; foreach (KeyValuePair <int, string> kv in m_dicParametresGraphiques) { CRepresentationExpressionGraphique rep = RepresentationRacine.GetFormule(kv.Value); CRepresentationExpressionGraphique graf = rep; while (graf != null) { result = graf.RefreshParametres(); if (!result) { return(result); } if (graf.LastErreur != "") { result.EmpileErreur(graf.LastErreur); return(result); } else { if (graf.Formule == null) { LastErreur = I.T("Bad parameter @1|20104", kv.Key.ToString()); result.EmpileErreur(LastErreur); return(result); } } graf = graf.Next; } m_formule.SetParametre(kv.Key, rep.FormuleFinale); } return(result); }
//----------------------------------------------- public void SetExterne(int nNumParametre, CRepresentationExpressionGraphique exp) { if (exp != null) { while (exp.Prev != null) { exp = exp.Prev; } m_dicParametresGraphiques[nNumParametre] = exp.Id; if (m_formule != null) { m_formule.SetParametre(nNumParametre, exp.FormuleFinale); } } else { C2iExpressionGraphique rep = RepresentationRacine; CRepresentationExpressionGraphique oldExt = GetExterne(nNumParametre); if (m_dicParametresGraphiques.ContainsKey(nNumParametre)) { m_dicParametresGraphiques.Remove(nNumParametre); } if (oldExt != null && oldExt.Next == null && oldExt.Prev == null) { if (rep != null && rep.GetUtilisateurs(oldExt.Id).Count() == 0) { rep.RemoveChild(oldExt); oldExt.ClearExternes(); } } } }
//----------------------------------------------- public void BringToFront(I2iObjetGraphique child) { CRepresentationExpressionGraphique exp = child as CRepresentationExpressionGraphique; if (m_listeRepresentations.Contains(exp)) { m_listeRepresentations.Remove(exp); m_listeRepresentations.Add(exp); } }
//------------------------------------------------------------------------ public virtual void DrawExpression(CContextDessinObjetGraphique ctx, CRepresentationExpressionGraphique expressionGraphique) { Rectangle rct = expressionGraphique.RectangleAbsolu; if ( expressionGraphique.LastErreur != null && expressionGraphique.LastErreur != "" ) ctx.Graphic.FillRectangle(Brushes.Red, rct); else ctx.Graphic.FillRectangle(Brushes.White, rct); ctx.Graphic.DrawRectangle(Pens.Black, rct); C2iExpressionAnalysable expAn = expressionGraphique.Formule as C2iExpressionAnalysable; string strText = ""; /*if (expAn != null) strText = expAn.GetInfos().Texte; else */if ( expressionGraphique.Formule != null ) strText = expressionGraphique.Formule.GetString(); StringFormat f = new StringFormat(); f.Alignment = StringAlignment.Center; f.LineAlignment = StringAlignment.Center; Font ft = new Font(FontFamily.GenericSansSerif, 8); ctx.Graphic.DrawString(strText, ft, Brushes.Black, expressionGraphique.RectangleAbsolu, f); AdjustableArrowCap cap = new AdjustableArrowCap(4, 4, true); C2iExpressionGraphique rep = expressionGraphique.RepresentationRacine; if (rep != null) { Pen pen = new Pen(Brushes.Black, 1); pen.DashStyle = DashStyle.Dot; pen.EndCap = LineCap.Custom; pen.CustomEndCap = cap; foreach (string strLien in expressionGraphique.IdElementsUtilises) { CRepresentationExpressionGraphique exp = rep.GetFormule(strLien); if (exp != null) { DrawLien(ctx, pen, ft, exp, expressionGraphique, ""); } } pen.Dispose(); } CRepresentationExpressionGraphique next = expressionGraphique.Next; if (next != null) { Pen pen = new Pen(Brushes.Black, 3); pen.CustomEndCap = cap; DrawLien(ctx, pen, ft, expressionGraphique, next, ""); pen.Dispose(); } cap.Dispose(); ft.Dispose(); }
//----------------------------------------------- public void StopUseExterne(CRepresentationExpressionGraphique exp) { OnChangeFormule(exp); foreach (KeyValuePair <int, string> kv in m_dicParametresGraphiques.ToArray()) { if (kv.Value == exp.Id) { m_dicParametresGraphiques.Remove(kv.Key); } } }
//----------------------------------------------- public bool IsAChildOf(I2iObjetGraphique parent, I2iObjetGraphique supposedChild) { if (parent == this) { CRepresentationExpressionGraphique rep = supposedChild as CRepresentationExpressionGraphique; if (rep != null) { return(m_listeRepresentations.Contains(rep)); } } return(false); }
//----------------------------------------------- public void OnChangeFormule(CRepresentationExpressionGraphique exp) { foreach (KeyValuePair <int, string> kv in m_dicParametresGraphiques) { if (kv.Value == exp.Id) { if (Formule != null) { Formule.SetParametre(kv.Key, exp.FormuleFinale); } } } }
//----------------------------------------------- public void OnChangeFormule(CRepresentationExpressionGraphique expression) { if (expression != null) { while (expression.Prev != null) { expression = expression.Prev; } foreach (CRepresentationExpressionGraphique user in GetUtilisateurs(expression.Id)) { user.OnChangeFormule(expression); } } }
//----------------------------------------------- public void Draw(CContextDessinObjetGraphique ctx) { MyDraw(ctx); foreach (CRepresentationExpressionGraphique rep in m_listeRepresentations) { rep.Draw(ctx); } CRepresentationExpressionGraphique start = StartPoint; if (start != null) { Rectangle rctStart = start.RectangleAbsolu; ctx.Graphic.DrawImageUnscaled(Resources.Start, rctStart.Left, rctStart.Top); } }
public static CDessineurExpressionGraphique GetDessineur(CRepresentationExpressionGraphique expression) { C2iExpression formule = expression.Formule; CDessineurExpressionGraphique dessineur = null; if (formule != null) { Type tp = formule.GetType(); while (tp != null) { if (m_dicDessineurs.TryGetValue(tp, out dessineur)) return dessineur; tp = tp.BaseType; } } return DefaultInstance; }
//----------------------------------------------- public void FrontToBack(I2iObjetGraphique child) { CRepresentationExpressionGraphique exp = child as CRepresentationExpressionGraphique; if (m_listeRepresentations.Contains(exp)) { m_listeRepresentations.Remove(exp); if (m_listeRepresentations.Count > 0) { m_listeRepresentations.Insert(0, exp); } else { m_listeRepresentations.Add(exp); } } }
//----------------------------------------------- public CResultAErreur RefreshFormuleFinale() { m_formuleFinale = null; CResultAErreur result = CResultAErreur.True; C2iExpressionBegin formule = new C2iExpressionBegin(); foreach (CDefinitionProprieteDynamiqueVariableFormule def in m_listeVariables) { C2iExpressionVariable var = new C2iExpressionVariable(); C2iExpression exp = new C2iExpressionChamp(); ((C2iExpressionChamp)exp).DefinitionPropriete = def; var.Parametres.Add(exp); exp = new C2iExpressionConstante(def.TypeDonnee.TypeDotNetNatif.ToString()); var.Parametres.Add(exp); if (def.TypeDonnee.IsArrayOfTypeNatif) { exp = new C2iExpressionVrai(); var.Parametres.Add(exp); } formule.Parametres.Add(var); } CRepresentationExpressionGraphique graf = StartPoint; if (graf == null) { result.EmpileErreur(I.T("No start point|20103")); return(result); } while (graf != null) { result = graf.RefreshParametres(); if (!result) { return(result); } if (graf.Formule != null) { formule.Parametres.Add(graf.Formule); } graf = graf.Next; } m_formuleFinale = formule; return(CResultAErreur.True); }
protected void DrawLien( CContextDessinObjetGraphique ctx, Pen pen, Font ft, CRepresentationExpressionGraphique de, CRepresentationExpressionGraphique vers, string strText ) { CLienTracable lien = CTraceurLienDroit.GetLienPourLier(de.RectangleAbsolu, vers.RectangleAbsolu, EModeSortieLien.Automatic); lien.RendVisibleAvecLesAutres(ctx.Liens); ctx.AddLien(lien); ctx.Graphic.DrawLines(pen, lien.Points.ToArray()); if (strText != "" && lien.Points.Count() > 0) { CSegmentDroite segment = lien.Segments[0]; Point ptMilieu = segment.Milieu; Brush br = new SolidBrush(pen.Color); ctx.Graphic.DrawString(strText, ft, br, ptMilieu); br.Dispose(); } }
//----------------------------------------------- public void RemoveChild(I2iObjetGraphique child) { CRepresentationExpressionGraphique c = child as CRepresentationExpressionGraphique; if (c != null) { foreach (CRepresentationExpressionGraphique user in GetUtilisateurs(c.Id)) { user.StopUseExterne(c); } if (c.Prev != null) { c.Prev.Next = null; } CRepresentationExpressionGraphique next = c.Next; if (next != null) { c.Next = null; RemoveChild(next); } m_listeRepresentations.Remove(c); } }
public override void DrawExpression(CContextDessinObjetGraphique ctx, CRepresentationExpressionGraphique expressionGraphique) { Rectangle rct = expressionGraphique.RectangleAbsolu; List<Point> pts = new List<Point>(); pts.Add(new Point(rct.Left, rct.Top + rct.Height / 2)); pts.Add(new Point(rct.Left + rct.Width / 2, rct.Top)); pts.Add(new Point(rct.Right, rct.Top + rct.Height / 2)); pts.Add(new Point(rct.Left + rct.Width / 2, rct.Bottom)); ctx.Graphic.FillPolygon(Brushes.White, pts.ToArray()); ctx.Graphic.DrawPolygon(Pens.Black, pts.ToArray()); C2iExpressionAnalysable expAn = expressionGraphique.Formule as C2iExpressionAnalysable; string strText = ""; if (expAn.Parametres.Count >0 && expAn.Parametres[0] != null) { strText = expAn.Parametres2i[0].GetString(); } else { if (expAn != null) strText = expAn.GetInfos().Texte; else if (expressionGraphique.Formule != null) strText = expressionGraphique.Formule.GetString(); } StringFormat f = new StringFormat(); f.Alignment = StringAlignment.Center; f.LineAlignment = StringAlignment.Center; Font ft = new Font(FontFamily.GenericSansSerif, 8); ctx.Graphic.DrawString(strText, ft, Brushes.Black, expressionGraphique.RectangleAbsolu, f); C2iExpressionGraphique rep = expressionGraphique.RepresentationRacine; AdjustableArrowCap cap = new AdjustableArrowCap(4, 4, true); if (rep != null) { Pen pen = new Pen ( Color.Black, 2 ); pen.CustomEndCap = cap; for ( int n = 0; n< 3; n++ ) { CRepresentationExpressionGraphique ext = expressionGraphique.GetExterne ( n ); if ( ext != null ) { if ( n == 0 ) { pen.Color = Color.Black; pen.Width = 1; pen.DashStyle = DashStyle.Dot; DrawLien ( ctx, pen, ft, ext, expressionGraphique, "?" ); } else if (n == 1) { pen.Width = 3; pen.DashStyle = DashStyle.Solid; pen.Color = Color.Green; DrawLien(ctx, pen, ft, expressionGraphique, ext, I.T("Yes|20082")); } else if (n == 2) { pen.Width = 3; pen.DashStyle = DashStyle.Solid; pen.Color = Color.Red; DrawLien(ctx, pen, ft, expressionGraphique, ext, I.T("no|20083")); } } } pen.Dispose(); } CRepresentationExpressionGraphique next = expressionGraphique.Next; if (next != null) { Pen pen = new Pen(Brushes.Black, 3); pen.CustomEndCap = cap; DrawLien(ctx, pen, ft, expressionGraphique, next, I.T("End if|20084")); pen.Dispose(); } cap.Dispose(); ft.Dispose(); }
//------------------------------------------------------------------------ public override void DrawExpression(CContextDessinObjetGraphique ctx, CRepresentationExpressionGraphique expressionGraphique) { C2iExpressionObjet expObjet = expressionGraphique.Formule as C2iExpressionObjet; if (expObjet == null) { return; } Rectangle rct = expressionGraphique.RectangleAbsolu; Rectangle[] rcts = new Rectangle[] { new Rectangle(rct.Left, rct.Top, rct.Width, rct.Height / 2), new Rectangle(rct.Left, rct.Top + rct.Height / 2, rct.Width, rct.Height / 2) }; //Dessin des deux paramètres for (int n = 0; n < 2; n++) { CRepresentationExpressionGraphique exp = new CRepresentationExpressionGraphique(); exp.Position = new Point(rcts[n].Left, rcts[n].Top); exp.Size = new Size(rcts[n].Width, rcts[n].Height); if (expObjet.Parametres.Count > n) { exp.Formule = expObjet.Parametres2i[n]; } CDessineurExpressionGraphique dessineur = CDessineurExpressionGraphique.GetDessineur(exp); if (dessineur != null) { dessineur.DrawExpression(ctx, exp); } } StringFormat f = new StringFormat(); f.Alignment = StringAlignment.Center; f.LineAlignment = StringAlignment.Center; Font ft = new Font(FontFamily.GenericSansSerif, 8); AdjustableArrowCap cap = new AdjustableArrowCap(4, 4, true); C2iExpressionGraphique rep = expressionGraphique.RepresentationRacine; if (rep != null) { Pen pen = new Pen(Brushes.DarkGreen, 1); pen.DashStyle = DashStyle.DashDotDot; pen.EndCap = LineCap.Custom; pen.CustomEndCap = cap; foreach (string strLien in expressionGraphique.IdElementsUtilises) { CRepresentationExpressionGraphique exp = rep.GetFormule(strLien); if (exp != null) { DrawLien(ctx, pen, ft, exp, expressionGraphique, ""); } } pen.Dispose(); } CRepresentationExpressionGraphique next = expressionGraphique.Next; if (next != null) { Pen pen = new Pen(Brushes.Black, 3); pen.CustomEndCap = cap; DrawLien(ctx, pen, ft, expressionGraphique, next, ""); pen.Dispose(); } cap.Dispose(); ft.Dispose(); }
//-------------------------------------------------- /// <summary> /// crée les éléments graphiques d'une formule /// </summary> /// <param name="formule"></param> public void InitFromFormule(C2iExpression formule) { m_listeRepresentations.Clear(); m_listeVariables.Clear(); if (formule == null) { return; } ArrayList lst = formule.ExtractExpressionsType(typeof(C2iExpressionVariable)); foreach (C2iExpressionVariable variable in lst) { if (variable.Parametres.Count > 0) { C2iExpressionChamp champ = variable.Parametres[0] as C2iExpressionChamp; if (champ != null) { CDefinitionProprieteDynamiqueVariableFormule def = champ.DefinitionPropriete as CDefinitionProprieteDynamiqueVariableFormule; if (def != null) { m_listeVariables.Add(def); } } } } C2iExpressionBegin begin = formule as C2iExpressionBegin; m_strIdStartPoint = ""; int nX = 100; int nY = 20; if (begin != null) { CRepresentationExpressionGraphique previous = null; foreach (C2iExpression action in begin.Parametres) { if (!(action is C2iExpressionVariable)) { CRepresentationExpressionGraphique rep = new CRepresentationExpressionGraphique(); rep.Position = new Point(nX, nY); AddChild(rep); rep.Parent = this; rep.Formule = action; nY = rep.RectangleAbsolu.Bottom; foreach (CRepresentationExpressionGraphique repTmp in m_listeRepresentations) { if (repTmp.RectangleAbsolu.Bottom > nY) { nY = rep.RectangleAbsolu.Bottom; } } nY += 20; if (previous == null) { StartPoint = rep; } else { previous.Next = rep; } previous = rep; } } } else { CRepresentationExpressionGraphique rep = new CRepresentationExpressionGraphique(); rep.Position = new Point(nX, nY); AddChild(rep); rep.Parent = this; rep.Formule = formule; StartPoint = rep; } }