Пример #1
0
        /// <summary>
        /// ремешок с перфорацие
        /// </summary>
        /// <param name="WatchData">информация о часах</param>
        /// <returns>Модель часов</returns>
        public Solid3d BuildStrapWithPerforations(WatchData WatchData)
        {
            //модель ремешка с перфор.
            Solid3d StrapWithPerforations = new Solid3d();

            StrapWithPerforations.CreateBox(Length / 2, Width, 3);

            //сглаживаем углы.
            Solid3d StrapSmoother = new Solid3d();

            StrapSmoother.CreateFrustum(Width, _params[ParNames.StrapTransformByY], _params[ParNames.StrapTransformByY], _params[ParNames.StrapTransformByY]);
            StrapSmoother.TransformBy(Matrix3d.Rotation(Math.PI / 2, new Vector3d(1, 0, 0), Point3d.Origin));
            StrapSmoother.TransformBy(Matrix3d.Displacement(new Vector3d(Length / 4, 0, 0)));
            StrapWithPerforations.BooleanOperation(BooleanOperationType.BoolUnite, StrapSmoother.Clone() as Solid3d);

            StrapSmoother.CreateFrustum(Width, _params[ParNames.StrapTransformByY], _params[ParNames.StrapTransformByY], _params[ParNames.StrapTransformByY]);
            StrapSmoother.TransformBy(Matrix3d.Rotation(Math.PI / 2, new Vector3d(1, 0, 0), Point3d.Origin));
            StrapSmoother.TransformBy(Matrix3d.Displacement(new Vector3d(-Length / 4, 0, 0)));
            StrapWithPerforations.BooleanOperation(BooleanOperationType.BoolUnite, StrapSmoother.Clone() as Solid3d);

            //проделываем перфорации
            Solid3d HoleMaker = new Solid3d();

            for (int i = 0; i < NumberOfPerforations; i++)
            {
                HoleMaker.CreateFrustum(3, PerforationRadius, PerforationRadius, PerforationRadius);
                HoleMaker.TransformBy(Matrix3d.Displacement(new Vector3d((Length / 4 - 10) - (Length / 3) / NumberOfPerforations * i, 0, 0)));
                StrapWithPerforations.BooleanOperation(BooleanOperationType.BoolSubtract, HoleMaker.Clone() as Solid3d);
            }

            StrapWithPerforations.TransformBy(Matrix3d.Displacement(new Vector3d(WatchData.BodyDiameter + WatchData.BootstrapLength + (Length / 4) - 0.5, 0, 0)));


            return(StrapWithPerforations);
        }
Пример #2
0
        public static void FindInterferenceBetweenSolids()
        {
            // 获取当前文档和数据库,启动事务
            var acDoc   = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
            var acCurDb = acDoc.Database;

            using (var acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // 以读模式打开块表
                BlockTable acBlkTbl;
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                             OpenMode.ForRead) as BlockTable;

                // 以写模式打开块表记录模型空间
                BlockTableRecord acBlkTblRec;
                acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                OpenMode.ForWrite) as BlockTableRecord;

                // 创建3D箱体
                var acSol3DBox = new Solid3d();
                acSol3DBox.CreateBox(5, 7, 10);
                acSol3DBox.ColorIndex = 7;

                // 3D实体的中心点放在(5,5,0)
                acSol3DBox.TransformBy(Matrix3d.Displacement(new Point3d(5, 5, 0) -
                                                             Point3d.Origin));

                // 将新对象添加到块表记录和事务
                acBlkTblRec.AppendEntity(acSol3DBox);
                acTrans.AddNewlyCreatedDBObject(acSol3DBox, true);

                // 创建3D圆柱体
                // 默认构造函数的中心点为(0,0,0)
                var acSol3DCyl = new Solid3d();
                acSol3DCyl.CreateFrustum(20, 5, 5, 5);
                acSol3DCyl.ColorIndex = 4;

                // 将新对象添加到块表记录和事务
                acBlkTblRec.AppendEntity(acSol3DCyl);
                acTrans.AddNewlyCreatedDBObject(acSol3DCyl, true);

                // 用箱体和圆柱体的干涉创建一个3D实体
                var acSol3DCopy = acSol3DCyl.Clone() as Solid3d;

                // 检查箱体和圆柱体是否有重叠部分
                if (acSol3DCopy.CheckInterference(acSol3DBox))
                {
                    acSol3DCopy.BooleanOperation(BooleanOperationType.BoolIntersect,
                                                 acSol3DBox.Clone() as Solid3d);
                    acSol3DCopy.ColorIndex = 1;
                }

                // 将新对象添加到块表记录和事务
                acBlkTblRec.AppendEntity(acSol3DCopy);
                acTrans.AddNewlyCreatedDBObject(acSol3DCopy, true);

                // 提交事务
                acTrans.Commit();
            }
        }
Пример #3
0
        /// <summary>
        /// 由底面中心点、半径和高度在UCS中创建圆柱体
        /// </summary>
        /// <param name="bottomCenPt">底面中心点</param>
        /// <param name="radius">底面半径</param>
        /// <param name="height">高度</param>
        /// <returns>返回创建的圆柱体的Id</returns>
        public static ObjectId AddCylinder(Point3d bottomCenPt, double radius, double height)
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Editor   ed = Application.DocumentManager.MdiActiveDocument.Editor;

            if (radius < 0.00001 || Math.Abs(height) < 0.00001)
            {
                ed.WriteMessage("\n参数不当,创建圆柱体失败!");
                return(ObjectId.Null);
            }

            // 创建
            Solid3d ent = new Solid3d();

            ent.RecordHistory = true;
            ent.CreateFrustum(Math.Abs(height), radius, radius, radius);

            // 位置调整
            Point3d  cenPt = bottomCenPt + new Vector3d(0.0, 0.0, 0.5 * height);
            Matrix3d mt    = ed.CurrentUserCoordinateSystem;

            mt = mt * Matrix3d.Displacement(cenPt - Point3d.Origin);
            ent.TransformBy(mt);

            ObjectId entId = ObjectId.Null;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                entId = db.AddToModelSpace(ent);
                tr.Commit();
            }
            return(entId);
        }
Пример #4
0
        /// <summary>
        /// ремешок с замком
        /// </summary>
        /// <param name="WatchData">информация о часах</param>
        /// <returns>модель ремешка</returns>
        public Solid3d BuildStrapWithLocker(WatchData WatchData)
        {
            //модель ремешка с замком
            Solid3d StrapWithLocker = new Solid3d();

            StrapWithLocker.CreateBox(Length / _params[ParNames.StrapTransformByX], Width, 3);

            //сглаживания ремешка
            Solid3d StrapSmoother = new Solid3d();

            StrapSmoother.CreateFrustum(Width, _params[ParNames.StrapTransformByY], _params[ParNames.StrapTransformByY], _params[ParNames.StrapTransformByY]);
            StrapSmoother.TransformBy(Matrix3d.Rotation(Math.PI / _params[ParNames.StrapTransformByX], new Vector3d(1, 0, 0), Point3d.Origin));
            StrapSmoother.TransformBy(Matrix3d.Displacement(new Vector3d(Length / 4, 0, 0)));
            StrapWithLocker.BooleanOperation(BooleanOperationType.BoolUnite, StrapSmoother.Clone() as Solid3d);

            StrapSmoother.CreateFrustum(Width, _params[ParNames.StrapTransformByY], _params[ParNames.StrapTransformByX], _params[ParNames.StrapTransformByY]);
            StrapSmoother.TransformBy(Matrix3d.Rotation(Math.PI / _params[ParNames.StrapTransformByX], new Vector3d(1, 0, 0), Point3d.Origin));
            StrapSmoother.TransformBy(Matrix3d.Displacement(new Vector3d(-Length / 4, 0, 0)));
            StrapWithLocker.BooleanOperation(BooleanOperationType.BoolUnite, StrapSmoother.Clone() as Solid3d);

            //замок ремешка
            Solid3d Locker = new Solid3d();

            Locker.CreateBox(20, Width + _params[ParNames.StrapTransformByX], 4);
            Solid3d LockerHole = new Solid3d();

            LockerHole.CreateBox(18, Width, 4);
            LockerHole.TransformBy(Matrix3d.Displacement(new Vector3d(4, 0, 0)));
            Locker.BooleanOperation(BooleanOperationType.BoolSubtract, LockerHole.Clone() as Solid3d);

            //Дерджатель на замке
            Solid3d LockerPin = new Solid3d();

            LockerPin.CreateBox(20, WatchData.StrapPerforationRadius, _params[ParNames.StrapTransformByX]);
            Locker.BooleanOperation(BooleanOperationType.BoolUnite, LockerPin.Clone() as Solid3d);

            //передвигаем ремешок
            Locker.TransformBy(Matrix3d.Displacement(new Vector3d((-Length / 4) - 5, 0, 0)));
            StrapWithLocker.BooleanOperation(BooleanOperationType.BoolUnite, Locker.Clone() as Solid3d);
            StrapWithLocker.TransformBy(Matrix3d.Displacement(new Vector3d(-(WatchData.BodyDiameter + WatchData.BootstrapLength + (Length / 4) - 0.5), 0, 0)));

            //возвращаем модель ремешка

            return(StrapWithLocker);
        }
Пример #5
0
        /// <summary>
        /// Построить 3д солид-модель
        /// </summary>
        /// <param name="WatchData">Параметры часов</param>
        /// <returns>3Д - солид модель</returns>
        public Solid3d BuildCrown(WatchData WatchData)
        {
            //заводная головка
            Solid3d CrownPart = new Solid3d();

            CrownPart.CreateFrustum(Height, Diameter, Diameter, Diameter);

            //низ заводной головки
            Solid3d CrownBottom = new Solid3d();

            CrownBottom.CreateFrustum(1, Diameter, Diameter, Diameter - _pararameters[ParNames.CrownBottomHeight]);
            CrownBottom.TransformBy(Matrix3d.Displacement(new Point3d(0, 0, Height / _pararameters[ParNames.CrownTransformByZ] + _pararameters[ParNames.CrownTopHeight]) - Point3d.Origin));
            CrownPart.BooleanOperation(BooleanOperationType.BoolUnite, CrownBottom.Clone() as Solid3d);

            //вверх зав.головки
            Solid3d CrownTop = new Solid3d();

            CrownBottom.CreateFrustum(_pararameters[ParNames.CrownTopHeight], Diameter - _pararameters[ParNames.CrownTopHeight], Diameter - _pararameters[ParNames.CrownTopHeight], Diameter);
            CrownBottom.TransformBy(Matrix3d.Displacement(new Point3d(0, 0, -Height / _pararameters[ParNames.CrownTransformByZ] - 0.25) - Point3d.Origin));
            CrownPart.BooleanOperation(BooleanOperationType.BoolUnite, CrownBottom.Clone() as Solid3d);

            CrownBottom.CreateFrustum(_pararameters[ParNames.CrownTopHeight], Diameter - _pararameters[ParNames.CrownTopHeight], Diameter - _pararameters[ParNames.CrownTopHeight], Diameter - 1);
            CrownBottom.TransformBy(Matrix3d.Displacement(new Point3d(0, 0, -Height / _pararameters[ParNames.CrownTransformByZ] - _pararameters[ParNames.CrownTopHeight]) - Point3d.Origin));
            CrownPart.BooleanOperation(BooleanOperationType.BoolSubtract, CrownBottom.Clone() as Solid3d);

            //вырезаем цилиндры по радиусу зав. головки
            Solid3d CrownCutter = new Solid3d();

            CrownCutter.CreateFrustum(Height + _pararameters[ParNames.CrownBottomHeight], Diameter / _pararameters[ParNames.CrownCutterCount], Diameter / _pararameters[ParNames.CrownCutterCount], Diameter / _pararameters[ParNames.CrownCutterCount]);

            for (int i = 0; i < _pararameters[ParNames.CrownCutterCylinder]; i++)
            {
                CrownCutter.TransformBy(Matrix3d.Displacement(new Vector3d(Diameter * Math.Cos(Math.PI / 12 * i), Diameter * Math.Sin(Math.PI / 12 * i), 0)));
                CrownPart.BooleanOperation(BooleanOperationType.BoolSubtract, CrownCutter.Clone() as Solid3d);
                CrownCutter.TransformBy(Matrix3d.Displacement(new Vector3d(-Diameter * Math.Cos(Math.PI / 12 * i), -Diameter * Math.Sin(Math.PI / 12 * i), 0)));
            }

            CrownPart.TransformBy(Matrix3d.Rotation(Math.PI / 2, new Vector3d(1, 0, 0), Point3d.Origin));
            CrownPart.TransformBy(Matrix3d.Displacement(new Vector3d(0, WatchData.BodyDiameter + Height / _pararameters[ParNames.CrownTransformByZ] + _pararameters[ParNames.CrownBottomHeight], 0)));
            return(CrownPart);
        }
Пример #6
0
        public void CreateBoolSolid()
        {
            // 在内存中创建旋转截面对象.
            Solid3d ent1 = new Solid3d();
            Solid3d ent2 = new Solid3d();

            ent1.CreateBox(100, 60, 40);
            ent2.CreateFrustum(90, 20, 20, 20);
            // 差集操作.
            ent1.BooleanOperation(BooleanOperationType.BoolSubtract, ent2);
            ModelSpace.AppendEntity(ent1);
        }
Пример #7
0
        // 由中心点、半径和高度创建圆锥体的函数.
        public static ObjectId AddCone(Point3d cenPt, double radius, double height)
        {
            Solid3d ent = new Solid3d();

            ent.CreateFrustum(height, radius, radius, 0);
            Matrix3d mt = Matrix3d.Displacement(cenPt - Point3d.Origin);

            ent.TransformBy(mt);
            ObjectId entId = AppendEntity(ent);

            return(entId);
        }
Пример #8
0
        /// <summary>
        /// Строим стрелки
        /// </summary>
        /// <param name="WatchData">Информация о часах</param>
        /// <returns>модель стрелок</returns>
        private Solid3d BuildArrows(WatchData WatchData)
        {
            //стрелки
            Solid3d Arrows = new Solid3d();
            //база
            Solid3d Base = new Solid3d();

            //первая часть базы
            Base.CreateFrustum(_params[ParNames.BodyTransformByX] / 2, _params[ParNames.BodyTransformByZ], _params[ParNames.BodyTransformByZ], _params[ParNames.BodyTransformByZ]);
            Base.TransformBy(Matrix3d.Displacement(new Vector3d(0, 0, Height / 2 + _params[ParNames.BodyTransformByX] / 4)));
            Arrows.BooleanOperation(BooleanOperationType.BoolUnite, Base.Clone() as Solid3d);

            //вторая часть бызы
            Base.CreateFrustum(_params[ParNames.BodyTransformByX] / 2, _params[ParNames.BodyTransformByY], _params[ParNames.BodyTransformByY], _params[ParNames.BodyTransformByY]);
            Base.TransformBy(Matrix3d.Displacement(new Vector3d(0, 0, Height / 2 + _params[ParNames.BodyTransformByX] / 4 * 3)));
            Arrows.BooleanOperation(BooleanOperationType.BoolUnite, Base.Clone() as Solid3d);

            //часовая стрелка
            Solid3d Arrow = new Solid3d();

            Arrow.CreateBox(Diameter / 2, _params[ParNames.BodyTransformByY], _params[ParNames.BodyTransformByX] / 4);
            Arrow.TransformBy(Matrix3d.Displacement(new Vector3d(-(Diameter / 4), 0, Height / 2 + _params[ParNames.BodyTransformByX] / 4)));
            double TrueHour = System.DateTime.Now.Hour + ((double)System.DateTime.Now.Minute / 60);

            Arrow.TransformBy(Matrix3d.Rotation(-(Math.PI / 6 * TrueHour), new Vector3d(0, 0, 1), Point3d.Origin));
            Arrows.BooleanOperation(BooleanOperationType.BoolUnite, Arrow.Clone() as Solid3d);

            //минутная стрелка
            Arrow.CreateBox(Diameter / 2 + _params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTransformByX] + _params[ParNames.BodyTransformByX] / 5, _params[ParNames.BodyTransformByX] / 5);
            Arrow.TransformBy(Matrix3d.Displacement(new Vector3d(-(Diameter / 4), 0, Height / 2 + _params[ParNames.BodyTransformByX] / 4 * 3)));
            Arrow.TransformBy(Matrix3d.Rotation(-(Math.PI / 30 * System.DateTime.Now.Minute), new Vector3d(0, 0, 1), Point3d.Origin));
            Arrows.BooleanOperation(BooleanOperationType.BoolUnite, Arrow.Clone() as Solid3d);
            //секундная стрелка
            Arrow.CreateBox(Diameter / 2 + _params[ParNames.BodyBottomHeight], _params[ParNames.BodyTransformByX] / 2, _params[ParNames.BodyTransformByX] / 5);
            Arrow.TransformBy(Matrix3d.Displacement(new Vector3d(-(Diameter / _params[ParNames.BodyTopTransformByX]), 0, Height / 2 + _params[ParNames.BodyTransformByX] + _params[ParNames.BodyTransformByX] / 10)));
            Arrow.TransformBy(Matrix3d.Rotation(-(Math.PI / 30 * System.DateTime.Now.Second), new Vector3d(0, 0, 1), Point3d.Origin));
            Arrows.BooleanOperation(BooleanOperationType.BoolUnite, Arrow.Clone() as Solid3d);

            return(Arrows);
        }
Пример #9
0
        /// <summary>
        /// Функция построения вала
        /// </summary>
        /// <param name="database">База данных</param>
        /// <param name="Trans">Транзакция</param>
        /// <param name="parameters">Класс с параметрами построения мотора</param>
        public void Build(Database database, Transaction trans, MotorParameters parameters)
        {
            int diameretRotor = _diameretRotor;
            int lenRotor      = _lenRotor;
            int lenPin        = _lenPin;

            int lenBox = parameters.LenBox;

            // Открываем таблицу блоков для чтения
            BlockTable blockTable = trans.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable;

            // Открываем таблицу блоков модели для записи
            BlockTableRecord blockTableRecord = trans.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

            // Создам новый цилиндр
            Solid3d rotor = new Solid3d();

            rotor.SetDatabaseDefaults();
            rotor.CreateFrustum(lenRotor, diameretRotor / 2, diameretRotor / 2, diameretRotor / 2);
            rotor.ColorIndex = 4;

            // Позиция центра отрисовки обьекта
            rotor.TransformBy(Matrix3d.Displacement(new Point3d(0, -lenRotor / 2 - lenBox / 2, 0) - Point3d.Origin));

            double   angleRotate = Math.PI / 2;
            Vector3d vRotRotor   = new Point3d(0, 0, 0).GetVectorTo(new Point3d(1, 0, 0));

            rotor.TransformBy(Matrix3d.Rotation(angleRotate, vRotRotor, new Point3d(0, -lenRotor / 2 - lenBox / 2, 0)));

            // Добавляем новый обьект в таблицу блоков и отправляем на транзакцию
            blockTableRecord.AppendEntity(rotor);
            trans.AddNewlyCreatedDBObject(rotor, true);

            // Созать новую фигуру
            Solid3d pin = new Solid3d();

            pin.SetDatabaseDefaults();
            pin.CreateBox(diameretRotor / 10, lenPin, diameretRotor / 10);
            pin.ColorIndex = 7;

            // Позиция центра
            pin.TransformBy(Matrix3d.Displacement(new Point3d(0, -lenBox / 2 - lenRotor + lenPin / 2, diameretRotor / 2) - Point3d.Origin));

            // Добавляем новый обьект в таблицу блоков и отправляем на транзакцию
            blockTableRecord.AppendEntity(pin);
            trans.AddNewlyCreatedDBObject(pin, true);
        }
Пример #10
0
        public KinectrotateCylinderJig(
            Document doc, Transaction tr, double profSide, double factor
            )
        {
            // Initialise the various members

            _doc             = doc;
            _tr              = tr;
            _vertices        = new Point3dCollection();
            _lastDrawnVertex = -1;
            _resizing        = false;
            _resizebool      = 0;
            _drawing         = false;
            leftHand         = new Point3d();
            rightHand        = new Point3d();
            leftHip          = new Point3d();
            _isRotate        = false;
            vRot             = new Vector3d();
            _changeaxis      = false;
            _firstdraw       = 0;
            ct         = 0;
            _created   = new DBObjectCollection();
            _profSide  = profSide;
            _segFactor = factor;

            cube = new Solid3d();
            cube.CreateFrustum(0.5, 0.5, 0.8, 0.5);

            Words.Add("red");
            Words.Add("green");
            Words.Add("blue");
            Words.Add("yellow");
            Words.Add("pink");
            Words.Add("magenta");
            Words.Add("cyan");
        }
Пример #11
0
        /// <summary>
        /// Функция отрисовки портов вывода
        /// </summary>
        /// <param name="database">База данныйх</param>
        /// <param name="Trans">Транцакция</param>
        /// <param name="parameters">Класс с параметрами построения мотора</param>
        /// <param name="positionPort">Позиция отверстия</param>
        /// <param name="Figure">Обьект класса</param>
        /// <param name="x">Позиция центра по координате Х</param>
        /// <param name="y">Позиция центра по координате Y</param>
        /// <param name="z">Позиция центра по координате Z</param>
        private void Ports(Database database, Transaction trans, MotorParameters parameters, int positionPort, Solid3d figure, double x, double y, double z)
        {
            // Открываем таблицу блоков для чтения
            BlockTable blockTable = trans.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable;

            // Открываем таблицу блоков модели для записи
            BlockTableRecord blockTableRecord = trans.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

            // Создаем 3D обьект - прямоугольник
            Solid3d port = new Solid3d();

            port.SetDatabaseDefaults();
            port.CreateFrustum(_widthFindings * (parameters.CountPorts - positionPort), _diameretPorts / 2, _diameretPorts / 2, _diameretPorts / 2);
            port.ColorIndex = 4;

            // Перемещение и и поворот
            port.TransformBy(Matrix3d.Displacement(new Point3d(x, y, z) - Point3d.Origin));
            Vector3d vRotPort = new Point3d(0, 0, 0).GetVectorTo(new Point3d(0, 1, 0));

            port.TransformBy(Matrix3d.Rotation(Math.PI / 2, vRotPort, new Point3d(x, y, z)));
            blockTableRecord.AppendEntity(port);
            trans.AddNewlyCreatedDBObject(port, true);
            figure.BooleanOperation(BooleanOperationType.BoolSubtract, port);
        }
        /// <summary>
        ///     Построить ножки
        /// </summary>
        private void BuildLegs()
        {
            var leftLegDisplacement =
                new Point3d(
                    -_parameters.ModelParameters[ParameterType.MainPartLength].Value / 2 +
                    _parameters.ModelParameters[ParameterType.LegsDiameter].Value / 2,
                    _parameters.ModelParameters[ParameterType.MainPartWidth].Value / 2 -
                    _parameters.ModelParameters[ParameterType.LegsDiameter].Value / 2,
                    -_parameters.ModelParameters[ParameterType.LegsHeight].Value / 2 -
                    _parameters.ModelParameters[ParameterType.MainPartHeight].Value / 2) -
                Point3d.Origin;

            var rightLegDisplacement =
                new Point3d(
                    -_parameters.ModelParameters[ParameterType.MainPartLength].Value / 2 +
                    _parameters.ModelParameters[ParameterType.LegsDiameter].Value / 2,
                    -_parameters.ModelParameters[ParameterType.MainPartWidth].Value / 2 +
                    _parameters.ModelParameters[ParameterType.LegsDiameter].Value / 2,
                    -_parameters.ModelParameters[ParameterType.LegsHeight].Value / 2 -
                    _parameters.ModelParameters[ParameterType.MainPartHeight].Value / 2) -
                Point3d.Origin;

            using (var transaction =
                       _database.TransactionManager.StartTransaction())
            {
                var blockTableRecord = GetBlockTableRecord(transaction);

                using (var leftLegSolid3d = new Solid3d())
                {
                    leftLegSolid3d.CreateFrustum(
                        _parameters.ModelParameters[ParameterType.LegsHeight].Value,
                        _parameters.ModelParameters[ParameterType.LegsDiameter].Value / 2,
                        _parameters.ModelParameters[ParameterType.LegsDiameter].Value / 2,
                        _parameters.ModelParameters[ParameterType.LegsDiameter].Value /
                        2);

                    leftLegSolid3d.TransformBy(
                        Matrix3d.Displacement(leftLegDisplacement));

                    blockTableRecord.AppendEntity(leftLegSolid3d);
                    transaction.AddNewlyCreatedDBObject(leftLegSolid3d, true);
                }

                using (var rightLegSolid3d = new Solid3d())
                {
                    rightLegSolid3d.CreateFrustum(
                        _parameters.ModelParameters[ParameterType.LegsHeight].Value,
                        _parameters.ModelParameters[ParameterType.LegsDiameter].Value / 2,
                        _parameters.ModelParameters[ParameterType.LegsDiameter].Value / 2,
                        _parameters.ModelParameters[ParameterType.LegsDiameter].Value /
                        2);

                    rightLegSolid3d.TransformBy(
                        Matrix3d.Displacement(rightLegDisplacement));

                    blockTableRecord.AppendEntity(rightLegSolid3d);
                    transaction.AddNewlyCreatedDBObject(rightLegSolid3d, true);
                }

                transaction.Commit();
            }
        }
Пример #13
0
        protected override bool WorldDrawData(WorldDraw draw)
        {
            if (!base.WorldDrawData(draw))
            {
                return(false);
            }

            short origCol = draw.SubEntityTraits.Color;

            if (_resizing)
            {
                using (Solid3d cube = new Solid3d())
                {
                    try
                    {
                        if (switchm == 1)
                        {
                            cube.CreateFrustum(_profSide, _profSide, _profSide, 0.0);
                        }
                        else if (switchm == 0)
                        {
                            cube.CreateBox(_profSide, _profSide, _profSide);
                        }


                        if (cube != null)
                        {
                            cube.TransformBy(
                                Matrix3d.Displacement(
                                    _resizeLocation - Point3d.Origin
                                    )
                                );

                            // Draw the cursor

                            draw.SubEntityTraits.Color = ColorIndex;
                            cube.WorldDraw(draw);
                        }
                    }
                    catch (System.Exception ex)
                    {
                        _doc.Editor.WriteMessage(
                            "\nException: {0} - {1}", ex.Message, ex.InnerException
                            );
                    }
                    finally
                    {
                        draw.SubEntityTraits.Color = origCol;
                    }
                }



                return(true);
            }

            // If we're currently drawing...

            if (_drawing)
            {
                Solid3d sol = null;
                try
                {
                    // If we have vertices that haven't yet been drawn...

                    if (_vertices.Count > 1 //&&
                        //_vertices.Count - 1 > _lastDrawnVertex
                        )
                    {
                        // ... generate a tube

                        if (GenerateTube(_profSide, _vertices, out sol))
                        {
                            // We now need to break the pipe...

                            // If it was created, add it to our list to draw

                            _created.Add(sol);
                            sol = null;

                            // Clear all but the last vertex to draw from
                            // next time

                            ClearAllButLast(_vertices, 1);
                        }
                    }
                }
                catch
                {
                    // If the tube generation failed...

                    if (sol != null)
                    {
                        sol.Dispose();
                    }

                    // Loop, creating the most recent successful tube we can

                    bool succeeded = false;
                    int  n         = 1;

                    do
                    {
                        try
                        {
                            // Generate the previous, working tube using all
                            // but the last points (if it fails, one more is
                            // excluded per iteration, until we get a working
                            // tube)

                            GenerateTube(
                                _profSide, GetAllButLast(_vertices, n++), out sol
                                );

                            _created.Add(sol);
                            sol       = null;
                            succeeded = true;
                        }
                        catch { }
                    }while (!succeeded && n < _vertices.Count);

                    if (succeeded)
                    {
                        ClearAllButLast(_vertices, n - 1);

                        if (_vertices.Count > 1)
                        {
                            try
                            {
                                // And generate a tube for the remaining vertices

                                GenerateTube(_profSide, _vertices, out sol);
                            }
                            catch
                            {
                                succeeded = false;
                            }
                        }
                    }

                    if (!succeeded && sol != null)
                    {
                        sol.Dispose();
                        sol = null;
                    }
                }

                // Draw our solid(s)

                draw.SubEntityTraits.Color = ColorIndex;

                foreach (DBObject obj in _created)
                {
                    Entity ent = obj as Entity;
                    if (ent != null)
                    {
                        try
                        {
                            ent.WorldDraw(draw);
                        }
                        catch
                        { }
                    }
                }

                if (sol != null)
                {
                    try
                    {
                        sol.WorldDraw(draw);
                    }
                    catch
                    { }
                }

                if (_vertices.Count > 0)
                {
                    Point3d lastPt = _vertices[_vertices.Count - 1];

                    // Create a cursor sphere

                    using (Solid3d cursor = new Solid3d())
                    {
                        try
                        {
                            if (switchm == 1)
                            {
                                cursor.CreateFrustum(_profSide, _profSide, _profSide, 0.0);
                            }
                            else if (switchm == 0)
                            {
                                cursor.CreateBox(_profSide, _profSide, _profSide);
                            }
                            if (cursor != null)
                            {
                                cursor.TransformBy(
                                    Matrix3d.Displacement(lastPt - Point3d.Origin)
                                    );

                                // Draw the cursor

                                draw.SubEntityTraits.Color = 4;     // ColorIndex;

                                cursor.WorldDraw(draw);
                            }
                        }
                        catch { }
                    }
                }

                if (sol != null)
                {
                    sol.Dispose();
                }
            }

            draw.SubEntityTraits.Color = origCol;

            return(true);
        }
Пример #14
0
        protected override bool WorldDrawData(WorldDraw draw)
        {
            if (!base.WorldDrawData(draw))
                return false;

            short origCol = draw.SubEntityTraits.Color;

            if (_resizing)
            {
                using (Solid3d cylinder = new Solid3d())
                {
                    try
                    {
                        cylinder.CreateFrustum(_profSide, _profSide, _profSide,_profSide);

                        if (cylinder != null)
                        {
                            cylinder.TransformBy(
                              Matrix3d.Displacement(
                                _resizeLocation - Point3d.Origin
                              )
                            );

                            // Draw the cursor

                            draw.SubEntityTraits.Color = ColorIndex;
                            cylinder.WorldDraw(draw);
                        }
                    }
                    catch (System.Exception ex)
                    {
                        _doc.Editor.WriteMessage(
                          "\nException: {0} - {1}", ex.Message, ex.InnerException
                        );
                    }
                    finally
                    {
                        draw.SubEntityTraits.Color = origCol;
                    }
                }
                return true;
            }

            // If we're currently drawing...

            if (_drawing)
            {
                Solid3d sol = null;
                try
                {
                    // If we have vertices that haven't yet been drawn...

                    if (_vertices.Count > 1 //&&
                        //_vertices.Count - 1 > _lastDrawnVertex
                      )
                    {
                        // ... generate a tube

                        if (GenerateTube(_profSide, _vertices, out sol))
                        {
                            // We now need to break the pipe...

                            // If it was created, add it to our list to draw

                            _created.Add(sol);
                            sol = null;

                            // Clear all but the last vertex to draw from
                            // next time

                            ClearAllButLast(_vertices, 1);
                        }
                    }
                }
                catch
                {
                    // If the tube generation failed...

                    if (sol != null)
                    {
                        sol.Dispose();
                    }

                    // Loop, creating the most recent successful tube we can

                    bool succeeded = false;
                    int n = 1;

                    do
                    {
                        try
                        {
                            // Generate the previous, working tube using all
                            // but the last points (if it fails, one more is
                            // excluded per iteration, until we get a working
                            // tube)

                            GenerateTube(
                              _profSide, GetAllButLast(_vertices, n++), out sol
                            );

                            _created.Add(sol);
                            sol = null;
                            succeeded = true;
                        }
                        catch { }
                    }
                    while (!succeeded && n < _vertices.Count);

                    if (succeeded)
                    {
                        ClearAllButLast(_vertices, n - 1);

                        if (_vertices.Count > 1)
                        {
                            try
                            {
                                // And generate a tube for the remaining vertices

                                GenerateTube(_profSide, _vertices, out sol);
                            }
                            catch
                            {
                                succeeded = false;
                            }
                        }
                    }

                    if (!succeeded && sol != null)
                    {
                        sol.Dispose();
                        sol = null;
                    }
                }

                // Draw our solid(s)

                draw.SubEntityTraits.Color = ColorIndex;

                foreach (DBObject obj in _created)
                {
                    Entity ent = obj as Entity;
                    if (ent != null)
                    {
                        try
                        {
                            ent.WorldDraw(draw);
                        }
                        catch
                        { }
                    }
                }

                if (sol != null)
                {
                    try
                    {
                        sol.WorldDraw(draw);
                    }
                    catch
                    { }
                }

                if (_vertices.Count > 0)
                {
                    Point3d lastPt = _vertices[_vertices.Count - 1];

                    // Create a cursor sphere

                    using (Solid3d cursor = new Solid3d())
                    {
                        try
                        {
                            cursor.CreateFrustum(_profSide, _profSide, _profSide, _profSide );

                            if (cursor != null)
                            {
                                cursor.TransformBy(
                                  Matrix3d.Displacement(lastPt - Point3d.Origin)
                                );

                                // Draw the cursor

                                draw.SubEntityTraits.Color = 5; //ColorIndex;

                                cursor.WorldDraw(draw);
                            }
                        }
                        catch { }
                    }
                }

                if (sol != null)
                {
                    sol.Dispose();
                }
            }

            draw.SubEntityTraits.Color = origCol;

            return true;
        }
        public void Test()
        {
            Document acDoc = Application.DocumentManager.MdiActiveDocument;

            Database acCurDb = acDoc.Database;

            Editor acEd = acDoc.Editor;

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                var blkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;

                var mdlSpc = acTrans.GetObject(blkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                /* var ent3dArray = Enumerable.Range(0, 8).Select(i => new Solid3d()).ToArray();
                 * var box = ent3dArray[0];
                 * box.CreateBox(1, 2, 3);
                 * //圆锥/圆柱
                 * var fru = ent3dArray[1];
                 * fru.CreateFrustum(3, 1, 1, 0);
                 *
                 * //台体
                 * var pyr = ent3dArray[2];
                 * pyr.CreatePyramid(3, 5, 2, 1);
                 *
                 * var sph = ent3dArray[3];
                 * sph.CreateSphere(2);
                 *
                 * var tor = ent3dArray[4];
                 * tor.CreateTorus(2, 0.5);
                 *
                 * var wdg = ent3dArray[5];
                 * wdg.CreateWedge(1, 2, 3);
                 *
                 * var poly = new Polyline();
                 *
                 * poly.AddVertexAt(poly.NumberOfVertices, Point2d.Origin - Vector2d.XAxis, 0, 0, 0);
                 * poly.AddVertexAt(poly.NumberOfVertices, Point2d.Origin + Vector2d.XAxis, 0, 0, 0);
                 * poly.AddVertexAt(poly.NumberOfVertices, Point2d.Origin + Vector2d.YAxis, 0, 0, 0);
                 * poly.Closed = true;
                 *
                 * var reg=Region.CreateFromCurves(new DBObjectCollection() { poly })[0] as Region;
                 *
                 * var ext1 = ent3dArray[6];
                 * ext1.Extrude(reg, 6, 0);
                 *
                 * var ext2 = ent3dArray[7];
                 * ext2.Revolve(reg, Point3d.Origin + Vector3d.XAxis, Vector3d.YAxis, Math.PI * 2);
                 *
                 * foreach (var i in Enumerable.Range(0,8))
                 * {
                 *
                 *   var ent3d = ent3dArray[i];
                 *
                 *   ent3d.TransformBy(Matrix3d.Displacement((Vector3d.XAxis * 10).RotateBy(i * Math.PI / 4, Vector3d.ZAxis)));
                 *
                 *   mdlSpc.AppendEntity(ent3d);
                 *   acTrans.AddNewlyCreatedDBObject(ent3d, true);
                 *
                 *
                 * }*/

                var unit0 = new Solid3d();
                unit0.CreateBox(2, 2, 0.2);
                unit0.TransformBy(Matrix3d.Displacement(Vector3d.ZAxis * 0.1));

                using (var unit1 = new Solid3d())
                {
                    unit1.CreateFrustum(3, 0.9, 0.9, 0);
                    unit1.TransformBy(Matrix3d.Displacement(Vector3d.ZAxis * 1.7));

                    unit0.BooleanOperation(BooleanOperationType.BoolUnite, unit1);
                }

                using (var unit2 = new Solid3d())
                {
                    unit2.CreateFrustum(3, 0.9, 0.9, 0);
                    unit2.TransformBy(Matrix3d.Displacement(Vector3d.ZAxis * 1.5));
                    unit0.BooleanOperation(BooleanOperationType.BoolSubtract, unit2);
                }

                using (var unit3 = new Solid3d())
                {
                    unit3.CreateFrustum(2, 0.6, 0.6, 0);
                    unit3.TransformBy(Matrix3d.Displacement(Vector3d.ZAxis * 1));
                    unit0.BooleanOperation(BooleanOperationType.BoolUnite, unit3);
                }

                var brep = new Brep(unit0);

                acEd.WriteMessage(string.Join("\n",
                                              new[]
                {
                    $"Complex:{brep.Complexes.Count()}",
                    $"Shell:{brep.Shells.Count()}",
                    $"Face:{brep.Faces.Count()}",
                    $"Edged:{brep.Edges.Count()}",
                    $"Vertex:{brep.Vertices.Count()}"
                }
                                              ));

                mdlSpc.AppendEntity(unit0);
                acTrans.AddNewlyCreatedDBObject(unit0, true);



                acTrans.Commit();
            }
        }
Пример #16
0
        /// <summary>
        /// Построить модель корпуса
        /// </summary>
        /// <param name="WatchData">параметры часов</param>
        /// <returns>3д модель корпуса</returns>
        private Solid3d BuildBody(WatchData WatchData)
        {
            //корпус часов
            Solid3d Body = new Solid3d();

            Body.CreateFrustum(Height, Diameter, Diameter, Diameter);

            //Верхняя часть корпуса
            Solid3d BodyTop = new Solid3d();

            BodyTop.CreateFrustum(_params[ParNames.BodyTransformByY], Diameter, Diameter, Diameter - _params[ParNames.BodyTransformByZ]);
            BodyTop.TransformBy(Matrix3d.Displacement(new Point3d(0, 0, Height / _params[ParNames.BodyTransformByY] + _params[ParNames.BodyTransformByX]) - Point3d.Origin));
            Body.BooleanOperation(BooleanOperationType.BoolUnite, BodyTop.Clone() as Solid3d);


            //Нижняя часть корпуса
            Solid3d BodyBottom = new Solid3d();

            BodyBottom.CreateFrustum(_params[ParNames.BodyTransformByX], Diameter - _params[ParNames.BodyTopTransformByY], Diameter - _params[ParNames.BodyTopTransformByY], Diameter - _params[ParNames.BodyTransformByY]);
            BodyBottom.TransformBy(Matrix3d.Displacement(new Point3d(0, 0, -(Height / 2 + _params[ParNames.BodyTransformByX] / 2)) - Point3d.Origin));
            Body.BooleanOperation(BooleanOperationType.BoolUnite, BodyBottom.Clone() as Solid3d);

            //Вырез на корпусе, сверху
            BodyTop = new Solid3d();
            BodyTop.CreateFrustum(_params[ParNames.BodyTransformByY], Diameter - _params[ParNames.BodyBottomTransformByX], Diameter - _params[ParNames.BodyBottomTransformByX], Diameter - _params[ParNames.BodyTopTransformByY]);
            BodyTop.TransformBy(Matrix3d.Displacement(new Point3d(0, 0, Height / _params[ParNames.BodyTransformByY] + _params[ParNames.BodyTransformByX]) - Point3d.Origin));
            Body.BooleanOperation(BooleanOperationType.BoolSubtract, BodyTop.Clone() as Solid3d);


            //ушки на корпусе
            Solid3d Bootstrap = new Solid3d();

            Bootstrap.CreateBox(BootstrapLength * _params[ParNames.BodyTransformByY] + Diameter * _params[ParNames.BodyTransformByY], _params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY]);
            Vector3d BootsrapPosition;
            Solid3d  ArcPart = new Solid3d();

            ArcPart.CreateFrustum(_params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY] / 2, _params[ParNames.BodyTopTransformByY] / 2, _params[ParNames.BodyTopTransformByY] / 2);
            ArcPart.TransformBy(Matrix3d.Rotation(Math.PI / 2, new Vector3d(1, 0, 0), Point3d.Origin));
            ArcPart.TransformBy(Matrix3d.Displacement(new Vector3d(Diameter + BootstrapLength, 0, 0)));

            //Держатели на ушках
            Solid3d StrapHolder = new Solid3d();

            StrapHolder.CreateFrustum(WatchData.StrapWidth + _params[ParNames.BodyTopTransformByX], _params[ParNames.BodyTransformByX] / _params[ParNames.BodyTransformByY], _params[ParNames.BodyTransformByX] / _params[ParNames.BodyTransformByY], _params[ParNames.BodyTransformByX] / _params[ParNames.BodyTransformByY]);
            StrapHolder.TransformBy(Matrix3d.Rotation(Math.PI / _params[ParNames.BodyTransformByY], new Vector3d(1, 0, 0), Point3d.Origin));
            StrapHolder.TransformBy(Matrix3d.Displacement(new Vector3d(Diameter + BootstrapLength, -WatchData.StrapWidth / 2 - _params[ParNames.BodyTransformByY], 0)));
            ArcPart.BooleanOperation(BooleanOperationType.BoolUnite, StrapHolder.Clone() as Solid3d);
            Bootstrap.BooleanOperation(BooleanOperationType.BoolUnite, ArcPart.Clone() as Solid3d);

            //сглаженные углы на ушках
            ArcPart.CreateFrustum(_params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY] / _params[ParNames.BodyTransformByY], _params[ParNames.BodyTopTransformByY] / 2, _params[ParNames.BodyTopTransformByY] / 2);
            ArcPart.TransformBy(Matrix3d.Rotation(Math.PI / _params[ParNames.BodyTransformByY], new Vector3d(1, 0, 0), Point3d.Origin));
            ArcPart.TransformBy(Matrix3d.Displacement(new Vector3d(-(Diameter + BootstrapLength), 0, 0)));

            StrapHolder.CreateFrustum(WatchData.StrapWidth + _params[ParNames.BodyTopTransformByX], _params[ParNames.BodyTransformByX] / 2, _params[ParNames.BodyTransformByX] / 2, _params[ParNames.BodyTransformByX] / 2);
            StrapHolder.TransformBy(Matrix3d.Rotation(Math.PI / 2, new Vector3d(1, 0, 0), Point3d.Origin));
            StrapHolder.TransformBy(Matrix3d.Displacement(new Vector3d(-(Diameter + BootstrapLength), -WatchData.StrapWidth / 2 - _params[ParNames.BodyTransformByY], 0)));
            ArcPart.BooleanOperation(BooleanOperationType.BoolUnite, StrapHolder.Clone() as Solid3d);

            Bootstrap.BooleanOperation(BooleanOperationType.BoolUnite, ArcPart.Clone() as Solid3d);
            BootsrapPosition = new Vector3d(0, WatchData.StrapWidth / _params[ParNames.BodyTransformByY] + _params[ParNames.BodyTransformByZ], 0);
            Bootstrap.TransformBy(Matrix3d.Displacement(BootsrapPosition));

            Body.BooleanOperation(BooleanOperationType.BoolUnite, Bootstrap.Clone() as Solid3d);
            Bootstrap = new Solid3d();
            Bootstrap.CreateBox(BootstrapLength * _params[ParNames.BodyTransformByY] + Diameter * _params[ParNames.BodyTransformByY], _params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY]);

            ArcPart = new Solid3d();
            ArcPart.CreateFrustum(_params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY] / 2, _params[ParNames.BodyTopTransformByY] / _params[ParNames.BodyTransformByY], _params[ParNames.BodyTopTransformByY] / _params[ParNames.BodyTransformByY]);
            ArcPart.TransformBy(Matrix3d.Rotation(Math.PI / _params[ParNames.BodyTransformByY], new Vector3d(1, 0, 0), Point3d.Origin));
            ArcPart.TransformBy(Matrix3d.Displacement(new Vector3d(Diameter + BootstrapLength, 0, 0)));
            Bootstrap.BooleanOperation(BooleanOperationType.BoolUnite, ArcPart.Clone() as Solid3d);
            ArcPart.CreateFrustum(_params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY] / _params[ParNames.BodyTransformByY], _params[ParNames.BodyTopTransformByY] / 2, _params[ParNames.BodyTopTransformByY] / _params[ParNames.BodyTransformByY]);
            ArcPart.TransformBy(Matrix3d.Rotation(Math.PI / _params[ParNames.BodyTransformByY], new Vector3d(1, 0, 0), Point3d.Origin));
            ArcPart.TransformBy(Matrix3d.Displacement(new Vector3d(-(Diameter + BootstrapLength), 0, 0)));
            Bootstrap.BooleanOperation(BooleanOperationType.BoolUnite, ArcPart.Clone() as Solid3d);
            BootsrapPosition = new Vector3d(0, -(WatchData.StrapWidth / _params[ParNames.BodyTransformByY] + _params[ParNames.BodyTransformByZ]), 0);
            Bootstrap.TransformBy(Matrix3d.Displacement(BootsrapPosition));


            //соеденяем все вместе
            Body.BooleanOperation(BooleanOperationType.BoolUnite, Bootstrap.Clone() as Solid3d);

            //если есть хронограф, то выполняем
            if (HasChronograph)
            {
                //первая кнопка хронографа
                Solid3d ChronoButtonTop = new Solid3d();
                ChronoButtonTop.CreateFrustum(_params[ParNames.BodyTopTransformByX], _params[ParNames.BodyTopTransformByX], _params[ParNames.BodyTopTransformByX], _params[ParNames.BodyTopTransformByX]);

                ChronoButtonTop.TransformBy(Matrix3d.Rotation(Math.PI / 2, new Vector3d(1, 0, 0), Point3d.Origin));
                ChronoButtonTop.TransformBy(Matrix3d.Displacement(new Vector3d(0, Diameter, 0)));
                ChronoButtonTop.TransformBy(Matrix3d.Rotation(Math.PI / 6, new Vector3d(0, 0, 1), Point3d.Origin));
                Body.BooleanOperation(BooleanOperationType.BoolUnite, ChronoButtonTop.Clone() as Solid3d);

                //вторая кнопка хронографа
                Solid3d ChronoButtonBottom = new Solid3d();
                ChronoButtonBottom.CreateFrustum(_params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY]);
                ChronoButtonBottom.TransformBy(Matrix3d.Rotation(Math.PI / 2, new Vector3d(1, 0, 0), Point3d.Origin));
                ChronoButtonBottom.TransformBy(Matrix3d.Displacement(new Vector3d(0, Diameter, 0)));
                ChronoButtonBottom.TransformBy(Matrix3d.Rotation(-Math.PI / 6, new Vector3d(0, 0, 1), Point3d.Origin));
                Body.BooleanOperation(BooleanOperationType.BoolUnite, ChronoButtonBottom.Clone() as Solid3d);
            }

            return(Body);
        }
Пример #17
0
        public void interferenceSolids()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                try
                {
                    BlockTable blkTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                    if (blkTable == null)
                    {
                        trans.Abort();
                        return;
                    }

                    BlockTableRecord blkTableRecord = trans.GetObject(blkTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                    if (blkTableRecord == null)
                    {
                        return;
                    }

                    using (Solid3d solid3DBox = new Solid3d())
                    {
                        // 3D Solid Box.
                        solid3DBox.CreateBox(5, 7, 10);
                        solid3DBox.ColorIndex = 7;

                        // Position of the center of solid3DBox at (5, 5, 0)
                        solid3DBox.TransformBy(Matrix3d.Displacement(new Point3d(5, 5, 0) - Point3d.Origin));

                        //blkTableRecord.AppendEntity(solid3DBox);
                        //trans.AddNewlyCreatedDBObject(solid3DBox, true);

                        // 3D Solid Cylinder.
                        using (Solid3d solid3DCylinder = new Solid3d())
                        {
                            solid3DCylinder.CreateFrustum(20, 5, 5, 5);
                            solid3DCylinder.ColorIndex = 4;

                            //blkTableRecord.AppendEntity(solid3DCylinder);
                            //trans.AddNewlyCreatedDBObject(solid3DCylinder, true);

                            // Create 3D solid from the interference of the box and cylinder.
                            //Solid3d solid3dCopy = solid3DCylinder.Clone() as Solid3d;

                            //if (solid3dCopy.CheckInterference(solid3DBox) == true)
                            //{
                            //    solid3dCopy.BooleanOperation(BooleanOperationType.BoolSubtract, solid3DBox.Clone() as Solid3d);
                            //    solid3dCopy.ColorIndex = 1;
                            //}

                            //// add solid3dCopy to the block table record.
                            //blkTableRecord.AppendEntity(solid3dCopy);
                            //trans.AddNewlyCreatedDBObject(solid3dCopy, true);

                            Solid3d solid3dCopyCylinder = solid3DCylinder.Clone() as Solid3d;

                            if (solid3dCopyCylinder.CheckInterference(solid3DBox) == true)
                            {
                                solid3dCopyCylinder.BooleanOperation(BooleanOperationType.BoolIntersect, solid3DBox);
                                solid3dCopyCylinder.ColorIndex = 3;
                            }

                            blkTableRecord.AppendEntity(solid3dCopyCylinder);
                            trans.AddNewlyCreatedDBObject(solid3dCopyCylinder, true);
                        }
                    }

                    trans.Commit();
                }
                catch (System.Exception)
                {
                    trans.Abort();
                    throw;
                }
            }
        }
Пример #18
0
        /// <summary>
        /// Функция построения корпуса мотора
        /// </summary>
        /// <param name="database">База данных</param>
        /// <param name="trans">Транцакция</param>
        /// <param name="parameters">Класс с параметрами построения мотора</param>
        public void Build(Database database, Transaction trans, MotorParameters parameters)
        {
            int lenBox      = _lenBox;
            int diameretBox = _diameretBox;

            // Открываем таблицу блоков для чтения
            BlockTable blockTable = trans.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable;

            // Открываем таблицу блоков модели для записи
            BlockTableRecord blockTableRecord = trans.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

            Solid3d box = new Solid3d();

            box.SetDatabaseDefaults();
            box.CreateFrustum(lenBox, diameretBox / 2, diameretBox / 2, diameretBox / 2);
            box.ColorIndex = 4;

            // Добавляем новый обьект в таблицу блоков и отправляем на транзакцию
            blockTableRecord.AppendEntity(box);
            trans.AddNewlyCreatedDBObject(box, true);

            ObjectId[] ids = new ObjectId[] { box.ObjectId };

            SubentityId subentId = new SubentityId(SubentityType.Null, IntPtr.Zero);

            FullSubentityPath path = new FullSubentityPath(ids, subentId);

            List <SubentityId> subentIds    = new List <SubentityId>();
            DoubleCollection   radii        = new DoubleCollection();
            DoubleCollection   startSetback = new DoubleCollection();
            DoubleCollection   endSetback   = new DoubleCollection();

            // Углы скругления
            double angTop  = 60.0;
            double angDown = 15.0;

            using (Autodesk.AutoCAD.BoundaryRepresentation.Brep brep = new Autodesk.AutoCAD.BoundaryRepresentation.Brep(path))
            {
                foreach (Autodesk.AutoCAD.BoundaryRepresentation.Edge edge in brep.Edges)
                {
                    if (edge.Vertex1.Point.Z == -lenBox / 2)
                    {
                        subentIds.Add(edge.SubentityPath.SubentId);
                        radii.Add(angTop);

                        startSetback.Add(0.0);
                        endSetback.Add(angDown);
                    }
                    if (edge.Vertex1.Point.Z == lenBox / 2)
                    {
                        subentIds.Add(edge.SubentityPath.SubentId);
                        radii.Add(angDown);

                        startSetback.Add(0.0);
                        endSetback.Add(angDown);
                    }
                }
            }

            box.FilletEdges(subentIds.ToArray(), radii, startSetback, endSetback);

            // Позиция центра новой фигуры
            box.TransformBy(Matrix3d.Displacement(new Point3d(0, 0, 0) - Point3d.Origin));

            double   angleRotate = Math.PI / 2;
            Vector3d vRot        = new Point3d(0, 0, 0).GetVectorTo(new Point3d(1, 0, 0));

            box.TransformBy(Matrix3d.Rotation(angleRotate, vRot, new Point3d(0, 0, 0)));

            double radiusBox  = diameretBox / 2;
            double coordinate = (radiusBox * ((Math.Sqrt(2) - 1) / 2) + radiusBox) / Math.Sqrt(2);

            // Отрисовка лап
            double lenPaw = 0.9 * lenBox;

            BuildPawsBox(database, trans, radiusBox / 2, lenBox, radiusBox, -radiusBox, 0);
            BuildPawsBox(database, trans, radiusBox / 2, lenPaw, coordinate, -coordinate, angleRotate / 2);
            BuildPawsBox(database, trans, radiusBox / 2, lenBox, -radiusBox, -radiusBox, 0);
            BuildPawsBox(database, trans, radiusBox / 2, lenPaw, -coordinate, -coordinate, -angleRotate / 2);

            // Элементы радиатора
            int    n      = parameters.CountGrille;
            double coordX = 0;
            double coordZ = 0;
            double angleRadiatorElements = 40;
            double angleRadiatorStep     = 5;

            if (n > 1)
            {
                angleRadiatorStep = 80 / (n - 1);
            }

            for (int i = 0; i < n; i++)
            {
                if (angleRadiatorElements <= 40 && angleRadiatorElements >= -40)
                {
                    coordX = radiusBox * Math.Cos(angleRadiatorElements * Math.PI / 180);
                    coordZ = radiusBox * Math.Sin(angleRadiatorElements * Math.PI / 180);

                    BuildRadiator(database, trans, coordX, coordZ);
                    BuildRadiator(database, trans, -coordX, coordZ);

                    angleRadiatorElements -= angleRadiatorStep;
                }
            }
        }
Пример #19
0
        public KinectrotateCylinderJig(
          Document doc, Transaction tr, double profSide, double factor
        )
        {
            // Initialise the various members

            _doc = doc;
            _tr = tr;
            _vertices = new Point3dCollection();
            _lastDrawnVertex = -1;
            _resizing = false;
            _resizebool = 0;
            _drawing = false;
            leftHand = new Point3d();
            rightHand = new Point3d();
            leftHip = new Point3d();
            _isRotate = false;
            vRot = new Vector3d();
            _changeaxis = false;
            _firstdraw = 0;
            ct = 0;
            _created = new DBObjectCollection();
            _profSide = profSide;
            _segFactor = factor;

            cube = new Solid3d();
            cube.CreateFrustum(0.5, 0.5, 0.8,0.5);

            Words.Add("red");
            Words.Add("green");
            Words.Add("blue");
            Words.Add("yellow");
            Words.Add("pink");
            Words.Add("magenta");
            Words.Add("cyan");
        }