Пример #1
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;
        }
Пример #2
0
        private static void SetCurveFromLine(CSAModel model, LocationCurve locationCurve)
        {
            XYZ parallelVector = null;
            XYZ verticalVector = null;

            parallelVector = (locationCurve.Curve as Line).Direction;
            verticalVector = new XYZ(parallelVector.Y, -parallelVector.X, 0);
            parallelVector = VLLocationHelper.GetVectorByQuadrant(parallelVector, QuadrantType.OneAndFour);
            verticalVector = VLLocationHelper.GetVectorByQuadrant(verticalVector, QuadrantType.OneAndTwo);
            if ((verticalVector.X - 1).IsMiniValue())
            {
                verticalVector = verticalVector.RevertByCoordinateType(VLCoordinateType.XY);
            }
            model.VerticalVector = verticalVector;
            model.ParallelVector = parallelVector;
        }
Пример #3
0
        public void UpdateVectors(Line locationCurve)
        {
            XYZ parallelVector = null;
            XYZ verticalVector = null;

            parallelVector = locationCurve.Direction;
            verticalVector = new XYZ(parallelVector.Y, -parallelVector.X, 0);
            parallelVector = VLLocationHelper.GetVectorByQuadrant(parallelVector, QuadrantType.OneAndFour);
            verticalVector = VLLocationHelper.GetVectorByQuadrant(verticalVector, QuadrantType.OneAndTwo);
            if ((verticalVector.X - 1).IsMiniValue())
            {
                verticalVector = verticalVector.RevertByCoordinateType(VLCoordinateType.XY);
            }
            VerticalVector = verticalVector;
            ParallelVector = parallelVector;
        }
Пример #4
0
        public void Execute(UpdaterData updateData)
        {
            var document   = updateData.GetDocument();
            var edits      = updateData.GetModifiedElementIds();
            var collection = PipeAnnotationContext.GetCollection(document);

            if (PipeAnnotationContext.IsEditing == true)
            {
                PipeAnnotationContext.IsEditing = false;
                return;
            }
            List <int> movedEntities = new List <int>();

            foreach (var editId in edits)
            {
                var element = document.GetElement(editId);
                PipeAnnotationEntity entity = null;
                var lineMoved = collection.FirstOrDefault(c => c.LineId == editId.IntegerValue);
                if (lineMoved != null)
                {
                    TaskDialog.Show("警告", "线移动了");
                    entity = lineMoved;
                    var            creater    = PipeAnnotationContext.Creater;
                    FamilyInstance line       = document.GetElement(new ElementId(entity.LineId)) as FamilyInstance;
                    XYZ            skewVector = (line.Location as LocationPoint).Point - entity.StartPoint;
                    creater.RegenerateMultipleTagSymbolByEntity(document, entity, skewVector);
                    movedEntities.Add(entity.LineId);
                    PipeAnnotationContext.IsEditing = true;
                }
                var pipeMoved = collection.FirstOrDefault(c => c.PipeIds.Contains(editId.IntegerValue));
                if (pipeMoved != null)
                {
                    TaskDialog.Show("警告", "管道移动了");
                    entity = pipeMoved;
                    if (movedEntities.Contains(entity.LineId))
                    {
                        continue;
                    }
                    var creater        = PipeAnnotationContext.Creater;
                    XYZ parallelVector = null;
                    XYZ verticalVector = null;
                    parallelVector = ((document.GetElement(new ElementId(entity.PipeIds.First())).Location as LocationCurve).Curve as Line).Direction;
                    verticalVector = new XYZ(parallelVector.Y, -parallelVector.X, 0);
                    parallelVector = VLLocationHelper.GetVectorByQuadrant(parallelVector, QuadrantType.OneAndFour, VLCoordinateType.XY);
                    verticalVector = VLLocationHelper.GetVectorByQuadrant(verticalVector, QuadrantType.OneAndTwo, VLCoordinateType.XY);
                    int indexOfPipe = entity.PipeIds.IndexOf(editId.IntegerValue);
                    var startPoint  = entity.StartPoint;
                    var movedPipe   = document.GetElement(new ElementId(editId.IntegerValue)) as Pipe;
                    var pipeLine    = (movedPipe.Location as LocationCurve).Curve;
                    pipeLine.MakeUnbound();
                    var    projectionPoint = pipeLine.Project(startPoint).XYZPoint;
                    var    line            = document.GetElement(new ElementId(entity.LineId)) as FamilyInstance;
                    double preHeight       = 0;
                    if (indexOfPipe > 0)
                    {
                        preHeight   = line.GetParameters(string.Format("节点{0}距离", indexOfPipe + 1)).First().AsDouble();
                        startPoint -= preHeight * verticalVector;
                    }
                    creater.RegenerateMultipleTagSymbolByEntity(document, entity, startPoint - projectionPoint);
                    movedEntities.Add(entity.LineId);
                    PipeAnnotationContext.IsEditing = true;
                }
                var tagMoved = collection.FirstOrDefault(c => c.TagIds.Contains(editId.IntegerValue));
                if (tagMoved != null)
                {
                    TaskDialog.Show("警告", "标注移动了");
                    entity = tagMoved;
                    if (movedEntities.Contains(entity.LineId))
                    {
                        continue;
                    }
                    var creater        = PipeAnnotationContext.Creater;
                    var index          = entity.TagIds.IndexOf(editId.IntegerValue);
                    var subTag         = document.GetElement(new ElementId(editId.IntegerValue)) as IndependentTag;
                    var text           = subTag.TagText;
                    var textLength     = System.Windows.Forms.TextRenderer.MeasureText(text, AnnotationConstaints.Font).Width;
                    var actualLength   = textLength / (creater.TextSize * creater.WidthScale);
                    XYZ parallelVector = null;
                    XYZ verticalVector = null;
                    parallelVector = ((document.GetElement(new ElementId(entity.PipeIds.First())).Location as LocationCurve).Curve as Line).Direction;
                    verticalVector = new XYZ(parallelVector.Y, -parallelVector.X, 0);
                    parallelVector = VLLocationHelper.GetVectorByQuadrant(parallelVector, QuadrantType.OneAndFour, VLCoordinateType.XY);
                    verticalVector = VLLocationHelper.GetVectorByQuadrant(verticalVector, QuadrantType.OneAndTwo, VLCoordinateType.XY);
                    var    height     = Convert.ToDouble(document.GetElement(new ElementId(entity.LineId)).GetParameters(TagProperty.线高度1.ToString()).First().AsValueString()) + (entity.PipeIds.Count() - 1) * AnnotationConstaints.TextHeight;
                    double skewLength = 0;
                    XYZ    startPoint = null;
                    switch (entity.LocationType)
                    {
                    case MultiPipeTagLocation.OnLineEdge:
                        skewLength = AnnotationConstaints.SkewLengthForOffLine;
                        startPoint = subTag.TagHeadPosition - skewLength * parallelVector - actualLength / 25.4 * parallelVector
                                     - UnitHelper.ConvertToInch(height - index * AnnotationConstaints.TextHeight, AnnotationConstaints.UnitType) * verticalVector;
                        break;

                    case MultiPipeTagLocation.OnLine:
                        skewLength = AnnotationConstaints.SkewLengthForOffLine;
                        startPoint = subTag.TagHeadPosition - skewLength * parallelVector - actualLength / 25.4 * parallelVector
                                     - UnitHelper.ConvertToInch(height - index * AnnotationConstaints.TextHeight + 0.5 * AnnotationConstaints.TextHeight, AnnotationConstaints.UnitType) * verticalVector;
                        break;
                    }
                    XYZ skewVector = startPoint - entity.StartPoint;
                    creater.RegenerateMultipleTagSymbolByEntity(document, entity, skewVector);
                    movedEntities.Add(entity.LineId);
                    PipeAnnotationContext.IsEditing = true;
                }
            }
            PipeAnnotationContext.SaveCollection(document);
        }
Пример #5
0
        /// <summary>
        /// 根据线的移动,重定位内容
        /// </summary>
        public bool RegenerateMultipleTagSymbolByEntity(Document document, PipeAnnotationEntity entity, XYZ skewVector)
        {
            Document = document;
            XYZ            startPoint = null;
            View           view       = Document.ActiveView;
            FamilyInstance line       = document.GetElement(new ElementId(entity.LineId)) as FamilyInstance;
            List <Pipe>    pipes      = new List <Pipe>();

            foreach (var pipeId in entity.PipeIds)
            {
                pipes.Add(Document.GetElement(new ElementId(pipeId)) as Pipe);
            }
            List <IndependentTag> tags = new List <IndependentTag>();

            foreach (var tagId in entity.TagIds)
            {
                tags.Add(Document.GetElement(new ElementId(tagId)) as IndependentTag);
            }
            ////偏移量
            //XYZ skew = (line.Location as LocationPoint).Point - entity.StartPoint;
            //管道 获取
            //平行,垂直 向量
            XYZ parallelVector = null;
            XYZ verticalVector = null;

            parallelVector = ((pipes.First().Location as LocationCurve).Curve as Line).Direction;
            verticalVector = new XYZ(parallelVector.Y, -parallelVector.X, 0);
            parallelVector = VLLocationHelper.GetVectorByQuadrant(parallelVector, QuadrantType.OneAndFour, VLCoordinateType.XY);
            verticalVector = VLLocationHelper.GetVectorByQuadrant(verticalVector, QuadrantType.OneAndTwo, VLCoordinateType.XY);
            //原始线高度
            var orientLineHeight = line.GetParameters(TagProperty.线高度1.ToString()).First().AsDouble();
            ////原始对象清理
            //Document.Delete(line.Id);
            //foreach (var tagId in entity.TagIds)
            //    Document.Delete(new ElementId(tagId));
            ////平行检测
            //if (!CheckParallel(pipes, verticalVector))
            //{
            //    return AnnotationBuildResult.NotParallel;
            //}
            //节点计算
            //TODO entity.StartPoint 不以记录为准 以其他点位的信息来计算
            List <XYZ> nodePoints = GetNodePoints(pipes, entity.StartPoint + skewVector).OrderByDescending(c => c.Y).ToList();

            //if (nodePoints.Count() == 0)
            //{
            //    return AnnotationBuildResult.NoOverlap;
            //}
            //起始点
            startPoint = nodePoints.First();
            //线 创建
            if (!MultipleTagSymbol.IsActive)
            {
                MultipleTagSymbol.Activate();
            }
            //line = Document.Create.NewFamilyInstance(startPoint, MultipleTagSymbol, view);
            (line.Location as LocationPoint).Point = startPoint;
            ////线 旋转处理
            //if (verticalVector.Y != 1)//TODO 判断是否相同方向
            //{
            //    LocationPoint locationPoint = line.Location as LocationPoint;
            //    if (locationPoint != null)
            //        locationPoint.RotateByXY(startPoint, verticalVector);
            //}
            //偏移计算
            var verticalSkew = VLLocationHelper.GetLengthBySide(skewVector, verticalVector);
            var parallelSkew = VLLocationHelper.GetLengthBySide(skewVector, parallelVector);

            //线参数
            UpdateLineParameters(nodePoints, line);
            //标注 创建
            var nodesHeight = UnitHelper.ConvertToInch((nodePoints.Count() - 1) * AnnotationConstaints.TextHeight, AnnotationConstaints.UnitType);
            var lineHeight  = orientLineHeight + verticalSkew > nodesHeight ? orientLineHeight + verticalSkew : nodesHeight;
            var tagHeight   = lineHeight + nodesHeight;

            line.GetParameters(TagProperty.线高度1.ToString()).First().Set(lineHeight);
            switch (entity.LocationType)
            {
            case MultiPipeTagLocation.OnLineEdge:
                //添加对应的单管直径标注
                line.GetParameters(TagProperty.线宽度.ToString()).First().Set(UnitHelper.ConvertToInch(200, AnnotationConstaints.UnitType));
                var skewLength = AnnotationConstaints.SkewLengthForOffLine;
                for (int i = 0; i < pipes.Count(); i++)
                {
                    //var subTag = Document.Create.NewTag(view, pipes[i], false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, startPoint);
                    var subTag       = tags[i];
                    var text         = subTag.TagText;
                    var textLength   = System.Windows.Forms.TextRenderer.MeasureText(text, AnnotationConstaints.Font).Width;
                    var actualLength = textLength / (TextSize * WidthScale);
                    subTag.TagHeadPosition = startPoint + skewLength * parallelVector + actualLength / 25.4 * parallelVector
                                             + (tagHeight + UnitHelper.ConvertToInch(-i * AnnotationConstaints.TextHeight, AnnotationConstaints.UnitType)) * verticalVector;
                    tags.Add(subTag);
                }
                break;

            case MultiPipeTagLocation.OnLine:
                //添加对应的单管直径标注
                line.GetParameters(TagProperty.线宽度.ToString()).First().Set(UnitHelper.ConvertToInch(800, AnnotationConstaints.UnitType));
                skewLength = AnnotationConstaints.SkewLengthForOnLine;
                for (int i = 0; i < pipes.Count(); i++)
                {
                    //var subTag = Document.Create.NewTag(view, pipes[i], false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, startPoint);
                    var subTag       = tags[i];
                    var text         = subTag.TagText;
                    var textLength   = System.Windows.Forms.TextRenderer.MeasureText(text, AnnotationConstaints.Font).Width;
                    var actualLength = textLength / (TextSize * WidthScale);
                    subTag.TagHeadPosition = startPoint + skewLength * parallelVector + actualLength / 25.4 * parallelVector
                                             + (tagHeight + UnitHelper.ConvertToInch(-i * AnnotationConstaints.TextHeight + 0.5 * AnnotationConstaints.TextHeight, AnnotationConstaints.UnitType)) * verticalVector;
                    tags.Add(subTag);
                }
                break;

            default:
                return(false);
            }
            entity.ViewId     = view.Id.IntegerValue;
            entity.StartPoint = startPoint;
            //entity.LineId = line.Id.IntegerValue;
            //entity.PipeIds.Clear();
            //entity.PipeIds.AddRange(pipes.Select(c => c.Id.IntegerValue));
            //entity.TagIds.Clear();
            //entity.TagIds.AddRange(tags.Select(c => c.Id.IntegerValue));
            return(true);
        }
Пример #6
0
        private AnnotationBuildResult GenerateMultipleTagSymbol(IEnumerable <ElementId> selectedIds, PipeAnnotationEntity entity, View view)
        {
            XYZ            startPoint = null;
            FamilyInstance line       = null;
            var            pipes      = new List <Pipe>();
            var            tags       = new List <IndependentTag>();

            //管道 获取
            foreach (var selectedId in selectedIds)
            {
                pipes.Add(Document.GetElement(selectedId) as Pipe);
            }
            //平行,垂直 向量
            XYZ parallelVector = null;
            XYZ verticalVector = null;

            parallelVector = ((pipes.First().Location as LocationCurve).Curve as Line).Direction;
            verticalVector = new XYZ(parallelVector.Y, -parallelVector.X, 0);
            parallelVector = VLLocationHelper.GetVectorByQuadrant(parallelVector, QuadrantType.OneAndFour, VLCoordinateType.XY);
            verticalVector = VLLocationHelper.GetVectorByQuadrant(verticalVector, QuadrantType.OneAndTwo, VLCoordinateType.XY);
            //平行检测
            if (!CheckParallel(pipes, verticalVector))
            {
                return(AnnotationBuildResult.NotParallel);
            }
            //节点计算
            List <XYZ> nodePoints = GetNodePoints(pipes).OrderByDescending(c => c.Y).ToList();

            if (nodePoints.Count() == 0)
            {
                return(AnnotationBuildResult.NoOverlap);
            }
            //起始点
            startPoint = nodePoints.First();
            //线 创建
            if (!MultipleTagSymbol.IsActive)
            {
                MultipleTagSymbol.Activate();
            }
            line = Document.Create.NewFamilyInstance(startPoint, MultipleTagSymbol, view);
            //线 旋转处理
            if (verticalVector.Y != 1)
            {
                LocationPoint locationPoint = line.Location as LocationPoint;
                if (locationPoint != null)
                {
                    locationPoint.RotateByXY(startPoint, verticalVector);
                }
            }
            //线 参数设置
            UpdateLineParameters(nodePoints, line);
            //标注 创建
            switch (entity.LocationType)
            {
            case MultiPipeTagLocation.OnLineEdge:
                //添加对应的单管直径标注
                line.GetParameters(TagProperty.线宽度.ToString()).First().Set(UnitHelper.ConvertToInch(200, AnnotationConstaints.UnitType));
                var height     = Convert.ToDouble(line.GetParameters(TagProperty.线高度1.ToString()).First().AsValueString()) + (nodePoints.Count() - 1) * AnnotationConstaints.TextHeight;
                var skewLength = AnnotationConstaints.SkewLengthForOffLine;
                for (int i = 0; i < pipes.Count(); i++)
                {
                    var subTag       = Document.Create.NewTag(view, pipes[i], false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, startPoint);
                    var text         = subTag.TagText;
                    var textLength   = System.Windows.Forms.TextRenderer.MeasureText(text, AnnotationConstaints.Font).Width;
                    var actualLength = textLength / (TextSize * WidthScale);
                    subTag.TagHeadPosition = startPoint + skewLength * parallelVector + actualLength / 25.4 * parallelVector
                                             + UnitHelper.ConvertToInch(height - i * AnnotationConstaints.TextHeight, AnnotationConstaints.UnitType) * verticalVector;
                    tags.Add(subTag);
                }
                break;

            case MultiPipeTagLocation.OnLine:
                //添加对应的单管直径标注
                line.GetParameters(TagProperty.线宽度.ToString()).First().Set(UnitHelper.ConvertToInch(800, AnnotationConstaints.UnitType));
                height = Convert.ToDouble(line.GetParameters(TagProperty.线高度1.ToString()).First().AsValueString()) +
                         (nodePoints.Count() - 1) * AnnotationConstaints.TextHeight;
                skewLength = AnnotationConstaints.SkewLengthForOnLine;
                for (int i = 0; i < pipes.Count(); i++)
                {
                    var subTag       = Document.Create.NewTag(view, pipes[i], false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, startPoint);
                    var text         = subTag.TagText;
                    var textLength   = System.Windows.Forms.TextRenderer.MeasureText(text, AnnotationConstaints.Font).Width;
                    var actualLength = textLength / (TextSize * WidthScale);
                    subTag.TagHeadPosition = startPoint + skewLength * parallelVector + actualLength / 25.4 * parallelVector
                                             + UnitHelper.ConvertToInch(height - i * AnnotationConstaints.TextHeight + 0.5 * AnnotationConstaints.TextHeight, AnnotationConstaints.UnitType) * verticalVector;
                    tags.Add(subTag);
                }
                break;

            default:
                return(AnnotationBuildResult.NoLocationType);
            }
            entity.ViewId = view.Id.IntegerValue;
            entity.LineId = line.Id.IntegerValue;
            foreach (var pipe in pipes)
            {
                entity.PipeIds.Add(pipe.Id.IntegerValue);
            }
            foreach (var tag in tags)
            {
                entity.TagIds.Add(tag.Id.IntegerValue);
            }
            entity.StartPoint = startPoint;
            return(AnnotationBuildResult.Success);
        }