Print

Print


Commit in GeomConverter/src/org/lcsim/material on MAIN
XMLMaterialManager.java+67-51.7 -> 1.8


GeomConverter/src/org/lcsim/material
XMLMaterialManager.java 1.7 -> 1.8
diff -u -r1.7 -r1.8
--- XMLMaterialManager.java	28 Jun 2005 22:42:41 -0000	1.7
+++ XMLMaterialManager.java	30 Jun 2005 00:35:12 -0000	1.8
@@ -22,9 +22,8 @@
  * Utility class for extracting material elements and their referenced elements
  * from a GDML, LCDD or Compact XML file.
  *
- * TODO: Return implementation classes for Material and Element rather than
+ * TODO: Return implementation classes for Material and Element rather than just XML elements.
  * TODO: Seems like an excessive number of methods are public
- * just XML elements.
  */
 public class XMLMaterialManager
 {
@@ -61,14 +60,16 @@
     /** Map of element names to elements. */
     protected LinkedHashMap<String, org.jdom.Element> elementMap;
     
+    private static MaterialFromGDMLCnv materialCnv = new MaterialFromGDMLCnv();
+    
     /** Return static manager containing chem element data. */
-    public static XMLMaterialManager getElements()
+    public static XMLMaterialManager elements()
     {
         return elements;
     }
     
     /** Return static manager with default composite materials and elements as parent. */
-    public static XMLMaterialManager getMaterials()
+    public static XMLMaterialManager materials()
     {
         if ( !loadedMaterials )
         {
@@ -101,6 +102,11 @@
     /** Create a material manager that has elements as parent with additional materials from InputStream. */
     public static XMLMaterialManager create(InputStream in) throws IOException
     {
+       if ( in == null )
+       {
+            throw new IOException("InputStream is null.");
+       }
+        
        try
        {
            return new XMLMaterialManager(elements, in);
@@ -744,6 +750,11 @@
         copyMaterialsToLCDD(lcdd);
     }
     
+    public void setLCDD(LCDD lcdd)
+    {
+        materialCnv.setLCDD(lcdd);
+    }
+    
     /** Read materials from a compact description and cache materials and their dependencies in this manager. */
     public void addReferencesFromCompact(org.jdom.Element lccdd) throws JDOMException
     {
@@ -789,5 +800,56 @@
     public org.jdom.Element getDefaultMaterial() 
     {
         return getMaterial(defaultMaterialName);
+    }        
+    
+    /** Make org.lcsim.Material impl class for all org.jdom.Element in the map. */
+    void makeMaterials(LCDD lcdd) throws JDOMException
+    {
+        for (Element me : materialMap.values() )
+        {
+            makeMaterial(me, lcdd);
+        }
+    }
+    
+    /**
+     * Make org.lcsim.Material from this org.jdom.Element material tag in GDML format, 
+     * defining referenced materials recursively. 
+     */
+    void makeMaterial(org.jdom.Element materialElement, LCDD lcdd) throws JDOMException
+    {    
+        System.out.println("makeMaterial - " + materialElement.getAttributeValue("name") );
+        
+        MaterialDefinitionType mdt = MaterialDefinitionType.getMaterialDefinitionType(materialElement);   
+        String tagname = mdt.getTagName();
+        
+        /** First need to add referenced materials. */
+        for ( Object o : materialElement.getChildren(tagname) )
+        {
+            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. */
+            if ( refMatElem != null )
+            {
+                this.makeMaterial(refMatElem, lcdd);
+            }
+            /*
+            else 
+            {
+                if ( getElement(ref) == null )
+                {
+                    throw new JDOMException("Not a valid element or material reference: " + ref);
+                }
+            }
+             */
+        }
+        
+        /* Now that deps are added for this material, make impl object. */
+        org.lcsim.material.Material material = materialCnv.makeMaterial(materialElement, lcdd);
+        MaterialManager.addMaterial(material);
     }
-}
+}
\ No newline at end of file
CVSspam 0.2.8