home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 September / Chip_2001-09_cd1.bin / zkuste / delphi / kolekce / d12345 / CHEMPLOT.ZIP / TPlot / Functons.pas < prev    next >
Pascal/Delphi Source File  |  2001-04-26  |  5KB  |  202 lines

  1. unit Functons;
  2.  
  3. {$I Plot.inc}
  4.  
  5. {-----------------------------------------------------------------------------
  6. The contents of this file are subject to the Q Public License
  7. ("QPL"); you may not use this file except in compliance
  8. with the QPL. You may obtain a copy of the QPL from 
  9. the file QPL.html in this distribution, derived from:
  10.  
  11. http://www.trolltech.com/products/download/freelicense/license.html
  12.  
  13. The QPL prohibits development of proprietary software. 
  14. There is a Professional Version of this software available for this. 
  15. Contact sales@chemware.hypermart.net for more information.
  16.  
  17. Software distributed under the QPL is distributed on an "AS IS" basis,
  18. WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the QPL for
  19. the specific language governing rights and limitations under the QPL.
  20.  
  21. The Original Code is: Functions.pas, released 12 April 2001.
  22.  
  23. The Initial Developer of the Original Code is Mat Ballard.
  24. Portions created by Mat Ballard are Copyright (C) 1999 Mat Ballard.
  25. Portions created by Microsoft are Copyright (C) 1998, 1999 Microsoft Corp.
  26. All Rights Reserved.
  27.  
  28. Contributor(s): Mat Ballard                 e-mail: mat.ballard@chemware.hypermart.net.
  29.  
  30. Last Modified: 03/04/2001
  31. Current Version: 2.00
  32.  
  33. You may retrieve the latest version of this file from:
  34.  
  35.         http://Chemware.hypermart.net/
  36.  
  37. This work was created with the Project JEDI VCL guidelines:
  38.  
  39.         http://www.delphi-jedi.org/Jedi:VCLVCL
  40.  
  41. in mind. 
  42.  
  43. Purpose:
  44. To create new series from existing series using mathematical expressions.
  45.  
  46. Known Issues: This requires FUNCTIONS to be defined in Plot.inc, and for the
  47.   TParser10 to be installed in the TPlot/Parser10 subdirectory.
  48. -----------------------------------------------------------------------------}
  49.  
  50. interface
  51.  
  52. uses
  53.   Classes, SysUtils,
  54. {$IFDEF WINDOWS}
  55.   WinTypes, WinProcs,
  56.   Buttons, Controls, Forms, Graphics, StdCtrls,
  57. {$ENDIF}
  58. {$IFDEF WIN32}
  59.   Windows,
  60.   Buttons, Controls, Forms, Graphics, StdCtrls,
  61. {$ENDIF}
  62. {$IFDEF LINUX}
  63.   QButtons, QControls, QForms, QGraphics, QStdCtrls,
  64. {$ENDIF}
  65.  
  66.   Misc;
  67.  
  68. type
  69.   TFunctionsForm = class(TForm)
  70.     HelpBitBtn: TBitBtn;
  71.     CancelBitBtn: TBitBtn;
  72.     OKBitBtn: TBitBtn;
  73.     SeriesLabel: TLabel;
  74.     FunctionMemo: TMemo;
  75.     FunctionComboBox: TComboBox;
  76.     InsertBitBtn: TBitBtn;
  77.     FunctionHintLabel: TLabel;
  78.     procedure FormCreate(Sender: TObject);
  79.     procedure InsertBitBtnClick(Sender: TObject);
  80.     procedure FunctionComboBoxClick(Sender: TObject);
  81.   private
  82.     { Private declarations }
  83.   public
  84.     { Public declarations }
  85.   end;
  86.  
  87. var
  88.   FunctionsForm: TFunctionsForm;
  89.  
  90. implementation
  91.  
  92. {$R *.dfm}
  93.  
  94. const
  95.   FUNCTION_MAX = 30;
  96.   {Functions: array [0..FUNCTION_MAX] of string =
  97.     'PI',
  98.     'COS',
  99.     'SIN',
  100.     'SINH',
  101.     'COSH',
  102.     'TAN',
  103.     'COTAN',
  104.     'ARCTAN',
  105.     'ARG',
  106.     'EXP',
  107.     'LN',
  108.     'LOG10',
  109.     'LOG2',
  110.     'LOGN',
  111.     'SQRT',
  112.     'SQR',
  113.     'POWER',
  114.     'INTPOWER',
  115.     'MIN',
  116.     'MAX',
  117.     'ABS',
  118.     'TRUNC',
  119.     'INT',
  120.     'CEIL',
  121.     'FLOOR',
  122.     'HEAV',
  123.     'SIGN',
  124.     'ZERO',
  125.     'PH',
  126.     'RND',
  127.     'RANDOM'];}
  128.  
  129.   FunctionHints: array [0..FUNCTION_MAX] of string =
  130.     ('3.14159...',
  131.     'Cosine of X',
  132.     'Sine of X',
  133.     'Hyperbloic Sine of X',
  134.     'Hyperbloic Cosine of X',
  135.     'Tangent of X',
  136.     'Cotangent of X',
  137.     'Inverse Tangent of X',
  138.     'ARG',
  139.     'Exponent: e raised to X',
  140.     'Natural logarithm to the base e',
  141.     'Logarithm to base 10',
  142.     'Logarithm to base 2',
  143.     'Logarithm to base N',
  144.     'Square root',
  145.     'Square',
  146.     'Power(Y, X): Y raised to the Xth power',
  147.     'IntPower(Y, N): Y raised to the integer Nth power',
  148.     'Min(A, B): minimium of A and B',
  149.     'Max(A, B): maximium of A and B',
  150.     'Absolute value of X',
  151.     'the value of X rounded toward zero',
  152.     'X rounded toward zero',
  153.     'the lowest integer greater than or equal to X',
  154.     'the highest integer less than or equal to X',
  155.     'Heaviside function is 1 for x=>0, 0 for x<0',
  156.     'Sign is 1 for x>1, 0 for x=0, -1 for x<0',
  157.     'Zero is 0 for x=0, 1 for x<>0),',
  158.     'Ph = x - 2*pi*round(x/2/pi)',
  159.     'Rnd = int(x) * Random',
  160.     'a random number within the range 0 <= X < Range');
  161.  
  162.  
  163. procedure TFunctionsForm.FormCreate(Sender: TObject);
  164. begin
  165.   SetDialogGeometry(TForm(Self), TControl(CancelBitBtn), HelpBitBtn.Left);
  166.   FunctionMemo.Hint :=
  167.     'Type your expression in here:' + #10 +
  168.     'eg:  4 * Series0 + Sqr(Series1) + Exp(Series3';
  169.  
  170.   FunctionComboBox.ItemIndex := 0;
  171.   FunctionHintLabel.Caption := FunctionHints[0];
  172. end;
  173.  
  174. procedure TFunctionsForm.InsertBitBtnClick(Sender: TObject);
  175. begin
  176.   with FunctionMemo do
  177.   begin
  178.     if (SelLength > 0) then
  179.       SelText := FunctionComboBox.Text + '(' +SelText + ')'
  180.      else
  181. {$IFDEF MSWINDOWS}
  182.       Lines[CaretPos.y] :=
  183.         Copy (Lines[CaretPos.y], 1, CaretPos.x) +
  184.         FunctionComboBox.Text + '() + ' +
  185.         Copy (Lines[CaretPos.y], CaretPos.x+1, 999);
  186. {$ENDIF}
  187. {$IFDEF LINUX}
  188.       Lines[CaretPos.Line] :=
  189.         Copy (Lines[CaretPos.Line], 1, CaretPos.Col) +
  190.         FunctionComboBox.Text + '() + ' +
  191.         Copy (Lines[CaretPos.Line], CaretPos.Col+1, 999);
  192. {$ENDIF}
  193.   end;
  194. end;
  195.  
  196. procedure TFunctionsForm.FunctionComboBoxClick(Sender: TObject);
  197. begin
  198.   FunctionHintLabel.Caption := FunctionHints[FunctionComboBox.ItemIndex];
  199. end;
  200.  
  201. end.
  202.