unit PlugMain;

interface

uses Windows, CSUnit, ECUnit, Forms, SysUtils, Dialogs, PlugCommon;

function PlugInsEnumerate(EnumProc:TEnumPlugInsProc):integer;stdcall;
function Initialize:integer;
//function Finalize:integer;

exports
  PlugInsEnumerate;

implementation

type
  PSimplexCreate = ^TSimplexCreate;
  TSimplexCreate = object(IPlugIn)
    function       MenuName:PChar;virtual;stdcall;
    function       CanDo:LongBool;virtual;stdcall;
    function       PluginMain:PChar;virtual;stdcall;
    constructor    Create;
  end;

type
  PSimplexExtremum = ^TSimplexExtremum;
  TSimplexExtremum = object(IPlugIn)
    function       MenuName:PChar;virtual;stdcall;
    function       CanDo:LongBool;virtual;stdcall;
    function       PluginMain:PChar;virtual;stdcall;
    constructor    Create;
  end;

constructor TSimplexCreate.Create;
begin
end;

function TSimplexCreate.MenuName;
begin
  Result:=PChar('Сетка плоского симплекса');
end;

function TSimplexCreate.CanDo;
var
  K : integer;
begin
  Result:=GetMainServer.CanDo(acExtremum);
  if(Result) then
  begin
    GetMainServer.GetKNR(@K,nil,nil);
    Result:=K=3;
  end;
end;

function TSimplexCreate.PluginMain;
var
  Frm : TForm;
begin
  Frm:=GetMainServer.GetMainForm;
  CSDialog.ParentWindow:=Frm.Handle;
  CSDialog.ShowModal;
  Result:=pchar('Done');
end;

constructor TSimplexExtremum.Create;
begin
end;

function TSimplexExtremum.MenuName;
begin
  Result:=PChar('Экстремум плоского симплекса');
end;

function TSimplexExtremum.CanDo;
var
  K : integer;
begin
  Assert(GetMainServer<>nil);
  Result:=GetMainServer.CanDo(acExtremum);
  if(Result) then
  begin
    GetMainServer.GetKNR(@K,nil,nil);
    Result:=K=3;
  end;
end;

function TSimplexExtremum.PluginMain;
var
  Frm : TForm;
  SEDialog: TSEDialog;
begin
  Assert(GetMainServer<>nil);
  Frm:=GetMainServer.GetMainForm;
  SEDialog:=TSEDialog.CreateParented(Frm.Handle);
  SEDialog.ShowModal;
  SEDialog.Free;
  Result:=pchar('Done');
end;

var
  SimplexCreate : TSimplexCreate;
  SimplexExtremum : TSimplexExtremum;

function Initialize;
begin
  SimplexCreate.Create;
  SimplexExtremum.Create;
  Result:=0;
end;

function PlugInsEnumerate(EnumProc:TEnumPlugInsProc):integer;stdcall;
begin
  Result:=0;
  if(EnumProc(@SimplexCreate)=PLGENUM_CANCEL) then exit;
  Result:=1;
  if(EnumProc(@SimplexExtremum)=PLGENUM_CANCEL) then exit;
  Result:=2;
end;

begin
  Initialize;
end.

