Exemplo n.º 1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            StringFormat leftJustified = new StringFormat(StringFormat.GenericTypographic);

            //      stringFormat.Alignment = StringAlignment.Center;
            leftJustified.LineAlignment = StringAlignment.Center;

            StringFormat rightJustified = new StringFormat(StringFormat.GenericTypographic);

            rightJustified.Alignment     = StringAlignment.Far;
            rightJustified.LineAlignment = StringAlignment.Center;

            StringFormat bothCentered = new StringFormat(StringFormat.GenericTypographic);

            bothCentered.Alignment     = StringAlignment.Center;
            bothCentered.LineAlignment = StringAlignment.Center;

            _fitBoxLocation = new Point(this.ClientSize.Width / 3, 0);
            _fitBoxSize     = new Size(this.ClientSize.Width / 3, _totalSlots * _slotHeight);


            e.Graphics.DrawRectangle(_pen, _fitBoxLocation.X, _fitBoxLocation.Y, _fitBoxSize.Width, _fitBoxSize.Height - 1);


            int currentY = 0;

            // Draw the independent variables

            for (int i = 0; i < _numberOfX; i++)
            {
                Point triangleStart = new Point(_fitBoxLocation.X, currentY + (1 * _slotHeight) / 4);
                Point triangleMidst = new Point(_fitBoxLocation.X + _slotHeight / 2, currentY + _slotHeight / 2);
                Point triangleEnd   = new Point(_fitBoxLocation.X, currentY + (3 * _slotHeight) / 4);

                e.Graphics.DrawLine(_pen, triangleStart, triangleMidst);
                e.Graphics.DrawLine(_pen, triangleMidst, triangleEnd);
                if (_fitElement.FitFunction != null)
                {
                    e.Graphics.DrawString(
                        _fitElement.FitFunction.IndependentVariableName(i),
                        System.Windows.Forms.SystemInformation.MenuFont,
                        System.Drawing.Brushes.Black,
                        new Rectangle(_fitBoxLocation.X + _slotHeight / 2 + 2, currentY, _fitBoxSize.Width - 1 - _slotHeight / 2, _slotHeight),
                        leftJustified
                        );
                }
                currentY += _slotHeight;
            }



            // now draw the dependent variables
            _DependentVariablesY = (_totalSlots - _numberOfY) * _slotHeight;
            currentY             = _DependentVariablesY;

            _errorFunctionWidth = (6 * _slotHeight) / 4;
            _errorFunctionX     = _fitBoxLocation.X - _errorFunctionWidth / 2;

            for (int i = 0; i < _numberOfY; i++)
            {
                Rectangle errorFuncRect = new Rectangle(
                    _errorFunctionX,
                    currentY,
                    _errorFunctionWidth,
                    _slotHeight - 1);


                e.Graphics.FillRectangle(Brushes.WhiteSmoke, errorFuncRect);
                e.Graphics.DrawRectangle(_pen, errorFuncRect);
                if (_fitElement.ErrorEvaluation(i) != null)
                {
                    e.Graphics.DrawString(_fitElement.ErrorEvaluation(i).ShortName,
                                          System.Windows.Forms.SystemInformation.MenuFont,
                                          System.Drawing.Brushes.Black,
                                          errorFuncRect,
                                          bothCentered);
                }



                if (_fitElement.FitFunction != null)
                {
                    e.Graphics.DrawString(
                        _fitElement.FitFunction.DependentVariableName(i),
                        System.Windows.Forms.SystemInformation.MenuFont,
                        System.Drawing.Brushes.Black,
                        new Rectangle(_errorFunctionX + _errorFunctionWidth + (1 * _slotHeight) / 4, currentY, _fitBoxSize.Width - 1 - _slotHeight / 2, _slotHeight),
                        leftJustified
                        );
                }

                currentY += _slotHeight;
            }


            // now draw the internal parameters
            currentY = 0;

            for (int i = 0; i < _numberOfParameter; i++)
            {
                e.Graphics.DrawEllipse(_pen, _fitBoxLocation.X + _fitBoxSize.Width - _slotHeight / 4, currentY + _slotHeight / 4, _slotHeight / 2, _slotHeight / 2);
                if (_fitElement.FitFunction != null)
                {
                    e.Graphics.DrawString(
                        _fitElement.FitFunction.ParameterName(i),
                        System.Windows.Forms.SystemInformation.MenuFont,
                        System.Drawing.Brushes.Black,
                        new Rectangle(_fitBoxLocation.X, currentY, _fitBoxSize.Width - 1 - _slotHeight / 4, _slotHeight),
                        rightJustified
                        );
                }

                currentY += _slotHeight;
            }


            // now draw the external parameters
            currentY = 0;

            _externalParametersX     = _fitBoxLocation.X + _fitBoxSize.Width + _slotHeight / 2;
            _externalParametersWidth = this.ClientSize.Width - _externalParametersX;
            for (int i = 0; i < _numberOfParameter; i++)
            {
                Rectangle rect = new Rectangle(_externalParametersX, currentY, _externalParametersWidth, _slotHeight);

                System.Windows.Forms.ControlPaint.DrawBorder3D(e.Graphics,
                                                               rect.X - 2, rect.Y, rect.Width + 2, rect.Height,
                                                               System.Windows.Forms.Border3DStyle.Etched,
                                                               System.Windows.Forms.Border3DSide.All);

                e.Graphics.DrawString(
                    _fitElement.ParameterName(i),
                    System.Windows.Forms.SystemInformation.MenuFont,
                    System.Drawing.Brushes.Black,
                    new Rectangle(_externalParametersX, currentY, _externalParametersWidth, _slotHeight),
                    leftJustified
                    );

                currentY += _slotHeight;
            }

            // Draw the names of the independent columns
            currentY    = 0;
            _VariablesX = 0;
            _IndependentVariablesWidth = _fitBoxLocation.X - _slotHeight / 4;
            for (int i = 0; i < _numberOfX; i++)
            {
                Rectangle rect = new Rectangle(0, currentY, _IndependentVariablesWidth, _slotHeight);
                System.Windows.Forms.ControlPaint.DrawBorder3D(e.Graphics,
                                                               rect.X, rect.Y, rect.Width + 2, rect.Height,
                                                               System.Windows.Forms.Border3DStyle.Etched,
                                                               System.Windows.Forms.Border3DSide.All);

                INumericColumn col = _fitElement.IndependentVariables(i);
                if (col != null)
                {
                    string name = col.FullName;

                    e.Graphics.DrawString(
                        name,
                        System.Windows.Forms.SystemInformation.MenuFont,
                        System.Drawing.Brushes.Black,
                        rect,
                        rightJustified
                        );
                }
                currentY += _slotHeight;
            }

            {
                // draw the plot range
                var       plotRange   = _fitElement.GetRowRange();
                string    rangestring = "Range: " + plotRange.Start.ToString() + " to " + (plotRange.IsInfinite ? "infinity" : plotRange.Last.ToString());
                Rectangle rect        = new Rectangle(0, currentY, _IndependentVariablesWidth, _slotHeight);
                System.Windows.Forms.ControlPaint.DrawBorder3D(e.Graphics,
                                                               rect.X, rect.Y, rect.Width + 2, rect.Height,
                                                               System.Windows.Forms.Border3DStyle.Etched,
                                                               System.Windows.Forms.Border3DSide.All);
                e.Graphics.DrawString(
                    rangestring,
                    System.Windows.Forms.SystemInformation.MenuFont,
                    System.Drawing.Brushes.Black,
                    rect,
                    rightJustified
                    );
            }
            // Draw the names of the dependent columns
            currentY = _DependentVariablesY;
            _DependentVariablesWidth = _errorFunctionX - (2 * _slotHeight) / 8;
            for (int i = 0; i < _numberOfY; i++)
            {
                Rectangle rect = new Rectangle(0, currentY, _DependentVariablesWidth, _slotHeight);

                System.Windows.Forms.ControlPaint.DrawBorder3D(e.Graphics,
                                                               rect.X, rect.Y, rect.Width + 2, rect.Height,
                                                               System.Windows.Forms.Border3DStyle.Etched,
                                                               System.Windows.Forms.Border3DSide.All);

                INumericColumn col = _fitElement.DependentVariables(i);
                if (col != null)
                {
                    string name = col.FullName;

                    e.Graphics.DrawString(
                        name,
                        System.Windows.Forms.SystemInformation.MenuFont,
                        System.Drawing.Brushes.Black,
                        rect,
                        rightJustified
                        );
                }
                currentY += _slotHeight;
            }

            string fitFuncName = null;

            if (_fitElement.FitFunction == null)
            {
                fitFuncName = "?";
            }
            else if (_fitElement.FitFunction is Altaxo.Scripting.IFitFunctionScriptText)
            {
                fitFuncName = (_fitElement.FitFunction as Altaxo.Scripting.IFitFunctionScriptText).FitFunctionName;
            }
            else
            {
                fitFuncName = _fitElement.FitFunction.ToString();
            }

            Rectangle fitFuncBox = new Rectangle(
                _fitBoxLocation.X + _fitBoxSize.Width / 4,
                _fitBoxLocation.Y + _fitBoxSize.Height / 4,
                _fitBoxSize.Width / 2,
                _fitBoxSize.Height / 2);

            e.Graphics.DrawString(fitFuncName,
                                  System.Windows.Forms.SystemInformation.MenuFont,
                                  System.Drawing.Brushes.Black,
                                  fitFuncBox
                                  );

            if (this._fitFunctionSelected)
            {
                e.Graphics.DrawRectangle(Pens.Red, fitFuncBox);
            }



            base.OnPaint(e);
        }
Exemplo n.º 2
0
        public void EhView_ChooseErrorFunction(int idx)
        {
            SingleInstanceChoice choice = new SingleInstanceChoice(typeof(IVarianceScaling), _doc.ErrorEvaluation(idx));

            object choiceAsObject = choice;

            if (Current.Gui.ShowDialog(ref choiceAsObject, "Select error norm"))
            {
                choice = (SingleInstanceChoice)choiceAsObject;
                _doc.SetErrorEvaluation(idx, (IVarianceScaling)choice.Instance);
                _view.Refresh();
            }
        }