public ControlShapeProperties(GraphicElement el) : base(el) { ClickEventName = ((ControlShape)el).ClickEventName; ClickEventData = ((ControlShape)el).ClickEventData; Enabled = ((ControlShape)el).Enabled; Visible = ((ControlShape)el).Visible; }
public override void Update(GraphicElement el, string label) { base.Update(el, label); (label == nameof(Minimum)).If(() => ((TrackbarShape)el).Minimum = Minimum); (label == nameof(Maximum)).If(() => ((TrackbarShape)el).Maximum = Maximum); (label == nameof(ValueChangedName)).If(() => ((TrackbarShape)el).ValueChangedName = ValueChangedName); }
// Ex: localhost:8001/flowsharp?cmd=CmdDropShape&ShapeName=Box&X=50&Y=100 // Ex: localhost:8001/flowsharp?cmd=CmdDropShape&ShapeName=Box&X=50&Y=100&Text=Foobar&FillColor=!FF00ff&Width=300 public void Process(ISemanticProcessor proc, IMembrane membrane, CmdDropShape cmd) { List <Type> shapes = proc.ServiceManager.Get <IFlowSharpToolboxService>().ShapeList; var controller = proc.ServiceManager.Get <IFlowSharpCanvasService>().ActiveController; Type t = shapes.Where(s => s.Name == cmd.ShapeName).SingleOrDefault(); if (t != null) { controller.Canvas.FindForm().BeginInvoke(() => { GraphicElement el = (GraphicElement)Activator.CreateInstance(t, new object[] { controller.Canvas }); el.DisplayRectangle = new Rectangle(cmd.X, cmd.Y, cmd.Width ?? el.DefaultRectangle().Width, cmd.Height ?? el.DefaultRectangle().Height); el.Name = cmd.Name; el.Text = cmd.Text; cmd.FillColor.IfNotNull(c => el.FillColor = GetColor(c)); cmd.BorderColor.IfNotNull(c => el.BorderPenColor = GetColor(c)); cmd.TextColor.IfNotNull(c => el.TextColor = GetColor(c)); el.UpdateProperties(); el.UpdatePath(); controller.Insert(el); }); } }
protected List <GraphicElement> GetReferencedAssemblies(GraphicElement elAssy) { List <GraphicElement> refs = new List <GraphicElement>(); // TODO: Qualify EndConnectedShape as being IAssemblyBox elAssy.Connections.Where(c => (c.ToElement is Connector) && ((Connector)c.ToElement).EndCap == AvailableLineCap.Arrow).ForEach(c => { // Connector endpoint will reference ourselves, so exclude. if (((Connector)c.ToElement).EndConnectedShape != elAssy) { GraphicElement toAssy = ((Connector)c.ToElement).EndConnectedShape; refs.Add(toAssy); } }); // TODO: Qualify EndConnectedShape as being IAssemblyBox elAssy.Connections.Where(c => (c.ToElement is Connector) && ((Connector)c.ToElement).StartCap == AvailableLineCap.Arrow).ForEach(c => { // Connector endpoint will reference ourselves, so exclude. if (((Connector)c.ToElement).StartConnectedShape != elAssy) { GraphicElement toAssy = ((Connector)c.ToElement).StartConnectedShape; refs.Add(toAssy); } }); return(refs); }
protected void UntagTaggedElement(BaseController controller) { GraphicElement untag = controller.Elements.FirstOrDefault(el => el.Tagged); untag?.ClearTag(); untag?.Redraw(); }
private void lbShapes_MouseClick(object sender, MouseEventArgs e) { Close(); GraphicElement shape = ((NavigateToShape)lbShapes.SelectedItem).Shape; serviceManager.Get <IFlowSharpEditService>().FocusOnShape(shape); }
private void OnLostFocus(object sender, EventArgs e) { selectedElement = null; BaseController controller = serviceManager.Get <IFlowSharpCanvasService>().ActiveController; UntagTaggedElement(controller); }
protected bool BuildModuleFromModuleSource(GraphicElement elClass, string className, string filename) { bool ok = true; StringBuilder sb = new StringBuilder(); // If there's no shapes (def's), then use whatever is in the actual class shape for code, // however we need to add/replace the #pylint line with whatever the current list of ignores are. string src = elClass.Json["python"] ?? ""; string[] lines = src.Split('\n'); if (lines.Length > 0 && lines[0].StartsWith("#pylint")) { // Remove the existing pylint options line. src = String.Join("\n", lines.Skip(1)); } // Insert pylint options as the first line before any imports. sb.Insert(0, PYLINT + "\n"); sb.Append(src); File.WriteAllText(filename, sb.ToString()); elClass.Json["python"] = sb.ToString(); return(ok); }
protected void RestoreConnections(List <ZOrderMap> zomList) { foreach (ZOrderMap zom in zomList) { GraphicElement el = zom.Element; List <Connection> connections = zom.Connections; foreach (Connection conn in connections) { conn.ToElement.SetConnection(conn.ToConnectionPoint.Type, el); } if (el.IsConnector) { Connector connector = el as Connector; connector.StartConnectedShape = zom.StartConnectedShape; connector.EndConnectedShape = zom.EndConnectedShape; if (connector.StartConnectedShape != null) { connector.StartConnectedShape.SetConnection(GripType.Start, connector); connector.StartConnectedShape.Connections.Add(zom.StartConnection); } if (connector.EndConnectedShape != null) { connector.EndConnectedShape.SetConnection(GripType.End, connector); connector.EndConnectedShape.Connections.Add(zom.EndConnection); } } } }
protected void Paste() { string copyBuffer = Clipboard.GetData("FlowSharp")?.ToString(); if (copyBuffer == null) { MessageBox.Show("Clipboard does not contain a FlowSharp shape", "Paste Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { try { GraphicElement el = Persist.DeserializeElement(canvas, copyBuffer); el.Move(new Point(20, 20)); el.UpdateProperties(); el.UpdatePath(); canvasController.Insert(el); canvasController.DeselectCurrentSelectedElement(); canvasController.SelectElement(el); } catch (Exception ex) { MessageBox.Show("Error pasting shape:\r\n" + ex.Message, "Paste Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
protected void InitializePluginsInToolbox() { int x = pnlToolbox.Width / 2 - 12; List <Type> pluginShapes = pluginManager.GetShapeTypes(); // Plugin shapes int n = x - 60; int y = 260; foreach (Type t in pluginShapes) { GraphicElement pluginShape = Activator.CreateInstance(t, new object[] { toolboxCanvas }) as GraphicElement; pluginShape.DisplayRectangle = new Rectangle(n, y, 25, 25); toolboxElements.Add(pluginShape); // Next toolbox shape position: n += 40; if (n > x + 60) { n = x - 60; y += 40; } } }
protected string CompileAssembly(BaseController canvasController, GraphicElement elAssy, List <GraphicElement> compiledAssemblies) { string assyFilename = ((IAssemblyBox)elAssy).Filename; if (!compiledAssemblies.Contains(elAssy)) { // Add now, so we don't accidentally recurse infinitely. compiledAssemblies.Add(elAssy); List <GraphicElement> referencedAssemblies = GetReferencedAssemblies(elAssy); List <string> refs = new List <string>(); // Recurse into referenced assemblies that need compiling first. foreach (GraphicElement el in referencedAssemblies) { string refAssy = CompileAssembly(canvasController, el, compiledAssemblies); refs.Add(refAssy); } List <string> sources = GetSources(canvasController, elAssy); Compile(assyFilename, sources, refs); } return(assyFilename); }
public string GetWorkflowCode(BaseController canvasController, GraphicElement wf) { StringBuilder sb = new StringBuilder(); // TODO: Hardcoded for now for POC. sb.AppendLine("namespace App"); sb.AppendLine("{"); sb.AppendLine("\tpublic partial class " + wf.Text); sb.AppendLine("\t{"); sb.AppendLine("\t\tpublic static void Execute(" + Clifton.Core.ExtensionMethods.ExtensionMethods.LeftOf(wf.Text, "Workflow") + " packet)"); sb.AppendLine("\t\t{"); sb.AppendLine("\t\t\t" + wf.Text + " workflow = new " + wf.Text + "();"); // Fill in the workflow steps. GraphicElement el = FindStartOfWorkflow(canvasController, wf); while (el != null) { sb.AppendLine("\t\t\tworkflow." + el.Text + "(packet);"); el = NextElementInWorkflow(el); } sb.AppendLine("\t\t}"); sb.AppendLine("\t}"); sb.AppendLine("}"); return(sb.ToString()); }
protected GraphicElement FindStartOfWorkflow(BaseController canvasController, GraphicElement wf) { GraphicElement start = null; foreach (GraphicElement srcEl in canvasController.Elements.Where(srcEl => wf.DisplayRectangle.Contains(srcEl.DisplayRectangle))) { if (!srcEl.IsConnector && srcEl != wf) { // Special case for a 1 step workflow. Untested. // Exclude any text annotations. if (srcEl.Connections.Count == 0) { if (!(srcEl is TextShape)) { start = srcEl; break; } } else { // start begins with a box or diamond shape, having only Start connection types. if (srcEl.Connections.All(c => c.ToConnectionPoint.Type == GripType.Start)) { start = srcEl; break; } } } } return(start); }
protected GraphicElement FindStartOfWorkflow(BaseController canvasController, GraphicElement wf) { GraphicElement start = null; foreach (GraphicElement srcEl in canvasController.Elements.Where(srcEl => wf.DisplayRectangle.Contains(srcEl.DisplayRectangle))) { if (!srcEl.IsConnector && srcEl != wf) { // Special case for a 1 step workflow. Untested. if (srcEl.Connections.Count == 0) { start = srcEl; break; } // start and end has only one connection. if (srcEl.Connections.Count == 1 && ((Connection)srcEl.Connections[0]).ToConnectionPoint.Type == FlowSharpLib.GripType.Start) { start = srcEl; break; } } } return(start); }
protected void InsertCodeInRunWorkflowMethod(GraphicElement root, StringBuilder code) { ICSharpClass cls = (ICSharpClass)root; string existingCode = String.Empty; // TODO: Verify that root.Json["Code"] defines the namespace, class, and stub, or figure out how to include "using" and field initialization and properties such that // we can create the namespace, class, and stub for the user. if (root.Json.ContainsKey("Code")) { existingCode = root.Json["Code"]; } //string before = existingCode.LeftOf("void RunWorkflow()"); //string after = existingCode.RightOf("void RunWorkflow()").RightOfMatching('{', '}'); //StringBuilder finalCode = new StringBuilder(before); StringBuilder finalCode = new StringBuilder(); finalCode.AppendLine("using System;"); finalCode.AppendLine("using System.Linq;"); finalCode.AppendLine(); finalCode.AppendLine("namespace " + cls.NamespaceName); finalCode.AppendLine("{"); finalCode.AppendLine(" public partial class " + cls.ClassName); finalCode.AppendLine(" {"); finalCode.AppendLine(new String(' ', 8) + "public void " + cls.MethodName + "()"); finalCode.AppendLine(new String(' ', 8) + "{"); finalCode.AppendLine(new String(' ', 12) + code.ToString().Trim()); finalCode.AppendLine(new String(' ', 8) + "}"); finalCode.AppendLine(" }"); finalCode.AppendLine("}"); // finalCode.Append(after); root.Json["Code"] = finalCode.ToString(); }
public static Task <bool> UpdateElementTransparencyAsync(string LayoutName, string ElementName, int TransValue) { //Reference a layoutitem in a project by name LayoutProjectItem layoutItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals(LayoutName)); if (layoutItem == null) { return(Task.FromResult(false)); } return(QueuedTask.Run <bool>(() => { //Reference and load the layout associated with the layout item Layout lyt = layoutItem.GetLayout(); //Reference a element by name GraphicElement graElm = lyt.FindElement(ElementName) as GraphicElement; if (graElm == null) { return false; } //Modify the Transparency property that exists only in the CIMGraphic class. CIMGraphic CIMGra = graElm.Graphic as CIMGraphic; CIMGra.Transparency = TransValue; //e.g., TransValue = 50 graElm.SetGraphic(CIMGra); return true; })); }
protected GraphicElement NextElementInWorkflow(GraphicElement el) { GraphicElement ret = null; if (el.Connections.Count == 1) { if (((Connector)((Connection)el.Connections[0]).ToElement).EndConnectedShape != el) { ret = ((Connector)((Connection)el.Connections[0]).ToElement).EndConnectedShape; } } else if (el.Connections.Count == 2) { if (((Connector)((Connection)el.Connections[0]).ToElement).StartConnectedShape == el) { ret = ((Connector)((Connection)el.Connections[0]).ToElement).EndConnectedShape; } else if (((Connector)((Connection)el.Connections[1]).ToElement).StartConnectedShape == el) { ret = ((Connector)((Connection)el.Connections[1]).ToElement).EndConnectedShape; } } return(ret); }
public void InitializePluginsInToolbox() { PluginManager pluginManager = new PluginManager(); pluginManager.InitializePlugins(); int x = pnlToolbox.Width / 2 - 12; List <Type> pluginShapes = pluginManager.GetShapeTypes(); // Plugin shapes int n = x - 60; int y = 260; foreach (Type t in pluginShapes.Where(t => !t.IsAbstract)) { GraphicElement pluginShape = Activator.CreateInstance(t, new object[] { toolboxCanvas }) as GraphicElement; pluginShape.DisplayRectangle = new Rectangle(n, y, 25, 25); toolboxController.AddElement(pluginShape); // Next toolbox shape position: n += 40; if (n > x + 60) { n = x - 60; y += 40; } } }
protected void AddConnections(TreeNode node, GraphicElement el) { el.Connections.ForEach(c => { node.Nodes.Add(CreateTreeNode(c.ToElement)); }); }
//private static void OnProcessCmdKeyEvent(object sender, ProcessCmdKeyEventArgs args) //{ // Action act; // if (canvasController.Canvas.Focused && keyActions.TryGetValue(args.KeyData, out act)) // { // act(); // args.Handled = true; // } //} private static void ElementSelected(object controller, ElementEventArgs args) { elementProperties = null; if (args.Element != null) { GraphicElement el = args.Element; elementProperties = el.CreateProperties(); string code; el.Json.TryGetValue("Code", out code); if (el.GetType().Name == "PythonFileBox" || el.GetType().Name == "HtmlFileBox") { pythonCodeEditorService.SetText(code ?? String.Empty); } else { csCodeEditorService.SetText(code ?? String.Empty); } } else { pythonCodeEditorService.SetText(String.Empty); csCodeEditorService.SetText(String.Empty); } propGrid.SelectedObject = elementProperties; canvasController.Canvas.Focus(); }
/// <summary> /// Find the next shape connected to el. /// </summary> /// <param name="el"></param> /// <returns>The next connected shape or null if no connection exists.</returns> protected GraphicElement NextElementInWorkflow(GraphicElement el) { GraphicElement ret = null; // The starting shape has one connection where the StartConnectedShape should be the el // and the EndConnectedShape is the next shape in the workflow. // A middle workflow element has two connections, again where the StartConnectedShape should be the el // and the EndConnectedShape is the next shape in the workflow. // The final workflow step has one connector, where the EndConnectedShape is the el. // 12/20/16, because of a current bug with connectors, where shapes incorrectly retain // connections to other shapes that they aren't actually connected to, we try to // compensate for this. foreach (Connection connection in el.Connections) { GraphicElement gr = connection.ToElement; // a shape's Connections should always be a Connector if (gr is Connector) { Connector connector = (Connector)gr; if (connector.StartConnectedShape == el) { ret = connector.EndConnectedShape; break; } } else { Trace.WriteLine("*** EXPECTED CONNECTOR FOR " + el.GetType().Name + " ID=" + el.Id.ToString() + " Text=" + el.Text + " ***"); } } /* * if (el.Connections.Count == 1) * { * if (((Connector)((Connection)el.Connections[0]).ToElement).EndConnectedShape != el) * { * ret = ((Connector)((Connection)el.Connections[0]).ToElement).EndConnectedShape; * } * } * else if (el.Connections.Count == 2) * { * if (((Connector)((Connection)el.Connections[0]).ToElement).StartConnectedShape == el) * { * ret = ((Connector)((Connection)el.Connections[0]).ToElement).EndConnectedShape; * } * else if (((Connector)((Connection)el.Connections[1]).ToElement).StartConnectedShape == el) * { * ret = ((Connector)((Connection)el.Connections[1]).ToElement).EndConnectedShape; * } * } */ return(ret); }
protected void CreateCodeFile(GraphicElement root, List <string> sources, string code) { string filename = Path.GetFileNameWithoutExtension(Path.GetTempFileName()) + ".cs"; tempToTextBoxMap[filename] = root.Text; File.WriteAllText(filename, GetCode(root)); sources.Add(filename); }
private static void CodeEditorServiceTextChanged(object sender, TextChangedEventArgs e) { if (canvasController.SelectedElements.Count == 1) { GraphicElement el = canvasController.SelectedElements[0]; el.Json["Code"] = e.Text; } }
protected TreeNode CreateTreeNode(GraphicElement el, string prefix = "") { TreeNode node = new TreeNode(prefix + el.ToString()); node.Tag = el; return(node); }
public override void Update(GraphicElement el, string label) { // ((ImageShape)el).Filename = Filename; // X1 //(label == nameof(Filename)).If(() => this.ChangePropertyWithUndoRedo<string>(el, nameof(Filename), nameof(Filename))); (label == nameof(Filename)).If(() => ((ImageShape)el).Filename = Filename); base.Update(el, label); }
protected void RightClick() { BaseController controller = serviceManager.Get <IFlowSharpCanvasService>().ActiveController; GraphicElement hoverShape = HoverShape; // Sometimes this is null. Not sure why. hoverShape?.RightClick(); }
public override void Update(GraphicElement el, string label) { base.Update(el, label); (label == nameof(ClickEventName)).If(() => ((ControlShape)el).ClickEventName = ClickEventName); (label == nameof(ClickEventData)).If(() => ((ControlShape)el).ClickEventData = ClickEventData); (label == nameof(Enabled)).If(() => ((ControlShape)el).Enabled = Enabled); (label == nameof(Visible)).If(() => ((ControlShape)el).Visible = Visible); }
protected string GetCode(GraphicElement el) { string code; el.Json.TryGetValue("Code", out code); return(code ?? ""); }
public void ShapeDeleted(GraphicElement el) { if (HoverShape == el) { DraggingSurface = false; HoverShape.ShowAnchors = false; HoverShape = null; } }
/// <summary> /// Create a Marker using default values /// </summary> /// <param name="point">The Point in map where the marker will be drawn.</param> /// <returns>A GraphicElement that can be drawn in a GraphicsLayer.</returns> private GraphicElement CreateMarker(Point point) { GraphicElement marker = new GraphicElement(); RasterMarkerSymbol icon = new RasterMarkerSymbol(HttpContext.Current.Request.MapPath("~/images/identify-map-icon.png")); marker.Symbol = icon; marker.Geometry = point; return marker; }