Пример #1
0
        /// <summary>
        /// Loads a Sketch and synchronizes Ink.  Clears the current contents
        /// of this InkSketch.
        /// </summary>
        /// <param name="sketch">The sketch to load</param>
        public void LoadFeatureSketch(FeatureSketch featureSketch)
        {
            unsubscribeToInk();

            this.Clear();

            mFeatureSketch = featureSketch;

            #region Create Collection - Load Ink Properties

            #region X

            Microsoft.Ink.TabletPropertyMetrics xMet = new Microsoft.Ink.TabletPropertyMetrics();
            xMet.Minimum    = 0;
            xMet.Maximum    = 24780;
            xMet.Resolution = 3003.63647f; //TABLET PEN ONLY 100.0f for mouse i think
            xMet.Units      = Microsoft.Ink.TabletPropertyMetricUnit.Inches;

            System.Guid xGuid = Microsoft.Ink.PacketProperty.X;

            Microsoft.Ink.TabletPropertyDescription xDesc = new Microsoft.Ink.TabletPropertyDescription(xGuid, xMet);

            #endregion

            #region Y

            Microsoft.Ink.TabletPropertyMetrics yMet = new Microsoft.Ink.TabletPropertyMetrics();
            yMet.Minimum    = 0;
            yMet.Maximum    = 18630;
            yMet.Resolution = 3010.66577f; //TABLET PEN ONLY 100.0f for mouse i think
            yMet.Units      = Microsoft.Ink.TabletPropertyMetricUnit.Inches;

            System.Guid yGuid = Microsoft.Ink.PacketProperty.Y;

            Microsoft.Ink.TabletPropertyDescription yDesc = new Microsoft.Ink.TabletPropertyDescription(yGuid, yMet);

            #endregion

            #region Pressure

            // Get max pressure in Sketch
            // Different input devices have different ranges of pressures
            int max = 0;
            foreach (Sketch.Point pt in Sketch.Points)
            {
                max = Math.Max(max, pt.Pressure);
            }

            Microsoft.Ink.TabletPropertyMetrics pMet = new Microsoft.Ink.TabletPropertyMetrics();
            pMet.Minimum = 0;
            if (max > 1024)
            {
                pMet.Maximum = 32767;
            }
            else if (max > 256)
            {
                pMet.Maximum = 1023;
            }
            else
            {
                pMet.Maximum = 255;
            }
            pMet.Resolution = float.PositiveInfinity;
            pMet.Units      = Microsoft.Ink.TabletPropertyMetricUnit.Default;

            System.Guid pGuid = Microsoft.Ink.PacketProperty.NormalPressure;

            Microsoft.Ink.TabletPropertyDescription pDesc = new Microsoft.Ink.TabletPropertyDescription(pGuid, pMet);

            #endregion

            Microsoft.Ink.TabletPropertyDescriptionCollection coll = new Microsoft.Ink.TabletPropertyDescriptionCollection();
            coll.Add(xDesc);
            coll.Add(yDesc);
            coll.Add(pDesc);

            #endregion

            // Load Sketch strokes into Ink
            List <int> points = new List <int>();
            foreach (Substroke sub in Sketch.Substrokes)
            {
                points.Clear();
                foreach (Sketch.Point point in sub.Points)
                {
                    points.Add((int)point.X);
                    points.Add((int)point.Y);
                    points.Add((int)point.Pressure);
                }

                Microsoft.Ink.Stroke stroke = mInk.CreateStroke(points.ToArray(), coll);
                ink2sketchStr.Add(stroke.Id, sub.XmlAttrs.Id);
                sketchStr2ink.Add(sub.XmlAttrs.Id, stroke.Id);
                substrokeIdMap.Add(sub.XmlAttrs.Id, sub);

                stroke.DrawingAttributes.AntiAliased    = true;
                stroke.DrawingAttributes.FitToCurve     = true;
                stroke.DrawingAttributes.IgnorePressure = false;


                //see ReadJnt.cs for opposite transformation

                /*
                 * if (sub.XmlAttrs.Time != null)
                 * {
                 *  stroke.ExtendedProperties.Add(Microsoft.Ink.StrokeProperty.TimeID,
                 *      (long)((ulong)sub.XmlAttrs.Time * 10000 + 116444736000000000));
                 * }
                 */

                if (sub.XmlAttrs.Color != null)
                {
                    stroke.DrawingAttributes.Color = Color.FromArgb((int)sub.XmlAttrs.Color);
                }
                if (sub.XmlAttrs.PenWidth != null)
                {
                    stroke.DrawingAttributes.Width = Convert.ToSingle(sub.XmlAttrs.PenWidth);
                }
                if (sub.XmlAttrs.PenHeight != null)
                {
                    stroke.DrawingAttributes.Height = Convert.ToSingle(sub.XmlAttrs.PenHeight);
                }
                if (sub.XmlAttrs.PenTip != null)
                {
                    if (sub.XmlAttrs.PenTip.Equals("Ball"))
                    {
                        stroke.DrawingAttributes.PenTip = Microsoft.Ink.PenTip.Ball;
                    }
                    else if (sub.XmlAttrs.PenTip.Equals("Rectangle"))
                    {
                        stroke.DrawingAttributes.PenTip = Microsoft.Ink.PenTip.Rectangle;
                    }
                }
                if (sub.XmlAttrs.Raster != null)
                {
                    if (sub.XmlAttrs.Raster.Equals("Black"))
                    {
                        stroke.DrawingAttributes.RasterOperation = Microsoft.Ink.RasterOperation.Black;
                    }
                    else if (sub.XmlAttrs.Raster.Equals("CopyPen"))
                    {
                        stroke.DrawingAttributes.RasterOperation = Microsoft.Ink.RasterOperation.CopyPen;
                    }
                    else if (sub.XmlAttrs.Raster.Equals("MakePenNot"))
                    {
                        stroke.DrawingAttributes.RasterOperation = Microsoft.Ink.RasterOperation.MakePenNot;
                    }
                    else if (sub.XmlAttrs.Raster.Equals("MaskNotPen"))
                    {
                        stroke.DrawingAttributes.RasterOperation = Microsoft.Ink.RasterOperation.MaskNotPen;
                    }
                    else if (sub.XmlAttrs.Raster.Equals("MaskPen"))
                    {
                        stroke.DrawingAttributes.RasterOperation = Microsoft.Ink.RasterOperation.MaskPen;
                    }
                    else if (sub.XmlAttrs.Raster.Equals("MergeNotPen"))
                    {
                        stroke.DrawingAttributes.RasterOperation = Microsoft.Ink.RasterOperation.MergeNotPen;
                    }
                    else if (sub.XmlAttrs.Raster.Equals("MergePen"))
                    {
                        stroke.DrawingAttributes.RasterOperation = Microsoft.Ink.RasterOperation.MergePen;
                    }
                    else if (sub.XmlAttrs.Raster.Equals("MergePenNot"))
                    {
                        stroke.DrawingAttributes.RasterOperation = Microsoft.Ink.RasterOperation.MergePenNot;
                    }
                    else if (sub.XmlAttrs.Raster.Equals("NoOperation"))
                    {
                        stroke.DrawingAttributes.RasterOperation = Microsoft.Ink.RasterOperation.NoOperation;
                    }
                    else if (sub.XmlAttrs.Raster.Equals("Not"))
                    {
                        stroke.DrawingAttributes.RasterOperation = Microsoft.Ink.RasterOperation.Not;
                    }
                    else if (sub.XmlAttrs.Raster.Equals("NotCopyPen"))
                    {
                        stroke.DrawingAttributes.RasterOperation = Microsoft.Ink.RasterOperation.NotCopyPen;
                    }
                    else if (sub.XmlAttrs.Raster.Equals("NotMaskPen"))
                    {
                        stroke.DrawingAttributes.RasterOperation = Microsoft.Ink.RasterOperation.NotMaskPen;
                    }
                    else if (sub.XmlAttrs.Raster.Equals("NetMergePen"))
                    {
                        stroke.DrawingAttributes.RasterOperation = Microsoft.Ink.RasterOperation.NotMergePen;
                    }
                    else if (sub.XmlAttrs.Raster.Equals("NotXOrPen"))
                    {
                        stroke.DrawingAttributes.RasterOperation = Microsoft.Ink.RasterOperation.NotXOrPen;
                    }
                    else if (sub.XmlAttrs.Raster.Equals("White"))
                    {
                        stroke.DrawingAttributes.RasterOperation = Microsoft.Ink.RasterOperation.White;
                    }
                    else if (sub.XmlAttrs.Raster.Equals("XOrPen"))
                    {
                        stroke.DrawingAttributes.RasterOperation = Microsoft.Ink.RasterOperation.XOrPen;
                    }
                }
            }


            subscribeToInk();
            if (SketchLoaded != null)
            {
                SketchLoaded();
            }
        }