Index: trunk/MagicSoft/Cosy/base/MGList.h
===================================================================
--- trunk/MagicSoft/Cosy/base/MGList.h	(revision 1687)
+++ trunk/MagicSoft/Cosy/base/MGList.h	(revision 1690)
@@ -1,40 +1,33 @@
-#ifndef MGLIST_H
-#define MGLIST_H
+#ifndef MARS_MGList
+#define MARS_MGList
 
-#ifdef DBG_MGLIST
-#include <iostream.h>
+#ifndef ROOT_TList
+#include <TList.h>
 #endif
 
-#ifndef ROOT_TOrdCollection
-#include <TOrdCollection.h>
-#endif
+class TGWidget;
+class TGPicture;
 
-class MGList : public TOrdCollection
+class MGList : public TList
 {
+private:
+    TGWidget *GetWidget(TObject *obj) const;
+    Bool_t    IsExisting(TObject *obj) const;
+
+    void      AddPicture(const TGPicture *pic, const char *name);
+
 public:
-    ~MGList()
-    {
-#ifdef DBG_MGLIST
-        cout << "Deleting:" << flush;
-#endif
+    MGList() : TList() {}
+    virtual ~MGList();
 
-        TIter Next(this);
+    void Add(TObject *obj);
+    void Add(TObject *obj, Option_t *opt);
 
-        TObject *obj;
-        while ((obj=Next()))
-        {
-#ifdef DBG_MGLIST
-            cout << " <" << ((TGObject*)obj)->GetName() << ">" << flush;
-#endif
-            delete (TGObject*)obj;
-        }
-#ifdef DBG_MGLIST
-        cout << endl;
-#endif
-    }
-    void Add(TGObject *obj)
-    {
-        TOrdCollection::Add(obj);
-    }
+    const TGPicture *GetPicture(const char *name);
+    const TGPicture *GetPicture(const char *name, Int_t width, Int_t height);
+
+    TObject *FindWidget(Int_t id) const;
+
+    ClassDef(MGList, 0)
 };
 
Index: trunk/MagicSoft/Cosy/candrv/network.cc
===================================================================
--- trunk/MagicSoft/Cosy/candrv/network.cc	(revision 1687)
+++ trunk/MagicSoft/Cosy/candrv/network.cc	(revision 1690)
@@ -237,5 +237,8 @@
             lout << "- Setting up Node #" << dec << i << endl;
             fNodes[i]->InitDevice(this);
-            fNodeInitialized[i] = TRUE;
+            if (!fNodes[i]->IsZombieNode())
+                fNodeInitialized[i] = TRUE;
+            else
+                fNodes[i]=NULL;
         }
     lout << "- All Nodes setup." << endl;
Index: trunk/MagicSoft/Cosy/candrv/nodedrv.cc
===================================================================
--- trunk/MagicSoft/Cosy/candrv/nodedrv.cc	(revision 1687)
+++ trunk/MagicSoft/Cosy/candrv/nodedrv.cc	(revision 1690)
@@ -56,5 +56,5 @@
 // and the node name. The name is a name for debug output.
 //
-NodeDrv::NodeDrv(BYTE_t nodeid, const char *name, MLog &out) : Log(out), fNetwork(NULL), fId(32), fError(0)
+NodeDrv::NodeDrv(BYTE_t nodeid, const char *name, MLog &out) : Log(out), fNetwork(NULL), fId(32), fError(0), fIsZombie(kFALSE)
 {
     if (nodeid>0x1f)
@@ -311,8 +311,9 @@
 // this device has been received.
 // You can stop waiting by StopWaitingForSDO.
-//
-void NodeDrv::WaitForSdo(WORD_t idx, BYTE_t subidx, WORDS_t timeout)
-{
-    fNetwork->WaitForSdo(fId, idx, subidx, timeout);
+// Return false if waiting timed out.
+//
+bool NodeDrv::WaitForSdo(WORD_t idx, BYTE_t subidx, WORDS_t timeout)
+{
+    return fNetwork->WaitForSdo(fId, idx, subidx, timeout);
 }
 
Index: trunk/MagicSoft/Cosy/candrv/nodedrv.h
===================================================================
--- trunk/MagicSoft/Cosy/candrv/nodedrv.h	(revision 1687)
+++ trunk/MagicSoft/Cosy/candrv/nodedrv.h	(revision 1690)
@@ -34,4 +34,6 @@
     void DelError()        { fError = 0; }
 
+    Bool_t fIsZombie;
+
 public:
     NodeDrv(BYTE_t nodeid, const char *name=NULL, MLog &out=gLog);
@@ -47,4 +49,6 @@
     int  GetError() const { return fError; }
     bool HasError() const { return fError; }
+
+    bool IsZombieNode() const { return fIsZombie; }
 
     virtual void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, timeval_t *tv);
@@ -82,5 +86,5 @@
 
     // void WaitForSdos();
-    void WaitForSdo(WORD_t idx, BYTE_t subidx=0, WORDS_t timeout=500);
+    bool WaitForSdo(WORD_t idx, BYTE_t subidx=0, WORDS_t timeout=500);
 
     void EnableCanMsg(BYTE_t fcode);
Index: trunk/MagicSoft/Cosy/devdrv/macs.cc
===================================================================
--- trunk/MagicSoft/Cosy/devdrv/macs.cc	(revision 1687)
+++ trunk/MagicSoft/Cosy/devdrv/macs.cc	(revision 1690)
@@ -113,4 +113,9 @@
         fVelRes = val;
         return;
+
+    case 0x6501:
+        lout << "- Encoder resolution " << GetNodeName() << ": " << dec << val << " ticks/min" << endl;
+        fRes = val;
+        return;
     }
     cout << "Macs: SDO, idx=0x"<< hex << idx << "/" << (int)subidx;
@@ -211,5 +216,7 @@
 void Macs::InitDevice(Network *net)
 {
+    lout << "- MAC Init device." << endl;
     NodeDrv::InitDevice(net);
+    lout << "- MAC Init device...done." << endl;
 
 //    SendSDO(0x4003, (LWORD_t)('E'<<24 | 'X'<<16 | 'I'<<8 'T'));
@@ -295,4 +302,11 @@
     RequestSDO(0x6004);
     WaitForSdo(0x6004);
+}
+
+void Macs::ReqRes()
+{
+    lout << "- Requesting Encoder Resolution of " << GetNodeName() << endl;
+    RequestSDO(0x6501);
+    WaitForSdo(0x6501);
 }
 
@@ -491,4 +505,5 @@
     case 100:
         lout << "Connection timed out." << endl;
+        EnableTimeout(false);
         return;
 
@@ -592,4 +607,5 @@
 void Macs::EnableTimeout(bool enable, LWORDS_t ms)
 {
+    lout << "- MAC " << (enable?"En":"Dis") << "able timeout, " << dec << ms << "ms." << endl;
     if (!enable)
     {
@@ -597,4 +613,6 @@
         WaitForSdo(0x4000, 1);
 
+        lout << "- Stopping handshake (PC)." << endl;
+
         fTimeout->Stop(); //kTRUE);
 
@@ -610,4 +628,5 @@
         fTimerOn = kTRUE;
         fTimeout->Start(fGuardTime/*/3*2*/, kTRUE); //kFALSE); //TRUE);
+
         //
         // Start with kFALSE would be a continous timer, but this
@@ -615,7 +634,7 @@
         // any reason
         //
-
-//        SendSDO(0x4000, 1, string('o', 'n'));
-//        WaitForSdo(0x4000, 1);
+        lout << "- MAC starting handshake." << endl;
+        SendSDO(0x4000, 1, string('o', 'n'));
+        WaitForSdo(0x4000, 1);
     }
     lout << "- Timeout timer of " << GetNodeName() << " turned "
@@ -666,5 +685,5 @@
     // --- lout << edev(MLog::eGui);
 
-    if (time.Now() > fTimeoutTime+0.5)
+    if (time.Now() > fTimeoutTime)
     {
         lout << ddev(MLog::eGui);
@@ -703,5 +722,5 @@
     fGuardTime = ms/3;      // how often do we send/request the handshake
 
-    SendSDO(0x4000, 2, ms); // How often do we check for the handshake
+    SendSDO(0x4000, 2, ms*2); // How often do we check for the handshake
     WaitForSdo(0x4000, 2);
 }
Index: trunk/MagicSoft/Cosy/devdrv/macs.h
===================================================================
--- trunk/MagicSoft/Cosy/devdrv/macs.h	(revision 1687)
+++ trunk/MagicSoft/Cosy/devdrv/macs.h	(revision 1690)
@@ -18,4 +18,6 @@
     Timer    fPosTime;
 
+    LWORD_t  fRes;      // Encoder resolution
+
     LWORDS_t fPdoPos;
     Timer    fPdoTime;
@@ -36,4 +38,6 @@
     void ResetTimeout();
     Bool_t HandleTimer(TTimer *t);
+
+    void ReqRes();
 
 public:
@@ -100,4 +104,5 @@
     LWORDS_t GetVel()    { return fVel; }
     LWORD_t  GetVelRes() { return fVelRes; } // Velocity units (would be 100 for %)
+    LWORD_t  GetRes()    { return fRes; }    // Encoder resolution
 
     void HandleError();
Index: trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc
===================================================================
--- trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc	(revision 1687)
+++ trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc	(revision 1690)
@@ -200,5 +200,10 @@
     lout << "- Requesting Hardware Type (SDO 0x1000) of " << GetNodeName() << endl;
     RequestSDO(0x1000);
-    WaitForSdo(0x1000);
+    if (!WaitForSdo(0x1000))
+    {
+        lout << "  ... failed." << endl;
+        fIsZombie = true;
+        return;
+    }
 
     //
Index: trunk/MagicSoft/Cosy/devdrv/shaftencoder.h
===================================================================
--- trunk/MagicSoft/Cosy/devdrv/shaftencoder.h	(revision 1687)
+++ trunk/MagicSoft/Cosy/devdrv/shaftencoder.h	(revision 1690)
@@ -51,4 +51,5 @@
 
     LWORDS_t GetPos() { return fPos+fTurn*fTicks; }
+    LWORD_t  GetPhysRes() { return fTicks; }
 
     double GetTime();
Index: trunk/MagicSoft/Cosy/gui/MGCosy.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGCosy.cc	(revision 1687)
+++ trunk/MagicSoft/Cosy/gui/MGCosy.cc	(revision 1690)
@@ -30,8 +30,11 @@
 #include "SlaStars.h"
 
+#undef DEBUG
+
 ClassImp(MGCosy);
 
-#define IDM_EXIT 1
-#define IDM_TEXT 2
+#define IDM_EXIT   1
+#define IDM_TEXT   2
+#define IDM_ASPECT 3
 
 enum
@@ -60,4 +63,5 @@
     //
     TGPopupMenu *fFileMenu = new TGPopupMenu(gClient->GetRoot());
+    fFileMenu->AddEntry("Set Aspect", IDM_ASPECT);
     fFileMenu->AddEntry("Exit", IDM_EXIT);
     fFileMenu->Associate(this);
@@ -477,22 +481,35 @@
     fList = new MGList;
 
+#ifdef DEBUG
     cout << "MGCosy: Creating Menu" << endl;
+#endif
     CreateMenu();
 
+#ifdef DEBUG
     cout << "MGCosy: Creating TGCompositeFrame" << endl;
-    TGCompositeFrame *f = new TGCompositeFrame(this, 0, 0);
-    f->SetLayoutManager(new TGMatrixLayout(f, 3, 2, 10));
-    fList->Add(f);
-
+#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;
-    fTab = new TGTab(f, 300, 300);
+#endif
+    fTab = new TGTab(f1, 300, 300);
     fList->Add(fTab);
 
+#ifdef DEBUG
     cout << "MGCosy: Creating MGSkyPosition" << endl;
-    fSkyPosition = new MGSkyPosition(f, 300);
+#endif
+    fSkyPosition = new MGSkyPosition(f1, 300);
+#ifdef DEBUG
     cout << "MGCosy: Creating MGAccuracy" << endl;
-    fAccuracy    = new MGAccuracy   (f, 300);
+#endif
+    fAccuracy    = new MGAccuracy   (f1, 300);
+#ifdef DEBUG
     cout << "MGCosy: Creating MGVelocity" << endl;
-    fVelocity    = new MGVelocity   (f, "Velocity [\"/min]", 300);
+#endif
+    fVelocity    = new MGVelocity   (f2, "Velocity [\"/min]", 300);
 //    fOffset      = new MGVelocity   (f, "Offset se-re [']", 300);
 
@@ -502,33 +519,61 @@
 //    fList->Add(fOffset);
 
+#ifdef DEBUG
     cout << "MGCosy: Creating TGGroupFrame" << endl;
-    TGGroupFrame *frame = new TGGroupFrame(f, "Status");
+#endif
+    TGGroupFrame *frame = new TGGroupFrame(f2, "Status");
     frame->Resize(300, 300);
     fList->Add(frame);
 
+#ifdef DEBUG
     cout << "MGCosy: Creating TGListBox" << endl;
-    fLog = new TGListBox(f, -1, kSunkenFrame);  //kSunkenFrame|kDoubleBorder,
+#endif
+    fLog = new TGListBox(f2, -1, kSunkenFrame);  //kSunkenFrame|kDoubleBorder,
     fLog->Resize(300, 300);
     fLog->ChangeBackground(TGFrame::GetBlackPixel());
     fList->Add(fLog);
 
-    //
-    // Layout the window, tile by tile...
-    //
-    f->AddFrame(fTab);
-    f->AddFrame(fSkyPosition);
-    f->AddFrame(fAccuracy);
-    f->AddFrame(frame);
-    f->AddFrame(fVelocity);
-    f->AddFrame(fLog);
-
-    AddFrame(f, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 1, 0));
+    TGLayoutHints *hints1  = new TGLayoutHints(kLHintsNormal  | kLHintsExpandX|kLHintsExpandY, 6, 6, 6, 3);
+    TGLayoutHints *hints2  = new TGLayoutHints(kLHintsNormal  | kLHintsExpandX|kLHintsExpandY, 6, 6, 3, 6);
+    TGLayoutHints *hints1a = new TGLayoutHints(kLHintsLeft    | kLHintsTop   |kLHintsExpandX|kLHintsExpandY);
+    TGLayoutHints *hints2a = new TGLayoutHints(kLHintsCenterY | kLHintsTop   |kLHintsExpandX|kLHintsExpandY, 6, 6);
+    TGLayoutHints *hints3a = new TGLayoutHints(kLHintsRight   | kLHintsTop   |kLHintsExpandX|kLHintsExpandY);
+    TGLayoutHints *hints1b = new TGLayoutHints(kLHintsLeft    | kLHintsBottom|kLHintsExpandX|kLHintsExpandY);
+    TGLayoutHints *hints2b = new TGLayoutHints(kLHintsCenterY | kLHintsBottom|kLHintsExpandX|kLHintsExpandY, 6, 6);
+    TGLayoutHints *hints3b = new TGLayoutHints(kLHintsRight   | kLHintsBottom|kLHintsExpandX|kLHintsExpandY);
+
+    fList->Add(hints1);
+    fList->Add(hints2);
+    fList->Add(hints1a);
+    fList->Add(hints2a);
+    fList->Add(hints3a);
+    fList->Add(hints1b);
+    fList->Add(hints2b);
+    fList->Add(hints3b);
+
+    // Layout upper frame
+    f1->AddFrame(fTab,         hints1a);
+    f1->AddFrame(fSkyPosition, hints2a);
+    f1->AddFrame(fAccuracy,    hints3a);
+
+    // Layout upper frame
+    f2->AddFrame(frame,        hints1b);
+    f2->AddFrame(fVelocity,    hints2b);
+    f2->AddFrame(fLog,         hints3b);
+
+    // Layout window
+    AddFrame(f1, hints1);
+    AddFrame(f2, hints2);
 
     //
     // FIXME!
     //
+#ifdef DEBUG
     cout << "MGCosy: Creating Tabs" << endl;
+#endif
     CreateTabs(fTab);
+#ifdef DEBUG
     cout << "MGCosy: Creating Label" << endl;
+#endif
     CreateLabel(frame);
 
@@ -536,15 +581,19 @@
     //   Map the window, set up the layout, etc.
     //
+#ifdef DEBUG
     cout << "MGCosy: Setting Size" << endl;
+#endif
     const Int_t w = 940;
     const Int_t h = 660;
-    SetWMSizeHints(w, h, w, h, 10, 10);  // set the smallest and biggest size of the Main frame
+    SetWMSizeHints(w, h, 1280, 900, 10, 10);  // set the smallest and biggest size of the Main frame
 
     SetWindowName("Cosy Main Window");
     SetIconName("Cosy");
 
+#ifdef DEBUG
     cout << "MGCosy: Map Window" << endl;
+#endif
     MapSubwindows();
-    Resize(GetDefaultSize());
+    Resize(w, h); //GetDefaultSize());
     MapWindow();
 }
@@ -930,4 +979,13 @@
                 //CloseWindow();
                 return kTRUE;
+            case IDM_ASPECT:
+                Int_t w = GetWidth();
+                Int_t h = GetHeight();
+                if (w>940*h/660)
+                    w = 940*h/660;
+                else
+                    h = 660*w/940;
+                Resize(w, h); 
+                return kTRUE;
             }
             return kTRUE;
Index: trunk/MagicSoft/Cosy/gui/MGEmbeddedCanvas.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGEmbeddedCanvas.cc	(revision 1687)
+++ trunk/MagicSoft/Cosy/gui/MGEmbeddedCanvas.cc	(revision 1690)
@@ -12,4 +12,6 @@
 #include <TCanvas.h>
 
+#undef DEBUG
+
 ClassImp(MGEmbeddedCanvas);
 
@@ -19,12 +21,19 @@
       fModified(kFALSE), fWidth(width), fRange(range), fPix(2.*range/width)
 {
+#ifdef DEBUG
     cout << "MGEmbeddedCanvas: Initializing." << endl;
+#endif
+
     fCanvas = GetCanvas();
 
+#ifdef DEBUG
     cout << "MGEmbeddedCanvas: fCanvas = 0x" << fCanvas << endl;
 
     cout << "MGEmbeddedCanvas: SetFillColor." << endl;
+#endif
     fCanvas->SetFillColor(39); // s. TAttFill
+#ifdef DEBUG
     cout << "MGEmbeddedCanvas: fRange=" << fRange << endl;
+#endif
     if (fRange>0)
         fCanvas->Range(-fRange, -fRange, fRange, fRange);
@@ -33,5 +42,7 @@
     fList->SetOwner();
 
+#ifdef DEBUG
     cout << "MGEmbeddedCanvas: Initializing done." << endl;
+#endif
 }
 
Index: trunk/MagicSoft/Cosy/gui/MGImage.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGImage.cc	(revision 1687)
+++ trunk/MagicSoft/Cosy/gui/MGImage.cc	(revision 1690)
@@ -11,4 +11,9 @@
 #include <iostream.h>
 #include <pthread.h>
+
+#include <TTimer.h>
+#include <TSystem.h>
+#include <TVirtualX.h>
+#include <TGX11.h>
 
 ClassImp(MGImage);
@@ -97,12 +102,7 @@
 
     //
-    // get frame id
-    //
-    fId = GetId();
-
-    //
     // Create Default Graphic Context (XCreateGC)
     //
-    fDefGC = gVirtualX->CreateGC(fId, 0); // GetBckgndGC(); //
+    fDefGC = gVirtualX->CreateGC(fId, 0); // GetBckgndGC().GetGC(); //
 
     //
@@ -120,9 +120,13 @@
 
     Resize(w, h);
+
+    //fTimer=new TTimer(Form("gClient->ProcessEventsFor((TGWindow*)0x%p);", this), 250, kTRUE);
+//    fTimer=new TTimer("printf(\"Timer!\\n\"); gSystem->ProcessEvents();", 250, kTRUE);
+    //fTimer->Start();
 }
 
 void MGImage::Resize(UInt_t w, UInt_t h)
 {
-    TGFrame::Resize(w+2*GetBorderWidth(), h+2*GetBorderWidth());
+//    TGFrame::Resize(w+2*GetBorderWidth(), h+2*GetBorderWidth());
     // FIXME: RESIZE THE PIXMAP
 }
@@ -130,5 +134,5 @@
 void MGImage::Resize(TGDimension size)
 {
-    TGFrame::Resize(size.fWidth+2*GetBorderWidth(), size.fHeight+2*GetBorderWidth());
+//    TGFrame::Resize(size.fWidth+2*GetBorderWidth(), size.fHeight+2*GetBorderWidth());
     // FIXME: RESIZE THE PIXMAP
 }
@@ -136,5 +140,5 @@
 void MGImage::MoveResize(Int_t x, Int_t y, UInt_t w, UInt_t h)
 {
-   TGFrame::MoveResize(x, y, w+2*GetBorderWidth(), h+2*GetBorderWidth());
+//   TGFrame::MoveResize(x, y, w+2*GetBorderWidth(), h+2*GetBorderWidth());
    // FIXME: RESIZE THE PIXMAP
 }
@@ -142,4 +146,7 @@
 MGImage::~MGImage()
 {
+    //fTimer->Stop();
+    //delete fTimer;
+
     pthread_mutex_lock((pthread_mutex_t*)fMuxPixmap);
 
@@ -154,8 +161,12 @@
 
     if (fPixmap!=kNone) // @@@
+    {
+        cout << "Delete Pixmap" << endl;
         gVirtualX->DeletePixmap(fPixmap);  // XFreePixmap(fDisplay, (Pixmap) pmap);
+    }
 
     cout << "Deleting GC..." << endl;
 
+
     gVirtualX->DeleteGC(fDefGC);       // XFreeGC(fDisplay, (GC) gc);
 
@@ -165,6 +176,6 @@
 }
 
+#include <X11/Xlib.h>
 /*
-#include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include <X11/Intrinsic.h>
@@ -174,8 +185,29 @@
 void MGImage::DoRedraw()
 {
-    // Pixmap_t pm = gVirtualX->CreatePixmap(this->GetId(), buffer,
-    //                                       768, 576, 0, 0xff, 8);
-    TGFrame::DrawBorder();
+//    TGFrame::DrawBorder();
     pthread_mutex_lock((pthread_mutex_t*)fMuxPixmap);
+
+    //===========================
+    if (TestBit(kNeedRecreate))
+    {
+        Pixmap_t mask = kNone;
+        PictureAttributes_t attr;
+        attr.fMask = kNone;
+
+        if (fPixmap!=kNone)
+            gVirtualX->DeletePixmap(fPixmap);
+
+        fPixmap=kNone;
+
+        if (!gVirtualX->CreatePictureFromData(fId, fBuffer, fPixmap,
+                                              mask, attr))
+        {
+            cout << "Warning: Error in CreatePictureFromData" << endl;
+            fPixmap=kNone;
+        }
+        ResetBit(kNeedRecreate);
+    }
+
+    //===========================
 
     // Copy a drawable (i.e. pixmap) to another drawable (pixmap, window).
@@ -185,7 +217,19 @@
     //           dest_x, dest_y);
     if (fPixmap!=kNone) //@@@
-    gVirtualX->CopyArea(fPixmap, fId, fDefGC,
-                        0, 0, fWidth, fHeight,
-                        GetBorderWidth(), GetBorderWidth());
+    {
+//        gVirtualX->DrawString(fId, fDefGC, 20, 20, "HELLO WORLD!", 12);
+//        gVirtualX->FillRectangle(fId, fDefGC, 10, 10, 50, 50);
+
+        //        cout << gVirtualX->IsA()->GetName() << endl;
+        gVirtualX->CopyArea(fPixmap, fId, fDefGC,
+                            0, 0, fWidth, fHeight,
+                            GetBorderWidth(), GetBorderWidth());
+
+        /*
+        XCopyArea((Display*)gVirtualX->GetDisplay(), pm, fId,
+                  (GC)fDefGC, 0, 0, fWidth, fHeight,
+                  GetBorderWidth(), GetBorderWidth());
+                  */
+    }
 /*
      if (fPix)
@@ -271,9 +315,11 @@
     cout << "Done " << (void*)fPix << endl;
     */
+
+/*
     Pixmap_t mask = kNone;
     PictureAttributes_t attr;
     attr.fMask = kNone;
     if (fPixmap!=kNone) // @@@
-    gVirtualX->DeletePixmap(fPixmap); // XFreePixmap(fDisplay, (Pixmap) pmap);
+        gVirtualX->DeletePixmap(fPixmap); // XFreePixmap(fDisplay, (Pixmap) pmap);
 
     // Create a pixture pixmap from data. The picture attributes
@@ -310,7 +356,13 @@
         fPixmap=kNone;
     }
-
+*/
+    SetBit(kNeedRecreate);
     pthread_mutex_unlock((pthread_mutex_t*)fMuxPixmap);
-    DoRedraw();
+    //gClient->NeedRedraw(this);
+    //fTimer->Start(10, kTRUE);
+    //gVirtualX->UpdateWindow(1);
+    //    ((TGX11*)gVirtualX)->Sync(1);
+    //new TTimer(Form("gClient->ProcessEventsFor((TGWindow*)0x%p);", this), 1, kFALSE);
+    //    DoRedraw();
 }
 
@@ -339,5 +391,5 @@
         }
     }
-
+/*
     Pixmap_t mask = kNone;
     PictureAttributes_t attr;
@@ -346,4 +398,5 @@
     if (fPixmap!=kNone)
         gVirtualX->DeletePixmap(fPixmap);
+
     fPixmap=kNone;
 
@@ -354,7 +407,13 @@
         fPixmap=kNone;
     }
-
+    */
+    SetBit(kNeedRecreate);
     pthread_mutex_unlock((pthread_mutex_t*)fMuxPixmap);
-    DoRedraw();
-}
-
+    //gClient->NeedRedraw(this);
+    //fTimer->Start(10, kTRUE);
+    //gVirtualX->UpdateWindow(1);
+    //    ((TGX11*)gVirtualX)->Sync(1);
+    //new TTimer(Form("gClient->ProcessEventsFor((TGWindow*)0x%p);", this), 1, kFALSE);
+    //    DoRedraw();
+}
+
Index: trunk/MagicSoft/Cosy/gui/MGImage.h
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGImage.h	(revision 1687)
+++ trunk/MagicSoft/Cosy/gui/MGImage.h	(revision 1690)
@@ -10,4 +10,6 @@
 #include <TGFrame.h>
 
+class TTimer;
+
 typedef unsigned char byte;
 
@@ -20,5 +22,4 @@
 
     GContext_t fDefGC;
-    Drawable_t fId;
     Pixmap_t   fPixmap;
 
@@ -28,5 +29,7 @@
     void *fMuxPixmap; //! test
 
-public:
+    TTimer *fTimer;
+
+    enum { kNeedRecreate = BIT(17) };
 
 public:
Index: trunk/MagicSoft/Cosy/gui/MGSkyPosition.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGSkyPosition.cc	(revision 1687)
+++ trunk/MagicSoft/Cosy/gui/MGSkyPosition.cc	(revision 1690)
@@ -172,5 +172,4 @@
     : MGEmbeddedCanvas("SkyPosition", p, w, 110)
 {
-    cout << "MGSkyPosition: Initilizing." << endl;
     DrawCoordinateSystem();
     InitPlanets();
@@ -178,5 +177,4 @@
     InitText();
     InitCanvas();
-    cout << "MGSkyPosition: Initilizing done." << endl;
 }
 
@@ -278,11 +276,11 @@
     static int Y = ~0;
 
-    int xd = (int)floor(x);
-    int yd = (int)floor(y);
+    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.);
+    int fx = (int)/*floor*/(x*10.);
+    int fy = (int)/*floor*/(y*10.);
 
     if (X==fx && Y==fy)
@@ -296,6 +294,6 @@
 
     char txt[100];
-    sprintf(txt, "Zd=%d\xb0%02.1f'\nAz=%d\xb0%02.1f'",
-            xd, xm, yd, ym);
+    sprintf(txt, "Zd=%s%d\xb0%02.1f'\nAz=%s%d\xb0%02.1f'",
+            x<0?"-":"", abs(xd), xm, y<0?"-":"", abs(yd), ym);
 
     fText->SetText(fText->GetX(), fText->GetY(), txt);
@@ -305,11 +303,11 @@
 
 
-void MGSkyPosition::Update(ZdAz &pos)
+void MGSkyPosition::Update(ZdAz &pos, double mjd)
 {
     //
     // calculate actual time for planet positions
     //
-    fSlaPlanet->SetMjd2Now();
-    fSlaStar->SetMjd2Now();
+    fSlaPlanet->SetMjd(mjd);
+    fSlaStar->SetMjd(mjd);
 
     UpdatePlanet(kESun,     fSun);
Index: trunk/MagicSoft/Cosy/gui/MGSkyPosition.h
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGSkyPosition.h	(revision 1687)
+++ trunk/MagicSoft/Cosy/gui/MGSkyPosition.h	(revision 1690)
@@ -66,5 +66,5 @@
     ~MGSkyPosition();
 
-    void Update(ZdAz &pos);
+    void Update(ZdAz &pos, double mjd);
 
     ClassDef(MGSkyPosition, 0)
Index: trunk/MagicSoft/Cosy/gui/MGStarguider.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGStarguider.cc	(revision 1687)
+++ trunk/MagicSoft/Cosy/gui/MGStarguider.cc	(revision 1690)
@@ -3,5 +3,7 @@
 #include <fstream.h>    // ifstream
 #include <iostream.h>   // cout
-#
+
+#include <TTimer.h>
+
 #include <TGMenu.h>
 #include <TSystem.h>
@@ -61,4 +63,11 @@
 };
 
+Bool_t MGStarguider::HandleTimer(TTimer *t)
+{
+    fImage->DoRedraw();
+    fZoomImage->DoRedraw();
+    return kTRUE;
+}
+
 #define kZOOM 96
 
@@ -199,4 +208,9 @@
     // Create Image Display
     //
+    fZoomImage = new MGImage(this, kZOOM, kZOOM);
+    fZoomImage->Move(768-kZOOM-2, 700-kZOOM-2);
+    AddFrame(fZoomImage);
+    fList->Add(fZoomImage);
+
     fImage = new MGImage(this, 768, 576);
     fImage->Move(0, fMenu->GetDefaultHeight());
@@ -204,9 +218,4 @@
     fList->Add(fImage);
 
-    fZoomImage = new MGImage(this, kZOOM, kZOOM);
-    fZoomImage->Move(768-kZOOM-2, 700-kZOOM-2);
-    AddFrame(fZoomImage);
-    fList->Add(fZoomImage);
-
     //
     // Make everything visible
@@ -217,8 +226,14 @@
     MapSubwindows();
     MapWindow();
+
+    fTimer=new TTimer(this, 100); // 100ms
+    fTimer->TurnOn();
 }
 
 MGStarguider::~MGStarguider()
 {
+    fTimer->TurnOff();
+    delete fTimer;
+
     delete fSao;
     delete fRaDec;
Index: trunk/MagicSoft/Cosy/gui/MGStarguider.h
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGStarguider.h	(revision 1687)
+++ trunk/MagicSoft/Cosy/gui/MGStarguider.h	(revision 1690)
@@ -14,4 +14,6 @@
 class AltAz;
 class RaDec;
+
+class TTimer;
 
 class TGMenuBar;
@@ -52,4 +54,6 @@
     RaDec *fRaDec;
 
+    TTimer *fTimer;
+
     Int_t fDx;
     Int_t fDy;
@@ -62,4 +66,6 @@
     void GetCoordinates();
     void CalcTrackingError(MStarList &, MStarList &);
+
+    Bool_t HandleTimer(TTimer *t);
 
 public:
Index: trunk/MagicSoft/Cosy/gui/MGVelocity.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGVelocity.cc	(revision 1687)
+++ trunk/MagicSoft/Cosy/gui/MGVelocity.cc	(revision 1690)
@@ -279,6 +279,6 @@
     vy /= 60.;  //['/min]
 
-    int fx = (int)floor(vx*10.);
-    int fy = (int)floor(vy*10.);
+    int fx = (int)/*floor*/(vx*10.);
+    int fy = (int)/*floor*/(vy*10.);
 
     if (X==fx && Y==fy)
@@ -290,5 +290,5 @@
     char txt[100];
     sprintf(txt, "Zd=%.1f'\nAz=%.1f'",
-            vx, vy);
+            vy, vx);
 
     fTextVel->SetText(fTextVel->GetX(), fTextVel->GetY(), txt);
Index: trunk/MagicSoft/Cosy/macros/rootlogon.C
===================================================================
--- trunk/MagicSoft/Cosy/macros/rootlogon.C	(revision 1687)
+++ trunk/MagicSoft/Cosy/macros/rootlogon.C	(revision 1690)
@@ -40,4 +40,7 @@
     }
 
+    gInterpreter->AddIncludePath("base");
+    gInterpreter->AddIncludePath("main");
+
     cout << endl;
 
