Example #1
0
        /// <summary>
        ///     TODO
        /// </summary>
        /// <param name="acSol"></param>
        private void ReadEntity(Solid3d acSol, Database acCurDb, Transaction acTrans)
        {
            RcName       = acSol.GetPartName();
            ParentHandle = acSol.GetParent();
            ChildHandles = acSol.GetChildren();
            IsSweep      = acSol.GetIsSweep();
            IsMirror     = acSol.GetIsMirror();
            RcInfo       = acSol.GetPartInfo();
            RcQtyOf      = acSol.GetQtyOf();
            RcQtyTotal   = acSol.GetQtyTotal();
            TxDirection  = acSol.GetTextureDirection();

            GetRotationMatrices(acSol);
            GetLayMatrix(acSol);

            if (LayMatrix == new Matrix3d())
            {
                LayMatrix = GetAbstractMatrix(acSol);
            }

            using (var solCopy = acSol.Clone() as Solid3d)
            {
                if (solCopy != null)
                {
                    if (LayMatrix != Matrix3d.Identity)
                    {
                        solCopy.TransformBy(LayMatrix);
                    }

                    //Get Volume & Extents
                    Extents  = solCopy.GetBounds();
                    MinExt   = Extents.MinPoint;
                    MaxExt   = Extents.MaxPoint;
                    Centroid = solCopy.MassProperties.Centroid;
                    Box      = Extents.Volume();
                    Volume   = acSol.Volume();
                }
            }

            var identity = Matrix3d.Identity;

            if ((MaxExt.Z + MinExt.Z) / 2 < 0)
            {
                var vector3D = new Vector3d(0, 1, 0);
                identity   = Matrix3d.Rotation(3.14159265358979, vector3D, new Point3d());
                LayMatrix *= identity;
            }

            if (IsBox)
            {
                Asymmetry = 0;
            }
            else
            {
                var boxCen = GetBoxCenter(MinExt, MaxExt).RoundToTolerance();

                AsymmetryVector = boxCen.GetVectorTo(Centroid.RoundToTolerance());
                AsymmetryVector = AsymmetryVector.TransformBy(identity);
                Asymmetry       = AsymmetryVector.Length;

                if (!Asymmetry.IsLessThanTol())
                {
                    Asymmetry = Asymmetry.RoundToTolerance();
                }
                else
                {
                    Asymmetry = 0;
                }

                AsymmetryVector = AsymmetryVector.RoundToTolerance();

                if (Asymmetry > 0)
                {
                    FixMatrix(boxCen);
                }

                AsymString = AsymVStr(AsymmetryVector);
            }

            //Get length, width, thickness

            if (IsSweep)
            {
                //TODO
            }
            else
            {
                var measures = new List <double>(3)
                {
                    MaxExt.X - MinExt.X,
                    MaxExt.Y - MinExt.Y,
                    MaxExt.Z - MinExt.Z
                };

                measures.Sort();

                if (TxDirection == TextureDirection.Across)
                {
                    Width  = measures[2].RoundToTolerance();
                    Length = measures[1].RoundToTolerance();
                }
                else
                {
                    Length = measures[2].RoundToTolerance();
                    Width  = measures[1].RoundToTolerance();
                }

                Thickness = measures[0].RoundToTolerance();
            }

            //Add the XData
            acSol.AddXData(this, acCurDb, acTrans);
        }