CMS 3D CMS Logo

Public Member Functions | Private Member Functions

DDLBooleanSolid Class Reference

This class takes care of processing all BooleanSolid type elements. More...

#include <DDLBooleanSolid.h>

Inheritance diagram for DDLBooleanSolid:
DDLSolid DDXMLElement

List of all members.

Public Member Functions

 DDLBooleanSolid (DDLElementRegistry *myreg)
 Constructor.
void preProcessElement (const std::string &name, const std::string &nmspace, DDCompactView &cpv)
 Called by loadAttributes AFTER attributes are loaded.
void processElement (const std::string &name, const std::string &nmspace, DDCompactView &cpv)
 Processing the element.
 ~DDLBooleanSolid ()
 Destructor.

Private Member Functions

std::string dumpBooleanSolid (const std::string &name, const std::string &nmspace)

Detailed Description

This class takes care of processing all BooleanSolid type elements.

Author:
Michael Case

DDLBooleanSolid.h - description ------------------- begin: Wed Dec 12, 2001 email: case@ucdhep.ucdavis.edu

This is the Intersection, Subtraction and Union processor. A BooleanSolid handles all of these because as far as the DDL is concerned, they have the same basic form, including two solid references, and potentially one translation and one rotation.

Definition at line 24 of file DDLBooleanSolid.h.


Constructor & Destructor Documentation

DDLBooleanSolid::DDLBooleanSolid ( DDLElementRegistry myreg)

Constructor.

Definition at line 24 of file DDLBooleanSolid.cc.

  : DDLSolid( myreg )
{}
DDLBooleanSolid::~DDLBooleanSolid ( void  )

Destructor.

Definition at line 28 of file DDLBooleanSolid.cc.

{}

Member Function Documentation

std::string DDLBooleanSolid::dumpBooleanSolid ( const std::string &  name,
const std::string &  nmspace 
) [private]

Definition at line 144 of file DDLBooleanSolid.cc.

References DDXMLElement::getAttributeSet(), DDLElementRegistry::getElement(), i, DDXMLElement::myRegistry_, asciidump::s, and DDXMLElement::size().

Referenced by processElement().

{
  std::string s;
  DDXMLAttribute atts = getAttributeSet();

  s = std::string ("\n<") + name + " name=\"" + atts.find("name")->second + "\"";

  if (atts.find("firstSolid") != atts.end()) s+= " firstSolid=\"" + atts.find("firstSolid")->second + "\"";
  if (atts.find("secondSolid") != atts.end()) s+= " secondSolid=\"" + atts.find("secondSolid")->second + "\"";
  s +=  ">\n";

  DDXMLElement* myrSolid = myRegistry_->getElement("rSolid"); // get rSolid children
  DDXMLElement* myTranslation = myRegistry_->getElement("Translation"); // get Translation child
  DDXMLElement* myrRotation  = myRegistry_->getElement("rRotation"); // get rRotation child
  if (myrSolid->size() > 0)
  {
    for (size_t i = 0; i < myrSolid->size(); ++i)
    {
      atts = myrSolid->getAttributeSet(i);
      s+="<rSolid name=\"" + atts.find("name")->second + "\"/>\n";
    }
  }

  atts = myTranslation->getAttributeSet();
  s+= "<Translation";
  if (atts.find("x") != atts.end()) 
    s+=" x=\"" + atts.find("x")->second + "\"";
  if (atts.find("y") != atts.end()) 
    s+= " y=\"" + atts.find("y")->second + "\"";
  if (atts.find("z") != atts.end()) 
    s+= " z=\"" + atts.find("z")->second + "\"";
  s+="/>\n";

  atts = myrRotation->getAttributeSet();
  if (atts.find("name") != atts.end())
  {
    s+= "<rRotation name=\"" + atts.find("name")->second + "\"/>\n";
  }
  s+= "</" + name + ">\n\n";
  return s;
}
void DDLBooleanSolid::preProcessElement ( const std::string &  name,
const std::string &  nmspace,
DDCompactView cpv 
) [virtual]

Called by loadAttributes AFTER attributes are loaded.

The preProcessElement method can assume that the attributes are loaded and perform any code that is necessary at the start of an element.

This would allow users to call their own code to setup anything necessary for the continued processing of the child elements.

Reimplemented from DDXMLElement.

Definition at line 33 of file DDLBooleanSolid.cc.

References DDXMLElement::clear(), DDLElementRegistry::getElement(), and DDXMLElement::myRegistry_.

{
  myRegistry_->getElement( "rSolid" )->clear();
}
void DDLBooleanSolid::processElement ( const std::string &  name,
const std::string &  nmspace,
DDCompactView cpv 
) [virtual]

Processing the element.

The processElement method completes any necessary work to process the XML element.

For example, this can be used to call the DDCore to make the geometry in memory. There is a default for this so that if not declared in the inheriting class, no processing is done.

Reimplemented from DDXMLElement.

Definition at line 42 of file DDLBooleanSolid.cc.

References DDXMLElement::clear(), DCOUT_V, dumpBooleanSolid(), ExprEvalInterface::eval(), DDXMLElement::getAttributeSet(), DDXMLElement::getDDName(), DDLElementRegistry::getElement(), DDI::Singleton< I >::instance(), reco::helper::VirtualJetProducerHelper::intersection(), DDXMLElement::myRegistry_, asciidump::s, DDLSolid::setReference(), DDXMLElement::size(), DDSolidFactory::subtraction(), DDXMLElement::throwError(), DDSolidFactory::unionSolid(), x, detailsBasic3DVector::y, and z.

{
  DCOUT_V( 'P', "DDLBooleanSolid::processElement started" );

  // new DDLBoolean will handle:
  // <UnionSolid name="bs" firstSolid="blah" secondSolid="argh"> <Translation...> <rRotation .../> </UnionSolid
  // AND <UnionSolid> <rSolid...> <rSolid...> <Translation...> <rRotation...> </UnionSolid>

  DDXMLElement* myrSolid = myRegistry_->getElement( "rSolid" ); // get rSolid children
  DDXMLElement* myTranslation = myRegistry_->getElement( "Translation" ); // get Translation child
  DDXMLElement* myrRotation  = myRegistry_->getElement( "rRotation" ); // get rRotation child

  ExprEvalInterface & ev = ExprEvalSingleton::instance();
  DDXMLAttribute atts = getAttributeSet();

  DDName ddn1, ddn2;
  double x=0.0, y=0.0, z=0.0;
  DDRotation ddrot;

  // Basically check if there are rSolids or Translation or rRotation then we have
  // should NOT have any of the attributes shown above.
  if( myrSolid->size() == 0 ) 
  {
    // do the solids using the attributes only.
    if ( atts.find("firstSolid") != atts.end() && atts.find("secondSolid") != atts.end() ) {
      ddn1 = getDDName(nmspace, "firstSolid");
      ddn2 = getDDName(nmspace, "secondSolid");
    } else {
      std::string s ("DDLBooleanSolid did not find any solids with which to form a boolean solid.");
      s += dumpBooleanSolid(name, nmspace);
      throwError( s );
    }
  }
  else if (myrSolid->size() == 2)
  {
    ddn1 = myrSolid->getDDName(nmspace, "name", 0);
    ddn2 = myrSolid->getDDName(nmspace, "name", 1);
  } else {
    std::string s("DDLBooleanSolid did not find any solids with which to form a boolean solid.");
    s += dumpBooleanSolid(name, nmspace);
    throwError( s );
  }

  if (myTranslation->size() > 0)
  {
    atts.clear();
    atts = myTranslation->getAttributeSet();
    x = ev.eval(nmspace, atts.find("x")->second);
    y = ev.eval(nmspace, atts.find("y")->second);
    z = ev.eval(nmspace, atts.find("z")->second);
  }

  if (myrRotation->size() > 0) 
  {
    ddrot = DDRotation( myrRotation->getDDName (nmspace) );
  }

  DDSolid theSolid;

  if (name == "UnionSolid") {
    theSolid = DDSolidFactory::unionSolid (getDDName(nmspace)
                                           , DDSolid(ddn1)
                                           , DDSolid(ddn2)
                                           , DDTranslation(x, y, z)
                                           , ddrot
      );               
  }
  else if (name == "SubtractionSolid") {
    theSolid = DDSolidFactory::subtraction (getDDName(nmspace)
                                            , DDSolid(ddn1)
                                            , DDSolid(ddn2)
                                            , DDTranslation(x, y, z)
                                            , ddrot
      );               
  }
  else if (name == "IntersectionSolid") {
    theSolid = DDSolidFactory::intersection (getDDName(nmspace)
                                             , DDSolid(ddn1)
                                             , DDSolid(ddn2)
                                             , DDTranslation(x, y, z)
                                             , ddrot
      );               
  }
  else {
    throw DDException("DDLBooleanSolid was asked to do something other than Union-, Subtraction- or IntersectionSolid?");
  }
  
  DDLSolid::setReference(nmspace, cpv);

  DCOUT_V('p', theSolid);

  // clear all "children" and attributes
  myTranslation->clear();
  myrRotation->clear();
  myrSolid->clear();
  clear();
  DCOUT_V('P', "DDLBooleanSolid::processElement completed");

}