00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "TArrowEditor.h"
00013 #include "TGComboBox.h"
00014 #include "TGLabel.h"
00015 #include "TGNumberEntry.h"
00016 #include "TArrow.h"
00017
00018 ClassImp(TArrowEditor)
00019
00020 enum EArrowWid {
00021 kARROW_ANG,
00022 kARROW_OPT,
00023 kARROW_SIZ
00024 };
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 TArrowEditor::TArrowEditor(const TGWindow *p, Int_t width,
00047 Int_t height, UInt_t options, Pixel_t back)
00048 : TGedFrame(p, width, height, options | kVerticalFrame, back)
00049 {
00050
00051
00052 fArrow = 0;
00053
00054 MakeTitle("Arrow");
00055
00056 TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
00057 AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
00058
00059 TGCompositeFrame *f2a = new TGCompositeFrame(f2, 80, 20);
00060 f2->AddFrame(f2a, new TGLayoutHints(kLHintsTop, 10, 0, 0, 0));
00061
00062 TGLabel *fShapeLabel = new TGLabel(f2a, "Shape:");
00063 f2a->AddFrame(fShapeLabel, new TGLayoutHints(kLHintsNormal, 0, 0, 1, 5));
00064
00065 TGLabel *fAngleLabel = new TGLabel(f2a, "Angle:");
00066 f2a->AddFrame(fAngleLabel, new TGLayoutHints(kLHintsNormal, 0, 0, 5, 5));
00067
00068 TGLabel *fSizeLabel = new TGLabel(f2a, "Size: ");
00069 f2a->AddFrame(fSizeLabel, new TGLayoutHints(kLHintsNormal, 0, 0, 5, 1));
00070
00071 TGCompositeFrame *f2b = new TGCompositeFrame(f2, 80, 20, kFixedWidth);
00072 f2->AddFrame(f2b, new TGLayoutHints(kLHintsTop, 10, 0, 0, 0));
00073
00074 fOptionCombo = BuildOptionComboBox(f2b, kARROW_OPT);
00075 fOptionCombo->Resize(80, 20);
00076 f2b->AddFrame(fOptionCombo, new TGLayoutHints(kLHintsExpandX, 1, 1, 1, 1));
00077 fOptionCombo->Associate(this);
00078
00079 fAngleEntry = new TGNumberEntry(f2b, 30, 8, kARROW_ANG,
00080 TGNumberFormat::kNESInteger,
00081 TGNumberFormat::kNEANonNegative,
00082 TGNumberFormat::kNELLimitMinMax,0, 180);
00083 fAngleEntry->GetNumberEntry()->SetToolTipText("Set the arrow opening angle in degrees.");
00084 f2b->AddFrame(fAngleEntry, new TGLayoutHints(kLHintsExpandX, 1, 1, 3, 1));
00085
00086 fSizeEntry = new TGNumberEntry(f2b, 0.03, 8, kARROW_SIZ,
00087 TGNumberFormat::kNESRealTwo,
00088 TGNumberFormat::kNEANonNegative,
00089 TGNumberFormat::kNELLimitMinMax, 0.01, 0.30);
00090 fSizeEntry->GetNumberEntry()->SetToolTipText("Set the size of arrow.");
00091 f2b->AddFrame(fSizeEntry, new TGLayoutHints(kLHintsExpandX, 1, 1, 3, 1));
00092
00093 }
00094
00095
00096 TArrowEditor::~TArrowEditor()
00097 {
00098
00099
00100 TGFrameElement *el;
00101 TIter next(GetList());
00102
00103 while ((el = (TGFrameElement *)next())) {
00104 if (!strcmp(el->fFrame->ClassName(), "TGCompositeFrame"))
00105 ((TGCompositeFrame *)el->fFrame)->Cleanup();
00106 }
00107 Cleanup();
00108 }
00109
00110
00111 void TArrowEditor::ConnectSignals2Slots()
00112 {
00113
00114
00115 fOptionCombo->Connect("Selected(Int_t)", "TArrowEditor", this, "DoOption(Int_t)");
00116 fAngleEntry->Connect("ValueSet(Long_t)", "TArrowEditor", this, "DoAngle()");
00117 (fAngleEntry->GetNumberEntry())->Connect("ReturnPressed()", "TArrowEditor", this, "DoAngle()");
00118 fSizeEntry->Connect("ValueSet(Long_t)", "TArrowEditor", this, "DoSize()");
00119 (fSizeEntry->GetNumberEntry())->Connect("ReturnPressed()", "TArrowEditor", this, "DoSize()");
00120
00121 fInit = kFALSE;
00122 }
00123
00124
00125 void TArrowEditor::SetModel(TObject* obj)
00126 {
00127
00128
00129 fArrow = (TArrow *)obj;
00130 fAvoidSignal = kTRUE;
00131
00132 Int_t id = GetShapeEntry(fArrow->GetDrawOption());
00133 if (id != fOptionCombo->GetSelected())
00134 fOptionCombo->Select(id);
00135
00136 Float_t sz = fArrow->GetArrowSize();
00137 fSizeEntry->SetNumber(sz);
00138
00139 Int_t deg = (Int_t)fArrow->GetAngle();
00140 fAngleEntry->SetNumber(deg);
00141
00142 if (fInit) ConnectSignals2Slots();
00143 fAvoidSignal = kFALSE;
00144 }
00145
00146
00147 void TArrowEditor::DoAngle()
00148 {
00149
00150
00151 if (fAvoidSignal) return;
00152 fArrow->SetAngle((Float_t)fAngleEntry->GetNumber());
00153 fArrow->Paint(fArrow->GetDrawOption());
00154 Update();
00155 }
00156
00157
00158 void TArrowEditor::DoOption(Int_t id)
00159 {
00160
00161
00162 if (fAvoidSignal) return;
00163 const char* opt=0;
00164 switch (id) {
00165 case 1:
00166 opt = "|>";
00167 break;
00168 case 2:
00169 opt = "<|";
00170 break;
00171 case 3:
00172 opt = ">";
00173 break;
00174 case 4:
00175 opt = "<";
00176 break;
00177 case 5:
00178 opt = "->-";
00179 break;
00180 case 6:
00181 opt = "-<-";
00182 break;
00183 case 7:
00184 opt = "-|>-";
00185 break;
00186 case 8:
00187 opt = "-<|-";
00188 break;
00189 case 9:
00190 opt = "<>";
00191 break;
00192 case 10:
00193 opt = "<|>";
00194 break;
00195 }
00196 fArrow->SetDrawOption(opt);
00197 fArrow->Paint(fArrow->GetDrawOption());
00198 Update();
00199 }
00200
00201
00202
00203 void TArrowEditor::DoSize()
00204 {
00205
00206
00207 if (fAvoidSignal) return;
00208 fArrow->SetArrowSize(fSizeEntry->GetNumber());
00209 fArrow->Paint(fArrow->GetDrawOption());
00210 Update();
00211 }
00212
00213
00214 TGComboBox* TArrowEditor::BuildOptionComboBox(TGFrame* parent, Int_t id)
00215 {
00216
00217
00218 TGComboBox *cb = new TGComboBox(parent, id);
00219
00220 cb->AddEntry(" -------|>",1);
00221 cb->AddEntry(" <|-------",2);
00222 cb->AddEntry(" -------->",3);
00223 cb->AddEntry(" <--------",4);
00224 cb->AddEntry(" ---->----",5);
00225 cb->AddEntry(" ----<----",6);
00226 cb->AddEntry(" ----|>---",7);
00227 cb->AddEntry(" ---<|----",8);
00228 cb->AddEntry(" <------>", 9);
00229 cb->AddEntry(" <|-----|>",10);
00230 (cb->GetListBox())->Resize((cb->GetListBox())->GetWidth(), 136);
00231 cb->Select(1);
00232 return cb;
00233 }
00234
00235
00236 Int_t TArrowEditor::GetShapeEntry(Option_t *option)
00237 {
00238
00239
00240 TString opt = option;
00241 opt.ToLower();
00242 Int_t id = 0;
00243
00244 if (opt == "|>") id = 1;
00245 if (opt == "<|") id = 2;
00246 if (opt == ">") id = 3;
00247 if (opt == "<") id = 4;
00248 if (opt == "->-") id = 5;
00249 if (opt == "-<-") id = 6;
00250 if (opt == "-|>-") id = 7;
00251 if (opt == "-<|-") id = 8;
00252 if (opt == "<>") id = 9;
00253 if (opt == "<|>") id = 10;
00254 return id;
00255 }