/[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 59 - (show annotations) (download)
Thu Aug 12 19:05:46 2010 UTC (9 years, 6 months ago) by william
File MIME type: text/plain
File size: 31994 byte(s)
tabify part of code

1 #define _CRT_SECURE_NO_WARNINGS
2 #pragma warning( disable : 4100 ) // disable 'unreferenced formal parameter' warnings
3 #pragma warning( disable : 4101 ) // disable 'unreferenced local variable' warnings
4
5 #define SHOW_DEBUG_MENU // if defined, will show the debug menu -> else it will not be shown
6
7 #define granny_pixel_layout_bitshift_size 4
8
9 #pragma once
10 //#include "gr2lib_core.h"
11 //#include "gr2lib_core_imports.h"
12 #ifndef GR2LIB_RIGEDITOR_FRM_H
13 #define GR2LIB_RIGEDITOR_FRM_H
14 #include "grannyfile.h"
15 //#include "guicon.h"
16 #include "VSDebugOutput.h"
17 #include "GrannyFileWriter.h"
18 #include <stdio.h>
19 #include <iostream>
20 #include <stdlib.h>
21 #include <assert.h>
22 #include <string>
23 #include <sstream>
24 #include <vcclr.h>
25 using namespace std;
26
27 using namespace gr2lib::core;
28 using namespace gr2lib::core::coretypes::implementation;
29 using namespace gr2lib::core::apiversion;
30 using namespace gr2lib::core::ui::helpers;
31 using namespace gr2lib::core::helpers;
32 using namespace System;
33 using namespace System::ComponentModel;
34 using namespace System::Collections;
35 using namespace System::Collections::Generic;
36 using namespace System::Windows::Forms;
37 using namespace System::Data;
38 using namespace System::Drawing;
39 using namespace System::Runtime::InteropServices;
40 //using namespace Microsoft::Xna::Framework;
41 //using namespace Microsoft::Xna::Framework::Graphics;
42 //
43 //namespace gr2lib
44 //{
45 // namespace core
46 // {
47 // namespace rigeditor
48 // {
49 /// <summary>
50 /// Summary for gr2lib_rigeditor_frm
51 ///
52 /// WARNING: If you change the name of this class, you will need to change the
53 /// 'Resource File Name' property for the managed resource compiler tool
54 /// associated with all .resx files this class depends on. Otherwise,
55 /// the designers will not be able to interact properly with localized
56 /// resources associated with this form.
57 /// </summary>
58 public ref class gr2lib_rigeditor_frm : public System::Windows::Forms::Form
59 {
60 private:
61 grannyfile* _grn_file;
62 void LogApplicationStartup()
63 {
64 const char* ApplicationName = "GR2Lib Rig Editor: ";
65
66 const char* product_version = (char*)(void*)Marshal::StringToHGlobalAnsi(Application::ProductVersion);
67 const char* version_prefix = "v";
68 const char* startup_string = " {Starting up...}";
69
70
71 int msg_malloc = (strlen(ApplicationName) + strlen(product_version) + strlen(version_prefix) + strlen(startup_string)) + 3;
72
73 char* msg = (char*)malloc(msg_malloc);
74 for (int i=0; i<msg_malloc; i++) {
75 msg[i] = 0; // Initialize all elements to zero.
76 }
77
78 strcat(msg,ApplicationName);
79 strcat(msg,version_prefix);
80 strcat(msg,product_version);
81 strcat(msg,startup_string);
82 strcat(msg,"\n");
83 _grn_file->_logger->LogMessage(msg);
84 }
85 public:
86 gr2lib_rigeditor_frm(void)
87 {
88 InitializeComponent();
89 _grn_file = new grannyfile();
90 //
91 //TODO: Add the constructor code here
92 //
93 // Log Application Startup
94 LogApplicationStartup();
95 }
96 gr2lib_rigeditor_frm(grannyfile* grn_file)
97 {
98 InitializeComponent();
99 // parse art tool info
100 _grn_file = grn_file;
101
102 // Log Application Startup
103 LogApplicationStartup();
104
105 this->GR2LibPropertyWrapper = gcnew GR2LibWrapper();
106 ConvertToManaged();
107 propgrid->SelectedObject = this->GR2LibPropertyWrapper;
108
109 }
110
111 protected:
112 /// <summary>
113 /// Clean up any resources being used.
114 /// </summary>
115 ~gr2lib_rigeditor_frm()
116 {
117 if (components)
118 {
119 delete components;
120 }
121 }
122 private: System::Windows::Forms::PropertyGrid^ propgrid;
123 protected:
124 private: System::Windows::Forms::MenuStrip^ mainmenu;
125 private: System::Windows::Forms::ToolStripMenuItem^ mnuFile;
126 private: System::Windows::Forms::ToolStripMenuItem^ mnuItemExit;
127 private: System::Windows::Forms::ToolStripMenuItem^ mnuItemOpen;
128 private: System::Windows::Forms::ToolStripMenuItem^ mnuItemSave;
129 private: System::Windows::Forms::ToolStripMenuItem^ mnuItemSaveAs;
130 private: System::Windows::Forms::ToolStripMenuItem^ mnuDebug;
131 private: System::Windows::Forms::ToolStripMenuItem^ mnuDebug_UnitTests;
132 private: System::Windows::Forms::ToolStripMenuItem^ mnuTestArtToolInfoReturnValues;
133
134 private: System::Windows::Forms::OpenFileDialog^ RigLoader;
135 private: System::Windows::Forms::ToolStripMenuItem^ mnuTestExporterInfoReturnValues;
136 private: System::Windows::Forms::SaveFileDialog^ RigSaver;
137 private: System::Windows::Forms::ToolStripMenuItem^ mnuItemClose;
138 private: System::Windows::Forms::ToolStripMenuItem^ mnuItemTestDDSRender;
139
140
141
142
143
144 protected:
145
146 private:
147 /// <summary>
148 /// Required designer variable.
149 /// </summary>
150 System::ComponentModel::Container ^components;
151
152 #pragma region Windows Form Designer generated code
153 /// <summary>
154 /// Required method for Designer support - do not modify
155 /// the contents of this method with the code editor.
156 /// </summary>
157 void InitializeComponent(void)
158 {
159 this->propgrid = (gcnew System::Windows::Forms::PropertyGrid());
160 this->mainmenu = (gcnew System::Windows::Forms::MenuStrip());
161 this->mnuFile = (gcnew System::Windows::Forms::ToolStripMenuItem());
162 this->mnuItemOpen = (gcnew System::Windows::Forms::ToolStripMenuItem());
163 this->mnuItemClose = (gcnew System::Windows::Forms::ToolStripMenuItem());
164 this->mnuItemSave = (gcnew System::Windows::Forms::ToolStripMenuItem());
165 this->mnuItemSaveAs = (gcnew System::Windows::Forms::ToolStripMenuItem());
166 this->mnuItemExit = (gcnew System::Windows::Forms::ToolStripMenuItem());
167 this->mnuDebug = (gcnew System::Windows::Forms::ToolStripMenuItem());
168 this->mnuDebug_UnitTests = (gcnew System::Windows::Forms::ToolStripMenuItem());
169 this->mnuTestArtToolInfoReturnValues = (gcnew System::Windows::Forms::ToolStripMenuItem());
170 this->mnuTestExporterInfoReturnValues = (gcnew System::Windows::Forms::ToolStripMenuItem());
171 this->mnuItemTestDDSRender = (gcnew System::Windows::Forms::ToolStripMenuItem());
172 this->RigLoader = (gcnew System::Windows::Forms::OpenFileDialog());
173 this->RigSaver = (gcnew System::Windows::Forms::SaveFileDialog());
174 this->mainmenu->SuspendLayout();
175 this->SuspendLayout();
176 //
177 // propgrid
178 //
179 this->propgrid->Dock = System::Windows::Forms::DockStyle::Fill;
180 this->propgrid->Location = System::Drawing::Point(0, 24);
181 this->propgrid->Name = L"propgrid";
182 this->propgrid->PropertySort = System::Windows::Forms::PropertySort::Categorized;
183 this->propgrid->Size = System::Drawing::Size(558, 456);
184 this->propgrid->TabIndex = 4;
185 this->propgrid->ToolbarVisible = false;
186 //
187 // mainmenu
188 //
189 this->mainmenu->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->mnuFile, this->mnuDebug});
190 this->mainmenu->Location = System::Drawing::Point(0, 0);
191 this->mainmenu->Name = L"mainmenu";
192 this->mainmenu->Size = System::Drawing::Size(558, 24);
193 this->mainmenu->TabIndex = 3;
194 this->mainmenu->Text = L"menuStrip1";
195 //
196 // mnuFile
197 //
198 this->mnuFile->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(5) {this->mnuItemOpen,
199 this->mnuItemClose, this->mnuItemSave, this->mnuItemSaveAs, this->mnuItemExit});
200 this->mnuFile->Name = L"mnuFile";
201 this->mnuFile->Size = System::Drawing::Size(37, 20);
202 this->mnuFile->Text = L"&File";
203 //
204 // mnuItemOpen
205 //
206 this->mnuItemOpen->Name = L"mnuItemOpen";
207 this->mnuItemOpen->Size = System::Drawing::Size(114, 22);
208 this->mnuItemOpen->Text = L"&Open";
209 this->mnuItemOpen->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemOpen_Click);
210 //
211 // mnuItemClose
212 //
213 this->mnuItemClose->Name = L"mnuItemClose";
214 this->mnuItemClose->Size = System::Drawing::Size(114, 22);
215 this->mnuItemClose->Text = L"&Close";
216 this->mnuItemClose->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemClose_Click);
217 //
218 // mnuItemSave
219 //
220 this->mnuItemSave->Name = L"mnuItemSave";
221 this->mnuItemSave->Size = System::Drawing::Size(114, 22);
222 this->mnuItemSave->Text = L"&Save";
223 this->mnuItemSave->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemSave_Click);
224 //
225 // mnuItemSaveAs
226 //
227 this->mnuItemSaveAs->Name = L"mnuItemSaveAs";
228 this->mnuItemSaveAs->Size = System::Drawing::Size(114, 22);
229 this->mnuItemSaveAs->Text = L"Save &As";
230 this->mnuItemSaveAs->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemSaveAs_Click);
231 //
232 // mnuItemExit
233 //
234 this->mnuItemExit->Name = L"mnuItemExit";
235 this->mnuItemExit->Size = System::Drawing::Size(114, 22);
236 this->mnuItemExit->Text = L"&Exit";
237 this->mnuItemExit->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemExit_Click);
238 //
239 // mnuDebug
240 //
241 this->mnuDebug->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->mnuDebug_UnitTests,
242 this->mnuItemTestDDSRender});
243 this->mnuDebug->Name = L"mnuDebug";
244 this->mnuDebug->Size = System::Drawing::Size(56, 20);
245 this->mnuDebug->Text = L"&DEBUG";
246 //
247 // mnuDebug_UnitTests
248 //
249 this->mnuDebug_UnitTests->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->mnuTestArtToolInfoReturnValues,
250 this->mnuTestExporterInfoReturnValues});
251 this->mnuDebug_UnitTests->Name = L"mnuDebug_UnitTests";
252 this->mnuDebug_UnitTests->Size = System::Drawing::Size(161, 22);
253 this->mnuDebug_UnitTests->Text = L"&Unit Tests...";
254 //
255 // mnuTestArtToolInfoReturnValues
256 //
257 this->mnuTestArtToolInfoReturnValues->Name = L"mnuTestArtToolInfoReturnValues";
258 this->mnuTestArtToolInfoReturnValues->Size = System::Drawing::Size(238, 22);
259 this->mnuTestArtToolInfoReturnValues->Text = L"Test ArtoolInfo Rerturn values";
260 this->mnuTestArtToolInfoReturnValues->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuTestArtToolInfoReturnValues_Click);
261 //
262 // mnuTestExporterInfoReturnValues
263 //
264 this->mnuTestExporterInfoReturnValues->Name = L"mnuTestExporterInfoReturnValues";
265 this->mnuTestExporterInfoReturnValues->Size = System::Drawing::Size(238, 22);
266 this->mnuTestExporterInfoReturnValues->Text = L"Test ExporterInfo Return Values";
267 this->mnuTestExporterInfoReturnValues->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuTestExporterInfoReturnValues_Click);
268 //
269 // mnuItemTestDDSRender
270 //
271 this->mnuItemTestDDSRender->Name = L"mnuItemTestDDSRender";
272 this->mnuItemTestDDSRender->Size = System::Drawing::Size(161, 22);
273 this->mnuItemTestDDSRender->Text = L"Test DDS Render";
274 //
275 // RigLoader
276 //
277 this->RigLoader->DefaultExt = L"gr2";
278 this->RigLoader->Filter = L"Granny2 Files|*.gr2;*.grannyrig";
279 this->RigLoader->SupportMultiDottedExtensions = true;
280 this->RigLoader->Title = L"Please choose the Granny2 Rig file to load";
281 //
282 // RigSaver
283 //
284 this->RigSaver->DefaultExt = L"gr2";
285 this->RigSaver->Filter = L"Granny2 Files|*.gr2;*.grannyrig";
286 this->RigSaver->SupportMultiDottedExtensions = true;
287 this->RigSaver->Title = L"Please select the Granny2 Rig to write to or create";
288 //
289 // gr2lib_rigeditor_frm
290 //
291 this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
292 this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
293 this->ClientSize = System::Drawing::Size(558, 480);
294 this->Controls->Add(this->propgrid);
295 this->Controls->Add(this->mainmenu);
296 this->Name = L"gr2lib_rigeditor_frm";
297 this->Text = L"gr2lib_rigeditor_frm";
298 this->Load += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::gr2lib_rigeditor_frm_Load);
299 this->FormClosed += gcnew System::Windows::Forms::FormClosedEventHandler(this, &gr2lib_rigeditor_frm::gr2lib_rigeditor_frm_FormClosed);
300 this->mainmenu->ResumeLayout(false);
301 this->mainmenu->PerformLayout();
302 this->ResumeLayout(false);
303 this->PerformLayout();
304
305 }
306 #pragma endregion
307
308 #pragma region MarshalToMananaged
309 //ArtToolInfo^ _ArtToolInfo;
310 //ExporterInfo^ _ExporterInfo;
311 GR2LibWrapper^ GR2LibPropertyWrapper;
312
313 #pragma region ManagedNativeParsing
314 void ConvertToManaged()
315 {
316 // Art Tool info
317 ArtToolInfo_ToManaged(_grn_file->GrannyFileInfo->ArtToolInfo);
318 // Exporter Info
319 ExporterInfo_ToManaged(_grn_file->GrannyFileInfo->ExporterInfo);
320 // Texture List
321 Textures_ToManaged(_grn_file->GrannyFileInfo->Textures,_grn_file->GrannyFileInfo->TextureCount);
322 }
323 void ConvertToNative()
324 {
325 // Art Tool info
326 ArtToolInfo_ToNative();
327 // Exporter Info
328 ExporterInfo_ToNative();
329 // Texture List
330 Textures_ToNative();
331 }
332 #pragma endregion
333
334 #pragma region ArtToolInfo_ToManaged
335 void ArtToolInfo_ToManaged(granny_art_tool_info* toolinfo)
336 {
337 //GR2LibPropertyWrapper->ArtToolInfo = gcnew ArtToolInfo();
338 if (toolinfo != NULL)
339 {
340 GR2LibPropertyWrapper->ArtToolInfo->FromArtToolName = gcnew String(reinterpret_cast<const char*>(toolinfo->FromArtToolName));
341
342 // Tool Vector
343 Vector3* Origin = new Vector3(
344 toolinfo->Origin[0],
345 toolinfo->Origin[1],
346 toolinfo->Origin[2]);
347 Vector3* Right = new Vector3(
348 toolinfo->RightVector[0],
349 toolinfo->RightVector[1],
350 toolinfo->RightVector[2]);
351 Vector3* Up = new Vector3(
352 toolinfo->UpVector[0],
353 toolinfo->UpVector[1],
354 toolinfo->UpVector[2]);
355 Vector3* Back = new Vector3(
356 toolinfo->BackVector[0],
357 toolinfo->BackVector[1],
358 toolinfo->BackVector[2]);
359 GR2LibPropertyWrapper->ArtToolInfo->Vector = gcnew ArtToolInfoVector(*Origin,*Right,*Up,*Back);
360
361 // Tool Version
362 GR2LibPropertyWrapper->ArtToolInfo->ToolVersion = gcnew ArtToolInfoVersion(toolinfo->ArtToolMajorRevision,toolinfo->ArtToolMinorRevision);
363 // Tool Units Per Meter
364 GR2LibPropertyWrapper->ArtToolInfo->UnitsPerMeter = toolinfo->UnitsPerMeter;
365 }
366 }
367 #pragma endregion
368 #pragma region ExporterInfo_ToManaged
369 void ExporterInfo_ToManaged(granny_exporter_info* toolinfo)
370 {
371 //GR2LibPropertyWrapper->ExporterInfo = gcnew ExporterInfo();
372 if (toolinfo != NULL)
373 {
374 GR2LibPropertyWrapper->ExporterInfo->ExporterName = gcnew String(reinterpret_cast<const char*>(toolinfo->ExporterName));
375 GR2LibPropertyWrapper->ExporterInfo->Version = gcnew versiontype(
376 toolinfo->ExporterMajorRevision,
377 toolinfo->ExporterMinorRevision,
378 toolinfo->ExporterCustomization,
379 toolinfo->ExporterBuildNumber);
380 }
381 //_ExporterInfo->ExtendedData = new IntPtr(toolinfo->ExtendedData.Object);
382 }
383 #pragma endregion
384 #pragma region Textures_ToManaged
385 void Textures_ToManaged(granny_texture** toolinfo, granny_int32 TextureCount)
386 {
387 if (toolinfo != NULL)
388 {
389 /*GR2LibPropertyWrapper->ExporterInfo->ExporterName = gcnew String(reinterpret_cast<const char*>(toolinfo->ExporterName));
390 GR2LibPropertyWrapper->ExporterInfo->Version = gcnew versiontype(
391 toolinfo->ExporterMajorRevision,
392 toolinfo->ExporterMinorRevision,
393 toolinfo->ExporterCustomization,
394 toolinfo->ExporterBuildNumber);*/
395 GR2LibPropertyWrapper->Textures = gcnew List<Texture^>();
396 for(int i=0;i<TextureCount;i++)
397 {
398 Texture^ t = gcnew Texture();
399
400 t->FromFileName = gcnew FilePath(gcnew String(reinterpret_cast<const char*>(toolinfo[i]->FromFileName)));
401 t->TextureType = gcnew NameValuePair<String^,gr2lib::core::typedefs::granny_texture_type>(
402 ::coreapi::EnumToStringSupport::GetGrannyEnumTypeString<gr2lib::core::typedefs::granny_texture_type>(
403 (gr2lib::core::typedefs::granny_texture_type)toolinfo[i]->TextureType),
404 (gr2lib::core::typedefs::granny_texture_type)toolinfo[i]->TextureType);
405 t->Width = toolinfo[i]->Width;
406 t->Height = toolinfo[i]->Height;
407 t->Encoding = gcnew NameValuePair<String^,gr2lib::core::typedefs::granny_texture_encoding>(
408 ::coreapi::EnumToStringSupport::GetGrannyEnumTypeString<gr2lib::core::typedefs::granny_texture_encoding>(
409 (gr2lib::core::typedefs::granny_texture_encoding)toolinfo[i]->Encoding),
410 (gr2lib::core::typedefs::granny_texture_encoding)toolinfo[i]->Encoding);
411 t->SubFormat = gcnew NameValuePair<String^,gr2lib::core::typedefs::granny_pixel_layout>(
412 ::coreapi::EnumToStringSupport::GetGrannyEnumTypeString<gr2lib::core::typedefs::granny_pixel_layout>(
413 (gr2lib::core::typedefs::granny_pixel_layout)toolinfo[i]->SubFormat),
414 (gr2lib::core::typedefs::granny_pixel_layout)toolinfo[i]->SubFormat);
415 t->Layout = gcnew gr2lib::core::coretypes::implementation::Layout();
416 t->Layout->BytesPerPixel = toolinfo[i]->Layout.BytesPerPixel;
417 for(int j=0;j<granny_pixel_layout_bitshift_size;j++)
418 {
419 t->Layout->ShiftForComponent[j] = toolinfo[i]->Layout.ShiftForComponent[j];
420 t->Layout->BitsForComponent[j] = toolinfo[i]->Layout.BitsForComponent[j];
421 }
422 t->Layout->NativePointer = *new IntPtr(&toolinfo[i]->Layout);
423
424 t->Images = gcnew List<gr2lib::core::coretypes::implementation::Image^>();
425 for(int j=0;j<toolinfo[i]->ImageCount;j++)
426 {
427 gr2lib::core::coretypes::implementation::Image^ img = gcnew gr2lib::core::coretypes::implementation::Image();
428 img->MIPLevels = gcnew List<gr2lib::core::coretypes::implementation::MIPLevel^>();
429
430 for(int k=0;k<toolinfo[i]->Images[j].MIPLevelCount;k++)
431 {
432 gr2lib::core::coretypes::implementation::MIPLevel^ mip = gcnew gr2lib::core::coretypes::implementation::MIPLevel();
433 mip->Stride = toolinfo[i]->Images[j].MIPLevels[k].Stride;
434 mip->Pixels = gcnew gr2lib::core::coretypes::implementation::Pixel();
435
436 unsigned char* bytes = (unsigned char*)malloc(toolinfo[i]->Images[j].MIPLevels[k].PixelByteCount);
437 for(int l =0;l<toolinfo[i]->Images[j].MIPLevels[k].PixelByteCount;l++)
438 {
439 bytes[l] =0;
440 }
441 bytes = (unsigned char*)toolinfo[i]->Images[j].MIPLevels[k].PixelBytes;
442
443 mip->Pixels->NativeTexture = t;
444 mip->Pixels->NativeTexturePointer = *new IntPtr(toolinfo[i]);
445 mip->Pixels->ImageIndex = j;
446 mip->Pixels->MipIndex = k;
447
448 for(int l =0;l<toolinfo[i]->Images[j].MIPLevels[k].PixelByteCount;l++)
449 {
450 mip->Pixels->PixelBytes->Add(bytes[l]);
451 }
452 img->MIPLevels->Add(mip);
453
454 }
455
456 t->Images->Add(img);
457 t->NativePointer = *new IntPtr(toolinfo[i]);
458 }
459 GR2LibPropertyWrapper->Textures->Add(t);
460 }
461 }
462 }
463 #pragma endregion
464
465 #pragma region MarshalToNative
466
467 #pragma region ArtToolInfo_ToNative
468 void ArtToolInfo_ToNative()
469 {
470 if (_grn_file->GrannyFileInfo->ArtToolInfo == NULL)
471 {
472 _grn_file->GrannyFileInfo->ArtToolInfo = new granny_art_tool_info();
473 }
474
475 _grn_file->GrannyFileInfo->ArtToolInfo->FromArtToolName = (char*)Marshal::StringToHGlobalAnsi(GR2LibPropertyWrapper->ArtToolInfo->FromArtToolName).ToPointer();
476 _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMajorRevision = GR2LibPropertyWrapper->ArtToolInfo->ToolVersion->Major;
477 _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMinorRevision = GR2LibPropertyWrapper->ArtToolInfo->ToolVersion->Minor;
478 _grn_file->GrannyFileInfo->ArtToolInfo->UnitsPerMeter = GR2LibPropertyWrapper->ArtToolInfo->UnitsPerMeter;
479
480
481 _grn_file->GrannyFileInfo->ArtToolInfo->Origin[0] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Origin.x;
482 _grn_file->GrannyFileInfo->ArtToolInfo->Origin[1] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Origin.y;
483 _grn_file->GrannyFileInfo->ArtToolInfo->Origin[2] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Origin.z;
484
485 _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[0] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Right.x;
486 _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[1] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Right.y;
487 _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[2] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Right.z;
488
489 _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[0] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Up.x;
490 _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[1] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Up.y;
491 _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[2] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Up.z;
492
493 _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[0] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Back.x;
494 _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[1] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Back.y;
495 _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[2] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Back.z;
496
497 }
498 #pragma endregion
499 #pragma region ExporterInfo_ToNative
500 void ExporterInfo_ToNative()
501 {
502 if (_grn_file->GrannyFileInfo->ExporterInfo == NULL)
503 {
504 _grn_file->GrannyFileInfo->ExporterInfo = new granny_exporter_info();
505 }
506 _grn_file->GrannyFileInfo->ExporterInfo->ExporterName = (char*)Marshal::StringToHGlobalAnsi(GR2LibPropertyWrapper->ExporterInfo->ExporterName).ToPointer();
507 _grn_file->GrannyFileInfo->ExporterInfo->ExporterMajorRevision = GR2LibPropertyWrapper->ExporterInfo->Version->major;
508 _grn_file->GrannyFileInfo->ExporterInfo->ExporterMinorRevision = GR2LibPropertyWrapper->ExporterInfo->Version->minor;
509 _grn_file->GrannyFileInfo->ExporterInfo->ExporterCustomization = GR2LibPropertyWrapper->ExporterInfo->Version->customization;
510 _grn_file->GrannyFileInfo->ExporterInfo->ExporterBuildNumber = GR2LibPropertyWrapper->ExporterInfo->Version->build;
511 //_grn_file->GrannyFileInfo->ExporterInfo->ExtendedData
512 }
513 #pragma endregion
514 #pragma region Textures_ToNative
515 void Textures_ToNative()
516 {
517 //_grn_file->GrannyFileInfo->Textures = (granny_texture**)malloc(GR2LibPropertyWrapper->Textures->Count);
518 //for(int i=0;i<GR2LibPropertyWrapper->Textures->Count;i++) { _grn_file->GrannyFileInfo->Textures[i] = new granny_texture(); }
519
520 _grn_file->GrannyFileInfo->TextureCount = GR2LibPropertyWrapper->Textures->Count;
521 for(int i=0;i<_grn_file->GrannyFileInfo->TextureCount;i++)
522 {
523 _grn_file->GrannyFileInfo->Textures[i]->FromFileName = (char*)Marshal::StringToHGlobalAnsi(GR2LibPropertyWrapper->Textures[i]->FromFileName->FullPath).ToPointer();
524 _grn_file->GrannyFileInfo->Textures[i]->TextureType = (granny_int32)GR2LibPropertyWrapper->Textures[i]->TextureType->Value;
525 _grn_file->GrannyFileInfo->Textures[i]->Width = GR2LibPropertyWrapper->Textures[i]->Width;
526 _grn_file->GrannyFileInfo->Textures[i]->Height = GR2LibPropertyWrapper->Textures[i]->Height;
527 _grn_file->GrannyFileInfo->Textures[i]->Encoding = (granny_int32)GR2LibPropertyWrapper->Textures[i]->Encoding->Value;
528 _grn_file->GrannyFileInfo->Textures[i]->SubFormat = (granny_int32)GR2LibPropertyWrapper->Textures[i]->SubFormat->Value;
529
530 _grn_file->GrannyFileInfo->Textures[i]->Layout.BytesPerPixel = (granny_int32)GR2LibPropertyWrapper->Textures[i]->Layout->BytesPerPixel;
531 for(int j=0;j<granny_pixel_layout_bitshift_size;j++)
532 {
533 _grn_file->GrannyFileInfo->Textures[i]->Layout.ShiftForComponent[j] = GR2LibPropertyWrapper->Textures[i]->Layout->ShiftForComponent[j];
534 _grn_file->GrannyFileInfo->Textures[i]->Layout.BitsForComponent[j] = GR2LibPropertyWrapper->Textures[i]->Layout->BitsForComponent[j];
535 }
536
537 _grn_file->GrannyFileInfo->Textures[i]->ImageCount = GR2LibPropertyWrapper->Textures[i]->Images->Count;
538 _grn_file->GrannyFileInfo->Textures[i]->Images = (granny_texture_image*)malloc(_grn_file->GrannyFileInfo->Textures[i]->ImageCount);
539 for(int j=0;j<_grn_file->GrannyFileInfo->Textures[i]->ImageCount;j++)
540 {
541 _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevelCount = GR2LibPropertyWrapper->Textures[i]->Images[j]->MIPLevels->Count;
542 _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels = (granny_texture_mip_level*)malloc(_grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevelCount);
543 for(int k=0;k<_grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevelCount;k++)
544 {
545 _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].Stride = GR2LibPropertyWrapper->Textures[i]->Images[j]->MIPLevels[k]->Stride;
546 _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelByteCount = GR2LibPropertyWrapper->Textures[i]->Images[j]->MIPLevels[k]->Pixels->PixelBytes->Count;
547 _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelBytes = (unsigned char*)malloc(_grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelByteCount);
548
549
550 for (int l=0;l<_grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelByteCount;l++)
551 {
552 _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelBytes[l] = GR2LibPropertyWrapper->Textures[i]->Images[j]->MIPLevels[k]->Pixels->PixelBytes[l];
553 }
554 }
555 }
556 _grn_file->GrannyFileInfo->Textures[i]->ExtendedData = *(new granny_variant());
557 }
558
559 }
560 #pragma endregion
561 #pragma endregion
562
563 #pragma endregion
564
565 #pragma region DoPostSave_Operations
566 void DoPostSave_Operations()
567 {
568 //// Compress Bink Textures
569 //for(int i=0;i<_grn_file->GrannyFileInfo->TextureCount;i++)
570 //{
571 // if (_grn_file->GrannyFileInfo->Textures[i]->Encoding == granny_texture_encoding::GrannyBinkTextureEncoding)
572 // {
573 // int bink_compress = GrannyBinkCompressTexture(
574 // _grn_file->GrannyFileInfo->Textures[i]->Width,
575 // _grn_file->GrannyFileInfo->Textures[i]->Height,
576 // _grn_file->GrannyFileInfo->Textures[i]->Width * _grn_file->GrannyFileInfo->Textures[i]->Layout.BytesPerPixel,
577 // _grn_file->GrannyFileInfo->Textures[i]->Images,
578 // granny_bink_texture_flags::GrannyBinkEncodeAlpha,
579 // granny_compression_type::GrannyNoCompression,
580 // _grn_file->GrannyFileInfo->Textures[i]);
581 // int a = 0;
582 // }
583 //}
584 }
585 #pragma endregion
586
587 private: System::Void mnuItemExit_Click(System::Object^ sender, System::EventArgs^ e)
588 {
589 ConvertToNative();
590 this->Close();
591 }
592 private: System::Void mnuItemOpen_Click(System::Object^ sender, System::EventArgs^ e)
593 {
594 System::Windows::Forms::DialogResult result = RigLoader->ShowDialog();
595 if (result != System::Windows::Forms::DialogResult::OK) return;
596 const char* fn = (char*)Marshal::StringToHGlobalAnsi(RigLoader->FileName).ToPointer();
597
598 _grn_file = new grannyfile();
599 const char* loading_msg = "Loading File: ";
600 int msg_malloc = (strlen(loading_msg) + strlen(fn));
601 char* msg = (char*)malloc(msg_malloc);
602 for (int i=0; i<msg_malloc; i++) { msg[i] = 0; }
603 strcat(msg,loading_msg);
604 strcat(msg,fn);
605 strcat(msg,"\n");
606 _grn_file->_logger->LogMessage(msg);
607 //_grn_file->_logger->SetLogFileName("c:\\gr2_logs",fn);
608 _grn_file = new grannyfile(fn);
609
610 this->GR2LibPropertyWrapper = gcnew GR2LibWrapper();
611 ConvertToManaged();
612 propgrid->SelectedObject = this->GR2LibPropertyWrapper;
613 }
614 private: System::Void gr2lib_rigeditor_frm_FormClosed(System::Object^ sender, System::Windows::Forms::FormClosedEventArgs^ e)
615 {
616 //TerminateConsoleIO();
617 }
618 private: System::Void gr2lib_rigeditor_frm_Load(System::Object^ sender, System::EventArgs^ e)
619 {
620 #if defined SHOW_DEBUG_MENU
621 mnuDebug->Visible = true;
622 #else
623 mnuDebug->Visible = false;
624 #endif
625 }
626 private: System::Void mnuTestArtToolInfoReturnValues_Click(System::Object^ sender, System::EventArgs^ e)
627 {
628 // Convert ArtToolInfo To Native, and ouput the values -> to check that they were updated correctly
629 ArtToolInfo_ToNative();
630 VSDebugWriterW VSDebugWriter;
631 VSDebugWriter
632 << "\n\n\tArtToolInfo ->"
633 << "\n\t\tTool Name: "
634 << _grn_file->GrannyFileInfo->ArtToolInfo->FromArtToolName
635 << "\n\t\tTool Version: "
636 << _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMajorRevision
637 << "." << _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMinorRevision
638 << "\n\t\tUnits Per Meter: "
639 << _grn_file->GrannyFileInfo->ArtToolInfo->UnitsPerMeter
640 << "\n\t\tOrigin: "
641 << "\n\t\t\tX: "
642 << _grn_file->GrannyFileInfo->ArtToolInfo->Origin[0]
643 << "\n\t\t\tY: "
644 << _grn_file->GrannyFileInfo->ArtToolInfo->Origin[1]
645 << "\n\t\t\tZ: "
646 << _grn_file->GrannyFileInfo->ArtToolInfo->Origin[2]
647 << "\n\t\tRight: "
648 << "\n\t\t\tX: "
649 << _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[0]
650 << "\n\t\t\tY: "
651 << _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[1]
652 << "\n\t\t\tZ: "
653 << _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[2]
654 << "\n\t\tUp: "
655 << "\n\t\t\tX: "
656 << _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[0]
657 << "\n\t\t\tY: "
658 << _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[1]
659 << "\n\t\t\tZ: "
660 << _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[2]
661 << "\n\t\tBack: "
662 << "\n\t\t\tX: "
663 << _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[0]
664 << "\n\t\t\tY: "
665 << _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[1]
666 << "\n\t\t\tZ: "
667 << _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[2]
668 ;
669 }
670 private: System::Void mnuTestExporterInfoReturnValues_Click(System::Object^ sender, System::EventArgs^ e)
671 {
672 // Convert ExporterInfo To Native, and ouput the values -> to check that they were updated correctly
673 ExporterInfo_ToNative();
674 VSDebugWriterW VSDebugWriter;
675 VSDebugWriter
676 << "\n\n\tExporterInfo ->"
677 << "\n\t\tExporter Name: "
678 << _grn_file->GrannyFileInfo->ExporterInfo->ExporterName
679 << "\n\t\tExporter Version: "
680 << _grn_file->GrannyFileInfo->ExporterInfo->ExporterMajorRevision
681 << "." << _grn_file->GrannyFileInfo->ExporterInfo->ExporterMinorRevision
682 << "." << _grn_file->GrannyFileInfo->ExporterInfo->ExporterCustomization
683 << "." << _grn_file->GrannyFileInfo->ExporterInfo->ExporterBuildNumber
684 ;
685 }
686 private: System::Void mnuItemSave_Click(System::Object^ sender, System::EventArgs^ e)
687 {
688 // convert Data to Native
689 try
690 {
691 ConvertToNative();
692 const char* filename = _grn_file->_GrannyFilename;
693 GrannyFileWriter::WriteFile(filename,_grn_file->GrannyFileInfo,_grn_file->_logger);
694 //DoPostSave_Operations();
695 //GrannyFileWriter::WriteFile(filename,_grn_file->GrannyFileInfo,_grn_file->_logger);
696 System::Windows::Forms::MessageBox::Show("Successfully Saved: \n" + gcnew String(_grn_file->GrannyFilename()),"File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Information);
697 }
698 catch(Exception^ ex)
699 {
700 System::Windows::Forms::MessageBox::Show("Failed to Save: \n" + gcnew String(_grn_file->GrannyFilename()),"File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Error);
701 }
702 }
703 private: System::Void mnuItemSaveAs_Click(System::Object^ sender, System::EventArgs^ e)
704 {
705 // convert Data to Native
706 try
707 {
708 ConvertToNative();
709 System::Windows::Forms::DialogResult result = RigSaver->ShowDialog();
710 if (result != System::Windows::Forms::DialogResult::OK) return;
711 const char* filename = (char*)Marshal::StringToHGlobalAnsi(RigSaver->FileName).ToPointer();
712 GrannyFileWriter::WriteFile(filename,_grn_file->GrannyFileInfo,_grn_file->_logger);
713 //DoPostSave_Operations();
714 //GrannyFileWriter::WriteFile(filename,_grn_file->GrannyFileInfo,_grn_file->_logger);
715 System::Windows::Forms::MessageBox::Show("Successfully Saved: \n" + gcnew String(_grn_file->GrannyFilename()),"File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Information);
716 }
717 catch(Exception^ ex)
718 {
719 System::Windows::Forms::MessageBox::Show("Failed to Save: \n" + gcnew String(_grn_file->GrannyFilename()),"File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Error);
720 }
721 }
722 private: System::Void mnuItemClose_Click(System::Object^ sender, System::EventArgs^ e)
723 {
724 propgrid->SelectedObject = nullptr;
725 }
726 };
727 // }
728 // }
729 //}
730 #endif /* GR2LIB_RIGEDITOR_FRM_H */

  ViewVC Help
Powered by ViewVC 1.1.22