00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "TLineEditor.h"
00027 #include "TGLabel.h"
00028 #include "TGNumberEntry.h"
00029 #include "TLine.h"
00030 #include "TVirtualPad.h"
00031
00032 ClassImp(TLineEditor)
00033
00034 enum ELineWid {
00035 kLine_STAX,
00036 kLine_STAY,
00037 kLine_ENDX,
00038 kLine_ENDY,
00039 kLine_VERTICAL,
00040 kLine_HORIZONTAL
00041 };
00042
00043
00044
00045 TLineEditor::TLineEditor(const TGWindow *p, Int_t width,
00046 Int_t height, UInt_t options, Pixel_t back)
00047 : TGedFrame(p, width, height, options | kVerticalFrame, back)
00048 {
00049
00050
00051 fLine = 0;
00052
00053 MakeTitle("Points");
00054
00055 TGCompositeFrame *f3 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
00056 AddFrame(f3, new TGLayoutHints(kLHintsTop, 1, 1, 3, 0));
00057
00058 TGCompositeFrame *f3a = new TGCompositeFrame(f3, 80, 20);
00059 f3->AddFrame(f3a, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
00060
00061 TGLabel *fStartPointXLabel = new TGLabel(f3a, "Start X:");
00062 f3a->AddFrame(fStartPointXLabel, new TGLayoutHints(kLHintsNormal, 8, 0, 5, 5));
00063
00064 TGLabel *fStartPointYLabel = new TGLabel(f3a, "Y:");
00065 f3a->AddFrame(fStartPointYLabel, new TGLayoutHints(kLHintsNormal, 37, 0, 5, 5));
00066
00067 TGLabel *fEndPointXLabel = new TGLabel(f3a, "End X:");
00068 f3a->AddFrame(fEndPointXLabel, new TGLayoutHints(kLHintsNormal, 10, 0, 5, 5));
00069
00070 TGLabel *fEndPointYLabel = new TGLabel(f3a, "Y:");
00071 f3a->AddFrame(fEndPointYLabel, new TGLayoutHints(kLHintsNormal, 37, 0, 5, 5));
00072
00073 TGCompositeFrame *f3b = new TGCompositeFrame(f3, 80, 20, kFixedWidth);
00074 f3->AddFrame(f3b, new TGLayoutHints(kLHintsNormal, 8, 0, 0, 0));
00075
00076 fStartPointX = new TGNumberEntry(f3b, 0.0, 8, kLine_STAX,
00077 TGNumberFormat::kNESRealThree,
00078 TGNumberFormat::kNEAAnyNumber,
00079 TGNumberFormat::kNELNoLimits);
00080 fStartPointX->GetNumberEntry()->SetToolTipText("Set start point X coordinate of Line.");
00081 f3b->AddFrame(fStartPointX, new TGLayoutHints(kLHintsExpandX, 1, 1, 1, 1));
00082
00083 fStartPointY = new TGNumberEntry(f3b, 0.0, 8, kLine_STAY,
00084 TGNumberFormat::kNESRealThree,
00085 TGNumberFormat::kNEAAnyNumber,
00086 TGNumberFormat::kNELNoLimits);
00087 fStartPointY->GetNumberEntry()->SetToolTipText("Set start point Y coordinate of Line.");
00088 f3b->AddFrame(fStartPointY, new TGLayoutHints(kLHintsExpandX, 1, 1, 3, 1));
00089
00090 fEndPointX = new TGNumberEntry(f3b, 0.0, 8, kLine_ENDX,
00091 TGNumberFormat::kNESRealThree,
00092 TGNumberFormat::kNEAAnyNumber,
00093 TGNumberFormat::kNELNoLimits);
00094 fEndPointX->GetNumberEntry()->SetToolTipText("Set end point X xoordinate of Line.");
00095 f3b->AddFrame(fEndPointX, new TGLayoutHints(kLHintsExpandX, 1, 1, 3, 1));
00096
00097 fEndPointY = new TGNumberEntry(f3b, 0.0, 8, kLine_ENDY,
00098 TGNumberFormat::kNESRealThree,
00099 TGNumberFormat::kNEAAnyNumber,
00100 TGNumberFormat::kNELNoLimits);
00101 fEndPointY->GetNumberEntry()->SetToolTipText("Set end point Y coordinate of Line.");
00102 f3b->AddFrame(fEndPointY, new TGLayoutHints(kLHintsExpandX, 1, 1, 3, 1));
00103
00104 fVertical = new TGCheckButton(this,"Vertical",kLine_VERTICAL);
00105 fVertical->SetToolTipText("Set vertical");
00106 AddFrame(fVertical, new TGLayoutHints(kLHintsTop, 8, 1, 5, 0));
00107
00108 fHorizontal = new TGCheckButton(this,"Horizontal",kLine_HORIZONTAL);
00109 fHorizontal->SetToolTipText("Set horizontal");
00110 AddFrame(fHorizontal, new TGLayoutHints(kLHintsTop, 8, 1, 3, 0));
00111 }
00112
00113
00114 TLineEditor::~TLineEditor()
00115 {
00116
00117 }
00118
00119
00120 void TLineEditor::ConnectSignals2Slots()
00121 {
00122
00123
00124 fStartPointX->Connect("ValueSet(Long_t)", "TLineEditor", this, "DoStartPoint()");
00125 (fStartPointX->GetNumberEntry())->Connect("ReturnPressed()", "TLineEditor", this, "DoStartPoint()");
00126 fStartPointY->Connect("ValueSet(Long_t)", "TLineEditor", this, "DoStartPoint()");
00127 (fStartPointY->GetNumberEntry())->Connect("ReturnPressed()", "TLineEditor", this, "DoStartPoint()");
00128 fEndPointX->Connect("ValueSet(Long_t)", "TLineEditor", this, "DoEndPoint()");
00129 (fEndPointX->GetNumberEntry())->Connect("ReturnPressed()", "TLineEditor", this, "DoEndPoint()");
00130 fEndPointY->Connect("ValueSet(Long_t)", "TLineEditor", this, "DoEndPoint()");
00131 (fEndPointY->GetNumberEntry())->Connect("ReturnPressed()", "TLineEditor", this, "DoEndPoint()");
00132 fVertical->Connect("Clicked()","TLineEditor",this,"DoLineVertical()");
00133 fHorizontal->Connect("Clicked()","TLineEditor",this,"DoLineHorizontal()");
00134
00135 fInit = kFALSE;
00136 }
00137
00138
00139 void TLineEditor::SetModel(TObject* obj)
00140 {
00141
00142
00143 fLine = (TLine *)obj;
00144 fAvoidSignal = kTRUE;
00145
00146 Float_t val = fLine->GetX1();
00147 fStartPointX->SetNumber(val);
00148
00149 val = fLine->GetX2();
00150 fEndPointX->SetNumber(val);
00151
00152 val = fLine->GetY1();
00153 fStartPointY->SetNumber(val);
00154
00155 val = fLine->GetY2();
00156 fEndPointY->SetNumber(val);
00157
00158 if (fLine->IsHorizontal()) fHorizontal->SetState(kButtonDown, kFALSE);
00159 else fHorizontal->SetState(kButtonUp, kFALSE);
00160
00161 if (fLine->IsVertical()) fVertical->SetState(kButtonDown, kFALSE);
00162 else fVertical->SetState(kButtonUp, kFALSE);
00163
00164 if (fInit) ConnectSignals2Slots();
00165
00166 fAvoidSignal = kFALSE;
00167 }
00168
00169
00170 void TLineEditor::DoStartPoint()
00171 {
00172
00173
00174 if (fAvoidSignal) return;
00175 fLine->SetX1((Double_t)fStartPointX->GetNumber());
00176 fLine->SetY1((Double_t)fStartPointY->GetNumber());
00177 fLine->Paint(fLine->GetDrawOption());
00178 Update();
00179 }
00180
00181 void TLineEditor::DoEndPoint()
00182 {
00183
00184
00185 if (fAvoidSignal) return;
00186 fLine->SetX2((Double_t)fEndPointX->GetNumber());
00187 fLine->SetY2((Double_t)fEndPointY->GetNumber());
00188 fLine->Paint(fLine->GetDrawOption());
00189 Update();
00190 }
00191
00192
00193 void TLineEditor::DoLineVertical()
00194 {
00195
00196
00197 if (fAvoidSignal) return;
00198 if (fVertical->GetState() == kButtonDown) {
00199 fLine->SetVertical();
00200 fHorizontal->SetState(kButtonUp, kFALSE);
00201 } else {
00202 fLine->SetVertical(kFALSE);
00203 }
00204 Update();
00205 }
00206
00207
00208 void TLineEditor::DoLineHorizontal()
00209 {
00210
00211
00212 if (fAvoidSignal) return;
00213 if (fHorizontal->GetState() == kButtonDown) {
00214 fLine->SetHorizontal();
00215 fVertical->SetState(kButtonUp, kFALSE);
00216 } else {
00217 fLine->SetHorizontal(kFALSE);
00218 }
00219 Update();
00220 }