//------------------------------------------------------------------------------ // gui_Map class -- // (C) Piero Giubilato 2008-2010, Berkeley Lab -- //------------------------------------------------------------------------------ //______________________________________________________________________________ // {Trace} // [File name] "gui_Map.cpp" // [Author] "Piero Giubilato" // [Version] "0.6" // [Modified by] "Piero Giubilato" // [Last revision] "10 Feb 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(const UShort_t* data, UInt_t data_Width, UInt_t data_Height, UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // This object presents a color-graded representation of a bidimensional // data structure (array). It embeds two basic GSO level objects, a map // and a palette, plus the label to show the current range. It accepts // 6 data types or structures (US, S, UI, I, F, D). // UShort_t constructor dbg_Print("gui_Map::gui_Map:(UShort)", DBG_LVL_ZERO); // Creates palette, map and places all the stuff palette = new gso_Palette(Container(), k_palette_Width, height); map = new gso_Map2D(Container(), palette, data, data_Width, data_Height, width, height); // Complete the object construction Init(left, top, width, height); } //______________________________________________________________________________ gui_Map::gui_Map(const Short_t* data, UInt_t data_Width, UInt_t data_Height, UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // Short_t constructor dbg_Print("gui_Map::gui_Map:(Short)", DBG_LVL_ZERO); // Creates palette, map and places all the stuff palette = new gso_Palette(Container(), k_palette_Width, height); map = new gso_Map2D(Container(), palette, data, data_Width, data_Height, width, height); Init(left, top, width, height); } //______________________________________________________________________________ gui_Map::gui_Map(const UInt_t* data, UInt_t data_Width, UInt_t data_Height, UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // UInt_t constructor dbg_Print("gui_Map::gui_Map:(UInt)", DBG_LVL_ZERO); // Creates palette, map and places all the stuff palette = new gso_Palette(Container(), k_palette_Width, height); map = new gso_Map2D(Container(), palette, data, data_Width, data_Height, width, height); Init(left, top, width, height); } //______________________________________________________________________________ gui_Map::gui_Map(const Int_t* data, UInt_t data_Width, UInt_t data_Height, UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // Int_t constructor dbg_Print("gui_Map::gui_Map:(Int)", DBG_LVL_ZERO); // Creates palette, map and places all the stuff palette = new gso_Palette(Container(), k_palette_Width, height); map = new gso_Map2D(Container(), palette, data, data_Width, data_Height, width, height); Init(left, top, width, height); } //______________________________________________________________________________ gui_Map::gui_Map(const Float_t* data, UInt_t data_Width, UInt_t data_Height, UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // Float_t constructor dbg_Print("gui_Map::gui_Map:(Float)", DBG_LVL_ZERO); // Creates palette, map and places all the stuff palette = new gso_Palette(Container(), k_palette_Width, height); map = new gso_Map2D(Container(), palette, data, data_Width, data_Height, width, height); Init(left, top, width, height); } //______________________________________________________________________________ gui_Map::gui_Map(const Double_t* data, UInt_t data_Width, UInt_t data_Height, UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // Double_t constructor dbg_Print("gui_Map::gui_Map:(Double)", DBG_LVL_ZERO); // Creates palette, map and places all the stuff palette = new gso_Palette(Container(), k_palette_Width, height); map = new gso_Map2D(Container(), palette, data, data_Width, data_Height, width, height); Init(left, top, width, height); } */ //______________________________________________________________________________ gui_Map::gui_Map(UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // Default, no data constructor dbg_Print("gui_Map::gui_Map:(default)", DBG_LVL_ZERO); // Creates palette, map and places all the stuff palette = new gso_Palette(Container(), k_palette_Width, height); map = new gso_Map2D(Container(), palette, width, height); Init(left, top, width, height); } //______________________________________________________________________________ gui_Map::~gui_Map() { // Default destructor. dbg_Print("gui_Map::~gui_Map()", DBG_LVL_ZERO); // Deletes the map Container()->RemoveFrame(map); map->DestroyWindow(); delete map; // Deletes the palette Container()->RemoveFrame(palette); palette->DestroyWindow(); delete palette; // Removes the labels for (UInt_t i = 0; i < label.size(); i++) { Container()->RemoveFrame(label[i]); label[i]->DestroyWindow(); delete label[i]; } } //______________________________________________________________________________ void gui_Map::Init(UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // Completes the construction of the object after that the specialized // constructor has properly initialized the pixmap Map2D object. dbg_Print("gui_Map::Init:(default)", DBG_LVL_MAKE); // Adds the map to the container Container()->AddFrame(map, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0)); // Adds the labels label.clear(); UInt_t label_Count = (UInt_t)(height / 64) + 1; for (UInt_t i = 0; i <= label_Count; i++) { label.push_back(new TGLabel(Container(), "Blank label")); Container()->AddFrame(label.back(), new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0)); label.back()->SetBackgroundColor(Container()->GetBackground()); } // Updates the label label_Set(); // Defines the object as transparent gui_Object::obj_Transparent = true; // Show the object MoveResize(left, top, width, height); } //______________________________________________________________________________ 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); // Updates labels label_Set(); } //______________________________________________________________________________ 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(); // Computes the labels TString label_Text; Double_t label_Value; for (UInt_t i = 0; i < label.size(); i++) { label_Value = ((Double_t)i / (label.size() - 1))*(range_Max - range_Min)+ range_Min; label_Text.Form("%g", label_Value); label[i]->ChangeText(label_Text.Data()); label[i]->SetTextJustify(kTextLeft | kTextCenterY); } } //______________________________________________________________________________ void gui_Map::Refresh() { // Rereads the map data dbg_Print("gui_Map::refresh:()", DBG_LVL_FLOW); // Tells the map to update itself map->Refresh(); // Updates labels in case if (map->range_Auto()) label_Set(); } //______________________________________________________________________________ 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 button color_Set(gui_Object::obj_foreColor, Container()->GetBackground()); } //______________________________________________________________________________ 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 labels color for (UInt_t i = 0; i < label.size(); i++) { label[i]->SetForegroundColor(foreColor); label[i]->SetBackgroundColor(backColor); } // Provides connections for the standard gui_Object color calls gui_Object::obj_foreColor = foreColor; gui_Object::obj_backColor = backColor; } //______________________________________________________________________________ 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); map->MoveResize(left, top, width, height); // Moves and resize the palette frame palette->MoveResize(left + width + k_palette_Margin, top, k_palette_Width, height); // Moves the labels for (UInt_t i = 0; i < label.size(); i++) { UInt_t v_Pos = (UInt_t)floor((Double_t)i / (label.size() - 1) * height); label[i]->Move(palette->GetX() + palette->GetWidth() + k_label_Margin, top + height - v_Pos - label[i]->GetHeight() / 2); } // Stores the new datas obj_Left = left; obj_Top = top; obj_Width = width; obj_Height = height; // Refresh the container Update(); }