summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorleo2002-04-12 21:59:52 +0000
committerleo2002-04-12 21:59:52 +0000
commit092422eb279bf9419831d04ed438bb4978a37573 (patch)
tree9779f5c317f6cbed54d906178890c2d0c9ef5423
parent525807c7290c8979dcdca3b210a14218c4edd8f1 (diff)
Moved Pieces Library functions to a new class.
git-svn-id: http://svn.leocad.org/trunk@291 c7d43263-9d01-0410-8a33-9dba5d9f93d6
-rw-r--r--win/Leocad.cpp8
-rw-r--r--win/Libdlg.cpp15
-rw-r--r--win/Print.cpp29
3 files changed, 29 insertions, 23 deletions
diff --git a/win/Leocad.cpp b/win/Leocad.cpp
index 819a168..c5601db 100644
--- a/win/Leocad.cpp
+++ b/win/Leocad.cpp
@@ -14,6 +14,7 @@
#include "pieceinf.h" // TODO: remove
#include "config.h"
#include "mainwnd.h"
+#include "library.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@@ -180,9 +181,10 @@ BOOL CCADApp::InitInstance()
else
ar >> dw;
- for (int j = 0; j < project->GetPieceLibraryCount(); j++)
+ PiecesLibrary *pLib = project->GetPiecesLibrary ();
+ for (int j = 0; j < pLib->GetPieceCount (); j++)
{
- PieceInfo* pInfo = project->GetPieceInfo(j);
+ PieceInfo* pInfo = pLib->GetPieceInfo (j);
if (strcmp (pInfo->m_strName, name) == 0)
{
@@ -310,7 +312,7 @@ void CCADApp::OnHelpUpdates()
else
str = "You are using the latest version of the program.\n";
- if (lib > project->GetPieceLibraryCount())
+ if (lib > project->GetPiecesLibrary ()->GetPieceCount ())
str += "There's an updated piece library.";
else
str += "There are no new pieces.";
diff --git a/win/Libdlg.cpp b/win/Libdlg.cpp
index 0c9a0a3..107d0a4 100644
--- a/win/Libdlg.cpp
+++ b/win/Libdlg.cpp
@@ -118,19 +118,20 @@ BOOL CLibraryDlg::OnInitDialog()
FileDisk idx;
char filename[LC_MAXPATH];
+ PiecesLibrary *pLib = project->GetPiecesLibrary ();
// Read the piece library index.
- strcpy(filename, project->GetLibraryPath());
+ 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(project->GetPieceLibraryCount());
- for (int i = 0; i < project->GetPieceLibraryCount(); i++)
+ m_Parts.SetSize(pLib->GetPieceCount ());
+ for (int i = 0; i < pLib->GetPieceCount (); i++)
{
PARTGROUPINFO* inf = &m_Parts[i];
- inf->info = project->GetPieceInfo(i);
+ inf->info = pLib->GetPieceInfo(i);
inf->group = inf->info->m_nGroups;
idx.Seek(85, SEEK_CUR);
@@ -324,7 +325,7 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
if (ReadLDrawPiece(str, &piece))
{
- if (project->FindPieceInfo(piece.name) != NULL)
+ if (project->GetPiecesLibrary ()->FindPieceInfo (piece.name) != NULL)
AfxMessageBox("Piece already exists in the library !", MB_OK|MB_ICONINFORMATION);
if (SaveLDrawPiece(&piece))
@@ -622,7 +623,7 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
DeletePiece(names, sel);
free(names);
- CString str = project->GetLibraryPath();
+ CString str = project->GetPiecesLibrary ()->GetLibraryPath();
FileDisk newidx;
if (!newidx.Open(str + "pieces.idx", "rb"))
{
@@ -641,7 +642,7 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
for (i = 0; i < count; i++)
{
PARTGROUPINFO* inf = &m_Parts[i];
- inf->info = project->GetPieceInfo(i);
+ inf->info = project->GetPiecesLibrary ()->GetPieceInfo(i);
inf->group = inf->info->m_nGroups;
newidx.Seek(85, SEEK_CUR);
diff --git a/win/Print.cpp b/win/Print.cpp
index 03a3753..122bd92 100644
--- a/win/Print.cpp
+++ b/win/Print.cpp
@@ -12,15 +12,17 @@
#include "CADView.h"
#include "Tools.h"
#include "Piece.h"
+#include "library.h"
static void PrintCatalogThread (CWnd* pParent, CFrameWnd* pMainFrame)
{
CCADView* pView = (CCADView*)pMainFrame->GetActiveView();
CPrintDialog* PD = new CPrintDialog(FALSE, PD_ALLPAGES|PD_USEDEVMODECOPIES|PD_NOSELECTION|PD_ENABLEPRINTHOOK, pParent);
+ PiecesLibrary *pLib = project->GetPiecesLibrary ();
int bricks = 0;
- for (int j = 0; j < project->GetPieceLibraryCount(); j++)
- if (project->GetPieceInfo(j)->m_strDescription[0] != '~')
+ for (int j = 0; j < pLib->GetPieceCount (); j++)
+ if (pLib->GetPieceInfo(j)->m_strDescription[0] != '~')
bricks++;
int rows = theApp.GetProfileInt("Default", "Catalog Rows", 10);
int cols = theApp.GetProfileInt("Default", "Catalog Columns", 3);
@@ -201,9 +203,9 @@ static void PrintCatalogThread (CWnd* pParent, CFrameWnd* pMainFrame)
start.next = NULL;
- for (j = 0; j < project->GetPieceLibraryCount(); j++)
+ for (j = 0; j < pLib->GetPieceCount (); j++)
{
- char* desc = project->GetPieceInfo(j)->m_strDescription;
+ char* desc = pLib->GetPieceInfo(j)->m_strDescription;
if (desc[0] != '~')
continue;
@@ -290,7 +292,7 @@ static void PrintCatalogThread (CWnd* pParent, CFrameWnd* pMainFrame)
// dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_DOCNAME, node->name);
node = node->next;
- PieceInfo* pInfo = project->GetPieceInfo(node->actual);
+ PieceInfo* pInfo = pLib->GetPieceInfo(node->actual);
pInfo->ZoomExtents();
float pos[4] = { 0, 0, 10, 0 };
@@ -409,21 +411,22 @@ static void PrintPiecesThread(void* pv)
CFrameWnd* pFrame = (CFrameWnd*)pv;
CView* pView = pFrame->GetActiveView();
CPrintDialog* PD = new CPrintDialog(FALSE, PD_ALLPAGES|PD_USEDEVMODECOPIES|PD_NOPAGENUMS|PD_NOSELECTION, pFrame);
+ PiecesLibrary *pLib = project->GetPiecesLibrary ();
- UINT *pieces = (UINT*)malloc(project->GetPieceLibraryCount()*28*sizeof(UINT));
+ UINT *pieces = (UINT*)malloc(pLib->GetPieceCount ()*28*sizeof(UINT));
int col[28];
- memset (pieces, 0, project->GetPieceLibraryCount()*28*sizeof(UINT));
+ memset (pieces, 0, pLib->GetPieceCount ()*28*sizeof(UINT));
memset (&col, 0, sizeof (col));
for (Piece* tmp = project->m_pPieces; tmp; tmp = tmp->m_pNext)
{
- int idx = (((char*)tmp->GetPieceInfo() - (char*)project->m_pPieceIdx)/sizeof(PieceInfo));
+ int idx = pLib->GetPieceIndex (tmp->GetPieceInfo ());
pieces[(idx*28)+tmp->GetColor()]++;
col[tmp->GetColor()]++;
}
int rows = 0, cols = 1, i, j;
- for (i = 0; i < project->GetPieceLibraryCount(); i++)
+ for (i = 0; i < pLib->GetPieceCount (); i++)
for (j = 0; j < 28; j++)
if (pieces[(i*28)+j] > 0)
{
@@ -580,9 +583,9 @@ static void PrintPiecesThread(void* pv)
} start, *node, *previous, *news;
start.next = NULL;
- for (j = 0; j < project->GetPieceLibraryCount(); j++)
+ for (j = 0; j < pLib->GetPieceCount (); j++)
{
- char* desc = project->GetPieceInfo(j)->m_strDescription;
+ char* desc = pLib->GetPieceInfo(j)->m_strDescription;
if (desc[0] == '~')
continue;
@@ -680,7 +683,7 @@ static void PrintPiecesThread(void* pv)
glColor3ubv(FlatColorArray[project->m_nCurColor]);
- PieceInfo* pInfo = project->GetPieceInfo(node->actual);
+ PieceInfo* pInfo = pLib->GetPieceInfo(node->actual);
node = node->next;
pInfo->ZoomExtents();
@@ -702,7 +705,7 @@ static void PrintPiecesThread(void* pv)
int rowtotal = 0;
char tmp[5];
- int idx = (((char*)pInfo - (char*)project->m_pPieceIdx)/sizeof(PieceInfo));
+ int idx = (pLib->GetPieceIndex (pInfo));
for (i = 0; i < 28; i++)
if (pieces[(idx*28)+i])
{