Main Content

createDiagramTwoWayLink

Class: slreportgen.webview.EmbeddedWebViewDocument
Package: slreportgen.webview

Link and anchor in embedded Web view report

Syntax

diag2link = createDiagramTwoWayLink(wvdoc,dhandle,domlabel)

Description

diag2link = createDiagramTwoWayLink(wvdoc,dhandle,domlabel) creates a two-way connection between a Simulink® Web view diagram and a DOM object in an embedded Web view Document panel. The diag2link DOM object is updated to include attributes that identifies it as a link. The diag2link DOM object is of the same type as domlabel or if domlabel is a string, an mlreportgen.DOM.Text object is created.

Input Arguments

expand all

Web view document, specified as an slreportgen.webview.WebViewDocument object.

Handle of Web view diagram anchor, specified as a character vector of the path or as an object handle. You can use the getExportDiagrams method to obtain the diagram paths and handles.

Example: Character vector: 'slrgex_vdp'. Object handle: get_param('slrgex_vdp','handle')

DOM object from which to link, specified as a valid DOM object or as a character vector. If you enter a character vector, an mlreportgen.DOM.Text object is created.

Output Arguments

expand all

Examples

expand all

Use createDiagramTwoWayLink to create two-way links between level-two headings in the document pane and the associated diagrams in the embedded web view. This example also uses createElementTwoWayLink to create links between block names in the document pane and blocks in the embedded web view.

Run the following command to access the supporting files used in this example.

openExample('rptgenext/SimulinkReportGeneratorFilesExample');

Write a class, ExampleWebView, that is a subclass of slreportgen.webview.EmbeddedWebViewDocument. Use createDiagramTwoWayLink and createElementTwoWayLink in the fillContent method.

classdef ExampleWebView< slreportgen.webview.EmbeddedWebViewDocument
    
    methods
        function wvdoc = ExampleWebView(reportPath,modelName)
            % Invoke the EmbeddedWebViewDocument constructor, which
            % saves the report path and model name for use by the
            % report's fill methods.
            wvdoc@slreportgen.webview.EmbeddedWebViewDocument(reportPath,modelName);
        end
        
        function fillContent(wvdoc)
            % Fill the Content hole in the report template with design
            % variable information. You can use DOM or Report API methods
            % to create, format, add, and append content to this report.
            
            [~, handles] = getExportDiagrams(wvdoc);
            
            n = numel(handles);
            for i = 1:n
                diagHandle = handles{i};
                diagHeading = createDiagramTwoWayLink(wvdoc,diagHandle, ...
                    mlreportgen.dom.Heading(2,get_param(diagHandle,'Name')));
                append(wvdoc,diagHeading);
                
                blockFinder = slreportgen.finder.BlockFinder(diagHandle);
                
                while hasNext(blockFinder)
                    r = next(blockFinder);
                    elemHandle = r.Object;
                    elemHeading = createElementTwoWayLink(wvdoc,elemHandle, ...
                        mlreportgen.dom.Heading(3,get_param(elemHandle,'Name')));
                    
                    append(wvdoc,elemHeading);
                end
                
            end
        end
    end
end

Create an object of the ExampleWebView class and use its methods to generate the embedded web view report.

model = 'slrgex_vdp';
open_system(model);
wvdoc = ExampleWebView('myReport',model);
open(wvdoc);
fill(wvdoc);
close(wvdoc);
rptview(wvdoc);

More About

expand all

Version History

Introduced in R2017a