示例#1
0
        public void Init(Table.Table table)
        {
            var stroke = _data.Stroke;

            _beginY           = _data.Center.Y;
            _endY             = _data.Center.Y - stroke;
            NumFrames         = (int)(stroke * (float)(PlungerFrameCount / 80.0)) + 1;     // 25 frames per 80 units travel
            _invScale         = NumFrames > 1 ? 1.0f / (NumFrames - 1) : 0.0f;
            _dyPerFrame       = (_endY - _beginY) * _invScale;
            _circlePoints     = _data.Type == PlungerType.PlungerTypeFlat ? 0 : 24;
            _springLoops      = 0.0f;
            _springEndLoops   = 0.0f;
            _springGauge      = 0.0f;
            _springRadius     = 0.0f;
            _springMinSpacing = 2.2f;
            _rodY             = _beginY + _data.Height;

            // note the number of cells in the source image
            _srcCells = _data.AnimFrames;
            if (_srcCells < 1)
            {
                _srcCells = 1;
            }

            // figure the width in relative units (0..1) of each cell
            _cellWid = 1.0f / _srcCells;

            if (table != null)
            {
                _zHeight = table.GetSurfaceHeight(_data.Surface, _data.Center.X, _data.Center.Y) + _data.ZAdjust;
                _zScale  = table.GetScaleZ();
            }
            _desc = GetPlungerDesc();
        }
示例#2
0
        private PlungerDesc GetPlungerDesc()
        {
            switch (_data.Type)
            {
            case PlungerType.PlungerTypeModern:
                return(PlungerDesc.GetModern());

            case PlungerType.PlungerTypeFlat:
                return(PlungerDesc.GetFlat());

            case PlungerType.PlungerTypeCustom:
                return(PlungerDesc.GetCustom(_data, _beginY, _springMinSpacing,
                                             out _rodY, out _springGauge, out _springRadius,
                                             out _springLoops, out _springEndLoops));
            }
            Logger.Warn("Unknown plunger type {0}.", _data.Type);
            return(PlungerDesc.GetModern());
        }
示例#3
0
        public static PlungerDesc GetCustom(PlungerData data, float beginY, float springMinSpacing,
                                            out float rody, out float springGauge, out float springRadius,
                                            out float springLoops, out float springEndLoops)
        {
            // Several of the entries are fixed:
            // shaft x 2 (top, bottom)
            // ring x 6 (inner top, outer top x 2, outer bottom x 2, inner bottom)
            // ring gap x 2 (top, bottom)
            // tip bottom inner x 1
            // first entry in custom tip list (there's always at least one;
            //    even if it's blank, we read the empty entry as "0,0" )
            var numCoords = 2 + 6 + 2 + 1 + 1;

            // Split the tip list.
            // Entries are separated by semicolons.
            var tipShapes = string.IsNullOrEmpty(data.TipShape)
                                ? new string[0]
                                : data.TipShape.Split(';');
            var numTips = tipShapes.Length;

            numCoords += numTips - 1;

            // allocate the descriptor and the coordinate array
            var desc = new PlungerDesc(new PlungerCoord[numCoords]);

            // figure the tip lathe descriptor from the shape point list
            //var c = customDesc.c;
            float tipLen = 0;
            int   i;

            for (i = 0; i < tipShapes.Length; i++)
            {
                // Parse the entry: "yOffset, diam".  yOffset is the
                // offset (in table distance units) from the previous
                // point.  "diam" is the diameter (relative to the
                // nominal width of the plunger, as given by the width
                // property) of the tip at this point.  1.0 means that
                // the diameter is the same as the nominal width; 0.5
                // is half the width.
                var     tipShape = tipShapes[i];
                var     ts       = tipShape.Trim().Split(' ');
                ref var c        = ref desc.c[i];

                try {
                    c.y = int.Parse(ts[0], CultureInfo.InvariantCulture);
                } catch (FormatException) {
                    c.y = 0;
                }

                try {
                    var v = ts.Length > 1 ? ts[1] : "0.0";
                    c.r = float.Parse(v.StartsWith(".") ? "0" + v : v, CultureInfo.InvariantCulture) * 0.5f;
                } catch (FormatException) {
                    c.r = 0;
                }

                // each entry has to have a higher y value than the last
                if (c.y < tipLen)
                {
                    c.y = tipLen;
                }

                // update the tip length so far
                tipLen = c.y;
            }