summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorleo2001-02-05 19:24:26 +0000
committerleo2001-02-05 19:24:26 +0000
commitf05b91ce8863e8066fed7d40603cd7b76ecd8785 (patch)
tree661bb71928c2fb2a0a9bd1ff5c50af6c59debc5d /common
parent84334fa7786709203afbe17cd781bccd81313681 (diff)
Use the lc*** integer types to load binary files.
git-svn-id: http://svn.leocad.org/trunk@244 c7d43263-9d01-0410-8a33-9dba5d9f93d6
Diffstat (limited to 'common')
-rw-r--r--common/pieceinf.cpp95
-rw-r--r--common/pieceinf.h8
-rw-r--r--common/project.cpp287
3 files changed, 208 insertions, 182 deletions
diff --git a/common/pieceinf.cpp b/common/pieceinf.cpp
index d8d02b3..2e02e1a 100644
--- a/common/pieceinf.cpp
+++ b/common/pieceinf.cpp
@@ -175,63 +175,68 @@ unsigned char ConvertColor(int c)
/////////////////////////////////////////////////////////////////////////////
// PieceInfo construction/destruction
-PieceInfo::PieceInfo()
+PieceInfo::PieceInfo (File& file)
{
- // Not called, initialize in LoadIndex().
+ LoadIndex (file);
}
-PieceInfo::~PieceInfo()
+PieceInfo::~PieceInfo ()
{
- FreeInformation();
+ FreeInformation ();
}
/////////////////////////////////////////////////////////////////////////////
// File I/O
-void PieceInfo::LoadIndex(File* file)
+void PieceInfo::LoadIndex (File& file)
{
- short sh[6];
- short scale;
+ static bool init = false;
+ short sh[6];
+ short scale;
- static bool init = false;
- if (!init)
- {
- for (int i = 0; i < SIDES; i++)
- {
- sintbl[i] = (float)sin((PI2*i)/(SIDES));
- costbl[i] = (float)cos((PI2*i)/(SIDES));
- }
- init = true;
- }
+ // Initialize sin/cos table
+ if (!init)
+ {
+ for (int i = 0; i < SIDES; i++)
+ {
+ sintbl[i] = (float)sin((PI2*i)/(SIDES));
+ costbl[i] = (float)cos((PI2*i)/(SIDES));
+ }
+ init = true;
+ }
- // TODO: don't change ref. if we're reloading ?
- m_nRef = 0;
- m_nVertexCount = 0;
- m_fVertexArray = NULL;
- m_nConnectionCount = 0;
- m_pConnections = NULL;
- m_nGroupCount = 0;
- m_pGroups = NULL;
- m_nTextureCount = 0;
- m_pTextures = NULL;
-
- file->Read(m_strName, 8);
- file->Read(m_strDescription, 64);
- file->ReadShort(sh, 6);
- file->ReadByte(&m_nFlags, 1);
- file->ReadLong(&m_nGroups, 1);
- file->ReadLong(&m_nOffset, 1);
- file->ReadLong(&m_nSize, 1);
-
- scale = 100;
- if (m_nFlags & LC_PIECE_MEDIUM) scale = 1000;
- if (m_nFlags & LC_PIECE_SMALL) scale = 10000;
- m_fDimensions[0] = (float)sh[0]/scale;
- m_fDimensions[1] = (float)sh[1]/scale;
- m_fDimensions[2] = (float)sh[2]/scale;
- m_fDimensions[3] = (float)sh[3]/scale;
- m_fDimensions[4] = (float)sh[4]/scale;
- m_fDimensions[5] = (float)sh[5]/scale;
+ // TODO: don't change ref. if we're reloading ?
+ m_nRef = 0;
+ m_nVertexCount = 0;
+ m_fVertexArray = NULL;
+ m_nConnectionCount = 0;
+ m_pConnections = NULL;
+ m_nGroupCount = 0;
+ m_pGroups = NULL;
+ m_nTextureCount = 0;
+ m_pTextures = NULL;
+
+ file.Read (m_strName, 8);
+ file.Read (m_strDescription, 64);
+ file.ReadShort (sh, 6);
+ file.ReadByte (&m_nFlags, 1);
+ file.ReadLong (&m_nGroups, 1);
+ file.ReadLong (&m_nOffset, 1);
+ file.ReadLong (&m_nSize, 1);
+
+ if (m_nFlags & LC_PIECE_SMALL)
+ scale = 10000;
+ else if (m_nFlags & LC_PIECE_MEDIUM)
+ scale = 1000;
+ else
+ scale = 100;
+
+ m_fDimensions[0] = (float)sh[0]/scale;
+ m_fDimensions[1] = (float)sh[1]/scale;
+ m_fDimensions[2] = (float)sh[2]/scale;
+ m_fDimensions[3] = (float)sh[3]/scale;
+ m_fDimensions[4] = (float)sh[4]/scale;
+ m_fDimensions[5] = (float)sh[5]/scale;
}
GLuint PieceInfo::AddRef()
diff --git a/common/pieceinf.h b/common/pieceinf.h
index f0e4db6..afd1ecf 100644
--- a/common/pieceinf.h
+++ b/common/pieceinf.h
@@ -43,9 +43,9 @@ unsigned char ConvertColor(int c);
class PieceInfo
{
-public:
- PieceInfo();
- ~PieceInfo();
+ public:
+ PieceInfo (File& file);
+ ~PieceInfo ();
// Operations
void ZoomExtents();
@@ -54,7 +54,6 @@ public:
void WriteWavefront(FILE* file, unsigned char color, unsigned long* start);
// Implementation
- void LoadIndex(File* file);
GLuint AddRef();
void DeRef();
@@ -82,6 +81,7 @@ protected:
int m_nRef;
GLuint m_nBoxList;
+ void LoadIndex (File& file);
void LoadInformation();
void FreeInformation();
/*
diff --git a/common/project.cpp b/common/project.cpp
index a96ddb2..3b535e3 100644
--- a/common/project.cpp
+++ b/common/project.cpp
@@ -281,13 +281,27 @@ bool Project::Initialize(int argc, char *argv[], char* binpath, char* libpath)
animation = 0;
else if (strcmp (param, "--highlight") == 0)
highlight = true;
- else if ((strcmp (param, "-V") == 0) || (strcmp (param, "--version") == 0))
+ else if ((strcmp (param, "-v") == 0) || (strcmp (param, "--version") == 0))
{
printf ("LeoCAD version "LC_VERSION" for "LC_VERSION_OSNAME"\n");
- printf ("Copyright (c) 1996-2000, BT Software\n");
+ printf ("Copyright (c) 1996-2001, BT Software\n");
+ printf ("Compiled "__DATE__"\n");
+
+#ifdef LC_HAVE_JPEGLIB
+ printf ("With JPEG support\n");
+#else
+ printf ("Without JPEG support\n");
+#endif
+
+#ifdef LC_HAVE_PNGLIB
+ printf ("With PNG support\n");
+#else
+ printf ("Without PNG support\n");
+#endif
+
return false;
}
- else if ((strcmp (param, "-H") == 0) || (strcmp (param, "--help") == 0))
+ else if ((strcmp (param, "-h") == 0) || (strcmp (param, "--help") == 0))
{
}
else
@@ -456,74 +470,63 @@ bool Project::Initialize(int argc, char *argv[], char* binpath, char* libpath)
// Load the piece library
bool Project::LoadPieceLibrary (char *libpath)
{
- FileDisk idx;
- char filename[LC_MAXPATH];
- unsigned char version;
- unsigned short count, movedcount;
- unsigned long binsize;
- PieceInfo* pElements;
- Texture* pTexture;
- int i;
-
- strcpy (m_LibraryPath, libpath);
-
- // Make sure that the path ends with a '/'
- i = strlen(m_LibraryPath)-1;
- if ((m_LibraryPath[i] != '\\') && (m_LibraryPath[i] != '/'))
- strcat(m_LibraryPath, "/");
-
- // Read the piece library index.
- strcpy(filename, m_LibraryPath);
- strcat(filename, "pieces.idx");
+ FileDisk idx;
+ char filename[LC_MAXPATH];
+ lcuint8 version;
+ lcuint16 count, movedcount;
+ lcuint32 binsize;
+ Texture* pTexture;
+ int i;
+
+ strcpy (m_LibraryPath, libpath);
+
+ // Make sure that the path ends with a '/'
+ i = strlen(m_LibraryPath)-1;
+ if ((m_LibraryPath[i] != '\\') && (m_LibraryPath[i] != '/'))
+ strcat(m_LibraryPath, "/");
+
+ // Read the piece library index.
+ strcpy (filename, m_LibraryPath);
+ strcat (filename, "pieces.idx");
+
+ if (!idx.Open (filename, "rb"))
+ return false;
- if (!idx.Open(filename, "rb"))
- return false;
+ idx.Seek (-(long)(2*sizeof(count)+sizeof(binsize)), SEEK_END);
+ idx.ReadShort (&movedcount, 1);
+ idx.ReadLong (&binsize, 1);
+ idx.ReadShort (&count, 1);
+ idx.Seek (32, SEEK_SET);
+ idx.ReadByte (&version, 1);
- idx.Seek(-(long)(2*sizeof(count)+sizeof(binsize)), SEEK_END);
- idx.ReadShort (&movedcount, 1);
- idx.ReadLong (&binsize, 1);
- idx.ReadShort (&count, 1);
- idx.Seek (32, SEEK_SET);
- idx.ReadByte (&version, 1);
-
- if ((version != 3) || (count == 0))
- {
- idx.Close();
- return false;
- }
- idx.Seek(34, SEEK_SET); // skip update byte
-
- // TODO: check .bin file size.
-
- if (m_pPieceIdx != NULL)
- {
- // call the destructors
- for (pElements = m_pPieceIdx; m_nPieceCount--; pElements++)
- pElements->~PieceInfo();
- delete [] m_pPieceIdx;
- }
+ if ((version != 3) || (count == 0))
+ {
+ idx.Close();
+ return false;
+ }
+ idx.Seek (34, SEEK_SET); // skip update byte
- m_pPieceIdx = new PieceInfo[count];
- m_nPieceCount = count;
- memset(m_pPieceIdx, 0, count * sizeof(PieceInfo));
+ // TODO: check .bin file size.
- for (pElements = m_pPieceIdx; count--; pElements++)
- pElements->LoadIndex(&idx);
+ // Load piece indexes
+ delete [] m_pPieceIdx;
+ m_pPieceIdx = new PieceInfo[count] (idx);
+ m_nPieceCount = count;
- // Load moved files reference.
- if (m_pMovedReference != NULL)
- free(m_pMovedReference);
- m_pMovedReference = (char*)malloc(18*movedcount);
- memset(m_pMovedReference, 0, 18*movedcount);
- m_nMovedCount = movedcount;
+ // Load moved files reference.
+ if (m_pMovedReference != NULL)
+ free(m_pMovedReference);
+ m_pMovedReference = (char*)malloc(18*movedcount);
+ memset (m_pMovedReference, 0, 18*movedcount);
+ m_nMovedCount = movedcount;
- for (i = 0; i < movedcount; i++)
- {
- idx.Read(&m_pMovedReference[i*18], 8);
- idx.Read(&m_pMovedReference[i*18+9], 8);
- }
+ for (i = 0; i < movedcount; i++)
+ {
+ idx.Read (&m_pMovedReference[i*18], 8);
+ idx.Read (&m_pMovedReference[i*18+9], 8);
+ }
- idx.Close();
+ idx.Close();
// TODO: Load group configuration here
@@ -534,8 +537,8 @@ bool Project::LoadPieceLibrary (char *libpath)
if (m_pTextures != NULL)
{
// call the destructors
- for (pTexture = m_pTextures; m_nTextureCount--; pTexture++)
- pTexture->~Texture();
+ // for (pTexture = m_pTextures; m_nTextureCount--; pTexture++)
+ // pTexture->~Texture();
delete [] m_pTextures;
m_pTextures = NULL;
@@ -6368,72 +6371,82 @@ void Project::MoveSelectedObjects(float x, float y, float z)
void Project::RotateSelectedObjects(float x, float y, float z)
{
- if (m_nSnap & LC_DRAW_LOCK_X)
- x = 0;
- if (m_nSnap & LC_DRAW_LOCK_Y)
- y = 0;
- if (m_nSnap & LC_DRAW_LOCK_Z)
- z = 0;
+ if (m_nSnap & LC_DRAW_LOCK_X)
+ x = 0;
+ if (m_nSnap & LC_DRAW_LOCK_Y)
+ y = 0;
+ if (m_nSnap & LC_DRAW_LOCK_Z)
+ z = 0;
+
+ if (x == 0 && y == 0 && z == 0)
+ return;
- if (x == 0 && y == 0 && z == 0)
- return;
+ float bs[6] = { 10000, 10000, 10000, -10000, -10000, -10000 };
+ float pos[3], rot[4];
+ int nSel = 0;
+ Piece *pPiece, *pFocus = NULL;
- float bs[6] = { 10000, 10000, 10000, -10000, -10000, -10000 };
- float pos[3], rot[4];
- int nSel = 0;
- Piece* pPiece;
+ for (pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext)
+ if (pPiece->IsSelected())
+ {
+ if (pPiece->IsFocused ())
+ pFocus = pPiece;
+ /*
+ pPiece->GetPosition (pos);
+ if (pos[0] < bs[0]) bs[0] = pos[0];
+ if (pos[1] < bs[1]) bs[1] = pos[1];
+ if (pos[2] < bs[2]) bs[2] = pos[2];
+ if (pos[0] > bs[3]) bs[3] = pos[0];
+ if (pos[1] > bs[4]) bs[4] = pos[1];
+ if (pos[2] > bs[5]) bs[5] = pos[2];
+ */
+ pPiece->CompareBoundingBox (bs);
+ nSel++;
+ }
- for (pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext)
- if (pPiece->IsSelected())
- {
- /*
- pPiece->GetPosition (pos);
- if (pos[0] < bs[0]) bs[0] = pos[0];
- if (pos[1] < bs[1]) bs[1] = pos[1];
- if (pos[2] < bs[2]) bs[2] = pos[2];
- if (pos[0] > bs[3]) bs[3] = pos[0];
- if (pos[1] > bs[4]) bs[4] = pos[1];
- if (pos[2] > bs[5]) bs[5] = pos[2];
- */
- pPiece->CompareBoundingBox (bs);
- nSel++;
- }
+ if (pFocus != NULL)
+ {
+ pFocus->GetPosition (pos);
+ bs[0] = bs[3] = pos[0];
+ bs[1] = bs[4] = pos[1];
+ bs[2] = bs[5] = pos[2];
+ }
- for (pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext)
- {
- if (!pPiece->IsSelected())
- continue;
+ for (pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext)
+ {
+ if (!pPiece->IsSelected())
+ continue;
- pPiece->GetPosition(pos);
- pPiece->GetRotation(rot);
- Matrix m(rot, pos);
-
- if (nSel == 1)
- {
- if (!(m_nSnap & LC_DRAW_LOCK_X))
- m.Rotate(x,1,0,0);
- if (!(m_nSnap & LC_DRAW_LOCK_Y))
- m.Rotate(y,0,1,0);
- if (!(m_nSnap & LC_DRAW_LOCK_Z))
- m.Rotate(z,0,0,1);
- }
- else
- {
- if (!(m_nSnap & LC_DRAW_LOCK_X))
- m.RotateCenter(x,1,0,0,(bs[0]+bs[3])/2,(bs[1]+bs[4])/2,(bs[2]+bs[5])/2);
- if (!(m_nSnap & LC_DRAW_LOCK_Y))
- m.RotateCenter(y,0,1,0,(bs[0]+bs[3])/2,(bs[1]+bs[4])/2,(bs[2]+bs[5])/2);
- if (!(m_nSnap & LC_DRAW_LOCK_Z))
- m.RotateCenter(z,0,0,1,(bs[0]+bs[3])/2,(bs[1]+bs[4])/2,(bs[2]+bs[5])/2);
- m.GetTranslation(pos);
+ pPiece->GetPosition(pos);
+ pPiece->GetRotation(rot);
+ Matrix m(rot, pos);
- // TODO: check if moved
- pPiece->ChangeKey(m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation, m_bAddKeys, pos, LC_PK_POSITION);
- }
+ if (nSel == 1)
+ {
+ if (!(m_nSnap & LC_DRAW_LOCK_X))
+ m.Rotate(x,1,0,0);
+ if (!(m_nSnap & LC_DRAW_LOCK_Y))
+ m.Rotate(y,0,1,0);
+ if (!(m_nSnap & LC_DRAW_LOCK_Z))
+ m.Rotate(z,0,0,1);
+ }
+ else
+ {
+ if (!(m_nSnap & LC_DRAW_LOCK_X))
+ m.RotateCenter(x,1,0,0,(bs[0]+bs[3])/2,(bs[1]+bs[4])/2,(bs[2]+bs[5])/2);
+ if (!(m_nSnap & LC_DRAW_LOCK_Y))
+ m.RotateCenter(y,0,1,0,(bs[0]+bs[3])/2,(bs[1]+bs[4])/2,(bs[2]+bs[5])/2);
+ if (!(m_nSnap & LC_DRAW_LOCK_Z))
+ m.RotateCenter(z,0,0,1,(bs[0]+bs[3])/2,(bs[1]+bs[4])/2,(bs[2]+bs[5])/2);
+ m.GetTranslation(pos);
+
+ // TODO: check if moved
+ pPiece->ChangeKey(m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation, m_bAddKeys, pos, LC_PK_POSITION);
+ }
- m.ToAxisAngle(rot);
- pPiece->ChangeKey(m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation, m_bAddKeys, rot, LC_PK_ROTATION);
- pPiece->UpdatePosition(m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation);
+ m.ToAxisAngle(rot);
+ pPiece->ChangeKey(m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation, m_bAddKeys, rot, LC_PK_ROTATION);
+ pPiece->UpdatePosition(m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation);
/*
for (POSITION pos2 = m_Pieces.GetHeadPosition(); pos2 != NULL;)
{
@@ -6447,11 +6460,11 @@ void Project::RotateSelectedObjects(float x, float y, float z)
wprintf("No Collision");
}
*/
- }
+ }
- for (pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext)
- if (pPiece->IsSelected())
- pPiece->CalculateConnections(m_pConnections, m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation, false, true);
+ for (pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext)
+ if (pPiece->IsSelected())
+ pPiece->CalculateConnections(m_pConnections, m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation, false, true);
}
bool Project::OnKeyDown(char nKey, bool bControl, bool bShift)
@@ -6843,21 +6856,25 @@ void Project::OnLeftButtonDown(int x, int y, bool bControl, bool bShift)
if (m_nCurAction == LC_ACTION_SELECT)
{
- SelectAndFocusNone(bControl);
-
if (ClickLine.pClosest != NULL)
+ {
switch (ClickLine.pClosest->GetType ())
{
case LC_OBJECT_PIECE:
{
Piece* pPiece = (Piece*)ClickLine.pClosest;
- pPiece->Select (true, true, false);
Group* pGroup = pPiece->GetTopGroup();
+ bool bFocus = pPiece->IsFocused ();
+
+ SelectAndFocusNone (bControl);
+
+ // if a piece has focus deselect it, otherwise set the focus
+ pPiece->Select (!bFocus, !bFocus, false);
if (pGroup != NULL)
for (pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext)
if (pPiece->GetTopGroup() == pGroup)
- pPiece->Select (true, false, false);
+ pPiece->Select (!bFocus, false, false);
} break;
case LC_OBJECT_CAMERA:
@@ -6865,9 +6882,13 @@ void Project::OnLeftButtonDown(int x, int y, bool bControl, bool bShift)
case LC_OBJECT_LIGHT:
case LC_OBJECT_LIGHT_TARGET:
{
+ SelectAndFocusNone (bControl);
ClickLine.pClosest->Select (true, true, bControl);
} break;
}
+ }
+ else
+ SelectAndFocusNone (bControl);
UpdateSelection();
UpdateAllViews();