/// <inheritdoc />
        public override void OnDragPerform(DragPerformEvent e)
        {
            var dropElements = DragSource.GetSelection();

            var contentViewContainer = (e.target as GraphView)?.ContentViewContainer ?? e.target as VisualElement;

            var variablesToCreate = dropElements
                                    .OfType <IVariableDeclarationModel>()
                                    .Select((e1, i) => (
                                                e1,
                                                GUID.Generate().ToSerializableGUID(),
                                                contentViewContainer.WorldToLocal(e.mousePosition) + i * DragDropSpacer * Vector2.down))
                                    .ToList();

            var droppedNodes = dropElements.OfType <INodeModel>();

            if (droppedNodes.Any(e2 => !(e2 is IVariableNodeModel)) && variablesToCreate.Any())
            {
                // no way to handle this ATM
                throw new ArgumentException("Unhandled case, dropping blackboard/variables fields and nodes at the same time");
            }

            if (variablesToCreate.Any())
            {
                Stencil.OnDragAndDropVariableDeclarations(Dispatcher, variablesToCreate);
            }
        }
        /// <summary>
        /// Converts the errors generated by the processing of the graph to instances of <see cref="IGraphProcessingErrorModel"/>.
        /// </summary>
        /// <param name="stencil">The stencil.</param>
        /// <param name="results">The graph processing results used as the source of errors to convert.</param>
        /// <returns>The converted errors.</returns>
        public static IEnumerable <IGraphProcessingErrorModel> GetErrors(Stencil stencil, GraphProcessingResult results)
        {
            if (results?.Errors != null)
            {
                return(results.Errors.Select(stencil.CreateProcessingErrorModel).Where(m => m != null));
            }

            return(Enumerable.Empty <IGraphProcessingErrorModel>());
        }
Exemplo n.º 3
0
        public static void ShowVariableTypes(Stencil stencil, GraphToolState graphToolState, Vector2 position, Action <TypeHandle, int> callback)
        {
            var databases = stencil.GetSearcherDatabaseProvider()?.GetVariableTypesSearcherDatabases();

            if (databases != null)
            {
                ShowTypes(graphToolState, databases, position, callback);
            }
        }
Exemplo n.º 4
0
        public static void ShowEdgeNodes(Stencil stencil, GraphToolState graphToolState, IEdgeModel edgeModel, Vector2 position,
                                         Action <GraphNodeModelSearcherItem> callback)
        {
            var filter     = stencil.GetSearcherFilterProvider()?.GetEdgeSearcherFilter(edgeModel);
            var adapter    = stencil.GetSearcherAdapter(graphToolState.WindowState.GraphModel, "Insert Node");
            var dbProvider = stencil.GetSearcherDatabaseProvider();

            if (dbProvider == null)
            {
                return;
            }

            var dbs = dbProvider.GetGraphElementsSearcherDatabases(graphToolState.WindowState.GraphModel).ToList();

            ShowSearcher(graphToolState, position, callback, dbs, filter, adapter, Usage.k_CreateNode);
        }
Exemplo n.º 5
0
        public static void ShowOutputToGraphNodes(Stencil stencil, GraphToolState graphToolState, IEnumerable <IPortModel> portModels, Vector2 position,
                                                  Action <GraphNodeModelSearcherItem> callback)
        {
            var filter     = stencil.GetSearcherFilterProvider()?.GetOutputToGraphSearcherFilter(portModels);
            var adapter    = stencil.GetSearcherAdapter(graphToolState.WindowState.GraphModel, $"Choose an action for {portModels.First().DataTypeHandle.GetMetadata(stencil).FriendlyName}", portModels);
            var dbProvider = stencil.GetSearcherDatabaseProvider();

            if (dbProvider == null)
            {
                return;
            }

            var dbs = dbProvider.GetGraphElementsSearcherDatabases(graphToolState.WindowState.GraphModel).ToList();

            ShowSearcher(graphToolState, position, callback, dbs, filter, adapter, Usage.k_CreateNode);
        }
Exemplo n.º 6
0
        public static void ShowGraphNodes(Stencil stencil, GraphToolState graphToolState, Vector2 position, Action <GraphNodeModelSearcherItem> callback)
        {
            var filter     = stencil.GetSearcherFilterProvider()?.GetGraphSearcherFilter();
            var adapter    = stencil.GetSearcherAdapter(graphToolState.WindowState.GraphModel, "Add a graph node");
            var dbProvider = stencil.GetSearcherDatabaseProvider();

            if (dbProvider == null)
            {
                return;
            }

            var dbs = dbProvider.GetGraphElementsSearcherDatabases(graphToolState.WindowState.GraphModel)
                      .Concat(dbProvider.GetDynamicSearcherDatabases((IPortModel)null))
                      .ToList();

            ShowSearcher(graphToolState, position, callback, dbs, filter, adapter, Usage.k_CreateNode);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GraphElementSearcherDatabase"/> class.
 /// </summary>
 /// <param name="stencil">Stencil of the graph elements.</param>
 /// <param name="graphModel">GraphModel of the graph elements.</param>
 public GraphElementSearcherDatabase(Stencil stencil, IGraphModel graphModel)
 {
     Stencil      = stencil;
     Items        = new List <SearcherItem>();
     m_GraphModel = graphModel;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultSearcherDatabaseProvider"/> class.
 /// </summary>
 /// <param name="stencil">The stencil.</param>
 public DefaultSearcherDatabaseProvider(Stencil stencil)
 {
     m_Stencil = stencil;
 }