//------------------------------------------------------------------------------ // gui_Plot class -- // (C) Piero Giubilato 2008-2010, Berkeley Lab -- //------------------------------------------------------------------------------ //______________________________________________________________________________ // {Trace} // [File name] "gui_Plot.cpp" // [Author] "Piero Giubilato" // [Version] "1.2" // [Modified by] "Piero Giubilato" // [Last revision] "27 Jun 2009" // [Language] "C++" // [Compiler] "Visual C++ 9.x" // [Member of] "Cool SEAL" // [Project] "SEAL" // [Description] "Source for the gui_Plot class" // [Key documentation] // "Visual C++ Reference Help" // "Root reference guide" // {Trace} //______________________________________________________________________________ // gui_Plot is a derived class of gui_2D. It refines the original class by // adding the controls and feedback necessary to handle an usual 2D plot. // Standard component #include // Root Component #include // Application component #include "global.h" #include "gui_Plot.h" // CINT Preprocessor class import definition ClassImp(gui_Plot) // ********************** // Object special methods // ********************** //______________________________________________________________________________ gui_Plot::gui_Plot(UInt_t left, UInt_t top, UInt_t width, UInt_t height, UInt_t textColor): gui_2D(left, top, width, height, textColor) { // Default, no data constructor dbg_Print("gui_Plot::gui_Plot:(default)", DBG_LVL_ZERO); // Sets up the plot Init(left, top, width, height, textColor); } //______________________________________________________________________________ gui_Plot::gui_Plot(gui_Object* parent, UInt_t left, UInt_t top, UInt_t width, UInt_t height, UInt_t textColor): gui_2D(parent, left, top, width, height, textColor) { // Parent constructor dbg_Print("gui_Plot::gui_Plot:(gui_Object*)", DBG_LVL_ZERO); // Sets up the map Init(left, top, width, height, textColor); } //______________________________________________________________________________ void gui_Plot::Init(UInt_t left, UInt_t top, UInt_t width, UInt_t height, UInt_t textColor) { // Common init procedure // Set the gso_2D in plot mode map->data_Style(gso_Map2D::ks_Plot); map->Connect(map, "data_Changed()", "gui_Plot", this, "map_data_changed_Do()"); // Set the palette mode accordingly palette->palette_Mode(gso_Map2D::ks_Plot); // Set the default color list //plot_Color.clear(); //plot_Color.push_back(0x00FF00); UInt_t col_List[8] = {0xFF0000, 0x00FF00, 0x0000FF, 0x880000, 0x008800, 0x000088, 0xFFFFFF, 0x888888}; palette->color_Set(col_List , 8); // Adds the auto range button btn_Range = new gso_Button(Parent()->Window(), "R", k_btn_Size, k_btn_Size, gso_Button::km_Latch, 0x000000, k_btn_Color, Parent()->backColor(), (Float_t)k_btn_Radius, (Float_t)k_btn_Depth); Parent()->Window()->AddFrame(btn_Range, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0)); btn_Range->Connect(btn_Range, "Clicked()", "gui_Plot", this, "btn_range_Do()"); // Provides connections for the standard gui_Object color calls obj_foreColor = textColor; obj_backColor = Parent()->Window()->GetBackground(); // Updates the label plot_Lbl.clear(); label_Set(); // Set the auto range to false range_Auto(false); // Show the object MoveResize(left, top, width, height); } //______________________________________________________________________________ gui_Plot::~gui_Plot() { // Default destructor. dbg_Print("gui_Plot::~gui_Plot()", DBG_LVL_ZERO); // Removes the button range Parent()->Window()->RemoveFrame(btn_Range); btn_Range->DestroyWindow(); delete btn_Range; // Removes the labels for (UInt_t i = 0; i < label.size(); i++) { Parent()->Window()->RemoveFrame(label[i]); label[i]->DestroyWindow(); delete label[i]; } } //______________________________________________________________________________ void gui_Plot::btn_range_Do() { // Handles the ROI numeric events dbg_Print("gui_Plot::btn_range_Do()", DBG_LVL_FLOW); // Change the map auto range status (btn_Range->Status() == btn_Range->kb_Raised) ? range_Auto(false) : range_Auto(true); } //______________________________________________________________________________ void gui_Plot::map_data_changed_Do() { // Handles the changing of the displayed data // This function is connected to the gso_Map object directly, and it is // triggered everytime the data pointer is updated. dbg_Print("gui_Plot::map_data_changed_Do()", DBG_LVL_FLOW); // Recreates the labels label_Set(); // Rearranges the palette hosted by the gui_2D object //gui_2D::Resize(obj_Width, obj_Height); } // ************************* // gui_Plot specific methods // ************************* //______________________________________________________________________________ bool gui_Plot::range_Auto() const { // Returns the palette maximum range dbg_Print("gui_Plot::range_Auto:()", DBG_LVL_FLOW); return map->range_Auto(); } //______________________________________________________________________________ void gui_Plot::range_Auto(bool automatic) { // Sets the palette maximum range dbg_Print("gui_Plot::range_Auto:(bool)", DBG_LVL_FLOW); map->range_Auto(automatic); // Disable vertical ROI controls in case gui_2D::num_Roi[2]->SetState(!automatic); gui_2D::num_Roi[3]->SetState(!automatic); } //______________________________________________________________________________ void gui_Plot::plot_Color(const UInt_t* col_List, UInt_t col_Count) { // Sets the color used to represent the plots dbg_Print("gui_Plot::plot_Color:()", DBG_LVL_FLOW); // This is a simply redirect to the gui_2D original function gui_2D::palette_Color(col_List, col_Count); } //______________________________________________________________________________ void gui_Plot::plot_Label(const char** lbl_List, UInt_t lbl_Count) { // Sets the text shown in the plot legend dbg_Print("gui_Plot::plot_Label:()", DBG_LVL_FLOW); // Clear previous labels (if any) for (UInt_t i = 0; i < plot_Lbl.size(); i++) delete plot_Lbl[i]; plot_Lbl.clear(); // Stores new labels for (UInt_t i = 0; i < lbl_Count; i++) { //std::cout << lbl_List[i] << "\n"; plot_Lbl.push_back(new TString(lbl_List[i])); } // Readraw labels label_Set(); //gui_2D::Resize(obj_Width, obj_Height); } //______________________________________________________________________________ void gui_Plot::label_Set() { // Sets the values into the labels dbg_Print("gui_Plot::label_Set:()", DBG_LVL_FLOW); // Deletes previous labels (if any) for (UInt_t i = 0; i < label.size(); i++) delete label[i]; // Creates the new labels label.clear(); TString label_Text; for (UInt_t i = 0; i < map->data_size_Y(); i++) { // Set a text for the label (i < plot_Lbl.size()) ? label_Text = *plot_Lbl[i] : label_Text.Form("Plot %i", i); // Creates the graphical label label.push_back(new TGLabel(Parent()->Window(), label_Text)); Parent()->Window()->AddFrame(label.back(), new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0)); label.back()->SetTextJustify(kTextLeft | kTextCenterY); label.back()->SetBackgroundColor(Parent()->Window()->GetBackground()); label.back()->SetForegroundColor(obj_foreColor); } } // ********************** // Object general methods // ********************** //______________________________________________________________________________ void gui_Plot::ReDraw() { // Redraw the object to keep it in pair with the general GUI parameters dbg_Print("gui_Plot::ReDraw:()", DBG_LVL_FLOW); // What we need here is to change the desk background color, this will in // turn trigger the re-rendering of the whole map color_Set(obj_foreColor, Parent()->backColor()); } //______________________________________________________________________________ void gui_Plot::color_Set(UInt_t foreColor, UInt_t backColor) { // Overloads the gui object color function dbg_Print("gui_Plot::color_Set:(default)", DBG_LVL_FLOW); // Set base object colors gui_2D::color_Set(foreColor, backColor); // Set labels color for (UInt_t i = 0; i < label.size(); i++) { label[i]->SetForegroundColor(foreColor); label[i]->SetBackgroundColor(Parent()->Window()->GetBackground()); } // Provides connections for the standard gui_Object color calls obj_foreColor = foreColor; obj_backColor = backColor; } //______________________________________________________________________________ void gui_Plot::Move(UInt_t left, UInt_t top) { // Moves the objrct dbg_Print("gui_Plot::Move:(default)", DBG_LVL_FLOW); // Moves the base object gui_2D::Move(left, top); // Moves the auto range button btn_Range->Move(left + obj_Width + k_palette_Margin - (Int_t)(k_btn_Radius / 2), top + obj_Height + k_palette_Margin / 2); // Moves the labels Int_t x_Pos = palette->GetX() + palette->GetWidth() + k_label_Margin; for (UInt_t i = 0; i < label.size(); i++) { Int_t y_Pos = i * k_palette_Width + top; label[i]->Move(x_Pos, y_Pos); } // Refresh the container //Update(); } //______________________________________________________________________________ void gui_Plot::MoveResize(UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // Moves and resizes the map frame dbg_Print("gui_Plot::MoveResize:(default)", DBG_LVL_FLOW); // Sets new object position obj_Left = left; obj_Top = top; // Resizes (this will also perform the move!) Resize(width, height); } //______________________________________________________________________________ void gui_Plot::Resize(UInt_t width, UInt_t height) { // Moves and resizes the map frame dbg_Print("gui_Plot::Resize:(default)", DBG_LVL_FLOW); // Do it with the base object gui_2D::Resize(width, height); // Move the ancyllary object accordingly Move(obj_Left, obj_Top); } //______________________________________________________________________________ void gui_Plot::LowerWindow() const { // Puts all the windows which compose the object to // the back of the Z-order stack dbg_Print("gui_Plot::LowerWindow:()", DBG_LVL_FLOW); // Base object gui_2D::LowerWindow(); // General buttons btn_Range->LowerWindow(); // Labels for (UInt_t i = 0; i < label.size(); i++) label[i]->LowerWindow(); } //______________________________________________________________________________ void gui_Plot::RaiseWindow() const { // Puts all the windows which compose the object on // the top of the Z-order stack dbg_Print("gui_Plot::RaiseWindow:()", DBG_LVL_FLOW); // Base object gui_2D::RaiseWindow(); // General buttons btn_Range->RaiseWindow(); // Labels for (UInt_t i = 0; i < label.size(); i++) label[i]->RaiseWindow(); }