AliRoot Core  3dc7879 (3dc7879)
AliDrawStyle.h
Go to the documentation of this file.
1 #ifndef ALIDRAWSTYLE_H
2 #define ALIDRAWSTYLE_H
3  /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice */
5 
229 
230 // TODO: Should we use some parser like bison, yacc or boost::spirit?
231 // TODO: create macro with handle style for test ApplyCssStyle
232 // TODO: change pad global indexes to local
233 // TODO: using TString - to be replaced by faster variant with rough pointers
234 // TODO: refactor godness function
235 // TODO: perhaps I should combine {TString elementID, TString classID, TString objectID, TString localStyle} to the array?
236 // TODO: add test for ReadCssString, ApplyCssStyle, WriteCssFile, private methods
237 // TODO: combine ElementSearch, ClassSearch, ObjectSearch into one function
238 // TODO: add parsing scheme
239 
240 #include <map>
241 #include <vector>
242 #include <string>
243 #include <iostream>
244 #include <fstream>
245 #include "TObject.h"
246 #include "TString.h"
247 class TPRegexp;
248 class TStyle;
249 class TPad;
250 class TCanvas;
251 class TF1;
252 class TH1;
253 class TGraph;
254 class TLegend;
255 class TMultiGraph;
256 class TFrame;
257 class TPaveText;
258 
259 class AliDrawStyle: public TObject {
260  //OLD CODE
261 public:
262  static void ApplyStyle(const char *styleName);
263  static const TStyle *GetStyle(const char *styleName) { return fStyleAlice[styleName]; }
264  static void SetDefaults();
265  static void SetDefaultStyles(const char *styleName, const char *arrayName);
266  static TString GetLatexAlice(const char *symbol);
267  static void AddLatexSymbol(const char *symbolName, const char *symbolTitle);
268  static const std::vector<int> &GetMarkerStyles(const char *style) { return AliDrawStyle::fMarkerStyles[style]; };
269  static const std::vector<float> &GetMarkerSize(const char *style) { return AliDrawStyle::fMarkerSize[style]; };
270  static const std::vector<int> &GetMarkerColors(const char *style) { return AliDrawStyle::fMarkerColors[style]; };
271  static const std::vector<float> &GetLineWidth(const char *style) { return AliDrawStyle::fLineWidth[style]; };
272  static const std::vector<int> &GetFillColors(const char *style) { return AliDrawStyle::fFillColors[style]; };
273  static Int_t GetIntegerAt(const char *format, Int_t index, const char *separator = ";");
274  static Float_t GetFloatAt(const char *format, Int_t index, const char *separator = ";");
275  static Int_t GetMarkerStyle(const char *style, Int_t index);
276  static Float_t GetMarkerSize(const char *style, Int_t index);
277  static Int_t GetMarkerColor(const char *style, Int_t index);
278  static Int_t GetFillColor(const char *style, Int_t index);
279  static Int_t GetLineStyle(const char *style, Int_t index);
280  static Int_t GetLineColor(const char *style, Int_t index);
281  static Float_t GetLineWidth(const char *style, Int_t index);
282  static void PrintLatexSymbols(Option_t *option, TPRegexp &regExp);
283  static void PrintStyles(Option_t *option, TPRegexp &regExp);
284 protected:
285  static TString fDefaultTStyleID;
286  static TString fDefaultArrayStyleID;
287  static std::map <TString, TString> fLatexAlice;
288  static std::map<TString, TStyle *> fStyleAlice;
289  static std::map<TString, TObjArray *> fCssStyleAlice;
290  static std::map <TString, std::vector<int> > fMarkerStyles;
291  static std::map <TString, std::vector<int> > fMarkerColors;
292  static std::map <TString, std::vector<float> > fMarkerSize;
293  static std::map <TString, std::vector<int> > fFillColors;
294  static std::map <TString, std::vector<float> > fLineWidth;
295  static std::map <TString, std::vector<float> > fLineStyle;
296  static std::map <TString, std::vector<float> > fLineColor;
297  static void RegisterDefaultLatexSymbols();
298  static void RegisterDefaultStyle();
299  static void RegisterDefaultMarkers();
300 
301 
302  // NEW CODE
303 public:
304  static void RegisterCssStyle(const char *styleName, TObjArray*array ) { fCssStyleAlice[styleName]=array;}
305  static const TObjArray *GetCssStyle(const char *styleName) {return fCssStyleAlice[styleName];}
306  static void WriteCSSFile(TObjArray *cssArray, const char * outputName, std::fstream *cssOut=nullptr);
307  static TObjArray *ReadCSSFile(const char *inputName, TObjArray * array=nullptr, Int_t verbose=0);
308  static TObjArray *ReadCssString(TString cssString, TObjArray *array=nullptr, Int_t verbose=0);
309  static void ApplyCssStyle(TPad *pad, const char *styleName, Int_t verbose=0);
310 //protected:
311  template <typename T>
312  static void TObjectApplyStyle(const char* styleName, T *cObj, Int_t objNum=0, Int_t verbose=0);
313  static void TGraphApplyStyle(const char* styleName, TGraph *cGraph, Int_t objNum=0, Int_t verbose=0);
314  static void TH1ApplyStyle(const char* styleName, TH1 *cHis, Int_t objNum=0, Int_t verbose=0);
315  static void TF1ApplyStyle(const char* styleName, TF1 *cFunc, Int_t objNum=0, Int_t verbose=0);
316  static void TLegendApplyStyle(const char* styleName, TLegend *cLegend, Int_t objNum=0, Int_t verbose=0);
317  static void TPadApplyStyle(const char* styleName, TPad *cPad, Int_t verbose=0);
318  static void TCanvasApplyCssStyle(const char* styleName, TCanvas *cCanvas, Int_t verbose=0);
319 
320 //public:
321  static void GetIds(TObject *cObj, TString &elementID, TString &classID, TString &objectID, TString &localStyle, Int_t verbose=0);
322  static Float_t PrepareValue(const char* styleName, TString propertyName, TString elementID, TString classID, TString objectID, TString localStyle, Bool_t &status, Int_t objNum=0, Int_t verbose=0);
323  static TString ParseDeclaration(const char *inputDec, const char *propertyName);
324  static TString GetValue(const char * styleName, TString propertyName, TString elementID, TString classID, TString objectID, TString localStyle=TString(""), Int_t verbose=0);
325  static Bool_t IsSelected(TString selectors, const TString elementID, const TString classID, const TString objectID, Int_t verbose=0);
326  static Bool_t ElementSearch(const TString selectors, const TString elementID, Int_t verbose=0);
327  static Bool_t ClassSearch(const TString selectors, const TString classID, Int_t verbose=0);
328  static Bool_t ObjectSearch(const TString selectors, const TString objectID, Int_t verbose=0);
329  static Float_t GetNamedTypeAt(const char *inputStr, Bool_t &status, Int_t index=0, const char *propertyName="", Int_t verbose=0, const char sep=',', const char *ignoreBrackets="()");
330  static Float_t ConvertUnit(const char *inputValues, const char * option="", Int_t verbose=0);
331  static Int_t ConvertColor(const char *inputString, Int_t verbose=0);
332  static Float_t PixelsToFloat_t(const char *value, const char *option="", Int_t verbose=0);
333  static Float_t PercentToFloat_t(const char *value, Int_t verbose);
334  static Int_t RgbToColor_t(const char *inputString, Int_t verbose=0);
335  static Int_t HexToColor_t(const char *inputString, Int_t verbose=0);
336 
337  static Int_t padNumber;
338  static void SetPadNumber(Int_t num) {padNumber = num;};
339  static Int_t GetPadNumber() {return padNumber;};
340 ClassDef(AliDrawStyle,1);
341 };
342 
343 #endif
static const TObjArray * GetCssStyle(const char *styleName)
Definition: AliDrawStyle.h:305
static Float_t PercentToFloat_t(const char *value, Int_t verbose)
converter from percents to float
static void ApplyStyle(const char *styleName)
static Float_t GetFloatAt(const char *format, Int_t index, const char *separator=";")
static Bool_t ElementSearch(const TString selectors, const TString elementID, Int_t verbose=0)
Checks element id in selector.
static const std::vector< int > & GetFillColors(const char *style)
Definition: AliDrawStyle.h:272
static void TF1ApplyStyle(const char *styleName, TF1 *cFunc, Int_t objNum=0, Int_t verbose=0)
static Bool_t IsSelected(TString selectors, const TString elementID, const TString classID, const TString objectID, Int_t verbose=0)
static std::map< TString, std::vector< int > > fMarkerColors
map of predefined colors arrays
Definition: AliDrawStyle.h:291
static void TGraphApplyStyle(const char *styleName, TGraph *cGraph, Int_t objNum=0, Int_t verbose=0)
static const std::vector< int > & GetMarkerColors(const char *style)
Definition: AliDrawStyle.h:270
static void TH1ApplyStyle(const char *styleName, TH1 *cHis, Int_t objNum=0, Int_t verbose=0)
#define TObjArray
static void RegisterDefaultLatexSymbols()
initialize default LatexSymbols
static Int_t GetFillColor(const char *style, Int_t index)
static Int_t GetIntegerAt(const char *format, Int_t index, const char *separator=";")
static void RegisterDefaultMarkers()
initialize default Markers/Colors
static Int_t GetPadNumber()
Definition: AliDrawStyle.h:339
static void TCanvasApplyCssStyle(const char *styleName, TCanvas *cCanvas, Int_t verbose=0)
static std::map< TString, std::vector< float > > fLineWidth
map of predefined line width
Definition: AliDrawStyle.h:294
static TString GetValue(const char *styleName, TString propertyName, TString elementID, TString classID, TString objectID, TString localStyle=TString(""), Int_t verbose=0)
GetValue gets value from css file or local style.
static const TStyle * GetStyle(const char *styleName)
Definition: AliDrawStyle.h:263
static void SetPadNumber(Int_t num)
Definition: AliDrawStyle.h:338
static TString ParseDeclaration(const char *inputDec, const char *propertyName)
static TString fDefaultTStyleID
ID of the default TStyle.
Definition: AliDrawStyle.h:285
static Float_t GetNamedTypeAt(const char *inputStr, Bool_t &status, Int_t index=0, const char *propertyName="", Int_t verbose=0, const char sep=',', const char *ignoreBrackets="()")
static Bool_t ClassSearch(const TString selectors, const TString classID, Int_t verbose=0)
Checks class in selector.
static std::map< TString, std::vector< float > > fLineColor
map of predefined line color
Definition: AliDrawStyle.h:296
static std::map< TString, std::vector< float > > fLineStyle
map of predefined line style
Definition: AliDrawStyle.h:295
static Int_t ConvertColor(const char *inputString, Int_t verbose=0)
Defines what format of color user used and call appropriate converter Rules for values: *for rgb we a...
TObjArray * array
Definition: AnalyzeLaser.C:12
static void AddLatexSymbol(const char *symbolName, const char *symbolTitle)
static const std::vector< float > & GetMarkerSize(const char *style)
Definition: AliDrawStyle.h:269
static void WriteCSSFile(TObjArray *cssArray, const char *outputName, std::fstream *cssOut=nullptr)
static std::map< TString, std::vector< int > > fMarkerStyles
map of predefined marker styles arrays
Definition: AliDrawStyle.h:290
static Int_t GetLineColor(const char *style, Int_t index)
static const std::vector< float > & GetLineWidth(const char *style)
Definition: AliDrawStyle.h:271
static std::map< TString, std::vector< float > > fMarkerSize
map of predefined marker sizes ()
Definition: AliDrawStyle.h:292
static void RegisterDefaultStyle()
initialize default TStyles
static void SetDefaultStyles(const char *styleName, const char *arrayName)
static void TPadApplyStyle(const char *styleName, TPad *cPad, Int_t verbose=0)
static void SetDefaults()
SetDefault call RegisterDefaultLatexSymbols(), RegisterDefaultStyle(), RegisterDefaultMarkers();.
static Float_t PixelsToFloat_t(const char *value, const char *option="", Int_t verbose=0)
converter from pixels to float Pixels are relative units, it means that we should have something for ...
static void PrintStyles(Option_t *option, TPRegexp &regExp)
static TObjArray * ReadCSSFile(const char *inputName, TObjArray *array=nullptr, Int_t verbose=0)
static void TObjectApplyStyle(const char *styleName, T *cObj, Int_t objNum=0, Int_t verbose=0)
Common part of TGraphApplyStyle(), TH1ApplyStyle(), TF1ApplyStyle()
static void PrintLatexSymbols(Option_t *option, TPRegexp &regExp)
static Bool_t ObjectSearch(const TString selectors, const TString objectID, Int_t verbose=0)
static Int_t HexToColor_t(const char *inputString, Int_t verbose=0)
converter from HEX to Int_t (root format of colors)
static Int_t GetLineStyle(const char *style, Int_t index)
static void RegisterCssStyle(const char *styleName, TObjArray *array)
Definition: AliDrawStyle.h:304
static std::map< TString, TString > fLatexAlice
map of predefined latex symbols - formatted according ALICE rules
Definition: AliDrawStyle.h:287
static Float_t ConvertUnit(const char *inputValues, const char *option="", Int_t verbose=0)
Defines what units user used and call appropriate converter Rules for values: *for pixels we are usin...
static TString GetLatexAlice(const char *symbol)
static void GetIds(TObject *cObj, TString &elementID, TString &classID, TString &objectID, TString &localStyle, Int_t verbose=0)
Method get IDs from the cObject->GetName() and parse it into input reference. Names of objects should...
static std::map< TString, TObjArray * > fCssStyleAlice
map of Alice predefined styles corresponding to css notation
Definition: AliDrawStyle.h:289
static std::map< TString, TStyle * > fStyleAlice
map of Alice predefined styles (+user defined)
Definition: AliDrawStyle.h:288
static Int_t padNumber
Definition: AliDrawStyle.h:337
static void ApplyCssStyle(TPad *pad, const char *styleName, Int_t verbose=0)
Applies style from css to all objects from Pad or Canvas. In case if pad inherited from TCanvas will ...
static TObjArray * ReadCssString(TString cssString, TObjArray *array=nullptr, Int_t verbose=0)
Class to access to drawing styles.
Definition: AliDrawStyle.h:259
static TString fDefaultArrayStyleID
ID of the default array styles.
Definition: AliDrawStyle.h:286
static Float_t PrepareValue(const char *styleName, TString propertyName, TString elementID, TString classID, TString objectID, TString localStyle, Bool_t &status, Int_t objNum=0, Int_t verbose=0)
prepares value for applying. This method defines which value user specified (color, unit, number, etc) and return number with appropriate type Returning value will use in Set methods of objects. (TH1.SetMarkerColor(value)).
static Int_t GetMarkerColor(const char *style, Int_t index)
static Int_t GetMarkerStyle(const char *style, Int_t index)
static const std::vector< int > & GetMarkerStyles(const char *style)
Definition: AliDrawStyle.h:268
static void TLegendApplyStyle(const char *styleName, TLegend *cLegend, Int_t objNum=0, Int_t verbose=0)
static Int_t RgbToColor_t(const char *inputString, Int_t verbose=0)
converter from RGB to Int_t (root format of colors)
static std::map< TString, std::vector< int > > fFillColors
map of predefined fill colors arrays
Definition: AliDrawStyle.h:293