Exemplo n.º 1
0
        public override void Execute()
        {
            var viewType = (CMViewType)Enum.Parse(typeof(CMViewType), ViewType.ToString());

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

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

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

            case CMViewType.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)CMViewType.PickSinglePipe_Location;
                    }
                }))
                {
                    ViewType = (int)CMViewType.Idle;
                }
                Execute();
                break;

            case CMViewType.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 = CMViewType.Idle;
                    //else
                    //    ViewType = CMViewType.GenerateSinglePipe;
                }))
                {
                    ViewType = (int)CMViewType.Idle;
                }
                Execute();
                break;

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

            default:
                throw new NotImplementedException("功能未实现");
            }
        }
Exemplo n.º 2
0
 public void Load(Document doc)
 {
     Data.Clear();
     Data.AddRange(CMContext.GetCollection(doc).Data);
 }