From 0798362509eed7b6fc8170d7ad46846927252beb Mon Sep 17 00:00:00 2001
From: Whitney Armstrong <warmstrong@anl.gov>
Date: Fri, 23 Jul 2021 00:25:11 -0500
Subject: [PATCH] Added VisAttr ref extension compact construction

 - Using `ref="OtherVisName"` attribute, the visualization attribute is an extension of
the `"OtherVisName"` which is used to initialize the new vis attribute.
 - The new VisAttr inherits all the properties  of the ref and additional arguments override these values.

Example where the only difference is the `alpha` value.

```
  <vis name="SiVertexBarrelModuleVis"
       alpha="1.0" r="1.0" g="0.75" b="0.76"
       drawingStyle="wireframe"
       showDaughters="false"
       visible="true"/>

  <vis name="SiVertexEndcapModuleVis"
       ref="SiVertexBarrelModuleVis"
       alpha="0.5"/>
```

	modified:   src/plugins/Compact2Objects.cpp
---
 DDCore/src/plugins/Compact2Objects.cpp | 35 ++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 5 deletions(-)

diff --git a/DDCore/src/plugins/Compact2Objects.cpp b/DDCore/src/plugins/Compact2Objects.cpp
index fab6267f8..0b5e15672 100644
--- a/DDCore/src/plugins/Compact2Objects.cpp
+++ b/DDCore/src/plugins/Compact2Objects.cpp
@@ -805,21 +805,46 @@ template <> void Converter<PropertyTable>::operator()(xml_h e) const {
 }
 #endif
 
-/** Convert compact visualization attribute to Detector visualization attribute
+/** Convert compact visualization attribute to Detector visualization attribute.
  *
  *  <vis name="SiVertexBarrelModuleVis"
  *       alpha="1.0" r="1.0" g="0.75" b="0.76"
  *       drawingStyle="wireframe"
  *       showDaughters="false"
  *       visible="true"/>
+ *
+ *  Optionally inherit an already defined VisAttr and override other properties.
+ *
+ *  <vis name="SiVertexEndcapModuleVis"
+ *       ref="SiVertexBarrelModuleVis"
+ *       alpha="0.5"/>
  */
 template <> void Converter<VisAttr>::operator()(xml_h e) const {
   VisAttr attr(e.attr<string>(_U(name)));
+  float alpha = 1.0;
+  float red   = 1.0;
+  float green = 1.0;
+  float blue  = 1.0;
+  if(e.hasAttr(_U(ref))) {
+    auto refName = e.attr<string>(_U(ref));
+    const auto refAttr = description.visAttributes(refName);
+    if(!refAttr.isValid() )  {
+        throw runtime_error("reference VisAttr " + refName + " does not exist");
+    }
+    // Not sure if there is an easy deep copy constructor
+    // Just copying things manually
+    refAttr.argb(alpha,red,green,blue);
+    attr.setColor(alpha,red,green,blue);
+    attr.setDrawingStyle( refAttr.drawingStyle());
+    attr.setLineStyle( refAttr.lineStyle());
+    attr.setShowDaughters(refAttr.showDaughters());
+    attr.setVisible(refAttr.visible());
+  }
   xml_dim_t dim(e);
-  float alpha = dim.alpha(1.0);
-  float red   = dim.r(1.0);
-  float green = dim.g(1.0);
-  float blue  = dim.b(1.0);
+  alpha = dim.alpha(alpha);
+  red   = dim.r(red  );
+  green = dim.g(green);
+  blue  = dim.b(blue );
 
   printout(s_debug.visattr ? ALWAYS : DEBUG, "Compact",
            "++ Converting VisAttr  structure: %-16s. Alpha=%.2f R=%.3f G=%.3f B=%.3f",
-- 
GitLab