%% Extract the Architecture of a Simulink Model Using System Composer

% Copyright 2019 The MathWorks, Inc.
%% Overview
% This example shows how we can export an existing Simulink model to a
% System Composer architecture model.
% The algorithmic sections of the original model are 
% removed and structural information is preserved during this
% process. Requirements links, if any, are also preserved.

%% Converting Simulink Model to System Composer Architecture
% System Composer converts structural constructs in a Simulink model to 
% equivalent architecture model constructs:
%
% * Subsystems to components
% * Variant subsystems to variant components
% * Bus objects to interfaces
% * Referenced models to reference components

%% Open the Model
% Open the Simulink model of a system.

[projectFolder, ~] = matlab.internal.project.example.projectDemoSetUp( ...
       fullfile(matlabroot,'toolbox','simulink'...
            ,'simdemos','automotive','powerwindow','powerwindow.zip'),...
            [], false);
proj = openProject(projectFolder);
open_system('slexPowerWindowExample');

%% Export the Model 
% Extract an architecture model from the original model.

systemcomposer.extractArchitectureFromSimulink('slexPowerWindowExample','PowerWindowArchitecture');
Simulink.BlockDiagram.arrangeSystem('PowerWindowArchitecture'); 
systemcomposer.openModel('PowerWindowArchitecture');
