예제 #1
0
        private void GraphItemsOnCollectionChangedWith(NotifyCollectionChangedEventArgs changeArgs)
        {
            if (changeArgs.NewItems != null)
            {
                foreach (var item in changeArgs.NewItems.OfType <ViewModel>())
                {
                    if (item == null)
                    {
                        InvertApplication.Log("Graph Item is null");
                    }

                    var drawer = InvertGraphEditor.Container.CreateDrawer <IDrawer>(item);

                    if (drawer == null)
                    {
                        InvertApplication.Log("Drawer is null");
                    }

                    Children.Add(drawer);

                    _cachedChildren = Children.OrderBy(p => p.ZOrder).ToArray();
                    drawer.Refresh((IPlatformDrawer)InvertGraphEditor.PlatformDrawer);
                }
            }
            if (changeArgs.OldItems != null && changeArgs.OldItems.Count > 0)
            {
                var c = Children.Count;
                Children.RemoveAll(p => changeArgs.OldItems.Contains(p.ViewModelObject));
                var d = Children.Count;
                if (c != d)
                {
                    _cachedChildren = Children.OrderBy(p => p.ZOrder).ToArray();
                }
            }
        }
예제 #2
0
        public override void Initialize(UFrameContainer container)
        {
            base.Initialize(container);
            var path          = DbRootPath;
            var dbDirectories = Directory.GetDirectories(path, "*.db", SearchOption.AllDirectories);

            foreach (var item in dbDirectories)
            {
                var db     = new TypeDatabase(new JsonRepositoryFactory(item));
                var config = GetConfig(db, Path.GetFileNameWithoutExtension(item));
                config.FullPath = item;
                container.RegisterInstance <IGraphConfiguration>(config, config.Identifier);
            }

            CurrentConfiguration = Configurations.ContainsKey(CurrentDatabaseIdentifier)
                ? Configurations[CurrentDatabaseIdentifier]
                : Configurations.Values.FirstOrDefault();

            if (CurrentConfiguration != null)
            {
                container.RegisterInstance <IGraphConfiguration>(CurrentConfiguration);

                container.RegisterInstance <IRepository>(CurrentConfiguration.Database);

                //var typeDatabase = container.Resolve<IRepository>();
                CurrentConfiguration.Database.AddListener <IDataRecordInserted>(this);
                CurrentConfiguration.Database.AddListener <IDataRecordRemoved>(this);
                CurrentConfiguration.Database.AddListener <IDataRecordPropertyChanged>(this);
                CurrentConfiguration.Database.AddListener <IDataRecordPropertyBeforeChange>(this);
            }
            else
            {
                InvertApplication.Log("A uFrameDatabase doesn't exist.");
            }
        }
예제 #3
0
        public void Execute(BackgroundTaskCommand command)
        {
            BackgroundWorker worker = new BackgroundWorker()
            {
                WorkerSupportsCancellation = true,
                WorkerReportsProgress      = true
            };

            InvertApplication.Log("Creating background task");
            worker.DoWork += (sender, args) =>
            {
                InvertApplication.Log("Executing background task");
                var bgCommand = args.Argument as BackgroundTaskCommand;

                if (bgCommand != null)
                {
                    bgCommand.Command.Worker = sender as BackgroundWorker;
                    bgCommand.Action(bgCommand.Command);
                }
            };
            worker.ProgressChanged += (sender, args) =>
            {
                InvertApplication.Log("PROGRESS");
                InvertApplication.SignalEvent <ICommandProgressEvent>(_ => _.Progress(null, args.UserState.ToString(), args.ProgressPercentage));
            };
            command.Task = new BackgroundTask(worker);
            worker.RunWorkerAsync(command);
        }
예제 #4
0
        private void ImportPositionData(JSONClass positionData)
        {
            foreach (KeyValuePair <string, JSONNode> item in positionData)
            {
                if (item.Key == "_CLRType")
                {
                    continue;
                }
                var filterId = item.Key;
                foreach (KeyValuePair <string, JSONNode> positionItem in item.Value.AsObject)
                {
                    var filterItem = new FilterItem();
                    filterItem.FilterId = filterId;
                    filterItem.NodeId   = positionItem.Key;

                    var x = positionItem.Value["x"].AsInt;
                    var y = positionItem.Value["y"].AsInt;
                    InvertApplication.Log("Importing position ");
                    filterItem.Position  = new Vector2(x, y);
                    filterItem.Collapsed = true;

                    Repository.Add(filterItem);
                }
            }
        }
예제 #5
0
 public override void OnConnectedToInput(IConnectable input)
 {
     base.OnConnectedToInput(input);
     if (RelatedTypeNode != null)
     {
         InvertApplication.Log("OnConnectedToInput");
         //RelatedType = RelatedTypeNode.Identifier;
     }
 }
예제 #6
0
        public void Execute(TestyCommand command)
        {
            var sb = new StringBuilder();

            foreach (var item in InvertApplication.Plugins.OrderBy(p => p.Title))
            {
                sb.AppendLine(item.Title);
            }
            InvertApplication.Log(sb.ToString());
        }
예제 #7
0
 public void InitItemWindow <TItem>(IEnumerable <TItem> items, Action <TItem> action, bool allowNone = false)
     where TItem : IItem
 {
     InvertApplication.Log("InitItemWindow");
     ItemSelectionWindow.Init("Select Item", items.Cast <IItem>(), (item) =>
     {
         InvertApplication.Execute(() =>
         {
             action((TItem)item);
         });
     }, allowNone);
 }
예제 #8
0
        private IEnumerable <IDrawer> CreateDrawers()
        {
            InvertApplication.Log("Creating drawers");
            foreach (var item in ViewModel.ContentItems)
            {
                var drawer = InvertGraphEditor.Container.CreateDrawer(item);
                if (drawer == null)
                {
                    InvertApplication.Log(string.Format("Couldn't create drawer for {0} make sure it is registered.",
                                                        item.GetType().Name));
                    continue;
                }

                yield return(drawer);
            }
        }
예제 #9
0
        public override IEnumerable <IValueItem> GetAllowed()
        {
            var action = this.Node as IVariableContextProvider;

            if (action != null)
            {
                foreach (var item in action.GetAllContextVariables().Where(p => p.VariableType.IsAssignableTo(VariableType)))
                {
                    yield return(item);
                }
            }
            else
            {
                InvertApplication.Log("BS");
            }
        }
        private IEnumerable <OutputGenerator> CreateTemplateGenerators(IGraphConfiguration config, IDataRecord graphItem, Type templateType)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            if (graphItem == null)
            {
                throw new ArgumentNullException("graphItem");
            }
            if (templateType == null)
            {
                throw new ArgumentNullException("templateType");
            }

            var templateClassType = templateType.GetGenericArguments()[1];
            var templateAttribute = templateClassType.GetCustomAttributes(typeof(TemplateClass), true)
                                    .OfType <TemplateClass>()
                                    .FirstOrDefault();

            if (templateAttribute == null)
            {
                InvertApplication.Log(string.Format("ClassTemplate attribute not found on {0} ", templateClassType.Name));
                yield break;
            }


            if (templateAttribute.Location == TemplateLocation.DesignerFile || templateAttribute.Location == TemplateLocation.Both)
            {
                var template = Activator.CreateInstance(templateType) as CodeGenerator;
                template.ObjectData     = graphItem;
                template.IsDesignerFile = true;

                //template.AssetDirectory = graphItem.Graph.Project.SystemDirectory;
                template.AssetDirectory = config.CodeOutputPath;
                yield return(template);
            }
            if (templateAttribute.Location == TemplateLocation.EditableFile || templateAttribute.Location == TemplateLocation.Both)
            {
                var template = Activator.CreateInstance(templateType) as CodeGenerator;
                template.ObjectData     = graphItem;
                template.IsDesignerFile = false;
                template.AssetDirectory = config.CodeOutputPath;

                yield return(template);
            }
        }
예제 #11
0
        public static IDrawer CreateDrawer <TDrawerBase>(this IUFrameContainer container, ViewModel viewModel) where TDrawerBase : IDrawer
        {
            if (_drawers != null)
            {
            }
            if (viewModel == null)
            {
                InvertApplication.LogError("Data is null.");
                return(null);
            }
            var drawer = container.ResolveRelation <TDrawerBase>(viewModel.GetType(), new object[] { viewModel });

            if (drawer == null)
            {
                InvertApplication.Log(String.Format("Couldn't Create drawer for {0}.", viewModel.GetType()));
            }
            return(drawer);
        }
예제 #12
0
        public virtual bool CanConnect(IConnectable output, IConnectable input)
        {
            if (CanConnect(output.GetType(), input.GetType()))
            {
                if (output.GetType().Name == "ShellNodeConfig" && input.GetType().Name == "ShellNodeConfigInput")
                {
                    InvertApplication.Log("!!!!Bingo!!!!");
                    InvertApplication.Log("CanOutputTo : " + output.CanOutputTo(input));
                    InvertApplication.Log("CanInputFrom : " + input.CanInputFrom(output));
                }

                if (output.CanOutputTo(input) && input.CanInputFrom(output))
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #13
0
 private void OnAdd(NodeConfigSectionBase section, NodeConfigSectionBase section1, DiagramNodeViewModel vm)
 {
     InvertApplication.Log("OnAdd");
     if (section1.AllowAdding && section1.ReferenceType != null && !section1.HasPredefinedOptions)
     {
         SelectReferenceItem(section, section1);
     }
     else
     {
         if (section1.GenericSelector != null && section1.HasPredefinedOptions)
         {
             SelectFromOptions(section1, vm);
         }
         else
         {
             CreateNewSectionItem(section1, vm);
         }
     }
 }
예제 #14
0
 public void LoadDiagram(IGraphData diagram)
 {
     InvertGraphEditor.DesignerWindow = this;
     if (diagram == null)
     {
         return;
     }
     try
     {
         DiagramDrawer       = new DiagramDrawer(new DiagramViewModel(diagram));
         DiagramDrawer.Dirty = true;
         //DiagramDrawer.Data.ApplyFilter();
         DiagramDrawer.Refresh(InvertGraphEditor.PlatformDrawer);
     }
     catch (Exception ex)
     {
         InvertApplication.LogException(ex);
         InvertApplication.Log("Either a plugin isn't installed or the file could no longer be found. See Exception error");
     }
 }
예제 #15
0
        private static void GenerateFile(FileInfo fileInfo, CodeFileGenerator codeFileGenerator)
        {
            // Get the path to the directory
            var directory = System.IO.Path.GetDirectoryName(fileInfo.FullName);

            // Create it if it doesn't exist
            if (directory != null && !Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
            try
            {
                // Write the file
                File.WriteAllText(fileInfo.FullName, codeFileGenerator.ToString());
            }
            catch (Exception ex)
            {
                InvertApplication.LogException(ex);
                InvertApplication.Log("Coudln't create file " + fileInfo.FullName);
            }
        }
예제 #16
0
 public string GetNewVariableName(string prefix)
 {
     InvertApplication.Log("YUP");
     return(string.Format("{0}{1}", prefix, VariableCount++));
 }
        private void HandleInput(MouseEvent mouse)
        {
            var e = Event.current;

            if (e == null)
            {
                return;
            }
            if (DesignerWindow == null)
            {
                return;
            }

            MouseEvent.DefaultHandler = DesignerWindow.DiagramDrawer;

            var handler = MouseEvent.CurrentHandler;

            if (handler == null)
            {
                MouseEvent = null;

                InvertApplication.Log("Handler is null");
                return;
            }

            if (e.type == EventType.MouseDown)
            {
                mouse.MouseDownPosition = mouse.MousePosition;
                mouse.IsMouseDown       = true;
                mouse.MouseButton       = e.button;
                mouse.ContextScroll     = _scrollPosition;
                if (e.button == 1)
                {
                    e.Use();
                    handler.OnRightClick(mouse);
                }
                else if (e.clickCount > 1)
                {
                    handler.OnMouseDoubleClick(mouse);
                    mouse.IsMouseDown = false;
                }
                else
                {
                    handler.OnMouseDown(mouse);
                }
                InvertApplication.SignalEvent <IMouseDown>(_ => _.MouseDown(mouse));
                LastMouseDownEvent = e;
            }
            if (e.rawType == EventType.MouseUp)
            {
                mouse.MouseUpPosition = mouse.MousePosition;
                mouse.IsMouseDown     = false;
                handler.OnMouseUp(mouse);
                InvertApplication.SignalEvent <IMouseUp>(_ => _.MouseUp(mouse));
            }
            else if (e.rawType == EventType.KeyDown)
            {
            }
            else
            {
                var mp = (e.mousePosition);     // * (1f / 1f /* Scale */);

                mouse.MousePosition             = mp;
                mouse.MousePositionDelta        = mouse.MousePosition - mouse.LastMousePosition;
                mouse.MousePositionDeltaSnapped = mouse.MousePosition.Snap(12f * 1f /* Scale */) -
                                                  mouse.LastMousePosition.Snap(12f * 1f);
                handler.OnMouseMove(mouse);
                mouse.LastMousePosition = mp;
                if (e.type == EventType.MouseMove)
                {
                    e.Use();
                    //Signal<IRepaintWindow>(_=>_.Repaint());
                    //Repaint();
                }
            }

            if (LastEvent != null)
            {
                if (LastEvent.type == EventType.keyUp)
                {
                    if (LastEvent.keyCode == KeyCode.LeftShift || LastEvent.keyCode == KeyCode.RightShift)
                    {
                        mouse.ModifierKeyStates.Shift = false;
                    }
                    if (LastEvent.keyCode == KeyCode.LeftControl || LastEvent.keyCode == KeyCode.RightControl || LastEvent.keyCode == KeyCode.LeftCommand || LastEvent.keyCode == KeyCode.RightCommand)
                    {
                        mouse.ModifierKeyStates.Ctrl = false;
                    }
                    if (LastEvent.keyCode == KeyCode.LeftAlt || LastEvent.keyCode == KeyCode.RightAlt)
                    {
                        mouse.ModifierKeyStates.Alt = false;
                    }
                }
            }

            if (LastEvent != null)
            {
                if (LastEvent.type == EventType.keyDown)
                {
                    if (LastEvent.keyCode == KeyCode.LeftShift || LastEvent.keyCode == KeyCode.RightShift)
                    {
                        mouse.ModifierKeyStates.Shift = true;
                    }
                    if (LastEvent.keyCode == KeyCode.LeftControl || LastEvent.keyCode == KeyCode.RightControl || LastEvent.keyCode == KeyCode.LeftCommand || LastEvent.keyCode == KeyCode.RightCommand)
                    {
                        mouse.ModifierKeyStates.Ctrl = true;
                    }
                    if (LastEvent.keyCode == KeyCode.LeftAlt || LastEvent.keyCode == KeyCode.RightAlt)
                    {
                        mouse.ModifierKeyStates.Alt = true;
                    }
                }
                // Debug.Log(string.Format("Shift: {0}, Alt: {1}, Ctrl: {2}",ModifierKeyStates.Shift,ModifierKeyStates.Alt,ModifierKeyStates.Ctrl));
            }

            LastEvent = Event.current;

            if (DiagramDrawer.IsEditingField)
            {
                // TODO 2.0 Get this out of here
                if (LastEvent.keyCode == KeyCode.Return)
                {
                    var selectedGraphItem = DesignerWindow.DiagramViewModel.SelectedGraphItem;
                    DesignerWindow.DiagramViewModel.DeselectAll();
                    if (selectedGraphItem != null)
                    {
                        selectedGraphItem.Select();
                    }
                    return;
                }
                return;
            }


            var evt = Event.current;

            if (evt != null && evt.isKey && evt.type == EventType.KeyUp)
            {
                Signal <IKeyboardEvent>(_ =>
                {
                    if (_.KeyEvent(evt.keyCode, mouse.ModifierKeyStates))
                    {
                        evt.Use();
                    }
                });
            }
        }
예제 #18
0
 public void Progress(ICommand command, string message, float progress)
 {
     InvertApplication.Log(message);
 }
예제 #19
0
        public void Draw(float width, float height, Vector2 scrollPosition, float scale)
        {
            DiagramDrawer.IsEditingField = false;
            if (Drawer == null)
            {
                InvertApplication.Log("DRAWER IS NULL");
                return;
            }
            var diagramRect = new Rect();

            if (DrawToolbar)
            {
                var toolbarTopRect  = new Rect(0, 0, width, 18);
                var tabsRect        = new Rect(0, toolbarTopRect.height, width, 31);
                var breadCrumbsRect = new Rect(0, tabsRect.y + tabsRect.height, width, 30);

                diagramRect = new Rect(0f, breadCrumbsRect.y + breadCrumbsRect.height, width,
                                       height - ((toolbarTopRect.height * 2)) - breadCrumbsRect.height - 31);
                var toolbarBottomRect = new Rect(0f, diagramRect.y + diagramRect.height, width,
                                                 toolbarTopRect.height);


                List <DesignerWindowModalContent> modalItems = new List <DesignerWindowModalContent>();
                Signal <IQueryDesignerWindowModalContent>(_ => _.QueryDesignerWindowModalContent(modalItems));

                List <DesignerWindowOverlayContent> overlayItems = new List <DesignerWindowOverlayContent>();
                Signal <IQueryDesignerWindowOverlayContent>(_ => _.QueryDesignerWindowOverlayContent(overlayItems));

                //Disable diagram input if any modal content presents or if mouse is over overlay content
                _shouldProcessInputFromDiagram = !modalItems.Any() && overlayItems.All(i => !i.Drawer.CalculateBounds(diagramRect).Contains(Event.current.mousePosition));

                Drawer.DrawStretchBox(toolbarTopRect, CachedStyles.Toolbar, 0f);

                Drawer.DoToolbar(toolbarTopRect, this, ToolbarPosition.Left);
                //drawer.DoToolbar(toolbarTopRect, this, ToolbarPosition.Right);

                Drawer.DrawRect(tabsRect, InvertGraphEditor.Settings.GridLinesColor);

                //Drawer.DoTabs(Drawer,tabsRect, this);
                DiagramRect = diagramRect;

                /*
                 * DRAW DIAGRAM
                 * Using GUI.color hack to avoid transparent diagram on disabled input (Thanks Unity :( )
                 */

                if (!_shouldProcessInputFromDiagram)
                {
                    Drawer.DisableInput();
                }

                if (DiagramDrawer != null)
                {
                    DiagramDrawer.DrawTabs(Drawer, tabsRect);
                    DiagramDrawer.DrawBreadcrumbs(Drawer, breadCrumbsRect.y);
                }

                var fpsCounterRect = tabsRect.WithWidth(80).RightOf(tabsRect).Translate(-100, 0);

                if (ShowFPS)
                {
                    if ((DateTime.Now - _lastFpsUpdate).TotalMilliseconds > 1000)
                    {
                        _fpsShown      = _framesLastSec;
                        _lastFpsUpdate = DateTime.Now;
                        _framesLastSec = 0;
                    }
                    else
                    {
                        _framesLastSec++;
                    }
                    Drawer.DrawLabel(fpsCounterRect, string.Format("FPS: {0}", _fpsShown), CachedStyles.WizardSubBoxTitleStyle);
                }

                Drawer.DrawRect(diagramRect, InvertGraphEditor.Settings.BackgroundColor);

                DiagramRect = diagramRect;

                DrawDiagram(Drawer, scrollPosition, scale, diagramRect);

                Drawer.EnableInput();

                /*
                 * DRAW OVERLAY CONTENT
                 */

                if (modalItems.Any())
                {
                    Drawer.DisableInput();
                }

                foreach (var item in overlayItems)
                {
                    var bounds      = item.Drawer.CalculateBounds(diagramRect);
                    var isMouseOver = bounds.Contains(Event.current.mousePosition);

                    var colorCache = GUI.color;

                    if (!isMouseOver && !item.DisableTransparency)
                    {
                        GUI.color = new Color(colorCache.r, colorCache.g, colorCache.b, colorCache.a / 4);
                    }

                    item.Drawer.Draw(bounds);

                    GUI.color = colorCache;
                }

                Drawer.EnableInput();

                /*
                 * DRAW MODAL CONTENT
                 */

                if (modalItems.Any())
                {
                    var modalBackgroundRect = new Rect().Cover(breadCrumbsRect, tabsRect, diagramRect);
                    var modalContentRect    = new Rect().WithSize(800, 500).CenterInsideOf(modalBackgroundRect);
                    var activeModal         = modalItems.OrderBy(i => i.ZIndex).Last();

                    Drawer.DisableInput();

                    foreach (var source in modalItems.OrderBy(i => i.ZIndex).Except(new[] { activeModal }))
                    {
                        source.Drawer(modalContentRect);
                    }

                    Drawer.EnableInput();

                    Drawer.DrawRect(modalBackgroundRect, new Color(0, 0, 0, 0.8f));

                    activeModal.Drawer(modalContentRect);
                }


                DrawToolip(breadCrumbsRect);

                Drawer.DoToolbar(toolbarBottomRect, this, ToolbarPosition.BottomLeft);
                //drawer.DoToolbar(toolbarBottomRect, this, ToolbarPosition.BottomRight);
            }
            else
            {
                diagramRect = new Rect(0f, 0f, width, height);
                DiagramRect = diagramRect;
                DrawDiagram(Drawer, scrollPosition, scale, diagramRect);
            }

            InvertApplication.SignalEvent <IDesignerWindowEvents>(_ => _.AfterDrawDesignerWindow(new Rect(0, 0, width, height)));
            InvertApplication.SignalEvent <IDesignerWindowEvents>(_ => _.DrawComplete());
        }
예제 #20
0
        public void ImportData(JSONClass node)
        {
            var typeName = string.Empty;

            if (node["_CLRType"] != null)
            {
                typeName = node["_CLRType"].Value;
            }
            else if (node["Type"] != null)
            {
                typeName = node["Type"].Value;
            }
            var type = InvertApplication.FindType(typeName) ?? Type.GetType(typeName);

            if (type == null && typeName.StartsWith("ConnectionData"))
            {
                type = typeof(ConnectionData);
            }

            if (type != null)
            {
                var result = ImportType(type, node);

                if (result is IGraphData)
                {
                    var item = InvertApplication.Container.Resolve <WorkspaceService>();
                    if (item.CurrentWorkspace != null)
                    {
                        item.CurrentWorkspace.AddGraph(result as IGraphData);
                    }
                    CurrentGraph = result as InvertGraph;
                    CurrentGraph.RootFilterId = node["RootNode"]["Identifier"].Value;
                    Debug.Log("Set Root filter id to " + CurrentGraph.RootFilterId);
                }
                if (result is GraphNode)
                {
                    CurrentNode         = result as GraphNode;
                    CurrentNode.GraphId = CurrentGraph.Identifier;
                }
                if (result is DiagramNodeItem)
                {
                    ((IDiagramNodeItem)result).NodeId = CurrentNode.Identifier;
                }
                if (result is ITypedItem)
                {
                    // TODO Find type and replace it will fullname
                    ((ITypedItem)result).RelatedType = node["ItemType"].Value;
                }

                foreach (KeyValuePair <string, JSONNode> child in node)
                {
                    var array = child.Value as JSONArray;
                    if (array != null)
                    {
                        foreach (var item in array.Childs.OfType <JSONClass>())
                        {
                            ImportData(item);
                        }
                    }
                    var cls = child.Value as JSONClass;
                    if (cls != null)
                    {
                        if (child.Key == "FilterState")
                        {
                            continue;
                        }
                        if (child.Key == "Settings")
                        {
                            continue;
                        }
                        if (child.Key == "Changes")
                        {
                            continue;
                        }
                        if (child.Key == "PositionData")
                        {
                            ImportPositionData(cls);
                        }
                        else
                        {
                            if (child.Key == "RootNode")
                            {
                                InvertApplication.Log("Importing ROOT NODE");
                            }
                            ImportData(cls);
                        }
                    }
                }
            }
        }