Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:35

0001 #include "Fireworks/Core/src/FW3DViewDistanceMeasureTool.h"
0002 #include "TGFrame.h"
0003 #include "TGButton.h"
0004 #include "TGLabel.h"
0005 #include "TG3DLine.h"
0006 
0007 namespace {
0008   const char* lbpformat = "(%.2f, %.2f, %.2f)";
0009 }
0010 
0011 FW3DViewDistanceMeasureTool::FW3DViewDistanceMeasureTool()
0012     : m_action(kNone), m_bp1(nullptr), m_bp2(nullptr), m_lp1(nullptr), m_lp2(nullptr), m_ldist(nullptr) {}
0013 
0014 void FW3DViewDistanceMeasureTool::Print() const {
0015   printf("==============================================\n");
0016   m_pnt1.Dump();
0017   m_pnt2.Dump();
0018   TGLVector3 a = m_pnt1 - m_pnt2;
0019   printf("Distance:\n%f \n", a.Mag());
0020 }
0021 
0022 void FW3DViewDistanceMeasureTool::resetAction() {
0023   // printf("Reset ACTION !!!! \n");
0024   m_action = kNone;
0025   m_bp1->SetState(kButtonUp);
0026   m_lp1->SetText(Form(lbpformat, m_pnt1.X(), m_pnt1.Y(), m_pnt1.Z()));
0027 
0028   m_bp2->SetState(kButtonUp);
0029   m_lp2->SetText(Form(lbpformat, m_pnt2.X(), m_pnt2.Y(), m_pnt2.Z()));
0030 
0031   TGLVector3 d = m_pnt2 - m_pnt1;
0032   m_ldist->SetText(Form("%.2f", d.Mag()));
0033 
0034   {
0035     TGCompositeFrame* p = (TGCompositeFrame*)(m_ldist->GetParent());
0036     p->Resize(p->GetDefaultSize());
0037   }
0038   {
0039     TGCompositeFrame* p = (TGCompositeFrame*)(m_ldist->GetParent()->GetParent());
0040     p->Layout();
0041   }
0042 }
0043 
0044 void FW3DViewDistanceMeasureTool::setActionPnt1() {
0045   // printf("Action ! 1111 \n");
0046   m_action = kPnt1;
0047   m_bp1->SetState(kButtonEngaged);
0048   m_bp2->SetState(kButtonUp);
0049 }
0050 
0051 void FW3DViewDistanceMeasureTool::setActionPnt2() {
0052   // printf("Action ! 222 \n");
0053   m_action = kPnt2;
0054   m_bp2->SetState(kButtonEngaged);
0055   m_bp1->SetState(kButtonUp);
0056 }
0057 
0058 TGLVector3& FW3DViewDistanceMeasureTool::refCurrentVertex() {
0059   //assert (m_action != kNone);
0060   if (m_action == kNone) {
0061     printf("ERROR refCurrentVertex m_action == kNone \n");
0062     return m_pnt1;
0063   }
0064   if (m_action == kPnt1)
0065     return m_pnt1;
0066   else
0067     return m_pnt2;
0068 }
0069 
0070 TGCompositeFrame* FW3DViewDistanceMeasureTool::buildGUI(TGCompositeFrame* p) {
0071   TGVerticalFrame* vf = new TGVerticalFrame(p);
0072 
0073   {
0074     TGHorizontalFrame* hf = new TGHorizontalFrame(vf);
0075     TGLabel* lb = new TGLabel(hf, "Distance: ");
0076     hf->AddFrame(lb);
0077     m_ldist = new TGLabel(hf, " --- ");
0078     hf->AddFrame(m_ldist);
0079     vf->AddFrame(hf);
0080   }
0081   {
0082     TGHorizontalFrame* hf = new TGHorizontalFrame(vf);
0083 
0084     m_bp1 = new TGTextButton(hf, "Pick Point1");
0085     m_bp1->Connect("Clicked()", "FW3DViewDistanceMeasureTool", this, "setActionPnt1()");
0086     m_bp1->SetToolTipText("Click on the butto to pick the first point in viewer.");
0087     hf->AddFrame(m_bp1, new TGLayoutHints(kLHintsNormal, 0, 5, 4, 4));
0088 
0089     m_lp1 = new TGLabel(hf, Form(lbpformat, m_pnt1.X(), m_pnt1.Y(), m_pnt1.Z()));
0090     hf->AddFrame(m_lp1, new TGLayoutHints(kLHintsNormal, 0, 1, 4, 4));
0091 
0092     vf->AddFrame(hf);
0093   }
0094 
0095   {
0096     TGHorizontalFrame* hf = new TGHorizontalFrame(vf);
0097 
0098     m_bp2 = new TGTextButton(hf, "Pick Point2");
0099     m_bp2->Connect("Clicked()", "FW3DViewDistanceMeasureTool", this, "setActionPnt2()");
0100     m_bp2->SetToolTipText("Click on the butto to pick the secoond point in viewer.");
0101     hf->AddFrame(m_bp2, new TGLayoutHints(kLHintsExpandX, 0, 5, 4, 4));
0102 
0103     m_lp2 = new TGLabel(hf, Form(lbpformat, m_pnt2.X(), m_pnt2.Y(), m_pnt2.Z()));
0104     hf->AddFrame(m_lp2, new TGLayoutHints(kLHintsNormal, 0, 1, 4, 4));
0105 
0106     vf->AddFrame(hf);
0107   }
0108 
0109   {
0110     TGHorizontalFrame* hf = new TGHorizontalFrame(vf);
0111     TGTextButton* b = new TGTextButton(hf, "Print distance to terminal");
0112     b->Connect("Clicked()", "FW3DViewDistanceMeasureTool", this, "Print()");
0113     hf->AddFrame(b, new TGLayoutHints(kLHintsNormal, 0, 5, 4, 4));
0114     vf->AddFrame(hf);
0115   }
0116   return vf;
0117 }