summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorleo2002-10-10 20:39:12 +0000
committerleo2002-10-10 20:39:12 +0000
commit89a11141852de0a6c66a8065faf6454fb7d382be (patch)
tree840eb5b4bd2786bb8f258692897a23fb2ee5c341
parentd82784547a0f37e21c3b6e4a402009655fc531bf (diff)
Added functions to manage textures.
git-svn-id: http://svn.leocad.org/trunk@301 c7d43263-9d01-0410-8a33-9dba5d9f93d6
-rwxr-xr-xcommon/library.cpp1031
-rwxr-xr-xcommon/library.h114
-rw-r--r--win/LeoCAD.dsp279
-rw-r--r--win/LeoCAD.rc41
-rw-r--r--win/Libdlg.cpp11
-rw-r--r--win/resource.h12
-rw-r--r--win/texdlg.cpp116
-rw-r--r--win/texdlg.h50
8 files changed, 969 insertions, 685 deletions
diff --git a/common/library.cpp b/common/library.cpp
index 6d818d6..b0d3d4a 100755
--- a/common/library.cpp
+++ b/common/library.cpp
@@ -8,9 +8,16 @@
#include "pieceinf.h"
#include "texture.h"
#include "config.h"
+#include "image.h"
+#include "system.h"
// =============================================================================
// PiecesLibrary class
+
+const char PiecesLibrary::TexturesBinHeader[32] = "LeoCAD texture data file\0\0\0\0\0\0\0";
+const char PiecesLibrary::TexturesIdxHeader[32] = "LeoCAD texture index file\0\0\0\0\0\0";
+const int PiecesLibrary::TexturesFileVersion = 1;
+
PiecesLibrary::PiecesLibrary ()
{
strcpy (m_LibraryPath, "");
@@ -89,7 +96,6 @@ bool PiecesLibrary::Load (const char *libpath)
m_pPieceIdx = new PieceInfo[count];
m_nPieceCount = count;
- // workaround for VC++ error C2538: new : cannot specify initializer for arrays
for (PieceInfo *pElements = m_pPieceIdx; count--; pElements++)
pElements->LoadIndex (idx);
@@ -124,6 +130,8 @@ bool PiecesLibrary::Load (const char *libpath)
if (!idx.Open(filename, "rb"))
return false;
+ // FIXME: check header
+
idx.Seek(-(long)(sizeof(count)+sizeof(binsize)), SEEK_END);
idx.ReadLong (&binsize, 1);
idx.ReadShort (&count, 1);
@@ -151,6 +159,9 @@ bool PiecesLibrary::Load (const char *libpath)
return true;
}
+// =============================================================================
+// Search functions
+
// Remeber to make 'name' uppercase.
PieceInfo* PiecesLibrary::FindPieceInfo (const char* name) const
{
@@ -197,8 +208,665 @@ Texture* PiecesLibrary::FindTexture (const char* name) const
return NULL;
}
+Texture* PiecesLibrary::GetTexture (int index) const
+{
+ return &m_pTextures[index];
+}
+
+// =============================================================================
+// Pieces handling stuff
+
+// Remove pieces from the library
+bool PiecesLibrary::DeletePiece (char** names, int numpieces)
+{
+ FileDisk newbin, newidx, oldbin, oldidx;
+ char file1[LC_MAXPATH], file2[LC_MAXPATH], tmp[200];
+ lcuint16 count, deleted = 0, j;
+ void* membuf;
+
+ strcpy(file1, m_LibraryPath);
+ strcat(file1, "pieces-b.old");
+ remove(file1);
+ strcpy(file2, m_LibraryPath);
+ strcat(file2, "pieces.bin");
+ rename(file2, file1);
+
+ if ((!oldbin.Open(file1, "rb")) ||
+ (!newbin.Open(file2, "wb")))
+ return false;
+
+ strcpy(file1, m_LibraryPath);
+ strcat(file1, "pieces-i.old");
+ remove(file1);
+ strcpy(file2, m_LibraryPath);
+ strcat(file2, "pieces.idx");
+ rename(file2, file1);
+
+ if ((!oldidx.Open(file1, "rb")) ||
+ (!newidx.Open(file2, "wb")))
+ return false;
+
+ oldidx.Seek(-2, SEEK_END);
+ oldidx.ReadShort(&count, 1);
+ oldidx.Seek(0, SEEK_SET);
+ oldidx.Read(tmp, 34);
+ newidx.Write(tmp, 34);
+ oldbin.Read(tmp, 32);
+ newbin.Write(tmp, 32);
+
+// CProgressDlg dlg("Deleting");
+// dlg.Create(this);
+// dlg.SetRange (0, count);
+
+ for (j = 0; j < count; j++)
+ {
+// dlg.StepIt();
+// dlg.SetStatus(m_Parts[j].info->m_strDescription);
+
+// if (dlg.CheckCancelButton())
+// if (AfxMessageBox(IDS_CANCEL_PROMPT, MB_YESNO) == IDYES)
+// break;
+
+ char name[9];
+ int i;
+ name[8] = 0;
+ oldidx.Read(&name, 8);
+
+ for (i = 0; i < numpieces; i++)
+ if (strcmp(name, names[i]) == 0)
+ break;
+
+ if (i != numpieces)
+ {
+ oldidx.Seek(64+12+1+4+4+4, SEEK_CUR);
+ deleted++;
+ continue;
+ }
+
+ newidx.Write(name, 8);
+ oldidx.Read(tmp, 64+12+1+4);
+ newidx.Write(tmp, 64+12+1+4);
+
+ unsigned long binoff = newbin.GetLength(), size;
+ newidx.WriteLong(&binoff, 1);
+ oldidx.ReadLong(&binoff, 1);
+ oldidx.ReadLong(&size, 1);
+ newidx.WriteLong(&size, 1);
+
+ membuf = malloc(size);
+ oldbin.Seek(binoff, SEEK_SET);
+ oldbin.Read(membuf, size);
+ newbin.Write(membuf, size);
+ free(membuf);
+ }
+
+ // list of moved pieces
+ unsigned short moved, cs;
+
+ oldidx.Seek(-(2+4+2), SEEK_END);
+ oldidx.ReadShort(&moved, 1);
+ cs = 2+(moved*16);
+ oldidx.Seek(-(long)cs, SEEK_CUR);
+ membuf = malloc(cs);
+ oldidx.Read(membuf, cs);
+ newidx.Write(membuf, cs);
+ free(membuf);
+
+ // info at the end
+ unsigned long binoff = newbin.GetPosition();
+ newidx.WriteLong(&binoff, 1);
+ count -= deleted;
+ newidx.WriteShort(&count, 1);
+
+ oldidx.Close();
+ oldbin.Close();
+ newidx.Close();
+ newbin.Close();
+
+ return true;
+}
+
+// Load update
+bool PiecesLibrary::LoadUpdate (const char* update)
+{
+ FileDisk newbin, newidx, oldbin, oldidx, up;
+ char file1[LC_MAXPATH], file2[LC_MAXPATH], tmp[200];
+ unsigned short changes, moved, count, i, j, newcount = 0;
+ unsigned long cs, group, binoff;
+ unsigned char bt;
+ void* membuf;
+
+ typedef struct
+ {
+ char name[9];
+ unsigned char type;
+ unsigned long offset;
+ } LC_UPDATE_INFO;
+ LC_UPDATE_INFO* upinfo;
+
+ strcpy(file1, m_LibraryPath);
+ strcat(file1, "pieces-b.old");
+ remove(file1);
+ strcpy(file2, m_LibraryPath);
+ strcat(file2, "pieces.bin");
+ rename(file2, file1);
+
+ if ((!oldbin.Open(file1, "rb")) ||
+ (!newbin.Open(file2, "wb")))
+ return false;
+
+ strcpy(file1, m_LibraryPath);
+ strcat(file1, "pieces-i.old");
+ remove(file1);
+ strcpy(file2, m_LibraryPath);
+ strcat(file2, "pieces.idx");
+ rename(file2, file1);
+
+ if ((!oldidx.Open(file1, "rb")) ||
+ (!newidx.Open(file2, "wb")))
+ return false;
+
+ if (!up.Open(update, "rb"))
+ return false;
+
+ up.Seek(32, SEEK_SET);
+ up.ReadByte(&bt, 1);
+ if (bt != 2)
+ return false; // wrong version
+
+ up.ReadByte(&bt, 1); // update number
+
+ up.Seek(-2, SEEK_END);
+ up.ReadShort(&changes, 1);
+ up.Seek(34, SEEK_SET);
+
+ oldidx.Seek(-2, SEEK_END);
+ oldidx.ReadShort(&count, 1);
+ oldidx.Seek(0, SEEK_SET);
+ oldidx.Read(tmp, 34);
+ newidx.Write(tmp, 33); // skip update byte
+ newidx.WriteByte(&bt, 1);
+ oldbin.Read(tmp, 32);
+ newbin.Write(tmp, 32);
+
+ upinfo = (LC_UPDATE_INFO*)malloc(sizeof(LC_UPDATE_INFO)*changes);
+ memset(upinfo, 0, sizeof(LC_UPDATE_INFO)*changes);
+
+ for (i = 0; i < changes; i++)
+ {
+ up.Read(&upinfo[i].name, 8);
+ up.Read(&upinfo[i].type, 1);
+ upinfo[i].offset = up.GetPosition();
+
+ if ((upinfo[i].type & LC_UPDATE_DESCRIPTION) ||
+ (upinfo[i].type & LC_UPDATE_NEWPIECE))
+ up.Seek(64+4, SEEK_CUR);
+
+ if ((upinfo[i].type & LC_UPDATE_DRAWINFO) ||
+ (upinfo[i].type & LC_UPDATE_NEWPIECE))
+ {
+ up.Seek(12+1, SEEK_CUR);
+ up.ReadLong(&cs, 1);
+ up.Seek(cs, SEEK_CUR);
+ }
+ }
+
+// CProgressDlg dlg(_T("Updating Library"));
+// dlg.Create(this);
+// dlg.SetRange (0, count);
+
+ for (i = 0; i < count; i++)
+ {
+ char name[9];
+ name[8] = 0;
+ oldidx.Read (&name, 8);
+
+// dlg.StepIt();
+// if(dlg.CheckCancelButton())
+// if(AfxMessageBox(IDS_CANCEL_PROMPT, MB_YESNO) == IDYES)
+// {
+// free(upinfo);
+// return TRUE;
+// }
+
+ for (j = 0; j < changes; j++)
+ if (strcmp(name, upinfo[j].name) == 0)
+ {
+ if (upinfo[j].type == LC_UPDATE_DELETE)
+ {
+ oldidx.Seek(64+12+1+4+4+4, SEEK_CUR);
+ break;
+ }
+
+ newcount++;
+ up.Seek(upinfo[j].offset, SEEK_SET);
+ newidx.Write(name, 8);
+
+ // description
+ if (upinfo[j].type & LC_UPDATE_DESCRIPTION)
+ {
+ up.Read(&tmp, 64);
+ up.Read(&group, 4);
+ oldidx.Seek(64, SEEK_CUR);
+ }
+ else
+ oldidx.Read(&tmp, 64);
+ newidx.Write(tmp, 64);
+// dlg.SetStatus(tmp);
+
+ // bounding box & flags
+ if (upinfo[j].type & LC_UPDATE_DRAWINFO)
+ {
+ up.Read(&tmp, 12+1);
+ oldidx.Seek(12+1, SEEK_CUR);
+ }
+ else
+ oldidx.Read(&tmp, 12+1);
+ newidx.Write(tmp, 12+1);
+
+ // group
+ if (upinfo[j].type & LC_UPDATE_DESCRIPTION)
+ oldidx.Seek(4, SEEK_CUR);
+ else
+ oldidx.Read(&group, 4);
+ newidx.Write(&group, 4);
+
+ binoff = newbin.GetLength();
+ newidx.WriteLong(&binoff, 1);
+
+ if (upinfo[j].type & LC_UPDATE_DRAWINFO)
+ {
+ up.ReadLong(&cs, 1);
+ oldidx.Seek(4+4, SEEK_CUR);
+
+ membuf = malloc(cs);
+ up.Read(membuf, cs);
+ newbin.Write(membuf, cs);
+ free(membuf);
+ }
+ else
+ {
+ oldidx.ReadLong(&binoff, 1);
+ oldidx.ReadLong(&cs, 1);
+
+ membuf = malloc(cs);
+ oldbin.Seek(binoff, SEEK_SET);
+ oldbin.Read(membuf, cs);
+ newbin.Write(membuf, cs);
+ free(membuf);
+ }
+ newidx.WriteLong(&cs, 1);
+ break;
+ }
+
+ // not changed, just copy
+ if (j == changes)
+ {
+ newcount++;
+ newidx.Write(name, 8);
+ oldidx.Read(tmp, 64+12+1+4);
+ newidx.Write(tmp, 64+12+1+4);
+ binoff = newbin.GetLength();
+ newidx.WriteLong(&binoff, 1);
+ oldidx.ReadLong(&binoff, 1);
+ oldidx.ReadLong(&cs, 1);
+ newidx.WriteLong(&cs, 1);
+
+// tmp[64] = 0;
+// dlg.SetStatus(tmp);
+
+ membuf = malloc(cs);
+ oldbin.Seek(binoff, SEEK_SET);
+ oldbin.Read(membuf, cs);
+ newbin.Write(membuf, cs);
+ free(membuf);
+ }
+ }
+
+ // now add new pieces
+ for (j = 0; j < changes; j++)
+ if (upinfo[j].type == LC_UPDATE_NEWPIECE)
+ {
+ newcount++;
+ newidx.Write(upinfo[j].name, 8);
+ up.Seek(upinfo[j].offset, SEEK_SET);
+ up.Read(&tmp, 64+12);
+ newidx.Write(tmp, 64+12);
+ up.Read(&group, 4);
+ up.Read(&bt, 1);
+ newidx.Write(&bt, 1);
+ newidx.Write(&group, 4);
+ binoff = newbin.GetLength();
+ newidx.WriteLong(&binoff, 1);
+
+ up.ReadLong(&cs, 1);
+ membuf = malloc(cs);
+ up.Read(membuf, cs);
+ newbin.Write(membuf, cs);
+ up.WriteLong(&cs, 1);
+ newidx.WriteLong(&cs, 1);
+ free (membuf);
+ }
+
+ up.Seek(-(2+2), SEEK_END);
+ up.ReadShort(&moved, 1);
+ cs = 2+moved*16;
+ up.Seek(-(long)(cs), SEEK_CUR);
+ membuf = malloc(cs);
+ up.Read(membuf, cs);
+ newidx.Write(membuf, cs);
+ free(membuf);
+
+ binoff = newbin.GetLength();
+ newidx.WriteLong(&binoff, 1);
+ newidx.WriteShort(&newcount, 1);
+
+ free(upinfo);
+ oldidx.Close();
+ oldbin.Close();
+ newidx.Close();
+ newbin.Close();
+ up.Close();
+
+ return true;
+}
+
+// =============================================================================
+// Textures handling stuff
+
+bool PiecesLibrary::DeleteTextures (char** Names, int NumTextures)
+{
+ char file1[LC_MAXPATH], file2[LC_MAXPATH];
+ FileDisk newbin, newidx, oldbin, oldidx;
+ lcuint32 binsize, offset = 0;
+ lcuint16 count, deleted = 0, i, j;
+ lcuint8 version, bt;
+
+ // Backup files
+ strcpy(file1, m_LibraryPath);
+ strcat(file1, "tex-b.old");
+ remove(file1);
+ strcpy(file2, m_LibraryPath);
+ strcat(file2, "textures.bin");
+ rename(file2, file1);
+
+ if ((!oldbin.Open(file1, "rb")) || (!newbin.Open(file2, "wb")))
+ return false;
+
+ strcpy(file1, m_LibraryPath);
+ strcat(file1, "tex-i.old");
+ remove(file1);
+ strcpy(file2, m_LibraryPath);
+ strcat(file2, "textures.idx");
+ rename(file2, file1);
+
+ if ((!oldidx.Open(file1, "rb")) || (!newidx.Open(file2, "wb")))
+ return false;
+
+ // Write the headers
+ newidx.Write (TexturesIdxHeader, sizeof (TexturesIdxHeader));
+ bt = 1; // version
+ newidx.WriteByte (&bt, 1);
+ bt = 0; // last update (unused for now)
+ newidx.WriteByte (&bt, 1);
+
+ newbin.Write (TexturesBinHeader, sizeof (TexturesBinHeader));
+ offset += sizeof (TexturesBinHeader);
+
+ oldidx.Seek(-(long)(sizeof(count)+sizeof(binsize)), SEEK_END);
+ oldidx.ReadLong (&binsize, 1);
+ oldidx.ReadShort (&count, 1);
+ oldidx.Seek(32, SEEK_SET);
+ oldidx.ReadByte (&version, 1);
+
+ if ((version != TexturesFileVersion) || (count == 0))
+ return false;
+
+ oldidx.Seek(34, SEEK_SET); // skip update byte
+
+ for (i = 0; i < count; i++)
+ {
+ lcuint32 OldOffset, FileSize;
+ lcuint16 Width, Height;
+ char TexName[9];
+ TexName[8] = 0;
+
+ oldidx.Read (TexName, 8);
+ oldidx.ReadShort (&Width, 1);
+ oldidx.ReadShort (&Height, 1);
+ oldidx.ReadByte (&bt, 1);
+
+ switch (bt)
+ {
+ case LC_INTENSITY:
+ FileSize = Width*Height;
+ break;
+
+ case LC_RGB:
+ FileSize = Width*Height*3;
+ break;
+
+ case LC_RGBA:
+ FileSize = Width*Height*4;
+ break;
+ }
+
+ oldidx.ReadLong(&OldOffset, 1);
+
+ for (j = 0; j < NumTextures; j++)
+ if (strcmp(TexName, Names[j]) == 0)
+ break;
+
+ if (j != NumTextures)
+ {
+ deleted++;
+ continue;
+ }
+
+ // Write index for this texture
+ newidx.Write (TexName, 8);
+ newidx.WriteShort (&Width, 1);
+ newidx.WriteShort (&Height, 1);
+ newidx.WriteByte (&bt, 1);
+ newidx.WriteLong (&offset, 1);
+
+ offset += FileSize;
+
+ // Copy texture data
+ void *membuf = malloc (FileSize);
+ oldbin.Seek (OldOffset, SEEK_SET);
+ oldbin.Read (membuf, FileSize);
+ newbin.Write (membuf, FileSize);
+ free (membuf);
+ }
+
+ newidx.WriteLong (&offset, 1);
+ count -= deleted;
+ newidx.WriteShort (&count, 1);
+
+ return true;
+}
+
+bool PiecesLibrary::ImportTexture (const char* Name)
+{
+ char file1[LC_MAXPATH], file2[LC_MAXPATH];
+ FileDisk newbin, newidx, oldbin, oldidx;
+ lcuint32 FileSize, binsize, offset = 0;
+ lcuint16 Width, Height, count, deleted = 0, i;
+ lcuint8 version, bt;
+ Image img;
+
+ if (!img.FileLoad (Name))
+ return false;
+
+ // Backup files
+ strcpy(file1, m_LibraryPath);
+ strcat(file1, "tex-b.old");
+ remove(file1);
+ strcpy(file2, m_LibraryPath);
+ strcat(file2, "textures.bin");
+ rename(file2, file1);
+
+ if ((!oldbin.Open(file1, "rb")) || (!newbin.Open(file2, "wb")))
+ return false;
+
+ strcpy(file1, m_LibraryPath);
+ strcat(file1, "tex-i.old");
+ remove(file1);
+ strcpy(file2, m_LibraryPath);
+ strcat(file2, "textures.idx");
+ rename(file2, file1);
+
+ if ((!oldidx.Open(file1, "rb")) || (!newidx.Open(file2, "wb")))
+ return false;
+
+ // Get the file name
+ char* p, NewTexName[9];
+
+ strcpy(file1, Name);
+ p = strrchr(file1, '.');
+ *p = 0;
+ p = strrchr(file1, '\\');
+ if (!p)
+ p = strrchr(file1, '/');
+ if (!p)
+ p = file1;
+ strupr(p);
+ p++;
+
+ memset(NewTexName, 0, 9);
+ strcpy(NewTexName, p);
+
+ if (FindTexture (NewTexName) != NULL)
+ Sys_MessageBox ("Texture already exists in the library !");
+
+ // Write the headers
+ newidx.Write (TexturesIdxHeader, sizeof (TexturesIdxHeader));
+ bt = 1; // version
+ newidx.WriteByte (&bt, 1);
+ bt = 0; // last update (unused for now)
+ newidx.WriteByte (&bt, 1);
+
+ newbin.Write (TexturesBinHeader, sizeof (TexturesBinHeader));
+ offset += sizeof (TexturesBinHeader);
+
+ oldidx.Seek(-(long)(sizeof(count)+sizeof(binsize)), SEEK_END);
+ oldidx.ReadLong (&binsize, 1);
+ oldidx.ReadShort (&count, 1);
+ oldidx.Seek(32, SEEK_SET);
+ oldidx.ReadByte (&version, 1);
+
+ if (version != TexturesFileVersion)
+ return false;
+
+ oldidx.Seek(34, SEEK_SET); // skip update byte
+
+ for (i = 0; i < count; i++)
+ {
+ lcuint32 OldOffset, FileSize;
+ lcuint16 Width, Height;
+ char TexName[9];
+ TexName[8] = 0;
+
+ oldidx.Read (TexName, 8);
+ oldidx.ReadShort (&Width, 1);
+ oldidx.ReadShort (&Height, 1);
+ oldidx.ReadByte (&bt, 1);
+
+ switch (bt)
+ {
+ case LC_INTENSITY:
+ FileSize = Width*Height;
+ break;
+
+ case LC_RGB:
+ FileSize = Width*Height*3;
+ break;
+
+ case LC_RGBA:
+ FileSize = Width*Height*4;
+ break;
+ }
+
+ oldidx.ReadLong(&OldOffset, 1);
+
+ if (strcmp(TexName, NewTexName) == 0)
+ {
+ deleted++;
+ continue;
+ }
+
+ // Write index for this texture
+ newidx.Write (TexName, 8);
+ newidx.WriteShort (&Width, 1);
+ newidx.WriteShort (&Height, 1);
+ newidx.WriteByte (&bt, 1);
+ newidx.WriteLong (&offset, 1);
+
+ offset += FileSize;
+
+ // Copy texture data
+ void *membuf = malloc (FileSize);
+ oldbin.Seek (OldOffset, SEEK_SET);
+ oldbin.Read (membuf, FileSize);
+ newbin.Write (membuf, FileSize);
+ free (membuf);
+ }
+
+ // Save the new texture
+ Width = img.Width ();
+ Height = img.Height ();
+ count++;
+
+ // FIXME: This should be an option when you choose the file but I'll leave it hardcoded for now.
+ if (!strcmp (NewTexName, "SYSFONT"))
+ {
+ lcuint8* buf = img.GetData();
+ int w = img.Alpha () ? 4 : 3;
+
+ for (i = 0; i < Width*Height; i++)
+ {
+ if (buf[i*w] > 0 || buf[i*w+1] > 0 || buf[i*w+2] > 0)
+ bt = 255;
+ else
+ bt = 0;
+
+ newbin.WriteByte (&bt, 1);
+ }
+
+ FileSize = Width*Height;
+ bt = LC_INTENSITY;
+ }
+ else
+ {
+ if (img.Alpha ())
+ {
+ FileSize = Width*Height*4;
+ bt = LC_RGBA;
+ }
+ else
+ {
+ FileSize = Width*Height*3;
+ bt = LC_RGB;
+ }
+ newbin.Write (img.GetData(), FileSize);
+ }
+ newidx.Write (NewTexName, 8);
+ newidx.WriteShort (&Width, 1);
+ newidx.WriteShort (&Height, 1);
+ newidx.WriteByte (&bt, 1);
+ newidx.WriteLong (&offset, 1);
+
+ offset += FileSize;
+
+ newidx.WriteLong (&offset, 1);
+ count -= deleted;
+ newidx.WriteShort (&count, 1);
+
+ return true;
+}
@@ -211,7 +879,6 @@ Texture* PiecesLibrary::FindTexture (const char* name) const
#include "globals.h"
#include "project.h"
#include "matrix.h"
-#include "system.h"
// =============================================================================
@@ -337,7 +1004,7 @@ void LibraryDialog::HandleCommand (int id)
if (!SystemDoDialog (LC_DLG_FILE_OPEN, filename))
return;
- LoadUpdate (filename);
+ project->GetPiecesLibrary ()->LoadUpdate (filename);
// update m_Parts
UpdateList();
@@ -1779,361 +2446,3 @@ void FreeLDrawPiece(LC_LDRAW_PIECE* piece)
// ========================================================
-// Remove pieces from the library
-bool DeletePiece(char** names, int numpieces)
-{
- FileDisk newbin, newidx, oldbin, oldidx;
- char file1[LC_MAXPATH], file2[LC_MAXPATH], tmp[200];
- unsigned short count, deleted = 0, j;
- void* membuf;
- PiecesLibrary *pLib = project->GetPiecesLibrary ();
-
- strcpy(file1, pLib->GetLibraryPath());
- strcat(file1, "pieces-b.old");
- remove(file1);
- strcpy(file2, pLib->GetLibraryPath());
- strcat(file2, "pieces.bin");
- rename(file2, file1);
-
- if ((!oldbin.Open(file1, "rb")) ||
- (!newbin.Open(file2, "wb")))
- return false;
-
- strcpy(file1, pLib->GetLibraryPath());
- strcat(file1, "pieces-i.old");
- remove(file1);
- strcpy(file2, pLib->GetLibraryPath());
- strcat(file2, "pieces.idx");
- rename(file2, file1);
-
- if ((!oldidx.Open(file1, "rb")) ||
- (!newidx.Open(file2, "wb")))
- return false;
-
- oldidx.Seek(-2, SEEK_END);
- oldidx.ReadShort(&count, 1);
- oldidx.Seek(0, SEEK_SET);
- oldidx.Read(tmp, 34);
- newidx.Write(tmp, 34);
- oldbin.Read(tmp, 32);
- newbin.Write(tmp, 32);
-
-// CProgressDlg dlg("Deleting");
-// dlg.Create(this);
-// dlg.SetRange (0, count);
-
- for (j = 0; j < count; j++)
- {
-// dlg.StepIt();
-// dlg.SetStatus(m_Parts[j].info->m_strDescription);
-
-// if (dlg.CheckCancelButton())
-// if (AfxMessageBox(IDS_CANCEL_PROMPT, MB_YESNO) == IDYES)
-// break;
-
- char name[9];
- int i;
- name[8] = 0;
- oldidx.Read(&name, 8);
-
- for (i = 0; i < numpieces; i++)
- if (strcmp(name, names[i]) == 0)
- break;
-
- if (i != numpieces)
- {
- oldidx.Seek(64+12+1+4+4+4, SEEK_CUR);
- deleted++;
- continue;
- }
-
- newidx.Write(name, 8);
- oldidx.Read(tmp, 64+12+1+4);
- newidx.Write(tmp, 64+12+1+4);
-
- unsigned long binoff = newbin.GetLength(), size;
- newidx.WriteLong(&binoff, 1);
- oldidx.ReadLong(&binoff, 1);
- oldidx.ReadLong(&size, 1);
- newidx.WriteLong(&size, 1);
-
- membuf = malloc(size);
- oldbin.Seek(binoff, SEEK_SET);
- oldbin.Read(membuf, size);
- newbin.Write(membuf, size);
- free(membuf);
- }
-
- // list of moved pieces
- unsigned short moved, cs;
-
- oldidx.Seek(-(2+4+2), SEEK_END);
- oldidx.ReadShort(&moved, 1);
- cs = 2+(moved*16);
- oldidx.Seek(-(long)cs, SEEK_CUR);
- membuf = malloc(cs);
- oldidx.Read(membuf, cs);
- newidx.Write(membuf, cs);
- free(membuf);
-
- // info at the end
- unsigned long binoff = newbin.GetPosition();
- newidx.WriteLong(&binoff, 1);
- count -= deleted;
- newidx.WriteShort(&count, 1);
-
- oldidx.Close();
- oldbin.Close();
- newidx.Close();
- newbin.Close();
-
- return true;
-}
-
-// ========================================================
-
-// Load update
-bool LoadUpdate(const char* update)
-{
- FileDisk newbin, newidx, oldbin, oldidx, up;
- char file1[LC_MAXPATH], file2[LC_MAXPATH], tmp[200];
- unsigned short changes, moved, count, i, j, newcount = 0;
- unsigned long cs, group, binoff;
- unsigned char bt;
- void* membuf;
- PiecesLibrary *pLib = project->GetPiecesLibrary ();
-
- typedef struct
- {
- char name[9];
- unsigned char type;
- unsigned long offset;
- } LC_UPDATE_INFO;
- LC_UPDATE_INFO* upinfo;
-
- strcpy(file1, pLib->GetLibraryPath());
- strcat(file1, "pieces-b.old");
- remove(file1);
- strcpy(file2, pLib->GetLibraryPath());
- strcat(file2, "pieces.bin");
- rename(file2, file1);
-
- if ((!oldbin.Open(file1, "rb")) ||
- (!newbin.Open(file2, "wb")))
- return false;
-
- strcpy(file1, pLib->GetLibraryPath());
- strcat(file1, "pieces-i.old");
- remove(file1);
- strcpy(file2, pLib->GetLibraryPath());
- strcat(file2, "pieces.idx");
- rename(file2, file1);
-
- if ((!oldidx.Open(file1, "rb")) ||
- (!newidx.Open(file2, "wb")))
- return false;
-
- if (!up.Open(update, "rb"))
- return false;
-
- up.Seek(32, SEEK_SET);
- up.ReadByte(&bt, 1);
- if (bt != 2)
- return false; // wrong version
-
- up.ReadByte(&bt, 1); // update number
-
- up.Seek(-2, SEEK_END);
- up.ReadShort(&changes, 1);
- up.Seek(34, SEEK_SET);
-
- oldidx.Seek(-2, SEEK_END);
- oldidx.ReadShort(&count, 1);
- oldidx.Seek(0, SEEK_SET);
- oldidx.Read(tmp, 34);
- newidx.Write(tmp, 33); // skip update byte
- newidx.WriteByte(&bt, 1);
- oldbin.Read(tmp, 32);
- newbin.Write(tmp, 32);
-
- upinfo = (LC_UPDATE_INFO*)malloc(sizeof(LC_UPDATE_INFO)*changes);
- memset(upinfo, 0, sizeof(LC_UPDATE_INFO)*changes);
-
- for (i = 0; i < changes; i++)
- {
- up.Read(&upinfo[i].name, 8);
- up.Read(&upinfo[i].type, 1);
- upinfo[i].offset = up.GetPosition();
-
- if ((upinfo[i].type & LC_UPDATE_DESCRIPTION) ||
- (upinfo[i].type & LC_UPDATE_NEWPIECE))
- up.Seek(64+4, SEEK_CUR);
-
- if ((upinfo[i].type & LC_UPDATE_DRAWINFO) ||
- (upinfo[i].type & LC_UPDATE_NEWPIECE))
- {
- up.Seek(12+1, SEEK_CUR);
- up.ReadLong(&cs, 1);
- up.Seek(cs, SEEK_CUR);
- }
- }
-
-// CProgressDlg dlg(_T("Updating Library"));
-// dlg.Create(this);
-// dlg.SetRange (0, count);
-
- for (i = 0; i < count; i++)
- {
- char name[9];
- name[8] = 0;
- oldidx.Read (&name, 8);
-
-// dlg.StepIt();
-// if(dlg.CheckCancelButton())
-// if(AfxMessageBox(IDS_CANCEL_PROMPT, MB_YESNO) == IDYES)
-// {
-// free(upinfo);
-// return TRUE;
-// }
-
- for (j = 0; j < changes; j++)
- if (strcmp(name, upinfo[j].name) == 0)
- {
- if (upinfo[j].type == LC_UPDATE_DELETE)
- {
- oldidx.Seek(64+12+1+4+4+4, SEEK_CUR);
- break;
- }
-
- newcount++;
- up.Seek(upinfo[j].offset, SEEK_SET);
- newidx.Write(name, 8);
-
- // description
- if (upinfo[j].type & LC_UPDATE_DESCRIPTION)
- {
- up.Read(&tmp, 64);
- up.Read(&group, 4);
- oldidx.Seek(64, SEEK_CUR);
- }
- else
- oldidx.Read(&tmp, 64);
- newidx.Write(tmp, 64);
-// dlg.SetStatus(tmp);
-
- // bounding box & flags
- if (upinfo[j].type & LC_UPDATE_DRAWINFO)
- {
- up.Read(&tmp, 12+1);
- oldidx.Seek(12+1, SEEK_CUR);
- }
- else
- oldidx.Read(&tmp, 12+1);
- newidx.Write(tmp, 12+1);
-
- // group
- if (upinfo[j].type & LC_UPDATE_DESCRIPTION)
- oldidx.Seek(4, SEEK_CUR);
- else
- oldidx.Read(&group, 4);
- newidx.Write(&group, 4);
-
- binoff = newbin.GetLength();
- newidx.WriteLong(&binoff, 1);
-
- if (upinfo[j].type & LC_UPDATE_DRAWINFO)
- {
- up.ReadLong(&cs, 1);
- oldidx.Seek(4+4, SEEK_CUR);
-
- membuf = malloc(cs);
- up.Read(membuf, cs);
- newbin.Write(membuf, cs);
- free(membuf);
- }
- else
- {
- oldidx.ReadLong(&binoff, 1);
- oldidx.ReadLong(&cs, 1);
-
- membuf = malloc(cs);
- oldbin.Seek(binoff, SEEK_SET);
- oldbin.Read(membuf, cs);
- newbin.Write(membuf, cs);
- free(membuf);
- }
- newidx.WriteLong(&cs, 1);
- break;
- }
-
- // not changed, just copy
- if (j == changes)
- {
- newcount++;
- newidx.Write(name, 8);
- oldidx.Read(tmp, 64+12+1+4);
- newidx.Write(tmp, 64+12+1+4);
- binoff = newbin.GetLength();
- newidx.WriteLong(&binoff, 1);
- oldidx.ReadLong(&binoff, 1);
- oldidx.ReadLong(&cs, 1);
- newidx.WriteLong(&cs, 1);
-
-// tmp[64] = 0;
-// dlg.SetStatus(tmp);
-
- membuf = malloc(cs);
- oldbin.Seek(binoff, SEEK_SET);
- oldbin.Read(membuf, cs);
- newbin.Write(membuf, cs);
- free(membuf);
- }
- }
-
- // now add new pieces
- for (j = 0; j < changes; j++)
- if (upinfo[j].type == LC_UPDATE_NEWPIECE)
- {
- newcount++;
- newidx.Write(upinfo[j].name, 8);
- up.Seek(upinfo[j].offset, SEEK_SET);
- up.Read(&tmp, 64+12);
- newidx.Write(tmp, 64+12);
- up.Read(&group, 4);
- up.Read(&bt, 1);
- newidx.Write(&bt, 1);
- newidx.Write(&group, 4);
- binoff = newbin.GetLength();
- newidx.WriteLong(&binoff, 1);
-
- up.ReadLong(&cs, 1);
- membuf = malloc(cs);
- up.Read(membuf, cs);
- newbin.Write(membuf, cs);
- up.WriteLong(&cs, 1);
- newidx.WriteLong(&cs, 1);
- free (membuf);
- }
-
- up.Seek(-(2+2), SEEK_END);
- up.ReadShort(&moved, 1);
- cs = 2+moved*16;
- up.Seek(-(long)(cs), SEEK_CUR);
- membuf = malloc(cs);
- up.Read(membuf, cs);
- newidx.Write(membuf, cs);
- free(membuf);
-
- binoff = newbin.GetLength();
- newidx.WriteLong(&binoff, 1);
- newidx.WriteShort(&newcount, 1);
-
- free(upinfo);
- oldidx.Close();
- oldbin.Close();
- newidx.Close();
- newbin.Close();
- up.Close();
-
- return true;
-}
diff --git a/common/library.h b/common/library.h
index bf550de..36338c0 100755
--- a/common/library.h
+++ b/common/library.h
@@ -16,14 +16,24 @@ public:
{ return m_LibraryPath; }
int GetPieceCount () const
{ return m_nPieceCount; }
+ int GetTextureCount () const
+ { return m_nTextureCount; }
bool Load (const char* libpath);
void Unload ();
+ // Search for stuff
PieceInfo* FindPieceInfo (const char* name) const;
PieceInfo* GetPieceInfo (int index) const;
int GetPieceIndex (PieceInfo *pInfo) const;
Texture* FindTexture (const char* name) const;
+ Texture* GetTexture (int index) const;
+
+ // File operations
+ bool DeletePiece (char** names, int numpieces);
+ bool LoadUpdate (const char* update);
+ bool DeleteTextures (char** Names, int NumTextures);
+ bool ImportTexture (const char* Name);
protected:
char m_LibraryPath[LC_MAXPATH]; // path to the library files
@@ -34,8 +44,63 @@ protected:
PieceInfo* m_pPieceIdx; // pieces array
int m_nTextureCount; // number of textures
Texture* m_pTextures; // textures array
+
+ // File headers
+ static const char TexturesBinHeader[32];
+ static const char TexturesIdxHeader[32];
+ static const int TexturesFileVersion;
};
+// This should be cleaned and moved to the PiecesLibrary class
+typedef struct connection_s
+{
+ unsigned char type;
+ float pos[3];
+ float up[3];
+ connection_s* next;
+} connection_t;
+
+typedef struct group_s
+{
+ connection_t* connections[5];
+ void* drawinfo;
+ unsigned long infosize;
+ group_s* next;
+} group_t;
+
+typedef struct lineinfo_s
+{
+ unsigned char type;
+ unsigned char color;
+ float points[12];
+ lineinfo_s* next;
+} lineinfo_t;
+
+typedef struct texture_s
+{
+ float points[20];
+ unsigned char color;
+ char name[9];
+ texture_s* next;
+} texture_t;
+
+typedef struct
+{
+ float* verts;
+ unsigned int verts_count;
+ connection_t* connections;
+ group_t* groups;
+ texture_t* textures;
+ char name[9];
+ char description[65];
+} LC_LDRAW_PIECE;
+
+bool ReadLDrawPiece(const char* filename, LC_LDRAW_PIECE* piece);
+bool SaveLDrawPiece(LC_LDRAW_PIECE* piece);
+void FreeLDrawPiece(LC_LDRAW_PIECE* piece);
+
+// And this should be moved to a different file (libdlg.h ?)
+
#include "basewnd.h"
typedef enum {
@@ -130,53 +195,4 @@ class LibraryDialog : public BaseWnd
char m_strFile[LC_MAXPATH];
};
-typedef struct connection_s
-{
- unsigned char type;
- float pos[3];
- float up[3];
- connection_s* next;
-} connection_t;
-
-typedef struct group_s
-{
- connection_t* connections[5];
- void* drawinfo;
- unsigned long infosize;
- group_s* next;
-} group_t;
-
-typedef struct lineinfo_s
-{
- unsigned char type;
- unsigned char color;
- float points[12];
- lineinfo_s* next;
-} lineinfo_t;
-
-typedef struct texture_s
-{
- float points[20];
- unsigned char color;
- char name[9];
- texture_s* next;
-} texture_t;
-
-typedef struct
-{
- float* verts;
- unsigned int verts_count;
- connection_t* connections;
- group_t* groups;
- texture_t* textures;
- char name[9];
- char description[65];
-} LC_LDRAW_PIECE;
-
-bool ReadLDrawPiece(const char* filename, LC_LDRAW_PIECE* piece);
-bool SaveLDrawPiece(LC_LDRAW_PIECE* piece);
-void FreeLDrawPiece(LC_LDRAW_PIECE* piece);
-bool DeletePiece(char** names, int numpieces);
-bool LoadUpdate(const char* update);
-
#endif // _LIBRARY_H_
diff --git a/win/LeoCAD.dsp b/win/LeoCAD.dsp
index a86782a..803a425 100644
--- a/win/LeoCAD.dsp
+++ b/win/LeoCAD.dsp
@@ -1,5 +1,5 @@
# Microsoft Developer Studio Project File - Name="LeoCAD" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# Microsoft Developer Studio Generated Build File, Format Version 60000
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
@@ -25,7 +25,7 @@ CFG=LeoCAD - Win32 Debug
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
-CPP=cl.exe
+CPP=snCl.exe
MTL=midl.exe
RSC=rc.exe
@@ -51,7 +51,7 @@ RSC=rc.exe
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
-LINK32=link.exe
+LINK32=snLink.exe
# ADD BASE LINK32 /nologo /subsystem:windows /machine:I386
# ADD LINK32 vfw32.lib jpeglib.lib 3dsftk.lib libpng.lib zlib.lib /nologo /subsystem:windows /map /machine:I386 /nodefaultlib:"libc.lib" /libpath:"./jpeglib/release" /libpath:"./3dsftk/release" /libpath:"./libpng/release" /libpath:"./zlib/release"
@@ -77,7 +77,7 @@ LINK32=link.exe
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
-LINK32=link.exe
+LINK32=snLink.exe
# ADD BASE LINK32 /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
# ADD LINK32 vfw32.lib jpeglib.lib 3dsftk.lib libpng.lib zlib.lib gdi32.lib /nologo /subsystem:windows /map /debug /machine:I386 /nodefaultlib:"libcd.lib" /libpath:"./jpeglib/debug" /libpath:"./3dsftk/debug" /libpath:"./libpng/debug" /libpath:"./zlib/debug"
# SUBTRACT LINK32 /pdb:none
@@ -235,10 +235,6 @@ SOURCE=.\Piececmb.cpp
# End Source File
# Begin Source File
-SOURCE=.\Piecelst.cpp
-# End Source File
-# Begin Source File
-
SOURCE=.\Pieceprv.cpp
# End Source File
# Begin Source File
@@ -324,6 +320,10 @@ SOURCE=.\Terrwnd.cpp
# End Source File
# Begin Source File
+SOURCE=.\texdlg.cpp
+# End Source File
+# Begin Source File
+
SOURCE=.\Titletip.cpp
# End Source File
# Begin Source File
@@ -548,6 +548,10 @@ SOURCE=.\Terrwnd.h
# End Source File
# Begin Source File
+SOURCE=.\texdlg.h
+# End Source File
+# Begin Source File
+
SOURCE=.\Titletip.h
# End Source File
# Begin Source File
@@ -1101,17 +1105,7 @@ SOURCE=..\common\view.h
# Begin Source File
SOURCE=..\Common\camera.cpp
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
# End Source File
# Begin Source File
@@ -1129,160 +1123,56 @@ SOURCE=..\common\console.cpp
# Begin Source File
SOURCE=..\common\curve.cpp
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
# End Source File
# Begin Source File
SOURCE=..\Common\file.cpp
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
# End Source File
# Begin Source File
SOURCE=..\Common\globals.cpp
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
# End Source File
# Begin Source File
SOURCE=..\Common\group.cpp
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
# End Source File
# Begin Source File
SOURCE=..\common\im_bmp.cpp
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
# End Source File
# Begin Source File
SOURCE=..\common\im_gif.cpp
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
# ADD CPP /I "./jpeglib"
# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
-# ADD CPP /I "./jpeglib"
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
# End Source File
# Begin Source File
SOURCE=..\common\im_jpg.cpp
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
-# ADD CPP /I "./jpeglib"
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
# ADD CPP /I "./jpeglib"
# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
# End Source File
# Begin Source File
SOURCE=..\common\im_png.cpp
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
-# ADD CPP /I "./libpng" /I "./zlib"
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
# ADD CPP /I "./libpng" /I "./zlib"
# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
# End Source File
# Begin Source File
SOURCE=..\Common\image.cpp
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
-# ADD CPP /I "./jpeglib"
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
# ADD CPP /I "./jpeglib"
# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
# End Source File
# Begin Source File
SOURCE=..\common\library.cpp
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
# End Source File
# Begin Source File
@@ -1292,77 +1182,27 @@ SOURCE=..\Common\light.cpp
# Begin Source File
SOURCE=..\common\mainwnd.cpp
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
# End Source File
# Begin Source File
SOURCE=..\Common\matrix.cpp
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
# End Source File
# Begin Source File
SOURCE=..\common\message.cpp
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
# End Source File
# Begin Source File
SOURCE=..\common\minifig.cpp
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
# End Source File
# Begin Source File
SOURCE=..\common\object.cpp
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
# End Source File
# Begin Source File
@@ -1382,26 +1222,19 @@ SOURCE=..\common\opengl.cpp
# Begin Source File
SOURCE=..\Common\piece.cpp
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
# SUBTRACT CPP /YX /Yc /Yu
+# End Source File
+# Begin Source File
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
+SOURCE=..\Common\pieceinf.cpp
# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
# End Source File
# Begin Source File
-SOURCE=..\Common\pieceinf.cpp
+SOURCE=..\common\piecelst.cpp
!IF "$(CFG)" == "LeoCAD - Win32 Release"
-# SUBTRACT CPP /YX /Yc /Yu
-
!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
# SUBTRACT CPP /YX /Yc /Yu
@@ -1412,62 +1245,22 @@ SOURCE=..\Common\pieceinf.cpp
# Begin Source File
SOURCE=..\Common\project.cpp
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
# End Source File
# Begin Source File
SOURCE=..\Common\quant.cpp
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
# End Source File
# Begin Source File
SOURCE=..\common\str.cpp
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
# End Source File
# Begin Source File
SOURCE=..\Common\terrain.cpp
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
# End Source File
# Begin Source File
@@ -1485,62 +1278,22 @@ SOURCE=..\common\texfont.cpp
# Begin Source File
SOURCE=..\Common\texture.cpp
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
# End Source File
# Begin Source File
SOURCE=..\Common\Tr.cpp
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
# End Source File
# Begin Source File
SOURCE=..\Common\vector.cpp
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
# End Source File
# Begin Source File
SOURCE=..\common\view.cpp
-
-!IF "$(CFG)" == "LeoCAD - Win32 Release"
-
-# SUBTRACT CPP /YX /Yc /Yu
-
-!ELSEIF "$(CFG)" == "LeoCAD - Win32 Debug"
-
# SUBTRACT CPP /YX /Yc /Yu
-
-!ENDIF
-
# End Source File
# End Group
# Begin Source File
diff --git a/win/LeoCAD.rc b/win/LeoCAD.rc
index 00c425a..841f054 100644
--- a/win/LeoCAD.rc
+++ b/win/LeoCAD.rc
@@ -204,6 +204,7 @@ BEGIN
BUTTON ID_TERDLG_FILE_OPEN
BUTTON ID_TERDLG_FILE_SAVE
SEPARATOR
+ BUTTON ID_TERDLG_EDIT_SELECT
BUTTON ID_TERDLG_EDIT_ZOOM
BUTTON ID_TERDLG_EDIT_PAN
BUTTON ID_TERDLG_EDIT_ROTATE
@@ -248,7 +249,7 @@ BEGIN
END
MENUITEM SEPARATOR
MENUITEM "Propert&ies...", ID_FILE_PROPERTIES
- MENUITEM "Piece &Library Manager...", ID_FILE_EDITPIECELIBRARY
+ MENUITEM "Pieces &Library Manager...", ID_FILE_EDITPIECELIBRARY
MENUITEM "Terrain &Editor...", ID_FILE_TERRAINEDITOR
MENUITEM SEPARATOR
MENUITEM "&Print...\tCtrl+P", ID_FILE_PRINT
@@ -519,6 +520,7 @@ BEGIN
MENUITEM "&Print Catalog...", ID_LIBDLG_FILE_PRINTCATALOG
MENUITEM "Load &Update...", ID_LIBDLG_FILE_MERGEUPDATE
MENUITEM "&Import Piece...", ID_FILE_IMPORTPIECE
+ MENUITEM "Te&xtures...", ID_LIBDLG_FILE_TEXTURES
MENUITEM SEPARATOR
MENUITEM "Re&turn", IDOK
MENUITEM "&Cancel", IDCANCEL
@@ -558,6 +560,7 @@ BEGIN
MENUITEM "&Random", ID_TERDLG_EDIT_RANDOM
MENUITEM "Reset &Camera", ID_TERDLG_EDIT_RESETCAMERA
MENUITEM SEPARATOR
+ MENUITEM "&Select", ID_TERDLG_EDIT_SELECT
MENUITEM "&Zoom", ID_TERDLG_EDIT_ZOOM
MENUITEM "&Pan", ID_TERDLG_EDIT_PAN
MENUITEM "Ro&tate", ID_TERDLG_EDIT_ROTATE
@@ -1380,6 +1383,19 @@ BEGIN
PUSHBUTTON "New",IDC_EDITGRP_NEWGROUP,7,136,41,14
END
+IDD_LIBRARY_TEXTURES DIALOG DISCARDABLE 0, 0, 226, 201
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "LeoCAD Pieces Library Textures"
+FONT 8, "MS Sans Serif"
+BEGIN
+ LISTBOX ID_LIBTEX_LIST,7,7,152,187,LBS_SORT |
+ LBS_NOINTEGRALHEIGHT | LBS_EXTENDEDSEL | WS_VSCROLL |
+ WS_TABSTOP
+ DEFPUSHBUTTON "Close",IDOK,169,7,50,14
+ PUSHBUTTON "Add...",ID_LIBTEX_ADD,169,24,50,14
+ PUSHBUTTON "Remove",ID_LIBTEX_REMOVE,169,41,50,14
+END
+
#ifndef _MAC
/////////////////////////////////////////////////////////////////////////////
@@ -1626,6 +1642,14 @@ BEGIN
TOPMARGIN, 7
BOTTOMMARGIN, 150
END
+
+ IDD_LIBRARY_TEXTURES, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 219
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 194
+ END
END
#endif // APSTUDIO_INVOKED
@@ -1694,18 +1718,18 @@ END
STRINGTABLE DISCARDABLE
BEGIN
- ID_FILE_NEW "Create a new document\nNew"
- ID_FILE_OPEN "Open an existing document\nOpen"
+ ID_FILE_NEW "Create a new project\nNew"
+ ID_FILE_OPEN "Open an existing project\nOpen"
ID_FILE_CLOSE "Close the active document\nClose"
- ID_FILE_SAVE "Save the active document\nSave"
- ID_FILE_SAVE_AS "Save the active document with a new name\nSave As"
+ ID_FILE_SAVE "Save the active project\nSave"
+ ID_FILE_SAVE_AS "Save the active project with a new name\nSave As"
ID_FILE_PAGE_SETUP "Change the printing options\nPage Setup"
ID_FILE_PRINT_SETUP "Change the printer and printing options\nPrint Setup"
- ID_FILE_PRINT "Print the active document\nPrint"
+ ID_FILE_PRINT "Print the active project\nPrint"
ID_FILE_PRINT_PREVIEW "Display full pages\nPrint Preview"
ID_FILE_UPDATE "Update the container to show any changes\nUpdate"
ID_FILE_SAVE_COPY_AS "Save a copy of the active document with a new name\nSave Copy"
- ID_FILE_SEND_MAIL "Send the active document through electronic mail\nSend Mail"
+ ID_FILE_SEND_MAIL "Send the active project through electronic mail\nSend Mail"
END
STRINGTABLE DISCARDABLE
@@ -1806,6 +1830,7 @@ BEGIN
ID_SNAP_SNAPZ "Snap Z Toggle"
ID_SNAP_SNAPALL "Snap Toggle"
ID_SNAP_SNAPNONE "Snap Toggle"
+ ID_FILE_SAVEPICTURE "Save a picture"
END
STRINGTABLE DISCARDABLE
@@ -1918,6 +1943,7 @@ BEGIN
ID_EDIT_SELECTNONE "De-select everything"
ID_EDIT_SELECTINVERT "Invert the current selection set"
ID_EDIT_SELECTBYNAME "Select objects by name"
+ ID_FILE_MERGE "Merge the contents of another project with the current one\nMerge"
ID_VIEW_FULLSCREEN "Toggle fullscreen mode\nFullscreen"
ID_VIEW_STEP_NEXT "Advance one step or frame\nGo Foward"
ID_VIEW_STEP_PREVIOUS "Go back one step or frame\nGo Back"
@@ -1943,6 +1969,7 @@ END
STRINGTABLE DISCARDABLE
BEGIN
+ ID_FILE_EDITPIECELIBRARY "Configure the LeoCAD Pieces Library"
ID_VIEW_ZOOMIN "Zoom In"
ID_VIEW_ZOOMOUT "Zoom Out"
ID_PIECE_EDITGROUPS "Edit groups"
diff --git a/win/Libdlg.cpp b/win/Libdlg.cpp
index 107d0a4..68fa91c 100644
--- a/win/Libdlg.cpp
+++ b/win/Libdlg.cpp
@@ -7,6 +7,7 @@
#include "GroupDlg.h"
#include "Print.h"
#include "Tools.h"
+#include "texdlg.h"
#include "ProgDlg.h"
#include "project.h"
#include "pieceinf.h"
@@ -293,7 +294,7 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
if (filedlg.DoModal() != IDOK)
return TRUE;
- LoadUpdate(filedlg.GetPathName());
+ project->GetPiecesLibrary ()->LoadUpdate(filedlg.GetPathName());
// update m_Parts
UpdateList();
@@ -342,6 +343,12 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
return TRUE;
}
+ case ID_LIBDLG_FILE_TEXTURES:
+ {
+ CTexturesDlg dlg;
+ dlg.DoModal();
+ } break;
+
case ID_LIBDLG_GROUP_INSERT:
{
HTREEITEM hti = m_Tree.GetSelectedItem();
@@ -620,7 +627,7 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
sel++;
}
- DeletePiece(names, sel);
+ project->GetPiecesLibrary ()->DeletePiece(names, sel);
free(names);
CString str = project->GetPiecesLibrary ()->GetLibraryPath();
diff --git a/win/resource.h b/win/resource.h
index 287b70a..8c84f02 100644
--- a/win/resource.h
+++ b/win/resource.h
@@ -133,6 +133,7 @@
#define IDD_TERRAIN_OPTIONS 218
#define IDR_PREVIEW 221
#define IDD_EDIT_GROUPS 231
+#define IDD_LIBRARY_TEXTURES 234
#define IDC_SELDLG_LIST 1000
#define IDC_SELDLG_ALL 1001
#define IDC_SELDLG_NONE 1002
@@ -398,9 +399,12 @@
#define IDC_HTMLDLG_HTMLEXT 1223
#define IDC_MF_ARMRANGLE 1224
#define IDC_MF_HANDLANGLE 1225
+#define ID_LIBTEX_ADD 1225
#define IDC_MF_HANDRANGLE 1226
+#define ID_LIBTEX_REMOVE 1226
#define IDC_MF_TOOLLANGLE 1227
#define IDC_MF_TOOLRANGLE 1228
+#define ID_LIBTEX_LIST 1228
#define IDC_MF_LEGLANGLE 1229
#define IDC_MF_LEGRANGLE 1230
#define IDC_MF_SHOELANGLE 1231
@@ -611,6 +615,7 @@
#define ID_TERDLG_FILE_OPEN 33114
#define ID_TERDLG_FILE_SAVE 33115
#define ID_TERDLG_EDIT_PREFERENCES 33116
+#define ID_TERDLG_EDIT_SELECT 33119
#define ID_TERDLG_EDIT_ZOOM 33120
#define ID_TERDLG_EDIT_PAN 33121
#define ID_TERDLG_EDIT_ROTATE 33122
@@ -638,6 +643,7 @@
#define ID_FILE_IMPORTPIECE 33152
#define ID_VIEW_NEWVIEW 33153
#define ID_VIEW_STEP_DELETE 33154
+#define ID_LIBDLG_FILE_TEXTURES 33157
#define ID_VIEW_PIECES_BAR 59425
#define ID_VIEW_TOOLS_BAR 59426
#define ID_VIEW_ANIMATION_BAR 59427
@@ -648,9 +654,9 @@
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_3D_CONTROLS 1
-#define _APS_NEXT_RESOURCE_VALUE 234
-#define _APS_NEXT_COMMAND_VALUE 33155
-#define _APS_NEXT_CONTROL_VALUE 1225
+#define _APS_NEXT_RESOURCE_VALUE 235
+#define _APS_NEXT_COMMAND_VALUE 33158
+#define _APS_NEXT_CONTROL_VALUE 1229
#define _APS_NEXT_SYMED_VALUE 121
#endif
#endif
diff --git a/win/texdlg.cpp b/win/texdlg.cpp
new file mode 100644
index 0000000..49b13dc
--- /dev/null
+++ b/win/texdlg.cpp
@@ -0,0 +1,116 @@
+// texdlg.cpp : implementation file
+//
+
+#include "stdafx.h"
+#include "leocad.h"
+#include "texdlg.h"
+#include "library.h"
+#include "project.h"
+#include "globals.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+#endif
+
+/////////////////////////////////////////////////////////////////////////////
+// CTexturesDlg dialog
+
+
+CTexturesDlg::CTexturesDlg(CWnd* pParent /*=NULL*/)
+ : CDialog(CTexturesDlg::IDD, pParent)
+{
+ //{{AFX_DATA_INIT(CTexturesDlg)
+ // NOTE: the ClassWizard will add member initialization here
+ //}}AFX_DATA_INIT
+}
+
+
+void CTexturesDlg::DoDataExchange(CDataExchange* pDX)
+{
+ CDialog::DoDataExchange(pDX);
+ //{{AFX_DATA_MAP(CTexturesDlg)
+ DDX_Control(pDX, ID_LIBTEX_LIST, m_List);
+ //}}AFX_DATA_MAP
+}
+
+
+BEGIN_MESSAGE_MAP(CTexturesDlg, CDialog)
+ //{{AFX_MSG_MAP(CTexturesDlg)
+ ON_BN_CLICKED(ID_LIBTEX_ADD, OnLibtexAdd)
+ ON_BN_CLICKED(ID_LIBTEX_REMOVE, OnLibtexRemove)
+ //}}AFX_MSG_MAP
+END_MESSAGE_MAP()
+
+/////////////////////////////////////////////////////////////////////////////
+// CTexturesDlg message handlers
+
+BOOL CTexturesDlg::OnInitDialog()
+{
+ CDialog::OnInitDialog();
+
+ UpdateList();
+
+ return TRUE;
+}
+
+void CTexturesDlg::OnOK()
+{
+ CDialog::OnOK();
+}
+
+void CTexturesDlg::OnLibtexAdd()
+{
+ CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
+ "All Image Files|*.bmp;*.gif;*.jpg;*.png|JPEG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif|BMP Files (*.bmp)|*.bmp|PNG Files (*.png)|*.png|All Files (*.*)|*.*||", this);
+
+ if (dlg.DoModal() == IDOK)
+ {
+ project->GetPiecesLibrary ()->ImportTexture (dlg.GetPathName());
+ UpdateList();
+ }
+}
+
+void CTexturesDlg::OnLibtexRemove()
+{
+ int i, selected = 0;
+
+ for (i = 0; i < m_List.GetCount(); i++)
+ if (m_List.GetSel(i))
+ selected++;
+
+ // Nothing to be done
+ if (selected == 0)
+ return;
+
+ char** names = (char**)malloc(selected*sizeof(char**));
+
+ for (selected = 0, i = 0; i < m_List.GetCount(); i++)
+ {
+ if (m_List.GetSel(i))
+ {
+ names[selected] = (char*)m_List.GetItemDataPtr (i);;
+ selected++;
+ }
+ }
+
+ project->GetPiecesLibrary ()->DeleteTextures (names, selected);
+
+ free (names);
+
+ UpdateList();
+}
+
+void CTexturesDlg::UpdateList()
+{
+ PiecesLibrary *pLib = project->GetPiecesLibrary ();
+
+ m_List.ResetContent ();
+
+ for (int i = 0; i < pLib->GetTextureCount (); i++)
+ {
+ int index = m_List.AddString (pLib->GetTexture(i)->m_strName);
+ m_List.SetItemDataPtr (index, pLib->GetTexture(i)->m_strName);
+ }
+}
diff --git a/win/texdlg.h b/win/texdlg.h
new file mode 100644
index 0000000..b0620bb
--- /dev/null
+++ b/win/texdlg.h
@@ -0,0 +1,50 @@
+#if !defined(AFX_TEXDLG_H__01AFB4FD_6C04_41FB_8FF6_CC87EAF49D31__INCLUDED_)
+#define AFX_TEXDLG_H__01AFB4FD_6C04_41FB_8FF6_CC87EAF49D31__INCLUDED_
+
+#if _MSC_VER > 1000
+#pragma once
+#endif // _MSC_VER > 1000
+// texdlg.h : header file
+//
+
+/////////////////////////////////////////////////////////////////////////////
+// CTexturesDlg dialog
+
+class CTexturesDlg : public CDialog
+{
+// Construction
+public:
+ CTexturesDlg(CWnd* pParent = NULL); // standard constructor
+
+// Dialog Data
+ //{{AFX_DATA(CTexturesDlg)
+ enum { IDD = IDD_LIBRARY_TEXTURES };
+ CListBox m_List;
+ //}}AFX_DATA
+
+
+// Overrides
+ // ClassWizard generated virtual function overrides
+ //{{AFX_VIRTUAL(CTexturesDlg)
+ protected:
+ virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
+ //}}AFX_VIRTUAL
+
+// Implementation
+protected:
+ void UpdateList();
+
+ // Generated message map functions
+ //{{AFX_MSG(CTexturesDlg)
+ virtual void OnOK();
+ afx_msg void OnLibtexAdd();
+ afx_msg void OnLibtexRemove();
+ virtual BOOL OnInitDialog();
+ //}}AFX_MSG
+ DECLARE_MESSAGE_MAP()
+};
+
+//{{AFX_INSERT_LOCATION}}
+// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
+
+#endif // !defined(AFX_TEXDLG_H__01AFB4FD_6C04_41FB_8FF6_CC87EAF49D31__INCLUDED_)