/[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 55 - (show annotations) (download)
Thu Aug 12 08:37:47 2010 UTC (9 years, 6 months ago) by william
File MIME type: text/plain
File size: 33364 byte(s)
Fix all, current, c++ compiler warnings and linker errors

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

  ViewVC Help
Powered by ViewVC 1.1.22