Code covered by the BSD License  

Highlights from
Simscape Language Equations, Pretty Print

image thumbnail

Simscape Language Equations, Pretty Print

by

 

14 Jan 2011 (Updated )

MATLAB code for displaying Simscape language equations in a format that is easy to read.

prettySimscape(varargin)
function varargout = prettySimscape(varargin)
  % PRETTYSIMSCAPE MATLAB code for prettySimscape.fig
  %      PRETTYSIMSCAPE, by itself, creates a new PRETTYSIMSCAPE or raises the existing
  %      singleton*.
  %
  %      H = PRETTYSIMSCAPE returns the handle to a new PRETTYSIMSCAPE or the handle to
  %      the existing singleton*.
  %
  %      PRETTYSIMSCAPE('CALLBACK',hObject,eventData,handles,...) calls the local
  %      function named CALLBACK in PRETTYSIMSCAPE.M with the given input arguments.
  %
  %      PRETTYSIMSCAPE('Property','Value',...) creates a new PRETTYSIMSCAPE or raises the
  %      existing singleton*.  Starting from the left, property value pairs are
  %      applied to the GUI before prettySimscape_OpeningFcn gets called.  An
  %      unrecognized property name or invalid value makes property application
  %      stop.  All inputs are passed to prettySimscape_OpeningFcn via varargin.
  %
  %      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
  %      instance to run (singleton)".
  %
  % See also: GUIDE, GUIDATA, GUIHANDLES
  % Copyright 2011 The MathWorks, Inc.
  
  % Edit the above text to modify the response to help prettySimscape
  
  % Last Modified by GUIDE v2.5 13-Jan-2011 10:25:22
  
  % Begin initialization code - DO NOT EDIT
  gui_Singleton = 1;
  gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @prettySimscape_OpeningFcn, ...
    'gui_OutputFcn',  @prettySimscape_OutputFcn, ...
    'gui_LayoutFcn',  [] , ...
    'gui_Callback',   []);
  if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
  end
  
  if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  else
    gui_mainfcn(gui_State, varargin{:});
  end
  % End initialization code - DO NOT EDIT
  
  
  % --- Executes just before prettySimscape is made visible.
function prettySimscape_OpeningFcn(hObject, eventdata, handles, varargin)
  % This function has no output args, see OutputFcn.
  % hObject    handle to figure
  % eventdata  reserved - to be defined in a future version of MATLAB
  % handles    structure with handles and user data (see GUIDATA)
  % varargin   command line arguments to prettySimscape (see VARARGIN)
  
  if isfield(handles,'Txt')% && all(ishghandle(handles.Txt))
    try
      delete(handles.Txt);
    catch
    end
  end
  set(handles.equations,'xlim',[0 1],'ylim',[0 1]);
  axis(handles.equations,'off');
  
  % Choose default command line output for prettySimscape
  handles.output = hObject;
  switch  numel(varargin)
    case 0
      try
        %2011a
        filename = matlab.desktop.editor.getActiveFilename;
      catch
        try
          %version<2011a
          filename = editorservices.getActiveFilename;
        catch
          error('prettySimscape:SpecifySimscapeFile','Please use the syntax prettySimscape(filename)');
        end
      end
    case 1
      filename = varargin{1};
    otherwise
      error('prettySimscape:TooManyArguments','Too many input arguments');
  end
  [buf, name, ext] = fileparts(filename);
  
  if strcmp(ext,'.ssc')
    set(handles.filePath,'string',[name ext]);
    s=ssc2latex(filename);
    
    pos = [0.01,1];
    EqNum = numel(s);
    maxFont = 14;
    minFont = 10;
    fontSize = max(floor(maxFont-(maxFont-minFont)/10*EqNum),minFont);
    for k=1:EqNum
      handles.Txt(k) = text('parent',handles.equations,...
        'Position',pos,'String',s(k),'Parent',handles.equations,...
        'interpreter','latex','fontsize',fontSize,'VerticalAlignment','top');
      textSize = get(handles.Txt(k),'Extent');
      pos = [0.01,pos(2)-textSize(4)];
    end
    
  else
    set(handles.filePath,'string','Simscape files only (*.ssc)');
  end
  
  % Update handles structure
  guidata(hObject, handles);
  
  % UIWAIT makes prettySimscape wait for user response (see UIRESUME)
  % uiwait(handles.figure1);
  
  
  
  
  % --- Outputs from this function are returned to the command line.
function varargout = prettySimscape_OutputFcn(hObject, eventdata, handles)
  % varargout  cell array for returning output args (see VARARGOUT);
  % hObject    handle to figure
  % eventdata  reserved - to be defined in a future version of MATLAB
  % handles    structure with handles and user data (see GUIDATA)
  
  % Get default command line output from handles structure
  varargout{1} = handles.output;


% --- Executes when figure1 is resized.
function figure1_ResizeFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
pos = get(hObject,'position');
n = pos(4)/450;%450 is the initial windows height
set(handles.equations,'ylim',[1-n,1]);

Contact us