GeomConverter/src/org/lcsim/material
diff -u -r1.15.2.1 -r1.15.2.2
--- XMLMaterialManager.java 5 Oct 2005 21:58:09 -0000 1.15.2.1
+++ XMLMaterialManager.java 6 Oct 2005 00:20:50 -0000 1.15.2.2
@@ -5,7 +5,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
-import java.util.ArrayList;
+import java.util.ArrayList;sys
import java.util.LinkedHashMap;
import java.util.Iterator;
import org.jdom.Document;
@@ -28,10 +28,7 @@
private static final String elementResource = "elements.xml";
/** Location of materials resource. */
- private static final String materialResource = "materials.xml";
-
- /** Default fill material. */
- private static final String defaultMaterialName = "Air";
+ private static final String materialResource = "materials.xml";
/** Static instance containing elements data. */
static private XMLMaterialManager elements = new XMLMaterialManager(true);
@@ -273,20 +270,13 @@
if (materialMap.get(e.getAttributeValue("name")) == null )
{
- //System.out.println("add material: " + e.getAttributeValue("name"));
materialMap.put(e.getAttributeValue("name"), e);
}
- //else
- //
- // System.out.println("ignoring dup mat: " + e.getAttributeValue("name"));
- //}
}
/** Add an element to the map. */
private void addElement(org.jdom.Element e) throws JDOMException
- {
- //System.out.println("add element: " + e.getAttributeValue("name"));
-
+ {
if ( e.getName() != "element")
{
throw new JDOMException("Element is not named element.");
@@ -296,10 +286,8 @@
}
/** Find a material in the map. */
- public org.jdom.Element getMaterial(String matName)
- {
- //System.out.println("lkp mat: " + matName);
-
+ protected org.jdom.Element getMaterial(String matName)
+ {
org.jdom.Element m = materialMap.get(matName);
if ( m == null )
@@ -309,22 +297,13 @@
//System.out.println("par lkp");
m = parent.getMaterial(matName);
}
- //else
- //{
- // System.out.println("no parent");
- //}
- }
-
- //if ( m != null )
- //{
- // System.out.println("fnd mat: " + matName);
- //}
+ }
return m;
}
/** Find an element in the map. */
- public org.jdom.Element getElement(String elemName)
+ private org.jdom.Element getElement(String elemName)
{
org.jdom.Element e = elementMap.get(elemName);
@@ -340,7 +319,7 @@
}
/** Find an element in the current document without affecting the map. */
- public org.jdom.Element findElementInDocument(String elemName, Document d) throws JDOMException
+ private org.jdom.Element findElementInDocument(String elemName, Document d) throws JDOMException
{
org.jdom.Element me = getMaterialsRoot(d);
org.jdom.Element fnd = null;
@@ -363,13 +342,13 @@
return fnd;
}
- public org.jdom.Element findElementInDocument(String elemName) throws JDOMException
+ private org.jdom.Element findElementInDocument(String elemName) throws JDOMException
{
return findElementInDocument(elemName, currentDoc);
}
/** Find a material in the current document without affecting the map. */
- public org.jdom.Element findMaterialInDocument(String matName, Document d) throws JDOMException
+ private org.jdom.Element findMaterialInDocument(String matName, Document d) throws JDOMException
{
org.jdom.Element me = getMaterialsRoot(d);
@@ -393,7 +372,7 @@
return fnd;
}
- public org.jdom.Element findMaterialInDocument(String matName) throws JDOMException
+ private org.jdom.Element findMaterialInDocument(String matName) throws JDOMException
{
return findMaterialInDocument(matName, currentDoc);
}
@@ -421,53 +400,31 @@
private void loadFromDocument(Document d) throws JDOMException
{
org.jdom.Element root = getMaterialsRoot(d);
-
- /* DEBUG: track number of materials and elements read. */
- //int mcount, ecount;
- //mcount = ecount = 0;
-
+
for ( org.jdom.Element e : (List<org.jdom.Element>) root.getChildren() )
{
String elemName = e.getName();
if ("material".equals(elemName))
{
- addMaterial(e);
-
- /* DEBUG: print materials read and track count. */
- //System.out.println("read material: " + e.getAttributeValue("name") );
- //++ecount;
+ addMaterial(e);
}
else if ("element".equals(elemName))
{
addElement(e);
-
- /* DEBUG: print elements read and track count. */
- //System.out.println("read element: " + e.getAttributeValue("name") );
- //++mcount;
}
else
{
System.err.println("WARNING - Unknown tag in materials block: " + elemName);
}
}
- //if ( mcount == 0 && ecount == 0)
- //{
- // System.err.println("WARNING - No materials or elements found in document: " + d.getBaseURI() );
- //}
- //else
- //{
- // System.out.println("materials read: " + mcount);
- // System.out.println("elements read: " + ecount);
- //}
}
/**
* Recursively add the referenced materials or elements from a single material node.
- * It will also automatically look in the parent.
+ * It will also automatically look in the parent XMLMaterialManager.
*/
private void addReferences(org.jdom.Element e, Document d) throws JDOMException
{
-// System.out.println("XMLMaterialManager.addReferences() - adding refs for " + e.getAttributeValue("name"));
if ( e != null )
{
if ( "material".equals(e.getName()))
@@ -503,10 +460,7 @@
if ( fnd != null )
{
/* Recursively add references of this material. */
-// System.out.println("adding dep - " + fnd.getAttributeValue("name"));
addReferences(fnd, d);
-
-// addMaterial(fnd);
}
else
{
@@ -515,8 +469,7 @@
}
}
- /* Lastly, add the material that was passed in after its references recursively resolved. */
-// System.out.println("adding material - " + e.getAttributeValue("name"));
+ /* Lastly, add the material that was passed in, after its references were resolved (recursively). */
addMaterial(e);
}
}
@@ -566,7 +519,6 @@
{
if ( !refs.contains(fnd))
{
- //System.out.println("add elem ref: " + ref);
refs.add(fnd);
}
}
@@ -586,7 +538,6 @@
/* Lastly, add the material that was passed in after its references are recursively resolved. */
if ( !refs.contains(m))
{
- //System.out.println("add mat ref: " + m.getAttributeValue("name"));
refs.add(m);
}
}
@@ -624,7 +575,7 @@
}
/** Copy all elements into LCDD. */
- public void copyElementsToLCDD(LCDD lcdd)
+ private void copyElementsToLCDD(LCDD lcdd)
{
for (Object o : getElementMap().values() )
{
@@ -634,20 +585,18 @@
}
/** Copy all materials into LCDD. */
- public void copyMaterialsToLCDD(LCDD lcdd) throws JDOMException
+ private void copyMaterialsToLCDD(LCDD lcdd) throws JDOMException
{
for (Object o : getMaterialMap().values() )
{
- org.jdom.Element e = (org.jdom.Element) o;
-
- //System.out.println ("mat " + e.getAttributeValue("name") + " -> LCDD");
+ org.jdom.Element e = (org.jdom.Element) o;
Material m = makeLCDDMaterial(e);
lcdd.addMaterial(m);
}
}
- public static Material makeLCDDMaterial(org.jdom.Element m) throws JDOMException
+ private static Material makeLCDDMaterial(org.jdom.Element m) throws JDOMException
{
if ( m.getName() != "material")
{
@@ -659,7 +608,7 @@
return mat;
}
- public static org.jdom.Element makeLCDDElement(org.jdom.Element e) throws JDOMException
+ private static org.jdom.Element makeLCDDElement(org.jdom.Element e) throws JDOMException
{
if (e.getName() != "element")
{
@@ -675,9 +624,7 @@
}
public void resolveLCDDMaterialReference(String name, LCDD lcdd) throws JDOMException
- {
- //System.out.println("lazy lkp for LCDD: " + name);
-
+ {
List l = new ArrayList();
makeReferenceList(name, l);
@@ -685,18 +632,17 @@
for (Object o : l)
{
org.jdom.Element e = (org.jdom.Element) o;
+
/* material */
if ( "material".equals(e.getName()) )
{
Material m = makeLCDDMaterial(e);
- //System.out.println("LCDD -> " + m.getAttributeValue("name"));
lcdd.addMaterial(m);
}
/* element */
else
{
org.jdom.Element ee = makeLCDDElement(e);
- //System.out.println("LCDD -> " + ee.getAttributeValue("name"));
lcdd.addElement(ee);
}
}
@@ -726,10 +672,10 @@
org.jdom.Element element = (org.jdom.Element) i.next();
if ("material".equals(element.getName()))
{
- // System.out.println("addReferencesFromCompact - " + element.getAttributeValue("name"));
addReferences(element);
}
}
+ MaterialManager.printMaterials();
}
/**
@@ -752,47 +698,28 @@
{
System.err.println("WARNING: Already loaded elements. loadElements() call was ignored.");
}
- }
-
- /**
- *
- */
- public org.jdom.Element getDefaultMaterial()
- {
- return getMaterial(defaultMaterialName);
- }
+ }
/** Make org.lcsim.Material impl class for all org.jdom.Element in the map. */
public void makeMaterials(LCDD lcdd) throws JDOMException
{
- //System.out.println("XMLMaterialManager.makeMaterials()");
int cnt = 0;
for (Element me : materialMap.values() )
{
makeMaterial(me, lcdd);
++cnt;
}
- //System.out.println("made " + cnt + " materials");
- }
-
- public void makeMaterials() throws JDOMException
- {
- makeMaterials(null);
}
/**
* Make org.lcsim.Material from this org.jdom.Element material tag in GDML format,
* defining referenced materials recursively.
*/
- public void makeMaterial(org.jdom.Element materialElement, LCDD lcdd) throws JDOMException
- {
- //System.out.println("makeMaterial - " + materialElement.getAttributeValue("name"));
-
+ protected void makeMaterial(org.jdom.Element materialElement, LCDD lcdd) throws JDOMException
+ {
/* Add the referenced material if it does not exist already. */
if ( MaterialManager.getMaterial(materialElement.getAttributeValue("name")) == null )
- {
- //System.out.println("XMLMaterialManager.makeMaterial() - " + materialElement.getAttributeValue("name") );
-
+ {
MaterialDefinitionType mdt = MaterialDefinitionType.getMaterialDefinitionType(materialElement);
String tagname = mdt.getTagName();
@@ -801,9 +728,7 @@
{
org.jdom.Element tag = (org.jdom.Element) o;
String ref = tag.getAttributeValue("ref");
-
- //System.out.println("child ref: " + ref);
-
+
org.jdom.Element refMatElem = getMaterial(ref);
/* Call this function recursively to add referenced materials. */