public Attribute(String name, bool iskey, NodeFigure fig, String color)
 {
     this.Name   = name;
     this.IsKey  = iskey;
     this.Figure = fig;
     this.Color  = color;
 }
Exemple #2
0
 public override void LoadFromXElement(XElement e)
 {
     base.LoadFromXElement(e);
     this.Figure    = XHelper.ReadEnum <NodeFigure>("Figure", e, NodeFigure.Rectangle);
     this.ToSpot    = XHelper.Read("ToSpot", e, "");
     this.FromSpot  = XHelper.Read("FromSpot", e, "");
     this.Color     = XHelper.Read("Color", e, "White");
     this.LinkColor = XHelper.Read("LinkColor", e, "LightGray");
     this.LayoutId  = XHelper.Read("LayoutId", e, "All");
 }
Exemple #3
0
        void InitMatrix()
        {
            // counting the number of source nodes and creating field of them
            field = new NodeItem[fieldSource.GetLength(0), fieldSource.GetLength(1)];

            // counting nodes
            int nodeItemCount = 0;

            for (int x = 0; x < fieldSource.GetLength(0); x++)
            {
                for (int y = 0; y < fieldSource.GetLength(1); y++)
                {
                    if (fieldSource[x, y] == 1)
                    {
                        NodeItem item = new NodeItem()
                        {
                            x = x, y = y
                        };
                        field[x, y] = item;
                        nodeItemCount++;
                    }
                }
            }

            dancingLinks.InitHeaders(nodeItemCount + figureSet.FigureCount);

            // assigning a node to every column header just to make it distinct
            ExactCover.Node header = dancingLinks.rootHeader.right;
            for (int x = 0; x < field.GetLength(0); x++)
            {
                for (int y = 0; y < field.GetLength(1); y++)
                {
                    if (field[x, y] != null)
                    {
                        header.nodedata = field[x, y];
                        header          = header.right;
                    }
                }
            }

            // assigning a node containing figure id to header columns
            figureNodes = new NodeFigure[figureSet.FigureCount];
            for (int i = 0; i < figureSet.FigureCount; i++)
            {
                var newNode = new NodeFigure()
                {
                    figureId = i
                };
                header.nodedata = newNode;
                // all figure headers are optional
                ((ExactCover.ColumnHeader)header).optional = true;
                header         = header.right;
                figureNodes[i] = newNode;
            }
        }
Exemple #4
0
        // walk the visual tree of adornment elements
        private void RenderHandles(FrameworkElement elt)
        {
            if (elt == null)
            {
                return;
            }
            Path path = elt as Path;

            if (path != null) // if it's a Path
            // and if NodePanel.Figure is specified and is None, it's a SelectionHandle equivalent
            {
                NodeFigure fig = NodePanel.GetFigure(elt);
                if (fig == NodeFigure.None)                                                                // must explicitly set go:NodePanel.Figure="None", to distinguish this selection handle from random Path shapes
                {
                    Shape adornedshape = this.AdornedElement as Shape;                                     // hack: because GetSelectionGeometry doesn't always return a Geometry of the AdornedElement's size
                    if (adornedshape != null && this.AdornedPart is Node &&
                        ((adornedshape is Path && NodePanel.GetFigure(adornedshape) != NodeFigure.None) || // when that Path is a NodeShape equivalent
                         adornedshape is Polygon || adornedshape is Polyline))                             // or is a Polygon or Polyline
                    {
                        path.Stretch = Stretch.Fill;
                        Size sz = GetEffectiveSize(adornedshape); // can't just use ActualWidth/Height, because measuring has reset them to zero
                        path.Width  = sz.Width;
                        path.Height = sz.Height;
                    }
                    path.Data = GetSelectionGeometry(path, this);
                }
                else // otherwise assume it's a ToolHandle equivalent
                {
                    if (path.Data == null)
                    {
                        path.Stretch = Stretch.Fill;
                        path.Data    = GetFigureGeometry(path); // returns a Geometry with points from 0,0 to 1,1
                    }
                }
            }
            else
            {
                int count = VisualTreeHelper.GetChildrenCount(elt);
                for (int i = 0; i < count; i++)
                {
                    RenderHandles(VisualTreeHelper.GetChild(elt, i) as FrameworkElement);
                }
            }
        }
Exemple #5
0
        private void RenderNodeShape(UIElement elt, Size sz)
        {
            if (elt == null)
            {
                return;
            }
            Path path = elt as Path;

            if (path != null) // if it's a Path
            // and if NodePanel.Figure is specified, it's a NodeShape equivalent
            {
                NodeFigure fig = NodePanel.GetFigure(elt);
                if (fig != NodeFigure.None)
                {
                    path.Stretch = Stretch.Fill;
                    path.Data    = new NodeGeometry(path).GetGeometry(sz);
                    // this also has the side-effect of setting any default Spot1/Spot2 parameters
                }
            }
        }
Exemple #6
0
 public override void LoadFromXElement(XElement e)
 {
     base.LoadFromXElement(e);
     this.Figure = XHelper.ReadEnum <NodeFigure>("Figure", e, NodeFigure.Rectangle);
 }
Exemple #7
0
 /// <summary>
 /// Sets the value of the <see cref="FigureProperty"/> attached dependency property.
 /// </summary>
 /// <param name="d"></param>
 /// <param name="v"></param>
 public static void SetFigure(DependencyObject d, NodeFigure v)
 {
     d.SetValue(FigureProperty, v);
 }
Exemple #8
0
 /// <summary>
 /// Sets the value of the <see cref="FigureProperty"/> attached dependency property.
 /// </summary>
 /// <param name="d"></param>
 /// <param name="v"></param>
 public static void SetFigure(DependencyObject d, NodeFigure v) { d.SetValue(FigureProperty, v); }
Exemple #9
0
        public bool Solve()
        {
            // matrix doesn't have any rows
            if (nLines == 0)
            {
                return(false);
            }

            bool result = dancingLinks.Solve();

            if (result)
            {
                // transforming the result to the form of array of chars that can be easily output to screen
                Solution = new char[field.GetLength(0), field.GetLength(1)];

                // filling all with spaces
                for (int x = 0; x < Solution.GetLength(0); x++)
                {
                    for (int y = 0; y < Solution.GetLength(1); y++)
                    {
                        Solution[x, y] = ' ';
                    }
                }

                foreach (ExactCover.Node figure in dancingLinks.Solution)
                {
                    // finding figure id (type)
                    int             figureId = 0;
                    ExactCover.Node node     = figure;
                    do
                    {
                        if (node.nodedata.GetType() == typeof(NodeFigure))
                        {
                            NodeFigure figureType = (NodeFigure)node.nodedata;
                            if (figureType != null)
                            {
                                figureId = figureType.figureId;
                                break;
                            }
                        }
                        node = node.right;
                    } while (node != figure);
                    // placing all nodes in the char[,] array

                    node = figure;
                    do
                    {
                        if (node.nodedata.GetType() == typeof(NodeItem))
                        {
                            NodeItem item = (NodeItem)node.nodedata;
                            if (item != null)
                            {
                                Solution[item.x, item.y] = (char)((int)'A' + figureId);
                            }
                        }
                        node = node.right;
                    } while (node != figure);
                }
            }
            return(result);
        }
Exemple #10
0
        void AddFigureToMatrix(long[] figure, int figureId, int fCol, int fRow)
        {
            int       nFigureRows = figure.Length;
            ArrayList newRow      = new ArrayList();

            // adding all five field nodes
            for (int row = 0; row < nFigureRows; row++)
            {
                for (int col = 0; col < 5; col++)
                {
                    if ((figure[row] & (1 << col)) != 0)
                    {
                        // add new node to header
                        NodeItem item = field[row + fRow, col + fCol];
                        foreach (ExactCover.ColumnHeader colHeader in dancingLinks.columnHeaders)
                        {
                            if (colHeader.nodedata == item)
                            {
                                ExactCover.Node newNode = new ExactCover.Node()
                                {
                                    nodedata = item
                                };
                                colHeader.Add(newNode);
                                newRow.Add(newNode);
                                break;
                            }
                        }
                    }
                }
            }
            // adding figure node
            NodeFigure nodeFigure = Array.Find <NodeFigure>(figureNodes, (fNode) => (fNode.figureId == figureId));

            foreach (ExactCover.ColumnHeader colHeader in dancingLinks.columnHeaders)
            {
                if (colHeader.nodedata == nodeFigure)
                {
                    ExactCover.Node newNode = new ExactCover.Node()
                    {
                        nodedata = nodeFigure
                    };
                    colHeader.Add(newNode);
                    newRow.Add(newNode);
                    break;
                }
            }

            // establishing links between nodes in a row through left and right pointers
            ExactCover.Node startNode    = null;
            ExactCover.Node previousNode = null;
            for (ExactCover.Node node = dancingLinks.rootHeader.right; node != dancingLinks.rootHeader; node = node.right)
            {
                foreach (ExactCover.Node rowNode in newRow)
                {
                    if ((startNode == null) && (node.nodedata == rowNode.nodedata))
                    {
                        startNode    = rowNode;
                        previousNode = rowNode;
                        continue;
                    }
                    if ((startNode != null) && (node.nodedata == rowNode.nodedata))
                    {
                        ExactCover.Node currentNode = rowNode;
                        previousNode.right = currentNode;
                        currentNode.left   = previousNode;
                        previousNode       = currentNode;
                    }
                }
            }
            previousNode.right = startNode;
            startNode.left     = previousNode;
        }
Exemple #11
0
        void InitMatrix()
        {
            // counting the number of source nodes and creating field of them
            field = new NodeItem[ fieldSource.GetLength(0), fieldSource.GetLength(1) ];

            // counting nodes
            int nodeItemCount = 0;
            for (int x = 0; x < fieldSource.GetLength(0); x++) {
                for (int y = 0; y < fieldSource.GetLength(1); y++) {
                    if (fieldSource[x, y] == 1) {
                        NodeItem item = new NodeItem() { x = x, y = y };
                        field[x,y] = item;
                        nodeItemCount++;
                    }
                }
            }

            dancingLinks.InitHeaders(nodeItemCount + figureSet.FigureCount);

            // assigning a node to every column header just to make it distinct
            ExactCover.Node header = dancingLinks.rootHeader.right;
            for (int x = 0; x < field.GetLength(0); x++) {
                for (int y = 0; y < field.GetLength(1); y++) {
                    if (field[x, y] != null) {
                        header.nodedata = field[x, y];
                        header = header.right;
                    }
                }
            }

            // assigning a node containing figure id to header columns
            figureNodes = new NodeFigure[ figureSet.FigureCount ];
            for (int i = 0; i < figureSet.FigureCount; i++) {
                var newNode = new NodeFigure() { figureId = i };
                header.nodedata = newNode;
                // all figure headers are optional
                ((ExactCover.ColumnHeader) header).optional = true;
                header = header.right;
                figureNodes[i] = newNode;
            }
        }