//unit:nm
 double GetActiveModelBoundaryZ()
 {
     BD.DgnModel activemodel = Program.GetActiveDgnModel();
     BG.DRange3d modelrange;
     activemodel.GetRange(out modelrange);
     return(modelrange.Low.Z);
 }
 ///////////////////////////////////////////////////////////////////////////////////
 double masterPerUOR()
 {
     Bentley.DgnPlatformNET.DgnModel  oModel = Session.Instance.GetActiveDgnModel();
     Bentley.DgnPlatformNET.ModelInfo myModelInfo;
     myModelInfo = oModel.GetModelInfo();
     return(1 / myModelInfo.UorPerMaster);
 }
示例#3
0
 public void SelectedCellNameChanged()
 {
     if (cellDgnFile == null)
     {
         mc.ShowErrorMessage("未载入任何cell库文件", "未加载cell库文件", false);
         return;
     }
     BD.StatusInt loadStatusInt;
     BD.DgnModel  selecteDgnModel = cellDgnFile.LoadRootModelById(out loadStatusInt,
                                                                  cellDgnFile.FindModelIdByName(SelectCellName));
     if (BD.StatusInt.Success != selecteDgnModel.FillSections(BD.DgnModelSections.All))
     {
         mc.ShowErrorMessage($"无法填充{selecteDgnModel}模型", "无法填充模型", false);
         return;
     }
     BG.DRange3d selectedModelDRange3D;
     if (selecteDgnModel.GetRange(out selectedModelDRange3D) != BD.StatusInt.Success)
     {
         mc.ShowErrorMessage($"无法获得{selecteDgnModel}模型的范围", "无法获得模型范围", false);
         return;
     }
     MasterUnitTooltip = $"单位:{GetMasterUnit(selecteDgnModel)}";
     celluor           = selecteDgnModel.GetModelInfo().UorPerMaster;
     celluorMeter      = selecteDgnModel.GetModelInfo().UorPerMeter;
     UAxisOffset       = selectedModelDRange3D.XSize / celluor;
     VAxisOffset       = selectedModelDRange3D.YSize / celluor;
 }
示例#4
0
        public static void CreateElementLine(string unparsed)
        {
            BD.DgnModel activeDgnModel = Program.ActiveDgnModel;
            double      uorPerMe       = activeDgnModel.GetModelInfo().UorPerMaster;

            BDE.LineElement lineElement = new BDE.LineElement(activeDgnModel, null, new BG.DSegment3d(0, 0, 0, 1000 * uorPerMe, 1000 * uorPerMe, 1000 * uorPerMe));
            lineElement.AddToModel();
        }
示例#5
0
        public void OpenCellLib()
        {
            OpenFileDialog cellFileDialog = new OpenFileDialog()
            {
                Filter = Resources.CellLibraryFilter,
                Title  = "选择Cell库文件"
            };

            if (cellFileDialog.ShowDialog() == DialogResult.OK)
            {
                BD.DgnDocument cellFileDocument = BD.DgnDocument.CreateForLocalFile(cellFileDialog.FileName);
                BD.DgnFile     cellDgnFile      = BD.DgnFile.Create(cellFileDocument, BD.DgnFileOpenMode.ReadOnly).DgnFile;
                if (cellDgnFile == null)
                {
                    Prompt = Resources.PromptHeader + $"无法读取{cellFileDialog.FileName}的DgnDocument对象";
                    Status = Resources.StatusHeader + Resources.ErrorString;
                    return;
                }
                BD.StatusInt loadStatusInt;
                if (BD.DgnFileStatus.Success != cellDgnFile.LoadDgnFile(out loadStatusInt))
                {
                    Prompt = Resources.PromptHeader + "无法载入文件";
                    Status = Resources.StatusHeader + Resources.ErrorString;
                    return;
                }
                if (cellDgnFile.FillDictionaryModel() != BD.StatusInt.Success)
                {
                    Prompt = Resources.PromptHeader + "填充模型失败";
                    Status = Resources.StatusHeader + Resources.ErrorString;
                    return;
                }
                CellNameTypes.Clear();
                ElementProps.Clear();
                int index = 0;
                foreach (var modelindex in cellDgnFile.GetModelIndexCollection())
                {
                    BD.DgnModel model = cellDgnFile.LoadRootModelById(out loadStatusInt, modelindex.Id);
                    if (model != null && modelindex.CellPlacementOptions == BD.CellPlacementOptions.CanBePlacedAsCell)
                    {
                        CellNameTypes.Add(model.ModelName + "(" + model.GetModelInfo().CellType.ToString() + ")");
                        index++;
                    }
                }
                string filename;
                if (CellFunction.AttachLibrary(out filename, cellFileDialog.FileName, "") != BD.StatusInt.Success)
                {
                    Prompt = Resources.PromptHeader + "附加模型失败";
                    Status = Resources.StatusHeader + Resources.ErrorString;
                    return;
                }
                Prompt = Resources.PromptHeader + $"{cellFileDialog.SafeFileName}已载入!";
                Status = Resources.StatusHeader + Resources.SuccessString;
            }
        }
示例#6
0
        private void tb_Calculation_Click(object sender, RoutedEventArgs e)
        {
            // 需要传入的参数
            double volume, area, closureError, ixy, ixz, iyz;

            BG.DPoint3d centroid, moment, principalMoment, pricipalDirection;
            IntPtr      nativeEdp;

            BD.DgnModel activeModel   = Program.GetActiveDgnModel();
            double      uor_per_meter = activeModel.GetModelInfo().UorPerMeter;
            IntPtr      modelPtr      = activeModel.GetNative();

            BD.LevelCache levelCache = activeModel.GetLevelCache();
            //存储每层图层对应的工程量
            Dictionary <string, double> volumeByLevel = new Dictionary <string, double>();
            string eleLevelName;

            foreach (var ele in activeModel.GetGraphicElements())
            {
                if (0 != BentleyMarshal.mdlElmdscr_getByElemRef(out nativeEdp, ele.GetNativeElementRef(), modelPtr, 0, IntPtr.Zero))
                {
                    if (0 == BentleyMarshal.mdlMeasure_volumeProperties(out volume, out area, out closureError, out centroid, out moment, out ixy, out ixz, out iyz, out principalMoment, out pricipalDirection, nativeEdp, uor_per_meter / 10000))
                    {
                        eleLevelName = levelCache.GetLevel(ele.LevelId).Name;
                        if (!volumeByLevel.ContainsKey(eleLevelName))
                        {
                            volumeByLevel.Add(eleLevelName, 0);
                        }
                        volumeByLevel[eleLevelName] += volume / Math.Pow(uor_per_meter, 3);
                    }
                }
                //利用DoEvents强制循环队列,防止界面卡死
                Bentley.UI.Threading.DispatcherHelper.DoEvents();
            }

            foreach (var i in volumeByLevel)
            {
                result.Add(new QuantitiesByLevelResult()
                {
                    LevelName = i.Key, Quantities = Math.Round(i.Value, 2)
                });
            }

            lv_output.ItemsSource = result;
        }
示例#7
0
        public static void TestAsync()
        {
            Task t = new Task(async() =>
            {
                await Task.Delay(TimeSpan.FromSeconds(2));
                System.Windows.Forms.MessageBox.Show("Test!", "Ha", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
            });

            t.Start();
            BD.DgnModel activemodel = Program.GetActiveDgnModel();
            //Singleton mode
            BM.MessageCenter messageCenter = BM.MessageCenter.Instance;
            foreach (var levelHandle in activemodel.GetLevelCache().GetHandles())
            {
                messageCenter.ShowInfoMessage(levelHandle.DisplayName, levelHandle.Name + "_" + levelHandle.DisplayName, Bentley.MstnPlatformNET.MessageAlert.None);
            }
            System.Windows.Forms.MessageBox.Show("Test!", "Ha", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
        }
示例#8
0
        private string GetMasterUnit(BD.DgnModel inModel)
        {
            var    activeModelInfo = inModel.GetModelInfo();
            double UorPerMeter     = activeModelInfo.UorPerMeter;
            double UorPerMaster    = activeModelInfo.UorPerMaster;
            double TOLERANCE       = 1e-8;

            if (Math.Abs(UorPerMaster - UorPerMeter) < TOLERANCE)
            {
                return("m");
            }
            else if (Math.Abs(UorPerMaster - UorPerMeter / 10) < TOLERANCE)
            {
                return("dm");
            }
            else if (Math.Abs(UorPerMaster - UorPerMeter / 100) < TOLERANCE)
            {
                return("cm");
            }
            else if (Math.Abs(UorPerMaster - UorPerMeter / 1000) < TOLERANCE)
            {
                return("mm");
            }
            else if (Math.Abs(UorPerMaster - UorPerMeter * 1e-6) < TOLERANCE)
            {
                return("um");
            }
            else if (Math.Abs(UorPerMaster - UorPerMeter * 1000) < TOLERANCE)
            {
                return("km");
            }
            else
            {
                return("Unknown");
            }
        }
示例#9
0
        public static void CreateElementUniLine(string unparsed)
        {
            BD.DgnModel activeDgnModel = Program.ActiveDgnModel;
            double      uorPerMe       = activeDgnModel.GetModelInfo().UorPerMaster;
            var         lines          = new BG.DPoint3d[]
            {
                new BG.DPoint3d(0, 0),
                new BG.DPoint3d(100 * uorPerMe, 0),
                new BG.DPoint3d(100 * uorPerMe, 100 * uorPerMe),
                new BG.DPoint3d(0, 100 * uorPerMe),
            };
            var curvePri = BG.CurvePrimitive.CreateLineString(lines);

            BG.DEllipse3d circle    = BG.DEllipse3d.FromCenterRadiusXY(new BG.DPoint3d(50 * uorPerMe, 50 * uorPerMe), 10 * uorPerMe);
            var           curvePriC = BG.CurvePrimitive.CreateArc(circle);

            BG.CurveVector composeCurveVector = new BG.CurveVector(BG.CurveVector.BoundaryType.ParityRegion)
            {
                curvePri, curvePriC
            };
            var ele = BDE.DraftingElementSchema.ToElement(activeDgnModel, composeCurveVector, null);

            ele.AddToModel();
        }
示例#10
0
        public static void TestGetVolum()
        {
            double volume, area, closureError, ixy, ixz, iyz;

            Bentley.GeometryNET.DPoint3d centroid, moment, principalMoment, pricipalDirection;
            BD.DgnModel activemodel    = Program.GetActiveDgnModel();
            double      uor_per_master = activemodel.GetModelInfo().UorPerMaster;

            foreach (var item in activemodel.GetGraphicElements())
            {
                IntPtr nativeElePtr = item.GetNativeElementRef();
                IntPtr nativeEdp;
                IntPtr filePos = IntPtr.Zero;
                if (nativeElePtr != null)
                {
                    Marshal.BentleyMarshal.mdlElmdscr_getByElemRef(out nativeEdp, nativeElePtr, activemodel.GetNative(), 0, filePos);

                    if (0 == Marshal.BentleyMarshal.mdlMeasure_volumeProperties(out volume, out area, out closureError, out centroid, out moment, out ixy, out ixz, out iyz, out principalMoment, out pricipalDirection, nativeEdp, uor_per_master / 10))
                    {
                        BD.NotificationManager.OutputMessage(new BD.NotifyMessageDetails(Bentley.DgnPlatformNET.OutputMessagePriority.Information, volume.ToString(), volume.ToString(), BD.NotifyTextAttributes.DynamicScroll, BD.OutputMessageAlert.None));
                    }
                }
            }
        }