changeset 389:45e04408fc19

Implement stub functions for the MadSwatter integration.
author wycc
date Sun, 12 Apr 2009 11:58:53 +0800
parents f3e6ac47752c
children 3c3de5520e37
files inkscape/firefox/content/inkscape.js inkscape/firefox/content/madbuilder.html inkscape/firefox/content/madswatter.js inkscape/firefox/content/main.js
diffstat 4 files changed, 190 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/inkscape/firefox/content/inkscape.js	Fri Apr 10 22:46:01 2009 +0800
+++ b/inkscape/firefox/content/inkscape.js	Sun Apr 12 11:58:53 2009 +0800
@@ -9,6 +9,17 @@
 	return reg.test(str);
 }
 
+function dumpXML(xml)
+{
+	return (new XMLSerializer()).serializeToString(xml);
+}
+
+
+function showInWindow(content)
+{
+	$('#debug').append("<pre>"+content+"</pre>");
+}
+
 function dumpObj(obj, name, indent, depth) {
       if (depth > MAX_DUMP_DEPTH) {
              return indent + name + ": <Maximum Depth Reached>\n";
@@ -84,6 +95,7 @@
 	ink.innerHTML = "<embed src="+file+" width=900 height=700 />";
 	this.isInProgress = 0;
 	this.callback = null;
+	this.animation = new MadSwatter(this);
 
 	setTimeout("inkscape.fetchDocument()",4000);
 }
@@ -123,6 +135,7 @@
 {
 	mbsvg = new MBSVGString(resp.Body[0].GETDOCResponse[0].Result[0].Text);
 	mbsvg.renderUI();
+	this.mbsvg = mbsvg;
 	if (this.callback)
 		this.callback(mbsvg);
 
@@ -286,6 +299,35 @@
 	$('#newsymbolname').val(val);
 }
 
+Inkscape.prototype.editAnimation=function () {
+	inkscape.fetchDocument(inkscape.editAnimationCallback);
+}
+
+Inkscape.prototype.editAnimationCallback=function(mbsvg) {
+
+	inkscape.animation.edit(mbsvg);
+	return;
+
+
+	var sodi = mbsvg.getElementsByTag('sodipodi:namedview')[0];	
+
+	var layer=sodi.getAttribute('inkscape:current-layer');
+	var animation = mbsvg.getElementsByTag('animationlist')[0];
+	var alist = animation.getElementsByTag('animation');
+	var len = alist.length;
+	var dialog = $('animation');
+	dialog.dialog('open');
+	var html = new Array();
+	html.append('<ul>');
+	for(i=0;i<alist.len;i++) {
+		html.append('<li><a href="#" onClick="">'+alist[i].getAttribute('name')+"</a></li>");
+	}
+	html.append('</ul>');
+	$('animation_list').html(html.join("\n"));
+	dialog.show();
+}
+
+
 Inkscape.prototype.loadSymbolScreen=function (mbsvg) {
 	// Swap the left side to be the SVG element tree.
 	var i,l;
@@ -352,6 +394,8 @@
 
 function MBSVG_loadFromDoc(self,xmlDoc)
 {
+	var top = xmlDoc.getElementsByTagNameNS("http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd","scenes")[0];
+	self.current = top.getAttribute("current");
 	var scenesNode = xmlDoc.getElementsByTagNameNS("http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd","scene");
 	if (scenesNode == null) {
 		alert('This is not a valid scene file');
@@ -465,6 +509,65 @@
 
 }
 
+
+/**
+ *   Return a new XML document that all objects which is not in the current scene are deleted.
+ *   
+ *   This function will traverse all scenes. For each scene which is not in the current scene, we will delete the reference group.
+ */
+
+function deepcopy(obj)
+{
+   var seenObjects = [];
+   var mappingArray = [];
+   var	f = function(simpleObject) {
+      var indexOf = seenObjects.indexOf(simpleObject);
+      if (indexOf == -1) {			
+         switch (Ext.type(simpleObject)) {
+            case 'object':
+               seenObjects.push(simpleObject);
+               var newObject = {};
+               mappingArray.push(newObject);
+               for (var p in simpleObject) 
+                  newObject[p] = f(simpleObject[p]);
+               newObject.constructor = simpleObject.constructor;				
+            return newObject;
+ 
+            case 'array':
+               seenObjects.push(simpleObject);
+               var newArray = [];
+               mappingArray.push(newArray);
+               for(var i=0,len=simpleObject.length; i<len; i++)
+                  newArray.push(f(simpleObject[i]));
+            return newArray;
+ 
+            default:	
+            return simpleObject;
+         }
+      } else {
+         return mappingArray[indexOf];
+      }
+   };
+   return f(obj);		
+}
+
+MBSVG.prototype.generateCurrentSVG=function()
+{
+	var i;
+	var scenes = this.scenes;
+	var len = scenes.length;
+	var newcopy = $(this.doc).clone();
+
+	for(i=0;i<len;i++) {
+		if (scenes[i].start > this.current || scenes[i].end < this.current) {
+			var obj = newcopy.find('#'+scenes[i].ref);
+			obj.remove();
+		}
+	}
+	return newcopy;
+}
+
+
 /**
  *    UI for madbuilder.html to build the scene editor
  */
@@ -521,6 +624,19 @@
 			project_run();
 		} else {
 		}
+	} else if (id == 'Open') {
+		filedialog = jQuery('#filedialog');
+		filedialog.dialog({width:500,
+			   modal: true,
+		           autoOpen:false,
+			   title:'Please select a file'});
+		filedialog.show();
+		filedialog.html('Please select the project file<br>');
+		filedialog.append('<input type=file value="Select the project file" id="mbsvg" accept="image/png">');
+		filedialog.append('<input type=button value="Load" onclick="project_loadFile()">');
+		filedialog.dialog("open");
+	} else if (id == 'EditAnimation') {
+		inkscape.editAnimation();
 	} else {
 		alert(id+' has not been implemented yet');
 	}
@@ -930,6 +1046,7 @@
 
 function loadOldProject()
 {
+	return -1;
 	var f = system_open_read("/tmp/madbuilder.ws");
 	if (f == null) return -1;
 	var s = f.read(f.available());
@@ -948,26 +1065,3 @@
 	
 }
 
-var last_select = null;
-var wizard = new Wizard();
-wizard.cb = onLoadProject;
-$('#filedialog').dialog({ width:500});
-jQuery(document).ready(function() {
-		if (loadOldProject()) {
-			filedialog = jQuery('#filedialog');
-			filedialog.dialog({width:500,
-				   modal: true,
-			           autoOpen:false,
-				   title:'Please select a file'});
-			filedialog.show();
-			filedialog.html('Please select the project file<br>');
-			filedialog.append('<input type=file value="Select the project file" id="mbsvg" accept="image/png">');
-			filedialog.append('<input type=button value="Load" onclick="project_loadFile()">');
-			filedialog.dialog("open");
-		}
-		});
-
-$('#frame').draggable();
-$('#btns').draggable({cursor:'crosshair'});
-$('#list').tabs();
-$('#display').tabs();
--- a/inkscape/firefox/content/madbuilder.html	Fri Apr 10 22:46:01 2009 +0800
+++ b/inkscape/firefox/content/madbuilder.html	Sun Apr 12 11:58:53 2009 +0800
@@ -10,6 +10,9 @@
 	<script type="text/javascript" src="jquery-ui-1.7.custom.min.js"></script>
 	<script type="text/javascript" src="jquery.simplemodal-1.2.3.pack.js"></script>
 	<script type="text/javascript" src="wizard.js"></script>
+	<script type="text/javascript" src="madswatter.js"></script>
+	<script type="text/javascript" src="inkscape.js"></script>
+	<script type="text/javascript" src="main.js" ></script>
 
 	<style type="text/css"> 
 		.normal {
@@ -47,7 +50,10 @@
 		    	padding: 6px 0 4px 18px; /* push text down 1px */
 		} 
 		.filepanel {
-			height:700px
+			height:700px;
+		}
+		.tab {
+			font-size: 20px;
 		}
 	</style>
 </head>
@@ -67,32 +73,37 @@
 	<a class='button' href='#'> <span id='Test' onClick='onButtonClick(this)'>Test</span></a>
 	<a class='button' href='#'> <span id='Save' onClick='onButtonClick(this)'>Save</span></a>
 	<a class='button' href='#'> <span id='Wizard' onClick='wizard.execute()'>Wizard</span></a>
+	<a class='button' href='#'> <span id='Open' onClick='onButtonClick(this)'>Open</span></a>
 	<br/>
 	<br/>
 </div>
 
 <table><tr>
 <td valign='top'>	
-	<div width='200' height='700' id='list'>
+<div width='200' height='700' id='list'>
 	<ul>
-		<li><a href='#filelist'>Project</a></li>
-		<li><a href='#sourcelist'>Source list</a></li>
+		<li><a class='tab' href='#filelist'>Project</a></li>
+		<li><a class='tab' href='#sourcelist'>Source list</a></li>
+		<li><a class='tab' href='#debug' valign='top'>Debug</a></li>
 	</ul>
-<span class='filepanel' height='600' id='filelist' valign='top'/>
-<span class='filepanel' id='sourcelist' valign=top/>
+<div class='filepanel' id='filelist'></div>
+<div class='filepanel' id='sourcelist'></div>
+<div class='filepanel' id='debug'></div>
 </div>
 </td>
 <td valign='top' width='900'>
 <div id='display'>
 	<ul>
-		<li><a href='#inkscape'>MBSVG</a></li>
-		<li><a href='#editor'>Editor</a></li>
-		<li><a href='#compiler'>Compiler</a></li>
-		<li><a href='#debugger'>Debugger</a></li>
+		<li><a class='tab' href='#inkscape'>MBSVG</a></li>
+		<li><a class='tab' href='#editor'>Editor</a></li>
+		<li><a class='tab' href='#madswatter'>Animation</a></li>
+		<li><a class='tab' href='#compiler'>Compiler</a></li>
+		<li><a class='tab' href='#debugger'>Debugger</a></li>
 	</ul>
 <div>
 <div class='filepanel' id='inkscape'></div>
 <div class='filepanel' id='editor'></div>
+<div class='filepanel' id='madswatter'></div>
 <div class='filepanel' id='compiler'></div>
 <div class='filepanel' id='debugger'></div>
 </div>
@@ -127,7 +138,5 @@
 
 <div id='symboldialog' />
 
-<script type="text/javascript" src="inkscape.js" >
-</script>
 </body>
 </html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inkscape/firefox/content/madswatter.js	Sun Apr 12 11:58:53 2009 +0800
@@ -0,0 +1,27 @@
+asdasd=1;
+function MadSwatter(inkscape)
+{
+	this.inkscape = inkscape;
+}
+
+
+function MadSwatter_callback(mbsvg,self)
+{
+
+	$(self.inkscape.mbsvg.doc).find("channels").replaceWith(mbsvg.find("channels"));
+	$('#display').tabs('select',0);
+	//self.inkscape.updateDocument();
+}
+
+MadSwatter.prototype.edit=function()
+{
+	// Generate a new document with the current scene
+	// FIXME: Do we need to do animation filter here?
+	// FIXME: Do we need to support hiearchical animation?
+	$('#display').tabs('select',2);
+	var kk = this.inkscape.mbsvg.generateCurrentSVG();
+	//MadSwatter_invoke(kk,MadSwatter_callback,this);
+	// Simulate the MadSwatter
+	kk.find("metadata").append("<channels></channels>");
+	setTimeout(function () { MadSwatter_callback(kk,this);}, 3000);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inkscape/firefox/content/main.js	Sun Apr 12 11:58:53 2009 +0800
@@ -0,0 +1,25 @@
+var last_select;
+var wizard;
+jQuery(document).ready(function() {
+		if (loadOldProject()) {
+			filedialog = jQuery('#filedialog');
+			filedialog.dialog({width:500,
+				   modal: true,
+			           autoOpen:false,
+				   title:'Please select a file'});
+			filedialog.show();
+			filedialog.html('Please select the project file<br>');
+			filedialog.append('<input type=file value="Select the project file" id="mbsvg" accept="image/png">');
+			filedialog.append('<input type=button value="Load" onclick="project_loadFile()">');
+			filedialog.dialog("open");
+			last_select = null;
+			wizard = new Wizard();
+			wizard.cb = onLoadProject;
+			$('#filedialog').dialog({ width:500});
+			$('#frame').draggable();
+			$('#btns').draggable({cursor:'crosshair'});
+			$('#list').tabs();
+			$('#display').tabs();
+		}
+		});
+