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

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ImgList, ActnList,
  XPStyleActnCtrls, ActnMan, ToolWin, ActnCtrls, Tabs, UParamGeneFrame,
  UConfigHardwareFrame, UDescripFrame, xmldom, XMLIntf, msxmldom, XMLDoc,
  XMLClasses, Menus, oxmldom, xercesxmldom, {Registry,} USimulFrame,
  UOrgaFrame, UOptionsConf, UOptionsExecFrame, UHelpFrame, OleCtrls,
  SHDocVw, ComObj, UExecFrame, XPMan, ActnColorMaps, ActnMenus, StdActns,
  UInspectFrame;

type
  TDocoForm = class(TForm)
    PageControl1: TPageControl;
    TabSet1: TTabSet;
    InfosTabSheet: TTabSheet;
    ParamGeneConfHardDescriptTabSheet: TTabSheet;
    SimulTabSheet: TTabSheet;
    OptionsExecTabSheet: TTabSheet;
    ParamGeneFrame: TParamGeneFrame;
    ConfigHardFrame: TConfigHardFrame;
    DescriptFrame: TDescriptFrame;
    Splitter1: TSplitter;
    RefreshIHMTimer: TTimer;
    XMLDoco: TXMLDocument;
    ActionList1: TActionList;
    NouveauAction: TAction;
    EnregistrerAction: TAction;
    SaveDialog: TSaveDialog;
    OuvrirAction: TAction;
    OpenDialog: TOpenDialog;
    EnregistrerSousAction: TAction;
    FermerAction: TAction;
    QuitterAction: TAction;
    SimulFrame: TSimulFrame;
    OptConfAction: TAction;
    AllerAInfoAction: TAction;
    AllerAParamGeneAction: TAction;
    AllerADescripAction: TAction;
    AllerAOrgaAction: TAction;
    AllerASimAction: TAction;
    AllerAOptionsExecAction: TAction;
    OrgaFrame: TOrgaFrame;
    ImageList1: TImageList;
    OptionsExecFrame: TOptionsExecFrame;
    HelpFrame: THelpFrame;
    Splitter2: TSplitter;
    StatusBar1: TStatusBar;
    InfosWebBrowser: TWebBrowser;
    PrintAction: TAction;
    RecentFileAction1: TAction;
    ViewBeforePrintAction: TAction;
    ExecTabSheet: TTabSheet;
    AllerAExecAction: TAction;
    ExecFrame: TExecFrame;
    XPManifest1: TXPManifest;
    ActionMainMenuBar1: TActionMainMenuBar;
    RecentFileAction2: TAction;
    RecentFileAction3: TAction;
    RecentFileAction4: TAction;
    RecentFileAction5: TAction;
    ActionToolBar1: TActionToolBar;
    ActionManager: TActionManager;
    AideAction: TAction;
    AProposAction: TAction;
    InspectTabSheet: TTabSheet;
    InspectFrame: TInspectFrame;
    AllerAInspecAction: TAction;
    procedure TabSet1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure RefreshIHMTimerTimer(Sender: TObject);
    procedure NouveauActionExecute(Sender: TObject);
    procedure EnregistrerActionExecute(Sender: TObject);
    procedure OuvrirActionExecute(Sender: TObject);
    procedure EnregistrerSousActionExecute(Sender: TObject);
    procedure FermerActionExecute(Sender: TObject);
    procedure QuitterActionExecute(Sender: TObject);
    procedure FormMouseWheel(Sender: TObject; Shift: TShiftState;
      WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
    procedure TabSet1DragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
    procedure PageControl1Change(Sender: TObject);
    procedure OptConfActionExecute(Sender: TObject);
    procedure AllerAInfoActionExecute(Sender: TObject);
    procedure AllerAParamGeneActionExecute(Sender: TObject);
    procedure AllerADescripActionExecute(Sender: TObject);
    procedure AllerAOrgaActionExecute(Sender: TObject);
    procedure AllerASimActionExecute(Sender: TObject);
    procedure AllerAOptionsExecActionExecute(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure SimulFrameRunSimulActionExecute(Sender: TObject);
    procedure ParamGeneFrameImage1Click(Sender: TObject);
    procedure PrintActionExecute(Sender: TObject);
    procedure RecentFileActionExecute(Sender: TObject);
    procedure ViewBeforePrintActionExecute(Sender: TObject);
    procedure InfosTabSheetShow(Sender: TObject);
    procedure AllerAExecActionExecute(Sender: TObject);
    procedure AideActionExecute(Sender: TObject);
    procedure AProposActionExecute(Sender: TObject);
    procedure ParamGeneFrameDescriptionMemoChange(Sender: TObject);
    procedure Splitter2Moved(Sender: TObject);
    procedure AllerAInspecActionExecute(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Déclarations privées }
    procedure OuvrirDocument(Nom : string);
    procedure MAJListeFichiersRecents(Nom : string);
  public
    { Déclarations publiques }
    procedure Delay(microsec : int64);
    procedure MAJIHM ;
    procedure ClearIHM;
    procedure MAJMenuTabSheets(Etat:string);
    procedure ShowHelp(index : integer);
    function checkChannelName(var channelName: string; var Key : char) : boolean;
  protected
  end;

var
  DocoForm: TDocoForm;
  DocDOCOMETRE : IXMLROOTType;

{  Rep_Actions,Rep_Traitements,Rep_Stimuli,Rep_Fonctions : string;
  Rep_Racine,Rep_Manip,Rep_FichiersInf,ADBasic : string;
  Nb_Process,Num_Process,Link_Address : integer;
  Level_Appli, Level_RecupGene, Level_Affiche : string;
  Enreg_Stats : boolean;      }

  
implementation


Uses UGlobal, UAPropos, UHelp;
//uses UOptionsConf;

{$R *.dfm}


procedure TDocoForm.Delay(microsec : int64);
var Freq,C1,C2,DC : int64;
    dummy : double;
begin
  QueryPerformanceFrequency(Freq);
  QueryPerformanceCounter(C1);
  dummy := 1.0*microsec/1000000.0;
  C2 := C1;
  DC := trunc(dummy*Freq);
  while (C2-C1) < DC do
  begin
    Application.ProcessMessages;
    QueryPerformanceCounter(C2);
  end;
end;

procedure TDocoForm.FormCreate(Sender: TObject);
begin
  OptionsConfForm.Readconfig;
	Application.HintHidePause := 10000;
  //ParamGeneFrame.Align := alTop;
  ConfigHardFrame.Align := alClient;
  DescriptFrame.Align := alClient;
  OrgaFrame.Align := alClient;
  HelpFrame.Width := 400;
  randomize;
  ParamGeneFrame.MAJFEGBitBtn.Caption := '';
  if ParamStr(2) = 'TEST' then
	begin
		OuvrirDocument(ParamStr(1));
		AllerAExecActionExecute(Self);
		ExecFrame.ListeSTCB.Checked[strtoint(ParamStr(3))] := true;
  end;
  if ParamStr(2) = 'EXEC' then
  begin
    OuvrirDocument(ParamStr(1));
    AllerAExecActionExecute(Self);
	end;
	if (ParamStr(2) = '') and (ParamStr(1) <> '') then
	begin
		if FileExists(ParamStr(1)) then
		begin
			OuvrirDocument(ParamStr(1));
			AllerAInfoActionExecute(Self);
		end;
	end;
end;

procedure TDocoForm.TabSet1Click(Sender: TObject);
var ListeCanaux : TInfoCanaux;
    i : integer;
    NewMenuItem : TMenuItem;
    FoundRec : TSearchRec;
    S : string;
begin
  ParamGeneFrame.Visible := false;
  ConfigHardFrame.Visible := false;
	DescriptFrame.Visible := false;
  OrgaFrame.Visible := false;
  Splitter1.Visible := false;
  case Tabset1.TabIndex of
    0:begin
        Tabset1.SelectedColor := ParamGeneFrame.Color;
        ConfigHardFrame.Visible := True;
        Splitter1.Visible := true;
        ParamGeneFrame.Visible := True;
      end;
		1:begin
		
				Tabset1.SelectedColor := DescriptFrame.Color;
        DescriptFrame.Visible := True;
        ListeCanaux := DocDOCOMETRE.RendreListeInfoCanaux;//DocoForm.ConfigHardFrame.RendreListeInfoCanaux;
        DescriptFrame.ESPopupMenu.Items.Clear;
        for i := 0 to ListeCanaux.Nom.Count - 1 do
        begin
					NewMenuItem := TMenuItem.Create(self);
					NewMenuItem.Name := 'ESMenuItem' + inttostr(i);
					NewMenuItem.OnClick := DescriptFrame.ChangeESClick;
					NewMenuItem.Caption := ListeCanaux.Nom[i];
					DescriptFrame.ESPopupMenu.Items.Add(NewMenuItem);
        end;
				ListeCanaux.Free;
				NewMenuItem := TMenuItem.Create(self);
				NewMenuItem.Name := 'ESMenuItemTime';
				NewMenuItem.OnClick := DescriptFrame.ChangeESClick;
				NewMenuItem.Caption := 'temps';
				DescriptFrame.ESPopupMenu.Items.Add(NewMenuItem);
				//Ajout du canal temps

        //Creation Menu Action
        //Liste de toutes les DLL Action
        DescriptFrame.ActionPopupMenu.Items.Clear;
        if findfirst(Rep_Actions+'*.dll',faAnyFile	,FoundRec)=0 then
        begin
          repeat
            if (FoundRec.Name <> '.') and (FoundRec.Name <> '..') and (FoundRec.Attr <> faDirectory)  then
            begin
              S := FoundRec.Name;
              delete(S,pos(ExtractFileExt(FoundRec.Name),FoundRec.Name),length(ExtractFileExt(FoundRec.Name)));
              NewMenuItem := TMenuItem.Create(self);
              NewMenuItem.Name := S + 'MenuItem';
              NewMenuItem.Hint := S;
              NewMenuItem.OnClick := DescriptFrame.AffecterGeneriqueActionExecute;
              NewMenuItem.Caption := 'Affecter "' + S + '"';
              DescriptFrame.ActionPopupMenu.Items.Add(NewMenuItem);
            end;
          until findNext(FoundRec) <> 0;
          findClose(FoundRec);
        end;
        if DescriptFrame.ActionPopupMenu.Items.Count = 0
        then showmessage('Aucun fichier "Action" n''est présent !');
        //Liste de toutes les DLL Traitement
        DescriptFrame.TraitementPopupMenu.Items.Clear;
        if findfirst(Rep_Traitements+'*.dll',faAnyFile	,FoundRec)=0 then
        begin
          repeat
            if (FoundRec.Name <> '.') and (FoundRec.Name <> '..') and (FoundRec.Attr <> faDirectory )  then
            begin
              S := FoundRec.Name;
              delete(S,pos(ExtractFileExt(FoundRec.Name),FoundRec.Name),length(ExtractFileExt(FoundRec.Name)));
              NewMenuItem := TMenuItem.Create(self);
              NewMenuItem.Name := S + 'MenuItem';
              NewMenuItem.Hint := S;
              NewMenuItem.OnClick := DescriptFrame.AffecterGeneriqueActionExecute;
              NewMenuItem.Caption := 'Affecter "' + S + '"';
              DescriptFrame.TraitementPopupMenu.Items.Add(NewMenuItem);
            end;
          until findNext(FoundRec) <> 0;
          findClose(FoundRec);
        end;
        if DescriptFrame.TraitementPopupMenu.Items.Count = 0
        then showmessage('Aucun fichier "Traitement" n''est présent !');
      end;
    2:begin
        Tabset1.SelectedColor := OrgaFrame.Color;
        OrgaFrame.Visible := true;
      end;
	end;
	PageControl1Change(Self);
end;

procedure TDocoForm.RefreshIHMTimerTimer(Sender: TObject);
begin
  ConfigHardFrame.MajPresentationESAnNumCanIntGridPS;
  OrgaFrame.MajPresentationSessionsEssais;
  OptionsExecFrame.MajPresentationOptionsExec;
  EnregistrerAction.Enabled := XMLDoco.Modified;

{  if PageControl1.ActivePage = InfosTabSheet then
  begin
    if (XMLDoco.FileName <> 'Prototype.dcm') and (XMLDoco.Modified)
    then InfosWebBrowser.Navigate('file:///'+ Rep_Manip + XMLDoco.FileName);
  end;      }
end;

procedure TDocoForm.MAJListeFichiersRecents(Nom : string);
var RecentFilesList : TStringList;
    i : integer;
    S : string;
begin
  //MAJ
  RecentFilesList := TStringList.Create;
  RecentFilesList.Sorted := false;

  for i := 1 to 5 do
  begin
    case i of
     1 : S := DocoForm.RecentFileAction1.Caption;
     2 : S := DocoForm.RecentFileAction2.Caption;
     3 : S := DocoForm.RecentFileAction3.Caption;
     4 : S := DocoForm.RecentFileAction4.Caption;
     5 : S := DocoForm.RecentFileAction5.Caption;
    end;
    while(pos('&',S)>0) do delete(S,pos('&',S),1);
    RecentFilesList.Add(S);
  end;

  if RecentFilesList.IndexOf(Nom) = -1 then
  begin
    //Insertion
    RecentFilesList.Insert(0,Nom);
    //Suppresion du dernier si > 5
    if RecentFilesList.Count > 5
    then RecentFilesList.Delete(5);
    //MAJ base de Registre
    OptionsConfForm.MAJListeFichiersRecentsReg(RecentFilesList);
    OptionsConfForm.CreateListeFichiersRecents;
  end;

  RecentFilesList.Free;
end;

procedure TDocoForm.NouveauActionExecute(Sender: TObject);
var ProtoFile : TStringList;
begin
  ProtoFile := TStringList.Create;
  ProtoFile.LoadFromFile(Rep_Racine + 'Prototype.dcm');
  ProtoFile.Strings[1] := '<?xml-stylesheet type="text/xsl" href="file:///' + Rep_Racine
                        +'Aide\Resume\Docometre.xsl"?>';
  ProtoFile.SaveToFile(Rep_Racine + 'Prototype.dcm');

  ProtoFile.Clear;

  ProtoFile.LoadFromFile(Rep_Racine + 'Aide\Resume\Docometre.xsl');
  ProtoFile.Strings[4] := '<link rel="stylesheet" type="text/css" href="file:///' + Rep_Racine +
                          'Aide\Resume\Docometre.css"/>';
  ProtoFile.SaveToFile(Rep_Racine + 'Aide\Resume\Docometre.xsl');
  ProtoFile.Free;

  XMLDoco.LoadFromFile(Rep_Racine + 'Prototype.dcm');
  DocDOCOMETRE := GetRoot(XMLDoco);

  MAJMenuTabSheets('NewOpen');
  MAJIHM;
  
	PageControl1.ActivePageIndex := 1;
	PageControl1Change(self)

end;

procedure TDocoForm.OuvrirDocument(Nom : string);
begin
  //init objet TXMLDocument
  XMLDoco.LoadFromFile(Nom);
  //lien avec racine IXMLROOTType
  DocDOCOMETRE := GetRoot(XMLDoco);
  Rep_manip := ExtractFilePath(Nom);
  MAJListeFichiersRecents(XMLDoco.FileName);

  MAJMenuTabSheets('NewOpen');
  MAJIHM;

  Caption := 'DOCoMETRe - ' + Nom;

	PageControl1.ActivePageIndex := 1;
	PageControl1Change(self);
  //InfosWebBrowser.Navigate('file:///'+ Rep_Manip + XMLDoco.FileName);
end;


procedure TDocoForm.OuvrirActionExecute(Sender: TObject);
begin
  OpenDialog.InitialDir := rep_manip;
  if OpenDialog.Execute
  then OuvrirDocument(OpenDialog.FileName);
end;

procedure TDocoForm.EnregistrerActionExecute(Sender: TObject);
var SaveCursor : TCursor;
begin
  if XMLDoco.FileName <> Rep_Racine + 'Prototype.dcm' then
  begin
    SaveCursor := Screen.Cursor;
    Screen.Cursor := crHourGlass;
    XMLDoco.SaveToFile(XMLDoco.FileName);
    Screen.Cursor := SaveCursor;
    Caption := 'DOCoMETRe - ' + XMLDoco.FileName;
  end else EnregistrerSousActionExecute(Self);
  InfosWebBrowser.Navigate('file:///'+ Rep_Manip + XMLDoco.FileName);
  PageControl1Change(self);
end;

procedure TDocoForm.EnregistrerSousActionExecute(Sender: TObject);
begin
  SaveDialog.InitialDir := rep_manip;
  if SaveDialog.Execute then
  begin

    XMLDoco.SaveToFile(SaveDialog.FileName);

    //Fermer
    XMLDoco.Active := false;
    XMLDoco.FileName := '';

    //Ouvrir
    XMLDoco.LoadFromFile(SaveDialog.FileName);
    DocDOCOMETRE := GetRoot(XMLDoco);

    Rep_manip := GetCurrentDir + '\';
    Caption := 'DOCoMETRe - ' + XMLDoco.FileName;
    
    //Reinit IHM Important pour RAZ des pointeurs Bloc, Fonction etc ...
    Self.DescriptFrame.MAJIHM;
    Self.SimulFrame.MAJIHM;
    Self.OptionsExecFrame.MAJIHM;

    MAJListeFichiersRecents(XMLDoco.FileName);
  end;
end;

procedure TDocoForm.FermerActionExecute(Sender: TObject);
begin
  if XMLDoco.Modified
  then EnregistrerActionExecute(Self);
  MAJMenuTabSheets('Close');

  XMLDoco.Active := false;
  XMLDoco.FileName := '';

  ClearIHM;
  Caption := 'DOCoMETRe';
  //AllerA.Visible := false;
end;

procedure TDocoForm.QuitterActionExecute(Sender: TObject);
begin
  close;
end;

procedure TDocoForm.ClearIHM;
begin
  ParamGeneFrame.ClearIHM;
  ConfigHardFrame.ClearIHM;
  DescriptFrame.ClearIHM;
  SimulFrame.ClearIHM;
  OrgaFrame.ClearIHM;
  OptionsExecFrame.ClearIHM;

	if DocoForm.ActionManager.ActionBars[0].Items[1].Caption = 'O&utils' then
  begin
    ActionManager.ActionBars[0].Items[2].Visible := false;
    DocoForm.ActionManager.ActionBars[0].Items[1].Free;
  end else ActionManager.ActionBars[0].Items[1].Visible := false;

end;

procedure TDocoForm.MAJIHM;
begin
  ParamGeneFrame.MAJIHM;
  ConfigHardFrame.MajIHM;
  DescriptFrame.MAJIHM;
  SimulFrame.MAJIHM;
  OrgaFrame.MAJIHM;
  OptionsExecFrame.MAJIHM;
  InspectFrame.MAJIHM;
  PageControl1Change(self);

  ActionManager.ActionBars[0].Items[1].Visible := true;
end;

procedure TDocoForm.MAJMenuTabSheets(Etat:string);
begin
  if Etat = 'NewOpen' then
  begin
    NouveauAction.Enabled := false;
    OuvrirAction.Enabled := false;
    EnregistrerAction.Enabled := true;
    EnregistrerSousAction.Enabled := true;
    PrintAction.Enabled := true;
    FermerAction.Enabled := true;
    PageControl1.Visible := true;
    ViewBeforePrintAction.Enabled := true;
    PageControl1.ActivePageIndex := 0;
  end;
  if Etat = 'Close' then
  begin
    NouveauAction.Enabled := true;
    OuvrirAction.Enabled := true;
    EnregistrerAction.Enabled := false;
    EnregistrerSousAction.Enabled := false;
    PrintAction.Enabled := false;
    FermerAction.Enabled := false;
    PageControl1.Visible := false;
    ViewBeforePrintAction.Enabled := false;    
  end;
end;

procedure TDocoForm.FormMouseWheel(Sender: TObject; Shift: TShiftState;
  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);

  function signe(X:integer):integer;
  begin
    if X>0
    then result := 1
    else result := -1;
  end;

begin
  if (PageControl1.ActivePageIndex = 1) and (tabSet1.TabIndex = 1)
  then DescriptFrame.FunctionScrollBox.VertScrollBar.Position
      := DescriptFrame.FunctionScrollBox.VertScrollBar.Position - 10*signe(WheelDelta);
end;

procedure TDocoForm.TabSet1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  DescriptFrame.FunctionScrollBox.VertScrollBar.Position
      := DescriptFrame.FunctionScrollBox.VertScrollBar.Position + 1;
end;

procedure TDocoForm.PageControl1Change(Sender: TObject);
begin
  if DocoForm.ActionManager.ActionBars[0].Items[1].Caption = 'O&utils'
	then DocoForm.ActionManager.ActionBars[0].Items[1].Free;
	if PageControl1.ActivePage = ParamGeneConfHardDescriptTabSheet then
	begin
		case tabSet1.TabIndex of
		0:begin//confighard
				configHardFrame.MAJMAIMENU;
			end;
		1:begin//descript
				descriptFrame.MAJMAINMENU;
			end;
		2:begin//orga
				orgaFrame.MAJMAINMENU;
			end;
		end;
	end;
	if PageControl1.ActivePage = SimulTabSheet
  then SimulFrame.MAJIHM;
  if PageControl1.ActivePage = OptionsExecTabSheet
  then OptionsExecFrame.MAJIHM;
  if PageControl1.ActivePage = ExecTabSheet
	then ExecFrame.MAJIHM;
	if PageControl1.ActivePage = InspectTabSheet
	then InspectFrame.MAJIHM;
end;

procedure TDocoForm.OptConfActionExecute(Sender: TObject);
begin
	OptionsConfForm.Showmodal;
end;

procedure TDocoForm.AllerAInfoActionExecute(Sender: TObject);
begin
  PageControl1.ActivePageIndex := 0;
	PageControl1Change(self);
end;

procedure TDocoForm.AllerAParamGeneActionExecute(Sender: TObject);
begin
	PageControl1.ActivePageIndex := 1;
	TabSet1.TabIndex := 0;
	PageControl1Change(self);
end;

procedure TDocoForm.AllerADescripActionExecute(Sender: TObject);
begin
  PageControl1.ActivePageIndex := 1;
	TabSet1.TabIndex := 1;
	PageControl1Change(self);
end;

procedure TDocoForm.AllerAOrgaActionExecute(Sender: TObject);
begin
  PageControl1.ActivePageIndex := 1;
	TabSet1.TabIndex := 2;
	PageControl1Change(self);
end;

procedure TDocoForm.AllerASimActionExecute(Sender: TObject);
begin
	PageControl1.ActivePageIndex := 2;
	PageControl1Change(Self);
end;

procedure TDocoForm.AllerAOptionsExecActionExecute(Sender: TObject);
begin
	PageControl1.ActivePageIndex := 3;
	PageControl1Change(Self);
end;

procedure TDocoForm.AllerAExecActionExecute(Sender: TObject);
begin
	PageControl1.ActivePageIndex := 4;
	PageControl1Change(Self);
end;

procedure TDocoForm.AllerAInspecActionExecute(Sender: TObject);
begin
	PageControl1.ActivePageIndex := 5;
	PageControl1Change(Self);
end;

procedure TDocoForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
	SimulFrame.StopSimulActionExecute(self);
  SimulFrame.ClearGenerators;

  if XMLDoco.Modified then
  begin
   if messageDLG('Souhaitez-vous enregistrer avant de quitter ?',mtInformation,[mbYes,mbNo],0) = mrYes
   then EnregistrerActionExecute(Self);
  end;
	ClearIHM;
  saveMainFormPositions((DocoForm.WindowState = wsMaximized),DocoForm.left,DocoForm.Top, DocoForm.Width, DocoForm.Height);
	InitialLocalMachineNavigate;
end;

procedure TDocoForm.SimulFrameRunSimulActionExecute(Sender: TObject);
begin
  SimulFrame.RunSimulActionExecute(Sender);
end;

procedure TDocoForm.ShowHelp(index : integer);
begin
  if HelpForm.Visible
  then HelpForm.HelpFrame.UpdateHelp(index)
  else begin
    HelpFrame.UpdateHelp(index);
    Splitter2.Visible := true;
    HelpFrame.Left := 10000;
    HelpFrame.Visible := true;
  end;
end;

procedure TDocoForm.ParamGeneFrameImage1Click(Sender: TObject);
begin
  ParamGeneFrame.HelpImageClick(Sender);
end;

procedure TDocoForm.PrintActionExecute(Sender: TObject);
begin
  InfosWebBrowser.ExecWB(OLECMDID_PRINT,OLECMDEXECOPT_DODEFAULT);
end;

procedure TDocoForm.RecentFileActionExecute(Sender: TObject);
var S : string;
begin
  if Sender.ClassName = 'TAction'
  then S := (Sender as TAction).Caption 
  else S := (Sender as TMenuItem).Caption ;
  while(pos('&',S)>0) do delete(S,pos('&',S),1);
  if FileExists(S)
  then OuvrirDocument(S)
  else showmessage('Le fichier "' + S +'" n''existe pas !');
end;

procedure TDocoForm.ViewBeforePrintActionExecute(Sender: TObject);
begin
  InfosWebBrowser.ExecWB(OLECMDID_PRINTPREVIEW ,OLECMDEXECOPT_DODEFAULT);
end;

procedure TDocoForm.InfosTabSheetShow(Sender: TObject);
begin
  //InfosWebBrowser.Navigate('file:///'+ Rep_Manip + XMLDoco.FileName);
  InfosWebBrowser.Navigate(XMLDoco.FileName);
end;

procedure TDocoForm.AideActionExecute(Sender: TObject);
var URL : string;
begin
  URL := 'file:///'+ Rep_Racine + 'Aide/Docs/index.html';
  if HelpForm.Visible
  then HelpForm.HelpFrame.HelpWebBrowser.Navigate(URL)
  else DocoForm.ShowHelp(0);
end;

procedure TDocoForm.AProposActionExecute(Sender: TObject);
begin
  AProposDeForm.Show;
end;

procedure TDocoForm.ParamGeneFrameDescriptionMemoChange(Sender: TObject);
begin
  ParamGeneFrame.ParamGeneChange(Sender);
end;

procedure TDocoForm.Splitter2Moved(Sender: TObject);
begin
  HelpFrame.Repaint;
end;

function TDocoForm.checkChannelName(var channelName: string; var Key : char) : boolean;
begin
  Result := true;
  if not (key in ['0'..'9','A'..'Z','a'..'z','_'])
  then if not (key in [Char(VK_BACK),Char(VK_DELETE)]) then key := #0;
  if length(ChannelName) > 0 then
  begin
    if channelName[1] in ['0'..'9'] then delete(channelName,1,1)
  end else Result := false;// else ChannelName := 'channelName';
  if length(channelName) > 32 then delete(channelName,32,length(channelName));
end;


procedure TDocoForm.FormShow(Sender: TObject);
begin
  
  DocoForm.Width := formWidth;
  DocoForm.Height := formHeight;
  DocoForm.Top := topPosition;
  DocoForm.Left := leftPosition;
  if(Maximized)
  then  DocoForm.WindowState := wsMaximized
  else DocoForm.WindowState := wsNormal;

end;

end.
