home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 September / Chip_2001-09_cd1.bin / zkuste / delphi / kolekce / d12345 / CHEMPLOT.ZIP / TPlot / Ptedit.pas < prev    next >
Pascal/Delphi Source File  |  2001-05-02  |  11KB  |  367 lines

  1. unit Ptedit;
  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: PtEdit.pas, released 12 September 2000.
  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: 12/06/2000
  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 facilitate user manipluation of Point values.
  45.  
  46. Known Issues: BCB problems with Spinedit - resolved by dynamic creation
  47.               of different controls depending on compiler
  48. -----------------------------------------------------------------------------}
  49.  
  50. interface
  51.  
  52. uses
  53.   Classes, SysUtils,
  54. {$IFDEF WINDOWS}
  55.   WinTypes, WinProcs,
  56.   Buttons, ComCtrls, Controls, Forms, Graphics, StdCtrls,
  57.   Spin,
  58. {$ENDIF}
  59. {$IFDEF WIN32}
  60.   Windows,
  61.   Buttons, ComCtrls, Controls, Forms, Graphics, StdCtrls,
  62.   {$IFDEF DELPHI}
  63.   Spin,
  64.   {$ENDIF}
  65. {$ENDIF}
  66. {$IFDEF LINUX}
  67.   QButtons, QComCtrls, QControls, QForms, QGraphics, QStdCtrls,
  68. {$ENDIF}
  69.  
  70.   Axis, Misc, Nedit, Slidebar;
  71.  
  72. type
  73.   TPointEditorForm = class(TForm)
  74.     HelpBitBtn: TBitBtn;
  75.     CancelBitBtn: TBitBtn;
  76.     OKBitBtn: TBitBtn;
  77.     DeleteBitBtn: TBitBtn;
  78.     AddBitBtn: TBitBtn;
  79.     DataGroupBox: TGroupBox;
  80.     Label1: TLabel;
  81.     YDataLabel: TLabel;
  82.     ScreenGroupBox: TGroupBox;
  83.     Label3: TLabel;
  84.     YScreenLabel: TLabel;
  85.     DetailsLabel: TLabel;
  86.     Label5: TLabel;
  87.     XStringDataEdit: TEdit;
  88.     XScreenNEdit: TNEdit;
  89.     YScreenNEdit: TNEdit;
  90.     XDataNEdit: TNEdit;
  91.     YDataNEdit: TNEdit;
  92.     ApplyBitBtn: TBitBtn;
  93.     PointSlideBar: TSlideBar;
  94.  
  95.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  96.     procedure FormCreate(Sender: TObject);
  97.     procedure CancelBitBtnClick(Sender: TObject);
  98.     procedure PointSlideBarChange(Sender: TObject);
  99.     procedure ApplyBitBtnClick(Sender: TObject);
  100.     procedure XDataNEditKeyPress(Sender: TObject; var Key: Char);
  101.     procedure XScreenNEditKeyPress(Sender: TObject; var Key: Char);
  102. {$IFDEF MSWINDOWS}
  103.     procedure PointEditChange(Sender: TObject);
  104. {$ENDIF}
  105. {$IFDEF LINUX}
  106.     procedure PointEditChanged(Sender: TObject; NewValue: Integer);
  107. {$ENDIF}
  108.   private
  109.     XData, YData: pSingleArray;
  110.     XStringData: TStringList;
  111.     XAxis, YAxis: TAxis;
  112.     SpinLock: Boolean;
  113.  
  114.   public
  115. {$IFDEF BCB}
  116.     PointNEdit: TNEdit;
  117.     PointUpDown: TUpDown;
  118. {$ELSE}
  119.     PointSpinEdit: TSpinEdit;
  120. {$ENDIF}
  121.     TheSeries: TObject;
  122.  
  123.     procedure Init(
  124.       FXData, FYData: pSingleArray;
  125.       FXStringData: TStringList;
  126.       FXAxis, FYAxisCurrent: TAxis);
  127.     procedure FillData(ThePoint: Integer);
  128.   end;
  129.  
  130. var
  131.   PointNEditorForm: TPointEditorForm;
  132.  
  133. implementation
  134.  
  135. {$R *.dfm}
  136.  
  137. uses
  138.   Data;
  139.  
  140. {------------------------------------------------------------------------------
  141.     Procedure: TPointEditorForm.FormCreate
  142.   Description: standard FormCreate procedure
  143.        Author: Mat Ballard
  144.  Date created: 04/25/2000
  145. Date modified: 04/25/2000 by Mat Ballard
  146.       Purpose: sets the position
  147.  Known Issues:
  148.  ------------------------------------------------------------------------------}
  149. procedure TPointEditorForm.FormCreate(Sender: TObject);
  150. begin
  151.   SetDialogGeometry(Self, ApplyBitBtn, DetailsLabel.Left);
  152.  
  153.   SpinLock := FALSE;
  154.  
  155. {$IFDEF BCB}
  156.   PointNEdit := TNEdit.Create(Self);
  157.   PointNEdit.Parent := Self;
  158.   PointNEdit.Left := PointSlideBar.Left + PointSlideBar.Width + 1;
  159.   PointNEdit.Top := PointSlideBar.Top;
  160.   PointNEdit.OnChange := PointEditChange;
  161.  
  162.   PointUpDown := TUpDown.Create(Self);
  163.   PointUpDown.Parent := Self;
  164.   PointUpDown.Associate := PointNEdit;
  165.  
  166.   {PointNEdit.Right := ScreenGroupBox.Right - PointUpDown.Width;}
  167.   PointNEdit.Width :=
  168.     ScreenGroupBox.Left + ScreenGroupBox.Width -
  169.     PointUpDown.Width - PointNEdit.Left;
  170.   //PointNEdit.TabOrder := 1;
  171.  
  172. {$ELSE}
  173.   PointSpinEdit := TSpinEdit.Create(Self);
  174.   PointSpinEdit.Parent := Self;
  175.   PointSpinEdit.Left := PointSlideBar.Left + PointSlideBar.Width + 1;
  176.   PointSpinEdit.Top := PointSlideBar.Top;
  177.   {$IFDEF MSWINDOWS}
  178.   PointSpinEdit.OnChange := PointEditChange;
  179.   {$ENDIF}
  180.   {$IFDEF LINUX}
  181.   PointSpinEdit.OnChanged := PointEditChanged;
  182.   {$ENDIF}
  183.   {PointSpinEdit.Right := ScreenGroupBox.Right;}
  184.   PointSpinEdit.Width :=
  185.     ScreenGroupBox.Left + ScreenGroupBox.Width -
  186.     PointSpinEdit.Left;
  187.   //PointSpinEdit.TabOrder := 1;
  188. {$ENDIF}
  189. end;
  190.  
  191. {------------------------------------------------------------------------------
  192.     Procedure: TPointEditorForm.Init
  193.   Description: initializes pointers to data and axes
  194.        Author: Mat Ballard
  195.  Date created: 04/25/2000
  196. Date modified: 05/04/2000 by Mat Ballard
  197.       Purpose: user management of data
  198.  Known Issues:
  199.  ------------------------------------------------------------------------------}
  200. procedure TPointEditorForm.Init(
  201.   FXData, FYData: pSingleArray;
  202.   FXStringData: TStringList;
  203.   FXAxis, FYAxisCurrent: TAxis);
  204. begin
  205.   XData := FXData;
  206.   YData := FYData;
  207.   XStringData := FXStringData;
  208.   XAxis := FXAxis;
  209.   YAxis := FYAxisCurrent;
  210. end;
  211.  
  212. {------------------------------------------------------------------------------
  213.     Procedure: TPointEditorForm.FormClose
  214.   Description: standard FormClose procedure
  215.        Author: Mat Ballard
  216.  Date created: 04/25/2000
  217. Date modified: 04/25/2000 by Mat Ballard
  218.       Purpose: checks for valid user input
  219.  Known Issues:
  220.  ------------------------------------------------------------------------------}
  221. procedure TPointEditorForm.FormClose(Sender: TObject;
  222.   var Action: TCloseAction);
  223. var
  224.   Test: Single;
  225. begin
  226. {Check that floating point values are valid:}
  227.   Action := caHide;
  228.   if (DataGroupBox.Enabled = TRUE) then
  229.   begin
  230.     try
  231.       Test := XDataNEdit.AsReal;
  232.       Test := Test + YDataNEdit.AsReal;
  233. {We do the above and below the squelch the warning messages.}
  234.       Tag := Trunc(Test);
  235.     except
  236. {Prevent closure:}
  237.       Action := caNone;
  238.     end;
  239.   end;
  240. end;
  241.  
  242. {------------------------------------------------------------------------------
  243.     Procedure: TPointEditorForm.FillData
  244.   Description: Gets the point data
  245.        Author: Mat Ballard
  246.  Date created: 04/25/2000
  247. Date modified: 04/25/2000 by Mat Ballard
  248.       Purpose: Synchronization of the two controls
  249.  Known Issues:
  250.  ------------------------------------------------------------------------------}
  251. procedure TPointEditorForm.FillData(ThePoint: Integer);
  252. begin
  253.   if ((ThePoint < 0) or (ThePoint > PointSlideBar.Position)) then raise
  254.     ERangeError.CreateFmt(
  255.       'FillData: the Point number %d is not within the valid range of 0 .. %d',
  256.       [ThePoint, PointSlideBar.Position]);
  257.  
  258.   XDataNEdit.AsReal := XData^[ThePoint];
  259.   YDataNEdit.AsReal := YData^[ThePoint];
  260.  
  261.   XScreenNEdit.AsInteger := XAxis.FofX(XData^[ThePoint]);
  262.   YScreenNEdit.AsInteger := YAxis.FofY(YData^[ThePoint]);
  263.  
  264.   if ((XStringData <> nil) and
  265.       (XStringData.Count > ThePoint)) then
  266.   begin
  267.     XStringDataEdit.Text := XStringData.Strings[ThePoint];
  268.     XStringDataEdit.Visible := TRUE;
  269.   end
  270.   else
  271.     XStringDataEdit.Visible := FALSE;
  272. end;
  273.  
  274. {------------------------------------------------------------------------------
  275.     Procedure: TPointEditorForm.CancelBitBtnClick
  276.   Description: Standard Cancel button event handler
  277.        Author: Mat Ballard
  278.  Date created: 04/25/2000
  279. Date modified: 04/25/2000 by Mat Ballard
  280.       Purpose: Disables the DataGroupBox, and hence prevents checking of edit boxes for validity
  281.  Known Issues:
  282.  ------------------------------------------------------------------------------}
  283. procedure TPointEditorForm.CancelBitBtnClick(Sender: TObject);
  284. begin
  285.   DataGroupBox.Enabled := FALSE;
  286. end;
  287.  
  288. {------------------------------------------------------------------------------
  289.     Procedure: TPointEditorForm.PointSlideBarChange
  290.   Description: Sets the value of PointNEdit
  291.        Author: Mat Ballard
  292.  Date created: 04/25/2000
  293. Date modified: 04/25/2000 by Mat Ballard
  294.       Purpose: Synchronization of the two controls
  295.  Known Issues:
  296.  ------------------------------------------------------------------------------}
  297. procedure TPointEditorForm.PointSlideBarChange(Sender: TObject);
  298. begin
  299.   if (not SpinLock) then
  300.   begin
  301.     SpinLock := TRUE;
  302. {$IFDEF BCB}
  303.     PointNEdit.AsInteger := PointSlideBar.Position;
  304. {$ELSE}
  305.     PointSpinEdit.Value := PointSlideBar.Position;
  306. {$ENDIF}
  307.     FillData(PointSlideBar.Position);
  308.     SpinLock := FALSE;
  309.   end;
  310.   //DataGroupBox.Enabled := TRUE;
  311.   //ScreenGroupBox.Enabled := TRUE;
  312. end;
  313.  
  314. {$IFDEF MSWINDOWS}
  315. procedure TPointEditorForm.PointEditChange(Sender: TObject);
  316. begin
  317.   if (not SpinLock) then
  318.   begin
  319.     SpinLock := TRUE;
  320. {$IFDEF BCB}
  321.     PointSlideBar.Position := PointNEdit.AsInteger;
  322. {$ELSE}
  323.     PointSlideBar.Position := PointSpinEdit.Value;
  324. {$ENDIF}
  325.     FillData(PointSlideBar.Position);
  326.     SpinLock := FALSE;
  327.   end;
  328. end;
  329. {$ENDIF}
  330.  
  331. {$IFDEF LINUX}
  332. procedure TPointEditorForm.PointEditChanged(Sender: TObject; NewValue: Integer);
  333. begin
  334.   if (not SpinLock) then
  335.   begin
  336.     SpinLock := TRUE;
  337. {$IFDEF BCB}
  338.     PointSlideBar.Position := PointNEdit.AsInteger;
  339. {$ELSE}
  340.     PointSlideBar.Position := NewValue;
  341. {$ENDIF}
  342.     FillData(PointSlideBar.Position);
  343.     SpinLock := FALSE;
  344.   end;
  345. end;
  346. {$ENDIF}
  347.  
  348. procedure TPointEditorForm.ApplyBitBtnClick(Sender: TObject);
  349. begin
  350.   TSeries(TheSeries).ApplyPointChange(Self, mrOK);
  351. end;
  352.  
  353. procedure TPointEditorForm.XDataNEditKeyPress(Sender: TObject;
  354.   var Key: Char);
  355. begin
  356.   ScreenGroupBox.Enabled := FALSE;
  357. end;
  358.  
  359. procedure TPointEditorForm.XScreenNEditKeyPress(Sender: TObject;
  360.   var Key: Char);
  361. begin
  362.   DataGroupBox.Enabled := FALSE;
  363. end;
  364.  
  365.  
  366. end.
  367.