/[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 23 - (show annotations) (download)
Mon Aug 2 02:24:50 2010 UTC (9 years, 6 months ago) by william
File MIME type: text/plain
File size: 29513 byte(s)
add support to convert managed texture back into a native texture

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

  ViewVC Help
Powered by ViewVC 1.1.22