/[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 196 - (show annotations) (download)
Thu Jul 29 07:47:26 2010 UTC (11 years, 5 months ago) by william
File size: 9908 byte(s)
bulk commit

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 managed.Materials[i].Index = i;
131 Application.DoEvents();
132 }
133 }
134 else
135 {
136 managed.Materials = new List<Material>();
137 }
138
139 if (native.Skeletons.Pointer != IntPtr.Zero)
140 {
141 IntPtr[] skeletons = Helpers.ReadArrayFromMemory(native.Skeletons);
142 length = skeletons.Length;
143 managed.Skeletons = new List<Skeleton>(length);
144 foreach (IntPtr ptr in skeletons)
145 {
146 managed.Skeletons.Add(new Skeleton());
147 Application.DoEvents();
148 }
149 for (int i = 0; i < length; i++)
150 {
151 managed.Skeletons[i] = (Skeleton.ReadFromMemory(skeletons[i]));
152 managed.Skeletons[i].Index = i;
153 Application.DoEvents();
154 }
155 }
156 else
157 {
158 managed.Skeletons = new List<Skeleton>();
159 }
160
161 return managed;
162 }
163 catch (Exception ex)
164 {
165 Console.WriteLine(ex.ToString());
166 return default(grnfileinfo);
167 }
168 }
169
170
171 #region Igrnfileinfo Members
172
173 /// <summary>
174 /// Gets a value indicating if the instance contains ArtToolInfo
175 /// </summary>
176 public bool HaveArtToolInfo { get { if (this.ArtToolInfo == null) return false; return true; } }
177 /// <summary>
178 /// Gets a value indicating if the instance contains ExporterInfo
179 /// </summary>
180 public bool HaveExporterInfo { get { if (this.ExporterInfo == null) return false; return true; } }
181 /// <summary>
182 /// Gets a value indicating if the instance contains FromFileName
183 /// </summary>
184 public bool HaveFromFileName { get { if (this.FromFileName == null || this.FromFileName == "") return false; return true; } }
185 /// <summary>
186 /// Gets a value indicating if the instance contains Textures
187 /// </summary>
188 public bool HaveTextures { get { if (this.Textures == null || this.Textures.Count <= 0) return false; return true; } }
189 /// <summary>
190 /// Gets a value indicating if the instance contains Materials
191 /// </summary>
192 public bool HaveMaterials { get { if (this.Materials == null || this.Materials.Count <= 0) return false; return true; } }
193 /// <summary>
194 /// Gets a value indicating if the instance contains Skeletons
195 /// </summary>
196 public bool HaveSkeletons { get { if (this.Skeletons == null || this.Skeletons.Count <= 0) return false; return true; } }
197
198 /// <summary>
199 /// Gets or Sets the ArtToolInfo associated with this instance
200 /// </summary>
201 public ArtToolInfo ArtToolInfo { get { return _ArtToolInfo; } set { _ArtToolInfo = value; } }
202 /// <summary>
203 /// Gets or Sets the ExporterInfo associated with this instance
204 /// </summary>
205 public ExporterInfo ExporterInfo { get { return _ExporterInfo; } set { _ExporterInfo = value; } }
206
207 /// <summary>
208 /// Gets or Sets the FromFileName associated with this instance
209 /// </summary>
210 [Browsable(true)]
211 public string FromFileName { get { return fromFileName; } set { fromFileName = value; } }
212
213 /// <summary>
214 /// Gets or Sets the FileName associated with this instance
215 /// </summary>
216 [Browsable(true)]
217 [Editor(typeof(UIGenericEditor<FilePath>), typeof(UITypeEditor))]
218 public FilePath FileName { get { return _FileName; } set { _FileName = value; } }
219
220 /// <summary>
221 /// Gets or Sets the Textures associated with this instance
222 /// </summary>
223 public List<Texture> Textures { get { return _Textures; } set { _Textures = value; } }
224 /// <summary>
225 /// Gets or Sets the Materials associated with this instance
226 /// </summary>
227 public List<Material> Materials { get { return _Materials; } set { _Materials = value; } }
228 /// <summary>
229 /// Gets or Sets the Skeletons associated with this instance
230 /// </summary>
231 public List<Skeleton> Skeletons { get { return _Skeletons; } set { _Skeletons = value; } }
232 #endregion
233
234 #region INativePointer Members
235 private IntPtr _NativePointer;
236 /// <summary>
237 /// When used in a derived class, gets the native pointer for this instance
238 /// </summary>
239 public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
240 #endregion
241
242 #region IExtendedData Members
243 private IntPtr _ExtendedData;
244 /// <summary>
245 /// When used in a derived class, gets the ExtendedData pointer for this instance
246 /// </summary>
247 public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
248 #endregion
249 }
250 }

  ViewVC Help
Powered by ViewVC 1.1.22