Index: /trunk/MagicSoft/Cosy/gui/MGCosy.cc
===================================================================
--- /trunk/MagicSoft/Cosy/gui/MGCosy.cc	(revision 8823)
+++ /trunk/MagicSoft/Cosy/gui/MGCosy.cc	(revision 8824)
@@ -37,5 +37,6 @@
 #include "SlaStars.h"
 
-#undef DEBUG
+#define DEBUG
+//#undef DEBUG
 //#define EXPERT
 //#define HAS_DEMO
@@ -84,30 +85,27 @@
 void MGCosy::CreateMenu()
 {
-    TGLayoutHints *laymenubar  = new TGLayoutHints (kLHintsNormal | kLHintsExpandX);
-    TGLayoutHints *laymenuitem = new TGLayoutHints (kLHintsNormal, 0, 4, 0, 0);
-    fList->Add(laymenubar);
-    fList->Add(laymenuitem);
+    //
+    //  the button messages are handled by main frame (this)
+    //
+    TGMenuBar   *menubar  = new TGMenuBar(this, 1, 1, kHorizontalFrame);
+    TGPopupMenu *filemenu = menubar->AddPopup("&File");
+    TGPopupMenu *logmenu  = menubar->AddPopup("&Log");
 
     //
     //  crate the menu bar
     //
-    TGPopupMenu *filemenu = new TGPopupMenu(gClient->GetRoot());
     filemenu->AddEntry("Set Aspect", IDM_ASPECT);
     filemenu->AddEntry("Exit", IDM_EXIT);
     filemenu->Associate(this);
-    fList->Add(filemenu);
 
     //
     // Log Menu
     //
-    TGPopupMenu *logmenu = new TGPopupMenu(gClient->GetRoot());
     logmenu->AddEntry("&Copy Selected", kLogCopy);
     logmenu->AddEntry("&Select All",    kLogSelect);
     logmenu->AddSeparator();
     logmenu->AddEntry("Clear &all",     kLogClear);
-    /*
-     logmenu->AddSeparator();
-     logmenu->AddEntry("Search",         kLogSearch);
-     */
+    //logmenu->AddSeparator();
+    //logmenu->AddEntry("Search",         kLogSearch);
     logmenu->AddSeparator();
     logmenu->AddEntry("Sa&ve",          kLogSave);
@@ -116,18 +114,17 @@
 
     //
-    //  the button messages are handled by main frame (this)
-    //
-    TGMenuBar *menubar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
-    menubar->AddPopup("File", filemenu, laymenuitem);
-    menubar->AddPopup("Lo&g", logmenu,  laymenuitem);
-    AddFrame(menubar, laymenubar);
-    fList->Add(menubar);
-
-    //
     //  Seperator beyond menubar
     //
     TGHorizontal3DLine *linesep = new TGHorizontal3DLine(this);
-    AddFrame(linesep, laymenubar);
-    fList->Add(linesep);
+
+    //
+    // Setup Frames
+    //
+    TGLayoutHints *laymenubar  = new TGLayoutHints (kLHintsNormal | kLHintsExpandX);
+
+    AddFrame(menubar, (TGLayoutHints*)laymenubar->Clone());
+    AddFrame(linesep, (TGLayoutHints*)laymenubar->Clone());
+
+    delete laymenubar;
 }
 
@@ -449,9 +446,9 @@
     l2->Move(x, y+h);
     l3->Move(x, y+2*h);
-    l4->Move(x, y+3*h);
+    //l4->Move(x, y+3*h);
     fList->Add(l1);
     fList->Add(l2);
     fList->Add(l3);
-    fList->Add(l4);
+    //fList->Add(l4);
 
 #ifdef EXPERT
@@ -713,69 +710,51 @@
     : TGMainFrame(p, w, h), fObservatory(key), fQueue(q)
 {
+    // This means that all objects added with AddFrame are deleted
+    // automatically, including all LayoutHints.
+    SetCleanup();
+
     fList = new MGList;
+    fList->SetOwner();
 
     fFont = gVirtualX->LoadQueryFont("7x13bold");
 
-#ifdef DEBUG
-    cout << "MGCosy: Creating Menu" << endl;
-#endif
     CreateMenu();
 
-#ifdef DEBUG
-    cout << "MGCosy: Creating TGCompositeFrame" << endl;
-#endif
     TGHorizontalFrame *f1 = new TGHorizontalFrame(this, 0, 0);
     TGHorizontalFrame *f2 = new TGHorizontalFrame(this, 0, 0);
-    fList->Add(f1);
-    fList->Add(f2);
-
-#ifdef DEBUG
-    cout << "MGCosy: Creating TGTab" << endl;
-#endif
+    f1->SetCleanup();
+    f2->SetCleanup();
+    //fList->Add(f1);
+    //fList->Add(f2);
+
     fTab = new TGTab(f1, 300, 300);
-    fList->Add(fTab);
-
-#ifdef DEBUG
-    cout << "MGCosy: Creating MGSkyPosition" << endl;
-#endif
+    //fList->Add(fTab);
+
     fSkyPosition = new MGSkyPosition(fObservatory, f1, 300);
-#ifdef DEBUG
-    cout << "MGCosy: Creating MGAccuracy" << endl;
-#endif
+
     fAccuracy = new MGAccuracy(f1, 300);
     fAccuracy->DrawText("0.5se", "1.0se", "2.0se", "Ctrl Deviation [min]");
     fAccuracy->DrawCircles();
-#ifdef DEBUG
-    cout << "MGCosy: Creating MGVelocity" << endl;
-#endif
 
     fImage = new MGImage(f2, 768/2-1, 576/2-1, kRaisedFrame);
     //fVelocity = new MGVelocity(f2, "Velocity [U_{mot}/min]", 300);
     //    fOffset      = new MGVelocity   (f, "Offset se-re [']", 300);
-#ifdef DEBUG
-    cout << "MGCosy: Creating MGVelocityTime" << endl;
-#endif
 //  fAccuracyTime = new MGAccuracyTime(f2, 300);
 
-    fList->Add(fSkyPosition);
-    fList->Add(fAccuracy);
+    //fList->Add(fSkyPosition);
+    //fList->Add(fAccuracy);
     //  fList->Add(fAccuracyTime);
     //  fList->Add(fVelocity);
     //  fList->Add(fOffset);
-    fList->Add(fImage);
-
-#ifdef DEBUG
-    cout << "MGCosy: Creating TGGroupFrame" << endl;
-#endif
+    //fList->Add(fImage);
+
     TGGroupFrame *frame = new TGGroupFrame(f2, "Status");
-    fList->Add(frame);
-
-#ifdef DEBUG
-    cout << "MGCosy: Creating TGTextView" << endl;
-#endif
+    // frame->SetCleanup();
+    //fList->Add(frame);
+
     fLog = new TGTextView(f2, 300, 300);
     if (fFont)
         fLog->SetFont(fFont);
-    fList->Add(fLog);
+    //fList->Add(fLog);
 
     TGLayoutHints *hints1  = new TGLayoutHints(kLHintsNormal  | kLHintsExpandX|kLHintsExpandY, 6, 6, 6, 3);
@@ -789,4 +768,5 @@
     TGLayoutHints *hints3b = new TGLayoutHints(kLHintsRight   | kLHintsCenterY|kLHintsExpandX|kLHintsExpandY);
 
+    /*
     fList->Add(hints1);
     fList->Add(hints2);
@@ -797,5 +777,5 @@
     fList->Add(hints2b);
     fList->Add(hints3b);
-
+    */
     // Layout upper frame
     f1->AddFrame(fTab,         hints1a);
@@ -814,11 +794,5 @@
     AddFrame(f2, hints2);
 
-#ifdef DEBUG
-    cout << "MGCosy: Creating Tabs" << endl;
-#endif
     CreateTabs();
-#ifdef DEBUG
-    cout << "MGCosy: Creating Label" << endl;
-#endif
     CreateLabel(frame);
 
@@ -826,7 +800,4 @@
     //   Map the window, set up the layout, etc.
     //
-#ifdef DEBUG
-    cout << "MGCosy: Setting Size" << endl;
-#endif
     const Int_t ww = 1010;
     const Int_t hh =  700;
@@ -848,4 +819,15 @@
 MGCosy::~MGCosy()
 {
+    /*
+    TIter Next(fList);
+    TObject *o=0;
+    while((o=Next()))
+    {
+        cout << o << " " << flush;
+        cout << o->ClassName() << " " << flush;
+        cout << o->GetName() << " " << endl;
+        delete o;
+    }
+    */
 #ifdef DEBUG
     cout << "MGCosy::~MGCosy called." << endl;
@@ -1466,14 +1448,14 @@
                     {
                     case kPB_RAp:
-                        xy.X(xy.X()+1./60);
+                        xy.Set(xy.X()+1./60, xy.Y());
                         break;
                     case kPB_RAm:
-                        xy.X(xy.X()-1./60);
+                        xy.Set(xy.X()-1./60, xy.Y());
                         break;
                     case kPB_DECp:
-                        xy.Y(xy.Y()+1./60);
+                        xy.Set(xy.X(), xy.Y()+1./60);
                         break;
                     case kPB_DECm:
-                        xy.Y(xy.Y()-1./60);
+                        xy.Set(xy.X(), xy.Y()-1./60);
                         break;
                     }
Index: /trunk/MagicSoft/Cosy/main/MSlewing.cc
===================================================================
--- /trunk/MagicSoft/Cosy/main/MSlewing.cc	(revision 8823)
+++ /trunk/MagicSoft/Cosy/main/MSlewing.cc	(revision 8824)
@@ -1,3 +1,5 @@
 #include "MSlewing.h"
+
+#include "MLogManip.h"
 
 #include "MCosy.h"
@@ -103,5 +105,5 @@
 
     MTime t(-1);
-    gLog << t << " - Target Position: " << d.Zd() << "deg, " << d.Az() << "deg (Zd/Az)" << endl;
+    gLog << all << t << " - Target Position: " << d.Zd() << "deg, " << d.Az() << "deg (Zd/Az)" << endl;
 
     //
@@ -150,5 +152,5 @@
     {
 
-        gLog << "- Step #" << i << endl;
+        gLog << inf2 << "- Step #" << i << endl;
 
         // Get Shaft Encoder Positions
@@ -173,5 +175,5 @@
         {
             t.Now();
-            gLog << t << " - Positioning done in " << i << (i==1?" step.":" steps.") << endl;
+            gLog << all << t << " - Positioning done in " << i << (i==1?" step.":" steps.") << endl;
             fCosy->SetStatus(MDriveCom::kStopped);
             fCosy->fCom->SendStatus("Target position reached.");
@@ -191,5 +193,6 @@
 
         // change units from se to re
-        rd *= fCosy->kGearTot/fCosy->kResSE; // [re]
+//        rd *= fCosy->kGearTot/fCosy->kResSE; // [re]
+        rd *= Div(fCosy->kGearTot,fCosy->kResSE); // [re]
         rd.Zd(f2-f1);
 
@@ -245,12 +248,12 @@
 
         // repositioning (relative)
-        gLog << "- Do Relative Positioning..." << endl;
+        gLog << inf2 << "- Do Relative Positioning..." << endl;
         DoRelPos(rd, cdzd, cdaz);
-        gLog << "- Relative Positioning Done" << endl;
+        gLog << inf2 << "- Relative Positioning Done" << endl;
     }
     if (i==1 && track && !Break()/*(fCosy->Break() || fCosy->HasError() || fCosy->HasZombie())*/)
     {
         t.Now();
-        gLog << t << " - Positioning done." << endl;
+        gLog << all << t << " - Positioning done." << endl;
         fCosy->SetStatus(MDriveCom::kStopped);
         fCosy->fCom->SendStatus("Tracking preposition reached.");
@@ -264,5 +267,5 @@
 
     t.Now();
-    gLog << t << " - Warning: Requested position not reached (i=" << dec << i << ")" << endl;
+    gLog << warn << t << " - Warning: Requested position not reached (i=" << dec << i << ")" << endl;
 
     fCosy->fCom->SendStatus("Target position missed!");
Index: /trunk/MagicSoft/Cosy/main/MStarguider.cc
===================================================================
--- /trunk/MagicSoft/Cosy/main/MStarguider.cc	(revision 8823)
+++ /trunk/MagicSoft/Cosy/main/MStarguider.cc	(revision 8824)
@@ -248,16 +248,8 @@
     fCaosAnalyse->AddEntry("St&op Analysis",  IDM_kCaosAnalStop);
     fCaosAnalyse->DisableEntry(IDM_kCaosAnalStop);
-    //    fCaosAnalyse->AddEntry("&Reset Histograms", IDM_kResetHistograms);
-    //    fCaosAnalyse->AddEntry("Reset &Graph", IDM_kResetGraph);
     fCaosAnalyse->Associate(this);
     fList->Add(fCaosAnalyse);
 
     fMenu = new TGMenuBar(this, 0, 0, kHorizontalFrame);
-    //fMenu->SetCleanup();
-    //fMenu->AddPopup("&Display",    fDisplay,         NULL);
-    //fMenu->AddPopup("&Mode",       fMode,            NULL);
-    //fMenu->AddPopup("&WritePics",  fWritePictures,   NULL);
-    //fMenu->AddPopup("&Setup",      fSetup,           NULL);
-    //fMenu->AddPopup("&Operations", fOperations,      NULL);
     fDisplay       = fMenu->AddPopup("&Display");
     fMode          = fMenu->AddPopup("&Mode");
@@ -266,7 +258,5 @@
     fOperations    = fMenu->AddPopup("&Operations");
     fMenu->Resize(fMenu->GetDefaultSize());
-    //fMenu->BindKeys(this);
     AddFrame(fMenu); 
-    //fList->Add(fMenu);
 
     //
@@ -290,13 +280,9 @@
     fDisplay->CheckEntry(IDM_kStretch);
     fDisplay->Associate(this);
-    //fList->Add(fDisplay);
-
-    //fMode = new MGPopupMenu(p);
+
     fMode->AddEntry("Starguider", IDM_kStarguiderMode);
     fMode->AddEntry("Tpoint",     IDM_kTpointMode);
     fMode->Associate(this);
-    //fList->Add(fMode);
-
-    //fWritePictures = new MGPopupMenu(p);
+
     fWritePictures->AddEntry("&Start",      IDM_kStart);
     fWritePictures->AddEntry("Sto&p",       IDM_kStop);
@@ -307,19 +293,13 @@
     fWritePictures->DisableEntry(IDM_kStop);
     fWritePictures->Associate(this);
-    //fList->Add(fWritePictures);
-
-    //fSetup = new MGPopupMenu(p);
+
     fSetup->AddPopup("Lim. &Magnitude",      fLimMag);
     fSetup->AddPopup("Disp. &Interpolation", fInterpol);
-    //fSetup->AddEntry("Use Ra/Dec from file", IDM_kUseFileRaDec);
     fSetup->Associate(this);
-    //fList->Add(fSetup);
-
-    //fOperations = new MGPopupMenu(p);
+
     fOperations->AddEntry("Roque Lamp Analysis", IDM_kRoqueLampAna);
     fOperations->AddEntry("Starguider Analysis", IDM_kStargAnalysis);
     fOperations->DisableEntry(IDM_kStargAnalysis);
     fOperations->Associate(this);
-    //fList->Add(fOperations);
 
     fCaOs = new TGPopupMenu(p);
@@ -328,12 +308,6 @@
     fCaOs->AddPopup("&Analyse", fCaosAnalyse);
     fCaOs->Associate(this);
-    //fCaOs->BindKeys(fMenu, this);
     fList->Add(fCaOs);
-/*
-    TGLayoutHints *hints2a = 
-	new TGLayoutHints(kLHintsCenterX|kLHintsCenterY|
-        		  kLHintsExpandX|kLHintsExpandY,1,1);
-    fList->Add(hints2a);
- */
+
     fGStarg = new MGStarg(this, 235);
     fGStarg->DrawText("0.75'", "1.50'", "3.00'", "Mispointing [min]");
@@ -346,5 +320,4 @@
     fCRaDec->Move(4, fMenu->GetDefaultHeight()+584);
     AddFrame(fCRaDec);
-    //fList->Add(fCRaDec);
 
     //telescope position
@@ -352,5 +325,4 @@
     fCZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+597);
     AddFrame(fCZdAz);
-    //fList->Add(fCZdAz);
 
     //starguider position
@@ -358,5 +330,4 @@
     fPZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+640);
     AddFrame(fPZdAz);
-    //fList->Add(fPZdAz);
 
     //mispointing
@@ -364,10 +335,8 @@
     fDZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+683);
     AddFrame(fDZdAz);
-    //fList->Add(fDZdAz);
 
     fSZdAz = new MGCoordinates(this, kETypeZdAz, 2);
     fSZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+795);
     AddFrame(fSZdAz);
-    //fList->Add(fSZdAz);
 
     fGNumStars = new MGNumStars(this, 235);
@@ -380,5 +349,4 @@
     fTPoint->AllowStayDown(kTRUE);
     AddFrame(fTPoint);
-    //fList->Add(fTPoint);
 
     fStargTPoint = new TGTextButton(this, "StargTPoint");
@@ -386,5 +354,4 @@
     fStargTPoint->AllowStayDown(kTRUE);
     AddFrame(fStargTPoint);
-    //fList->Add(fStargTPoint);
 
     fFps = new TGLabel(this, "---fps");
@@ -392,5 +359,4 @@
     fFps->Move(650-495, fMenu->GetDefaultHeight()+714+23);
     AddFrame(fFps);
-    //fList->Add(fFps);
 
     fPosZoom = new TGLabel(this, "(----, ----) ----.--d/----.--d");
@@ -398,5 +364,4 @@
     fPosZoom->Move(4, fMenu->GetDefaultHeight()+765);
     AddFrame(fPosZoom);
-    //fList->Add(fPosZoom);
 
     fSkyBright = new TGLabel(this, "Sky Brightness: ---         ");
@@ -404,5 +369,4 @@
     fSkyBright->Move(4, fMenu->GetDefaultHeight()+785);
     AddFrame(fSkyBright);
-    //fList->Add(fSkyBright);
 
     TGLabel *l = new TGLabel(this, "deg");
@@ -410,5 +374,4 @@
     l->Move(606-412, fMenu->GetDefaultHeight()+669);
     AddFrame(l);
-    //fList->Add(l);
 
     l = new TGLabel(this, "arcsec/pix");
@@ -416,5 +379,4 @@
     l->Move(606-412, fMenu->GetDefaultHeight()+692);
     AddFrame(l);
-    //fList->Add(l);
 
     l = new TGLabel(this, "sigma");
@@ -422,5 +384,4 @@
     l->Move(606-412, fMenu->GetDefaultHeight()+715);
     AddFrame(l);
-    //fList->Add(l);
 
     fCZdAzText = new TGLabel(this, "Zd/Az telescope pointing at");
@@ -428,5 +389,4 @@
     fCZdAzText->Move(240+12+20+7, fMenu->GetDefaultHeight()+584-5);
     AddFrame(fCZdAzText);
-    //fList->Add(fCZdAzText);
 
     fPZdAzText = new TGLabel(this, "Zd/Az starguider pointing at");
@@ -434,5 +394,4 @@
     fPZdAzText->Move(240+12+20+7, fMenu->GetDefaultHeight()+630+20-5-23);
     AddFrame(fPZdAzText);
-    //fList->Add(fPZdAzText);
 
     fDZdAzText = new TGLabel(this, "Zd/Az mispointing");
@@ -440,5 +399,4 @@
     fDZdAzText->Move(240+12+20+7, fMenu->GetDefaultHeight()+676+2*20-5-46);
     AddFrame(fDZdAzText);
-    //fList->Add(fDZdAzText);
 
 #ifdef EXPERT
@@ -447,5 +405,4 @@
     l->Move(240+12+20, fMenu->GetDefaultHeight()+722+3*20-5);
     AddFrame(l);
-    //fList->Add(l);
 #endif
 
@@ -453,5 +410,5 @@
     const Double_t angle = -0.2;
     fSao->SetRotationAngle(angle);
-    
+
     TString txt;
     txt += angle;
@@ -461,5 +418,4 @@
     fAngle->Move(547-410, fMenu->GetDefaultHeight()+667);
     AddFrame(fAngle);
-    //fList->Add(fAngle);
 
     // Set input box for pixel size
@@ -475,5 +431,4 @@
     fPixSize->Move(547-410, fMenu->GetDefaultHeight()+690);
     AddFrame(fPixSize);
-    //fList->Add(fPixSize);
 
     // Set input box for cleaning cut
@@ -487,5 +442,4 @@
     fCut->Move(547-410, fMenu->GetDefaultHeight()+713);
     AddFrame(fCut);
-    //fList->Add(fCut);
 
     // TGHorizontal3DLine *fLineSep = new TGHorizontal3DLine(this);
@@ -500,10 +454,8 @@
     fZoomImage->Move(4, 700-kZOOM-2+85);
     AddFrame(fZoomImage);
-    //fList->Add(fZoomImage);
 
     fImage = new MGImage(this, 768, 576);
     fImage->Move(0, fMenu->GetDefaultHeight());
     AddFrame(fImage);
-    //fList->Add(fImage);
 
     const Int_t w = 768;
@@ -1863,5 +1815,5 @@
 	    for (int x=0; x<768/2-1; x++)
 		simg[x+y*(768/2-1)] = ((unsigned int)img[2*x+2*y*768]+img[2*x+2*y*768+1]+img[2*x+2*(y+1)*768]+img[2*x+2*(y+1)*768+1])/4;	
-	
+
 	fCosy->GetWin()->GetImage()->DrawImg(simg);
     }
