Example #1
0
        // http://msdn.microsoft.com/en-us/library/system.windows.ink.contextnode(v=vs.90).aspx
        private void BuildTree(ContextNode parentCNode, TreeViewItem parentTNode)
        {
            parentTNode.IsExpanded = true;

            foreach (ContextNode cNode in parentCNode.SubNodes)
            {
                // Create new tree node corresponding to context node.
                TreeViewItem tNode = new TreeViewItem();
                tNode.Tag    = cNode;
                tNode.Header = cNode.ToString();

                if (cNode is InkWordNode)
                {
                    tNode.Header += ": " + (cNode as InkWordNode).GetRecognizedString();
                }
                else if (cNode is InkDrawingNode)
                {
                    tNode.Header += ": " + (cNode as InkDrawingNode).GetShapeName();
                }

                if (cNode.IsConfirmed(ConfirmationType.NodeTypeAndProperties))
                {
                    tNode.Header += "Confirmed.";
                }

                parentTNode.Items.Add(tNode);
                BuildTree(cNode, tNode);
            }
        }
Example #2
0
        private int WriteChunkInternal(ContextNode top, byte[] buffer, int offset, int count)
        {
            ulong maxBytes;

            if ((top.Size != (ulong)ChunkSize.Unknown32Bit) &&
                (top.Size != (ulong)ChunkSize.Unknown64Bit))
            {
                maxBytes = top.Size - top.Offset;
                if ((ulong)count > maxBytes)
                {
                    count = (int)maxBytes;
                }
            }
            if (count <= 0)
            {
                return(0);
            }
            var result = _streamOperations.Write(_ioContext, buffer, offset, count);

            if (result >= 0)
            {
                top.Offset += (ulong)result;
                if (top.Offset > top.CurrentSize)
                {
                    top.CurrentSize = top.Offset;
                }
            }
            return(result);
        }
Example #3
0
 private void TsDelete_Click(object sender, EventArgs e)
 {
     Path = null;
     MainGraph.RemoveNode(NodeContext);
     ContextNode.Close();
     NodeContext = null;
 }
        public TContext Resolve <TContext>(string name = null)
            where TContext : class
        {
            Type contextType = typeof(TContext);

            if (_contextRegistry.ContainsKey(contextType) == false)
            {
                _contextRegistry[contextType] = new ContextNode();
            }

            if (string.IsNullOrEmpty(name))
            {
                if (_contextRegistry[contextType].Default == null)
                {
                    _contextRegistry[contextType].Default = Create <TContext>(name);
                }

                return(_contextRegistry[contextType].Default as TContext);
            }

            if (_contextRegistry[contextType].ContainsKey(name) == false)
            {
                _contextRegistry[contextType][name] = Create <TContext>(name);
            }

            return(_contextRegistry[contextType][name] as TContext);
        }
Example #5
0
 private SerilogLoggingAdapter(LoggingBus bus, string logSource, Type logClass, ContextNode enricher) : base(bus, logSource, logClass, SerilogLogMessageFormatter.Instance)
 {
     _bus          = bus;
     _logSource    = logSource;
     _logClass     = logClass;
     _enricherNode = enricher;
 }
Example #6
0
 public void AddChildContext(ContextNode child)
 {
     if (children.IndexOf(child) < 0)
     {
         children.Add(child);
     }
 }
Example #7
0
        /// <summary>
        ///   Unity callback.
        /// </summary>
        protected void OnDestroy()
        {
            this.Trigger = null;

            this.node.SetValueListener(null);
            this.node = null;
        }
Example #8
0
        private static Range NotContainingSubformula(Range applyto, ContextNode subformula)
        {
            var which = applyto.Cells.Cast <Range>()
                        .GroupBy(c => (string)c.FormulaR1C1)
                        .Select(group => new { parse = Helper.ParseCtx(@group.First(), subformula.Ctx), example = @group.First() })
                        .FirstOrDefault(t => !t.parse.Contains(subformula));

            return(which?.example);
        }
Example #9
0
        protected virtual void Awake()
        {
            this.node = new ContextNode(this.gameObject, this.Path);

            if (this.Target == null)
            {
                this.Target = this.GetComponent <TComponent>();
            }
        }
Example #10
0
        public void CreatePreViewCode()
        {
            var selectedTransform = Selection.activeTransform;

            if (selectedTransform == null)
            {
                Debug.LogError("No transform is selected");
                return;
            }
            else
            {
                var transformPath = GraphEditorWindow.GetGameObjectPath(selectedTransform);
                Debug.Log(string.Format("Create binding graph for {0}", transformPath), selectedTransform);
            }
            ReadTemplate();
            templateOut = string.Empty;
            var container = selectedTransform.GetComponent <Hugula.Databinding.BindableObject>();

            ContextNode.templateDic.Clear();
            ContextNode.templateDic["name"]     = new StringBuilder().Append(container.name);
            ContextNode.templateDic["property"] = new StringBuilder();
            ContextNode.templateDic["command"]  = new StringBuilder();


            var root = new ContextNode()
            {
                name = container.name, contextType = ContextType.ViewModel
            };
            Dictionary <Hugula.Databinding.BindableObject, ContextNode> sourceContext = new Dictionary <BindableObject, ContextNode>();

            BuildContextTree(container, root, sourceContext);
            Debug.Log(root.name);
            root.GenTemplateString();


            var    tempOut       = template;
            string key           = string.Empty;
            string content       = string.Empty;
            var    templateTypes = System.Enum.GetValues(typeof(TemplateType));

            System.Text.StringBuilder sb = new StringBuilder();
            foreach (var en in templateTypes)
            {
                key     = System.Enum.GetName(typeof(TemplateType), en);//获取名称
                content = string.Empty;
                if (ContextNode.templateDic.TryGetValue(key, out sb))
                {
                    content = sb.ToString();
                }

                key     = "{" + key + "}";
                tempOut = tempOut.Replace(key, content);
            }

            Debug.Log(tempOut);
            templateOut = tempOut;
        }
Example #11
0
 private void FreeContextNode(ContextNode contextNode)
 {
     _stack.Remove(contextNode);
     while (contextNode.ContextInfoNodes.Count > 0)
     {
         var contextInfoNode = contextNode.ContextInfoNodes.RemoveHead();
         PurgeContextInfoNode(contextInfoNode);
     }
     contextNode.Dispose();
 }
 private void setRefactoredFormula()
 {
     if (orFormula == null || Formula == null || NewCellAddress == null)
     {
         return;
     }
     RefactoredFormula = orFormula.Replace(Formula, orFormula.Ctx.Parse(NewCellAddress.Address()));
     OnPropertyChanged("RefactoredFormula");
     OnPropertyChanged("RefactoredFormulaStr");
 }
Example #13
0
        public void insertStrokes(InkAnalyzer analyzer, InkCanvas mainInkCanvas, InkCanvas insertionCanvas)
        {
            double      bestY        = -10000;
            ContextNode selectedNode = null;

            foreach (ContextNode node in analyzer.FindLeafNodes())
            {
                double y1 = strokeToBeReplaced.GetBounds().Y;
                double y2 = node.Strokes.GetBounds().Y;
                if (y1 - y2 > 0 && y1 - y2 < y1 - bestY)
                {
                    bestY        = y2;
                    selectedNode = node;
                }
            }
            if (bestY == -10000)
            {
                bestY = strokeToBeReplaced.GetBounds().Y;
            }
            StrokeCollection strokeCollection = insertionCanvas.Strokes.Clone();

            insertionCanvas.Strokes.Clear();
            double bestX        = strokeToBeReplaced.GetBounds().X;
            double strokeX      = strokeCollection.GetBounds().X;
            double strokeY      = strokeCollection.GetBounds().Y;
            Matrix inkTransform = new Matrix();

            inkTransform.Translate(bestX - strokeX + 20, bestY - strokeY);
            strokeCollection.Transform(inkTransform, false);
            double width     = strokeCollection.GetBounds().Width + Constants.SPACING;
            double startX    = strokeCollection.GetBounds().X;
            Matrix transform = new Matrix();

            transform.Translate(width, 0);
            if (selectedNode != null)
            {
                for (int i = 0; i < selectedNode.ParentNode.SubNodes.Count; i++)
                {
                    ContextNode siblingNode = selectedNode.ParentNode.SubNodes[i];
                    for (int j = 0; j < siblingNode.Strokes.Count; j++)
                    {
                        Stroke stroke  = siblingNode.Strokes[j];
                        double offsetX = stroke.GetBounds().X;

                        if (offsetX > startX)
                        {
                            stroke.Transform(transform, false);
                        }
                    }
                }
            }
            mainInkCanvas.Strokes.Add(strokeCollection);
            mainInkCanvas.Strokes.Remove(strokeToBeReplaced);
        }
Example #14
0
        /// <summary>
        /// Gets the parent context.
        /// </summary>
        /// <returns>The parent context.</returns>
        /// <param name="contextNode">Context node.</param>
        public ContextNode GetParentContext(ContextNode contextNode)
        {
            ContextNode parent;

            parent = (ContextNode)contextNode.Successor;
            if (parent != null && parent.Id != 0)
            {
                return(parent);
            }
            return(null);
        }
Example #15
0
        private void MarkNodeAsRed(ContextNode cNode)
        {
            foreach (Stroke stroke in MainInkCanvas.Strokes)
            {
                stroke.DrawingAttributes.Color = Colors.Black;
            }

            foreach (Stroke stroke in cNode.Strokes)
            {
                stroke.DrawingAttributes.Color = Colors.Red;
            }
        }
        public ILoggingAdapter SetContextProperty(string name, object value, bool destructureObjects = false)
        {
            var contextProperty = new PropertyEnricher(name, value, destructureObjects);

            var contextNode = new ContextNode
            {
                Enricher = contextProperty,
                Next     = _enricherNode
            };

            return(new SerilogExtendedLoggingAdapter(_adapter, contextNode));
        }
Example #17
0
 public void SetContext(ContextPickerData aContext)
 {
     if (aContext == null)
     {
         _Context     = aContext;
         _ContextRoot = null;
     }
     else
     {
         _Context     = aContext.Clone() as ContextPickerData;
         _ContextRoot = new ContextNode(aContext.Selected);
     }
 }
Example #18
0
        private void AnalysisView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            TreeViewItem selectedItem = e.NewValue as TreeViewItem;

            if (selectedItem == null)
            {
                return;
            }

            ContextNode cNode = (ContextNode)selectedItem.Tag;

            MarkNodeAsRed(cNode);
        }
Example #19
0
 private void DeleteContentsToTrash()
 {
     if (RequestIdList.Count == 0)
     {
         ContextNode.Delete();
     }
     else
     {
         foreach (var node in RequestNodeList)
         {
             node.Delete();
         }
     }
 }
Example #20
0
        public static void Refactor(Range applyto, Location to, ContextNode subformula)
        {
            // Check if all cells contain the subformula
            var notContaining = NotContainingSubformula(applyto, subformula);

            if (notContaining != null)
            {
                throw new ArgumentException(String.Format((string)"Not all cells contain that subformula, for example: {0}", (object)notContaining.Address[false, false]));
            }

            Range target = applyto.Worksheet.Cells[to.Row1, to.Column1];

            if (target.Value2 != null && target.Value2 != "")
            {
                throw new ArgumentException($"Target cell {to} is not empty");
            }
            target.Formula = "=" + subformula.Print();
            var targetAddr = subformula.Ctx.Parse(to.Address());

            foreach (var uniqueR1C1Group in applyto.Cells.Cast <Range>().GroupBy(c => c.FormulaR1C1))
            {
                var prototype = uniqueR1C1Group.First();
                var parsed    = Helper.ParseCtx(prototype);

                prototype.Formula = "=" + parsed.Replace(subformula, targetAddr).Print();
                var r1c1 = prototype.FormulaR1C1;

                foreach (var cell in uniqueR1C1Group)
                {
                    cell.FormulaR1C1 = r1c1;
                }
            }

            // TODO: Provide some sort of undo functionality if possible
            // Warning: You cannot allow Excel to undo the actions of a VSTO plugin, so that path is doomed to fail :(
            // Quote from page 176 from "Visual Studio Tools for Office 2007" by E. Carter:

            /* Undo in Excel
             *      Excel has an Undo method that can be used to undo the last few actions
             *      taken by the user. However, Excel does not support undoing actions taken
             *      by your code. As soon as your code touches the object model, Excel clears
             *      the undo history and it does not add any of the actions your code performs
             *      to the undo history.
             */
            // Best option would be a manual undo stack, but that still goes against user expectations:
            //      (will Ctrl+Z work?, cannot undo further than Add-in actions etc.)
            // To hook up on Excel's undo trigger there's [Application.OnUndo](https://msdn.microsoft.com/en-us/library/office/ff194135(v=office.15).aspx)
            //      but that still requires a VBA macro to be defined to undo the changes made by the addon.
        }
Example #21
0
 internal IFFParser(IFFIOCallbacks callbacks, string openKey, bool writeMode)
 {
     _streamOperations = callbacks;
     _writeMode        = writeMode;
     _newIO            = true;
     _alignment        = (UInt16)ChunkSize.Alignment;
     _stack            = new List <ContextNode>();
     _topContext       = new ContextNode(0, 0);
     _stack.AddHead(_topContext);
     try {
         _ioContext = _streamOperations.Open(openKey, writeMode);
     } catch (Exception ex) {
         throw ex;
     }
 }
Example #22
0
 /// <summary>
 /// Loads the command binding from the specified section.
 /// </summary>
 /// <param name="decoupledStorage"></param>
 /// <param name="section"></param>
 /// <returns>Returns true if this command was most recently selected.</returns>
 public bool Load(DecoupledStorage decoupledStorage, string section)
 {
     _CustomData       = decoupledStorage.ReadString(section, "CustomData", "");
     _Command          = decoupledStorage.ReadString(section, "Command", "");
     _Comments         = decoupledStorage.ReadString(section, "Comments", "");
     _Parameters       = decoupledStorage.ReadString(section, "Parameters", "");
     _CtrlKeyDown      = decoupledStorage.ReadBoolean(section, "CtrlKeyDown", false);
     _AnyShiftModifier = decoupledStorage.ReadBoolean(section, "AnyShiftModifier", false);
     _AltKeyDown       = decoupledStorage.ReadBoolean(section, "AltKeyDown", false);
     _ShiftKeyDown     = decoupledStorage.ReadBoolean(section, "ShiftKeyDown", false);
     _Enabled          = decoupledStorage.ReadBoolean(section, "Enabled", true);
     _Context.Load(decoupledStorage, section, "Context");
     _ContextRoot = new ContextNode(_Context.Selected);
     return(decoupledStorage.ReadBoolean(section, "Selected", false));
 }
Example #23
0
        public string GetReadableContext(ContextNameDecorator decorator)
        {
            string lResult = "";

            if (_ContextRoot == null)
            {
                if (_Context == null)
                {
                    lResult = "";
                }
                _ContextRoot = new ContextNode(_Context.Selected);
            }
            lResult = _ContextRoot.GetReadableContext(_Context, decorator);
            return(lResult);
        }
Example #24
0
        private static void Inline(ExcelRaw.Range toInline, Context toInlineCtx, ContextNode toInlineAST)
        {
            // Gather dependencies
            var dependencies = InlineFormula.GetAllDirectDependents(toInline);

            var toInlineAddress = Helper.ParseCtx(toInline.Address[false, false], toInlineCtx);

            var errors = new List <Exception>();

            foreach (ExcelRaw.Range dependent in dependencies)
            {
                try
                {
                    var dependentAST = Helper.ParseCtx(dependent);
                    if (dependentAST.Node == null)
                    {
                        throw new InvalidOperationException($"Could not parse formula of {dependent.SheetAndAddress()}");
                    }

                    var newFormula = dependentAST.Replace(toInlineAddress, toInlineAST);
                    try
                    {
                        dependent.Formula = "=" + newFormula.Print();
                    }
                    catch (COMException e)
                    {
                        throw new InvalidOperationException(
                                  $"Refactoring produced invalid formula '={newFormula.Print()}' from original formula '{dependentAST.Print()}' for cell {dependent.SheetAndAddress()}",
                                  e);
                    }
                }
                catch (Exception e)
                {
                    errors.Add(e);
                }
                finally
                {
                    Marshal.ReleaseComObject(dependent);
                }
            }

            if (errors.Count > 0)
            {
                throw new AggregateException(
                          $"Could not replace references with name in all dependents:\n{String.Join("\n", errors.Select(e => e.Message))}",
                          errors);
            }
        }
Example #25
0
        public void ContextHasExpectedParts()
        {
            GraphView graphView = new GraphView(null, null, "");
            var       nodeModel = new ContextNodeModel();

            nodeModel.DefineNode();

            var context = new ContextNode();

            context.SetupBuildAndUpdate(nodeModel, null, graphView);

            Assert.IsNotNull(context.SafeQ <VisualElement>(CollapsibleInOutNode.topPortContainerPartName), "Top vertical port Container part was expected but not found");
            Assert.IsNotNull(context.SafeQ <VisualElement>(CollapsibleInOutNode.titleIconContainerPartName), "Title part was expected but not found");
            Assert.IsNotNull(context.SafeQ <VisualElement>(Node.portContainerPartName), "Horizontal Port Container part was expected but not found");
            Assert.IsNotNull(context.SafeQ <VisualElement>(ContextNode.blocksPartName), "Blocks part was expected but not found");
            Assert.IsNotNull(context.SafeQ <VisualElement>(CollapsibleInOutNode.bottomPortContainerPartName), "Bottom vertical Port Container part was expected but not found");
        }
Example #26
0
        private static bool strokeIsHorizontalLine(Stroke stroke)
        {
            InkAnalyzer temp = new InkAnalyzer();

            temp.AddStroke(stroke);
            temp.Analyze();
            ContextNode node = temp.RootNode.SubNodes[0];

            if (node is InkDrawingNode)
            {
                InkDrawingNode  drawing     = node as InkDrawingNode;
                PointCollection boundingBox = drawing.GetRotatedBoundingBox();

                double d1 = distSquared(boundingBox[0], boundingBox[1]);
                double d2 = distSquared(boundingBox[1], boundingBox[2]);
                return((d2 > 0 && d1 / d2 > 10 * 10 && d1 > 100 && Math.Abs(slope(boundingBox[0], boundingBox[1])) < 0.5) ||
                       (d1 > 0 && d2 / d1 > 10 * 10 && d2 > 100 && Math.Abs(slope(boundingBox[1], boundingBox[2])) < 0.5));
            }
            return(false);
        }
Example #27
0
        public static void MergeParagraphs(InkAnalyzer inkAnalyzer)
        {
            foreach (ContextNode writingRegion in inkAnalyzer.RootNode.SubNodes)
            {
                List <ParagraphAnalysisEntry> paragraphs = new List <ParagraphAnalysisEntry>();
                foreach (ContextNode node in writingRegion.SubNodes)
                {
                    if (node is ParagraphNode)
                    {
                        ParagraphNode          paragraph          = node as ParagraphNode;
                        ContextNode            firstLine          = paragraph.SubNodes[0];
                        Point                  paragraphReference = firstLine.Strokes.GetBounds().TopLeft;
                        ParagraphAnalysisEntry entry = new ParagraphAnalysisEntry();
                        entry.paragraph = paragraph;
                        entry.point     = paragraphReference;
                        paragraphs.Add(entry);
                    }
                }

                paragraphs.Sort(delegate(ParagraphAnalysisEntry a, ParagraphAnalysisEntry b)
                {
                    return(a.point.Y.CompareTo(b.point.Y));
                });

                for (int i = 0; i < paragraphs.Count - 1; i++)
                {
                    ParagraphAnalysisEntry entry = paragraphs[i];
                    ParagraphAnalysisEntry next  = paragraphs[i + 1];
                    bool closeto = entry.closeTo(next);
                    if (closeto)
                    {
                        foreach (ContextNode node in next.paragraph.SubNodes)
                        {
                            node.Reparent(entry.paragraph);
                        }
                        writingRegion.DeleteSubNode(next.paragraph);
                        paragraphs[i + 1] = entry;
                    }
                }
            }
        }
Example #28
0
        /// <summary>
        /// Dispose the <see cref="IFFParser"/>.
        /// </summary>
        /// <param name="disposing">If set to <c>true</c> disposing.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    var result = 0L;
                    var top    = (ContextNode)null;
                    var ci     = (ContextInfoNode)null;
                    while (GetCurrentContext() != null)
                    {
                        result = PopChunkRead();
                        if (result < 0)
                        {
                            while ((top = GetCurrentContext()) != null)
                            {
                                FreeContextNode(top);
                            }
                        }
                    }
                    /* also do the master context */
                    while (_topContext.ContextInfoNodes.Count > 0)
                    {
                        ci = _topContext.ContextInfoNodes.RemoveHead();
                        PurgeContextInfoNode(ci);
                    }

                    if (result >= 0)
                    {
                        result = _streamOperations.Close(_ioContext);
                    }
                    else
                    {
                        _streamOperations.Close(_ioContext);
                    }
                    _topContext.Dispose();
                    _topContext = null;
                }
                _disposed = true;
            }
        }
        private XmlNodeList SelectNodes()
        {
            XmlNamespaceManager nsMgr = NamespaceManager;
            XmlNodeList         nodes = null;

            try
            {
                if (nsMgr != null)
                {
                    nodes = ContextNode.SelectNodes(XPath, nsMgr);
                }
                else
                {
                    nodes = ContextNode.SelectNodes(XPath);
                }
            }
            catch (XPathException xe)
            {
                Status = BindingStatusInternal.PathError;
                if (TraceData.IsEnabled)
                {
                    TraceData.TraceAndNotify(TraceEventType.Error, TraceData.CannotGetXmlNodeCollection, ParentBindingExpression,
                                             traceParameters: new object[] { (ContextNode != null) ? ContextNode.Name : null, XPath, ParentBindingExpression, xe },
                                             eventParameters: new object[] { xe });
                }
            }

            if (TraceData.IsExtendedTraceEnabled(ParentBindingExpression, TraceDataLevel.GetValue))
            {
                TraceData.TraceAndNotifyWithNoParameters(TraceEventType.Warning,
                                                         TraceData.SelectNodes(
                                                             TraceData.Identify(ParentBindingExpression),
                                                             IdentifyNode(ContextNode),
                                                             TraceData.Identify(XPath),
                                                             IdentifyNodeList(nodes)),
                                                         ParentBindingExpression);
            }

            return(nodes);
        }
Example #30
0
        /// <summary>
        /// Attaches the context info.
        /// </summary>
        /// <param name="contextNode">Context node.</param>
        /// <param name="contextInfoNode">Context info node.</param>
        public void AttachContextInfo(ContextNode contextNode, ContextInfoNode contextInfoNode)
        {
            uint type       = contextInfoNode.Type,
                 id         = contextInfoNode.Id,
                 identifier = contextInfoNode.Identifier;

            var contextInfoNodesToDelete = new List <ContextInfoNode> ();

            foreach (var ci in contextNode.ContextInfoNodes)
            {
                if (ci.Id == id && ci.Type == type && ci.Identifier == identifier)
                {
                    contextInfoNodesToDelete.AddHead(ci);
                }
            }
            foreach (var ci in contextInfoNodesToDelete)
            {
                contextNode.ContextInfoNodes.Remove(ci);
                PurgeContextInfoNode(ci);
            }
            contextNode.ContextInfoNodes.AddHead(contextInfoNode);
        }
Example #31
0
        // http://msdn.microsoft.com/en-us/library/system.windows.ink.contextnode(v=vs.90).aspx
        private void BuildTree(ContextNode parentCNode, TreeViewItem parentTNode)
        {
            parentTNode.IsExpanded = true;

            foreach (ContextNode cNode in parentCNode.SubNodes)
            {
                // Create new tree node corresponding to context node.
                TreeViewItem tNode = new TreeViewItem();
                tNode.Tag = cNode;
                tNode.Header = cNode.ToString();

                if (cNode is InkWordNode)
                {
                    tNode.Header += ": " + (cNode as InkWordNode).GetRecognizedString();
                }
                else if (cNode is InkDrawingNode)
                {
                    tNode.Header += ": " + (cNode as InkDrawingNode).GetShapeName();
                }

                if (cNode.IsConfirmed(ConfirmationType.NodeTypeAndProperties))
                {
                    tNode.Header += "Confirmed.";
                }

                parentTNode.Items.Add(tNode);
                BuildTree(cNode, tNode);
            }
        }
        /// <summary>
        /// InkAnalysis results form a tree, this method is called recursively
        /// to render each node in the tree.
        /// </summary>
        private void DrawFeedback(DrawingContext drawingContext, ContextNode contextNode)
        {
            //see what type of ContextNode this is by casting it

            Rect nodeBounds = contextNode.Strokes.GetBounds();
            InkWordNode inkWordNode = contextNode as InkWordNode;
            if (inkWordNode != null)
            {
                drawingContext.DrawRoundedRectangle(null, new Pen(Brushes.Blue, 1.0d), nodeBounds, 1d, 1d);
                drawingContext.DrawText(new FormattedText(inkWordNode.GetRecognizedString(),
                                                            CultureInfo.CurrentCulture,
                                                            FlowDirection.LeftToRight,
                                                            new Typeface("Verdana"),
                                                            9.0d,
                                                            Brushes.Black),
                                        nodeBounds.BottomLeft);

                //check current output value
                CheckOutputValue(contextNode.Strokes, inkWordNode.GetRecognizedString());
                goto recurse;
            }

            InkDrawingNode inkDrawingNode = contextNode as InkDrawingNode;
            if (inkDrawingNode != null)
            {
                drawingContext.DrawRoundedRectangle(null, new Pen(Brushes.Purple, 1.0d), nodeBounds, 1d, 1d);
                drawingContext.DrawText(new FormattedText("Drawing: " + inkDrawingNode.GetShapeName(),
                                                            CultureInfo.CurrentCulture,
                                                            FlowDirection.LeftToRight,
                                                            new Typeface("Verdana"),
                                                            9.0d,
                                                            Brushes.Black),
                                        nodeBounds.BottomLeft);
                CheckOutputValue(contextNode.Strokes, inkDrawingNode.GetShapeName());
                goto recurse;
            }

            InkBulletNode inkBulletNode = contextNode as InkBulletNode;
            if (inkBulletNode != null)
            {
                drawingContext.DrawRoundedRectangle(null, new Pen(Brushes.Green, 1.0d), nodeBounds, 1d, 1d);
                drawingContext.DrawText(new FormattedText(inkBulletNode.GetRecognizedString(),
                                            CultureInfo.CurrentCulture,
                                            FlowDirection.LeftToRight,
                                            new Typeface("Verdana"),
                                            9.0d,
                                            Brushes.Black),
                                        nodeBounds.BottomLeft);
                goto recurse;
            }

            WritingRegionNode writingRegionNode = contextNode as WritingRegionNode;
            if (writingRegionNode != null)
            {
                nodeBounds.Inflate(3d, 3d);
                drawingContext.DrawRoundedRectangle(null, new Pen(Brushes.Black, 1.0d), nodeBounds, 1d, 1d);
                drawingContext.DrawText(new FormattedText("Writing Region",
                                            CultureInfo.CurrentCulture,
                                            FlowDirection.LeftToRight,
                                            new Typeface("Verdana"),
                                            9.0d,
                                            Brushes.Black),
                                        nodeBounds.BottomLeft + new Vector(0, 3));
        
                goto recurse;
            }

            ParagraphNode paragraphNode = contextNode as ParagraphNode;
            if (paragraphNode != null)
            {
                nodeBounds.Inflate(2d, 2d); //inflate so this will be visible outside the line node
                drawingContext.DrawRoundedRectangle(null, new Pen(Brushes.Red, 1.0d), nodeBounds, 1d, 1d);
                goto recurse;
            }

            LineNode lineNode = contextNode as LineNode;
            if (lineNode != null)
            {
                nodeBounds.Inflate(1d, 1d); //inflate so this will be visible outside the word node
                drawingContext.DrawRoundedRectangle(null, new Pen(Brushes.Orange, 1.0d), nodeBounds, 1d, 1d);
                goto recurse;
            }

        recurse:
            foreach (ContextNode subNode in contextNode.SubNodes)
            {
                DrawFeedback(drawingContext, subNode);
            }
        }
Example #33
0
        private void GenerateBoundingBoxes(ContextNode node = null)
        {
            if (node == null)
            {
                OverlayInkCanvas.Strokes.Clear();
                node = inkAnalyzer.RootNode;
            }

            PointCollection boundingBox = null;
            Color strokeColor = Colors.Black;
            if (node is InkWordNode)
            {
                boundingBox = (node as InkWordNode).GetRotatedBoundingBox();
                strokeColor = Colors.Azure;
            }
            else if (node is LineNode)
            {
                boundingBox = (node as LineNode).GetRotatedBoundingBox();
                strokeColor = Colors.Lime;
            }
            else if (node is ParagraphNode)
            {
                boundingBox = (node as ParagraphNode).GetRotatedBoundingBox();
                strokeColor = Colors.Magenta;
            }
            else if (node is InkDrawingNode)
            {
                boundingBox = (node as InkDrawingNode).GetRotatedBoundingBox();
                strokeColor = Colors.Gold;
            }

            if (boundingBox != null)
            {
                StrokeCollection collection = new StrokeCollection();

                // Copy of the points for wrapping.
                boundingBox.Add(boundingBox[0]);
                for (int i = 0; i < boundingBox.Count - 1; i++)
                {
                    StylusPointCollection points = new StylusPointCollection();
                    StylusPoint point1 = new StylusPoint(boundingBox[i].X, boundingBox[i].Y, 1.0f);
                    StylusPoint point2 = new StylusPoint(boundingBox[i + 1].X, boundingBox[i + 1].Y, 1.0f);
                    points.Add(point1);
                    points.Add(point2);

                    Stroke stroke = new Stroke(points);
                    stroke.DrawingAttributes.IsHighlighter = true; // for transparency
                    stroke.DrawingAttributes.Color = strokeColor;
                    collection.Add(stroke);
                }

                OverlayInkCanvas.Strokes.Add(collection);
            }

            // Recurse
            foreach (ContextNode child in node.SubNodes)
                GenerateBoundingBoxes(child);
        }
Example #34
0
        private void MarkNodeAsRed(ContextNode cNode)
        {
            foreach (Stroke stroke in MainInkCanvas.Strokes)
                stroke.DrawingAttributes.Color = Colors.Black;

            foreach (Stroke stroke in cNode.Strokes)
                stroke.DrawingAttributes.Color = Colors.Red;
        }