Esempio n. 1
0
 public RegionDescriptionForm(RegionMassProperties aRMS, Document doc)
 {
     InitializeComponent();
     RMS    = aRMS;
     bakRMS = aRMS;
     _doc   = doc;
 }
Esempio n. 2
0
        public static void Draw(ref RegionMassProperties regMassProps, string dimstyle)
        {
            using (var tr = Db.TransactionManager.StartTransaction())
            {
                var color = System.Drawing.Color.Red;
                DrawingHelper.LayerManipulator.CreateLayer("DIM", color);
                var acLine1 = new Line(
                    new Point3d(regMassProps.MRegCentroid.X, regMassProps.MRegCentroid.Y + 15.0, 0),
                    new Point3d(regMassProps.MRegCentroid.X, regMassProps.MRegCentroid.Y - 15.0, 0));
                var acLine2 = new Line(
                    new Point3d(regMassProps.MRegCentroid.X - 15.0, regMassProps.MRegCentroid.Y, 0),
                    new Point3d(regMassProps.MRegCentroid.X + 15.0, regMassProps.MRegCentroid.Y, 0));
                acLine1.Layer = "DIM";
                acLine2.Layer = "DIM";

                DrawingHelper.AddEntityDefinitionToCurrentSpace(acLine1, tr);
                DrawingHelper.AddEntityDefinitionToCurrentSpace(acLine2, tr);

                var acCirc = new Circle();
                acCirc.SetDatabaseDefaults();
                acCirc.Center = regMassProps.MRegCentroid;
                acCirc.Radius = 10.0;
                acCirc.Layer  = "DIM";
                DrawingHelper.AddEntityDefinitionToCurrentSpace(acCirc, tr);

                var c1 = new Complex(regMassProps.MRegCentroid.X, regMassProps.MMaxPoint.Y);
                var c2 = new Complex(regMassProps.MMaxPoint.X, regMassProps.MMaxPoint.Y);
                AddRegDescrDimLine(c1, c2, 50.0, dimstyle);

                c1 = new Complex(regMassProps.MRegCentroid.X, regMassProps.MMaxPoint.Y);
                c2 = new Complex(regMassProps.MMinPoint.X, regMassProps.MMaxPoint.Y);
                AddRegDescrDimLine(c2, c1, 50.0, dimstyle);

                c1 = new Complex(regMassProps.MMaxPoint.X, regMassProps.MRegCentroid.Y);
                c2 = new Complex(regMassProps.MMaxPoint.X, regMassProps.MMaxPoint.Y);
                AddRegDescrDimLine(c2, c1, 50.0, dimstyle);

                c1 = new Complex(regMassProps.MMaxPoint.X, regMassProps.MRegCentroid.Y);
                c2 = new Complex(regMassProps.MMaxPoint.X, regMassProps.MMinPoint.Y);
                AddRegDescrDimLine(c1, c2, 50.0, dimstyle);

                tr.Commit();
            }
            Ed.Regen();
        }
Esempio n. 3
0
        private void comboUnits_SelectedIndexChanged(object sender, EventArgs e)
        {
            RMS = bakRMS;
            ComboBox cb = (ComboBox)sender;
            int      N  = 0;
            double   k  = 1.0;

            switch (cb.Text)
            {
            case "Inches":
                N = 1;
                k = 25.4;
                break;

            case "Feet":
                N = 2;
                k = 12.0 * 25.4;
                break;

            case "Millimeters":
                N = 4;
                k = 1.0;
                break;

            case "Centimeters":
                N = 5;
                k = 10.0;
                break;

            case "Meters":
                N = 6;
                k = 1000.0;
                break;

            case "Decimeters":
                N = 14;
                k = 100.0;
                break;

            default:
                break;
            }
            RMS.Density      = Convert.ToDouble(tableRegDescr.TableModel.Rows[15].Cells[1].Data);
            RMS.LinearVolume = bakRMS.Area * k * k / (1000.0 * 1000.0);

            //MessageBox.Show(RMS.LinearVolume.ToString());

            RMS.G = RMS.Density * RMS.LinearVolume;

            Application.SetSystemVariable("INSUNITS", N);

            tableRegDescr.TableModel.Rows[0].Cells[1].Data  = RMS.Area;
            tableRegDescr.TableModel.Rows[1].Cells[1].Data  = RMS.Iy;
            tableRegDescr.TableModel.Rows[2].Cells[1].Data  = RMS.WyUpper;
            tableRegDescr.TableModel.Rows[3].Cells[1].Data  = RMS.WyLower;
            tableRegDescr.TableModel.Rows[4].Cells[1].Data  = RMS.DUpper;
            tableRegDescr.TableModel.Rows[5].Cells[1].Data  = RMS.DLower;
            tableRegDescr.TableModel.Rows[6].Cells[1].Data  = RMS.Iyy;
            tableRegDescr.TableModel.Rows[7].Cells[1].Data  = RMS.Iz;
            tableRegDescr.TableModel.Rows[8].Cells[1].Data  = RMS.WzRight;
            tableRegDescr.TableModel.Rows[9].Cells[1].Data  = RMS.WzLeft;
            tableRegDescr.TableModel.Rows[10].Cells[1].Data = RMS.DRight;
            tableRegDescr.TableModel.Rows[11].Cells[1].Data = RMS.DLeft;
            tableRegDescr.TableModel.Rows[12].Cells[1].Data = RMS.Izz;
            tableRegDescr.TableModel.Rows[13].Cells[1].Data = RMS.Imin;
            tableRegDescr.TableModel.Rows[14].Cells[1].Data = RMS.Imax;


            for (int i = 0; i < 15; i++)
            {
                tableRegDescr.TableModel.Rows[i].Cells[2].Text = cb.Text;
            }

            tableRegDescr.TableModel.Rows[16].Cells[1].Data = RMS.G;
            tableRegDescr.TableModel.Rows[17].Cells[1].Data = RMS.G;

            if (radioKg.Checked == true)
            {
                k = 1.0;
            }
            if (radioG.Checked == true)
            {
                k = 1.0 / 1000.0;
            }
            if (radioT.Checked == true)
            {
                k = 1000.0;
            }
            tableRegDescr.TableModel.Rows[18].Cells[1].Data = RMS.G * 9.80665 * k;
        }
Esempio n. 4
0
        public static void DrawText(ref RegionMassProperties aRms, string dU, string mU, Database db)
        {
            #region scale

            var scale           = "mm";
            var scaleUnitsValue = UnitsValue.Millimeters;
            var sysUnits        =
                Application.GetSystemVariable("INSUNITS").ToString();
            switch (sysUnits)
            {
            case "1":
                scale           = "inch";
                scaleUnitsValue = UnitsValue.Inches;
                break;

            case "2":
                scale           = "feet";
                scaleUnitsValue = UnitsValue.Feet;
                break;

            case "4":
                scale           = "mm";
                scaleUnitsValue = UnitsValue.Millimeters;
                break;

            case "5":
                scale           = "cm";
                scaleUnitsValue = UnitsValue.Centimeters;
                break;

            case "6":
                scale           = "m";
                scaleUnitsValue = UnitsValue.Meters;
                break;

            case "14":
                scale           = "dm";
                scaleUnitsValue = UnitsValue.Decimeters;
                break;

            default:
                MessageBox.Show("\nUnits to scale inserted content: UNRECOGNIZED ?!", "units E R R O R");
                break;
            }

            var format       = "f5";
            var mTextMessage = "";

            #endregion

            mTextMessage += AssemblyText(
                "Area",
                aRms.Area * Math.Pow(UnitsConverter.GetConversionFactor(scaleUnitsValue, aRms.AreaUnit), 2),
                aRms.AreaUnit,
                "2",
                scale,
                format);
            mTextMessage += AssemblyText(
                "Iy",
                aRms.Iy * Math.Pow(UnitsConverter.GetConversionFactor(scaleUnitsValue, aRms.IyUnit), 4),
                aRms.IyUnit,
                "4",
                scale,
                format);
            mTextMessage += AssemblyText(
                "Wy_Upper",
                aRms.WyUpper * Math.Pow(UnitsConverter.GetConversionFactor(scaleUnitsValue, aRms.WyUpperUnit), 3),
                aRms.WyUpperUnit,
                "3",
                scale,
                format);
            mTextMessage += AssemblyText(
                "Wy_Lower",
                aRms.WyLower * Math.Pow(UnitsConverter.GetConversionFactor(scaleUnitsValue, aRms.WyLowerUnit), 3),
                aRms.WyLowerUnit,
                "3",
                scale,
                format);
            mTextMessage += AssemblyText(
                "D_Upper",
                aRms.DUpper * Math.Pow(UnitsConverter.GetConversionFactor(scaleUnitsValue, aRms.DUpperUnit), 1),
                aRms.DUpperUnit,
                "",
                scale,
                format);
            mTextMessage += AssemblyText(
                "D_Lower",
                aRms.DLower * Math.Pow(UnitsConverter.GetConversionFactor(scaleUnitsValue, aRms.DLowerUnit), 1),
                aRms.DLowerUnit,
                "",
                scale,
                format);
            mTextMessage += AssemblyText(
                "Iyy",
                aRms.Iyy * Math.Pow(UnitsConverter.GetConversionFactor(scaleUnitsValue, aRms.IyyUnit), 1),
                aRms.IyyUnit,
                "",
                scale,
                format);
            mTextMessage += AssemblyText(
                "Iz",
                aRms.Iz * Math.Pow(UnitsConverter.GetConversionFactor(scaleUnitsValue, aRms.IzUnit), 4),
                aRms.IzUnit,
                "4",
                scale,
                format);
            mTextMessage += AssemblyText(
                "Wz_Right",
                aRms.WzRight * Math.Pow(UnitsConverter.GetConversionFactor(scaleUnitsValue, aRms.WzRightUnit), 3),
                aRms.WzRightUnit,
                "3",
                scale,
                format);
            mTextMessage += AssemblyText(
                "Wz_Left",
                aRms.WzLeft * Math.Pow(UnitsConverter.GetConversionFactor(scaleUnitsValue, aRms.WzLeftUnit), 3),
                aRms.WzLeftUnit,
                "3",
                scale,
                format);
            mTextMessage += AssemblyText(
                "D_Right",
                aRms.DRight * Math.Pow(UnitsConverter.GetConversionFactor(scaleUnitsValue, aRms.DRightUnit), 1),
                aRms.DRightUnit,
                "",
                scale,
                format);
            mTextMessage += AssemblyText(
                "D_Left",
                aRms.DLeft * Math.Pow(UnitsConverter.GetConversionFactor(scaleUnitsValue, aRms.DLeftUnit), 1),
                aRms.DLeftUnit,
                "",
                scale,
                format);
            mTextMessage += AssemblyText(
                "Izz",
                aRms.Izz * Math.Pow(UnitsConverter.GetConversionFactor(scaleUnitsValue, aRms.IzzUnit), 1),
                aRms.IzzUnit,
                "",
                scale,
                format);
            mTextMessage += AssemblyText(
                "Imin",
                aRms.Imin * Math.Pow(UnitsConverter.GetConversionFactor(scaleUnitsValue, aRms.IminUnit), 4),
                aRms.IminUnit,
                "4",
                scale,
                format);
            mTextMessage += AssemblyText(
                "Imax",
                aRms.Imax * Math.Pow(UnitsConverter.GetConversionFactor(scaleUnitsValue, aRms.ImaxUnit), 4),
                aRms.ImaxUnit,
                "4",
                scale,
                format);

            // Density
            var density = aRms.Density * UnitsConverter.GetConversionFactor(UnitsValue.Millimeters, aRms.DensityUnit);
            mTextMessage += "{\\A0Density:\\~" + density.ToString(scale != "m" ? format : "") + "\\~" + dU +
                            "\\S3;}\\P\n";

            // weight G
            var g = aRms.G * UnitsConverter.GetConversionFactor(UnitsValue.Millimeters, aRms.GUnit);
            mTextMessage += "{\\A0G:\\~" + g.ToString(scale != "m" ? format : "") + "\\~" + mU + "}\\P\n";
            Ed.WriteMessage(mTextMessage);

            // draw message
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var bt  = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                var btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                if (!_textId.IsNull && !_textId.IsErased)
                {
                    var regoinTextEnt = (Entity)tr.GetObject(_textId, OpenMode.ForWrite);
                    regoinTextEnt.Erase(true);
                }

                var regionText = new MText();
                regionText.SetDatabaseDefaults();
                regionText.Location = aRms.TextInsertionPoint;
                regionText.Width    = 1000;
                regionText.Height   = 1.2;
                regionText.Contents = mTextMessage + "\n";
                btr.AppendEntity(regionText);
                _textId = regionText.ObjectId;
                tr.AddNewlyCreatedDBObject(regionText, true);
                tr.Commit();
            }

            CommandLineHelper.Command("_REGEN");
        }
Esempio n. 5
0
        public void RegionDescriptionStart()
        {
            var sysUnits =
                Application.GetSystemVariable("INSUNITS").ToString();

            if ((sysUnits != "1") && (sysUnits != "2") && (sysUnits != "4") && (sysUnits != "5") && (sysUnits != "6") &&
                (sysUnits != "14"))
            {
                MessageBox.Show("\nUnits to scale inserted content: UNRECOGNIZED ?!", "units E R R O R");
                return;
            }

            // Prompt the user to select region mode - points or object
            //var regDescrModeOpts =new PromptKeywordOptions("\nSelect mode [Polylines And Circles/Regions/Block]", "PolylinesAndCircles Regions Block");
            var regDescrModeOpts = new PromptKeywordOptions("")
            {
                Message = "Select cross section mode:"
            };

            regDescrModeOpts.Keywords.Add("PolylinesAndCircles");
            regDescrModeOpts.Keywords.Add("Regions");
            regDescrModeOpts.Keywords.Add("Block");
            var regDescrModeRslt = Ed.GetKeywords(regDescrModeOpts);

            // If the user pressed cancel - return with no error
            if (regDescrModeRslt.Status != PromptStatus.OK)
            {
                return;
            }

            var myRegionColl = new DBObjectCollection();
            var objectsType  = typeof(bool);

            switch (regDescrModeRslt.StringResult)
            {
            case "PolylinesAndCircles":

                #region Contours Selection

                // Start a transaction
                using (var tr = Db.TransactionManager.StartTransaction())
                {
                    #region contour

                    // Request for objects to be selected in the drawing area       \
                    Ed.WriteMessage("\nSelect object describing outer contour");

                    //TypeVals.SetValue(new TypedValue((int)DxfCode.Start , "POLYLINE") , 0);
                    //TypeVals.SetValue(new TypedValue((int)DxfCode.Operator , "OR") , 1);
                    //TypeVals.SetValue(new TypedValue((int)DxfCode.Start , "CIRCLE") , 2);
                    // Assign the filter criteria to a SelectionFilter object
                    //SelectionFilter SelFilter = new SelectionFilter(TypeVals);

                    //PromptSelectionResult SSPrompt = Ed.GetSelection(SelFilter);
                    var ssPrompt = Ed.GetSelection();

                    // If the prompt status is OK, objects were selected
                    if (ssPrompt.Status == PromptStatus.OK)
                    {
                        var acSSet = ssPrompt.Value;

                        // Step through the objects in the selection set
                        var acDbObjColl = new DBObjectCollection();
                        foreach (SelectedObject acSsObj in acSSet)
                        {
                            // Check to make sure a valid SelectedObject object was returned
                            if (acSsObj == null)
                            {
                                continue;
                            }
                            // Open the selected object for write
                            var acEnt = tr.GetObject(acSsObj.ObjectId, OpenMode.ForWrite) as Entity;

                            if (acEnt != null)
                            {
                                acDbObjColl.Add(acEnt);
                            }
                            else
                            {
                                Ed.WriteMessage("Invalid input.");
                            }
                        }
                        myRegionColl = Region.CreateFromCurves(acDbObjColl);
                    }

                    #endregion

                    tr.Commit();
                }

                // If the user did not select any objects
                if (myRegionColl.Count == 0)
                {
                    return;
                }

                objectsType = typeof(Polyline);

                #endregion

                break;

            case "Regions":

                #region Regions Selection

                // Prompt for Regions
                var regionsSsOpts = new PromptSelectionOptions {
                    AllowDuplicates = false
                };

                //PromptEntityResult ObjectSelectionRslt = Ed.GetEntity(ObjectSelectionOpts);
                var regionsSsPrompt = Ed.GetSelection(regionsSsOpts);

                // If the prompt status is OK, objects were selected
                if (regionsSsPrompt.Status != PromptStatus.OK)
                {
                    return;
                }

                var regionsacSSet = regionsSsPrompt.Value;
                // Step through the objects in the selection set
                using (var tr = Db.TransactionManager.StartTransaction())
                {
                    var acDbObjColl = new DBObjectCollection();
                    foreach (SelectedObject acSsObj in regionsacSSet)
                    {
                        // Check to make sure a valid SelectedObject object was returned
                        if (acSsObj == null)
                        {
                            continue;
                        }
                        // Open the selected object for write
                        var acEnt = tr.GetObject(acSsObj.ObjectId, OpenMode.ForWrite) as Region;
                        if (acEnt != null)
                        {
                            var acDBObjColl_ = new DBObjectCollection();
                            acEnt.Explode(acDBObjColl_);
                            foreach (Entity acEntt in acDBObjColl_)
                            {
                                acDbObjColl.Add(acEntt);
                            }
                        }
                    }
                    myRegionColl = Region.CreateFromCurves(acDbObjColl);
                }

                // Dispatch function here

                #endregion

                objectsType = typeof(Region);
                break;

            case "Block":

                #region Block Selection

                // Ask the user to select a block

                var peo = new PromptEntityOptions("\nSelect a block:");
                peo.AllowNone = false;
                peo.SetRejectMessage("\nMust select a block.");
                peo.AddAllowedClass(typeof(BlockReference), false);

                var per = Ed.GetEntity(peo);
                if (per.Status != PromptStatus.OK)
                {
                    return;
                }


                using (var tr = Db.TransactionManager.StartTransaction())
                {
                    try
                    {
                        var ent = (Entity)tr.GetObject(per.ObjectId, OpenMode.ForRead);
                        var br  = ent as BlockReference;

                        if (br != null)
                        {
                            var btr =
                                (BlockTableRecord)tr.GetObject(br.BlockTableRecord, OpenMode.ForWrite);
                            var acDbObjColl = new DBObjectCollection();
                            foreach (var id in btr)
                            {
                                var ent2 = (Entity)tr.GetObject(id, OpenMode.ForWrite);
                                var str  = ent2.GetType().ToString().Split('.');
                                var Str  = str[str.Length - 1];

                                if (Str != "Polyline")
                                {
                                    if (Str == "Region")
                                    {
                                        var acEnt        = (Region)tr.GetObject(ent2.ObjectId, OpenMode.ForWrite);
                                        var acDBObjColl_ = new DBObjectCollection();
                                        acEnt.Explode(acDBObjColl_);
                                        foreach (Entity acEntt in acDBObjColl_)
                                        {
                                            acDbObjColl.Add(acEntt);
                                        }
                                    }
                                    else
                                    {
                                        acDbObjColl.Add(ent2);
                                    }
                                }
                                else
                                {
                                    var pl = ent2 as Polyline;
                                    if (pl != null)
                                    {
                                        if (pl.Closed)
                                        {
                                            acDbObjColl.Add(pl);
                                        }
                                        else
                                        {
                                            if ((pl.StartPoint.DistanceTo(pl.EndPoint) < 0.0000001) &&
                                                (Str == "Polyline"))
                                            {
                                                acDbObjColl.Add(pl);
                                            }
                                            else
                                            {
                                                MessageBox.Show("Not Closed PolyLine !");
                                            }
                                        }
                                    }
                                    else
                                    {
                                        var crl = ent2 as Circle;
                                        if (crl != null)
                                        {
                                            acDbObjColl.Add(crl);
                                        }
                                    }
                                }
                            }     //
                            myRegionColl = new DBObjectCollection();
                            myRegionColl = Region.CreateFromCurves(acDbObjColl);
                            var ori = new Point3d(0, 0, 0);
                            var pos = br.Position;
                            foreach (Region reg in myRegionColl)
                            {
                                var Reg = reg;
                                MoveRegionInOrigin(ref Reg, ref ori, ref pos);
                            }
                            tr.Commit();
                        }
                    }
                    catch (Exception e)
                    {
                        Ed.WriteMessage(e.ToString());
                    }
                }

                #endregion

                objectsType = typeof(BlockReference);
                break;
            }

            #region Density selection

            /*      PromptDoubleOptions DensityOptions = new PromptDoubleOptions( "Enter density [kg/m3] : " );
             * DensityOptions.UseDefaultValue = true;
             * DensityOptions.DefaultValue = Settings.Default.RegionDescrDensity;
             * PromptDoubleResult DensityResult = Ed.GetDouble( DensityOptions );
             * if ( DensityResult.Status != PromptStatus.OK )
             * {
             *  return;
             * }
             * else if ( DensityResult.Value == 0.0 )
             * {
             *  MessageBox.Show( "Density must be greater than zero!" );
             *  return;
             * }*/
            Settings.Default.RegionDescrDensity = 1000.0 /*DensityResult.Value*/;
            Settings.Default.Save();

            #endregion

            #region Insertion Point selection

            var insPointOptions = new PromptPointOptions("Pick insertion point : ");
            var insPointResult  = Ed.GetPoint(insPointOptions);
            if (insPointResult.Status != PromptStatus.OK)
            {
                return;
            }

            #endregion

            if (objectsType.Name == "Boolean")
            {
                MessageBox.Show("Error identifing type.");
                return;
            }
            using (var tr = Db.TransactionManager.StartTransaction())
            {
                var extractedRegion = ExtractRegionFromObjects(ref myRegionColl, tr);
                //RegMassProps = GetRegionMassProperties(ExtractedRegion);

                var regMassProps = new RegionMassProperties(extractedRegion, Settings.Default.RegionDescrDensity)
                {
                    TextInsertionPoint = insPointResult.Value
                };


                var rdForm = new RegionDescriptionForm(regMassProps, Ed.Document);
                rdForm.ShowDialog();
                if (rdForm.DialogResult == DialogResult.OK)
                {
                    _textId = new ObjectId();
                }

                tr.Commit();
            }
        }