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); } }
private void PasteFromTemplate(GridItem _gridItem) { object _object = Clipboard.GetData(DataFormats.Serializable); if (_gridItem.Value is CustomList <PositionedCylinder> ) { CustomList <PositionedCylinder> _selectedItem = (CustomList <PositionedCylinder>)_gridItem.Value; PositionedCylinder _fromClipboard = (PositionedCylinder)_object; //NOTE: to je bilo po starem //@List<PositionedCylinder> _positionedCylinders = new @List<PositionedCylinder>(); //foreach (PositionedCylinder _existingPositionedCylinder in _selectedItem) //{ // PositionedCylinder _newPositionedCylinder = EngineDesigner.Common.Utility.CopyObject<PositionedCylinder>(_fromClipboard); // _newPositionedCylinder.Position = _existingPositionedCylinder.Position; //pozicije ne popravljamo! // _newPositionedCylinder.Offset_mm = _existingPositionedCylinder.Offset_mm; //offseta ne popravljamo! // _newPositionedCylinder.Tilt_deg = _existingPositionedCylinder.Tilt_deg; //offseta ne popravljamo! // _newPositionedCylinder.FiringAngle_deg = _existingPositionedCylinder.FiringAngle_deg; //kota vžiga ne popravljamo! // _positionedCylinders.Add(_newPositionedCylinder); //} //base.SetItemValue(_gridItem, _positionedCylinders); //NOTE: po novem ne spreminjamo več celega propetija, ker ni prav (in nima niti več setterja), ampak samo cilindre! for (int a = 0; a < _selectedItem.Count; a++) { int _position = _selectedItem[a].Position; double _offset_mm = _selectedItem[a].Offset_mm; double _tilt_deg = _selectedItem[a].Tilt_deg; double _firingAngle_deg = _selectedItem[a].FiringAngle_deg; _selectedItem[a] = EngineDesigner.Common.Utility.CopyObject <PositionedCylinder>(_fromClipboard); _selectedItem[a].Position = _position; //pozicije ne popravljamo! _selectedItem[a].Offset_mm = _offset_mm; //offseta ne popravljamo! _selectedItem[a].Tilt_deg = _tilt_deg; //offseta ne popravljamo! _selectedItem[a].FiringAngle_deg = _firingAngle_deg; //kota vžiga ne popravljamo! } } else if (_gridItem.Value is PositionedCylinder) { PositionedCylinder _selectedItem = (PositionedCylinder)_gridItem.Value; PositionedCylinder _fromClipboard = (PositionedCylinder)_object; PositionedCylinder _positionedCylinder = EngineDesigner.Common.Utility.CopyObject <PositionedCylinder>(_fromClipboard); _positionedCylinder.Position = _selectedItem.Position; //pozicije ne popravljamo! _positionedCylinder.Offset_mm = _selectedItem.Offset_mm; //offseta ne popravljamo! _positionedCylinder.Tilt_deg = _selectedItem.Tilt_deg; //offseta ne popravljamo! _positionedCylinder.FiringAngle_deg = _selectedItem.FiringAngle_deg; //kota vžiga ne popravljamo! base.SetItemValue(_gridItem, _positionedCylinder); } else if (_gridItem.Value is Cycle) { Cycle _fromClipboard = (Cycle)_object; base.SetItemValue(_gridItem, EngineDesigner.Common.Utility.CopyObject <Cycle>(_fromClipboard)); } else if (_gridItem.Value is Piston) { Piston _fromClipboard = (Piston)_object; base.SetItemValue(_gridItem, EngineDesigner.Common.Utility.CopyObject <Piston>(_fromClipboard)); } else if (_gridItem.Value is ConnectingRod) { ConnectingRod _fromClipboard = (ConnectingRod)_object; base.SetItemValue(_gridItem, EngineDesigner.Common.Utility.CopyObject <ConnectingRod>(_fromClipboard)); } else { throw new NotSupportedException(); } this.EditedPart.Validate(); }