home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2001 October
/
Chip_2001-10_cd1.bin
/
zkuste
/
delphi
/
kompon
/
d123456
/
CHEMPLOT.ZIP
/
TPlot
/
Functons.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
2001-07-24
|
8KB
|
253 lines
unit Functons;
{$I Plot.inc}
{-----------------------------------------------------------------------------
The contents of this file are subject to the Q Public License
("QPL"); you may not use this file except in compliance
with the QPL. You may obtain a copy of the QPL from
the file QPL.html in this distribution, derived from:
http://www.trolltech.com/products/download/freelicense/license.html
The QPL prohibits development of proprietary software.
There is a Professional Version of this software available for this.
Contact sales@chemware.hypermart.net for more information.
Software distributed under the QPL is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the QPL for
the specific language governing rights and limitations under the QPL.
The Original Code is: Functions.pas, released 12 April 2001.
The Initial Developer of the Original Code is Mat Ballard.
Portions created by Mat Ballard are Copyright (C) 1999 Mat Ballard.
Portions created by Microsoft are Copyright (C) 1998, 1999 Microsoft Corp.
All Rights Reserved.
Contributor(s): Mat Ballard e-mail: mat.ballard@chemware.hypermart.net.
Last Modified: 03/04/2001
Current Version: 2.00
You may retrieve the latest version of this file from:
http://Chemware.hypermart.net/
This work was created with the Project JEDI VCL guidelines:
http://www.delphi-jedi.org/Jedi:VCLVCL
in mind.
Purpose:
To create new series from existing series using mathematical expressions.
Known Issues: This requires FUNCTIONS to be defined in Plot.inc, and for the
TParser10 to be installed in the TPlot/Parser10 subdirectory.
-----------------------------------------------------------------------------}
interface
uses
Classes, SysUtils,
{$IFDEF WINDOWS}
WinTypes, WinProcs,
Buttons, Controls, Forms, Graphics, StdCtrls,
{$ENDIF}
{$IFDEF WIN32}
Windows,
Buttons, Controls, Forms, Graphics, StdCtrls,
{$ENDIF}
{$IFDEF LINUX}
QButtons, QControls, QForms, QGraphics, QStdCtrls,
{$ENDIF}
Parser10,
Misc, Plotdefs;
type
TFunctionsForm = class(TForm)
HelpBitBtn: TBitBtn;
CancelBitBtn: TBitBtn;
OKBitBtn: TBitBtn;
SeriesLabel: TLabel;
FunctionMemo: TMemo;
FunctionComboBox: TComboBox;
InsertBitBtn: TBitBtn;
FunctionHintLabel: TLabel;
TestBitBtn: TBitBtn;
procedure FormCreate(Sender: TObject);
procedure InsertBitBtnClick(Sender: TObject);
procedure FunctionComboBoxClick(Sender: TObject);
procedure TestBitBtnClick(Sender: TObject);
private
{ Private declarations }
public
SeriesCount: Integer;
{You have to set the SeriesCount for Test-ing to work}
{$IFNDEF LANG_ENGLISH}
procedure DoCaptionsFromResource;
{$ENDIF}
procedure DoHintsFromResource;
end;
var
FunctionsForm: TFunctionsForm;
implementation
{$R *.dfm}
const
FUNCTION_MAX = 30;
{Functions: array [0..FUNCTION_MAX] of string =
['PI', 'COS', 'SIN', 'SINH', 'COSH',
'TAN', 'COTAN', 'ARCTAN', 'ARG', 'EXP',
'LN', 'LOG10', 'LOG2', 'LOGN', 'SQRT',
'SQR', 'POWER', 'INTPOWER', 'MIN', 'MAX',
'ABS', 'TRUNC', 'INT', 'CEIL', 'FLOOR',
'HEAV', 'SIGN', 'ZERO', 'PH', 'RND',
'RANDOM'];}
FunctionHints: array [0..FUNCTION_MAX] of string =
(sFHint0, sFHint1, sFHint2, sFHint3, sFHint4,
sFHint5, sFHint6, sFHint7, sFHint8, sFHint9,
sFHint10, sFHint11, sFHint12, sFHint13, sFHint14,
sFHint15, sFHint16, sFHint17, sFHint18, sFHint19,
sFHint20, sFHint21, sFHint22, sFHint23, sFHint24,
sFHint25, sFHint26, sFHint27, sFHint28, sFHint29,
sFHint30);
{------------------------------------------------------------------------------
Procedure: TFunctionsForm.FormCreate
Description: standard FormCreate procedure
Author: Mat Ballard
Date created: 04/25/2000
Date modified: 04/25/2000 by Mat Ballard
Purpose: sets the position and populates the Color combo
Known Issues:
------------------------------------------------------------------------------}
procedure TFunctionsForm.FormCreate(Sender: TObject);
var
i: Integer;
begin
{$IFNDEF LANG_ENGLISH}
DoCaptionsFromResource;
{$ENDIF}
DoHintsFromResource;
{set combo and edit box widths:}
for i := 0 to Self.ComponentCount - 1 do
if (Self.Components[i] is TBitBtn) then
TControl(Self.Components[i]).Width := 97;
FunctionComboBox.Width := 97;
SetDialogGeometry(TForm(Self), TControl(OKBitBtn), HelpBitBtn.Left);
FunctionMemo.Width := OKBitBtn.Left + OKBitBtn.Width - HelpBitBtn.Left;
FunctionComboBox.ItemIndex := 0;
FunctionHintLabel.Caption := FunctionHints[0];
end;
{------------------------------------------------------------------------------
Procedure: TFunctionsForm.DoCaptionsFromResource
Description: standard loading of labels from resources
Author: Mat Ballard
Date created: 06/25/2001
Date modified: 06/25/2001 by Mat Ballard
Purpose: display in different languages
Known Issues:
------------------------------------------------------------------------------}
{$IFNDEF LANG_ENGLISH}
procedure TFunctionsForm.DoCaptionsFromResource;
begin
Self.Caption := sFunctions;
InsertBitBtn.Caption := sInsert;
TestBitBtn.Caption := sTest;
HelpBitBtn.Caption := sHelp;
OKBitBtn.Caption := sOK;
CancelBitBtn.Caption := sCancel;
end;
{$ENDIF}
{------------------------------------------------------------------------------
Procedure: TFunctionsForm.DoHintsFromResource
Description: standard loading of labels from resources
Author: Mat Ballard
Date created: 06/25/2001
Date modified: 06/25/2001 by Mat Ballard
Purpose: display in different languages
Known Issues:
------------------------------------------------------------------------------}
procedure TFunctionsForm.DoHintsFromResource;
begin
InsertBitBtn.Hint := sInsertHint;
FunctionComboBox.Hint := sAvailableFunctions;
FunctionMemo.Hint := sFunctionMemoHint;
TestBitBtn.Hint := sTestHint;
end;
procedure TFunctionsForm.InsertBitBtnClick(Sender: TObject);
begin
with FunctionMemo do
begin
if (SelLength > 0) then
SelText := FunctionComboBox.Text + '(' +SelText + ')'
else
{$IFDEF MSWINDOWS}
Lines[CaretPos.y] :=
Copy (Lines[CaretPos.y], 1, CaretPos.x) +
FunctionComboBox.Text + '() + ' +
Copy (Lines[CaretPos.y], CaretPos.x+1, 999);
{$ENDIF}
{$IFDEF LINUX}
Lines[CaretPos.Line] :=
Copy (Lines[CaretPos.Line], 1, CaretPos.Col) +
FunctionComboBox.Text + '() + ' +
Copy (Lines[CaretPos.Line], CaretPos.Col+1, 999);
{$ENDIF}
end;
end;
procedure TFunctionsForm.FunctionComboBoxClick(Sender: TObject);
begin
FunctionHintLabel.Caption := FunctionHints[FunctionComboBox.ItemIndex];
end;
{------------------------------------------------------------------------------
Procedure: TFunctionsForm.TestBitBtnClick
Description: checks the validity of the user's mathematical expression
Author: Mat Ballard
Date created: 06/25/2001
Date modified: 06/25/2001 by Mat Ballard
Purpose: must be used before "OK" is enabled
Known Issues:
------------------------------------------------------------------------------}
procedure TFunctionsForm.TestBitBtnClick(Sender: TObject);
var
i: Integer;
TheParser: TParser;
TheExpression: String;
TheData: array [0..99] of PParserFloat;
begin
TheParser := TParser.Create(nil);
TheExpression := '';
{read the equation:}
for i := 0 to FunctionMemo.Lines.Count-1 do
TheExpression := TheExpression + FunctionMemo.Lines[i];
TheExpression := Misc.CleanString(TheExpression, ' ');
{try to run the Parser:}
try
{Set up the variables:}
for i := 0 to SeriesCount-1 do
TheData[i] := TheParser.SetVariable(Format(UpperCase(sSeries) + '%d', [i]), 0);
{Set up equation:}
TheParser.Expression := TheExpression;
OKBitBtn.Enabled := TRUE;
finally
TheParser.Free;
end;
end;
end.