/// <summary> /// Paste AXL or text under the current node /// </summary> /// <returns></returns> public bool paste() { string s; TreeNode tn; tn = tv.SelectedNode; // check what is on the clipboard IDataObject data = Clipboard.GetDataObject(); if (data.GetDataPresent("AXL")) { Argument arg = new Argument(); s = data.GetData("AXL").ToString(); arg = arg.loadXmlArgString(s); Node n, nn; n = (Node)tv.SelectedNode.Tag; nn = arg.findHead(); if (nn.nodeType == Node.ArgumentNodeType.premise) // cannot add a second premise { nn.nodeType = Node.ArgumentNodeType.reason; } n.addKid(nn); // a.loadTree(); // recreates tree view dependent on the argument return(true); // needs loadTree } else if (data.GetDataPresent(DataFormats.Text)) { s = data.GetData(DataFormats.Text).ToString(); pasteFromText(s); } tv.SelectedNode = tn; return(false); }
/// <summary> /// Is the given argument the same as this argument? /// </summary> /// <remarks>Used for testing</remarks> /// <param name="arg">Argument to compare</param> /// <returns>True if all nodes are equal.</returns> public bool Equals(Argument arg) { Node n, nn; n = arg.findHead(); nn = this.findHead(); return(n.Equals(nn)); }
public void writeWordDoc() { Node n; // file.WriteLine("<argument>"); n = arg.findHead(); this.writeNode(n, 0); // file.WriteLine("</argument>"); }
/// <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)); }
/// <summary> /// Transform argument through XSL /// </summary> /// <param name="filename">Source AXL file name</param> /// <param name="stylesheet">XSLT Stylesheet file</param> /// <param name="outfilename">Output File Name</param> /// <param name="arg">Current argument</param> /// <returns></returns> public bool doTransform(string filename, string stylesheet, string outfilename, Argument arg) { StringBuilder sb; XPathDocument xpathdocument; // Get output path outfilepath = System.IO.Path.GetDirectoryName(outfilename); if (outfilepath.IndexOf('\\') >= 0) { outfilepath += '\\'; } // Send text to outfilename, a text file StreamWriter sw = new StreamWriter(outfilename); // //XslTransform xslt = new XslTransform(); XslCompiledTransform xslt = new XslCompiledTransform(); if (filename == null | filename.Equals("")) // empty string means read from current XML { // load current argument into the string sb = arg.writeArgumentXMLstring(arg.findHead(), true); xpathdocument = new XPathDocument(new XmlTextReader(new StringReader(sb.ToString()))); } else { xpathdocument = new XPathDocument(filename); } XmlTextReader xtr = new XmlTextReader(stylesheet); xslt.Load(xtr, null, null); XmlTextWriter writer = new XmlTextWriter(sw); writer.Formatting = Formatting.Indented; // Create an XsltArgumentList. XsltArgumentList xslArg = new XsltArgumentList(); // Add an object to create image TODO Possible error - Current argument can only have a transformed image ImageXSLextension obj = new ImageXSLextension(arg, this.outfilepath); xslArg.AddExtensionObject("urn:image", obj); xslt.Transform(xpathdocument, xslArg, writer); // xslt.Transform(xpathdocument, writer); xtr.Close(); sw.Close(); return(true); }
/// <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); }
/// <summary> /// Create the current argument in MS PowerPoint using COM /// </summary> /// <param name="a"></param> public void outputToPowerPoint(Argument a) { Node n; n = a.findHead(); // find main premise node a.referenceTree(); // reference tree index = 1; PPapp = new Microsoft.Office.Interop.PowerPoint.ApplicationClass(); object missing = System.Reflection.Missing.Value; Microsoft.Office.Core.MsoTriState mts = MsoTriState.msoTrue; PPapp.Presentations.Add(mts); PPapp.Visible = mts; doNode(n); // release the COM object. GC.Collect(); would be overkill System.Runtime.InteropServices.Marshal.ReleaseComObject(PPapp); }
/// <summary> /// Loads an argument into a TreeView /// </summary> public void loadTree() { // loads argument into tree view TreeNode tn; Node n; if (this.modifiedCount > 0) { // Save current map first } n = currentArg.findHead(); theTV.Nodes.Clear(); tn = addTreeNode(n); theTV.Nodes.Add(tn); theTV.ExpandAll(); // update edit area editArea.Text = n.EditorText; // Select top level theTV.SelectedNode = theTV.Nodes[0]; }
/// <summary> /// Open an argument file with a standard open file dialog box. /// </summary> /// <returns></returns> public ArgMapInterface openArgument() { System.Windows.Forms.OpenFileDialog openFileDialog1; ArgMapInterface ai; // if this object needs to be re-created DialogResult r; string fn; openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); openFileDialog1.Filter = "Argumentative files (*.axl)|*.axl|Reasonable files (*.re3)|*.re3" + "|Araucaria (*.aml;*.scm)|*.aml;*.scm|All Argument files (.axl;.re3;.rtnl)|*.axl;*.re3;*.rtnl"; openFileDialog1.FilterIndex = 4; try { r = openFileDialog1.ShowDialog(); } catch { r = DialogResult.Cancel; } if (r == DialogResult.OK) { fn = openFileDialog1.FileName; if (fn.ToLower().EndsWith(".axl") || fn.ToLower().EndsWith(".re3")) { ai = new ArgMapInterface(false, theTV, editArea); ai.loadAXLorRE3(fn); currentfilename = fn; return(ai); } else if (fn.ToLower().EndsWith(".aml")) // Araucaria file { Araucaria ara = new Araucaria(); ara.load(fn); CurrentArg.setArg(ara.A.findHead()); loadTree(); currentfilename = fn; return(this); } else if (fn.ToLower().EndsWith(".scm")) // Read scheme set { Araucaria ara = new Araucaria(); MessageBox.Show("Araucaria Scheme Sets are read but are not yet supported."); ara.load(fn); // TODO What to do with the scheme set } else if (fn.ToLower().EndsWith(".rtnl")) // Read scheme set { Rationale rat = new Rationale(); Argument arat = rat.importFromRationale(fn); if (arat == null) { return(null); } CurrentArg.setArg(arat.findHead()); loadTree(); currentfilename = fn; return(this); } else { MessageBox.Show(String.Format("Do not know how to open file type {0}", System.IO.Path.GetExtension(fn))); } } return(null); }