/[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 14 - (hide annotations) (download)
Sun Aug 1 02:15:12 2010 UTC (10 years, 3 months ago) by william
File MIME type: text/plain
File size: 12736 byte(s)
implement ExporterInfo

1 william 5 #pragma once
2 william 7 //#include "gr2lib_core.h"
3     //#include "gr2lib_core_imports.h"
4     #ifndef GR2LIB_RIGEDITOR_FRM_H
5     #define GR2LIB_RIGEDITOR_FRM_H
6     #include "grannyfile.h"
7 william 12 //#include "guicon.h"
8 william 7 #include <stdio.h>
9     #include <iostream>
10     #include <stdlib.h>
11     #include <assert.h>
12     #include <string>
13     #include <sstream>
14 william 12 #include <vcclr.h>
15 william 7 using namespace std;
16 william 5
17 william 7 using namespace gr2lib::core;
18     using namespace gr2lib::core::coretypes::implementation;
19 william 14 using namespace gr2lib::core::apiversion;
20 william 5 using namespace System;
21     using namespace System::ComponentModel;
22     using namespace System::Collections;
23     using namespace System::Collections::Generic;
24     using namespace System::Windows::Forms;
25     using namespace System::Data;
26     using namespace System::Drawing;
27 william 6 using namespace System::Runtime::InteropServices;
28     //
29     //namespace gr2lib
30     //{
31     // namespace core
32     // {
33     // namespace rigeditor
34     // {
35 william 12 /// <summary>
36     /// Summary for gr2lib_rigeditor_frm
37     ///
38     /// WARNING: If you change the name of this class, you will need to change the
39     /// 'Resource File Name' property for the managed resource compiler tool
40     /// associated with all .resx files this class depends on. Otherwise,
41     /// the designers will not be able to interact properly with localized
42     /// resources associated with this form.
43     /// </summary>
44     public ref class gr2lib_rigeditor_frm : public System::Windows::Forms::Form
45     {
46     private:
47     grannyfile* _grn_file;
48     void LogApplicationStartup()
49     {
50     const char* ApplicationName = "GR2Lib Rig Editor: ";
51 william 5
52 william 12 const char* product_version = (char*)(void*)Marshal::StringToHGlobalAnsi(Application::ProductVersion);
53     const char* version_prefix = "v";
54     const char* startup_string = " {Starting up...}";
55 william 5
56 william 6
57 william 12 int msg_malloc = (strlen(ApplicationName) + strlen(product_version) + strlen(version_prefix) + strlen(startup_string)) + 3;
58 william 5
59 william 12 char* msg = (char*)malloc(msg_malloc);
60     for (int i=0; i<msg_malloc; i++) {
61     msg[i] = 0; // Initialize all elements to zero.
62     }
63 william 5
64 william 12 strcat(msg,ApplicationName);
65     strcat(msg,version_prefix);
66     strcat(msg,product_version);
67     strcat(msg,startup_string);
68     strcat(msg,"\n");
69     _grn_file->_logger->LogMessage(msg);
70     }
71     public:
72     gr2lib_rigeditor_frm(void)
73     {
74     InitializeComponent();
75     _grn_file = new grannyfile();
76     //
77     //TODO: Add the constructor code here
78     //
79     // Log Application Startup
80     LogApplicationStartup();
81     }
82     gr2lib_rigeditor_frm(grannyfile* grn_file)
83     {
84     InitializeComponent();
85     // parse art tool info
86     _grn_file = grn_file;
87    
88     // Log Application Startup
89     LogApplicationStartup();
90    
91     propgrid->SelectedObjects = ConvertToManaged();
92    
93     }
94    
95     protected:
96     /// <summary>
97     /// Clean up any resources being used.
98     /// </summary>
99     ~gr2lib_rigeditor_frm()
100     {
101     if (components)
102     {
103     delete components;
104     }
105     }
106     private: System::Windows::Forms::PropertyGrid^ propgrid;
107     protected:
108     private: System::Windows::Forms::MenuStrip^ mainmenu;
109     private: System::Windows::Forms::ToolStripMenuItem^ mnuFile;
110     private: System::Windows::Forms::ToolStripMenuItem^ mnuItemExit;
111     private: System::Windows::Forms::ToolStripMenuItem^ mnuItemOpen;
112     private: System::Windows::Forms::ToolStripMenuItem^ mnuItemSave;
113     private: System::Windows::Forms::ToolStripMenuItem^ mnuItemSaveAs;
114    
115     protected:
116    
117     private:
118     /// <summary>
119     /// Required designer variable.
120     /// </summary>
121     System::ComponentModel::Container ^components;
122    
123     #pragma region Windows Form Designer generated code
124     /// <summary>
125     /// Required method for Designer support - do not modify
126     /// the contents of this method with the code editor.
127     /// </summary>
128     void InitializeComponent(void)
129     {
130     this->propgrid = (gcnew System::Windows::Forms::PropertyGrid());
131     this->mainmenu = (gcnew System::Windows::Forms::MenuStrip());
132     this->mnuFile = (gcnew System::Windows::Forms::ToolStripMenuItem());
133     this->mnuItemOpen = (gcnew System::Windows::Forms::ToolStripMenuItem());
134     this->mnuItemSave = (gcnew System::Windows::Forms::ToolStripMenuItem());
135     this->mnuItemSaveAs = (gcnew System::Windows::Forms::ToolStripMenuItem());
136     this->mnuItemExit = (gcnew System::Windows::Forms::ToolStripMenuItem());
137     this->mainmenu->SuspendLayout();
138     this->SuspendLayout();
139     //
140     // propgrid
141     //
142     this->propgrid->Dock = System::Windows::Forms::DockStyle::Fill;
143     this->propgrid->Location = System::Drawing::Point(0, 24);
144     this->propgrid->Name = L"propgrid";
145     this->propgrid->PropertySort = System::Windows::Forms::PropertySort::Categorized;
146     this->propgrid->Size = System::Drawing::Size(558, 456);
147     this->propgrid->TabIndex = 4;
148     this->propgrid->ToolbarVisible = false;
149     //
150     // mainmenu
151     //
152     this->mainmenu->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->mnuFile});
153     this->mainmenu->Location = System::Drawing::Point(0, 0);
154     this->mainmenu->Name = L"mainmenu";
155     this->mainmenu->Size = System::Drawing::Size(558, 24);
156     this->mainmenu->TabIndex = 3;
157     this->mainmenu->Text = L"menuStrip1";
158     //
159     // mnuFile
160     //
161     this->mnuFile->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(4) {this->mnuItemOpen,
162     this->mnuItemSave, this->mnuItemSaveAs, this->mnuItemExit});
163     this->mnuFile->Name = L"mnuFile";
164     this->mnuFile->Size = System::Drawing::Size(37, 20);
165     this->mnuFile->Text = L"&File";
166     //
167     // mnuItemOpen
168     //
169     this->mnuItemOpen->Name = L"mnuItemOpen";
170     this->mnuItemOpen->Size = System::Drawing::Size(114, 22);
171     this->mnuItemOpen->Text = L"&Open";
172     this->mnuItemOpen->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemOpen_Click);
173     //
174     // mnuItemSave
175     //
176     this->mnuItemSave->Name = L"mnuItemSave";
177     this->mnuItemSave->Size = System::Drawing::Size(114, 22);
178     this->mnuItemSave->Text = L"&Save";
179     //
180     // mnuItemSaveAs
181     //
182     this->mnuItemSaveAs->Name = L"mnuItemSaveAs";
183     this->mnuItemSaveAs->Size = System::Drawing::Size(114, 22);
184     this->mnuItemSaveAs->Text = L"Save &As";
185     //
186     // mnuItemExit
187     //
188     this->mnuItemExit->Name = L"mnuItemExit";
189     this->mnuItemExit->Size = System::Drawing::Size(114, 22);
190     this->mnuItemExit->Text = L"&Exit";
191     this->mnuItemExit->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemExit_Click);
192     //
193     // gr2lib_rigeditor_frm
194     //
195     this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
196     this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
197     this->ClientSize = System::Drawing::Size(558, 480);
198     this->Controls->Add(this->propgrid);
199     this->Controls->Add(this->mainmenu);
200     this->Name = L"gr2lib_rigeditor_frm";
201     this->Text = L"gr2lib_rigeditor_frm";
202     this->FormClosed += gcnew System::Windows::Forms::FormClosedEventHandler(this, &gr2lib_rigeditor_frm::gr2lib_rigeditor_frm_FormClosed);
203     this->mainmenu->ResumeLayout(false);
204     this->mainmenu->PerformLayout();
205     this->ResumeLayout(false);
206     this->PerformLayout();
207    
208     }
209     #pragma endregion
210 william 6 #pragma region MarshalToMananaged
211 william 12 ArtToolInfo^ _ArtToolInfo;
212 william 14 ExporterInfo^ _ExporterInfo;
213 william 6
214 william 12 #pragma region ManagedNativeParsing
215     array<Object^>^ ConvertToManaged()
216     {
217     List<Object^> ret = gcnew List<Object^>();
218 william 6
219 william 12 // Art Tool info
220     ret.Add(ArtToolInfo_ToManaged(_grn_file->GrannyFileInfo->ArtToolInfo));
221 william 14 // Exporter Info
222     ret.Add(ExporterInfo_ToManaged(_grn_file->GrannyFileInfo->ExporterInfo));
223 william 12 return ret.ToArray();
224     }
225     void ConvertToNative()
226     {
227     // Art Tool info
228     ArtToolInfo_ToNative();
229 william 14 // Exporter Info
230     ExporterInfo_ToNative();
231 william 12 }
232     #pragma endregion
233 william 6
234 william 14 #pragma region ArtToolInfo_ToManaged
235 william 12 ArtToolInfo^ ArtToolInfo_ToManaged(granny_art_tool_info* toolinfo)
236     {
237     _ArtToolInfo = gcnew ArtToolInfo();
238     // Tool Name
239     _ArtToolInfo->FromArtToolName = gcnew String(reinterpret_cast<const char*>(toolinfo->FromArtToolName));
240 william 6
241 william 12 // Tool Vector
242     Vector3* Origin = new Vector3(
243     toolinfo->Origin[0],
244     toolinfo->Origin[1],
245     toolinfo->Origin[2]);
246     Vector3* Right = new Vector3(
247     toolinfo->RightVector[0],
248     toolinfo->RightVector[1],
249     toolinfo->RightVector[2]);
250     Vector3* Up = new Vector3(
251     toolinfo->UpVector[0],
252     toolinfo->UpVector[1],
253     toolinfo->UpVector[2]);
254     Vector3* Back = new Vector3(
255     toolinfo->BackVector[0],
256     toolinfo->BackVector[1],
257     toolinfo->BackVector[2]);
258     _ArtToolInfo->Vector = gcnew ArtToolInfoVector(*Origin,*Right,*Up,*Back);
259 william 6
260 william 12 // Tool Version
261     _ArtToolInfo->ToolVersion = gcnew ArtToolInfoVersion(toolinfo->ArtToolMajorRevision,toolinfo->ArtToolMinorRevision);
262     // Tool Units Per Meter
263     _ArtToolInfo->UnitsPerMeter = toolinfo->UnitsPerMeter;
264     return _ArtToolInfo;
265     }
266     #pragma endregion
267 william 14 #pragma region ExporterInfo_ToManaged
268     ExporterInfo^ ExporterInfo_ToManaged(granny_exporter_info* toolinfo)
269     {
270     _ExporterInfo = gcnew ExporterInfo();
271     // Tool Name
272     _ExporterInfo->ExporterName = gcnew String(reinterpret_cast<const char*>(toolinfo->ExporterName));
273     _ExporterInfo->Version = gcnew versiontype(
274     toolinfo->ExporterMajorRevision,
275     toolinfo->ExporterMinorRevision,
276     toolinfo->ExporterCustomization,
277     toolinfo->ExporterBuildNumber);
278     //_ExporterInfo->ExtendedData = new IntPtr(toolinfo->ExtendedData.Object);
279     return _ExporterInfo;
280     }
281     #pragma endregion
282 william 6
283 william 12 #pragma region MarshalToNative
284 william 6
285 william 14 #pragma region ArtToolInfo_ToNative
286 william 12 void ArtToolInfo_ToNative()
287     {
288 william 6
289 william 12 _grn_file->GrannyFileInfo->ArtToolInfo->FromArtToolName = (char*)Marshal::StringToHGlobalAnsi(_ArtToolInfo->FromArtToolName).ToPointer();
290     _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMajorRevision = _ArtToolInfo->ToolVersion->Major;
291     _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMinorRevision = _ArtToolInfo->ToolVersion->Minor;
292     _grn_file->GrannyFileInfo->ArtToolInfo->UnitsPerMeter = _ArtToolInfo->UnitsPerMeter;
293 william 6
294    
295 william 12 _grn_file->GrannyFileInfo->ArtToolInfo->Origin[0] = _ArtToolInfo->Vector->Origin.x;
296     _grn_file->GrannyFileInfo->ArtToolInfo->Origin[1] = _ArtToolInfo->Vector->Origin.y;
297     _grn_file->GrannyFileInfo->ArtToolInfo->Origin[2] = _ArtToolInfo->Vector->Origin.z;
298    
299     _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[0] = _ArtToolInfo->Vector->Right.x;
300     _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[1] = _ArtToolInfo->Vector->Right.y;
301     _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[2] = _ArtToolInfo->Vector->Right.z;
302    
303     _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[0] = _ArtToolInfo->Vector->Up.x;
304     _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[1] = _ArtToolInfo->Vector->Up.y;
305     _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[2] = _ArtToolInfo->Vector->Up.z;
306    
307     _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[0] = _ArtToolInfo->Vector->Back.x;
308     _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[1] = _ArtToolInfo->Vector->Back.y;
309     _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[2] = _ArtToolInfo->Vector->Back.z;
310    
311     }
312     #pragma endregion
313 william 14 #pragma region ExporterInfo_ToNative
314     void ExporterInfo_ToNative()
315     {
316     _grn_file->GrannyFileInfo->ExporterInfo->ExporterName = (char*)Marshal::StringToHGlobalAnsi(_ExporterInfo->ExporterName).ToPointer();
317     _grn_file->GrannyFileInfo->ExporterInfo->ExporterMajorRevision = _ExporterInfo->Version->major;
318     _grn_file->GrannyFileInfo->ExporterInfo->ExporterMinorRevision = _ExporterInfo->Version->minor;
319     _grn_file->GrannyFileInfo->ExporterInfo->ExporterCustomization = _ExporterInfo->Version->customization;
320     _grn_file->GrannyFileInfo->ExporterInfo->ExporterBuildNumber = _ExporterInfo->Version->build;
321     //_grn_file->GrannyFileInfo->ExporterInfo->ExtendedData
322     }
323 william 12 #pragma endregion
324 william 14 #pragma endregion
325 william 12
326     #pragma endregion
327 william 6 private: System::Void mnuItemExit_Click(System::Object^ sender, System::EventArgs^ e)
328     {
329     ConvertToNative();
330     this->Close();
331     }
332     private: System::Void mnuItemOpen_Click(System::Object^ sender, System::EventArgs^ e)
333     {
334 william 12 const char* fn = "C:\\Program Files\\Granny Viewer\\Gryphon.gr2";
335     _grn_file = new grannyfile();
336     const char* loading_msg = "Loading File: ";
337     int msg_malloc = (strlen(loading_msg) + strlen(fn));
338     char* msg = (char*)malloc(msg_malloc);
339     for (int i=0; i<msg_malloc; i++) { msg[i] = 0; }
340     strcat(msg,loading_msg);
341     strcat(msg,fn);
342     strcat(msg,"\n");
343     _grn_file->_logger->LogMessage(msg);
344     //_grn_file->_logger->SetLogFileName("c:\\gr2_logs",fn);
345     _grn_file = new grannyfile(fn);
346    
347    
348     propgrid->SelectedObjects = ConvertToManaged();
349 william 6 }
350 william 12 private: System::Void gr2lib_rigeditor_frm_FormClosed(System::Object^ sender, System::Windows::Forms::FormClosedEventArgs^ e)
351     {
352     //TerminateConsoleIO();
353     }
354 william 6 };
355     // }
356     // }
357 william 7 //}
358     #endif /* GR2LIB_RIGEDITOR_FRM_H */

  ViewVC Help
Powered by ViewVC 1.1.22