/// <summary>
 /// Loads the simulation node and creates a simulation master
 /// </summary>
 private void InitialiseSimulation(ILessonEntity openedLesson)
 {
     _loadedSimulationNode.InitialiseWith(_mainNode, openedLesson);
     _simulationMaster = new Master(_processingData.SfcEntity, _loadedSimulationNode);
     _loadedSimulationNode.SetupUi();
     _isExecutable = _simulationMaster.IsProgramSimulationValid();
 }
Пример #2
0
 /// <summary>
 /// Initializes the whole page. Called before the node is added to the tree by the lesson controller.
 /// </summary>
 public override void InitialiseWith(IMainNode mainNode, ILessonEntity openedLesson)
 {
     _digitalInputs  = GetNode <DigitalInputs>("UI/DigitalInputs");
     _digitalOutputs = GetNode <DigitalOutputs>("UI/DigitalOutputs");
     _analogueIO     = GetNode <AnalogueIO>("UI/AnalogueIO");
     _digitalInputs.SetupUi();
     _digitalOutputs.SetupUi();
     _analogueIO.SetupUi();
 }
Пример #3
0
 /// <summary>
 /// Initializes the whole page. Called before the node is added to the tree by the lesson controller.
 /// </summary>
 public override void InitialiseWith(IMainNode mainNode, ILessonEntity openedLesson)
 {
     CentralParticles = GetNode <CentralParticles>("CentralParticles");
     CentralParticles.Setup();
     EmergencyActors = GetNode <EmergencyActors>("EmergencyActors");
     EmergencyActors.Setup();
     _decoration = GetNode <DecorationNode>("DecorationNode");
     _decoration.Initialise();
 }
Пример #4
0
        /// <summary>
        /// Updates the BBCode description of the lesson entity.
        /// </summary>
        public void UpdateLessonEntity(ILessonEntity lessonEntity)
        {
            StringBuilder builder = new StringBuilder(100);

            builder.AppendLine("[center][b][u]Lesson Description[/u][/b][/center]");
            builder.AppendLine(lessonEntity.Description);
            builder.AppendLine("[center][b][u]Goal[/u][/b][/center]");
            builder.AppendLine(lessonEntity.Goal);
            GetNode <RichTextLabel>(LessonInfoLabelPath).BbcodeText = builder.ToString();
        }
        private static IDiagramSimulationMaster LoadSfc(ILessonEntity openedLesson, SimulationPage simulationPage)
        {
            SfcEntity sfcEntity = SfcEntity.TryLoadFromFile(openedLesson.TemporaryDiagramFilePath);

            if (sfcEntity == null)
            {
                return(null);
            }
            return(new Master(sfcEntity, simulationPage));
        }
Пример #6
0
 /// <summary>
 /// The given lesson will be forwarded to the main view to
 /// switch from the landing page to the editor.
 /// </summary>
 public void StartSelectedLesson(ILessonEntity selectedLesson)
 {
     if (_lessonView.PlantView.LoadedSimulationNode != null)
     {
         _landingPageNode.StartLesson(selectedLesson);
     }
     else
     {
         GD.PushWarning("could not load " + selectedLesson.Title);
     }
 }
 /// <summary>
 /// Initializes the whole sfc editor
 /// </summary>
 public override void InitialiseWith(IMainNode mainNode, ILessonEntity openedLesson)
 {
     _mainNode       = mainNode;
     _processingData = InitialisePlant(openedLesson);
     InitialiseDiagram(openedLesson);
     InitialiseSimulation(openedLesson);
     _breakpoints = new BreakpointManager(_simulationMaster, _sfc2dEditorNode);
     if (!_isExecutable)
     {
         GetNode <Label>(_errorLabelPath).Visible = true;
     }
 }
 /// <summary>
 /// Sets the texts and stores the lesson entity
 /// </summary>
 public void SetLessonInfo(ILessonEntity info, LessonSelectionGridNode gridController)
 {
     LessonEntity    = info;
     _gridController = gridController;
     SetTitle(info.Title);
     SetStars(info.Stars);
     if (string.IsNullOrEmpty(info.SimulationPath))
     {
         GetNode <Button>("LessonButton").Disabled = true;
         GetNode <Button>("LessonButton").MouseDefaultCursorShape = CursorShape.Forbidden;
     }
 }
        /// <summary>
        /// Initializes the whole test viewer. Called before the node is added to the tree by the lesson controller.
        /// </summary>
        public override void InitialiseWith(IMainNode mainNode, ILessonEntity openedLesson)
        {
            _openedLesson = openedLesson;

            _regularOperation = GetNode <RegularOperation>("Tests/RegularOperation");
            _regularOperation.InitialiseWith(mainNode, openedLesson);
            _startOpen = GetNode <StartOpen>("Tests/StartOpen");
            _startOpen.InitialiseWith(mainNode, openedLesson);
            _startPassing = GetNode <StartPassing>("Tests/StartPassing");
            _startPassing.InitialiseWith(mainNode, openedLesson);
            _noiseAndBlackout = GetNode <NoiseAndBlackout>("Tests/NoiseAndBlackout");
            _noiseAndBlackout.InitialiseWith(mainNode, openedLesson);
        }
        /// <summary>
        /// Loads the file and builds the SFC diagram
        /// </summary>
        private void InitialiseDiagram(ILessonEntity openedLesson)
        {
            _sfc2dEditorNode = GetNode <Sfc2dEditorNode>("HscRelative/Sfc2dViewer/Sfc2dEditor");
            _sfc2dEditorNode.InitializeEditor(_processingData, false);
            string filepath = openedLesson.TemporaryDiagramFilePath;
            bool   success  = _sfc2dEditorNode.TryLoadDiagram(filepath);

            if (!success)
            {
                GetNode <Label>(_errorLabelPath).Text    = "No file access permission in the lesson folder.";
                GetNode <Label>(_errorLabelPath).Visible = true;
            }
        }
 /// <summary>
 /// Loads all aviable lessons at the locations:
 /// res://lessons/ and as an alternative user://lessons
 /// If it does not exist we try to create a default directory at
 /// res://lessons/ and as an alternative user://lessons
 /// </summary>
 public static ILessonEntity[] LoadLessons()
 {
     string[] LessonPaths = GetLessonPaths();
     System.Array.Sort <string>(LessonPaths);
     ILessonEntity[] lessonEntities = new ILessonEntity[LessonPaths.Length];
     for (int i = 0; i < LessonPaths.Length; i++)
     {
         LessonEntity lessonData = new LessonEntity(LessonPaths[i]);
         lessonData.LoadFolderContent();
         lessonEntities[i] = lessonData;
     }
     return(lessonEntities);
 }
 /// <summary>
 /// Exchanges the current simulation view to the given simulation.
 /// </summary>
 public void UpdateLessonEntity(ILessonEntity lessonEntity)
 {
     if (LoadedSimulationNode != null && IsInstanceValid(LoadedSimulationNode))
     {
         LoadedSimulationNode.QueueFree();
         LoadedSimulationNode = null;
     }
     if (!string.IsNullOrEmpty(lessonEntity.SimulationPath))
     {
         LoadedSimulationNode = (SimulationPage)((PackedScene)GD.Load(lessonEntity.SimulationPath)).Instance();
         GetNode(ViewportPath).AddChild(LoadedSimulationNode);
     }
 }
        /// <summary>
        /// Loads the plant node and links the I/O Table
        /// </summary>
        private ProcessingData InitialisePlant(ILessonEntity openedLesson)
        {
            _lessonView = GetNode <LessonView>("HscRelative/LessonView");
            _lessonView.LoadAndShowInfo(openedLesson);
            _loadedSimulationNode = _lessonView.PlantView.LoadedSimulationNode;
            ProcessingData data = new ProcessingData
            {
                InputRegisters  = new StateTable(_loadedSimulationNode.SimulationOutput),
                OutputRegisters = new StateTable(_loadedSimulationNode.SimulationInput)
            };

            return(data);
        }
Пример #14
0
 /// <summary>
 /// Initializes the whole twat viewer. Called before the node is added to the tree by the lesson controller.
 /// </summary>
 public override void InitialiseWith(IMainNode mainNode, ILessonEntity openedLesson)
 {
     _simulation       = GetNode <MinimalSimulationExample>("MinimalSimulationExample");
     _simulationMaster = DiagramSimulationLoader.LoadTemp(openedLesson, _simulation);
     if (_simulationMaster != null)
     {
         _simulation.InitialiseWith(mainNode, openedLesson);
         _isExecutable = _simulationMaster.IsProgramSimulationValid();
     }
     else
     {
         _isExecutable = false;
     }
 }
        /// <summary>
        /// Loads the TemporaryDiagramFilePath and creates a simulation master from it.
        /// </summary>
        /// <param name="openedLesson">The opened lesson we want to create a simulation master from.</param>
        /// <param name="simulationPage">the target simulation page we want to control.</param>
        /// <returns>the simulation master if the data could be loaded. Null otherwise.</returns>
        public static IDiagramSimulationMaster LoadTemp(ILessonEntity openedLesson, SimulationPage simulationPage)
        {
            string tempFile = openedLesson.TemporaryDiagramFilePath;

            if (string.IsNullOrEmpty(tempFile))
            {
                return(null);
            }
            if (tempFile.EndsWith(SFC))
            {
                return(LoadSfc(openedLesson, simulationPage));
            }
            return(null);
        }
        private void OnFileSelected(string path)
        {
            ILessonEntity entity = Controller.SfcEditorNode.OpenedLesson;

            entity.CustomDiagramFilePath = ProjectSettings.GlobalizePath(path);
            if (Mode == ModeEnum.SaveFile)
            {
                Controller.SaveDiagram();
            }
            else
            {
                Controller.LoadDiagram();
            }
            Hide();
        }
        /// <summary>
        /// Initializes the whole page. Called before the node is added to the tree by the lesson controller.
        /// </summary>
        public override void InitialiseWith(IMainNode mainNode, ILessonEntity openedLesson)
        {
            _topTrafficLight = GetNode <TrafficControlSystem>("Signalisation/TrafficControlSystemTop");
            _topTrafficLight.SetToGreen(SimulationInput.PollBoolean(_topTrafficLightKey));
            _botTrafficLight = GetNode <TrafficControlSystem>("Signalisation/TrafficControlSystemBot");
            _botTrafficLight.SetToGreen(SimulationInput.PollBoolean(_botTrafficLightKey));
            PathController topPath = GetNode <PathController>("DynamicCars/TopPath");

            topPath.Setup(_topTrafficLight);
            PathController botPath = GetNode <PathController>("DynamicCars/BotPath");

            botPath.Setup(_botTrafficLight);
            _trafficController = new TrafficController(topPath, botPath);
            SpawnTimeGenerator.ResetGenerator();
        }
 /// <summary>
 /// Initializes the whole test viewer. Called before the node is added to the tree by the lesson controller.
 /// </summary>
 public void InitialiseWith(IMainNode mainNode, ILessonEntity openedLesson)
 {
     _simulation       = GetNode <ElectricalBarrier>("Viewport/ElectricalBarrier");
     _simulationMaster = DiagramSimulationLoader.LoadTemp(openedLesson, _simulation);
     if (_simulationMaster != null)
     {
         _simulation.InitialiseWith(mainNode, openedLesson);
         _isExecutable = _simulationMaster.IsProgramSimulationValid();
     }
     else
     {
         _isExecutable = false;
         Result        = 0;
         GetNode <Label>("Label").Text = "Program can not be executed";
     }
 }
Пример #19
0
 /// <summary>
 /// Initializes the whole twat viewer. Called before the node is added to the tree by the lesson controller.
 /// </summary>
 public override void InitialiseWith(IMainNode mainNode, ILessonEntity openedLesson)
 {
     _openedLesson    = openedLesson;
     Simulation       = GetNode <CircularSawModel>("ViewportContainer/Viewport/CircularSawModel");
     SimulationMaster = DiagramSimulationLoader.LoadTemp(openedLesson, Simulation);
     if (SimulationMaster != null)
     {
         Simulation.InitialiseWith(mainNode, openedLesson);
         _isExecutable = SimulationMaster.IsProgramSimulationValid();
         SetupTestSteps();
     }
     else
     {
         _isExecutable = false;
     }
 }
        /// <summary>
        /// Initializes the whole page. Called before the node is added to the tree by the lesson controller.
        /// </summary>
        public override void InitialiseWith(IMainNode mainNode, ILessonEntity openedLesson)
        {
            MainNode     = mainNode;
            OpenedLesson = openedLesson;
            LessonView   = GetNode <LessonView>(LessonViewPath);
            LessonView.LoadAndShowInfo(openedLesson);
            Sfc2dEditorNode = GetNode <Sfc2dEditorNode>(Sfc2dEditorPath);
            HelpPage        = GetNode <HelpPage>(EditorHelpPath);
            ProcessingData data = new ProcessingData
            {
                InputRegisters  = new StateTable(LessonView.PlantView.LoadedSimulationNode.SimulationOutput),
                OutputRegisters = new StateTable(LessonView.PlantView.LoadedSimulationNode.SimulationInput)
            };

            Sfc2dEditorNode.InitializeEditor(data, true);
            TryLoadDiagram();
        }
 /// <summary>
 /// Initializes the whole twat viewer. Called before the node is added to the tree by the lesson controller.
 /// </summary>
 public override void InitialiseWith(IMainNode mainNode, ILessonEntity openedLesson)
 {
     _openedLesson     = openedLesson;
     _simulation       = GetNode <RoadConstructionSite>("PlantViewportContainer/PlantViewport/RoadConstructionSite");
     _simulationMaster = DiagramSimulationLoader.LoadTemp(openedLesson, _simulation);
     if (_simulationMaster != null)
     {
         _simulation.InitialiseWith(mainNode, openedLesson);
         _isExecutable = _simulationMaster.IsProgramSimulationValid();
     }
     if (_simulationMaster == null || !_isExecutable)
     {
         _isExecutable = false;
         _testState    = TestState.Done;
         _openedLesson.SetAndSaveStars(0);
     }
     SpawnTimeGenerator.ResetGenerator();
 }
Пример #22
0
 /// <summary>
 /// Initializes the whole test viewer. Called before the node is added to the tree by the lesson controller.
 /// </summary>
 public override void InitialiseWith(IMainNode mainNode, ILessonEntity openedLesson)
 {
     _openedLesson    = openedLesson;
     Simulation       = GetNode <MassTestChamber>(_testChamberPath);
     SimulationMaster = DiagramSimulationLoader.LoadTemp(openedLesson, Simulation);
     if (SimulationMaster != null)
     {
         Simulation.InitialiseWith(mainNode, openedLesson);
         IsExecutable = SimulationMaster.IsProgramSimulationValid();
     }
     else
     {
         IsExecutable = false;
     }
     PaperLog = GetNode <PaperLog>("PaperLog");
     PaperLog.Setup();
     TestController = new TestController(this);
     TestController.Setup();
 }
Пример #23
0
 /// <summary>
 /// Initializes the whole test viewer. Called before the node is added to the tree by the lesson controller.
 /// </summary>
 public override void InitialiseWith(IMainNode mainNode, ILessonEntity openedLesson)
 {
     _openedLesson     = openedLesson;
     _simulation       = GetNode <Lights>("Lights");
     _simulationMaster = DiagramSimulationLoader.LoadTemp(openedLesson, _simulation);
     if (_simulationMaster != null)
     {
         _simulation.InitialiseWith(mainNode, openedLesson);
         _isExecutable = _simulationMaster.IsProgramSimulationValid();
     }
     else
     {
         _isExecutable = false;
     }
     if (!_isExecutable)
     {
         _stage = Stages.CreateResult;
     }
 }
 /// <summary>
 /// Initializes the whole page. Called before the node is added to the tree by the lesson controller.
 /// </summary>
 public virtual void InitialiseWith(IMainNode mainNode, ILessonEntity openedLesson)
 {
 }
Пример #25
0
 /// <summary>
 /// Opens up a new lesson and changes the view to the editor step.
 /// </summary>
 public void OpenNewLesson(ILessonEntity lessonData)
 {
 }
 /// <summary>
 /// Initializes the whole page. Called before the node is added to the tree by the lesson controller.
 /// </summary>
 public override void InitialiseWith(IMainNode mainNode, ILessonEntity openedLesson)
 {
     CircularSawNode = GetNode <CircularSawNode>("CircularSawNode");
     CircularSawNode.Setup();
 }
Пример #27
0
 /// <summary>
 /// Opens up a new lesson and changes the view to the editor step.
 /// </summary>
 public void OpenNewLesson(ILessonEntity lessonData)
 {
     _lessonController.ApplyNewLesson(lessonData);
     _navigationSteps.VisibleViewIs(PageCategory.LogicEditor);
 }
Пример #28
0
 /// <summary>
 /// Informs the grid, that the selection has changed to this button and the UI needs to be updated.
 /// </summary>
 public void SelectionChangedTo(ILessonEntity selectedLesson)
 {
     _lessonView.LoadAndShowInfo(selectedLesson);
 }
 /// <summary>
 /// The currently selected lesson will be told tho the main view to
 /// switch from the landing page to the SFC editor.
 /// </summary>
 public void StartLesson(ILessonEntity lesson)
 {
     _mainNode.OpenNewLesson(lesson);
 }
 /// <summary>
 /// Informs the grid, that the selection has changed to this button and the UI needs to be updated.
 /// </summary>
 public void LoadAndShowInfo(ILessonEntity selectedLesson)
 {
     PlantView.UpdateLessonEntity(selectedLesson);
     LessonInfo.UpdateLessonEntity(selectedLesson);
     IoInfo.UpdateText(PlantView.LoadedSimulationNode?.SimulationOutput, PlantView.LoadedSimulationNode?.SimulationInput);
 }