//------------------------------------------------------------------------------ // gui_Map class -- // (C) Piero Giubilato 2008-2010, Berkeley Lab -- //------------------------------------------------------------------------------ //______________________________________________________________________________ // {Trace} // [File name] "gui_Map.cpp" // [Author] "Piero Giubilato" // [Version] "2.0" // [Modified by] "Piero Giubilato" // [Last revision] "02 Jul 2009" // [Language] "C++" // [Compiler] "Visual C++ 9.x" // [Member of] "Cool SEAL" // [Project] "SEAL" // [Description] "Source for the gui_Map class" // [Key documentation] // "Visual C++ Reference Help" // "Root reference guide" // {Trace} //______________________________________________________________________________ // Standard component #include // Root Component #include // Application component #include "global.h" #include "gui_Map.h" // CINT Preprocessor class import definition ClassImp(gui_Map) //______________________________________________________________________________ gui_Map::gui_Map(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_Map::gui_Map:(default)", DBG_LVL_ZERO); // Sets up the map Init(left, top, width, height, textColor); } //______________________________________________________________________________ gui_Map::gui_Map(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_Map::gui_Map:(gui_Object*)", DBG_LVL_ZERO); // Sets up the map Init(left, top, width, height, textColor); } //______________________________________________________________________________ void gui_Map::Init(UInt_t left, UInt_t top, UInt_t width, UInt_t height, UInt_t textColor) { // Common init procedure // Sets the gui_2D as a map map->data_Style(gso_Map2D::ks_Map); // Do all necessary conncetions map->Connect(map, "data_Changed()", "gui_Map", this, "map_data_changed_Do()"); map->Connect(map, "range_Updated()", "gui_Map", this, "map_range_Do()"); // Creates two numeric for data range for (UInt_t i = 0; i < 2; i++) { num_Pal.push_back(new TGNumberEntry(Parent()->Window(), 0)); num_Pal.back()->Connect(num_Pal.back(), "ValueSet(Long_t)", "gui_Map", this, "num_pal_Do(Long_t)"); Parent()->Window()->AddFrame(num_Pal.back(), new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0)); } // Creates the labels label.clear(); UInt_t label_Count = (UInt_t)(height / 128); for (UInt_t i = 0; i <= label_Count; i++) { label.push_back(new TGLabel(Parent()->Window(), "Blank label")); Parent()->Window()->AddFrame(label.back(), new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0)); label.back()->SetBackgroundColor(Parent()->Window()->GetBackground()); label.back()->SetForegroundColor(textColor); } // 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_Map", this, "btn_range_Do()"); // Updates the label label_Set(); // Defines the object as transparent gui_Object::obj_Transparent = true; // Show the object MoveResize(left, top, width, height); } //______________________________________________________________________________ gui_Map::~gui_Map() { // Default destructor. dbg_Print("gui_Map::~gui_Map()", DBG_LVL_ZERO); // Removes the num_Pal for (UInt_t i = 0; i < 2; i++) { Parent()->Window()->RemoveFrame(num_Pal[i]); num_Pal[i]->DestroyWindow(); delete num_Pal[i]; } // 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_Map::map_data_changed_Do() { // Handles the changing of the displayed data // This function is connected to the gso_Map objeect directly, and it is // triggered everytime the data pointer is updated. dbg_Print("gui_Map::map_data_changed_Do()", DBG_LVL_FLOW); // Recreates the labels //label_Set(); } //______________________________________________________________________________ void gui_Map::btn_range_Do() { // Handles the ROI numeric events dbg_Print("gui_Map::btn_range_Do()", DBG_LVL_FLOW); // Change the map auto range status if (btn_Range->Status() == btn_Range->kb_Raised) map->range_Auto(false); else map->range_Auto(true); } //______________________________________________________________________________ void gui_Map::num_pal_Do(Long_t) { // Handles the Pal numeric events dbg_Print("gui_Map::num_pal_Do:(Long_t)", DBG_LVL_FLOW); // Set the new map palette ranges map->range_Set(num_Pal[0]->GetNumber(), num_Pal[1]->GetNumber()); // Updates the labels label_Set(); } //______________________________________________________________________________ void gui_Map::map_range_Do() { // Handles the range changes from the map dbg_Print("gui_Map::map_range_Do:()", DBG_LVL_FLOW); //std::cout << "Map range updated\n"; // Updates the range labels label_Set(); // Update range button status if (map->range_Auto()) { //btn_Range->Status(gso_Button::ks_Down); //std::cout << "now range is ON" << "\n"; } else { //btn_Range->Status(gso_Button::ks_Up); //std::cout << "now range is OFF" << "\n"; } } // ************************ // gui_Map specific methods // ************************ //______________________________________________________________________________ bool gui_Map::range_Auto() const { // Returns the palette maximum range dbg_Print("gui_Map::range_Auto:()", DBG_LVL_FLOW); return map->range_Auto(); } //______________________________________________________________________________ void gui_Map::range_Auto(bool automatic) { // Sets the palette maximum range dbg_Print("gui_Map::range_Auto:(bool)", DBG_LVL_FLOW); map->range_Auto(automatic); // Updates labels //label_Set(); } //______________________________________________________________________________ Double_t gui_Map::range_Max() const { // Returns the palette maximum range dbg_Print("gui_Map::range_Max:()", DBG_LVL_FLOW); return map->range_Max(); } //______________________________________________________________________________ Double_t gui_Map::range_Min() const { // Returns the palette minimum range dbg_Print("gui_Map::range_Min:()", DBG_LVL_FLOW); return map->range_Min(); } //______________________________________________________________________________ void gui_Map::range_Max(Double_t max) { // Sets the palette maximum range dbg_Print("gui_Map::range_Max:(Double)", DBG_LVL_FLOW); map->range_Max(max); } //______________________________________________________________________________ void gui_Map::range_Min(Double_t min) { // Sets the palette minimum range dbg_Print("gui_Map::range_Min:(Double)", DBG_LVL_FLOW); map->range_Min(min); // Updates map and labels //label_Set(); } //______________________________________________________________________________ void gui_Map::range_Color(UInt_t* col_List, UInt_t col_Count) { // Updates the palette dbg_Print("gui_Map::range_Color:(default)", DBG_LVL_FLOW); palette->color_Set(col_List, col_Count); // Refreshes the map map->Refresh(); } //______________________________________________________________________________ void gui_Map::label_Set() { // Sets the values into the labels dbg_Print("gui_Map::label_Set:()", DBG_LVL_FLOW); // Pivot vars Double_t range_Max = map->range_Max(); Double_t range_Min = map->range_Min(); Double_t range_Step = (range_Max - range_Min) / (label.size() + 1); // Updates the two numeric num_Pal[0]->SetNumber(range_Max); num_Pal[1]->SetNumber(range_Min); // Computes the labels TString label_Text; double label_Value; for (UInt_t i = 0; i < label.size(); i++) { label_Value = (double)((long)((range_Min + (Double_t)(i + 1) * range_Step) * 100))/100; label_Text.Form("%g", label_Value); label[i]->ChangeText(label_Text.Data()); label[i]->SetTextJustify(kTextLeft | kTextCenterY); } } // ********************** // Object general methods // ********************** //______________________________________________________________________________ void gui_Map::ReDraw() { // Redraw the object to keep it in pair with the general GUI parameters dbg_Print("gui_CoolButton::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_Map::color_Set(UInt_t foreColor, UInt_t backColor) { // Overloads the gui object color function dbg_Print("gui_Map::color_Set:(default)", DBG_LVL_FLOW); // Set base object colors gui_2D::color_Set(foreColor, backColor); // Set buttons color btn_Range->SetColor(k_btn_Color, 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_Map::Move(UInt_t left, UInt_t top) { // 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 num_Pal num_Pal[0]->Move(left + obj_Width + (Int_t)(k_palette_Margin * 1.5) + k_palette_Width, top); num_Pal[1]->Move(left + obj_Width + (Int_t)(k_palette_Margin * 1.5) + k_palette_Width, top + obj_Height - num_Pal[1]->GetHeight()); // 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 = (UInt_t)floor((Double_t)(i + 1) / (label.size() + 1) * obj_Height); label[i]->Move(x_Pos, top + obj_Height - y_Pos - label[i]->GetHeight() / 2); } } //______________________________________________________________________________ void gui_Map::MoveResize(UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // Moves and resizes the map frame dbg_Print("gui_Map::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_Map::Resize(UInt_t width, UInt_t height) { // Moves and resizes the map frame dbg_Print("gui_Map::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_Map::LowerWindow() const { // Puts all the windows which compose the object to // the back of the Z-order stack dbg_Print("gui_Map::LowerWindow:()", DBG_LVL_FLOW); // Base object gui_2D::LowerWindow(); // General buttons btn_Range->LowerWindow(); // Palette num for (UInt_t i = 0; i < num_Pal.size(); i++) num_Pal[i]->LowerWindow(); // Labels for (UInt_t i = 0; i < label.size(); i++) label[i]->LowerWindow(); } //______________________________________________________________________________ void gui_Map::RaiseWindow() const { // Puts all the windows which compose the object on // the top of the Z-order stack dbg_Print("gui_Map::RaiseWindow:()", DBG_LVL_FLOW); // Base object gui_2D::RaiseWindow(); // General buttons btn_Range->RaiseWindow(); // Palette num for (UInt_t i = 0; i < num_Pal.size(); i++) num_Pal[i]->RaiseWindow(); // Labels for (UInt_t i = 0; i < label.size(); i++) label[i]->RaiseWindow(); }