1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #include "PropertiesPanel.h"
29 
30 #include <boost/any.hpp>
31 #include <boost/bind.hpp>
32 
33 #include <wx/button.h>
34 #include <wx/dcclient.h>
35 #include <wx/scrolwin.h>
36 #include <wx/sizer.h>
37 #include <wx/stattext.h>
38 #include <wx/toolbar.h>
39 #include <wx/propgrid/manager.h>
40 #include <wx/propgrid/advprops.h>
41 
42 #include "OgreMaterial.h"
43 #include "OgreMaterialManager.h"
44 #include "OgrePass.h"
45 #include "OgreTechnique.h"
46 
47 #include "EventArgs.h"
48 #include "MaterialController.h"
49 #include "MaterialEventArgs.h"
50 #include "MaterialPropertyGridPage.h"
51 #include "MaterialWizard.h"
52 #include "PassController.h"
53 #include "PassPropertyGridPage.h"
54 #include "Project.h"
55 #include "ProjectEventArgs.h"
56 #include "ProjectWizard.h"
57 #include "PassPropertyGridPage.h"
58 #include "SelectionEventArgs.h"
59 #include "SelectionService.h"
60 #include "TechniqueController.h"
61 #include "TechniqueEventArgs.h"
62 #include "TechniquePropertyGridPage.h"
63 #include "TechniqueWizard.h"
64 #include "Workspace.h"
65 #include "WorkspaceEventArgs.h"
66 
BEGIN_EVENT_TABLE(PropertiesPanel,wxPanel)67 BEGIN_EVENT_TABLE(PropertiesPanel, wxPanel)
68 END_EVENT_TABLE()
69 
70 PropertiesPanel::PropertiesPanel(wxWindow* parent,
71 							   wxWindowID id /* = wxID_ANY */,
72 							   const wxPoint& pos /* = wxDefaultPosition */,
73 							   const wxSize& size /* = wxDefaultSize */,
74 							   long style /* = wxTAB_TRAVERSAL | wxNO_BORDER */,
75 							   const wxString& name /* = wxT("Workspace Panel")) */)
76 							   : wxPanel(parent, id, pos, size, style, name)
77 {
78 	mGridSizer = new wxGridSizer(1, 1, 0, 0);
79 
80 	mPropertyGrid = new wxPropertyGridManager(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
81 		wxPG_BOLD_MODIFIED | wxPG_SPLITTER_AUTO_CENTER | wxPG_DESCRIPTION | wxPGMAN_DEFAULT_STYLE);
82 
83 	// Adding a page sets target page to the one added, so
84 	// we don't have to call SetTargetPage if we are filling
85 	// it right after adding.
86 	//MaterialController* controller = new MaterialController((MaterialPtr)MaterialManager::getSingletonPtr()->create("Test", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME));
87 	//TechniqueController* tc = controller->createTechnique();
88 	//PassController* pc = tc->createPass();
89 	//PassPropertyGridPage* page = new PassPropertyGridPage(pc);
90 	//TechniquePropertyGridPage* page = new TechniquePropertyGridPage(tc);
91 	//MaterialPropertyGridPage* page = new MaterialPropertyGridPage(controller);
92 	//mPropertyGrid->AddPage(wxEmptyString, wxPG_NULL_BITMAP, page);
93 	//page->populate();
94 
95 	// For total safety, finally reset the target page.
96 	//mPropertyGrid->SetTargetPage(0);
97 
98 	mGridSizer->Add(mPropertyGrid, 0, wxALL | wxEXPAND, 0);
99 
100 	SetSizer(mGridSizer);
101 	Layout();
102 
103 	SelectionService::getSingletonPtr()->subscribe(SelectionService::SelectionChanged, boost::bind(&PropertiesPanel::selectionChanged, this, _1));
104 	Workspace::getSingletonPtr()->subscribe(Workspace::ProjectRemoved, boost::bind(&PropertiesPanel::projectRemoved, this, _1));
105 }
106 
~PropertiesPanel()107 PropertiesPanel::~PropertiesPanel()
108 {
109 }
110 
selectionChanged(EventArgs & args)111 void PropertiesPanel::selectionChanged(EventArgs& args)
112 {
113 	SelectionEventArgs sea = dynamic_cast<SelectionEventArgs&>(args);
114 	SelectionList selection = sea.getSelection();
115 	if(!selection.empty())
116 	{
117 		boost::any sel = selection.front();
118 		if(sel.type() == typeid(Project))
119 		{
120 		}
121 		else if(sel.type() == typeid(MaterialController*))
122 		{
123 			MaterialController* mc = any_cast<MaterialController*>(sel);
124 
125 			MaterialPageIndexMap::iterator it = mMaterialPageIndexMap.find(mc);
126 			if(it != mMaterialPageIndexMap.end())
127 			{
128 				int index = mMaterialPageIndexMap[mc];
129 				mPropertyGrid->SelectPage(index);
130 			}
131 			else
132 			{
133 				MaterialPropertyGridPage* page = new MaterialPropertyGridPage(mc);
134 
135 				int index = mPropertyGrid->AddPage(wxEmptyString, wxPG_NULL_BITMAP, page);
136 				page->populate();
137 
138 				mMaterialPageIndexMap[mc] = index;
139 
140 				mPropertyGrid->SelectPage(index);
141 			}
142 		}
143 		else if(sel.type() == typeid(TechniqueController*))
144 		{
145 			TechniqueController* tc = any_cast<TechniqueController*>(sel);
146 
147 			TechniquePageIndexMap::iterator it = mTechniquePageIndexMap.find(tc);
148 			if(it != mTechniquePageIndexMap.end())
149 			{
150 				int index = mTechniquePageIndexMap[tc];
151 				mPropertyGrid->SelectPage(index);
152 			}
153 			else
154 			{
155 				TechniquePropertyGridPage* page = new TechniquePropertyGridPage(tc);
156 
157 				int index = mPropertyGrid->AddPage(wxEmptyString, wxPG_NULL_BITMAP, page);
158 				page->populate();
159 
160 				mTechniquePageIndexMap[tc] = index;
161 
162 				mPropertyGrid->SelectPage(index);
163 			}
164 		}
165 		else if(sel.type() == typeid(PassController*))
166 		{
167 			PassController* pc = any_cast<PassController*>(sel);
168 
169 			PassPageIndexMap::iterator it = mPassPageIndexMap.find(pc);
170 			if(it != mPassPageIndexMap.end())
171 			{
172 				int index = mPassPageIndexMap[pc];
173 				mPropertyGrid->SelectPage(index);
174 			}
175 			else
176 			{
177 				PassPropertyGridPage* page = new PassPropertyGridPage(pc);
178 
179 				int index = mPropertyGrid->AddPage(wxEmptyString, wxPG_NULL_BITMAP, page);
180 				page->populate();
181 
182 				mPassPageIndexMap[pc] = index;
183 
184 				mPropertyGrid->SelectPage(index);
185 			}
186 		}
187 
188 		mPropertyGrid->Refresh();
189 	}
190 }
191 
projectRemoved(EventArgs & args)192 void PropertiesPanel::projectRemoved(EventArgs& args)
193 {
194 	// Consider: Should this method also attempt to remove all
195 	//           of the page associated with this Projects,
196 	//           Materials, Techniques, and Passes?
197 }
198 
materialRemoved(EventArgs & args)199 void PropertiesPanel::materialRemoved(EventArgs& args)
200 {
201 	// Consider: Should this method also attempt to remove all
202 	//           of the page associated with this Materials, Techniques,
203 	//           and Passes?
204 
205 	ProjectEventArgs pea = dynamic_cast<ProjectEventArgs&>(args);
206 	MaterialController* mc = pea.getMaterial();
207 
208 	MaterialPageIndexMap::iterator it = mMaterialPageIndexMap.find(mc);
209 	if(it != mMaterialPageIndexMap.end())
210 	{
211 		mPropertyGrid->RemovePage(mMaterialPageIndexMap[mc]);
212 		mMaterialPageIndexMap.erase(it);
213 	}
214 }
215 
techniqueRemoved(EventArgs & args)216 void PropertiesPanel::techniqueRemoved(EventArgs& args)
217 {
218 	// Consider: Should this method also attempt to remove all
219 	//           of the page associated with this Techniques, Passes?
220 
221 	MaterialEventArgs mea = dynamic_cast<MaterialEventArgs&>(args);
222 	TechniqueController* tc = mea.getTechniqueController();
223 
224 	TechniquePageIndexMap::iterator it = mTechniquePageIndexMap.find(tc);
225 	if(it != mTechniquePageIndexMap.end())
226 	{
227 		mPropertyGrid->RemovePage(mTechniquePageIndexMap[tc]);
228 		mTechniquePageIndexMap.erase(it);
229 	}
230 }
231 
passRemoved(EventArgs & args)232 void PropertiesPanel::passRemoved(EventArgs& args)
233 {
234 	TechniqueEventArgs tea = dynamic_cast<TechniqueEventArgs&>(args);
235 	PassController* pc = tea.getPassController();
236 
237 	PassPageIndexMap::iterator it = mPassPageIndexMap.find(pc);
238 	if(it != mPassPageIndexMap.end())
239 	{
240 		mPropertyGrid->RemovePage(mPassPageIndexMap[pc]);
241 		mPassPageIndexMap.erase(it);
242 	}
243 }
244