コード例 #1
0
        protected bool GetCubeAddAndRemovePositions(Vector3I intersectedCube, bool placingSmallGridOnLargeStatic, out Vector3I addPos, out Vector3I addDir, out Vector3I removePos)
        {
            bool result = false;

            addPos    = new Vector3I();
            addDir    = new Vector3I();
            removePos = new Vector3I();

            MatrixD worldInv = MatrixD.Invert(CurrentGrid.WorldMatrix);

            Vector3D intersectionPos;

            addPos = intersectedCube;
            addDir = Vector3I.Forward;

            Vector3D rayStart = Vector3D.Transform(IntersectionStart, worldInv);
            Vector3D rayDir   = Vector3D.Normalize(Vector3D.TransformNormal(IntersectionDirection, worldInv));

            RayD r = new RayD(rayStart, rayDir);

            for (int i = 0; i < 100; ++i) // Limit iterations to 100
            {
                var cubeBb = GetCubeBoundingBox(addPos);
                if (!placingSmallGridOnLargeStatic && cubeBb.Contains(rayStart) == ContainmentType.Contains)
                {
                    break;
                }

                double?dist = cubeBb.Intersects(r);
                if (!dist.HasValue)
                {
                    break;
                }

                removePos = addPos;

                intersectionPos = rayStart + rayDir * dist.Value;
                Vector3  center = removePos * CurrentGrid.GridSize;
                Vector3I dirInt = Vector3I.Sign(Vector3.DominantAxisProjection(intersectionPos - center));

                addPos = removePos + dirInt;
                addDir = dirInt;
                result = true;

                if (!CurrentGrid.CubeExists(addPos))
                {
                    break;
                }
            }

            Debug.Assert(!result || addDir != Vector3I.Zero, "Direction vector cannot be zero");
            return(result);
        }
コード例 #2
0
        protected override Vector2 LimitMovePosition(Vector2 _position)
        {
            if (InvalidNextPosition(_position))
            {
                CurrentGrid.SetCurrentUnitObject(this);
                return(transform.position);
            }

            CurrentGrid.SetCurrentUnitObject(null);

            return(new Vector2(Mathf.Clamp(_position.x, -(GameManager.ScreenBounds.x + Width), GameManager.ScreenBounds.x - Width),
                               Mathf.Clamp(_position.y, -(GameManager.ScreenBounds.y + Height), GameManager.LimitScreenHeight)));
        }
コード例 #3
0
        protected void ShowProperties(XmlNode xmlNode)
        {
            XmlAttributeAdapter attAdapter = null;

            if (xmlNode != null)
            {
                attAdapter = new XmlAttributeAdapter(xmlNode, WixFiles);
            }

            CurrentGrid.SelectedObject = attAdapter;
            CurrentGrid.Update();

            return;
        }
コード例 #4
0
        public void LoadFileParallel(string FileName)
        {
            using (StreamReader sr = new StreamReader(FileName))
            {
                List <string> lines    = new List <string>();
                bool          finished = false;

                while (!finished)
                {
                    lines.Clear();
                    for (int i = 0; i < 10000; i++)
                    {
                        if (sr.EndOfStream)
                        {
                            finished = true;
                            break;
                        }
                        lines.Add(sr.ReadLine());
                    }

                    Parallel.ForEach(lines, l =>
                    {
                        var data   = l.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                        int gridid = int.Parse(data[0]);

                        GridLeach CurrentGrid = null;
                        if (!Grids.TryGetValue(gridid, out CurrentGrid)) //Check if we have read the grid before. No need for the grids to be ordered
                        {
                            CurrentGrid           = new GridLeach(gridid);
                            CurrentGrid.SoilID    = int.Parse(data[4]);
                            CurrentGrid.DMIGridID = int.Parse(data[5]);
                            CurrentGrid.LandUseID = int.Parse(data[6]);
                            lock (Lock)
                                Grids.Add(gridid, CurrentGrid);
                        }

                        //If the end date is written
                        //          DateTime Start = new DateTime(int.Parse(data[1]), int.Parse(data[2]), int.Parse(data[3])).AddDays(-int.Parse(data[7]) + 1);
                        //If the start date is written
                        DateTime Start = new DateTime(int.Parse(data[1]), int.Parse(data[2]), int.Parse(data[3]));
                        CurrentGrid.AddYear(Start, data.Skip(9).Select(v => float.Parse(v)).ToArray());
                    });
                }
            }
        }
コード例 #5
0
        protected void OnDeletePropertyGridItem(object sender, EventArgs e)
        {
            XmlNode element = GetSelectedProperty();

            if (element == null)
            {
                throw new WixEditException("No element found to delete!");
            }

            // Temporarily store the XmlAttributeAdapter, while resetting the CurrentGrid.
            PropertyAdapterBase attAdapter = (PropertyAdapterBase)CurrentGrid.SelectedObject;

            CurrentGrid.SelectedObject = null;

            WixFiles.UndoManager.BeginNewCommandRange();
            attAdapter.RemoveProperty(element);

            // Update the CurrentGrid.
            CurrentGrid.SelectedObject = attAdapter;
            CurrentGrid.Update();
        }
コード例 #6
0
        void CurrentGrid_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
        {
            GridItem item = e.ChangedItem;

            if (item.Label == "Id" && !String.IsNullOrEmpty((string)e.OldValue))
            {
                XmlAttributePropertyDescriptor pd = (XmlAttributePropertyDescriptor)item.PropertyDescriptor;
                XmlNodeList equalNamedColumns     = pd.Attribute.OwnerElement.ParentNode.SelectNodes(String.Format("wix:Column[@Id='{0}']", item.Value), WixFiles.WxsNsmgr);
                if (equalNamedColumns.Count >= 2)
                {
                    MessageBox.Show(String.Format("There is already a column with the name \"{0}\"!", item.Value), "Duplicate column name", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    // Rollback
                    WixFiles.UndoManager.Undo();

                    // Refresh the tree
                    if (CurrentTreeView.SelectedNode != null)
                    {
                        XmlNode node        = (XmlNode)currTreeView.SelectedNode.Tag;
                        string  displayName = GetDisplayName(node);
                        if (displayName != null && displayName.Length > 0 &&
                            currTreeView.SelectedNode.Text != displayName)
                        {
                            currTreeView.SelectedNode.Text = displayName;
                        }
                    }

                    // and the grid
                    CurrentGrid.Refresh();
                }
                else
                {
                    // Rename all row elements
                    foreach (XmlElement dataElement in pd.Attribute.OwnerElement.ParentNode.SelectNodes(String.Format("wix:Row/wix:Data[@Column='{0}']", e.OldValue), WixFiles.WxsNsmgr))
                    {
                        dataElement.SetAttribute("Column", (string)item.Value);
                    }
                }
            }
        }
コード例 #7
0
        protected override Vector2 LimitMovePosition(Vector2 _position)
        {
            if (InvalidNextPosition(_position))
            {
                CurrentGrid.SetCurrentUnitObject(this);

                if (_GoUp)
                {
                    GoUp();
                }
                else
                {
                    GoDown();
                }

                ToggleDirection();

                return(transform.position);
            }

            CurrentGrid.SetCurrentUnitObject(null);
            return(_position);
        }
コード例 #8
0
        protected bool GetBlockAddPosition(float gridSize, bool placingSmallGridOnLargeStatic, out MySlimBlock intersectedBlock, out Vector3D intersectedBlockPos, out Vector3D intersectExactPos,
                                           out Vector3I addPositionBlock, out Vector3I addDirectionBlock, out ushort?compoundBlockId)
        {
            intersectedBlock    = null;
            intersectedBlockPos = new Vector3D();
            intersectExactPos   = new Vector3();
            addDirectionBlock   = new Vector3I();
            addPositionBlock    = new Vector3I();
            compoundBlockId     = null;

            if (CurrentVoxelBase != null)
            {
                Vector3 hitInfoNormal = m_hitInfo.Value.HkHitInfo.Normal;
                Base6Directions.Direction closestDir = Base6Directions.GetClosestDirection(hitInfoNormal);
                Vector3I hitNormal = Base6Directions.GetIntVector(closestDir);

                double distance = IntersectionDistance * m_hitInfo.Value.HkHitInfo.HitFraction;

                Vector3D rayStart     = IntersectionStart;
                Vector3D rayDir       = Vector3D.Normalize(IntersectionDirection);
                Vector3D intersection = rayStart + distance * rayDir;

                // Get cube block placement position (add little threshold to hit normal direction to avoid wavy surfaces).
                addPositionBlock    = MyCubeGrid.StaticGlobalGrid_WorldToUGInt(intersection + 0.1f * Vector3.Half * hitNormal * gridSize, gridSize, CubeBuilderDefinition.BuildingSettings.StaticGridAlignToCenter);
                addDirectionBlock   = hitNormal;
                intersectedBlockPos = addPositionBlock - hitNormal;

                // Exact intersection in uniform grid coords.
                intersectExactPos = MyCubeGrid.StaticGlobalGrid_WorldToUG(intersection, gridSize, CubeBuilderDefinition.BuildingSettings.StaticGridAlignToCenter);
                // Project exact intersection to cube face of intersected block.
                intersectExactPos = ((Vector3.One - Vector3.Abs(hitNormal)) * intersectExactPos) + ((intersectedBlockPos + 0.5f * hitNormal) * Vector3.Abs(hitNormal));

                return(true);
            }

            Vector3D?intersectedObjectPos = GetIntersectedBlockData(ref m_invGridWorldMatrix, out intersectExactPos, out intersectedBlock, out compoundBlockId);

            if (intersectedObjectPos == null)
            {
                return(false);
            }

            intersectedBlockPos = intersectedObjectPos.Value;

            Vector3I removePos;

            if (!GetCubeAddAndRemovePositions(Vector3I.Round(intersectedBlockPos), placingSmallGridOnLargeStatic, out addPositionBlock, out addDirectionBlock, out removePos))
            {
                return(false);
            }

            if (!placingSmallGridOnLargeStatic)
            {
                if (MyFakes.ENABLE_BLOCK_PLACING_ON_INTERSECTED_POSITION)
                {
                    Vector3I newRemovepos = Vector3I.Round(intersectedBlockPos);

                    if (newRemovepos != removePos)
                    {
                        if (m_hitInfo.HasValue)
                        {
                            Vector3 hitInfoNormal = m_hitInfo.Value.HkHitInfo.Normal;
                            Base6Directions.Direction closestDir = Base6Directions.GetClosestDirection(hitInfoNormal);
                            Vector3I hitNormal = Base6Directions.GetIntVector(closestDir);
                            addDirectionBlock = hitNormal;
                        }
                        removePos        = newRemovepos;
                        addPositionBlock = removePos + addDirectionBlock;
                    }
                }
                else
                {
                    if (CurrentGrid.CubeExists(addPositionBlock))
                    {
                        return(false);
                    }
                }
            }

            if (placingSmallGridOnLargeStatic)
            {
                removePos = Vector3I.Round(intersectedBlockPos);
            }

            intersectedBlockPos = removePos;
            intersectedBlock    = CurrentGrid.GetCubeBlock(removePos);
            if (intersectedBlock == null)
            {
                Debug.Assert(false, "No intersected block");
                return(false);
            }

            return(true);
        }
コード例 #9
0
        /// <summary>
        /// Calculates exact intersection point (in uniform grid coordinates) from stored havok's hit info object obtained during FindClosest grid.
        /// Returns position of intersected object in uniform grid coordinates.
        /// </summary>
        protected Vector3D?GetIntersectedBlockData(ref MatrixD inverseGridWorldMatrix, out Vector3D intersection, out MySlimBlock intersectedBlock, out ushort?compoundBlockId)
        {
            Debug.Assert(m_hitInfo != null);
            //Debug.Assert(m_hitInfo.Value.HkHitInfo.GetEntity() == CurrentGrid);

            intersection     = Vector3D.Zero;
            intersectedBlock = null;
            compoundBlockId  = null;

            Debug.Assert(CurrentGrid != null);
            if (CurrentGrid == null)
            {
                return(null);
            }

            double   distance             = double.MaxValue;
            Vector3D?intersectedObjectPos = null;

            var      line     = new LineD(IntersectionStart, IntersectionStart + IntersectionDirection * IntersectionDistance);
            Vector3I position = Vector3I.Zero;

            if (!CurrentGrid.GetLineIntersectionExactGrid(ref line, ref position, ref distance, m_hitInfo.Value))
            {
                return(null);
            }

            distance             = Math.Sqrt(distance);
            intersectedObjectPos = position;

            intersectedBlock = CurrentGrid.GetCubeBlock(position);
            if (intersectedBlock == null)
            {
                return(null);
            }

            // Compound block - get index of internal block for removing
            if (intersectedBlock.FatBlock is MyCompoundCubeBlock)
            {
                MyCompoundCubeBlock compoundBlock = intersectedBlock.FatBlock as MyCompoundCubeBlock;
                ushort?idInCompound = null;

                ushort blockId;
                VRage.Game.Models.MyIntersectionResultLineTriangleEx?triIntersection;

                if (compoundBlock.GetIntersectionWithLine(ref line, out triIntersection, out blockId))
                {
                    idInCompound = blockId;
                }
                else if (compoundBlock.GetBlocksCount() == 1) // If not intersecting with any internal block and there is only one then set the index to it
                {
                    idInCompound = compoundBlock.GetBlockId(compoundBlock.GetBlocks()[0]);
                }

                compoundBlockId = idInCompound;
            }

            Debug.Assert(intersectedObjectPos != null);
            Vector3D rayStart = Vector3D.Transform(IntersectionStart, inverseGridWorldMatrix);
            Vector3D rayDir   = Vector3D.Normalize(Vector3D.TransformNormal(IntersectionDirection, inverseGridWorldMatrix));

            intersection  = rayStart + distance * rayDir;
            intersection *= 1.0f / CurrentGrid.GridSize;

            return(intersectedObjectPos);
        }
コード例 #10
0
        /// <summary>
        /// Calculates exact intersection point (in uniform grid coordinates) from stored havok's hit info object obtained during FindClosest grid.
        /// Returns position of intersected object in uniform grid coordinates.
        /// </summary>
        protected Vector3D?GetIntersectedBlockData(ref MatrixD inverseGridWorldMatrix, out Vector3D intersection, out MySlimBlock intersectedBlock, out ushort?compoundBlockId)
        {
            Debug.Assert(m_hitInfo != null);
            Debug.Assert(m_hitInfo.Value.HkHitInfo.Body.GetEntity() == CurrentGrid);

            intersection     = Vector3D.Zero;
            intersectedBlock = null;
            compoundBlockId  = null;

            double   distance             = double.MaxValue;
            Vector3D?intersectedObjectPos = null;

            var      line     = new LineD(IntersectionStart, IntersectionStart + IntersectionDirection * IntersectionDistance);
            Vector3I position = Vector3I.Zero;

            if (!CurrentGrid.GetLineIntersectionExactGrid(ref line, ref position, ref distance, m_hitInfo.Value))
            {
                return(null);
            }

            distance             = Math.Sqrt(distance);
            intersectedObjectPos = position;

            intersectedBlock = CurrentGrid.GetCubeBlock(position);
            if (intersectedBlock == null)
            {
                return(null);
            }

            // Compound block - get index of internal block for removing
            if (intersectedBlock.FatBlock is MyCompoundCubeBlock)
            {
                MyCompoundCubeBlock      compoundBlock        = intersectedBlock.FatBlock as MyCompoundCubeBlock;
                ListReader <MySlimBlock> slimBlocksInCompound = compoundBlock.GetBlocks();
                double distanceSquaredInCompound = double.MaxValue;
                ushort?idInCompound = null;
                for (int i = 0; i < slimBlocksInCompound.Count; ++i)
                {
                    MySlimBlock cmpSlimBlock = slimBlocksInCompound.ItemAt(i);
                    MyIntersectionResultLineTriangleEx?intersectionTriResult;
                    if (cmpSlimBlock.FatBlock.GetIntersectionWithLine(ref line, out intersectionTriResult) && intersectionTriResult != null)
                    {
                        Vector3D startToIntersection = intersectionTriResult.Value.IntersectionPointInWorldSpace - IntersectionStart;
                        double   instrDistanceSq     = startToIntersection.LengthSquared();
                        if (instrDistanceSq < distanceSquaredInCompound)
                        {
                            distanceSquaredInCompound = instrDistanceSq;
                            idInCompound = compoundBlock.GetBlockId(cmpSlimBlock);
                        }
                    }
                }

                // If not intersecting with any internal block and there is only one then set the index to it
                if (idInCompound == null && compoundBlock.GetBlocksCount() == 1)
                {
                    idInCompound = compoundBlock.GetBlockId(compoundBlock.GetBlocks()[0]);
                }

                compoundBlockId = idInCompound;
            }

            Debug.Assert(intersectedObjectPos != null);
            Vector3D rayStart = Vector3D.Transform(IntersectionStart, inverseGridWorldMatrix);
            Vector3D rayDir   = Vector3D.Normalize(Vector3D.TransformNormal(IntersectionDirection, inverseGridWorldMatrix));

            intersection  = rayStart + distance * rayDir;
            intersection *= 1.0f / CurrentGrid.GridSize;

            return(intersectedObjectPos);
        }
コード例 #11
0
        public void OnNewPropertyGridItem(object sender, EventArgs e)
        {
            WixFiles.UndoManager.BeginNewCommandRange();

            // Temporarily store the XmlAttributeAdapter
            XmlAttributeAdapter attAdapter = (XmlAttributeAdapter)CurrentGrid.SelectedObject;

            ArrayList attributes = new ArrayList();

            XmlNodeList xmlAttributes = attAdapter.XmlNodeDefinition.SelectNodes("xs:attribute", WixFiles.XsdNsmgr);

            foreach (XmlNode at in xmlAttributes)
            {
                string attName = at.Attributes["name"].Value;
                if (attAdapter.XmlNode.Attributes[attName] == null)
                {
                    attributes.Add(attName);
                }
            }

            if (attAdapter.XmlNodeDefinition.Name == "xs:extension")
            {
                bool hasInnerText = false;
                foreach (GridItem it in CurrentGrid.SelectedGridItem.Parent.GridItems)
                {
                    if (it.Label == "InnerText")
                    {
                        hasInnerText = true;
                        break;
                    }
                }
                if (hasInnerText == false)
                {
                    attributes.Add("InnerText");
                }
            }

            attributes.Sort();

            SelectStringForm frm = new SelectStringForm();

            frm.PossibleStrings = attributes.ToArray(typeof(String)) as String[];
            if (DialogResult.OK != frm.ShowDialog() ||
                frm.SelectedStrings.Length == 0)
            {
                return;
            }

            // Show dialog to choose from available items.
            XmlAttribute att = null;

            foreach (string newAttributeName in frm.SelectedStrings)
            {
                if (string.Equals(newAttributeName, "InnerText"))
                {
                    attAdapter.ShowInnerTextIfEmpty = true;
                }
                else
                {
                    att = WixFiles.WxsDocument.CreateAttribute(newAttributeName);
                    attAdapter.XmlNode.Attributes.Append(att);
                }
            }

            CurrentGrid.SelectedObject = null;
            // Update the CurrentGrid.
            CurrentGrid.SelectedObject = attAdapter;
            CurrentGrid.Update();

            string firstNewAttributeName = frm.SelectedStrings[0];

            foreach (GridItem it in CurrentGrid.SelectedGridItem.Parent.GridItems)
            {
                if (it.Label == firstNewAttributeName)
                {
                    CurrentGrid.SelectedGridItem = it;
                    break;
                }
            }
        }
コード例 #12
0
        private void UnChecked(object sender, RoutedEventArgs e)
        {
            if (_isLoading)
            {
                return;
            }
            try
            {
                _isLoading = true;
                var checkbox = (CheckBox)sender;
                var listBox  = FindControls.FindParent <ListBox>(checkbox);
                AutoFilterHelper.CurrentListBox = listBox;
                var popup = (Popup)((StackPanel)(listBox.Parent)).Parent;
                var grid  = FindControls.FindParent <ExtendedDataGrid>(popup);
                CurrentGrid = AutoFilterHelper.CurrentGrid = grid;
                var value = Convert.ToString(checkbox.Content);
                if (Convert.ToString(checkbox.Tag) != "(Select All)")
                {
                    var distictValues = AutoFilterHelper.CurrentListBox.ItemsSource as List <CheckedListItem>;
                    if (distictValues != null)
                    {
                        var countOfFiltersSelected = distictValues.Count(c => c.IsChecked && c.Name != "(Select All)" && c.IsSelectAll != "(Select All)");
                        if (countOfFiltersSelected == distictValues.Count - 1)
                        {
                            _isLoading = true;
                            distictValues[0].IsChecked = false;


                            AutoFilterHelper.CurrentListBox.UpdateLayout();
                            AutoFilterHelper.CurrentListBox.Items.Refresh();
                        }

                        bool isFilterApplicable = !string.IsNullOrEmpty(((DataView)CurrentGrid.ItemsSource).RowFilter) && ((DataView)CurrentGrid.ItemsSource).RowFilter.Contains(CurrentColumn + "  IN ");
                        if (!isFilterApplicable)
                        {
                            if (string.IsNullOrEmpty(((DataView)CurrentGrid.ItemsSource).RowFilter))
                            {
                                var actualValues = ((DataView)CurrentGrid.ItemsSource).Table.Rows.Cast <DataRow>().Select(row => Convert.ToString(row[CurrentColumn])).Where(val => val != value).ToList();


                                AutoFilterHelper.ApplyFilters(CurrentGrid, CurrentColumn, actualValues);


                                var distictictValues = AutoFilterHelper.CurrentDistictValues;
                                distictictValues[0].IsChecked         = false;
                                AutoFilterHelper.CurrentDistictValues = distictictValues;
                                AutoFilterHelper.CurrentListBox.Items.Refresh();
                                popup.Tag = distictictValues.Count(c => c.IsChecked) == 0 ? "False" : "True";
                                CurrentGrid.Items.Refresh();
                                CurrentGrid.UpdateLayout();
                                return;
                            }
                            else
                            {
                                AutoFilterHelper.CurrentDistictValues[0].IsChecked = countOfFiltersSelected == distictValues.Count - 1;
                                AutoFilterHelper.CurrentListBox.Items.Refresh();
                                AutoFilterHelper.CurrentListBox.UpdateLayout();
                                popup.Tag = AutoFilterHelper.CurrentDistictValues.Count(c => c.IsChecked) == 0 ? "False" : "True";
                                CurrentGrid.Items.Refresh();
                                CurrentGrid.UpdateLayout();
                            }
                        }
                        else
                        {
                            AutoFilterHelper.RemoveFilters(CurrentGrid, CurrentColumn, value);
                            var distictictValues = AutoFilterHelper.CurrentDistictValues;
                            popup.Tag = distictictValues.Count(c => c.IsChecked) == 0 ? "False" : "True";
                        }
                    }
                }

                else
                {
                    _isLoading = true;
                    var distictictValues = AutoFilterHelper.CurrentDistictValues;
                    distictictValues[0].IsChecked = false;
                    foreach (var distictictValue in distictictValues)
                    {
                        if (distictictValue.Name != "(Select All)" && distictictValue.IsSelectAll != "(Select All)")
                        {
                            distictictValue.IsChecked = false;
                        }
                    }
                    AutoFilterHelper.CurrentDistictValues = distictictValues;
                    AutoFilterHelper.RemoveAllFilter(CurrentGrid, CurrentColumn);
                    AutoFilterHelper.CurrentListBox.Items.Refresh();
                    var countOfFiltersSelected = distictictValues.Count(c => c.IsChecked && c.Name != "(Select All)");
                    popup.Tag = countOfFiltersSelected == 0?"False":"True";
                }
                AutoFilterHelper.CurrentGrid.Items.Refresh();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            finally
            {
                _isLoading = false;
            }
        }