G4OCCT 0.1.0
Geant4 interface to Open CASCADE Technology (OCCT) geometry definitions
Loading...
Searching...
No Matches
main.cc File Reference

step2dd4hep — generate a DD4hep compact file from a STEP geometry. More...

#include <IFSelect_ReturnStatus.hxx>
#include <STEPCAFControl_Reader.hxx>
#include <TDataStd_Name.hxx>
#include <TDF_LabelSequence.hxx>
#include <TDocStd_Application.hxx>
#include <TDocStd_Document.hxx>
#include <XCAFDoc_DocumentTool.hxx>
#include <XCAFDoc_MaterialTool.hxx>
#include <XCAFDoc_ShapeTool.hxx>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>

Go to the source code of this file.

Functions

static std::string LabelName (const TDF_Label &label)
 Return the TDataStd_Name value for label, or empty string.
 
static std::string MaterialName (const TDF_Label &label, const Handle(XCAFDoc_MaterialTool) &matTool)
 Return the XDE material name for label, or empty string.
 
static void CollectMaterials (const TDF_Label &label, const Handle(XCAFDoc_ShapeTool) &shapeTool, const Handle(XCAFDoc_MaterialTool) &matTool, std::set< std::string > &out)
 
static std::string XmlAttr (const std::string &s)
 Escape characters that must be escaped inside an XML attribute value.
 
static std::string XmlUnescape (std::string s)
 
static std::map< std::string, std::string > ReadExistingMap (const std::string &path)
 
static void PrintUsage (const char *prog)
 
int main (int argc, char **argv)
 

Detailed Description

step2dd4hep — generate a DD4hep compact file from a STEP geometry.

Usage:

step2dd4hep [options] geometry.step
Options:
-o <file> Output compact XML (default: <stem>.xml)
-m <file> Output material-map XML (default: <stem>_materials.xml)
--existing-map <file>
Existing material-map XML to read; only unmapped STEP
material names will be added to the generated stub.
--detector-id <n>
Numeric detector id in the compact file (default: 1)
--detector-name <name>
Detector element name (default: derived from STEP stem)
-h, --help Print this help

The tool reads the STEP file with the OpenCASCADE XDE framework, collects all unique material names attached to solid labels (the same attribute that G4OCCTAssemblyVolume::FromSTEP uses), and emits:

  1. A minimal DD4hep compact XML that references the STEP file and the generated material-map via the G4OCCT_STEPAssembly plugin.
  2. A material-map XML stub with one <entry> per unique STEP material name, with dd4hep_material left as a TODO placeholder (or filled in from an existing map that the user provides).

If no material names are found in the STEP metadata, the label names of the free shapes are used instead, which matches the fall-back key used by G4OCCTAssemblyVolume when a material attribute is absent.

Definition in file main.cc.

Function Documentation

◆ CollectMaterials()

static void CollectMaterials ( const TDF_Label &  label,
const Handle(XCAFDoc_ShapeTool) &  shapeTool,
const Handle(XCAFDoc_MaterialTool) &  matTool,
std::set< std::string > &  out 
)
static

Recursively walk the XDE label tree and collect unique material keys.

The priority order matches G4OCCTAssemblyVolume::ImportLabel:

  1. XDE material attribute on the referred shape label.
  2. TDataStd_Name of the referred shape label.

Definition at line 96 of file main.cc.

References CollectMaterials(), LabelName(), and MaterialName().

Referenced by CollectMaterials(), and main().

◆ LabelName()

static std::string LabelName ( const TDF_Label &  label)
static

Return the TDataStd_Name value for label, or empty string.

Definition at line 66 of file main.cc.

Referenced by CollectMaterials().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 216 of file main.cc.

References CollectMaterials(), PrintUsage(), ReadExistingMap(), and XmlAttr().

◆ MaterialName()

static std::string MaterialName ( const TDF_Label &  label,
const Handle(XCAFDoc_MaterialTool) &  matTool 
)
static

Return the XDE material name for label, or empty string.

Definition at line 77 of file main.cc.

Referenced by CollectMaterials().

◆ PrintUsage()

static void PrintUsage ( const char *  prog)
static

Definition at line 201 of file main.cc.

Referenced by main().

◆ ReadExistingMap()

static std::map< std::string, std::string > ReadExistingMap ( const std::string &  path)
static

Parse an existing material-map XML produced by this tool and return a map of step_name → dd4hep_material for entries that are not placeholders.

Definition at line 171 of file main.cc.

References XmlUnescape().

Referenced by main().

◆ XmlAttr()

static std::string XmlAttr ( const std::string &  s)
static

Escape characters that must be escaped inside an XML attribute value.

Definition at line 123 of file main.cc.

Referenced by main().

◆ XmlUnescape()

static std::string XmlUnescape ( std::string  s)
static

Unescape the five predefined XML entities in an attribute value string so that names read back from the written XML match the raw OCCT strings.

Definition at line 151 of file main.cc.

Referenced by ReadExistingMap().