-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNodePropertyPage.cpp
103 lines (82 loc) · 2.98 KB
/
NodePropertyPage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "stdafx.h"
#include "NodePropertyPage.h"
#include "WorldFrame.h"
#include "WorldNode.h"
#include <wx/toolbar.h>
#include <wx/propgrid/advprops.h>
// Required for WX
IMPLEMENT_CLASS(NodePropertyPage, wxPropertyGridPage)
// Portion of an imaginary event table
BEGIN_EVENT_TABLE(NodePropertyPage, wxPropertyGridPage)
// This occurs when a property value changes
EVT_PG_CHANGED(wxID_ANY, NodePropertyPage::OnPropertyGridChange)
END_EVENT_TABLE()
//BEGIN_EVENT_TABLE(wxMyPropertyGridPage, wxPropertyGridPage)
// EVT_PG_SELECTED(wxID_ANY, wxMyPropertyGridPage::OnPropertySelect)
// EVT_PG_CHANGED(wxID_ANY, wxMyPropertyGridPage::OnPropertyChange)
// EVT_PG_PAGE_CHANGED(wxID_ANY, wxMyPropertyGridPage::OnPageChange)
//END_EVENT_TABLE()
NodePropertyPage::NodePropertyPage(WorldFrame* wf)
: wxPropertyGridPage()
{
_worldFrame = wf;
}
void NodePropertyPage::OnPropertyGridChange(wxPropertyGridEvent& event)
{
//const wxId& id = event.GetId();
const wxPGProperty* eventProp = event.GetPropertyPtr();
if((eventProp == _xProp) || (eventProp == _yProp) || (eventProp == _zProp)
|| (eventProp == _labelProp))
{
WorldNode* wn = _worldFrame->getSelectedNode();
if(wn)
{
//wn->setLabel(GetPropertyValueAsString(labelProp));
wn->setPosition2D(GetPropertyValueAsDouble(_xProp), GetPropertyValueAsDouble(_zProp));
std::string s(_C(GetPropertyValueAsString(_labelProp)));
wn->setLabel(s);
update();
_worldFrame->Refresh();
}
}
// Get resulting value - wxVariant is convenient here.
wxVariant value = event.GetPropertyValue();
}
void NodePropertyPage::Init()
{
Append(wxPropertyCategory(wxT("Main")));
//Add some properties just to test this out
_labelProp = Append(wxStringProperty(wxT("Label"),wxT("Name"),wxT("Node x")));
// Add a bool property
Append(wxBoolProperty(wxT("Selected"), wxPG_LABEL, true));
// Colour property with arbitrary colour.
Append(wxColourProperty(wxT("Node Colour"),
wxPG_LABEL,
wxColour(200,0,0)));
Append(wxPropertyCategory(wxT("Position")));
// Add float property (value type is actually double)
_xProp = Append(wxFloatProperty(wxT("x (m)"), wxPG_LABEL, 0.0));
_yProp = Append(wxFloatProperty(wxT("y (m)"), wxPG_LABEL, 0.0));
_zProp = Append(wxFloatProperty(wxT("z (m)"), wxPG_LABEL, 0.0));
Append(wxPropertyCategory(wxT("Extra")));
}
void NodePropertyPage::update()
{
//get data from worldframe
Ogre::Vector3 nodePos(Ogre::Vector3::ZERO);
Ogre::String label;
WorldNode* wn = _worldFrame->getSelectedNode();
if(wn != 0)
{
nodePos = wn->getPosition3D();
label = wn->getLabel();
}
SetPropertyValue(_labelProp, wxString(label.c_str(), wxConvUTF8));
SetPropertyValue(_xProp, nodePos.x);
SetPropertyValue(_yProp, nodePos.y);
SetPropertyValue(_zProp, nodePos.z);
RefreshProperty(_labelProp);
RefreshProperty(_xProp);
RefreshProperty(_yProp);
RefreshProperty(_zProp);
}