unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  ExtCtrls, Buttons, PairSplitter, ShlepsUtils, ClipBrd, blcksock, synsock, synautil, synamisc;

type

  { TForm1 }

  TForm1 = class(TForm)
    Memo1: TMemo;
    Memo2: TMemo;
    OpenDialog1: TOpenDialog;
    Panel1: TPanel;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SaveToFileSpeedButton: TSpeedButton;
    SaveToClipbrdSpeedButton: TSpeedButton;
    SaveToAppSpeedButton: TSpeedButton;
    Splitter1: TSplitter;
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    Procedure SaveToAppSpeedButtonClick(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.SpeedButton2Click(Sender: TObject);
Var I:Longint;
    Lcmd,Command,Cmd,B,PB:String;
    CursorName,Addr1,Addr2,RelIntName,Aspect1,Aspect2:String;
begin
  Memo2.Lines.Clear;
  For I:=0 To Memo1.Lines.Count-1 Do Begin
    LCmd:=Memo1.Lines[I];
    Command:=Copy(LCmd,Pos('::',LCmd)+2,Length(LCmd)-Pos('::',LCmd)-1);
    Cmd:=GetNextToken(Command,PB,':');
    B:=PB;
    If LowerCase(Cmd)='sdb_crcreateconcept' Then Begin
//    ('self::sDB_CRCreateConcept:<Cursorame>:<InternalName>');
      CursorName:=GetNextToken(B,PB,':');
      B:=PB;
//      Result:=sDB_CRCreateConcept(CursorName,B);
      Memo2.Lines.Add('self::CAD_CreateObject:Name='+B+' A=1440 W=4 H=1 ');
    end;

    If LowerCase(Cmd)='sdb_cacreatebinrel' Then Begin
  //    ('self::sDB_CACreateBinRel:<CursorName>:<Addr1>:<Addr2>:<RelIntName>:<Aspect1>:<Aspect2>');
      CursorName:=GetNextToken(B,PB,':');
      B:=PB;
      Addr1:=GetNextToken(B,PB,':');
      If Pos('/',Addr1)>0 Then Delete(Addr1,1,Pos('/',Addr1));
      If Addr1[1]='@' Then Delete(Addr1,1,1);
      B:=PB;
      Addr2:=GetNextToken(B,PB,':');
      If Pos('/',Addr2)>0 Then Delete(Addr2,1,Pos('/',Addr2));
      If Addr2[1]='@' Then Delete(Addr2,1,1);
      B:=PB;
      RelIntName:=GetNextToken(B,PB,':');
      B:=PB;
      Aspect1:=GetNextToken(B,PB,':');
      B:=PB;
      Aspect2:=GetNextToken(B,PB,':');
      Memo2.Lines.Add('self::CAD_CreateConnection:StartObj='+Addr1+' EndObj='+Addr2+' Color=clGreen AutoText="'''+Aspect1+''','''+RelIntName+''','''+Aspect2+'''"');
//      Result:=sDB_CACreateBinRel(CursorName,Addr1,Addr2,RelIntName,Aspect1,Aspect2);
    end;

  end;

end;

Procedure TForm1.SaveToAppSpeedButtonClick(Sender: TObject);
Var I:Longint;
    TCPSocket:TTCPBlockSocket;
Begin
  Case (Sender As TSpeedButton).Tag Of
  1: Begin Memo2.Lines.SaveToFile('test');
     End;
  2: Begin
       ClipBoard.AsText:=Memo2.Lines.Text;
     End;
  3: Begin
       TCPSocket:=TTCPBlockSocket.Create;
       TCPSocket.Connect('127.0.0.1','33333');
       For I:=0 To Memo2.Lines.Count-1 Do
         TCPSocket.SendString(Memo2.Lines[I]+#10);
       TCPSocket.SendString('disconnect');
       TCPSocket.CloseSocket;
       TCPSocket.Free;
     End;
  End;
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
  If OpenDialog1.Execute Then
    Memo1.Lines.LoadFromFile(OpenDialog1.FileName);
end;

end.

