summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorleo2005-12-20 20:22:46 +0000
committerleo2005-12-20 20:22:46 +0000
commit98f3bd8740246fe88c3db3278fe533dc2f368d12 (patch)
tree076cfa089cd19faabc144deca4d0fb303d97cb07
parent85c3a7f5afcc88696d50866525588756e6bf80c3 (diff)
Updated the Pieces Library Manager to use the new categories.
git-svn-id: http://svn.leocad.org/trunk@443 c7d43263-9d01-0410-8a33-9dba5d9f93d6
-rw-r--r--common/defines.h5
-rw-r--r--common/file.cpp19
-rw-r--r--common/file.h25
-rw-r--r--common/keyboard.cpp2
-rw-r--r--common/libman.cpp409
-rw-r--r--common/libman.h81
-rwxr-xr-xcommon/library.cpp559
-rwxr-xr-xcommon/library.h74
-rw-r--r--common/project.cpp6
-rw-r--r--common/typedefs.h14
-rw-r--r--win/LeoCAD.dsp9
-rw-r--r--win/LeoCAD.rc44
-rw-r--r--win/Libdlg.cpp605
-rw-r--r--win/Libdlg.h40
-rw-r--r--win/Piecebar.cpp2
-rw-r--r--win/System.cpp49
-rw-r--r--win/res/library.bmpbin1198 -> 838 bytes
-rw-r--r--win/resource.h6
18 files changed, 583 insertions, 1366 deletions
diff --git a/common/defines.h b/common/defines.h
index e5e7e7d..d1b50a7 100644
--- a/common/defines.h
+++ b/common/defines.h
@@ -92,6 +92,11 @@ int stricmp(const char* str1, const char* str2);
#define M_PI 3.14159265
#endif
+#define LC_FOURCC(ch0, ch1, ch2, ch3) (lcuint32)((lcuint32)(lcuint8)(ch0) | ((lcuint32)(lcuint8)(ch1) << 8) | \
+ ((lcuint32)(lcuint8)(ch2) << 16) | ((lcuint32)(lcuint8)(ch3) << 24 ))
+
+#define LC_FILE_ID LC_FOURCC('L','C','D', 0)
+
#define LC_CONNECTIONS 2 // Different piece connections
#define LC_STR_VERSION "LeoCAD 0.7 Project\0\0" // char[20]
diff --git a/common/file.cpp b/common/file.cpp
index 8962401..23825ca 100644
--- a/common/file.cpp
+++ b/common/file.cpp
@@ -9,6 +9,7 @@
#include "file.h"
#include "defines.h"
#include "config.h"
+#include "str.h"
// =============================================================================
// File construction/destruction
@@ -243,6 +244,20 @@ unsigned long File::WriteDouble (const void* pBuf, unsigned long nCount)
#endif
}
+void File::ReadString(String& Value)
+{
+ lcuint32 l;
+ ReadInt(&l);
+ Read(Value.GetBuffer(l+1), l);
+ ((char*)Value)[l] = 0;
+}
+
+void File::WriteString(const String& Value)
+{
+ WriteInt(Value.GetLength());
+ Write((const char*)Value, Value.GetLength());
+}
+
// =============================================================================
FileMem::FileMem()
@@ -281,7 +296,7 @@ FileDisk::~FileDisk()
/////////////////////////////////////////////////////////////////////////////
// File operations
-char* FileMem::ReadString(char* pBuf, unsigned long nMax)
+char* FileMem::ReadLine(char* pBuf, unsigned long nMax)
{
int nRead = 0;
unsigned char ch;
@@ -308,7 +323,7 @@ char* FileMem::ReadString(char* pBuf, unsigned long nMax)
return pBuf;
}
-char* FileDisk::ReadString(char* pBuf, unsigned long nMax)
+char* FileDisk::ReadLine(char* pBuf, unsigned long nMax)
{
return fgets(pBuf, nMax, m_hFile);
}
diff --git a/common/file.h b/common/file.h
index d891e9c..b662bdd 100644
--- a/common/file.h
+++ b/common/file.h
@@ -4,6 +4,9 @@
#include <stdio.h>
#include <string.h>
#include "defines.h"
+#include "config.h"
+
+class String;
class File
{
@@ -19,7 +22,7 @@ public:
virtual void SetLength(unsigned long nNewLen) = 0;
virtual unsigned long GetLength() const = 0;
- virtual char* ReadString(char* pBuf, unsigned long nMax)=0;
+ virtual char* ReadLine(char* pBuf, unsigned long nMax)=0;
virtual unsigned long Read(void* pBuf, unsigned long nCount)=0;
virtual unsigned long Write(const void* pBuf, unsigned long nCount)=0;
virtual int GetChar()=0;
@@ -36,15 +39,27 @@ public:
unsigned long WriteFloat(const void* pBuf, unsigned long nCount);
unsigned long WriteDouble(const void* pBuf, unsigned long nCount);
+ void ReadString(String& Value);
+ void ReadInt(lcint32* Value)
+ { ReadLong(Value, 1); }
+ void ReadInt(lcuint32* Value)
+ { ReadLong(Value, 1); }
+
+ void WriteString(const String& Value);
+ void WriteInt(lcint32 Value)
+ { WriteLong(&Value, 1); }
+ void WriteInt(lcuint32 Value)
+ { WriteLong(&Value, 1); }
+
virtual void Abort()=0;
virtual void Flush()=0;
virtual void Close()=0;
const char* GetFileName() const
- { return FileName; }
+ { return FileName; }
void SetFileName(const char* Name)
- { strncpy(FileName, Name, LC_MAXPATH); }
+ { strncpy(FileName, Name, LC_MAXPATH); }
protected:
char FileName[LC_MAXPATH];
@@ -64,7 +79,7 @@ public:
void SetLength(unsigned long nNewLen);
unsigned long GetLength() const;
- char* ReadString(char* pBuf, unsigned long nMax);
+ char* ReadLine(char* pBuf, unsigned long nMax);
unsigned long Read(void* pBuf, unsigned long nCount);
unsigned long Write(const void* pBuf, unsigned long nCount);
int GetChar();
@@ -100,7 +115,7 @@ public:
void SetLength(unsigned long nNewLen);
unsigned long GetLength() const;
- char* ReadString(char* pBuf, unsigned long nMax);
+ char* ReadLine(char* pBuf, unsigned long nMax);
unsigned long Read(void* pBuf, unsigned long nCount);
unsigned long Write(const void* pBuf, unsigned long nCount);
int GetChar();
diff --git a/common/keyboard.cpp b/common/keyboard.cpp
index c001af0..ceff07c 100644
--- a/common/keyboard.cpp
+++ b/common/keyboard.cpp
@@ -206,7 +206,7 @@ bool LoadKeyboardShortcuts(const char* FileName)
}
char Line[1024];
- while (f.ReadString(Line, 1024))
+ while (f.ReadLine(Line, 1024))
{
char* ptr = strchr(Line, '=');
diff --git a/common/libman.cpp b/common/libman.cpp
deleted file mode 100644
index fd5145b..0000000
--- a/common/libman.cpp
+++ /dev/null
@@ -1,409 +0,0 @@
-//
-// Handle all commands from the Pieces Library Manager
-//
-
-#include <string.h>
-#include "libman.h"
-#include "library.h"
-#include "pieceinf.h"
-#include "globals.h"
-#include "project.h"
-#include "system.h"
-
-LibraryManager::LibraryManager ()
-{
- m_nPieces = 0;
- m_pPieces = NULL;
- m_nGroups = 0;
- m_bModified = false;
- strcpy (m_strFile, "");
-
- Initialize ();
-}
-
-LibraryManager::~LibraryManager ()
-{
- free (m_pPieces);
-}
-
-bool LibraryManager::Initialize ()
-{
- PiecesLibrary *pLib = project->GetPiecesLibrary ();
- int i;
-
- m_nPieces = pLib->GetPieceCount();
- m_pPieces = (LC_LIBDLG_PIECEINFO*) malloc (sizeof (LC_LIBDLG_PIECEINFO) * m_nPieces);
-
- for (i = 0; i < m_nPieces; i++)
- {
- m_pPieces[i].Info = pLib->GetPieceInfo (i);
- m_pPieces[i].CurrentGroups = m_pPieces[i].Info->m_nGroups;
- }
-
- m_nGroups = pLib->GetGroupCount();
- for (i = 0; i < m_nGroups; i++)
- m_strGroups[i] = pLib->GetGroup(i);
-
- return true;
-}
-
-void LibraryManager::LoadDefaults ()
-{
- strcpy (m_strFile, "");
-
- strcpy (m_strGroups[0], "Plates");
- strcpy (m_strGroups[1], "Bricks");
- strcpy (m_strGroups[2], "Tiles");
- strcpy (m_strGroups[3], "Slope Bricks");
- strcpy (m_strGroups[4], "Technic");
- strcpy (m_strGroups[5], "Space");
- strcpy (m_strGroups[6], "Train");
- strcpy (m_strGroups[7], "Other Bricks");
- strcpy (m_strGroups[8], "Accessories");
- m_nGroups = 9;
-
- for (int i = 0; i < m_nPieces; i++)
- m_pPieces[i].CurrentGroups = PiecesLibrary::GetDefaultPieceGroup (m_pPieces[i].Info->m_strName);
-}
-
-void LibraryManager::HandleCommand (int id, int param)
-{
- switch (id)
- {
- case LC_LIBDLG_FILE_RESET:
- {
- LoadDefaults ();
- m_bModified = true;
- } break;
-
- case LC_LIBDLG_FILE_OPEN:
- break;
-
- case LC_LIBDLG_FILE_SAVE:
- break;
-
- case LC_LIBDLG_FILE_SAVEAS:
- break;
-
- case LC_LIBDLG_FILE_MERGEUPDATE:
- {
- LC_FILEOPENDLG_OPTS opts;
-
- strcpy (opts.path, "");
- opts.type = LC_FILEOPENDLG_LUP;
-
- if (!SystemDoDialog (LC_DLG_FILE_OPEN, &opts))
- return;
-
- project->GetPiecesLibrary ()->LoadUpdate (opts.filenames[0]);
-
- free (opts.filenames[0]);
- free (opts.filenames);
-
- // FIXME: update m_pPieces
- } break;
-
- case LC_LIBDLG_FILE_IMPORTPIECE:
- {
- LC_FILEOPENDLG_OPTS opts;
-
- strcpy(opts.path, Sys_ProfileLoadString ("Default", "LDraw Pieces Path", ""));
- opts.type = LC_FILEOPENDLG_DAT;
-
- if (!SystemDoDialog (LC_DLG_FILE_OPEN, &opts))
- return;
-
- for (int i = 0; i < opts.numfiles; i++)
- {
- project->GetPiecesLibrary ()->ImportLDrawPiece (opts.filenames[i]);
- free (opts.filenames[i]);
- }
-
- free (opts.filenames);
- Sys_ProfileSaveString ("Default", "LDraw Pieces Path", opts.path);
-
- // FIXME: update m_pPieces
- } break;
-
- case LC_LIBDLG_FILE_RETURN:
- break;
-
- case LC_LIBDLG_FILE_CANCEL:
- break;
-
- case LC_LIBDLG_GROUP_INSERT:
- {
- char Name[64];
- int i, Idx = (int)param;
-
- if (m_nGroups == LC_PIECESLIB_MAXGROUPS)
- {
- SystemDoMessageBox ("Cannot add more groups!", LC_MB_OK|LC_MB_ICONINFORMATION);
- return;
- }
-
- strcpy (Name, "New Group");
-
- if (!SystemDoDialog (LC_DLG_GROUP, Name))
- return;
-
- for (i = m_nGroups; i > Idx; i--)
- m_strGroups[i] = m_strGroups[i-1];
-
- m_strGroups[i] = Name;
-
- for (int j = 0; j < m_nPieces; j++)
- {
- lcuint32 grp = m_pPieces[j].CurrentGroups;
-
- for (i = m_nGroups; i >= Idx; i--)
- {
- lcuint32 d = (1 << i);
- if (grp & d)
- {
- grp &= ~d;
- grp |= (1 << (i+1));
- }
- }
- m_pPieces[j].CurrentGroups = grp;
- }
-
- m_nGroups++;
- m_bModified = true;
-
- } break;
-
- case LC_LIBDLG_GROUP_DELETE:
- {
- int i, j;
-
- if (SystemDoMessageBox ("Are you sure you want to delete this group ?", LC_MB_YESNO|LC_MB_ICONQUESTION) != LC_YES)
- return;
-
- for (i = param; i < (m_nGroups - 1); i++)
- m_strGroups[i] = m_strGroups[i+1];
-
- for (j = 0; j < m_nPieces; j++)
- {
- lcuint32 grp = m_pPieces[j].CurrentGroups;
-
- // Remove from the group
- if (grp & (1 << param))
- grp &= ~(1 << param);
-
- // Shift other groups
- for (i = param+1; i < m_nGroups; i++)
- {
- lcuint32 d = (1 << i);
-
- if (grp & d)
- {
- grp &= ~d;
- grp |= (1 << (i-1));
- }
- }
- m_pPieces[j].CurrentGroups = grp;
- }
-
- m_bModified = true;
- m_nGroups--;
- } break;
-
- case LC_LIBDLG_GROUP_EDIT:
- {
- // TODO: Make this a group edit dialog where you can choose the icon.
- char Name[64];
- int i = (int)param;
-
- strcpy (Name, m_strGroups[i]);
-
- if (!SystemDoDialog (LC_DLG_GROUP, Name))
- return;
-
- m_strGroups[i] = Name;
- m_bModified = true;
- } break;
-
- case LC_LIBDLG_GROUP_MOVEUP:
- {
- String tmp;
- int j;
-
- if (param < 1)
- return;
-
- tmp = m_strGroups[param];
- m_strGroups[param] = m_strGroups[param-1];
- m_strGroups[param-1] = tmp;
-
- for (j = 0; j < m_nPieces; j++)
- {
- lcuint32 grp = m_pPieces[j].CurrentGroups;
- bool g1 = (grp & (1 << param)) != 0;
- bool g2 = (grp & (1 << (param-1))) != 0;
-
- if (g1)
- grp |= (1 << (param-1));
- else
- grp &= ~(1 << (param-1));
-
- if (g2)
- grp |= (1 << param);
- else
- grp &= ~(1 << param);
-
- m_pPieces[j].CurrentGroups = grp;
- }
-
- m_bModified = true;
- } break;
-
- case LC_LIBDLG_GROUP_MOVEDOWN:
- {
- String tmp;
- int j;
-
- if (param < 1)
- return;
-
- tmp = m_strGroups[param];
- m_strGroups[param] = m_strGroups[param+1];
- m_strGroups[param+1] = tmp;
-
- for (j = 0; j < m_nPieces; j++)
- {
- lcuint32 grp = m_pPieces[j].CurrentGroups;
- bool g1 = (grp & (1 << param)) != 0;
- bool g2 = (grp & (1 << (param+1))) != 0;
-
- if (g1)
- grp |= (1 << (param+1));
- else
- grp &= ~(1 << (param+1));
-
- if (g2)
- grp |= (1 << param);
- else
- grp &= ~(1 << param);
-
- m_pPieces[j].CurrentGroups = grp;
- }
-
- m_bModified = true;
- } break;
- }
-}
-
-bool LibraryManager::DeletePieces (char** Names, int Count)
-{
- if (SystemDoMessageBox ("Are you sure you want to permanently delete the selected pieces?", LC_MB_YESNO|LC_MB_ICONQUESTION) != LC_YES)
- return false;
-
- project->GetPiecesLibrary ()->DeletePieces (Names, Count);
-
- // Delete pieces from our list
- for (int i = 0; i < Count; i++)
- {
- for (int j = 0; j < m_nPieces; j++)
- {
- if (!strcmp (Names[i], m_pPieces[j].Info->m_strName))
- {
- for (int k = j; k < m_nPieces; k++)
- {
- m_pPieces[k].Info = m_pPieces[k+1].Info;
- m_pPieces[k].CurrentGroups = m_pPieces[k+1].CurrentGroups;
- }
-
- m_nPieces--;
- break;
- }
- }
- }
-
- return true;
-}
-
-// Returns true if it's ok to continue.
-bool LibraryManager::SaveModified ()
-{
- if (m_bModified)
- {
- switch (SystemDoMessageBox ("Save changes ?", LC_MB_YESNOCANCEL|LC_MB_ICONQUESTION))
- {
- case LC_CANCEL:
- return false; // don't continue
- break;
-
- case LC_YES:
- // If so, either Save or Update, as appropriate
- if (!DoSave (false))
- return false; // don't continue
- break;
-
- case LC_NO:
- // Not saving changes
- return true;
- break;
- }
-
- // Apply changes
- Sys_ProfileSaveString ("Settings", "Groups", m_strFile);
- project->GetPiecesLibrary ()->LoadGroupConfig (m_strFile);
- }
-
- project->GetPiecesLibrary ()->CheckReload ();
-
- return true; // keep going
-}
-
-bool LibraryManager::DoSave (bool bAskName)
-{
- /*
- if (bAskName || (strlen (m_strFile) == 0))
- {
- char filename[LC_MAXPATH];
-
- // CFileDialog dlg(FALSE, ".lgf\0", NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
- // "LeoCAD Group Files (*.lgf)|*.lgf|All Files (*.*)|*.*||",this);
-// FIXME: file extension
- if (!SystemDoDialog (LC_DLG_FILE_SAVE, filename))
- return false;
- strcpy (m_strFile, filename);
- }
-*/
- /*
- Sys_BeginWait ();
- FileDisk f;
- int i;
-
- if (!f.Open (m_strFile, "wb"))
- return false;
-
- f.Write (ver_str, sizeof (ver_str));
- f.Write (ver_flt, sizeof (ver_flt));
- f.WriteByte (&m_nMaxGroups);
-
- for (i = 0; i < m_nMaxGroups; i++)
- {
- f.Write (m_strGroups[i], sizeof(m_strGroups[i]));
- ar << m_nBitmaps[i];
- }
-
- m_ImageList.Write(&ar);
-
- ar << (int) m_Parts.GetSize();
- for (i = 0; i < m_Parts.GetSize(); i++)
- {
- ar.Write (m_Parts[i].info->m_strName, sizeof(m_Parts[i].info->m_strName));
- ar << m_Parts[i].group;
- }
- ar.Close();
- f.Close();
- m_bModified = FALSE;
-// m_bLoaded = TRUE;
-
- fclose (f);
- Sys_EndWait ();
- */
- return true;
-}
diff --git a/common/libman.h b/common/libman.h
deleted file mode 100644
index ac48c1b..0000000
--- a/common/libman.h
+++ /dev/null
@@ -1,81 +0,0 @@
-#ifndef _LIBMAN_H_
-#define _LIBMAN_H_
-
-#include "defines.h"
-#include "config.h"
-#include "str.h"
-#include "library.h"
-
-class PieceInfo;
-
-typedef enum
-{
- LC_LIBDLG_FILE_RESET,
- LC_LIBDLG_FILE_OPEN,
- LC_LIBDLG_FILE_SAVE,
- LC_LIBDLG_FILE_SAVEAS,
- LC_LIBDLG_FILE_MERGEUPDATE,
- LC_LIBDLG_FILE_IMPORTPIECE,
- LC_LIBDLG_FILE_RETURN,
- LC_LIBDLG_FILE_CANCEL,
- LC_LIBDLG_GROUP_INSERT,
- LC_LIBDLG_GROUP_DELETE,
- LC_LIBDLG_GROUP_EDIT,
- LC_LIBDLG_GROUP_MOVEUP,
- LC_LIBDLG_GROUP_MOVEDOWN
-} LC_LIBDLG_COMMANDS;
-
-class LibraryManager
-{
-public:
- LibraryManager ();
- virtual ~LibraryManager ();
-
- void HandleCommand (int id, int param);
- bool Initialize ();
- bool DoSave (bool bAskName);
- bool SaveModified ();
-
- // Commands
- bool DeletePieces (char** Names, int Count);
-
- // Access
- int GetGroupCount () const
- { return m_nGroups; }
- String& GetGroupName (int index)
- { return m_strGroups[index]; }
-
- int GetPieceCount () const
- { return m_nPieces; }
- void GetPieceInfo (int index, PieceInfo** Info, lcuint32* Group)
- { *Info = m_pPieces[index].Info; *Group = m_pPieces[index].CurrentGroups; }
- void SetPieceGroup (int Index, int Group, bool Add)
- {
- if (Add)
- m_pPieces[Index].CurrentGroups = Group;
- else
- m_pPieces[Index].CurrentGroups |= Group;
-
- m_bModified = true;
- }
-
-protected:
- void LoadDefaults ();
-
- typedef struct
- {
- PieceInfo* Info;
- lcuint32 CurrentGroups;
- } LC_LIBDLG_PIECEINFO;
-
- int m_nPieces;
- LC_LIBDLG_PIECEINFO* m_pPieces;
-
- int m_nGroups;
- String m_strGroups[LC_PIECESLIB_MAXGROUPS];
-
- bool m_bModified;
- char m_strFile[LC_MAXPATH];
-};
-
-#endif // _LIBMAN_H_
diff --git a/common/library.cpp b/common/library.cpp
index dfc7619..4da81b9 100755
--- a/common/library.cpp
+++ b/common/library.cpp
@@ -22,137 +22,114 @@ const char PiecesLibrary::TexturesBinHeader[32] = "LeoCAD texture data file\0\0\
const char PiecesLibrary::TexturesIdxHeader[32] = "LeoCAD texture index file\0\0\0\0\0\0";
const int PiecesLibrary::TexturesFileVersion = 1;
-PiecesLibrary::PiecesLibrary ()
+PiecesLibrary::PiecesLibrary()
{
- strcpy (m_LibraryPath, "");
- m_pMovedReference = NULL;
- m_nMovedCount = 0;
- m_pPieceIdx = NULL;
- m_nPieceCount = 0;
- m_pTextures = NULL;
- m_nTextureCount = 0;
- m_bNeedsReload = false;
+ strcpy(m_LibraryPath, "");
+ strcpy(m_CategoriesFile, "");
+ m_pMovedReference = NULL;
+ m_nMovedCount = 0;
+ m_pPieceIdx = NULL;
+ m_nPieceCount = 0;
+ m_pTextures = NULL;
+ m_nTextureCount = 0;
+ m_Modified = false;
+ m_CategoriesModified = false;
}
-PiecesLibrary::~PiecesLibrary ()
+PiecesLibrary::~PiecesLibrary()
{
- Unload ();
-}
-
-void PiecesLibrary::CheckReload ()
-{
- char LibraryPath[LC_MAXPATH];
-
- strcpy (LibraryPath, m_LibraryPath);
-
- if (m_bNeedsReload)
- {
- // FIXME: project will crash if we don't update the pieceinfos
-
- Unload ();
- Load (LibraryPath);
- }
+ Unload();
}
void PiecesLibrary::Unload ()
{
- strcpy (m_LibraryPath, "");
+ strcpy(m_LibraryPath, "");
- free (m_pMovedReference);
- m_pMovedReference = NULL;
- m_nMovedCount = 0;
+ free(m_pMovedReference);
+ m_pMovedReference = NULL;
+ m_nMovedCount = 0;
- delete [] m_pPieceIdx;
- m_pPieceIdx = NULL;
- m_nPieceCount = 0;
+ delete [] m_pPieceIdx;
+ m_pPieceIdx = NULL;
+ m_nPieceCount = 0;
- delete [] m_pTextures;
- m_pTextures = NULL;
- m_nTextureCount = 0;
+ delete [] m_pTextures;
+ m_pTextures = NULL;
+ m_nTextureCount = 0;
}
bool PiecesLibrary::Load (const char *libpath)
{
- FileDisk idx, bin;
- char filename[LC_MAXPATH];
- lcuint16 count, movedcount;
- lcuint32 binsize;
- Texture* pTexture;
- int i;
+ FileDisk idx, bin;
+ char filename[LC_MAXPATH];
+ lcuint16 count, movedcount;
+ lcuint32 binsize;
+ Texture* pTexture;
+ int i;
- strcpy (m_LibraryPath, libpath);
+ strcpy (m_LibraryPath, libpath);
- // Make sure that the path ends with a '/'
- i = strlen(m_LibraryPath)-1;
- if ((m_LibraryPath[i] != '\\') && (m_LibraryPath[i] != '/'))
- strcat(m_LibraryPath, "/");
+ // Make sure that the path ends with a '/'
+ i = strlen(m_LibraryPath)-1;
+ if ((m_LibraryPath[i] != '\\') && (m_LibraryPath[i] != '/'))
+ strcat(m_LibraryPath, "/");
- // Read the piece library index.
- strcpy (filename, m_LibraryPath);
- strcat (filename, "pieces.idx");
+ // Read the piece library index.
+ strcpy (filename, m_LibraryPath);
+ strcat (filename, "pieces.idx");
- if (!idx.Open (filename, "rb"))
+ if (!idx.Open (filename, "rb"))
{
console.PrintError ("Cannot open Pieces Library file: %s.\n", filename);
- return false;
+ return false;
}
- strcpy (filename, m_LibraryPath);
- strcat (filename, "pieces.bin");
+ strcpy (filename, m_LibraryPath);
+ strcat (filename, "pieces.bin");
- if (!bin.Open (filename, "rb"))
+ if (!bin.Open (filename, "rb"))
{
console.PrintError ("Cannot open Pieces Library file: %s.\n", filename);
- return false;
+ return false;
}
if (!ValidatePiecesFile (idx, bin))
return false;
- idx.Seek (-(long)(2*sizeof(count)+sizeof(binsize)), SEEK_END);
- idx.ReadShort (&movedcount, 1);
- idx.ReadLong (&binsize, 1);
- idx.ReadShort (&count, 1);
- idx.Seek (34, SEEK_SET);
-
- // Load piece indexes
- delete [] m_pPieceIdx;
- m_pPieceIdx = new PieceInfo[count];
- m_nPieceCount = count;
-
- for (PieceInfo *pElements = m_pPieceIdx; count--; pElements++)
- pElements->LoadIndex (idx);
-
- // Load moved files reference.
- if (m_pMovedReference != NULL)
- free(m_pMovedReference);
- m_pMovedReference = (char*)malloc(18*movedcount);
- memset (m_pMovedReference, 0, 18*movedcount);
- m_nMovedCount = movedcount;
-
- for (i = 0; i < movedcount; i++)
- {
- idx.Read (&m_pMovedReference[i*18], 8);
- idx.Read (&m_pMovedReference[i*18+9], 8);
- }
-
- idx.Close();
+ idx.Seek (-(long)(2*sizeof(count)+sizeof(binsize)), SEEK_END);
+ idx.ReadShort (&movedcount, 1);
+ idx.ReadLong (&binsize, 1);
+ idx.ReadShort (&count, 1);
+ idx.Seek (34, SEEK_SET);
+
+ // Load piece indexes
+ delete [] m_pPieceIdx;
+ m_pPieceIdx = new PieceInfo[count];
+ m_nPieceCount = count;
+
+ for (PieceInfo *pElements = m_pPieceIdx; count--; pElements++)
+ pElements->LoadIndex (idx);
+
+ // Load moved files reference.
+ if (m_pMovedReference != NULL)
+ free(m_pMovedReference);
+ m_pMovedReference = (char*)malloc(18*movedcount);
+ memset (m_pMovedReference, 0, 18*movedcount);
+ m_nMovedCount = movedcount;
+
+ for (i = 0; i < movedcount; i++)
+ {
+ idx.Read (&m_pMovedReference[i*18], 8);
+ idx.Read (&m_pMovedReference[i*18+9], 8);
+ }
+
+ idx.Close();
bin.Close();
// Load groups configuration
- if (!LoadGroupConfig (Sys_ProfileLoadString ("Settings", "Groups", "")))
- {
- m_strGroups[0] = "Plates";
- m_strGroups[1] = "Bricks";
- m_strGroups[2] = "Tiles";
- m_strGroups[3] = "Slope Bricks";
- m_strGroups[4] = "Technic";
- m_strGroups[5] = "Space";
- m_strGroups[6] = "Train";
- m_strGroups[7] = "Other Bricks";
- m_strGroups[8] = "Accessories";
- m_nGroupCount = 9;
- }
+ const char* FileName = Sys_ProfileLoadString("Settings", "Categories", "");
+ if (!strlen(FileName) || !LoadCategories(FileName))
+ ResetCategories();
// Read the texture index.
strcpy(filename, m_LibraryPath);
@@ -171,13 +148,13 @@ bool PiecesLibrary::Load (const char *libpath)
return false;
}
- strcpy (filename, m_LibraryPath);
- strcat (filename, "textures.bin");
+ strcpy (filename, m_LibraryPath);
+ strcat (filename, "textures.bin");
- if (!bin.Open (filename, "rb"))
+ if (!bin.Open (filename, "rb"))
{
console.PrintError ("Cannot open Textures Library file: %s.\n", filename);
- return false;
+ return false;
}
if (!ValidateTexturesFile (idx, bin))
@@ -198,43 +175,10 @@ bool PiecesLibrary::Load (const char *libpath)
idx.Close();
bin.Close();
- // TODO: Load categories.
-
- const int NumCategories = 34;
- const char* DefaultCategories[] =
- {
- "Animal", "Antenna", "Arm", "Bar", "Baseplate", "Belville", "Boat", "Bracket", "Brick", "Car",
- "Cone", "Container", "Crane", "Cylinder", "Door", "Flag", "Hinge", "Hose", "Magnet", "Minifig",
- "Minifig Accessory", "Plane", "Plant", "Plate", "Propellor", "Rock", "Round", "Scala",
- "Slope", "Space", "Support", "Technic", "Wheel", "Windscreen"
- };
-
-
- for (i = 0; i < NumCategories; i++)
- {
- PiecesLibraryCategory Cat;
-
- Cat.Name = DefaultCategories[i];
- Cat.Keywords = DefaultCategories[i];
-
- m_Categories.Add(Cat);
- }
-
SystemUpdateCategories(false);
- m_bNeedsReload = false;
-
- return true;
-}
-
-bool PiecesLibrary::LoadGroupConfig (const char* Filename)
-{
- // FIXME:
- return false;
-
-
- strcpy (m_GroupsFile, Filename);
-
+ m_CategoriesModified = false;
+ m_Modified = false;
return true;
}
@@ -243,12 +187,12 @@ bool PiecesLibrary::LoadGroupConfig (const char* Filename)
bool PiecesLibrary::ValidatePiecesFile (File& IdxFile, File& BinFile) const
{
lcuint32 binsize, IdxPos = IdxFile.GetPosition(), BinPos = BinFile.GetPosition();
- lcuint16 count, movedcount;
+ lcuint16 count, movedcount;
lcuint8 version;
char header[32];
- IdxFile.Seek (-(long)(2*sizeof(count)+sizeof(binsize)), SEEK_END);
- IdxFile.ReadShort (&movedcount, 1);
+ IdxFile.Seek (-(long)(2*sizeof(count)+sizeof(binsize)), SEEK_END);
+ IdxFile.ReadShort (&movedcount, 1);
IdxFile.ReadLong (&binsize, 1);
IdxFile.ReadShort (&count, 1);
IdxFile.Seek (0, SEEK_SET);
@@ -291,7 +235,7 @@ bool PiecesLibrary::ValidatePiecesFile (File& IdxFile, File& BinFile) const
bool PiecesLibrary::ValidateTexturesFile (File& IdxFile, File& BinFile) const
{
lcuint32 binsize, IdxPos = IdxFile.GetPosition(), BinPos = BinFile.GetPosition();
- lcuint16 count;
+ lcuint16 count;
lcuint8 version;
char header[32];
@@ -340,57 +284,211 @@ bool PiecesLibrary::ValidateTexturesFile (File& IdxFile, File& BinFile) const
// Remember to make 'name' uppercase.
PieceInfo* PiecesLibrary::FindPieceInfo (const char* name) const
{
- PieceInfo* pInfo;
- int i;
+ PieceInfo* pInfo;
+ int i;
- for (i = 0, pInfo = m_pPieceIdx; i < m_nPieceCount; i++, pInfo++)
- if (!strcmp (name, pInfo->m_strName))
- return pInfo;
+ for (i = 0, pInfo = m_pPieceIdx; i < m_nPieceCount; i++, pInfo++)
+ if (!strcmp (name, pInfo->m_strName))
+ return pInfo;
- for (i = 0; i < m_nMovedCount; i++)
- {
- if (!strcmp (&m_pMovedReference[i*18], name))
- {
- char* tmp = &m_pMovedReference[i*18+9];
+ for (i = 0; i < m_nMovedCount; i++)
+ {
+ if (!strcmp (&m_pMovedReference[i*18], name))
+ {
+ char* tmp = &m_pMovedReference[i*18+9];
- for (i = 0, pInfo = m_pPieceIdx; i < m_nPieceCount; i++, pInfo++)
- if (!strcmp (tmp, pInfo->m_strName))
- return pInfo;
+ for (i = 0, pInfo = m_pPieceIdx; i < m_nPieceCount; i++, pInfo++)
+ if (!strcmp (tmp, pInfo->m_strName))
+ return pInfo;
- break; // something went wrong.
- }
- }
+ break; // something went wrong.
+ }
+ }
- return NULL;
+ return NULL;
}
-PieceInfo* PiecesLibrary::GetPieceInfo (int index) const
+PieceInfo* PiecesLibrary::GetPieceInfo(int index) const
{
- return &m_pPieceIdx[index];
+ return &m_pPieceIdx[index];
}
-int PiecesLibrary::GetPieceIndex (PieceInfo *pInfo) const
+int PiecesLibrary::GetPieceIndex(PieceInfo *pInfo) const
{
- return (((char*)pInfo - (char*)m_pPieceIdx) / sizeof (PieceInfo));
+ return (((char*)pInfo - (char*)m_pPieceIdx) / sizeof (PieceInfo));
}
-Texture* PiecesLibrary::FindTexture (const char* name) const
+Texture* PiecesLibrary::FindTexture(const char* name) const
{
- for (int i = 0; i < m_nTextureCount; i++)
- if (!strcmp (name, m_pTextures[i].m_strName))
- return &m_pTextures[i];
+ for (int i = 0; i < m_nTextureCount; i++)
+ if (!strcmp (name, m_pTextures[i].m_strName))
+ return &m_pTextures[i];
- return NULL;
+ return NULL;
}
Texture* PiecesLibrary::GetTexture (int index) const
{
- return &m_pTextures[index];
+ return &m_pTextures[index];
+}
+
+// =============================================================================
+// Category functions.
+
+void PiecesLibrary::ResetCategories()
+{
+ const int NumCategories = 34;
+ const char* DefaultCategories[] =
+ {
+ "Animal", "Antenna", "Arm", "Bar", "Baseplate", "Belville", "Boat", "Bracket", "Brick", "Car",
+ "Cone", "Container", "Crane", "Cylinder", "Door", "Flag", "Hinge", "Hose", "Magnet", "Minifig",
+ "Minifig Accessory", "Plane", "Plant", "Plate", "Propellor", "Rock", "Round", "Scala",
+ "Slope", "Space", "Support", "Technic", "Wheel", "Windscreen"
+ };
+
+ m_Categories.RemoveAll();
+ for (int i = 0; i < NumCategories; i++)
+ {
+ PiecesLibraryCategory Cat;
+
+ Cat.Name = DefaultCategories[i];
+ Cat.Keywords = DefaultCategories[i];
+
+ m_Categories.Add(Cat);
+ }
+
+ strcpy(m_CategoriesFile, "");
+ Sys_ProfileSaveString("Settings", "Categories", m_CategoriesFile);
+ m_CategoriesModified = false;
+}
+
+bool PiecesLibrary::LoadCategories(const char* FileName)
+{
+ char Path[LC_MAXPATH];
+
+ if (FileName)
+ {
+ strcpy(Path, FileName);
+ }
+ else
+ {
+ LC_FILEOPENDLG_OPTS opts;
+
+ opts.type = LC_FILEOPENDLG_LCF;
+ strcpy(opts.path, m_CategoriesFile);
+
+ if (!SystemDoDialog(LC_DLG_FILE_OPEN, &opts))
+ return false;
+
+ strcpy(Path, (char*)opts.filenames);
+
+ free(opts.filenames);
+ }
+
+ // Load the file.
+ FileDisk File;
+
+ if (!File.Open(Path, "rb"))
+ return false;
+
+ lcuint32 i;
+
+ File.ReadInt(&i);
+ if (i != LC_FILE_ID)
+ return false;
+
+ File.ReadInt(&i);
+ if (i != LC_CATEGORY_FILE_ID)
+ return false;
+
+ File.ReadInt(&i);
+ if (i != LC_CATEGORY_FILE_VERSION)
+ return false;
+
+ File.ReadInt(&i);
+ while (i--)
+ {
+ PiecesLibraryCategory Cat;
+
+ File.ReadString(Cat.Name);
+ File.ReadString(Cat.Keywords);
+
+ m_Categories.Add(Cat);
+ }
+
+ strcpy(m_CategoriesFile, Path);
+ Sys_ProfileSaveString("Settings", "Categories", m_CategoriesFile);
+ m_CategoriesModified = false;
+
+ return true;
+}
+
+// Returns true if it's ok to continue.
+bool PiecesLibrary::SaveCategories()
+{
+ if (m_CategoriesModified)
+ {
+ switch (SystemDoMessageBox("Save category changes ?", LC_MB_YESNOCANCEL|LC_MB_ICONQUESTION))
+ {
+ case LC_CANCEL:
+ return false;
+
+ case LC_YES:
+ if (!DoSaveCategories(false))
+ return false;
+ break;
+
+ case LC_NO:
+ return true;
+ break;
+ }
+ }
+
+ return true;
+}
+
+bool PiecesLibrary::DoSaveCategories(bool AskName)
+{
+ // Get the file name.
+ if (AskName || (strlen(m_CategoriesFile) == 0))
+ {
+ LC_FILESAVEDLG_OPTS opts;
+
+ opts.type = LC_FILESAVEDLG_LCF;
+ strcpy(opts.path, m_CategoriesFile);
+
+ if (!SystemDoDialog(LC_DLG_FILE_SAVE, &opts))
+ return false;
+
+ strcpy(m_CategoriesFile, opts.path);
+ }
+
+ // Save the file.
+ FileDisk File;
+
+ if (!File.Open(m_CategoriesFile, "wb"))
+ return false;
+
+ File.WriteInt(LC_FILE_ID);
+ File.WriteInt(LC_CATEGORY_FILE_ID);
+ File.WriteInt(LC_CATEGORY_FILE_VERSION);
+
+ File.WriteInt(m_Categories.GetSize());
+ for (int i = 0; i < m_Categories.GetSize(); i++)
+ {
+ File.WriteString(m_Categories[i].Name);
+ File.WriteString(m_Categories[i].Keywords);
+ }
+
+ Sys_ProfileSaveString("Settings", "Categories", m_CategoriesFile);
+ m_CategoriesModified = false;
+
+ return true;
}
// =============================================================================
-void PiecesLibrary::GetCategoryEntries(int CategoryIndex, PtrArray<PieceInfo>& SinglePieces, PtrArray<PieceInfo>& GroupedPieces)
+void PiecesLibrary::GetCategoryEntries(int CategoryIndex, bool GroupPieces, PtrArray<PieceInfo>& SinglePieces, PtrArray<PieceInfo>& GroupedPieces)
{
bool m_bSubParts = false;
@@ -400,7 +498,9 @@ void PiecesLibrary::GetCategoryEntries(int CategoryIndex, PtrArray<PieceInfo>& S
String Keywords = m_Categories[CategoryIndex].Keywords;
Keywords.MakeLower();
- bool SearchResults = (m_Categories[CategoryIndex].Name == "Search Results");
+ // Don't group entries in the search results category.
+ if (m_Categories[CategoryIndex].Name == "Search Results")
+ GroupPieces = false;
for (int i = 0; i < m_nPieceCount; i++)
{
@@ -441,24 +541,27 @@ void PiecesLibrary::GetCategoryEntries(int CategoryIndex, PtrArray<PieceInfo>& S
if (!Match)
continue;
+ if (!GroupPieces)
+ {
+ SinglePieces.Add(Info);
+ continue;
+ }
+
// Check if it's a patterned piece.
const char* Name = Info->m_strName;
- if (!SearchResults)
+ while (*Name)
{
- while (*Name)
- {
- if (!*Name || *Name < '0' || *Name > '9')
- break;
+ if (!*Name || *Name < '0' || *Name > '9')
+ break;
- if (*Name == 'P')
- break;
+ if (*Name == 'P')
+ break;
- Name++;
- }
+ Name++;
}
- if (*Name == 'P' && !SearchResults)
+ if (*Name == 'P')
{
PieceInfo* Parent;
@@ -522,6 +625,8 @@ void PiecesLibrary::SetCategory(int Index, const String& Name, const String& Key
m_Categories[Index].Keywords = Keywords;
SystemUpdateCategories(true);
+
+ m_CategoriesModified = true;
}
void PiecesLibrary::AddCategory(const String& Name, const String& Keywords)
@@ -534,94 +639,22 @@ void PiecesLibrary::AddCategory(const String& Name, const String& Keywords)
m_Categories.Add(Cat);
SystemUpdateCategories(true);
+
+ m_CategoriesModified = true;
}
void PiecesLibrary::RemoveCategory(int Index)
{
m_Categories.RemoveIndex(Index);
-}
-
-unsigned long PiecesLibrary::GetDefaultPieceGroup (const char* name)
-{
- char tmp[9];
- strncpy(tmp, name, 9);
-// tmp[8] = 0;
-
- if (strstr(tmp,"Baseplate") || strstr(tmp,"Plate") ||
- strstr(tmp,"Platform"))
- return 0x001;
- if (strstr(tmp,"Brick") || strstr(tmp,"Cylin") ||
- strstr(tmp,"Cone"))
- return 0x002;
-
- if (strstr(tmp,"Tile"))
- return 0x004;
-
- if (strstr(tmp,"Slope"))
- return 0x008;
-
- if (strstr(tmp,"Technic") || strstr(tmp,"Crane") ||
- strstr(tmp,"Wheel") || strstr(tmp,"Tyre") ||
- strstr(tmp,"Electric"))
- return 0x010;
-
- // space & plane
- if (strstr(tmp,"Space") || strstr(tmp,"Plane") ||
- strstr(tmp,"Windscr") || strstr(tmp,"~2421") ||
- strstr(tmp,"Wing") || strstr(tmp,"Wedge") ||
- strstr(tmp,"Propellor") || strstr(tmp,"Rotor") ||
- strstr(tmp,"Rack") || strstr(tmp,"Tail") ||
- strstr(tmp,"Cockpit"))
- return 0x020;
-
- if (strstr(tmp,"Train"))
- return 0x040;
-
- // other parts
- if (strstr(tmp,"Arch") || strstr(tmp,"Panel") ||
- strstr(tmp,"Car") || strstr(tmp,"Window") ||
- strstr(tmp,"Freestyle") || strstr(tmp,"Support")||
- strstr(tmp,"Fence") || strstr(tmp,"Gate") ||
- strstr(tmp,"Garage") || strstr(tmp,"Stairs") ||
- strstr(tmp,"Bracket") || strstr(tmp,"Hinge") ||
- strstr(tmp,"Homemaker") || strstr(tmp,"Rock") ||
- strstr(tmp,"Cupboard") || strstr(tmp,"Storage")||
- strstr(tmp,"Scala") || strstr(tmp,"Boat") ||
- strstr(tmp,"Trailer") || strstr(tmp,"Box") ||
- strstr(tmp,"Turntab") || strstr(tmp,"Winch") ||
- strstr(tmp,"Door") || strstr(tmp,"Magnet") ||
- strstr(tmp,"Staircase") || strstr(tmp,"Glass") ||
- strstr(tmp,"Container"))
- return 0x080;
-
- // accessories
- if (strstr(tmp,"Minifig") || strstr(tmp,"Antenna")||
- strstr(tmp,"Ladder") || strstr(tmp,"Jack") ||
- strstr(tmp,"Exhaust") || strstr(tmp,"Lever") ||
- strstr(tmp,"Roadsign") || strstr(tmp,"Town") ||
- strstr(tmp,"Leaves") || strstr(tmp,"Horse") ||
- strstr(tmp,"Tree") || strstr(tmp,"Flower") ||
- strstr(tmp,"Plant") || strstr(tmp,"Pannier")||
- strstr(tmp,"Conveyor") || strstr(tmp,"Tractor")||
- strstr(tmp,"Grab") || strstr(tmp,"Roller") ||
- strstr(tmp,"Stretch") || strstr(tmp,"Tap ") ||
- strstr(tmp,"Forklift") || strstr(tmp,"Flag") ||
- strstr(tmp,"Belville") || strstr(tmp,"Light &")||
- strstr(tmp,"Hose") || strstr(tmp,"Arm P") ||
- strstr(tmp,"Brush") || strstr(tmp,"Castle") ||
- strstr(tmp,"Tipper") || strstr(tmp,"Bar") ||
- strstr(tmp,"Animal"))
- return 0x100;
-
- return 1;
+ m_CategoriesModified = true;
}
// =============================================================================
// Pieces handling stuff
// Remove pieces from the library
-bool PiecesLibrary::DeletePieces (char** names, int numpieces)
+bool PiecesLibrary::DeletePieces (PtrArray<PieceInfo>& Pieces)
{
FileDisk newbin, newidx, oldbin, oldidx;
char file1[LC_MAXPATH], file2[LC_MAXPATH], tmp[200];
@@ -676,11 +709,11 @@ bool PiecesLibrary::DeletePieces (char** names, int numpieces)
name[8] = 0;
oldidx.Read(&name, 8);
- for (i = 0; i < numpieces; i++)
- if (strcmp(name, names[i]) == 0)
+ for (i = 0; i < Pieces.GetSize(); i++)
+ if (strcmp(name, Pieces[i]->m_strName) == 0)
break;
- if (i != numpieces)
+ if (i != Pieces.GetSize())
{
oldidx.Seek(64+12+1+4+4+4, SEEK_CUR);
deleted++;
@@ -727,7 +760,7 @@ bool PiecesLibrary::DeletePieces (char** names, int numpieces)
newidx.Close();
newbin.Close();
- m_bNeedsReload = true;
+ m_Modified = true;
return true;
}
@@ -974,7 +1007,7 @@ bool PiecesLibrary::LoadUpdate (const char* update)
newbin.Close();
up.Close();
- m_bNeedsReload = true;
+ m_Modified = true;
return true;
}
@@ -1092,7 +1125,7 @@ bool PiecesLibrary::DeleteTextures (char** Names, int NumTextures)
count -= deleted;
newidx.WriteShort (&count, 1);
- m_bNeedsReload = true;
+ m_Modified = true;
return true;
}
@@ -1275,7 +1308,7 @@ bool PiecesLibrary::ImportTexture (const char* Name)
count -= deleted;
newidx.WriteShort (&count, 1);
- m_bNeedsReload = true;
+ m_Modified = true;
return true;
}
@@ -2538,7 +2571,7 @@ bool SaveLDrawPiece(LC_LDRAW_PIECE* piece)
newidx.WriteByte(&bt, 1);
- i = PiecesLibrary::GetDefaultPieceGroup(piece->description);
+ i = 0;//PiecesLibrary::GetDefaultPieceGroup(piece->description);
newidx.WriteLong(&i, 1);
newidx.WriteLong(&binoff, 1);
diff --git a/common/library.h b/common/library.h
index 0300e04..a8ba118 100755
--- a/common/library.h
+++ b/common/library.h
@@ -9,7 +9,8 @@ class File;
class Texture;
class PieceInfo;
-#define LC_PIECESLIB_MAXGROUPS 32
+#define LC_CATEGORY_FILE_ID LC_FOURCC('C', 'A', 'T', 0)
+#define LC_CATEGORY_FILE_VERSION 0x0100
typedef struct
{
@@ -20,28 +21,26 @@ typedef struct
class PiecesLibrary
{
public:
- PiecesLibrary ();
- ~PiecesLibrary ();
-
- const char* GetLibraryPath() const
- { return m_LibraryPath; }
- int GetPieceCount () const
- { return m_nPieceCount; }
- int GetTextureCount () const
- { return m_nTextureCount; }
- int GetGroupCount () const
- { return m_nGroupCount; }
- String& GetGroup (int i)
- { return m_strGroups[i]; }
- bool NeedsReload () const
- { return m_bNeedsReload; }
+ PiecesLibrary();
+ ~PiecesLibrary();
+
+ const char* GetLibraryPath() const
+ { return m_LibraryPath; }
+ int GetPieceCount () const
+ { return m_nPieceCount; }
+ int GetTextureCount () const
+ { return m_nTextureCount; }
// Categories.
- void GetCategoryEntries(int CategoryIndex, PtrArray<PieceInfo>& SinglePieces, PtrArray<PieceInfo>& GroupedPieces);
+ void GetCategoryEntries(int CategoryIndex, bool GroupPieces, PtrArray<PieceInfo>& SinglePieces, PtrArray<PieceInfo>& GroupedPieces);
void GetPatternedPieces(PieceInfo* Parent, PtrArray<PieceInfo>& Pieces);
void SetCategory(int Index, const String& Name, const String& Keywords);
void AddCategory(const String& Name, const String& Keywords);
void RemoveCategory(int Index);
+ void ResetCategories();
+ bool SaveCategories();
+ bool DoSaveCategories(bool AskName);
+ bool LoadCategories(const char* FileName);
const char* GetCategoryName(int Index) const
{ return m_Categories[Index].Name; }
@@ -61,32 +60,28 @@ public:
return -1;
}
- void CheckReload ();
- bool Load (const char* libpath);
- void Unload ();
- bool LoadGroupConfig (const char* Filename);
+ bool Load(const char* libpath);
+ void Unload();
// Search for pieces.
- 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;
+ 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 DeletePieces (char** names, int numpieces);
- bool LoadUpdate (const char* update);
- bool DeleteTextures (char** Names, int NumTextures);
- bool ImportTexture (const char* Name);
- bool ImportLDrawPiece (const char* Filename);
-
- static unsigned long GetDefaultPieceGroup (const char* name);
+ bool DeletePieces(PtrArray<PieceInfo>& Pieces);
+ bool LoadUpdate(const char* update);
+ bool DeleteTextures(char** Names, int NumTextures);
+ bool ImportTexture(const char* Name);
+ bool ImportLDrawPiece(const char* Filename);
protected:
- char m_LibraryPath[LC_MAXPATH]; // path to the library files
+ char m_LibraryPath[LC_MAXPATH]; // path to the library files
int m_nMovedCount; // number of moved pieces
- char* m_pMovedReference; // moved pieces list
+ char* m_pMovedReference; // moved pieces list
int m_nPieceCount; // number of pieces
PieceInfo* m_pPieceIdx; // pieces array
int m_nTextureCount; // number of textures
@@ -95,12 +90,9 @@ protected:
// Categories.
ObjArray<PiecesLibraryCategory> m_Categories;
- // Groups stuff
- int m_nGroupCount;
- String m_strGroups[LC_PIECESLIB_MAXGROUPS];
- char m_GroupsFile[LC_MAXPATH];
-
- bool m_bNeedsReload; // if the library files were changed and they need to be reloaded
+ bool m_Modified;
+ bool m_CategoriesModified;
+ char m_CategoriesFile[LC_MAXPATH];
bool ValidatePiecesFile (File& IdxFile, File& BinFile) const;
bool ValidateTexturesFile (File& IdxFile, File& BinFile) const;
diff --git a/common/project.cpp b/common/project.cpp
index 9f60bb8..af5cf72 100644
--- a/common/project.cpp
+++ b/common/project.cpp
@@ -1228,7 +1228,7 @@ void Project::FileReadMPD(File& MPD, PtrArray<File>& FileArray) const
FileMem* CurFile = NULL;
char Buf[1024];
- while (MPD.ReadString(Buf, 1024))
+ while (MPD.ReadLine(Buf, 1024))
{
String Line(Buf);
@@ -1279,7 +1279,7 @@ void Project::FileReadLDraw(File* file, Matrix* prevmat, int* nOk, int DefColor,
lcuint32 Offset = file->GetPosition();
file->Seek(0, SEEK_SET);
- while (file->ReadString(buf, 1024))
+ while (file->ReadLine(buf, 1024))
{
strupr(buf);
if (strstr(buf, "STEP"))
@@ -4728,6 +4728,8 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
FileMem file;
FileSave(&file, true);
+ // TODO: save piece IDs and reload.
+
if (SystemDoDialog(LC_DLG_LIBRARY, NULL))
{
/*
diff --git a/common/typedefs.h b/common/typedefs.h
index 51c1283..0d147c6 100644
--- a/common/typedefs.h
+++ b/common/typedefs.h
@@ -287,6 +287,7 @@ typedef enum {
LC_DLG_FILE_SAVE_PROJECT,
LC_DLG_FILE_MERGE_PROJECT,
LC_DLG_FILE_OPEN,
+ LC_DLG_FILE_SAVE,
LC_DLG_PICTURE_SAVE,
LC_DLG_HTML,
LC_DLG_POVRAY,
@@ -308,7 +309,7 @@ typedef enum {
typedef enum
{
LC_FILEOPENDLG_DAT,
- LC_FILEOPENDLG_LGF,
+ LC_FILEOPENDLG_LCF,
LC_FILEOPENDLG_LUP
} LC_FILEOPENDLG_TYPES;
@@ -320,6 +321,17 @@ typedef struct
char** filenames;
} LC_FILEOPENDLG_OPTS;
+typedef enum
+{
+ LC_FILESAVEDLG_LCF,
+} LC_FILESAVEDLG_TYPES;
+
+typedef struct
+{
+ int type;
+ char path[LC_MAXPATH];
+} LC_FILESAVEDLG_OPTS;
+
typedef struct
{
bool render;
diff --git a/win/LeoCAD.dsp b/win/LeoCAD.dsp
index 7f54c21..c760b42 100644
--- a/win/LeoCAD.dsp
+++ b/win/LeoCAD.dsp
@@ -1056,10 +1056,6 @@ SOURCE=..\common\keyboard.h
# End Source File
# Begin Source File
-SOURCE=..\common\libman.h
-# End Source File
-# Begin Source File
-
SOURCE=..\common\library.h
# End Source File
# Begin Source File
@@ -1230,11 +1226,6 @@ SOURCE=..\common\keyboard.cpp
# End Source File
# Begin Source File
-SOURCE=..\common\libman.cpp
-# SUBTRACT CPP /YX /Yc /Yu
-# End Source File
-# Begin Source File
-
SOURCE=..\common\library.cpp
# SUBTRACT CPP /YX /Yc /Yu
# End Source File
diff --git a/win/LeoCAD.rc b/win/LeoCAD.rc
index 7a1c0a2..eebc1b1 100644
--- a/win/LeoCAD.rc
+++ b/win/LeoCAD.rc
@@ -187,16 +187,13 @@ END
IDR_LIBRARY TOOLBAR DISCARDABLE 16, 15
BEGIN
- BUTTON ID_LIBDLG_FILE_RESET
BUTTON ID_LIBDLG_FILE_OPEN
BUTTON ID_LIBDLG_FILE_SAVE
BUTTON ID_LIBDLG_FILE_PRINTCATALOG
SEPARATOR
- BUTTON ID_LIBDLG_GROUP_INSERT
- BUTTON ID_LIBDLG_GROUP_DELETE
- BUTTON ID_LIBDLG_GROUP_MOVEUP
- BUTTON ID_LIBDLG_GROUP_MOVEDOWN
- BUTTON ID_LIBDLG_GROUP_RENAME
+ BUTTON ID_LIBDLG_CATEGORY_NEW
+ BUTTON ID_LIBDLG_CATEGORY_REMOVE
+ BUTTON ID_LIBDLG_CATEGORY_EDIT
END
IDR_TERRAIN TOOLBAR DISCARDABLE 16, 15
@@ -514,35 +511,30 @@ IDR_LIBRARY MENU DISCARDABLE
BEGIN
POPUP "&File"
BEGIN
- MENUITEM "&Reset", ID_LIBDLG_FILE_RESET
MENUITEM "&Open...", ID_LIBDLG_FILE_OPEN
MENUITEM "&Save", ID_LIBDLG_FILE_SAVE
MENUITEM "Save &As...", ID_LIBDLG_FILE_SAVEAS
MENUITEM SEPARATOR
- MENUITEM "Load &Bitmap", ID_LIBDLG_FILE_LOADBITMAP
- , GRAYED
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
+ MENUITEM "Close", IDOK
END
- POPUP "&Group"
+ POPUP "&Category"
BEGIN
- MENUITEM "Insert...", ID_LIBDLG_GROUP_INSERT
- MENUITEM "Delete", ID_LIBDLG_GROUP_DELETE
- MENUITEM "Rename...", ID_LIBDLG_GROUP_RENAME
+ MENUITEM "Rese&t Categories...", ID_LIBDLG_CATEGORY_RESET
MENUITEM SEPARATOR
- MENUITEM "Move Up", ID_LIBDLG_GROUP_MOVEUP
- MENUITEM "Move Down", ID_LIBDLG_GROUP_MOVEDOWN
+ MENUITEM "&New...", ID_LIBDLG_CATEGORY_NEW
+ MENUITEM "&Remove...", ID_LIBDLG_CATEGORY_REMOVE
+ MENUITEM "&Edit...", ID_LIBDLG_CATEGORY_EDIT
END
POPUP "&Piece"
BEGIN
MENUITEM "&New", ID_LIBDLG_PIECE_NEW, GRAYED
MENUITEM "&Edit", ID_LIBDLG_PIECE_EDIT, GRAYED
- MENUITEM "&Delete", ID_LIBDLG_PIECE_DELETE
+ MENUITEM "&Delete...", ID_LIBDLG_PIECE_DELETE
END
END
@@ -2069,22 +2061,6 @@ END
STRINGTABLE DISCARDABLE
BEGIN
- ID_LIBDLG_GROUP_MOVEUP "Move Group Up"
- ID_LIBDLG_GROUP_MOVEDOWN "Move Group Down"
- ID_LIBDLG_FILE_RESET "Reset"
- ID_LIBDLG_FILE_OPEN "Open Configuration"
- ID_LIBDLG_FILE_SAVE "Save Configuration"
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- ID_LIBDLG_GROUP_INSERT "New Group"
- ID_LIBDLG_GROUP_DELETE "Delete Group"
- ID_LIBDLG_GROUP_RENAME "Rename Group"
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
ID_PIECE_COPYKEYS "Copy position and rotation"
END
diff --git a/win/Libdlg.cpp b/win/Libdlg.cpp
index bca7222..fc45916 100644
--- a/win/Libdlg.cpp
+++ b/win/Libdlg.cpp
@@ -13,6 +13,7 @@
#include "pieceinf.h"
#include "globals.h"
#include "system.h"
+#include "library.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@@ -20,9 +21,6 @@
static char THIS_FILE[] = __FILE__;
#endif
-static const char ver_str[32] = "LeoCAD Group Configuration File";
-static const float ver_flt = 0.3f;
-
/////////////////////////////////////////////////////////////////////////////
// CLibraryDlg dialog
@@ -30,9 +28,6 @@ static const float ver_flt = 0.3f;
CLibraryDlg::CLibraryDlg(CWnd* pParent /*=NULL*/)
: CDialog(CLibraryDlg::IDD, pParent)
{
- m_pDragImage = NULL;
- m_bDragging = FALSE;
-
//{{AFX_DATA_INIT(CLibraryDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
@@ -40,7 +35,6 @@ CLibraryDlg::CLibraryDlg(CWnd* pParent /*=NULL*/)
CLibraryDlg::~CLibraryDlg()
{
- delete m_pDragImage;
}
void CLibraryDlg::DoDataExchange(CDataExchange* pDX)
@@ -56,9 +50,6 @@ void CLibraryDlg::DoDataExchange(CDataExchange* pDX)
BEGIN_MESSAGE_MAP(CLibraryDlg, CDialog)
//{{AFX_MSG_MAP(CLibraryDlg)
ON_NOTIFY(TVN_SELCHANGED, IDC_LIBDLG_TREE, OnSelChangedTree)
- ON_NOTIFY(LVN_BEGINDRAG, IDC_LIBDLG_LIST, OnBeginDragList)
- ON_WM_MOUSEMOVE()
- ON_WM_LBUTTONUP()
//}}AFX_MSG_MAP
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
@@ -72,45 +63,44 @@ BOOL CLibraryDlg::OnInitDialog()
CDialog::OnInitDialog();
// Add the ToolBar.
- if (!m_wndToolBar.Create(this) ||
- !m_wndToolBar.LoadToolBar(IDR_LIBRARY))
+ if (!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_LIBRARY))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
-
+
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
-
+
// We need to resize the dialog to make room for control bars.
// First, figure out how big the control bars are.
CRect rcClientStart;
CRect rcClientNow;
GetClientRect(rcClientStart);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0, reposQuery, rcClientNow);
-
+
// Now move all the controls so they are in the same relative
// position within the remaining client area as they would be
// with no control bars.
CPoint ptOffset(rcClientNow.left - rcClientStart.left, rcClientNow.top - rcClientStart.top);
-
- CRect rcChild;
+
+ CRect rcChild;
CWnd* pwndChild = GetWindow(GW_CHILD);
while (pwndChild)
- {
+ {
pwndChild->GetWindowRect(rcChild);
ScreenToClient(rcChild);
rcChild.OffsetRect(ptOffset);
pwndChild->MoveWindow(rcChild, FALSE);
pwndChild = pwndChild->GetNextWindow();
}
-
+
// Adjust the dialog window dimensions
CRect rcWindow;
GetWindowRect(rcWindow);
rcWindow.right += rcClientStart.Width() - rcClientNow.Width();
rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height();
MoveWindow(rcWindow, FALSE);
-
+
// And position the control bars
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
@@ -127,118 +117,21 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
{
switch (LOWORD(wParam))
{
- case ID_LIBDLG_FILE_RESET:
- {
- m_Manager.HandleCommand (LC_LIBDLG_FILE_RESET, 0);
-
- m_ImageList.DeleteImageList();
- m_ImageList.Create(IDB_PIECEBAR, 16, 0, 0x00ff00ff);
-
- for (int i = 0; i < 32; i++)
- m_nBitmaps[i] = min(i,9);
-
- UpdateList();
- UpdateTree();
-
- return TRUE;
- }
-
case ID_LIBDLG_FILE_OPEN:
{
-/*
- CFileDialog dlg(TRUE, ".lgf\0", NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
- "LeoCAD Group Files (*.lgf)|*.lgf|All Files (*.*)|*.*||",this);
-
- if (dlg.DoModal() == IDOK)
- {
- m_ImageList.DeleteImageList();
- m_strFile = dlg.GetPathName();
- CWaitCursor wait;
- CFile f(m_strFile, CFile::modeRead|CFile::shareDenyWrite);
- if (f.GetLength() != 0)
- {
- CArchive ar(&f, CArchive::load | CArchive::bNoFlushOnDelete);
- for (int i = 0; i < m_Parts.GetSize(); i++)
- m_Parts[i].group = m_Parts[i].defgroup;
-
- char tmp[32];
- float ver;
- CString str;
- int n;
- ar.Read (tmp, sizeof(tmp));
- ar >> ver;
- if (ver == 0.1f)
- ar >> i;
- else
- {
- memset(m_strGroups, 0, sizeof(m_strGroups));
- ar >> m_nMaxGroups;
- for (i = 0; i < m_nMaxGroups; i++)
- {
- ar.Read (m_strGroups[i], sizeof(m_strGroups[i]));
-
- if (ver > 0.2f)
- ar >> m_nBitmaps[i];
- }
- }
-
- if (ver > 0.2f)
- m_ImageList.Read(&ar);
-
- ar >> n;
- for (i = 0; i < n; i++)
- {
- char name[9], description[65];
- unsigned long group;
-
- ar.Read (name, sizeof(name));
- if (ver == 0.1f)
- {
- BYTE b;
- ar.Read (description, sizeof(description));
- ar >> b;
- group = 1 << b;
- }
- else
- ar >> group;
-
- for (int j = 0; j < m_Parts.GetSize(); j++)
- if (strcmp (m_Parts[j].info->m_strName, name) == 0)
- {
- m_Parts[j].group = group;
- break;
- }
- }
- ar.Close();
- }
- f.Close();
-
- if (m_ImageList.GetImageCount() == 0)
- m_ImageList.Create(IDB_PIECEBAR, 16, 0, 0x00ff00ff);
-
- m_bModified = FALSE;
- UpdateList();
- UpdateTree();
- }
-*/
+ project->GetPiecesLibrary()->LoadCategories(NULL);
return TRUE;
}
case ID_LIBDLG_FILE_SAVE:
{
- m_Manager.DoSave(false);
+ project->GetPiecesLibrary()->DoSaveCategories(false);
return TRUE;
}
case ID_LIBDLG_FILE_SAVEAS:
{
- m_Manager.DoSave(true);
- return TRUE;
- }
-
- case ID_LIBDLG_FILE_LOADBITMAP:
- {
-
+ project->GetPiecesLibrary()->DoSaveCategories(true);
return TRUE;
}
@@ -254,190 +147,167 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
case ID_LIBDLG_FILE_MERGEUPDATE:
{
- m_Manager.HandleCommand (LC_LIBDLG_FILE_MERGEUPDATE, 0);
- UpdateList();
+ LC_FILEOPENDLG_OPTS opts;
- return TRUE;
- }
+ strcpy(opts.path, "");
+ opts.type = LC_FILEOPENDLG_LUP;
- case ID_FILE_IMPORTPIECE:
- {
- m_Manager.HandleCommand (LC_LIBDLG_FILE_IMPORTPIECE, 0);
- UpdateList();
+ if (SystemDoDialog(LC_DLG_FILE_OPEN, &opts))
+ {
+ project->GetPiecesLibrary()->LoadUpdate((char*)opts.filenames);
+
+ free(opts.filenames);
+
+ UpdateList();
+ }
return TRUE;
}
- case ID_LIBDLG_FILE_TEXTURES:
+ case ID_FILE_IMPORTPIECE:
{
- CTexturesDlg dlg;
- dlg.DoModal();
- } break;
+ LC_FILEOPENDLG_OPTS opts;
- case ID_LIBDLG_GROUP_INSERT:
- {
- HTREEITEM hti = m_Tree.GetSelectedItem();
+ strcpy(opts.path, Sys_ProfileLoadString ("Default", "LDraw Pieces Path", ""));
+ opts.type = LC_FILEOPENDLG_DAT;
- if (hti)
+ if (SystemDoDialog (LC_DLG_FILE_OPEN, &opts))
{
- DWORD dw = m_Tree.GetItemData(hti);
- if (dw == 0)
- dw = 1;
- dw--;
-
- m_Manager.HandleCommand (LC_LIBDLG_GROUP_INSERT, dw);
+ for (int i = 0; i < opts.numfiles; i++)
+ {
+ project->GetPiecesLibrary ()->ImportLDrawPiece (opts.filenames[i]);
+ free (opts.filenames[i]);
+ }
- for (int i = m_Manager.GetGroupCount(); i > (int)dw; i--)
- m_nBitmaps[i] = m_nBitmaps[i-1];
- m_nBitmaps[i] = 9;
+ free (opts.filenames);
+ Sys_ProfileSaveString ("Default", "LDraw Pieces Path", opts.path);
- UpdateTree();
+ UpdateList();
}
return TRUE;
}
-
- case ID_LIBDLG_GROUP_DELETE:
+
+ case ID_LIBDLG_FILE_TEXTURES:
{
- HTREEITEM hti = m_Tree.GetSelectedItem();
+ CTexturesDlg dlg;
+ dlg.DoModal();
+ } break;
- if (hti)
+ case ID_LIBDLG_CATEGORY_RESET:
+ {
+ if (SystemDoMessageBox("Are you sure you want to reset the categories?", LC_MB_YESNO | LC_MB_ICONQUESTION) == LC_YES)
{
- DWORD dw = m_Tree.GetItemData(hti);
- if (dw == 0)
- return TRUE;
- dw--;
-
- CWaitCursor wc;
-
- for (int i = dw; i < m_Manager.GetGroupCount(); i++)
- m_nBitmaps[i] = m_nBitmaps[i+1];
-
- m_Manager.HandleCommand (LC_LIBDLG_GROUP_DELETE, dw);
+ project->GetPiecesLibrary()->ResetCategories();
- UpdateTree();
UpdateList();
+ UpdateTree();
}
return TRUE;
}
- case ID_LIBDLG_GROUP_RENAME:
+ case ID_LIBDLG_CATEGORY_NEW:
{
- HTREEITEM hti = m_Tree.GetSelectedItem();
+ LC_CATEGORYDLG_OPTS Opts;
+ Opts.Name = "New Category";
+ Opts.Keywords = "";
- if (hti)
+ if (SystemDoDialog(LC_DLG_EDITCATEGORY, &Opts))
{
- DWORD dw = m_Tree.GetItemData(hti);
- if (dw == 0)
- return TRUE;
- dw--;
-
- m_Manager.HandleCommand (LC_LIBDLG_GROUP_EDIT, dw);
- UpdateTree();
+ PiecesLibrary* Lib = project->GetPiecesLibrary();
+ Lib->AddCategory(Opts.Name, Opts.Keywords);
}
+ UpdateTree();
+
return TRUE;
}
- case ID_LIBDLG_GROUP_MOVEUP:
+ case ID_LIBDLG_CATEGORY_REMOVE:
{
- HTREEITEM hti = m_Tree.GetSelectedItem();
+ HTREEITEM Item = m_Tree.GetSelectedItem();
- if (hti)
- {
- DWORD dw = m_Tree.GetItemData(hti);
- int j;
-
- if (dw == 0)
- return TRUE;
- dw--;
+ if (Item == NULL)
+ break;
- CWaitCursor wc;
+ PiecesLibrary* Lib = project->GetPiecesLibrary();
+ CString CategoryName = m_Tree.GetItemText(Item);
+ int Index = Lib->FindCategoryIndex((const char*)CategoryName);
- m_Manager.HandleCommand (LC_LIBDLG_GROUP_MOVEUP, dw);
+ if (Index == -1)
+ break;
- j = m_nBitmaps[dw];
- m_nBitmaps[dw] = m_nBitmaps[dw-1];
- m_nBitmaps[dw-1] = j;
+ char Msg[1024];
+ String Name = Lib->GetCategoryName(Index);
+ sprintf(Msg, "Are you sure you want to remove the %s category?", Name);
- UpdateTree();
- UpdateList();
+ if (SystemDoMessageBox(Msg, LC_MB_YESNO | LC_MB_ICONQUESTION) == LC_YES)
+ {
+ Lib->RemoveCategory(Index);
}
+
+ UpdateTree();
+
return TRUE;
}
- case ID_LIBDLG_GROUP_MOVEDOWN:
+ case ID_LIBDLG_CATEGORY_EDIT:
{
- HTREEITEM hti = m_Tree.GetSelectedItem();
-
- if (hti)
- {
- DWORD dw = m_Tree.GetItemData(hti);
- int j;
+ HTREEITEM Item = m_Tree.GetSelectedItem();
- if (dw == 0)
- return TRUE;
- dw--;
+ if (Item == NULL)
+ break;
- CWaitCursor wc;
+ PiecesLibrary* Lib = project->GetPiecesLibrary();
+ CString CategoryName = m_Tree.GetItemText(Item);
+ int Index = Lib->FindCategoryIndex((const char*)CategoryName);
- m_Manager.HandleCommand (LC_LIBDLG_GROUP_MOVEDOWN, dw);
+ if (Index == -1)
+ break;
- j = m_nBitmaps[dw];
- m_nBitmaps[dw] = m_nBitmaps[dw+1];
- m_nBitmaps[dw+1] = j;
+ LC_CATEGORYDLG_OPTS Opts;
+ Opts.Name = Lib->GetCategoryName(Index);
+ Opts.Keywords = Lib->GetCategoryKeywords(Index);
- UpdateTree();
- UpdateList();
+ if (SystemDoDialog(LC_DLG_EDITCATEGORY, &Opts))
+ {
+ String OldName = Lib->GetCategoryName(Index);
+ Lib->SetCategory(Index, Opts.Name, Opts.Keywords);
}
+
+ UpdateTree();
+
return TRUE;
}
case ID_LIBDLG_PIECE_NEW:
{
-// CPieceEditorDlg dlg;
-// dlg.DoModal();
-
return TRUE;
}
case ID_LIBDLG_PIECE_EDIT:
{
-
return TRUE;
}
case ID_LIBDLG_PIECE_DELETE:
{
- int i, sel = 0;
+ PtrArray<PieceInfo> Pieces;
- for (i = 0; i < m_List.GetItemCount(); i++)
+ for (int i = 0; i < m_List.GetItemCount(); i++)
+ {
if (m_List.GetItemState(i, LVIS_SELECTED))
- sel++;
+ Pieces.Add((PieceInfo*)m_List.GetItemData(i));
+ }
- // Nothing to be done
- if (sel == 0)
+ if (Pieces.GetSize() == 0)
return TRUE;
- char** names = (char**)malloc(sel*sizeof(char**));
-
- for (sel = 0, i = 0; i < m_List.GetItemCount(); i++)
- {
- PieceInfo* info;
- lcuint32 group;
-
- if (m_List.GetItemState(i, LVIS_SELECTED))
- {
- m_Manager.GetPieceInfo (m_List.GetItemData(i), &info, &group);
-
- names[sel] = info->m_strName;
- sel++;
- }
- }
+ if (SystemDoMessageBox ("Are you sure you want to permanently delete the selected pieces?", LC_MB_YESNO|LC_MB_ICONQUESTION) != LC_YES)
+ return TRUE;
- m_Manager.DeletePieces (names, sel);
- free(names);
+ project->GetPiecesLibrary()->DeletePieces(Pieces);
UpdateList();
@@ -450,109 +320,51 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
void CLibraryDlg::UpdateList()
{
- HTREEITEM hti = m_Tree.GetSelectedItem();
m_List.DeleteAllItems();
-
m_List.SetRedraw(FALSE);
- if (hti)
- {
- DWORD dw = m_Tree.GetItemData (hti);
- for (int i = 0; i < m_Manager.GetPieceCount(); i++)
- {
- PieceInfo* info;
- lcuint32 group;
+ PiecesLibrary *Lib = project->GetPiecesLibrary();
+
+ HTREEITEM CategoryItem = m_Tree.GetSelectedItem();
+ CString CategoryName = m_Tree.GetItemText(CategoryItem);
+ int CategoryIndex = Lib->FindCategoryIndex((const char*)CategoryName);
+
+ if (CategoryIndex != -1)
+ {
+ PtrArray<PieceInfo> SinglePieces, GroupedPieces;
- m_Manager.GetPieceInfo (i, &info, &group);
+ Lib->GetCategoryEntries(CategoryIndex, false, SinglePieces, GroupedPieces);
- if ((dw != 0) && (((1 << (dw-1)) & group) == 0))
- continue;
+ for (int i = 0; i < SinglePieces.GetSize(); i++)
+ {
+ PieceInfo* Info = SinglePieces[i];
LVITEM lvi;
lvi.mask = LVIF_TEXT | LVIF_PARAM;
lvi.iItem = 0;
lvi.iSubItem = 0;
- lvi.lParam = i;
- lvi.pszText = info->m_strDescription;
+ lvi.lParam = (LPARAM)Info;
+ lvi.pszText = Info->m_strDescription;
m_List.InsertItem(&lvi);
}
}
+
m_List.SetRedraw(TRUE);
}
void CLibraryDlg::UpdateTree()
{
+ m_Tree.SetRedraw(FALSE);
m_Tree.DeleteAllItems();
- TV_INSERTSTRUCT tvs;
- tvs.hParent = NULL;
- tvs.hInsertAfter = TVI_LAST;
- tvs.item.iImage = 1;
- tvs.item.iSelectedImage = 1;
- tvs.item.lParam = 0;
- tvs.item.pszText = _T("Groups");
- tvs.item.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT | TVIF_PARAM;
- HTREEITEM hRootItem = m_Tree.InsertItem(&tvs);
-
- for (int i = 0; i < m_Manager.GetGroupCount(); i++)
- {
- TV_INSERTSTRUCT tvstruct;
- tvstruct.hParent = hRootItem;
- tvstruct.hInsertAfter = TVI_LAST;
- tvstruct.item.iImage = 0;
- tvstruct.item.iSelectedImage = 1;
- tvstruct.item.lParam = i+1;
- tvstruct.item.pszText = m_Manager.GetGroupName(i);
- tvstruct.item.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT | TVIF_PARAM;
- m_Tree.InsertItem(&tvstruct);
- }
- m_Tree.Expand (hRootItem, TVE_EXPAND);
- m_Tree.SelectItem(hRootItem);
-}
-/*
-BOOL CLibraryDlg::DoSave(BOOL bAskName)
-{
- if (bAskName || m_strFile.IsEmpty())
- {
- CString Name;
- CFileDialog dlg(FALSE, ".lgf\0", NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
- "LeoCAD Group Files (*.lgf)|*.lgf|All Files (*.*)|*.*||",this);
- dlg.m_ofn.lpstrFile = Name.GetBuffer(_MAX_PATH);
- if (dlg.DoModal() != IDOK)
- return FALSE;
- Name.ReleaseBuffer();
- m_strFile = Name;
- }
-
- CWaitCursor wait;
- CFile f(m_strFile, CFile::modeCreate | CFile::modeReadWrite | CFile::shareExclusive);
- CArchive ar(&f,CArchive::store | CArchive::bNoFlushOnDelete);
+ PiecesLibrary *Lib = project->GetPiecesLibrary();
+ for (int i = 0; i < Lib->GetNumCategories(); i++)
+ m_Tree.InsertItem(TVIF_IMAGE|TVIF_CHILDREN|TVIF_PARAM|TVIF_TEXT, Lib->GetCategoryName(i), 0, 1, 0, 0, 0, TVI_ROOT, TVI_SORT);
- CString str;
- ar.Write (ver_str, sizeof(ver_str));
- ar << ver_flt;
- ar << m_nMaxGroups;
- for (int i = 0; i < m_nMaxGroups; i++)
- {
- ar.Write (m_strGroups[i], sizeof(m_strGroups[i]));
- ar << m_nBitmaps[i];
- }
-
- m_ImageList.Write(&ar);
-
- ar << (int) m_Parts.GetSize();
- for (i = 0; i < m_Parts.GetSize(); i++)
- {
- ar.Write (m_Parts[i].info->m_strName, sizeof(m_Parts[i].info->m_strName));
- ar << m_Parts[i].group;
- }
- ar.Close();
- f.Close();
- m_bModified = FALSE;
-// m_bLoaded = TRUE;
- return TRUE;
+ m_Tree.SetRedraw(TRUE);
+ m_Tree.Invalidate();
}
-*/
+
void CLibraryDlg::OnSelChangedTree(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
@@ -560,105 +372,42 @@ void CLibraryDlg::OnSelChangedTree(NMHDR* pNMHDR, LRESULT* pResult)
*pResult = 0;
}
-void CLibraryDlg::OnBeginDragList(NMHDR* pNMHDR, LRESULT* pResult)
+void CLibraryDlg::OnCancel()
{
- NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
-
- // save the index of the item being dragged in m_nDragIndex
- m_nDragIndex = pNMListView->iItem;
- POINT pt;
- pt.x = 8;
- pt.y = 8;
+ // Check if it's ok to close the dialog
+ if (!project->GetPiecesLibrary()->SaveCategories())
+ return;
- // create a drag image
- if(m_pDragImage)
- delete m_pDragImage;
-
- m_pDragImage = m_List.CreateDragImage (m_nDragIndex, &pt);
- ASSERT (m_pDragImage);
- // changes the cursor to the drag image (DragMove() is still required in
- // OnMouseMove())
- VERIFY (m_pDragImage->BeginDrag (0, CPoint (8, 8)));
- VERIFY (m_pDragImage->DragEnter (GetDesktopWindow (), pNMListView->ptAction));
- // set dragging flag
- m_bDragging = TRUE;
- m_hDropItem = NULL;
-
- // capture all mouse messages
- SetCapture ();
-
- *pResult = 0;
+ CDialog::OnCancel();
}
-void CLibraryDlg::OnMouseMove(UINT nFlags, CPoint point)
+void CLibraryDlg::OnOK()
{
- if (m_bDragging)
- {
- CPoint pt (point);
- ClientToScreen (&pt);
- // move the drag image and unlock window updates
- VERIFY (m_pDragImage->DragMove (pt));
- VERIFY (m_pDragImage->DragShowNolock (FALSE));
-
- m_Tree.ScreenToClient (&pt);
-
- UINT uFlags;
- // get the item that is below cursor and highlight it
- m_hDropItem = m_Tree.HitTest(pt, &uFlags);
- m_Tree.SelectDropTarget(m_hDropItem);
+ // Check if it's ok to close the dialog
+ if (!project->GetPiecesLibrary()->SaveCategories())
+ return;
- // lock window updates
- VERIFY (m_pDragImage->DragShowNolock (TRUE));
- }
-
- CDialog::OnMouseMove(nFlags, point);
+ CDialog::OnOK();
}
-void CLibraryDlg::OnLButtonUp(UINT nFlags, CPoint point)
+BOOL CLibraryDlg::ContinueModal()
{
- if (m_bDragging)
- {
- // release mouse capture
- VERIFY (::ReleaseCapture ());
- m_bDragging = FALSE;
- // end dragging
- VERIFY (m_pDragImage->DragLeave (GetDesktopWindow ()));
- m_pDragImage->EndDrag ();
-
- if (m_hDropItem)
- {
- DWORD dw = m_Tree.GetItemData(m_hDropItem);
- bool bControl = (GetKeyState (VK_CONTROL) < 0);
-
- for (int i = 0; i < m_List.GetItemCount(); i++)
- if (m_List.GetItemState(i,LVIS_SELECTED))
- m_Manager.SetPieceGroup(m_List.GetItemData(i), dw, bControl);
-
- m_Tree.SelectDropTarget (NULL);
- m_hDropItem = NULL;
- UpdateList();
- }
- }
-
- CDialog::OnLButtonUp(nFlags, point);
-}
+ HTREEITEM h = m_Tree.GetSelectedItem();
+ BOOL bValid = (h != m_Tree.GetRootItem()) && (h != NULL);
-void CLibraryDlg::OnCancel()
-{
- // Check if it's ok to close the dialog
- if (!m_Manager.SaveModified ())
- return;
+ EnableControl(ID_LIBDLG_GROUP_RENAME, bValid);
+ EnableControl(ID_LIBDLG_GROUP_DELETE, bValid);
- CDialog::OnCancel();
+ return CDialog::ContinueModal();
}
-void CLibraryDlg::OnOK()
+void CLibraryDlg::EnableControl(UINT nID, BOOL bEnable)
{
- // Check if it's ok to close the dialog
- if (!m_Manager.SaveModified ())
- return;
-
- CDialog::OnOK();
+ GetMenu()->GetSubMenu(1)->EnableMenuItem(nID, MF_BYCOMMAND | (bEnable ? MF_ENABLED : (MF_DISABLED | MF_GRAYED)));
+ int state = m_wndToolBar.GetToolBarCtrl().GetState(nID) & ~TBSTATE_ENABLED;
+ if (bEnable)
+ state |= TBSTATE_ENABLED;
+ m_wndToolBar.GetToolBarCtrl().SetState(nID, state);
}
BOOL CLibraryDlg::OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult)
@@ -701,63 +450,3 @@ BOOL CLibraryDlg::OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult)
return TRUE; // message was handled
}
-
-BOOL CLibraryDlg::ContinueModal()
-{
- HTREEITEM h = m_Tree.GetSelectedItem();
- DWORD dw = m_Tree.GetItemData (h);
- BOOL bValid = (h != m_Tree.GetRootItem()) && (h != NULL);
-
- EnableControl(ID_LIBDLG_GROUP_INSERT, m_Manager.GetGroupCount() < 32);
- EnableControl(ID_LIBDLG_GROUP_RENAME, bValid);
- EnableControl(ID_LIBDLG_GROUP_DELETE, bValid && m_Manager.GetGroupCount() != 1);
- EnableControl(ID_LIBDLG_GROUP_MOVEUP, dw > 1);
- EnableControl(ID_LIBDLG_GROUP_MOVEDOWN, (dw != 0) && ((int)dw != m_Manager.GetGroupCount()));
-
- return CDialog::ContinueModal();
-}
-
-void CLibraryDlg::EnableControl(UINT nID, BOOL bEnable)
-{
- GetMenu()->GetSubMenu(1)->EnableMenuItem(nID, MF_BYCOMMAND | (bEnable ? MF_ENABLED : (MF_DISABLED | MF_GRAYED)));
- int state = m_wndToolBar.GetToolBarCtrl().GetState(nID) & ~TBSTATE_ENABLED;
- if (bEnable)
- state |= TBSTATE_ENABLED;
- m_wndToolBar.GetToolBarCtrl().SetState(nID, state);
-}
-
-/*
-CImageList* CTreeCtrlEx::CreateDragImageEx(HTREEITEM hItem)
-{
- CRect rect;
- GetItemRect(hItem, rect, LVIR_LABEL);
- rect.top = rect.left = 0;
-
- // Create bitmap
- CClientDC dc(this);
- CDC memDC;
-
- if(!memDC.CreateCompatibleDC(&dc))
- return NULL;
-
- CBitmap bitmap;
- if(!bitmap.CreateCompatibleBitmap(&dc, rect.Width(), rect.Height()))
- return NULL;
-
- CBitmap* pOldMemDCBitmap = memDC.SelectObject(&bitmap);
- CFont* pOldFont = memDC.SelectObject(GetFont());
- memDC.FillSolidRect(&rect, RGB(0, 255, 0)); // Here green is used as mask color
- memDC.SetTextColor(GetSysColor(COLOR_GRAYTEXT));
- memDC.TextOut(rect.left, rect.top, GetItemText(hItem));
- memDC.SelectObject(pOldFont);
- memDC.SelectObject(pOldMemDCBitmap);
-
- // Create imagelist
- CImageList* pImageList = new CImageList;
- pImageList->Create(rect.Width(), rect.Height(),
- ILC_COLOR | ILC_MASK, 0, 1);
- pImageList->Add(&bitmap, RGB(0, 255, 0)); // Here green is used as mask color
-
- return pImageList;
-}
-*/
diff --git a/win/Libdlg.h b/win/Libdlg.h
index 798e6b6..2aefa5d 100644
--- a/win/Libdlg.h
+++ b/win/Libdlg.h
@@ -1,27 +1,8 @@
-#if !defined(AFX_LIBDLG_H__BABBE241_AF9C_11D2_8203_DC3ED7F79C17__INCLUDED_)
-#define AFX_LIBDLG_H__BABBE241_AF9C_11D2_8203_DC3ED7F79C17__INCLUDED_
-
-#if _MSC_VER >= 1000
-#pragma once
-#endif // _MSC_VER >= 1000
-// LibDlg.h : header file
-//
-
-#include "libman.h"
+#ifndef _LIBDLG_H_
+#define _LIBDLG_H_
class PieceInfo;
-typedef struct {
- PieceInfo* info;
- unsigned long group;
- unsigned long defgroup;
-} PARTGROUPINFO;
-
-#include <afxtempl.h> // CArray;
-
-/////////////////////////////////////////////////////////////////////////////
-// CLibraryDlg dialog
-
class CLibraryDlg : public CDialog
{
// Construction
@@ -52,29 +33,14 @@ public:
void UpdateTree();
void UpdateList();
-// BYTE m_nMaxGroups;
- int m_nBitmaps[32];
- CImageList m_ImageList;
-
CToolBar m_wndToolBar;
CImageList m_TreeImages;
- CImageList* m_pDragImage;
- BOOL m_bDragging;
- int m_nDragIndex;
- HTREEITEM m_hDropItem;
-
-protected:
- LibraryManager m_Manager;
-
protected:
// Generated message map functions
//{{AFX_MSG(CLibraryDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSelChangedTree(NMHDR* pNMHDR, LRESULT* pResult);
- afx_msg void OnBeginDragList(NMHDR* pNMHDR, LRESULT* pResult);
- afx_msg void OnMouseMove(UINT nFlags, CPoint point);
- afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
virtual void OnCancel();
virtual void OnOK();
//}}AFX_MSG
@@ -87,4 +53,4 @@ protected:
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
-#endif // !defined(AFX_LIBDLG_H__BABBE241_AF9C_11D2_8203_DC3ED7F79C17__INCLUDED_)
+#endif // _LIBDLG_H_
diff --git a/win/Piecebar.cpp b/win/Piecebar.cpp
index 0a793e4..7395301 100644
--- a/win/Piecebar.cpp
+++ b/win/Piecebar.cpp
@@ -1106,7 +1106,7 @@ BOOL CPiecesBar::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
PtrArray<PieceInfo> SinglePieces, GroupedPieces;
int i;
- Lib->GetCategoryEntries(CategoryIndex, SinglePieces, GroupedPieces);
+ Lib->GetCategoryEntries(CategoryIndex, true, SinglePieces, GroupedPieces);
for (i = 0; i < SinglePieces.GetSize(); i++)
{
diff --git a/win/System.cpp b/win/System.cpp
index 5fde157..e80c811 100644
--- a/win/System.cpp
+++ b/win/System.cpp
@@ -1208,10 +1208,10 @@ bool SystemDoDialog(int nMode, void* param)
{
const char *ext, *filter;
- if (opts->type == LC_FILEOPENDLG_LGF)
+ if (opts->type == LC_FILEOPENDLG_LCF)
{
- ext = ".lgf\0";
- filter = "LeoCAD Group Files (*.lgf)|*.lgf|All Files (*.*)|*.*||";
+ ext = ".lcf\0";
+ filter = "LeoCAD Category Files (*.lcf)|*.lcf|All Files (*.*)|*.*||";
}
else
{
@@ -1224,12 +1224,11 @@ bool SystemDoDialog(int nMode, void* param)
if (dlg.DoModal() == IDOK)
{
opts->numfiles = 1;
- opts->filenames = (char**)malloc(sizeof(char*));
- opts->filenames[0] = (char*)malloc(LC_MAXPATH);
- strcpy (opts->filenames[0], dlg.GetPathName ());
+ opts->filenames = (char**)malloc(LC_MAXPATH);
+ strcpy((char*)opts->filenames, dlg.GetPathName ());
// Get the file path.
- strcpy (opts->path, opts->filenames[0]);
+ strcpy(opts->path, (char*)opts->filenames);
if (strlen (opts->path) > 0)
{
char* ptr = strrchr(opts->path, '/');
@@ -1250,6 +1249,25 @@ bool SystemDoDialog(int nMode, void* param)
} break;
+ case LC_DLG_FILE_SAVE:
+ {
+ LC_FILESAVEDLG_OPTS* opts = (LC_FILESAVEDLG_OPTS*)param;
+
+ if (opts->type == LC_FILESAVEDLG_LCF)
+ {
+ CFileDialog dlg(FALSE, ".lcf", NULL, OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
+ "LeoCAD Category Files (*.lcf)|*.lcf|All Files (*.*)|*.*||", NULL);
+
+ if (dlg.DoModal() == IDOK)
+ {
+ strcpy(opts->path, dlg.GetPathName ());
+ return true;
+ }
+ }
+
+ return false;
+ } break;
+
case LC_DLG_PICTURE_SAVE:
{
CFileDialog dlg(FALSE, NULL, NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ENABLEHOOK|OFN_ENABLETEMPLATE|OFN_EXPLORER,
@@ -1454,21 +1472,10 @@ bool SystemDoDialog(int nMode, void* param)
case LC_DLG_LIBRARY:
{
CLibraryDlg dlg;
- CFrameWnd* pFrame = (CFrameWnd*)AfxGetMainWnd();
- CPiecesBar* pBar = (CPiecesBar*)pFrame->GetControlBar(ID_VIEW_PIECES_BAR);
-
- for (int i = 0; i < pBar->m_wndGroupsBar.m_ToolbarData.iButtons; i++)
- dlg.m_nBitmaps[i] = pBar->m_wndGroupsBar.m_ToolbarData.ButtonData[i].iBitmap;
- dlg.m_ImageList.Create(IDB_PIECEBAR, 16, 0, 0x00ff00ff);
+ dlg.DoModal();
- if (dlg.DoModal() == IDOK)
- {
- pBar->CreateGroupsBar();
- pBar->m_wndPiecesList.UpdateList();
- RECT rc;
- pBar->GetClientRect(&rc);
- pBar->PostMessage(WM_SIZE, SIZE_RESTORED, MAKELPARAM(rc.right, rc.bottom));
- }
+ CPiecesBar* pBar = (CPiecesBar*)((CFrameWnd*)AfxGetMainWnd())->GetControlBar(ID_VIEW_PIECES_BAR);
+ pBar->UpdatePiecesTree(false);
return true;
} break;
diff --git a/win/res/library.bmp b/win/res/library.bmp
index 45b9e31..49192c4 100644
--- a/win/res/library.bmp
+++ b/win/res/library.bmp
Binary files differ
diff --git a/win/resource.h b/win/resource.h
index 48f5f9f..bad6599 100644
--- a/win/resource.h
+++ b/win/resource.h
@@ -674,6 +674,10 @@
#define ID_PIECEBAR_EDITCATEGORY 33160
#define ID_PIECEBAR_REMOVECATEGORY 33161
#define ID_PIECE_TRANSFORM 33162
+#define ID_LIBDLG_CATEGORY_NEW 33163
+#define ID_LIBDLG_CATEGORY_REMOVE 33164
+#define ID_LIBDLG_CATEGORY_EDIT 33165
+#define ID_LIBDLG_CATEGORY_RESET 33166
#define ID_VIEW_PIECES_BAR 59425
#define ID_VIEW_TOOLS_BAR 59426
#define ID_VIEW_ANIMATION_BAR 59427
@@ -685,7 +689,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_3D_CONTROLS 1
#define _APS_NEXT_RESOURCE_VALUE 240
-#define _APS_NEXT_COMMAND_VALUE 33163
+#define _APS_NEXT_COMMAND_VALUE 33167
#define _APS_NEXT_CONTROL_VALUE 1247
#define _APS_NEXT_SYMED_VALUE 121
#endif