ROOT logo
// @(#):$Id: TGeoEltuEditor.cxx 20882 2007-11-19 11:31:26Z rdm $
// Author: M.Gheata 

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

//////////////////////////////////////////////////////////////////////////
//                                                                      //
//  TGeoEltuEditor                                                      //
//                                                                      //
//////////////////////////////////////////////////////////////////////////
//Begin_Html
/*
<img src="gif/eltu_pic.gif">
*/
//End_Html
//Begin_Html
/*
<img src="gif/eltu_ed.jpg">
*/
//End_Html

#include "TGeoEltuEditor.h"
#include "TGeoTabManager.h"
#include "TGeoEltu.h"
#include "TGeoManager.h"
#include "TVirtualGeoPainter.h"
#include "TPad.h"
#include "TView.h"
#include "TGTab.h"
#include "TGComboBox.h"
#include "TGButton.h"
#include "TGTextEntry.h"
#include "TGNumberEntry.h"
#include "TGLabel.h"

ClassImp(TGeoEltuEditor)

enum ETGeoEltuWid {
   kELTU_NAME, kELTU_A, kELTU_B,  kELTU_DZ,
   kELTU_APPLY, kELTU_UNDO
};

//______________________________________________________________________________
TGeoEltuEditor::TGeoEltuEditor(const TGWindow *p, Int_t width,
                                   Int_t height, UInt_t options, Pixel_t back)
   : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
{
   // Constructor for para editor
   fShape   = 0;
   fAi = fBi = fDzi = 0.0;
   fNamei = "";
   fIsModified = kFALSE;
   fIsShapeEditable = kTRUE;

   // TextEntry for shape name
   MakeTitle("Name");
   fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kELTU_NAME);
   fShapeName->Resize(135, fShapeName->GetDefaultHeight());
   fShapeName->SetToolTipText("Enter the elliptical tube name");
   fShapeName->Associate(this);
   AddFrame(fShapeName, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));

   TGTextEntry *nef;
   MakeTitle("Dimensions");
   // Number entry for A
   TGCompositeFrame *f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
   f1->AddFrame(new TGLabel(f1, "A"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
   fEA = new TGNumberEntry(f1, 0., 5, kELTU_A);
   fEA->SetNumAttr(TGNumberFormat::kNEAPositive);
   fEA->Resize(100, fEA->GetDefaultHeight());
   nef = (TGTextEntry*)fEA->GetNumberEntry();
   nef->SetToolTipText("Enter the semi-axis of the ellipse along x");
   fEA->Associate(this);
   f1->AddFrame(fEA, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
   AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
   
   // Number entry for B
   f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
   f1->AddFrame(new TGLabel(f1, "B"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
   fEB = new TGNumberEntry(f1, 0., 5, kELTU_B);
   fEB->SetNumAttr(TGNumberFormat::kNEAPositive);
   fEB->Resize(100, fEB->GetDefaultHeight());
   nef = (TGTextEntry*)fEB->GetNumberEntry();
   nef->SetToolTipText("Enter the semi-axis of the ellipse along y");
   fEB->Associate(this);
   f1->AddFrame(fEB, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
   AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
   
   // Number entry for dz
   f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
   f1->AddFrame(new TGLabel(f1, "Dz"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
   fEDz = new TGNumberEntry(f1, 0., 5, kELTU_DZ);
   fEDz->SetNumAttr(TGNumberFormat::kNEAPositive);
   fEDz->Resize(100, fEDz->GetDefaultHeight());
   nef = (TGTextEntry*)fEDz->GetNumberEntry();
   nef->SetToolTipText("Enter the half-lenth in Z");
   fEDz->Associate(this);
   f1->AddFrame(fEDz, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
   AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
 
   // Delayed draw
   f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame);
   fDelayed = new TGCheckButton(f1, "Delayed draw");
   f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
   AddFrame(f1,  new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));  

   // Buttons
   f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
   fApply = new TGTextButton(f1, "Apply");
   f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
   fApply->Associate(this);
   fUndo = new TGTextButton(f1, "Undo");
   f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
   fUndo->Associate(this);
   AddFrame(f1,  new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));  
   fUndo->SetSize(fApply->GetSize());
}

//______________________________________________________________________________
TGeoEltuEditor::~TGeoEltuEditor()
{
// Destructor
   TGFrameElement *el;
   TIter next(GetList());
   while ((el = (TGFrameElement *)next())) {
      if (el->fFrame->IsComposite()) 
         TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
   }
   Cleanup();   
}

//______________________________________________________________________________
void TGeoEltuEditor::ConnectSignals2Slots()
{
   // Connect signals to slots.
   fApply->Connect("Clicked()", "TGeoEltuEditor", this, "DoApply()");
   fUndo->Connect("Clicked()", "TGeoEltuEditor", this, "DoUndo()");
   fShapeName->Connect("TextChanged(const char *)", "TGeoEltuEditor", this, "DoModified()");
   fEA->Connect("ValueSet(Long_t)", "TGeoEltuEditor", this, "DoA()");
   fEB->Connect("ValueSet(Long_t)", "TGeoEltuEditor", this, "DoB()");
   fEDz->Connect("ValueSet(Long_t)", "TGeoEltuEditor", this, "DoDz()");
   fEA->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoEltuEditor", this, "DoModified()");
   fEB->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoEltuEditor", this, "DoModified()");
   fEDz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoEltuEditor", this, "DoModified()");
   fInit = kFALSE;
}

//______________________________________________________________________________
void TGeoEltuEditor::SetModel(TObject* obj)
{
   // Connect to the selected object.
   if (obj == 0 || (obj->IsA()!=TGeoEltu::Class())) {
      SetActive(kFALSE);
      return;                 
   } 
   fShape = (TGeoEltu*)obj;
   fAi = fShape->GetA();
   fBi = fShape->GetB();
   fDzi = fShape->GetDz();
   const char *sname = fShape->GetName();
   if (!strcmp(sname, fShape->ClassName())) fShapeName->SetText("-no_name");
   else {
      fShapeName->SetText(sname);
      fNamei = sname;
   }   
   fEA->SetNumber(fAi);
   fEB->SetNumber(fBi);
   fEDz->SetNumber(fDzi);
   fApply->SetEnabled(kFALSE);
   fUndo->SetEnabled(kFALSE);
   
   if (fInit) ConnectSignals2Slots();
   SetActive();
}

//______________________________________________________________________________
void TGeoEltuEditor::DoName()
{
// Slot for name.
   DoModified();
}

//______________________________________________________________________________
Bool_t TGeoEltuEditor::IsDelayed() const
{
// Check if shape drawing is delayed.
   return (fDelayed->GetState() == kButtonDown);
}

//______________________________________________________________________________
void TGeoEltuEditor::DoApply()
{
// Slot for applying current settings.
   const char *name = fShapeName->GetText();
   if (strcmp(name,fShape->GetName())) fShape->SetName(name);
   Double_t a = fEA->GetNumber();
   Double_t b = fEB->GetNumber(); 
   Double_t z = fEDz->GetNumber();  
   Double_t param[3];
   param[0] = a;
   param[1] = b;
   param[2] = z;
   fShape->SetDimensions(param);
   fShape->ComputeBBox();
   fUndo->SetEnabled();
   fApply->SetEnabled(kFALSE);
   if (fPad) {
      if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
         TView *view = fPad->GetView();
         if (!view) {
            fShape->Draw();
            fPad->GetView()->ShowAxis();
         } else {
            view->SetRange(-fShape->GetDX(), -fShape->GetDY(), -fShape->GetDZ(),
                           fShape->GetDX(), fShape->GetDY(), fShape->GetDZ());
            Update();
         }                  
      } else Update();
   }   
}

//______________________________________________________________________________
void TGeoEltuEditor::DoModified()
{
// Slot for notifying modifications.
   fApply->SetEnabled();
}

//______________________________________________________________________________
void TGeoEltuEditor::DoUndo()
{
// Slot for undoing last operation.
   fEA->SetNumber(fAi);
   fEB->SetNumber(fBi);
   fEDz->SetNumber(fDzi);
   DoApply();
   fUndo->SetEnabled(kFALSE);
   fApply->SetEnabled(kFALSE);
}
   
//______________________________________________________________________________
void TGeoEltuEditor::DoA()
{
// Slot for A.
   Double_t a = fEA->GetNumber();
   if (a <= 0) {
      a = 0.1;
      fEA->SetNumber(a);
   }   
   DoModified();
   if (!IsDelayed()) DoApply();
}

//______________________________________________________________________________
void TGeoEltuEditor::DoB()
{
// Slot for B.
   Double_t b = fEB->GetNumber();
   if (b <= 0) {
      b = 0.1;
      fEB->SetNumber(b);
   }   
   DoModified();
   if (!IsDelayed()) DoApply();
}

//______________________________________________________________________________
void TGeoEltuEditor::DoDz()
{
// Slot for Z.
   Double_t z = fEDz->GetNumber();
   if (z <= 0) {
      z = 0.1;
      fEDz->SetNumber(z);
   }   
   DoModified();
   if (!IsDelayed()) DoApply();
}

 TGeoEltuEditor.cxx:1
 TGeoEltuEditor.cxx:2
 TGeoEltuEditor.cxx:3
 TGeoEltuEditor.cxx:4
 TGeoEltuEditor.cxx:5
 TGeoEltuEditor.cxx:6
 TGeoEltuEditor.cxx:7
 TGeoEltuEditor.cxx:8
 TGeoEltuEditor.cxx:9
 TGeoEltuEditor.cxx:10
 TGeoEltuEditor.cxx:11
 TGeoEltuEditor.cxx:12
 TGeoEltuEditor.cxx:13
 TGeoEltuEditor.cxx:14
 TGeoEltuEditor.cxx:15
 TGeoEltuEditor.cxx:16
 TGeoEltuEditor.cxx:17
 TGeoEltuEditor.cxx:18
 TGeoEltuEditor.cxx:19
 TGeoEltuEditor.cxx:20
 TGeoEltuEditor.cxx:21
 TGeoEltuEditor.cxx:22
 TGeoEltuEditor.cxx:23
 TGeoEltuEditor.cxx:24
 TGeoEltuEditor.cxx:25
 TGeoEltuEditor.cxx:26
 TGeoEltuEditor.cxx:27
 TGeoEltuEditor.cxx:28
 TGeoEltuEditor.cxx:29
 TGeoEltuEditor.cxx:30
 TGeoEltuEditor.cxx:31
 TGeoEltuEditor.cxx:32
 TGeoEltuEditor.cxx:33
 TGeoEltuEditor.cxx:34
 TGeoEltuEditor.cxx:35
 TGeoEltuEditor.cxx:36
 TGeoEltuEditor.cxx:37
 TGeoEltuEditor.cxx:38
 TGeoEltuEditor.cxx:39
 TGeoEltuEditor.cxx:40
 TGeoEltuEditor.cxx:41
 TGeoEltuEditor.cxx:42
 TGeoEltuEditor.cxx:43
 TGeoEltuEditor.cxx:44
 TGeoEltuEditor.cxx:45
 TGeoEltuEditor.cxx:46
 TGeoEltuEditor.cxx:47
 TGeoEltuEditor.cxx:48
 TGeoEltuEditor.cxx:49
 TGeoEltuEditor.cxx:50
 TGeoEltuEditor.cxx:51
 TGeoEltuEditor.cxx:52
 TGeoEltuEditor.cxx:53
 TGeoEltuEditor.cxx:54
 TGeoEltuEditor.cxx:55
 TGeoEltuEditor.cxx:56
 TGeoEltuEditor.cxx:57
 TGeoEltuEditor.cxx:58
 TGeoEltuEditor.cxx:59
 TGeoEltuEditor.cxx:60
 TGeoEltuEditor.cxx:61
 TGeoEltuEditor.cxx:62
 TGeoEltuEditor.cxx:63
 TGeoEltuEditor.cxx:64
 TGeoEltuEditor.cxx:65
 TGeoEltuEditor.cxx:66
 TGeoEltuEditor.cxx:67
 TGeoEltuEditor.cxx:68
 TGeoEltuEditor.cxx:69
 TGeoEltuEditor.cxx:70
 TGeoEltuEditor.cxx:71
 TGeoEltuEditor.cxx:72
 TGeoEltuEditor.cxx:73
 TGeoEltuEditor.cxx:74
 TGeoEltuEditor.cxx:75
 TGeoEltuEditor.cxx:76
 TGeoEltuEditor.cxx:77
 TGeoEltuEditor.cxx:78
 TGeoEltuEditor.cxx:79
 TGeoEltuEditor.cxx:80
 TGeoEltuEditor.cxx:81
 TGeoEltuEditor.cxx:82
 TGeoEltuEditor.cxx:83
 TGeoEltuEditor.cxx:84
 TGeoEltuEditor.cxx:85
 TGeoEltuEditor.cxx:86
 TGeoEltuEditor.cxx:87
 TGeoEltuEditor.cxx:88
 TGeoEltuEditor.cxx:89
 TGeoEltuEditor.cxx:90
 TGeoEltuEditor.cxx:91
 TGeoEltuEditor.cxx:92
 TGeoEltuEditor.cxx:93
 TGeoEltuEditor.cxx:94
 TGeoEltuEditor.cxx:95
 TGeoEltuEditor.cxx:96
 TGeoEltuEditor.cxx:97
 TGeoEltuEditor.cxx:98
 TGeoEltuEditor.cxx:99
 TGeoEltuEditor.cxx:100
 TGeoEltuEditor.cxx:101
 TGeoEltuEditor.cxx:102
 TGeoEltuEditor.cxx:103
 TGeoEltuEditor.cxx:104
 TGeoEltuEditor.cxx:105
 TGeoEltuEditor.cxx:106
 TGeoEltuEditor.cxx:107
 TGeoEltuEditor.cxx:108
 TGeoEltuEditor.cxx:109
 TGeoEltuEditor.cxx:110
 TGeoEltuEditor.cxx:111
 TGeoEltuEditor.cxx:112
 TGeoEltuEditor.cxx:113
 TGeoEltuEditor.cxx:114
 TGeoEltuEditor.cxx:115
 TGeoEltuEditor.cxx:116
 TGeoEltuEditor.cxx:117
 TGeoEltuEditor.cxx:118
 TGeoEltuEditor.cxx:119
 TGeoEltuEditor.cxx:120
 TGeoEltuEditor.cxx:121
 TGeoEltuEditor.cxx:122
 TGeoEltuEditor.cxx:123
 TGeoEltuEditor.cxx:124
 TGeoEltuEditor.cxx:125
 TGeoEltuEditor.cxx:126
 TGeoEltuEditor.cxx:127
 TGeoEltuEditor.cxx:128
 TGeoEltuEditor.cxx:129
 TGeoEltuEditor.cxx:130
 TGeoEltuEditor.cxx:131
 TGeoEltuEditor.cxx:132
 TGeoEltuEditor.cxx:133
 TGeoEltuEditor.cxx:134
 TGeoEltuEditor.cxx:135
 TGeoEltuEditor.cxx:136
 TGeoEltuEditor.cxx:137
 TGeoEltuEditor.cxx:138
 TGeoEltuEditor.cxx:139
 TGeoEltuEditor.cxx:140
 TGeoEltuEditor.cxx:141
 TGeoEltuEditor.cxx:142
 TGeoEltuEditor.cxx:143
 TGeoEltuEditor.cxx:144
 TGeoEltuEditor.cxx:145
 TGeoEltuEditor.cxx:146
 TGeoEltuEditor.cxx:147
 TGeoEltuEditor.cxx:148
 TGeoEltuEditor.cxx:149
 TGeoEltuEditor.cxx:150
 TGeoEltuEditor.cxx:151
 TGeoEltuEditor.cxx:152
 TGeoEltuEditor.cxx:153
 TGeoEltuEditor.cxx:154
 TGeoEltuEditor.cxx:155
 TGeoEltuEditor.cxx:156
 TGeoEltuEditor.cxx:157
 TGeoEltuEditor.cxx:158
 TGeoEltuEditor.cxx:159
 TGeoEltuEditor.cxx:160
 TGeoEltuEditor.cxx:161
 TGeoEltuEditor.cxx:162
 TGeoEltuEditor.cxx:163
 TGeoEltuEditor.cxx:164
 TGeoEltuEditor.cxx:165
 TGeoEltuEditor.cxx:166
 TGeoEltuEditor.cxx:167
 TGeoEltuEditor.cxx:168
 TGeoEltuEditor.cxx:169
 TGeoEltuEditor.cxx:170
 TGeoEltuEditor.cxx:171
 TGeoEltuEditor.cxx:172
 TGeoEltuEditor.cxx:173
 TGeoEltuEditor.cxx:174
 TGeoEltuEditor.cxx:175
 TGeoEltuEditor.cxx:176
 TGeoEltuEditor.cxx:177
 TGeoEltuEditor.cxx:178
 TGeoEltuEditor.cxx:179
 TGeoEltuEditor.cxx:180
 TGeoEltuEditor.cxx:181
 TGeoEltuEditor.cxx:182
 TGeoEltuEditor.cxx:183
 TGeoEltuEditor.cxx:184
 TGeoEltuEditor.cxx:185
 TGeoEltuEditor.cxx:186
 TGeoEltuEditor.cxx:187
 TGeoEltuEditor.cxx:188
 TGeoEltuEditor.cxx:189
 TGeoEltuEditor.cxx:190
 TGeoEltuEditor.cxx:191
 TGeoEltuEditor.cxx:192
 TGeoEltuEditor.cxx:193
 TGeoEltuEditor.cxx:194
 TGeoEltuEditor.cxx:195
 TGeoEltuEditor.cxx:196
 TGeoEltuEditor.cxx:197
 TGeoEltuEditor.cxx:198
 TGeoEltuEditor.cxx:199
 TGeoEltuEditor.cxx:200
 TGeoEltuEditor.cxx:201
 TGeoEltuEditor.cxx:202
 TGeoEltuEditor.cxx:203
 TGeoEltuEditor.cxx:204
 TGeoEltuEditor.cxx:205
 TGeoEltuEditor.cxx:206
 TGeoEltuEditor.cxx:207
 TGeoEltuEditor.cxx:208
 TGeoEltuEditor.cxx:209
 TGeoEltuEditor.cxx:210
 TGeoEltuEditor.cxx:211
 TGeoEltuEditor.cxx:212
 TGeoEltuEditor.cxx:213
 TGeoEltuEditor.cxx:214
 TGeoEltuEditor.cxx:215
 TGeoEltuEditor.cxx:216
 TGeoEltuEditor.cxx:217
 TGeoEltuEditor.cxx:218
 TGeoEltuEditor.cxx:219
 TGeoEltuEditor.cxx:220
 TGeoEltuEditor.cxx:221
 TGeoEltuEditor.cxx:222
 TGeoEltuEditor.cxx:223
 TGeoEltuEditor.cxx:224
 TGeoEltuEditor.cxx:225
 TGeoEltuEditor.cxx:226
 TGeoEltuEditor.cxx:227
 TGeoEltuEditor.cxx:228
 TGeoEltuEditor.cxx:229
 TGeoEltuEditor.cxx:230
 TGeoEltuEditor.cxx:231
 TGeoEltuEditor.cxx:232
 TGeoEltuEditor.cxx:233
 TGeoEltuEditor.cxx:234
 TGeoEltuEditor.cxx:235
 TGeoEltuEditor.cxx:236
 TGeoEltuEditor.cxx:237
 TGeoEltuEditor.cxx:238
 TGeoEltuEditor.cxx:239
 TGeoEltuEditor.cxx:240
 TGeoEltuEditor.cxx:241
 TGeoEltuEditor.cxx:242
 TGeoEltuEditor.cxx:243
 TGeoEltuEditor.cxx:244
 TGeoEltuEditor.cxx:245
 TGeoEltuEditor.cxx:246
 TGeoEltuEditor.cxx:247
 TGeoEltuEditor.cxx:248
 TGeoEltuEditor.cxx:249
 TGeoEltuEditor.cxx:250
 TGeoEltuEditor.cxx:251
 TGeoEltuEditor.cxx:252
 TGeoEltuEditor.cxx:253
 TGeoEltuEditor.cxx:254
 TGeoEltuEditor.cxx:255
 TGeoEltuEditor.cxx:256
 TGeoEltuEditor.cxx:257
 TGeoEltuEditor.cxx:258
 TGeoEltuEditor.cxx:259
 TGeoEltuEditor.cxx:260
 TGeoEltuEditor.cxx:261
 TGeoEltuEditor.cxx:262
 TGeoEltuEditor.cxx:263
 TGeoEltuEditor.cxx:264
 TGeoEltuEditor.cxx:265
 TGeoEltuEditor.cxx:266
 TGeoEltuEditor.cxx:267
 TGeoEltuEditor.cxx:268
 TGeoEltuEditor.cxx:269
 TGeoEltuEditor.cxx:270
 TGeoEltuEditor.cxx:271
 TGeoEltuEditor.cxx:272
 TGeoEltuEditor.cxx:273
 TGeoEltuEditor.cxx:274
 TGeoEltuEditor.cxx:275
 TGeoEltuEditor.cxx:276
 TGeoEltuEditor.cxx:277
 TGeoEltuEditor.cxx:278
 TGeoEltuEditor.cxx:279
 TGeoEltuEditor.cxx:280
 TGeoEltuEditor.cxx:281
 TGeoEltuEditor.cxx:282
 TGeoEltuEditor.cxx:283
 TGeoEltuEditor.cxx:284
 TGeoEltuEditor.cxx:285