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
00027
00028 #include "TGeoPgonEditor.h"
00029 #include "TGeoTabManager.h"
00030 #include "TGeoPgon.h"
00031 #include "TGeoManager.h"
00032 #include "TVirtualGeoPainter.h"
00033 #include "TPad.h"
00034 #include "TView.h"
00035 #include "TGTab.h"
00036 #include "TGComboBox.h"
00037 #include "TGButton.h"
00038 #include "TGTextEntry.h"
00039 #include "TGNumberEntry.h"
00040 #include "TGLabel.h"
00041
00042 ClassImp(TGeoPgonEditor)
00043
00044 enum ETGeoPgonWid {
00045 kPGON_NEDGES
00046 };
00047
00048
00049 TGeoPgonEditor::TGeoPgonEditor(const TGWindow *p, Int_t width,
00050 Int_t height, UInt_t options, Pixel_t back)
00051 : TGeoPconEditor(p, width, height, options | kVerticalFrame, back)
00052 {
00053
00054 fNedgesi = 0;
00055 CreateEdges();
00056 TGeoTabManager::MoveFrame(fDFrame, this);
00057 TGeoTabManager::MoveFrame(fBFrame, this);
00058 fENedges->Connect("ValueSet(Long_t)", "TGeoPgonEditor", this, "DoNedges()");
00059 fENedges->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoPgonEditor", this, "DoModified()");
00060 }
00061
00062
00063 TGeoPgonEditor::~TGeoPgonEditor()
00064 {
00065
00066 TGFrameElement *el;
00067 TIter next(GetList());
00068 while ((el = (TGFrameElement *)next())) {
00069 if (el->fFrame->IsComposite())
00070 TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
00071 }
00072 Cleanup();
00073 }
00074
00075
00076 void TGeoPgonEditor::SetModel(TObject* obj)
00077 {
00078
00079 if (obj == 0 || (obj->IsA()!=TGeoPgon::Class())) {
00080 SetActive(kFALSE);
00081 return;
00082 }
00083 fShape = (TGeoPcon*)obj;
00084 const char *sname = fShape->GetName();
00085 if (!strcmp(sname, fShape->ClassName())) fShapeName->SetText("-no_name");
00086 else fShapeName->SetText(sname);
00087
00088 Int_t nsections = fShape->GetNz();
00089 fNsecti = nsections;
00090 fNedgesi = ((TGeoPgon*)fShape)->GetNedges();
00091 fENz->SetNumber(nsections);
00092 fENedges->SetNumber(fNedgesi);
00093 fEPhi1->SetNumber(fShape->GetPhi1());
00094 fPhi1i = fShape->GetPhi1();
00095 fEDPhi->SetNumber(fShape->GetDphi());
00096 fDPhii = fShape->GetDphi();
00097 CreateSections(nsections);
00098 UpdateSections();
00099
00100 fApply->SetEnabled(kFALSE);
00101 fUndo->SetEnabled(kFALSE);
00102
00103 if (fInit) ConnectSignals2Slots();
00104 SetActive();
00105 }
00106
00107
00108 void TGeoPgonEditor::DoApply()
00109 {
00110
00111 TGeoPgon *shape = (TGeoPgon*)fShape;
00112 const char *name = fShapeName->GetText();
00113 if (strcmp(name,fShape->GetName())) fShape->SetName(name);
00114 fApply->SetEnabled(kFALSE);
00115 fUndo->SetEnabled();
00116 if (!CheckSections()) return;
00117
00118 Bool_t recreate = kFALSE;
00119 Int_t nz = fENz->GetIntNumber();
00120 Int_t nedges = fENedges->GetIntNumber();
00121 Double_t phi1 = fEPhi1->GetNumber();
00122 Double_t dphi = fEDPhi->GetNumber();
00123 if (nz != fShape->GetNz()) recreate = kTRUE;
00124 TGeoPconSection *sect;
00125 Int_t isect;
00126 if (recreate) {
00127 Double_t *array = new Double_t[3*(nz+1)+1];
00128 array[0] = phi1;
00129 array[1] = dphi;
00130 array[2] = nedges;
00131 array[3] = nz;
00132 for (isect=0; isect<nz; isect++) {
00133 sect = (TGeoPconSection*)fSections->At(isect);
00134 array[4+3*isect] = sect->GetZ();
00135 array[5+3*isect] = sect->GetRmin();
00136 array[6+3*isect] = sect->GetRmax();
00137 }
00138 shape->SetDimensions(array);
00139 delete [] array;
00140 if (fPad) {
00141 if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
00142 TView *view = fPad->GetView();
00143 if (!view) {
00144 fShape->Draw();
00145 fPad->GetView()->ShowAxis();
00146 } else {
00147 const Double_t *orig = fShape->GetOrigin();
00148 view->SetRange(orig[0]-fShape->GetDX(), orig[1]-fShape->GetDY(), orig[2]-fShape->GetDZ(),
00149 orig[0]+fShape->GetDX(), orig[1]+fShape->GetDY(), orig[2]+fShape->GetDZ());
00150 Update();
00151 }
00152 } else Update();
00153 }
00154 return;
00155 }
00156
00157 if (TMath::Abs(phi1-fShape->GetPhi1())>1.e-6) fShape->Phi1() = phi1;
00158 if (TMath::Abs(dphi-fShape->GetDphi())>1.e-6) fShape->Dphi() = dphi;
00159 if (nedges != shape->GetNedges()) shape->SetNedges(nedges);
00160 for (isect=0; isect<fNsections; isect++) {
00161 sect = (TGeoPconSection*)fSections->At(isect);
00162 fShape->Z(isect) = sect->GetZ();
00163 fShape->Rmin(isect) = sect->GetRmin();
00164 fShape->Rmax(isect) = sect->GetRmax();
00165 }
00166 shape->ComputeBBox();
00167 if (fPad) {
00168 if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
00169 TView *view = fPad->GetView();
00170 if (!view) {
00171 shape->Draw();
00172 fPad->GetView()->ShowAxis();
00173 } else {
00174 const Double_t *orig = fShape->GetOrigin();
00175 view->SetRange(orig[0]-fShape->GetDX(), orig[1]-fShape->GetDY(), orig[2]-fShape->GetDZ(),
00176 orig[0]+fShape->GetDX(), orig[1]+fShape->GetDY(), orig[2]+fShape->GetDZ());
00177 Update();
00178 }
00179 } else Update();
00180 }
00181 }
00182
00183
00184 void TGeoPgonEditor::DoUndo()
00185 {
00186
00187 fENedges->SetNumber(fNedgesi);
00188 TGeoPconEditor::DoUndo();
00189 }
00190
00191
00192 void TGeoPgonEditor::CreateEdges()
00193 {
00194
00195 TGTextEntry *nef;
00196 TGCompositeFrame *f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00197 f1->AddFrame(new TGLabel(f1, "Nedges"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00198 fENedges = new TGNumberEntry(f1, 0., 5, kPGON_NEDGES);
00199 fENedges->SetNumAttr(TGNumberFormat::kNEAPositive);
00200 fENedges->SetNumStyle(TGNumberFormat::kNESInteger);
00201 fENedges->Resize(100,fENedges->GetDefaultHeight());
00202 nef = (TGTextEntry*)fENedges->GetNumberEntry();
00203 nef->SetToolTipText("Enter the number of edges of the polygon");
00204 fENedges->Associate(this);
00205 f1->AddFrame(fENedges, new TGLayoutHints(kLHintsRight, 2, 2, 2, 2));
00206 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00207 }
00208
00209
00210 void TGeoPgonEditor::DoNedges()
00211 {
00212
00213 Int_t nedges = fENedges->GetIntNumber();
00214 if (nedges < 3) {
00215 nedges = 3;
00216 fENedges->SetNumber(nedges);
00217 }
00218 DoModified();
00219 if (!IsDelayed()) DoApply();
00220 }
00221