Exemple #1
0
        private void StartTest_Click(object sender, EventArgs e)
        {
#if DEBUG            
            // Диагностика времени выполнения функции
            System.Diagnostics.Stopwatch myStopwatch = new System.Diagnostics.Stopwatch();

            // Создание и открытие его для записи
            StreamWriter file = new StreamWriter("D:\\TestMOTOR.txt");

            for (int i = 0; i < 100; i++)
            {
                // Сброс
                myStopwatch.Reset(); 
                // Запуск
                myStopwatch.Start(); 
                     
                List<int> parameters = new List<int>() {300,200,50,50,10,50,100,30,10,3,7};
                MotorParameters parametersMotor = new MotorParameters(parameters);                    
                Motor.BuildMotor(parametersMotor);
                                   
                // Остановить
                myStopwatch.Stop(); 

                TimeSpan ts = myStopwatch.Elapsed;
                string elapsedTime = String.Format("{0:f}", ts.Milliseconds);
                // Запись в файл результатов
                file.Write(elapsedTime + "\n"); 
            }
            file.Close();
        }
Exemple #2
0
        /// <summary>
        /// Построение модели
        /// </summary>
        /// <param name="parameters">Класс с параметрами построения мотора</param>
        public static void BuildMotor(MotorParameters parameters)
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

            Database database = doc.Database;

            Transaction trans = database.TransactionManager.StartTransaction();

            // Коробка выводов
            IPart finding = new Findings(parameters);

            finding.Build(database, trans, parameters);

            // Корпус мотора
            IPart box = new Box(parameters);

            box.Build(database, trans, parameters);

            // Ротор
            IPart rotor = new Rotor(parameters);

            rotor.Build(database, trans, parameters);

            trans.Commit();
        }
Exemple #3
0
 /// <summary>
 /// Конструктор класса
 /// </summary>
 /// <param name="parameters">Класс с параметрами построения мотора</param>
 public Findings(MotorParameters parameters)
 {
     _widthFindings  = parameters.WidthFindings;
     _lenFindings    = parameters.LenFindings;
     _heightFindings = parameters.HeightFindings;
     _countPorts     = parameters.CountPorts;
     _diameretPorts  = parameters.DiameretPorts;
 }
Exemple #4
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);
        }
Exemple #5
0
 /// <summary>
 /// Обработчик события нажатия кнопки
 /// </summary>
 /// <param name="sender"> Обьект, который вызвал событие</param>
 /// <param name="e"> Обьект класса передающий дополнительную информацию обработчику</param>
 private void StartBuild_Click(object sender, EventArgs e)
 {
     if (LenBox.Text == ""
         || DiameretBox.Text == ""
         || LenRotor.Text == ""
         || DiameretRotor.Text == ""
         || LenPin.Text == ""
         || WidthFindings.Text == ""
         || LenFindings.Text == ""
         || HeightFindings.Text == ""
         || DiameretPorts.Text == ""
         || CountPorts.Text == "")
     {
         MessageBox.Show(this, "Не все поля заполнены!", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
     else
     {
         List<int> parameters = new List<int>() 
         {
             Convert.ToInt32(LenBox.Text, 10),
             Convert.ToInt32(DiameretBox.Text, 10),
             Convert.ToInt32(LenRotor.Text, 10),
             Convert.ToInt32(DiameretRotor.Text, 10),
             Convert.ToInt32(LenPin.Text, 10),
             Convert.ToInt32(WidthFindings.Text, 10),
             Convert.ToInt32(LenFindings.Text, 10),
             Convert.ToInt32(HeightFindings.Text, 10),
             Convert.ToInt32(DiameretPorts.Text, 10),
             Convert.ToInt32(CountPorts.Text, 10),
             Convert.ToInt32(CountGrille.Text, 10)
         };
         try 
         {
             MotorParameters parametersMotor = new MotorParameters(parameters);                    
             Motor.BuildMotor(parametersMotor);
             Form.ActiveForm.Close();                    
         }
         catch(Exception exception) 
         {
             MessageBox.Show(this, exception.Message, "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }               
     }
 }
Exemple #6
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);
        }
Exemple #7
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 widthFindings  = _widthFindings;
            int lenFindings    = _lenFindings;
            int heightFindings = _heightFindings;

            int countPorts    = _countPorts;
            int diameretPorts = _diameretPorts;

            int lenBox      = parameters.LenBox;
            int diameretBox = parameters.DiameretBox;

            // Коэффициенты трансформации
            double transformationFactorLen    = 1.2;
            double transformationFactorHeight = 0.1;

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

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

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

            findings.SetDatabaseDefaults();
            findings.CreateBox(widthFindings, lenFindings, heightFindings);
            findings.ColorIndex = 7;

            // Задаем позицию центра 3D обьекта
            findings.TransformBy(Matrix3d.Displacement(new Point3d(0, -lenBox / 2 + transformationFactorLen * lenFindings / 2, diameretBox / 2 + heightFindings / 2 - transformationFactorHeight * heightFindings) - Point3d.Origin));

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

            // Параметры
            double cavityWidth  = widthFindings * 0.8;
            double cavityLen    = lenFindings * 0.9;
            double cavityHeight = heightFindings * 0.8;

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

            cavity.SetDatabaseDefaults();
            cavity.CreateBox(cavityWidth, cavityLen, cavityHeight);
            cavity.TransformBy(Matrix3d.Displacement(new Point3d(0, -lenBox / 2 + transformationFactorLen * lenFindings / 2, diameretBox / 2 + heightFindings / 2 - transformationFactorHeight * heightFindings) - Point3d.Origin));

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

            findings.BooleanOperation(BooleanOperationType.BoolSubtract, cavity);


            double coordZ = diameretBox / 2 + heightFindings / 2 - transformationFactorHeight * heightFindings;
            double coordX = widthFindings / 3;


            if (countPorts >= 1)
            {
                double y1 = -lenBox / 2 + (transformationFactorLen * lenFindings / 2 + lenFindings / 3);
                Ports(database, trans, parameters, 0, findings, coordX, y1, coordZ);
            }
            if (countPorts > 2)
            {
                double y2 = -lenBox / 2 + (transformationFactorLen * lenFindings / 2);
                Ports(database, trans, parameters, 2, findings, coordX, y2, coordZ);
            }
            if (countPorts > 4)
            {
                double y3 = -lenBox / 2 + (transformationFactorLen * lenFindings / 2 - lenFindings / 3);
                Ports(database, trans, parameters, 4, findings, -coordX, y3, coordZ);
            }
        }
Exemple #8
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;
                }
            }
        }
Exemple #9
0
 /// <summary>
 /// Конструктор класса
 /// </summary>
 /// <param name="parameters">Класс с параметрами построения мотора</param>
 public Box(MotorParameters parameters)
 {
     _diameretBox = parameters.DiameretBox;
     _lenBox      = parameters.LenBox;
 }
Exemple #10
0
 /// <summary>
 /// Конструктор класса
 /// </summary>
 /// <param name="parameters">Класс с параметрами построения мотора</param>
 public Rotor(MotorParameters parameters)
 {
     _diameretRotor = parameters.DiameretRotor;
     _lenRotor      = parameters.LenRotor;
     _lenPin        = parameters.LenPin;
 }