Esempio n. 1
0
 protected override bool OnPostLocate(BD.HitPath path, out string cantAcceptReason)
 {
     BDE.Element ele = path.GetHeadElement();
     if (ele.ElementType != BD.MSElementType.Shape)
     {
         cantAcceptReason = Resources.PutArmorToolRejectReason;
         return(false);
     }
     BDE.ShapeElement shape            = ele as BDE.ShapeElement;
     BG.CurveVector   shapeCurveVector = shape.GetCurveVector();
     BG.DTransform3d  world2LoaclDTransform3D;
     BG.DTransform3d  loacl2WorlDTransform3D;
     BG.DRange3d      shapeRange3D;
     if (!shapeCurveVector.IsPlanar(out loacl2WorlDTransform3D, out world2LoaclDTransform3D, out shapeRange3D))
     {
         cantAcceptReason = Resources.PutArmorToolRejectReason2;
         return(false);
     }
     if (!IsRectangel(shapeCurveVector))
     {
         cantAcceptReason = Resources.PutArmorToolRejectReason3;
         return(false);
     }
     return(base.OnPostLocate(path, out cantAcceptReason));
 }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public static BDE.ShapeElement DrawShapeFromLineString(BDE.LineStringElement linestringele)
        {
            var pointlist = new List <BG.DPoint3d>();
            var cv        = linestringele.GetCurveVector();

            if (cv.Count == 1 && cv.GetAt(0).TryGetLineString(pointlist))
            {
                if (pointlist.Count > 2)
                {
                    var shape = new BDE.ShapeElement(linestringele.DgnModel, null, pointlist.ToArray());
                    shape.AddSolidFill(2, true);
                    return(shape);
                }
            }
            return(null);
        }
        // should create on 0,0,0 center
        private Bentley.DgnPlatformNET.Elements.Element CreatePolyhedronCell(string sPolyhedronName,
                                                                             List <DPoint3d> points, List <List <int> > faces, List <DPoint3d> colors)
        {
            try
            {
                List <Bentley.DgnPlatformNET.Elements.Element> listElements = new List <Bentley.DgnPlatformNET.Elements.Element>();

                if (points.Count > 0 && faces.Count > 0)
                {
                    int iFaceIndex = 0;

                    foreach (List <int> listVertices in faces)
                    {
                        List <DPoint3d> listPoints = new List <DPoint3d>();

                        foreach (int iVertexIndex in listVertices)
                        {
                            DPoint3d pt = points[iVertexIndex];
                            pt.ScaleInPlace(uorPerMaster());
                            listPoints.Add(pt);
                        }

                        DPoint3d color = colors.ToArray()[iFaceIndex++];

                        Bentley.DgnPlatformNET.Elements.ShapeElement shapeElement =
                            new Bentley.DgnPlatformNET.Elements.ShapeElement(Session.Instance.GetActiveDgnModel(), null, listPoints.ToArray());

                        DVector3d normal    = new DVector3d();
                        DPoint3d  somePoint = new DPoint3d();
                        DPoint3d  defNormal = listPoints.ToArray()[0];

                        shapeElement.IsPlanar(out normal, out somePoint, ref defNormal);

                        uint iColorIndex = (uint)listPoints.Count - 1;

                        ElementPropertiesSetter pSetter = new ElementPropertiesSetter();

                        pSetter.SetColor(iColorIndex);
                        pSetter.SetFillColor(iColorIndex);
                        shapeElement.AddSolidFill(iColorIndex, false);

                        pSetter.Apply(shapeElement);

                        listElements.Add(shapeElement);
                    }
                }

                if (listElements.Count > 0)
                {
                    DMatrix3d rotation = new DMatrix3d(1, 0, 0, 0, 1, 0, 0, 0, 1);   // Identity
                    Bentley.DgnPlatformNET.Elements.CellHeaderElement cellHeaderElement = new CellHeaderElement(Session.Instance.GetActiveDgnModel(), sPolyhedronName,
                                                                                                                new DPoint3d(0, 0, 0), rotation, listElements);

                    return(cellHeaderElement);
                }
            }
            catch (Exception ex)
            {
                BPSUtilities.WriteLog($"CreatePolyhedronCell {ex.Message}\n{ex.StackTrace}");
            }


            return(null);
        }
Esempio n. 5
0
        protected override void OnPostInstall()
        {
            try
            {
                BPSUtilities.WriteLog("PlaceQRCode OnPostInstall");

                NotificationManager.OutputPrompt("Enter data point for corner of QR Code. Reset to exit.");
                // AccuSnap.SnapEnabled = true;
                // AccuSnap.LocateEnabled = true;
                base.OnPostInstall();

                m_haveFirstPoint = false;
                // base.BeginDynamics();
                m_firstPoint = DPoint3d.Zero;

                if (!string.IsNullOrEmpty(LongURL))
                {
                    QRCodeEncoderLibrary.QREncoder enc = QRCodeImageFunctions.GetQREncoderObject(LongURL);

                    BPSUtilities.WriteLog($"QRCodeDimension: {enc.QRCodeDimension}");

                    if (enc.QRCodeDimension > 0)
                    {
                        DPoint3d[] blkPts = new DPoint3d[4];

                        blkPts[0] = blkPts[1] = blkPts[2] = blkPts[3] = DPoint3d.Zero;

                        blkPts[0].X = enc.QuietZone;
                        blkPts[0].Y = enc.QuietZone;

                        blkPts[1].X = enc.QuietZone + 1.0;
                        blkPts[1].Y = enc.QuietZone;
                        blkPts[2].X = enc.QuietZone + 1.0;
                        blkPts[2].Y = enc.QuietZone + 1.0;
                        blkPts[3].X = enc.QuietZone;
                        blkPts[3].Y = enc.QuietZone + 1.0;

                        DPoint3d[] blkPts2 = new DPoint3d[4];

                        DVector3d yVec = new DVector3d(0, 1, 0);
                        DVector3d xVec = new DVector3d(1, 0, 0);

                        DMatrix3d cellRotation = new DMatrix3d(1, 0, 0, 0, 1, 0, 0, 0, 1);   // Identity

                        List <Bentley.DgnPlatformNET.Elements.Element> listChildElements = new List <Bentley.DgnPlatformNET.Elements.Element>();

                        // bool[,] pixels = enc.ConvertQRCodeMatrixToPixels();

                        for (int i = 0; i < enc.QRCodeDimension; i++)
                        {
                            // reset row
                            for (int index = 0; index < 4; index++)
                            {
                                blkPts2[index] = blkPts[index];
                            }

                            // move up
                            for (int index = 0; index < 4; index++)
                            {
                                blkPts2[index] = DPoint3d.Add(blkPts2[index], yVec, (double)i);
                            }

                            for (int j = 0; j < enc.QRCodeDimension; j++)
                            {
                                if (enc.QRCodeMatrix[i, j])
                                {
                                    Bentley.DgnPlatformNET.Elements.ShapeElement shapeElement =
                                        new Bentley.DgnPlatformNET.Elements.ShapeElement(Session.Instance.GetActiveDgnModel(), null, blkPts2);

                                    ElementPropertiesSetter pSetter = new ElementPropertiesSetter();

                                    pSetter.SetColor((uint)Bentley.MstnPlatformNET.Settings.GetActiveFillColor().Index);
                                    pSetter.SetFillColor((uint)Bentley.MstnPlatformNET.Settings.GetActiveFillColor().Index);
                                    shapeElement.AddSolidFill((uint)Bentley.MstnPlatformNET.Settings.GetActiveFillColor().Index, true);

                                    pSetter.Apply(shapeElement);

                                    if (shapeElement.IsValid)
                                    {
                                        listChildElements.Add(shapeElement);
                                    }
                                }

                                // move across
                                for (int index = 0; index < 4; index++)
                                {
                                    blkPts2[index] = DPoint3d.Add(blkPts2[index], xVec);
                                }
                            }
                        }

                        DPoint3d[] blkPts3 = new DPoint3d[5];

                        blkPts3[0] = blkPts3[1] = blkPts3[2] = blkPts3[3] = blkPts3[4] = DPoint3d.Zero;

                        blkPts3[1].X = 2 * enc.QuietZone + enc.QRCodeDimension;
                        blkPts3[2].X = 2 * enc.QuietZone + enc.QRCodeDimension;
                        blkPts3[2].Y = 2 * enc.QuietZone + enc.QRCodeDimension;
                        blkPts3[3].Y = 2 * enc.QuietZone + enc.QRCodeDimension;

                        Bentley.DgnPlatformNET.Elements.LineStringElement border = new LineStringElement(Session.Instance.GetActiveDgnModel(), null, blkPts3);

                        ElementPropertiesSetter pSetter2 = new ElementPropertiesSetter();

                        pSetter2.SetColor((uint)Bentley.MstnPlatformNET.Settings.GetActiveFillColor().Index);

                        pSetter2.Apply(border);

                        listChildElements.Add(border);

                        Bentley.DgnPlatformNET.Elements.CellHeaderElement codeElement = new CellHeaderElement(Session.Instance.GetActiveDgnModel(), "QRCode",
                                                                                                              new DPoint3d(0, 0, 0), cellRotation, listChildElements);

                        // scale down to one...

                        DMatrix3d rotMatrix = DMatrix3d.Identity;

                        rotMatrix.ScaleInPlace((double)1.0 / (double)enc.QRCodeDimension);

                        DTransform3d translateAndScale =
                            DTransform3d.FromMatrixAndTranslation(rotMatrix, DPoint3d.Zero);

                        TransformInfo transformInfo = new TransformInfo(translateAndScale);

                        codeElement.ApplyTransform(transformInfo);

                        CodeElement = codeElement;

                        // might want to tag with the URL...

                        if (CodeElement.IsValid)
                        {
                            base.BeginDynamics();
                        }
                    }
                }

                BPSUtilities.WriteLog($"PlaceQRCode OnPostInstall Dynamics {(this.DynamicsStarted ? "is" : "is not")} started.");
            }
            catch (Exception ex)
            {
                BPSUtilities.WriteLog($"PlaceQRCode OnPostInstall {ex.Message}\n{ex.StackTrace}");
            }
        }