Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGeoPgonEditor.cxx
Go to the documentation of this file.
1 // @(#):$Id$
2 // Author: M.Gheata
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2002, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /** \class TGeoPgonEditor
13 \ingroup Geometry_builder
14 
15 Editor for a TGeoPgon.
16 
17 \image html geom_pgon_pic.png
18 
19 \image html geom_pgon_ed.png
20 
21 */
22 
23 #include "TGeoPgonEditor.h"
24 #include "TGeoTabManager.h"
25 #include "TGeoPgon.h"
26 #include "TGeoManager.h"
27 #include "TVirtualGeoPainter.h"
28 #include "TPad.h"
29 #include "TView.h"
30 #include "TGTab.h"
31 #include "TGComboBox.h"
32 #include "TGButton.h"
33 #include "TGTextEntry.h"
34 #include "TGNumberEntry.h"
35 #include "TGLabel.h"
36 
37 ClassImp(TGeoPgonEditor);
38 
39 enum ETGeoPgonWid {
40  kPGON_NEDGES
41 };
42 
43 ////////////////////////////////////////////////////////////////////////////////
44 /// Constructor for polygone editor
45 
46 TGeoPgonEditor::TGeoPgonEditor(const TGWindow *p, Int_t width,
47  Int_t height, UInt_t options, Pixel_t back)
48  : TGeoPconEditor(p, width, height, options | kVerticalFrame, back)
49 {
50  fNedgesi = 0;
51  CreateEdges();
52  TGeoTabManager::MoveFrame(fDFrame, this);
53  TGeoTabManager::MoveFrame(fBFrame, this);
54  fENedges->Connect("ValueSet(Long_t)", "TGeoPgonEditor", this, "DoNedges()");
55  fENedges->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoPgonEditor", this, "DoModified()");
56 }
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 /// Destructor
60 
61 TGeoPgonEditor::~TGeoPgonEditor()
62 {
63  TGFrameElement *el;
64  TIter next(GetList());
65  while ((el = (TGFrameElement *)next())) {
66  if (el->fFrame->IsComposite())
67  TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
68  }
69  Cleanup();
70 }
71 
72 ////////////////////////////////////////////////////////////////////////////////
73 /// Connect to a given pgon.
74 
75 void TGeoPgonEditor::SetModel(TObject* obj)
76 {
77  if (obj == 0 || (obj->IsA()!=TGeoPgon::Class())) {
78  SetActive(kFALSE);
79  return;
80  }
81  fShape = (TGeoPcon*)obj;
82  const char *sname = fShape->GetName();
83  if (!strcmp(sname, fShape->ClassName())) fShapeName->SetText("-no_name");
84  else fShapeName->SetText(sname);
85 
86  Int_t nsections = fShape->GetNz();
87  fNsecti = nsections;
88  fNedgesi = ((TGeoPgon*)fShape)->GetNedges();
89  fENz->SetNumber(nsections);
90  fENedges->SetNumber(fNedgesi);
91  fEPhi1->SetNumber(fShape->GetPhi1());
92  fPhi1i = fShape->GetPhi1();
93  fEDPhi->SetNumber(fShape->GetDphi());
94  fDPhii = fShape->GetDphi();
95  CreateSections(nsections);
96  UpdateSections();
97 
98  fApply->SetEnabled(kFALSE);
99  fUndo->SetEnabled(kFALSE);
100 
101  if (fInit) ConnectSignals2Slots();
102  SetActive();
103 }
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 /// Slot for applying modifications.
107 
108 void TGeoPgonEditor::DoApply()
109 {
110  TGeoPgon *shape = (TGeoPgon*)fShape;
111  const char *name = fShapeName->GetText();
112  if (strcmp(name,fShape->GetName())) fShape->SetName(name);
113  fApply->SetEnabled(kFALSE);
114  fUndo->SetEnabled();
115  if (!CheckSections()) return;
116  // check if number of sections changed
117  Bool_t recreate = kFALSE;
118  Int_t nz = fENz->GetIntNumber();
119  Int_t nedges = fENedges->GetIntNumber();
120  Double_t phi1 = fEPhi1->GetNumber();
121  Double_t dphi = fEDPhi->GetNumber();
122  if (nz != fShape->GetNz()) recreate = kTRUE;
123  TGeoPconSection *sect;
124  Int_t isect;
125  if (recreate) {
126  Double_t *array = new Double_t[3*(nz+1)+1];
127  array[0] = phi1;
128  array[1] = dphi;
129  array[2] = nedges;
130  array[3] = nz;
131  for (isect=0; isect<nz; isect++) {
132  sect = (TGeoPconSection*)fSections->At(isect);
133  array[4+3*isect] = sect->GetZ();
134  array[5+3*isect] = sect->GetRmin();
135  array[6+3*isect] = sect->GetRmax();
136  }
137  shape->SetDimensions(array);
138  delete [] array;
139  if (fPad) {
140  if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
141  TView *view = fPad->GetView();
142  if (!view) {
143  fShape->Draw();
144  fPad->GetView()->ShowAxis();
145  } else {
146  const Double_t *orig = fShape->GetOrigin();
147  view->SetRange(orig[0]-fShape->GetDX(), orig[1]-fShape->GetDY(), orig[2]-fShape->GetDZ(),
148  orig[0]+fShape->GetDX(), orig[1]+fShape->GetDY(), orig[2]+fShape->GetDZ());
149  Update();
150  }
151  } else Update();
152  }
153  return;
154  }
155  // No need to call SetDimensions
156  if (TMath::Abs(phi1-fShape->GetPhi1())>1.e-6) fShape->Phi1() = phi1;
157  if (TMath::Abs(dphi-fShape->GetDphi())>1.e-6) fShape->Dphi() = dphi;
158  if (nedges != shape->GetNedges()) shape->SetNedges(nedges);
159  for (isect=0; isect<fNsections; isect++) {
160  sect = (TGeoPconSection*)fSections->At(isect);
161  fShape->Z(isect) = sect->GetZ();
162  fShape->Rmin(isect) = sect->GetRmin();
163  fShape->Rmax(isect) = sect->GetRmax();
164  }
165  shape->ComputeBBox();
166  if (fPad) {
167  if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
168  TView *view = fPad->GetView();
169  if (!view) {
170  shape->Draw();
171  fPad->GetView()->ShowAxis();
172  } else {
173  const Double_t *orig = fShape->GetOrigin();
174  view->SetRange(orig[0]-fShape->GetDX(), orig[1]-fShape->GetDY(), orig[2]-fShape->GetDZ(),
175  orig[0]+fShape->GetDX(), orig[1]+fShape->GetDY(), orig[2]+fShape->GetDZ());
176  Update();
177  }
178  } else Update();
179  }
180 }
181 
182 ////////////////////////////////////////////////////////////////////////////////
183 /// Slot for undoing last operation.
184 
185 void TGeoPgonEditor::DoUndo()
186 {
187  fENedges->SetNumber(fNedgesi);
188  TGeoPconEditor::DoUndo();
189 }
190 
191 ////////////////////////////////////////////////////////////////////////////////
192 /// Create number entry for Nedges.
193 
194 void TGeoPgonEditor::CreateEdges()
195 {
196  TGTextEntry *nef;
197  TGCompositeFrame *f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
198  f1->AddFrame(new TGLabel(f1, "Nedges"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
199  fENedges = new TGNumberEntry(f1, 0., 5, kPGON_NEDGES);
200  fENedges->SetNumAttr(TGNumberFormat::kNEAPositive);
201  fENedges->SetNumStyle(TGNumberFormat::kNESInteger);
202  fENedges->Resize(100,fENedges->GetDefaultHeight());
203  nef = (TGTextEntry*)fENedges->GetNumberEntry();
204  nef->SetToolTipText("Enter the number of edges of the polygon");
205  fENedges->Associate(this);
206  f1->AddFrame(fENedges, new TGLayoutHints(kLHintsRight, 2, 2, 2, 2));
207  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
208 }
209 
210 ////////////////////////////////////////////////////////////////////////////////
211 /// Change number of edges.
212 
213 void TGeoPgonEditor::DoNedges()
214 {
215  Int_t nedges = fENedges->GetIntNumber();
216  if (nedges < 3) {
217  nedges = 3;
218  fENedges->SetNumber(nedges);
219  }
220  DoModified();
221  if (!IsDelayed()) DoApply();
222 }
223