/[gr2lib]/trunk/gr2lib/core/coretypes/implementation/grnfileinfo.cs
ViewVC logotype

Contents of /trunk/gr2lib/core/coretypes/implementation/grnfileinfo.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 185 - (show annotations) (download)
Fri Jul 23 23:55:52 2010 UTC (9 years, 3 months ago) by william
File size: 9794 byte(s)
continue to add xml documentation

1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using gr2lib.core.helpers;
5 using gr2lib.core.interfaces;
6 using gr2lib.core.header;
7 using System.ComponentModel;
8 using gr2lib.core.ui.typeeditors;
9 using System.Drawing.Design;
10 using gr2lib.core.ui.helpers;
11 using System.Windows.Forms;
12
13 namespace gr2lib.core.coretypes.implementation
14 {
15 /// <summary>
16 /// Granny File Info class
17 /// </summary>
18 public class grnfileinfo : Igrnfileinfo
19 {
20 private string fromFileName;
21 private FilePath _FileName;
22 private ArtToolInfo _ArtToolInfo;
23 private ExporterInfo _ExporterInfo;
24 private List<Texture> _Textures;
25 private List<Material> _Materials;
26 private List<Skeleton> _Skeletons;
27
28
29 //VertexDatas
30 //TriTopologies
31 //Meshes
32 //Models
33 //TrackGroups
34 //Animations
35 //ExtendedData
36
37
38 /// <summary>
39 /// default contructor
40 /// </summary>
41 public grnfileinfo()
42 {
43 this.FileName = new FilePath();
44 }
45 /// <summary>
46 /// default contructor, specifying filename
47 /// </summary>
48 public grnfileinfo(string path)
49 {
50 this.FileName = new FilePath(path);
51 }
52
53 private static string FileNameFromPath(string path)
54 {
55 int lastSlash = path.LastIndexOf('\\');
56 if (lastSlash > 0) return path.Substring(lastSlash + 1);
57 lastSlash = path.LastIndexOf('/');
58 if (lastSlash > 0) return path.Substring(lastSlash + 1);
59 return path;
60 }
61
62 internal static grnfileinfo ReadFromMemory(IntPtr pointer)
63 {
64 try
65 {
66 if (pointer == IntPtr.Zero) return null;
67 native.grnfileinfo native = Helpers.ReadFromMemory<native.grnfileinfo>(pointer);
68 grnfileinfo managed = new grnfileinfo();
69 managed.NativePointer = pointer;
70
71 if (native.ArtToolInfo != IntPtr.Zero)
72 {
73 managed.ArtToolInfo = ArtToolInfo.ReadFromMemory(native.ArtToolInfo);
74 }
75 //else
76 //{
77 // managed.ArtToolInfo = new ArtToolInfo();
78 //}
79 if (native.ExporterInfo != IntPtr.Zero)
80 {
81 managed.ExporterInfo = ExporterInfo.ReadFromMemory(native.ExporterInfo);
82 }
83 //else
84 //{
85 // managed.ExporterInfo = new ExporterInfo();
86 //}
87
88 managed.fromFileName = string.IsNullOrEmpty(native.FromFileName) ? "{null}" : native.FromFileName;
89 managed.ExtendedData = native.ExtendedData;
90
91 int length = 0;
92 if (native.Textures.Pointer != IntPtr.Zero)
93 {
94
95 IntPtr[] textures = Helpers.ReadArrayFromMemory(native.Textures);
96 length = textures.Length;
97 managed.Textures = new List<Texture>(length);
98 foreach (IntPtr ptr in textures)
99 {
100 Texture _tmp = new Texture();
101 _tmp.NativePointer = ptr;
102 managed.Textures.Add(_tmp);
103 Application.DoEvents();
104 }
105 for (int i = 0; i < length; i++)
106 {
107 managed.Textures[i] = Texture.ReadFromMemory(textures[i]);
108 managed.Textures[i].Index = i;
109 Application.DoEvents();
110 }
111 }
112 else
113 {
114 managed.Textures = new List<Texture>();
115 }
116
117 if (native.Materials.Pointer != IntPtr.Zero)
118 {
119 IntPtr[] materials = Helpers.ReadArrayFromMemory(native.Materials);
120 length = materials.Length;
121 managed.Materials = new List<Material>(length);
122 foreach (IntPtr ptr in materials)
123 {
124 managed.Materials.Add(new Material());
125 Application.DoEvents();
126 }
127 for (int i = 0; i < length; i++)
128 {
129 managed.Materials[i] = Material.ReadFromMemory(materials[i]);
130 Application.DoEvents();
131 }
132 }
133 else
134 {
135 managed.Materials = new List<Material>();
136 }
137
138 if (native.Skeletons.Pointer != IntPtr.Zero)
139 {
140 IntPtr[] skeletons = Helpers.ReadArrayFromMemory(native.Skeletons);
141 length = skeletons.Length;
142 managed.Skeletons = new List<Skeleton>(length);
143 foreach (IntPtr ptr in skeletons)
144 {
145 managed.Skeletons.Add(new Skeleton());
146 Application.DoEvents();
147 }
148 for (int i = 0; i < length; i++)
149 {
150 managed.Skeletons[i] = (Skeleton.ReadFromMemory(skeletons[i]));
151 Application.DoEvents();
152 }
153 }
154 else
155 {
156 managed.Skeletons = new List<Skeleton>();
157 }
158
159 return managed;
160 }
161 catch (Exception ex)
162 {
163 Console.WriteLine(ex.ToString());
164 return default(grnfileinfo);
165 }
166 }
167
168
169 #region Igrnfileinfo Members
170
171 /// <summary>
172 /// Gets a value indicating if the instance contains ArtToolInfo
173 /// </summary>
174 public bool HaveArtToolInfo { get { if (this.ArtToolInfo == null) return false; return true; } }
175 /// <summary>
176 /// Gets a value indicating if the instance contains ExporterInfo
177 /// </summary>
178 public bool HaveExporterInfo { get { if (this.ExporterInfo == null) return false; return true; } }
179 /// <summary>
180 /// Gets a value indicating if the instance contains FromFileName
181 /// </summary>
182 public bool HaveFromFileName { get { if (this.FromFileName == null || this.FromFileName == "") return false; return true; } }
183 /// <summary>
184 /// Gets a value indicating if the instance contains Textures
185 /// </summary>
186 public bool HaveTextures { get { if (this.Textures == null || this.Textures.Count <= 0) return false; return true; } }
187 /// <summary>
188 /// Gets a value indicating if the instance contains Materials
189 /// </summary>
190 public bool HaveMaterials { get { if (this.Materials == null || this.Materials.Count <= 0) return false; return true; } }
191 /// <summary>
192 /// Gets a value indicating if the instance contains Skeletons
193 /// </summary>
194 public bool HaveSkeletons { get { if (this.Skeletons == null || this.Skeletons.Count <= 0) return false; return true; } }
195
196 /// <summary>
197 /// Gets or Sets the ArtToolInfo associated with this instance
198 /// </summary>
199 public ArtToolInfo ArtToolInfo { get { return _ArtToolInfo; } set { _ArtToolInfo = value; } }
200 /// <summary>
201 /// Gets or Sets the ExporterInfo associated with this instance
202 /// </summary>
203 public ExporterInfo ExporterInfo { get { return _ExporterInfo; } set { _ExporterInfo = value; } }
204
205 /// <summary>
206 /// Gets or Sets the FromFileName associated with this instance
207 /// </summary>
208 [Browsable(true)]
209 public string FromFileName { get { return fromFileName; } set { fromFileName = value; } }
210
211 /// <summary>
212 /// Gets or Sets the FileName associated with this instance
213 /// </summary>
214 [Browsable(true)]
215 [Editor(typeof(UIGenericEditor<FilePath>), typeof(UITypeEditor))]
216 public FilePath FileName { get { return _FileName; } set { _FileName = value; } }
217
218 /// <summary>
219 /// Gets or Sets the Textures associated with this instance
220 /// </summary>
221 public List<Texture> Textures { get { return _Textures; } set { _Textures = value; } }
222 /// <summary>
223 /// Gets or Sets the Materials associated with this instance
224 /// </summary>
225 public List<Material> Materials { get { return _Materials; } set { _Materials = value; } }
226 /// <summary>
227 /// Gets or Sets the Skeletons associated with this instance
228 /// </summary>
229 public List<Skeleton> Skeletons { get { return _Skeletons; } set { _Skeletons = value; } }
230 #endregion
231
232 #region INativePointer Members
233 private IntPtr _NativePointer;
234 /// <summary>
235 /// When used in a derived class, gets the native pointer for this instance
236 /// </summary>
237 public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
238 #endregion
239
240 #region IExtendedData Members
241 private IntPtr _ExtendedData;
242 /// <summary>
243 /// When used in a derived class, gets the ExtendedData pointer for this instance
244 /// </summary>
245 public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
246 #endregion
247 }
248 }

  ViewVC Help
Powered by ViewVC 1.1.22