Пример #1
0
        /*---------------------------------------------------------------------------------**//**
        * Actual modification on first data button if it lies on GroupedHole element.
        * @bsimethod                                                              Bentley Systems
        *  /*--------------+---------------+---------------+---------------+---------------+------*/
        protected override bool OnDataButton(Bentley.DgnPlatformNET.DgnButtonEvent ev)
        {
            //Locate an element.
            Bentley.DgnPlatformNET.HitPath hitPath = DoLocate(ev, true, 1);

            //If an element is located and the element is a grouped hole.
            //If element has a solid fill, remove it.
            //Else add a solid fill.
            if (null != hitPath)
            {
                int numHoles = PlaceGroupedHoleForm.GetNumberOfHoles();
                Bentley.DgnPlatformNET.Elements.Element element = hitPath.GetHeadElement();

                if (element is GroupedHoleElement)
                {
                    GroupedHoleElement groupedHoleElement = element as GroupedHoleElement;

                    uint fillColor;
                    bool alwaysFilled;
                    if (groupedHoleElement.GetSolidFill(out fillColor, out alwaysFilled))
                    {
                        groupedHoleElement.RemoveAreaFill();
                    }
                    else
                    {
                        groupedHoleElement.AddSolidFill((uint)Bentley.MstnPlatformNET.Settings.GetActiveFillColor().Index, false);
                    }

                    //Element must be replaced in model.
                    groupedHoleElement.ReplaceInModel(groupedHoleElement);
                }
            }

            return(true);
        }
Пример #2
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));
 }
Пример #3
0
 public static void CreateExtrudedSolid()
 {
     BG.CurveVector  curveVector  = BG.CurveVector.CreateDisk(new BG.DEllipse3d(BG.DPoint3d.Zero, BG.DVector3d.UnitX * 300, BG.DVector3d.UnitY * 200), BG.CurveVector.BoundaryType.Outer);
     BG.DgnExtrusion extrusion    = new Bentley.GeometryNET.DgnExtrusion(curveVector, BG.DVector3d.UnitZ * 200, true);
     BDE.Element     extrusionEle = BDE.DraftingElementSchema.ToElement(Program.GetActiveDgnModel(), extrusion, null);
     extrusionEle.AddToModel();
 }
Пример #4
0
        public static void CreateSphere()
        {
            BG.DgnSphereDetail sphereDetail = new Bentley.GeometryNET.DgnSphereDetail(BG.DPoint3d.Zero, 2000);
            var sphere = BG.SolidPrimitive.CreateDgnSphere(sphereDetail);

            BDE.Element sphereEle = BDE.DraftingElementSchema.ToElement(Program.GetActiveDgnModel(), sphere, null);
            sphereEle.AddToModel();
        }
Пример #5
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);
        }
Пример #6
0
        protected override bool OnDataButton(BD.DgnButtonEvent ev)
        {
            BD.HitPath hitPath = DoLocate(ev, true, 1);
            if (null != hitPath)
            {
                InstanceToWrite instanceInfo = (WriteInstanceOnElementView.Instance.DataContext as WriteInstanceOnElementViewModel).GetInstanceToWrite();
                if (string.IsNullOrEmpty(instanceInfo.SchemaName) || string.IsNullOrEmpty(instanceInfo.ClassName) || instanceInfo.Properties.Count == 0)
                {
                    mc.StatusPrompt = "请先选择要附加的class";
                    return(false);
                }
                BDEC.FindInstancesScope scope  = BDEC.FindInstancesScope.CreateScope(Program.GetActiveDgnFile(), new BDEC.FindInstancesScopeOption());
                BES.IECSchema           schema = BDEC.DgnECManager.Manager.LocateSchemaInScope(scope, instanceInfo.SchemaName, instanceInfo.MajorVersion, instanceInfo.MinorVersion, BES.SchemaMatchType.Exact);
                BDE.Element             ele    = hitPath.GetHeadElement();

                BES.ECClass class1 = schema.GetClass(instanceInfo.ClassName) as BES.ECClass;
                BDEC.DgnECInstanceEnabler instanceEnabler = BDEC.DgnECManager.Manager.ObtainInstanceEnabler(Program.GetActiveDgnFile(), class1);
                BEI.StandaloneECDInstance instance        = instanceEnabler.SharedWipInstance;
                foreach (var pInfo in instanceInfo.Properties)
                {
                    switch (pInfo.PropertyType.ToLower())
                    {
                    case "string":
                        instance.MemoryBuffer.SetStringValue(pInfo.PropertyName, -1, pInfo.GetValueAsString());
                        break;

                    case "boolean":
                        instance.MemoryBuffer.SetBooleanValue(pInfo.PropertyName, -1, pInfo.GetValueAsBoolean());
                        break;

                    case "int":
                        instance.MemoryBuffer.SetIntegerValue(pInfo.PropertyName, -1, pInfo.GetValueAsInt());
                        break;

                    case "double":
                        instance.MemoryBuffer.SetDoubleValue(pInfo.PropertyName, -1, pInfo.GetValueAsDouble());
                        break;
                    }
                }
                instanceEnabler.CreateInstanceOnElement(ele, instance, false);
                mc.StatusPrompt  = "附加完成";
                mc.StatusMessage = $"将{instanceInfo.ClassName}附加到ID:{ele.ElementId}物体上";
            }

            return(true);
        }
Пример #7
0
        public override List <string> GetSelectedObjects()
        {
            var objs = new List <string>();

            if (Model == null)
            {
                return(objs);
            }

            uint        numSelected = SelectionSetManager.NumSelected();
            DgnModelRef modelRef    = Session.Instance.GetActiveDgnModelRef();

            for (uint i = 0; i < numSelected; i++)
            {
                Bentley.DgnPlatformNET.Elements.Element el = null;
                SelectionSetManager.GetElement(i, ref el, ref modelRef);
                objs.Add(el.ElementId.ToString());
            }

            return(objs);
        }
Пример #8
0
 public override BD.StatusInt OnElementModify(BDE.Element element)
 {
     return(BD.StatusInt.Error);
 }
Пример #9
0
 public static void CreateDgnBox()
 {
     BG.DgnBox   box    = new BG.DgnBox(BG.DPoint3d.Zero, new BG.DPoint3d(100, 100, 100), BG.DVector3d.UnitX, BG.DVector3d.UnitY, 100, 100, 100, 100, true);
     BDE.Element boxEle = BDE.DraftingElementSchema.ToElement(Program.GetActiveDgnModel(), box, null);
     boxEle.AddToModel();
 }
        public CreatePolyhedronX64(int toolId, int prompt, string sPolyhedronName) : base(toolId, prompt)
        {
            try
            {
                // m_points = new List<DPoint3d>();

                PolyhedronName = sPolyhedronName;

                // string sXMLFileName = string.Empty;

                BPSUtilities.WriteLog($"CreatePolyhedronX64 Initialized '{PolyhedronName}'");

                string sOutputXML2 = Path.Combine(Path.GetTempPath(), $"{BPSUtilities.GetARandomString(8, BPSUtilities.LOWER_CASE)}.xml");

                if (PolyhedraCE.ListOfPolyhedra.Count == 0)
                {
                    string sOutputXML = Path.Combine(Path.GetTempPath(), $"{BPSUtilities.GetARandomString(8, BPSUtilities.LOWER_CASE)}.xml");

                    try
                    {
                        System.Reflection.Assembly thisExe = System.Reflection.Assembly.GetExecutingAssembly();

                        foreach (string sResName in thisExe.GetManifestResourceNames())
                        {
                            if (sResName.ToLower().EndsWith(".polyhedra.xml"))
                            {
                                using (var resourceStream = thisExe.GetManifestResourceStream(sResName))
                                {
                                    resourceStream.CopyTo(new System.IO.FileStream(sOutputXML, FileMode.Create));
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        BPSUtilities.WriteLog($"{ex.Message}\n{ex.StackTrace}");
                    }

                    File.Copy(sOutputXML, sOutputXML2);

                    try
                    {
                        XmlDocument xmlDoc = new XmlDocument();
                        xmlDoc.Load(sOutputXML2);

                        XmlNode root = xmlDoc.DocumentElement;

                        // need form to list available polyhedra

                        XmlNodeList nodeList = root.SelectNodes(".//polyhedron");

                        List <string> listPolyhedrons = new List <string>();

                        foreach (XmlNode node in nodeList)
                        {
                            string sPolyName = node.Attributes["name"].Value;
                            listPolyhedrons.Add(sPolyName);
                        }

                        foreach (string sPolyName in listPolyhedrons)
                        {
                            try
                            {
                                BPSUtilities.WriteLog($"Processing '{sPolyName}'...");

                                Bentley.DgnPlatformNET.Elements.Element elm = SetPolyhedron(sPolyName, sOutputXML2);

                                if (elm != null)
                                {
                                    PolyhedraCE.ListOfPolyhedra.AddWithCheck(sPolyName, elm);
                                    // elm.AddToModel();
                                    BPSUtilities.WriteLog($"Added '{sPolyName}'");
                                }
                                else
                                {
                                    BPSUtilities.WriteLog($"Error creating '{sPolyName}'");
                                }
                            }
                            catch (Exception ex)
                            {
                                BPSUtilities.WriteLog($"{ex.Message}\n{ex.StackTrace}");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        BPSUtilities.WriteLog($"{ex.Message}\n{ex.StackTrace}");
                    }
                }
                else
                {
                }

                BPSUtilities.WriteLog($"List contains {PolyhedraCE.ListOfPolyhedra.Count} entries.");

                BPSUtilities.WriteLog($"CreatePolyhedronX64: Dynamics {(this.DynamicsStarted ? "is" : "is not")} started.");
            }
            catch (Exception ex)
            {
                BPSUtilities.WriteLog($"CreatePolyhedronX64 {ex.Message}\n{ex.StackTrace}");
            }
        }
Пример #11
0
 /*---------------------------------------------------------------------------------**//**
 * All modification is done in OnDataButton method, just return Error from this method.
 * @bsimethod                                                              Bentley Systems
 *  /*--------------+---------------+---------------+---------------+---------------+------*/
 public override Bentley.DgnPlatformNET.StatusInt OnElementModify(Bentley.DgnPlatformNET.Elements.Element element)
 {
     return(Bentley.DgnPlatformNET.StatusInt.Error);
 }
Пример #12
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}");
            }
        }