function tbTab = getTabDialogSchema(this, schemaName, hdlcc) %#ok
%GETTABDIALOGSCHEMA   Get the tabDialogSchema.
%   Author(s): P. Costa, J.Sun

%   Copyright 2005-2023 The MathWorks, Inc.

cs = hdlcc.getSourceObject.getConfigSet;
enableWidget = strcmpi(cs.ReadOnly, 'off');

tagpf = [getWidgetTagPrefix(this),'TestBenchPanel_'];

src = hdlcc.getCLI;
hSrc = hdlcc.getSourceObject;

tbgeneration = strcmpi(src.GenerateHDLTestBench, 'on');
if ~tbgeneration && this.edalinksinstalled
    tbgeneration = this.CosimModel || this.svdpi_tb;
end

if ~isempty(strfind(src.HDLSubsystem, '/'))
% Button disabled during testbench generation    
   canGenerateTB =  ~isempty(hdlcc.getModel) && ~hSrc.isObjectLocked;
else
    canGenerateTB = false;
end

currRow = 1;
currCol = 1;
chkGenerateTB.Type = 'checkbox';
chkGenerateTB.Name = DAStudio.message('HDLShared:hdldialog:generateTB');
chkGenerateTB.Tag = [tagpf,'GenerateHDLTestBench'];
chkGenerateTB.Source = src;
chkGenerateTB.ObjectProperty = 'GenerateHDLTestBench';
chkGenerateTB.RowSpan = [currRow currRow];
chkGenerateTB.ColSpan = [2 3];
chkGenerateTB.Mode = true;
chkGenerateTB.DialogRefresh = true;

currRow = currRow+1;
[CosimWidget, currRow] = getCosimulationWidget(this, src, currRow,2, tagpf);
currRow = currRow+1;

pageName = [message('HDLShared:hdldialog:hdlccHDLCodername').getString '/' ...
            message('HDLShared:hdldialog:hdltbComponentName').getString];

SimulationToolType.Type = 'combobox';
SimulationToolType.Name = DAStudio.message('HDLShared:hdldialog:hdltbSimulationTool');
%Associated to local property, need to assign to CLI at apply time.
SimulationToolType.ObjectProperty = 'SimulationTool';
SimulationToolType.Tag = [tagpf 'TestbenchSimTool'];
SimulationToolType.RowSpan = [currRow currRow];
SimulationToolType.ColSpan = [currCol+1 currCol+1];
SimulationToolType.Source = src;
SimulationToolType.Mode = true;
SimulationToolType.Enabled = tbgeneration;
SimulationToolType.DialogRefresh   = true;
SimulationToolType.UserData.Page = pageName;

chkCodeCoverage.Type = 'checkbox';
chkCodeCoverage.Name = DAStudio.message('HDLShared:hdldialog:hdltbHDLCodeCoverage');
chkCodeCoverage.Tag = [tagpf,'GenerateCodeCoverage'];
chkCodeCoverage.Source = src;
chkCodeCoverage.ObjectProperty = 'HDLCodeCoverage';
chkCodeCoverage.RowSpan = [currRow currRow];
chkCodeCoverage.ColSpan = [4 4];
chkCodeCoverage.Mode = true;
chkCodeCoverage.Enabled = tbgeneration && ~strcmpi(src.SimulationTool,'Custom');
chkCodeCoverage.Visible=this.edalinksinstalled;
chkCodeCoverage.DialogRefresh = true;

gpTop.Type = 'group';
gpTop.Name = DAStudio.message('HDLShared:hdldialog:hdltbGenerationOutput');
gpTop.Items = [{SimulationToolType},{chkGenerateTB},{chkCodeCoverage},CosimWidget];
gpTop.LayoutGrid = [currRow 4];
gpTop.RowStretch = [zeros(1, currRow-1) 1];
gpTop.ColStretch = [0 0 0 1];
gpTop.RowSpan = [1 1];
gpTop.ColSpan = [1 4];
gpTop.Enabled = canGenerateTB && enableWidget;

currRow = 1;
tbName_lbl.Name    = DAStudio.message('HDLShared:hdldialog:hdltbTestBenchPostfix');
tbName_lbl.Type    = 'text';
tbName_lbl.RowSpan = [currRow currRow];
tbName_lbl.ColSpan = [1 1];

tbName.Type           = 'edit';
tbName.ObjectProperty = 'TestBenchPostfix';
tbName.Source         = src;
tbName.Tag            = [tagpf 'TestBenchPostfix'];
tbName_lbl.Buddy      = tbName.Tag;
tbName.RowSpan        = [currRow currRow];
tbName.ColSpan        = [2 2];
tbName.Mode = true;
tbName.Enabled = enableWidget;

txtsubsys.Type = 'text'; 
txtsubsys.Name = '       ';
txtsubsys.RowSpan = [currRow currRow];
txtsubsys.ColSpan = [3 4];

currRow = currRow+1;
% Get the common widgets for all test bench dialogs
[tbWidgets, currRow] = getSharedWidgets(this, src, enableWidget, currRow, 1, tagpf);

currRow = currRow+1;
tbUseFileIOInTestBench.Name         = DAStudio.message('HDLShared:hdldialog:hdltbUseFileIOInTestBench');
tbUseFileIOInTestBench.Type         = 'checkbox';
tbUseFileIOInTestBench.ObjectProperty = 'UseFileIOInTestBench';
tbUseFileIOInTestBench.Source       = src;
tbUseFileIOInTestBench.Tag          = [tagpf 'UseFileIOInTestBench'];
tbUseFileIOInTestBench.RowSpan      = [currRow currRow];
tbUseFileIOInTestBench.ColSpan      = [1 2];
tbUseFileIOInTestBench.Mode           = true;
tbUseFileIOInTestBench.Enabled = enableWidget;


currRow = currRow+1;
tbIgnoreDatacheck_lbl.Name    = DAStudio.message('HDLShared:hdldialog:hdltbIgnoreDataChecking');
tbIgnoreDatacheck_lbl.Type    = 'text';
tbIgnoreDatacheck_lbl.RowSpan = [currRow currRow];
tbIgnoreDatacheck_lbl.ColSpan = [1 1];

tbIgnoreDatacheck.Type    = 'edit';
tbIgnoreDatacheck.ObjectProperty = 'IgnoreDataChecking';
tbIgnoreDatacheck.Source  = src;
tbIgnoreDatacheck.Tag     = [tagpf 'ignoreDataChecking'];
tbIgnoreDatacheck_lbl.Buddy = tbIgnoreDatacheck.Tag;
tbIgnoreDatacheck.RowSpan = [currRow currRow];
tbIgnoreDatacheck.ColSpan = [2 2];
tbIgnoreDatacheck.Mode    = true;
tbIgnoreDatacheck.DialogRefresh   = true;
tbIgnoreDatacheck.Enabled = enableWidget;

currRow = currRow+1;

tbFloatTolerance_lbl.Type = 'text';
tbFloatTolerance_lbl.Name = DAStudio.message('HDLShared:hdldialog:hdlglblsettingsTBFloatTolerance');
tbFloatTolerance_lbl.RowSpan = [currRow currRow];
tbFloatTolerance_lbl.ColSpan = [1 1];

tbFloatTolerance.Type = 'combobox';
tbFloatTolerance.Tag = [tagpf 'FPToleranceScheme'];
tbFloatTolerance_lbl.Buddy = tbFloatTolerance.Tag;
tbFloatTolerance.RowSpan = [currRow currRow];
tbFloatTolerance.ColSpan = [2 2];
tbFloatTolerance.DialogRefresh = true;
tbFloatTolerance.Mode = true;
tbFloatTolerance.Entries = {'relative error', 'ulp error'};
tbFloatTolerance.Enabled = enableWidget;
tbFloatTolerance.MatlabMethod = 'hdlcoderui.hdltb.floatDialogCallback';
tbFloatTolerance.MatlabArgs = {'fptolerance', src,'%dialog','%tag'};
if strcmpi(src.FPToleranceStrategy, 'Ulp')
   tbFloatTolerance.Value = 1;
else
   tbFloatTolerance.Value = 0;
end

currRow = currRow+1;
tbFloatTolVal_lbl.Name    = ['        ' DAStudio.message('HDLShared:hdldialog:hdlglblsettingsTBFloatToleranceValue')];
tbFloatTolVal_lbl.Type    = 'text';
tbFloatTolVal_lbl.RowSpan = [currRow currRow];
tbFloatTolVal_lbl.ColSpan = [1 1];

tbFloatTolVal.Type           = 'edit';
tbFloatTolVal.Tag            = [tagpf 'FPToleranceValue'];
tbFloatTolVal_lbl.Buddy      = tbFloatTolVal.Tag;
tbFloatTolVal.RowSpan        = [currRow currRow];
tbFloatTolVal.ColSpan        = [2 2];
tbFloatTolVal.Mode = true;
tbFloatTolVal.Enabled = enableWidget;
tbFloatTolVal.MatlabMethod = 'hdlcoderui.hdltb.floatDialogCallback';
tbFloatTolVal.MatlabArgs = {'fptolerance', src,'%dialog','%tag'};
tbFloatTolVal.DialogRefresh = true;
if strcmpi(src.FPToleranceStrategy, 'Ulp')
   tbFloatTolVal.Value = cast(src.FPToleranceValue, 'int32');
else
   tbFloatTolVal.Value = src.FPToleranceValue;
end

currRow = currRow+1;
tbSimulationLibPath_lbl.Name    = DAStudio.message('HDLShared:hdldialog:hdltbSimulationLibPath');
tbSimulationLibPath_lbl.Type    = 'text';
tbSimulationLibPath_lbl.RowSpan = [currRow currRow];
tbSimulationLibPath_lbl.ColSpan = [1 1];

tbSimulationLibPath.Type    = 'edit';
tbSimulationLibPath.ObjectProperty = 'SimulationLibPath';
tbSimulationLibPath.Source  = src;
tbSimulationLibPath.Tag     = [tagpf 'SimulationLibPath'];
tbSimulationLibPath_lbl.Buddy = tbSimulationLibPath.Tag;
tbSimulationLibPath.RowSpan = [currRow currRow];
tbSimulationLibPath.ColSpan = [2 4];
tbSimulationLibPath.Mode    = true;
tbSimulationLibPath.DialogRefresh   = true;
tbSimulationLibPath.Enabled = enableWidget;

% Browse button for SimulationLibPath
browse_pb.Type = 'pushbutton';
browse_pb.Name = DAStudio.message('HDLShared:hdldialog:hdlccBrowse');
browse_pb.Tag = [tagpf 'Browse'];
browse_pb.Source = this;
browse_pb.ObjectMethod = 'dialogCallback';
browse_pb.MethodArgs = {'%dialog', browse_pb.Tag, src, 'enableApply'};
browse_pb.ArgDataTypes = {'handle', 'string', 'handle', 'string'};
browse_pb.Mode = true;
browse_pb.DialogRefresh = true;
browse_pb.RowSpan = [currRow currRow];
browse_pb.ColSpan = [5 5];
browse_pb.Enabled = enableWidget;

tbsettings.Type = 'group';
tbsettings.Name  = DAStudio.message('HDLShared:fdhdldialog:additionalSettings');
tbsettings.Items = [tbWidgets, {tbName_lbl, tbName, txtsubsys, tbUseFileIOInTestBench, tbIgnoreDatacheck_lbl, tbIgnoreDatacheck, tbFloatTolerance_lbl, tbFloatTolerance, tbFloatTolVal_lbl, tbFloatTolVal,tbSimulationLibPath_lbl, tbSimulationLibPath, browse_pb}];

tbsettings.LayoutGrid = [currRow 5];
tbsettings.RowStretch = [zeros(1, currRow-1) 1];
tbsettings.ColStretch = [0 0 0 1 0];
tbsettings.RowSpan = [2 2];
tbsettings.ColSpan = [1 4];

tbsettings.Enabled = tbgeneration && canGenerateTB && enableWidget;

% Generate TB button
% Get the pixel unit
pf = hdlcoderui.getpixunit;

buttonWidth = 168*pf;
buttonHeight = 24*pf;

currRow = 3;
gbtn.Name = DAStudio.message('HDLShared:hdldialog:hdltbGenerateTB');
gbtn.Type = 'pushbutton';
gbtn.Tag = [tagpf 'Generate'];
gbtn.Source = this;
gbtn.ObjectMethod = 'testbenchCallback';
gbtn.MethodArgs = {'%dialog', gbtn.Tag, '', hdlcc};
gbtn.ArgDataTypes = {'handle', 'string', 'string', 'handle'};
gbtn.RowSpan = [currRow currRow];
gbtn.ColSpan = [3 4];
gbtn.Enabled = tbgeneration && canGenerateTB && enableWidget;
gbtn.Alignment = 7; %central right alignment
gbtn.MinimumSize = [buttonWidth buttonHeight];

currRow = currRow+1;

tbTab.Items = {gpTop, tbsettings, gbtn};   
tbTab.LayoutGrid = [currRow 4];
tbTab.RowStretch = [zeros(1, currRow-1) 1];
tbTab.ColStretch = [0 0 0 1];

tbTab.Name       = DAStudio.message('HDLShared:hdldialog:hdltbComponentName');
% %% CSHTAG
tbTab.Tag = [getWidgetTagPrefix(this),'TestBenchPanel'];

% [EOF]

% LocalWords:  hdltb fdhdldialog hdltb fdhdldialog FP ulp fptolerance
