{Copyright or © or Copr. :

CNRS - Laboratoire Mouvement & Perception
franck.buloup@univmed.fr

This software is a computer program whose purpose is to highly simplify  
the use of ADwinPro realtime systems when you develop experimental
protocols  on life's sciences area.

This software is governed by the CeCILL  license under French law and
abiding by the rules of distribution of free software.  You can  use, 
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info". 

As a counterpart to the access to the source code and  rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty  and the software's author,  the holder of the
economic rights,  and the successive licensors  have only  limited
liability. 

In this respect, the user's attention is drawn to the risks associated
with loading,  using,  modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean  that it is complicated to manipulate,  and  that  also
therefore means  that it is reserved for developers  and  experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or 
data to be ensured and,  more generally, to use and operate it in the 
same conditions as regards security.

The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.}
unit UOptionsExecFrame;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, ExtCtrls, Grids, ActnList, Menus, StdCtrls, ComCtrls, ToolWin, XMLClasses;

type
  TOptionsExecFrame = class(TFrame)
    EnregVisuPanel: TPanel;
    Panel2: TPanel;
    TailleTamponPanel: TPanel;
    FormatFichierSauvPanel: TPanel;
    Panel3: TPanel;
    Shape3: TShape;
    Shape4: TShape;
    TampTrsfrtRecVisuStringGrid: TStringGrid;
    ActionList1: TActionList;
    Image2: TImage;
    Appliquer100Action: TAction;
    Appliquer1000Action: TAction;
    Appliquer2000Action: TAction;
    Appliquer3000Action: TAction;
    Appliquer4000Action: TAction;
    Appliquer5000Action: TAction;
    Aplliquer10000Action: TAction;
    Appliquer20000Action: TAction;
    Appliquer30000Action: TAction;
    Appliquer40000Action: TAction;
    Appliquer50000Action: TAction;
    Appliquer100000Action: TAction;
    PopupMenu1: TPopupMenu;
    Appliquer1001: TMenuItem;
    Appliquer10001: TMenuItem;
    Appliquer20001: TMenuItem;
    Appliquer30001: TMenuItem;
    Appliquer40001: TMenuItem;
    Appliquer50001: TMenuItem;
    Aplliquer100001: TMenuItem;
    Appliquer200001: TMenuItem;
    Appliquer300001: TMenuItem;
    Appliquer400001: TMenuItem;
    Appliquer500001: TMenuItem;
    Appliquer1000001: TMenuItem;
    AppliquerAutreAction: TAction;
    Description1: TMenuItem;
    Panel5: TPanel;
    DefaultRadioButton: TRadioButton;
    Label1: TLabel;
    UserRadioButton: TRadioButton;
    OptionsGroupBox: TGroupBox;
    ChannelNameCheckBox: TCheckBox;
    STNameCheckBox: TCheckBox;
    SessNameRadioButton: TRadioButton;
    SessNumRadioButton: TRadioButton;
    EssaiNumCheckBox: TCheckBox;
    Label2: TLabel;
    ExempleLabel: TLabel;
    N1: TMenuItem;
    Enregistrer1: TMenuItem;
    Visualiser1: TMenuItem;
    EnregistrerAction: TAction;
    VisualiserAction: TAction;
    Panel6: TPanel;
    STComboBox: TComboBox;
    Shape8: TShape;
    Shape9: TShape;
    Panel7: TPanel;
    Image4: TImage;
    Label3: TLabel;
    GroupBox1: TGroupBox;
    GraphesStringGrid: TStringGrid;
    Panel9: TPanel;
    DupGrapheButton: TButton;
    SuppGrapheButton: TButton;
    NewGrapheButton: TButton;
    Splitter1: TSplitter;
    GroupBox2: TGroupBox;
    Panel8: TPanel;
    SuppCourbeButton: TButton;
    NewCourbeButton: TButton;
    CourbesStringGrid: TStringGrid;
    OptionsSTGroupBox: TGroupBox;
    ToolBar1: TToolBar;
    AppConfigSTToolButton: TToolButton;
    FullScreenCheckBox: TCheckBox;
    StatusBarCheckBox: TCheckBox;
    AppConfigSTPopupMenu: TPopupMenu;
    TtesLesSTMenuItem: TMenuItem;
    N2: TMenuItem;
    AppConfigSTAction: TAction;
    AppToutesConfigSTAction: TAction;
    procedure TampTrsfrtRecVisuStringGridDrawCell(Sender: TObject; ACol,
      ARow: Integer; Rect: TRect; State: TGridDrawState);
    procedure AppliquerTailleTamponActionExecute(Sender: TObject);
    procedure AppliquerAutreActionExecute(Sender: TObject);
    procedure TampTrsfrtRecVisuStringGridKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure HelpImageClick(Sender: TObject);
    procedure UserRadioButtonClick(Sender: TObject);
    procedure ConfigChangeClick(Sender: TObject);
    procedure EnregActionExecute(Sender: TObject);
    procedure VisualiserActionExecute(Sender: TObject);
    procedure STComboBoxChange(Sender: TObject);
    procedure FullScreenStatusBarCheckBoxClick(Sender: TObject);
    procedure AppConfigSTPopupMenuPopup(Sender: TObject);
    procedure AppConfigSTToolButtonClick(Sender: TObject);
    procedure AppConfigSTActionExecute(Sender: TObject);
    procedure AppToutesConfigSTActionExecute(Sender: TObject);
    procedure NewGrapheButtonClick(Sender: TObject);
    procedure SuppGrapheButtonClick(Sender: TObject);
    procedure DupGrapheButtonClick(Sender: TObject);
    procedure GraphesStringGridDblClick(Sender: TObject);
    procedure NewCourbeButtonClick(Sender: TObject);
    procedure SuppCourbeButtonClick(Sender: TObject);
    procedure CourbesStringGridDblClick(Sender: TObject);
    procedure GraphesStringGridClick(Sender: TObject);
    procedure PopupMenu1Popup(Sender: TObject);
  private
    { Déclarations privées }
    channelNameSample : string;
    procedure AppliquerTailleTampon(Taille : integer);
    procedure AppliquerEnregVisu(Enreg,Visu,TraiterEnreg,TraiterVisu : boolean);
    procedure CopyConfigST(indexFrom,indexTo : integer);

//    procedure buildListeCanauxTransfert(ABloc : IXMLBlocType; ListeCanauxTrsfrt : TStringList);
  public
    { Déclarations publiques }
    procedure MajPresentationOptionsExec;
    procedure MAJIHM;
    procedure ClearIHM;
    procedure MAJCourbes;
    procedure MAJGraphes;
  end;





implementation

{$R *.dfm}

uses UDocometre, UTailleTampRecVisu, UGraphe, UCourbe, UGlobal;


var 
    MajIsRunning : boolean = false;

procedure TOptionsExecFrame.MajPresentationOptionsExec;
var enregVisuIcon : TImage;
begin
  TampTrsfrtRecVisuStringGrid.ColWidths[0] := 20;
  TampTrsfrtRecVisuStringGrid.ColWidths[1] := 20;
  TampTrsfrtRecVisuStringGrid.ColWidths[2] := (TampTrsfrtRecVisuStringGrid.ClientWidth - 40) div 2 - 2;
	TampTrsfrtRecVisuStringGrid.ColWidths[3] := (TampTrsfrtRecVisuStringGrid.ClientWidth - 40) div 2 - 2;

  if MajIsRunning = false then
  begin
    MajIsRunning := true;
    if TampTrsfrtRecVisuStringGrid.Objects[0,0] = nil then
    begin
      enregVisuIcon := TImage.Create(TampTrsfrtRecVisuStringGrid);
      enregVisuIcon.Parent := TampTrsfrtRecVisuStringGrid;
      enregVisuIcon.Name := 'EnregIconTitle';
      enregVisuIcon.Hint := 'Enregistrement';
      enregVisuIcon.ShowHint := true;
      enregVisuIcon.Picture.LoadFromFile(ExtractFilePath(Application.ExeName) + '/Icons/record.bmp');
      enregVisuIcon.AutoSize := false;
      enregVisuIcon.Center := true;
      enregVisuIcon.Transparent := true;
      enregVisuIcon.Visible := false;
      enregVisuIcon.Stretch := false;
      TampTrsfrtRecVisuStringGrid.Objects[0,0] := enregVisuIcon;
    end;

    if TampTrsfrtRecVisuStringGrid.Objects[1,0] = nil then
    begin
      enregVisuIcon := TImage.Create(TampTrsfrtRecVisuStringGrid);
      enregVisuIcon.Parent := TampTrsfrtRecVisuStringGrid;
      enregVisuIcon.Name := 'VisuIconTitle';
      enregVisuIcon.Hint := 'Visualisation';
      enregVisuIcon.ShowHint := true;
      enregVisuIcon.Picture.LoadFromFile(ExtractFilePath(Application.ExeName) + '/Icons/read_obj.bmp');
      enregVisuIcon.AutoSize := false;
      enregVisuIcon.Center := true;
      enregVisuIcon.Transparent := true;
      enregVisuIcon.Visible := false;
      enregVisuIcon.Stretch := false;
      TampTrsfrtRecVisuStringGrid.Objects[1,0] := enregVisuIcon;
    end;
  end;

  TampTrsfrtRecVisuStringGrid.Cells[2,0] := 'Nom du canal';
  TampTrsfrtRecVisuStringGrid.Cells[3,0] := 'Taille du tampon';

  GraphesStringGrid.DefaultColWidth := GraphesStringGrid.ClientWidth div 8 - 1;
  GraphesStringGrid.Cells[0,0] := 'Type de graphe';
  GraphesStringGrid.Cells[1,0] := 'Temps/Fréq. de visu.';
  GraphesStringGrid.Cells[2,0] := 'Echelle Y auto ?';
  GraphesStringGrid.Cells[3,0] := 'Ymin';
  GraphesStringGrid.Cells[4,0] := 'Ymax';
  GraphesStringGrid.Cells[5,0] := 'Echelle X auto ?';
  GraphesStringGrid.Cells[6,0] := 'Xmin';
  GraphesStringGrid.Cells[7,0] := 'Xmax';

	CourbesStringGrid.ColWidths[2] := (CourbesStringGrid.ClientWidth - 40) div 2;
	CourbesStringGrid.ColWidths[1] := (CourbesStringGrid.ClientWidth - 40) div 2;
	CourbesStringGrid.ColWidths[0] := 40;
  CourbesStringGrid.Cells[1,0] := 'Ordonnée';
  CourbesStringGrid.Cells[2,0] := 'Abscisse';
  CourbesStringGrid.Cells[0,0] := 'Couleur';

end;

procedure TOptionsExecFrame.ClearIHM;
var i : integer;
begin
  for i := 1 to TampTrsfrtRecVisuStringGrid.RowCount - 1 do
  begin
    TampTrsfrtRecVisuStringGrid.Objects[0,i].Free;
    TampTrsfrtRecVisuStringGrid.Objects[0,i] := nil;
    TampTrsfrtRecVisuStringGrid.Objects[1,i].Free;
    TampTrsfrtRecVisuStringGrid.Objects[1,i] := nil;
  end;

  for i := 1 to CourbesStringGrid.RowCount - 1 do
  begin
    CourbesStringGrid.Objects[0,i].Free;
    CourbesStringGrid.Objects[0,i] := nil;
  end;

  TampTrsfrtRecVisuStringGrid.RowCount := 1;
  GraphesStringGrid.RowCount := 1;
  CourbesStringGrid.RowCount := 1;
end;

procedure TOptionsExecFrame.MAJIHM;
var i : integer;
    InfosCanaux : TInfoCanaux;
    S : string;
    UseForAnalyse : boolean;
    numSTSelected : integer;
begin
  numSTSelected := STCombobox.ItemIndex;
  ClearIHM;
  STCombobox.Clear;
  StatusBarCheckBox.Checked := false;
  FullScreenCheckBox.Checked := false;
  OptionsSTGroupBox.Enabled := false;
  for i := 0 to DocDOCOMETRE.ST.Count - 1
  do STCombobox.Items.Add(DocDOCOMETRE.ST[i].NOM);

  ///Continuer a faire la reconstruction partie format fichier save ...
  UserRadioButton.OnClick := nil;
  DefaultRadioButton.OnClick := nil;
  ChannelNameCheckBox.OnClick := nil;
  STNameCheckBox.OnClick := nil;
  SessNameRadioButton.OnClick := nil;
  SessNumRadioButton.OnClick := nil;
  EssaiNumCheckBox.OnClick := nil;

  UseForAnalyse :=(DocDOCOMETRE.FORMATNOMFICHIERSSAVE.UseNOMCANAL = 1) and
                  (DocDOCOMETRE.FORMATNOMFICHIERSSAVE.UseNOMST = 0) and
                  (DocDOCOMETRE.FORMATNOMFICHIERSSAVE.UseNOMSESSION = 0) and
                  (DocDOCOMETRE.FORMATNOMFICHIERSSAVE.UseNUMSESSION = 1) and
                  (DocDOCOMETRE.FORMATNOMFICHIERSSAVE.UseNUMESSAI = 1);

  if not UseForAnalyse then
  begin
    ChannelNameCheckBox.Checked := DocDOCOMETRE.FORMATNOMFICHIERSSAVE.UseNOMCANAL = 1;
    STNameCheckBox.Checked := DocDOCOMETRE.FORMATNOMFICHIERSSAVE.UseNOMST = 1;
    SessNameRadioButton.Checked := DocDOCOMETRE.FORMATNOMFICHIERSSAVE.UseNOMSESSION = 1;
    SessNumRadioButton.Checked := DocDOCOMETRE.FORMATNOMFICHIERSSAVE.UseNUMSESSION = 1;
    EssaiNumCheckBox.Checked := DocDOCOMETRE.FORMATNOMFICHIERSSAVE.UseNUMESSAI = 1;
    UserRadioButton.Checked := true;
  end else DefaultRadioButton.Checked := true;
  OptionsGroupBox.Enabled := UserRadioButton.Checked;

  UserRadioButton.OnClick := UserRadioButtonClick;
  DefaultRadioButton.OnClick := UserRadioButtonClick;
  ChannelNameCheckBox.OnClick := ConfigChangeClick;
  STNameCheckBox.OnClick := ConfigChangeClick;
  SessNameRadioButton.OnClick := ConfigChangeClick;
  SessNumRadioButton.OnClick := ConfigChangeClick;
  EssaiNumCheckBox.OnClick := ConfigChangeClick;

  InfosCanaux := DocDOCOMETRE.RendreListeInfoCanaux;
  
  if InfosCanaux.Nom.Count > 0
  then channelNameSample := InfosCanaux.Nom[0];

  S := '';
  if InfosCanaux.Nom.Count > 0
  then if ChannelNameCheckBox.Checked
       then S := InfosCanaux.Nom[0];
  if DocDOCOMETRE.ST.Count>0
  then if STNameCheckBox.Checked
       then S := S + '_' + DocDOCOMETRE.ST.Items[0].NOM;
  if DocDOCOMETRE.SESSIONS.Count > 0
  then if SessNameRadioButton.Checked
       then S := S + '_' + DocDOCOMETRE.SESSIONS[0].NOM;
  if SessNumRadioButton.Checked
  then S := S + '_' + 'S1';
  if EssaiNumCheckBox.Checked
  then S := S + '_' + 'E1';
  ExempleLabel.Caption := S + '.sau';

  InfosCanaux.Free;
  STCombobox.ItemIndex := numSTSelected;
  if STCombobox.ItemIndex > - 1 then Self.STComboBoxChange(Self);
end;

procedure TOptionsExecFrame.TampTrsfrtRecVisuStringGridDrawCell(Sender: TObject;
  ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
var R : TRect;
begin
  with (Sender as TStringGrid) do
  begin
		Canvas.Brush.Color := clWhite;
		if ARow = 0 then
		begin
      if Name = 'TampTrsfrtRecVisuStringGrid' then
			begin
				if (ACol = 0) or (ACol = 1) then
				begin
          R := TampTrsfrtRecVisuStringGrid.CellRect(ACol, ARow);
          (Objects[ACol,ARow] as TImage).Left := R.Left + 1;
          (Objects[ACol,ARow] as TImage).Top := R.Top + 1;
          (Objects[ACol,ARow] as TImage).Width := R.Right - R.Left - 5;
          (Objects[ACol,ARow] as TImage).Height := R.Bottom - R.Top - 5;
          (Objects[ACol,ARow] as TImage).Visible := True;
				end;
			end;
		end;

    if ARow > 0 then
    begin
      if (ARow mod 2) = 0 then Canvas.Brush.Color := $DDEEFF;

      if Name = 'TampTrsfrtRecVisuStringGrid' then
      begin
        if (Arow >= TampTrsfrtRecVisuStringGrid.Selection.Top) and
           (ARow <= TampTrsfrtRecVisuStringGrid.Selection.Bottom)
        then Canvas.Brush.Color := $FFF8DF;
        if Objects[ACol,ARow] <> nil then
        begin
          R := TampTrsfrtRecVisuStringGrid.CellRect(ACol, ARow);
          (Objects[ACol,ARow] as TImage).Left := R.Left + 1;
          (Objects[ACol,ARow] as TImage).Top := R.Top + 1;
          (Objects[ACol,ARow] as TImage).Width := R.Right - R.Left - 5;
          (Objects[ACol,ARow] as TImage).Height := R.Bottom - R.Top - 5;
          (Objects[ACol,ARow] as TImage).Visible := True;
        end;
      end;

      if Name = 'GraphesStringGrid'
      then if (Arow = GraphesStringGrid.Selection.Top)
           then Canvas.Brush.Color := $FFF8DF;

      if Name = 'CourbesStringGrid' then
      begin
        if (Arow = CourbesStringGrid.Selection.Top)
        then Canvas.Brush.Color := $FFF8DF;

        if Objects[ACol,ARow] <> nil then
        begin
					R := CourbesStringGrid.CellRect(ACol, ARow);
					(Objects[ACol,ARow] as TShape).Width := (R.Right - R.Left - 1) div 2;
					(Objects[ACol,ARow] as TShape).Height := (R.Bottom - R.Top - 1) div 2;

					(Objects[ACol,ARow] as TShape).Left := R.Left + (R.Right - R.Left) div 4;
					(Objects[ACol,ARow] as TShape).Top := R.Top + (R.Bottom - R.Top) div 4;

					(Objects[ACol,ARow] as TShape).Visible := True;
        end;

      end;

    end else Canvas.Brush.Color := clBtnFace;
    Canvas.FillRect(Rect);
    DrawText(Canvas.Handle, PChar(Cells[ACol,ARow]), -1, Rect ,
                DT_CENTER or DT_VCENTER or DT_SINGLELINE	 );
  end;
end;

procedure TOptionsExecFrame.AppConfigSTPopupMenuPopup(Sender: TObject);
var i : integer;
    NewMenuItem : TMenuItem;
begin
  AppConfigSTPopupMenu.Items.Clear;
  NewMenuItem := TMenuItem.Create(AppConfigSTPopupMenu.Items);
  NewMenuItem.Name := 'AppTtesLesSTMenuItem';
  NewMenuItem.Caption := 'Toutes les séquences type';
  NewMenuItem.OnClick := AppToutesConfigSTActionExecute;
  AppConfigSTPopupMenu.Items.Add(NewMenuItem);

  NewMenuItem := TMenuItem.Create(AppConfigSTPopupMenu.Items);
  NewMenuItem.Name := 'SeparateurMenuItem';
  NewMenuItem.Caption := '-';
  AppConfigSTPopupMenu.Items.Add(NewMenuItem);
  
  for i := 0 to DocDOCOMETRE.ST.Count - 1 do
  begin
    if i <> STCombobox.ItemIndex then
    begin
      NewMenuItem := TMenuItem.Create(AppConfigSTPopupMenu.Items);
      NewMenuItem.Name := 'ST'+inttostr(i);
      NewMenuItem.OnClick := AppConfigSTActionExecute;
      NewMenuItem.Caption := DocDOCOMETRE.ST.Items[i].NOM;
      AppConfigSTPopupMenu.Items.Add(NewMenuItem);
    end;
  end;
end;

procedure TOptionsExecFrame.AppConfigSTToolButtonClick(Sender: TObject);
begin
  if MessageDLG('Souhaitez-vous appliquer cette configuration à toutes les séquences type ?',mtConfirmation	,[mbYes,mbNo],0) = mrYes 
	then AppToutesConfigSTActionExecute(self);
end;

{
procedure TOptionsExecFrame.buildListeCanauxTransfert(ABloc : IXMLBlocType; ListeCanauxTrsfrt : TStringList);
var i,j : integer;
    AFunction : IXMLFonctionType;
begin
  for i:= 0 to ABLOC.FONCTION.Count - 1 do
  begin
    AFunction := ABLOC.FONCTION[i];
    if AFunction.FICHIER = 'Transfert' then
    begin
      for j := 0 to AFunction.SORTIE.Count - 1 do
      begin
        if AFunction.SORTIE[j].NOM <> ''
        then ListeCanauxTrsfrt.Add(AFunction.SORTIE[j].NOM);
      end;
    end;
  end;

  for i := 0 to ABLOC.BLOC.Count - 1
  do buildListeCanauxTransfert(ABLOC.BLOC[i],ListeCanauxTrsfrt);
end;
}

procedure TOptionsExecFrame.CopyConfigST(indexFrom,indexTo : integer);
var i,j : integer;
    ListeCanauxTrsfrt : TStringList;
//    AGraphe : IXMLListeGraphesType;
begin
  //copier fullscreen statusbar
  docDOCOMETRE.ST[indexTo].FULLSCREEN := docDOCOMETRE.ST[indexFrom].FULLSCREEN;
  docDOCOMETRE.ST[indexTo].STATUSBAR := docDOCOMETRE.ST[indexFrom].STATUSBAR;
  //copier enreg visu taille tampon
  docDOCOMETRE.ST[indexTo].LISTECANAUXENREG.Clear;
  for i := 0 to docDOCOMETRE.ST[indexFrom].LISTECANAUXENREG.Count - 1
  do 
docDOCOMETRE.ST[indexTo].LISTECANAUXENREG.ChildNodes.Add(docDOCOMETRE.ST[indexFrom].LISTECANAUXENREG[i].CloneNode(true) as IXMLListeCanauxEnregVisuType);
  docDOCOMETRE.ST[indexTo].LISTECANAUXVISU.Clear;
  for i := 0 to docDOCOMETRE.ST[indexFrom].LISTECANAUXVISU.Count - 1
  do 
docDOCOMETRE.ST[indexTo].LISTECANAUXVISU.ChildNodes.Add(docDOCOMETRE.ST[indexFrom].LISTECANAUXVISU[i].CloneNode(true) as IXMLListeCanauxEnregVisuType);

  //parcours de toutes les actions de la ST pour trouver les actions
  //de type trsfrt et suppression dans ListeCanauxVisu ou enreg si pas present
  //dans trsfrt
  ListeCanauxTrsfrt := TStringList.Create;
  ListeCanauxTrsfrt.CaseSensitive := false;
  ListeCanauxTrsfrt.Sorted := true;


  DocDOCOMETRE.ST[indexTo].RendreListeCanauxTransfertKeithleyPC(ListeCanauxTrsfrt);
  DocDOCOMETRE.ST[STCombobox.ItemIndex].RendreListeCanauxTransfertPCKeithley(ListeCanauxTrsfrt);



//  for i := 0 to DocDOCOMETRE.ST[indexTo].BLOC.Count - 1
//  do buildListeCanauxTransfert(DocDOCOMETRE.ST[indexTo].BLOC[i],ListeCanauxTrsfrt);

  i := 0;
  while i < docDOCOMETRE.ST[indexTo].LISTECANAUXENREG.Count do
  begin
    if ListeCanauxTrsfrt.IndexOf(docDOCOMETRE.ST[indexTo].LISTECANAUXENREG[i].NOMCANAL) = -1
    then docDOCOMETRE.ST[indexTo].LISTECANAUXENREG.Delete(i)
    else inc(i);
  end;
  i := 0;
  while i < docDOCOMETRE.ST[indexTo].LISTECANAUXVISU.Count do
  begin
    if ListeCanauxTrsfrt.IndexOf(docDOCOMETRE.ST[indexTo].LISTECANAUXVISU[i].NOMCANAL) = -1
    then docDOCOMETRE.ST[indexTo].LISTECANAUXVISU.Delete(i)
    else inc(i);
  end;

  //copier graphes et courbes
  ListeCanauxTrsfrt.Add('temps');
  docDOCOMETRE.ST[indexTo].GRAPHES.Clear;
  for i := 0 to docDOCOMETRE.ST[indexFrom].GRAPHES.Count - 1
  do docDOCOMETRE.ST[indexTo].GRAPHES.ChildNodes.Add(docDOCOMETRE.ST[indexFrom].GRAPHES[i].CloneNode(true));
  
  for i := 0 to docDOCOMETRE.ST[indexTo].Graphes.Count - 1 do
  begin
    for j := 0 to docDOCOMETRE.ST[indexTo].Graphes[i].COURBES.Count - 1 do
    begin
      if ListeCanauxTrsfrt.IndexOf(docDOCOMETRE.ST[indexTo].Graphes[i].COURBES[j].NOMCANALORDO) = -1
      then docDOCOMETRE.ST[indexTo].Graphes[i].COURBES[j].NOMCANALORDO := '';
      if ListeCanauxTrsfrt.IndexOf(docDOCOMETRE.ST[indexTo].Graphes[i].COURBES[j].NOMCANALABSC) = -1
      then docDOCOMETRE.ST[indexTo].Graphes[i].COURBES[j].NOMCANALABSC := '';
    end;
  end;

  ListeCanauxTrsfrt.Free;
end;

procedure TOptionsExecFrame.AppConfigSTActionExecute(Sender: TObject);
var n : integer;
begin
  n := strtoint(copy((Sender as TMenuItem).Name,3,length((Sender as TMenuItem).Name)));
  CopyConfigST(STCombobox.ItemIndex,n);
end;

procedure TOptionsExecFrame.AppToutesConfigSTActionExecute(
  Sender: TObject);
var i : integer;
begin
  for i := 0 to DocDOCOMETRE.ST.Count - 1
  do if i <> STCombobox.ItemIndex
        then CopyConfigST(STCombobox.ItemIndex,i);
end;

procedure TOptionsExecFrame.FullScreenStatusBarCheckBoxClick(Sender: TObject);
begin
  if STCombobox.ItemIndex > - 1 then
  begin
    if (Sender as TCheckBox).Name = 'StatusBarCheckBox' then
    begin
      case StatusBarCheckBox.Checked of
        true : DocDOCOMETRE.ST[STCombobox.ItemIndex].STATUSBAR := 1;
        false :DocDOCOMETRE.ST[STCombobox.ItemIndex].STATUSBAR := 0;
      end;
    end;
    if (Sender as TCheckBox).Name = 'FullScreenCheckBox' then
    begin
      case FullScreenCheckBox.Checked of
        true : DocDOCOMETRE.ST[STCombobox.ItemIndex].FULLSCREEN := 1;
        false :DocDOCOMETRE.ST[STCombobox.ItemIndex].FULLSCREEN := 0;
      end;
    end;
  end;
end;

procedure TOptionsExecFrame.TampTrsfrtRecVisuStringGridKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
var myRect : TGridRect;
begin
  if (ssCtrl in Shift) and ((key = Ord('A')) or (key = Ord('a'))) then
  begin
    myRect.Left := 0;
    myRect.Top := 1;
    myRect.Right := 3;
    myRect.Bottom := TampTrsfrtRecVisuStringGrid.RowCount - 1;
    TampTrsfrtRecVisuStringGrid.Selection := myRect;
  end;
end;

procedure TOptionsExecFrame.UserRadioButtonClick(Sender: TObject);
begin
  OptionsGroupBox.Enabled := UserRadioButton.Checked;
  if DefaultRadioButton.Checked then
  begin
    ChannelNameCheckBox.Checked := true;
    STNameCheckBox.Checked := false;
    SessNumRadioButton.Checked := true;
    EssaiNumCheckBox.Checked := true;
  end;
  ConfigChangeClick(self);
end;

procedure TOptionsExecFrame.ConfigChangeClick(Sender: TObject);
var S : string;
begin
  case ChannelNameCheckBox.Checked of
   true: DocDOCOMETRE.FORMATNOMFICHIERSSAVE.UseNOMCANAL := 1;
   false: DocDOCOMETRE.FORMATNOMFICHIERSSAVE.UseNOMCANAL := 0;
  end;

  case STNameCheckBox.Checked of
   true: DocDOCOMETRE.FORMATNOMFICHIERSSAVE.UseNOMST := 1;
   false: DocDOCOMETRE.FORMATNOMFICHIERSSAVE.UseNOMST := 0;
  end;

  case SessNameRadioButton.Checked of
   true: DocDOCOMETRE.FORMATNOMFICHIERSSAVE.UseNOMSESSION := 1;
   false: DocDOCOMETRE.FORMATNOMFICHIERSSAVE.UseNOMSESSION := 0;
  end;

  case SessNumRadioButton.Checked of
   true: DocDOCOMETRE.FORMATNOMFICHIERSSAVE.UseNUMSESSION := 1;
   false: DocDOCOMETRE.FORMATNOMFICHIERSSAVE.UseNUMSESSION := 0;
  end;

  case EssaiNumCheckBox.Checked of
   true: DocDOCOMETRE.FORMATNOMFICHIERSSAVE.UseNUMESSAI := 1;
   false: DocDOCOMETRE.FORMATNOMFICHIERSSAVE.UseNUMESSAI := 0;
  end;

  S := '';
  if ChannelNameCheckBox.Checked
  then S := channelNameSample;

  if DocDOCOMETRE.ST.Count>0
  then if STNameCheckBox.Checked
       then S := S + '_' + DocDOCOMETRE.ST.Items[0].NOM;
  if DocDOCOMETRE.SESSIONS.Count > 0
  then if SessNameRadioButton.Checked
       then S := S + '_' + DocDOCOMETRE.SESSIONS[0].NOM;
  if SessNumRadioButton.Checked
  then S := S + '_' + 'S1';
  if EssaiNumCheckBox.Checked
  then S := S + '_' + 'E1';
  ExempleLabel.Caption := S + '.sau';
end;

procedure TOptionsExecFrame.AppliquerTailleTamponActionExecute(Sender: TObject);
var S : string;
begin
  S := (Sender as TAction).Caption;
  delete(S,1,10);
  AppliquerTailleTampon(strtoint(S));
  STComboBoxChange(self);
end;

procedure TOptionsExecFrame.AppliquerTailleTampon(Taille : integer);
var i,j,k,index : integer;
    InfosCanaux : TInfoCanaux;
begin
	InfosCanaux := DocDOCOMETRE.RendreListeInfoCanaux;
  for i := TampTrsfrtRecVisuStringGrid.Selection.Top to TampTrsfrtRecVisuStringGrid.Selection.Bottom do
  begin
    index := InfosCanaux.Nom.IndexOf(TampTrsfrtRecVisuStringGrid.Cells[2,i]);
    if index > -1 then
    begin
      if InfosCanaux.ISPSerie[index] = '1' then
      begin
        if pos(DocDOCOMETRE.PSERIE.Items[0].NOM,InfosCanaux.Nom[index])=1 then
        begin
          DocDOCOMETRE.PSERIE.Items[0].TAILLETAMPON := Taille;
          InfosCanaux.TailleTampon[index] := inttostr(Taille);
					DocDOCOMETRE.ST.ChangeChannelName(DocDOCOMETRE.PSERIE[0].NOM,DocDOCOMETRE.PSERIE[0].NOM,'1',InfosCanaux);
        end;
        if DocDOCOMETRE.PSERIE.Count > 1
        then if pos(DocDOCOMETRE.PSERIE.Items[1].NOM,InfosCanaux.Nom[index])=1 then
             begin
               DocDOCOMETRE.PSERIE.Items[1].TAILLETAMPON := Taille;
               InfosCanaux.TailleTampon[index] := inttostr(Taille);
							 DocDOCOMETRE.ST.ChangeChannelName(DocDOCOMETRE.PSERIE[1].NOM,DocDOCOMETRE.PSERIE[1].NOM,'1',InfosCanaux);
             end;
      end else
      begin
        for j := 0 to DocDOCOMETRE.EAN.Count - 1 do
        begin
          if DocDOCOMETRE.EAN[j].NOM = InfosCanaux.Nom[index] then
          begin
            DocDOCOMETRE.EAN[j].TAILLETAMPON := Taille;
            InfosCanaux.TailleTampon[index] := inttostr(Taille);
						DocDOCOMETRE.ST.ChangeChannelName(DocDOCOMETRE.EAN[j].NOM,DocDOCOMETRE.EAN[j].NOM,'',InfosCanaux);
            break;
          end;
        end;
				for j := 0 to DocDOCOMETRE.SAN.Count - 1 do
        begin
          if DocDOCOMETRE.SAN[j].NOM = InfosCanaux.Nom[index] then
          begin
            DocDOCOMETRE.SAN[j].TAILLETAMPON := Taille;
            InfosCanaux.TailleTampon[index] := inttostr(Taille);
						DocDOCOMETRE.ST.ChangeChannelName(DocDOCOMETRE.SAN[j].NOM,DocDOCOMETRE.SAN[j].NOM,'',InfosCanaux);
            break;
          end;
        end;
        for j := 0 to DocDOCOMETRE.ENUM.Count - 1 do
        begin
          if DocDOCOMETRE.ENUM[j].NOM = InfosCanaux.Nom[index] then
          begin
            DocDOCOMETRE.ENUM[j].TAILLETAMPON := Taille;
            InfosCanaux.TailleTampon[index] := inttostr(Taille);
						DocDOCOMETRE.ST.ChangeChannelName(DocDOCOMETRE.ENUM[j].NOM,DocDOCOMETRE.ENUM[j].NOM,'',InfosCanaux);
            break;
          end;
        end;
        for j := 0 to DocDOCOMETRE.SNUM.Count - 1 do
        begin
          if DocDOCOMETRE.SNUM[j].NOM = InfosCanaux.Nom[index] then
          begin
            DocDOCOMETRE.SNUM[j].TAILLETAMPON := Taille;
            InfosCanaux.TailleTampon[index] := inttostr(Taille);
						DocDOCOMETRE.ST.ChangeChannelName(DocDOCOMETRE.SNUM[j].NOM,DocDOCOMETRE.SNUM[j].NOM,'',InfosCanaux);
            break;
          end;
        end;
        for j := 0 to DocDOCOMETRE.CANINT.Count - 1 do
        begin
          if DocDOCOMETRE.CANINT.Items[j].TAILLE > 1 then
					begin

            if DocDOCOMETRE.CANINT[j].NOM = InfosCanaux.Nom[index] then
            begin
              DocDOCOMETRE.CANINT[j].TAILLETAMPON := Taille;
              InfosCanaux.TailleTampon[index] := inttostr(Taille);
              DocDOCOMETRE.ST.ChangeChannelName(DocDOCOMETRE.CANINT[j].NOM,DocDOCOMETRE.CANINT[j].NOM,'',InfosCanaux);
              break;
            end;

            for k := 0 to DocDOCOMETRE.CANINT.Items[j].TAILLE - 1 do
            begin
              if DocDOCOMETRE.CANINT[j].NOM + '['+inttostr(k+1)+']' = InfosCanaux.Nom[index] then
              begin
                DocDOCOMETRE.CANINT[j].TAILLETAMPON := Taille;
                InfosCanaux.TailleTampon[index] := inttostr(Taille);
								DocDOCOMETRE.ST.ChangeChannelName(DocDOCOMETRE.CANINT[j].NOM,DocDOCOMETRE.CANINT[j].NOM,'',InfosCanaux);
                break;
              end;
            end;

          end else
          begin
            if DocDOCOMETRE.CANINT[j].NOM = InfosCanaux.Nom[index] then
            begin
              DocDOCOMETRE.CANINT[j].TAILLETAMPON := Taille;
              InfosCanaux.TailleTampon[index] := inttostr(Taille);
              DocDOCOMETRE.ST.ChangeChannelName(DocDOCOMETRE.CANINT[j].NOM,DocDOCOMETRE.CANINT[j].NOM,'',InfosCanaux);
              break;
            end;
          end;
        end;
      end;
    end;
  end;
  InfosCanaux.Free;
end;

procedure TOptionsExecFrame.AppliquerEnregVisu(Enreg,Visu,TraiterEnreg,TraiterVisu : boolean);
var i,j : integer;
    InfosCanaux : TInfoCanaux;
    AListeCanauxEnreg,AListeCanauxVisu : IXMLListeCanauxEnregVisuTypeList;
    ACanalEnreg,ACanalVisu : IXMLListeCanauxEnregVisuType;
    AlreadyExist : boolean;
begin
  AListeCanauxEnreg := DocDOCOMETRE.ST[STCombobox.ItemIndex].LISTECANAUXENREG;
  AListeCanauxVisu := DocDOCOMETRE.ST[STCombobox.ItemIndex].LISTECANAUXVISU;
  InfosCanaux := DocDOCOMETRE.RendreListeInfoCanaux;

  for i := TampTrsfrtRecVisuStringGrid.Selection.Top to TampTrsfrtRecVisuStringGrid.Selection.Bottom do
  begin

    if TraiterEnreg then
    begin
      AlreadyExist := false;
      for j := 0 to AListeCanauxEnreg.Count - 1 do
      begin
        if TampTrsfrtRecVisuStringGrid.Cells[2,i] = AListeCanauxEnreg[j].NOMCANAL then
        begin
          AlreadyExist := true;
          break;
        end;
      end;
      if (not AlreadyExist) and Enreg then
      begin
        ACanalEnreg := AListeCanauxEnreg.Add;
        ACanalEnreg.NOMCANAL := TampTrsfrtRecVisuStringGrid.Cells[2,i];
      end;
      if AlreadyExist and (not Enreg) then AListeCanauxEnreg.Delete(j);
    end;

    if Traitervisu then
    begin
      AlreadyExist := false;
      for j := 0 to AListeCanauxVisu.Count - 1 do
      begin
        if TampTrsfrtRecVisuStringGrid.Cells[2,i] = AListeCanauxVisu[j].NOMCANAL then
        begin
          AlreadyExist := true;
          break;
        end;
      end;
      if (not AlreadyExist) and Visu then
      begin
        ACanalVisu := AListeCanauxVisu.Add;
        ACanalVisu.NOMCANAL := TampTrsfrtRecVisuStringGrid.Cells[2,i];
      end;
      if AlreadyExist and (not Visu) then AListeCanauxVisu.Delete(j);
    end;
  end;
  InfosCanaux.Free;
end;

procedure TOptionsExecFrame.AppliquerAutreActionExecute(Sender: TObject);
begin
  TailleTampRecVisuDLGForm.EnregCheckBox.Checked :=
  (TampTrsfrtRecVisuStringGrid.Objects[0,TampTrsfrtRecVisuStringGrid.Selection.Top] <> nil);

  TailleTampRecVisuDLGForm.VisuCheckBox.Checked :=
  (TampTrsfrtRecVisuStringGrid.Objects[1,TampTrsfrtRecVisuStringGrid.Selection.Top] <> nil);

  if TailleTampRecVisuDLGForm.ShowModal = mrOK then
  begin
    AppliquerTailleTampon(strtoint(TailleTampRecVisuDLGForm.TailleTamponEdit.Text));
    
AppliquerEnregVisu(TailleTampRecVisuDLGForm.EnregCheckBox.Checked,TailleTampRecVisuDLGForm.VisuCheckBox.Checked,true,true);
    STComboBoxChange(self);
  end;
end;

procedure TOptionsExecFrame.HelpImageClick(Sender: TObject);
begin
  DocoForm.ShowHelp((Sender as TImage).Tag);
end;

procedure TOptionsExecFrame.EnregActionExecute(Sender: TObject);
begin
  if TampTrsfrtRecVisuStringGrid.Selection.Top > 0 then
  begin
    AppliquerEnregVisu(true,false,true,false);
    STComboBoxChange(self);
  end;
end;

procedure TOptionsExecFrame.VisualiserActionExecute(Sender: TObject);
begin
  AppliquerEnregVisu(false,true,false,true);
  STComboBoxChange(self);
end;

procedure TOptionsExecFrame.STComboBoxChange(Sender: TObject);
var i,j,n : integer;
    ListeCanauxTrsfrt : TStringList;
    InfosCanaux : TInfoCanaux;
    AListeCanauxEnreg,AListeCanauxVisu : IXMLListeCanauxEnregVisuTypeList;
    //AlisteGraphes : IXMLListeGraphesTypeList;
    //AListeCourbes : IXMLListeCourbesTypeList;
    enregVisuIcon : TImage;
begin
  for i := 1 to TampTrsfrtRecVisuStringGrid.RowCount - 1 do
  begin
    TampTrsfrtRecVisuStringGrid.Objects[0,i].Free;
    TampTrsfrtRecVisuStringGrid.Objects[0,i] := nil;
    TampTrsfrtRecVisuStringGrid.Objects[1,i].Free;
    TampTrsfrtRecVisuStringGrid.Objects[1,i] := nil;
  end;

  InfosCanaux := DocDOCOMETRE.RendreListeInfoCanaux;
  TampTrsfrtRecVisuStringGrid.RowCount := 1;

  //parcours de toutes les actions de la ST pour trouver les actions
  //de type trsfrt pour compil canaux - Ajout des nom de ST dans Combobox
  ListeCanauxTrsfrt := TStringList.Create;
  ListeCanauxTrsfrt.CaseSensitive := false;
  ListeCanauxTrsfrt.Sorted := true;

  DocDOCOMETRE.ST[STCombobox.ItemIndex].RendreListeCanauxTransfertKeithleyPC(ListeCanauxTrsfrt);
  DocDOCOMETRE.ST[STCombobox.ItemIndex].RendreListeCanauxTransfertPCKeithley(ListeCanauxTrsfrt);

  AListeCanauxEnreg := DocDOCOMETRE.ST[STCombobox.ItemIndex].LISTECANAUXENREG;
  AListeCanauxVisu := DocDOCOMETRE.ST[STCombobox.ItemIndex].LISTECANAUXVISU;

  TampTrsfrtRecVisuStringGrid.RowCount := ListeCanauxTrsfrt.Count + 1;
  for i := 0 to ListeCanauxTrsfrt.Count - 1 do
  begin
    TampTrsfrtRecVisuStringGrid.Cells[2,i+1] := ListeCanauxTrsfrt[i];
    j := InfosCanaux.Nom.IndexOf(ListeCanauxTrsfrt[i]);
    TampTrsfrtRecVisuStringGrid.Cells[3,i+1] := InfosCanaux.TailleTampon[j];
  end;


  for i := 0 to AListeCanauxEnreg.Count - 1 do
  begin
    n := TampTrsfrtRecVisuStringGrid.Cols[2].IndexOf(AListeCanauxEnreg[i].NOMCANAL);
    if n > -1 then
    begin
      if TampTrsfrtRecVisuStringGrid.Objects[0,n] = nil then
      begin
				enregVisuIcon := TImage.Create(TampTrsfrtRecVisuStringGrid);
        enregVisuIcon.Parent := TampTrsfrtRecVisuStringGrid;
        enregVisuIcon.Name := 'EnregIcon' + inttostr(n);
        enregVisuIcon.Hint := 'Enregistrement';
        enregVisuIcon.ShowHint := true;
        enregVisuIcon.Picture.LoadFromFile(ExtractFilePath(Application.ExeName) + '/Icons/record.bmp');
        enregVisuIcon.AutoSize := false;
        enregVisuIcon.Center := true;
        enregVisuIcon.Transparent := true;
        enregVisuIcon.Visible := false;
        enregVisuIcon.Stretch := false;
        //enregVisuIcon.Width := TampTrsfrtRecVisuStringGrid.ColWidths[0];
        //enregVisuIcon.Height := TampTrsfrtRecVisuStringGrid.RowHeights[0];
        TampTrsfrtRecVisuStringGrid.Objects[0,n] := enregVisuIcon;
      end;
    end else
    begin
      TampTrsfrtRecVisuStringGrid.Objects[0,n].Free;
      TampTrsfrtRecVisuStringGrid.Objects[0,n] := nil;
    end;
  end;

  for i := 0 to AListeCanauxVisu.Count - 1 do
  begin
    n := TampTrsfrtRecVisuStringGrid.Cols[2].IndexOf(AListeCanauxVisu[i].NOMCANAL);
    if n > -1 then
    begin
      if TampTrsfrtRecVisuStringGrid.Objects[1,n] = nil then
      begin
				enregVisuIcon := TImage.Create(TampTrsfrtRecVisuStringGrid);
				enregVisuIcon.Parent := TampTrsfrtRecVisuStringGrid;
				enregVisuIcon.Name := 'VisuIcon' + inttostr(n);
				enregVisuIcon.Hint := 'Visualisation';
        enregVisuIcon.ShowHint := true;
				enregVisuIcon.Picture.LoadFromFile(ExtracfFilePath(Application.ExeName) + '/Icons/read_obj.bmp');
				enregVisuIcon.AutoSize := false;
				enregVisuIcon.Center := true;
				enregVisuIcon.Transparent := true;
				enregVisuIcon.Visible := false;
				enregVisuIcon.Stretch := false;
				TampTrsfrtRecVisuStringGrid.Objects[1,n] := enregVisuIcon;
      end;
    end else
    begin
      TampTrsfrtRecVisuStringGrid.Objects[1,n].Free;
      TampTrsfrtRecVisuStringGrid.Objects[1,n] := nil;
    end;
  end;

  FullScreenCheckBox.OnClick := nil;
  StatusBarCheckBox.OnClick := nil;

  FullScreenCheckBox.Checked := DocDOCOMETRE.ST[STCombobox.ItemIndex].FULLSCREEN = 1;
  StatusBarCheckBox.Checked := DocDOCOMETRE.ST[STCombobox.ItemIndex].STATUSBAR = 1;

  FullScreenCheckBox.OnClick := FullScreenStatusBarCheckBoxClick;
  StatusBarCheckBox.OnClick := FullScreenStatusBarCheckBoxClick;

  OptionsSTGroupBox.Enabled := true;

  //reconstruire Graphes
  MAJGraphes;

  ListeCanauxTrsfrt.Free;
  InfosCanaux.Free;
end;

procedure TOptionsExecFrame.MAJGraphes;
var i,n : integer;
begin
  //clear courbes
  for i := 1 to CourbesStringGrid.RowCount - 1 do
  begin
    CourbesStringGrid.Objects[0,i].Free;
    CourbesStringGrid.Objects[0,i] := nil;
  end;
  //clear courbes
  CourbesStringGrid.RowCount := 1;
  n := STCombobox.ItemIndex;
  GraphesStringGrid.RowCount := 1 + DocDOCOMETRE.ST[n].GRAPHES.Count;
  for i := 0 to DocDOCOMETRE.ST[STCombobox.ItemIndex].GRAPHES.Count - 1 do
  begin
    // []
    GraphesStringGrid.Cells[0,i+1] := DocDOCOMETRE.ST[n].GRAPHES[i].GENRE;
    GraphesStringGrid.Cells[1,i+1] := floattostr(DocDOCOMETRE.ST[n].GRAPHES[i].TEMPSVISU);
    case DocDOCOMETRE.ST[n].GRAPHES[i].ECHELLEYAUTO of
       0 : GraphesStringGrid.Cells[2,i+1] := 'Non';
       1 : GraphesStringGrid.Cells[2,i+1] := 'Oui';
    end;
    GraphesStringGrid.Cells[3,i+1] := floattostr(DocDOCOMETRE.ST[n].GRAPHES[i].YMIN);
    GraphesStringGrid.Cells[4,i+1] := floattostr(DocDOCOMETRE.ST[n].GRAPHES[i].YMAX);
    case DocDOCOMETRE.ST[n].GRAPHES[i].ECHELLEXAUTO of
       0 : GraphesStringGrid.Cells[5,i+1] := 'Non';
       1 : GraphesStringGrid.Cells[5,i+1] := 'Oui';
    end;
    GraphesStringGrid.Cells[6,i+1] := floattostr(DocDOCOMETRE.ST[n].GRAPHES[i].XMIN);
    GraphesStringGrid.Cells[7,i+1] := floattostr(DocDOCOMETRE.ST[n].GRAPHES[i].XMAX);
  end;
end;

procedure TOptionsExecFrame.MAJCourbes;
var i,m,n : integer;
    ACourbe : IXMLListeCourbesType;
    AShape : TShape;
begin
  //clear courbes
  for i := 1 to CourbesStringGrid.RowCount - 1 do
  begin
    CourbesStringGrid.Objects[0,i].Free;
    CourbesStringGrid.Objects[0,i] := nil;
  end;
  CourbesStringGrid.RowCount := 1;
  m := STCombobox.ItemIndex;
  n := GraphesStringGrid.Selection.Top - 1;
  CourbesStringGrid.RowCount := 1 + DocDOCOMETRE.ST[m].GRAPHES[n].COURBES.Count;
  for i := 0 to DocDOCOMETRE.ST[m].GRAPHES[n].COURBES.Count - 1 do
  begin
    ACourbe := DocDOCOMETRE.ST[m].GRAPHES[n].COURBES[i];
    CourbesStringGrid.Cells[1,i+1] := ACourbe.NOMCANALORDO;
    CourbesStringGrid.Cells[2,i+1] := ACourbe.NOMCANALABSC;
    AShape := TShape.Create(CourbesStringGrid);
    AShape.Parent := CourbesStringGrid;
    AShape.Name := 'Color' + inttostr(i);
    AShape.Brush.Color := ACourbe.COLOR;
    AShape.Shape := stCircle;
    AShape.Width := 15;
    AShape.Height := 15;
    CourbesStringGrid.Objects[0,i+1] := AShape;
  end;
end;

procedure TOptionsExecFrame.NewGrapheButtonClick(Sender: TObject);
var NewGraphe : IXMLListeGraphesType;
begin
  GrapheDLGForm.Operation := 'C';
  if GrapheDLGForm.ShowModal = mrOK then
  begin
    //Ajout du nouveau graphe
    NewGraphe := DocDOCOMETRE.ST[STCombobox.ItemIndex].GRAPHES.Add;
    NewGraphe.GENRE := GrapheDLGForm.TypeCB.Items[GrapheDLGForm.TypeCB.ItemIndex];
    NewGraphe.TEMPSVISU := strtofloat(GrapheDLGForm.TpsVisuLE.Text);
    case GrapheDLGForm.EchelleYAutoCB.Checked of
      true: NewGraphe.ECHELLEYAUTO := 1;
      false : NewGraphe.ECHELLEYAUTO := 0;
    end;
    case GrapheDLGForm.EchelleXAutoCB.Checked of
      true: NewGraphe.ECHELLEXAUTO := 1;
      false : NewGraphe.ECHELLEXAUTO := 0;
    end;
    NewGraphe.YMIN := strtofloat(GrapheDLGForm.YminLE.Text);
    NewGraphe.YMAX := strtofloat(GrapheDLGForm.YmaxLE.Text);
    NewGraphe.XMIN := strtofloat(GrapheDLGForm.XminLE.Text);
    NewGraphe.XMAX := strtofloat(GrapheDLGForm.XmaxLE.Text);
    MAJGraphes;
  end;
end;

procedure TOptionsExecFrame.SuppGrapheButtonClick(Sender: TObject);
var m,n : integer;
begin
  if GraphesStringGrid.Selection.Top > 0 then
  begin
    m := STComboBox.ItemIndex;
    n := GraphesStringGrid.Selection.Top - 1;
    DocDOCOMETRE.ST[m].GRAPHES.Delete(n);
    MAJGraphes;
  end;
end;

procedure TOptionsExecFrame.DupGrapheButtonClick(Sender: TObject);
var m,n : integer;
begin
  if GraphesStringGrid.Selection.Top > 0 then
  begin
    m := STComboBox.ItemIndex;
    n := GraphesStringGrid.Selection.Top - 1;
    DocDOCOMETRE.ST[m].GRAPHES.ChildNodes.Add(DocDOCOMETRE.ST[m].GRAPHES[n].CloneNode(false) as 
IXMLListeGraphesType);
    MAJGraphes;
  end;
end;

procedure TOptionsExecFrame.GraphesStringGridDblClick(Sender: TObject);
var m,n : integer;
    AGraphe : IXMLListeGraphesType;
begin
  if GraphesStringGrid.Selection.Top > 0 then
  begin
    GrapheDLGForm.Operation := 'M';
    if GrapheDLGForm.ShowModal = mrOK then
    begin
      //Modif du graphe
      //Recup n° ST et n° Graphe
      m := STComboBox.ItemIndex;
      n := GraphesStringGrid.Selection.Top-1;
      AGraphe := DocDOCOMETRE.ST[m].GRAPHES[n];
      AGraphe.GENRE := GrapheDLGForm.TypeCB.Items[GrapheDLGForm.TypeCB.ItemIndex];
      AGraphe.TEMPSVISU := strtofloat(GrapheDLGForm.TpsVisuLE.Text);
      case GrapheDLGForm.EchelleYAutoCB.Checked of
        true: AGraphe.ECHELLEYAUTO := 1;
        false : AGraphe.ECHELLEYAUTO := 0;
      end;
      case GrapheDLGForm.EchelleXAutoCB.Checked of
        true: AGraphe.ECHELLEXAUTO := 1;
        false : AGraphe.ECHELLEXAUTO := 0;
      end;
      AGraphe.YMIN := strtofloat(GrapheDLGForm.YminLE.Text);
      AGraphe.YMAX := strtofloat(GrapheDLGForm.YmaxLE.Text);
      AGraphe.XMIN := strtofloat(GrapheDLGForm.XminLE.Text);
      AGraphe.XMAX := strtofloat(GrapheDLGForm.XmaxLE.Text);
      MAJGraphes;
    end;
  end;
end;

procedure TOptionsExecFrame.NewCourbeButtonClick(Sender: TObject);
var ACourbe : IXMLListeCourbesType;
    AGraphe : IXMLListeGraphesType;
    m,n : integer;
begin
  if GraphesStringGrid.Selection.Top > 0 then
  begin
    CourbeDLGForm.Operation := 'C';
    if CourbeDLGForm.ShowModal = mrOK then
    begin
			if (CourbeDLGForm.OrdoCB.Text <> CourbeDLGForm.AbscCB.Text) and
				 (CourbeDLGForm.OrdoCB.Text <> '') and
				 (CourbeDLGForm.AbscCB.Text <> '')	then
      begin
        m := STComboBox.ItemIndex;
        n := GraphesStringGrid.Selection.Top-1;
        AGraphe := DocDOCOMETRE.ST[m].GRAPHES[n];
        ACourbe := AGraphe.COURBES.Add;
        ACourbe.NOMCANALORDO := CourbeDLGForm.OrdoCB.Text;
        ACourbe.NOMCANALABSC := CourbeDLGForm.AbscCB.Text;
        ACourbe.COLOR := CourbeDLGForm.ColorShape.Brush.Color;
        MAJCourbes;
			end else if (CourbeDLGForm.OrdoCB.Text = CourbeDLGForm.AbscCB.Text) and
                  (CourbeDLGForm.OrdoCB.Text <> '')
							 then showmessage('Les canaux en abscisse et ordonnée sont identiques !');
    end;
  end;
end;

procedure TOptionsExecFrame.SuppCourbeButtonClick(Sender: TObject);
var AGraphe : IXMLListeGraphesType;
    m,n,p : integer;
begin
  if CourbesStringGrid.Selection.Top > 0 then
  begin
    m := STComboBox.ItemIndex;
    n := GraphesStringGrid.Selection.Top-1;
    p := CourbesStringGrid.Selection.Top-1;
    AGraphe := DocDOCOMETRE.ST[m].GRAPHES[n];
    AGraphe.COURBES.Delete(p);
    MAJCourbes;
  end;
end;

procedure TOptionsExecFrame.CourbesStringGridDblClick(Sender: TObject);
var ACourbe : IXMLListeCourbesType;
    AGraphe : IXMLListeGraphesType;
    m,n,p : integer;
begin
  if CourbesStringGrid.Selection.Top > 0 then
  begin
    CourbeDLGForm.Operation := 'M';
    if CourbeDLGForm.ShowModal = mrOK then
    begin
      if CourbeDLGForm.OrdoCB.Text <> CourbeDLGForm.AbscCB.Text then
      begin
        m := STComboBox.ItemIndex;
        n := GraphesStringGrid.Selection.Top-1;
        p := CourbesStringGrid.Selection.Top-1;
        AGraphe := DocDOCOMETRE.ST[m].GRAPHES[n];
        ACourbe := AGraphe.COURBES[p];
        ACourbe.NOMCANALORDO := CourbeDLGForm.OrdoCB.Text;
        ACourbe.NOMCANALABSC := CourbeDLGForm.AbscCB.Text;
        ACourbe.COLOR := CourbeDLGForm.ColorShape.Brush.Color;
        MAJCourbes;
      end else showmessage('Les canaux en abscisse et ordonnée sont identiques !');
    end;
  end;
end;

procedure TOptionsExecFrame.GraphesStringGridClick(Sender: TObject);
var i : integer;
begin
  if GraphesStringGrid.Selection.Top > 0
  then MAJCourbes
  else begin
    for i := 1 to CourbesStringGrid.RowCount - 1 do
    begin
      CourbesStringGrid.Objects[0,i].Free;
      CourbesStringGrid.Objects[0,i] := nil;
    end;
    CourbesStringGrid.RowCount := 1;
  end;
end;

procedure TOptionsExecFrame.PopupMenu1Popup(Sender: TObject);
var i : integer;
begin
  for i := 0 to PopupMenu1.Items.Count - 1
  do PopupMenu1.Items[i].Enabled := TampTrsfrtRecVisuStringGrid.Selection.Top > 0;
end;

end.
