Beispiel #1
0
        private double GetLayoutOffset(NewEngineWizardState _newEngineWizardState)
        {
            double _offset_deg = 0d;

            foreach (NewEngineWizardState.CylinderLyout _cylinderLayout in _newEngineWizardState.CylinderLyouts)
            {
                if (_cylinderLayout.Tilt != 0)
                {
                    _offset_deg  = Math.Abs(_cylinderLayout.Tilt);
                    _offset_deg *= 2;

                    break;
                }
            }

            return(_offset_deg);
        }
Beispiel #2
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker     _backgroundWorker     = (BackgroundWorker)sender;
            NewEngineWizardState _newEngineWizardState = (NewEngineWizardState)e.Argument;

            _backgroundWorker.ReportProgress(10);


            try
            {
                Engine _engine = null;


                List <PositionedCylinder> _positionedCylinders = new List <PositionedCylinder>();

                foreach (NewEngineWizardState.CylinderLyout _cylinderLayout in _newEngineWizardState.CylinderLyouts)
                {
                    #region "Piston"
                    Piston _piston = Piston.FromParameters(
                        _newEngineWizardState.Bore,
                        _newEngineWizardState.PistonMass);
                    #endregion "Piston"


                    #region "ConnectingRod"
                    double _rotatingDistributionPercentage      = (100d - _newEngineWizardState.ConnectingRodMassAndDistanceDistributionPercentage) / 100d;
                    double _reciprocatingDistributionPercentage = _newEngineWizardState.ConnectingRodMassAndDistanceDistributionPercentage / 100d;

                    ConnectingRod _connectingRod = new ConnectingRod(
                        _newEngineWizardState.ConnectingRodMass * _rotatingDistributionPercentage,
                        _newEngineWizardState.ConnectingRodLength * _reciprocatingDistributionPercentage,
                        _newEngineWizardState.ConnectingRodMass * _reciprocatingDistributionPercentage,
                        _newEngineWizardState.ConnectingRodLength * _rotatingDistributionPercentage);
                    #endregion "ConnectingRod"


                    #region "CrankThrow"
                    CrankThrow _crankThrow;
                    if (_newEngineWizardState.BalancerMass > 0)
                    {
                        _crankThrow = CrankThrow.FromParameters(
                            _newEngineWizardState.Stroke / 2d,
                            _newEngineWizardState.BalancerMass,
                            _newEngineWizardState.BalancerRotationRadius);
                    }
                    else
                    {
                        _crankThrow = CrankThrow.FromParameters(_newEngineWizardState.Stroke / 2d);
                    }
                    #endregion "CrankThrow"


                    #region "Cylinder"
                    Cylinder _cylinder = new Cylinder(
                        _newEngineWizardState.Cycle,
                        _piston,
                        _connectingRod,
                        _crankThrow);
                    #endregion "Cylinder"


                    #region "PositionedCylinder"
                    double _offset = 0;
                    double _tilt   = 0;

                    if (this.GetLayoutOffset(_newEngineWizardState) == 0d) //motor je inline
                    {
                        _offset = (_cylinderLayout.CylinderPosition - 1)
                                  * (_newEngineWizardState.Bore + (_newEngineWizardState.Bore / EngineDesigner.Machine.Properties.Settings.Default.DefaultOffsetDivisor));
                    }
                    else
                    {
                        _tilt = _cylinderLayout.Tilt;

                        if (Mathematics.IsOdd(_cylinderLayout.CylinderPosition))
                        {
                            if (_positionedCylinders.Count > 0)
                            {
                                _offset = (_positionedCylinders[_positionedCylinders.Count - 1].Offset_mm
                                           + (_newEngineWizardState.Bore + (_newEngineWizardState.Bore / EngineDesigner.Machine.Properties.Settings.Default.DefaultOffsetDivisor)));
                            }
                        }
                        else
                        {
                            _offset  = _positionedCylinders[_positionedCylinders.Count - 1].Offset_mm;
                            _offset += _crankThrow.CrankPinWidth_mm;
                        }
                    }

                    PositionedCylinder _positionedCylinder = new PositionedCylinder(
                        _cylinder,
                        _cylinderLayout.CylinderPosition,
                        _offset,
                        _tilt,
                        _cylinderLayout.FiringAngle);
                    _positionedCylinders.Add(_positionedCylinder);


                    //javimo progress (60% gre za ustvarjanje cilindrov, 10 je bilo že od prej)
                    double _progressPercentage = 10d + (_cylinderLayout.CylinderPosition * 60d / _newEngineWizardState.CylinderLyouts.Length);
                    _backgroundWorker.ReportProgress((int)_progressPercentage);
                    #endregion "PositionedCylinder"
                }


                _engine = new Engine(_positionedCylinders.ToArray());
                _engine.Flywheel.Mass_g      = _newEngineWizardState.FlywheelMass;
                _engine.Flywheel.Diameter_mm = _newEngineWizardState.FlywheelDiameter;


                e.Result = _engine;
            }
            catch (Exception _exception)
            {
                e.Result = _exception;
            }
            finally
            {
                _backgroundWorker.ReportProgress(100);
            }
        }