Exemplo n.º 1
0
        private void GroupLines()
        {
            var sectorLines = new List <LineDef>();
            var boundingBox = new Fixed[4];

            foreach (var line in this.lines)
            {
                if (line.Special != 0)
                {
                    var so = new Mobj(this.world);
                    so.X             = (line.Vertex1.X + line.Vertex2.X) / 2;
                    so.Y             = (line.Vertex1.Y + line.Vertex2.Y) / 2;
                    line.SoundOrigin = so;
                }
            }

            foreach (var sector in this.sectors)
            {
                sectorLines.Clear();
                Box.Clear(boundingBox);

                foreach (var line in this.lines)
                {
                    if (line.FrontSector == sector || line.BackSector == sector)
                    {
                        sectorLines.Add(line);
                        Box.AddPoint(boundingBox, line.Vertex1.X, line.Vertex1.Y);
                        Box.AddPoint(boundingBox, line.Vertex2.X, line.Vertex2.Y);
                    }
                }

                sector.Lines = sectorLines.ToArray();

                // Set the degenmobj_t to the middle of the bounding box.
                sector.SoundOrigin   = new Mobj(this.world);
                sector.SoundOrigin.X = (boundingBox[Box.Right] + boundingBox[Box.Left]) / 2;
                sector.SoundOrigin.Y = (boundingBox[Box.Top] + boundingBox[Box.Bottom]) / 2;

                sector.BlockBox = new int[4];
                int block;

                // Adjust bounding box to map blocks.
                block = (boundingBox[Box.Top] - this.blockMap.OriginY + GameConst.MaxThingRadius).Data >> BlockMap.FracToBlockShift;
                block = block >= this.blockMap.Height ? this.blockMap.Height - 1 : block;
                sector.BlockBox[Box.Top] = block;

                block = (boundingBox[Box.Bottom] - this.blockMap.OriginY - GameConst.MaxThingRadius).Data >> BlockMap.FracToBlockShift;
                block = block < 0 ? 0 : block;
                sector.BlockBox[Box.Bottom] = block;

                block = (boundingBox[Box.Right] - this.blockMap.OriginX + GameConst.MaxThingRadius).Data >> BlockMap.FracToBlockShift;
                block = block >= this.blockMap.Width ? this.blockMap.Width - 1 : block;
                sector.BlockBox[Box.Right] = block;

                block = (boundingBox[Box.Left] - this.blockMap.OriginX - GameConst.MaxThingRadius).Data >> BlockMap.FracToBlockShift;
                block = block < 0 ? 0 : block;
                sector.BlockBox[Box.Left] = block;
            }
        }
Exemplo n.º 2
0
        public void Add(JointCoordinate item)
        {
            BoundingBox.AddPoint(item.Point);
            list.Add(item);

            if (item.Point.x > 0)
            {
                if (max_x_positive < item.Point.x)
                {
                    max_x_positive = item.Point.x;
                }
            }
            else if (item.Point.x < 0)
            {
                if (max_x_negative < item.Point.x)
                {
                    max_x_negative = item.Point.x;
                }
            }
            if (item.Point.y > 0)
            {
                if (max_y_positive < item.Point.y)
                {
                    max_y_positive = item.Point.y;
                }
            }
            else if (item.Point.y < 0)
            {
                if (max_y_negative < item.Point.y)
                {
                    max_y_negative = item.Point.y;
                }
            }
            if (item.Point.z > 0)
            {
                if (max_z_positive < item.Point.z)
                {
                    max_z_positive = item.Point.z;
                }
            }
            else if (item.Point.z < 0)
            {
                if (max_z_negative < item.Point.z)
                {
                    max_z_negative = item.Point.z;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 匹配
        /// </summary>
        /// <param name="srcFigures"></param>
        /// <param name="itemsOfSample">样本组,里面包含多个图元</param>
        /// <returns></returns>
        public MatchItem Match(List <vdFigure> srcFigures, List <vdFigure> itemsOfSample)
        {
            if (itemsOfSample == null || itemsOfSample.Count < 2)
            {
                throw new ArgumentException(nameof(itemsOfSample));
            }

            //选中的样品,后续就是找跟这个相似的
            var sample = new FigureSet(itemsOfSample);

            var majorFilter = FilterFactory.Get(sample.Major.GetType());

            if (majorFilter == null)
            {
                return(null);
            }
            //从源图元集合中找出符合样本特征图元的元素
            var majorList = majorFilter.Filter(srcFigures, sample.Major);

            //样本组外包矩形
            var sampleBoundingBox = sample.GetBoundingBox();
            //样本组特征图元到中心点的位移
            var sampleOffsetOfMajor2Center = new gPoint(
                sampleBoundingBox.MidPoint.x - sample.Major.BoundingBox.MidPoint.x,
                sampleBoundingBox.MidPoint.y - sample.Major.BoundingBox.MidPoint.y);
            //样本组特征图元到中心点的位移长度
            var sampleOffsetLenOfMajor2Center = gPoint.Distance2D(sampleBoundingBox.MidPoint,
                                                                  sample.Major.BoundingBox.MidPoint);
            //sampleBoundingBox.MidPoint - sample.Major.BoundingBox.MidPoint;
            //样本外包矩形的对角线长度
            var sampleDiagonalLen = Math.Pow(Math.Pow(sampleBoundingBox.Width, 2.0) + Math.Pow(sampleBoundingBox.Height, 2.0), 0.5);

            //找到的和样本组类似的图元组集合
            var result = new MatchItem {
                Sample = sample, CadFileName = _document.FileName
            };

            //选择集合
            var selectingList = new List <vdFigure>();
            var debugLayer    = VdSqlUtil.AppendLayer(_document, "DebugLayer");

            VdSqlUtil.DeleteFiguresByLayer(_document.ActionLayout, debugLayer);
            foreach (var major in majorList)
            {
                //根据特征图元的中心点、样本组外包矩形的对角线长度,样本组特征图元到中心点的位移
                //计算该次框选的范围
                var boundingBox = new Box();
                boundingBox.AddPoint(major.BoundingBox.MidPoint);
                boundingBox.AddWidth((sampleDiagonalLen + sampleOffsetLenOfMajor2Center) / 2d + 1);
                //boundingBox.AddWidth(sampleMajorMaxLenOfBox);
                //boundingBox.AddWidth(1);
                //boundingBox.Offset(sampleOffsetOfMajor2Center.x, sampleOffsetOfMajor2Center.y, 0);

                //框选
                var selection = _document.Selections.Add("BoundingByMajor");
                selection.RemoveAll();
                selection.Select(RenderSelect.SelectingMode.WindowRectangle, new gPoints(new[] { boundingBox.UpperLeft, boundingBox.LowerRight }));

                //selectingList.Add(major);
                //selectingList.Add(AppendRect(_document, boundingBox, debugLayer));
                //continue;

                var fromFigures = selection.OfType <vdFigure>().ToList();
                fromFigures.Sort(new FigureMidPointComparer());
                //从框选结果中筛选图元
                var item = MatchCore(fromFigures, major, sample);
                if (item != null && GetXorItem(result, item) == null)
                {
                    result.Results.Add(item);
                    //selectingList.AddRange(item.Entities);
                }
                else
                {
                    //VdUtil.SelectFigures(_document, fromFigures);
                    //VdUtil.RefreshVectorDraw(_document);
                    //break;
                }
            }
            if (selectingList.Count > 0)
            {
                VdActionUtil.SelectFigures(_document, selectingList);
                VdActionUtil.RefreshVectorDraw(_document);
            }

            return(result);
        }
Exemplo n.º 4
0
        void BaseControl_vdMouseDown(MouseEventArgs e, ref bool cancel)
        {
            Childform frm = this.ActiveMdiChild as Childform;

            if (frm == null)
            {
                return;
            }

            if (e.Button != MouseButtons.Left)
            {
                return;
            }
            if (frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.OverAllActiveActions == null)
            {
                return;
            }
            if (frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.OverAllActiveActions.Count > 1)
            {
                return;
            }

            if (frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.ActiveAction is VectorDraw.Professional.CommandActions.ActionLine)
            {
                return;
            }
            vdSelection GripEntities = GetGripsCollection();
            gPoint      p1           = frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.ActiveActionRender.World2Pixelmatrix.Transform(frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.OverAllActiveAction.MouseLocation);
            gPoint      p1viewCS     = frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.ActiveActionRender.CurrentMatrix.Transform(frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.OverAllActiveAction.MouseLocation);
            Point       location     = new Point((int)p1.x, (int)p1.y);

            #region Grip Move Code
            if (System.Windows.Forms.Control.ModifierKeys == Keys.None)
            {
                Box box = new Box();
                box.AddPoint(p1viewCS);
                box.AddWidth(frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.ActiveActionRender.GlobalProperties.GripSize * frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.ActiveActionRender.PixelSize / 2.0d);

                vdSelection          selset       = new vdSelection();
                vdArray <Int32Array> indexesArray = new vdArray <Int32Array>();
                gPoint pt = frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.Document.World2UserMatrix.Transform(frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.OverAllActiveAction.MouseLocation);
                foreach (vdFigure fig in GripEntities)
                {
                    Int32Array indexes = frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.getGripIndexes(fig, box);
                    if (indexes.Count != 0)
                    {
                        selset.AddItem(fig, false, vdSelection.AddItemCheck.Nochecking);
                        indexesArray.AddItem(indexes);
                    }
                }
                if (selset.Count > 0)
                {
                    VectorDraw.Professional.ActionUtilities.CmdMoveGripPoints MoveGrips = new VectorDraw.Professional.ActionUtilities.CmdMoveGripPoints(pt, frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut, selset, indexesArray);
                    frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.ActionAdd(MoveGrips);
                    VectorDraw.Actions.StatusCode ret = MoveGrips.WaitToFinish();
                    cancel = true;
                    return;
                }
            }
            #endregion

            #region One by One implementation
            vdFigure Fig = null;
            Fig = frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.GetEntityFromPoint(location, frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.ActiveActionRender.GlobalProperties.PickSize, false, vdDocument.LockLayerMethodEnum.EnableGetObjectGrip);
            frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.Document.LockLayerMethodStack.Push(vdDocument.LockLayerMethodEnum.DisableAll | ((frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.Document.LockLayerMethod & vdDocument.LockLayerMethodEnum.EnableGetObjectGrip) != 0 ? vdDocument.LockLayerMethodEnum.EnableAddToSelections : 0));
            bool bShift = ((System.Windows.Forms.Control.ModifierKeys & Keys.Shift) == Keys.Shift);
            if (Fig != null)
            {
                ClearAllGrips(GripEntities);
                GripEntities.AddItem(Fig, true, vdSelection.AddItemCheck.RemoveInVisibleEntities);
                if (cancel)
                {
                    Fig.ShowGrips = false;
                }
                else
                {
                    Fig.ShowGrips = true;
                }
                frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.RefreshGraphicsControl(frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.ActiveActionRender.control);
                //  DrawGrips(GripEntities);
            }
            frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.Document.LockLayerMethodStack.Pop();
            #endregion
        }