protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider) { var container = (ExpressionTreeContainer) objectProvider.GetObject(); var strExpression = container.Expression.DeserializeExpression(); var graph = new ExpressionGraph(strExpression); var viewModel = new MainWindowViewModel(graph); MainWindow window = new MainWindow(viewModel); window.ShowDialog(); }
/// <summary> /// Updates the surface graph asset (save new one, discard cached data, reload asset). /// </summary> /// <param name="data">Surface data.</param> /// <returns>True if cannot save it, otherwise false.</returns> public static bool SaveSurface(JsonAsset asset, ExpressionGraph assetInstance, byte[] surfaceData) { if (!asset) { throw new ArgumentNullException(nameof(asset)); } assetInstance.VisjectSurface = surfaceData; bool success = FlaxEditor.Editor.SaveJsonAsset(asset.Path, assetInstance); asset.Reload(); return(success); }
/// <summary> /// Tries to load surface graph from the asset. /// </summary> /// <param name="createDefaultIfMissing">True if create default surface if missing, otherwise won't load anything.</param> /// <returns>Loaded surface bytes or null if cannot load it or it's missing.</returns> public static byte[] LoadSurface(JsonAsset asset, ExpressionGraph assetInstance, bool createDefaultIfMissing) { if (!asset) { throw new ArgumentNullException(nameof(asset)); } if (assetInstance == null) { throw new ArgumentNullException(nameof(assetInstance)); } // Return its data if (assetInstance.VisjectSurface?.Length > 0) { return(assetInstance.VisjectSurface); } // Create it if it's missing if (createDefaultIfMissing) { // A bit of a hack // Create a Visject Graph with a main node and serialize it! var surfaceContext = new VisjectSurfaceContext(null, null, new FakeSurfaceContext()); // Add the main node var node = NodeFactory.CreateNode(ExpressionGraphGroups, 1, surfaceContext, MainNodeGroupId, MainNodeTypeId); if (node == null) { Debug.LogWarning("Failed to create main node."); return(null); } surfaceContext.Nodes.Add(node); // Initialize node.Location = Vector2.Zero; surfaceContext.Save(); return(surfaceContext.Context.SurfaceData); } else { return(null); } }
public MainWindowViewModel(ExpressionGraph graph) { ExpressionGraph = graph; }
/// <inheritdoc /> public override void OnDestroy() { ExpressionGraph = null; base.OnDestroy(); }
/// <summary> /// Compiles the surface to an expression graph instance /// </summary> /// <param name="graph">Expression graph instance</param> public void CompileSurface(ExpressionGraph graph) { // We're mapping every output box to an index // So we can store the node outputs in an array var variableIndexGetter = new ExpressionGraphVariables(); // Get the parameters GetParameterGetterNodeArchetype(out ushort paramNodeGroupId); var graphParams = new Dictionary <Guid, VisjectGraphs.GraphParameter>(); for (int i = 0; i < Parameters.Count; i++) { var param = Parameters[i]; graphParams.Add(param.ID, new VisjectGraphs.GraphParameter(param.Name, i, param.Value, variableIndexGetter.RegisterNewVariable())); } // Set the parameters graph.Parameters = graphParams.Values.ToArray(); // Now go over the nodes (depth first) starting from the main node graph.Nodes = FindNode(MainNodeGroupId, MainNodeTypeId) .DepthFirstTraversal(true, true) // Turn surface nodes into graph nodes .Select(node => { // Internal node values object[] nodeValues = (node.Values ?? new object[0]).ToArray(); // Input boxes - Values object[] inputValues = node.Elements .OfType <InputBox>() .Select(inputBox => { // Input box has a value int valueIndex = inputBox.Archetype.ValueIndex; return((valueIndex != -1) ? nodeValues[valueIndex] : null); }) .ToArray(); // Input boxes - Indices int[] inputIndices = node.Elements .OfType <InputBox>() .Select(inputBox => { // Set the connections bool hasConnection = inputBox.HasAnyConnection; return((hasConnection) ? variableIndexGetter.UseInputBox(inputBox) : -1); }) .ToArray(); // Output boxes int[] outputIndices = node.Elements .OfType <OutputBox>() .Select(box => variableIndexGetter.RegisterOutputBox(box)) .ToArray(); int groupId = node.GroupArchetype.GroupID; int typeId = node.Archetype.TypeID; int methodId = 0; // Create the nodes if (groupId == MainNodeGroupId && typeId == MainNodeTypeId) { // Main node return(new MainNode(groupId, typeId, methodId, nodeValues, inputValues, inputIndices, outputIndices)); } else if (groupId == paramNodeGroupId) { // Parameter node var graphParam = graphParams[(Guid)node.Values[0]]; return(new GraphNode(groupId, typeId, methodId, new object[0], new object[1], new int[1] { graphParam.OutputIndex }, outputIndices)); } else { // Generic node return(new GraphNode(groupId, typeId, methodId, nodeValues, inputValues, inputIndices, outputIndices)); } }) .ToArray(); }
public abstract Exceptional<IExpressionGraph> TypeOperation(IExpressionGraph myLeftValueObject, IExpressionGraph myRightValueObject, DBContext dbContext, TypesOfBinaryExpression typeOfBinExpr, TypesOfAssociativity associativity, ExpressionGraph.IExpressionGraph result, bool aggregateAllowed = true);
public override Exceptional<IExpressionGraph> TypeOperation(AExpressionDefinition myLeftValueObject, AExpressionDefinition myRightValueObject, DBContext dbContext, TypesOfBinaryExpression typeOfBinExpr, TypesOfAssociativity associativity, ExpressionGraph.IExpressionGraph result, bool aggregateAllowed = true) { throw new NotImplementedException(); }