/[Sims3RigEditor]/trunk/gr2lib_cpp/gr2lib_rigeditor_frm.h
ViewVC logotype

Annotation of /trunk/gr2lib_cpp/gr2lib_rigeditor_frm.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 26 - (hide annotations) (download)
Mon Aug 2 03:33:24 2010 UTC (9 years, 6 months ago) by william
File MIME type: text/plain
File size: 29899 byte(s)
add support to close current granny file

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

  ViewVC Help
Powered by ViewVC 1.1.22