svghmi/gen_index_xhtml.xslt
branchsvghmi
changeset 3085 6b1b23971960
parent 3084 1ae4a871b6f9
child 3090 9e172e4e50c7
equal deleted inserted replaced
3084:1ae4a871b6f9 3085:6b1b23971960
  1673     <xsl:text>    }
  1673     <xsl:text>    }
  1674 </xsl:text>
  1674 </xsl:text>
  1675     <xsl:text>}
  1675     <xsl:text>}
  1676 </xsl:text>
  1676 </xsl:text>
  1677   </xsl:template>
  1677   </xsl:template>
       
  1678   <xsl:variable name="_button_fsm">
       
  1679     <fsm>
       
  1680       <state name="init">
       
  1681         <on-dispatch value="false">
       
  1682           <jump state="released"/>
       
  1683         </on-dispatch>
       
  1684         <on-dispatch value="true">
       
  1685           <jump state="pressed"/>
       
  1686         </on-dispatch>
       
  1687       </state>
       
  1688       <state name="pressing">
       
  1689         <hmi-value value="true"/>
       
  1690         <on-dispatch value="true">
       
  1691           <jump state="pressed"/>
       
  1692         </on-dispatch>
       
  1693         <on-mouse position="up">
       
  1694           <jump state="shortpress"/>
       
  1695         </on-mouse>
       
  1696       </state>
       
  1697       <state name="pressed">
       
  1698         <show eltname="active"/>
       
  1699         <on-mouse position="up">
       
  1700           <jump state="releasing"/>
       
  1701         </on-mouse>
       
  1702         <on-dispatch value="false">
       
  1703           <jump state="released"/>
       
  1704         </on-dispatch>
       
  1705       </state>
       
  1706       <state name="shortpress">
       
  1707         <on-dispatch value="true">
       
  1708           <jump state="releasing"/>
       
  1709         </on-dispatch>
       
  1710         <on-mouse position="down">
       
  1711           <jump state="pressing"/>
       
  1712         </on-mouse>
       
  1713       </state>
       
  1714       <state name="releasing">
       
  1715         <hmi-value value="false"/>
       
  1716         <on-dispatch value="false">
       
  1717           <jump state="released"/>
       
  1718         </on-dispatch>
       
  1719         <on-mouse position="down">
       
  1720           <jump state="shortrelease"/>
       
  1721         </on-mouse>
       
  1722       </state>
       
  1723       <state name="released">
       
  1724         <show eltname="inactive"/>
       
  1725         <on-mouse position="down">
       
  1726           <jump state="pressing"/>
       
  1727         </on-mouse>
       
  1728         <on-dispatch value="true">
       
  1729           <jump state="pressed"/>
       
  1730         </on-dispatch>
       
  1731       </state>
       
  1732       <state name="shortrelease">
       
  1733         <on-dispatch value="false">
       
  1734           <jump state="pressing"/>
       
  1735         </on-dispatch>
       
  1736         <on-mouse position="up">
       
  1737           <jump state="releasing"/>
       
  1738         </on-mouse>
       
  1739       </state>
       
  1740     </fsm>
       
  1741   </xsl:variable>
       
  1742   <xsl:template mode="dispatch_transition" match="fsm">
       
  1743     <xsl:text>        switch (this.state) {
       
  1744 </xsl:text>
       
  1745     <xsl:apply-templates mode="dispatch_transition" select="state"/>
       
  1746     <xsl:text>        }
       
  1747 </xsl:text>
       
  1748   </xsl:template>
       
  1749   <xsl:template mode="dispatch_transition" match="state">
       
  1750     <xsl:text>          case "</xsl:text>
       
  1751     <xsl:value-of select="@name"/>
       
  1752     <xsl:text>":
       
  1753 </xsl:text>
       
  1754     <xsl:apply-templates select="on-dispatch"/>
       
  1755     <xsl:text>            break;
       
  1756 </xsl:text>
       
  1757   </xsl:template>
       
  1758   <xsl:template match="on-dispatch">
       
  1759     <xsl:text>            if(value ==  </xsl:text>
       
  1760     <xsl:value-of select="@value"/>
       
  1761     <xsl:text>) {
       
  1762 </xsl:text>
       
  1763     <xsl:apply-templates mode="transition" select="jump"/>
       
  1764     <xsl:text>            }
       
  1765 </xsl:text>
       
  1766   </xsl:template>
       
  1767   <xsl:template mode="mouse_transition" match="fsm">
       
  1768     <xsl:param name="position"/>
       
  1769     <xsl:text>        switch (this.state) {
       
  1770 </xsl:text>
       
  1771     <xsl:apply-templates mode="mouse_transition" select="state">
       
  1772       <xsl:with-param name="position" select="$position"/>
       
  1773     </xsl:apply-templates>
       
  1774     <xsl:text>        }
       
  1775 </xsl:text>
       
  1776   </xsl:template>
       
  1777   <xsl:template mode="mouse_transition" match="state">
       
  1778     <xsl:param name="position"/>
       
  1779     <xsl:text>          case "</xsl:text>
       
  1780     <xsl:value-of select="@name"/>
       
  1781     <xsl:text>":
       
  1782 </xsl:text>
       
  1783     <xsl:apply-templates select="on-mouse[@position = $position]"/>
       
  1784     <xsl:text>            break;
       
  1785 </xsl:text>
       
  1786   </xsl:template>
       
  1787   <xsl:template match="on-mouse">
       
  1788     <xsl:apply-templates mode="transition" select="jump"/>
       
  1789   </xsl:template>
       
  1790   <xsl:template mode="transition" match="jump">
       
  1791     <xsl:text>            this.state = "</xsl:text>
       
  1792     <xsl:value-of select="@state"/>
       
  1793     <xsl:text>";
       
  1794 </xsl:text>
       
  1795     <xsl:text>            this.</xsl:text>
       
  1796     <xsl:value-of select="@state"/>
       
  1797     <xsl:text>_action();
       
  1798 </xsl:text>
       
  1799   </xsl:template>
       
  1800   <xsl:template mode="actions" match="fsm">
       
  1801     <xsl:apply-templates mode="actions" select="state"/>
       
  1802   </xsl:template>
       
  1803   <xsl:template mode="actions" match="state">
       
  1804     <xsl:text>    </xsl:text>
       
  1805     <xsl:value-of select="@name"/>
       
  1806     <xsl:text>_action(){
       
  1807 </xsl:text>
       
  1808     <xsl:apply-templates mode="actions" select="*"/>
       
  1809     <xsl:text>    }
       
  1810 </xsl:text>
       
  1811   </xsl:template>
       
  1812   <xsl:template mode="actions" match="show">
       
  1813     <xsl:text>        this.display = "</xsl:text>
       
  1814     <xsl:value-of select="@eltname"/>
       
  1815     <xsl:text>";
       
  1816 </xsl:text>
       
  1817     <xsl:text>        this.request_animate();
       
  1818 </xsl:text>
       
  1819   </xsl:template>
       
  1820   <xsl:template mode="actions" match="hmi-value">
       
  1821     <xsl:text>        this.apply_hmi_value(0, </xsl:text>
       
  1822     <xsl:value-of select="@value"/>
       
  1823     <xsl:text>);
       
  1824 </xsl:text>
       
  1825   </xsl:template>
  1678   <xsl:template mode="widget_class" match="widget[@type='Button']">
  1826   <xsl:template mode="widget_class" match="widget[@type='Button']">
       
  1827     <xsl:variable name="fsm" select="exsl:node-set($_button_fsm)"/>
  1679     <xsl:text>class ButtonWidget extends Widget{
  1828     <xsl:text>class ButtonWidget extends Widget{
  1680 </xsl:text>
  1829 </xsl:text>
  1681     <xsl:text>    frequency = 5;
  1830     <xsl:text>    frequency = 5;
  1682 </xsl:text>
  1831 </xsl:text>
  1683     <xsl:text>    state_plc = 0;
  1832     <xsl:text>    display = "inactive";
  1684 </xsl:text>
  1833 </xsl:text>
  1685     <xsl:text>    state_hmi = 0;
  1834     <xsl:text>    state = "init";
  1686 </xsl:text>
       
  1687     <xsl:text>    plc_lock = false;
       
  1688 </xsl:text>
       
  1689     <xsl:text>    active_style = undefined;
       
  1690 </xsl:text>
       
  1691     <xsl:text>    inactive_style = undefined;
       
  1692 </xsl:text>
       
  1693     <xsl:text>
       
  1694 </xsl:text>
  1835 </xsl:text>
  1695     <xsl:text>    dispatch(value) {
  1836     <xsl:text>    dispatch(value) {
  1696 </xsl:text>
  1837 </xsl:text>
  1697     <xsl:text>        this.state_plc = value;
  1838     <xsl:apply-templates mode="dispatch_transition" select="$fsm"/>
  1698 </xsl:text>
  1839     <xsl:text>    }
  1699     <xsl:text>        if(this.plc_lock){
  1840 </xsl:text>
  1700 </xsl:text>
  1841     <xsl:text>    onmouseup(evt) {
  1701     <xsl:text>            if(this.state_plc == 1){
  1842 </xsl:text>
  1702 </xsl:text>
  1843     <xsl:text>        svg_root.removeEventListener("pointerup", this.bound_onmouseup, true);
  1703     <xsl:text>                this.apply_hmi_value(0, 0);
  1844 </xsl:text>
  1704 </xsl:text>
  1845     <xsl:apply-templates mode="mouse_transition" select="$fsm">
  1705     <xsl:text>                this.plc_lock = false;
  1846       <xsl:with-param name="position" select="'up'"/>
  1706 </xsl:text>
  1847     </xsl:apply-templates>
  1707     <xsl:text>            }
  1848     <xsl:text>    }
  1708 </xsl:text>
  1849 </xsl:text>
  1709     <xsl:text>        }
  1850     <xsl:text>    onmousedown(evt) {
  1710 </xsl:text>
  1851 </xsl:text>
  1711     <xsl:text>
  1852     <xsl:text>        svg_root.addEventListener("pointerup", this.bound_onmouseup, true);
  1712 </xsl:text>
  1853 </xsl:text>
  1713     <xsl:text>        //redraw button
  1854     <xsl:apply-templates mode="mouse_transition" select="$fsm">
  1714 </xsl:text>
  1855       <xsl:with-param name="position" select="'down'"/>
  1715     <xsl:text>        this.state_hmi = this.state_plc;
  1856     </xsl:apply-templates>
  1716 </xsl:text>
  1857     <xsl:text>    }
  1717     <xsl:text>        this.request_animate();
  1858 </xsl:text>
  1718 </xsl:text>
  1859     <xsl:apply-templates mode="actions" select="$fsm"/>
  1719     <xsl:text>    }
       
  1720 </xsl:text>
       
  1721     <xsl:text>
       
  1722 </xsl:text>
       
  1723     <xsl:text>    animate(){
  1860     <xsl:text>    animate(){
  1724 </xsl:text>
  1861 </xsl:text>
  1725     <xsl:text>        if (this.active_style &amp;&amp; this.inactive_style) {
  1862     <xsl:text>        if (this.active_elt &amp;&amp; this.inactive_elt) {
  1726 </xsl:text>
  1863 </xsl:text>
  1727     <xsl:text>           // redraw button on screen refresh
  1864     <xsl:for-each select="str:split('active inactive')">
  1728 </xsl:text>
  1865       <xsl:text>            if(this.display == "</xsl:text>
  1729     <xsl:text>           if (this.state_hmi) {
  1866       <xsl:value-of select="."/>
  1730 </xsl:text>
  1867       <xsl:text>")
  1731     <xsl:text>               this.active_elt.setAttribute("style", this.active_style);
  1868 </xsl:text>
  1732 </xsl:text>
  1869       <xsl:text>                this.</xsl:text>
  1733     <xsl:text>               this.inactive_elt.setAttribute("style", "display:none");
  1870       <xsl:value-of select="."/>
  1734 </xsl:text>
  1871       <xsl:text>_elt.style.display = "";
  1735     <xsl:text>           } else {
  1872 </xsl:text>
  1736 </xsl:text>
  1873       <xsl:text>            else
  1737     <xsl:text>               this.inactive_elt.setAttribute("style", this.inactive_style);
  1874 </xsl:text>
  1738 </xsl:text>
  1875       <xsl:text>                this.</xsl:text>
  1739     <xsl:text>               this.active_elt.setAttribute("style", "display:none");
  1876       <xsl:value-of select="."/>
  1740 </xsl:text>
  1877       <xsl:text>_elt.style.display = "none";
  1741     <xsl:text>           }
  1878 </xsl:text>
  1742 </xsl:text>
  1879     </xsl:for-each>
  1743     <xsl:text>       }
  1880     <xsl:text>        }
  1744 </xsl:text>
  1881 </xsl:text>
  1745     <xsl:text>    }
  1882     <xsl:text>    }
  1746 </xsl:text>
  1883 </xsl:text>
  1747     <xsl:text>
  1884     <xsl:text>    init() {
  1748 </xsl:text>
  1885 </xsl:text>
  1749     <xsl:text>    on_click(evt) {
  1886     <xsl:text>        this.bound_onmouseup = this.onmouseup.bind(this);
  1750 </xsl:text>
  1887 </xsl:text>
  1751     <xsl:text>        //set state and apply if plc is 0
  1888     <xsl:text>        this.element.addEventListener("pointerdown", this.onmousedown.bind(this));
  1752 </xsl:text>
  1889 </xsl:text>
  1753     <xsl:text>        this.plc_lock = true;
  1890     <xsl:text>    }
  1754 </xsl:text>
       
  1755     <xsl:text>        if(this.state_plc == 0){
       
  1756 </xsl:text>
       
  1757     <xsl:text>            this.apply_hmi_value(0, 1);
       
  1758 </xsl:text>
       
  1759     <xsl:text>        }
       
  1760 </xsl:text>
       
  1761     <xsl:text>        //redraw button
       
  1762 </xsl:text>
       
  1763     <xsl:text>        this.request_animate();
       
  1764 </xsl:text>
       
  1765     <xsl:text>    }
       
  1766 </xsl:text>
       
  1767     <xsl:text>
       
  1768 </xsl:text>
       
  1769     <xsl:text>    on_press(evt) {
       
  1770 </xsl:text>
       
  1771     <xsl:text>        //set graphic
       
  1772 </xsl:text>
       
  1773     <xsl:text>        this.state_hmi = 1;
       
  1774 </xsl:text>
       
  1775     <xsl:text>        //redraw button
       
  1776 </xsl:text>
       
  1777     <xsl:text>        this.request_animate();
       
  1778 </xsl:text>
       
  1779     <xsl:text>    }
       
  1780 </xsl:text>
       
  1781     <xsl:text>
       
  1782 </xsl:text>
       
  1783     <xsl:text>     init() {
       
  1784 </xsl:text>
       
  1785     <xsl:text>        this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined;
       
  1786 </xsl:text>
       
  1787     <xsl:text>        this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined;
       
  1788 </xsl:text>
       
  1789     <xsl:text>
       
  1790 </xsl:text>
       
  1791     <xsl:text>        if (this.active_style &amp;&amp; this.inactive_style) {
       
  1792 </xsl:text>
       
  1793     <xsl:text>            this.active_elt.setAttribute("style", "display:none");
       
  1794 </xsl:text>
       
  1795     <xsl:text>            this.inactive_elt.setAttribute("style", this.inactive_style);
       
  1796 </xsl:text>
       
  1797     <xsl:text>        }
       
  1798 </xsl:text>
       
  1799     <xsl:text>
       
  1800 </xsl:text>
       
  1801     <xsl:text>        this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)");
       
  1802 </xsl:text>
       
  1803     <xsl:text>        this.element.setAttribute("onmousedown", "hmi_widgets['"+this.element_id+"'].on_press(evt)");
       
  1804 </xsl:text>
       
  1805     <xsl:text>     }
       
  1806 </xsl:text>
  1891 </xsl:text>
  1807     <xsl:text>}
  1892     <xsl:text>}
  1808 </xsl:text>
  1893 </xsl:text>
  1809   </xsl:template>
  1894   </xsl:template>
  1810   <xsl:template mode="widget_defs" match="widget[@type='Button']">
  1895   <xsl:template mode="widget_defs" match="widget[@type='Button']">
  6643 </xsl:text>
  6728 </xsl:text>
  6644           <xsl:text>
  6729           <xsl:text>
  6645 </xsl:text>
  6730 </xsl:text>
  6646           <xsl:text>function prepare_svg() {
  6731           <xsl:text>function prepare_svg() {
  6647 </xsl:text>
  6732 </xsl:text>
       
  6733           <xsl:text>    // prevents context menu from appearing on right click and long touch
       
  6734 </xsl:text>
  6648           <xsl:text>    document.body.addEventListener('contextmenu', e =&gt; {
  6735           <xsl:text>    document.body.addEventListener('contextmenu', e =&gt; {
  6649 </xsl:text>
  6736 </xsl:text>
  6650           <xsl:text>        e.preventDefault();
  6737           <xsl:text>        e.preventDefault();
  6651 </xsl:text>
  6738 </xsl:text>
  6652           <xsl:text>    });
  6739           <xsl:text>    });
       
  6740 </xsl:text>
       
  6741           <xsl:text>
  6653 </xsl:text>
  6742 </xsl:text>
  6654           <xsl:text>    for(let eltid in detachable_elements){
  6743           <xsl:text>    for(let eltid in detachable_elements){
  6655 </xsl:text>
  6744 </xsl:text>
  6656           <xsl:text>        let [element,parent] = detachable_elements[eltid];
  6745           <xsl:text>        let [element,parent] = detachable_elements[eltid];
  6657 </xsl:text>
  6746 </xsl:text>