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

  1. unit Seredit;
  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: SerEdit.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: 02/25/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 Series properties
  45.  
  46. Known Issues:
  47. -----------------------------------------------------------------------------}
  48.  
  49. interface
  50.  
  51. uses
  52.   Classes, SysUtils, TypInfo,
  53. {$IFDEF WINDOWS}
  54.   WinTypes, WinProcs,
  55.   Buttons, Controls, {Dialogs,} Forms, Graphics, StdCtrls,
  56. {$ENDIF}
  57. {$IFDEF WIN32}
  58.   Windows,
  59.   Buttons, Controls, {Dialogs,} Forms, Graphics, StdCtrls,
  60. {$ENDIF}
  61. {$IFDEF LINUX}
  62.   QButtons, QControls, QDialogs, QExtCtrls, QForms, QGraphics, QStdCtrls,
  63. {$ENDIF}
  64.  
  65.   Misc, NEdit, Plotdefs, Coloredt;
  66.  
  67. type
  68.   TSeriesProperty = record
  69.     PenColor: TColor;
  70.     PenWidthIndex: Integer;
  71.     PenStyleIndex: Integer;
  72.     BrushColor: TColor;
  73.     BrushStyleIndex: Integer;
  74.     SymbolIndex: Integer;
  75.     SymbolSize: Integer;
  76.     YAxisIndex: Byte;
  77.     DeltaX: Integer;
  78.     DeltaY: Integer;
  79.     XDataIndependent: Boolean;
  80.     ExternalXSeries: Boolean;
  81.     Visible: Boolean;
  82.   end;
  83.  
  84.   TSeriesEditorForm = class(TForm)
  85.     HelpBitBtn: TBitBtn;
  86.     CancelBitBtn: TBitBtn;
  87.     OKBitBtn: TBitBtn;
  88.     Label1: TLabel;
  89.     Label3: TLabel;
  90.     VisibleCheckBox: TCheckBox;
  91.     SymbolComboBox: TComboBox;
  92.     PenGroupBox: TGroupBox;
  93.     Label2: TLabel;
  94.     Label4: TLabel;
  95.     PenWidthComboBox: TComboBox;
  96.     PenStyleComboBox: TComboBox;
  97.     Label5: TLabel;
  98.     NoComboBox: TComboBox;
  99.     GroupBox1: TGroupBox;
  100.     Label6: TLabel;
  101.     Label7: TLabel;
  102.     Label8: TLabel;
  103.     NoLabel: TLabel;
  104.     NameEdit: TEdit;
  105.     Label10: TLabel;
  106.     YAxisComboBox: TComboBox;
  107.     XDataIndependentCheckBox: TCheckBox;
  108.     BrushGroupBox: TGroupBox;
  109.     Label11: TLabel;
  110.     Label13: TLabel;
  111.     BrushStyleComboBox: TComboBox;
  112.     SymbolSizeNEdit: TNEdit;
  113.     DeltaXNEdit: TNEdit;
  114.     DeltaYNEdit: TNEdit;
  115.     PenColorEdit: TColorEdit;
  116.     BrushColorEdit: TColorEdit;
  117.     ApplyBitBtn: TBitBtn;
  118.     procedure FormCreate(Sender: TObject);
  119.     procedure FormDestroy(Sender: TObject);
  120.     procedure NoComboBoxClick(Sender: TObject);
  121.     procedure PenWidthComboBoxClick(Sender: TObject);
  122.     procedure PenStyleComboBoxClick(Sender: TObject);
  123.     procedure SymbolComboBoxClick(Sender: TObject);
  124.     procedure VisibleCheckBoxClick(Sender: TObject);
  125.     procedure YAxisComboBoxClick(Sender: TObject);
  126.     procedure DeltaXNEditChange(Sender: TObject);
  127.     procedure DeltaYNEditChange(Sender: TObject);
  128.     procedure SymbolSizeNEditChange(Sender: TObject);
  129.     procedure NameEditChange(Sender: TObject);
  130.     procedure XDataIndependentCheckBoxClick(Sender: TObject);
  131.     procedure PenColorEditChange(Sender: TObject);
  132.     procedure BrushColorEditChange(Sender: TObject);
  133.     procedure ApplyBitBtnClick(Sender: TObject);
  134.   private
  135.     pASP: ^TSeriesProperty;
  136.     CurrentIndex: Integer;
  137.  
  138.   public
  139.     SeriesPropertyList: TList;
  140.     SeriesNames: TStringList;
  141.     ThePlot: TObject;
  142.     
  143.     function AddSeries(AName: String; ASeriesProperty: TSeriesProperty): Integer;
  144.     procedure SelectSeries(Index: Integer);
  145.   end;
  146.  
  147. var
  148.   SeriesEditorForm: TSeriesEditorForm;
  149.  
  150. implementation
  151.  
  152. {$R *.dfm}
  153.  
  154. uses
  155.   Plot;
  156.   
  157. {------------------------------------------------------------------------------
  158.     Procedure: TSeriesEditorForm.FormCreate
  159.   Description: standard FormCreate procedure
  160.        Author: Mat Ballard
  161.  Date created: 04/25/2000
  162. Date modified: 04/25/2000 by Mat Ballard
  163.       Purpose: sets the position, populates the PenColor combo, and initializes SeriesNames and SeriesPropertyList
  164.  Known Issues:
  165.  ------------------------------------------------------------------------------}
  166. procedure TSeriesEditorForm.FormCreate(Sender: TObject);
  167. var
  168.   i: Integer;
  169. begin
  170.   SetDialogGeometry(Self, ApplyBitBtn, NoLabel.Left);
  171.  
  172. {Populate the combo boxes:}
  173.   for i := 0 to Ord(High(TBrushStyle)) do
  174.     BrushStyleComboBox.Items.Add(Copy(GetEnumName(TypeInfo(TBrushStyle), i), 3, 99));
  175.   for i := 0 to 20 do
  176.     PenWidthComboBox.Items.Add(IntToStr(i));
  177.   for i := 0 to Ord(High(TPenStyle)) do
  178.     PenStyleComboBox.Items.Add(Copy(GetEnumName(TypeInfo(TPenStyle), i), 3, 99));
  179.   for i := 0 to Ord(High(TSymbol)) do
  180.     SymbolComboBox.Items.Add(Copy(GetEnumName(TypeInfo(TSymbol), i), 3, 99));
  181.  
  182. {set combo and edit box widths:}
  183.   for i := 0 to Self.ComponentCount - 1 do
  184.     if ((Self.Components[i] is TEdit) or
  185.         (Self.Components[i] is TNEdit) or
  186.         (Self.Components[i] is TColorEdit) or
  187.         (Self.Components[i] is TComboBox)) then
  188.       TControl(Self.Components[i]).Width := 88;
  189. {the exceptions:}
  190.   NoComboBox.Width := 48;
  191.   SymbolSizeNEdit.Width := 48;
  192.   YAxisComboBox.Width := 145;
  193.  
  194.   SymbolComboBox.ItemIndex := 0;
  195.   SeriesPropertyList := TList.Create;
  196.   SeriesNames := TStringList.Create;
  197. end;
  198.  
  199. {------------------------------------------------------------------------------
  200.     Procedure: TSeriesEditorForm.FormDestroy
  201.   Description: standard FormDestroy procedure
  202.        Author: Mat Ballard
  203.  Date created: 04/25/2000
  204. Date modified: 04/25/2000 by Mat Ballard
  205.       Purpose: frees the SeriesNames and SeriesPropertyList
  206.  Known Issues:
  207.  ------------------------------------------------------------------------------}
  208. procedure TSeriesEditorForm.FormDestroy(Sender: TObject);
  209. var
  210.   i: Integer;
  211. begin
  212.   for i := 0 to SeriesPropertyList.Count-1 do
  213.     FreeMem(SeriesPropertyList.Items[i], SizeOf(TSeriesProperty));
  214.  
  215.   SeriesPropertyList.Free;
  216.   SeriesNames.Free;
  217. end;
  218.  
  219. {------------------------------------------------------------------------------
  220.      Function: TSeriesEditorForm.AddSeries
  221.   Description: adds a new series to the list
  222.        Author: Mat Ballard
  223.  Date created: 04/25/2000
  224. Date modified: 04/25/2000 by Mat Ballard
  225.       Purpose: stores the Series properties
  226.  Known Issues:
  227.  ------------------------------------------------------------------------------}
  228. function TSeriesEditorForm.AddSeries(AName: String; ASeriesProperty: TSeriesProperty): Integer;
  229. var
  230.   i: Integer;
  231.   pDestination: Pointer;
  232.   pSource,
  233.   pDest: PChar;
  234. begin
  235.   NoComboBox.Items.Add(IntToStr(SeriesNames.Count));
  236.  
  237.   SeriesNames.Add(AName);
  238.  
  239.   GetMem(pDestination, SizeOf(ASeriesProperty));
  240.   pSource := @ASeriesProperty;
  241. {NB: this causes terminal access violations:
  242.   System.Move(pSource, pDestination, SizeOf(TSeriesProperty));}
  243.   pDest := pDestination;
  244.   for i := 1 to SizeOf(ASeriesProperty) do
  245.   begin
  246.     pDest^ := pSource^;
  247.     Inc(pSource);
  248.     Inc(pDest);
  249.   end;
  250.  
  251.   SeriesPropertyList.Add(pDestination);
  252.   AddSeries := SeriesPropertyList.Count;
  253. end;
  254.  
  255. {------------------------------------------------------------------------------
  256.     Procedure: TSeriesEditorForm.SelectSeries
  257.   Description: responds to selection of a new Series
  258.        Author: Mat Ballard
  259.  Date created: 04/25/2000
  260. Date modified: 04/25/2000 by Mat Ballard
  261.       Purpose: manage user input
  262.  Known Issues:
  263.  ------------------------------------------------------------------------------}
  264. procedure TSeriesEditorForm.SelectSeries(Index: Integer);
  265. begin
  266.   pASP := SeriesPropertyList.Items[Index];
  267.   CurrentIndex := Index;
  268.  
  269.   NameEdit.Text := SeriesNames.Strings[Index];
  270.  
  271.   PenColorEdit.Color := pASP^.PenColor;
  272.   PenColorEdit.Text := ColorToString(pASP^.PenColor)+ ' ...';
  273.   PenWidthComboBox.ItemIndex := pASP^.PenWidthIndex;
  274.   PenStyleComboBox.ItemIndex := pASP^.PenStyleIndex;
  275.  
  276.   BrushColorEdit.Color := pASP^.BrushColor;
  277.   BrushColorEdit.Text := ColorToString(pASP^.BrushColor)+ ' ...';
  278.   BrushStyleComboBox.ItemIndex := pASP^.BrushStyleIndex;
  279.   SymbolComboBox.ItemIndex := pASP^.SymbolIndex;
  280.   SymbolSizeNEdit.AsInteger := pASP^.SymbolSize;
  281. {We define YAxisIndex to run from 1 to FAxisList.Count-1}
  282.   YAxisComboBox.ItemIndex := pASP^.YAxisIndex-1;
  283.   DeltaXNEdit.AsInteger := pASP^.DeltaX;
  284.   DeltaYNEdit.AsInteger := pASP^.DeltaY;
  285.   VisibleCheckBox.Checked := pASP^.Visible;
  286.   XDataIndependentCheckBox.Checked := pASP^.XDataIndependent;
  287.   XDataIndependentCheckBox.Visible := pASP^.ExternalXSeries;
  288. end;
  289.  
  290. {------------------------------------------------------------------------------
  291.     Procedure: TSeriesEditorForm.NoComboBoxClick
  292.   Description: responds to user selection of a new Series
  293.        Author: Mat Ballard
  294.  Date created: 04/25/2000
  295. Date modified: 04/25/2000 by Mat Ballard
  296.       Purpose: manage user input
  297.  Known Issues: see SelectSeries above
  298.  ------------------------------------------------------------------------------}
  299. procedure TSeriesEditorForm.NoComboBoxClick(Sender: TObject);
  300. begin
  301.   SelectSeries(NoComboBox.ItemIndex);
  302. end;
  303.  
  304. {------------------------------------------------------------------------------
  305.     Procedure: TSeriesEditorForm.PenWidthComboBoxClick
  306.   Description: responds to selection of a new Pen Width for the Series
  307.        Author: Mat Ballard
  308.  Date created: 04/25/2000
  309. Date modified: 04/25/2000 by Mat Ballard
  310.       Purpose: manage user input
  311.  Known Issues:
  312.  ------------------------------------------------------------------------------}
  313. procedure TSeriesEditorForm.PenWidthComboBoxClick(Sender: TObject);
  314. begin
  315.   pASP^.PenWidthIndex := PenWidthComboBox.ItemIndex;
  316. end;
  317.  
  318. {------------------------------------------------------------------------------
  319.     Procedure: TSeriesEditorForm.PenStyleComboBoxClick
  320.   Description: responds to selection of a new Pen Style for the Series
  321.        Author: Mat Ballard
  322.  Date created: 04/25/2000
  323. Date modified: 04/25/2000 by Mat Ballard
  324.       Purpose: manage user input
  325.  Known Issues:
  326.  ------------------------------------------------------------------------------}
  327. procedure TSeriesEditorForm.PenStyleComboBoxClick(Sender: TObject);
  328. begin
  329.   pASP^.PenStyleIndex := PenStyleComboBox.ItemIndex;
  330.   if (PenStyleComboBox.ItemIndex > Ord(psSolid)) then
  331.     PenWidthComboBox.ItemIndex := 1;
  332. end;
  333.  
  334. {------------------------------------------------------------------------------
  335.     Procedure: TSeriesEditorForm.SymbolComboBoxClick
  336.   Description: responds to selection of a new Symbol for the Series
  337.        Author: Mat Ballard
  338.  Date created: 04/25/2000
  339. Date modified: 04/25/2000 by Mat Ballard
  340.       Purpose: manage user input
  341.  Known Issues:
  342.  ------------------------------------------------------------------------------}
  343. procedure TSeriesEditorForm.SymbolComboBoxClick(Sender: TObject);
  344. begin
  345.   pASP^.SymbolIndex := SymbolComboBox.ItemIndex;
  346. end;
  347.  
  348. {------------------------------------------------------------------------------
  349.     Procedure: TSeriesEditorForm.VisibleCheckBoxClick
  350.   Description: responds to changes to the Visibility of the Series
  351.        Author: Mat Ballard
  352.  Date created: 04/25/2000
  353. Date modified: 04/25/2000 by Mat Ballard
  354.       Purpose: manage user input
  355.  Known Issues:
  356.  ------------------------------------------------------------------------------}
  357. procedure TSeriesEditorForm.VisibleCheckBoxClick(Sender: TObject);
  358. begin
  359.   pASP^.Visible := VisibleCheckBox.Checked;
  360. end;
  361.  
  362. {------------------------------------------------------------------------------
  363.     Procedure: TSeriesEditorForm.YAxisComboBoxClick
  364.   Description: responds to changes in the selected Y Axis (primary or 2nd)
  365.        Author: Mat Ballard
  366.  Date created: 04/25/2000
  367. Date modified: 04/25/2000 by Mat Ballard
  368.       Purpose: manage user input
  369.  Known Issues:
  370.  ------------------------------------------------------------------------------}
  371. procedure TSeriesEditorForm.YAxisComboBoxClick(Sender: TObject);
  372. begin
  373. {We define YAxisIndex to run from 1 to FAxisList.Count-1}
  374.   pASP^.YAxisIndex := YAxisComboBox.ItemIndex+1;
  375. end;
  376.  
  377. {------------------------------------------------------------------------------
  378.     Procedure: TSeriesEditorForm.DeltaXNEditChange
  379.   Description: responds to changes in DeltaX
  380.        Author: Mat Ballard
  381.  Date created: 04/25/2000
  382. Date modified: 04/25/2000 by Mat Ballard
  383.       Purpose: manage user input
  384.  Known Issues:
  385.  ------------------------------------------------------------------------------}
  386. procedure TSeriesEditorForm.DeltaXNEditChange(Sender: TObject);
  387. begin
  388.   pASP^.DeltaX := DeltaXNEdit.AsInteger;
  389. end;
  390.  
  391. {------------------------------------------------------------------------------
  392.     Procedure: TSeriesEditorForm.DeltaYNEditChange
  393.   Description: repsonds to changes in DeltaY
  394.        Author: Mat Ballard
  395.  Date created: 04/25/2000
  396. Date modified: 04/25/2000 by Mat Ballard
  397.       Purpose: manage user input
  398.  Known Issues:
  399.  ------------------------------------------------------------------------------}
  400. procedure TSeriesEditorForm.DeltaYNEditChange(Sender: TObject);
  401. begin
  402.   pASP^.DeltaY := DeltaYNEdit.AsInteger;
  403. end;
  404.  
  405. {------------------------------------------------------------------------------
  406.     Procedure: TSeriesEditorForm.SymbolSizeNEditChange
  407.   Description: repsonds to changes in SymbolSize
  408.        Author: Mat Ballard
  409.  Date created: 04/25/2000
  410. Date modified: 04/25/2000 by Mat Ballard
  411.       Purpose: manage user input
  412.  Known Issues:
  413.  ------------------------------------------------------------------------------}
  414. procedure TSeriesEditorForm.SymbolSizeNEditChange(Sender: TObject);
  415. begin
  416.   pASP^.SymbolSize := SymbolSizeNEdit.AsInteger;
  417. end;
  418.  
  419. {------------------------------------------------------------------------------
  420.     Procedure: TSeriesEditorForm.NameEditChange
  421.   Description: repsonds to changes in the Series Name
  422.        Author: Mat Ballard
  423.  Date created: 04/25/2000
  424. Date modified: 04/25/2000 by Mat Ballard
  425.       Purpose: manage user input
  426.  Known Issues:
  427.  ------------------------------------------------------------------------------}
  428. procedure TSeriesEditorForm.NameEditChange(Sender: TObject);
  429. begin
  430.   SeriesNames.Strings[CurrentIndex] := NameEdit.Text;
  431. end;
  432.  
  433. procedure TSeriesEditorForm.XDataIndependentCheckBoxClick(Sender: TObject);
  434. begin
  435.   pASP^.XDataIndependent := XDataIndependentCheckBox.Checked;
  436. end;
  437.  
  438. procedure TSeriesEditorForm.PenColorEditChange(Sender: TObject);
  439. begin
  440.   pASP^.PenColor := PenColorEdit.Color;
  441.   pASP^.BrushColor := Misc.GetPalerColor(pASP.PenColor, 70);
  442. end;
  443.  
  444. procedure TSeriesEditorForm.BrushColorEditChange(Sender: TObject);
  445. begin
  446.   pASP^.BrushColor := BrushColorEdit.Color;
  447. end;
  448.  
  449. procedure TSeriesEditorForm.ApplyBitBtnClick(Sender: TObject);
  450. begin
  451.   TPlot(ThePlot).ApplySeriesChange(Self);
  452. end;
  453.  
  454.  
  455. end.
  456.