svgui/livesvg.js
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Sun, 06 Jan 2019 01:22:46 +0300
changeset 2499 68f4f2d4516b
parent 728 e0424e96e3fd
permissions -rw-r--r--
use pregenerated CRC32 lookup tables for retain on Win32 and GNU/Linux

This code could be possible reused on low-end targets with limited RAM.

code to generate lookup table:
[---------------------------------------------------------------------]

/* CRC lookup table and initial state. */
uint32_t crc32_table[256];

/* Generate CRC32 lookup table. */
void GenerateCRC32Table(void)
{
unsigned int i, j;
/* Use CRC-32-IEEE 802.3 polynomial 0x04C11DB7 (bit reflected). */
uint32_t poly = 0xEDB88320;

for (i = 0; i <= 0xFF; i++)
{
uint32_t c = i;
for (j = 0 ; j < 8 ; j++)
c = (c & 1) ? (c >> 1 ) ^ poly : (c >> 1);
crc32_table[i] = c;
}
}

void main(void)
{
GenerateCRC32Table();
int j=0;
for(int i=0; i<256; i++) {
printf("0x%08X, ", crc32_table[i]);
if (++j >= 8) {
j = 0;
printf("\n");
}
}
}
[---------------------------------------------------------------------]
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     1
// import Nevow.Athena
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     2
// import Divmod.Base
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     3
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     4
function updateAttr(id, param, value) {
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     5
  Nevow.Athena.Widget.fromAthenaID(1).callRemote('HMIexec', 'setattr', id, param, value);
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     6
}
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     7
381
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
     8
var svguiWidgets = new Array();
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     9
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    10
var currentObject = null;
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    11
function setCurrentObject(obj) {
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    12
	currentObject = obj;
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    13
}
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    14
function isCurrentObject(obj) {
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    15
	return currentObject == obj;
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    16
}
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    17
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    18
function getSVGElementById(id) {
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    19
	return document.getElementById(id);
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    20
}
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    21
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    22
function blockSVGElementDrag(element) {
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    23
	element.addEventListener("draggesture", function(event){event.stopPropagation()}, true);
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    24
}
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    25
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    26
LiveSVGPage.LiveSVGWidget = Nevow.Athena.Widget.subclass('LiveSVGPage.LiveSVGWidget');
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    27
LiveSVGPage.LiveSVGWidget.methods(
381
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    28
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    29
    function handleEvent(self, evt) {
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    30
        if (currentObject != null) {
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    31
            currentObject.handleEvent(evt);
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    32
        }
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    33
    },
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    34
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    35
    function receiveData(self, data){
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    36
        dataReceived = json_parse(data);
381
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    37
        gadget = svguiWidgets[dataReceived.id]
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    38
        if (gadget) {
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    39
        	gadget.updateValues(json_parse(dataReceived.kwargs));
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    40
        }
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    41
        //console.log("OBJET : " + dataReceived.back_id + " STATE : " + newState);
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    42
    },
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    43
    
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    44
    function init(self, arg1){
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    45
        //console.log("Object received : " + arg1);
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    46
        for (ind in arg1) {
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    47
            gad = json_parse(arg1[ind]);
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    48
            args = json_parse(gad.kwargs);
381
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    49
            gadget = new svguilib[gad.__class__](self, gad.id, args);
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    50
            svguiWidgets[gadget.id]=gadget;
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    51
            //console.log('GADGET :' + gadget);
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    52
        }
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    53
        var elements = document.getElementsByTagName("svg");
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    54
        for (var i = 0; i < elements.length; i++) {
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    55
        	elements[i].addEventListener("mouseup", self, false);
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    56
        }
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    57
        //console.log("SVGUIWIDGETS : " + svguiWidgets);
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    58
    }
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    59
);