|
From: <tre...@us...> - 2007-10-19 22:09:23
|
Revision: 520
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=520&view=rev
Author: trevorolio
Date: 2007-10-19 15:09:27 -0700 (Fri, 19 Oct 2007)
Log Message:
-----------
Fixed up the chairs so that they are populated as seats with reasonable seat positioning.
This required an addition of a template.properties file to template population dirs.
Tweaked template editor html to handle seat position editing keystrokes a little better.
Modified Paths:
--------------
maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/PopulateMojo.java
Modified: maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/PopulateMojo.java
===================================================================
--- maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/PopulateMojo.java 2007-10-19 22:09:21 UTC (rev 519)
+++ maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/PopulateMojo.java 2007-10-19 22:09:27 UTC (rev 520)
@@ -12,7 +12,12 @@
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
+import java.util.Properties;
+import javax.media.j3d.Transform3D;
+import javax.vecmath.Quat4d;
+import javax.vecmath.Vector3d;
+
import nanoxml.XMLElement;
import org.apache.maven.plugin.MojoExecutionException;
@@ -31,11 +36,14 @@
* @goal populate
*/
public class PopulateMojo extends OgServiceMojoBase {
+ public static final String PROPERTIES_FILE_NAME = "template.properties";
+
private Map<Long, Long> templateIdMap = new HashMap<Long, Long>();
- private Map<Long,SpaceDocument> localSpaces = new HashMap<Long,SpaceDocument>();
- private Map<String,SpaceDocument> serveSpacerNameToSpaceDoc = new HashMap<String, SpaceDocument>();
+ private Map<Long, SpaceDocument> localSpaces = new HashMap<Long, SpaceDocument>();
+ private Map<String, SpaceDocument> serveSpacerNameToSpaceDoc = new HashMap<String, SpaceDocument>();
+
private Map<String, TemplateDocument> existingServerTemplates = null;
public static final DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, Locale.US);
@@ -66,20 +74,20 @@
}
}
}
- serveSpacerNameToSpaceDoc=getAllServerSpaces(client);
+ serveSpacerNameToSpaceDoc = getAllServerSpaces(client);
patchSpaces(client);
}
- private Map<String,SpaceDocument> getAllServerSpaces(WebAPIClient client) throws MojoExecutionException{
+ private Map<String, SpaceDocument> getAllServerSpaces(WebAPIClient client) throws MojoExecutionException {
try {
- Map<String,SpaceDocument> result=new HashMap<String,SpaceDocument>();
- SpaceDocument[] doc=client.getAccountSpaceDocuments(username);
- for (int i=0; i<doc.length;++i) {
- result.put(doc[i].getDisplayName(),doc[i]);
+ Map<String, SpaceDocument> result = new HashMap<String, SpaceDocument>();
+ SpaceDocument[] doc = client.getAccountSpaceDocuments(username);
+ for (int i = 0; i < doc.length; ++i) {
+ result.put(doc[i].getDisplayName(), doc[i]);
}
return result;
} catch (IOException e) {
- throw new MojoExecutionException("Unable to read server set of space documents",e);
+ throw new MojoExecutionException("Unable to read server set of space documents", e);
}
}
@@ -87,7 +95,7 @@
Map<String, TemplateDocument> result = new HashMap<String, TemplateDocument>();
TemplateDocument[] doc = client.getTemplateDocuments(username);
- getLog().info("Checking existing server templates...total of:"+doc.length);
+ getLog().info("Checking existing server templates...total of:" + doc.length);
for (int i = 0; i < doc.length; ++i) {
result.put(doc[i].getDisplayName(), doc[i]);
}
@@ -96,24 +104,24 @@
private void patchSpaces(WebAPIClient client) throws MojoExecutionException {
SpaceDocument fakeSpaceDoc, realSpaceDoc;
- Iterator<Long> iter=localSpaces.keySet().iterator();
-
+ Iterator<Long> iter = localSpaces.keySet().iterator();
+
while (iter.hasNext()) {
try {
long localModTime = iter.next();
fakeSpaceDoc = localSpaces.get(localModTime);
if (serveSpacerNameToSpaceDoc.containsKey(fakeSpaceDoc.getDisplayName())) {
realSpaceDoc = serveSpacerNameToSpaceDoc.get(fakeSpaceDoc.getDisplayName());
-
- Date fileModified=new Date(localModTime);
+
+ Date fileModified = new Date(localModTime);
Date serverModified = TemplateSupportFileDocument.fmt.parse(realSpaceDoc.getLastModifiedAsUTC());
if (fileModified.before(serverModified)) {
- getLog().info("Not patching space document "+realSpaceDoc.getDisplayName()+". Server copy is newer.");
+ getLog().info("Not patching space document " + realSpaceDoc.getDisplayName() + ". Server copy is newer.");
continue;
} else {
//need to torch the server version b/c it's too old
client.deleteSpace(realSpaceDoc.getSpaceID());
- getLog().info("Deleted old server version of "+realSpaceDoc.getDisplayName()+" ["+realSpaceDoc.getSpaceID()+"]");
+ getLog().info("Deleted old server version of " + realSpaceDoc.getDisplayName() + " [" + realSpaceDoc.getSpaceID() + "]");
}
}
realSpaceDoc = client.createSpace(fakeSpaceDoc.getDisplayName());
@@ -149,7 +157,7 @@
client.createDoor(realSpaceID, doorDocs[j].getTemplateID(), doorDocs[j].getTemplateOwner(), doorDocs[j].getDisplayName(), doorDocs[j].getLink(), doorDocs[j].getTransform());
}
- getLog().info("Patched up space " + realSpaceDoc.getDisplayName() +" ["+realSpaceDoc.getSpaceID()+"]");
+ getLog().info("Patched up space " + realSpaceDoc.getDisplayName() + " [" + realSpaceDoc.getSpaceID() + "]");
} catch (ParseException e) {
throw new MojoExecutionException("Parse exception patching space", e);
} catch (IOException e) {
@@ -174,7 +182,7 @@
FileInputStream inputStream = new FileInputStream(candidate);
String docContent = StreamUtils.readInput(inputStream);
SpaceDocument doc = new SpaceDocument(XMLElement.parseElementFromString(docContent));
- localSpaces.put(candidate.lastModified(),doc);
+ localSpaces.put(candidate.lastModified(), doc);
inputStream.close();
} catch (IOException e) {
throw new MojoExecutionException("IO Error reading space", e);
@@ -195,10 +203,10 @@
throw new MojoExecutionException("Badly formed directory " + name + ". Should have 1 obj file but has " + objs.length);
}
- String templateVisibleName=fileToTemplateName(objs[0]);
+ String templateVisibleName = fileToTemplateName(objs[0]);
if (!checkFileTemplateIsNewer(client, candidate, existing, templateVisibleName)) {
getLog().info("Not uploading template " + templateVisibleName + ". Server copy is newer.");
- templateIdMap.put(templateFakeId,existing.get(templateVisibleName).getTemplateID());
+ templateIdMap.put(templateFakeId, existing.get(templateVisibleName).getTemplateID());
return;
} else {
getLog().info("Uploading template #" + templateFakeId + " to " + serviceURI);
@@ -207,6 +215,15 @@
try {
TemplateDocument doc = fileNameToTemplateDocument(client, objs[0]);
+ File propertiesFile = new File(candidate, PROPERTIES_FILE_NAME);
+ if (propertiesFile.exists() && propertiesFile.canRead()) {
+ Properties templateProperties = new Properties();
+ templateProperties.load(new FileInputStream(propertiesFile));
+ if (templateProperties.size() > 0) {
+ updateTemplateDoc(client, doc, templateProperties);
+ }
+ }
+
InputStream objStream = new FileInputStream(objs[0]);
client.uploadTemplateGeometryStream(username, doc.getTemplateID(), 0, objStream);
@@ -228,7 +245,7 @@
} else {
if ((!(supportName.endsWith(".gif"))) && (!(supportName.endsWith(".jpg"))) && (!(supportName.endsWith(".png"))) && (!(supportName.endsWith(".mtl")))) {
- if ((!(supportName.endsWith(".blend"))) && (!(supportName.endsWith(".3DS"))) && (!(supportName.endsWith(".txt"))) && (!(supportName.equals(".svn")))) {
+ if ((!(supportName.endsWith(".blend"))) && (!(supportName.endsWith(".3DS"))) && (!(supportName.endsWith(".txt"))) && (!(supportName.equals(".svn"))) && !supportName.equals(PROPERTIES_FILE_NAME)) {
getLog().warn("Don't know what to do with file " + supportName + ". Ignoring.");
}
continue;
@@ -244,6 +261,42 @@
}
}
+ private void updateTemplateDoc(WebAPIClient client, TemplateDocument doc, Properties templateProperties) throws IOException {
+ String[] keys = (String[])templateProperties.keySet().toArray(new String[0]);
+ double rotX = 0, rotY = 0, rotZ = 0;
+
+ for (int i = 0; i < keys.length; i++) {
+ if("seat".equals(keys[i])){
+ doc.setSeat("true".equals(templateProperties.get(keys[i])));
+ } else if("seatX".equals(keys[i])){
+ doc.setSeatPosition(Double.parseDouble((String)templateProperties.get(keys[i])), doc.getSeatPosition().y, doc.getSeatPosition().z);
+ } else if("seatY".equals(keys[i])){
+ doc.setSeatPosition(doc.getSeatPosition().x, Double.parseDouble((String)templateProperties.get(keys[i])), doc.getSeatPosition().z);
+ } else if("seatZ".equals(keys[i])){
+ doc.setSeatPosition(doc.getSeatPosition().x, doc.getSeatPosition().y, Double.parseDouble((String)templateProperties.get(keys[i])));
+ } else if("seatRotX".equals(keys[i])){
+ rotX = Double.parseDouble(templateProperties.getProperty(keys[i]));
+ } else if("seatRotY".equals(keys[i])){
+ rotY = Double.parseDouble(templateProperties.getProperty(keys[i]));
+ } else if("seatRotZ".equals(keys[i])){
+ rotZ = Double.parseDouble(templateProperties.getProperty(keys[i]));
+ } else {
+ System.err.println("Unknown properties in template.properties: " + keys[i]);
+ }
+ }
+
+ if(rotX != 0 || rotY != 0 || rotZ != 0){
+ Transform3D transform = new Transform3D();
+ transform.setEuler(new Vector3d(rotX, rotY, rotZ));
+ Quat4d quat = new Quat4d();
+ transform.get(quat);
+ doc.setSeatRotation(quat);
+ }
+
+ getLog().info("Updating template " + doc.getDisplayName() + " with properties from template.properties");
+ client.updateTemplate(doc);
+ }
+
private boolean checkFileTemplateIsNewer(WebAPIClient client, File candidate, Map<String, TemplateDocument> existing, String displayName) throws MojoExecutionException {
//is it even on server?
if (!existing.containsKey(displayName)) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|