Пример #1
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);
        }
Пример #2
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
        }