示例#1
0
        private string UnitToSpeckle(UnitsValue units)
        {
            switch (units)
            {
            case UnitsValue.Millimeters:
                return(Units.Millimeters);

            case UnitsValue.Centimeters:
                return(Units.Centimeters);

            case UnitsValue.Meters:
                return(Units.Meters);

            case UnitsValue.Kilometers:
                return(Units.Kilometers);

            case UnitsValue.Inches:
                return(Units.Inches);

            case UnitsValue.Feet:
                return(Units.Feet);

            case UnitsValue.Yards:
                return(Units.Yards);

            case UnitsValue.Miles:
                return(Units.Miles);

            default:
                throw new System.Exception("The current Unit System is unsupported.");
            }
        }
 public double GetScaleRatio(UnitsValue sourceUnits, UnitsValue targetUnits)
 {
     if (sourceUnits == UnitsValue.Undefined || targetUnits == UnitsValue.Undefined ||
         !_linkBetweenDrawingUnitsAndMilimeters.ContainsKey(sourceUnits) ||
         !_linkBetweenDrawingUnitsAndMilimeters.ContainsKey(targetUnits))
     {
         return(1);
     }
     return(_linkBetweenDrawingUnitsAndMilimeters[sourceUnits]
            / _linkBetweenDrawingUnitsAndMilimeters[targetUnits]);
 }
示例#3
0
        public RegionMassProperties()
        {
            var scaleUnitsValue = UnitsValue.Millimeters;
            var sysUnits        =
                Application.GetSystemVariable("INSUNITS").ToString();

            switch (sysUnits)
            {
            case "1":
                scaleUnitsValue = UnitsValue.Inches;
                break;

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

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

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

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

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

            default:
                MessageBox.Show("\nUnits to scale inserted content: UNRECOGNIZED ?!", "units E R R O R");
                break;
            }
            AreaUnit    = scaleUnitsValue;
            IyUnit      = scaleUnitsValue;
            WyUpperUnit = scaleUnitsValue;
            WyLowerUnit = scaleUnitsValue;
            DUpperUnit  = scaleUnitsValue;
            DLowerUnit  = scaleUnitsValue;
            IyyUnit     = scaleUnitsValue;
            IzUnit      = scaleUnitsValue;
            WzRightUnit = scaleUnitsValue;
            WzLeftUnit  = scaleUnitsValue;
            DRightUnit  = scaleUnitsValue;
            DLeftUnit   = scaleUnitsValue;
            IzzUnit     = scaleUnitsValue;
            IminUnit    = scaleUnitsValue;
            ImaxUnit    = scaleUnitsValue;
        }
示例#4
0
        private static string AssemblyText(
            string name, double aP, UnitsValue uv, string grade, string scale, string format)
        {
            switch (uv)
            {
            case UnitsValue.Millimeters:
                scale = "mm";
                break;

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

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

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

            case UnitsValue.Inches:
                scale = "inch";
                break;

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

            default:
                throw new ArgumentException("Bad conversion unit in DrawText()!");
            }

            var rez = "{\\A0" + name + ":\\~" + aP.ToString(scale != "m" ? format : "") + "\\~" + scale + "\\S" + grade
                      + ";}\\P\n";

            return(rez);
        }
示例#5
0
文件: DxfGeoData.cs 项目: 15831944/WW
        public override void CopyFrom(DxfHandledObject from, CloneContext cloneContext)
        {
            base.CopyFrom(from, cloneContext);
            DxfGeoData dxfGeoData = (DxfGeoData)from;

            this.int_0 = dxfGeoData.int_0;
            this.designCoordinatesType_0 = dxfGeoData.designCoordinatesType_0;
            this.HostBlock               = Class906.smethod_0(cloneContext, dxfGeoData.HostBlock, false);
            this.point3D_0               = dxfGeoData.point3D_0;
            this.point3D_1               = dxfGeoData.point3D_1;
            this.vector2D_0              = dxfGeoData.vector2D_0;
            this.vector2D_1              = dxfGeoData.vector2D_1;
            this.unitsValue_0            = dxfGeoData.unitsValue_0;
            this.unitsValue_1            = dxfGeoData.unitsValue_1;
            this.vector3D_0              = dxfGeoData.vector3D_0;
            this.scaleEstimationMethod_0 = dxfGeoData.scaleEstimationMethod_0;
            this.bool_0   = dxfGeoData.bool_0;
            this.double_0 = dxfGeoData.double_0;
            this.double_1 = dxfGeoData.double_1;
            this.double_2 = dxfGeoData.double_2;
            this.string_0 = dxfGeoData.string_0;
            this.string_1 = dxfGeoData.string_1;
            this.string_2 = dxfGeoData.string_2;
            this.string_3 = dxfGeoData.string_3;
            this.string_4 = dxfGeoData.string_4;
            this.list_0.Clear();
            foreach (GeoMeshPoint geoMeshPoint in dxfGeoData.list_0)
            {
                this.list_0.Add(new GeoMeshPoint(geoMeshPoint.Source, geoMeshPoint.Destination));
            }
            this.list_1.Clear();
            foreach (GeoMeshFace geoMeshFace in dxfGeoData.list_1)
            {
                this.list_1.Add(new GeoMeshFace(geoMeshFace.FaceIndex1, geoMeshFace.FaceIndex2, geoMeshFace.FaceIndex3));
            }
        }
示例#6
0
        // Note: Difference between International Foot and US Foot is ~ 0.0000006 as described in: https://www.pobonline.com/articles/98788-us-survey-feet-versus-international-feet
        private string UnitToSpeckle(UnitsValue units)
        {
            switch (units)
            {
            case UnitsValue.Millimeters:
                return(Units.Millimeters);

            case UnitsValue.Centimeters:
                return(Units.Centimeters);

            case UnitsValue.Meters:
                return(Units.Meters);

            case UnitsValue.Kilometers:
                return(Units.Kilometers);

            case UnitsValue.Inches:
            case UnitsValue.USSurveyInch:
                return(Units.Inches);

            case UnitsValue.Feet:
            case UnitsValue.USSurveyFeet:
                return(Units.Feet);

            case UnitsValue.Yards:
            case UnitsValue.USSurveyYard:
                return(Units.Yards);

            case UnitsValue.Miles:
            case UnitsValue.USSurveyMile:
                return(Units.Miles);

            default:
                throw new Speckle.Core.Logging.SpeckleException($"The Unit System \"{units}\" is unsupported.");
            }
        }
        void tableRegDescr_CellPropertyChanged(object sender, XPTable.Events.CellEventArgs e)
        {
            // MessageBox.Show( e.CellPos.Column + "\n" + e.CellPos.Row + "\n" + e.Cell.Text + "\n" +  tableRegDescr.TableModel.Rows[e.CellPos.Row].Cells[0].Text + "\n" + e.OldValue);

            if (e.Column == 1)
            {
                if (tableRegDescr.TableModel.Rows[e.CellPos.Row].Cells[0].Text == " Density")
                {
                    RMS.Density = Convert.ToDouble(tableRegDescr.TableModel.Rows[15].Cells[1].Data);
                    RMS.G       = RMS.Density * RMS.LinearVolume;
                    tableRegDescr.TableModel.Rows[16].Cells[1].Data = RMS.G;
                    tableRegDescr.TableModel.Rows[17].Cells[1].Data = RMS.G;
                    tableRegDescr.TableModel.Rows[18].Cells[1].Data = RMS.G * 9.80665;
                }

                return;
            }

            UnitsValue UnitToConvertTo = UnitsValue.Millimeters;

            foreach (UnitsValue aUnit in Enum.GetValues(typeof(UnitsValue)))
            {
                if (aUnit.ToString() == e.Cell.Text)
                {
                    UnitToConvertTo = aUnit;
                }
            }

            string     checkStr        = tableRegDescr.TableModel.Rows[e.CellPos.Row].Cells[0].Text;
            UnitsValue scaleUnitsValue = UnitsValue.Millimeters;
            string     sysUnits        = (Application.GetSystemVariable("INSUNITS")).ToString();

            switch (sysUnits)
            {
            case "1":
                scaleUnitsValue = UnitsValue.Inches;
                break;

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

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

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

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

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

            default:
                MessageBox.Show("\nUnits to scale inserted content: UNRECOGNIZED ?!", "units E R R O R");
                break;
            }
            switch (checkStr.Remove(0, 1) /*tableRegDescr.TableModel.Rows[e.CellPos.Row].Cells[0].Text*/)
            {
            case "Area":
                RMS.AreaUnit = UnitToConvertTo;
                tableRegDescr.TableModel.Rows[0].Cells[1].Data = RMS.Area *
                                                                 Math.Pow(
                    UnitsConverter.GetConversionFactor(
                        scaleUnitsValue, RMS.AreaUnit), 2);
                break;

            case "Iy":
                RMS.IyUnit = UnitToConvertTo;
                tableRegDescr.TableModel.Rows[1].Cells[1].Data = RMS.Iy *
                                                                 Math.Pow(
                    UnitsConverter.GetConversionFactor(
                        scaleUnitsValue, RMS.IyUnit), 4);
                break;

            case "Wy_Upper":
                RMS.WyUpperUnit = UnitToConvertTo;
                tableRegDescr.TableModel.Rows[2].Cells[1].Data = RMS.WyUpper *
                                                                 Math.Pow(
                    UnitsConverter.GetConversionFactor(
                        scaleUnitsValue, RMS.WyUpperUnit), 3);
                break;

            case "Wy_Lower":
                RMS.WyLowerUnit = UnitToConvertTo;
                tableRegDescr.TableModel.Rows[3].Cells[1].Data = RMS.WyLower *
                                                                 Math.Pow(
                    UnitsConverter.GetConversionFactor(
                        scaleUnitsValue, RMS.WyLowerUnit), 3);
                break;

            case "D_Upper":
                RMS.DUpperUnit = UnitToConvertTo;
                tableRegDescr.TableModel.Rows[4].Cells[1].Data = RMS.DUpper *
                                                                 Math.Pow(
                    UnitsConverter.GetConversionFactor(
                        scaleUnitsValue, RMS.DUpperUnit), 1);
                break;

            case "D_Lower":
                RMS.DLowerUnit = UnitToConvertTo;
                tableRegDescr.TableModel.Rows[5].Cells[1].Data = RMS.DLower *
                                                                 Math.Pow(
                    UnitsConverter.GetConversionFactor(
                        scaleUnitsValue, RMS.DLowerUnit), 1);
                break;

            case "Iyy":
                RMS.IyyUnit = UnitToConvertTo;
                tableRegDescr.TableModel.Rows[6].Cells[1].Data = RMS.Iyy *
                                                                 Math.Pow(
                    UnitsConverter.GetConversionFactor(
                        scaleUnitsValue, RMS.IyyUnit), 1);
                break;

            case "Iz":
                RMS.IzUnit = UnitToConvertTo;
                tableRegDescr.TableModel.Rows[7].Cells[1].Data = RMS.Iz *
                                                                 Math.Pow(
                    UnitsConverter.GetConversionFactor(
                        scaleUnitsValue, RMS.IzUnit), 4);
                break;

            case "Wz_Right":
                RMS.WzRightUnit = UnitToConvertTo;
                tableRegDescr.TableModel.Rows[8].Cells[1].Data = RMS.WzRight *
                                                                 Math.Pow(
                    UnitsConverter.GetConversionFactor(
                        scaleUnitsValue, RMS.WzRightUnit), 3);
                break;

            case "Wz_Left":
                RMS.WzLeftUnit = UnitToConvertTo;
                tableRegDescr.TableModel.Rows[9].Cells[1].Data = RMS.WzLeft *
                                                                 Math.Pow(
                    UnitsConverter.GetConversionFactor(
                        scaleUnitsValue, RMS.WzLeftUnit), 3);
                break;

            case "D_Right":
                RMS.DRightUnit = UnitToConvertTo;
                tableRegDescr.TableModel.Rows[10].Cells[1].Data = RMS.DRight *
                                                                  Math.Pow(
                    UnitsConverter.GetConversionFactor(
                        scaleUnitsValue, RMS.DRightUnit), 1);
                break;

            case "D_Left":
                RMS.DLeftUnit = UnitToConvertTo;
                tableRegDescr.TableModel.Rows[11].Cells[1].Data = RMS.DLeft *
                                                                  Math.Pow(
                    UnitsConverter.GetConversionFactor(
                        scaleUnitsValue, RMS.DLeftUnit), 1);
                break;

            case "Izz":
                RMS.IzzUnit = UnitToConvertTo;
                tableRegDescr.TableModel.Rows[12].Cells[1].Data = RMS.Izz *
                                                                  Math.Pow(
                    UnitsConverter.GetConversionFactor(
                        scaleUnitsValue, RMS.IzzUnit), 1);
                break;

            case "Imin":
                RMS.IminUnit = UnitToConvertTo;
                tableRegDescr.TableModel.Rows[13].Cells[1].Data = RMS.Imin *
                                                                  Math.Pow(
                    UnitsConverter.GetConversionFactor(
                        scaleUnitsValue, RMS.IminUnit), 4);
                break;

            case "Imax":
                RMS.ImaxUnit = UnitToConvertTo;
                tableRegDescr.TableModel.Rows[14].Cells[1].Data = RMS.Imax *
                                                                  Math.Pow(
                    UnitsConverter.GetConversionFactor(
                        scaleUnitsValue, RMS.ImaxUnit), 4);
                break;
                // case "Density":
                // RMS.DensityUnit = UnitToConvertTo;
                //  break;
                //   case "G":
                //RMS.GUnit = UnitToConvertTo;
                //     break;
                //   case "LinearVolume":
                //     RMS.LinearVolumeUnit = UnitToConvertTo;
                //    break;
            }

            // RegionDescription.DrawText( ref RMS );
        }
示例#8
0
文件: DxfGeoData.cs 项目: 15831944/WW
        private bool method_13(DxfReader r, Class259 objectBuilder)
        {
            switch (r.CurrentGroup.Code)
            {
            case 10:
                this.point3D_0.X = (double)r.CurrentGroup.Value;
                goto case 93;

            case 11:
                this.point3D_1.X = (double)r.CurrentGroup.Value;
                goto case 93;

            case 12:
                this.vector2D_0.X = (double)r.CurrentGroup.Value;
                goto case 93;

            case 13:
                this.list_0.Add(new GeoMeshPoint(new WW.Math.Point2D((double)r.CurrentGroup.Value, 0.0), WW.Math.Point2D.Zero));
                goto case 93;

            case 14:
                if (this.list_0.Count > 0)
                {
                    GeoMeshPoint geoMeshPoint = this.list_0[this.list_0.Count - 1];
                    geoMeshPoint.Destination = new WW.Math.Point2D((double)r.CurrentGroup.Value, geoMeshPoint.Destination.Y);
                    goto case 93;
                }
                else
                {
                    this.list_0.Add(new GeoMeshPoint(WW.Math.Point2D.Zero, new WW.Math.Point2D((double)r.CurrentGroup.Value, 0.0)));
                    goto case 93;
                }

            case 20:
                this.point3D_0.Y = (double)r.CurrentGroup.Value;
                goto case 93;

            case 21:
                this.point3D_1.Y = (double)r.CurrentGroup.Value;
                goto case 93;

            case 22:
                this.vector2D_0.Y = (double)r.CurrentGroup.Value;
                goto case 93;

            case 23:
                if (this.list_0.Count > 0)
                {
                    GeoMeshPoint geoMeshPoint = this.list_0[this.list_0.Count - 1];
                    geoMeshPoint.Source = new WW.Math.Point2D(geoMeshPoint.Source.X, (double)r.CurrentGroup.Value);
                    goto case 93;
                }
                else
                {
                    this.list_0.Add(new GeoMeshPoint(new WW.Math.Point2D(0.0, (double)r.CurrentGroup.Value), WW.Math.Point2D.Zero));
                    goto case 93;
                }

            case 24:
                if (this.list_0.Count > 0)
                {
                    GeoMeshPoint geoMeshPoint = this.list_0[this.list_0.Count - 1];
                    geoMeshPoint.Destination = new WW.Math.Point2D(geoMeshPoint.Destination.X, (double)r.CurrentGroup.Value);
                    goto case 93;
                }
                else
                {
                    this.list_0.Add(new GeoMeshPoint(WW.Math.Point2D.Zero, new WW.Math.Point2D(0.0, (double)r.CurrentGroup.Value)));
                    goto case 93;
                }

            case 30:
                this.point3D_0.Z = (double)r.CurrentGroup.Value;
                goto case 93;

            case 31:
                this.point3D_1.Z = (double)r.CurrentGroup.Value;
                goto case 93;

            case 40:
                this.vector2D_1.X = (double)r.CurrentGroup.Value;
                goto case 93;

            case 41:
                this.vector2D_1.Y = (double)r.CurrentGroup.Value;
                goto case 93;

            case 70:
                this.designCoordinatesType_0 = (DesignCoordinatesType)(short)r.CurrentGroup.Value;
                goto case 93;

            case 90:
                this.int_0 = (int)r.CurrentGroup.Value;
                goto case 93;

            case 91:
                this.unitsValue_0 = (UnitsValue)r.CurrentGroup.Value;
                goto case 93;

            case 92:
                this.unitsValue_1 = (UnitsValue)r.CurrentGroup.Value;
                goto case 93;

            case 93:
            case 96:
                r.method_85();
                return(true);

            case 95:
                this.scaleEstimationMethod_0 = (ScaleEstimationMethod)r.CurrentGroup.Value;
                goto case 93;

            case 97:
                this.list_1.Add(new GeoMeshFace()
                {
                    FaceIndex1 = (int)r.CurrentGroup.Value
                });
                goto case 93;

            case 98:
                if (this.list_1.Count > 0)
                {
                    this.list_1[this.list_1.Count - 1].FaceIndex2 = (int)r.CurrentGroup.Value;
                    goto case 93;
                }
                else
                {
                    this.list_1.Add(new GeoMeshFace()
                    {
                        FaceIndex2 = (int)r.CurrentGroup.Value
                    });
                    goto case 93;
                }

            case 99:
                if (this.list_1.Count > 0)
                {
                    this.list_1[this.list_1.Count - 1].FaceIndex3 = (int)r.CurrentGroup.Value;
                    goto case 93;
                }
                else
                {
                    this.list_1.Add(new GeoMeshFace()
                    {
                        FaceIndex3 = (int)r.CurrentGroup.Value
                    });
                    goto case 93;
                }

            case 141:
                this.double_0 = (double)r.CurrentGroup.Value;
                goto case 93;

            case 142:
                this.double_1 = (double)r.CurrentGroup.Value;
                goto case 93;

            case 143:
                this.double_2 = (double)r.CurrentGroup.Value;
                goto case 93;

            case 210:
                this.vector3D_0.X = (double)r.CurrentGroup.Value;
                goto case 93;

            case 220:
                this.vector3D_0.Y = (double)r.CurrentGroup.Value;
                goto case 93;

            case 230:
                this.vector3D_0.Z = (double)r.CurrentGroup.Value;
                goto case 93;

            case 294:
                this.bool_0 = (bool)r.CurrentGroup.Value;
                goto case 93;

            case 301:
            case 303:
                this.string_0 += ((string)r.CurrentGroup.Value).Replace("^J", "\n");
                goto case 93;

            case 302:
                this.GeoRssTag = (string)r.CurrentGroup.Value;
                goto case 93;

            case 305:
                this.ObservationFromTag = (string)r.CurrentGroup.Value;
                goto case 93;

            case 306:
                this.ObservationToTag = (string)r.CurrentGroup.Value;
                goto case 93;

            case 307:
                this.ObservationCoverageTag = (string)r.CurrentGroup.Value;
                goto case 93;

            case 330:
                r.ModelBuilder.method_10((ulong)r.CurrentGroup.Value, (System.Action <DxfObjectReference>)(o => this.dxfObjectReference_3 = o));
                goto case 93;

            default:
                return(this.method_6(r, objectBuilder));
            }
        }
示例#9
0
文件: DxfGeoData.cs 项目: 15831944/WW
        internal override void Read(Class434 or, Class259 ob)
        {
            base.Read(or, ob);
            Interface30 objectBitStream = or.ObjectBitStream;

            this.int_0 = objectBitStream.imethod_11();
            or.Builder.method_10(objectBitStream.imethod_32(true), (System.Action <DxfObjectReference>)(o => this.dxfObjectReference_3 = o));
            this.designCoordinatesType_0 = (DesignCoordinatesType)objectBitStream.imethod_14();
            switch (this.int_0)
            {
            case 1:
                this.point3D_1    = objectBitStream.imethod_39();
                this.unitsValue_0 = (UnitsValue)objectBitStream.imethod_11();
                this.unitsValue_1 = this.unitsValue_0;
                this.point3D_0    = objectBitStream.imethod_39();
                objectBitStream.imethod_39();
                this.vector3D_0 = objectBitStream.imethod_51();
                this.vector2D_0 = Vector2D.FromAngle(System.Math.PI / 2.0 - objectBitStream.imethod_8());
                objectBitStream.imethod_39();
                this.string_0     = objectBitStream.ReadString();
                this.string_1     = objectBitStream.ReadString();
                this.vector2D_1.X = objectBitStream.imethod_8();
                this.vector2D_1.Y = this.vector2D_1.X;
                objectBitStream.ReadString();
                objectBitStream.ReadString();
                break;

            case 2:
            case 3:
                this.point3D_0               = objectBitStream.imethod_39();
                this.point3D_1               = objectBitStream.imethod_39();
                this.vector2D_1.X            = objectBitStream.imethod_8();
                this.unitsValue_0            = (UnitsValue)objectBitStream.imethod_11();
                this.vector2D_1.Y            = objectBitStream.imethod_8();
                this.unitsValue_1            = (UnitsValue)objectBitStream.imethod_11();
                this.vector3D_0              = objectBitStream.imethod_51();
                this.vector2D_0              = objectBitStream.imethod_50();
                this.scaleEstimationMethod_0 = (ScaleEstimationMethod)objectBitStream.imethod_11();
                this.double_0 = objectBitStream.imethod_8();
                this.bool_0   = objectBitStream.imethod_6();
                this.double_1 = objectBitStream.imethod_8();
                this.double_2 = objectBitStream.imethod_8();
                this.string_0 = objectBitStream.ReadString();
                this.string_1 = objectBitStream.ReadString();
                break;
            }
            this.string_2 = objectBitStream.ReadString();
            this.string_3 = objectBitStream.ReadString();
            this.string_4 = objectBitStream.ReadString();
            int num1 = objectBitStream.imethod_11();

            for (int index = 0; index < num1; ++index)
            {
                this.list_0.Add(new GeoMeshPoint(objectBitStream.imethod_38(), objectBitStream.imethod_38()));
            }
            int num2 = objectBitStream.imethod_11();

            for (int index = 0; index < num2; ++index)
            {
                this.list_1.Add(new GeoMeshFace(objectBitStream.imethod_11(), objectBitStream.imethod_11(), objectBitStream.imethod_11()));
            }
            if (this.int_0 != 1 || !objectBitStream.imethod_6())
            {
                return;
            }
            objectBitStream.imethod_6();
            objectBitStream.imethod_38();
            objectBitStream.imethod_38();
            objectBitStream.imethod_11();
            objectBitStream.imethod_11();
            objectBitStream.imethod_38();
            objectBitStream.imethod_38();
            objectBitStream.imethod_6();
            objectBitStream.imethod_8();
            objectBitStream.imethod_8();
            this.scaleEstimationMethod_0 = (ScaleEstimationMethod)objectBitStream.imethod_11();
            this.double_0 = objectBitStream.imethod_8();
            this.bool_0   = objectBitStream.imethod_6();
            this.double_1 = objectBitStream.imethod_8();
            this.double_2 = objectBitStream.imethod_8();
        }
示例#10
0
        /// <summary>
        /// Creates BlockReference from the block with the given name.
        /// Throws ArgumentException if block with such a name does not exist.
        /// </summary>
        /// <param name="blockName"></param>
        /// <param name="insertionPoint"></param>
        /// <param name="space">The model space or some of the paper spaces</param>
        /// <param name="blockTable">The block table of the associated drawing in the helper.</param>
        /// <returns>The BlockReference of the block</returns>
        private BlockReference CreateBlockReference(string blockName, UnitsValue sourceBlockMeasurementUnits, Point3d insertionPoint, BlockTableRecord space, BlockTable blockTable)
        {
            Matrix3d       ucs = _ed.CurrentUserCoordinateSystem;
            BlockReference newBlockReference;

            //All open objects opened during a transaction are closed at the end of the transaction.
            using (Transaction transaction = _db.TransactionManager.StartTransaction())
            {
                blockTable.UpgradeOpen();

                // If the DWG already contains this block definition we will create a block reference and not a copy of the same definition
                if (!blockTable.Has(blockName))
                {
                    _logger.Error(MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + MethodBase.GetCurrentMethod().Name + " : Block with name '" + blockName + "' does not exist.");
                    transaction.Abort();
                    throw new ArgumentException("Block with name '" + blockName + "' does not exist.");
                }

                BlockTableRecord sourceBlockTableRecord = (BlockTableRecord)transaction.GetObject(blockTable[blockName], OpenMode.ForRead);

                newBlockReference = new BlockReference(insertionPoint, sourceBlockTableRecord.ObjectId);

                var converter = new MeasurementUnitsConverter();

                var scaleFactor = converter.GetScaleRatio(sourceBlockMeasurementUnits, blockTable.Database.Insunits);

                _ed.CurrentUserCoordinateSystem = Matrix3d.Identity;
                newBlockReference.TransformBy(ucs);
                _ed.CurrentUserCoordinateSystem = ucs;

                newBlockReference.ScaleFactors = new Scale3d(scaleFactor);

                space.UpgradeOpen();
                space.AppendEntity(newBlockReference);
                transaction.AddNewlyCreatedDBObject(newBlockReference, true);

                AttributeCollection atcoll = newBlockReference.AttributeCollection;
                foreach (ObjectId subid in sourceBlockTableRecord)
                {
                    var entity = (Entity)subid.GetObject(OpenMode.ForRead);
                    var attributeDefinition = entity as AttributeDefinition;

                    if (attributeDefinition != null)
                    {
                        var attributeReference = new AttributeReference();

                        attributeReference.SetPropertiesFrom(attributeDefinition);
                        attributeReference.Visible = attributeDefinition.Visible;
                        attributeReference.SetAttributeFromBlock(attributeDefinition, newBlockReference.BlockTransform);
                        attributeReference.HorizontalMode = attributeDefinition.HorizontalMode;
                        attributeReference.VerticalMode   = attributeDefinition.VerticalMode;
                        attributeReference.Rotation       = attributeDefinition.Rotation;
                        attributeReference.Position       = attributeDefinition.Position + insertionPoint.GetAsVector();
                        attributeReference.Tag            = attributeDefinition.Tag;
                        attributeReference.FieldLength    = attributeDefinition.FieldLength;
                        attributeReference.TextString     = attributeDefinition.TextString;
                        attributeReference.AdjustAlignment(_db);
                        atcoll.AppendAttribute(attributeReference);
                        transaction.AddNewlyCreatedDBObject(attributeReference, true);
                    }
                }
                transaction.Commit();
            }
            _ed.Regen();

            return(newBlockReference);
        }
示例#11
0
        public RegionMassProperties(Region reg, double density)
        {
            var k = 1.0;
            var scaleUnitsValue = UnitsValue.Millimeters;
            var sysUnits        = Application.GetSystemVariable("INSUNITS").ToString();

            switch (sysUnits)
            {
            case "1":
                scaleUnitsValue = UnitsValue.Inches;
                k = 25.4;
                break;

            case "2":
                scaleUnitsValue = UnitsValue.Feet;
                k = 25.4 * 12.0;
                break;

            case "4":
                scaleUnitsValue = UnitsValue.Millimeters;
                k = 1.0;
                break;

            case "5":
                scaleUnitsValue = UnitsValue.Centimeters;
                k = 10.0;
                break;

            case "6":
                scaleUnitsValue = UnitsValue.Meters;
                k = 1000.0;
                break;

            case "14":
                scaleUnitsValue = UnitsValue.Decimeters;
                k = 100.0;
                break;

            default:
                MessageBox.Show("\nUnits to scale inserted content: UNRECOGNIZED ?!", "units E R R O R");
                break;
            }
            AreaUnit    = scaleUnitsValue;
            IyUnit      = scaleUnitsValue;
            WyUpperUnit = scaleUnitsValue;
            WyLowerUnit = scaleUnitsValue;
            DUpperUnit  = scaleUnitsValue;
            DLowerUnit  = scaleUnitsValue;
            IyyUnit     = scaleUnitsValue;
            IzUnit      = scaleUnitsValue;
            WzRightUnit = scaleUnitsValue;
            WzLeftUnit  = scaleUnitsValue;
            DRightUnit  = scaleUnitsValue;
            DLeftUnit   = scaleUnitsValue;
            IzzUnit     = scaleUnitsValue;
            IminUnit    = scaleUnitsValue;
            ImaxUnit    = scaleUnitsValue;

            // area
            Area = reg.Area;

            // Linear Volume
            Density      = density;
            LinearVolume = Area * k * k / (1000.0 * 1000.0);

            // weight G
            G = Density * LinearVolume;

            var Reg          = (AcadRegion)reg.AcadObject;
            var db           = Application.DocumentManager.MdiActiveDocument.Database;
            var tempCentroid = (double[])Reg.Centroid;

            MRegCentroid = new Point3d(tempCentroid[0], tempCentroid[1], 0.0);

            MMaxPoint = reg.GeometricExtents.MaxPoint;
            MMinPoint = reg.GeometricExtents.MinPoint;

            // Extents

            var maxZ = Math.Abs(reg.GeometricExtents.MaxPoint.Y - MRegCentroid.Y);
            var minZ = Math.Abs(reg.GeometricExtents.MinPoint.Y - MRegCentroid.Y);
            var maxY = Math.Abs(reg.GeometricExtents.MaxPoint.X - MRegCentroid.X);
            var minY = Math.Abs(reg.GeometricExtents.MinPoint.X - MRegCentroid.X);

            DUpper = maxZ;
            DLower = minZ;
            DRight = maxY;
            DLeft  = minY;

            using (var tr = db.TransactionManager.StartTransaction())
            {
                var origin = new Point3d(0, 0, 0);
                reg = (Region)tr.GetObject(reg.ObjectId, OpenMode.ForWrite);

                var acVec3D = MRegCentroid.GetVectorTo(origin);
                reg.TransformBy(Matrix3d.Displacement(acVec3D));

                Reg = (AcadRegion)reg.AcadObject;

                var principalMoments = (double[])Reg.PrincipalMoments;
                var momentOfInertia  = (double[])Reg.MomentOfInertia;

                // Y Moments
                Iy      = momentOfInertia[0];
                WyUpper = Iy / maxZ;
                WyLower = Iy / minZ;
                Iyy     = Math.Sqrt(Iy / Reg.Area);

                // Z Moments
                Iz      = momentOfInertia[1];
                WzRight = Iz / maxY;
                WzLeft  = Iz / minY;
                Izz     = Math.Sqrt(Iz / Reg.Area);


                // principal moments
                Imin = principalMoments[0];
                Imax = principalMoments[1];

                Reg.Erase();
                tr.Commit();
            }
        }