/// <summary> /// Iterate through all DLLs in same location as the editor and load all non-abstract classes derived from NodeViewModel. /// </summary> public static void LoadNodeViewModels() { NodeViewModelsImpl.Clear(); NodeViewModelLookup.Clear(); // Go through each custom loaded type foreach (Type type in ExtensibilityUtils.Types) { if (!type.IsAbstract && type.IsSubclassOf(typeof(NodeViewModel))) { NodeViewModelsImpl.Add(type); } } foreach (Type viewModel in NodeViewModelsImpl) { NodeViewModelAttribute viewModelAttribute = viewModel.GetCustomAttribute <NodeViewModelAttribute>(); if (!NodeViewModelLookup.ContainsKey(viewModelAttribute.NodeType)) { NodeViewModelLookup.Add(viewModelAttribute.NodeType, (SpeechNode node) => { return(Activator.CreateInstance(viewModel, node) as NodeViewModel); }); } else { CelDebug.Fail("Duplicate view model type for node type " + viewModelAttribute.NodeType.Name); continue; } } }
/// <summary> /// Use the inputted node to create a view model from all the registered node view models. /// Returns null if no view model exists for the inputted node type. /// </summary> /// <param name="node"></param> /// <returns></returns> public static NodeViewModel CreateViewModel(SpeechNode node) { if (NodeViewModelLookup.ContainsKey(node.GetType())) { return(NodeViewModelLookup[node.GetType()](node) as NodeViewModel); } CelDebug.Fail("No node view model for inputted node type " + node.Name); return(null); }
public SpeechNodeViewModel(SpeechNode speechNode) { CelDebug.AssertNotNull(speechNode); Node = speechNode; // Have to set the name on the base view model otherwise it will not get refreshed in the UI when we create this view model base.Name = speechNode.Name; // Have to set the position on the base view model otherwise it will not get refreshed in the UI when we create this view model Position = new Point((int)speechNode.Position.X, (int)speechNode.Position.Y); // The node view model's position can be changed in the network, so we add a callback here to update the node's position too when that happens Changed.Subscribe(Observer.Create((IReactivePropertyChangedEventArgs <IReactiveObject> e) => { if (e.PropertyName == nameof(Position)) { Node.Position.X = (float)Position.X; Node.Position.Y = (float)Position.Y; } })); CreateInputPin <NodeInputViewModel>("Input"); CreateOutputPin <NodeOutputViewModel>("Output"); }