コード例 #1
0
        public static ITFFrameList createFrameCN
            (PenetrTask task, PenetrInfo penInfo)
        {
            task.scanInfo();

            // TODO отключено временно, до решения по алгоритму пересечений фланцев:
            //if (!Keyins.Penetrations.DEBUG_MODE) {
            //    if (task.isCompoundExistsInPlace || task.TFFormsIntersected.Count == 0)
            //        return null;
            //}

            var taskUOR = task.UOR;

            double pipeInsideDiam  = penInfo.pipeDiameterInside * taskUOR.active_perSub;
            double pipeOutsideDiam = penInfo.pipeDiameterOutside * taskUOR.active_perSub;

            double flangeInsideDiam  = penInfo.flangeDiameterInside * taskUOR.active_perSub;
            double flangeOutsideDiam = penInfo.flangeDiameterOutside * taskUOR.active_perSub;
            double flangeThick       = penInfo.flangeThick * taskUOR.active_perSub;

            double length = task.Length * taskUOR.active_perSub;

            double pipeInRadius  = pipeInsideDiam / 2;
            double pipeOutRadius = pipeOutsideDiam / 2;


            var tfApi = new Bentley.Building.Api.TFApplicationList().AsTFApplication;

            BCOM.ModelReference activeModel = App.ActiveModelReference;

            //ITFBrepList brepList;
            //tfApi.CreateTFBrep(0, out brepList);

            DPoint3d origin = task.Location.ToDPoint();

            origin.ScaleInPlace(taskUOR.active_perMaster);

            DMatrix3d rot      = task.Rotation.ToDMatrix3d();
            var       dTran    = DTransform3d.FromMatrixAndTranslation(rot, origin);
            var       tranInfo = new TransformInfo(dTran);
            // DMatrix3d.FromColumns(
            //rot.RowX.ToDVector(), rot.RowX.ToDVector(), rot.RowX.ToDVector());

            //ITFFormRecipeList recipeList;

            var model    = Session.Instance.GetActiveDgnModel();
            var modelRef = Session.Instance.GetActiveDgnModelRef();

            //CellHeaderElement taskEl = Element.GetFromElementRef(task.elemRefP) as CellHeaderElement;
            //DPoint3d taskOrigin;
            //taskEl.GetSnapOrigin(out taskOrigin);

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

            ellips.ApplyTransform(tranInfo);

            var cone = new ConeElement(model, null, pipeOutRadius, pipeOutRadius,
                                       DPoint3d.FromXYZ(0, length, 0), DPoint3d.Zero,
                                       DMatrix3d.Rotation(DVector3d.UnitX, Angle.FromDegrees(-90)), true);

            cone.ApplyTransform(tranInfo);

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

            ellips2.ApplyTransform(tranInfo);

            var cone2 = new ConeElement(model, null, pipeInRadius, pipeInRadius,
                                        DPoint3d.Zero, DPoint3d.FromXYZ(0, length, 0), DMatrix3d.Zero, false);

            cone2.ApplyTransform(tranInfo);



            //int status = brepList.InitCylinder(pipeInsideRadius*task_subPerMaster,
            //    (length - flangeThick)*task_subPerMaster, ref origin,
            //    ref matrix, "");

            //ITFElementList elemList;
            //tfApi.CreateTFElement(0, out elemList);
            // Bentley.GeometryNET.Common.CircularCylinder



            //ITFBrepList coneBrepList, cone2BrepList, resBrepList;
            //tfApi.CreateTFBrep(0, out coneBrepList);
            //tfApi.CreateTFBrep(0, out cone2BrepList);
            //coneBrepList.InitFromElement(cone, modelRef, "");
            //cone2BrepList.InitFromElement(cone2, modelRef, "");

            //coneBrepList.AsTFBrep.InitCylinder(pipeInsideRadius, length, ref origin,
            //    ref matrix, 0);

            ITFItemList itemList;

            tfApi.CreateTFItem(0, out itemList);

            //var sweepDir = DVector3d.FromXY(1, 0);
            //coneBrepList.AsTFBrep.Drop(out resBrepList, cone2BrepList, 0);
            //sweepDir.NegateInPlace();
            // coneBrepList.AsTFBrep.Cut(out resBrepList, cone2BrepList,  ref sweepDir, length + 150, false, 0);
            //coneBrepList.AsTFBrep.SweepByVector3(ref sweepDir, length + 300,
            //    pipeOutsideRadius - pipeInsideRadius, 0, 0);

            //Array arr = new System.Collections.ArrayList().ToArray();

            //coneBrepList.AsTFBrep.Cut2(out resBrepList, cone2BrepList.AsTFBrep, ref sweepDir,
            //Bentley.Building.Api.TFdBrepCutMethod.tfdBrepCutMethod_Outside,
            //Bentley.Building.Api.TFdBrepCutDirection.tfdBrepCutDirection_Both,
            //Bentley.Building.Api.TFdBrepCutDepth.tfdBrepCutDepth_UpToSolid, length,
            //arr, 0, false, Bentley.Building.Api.TFdBrepCutDepth.tfdBrepCutDepth_UpToSolid, length,
            //arr, 0, false, 0, 0, 0.00005, 0);

            //lement resElement;
            //resBrepList.GetElement(out resElement, 0, "");
            //coneBrepList.GetElement(out resElement, 0, "");

            ITFFrameList frameList;

            tfApi.CreateTFFrame(0, out frameList);
            frameList.AsTFFrame.Add3DElement(cone, 0);
            //frameList.AsTFFrame.Add3DElement(cone2, 0);
            //frameList.AsTFFrame.Add3DElement(resElement, 0);

            //ITFFrameList openingFrameList;
            //tfApi.CreateTFFrame(0, out openingFrameList);
            //openingFrameList.AsTFFrame.Add3DElement(cone2, 0);

            //ITFFormRecipeList openRecipeList;
            ////tfApi.CreateTFFormRecipeArc
            //ITFFormRecipe openRecipe;
            //openingFrameList.AsTFFrame.GetFormRecipeList(0, out openRecipeList);
            //openRecipe = openRecipeList.AsTFFormRecipe;

            //ITFItemList featureList;
            //frameList.AsTFFrame.AddOpeningsToForm(out featureList, ref openRecipe, "", 0);


            ITFPerforatorList perfoList;

            tfApi.CreateTFPerforator(0, out perfoList);
            var dir  = DVector3d.FromXY(1, 0);
            var tran = DTransform3d.Identity;

            perfoList.InitFromElement(ellips, ref dir, length, ref tran, "");
            perfoList.AsTFPerforator.SetIsVisible(false, 0);
            perfoList.SetSweepMode(Bentley.Building.Api.TFdPerforatorSweepMode.tfdPerforatorSweepModeBi, "");
            perfoList.SetPolicy(Bentley.Building.Api.TFdPerforatorPolicy.tfdPerforatorPolicyThroughHoleWithinSenseDist, "");


            frameList.AsTFFrame.SetPerforatorList(ref perfoList, 0);
            frameList.AsTFFrame.SetSenseDistance2(length / 100, 0);
            frameList.AsTFFrame.SetPerforatorsAreActive(true, 0);


            int stat; // = tfApi.ModelReferenceAddFrameList(modelRef, ref frameList, 0);
            var frame = frameList.AsTFFrame;

            stat = tfApi.ModelReferenceUpdateAutoOpeningsByFrame(modelRef,
                                                                 ref frame, true, false, Bentley.Building.Api.TFdFramePerforationPolicy.tfdFramePerforationPolicyNone, 0);


            //Element cylindr;
            //brepList.GetElement(out cylindr, 0, "");

            //cylindr.AddToModel();

            //Element tfElement;
            //Element perfo = null;
            //Element dp_2d = null;
            //int value;
            //tfApi.ModelReferenceAddElement(ref cylindr, Session.Instance.GetActiveDgnModel(),
            //    0, 0, out value);

            //tfApi.ModelReferenceConstructFrameElement(Session.Instance.GetActiveDgnModel(),
            //    0, ref cylindr, ref perfo, ref origin, ref dp_2d, "name", null,
            //    1, 0, false, null, false, task.Length, 0.00005, 0, out tfElement);

            //frameList.InitFromElement(cylindr, "");

            // frameList.AsTFFrame.Add3DElement(cylindr, 0);


            return(frameList);
        }
コード例 #2
0
 public static DMatrix3d ToDMatrix3d(this BCOM.Matrix3d rotation)
 {
     return(DMatrix3d.FromRows(rotation.RowX.ToDVector(),
                               rotation.RowY.ToDVector(), rotation.RowZ.ToDVector()));
 }
コード例 #3
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);
        }
        protected override void OnDynamicFrame(Bentley.DgnPlatformNET.DgnButtonEvent ev)
        {
            try
            {
                if (PolyhedraCE.StaticElement == null)
                {
                    if (!string.IsNullOrEmpty(PolyhedronName))
                    {
                        if (PolyhedraCE.ListOfPolyhedra.ContainsKey(PolyhedronName))
                        {
                            BPSUtilities.WriteLog($"Found cell for '{PolyhedronName}'");
                            PolyhedraCE.StaticElement = PolyhedraCE.ListOfPolyhedra[PolyhedronName];
                        }
                        else
                        {
                            m_haveFirstPoint = false;
                            BPSUtilities.WriteLog($"Cell for '{PolyhedronName}' not found.");
                            this.EndDynamics();
                        }
                    }
                    else
                    {
                        BPSUtilities.WriteLog("Polyhedron Name not set.");
                        m_haveFirstPoint = false;
                        this.EndDynamics();
                    }
                }

                try
                {
                    Bentley.DgnPlatformNET.Elements.CellHeaderElement cellElem = (Bentley.DgnPlatformNET.Elements.CellHeaderElement)(PolyhedraCE.StaticElement);
                    if (cellElem.CellName != PolyhedronName)
                    {
                        BPSUtilities.WriteLog($"Current cell is {cellElem.CellName}");

                        if (!string.IsNullOrEmpty(PolyhedronName))
                        {
                            if (PolyhedraCE.ListOfPolyhedra.ContainsKey(PolyhedronName))
                            {
                                BPSUtilities.WriteLog($"Found cell for '{PolyhedronName}'");

                                if (PolyhedraCE.StaticElement != null)
                                {
                                    PolyhedraCE.StaticElement.Dispose();
                                }

                                PolyhedraCE.StaticElement = PolyhedraCE.ListOfPolyhedra[PolyhedronName];
                            }
                            else
                            {
                                m_haveFirstPoint = false;
                                BPSUtilities.WriteLog($"Cell for '{PolyhedronName}' not found.");
                                this.EndDynamics();
                            }
                        }
                        else
                        {
                            BPSUtilities.WriteLog("Polyhedron Name not set.");
                            m_haveFirstPoint = false;
                            this.EndDynamics();
                        }
                    }
                }
                catch (Exception ex)
                {
                    BPSUtilities.WriteLog($"Error casting cell {ex.Message}");
                }

                if (PolyhedraCE.StaticElement != null)
                {
                    RedrawElems redrawElems = new RedrawElems();
                    redrawElems.SetDynamicsViewsFromActiveViewSet(Bentley.MstnPlatformNET.Session.GetActiveViewport());
                    redrawElems.DrawMode    = DgnDrawMode.TempDraw;
                    redrawElems.DrawPurpose = DrawPurpose.Dynamics;

                    try
                    {
                        DMatrix3d invertedViewportRotation = new DMatrix3d(1, 0, 0, 0, 1, 0, 0, 0, 1);   // Identity

                        if (ev.Viewport.GetRotation().TryInvert(out invertedViewportRotation))
                        {
                            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>();

                            foreach (Bentley.DgnPlatformNET.Elements.Element child in PolyhedraCE.StaticElement.GetChildren())
                            {
                                listChildElements.Add(child);
                            }

                            Bentley.DgnPlatformNET.Elements.CellHeaderElement copiedElement = new CellHeaderElement(Session.Instance.GetActiveDgnModel(), PolyhedronName,
                                                                                                                    new DPoint3d(0, 0, 0), cellRotation, listChildElements);

                            if (copiedElement != null)
                            {
                                if (copiedElement.IsValid)
                                {
                                    if (!m_haveFirstPoint)
                                    {
                                        DPoint3d translation = ev.Point;

                                        DMatrix3d viewMatrix = ev.Viewport.GetRotation();

                                        DPoint3d[] blkPts = new DPoint3d[4];

                                        DPoint3d low = DPoint3d.Zero, high = DPoint3d.Zero;

                                        ev.Viewport.GetViewCorners(out low, out high);

                                        // rotate points to orthogonal
                                        blkPts[0] = new DPoint3d(viewMatrix.Multiply(new DVector3d(low)));

                                        blkPts[2] = new DPoint3d(viewMatrix.Multiply(new DVector3d(high)));

                                        blkPts[2].Z = blkPts[0].Z;

                                        DPoint3d ext = DPoint3d.Subtract(blkPts[2], blkPts[0]);

                                        double dScale = Math.Max(0.15 * Math.Abs(ext.Magnitude / uorPerMaster()), 1.0);

                                        DPoint3d dPtScale = ev.Viewport.GetScale();

                                        // dScale = dPtScale.Magnitude;

                                        // BPSUtilities.WriteLog($"Scale: {dScale}, View: {ev.ViewNumber}");

                                        invertedViewportRotation.ScaleInPlace(dScale);

                                        // works
                                        DTransform3d translateAndRotateToUpInViewWithViewBasedScale =
                                            DTransform3d.FromMatrixAndTranslation(invertedViewportRotation, translation);

                                        TransformInfo transformInfo = new TransformInfo(translateAndRotateToUpInViewWithViewBasedScale);

                                        // works
                                        copiedElement.ApplyTransform(transformInfo);
                                    }
                                    else
                                    {
                                        // now to work on rotation and scale
                                        DPoint3d translation = m_firstPoint;

                                        DMatrix3d viewMatrix = ev.Viewport.GetRotation();

                                        DPoint3d[] blkPts = new DPoint3d[4];

                                        // rotate points to orthogonal
                                        blkPts[0] = new DPoint3d(viewMatrix.Multiply(new DVector3d(m_firstPoint)));

                                        blkPts[2] = new DPoint3d(viewMatrix.Multiply(new DVector3d(ev.Point)));

                                        blkPts[2].Z = blkPts[0].Z;

                                        DPoint3d ext = DPoint3d.Subtract(blkPts[2], blkPts[0]);

                                        DVector3d angleVec = new DVector3d(ext);

                                        double dScale = Math.Max(0.1, Math.Abs(ext.Magnitude / uorPerMaster()));

                                        invertedViewportRotation.ScaleInPlace(dScale);

                                        DMatrix3d scaleRotateInViewRotateAroundPoint = DMatrix3d.Multiply(invertedViewportRotation, DMatrix3d.Rotation(2, angleVec.AngleXY));

                                        DTransform3d translateAndRotatetoUpInViewAndScale =
                                            DTransform3d.FromMatrixAndTranslation(scaleRotateInViewRotateAroundPoint, translation);

                                        TransformInfo transformInfo2 = new TransformInfo(translateAndRotatetoUpInViewAndScale);

                                        copiedElement.ApplyTransform(transformInfo2);
                                    }

                                    redrawElems.DoRedraw(copiedElement);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        BPSUtilities.WriteLog($"{ex.Message}\n{ex.StackTrace}");
                    }
                    //    if (!m_haveFirstPoint)
                    //{
                    //    BPSUtilities.WriteLog("Don't have first point.");
                    //    // move it around on cursor
                    //    redrawElems.DoRedraw(GetTransformedElement(m_element, ev));
                    //}
                    //else
                    //{
                    //    BPSUtilities.WriteLog("Do have first point.");
                    //    redrawElems.DoRedraw(GetTransformedElement(m_element, ev));
                    //}
                }
                else
                {
                    BPSUtilities.WriteLog("Element is null");
                    this.EndDynamics();
                }
            }
            catch (Exception ex)
            {
                BPSUtilities.WriteLog($"OnDynamicFrame: {ex.Message}\n{ex.StackTrace}");
            }
        }
        protected override bool OnDataButton(DgnButtonEvent ev)
        {
            try
            {
                if (m_haveFirstPoint)
                {
                    // we're going to write the element

                    base.EndDynamics();

                    // now to work on rotation and scale
                    DPoint3d translation = m_firstPoint;

                    DMatrix3d viewMatrix = ev.Viewport.GetRotation();

                    DPoint3d[] blkPts = new DPoint3d[4];

                    // rotate points to orthogonal
                    blkPts[0] = new DPoint3d(viewMatrix.Multiply(new DVector3d(m_firstPoint)));

                    blkPts[2] = new DPoint3d(viewMatrix.Multiply(new DVector3d(ev.Point)));

                    blkPts[2].Z = blkPts[0].Z;

                    DPoint3d ext = DPoint3d.Subtract(blkPts[2], blkPts[0]);

                    DVector3d angleVec = new DVector3d(ext);

                    double dScale = Math.Max(0.1, Math.Abs(ext.Magnitude / uorPerMaster()));

                    //RedrawElems redrawElems = new RedrawElems();
                    //redrawElems.SetDynamicsViewsFromActiveViewSet(Bentley.MstnPlatformNET.Session.GetActiveViewport());
                    //redrawElems.DrawMode = DgnDrawMode.Normal;
                    //redrawElems.DrawPurpose = DrawPurpose.ForceRedraw;

                    try
                    {
                        DMatrix3d invertedViewportRotation = new DMatrix3d(1, 0, 0, 0, 1, 0, 0, 0, 1);   // Identity

                        if (ev.Viewport.GetRotation().TryInvert(out invertedViewportRotation))
                        {
                            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>();

                            foreach (Bentley.DgnPlatformNET.Elements.Element child in PolyhedraCE.StaticElement.GetChildren())
                            {
                                listChildElements.Add(child);
                            }

                            Bentley.DgnPlatformNET.Elements.CellHeaderElement copiedElement = new CellHeaderElement(Session.Instance.GetActiveDgnModel(), PolyhedronName,
                                                                                                                    new DPoint3d(0, 0, 0), cellRotation, listChildElements);

                            if (copiedElement != null)
                            {
                                if (copiedElement.IsValid)
                                {
                                    invertedViewportRotation.ScaleInPlace(dScale);

                                    DMatrix3d scaleRotateInViewRotateAroundPoint = DMatrix3d.Multiply(invertedViewportRotation, DMatrix3d.Rotation(2, angleVec.AngleXY));

                                    DTransform3d translateAndRotatetoUpInViewAndScale =
                                        DTransform3d.FromMatrixAndTranslation(scaleRotateInViewRotateAroundPoint, translation);

                                    TransformInfo transformInfo2 = new TransformInfo(translateAndRotatetoUpInViewAndScale);

                                    copiedElement.ApplyTransform(transformInfo2);

                                    copiedElement.AddToModel();

                                    BPSUtilities.WriteLog("Added element to model");

                                    RedrawElems redrawElems = new RedrawElems();
                                    redrawElems.SetDynamicsViewsFromActiveViewSet(ev.Viewport);
                                    redrawElems.DrawMode    = DgnDrawMode.Normal;
                                    redrawElems.DrawPurpose = DrawPurpose.ForceRedraw;

                                    redrawElems.DoRedraw(copiedElement);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        BPSUtilities.WriteLog($"OnDataBurron {ex.Message}\n{ex.StackTrace}");
                    }

                    m_haveFirstPoint = false;

                    m_firstPoint = new DPoint3d(0, 0, 0);

                    base.BeginDynamics();

                    return(true);
                }

                m_haveFirstPoint = true;

                m_firstPoint = ev.Point;

                base.BeginDynamics();
            }
            catch (Exception ex)
            {
                BPSUtilities.WriteLog($"OnDataButton {ex.Message}\n{ex.StackTrace}");
            }

            return(true);
        }
コード例 #7
0
        protected override void OnDynamicFrame(Bentley.DgnPlatformNET.DgnButtonEvent ev)
        {
            RedrawElems redrawElems = new RedrawElems();

            redrawElems.SetDynamicsViewsFromActiveViewSet(Bentley.MstnPlatformNET.Session.GetActiveViewport());
            redrawElems.DrawMode    = DgnDrawMode.TempDraw;
            redrawElems.DrawPurpose = DrawPurpose.Dynamics;

            try
            {
                DMatrix3d invertedViewportRotation = new DMatrix3d(1, 0, 0, 0, 1, 0, 0, 0, 1);   // Identity

                if (ev.Viewport.GetRotation().TryInvert(out invertedViewportRotation))
                {
                    if (CodeElement != null)
                    {
                        if (CodeElement.IsValid)
                        {
                            List <Bentley.DgnPlatformNET.Elements.Element> listChildElements = CodeElement.GetChildren().GetEnumerator().ConvertToList();

                            Bentley.DgnPlatformNET.Elements.CellHeaderElement codeElement = new CellHeaderElement(Session.Instance.GetActiveDgnModel(), "QRCode",
                                                                                                                  DPoint3d.Zero, DMatrix3d.Identity, listChildElements);

                            if (codeElement.IsValid)
                            {
                                if (m_haveFirstPoint)
                                {
                                    // now to work on rotation and scale
                                    DPoint3d translation = m_firstPoint;

                                    DMatrix3d viewMatrix = ev.Viewport.GetRotation();

                                    DPoint3d[] blkPts = new DPoint3d[4];

                                    // rotate points to orthogonal
                                    blkPts[0] = new DPoint3d(viewMatrix.Multiply(new DVector3d(m_firstPoint)));

                                    blkPts[2] = new DPoint3d(viewMatrix.Multiply(new DVector3d(ev.Point)));

                                    blkPts[2].Z = blkPts[0].Z;

                                    DPoint3d ext = DPoint3d.Subtract(blkPts[2], blkPts[0]);

                                    DVector3d angleVec = new DVector3d(ext);

                                    // double dScale = Math.Max(0.1, Math.Abs(ext.Magnitude / uorPerMaster()));

                                    invertedViewportRotation.ScaleInPlace(ext.Magnitude);

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

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

                                    Angle angle = Angle.Zero;

                                    //// UR and LR
                                    if (angleVec.AngleTo(xVec).Radians >= 0.0 && angleVec.AngleTo(xVec).Radians <= (Angle.PI.Radians / 2.0))
                                    {
                                        if (angleVec.AngleTo(yVec).Radians >= 0.0 && angleVec.AngleTo(yVec).Radians <= (Angle.PI.Radians / 2.0))
                                        {
                                            angle = Angle.Zero;
                                        }
                                        else
                                        {
                                            angle.Radians = Angle.NEGATIVE_PI.Radians / 2.0;
                                        }
                                    }
                                    // UL and LL
                                    else
                                    {
                                        if (angleVec.AngleTo(yVec).Radians >= 0.0 && angleVec.AngleTo(yVec).Radians <= (Angle.PI.Radians / 2.0))
                                        {
                                            angle.Radians = Angle.PI.Radians / 2.0;
                                        }
                                        else
                                        {
                                            angle.Radians = Angle.PI.Radians;
                                        }
                                    }

                                    DMatrix3d scaleRotateInViewRotateAroundPoint = DMatrix3d.Multiply(invertedViewportRotation,
                                                                                                      // DMatrix3d.Rotation(2, angleVec.AngleXY));
                                                                                                      DMatrix3d.Rotation(2, angle));

                                    // DMatrix3d scaleRotateInViewRotateAroundPoint = DMatrix3d.Multiply(invertedViewportRotation,
                                    // DMatrix3d.Rotation(2, angleVec.AngleXY));

                                    DTransform3d translateAndRotatetoUpInViewAndScale =
                                        DTransform3d.FromMatrixAndTranslation(scaleRotateInViewRotateAroundPoint, translation);

                                    TransformInfo transformInfo2 = new TransformInfo(translateAndRotatetoUpInViewAndScale);

                                    codeElement.ApplyTransform(transformInfo2);

                                    // below works great for drawing a block
                                    //DPoint3d[] blkPts = new DPoint3d[4];

                                    //DMatrix3d viewMatrix = ev.Viewport.GetRotation();

                                    //// rotate points to orthogonal
                                    //blkPts[0] = new DPoint3d(viewMatrix.Multiply(new DVector3d(m_firstPoint)));

                                    //blkPts[2] = new DPoint3d(viewMatrix.Multiply(new DVector3d(ev.Point)));

                                    //blkPts[2].Z = blkPts[0].Z;

                                    //blkPts[1].X = blkPts[0].X;
                                    //blkPts[1].Y = blkPts[2].Y;
                                    //blkPts[1].Z = blkPts[0].Z;

                                    //blkPts[3].X = blkPts[2].X;
                                    //blkPts[3].Y = blkPts[0].Y;
                                    //blkPts[3].Z = blkPts[0].Z;

                                    //DVector3d dVec = new DVector3d(blkPts[0], blkPts[2]);

                                    //double dWidth = blkPts[0].Distance(blkPts[1]);
                                    //double dHeight = blkPts[0].Distance(blkPts[3]);

                                    //double dDelta = Math.Abs(dWidth);

                                    //if (Math.Abs(dHeight) > Math.Abs(dWidth))
                                    //    dDelta = Math.Abs(dHeight);

                                    //blkPts[3] = blkPts[2] = blkPts[1] = blkPts[0];

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

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

                                    //double xFactor = 1.0, yFactor = 1.0;

                                    //// UR and LR
                                    //if (dVec.AngleTo(xVec).Radians >= 0.0 && dVec.AngleTo(xVec).Radians <= (Angle.PI.Radians / 2.0))
                                    //{
                                    //    if (dVec.AngleTo(yVec).Radians >= 0.0 && dVec.AngleTo(yVec).Radians <= (Angle.PI.Radians / 2.0))
                                    //    {
                                    //        blkPts[2].X = blkPts[0].X + dDelta;
                                    //        blkPts[2].Y = blkPts[0].Y + dDelta;
                                    //    }
                                    //    else
                                    //    {
                                    //        blkPts[2].X = blkPts[0].X + dDelta;
                                    //        blkPts[2].Y = blkPts[0].Y - dDelta;
                                    //        yFactor = -1.0;
                                    //    }
                                    //}
                                    //// UL and LL
                                    //else
                                    //{
                                    //    if (dVec.AngleTo(yVec).Radians >= 0.0 && dVec.AngleTo(yVec).Radians <= (Angle.PI.Radians / 2.0))
                                    //    {
                                    //        blkPts[2].X = blkPts[0].X - dDelta;
                                    //        blkPts[2].Y = blkPts[0].Y + dDelta;
                                    //        xFactor = -1.0;
                                    //    }
                                    //    else
                                    //    {
                                    //        blkPts[2].X = blkPts[0].X - dDelta;
                                    //        blkPts[2].Y = blkPts[0].Y - dDelta;
                                    //        xFactor = -1.0;
                                    //        yFactor = -1.0;
                                    //    }
                                    //}

                                    //blkPts[1].X = blkPts[0].X;
                                    //blkPts[1].Y = blkPts[2].Y;
                                    //blkPts[1].Z = blkPts[0].Z;

                                    //blkPts[3].X = blkPts[2].X;
                                    //blkPts[3].Y = blkPts[0].Y;
                                    //blkPts[3].Z = blkPts[0].Z;

                                    //DPoint3d[] blkPts2 = new DPoint3d[4];

                                    //blkPts2[0] = blkPts2[1] = blkPts2[2] = blkPts2[3] = blkPts[0];

                                    //for (int i = 0; i < 4; i++)
                                    //{
                                    //    blkPts[i] = new DPoint3d(invertedViewportRotation.Multiply(new DVector3d(blkPts[i])));
                                    //}

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

                                    //blkPts2[0].X += (xFactor) * dDelta / 4.0;
                                    //blkPts2[0].Y += (yFactor) * dDelta / 4.0;

                                    //blkPts2[2].X += (xFactor) * 3.0 * (dDelta / 4.0);
                                    //blkPts2[2].Y += (yFactor) * 3.0 * (dDelta / 4.0);

                                    //blkPts2[1].X = blkPts2[0].X;
                                    //blkPts2[1].Y = blkPts2[2].Y;
                                    //blkPts2[1].Z = blkPts2[0].Z;

                                    //blkPts2[3].X = blkPts2[2].X;
                                    //blkPts2[3].Y = blkPts2[0].Y;
                                    //blkPts2[3].Z = blkPts2[0].Z;

                                    //for (int i = 0; i < 4; i++)
                                    //{
                                    //    blkPts2[i] = new DPoint3d(invertedViewportRotation.Multiply(new DVector3d(blkPts2[i])));
                                    //}

                                    //Bentley.DgnPlatformNET.Elements.ShapeElement shapeElement2 =
                                    //    new Bentley.DgnPlatformNET.Elements.ShapeElement(Session.Instance.GetActiveDgnModel(), null, blkPts2);

                                    //redrawElems.DoRedraw(shapeElement);
                                    //redrawElems.DoRedraw(shapeElement2);
                                }
                                else
                                {
                                    // picking something arbitrary to use as scale factor
                                    invertedViewportRotation.ScaleInPlace(Bentley.MstnPlatformNET.Settings.TextHeight);

                                    DTransform3d scaleAndRotateToUpInView = DTransform3d.FromMatrixAndTranslation(invertedViewportRotation, ev.Point);

                                    TransformInfo transformInfo = new TransformInfo(scaleAndRotateToUpInView);

                                    codeElement.ApplyTransform(transformInfo);
                                }

                                redrawElems.DoRedraw(codeElement);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                BPSUtilities.WriteLog($"{ex.Message}\n{ex.StackTrace}");
            }
        }
コード例 #8
0
        protected override bool OnDataButton(DgnButtonEvent ev)
        {
            try
            {
                if (m_haveFirstPoint)
                {
                    // we're going to write the element

                    base.EndDynamics();

                    if (CodeElement != null)
                    {
                        if (CodeElement.IsValid)
                        {
                            List <Bentley.DgnPlatformNET.Elements.Element> listChildElements = CodeElement.GetChildren().GetEnumerator().ConvertToList();

                            Bentley.DgnPlatformNET.Elements.CellHeaderElement codeElement = new CellHeaderElement(Session.Instance.GetActiveDgnModel(), "QRCode",
                                                                                                                  DPoint3d.Zero, DMatrix3d.Identity, listChildElements);

                            if (codeElement.IsValid)
                            {
                                DMatrix3d invertedViewportRotation = new DMatrix3d(1, 0, 0, 0, 1, 0, 0, 0, 1);   // Identity

                                if (ev.Viewport.GetRotation().TryInvert(out invertedViewportRotation))
                                {
                                    // now to work on rotation and scale
                                    DPoint3d translation = m_firstPoint;

                                    DMatrix3d viewMatrix = ev.Viewport.GetRotation();

                                    DPoint3d[] blkPts = new DPoint3d[4];

                                    // rotate points to orthogonal
                                    blkPts[0] = new DPoint3d(viewMatrix.Multiply(new DVector3d(m_firstPoint)));

                                    blkPts[2] = new DPoint3d(viewMatrix.Multiply(new DVector3d(ev.Point)));

                                    blkPts[2].Z = blkPts[0].Z;

                                    DPoint3d ext = DPoint3d.Subtract(blkPts[2], blkPts[0]);

                                    DVector3d angleVec = new DVector3d(ext);

                                    // double dScale = Math.Max(0.1, Math.Abs(ext.Magnitude / uorPerMaster()));

                                    invertedViewportRotation.ScaleInPlace(ext.Magnitude);

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

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

                                    Angle angle = Angle.Zero;

                                    //// UR and LR
                                    if (angleVec.AngleTo(xVec).Radians >= 0.0 && angleVec.AngleTo(xVec).Radians <= (Angle.PI.Radians / 2.0))
                                    {
                                        if (angleVec.AngleTo(yVec).Radians >= 0.0 && angleVec.AngleTo(yVec).Radians <= (Angle.PI.Radians / 2.0))
                                        {
                                            angle = Angle.Zero;
                                        }
                                        else
                                        {
                                            angle.Radians = Angle.NEGATIVE_PI.Radians / 2.0;
                                        }
                                    }
                                    // UL and LL
                                    else
                                    {
                                        if (angleVec.AngleTo(yVec).Radians >= 0.0 && angleVec.AngleTo(yVec).Radians <= (Angle.PI.Radians / 2.0))
                                        {
                                            angle.Radians = Angle.PI.Radians / 2.0;
                                        }
                                        else
                                        {
                                            angle.Radians = Angle.PI.Radians;
                                        }
                                    }

                                    DMatrix3d scaleRotateInViewRotateAroundPoint = DMatrix3d.Multiply(invertedViewportRotation,
                                                                                                      // DMatrix3d.Rotation(2, angleVec.AngleXY));
                                                                                                      DMatrix3d.Rotation(2, angle));

                                    DTransform3d translateAndRotatetoUpInViewAndScale =
                                        DTransform3d.FromMatrixAndTranslation(scaleRotateInViewRotateAroundPoint, translation);

                                    TransformInfo transformInfo2 = new TransformInfo(translateAndRotatetoUpInViewAndScale);

                                    codeElement.ApplyTransform(transformInfo2);

                                    //DPoint3d[] blkPts = new DPoint3d[4];

                                    //DMatrix3d viewMatrix = ev.Viewport.GetRotation();

                                    //// rotate points to orthogonal
                                    //blkPts[0] = new DPoint3d(viewMatrix.Multiply(new DVector3d(m_firstPoint)));

                                    //blkPts[2] = new DPoint3d(viewMatrix.Multiply(new DVector3d(ev.Point)));

                                    //blkPts[2].Z = blkPts[0].Z;

                                    //blkPts[1].X = blkPts[0].X;
                                    //blkPts[1].Y = blkPts[2].Y;
                                    //blkPts[1].Z = blkPts[0].Z;

                                    //blkPts[3].X = blkPts[2].X;
                                    //blkPts[3].Y = blkPts[0].Y;
                                    //blkPts[3].Z = blkPts[0].Z;

                                    //DVector3d dVec = new DVector3d(blkPts[0], blkPts[2]);

                                    //double dWidth = blkPts[0].Distance(blkPts[1]);
                                    //double dHeight = blkPts[0].Distance(blkPts[3]);

                                    //double dDelta = Math.Max(Math.Abs(dWidth), Math.Abs(dHeight));

                                    //blkPts[3] = blkPts[2] = blkPts[1] = blkPts[0];

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

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

                                    //// UR and LR
                                    //if (dVec.AngleTo(xVec).Radians >= 0.0 && dVec.AngleTo(xVec).Radians <= (Angle.PI.Radians / 2.0))
                                    //{
                                    //    if (dVec.AngleTo(yVec).Radians >= 0.0 && dVec.AngleTo(yVec).Radians <= (Angle.PI.Radians / 2.0))
                                    //    {
                                    //        blkPts[2].X = blkPts[0].X + dDelta;
                                    //        blkPts[2].Y = blkPts[0].Y + dDelta;
                                    //    }
                                    //    else
                                    //    {
                                    //        blkPts[2].X = blkPts[0].X + dDelta;
                                    //        blkPts[2].Y = blkPts[0].Y - dDelta;
                                    //    }
                                    //}
                                    //// UL and LL
                                    //else
                                    //{
                                    //    if (dVec.AngleTo(yVec).Radians >= 0.0 && dVec.AngleTo(yVec).Radians <= (Angle.PI.Radians / 2.0))
                                    //    {
                                    //        blkPts[2].X = blkPts[0].X - dDelta;
                                    //        blkPts[2].Y = blkPts[0].Y + dDelta;
                                    //    }
                                    //    else
                                    //    {
                                    //        blkPts[2].X = blkPts[0].X - dDelta;
                                    //        blkPts[2].Y = blkPts[0].Y - dDelta;
                                    //    }
                                    //}

                                    //blkPts[1].X = blkPts[0].X;
                                    //blkPts[1].Y = blkPts[2].Y;
                                    //blkPts[1].Z = blkPts[0].Z;

                                    //blkPts[3].X = blkPts[2].X;
                                    //blkPts[3].Y = blkPts[0].Y;
                                    //blkPts[3].Z = blkPts[0].Z;

                                    //for (int i = 0; i < 4; i++)
                                    //{
                                    //    blkPts[i] = new DPoint3d(invertedViewportRotation.Multiply(new DVector3d(blkPts[i])));
                                    //}

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

                                    RedrawElems redrawElems = new RedrawElems();
                                    redrawElems.SetDynamicsViewsFromActiveViewSet(Bentley.MstnPlatformNET.Session.GetActiveViewport());
                                    redrawElems.DrawMode    = DgnDrawMode.Normal;
                                    redrawElems.DrawPurpose = DrawPurpose.ForceRedraw;

                                    codeElement.AddToModel();

                                    redrawElems.DoRedraw(codeElement);

                                    m_haveFirstPoint = false;

                                    m_firstPoint = new DPoint3d(0, 0, 0);

                                    base.BeginDynamics();

                                    return(true);
                                }
                            }
                        }
                    }
                }
                else
                {
                    m_haveFirstPoint = true;

                    m_firstPoint = ev.Point;

                    // base.BeginDynamics();
                }
            }
            catch (Exception ex)
            {
                BPSUtilities.WriteLog($"OnDataButton {ex.Message}\n{ex.StackTrace}");
            }

            return(true);
        }
コード例 #9
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}");
            }
        }
コード例 #10
0
        public NodeUpdateResult PlaceParametricCell
        (
            NodeUpdateContext updateContext,
            [Replicatable, DgnModelProvider] IPoint PlacementPoint,
            [Replicatable] IPlane PlacementPlane,
            [In] string CellLibraryPath,
            [In] string CellDefinitionName,
            [In] string CellVariation,
            [Replicatable(-1, true)] string[] CellVariableNames,
            [Replicatable(-1, true)] string[] CellVariableValues
        )
        {
            this.ClearAndErase(updateContext); // Remove old feature
            
            if (this.ReplicationIndex == 0 && CellLibraryPath == null || CellDefinitionName == null)
            {
                return new NodeUpdateResult.IncompleteInputs(CellLibraryPath, CellDefinitionName);
            }
            else
            {
                //NEED TO IMPLEMENT A SHARED CELL UPDATE IF UpdateSharedCell == true; THEN ONCE UPDATED SET THE PARAMETER TO FALSE SO THAT THE NEXT PLACED CELL DOESN'T UPDATE THE SHARED CELL AGAIN
                //Check if cell library is attached and if not attach it
                if (this.ReplicationIndex == 0 && MSApp.IsCellLibraryAttached == false || MSApp.AttachedCellLibrary.FullName != CellLibraryPath)
                {
                    MSApp.AttachCellLibrary(CellLibraryPath);
                }
                
                DgnFile activeDgnFile = Session.Instance.GetActiveDgnFile();
                DgnModel activeModel = Session.Instance.GetActiveDgnModel();
                DgnModel cellModel = null;
                ParametricCellElement pCell = null;

                ParametricCellDefinitionElement cellDef = ParametricCellDefinitionElement.FindByName(CellDefinitionName, activeDgnFile);

                if (cellDef == null) //cell not in active file, load from attached cell library
                {
                    var opts = CellLibraryOptions.Include3d | CellLibraryOptions.IncludeAllLibraries | CellLibraryOptions.IncludeParametric;
                    var libs = new CellLibraryCollection(opts);

                    foreach (var lib in libs)
                    {
                        if (CellDefinitionName.Equals(lib.Name))
                        {
                            StatusInt status;
                            cellModel = lib.File.LoadRootModelById(out status, lib.File.FindModelIdByName(lib.Name), true, false, true);
                            break;
                        }
                    }

                    if (null == cellModel) //Cell definition (model) doesn't exist in the cell model file
                    {
                        LsBuilder lsBuilder = new LsBuilder();
                        Ls ls = lsBuilder.AppendLineLiteral("Error loading cell definition. Check cell definition name and library are correct.").ToLs();
                        return new NodeUpdateResult.TechniqueFailureMessage(ls);
                    }
                    else
                    {
                        var hdlr = DgnComponentDefinitionHandler.GetForModel(cellModel);
                        var status = hdlr.DefinitionModelHandler.CreateCellDefinition(activeDgnFile);

                        if (ParameterStatus.Success == status)
                            cellDef = ParametricCellDefinitionElement.FindByName(CellDefinitionName, activeDgnFile);
                        else
                        {
                            LsBuilder lsBuilder = new LsBuilder();
                            Ls ls = lsBuilder.AppendLineLiteral("Error creating cell definition in active file.").ToLs();
                            return new NodeUpdateResult.TechniqueFailureMessage(ls);
                        }
                    }
                }
                

                try
                {
                    pCell = ParametricCellElement.Create(cellDef, CellVariation, activeModel);

                    //Cell origin point - adjusted for U.O.R.
                    double uor = MSApp.ActiveModelReference.UORsPerMasterUnit;
                    DPoint3d cellOrigin = DPoint3d.Multiply(uor, PlacementPoint.GetDPoint3d());
                    pCell.Origin = cellOrigin;

                    DTransform3d dTransform3D = PlacementPlane.GetDTransform3d();
                    DPlane3d dPlane3D = PlacementPlane.GetDPlane3d();

                    DMatrix3d dMatrix3D = new DMatrix3d(dTransform3D);

                    pCell.Rotation = dMatrix3D;

                    //pCell.IsInvisible = true; //We don't want multiple elements visible
                    pCell.AddToModel(); //Add to the model so we can assign variables and retrieve the element

                    //Assign custom variables if they exist
                    if (CellVariableNames != null && CellVariableValues != null)
                    {
                        IECClass ecClass = pCell.Parameters.ClassDefinition;
                        IDgnECInstance eci = DgnECManager.FindECInstanceOnElement(pCell, ecClass);

                        for (int i = 0; i < CellVariableNames.Length; ++i)
                        {                            
                            IEnumerator<IECPropertyValue> props = eci.GetEnumerator(false, true);
                            
                            while (props.MoveNext())
                            {
                                if (props.Current.Property.DisplayLabel == CellVariableNames[i].ToString())
                                {
                                    props.Current.StringValue = CellVariableValues[i].ToString();
                                }
                            }
                        }
                        eci.WriteChanges();
                    }
                    
                    IElement ele = MSApp.ActiveModelReference.GetLastValidGraphicalElement();

                    SetElement(ele); //Commit as a GC feature
                    pCell.Dispose(); //Clean up the memory of pCell, only 'ele' will be retained
                }
                catch (Exception ex)
                {
                    return new NodeUpdateResult.TechniqueException(ex);
                }

                return NodeUpdateResult.Success;
            }
        }