/[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 12 - (hide annotations) (download)
Sat Jul 31 09:33:11 2010 UTC (9 years, 6 months ago) by william
File MIME type: text/plain
File size: 11217 byte(s)
Added support to write Granny2 Log out to a file, as well as fully implement the logging callback

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    
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 6
213 william 12 #pragma region ManagedNativeParsing
214     array<Object^>^ ConvertToManaged()
215     {
216     List<Object^> ret = gcnew List<Object^>();
217 william 6
218 william 12 // Art Tool info
219     ret.Add(ArtToolInfo_ToManaged(_grn_file->GrannyFileInfo->ArtToolInfo));
220 william 6
221 william 12 return ret.ToArray();
222     }
223     void ConvertToNative()
224     {
225     // Art Tool info
226     ArtToolInfo_ToNative();
227     }
228     #pragma endregion
229 william 6
230 william 12 #pragma region ArtToolInfo
231     ArtToolInfo^ ArtToolInfo_ToManaged(granny_art_tool_info* toolinfo)
232     {
233     _ArtToolInfo = gcnew ArtToolInfo();
234     // Tool Name
235     _ArtToolInfo->FromArtToolName = gcnew String(reinterpret_cast<const char*>(toolinfo->FromArtToolName));
236 william 6
237 william 12 // Tool Vector
238     Vector3* Origin = new Vector3(
239     toolinfo->Origin[0],
240     toolinfo->Origin[1],
241     toolinfo->Origin[2]);
242     Vector3* Right = new Vector3(
243     toolinfo->RightVector[0],
244     toolinfo->RightVector[1],
245     toolinfo->RightVector[2]);
246     Vector3* Up = new Vector3(
247     toolinfo->UpVector[0],
248     toolinfo->UpVector[1],
249     toolinfo->UpVector[2]);
250     Vector3* Back = new Vector3(
251     toolinfo->BackVector[0],
252     toolinfo->BackVector[1],
253     toolinfo->BackVector[2]);
254     _ArtToolInfo->Vector = gcnew ArtToolInfoVector(*Origin,*Right,*Up,*Back);
255 william 6
256 william 12 // Tool Version
257     _ArtToolInfo->ToolVersion = gcnew ArtToolInfoVersion(toolinfo->ArtToolMajorRevision,toolinfo->ArtToolMinorRevision);
258     // Tool Units Per Meter
259     _ArtToolInfo->UnitsPerMeter = toolinfo->UnitsPerMeter;
260     return _ArtToolInfo;
261     }
262     #pragma endregion
263 william 6
264 william 12 #pragma region MarshalToNative
265 william 6
266 william 12 #pragma region ArtToolInfo
267     void ArtToolInfo_ToNative()
268     {
269 william 6
270 william 12 _grn_file->GrannyFileInfo->ArtToolInfo->FromArtToolName = (char*)Marshal::StringToHGlobalAnsi(_ArtToolInfo->FromArtToolName).ToPointer();
271     _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMajorRevision = _ArtToolInfo->ToolVersion->Major;
272     _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMinorRevision = _ArtToolInfo->ToolVersion->Minor;
273     _grn_file->GrannyFileInfo->ArtToolInfo->UnitsPerMeter = _ArtToolInfo->UnitsPerMeter;
274 william 6
275    
276 william 12 _grn_file->GrannyFileInfo->ArtToolInfo->Origin[0] = _ArtToolInfo->Vector->Origin.x;
277     _grn_file->GrannyFileInfo->ArtToolInfo->Origin[1] = _ArtToolInfo->Vector->Origin.y;
278     _grn_file->GrannyFileInfo->ArtToolInfo->Origin[2] = _ArtToolInfo->Vector->Origin.z;
279    
280     _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[0] = _ArtToolInfo->Vector->Right.x;
281     _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[1] = _ArtToolInfo->Vector->Right.y;
282     _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[2] = _ArtToolInfo->Vector->Right.z;
283    
284     _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[0] = _ArtToolInfo->Vector->Up.x;
285     _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[1] = _ArtToolInfo->Vector->Up.y;
286     _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[2] = _ArtToolInfo->Vector->Up.z;
287    
288     _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[0] = _ArtToolInfo->Vector->Back.x;
289     _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[1] = _ArtToolInfo->Vector->Back.y;
290     _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[2] = _ArtToolInfo->Vector->Back.z;
291    
292     }
293     #pragma endregion
294    
295     #pragma endregion
296    
297     #pragma endregion
298 william 6 private: System::Void mnuItemExit_Click(System::Object^ sender, System::EventArgs^ e)
299     {
300     ConvertToNative();
301     this->Close();
302     }
303     private: System::Void mnuItemOpen_Click(System::Object^ sender, System::EventArgs^ e)
304     {
305 william 12 const char* fn = "C:\\Program Files\\Granny Viewer\\Gryphon.gr2";
306     _grn_file = new grannyfile();
307     const char* loading_msg = "Loading File: ";
308     int msg_malloc = (strlen(loading_msg) + strlen(fn));
309     char* msg = (char*)malloc(msg_malloc);
310     for (int i=0; i<msg_malloc; i++) { msg[i] = 0; }
311     strcat(msg,loading_msg);
312     strcat(msg,fn);
313     strcat(msg,"\n");
314     _grn_file->_logger->LogMessage(msg);
315     //_grn_file->_logger->SetLogFileName("c:\\gr2_logs",fn);
316     _grn_file = new grannyfile(fn);
317    
318    
319     propgrid->SelectedObjects = ConvertToManaged();
320 william 6 }
321 william 12 private: System::Void gr2lib_rigeditor_frm_FormClosed(System::Object^ sender, System::Windows::Forms::FormClosedEventArgs^ e)
322     {
323     //TerminateConsoleIO();
324     }
325 william 6 };
326     // }
327     // }
328 william 7 //}
329     #endif /* GR2LIB_RIGEDITOR_FRM_H */

  ViewVC Help
Powered by ViewVC 1.1.22