Exemple #1
0
        private bool OpenProject(string fileName)
        {
            MyLog.INFO.WriteLine("--------------");
            MyLog.INFO.WriteLine("Loading project: " + fileName);
            try
            {
                TextReader reader  = new StreamReader(fileName);
                string     content = reader.ReadToEnd();
                reader.Close();

                Project = MyProject.Deserialize(content, Path.GetDirectoryName(fileName));

                Properties.Settings.Default.LastProject = fileName;
                saveFileDialog.FileName      = fileName;
                m_savedProjectRepresentation = content;

                CloseAllGraphLayouts();
                CloseAllObservers();

                CreateNetworkView();
                OpenGraphLayout(Project.Network);

                if (Project.World != null)
                {
                    SelectWorldInWorldList(Project.World);
                }

                if (Project.Observers != null)
                {
                    foreach (MyAbstractObserver observer in Project.Observers)
                    {
                        observer.RestoreTargetFromIdentifier(Project);

                        if (observer.GenericTarget != null)
                        {
                            ShowObserverView(observer);
                        }
                    }
                }
                Project.Observers = null;

                exportStateButton.Enabled = MyMemoryBlockSerializer.TempDataExists(Project);
                clearDataButton.Enabled   = exportStateButton.Enabled;

                Text = TITLE_TEXT + " - " + Project.Name;
                return(true);
            }
            catch (Exception e)
            {
                MyLog.ERROR.WriteLine("Project loading failed: " + e.Message);
                return(false);
            }
        }
Exemple #2
0
        internal override void ValidateMandatory(MyValidator validator)
        {
            base.ValidateMandatory(validator);

            if (LoadOnStart || validator.Simulation.LoadAllNodesData)
            {
                if (MyMemoryBlockSerializer.TempDataExists(this))
                {
                    validator.AddInfo(this, "Node will load data from temporal storage.");
                }
                else if (DataFolder != null && DataFolder != String.Empty)
                {
                    validator.AddInfo(this, "Node will load data from user defined folder: " + DataFolder);
                }
                else if (validator.Simulation.LoadAllNodesData && !(String.IsNullOrEmpty(validator.Simulation.GlobalDataFolder)))
                {
                    validator.AddInfo(this, "Node will load data from user defined folder: "
                                      + validator.Simulation.GlobalDataFolder + "\\" + MyMemoryBlockSerializer.GetNodeFolder(this));
                }
                else if (validator.Simulation.LoadAllNodesData && (String.IsNullOrEmpty(validator.Simulation.GlobalDataFolder)))
                {
                    validator.AddInfo(this, "Node will load data from temporal storage.");
                }
                else
                {
                    validator.AddWarning(this, "LoadOnStart is active but no temporal data and no local or global data folder is set. Data will NOT be loaded.");
                }
            }

            validator.AssertInfo(!(SaveOnStop || validator.Simulation.SaveAllNodesData), this, "Node will save data to temporal storage before stop.");

            foreach (PropertyInfo pInfo in GetInfo().OwnedMemoryBlocks)
            {
                MyAbstractMemoryBlock mb = (pInfo.GetValue(this) as MyAbstractMemoryBlock);
                validator.AssertError(mb.Count >= 0, this, "Size of " + mb.Name + " memory block cannot be negative.");
            }

            List <PropertyInfo> inputBlocks = GetInfo().InputBlocks;

            for (int i = 0; i < inputBlocks.Count; i++)
            {
                PropertyInfo pInfo = inputBlocks[i];

                if (GetAbstractInput(i) != pInfo.GetValue(this))
                {
                    validator.AddError(this, "Incompatible memory block for \"" + pInfo.Name + "\" (" + GetAbstractInput(i).GetType().GenericTypeArguments[0].Name + " != " + pInfo.PropertyType.GenericTypeArguments[0].Name + ")");
                }
            }
        }
Exemple #3
0
        //TODO: this should be done by data binding but menu items cannot do that (add this support)
        void SimulationHandler_StateChanged(object sender, MySimulationHandler.StateEventArgs e)
        {
            runToolButton.Enabled          = SimulationHandler.CanStart;
            startToolStripMenuItem.Enabled = SimulationHandler.CanStart;

            pauseToolButton.Enabled        = SimulationHandler.CanPause;
            pauseToolStripMenuItem.Enabled = SimulationHandler.CanPause;

            stopToolButton.Enabled        = SimulationHandler.CanStop;
            stopToolStripMenuItem.Enabled = SimulationHandler.CanStop;


            debugToolButton.Enabled        = SimulationHandler.CanStartDebugging;
            debugToolStripMenuItem.Enabled = SimulationHandler.CanStartDebugging;

            stepOverToolButton.Enabled        = SimulationHandler.CanStepOver;
            stepOverToolStripMenuItem.Enabled = SimulationHandler.CanStepOver;

            stepIntoToolStripMenuItem.Enabled = SimulationHandler.CanStepInto;
            stepOutToolStripMenuItem.Enabled  = SimulationHandler.CanStepOut;

            reloadButton.Enabled = SimulationHandler.State == MySimulationHandler.SimulationState.STOPPED;

            simStatusLabel.Text = SimulationHandler.State.GetAttributeProperty((DescriptionAttribute x) => x.Description);

            //TODO: this is awful, binding is needed here for sure
            newProjectToolButton.Enabled        = SimulationHandler.State == MySimulationHandler.SimulationState.STOPPED;
            newProjectToolStripMenuItem.Enabled = SimulationHandler.State == MySimulationHandler.SimulationState.STOPPED;

            openProjectToolButton.Enabled        = SimulationHandler.State == MySimulationHandler.SimulationState.STOPPED;
            openProjectToolStripMenuItem.Enabled = SimulationHandler.State == MySimulationHandler.SimulationState.STOPPED;

            saveProjectToolButton.Enabled          = SimulationHandler.State == MySimulationHandler.SimulationState.STOPPED;
            saveProjectAsToolStripMenuItem.Enabled = SimulationHandler.State == MySimulationHandler.SimulationState.STOPPED;
            saveProjectToolStripMenuItem.Enabled   = SimulationHandler.State == MySimulationHandler.SimulationState.STOPPED;

            copySelectionToolStripMenuItem.Enabled = pasteSelectionToolStripMenuItem.Enabled =
                SimulationHandler.State == MySimulationHandler.SimulationState.STOPPED;

            worldList.Enabled = SimulationHandler.State == MySimulationHandler.SimulationState.STOPPED;

            NodePropertyView.CanEdit = SimulationHandler.State == MySimulationHandler.SimulationState.STOPPED;

            updateMemoryBlocksToolStripMenuItem.Enabled = SimulationHandler.State == MySimulationHandler.SimulationState.STOPPED;

            MemoryBlocksView.Enabled = SimulationHandler.State == MySimulationHandler.SimulationState.STOPPED ||
                                       SimulationHandler.State == MySimulationHandler.SimulationState.PAUSED;

            if (SimulationHandler.State == MySimulationHandler.SimulationState.STOPPED)
            {
                stepStatusLabel.Text  = String.Empty;
                statusStrip.BackColor = STATUS_BAR_BLUE;

                exportStateButton.Enabled = MyMemoryBlockSerializer.TempDataExists(Project);
                clearDataButton.Enabled   = exportStateButton.Enabled;
            }
            else if (SimulationHandler.State == MySimulationHandler.SimulationState.PAUSED)
            {
                statusStrip.BackColor = Color.Chocolate;
            }
            else
            {
                statusStrip.BackColor = STATUS_BAR_BLUE_BUILDING;
            }
            RefreshUndoRedoButtons();
        }