// @(#)root/ged:$Id$
// Author: Ilka  Antcheva 24/04/06

/*************************************************************************
 * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
//  TLineEditor                                                        //
//                                                                      //
//  Implements GUI for editing line attributes: shape, size, angle.    //                                             //
//                                                                      //
//////////////////////////////////////////////////////////////////////////
//Begin_Html
/*
<img src="gif/TLineEditor.gif">
*/
//End_Html


#include "TLineEditor.h"
#include "TGLabel.h"
#include "TGNumberEntry.h"
#include "TLine.h"
#include "TVirtualPad.h"

ClassImp(TLineEditor)

enum ELineWid {
   kLine_STAX,
   kLine_STAY,
   kLine_ENDX,
   kLine_ENDY,
   kLine_VERTICAL,
   kLine_HORIZONTAL
};


//______________________________________________________________________________
TLineEditor::TLineEditor(const TGWindow *p, Int_t width,
                           Int_t height, UInt_t options, Pixel_t back)
   : TGedFrame(p, width, height, options | kVerticalFrame, back)
{
   // Constructor of line GUI.

   fLine = 0;

   MakeTitle("Points");

   TGCompositeFrame *f3 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
   AddFrame(f3, new TGLayoutHints(kLHintsTop, 1, 1, 3, 0));

   TGCompositeFrame *f3a = new TGCompositeFrame(f3, 80, 20);
   f3->AddFrame(f3a, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));

   TGLabel *fStartPointXLabel = new TGLabel(f3a, "Start X:");
   f3a->AddFrame(fStartPointXLabel, new TGLayoutHints(kLHintsNormal, 8, 0, 5, 5));

   TGLabel *fStartPointYLabel = new TGLabel(f3a, "Y:");
   f3a->AddFrame(fStartPointYLabel, new TGLayoutHints(kLHintsNormal, 37, 0, 5, 5));

   TGLabel *fEndPointXLabel = new TGLabel(f3a, "End X:");
   f3a->AddFrame(fEndPointXLabel, new TGLayoutHints(kLHintsNormal, 10, 0, 5, 5));

   TGLabel *fEndPointYLabel = new TGLabel(f3a, "Y:");
   f3a->AddFrame(fEndPointYLabel, new TGLayoutHints(kLHintsNormal, 37, 0, 5, 5));

   TGCompositeFrame *f3b = new TGCompositeFrame(f3, 80, 20, kFixedWidth);
   f3->AddFrame(f3b, new TGLayoutHints(kLHintsNormal, 8, 0, 0, 0));

   fStartPointX = new TGNumberEntry(f3b, 0.0, 8, kLine_STAX,
                                      TGNumberFormat::kNESRealThree,
                                      TGNumberFormat::kNEAAnyNumber,
                                      TGNumberFormat::kNELNoLimits);
   fStartPointX->GetNumberEntry()->SetToolTipText("Set start point X coordinate of Line.");
   f3b->AddFrame(fStartPointX, new TGLayoutHints(kLHintsExpandX, 1, 1, 1, 1));

   fStartPointY = new TGNumberEntry(f3b, 0.0, 8, kLine_STAY,
                                      TGNumberFormat::kNESRealThree,
                                      TGNumberFormat::kNEAAnyNumber,
                                      TGNumberFormat::kNELNoLimits);
   fStartPointY->GetNumberEntry()->SetToolTipText("Set start point Y coordinate of Line.");
   f3b->AddFrame(fStartPointY, new TGLayoutHints(kLHintsExpandX, 1, 1, 3, 1));

   fEndPointX = new TGNumberEntry(f3b, 0.0, 8, kLine_ENDX,
                                    TGNumberFormat::kNESRealThree,
                                    TGNumberFormat::kNEAAnyNumber,
                                    TGNumberFormat::kNELNoLimits);
   fEndPointX->GetNumberEntry()->SetToolTipText("Set end point X xoordinate of Line.");
   f3b->AddFrame(fEndPointX, new TGLayoutHints(kLHintsExpandX, 1, 1, 3, 1));

   fEndPointY = new TGNumberEntry(f3b, 0.0, 8, kLine_ENDY,
                                    TGNumberFormat::kNESRealThree,
                                    TGNumberFormat::kNEAAnyNumber,
                                    TGNumberFormat::kNELNoLimits);
   fEndPointY->GetNumberEntry()->SetToolTipText("Set end point Y coordinate of Line.");
   f3b->AddFrame(fEndPointY, new TGLayoutHints(kLHintsExpandX, 1, 1, 3, 1));

   fVertical = new TGCheckButton(this,"Vertical",kLine_VERTICAL);
   fVertical->SetToolTipText("Set vertical");
   AddFrame(fVertical, new TGLayoutHints(kLHintsTop, 8, 1, 5, 0));

   fHorizontal = new TGCheckButton(this,"Horizontal",kLine_HORIZONTAL);
   fHorizontal->SetToolTipText("Set horizontal");
   AddFrame(fHorizontal, new TGLayoutHints(kLHintsTop, 8, 1, 3, 0));
}

//______________________________________________________________________________
TLineEditor::~TLineEditor()
{
   // Destructor of line editor.
}

//______________________________________________________________________________
void TLineEditor::ConnectSignals2Slots()
{
   // Connect signals to slots.

   fStartPointX->Connect("ValueSet(Long_t)", "TLineEditor", this, "DoStartPoint()");
   (fStartPointX->GetNumberEntry())->Connect("ReturnPressed()", "TLineEditor", this, "DoStartPoint()");
   fStartPointY->Connect("ValueSet(Long_t)", "TLineEditor", this, "DoStartPoint()");
   (fStartPointY->GetNumberEntry())->Connect("ReturnPressed()", "TLineEditor", this, "DoStartPoint()");
   fEndPointX->Connect("ValueSet(Long_t)", "TLineEditor", this, "DoEndPoint()");
   (fEndPointX->GetNumberEntry())->Connect("ReturnPressed()", "TLineEditor", this, "DoEndPoint()");
   fEndPointY->Connect("ValueSet(Long_t)", "TLineEditor", this, "DoEndPoint()");
   (fEndPointY->GetNumberEntry())->Connect("ReturnPressed()", "TLineEditor", this, "DoEndPoint()");
   fVertical->Connect("Clicked()","TLineEditor",this,"DoLineVertical()");
   fHorizontal->Connect("Clicked()","TLineEditor",this,"DoLineHorizontal()");

   fInit = kFALSE;
}

//______________________________________________________________________________
void TLineEditor::SetModel(TObject* obj)
{
   // Pick up the used line attributes.

   fLine = (TLine *)obj;
   fAvoidSignal = kTRUE;

   Float_t val = fLine->GetX1();
   fStartPointX->SetNumber(val);

   val = fLine->GetX2();
   fEndPointX->SetNumber(val);

   val = fLine->GetY1();
   fStartPointY->SetNumber(val);

   val = fLine->GetY2();
   fEndPointY->SetNumber(val);

   if (fLine->IsHorizontal()) fHorizontal->SetState(kButtonDown, kFALSE);
   else fHorizontal->SetState(kButtonUp, kFALSE);

   if (fLine->IsVertical()) fVertical->SetState(kButtonDown, kFALSE);
   else fVertical->SetState(kButtonUp, kFALSE);

   if (fInit) ConnectSignals2Slots();

   fAvoidSignal = kFALSE;
}

//______________________________________________________________________________
void TLineEditor::DoStartPoint()
{
   // Slot connected to the line start point.

   if (fAvoidSignal) return;
   fLine->SetX1((Double_t)fStartPointX->GetNumber());
   fLine->SetY1((Double_t)fStartPointY->GetNumber());
   fLine->Paint(fLine->GetDrawOption());
   Update();
}
//______________________________________________________________________________
void TLineEditor::DoEndPoint()
{
   // Slot connected to the line EndPoint.

   if (fAvoidSignal) return;
   fLine->SetX2((Double_t)fEndPointX->GetNumber());
   fLine->SetY2((Double_t)fEndPointY->GetNumber());
   fLine->Paint(fLine->GetDrawOption());
   Update();
}

//______________________________________________________________________________
void TLineEditor::DoLineVertical()
{
   // Slot so set the line vertical

   if (fAvoidSignal) return;
   if (fVertical->GetState() == kButtonDown) {
      fLine->SetVertical();
      fHorizontal->SetState(kButtonUp, kFALSE);
   } else {
      fLine->SetVertical(kFALSE);
   }
   Update();
}

//______________________________________________________________________________
void TLineEditor::DoLineHorizontal()
{
   // Slot so set the line horizontal

   if (fAvoidSignal) return;
   if (fHorizontal->GetState() == kButtonDown) {
      fLine->SetHorizontal();
      fVertical->SetState(kButtonUp, kFALSE);
   } else {
      fLine->SetHorizontal(kFALSE);
   }
   Update();
}
 TLineEditor.cxx:1
 TLineEditor.cxx:2
 TLineEditor.cxx:3
 TLineEditor.cxx:4
 TLineEditor.cxx:5
 TLineEditor.cxx:6
 TLineEditor.cxx:7
 TLineEditor.cxx:8
 TLineEditor.cxx:9
 TLineEditor.cxx:10
 TLineEditor.cxx:11
 TLineEditor.cxx:12
 TLineEditor.cxx:13
 TLineEditor.cxx:14
 TLineEditor.cxx:15
 TLineEditor.cxx:16
 TLineEditor.cxx:17
 TLineEditor.cxx:18
 TLineEditor.cxx:19
 TLineEditor.cxx:20
 TLineEditor.cxx:21
 TLineEditor.cxx:22
 TLineEditor.cxx:23
 TLineEditor.cxx:24
 TLineEditor.cxx:25
 TLineEditor.cxx:26
 TLineEditor.cxx:27
 TLineEditor.cxx:28
 TLineEditor.cxx:29
 TLineEditor.cxx:30
 TLineEditor.cxx:31
 TLineEditor.cxx:32
 TLineEditor.cxx:33
 TLineEditor.cxx:34
 TLineEditor.cxx:35
 TLineEditor.cxx:36
 TLineEditor.cxx:37
 TLineEditor.cxx:38
 TLineEditor.cxx:39
 TLineEditor.cxx:40
 TLineEditor.cxx:41
 TLineEditor.cxx:42
 TLineEditor.cxx:43
 TLineEditor.cxx:44
 TLineEditor.cxx:45
 TLineEditor.cxx:46
 TLineEditor.cxx:47
 TLineEditor.cxx:48
 TLineEditor.cxx:49
 TLineEditor.cxx:50
 TLineEditor.cxx:51
 TLineEditor.cxx:52
 TLineEditor.cxx:53
 TLineEditor.cxx:54
 TLineEditor.cxx:55
 TLineEditor.cxx:56
 TLineEditor.cxx:57
 TLineEditor.cxx:58
 TLineEditor.cxx:59
 TLineEditor.cxx:60
 TLineEditor.cxx:61
 TLineEditor.cxx:62
 TLineEditor.cxx:63
 TLineEditor.cxx:64
 TLineEditor.cxx:65
 TLineEditor.cxx:66
 TLineEditor.cxx:67
 TLineEditor.cxx:68
 TLineEditor.cxx:69
 TLineEditor.cxx:70
 TLineEditor.cxx:71
 TLineEditor.cxx:72
 TLineEditor.cxx:73
 TLineEditor.cxx:74
 TLineEditor.cxx:75
 TLineEditor.cxx:76
 TLineEditor.cxx:77
 TLineEditor.cxx:78
 TLineEditor.cxx:79
 TLineEditor.cxx:80
 TLineEditor.cxx:81
 TLineEditor.cxx:82
 TLineEditor.cxx:83
 TLineEditor.cxx:84
 TLineEditor.cxx:85
 TLineEditor.cxx:86
 TLineEditor.cxx:87
 TLineEditor.cxx:88
 TLineEditor.cxx:89
 TLineEditor.cxx:90
 TLineEditor.cxx:91
 TLineEditor.cxx:92
 TLineEditor.cxx:93
 TLineEditor.cxx:94
 TLineEditor.cxx:95
 TLineEditor.cxx:96
 TLineEditor.cxx:97
 TLineEditor.cxx:98
 TLineEditor.cxx:99
 TLineEditor.cxx:100
 TLineEditor.cxx:101
 TLineEditor.cxx:102
 TLineEditor.cxx:103
 TLineEditor.cxx:104
 TLineEditor.cxx:105
 TLineEditor.cxx:106
 TLineEditor.cxx:107
 TLineEditor.cxx:108
 TLineEditor.cxx:109
 TLineEditor.cxx:110
 TLineEditor.cxx:111
 TLineEditor.cxx:112
 TLineEditor.cxx:113
 TLineEditor.cxx:114
 TLineEditor.cxx:115
 TLineEditor.cxx:116
 TLineEditor.cxx:117
 TLineEditor.cxx:118
 TLineEditor.cxx:119
 TLineEditor.cxx:120
 TLineEditor.cxx:121
 TLineEditor.cxx:122
 TLineEditor.cxx:123
 TLineEditor.cxx:124
 TLineEditor.cxx:125
 TLineEditor.cxx:126
 TLineEditor.cxx:127
 TLineEditor.cxx:128
 TLineEditor.cxx:129
 TLineEditor.cxx:130
 TLineEditor.cxx:131
 TLineEditor.cxx:132
 TLineEditor.cxx:133
 TLineEditor.cxx:134
 TLineEditor.cxx:135
 TLineEditor.cxx:136
 TLineEditor.cxx:137
 TLineEditor.cxx:138
 TLineEditor.cxx:139
 TLineEditor.cxx:140
 TLineEditor.cxx:141
 TLineEditor.cxx:142
 TLineEditor.cxx:143
 TLineEditor.cxx:144
 TLineEditor.cxx:145
 TLineEditor.cxx:146
 TLineEditor.cxx:147
 TLineEditor.cxx:148
 TLineEditor.cxx:149
 TLineEditor.cxx:150
 TLineEditor.cxx:151
 TLineEditor.cxx:152
 TLineEditor.cxx:153
 TLineEditor.cxx:154
 TLineEditor.cxx:155
 TLineEditor.cxx:156
 TLineEditor.cxx:157
 TLineEditor.cxx:158
 TLineEditor.cxx:159
 TLineEditor.cxx:160
 TLineEditor.cxx:161
 TLineEditor.cxx:162
 TLineEditor.cxx:163
 TLineEditor.cxx:164
 TLineEditor.cxx:165
 TLineEditor.cxx:166
 TLineEditor.cxx:167
 TLineEditor.cxx:168
 TLineEditor.cxx:169
 TLineEditor.cxx:170
 TLineEditor.cxx:171
 TLineEditor.cxx:172
 TLineEditor.cxx:173
 TLineEditor.cxx:174
 TLineEditor.cxx:175
 TLineEditor.cxx:176
 TLineEditor.cxx:177
 TLineEditor.cxx:178
 TLineEditor.cxx:179
 TLineEditor.cxx:180
 TLineEditor.cxx:181
 TLineEditor.cxx:182
 TLineEditor.cxx:183
 TLineEditor.cxx:184
 TLineEditor.cxx:185
 TLineEditor.cxx:186
 TLineEditor.cxx:187
 TLineEditor.cxx:188
 TLineEditor.cxx:189
 TLineEditor.cxx:190
 TLineEditor.cxx:191
 TLineEditor.cxx:192
 TLineEditor.cxx:193
 TLineEditor.cxx:194
 TLineEditor.cxx:195
 TLineEditor.cxx:196
 TLineEditor.cxx:197
 TLineEditor.cxx:198
 TLineEditor.cxx:199
 TLineEditor.cxx:200
 TLineEditor.cxx:201
 TLineEditor.cxx:202
 TLineEditor.cxx:203
 TLineEditor.cxx:204
 TLineEditor.cxx:205
 TLineEditor.cxx:206
 TLineEditor.cxx:207
 TLineEditor.cxx:208
 TLineEditor.cxx:209
 TLineEditor.cxx:210
 TLineEditor.cxx:211
 TLineEditor.cxx:212
 TLineEditor.cxx:213
 TLineEditor.cxx:214
 TLineEditor.cxx:215
 TLineEditor.cxx:216
 TLineEditor.cxx:217
 TLineEditor.cxx:218
 TLineEditor.cxx:219
 TLineEditor.cxx:220