Geant4 11.4.0
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 "G4ToolsSGViewer.hh"
#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 617 of file G4ToolsSGSceneHandler.cc.

617 {
618 for(auto& style : a_styles.named_styles()) {
619 if(style.first==a_name) return &(style.second);
620 }
621 return nullptr;
622}

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 681 of file G4ToolsSGSceneHandler.cc.

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

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 624 of file G4ToolsSGSceneHandler.cc.

626 {
627
629
630 tools::xml::styles _tools_styles(G4cout);
631 _tools_styles.add_colormap("default",tools::sg::style_default_colormap());
632 _tools_styles.add_colormap("ROOT",tools::sg::style_ROOT_colormap());
633
634 for(const auto& [name, style_items] : _styles) {
635 tools::xml::styles::style_t _tools_style;
636 for(const auto& [param, value] : style_items) {
637 if(param.find('.')==std::string::npos) {
638 _tools_style.push_back(tools::xml::styles::style_item_t(param,value));
639 }
640 }
641 _tools_styles.add_style(name, _tools_style);
642 }
643
644 // sub styles:
645 for(const auto& [name, style_items] : _styles) {
646 for(const auto& [param, value] : style_items) {
647 std::string::size_type pos = param.rfind('.');
648 if(pos!=std::string::npos) {
649 std::string sub_style = name + "." + param.substr(0,pos);
650 G4String parameter = param.substr(pos+1,param.size()-pos);
651 tools::xml::styles::style_t* _tools_style = find_style(_tools_styles,sub_style);
652 if(_tools_style) {
653 _tools_style->push_back(tools::xml::styles::style_item_t(parameter,value));
654 } else {
655 tools::xml::styles::style_t _tools_style_2;
656 _tools_style_2.push_back(tools::xml::styles::style_item_t(parameter,value));
657 _tools_styles.add_style(sub_style,_tools_style_2);
658 }
659 }
660 }
661 }
662
663 unsigned int number = a_plots.number();
664 for(unsigned int index=0;index<number;index++) {
665 tools::sg::plotter* _plotter = a_plots.find_plotter(index);
666 if(_plotter) {
667 for(const auto& style : a_plotter_styles) {
668 SetRegionStyles(_tools_styles,a_plots,*_plotter,style);
669 }
670 }
671 }
672
673 for(const auto& [region, style] : a_region_styles) {
674 tools::sg::plotter* _plotter = a_plots.find_plotter(region);
675 if(_plotter) {
676 SetRegionStyles(_tools_styles, a_plots, *_plotter, style);
677 }
678 }
679}
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
static G4PlotterManager & GetInstance()
const Styles & GetStyles() const
const char * name(G4int ptype)

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 599 of file G4ToolsSGSceneHandler.cc.

602 {
603 if(a_style=="reset") {
604 a_plotter.reset_style(true);
605 a_plots.touch(); //to apply indirectly plots::set_plotter_layout() on _plotter.
606 } else if( (a_style=="inlib_default")|| (a_style=="default")) {
607 tools::sg::set_inlib_default_style(G4cout,a_styles.cmaps(),a_plotter,tools::sg::font_hershey());
608 } else if(a_style=="ROOT_default") {
609 tools::sg::set_ROOT_default_style(G4cout,a_styles.cmaps(),a_plotter,tools::sg::font_roboto_bold_ttf());
610 } else if(a_style=="hippodraw") {
611 tools::sg::set_hippodraw_style(G4cout,a_styles.cmaps(),a_plotter,tools::sg::font_lato_regular_ttf());
612 } else {
613 tools::sg::style_from_res(a_styles,a_style,a_plotter,false);
614 }
615}

Referenced by SetPlotterStyles().