public RenamableLabel(IGraphElementModel graphElementModel, string text, Store store, Action <string> renameAction)
        {
            name = "renamableLabel";

            GraphElementModel = graphElementModel;
            Store             = store;

            m_RenameAction = renameAction;

            ClearClassList();

            m_Label = new Label()
            {
                text = text, name = "label"
            };
            Add(m_Label);

            m_TextField = new TextField {
                name = "textField", isDelayed = true
            };
            m_TextField.style.display = DisplayStyle.None;
            Add(m_TextField);

            var textInput = m_TextField.Q(TextField.textInputUssName);

            textInput.RegisterCallback <FocusOutEvent>(_ => OnEditTextFinished());

            RegisterCallback <MouseDownEvent>(OnMouseDownEvent);

            capabilities |= Capabilities.Renamable;

            this.AddManipulator(new ContextualMenuManipulator(OnContextualMenuEvent));
        }
示例#2
0
        public MacroNode(MacroRefNodeModel model, Store store, GraphView graphView) : base(model, store, graphView)
        {
            m_MacroModel = model;
            AddToClassList("macro");

            m_TitleElement             = this.MandatoryQ("title");
            m_TitleElement.pickingMode = PickingMode.Position;

            this.EnableRename();

            var clickable = new Clickable(DoAction);

            clickable.activators.Clear();
            clickable.activators.Add(
                new ManipulatorActivationFilter {
                button = MouseButton.LeftMouse, clickCount = 2
            });
            this.AddManipulator(clickable);

            IGraphElementModel elementModelToRename = m_Store.GetState().EditorDataModel.ElementModelToRename;

            if (elementModelToRename as MacroRefNodeModel == model)
            {
                ((VseGraphView)m_GraphView).UIController.ElementToRename = this;
            }
        }
 /// <summary>
 /// Remove all capabilities from a model.
 /// </summary>
 /// <param name="self">The model to remove capabilites from</param>
 public static void ClearCapabilities(this IGraphElementModel self)
 {
     if (self.Capabilities is List <Capabilities> capabilities)
     {
         capabilities.Clear();
     }
 }
        public void TryGetModelByGUIDWorks()
        {
            var graphModel          = m_GraphAsset.GraphModel;
            var node1               = graphModel.CreateNode <Type0FakeNodeModel>();
            var node2               = graphModel.CreateNode <Type0FakeNodeModel>();
            var edge                = graphModel.CreateEdge(node1.ExeInput0, node2.ExeOutput0);
            var placemat            = graphModel.CreatePlacemat(new Rect(100, 100, 300, 300));
            var stickyNote          = graphModel.CreateStickyNote(new Rect(-100, -100, 100, 100));
            var constant            = graphModel.CreateConstantNode(TypeHandle.Float, "constant", new Vector2(42, 42));
            var variableDeclaration = graphModel.CreateGraphVariableDeclaration(TypeHandle.Float, "varDecl", ModifierFlags.None, true);
            var variable            = graphModel.CreateVariableNode(variableDeclaration, new Vector2(-76, 245));
            var portal              = graphModel.CreateEntryPortalFromEdge(edge);
            var badge               = new BadgeModel(node1);

            graphModel.AddBadge(badge);

            var graphElements = new IGraphElementModel[] { node1, node2, edge, placemat, stickyNote, constant, variableDeclaration, variable, portal, badge };

            foreach (var element in graphElements)
            {
                Assert.IsTrue(graphModel.TryGetModelFromGuid(element.Guid, out var retrieved), element + " was not found");
                Assert.AreSame(element, retrieved);
            }

            graphModel.DeleteBadges();
            graphModel.DeleteEdges(new[] { edge });
            graphModel.DeleteNodes(new IInputOutputPortsNodeModel[] { node1, node2, constant, variable, portal }, true);
            graphModel.DeletePlacemats(new[] { placemat });
            graphModel.DeleteStickyNotes(new[] { stickyNote });
            graphModel.DeleteVariableDeclarations(new[] { variableDeclaration });
            foreach (var element in graphElements)
            {
                Assert.IsFalse(graphModel.TryGetModelFromGuid(element.Guid, out _), element + " was found after removal");
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ModelSerializedFieldField{TValue}"/> class.
        /// </summary>
        /// <param name="dispatcher">The dispatcher to use to dispatch commands when the field is edited.</param>
        /// <param name="model">The model that owns the field.</param>
        /// <param name="fieldName">The field name.</param>
        public ModelSerializedFieldField(
            Dispatcher dispatcher,
            IGraphElementModel model,
            string fieldName)
            : base(dispatcher, model, fieldName, null)
        {
            m_ValueGetter = MakeFieldValueGetter(Model, fieldName);

            switch (m_Field)
            {
            case null:
                break;

            case PopupField <string> _:
                m_Field.RegisterCallback <ChangeEvent <string>, ModelPropertyField <TValue> >(
                    (e, f) =>
                {
                    var newValue = Enum.Parse(typeof(TValue), e.newValue);
                    var command  = new SetModelFieldCommand(newValue, f.Model, fieldName);
                    f.Dispatcher.Dispatch(command);
                }, this);
                break;

            default:
                m_Field.RegisterCallback <ChangeEvent <TValue>, ModelPropertyField <TValue> >(
                    (e, f) =>
                {
                    var command = new SetModelFieldCommand(e.newValue, f.Model, fieldName);
                    f.Dispatcher.Dispatch(command);
                }, this);
                break;
            }
        }
示例#6
0
 static void Visit(IGraphElementModel model)
 {
     if (model is IUndoRedoAware u)
     {
         u.UndoRedoPerformed();
     }
 }
示例#7
0
 private GraphModelImpl(IGraphElementModel verticesModel, IGraphElementModel edgesModel, IGraphElementPropertyModel propertiesModel, IImmutableSet <Type> nativeTypes)
 {
     VerticesModel   = verticesModel;
     EdgesModel      = edgesModel;
     PropertiesModel = propertiesModel;
     NativeTypes     = nativeTypes;
 }
        public static void AssertIsGraphElementAsExpected(IGraphElementModel expected, IGraphElementModel actual, string elementId)
        {
            Assert.AreSame(expected.GetType(), actual.GetType(),
                           UnexpectedValueMessage("Type", elementId));

            Assert.AreEqual(expected.Capabilities, actual.Capabilities,
                            UnexpectedValueMessage(nameof(expected.Capabilities), elementId));
            Assert.AreEqual(expected.Color, actual.Color,
                            UnexpectedValueMessage(nameof(expected.Color), elementId));
            Assert.AreEqual(expected.HasUserColor, actual.HasUserColor,
                            UnexpectedValueMessage(nameof(expected.HasUserColor), elementId));

            if (expected is IHasTitle expectedTitle)
            {
                var actualTitle = actual as IHasTitle;
                Assert.IsNotNull(actualTitle, elementId);
                Assert.AreEqual(expectedTitle.Title, actualTitle.Title,
                                UnexpectedValueMessage(nameof(expectedTitle.Title), elementId));
            }

            if (expected is IHasProgress expectedProgress)
            {
                var actualProgress = actual as IHasProgress;
                Assert.IsNotNull(actualProgress, elementId);
                Assert.AreEqual(expectedProgress.HasProgress, actualProgress.HasProgress,
                                UnexpectedValueMessage(nameof(expectedProgress.HasProgress), elementId));
            }

            if (expected is ICollapsible expectedCollapsible)
            {
                var actualCollapsible = actual as ICollapsible;
                Assert.IsNotNull(actualCollapsible, elementId);
                Assert.AreEqual(expectedCollapsible.Collapsed, actualCollapsible.Collapsed,
                                UnexpectedValueMessage(nameof(expectedCollapsible.Collapsed), elementId));
            }

            if (expected is IResizable expectedResizable)
            {
                var actualResizable = actual as IResizable;
                Assert.IsNotNull(actualResizable, elementId);
                Assert.AreEqual(expectedResizable.PositionAndSize, actualResizable.PositionAndSize,
                                UnexpectedValueMessage(nameof(expectedResizable.PositionAndSize), elementId));
            }

            if (expected is IMovable expectedMovable)
            {
                var actualMovable = actual as IMovable;
                Assert.IsNotNull(actualMovable, elementId);
                Assert.AreEqual(expectedMovable.Position, actualMovable.Position,
                                UnexpectedValueMessage(nameof(expectedMovable.Position), elementId));
            }

            if (expected is IHasDeclarationModel expectedDeclarationModel)
            {
                var actualDeclarationModel = actual as IHasDeclarationModel;
                Assert.IsNotNull(actualDeclarationModel, elementId);
                Assert.AreEqual(expectedDeclarationModel.DeclarationModel.Guid, actualDeclarationModel.DeclarationModel.Guid,
                                UnexpectedValueMessage(nameof(expectedDeclarationModel.DeclarationModel), elementId));
            }
        }
示例#9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseModelUIPart"/> class.
 /// </summary>
 /// <param name="name">The name of the part.</param>
 /// <param name="model">The model displayed in this part.</param>
 /// <param name="ownerElement">The owner of the part.</param>
 /// <param name="parentClassName">The class name of the parent.</param>
 protected BaseModelUIPart(string name, IGraphElementModel model, IModelUI ownerElement, string parentClassName)
 {
     PartName          = name;
     m_Model           = model;
     m_OwnerElement    = ownerElement;
     m_ParentClassName = parentClassName;
 }
示例#10
0
 /// <summary>
 /// Removes a dependency between a model and a UI.
 /// </summary>
 /// <param name="model">The model side of the dependency.</param>
 /// <param name="ui">The UI side of the dependency.</param>
 public static void RemoveDependency(this IGraphElementModel model, IModelUI ui)
 {
     if (s_ModelDependencies.TryGetValue(model.Guid, out var uiList))
     {
         uiList.Remove(ui);
     }
 }
示例#11
0
 internal static Step GetFilterStepOrNone(this IGraphElementModel model, Type type,
                                          FilterLabelsVerbosity verbosity, Func <string[], Step> stepFactory)
 {
     return(model
            .TryGetFilterLabels(type, verbosity)
            .Map(stepFactory)
            .IfNone(NoneStep.Instance));
 }
        /// <summary>
        /// Creates a new instance of the <see cref="PortContainerPart"/> class.
        /// </summary>
        /// <param name="name">The name of the part.</param>
        /// <param name="model">The model displayed in this part.</param>
        /// <param name="ownerElement">The owner of the part.</param>
        /// <param name="parentClassName">The class name of the parent.</param>
        /// <returns>A new instance of <see cref="PortContainerPart"/>.</returns>
        public static PortContainerPart Create(string name, IGraphElementModel model, IModelUI ownerElement, string parentClassName)
        {
            if (model is IPortNodeModel)
            {
                return(new PortContainerPart(name, model, ownerElement, parentClassName));
            }

            return(null);
        }
        public static PrintResultPart Create(string name, IGraphElementModel model, IModelUI modelUI, string parentClassName)
        {
            if (model is MathResult)
            {
                return(new PrintResultPart(name, model, modelUI, parentClassName));
            }

            return(null);
        }
示例#14
0
        /// <summary>
        /// Creates a new instance of the <see cref="EditableTitlePart"/> class.
        /// </summary>
        /// <param name="name">The name of the part.</param>
        /// <param name="model">The model displayed in this part.</param>
        /// <param name="ownerElement">The owner of the part.</param>
        /// <param name="parentClassName">The class name of the parent.</param>
        /// <param name="multiline">Whether the text should be displayed on multiple lines.</param>
        /// <returns>A new instance of <see cref="EditableTitlePart"/>.</returns>
        public static EditableTitlePart Create(string name, IGraphElementModel model, IModelUI ownerElement, string parentClassName, bool multiline = false)
        {
            if (model is IHasTitle)
            {
                return(new EditableTitlePart(name, model, ownerElement, parentClassName, multiline));
            }

            return(null);
        }
示例#15
0
        /// <summary>
        /// Creates a new instance of the <see cref="FourWayResizerPart"/> class.
        /// </summary>
        /// <param name="name">The name of the part.</param>
        /// <param name="model">The model displayed in this part.</param>
        /// <param name="ownerElement">The owner of the part.</param>
        /// <param name="parentClassName">The class name of the parent.</param>
        /// <returns>A new instance of <see cref="FourWayResizerPart"/>.</returns>
        public static FourWayResizerPart Create(string name, IGraphElementModel model, IModelUI ownerElement, string parentClassName)
        {
            if (model is IResizable)
            {
                return(new FourWayResizerPart(name, model, ownerElement, parentClassName));
            }

            return(null);
        }
        /// <summary>
        /// Creates a new instance of the <see cref="NodeFieldsInspector"/> class.
        /// </summary>
        /// <param name="name">The name of the part.</param>
        /// <param name="model">The model displayed in this part.</param>
        /// <param name="ownerElement">The owner of the part.</param>
        /// <param name="parentClassName">The class name of the parent.</param>
        /// <returns>A new instance of <see cref="BlackboardHeaderPart"/>.</returns>
        public static NodeFieldsInspector Create(string name, IGraphElementModel model, IModelUI ownerElement, string parentClassName)
        {
            if (model is INodeModel)
            {
                return(new NodeFieldsInspector(name, model, ownerElement, parentClassName));
            }

            return(null);
        }
示例#17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IconTitleProgressPart"/> class.
        /// </summary>
        /// <param name="name">The name of the part.</param>
        /// <param name="model">The model displayed in this part.</param>
        /// <param name="ownerElement">The owner of the part.</param>
        /// <param name="parentClassName">The class name of the parent.</param>
        /// <returns>A new instance of <see cref="IconTitleProgressPart"/>.</returns>
        public static IconTitleProgressPart Create(string name, IGraphElementModel model, IModelUI ownerElement, string parentClassName)
        {
            if (model is INodeModel)
            {
                return(new IconTitleProgressPart(name, model, ownerElement, parentClassName));
            }

            return(null);
        }
        /// <summary>
        /// Creates a new instance of the <see cref="BlackboardHeaderPart"/> class.
        /// </summary>
        /// <param name="name">The name of the part.</param>
        /// <param name="model">The model displayed in this part.</param>
        /// <param name="ownerElement">The owner of the part.</param>
        /// <param name="parentClassName">The class name of the parent.</param>
        /// <returns>A new instance of <see cref="BlackboardHeaderPart"/>.</returns>
        public static BlackboardHeaderPart Create(string name, IGraphElementModel model, IModelUI ownerElement, string parentClassName)
        {
            if (model is IBlackboardGraphModel)
            {
                return(new BlackboardHeaderPart(name, model, ownerElement, parentClassName));
            }

            return(null);
        }
        /// <summary>
        /// Creates a new instance of the <see cref="PortConnectorWithIconPart"/> class.
        /// </summary>
        /// <param name="name">The name of the part.</param>
        /// <param name="model">The model displayed in this part.</param>
        /// <param name="ownerElement">The owner of the part.</param>
        /// <param name="parentClassName">The class name of the parent.</param>
        /// <returns>A new instance of <see cref="PortConnectorWithIconPart"/>.</returns>
        public new static PortConnectorWithIconPart Create(string name, IGraphElementModel model, IModelUI ownerElement, string parentClassName)
        {
            if (model is IPortModel && ownerElement is Port)
            {
                return(new PortConnectorWithIconPart(name, model, ownerElement, parentClassName));
            }

            return(null);
        }
        /// <summary>
        /// Creates a new instance of the <see cref="CollapseButtonPart"/> class.
        /// </summary>
        /// <param name="name">The name of the part.</param>
        /// <param name="model">The model displayed in this part.</param>
        /// <param name="ownerElement">The owner of the part.</param>
        /// <param name="parentClassName">The class name of the parent.</param>
        /// <returns>A new instance of <see cref="CollapseButtonPart"/>.</returns>
        public static CollapseButtonPart Create(string name, IGraphElementModel model, IModelUI ownerElement, string parentClassName)
        {
            if (model is ICollapsible)
            {
                return(new CollapseButtonPart(name, model, ownerElement, parentClassName));
            }

            return(null);
        }
        public static MathOperatorInspector Create(string name, IGraphElementModel model, IModelUI ownerElement, string parentClassName)
        {
            if (model is MathOperator)
            {
                return(new MathOperatorInspector(name, model, ownerElement, parentClassName));
            }

            return(null);
        }
        /// <summary>
        /// Creates a new instance of the <see cref="BlackboardVariablePart"/> class.
        /// </summary>
        /// <param name="name">The name of the part.</param>
        /// <param name="model">The model displayed in this part.</param>
        /// <param name="ownerElement">The owner of the part.</param>
        /// <param name="parentClassName">The class name of the parent.</param>
        /// <returns>A new instance of <see cref="BlackboardVariablePart"/>.</returns>
        public static BlackboardVariablePart Create(string name, IGraphElementModel model, IModelUI ownerElement, string parentClassName)
        {
            if (model is IVariableDeclarationModel)
            {
                return(new BlackboardVariablePart(name, model, ownerElement, parentClassName));
            }

            return(null);
        }
示例#23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IconTitleProgressPart"/> class.
 /// </summary>
 /// <param name="name">The name of the part.</param>
 /// <param name="model">The model displayed in this part.</param>
 /// <param name="ownerElement">The owner of the part.</param>
 /// <param name="parentClassName">The class name of the parent.</param>
 protected IconTitleProgressPart(string name, IGraphElementModel model, IModelUI ownerElement, string parentClassName)
     : base(name, model, ownerElement, parentClassName, multiline: false)
 {
     if (model.IsCollapsible())
     {
         var collapseButtonPart = NodeCollapseButtonPart.Create(collapseButtonPartName, model, ownerElement, ussClassName);
         PartList.AppendPart(collapseButtonPart);
     }
 }
        /// <summary>
        /// Creates a new <see cref="ContextBlocksPart"/>.
        /// </summary>
        /// <param name="name">The name of the part to create.</param>
        /// <param name="model">The model which the part represents.</param>
        /// <param name="ownerElement">The owner of the part to create.</param>
        /// <param name="parentClassName">The class name of the parent UI.</param>
        /// <returns>A new instance of <see cref="ContextBlocksPart"/>.</returns>
        public static ContextBlocksPart Create(string name, IGraphElementModel model, IModelUI ownerElement, string parentClassName)
        {
            if (model is IContextNodeModel contextModel)
            {
                return(new ContextBlocksPart(name, contextModel, ownerElement, parentClassName));
            }

            return(null);
        }
        /// <summary>
        /// Creates a new instance of the <see cref="EdgeControlPart"/> class.
        /// </summary>
        /// <param name="name">The name of the part.</param>
        /// <param name="model">The model displayed in this part.</param>
        /// <param name="ownerElement">The owner of the part.</param>
        /// <param name="parentClassName">The class name of the parent.</param>
        /// <returns>A new instance of <see cref="EdgeControlPart"/>.</returns>
        public static EdgeControlPart Create(string name, IGraphElementModel model, IModelUI ownerElement, string parentClassName)
        {
            if (model is IEdgeModel)
            {
                return(new EdgeControlPart(name, model, ownerElement, parentClassName));
            }

            return(null);
        }
示例#26
0
        public static TemperatureAndTimePart Create(string name, IGraphElementModel model, IModelUI modelUI, string parentClassName)
        {
            if (model is INodeModel)
            {
                return(new TemperatureAndTimePart(name, model, modelUI, parentClassName));
            }

            return(null);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="StickyNoteContentPart"/> class.
        /// </summary>
        /// <param name="name">The name of the part.</param>
        /// <param name="model">The model displayed in this part.</param>
        /// <param name="ownerElement">The owner of the part.</param>
        /// <param name="parentClassName">The class name of the parent.</param>
        /// <returns>A new instance of <see cref="StickyNoteContentPart"/>.</returns>
        public static StickyNoteContentPart Create(string name, IGraphElementModel model, IModelUI ownerElement, string parentClassName)
        {
            if (model is IStickyNoteModel)
            {
                return(new StickyNoteContentPart(name, model, ownerElement, parentClassName));
            }

            return(null);
        }
示例#28
0
        public static GraphElement CreateUI(GraphView graphView, Store store, IGraphElementModel model)
        {
            if (model == null)
            {
                Debug.LogError("GraphElementFactory could not create node because of a null reference model.");
                return(null);
            }

            var ext = ModelUtility.ExtensionMethodCache <INodeBuilder> .GetExtensionMethod(
                model.GetType(),
                NodeBuilder.FilterMethods,
                NodeBuilder.KeySelector
                );

            GraphElement newElem = null;

            if (ext != null)
            {
                var nodeBuilder = new NodeBuilder {
                    GraphView = graphView
                };
                newElem = (GraphElement)ext.Invoke(null, new object[] { nodeBuilder, store, model });
            }
            else if (model is INodeModel nodeModel)
            {
                newElem = new Node(nodeModel, store, graphView);
            }

            if (newElem == null)
            {
                Debug.LogError($"GraphElementFactory doesn't know how to create a node of type: {model.GetType()}");
            }
            else if (model is INodeModel nodeModel)
            {
                if (nodeModel.HasUserColor)
                {
                    (newElem as ICustomColor)?.SetColor(nodeModel.Color);
                }

                if (newElem is INodeState nodeState)
                {
                    if (nodeModel.State == ModelState.Disabled)
                    {
                        nodeState.UIState = NodeUIState.Disabled;
                    }
                    else
                    {
                        nodeState.UIState = NodeUIState.Enabled;
                    }
                    nodeState.ApplyNodeState();
                    nodeState.AddOverlay();
                }
            }

            return(newElem);
        }
示例#29
0
        protected static IGraphElementModel ExtractOutputPortModel(IGraphElementModel model)
        {
            if (model is ISingleOutputPortNodeModel outputPortHolder && outputPortHolder.OutputPort != null)
            {
                Debug.Assert(outputPortHolder.OutputPort.Direction == PortDirection.Output);
                return(outputPortHolder.OutputPort);
            }

            return(null);
        }
示例#30
0
        /// <summary>
        /// Adds a dependency between a model and a UI.
        /// </summary>
        /// <param name="model">The model side of the dependency.</param>
        /// <param name="ui">The UI side of the dependency.</param>
        public static void AddDependency(this IGraphElementModel model, IModelUI ui)
        {
            if (!s_ModelDependencies.TryGetValue(model.Guid, out var uiList))
            {
                uiList = new HashSet <IModelUI>();
                s_ModelDependencies[model.Guid] = uiList;
            }

            uiList.Add(ui);
        }