00001 #include "Fireworks/Core/src/FW3DViewDistanceMeasureTool.h"
00002 #include "TGFrame.h"
00003 #include "TGButton.h"
00004 #include "TGLabel.h"
00005 #include "TG3DLine.h"
00006
00007 namespace {
00008 const char * lbpformat="(%.2f, %.2f, %.2f)";
00009 }
00010
00011 FW3DViewDistanceMeasureTool::FW3DViewDistanceMeasureTool():
00012 m_action(kNone), m_bp1(0), m_bp2(0),
00013 m_lp1(0), m_lp2(0), m_ldist(0)
00014 {
00015 }
00016
00017 void FW3DViewDistanceMeasureTool::Print() const
00018 {
00019 printf("==============================================\n");
00020 m_pnt1.Dump();
00021 m_pnt2.Dump();
00022 TGLVector3 a = m_pnt1 - m_pnt2;
00023 printf("Distance:\n%f \n", a.Mag());
00024 }
00025
00026 void FW3DViewDistanceMeasureTool::resetAction()
00027 {
00028
00029 m_action = kNone;
00030 m_bp1->SetState(kButtonUp);
00031 m_lp1->SetText( Form(lbpformat, m_pnt1.X(), m_pnt1.Y(), m_pnt1.Z()));
00032
00033 m_bp2->SetState(kButtonUp);
00034 m_lp2->SetText( Form(lbpformat, m_pnt2.X(), m_pnt2.Y(), m_pnt2.Z()));
00035
00036 TGLVector3 d = m_pnt2 - m_pnt1;
00037 m_ldist->SetText(Form("%.2f", d.Mag()));
00038
00039 {
00040 TGCompositeFrame* p = (TGCompositeFrame*)(m_ldist->GetParent());
00041 p->Resize(p->GetDefaultSize());
00042 }
00043 {
00044 TGCompositeFrame* p = (TGCompositeFrame*)(m_ldist->GetParent()->GetParent());
00045 p->Layout();
00046 }
00047 }
00048
00049 void FW3DViewDistanceMeasureTool::setActionPnt1()
00050 {
00051
00052 m_action = kPnt1;
00053 m_bp1->SetState(kButtonEngaged);
00054 m_bp2->SetState(kButtonUp);
00055 }
00056
00057 void FW3DViewDistanceMeasureTool::setActionPnt2()
00058 {
00059
00060 m_action = kPnt2;
00061 m_bp2->SetState(kButtonEngaged);
00062 m_bp1->SetState(kButtonUp);
00063 }
00064
00065 TGLVector3& FW3DViewDistanceMeasureTool::refCurrentVertex()
00066 {
00067
00068 if (m_action == kNone) {
00069 printf("ERROR refCurrentVertex m_action == kNone \n");
00070 return m_pnt1 ;
00071 }
00072 if (m_action == kPnt1)
00073 return m_pnt1;
00074 else
00075 return m_pnt2;
00076
00077 }
00078
00079 TGCompositeFrame* FW3DViewDistanceMeasureTool::buildGUI(TGCompositeFrame* p)
00080 {
00081 TGVerticalFrame* vf = new TGVerticalFrame(p);
00082
00083 {
00084 TGHorizontalFrame* hf = new TGHorizontalFrame(vf);
00085 TGLabel* lb = new TGLabel(hf, "Distance: ");
00086 hf->AddFrame(lb);
00087 m_ldist = new TGLabel(hf, " --- ");
00088 hf->AddFrame(m_ldist);
00089 vf->AddFrame(hf);
00090 }
00091 {
00092 TGHorizontalFrame* hf = new TGHorizontalFrame(vf);
00093
00094 m_bp1 = new TGTextButton(hf, "Pick Point1");
00095 m_bp1->Connect("Clicked()", "FW3DViewDistanceMeasureTool", this, "setActionPnt1()");
00096 m_bp1->SetToolTipText("Click on the butto to pick the first point in viewer.");
00097 hf->AddFrame( m_bp1, new TGLayoutHints(kLHintsNormal, 0, 5, 4, 4));
00098
00099 m_lp1 = new TGLabel(hf, Form(lbpformat, m_pnt1.X(), m_pnt1.Y(), m_pnt1.Z()));
00100 hf->AddFrame(m_lp1, new TGLayoutHints(kLHintsNormal, 0, 1, 4, 4));
00101
00102 vf->AddFrame(hf);
00103 }
00104
00105 {
00106 TGHorizontalFrame* hf = new TGHorizontalFrame(vf);
00107
00108 m_bp2 = new TGTextButton(hf, "Pick Point2");
00109 m_bp2->Connect("Clicked()", "FW3DViewDistanceMeasureTool", this, "setActionPnt2()");
00110 m_bp2->SetToolTipText("Click on the butto to pick the secoond point in viewer.");
00111 hf->AddFrame( m_bp2, new TGLayoutHints(kLHintsExpandX, 0, 5, 4, 4));
00112
00113 m_lp2 = new TGLabel(hf, Form(lbpformat, m_pnt2.X(), m_pnt2.Y(), m_pnt2.Z()));
00114 hf->AddFrame(m_lp2, new TGLayoutHints(kLHintsNormal, 0, 1, 4, 4));
00115
00116 vf->AddFrame(hf);
00117 }
00118
00119 {
00120 TGHorizontalFrame* hf = new TGHorizontalFrame(vf);
00121 TGTextButton* b = new TGTextButton(hf, "Print distance to terminal");
00122 b->Connect("Clicked()", "FW3DViewDistanceMeasureTool", this, "Print()");
00123 hf->AddFrame(b, new TGLayoutHints(kLHintsNormal, 0, 5, 4, 4));
00124 vf->AddFrame(hf);
00125 }
00126 return vf;
00127
00128 }