/[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 57 - (show annotations) (download)
Thu Aug 12 18:49:34 2010 UTC (9 years, 6 months ago) by william
File MIME type: text/plain
File size: 33444 byte(s)
update to account for change in pixels class

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 for(int l =0;l<toolinfo[i]->Images[j].MIPLevels[k].PixelByteCount;l++)
444 {
445 gr2lib::core::coretypes::implementation::Pixel^ pix = gcnew gr2lib::core::coretypes::implementation::Pixel();
446
447 pix->PixelBytes->Add(bytes[l]);
448 pix->NativeTexture = t;
449 pix->NativeTexturePointer = *new IntPtr(toolinfo[i]);
450 pix->ImageIndex = j;
451 pix->MipIndex = k;
452 mip->Pixels = pix;
453 }
454
455 img->MIPLevels->Add(mip);
456 }
457
458 t->Images->Add(img);
459 t->NativePointer = *new IntPtr(toolinfo[i]);
460 }
461 GR2LibPropertyWrapper->Textures->Add(t);
462 }
463 }
464 }
465 #pragma endregion
466
467 #pragma region MarshalToNative
468
469 #pragma region ArtToolInfo_ToNative
470 void ArtToolInfo_ToNative()
471 {
472 if (_grn_file->GrannyFileInfo->ArtToolInfo == NULL)
473 {
474 _grn_file->GrannyFileInfo->ArtToolInfo = new granny_art_tool_info();
475 }
476
477 _grn_file->GrannyFileInfo->ArtToolInfo->FromArtToolName = (char*)Marshal::StringToHGlobalAnsi(GR2LibPropertyWrapper->ArtToolInfo->FromArtToolName).ToPointer();
478 _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMajorRevision = GR2LibPropertyWrapper->ArtToolInfo->ToolVersion->Major;
479 _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMinorRevision = GR2LibPropertyWrapper->ArtToolInfo->ToolVersion->Minor;
480 _grn_file->GrannyFileInfo->ArtToolInfo->UnitsPerMeter = GR2LibPropertyWrapper->ArtToolInfo->UnitsPerMeter;
481
482
483 _grn_file->GrannyFileInfo->ArtToolInfo->Origin[0] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Origin.x;
484 _grn_file->GrannyFileInfo->ArtToolInfo->Origin[1] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Origin.y;
485 _grn_file->GrannyFileInfo->ArtToolInfo->Origin[2] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Origin.z;
486
487 _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[0] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Right.x;
488 _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[1] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Right.y;
489 _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[2] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Right.z;
490
491 _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[0] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Up.x;
492 _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[1] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Up.y;
493 _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[2] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Up.z;
494
495 _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[0] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Back.x;
496 _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[1] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Back.y;
497 _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[2] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Back.z;
498
499 }
500 #pragma endregion
501 #pragma region ExporterInfo_ToNative
502 void ExporterInfo_ToNative()
503 {
504 if (_grn_file->GrannyFileInfo->ExporterInfo == NULL)
505 {
506 _grn_file->GrannyFileInfo->ExporterInfo = new granny_exporter_info();
507 }
508 _grn_file->GrannyFileInfo->ExporterInfo->ExporterName = (char*)Marshal::StringToHGlobalAnsi(GR2LibPropertyWrapper->ExporterInfo->ExporterName).ToPointer();
509 _grn_file->GrannyFileInfo->ExporterInfo->ExporterMajorRevision = GR2LibPropertyWrapper->ExporterInfo->Version->major;
510 _grn_file->GrannyFileInfo->ExporterInfo->ExporterMinorRevision = GR2LibPropertyWrapper->ExporterInfo->Version->minor;
511 _grn_file->GrannyFileInfo->ExporterInfo->ExporterCustomization = GR2LibPropertyWrapper->ExporterInfo->Version->customization;
512 _grn_file->GrannyFileInfo->ExporterInfo->ExporterBuildNumber = GR2LibPropertyWrapper->ExporterInfo->Version->build;
513 //_grn_file->GrannyFileInfo->ExporterInfo->ExtendedData
514 }
515 #pragma endregion
516 #pragma region Textures_ToNative
517 void Textures_ToNative()
518 {
519 //_grn_file->GrannyFileInfo->Textures = (granny_texture**)malloc(GR2LibPropertyWrapper->Textures->Count);
520 //for(int i=0;i<GR2LibPropertyWrapper->Textures->Count;i++) { _grn_file->GrannyFileInfo->Textures[i] = new granny_texture(); }
521
522 _grn_file->GrannyFileInfo->TextureCount = GR2LibPropertyWrapper->Textures->Count;
523 for(int i=0;i<_grn_file->GrannyFileInfo->TextureCount;i++)
524 {
525 _grn_file->GrannyFileInfo->Textures[i]->FromFileName = (char*)Marshal::StringToHGlobalAnsi(GR2LibPropertyWrapper->Textures[i]->FromFileName->FullPath).ToPointer();
526 _grn_file->GrannyFileInfo->Textures[i]->TextureType = (granny_int32)GR2LibPropertyWrapper->Textures[i]->TextureType->Value;
527 _grn_file->GrannyFileInfo->Textures[i]->Width = GR2LibPropertyWrapper->Textures[i]->Width;
528 _grn_file->GrannyFileInfo->Textures[i]->Height = GR2LibPropertyWrapper->Textures[i]->Height;
529 _grn_file->GrannyFileInfo->Textures[i]->Encoding = (granny_int32)GR2LibPropertyWrapper->Textures[i]->Encoding->Value;
530 _grn_file->GrannyFileInfo->Textures[i]->SubFormat = (granny_int32)GR2LibPropertyWrapper->Textures[i]->SubFormat->Value;
531
532 _grn_file->GrannyFileInfo->Textures[i]->Layout.BytesPerPixel = (granny_int32)GR2LibPropertyWrapper->Textures[i]->Layout->BytesPerPixel;
533 for(int j=0;j<granny_pixel_layout_bitshift_size;j++)
534 {
535 _grn_file->GrannyFileInfo->Textures[i]->Layout.ShiftForComponent[j] = GR2LibPropertyWrapper->Textures[i]->Layout->ShiftForComponent[j];
536 _grn_file->GrannyFileInfo->Textures[i]->Layout.BitsForComponent[j] = GR2LibPropertyWrapper->Textures[i]->Layout->BitsForComponent[j];
537 }
538
539 _grn_file->GrannyFileInfo->Textures[i]->ImageCount = GR2LibPropertyWrapper->Textures[i]->Images->Count;
540 _grn_file->GrannyFileInfo->Textures[i]->Images = (granny_texture_image*)malloc(_grn_file->GrannyFileInfo->Textures[i]->ImageCount);
541 //for(int k=0;k<_grn_file->GrannyFileInfo->Textures[i]->ImageCount;k++) { _grn_file->GrannyFileInfo->Textures[i]->Images[k] = *(new granny_texture_image()); }
542
543 for(int j=0;j<_grn_file->GrannyFileInfo->Textures[i]->ImageCount;j++)
544 {
545 _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevelCount = GR2LibPropertyWrapper->Textures[i]->Images[j]->MIPLevels->Count;
546 _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels = (granny_texture_mip_level*)malloc(_grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevelCount);
547 //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()); }
548 for(int k=0;k<_grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevelCount;k++)
549 {
550 _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].Stride = GR2LibPropertyWrapper->Textures[i]->Images[j]->MIPLevels[k]->Stride;
551 _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelByteCount = GR2LibPropertyWrapper->Textures[i]->Images[j]->MIPLevels[k]->Pixels->PixelBytes->Count;
552 _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelBytes = (unsigned char*)malloc(_grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelByteCount);
553
554
555 for (int l=0;l<_grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelByteCount;l++)
556 {
557 _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelBytes[l] = GR2LibPropertyWrapper->Textures[i]->Images[j]->MIPLevels[k]->Pixels->PixelBytes[l];
558 }
559
560 //// try to compress texture?
561 //if (_grn_file->GrannyFileInfo->Textures[i]->Encoding == granny_texture_encoding::GrannyBinkTextureEncoding)
562 //{
563 // granny_texture* src = _grn_file->GrannyFileInfo->Textures[i];
564 // //granny_texture* dest = new granny_texture();
565 // unsigned char* dest;
566 // GrannyBinkCompressTexture(
567 // _grn_file->GrannyFileInfo->Textures[i]->Width,
568 // _grn_file->GrannyFileInfo->Textures[i]->Height,
569 // _grn_file->GrannyFileInfo->Textures[i]->Width * _grn_file->GrannyFileInfo->Textures[i]->Layout.BytesPerPixel,
570 // src->Images[j].MIPLevels[k].PixelBytes,
571 // granny_bink_texture_flags::GrannyBinkEncodeAlpha,
572 // granny_compression_type::GrannyNoCompression,
573 // &dest);
574 //}
575
576 }
577 }
578 //granny_pixel_layout _layout;
579 //GrannyGetRecommendedPixelLayout(_grn_file->GrannyFileInfo->Textures[i],&_layout);
580 //_grn_file->GrannyFileInfo->Textures[i]->Layout = _layout;
581 _grn_file->GrannyFileInfo->Textures[i]->ExtendedData = *(new granny_variant());
582
583
584
585
586 }
587
588 }
589 #pragma endregion
590 #pragma endregion
591
592 #pragma endregion
593
594 #pragma region DoPostSave_Operations
595 void DoPostSave_Operations()
596 {
597 //// Compress Bink Textures
598 //for(int i=0;i<_grn_file->GrannyFileInfo->TextureCount;i++)
599 //{
600 // if (_grn_file->GrannyFileInfo->Textures[i]->Encoding == granny_texture_encoding::GrannyBinkTextureEncoding)
601 // {
602 // int bink_compress = GrannyBinkCompressTexture(
603 // _grn_file->GrannyFileInfo->Textures[i]->Width,
604 // _grn_file->GrannyFileInfo->Textures[i]->Height,
605 // _grn_file->GrannyFileInfo->Textures[i]->Width * _grn_file->GrannyFileInfo->Textures[i]->Layout.BytesPerPixel,
606 // _grn_file->GrannyFileInfo->Textures[i]->Images,
607 // granny_bink_texture_flags::GrannyBinkEncodeAlpha,
608 // granny_compression_type::GrannyNoCompression,
609 // _grn_file->GrannyFileInfo->Textures[i]);
610 // int a = 0;
611 // }
612 //}
613 }
614 #pragma endregion
615
616 private: System::Void mnuItemExit_Click(System::Object^ sender, System::EventArgs^ e)
617 {
618 ConvertToNative();
619 this->Close();
620 }
621 private: System::Void mnuItemOpen_Click(System::Object^ sender, System::EventArgs^ e)
622 {
623 System::Windows::Forms::DialogResult result = RigLoader->ShowDialog();
624 if (result != System::Windows::Forms::DialogResult::OK) return;
625 const char* fn = (char*)Marshal::StringToHGlobalAnsi(RigLoader->FileName).ToPointer();
626
627 _grn_file = new grannyfile();
628 const char* loading_msg = "Loading File: ";
629 int msg_malloc = (strlen(loading_msg) + strlen(fn));
630 char* msg = (char*)malloc(msg_malloc);
631 for (int i=0; i<msg_malloc; i++) { msg[i] = 0; }
632 strcat(msg,loading_msg);
633 strcat(msg,fn);
634 strcat(msg,"\n");
635 _grn_file->_logger->LogMessage(msg);
636 //_grn_file->_logger->SetLogFileName("c:\\gr2_logs",fn);
637 _grn_file = new grannyfile(fn);
638
639 this->GR2LibPropertyWrapper = gcnew GR2LibWrapper();
640 ConvertToManaged();
641 propgrid->SelectedObject = this->GR2LibPropertyWrapper;
642 }
643 private: System::Void gr2lib_rigeditor_frm_FormClosed(System::Object^ sender, System::Windows::Forms::FormClosedEventArgs^ e)
644 {
645 //TerminateConsoleIO();
646 }
647 private: System::Void gr2lib_rigeditor_frm_Load(System::Object^ sender, System::EventArgs^ e)
648 {
649 #if defined SHOW_DEBUG_MENU
650 mnuDebug->Visible = true;
651 #else
652 mnuDebug->Visible = false;
653 #endif
654 }
655 private: System::Void mnuTestArtToolInfoReturnValues_Click(System::Object^ sender, System::EventArgs^ e)
656 {
657 // Convert ArtToolInfo To Native, and ouput the values -> to check that they were updated correctly
658 ArtToolInfo_ToNative();
659 VSDebugWriterW VSDebugWriter;
660 VSDebugWriter
661 << "\n\n\tArtToolInfo ->"
662 << "\n\t\tTool Name: "
663 << _grn_file->GrannyFileInfo->ArtToolInfo->FromArtToolName
664 << "\n\t\tTool Version: "
665 << _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMajorRevision
666 << "." << _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMinorRevision
667 << "\n\t\tUnits Per Meter: "
668 << _grn_file->GrannyFileInfo->ArtToolInfo->UnitsPerMeter
669 << "\n\t\tOrigin: "
670 << "\n\t\t\tX: "
671 << _grn_file->GrannyFileInfo->ArtToolInfo->Origin[0]
672 << "\n\t\t\tY: "
673 << _grn_file->GrannyFileInfo->ArtToolInfo->Origin[1]
674 << "\n\t\t\tZ: "
675 << _grn_file->GrannyFileInfo->ArtToolInfo->Origin[2]
676 << "\n\t\tRight: "
677 << "\n\t\t\tX: "
678 << _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[0]
679 << "\n\t\t\tY: "
680 << _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[1]
681 << "\n\t\t\tZ: "
682 << _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[2]
683 << "\n\t\tUp: "
684 << "\n\t\t\tX: "
685 << _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[0]
686 << "\n\t\t\tY: "
687 << _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[1]
688 << "\n\t\t\tZ: "
689 << _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[2]
690 << "\n\t\tBack: "
691 << "\n\t\t\tX: "
692 << _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[0]
693 << "\n\t\t\tY: "
694 << _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[1]
695 << "\n\t\t\tZ: "
696 << _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[2]
697 ;
698 }
699 private: System::Void mnuTestExporterInfoReturnValues_Click(System::Object^ sender, System::EventArgs^ e)
700 {
701 // Convert ExporterInfo To Native, and ouput the values -> to check that they were updated correctly
702 ExporterInfo_ToNative();
703 VSDebugWriterW VSDebugWriter;
704 VSDebugWriter
705 << "\n\n\tExporterInfo ->"
706 << "\n\t\tExporter Name: "
707 << _grn_file->GrannyFileInfo->ExporterInfo->ExporterName
708 << "\n\t\tExporter Version: "
709 << _grn_file->GrannyFileInfo->ExporterInfo->ExporterMajorRevision
710 << "." << _grn_file->GrannyFileInfo->ExporterInfo->ExporterMinorRevision
711 << "." << _grn_file->GrannyFileInfo->ExporterInfo->ExporterCustomization
712 << "." << _grn_file->GrannyFileInfo->ExporterInfo->ExporterBuildNumber
713 ;
714 }
715 private: System::Void mnuItemSave_Click(System::Object^ sender, System::EventArgs^ e)
716 {
717 // convert Data to Native
718 try
719 {
720 ConvertToNative();
721 const char* filename = _grn_file->_GrannyFilename;
722 GrannyFileWriter::WriteFile(filename,_grn_file->GrannyFileInfo,_grn_file->_logger);
723 //DoPostSave_Operations();
724 //GrannyFileWriter::WriteFile(filename,_grn_file->GrannyFileInfo,_grn_file->_logger);
725 System::Windows::Forms::MessageBox::Show("Successfully Saved: \n" + gcnew String(_grn_file->GrannyFilename()),"File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Information);
726 }
727 catch(Exception^ ex)
728 {
729 System::Windows::Forms::MessageBox::Show("Failed to Save: \n" + gcnew String(_grn_file->GrannyFilename()),"File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Error);
730 }
731 }
732 private: System::Void mnuItemSaveAs_Click(System::Object^ sender, System::EventArgs^ e)
733 {
734 // convert Data to Native
735 try
736 {
737 ConvertToNative();
738 System::Windows::Forms::DialogResult result = RigSaver->ShowDialog();
739 if (result != System::Windows::Forms::DialogResult::OK) return;
740 const char* filename = (char*)Marshal::StringToHGlobalAnsi(RigSaver->FileName).ToPointer();
741 GrannyFileWriter::WriteFile(filename,_grn_file->GrannyFileInfo,_grn_file->_logger);
742 //DoPostSave_Operations();
743 //GrannyFileWriter::WriteFile(filename,_grn_file->GrannyFileInfo,_grn_file->_logger);
744 System::Windows::Forms::MessageBox::Show("Successfully Saved: \n" + gcnew String(_grn_file->GrannyFilename()),"File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Information);
745 }
746 catch(Exception^ ex)
747 {
748 System::Windows::Forms::MessageBox::Show("Failed to Save: \n" + gcnew String(_grn_file->GrannyFilename()),"File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Error);
749 }
750 }
751 private: System::Void mnuItemClose_Click(System::Object^ sender, System::EventArgs^ e)
752 {
753 propgrid->SelectedObject = nullptr;
754 }
755 };
756 // }
757 // }
758 //}
759 #endif /* GR2LIB_RIGEDITOR_FRM_H */

  ViewVC Help
Powered by ViewVC 1.1.22