TGLPShapeObjEditor.cxx

Go to the documentation of this file.
00001 // @(#)root/gl:$Id: TGLPShapeObjEditor.cxx 34286 2010-07-01 20:38:57Z rdm $
00002 // Author: Matevz Tadel   25/09/2006
00003 
00004 #include <cstring>
00005 
00006 #include "TGLPShapeObjEditor.h"
00007 #include "TGLPShapeObj.h"
00008 #include "TGedEditor.h"
00009 
00010 #include "TG3DLine.h"
00011 #include "TGButton.h"
00012 #include "TGButtonGroup.h"
00013 #include "TString.h"
00014 #include "TGLabel.h"
00015 #include "TClass.h"
00016 #include "TGCanvas.h"
00017 #include "TGTab.h"
00018 #include "TGSlider.h"
00019 #include "TGNumberEntry.h"
00020 #include "TGButtonGroup.h"
00021 #include "TROOT.h"
00022 
00023 #include "TVirtualGL.h"
00024 #include "TVirtualX.h"
00025 #include "TGLViewer.h"
00026 #include "TGLUtil.h"
00027 #include "TGLPhysicalShape.h"
00028 #include "TGLWidget.h"
00029 #include "TGLIncludes.h"
00030 
00031 #include "Buttons.h"
00032 
00033 //______________________________________________________________________________
00034 //
00035 // GUI editor for TGLPShapeObj.
00036 
00037 ClassImp(TGLPShapeObjEditor);
00038 
00039 enum EGeometry {
00040       kCenterX,
00041       kCenterY,
00042       kCenterZ,
00043       kScaleX,
00044       kScaleY,
00045       kScaleZ,
00046       kTot
00047 };
00048 
00049 enum EApplyButtonIds {
00050       kTBcp,
00051       kTBcpm,
00052       kTBda,
00053       kTBa,
00054       kTBaf,
00055       kTBEndOfList
00056 };
00057 
00058 enum EGLEditorIdent {
00059       kCPa = kTBEndOfList + 1,
00060       kCPd, kCPs, kCPe,
00061       kHSr, kHSg, kHSb,
00062       kHSa, kHSs, kHSe,
00063       kNExc, kNEyc, kNEzc,
00064       kNExs, kNEys, kNEzs,
00065       kNExp, kNEyp, kNEzp,
00066       kNEat
00067 };
00068 
00069 //______________________________________________________________________________
00070 TGLPShapeObjEditor::TGLPShapeObjEditor(const TGWindow *p,  Int_t width, Int_t height, UInt_t options, Pixel_t back)
00071    : TGedFrame(p,  width, height, options | kVerticalFrame, back),
00072      fLb(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 2, 3, 3), //button
00073      fLe(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 0, 0, 3, 3), //entries
00074      fLl(kLHintsLeft, 0, 8, 6, 0), // labels
00075      fLs(kLHintsTop | kLHintsCenterX, 2, 2, 0, 0),  ///sliders
00076      fGeoFrame(0),fGeoApplyButton(0),
00077      fColorFrame(0),
00078      fRedSlider(0), fGreenSlider(0), fBlueSlider(0), fAlphaSlider(0), fShineSlider(0),
00079      fColorApplyButton(0), fColorApplyFamily(0),
00080      fRGBA(),
00081      fPShapeObj(0)
00082 {
00083    // Constructor of TGLPhysicalShape editor GUI.
00084 
00085    fRGBA[12] = fRGBA[13] = fRGBA[14] = 0.0f;
00086    fRGBA[15] = 1.0f;
00087    fRGBA[16] = 60.0f;
00088 
00089    CreateColorControls();
00090    CreateGeoControls();
00091 }
00092 
00093 //______________________________________________________________________________
00094 TGLPShapeObjEditor::~TGLPShapeObjEditor()
00095 {
00096    // Destroy color editor GUI component.
00097    // Done automatically.
00098 }
00099 
00100 //______________________________________________________________________________
00101 void TGLPShapeObjEditor::SetPShape(TGLPhysicalShape * shape)
00102 {
00103    // Shape has changed.
00104    // Check if set to zero and make sure we're no longer in editor.
00105 
00106    TGLPShapeRef::SetPShape(shape);
00107    if (shape == 0 && fGedEditor->GetModel() == fPShapeObj)
00108       fGedEditor->SetModel(fGedEditor->GetPad(), fPShapeObj->fViewer, kButton1Down);
00109 }
00110 
00111 //______________________________________________________________________________
00112 void TGLPShapeObjEditor::PShapeModified()
00113 {
00114    // Shape has been modified.
00115    // Update editor if we're still shown. Otherwise unref.
00116 
00117    if (fGedEditor->GetModel() == fPShapeObj)
00118       fGedEditor->SetModel(fGedEditor->GetPad(), fPShapeObj, kButton1Down);
00119    else
00120       SetPShape(0);
00121 }
00122 
00123 //______________________________________________________________________________
00124 void TGLPShapeObjEditor::SetModel(TObject* obj)
00125 {
00126    // Sets model or disables/hides viewer.
00127 
00128    fPShapeObj = 0;
00129 
00130    fPShapeObj = static_cast<TGLPShapeObj *>(obj);
00131    SetPShape(fPShapeObj->fPShape);
00132 
00133    SetRGBA(fPShapeObj->fPShape->Color());
00134    SetCenter(fPShapeObj->fPShape->GetTranslation().CArr());
00135    SetScale(fPShapeObj->fPShape->GetScale().CArr());
00136    fGeoApplyButton->SetState(kButtonDisabled);
00137 }
00138 
00139 //______________________________________________________________________________
00140 void TGLPShapeObjEditor::SetCenter(const Double_t *c)
00141 {
00142    // Set internal center data from 3 component 'c'.
00143 
00144    fGeomData[kCenterX]->SetNumber(c[0]);
00145    fGeomData[kCenterY]->SetNumber(c[1]);
00146    fGeomData[kCenterZ]->SetNumber(c[2]);
00147 }
00148 
00149 //______________________________________________________________________________
00150 void TGLPShapeObjEditor::SetScale(const Double_t *s)
00151 {
00152    // Set internal scale data from 3 component 'c'.
00153 
00154    fGeomData[kScaleX]->SetNumber(s[0]);
00155    fGeomData[kScaleY]->SetNumber(s[1]);
00156    fGeomData[kScaleZ]->SetNumber(s[2]);
00157 }
00158 
00159 //______________________________________________________________________________
00160 void TGLPShapeObjEditor::DoGeoButton()
00161 {
00162    // Process 'Apply' - update the viewer object from GUI.
00163 
00164    TGLVertex3 trans;
00165    TGLVector3 scale;
00166    GetObjectData(trans.Arr(), scale.Arr());
00167    if (fPShape) {
00168       fPShape->SetTranslation(trans);
00169       fPShape->Scale(scale);
00170    }
00171    fPShapeObj->fViewer->RequestDraw();
00172    fGeoApplyButton->SetState(kButtonDisabled);
00173 }
00174 
00175 //______________________________________________________________________________
00176 void TGLPShapeObjEditor::GetObjectData(Double_t *center, Double_t *scale)
00177 {
00178    // Extract the GUI object data, return center in 3 component 'center'
00179    // scale in 3 component 'scale'.
00180 
00181    center[0] = fGeomData[kCenterX]->GetNumber();
00182    center[1] = fGeomData[kCenterY]->GetNumber();
00183    center[2] = fGeomData[kCenterZ]->GetNumber();
00184    scale[0] = fGeomData[kScaleX]->GetNumber();
00185    scale[1] = fGeomData[kScaleY]->GetNumber();
00186    scale[2] = fGeomData[kScaleZ]->GetNumber();
00187 }
00188 
00189 //______________________________________________________________________________
00190 void TGLPShapeObjEditor::GeoValueSet(Long_t)
00191 {
00192    // Process setting of value in edit box - activate 'Apply' button.
00193 
00194    if (fGeoApplyButton->GetState() != kButtonUp)
00195        fGeoApplyButton->SetState(kButtonUp);
00196 }
00197 
00198 //______________________________________________________________________________
00199 void TGLPShapeObjEditor::CreateGeoControls()
00200 {
00201    // Create GUI for setting scale and position.
00202 
00203    fGeoFrame = CreateEditorTabSubFrame("Geometry");
00204 
00205    TGLabel *label=0;
00206 
00207    // Postion container
00208    TGGroupFrame* container = new TGGroupFrame(fGeoFrame, "Object position:");
00209    container->SetTitlePos(TGGroupFrame::kLeft);
00210    fGeoFrame->AddFrame(container, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 8, 8, 3, 3));//-
00211    TGLayoutHints lh =  TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 0, 0, 0, 0);
00212 
00213    TGHorizontalFrame* hf;
00214 
00215    hf = new TGHorizontalFrame(container);
00216    label = new TGLabel(hf, "X:");
00217    hf->AddFrame(label, new TGLayoutHints(fLl));
00218    fGeomData[kCenterX] = new TGNumberEntry(hf, 0.0, 8, kNExc);
00219    hf->AddFrame(fGeomData[kCenterX], new TGLayoutHints(fLe));
00220    fGeomData[kCenterX]->Connect("ValueSet(Long_t)", "TGLPShapeObjEditor",
00221                                 this, "GeoValueSet(Long_t)");
00222    container->AddFrame(hf, new TGLayoutHints(lh));
00223 
00224    hf = new TGHorizontalFrame(container);
00225    label = new TGLabel(hf, "Y:");
00226    hf->AddFrame(label, new TGLayoutHints(fLl));
00227    fGeomData[kCenterY] = new TGNumberEntry(hf, 0.0, 8, kNEyc);
00228    hf->AddFrame(fGeomData[kCenterY], new TGLayoutHints(fLe));
00229    fGeomData[kCenterY]->Connect("ValueSet(Long_t)", "TGLPShapeObjEditor",
00230                                 this, "GeoValueSet(Long_t)");
00231    container->AddFrame(hf, new TGLayoutHints(lh));
00232 
00233    hf = new TGHorizontalFrame(container);
00234    hf->AddFrame(new TGLabel(hf, "Z:"), new TGLayoutHints(fLl));
00235    fGeomData[kCenterZ] = new TGNumberEntry(hf, 1.0, 8, kNEzc);
00236    hf->AddFrame(fGeomData[kCenterZ], new TGLayoutHints(fLe));
00237    fGeomData[kCenterZ]->Connect("ValueSet(Long_t)", "TGLPShapeObjEditor",
00238                                 this, "GeoValueSet(Long_t)");
00239    container->AddFrame(hf, new TGLayoutHints(lh));
00240 
00241    // Scale container
00242    TGGroupFrame* osf = new TGGroupFrame(fGeoFrame, "Object scale:", kLHintsTop | kLHintsCenterX);
00243    osf->SetTitlePos(TGGroupFrame::kLeft);
00244    fGeoFrame->AddFrame(osf, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 8, 8, 3, 3));
00245 
00246    hf = new TGHorizontalFrame(osf);
00247    hf->AddFrame(new TGLabel(hf, "X:"),new TGLayoutHints(fLl));
00248    fGeomData[kScaleX] = new TGNumberEntry(hf, 1.0, 5, kNExs);
00249    hf->AddFrame(fGeomData[kScaleX], new TGLayoutHints(fLe));
00250    fGeomData[kScaleX]->Connect("ValueSet(Long_t)", "TGLPShapeObjEditor",
00251                                this, "GeoValueSet(Long_t)");
00252    osf->AddFrame(hf, new TGLayoutHints(lh));
00253 
00254    hf = new TGHorizontalFrame(osf);
00255    hf->AddFrame(new TGLabel(hf, "Y:"),new TGLayoutHints(fLl));
00256    fGeomData[kScaleY] = new TGNumberEntry(hf, 1.0, 5, kNEys);
00257    hf->AddFrame(fGeomData[kScaleY], new TGLayoutHints(fLe));
00258    fGeomData[kScaleY]->Connect("ValueSet(Long_t)", "TGLPShapeObjEditor",
00259                                this, "GeoValueSet(Long_t)");
00260    osf->AddFrame(hf, new TGLayoutHints(lh));
00261 
00262    hf = new TGHorizontalFrame(osf);
00263    hf->AddFrame(new TGLabel(hf, "Z:"),new TGLayoutHints(fLl));
00264    fGeomData[kScaleZ] = new TGNumberEntry(hf, 1.0, 5, kNEzs);
00265    hf->AddFrame(fGeomData[kScaleZ], new TGLayoutHints(fLe));
00266    fGeomData[kScaleZ]->Connect("ValueSet(Long_t)", "TGLPShapeObjEditor",
00267                                this, "GeoValueSet(Long_t)");
00268    osf->AddFrame(hf, new TGLayoutHints(lh));
00269 
00270    hf = new TGHorizontalFrame(osf);
00271    fGeomData[kScaleX]->SetLimits(TGNumberFormat::kNELLimitMin, 0.1);
00272    fGeomData[kScaleY]->SetLimits(TGNumberFormat::kNELLimitMin, 0.1);
00273    fGeomData[kScaleZ]->SetLimits(TGNumberFormat::kNELLimitMin, 0.1);
00274    osf->AddFrame(hf, new TGLayoutHints(lh));
00275 
00276    // Modify button
00277    fGeoApplyButton = new TGTextButton(fGeoFrame, "Modify object");
00278    fGeoFrame->AddFrame(fGeoApplyButton, new TGLayoutHints(fLb));
00279    fGeoApplyButton->SetState(kButtonDisabled);
00280    fGeoApplyButton->Connect("Pressed()", "TGLPShapeObjEditor", this, "DoGeoButton()");
00281 }
00282 
00283 //______________________________________________________________________________
00284 void TGLPShapeObjEditor::SetRGBA(const Float_t *rgba)
00285 {
00286    // Set color sliders from 17 component 'rgba'.
00287 
00288    fColorApplyButton->SetState(kButtonDisabled);
00289    fColorApplyFamily->SetState(kButtonDisabled);
00290 
00291    for (Int_t i = 0; i < 17; ++i) fRGBA[i] = rgba[i];
00292 
00293    fRedSlider->SetPosition(Int_t(fRGBA[fLMode * 4] * 100));
00294    fGreenSlider->SetPosition(Int_t(fRGBA[fLMode * 4 + 1] * 100));
00295    fBlueSlider->SetPosition(Int_t(fRGBA[fLMode * 4 + 2] * 100));
00296    fShineSlider->SetPosition(Int_t(fRGBA[16]));
00297 
00298    DrawSphere();
00299 }
00300 
00301 //______________________________________________________________________________
00302 void TGLPShapeObjEditor::DoColorSlider(Int_t val)
00303 {
00304    // Process slider movement.
00305 
00306    TGSlider *frm = (TGSlider *)gTQSender;
00307 
00308    if (frm) {
00309       Int_t wid = frm->WidgetId();
00310 
00311       switch (wid) {
00312       case kHSr:
00313          fRGBA[fLMode * 4] = val / 100.f;
00314          break;
00315       case kHSg:
00316          fRGBA[fLMode * 4 + 1] = val / 100.f;
00317          break;
00318       case kHSb:
00319          fRGBA[fLMode * 4 + 2] = val / 100.f;
00320          break;
00321       case kHSa:
00322          fRGBA[fLMode * 4 + 3] = val / 100.f;
00323          break;
00324       case kHSs:
00325          fRGBA[16] = val;
00326          break;
00327       }
00328 
00329       fColorApplyButton->SetState(kButtonUp);
00330       fColorApplyFamily->SetState(kButtonUp);
00331       DrawSphere();
00332    }
00333 }
00334 
00335 //______________________________________________________________________________
00336 void TGLPShapeObjEditor::DoColorButton()
00337 {
00338    // Process button action.
00339 
00340    TGButton *btn = (TGButton *) gTQSender;
00341    Int_t id = btn->WidgetId();
00342 
00343    switch (id) {
00344    case kCPd:
00345       fLightTypes[fLMode]->SetState(kButtonUp);
00346       fLMode = kDiffuse;
00347       SetColorSlidersPos();
00348       break;
00349    case kCPa:
00350       fLightTypes[fLMode]->SetState(kButtonUp);
00351       fLMode = kAmbient;
00352       SetColorSlidersPos();
00353       break;
00354    case kCPs:
00355       fLightTypes[fLMode]->SetState(kButtonUp);
00356       fLMode = kSpecular;
00357       SetColorSlidersPos();
00358       break;
00359    case kCPe:
00360       fLightTypes[fLMode]->SetState(kButtonUp);
00361       fLMode = kEmission;
00362       SetColorSlidersPos();
00363       break;
00364    case kTBa:
00365       fColorApplyButton->SetState(kButtonDisabled);
00366       fColorApplyFamily->SetState(kButtonDisabled);
00367       if (fPShape) {
00368          fPShape->SetColor(GetRGBA());
00369       }
00370       fPShapeObj->fViewer->RequestDraw();
00371       break;
00372    case kTBaf:
00373       fColorApplyButton->SetState(kButtonDisabled);
00374       fColorApplyFamily->SetState(kButtonDisabled);
00375       if (fPShape) {
00376          fPShape->SetColorOnFamily(GetRGBA());
00377       }
00378       fPShapeObj->fViewer->RequestDraw();
00379       break;
00380    }
00381 }
00382 
00383 //______________________________________________________________________________
00384 void TGLPShapeObjEditor::CreateColorRadioButtons()
00385 {
00386    // Create Diffuse/Ambient/Specular/Emissive radio buttons and sub-frames.
00387 
00388    TGGroupFrame *partFrame = new TGGroupFrame(fColorFrame, "Color components:", kLHintsTop | kLHintsCenterX);
00389    fColorFrame->AddFrame(partFrame, new TGLayoutHints(kLHintsTop | kLHintsCenterX, 2, 0, 2, 2));
00390 
00391    partFrame->SetTitlePos(TGGroupFrame::kLeft);
00392    TGMatrixLayout *ml = new TGMatrixLayout(partFrame, 0, 1, 10);
00393    partFrame->SetLayoutManager(ml);
00394 
00395    // partFrame will delete the layout manager ml for us so don't add to fTrash
00396    fLightTypes[kDiffuse] = new TGRadioButton(partFrame, "Diffuse", kCPd);
00397    fLightTypes[kDiffuse]->Connect("Pressed()", "TGLPShapeObjEditor", this, "DoColorButton()");
00398    fLightTypes[kDiffuse]->SetToolTipText("Diffuse component of color");
00399    partFrame->AddFrame(fLightTypes[kDiffuse]);
00400 
00401    fLightTypes[kAmbient] = new TGRadioButton(partFrame, "Ambient", kCPa);
00402    fLightTypes[kAmbient]->Connect("Pressed()", "TGLPShapeObjEditor", this, "DoColorButton()");
00403    fLightTypes[kAmbient]->SetToolTipText("Ambient component of color");
00404    partFrame->AddFrame(fLightTypes[kAmbient]);
00405 
00406    fLightTypes[kSpecular] = new TGRadioButton(partFrame, "Specular", kCPs);
00407    fLightTypes[kSpecular]->Connect("Pressed()", "TGLPShapeObjEditor", this, "DoColorButton()");
00408    fLightTypes[kSpecular]->SetToolTipText("Specular component of color");
00409    partFrame->AddFrame(fLightTypes[kSpecular]);
00410 
00411    fLightTypes[kEmission] = new TGRadioButton(partFrame, "Emissive", kCPe);
00412    fLightTypes[kEmission]->Connect("Pressed()", "TGLPShapeObjEditor", this, "DoColorButton()");
00413    fLightTypes[kEmission]->SetToolTipText("Emissive component of color");
00414    partFrame->AddFrame(fLightTypes[kEmission]);
00415 
00416    fLMode = kDiffuse;
00417    fLightTypes[fLMode]->SetState(kButtonDown);
00418 }
00419 
00420 //______________________________________________________________________________
00421 void TGLPShapeObjEditor::CreateColorSliders()
00422 {
00423    // Create GUI for setting light color.
00424 
00425    UInt_t sw = 120; //fColorFrame->GetDefalutWidth();,
00426 
00427    // Create Red/Green/BlueAlpha/Shine sliders
00428    fColorFrame->AddFrame(new TGLabel(fColorFrame, "Red :"), new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 0, 0, 0));
00429    fRedSlider = new TGHSlider(fColorFrame, sw, kSlider1 | kScaleBoth, kHSr);
00430    fRedSlider->Connect("PositionChanged(Int_t)", "TGLPShapeObjEditor", this, "DoColorSlider(Int_t)");
00431    fRedSlider->SetRange(0, 100);
00432    fRedSlider->SetPosition(Int_t(fRGBA[0] * 100));
00433    fColorFrame->AddFrame(fRedSlider, new TGLayoutHints(fLs));
00434 
00435 
00436    fColorFrame->AddFrame(new TGLabel(fColorFrame, "Green :"), new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 0, 0, 0));
00437    fGreenSlider = new TGHSlider(fColorFrame, sw, kSlider1 | kScaleBoth, kHSg);
00438    fGreenSlider->Connect("PositionChanged(Int_t)", "TGLPShapeObjEditor", this, "DoColorSlider(Int_t)");
00439    fGreenSlider->SetRange(0, 100);
00440    fGreenSlider->SetPosition(Int_t(fRGBA[1] * 100));
00441    fColorFrame->AddFrame(fGreenSlider, new TGLayoutHints(fLs));
00442 
00443 
00444    fColorFrame->AddFrame(new TGLabel(fColorFrame, "Blue :"), new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 0, 0, 0));
00445    fBlueSlider = new TGHSlider(fColorFrame, sw, kSlider1 | kScaleBoth, kHSb);
00446    fBlueSlider->Connect("PositionChanged(Int_t)", "TGLPShapeObjEditor", this, "DoColorSlider(Int_t)");
00447    fBlueSlider->SetRange(0, 100);
00448    fBlueSlider->SetPosition(Int_t(fRGBA[2] * 100));
00449    fColorFrame->AddFrame(fBlueSlider, new TGLayoutHints(fLs));
00450 
00451    fColorFrame->AddFrame(new TGLabel(fColorFrame, "Shine :"), new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 0, 0, 0));
00452    fShineSlider = new TGHSlider(fColorFrame, sw, kSlider1 | kScaleBoth, kHSs);
00453    fShineSlider->Connect("PositionChanged(Int_t)", "TGLPShapeObjEditor", this, "DoColorSlider(Int_t)");
00454    fShineSlider->SetRange(0, 128);
00455    fColorFrame->AddFrame(fShineSlider, new TGLayoutHints(fLs));
00456 }
00457 
00458 //______________________________________________________________________________
00459 void TGLPShapeObjEditor::SetColorSlidersPos()
00460 {
00461    // Update GUI sliders from internal data.
00462 
00463    fRedSlider->SetPosition(Int_t(fRGBA[fLMode * 4] * 100));
00464    fGreenSlider->SetPosition(Int_t(fRGBA[fLMode * 4 + 1] * 100));
00465    fBlueSlider->SetPosition(Int_t(fRGBA[fLMode * 4 + 2] * 100));
00466    //   fAlphaSlider->SetPosition(Int_t(fRGBA[fLMode * 4 + 3] * 100));
00467 
00468    if (fRGBA[16] >= 0.f)
00469       fShineSlider->SetPosition(Int_t(fRGBA[16]));
00470 }
00471 
00472 //______________________________________________________________________________
00473 void TGLPShapeObjEditor::DoRedraw()
00474 {
00475    // Redraw widget. Render sphere and pass to base-class.
00476 
00477    DrawSphere();
00478    TGedFrame::DoRedraw();
00479 }
00480 
00481 //______________________________________________________________________________
00482 namespace {
00483 
00484    GLUquadric *GetQuadric()
00485    {
00486       // GLU quadric.
00487 
00488       static struct Init {
00489          Init()
00490          {
00491             fQuad = gluNewQuadric();
00492             if (!fQuad) {
00493                Error("GetQuadric::Init", "could not create quadric object");
00494             } else {
00495                gluQuadricOrientation(fQuad, (GLenum)GLU_OUTSIDE);
00496                gluQuadricDrawStyle(fQuad,   (GLenum)GLU_FILL);
00497                gluQuadricNormals(fQuad,     (GLenum)GLU_FLAT);
00498             }
00499          }
00500          ~Init()
00501          {
00502             if(fQuad)
00503                gluDeleteQuadric(fQuad);
00504          }
00505          GLUquadric *fQuad;
00506       }singleton;
00507 
00508       return singleton.fQuad;
00509    }
00510 
00511 }
00512 
00513 //______________________________________________________________________________
00514 void TGLPShapeObjEditor::DrawSphere()const
00515 {
00516    // Draw local sphere reflecting current color options.
00517 
00518    if (!gVirtualX->IsCmdThread()) {
00519       gROOT->ProcessLineFast(Form("((TGLPShapeObjEditor *)0x%lx)->DrawSphere()", (ULong_t)this));
00520       return;
00521    }
00522 
00523    fMatView->MakeCurrent();
00524    glViewport(0, 0, fMatView->GetWidth(), fMatView->GetHeight());
00525    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00526 
00527    glEnable(GL_LIGHTING);
00528    glEnable(GL_LIGHT0);
00529    glEnable(GL_DEPTH_TEST);
00530    glEnable(GL_CULL_FACE);
00531    glCullFace(GL_BACK);
00532    glMatrixMode(GL_PROJECTION);
00533    glLoadIdentity();
00534    glFrustum(-0.5, 0.5, -0.5, 0.5, 1., 10.);
00535    glMatrixMode(GL_MODELVIEW);
00536    glLoadIdentity();
00537    Float_t ligPos[] = {0.f, 0.f, 0.f, 1.f};
00538    glLightfv(GL_LIGHT0, GL_POSITION, ligPos);
00539    glTranslated(0., 0., -3.);
00540 
00541    const Float_t whiteColor[] = {1.f, 1.f, 1.f, 1.f};
00542    const Float_t nullColor[] = {0.f, 0.f, 0.f, 1.f};
00543 
00544    if (fRGBA[16] < 0.f) {
00545       glLightfv(GL_LIGHT0, GL_DIFFUSE, fRGBA);
00546       glLightfv(GL_LIGHT0, GL_AMBIENT, fRGBA + 4);
00547       glLightfv(GL_LIGHT0, GL_SPECULAR, fRGBA + 8);
00548       glMaterialfv(GL_FRONT, GL_DIFFUSE, whiteColor);
00549       glMaterialfv(GL_FRONT, GL_AMBIENT, nullColor);
00550       glMaterialfv(GL_FRONT, GL_SPECULAR, whiteColor);
00551       glMaterialfv(GL_FRONT, GL_EMISSION, nullColor);
00552       glMaterialf(GL_FRONT, GL_SHININESS, 60.f);
00553    } else {
00554       glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteColor);
00555       glLightfv(GL_LIGHT0, GL_AMBIENT, nullColor);
00556       glLightfv(GL_LIGHT0, GL_SPECULAR, whiteColor);
00557       glMaterialfv(GL_FRONT, GL_DIFFUSE, fRGBA);
00558       glMaterialfv(GL_FRONT, GL_AMBIENT, fRGBA + 4);
00559       glMaterialfv(GL_FRONT, GL_SPECULAR, fRGBA + 8);
00560       glMaterialfv(GL_FRONT, GL_EMISSION, fRGBA + 12);
00561       glMaterialf(GL_FRONT, GL_SHININESS, fRGBA[16]);
00562    }
00563 
00564    glEnable(GL_BLEND);
00565    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00566    GLUquadric * quad = GetQuadric();
00567    if (quad) {
00568       glRotated(-90., 1., 0., 0.);
00569       gluSphere(quad, 1., 100, 100);
00570    }
00571    glDisable(GL_BLEND);
00572 
00573    fMatView->SwapBuffers();
00574 }
00575 
00576 //______________________________________________________________________________
00577 void TGLPShapeObjEditor::CreateColorControls()
00578 {
00579    // Create widgets to chhos colors componnet and its RGBA values on fGedEditor
00580    // model or family it belongs to.
00581 
00582    fColorFrame = this;
00583 
00584    fMatView = TGLWidget::Create(fColorFrame, kFALSE, kTRUE, 0, 120, 120);
00585    fColorFrame->AddFrame(fMatView, new TGLayoutHints(kLHintsTop | kLHintsCenterX, 2, 0, 2, 2));
00586 
00587    CreateColorRadioButtons();
00588 
00589    CreateColorSliders();
00590 
00591    //apply button creation
00592    fColorApplyButton = new TGTextButton(fColorFrame, "Apply", kTBa);
00593    fColorFrame->AddFrame(fColorApplyButton, new TGLayoutHints(fLb));
00594    fColorApplyButton->SetState(kButtonDisabled);
00595    fColorApplyButton->Connect("Pressed()", "TGLPShapeObjEditor", this, "DoColorButton()");
00596    //apply to family button creation
00597    fColorApplyFamily = new TGTextButton(fColorFrame, "Apply to family", kTBaf);
00598    fColorFrame->AddFrame(fColorApplyFamily, new TGLayoutHints(fLb));
00599    fColorApplyFamily->SetState(kButtonDisabled);
00600    fColorApplyFamily->Connect("Pressed()", "TGLPShapeObjEditor", this, "DoColorButton()");
00601 }

Generated on Tue Jul 5 14:18:08 2011 for ROOT_528-00b_version by  doxygen 1.5.1