% ----------------------------------------------------------------------------
% function HfssRectangle(fid, HName, HAxis, HStart, HWidth, HHeight, HUnits)
% 
% Popis funkce :
% -------------
% Vytvoreni m-file skriptu potrebneho k vytvoreni ctverce v HFSS.
%
% Parametery :
% ------------
% fid     - file identifier of the HFSS script file.
% HName    - jmeno ctverce (v HFSS).
% HAxis    - osa natoceni ctverce.
% HStart   - pozice startu ctverce(spodni roh ctverce). Specifikovane jako
%           [sx, sy, sz].
% HWidth   - (scalar) sirka ctverce. Jestli ze je osa 'X', pak
%           to reprezentuje velikost osy Y ve ctverci.
% HHeight  - (scalar) vyska ctverce. Jestli ze je osa 'X', pak
%           to reprezentuje velikost osy Z ve ctverci. 
% HUnits   - specifikovano jako 'in', 'meter', 'mm', ... nebo jine
% definovane jednotky v HFSS.
%
% Priklad pouziti funkce :
% ---------
% fid = fopen('antenna.m', 'wt');
% ... 
% % v tomto pripade, velikost osy Yje 10in a osy Z je 20in.
% HfssRectangle(fid, 'Rect1', 'X', [0,0,0], 10, 20, 'in');
%
% ----------------------------------------------------------------------------

function HfssRectangle(fid, HName, HAxis, HStart, HWidth, HHeight, HUnits)
global Editor
HTransparency = 0.5;

%zapis do souboru temp
fprintf(fid,'%% Vytvoreni ctverce\n');
fprintf(fid,'invoke(Editor,''CreateRectangle'',...\n');
fprintf(fid,'{''NAME:RectangleParameters'',...\n');
fprintf(fid,'''IsCovered:='',true,...\n');
fprintf(fid,['''XStart:='',''',num2str(HStart(1)),HUnits,''',...\n']);
fprintf(fid,['''YStart:='',''',[num2str(HStart(2)),HUnits],''',...\n']);
fprintf(fid,['''ZStart:='',''',[num2str(HStart(3)),HUnits],''',...\n']);
fprintf(fid,['''Width:='',''',[num2str(HWidth),HUnits],''',...\n']);
fprintf(fid,['''Height:='',''',[num2str(HHeight),HUnits],''',...\n']);
fprintf(fid,['''WhichAxis:='',''',upper(HAxis),'''},...\n']);
fprintf(fid,'{''NAME:Attributes'',...\n');
fprintf(fid,['''Name:='',''',HName,''',...\n']);
fprintf(fid,'''Flags:='','''',...\n');
fprintf(fid,'''Color:='',''(132 132 193)'',...\n');
fprintf(fid,['''Transparency:='',',num2str(HTransparency),',...\n']);
fprintf(fid,'''PartCoordinateSystem:='',''Global'',...\n');
fprintf(fid,'''MaterialName:='',''vacuum'',...\n');
fprintf(fid,'''SolveInside:='',true})\n\n');

%Prime vykonani v progrqamu Hfss
invoke(Editor,'CreateRectangle',...
    {'NAME:RectangleParameters',...
    'IsCovered:=',true,...
    'XStart:=',[num2str(HStart(1)),HUnits],...
    'YStart:=',[num2str(HStart(2)),HUnits],...
    'ZStart:=',[num2str(HStart(3)),HUnits],...
    'Width:=',[num2str(HWidth),HUnits],...
    'Height:=',[num2str(HHeight),HUnits],...
    'WhichAxis:=',upper(HAxis)},...
    {'NAME:Attributes',...
    'Name:=',HName,...
    'Flags:=','',...
    'Color:=','(132 132 193)',...
    'Transparency:=',HTransparency,...
    'PartCoordinateSystem:=','Global',...
    'MaterialName:=','vacuum',...
    'SolveInside:=',true})

end