예제 #1
0
파일: Model.cs 프로젝트: wzfxue/Revit
        public FamilySymbol GetAnnotationFamily(Document doc, ElementId targetId)
        {
            switch (AnnotationType)
            {
            case PBPAAnnotationType.TwoLine:
                return(PBPAContext.GetTwoLine_Annotation(Document));

            case PBPAAnnotationType.OneLine:
                return(PBPAContext.GetOneLine_Annotation(Document));

            default:
                throw new NotImplementedException("暂不支持该类型");
            }
        }
예제 #2
0
 private void SaveSetting()
 {
     VLTransactionHelper.DelegateTransaction(Document, "Close", (Func <bool>)(() =>
     {
         Setting.TargetType_BranchPipe = TargetType_BranchPipe;
         Setting.TargetType_Punch      = TargetType_Punch;
         Setting.AnnotationType        = AnnotationType;
         Setting.LocationType          = LocationType;
         Setting.BottomPrefix          = BottomPrefix;
         Setting.CenterPrefix          = CenterPrefix;
         Setting.TopPrefix             = TopPrefix;
         PBPAContext.SaveSetting(Document);
         return(true);
     }));
 }
예제 #3
0
        public PBPAViewModel(UIApplication app) : base(app)
        {
            Model = new PBPAModel("");
            View  = new PBPAWindow(this);

            Setting = PBPAContext.GetSetting(Document);
            MemoHelper.SettingTextMemo = Setting.CloneText();
            TargetType_BranchPipe      = Setting.TargetType_BranchPipe;
            TargetType_Punch           = Setting.TargetType_Punch;
            AnnotationType             = Setting.AnnotationType;
            LocationType = Setting.LocationType;
            CenterPrefix = Setting.CenterPrefix;
            TopPrefix    = Setting.TopPrefix;
            BottomPrefix = Setting.BottomPrefix;
        }
예제 #4
0
        public void Execute(UpdaterData updateData)
        {
            try
            {
                //if (PBPAContext.IsEditing == true)
                //{
                //    PBPAContext.IsEditing = false;
                //    return;
                //}
                var        document      = updateData.GetDocument();
                var        edits         = updateData.GetModifiedElementIds();
                var        collection    = PBPAContext.GetCollection(document);
                List <int> movedEntities = new List <int>();
                foreach (var changeId in edits)
                {
                    PBPAModel model = null;

                    #region 单管 主体 重新生成
                    var targetMoved = collection.Data.FirstOrDefault(c => c.TargetId == changeId);
                    if (targetMoved != null)
                    {
                        model = targetMoved;
                        if (movedEntities.Contains(model.TargetId.IntegerValue))
                        {
                            continue;
                        }
                        var creater        = PBPAContext.Creator;
                        var target         = document.GetElement(model.TargetId);//标注主体失效时删除
                        var targetLocation = target.Location as LocationCurve;
                        var p0             = targetLocation.Curve.GetEndPoint(0);
                        var p1             = targetLocation.Curve.GetEndPoint(1);
                        var pMiddle        = new XYZ((p0.X + p1.X) / 2, (p0.Y + p1.Y) / 2, (p0.Z + p1.Z) / 2);
                        var offset         = pMiddle - model.TargetLocation;
                        offset.ToSameZ(new XYZ(0, 0, 0));
                        model.BodyStartPoint += offset;
                        model.BodyEndPoint   += offset;
                        model.LeafEndPoint   += offset;
                        //必要族
                        model.Document     = document;
                        model.IsRegenerate = true;
                        if (!PBPAContext.Creator.Regenerate(model))
                        {
                            collection.Data.Remove(model);
                        }
                        movedEntities.Add(model.TargetId.IntegerValue);
                        //PBPAContext.IsEditing = true;//重新生成无需避免移动导致的重复触发
                        continue;
                    }
                    #endregion

                    #region 根据 标注 重新生成
                    var textMoved = collection.Data.FirstOrDefault(c => c.AnnotationId == changeId);
                    if (textMoved != null)
                    {
                        model = textMoved;
                        if (movedEntities.Contains(model.TargetId.IntegerValue))
                        {
                            continue;
                        }
                        var creater    = PBPAContext.Creator;
                        var annotation = document.GetElement(changeId) as IndependentTag;
                        var offset     = annotation.TagHeadPosition - model.AnnotationLocation;
                        offset.ToSameZ(new XYZ(0, 0, 0));
                        model.BodyEndPoint += offset;
                        model.LeafEndPoint += offset;
                        model.Document      = document;
                        model.IsRegenerate  = true;
                        if (!PBPAContext.Creator.Regenerate(model))
                        {
                            collection.Data.Remove(model);
                        }
                        movedEntities.Add(model.TargetId.IntegerValue);
                        //PBPAContext.IsEditing = true;//重新生成无需避免移动导致的重复触发
                        continue;
                    }
                    #endregion
                }
                PBPAContext.SaveCollection(document);
            }
            catch (Exception ex)
            {
                VLLogHelper.Error(ex);
            }
        }
예제 #5
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("功能未实现");
            }
        }
예제 #6
0
        public void UpdateDifference(Document doc, PBPASetting origin, bool needUserConfirm = true)
        {
            bool IsPunchUpdate      = origin.TargetType_Punch;
            bool IsBranchPipeUpdate = origin.TargetType_BranchPipe;

            CheckDifference(origin);
            if (!IsSame)
            {
                if (!needUserConfirm || VLViewModel.ShowQuestion("前缀发生变化,是否更新所对应的标签") == DialogResult.OK)
                {
                    SettingTextMemo = origin.CloneText();
                    VLTransactionHelper.DelegateTransaction(doc, "RegenerateAllFor_L", (Func <bool>)(() =>
                    {
                        var collection = PBPAContext.GetCollection(doc);
                        if (!IsSame_CenterPrefix)
                        {
                            if (IsPunchUpdate)
                            {
                                var targetType   = PBPATargetType.Punch;
                                var locationType = PBPALocationType.Center;
                                RegenerateAllFor_Prefix(doc, collection, targetType, locationType);
                            }
                            if (IsBranchPipeUpdate)
                            {
                                var targetType   = PBPATargetType.BranchPipe;
                                var locationType = PBPALocationType.Center;
                                RegenerateAllFor_Prefix(doc, collection, targetType, locationType);
                            }
                        }
                        if (!IsSame_TopPrefix)
                        {
                            if (IsPunchUpdate)
                            {
                                var targetType   = PBPATargetType.Punch;
                                var locationType = PBPALocationType.Top;
                                RegenerateAllFor_Prefix(doc, collection, targetType, locationType);
                            }
                            if (IsBranchPipeUpdate)
                            {
                                var targetType   = PBPATargetType.BranchPipe;
                                var locationType = PBPALocationType.Top;
                                RegenerateAllFor_Prefix(doc, collection, targetType, locationType);
                            }
                        }
                        if (!IsSame_BottomPrefix)
                        {
                            if (IsPunchUpdate)
                            {
                                var targetType   = PBPATargetType.Punch;
                                var locationType = PBPALocationType.Bottom;
                                RegenerateAllFor_Prefix(doc, collection, targetType, locationType);
                            }
                            if (IsBranchPipeUpdate)
                            {
                                var targetType   = PBPATargetType.BranchPipe;
                                var locationType = PBPALocationType.Bottom;
                                RegenerateAllFor_Prefix(doc, collection, targetType, locationType);
                            }
                        }
                        collection.Save(doc);
                        return(true);
                    }));
                }
            }
            IsSame = true;
        }
예제 #7
0
 /// <summary>
 /// 保存
 /// </summary>
 /// <param name="doc"></param>
 public void Save(Document doc)
 {
     PBPAContext.SaveCollection(doc);
 }