Example #1
0
        //其余扩展
        public static MES.Line3D DSegement3dToLine3D(this BG.DSegment3d p)
        {
            var startp = p.StartPoint;
            var endp   = p.EndPoint;

            return(new MES.Line3D(new MES.Point3D(startp.X, startp.Y, startp.Z), new MES.Point3D(endp.X, endp.Y, endp.Z)));
        }
        //return-> unit:m
        //lowpointz-> unit:m
        BG.DPoint3d GetVirtualPileAxisBottomPoint(double lowpointz)
        {
            BG.DSegment3d pileaxis           = new BG.DSegment3d(m_pile.PilePropertyInfo.PileTopPoint.Point3dToDPoint3d(), m_pile.PilePropertyInfo.PileBottomPoint.Point3dToDPoint3d());
            double        pileaxiszlength    = pileaxis.Extent.Z;
            double        virtualaxiszlength = pileaxis.StartPoint.Z - lowpointz;
            double        scale = Math.Abs(virtualaxiszlength / pileaxiszlength);

            return(pileaxis.PointAtFraction(scale));
        }
        public ObservableCollection <CollisionInfo> GetCollisionInfoList(double minallowdistance = 0 /*unit mm*/)
        {
            //double uor_per_meter = Program.GetActiveDgnModel().GetModelInfo().UorPerMeter;
            double uor_per_master = Program.GetActiveDgnModel().GetModelInfo().UorPerMaster;
            //double uor_per_storage = Program.GetActiveDgnModel().GetModelInfo().UorPerStorage;
            //double uor_per_sub = Program.GetActiveDgnModel().GetModelInfo().UorPerSub;
            var collisionInfoList     = new ObservableCollection <CollisionInfo>();
            var pileidlist            = GetPileAxisLineIds();
            var collisiontestpilelist = new List <CollisionTestPileInfo>();

            var activemodel = Program.GetActiveDgnModel();

            foreach (var id in pileidlist)
            {
                var ele = activemodel.FindElementById((BD.ElementId)id);
                if (ele != null && ele.ElementType == BD.MSElementType.Line)
                {
                    var    blockdatareader = ele.GetLinkage((ushort)BD.ElementLinkageId.String);
                    string elename         = string.Empty;
                    if (blockdatareader != null)
                    {
                        elename = blockdatareader.ReadString();
                    }
                    else
                    {
                        elename = ele.Description + " ID:" + ele.ElementId.ToString();
                    }

                    var comele = app.ActiveModelReference.GetElementByID64(id).AsLineElement();
                    collisiontestpilelist.Add(new CollisionTestPileInfo {
                        PileCode = elename, PileAxisSegement = new BG.DSegment3d(comele.StartPoint.Point3dToDPoint3d(uor_per_master), comele.EndPoint.Point3dToDPoint3d(uor_per_master))
                    });
                }
            }
            int pileaxiscount = collisiontestpilelist.Count;

            for (int i = 0; i < pileaxiscount - 1; i++)
            {
                for (int j = i + 1; j < pileaxiscount; j++)
                {
                    if (i == 58 && j == 59)
                    {
                        activemodel.FindElementById((BD.ElementId)(ulong) 1);
                    }
                    BG.DSegment3d minsegement = GetMinDistanceBetweenToLine(collisiontestpilelist[i].PileAxisSegement, collisiontestpilelist[j].PileAxisSegement);
                    if (minsegement.Length / 10 <= minallowdistance)
                    {
                        collisionInfoList.Add(new CollisionInfo {
                            PileAName = collisiontestpilelist[i].PileCode, PileBName = collisiontestpilelist[j].PileCode, PileACollisionPoint = minsegement.StartPoint, PileBCollisionPoint = minsegement.EndPoint, MinDistance = minsegement.Length / 10
                        });
                    }
                }
            }
            //完成在一个图层上绘制最短距离
            //if (collisionInfoList.Count != 0) return true; else return false;
            return(collisionInfoList);
        }
Example #4
0
        public override BD.StatusInt OnElementModify(BDE.Element element)
        {
            BDE.ShapeElement shape = element as BDE.ShapeElement;
            if (shape == null)
            {
                return(BD.StatusInt.Error);
            }
            BG.CurveVector  curveVector = shape.GetCurveVector();
            BG.DTransform3d world2LoaclDTransform3D;
            BG.DTransform3d loacl2WorlDTransform3D;
            BG.DRange3d     shapeRange3D;
            curveVector.IsPlanar(out loacl2WorlDTransform3D, out world2LoaclDTransform3D, out shapeRange3D);
            BG.DMatrix3d       rotMatrix3D = loacl2WorlDTransform3D.Matrix;
            List <BG.DPoint3d> points      = new List <BG.DPoint3d>();

            curveVector.GetPrimitive(0).TryGetLineString(points);

            BG.DSegment3d linex = new BG.DSegment3d(points[0], points[1]);
            BG.DSegment3d liney = new BG.DSegment3d(points[0], points[3]);

            int ucellnum = 0;
            int vcellnum = 0;

            if (isOutRect)
            {
                ucellnum = (int)Math.Ceiling(linex.Length / uaxisoffset);
                vcellnum = (int)Math.Ceiling(liney.Length / vaxisoffset);
            }
            else
            {
                ucellnum = (int)Math.Floor(linex.Length / uaxisoffset);
                vcellnum = (int)Math.Floor(liney.Length / vaxisoffset);
            }

            double ufraction = uaxisoffset / linex.Length;
            double vfraction = vaxisoffset / liney.Length;

            for (int i = 0; i < vcellnum; i++)
            {
                BG.DPoint3d yaxisPoint = liney.PointAtFraction(i * vfraction);
                for (int j = 0; j < ucellnum; j++)
                {
                    BG.DPoint3d  xaxisPoint  = linex.PointAtFraction(j * ufraction);
                    BG.DVector3d xyDVector3D = BG.DVector3d.Add(BG.DPoint3d.Subtract(xaxisPoint, points[0]), BG.DPoint3d.Subtract(yaxisPoint, points[0]));
                    BG.DPoint3d  putPoint3D  = BG.DPoint3d.Add(points[0], xyDVector3D);
                    CellFunction.PlaceCell(new ArmorCellInfo()
                    {
                        CellName  = cellName,
                        CellTrans = rotMatrix3D,
                        Origin    = putPoint3D
                    });
                    Bentley.UI.Threading.DispatcherHelper.DoEvents();
                }
            }
            return(BD.StatusInt.Success);
        }
        public void Test()
        {
            BG.DSegment3d lineAB = new Bentley.GeometryNET.DSegment3d(0, 0, 5, 0, 0, 10);
            BG.DSegment3d lineCD = new Bentley.GeometryNET.DSegment3d(0, 0, -5, 0, 0, -10);
            BG.DSegment3d outline;
            double        fa, fb;

            BG.DSegment3d.ClosestApproachSegment(lineAB, lineCD, out outline, out fa, out fb);
            //MinDistance = 1;
        }
        BG.DSegment3d GetMinDistanceBetweenToLine(BG.DSegment3d lineAB, BG.DSegment3d lineCD)
        {
            //var lineab = lineAB.DSegement3dToLine3D();
            //var linecd = lineCD.DSegement3dToLine3D();
            //var closetline = lineab.ClosestPointsBetween(linecd, true);
            //return new Bentley.GeometryNET.DSegment3d(closetline.Item1.Point3DToDPoint3d(), closetline.Item2.Point3DToDPoint3d());
            BG.DSegment3d crossline;
            double        fa, fb;
            bool          isCross;

            isCross = BG.DSegment3d.ClosestApproachSegment(lineAB, lineCD, out crossline, out fa, out fb);

            if (0 <= fa && fa <= 1 && 0 <= fb && fb <= 1)
            {
                return(new BG.DSegment3d(lineAB.PointAtFraction(fa), lineCD.PointAtFraction(fb)));
            }
            else
            {
                //double A_LineCD, B_LineCD, C_LineAB, D_LineAB;
                BG.DPoint3d P_A_LineCD, P_B_LineCD, P_C_LineAB, P_D_LineAB;
                double      f;
                lineCD.ClosestFractionAndPoint(lineAB.StartPoint, true, out f, out P_A_LineCD);
                lineCD.ClosestFractionAndPoint(lineAB.EndPoint, true, out f, out P_B_LineCD);
                lineAB.ClosestFractionAndPoint(lineCD.StartPoint, true, out f, out P_C_LineAB);
                lineAB.ClosestFractionAndPoint(lineCD.EndPoint, true, out f, out P_D_LineAB);
                var closedis = new double[]
                {
                    lineAB.StartPoint.Distance(P_A_LineCD),
                    lineAB.EndPoint.Distance(P_B_LineCD),
                    lineCD.StartPoint.Distance(P_C_LineAB),
                    lineCD.EndPoint.Distance(P_D_LineAB)
                };
                BG.DSegment3d minsegement = new Bentley.GeometryNET.DSegment3d();
                switch (closedis.FindIndex(n => n == closedis.Min()))
                {
                case 0:
                    minsegement = new BG.DSegment3d(lineAB.StartPoint, P_A_LineCD);
                    break;

                case 1:
                    minsegement = new BG.DSegment3d(lineAB.EndPoint, P_B_LineCD);
                    break;

                case 2:
                    minsegement = new BG.DSegment3d(P_C_LineAB, lineCD.StartPoint);
                    break;

                case 3:
                    minsegement = new BG.DSegment3d(P_D_LineAB, lineCD.EndPoint);
                    break;
                }
                return(minsegement);
            }
        }
Example #7
0
        public void DrawLines()
        {
            var activemodel = Program.GetActiveDgnModel();

            //Create ItemTypeLibrary
            BD.ItemTypeLibrary pilePropItemTypeLibrary = CreateItemTypeLibrary();

            //Create PileAxisLevelHandle
            var pileaxislevelhandle = CreatePileAxisLevel();

            if (pileaxislevelhandle == null)
            {
                return;
            }
            BM.SettingsActivator.SetActiveLevel(pileaxislevelhandle.LevelId);
            BD.ElementPropertiesSetter levelSetter = new BD.ElementPropertiesSetter();
            levelSetter.SetLevel(pileaxislevelhandle.LevelId);

            //Get the PileAxisInfomation And Create the Pile and Schedule Itemtype
            var pileAxisInfoList = ExtractPileAxisInfo();

            BG.DPoint3d top, bottom;
            double      uorPerMillimeter = activemodel.GetModelInfo().UorPerMeter / 1000;
            double      tolerance        = 1e-5;

            foreach (var pileAxisInfo in pileAxisInfoList)
            {
                top = BG.DPoint3d.FromXYZ(pileAxisInfo.TopX, pileAxisInfo.TopY, pileAxisInfo.TopZ);
                if (Math.Abs(pileAxisInfo.Skewness) < tolerance)
                {
                    bottom = top - BG.DPoint3d.UnitY * pileAxisInfo.Length;
                }
                else
                {
                    double temp = pileAxisInfo.Length / (Math.Sqrt(pileAxisInfo.Skewness * pileAxisInfo.Skewness + 1));
                    bottom = top + new BG.DPoint3d(Math.Cos(pileAxisInfo.RotationDegree * deg2rad), Math.Sin(pileAxisInfo.RotationDegree * deg2rad), -pileAxisInfo.Skewness) * temp;
                }
                top.ScaleInPlace(uorPerMillimeter);
                bottom.ScaleInPlace(uorPerMillimeter);

                BG.DSegment3d   lineDSegment3D = new BG.DSegment3d(top, bottom);
                BDE.LineElement line           = new BDE.LineElement(activemodel, null, lineDSegment3D);
                levelSetter.Apply(line);

                if (SetLineElementProp(pileAxisInfo, line, pilePropItemTypeLibrary) == BD.StatusInt.Error)
                {
                    BM.MessageCenter.Instance.ShowErrorMessage($"{pileAxisInfo.PileCode}桩写入属性失败", "写入属性失败", false);
                    continue;
                }
                line.AddToModel();
            }
        }
Example #8
0
        public void DrawLines()
        {
            var activemodel = Program.GetActiveDgnModel();
            var levelcache  = activemodel.GetFileLevelCache();
            var levelhandle = levelcache.GetLevelByName("PileAxis");

            if (levelhandle.Status == BD.LevelCacheErrorCode.CannotFindLevel)
            {
                levelhandle = levelcache.CreateLevel("PileAxis");
            }
            levelcache.Write();
            var leveledithandle = levelhandle.GetEditHandle();

            leveledithandle.Description = "桩的轴中心线";
            BM.SettingsActivator.SetActiveLevel(levelhandle.LevelId);

            BD.ElementPropertiesSetter levelsetter = new BD.ElementPropertiesSetter();
            levelsetter.SetLevel(levelhandle.LevelId);
            levelsetter.SetColor(3);

            BG.DPoint3d top, bottom;
            var         pilelist = ExtractPileInfo();

            foreach (var pile in pilelist)
            {
                top = new BG.DPoint3d(pile.TopX, pile.TopY, pile.TopZ);
                if (pile.Skewness == 0)
                {
                    bottom = top - BG.DPoint3d.UnitZ * pile.Length;
                }
                else
                {
                    double temp = pile.Length / (Math.Sqrt(pile.Skewness * pile.Skewness + 1));
                    bottom = top + new BG.DPoint3d(Math.Cos(pile.RotationDegree * deg2rad), Math.Sin(pile.RotationDegree * deg2rad), -pile.Skewness) * temp;
                }
                BG.DSegment3d   lineseg = new BG.DSegment3d(top * 10, bottom * 10);
                BDE.LineElement line    = new BDE.LineElement(activemodel, null, lineseg);
                levelsetter.Apply(line);

                var wb = new BDE.WriteDataBlock();
                wb.WriteString(pile.PileCode);
                line.AppendLinkage((ushort)BD.ElementLinkageId.String, wb);
                line.AddToModel();
            }
        }
Example #9
0
 public static HCHXCodeQueryErrorCode QueryByRay(this HCHXCodeQuery pilequery, ref ColumnLayerInfoArray result, BG.DSegment3d linesegement)
 {
     return(pilequery.QueryByRay(ref result, linesegement.StartPoint.DPoint3dToPoint3d(), linesegement.EndPoint.DPoint3dToPoint3d()));
 }