Ejemplo n.º 1
0
        public bool CalculateLocations()
        {
            VLCoordinateType coordinateType = VLCoordinateType.XY;

            UpdateVector(coordinateType);

            var target        = Document.GetElement(TargetId);
            var locationCurve = (target.Location as LocationCurve).Curve as Line;
            //干线起始点
            var lineBound = Line.CreateBound(BodyStartPoint, BodyEndPoint);

            if (lineBound.VL_IsIntersect(locationCurve))
            {
                var intersectionPoints = lineBound.VL_GetIntersectedOrContainedPoints(locationCurve);
                if (intersectionPoints.Count == 1)
                {
                    BodyStartPoint = intersectionPoints.FirstOrDefault().ToSameZ(BodyEndPoint);//.ToSameZ(BodyStartPoint);
                }
            }
            else
            {
            }        //否则不改变原始坐标,仅重置
                     //支线终点
            if (AnnotationType == PBPAAnnotationType.OneLine)
            {
                if (!IsRegenerate)
                {
                    LeafEndPoint = BodyEndPoint + LineWidth * ParallelVector;
                }
                //文本位置 start:(附着元素中点+线基本高度+文本高度*(文本个数-1))  end: start+宽
                //高度,宽度 取决于文本
                AnnotationLocation = BodyEndPoint;
            }
            else
            {
                if (!IsRegenerate)
                {
                    LeafEndPoint = BodyEndPoint + (IsReversed ? -LineWidth * ParallelVector : LineWidth * ParallelVector);
                }
                var bb = BodyEndPoint - BodyStartPoint;
                var lb = (LeafEndPoint - BodyEndPoint);
                if (lb.CrossProductByCoordinateType(bb, VLCoordinateType.XY) < 0)
                {
                    var temp = LeafEndPoint;
                    LeafEndPoint = BodyEndPoint;
                    BodyEndPoint = temp;
                }
                //文本位置 start:(附着元素中点+线基本高度+文本高度*(文本个数-1))  end: start+宽
                //高度,宽度 取决于文本
                if (bb.CrossProductByCoordinateType(ParallelVector, VLCoordinateType.XY) < 0)
                {
                    AnnotationLocation = LeafEndPoint;
                }
                else
                {
                    AnnotationLocation = BodyEndPoint;
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        public void UpdateVector(VLCoordinateType coordinateType)
        {
            var pVector = coordinateType.GetParallelVector();

            pVector = VLLocationHelper.GetVectorByQuadrant(pVector, QuadrantType.OneAndFour, coordinateType);
            var vVector = VLLocationHelper.GetVerticalVector(pVector, VLCoordinateType.XY);

            vVector        = VLLocationHelper.GetVectorByQuadrant(vVector, QuadrantType.OneAndFour, coordinateType);
            VerticalVector = vVector;
            ParallelVector = pVector;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获得parallelVector相交的Z轴为0的向量
        /// </summary>
        /// <param name="parallelVector"></param>
        /// <returns></returns>
        public static XYZ GetVerticalVector(XYZ parallelVector, VLCoordinateType coordinateType)
        {
            switch (coordinateType)
            {
            case VLCoordinateType.XY:
                return(new XYZ(parallelVector.Y, -parallelVector.X, 0));

            case VLCoordinateType.YZ:
            case VLCoordinateType.XZ:
            default:
                throw new NotImplementedException("未支持");
            }
        }
Ejemplo n.º 4
0
        public static double GetLengthByCoordinate(this XYZ vector, VLCoordinateType coordinateType = VLCoordinateType.XY)
        {
            switch (coordinateType)
            {
            case VLCoordinateType.XY:
                return(Math.Sqrt(vector.X * vector.X + vector.Y * vector.Y));

            case VLCoordinateType.YZ:
            case VLCoordinateType.XZ:
            default:
                throw new NotImplementedException("");
            }
        }
Ejemplo n.º 5
0
        public static double CrossProductByCoordinateType(this XYZ lb, XYZ bb, VLCoordinateType coordinateType)
        {
            switch (coordinateType)
            {
            case VLCoordinateType.XY:
                return(lb.X * bb.X + lb.Y * bb.Y);

            case VLCoordinateType.YZ:
            case VLCoordinateType.XZ:
            default:
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 6
0
        public static double DotProductByCoordinate(this XYZ vector, XYZ vector2, VLCoordinateType coordinateType = VLCoordinateType.XY)
        {
            switch (coordinateType)
            {
            case VLCoordinateType.XY:
                return(vector.X * vector2.X + vector.Y * vector2.Y);

            case VLCoordinateType.YZ:
            case VLCoordinateType.XZ:
            default:
                throw new NotImplementedException("");
            }
        }
Ejemplo n.º 7
0
        public static XYZ RevertByCoordinateType(this XYZ vector, VLCoordinateType coordinateType)
        {
            switch (coordinateType)
            {
            case VLCoordinateType.XY:
                return(new XYZ(-vector.X, -vector.Y, vector.Z));

            case VLCoordinateType.YZ:
            case VLCoordinateType.XZ:
            default:
                throw new NotImplementedException("未支持");
            }
        }
Ejemplo n.º 8
0
        public DrawAreaView(UIApplication uiApp, VLCoordinateType coordinateType = VLCoordinateType.XY)
        {
            UIView         = uiApp.ActiveUIDocument.GetOpenUIViews().FirstOrDefault(p => p.ViewId == uiApp.ActiveUIDocument.ActiveGraphicalView.Id);
            CoordinateType = coordinateType;

            InitializeComponent();

            new System.Windows.Interop.WindowInteropHelper(this).Owner = Autodesk.Windows.ComponentManager.ApplicationWindow;

            Rect        = UIView.GetWindowRectangle();
            this.Left   = Rect.Left;
            this.Top    = Rect.Top;
            this.Width  = Rect.Right - Rect.Left;
            this.Height = Rect.Bottom - Rect.Top;
            co_s        = co_e = Height / 400;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 选择点,带预览,空时返回null
        /// </summary>
        /// <param name="uiApp"></param>
        /// <param name="startPoint"></param>
        /// <returns></returns>
        public XYZ PickPointWithPreview(UIApplication uiApp, VLCoordinateType coordinateType, Action <DrawAreaView> preview = null)
        {
            XYZ      result = null;
            Document doc    = uiApp.ActiveUIDocument.Document;

            #region old鼠标右键取消
            //PickObjectsMouseHook mouseHook = null;
            //mouseHook = InitMouseHook();
            //try
            //{
            //    result = uiApp.ActiveUIDocument.Selection.PickPoint("PM-预览绘线中,鼠标左键确定,右键取消");//Autodesk.Revit.UI.Selection.ObjectSnapTypes.Endpoints,
            //}
            //catch
            //{
            //    mouseHook.UninstallHook();
            //}
            //mouseHook.Dispose();
            //mouseHook = null;
            #endregion

            //选点
            System.Windows.Forms.Timer timer = null;
            DrawAreaView view = null;
            VLHookHelper.DelegateKeyBoardHook(() =>
            {
                IntPtr intPtr = Process.GetCurrentProcess().MainWindowHandle;
                view          = new DrawAreaView(uiApp, coordinateType);
                view.Show();
                //开启定时器 实时绘图
                timer          = new System.Windows.Forms.Timer();
                timer.Interval = 6;
                timer.Tick    += (sender, e) =>
                {
                    if (preview != null)
                    {
                        preview(view);
                    }
                };
                timer.Start();
                SetForegroundWindow(intPtr.ToInt32());
                result = uiApp.ActiveUIDocument.Selection.PickPoint("PM-预览绘线中,鼠标左键确定,ESC取消");
            });
            timer.Stop();
            view.Close();
            return(result);
        }
Ejemplo n.º 10
0
        public static System.Windows.Point ToWindowsPoint(this XYZ xyz, VLCoordinateType coordinateType = VLCoordinateType.XY)
        {
            switch (coordinateType)
            {
            case VLCoordinateType.XY:
                return(new System.Windows.Point(xyz.X, xyz.Y));

            case VLCoordinateType.YZ:
                return(new System.Windows.Point(xyz.Y, xyz.Z));

            case VLCoordinateType.XZ:
                return(new System.Windows.Point(xyz.X, xyz.Z));

            default:
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 转移到相同的Z轴
        /// </summary>
        /// <param name="point"></param>
        /// <param name="pointZ"></param>
        /// <returns></returns>
        public static XYZ ToSame(this XYZ point1, XYZ point2, VLCoordinateType coordinateType)
        {
            switch (coordinateType)
            {
            case VLCoordinateType.XY:
                return(new XYZ(point1.X, point1.Y, point2.Z));

            case VLCoordinateType.YZ:
                return(new XYZ(point2.X, point1.Y, point1.Z));

            case VLCoordinateType.XZ:
                return(new XYZ(point1.X, point2.Y, point1.Z));

            default:
                return(null);
            }
        }
Ejemplo n.º 12
0
        public static XYZ GetParallelVector(this VLCoordinateType type)
        {
            switch (type)
            {
            case VLCoordinateType.XY:
                return(new XYZ(1, 0, 0));

            case VLCoordinateType.YZ:
                return(new XYZ(0, 1, 0));

            case VLCoordinateType.XZ:
                return(new XYZ(1, 0, 0));

            default:
                return(null);
            }
        }
Ejemplo n.º 13
0
        public override void Execute()
        {
            PBPAModelCollection collection;
            var viewType = (PBPAViewType)Enum.Parse(typeof(PBPAViewType), ViewType.ToString());

            switch (viewType)
            {
            case PBPAViewType.Idle:
                View = new PBPAWindow(this);
                View.ShowDialog();
                break;

            case PBPAViewType.Close:
                View.Close();
                SaveSetting();
                break;

            case PBPAViewType.Closing:
                SaveSetting();
                break;

            case PBPAViewType.RegenerateAllFor_L:
                VLTransactionHelper.DelegateTransaction(Document, "RegenerateAllFor_L", (Func <bool>)(() =>
                {
                    collection = PBPAContext.GetCollection(Document);
                    for (int i = collection.Data.Count - 1; i >= 0; i--)
                    {
                        var model          = collection.Data[i];
                        model.Document     = Document;
                        model.IsRegenerate = true;

                        var element = Document.GetElement(model.TargetId);
                        element.GetParameters(PBPAContext.SharedParameterPL).FirstOrDefault().Set(model.GetFull_L(element));
                        if (!PBPAContext.Creator.Regenerate(model))
                        {
                            collection.Data.Remove(model);
                        }
                    }
                    collection.Save(Document);
                    return(true);
                }));
                ViewType = (int)PBPAViewType.Idle;
                break;

            case PBPAViewType.PickSingle_Target:
                UpdateSetting();
                MemoHelper.UpdateDifference(Document, Setting, false);
                Model.Document = Document;
                Model.ViewId   = Document.ActiveView.Id;
                View.Close();
                if (!VLHookHelper.DelegateKeyBoardHook(() =>
                {
                    //业务逻辑处理
                    //选择符合类型的过滤
                    UpdateModelTargetType();
                    var targetType = Model.GetFilter();
                    var obj = UIDocument.Selection.PickObject(ObjectType.Element, targetType, "请选择标注点");
                    if (obj != null)
                    {
                        Model.TargetId = obj.ElementId;
                        Model.TargetType = Model.IsPunch(Document.GetElement(obj.ElementId)) ? PBPATargetType.Punch : PBPATargetType.BranchPipe;
                        ViewType = (int)PBPAViewType.PickSingle_End;
                        Model.BodyStartPoint = obj.GlobalPoint;
                    }
                }))
                {
                    ViewType = (int)PBPAViewType.Idle;
                }
                //获取族内参数信息
                if (!GetFamilySymbolInfo(Model.TargetId))
                {
                    ShowMessage("加载族信息失败");
                    ViewType = (int)PBPAViewType.Idle;
                    Execute();
                    return;
                }
                Model.CurrentFontWidthSize = PBPAContext.FontManagement.CurrentFontWidthSize;
                Execute();
                break;

            case PBPAViewType.PickSingle_End:
                //业务逻辑处理
                if (!VLHookHelper.DelegateKeyBoardHook(() =>
                {
                    //var locationCurve = (target.Location as LocationCurve).Curve as Line;
                    //XYZ vVector, pVector;
                    //VLLocationHelper.GetVectors(locationCurve, CoordinateType.XY, out vVector, out pVector);

                    #region 平面+立面支持
                    //CoordinateType coordinateType;
                    //coordinateType = VLLocationHelper.GetCoordinateType(Document);
                    //Model.CoordinateType = coordinateType;
                    //var hVector = coordinateType.GetParallelVector();
                    //hVector = VLLocationHelper.GetVectorByQuadrant(hVector, QuadrantType.OneAndFour, coordinateType);
                    //var vVector = VLLocationHelper.GetVerticalVector(hVector);
                    //vVector = VLLocationHelper.GetVectorByQuadrant(vVector, QuadrantType.OneAndFour, coordinateType);
                    #endregion

                    VLCoordinateType coordinateType = VLCoordinateType.XY;
                    Model.UpdateVector(coordinateType);
                    var target = Document.GetElement(Model.TargetId);
                    Model.UpdateLineWidth(target);
                    var startPoint = Model.BodyStartPoint.ToWindowsPoint(coordinateType);
                    var offSet = (Model.LineWidth * Model.ParallelVector).ToWindowsPoint();
                    //var endPoint = (Model.BodyStartPoint + Model.LineWidth * 1.02 * Model.ParallelVector).ToWindowsPoint(coordinateType);
                    var pEnd = new VLPointPicker().PickPointWithPreview(UIApplication, coordinateType, (view) =>
                    {
                        var mousePosition = System.Windows.Forms.Control.MousePosition;
                        var midDrawP = new System.Windows.Point(mousePosition.X - view.Left, mousePosition.Y - view.Top); //中间选择点
                        var midPoint = view.ConvertToRevitPointFromDrawPoint(midDrawP);
                        var startDrawP = view.ConvertToDrawPointFromRevitPoint(startPoint);                               //起点
                        var M_S = midPoint - Model.BodyStartPoint;
                        if (Model.AnnotationType == PBPAAnnotationType.OneLine || Model.ParallelVector.CrossProductByCoordinateType(M_S, VLCoordinateType.XY) > 0)
                        {
                            var endPoint = startPoint.Plus(offSet);
                            var endP = view.ConvertToDrawPointFromRevitPoint(endPoint);    //终点
                            if (Math.Abs(startDrawP.X - midDrawP.X) < 2 && Math.Abs(startDrawP.Y - midDrawP.Y) < 2)
                            {
                                return;
                            }
                            var mid_s = midDrawP - startDrawP;
                            mid_s.Normalize();
                            var midSDrawP = midDrawP - mid_s * view.co_s;
                            var height = midDrawP - startDrawP;
                            var endDrawP = endP + height;
                            var mid_e = midDrawP - endDrawP;
                            mid_e.Normalize();
                            var midEDrawP = midDrawP - mid_e * view.co_e;
                            if (double.IsNaN(midEDrawP.X))
                            {
                                return;
                            }

                            var canvas = view.canvas;
                            canvas.Children.RemoveRange(0, canvas.Children.Count);
                            var line = new System.Windows.Shapes.Line()
                            {
                                X1 = startDrawP.X, Y1 = startDrawP.Y, X2 = midSDrawP.X, Y2 = midSDrawP.Y, Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(136, 136, 136)), StrokeThickness = 1
                            };
                            var line2 = new System.Windows.Shapes.Line()
                            {
                                X1 = midEDrawP.X, Y1 = midEDrawP.Y, X2 = endDrawP.X, Y2 = endDrawP.Y, Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(136, 136, 136)), StrokeThickness = 1
                            };
                            System.Windows.Media.RenderOptions.SetBitmapScalingMode(line, System.Windows.Media.BitmapScalingMode.LowQuality);
                            System.Windows.Media.RenderOptions.SetBitmapScalingMode(line2, System.Windows.Media.BitmapScalingMode.LowQuality);
                            canvas.Children.Add(line);
                            canvas.Children.Add(line2);
                            Model.IsReversed = false;
                        }
                        else
                        {
                            var endPoint = startPoint.Minus(offSet);
                            var endP = view.ConvertToDrawPointFromRevitPoint(endPoint);    //终点
                            if (Math.Abs(startDrawP.X - midDrawP.X) < 2 && Math.Abs(startDrawP.Y - midDrawP.Y) < 2)
                            {
                                return;
                            }
                            var mid_s = midDrawP - startDrawP;
                            mid_s.Normalize();
                            var midSDrawP = midDrawP - mid_s * view.co_s;
                            var height = midDrawP - startDrawP;
                            var endDrawP = endP + height;
                            var mid_e = midDrawP - endDrawP;
                            mid_e.Normalize();
                            var midEDrawP = midDrawP - mid_e * view.co_e;
                            if (double.IsNaN(midEDrawP.X))
                            {
                                return;
                            }

                            var canvas = view.canvas;
                            canvas.Children.RemoveRange(0, canvas.Children.Count);
                            var line = new System.Windows.Shapes.Line()
                            {
                                X1 = startDrawP.X, Y1 = startDrawP.Y, X2 = midSDrawP.X, Y2 = midSDrawP.Y, Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(136, 136, 136)), StrokeThickness = 1
                            };
                            var line2 = new System.Windows.Shapes.Line()
                            {
                                X1 = midEDrawP.X, Y1 = midEDrawP.Y, X2 = endDrawP.X, Y2 = endDrawP.Y, Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(136, 136, 136)), StrokeThickness = 1
                            };
                            System.Windows.Media.RenderOptions.SetBitmapScalingMode(line, System.Windows.Media.BitmapScalingMode.LowQuality);
                            System.Windows.Media.RenderOptions.SetBitmapScalingMode(line2, System.Windows.Media.BitmapScalingMode.LowQuality);
                            canvas.Children.Add(line);
                            canvas.Children.Add(line2);
                            Model.IsReversed = true;
                        }
                    });
                    if (pEnd == null)
                    {
                        ViewType = (int)PBPAViewType.Idle;
                    }
                    else
                    {
                        Model.BodyEndPoint = pEnd.ToSame(Model.BodyStartPoint, coordinateType);
                        ViewType = (int)PBPAViewType.GenerateSingle;
                    }
                }))
                {
                    ViewType = (int)PBPAViewType.Idle;
                }
                Execute();
                break;

            case PBPAViewType.GenerateSingle:
                //生成处理
                if (VLTransactionHelper.DelegateTransaction(Document, "GenerateSingle", (Func <bool>)(() =>
                {
                    #region 生成处理
                    collection = PBPAContext.GetCollection(Document);
                    var existedModels = collection.Data.Where(c => Model.TargetId == c.TargetId).ToList();    //避免重复生成
                    if (existedModels != null)
                    {
                        for (int i = existedModels.Count() - 1; i >= 0; i--)
                        {
                            existedModels[i].Document = Document;
                            collection.Data.Remove(existedModels[i]);
                            existedModels[i].Clear();
                        }
                    }
                    if (!PBPAContext.Creator.Generate(Model))
                    {
                        return(false);
                    }
                    collection.Data.Add(Model);
                    collection.Save(Document);
                    #endregion

                    #region 共享参数设置
                    var element = Document.GetElement(Model.TargetId);
                    element.GetParameters(PBPAContext.SharedParameterPL).FirstOrDefault().Set(Model.GetFull_L(element));
                    #endregion
                    return(true);
                })))
                {
                    ViewType = (int)PBPAViewType.PickSingle_Target;
                }
                else
                {
                    ViewType = (int)PBPAViewType.Idle;
                }
                Execute();
                break;

            case PBPAViewType.GenerateAll:
            default:
                throw new NotImplementedException("功能未实现");
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 根据象限获取向量
        /// </summary>
        /// <param name="vector"></param>
        /// <param name="quadrantType"></param>
        /// <returns></returns>
        public static XYZ GetVectorByQuadrant(this XYZ vector, QuadrantType quadrantType, VLCoordinateType coordinateType = VLCoordinateType.XY)
        {
            var result = vector;

            switch (quadrantType)
            {
            case QuadrantType.OneAndFour:    //竖直时取第一象限
                switch (coordinateType)
                {
                case VLCoordinateType.XY:
                    if ((!vector.X.IsMiniValue() && vector.X < 0) || (vector.X.IsMiniValue() && (result.Y + 1).IsMiniValue()))
                    {
                        result = new XYZ(-vector.X, -vector.Y, vector.Z);
                    }
                    return(result);

                case VLCoordinateType.YZ:
                case VLCoordinateType.XZ:
                    throw new NotImplementedException("未支持");

                default:
                    return(null);
                }

            case QuadrantType.OneAndTwo:    //水平时取第一象限
                switch (coordinateType)
                {
                case VLCoordinateType.XY:
                    if ((!vector.Y.IsMiniValue() && vector.Y < 0) || (vector.Y.IsMiniValue() && (result.X + 1).IsMiniValue()))
                    {
                        result = new XYZ(-vector.X, -vector.Y, vector.Z);
                    }
                    return(result);

                case VLCoordinateType.YZ:
                case VLCoordinateType.XZ:
                    throw new NotImplementedException("未支持");

                default:
                    return(null);
                }

            case QuadrantType.One:
            case QuadrantType.Two:
            case QuadrantType.Three:
            case QuadrantType.Four:
            default:
                throw new NotImplementedException("");
            }
        }