Example #1
0
        public override void Execute()
        {
            var viewType = (MATViewType)Enum.Parse(typeof(MATViewType), ViewType.ToString());

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

            case MATViewType.Close:
                View.Close();
                //SaveSetting();
                break;

            case MATViewType.Closing:
                //SaveSetting();
                break;

            case MATViewType.PickSinglePipe_Pipe:
                View.Close();
                if (!VLHookHelper.DelegateKeyBoardHook(() =>
                {
                    //业务逻辑处理
                    //选择符合类型的过滤
                    var targetType = Model.GetFilter();
                    Model.TargetIds = new List <ElementId>()
                    {
                        UIDocument.Selection.PickObject(ObjectType.Element, targetType, "请选择管道标注点").ElementId
                    };
                    if (Model.TargetIds.Count > 0)
                    {
                        ViewType = (int)MATViewType.PickSinglePipe_Location;
                    }
                }))
                {
                    ViewType = (int)MATViewType.Idle;
                }
                Execute();
                break;

            case MATViewType.PickSinglePipe_Location:
                if (!VLHookHelper.DelegateKeyBoardHook(() =>
                {
                    ////业务逻辑处理
                    //var target = Document.GetElement(Model.TargetIds.First());
                    //var targetLocation = target.Location as LocationCurve;
                    //var p0 = targetLocation.Curve.GetEndPoint(0);
                    //var p1 = targetLocation.Curve.GetEndPoint(1);
                    //var pStart = new XYZ((p0.X + p1.X) / 2, (p0.Y + p1.Y) / 2, (p0.Z + p1.Z) / 2);
                    //var pEnd = new VLPointPicker().PickPointWithLinePreview(UIApplication, pStart);
                    //if (pEnd == null)
                    //    ViewType = MATViewType.Idle;
                    //else
                    //    ViewType = MATViewType.GenerateSinglePipe;
                }))
                {
                    ViewType = (int)MATViewType.Idle;
                }
                Execute();
                break;

            case MATViewType.GenerateSinglePipe:
                if (TransactionUtils.DelegateTransaction(Document, "GenerateSinglePipe", (Func <bool>)(() =>
                {
                    var element = Document.GetElement(Model.TargetIds.First());
                    var Collection = MATContext.GetCollection(Document);
                    //避免重复生成 由于一个对象可能在不同的视图中进行标注设置 所以还是需要重复生成的
                    var existedModels = Collection.Data.Where(c => c.TargetIds.Intersect(Model.TargetIds, new VLElementIdComparer()) != null);
                    if (existedModels != null)
                    {
                        foreach (var existedModel in existedModels)
                        {
                            Collection.Data.Remove(existedModel);
                            MATContext.Creator.Clear(Document, existedModel);
                        }
                    }
                    MATContext.Creator.Generate(Document, Model, element);
                    Collection.Data.Add(Model);
                    Collection.Save(Document);
                    return(true);
                })))
                {
                    ViewType = (int)MATViewType.PickSinglePipe_Pipe;
                }
                else
                {
                    ViewType = (int)MATViewType.Idle;
                }
                Execute();
                break;

            default:
                throw new NotImplementedException("功能未实现");
            }
        }
Example #2
0
 /// <summary>
 /// 保存
 /// </summary>
 /// <param name="doc"></param>
 public void Save(Document doc)
 {
     MATContext.SaveCollection(doc);
 }