Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 4057)
+++ trunk/MagicSoft/Mars/Changelog	(revision 4058)
@@ -18,4 +18,42 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+ 2004/05/12: Thomas Bretz
+
+   * mona.cc:
+     - changed names
+
+   * macros/sumcurrents.C:
+     - changed units from nA to \\mu A
+
+   *: mastro/MAstroCamera.[h,cc]:
+     - added '=' Draw option
+     - use fMapG directly
+
+   * mastro/MAstroCatalog.[h,cc]:
+     - added support to read and write a compressed catalog
+     - changed TExMap to new MGMap
+     - added support for HeasarcPPM catalog
+     - added PaintImg to paint catalog into a bitmap (used in
+       starguider software)
+     - don't clone MObservatory copy the contents
+     - changed type of dx and dy in DrawLine from Double to Int
+     - fixed drawig of the tooltip corresponding to the grid
+       (some were missing, some were existing twice)
+     - Now AddPrimitives takes fLimMag into account
+
+   * mhbase/MFillH.cc:
+     - added a const-qualifier
+
+   * mhist/MHCamera.cc:
+     - fixed a bug which caused SetPalette in the constructor to crash
+
+   * mbase/MGMap.[h,cc]:
+     - added
+
+   * mbase/Makefile, mbase/BaseLinkDef.h:
+     - added MGMap
+
+
 
  2004/05/11: Thomas Bretz
Index: trunk/MagicSoft/Mars/macros/sumcurrents.C
===================================================================
--- trunk/MagicSoft/Mars/macros/sumcurrents.C	(revision 4057)
+++ trunk/MagicSoft/Mars/macros/sumcurrents.C	(revision 4058)
@@ -97,5 +97,5 @@
 
     disp1->SetYTitle("I [nA]");
-    disp2->SetYTitle("\\sigma_{I} [nA]");
+    disp2->SetYTitle("\\sigma_{I} [\\mu A]");
     disp3->SetYTitle("\\sigma_{I} [%]");
     disp1->SetName("Currents;avg");
Index: trunk/MagicSoft/Mars/mastro/MAstroCamera.cc
===================================================================
--- trunk/MagicSoft/Mars/mastro/MAstroCamera.cc	(revision 4057)
+++ trunk/MagicSoft/Mars/mastro/MAstroCamera.cc	(revision 4058)
@@ -90,5 +90,5 @@
 
 #include "../mhist/MHCamera.h" // FIXME: This dependancy is very bad!
-                               // HOW TO GET RID OF IT? Move MHCamera to mgeom?
+                      // HOW TO GET RID OF IT? Move MHCamera to mgeom?
 
 //#include "MStarLocalPos.h"
@@ -292,4 +292,5 @@
 //  'c' Use the underlaying MHCamera as histogram
 //  '0' Draw the reflection on a virtual perfect mirror
+//  '=' Draw '0' or '*' propotional to the star magnitude
 //
 // If the Pad contains an object MHCamera of type MHCamera it is used.
@@ -312,4 +313,5 @@
     const Bool_t hasdot  = o.Contains(".", TString::kIgnoreCase);
     const Bool_t usecam  = o.Contains("c", TString::kIgnoreCase);
+    const Bool_t resize  = o.Contains("=", TString::kIgnoreCase);
 
     // Get camera
@@ -389,5 +391,5 @@
                 m->SetMarkerColor(kMagenta);
                 m->SetMarkerStyle(kDot);
-                AddMap(m);
+                fMapG.Add(m);
             }
             if (h)
@@ -402,5 +404,5 @@
         // transform meters into millimeters (camera display works with mm)
         mean *= 1./num;
-        DrawStar(mean(0), mean(1), *radec, !hasmean, Form("x=%.1fmm y=%.1fmm", mean(0), mean(1)));
+        DrawStar(mean(0), mean(1), *radec, hasmean?kBlack:-1, Form("x=%.1fmm y=%.1fmm", mean(0), mean(1)), resize);
 
         if (hasnull)
@@ -409,5 +411,6 @@
             star *= rot;
             const TVector3 spot = fMirror0->GetReflection(star, fGeom->GetCameraDist())*1000;
-            DrawStar(spot(0), spot(1), *radec, !hasmean, Form("x=%.1fmm y=%.1fmm", mean(0), mean(1)));
+            DrawStar(spot(0), spot(1), *radec, hasmean?kBlack:-1, Form("x=%.1fmm y=%.1fmm", mean(0), mean(1)), resize);
+            // This can be used to get the abberation...
             //cout << TMath::Hypot(spot(0), spot(1)) << " " << TMath::Hypot(mean(0)-spot(0), mean(1)-spot(1)) << endl;
         }
@@ -481,4 +484,6 @@
 // x [mm]: x coordinate in the camera plane (assuming a perfect mirror)
 // y [mm]: y coordinate in the camera plane (assuming a perfect mirror)
+//
+// We assume (0, 0) to be the center of the FOV
 //
 // dzd [deg]: Delta Zd
Index: trunk/MagicSoft/Mars/mastro/MAstroCatalog.cc
===================================================================
--- trunk/MagicSoft/Mars/mastro/MAstroCatalog.cc	(revision 4057)
+++ trunk/MagicSoft/Mars/mastro/MAstroCatalog.cc	(revision 4058)
@@ -128,4 +128,5 @@
 
 #include "MTime.h"
+//#include "MString.h"
 #include "MAstro.h"
 #include "MAstroSky2Local.h"
@@ -144,4 +145,28 @@
 using namespace std;
 
+void MVector3::WriteBinary(ostream &out) const
+{
+    const Double_t t = Theta();
+    const Double_t p = Phi();
+    const Float_t  m = Mag();
+    out.write((char*)&t, 8);
+    out.write((char*)&p, 8);
+    out.write((char*)&m, 4);
+    out << fName << endl;
+}
+
+void MVector3::ReadBinary(istream &in)
+{
+    Double_t t, p;
+    Float_t  m;
+
+    in.read((char*)&t, 8);
+    in.read((char*)&p, 8);
+    in.read((char*)&m, 4);
+    fName.ReadLine(in);
+
+    SetMagThetaPhi(m, t, p);
+}
+
 // --------------------------------------------------------------------------
 //
@@ -153,4 +178,5 @@
 {
     fList.SetOwner();
+    fMapG.SetOwner();
     fToolTip = new TGToolTip(0, "", 0);
 }
@@ -179,6 +205,4 @@
     fToolTip->Hide();
     delete fToolTip;
-
-    DeleteMap();
 }
 
@@ -253,5 +277,5 @@
     if (!fin)
     {
-        gLog << err << "Cannot open file " << catalog << ": ";
+        gLog << err << "Cannot open catalog file " << catalog << ": ";
         gLog << strerror(errno) << endl;
         return 0;
@@ -345,5 +369,5 @@
     if (!fin)
     {
-        gLog << err << "Cannot open file " << catalog << ": ";
+        gLog << err << "Cannot open catalog file " << catalog << ": ";
         gLog << strerror(errno) << endl;
         return 0;
@@ -420,5 +444,5 @@
     if (!fin)
     {
-        gLog << err << "Cannot open file " << catalog << ": ";
+        gLog << err << "Cannot open catalog file " << catalog << ": ";
         gLog << strerror(errno) << endl;
         return 0;
@@ -484,4 +508,173 @@
 // --------------------------------------------------------------------------
 //
+// Read from a ascii heasarc ppm catalog. set bit kHasChanged
+// Already read data is not deleted. To delete the stored data call
+// Delete().
+// If the second argument is given all survived stars are written
+// to a file outname. This files will contain an apropriate compressed
+// file format. You can read such files again using ReadCompressed.
+//
+Int_t MAstroCatalog::ReadHeasarcPPM(TString catalog, TString outname)
+{
+    SetBit(kHasChanged);
+
+    gLog << inf << "Reading Heasarc PPM catalog: " << catalog << endl;
+
+    ifstream fin(catalog);
+    if (!fin)
+    {
+        gLog << err << "Cannot open catalog file " << catalog << ": ";
+        gLog << strerror(errno) << endl;
+        return 0;
+    }
+
+    ofstream *fout = outname.IsNull() ? 0 : new ofstream(outname);
+    if (fout && !*fout)
+    {
+        gLog << warn << "Cannot open output file " << outname << ": ";
+        gLog << strerror(errno) << endl;
+        delete fout;
+        fout = 0;
+    }
+
+    Int_t add=0;
+    Int_t cnt=0;
+    Int_t n  =0;
+
+    Double_t maxmag=0;
+
+    while (1)
+    {
+        TString row;
+        row.ReadLine(fin);
+        if (!fin)
+            break;
+
+        cnt++;
+
+        if (!row.BeginsWith("PPM "))
+            continue;
+
+        const TString name = row(0, row.First('|'));
+        row = row(row.First('|')+1, row.Length());
+        row = row(row.First('|')+1, row.Length());
+
+        const TString vmag = row(0, row.First('|'));
+
+        n++;
+        const Double_t mag = atof(vmag.Data());
+        maxmag = TMath::Max(maxmag, mag);
+        if (mag>fLimMag)
+            continue;
+
+        row = row(row.First('|')+1, row.Length());
+        row = row(row.First('|')+1, row.Length());
+
+        row = row(row.First('|')+1, row.Length());
+        row = row(row.First('|')+1, row.Length());
+
+        row = row(row.First('|')+1, row.Length());
+        row = row(row.First('|')+1, row.Length());
+
+        const TString ra = row(0, row.First('|'));
+        row = row(row.First('|')+1, row.Length());
+        const TString de = row(0, row.First('|'));
+        row = row(row.First('|')+1, row.Length());
+
+        Char_t sgn;
+        Int_t d, m;
+        Float_t s;
+        if (sscanf(ra.Data(), "%d %d %f", &d, &m, &s)!=3)
+        {
+            // gLog << "Error loading entry in line " << i << endl;
+            continue;
+        }
+        const Double_t ra0 = MAstro::Hms2Rad(d, m, s);
+
+        if (sscanf(de.Data(), "%c%d %d %f", &sgn, &d, &m, &s)!=4)
+        {
+            // gLog << "Error loading entry in line " << i << endl;
+            continue;
+        }
+        const Double_t de0 = MAstro::Dms2Rad(d, m, s, sgn);
+
+        MVector3 *star=new MVector3;
+        star->SetRaDec(ra0, de0, mag);
+        star->SetName(name);
+        if (star->Angle(fRaDec)*TMath::RadToDeg()>fRadiusFOV)
+        {
+            delete star;
+            continue;
+        }
+
+        fList.Add(star);
+        add++;
+
+        if (fout)
+            star->WriteBinary(*fout);
+    }
+
+    gLog << inf << "Read " << add << " out of " << n << " (Total max mag=" << maxmag << ")" << endl;
+
+    return add;
+}
+
+// --------------------------------------------------------------------------
+//
+// Read from a MAstroCatalog compressed catalog. set bit kHasChanged
+// Already read data is not deleted. To delete the stored data call
+// Delete().
+//
+Int_t MAstroCatalog::ReadCompressed(TString catalog)
+{
+    SetBit(kHasChanged);
+
+    gLog << inf << "Reading MAstroCatalog compressed catalog: " << catalog << endl;
+
+    ifstream fin(catalog);
+    if (!fin)
+    {
+        gLog << err << "Cannot open catalog file " << catalog << ": ";
+        gLog << strerror(errno) << endl;
+        return 0;
+    }
+
+    Int_t add=0;
+    Int_t cnt=0;
+    Int_t n  =0;
+
+    Double_t maxmag=0;
+
+    MVector3 entry;
+
+    while (1)
+    {
+        cnt++;
+
+        entry.ReadBinary(fin);
+        if (!fin)
+            break;
+
+        n++;
+
+        const Double_t mag = entry.Magnitude();
+        maxmag = TMath::Max(maxmag, mag);
+        if (mag>fLimMag)
+            continue;
+
+        if (entry.Angle(fRaDec)*TMath::RadToDeg()>fRadiusFOV)
+            continue;
+
+        fList.Add(entry.Clone());
+        add++;
+    }
+
+    gLog << inf << "Read " << add << " out of " << n << " (Total max mag=" << maxmag << ")" << endl;
+
+    return add;
+}
+
+// --------------------------------------------------------------------------
+//
 // Set Range of pad. If something has changed create and draw new primitives.
 // Paint all gui primitives.
@@ -494,5 +687,55 @@
         DrawPrimitives(o);
 
-    PaintMap();
+    fMapG.Paint();
+}
+
+// --------------------------------------------------------------------------
+//
+// Set Range of pad if pad available. If something has changed create
+// and draw new primitives. Paint all gui primitives to the Drawable with
+// Id id. This can be used to be able to
+//
+/*
+void MAstroCatalog::PaintImg(Int_t id, Option_t *o)
+{
+    if (gPad)
+        SetRangePad(o);
+
+    if (TestBit(kHasChanged))
+    {
+        if (id>0)
+            gPad=0;
+        DrawPrimitives(o);
+    }
+
+    fMapG.Paint(id, fRadiusFOV);
+}
+*/
+
+// --------------------------------------------------------------------------
+//
+// Set Range of pad. If something has changed create and draw new primitives.
+// Paint all gui primitives.
+//
+// Because in some kind of multi-threaded environments gPad doesn't stay
+// the same in a single thread (because it might be changed in the same
+// thread inside a gui updating timer for example) we have to secure the
+// usage of gPad with a bit. This is also not multi-thread safe against
+// calling this function, but the function should work well in multi-
+// threaded environments. Never call this function from different threads
+// simultaneously.
+//
+void MAstroCatalog::PaintImg(unsigned char *buf, int w, int h)
+{
+    const char * o = "local mirrorx yellow *";
+
+    if (TestBit(kHasChanged))
+    {
+        SetBit(kDrawingImage);
+        DrawPrimitives(o);
+        ResetBit(kDrawingImage);
+    }
+
+    fMapG.Paint(buf, w, h, fRadiusFOV);
 }
 
@@ -503,23 +746,35 @@
 // x, y: Pad Coordinates to draw star
 // v: Sky position (Ra/Dec) of the star
-// transparent: Draw marker or tooltip only
+// col: Color of marker (<0 mean transparent)
 // txt: additional tooltip text
-//
-void MAstroCatalog::DrawStar(Double_t x, Double_t y, const TVector3 &v, Bool_t transparent, const char *txt)
+// resize: means resize the marker according to the magnitude
+//
+void MAstroCatalog::DrawStar(Double_t x, Double_t y, const TVector3 &v, Int_t col, const char *txt, Bool_t resize)
 {
     const Double_t ra  = v.Phi()*TMath::RadToDeg()/15;
     const Double_t dec = (TMath::Pi()/2-v.Theta())*TMath::RadToDeg();
 
-    TString str = v.GetName();
-    str += Form(":  Ra=%.2fh", ra);
-    str += Form("  Dec=%.1fd", dec);
-    str += Form("  Mag=%.1f", -2.5*log10(v.Mag()));
+    const Double_t mag = -2.5*log10(v.Mag());
+
+    //MString str;
+    //str.Print("%s:  Ra=%.2fh  Dec=%.1fd  Mag=%.1f", v.GetName(), ra, dec, mag);
+    TString str(Form("%s:  Ra=%.2fh  Dec=%.1fd  Mag=%.1f", v.GetName(), ra, dec, mag));
     if (txt)
-        str += Form("  (%s)", txt);
+    {
+        str += "  (";
+        str += txt;
+        str += ")";
+    }
 
     // draw star on the camera display
-    TMarker *tip=new TMarker(x, y, transparent ? kDot : kFullDotMedium);;
-    tip->SetMarkerColor(kBlack);
-    AddMap(tip, new TString(str));
+    TMarker *tip=new TMarker(x, y, col<0 ? kDot : kFullDotMedium);;
+    tip->SetMarkerColor(col);
+    fMapG.Add(tip, new TString(str));
+
+    if (!resize)
+        return;
+
+    tip->SetMarkerSize((10 - (mag>1 ? mag : 1))/15);
+    tip->SetMarkerStyle(kCircle);
 }
 
@@ -530,7 +785,7 @@
 void MAstroCatalog::Update(Bool_t upd)
 {
+    SetBit(kHasChanged);
     if (gPad && TestBit(kMustCleanup))
     {
-        SetBit(kHasChanged);
         gPad->Modified();
         if (upd)
@@ -560,5 +815,6 @@
     if (fObservatory)
         delete fObservatory;
-    fObservatory=(MObservatory*)obs.Clone();
+    fObservatory=new MObservatory;
+    obs.Copy(*fObservatory);
 }
 
@@ -588,4 +844,7 @@
         return kERROR;
 
+    if (TestBit(kDrawingImage) || !gPad)
+        return v.Mod2()<fRadiusFOV*fRadiusFOV;
+
     return v.X()>gPad->GetX1() && v.Y()>gPad->GetY1() &&
            v.X()<gPad->GetX2() && v.Y()<gPad->GetY2();
@@ -612,10 +871,14 @@
 // corresponding pad coordinates.
 //
-Bool_t MAstroCatalog::DrawLine(const TVector2 &v, Double_t dx, Double_t dy, const TRotation &rot, Int_t type)
+Bool_t MAstroCatalog::DrawLine(const TVector2 &v, Int_t dx, Int_t dy, const TRotation &rot, Int_t type)
 {
     const TVector2 add(dx*TMath::DegToRad(), dy*TMath::DegToRad());
 
-    TVector2 v0 = v;
-    TVector2 v1 = v+add;
+    // Define all lines in the same direction
+    const TVector2 va(dy==1?v:v+add);
+    const TVector2 vb(dy==1?v+add:v);
+
+    TVector2 v0(va);
+    TVector2 v1(vb);
 
     const Int_t rc0 = Convert(rot, v0);
@@ -629,14 +892,26 @@
     line->SetLineStyle(kDashDotted); //kDashed, kDotted, kDashDotted
     line->SetLineColor(kWhite+type*2);
-    AddMap(line);
-
-    const TVector2 deg = v*TMath::RadToDeg();
-    TString txt = type==1 ?
-        Form("Ra=%.2fh  Dec=%.1fd", fmod(deg.X()/15+48, 24),  fmod(90-deg.Y()+270,180)-90) :
-        Form("Zd=%.1fd  Az=%.1fd",  fmod(deg.Y()+270,180)-90, fmod(deg.X()+720, 360));
+    fMapG.Add(line);
+
+    if (dx!=0)
+        return kTRUE;
+
+    const TVector2 deg = va*TMath::RadToDeg();
+    /*
+    MString txt;
+    if (type==1)
+        txt.Print("Ra=%.2fh  Dec=%.1fd", fmod(deg.X()/15+48, 24),  fmod(90-deg.Y()+270,180)-90);
+    else
+        txt.Print("Zd=%.1fd  Az=%.1fd",  fmod(deg.Y()+270,180)-90, fmod(deg.X()+720, 360));
+        */
+    TString txt;
+    if (type==1)
+        txt = Form("Ra=%.2fh  Dec=%.1fd", fmod(deg.X()/15+48, 24),  fmod(90-deg.Y()+270,180)-90);
+    else
+        txt = Form("Zd=%.1fd  Az=%.1fd",  fmod(deg.Y()+270,180)-90, fmod(deg.X()+720, 360));
 
     TMarker *tip=new TMarker(v0.X(), v0.Y(), kDot);
     tip->SetMarkerColor(kWhite+type*2);
-    AddMap(tip, new TString(txt));
+    fMapG.Add(tip, new TString(txt));
 
     return kTRUE;
@@ -885,4 +1160,10 @@
 // be more far away from the center than the display shows.
 //
+// If you want the stars to be displayed as circles with a size
+// showing their magnitude use "*" as an option.
+//
+// Use 'white'  to display white instead of black stars
+// Use 'yellow' to display white instead of black stars
+//
 //
 void MAstroCatalog::AddPrimitives(TString o)
@@ -893,4 +1174,7 @@
     const Bool_t miry   = o.Contains("mirrory", TString::kIgnoreCase);
     const Bool_t mirror = o.Contains("mirror",  TString::kIgnoreCase) && !mirx && !miry;
+    const Bool_t size   = o.Contains("*",       TString::kIgnoreCase);
+    const Bool_t white  = o.Contains("white",   TString::kIgnoreCase);
+    const Bool_t yellow = o.Contains("yellow",  TString::kIgnoreCase) && !white;
 
     // X is vice versa, because ra is defined anti-clockwise
@@ -901,24 +1185,26 @@
 
     TIter Next(&fList);
-    TVector3 *v=0;
-    while ((v=(TVector3*)Next()))
-    {
-        // FIXME: Check Magnitude!
+    MVector3 *v=0;
+    while ((v=(MVector3*)Next()))
+    {
+        if (v->Magnitude()>fLimMag)
+            continue;
+
         TVector2 s(v->Phi(), v->Theta());
         if (Convert(rot, s)==kTRUE)
-            DrawStar(s.X(), s.Y(), *v, kFALSE);
-    }
-
-    if (!same)
+            DrawStar(s.X(), s.Y(), *v, yellow?kYellow:(white?kWhite:kBlack), 0, size);
+    }
+
+    if (!same && !TestBit(kDrawingImage) && gPad)
     {
         TPaveText *pv = new TPaveText(0.01, 0.90, 0.63, 0.99, "brNDC");
         pv->AddText(GetPadTitle());
-        AddMap(pv);
+        fMapG.Add(pv);
     }
 
     TMarker *mk=new TMarker(0, 0, kMultiply);
-    mk->SetMarkerColor(kBlack);
+    mk->SetMarkerColor(white||yellow?kWhite:kBlack);
     mk->SetMarkerSize(1.5);
-    AddMap(mk);
+    fMapG.Add(mk);
 }
 
@@ -935,5 +1221,5 @@
 
     const Double_t edge = fRadiusFOV/TMath::Sqrt(2.);
-    gPad->Range(-edge, -edge, edge, edge);
+    //gPad->Range(-edge, -edge, edge, edge);
 
     const Float_t w = gPad->GetWw();
@@ -956,7 +1242,8 @@
 void MAstroCatalog::DrawPrimitives(Option_t *o)
 {
-    DeleteMap();
-
-    SetRangePad(o);
+    fMapG.Delete();
+
+    if (!TestBit(kDrawingImage) && gPad)
+        SetRangePad(o);
 
 #ifdef DEBUG
@@ -971,20 +1258,8 @@
 
     // Append to a possible second pad
-    if (!gPad->GetListOfPrimitives()->FindObject(this))
+    if (!TestBit(kDrawingImage) && gPad && !gPad->GetListOfPrimitives()->FindObject(this))
         AppendPad(o);
 
     ResetBit(kHasChanged);
-}
-
-// --------------------------------------------------------------------------
-//
-// Call Paint() of all gui elements
-//
-void MAstroCatalog::PaintMap()
-{
-    Long_t key, val;
-    TExMapIter map(&fMapG);
-    while (map.Next(key, val))
-        ((TObject*)key)->Paint();
 }
 
@@ -1014,28 +1289,4 @@
 // --------------------------------------------------------------------------
 //
-// Search for an object at px, py in fMapG. Return the pointer to it
-// if found. Set str accordingly if a tooltip string is found.
-//
-TObject *MAstroCatalog::PickObject(Int_t px, Int_t py, TString &str) const
-{
-    Long_t key, val;
-    TExMapIter map(&fMapG);
-    while (map.Next(key, val))
-    {
-        if (!val)
-            continue;
-
-        TObject *o=(TObject*)key;
-        if (o->DistancetoPrimitive(px, py)>TPad::GetMaxPickDistance())
-            continue;
-
-        str = *(TString*)val;
-        return o;
-    }
-    return NULL;
-}
-
-// --------------------------------------------------------------------------
-//
 // This function was connected to all created canvases. It is used
 // to redirect GetObjectInfo into our own status bar.
@@ -1051,4 +1302,5 @@
     if (!gPad)
         return;
+
 
     // Try to find a corresponding object with kCannotPick set and
@@ -1056,5 +1308,5 @@
     TString str;
     if (!selected || selected==this)
-        selected = PickObject(px, py, str);
+        selected =  fMapG.PickObject(px, py, str);
 
     if (!selected)
@@ -1137,30 +1389,4 @@
 // --------------------------------------------------------------------------
 //
-// Calculate distance to primitive by checking all gui elements
-//
-Int_t MAstroCatalog::DistancetoPrimitive(Int_t px, Int_t py)
-{
-    Int_t min = INT_MAX;
-
-    Long_t key, val;
-    TExMapIter map(&fMapG);
-    while (map.Next(key, val))
-    {
-        TObject *o=(TObject*)key;
-
-        const Int_t d = o->DistancetoPrimitive(px, py);
-
-        if (d<TPad::GetMaxPickDistance())
-            return 0;
-
-        if (d<min)
-            min=d;
-    }
-
-    return min;
-}
-
-// --------------------------------------------------------------------------
-//
 // Displays a tooltip
 //
@@ -1184,4 +1410,13 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Calculate distance to primitive by checking all gui elements
+//
+Int_t MAstroCatalog::DistancetoPrimitive(Int_t px, Int_t py)
+{
+    return fMapG.DistancetoPrimitive(px, py);
+}
+
 // ------------------------------------------------------------------------
 //
@@ -1191,33 +1426,4 @@
 char *MAstroCatalog::GetObjectInfo(Int_t px, Int_t py) const
 {
-
-    TString str;
-    PickObject(px, py, str);
-
-    static char txt[129];
-    txt[128]=0;
-
-    return strncpy(txt, str.Data(), 128);
-}
-
-
-/*
-void MAstroCatalog::RecursiveRemove(TObject *obj)
-{
-    ULong_t hash;
-    Long_t key, val;
-
-    TExMapIter map(&fMapG);
-    while (map.Next(hash, key, val))
-    {
-        if (key != (Long_t)obj)
-            continue;
-
-        fMapG.Remove(hash, key);
-        delete (TObject*)(key);
-        if (val)
-            delete (TString*)(val);
-        break;
-    }
-}
-*/
+    return fMapG.GetObjectInfo(px, py);
+}
Index: trunk/MagicSoft/Mars/mastro/MAstroCatalog.h
===================================================================
--- trunk/MagicSoft/Mars/mastro/MAstroCatalog.h	(revision 4057)
+++ trunk/MagicSoft/Mars/mastro/MAstroCatalog.h	(revision 4058)
@@ -5,9 +5,9 @@
 #include <TVector3.h>
 #endif
-#ifndef ROOT_TExMap
-#include <TExMap.h>
-#endif
 #ifndef ROOT_TList
 #include <TList.h>
+#endif
+#ifndef MARS_MGMap
+#include <MGMap.h>
 #endif
 
@@ -57,4 +57,7 @@
     const char *GetName() const { return fName; }
 
+    void WriteBinary(ostream &out) const;
+    void ReadBinary(istream &in);
+
     ClassDef(MVector3, 1) // A specialized TVector3 storeing a star-name
 };
@@ -66,5 +69,4 @@
     Double_t   fRadiusFOV; // [deg] Radius of Field of View
 
-    TExMap     fMapG;      //! A map with all gui primitives and tooltips
     TGToolTip *fToolTip;   //! The tooltip currently displayed
 
@@ -80,4 +82,5 @@
 //#if ROOT_VERSION_CODE < ROOT_VERSION(4,00,03)
     Bool_t fPlainScreen;  //! Just a dummy!!!! ([Set,Is]Freezed)
+    Bool_t fNoToolTips;   //! Just a dummy!!!! ([Set,Is]Freezed)
 //#endif
 
@@ -86,69 +89,40 @@
     virtual void  SetRangePad(Option_t *o);
 
-    Int_t     Convert(const TRotation &rot, TVector2 &v) const;
-    void      Draw(const TVector2 &v0, const TRotation &rot, TArrayI &dx, TArrayI &dy, Int_t stepx, Int_t stepy, Int_t type);
-    void      DrawPrimitives(Option_t *o);
-    Bool_t    DrawLine(const TVector2 &v0, Double_t dx, Double_t dy, const TRotation &rot, Int_t type);
-    void      DrawGrid(const TVector3 &v0, const TRotation &rot, Int_t type);
-    void      Paint(Option_t *o="");
-    Int_t     DistancetoPrimitive(Int_t px, Int_t py);
-    //void      RecursiveRemove(TObject *obj);
-    void      PaintMap();
-    void      DeleteMap()
-    {
-        Long_t key, val;
-        TExMapIter map(&fMapG);
-        while (map.Next(key, val))
-        {
-            delete (TObject*)(key);
-            if (!val)
-                continue;
-
-            delete (TString*)(val);
-            /*
-              Long_t key2, val2;
-              TExMapIter map2(&fMapG);
-              while (map2.Next(key2, val2))
-                  if (val==val2)
-                  {
-                      delete (TObject*)key;
-                      fMapG.Remove(key);
-                  }
-             */
-        }
-        fMapG.Delete();
-    }
+    Int_t  Convert(const TRotation &rot, TVector2 &v) const;
+    void   Draw(const TVector2 &v0, const TRotation &rot, TArrayI &dx, TArrayI &dy, Int_t stepx, Int_t stepy, Int_t type);
+    void   DrawPrimitives(Option_t *o);
+    Bool_t DrawLine(const TVector2 &v0, Int_t dx, Int_t dy, const TRotation &rot, Int_t type);
+    void   DrawGrid(const TVector3 &v0, const TRotation &rot, Int_t type);
+    void   Paint(Option_t *o="");
+    Int_t  DistancetoPrimitive(Int_t px, Int_t py);
 
 protected:
     enum {
-        kHasChanged  = BIT(15), // Display has changed
-        kGuiActive   = BIT(16), // GUI is interactive
-        kPlainScreen = BIT(17), // View is a plain screen view
-        kMirrorX     = BIT(18), // Mirror display in X
-        kMirrorY     = BIT(19), // Mirror display in Y
-        kNoToolTips  = BIT(20)  // suppress tooltips
+        kHasChanged   = BIT(15), // Display has changed
+        kGuiActive    = BIT(16), // GUI is interactive
+        kPlainScreen  = BIT(17), // View is a plain screen view
+        kMirrorX      = BIT(18), // Mirror display in X
+        kMirrorY      = BIT(19), // Mirror display in Y
+        kNoToolTips   = BIT(20), // suppress tooltips
+        kDrawingImage = BIT(21)  // just drawing into a bitmap
     };
 
-    TList    fList;             // List of stars loaded
-    MVector3 fRaDec;            // pointing position
+    MGMap    fMapG;              //! A map with all gui primitives and tooltips
 
-    MObservatory *fObservatory; // Possible obervatory location
-    MTime        *fTime;        // Possible observation time
+    TList    fList;              // List of stars loaded
+    MVector3 fRaDec;             // pointing position
+
+    MObservatory *fObservatory;  // Possible obervatory location
+    MTime        *fTime;         // Possible observation time
 
     TRotation AlignCoordinates(const TVector3 &v) const;
     virtual TString GetPadTitle() const;
     TRotation GetGrid(Bool_t local);
-    void      DrawStar(Double_t x, Double_t y, const TVector3 &v, Bool_t t, const char *txt=0);
+    void      DrawStar(Double_t x, Double_t y, const TVector3 &v, Int_t col, const char *txt=0, Bool_t resize=kFALSE);
     void      Update(Bool_t upd=kFALSE);
 
     void      ExecuteEventKbd(Int_t keycode, Int_t keysym);
     void      ExecuteEvent(Int_t event, Int_t mp1, Int_t mp2);
-    TObject  *PickObject(Int_t px, Int_t py, TString &str) const;
     char     *GetObjectInfo(Int_t px, Int_t py) const;
-
-    void AddMap(TObject *k, void *v=0)
-    {
-        fMapG.Add(fMapG.GetSize(), (Long_t)k, (Long_t)v);
-    }
 
 public:
@@ -172,4 +146,13 @@
         Update();
     } // *MENU* *ARGS={deg=>fRadiusFOV}
+    void SetRadiusFOV(Double_t pixsize, Double_t w, Double_t h)
+    {
+        // pixsize [arcsec/pixel]
+        // w       [pixel]
+        // h       [pixel]
+        const Double_t scale = TMath::Hypot(w, h)/2;
+        SetRadiusFOV(scale*pixsize/3600);
+    } // Set Radius of FOV using the pixsize [arcsec/pix], width and height [pixel] of image
+
     void SetRaDec(Double_t ra, Double_t dec) { fRaDec.SetRaDec(ra, dec, 1); Update(); }
     void SetRaDec(const TVector3 &v)         { fRaDec=v; Update(); }
@@ -185,9 +168,11 @@
     Double_t GetRadiusFOV() const { return fRadiusFOV; } // Get maximum radius of Field Of View
 
-    void Delete(Option_t *o="") { fList.Delete(); DeleteMap(); } // Delete list of stars
+    void Delete(Option_t *o="") { fList.Delete(); fMapG.Delete(); } // Delete list of stars
 
     Int_t ReadXephem(TString catalog = "/usr/X11R6/lib/xephem/catalogs/YBS.edb");
     Int_t ReadNGC2000(TString catalog = "ngc2000.dat");
     Int_t ReadBSC(TString catalog = "bsc5.dat");
+    Int_t ReadHeasarcPPM(TString catalog = "heasarc_ppm.tdat", TString fout="");
+    Int_t ReadCompressed(TString catalog);
 
     void Print(Option_t *o="") const { fList.Print(); } // Print all stars
@@ -195,4 +180,6 @@
     TList *GetList() { return &fList; } // Return list of stars
 
+    //void PaintImg(Int_t id=0, Option_t *o="");
+    void PaintImg(unsigned char *buf, int w=768, int h=576);
     void Draw(Option_t *o="");
     void SetDrawOption(Option_t *option="")
Index: trunk/MagicSoft/Mars/mbase/BaseLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/BaseLinkDef.h	(revision 4057)
+++ trunk/MagicSoft/Mars/mbase/BaseLinkDef.h	(revision 4058)
@@ -47,5 +47,9 @@
 #pragma link C++ class MGTask+;
 #pragma link C++ class MGList+;
+#pragma link C++ class MGMap+;
 #pragma link C++ class MGGroupFrame+;
+
+// Root enhancements
+//#pragma link C++ class MGraph+;
 
 // Basic containers
Index: trunk/MagicSoft/Mars/mbase/MGMap.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MGMap.cc	(revision 4057)
+++ trunk/MagicSoft/Mars/mbase/MGMap.cc	(revision 4058)
@@ -52,4 +52,8 @@
 using namespace std;
 
+//
+// THIS IS A WORKAROUND TO GET A MORE DIRECT ACCESS TO TGX11
+//
+/*
 #include <TGX11.h>
 class MGX11 : public TGX11
@@ -114,5 +118,5 @@
     }
 };
-
+*/
 // --------------------------------------------------------------------------
 //
@@ -187,4 +191,5 @@
 //        find a way to get it from the drawable.
 //
+/*
 void MGMap::Paint(Drawable_t id, Float_t scale)
 {
@@ -206,4 +211,5 @@
     }
 }
+*/
 
 // --------------------------------------------------------------------------
Index: trunk/MagicSoft/Mars/mbase/MGMap.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MGMap.h	(revision 4057)
+++ trunk/MagicSoft/Mars/mbase/MGMap.h	(revision 4058)
@@ -36,6 +36,6 @@
 
     void     Paint(Option_t *o="");
-    void     Paint(Drawable_t id, Float_t scale);
     void     Paint(unsigned char *buf, int w, int h, Float_t scale);
+    //void     Paint(Drawable_t id, Float_t scale);
 
     Int_t    Color(int col);
Index: trunk/MagicSoft/Mars/mbase/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mbase/Makefile	(revision 4057)
+++ trunk/MagicSoft/Mars/mbase/Makefile	(revision 4058)
@@ -36,4 +36,5 @@
            MSearch.cc \
            MGMenu.cc \
+           MGMap.cc \
            MIter.cc \
            MDirIter.cc \
Index: trunk/MagicSoft/Mars/mhbase/MFillH.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MFillH.cc	(revision 4057)
+++ trunk/MagicSoft/Mars/mhbase/MFillH.cc	(revision 4058)
@@ -524,5 +524,5 @@
         fCanvas->cd();
 
-    Bool_t rc = fH->Fill(fParContainer, fWeight?fWeight->GetWeight():1);
+    const Bool_t rc = fH->Fill(fParContainer, fWeight?fWeight->GetWeight():1);
 
     if (save && fCanvas)
Index: trunk/MagicSoft/Mars/mhist/MHCamera.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 4057)
+++ trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 4058)
@@ -100,4 +100,6 @@
     gROOT->GetListOfCleanups()->Add(fNotify);
 
+    TVirtualPad *save = gPad;
+    gPad = 0;
 #if ROOT_VERSION_CODE < ROOT_VERSION(3,01,06)
     SetPalette(1, 0);
@@ -105,4 +107,5 @@
     SetInvDeepBlueSeaPalette();
 #endif
+    gPad = save;
 }
 
@@ -928,4 +931,10 @@
 
 
+// ------------------------------------------------------------------------
+//
+// Changes the palette of the displayed camera histogram.
+//
+// Change to the right pad first - otherwise GetDrawOption() might fail.
+//
 void MHCamera::SetPrettyPalette()
 {
@@ -934,4 +943,10 @@
 }
 
+// ------------------------------------------------------------------------
+//
+// Changes the palette of the displayed camera histogram.
+//
+// Change to the right pad first - otherwise GetDrawOption() might fail.
+//
 void MHCamera::SetDeepBlueSeaPalette()
 {
@@ -940,4 +955,10 @@
 }
 
+// ------------------------------------------------------------------------
+//
+// Changes the palette of the displayed camera histogram.
+//
+// Change to the right pad first - otherwise GetDrawOption() might fail.
+//
 void MHCamera::SetInvDeepBlueSeaPalette()
 {
@@ -946,4 +967,12 @@
 }
 
+// ------------------------------------------------------------------------
+//
+// Paint indices (as text) inside the pixels. Depending of the type-
+// argument we paint:
+//  0: pixel number
+//  1: sector number
+//  2: content
+//
 void MHCamera::PaintIndices(Int_t type)
 {
Index: trunk/MagicSoft/Mars/mona.cc
===================================================================
--- trunk/MagicSoft/Mars/mona.cc	(revision 4057)
+++ trunk/MagicSoft/Mars/mona.cc	(revision 4058)
@@ -291,5 +291,5 @@
     }
 
-    TApplication app("Mars", &argc, argv);
+    TApplication app("Mona", &argc, argv);
     if (gROOT->IsBatch() || !gClient)
     {
@@ -314,4 +314,7 @@
     gLog << dbg << "Starting Display..." << flush;
     MOnlineDisplay d;
+    d.SetWindowName("Magic ONline Analysis");
+    d.SetIconName("Mona");
+
     d.SetBit(MStatusDisplay::kExitLoopOnExit);
     gLog << "done." << endl;
