Start using the new Pieces Library.

This commit is contained in:
leo 2012-10-02 01:23:44 +00:00
parent 51b9570396
commit 30ec8634d8
20 changed files with 560 additions and 3803 deletions

View file

@ -2,7 +2,7 @@
#include <stdio.h>
#include "lc_application.h"
#include "lc_colors.h"
#include "library.h"
#include "lc_library.h"
#include "system.h"
#include "console.h"
#include "opengl.h"
@ -14,7 +14,7 @@
lcApplication* g_App;
PiecesLibrary* lcGetPiecesLibrary()
lcPiecesLibrary* lcGetPiecesLibrary()
{
LC_ASSERT(g_App, "g_App not initialized.");
return g_App->GetPiecesLibrary();
@ -51,9 +51,7 @@ bool lcApplication::LoadPiecesLibrary(const char* LibPath, const char* SysLibPat
{
// Create an empty library.
if (m_Library == NULL)
m_Library = new PiecesLibrary();
else
m_Library->Unload();
m_Library = new lcPiecesLibrary();
// Check if the user specified a library path in the command line.
if (LibPath != NULL)
@ -83,86 +81,6 @@ bool lcApplication::LoadPiecesLibrary(const char* LibPath, const char* SysLibPat
return false;
}
void lcApplication::ConvertPiecesLibrary(const char* SrcPath, const char* DstPath)
{
ObjArray<String> FileList;
PiecesLibrary Library;
Library.SetPath(DstPath);
if (!Library.DeleteAllPieces())
{
printf("Error: Couldn't open library file for writing."); // TODO: replace printfs with a callback and progress dialog, then delete the duplicate code in libdlg.cpp
return;
}
Sys_GetFileList(SrcPath, FileList);
if (!FileList.GetSize())
{
printf("Error: No files to import.");
return;
}
char file1[LC_MAXPATH], file2[LC_MAXPATH];
lcDiskFile DiskIdx, DiskBin;
strcpy(file1, Library.GetLibraryPath());
strcat(file1, "pieces.idx");
strcpy(file2, Library.GetLibraryPath());
strcat(file2, "pieces.bin");
if ((!DiskIdx.Open(file1, "rb")) || (!DiskBin.Open(file2, "rb")))
return;
lcMemFile IdxFile1, IdxFile2, BinFile1, BinFile2;
IdxFile1.CopyFrom(DiskIdx);
BinFile1.CopyFrom(DiskBin);
lcMemFile* NewIdx = &IdxFile1;
lcMemFile* NewBin = &BinFile1;
lcMemFile* OldIdx = &IdxFile2;
lcMemFile* OldBin = &BinFile2;
for (int i = 0; i < FileList.GetSize(); i++)
{
char* Name = FileList[i];
char* Slash = strrchr(Name, '\\');
if (Slash > Name)
Name = Slash+1;
Slash = strrchr(Name, '/');
if (Slash > Name)
Name = Slash+1;
printf("Importing %s\n", Name);
lcMemFile* TmpFile;
TmpFile = NewBin;
NewBin = OldBin;
OldBin = TmpFile;
NewBin->SetLength(0);
TmpFile = NewIdx;
NewIdx = OldIdx;
OldIdx = TmpFile;
NewIdx->SetLength(0);
lcGetPiecesLibrary()->ImportLDrawPiece(FileList[i], NewIdx, NewBin, OldIdx, OldBin);
}
if ((!DiskIdx.Open(file1, "wb")) || (!DiskBin.Open(file2, "wb")))
{
printf("Error: Couldn't open library file for writing.");
return;
}
DiskIdx.CopyFrom(*NewIdx);
DiskBin.CopyFrom(*NewBin);
}
void lcApplication::ParseIntegerArgument(int* CurArg, int argc, char* argv[], int* Value)
{
if (argc > (*CurArg + 1))
@ -232,22 +150,6 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* SysLibPath)
{
ParseStringArgument(&i, argc, argv, &LibPath);
}
else if (strcmp(Param, "--convert") == 0)
{
if (argc > i + 2)
{
ParseStringArgument(&i, argc, argv, &LDrawPath);
ParseStringArgument(&i, argc, argv, &LibPath);
ConvertPiecesLibrary(LDrawPath, LibPath);
}
else
{
printf("Not enough command line arguments.\n");
}
return false;
}
else if ((strcmp(Param, "-i") == 0) || (strcmp(Param, "--image") == 0))
{
SaveImage = true;

View file

@ -4,7 +4,7 @@
#include "array.h"
class Project;
class PiecesLibrary;
class lcPiecesLibrary;
class lcApplication
{
@ -16,9 +16,8 @@ public:
void Shutdown();
// Pieces library.
void ConvertPiecesLibrary(const char* SrcPath, const char* DstPath);
bool LoadPiecesLibrary(const char* LibPath, const char* SysLibPath);
PiecesLibrary* GetPiecesLibrary() const
lcPiecesLibrary* GetPiecesLibrary() const
{
return m_Library;
}
@ -42,11 +41,11 @@ protected:
Project* m_ActiveProject;
PtrArray<Project> m_Projects;
PiecesLibrary* m_Library;
lcPiecesLibrary* m_Library;
};
extern lcApplication* g_App;
PiecesLibrary* lcGetPiecesLibrary();
lcPiecesLibrary* lcGetPiecesLibrary();
Project* lcGetActiveProject();
#endif // _LC_APPLICATION_H_

View file

@ -4,6 +4,7 @@
#include "lc_file.h"
#include "pieceinf.h"
#include "lc_colors.h"
#include "system.h"
lcPiecesLibrary::lcPiecesLibrary()
{
@ -18,6 +19,57 @@ lcPiecesLibrary::~lcPiecesLibrary()
delete mZipFile;
}
PieceInfo* lcPiecesLibrary::FindPiece(const char* PieceName, bool CreatePlaceholderIfMissing)
{
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
if (!strcmp(PieceName, mPieces[PieceIdx]->m_strName))
return mPieces[PieceIdx];
if (CreatePlaceholderIfMissing)
return CreatePlaceholder(PieceName);
return NULL;
}
PieceInfo* lcPiecesLibrary::CreatePlaceholder(const char* PieceName)
{
PieceInfo* Info = new PieceInfo();
Info->CreatePlaceholder(PieceName);
mPieces.Add(Info);
return Info;
}
bool lcPiecesLibrary::Load(const char* SearchPath)
{
char LibraryPath[LC_MAXPATH];
strcpy(LibraryPath, SearchPath);
int i = strlen(LibraryPath) - 1;
if ((LibraryPath[i] != '\\') && (LibraryPath[i] != '/'))
strcat(LibraryPath, "/");
strcpy(mLibraryPath, LibraryPath);
strcat(LibraryPath, "complete.zip");
if (!OpenArchive(LibraryPath))
return false;
const char* FileName = Sys_ProfileLoadString("Settings", "Categories", "");
if (!strlen(FileName) || !LoadCategories(FileName))
ResetCategories();
SystemUpdateCategories(false);
mCategoriesModified = false;
Sys_ProfileSaveString("Settings", "PiecesLibrary", mLibraryPath);
return true;
}
bool lcPiecesLibrary::OpenArchive(const char* FileName)
{
mZipFile = new lcZipFile();
@ -579,3 +631,363 @@ void lcLibraryMeshData::AddMeshDataNoDuplicateCheck(const lcLibraryMeshData& Dat
DstSection->mIndices.Add(BaseIndex + SrcSection->mIndices[IndexIdx]);
}
}
bool lcPiecesLibrary::PieceInCategory(PieceInfo* Info, const String& CategoryKeywords) const
{
String PieceName = Info->m_strDescription;
PieceName.MakeLower();
String Keywords = CategoryKeywords;
Keywords.MakeLower();
return PieceName.Match(Keywords);
}
int lcPiecesLibrary::GetFirstPieceCategory(PieceInfo* Info) const
{
for (int i = 0; i < mCategories.GetSize(); i++)
if (PieceInCategory(Info, mCategories[i].Keywords))
return i;
return -1;
}
void lcPiecesLibrary::GetCategoryEntries(int CategoryIndex, bool GroupPieces, PtrArray<PieceInfo>& SinglePieces, PtrArray<PieceInfo>& GroupedPieces)
{
SinglePieces.RemoveAll();
GroupedPieces.RemoveAll();
// Don't group entries in the search results category.
if (mCategories[CategoryIndex].Name == "Search Results")
GroupPieces = false;
for (int i = 0; i < mPieces.GetSize(); i++)
{
PieceInfo* Info = mPieces[i];
if (!PieceInCategory(Info, mCategories[CategoryIndex].Keywords))
continue;
if (!GroupPieces)
{
SinglePieces.Add(Info);
continue;
}
// Check if it's a patterned piece.
if (Info->IsPatterned())
{
PieceInfo* Parent;
// Find the parent of this patterned piece.
char ParentName[LC_PIECE_NAME_LEN];
strcpy(ParentName, Info->m_strName);
*strchr(ParentName, 'P') = '\0';
Parent = FindPiece(ParentName, false);
if (Parent)
{
// Check if the parent was added as a single piece.
int Index = SinglePieces.FindIndex(Parent);
if (Index != -1)
SinglePieces.RemoveIndex(Index);
Index = GroupedPieces.FindIndex(Parent);
if (Index == -1)
GroupedPieces.Add(Parent);
}
else
{
// Patterned pieces should have a parent but in case they don't just add them anyway.
SinglePieces.Add(Info);
}
}
else
{
// Check if this piece has already been added to this category by one of its children.
int Index = GroupedPieces.FindIndex(Info);
if (Index == -1)
SinglePieces.Add(Info);
}
}
}
void lcPiecesLibrary::GetPatternedPieces(PieceInfo* Parent, PtrArray<PieceInfo>& Pieces) const
{
char Name[LC_PIECE_NAME_LEN];
strcpy(Name, Parent->m_strName);
strcat(Name, "P");
Pieces.RemoveAll();
for (int i = 0; i < mPieces.GetSize(); i++)
{
PieceInfo* Info = mPieces[i];
if (strncmp(Name, Info->m_strName, strlen(Name)) == 0)
Pieces.Add(Info);
}
// Sometimes pieces with A and B versions don't follow the same convention (for example, 3040Pxx instead of 3040BPxx).
if (Pieces.GetSize() == 0)
{
strcpy(Name, Parent->m_strName);
int Len = strlen(Name);
if (Name[Len-1] < '0' || Name[Len-1] > '9')
Name[Len-1] = 'P';
for (int i = 0; i < mPieces.GetSize(); i++)
{
PieceInfo* Info = mPieces[i];
if (strncmp(Name, Info->m_strName, strlen(Name)) == 0)
Pieces.Add(Info);
}
}
}
void lcPiecesLibrary::ResetCategories()
{
struct CategoryEntry
{
const char* Name;
const char* Keywords;
};
// Animal, Antenna, Arch, Arm, Bar, Baseplate, Belville, Boat, Bracket, Brick,
// Car, Cone, Container, Conveyor, Crane, Cylinder, Door, Electric, Exhaust,
// Fence, Flag, Forklift, Freestyle, Garage, Gate, Glass, Grab, Hinge, Homemaker,
// Hose, Jack, Ladder, Lever, Magnet, Minifig, Minifig Accessory, Panel, Plane,
// Plant, Plate, Platform, Propellor, Rack, Roadsign, Rock, Scala, Slope, Staircase,
// Support, Tail, Tap, Technic, Tile, Tipper, Tractor, Trailer, Train, Turntable,
// Tyre, Wedge, Wheel, Winch, Window, Windscreen, Wing
CategoryEntry DefaultCategories[] =
{
{ "Animal", "^%Animal" },
{ "Antenna", "^%Antenna" },
{ "Arch", "^%Arch" },
{ "Bar", "^%Bar" },
{ "Baseplate", "^%Baseplate | ^%Platform" },
{ "Boat", "^%Boat" },
{ "Brick", "^%Brick" },
{ "Container", "^%Container | ^%Box | ^Chest | ^%Storage | ^Mailbox" },
{ "Door and Window", "^%Door | ^%Window | ^%Glass | ^%Freestyle | ^%Gate | ^%Garage | ^%Roller" },
{ "Duplo", "^%Duplo | ^%Scala | ^%Belville" },
{ "Electric", "^%Electric | ^%Light | ^%Excavator | ^%Exhaust" },
{ "Hinge and Bracket", "^%Hinge | ^%Bracket | ^%Turntable" },
{ "Hose", "^%Hose" },
{ "Minifig", "^%Minifig" },
{ "Miscellaneous", "^%Arm | ^%Barrel | ^%Brush | ^%Cockpit | ^%Conveyor | ^%Crane | ^%Cupboard | ^%Fabuland | ^%Fence | ^%Homemaker | ^%Jack | ^%Ladder | ^%Rock | ^%Staircase | ^%Stretcher | ^%Tap | ^%Tipper | ^%Trailer | ^%Winch" },
{ "Panel", "^%Panel | ^%Castle Wall | ^%Castle Turret" },
{ "Plant", "^%Plant" },
{ "Plate", "^%Plate" },
{ "Round", "^%Cylinder | ^%Cone | ^%Dish | ^%Round" },
{ "Sign and Flag", "^%Flag | ^%Roadsign | ^%Streetlight | ^%Flagpost | ^%Lamppost | ^%Signpost" },
{ "Slope", "^%Slope" },
{ "Space", "^%Space" },
{ "Sticker", "^%Sticker" },
{ "Support", "^%Support" },
{ "Technic", "^%Technic | ^%Rack" },
{ "Tile", "^%Tile" },
{ "Train", "^%Train | ^%Monorail | ^%Magnet" },
{ "Tyre and Wheel", "^%Tyre | %^Wheel | ^%Castle Wagon" },
{ "Vehicle", "^%Car | ^%Tractor | ^%Bike | ^%Plane | ^%Propellor | ^%Tail | ^%Landing | ^%Forklift | ^%Grab Jaw" },
{ "Windscreen", "^%Windscreen" },
{ "Wedge", "^%Wedge" },
{ "Wing", "^%Wing" },
};
const int NumCategories = sizeof(DefaultCategories)/sizeof(DefaultCategories[0]);
mCategories.RemoveAll();
for (int i = 0; i < NumCategories; i++)
{
lcLibraryCategory& Category = mCategories.Add();
Category.Name = DefaultCategories[i].Name;
Category.Keywords = DefaultCategories[i].Keywords;
}
strcpy(mCategoriesFile, "");
Sys_ProfileSaveString("Settings", "Categories", mCategoriesFile);
mCategoriesModified = false;
}
bool lcPiecesLibrary::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, mCategoriesFile);
if (!SystemDoDialog(LC_DLG_FILE_OPEN, &opts))
return false;
strcpy(Path, (char*)opts.filenames);
free(opts.filenames);
}
// Load the file.
lcDiskFile File;
if (!File.Open(Path, "rb"))
return false;
lcuint32 i;
File.ReadU32(&i, 1);
if (i != LC_FILE_ID)
return false;
File.ReadU32(&i, 1);
if (i != LC_CATEGORY_FILE_ID)
return false;
File.ReadU32(&i, 1);
if (i != LC_CATEGORY_FILE_VERSION)
return false;
mCategories.RemoveAll();
File.ReadU32(&i, 1);
while (i--)
{
lcLibraryCategory& Category = mCategories.Add();
File.ReadString(Category.Name);
File.ReadString(Category.Keywords);
}
strcpy(mCategoriesFile, Path);
Sys_ProfileSaveString("Settings", "Categories", mCategoriesFile);
mCategoriesModified = false;
return true;
}
bool lcPiecesLibrary::SaveCategories()
{
if (mCategoriesModified)
{
switch (SystemDoMessageBox("Save changes to categories?", 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 lcPiecesLibrary::DoSaveCategories(bool AskName)
{
// Get the file name.
if (AskName || (strlen(mCategoriesFile) == 0))
{
LC_FILESAVEDLG_OPTS opts;
opts.type = LC_FILESAVEDLG_LCF;
strcpy(opts.path, mCategoriesFile);
if (!SystemDoDialog(LC_DLG_FILE_SAVE, &opts))
return false;
strcpy(mCategoriesFile, opts.path);
}
// Save the file.
lcDiskFile File;
if (!File.Open(mCategoriesFile, "wb"))
return false;
File.WriteU32(LC_FILE_ID);
File.WriteU32(LC_CATEGORY_FILE_ID);
File.WriteU32(LC_CATEGORY_FILE_VERSION);
int NumCategories = mCategories.GetSize();
int i;
for (i = 0; i < mCategories.GetSize(); i++)
{
if (mCategories[i].Name == "Search Results")
{
NumCategories--;
break;
}
}
File.WriteU32(NumCategories);
for (i = 0; i < mCategories.GetSize(); i++)
{
if (mCategories[i].Name == "Search Results")
continue;
File.WriteString(mCategories[i].Name);
File.WriteString(mCategories[i].Keywords);
}
Sys_ProfileSaveString("Settings", "Categories", mCategoriesFile);
mCategoriesModified = false;
return true;
}
int lcPiecesLibrary::FindCategoryIndex(const String& CategoryName) const
{
for (int i = 0; i < mCategories.GetSize(); i++)
if (mCategories[i].Name == CategoryName)
return i;
return -1;
}
void lcPiecesLibrary::SetCategory(int Index, const String& Name, const String& Keywords)
{
mCategories[Index].Name = Name;
mCategories[Index].Keywords = Keywords;
SystemUpdateCategories(true);
mCategoriesModified = true;
}
void lcPiecesLibrary::AddCategory(const String& Name, const String& Keywords)
{
lcLibraryCategory& Category = mCategories.Add();
Category.Name = Name;
Category.Keywords = Keywords;
SystemUpdateCategories(true);
mCategoriesModified = true;
}
void lcPiecesLibrary::RemoveCategory(int Index)
{
mCategories.RemoveIndex(Index);
mCategoriesModified = true;
}

View file

@ -3,10 +3,14 @@
#include "lc_mesh.h"
#include "array.h"
#include "str.h"
class PieceInfo;
class lcZipFile;
#define LC_CATEGORY_FILE_ID LC_FOURCC('C', 'A', 'T', 0)
#define LC_CATEGORY_FILE_VERSION 0x0100
class lcLibraryMeshSection
{
public:
@ -57,15 +61,39 @@ public:
lcLibraryMeshData mMeshData;
};
struct lcLibraryCategory
{
String Name;
String Keywords;
};
class lcPiecesLibrary
{
public:
lcPiecesLibrary();
~lcPiecesLibrary();
bool Load(const char* SearchPath);
PieceInfo* FindPiece(const char* PieceName, bool CreatePlaceholderIfMissing);
PieceInfo* CreatePlaceholder(const char* PieceName);
bool PieceInCategory(PieceInfo* Info, const String& CategoryKeywords) const;
int GetFirstPieceCategory(PieceInfo* Info) const;
void GetCategoryEntries(int CategoryIndex, bool GroupPieces, PtrArray<PieceInfo>& SinglePieces, PtrArray<PieceInfo>& GroupedPieces);
void GetPatternedPieces(PieceInfo* Parent, PtrArray<PieceInfo>& Pieces) const;
int FindCategoryIndex(const String& CategoryName) const;
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 LoadCategories(const char* FileName);
bool SaveCategories();
bool DoSaveCategories(bool AskName);
bool OpenArchive(const char* FileName);
bool LoadPiece(const char* PieceName);
bool LoadPiece(int PieceIndex);
int FindPrimitiveIndex(const char* Name);
@ -74,8 +102,14 @@ public:
PtrArray<PieceInfo> mPieces;
PtrArray<lcLibraryPrimitive> mPrimitives;
ObjArray<lcLibraryCategory> mCategories;
char mLibraryPath[LC_MAXPATH];
protected:
bool mCategoriesModified;
char mCategoriesFile[LC_MAXPATH];
lcZipFile* mZipFile;
};

File diff suppressed because it is too large Load diff

View file

@ -1,169 +0,0 @@
#ifndef _LIBRARY_H_
#define _LIBRARY_H_
#include "str.h"
#include "array.h"
class Texture;
class PieceInfo;
#define LC_CATEGORY_FILE_ID LC_FOURCC('C', 'A', 'T', 0)
#define LC_CATEGORY_FILE_VERSION 0x0100
struct PiecesLibraryCategory
{
String Name;
String Keywords;
};
class PiecesLibrary
{
public:
PiecesLibrary();
~PiecesLibrary();
const char* GetLibraryPath() const
{
return m_LibraryPath;
}
int GetPieceCount() const
{
return m_Pieces.GetSize();
}
int GetTextureCount() const
{
return m_nTextureCount;
}
// Categories.
bool PieceInCategory(PieceInfo* Info, const String& CategoryKeywords) const;
int GetFirstCategory(PieceInfo* Info) const;
void GetCategoryEntries(int CategoryIndex, bool GroupPieces, PtrArray<PieceInfo>& SinglePieces, PtrArray<PieceInfo>& GroupedPieces) const;
void GetPatternedPieces(PieceInfo* Parent, PtrArray<PieceInfo>& Pieces) const;
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 String& GetCategoryName(int Index) const
{ return m_Categories[Index].Name; }
const String& GetCategoryKeywords(int Index) const
{ return m_Categories[Index].Keywords; }
int GetNumCategories() const
{ return m_Categories.GetSize(); }
int FindCategoryIndex(const String& CategoryName) const
{
for (int i = 0; i < m_Categories.GetSize(); i++)
if (m_Categories[i].Name == CategoryName)
return i;
return -1;
}
bool Load(const char* libpath);
void Unload();
void SetPath(const char* LibPath);
// 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* CreatePiecePlaceholder(const char* Name);
// File operations.
bool DeleteAllPieces();
bool DeletePieces(PtrArray<const char>& Pieces);
bool LoadUpdate(const char* update);
bool DeleteTextures(char** Names, int NumTextures);
bool ImportTexture(const char* Name);
bool ImportLDrawPiece(const char* Filename, lcFile* NewIdxFile, lcFile* NewBinFile, lcFile* OldIdxFile, lcFile* OldBinFile);
// Set when pieces are added/removed from the library.
bool m_Modified;
protected:
PtrArray<PieceInfo> m_Pieces;
char m_LibraryPath[LC_MAXPATH]; // path to the library files
int m_nMovedCount; // number of moved pieces
char* m_pMovedReference; // moved pieces list
int m_nTextureCount; // number of textures
Texture* m_pTextures; // textures array
// Categories.
ObjArray<PiecesLibraryCategory> m_Categories;
bool m_CategoriesModified;
char m_CategoriesFile[LC_MAXPATH];
bool ValidatePiecesFile(lcFile& IdxFile, lcFile& BinFile) const;
bool ValidateTexturesFile(lcFile& IdxFile, lcFile& BinFile) const;
// File headers
static const char PiecesBinHeader[32];
static const char PiecesIdxHeader[32];
static const int PiecesFileVersion;
static const char TexturesBinHeader[32];
static const char TexturesIdxHeader[32];
static const int TexturesFileVersion;
};
// ============================================================================
// This should be cleaned and moved to the PiecesLibrary class
struct connection_t
{
unsigned char type;
float pos[3];
float up[3];
connection_t* next;
};
struct group_t
{
connection_t* connections[5];
void* drawinfo;
unsigned long infosize;
group_t* next;
};
struct lineinfo_t
{
int type;
lcuint32 color;
float points[12];
int indices[4];
lineinfo_t* next;
};
struct LC_LDRAW_PIECE
{
float* verts;
unsigned int verts_count;
bool long_info;
connection_t* connections;
group_t* groups;
char name[LC_MAXPATH];
char description[256];
};
bool ReadLDrawPiece(const char* filename, LC_LDRAW_PIECE* piece);
bool SaveLDrawPiece(LC_LDRAW_PIECE* piece, lcFile* NewIdxFile, lcFile* NewBinFile, lcFile* OldIdxFile, lcFile* OldBinFile);
void FreeLDrawPiece(LC_LDRAW_PIECE* piece);
#endif // _LIBRARY_H_

View file

@ -15,7 +15,7 @@
#include "globals.h"
#include "project.h"
#include "system.h"
#include "library.h"
#include "lc_library.h"
#include "lc_application.h"
// =============================================================================
@ -858,11 +858,11 @@ static int lcGetMinifigSettings(lcMemFile& File)
// =============================================================================
// MinifigWizard class
MinifigWizard::MinifigWizard (GLWindow *share)
MinifigWizard::MinifigWizard(GLWindow *share)
: GLWindow (share)
{
char Filename[LC_MAXPATH];
strcpy(Filename, lcGetPiecesLibrary()->GetLibraryPath());
strcpy(Filename, lcGetPiecesLibrary()->mLibraryPath);
strcat(Filename, "mlcad.ini");
lcDiskFile DiskSettings;
@ -932,7 +932,7 @@ void MinifigWizard::OnInitialUpdate()
m_Colors[i] = lcGetColorIndex(ColorCodes[i]);
m_Angles[i] = 0;
m_Info[i] = lcGetPiecesLibrary()->FindPieceInfo(Pieces[i]);
m_Info[i] = lcGetPiecesLibrary()->FindPiece(Pieces[i], false);
if (m_Info[i] != NULL)
m_Info[i]->AddRef();
}
@ -1081,7 +1081,7 @@ void MinifigWizard::ParseSettings(lcFile& Settings)
*Ext = 0;
}
PieceInfo* Info = lcGetPiecesLibrary()->FindPieceInfo(NameStart);
PieceInfo* Info = lcGetPiecesLibrary()->FindPiece(NameStart, false);
if (!Info && *NameStart)
continue;
@ -1440,7 +1440,7 @@ bool MinifigWizard::LoadMinifig(const char* name)
endptr = strchr(ptr, ' ');
*endptr = '\0';
m_Info[j] = lcGetPiecesLibrary()->FindPieceInfo(ptr);
m_Info[j] = lcGetPiecesLibrary()->FindPiece(ptr, false);
*endptr = ' ';
ptr = endptr;

View file

@ -10,7 +10,7 @@
#include "texture.h"
#include "pieceinf.h"
#include "project.h"
#include "library.h"
#include "lc_library.h"
#include "lc_application.h"
#define SIDES 16
@ -172,624 +172,18 @@ void PieceInfo::CreateBoxDisplayList()
glEndList();
}
inline lcuint16 EndianSwap(lcuint16 Val)
{
return LCUINT16(Val);
}
inline lcuint32 EndianSwap(lcuint32 Val)
{
return LCUINT32(Val);
}
template<typename SrcType, typename DstType>
static void WriteMeshDrawInfo(lcuint32*& Data, lcMesh* Mesh, float*& OutVertex, int* SectionIndices, lcMeshSection** DstSections)
{
int NumColors = EndianSwap(*Data);
Data++;
for (int Color = 0; Color < NumColors; Color++)
{
int ColorIdx = lcGetColorIndex(EndianSwap(*Data));
Data++;
SrcType* SrcPtr = (SrcType*)Data;
int NumQuads = EndianSwap(*SrcPtr);
SrcPtr++;
int NumTris = EndianSwap(*(SrcPtr + NumQuads));
if (NumTris || NumQuads)
{
lcMeshSection* Section = DstSections[ColorIdx * 2 + 0];
DstType* OutIndex = (DstType*)Mesh->mIndexBuffer.mData + Section->IndexOffset / sizeof(DstType) + Section->NumIndices;
for (int i = 0; i < NumQuads; i += 4)
{
*OutIndex++ = EndianSwap(SrcPtr[0]);
*OutIndex++ = EndianSwap(SrcPtr[1]);
*OutIndex++ = EndianSwap(SrcPtr[2]);
*OutIndex++ = EndianSwap(SrcPtr[0]);
*OutIndex++ = EndianSwap(SrcPtr[2]);
*OutIndex++ = EndianSwap(SrcPtr[3]);
SrcPtr += 4;
}
SrcPtr++;
for (int i = 0; i < NumTris; i++)
{
*OutIndex++ = EndianSwap(*SrcPtr);
SrcPtr++;
}
Section->NumIndices += NumQuads / 4 * 6 + NumTris;
}
else
SrcPtr++;
int NumLines = EndianSwap(*SrcPtr);
SrcPtr++;
if (NumLines)
{
lcMeshSection* Section = DstSections[ColorIdx * 2 + 1];
DstType* OutIndex = (DstType*)Mesh->mIndexBuffer.mData + Section->IndexOffset / sizeof(DstType) + Section->NumIndices;
for (int i = 0; i < NumLines; i++)
{
*OutIndex++ = EndianSwap(*SrcPtr);
SrcPtr++;
}
Section->NumIndices += NumLines;
}
Data = (lcuint32*)SrcPtr;
}
}
template<class DstType>
static void WriteStudDrawInfo(int ColorIdx, const lcMatrix44& Mat, lcMesh* Mesh, float*& OutVertex, float Radius, int* SectionIndices, lcMeshSection** DstSections)
{
// Build vertices.
int BaseVertex = (OutVertex - (float*)Mesh->mVertexBuffer.mData) / 3;
lcVector3 Vert;
for (int i = 0; i < SIDES; i++)
{
Vert = lcMul31(lcVector3(Radius * costbl[i], Radius * sintbl[i], 0.0f), Mat);
*OutVertex++ = Vert[0];
*OutVertex++ = Vert[1];
*OutVertex++ = Vert[2];
Vert = lcMul31(lcVector3(Radius * costbl[i], Radius * sintbl[i], LC_STUD_HEIGHT), Mat);
*OutVertex++ = Vert[0];
*OutVertex++ = Vert[1];
*OutVertex++ = Vert[2];
}
Vert = lcMul31(lcVector3(0.0f, 0.0f, LC_STUD_HEIGHT), Mat);
*OutVertex++ = Vert[0];
*OutVertex++ = Vert[1];
*OutVertex++ = Vert[2];
int v0 = BaseVertex + 2 * SIDES;
// Triangles.
lcMeshSection* Section = DstSections[ColorIdx * 2 + 0];
DstType* OutIndex = (DstType*)Mesh->mIndexBuffer.mData + Section->IndexOffset / sizeof(DstType) + Section->NumIndices;
for (int i = 0; i < SIDES; i++)
{
int i1 = BaseVertex + (i % SIDES) * 2;
int i2 = BaseVertex + ((i + 1) % SIDES) * 2;
int v1 = i1;
int v2 = i1 + 1;
int v3 = i2;
int v4 = i2 + 1;
*OutIndex++ = v0;
*OutIndex++ = v2;
*OutIndex++ = v4;
*OutIndex++ = v1;
*OutIndex++ = v3;
*OutIndex++ = v2;
*OutIndex++ = v3;
*OutIndex++ = v4;
*OutIndex++ = v2;
}
Section->NumIndices += 9 * SIDES;
// Lines.
Section = DstSections[gEdgeColor * 2 + 1];
OutIndex = (DstType*)Mesh->mIndexBuffer.mData + Section->IndexOffset / sizeof(DstType) + Section->NumIndices;
for (int i = 0; i < SIDES; i++)
{
int i1 = BaseVertex + (i % SIDES) * 2;
int i2 = BaseVertex + ((i + 1) % SIDES) * 2;
int v1 = i1;
int v2 = i1 + 1;
int v3 = i2;
int v4 = i2 + 1;
*OutIndex++ = v1;
*OutIndex++ = v3;
*OutIndex++ = v2;
*OutIndex++ = v4;
}
Section->NumIndices += 4 * SIDES;
}
template<class DstType>
static void WriteHollowStudDrawInfo(int ColorIdx, const lcMatrix44& Mat, lcMesh* Mesh, float*& OutVertex, float InnerRadius, float OuterRadius, int* SectionIndices, lcMeshSection** DstSections)
{
// Build vertices.
int BaseVertex = (OutVertex - (float*)Mesh->mVertexBuffer.mData) / 3;
lcVector3 Vert;
for (int i = 0; i < SIDES; i++)
{
// Outside.
Vert = lcMul31(lcVector3(OuterRadius * costbl[i], OuterRadius * sintbl[i], 0.0f), Mat);
*OutVertex++ = Vert[0];
*OutVertex++ = Vert[1];
*OutVertex++ = Vert[2];
Vert = lcMul31(lcVector3(OuterRadius * costbl[i], OuterRadius * sintbl[i], LC_STUD_HEIGHT), Mat);
*OutVertex++ = Vert[0];
*OutVertex++ = Vert[1];
*OutVertex++ = Vert[2];
// Inside.
Vert = lcMul31(lcVector3(InnerRadius * costbl[i], InnerRadius * sintbl[i], LC_STUD_HEIGHT), Mat);
*OutVertex++ = Vert[0];
*OutVertex++ = Vert[1];
*OutVertex++ = Vert[2];
Vert = lcMul31(lcVector3(InnerRadius * costbl[i], InnerRadius * sintbl[i], 0.0f), Mat);
*OutVertex++ = Vert[0];
*OutVertex++ = Vert[1];
*OutVertex++ = Vert[2];
}
// Triangles.
lcMeshSection* Section = DstSections[ColorIdx * 2 + 0];
DstType* OutIndex = (DstType*)Mesh->mIndexBuffer.mData + Section->IndexOffset / sizeof(DstType) + Section->NumIndices;
for (int i = 0; i < SIDES; i++)
{
int i1 = BaseVertex + (i % SIDES) * 4;
int i2 = BaseVertex + ((i + 1) % SIDES) * 4;
int v1 = i1;
int v2 = i1 + 1;
int v3 = i1 + 2;
int v4 = i1 + 3;
int v5 = i2;
int v6 = i2 + 1;
int v7 = i2 + 2;
int v8 = i2 + 3;
*OutIndex++ = v1;
*OutIndex++ = v5;
*OutIndex++ = v2;
*OutIndex++ = v5;
*OutIndex++ = v6;
*OutIndex++ = v2;
*OutIndex++ = v2;
*OutIndex++ = v6;
*OutIndex++ = v3;
*OutIndex++ = v6;
*OutIndex++ = v7;
*OutIndex++ = v3;
*OutIndex++ = v3;
*OutIndex++ = v7;
*OutIndex++ = v4;
*OutIndex++ = v7;
*OutIndex++ = v8;
*OutIndex++ = v4;
}
Section->NumIndices += 18 * SIDES;
// Lines.
Section = DstSections[gEdgeColor * 2 + 1];
OutIndex = (DstType*)Mesh->mIndexBuffer.mData + Section->IndexOffset / sizeof(DstType) + Section->NumIndices;
for (int i = 0; i < SIDES; i++)
{
int i1 = BaseVertex + (i % SIDES) * 4;
int i2 = BaseVertex + ((i + 1) % SIDES) * 4;
int v1 = i1;
int v2 = i1 + 1;
int v3 = i1 + 2;
int v4 = i1 + 3;
int v5 = i2;
int v6 = i2 + 1;
int v7 = i2 + 2;
int v8 = i2 + 3;
*OutIndex++ = v1;
*OutIndex++ = v5;
*OutIndex++ = v2;
*OutIndex++ = v6;
*OutIndex++ = v3;
*OutIndex++ = v7;
*OutIndex++ = v4;
*OutIndex++ = v8;
}
Section->NumIndices += 8 * SIDES;
}
template<typename DstType>
void PieceInfo::BuildMesh(void* Data, int* SectionIndices)
{
// Create empty sections.
lcMeshSection** DstSections = new lcMeshSection*[gColorList.GetSize() * 2];
memset(DstSections, 0, sizeof(DstSections[0]) * gColorList.GetSize() * 2);
int IndexOffset = 0;
int NumSections = 0;
for (int ColorIdx = 0; ColorIdx < gColorList.GetSize(); ColorIdx++)
{
if (SectionIndices[ColorIdx * 2 + 0])
{
lcMeshSection* Section = &mMesh->mSections[NumSections];
DstSections[ColorIdx * 2 + 0] = Section;
Section->PrimitiveType = GL_TRIANGLES;
Section->ColorIndex = ColorIdx;
Section->IndexOffset = IndexOffset;
Section->NumIndices = 0;
IndexOffset += SectionIndices[ColorIdx * 2 + 0] * sizeof(DstType);
NumSections++;
if (ColorIdx == gDefaultColor)
m_nFlags |= LC_PIECE_HAS_DEFAULT;
else
{
if (lcIsColorTranslucent(ColorIdx))
m_nFlags |= LC_PIECE_HAS_TRANSLUCENT;
else
m_nFlags |= LC_PIECE_HAS_SOLID;
}
}
if (SectionIndices[ColorIdx * 2 + 1])
{
lcMeshSection* Section = &mMesh->mSections[NumSections];
DstSections[ColorIdx * 2 + 1] = Section;
Section->PrimitiveType = GL_LINES;
Section->ColorIndex = ColorIdx;
Section->IndexOffset = IndexOffset;
Section->NumIndices = 0;
IndexOffset += SectionIndices[ColorIdx * 2 + 1] * sizeof(DstType);
NumSections++;
m_nFlags |= LC_PIECE_HAS_LINES;
}
}
// Read groups
lcuint32* longs = (lcuint32*)Data;
int NumVertices = LCUINT32(*longs);
float* OutVertex = (float*)mMesh->mVertexBuffer.mData + NumVertices * 3;
lcuint8* bytes = (lcuint8*)(longs + 1);
bytes += NumVertices * sizeof(lcint16) * 3;
lcuint16 ConnectionCount = LCUINT16(*((lcuint16*)bytes));
bytes += 2 + (1 + 6 * 2) * ConnectionCount;
bytes++; // TextureCount
lcuint16 GroupCount = LCUINT16(*((lcuint16*)bytes));
bytes += sizeof(lcuint16);
while (GroupCount--)
{
bytes += 1 + 2 * *bytes;
lcuint32* info = (lcuint32*)bytes;
lcuint32 type = *info;
switch (type)
{
case LC_MESH:
{
info++;
if (m_nFlags & LC_PIECE_LONGDATA_FILE)
WriteMeshDrawInfo<lcuint32, DstType>(info, mMesh, OutVertex, SectionIndices, DstSections);
else
WriteMeshDrawInfo<lcuint16, DstType>(info, mMesh, OutVertex, SectionIndices, DstSections);
} break;
case LC_STUD:
case LC_STUD3:
{
info++;
int ColorIdx = lcGetColorIndex(LCUINT32(*info));
float* MatFloats = (float*)(info + 1);
info += 1 + 12;
for (int i = 0; i < 12; i++)
MatFloats[i] = LCFLOAT(MatFloats[i]);
lcMatrix44 Mat(lcVector4(MatFloats[0], MatFloats[1], MatFloats[2], 0.0f),
lcVector4(MatFloats[3], MatFloats[4], MatFloats[5], 0.0f),
lcVector4(MatFloats[6], MatFloats[7], MatFloats[8], 0.0f),
lcVector4(MatFloats[9], MatFloats[10], MatFloats[11], 1.0f));
if (type == LC_STUD)
WriteStudDrawInfo<DstType>(ColorIdx, Mat, mMesh, OutVertex, LC_STUD_RADIUS, SectionIndices, DstSections);
else
WriteStudDrawInfo<DstType>(ColorIdx, Mat, mMesh, OutVertex, 0.16f, SectionIndices, DstSections);
} break;
case LC_STUD2:
case LC_STUD4:
{
info++;
int ColorIdx = lcGetColorIndex(LCUINT32(*info));
float* MatFloats = (float*)(info + 1);
info += 1 + 12;
for (int i = 0; i < 12; i++)
MatFloats[i] = LCFLOAT(MatFloats[i]);
lcMatrix44 Mat(lcVector4(MatFloats[0], MatFloats[1], MatFloats[2], 0.0f),
lcVector4(MatFloats[3], MatFloats[4], MatFloats[5], 0.0f),
lcVector4(MatFloats[6], MatFloats[7], MatFloats[8], 0.0f),
lcVector4(MatFloats[9], MatFloats[10], MatFloats[11], 1.0f));
if (type == LC_STUD2)
WriteHollowStudDrawInfo<DstType>(ColorIdx, Mat, mMesh, OutVertex, 0.16f, LC_STUD_RADIUS, SectionIndices, DstSections);
else
WriteHollowStudDrawInfo<DstType>(ColorIdx, Mat, mMesh, OutVertex, LC_STUD_RADIUS, 0.32f, SectionIndices, DstSections);
} break;
}
info++; // should be 0
bytes = (lcuint8*)info;
}
delete[] DstSections;
}
void PieceInfo::LoadInformation()
{
if (m_nFlags & LC_PIECE_PLACEHOLDER)
{
mMesh = new lcMesh();
mMesh->CreateBox();
return;
}
lcDiskFile bin;
char filename[LC_MAXPATH];
void* buf;
lcuint32 verts, *longs, fixverts;
lcuint8 *bytes, *tmp, bt;
float scale, shift;
lcint16* shorts;
FreeInformation();
// Open pieces.bin and buffer the information we need.
strcpy (filename, lcGetPiecesLibrary()->GetLibraryPath());
strcat (filename, "pieces.bin");
if (!bin.Open (filename, "rb"))
return;
buf = malloc(m_nSize);
bin.Seek(m_nOffset, SEEK_SET);
bin.ReadBuffer(buf, m_nSize);
shift = 1.0f/(1<<14);
scale = 0.01f;
if (m_nFlags & LC_PIECE_MEDIUM) scale = 0.001f;
if (m_nFlags & LC_PIECE_SMALL) scale = 0.0001f;
longs = (lcuint32*)buf;
fixverts = verts = LCUINT32(*longs);
bytes = (unsigned char*)(longs + 1);
bytes += verts * sizeof(lcint16) * 3;
lcuint16 ConnectionCount = LCUINT16(*((lcuint16*)bytes));
bytes += 2 + (1 + 6 * 2) * ConnectionCount;
bytes++; // TextureCount
// Read groups.
lcuint16 GroupCount = LCUINT16(*((lcuint16*)bytes));
bytes += sizeof(lcuint16);
// Count sections, vertices and indices.
tmp = bytes;
int NumSections = 0;
int NumVertices = fixverts;
int NumIndices = 0;
ObjArray<int> SectionIndices(gColorList.GetSize() * 2);
SectionIndices.SetSize(gColorList.GetSize() * 2);
memset(&SectionIndices[0], 0, SectionIndices.GetSize() * sizeof(int));
while (GroupCount--)
{
bt = *bytes;
bytes++;
bytes += bt*sizeof(lcuint16);
lcuint32* info = (lcuint32*)bytes;
while (*info)
{
if (*info == LC_MESH)
{
info++;
lcuint32 NumColors = LCUINT32(*info);
info++;
while (NumColors--)
{
int ColorIndex = lcGetColorIndex(LCUINT32(*info));
info++;
if (SectionIndices.GetSize() < (ColorIndex + 1) * 2)
{
int OldSize = SectionIndices.GetSize();
SectionIndices.SetSize((ColorIndex + 1) * 2);
memset(&SectionIndices[OldSize], 0, (SectionIndices.GetSize() - OldSize) * sizeof(int));
}
if (m_nFlags & LC_PIECE_LONGDATA_FILE)
{
lcuint32* Indices = (lcuint32*)info;
int Triangles = LCUINT32(*Indices) / 4 * 6;
Indices += LCUINT32(*Indices) + 1;
Triangles += LCUINT32(*Indices);
Indices += LCUINT32(*Indices) + 1;
if (Triangles)
{
if (!SectionIndices[ColorIndex * 2 + 0])
NumSections++;
SectionIndices[ColorIndex * 2 + 0] += Triangles;
NumIndices += Triangles;
}
int Lines = LCUINT32(*Indices);
Indices += LCUINT32(*Indices) + 1;
if (Lines)
{
if (!SectionIndices[ColorIndex * 2 + 1])
NumSections++;
SectionIndices[ColorIndex * 2 + 1] += Lines;
NumIndices += Lines;
}
info = (lcuint32*)Indices;
}
else
{
lcuint16* Indices = (lcuint16*)info;
int Triangles = LCUINT16(*Indices) / 4 * 6;
Indices += LCUINT16(*Indices) + 1;
Triangles += LCUINT16(*Indices);
Indices += LCUINT16(*Indices) + 1;
if (Triangles)
{
if (!SectionIndices[ColorIndex * 2 + 0])
NumSections++;
SectionIndices[ColorIndex * 2 + 0] += Triangles;
NumIndices += Triangles;
}
int Lines = LCUINT16(*Indices);
Indices += LCUINT16(*Indices) + 1;
if (Lines)
{
if (!SectionIndices[ColorIndex * 2 + 1])
NumSections++;
SectionIndices[ColorIndex * 2 + 1] += Lines;
NumIndices += Lines;
}
info = (lcuint32*)Indices;
}
}
}
else if ((*info == LC_STUD) || (*info == LC_STUD3))
{
info++;
int ColorIndex = lcGetColorIndex(LCUINT32(*info));
info += 1 + 12;
NumVertices += (2 * SIDES) + 1;
if (!SectionIndices[ColorIndex * 2 + 0])
NumSections++;
SectionIndices[ColorIndex * 2 + 0] += 9 * SIDES;
NumIndices += 9 * SIDES;
if (!SectionIndices[gEdgeColor * 2 + 1])
NumSections++;
SectionIndices[gEdgeColor * 2 + 1] += 4 * SIDES;
NumIndices += 4 * SIDES;
}
else if ((*info == LC_STUD2) || (*info == LC_STUD4))
{
info++;
int ColorIndex = lcGetColorIndex(LCUINT32(*info));
info += 1 + 12;
NumVertices += 4 * SIDES;
if (!SectionIndices[ColorIndex * 2 + 0])
NumSections++;
SectionIndices[ColorIndex * 2 + 0] += 18 * SIDES;
NumIndices += 18 * SIDES;
if (!SectionIndices[gEdgeColor * 2 + 1])
NumSections++;
SectionIndices[gEdgeColor * 2 + 1] += 8 * SIDES;
NumIndices += 8 * SIDES;
}
}
info++; // should be 0
bytes = (lcuint8*)info;
}
mMesh = new lcMesh();
mMesh->Create(NumSections, NumVertices, NumIndices);
float* OutVertex = (float*)mMesh->mVertexBuffer.mData;
shorts = (lcint16*)(longs + 1);
for (verts = 0; verts < LCUINT32(*longs); verts++)
{
*OutVertex++ = (float)LCINT16(*shorts)*scale;
shorts++;
*OutVertex++ = (float)LCINT16(*shorts)*scale;
shorts++;
*OutVertex++ = (float)LCINT16(*shorts)*scale;
shorts++;
}
if (NumVertices < 0x10000)
BuildMesh<GLushort>(buf, &SectionIndices[0]);
else
BuildMesh<GLuint>(buf, &SectionIndices[0]);
mMesh->UpdateBuffers();
free(buf);
{
FreeInformation();
lcGetPiecesLibrary()->LoadPiece(m_strName);
}
}
void PieceInfo::FreeInformation()

View file

@ -72,9 +72,6 @@ class PieceInfo
void AddRef();
void DeRef();
template<typename DstType>
void BuildMesh(void* Data, int* SectionIndices);
public:
lcMesh* mMesh;

View file

@ -28,7 +28,7 @@
#include "curve.h"
#include "mainwnd.h"
#include "view.h"
#include "library.h"
#include "lc_library.h"
#include "texfont.h"
#include "debug.h"
#include "lc_application.h"
@ -417,7 +417,7 @@ bool Project::FileLoad(lcFile* file, bool bUndo, bool bMerge)
char name[LC_PIECE_NAME_LEN];
Piece* pPiece = new Piece(NULL);
pPiece->FileLoad(*file, name);
PieceInfo* pInfo = lcGetPiecesLibrary()->FindPieceInfo(name);
PieceInfo* pInfo = lcGetPiecesLibrary()->FindPiece(name, true);
if (pInfo)
{
pPiece->SetPieceInfo(pInfo);
@ -453,7 +453,7 @@ bool Project::FileLoad(lcFile* file, bool bUndo, bool bMerge)
file->ReadU8(&step, 1);
file->ReadU8(&group, 1);
PieceInfo* pInfo = lcGetPiecesLibrary()->FindPieceInfo(name);
PieceInfo* pInfo = lcGetPiecesLibrary()->FindPiece(name, true);
if (pInfo != NULL)
{
Piece* pPiece = new Piece(pInfo);
@ -1001,7 +1001,7 @@ void Project::FileReadLDraw(lcFile* file, Matrix* prevmat, int* nOk, int DefColo
char name[LC_PIECE_NAME_LEN];
strcpy(name, tmp);
PieceInfo* pInfo = lcGetPiecesLibrary()->FindPieceInfo(name);
PieceInfo* pInfo = lcGetPiecesLibrary()->FindPiece(name, false);
if (pInfo != NULL)
{
float x, y, z, rot[4];
@ -1050,7 +1050,7 @@ void Project::FileReadLDraw(lcFile* file, Matrix* prevmat, int* nOk, int DefColo
if (read)
{
// Create a placeholder.
PieceInfo* Info = lcGetPiecesLibrary()->CreatePiecePlaceholder(tmp);
PieceInfo* Info = lcGetPiecesLibrary()->CreatePlaceholder(tmp);
float x, y, z, rot[4];
Piece* pPiece = new Piece(Info);
@ -3250,11 +3250,11 @@ void Project::CreateHTMLPieceList(FILE* f, int nStep, bool bImages, const char*
fputs("</tr>\n",f);
PieceInfo* pInfo;
for (int j = 0; j < lcGetPiecesLibrary()->GetPieceCount (); j++)
for (int j = 0; j < lcGetPiecesLibrary()->mPieces.GetSize(); j++)
{
bool Add = false;
memset(PiecesUsed, 0, sizeof(PiecesUsed[0]) * gColorList.GetSize());
pInfo = lcGetPiecesLibrary()->GetPieceInfo(j);
pInfo = lcGetPiecesLibrary()->mPieces[j];
for (Piece* pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext)
{
@ -3853,14 +3853,14 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
break;
}
PiecesLibrary* Library = lcGetPiecesLibrary();
char* PieceTable = new char[Library->GetPieceCount() * LC_PIECE_NAME_LEN];
int* PieceFlags = new int[Library->GetPieceCount()];
lcPiecesLibrary* Library = lcGetPiecesLibrary();
char* PieceTable = new char[Library->mPieces.GetSize() * LC_PIECE_NAME_LEN];
int* PieceFlags = new int[Library->mPieces.GetSize()];
int NumColors = gColorList.GetSize();
char* ColorTable = new char[NumColors * LC_MAX_COLOR_NAME];
memset(PieceTable, 0, Library->GetPieceCount() * LC_PIECE_NAME_LEN);
memset(PieceFlags, 0, Library->GetPieceCount() * sizeof(int));
memset(PieceTable, 0, Library->mPieces.GetSize() * LC_PIECE_NAME_LEN);
memset(PieceFlags, 0, Library->mPieces.GetSize() * sizeof(int));
memset(ColorTable, 0, NumColors * LC_MAX_COLOR_NAME);
enum
@ -3915,11 +3915,11 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
strupr(Src);
PieceInfo* Info = Library->FindPieceInfo(Src);
PieceInfo* Info = Library->FindPiece(Src, false);
if (!Info)
continue;
int Index = Library->GetPieceIndex(Info);
int Index = Library->mPieces.FindIndex(Info);
if (strchr(Flags, 'L'))
{
@ -3986,7 +3986,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
if (FirstPiece != piece)
break;
int Index = Library->GetPieceIndex(Info);
int Index = Library->mPieces.FindIndex(Info);
if (PieceTable[Index * LC_PIECE_NAME_LEN])
{
@ -4031,7 +4031,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
for (Piece* piece = m_pPieces; piece; piece = piece->m_pNext)
{
PieceInfo* Info = piece->mPieceInfo;
int Index = Library->GetPieceIndex(Info);
int Index = Library->mPieces.FindIndex(Info);
if (PieceTable[Index * LC_PIECE_NAME_LEN])
continue;
@ -4066,7 +4066,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
for (Piece* piece = m_pPieces; piece; piece = piece->m_pNext)
{
int Index = Library->GetPieceIndex(piece->mPieceInfo);
int Index = Library->mPieces.FindIndex(piece->mPieceInfo);
float fl[12];
int Color;
@ -4256,7 +4256,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
case LC_FILE_PROPERTIES:
{
PiecesLibrary* Library = lcGetPiecesLibrary();
lcPiecesLibrary* Library = lcGetPiecesLibrary();
LC_PROPERTIESDLG_OPTS opts;
opts.strTitle = m_strTitle;
@ -4265,18 +4265,18 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
strcpy(opts.strComments, m_strComments);
opts.strFilename = m_strPathName;
opts.NumPieces = Library->GetPieceCount();
opts.NumPieces = Library->mPieces.GetSize();
opts.NumColors = gColorList.GetSize();
opts.PieceColorCount = new int[(opts.NumPieces + 1) * (opts.NumColors + 1)];
memset(opts.PieceColorCount, 0, (opts.NumPieces + 1) * (opts.NumColors + 1) * sizeof(opts.PieceColorCount[0]));
opts.PieceNames = new const char*[opts.NumPieces];
for (int i = 0; i < opts.NumPieces; i++)
opts.PieceNames[i] = Library->GetPieceInfo(i)->m_strDescription;
opts.PieceNames[i] = Library->mPieces[i]->m_strDescription;
for (Piece* pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext)
{
int idx = Library->GetPieceIndex(pPiece->mPieceInfo);
int idx = Library->mPieces.FindIndex(pPiece->mPieceInfo);
opts.PieceColorCount[idx * (opts.NumColors + 1) + pPiece->mColorIndex]++;
opts.PieceColorCount[idx * (opts.NumColors + 1) + opts.NumColors]++;
opts.PieceColorCount[opts.NumPieces * (opts.NumColors + 1) + pPiece->mColorIndex]++;
@ -4315,17 +4315,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
case LC_FILE_LIBRARY:
{
lcMemFile file;
FileSave(&file, true);
if (SystemDoDialog(LC_DLG_LIBRARY, NULL))
{
if (lcGetPiecesLibrary()->m_Modified)
{
DeleteContents(true);
FileLoad(&file, true, false);
}
}
SystemDoDialog(LC_DLG_LIBRARY, NULL);
} break;
case LC_FILE_RECENT:
@ -4474,7 +4464,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
char name[LC_PIECE_NAME_LEN];
Piece* pPiece = new Piece(NULL);
pPiece->FileLoad(*file, name);
PieceInfo* pInfo = lcGetPiecesLibrary()->FindPieceInfo(name);
PieceInfo* pInfo = lcGetPiecesLibrary()->FindPiece(name, true);
if (pInfo)
{
pPiece->SetPieceInfo(pInfo);

View file

@ -52,7 +52,6 @@ class PieceInfo;
class Matrix;
class View;
class Image;
class PiecesLibrary;
class TexFont;
// Undo support

View file

@ -10,7 +10,7 @@
#include "project.h"
#include "globals.h"
#include "image.h"
#include "library.h"
#include "lc_library.h"
#include "lc_application.h"
// =============================================================================
@ -129,6 +129,7 @@ void Texture::Unload()
// Load from textures.bin file
void Texture::Load(bool bFilter)
{
/*
char filename[LC_MAXPATH];
lcDiskFile bin;
void* bits;
@ -149,6 +150,7 @@ void Texture::Load(bool bFilter)
FinishLoadImage (bFilter, bits);
free(bits);
*/
}
bool Texture::LoadFromFile (char* strFilename, bool bFilter)

View file

@ -11,7 +11,7 @@
#include "system.h"
#include "pieceinf.h" // TODO: remove
#include "mainwnd.h"
#include "library.h"
#include "lc_library.h"
#include "keyboard.h"
#include "lc_application.h"
@ -96,7 +96,7 @@ static void CheckForUpdates(void* Data)
else
str = "You are using the latest version of LeoCAD.\n";
if (lib > lcGetPiecesLibrary()->GetPieceCount ())
if (lib > lcGetPiecesLibrary()->mPieces.GetSize())
{
str += "There are new pieces available.\n\n";
Update = true;
@ -213,9 +213,9 @@ BOOL CCADApp::InitInstance()
MainFrame->UpdateMenuAccelerators();
// Show something in the piece preview window.
PieceInfo* Info = lcGetPiecesLibrary()->FindPieceInfo("3005");
if (!Info)
Info = lcGetPiecesLibrary()->GetPieceInfo(0);
PieceInfo* Info = lcGetPiecesLibrary()->FindPiece("3005", false);
if (!Info && lcGetPiecesLibrary()->mPieces.GetSize())
Info = lcGetPiecesLibrary()->mPieces[0];
if (Info)
{

View file

@ -9,7 +9,7 @@
#include "pieceinf.h"
#include "globals.h"
#include "system.h"
#include "library.h"
#include "lc_library.h"
#include "lc_application.h"
#ifdef _DEBUG
@ -206,7 +206,7 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
if (Item == NULL)
break;
PiecesLibrary* Lib = lcGetPiecesLibrary();
lcPiecesLibrary* Lib = lcGetPiecesLibrary();
CString CategoryName = m_Tree.GetItemText(Item);
int Index = Lib->FindCategoryIndex((const char*)CategoryName);
@ -214,8 +214,8 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
break;
char Msg[1024];
String Name = Lib->GetCategoryName(Index);
sprintf(Msg, "Are you sure you want to remove the %s category?", Name);
const String& Name = Lib->mCategories[Index].Name;
sprintf(Msg, "Are you sure you want to remove the '%s' category?", Name);
if (SystemDoMessageBox(Msg, LC_MB_YESNO | LC_MB_ICONQUESTION) == LC_YES)
{
@ -234,7 +234,7 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
if (Item == NULL)
break;
PiecesLibrary* Lib = lcGetPiecesLibrary();
lcPiecesLibrary* Lib = lcGetPiecesLibrary();
CString CategoryName = m_Tree.GetItemText(Item);
int Index = Lib->FindCategoryIndex((const char*)CategoryName);
@ -242,12 +242,12 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
break;
LC_CATEGORYDLG_OPTS Opts;
Opts.Name = Lib->GetCategoryName(Index);
Opts.Keywords = Lib->GetCategoryKeywords(Index);
Opts.Name = Lib->mCategories[Index].Name;
Opts.Keywords = Lib->mCategories[Index].Keywords;
if (SystemDoDialog(LC_DLG_EDITCATEGORY, &Opts))
{
String OldName = Lib->GetCategoryName(Index);
String OldName = Lib->mCategories[Index].Name;
Lib->SetCategory(Index, Opts.Name, Opts.Keywords);
}
@ -275,7 +275,7 @@ void CLibraryDlg::UpdateList()
m_List.DeleteAllItems();
m_List.SetRedraw(FALSE);
PiecesLibrary *Lib = lcGetPiecesLibrary();
lcPiecesLibrary *Lib = lcGetPiecesLibrary();
HTREEITEM CategoryItem = m_Tree.GetSelectedItem();
CString CategoryName = m_Tree.GetItemText(CategoryItem);
@ -307,18 +307,18 @@ void CLibraryDlg::UpdateList()
if (CategoryName == "Unassigned")
{
// Test each piece against all categories.
for (int i = 0; i < Lib->GetPieceCount(); i++)
for (int i = 0; i < Lib->mPieces.GetSize(); i++)
{
PieceInfo* Info = Lib->GetPieceInfo(i);
PieceInfo* Info = Lib->mPieces[i];
int j;
for (j = 0; j < Lib->GetNumCategories(); j++)
for (j = 0; j < Lib->mCategories.GetSize(); j++)
{
if (Lib->PieceInCategory(Info, Lib->GetCategoryKeywords(j)))
if (Lib->PieceInCategory(Info, Lib->mCategories[j].Keywords))
break;
}
if (j == Lib->GetNumCategories())
if (j == Lib->mCategories.GetSize())
{
LVITEM lvi;
lvi.mask = LVIF_TEXT | LVIF_PARAM;
@ -334,9 +334,9 @@ void CLibraryDlg::UpdateList()
}
else if (CategoryName == "Pieces")
{
for (int i = 0; i < Lib->GetPieceCount(); i++)
for (int i = 0; i < Lib->mPieces.GetSize(); i++)
{
PieceInfo* Info = Lib->GetPieceInfo(i);
PieceInfo* Info = Lib->mPieces[i];
LVITEM lvi;
lvi.mask = LVIF_TEXT | LVIF_PARAM;
@ -362,9 +362,9 @@ void CLibraryDlg::UpdateTree()
HTREEITEM Root = m_Tree.InsertItem(TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_TEXT, "Pieces", 0, 1, 0, 0, 0, TVI_ROOT, TVI_SORT);
PiecesLibrary *Lib = lcGetPiecesLibrary();
for (int i = 0; i < Lib->GetNumCategories(); i++)
m_Tree.InsertItem(TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM|TVIF_TEXT, Lib->GetCategoryName(i), 0, 1, 0, 0, 0, Root, TVI_SORT);
lcPiecesLibrary *Lib = lcGetPiecesLibrary();
for (int i = 0; i < Lib->mCategories.GetSize(); i++)
m_Tree.InsertItem(TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM|TVIF_TEXT, Lib->mCategories[i].Name, 0, 1, 0, 0, 0, Root, TVI_SORT);
m_Tree.InsertItem(TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM|TVIF_TEXT, "Unassigned", 0, 1, 0, 0, 0, Root, TVI_LAST);

View file

@ -11,7 +11,7 @@
#include "console.h"
#include "keyboard.h"
#include "system.h"
#include "library.h"
#include "lc_library.h"
#include "lc_application.h"
#include "Print.h"
#include "dynsplit.h"
@ -1052,7 +1052,7 @@ BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam)
if (Item == NULL)
break;
PiecesLibrary* Lib = lcGetPiecesLibrary();
lcPiecesLibrary* Lib = lcGetPiecesLibrary();
CString CategoryName = m_wndPiecesBar.m_PiecesTree.GetItemText(Item);
int Index = Lib->FindCategoryIndex((const char*)CategoryName);
@ -1060,12 +1060,12 @@ BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam)
break;
LC_CATEGORYDLG_OPTS Opts;
Opts.Name = Lib->GetCategoryName(Index);
Opts.Keywords = Lib->GetCategoryKeywords(Index);
Opts.Name = Lib->mCategories[Index].Name;
Opts.Keywords = Lib->mCategories[Index].Keywords;
if (SystemDoDialog(LC_DLG_EDITCATEGORY, &Opts))
{
String OldName = Lib->GetCategoryName(Index);
String OldName = Lib->mCategories[Index].Name;
Lib->SetCategory(Index, Opts.Name, Opts.Keywords);
m_wndPiecesBar.UpdatePiecesTree(OldName, Opts.Name);
}
@ -1080,7 +1080,7 @@ BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam)
if (SystemDoDialog(LC_DLG_EDITCATEGORY, &Opts))
{
PiecesLibrary* Lib = lcGetPiecesLibrary();
lcPiecesLibrary* Lib = lcGetPiecesLibrary();
Lib->AddCategory(Opts.Name, Opts.Keywords);
m_wndPiecesBar.UpdatePiecesTree(NULL, Opts.Name);
}
@ -1094,7 +1094,7 @@ BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam)
if (Item == NULL)
break;
PiecesLibrary* Lib = lcGetPiecesLibrary();
lcPiecesLibrary* Lib = lcGetPiecesLibrary();
CString CategoryName = m_wndPiecesBar.m_PiecesTree.GetItemText(Item);
int Index = Lib->FindCategoryIndex((const char*)CategoryName);
@ -1102,8 +1102,8 @@ BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam)
break;
char Msg[1024];
String Name = Lib->GetCategoryName(Index);
sprintf(Msg, "Are you sure you want to remove the %s category?", Name);
const String& Name = Lib->mCategories[Index].Name;
sprintf(Msg, "Are you sure you want to remove the '%s' category?", Name);
if (SystemDoMessageBox(Msg, LC_MB_YESNO | LC_MB_ICONQUESTION) == LC_YES)
{

View file

@ -1,7 +1,7 @@
#include "lc_global.h"
#include "resource.h"
#include "piecebar.h"
#include "library.h"
#include "lc_library.h"
#include "pieceinf.h"
#include "project.h"
#include "globals.h"
@ -204,7 +204,7 @@ void CPiecesBar::OnContextMenu(CWnd* pWnd, CPoint point)
if (Item != NULL)
{
PiecesLibrary *Lib = lcGetPiecesLibrary();
lcPiecesLibrary *Lib = lcGetPiecesLibrary();
CString CategoryName = m_PiecesTree.GetItemText(Item);
int CategoryIndex = Lib->FindCategoryIndex((const char*)CategoryName);
@ -259,7 +259,7 @@ void CPiecesBar::SelectPiece(const char* Category, PieceInfo* Info)
strcpy(ParentName, Info->m_strName);
*strchr(ParentName, 'P') = '\0';
Parent = lcGetPiecesLibrary()->FindPieceInfo(ParentName);
Parent = lcGetPiecesLibrary()->FindPiece(ParentName, false);
if (Parent)
{
@ -367,7 +367,7 @@ void CPiecesBar::UpdatePiecesTree(const char* OldCategory, const char* NewCatego
void CPiecesBar::UpdatePiecesTree(bool SearchOnly)
{
PiecesLibrary *Lib = lcGetPiecesLibrary();
lcPiecesLibrary *Lib = lcGetPiecesLibrary();
if (SearchOnly)
{
@ -413,12 +413,12 @@ void CPiecesBar::UpdatePiecesTree(bool SearchOnly)
Insert.item.mask = TVIF_CHILDREN|TVIF_PARAM|TVIF_TEXT;
Insert.item.cChildren = 1;
for (int i = 0; i < Lib->GetNumCategories(); i++)
for (int i = 0; i < Lib->mCategories.GetSize(); i++)
{
if (Lib->GetCategoryName(i) == "Search Results")
if (Lib->mCategories[i].Name == "Search Results")
continue;
Insert.item.pszText = (LPSTR)Lib->GetCategoryName(i);
Insert.item.pszText = (LPSTR)Lib->mCategories[i].Name;
m_PiecesTree.InsertItem(&Insert);
}
@ -495,7 +495,7 @@ BOOL CPiecesBar::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
m_PiecesTree.SetRedraw(FALSE);
PiecesLibrary *Lib = lcGetPiecesLibrary();
lcPiecesLibrary* Lib = lcGetPiecesLibrary();
// Remove all children.
HTREEITEM Item = Notify->itemNew.hItem;
@ -590,7 +590,7 @@ BOOL CPiecesBar::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
if (CategoryIndex != -1)
{
if (!Lib->PieceInCategory(Info, Lib->GetCategoryKeywords(CategoryIndex)))
if (!Lib->PieceInCategory(Info, Lib->mCategories[CategoryIndex].Keywords))
continue;
}

View file

@ -5,7 +5,7 @@
#include "pieceinf.h"
#include "project.h"
#include "globals.h"
#include "library.h"
#include "lc_library.h"
#include "lc_application.h"
#ifdef _DEBUG
@ -43,7 +43,7 @@ void CPiecesCombo::OnEditupdate()
return;
char str[66];
PiecesLibrary *pLib = lcGetPiecesLibrary();
lcPiecesLibrary *pLib = lcGetPiecesLibrary();
CPiecesBar* pBar = (CPiecesBar*)GetParent();
PieceInfo* pInfo;
@ -52,9 +52,9 @@ void CPiecesCombo::OnEditupdate()
char newstr[66];
int sel = -1;
strcpy (newstr, "Z");
for (int i = 0; i < pLib->GetPieceCount(); i++)
for (int i = 0; i < pLib->mPieces.GetSize(); i++)
{
pInfo = pLib->GetPieceInfo(i);
pInfo = pLib->mPieces[i];
if ((pInfo->m_strDescription[0] == '~') && !pBar->m_bSubParts)
continue;
@ -79,9 +79,9 @@ void CPiecesCombo::OnEditupdate()
}
if (sel >= 0)
SelectPiece(pLib->GetPieceInfo(sel));
SelectPiece(pLib->mPieces[sel]);
if (strlen (newstr) > 1)
if (strlen(newstr) > 1)
{
SetWindowText(newstr);
SetEditSel(n, -1);
@ -103,7 +103,7 @@ BOOL CPiecesCombo::PreTranslateMessage(MSG* pMsg)
}
else if (nVirtKey == VK_RETURN)
{
PiecesLibrary* Lib = lcGetPiecesLibrary();
lcPiecesLibrary* Lib = lcGetPiecesLibrary();
CString str;
GetWindowText(str);
@ -124,14 +124,14 @@ void CPiecesCombo::OnSelchange()
{
char str[66];
CPiecesBar* pBar = (CPiecesBar*)GetParent();
PiecesLibrary *pLib = lcGetPiecesLibrary();
lcPiecesLibrary* pLib = lcGetPiecesLibrary();
if (!GetLBText (GetCurSel(), str))
return;
for (int i = 0; i < pLib->GetPieceCount(); i++)
for (int i = 0; i < pLib->mPieces.GetSize(); i++)
{
PieceInfo* pInfo = pLib->GetPieceInfo(i);
PieceInfo* pInfo = pLib->mPieces[i];
if (strcmp(str, pInfo->m_strDescription) == 0)
SelectPiece(pInfo);
@ -140,11 +140,11 @@ void CPiecesCombo::OnSelchange()
void CPiecesCombo::SelectPiece(PieceInfo* Info)
{
PiecesLibrary *Lib = lcGetPiecesLibrary();
lcPiecesLibrary* Lib = lcGetPiecesLibrary();
CPiecesBar* Bar = (CPiecesBar*)GetParent();
int Index = Lib->GetFirstCategory(Info);
int Index = Lib->GetFirstPieceCategory(Info);
if (Index != -1)
Bar->SelectPiece(Lib->GetCategoryName(Index), Info);
Bar->SelectPiece(Lib->mCategories[Index].Name, Info);
}

View file

@ -8,7 +8,7 @@
#include "CADView.h"
#include "Tools.h"
#include "Piece.h"
#include "library.h"
#include "lc_library.h"
#include "lc_application.h"
// TODO: rewrite everything
@ -17,11 +17,11 @@ static void PrintCatalogThread (CWnd* pParent, CFrameWndEx* pMainFrame)
{
CCADView* pView = (CCADView*)pMainFrame->GetActiveView();
CPrintDialog* PD = new CPrintDialog(FALSE, PD_ALLPAGES|PD_USEDEVMODECOPIES|PD_NOSELECTION|PD_ENABLEPRINTHOOK, pParent);
PiecesLibrary *pLib = lcGetPiecesLibrary();
lcPiecesLibrary *pLib = lcGetPiecesLibrary();
int bricks = 0;
for (int j = 0; j < pLib->GetPieceCount (); j++)
if (pLib->GetPieceInfo(j)->m_strDescription[0] != '~')
for (int j = 0; j < pLib->mPieces.GetSize(); j++)
if (pLib->mPieces[j]->m_strDescription[0] != '~')
bricks++;
int rows = theApp.GetProfileInt("Default", "Catalog Rows", 10);
int cols = theApp.GetProfileInt("Default", "Catalog Columns", 3);
@ -203,9 +203,9 @@ static void PrintCatalogThread (CWnd* pParent, CFrameWndEx* pMainFrame)
start.next = NULL;
for (int j = 0; j < pLib->GetPieceCount (); j++)
for (int j = 0; j < pLib->mPieces.GetSize(); j++)
{
char* desc = pLib->GetPieceInfo(j)->m_strDescription;
char* desc = pLib->mPieces[j]->m_strDescription;
if (desc[0] != '~')
continue;
@ -287,7 +287,7 @@ static void PrintCatalogThread (CWnd* pParent, CFrameWndEx* pMainFrame)
// dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_DOCNAME, node->name);
node = node->next;
PieceInfo* pInfo = pLib->GetPieceInfo(node->actual);
PieceInfo* pInfo = pLib->mPieces[node->actual];
pInfo->ZoomExtents(30.0f, (float)aspect);
float pos[4] = { 0, 0, 10, 0 };
@ -407,11 +407,11 @@ static void PrintPiecesThread(void* pv)
CFrameWndEx* pFrame = (CFrameWndEx*)pv;
CView* pView = pFrame->GetActiveView();
CPrintDialog* PD = new CPrintDialog(FALSE, PD_ALLPAGES|PD_USEDEVMODECOPIES|PD_NOPAGENUMS|PD_NOSELECTION, pFrame);
PiecesLibrary *pLib = lcGetPiecesLibrary();
lcPiecesLibrary *pLib = lcGetPiecesLibrary();
Project* project = lcGetActiveProject();
int NumColors = gColorList.GetSize();
int NumPieces = pLib->GetPieceCount();
int NumPieces = pLib->mPieces.GetSize();
lcuint32* PiecesUsed = new lcuint32[NumPieces * NumColors];
memset(PiecesUsed, 0, NumPieces * NumColors * sizeof(lcuint32));
@ -420,7 +420,7 @@ static void PrintPiecesThread(void* pv)
for (Piece* tmp = project->m_pPieces; tmp; tmp = tmp->m_pNext)
{
int idx = pLib->GetPieceIndex(tmp->mPieceInfo);
int idx = pLib->mPieces.FindIndex(tmp->mPieceInfo);
PiecesUsed[(idx * NumColors) + tmp->mColorIndex]++;
ColorsUsed[tmp->mColorIndex]++;
}
@ -586,7 +586,7 @@ static void PrintPiecesThread(void* pv)
for (j = 0; j < NumPieces; j++)
{
char* desc = pLib->GetPieceInfo(j)->m_strDescription;
char* desc = pLib->mPieces[j]->m_strDescription;
if (desc[0] == '~')
continue;
@ -679,7 +679,7 @@ static void PrintPiecesThread(void* pv)
lcSetColor(project->m_nCurColor);
PieceInfo* pInfo = pLib->GetPieceInfo(node->actual);
PieceInfo* pInfo = pLib->mPieces[node->actual];
node = node->next;
pInfo->ZoomExtents(30.0f, (float)aspect);
@ -701,7 +701,7 @@ static void PrintPiecesThread(void* pv)
int rowtotal = 0;
char tmp[5];
int idx = (pLib->GetPieceIndex (pInfo));
int idx = (pLib->mPieces.FindIndex(pInfo));
for (i = 0; i < NumColors; i++)
if (PiecesUsed[(idx*NumColors)+i])
{

View file

@ -186,7 +186,6 @@
<ClCompile Include="..\common\lc_application.cpp" />
<ClCompile Include="..\common\lc_colors.cpp" />
<ClCompile Include="..\common\lc_file.cpp" />
<ClCompile Include="..\common\library.cpp" />
<ClCompile Include="..\Common\light.cpp" />
<ClCompile Include="..\common\mainwnd.cpp" />
<ClCompile Include="..\Common\matrix.cpp" />
@ -384,7 +383,6 @@
<ClInclude Include="..\Common\image.h" />
<ClInclude Include="..\common\keyboard.h" />
<ClInclude Include="..\common\lc_application.h" />
<ClInclude Include="..\common\library.h" />
<ClInclude Include="..\Common\light.h" />
<ClInclude Include="..\common\mainwnd.h" />
<ClInclude Include="..\Common\matrix.h" />

View file

@ -206,9 +206,6 @@
<ClCompile Include="..\common\lc_application.cpp">
<Filter>Common Source Files</Filter>
</ClCompile>
<ClCompile Include="..\common\library.cpp">
<Filter>Common Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Common\light.cpp">
<Filter>Common Source Files</Filter>
</ClCompile>
@ -744,9 +741,6 @@
<ClInclude Include="..\common\lc_application.h">
<Filter>Common Header Files</Filter>
</ClInclude>
<ClInclude Include="..\common\library.h">
<Filter>Common Header Files</Filter>
</ClInclude>
<ClInclude Include="..\Common\light.h">
<Filter>Common Header Files</Filter>
</ClInclude>