classdef Rotate3D < handle

properties (getAccess = public, SetAccess = private)
  FigureHandle;
endproperties

properties (public)
  Enable = "off";
  RotateStyle = "orbit";
  
  UIContextMenu = [];
  ButtonDownFilter = [];
  ActionPreCallback = [];
  ActionPostCallback = [];
endproperties

methods (Access = public)

function this = Rotate3D (hfig)
  if (nargin == 0)
    error ("A figure handle has to be provided.");
  endif
  this.FigureHandle = hfig;
endfunction

function val = get (this, prop)
  if (nargin == 1)
    if (! nargout)
      display (this);
    else
      val = struct (this);
    endif
    return;
  endif
  val = this.(prop);
endfunction

function set (this, prop, val)
  if (strcmp (prop, "FigureHandle"))
    error ("property `FigureHandle' has private access and cannot be set in this context");
  endif
  this.(prop) = val;
endfunction

function set.Enable (this, rm)
  switch lower (rm)
    case "on"
      this.Enable = "on";
    case "off"
      this.Enable = "off";
    otherwise
      error ("Invalid rotate3d mode.");
  endswitch
  rotate3d (this.FigureHandle, rm);
endfunction

function set.RotateStyle (this, rs)
  switch lower (rs)
    case "orbit"
      this.RotateStyle = "orbit";
    case "box"
      this.RotateStyle = "box";
    otherwise
      error ("Invalid rotate3d style.");
  endswitch
endfunction

function display (this)
  if (nargin > 1)
    print_usage ();
  endif
  printf ("Rotate3D object with properties:\n\n");
  printf (["   FigureHandle : %d\n" ...
           "   Enable       : \"%s\"\n" ...
           "   RotateStyle  : \"%s\"\n\n"],
           this.FigureHandle, this.Enable, this.RotateStyle);
endfunction

function retval = struct (this)
  retval = struct(...
    "FigureHandle", this.FigureHandle,...
    "Enable", this.Enable,...
    "RotateStyle", this.RotateStyle);
endfunction

endmethods

endclassdef
