{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 UInspectFrame;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, ExtCtrls, StdCtrls, CheckLst, UGlobal, UGrapheInspectFrame,XMLClasses,
  StimuliClass, Menus, ComCtrls, ToolWin;

const color1 = $DDEEFF;
      color2 = $FFF8DF;

type
  TInspectFrame = class(TFrame)
    Panel7: TPanel;
    Shape8: TShape;
    Shape9: TShape;
    Panel1: TPanel;
    Panel2: TPanel;
    DataCLB: TCheckListBox;
    SujetCB: TComboBox;
    Splitter1: TSplitter;
    Image1: TImage;
    GrapheScrollBox: TScrollBox;
    ExportPopupMenu: TPopupMenu;
    ExportAnalyse: TMenuItem;
    ExportSelectedFilesToText: TMenuItem;
		ExportAllFilesToText: TMenuItem;
		Panel3: TPanel;
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    ExportProgressBar: TProgressBar;
    N1: TMenuItem;
    ExportAllSubjectToAnalyse: TMenuItem;
    ExportAllSubjectsToTextFile: TMenuItem;
    procedure SujetCBSelect(Sender: TObject);
    procedure DataCLBDrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    procedure DataCLBClickCheck(Sender: TObject);
    procedure GrapheScrollBoxResize(Sender: TObject);
    procedure GrapheScrollBoxDragOver(Sender, Source: TObject; X,
      Y: Integer; State: TDragState; var Accept: Boolean);
    procedure GrapheScrollBoxDragDrop(Sender, Source: TObject; X,
      Y: Integer);
    procedure DataCLBDblClick(Sender: TObject);
    procedure ExportAnalyseClick(Sender: TObject);
    procedure ExportSelectedFilesToTextClick(Sender: TObject);
    procedure ExportAllFilesToTextClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ExportPopupMenuPopup(Sender: TObject);
    procedure ExportAllSubjectToAnalyseClick(Sender: TObject);
    procedure ExportAllSubjectsToTextFileClick(Sender: TObject);
    procedure Image1Click(Sender: TObject);
  private
    { Déclarations privées }
    lastColor : TColor;
    procedure DataCLBClear;
    procedure addSerieToNewGraphe(Name : string);
    procedure deleteSerieFromGraph(Name : string);
    procedure GrapheScrollBoxTile;
		function GrapheScrollBoxGetNewGraphName : string;
		procedure ExportBinFileToTextFile(fileName : string);
  public
    { Déclarations publiques }
    procedure MAJIHM;
    procedure addSerieToGraphe(AGraph : TGrapheInspectFrame;Name : string);
  end;

implementation

uses UDocometre, UShiftGainInspect;

var colorCLB : array of TColor;

{$R *.dfm}

procedure TInspectFrame.DataCLBClear;
var i : integer;
begin
  DataCLB.Style := lbStandard;
  for i := 0 to DataCLB.Items.Count - 1 do
  begin
    if DataCLB.Checked[i] then
		begin
			DataCLB.ItemIndex := i;
      deleteSerieFromGraph(DataCLB.Items[i]);
    end;
  end;
  DataCLB.Clear;
  DataCLB.Style := lbOwnerDrawFixed;
end;

procedure TInspectFrame.MAJIHM;
var //sr : TSearchRec;
		i : integer;
begin
	SujetCB.Clear;
	DataCLBClear;

	for i := 0 to DocDOCOMETRE.SUJETS.Count - 1
	do SujetCB.Items.Add(DocDOCOMETRE.SUJETS[i].NOM);

	for i := 0 to DocDOCOMETRE.ST.Count - 1
	do SujetCB.Items.Add('Test_' + DocDOCOMETRE.ST[i].NOM);

	{
	if FindFirst(Rep_Manip + '*.', faDirectory, sr) = 0 then
  begin
    repeat
      if (sr.Name <> '.') and (sr.Name <> '..') and (sr.Name <> 'BinSources')
			then SujetCB.Items.Add(sr.Name);
    until FindNext(sr) <> 0;
    FindClose(sr);
	end;      }
end;

procedure TInspectFrame.SujetCBSelect(Sender: TObject);
var sr : TSearchRec;
    n : integer;
begin
	SetLength(colorCLB,0);
  DataCLBClear;
  n := 0;
  if FindFirst(Rep_Manip + SujetCB.Text + '\*.sau', faAnyFile	, sr) = 0 then
  begin
    repeat
      DataCLB.Items.Add(sr.Name);
			inc(n);
    until FindNext(sr) <> 0;
    FindClose(sr);
  end;
  SetLength(colorCLB,n);
  for n := 0 to high(colorCLB) do colorCLB[n] := -1;
end;

procedure TInspectFrame.DataCLBDrawItem(Control: TWinControl;
  Index: Integer; Rect: TRect; State: TOwnerDrawState);
var section1,section2 : string;
begin
  if colorCLB[index] = -1 then
  begin
    section2 := DataCLB.Items[index];
    delete(section2,1,pos('_',section2));
    delete(section2,pos('_',section2),length(section2));
    section1 := '';
    if index > 0 then
    begin
      section1 := DataCLB.Items[index-1];
      delete(section1,1,pos('_',section1));
      delete(section1,pos('_',section1),length(section1));
    end;

    if index = 0 then lastColor := color1;

    if section1 <> section2 then
    begin
      if lastColor = color2
      then colorCLB[index] := color1
      else colorCLB[index] := color2;
    end else colorCLB[index] := lastColor;
    lastColor := colorCLB[index];
	end;
  
  if odSelected in State
  then DataCLB.Canvas.Brush.Color := clBlue
  else DataCLB.Canvas.Brush.Color := colorCLB[index];
  DataCLB.Canvas.FillRect(Rect);
	DataCLB.Canvas.TextOut(Rect.Left,Rect.Top,DataCLB.Items[index]);
end;

procedure TInspectFrame.GrapheScrollBoxTile;
var i,aHeight : integer;
begin
  if GrapheScrollBox.ControlCount > 0 then
  begin
    aHeight := GrapheScrollBox.ClientHeight div GrapheScrollBox.ControlCount;
    for i := 0 to GrapheScrollBox.ControlCount - 1
    do GrapheScrollBox.Controls[i].Height := aHeight;
  end;
end;

function TInspectFrame.GrapheScrollBoxGetNewGraphName : string;
var n,i : integer;
    fin : boolean;
begin
  n := 1;
  repeat
    fin := true;
    Result := 'GrapheInspectFrame' + inttostr(n);
    for i := 0 to GrapheScrollBox.ControlCount - 1
    do if GrapheScrollBox.Controls[i].Name = Result
       then fin := false;
    inc(n);
  until fin;
end;

procedure TInspectFrame.addSerieToGraphe(AGraph : TGrapheInspectFrame;Name : string);
var ListeCanaux : TInfoCanaux;
    channelName : string;
		fe : double;
    nbUnderscores,index,nbUnderscoresCurent : integer;
begin
	ListeCanaux := DocDOCOMETRE.RendreListeInfoCanaux;

  nbUnderscores := DocDOCOMETRE.FORMATNOMFICHIERSSAVE.UseNOMST +
                   DocDOCOMETRE.FORMATNOMFICHIERSSAVE.UseNOMSESSION +
                   DocDOCOMETRE.FORMATNOMFICHIERSSAVE.UseNUMSESSION +
                   DocDOCOMETRE.FORMATNOMFICHIERSSAVE.UseNUMESSAI;

	channelName := name;

  index := length(channelName);
  nbUnderscoresCurent := 0;
  repeat
        if channelName[index] = '_' then inc(nbUnderscoresCurent);
        dec(index);
  until  nbUnderscoresCurent = nbUnderscores;
  inc(index);

	delete(channelName,index,length(channelName));

	if ListeCanaux.Nom.IndexOf(channelName) > -1 then
	begin
		fe := DocDOCOMETRE.EXPERIENCE.FEG div strtoint(ListeCanaux.RappFreq[ListeCanaux.Nom.IndexOf(channelName)]);
		DataCLB.Items.Objects[DataCLB.ItemIndex] := AGraph.addSerie(name,rep_manip + SujetCB.Text + '\' + Name,fe);
		DocoForm.StatusBar1.SimpleText := '';
	end else
	begin
		DocoForm.StatusBar1.SimpleText := 'le canal "' + channelName + '" est inconnu !';
		DataCLB.Checked[DataCLB.ItemIndex] := false;
		if AGraph.Chart.SeriesCount = 0 then AGraph.Free;
	end;
	ListeCanaux.free;
  GrapheScrollBoxTile;
end;

procedure TInspectFrame.addSerieToNewGraphe(Name : string);
var AGraph : TGrapheInspectFrame;
begin
	AGraph := TGrapheInspectFrame.Create(Self);
	AGraph.Name := GrapheScrollBoxGetNewGraphName;
	AGraph.Parent := GrapheScrollBox;
	addSerieToGraphe(AGraph,Name);
end;

procedure TInspectFrame.deleteSerieFromGraph(Name : string);
var AStimulus : TStimulus;
    ParentGrapheInspectFrame : TGrapheInspectFrame;//TWinControl;
begin
  AStimulus := (DataCLB.Items.Objects[DataCLB.ItemIndex] as TStimulus);
  ParentGrapheInspectFrame := AStimulus.ParentChart.Parent as TGrapheInspectFrame;
  ParentGrapheInspectFrame.removeSerie(AStimulus);
       {
  if AStimulus.ParentChart.SeriesCount = 1 then
  begin
    AStimulus.Free;
    ParentGrapheInspectFrame.Free;
	end else AStimulus.Free;                              }
  DataCLB.Items.Objects[DataCLB.ItemIndex] := nil;
  GrapheScrollBoxTile;
end;

procedure TInspectFrame.DataCLBClickCheck(Sender: TObject);
begin
	if DataCLB.Checked[DataCLB.ItemIndex]
  then addSerieToNewGraphe(DataCLB.Items[DataCLB.ItemIndex])
  else deleteSerieFromGraph(DataCLB.Items[DataCLB.ItemIndex]);
end;

procedure TInspectFrame.GrapheScrollBoxResize(Sender: TObject);
begin
  GrapheScrollBoxTile;
end;

procedure TInspectFrame.GrapheScrollBoxDragOver(Sender, Source: TObject; X,
  Y: Integer; State: TDragState; var Accept: Boolean);
var theCheckListBox : TCheckListBox;
begin
  Accept := false;
  if Source.ClassName = 'TCheckListBox' then
  begin
    theCheckListBox := (Source as TCheckListBox);
    if not theCheckListBox.Checked[theCheckListBox.ItemIndex]
    then accept := true;
  end;
end;

procedure TInspectFrame.GrapheScrollBoxDragDrop(Sender, Source: TObject; X,
  Y: Integer);
begin
  DataCLB.Checked[DataCLB.ItemIndex] := true;
	addSerieToNewGraphe(DataCLB.Items[DataCLB.ItemIndex]);
end;

procedure TInspectFrame.DataCLBDblClick(Sender: TObject);
begin
  if DataCLB.Items.Objects[DataCLB.ItemIndex] <> nil then
	begin
    ShiftGainInspectDLGForm.AStimulus := (DataCLB.Items.Objects[DataCLB.ItemIndex] as TStimulus);
    ShiftGainInspectDLGForm.AInspectFrame := Self;
    ShiftGainInspectDLGForm.ShowModal;
  end;
end;

procedure TInspectFrame.ExportAnalyseClick(Sender: TObject);
var FoundRec : TSearchRec;
		path : string;
		Liste_Fichier : TStringList;
		nSession,sessDone : integer;
    createFileForAnalyse : boolean;
    SaveCursor : TCursor;
												 
		procedure CreerFichier(numSujet : integer);
		var Fichier_ADW : TFileStream;
				i,j,k,l,nb,taille,dummy : integer;
				nom_fichier,CR,nom,S : string;
				Sous_Liste,Liste_Nom_Canaux : TStringList;
				fe : single;
				Fichier_Courant : TFileStream;
				infosCanaux : TInfoCanaux;
		begin
			//creer le fichier nomexp_nomsujet.adw
			nom_fichier := path + DocDOCOMETRE.EXPERIENCE.NOM + DocDOCOMETRE.SUJETS[numSujet].NOM + '.adw';
			Fichier_ADW := TFileStream.Create(nom_fichier,fmCreate);
			CR := '|';
			//******
			//ENTETE
			//construction Nom des canaux
			Liste_Nom_Canaux:= TStringList.Create;
			Liste_Nom_Canaux.Sorted := true;
			for i := 0 to Liste_Fichier.count - 1 do
			begin
				k := length(Liste_Fichier[i]);
				repeat
					dec(k);
				until Liste_Fichier[i][k] = 'S';
				nom := copy(Liste_fichier[i],1,k-2);
				Liste_Nom_Canaux.Add(nom);
			end;
			//Nombre de canaux
			nb := Liste_Nom_Canaux.Count;
			Fichier_ADW.Write(nb,sizeof(nb));
			//Nom des canaux
			for i := 0 to Liste_Nom_Canaux.Count - 1 do
			begin
				Fichier_ADW.Write(PChar(Liste_Nom_Canaux[i])^,length(Liste_Nom_Canaux[i]));
				Fichier_ADW.Write(PChar(CR)^,length(CR));
			end;

			//Nombre de sessions
			nb := DocDOCOMETRE.SUJETS[numSujet].SESSIONS.Count;
			Fichier_ADW.Write(nb,sizeof(nb));
			//Nom des sessions
			for i := 0 to DocDOCOMETRE.SUJETS[numSujet].SESSIONS.Count - 1 do
			begin
				nom := DocDOCOMETRE.SUJETS[numSujet].SESSIONS[i].NOM;
				Fichier_ADW.Write(PChar(nom)^,length(nom));
				Fichier_ADW.Write(PChar(CR)^,length(CR));
			end;

			// DEBUT ----> laisser pour compatibilité *************
			//Nombre de CE
			nb := 1;
			Fichier_ADW.Write(nb,sizeof(nb));
			//Nom des CE
			for i := 0 to nb - 1 do
			begin
				nom := 'Cond_Exp_1';
				Fichier_ADW.Write(PChar(nom)^,length(nom));
				Fichier_ADW.Write(PChar(CR)^,length(CR));
			end;
			// FIN ----> laisser pour compatibilité *************

			//Nombre de ST
			nb := DocDOCOMETRE.ST.Count;
			Fichier_ADW.Write(nb,sizeof(nb));
			//Nom des ST
			for i := 0 to DocDOCOMETRE.ST.Count - 1 do
			begin
				nom := DocDOCOMETRE.ST[i].NOM;
				Fichier_ADW.Write(PChar(nom)^,length(nom));
				Fichier_ADW.Write(PChar(CR)^,length(CR));
			end;
			//Nombre total d'essais
			nb := 0;
			for i := 0 to DocDOCOMETRE.SUJETS[numSujet].SESSIONS.Count - 1
			do nb := nb + DocDOCOMETRE.SUJETS[numSujet].SESSIONS[i].ESSAIS.Count;
			Fichier_ADW.Write(nb,sizeof(nb));
			//ENTETE
			//******

			//*****************
			//POUR CHAQUE ESSAI
			ExportProgressBar.Position := 0;
			ExportProgressBar.Max := DocDOCOMETRE.SUJETS[numSujet].SESSIONS.Count;

			infosCanaux := DocDOCOMETRE.RendreListeInfoCanaux;

			Sous_liste := TStringList.Create;
			Sous_Liste.sorted := true;
			for i := 0 to DocDOCOMETRE.SUJETS[numSujet].SESSIONS.Count - 1 do
			begin
			  ExportProgressBar.Position := i + 1;
				for j := 0 to DocDOCOMETRE.SUJETS[numSujet].SESSIONS[i].ESSAIS.Count - 1 do
				begin
					k := 0;
					repeat
						nom := '_S'+inttostr(i+1)+'_E'+inttostr(j+1);
						if Liste_Fichier.Count > 0
						then S := copy(Liste_Fichier[k],pos(nom,Liste_Fichier[k]),length(Liste_Fichier[k]))
						else S := '';
						delete(S,pos('.sau',S),4);
						if S = nom then
						begin
							Sous_Liste.Add(Liste_Fichier[k]);
							Liste_Fichier.Delete(k);
							dec(k);
						end;
						inc(k);
					until (k = Liste_fichier.Count) or (Liste_Fichier.Count = 0);
					//Numéro de la session
					nb := i+1;
					Fichier_ADW.Write(nb,sizeof(nb));

					// DEBUT ----> laisser pour compatibilité *************
					//Numéro de la CE
					nb := 1;
					Fichier_ADW.Write(nb,sizeof(nb));
					// FIN ----> laisser pour compatibilité *************

					//Numéro de la ST
					dummy := -1;
					repeat
						inc(dummy);
					until DocDOCOMETRE.ST[dummy].NOM = DocDOCOMETRE.SUJETS[numSujet].SESSIONS[i].ESSAIS[j].NOMST;
					nb := dummy+1;
					Fichier_ADW.Write(nb,sizeof(nb));
					//Nb canaux
					nb := Sous_Liste.Count;
					Fichier_ADW.Write(nb,sizeof(nb));
					//*****************
					//Pour chaque canal
					for k := 0 to Sous_Liste.Count - 1 do
					begin
						//NOM
						l := length(Sous_Liste[k]);
						repeat
							dec(l);
						until Sous_Liste[k][l] = 'S';
						nom := copy(Sous_Liste[k],1,l-2);
						Liste_Nom_Canaux.Find(nom,nb);
						inc(nb);
						Fichier_ADW.Write(nb,sizeof(nb));
						//Fichier_ADW.Write(PChar(nom)^,Length(nom));
						//Fichier_ADW.Write(PChar(CR)^,length(CR));
						//FE
						fe := strtofloat(infosCanaux.RappFreq[infosCanaux.Nom.IndexOf(nom)]);
						fe := DocDOCOMETRE.EXPERIENCE.FEG / fe;
						Fichier_ADW.Write(fe,sizeof(fe));
						//TAILLE DONNEES
						Fichier_Courant := TFileStream.Create(path+Sous_Liste[k],fmOpenRead);
						Taille := Fichier_Courant.Size div 4;
						Fichier_ADW.Write(taille,sizeof(taille));
						//DONNEES
						Fichier_ADW.CopyFrom(Fichier_Courant,Fichier_Courant.size);
						Fichier_Courant.free;
					end;
					Sous_Liste.Clear;
				end;
			end;
			infosCanaux.free;
			Sous_Liste.free;
			Fichier_ADW.Free;
			Liste_Nom_Canaux.Clear;
			Liste_Nom_Canaux.free;
		end;

begin
	//Verifier que ttes les sessions de ce sujets sont faites
  createFileForAnalyse := false;
	sessDone := 0;
	for nSession := 0 to DocDOCOMETRE.SUJETS[SujetCB.ItemIndex].SESSIONS.Count - 1 do
  begin
		if DocDOCOMETRE.SUJETS[SujetCB.ItemIndex].SESSIONS[nSession].percentDone = 100
		then inc(SessDone);
	end;

  createFileForAnalyse := (sessDone = DocDOCOMETRE.SUJETS[SujetCB.ItemIndex].SESSIONS.Count);
  if not createFileForAnalyse then
  begin
    showmessage('Toutes les sessions de ce Sujet n''ont pas été effectuées !');
    createFileForAnalyse  := messageDLG('Créer quand même le fichier pour analyse ?',mtConfirmation	,[mbYES,mbNO],0) = mrYes;
    createFileForAnalyse := false;
    if createFileForAnalyse then
    begin
      //créer les fichiers manquant
      //... 
    end;
  end;

	if createFileForAnalyse then
	begin
		path := rep_manip + SujetCB.Text + '\';
		Liste_Fichier := TStringList.Create;
		Liste_Fichier.Sorted := true;
		if findfirst(path + '*.sau',faArchive,FoundRec)=0 then
		begin
			repeat
				Liste_fichier.Add(FoundRec.Name);
			until findNext(FoundRec) <> 0;
			findClose(FoundRec);
      SaveCursor := Screen.Cursor;
      Screen.Cursor := crHourGlass;
			CreerFichier(SujetCB.ItemIndex);
      Screen.Cursor := SaveCursor;
      ShowMessage('Fichier pour analyse créé');
		end else showmessage('Aucun fichier de sauvegarde de données n''est présent !');
		Liste_Fichier.Free;
	end;
end;

procedure TInspectFrame.ExportBinFileToTextFile(fileName : string);
var binFile,textFile : TFileStream;
		i : integer;
		FormatX,FormatY : string;
		value,time,fe,tempX,tempY : single;
		stringValue : string;
		infosCanaux : TInfoCanaux;
		fin : boolean;
begin
	infosCanaux := DocDOCOMETRE.RendreListeInfoCanaux;

	i := -1;
	repeat
		inc(i);
	until pos(infosCanaux.Nom[i],fileName) > -1;
	fe := strtofloat(infosCanaux.RappFreq[i]);
	fe := DocDOCOMETRE.EXPERIENCE.FEG / fe;
	infosCanaux.Free;
	
	fileName := rep_manip + SujetCB.Text + '\' + fileName;
	binFile := TFileStream.Create(fileName,fmOpenRead);
	delete(fileName,length(fileName) - 2,3);
	fileName := fileName + 'txt';
	textFile := TFileStream.Create(fileName,fmCreate);

	for i := 0 to (binFile.Size div 4) - 1 do
	begin
		binFile.Read(value,4);
		time := i / fe;

		tempx := time;
			formatX := '0';
			fin := false;
			repeat
				tempx := tempx /10.0;
				if tempx<1.0
				then fin := true
				else FormatX := FormatX + '0';
			until fin ;
			formatX := FormatX + '.######';

			tempy := value;
			formatY := '0';
			fin := false;
			repeat
				tempy := tempy /10.0;
				if tempy<1.0
				then fin := true
				else FormatY := FormatY + '0';
			until fin;
			formatY := FormatY + '.######';   

		stringValue := FormatFloat(formatY,value);
		stringValue := stringValue + ';' + FormatFloat(formatX,time);
		stringValue := stringValue + #13 + #10;
		textFile.Write(stringValue[1],length(stringValue));

	end;


	binFile.Free;
	textFile.Free
end;

procedure TInspectFrame.ExportSelectedFilesToTextClick(Sender: TObject);
var i,n : integer;
    SaveCursor : TCursor;
begin
	i := 0;
	n := 0;
	repeat
		if DataCLB.Checked[i] then inc(n);
		inc(i)
	until i = DataCLB.Items.Count;

	ExportProgressBar.Position := 0;
	ExportProgressBar.Max := n;
  SaveCursor := Screen.Cursor;
  Screen.Cursor := crHourGlass;
	for i := 0 to DataCLB.Items.Count - 1 do
	begin
		if DataCLB.Checked[i] then
		begin
		  ExportProgressBar.Position := ExportProgressBar.Position + 1;
			ExportBinFileToTextFile(DataCLB.Items[i]);
		end;
	end;
  Screen.Cursor := SaveCursor;
  ShowMessage('Exportation terminée');
end;

procedure TInspectFrame.ExportAllFilesToTextClick(Sender: TObject);
var i : integer;
    SaveCursor : TCursor;
begin
	ExportProgressBar.Position := 0;
	ExportProgressBar.Max := DataCLB.Items.Count;
  SaveCursor := Screen.Cursor;
  Screen.Cursor := crHourGlass;
	for i := 0 to DataCLB.Items.Count - 1 do
	begin
		ExportProgressBar.Position := i + 1;
		ExportBinFileToTextFile(DataCLB.Items[i])
	end;
  Screen.Cursor := SaveCursor;
  ShowMessage('Exportation terminée');
end;

procedure TInspectFrame.ToolButton1Click(Sender: TObject);
begin
	if SujetCB.ItemIndex > -1
	then if messageDlg('Souhaitez créer le fichier pour Analyse ?',mtConfirmation ,[mbYes,mbNo],0) = mrYes
			 then ExportAnalyseClick(self);
end;

procedure TInspectFrame.ExportPopupMenuPopup(Sender: TObject);
var i : integer;
		isSubject : boolean;
begin
	i := 0;
	repeat
		ExportPopupMenu.Items[i].Enabled := (SujetCB.ItemIndex > -1);
		inc(i);
	until ExportPopupMenu.Items[i].Caption = '-';

	isSubject := false;
	for i := 0 to DocDOCOMETRE.SUJETS.Count - 1 do
	begin
		if DocDOCOMETRE.SUJETS[i].NOM = SujetCB.Text
		then isSubject := true;
	end;

	ExportAnalyse.Enabled := isSubject;
  ExportAllSubjectToAnalyse.Enabled := isSubject;

end;

procedure TInspectFrame.ExportAllSubjectToAnalyseClick(Sender: TObject);
var i : integer;
begin
	try
	  panel1.Enabled := false;
		for i := 0 to SujetCB.Items.Count - 1 do
		begin
			SujetCB.ItemIndex := i;
			SujetCBSelect(Self);
			DataCLB.Refresh;
			ExportAnalyseClick(Self);
		end;
	finally
		panel1.Enabled := true;
	end;
end;

procedure TInspectFrame.ExportAllSubjectsToTextFileClick(Sender: TObject);
var i : integer;
begin
	try
		panel1.Enabled := false;
		for i := 0 to SujetCB.Items.Count - 1 do
		begin
			SujetCB.ItemIndex := i;
			SujetCBSelect(Self);
			DataCLB.Refresh;
			ExportAllFilesToTextClick(Self);
		end;
	finally
		panel1.Enabled := true;
	end;
end;

procedure TInspectFrame.Image1Click(Sender: TObject);
begin
  ShowMessage(inttostr((Sender as TImage).Tag));
  DocoForm.ShowHelp((Sender as TImage).Tag);
end;

end.
