Beispiel #1
0
        private void LoadSlots_OnClick(object sender, RoutedEventArgs e)
        {
            var dialog = new OpenFileDialog();

            dialog.Filter = "TTAP file (*.ttap)|*.ttap";
            if (dialog.ShowDialog() == true)
            {
                var os = new ObjectSerializer();
                Global.InputSlotList = os.DeSerializeObject <SlotList>(dialog.FileName);
                MainFrame.Navigate(Page_CreateTimetable.GetInstance(Global.Settings.SearchByConsideringWeekNumber,
                                                                    Global.Settings.GeneralizeSlot));
            }
        }
        public static List <Media> GetMediaList()
        {
            ObjectSerializer  serializer      = new ObjectSerializer();
            ObjectToSerialize serializedMedia = new ObjectToSerialize();

            serializedMedia = serializer.DeSerializeObject("media.txt");

            List <Media> mediaFromFile = new List <Media>();

            mediaFromFile = serializedMedia.Media;

            return(mediaFromFile);
        }
    /// <summary>
    /// Browse for XML files to deserialize into Simulation.Settings
    /// </summary>
    void XmlBrowser(int windowID)
    {
        // back button
        GUILayout.BeginHorizontal(GUILayout.Width(UI_Toolbar.I.innerWidth));
        if (GUILayout.Button("<", GUILayout.Width(30f)))
        {
            _windows.Pop();
        }
        // refresh files and folders
        if (GUILayout.Button("R", GUILayout.Width(30f)))
        {
            Refresh();
        }
        GUILayout.EndHorizontal();

        // go up one directory
        if (_subPath != "")
        {
            if (GUILayout.Button(".."))
            {
                _subPath = Directory.GetParent(_subPath).Name;
                Refresh();
            }
        }
        // list subdirectories
        for (int i = 0; i < _folders.Count; i++)
        {
            // enter subdirectory
            if (GUILayout.Button(_folders[i]))
            {
                _subPath += "\\" + new DirectoryInfo(_folders[i]).Name;
                Refresh();
            }
        }
        // list files
        for (int i = 0; i < _files.Count; i++)
        {
            // try paths from file
            if (GUILayout.Button(_files[i]))
            {
                string path = currentDir + "\\" + _files[i];
                Simulation.Settings settings = ObjectSerializer.DeSerializeObject <Simulation.Settings>(path);
                if (settings != null)
                {
                    settings.active = false;
                    Simulation.batch.Add(settings);
                    _windows.Pop();
                }
            }
        }
    }
        private void LoadSlots_OnClick(object sender, RoutedEventArgs e)
        {
            var dialog = new OpenFileDialog();

            dialog.Filter = "TTAP file (*.ttap)|*.ttap";
            if (dialog.ShowDialog() == true)
            {
                var os = new ObjectSerializer();
                Global.InputSlotList = os.DeSerializeObject <SlotList>(dialog.FileName);
                MainFrame.Navigate(
                    Global.Factory
                    .Generate_Page_CreateTimetable_with_GeneralizedSlots
                        (Global.InputSlotList));
            }
        }
Beispiel #5
0
    /// <summary>
    /// Main routine for loading a CSV log file.
    /// </summary>
    /// <param name="csvFilePath">Csv file path.</param>
    static IEnumerator LoadCsvRoutine(string csvFilePath)
    {
        loading = true;

        string csvPath     = Path.GetDirectoryName(csvFilePath);
        string csvFileName = Path.GetFileName(csvFilePath);

        // try opening the file with StreamReader
        StreamReader sr;

        try {
            sr = new StreamReader(csvFilePath);
        }
        catch (Exception e) {
            // log exception
            Debug.LogException(e);
            UI_Toolbar.I.additionalWindows.Add(
                new UI_Prompt(
                    PromptResponse,
                    UI_Prompt.Type.Close,
                    "File Load Exception!",
                    "See log for details"
                    )
                );
            // stop loading
            loading = false;
            yield break;
        }

        // inspect CSV header
        string line;
        string header      = "";
        string xmlFileName = null;

        while ((line = sr.ReadLine()) != null)
        {
            // stop inspecting when comments are no longer found
            if (!line.StartsWith(Strings.csvComment))
            {
                break;
            }
            header += line;
            // find XML filename stored in CSV
            if (line.Contains(Strings.csvXmlCommentTag))
            {
                xmlFileName = line.Substring(
                    line.IndexOf(Strings.csvXmlCommentTag) +
                    Strings.csvXmlCommentTag.Length);
                Debug.Log("XML filename from CSV is: " + xmlFileName);
            }
        }

        // temporary settings object for deserialization
        Simulation.Settings settings;


        // if xml filename was not found in csv...
        if (xmlFileName == null)
        {
            settings = new Simulation.Settings();
            // prompt user whether to select environment
            _waitingForResponse = true;
            UI_Toolbar.I.additionalWindows.Add(
                new UI_Prompt(
                    PromptResponse,
                    UI_Prompt.Type.YesNo,
                    "XML filename not found in CSV header!",
                    header + "\n Select environment to load?"
                    )
                );
            while (_waitingForResponse)
            {
                yield return(new WaitForSeconds(0.1f));
            }
            if (_response)
            {
                /// not yet implemented
                // browse environments and load selection
                Debug.Log("Not yet implemented: browse and load environment");
            }
        }
        else
        {
            // try loading environment
            settings = ObjectSerializer.DeSerializeObject <Simulation.Settings>(csvPath + "\\" + xmlFileName);
            // if environment is different to the currently loaded environment
            // prompt user for action  (discard other paths, or load new env and paths?)
            // (not yet implemented)
            if (environment)
            {
                if (environment.name != settings.environmentName)
                {
                    _waitingForResponse = true;
                    UI_Toolbar.I.additionalWindows.Add(
                        new UI_Prompt(
                            PromptResponse,
                            UI_Prompt.Type.OkCancel,
                            "Load new environment and paths?",
                            "CSV log is for a different environment. Load new environment and paths instead?"
                            )
                        );
                    while (_waitingForResponse)
                    {
                        yield return(new WaitForSeconds(0.1f));
                    }
                    if (_response)
                    {
                        // load environment and clear paths if YES
                        paths.Clear();
                        CamController.ClearAreaList();
                        LoadEnvironment(settings.environmentName);
                    }
                    else
                    {
                        // stop loading if NO
                        loading = false;
                        yield break;
                    }
                }
            }
            else
            {
                LoadEnvironment(settings.environmentName);
            }
        }

        // load paths from CSV and display them

        // go to line with SimulationTime as first string
        while ((line = sr.ReadLine()) != null)
        {
            if (line.StartsWith(Log.Parameters.SimulationTime.ToString()))
            {
                break;
            }
        }

        // extract headings and store column indexes for path types
        int robotPositionIndex;

        string[] row = line.Split(Strings.csvDelimiter);
        for (robotPositionIndex = 0; robotPositionIndex < row.Length; robotPositionIndex++)
        {
            if (row[robotPositionIndex] == Log.Parameters.RobotPosition.ToString())
            {
                break;
            }
        }


        BotPath botpos = new BotPath();

        botpos.csvName = csvFileName;

        // Build BotPath objects for each path type columns found
        while ((line = sr.ReadLine()) != null)
        {
            row = line.Split(Strings.csvDelimiter);
            if (robotPositionIndex > row.Length)
            {
                Debug.LogWarning("LogLoader: row length too short?");
                continue;
            }
            // try deserializing this vector3 data
            // (catch parsing errors not yet implemented)
            Vector3 pos = ParseVector3(row[robotPositionIndex]);
            // remove " chars from "12.3", for example
            // (catch parsing errors not yet implemented)
            float time = float.Parse(row[0].Substring(1, row[0].Length - 2));
            botpos.AddNode(pos, time);
        }


        AddPath(botpos);
        UpdatePathColors();
        loading = false;
    }