/[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 50 - (show annotations) (download)
Sun Aug 8 08:23:57 2010 UTC (9 years, 6 months ago) by william
File MIME type: text/plain
File size: 31991 byte(s)
When saving Granny2 files: Show a message box informing of save success/failure

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

  ViewVC Help
Powered by ViewVC 1.1.22