/// <summary> /// Converts the XML format into Ink strokes and creates a mapping between the XML stroke Ids and the /// Ink stroke Ids. /// </summary> public MakeInk(MakeXML xmlHolder, Ink ink) { this.ink = ink; this.idToCStroke = this.getIdToCStroke(xmlHolder.getSketch(), this.ink); calculateIdToMStroke(); this.idToMSubstrokes = new Hashtable(); }
private void addColor(MakeXML xmlHolder, Ink ink, Shape.ShapeType type) { Shape[] shapes = new Shape[0]; switch (type) { case (Shape.ShapeType.LABELED): shapes = xmlHolder.getSketch().Labeled; break; case (Shape.ShapeType.CLUSTERED): shapes = xmlHolder.getSketch().Clustered; break; } foreach (Shape shape in shapes) { string name = shape.Name; Color c = getRandomColor(); foreach (Shape.Arg arg in shape.Args) { string guid = arg.Id; Shape toColor = (Shape)xmlHolder.getSketch().IdToShape[guid]; if (toColor != null) { string guid2 = toColor.Id; if (guidToMStroke.ContainsKey(guid2)) { ((Microsoft.Ink.Stroke)guidToMStroke[guid2]).DrawingAttributes.Color = c; } } } } }
/// <summary> /// Split both a Microsoft and Converter stroke at indices and add them to the docmunte /// </summary> /// <param name="id">The id of the Microsoft and Converter stroke</param> /// <param name="indices">The indices to split at</param> /// <param name="document">The document to add to</param> public void splitStrokes(int id, float[] indices, MakeXML document) { Microsoft.Ink.Stroke mStroke = this.getMStrokeById(id); Stroke cStroke = (Stroke)this.idToCStroke[id]; this.splitStrokes(mStroke, cStroke, indices, document); }
private static void WriteStroke(Sketch.Stroke stroke, XmlTextWriter xmlDocument) { string[] strokeAttributeNames = stroke.XmlAttrs.getAttributeNames(); object[] strokeAttributeValues = stroke.XmlAttrs.getAttributeValues(); Sketch.Substroke[] substrokes = stroke.Substrokes; int length; int i; xmlDocument.WriteStartElement("shape"); // Write all the attributes length = strokeAttributeNames.Length; for (i = 0; i < length; ++i) { if (strokeAttributeValues[i] != null) { xmlDocument.WriteAttributeString(strokeAttributeNames[i], strokeAttributeValues[i].ToString()); } } // Write the substroke references length = substrokes.Length; for (i = 0; i < length; ++i) { MakeXML.WriteSubstrokeReference(substrokes[i], xmlDocument); } xmlDocument.WriteEndElement(); }
/// <summary> /// Converts the XML format into Ink strokes and creates a mapping between the XML stroke Ids and the /// Ink stroke Ids. /// </summary> public MakeInk(MakeXML xmlHolder, Ink ink, Shape.ShapeType type) { this.ink = ink; this.idToCStroke = this.getIdToCStroke(xmlHolder.getSketch(), this.ink); calculateIdToMStroke(); this.idToMSubstrokes = new Hashtable(); addColor(xmlHolder, ink, type); }
private static void WriteSketch(Sketch.Sketch sketch, XmlTextWriter xmlDocument) { string[] sketchAttributeNames = sketch.XmlAttrs.getAttributeNames(); object[] sketchAttributeValues = sketch.XmlAttrs.getAttributeValues(); Sketch.Point[] points = sketch.Points; Sketch.Shape[] shapes = sketch.Shapes; Sketch.Stroke[] strokes = sketch.Strokes; Sketch.Substroke[] substrokes = sketch.Substrokes; int length; int i; xmlDocument.WriteStartElement("sketch"); // Write all the attributes length = sketchAttributeNames.Length; for (i = 0; i < length; ++i) { if (sketchAttributeValues[i] != null) { xmlDocument.WriteAttributeString(sketchAttributeNames[i], sketchAttributeValues[i].ToString()); } } // Write all the points length = points.Length; for (i = 0; i < length; ++i) { MakeXML.WritePoint(points[i], xmlDocument); } // Write all the substrokes length = substrokes.Length; for (i = 0; i < length; ++i) { MakeXML.WriteSubstroke(substrokes[i], xmlDocument); } // Write all the strokes length = strokes.Length; for (i = 0; i < length; ++i) { MakeXML.WriteStroke(strokes[i], xmlDocument); } // Write all the shapes length = shapes.Length; for (i = 0; i < length; ++i) { MakeXML.WriteShape(shapes[i], xmlDocument); } xmlDocument.WriteEndElement(); }
/// <summary> /// Write the XML to the given XmlTextWriter /// </summary> /// <param name="textWriter">the target XmlTextWriter, which could be a file or string</param> private void WriteXML(XmlTextWriter textWriter) { // Use indentation textWriter.Formatting = System.Xml.Formatting.Indented; // Create the XML document textWriter.WriteStartDocument(); MakeXML.WriteSketch(this.sketch, textWriter); textWriter.WriteEndDocument(); // Close the XML document textWriter.Close(); }
/// <summary> /// Adds the necessary substrokes to the documnent and writes it out. /// </summary> /// <param name="document"></param> /// <param name="idToIndices"></param> public void createSubstrokes(MakeXML document, Hashtable idToIndices) { IDictionaryEnumerator Enumerator = idToMSubstrokes.GetEnumerator(); //Iterate through each Stroke that will be subdivided while (Enumerator.MoveNext()) { //Get the id of the Stroke... we use it for hashtable lookups int id = (int)Enumerator.Key; Microsoft.Ink.Stroke[] substrokes = (Microsoft.Ink.Stroke[])Enumerator.Value; //Here is the stroke we want to break up Stroke xmlStroke = (Stroke)idToCStroke[id]; //Here are the indices we will use to break it up float[] indices = (float[])((ArrayList)idToIndices[id]).ToArray(typeof(float)); //Break up the stroke into multiple substrokes Stroke[] xmlSubstrokes = breakXmlStroke(xmlStroke, indices); //Add the substrokes into the xml document foreach (Stroke s in xmlSubstrokes) { document.addShape(s); } //TEST... MIGHT NEED TO REMOVE THIS... //idToIndices.Remove(id); //ADD REST this.idToCStroke.Remove(id); for (int i = 0; i < substrokes.Length; ++i) { this.idToCStroke.Add(substrokes[i].Id, xmlSubstrokes[i]); } } }
/// <summary> /// /// </summary> /// <param name="document"></param> /// <param name="strokes"></param> /// <param name="label"></param> public void createShapeWithLabel(MakeXML document, Microsoft.Ink.Strokes strokes, string label) { //Create the new shape we will add Shape toAdd = new Shape(System.Guid.NewGuid().ToString(), label, "", label); //Extra information for the shape toAdd.Source = "LabelerSession" + this.GetHashCode().ToString(); toAdd.Width = strokes.GetBoundingBox().Width.ToString(); toAdd.Height = strokes.GetBoundingBox().Height.ToString(); toAdd.X = strokes.GetBoundingBox().X.ToString(); toAdd.Y = strokes.GetBoundingBox().Y.ToString(); ulong currentTime; ulong bestTime = 0; foreach (Microsoft.Ink.Stroke stroke in strokes) { int id = stroke.Id; Stroke s = (Stroke)idToCStroke[id]; Stroke.Arg arg = new Stroke.Arg(s.Type, s.Id); toAdd.Args.Add(arg); currentTime = Convert.ToUInt64(s.Time); if (currentTime > bestTime) { bestTime = currentTime; } } toAdd.Time = bestTime.ToString(); document.addShape(toAdd); }
/// <summary> /// Create the xml document /// </summary> /// <param name="filename"></param> /// <param name="document"></param> public void writeXML(string filename, MakeXML document) { document.writeXML(filename); }
/// <summary> /// Split both a Microsoft and Converter stroke /// </summary> /// <param name="mStroke">The Microsoft stroke</param> /// <param name="cStroke">The Converter stroke</param> /// <param name="indices">The indices to split at</param> /// <param name="document">The document</param> private void splitStrokes(Microsoft.Ink.Stroke mStroke, Stroke cStroke, float[] indices, MakeXML document) { int id = mStroke.Id; //We can only split two of the same strokes... they must be in the hashtable as such if (this.idToCStroke.ContainsKey(id) && this.getMStrokeById(id) != null) { //Remove the stroke from the hashtable (this may work below the splitting up code) //this.mStrokeToCStroke.Remove(mStroke); this.idToCStroke.Remove(id); //Get the corresponding splitted strokes //The should line up Microsoft.Ink.Stroke[] mStrokes = splitMStroke(mStroke, indices); Stroke[] cStrokes = splitCStroke(cStroke, indices); //Create the updated mapping for (int i = 0; i < mStrokes.Length; ++i) { int sId = mStrokes[i].Id; this.idToCStroke.Add(sId, cStrokes[i]); document.addShape(cStrokes[i]); } } else { object i = "test"; int b = (int)i; //Error halt here } }
/// <summary> /// Break up the Microsoft stroke, and associated Converter stroke, at the given indices and add it to the document /// </summary> /// <param name="mStroke">The Microsoft Stroke</param> /// <param name="indices">The indices to split at</param> /// <param name="document">The document to add to</param> public void splitStrokes(Microsoft.Ink.Stroke mStroke, float[] indices, MakeXML document) { this.splitStrokes(mStroke.Id, indices, document); }
/// <summary> /// Constructor /// </summary> /// <param name="makeXML">Create a MakeXML from a copy of an existing one</param> public MakeXML(MakeXML makeXML) : this(makeXML.sketch.Clone()) { //Calls the main constructor }