示例#1
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);
        }
示例#2
0
文件: CSAModel.cs 项目: wzfxue/Revit
        //public void CalculateLocations(Element element, XYZ offset)
        //{
        //    var scale = 1 / VLConstraints.OrientFontSizeScale * VLConstraints.CurrentFontSizeScale;
        //    var width = CSALocationType.GetLineWidth() * scale;
        //    var height = 400 * scale;
        //    var widthFoot = UnitHelper.ConvertToFoot(width, VLUnitType.millimeter);
        //    var heightFoot = UnitHelper.ConvertToFoot(height, VLUnitType.millimeter);
        //    var verticalFix = UnitHelper.ConvertToFoot(100, VLUnitType.millimeter) * scale;
        //    var locationCurve = TargetType.GetLine(element);
        //    UpdateVectors(locationCurve);
        //    //线起始点 (中点)
        //    LineStartLocation = (locationCurve.GetEndPoint(0) + locationCurve.GetEndPoint(1)) / 2;
        //    //文本位置 start:(附着元素中点+线基本高度+文本高度*(文本个数-1))  end: start+宽
        //    //高度,宽度 取决于文本
        //    ParallelLinesLocations = new List<TextLocation>();
        //    TextLocations = new List<XYZ>();
        //    for (int i = Texts.Count() - 1; i >= 0; i--)
        //    {
        //        var start = LineStartLocation + (heightFoot + i * VLConstraints.CurrentFontHeight) * VerticalVector;
        //        var end = start + widthFoot * ParallelVector;
        //        ParallelLinesLocations.Add(new TextLocation(start, end));
        //        TextLocations.Add(CSALocationType.GetTextLocation(verticalFix, VerticalVector, start, end));
        //    }
        //    //线终点 (最高的文本位置)
        //    LineEndLocation = ParallelLinesLocations[0].Start;
        //}

        //public void CalculateLocations(Element element)
        //{
        //    CalculateLocations(element, new XYZ(0, 0, 0));
        //}
        #endregion


        #region 线族的计算方案
        public void CalculateLocations(Element element, FamilyInstance line, XYZ offset)
        {
            //数据准备
            var locationCurve = TargetType.GetLine(element);
            var miniHeight    = CurrentFontHeight * 2;

            UpdateVectors((locationCurve as Line));
            //ParallelVector = VLLocationHelper.GetVectorByQuadrant((locationCurve as Line).Direction, QuadrantType.OneAndFour);
            //VerticalVector = VLLocationHelper.GetVectorByQuadrant(new XYZ(ParallelVector.Y, -ParallelVector.X, 0), QuadrantType.OneAndTwo);
            //计算线的定位位置
            bool isRegenerate = offset != null;

            if (!isRegenerate)
            {
                LineLocation = (locationCurve.GetEndPoint(0) + locationCurve.GetEndPoint(1)) / 2;
                offset       = new XYZ(0, 0, 0);
                LineHeight   = UnitHelper.ConvertToFoot(1000, VLUnitType.millimeter);
            }
            else
            {
                LineLocation = locationCurve.Project(LineLocation + offset).XYZPoint;
                LineHeight   = line.GetParameters(TagProperty.线高度1.ToString()).First().AsDouble() + VLLocationHelper.GetLengthBySide(offset, VerticalVector);
                LineHeight   = LineHeight > miniHeight ? LineHeight : miniHeight;//确保最短长度有一个文字高度
            }
            //高度,宽度 取决于文本
            FontScale = 1 / VLConstraintsForCSA.OrientFontSizeScale * CurrentFontSizeScale;
            //LineWidth = UnitHelper.ConvertToFoot(CSALocationType.GetLineWidth() * FontScale, VLUnitType.millimeter);
            var verticalFix   = CurrentFontHeight * VLConstraintsForCSA.TextSpace;;  //偏移修正 为了显示更好 方便更改
            var horizontalFix = UnitHelper.ConvertToFoot(50, VLUnitType.millimeter); //偏移修正 为了显示更好 方便更改

            LineSpace     = CurrentFontHeight * (1 + VLConstraintsForCSA.TextSpace);
            TextLocations = new List <XYZ>();
            for (int i = Texts.Count() - 1; i >= 0; i--)
            {
                var start = LineLocation + (LineHeight + i * LineSpace) * VerticalVector;
                var end   = start + LineWidth * ParallelVector;
                TextLocations.Add(CSALocationType.GetTextLocation(CurrentFontHeight, verticalFix, VerticalVector, horizontalFix, ParallelVector, start, end));
            }
        }
示例#3
0
文件: PAAModel.cs 项目: wzfxue/Revit
        public bool CalculateLocations()
        {
            switch (ModelType)
            {
            case PAAModelType.SinglePipe:
                #region single
                var target        = Document.GetElement(TargetId);
                var locationCurve = TargetType.GetLine(target);
                UpdateVectors(locationCurve);
                //干线起始点
                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 (TextType == PAATextType.Option2)
                {
                    if (!IsRegenerate)
                    {
                        LeafEndPoint = BodyEndPoint + LineWidth * ParallelVector;
                    }
                    //文本位置 start:(附着元素中点+线基本高度+文本高度*(文本个数-1))  end: start+宽
                    //高度,宽度 取决于文本
                    AnnotationLocation = TextType.GetTextLocation(CurrentFontHeight, VerticalVector, BodyEndPoint, LeafEndPoint);
                }
                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 = TextType.GetTextLocation(CurrentFontHeight, VerticalVector, LeafEndPoint, BodyEndPoint);
                    }
                    else
                    {
                        AnnotationLocation = TextType.GetTextLocation(CurrentFontHeight, VerticalVector, BodyEndPoint, LeafEndPoint);
                    }
                }
                return(true);

                #endregion
            case PAAModelType.MultiplePipe:
                #region multiple
                PipeAndNodePoints = new List <ElementAndNodePoint>();
                if (IsRegenerate)
                {
                    for (int i = 0; i < TargetIds.Count; i++)
                    {
                        target = Document.GetElement(TargetIds[i]);
                        var annotationId = AnnotationIds[i];
                        var annotation   = Document.GetElement(annotationId);
                        if (annotation == null)
                        {
                            return(false);
                        }
                        PipeAndNodePoints.Add(new ElementAndNodePoint(target, annotation as IndependentTag));
                    }
                }
                else
                {
                    foreach (var selectedId in TargetIds)
                    {
                        PipeAndNodePoints.Add(new ElementAndNodePoint(Document.GetElement(selectedId)));
                    }
                }
                //平行,垂直 向量
                UpdateVectors(PipeAndNodePoints.First().Line);
                //重叠区间
                XYZ        rightOfLefts;
                XYZ        leftOfRights;
                XYZ        startPoint = TargetLocation;
                List <XYZ> lefts      = new List <XYZ>();
                List <XYZ> rights     = new List <XYZ>();
                if (!IsRegenerate)
                {
                    bool usingX = GetLeftsAndRights(PipeAndNodePoints, lefts, rights);
                    rightOfLefts = usingX ? lefts.First(c => c.X == lefts.Max(p => p.X)) : lefts.First(c => c.Y == lefts.Max(p => p.Y));
                    leftOfRights = usingX ? rights.First(c => c.X == rights.Min(p => p.X)) : rights.First(c => c.Y == rights.Min(p => p.Y));
                    if ((usingX && rightOfLefts.X > leftOfRights.X) || (!usingX && rightOfLefts.Y > leftOfRights.Y))
                    {
                        //TODO 提示无重叠区间
                        return(false);
                    }
                }
                else
                {
                    rightOfLefts = leftOfRights = null;
                }
                //节点计算
                XYZ firstNode;
                if (!IsRegenerate)
                {
                    firstNode = (rightOfLefts + leftOfRights) / 2;
                }
                else
                {
                    locationCurve = PipeAndNodePoints[0].Line;
                    firstNode     = locationCurve.Project(startPoint).XYZPoint;
                }
                PipeAndNodePoints[0].NodePoint = firstNode;
                //节点位置
                for (int i = 1; i < PipeAndNodePoints.Count(); i++)
                {
                    PipeAndNodePoints[i].NodePoint = PipeAndNodePoints[i].Line.Project(PipeAndNodePoints[0].NodePoint).XYZPoint;
                }
                //排序
                if (PipeAndNodePoints.Count() > 1)
                {
                    if (Math.Abs(PipeAndNodePoints[0].NodePoint.Y - PipeAndNodePoints[1].NodePoint.Y) < 0.01)
                    {
                        PipeAndNodePoints = PipeAndNodePoints.OrderBy(c => c.NodePoint.X).ToList();
                    }
                    else
                    {
                        PipeAndNodePoints = PipeAndNodePoints.OrderByDescending(c => c.NodePoint.Y).ToList();
                    }
                }
                TargetIds = PipeAndNodePoints.Select(c => c.Target.Id).ToList();
                //标注定位计算
                XYZ    offset       = GetOffSet();
                bool   overMoved    = false;//位移是否超过的最低限制
                double parallelSkew = offset.GetLengthBySide(ParallelVector);
                foreach (var PipeAndNodePoint in PipeAndNodePoints)
                {
                    PipeAndNodePoint.NodePoint += parallelSkew * ParallelVector;
                }
                TargetLocation = PipeAndNodePoints.First().NodePoint;
                if (IsRegenerate)    // && regenerateType != RegenerateType.RegenerateByPipe)
                {
                    //原始线高度+偏移数据
                    var line             = Document.GetElement(LineId);
                    var orientLineHeight = IsRegenerate ? line.GetParameters(TagProperty.线高度1.ToString()).First().AsDouble() : 0;
                    var verticalSkew     = RegenerateType == RegenerateType.ByMultipleTarget ? 0 : VLLocationHelper.GetLengthBySide(offset, VerticalVector);
                    //if (Math.Abs(VerticalVector.X) > 1 - UnitHelper.MiniValueForXYZ)
                    //    verticalSkew = -verticalSkew;
                    var nodesHeight = UnitHelper.ConvertToFoot((PipeAndNodePoints.Count() - 1) * CurrentFontHeight, VLUnitType.millimeter);
                    overMoved = orientLineHeight + verticalSkew < nodesHeight;
                    var lineHeight = orientLineHeight + verticalSkew;
                    if (overMoved)
                    {
                        lineHeight   = nodesHeight;
                        verticalSkew = nodesHeight - orientLineHeight;
                    }
                    LineHeight = lineHeight;
                }
                else
                {
                    LineHeight = CurrentFontHeight;
                }
                LineSpace = CurrentFontHeight;
                UpdateLineWidth(Document.GetElement(TargetIds.First()));
                //string text = GetFullTextForLine(Document.GetElement(TargetIds.First()));
                //var textWidth = TextRenderer.MeasureText(text, PAAContext.FontManagement.OrientFont).Width;
                //LineWidth = textWidth * PAAContext.FontManagement.CurrentFontWidthSize;
                //标注位置
                for (int i = 0; i < PipeAndNodePoints.Count(); i++)
                {
                    var start = TargetLocation + (LineHeight + i * LineSpace) * VerticalVector;
                    var end   = start + LineWidth * ParallelVector;
                    PipeAndNodePoints[PipeAndNodePoints.Count() - 1 - i].AnnotationPoint = TextType.GetTextLocation(CurrentFontHeight, VerticalVector, start, end);
                }
                #endregion
                return(true);

            default:
                throw new NotImplementedException("未支持该类型的生成");
            }
        }