function dummy = initialize(Editor,Anchors)
%INITIALIZE  Initializes Root Locus Editor.

%   Author(s): P. Gahinet
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.10 $ $Date: 2000/08/02 16:06:32 $

% REVISIT
dummy = [];

% Render editor
Editor.HG = LocalRender(Editor,Anchors);

% Set (and draw) labels
% REVISIT: Simplify when h.Title.String = xxx works
Title = Editor.Title;
Title.String = 'Root Locus';
Title.Visible = 'on';
Editor.Title = Title;
Xlabel = Editor.Xlabel;
Xlabel.String = 'Real Axis';
Xlabel.Visible = 'off';
Editor.Xlabel = Xlabel;
Ylabel = Editor.Ylabel;
Ylabel.String = 'Imag Axis';
Ylabel.Visible = 'off';
Editor.Ylabel = Ylabel;


%---------------- Local Functions ------------------------------

%%%%%%%%%%%%%%%%%%%
%%% LocalRender %%%
%%%%%%%%%%%%%%%%%%%
function HG = LocalRender(Editor,Anchors)

SISOfig = Anchors.Figure; % host figure

% Plot axes
PlotAxes = axes('Parent',SISOfig, ...
    'Units','norm', ...
    'DrawMode','fast', ...
    'Visible','off', ...
    'XColor',Editor.AxesForegroundColor,...
    'Xlim',[-1,1], ...
    'YColor',Editor.AxesForegroundColor,...
    'Ylim',[-1 1],...
    'Box','on',...
    'HelpTopicKey','sisorootlocusplot',...
    'ButtonDownFcn',{@LocalButtonDown Editor});

% Axis lines
XaxisLine = line([-1 1],[0 0],'Visible','off',...
    'Color',Editor.AxesForegroundColor,'LineStyle',':','Parent',PlotAxes);
YaxisLine = line([0 0],[-1 1],'Visible','off',...
    'Color',Editor.AxesForegroundColor,'LineStyle',':','Parent',PlotAxes);

% Add context menus
U = uicontextmenu('Parent',SISOfig); 
set(PlotAxes,'UIContextMenu',U)  % anchor to plot axes
LocalAddMenus(Editor,U,1);
set(get(U,'children'),'Enable','off')

% Replicate menus in main figure
LocalAddMenus(Editor,Anchors.Menu,0);

% Data structure of HG objects
HG = struct(...
    'AxisLines',[XaxisLine;YaxisLine],...
    'ClosedLoop',[],...
    'Compensator',[],...
    'ConstraintDialog',[],...
    'ConstraintLines',[],...
    'GridLines',[],...
    'Locus',[],...
    'PlotAxes',PlotAxes,...
    'StatusText',Anchors.Status,...
    'System',[]);

%-------------------------- Local Functions ------------------------

%%%%%%%%%%%%%%%%%%%%%
%%% LocalAddMenus %%%
%%%%%%%%%%%%%%%%%%%%%
function LocalAddMenus(Editor,MenuAnchor,EditFlag)
% Builds right-click menus

% Edit pole/zero group
addmenu(Editor,MenuAnchor,'add');
addmenu(Editor,MenuAnchor,'delete');
if EditFlag
    addmenu(Editor,MenuAnchor,'edit');
end

% Constraints/Grid/Zoom
h = addmenu(Editor,MenuAnchor,'constraint');
set(h,'Separator','on')
h = addmenu(Editor,MenuAnchor,'grid');
set(h,'Checked',Editor.Grid);
addmenu(Editor,MenuAnchor,'zoom');

% Properties
if usejava('MWT')
    h = addmenu(Editor,MenuAnchor,'property');
    set(h,'Separator','on')
end


%%%%%%%%%%%%%%%%%%%%%%%
%%% LocalButtonDown %%%
%%%%%%%%%%%%%%%%%%%%%%%
function LocalButtonDown(hSrc,event,Editor)
% Button down callbacks
if strcmp(Editor.EditMode,'idle')
	switch get(get(hSrc,'Parent'),'SelectionType')
	case 'normal'
		if isopen(cstprefs.sisoprops)
			cstprefs.sisoprops(Editor);
		end
	case 'open'
		cstprefs.sisoprops(Editor);
	end
end
