/// <summary> /// Construct a new graph /// </summary> public Graph() { Out = new Module(ModuleDefinition.Registry["!out"]); Out.Name = "Output"; Modules = new List<Module>(); Modules.Add(Out); }
internal void SetEditModule(Module mod) { if (mod == null) { objectListView1.SetObjects(null); return; } objectListView1.SetObjects(Enumerable.Range(0, mod.Params.Length).Select(i => new ParamEditProxy(mod, i))); }
public ParamEditProxy(Module mod, int index) { Mod = mod; Index = index; }
public TModule(Module mod, GraphControl c, Graphics g) { var hw = g.MeasureString(mod.Name, c.ModHeadFnt); var x = mod.X; var y = mod.Y; var w = (int)(hw.Width + 15); var h = ParamY + ParamH * (mod.Inputs.Length - 1); Mod = mod; HitRect = new Rectangle(x, y, w, h); }
/// <summary> /// Add module to graph /// </summary> /// <param name="defName">definition name</param> public Module AddModule(string defName) { ModuleDefinition def; if (!ModuleDefinition.Registry.TryGetValue(defName, out def)) throw new ModelException("Module '{0}' not found", defName); var module = new Module(def); Modules.Add(module); // TODO: set x/y somehow return module; }
private void MakeNodes(Module mod, IList<ModuleNode> list) { list.Add(new ModuleNode { Mod = mod }); if (mod.Definition.InChannels > 0 && mod.Inputs[0] == null) throw new ModelException("Input of {0} is unused", mod.Name); foreach (var imod in mod.Inputs.Where(m => m != null)) if (!list.Any(mn => mn.Mod == imod)) MakeNodes(imod, list); }
/// <summary> /// Remove module from graph (also disconnects module from everything) /// </summary> /// <param name="module">module to remove</param> public void RemoveModule(Module module) { if (!Modules.Remove(module)) throw new ModelException("Module not in graph"); // disconnect from everything foreach (var m in Modules) { for (int i=0; i<m.Inputs.Length; i++) if (m.Inputs[i] == module) m.Inputs[i] = null; } // ... and before anyone does anything funny... Array.Clear(module.Inputs, 0, module.Inputs.Length); }
/// <summary> /// Remove connection between two modules /// </summary> /// <param name="to">Module whose input/parameter is connected</param> /// <param name="paramName">name of parameter to disconnect, or null for the module's input</param> public void Disconnect(Module to, string paramName=null) { if (!Modules.Contains(to)) throw new ModelException("Receiver module not in graph"); if (paramName == null) // disconnect from input { if (to.Definition.InChannels == 0) throw new ModelException("Module {0} has no input", to.Name); to.Inputs[0] = null; } else // disconnect from parameter { var slot = Array.IndexOf(to.Definition.ParamNames, paramName) + 1; if (slot <= 0) throw new ModelException("Module {0} has no parameter {1}", to.Name, paramName); to.Inputs[slot] = null; } }
/// <summary> /// Connect output of one module to the input of another /// </summary> /// <param name="from">Module whose output to connect</param> /// <param name="to">Module whose input/parameter to connect</param> /// <param name="paramName">name of parameter to connect to, or null for the module's input</param> public void Connect(Module from, Module to, string paramName=null) { if (!Modules.Contains(from)) throw new ModelException("Sender module not in graph"); if (!Modules.Contains(to)) throw new ModelException("Receiver module not in graph"); if (from.Definition.OutChannels == 0) throw new ModelException("Module {0} has no output", from.Name); if (paramName == null) // connect to input { if (to.Definition.InChannels == 0) throw new ModelException("Module {0} has no input", to.Name); if (to.Definition.InChannels != from.Definition.OutChannels) throw new ModelException("Module {0} needs {1} input channels", to.Name, to.Definition.InChannels); if (to.Inputs[0] != null) throw new ModelException("Input of {0} is already connected", to.Name); to.Inputs[0] = from; } else // connect to parameter { if (from.Definition.OutChannels != 1) throw new ModelException("Module {0} needs 1 output channel", from.Name); var slot = Array.IndexOf(to.Definition.ParamNames, paramName)+1; if (slot <= 0) throw new ModelException("Module {0} has no parameter {1}", to.Name, paramName); if (to.Inputs[slot] != null) throw new ModelException("Param {0} of {1} is already connected", paramName, to.Name); to.Inputs[slot] = from; } }