00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "TGLClipSetEditor.h"
00013 #include "TGLClip.h"
00014 #include "TVirtualPad.h"
00015 #include "TColor.h"
00016 #include "TGLabel.h"
00017 #include "TGButton.h"
00018 #include "TGButtonGroup.h"
00019 #include "TGNumberEntry.h"
00020
00021 #include "TGLViewerEditor.h"
00022
00023
00024
00025
00026
00027
00028 ClassImp(TGLClipSetSubEditor);
00029
00030
00031 TGLClipSetSubEditor::TGLClipSetSubEditor(const TGWindow *p) :
00032 TGVerticalFrame(p),
00033 fM(0),
00034 fCurrentClip(kClipNone),
00035 fTypeButtons(0),
00036 fPlanePropFrame(0),
00037 fPlaneProp(),
00038 fBoxPropFrame(0),
00039 fBoxProp(),
00040 fClipInside(0),
00041 fAutoUpdate(0),
00042 fClipEdit(0),
00043 fClipShow(0),
00044 fApplyButton(0),
00045 fResetButton(0)
00046 {
00047
00048
00049 fTypeButtons = new TGButtonGroup(this, "Clip Type", kChildFrame|kHorizontalFrame);
00050 new TGRadioButton(fTypeButtons, "None ");
00051 new TGRadioButton(fTypeButtons, "Plane ");
00052 new TGRadioButton(fTypeButtons, "Box");
00053 fTypeButtons->SetLayoutHints(new TGLayoutHints(kLHintsLeft|kLHintsBottom, 0, 0, 2, -10));
00054 AddFrame(fTypeButtons, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 3, 2, 2));
00055
00056 fClipInside = new TGCheckButton(this, "Clip away inside");
00057 AddFrame(fClipInside, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 3, 2, 2));
00058 fAutoUpdate = new TGCheckButton(this, "Auto update clip");
00059 AddFrame(fAutoUpdate, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 3, 2, 2));
00060 fClipEdit = new TGCheckButton(this, "Edit In Viewer");
00061 AddFrame(fClipEdit, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 3, 2, 2));
00062 fClipShow = new TGCheckButton(this, "Show In Viewer");
00063 AddFrame(fClipShow, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 3, 2, 2));
00064
00065
00066 fPlanePropFrame = new TGCompositeFrame(this);
00067 AddFrame(fPlanePropFrame, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 3, 2, 2));
00068
00069 static const char * const planeStr[] = { "aX + ", "bY +", "cZ + ", "d = 0" };
00070
00071 for (Int_t i = 0; i < 4; ++i)
00072 fPlaneProp[i] = TGLViewerEditor::MakeLabeledNEntry(fPlanePropFrame, planeStr[i] , 40);
00073
00074
00075 fBoxPropFrame = new TGCompositeFrame(this);
00076 AddFrame(fBoxPropFrame, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 3, 2, 2));
00077
00078 static const char * const boxStr[] = {"Center X", "Center Y", "Center Z", "Length X", "Length Y", "Length Z" };
00079
00080 for (Int_t i = 0; i < 6; ++i)
00081 fBoxProp[i] = TGLViewerEditor::MakeLabeledNEntry(fBoxPropFrame, boxStr[i] , 60);
00082
00083
00084 fApplyButton = new TGTextButton(this, "Apply");
00085 AddFrame(fApplyButton, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 3, 2, 2));
00086
00087 fResetButton = new TGTextButton(this, "Reset");
00088 AddFrame(fResetButton, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 3, 2, 2));
00089
00090 fTypeButtons->Connect("Clicked(Int_t)", "TGLClipSetSubEditor", this, "ClipTypeChanged(Int_t)");
00091 fClipInside->Connect("Clicked()", "TGLClipSetSubEditor", this, "UpdateViewerClip()");
00092 fAutoUpdate->Connect("Clicked()", "TGLClipSetSubEditor", this, "UpdateViewerClip()");
00093 fClipEdit->Connect("Clicked()", "TGLClipSetSubEditor", this, "UpdateViewerClip()");
00094 fClipShow->Connect("Clicked()", "TGLClipSetSubEditor", this, "UpdateViewerClip()");
00095
00096 for (Int_t i = 0; i < 4; ++i)
00097 fPlaneProp[i]->Connect("ValueSet(Long_t)", "TGLClipSetSubEditor", this, "ClipValueChanged()");
00098
00099 for (Int_t i = 0; i < 6; ++i)
00100 fBoxProp[i]->Connect("ValueSet(Long_t)", "TGLClipSetSubEditor", this, "ClipValueChanged()");
00101
00102 fApplyButton->Connect("Pressed()", "TGLClipSetSubEditor", this, "UpdateViewerClip()");
00103 fResetButton->Connect("Pressed()", "TGLClipSetSubEditor", this, "ResetViewerClip()");
00104 }
00105
00106
00107
00108 void TGLClipSetSubEditor::SetModel(TGLClipSet* m)
00109 {
00110
00111
00112 fM = m;
00113
00114 fTypeButtons->GetButton(fCurrentClip+1)->SetDown(kFALSE);
00115 fCurrentClip = fM->GetClipType();
00116
00117 Double_t clip[6] = {0.};
00118 fM->GetClipState(fCurrentClip, clip);
00119
00120 fApplyButton->SetState(kButtonDisabled);
00121
00122
00123 if (TGButton *btn = fTypeButtons->GetButton(fCurrentClip+1)) {
00124 btn->SetDown();
00125 fTypeButtons->SetButton(fCurrentClip+1);
00126 }
00127 Bool_t active = (fCurrentClip != kClipNone);
00128 fClipInside->SetEnabled(active);
00129 fAutoUpdate->SetEnabled(active);
00130 fClipEdit ->SetEnabled(active);
00131 fClipShow ->SetEnabled(active);
00132 if (active) {
00133 fClipEdit->SetDown(fM->GetShowManip());
00134 fClipShow->SetDown(fM->GetShowClip());
00135 fClipInside->SetDown(fM->GetCurrentClip()->GetMode() == TGLClip::kInside);
00136 fAutoUpdate->SetDown(fM->GetAutoUpdate());
00137
00138 if (fCurrentClip == kClipPlane) {
00139 HideFrame(fBoxPropFrame);
00140 ShowFrame(fPlanePropFrame);
00141 for (Int_t i = 0; i < 4; ++i)
00142 fPlaneProp[i]->SetNumber(clip[i]);
00143 } else if (fCurrentClip == kClipBox) {
00144 HideFrame(fPlanePropFrame);
00145 ShowFrame(fBoxPropFrame);
00146 for (Int_t i = 0; i < 6; ++i)
00147 fBoxProp[i]->SetNumber(clip[i]);
00148 }
00149
00150 fResetButton->SetState(kButtonUp);
00151 } else {
00152 HideFrame(fPlanePropFrame);
00153 HideFrame(fBoxPropFrame);
00154
00155 fResetButton->SetState(kButtonDisabled);
00156 }
00157 }
00158
00159
00160
00161 void TGLClipSetSubEditor::Changed()
00162 {
00163
00164
00165 Emit("Changed()");
00166 }
00167
00168
00169
00170 void TGLClipSetSubEditor::ClipValueChanged()
00171 {
00172
00173
00174 fApplyButton->SetState(kButtonUp);
00175 }
00176
00177
00178
00179 void TGLClipSetSubEditor::ClipTypeChanged(Int_t id)
00180 {
00181
00182
00183 switch (id)
00184 {
00185 case 2: fCurrentClip = kClipPlane; break;
00186 case 3: fCurrentClip = kClipBox; break;
00187 default: fCurrentClip = kClipNone; break;
00188 }
00189 fM->SetClipType(fCurrentClip);
00190 SetModel(fM);
00191 ((TGMainFrame*)GetMainFrame())->Layout();
00192 Changed();
00193 }
00194
00195
00196
00197 void TGLClipSetSubEditor::UpdateViewerClip()
00198 {
00199
00200
00201 Double_t data[6] = {0.};
00202
00203 if (fCurrentClip == kClipPlane)
00204 for (Int_t i = 0; i < 4; ++i)
00205 data[i] = fPlaneProp[i]->GetNumber();
00206 else if (fCurrentClip == kClipBox)
00207 for (Int_t i = 0; i < 6; ++i)
00208 data[i] = fBoxProp[i]->GetNumber();
00209
00210 fApplyButton->SetState(kButtonDisabled);
00211
00212 fM->SetClipState(fCurrentClip, data);
00213 fM->SetShowManip(fClipEdit->IsDown());
00214 fM->SetShowClip (fClipShow->IsDown());
00215 if (fCurrentClip != kClipNone)
00216 fM->GetCurrentClip()->SetMode(fClipInside->IsDown() ? TGLClip::kInside : TGLClip::kOutside);
00217 fM->SetAutoUpdate(fAutoUpdate->IsDown());
00218
00219 Changed();
00220 }
00221
00222
00223 void TGLClipSetSubEditor::ResetViewerClip()
00224 {
00225
00226
00227 if (fCurrentClip != kClipNone) {
00228 if (fM->GetClipType() == kClipPlane) {
00229 TGLPlane plane(0.0, -1.0, 0.0, 0.0);
00230 dynamic_cast<TGLClipPlane*>(fM->GetCurrentClip())->Set(plane);
00231 } else if (fM->GetClipType() == kClipBox) {
00232 fM->GetCurrentClip()->SetTransform(TGLMatrix());
00233 }
00234 Changed();
00235 }
00236 }
00237
00238
00239
00240
00241
00242
00243 ClassImp(TGLClipSetEditor);
00244
00245
00246 TGLClipSetEditor::TGLClipSetEditor(const TGWindow *p, Int_t width, Int_t height,
00247 UInt_t options, Pixel_t back) :
00248 TGedFrame(p, width, height, options | kVerticalFrame, back),
00249 fM (0),
00250 fSE (0)
00251 {
00252
00253
00254 MakeTitle("TGLClipSet");
00255
00256 fSE = new TGLClipSetSubEditor(this);
00257 AddFrame(fSE, new TGLayoutHints(kLHintsTop, 2, 0, 2, 2));
00258 fSE->Connect("Changed()", "TGLClipSetEditor", this, "Update()");
00259 }
00260
00261
00262
00263 void TGLClipSetEditor::SetModel(TObject* obj)
00264 {
00265
00266
00267 fM = dynamic_cast<TGLClipSet*>(obj);
00268 fSE->SetModel(fM);
00269 }