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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22