Esempio n. 1
0
        /*---------------------------------------------------------------------------------**//**
        * Create Grouped hole element.
        * @bsimethod                                                              Bentley Systems
        *  /*--------------+---------------+---------------+---------------+---------------+------*/
        public static Element CreateElement(DPoint3d start, DPoint3d opposite)
        {
            DgnModel model = Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnModel();

            //Create Solid shape element from actual start and opposite points.
            ShapeElement solidShape = CreateShapeElement(model, start, opposite);

            //Get holes for grouped hole element.
            ElementAgenda holes;

            PopulateHolesAgenda(out holes, start, opposite, model);

            //Create actual grouped hole element with given solid and holes.
            GroupedHoleElement groupedHoleElement = new GroupedHoleElement(model, solidShape, holes);

            //Set line color.
            ElementPropertiesSetter pSetter = new ElementPropertiesSetter();

            pSetter.SetColor((uint)Bentley.MstnPlatformNET.Settings.GetActiveColor().Index);
            pSetter.Apply(groupedHoleElement);

            //Add fill color.
            if (PlaceGroupedHoleForm.GetAddFillColor())
            {
                groupedHoleElement.AddSolidFill((uint)Bentley.MstnPlatformNET.Settings.GetActiveFillColor().Index, false);
            }

            return(groupedHoleElement);
        }
Esempio n. 2
0
        public static void addToModelWithProjAndPerfo(ref TFCOM.TFFrameList frameList,
                                                      PenetrTask task, PenetrInfo penInfo,
                                                      BCOM.Level levelSymb, BCOM.Level levelRefPoint)
        {
            var taskUOR = new UOR(task.modelRef);

            double pipeInsideDiam  = penInfo.pipeDiameterInside / taskUOR.active_subPerMaster;
            double pipeOutsideDiam = penInfo.pipeDiameterOutside / taskUOR.active_subPerMaster;

            double flangeInsideDiam  = penInfo.flangeDiameterInside / taskUOR.active_subPerMaster;
            double flangeOutsideDiam = penInfo.flangeDiameterOutside / taskUOR.active_subPerMaster;
            double flangeThick       = penInfo.flangeThick / taskUOR.active_subPerMaster;

            double length = task.LengthCm * 10 / taskUOR.active_subPerMaster;

            BCOM.ModelReference activeModel = App.ActiveModelReference;
            //AppTF.ModelReferenceAddFrameList(activeModel, ref frameList);

            frameList.Synchronize();
            var frameListClass = frameList as TFCOM.TFFrameListClass;

            BCOM.Element bcomElem;
            frameListClass.GetElement(out bcomElem);

            var tfApi    = new Bentley.Building.Api.TFApplicationList().AsTFApplication;
            var modelRef = Session.Instance.GetActiveDgnModelRef();
            var model    = Session.Instance.GetActiveDgnModel();

            Element ielement = Element.GetFromElementRef((IntPtr)bcomElem.MdlElementRef());

            modelRef.GetFromElementRef((IntPtr)bcomElem.MdlElementRef());

            ITFFrameList iframeList;

            tfApi.CreateTFFrame(0, out iframeList);
            iframeList.InitFromElement(ielement, "");
            iframeList.Synchronize("");

            DPoint3d origin = task.Location.ToDPoint();

            origin.ScaleInPlace(taskUOR.active_perMaster);

            DMatrix3d matrix = DMatrix3d.FromRows(
                task.Rotation.RowX.ToDVector(), task.Rotation.RowY.ToDVector(),
                task.Rotation.RowZ.ToDVector());

            DTransform3d  dTran    = DTransform3d.FromMatrixAndTranslation(matrix, origin);
            TransformInfo tranInfo = new TransformInfo(dTran);

            double pipeInsideRadius = pipeOutsideDiam / 2 * taskUOR.active_perMaster;
            double dgnLength        = length * taskUOR.active_perMaster;

            var ellips = new EllipseElement(model, null,
                                            DEllipse3d.FromCenterRadiusNormal(DPoint3d.Zero, pipeInsideRadius,
                                                                              DVector3d.FromXY(0, 1)));

            ellips.ApplyTransform(tranInfo);



            //{  // ПЕРФОРАТОР:
            //    ITFPerforatorList perfoList;
            //    tfApi.CreateTFPerforator(0, out perfoList);
            //    var dir = DVector3d.FromXY(1, 0);
            //    var tran = DTransform3d.Identity;
            //    //perfoList.InitFromElement(ellips, ref dir, length*toUOR, ref tran, "");
            //    perfoList.InitFromElement2(ellips, length*taskUOR.active_perMaster, "");
            //    perfoList.AsTFPerforator.SetIsVisible(false, 0);
            //    perfoList.SetSweepMode(Bentley.Building.Api.TFdPerforatorSweepMode.tfdPerforatorSweepModeBi, "");
            //    perfoList.SetPolicy(Bentley.Building.Api.TFdPerforatorPolicy.tfdPerforatorPolicyThroughHoleWithinSenseDist, "");

            //    (iframeList as Bentley.Building.Api.TFFrameList).SetPerforatorList(ref perfoList, 0);

            //   // iframeList.AsTFFrame.SetPerforatorList(ref perfoList, 0);
            //    iframeList.AsTFFrame.SetSenseDistance2(length, 0);
            //    iframeList.AsTFFrame.SetPerforatorsAreActive(true, 0);
            //        var frame = iframeList.AsTFFrame;
            //    tfApi.ModelReferenceUpdateAutoOpeningsByFrame(modelRef,
            //ref frame, true, false, Bentley.Building.Api.TFdFramePerforationPolicy.tfdFramePerforationPolicyStrict, 0);

            //}



            // tfApi.ModelReferenceRewriteFrameInstance(modelRef, iframeList.AsTFFrame, 0);
            //iframeList.AsTFFrame.Synchronize(0);

            { // ПРОЕКЦИОННАЯ ГЕОМЕТРИЯ
                ITFProjectionList projList, projList1, projList2, projList3;
                tfApi.CreateTFProjection(0, out projList);
                tfApi.CreateTFProjection(0, out projList1);
                tfApi.CreateTFProjection(0, out projList2);
                tfApi.CreateTFProjection(0, out projList3);

                var        zero  = DPoint3d.Zero;
                DPoint3d[] verts = { zero, zero, zero, zero, zero };
                double     k     = pipeInsideRadius * Math.Cos(Math.PI / 4);
                verts[0].X  = -k;
                verts[0].Z  = -k;
                verts[1].X  = k;
                verts[1].Z  = k;
                verts[3]    = verts[0];
                verts[3].Z *= -1;
                verts[4]    = verts[1];
                verts[4].Z *= -1;

                LineStringElement cross1 = new LineStringElement(model, null, verts);
                for (int i = 0; i < verts.Count(); ++i)
                {
                    verts[i].Y = dgnLength;
                }
                LineStringElement cross2 = new LineStringElement(model, null, verts);

                cross1.ApplyTransform(tranInfo);
                cross2.ApplyTransform(tranInfo);

                projList1.AsTFProjection.SetEmbeddedElement(cross1, 0);
                projList2.AsTFProjection.SetEmbeddedElement(cross2, 0);

                LineElement refPoint =
                    new LineElement(model, null, new DSegment3d(zero, zero));

                refPoint.ApplyTransform(tranInfo);
                ElementPropertiesSetter setter = new ElementPropertiesSetter();
                setter.SetWeight(7);
                setter.Apply(refPoint);

                projList3.AsTFProjection.SetEmbeddedElement(refPoint, 0);

                projList.Append(projList1, "");
                projList.Append(projList2, "");
                projList.Append(projList3, "");
                iframeList.AsTFFrame.SetProjectionList(projList, 0);
                //iframeList.AsTFFrame.Synchronize(0);
                //iframeList.Synchronize(string.Empty);
            }

            tfApi.ModelReferenceRewriteFrameInstance(modelRef, iframeList.AsTFFrame, 0);

            //  int stat = tfApi.ModelReferenceRewriteFrameList(modelRef, iframeList, 0);
            //tfApi.ModelReferenceAddFrameList(modelRef, ref iframeList, 0);


            //    tfApi.ModelReferenceRewriteFrameList(modelRef, iframeList, 0);



            //frameListClass = frameList as TFCOM.TFFrameListClass;
            //frameListClass.GetElement(out bcomElem);

            // setDataGroupInstance(bcomElem, task);
        }
        // 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. 4
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}");
            }
        }