/[Sims3RigEditor]/trunk/gr2lib_cpp/gr2lib_rigeditor_frm.h
ViewVC logotype

Contents of /trunk/gr2lib_cpp/gr2lib_rigeditor_frm.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 15 - (show annotations) (download)
Sun Aug 1 02:44:09 2010 UTC (9 years, 6 months ago) by william
File MIME type: text/plain
File size: 13425 byte(s)
Add Property Wrapper for displaying Granny2 Rig data in property grid

1 #pragma once
2 //#include "gr2lib_core.h"
3 //#include "gr2lib_core_imports.h"
4 #ifndef GR2LIB_RIGEDITOR_FRM_H
5 #define GR2LIB_RIGEDITOR_FRM_H
6 #include "grannyfile.h"
7 //#include "guicon.h"
8 #include <stdio.h>
9 #include <iostream>
10 #include <stdlib.h>
11 #include <assert.h>
12 #include <string>
13 #include <sstream>
14 #include <vcclr.h>
15 using namespace std;
16
17 using namespace gr2lib::core;
18 using namespace gr2lib::core::coretypes::implementation;
19 using namespace gr2lib::core::apiversion;
20 using namespace System;
21 using namespace System::ComponentModel;
22 using namespace System::Collections;
23 using namespace System::Collections::Generic;
24 using namespace System::Windows::Forms;
25 using namespace System::Data;
26 using namespace System::Drawing;
27 using namespace System::Runtime::InteropServices;
28 //
29 //namespace gr2lib
30 //{
31 // namespace core
32 // {
33 // namespace rigeditor
34 // {
35 /// <summary>
36 /// Summary for gr2lib_rigeditor_frm
37 ///
38 /// WARNING: If you change the name of this class, you will need to change the
39 /// 'Resource File Name' property for the managed resource compiler tool
40 /// associated with all .resx files this class depends on. Otherwise,
41 /// the designers will not be able to interact properly with localized
42 /// resources associated with this form.
43 /// </summary>
44 public ref class gr2lib_rigeditor_frm : public System::Windows::Forms::Form
45 {
46 private:
47 grannyfile* _grn_file;
48 void LogApplicationStartup()
49 {
50 const char* ApplicationName = "GR2Lib Rig Editor: ";
51
52 const char* product_version = (char*)(void*)Marshal::StringToHGlobalAnsi(Application::ProductVersion);
53 const char* version_prefix = "v";
54 const char* startup_string = " {Starting up...}";
55
56
57 int msg_malloc = (strlen(ApplicationName) + strlen(product_version) + strlen(version_prefix) + strlen(startup_string)) + 3;
58
59 char* msg = (char*)malloc(msg_malloc);
60 for (int i=0; i<msg_malloc; i++) {
61 msg[i] = 0; // Initialize all elements to zero.
62 }
63
64 strcat(msg,ApplicationName);
65 strcat(msg,version_prefix);
66 strcat(msg,product_version);
67 strcat(msg,startup_string);
68 strcat(msg,"\n");
69 _grn_file->_logger->LogMessage(msg);
70 }
71 public:
72 gr2lib_rigeditor_frm(void)
73 {
74 InitializeComponent();
75 _grn_file = new grannyfile();
76 //
77 //TODO: Add the constructor code here
78 //
79 // Log Application Startup
80 LogApplicationStartup();
81 }
82 gr2lib_rigeditor_frm(grannyfile* grn_file)
83 {
84 InitializeComponent();
85 // parse art tool info
86 _grn_file = grn_file;
87
88 // Log Application Startup
89 LogApplicationStartup();
90
91 this->GR2LibPropertyWrapper = gcnew GR2LibWrapper();
92 ConvertToManaged();
93 propgrid->SelectedObject = this->GR2LibPropertyWrapper;
94
95 }
96
97 protected:
98 /// <summary>
99 /// Clean up any resources being used.
100 /// </summary>
101 ~gr2lib_rigeditor_frm()
102 {
103 if (components)
104 {
105 delete components;
106 }
107 }
108 private: System::Windows::Forms::PropertyGrid^ propgrid;
109 protected:
110 private: System::Windows::Forms::MenuStrip^ mainmenu;
111 private: System::Windows::Forms::ToolStripMenuItem^ mnuFile;
112 private: System::Windows::Forms::ToolStripMenuItem^ mnuItemExit;
113 private: System::Windows::Forms::ToolStripMenuItem^ mnuItemOpen;
114 private: System::Windows::Forms::ToolStripMenuItem^ mnuItemSave;
115 private: System::Windows::Forms::ToolStripMenuItem^ mnuItemSaveAs;
116
117 protected:
118
119 private:
120 /// <summary>
121 /// Required designer variable.
122 /// </summary>
123 System::ComponentModel::Container ^components;
124
125 #pragma region Windows Form Designer generated code
126 /// <summary>
127 /// Required method for Designer support - do not modify
128 /// the contents of this method with the code editor.
129 /// </summary>
130 void InitializeComponent(void)
131 {
132 this->propgrid = (gcnew System::Windows::Forms::PropertyGrid());
133 this->mainmenu = (gcnew System::Windows::Forms::MenuStrip());
134 this->mnuFile = (gcnew System::Windows::Forms::ToolStripMenuItem());
135 this->mnuItemOpen = (gcnew System::Windows::Forms::ToolStripMenuItem());
136 this->mnuItemSave = (gcnew System::Windows::Forms::ToolStripMenuItem());
137 this->mnuItemSaveAs = (gcnew System::Windows::Forms::ToolStripMenuItem());
138 this->mnuItemExit = (gcnew System::Windows::Forms::ToolStripMenuItem());
139 this->mainmenu->SuspendLayout();
140 this->SuspendLayout();
141 //
142 // propgrid
143 //
144 this->propgrid->Dock = System::Windows::Forms::DockStyle::Fill;
145 this->propgrid->Location = System::Drawing::Point(0, 24);
146 this->propgrid->Name = L"propgrid";
147 this->propgrid->PropertySort = System::Windows::Forms::PropertySort::NoSort;
148 this->propgrid->Size = System::Drawing::Size(558, 456);
149 this->propgrid->TabIndex = 4;
150 this->propgrid->ToolbarVisible = false;
151 //
152 // mainmenu
153 //
154 this->mainmenu->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->mnuFile});
155 this->mainmenu->Location = System::Drawing::Point(0, 0);
156 this->mainmenu->Name = L"mainmenu";
157 this->mainmenu->Size = System::Drawing::Size(558, 24);
158 this->mainmenu->TabIndex = 3;
159 this->mainmenu->Text = L"menuStrip1";
160 //
161 // mnuFile
162 //
163 this->mnuFile->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(4) {this->mnuItemOpen,
164 this->mnuItemSave, this->mnuItemSaveAs, this->mnuItemExit});
165 this->mnuFile->Name = L"mnuFile";
166 this->mnuFile->Size = System::Drawing::Size(37, 20);
167 this->mnuFile->Text = L"&File";
168 //
169 // mnuItemOpen
170 //
171 this->mnuItemOpen->Name = L"mnuItemOpen";
172 this->mnuItemOpen->Size = System::Drawing::Size(114, 22);
173 this->mnuItemOpen->Text = L"&Open";
174 this->mnuItemOpen->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemOpen_Click);
175 //
176 // mnuItemSave
177 //
178 this->mnuItemSave->Name = L"mnuItemSave";
179 this->mnuItemSave->Size = System::Drawing::Size(114, 22);
180 this->mnuItemSave->Text = L"&Save";
181 //
182 // mnuItemSaveAs
183 //
184 this->mnuItemSaveAs->Name = L"mnuItemSaveAs";
185 this->mnuItemSaveAs->Size = System::Drawing::Size(114, 22);
186 this->mnuItemSaveAs->Text = L"Save &As";
187 //
188 // mnuItemExit
189 //
190 this->mnuItemExit->Name = L"mnuItemExit";
191 this->mnuItemExit->Size = System::Drawing::Size(114, 22);
192 this->mnuItemExit->Text = L"&Exit";
193 this->mnuItemExit->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemExit_Click);
194 //
195 // gr2lib_rigeditor_frm
196 //
197 this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
198 this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
199 this->ClientSize = System::Drawing::Size(558, 480);
200 this->Controls->Add(this->propgrid);
201 this->Controls->Add(this->mainmenu);
202 this->Name = L"gr2lib_rigeditor_frm";
203 this->Text = L"gr2lib_rigeditor_frm";
204 this->FormClosed += gcnew System::Windows::Forms::FormClosedEventHandler(this, &gr2lib_rigeditor_frm::gr2lib_rigeditor_frm_FormClosed);
205 this->mainmenu->ResumeLayout(false);
206 this->mainmenu->PerformLayout();
207 this->ResumeLayout(false);
208 this->PerformLayout();
209
210 }
211 #pragma endregion
212 #pragma region MarshalToMananaged
213 //ArtToolInfo^ _ArtToolInfo;
214 //ExporterInfo^ _ExporterInfo;
215 GR2LibWrapper^ GR2LibPropertyWrapper;
216
217 #pragma region ManagedNativeParsing
218 void ConvertToManaged()
219 {
220 // Art Tool info
221 ArtToolInfo_ToManaged(_grn_file->GrannyFileInfo->ArtToolInfo);
222 // Exporter Info
223 ExporterInfo_ToManaged(_grn_file->GrannyFileInfo->ExporterInfo);
224 }
225 void ConvertToNative()
226 {
227 // Art Tool info
228 ArtToolInfo_ToNative();
229 // Exporter Info
230 ExporterInfo_ToNative();
231 }
232 #pragma endregion
233
234 #pragma region ArtToolInfo_ToManaged
235 void ArtToolInfo_ToManaged(granny_art_tool_info* toolinfo)
236 {
237 //GR2LibPropertyWrapper->ArtToolInfo = gcnew ArtToolInfo();
238 // Tool Name
239 GR2LibPropertyWrapper->ArtToolInfo->FromArtToolName = gcnew String(reinterpret_cast<const char*>(toolinfo->FromArtToolName));
240
241 // Tool Vector
242 Vector3* Origin = new Vector3(
243 toolinfo->Origin[0],
244 toolinfo->Origin[1],
245 toolinfo->Origin[2]);
246 Vector3* Right = new Vector3(
247 toolinfo->RightVector[0],
248 toolinfo->RightVector[1],
249 toolinfo->RightVector[2]);
250 Vector3* Up = new Vector3(
251 toolinfo->UpVector[0],
252 toolinfo->UpVector[1],
253 toolinfo->UpVector[2]);
254 Vector3* Back = new Vector3(
255 toolinfo->BackVector[0],
256 toolinfo->BackVector[1],
257 toolinfo->BackVector[2]);
258 GR2LibPropertyWrapper->ArtToolInfo->Vector = gcnew ArtToolInfoVector(*Origin,*Right,*Up,*Back);
259
260 // Tool Version
261 GR2LibPropertyWrapper->ArtToolInfo->ToolVersion = gcnew ArtToolInfoVersion(toolinfo->ArtToolMajorRevision,toolinfo->ArtToolMinorRevision);
262 // Tool Units Per Meter
263 GR2LibPropertyWrapper->ArtToolInfo->UnitsPerMeter = toolinfo->UnitsPerMeter;
264 }
265 #pragma endregion
266 #pragma region ExporterInfo_ToManaged
267 void ExporterInfo_ToManaged(granny_exporter_info* toolinfo)
268 {
269 //GR2LibPropertyWrapper->ExporterInfo = gcnew ExporterInfo();
270 // Tool Name
271 GR2LibPropertyWrapper->ExporterInfo->ExporterName = gcnew String(reinterpret_cast<const char*>(toolinfo->ExporterName));
272 GR2LibPropertyWrapper->ExporterInfo->Version = gcnew versiontype(
273 toolinfo->ExporterMajorRevision,
274 toolinfo->ExporterMinorRevision,
275 toolinfo->ExporterCustomization,
276 toolinfo->ExporterBuildNumber);
277 //_ExporterInfo->ExtendedData = new IntPtr(toolinfo->ExtendedData.Object);
278 }
279 #pragma endregion
280
281 #pragma region MarshalToNative
282
283 #pragma region ArtToolInfo_ToNative
284 void ArtToolInfo_ToNative()
285 {
286
287 _grn_file->GrannyFileInfo->ArtToolInfo->FromArtToolName = (char*)Marshal::StringToHGlobalAnsi(GR2LibPropertyWrapper->ArtToolInfo->FromArtToolName).ToPointer();
288 _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMajorRevision = GR2LibPropertyWrapper->ArtToolInfo->ToolVersion->Major;
289 _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMinorRevision = GR2LibPropertyWrapper->ArtToolInfo->ToolVersion->Minor;
290 _grn_file->GrannyFileInfo->ArtToolInfo->UnitsPerMeter = GR2LibPropertyWrapper->ArtToolInfo->UnitsPerMeter;
291
292
293 _grn_file->GrannyFileInfo->ArtToolInfo->Origin[0] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Origin.x;
294 _grn_file->GrannyFileInfo->ArtToolInfo->Origin[1] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Origin.y;
295 _grn_file->GrannyFileInfo->ArtToolInfo->Origin[2] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Origin.z;
296
297 _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[0] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Right.x;
298 _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[1] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Right.y;
299 _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[2] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Right.z;
300
301 _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[0] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Up.x;
302 _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[1] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Up.y;
303 _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[2] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Up.z;
304
305 _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[0] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Back.x;
306 _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[1] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Back.y;
307 _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[2] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Back.z;
308
309 }
310 #pragma endregion
311 #pragma region ExporterInfo_ToNative
312 void ExporterInfo_ToNative()
313 {
314 _grn_file->GrannyFileInfo->ExporterInfo->ExporterName = (char*)Marshal::StringToHGlobalAnsi(GR2LibPropertyWrapper->ExporterInfo->ExporterName).ToPointer();
315 _grn_file->GrannyFileInfo->ExporterInfo->ExporterMajorRevision = GR2LibPropertyWrapper->ExporterInfo->Version->major;
316 _grn_file->GrannyFileInfo->ExporterInfo->ExporterMinorRevision = GR2LibPropertyWrapper->ExporterInfo->Version->minor;
317 _grn_file->GrannyFileInfo->ExporterInfo->ExporterCustomization = GR2LibPropertyWrapper->ExporterInfo->Version->customization;
318 _grn_file->GrannyFileInfo->ExporterInfo->ExporterBuildNumber = GR2LibPropertyWrapper->ExporterInfo->Version->build;
319 //_grn_file->GrannyFileInfo->ExporterInfo->ExtendedData
320 }
321 #pragma endregion
322 #pragma endregion
323
324 #pragma endregion
325 private: System::Void mnuItemExit_Click(System::Object^ sender, System::EventArgs^ e)
326 {
327 ConvertToNative();
328 this->Close();
329 }
330 private: System::Void mnuItemOpen_Click(System::Object^ sender, System::EventArgs^ e)
331 {
332 const char* fn = "C:\\Program Files\\Granny Viewer\\Gryphon.gr2";
333 _grn_file = new grannyfile();
334 const char* loading_msg = "Loading File: ";
335 int msg_malloc = (strlen(loading_msg) + strlen(fn));
336 char* msg = (char*)malloc(msg_malloc);
337 for (int i=0; i<msg_malloc; i++) { msg[i] = 0; }
338 strcat(msg,loading_msg);
339 strcat(msg,fn);
340 strcat(msg,"\n");
341 _grn_file->_logger->LogMessage(msg);
342 //_grn_file->_logger->SetLogFileName("c:\\gr2_logs",fn);
343 _grn_file = new grannyfile(fn);
344
345 this->GR2LibPropertyWrapper = gcnew GR2LibWrapper();
346 ConvertToManaged();
347 propgrid->SelectedObject = this->GR2LibPropertyWrapper;
348 }
349 private: System::Void gr2lib_rigeditor_frm_FormClosed(System::Object^ sender, System::Windows::Forms::FormClosedEventArgs^ e)
350 {
351 //TerminateConsoleIO();
352 }
353 };
354 // }
355 // }
356 //}
357 #endif /* GR2LIB_RIGEDITOR_FRM_H */

  ViewVC Help
Powered by ViewVC 1.1.22