Esempio n. 1
0
        public void GetMatches(Bitmap bitmap, int probeOffsetX, int probeOffsetY, ICollection <Tree> bucket)
        {
            int imageOffsetX, imageOffsetY;

            imageOffsetX = probeOffsetX + m_offsetToTest.X;
            imageOffsetY = probeOffsetY + m_offsetToTest.Y;
            //Point.Add(probeOffsetX, m_offsetToTest.X, probeOffsetY, m_offsetToTest.Y, out imageOffsetX, out imageOffsetY);

            if (imageOffsetX >= 0 && imageOffsetY >= 0 &&
                imageOffsetY < bitmap.Height && imageOffsetX < bitmap.Width)
            {
                FeatureTreeNode child = null;
                bool            has   = m_childrenByColor.TryGetValue(bitmap[imageOffsetY, imageOffsetX], out child);
                if (has)
                {
                    child.GetMatches(bitmap, probeOffsetX, probeOffsetY, bucket);
                    if (m_transparentChild != null)
                    {
                        m_transparentChild.GetMatches(bitmap, probeOffsetX, probeOffsetY, bucket);
                    }
                    return;
                }
            }
            if (m_transparentChild != null)
            {
                m_transparentChild.GetMatches(bitmap, probeOffsetX, probeOffsetY, bucket);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Constructs a node given the parameters. A shallow copy is
 /// made of each parameter.
 /// </summary>
 /// <param name="offsetToTest">The offset to test at this node.</param>
 /// <param name="childrenByColor">The children bucketed by their pixel value at offsetToTest.</param>
 /// <param name="transparentChild">The child node that should be checked if no other children are matched. </param>
 public InnerFeatureTreeNode(Point offsetToTest,
                             Dictionary <Int32, FeatureTreeNode> childrenByColor, FeatureTreeNode transparentChild)
 {
     m_offsetToTest     = offsetToTest;
     m_childrenByColor  = childrenByColor;
     m_transparentChild = transparentChild;
 }
		/// <summary>
		/// Constructs a node given the parameters. A shallow copy is
		/// made of each parameter.
		/// </summary>
		/// <param name="offsetToTest">The offset to test at this node.</param>
		/// <param name="childrenByColor">The children bucketed by their pixel value at offsetToTest.</param>
		/// <param name="transparentChild">The child node that should be checked if no other children are matched. </param>
		public InnerFeatureTreeNode(Point offsetToTest, 
			Dictionary<Int32, FeatureTreeNode> childrenByColor, FeatureTreeNode transparentChild)
		{
			m_offsetToTest = offsetToTest;
			m_childrenByColor = childrenByColor;
			m_transparentChild = transparentChild;
		}
Esempio n. 4
0
 /// <summary>
 /// Constructs a feature tree with the given parameters.
 /// </summary>
 /// <param name="root">The root node of the tree</param>
 /// <param name="features">The features that the tree can locate</param>
 private FeatureTree(FeatureTreeNode root, int farthestUpFromBottom, int farthestLeftFromRight, int farthestDown, int farthestRight)
 {
     this.root = root;
     farthestUpHotspotYFromBottom = farthestUpFromBottom;
     farthestLeftHotspotXFromLeft = farthestLeftFromRight;
     farthestDownHotspotY         = farthestDown;
     farthestRightHotspotX        = farthestRight;
 }
Esempio n. 5
0
		/// <summary>
		/// Constructs a feature tree with the given parameters.
		/// </summary>
		/// <param name="root">The root node of the tree</param>
		/// <param name="features">The features that the tree can locate</param>
		private FeatureTree(FeatureTreeNode root, int farthestUpFromBottom, int farthestLeftFromRight, int farthestDown, int farthestRight)
		{
			this.root = root;
			farthestUpHotspotYFromBottom = farthestUpFromBottom;
			farthestLeftHotspotXFromLeft = farthestLeftFromRight;
			farthestDownHotspotY = farthestDown;
			farthestRightHotspotX = farthestRight;


		}
Esempio n. 6
0
        private void deleteGroupButton_Click(object sender, EventArgs e)
        {
            if (treeView.SelectedNode is FeatureTreeNode)
            {
                FeatureTreeNode node = (FeatureTreeNode)treeView.SelectedNode;

                if (node.FeatureDef.ID != 0)
                {
                    DialogResult result = MessageBox.Show("Czy napewno chcesz usunąć grupę", "EnovaTools", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                                          MessageBoxDefaultButton.Button2);

                    if (result == DialogResult.Yes)
                    {
                        ((Enova.Business.Old.Core.IDeleteRecord)node.FeatureDef).DeleteRecord();
                    }
                    //LoadFeatures(Enova.Business.Core.ContextManager.DataContext);
                    if (node.Parent == null)
                    {
                        treeView.Nodes.Remove(node);
                    }
                    else
                    {
                        node.Parent.Nodes.Remove(node);
                    }
                    this.treeView.SelectedNode = treeView.Nodes[0];
                }
            }
            else
            {
                DialogResult result = MessageBox.Show("Chy napewno chcesz usunąć podgrupę", "EnovaTools", MessageBoxButtons.YesNo,
                                                      MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);

                if (result == DialogResult.Yes)
                {
                    DictionaryTreeNode node   = (DictionaryTreeNode)treeView.SelectedNode;
                    TreeNode           parent = node.Parent;
                    ((Enova.Business.Old.Core.IDeleteRecord)node.Dictionary).DeleteRecord();
                    //LoadFeatures(Enova.Business.Core.ContextManager.DataContext);
                    parent.Nodes.Remove(node);
                    treeView.SelectedNode = parent;
                }
            }
        }
Esempio n. 7
0
        void Bind()
        {
            var products =
                (from p in _data.Products
                 join f in _data.Features on p.ProductID equals f.ProductID into features
                 select new { p, features }).AsDynamic();
            var indexedAssignments = _data.Assignments;
            var index = indexedAssignments.Indexes.Add(a => new Tuple <int, int, int>(a.ProductID, a.FeatureID, a.EmployeeID));

            Index <Assignment> productIndex = indexedAssignments.Indexes.Add(a => a.ProductID);

            treeViewFeatures.BeginUpdate();
            treeViewFeatures.Nodes.Clear();
            int employeeID = comboAssignedTo.SelectedIndex;

            foreach (var product in products)
            {
                var productNode = new ProductTreeNode();
                productNode.ProductID = product.p.ProductID;
                productNode.Text      = product.p.ProductName;
                treeViewFeatures.Nodes.Add(productNode);
                bool productChecked = false;
                foreach (var feature in product.features)
                {
                    FeatureTreeNode featureNode = new FeatureTreeNode();
                    featureNode.FeatureID = feature.FeatureID;
                    featureNode.Text      = feature.FeatureName;
                    productNode.Nodes.Add(featureNode);

                    bool isChecked = index.ContainsKey(new Tuple <int, int, int>(product.p.ProductID, feature.FeatureID, employeeID));
                    if (isChecked)
                    {
                        featureNode.Checked = true;
                        productChecked      = true;
                    }
                }
                productNode.Checked = productChecked;
            }
            treeViewFeatures.ExpandAll();
            treeViewFeatures.EndUpdate();
            _dirty = false;
        }
Esempio n. 8
0
        private void addGroup(bool isSubGroup, FeatureTypeNumber?type)
        {
            Enova.Business.Old.Forms.FeatureEditForm form = new Enova.Business.Old.Forms.FeatureEditForm(isSubGroup);

            DialogResult result = form.ShowDialog();

            if (result == DialogResult.OK && !string.IsNullOrEmpty(form.Value))
            {
                EnovaContext dc = Enova.Business.Old.Core.ContextManager.DataContext;

                if (treeView.SelectedNode is FeatureTreeNode && ((FeatureTreeNode)treeView.SelectedNode).FeatureDef.ID == 0)
                {
                    if (dc.FeatureDefs.Any(f => f.Name == form.Value))
                    {
                        MessageBox.Show("Istnieje już grupa o takiej nazwie.", "EnovaTools", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    FeatureTreeNode node       = (FeatureTreeNode)treeView.SelectedNode;
                    FeatureDef      featureDef = new FeatureDef(TableName, form.Value, type.Value);
                    ((Enova.Business.Old.Core.IContextSaveChanges)featureDef).SaveChanges(dc);

                    FeatureTreeNode newNode = new FeatureTreeNode(featureDef);
                    treeView.Nodes.Add(newNode);
                    treeView.SelectedNode = newNode;
                }
                else
                {
                    Dictionary parent     = null;
                    FeatureDef featureDef = null;
                    TreeNode   parentNode = null;
                    if (treeView.SelectedNode is FeatureTreeNode)
                    {
                        featureDef = ((FeatureTreeNode)treeView.SelectedNode).FeatureDef;
                        parentNode = treeView.SelectedNode;
                    }
                    else
                    {
                        featureDef = ((DictionaryTreeNode)treeView.SelectedNode).FeatureDef;
                        if (featureDef.IsTree)
                        {
                            parent     = ((DictionaryTreeNode)treeView.SelectedNode).Dictionary;
                            parentNode = treeView.SelectedNode;
                        }
                        else
                        {
                            parentNode = treeView.SelectedNode;
                            if (parentNode.Parent != null)
                            {
                                parentNode = parentNode.Parent;
                            }
                        }
                    }

                    Dictionary dictionary = new Dictionary(parent, "F." + featureDef.Dictionary, form.Value);
                    ((Enova.Business.Old.Core.ISaveChanges)dictionary).SaveChanges();

                    DictionaryTreeNode newNode = new DictionaryTreeNode(dictionary, featureDef);
                    parentNode.Nodes.Add(newNode);
                    treeView.SelectedNode = newNode;
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Recursively builds a tree.
        /// </summary>
        /// <param name="features">The current set of features to discriminate.</param>
        /// <param name="validOffsets">The list of offsets that can be used to discriminate features.</param>
        /// <param name="thisIsRoot">Set this to true if the current node to be built is the root node. This will
        /// make sure that the hotspot is chosen as the offset to use.</param>
        /// <returns>A feature tree node where every valid offset is checked and the leaf nodes of this indicate features.</returns>
        private static FeatureTreeNode BuildTreeHelper(List <FeatureWrapper> features, List <Point> validOffsets, bool thisIsRoot)
        {
            //Check if we're at a leaf node and return it if we are
            //If there's no features, then just make a null leaf.
            if (features.Count == 0)
            {
                return(null);
            }

            //If there's only one feature then create a leaf node.
            if (features.Count == 1)
            {
                return(new LeafFeatureTreeNode(features[0], validOffsets));
            }

            if (!AnyOffsetsThatDiscriminate(features, validOffsets))
            {
                throw new Exception("No two offests discriminate these features.");
            }
            //--------------------------------------------


            //Pick the offset (offsetToTest) that will be used to bucket the features and bucket the features by that offset
            //Pick the offset to use to build the current node's children and remove from the list of valid offsets.----------
            //And bucket the features by that offset.
            Point offsetToTest = new Point(0, 0);
            Dictionary <int, List <FeatureWrapper> > featuresByColor = ChooseOffsetToTeset(features, validOffsets, thisIsRoot, offsetToTest);
            List <Point> remainingValidOffsets = new List <Point>(validOffsets);

            remainingValidOffsets.Remove(offsetToTest);
            //----------------------------------------------------------------------------------------


            //Build the transparent child node
            //Build the transparent child-------------------------------------------------------------------

            FeatureTreeNode transparentNode = null;

            if (featuresByColor.ContainsKey(Feature.TRANSPARENT_VALUE))
            {
                transparentNode = BuildTreeHelper(featuresByColor[Feature.TRANSPARENT_VALUE], remainingValidOffsets, false);
                featuresByColor.Remove(Feature.TRANSPARENT_VALUE);
            }

            //----------------------------------------------------------------------------------------



            //Build the rest of the children------------------------------------------------------------------
            Dictionary <int, FeatureTreeNode> nodesByColor = new Dictionary <int, FeatureTreeNode>();

            foreach (int key in featuresByColor.Keys)
            {
                nodesByColor.Add(key, BuildTreeHelper(featuresByColor[key], remainingValidOffsets, false));
            }
            //-----------------------------------------------------------------------------------------



            return(new InnerFeatureTreeNode(offsetToTest, nodesByColor, transparentNode));
        }