Example #1
0
        private void Open(string fileName)
        {
            if (this.CommandsListHead != null)
            {
                this.CommandsListHead.Destroy();
                this.CurrentCommand = null;
            }

            ResetCommandQueue();

            try {
                if (fileName.ToLowerInvariant().EndsWith(".tex"))
                {
                    // try to load as LaTeX
                    // ++++++++++++++++++++
                    List <string> dummy;
                    this.DocumentPath = fileName;
                    LatexIO.SplitTexFile(fileName, out dummy, out this.currentDocument);

                    //this.TeXlinkFilename = fileName;
                    //this.MenuItem_Bws2Tex.Enabled = true;
                }
                else
                {
                    // try to load as LaTeX
                    // ++++++++++++++++++++

                    this.currentDocument = Document.Deserialize(fileName);
                    this.Altered         = false;
                    this.m_DocumentPath  = fileName;
                }
            } catch (Exception e) {
                MessageBox.Show(this,
                                e.GetType().Name + ":\n" + e.Message,
                                "Error opening file",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            if (this.currentDocument.CommandAndResult.Count <= 0)
            {
                this.currentDocument.CommandAndResult.Add(new Document.Tuple {
                    Command = "\"Empty document - lets try restart?\""
                });
            }

            this.DocumentPath = this.m_DocumentPath;

            this.CommandsListHead = new WorksheetEntry(this, this.currentDocument);
            this.CurrentCommand   = this.CommandsListHead;
            //this.CommandsListHead.ResizeAll();

            string workingDirectory = Path.GetDirectoryName(fileName);

            if (workingDirectory != null && workingDirectory.Length > 0 && Directory.Exists(workingDirectory))
            {
                Directory.SetCurrentDirectory(workingDirectory);
            }
        }
Example #2
0
        private bool Save()
        {
            if (this.DocumentPath == null)
            {
                return(SaveAs());
            }
            else if (DocumentPath.ToLowerInvariant().EndsWith(".tex"))
            {
                var result = MessageBox.Show(
                    "This will transfer the Worksheet content to TeX-file '" + Path.GetFileName(this.DocumentPath) + "'." + Environment.NewLine
                    + "The content of the tex-file will be altered!" + Environment.NewLine
                    + "Ensure the file is saved in the TeX-Editor before clicking 'OK'!" + Environment.NewLine
                    + "Afterwards, reload the file.",
                    "Transfer from Worksheet to TeX-file...",
                    MessageBoxButtons.OKCancel,
                    MessageBoxIcon.Exclamation);

                if (result == DialogResult.OK)
                {
#if !DEBUG
                    try {
#endif
                    LatexIO.UpdateTexFile(this.DocumentPath, this.currentDocument);
#if !DEBUG
                }
                catch (Exception exc) {
                    MessageBox.Show(
                        exc.GetType().Name + ":" + Environment.NewLine + exc.Message,
                        "TeXlink Error.",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    return(false);
                }
#endif

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                try {
                    this.currentDocument.Serialize(this.DocumentPath);
                    this.Altered = false;
                } catch (Exception e) {
                    MessageBox.Show(this,
                                    e.GetType().Name + ":\n" + e.Message,
                                    "Error saving file",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return(false);
                }
            }

            return(true);
        }
Example #3
0
        public static int Main(string[] args)
        {
            int errCount = 0;

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            // interpretation of command line options
            // ======================================
            string fileToOpen;
            Modes  mode;

            {
                bool parseModeSuccesfully = true;
                if (args.Length == 0)
                {
                    // assuming the user wants to run the worksheet mode
                    mode       = Modes.Worksheet;
                    fileToOpen = null;
                }
                else if (args.Length == 1)
                {
                    if (args[0].StartsWith("--"))
                    {
                        parseModeSuccesfully = Enum <Modes> .TryParse(args[0].Substring(2), out mode);

                        fileToOpen = null;
                    }
                    else
                    {
                        mode       = Modes.Worksheet;
                        fileToOpen = args[0];
                    }
                }
                else if (args.Length == 2)
                {
                    parseModeSuccesfully = Enum <Modes> .TryParse(args[0].Substring(2), out mode);

                    fileToOpen = args[1];
                }
                else
                {
                    PrintUsage();
                    return(int.MinValue);
                }

                if (!parseModeSuccesfully)
                {
                    PrintUsage();
                    return(int.MinValue);
                }

                if (mode == Modes.Console && fileToOpen != null)
                {
                    PrintUsage();
                    return(int.MinValue);
                }

                if ((mode == Modes.Batch || mode == Modes.TexBatch) && (fileToOpen == null))
                {
                    PrintUsage();
                    return(int.MinValue);
                }
            }

            // launch the app
            // ==============
            ilPSP.Environment.Bootstrap(
                new string[0],
                Utils.GetBoSSSInstallDir(),
                out bool mpiInitialized);

            switch (mode)
            {
            case Modes.Worksheet:
                var ws = new Worksheet(fileToOpen);
                ws.Shown += Worksheet.OnShown;     // Workaround for wrong word-wrap on start-up of the application
                System.Windows.Forms.Application.Run(ws);

                ws.m_ExecutorOfCommandQueue_RegularTermination = false;
                Thread.Sleep(800);

                if (ws.m_ExecutorOfCommandQueue.IsAlive)
                {
                    // hardcore
                    Thread.Sleep(5000);
                    if (ws.m_ExecutorOfCommandQueue.IsAlive)
                    {
                        ws.m_ExecutorOfCommandQueue.Abort();
                    }
                }
                break;

            case Modes.Console:
                ReadEvalPrintLoop.REPL();
                break;

            case Modes.Check:
                InstallationChecker.CheckSetup();
                break;

            case Modes.Batch:
            case Modes.TexBatch:
                Document doc;
                if (fileToOpen.ToLowerInvariant().EndsWith(".tex"))
                {
                    List <string> dummy;
                    LatexIO.SplitTexFile(fileToOpen, out dummy, out doc);
                }
                else
                {
                    doc = Document.Deserialize(fileToOpen);
                }
                string OutDir = Path.GetDirectoryName(fileToOpen);
                string DocNam = Path.GetFileNameWithoutExtension(fileToOpen) + ".texbatch";

                // Which text boxes should be removed before 'restart' occurs
                int f = 0;
                if (mode == Modes.TexBatch)
                {
                    // bws was produced by Latex - some string replacements are necessary
                    for (int iEntry = 0; iEntry < doc.CommandAndResult.Count; iEntry++)
                    {
                        var Entry = doc.CommandAndResult[iEntry];

                        // Check whether there are boxes before restart
                        if (Entry.Command.Equals("restart") || Entry.Command.Equals("restart;"))
                        {
                            f = iEntry;
                        }

                        Entry.Command = LatexIO.Tex2Bws(Entry.Command);
                    }

                    GnuplotExtensions.UseCairoLatex = true;
                }

                // All boxes before 'restart' should not be counted as error
                int count = 0;
                foreach (Document.Tuple dt in doc.CommandAndResult)
                {
                    Console.WriteLine(dt.Command);
                    bool success = dt.Evaluate();

                    if (!success && count >= f)
                    {
                        errCount++;
                    }

                    Console.WriteLine(Document.ResultStartMarker);
                    Console.WriteLine(dt.InterpreterTextOutput);
                    Console.WriteLine(Document.ResultEndMarker);

                    count++;
                }

                if (mode == Modes.TexBatch)
                {
                    LatexIO.Save_Texbatch(OutDir, DocNam, doc);
                }
                else
                {
                    if (fileToOpen.EndsWith(".tex"))
                    {
                    }
                    else
                    {
                        doc.Serialize(fileToOpen);
                    }
                }
                break;

            default:
                throw new NotImplementedException();
            }

            if (mpiInitialized)
            {
                csMPI.Raw.mpiFinalize();
            }

            return(errCount);
        }