Beispiel #1
0
        public void AddModule(IGenericMenuCallback callback)
        {
            String name = callback.RequestString("Add Module", "Name for new module:");

            if (name != null)
            {
                bool           success;
                Transaction    xn   = new Transaction();
                IProjectAccess proj = xn.RequestWriteAccess(window.Project);
                using (xn.Start()) {
                    ProjectModule cur = proj.GetModule(name);
                    if (cur == null)
                    {
                        success = true;
                        proj.AddModule(name, new LayoutModel());
                    }
                    else
                    {
                        success = false;
                    }
                }
                if (!success)
                {
                    callback.Notify("Cannot Add", "Cannot add second module of same name.");
                }
            }
        }
Beispiel #2
0
 public ProjectListViewModel(SimpleContainer simpleContainer, IWindowManager windowManager, IEventAggregator eventAggregator,
                             IProjectAccess projectAccess, ICustomerAccess customerAccess)
 {
     _container      = simpleContainer;
     _projectAccess  = projectAccess;
     _customerAccess = customerAccess;
     _windowManager  = windowManager;
     eventAggregator.Subscribe(this);
 }
Beispiel #3
0
        public void RemoveModule(IGenericMenuCallback callback)
        {
            ProjectModule  toRemove      = window.CurrentModule;
            Transaction    xn            = new Transaction();
            IProjectAccess proj          = xn.RequestWriteAccess(window.Project);
            int            failureReason = 0;

            using (xn.Start()) {
                IEnumerator <ProjectModule> mods = proj.GetModules().GetEnumerator();
                int size;
                if (!mods.MoveNext())
                {
                    size = 0;
                }
                else
                {
                    if (!mods.MoveNext())
                    {
                        size = 1;
                    }
                    else
                    {
                        size = 2;
                    }
                }
                if (size == 1)
                {
                    failureReason = 1;
                }
                else
                {
                    bool success = proj.RemoveModule(toRemove);
                    if (!success)
                    {
                        failureReason = 2;
                    }
                }
            }
            if (failureReason == 1)
            {
                callback.Notify("Cannot Remove", "Cannot remove only module in project.");
            }
            else if (failureReason == 2)
            {
                callback.Notify("Cannot Remove", "Module not found within project.");
            }
        }
Beispiel #4
0
        public ToolboxModel(WindowModel window)
        {
            this.window = window;

            Transaction    xn   = new Transaction();
            IProjectAccess proj = xn.RequestReadAccess(window.Project);

            using (xn.Start()) {
                foreach (ProjectModule mod in proj.GetModules())
                {
                    string        modName = proj.GetModuleName(mod);
                    ToolboxModule toAdd   = new ToolboxModule(mod, modName);
                    if (mod == window.CurrentModule)
                    {
                        toAdd.SetName(toAdd.Name + "*");
                        currentModule = toAdd;
                    }
                    modules.Add(toAdd);
                }
            }
            window.Project.ProjectModifiedEvent += RefreshModules;

            List <ToolboxItem> builtins = new List <ToolboxItem>();

            Component[] masters =
            {
                new AndGate(),
                new OrGate(),
                new NotGate(),
                new ToggleSwitch(),
                new Led(),
                new Pin(),
                new PinOut()
            };
            foreach (Component master in masters)
            {
                builtins.Add(new ToolboxComponent(master));
            }

            List <ToolboxDrawer> drawers = new List <ToolboxDrawer>();

            drawers.Add(new ToolboxDrawer("Project", modules.AsReadOnly()));
            drawers.Add(new ToolboxDrawer("Built-Ins", builtins.AsReadOnly()));
            this.drawers = drawers.AsReadOnly();
        }
Beispiel #5
0
        public WindowModel()
        {
            this.Project = new Project();
            Transaction    xn   = new Transaction();
            IProjectAccess proj = xn.RequestWriteAccess(this.Project);
            ProjectModule  currentModule;

            using (xn.Start()) {
                currentModule = proj.AddModule("main", new LayoutModel());
            }

            this.LayoutCanvas = new LayoutCanvasModel(this);
            this.ToolboxModel = new ToolboxModel(this);
            this.ToolbarModel = new ToolbarModel(this);
            this.simThread    = null;

            menus.Add(new ProjectMenu(this));
            SetView(currentModule);
        }
Beispiel #6
0
        public void SelectItem(ToolboxItem item)
        {
            Component master;

            if (item is ToolboxComponent)
            {
                master = ((ToolboxComponent)item).Component;
            }
            else if (item is ToolboxModule)
            {
                ProjectModule module = ((ToolboxModule)item).Module;
                if (module == window.CurrentModule)
                {
                    OnToolboxChanged(ToolboxChangedArgs.ChangeTypes.ItemUnselected, item);
                    master = null;
                }
                else
                {
                    master = new ModuleComponent(module, () => {
                        Transaction xn      = new Transaction();
                        IProjectAccess proj = xn.RequestReadAccess(window.Project);
                        using (xn.Start()) {
                            return(proj.GetModuleName(module));
                        }
                    });
                }
            }
            else
            {
                master = null;
            }
            if (master != null)
            {
                window.BeginAdd(master, () => {
                    OnToolboxChanged(ToolboxChangedArgs.ChangeTypes.ItemUnselected, item);
                });
            }
        }
Beispiel #7
0
        public ProjectDetailsViewModel_Tests()
        {
            var customersList = GenerateCustomersName();

            var customerAccessMock = new Mock <ICustomerAccess>();

            customerAccessMock
            .Setup(x => x.GetCustomersName())
            .ReturnsAsync(customersList);

            _customerAccess = customerAccessMock.Object;


            var projectAccessMock = new Mock <IProjectAccess>();

            projectAccessMock
            .Setup(x => x.UpdateProject(It.IsAny <Project>()))
            .ReturnsAsync(true);

            _projectAccess = projectAccessMock.Object;

            _events = new EventAggregator();
        }
Beispiel #8
0
        public void RenameModule(IGenericMenuCallback callback)
        {
            ProjectModule toRename = window.CurrentModule;
            String        name     = callback.RequestString("Rename Module", "New name for module:");

            if (name != null)
            {
                name = name.Trim();
                if (name == "")
                {
                    callback.Notify("Cannot Rename", "Module cannot have an empty name.");
                }
                else
                {
                    bool           success;
                    Transaction    xn   = new Transaction();
                    IProjectAccess proj = xn.RequestWriteAccess(window.Project);
                    using (xn.Start()) {
                        ProjectModule cur = proj.GetModule(name);
                        if (cur == null)
                        {
                            success = true;
                            proj.SetModuleName(toRename, name);
                        }
                        else
                        {
                            success = false;
                        }
                    }
                    if (!success)
                    {
                        callback.Notify("Cannot Rename", "Cannot add second module of same name.");
                    }
                }
            }
        }
Beispiel #9
0
 public XamlReferencesReader(IProjectAccess projectAccess)
 {
     _projectAccess = projectAccess;
 }
 public ProjectDetailsViewModel(IEventAggregator eventAggregator, ICustomerAccess customerAccess, IProjectAccess projectAccess)
 {
     _events         = eventAggregator;
     _customerAccess = customerAccess;
     _projectAccess  = projectAccess;
 }
 public ReferencesEditor(IProjectAccess projectAccess)
 {
     _projectAccess = new CachedProjectAccess(projectAccess);
 }
Beispiel #12
0
 public ProjectModifiedArgs(IProjectAccess access, ChangeTypes changeType, ProjectModule changedModule)
 {
     this.ProjectAccess = access;
     this.ChangeType = changeType;
     this.ChangedModule = changedModule;
 }
 public CachedProjectAccess(IProjectAccess projectAccess)
 {
     _projectAccess = projectAccess;
     _cache         = new Dictionary <string, string>();
 }
 public ProjectService(IProjectAccess access)
 {
     this._memberAccess = access;
 }
Beispiel #15
0
        private void RefreshModules(object src, ProjectModifiedArgs args)
        {
            ProjectModule changedModule = args.ChangedModule;
            ToolboxItem   changedItem   = null;
            ProjectModule currentModule = window.CurrentModule;

            Transaction    xn   = new Transaction();
            IProjectAccess proj = xn.RequestReadAccess(window.Project);

            using (xn.Start()) {
                Dictionary <ProjectModule, ToolboxModule> oldItems = new Dictionary <ProjectModule, ToolboxModule>();
                List <ToolboxModule> newModules = new List <ToolboxModule>();
                foreach (ToolboxModule item in modules)
                {
                    oldItems[item.Module] = item;
                    if (item.Module == changedModule)
                    {
                        changedItem = item;
                    }
                }
                foreach (ProjectModule mod in proj.GetModules())
                {
                    string curName = proj.GetModuleName(mod);
                    if (mod == currentModule)
                    {
                        curName = curName + "*";
                    }
                    ToolboxModule nextItem;
                    if (oldItems.TryGetValue(mod, out nextItem))
                    {
                        if (nextItem.Name != curName)
                        {
                            nextItem.SetName(curName);
                        }
                    }
                    else
                    {
                        nextItem = new ToolboxModule(mod, curName);
                    }
                    newModules.Add(nextItem);
                    if (nextItem.Module == changedModule)
                    {
                        changedItem = nextItem;
                    }
                }
                this.modules.Clear();
                foreach (ToolboxModule item in newModules)
                {
                    this.modules.Add(item);
                }
            }

            if (changedItem != null)
            {
                ToolboxChangedArgs.ChangeTypes changeType;
                bool found = true;
                switch (args.ChangeType)
                {
                case ProjectModifiedArgs.ChangeTypes.ModuleAdded:
                    changeType = ToolboxChangedArgs.ChangeTypes.ItemAdded;
                    break;

                case ProjectModifiedArgs.ChangeTypes.ModuleRemoved:
                    changeType = ToolboxChangedArgs.ChangeTypes.ItemRemoved;
                    break;

                case ProjectModifiedArgs.ChangeTypes.ModuleRenamed:
                    changeType = ToolboxChangedArgs.ChangeTypes.ItemRenamed;
                    break;

                default:
                    changeType = ToolboxChangedArgs.ChangeTypes.ItemAdded; // unused value to trick compiler
                    found      = false;
                    break;
                }
                if (found)
                {
                    OnToolboxChanged(changeType, changedItem);
                }
            }
        }