svghmi/gen_index_xhtml.xslt
branchsvghmi
changeset 2864 36f78f6cfabd
parent 2862 a108677bd3d0
child 2865 545902730141
equal deleted inserted replaced
2863:e120d6985a2f 2864:36f78f6cfabd
   623 </xsl:text>
   623 </xsl:text>
   624     <xsl:text>var cache = hmitree_types.map(_ignored =&gt; undefined);
   624     <xsl:text>var cache = hmitree_types.map(_ignored =&gt; undefined);
   625 </xsl:text>
   625 </xsl:text>
   626     <xsl:text>var updates = {};
   626     <xsl:text>var updates = {};
   627 </xsl:text>
   627 </xsl:text>
   628     <xsl:text>var page_switch = null;
       
   629 </xsl:text>
       
   630     <xsl:text>
   628     <xsl:text>
   631 </xsl:text>
   629 </xsl:text>
   632     <xsl:text>function dispatch_value_to_widget(widget, index, value, oldval) {
   630     <xsl:text>function dispatch_value_to_widget(widget, index, value, oldval) {
   633 </xsl:text>
   631 </xsl:text>
   634     <xsl:text>    try {
   632     <xsl:text>    try {
   759 </xsl:text>
   757 </xsl:text>
   760     <xsl:text>// Called on requestAnimationFrame, modifies DOM
   758     <xsl:text>// Called on requestAnimationFrame, modifies DOM
   761 </xsl:text>
   759 </xsl:text>
   762     <xsl:text>function animate() {
   760     <xsl:text>function animate() {
   763 </xsl:text>
   761 </xsl:text>
   764     <xsl:text>    if(page_switch != null){
   762     <xsl:text>    if(current_subscribed_page != current_visible_page){
   765 </xsl:text>
   763 </xsl:text>
   766     <xsl:text>        do_switch_page(page_switch);
   764     <xsl:text>        switch_visible_page(current_subscribed_page);
   767 </xsl:text>
       
   768     <xsl:text>        page_switch=null;
       
   769 </xsl:text>
   765 </xsl:text>
   770     <xsl:text>    }
   766     <xsl:text>    }
   771 </xsl:text>
   767 </xsl:text>
   772     <xsl:text>
   768     <xsl:text>
   773 </xsl:text>
   769 </xsl:text>
   781 </xsl:text>
   777 </xsl:text>
   782     <xsl:text>        delete updates[index];
   778     <xsl:text>        delete updates[index];
   783 </xsl:text>
   779 </xsl:text>
   784     <xsl:text>    }
   780     <xsl:text>    }
   785 </xsl:text>
   781 </xsl:text>
       
   782     <xsl:text>    requestAnimationFrameID = null;
       
   783 </xsl:text>
   786     <xsl:text>}
   784     <xsl:text>}
   787 </xsl:text>
   785 </xsl:text>
   788     <xsl:text>
   786     <xsl:text>
   789 </xsl:text>
   787 </xsl:text>
   790     <xsl:text>var requestAnimationFrameID = null;
   788     <xsl:text>var requestAnimationFrameID = null;
   791 </xsl:text>
   789 </xsl:text>
   792     <xsl:text>function requestHMIAnimation() {
   790     <xsl:text>function requestHMIAnimation() {
   793 </xsl:text>
   791 </xsl:text>
   794     <xsl:text>    if(requestAnimationFrameID != null){
   792     <xsl:text>    if(requestAnimationFrameID == null){
   795 </xsl:text>
   793 </xsl:text>
   796     <xsl:text>        window.cancelAnimationFrame(requestAnimationFrameID);
   794     <xsl:text>        requestAnimationFrameID = window.requestAnimationFrame(animate);
   797 </xsl:text>
   795 </xsl:text>
   798     <xsl:text>        requestAnimationFrameID = null;
   796     <xsl:text>    }
   799 </xsl:text>
       
   800     <xsl:text>    }
       
   801 </xsl:text>
       
   802     <xsl:text>    requestAnimationFrameID = window.requestAnimationFrame(animate);
       
   803 </xsl:text>
   797 </xsl:text>
   804     <xsl:text>}
   798     <xsl:text>}
   805 </xsl:text>
   799 </xsl:text>
   806     <xsl:text>
   800     <xsl:text>
   807 </xsl:text>
   801 </xsl:text>
   863 </xsl:text>
   857 </xsl:text>
   864     <xsl:text>        };
   858     <xsl:text>        };
   865 </xsl:text>
   859 </xsl:text>
   866     <xsl:text>        // register for rendering on next frame, since there are updates
   860     <xsl:text>        // register for rendering on next frame, since there are updates
   867 </xsl:text>
   861 </xsl:text>
   868     <xsl:text>        window.requestAnimationFrame(animate);
   862     <xsl:text>        requestHMIAnimation();
   869 </xsl:text>
   863 </xsl:text>
   870     <xsl:text>    } catch(err) {
   864     <xsl:text>    } catch(err) {
   871 </xsl:text>
   865 </xsl:text>
   872     <xsl:text>        // 1003 is for "Unsupported Data"
   866     <xsl:text>        // 1003 is for "Unsupported Data"
   873 </xsl:text>
   867 </xsl:text>
  1113 </xsl:text>
  1107 </xsl:text>
  1114     <xsl:text>}
  1108     <xsl:text>}
  1115 </xsl:text>
  1109 </xsl:text>
  1116     <xsl:text>
  1110     <xsl:text>
  1117 </xsl:text>
  1111 </xsl:text>
  1118     <xsl:text>var current_page;
  1112     <xsl:text>var current_visible_page;
       
  1113 </xsl:text>
       
  1114     <xsl:text>var current_subscribed_page;
  1119 </xsl:text>
  1115 </xsl:text>
  1120     <xsl:text>
  1116     <xsl:text>
  1121 </xsl:text>
  1117 </xsl:text>
  1122     <xsl:text>function prepare_svg() {
  1118     <xsl:text>function prepare_svg() {
  1123 </xsl:text>
  1119 </xsl:text>
  1133 </xsl:text>
  1129 </xsl:text>
  1134     <xsl:text>
  1130     <xsl:text>
  1135 </xsl:text>
  1131 </xsl:text>
  1136     <xsl:text>function switch_page(page_name) {
  1132     <xsl:text>function switch_page(page_name) {
  1137 </xsl:text>
  1133 </xsl:text>
  1138     <xsl:text>    page_switch = page_name;
  1134     <xsl:text>    if(current_subscribed_page != current_visible_page){
  1139 </xsl:text>
  1135 </xsl:text>
  1140     <xsl:text>    window.requestAnimationFrame(animate);
  1136     <xsl:text>        /* page switch already going */
       
  1137 </xsl:text>
       
  1138     <xsl:text>        /* TODO LOG ERROR */
       
  1139 </xsl:text>
       
  1140     <xsl:text>        return;
       
  1141 </xsl:text>
       
  1142     <xsl:text>    } else if(page_name == current_visible_page){
       
  1143 </xsl:text>
       
  1144     <xsl:text>        /* already in that page */
       
  1145 </xsl:text>
       
  1146     <xsl:text>        /* TODO LOG ERROR */
       
  1147 </xsl:text>
       
  1148     <xsl:text>        return;
       
  1149 </xsl:text>
       
  1150     <xsl:text>    }
       
  1151 </xsl:text>
       
  1152     <xsl:text>    switch_subscribed_page(page_name);
       
  1153 </xsl:text>
       
  1154     <xsl:text>};
       
  1155 </xsl:text>
       
  1156     <xsl:text>
       
  1157 </xsl:text>
       
  1158     <xsl:text>function switch_subscribed_page(page_name) {
       
  1159 </xsl:text>
       
  1160     <xsl:text>    let old_desc = page_desc[current_subscribed_page];
       
  1161 </xsl:text>
       
  1162     <xsl:text>    let new_desc = page_desc[page_name];
       
  1163 </xsl:text>
       
  1164     <xsl:text>
       
  1165 </xsl:text>
       
  1166     <xsl:text>    if(new_desc == undefined){
       
  1167 </xsl:text>
       
  1168     <xsl:text>        /* TODO LOG ERROR */
       
  1169 </xsl:text>
       
  1170     <xsl:text>        return;
       
  1171 </xsl:text>
       
  1172     <xsl:text>    }
       
  1173 </xsl:text>
       
  1174     <xsl:text>
       
  1175 </xsl:text>
       
  1176     <xsl:text>    if(old_desc){
       
  1177 </xsl:text>
       
  1178     <xsl:text>        for(let widget of old_desc.widgets){
       
  1179 </xsl:text>
       
  1180     <xsl:text>            /* remove subsribers */
       
  1181 </xsl:text>
       
  1182     <xsl:text>            for(let index of widget.indexes){
       
  1183 </xsl:text>
       
  1184     <xsl:text>                subscribers[index].delete(widget);
       
  1185 </xsl:text>
       
  1186     <xsl:text>            }
       
  1187 </xsl:text>
       
  1188     <xsl:text>        }
       
  1189 </xsl:text>
       
  1190     <xsl:text>    }
       
  1191 </xsl:text>
       
  1192     <xsl:text>    for(let widget of new_desc.widgets){
       
  1193 </xsl:text>
       
  1194     <xsl:text>        /* add widget's subsribers */
       
  1195 </xsl:text>
       
  1196     <xsl:text>        for(let index of widget.indexes){
       
  1197 </xsl:text>
       
  1198     <xsl:text>            subscribers[index].add(widget);
       
  1199 </xsl:text>
       
  1200     <xsl:text>        }
       
  1201 </xsl:text>
       
  1202     <xsl:text>    }
       
  1203 </xsl:text>
       
  1204     <xsl:text>
       
  1205 </xsl:text>
       
  1206     <xsl:text>    update_subscriptions();
       
  1207 </xsl:text>
       
  1208     <xsl:text>
       
  1209 </xsl:text>
       
  1210     <xsl:text>    current_subscribed_page = page_name;
       
  1211 </xsl:text>
       
  1212     <xsl:text>
       
  1213 </xsl:text>
       
  1214     <xsl:text>    requestHMIAnimation();
  1141 </xsl:text>
  1215 </xsl:text>
  1142     <xsl:text>}
  1216     <xsl:text>}
  1143 </xsl:text>
  1217 </xsl:text>
  1144     <xsl:text>
  1218     <xsl:text>
  1145 </xsl:text>
  1219 </xsl:text>
  1146     <xsl:text>function do_switch_page(page_name) {
  1220     <xsl:text>function switch_visible_page(page_name) {
  1147 </xsl:text>
  1221 </xsl:text>
  1148     <xsl:text>    let old_desc = page_desc[current_page];
  1222     <xsl:text>
       
  1223 </xsl:text>
       
  1224     <xsl:text>    let old_desc = page_desc[current_visible_page];
  1149 </xsl:text>
  1225 </xsl:text>
  1150     <xsl:text>    let new_desc = page_desc[page_name];
  1226     <xsl:text>    let new_desc = page_desc[page_name];
  1151 </xsl:text>
  1227 </xsl:text>
  1152     <xsl:text>
  1228     <xsl:text>
  1153 </xsl:text>
  1229 </xsl:text>
  1154     <xsl:text>    if(new_desc == undefined){
       
  1155 </xsl:text>
       
  1156     <xsl:text>        /* TODO LOG ERROR */
       
  1157 </xsl:text>
       
  1158     <xsl:text>        return;
       
  1159 </xsl:text>
       
  1160     <xsl:text>    }
       
  1161 </xsl:text>
       
  1162     <xsl:text>
       
  1163 </xsl:text>
       
  1164     <xsl:text>    if(old_desc){
  1230     <xsl:text>    if(old_desc){
  1165 </xsl:text>
  1231 </xsl:text>
  1166     <xsl:text>        for(let widget of old_desc.widgets){
  1232     <xsl:text>        for(let eltid in old_desc.required_detachables){
  1167 </xsl:text>
  1233 </xsl:text>
  1168     <xsl:text>            /* remove subsribers */
  1234     <xsl:text>            if(!(eltid in new_desc.required_detachables)){
  1169 </xsl:text>
  1235 </xsl:text>
  1170     <xsl:text>            for(let index of widget.indexes){
  1236     <xsl:text>                let [element, parent] = old_desc.required_detachables[eltid];
  1171 </xsl:text>
  1237 </xsl:text>
  1172     <xsl:text>                subscribers[index].delete(widget);
  1238     <xsl:text>                parent.removeChild(element);
  1173 </xsl:text>
  1239 </xsl:text>
  1174     <xsl:text>            }
  1240     <xsl:text>            }
  1175 </xsl:text>
  1241 </xsl:text>
  1176     <xsl:text>        }
  1242     <xsl:text>        }
  1177 </xsl:text>
  1243 </xsl:text>
  1178     <xsl:text>        for(let eltid in old_desc.required_detachables){
  1244     <xsl:text>        for(let eltid in new_desc.required_detachables){
  1179 </xsl:text>
  1245 </xsl:text>
  1180     <xsl:text>            if(!(eltid in new_desc.required_detachables)){
  1246     <xsl:text>            if(!(eltid in old_desc.required_detachables)){
  1181 </xsl:text>
  1247 </xsl:text>
  1182     <xsl:text>                let [element, parent] = old_desc.required_detachables[eltid];
  1248     <xsl:text>                let [element, parent] = new_desc.required_detachables[eltid];
  1183 </xsl:text>
  1249 </xsl:text>
  1184     <xsl:text>                parent.removeChild(element);
  1250     <xsl:text>                parent.appendChild(element);
  1185 </xsl:text>
  1251 </xsl:text>
  1186     <xsl:text>            }
  1252     <xsl:text>            }
  1187 </xsl:text>
  1253 </xsl:text>
  1188     <xsl:text>        }
  1254     <xsl:text>        }
  1189 </xsl:text>
  1255 </xsl:text>
       
  1256     <xsl:text>    }else{
       
  1257 </xsl:text>
  1190     <xsl:text>        for(let eltid in new_desc.required_detachables){
  1258     <xsl:text>        for(let eltid in new_desc.required_detachables){
  1191 </xsl:text>
  1259 </xsl:text>
  1192     <xsl:text>            if(!(eltid in old_desc.required_detachables)){
  1260     <xsl:text>            let [element, parent] = new_desc.required_detachables[eltid];
  1193 </xsl:text>
  1261 </xsl:text>
  1194     <xsl:text>                let [element, parent] = new_desc.required_detachables[eltid];
  1262     <xsl:text>            parent.appendChild(element);
  1195 </xsl:text>
       
  1196     <xsl:text>                parent.appendChild(element);
       
  1197 </xsl:text>
       
  1198     <xsl:text>            }
       
  1199 </xsl:text>
  1263 </xsl:text>
  1200     <xsl:text>        }
  1264     <xsl:text>        }
  1201 </xsl:text>
  1265 </xsl:text>
  1202     <xsl:text>    }else{
  1266     <xsl:text>    }
  1203 </xsl:text>
  1267 </xsl:text>
  1204     <xsl:text>        for(let eltid in new_desc.required_detachables){
  1268     <xsl:text>
  1205 </xsl:text>
  1269 </xsl:text>
  1206     <xsl:text>            let [element, parent] = new_desc.required_detachables[eltid];
  1270     <xsl:text>    for(let widget of new_desc.widgets){
  1207 </xsl:text>
  1271 </xsl:text>
  1208     <xsl:text>            parent.appendChild(element);
  1272     <xsl:text>        for(let index of widget.indexes){
       
  1273 </xsl:text>
       
  1274     <xsl:text>            /* dispatch current cache in newly opened page widgets */
       
  1275 </xsl:text>
       
  1276     <xsl:text>            let cached_val = cache[index];
       
  1277 </xsl:text>
       
  1278     <xsl:text>            if(cached_val != undefined)
       
  1279 </xsl:text>
       
  1280     <xsl:text>                dispatch_value_to_widget(widget, index, cached_val, cached_val);
  1209 </xsl:text>
  1281 </xsl:text>
  1210     <xsl:text>        }
  1282     <xsl:text>        }
  1211 </xsl:text>
  1283 </xsl:text>
  1212     <xsl:text>    }
  1284     <xsl:text>    }
  1213 </xsl:text>
  1285 </xsl:text>
  1214     <xsl:text>
  1286     <xsl:text>
  1215 </xsl:text>
  1287 </xsl:text>
  1216     <xsl:text>    for(let widget of new_desc.widgets){
       
  1217 </xsl:text>
       
  1218     <xsl:text>        /* add widget's subsribers */
       
  1219 </xsl:text>
       
  1220     <xsl:text>        for(let index of widget.indexes){
       
  1221 </xsl:text>
       
  1222     <xsl:text>            subscribers[index].add(widget);
       
  1223 </xsl:text>
       
  1224     <xsl:text>            /* dispatch current cache in newly opened page widgets */
       
  1225 </xsl:text>
       
  1226     <xsl:text>            let cached_val = cache[index];
       
  1227 </xsl:text>
       
  1228     <xsl:text>            if(cached_val != undefined)
       
  1229 </xsl:text>
       
  1230     <xsl:text>                dispatch_value_to_widget(widget, index, cached_val, cached_val);
       
  1231 </xsl:text>
       
  1232     <xsl:text>        }
       
  1233 </xsl:text>
       
  1234     <xsl:text>    }
       
  1235 </xsl:text>
       
  1236     <xsl:text>
       
  1237 </xsl:text>
       
  1238     <xsl:text>    svg_root.setAttribute('viewBox',new_desc.bbox.join(" "));
  1288     <xsl:text>    svg_root.setAttribute('viewBox',new_desc.bbox.join(" "));
  1239 </xsl:text>
  1289 </xsl:text>
  1240     <xsl:text>    current_page = page_name;
  1290     <xsl:text>    current_visible_page = page_name;
  1241 </xsl:text>
       
  1242     <xsl:text>
       
  1243 </xsl:text>
       
  1244     <xsl:text>    window.setTimeout(update_subscriptions,0);
       
  1245 </xsl:text>
  1291 </xsl:text>
  1246     <xsl:text>};
  1292     <xsl:text>};
  1247 </xsl:text>
  1293 </xsl:text>
  1248     <xsl:text>
  1294     <xsl:text>
  1249 </xsl:text>
  1295 </xsl:text>