public static MetaOperator DuplicateOperatorTypeWithDialog(MetaOperator orgMetaOp) { var dialog = new Components.Dialogs.NewOperatorDialog(); dialog.Title = "Duplicate as new type"; dialog.XText.Text = String.Format("Do you really want to create a new Operator type derived from {0}?", orgMetaOp.Name); dialog.XNamespace.Text = orgMetaOp.Namespace; dialog.XName.Text = Utilities.GetDuplicatedTitle(orgMetaOp.Name); dialog.XName.SelectAll(); dialog.XDescription.Text = orgMetaOp.Description; dialog.ShowDialog(); if (dialog.DialogResult == false) { return(null); } // FIXME: shouldn't this be a command? var copiedMetaOp = orgMetaOp.Clone(dialog.XName.Text); copiedMetaOp.Description = dialog.XDescription.Text; copiedMetaOp.Namespace = dialog.XNamespace.Text; App.Current.Model.MetaOpManager.AddMetaOperator(copiedMetaOp.ID, copiedMetaOp); // copy presets to new type App.Current.OperatorPresetManager.CopyPresetsOfOpToAnother(orgMetaOp, copiedMetaOp); return(copiedMetaOp); }
public void RemoveOperator_SourceOperatorWithConnection_operatorAndConnectionRemoved() { var metaCompOp = new MetaOperator(Guid.NewGuid()); metaCompOp.AddOperator(MetaOperatorTests.CreateFloatMetaOperator(Guid.NewGuid())); metaCompOp.AddOperator(MetaOperatorTests.CreateFloatMetaOperator(Guid.NewGuid())); Operator op = metaCompOp.CreateOperator(Guid.NewGuid()); Operator float1 = op.InternalOps[0]; Operator float2 = op.InternalOps[1]; op.InsertConnectionAt(new Connection(float1, float1.Outputs[0], float2, float2.Inputs[0], 0)); Assert.AreEqual(float1.Outputs[0], float2.Inputs[0].Connections[0]); List <System.EventArgs> eventArgs = new List <System.EventArgs>(); op.ConnectionRemovedEvent += (o, e) => { eventArgs.Add(e); }; op.OperatorRemovedEvent += (o, e) => { eventArgs.Add(e); }; op.RemoveOperator(float1); Assert.AreEqual(2, eventArgs.Count); var connectionChangedEventArgs = eventArgs[0] as ConnectionChangedEventArgs; Assert.AreNotEqual(null, connectionChangedEventArgs); Assert.AreEqual(float1, connectionChangedEventArgs.Connection.SourceOp); Assert.AreEqual(float1.Outputs[0], connectionChangedEventArgs.Connection.SourceOpPart); Assert.AreEqual(float2, connectionChangedEventArgs.Connection.TargetOp); Assert.AreEqual(float2.Inputs[0], connectionChangedEventArgs.Connection.TargetOpPart); Assert.AreNotEqual(null, eventArgs[1] as OperatorChangedEventArgs); Assert.AreEqual(1, op.InternalOps.Count); Assert.AreEqual(float2, op.InternalOps[0]); Assert.AreEqual(0, float2.Inputs[0].Connections.Count); }
public void AddOperatorToWorkspace(MetaOperator metaOperator) { var compoGraphView = App.Current.MainWindow.CompositionView.CompositionGraphView; if (_showingPreview) { // we don't have to do anything, but prevent the preview comment to be undone //_showingPreview = false; } else { compoGraphView.AddOperatorAtPosition(metaOperator, RelavantPositionOnWorkspace); } // Don't close window when ALT is pressed if (Keyboard.Modifiers.HasFlag(ModifierKeys.Alt)) { _showingPreview = false; return; } // Make sure the Parameter view gets refreshed App.Current.MainWindow.XParameterView.PreventUIUpdate = false; if (_showingPreview) { _showingPreview = false; var newElement = compoGraphView.SelectionHandler.SelectedElements.ToList(); compoGraphView.SelectionHandler.Clear(); // To trigger an update we have to clear the list first compoGraphView.SelectionHandler.SetElements(newElement); } Close(); compoGraphView.Focus(); }
public void ShowOpDescription(MetaOperator metaOperator) { if (metaOperator == null) { XName.Text = ""; XNamespace.Text = ""; XDescription.Text = ""; } else { XName.Text = metaOperator.Name; XNamespace.Text = metaOperator.Namespace; XDescription.Text = metaOperator.Description; } // Show preview if (XPreviewCheckbox.IsChecked.Value) { _showingPreview = true; App.Current.MainWindow.XParameterView.PreventUIUpdate = true; var compoGraphView = App.Current.MainWindow.CompositionView.CompositionGraphView; _selectionBeforePreview = compoGraphView.SelectedElements; compoGraphView.AddOperatorAtPosition(metaOperator, RelavantPositionOnWorkspace); } }
private string GenerateSetup(MetaOperator metaOp, MetaOperatorPart codeMetaOpPart) { var lines = new List <string>(); var metaInputOpParts = metaOp.GetOrderedInputs(); var imageMetaInputOpParts = (from p in metaInputOpParts where p.OpPart.Type == FunctionType.Image select p).ToList(); foreach (var input in imageMetaInputOpParts) { var inputName = Utilities.AdjustOpPartNameForCode(input.Name); lines.Add(string.Format("using (var {0}View = new ShaderResourceView(context.D3DDevice, {0}))", inputName)); } lines.Add("{"); lines.Add(" _effect.GetVariableByName(\"RenderTargetSize\").AsVector().Set(new Vector2(_usedViewport.Width, _usedViewport.Height));"); var inputGroups = from input in metaInputOpParts group input by input.Name.Split(new[] { '.' })[0] into g select new { Name = g.Key, Inputs = g.ToArray() }; foreach (var group in inputGroups) { var inputGroupName = Utilities.AdjustOpPartNameForCode(group.Name); switch (group.Inputs[0].OpPart.Type) { case FunctionType.Float: switch (group.Inputs.Length) { case 1: lines.Add(string.Format(" _effect.GetVariableByName(\"{0}\").AsScalar().Set({0});", inputGroupName)); break; case 2: case 3: case 4: string vectorParams = Utilities.AdjustOpPartNameForCode(group.Inputs[0].Name); for (int i = 1; i < group.Inputs.Length; ++i) { vectorParams += ", " + Utilities.AdjustOpPartNameForCode(group.Inputs[i].Name); } lines.Add(string.Format(" _effect.GetVariableByName(\"{0}\").AsVector().Set(new Vector{1}({2}));", inputGroupName, group.Inputs.Length, vectorParams)); break; } break; case FunctionType.Image: lines.Add(string.Format(" _effect.GetVariableByName(\"{0}\").AsShaderResource().SetResource({0}View);", inputGroupName)); break; default: break; } } return(string.Join("\n", lines)); }
public void ShowOpDescription(MetaOperator metaOperator) { if (metaOperator == null) { XName.Text = ""; XNamespace.Text = ""; XDescription.Text = ""; XShowExampleButton.Visibility = Visibility.Hidden; return; } _exampleMetaOp = Utils.OpUtils.FindExampleOperator(metaOperator); XShowExampleButton.Visibility = _exampleMetaOp != null ? Visibility.Visible : Visibility.Hidden; XName.Text = metaOperator.Name; XNamespace.Text = metaOperator.Namespace; XDescription.Text = metaOperator.Description; // Show preview if (XPreviewCheckbox.IsChecked.Value) { _showingPreview = true; App.Current.MainWindow.XParameterView.PreventUIUpdate = true; var compoGraphView = App.Current.MainWindow.CompositionView.CompositionGraphView; _selectionBeforePreview = compoGraphView.SelectedElements; compoGraphView.AddOperatorAtPosition(metaOperator, RelavantPositionOnWorkspace); } }
public CopyOperatorsCommand(IEnumerable <Guid> opIdsToCopy, MetaOperator sourceCompositionOp, MetaOperator targetCompositionOp, Point basePosition) { _opIdsToCopy = opIdsToCopy; _sourceCompositionOp = sourceCompositionOp; _targetCompositionOp = targetCompositionOp; _basePosition = basePosition; }
public Operator(Guid id, MetaOperator metaOp, List <OperatorPart> inputs, List <OperatorPart> outputs, List <Operator> internalOps, List <OperatorPart> internalParts) { ID = id; Definition = metaOp; Inputs = inputs; Outputs = outputs; InternalOps = internalOps; InternalParts = internalParts; Name = ""; Position = new Point(100, 100); Width = 75; // This should be Grid.Size * 3 UpdateOutputIndices(); // Forward Modified-events of parameters as Manipulated-Event foreach (var opPart in Inputs.Union(Outputs).Union(InternalParts)) { opPart.Parent = this; opPart.ManipulatedEvent += (o, a) => EventExt.Raise(ModifiedEvent, this, EventArgs.Empty); } foreach (var op in InternalOps) { op.Parent = this; } ConnectTypeChangedHanderWith(Inputs); }
public void Replace_OperatorWithoutConnectionsWithOperatorWithoutConnections_NewOpHasInternalIdOfOldOp() { var internalOldID = Guid.NewGuid(); var floatMetaOld = OperatorTests.CreateMetaFloatWithoutConnections(); var floatMetaNew = OperatorTests.CreateMetaFloatWithoutConnections(); var metacompositionOp = new MetaOperator(Guid.NewGuid()); metacompositionOp.AddOperator(floatMetaOld, internalOldID); MetaManager.Instance.AddMetaOperator(metacompositionOp.ID, metacompositionOp); MetaManager.Instance.AddMetaOperator(floatMetaNew.ID, floatMetaNew); MetaManager.Instance.AddMetaOperator(floatMetaOld.ID, floatMetaOld); var replaceCommand = new ReplaceOperatorCommand(metacompositionOp, floatMetaOld, floatMetaNew, internalOldID); replaceCommand.Do(); Assert.AreEqual(metacompositionOp.Operators.Count, 1); Assert.IsFalse(metacompositionOp.Operators.ContainsKey(internalOldID)); Assert.AreEqual(metacompositionOp.Operators.Values.Count(value => value.Item1 == floatMetaNew), 1); Assert.AreEqual(metacompositionOp.Operators.Values.Count(value => value.Item1 == floatMetaOld), 0); MetaManager.Instance.RemoveMetaOperator(metacompositionOp.ID); MetaManager.Instance.RemoveMetaOperator(floatMetaNew.ID); MetaManager.Instance.RemoveMetaOperator(floatMetaOld.ID); }
private void ReplaceOperator(MetaOperator operatorToAdd, Guid idToAdd, Guid idToRemove) { var position = ParentOperator.Operators[idToRemove].Item2.Position; ParentOperator.RemoveOperator(idToRemove); ParentOperator.AddOperator(operatorToAdd, idToAdd); ParentOperator.Operators[idToAdd].Item2.Position = position; }
internal static bool IsSearchTextMatchingToMetaOp(MetaOperator metaOp, string searchText) { var pattern = searchText.Select((t, i) => searchText.Substring(i, 1)) .Where(subString => Regex.Match(subString, "[A-Z0-9_-]", RegexOptions.IgnoreCase) != Match.Empty) .Aggregate(".*", (current, subString) => current + (subString + ".*")); return(Regex.IsMatch(metaOp.Namespace + metaOp.Name, pattern, RegexOptions.IgnoreCase)); }
public static void WriteOpWithWriter(MetaOperator metaOp, TextWriter writer) { var json = new Json(); json.Writer = new JsonTextWriter(writer); json.Writer.Formatting = Formatting.Indented; json.WriteMetaOperator(metaOp); }
private void ReplacePopupOnSelectionChanged(object sender, SelectionChangedEventArgs e) { var selectedItem = e.AddedItems.Count > 0 ? e.AddedItems[0] as AutoCompleteEntry : null; if (selectedItem != null) { _metaOperatorToBeReplacedWith = selectedItem.MetaOperator; } }
public static Operator CreateEmptyOperator() { var metaOp = new MetaOperator(Guid.NewGuid()) { Name = "Empty" }; return(metaOp.CreateOperator(Guid.NewGuid())); }
public AddOperatorCommand(MetaOperator compositionOp, Guid opIDToAdd, double posX = 100, double posY = 100, double width = 100, bool visible = true, string instanceName = "") { _parentMetaID = compositionOp.ID; _opToAddMetaID = opIDToAdd; _addedOpInstanceID = Guid.NewGuid(); Position = new Point(posX, posY); Width = width; InstanceName = instanceName; _visible = visible; }
public void AddMetaOperator(Guid id, MetaOperator metaOp) { if (_metaOperators.ContainsKey(id)) { Logger.Warn("operator definition ({0}) already added. skipped adding operator definition {1}.", id, metaOp.Name); } else { _metaOperators.Add(id, metaOp); ChangedEvent(this, EventArgs.Empty); } }
public ReplaceOperatorCommand(MetaOperator parentMetaOp, MetaOperator oldOperator, MetaOperator newOperator, Guid internalOldID, Guid internalNewID = new Guid()) { _parentMetaOpID = parentMetaOp.ID; _oldOperatorID = oldOperator.ID; _newOperatorID = newOperator.ID; _internalOldID = internalOldID; _internalNewID = internalNewID != Guid.Empty ? internalNewID : Guid.NewGuid(); _outgoingConnections = parentMetaOp.Connections.Where(connection => connection.SourceOpID == _internalOldID).ToArray(); _ingoingConnections = parentMetaOp.Connections.Where(connection => connection.TargetOpID == internalOldID).ToArray(); FillNewInputs(); FillNewOutputs(); }
public void EndShowOpDescription(MetaOperator metaOperator) { // Undo preview if (_showingPreview) { App.Current.MainWindow.XParameterView.PreventUIUpdate = true; App.Current.UndoRedoStack.Undo(); var compoGraphView = App.Current.MainWindow.CompositionView.CompositionGraphView; compoGraphView.SelectedElements = _selectionBeforePreview; App.Current.MainWindow.XParameterView.PreventUIUpdate = false; _showingPreview = false; } }
public static MetaOperator FindExampleOperator(MetaOperator metaOp) { foreach (var potentialExample in App.Current.Model.MetaOpManager.MetaOperators.Values) { if (potentialExample.Name != metaOp.Name + "Example" && potentialExample.Name != metaOp.Name + "Examples") { continue; } return(potentialExample); } return(null); }
public MetaOperator ReadMetaOperator(MetaManager metaManager) { var o = JObject.ReadFrom(Reader); var name = o["Name"].Value <string>(); var id = Guid.Parse(o["_id"].Value <string>()); var rev = o.Value <string>("_rev"); if (rev == null) { rev = string.Empty; } var namesp = o["Namespace"].Value <string>(); var description = o["Description"].Value <string>(); var inputs = (from i in ((JArray)o["Inputs"]) let metaInput = BuildMetaInput(metaManager, i) select metaInput).ToList(); var outputs = (from output in ((JArray)o["Outputs"]) let metaOutput = BuildMetaOutput(metaManager, output) select metaOutput).ToList(); var operators = (from op in ((JArray)o["Operators"]) let metaOp = BuildMetaOperator(metaManager, op) select metaOp).ToDictionary(e => { return(e.Item1); }, e => { return(e.Item2); }); var connections = (from c in ((JArray)o["Connections"]) let metaConnection = BuildMetaConnection(c) select metaConnection).ToList(); var newMetaOp = new MetaOperator(id) { Revision = rev, Name = name, Inputs = inputs, Outputs = outputs, Operators = operators, Connections = connections, Description = description, Namespace = namesp, }; // the loading order matters here, operator parts potentially need the parent op (newMetaOp) in // order to determine which supplier assembly need to be loaded var opParts = (from opPart in ((JArray)o["OperatorParts"]) let metaOpPart = BuildMetaOpPart(metaManager, newMetaOp, opPart) select metaOpPart).ToList(); newMetaOp.OperatorParts = opParts; newMetaOp.CheckForInconsistencyAndFixThem(); newMetaOp.Changed = false; // must be set after inconsistencies have been fixed! return(newMetaOp); }
public TransformGizmo() { MetaOperator sceneTransformGizmoDefinition = MetaManager.Instance.GetMetaOperator(Guid.Parse("2e56b389-a983-42fe-a015-61d9f9532af4")); _sceneTransformGizmoOperator = sceneTransformGizmoDefinition.CreateOperator(Guid.Empty); GizmoParts = new GizmoPart[] { new AxisGizmoPart(0, Vector3.Zero, Vector3.UnitX, new[] { _translateXParam, _translateYParam, _translateZParam }), new AxisGizmoPart(1, Vector3.Zero, Vector3.UnitY, new[] { _translateXParam, _translateYParam, _translateZParam }), new AxisGizmoPart(2, Vector3.Zero, Vector3.UnitZ, new[] { _translateXParam, _translateYParam, _translateZParam }), new PlaneGizmoPart(3, Vector3.Zero, new Vector3(1, 1, 0), new[] { _translateXParam, _translateYParam, _translateZParam }), new PlaneGizmoPart(4, Vector3.Zero, new Vector3(1, 0, 1), new[] { _translateXParam, _translateYParam, _translateZParam }), new PlaneGizmoPart(5, Vector3.Zero, new Vector3(0, 1, 1), new[] { _translateXParam, _translateYParam, _translateZParam }), }; }
public void Replace_OperatorWith1InWithOperatorWith1In_ConnectionHasSameSourceAndNewOpAsTarget() { var internalSourceID = Guid.NewGuid(); var targetOpPartID = Guid.NewGuid(); var sourceOpPartID = Guid.NewGuid(); var connectionSourceOp = new MetaOperator(internalSourceID); var metaOutput = new MetaOutput(sourceOpPartID, "targetOutput", new MetaOperatorPart(Guid.NewGuid())); connectionSourceOp.AddOutput(metaOutput); var internalOldID = Guid.NewGuid(); var floatMetaOld = OperatorTests.CreateMetaFloatWithoutConnections(); var floatInput = new MetaInput(targetOpPartID, "targetInputOld", new MetaOperatorPart(Guid.NewGuid()), new Float(5.0f), false); floatMetaOld.AddInput(floatInput); var floatMetaNew = OperatorTests.CreateMetaFloatWithoutConnections(); floatMetaNew.AddInput(new MetaInput(Guid.NewGuid(), "targetInputNew", new MetaOperatorPart(Guid.NewGuid()), new Float(5.0f), false)); var metacompositionOp = new MetaOperator(Guid.NewGuid()); metacompositionOp.AddOperator(connectionSourceOp); metacompositionOp.AddOperator(floatMetaOld, internalOldID); metacompositionOp.Connections = new[] { new MetaConnection(internalSourceID, sourceOpPartID, internalOldID, targetOpPartID) }.ToList(); MetaManager.Instance.AddMetaOperator(floatMetaOld.ID, floatMetaOld); MetaManager.Instance.AddMetaOperator(floatMetaNew.ID, floatMetaNew); MetaManager.Instance.AddMetaOperator(metacompositionOp.ID, metacompositionOp); var replaceCommand = new ReplaceOperatorCommand(metacompositionOp, floatMetaOld, floatMetaNew, internalOldID); replaceCommand.Do(); var targetID = metacompositionOp.Connections.ElementAt(0).TargetOpID; Assert.AreEqual(metacompositionOp.Connections.Count, 1); Assert.AreEqual(metacompositionOp.Operators[targetID].Item1, floatMetaNew); MetaManager.Instance.RemoveMetaOperator(metacompositionOp.ID); MetaManager.Instance.RemoveMetaOperator(floatMetaNew.ID); MetaManager.Instance.RemoveMetaOperator(floatMetaOld.ID); }
public static MetaOperator CreateSubMetaOp(float inputValue1, float inputValue2) { var input0 = new MetaInput(Guid.Parse("{AA522720-BB43-449F-9EAC-2FA2B13822C6}"), "Input0", BasicMetaTypes.FloatMeta, new Float(inputValue1), false); var input1 = new MetaInput(Guid.Parse("{9FC79D4C-3639-4A44-9ED8-69E8C5FF3E05}"), "Input1", BasicMetaTypes.FloatMeta, new Float(inputValue2), false); var output = new MetaOutput(Guid.Parse("{82B5272B-4884-4622-8891-2A9465550E18}"), "Output", BasicMetaTypes.FloatMeta); var opPartID = Guid.Parse("{3A6EA1C9-F479-4D89-A117-286D4DA49BCF}"); var opPart = new MetaOperatorPart(Guid.Parse("{E6FA8A63-AAA5-4533-BC02-BD8E04157A2F}")) { IsMultiInput = true, Name = "Func", Type = FunctionType.Float }; var metaOp = new MetaOperator(Guid.Parse("{5732DB8C-A1CC-48E7-85E3-3B3428957AF5}")) { Name = "SimpleOp", Inputs = new[] { input0, input1 }.ToList(), Outputs = new[] { output }.ToList(), OperatorParts = new[] { new Tuple <Guid, MetaOperatorPart>(opPartID, opPart) }.ToList(), Connections = new[] { new MetaConnection(Guid.Empty, input0.ID, Guid.Empty, opPartID), new MetaConnection(Guid.Empty, input1.ID, Guid.Empty, opPartID), new MetaConnection(Guid.Empty, opPartID, Guid.Empty, output.ID) }.ToList() }; var script = @"using System; using System.Collections.Generic; namespace Framefield.Core.IDca9a3a0e_c1c7_42b6_a0e5_cdb4c61d0b18 { public class Class_Sub : OperatorPart.Function { public override OperatorPartContext Eval(OperatorPartContext context, List<OperatorPart> inputs, int outputIdx) { context.Value = input[0].Eval(context).Value - input[1].Eval(context).Value; return context; } } }"; opPart.Script = script; opPart.Compile(); return(metaOp); }
private void WriteMetaOperators(MetaOperator parentOp, Dictionary <Guid, Tuple <MetaOperator, MetaOperator.InstanceProperties> > operators) { Writer.WritePropertyName("Operators"); Writer.WriteStartArray(); foreach (var IdAndMetaOp in operators) { Writer.WriteStartObject(); Writer.WriteValue("Name", IdAndMetaOp.Value.Item1.Name); Writer.WriteValue("MetaInstanceID", IdAndMetaOp.Key); Writer.WriteValue("MetaID", IdAndMetaOp.Value.Item1.ID); Writer.WritePropertyName("OperatorProperties"); WriteOperatorInstanceProperties(parentOp, IdAndMetaOp.Key, IdAndMetaOp.Value.Item1, IdAndMetaOp.Value.Item2); Writer.WriteEndObject(); } ; Writer.WriteEndArray(); }
public void InsertConnectionAt_Inserting2ndConnectionAtIndex0ToMultiInput_connectionIsInsertedAtFront() { var metaCompOp = new MetaOperator(Guid.NewGuid()); metaCompOp.AddOperator(MetaOperatorTests.CreateGenericMultiInputMetaOperator()); metaCompOp.AddOperator(MetaOperatorTests.CreateFloatMetaOperator(Guid.NewGuid())); metaCompOp.AddOperator(MetaOperatorTests.CreateFloatMetaOperator(Guid.NewGuid())); Operator op = metaCompOp.CreateOperator(Guid.NewGuid()); Operator multiply = op.InternalOps[0]; Operator float1 = op.InternalOps[1]; Operator float2 = op.InternalOps[2]; op.InsertConnectionAt(new Connection(float1, float1.Outputs[0], multiply, multiply.Inputs[0], 0)); op.InsertConnectionAt(new Connection(float2, float2.Outputs[0], multiply, multiply.Inputs[0], 0)); Assert.AreEqual(multiply.Inputs[0].Connections[0], float2.Outputs[0]); }
private bool IsOperatorRelevantToProject(MetaOperator operatorDefinition) { if (operatorDefinition.Namespace.StartsWith("lib.")) { if (operatorDefinition.Namespace.Contains("._test")) { return(false); } return(true); } if (operatorDefinition.Namespace.StartsWith("examples.")) { return(true); } var CGV = App.Current.MainWindow.CompositionView.CompositionGraphView; // Projects-operators in Home if (operatorDefinition.Namespace.StartsWith("projects.") && operatorDefinition.Namespace.Split('.').Count() == 2 && GetCurrentCompositionOperator().Definition.Name == "Home") { return(true); } // Same project ? var projectNamespace = GetProjectFromNamespace(operatorDefinition.Namespace); if (projectNamespace != null && projectNamespace == GetCurrentProjectName()) { return(true); } // Current user // TODO:implement return(false); }
public void WriteMetaOperator(MetaOperator metaOp) { Writer.WriteStartObject(); Writer.WriteValue("Name", metaOp.Name); Writer.WriteValue("_id", metaOp.ID); if (metaOp.Revision != string.Empty) { Writer.WriteValue("_rev", metaOp.Revision); } Writer.WriteValue("Namespace", metaOp.Namespace); Writer.WriteValue("Description", metaOp.Description); WriteInputs(metaOp.Inputs); WriteOutputs(metaOp.Outputs); WriteMetaOperatorParts(metaOp.OperatorParts); WriteMetaOperators(metaOp, metaOp.Operators); WriteMetaConnections(metaOp.Connections); Writer.WriteEndObject(); }
private string GenerateOutputIds(MetaOperator metaOp, MetaOperatorPart codeMetaOpPart) { var lines = new List <string>(); var outputs = metaOp.GetOrderedOutputs().ToList(); outputs.Reverse(); if (outputs.Count > 0) { var outputName = Utilities.AdjustOpPartNameForCode(outputs[0].Name); lines.Insert(0, string.Format(" {0} = {1}", outputName, outputs.Count - 1)); } for (int i = 1; i < outputs.Count; ++i) { var outputName = Utilities.AdjustOpPartNameForCode(outputs[i].Name); lines.Insert(0, string.Format(" {0} = {1},", outputName, outputs.Count - 1 - i)); } lines.Insert(0, "{"); lines.Insert(0, "private enum OutputId"); lines.Add("}"); return(string.Join("\n", lines)); }
private string GenerateParameters(MetaOperator metaOp, MetaOperatorPart codeMetaOpPart) { var inputGroups = from input in metaOp.GetOrderedInputs() group input by input.Name.Split(new[] { '.' })[0] into g select new { Name = g.Key, Inputs = g.ToArray() }; var lines = new List <string>(); foreach (var group in inputGroups) { var inputGroupName = Utilities.AdjustOpPartNameForCode(group.Name); switch (group.Inputs[0].OpPart.Type) { case FunctionType.Float: switch (group.Inputs.Length) { case 1: lines.Add(string.Format("float {0};", inputGroupName)); break; case 2: case 3: case 4: lines.Add(string.Format("float{0} {1};", group.Inputs.Length, inputGroupName)); break; } break; case FunctionType.Image: lines.Add(string.Format("Texture2D {0};", inputGroupName)); break; default: break; } } return(string.Join("\n", lines)); }
/** Should be used when duplicating an Operator-Definition */ public void CopyPresetsOfOpToAnother(MetaOperator source, MetaOperator target) { int idx = 0; if (_operatorPresetsByMetaOpID.ContainsKey(source.ID)) { foreach (var srcPreset in _operatorPresetsByMetaOpID[source.ID]) { var newPreset = new OperatorPreset { MetaOperatorID = target.ID }; foreach (var srcEntry in srcPreset.ValuesByParameterID) { try { var srcInputIdx = (from input in source.Inputs where input.ID == srcEntry.Key select source.Inputs.IndexOf(input)).Single(); newPreset.ValuesByParameterID[target.Inputs[srcInputIdx].ID] = srcEntry.Value; } catch (Exception) { Logger.Warn("Could not copy preset parameter. This can happen when the preset contains obsolete parameters."); } } if (newPreset.ValuesByParameterID.Count > 0) { AddPreset(newPreset, idx++); } else { Logger.Debug("Skipped a preset without any matching parameters"); } } } FindAndShowPresetsForSelectedOp(); SaveAllPresets(); }