function mcodeConstructor(hObj,hCode)
% Generate code for surfaceplot, called by MAKEMCODE

% Copyright 2003 The MathWorks, Inc.

propsToIgnore = {};

% Determine constructor name: SURF or MESH
edgecolor = get(hObj,'EdgeColor');
facelighting = get(hObj,'FaceLighting');
edgelighting = get(hObj,'EdgeLighting');
if strcmp(edgecolor,'flat') && ...
   strcmp(facelighting,'none') && ...
   strcmp(edgelighting,'flat')  
     propsToIgnore = {propsToIgnore{:},...
                      'FaceColor','EdgeColor',...
                      'FaceLighting','EdgeLighting'};
     constructor_name = 'mesh';
else
     constructor_name = 'surf';
end
setConstructorName(hCode,constructor_name);


% Ignore new properties until this object is default
propsToIgnore = {'DisplayName','XDataMode','YDataMode','CDataMode',...
                 'XDataSource','YDataSource','CDataSource',...
                 propsToIgnore{:}};
ignoreProperty(hCode,propsToIgnore);

% Don't show xdata, ydata if auto-generated
% Determine if xdata and ydata were auto generated by
% surface at constructor time. This is basically 
% reverse engineering how the surface constructor wrt
% how it handles zdata when doing: "surface(zdata)"
xdata = get(hObj,'xdata');
ydata = get(hObj,'ydata');
zdata = get(hObj,'zdata');
cdata = get(hObj,'cdata');

m = size(zdata,1);
n = size(zdata,2);

is_default_xdata = isequal((1:n),xdata); 
is_default_ydata = isequal((1:m)',ydata);
is_default_cdata = isequal(zdata,cdata);

ignoreProperty(hCode,{'XData','YData','ZData','CData'});
   
% SURFACE(Z,...)
if is_default_xdata && is_default_ydata && is_default_cdata
   
    % ZData
    hArg = codegen.codeargument('Value',zdata,'Name','zdata','IsParameter',true);
    addConstructorArgin(hCode,hArg);

% SURFACE(Z,C,...)
elseif is_default_xdata && is_default_ydata 
   
    % ZData
    hArg = codegen.codeargument('Value',zdata,'Name','zdata','IsParameter',true);
    addConstructorArgin(hCode,hArg);
    
    % CData
    hArg = codegen.codeargument('Value',cdata,'Name','cdata','IsParameter',true);
    addConstructorArgin(hCode,hArg);
    
% SURFACE(X,Y,Z,...)
elseif is_default_cdata
   
    % XData
    hArg = codegen.codeargument('Value',xdata,'Name','xdata','IsParameter',true);
    addConstructorArgin(hCode,hArg);
    
    % YData
    hArg = codegen.codeargument('Value',ydata,'Name','ydata','IsParameter',true);
    addConstructorArgin(hCode,hArg);
    
    % ZData
    hArg = codegen.codeargument('Value',zdata,'Name','zdata','IsParameter',true);
    addConstructorArgin(hCode,hArg);
    
% SURFACE(X,Y,Z,C,...)
else
    % XData
    hArg = codegen.codeargument('Value',xdata,'Name','xdata','IsParameter',true);
    addConstructorArgin(hCode,hArg);
    
    % YData
    hArg = codegen.codeargument('Value',ydata,'Name','ydata','IsParameter',true);
    addConstructorArgin(hCode,hArg);
    
    % ZData
    hArg = codegen.codeargument('Value',zdata,'Name','zdata','IsParameter',true);
    addConstructorArgin(hCode,hArg);
    
    % CData
    hArg = codegen.codeargument('Value',zdata,'Name','cdata','IsParameter',true);
    addConstructorArgin(hCode,hArg);
end

% Don't show VertexNormals if auto-generated
if strcmpi(get(hObj,'NormalMode'),'auto');
    ignoreProperty(hCode,{'VertexNormals'});
end

generateDefaultPropValueSyntax(hCode); % method