summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorleo2002-10-15 23:16:30 +0000
committerleo2002-10-15 23:16:30 +0000
commitaac0e540c168a9926cf34ebf02d6df34d0edfa8f (patch)
tree4b8c4622cd972b422031be64ba7864b07f3a7775
parente759cbbb96e6212ac0a8f7456a5d04682b815d0b (diff)
Making the PLM cross platform.
git-svn-id: http://svn.leocad.org/trunk@314 c7d43263-9d01-0410-8a33-9dba5d9f93d6
-rw-r--r--common/libman.cpp363
-rw-r--r--common/libman.h81
-rwxr-xr-xcommon/library.cpp427
-rwxr-xr-xcommon/library.h125
-rw-r--r--win/Libdlg.cpp332
-rw-r--r--win/Libdlg.h14
6 files changed, 696 insertions, 646 deletions
diff --git a/common/libman.cpp b/common/libman.cpp
new file mode 100644
index 0000000..82d2fd3
--- /dev/null
+++ b/common/libman.cpp
@@ -0,0 +1,363 @@
+//
+// 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:
+ {
+ char filename[LC_MAXPATH];
+
+ // FIXME: file extension
+ if (!SystemDoDialog (LC_DLG_FILE_OPEN, filename))
+ return;
+
+ project->GetPiecesLibrary ()->LoadUpdate (filename);
+
+ // FIXME: update m_pPieces
+ } break;
+
+ case LC_LIBDLG_FILE_IMPORTPIECE:
+ {
+/*
+ char filename[LC_MAXPATH];
+ LC_LDRAW_PIECE piece;
+
+ // CFileDialog dlg(TRUE, ".dat\0", NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
+ // "LDraw Files (*.dat)|*.dat|All Files (*.*)|*.*||",this);
+ if (!SystemDoDialog (LC_DLG_FILE_OPEN, filename))
+ return;
+
+ BeginWait ();
+
+ if (ReadLDrawPiece(filename, &piece))
+ {
+ if (project->GetPiecesLibrary ()->FindPieceInfo(piece.name) != NULL)
+ Sys_MessageBox ("Piece already exists in the library !");
+
+ if (SaveLDrawPiece(&piece))
+ Sys_MessageBox ("Piece successfully imported.");
+ else
+ Sys_MessageBox ("Error saving library.");
+ }
+ else
+ Sys_MessageBox ("Error reading file.");
+
+ EndWait ();
+ FreeLDrawPiece(&piece);
+ // FIXME: update m_pPieces
+*/
+ } break;
+
+ case LC_LIBDLG_FILE_RETURN:
+ break;
+
+ case LC_LIBDLG_FILE_CANCEL:
+ break;
+
+ case LC_LIBDLG_GROUP_INSERT:
+ 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:
+ 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
new file mode 100644
index 0000000..ac48c1b
--- /dev/null
+++ b/common/libman.h
@@ -0,0 +1,81 @@
+#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 64ab43d..6f9db2c 100755
--- a/common/library.cpp
+++ b/common/library.cpp
@@ -1,12 +1,12 @@
//
-// Piece library management
+// Pieces library management
//
#include <stdlib.h>
#include "library.h"
#include "file.h"
-#include "pieceinf.h"
#include "texture.h"
+#include "pieceinf.h"
#include "config.h"
#include "image.h"
#include "system.h"
@@ -31,6 +31,7 @@ PiecesLibrary::PiecesLibrary ()
m_nPieceCount = 0;
m_pTextures = NULL;
m_nTextureCount = 0;
+ m_bNeedsReload = false;
}
PiecesLibrary::~PiecesLibrary ()
@@ -38,6 +39,18 @@ PiecesLibrary::~PiecesLibrary ()
Unload ();
}
+void PiecesLibrary::CheckReload ()
+{
+ char LibraryPath[LC_MAXPATH];
+
+ strcpy (LibraryPath, m_LibraryPath);
+
+ // FIXME: project will crash if we don't update the pieceinfos
+
+ Unload ();
+ Load (LibraryPath);
+}
+
void PiecesLibrary::Unload ()
{
strcpy (m_LibraryPath, "");
@@ -123,7 +136,20 @@ bool PiecesLibrary::Load (const char *libpath)
idx.Close();
bin.Close();
- // TODO: Load group configuration here
+ // 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;
+ }
// Read the texture index.
strcpy(filename, m_LibraryPath);
@@ -169,6 +195,20 @@ bool PiecesLibrary::Load (const char *libpath)
idx.Close();
bin.Close();
+ m_bNeedsReload = false;
+
+ return true;
+}
+
+bool PiecesLibrary::LoadGroupConfig (const char* Filename)
+{
+ // FIXME:
+ return false;
+
+
+ strcpy (m_GroupsFile, Filename);
+
+
return true;
}
@@ -322,10 +362,88 @@ Texture* PiecesLibrary::GetTexture (int index) const
}
// =============================================================================
+
+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;
+}
+
+// =============================================================================
// Pieces handling stuff
// Remove pieces from the library
-bool PiecesLibrary::DeletePiece (char** names, int numpieces)
+bool PiecesLibrary::DeletePieces (char** names, int numpieces)
{
FileDisk newbin, newidx, oldbin, oldidx;
char file1[LC_MAXPATH], file2[LC_MAXPATH], tmp[200];
@@ -431,6 +549,8 @@ bool PiecesLibrary::DeletePiece (char** names, int numpieces)
newidx.Close();
newbin.Close();
+ m_bNeedsReload = true;
+
return true;
}
@@ -676,6 +796,8 @@ bool PiecesLibrary::LoadUpdate (const char* update)
newbin.Close();
up.Close();
+ m_bNeedsReload = true;
+
return true;
}
@@ -792,6 +914,8 @@ bool PiecesLibrary::DeleteTextures (char** Names, int NumTextures)
count -= deleted;
newidx.WriteShort (&count, 1);
+ m_bNeedsReload = true;
+
return true;
}
@@ -973,331 +1097,62 @@ bool PiecesLibrary::ImportTexture (const char* Name)
count -= deleted;
newidx.WriteShort (&count, 1);
+ m_bNeedsReload = true;
+
return true;
}
-
-
-
-
-
-#include <string.h>
-#include <stdlib.h>
-#include <math.h>
-#include "globals.h"
-#include "project.h"
-#include "matrix.h"
-
-
// =============================================================================
-// LibraryDialog class
-static const char ver_str[32] = "LeoCAD Group Configuration File";
-static const float ver_flt = 0.3f;
-LibraryDialog::LibraryDialog ()
- : BaseWnd (NULL, 0) // FIXME: set parent
-{
- m_nPieces = 0;
- m_pPieces = NULL;
- m_nGroups = 0;
- m_nCurrentGroup = 0;
- m_bReload = false;
- m_bModified = false;
- strcpy (m_strFile, "");
-}
-LibraryDialog::~LibraryDialog ()
-{
- free (m_pPieces);
-}
-bool LibraryDialog::Initialize ()
-{
- FileDisk idx;
- char filename[LC_MAXPATH];
- PiecesLibrary *pLib = project->GetPiecesLibrary ();
- // Read the piece library index.
- strcpy(filename, pLib->GetLibraryPath());
- strcat(filename, "pieces.idx");
- if (!idx.Open(filename, "rb"))
- return false;
- idx.Seek(34, SEEK_SET); // skip update byte
- m_nPieces = pLib->GetPieceCount();
- m_pPieces = (LC_LIBDLG_PIECEINFO*) malloc (sizeof (LC_LIBDLG_PIECEINFO) * m_nPieces);
- for (int i = 0; i < m_nPieces; i++)
- {
- LC_LIBDLG_PIECEINFO* inf = &m_pPieces[i];
- inf->info = pLib->GetPieceInfo(i);
- inf->current_groups = inf->info->m_nGroups;
- idx.Seek (85, SEEK_CUR);
- idx.ReadLong (&inf->default_groups, 1);
- idx.Seek (8, SEEK_CUR);
- }
- idx.Close();
- // FIX ME: get the current settings
- 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;
-
- // UpdateList();
- UpdateTree();
-
- return true;
-}
-void LibraryDialog::HandleCommand (int id)
-{
- switch (id)
- {
- case LC_LIBDLG_FILE_RESET:
- {
- int i;
-
- for (i = 0; i < m_nPieces; i++)
- m_pPieces[i].current_groups = m_pPieces[i].default_groups;
-
- strcpy (m_strFile, "");
- m_nGroups = 9;
- /*
- m_ImageList.DeleteImageList();
- m_ImageList.Create(IDB_PIECEBAR, 16, 0, 0x00ff00ff);
-
- CString str;
- for (i = 0; i < 32; i++)
- {
- str.LoadString (ID_PIECE_GROUP01 + i);
- strcpy (m_strGroups[i], str);
- m_nBitmaps[i] = min(i,9);
- }
- */
- m_bModified = false;
- UpdateList();
- UpdateTree();
- } break;
-
- case LC_LIBDLG_FILE_OPEN:
- {
- } break;
- case LC_LIBDLG_FILE_SAVE:
- {
- } break;
- case LC_LIBDLG_FILE_SAVEAS:
- {
- } break;
- case LC_LIBDLG_FILE_PRINTCATALOG:
- {
- } break;
- case LC_LIBDLG_FILE_MERGEUPDATE:
- {
- char filename[LC_MAXPATH];
- // CFileDialog filedlg(TRUE, ".lup\0", NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
- // "LeoCAD Library Updates (*.lup)|*.lup|All Files (*.*)|*.*||", this);
- if (!SystemDoDialog (LC_DLG_FILE_OPEN, filename))
- return;
- project->GetPiecesLibrary ()->LoadUpdate (filename);
-// update m_Parts
- UpdateList();
- m_bReload = true;
- } break;
- case LC_LIBDLG_FILE_IMPORTPIECE:
- {
- char filename[LC_MAXPATH];
- LC_LDRAW_PIECE piece;
- // CFileDialog dlg(TRUE, ".dat\0", NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
- // "LDraw Files (*.dat)|*.dat|All Files (*.*)|*.*||",this);
- if (!SystemDoDialog (LC_DLG_FILE_OPEN, filename))
- return;
- BeginWait ();
- if (ReadLDrawPiece(filename, &piece))
- {
- if (project->GetPiecesLibrary ()->FindPieceInfo(piece.name) != NULL)
- Sys_MessageBox ("Piece already exists in the library !");
- if (SaveLDrawPiece(&piece))
- Sys_MessageBox ("Piece successfully imported.");
- else
- Sys_MessageBox ("Error saving library.");
- }
- else
- Sys_MessageBox ("Error reading file.");
-
- EndWait ();
- FreeLDrawPiece(&piece);
- } break;
-
- case LC_LIBDLG_FILE_RETURN:
- break;
- case LC_LIBDLG_FILE_CANCEL:
- break;
- case LC_LIBDLG_GROUP_INSERT:
- break;
- case LC_LIBDLG_GROUP_DELETE:
- break;
- case LC_LIBDLG_GROUP_EDIT:
- break;
- case LC_LIBDLG_GROUP_MOVEUP:
- break;
- case LC_LIBDLG_GROUP_MOVEDOWN:
- break;
- case LC_LIBDLG_PIECE_NEW:
- break;
- case LC_LIBDLG_PIECE_EDIT:
- break;
- case LC_LIBDLG_PIECE_DELETE:
- break;
- }
-}
-bool LibraryDialog::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);
- 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;
-}
// =============================================================================
+// Stuff that needs to be reorganized
-static unsigned long GetDefaultPieceGroup(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;
+#include <string.h>
+#include <math.h>
+#include "globals.h"
+#include "project.h"
+#include "matrix.h"
- 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;
+// =============================================================================
+// LibraryDialog class
- if (strstr(tmp,"Train"))
- return 0x040;
+static const char ver_str[32] = "LeoCAD Group Configuration File";
+static const float ver_flt = 0.3f;
- // 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;
-}
// ========================================================
// Import LDraw piece
@@ -2466,7 +2321,7 @@ bool SaveLDrawPiece(LC_LDRAW_PIECE* piece)
if (scale == 1000) bt |= 0x20; // LC_PIECE_MEDIUM
newidx.WriteByte(&bt, 1);
- i = GetDefaultPieceGroup(piece->description);
+ i = PiecesLibrary::GetDefaultPieceGroup(piece->description);
newidx.WriteLong(&i, 1);
newidx.WriteLong(&binoff, 1);
diff --git a/common/library.h b/common/library.h
index 68f610d..c9b60c6 100755
--- a/common/library.h
+++ b/common/library.h
@@ -2,11 +2,14 @@
#define _LIBRARY_H_
#include "defines.h"
+#include "str.h"
class File;
class Texture;
class PieceInfo;
+#define LC_PIECESLIB_MAXGROUPS 32
+
class PiecesLibrary
{
public:
@@ -19,9 +22,17 @@ public:
{ 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; }
+
+ void CheckReload ();
bool Load (const char* libpath);
void Unload ();
+ bool LoadGroupConfig (const char* Filename);
// Search for stuff
PieceInfo* FindPieceInfo (const char* name) const;
@@ -31,11 +42,13 @@ public:
Texture* GetTexture (int index) const;
// File operations
- bool DeletePiece (char** names, int numpieces);
+ bool DeletePieces (char** names, int numpieces);
bool LoadUpdate (const char* update);
bool DeleteTextures (char** Names, int NumTextures);
bool ImportTexture (const char* Name);
+ static unsigned long GetDefaultPieceGroup (const char* name);
+
protected:
char m_LibraryPath[LC_MAXPATH]; // path to the library files
@@ -46,6 +59,13 @@ protected:
int m_nTextureCount; // number of textures
Texture* m_pTextures; // textures array
+ // 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 ValidatePiecesFile (File& IdxFile, File& BinFile) const;
bool ValidateTexturesFile (File& IdxFile, File& BinFile) const;
@@ -58,6 +78,11 @@ protected:
static const int TexturesFileVersion;
};
+
+
+
+// ============================================================================
+
// This should be cleaned and moved to the PiecesLibrary class
typedef struct connection_s
{
@@ -106,100 +131,4 @@ 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 {
- LC_LIBDLG_FILE_RESET,
- LC_LIBDLG_FILE_OPEN,
- LC_LIBDLG_FILE_SAVE,
- LC_LIBDLG_FILE_SAVEAS,
- LC_LIBDLG_FILE_PRINTCATALOG,
- 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_PIECE_NEW,
- LC_LIBDLG_PIECE_EDIT,
- LC_LIBDLG_PIECE_DELETE
-} LC_LIBDLG_COMMANDS;
-
-class PieceInfo;
-class LibraryDialog;
-
-typedef struct
-{
- PieceInfo* info;
- unsigned long current_groups;
- unsigned long default_groups;
-} LC_LIBDLG_PIECEINFO;
-
-#define LC_LIBDLG_MAXGROUPS 32
-#define LC_LIBDLG_MAXNAME 32
-
-typedef void (*PFNLIBDLGUPDATELISTFUNC) (LC_LIBDLG_PIECEINFO *piece_info, int count, int group, void *data);
-typedef void (*PFNLIBDLGUPDATETREEFUNC) (int num_groups, char str_groups[][LC_LIBDLG_MAXNAME+1], void *data);
-
-class LibraryDialog : public BaseWnd
-{
- public:
- LibraryDialog ();
- virtual ~LibraryDialog ();
-
- void HandleCommand (int id);
- bool DoSave (bool bAskName);
- bool Initialize ();
-
- void SetListFunc (PFNLIBDLGUPDATELISTFUNC func, void *data)
- {
- m_pUpdateListFunc = func;
- m_pUpdateListData = data;
- }
-
- void SetTreeFunc (PFNLIBDLGUPDATETREEFUNC func, void *data)
- {
- m_pUpdateTreeFunc = func;
- m_pUpdateTreeData = data;
- }
-
- void UpdateList ()
- {
- m_pUpdateListFunc (m_pPieces, m_nPieces, m_nCurrentGroup, m_pUpdateListData);
- }
-
- void UpdateTree ()
- {
- m_pUpdateTreeFunc (m_nGroups, m_strGroups, m_pUpdateTreeData);
- }
-
- void SetCurrentGroup (unsigned long group)
- {
- m_nCurrentGroup = group;
- UpdateList ();
- }
-
- protected:
- void *m_pUpdateListData;
- void *m_pUpdateTreeData;
- PFNLIBDLGUPDATELISTFUNC m_pUpdateListFunc;
- PFNLIBDLGUPDATETREEFUNC m_pUpdateTreeFunc;
-
- int m_nPieces;
- LC_LIBDLG_PIECEINFO* m_pPieces;
-
- unsigned char m_nGroups;
- char m_strGroups[LC_LIBDLG_MAXGROUPS][LC_LIBDLG_MAXNAME+1];
- int m_nCurrentGroup;
-
- bool m_bModified;
- bool m_bReload;
- char m_strFile[LC_MAXPATH];
-};
-
#endif // _LIBRARY_H_
diff --git a/win/Libdlg.cpp b/win/Libdlg.cpp
index 68fa91c..72c1c78 100644
--- a/win/Libdlg.cpp
+++ b/win/Libdlg.cpp
@@ -13,7 +13,6 @@
#include "pieceinf.h"
#include "globals.h"
#include "system.h"
-#include "library.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@@ -31,17 +30,18 @@ static const float ver_flt = 0.3f;
CLibraryDlg::CLibraryDlg(CWnd* pParent /*=NULL*/)
: CDialog(CLibraryDlg::IDD, pParent)
{
- m_bReload = FALSE;
- m_bModified = FALSE;
m_pDragImage = NULL;
m_bDragging = FALSE;
- m_strFile = theApp.GetProfileString("Settings", "Groups", "");
//{{AFX_DATA_INIT(CLibraryDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
+CLibraryDlg::~CLibraryDlg()
+{
+ delete m_pDragImage;
+}
void CLibraryDlg::DoDataExchange(CDataExchange* pDX)
{
@@ -117,30 +117,6 @@ BOOL CLibraryDlg::OnInitDialog()
m_TreeImages.Create(IDB_PARTICONS, 16, 0, RGB (0,128,128));
m_Tree.SetImageList(&m_TreeImages, TVSIL_NORMAL);
- FileDisk idx;
- char filename[LC_MAXPATH];
- PiecesLibrary *pLib = project->GetPiecesLibrary ();
-
- // Read the piece library index.
- strcpy(filename, pLib->GetLibraryPath());
- strcat(filename, "pieces.idx");
- if (!idx.Open(filename, "rb"))
- return FALSE;
- idx.Seek(34, SEEK_SET); // skip update byte
-
- m_Parts.SetSize(pLib->GetPieceCount ());
- for (int i = 0; i < pLib->GetPieceCount (); i++)
- {
- PARTGROUPINFO* inf = &m_Parts[i];
- inf->info = pLib->GetPieceInfo(i);
- inf->group = inf->info->m_nGroups;
-
- idx.Seek(85, SEEK_CUR);
- idx.Read(&inf->defgroup , 4);
- idx.Seek(8, SEEK_CUR);
- }
- idx.Close();
-
UpdateList();
UpdateTree();
@@ -153,26 +129,14 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
{
case ID_LIBDLG_FILE_RESET:
{
- for (int i = 0; i < m_Parts.GetSize(); i++)
- {
- PARTGROUPINFO* inf = &m_Parts[i];
- inf->group = inf->defgroup;
- }
- m_strFile.Empty();
- m_nMaxGroups = 9;
-
+ m_Manager.HandleCommand (LC_LIBDLG_FILE_RESET, 0);
+
m_ImageList.DeleteImageList();
m_ImageList.Create(IDB_PIECEBAR, 16, 0, 0x00ff00ff);
-
- CString str;
- for (i = 0; i < 32; i++)
- {
- str.LoadString (ID_PIECE_GROUP01 + i);
- strcpy (m_strGroups[i], str);
+
+ for (int i = 0; i < 32; i++)
m_nBitmaps[i] = min(i,9);
- }
-
- m_bModified = FALSE;
+
UpdateList();
UpdateTree();
@@ -181,6 +145,7 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
case ID_LIBDLG_FILE_OPEN:
{
+/*
CFileDialog dlg(TRUE, ".lgf\0", NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"LeoCAD Group Files (*.lgf)|*.lgf|All Files (*.*)|*.*||",this);
@@ -255,19 +220,19 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
UpdateList();
UpdateTree();
}
-
+*/
return TRUE;
}
case ID_LIBDLG_FILE_SAVE:
{
- DoSave(FALSE);
+ m_Manager.DoSave(false);
return TRUE;
}
case ID_LIBDLG_FILE_SAVEAS:
{
- DoSave(TRUE);
+ m_Manager.DoSave(true);
return TRUE;
}
@@ -289,16 +254,8 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
case ID_LIBDLG_FILE_MERGEUPDATE:
{
- CFileDialog filedlg(TRUE, ".lup\0", NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
- "LeoCAD Library Updates (*.lup)|*.lup|All Files (*.*)|*.*||", this);
- if (filedlg.DoModal() != IDOK)
- return TRUE;
-
- project->GetPiecesLibrary ()->LoadUpdate(filedlg.GetPathName());
-
-// update m_Parts
+ m_Manager.HandleCommand (LC_LIBDLG_FILE_MERGEUPDATE, 0);
UpdateList();
- m_bReload = TRUE;
return TRUE;
}
@@ -340,6 +297,7 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
SystemDoWaitCursor(-1);
FreeLDrawPiece(&piece);
}
+// update m_Parts
return TRUE;
}
@@ -351,20 +309,16 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
case ID_LIBDLG_GROUP_INSERT:
{
+/*
HTREEITEM hti = m_Tree.GetSelectedItem();
if (hti)
{
DWORD dw = m_Tree.GetItemData(hti);
- if (dw == 0) dw = 1;
-
- for (int i = 0; i < 32; i++)
- if ((DWORD)(1 << i) == dw)
- {
- dw = i;
- break;
- }
-
+ if (dw == 0)
+ dw = 1;
+ dw--;
+
CGroupDlg dlg(this);
if (dlg.DoModal() == IDOK)
{
@@ -400,7 +354,7 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
UpdateList();
}
}
-
+*/
return TRUE;
}
@@ -413,40 +367,15 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
DWORD dw = m_Tree.GetItemData(hti);
if (dw == 0)
return TRUE;
+ dw--;
CWaitCursor wc;
- m_bModified = TRUE;
-
- for (int i = 0; i < 32; i++)
- if ((DWORD)(1 << i) == dw)
- {
- dw = i;
- break;
- }
- for (i = dw; i < m_nMaxGroups; i++)
- {
- strcpy (m_strGroups[i], m_strGroups[i+1]);
+ for (int i = dw; i < m_Manager.GetGroupCount(); i++)
m_nBitmaps[i] = m_nBitmaps[i+1];
- }
- for (int j = 0; j < m_Parts.GetSize(); j++)
- {
- DWORD grp = m_Parts[j].group;
+ m_Manager.HandleCommand (LC_LIBDLG_GROUP_DELETE, dw);
- for (i = dw+1; i < m_nMaxGroups; i++)
- {
- DWORD d = (1 << i);
- if (grp & d)
- {
- grp &= ~d;
- grp |= (1 << (i-1));
- }
- }
- m_Parts[j].group = grp;
- }
-
- m_nMaxGroups--;
UpdateTree();
UpdateList();
}
@@ -456,6 +385,7 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
case ID_LIBDLG_GROUP_RENAME:
{
+/*
HTREEITEM hti = m_Tree.GetSelectedItem();
if (hti)
@@ -463,14 +393,8 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
DWORD dw = m_Tree.GetItemData(hti);
if (dw == 0)
return TRUE;
-
- for (int i = 0; i < 32; i++)
- if ((DWORD)(1 << i) == dw)
- {
- dw = i;
- break;
- }
-
+ dw--;
+
CGroupDlg dlg(this);
if (dlg.DoModal() == IDOK)
{
@@ -479,7 +403,7 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
m_bModified = TRUE;
}
}
-
+*/
return TRUE;
}
@@ -490,45 +414,19 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
if (hti)
{
DWORD dw = m_Tree.GetItemData(hti);
- if (dw == 0)
- dw = 1;
+ int j;
- for (int i = 0; i < 32; i++)
- if ((DWORD)(1 << i) == dw)
- {
- dw = i;
- break;
- }
+ if (dw == 0)
+ return TRUE;
+ dw--;
CWaitCursor wc;
- m_bModified = TRUE;
-
- char tmp[33];
- int j;
- strcpy (tmp, m_strGroups[i]);
- strcpy (m_strGroups[i], m_strGroups[i-1]);
- strcpy (m_strGroups[i-1], tmp);
- j = m_nBitmaps[i];
- m_nBitmaps[i] = m_nBitmaps[i-1];
- m_nBitmaps[i-1] = j;
-
- for (j = 0; j < m_Parts.GetSize(); j++)
- {
- DWORD grp = m_Parts[j].group;
- BOOL g1 = (grp & (1 << i)) != 0;
- BOOL g2 = (grp & (1 << (i-1))) != 0;
- if (g1)
- grp |= (1 << (i-1));
- else
- grp &= ~(1 << (i-1));
- if (g2)
- grp |= (1 << i);
- else
- grp &= ~(1 << i);
+ m_Manager.HandleCommand (LC_LIBDLG_GROUP_MOVEUP, dw);
- m_Parts[j].group = grp;
- }
+ j = m_nBitmaps[dw];
+ m_nBitmaps[dw] = m_nBitmaps[dw-1];
+ m_nBitmaps[dw-1] = j;
UpdateTree();
UpdateList();
@@ -543,45 +441,19 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
if (hti)
{
DWORD dw = m_Tree.GetItemData(hti);
- if (dw == 0)
- dw = 1;
+ int j;
- for (int i = 0; i < 32; i++)
- if ((DWORD)(1 << i) == dw)
- {
- dw = i;
- break;
- }
+ if (dw == 0)
+ return TRUE;
+ dw--;
CWaitCursor wc;
- m_bModified = TRUE;
- char tmp[33];
- int j;
- strcpy (tmp, m_strGroups[i]);
- strcpy (m_strGroups[i], m_strGroups[i+1]);
- strcpy (m_strGroups[i+1], tmp);
- j = m_nBitmaps[i];
- m_nBitmaps[i] = m_nBitmaps[i+1];
- m_nBitmaps[i+1] = j;
-
- for (j = 0; j < m_Parts.GetSize(); j++)
- {
- DWORD grp = m_Parts[j].group;
- BOOL g1 = (grp & (1 << i)) != 0;
- BOOL g2 = (grp & (1 << (i+1))) != 0;
-
- if (g1)
- grp |= (1 << (i+1));
- else
- grp &= ~(1 << (i+1));
- if (g2)
- grp |= (1 << i);
- else
- grp &= ~(1 << i);
+ m_Manager.HandleCommand (LC_LIBDLG_GROUP_MOVEDOWN, dw);
- m_Parts[j].group = grp;
- }
+ j = m_nBitmaps[dw];
+ m_nBitmaps[dw] = m_nBitmaps[dw+1];
+ m_nBitmaps[dw+1] = j;
UpdateTree();
UpdateList();
@@ -605,9 +477,6 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
case ID_LIBDLG_PIECE_DELETE:
{
- if (AfxMessageBox("Are you sure you want to delete ?", MB_ICONQUESTION | MB_YESNO) != IDYES)
- return TRUE;
-
int i, sel = 0;
for (i = 0; i < m_List.GetItemCount(); i++)
@@ -621,46 +490,23 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
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))
{
- names[sel] = m_Parts[m_List.GetItemData(i)].info->m_strName;
+ m_Manager.GetPieceInfo (m_List.GetItemData(i), &info, &group);
+
+ names[sel] = info->m_strName;
sel++;
}
-
- project->GetPiecesLibrary ()->DeletePiece(names, sel);
- free(names);
-
- CString str = project->GetPiecesLibrary ()->GetLibraryPath();
- FileDisk newidx;
- if (!newidx.Open(str + "pieces.idx", "rb"))
- {
- AfxMessageBox("Cannot open file.", MB_OK|MB_ICONERROR);
- return TRUE;
- }
-
- unsigned short count;
-
- // Reload the piece library index.
- newidx.Seek(-2, SEEK_END);
- newidx.Read(&count, 2);
- newidx.Seek(34, SEEK_SET);
-
- m_Parts.SetSize(count);
- for (i = 0; i < count; i++)
- {
- PARTGROUPINFO* inf = &m_Parts[i];
- inf->info = project->GetPiecesLibrary ()->GetPieceInfo(i);
- inf->group = inf->info->m_nGroups;
-
- newidx.Seek(85, SEEK_CUR);
- newidx.Read(&inf->defgroup , 4);
- newidx.Seek(8, SEEK_CUR);
}
- newidx.Close();
+ m_Manager.DeletePieces (names, sel);
+ free(names);
UpdateList();
- m_bReload = TRUE;
return TRUE;
}
@@ -679,9 +525,14 @@ void CLibraryDlg::UpdateList()
{
DWORD dw = m_Tree.GetItemData (hti);
- for (int i = 0; i < m_Parts.GetSize(); i++)
+ for (int i = 0; i < m_Manager.GetPieceCount(); i++)
{
- if ((dw != 0) && ((dw & m_Parts[i].group) == 0))
+ PieceInfo* info;
+ lcuint32 group;
+
+ m_Manager.GetPieceInfo (i, &info, &group);
+
+ if ((dw != 0) && (((1 << (dw-1)) & group) == 0))
continue;
LVITEM lvi;
@@ -689,7 +540,7 @@ void CLibraryDlg::UpdateList()
lvi.iItem = 0;
lvi.iSubItem = 0;
lvi.lParam = i;
- lvi.pszText = m_Parts[i].info->m_strDescription;
+ lvi.pszText = info->m_strDescription;
m_List.InsertItem(&lvi);
}
}
@@ -710,22 +561,22 @@ void CLibraryDlg::UpdateTree()
tvs.item.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT | TVIF_PARAM;
HTREEITEM hRootItem = m_Tree.InsertItem(&tvs);
- for (int i = 0; i < m_nMaxGroups; i++)
+ 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 = (LONG)(1 << i);
- tvstruct.item.pszText = m_strGroups[i];
+ 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())
@@ -768,7 +619,7 @@ BOOL CLibraryDlg::DoSave(BOOL bAskName)
// m_bLoaded = TRUE;
return TRUE;
}
-
+*/
void CLibraryDlg::OnSelChangedTree(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
@@ -844,18 +695,12 @@ void CLibraryDlg::OnLButtonUp(UINT nFlags, CPoint point)
if (m_hDropItem)
{
DWORD dw = m_Tree.GetItemData(m_hDropItem);
- BOOL bControl = (GetKeyState (VK_CONTROL) < 0);
+ bool bControl = (GetKeyState (VK_CONTROL) < 0);
for (int i = 0; i < m_List.GetItemCount(); i++)
if (m_List.GetItemState(i,LVIS_SELECTED))
- {
- m_bModified = TRUE;
+ m_Manager.SetPieceGroup(m_List.GetItemData(i), dw, bControl);
- if (bControl)
- m_Parts[m_List.GetItemData(i)].group |= dw;
- else
- m_Parts[m_List.GetItemData(i)].group = dw;
- }
m_Tree.SelectDropTarget (NULL);
m_hDropItem = NULL;
UpdateList();
@@ -867,43 +712,20 @@ void CLibraryDlg::OnLButtonUp(UINT nFlags, CPoint point)
void CLibraryDlg::OnCancel()
{
- if (m_bModified)
- if (AfxMessageBox("Discard changes ?", MB_YESNO|MB_ICONQUESTION) == IDNO)
- return;
+ // Check if it's ok to close the dialog
+ if (!m_Manager.SaveModified ())
+ return;
CDialog::OnCancel();
-
- if (m_pDragImage)
- delete m_pDragImage;
}
void CLibraryDlg::OnOK()
{
- if (m_bModified)
- switch(AfxMessageBox ("Save changes ?", MB_YESNOCANCEL|MB_ICONQUESTION))
- {
- case IDYES:
- {
- if (DoSave(FALSE) == FALSE)
- return;
- } break;
- case IDNO:
- break;
- case IDCANCEL:
- return;
- }
+ // Check if it's ok to close the dialog
+ if (!m_Manager.SaveModified ())
+ return;
CDialog::OnOK();
-
- for (int i = 0; i < m_Parts.GetSize(); i++)
- {
- PARTGROUPINFO* inf = &m_Parts[i];
- inf->info->m_nGroups = inf->group;
- }
- theApp.WriteProfileString("Settings", "Groups", m_strFile);
-
- if (m_pDragImage)
- delete m_pDragImage;
}
BOOL CLibraryDlg::OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult)
@@ -953,11 +775,11 @@ BOOL CLibraryDlg::ContinueModal()
DWORD dw = m_Tree.GetItemData (h);
BOOL bValid = (h != m_Tree.GetRootItem()) && (h != NULL);
- EnableControl(ID_LIBDLG_GROUP_INSERT, m_nMaxGroups < 32);
+ EnableControl(ID_LIBDLG_GROUP_INSERT, m_Manager.GetGroupCount() < 32);
EnableControl(ID_LIBDLG_GROUP_RENAME, bValid);
- EnableControl(ID_LIBDLG_GROUP_DELETE, bValid && m_nMaxGroups != 1);
+ EnableControl(ID_LIBDLG_GROUP_DELETE, bValid && m_Manager.GetGroupCount() != 1);
EnableControl(ID_LIBDLG_GROUP_MOVEUP, dw > 1);
- EnableControl(ID_LIBDLG_GROUP_MOVEDOWN, (dw != 0) && (dw != (DWORD)(1 << (m_nMaxGroups-1))));
+ EnableControl(ID_LIBDLG_GROUP_MOVEDOWN, (dw != 0) && ((int)dw != m_Manager.GetGroupCount()));
return CDialog::ContinueModal();
}
diff --git a/win/Libdlg.h b/win/Libdlg.h
index fbc3d45..798e6b6 100644
--- a/win/Libdlg.h
+++ b/win/Libdlg.h
@@ -7,6 +7,8 @@
// LibDlg.h : header file
//
+#include "libman.h"
+
class PieceInfo;
typedef struct {
@@ -24,11 +26,8 @@ class CLibraryDlg : public CDialog
{
// Construction
public:
- BOOL DoSave(BOOL bAskName);
CLibraryDlg(CWnd* pParent = NULL); // standard constructor
- BOOL m_bReload;
- BOOL m_bModified;
- CString m_strFile;
+ virtual ~CLibraryDlg();
// Dialog Data
//{{AFX_DATA(CLibraryDlg)
@@ -53,12 +52,10 @@ public:
void UpdateTree();
void UpdateList();
- BYTE m_nMaxGroups;
+// BYTE m_nMaxGroups;
int m_nBitmaps[32];
- char m_strGroups[32][33];
CImageList m_ImageList;
- CArray<PARTGROUPINFO, PARTGROUPINFO> m_Parts;
CToolBar m_wndToolBar;
CImageList m_TreeImages;
@@ -68,6 +65,9 @@ public:
HTREEITEM m_hDropItem;
protected:
+ LibraryManager m_Manager;
+
+protected:
// Generated message map functions
//{{AFX_MSG(CLibraryDlg)
virtual BOOL OnInitDialog();