void diagram1_ElementDoubleClick(object sender, EventArgs e) { try { string[] shapeClicked = new string[diagram1.Model.SelectedShapes().Keys.Count]; diagram1.Model.SelectedShapes().Keys.CopyTo(shapeClicked, 0); if (shapeClicked.Length > 1 || shapeClicked == null || diagram1.Model.Shapes[shapeClicked[0]].StencilItem.Key != "REGRA") { return; } ScriptDialog sDialog = new ScriptDialog(this, diagram1.Model.Shapes[shapeClicked[0]].Label.Text); sDialog.StartPosition = FormStartPosition.CenterParent; sDialog.ShowDialog(); if (!sDialog.ERROR) { diagram1.Model.Shapes[shapeClicked[0]].Label.Text = sDialog.Script; diagram1.Model.Shapes[shapeClicked[0]].Width += sDialog.Script.Length * diagram1.Model.Shapes[shapeClicked[0]].Label.FontSize; ResetDiagram(); Statements[Statements.FindIndex(s => s.Key == shapeClicked[0])].Script = sDialog.Script; } } catch (Exception) { } }
private void diagram1_ElementInserted(object sender, ElementsEventArgs e) { try { e.Value.ApplyTheme(Singleton.Instance.GetTheme(Crainiate.Diagramming.Themes.LightBlue)); bool isStatement = false; if (!((string)e.Value.Key).Contains("Shape") || ignoreInsert && sender != null) { return; } if (((Shape)e.Value).StencilItem.Key == "REGRA") { isStatement = true; } // _E_ | _OU_ : Create connectors if (!isStatement) { e.Value.ApplyTheme(Singleton.Instance.GetTheme(Crainiate.Diagramming.Themes.Orange)); ((Shape)e.Value).AllowSnap = ((Shape)e.Value).AllowScale = false; ignoreInsert = true; Link connector1 = new Link(); connector1.Start.Shape = diagram1.Model.Shapes[((Shape)e.Value).Key]; connector1.End.Location = new PointF(((Shape)e.Value).Location.X + ((Shape)e.Value).Width / 2, ((Shape)e.Value).Location.Y - 10); //connector1.Avoid = true; connector1.End.Marker = new Marker(MarkerStyle.Ellipse); connector1.Start.Marker = new Marker(MarkerStyle.Ellipse); connector1.SetKey("Link - " + ((Shape)e.Value).Key); diagram1.Model.Lines.Add("Link - " + ((Shape)e.Value).Key, connector1); if (((Shape)e.Value).StencilItem.Key == "_E_") { Booleans.Add(new BoolConnector(((Shape)e.Value).Key, "AND")); ((Shape)e.Value).Label = new Crainiate.Diagramming.Label("E"); } else if (((Shape)e.Value).StencilItem.Key == "_OU_") { Booleans.Add(new BoolConnector(((Shape)e.Value).Key, "OR")); ((Shape)e.Value).Label = new Crainiate.Diagramming.Label("OU"); } } else { e.Value.ApplyTheme(Singleton.Instance.GetTheme(Crainiate.Diagramming.Themes.Green)); //((Shape)e.Value).AllowSnap = ((Shape)e.Value).AllowScale = false; ScriptDialog sDialog = new ScriptDialog(this); sDialog.StartPosition = FormStartPosition.CenterParent; sDialog.ShowDialog(); ignoreInsert = true; Link connector1 = new Link(); connector1.Start.Shape = diagram1.Model.Shapes[((Shape)e.Value).Key]; connector1.End.Location = new PointF(((Shape)e.Value).Location.X + ((Shape)e.Value).Width / 2, ((Shape)e.Value).Location.Y - 10); //connector1.Avoid = true; connector1.End.Marker = new Marker(MarkerStyle.Ellipse); connector1.Start.Marker = new Marker(MarkerStyle.Ellipse); connector1.SetKey("Link - " + ((Shape)e.Value).Key); diagram1.Model.Lines.Add("Link - " + ((Shape)e.Value).Key, connector1); if (!sDialog.ERROR) { ((Shape)e.Value).Label = new Crainiate.Diagramming.Label(sDialog.Script); ((Shape)e.Value).Width = sDialog.Script.Length * ((Shape)e.Value).Label.FontSize; Statements.Add(new Statement(((Shape)e.Value).Key, sDialog.Script)); } else { Statements.Add(new Statement(((Shape)e.Value).Key, "")); } } ignoreInsert = false; } catch (Exception) { } }