unit U_ChooseComponTypes;

interface

uses
  Windows, U_LNG, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxControls, cxContainer, cxEdit, cxLabel, cxLookAndFeelPainters,
  StdCtrls, cxButtons, ComCtrls, Contnrs, cxCheckBox, siComp, siLngLnk,
  RzButton, RzRadChk, cxGraphics, cxLookAndFeels, Menus;

type
  TF_ChooseComponTypes = class(TForm)
    cxLabel1: TcxLabel;
    bOK: TcxButton;
    lvComponTypes: TListView;
    bCancel: TcxButton;
    lng_Forms: TsiLangLinked;
    cbDivideGroupsByJoinedNetTypes: TRzCheckBox;
    cbShowGroupContents: TRzCheckBox;
  private
    { Private declarations }
  public
    { Public declarations }
    function Execute: Boolean;
  end;

var
  F_ChooseComponTypes: TF_ChooseComponTypes;

implementation
uses U_Common, U_BaseCommon, U_SCSComponent, U_ESCadClasess, U_ProjectPlan, U_Constants;

{$R *.dfm}

function TF_ChooseComponTypes.Execute: Boolean;
var
  CurComponType: TNBComponentType;
  ComponTypes: TObjectList;
  i: Integer;
  Item: TListItem;
  ListParams: TListParams;
  CheckedCTSN: TStringList; //CTSN - compon type sys name
begin
  try
    Result := False;

    CheckedCTSN := CreateStringListSorted;
    CheckedCTSN.AddStrings(GCompTypeSysNamePanels);
    CheckedCTSN.AddStrings(GCompTypeSysNameModules);
    CheckedCTSN.AddStrings(GCompTypeSysNameComplexCompons);
    CheckedCTSN.Add(ctsnAnalyser);
    CheckedCTSN.Add(ctsnInstallBox);
    CheckedCTSN.Add(ctsnCupboard);
    CheckedCTSN.Add(ctsnTerminalBox);
    CheckedCTSN.Add(ctsnOrganizer);
    CheckedCTSN.Add(ctsnWorkPlace);
    CheckedCTSN.Add(ctsnBox);

    lvComponTypes.Items.Clear;
    ComponTypes := GetCurrProectPointComponTypes;
    for i := 0 to ComponTypes.Count - 1 do
    begin
      CurComponType := TNBComponentType(ComponTypes[i]);
      Item := lvComponTypes.Items.Add;
      if CurComponType.ComponentType.SysName = ctsnCableChannelElement then
        Item.Caption := CurComponType.ComponentType.Name
      else
        Item.Caption := CurComponType.ComponentType.NamePlural;
      Item.Checked := CheckedCTSN.IndexOf(CurComponType.ComponentType.SysName) <> -1; //30.03.2013 True;
      Item.Data := CurComponType;
    end;

    if ShowModal = mrOK then
    begin
      Result := True;
      ListParams := GetListParamsForNewList;
      ListParams.Caption := cChooseComponType_Mes1;
      ListParams.Name := ListParams.Caption;
      ListParams.MarkID := 0;
      ListParams.Settings.ListType := lt_ProjectPlan;
      MakeEditList(meMake, ListParams, False);

      for i := 0 to lvcompontypes.items.Count - 1 do
      begin
        item := lvcompontypes.items[i];
        CurComponType := TNBComponentType(item.Data);
        CurComponType.IsSelected := item.Checked;
      end;
      DrawProjectPlan(GCadForm, ComponTypes, cbDivideGroupsByJoinedNetTypes.Checked, cbShowGroupContents.Checked);
      DisableOptionsForDesignList;
    end;
    FreeAndNil(ComponTypes);

    FreeAndNil(CheckedCTSN);
  except
    on E: Exception do AddExceptionToLogEx('TF_ChooseComponTypes.Execute', E.Message);
  end;
end;

end.
