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

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls, Gauges, ComCtrls, XMLClasses;

type
  TRunSujetForm = class(TForm)
    BitBtn2: TBitBtn;
    BitBtn1: TBitBtn;
    SujetsCB: TComboBox;
    Label1: TLabel;
    sessDoneGauge: TGauge;
    Label3: TLabel;
    runSessionRG: TRadioGroup;
    sessionPC: TPageControl;
    oneSessionTS: TTabSheet;
    severalSessionsTS: TTabSheet;
    Label2: TLabel;
    SessionsCB: TComboBox;
    Label4: TLabel;
    essaiDoneGauge: TGauge;
    usedSessionsLB: TListBox;
    Panel2: TPanel;
    Label5: TLabel;
    Label6: TLabel;
    sessionsLB: TListBox;
    Panel1: TPanel;
    addSP: TSpeedButton;
    addAllSP: TSpeedButton;
    supSP: TSpeedButton;
    supAllSP: TSpeedButton;
    randomSP: TSpeedButton;
    procedure FormShow(Sender: TObject);
    procedure SujetsCBChange(Sender: TObject);
    procedure SessionsCBChange(Sender: TObject);
    procedure runSessionRGClick(Sender: TObject);
    procedure addSPClick(Sender: TObject);
    procedure addAllSPClick(Sender: TObject);
    procedure supSPClick(Sender: TObject);
    procedure supAllSPClick(Sender: TObject);
    procedure randomSPClick(Sender: TObject);
    procedure FormResize(Sender: TObject);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
  end;

var
  RunSujetForm: TRunSujetForm;

implementation

uses UDocometre;

{$R *.dfm}

procedure TRunSujetForm.FormShow(Sender: TObject);
var i : integer;
begin
  SujetsCB.Clear;
  SessionsCB.Clear;
  sessionsLB.Clear;
  usedSessionsLB.Clear;
  sessDoneGauge.Progress := 0;
  essaiDoneGauge.Progress := 0;
  runSessionRG.Enabled := false;
  sessionPC.Enabled := false;
  sessionPC.TabIndex := 0;
  for i := 0 to DocDOCOMETRE.SUJETS.Count - 1
  do SujetsCB.Items.Add(DocDOCOMETRE.SUJETS[i].NOM);
end;

procedure TRunSujetForm.SujetsCBChange(Sender: TObject);
var i,SessDone : integer;
    S : string;
    session : IXMLSESSIONType;
begin
  SessDone := 0;
  SessionsCB.Clear;
  for i := 0 to DocDOCOMETRE.SUJETS[SujetsCB.ItemIndex].SESSIONS.Count - 1 do
  begin
    session := DocDOCOMETRE.SUJETS[SujetsCB.ItemIndex].SESSIONS[i];
    if(session.ESSAIS.Count > 0) then
    begin
      if session.percentDone = 100  then inc(SessDone);
    end else
    begin
      inc(SessDone);
      MessageDlg('Aucun essai pour la session ' + session.Get_NOM,mtWarning,[mbOK],0);
    end;
    S := session.NOM;
    SessionsCB.Items.Add(S);
    SessionsLB.Items.Add(inttostr(i+1) + '-' + S);
  end;
  if DocDOCOMETRE.SUJETS[SujetsCB.ItemIndex].SESSIONS.Count > 0 then
  begin
    sessDoneGauge.Progress := trunc(100.0*SessDone/DocDOCOMETRE.SUJETS[SujetsCB.ItemIndex].SESSIONS.Count);
    essaiDoneGauge.Progress := 0;
    runSessionRG.Enabled := true;
    sessionPC.Enabled := true;
  end else MessageDlg('Aucune session de définie pour ce sujet !',mtWarning,[mbOK],0);
end;

procedure TRunSujetForm.SessionsCBChange(Sender: TObject);
begin
  if DocDOCOMETRE.SUJETS[SujetsCB.ItemIndex].SESSIONS[SessionsCB.ItemIndex].ESSAIS.Count > 0
  then essaiDoneGauge.Progress := DocDOCOMETRE.SUJETS[SujetsCB.ItemIndex].SESSIONS[SessionsCB.ItemIndex].percentDone
  else begin
    essaiDoneGauge.Progress := 100;
    MessageDlg('Aucun essai pour cette session!',mtWarning,[mbOK],0);
  end;
end;

procedure TRunSujetForm.runSessionRGClick(Sender: TObject);
begin
  oneSessionTS.TabVisible := runSessionRG.ItemIndex = 0;
  severalSessionsTS.TabVisible := runSessionRG.ItemIndex = 1;
end;

procedure TRunSujetForm.addSPClick(Sender: TObject);
var i : integer;
begin
  for i := 0 to sessionsLB.Count - 1 do
  begin
    if sessionsLB.Selected[i] then usedSessionsLB.Items.Add(sessionsLB.Items[i])
  end;
  sessionsLB.DeleteSelected;
end;

procedure TRunSujetForm.addAllSPClick(Sender: TObject);
begin
  usedSessionsLB.Items.AddStrings(sessionsLB.Items);
  sessionsLB.Clear;
end;

procedure TRunSujetForm.supSPClick(Sender: TObject);
var i : integer;
begin
  for i := 0 to usedSessionsLB.Count - 1 do
  begin
    if usedSessionsLB.Selected[i] then sessionsLB.Items.Add(usedSessionsLB.Items[i])
  end;
  usedSessionsLB.DeleteSelected;
end;

procedure TRunSujetForm.supAllSPClick(Sender: TObject);
begin
  sessionsLB.Items.AddStrings(usedSessionsLB.Items);
  usedSessionsLB.Clear;
end;

procedure TRunSujetForm.randomSPClick(Sender: TObject);
var n : integer;
    liste : TStringList;
begin
  if usedSessionsLB.Count > 1 then
  begin
    liste := TStringList.Create;

    liste.AddStrings(usedSessionsLB.Items);
    usedSessionsLB.Clear;
    repeat
      n := random(liste.Count);
      usedSessionsLB.Items.Add(Liste[n]);
      liste.Delete(n);
    until liste.Count = 0;
    liste.Free;
  end;
end;

procedure TRunSujetForm.FormResize(Sender: TObject);
begin
  sessionsLB.Width := sessionsLB.Parent.ClientWidth div 2 - Panel1.Width div 2;
  usedSessionsLB.Width := sessionsLB.Width;
end;

end.
