Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ToolsSGSceneHandler.cc File Reference
#include "G4ToolsSGSceneHandler.hh"
#include "G4ToolsSGNode.hh"
#include "G4TransportationManager.hh"
#include "G4Polyline.hh"
#include "G4Polymarker.hh"
#include "G4Circle.hh"
#include "G4Square.hh"
#include "G4Polyhedron.hh"
#include "G4Text.hh"
#include "G4Mesh.hh"
#include "G4PlotterManager.hh"
#include <tools/sg/separator>
#include <tools/sg/matrix>
#include <tools/sg/rgba>
#include <tools/sg/draw_style>
#include <tools/sg/atb_vertices>
#include <tools/sg/markers>
#include <tools/sg/dummy_freetype>
#include <tools/sg/text_hershey_marker>
#include <tools/sg/light_off>
#include <tools/sg/plots>
#include <tools/sg/h2plot_cp>
#include <tools/sg/plotter_style>
#include <tools/sg/event_dispatcher>
#include <tools/sg/path>
#include <tools/sg/search>
#include <tools/histo/h1d>
#include <tools/histo/h2d>
#include <tools/sg/plotter_some_styles>
#include <utility>
#include "G4UImanager.hh"

Go to the source code of this file.

Classes

class  plots_cbk
 

Functions

void SetRegionStyles (tools::xml::styles &a_styles, tools::sg::plots &a_plots, tools::sg::plotter &a_plotter, const G4String &a_style)
 
tools::xml::styles::style_t * find_style (tools::xml::styles &a_styles, const std::string &a_name)
 
void SetPlotterStyles (tools::sg::plots &a_plots, const std::vector< G4String > &a_plotter_styles, const std::vector< G4Plotter::RegionStyle > &a_region_styles)
 
void SetPlotterParameters (tools::sg::cmaps_t &a_cmaps, tools::sg::plots &a_plots, const std::vector< G4Plotter::RegionParameter > &a_region_parameters)
 

Function Documentation

◆ find_style()

tools::xml::styles::style_t * find_style ( tools::xml::styles & a_styles,
const std::string & a_name )
inline

Definition at line 610 of file G4ToolsSGSceneHandler.cc.

610 {
611 tools_vforit(tools::xml::styles::named_style_t,a_styles.named_styles(),it){
612 if((*it).first==a_name) return &((*it).second);
613 }
614 return 0;
615}

Referenced by SetPlotterStyles().

◆ SetPlotterParameters()

void SetPlotterParameters ( tools::sg::cmaps_t & a_cmaps,
tools::sg::plots & a_plots,
const std::vector< G4Plotter::RegionParameter > & a_region_parameters )
inline

Definition at line 677 of file G4ToolsSGSceneHandler.cc.

678 {
679 // parameter/field examples :
680 // title_automated
681 // title
682 // bins_style.0.color
683 // x_axis.divisions
684 // x_axis.line_style.color
685 // background_style.back_color
686 tools_vforcit(G4Plotter::RegionParameter,a_region_parameters,it) {
687 tools::sg::plotter* _plotter = a_plots.find_plotter((*it).first);
688 if(_plotter) {
689 const G4String& parameter = (*it).second.first;
690 const G4String& value = (*it).second.second;
691 tools::sg::field* fd = _plotter->find_field_by_name(parameter);
692 if(!fd) fd = _plotter->find_field_by_name(_plotter->s_cls()+"."+parameter);
693 if(fd) {if(fd->s2value(value)) continue;}
694 // look for sf_enum for which value is given with a string, or
695 // for sf<bool> for which value given with true/false, or
696 // for a style, for example: bins_style.0.color:
697 if(!_plotter->set_from_string(G4cout,a_cmaps,parameter,value)) {
698 G4cout << "G4ToolsSGSceneHandler::SetPlotterParameters: plotter.set_from_string() failed for field "
699 << tools::sout(parameter) << ", and value " << tools::sout(value) << "."
700 << std::endl;
701 }
702 }
703 }
704}
G4GLOB_DLL std::ostream G4cout
std::pair< unsigned int, Parameter > RegionParameter
Definition G4Plotter.hh:44

Referenced by G4ToolsSGSceneHandler::AddPrimitive().

◆ SetPlotterStyles()

void SetPlotterStyles ( tools::sg::plots & a_plots,
const std::vector< G4String > & a_plotter_styles,
const std::vector< G4Plotter::RegionStyle > & a_region_styles )
inline

Definition at line 617 of file G4ToolsSGSceneHandler.cc.

619 {
620
622
623 tools::xml::styles _tools_styles(G4cout);
624 _tools_styles.add_colormap("default",tools::sg::style_default_colormap());
625 _tools_styles.add_colormap("ROOT",tools::sg::style_ROOT_colormap());
626
627 {tools_vforcit(G4PlotterManager::NamedStyle,_styles,it) {
628 tools::xml::styles::style_t _tools_style;
629 tools_vforcit(G4PlotterManager::StyleItem,(*it).second,its) {
630 const G4String& param = (*its).first;
631 if(param.find('.')==std::string::npos) {
632 const G4String& value = (*its).second;
633 _tools_style.push_back(tools::xml::styles::style_item_t(param,value));
634 }
635 }
636 _tools_styles.add_style((*it).first,_tools_style);
637 }}
638
639 // sub styles:
640 {tools_vforcit(G4PlotterManager::NamedStyle,_styles,it) {
641 tools_vforcit(G4PlotterManager::StyleItem,(*it).second,its) {
642 const G4String& param = (*its).first;
643 std::string::size_type pos = param.rfind('.');
644 if(pos!=std::string::npos) {
645 std::string sub_style = (*it).first+"."+param.substr(0,pos);
646 G4String parameter = param.substr(pos+1,param.size()-pos);
647 const G4String& value = (*its).second;
648 tools::xml::styles::style_t* _tools_style = find_style(_tools_styles,sub_style);
649 if(_tools_style) {
650 _tools_style->push_back(tools::xml::styles::style_item_t(parameter,value));
651 } else {
652 tools::xml::styles::style_t _tools_style_2;
653 _tools_style_2.push_back(tools::xml::styles::style_item_t(parameter,value));
654 _tools_styles.add_style(sub_style,_tools_style_2);
655 }
656 }
657 }
658 }}
659
660 {unsigned int number = a_plots.number();
661 for(unsigned int index=0;index<number;index++) {
662 tools::sg::plotter* _plotter = a_plots.find_plotter(index);
663 if(_plotter) {
664 tools_vforcit(G4String,a_plotter_styles,it) {
665 SetRegionStyles(_tools_styles,a_plots,*_plotter,*it);
666 }
667 }
668 }}
669 {tools_vforcit(G4Plotter::RegionStyle,a_region_styles,it) {
670 tools::sg::plotter* _plotter = a_plots.find_plotter((*it).first);
671 if(_plotter) {
672 SetRegionStyles(_tools_styles,a_plots,*_plotter,(*it).second);
673 }
674 }}
675}
void SetRegionStyles(tools::xml::styles &a_styles, tools::sg::plots &a_plots, tools::sg::plotter &a_plotter, const G4String &a_style)
tools::xml::styles::style_t * find_style(tools::xml::styles &a_styles, const std::string &a_name)
std::vector< NamedStyle > Styles
std::pair< G4String, Style > NamedStyle
std::pair< G4String, G4String > StyleItem
static G4PlotterManager & GetInstance()
const Styles & GetStyles() const
std::pair< unsigned int, G4String > RegionStyle
Definition G4Plotter.hh:42

Referenced by G4ToolsSGSceneHandler::AddPrimitive().

◆ SetRegionStyles()

void SetRegionStyles ( tools::xml::styles & a_styles,
tools::sg::plots & a_plots,
tools::sg::plotter & a_plotter,
const G4String & a_style )
inline

Definition at line 592 of file G4ToolsSGSceneHandler.cc.

595 {
596 if(a_style=="reset") {
597 a_plotter.reset_style(true);
598 a_plots.touch(); //to apply indirectly plots::set_plotter_layout() on _plotter.
599 } else if( (a_style=="inlib_default")|| (a_style=="default")) {
600 tools::sg::set_inlib_default_style(G4cout,a_styles.cmaps(),a_plotter,tools::sg::font_hershey());
601 } else if(a_style=="ROOT_default") {
602 tools::sg::set_ROOT_default_style(G4cout,a_styles.cmaps(),a_plotter,tools::sg::font_roboto_bold_ttf());
603 } else if(a_style=="hippodraw") {
604 tools::sg::set_hippodraw_style(G4cout,a_styles.cmaps(),a_plotter,tools::sg::font_lato_regular_ttf());
605 } else {
606 tools::sg::style_from_res(a_styles,a_style,a_plotter,false);
607 }
608}

Referenced by SetPlotterStyles().