/// <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> /// 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); }