/// <summary> /// open existing diagram or create new empty diagram /// Create diagram model and then open diagram view on this model</summary> public void OpenDiagram(String FilePath = "") { Program.log.write("Program : OpenDiagram: " + FilePath); // open new empty diagram if (FilePath == "") { // if server already exist in system, send him message whitch open empty diagram if (!server.mainProcess) { server.SendMessage("open:"); } // open diagram in current program instance else { // create new model Diagram diagram = new Diagram(this); Diagrams.Add(diagram); // open diagram view on diagram model diagram.openDiagramView(); } } // open existing diagram file else { if (passwordForm != null) // prevent open diagram if another diagram triing open { return; } if (Os.FileExists(FilePath)) { FilePath = Os.getFullPath(FilePath); // if server already exist in system, send him message whitch open diagram file if (!server.mainProcess) { server.SendMessage("open:" + FilePath); } // open diagram in current program instance else { // check if file is already opened in current instance bool alreadyOpen = false; foreach (Diagram diagram in Diagrams) { if (diagram.FileName == FilePath) { // focus if (diagram.DiagramViews.Count() > 0) { Program.log.write("window get focus"); Program.log.write("OpenDiagram: diagramView: setFocus"); if (!diagram.DiagramViews[0].Visible) { diagram.DiagramViews[0].Show(); } Program.log.write("bring focus"); Media.bringToFront(diagram.DiagramViews[0]); } alreadyOpen = true; break; } } if (!alreadyOpen) { Diagram diagram = new Diagram(this); lock (diagram) { // create new model if (diagram.OpenFile(FilePath)) { this.options.addRecentFile(FilePath); Diagrams.Add(diagram); // open diagram view on diagram model diagram.openDiagramView(); } } } } } } }
public bool ClickOnNodeAction(Diagram.Diagram diagram, DiagramView diagramView, Node node) { if (node.link.Trim() == "#csharp") // OPEN SCRIPT node with link "script" is executed as script { String clipboard = Os.GetTextFormClipboard(); try { this.EvaluateAsync(diagram, diagramView, node, clipboard).Wait(); } catch (System.AggregateException ae) { ae.Handle(ex => { Program.log.Write("Exception in embed csharp script: " + ex.Message); return(true); }); } return(true); } return(false); }
public bool LoadAction(Diagram.Diagram diagram, XElement root) { this.counter = Int32.Parse(diagram.dataStorage.getStorage("FirstPlugin").getItem("counter", "0")); log.Write("FirstPlugin: load diagram xml"); foreach (XElement el in root.Descendants()) { try { if (el.Name.ToString() == "plugins") { foreach (XElement plugin in el.Descendants()) { if (plugin.Name.ToString() == "FirstPlugin") { foreach (XElement firstPluginElement in el.Descendants()) { if (firstPluginElement.Name.ToString() == "counter") { this.counter = Int32.Parse(firstPluginElement.Value); } } } } } } catch (Exception ex) { Program.log.Write("FirstPlugin: load xml: " + ex.Message); } } return(false); }
public Tools(Diagram.Diagram diagram, DiagramView diagramView, Node node, string clipboard = "") { this.diagram = diagram; this.diagramView = diagramView; this.node = node; this.clipboard = clipboard; }
public bool SaveAction(Diagram.Diagram diagram, XElement root) { log.Write("FirstPlugin: save diagram xml"); // second way to save data (if plugin is not installed this data are preserverd) diagram.dataStorage.addStorage("FirstPlugin").addItem("counter", this.counter.ToString()); // second way to save data (if plugin is not installed this data are removed) XElement plugins = null; foreach (XElement el in root.Descendants()) { if (el.Name.ToString() == "plugins") { plugins = el; } } if (plugins == null) { plugins = new XElement("plugins"); root.Add(plugins); } XElement FirstPlugin = new XElement("FirstPlugin"); FirstPlugin.Add(new XElement("counter", this.counter.ToString())); plugins.Add(FirstPlugin); return(true); }
// SCRIPT evaluate python script in nodes signed with stamp in node link [F9] private void Evaluate(Diagram.Diagram diagram, DiagramView diagramView) { Nodes nodes = null; if (diagramView.selectedNodes.Count() > 0) { nodes = new Nodes(diagramView.selectedNodes); } else { nodes = new Nodes(diagram.GetAllNodes()); } // remove nodes whit link other then [ ! | eval | evaluate | !#num_order | eval#num_order | evaluate#num_order] // higest number is executed first Regex regex = new Regex(@"^\s*(eval(uate)|!){1}(#\w+){0,1}\s*$"); nodes.RemoveAll(n => !regex.Match(n.link).Success); nodes.OrderByLink(); nodes.Reverse(); String clipboard = Os.GetTextFormClipboard(); #if !DEBUG Job.DoJob( new DoWorkEventHandler( delegate (object o, DoWorkEventArgs args) { #endif this.Evaluate(diagram, diagramView, nodes, clipboard); #if !DEBUG } ) ); #endif }
public bool ClickOnNodeAction(Diagram.Diagram diagram, DiagramView diagramView, Node node) { if (node.link.Trim() == "#ironpython") // OPEN SCRIPT node with link "script" is executed as script { this.Evaluate(diagram, diagramView, node, ""); return true; } return false; }
public bool KeyPressAction(Diagram.Diagram diagram, DiagramView diagramView, Keys keyData) { if (KeyMap.ParseKey("F9", keyData)) // [KEY] [F9] evaluate python script for selected nodes by stamp in link { this.Evaluate(diagram, diagramView); return true; } return false; }
// SCRIPT evaluate python script in node name or in node note in node private void Evaluate(Diagram.Diagram diagram, DiagramView diagramView, Node node, string clipboard = "") { // run macro Program.log.Write("diagram: openlink: run macro"); initScriptEngine(); script.SetDiagram(diagram); script.SetDiagramView(diagramView); script.SetClipboard(clipboard); string body = node.note.Trim() != "" ? node.note : node.name; script.RunScript(body); }
public bool ClickOnNodeAction(Diagram.Diagram diagram, DiagramView diagramview, Node node) { if (diagram.FileName != "" && this.IsUid(node.link)) { string uid = this.GetUid(node.link); if (Os.FileExists(diagram.FileName)) { string diagramDirectory = Os.GetFileDirectory(diagram.FileName); List <FileNameAndSizePair> files = new List <FileNameAndSizePair>(); foreach (string file in Directory.EnumerateFiles(diagramDirectory, "*.*", SearchOption.AllDirectories)) { FileNameAndSizePair pair = new FileNameAndSizePair(); pair.name = file; pair.size = new System.IO.FileInfo(file).Length; files.Add(pair); } files.Sort(delegate(FileNameAndSizePair p1, FileNameAndSizePair p2) { return(p1.size <p2.size ? -1 : p1.size> p2.size ? 1 : 0); }); foreach (FileNameAndSizePair file in files) { try { // skip self if (file.name == diagram.FileName) { continue; } long pos = 1; foreach (string line in File.ReadAllLines(file.name)) { if (line.Contains(uid)) { this.OpenFileOnPosition(file.name, pos); return(true); } pos++; } } catch (Exception ex) { Program.log.Write("FindUidPlugin: " + ex.Message); } } } } return(false); }
public bool KeyPressAction(Diagram.Diagram diagram, DiagramView diagramView, Keys keyData) { if (KeyMap.ParseKey("CTRL+G", keyData)) // [KEY] [CTRL+G] Evaluate expresion or generate random value { if (diagramView.selectedNodes.Count == 0) { this.Random(diagramView); } else { this.EvaluateExpression(diagramView); } } return(false); }
// SCRIPT evaluate python script in node name or in node note in node private async System.Threading.Tasks.Task EvaluateAsync(Diagram.Diagram diagram, DiagramView diagramView, Node node, string clipboard = "") { string body = node.note; if (this.interactiveLoader == null) { this.interactiveLoader = new InteractiveAssemblyLoader(); } if (this.scriptOptions == null) { this.scriptOptions = ScriptOptions.Default; var asms = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly asm in asms) { Program.log.Write("CSScriptPlugin: " + asm.ManifestModule.Name); if (asm.ManifestModule.Name == "InfiniteDiagram.exe") { this.scriptOptions = this.scriptOptions.AddReferences(asm); } } this.scriptOptions = this.scriptOptions.AddImports("Diagram"); } System.Threading.Tasks.Task <ScriptState <object> > task = CSharpScript.Create( options: this.scriptOptions, code: body, globalsType: typeof(Globals), assemblyLoader: this.interactiveLoader ) .RunAsync(new Globals { Script = new Tools(diagram, diagramView, node, clipboard) });; }
public bool ClickOnNodeAction(Diagram.Diagram diagram, DiagramView diagramview, Node node) { log.Write("FirstPlugin: Do Something in First Plugin:" + (counter++).ToString()); return(false); }
/// <summary> /// remove diagram from list of all diagrams</summary> public void removeDiagram(Diagram diagram) { this.Diagrams.Remove(diagram); }
public bool KeyPressAction(Diagram.Diagram diagram, DiagramView diagramView, Keys keyData) { return(false); }
/// <summary> /// add diagram to list of all diagrams</summary> public void addDiagram(Diagram diagram) { this.Diagrams.Add(diagram); }
/*************************************************************************************************************************/ // REFERENCIES /// <summary> /// Set current diagram for context in script /// </summary> /// <param name="diagram"></param> public void SetDiagram(Diagram.Diagram diagram) { this.diagram = diagram; }
public void OpenDiagramAction(Diagram.Diagram diagram) { log.Write("FirstPlugin: Open diagram action"); this.counter++; }
/*************************************************************************************************************************/ // REFERENCIES /// <summary> /// Set current diagram for context in script /// </summary> /// <param name="diagram"></param> public void setDiagram(Diagram diagram) { this.diagram = diagram; }
public void OpenDiagramAction(Diagram.Diagram diagram) { }
public bool saveLost = false; // if save is in redo and redo is cleared then save position is lost #endregion Fields #region Constructors /*************************************************************************************************************************/ // CONSTRUCTORS public UndoOperations(Diagram diagram) { this.diagram = diagram; }
public bool KeyPressAction(Diagram.Diagram diagram, DiagramView diagramview, Keys keyData) { log.Write("FirstPlugin: key press: " + keyData.ToString()); return(false); }
private string lastEvent = ""; // remember last event in console (for remove duplicate events) #endif #region Constructors /*************************************************************************************************************************/ // FORM Constructor public DiagramView(Main main, Diagram diagram, DiagramView parentView = null) { this.main = main; this.diagram = diagram; this.parentView = parentView; // initialize layer history this.currentLayer = this.diagram.layers.getLayer(0); this.layersHistory.Add(this.currentLayer); this.InitializeComponent(); // initialize popup menu this.PopupMenu = new Popup(this.components, this); // initialize edit panel this.editPanel = new EditPanel(this); this.Controls.Add(this.editPanel); // initialize edit link panel this.editLinkPanel = new EditLinkPanel(this); this.Controls.Add(this.editLinkPanel); // initialize breadcrumbs this.breadcrumbs = new Breadcrumbs(this); // move timer this.animationTimer.Tick += new EventHandler(animationTimer_Tick); this.animationTimer.Interval = 10; this.animationTimer.Enabled = false; // move timer this.zoomTimer.Tick += new EventHandler(zoomTimer_Tick); this.zoomTimer.Interval = 10; this.zoomTimer.Enabled = false; // lineWidthForm this.lineWidthForm.trackbarStateChanged += this.resizeLineWidth; //colorPickerForm this.colorPickerForm.changeColor += this.changeColor; // custom diagram icon if (this.diagram.options.icon != "") { this.Icon = Media.StringToIcon(this.diagram.options.icon); } }