Exemple #1
0
        private void AddFunctionToolStripMenuItemClick(object sender, EventArgs e)
        {
            OpenFileDialog opf = new OpenFileDialog();

            opf.Multiselect = false;
            opf.Filter      = "PDDL File (*.pddl)|*.pddl|All File (*.*)|*.*";
            opf.Title       = "Choose the PDDL file to be added";

            if (Path.IsPathRooted(FileName))
            {
                opf.InitialDirectory = FileName;
            }
            else
            {
                opf.InitialDirectory = Directory.GetCurrentDirectory();
            }

            if (opf.ShowDialog() == DialogResult.OK)
            {
                string pathOfNewPDDL = opf.FileName;
                string fName         = Path.GetFileNameWithoutExtension(pathOfNewPDDL);

                TreeNode newNode = ProblemsNode.Nodes.Add(fName);
                newNode.Name = fName;
                newNode.Text = fName;

                TreeView_Structure.SelectedNode = newNode;

                StreamReader sReader     = null;
                string       pddlContent = "";
                try
                {
                    FileStream fileStream = new FileStream(pathOfNewPDDL, FileMode.Open, FileAccess.Read);
                    sReader     = new StreamReader(fileStream);
                    pddlContent = sReader.ReadToEnd();
                }
                catch (DirectoryNotFoundException DNF)
                {
                    pddlContent = "";
                }
                catch (FileNotFoundException FNF)
                {
                    pddlContent = "";
                }
                finally
                {
                    if (sReader != null)
                    {
                        sReader.Close();
                    }
                }
                PDDLFile newFunction = new PDDLFile(fName, opf.FileName, pddlContent);
                newNode.Tag = newFunction;
            }
        }
Exemple #2
0
        private void importDomainFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog opf = new OpenFileDialog();

            opf.Multiselect = false;
            opf.Filter      = "PDDL File (*.pddl)|*.pddl|All File (*.*)|*.*";
            opf.Title       = "Choose the PDDL file to be imported as DOMAIN";

            if (Path.IsPathRooted(FileName))
            {
                opf.InitialDirectory = FileName;
            }
            else
            {
                opf.InitialDirectory = Directory.GetCurrentDirectory();
            }

            if (opf.ShowDialog() == DialogResult.OK)
            {
                string pathOfNewPDDL = opf.FileName;
                string fName         = Path.GetFileNameWithoutExtension(pathOfNewPDDL);

                StreamReader sReader     = null;
                string       pddlContent = "";
                try
                {
                    FileStream fileStream = new FileStream(pathOfNewPDDL, FileMode.Open, FileAccess.Read);
                    sReader     = new StreamReader(fileStream);
                    pddlContent = sReader.ReadToEnd();
                }
                catch (DirectoryNotFoundException DNF)
                {
                    pddlContent = "";
                }
                catch (FileNotFoundException FNF)
                {
                    pddlContent = "";
                }
                finally
                {
                    if (sReader != null)
                    {
                        sReader.Close();
                    }
                }
                PDDLFile newFile = new PDDLFile(fName, opf.FileName, pddlContent);
                DomainNode.Tag         = newFile;
                textEditorControl.Text = pddlContent;
            }
        }
Exemple #3
0
        private static void SaveFile(string path, string content, PDDLFile fileObj)
        {
            string pathToSave = path;

            if (string.IsNullOrEmpty(path) || !Path.IsPathRooted(path))
            {
                var getNewPath = MessageBox.Show("File \"" + path + "\" doesn't exist! Do you want to continue to select a path?",
                                                 "Yes", MessageBoxButtons.YesNo) == DialogResult.Yes;

                if (getNewPath)
                {
                    SaveFileDialog svd = new SaveFileDialog();

                    svd.Filter = "PDDL File (*.pddl)|*.pddl|All File (*.*)|*.*";

                    if (svd.ShowDialog() == DialogResult.OK)
                    {
                        pathToSave       = svd.FileName;
                        fileObj.FilePath = pathToSave;
                        fileObj.Name     = Path.GetFileNameWithoutExtension(pathToSave);
                    }
                }
                else
                {
                    MessageBox.Show("The file is not saved!",
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            try
            {
                File.WriteAllText(@pathToSave, content);
            }
            catch (DirectoryNotFoundException)
            {
            }
            catch (FileNotFoundException)
            {
            }

            //MessageBox.Show("The file is saved successfully!",
            //                                   "Save File Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
Exemple #4
0
        //Generate XML from the current PDDLTabItem
        private XmlDocument GetDoc()
        {
            PDDLFile domain = null;

            if (DomainNode.Tag != null)
            {
                domain = DomainNode.Tag as PDDLFile;
            }

            Dictionary <string, PDDLFile> problems = new Dictionary <string, PDDLFile>();

            foreach (TreeNode node in ProblemsNode.Nodes)
            {
                problems.Add(node.Name, node.Tag as PDDLFile);
            }

            PDDLModel pddlModel = new PDDLModel("PDDLModel", problems, domain);

            return(pddlModel.GenerateXML());
        }