Index: trunk/MagicSoft/Cosy/Changelog
===================================================================
--- trunk/MagicSoft/Cosy/Changelog	(revision 912)
+++ trunk/MagicSoft/Cosy/Changelog	(revision 913)
@@ -1,3 +1,43 @@
                                                                   -*-*- END -*-*-
+ 2001/08/23 - Thomas Bretz:
+
+   * gui/MGEmbeddedCanvas.[h,cc]:
+     - added
+     
+   * gui/MGVelocity.[h,cc]:
+     - added
+     
+   * MCosy.[h,cc]:
+     - added GetRePosPdo
+     - changed fOffset to an offset between the se and re system
+     - changed old fOffset to fTrackingError which gives you a good
+       estimate what the tracking error really is
+     - changed the weighting of fOffset from 0.1 to 0.3
+     - reordered some statements for a better overview
+     - changed update of GUI from thread to a timer (s.HandleTimer)
+
+   * Makefile:
+     - added libpthread.a
+     - reordered libraries
+     
+   * gui/MGAccuracy.[h,cc]:
+     - changed the layout
+     - make use of TGaxis
+     - added the numbers as text into canvas
+     - added a title
+     - derived from MEmbeddedCanvas
+     
+   * gui/MGCosy.[h,cc]:
+     - changed layout
+     - added canvas for velocity
+     - added canvas for offset
+     
+   * gui/MGSkyPosition.[h,cc]:
+     - added position as text
+     - added axis labels
+     - derived from MEmbeddedCanvas
+     - reorganized parts of the existing code
+
+
 
  2001/08/17 - Thomas Bretz:
Index: trunk/MagicSoft/Cosy/gui/MGAccuracy.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGAccuracy.cc	(revision 912)
+++ trunk/MagicSoft/Cosy/gui/MGAccuracy.cc	(revision 913)
@@ -11,5 +11,8 @@
 #include <TArc.h>
 #include <TLine.h>
+#include <TText.h>
+#include <TWbox.h>
 #include <TList.h>
+#include <TGaxis.h>
 #include <TCanvas.h>
 
@@ -18,34 +21,11 @@
 void MGAccuracy::DrawCoordinateSystem()
 {
-    TLine line;
-
-    line.SetLineColor(13);
-    line.SetLineStyle(3);  // dotted  (s. TAttLine)
-    line.DrawLine(-.5,  -1.05, -.5,   1.05);
-    line.DrawLine( -1.05, -.5,   1.05, -.5);
-    line.DrawLine( .5,  -1.05,  .5,   1.05);
-    line.DrawLine( -1.05,  .5,   1.05,  .5);
-
-    line.DrawLine(-.25,  -1.05, -.25,   1.05);
-    line.DrawLine( -1.05, -.25,   1.05, -.25);
-    line.DrawLine( .25,  -1.05,  .25,   1.05);
-    line.DrawLine( -1.05,  .25,   1.05,  .25);
-
-    line.DrawLine(-.75,  -1.05, -.75,   1.05);
-    line.DrawLine( -1.05, -.75,   1.05, -.75);
-    line.DrawLine( .75,  -1.05,  .75,   1.05);
-    line.DrawLine( -1.05,  .75,   1.05,  .75);
-
-    line.SetLineColor(12);
-    line.SetLineStyle(2);  // dashed  (s. TAttLine)
-    line.DrawLine(-1, -1.05, -1,  1.05);
-    line.DrawLine(-1.05, -1,  1.05, -1);
-    line.DrawLine( 1, -1.05,  1,  1.05);
-    line.DrawLine(-1.05,  1,  1.05,  1);
-
-    line.SetLineColor(1);  // black
-    line.SetLineStyle(1);  // solid  (s. TAttLine)
-    line.DrawLine(-1.05,     0, 1.05,    0);
-    line.DrawLine(    0, -1.05,    0, 1.05);
+    TWbox box;
+    box.DrawWbox(-145*2, 145*2, -15*2, 120*2,  18,  2, 1);
+
+    TText text;
+    text.SetTextAlign(22);  // centered, centered (s.TAttText)
+    text.DrawText(-80*2, 132.5*2, "Tracking Error [']");
+
 
     TArc arc;
@@ -54,14 +34,113 @@
     arc.SetLineColor(3);     // green
     arc.SetLineStyle(2);     // dashed  (s. TAttLine)
-    arc.DrawArc(0, 0, 20./60);
+    arc.DrawArc(0, 0, 79.1/2.);        // 0.5se
 
     arc.SetLineColor(5);     // yellow
-    arc.DrawArc(0, 0, 40./60);
+    arc.DrawArc(0, 0, 79.1);            // 1.0se
 
     arc.SetLineColor(2);     // red
-    arc.DrawArc(0, 0, 1);
-}
-
-void MGAccuracy::InitPosition()
+    arc.DrawArc(0, 0, 79.1*2.);         // 2.0se
+
+
+    text.SetTextAlign(11);  // left, bottom (s.TAttText)
+    text.SetTextColor(3);
+    text.DrawText(220, -220, "0.5se");
+
+    text.SetTextColor(5);
+    text.DrawText(220, -250, "1.0se");
+
+    text.SetTextColor(2);
+    text.DrawText(220, -280, "2.0se");
+
+
+    TLine line;
+    line.DrawLine(-65*4,     0, 65*4,    0);
+    line.DrawLine(    0, -65*4,    0, 65*4);
+
+    TGaxis *axe;
+    axe = new TGaxis(-60*4,   0, 60*4,  0,  -4, 4, 30204, "+-N");
+    axe->SetTitle("Az"); // \xb0
+    axe->SetBit(kCanDelete);
+    axe->Draw();
+
+    axe = new TGaxis(  0, -60*4,  0, 60*4,  -4, 4,   304, "+-N");
+    axe->SetTitle("Zd"); // \xb0
+    axe->SetBit(kCanDelete);
+    axe->Draw();
+
+    //
+    // FIXME? Use TAxis?
+    //
+/*
+    TLine line;
+    line.SetLineColor(13);
+    line.SetLineStyle(3);  // dotted  (s. TAttLine)
+    line.DrawLine(-30, -65, -30,  65);
+    line.DrawLine(-65, -30,  65, -30);
+    line.DrawLine( 30, -65,  30,  65);
+    line.DrawLine(-65,  30,  65,  30);
+
+    line.DrawLine(-15, -65, -15,  65);
+    line.DrawLine(-65, -15,  65, -15);
+    line.DrawLine( 15, -65,  15,  65);
+    line.DrawLine(-65,  15,  65,  15);
+
+    line.DrawLine(-45, -65, -45,  65);
+    line.DrawLine(-65, -45,  65, -45);
+    line.DrawLine( 45, -65,  45,  65);
+    line.DrawLine(-65,  45,  65,  45);
+
+    line.SetLineColor(12);
+    line.SetLineStyle(2);  // dashed  (s. TAttLine)
+    line.DrawLine(-60, -65, -60,  65);
+    line.DrawLine(-65, -60,  65, -60);
+    line.DrawLine( 60, -65,  60,  65);
+    line.DrawLine(-65,  60,  65,  60);
+
+    line.SetLineColor(1);  // black
+    line.SetLineStyle(1);  // solid  (s. TAttLine)
+    line.DrawLine(-65,   0, 65,  0);
+    line.DrawLine(  0, -65,  0, 65);
+
+    line.DrawLine(-1,  60, 1,  60);
+    line.DrawLine(-1, -60, 1, -60);
+    line.DrawLine(-1,  30, 1,  30);
+    line.DrawLine(-1, -30, 1, -30);
+
+    line.DrawLine( 60, -1,  60, 1);
+    line.DrawLine(-60, -1, -60, 1);
+    line.DrawLine( 30, -1,  30, 1);
+    line.DrawLine(-30, -1, -30, 1);
+
+    TText text;
+    text.SetTextAlign(22);  // centered, centered (s.TAttText)
+    text.DrawText(60, 5, "dAz[\xb0]");
+    text.DrawText(0, 70, "dZd[\xb0]");
+
+    text.SetTextAlign(23);  // centered, centered (s.TAttText)
+    text.DrawText(-60, -2, "-1'");
+    text.DrawText( 60, -2, "1'");
+    text.DrawText(-30, -2, "-30\"");
+    text.DrawText( 30, -2, "30\"");
+
+    text.SetTextAlign(32);  // centered, centered (s.TAttText)
+    text.DrawText(-2, -60, "-1'");
+    text.DrawText(-2,  60, "1'");
+    text.DrawText(-2, -30, "-30\"");
+    text.DrawText(-2,  30, "30\"");
+    */
+}
+
+void MGAccuracy::InitText()
+{
+    fTxt = new TText(280, 280, "0' / 0'");
+    fTxt->SetTextAlign(33); // right, top
+    fTxt->SetTextColor(10);
+    fTxt->Draw();
+
+    fList->Add(fTxt);
+}
+
+void MGAccuracy::InitCross()
 {
     fLin1 = new TLine(0, 0, 0, 0);
@@ -73,4 +152,7 @@
     fLin2->SetLineStyle(1); 
 
+    fLin1->SetLineWidth(2);
+    fLin2->SetLineWidth(2);
+
     fLin1->Draw();
     fLin2->Draw();
@@ -80,31 +162,69 @@
 }
 
-MGAccuracy::MGAccuracy(const TGWindow* p, const Int_t w, const Int_t h)
-    : TRootEmbeddedCanvas("Accuracy", p, w-1, h-1, kRaisedFrame),//, 0) //234, 76, kFixedSize)
-    fModified(kFALSE)
-{
-    fCanvas = GetCanvas();
-
-    fCanvas->SetFillColor(39); // s. TAttFill
-    fCanvas->Range(-1.1, -1.1, 1.1, 1.1);
-
-    fList = new TList;
-    fList->SetOwner();
-
+MGAccuracy::MGAccuracy(const TGWindow* p, const UInt_t w)
+: MGEmbeddedCanvas("Accuracy", p, w, 75*4)
+{
     DrawCoordinateSystem();
-    InitPosition();
-
-    Resize(w, h); //GetDefaultSize()); // ???
-
-    MapSubwindows();
+
+    InitText();
+    InitCross();
+
+    InitCanvas();
 }
 
 MGAccuracy::~MGAccuracy()
 {
-    delete fList;
-
     cout << "MGAccuracy destroyed." << endl;
 }
 
+void MGAccuracy::UpdateText(Float_t x, Float_t y)
+{
+    /*
+     int xs = (int)floor(fmod(fabs(x), 60.));
+     int ys = (int)floor(fmod(fabs(y), 60.));
+     x /= 60.;
+     y /= 60.;
+     int xm = (int)floor(fmod(fabs(x), 60.));
+     int ym = (int)floor(fmod(fabs(y), 60.));
+
+     char tx[100];
+     char ty[100];
+
+     xm ? sprintf(tx, "%d'%02d\"", xm, xs) : sprintf(tx, "%d\"", xs);
+     ym ? sprintf(ty, "%d'%02d\"", ym, ys) : sprintf(ty, "%d\"", ys);
+
+     char txt[200];
+     sprintf(txt, "%s / %s", tx, ty);
+     */
+
+    // FIXME: We are on a sphere
+
+    float r = sqrt(x*x+y*y);
+
+    int rs = (int)floor(fmod(r, 60.));
+    r /= 60.;
+    int rm = (int)floor(fmod(r, 60.));
+
+    char txt[100];
+    rm ? sprintf(txt, "%d'%02d\"", rm, rs) : sprintf(txt, "%d\"", rs);
+
+    fTxt->SetText(fTxt->GetX(), fTxt->GetY(), txt);
+}
+
+void MGAccuracy::UpdateCross(Float_t x, Float_t y)
+{
+    fLin1->SetX1(x-5.);
+    fLin1->SetX2(x+5.);
+
+    fLin2->SetX1(x-5.);
+    fLin2->SetX2(x+5.);
+
+    fLin1->SetY1(y-5.);
+    fLin1->SetY2(y+5.);
+
+    fLin2->SetY1(y+5.);
+    fLin2->SetY2(y-5.);
+}
+
 void MGAccuracy::Update(ZdAz &zdaz)
 {
@@ -112,30 +232,23 @@
     // calculate actual time for planet positions
     //
-
-    fLin1->SetX1(zdaz.Zd()*60.-0.02);
-    fLin1->SetX2(zdaz.Zd()*60.+0.02);
-
-    fLin2->SetX1(zdaz.Zd()*60.-0.02);
-    fLin2->SetX2(zdaz.Zd()*60.+0.02);
-
-    fLin1->SetY1(zdaz.Az()*60.-0.02);
-    fLin1->SetY2(zdaz.Az()*60.+0.02);
-
-    fLin2->SetY1(zdaz.Az()*60.+0.02);
-    fLin2->SetY2(zdaz.Az()*60.-0.02);
-
-    fCanvas->Modified();
-    fCanvas->Update();
-
-    /*
-    DrawPosition(pos.Zd(), pos.Az());
-
-    if (!fModified)
+    static int X = ~0;
+    static int Y = ~0;
+
+    float x = zdaz.Az()*3600.; // ["]
+    float y = zdaz.Zd()*3600.; // ["]
+
+    int pixx = (int)(x/fPix);  // [pix]
+    int pixy = (int)(y/fPix);  // [pix]
+
+    if (X==pixx && Y==pixy)
         return;
 
-    // FIXME: Sometimes (if the canvas couldn't be created correctly:
-    // X11 Pixmap error) Update hangs the Gui system.
-
-    fModified = kFALSE;
-    */
-}
+    X = pixx;
+    Y = pixy;
+
+    UpdateCross(x, y);
+    UpdateText(x, y);
+
+    SetModified();
+    UpdateCanvas();
+}
Index: trunk/MagicSoft/Cosy/gui/MGAccuracy.h
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGAccuracy.h	(revision 912)
+++ trunk/MagicSoft/Cosy/gui/MGAccuracy.h	(revision 913)
@@ -8,11 +8,11 @@
 //   Version: V1.0 (1-8-2000)
 
-
-#ifndef ROOT_TRootEmbeddedCanvas
-#include <TRootEmbeddedCanvas.h>
+#ifndef MGEMBEDDEDCANVAS_H
+#include "MGEmbeddedCanvas.h"
 #endif
 
 class TList;
 class TLine;
+class TText;
 class TCanvas;
 
@@ -20,26 +20,21 @@
 class SlaPlanets;
 
-class MGAccuracy : public TRootEmbeddedCanvas
+class MGAccuracy : public MGEmbeddedCanvas
 {
-    TCanvas    *fCanvas;
+    TLine  *fLin1;
+    TLine  *fLin2;
 
-    TLine      *fLin1;
-    TLine      *fLin2;
-/*
-    TLine      *fLin2;
-*/
-    TList      *fList;
-
-    Bool_t fModified;
-
-    void InitPosition();
-
-    //    void SetLin1(int x, int y);
-    //    void SetLin2(int x1, int y1, int x2, int y2);
+    TText  *fTxt;
 
     void DrawCoordinateSystem();
 
+    void InitText();
+    void InitCross();
+
+    void UpdateText(Float_t x, Float_t y);
+    void UpdateCross(Float_t x, Float_t y);
+
 public:
-    MGAccuracy(const TGWindow* p, const Int_t w, const Int_t h);
+    MGAccuracy(const TGWindow* p, const UInt_t w);
     ~MGAccuracy();
 
Index: trunk/MagicSoft/Cosy/gui/MGCosy.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGCosy.cc	(revision 912)
+++ trunk/MagicSoft/Cosy/gui/MGCosy.cc	(revision 913)
@@ -9,5 +9,5 @@
 #include <TSystem.h>       // gSystem
 #include <TGLabel.h>       // TGLabel
-#include <TGSplitter.h>    // TGHorizontal3DLine
+#include <TG3DLine.h>      // TGHorizontal3DLine (TGSplitter)
 #include <TApplication.h>  // gApplication
 
@@ -19,4 +19,5 @@
 #include "MGCoordinates.h"
 #include "MGSkyPosition.h"
+#include "MGVelocity.h"
 
 #include "SlaStars.h"
@@ -156,16 +157,26 @@
     fList->Add(fCoord);
 
-    fAccuracy = new MGAccuracy(this, 200, 200);
-    fAccuracy->Move(320, 260);
-    fList->Add(fAccuracy);
-
-    fSkyPosition = new MGSkyPosition(this, 200, 200);
+    fSkyPosition = new MGSkyPosition(this, 300);
     fSkyPosition->Move(320, 40);
     fList->Add(fSkyPosition);
 
+    fAccuracy = new MGAccuracy(this, 300);
+    fAccuracy->Move(320, 360);
+    fList->Add(fAccuracy);
+
+    fVelocity = new MGVelocity(this, "Velocity ['/min]", 300);
+    fVelocity->Move(10, 360);
+    fList->Add(fVelocity);
+
+    fOffset = new MGVelocity(this, "Offset se-re [']", 300);
+    fOffset->Move(630, 360);
+    fList->Add(fOffset);
+
     //
     //   Map the window, set up the layout, etc.
     //
-    SetWMSizeHints(550, 500, 550, 500, 10, 10);  // set the smallest and biggest size of the Main frame
+    const Int_t w = 650+310;
+    const Int_t h = 690;
+    SetWMSizeHints(w, h, w, h, 10, 10);  // set the smallest and biggest size of the Main frame
 
     MapSubwindows();
@@ -178,6 +189,4 @@
 }
 
-
-
 // ======================================================================
 
@@ -196,8 +205,10 @@
 }
 // ======================================================================
-void MGCosy::Update(ZdAz pos, ZdAz acc)
+void MGCosy::Update(ZdAz pos, ZdAz acc, ZdAz vel, ZdAz off)
 {
     fSkyPosition->Update(pos);
     fAccuracy->Update(acc);
+    fVelocity->Update(vel);
+    fOffset->Update(off);
 }
 // ======================================================================
Index: trunk/MagicSoft/Cosy/gui/MGCosy.h
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGCosy.h	(revision 912)
+++ trunk/MagicSoft/Cosy/gui/MGCosy.h	(revision 913)
@@ -30,4 +30,5 @@
 class MGSkyPosition;
 class MGAccuracy;
+class MGVelocity;
 
 class MGCosy : public TGMainFrame
@@ -50,4 +51,6 @@
     MGSkyPosition *fSkyPosition;
     MGAccuracy    *fAccuracy;
+    MGVelocity    *fVelocity;
+    MGVelocity    *fOffset;
 
     MsgQueue      *fQueue;
@@ -67,5 +70,5 @@
     TGLabel **GetLabel3() { return fLabel3; }
 
-    void Update(ZdAz pos, ZdAz acc);
+    void Update(ZdAz pos, ZdAz acc, ZdAz vel, ZdAz off);
 
     Bool_t ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2);
Index: trunk/MagicSoft/Cosy/gui/MGEmbeddedCanvas.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGEmbeddedCanvas.cc	(revision 913)
+++ trunk/MagicSoft/Cosy/gui/MGEmbeddedCanvas.cc	(revision 913)
@@ -0,0 +1,53 @@
+//
+// This File contains the definition of the MGCoordinates-class
+//
+//   Author: Thomas Bretz
+//   Version: V1.0 (1-8-2000)
+
+#include "MGEmbeddedCanvas.h"
+
+#include <TList.h>
+#include <TCanvas.h>
+
+MGEmbeddedCanvas::MGEmbeddedCanvas(const char *name, const TGWindow* p,
+                                   const UInt_t width, Float_t range)
+    : TRootEmbeddedCanvas(name, p, width, width, kRaisedFrame),//, 0) //234, 76, kFixedSize)
+      fModified(kFALSE), fWidth(width), fRange(range), fPix(2.*range/width)
+{
+    fCanvas = GetCanvas();
+
+    fCanvas->SetFillColor(39); // s. TAttFill
+    fCanvas->Range(-fRange, -fRange, fRange, fRange);
+
+    fList = new TList;
+    fList->SetOwner();
+}
+
+MGEmbeddedCanvas::~MGEmbeddedCanvas()
+{
+    delete fList;
+}
+
+void MGEmbeddedCanvas::InitCanvas()
+{
+    MapSubwindows();
+
+    Resize(fWidth-1, fWidth-1); //GetDefaultSize()); // ???
+    MapWindow();
+
+    fCanvas->SetEditable(kFALSE);
+}
+
+void MGEmbeddedCanvas::UpdateCanvas()
+{
+    if (!fModified)
+        return;
+
+    // FIXME: Sometimes (if the canvas couldn't be created correctly:
+    // X11 Pixmap error) Update hangs the Gui system.
+
+    fCanvas->Modified();
+    fCanvas->Update();
+
+    fModified = kFALSE;
+}
Index: trunk/MagicSoft/Cosy/gui/MGEmbeddedCanvas.h
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGEmbeddedCanvas.h	(revision 913)
+++ trunk/MagicSoft/Cosy/gui/MGEmbeddedCanvas.h	(revision 913)
@@ -0,0 +1,44 @@
+#ifndef MGEMBEDDEDCANVAS_H
+#define MGEMBEDDEDCANVAS_H
+
+//
+// This File contains the declaration of the MGCoordinates-class
+//
+//   Author: Thomas Bretz
+//   Version: V1.0 (1-8-2000)
+
+
+#ifndef ROOT_TRootEmbeddedCanvas
+#include <TRootEmbeddedCanvas.h>
+#endif
+
+class TList;
+class TCanvas;
+
+class MGEmbeddedCanvas : public TRootEmbeddedCanvas
+{
+private:
+    Bool_t fModified;
+
+protected:
+
+    TCanvas    *fCanvas;
+    TList      *fList;
+
+    const UInt_t  fWidth;
+    const Float_t fRange;
+    const Float_t fPix;
+
+    void InitCanvas();
+
+public:
+    MGEmbeddedCanvas(const char *name, const TGWindow* p,
+                     const UInt_t width, const Float_t range);
+    ~MGEmbeddedCanvas();
+
+    void UpdateCanvas();
+
+    void SetModified() { fModified = kTRUE; }
+};
+
+#endif // MGSKYPOSITION_H
Index: trunk/MagicSoft/Cosy/gui/MGSkyPosition.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGSkyPosition.cc	(revision 912)
+++ trunk/MagicSoft/Cosy/gui/MGSkyPosition.cc	(revision 913)
@@ -11,4 +11,5 @@
 #include <TArc.h>
 #include <TLine.h>
+#include <TText.h>
 #include <TList.h>
 #include <TCanvas.h>
@@ -94,4 +95,15 @@
 }
 
+void MGSkyPosition::InitText()
+{
+    fText = new TText(105, 105, "");
+    fText->SetFillStyle(4000);  // transparent
+    fText->SetTextAlign(33);  // right, top
+    fText->SetTextColor(10);  // white
+    fText->Draw();
+
+    fList->Add(fText);
+}
+
 void MGSkyPosition::DrawCoordinateSystem()
 {
@@ -105,4 +117,7 @@
     arc.DrawArc(0, 0, 22.5);
 
+    //
+    // FIXME? Use TAxis?
+    //
     TLine line;
     line.SetLineColor(1);  // black
@@ -110,4 +125,24 @@
     line.DrawLine(-95,   0, 95,  0);
     line.DrawLine(  0, -95,  0, 95);
+
+    TText text;
+    text.SetTextAlign(22);  // centered, centered (s.TAttText)
+    text.SetTextColor(13);  // dark gray
+    text.DrawText(0.71*22.5, 0.71*22.5, "22.5\xb0");
+    text.DrawText(0.71*45.0, 0.71*45.0, "45\xb0");
+    text.DrawText(0.71*67.5, 0.71*67.5, "67.5\xb0");
+    text.DrawText(0.71*90.0, 0.71*90.0, "90\xb0");
+
+    text.SetTextAlign(22);  // centered, centered (s.TAttText)
+    text.SetTextColor(1);   // black
+
+    text.DrawText(0,  102, "N (0\xb0)");
+    text.DrawText(0, -102, "S (180\xb0)");
+
+    text.SetTextAngle(270);
+    text.DrawText( 102, 0, "E (90\xb0)");
+
+    text.SetTextAngle(90);
+    text.DrawText(-102, 0, "W (270\xb0)");
 }
 
@@ -133,27 +168,16 @@
 }
 
-MGSkyPosition::MGSkyPosition(const TGWindow* p, const Int_t w, const Int_t h)
-    : TRootEmbeddedCanvas("SkyPosition", p, w-1, h-1, kRaisedFrame),//, 0) //234, 76, kFixedSize)
-    fModified(kFALSE)
-{
-    fCanvas = GetCanvas();
-
-    fCanvas->SetFillColor(39); // s. TAttFill
-    fCanvas->Range(-100, -100, 100, 100);
-
-    fList = new TList;
-    fList->SetOwner();
-
+MGSkyPosition::MGSkyPosition(const TGWindow* p, const UInt_t w)
+    : MGEmbeddedCanvas("SkyPosition", p, w, 110)
+{
     DrawCoordinateSystem();
+    InitPlanets();
     InitPosition();
-    InitPlanets();
-
-    Resize(w, h); //GetDefaultSize()); // ???
-    MapSubwindows();
+    InitText();
+    InitCanvas();
 }
 
 MGSkyPosition::~MGSkyPosition()
 {
-    delete fList;
     delete fSlalib;
 
@@ -161,5 +185,5 @@
 }
 
-void MGSkyPosition::SetLin1(int x, int y)
+void MGSkyPosition::SetLin1(Float_t x, Float_t y)
 {
     fLin1a->SetX2(x);
@@ -169,5 +193,5 @@
 }
 
-void MGSkyPosition::SetLin2(int x1, int y1, int x2, int y2)
+void MGSkyPosition::SetLin2(Float_t x1, Float_t y1, Float_t x2, Float_t y2)
 {
     fLin2->SetX1(x1);
@@ -177,5 +201,5 @@
 }
 
-void MGSkyPosition::DrawPosition(Float_t zd, Float_t az)
+void MGSkyPosition::UpdatePosition(Float_t zd, Float_t az)
 {
     static int X=~0;
@@ -187,21 +211,56 @@
     const float c = cos(rad);
 
-    const int x = (int)(s*zd);
-    const int y = (int)(c*zd);
-
-    if (X==x && Y==y)
+    const float x = s*zd;
+    const float y = c*zd;
+
+    const int pixx = (int)(x/fPix);
+    const int pixy = (int)(y/fPix);
+
+    if (X==pixx && Y==pixy)
         return;
 
-    X = x;
-    Y = y;
-
-    const int dx = (int)(s*4);
-    const int dy = (int)(c*4);
-
-    SetLin1(s*95, c*95);
+    X = pixx;
+    Y = pixy;
+
+    const float dx = s*4.;
+    const float dy = c*4.;
+
+    SetLin1(s*95., c*95.);
     SetLin2(x+dy, y-dx, x-dy, y+dx);
 
-    fModified = kTRUE;
-}
+    SetModified();
+}
+
+void MGSkyPosition::UpdateText(Float_t x, Float_t y)
+{
+    static int X = ~0;
+    static int Y = ~0;
+
+    int xd = (int)floor(x);
+    int yd = (int)floor(y);
+    x *= 60.;
+    y *= 60.;
+
+    int fx = (int)floor(x*10.);
+    int fy = (int)floor(y*10.);
+
+    if (X==fx && Y==fy)
+        return;
+
+    X = fx;
+    Y = fy;
+
+    float/*int*/ xm = /*(int)floor*/(fmod(fabs(x), 60.));
+    float/*int*/ ym = /*(int)floor*/(fmod(fabs(y), 60.));
+
+    char txt[100];
+    sprintf(txt, "Zd=%d\xb0%02.1f'\nAz=%d\xb0%02.1f'",
+            xd, xm, yd, ym);
+
+    fText->SetText(fText->GetX(), fText->GetY(), txt);
+
+    SetModified();
+}
+
 
 void MGSkyPosition::Update(ZdAz &pos)
@@ -212,25 +271,17 @@
     fSlalib->SetMjd2Now();
 
-    DrawPlanet(kESun,     fSun);
-    DrawPlanet(kEMoon,    fMoon);
-    DrawPlanet(kEJupiter, fJupiter);
-    DrawPlanet(kEVenus,   fVenus);
-    DrawPlanet(kEMars,    fMars);
-
-    DrawPosition(pos.Zd(), pos.Az());
-
-    if (!fModified)
-        return;
-
-    // FIXME: Sometimes (if the canvas couldn't be created correctly:
-    // X11 Pixmap error) Update hangs the Gui system.
-
-    fCanvas->Modified();
-    fCanvas->Update();
-
-    fModified = kFALSE;
-}
-
-void MGSkyPosition::DrawPlanet(Int_t planet, TArc *arc)
+    UpdatePlanet(kESun,     fSun);
+    UpdatePlanet(kEMoon,    fMoon);
+    UpdatePlanet(kEJupiter, fJupiter);
+    UpdatePlanet(kEVenus,   fVenus);
+    UpdatePlanet(kEMars,    fMars);
+
+    UpdatePosition(pos.Zd(), pos.Az());
+    UpdateText(pos.Zd(), pos.Az());
+
+    UpdateCanvas();
+}
+
+void MGSkyPosition::UpdatePlanet(Int_t planet, TArc *arc)
 {
     //
@@ -249,12 +300,15 @@
     const float deg = 360.0/D2PI*zdaz.Zd();
 
-    const int x = (int)(s*deg);
-    const int y = (int)(c*deg);
-
-    if (fX[planet]==x && fY[planet]==y)
+    const float x = s*deg;
+    const float y = c*deg;
+
+    const int pixx = (int)(x/fPix);
+    const int pixy = (int)(y/fPix);
+
+    if (fX[planet]==pixx && fY[planet]==pixy)
         return;
 
-    fX[planet] = x;
-    fY[planet] = y;
+    fX[planet] = pixx;
+    fY[planet] = pixy;
 
     //
@@ -264,5 +318,5 @@
     arc->SetY1(y);
 
-    fModified = kTRUE;
+    SetModified();
 
     if (planet!=kESun)
@@ -272,12 +326,12 @@
     cout << "   Zd=" << deg << " Az=" << 360./D2PI*zdaz.Az() << endl;
 
-    fSunL[0]->SetX1(x-4); fSunL[0]->SetX2(x+4);
-    fSunL[1]->SetX1(x-3); fSunL[1]->SetX2(x+3);
-    fSunL[2]->SetX1(x-3); fSunL[2]->SetX2(x+3);
-    fSunL[3]->SetX1(x  ); fSunL[3]->SetX2(x  );
-
-    fSunL[0]->SetY1(y  ); fSunL[0]->SetY2(y  );
-    fSunL[1]->SetY1(y-3); fSunL[1]->SetY2(y+3);
-    fSunL[2]->SetY1(y+3); fSunL[2]->SetY2(y-3);
-    fSunL[3]->SetY1(y-4); fSunL[3]->SetY2(y+4);
-}
+    fSunL[0]->SetX1(x-3.5); fSunL[0]->SetX2(x+3.5);
+    fSunL[1]->SetX1(x-2.5); fSunL[1]->SetX2(x+2.5);
+    fSunL[2]->SetX1(x-2.5); fSunL[2]->SetX2(x+2.5);
+    fSunL[3]->SetX1(x);     fSunL[3]->SetX2(x);
+
+    fSunL[0]->SetY1(y);     fSunL[0]->SetY2(y);
+    fSunL[1]->SetY1(y-2.5); fSunL[1]->SetY2(y+2.5);
+    fSunL[2]->SetY1(y+2.5); fSunL[2]->SetY2(y-2.5);
+    fSunL[3]->SetY1(y-3.5); fSunL[3]->SetY2(y+3.5);
+}
Index: trunk/MagicSoft/Cosy/gui/MGSkyPosition.h
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGSkyPosition.h	(revision 912)
+++ trunk/MagicSoft/Cosy/gui/MGSkyPosition.h	(revision 913)
@@ -9,20 +9,17 @@
 
 
-#ifndef ROOT_TRootEmbeddedCanvas
-#include <TRootEmbeddedCanvas.h>
+#ifndef MGEMBEDDEDCANVAS_H
+#include "MGEmbeddedCanvas.h"
 #endif
 
 class TArc;
-class TList;
 class TLine;
-class TCanvas;
 
 class ZdAz;
+class TText;
 class SlaPlanets;
 
-class MGSkyPosition : public TRootEmbeddedCanvas
+class MGSkyPosition : public MGEmbeddedCanvas
 {
-    TCanvas    *fCanvas;
-
     TArc       *fMoon;
     TArc       *fJupiter;
@@ -37,30 +34,25 @@
     TLine      *fSunL[4];
 
+    TText      *fText;
+
     SlaPlanets *fSlalib;
-
-    TList      *fList;
 
     Int_t fX[9];
     Int_t fY[9];
 
-    Bool_t fModified;
-
+    void InitText();
     void InitPlanets();
     void InitPosition();
-
-    void SetLin1(int x, int y);
-    void SetLin2(int x1, int y1, int x2, int y2);
-
-    void DrawPlanet(Int_t planet, TArc *arc);
-    void DrawPosition(Float_t zd, Float_t az);
     void DrawCoordinateSystem();
 
-    Bool_t CheckRange(Int_t x, Int_t y) const
-    {
-        return x>-95 && x<95 && y>-95 && y<95;
-    }
+    void SetLin1(Float_t x, Float_t y);
+    void SetLin2(Float_t x1, Float_t y1, Float_t x2, Float_t y2);
+
+    void UpdateText(Float_t zd, Float_t az);
+    void UpdatePlanet(Int_t planet, TArc *arc);
+    void UpdatePosition(Float_t zd, Float_t az);
 
 public:
-    MGSkyPosition(const TGWindow* p, const Int_t w, const Int_t h);
+    MGSkyPosition(const TGWindow* p, const UInt_t w);
     ~MGSkyPosition();
 
Index: trunk/MagicSoft/Cosy/gui/MGVelocity.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGVelocity.cc	(revision 913)
+++ trunk/MagicSoft/Cosy/gui/MGVelocity.cc	(revision 913)
@@ -0,0 +1,310 @@
+//
+// This File contains the definition of the MGCoordinates-class
+//
+//   Author: Thomas Bretz
+//   Version: V1.0 (1-8-2000)
+
+#include "MGVelocity.h"
+
+#include <iostream.h>  // cout
+
+#include <TArc.h>
+#include <TWbox.h>
+#include <TLine.h>
+#include <TText.h>
+#include <TList.h>
+#include <TGaxis.h>
+#include <TArrow.h>
+#include <TCanvas.h>
+
+#include "coord.h"
+
+void MGVelocity::DrawCoordinateSystem()
+{
+    /*
+    TArc arc;
+    arc.SetFillStyle(4000);  // transparent
+    arc.SetFillColor(39);
+    arc.SetLineColor(3);     // green
+    arc.SetLineStyle(2);     // dashed  (s. TAttLine)
+    arc.DrawArc(0, 0,  20);
+
+    arc.SetLineColor(5);     // yellow
+    arc.DrawArc(0, 0,  40);
+
+    arc.SetLineColor(2);     // red
+    arc.DrawArc(0, 0, 60);
+    */
+    //
+    // FIXME? Use TAxis?
+    //
+/*
+    TLine line;
+    line.SetLineColor(13);
+    line.SetLineStyle(3);  // dotted  (s. TAttLine)
+    line.DrawLine(-30., -65., -30.,  65.);
+    line.DrawLine(-65., -30.,  65., -30.);
+    line.DrawLine( 30., -65.,  30.,  65.);
+    line.DrawLine( -6.,  30.,  65.,  30.);
+
+    line.DrawLine(-15., -65., -15.,  65.);
+    line.DrawLine(-65., -15.,  65., -15.);
+    line.DrawLine( 15., -65.,  15.,  65.);
+    line.DrawLine(-65.,  15.,  65.,  15.);
+
+    line.DrawLine(-45., -65., -45.,  65.);
+    line.DrawLine(-65., -45.,  65., -45.);
+    line.DrawLine( 45., -65.,  45.,  65.);
+    line.DrawLine(-65.,  45.,  65.,  45.);
+
+    line.SetLineColor(12);
+    line.SetLineStyle(2);  // dashed  (s. TAttLine)
+    line.DrawLine(-60., -65., -60.,  65.);
+    line.DrawLine(-65., -60.,  65., -60.);
+    line.DrawLine( 60., -65.,  60.,  65.);
+    line.DrawLine(-65.,  60.,  65.,  60.);
+
+    line.SetLineColor(1);  // black
+    line.SetLineStyle(1);  // solid  (s. TAttLine)
+    line.DrawLine(-65.,   0, 65.,  0);
+    line.DrawLine(  0, -65.,  0, 65.);
+
+    line.DrawLine(-1.,  60., 1.,  60.);
+    line.DrawLine(-1., -60., 1., -60.);
+    line.DrawLine(-1.,  30., 1.,  30.);
+    line.DrawLine(-1., -30., 1., -30.);
+
+    line.DrawLine( 60., -1.,  60., 1.);
+    line.DrawLine(-60., -1., -60., 1.);
+    line.DrawLine( 30., -1.,  30., 1.);
+    line.DrawLine(-30., -1., -30., 1.);
+
+    TText text;
+    text.SetTextAlign(22);  // centered, centered (s.TAttText)
+    text.DrawText(60., 5., "vAz['/min]");
+    text.DrawText(0,  70., "vZd['/min]");
+
+    text.SetTextAlign(23);  // centered, centered (s.TAttText)
+    text.DrawText(-60., -2., "-1'");
+    text.DrawText( 60., -2., "1'");
+    text.DrawText(-30., -2., "-.5'");
+    text.DrawText( 30., -2., ".5'");
+
+    text.SetTextAlign(32);  // centered, centered (s.TAttText)
+    text.DrawText(-2., -60., "-1'");
+    text.DrawText(-2.,  60., "1'");
+    text.DrawText(-2., -30., "-.5'");
+    text.DrawText(-2.,  30., ".5'");
+    */
+    TWbox box;
+    box.DrawWbox(-145, 145, -35, 120,  18,  2, 1);
+
+    TText text;
+    text.SetTextAlign(22);  // centered, centered (s.TAttText)
+    text.DrawText(-90., 132.5, fCanvas->GetName());
+
+
+    TLine line;
+    line.DrawLine(-65*2,     0, 65*2,    0);
+    line.DrawLine(    0, -65*2,    0, 65*2);
+
+    TGaxis *axe;
+    axe = new TGaxis(-60*2, 0, 60*2, 0,  -2, 2,  304, "+-N");
+    axe->SetTitle("Az"); // \xb0
+    axe->SetBit(kCanDelete);
+    axe->Draw();
+
+    axe = new TGaxis(0, -60*2, 0, 60*2,  -2, 2,  304, "+-N");
+    axe->SetTitle("Zd"); // \xb0
+    axe->SetBit(kCanDelete);
+    axe->Draw();
+}
+
+void MGVelocity::InitVelocity()
+{
+    /*
+     fLin1  = new TLine(0, 0, 0, 0);
+    fLin2  = new TLine(0, 0, 0, 0);
+
+    fLin1->SetLineColor(10); // white (s. TAttFill)
+    fLin2->SetLineColor(10); // white
+    fLin1->SetLineStyle(1);  // solid (s. TAttLine)
+    fLin2->SetLineStyle(1); 
+
+    fLin1->Draw();
+    fLin2->Draw();
+
+    fList->Add(fLin1);
+    fList->Add(fLin2);
+    */
+    fArrow    = new TArrow(0, 0, 0, 0, 0.01);
+    fArrowX   = new TArrow(0, 0, 0, 0, 0.01);
+    fArrowY   = new TArrow(0, 0, 0, 0, 0.01);
+    fArrowAvg = new TArrow(0, 0, 0, 0, 0.01);
+
+    fArrow->SetLineColor(10);   // white
+    fArrowX->SetLineColor(17);  // light gray
+    fArrowY->SetLineColor(17);  // light gray
+    fArrowAvg->SetLineColor(137);  // light gray
+
+    fArrow->Draw();
+    fArrowX->Draw();
+    fArrowY->Draw();
+    fArrowAvg->Draw();
+
+    fList->Add(fArrow);
+    fList->Add(fArrowX);
+    fList->Add(fArrowY);
+    fList->Add(fArrowAvg);
+
+    fText = new TText(70*2, -70*2, "x1");
+    fText->SetTextColor(10);
+    fText->SetTextAlign(31); // right, bottom
+    fText->Draw();
+    fList->Add(fText);
+}
+
+MGVelocity::MGVelocity(const TGWindow* p, const char *name, const UInt_t w)
+: MGEmbeddedCanvas(name, p, w, 75*2), fPos(-1), fScale(1)
+{
+    fOld = new XY;
+    fAvg = new XY[10];
+
+    DrawCoordinateSystem();
+    InitVelocity();
+
+    InitCanvas();
+}
+
+MGVelocity::~MGVelocity()
+{
+    delete fList;
+
+    delete fOld;
+    delete fAvg;
+
+    cout << "MGVelocity destroyed." << endl;
+}
+
+void MGVelocity::UpdateText()
+{
+    char txt[10];
+
+    if (fScale>1)
+        sprintf(txt,  "/%.0f", fScale);
+    else
+        sprintf(txt,  "x%.0f", 1./fScale);
+
+    fText->SetText(fText->GetX()/*70*2*/, fText->GetY()/*70*2*/, txt);
+}
+
+Bool_t MGVelocity::UpdateAvg(const float x, const float y)
+{
+
+    //
+    // calculate scale factor from avarage over
+    // speed, not pixels
+    //
+    // different scales for Az and Zd
+    //
+    // check for the number of the value
+    //
+    //
+    const int num = 10;
+
+    //    static int pos = -1;
+    //    static XY avg[num];
+
+    if (fPos<0)
+        for (int i=1; i<num; i++)
+            fAvg[i].Set(x, y);
+
+    fPos++;
+    fPos %= num;
+
+    fAvg[fPos].Set(x, y);
+
+    Float_t avgx = 0;
+    Float_t avgy = 0;
+
+    for (int i=0; i<num; i++)
+    {
+        avgx += fAvg[i].X();
+        avgy += fAvg[i].Y();
+    }
+
+    avgx /= 10.;
+    avgy /= 10.;
+
+    avgx *= fScale;
+    avgy *= fScale;
+
+    fArrowAvg->SetX2(avgx);
+    fArrowAvg->SetY2(avgy);
+
+    //    cout << avgx << " " << avgy << endl;
+
+    if ((fabs(avgx)>/*40.*/110. || fabs(avgy)>/*40.*/110.))
+    {
+        fScale /= 2;
+        return kTRUE;
+    }
+
+    if ((fabs(avgx)< 5. && fabs(avgy)<20.) ||
+        (fabs(avgx)<20. && fabs(avgy)< 5.))
+    {
+        fScale *= 2;
+        return kTRUE;
+    }
+
+    return kFALSE;
+}
+
+
+void MGVelocity::Update(ZdAz &zdaz)
+{
+    //
+    // calculate actual time for planet positions
+    //
+    //    static int X = 0xaffe;
+    //    static int Y = 0xaffe;
+
+    float x = zdaz.Az()*3600.*4;
+    float y = zdaz.Zd()*3600.*4;
+
+    int pixx = (int)(x*fScale/fPix);
+    int pixy = (int)(y*fScale/fPix);
+
+    //
+    // FIXME! Check for the right place!
+    //
+    Bool_t rc = kFALSE;
+
+    if (pixx || pixy)
+        rc = UpdateAvg(x, y);
+
+    if (rc)
+        UpdateText();
+
+    if (!rc && (int)fOld->X()==pixx && (int)fOld->Y()==pixy)
+        return;
+
+    //    cout << fScale << ": " << pixx << " " << pixy;
+    //    cout << fScale << ": " << (int)rc << (int)((int)fOld->X()==pixx) << (int)((int)fOld->Y()==pixy) << "  ";
+    //    cout << zdaz.Az()*3600. << " " << zdaz.Zd()*3600. << endl;
+
+    x *= fScale;
+    y *= fScale;
+
+    fArrow->SetX2(x);
+    fArrow->SetY2(y);
+
+    fArrowX->SetX2(x);
+    fArrowY->SetY2(y);
+
+    fOld->Set(pixx, pixy);
+
+    SetModified();
+    UpdateCanvas();
+
+}
Index: trunk/MagicSoft/Cosy/gui/MGVelocity.h
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGVelocity.h	(revision 913)
+++ trunk/MagicSoft/Cosy/gui/MGVelocity.h	(revision 913)
@@ -0,0 +1,53 @@
+#ifndef MGVELOCITY_H
+#define MGVELOCITY_H
+
+//
+// This File contains the declaration of the MGCoordinates-class
+//
+//   Author: Thomas Bretz
+//   Version: V1.0 (1-8-2000)
+
+#ifndef MGEMBEDDEDCANVAS_H
+#include "MGEmbeddedCanvas.h"
+#endif
+
+class TList;
+class TText;
+class TArrow;
+class TCanvas;
+
+class XY;
+class ZdAz;
+class SlaPlanets;
+
+class MGVelocity : public MGEmbeddedCanvas
+{
+    TArrow *fArrow;
+
+    TArrow *fArrowX;
+    TArrow *fArrowY;
+
+    TArrow *fArrowAvg;
+
+    TText *fText;
+
+    XY *fOld;
+    XY *fAvg;
+    Char_t fPos;
+
+    Float_t fScale;
+
+    Bool_t UpdateAvg(const float x, const float y);
+
+    void InitVelocity();
+    void DrawCoordinateSystem();
+    void UpdateText();
+
+public:
+    MGVelocity(const TGWindow* p, const char *name, const UInt_t w);
+    ~MGVelocity();
+
+    void Update(ZdAz &pos);
+};
+
+#endif // MGSKYPOSITION_H
Index: trunk/MagicSoft/Cosy/gui/Makefile
===================================================================
--- trunk/MagicSoft/Cosy/gui/Makefile	(revision 912)
+++ trunk/MagicSoft/Cosy/gui/Makefile	(revision 913)
@@ -35,5 +35,7 @@
 	   MGCosy.cc \
 	   MGImage.cc \
+	   MGEmbeddedCanvas.cc \
 	   MGAccuracy.cc \
+	   MGVelocity.cc \
 	   MGSkyPosition.cc
 
