Exemplo n.º 1
0
        /// <summary>
        /// Copies the current node and its children to the clipboard in text and graphic formats
        /// </summary>
        /// <param name="arg"></param>
        public void copyToClipboard(Argument arg)
        {
            DataObject myDataObject;

            Node     n;
            DrawTree d;
            Bitmap   b;

            n = (Node)tv.SelectedNode.Tag;

            System.Text.StringBuilder sb;

            // builds a string which is the AXL (XML) for the current node
            sb = arg.writeArgumentXMLstring(n, false);
            // Creates a new data format.
            DataFormats.Format myFormat = DataFormats.GetFormat("AXL");
            myDataObject = new DataObject(myFormat.Name, sb.ToString());
            // Add the text format
            myDataObject.SetData(copySelectedTreeNodeAsText());
            // add graphic
            d = new DrawTree(0, 0, 1F);           // no offset or zoom
            b = d.drawTree(n);                    // create image
            myDataObject.SetData(b);

            Clipboard.SetDataObject(myDataObject, true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Exports the argument to Microsoft Word using COM
        /// </summary>
        /// <param name="a"></param>
        public void outputToWord(Argument a)
        {
            Node     n;
            DrawTree d;
            Bitmap   b;

            arg = a;
            Document aDoc = null;

            WordApp = new  Word.ApplicationClass();

            object missing     = System.Reflection.Missing.Value;
            object fileName    = "normal.dot";            // template file name
            object newTemplate = false;

            object docType   = 0;
            object isVisible = true;

            //  Create a new Document, by calling the Add function in the Documents collection
            try
            {
                aDoc = WordApp.Documents.Add(ref fileName, ref newTemplate, ref docType,
                                             ref isVisible);
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("Cannot create new document in MS Word.\n"
                                                     + e.Message);
            }


            WordApp.Visible = true;
            aDoc.Activate();

            WordApp.Selection.Font.Bold = (int)Word.WdConstants.wdToggle;
            WordApp.Selection.TypeText("Argument");
            WordApp.Selection.Font.Bold = (int)Word.WdConstants.wdToggle;
            WordApp.Selection.TypeParagraph();

            n = arg.findHead();
            d = new DrawTree(0, 0, 1F);           // no offset or zoom
            b = d.drawTree(n);
            System.Windows.Forms.Clipboard.SetDataObject(b);
            WordApp.Selection.Paste();
            WordApp.Selection.TypeParagraph();

            writeWordDoc();

            // release the COM object. GC.Collect(); would be overkill
            System.Runtime.InteropServices.Marshal.ReleaseComObject(WordApp);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Converts an element to a PNG file.
        /// </summary>
        /// <param name="reference"></param>
        /// <param name="fileName">File name for PNG file</param>
        /// <returns></returns>
        public string ImageToPNG(string reference, string fileName)
        {
            Node n;

            n = arg.findByReference(arg.findHead(), reference);

            if (n == null)
            {
                return(String.Format("ImageToPNG ({0}) not found", reference));
            }
            DrawTree draw;

            System.Drawing.Bitmap b;
            draw = new DrawTree(0, 0, 1F);           // no offset or zoom
            b    = draw.drawTree(n);
            b.Save(filePath + fileName, System.Drawing.Imaging.ImageFormat.Png);
            return(fileName);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Converts the argument element referred to a picture in RTF format.
        /// The sub elements are also rendered in the image.
        /// </summary>
        /// <param name="reference">Element reference e.g "1.1"</param>
        /// <returns></returns>
        public string ImageToRTF(string reference)
        {
            Node n;

            n = arg.findByReference(arg.findHead(), reference);

            if (n == null)
            {
                return("ImageToRTF (" + reference + ") not found");
            }
            DrawTree draw;

            System.Drawing.Bitmap b;
            draw = new DrawTree(0, 0, 1F);           // no offset or zoom
            b    = draw.drawTree(n);
            RTF rtf = new RTF();

            return(rtf.ImageRTF(b));
        }
Exemplo n.º 5
0
        // The PrintPage event is raised for each page to be printed.
        private void pd_PrintPageGraphic(object sender, System.Drawing.Printing.PrintPageEventArgs ev)
        {
            float    offsetX, offsetY;
            float    marginWidth  = ev.MarginBounds.Width;
            float    marginHeight = ev.MarginBounds.Height;
            float    left         = ev.MarginBounds.Left;
            float    top          = ev.MarginBounds.Top;
            SizeF    footerSize;
            string   footer;
            DrawTree d;

            if (scaleToPage)             // Print the whole argument on one page
            {
                Bitmap b;
                float  hz, wz, fz;                       // Horizontal, vertical & final zoom
                // Calculate maximum width & height
                d = new DrawTree(0, 0, 1F);              // no offset or zoom
                b = d.drawTree(a.CurrentArg.findHead()); // create image

                hz = (marginHeight) / (d.MaxHeight + 2 * DrawTree.margin);
                wz = (marginWidth) / (d.MaxWidth + 2 * DrawTree.margin);
                fz = Math.Min(hz, wz);                  // Smallest zoom
                fz = Math.Min(fz, 1F);                  // No enlargement
                d  = new DrawTree(left / fz, top / fz, fz);
                ev.Graphics.Clip = new Region(new RectangleF(left, top, marginWidth, marginHeight));
                d.drawTree(ev.Graphics, a.CurrentArg.findHead());
                ev.HasMorePages = false;
                return;
            }

            if (firstPage)
            {
                cpx             = this.rangeStart - 1;          // TODO Check - what if the page is in the second row?
                this.pageNumber = this.rangeStart;
            }
            offsetX = -cpx * marginWidth;
            offsetY = -cpy * marginHeight;
            d       = new DrawTree(left + offsetX, top + offsetY, 1);

            ev.Graphics.Clip = new Region(new RectangleF(left, top, marginWidth, marginHeight));
            d.drawTree(ev.Graphics, a.CurrentArg.findHead());

            if (firstPage)             // how many pages high if not calculated
            {
                float ph = d.MaxHeight / marginHeight;
                pagesHigh = (int)ph + 1;                  // round up
                float pw = d.MaxWidth / marginWidth;
                pagesWide = (int)pw + 1;                  // round up
            }

            // add page number in the lower right
            if (this.showPageNumber)
            {
                footer = "Page " + pageNumber++;
                Font       f     = new Font("Arial", 10);
                SolidBrush brush = new SolidBrush(Color.Black);
                footerSize = calcFooter(footer, marginWidth, ev.Graphics, f);
                ev.Graphics.DrawString(footer, f, brush,
                                       left + marginWidth - footerSize.Width,
                                       top + marginHeight - footerSize.Height);
            }

            cpy++;                // next page down
            if (cpy >= pagesHigh) // have we come to the bottom?
            {
                cpx++;            // next column of pages
                cpy = 0;          // start from the top page
            }

            firstPage = false;

            // If more pages exist, print another page.
            if (pageNumber > this.rangeFinish)                  // this was the last page to be printed
            {
                ev.HasMorePages = false;
            }
            else if (cpx < pagesWide)             // any more pages across to go?
            {
                ev.HasMorePages = true;
            }
            else
            {
                ev.HasMorePages = false;
            }
        }
Exemplo n.º 6
0
        private void doNode(Node n)
        {
            Microsoft.Office.Interop.PowerPoint.Slide ss;
            string nt;

            Microsoft.Office.Interop.PowerPoint.PpSlideLayout ppl;

            if (n == null)
            {
                return;
            }


            nt = n.ArgumentNodeTypeString(); // get not type text - Reason, objection etc
            if (index == 1)                  // first slide
            {
                DrawTree d;
                Bitmap   b;

                // Title page slide
                ppl = Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutTitle;

                PPapp.ActivePresentation.Slides.Add(index, ppl);
                ss = PPapp.ActiveWindow.Presentation.Slides[index];
                ss.Shapes[1].TextFrame.TextRange.Text = n.getRef(": ") + nt;
                ss.Shapes[2].TextFrame.TextRange.Text = n.EditorText;

                // Copy map to clipboard
                d = new DrawTree(0, 0, 1F);               // no offset or zoom
                b = d.drawTree(n);
                System.Windows.Forms.Clipboard.SetDataObject(b);

                // Map page slide
                index++;
                ppl = Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutBlank;
                PPapp.ActivePresentation.Slides.Add(index, ppl);
                ss = PPapp.ActiveWindow.Presentation.Slides[index];
                // ss.Shapes.SelectAll();
                ss.Shapes.Paste();
            }
            else
            {
                ppl = Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText;

                PPapp.ActivePresentation.Slides.Add(index, ppl);
                ss = PPapp.ActiveWindow.Presentation.Slides[index];
                ss.Shapes[1].TextFrame.TextRange.Text = n.getRef(": ") + nt;
                ss.Shapes[2].TextFrame.TextRange.Text = n.EditorText;
            }
            index++;
            if (n.kids == null)
            {
                return;
            }
            int k;

            for (k = 0; k < n.kids.Count; k++)
            {
                doNode((Node)n.kids[k]);
            }
        }
Exemplo n.º 7
0
        /// <summary>Save argument in format depanding on file extension or id number</summary>
        /// <param name="fileName">File name with extension</param>
        /// <param name="FilterIndex"></param>
        public void saveAs(string fileName, int FilterIndex)
        {
            Node   n;
            string ending;

            n      = this.findHead();
            ending = System.IO.Path.GetExtension(fileName).ToLower();
            if (ending.Equals(".bmp") || FilterIndex == (int)fileIndex.bmp)
            {
                DrawTree d = new DrawTree(0, 0, 1);
                d.drawTree(System.IO.Path.GetFileNameWithoutExtension(fileName) + ".bmp", n, ImageFormat.Bmp);
            }
            else if (ending.ToLower().Equals(".png") || FilterIndex == (int)fileIndex.png)
            {
                DrawTree d = new DrawTree(0, 0, 1);
                d.drawTree(System.IO.Path.GetFileNameWithoutExtension(fileName) + ".png", n, ImageFormat.Png);
            }
            else if (ending.ToLower().Equals(".jpg") || FilterIndex == (int)fileIndex.jpg)
            {
                DrawTree d = new DrawTree(0, 0, 1);
                d.drawTree(fileName, n, ImageFormat.Jpeg);
            }
            else if (ending.ToLower().Equals(".gif") || FilterIndex == (int)fileIndex.gif)
            {
                DrawTree d = new DrawTree(0, 0, 1);
                d.drawTree(fileName, n, ImageFormat.Gif);
            }
            else if (ending.ToLower().Equals(".rtnl") || FilterIndex == (int)fileIndex.rtn)                    // Rationale export
            {
                Rationale rx = new Rationale();
                rx.exportToRationale(fileName, findHead(), false);                       // expanded = false.  Option should set to true zz
            }
            else if (ending.Equals(".axl") || FilterIndex == (int)fileIndex.axl)         // already has the correct extension
            {
                saveArg(fileName, null, false);
                // addFileToRecent(fileName);
            }
            else if (ending.ToLower().Equals(""))
            {
                if (fileName != fileName + ".axl")
                {
                    if (System.IO.File.Exists(fileName + ".axl"))
                    {
                        DialogResult result;
                        string       message = String.Format("{0} exists. Do you wish to overwrite?", fileName);

                        result = System.Windows.Forms.MessageBox.Show
                                     (message, "Overwrite?", System.Windows.Forms.MessageBoxButtons.YesNo);
                        if (result != DialogResult.Yes)
                        {
                            return;
                        }
                    }
                }
                fileName = fileName + ".axl";
                saveArg(fileName, null, false);
            }
            else
            {
                fileName = fileName + ".axl";
                saveArg(fileName, null, false);
                // addFileToRecent(fileName);
            }
        }