Deleted unused files.

This commit is contained in:
Leonardo Zide
2017-01-14 17:56:48 -08:00
parent 84cac517bb
commit e3f5be649e
8 changed files with 0 additions and 3631 deletions
-43
View File
@@ -1,43 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <time.h>
static void Abort (char *fmt,...)
{
va_list args;
va_start (args, fmt);
vfprintf (stderr, fmt, args);
va_end (args);
exit (1);
}
int main (int argc, char **argv)
{
FILE *inFile;
FILE *outFile = stdout;
time_t now = time (NULL);
int ch, i;
if (argc != 2)
Abort ("Usage: %s bin-file [> result]", argv[0]);
if ((inFile = fopen(argv[1],"rb")) == NULL)
Abort ("Cannot open %s\n", argv[1]);
fprintf (outFile,
"/* data statements for file %s at %.24s */\n"
"/* Generated by BIN2C, G.Vanem 1995 */\n",
argv[1], ctime(&now));
i = 0;
while ((ch = fgetc(inFile)) != EOF)
{
if (i++ % 32 == 0)
fputs ("\n ", outFile);
fprintf (outFile, "0x%02X,", ch);
}
fputc ('\n', outFile);
fclose (inFile);
return (0);
}
-267
View File
@@ -1,267 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
void GeneratePart(const char* ID, const char* Description)
{
const int StudSides = 16;
char FileName[64];
strcpy(FileName, ID);
strcat(FileName, ".DAT");
FILE* output = fopen(FileName, "wt");
fprintf(output, "0 %s\n", Description);
fprintf(output, "0 This file is part of LeoCAD's built-in fallback library and released under GPL2\n", Description);
bool Brick = !strncmp(Description, "Brick ", 6);
bool Plate = !strncmp(Description, "Plate ", 6);
if (Brick || Plate)
{
int StudsX, StudsY;
float MinZ = Brick ? -0.96f : -0.32f;
sscanf(Description + 6, "%d x %d", &StudsY, &StudsX);
int NumVertices = (StudSides * 2 + 1) * StudsX * StudsY + 16;
int NumIndices = ((StudSides * 3) * StudsX * StudsY + 28) * 3 + ((StudSides * 2) * StudsX * StudsY + 24) * 2;
float* VertexBuffer = (float*)malloc(NumVertices * 3 * sizeof(float));
int* IndexBuffer = (int*)malloc(NumIndices * sizeof(int));
float* Verts = VertexBuffer;
int* Indices = IndexBuffer;
const float OutBoxMin[3] = { -0.4f * StudsX, -0.4f * StudsY, MinZ };
const float OutBoxMax[3] = { 0.4f * StudsX, 0.4f * StudsY, 0.0f };
*Verts++ = OutBoxMin[0]; *Verts++ = OutBoxMin[1]; *Verts++ = OutBoxMin[2];
*Verts++ = OutBoxMin[0]; *Verts++ = OutBoxMax[1]; *Verts++ = OutBoxMin[2];
*Verts++ = OutBoxMax[0]; *Verts++ = OutBoxMax[1]; *Verts++ = OutBoxMin[2];
*Verts++ = OutBoxMax[0]; *Verts++ = OutBoxMin[1]; *Verts++ = OutBoxMin[2];
*Verts++ = OutBoxMin[0]; *Verts++ = OutBoxMin[1]; *Verts++ = OutBoxMax[2];
*Verts++ = OutBoxMin[0]; *Verts++ = OutBoxMax[1]; *Verts++ = OutBoxMax[2];
*Verts++ = OutBoxMax[0]; *Verts++ = OutBoxMax[1]; *Verts++ = OutBoxMax[2];
*Verts++ = OutBoxMax[0]; *Verts++ = OutBoxMin[1]; *Verts++ = OutBoxMax[2];
const float InBoxMin[3] = { -0.4f * StudsX + 0.16f, -0.4f * StudsY + 0.16f, MinZ };
const float InBoxMax[3] = { 0.4f * StudsX - 0.16f, 0.4f * StudsY - 0.16f, -0.16f };
*Verts++ = InBoxMin[0]; *Verts++ = InBoxMin[1]; *Verts++ = InBoxMin[2];
*Verts++ = InBoxMin[0]; *Verts++ = InBoxMax[1]; *Verts++ = InBoxMin[2];
*Verts++ = InBoxMax[0]; *Verts++ = InBoxMax[1]; *Verts++ = InBoxMin[2];
*Verts++ = InBoxMax[0]; *Verts++ = InBoxMin[1]; *Verts++ = InBoxMin[2];
*Verts++ = InBoxMin[0]; *Verts++ = InBoxMin[1]; *Verts++ = InBoxMax[2];
*Verts++ = InBoxMin[0]; *Verts++ = InBoxMax[1]; *Verts++ = InBoxMax[2];
*Verts++ = InBoxMax[0]; *Verts++ = InBoxMax[1]; *Verts++ = InBoxMax[2];
*Verts++ = InBoxMax[0]; *Verts++ = InBoxMin[1]; *Verts++ = InBoxMax[2];
for (int x = 0; x < StudsX; x++)
{
for (int y = 0; y < StudsY; y++)
{
const float Center[3] = { ((float)StudsX / 2.0f - x) * 0.8f - 0.4f, ((float)StudsY / 2.0f - y) * 0.8f - 0.4f, 0.0f };
*Verts++ = Center[0]; *Verts++ = Center[1]; *Verts++ = 0.16f;
for (int Step = 0; Step < StudSides; Step++)
{
float s = Center[0] + sinf((float)Step / (float)StudSides * 2 * M_PI) * 0.24f;
float c = Center[1] + cosf((float)Step / (float)StudSides * 2 * M_PI) * 0.24f;
*Verts++ = s; *Verts++ = c; *Verts++ = 0.16f;
*Verts++ = s; *Verts++ = c; *Verts++ = 0.0f;
}
}
}
*Indices++ = 0; *Indices++ = 1; *Indices++ = 8;
*Indices++ = 1; *Indices++ = 8; *Indices++ = 9;
*Indices++ = 2; *Indices++ = 3; *Indices++ = 10;
*Indices++ = 3; *Indices++ = 10; *Indices++ = 11;
*Indices++ = 0; *Indices++ = 8; *Indices++ = 11;
*Indices++ = 0; *Indices++ = 11; *Indices++ = 3;
*Indices++ = 1; *Indices++ = 9; *Indices++ = 10;
*Indices++ = 1; *Indices++ = 10; *Indices++ = 2;
*Indices++ = 7; *Indices++ = 6; *Indices++ = 5;
*Indices++ = 7; *Indices++ = 5; *Indices++ = 4;
*Indices++ = 0; *Indices++ = 1; *Indices++ = 5;
*Indices++ = 0; *Indices++ = 5; *Indices++ = 4;
*Indices++ = 2; *Indices++ = 3; *Indices++ = 7;
*Indices++ = 2; *Indices++ = 7; *Indices++ = 6;
*Indices++ = 0; *Indices++ = 3; *Indices++ = 7;
*Indices++ = 0; *Indices++ = 7; *Indices++ = 4;
*Indices++ = 1; *Indices++ = 2; *Indices++ = 6;
*Indices++ = 1; *Indices++ = 6; *Indices++ = 5;
*Indices++ = 15; *Indices++ = 14; *Indices++ = 13;
*Indices++ = 15; *Indices++ = 13; *Indices++ = 12;
*Indices++ = 8; *Indices++ = 9; *Indices++ = 13;
*Indices++ = 8; *Indices++ = 13; *Indices++ = 12;
*Indices++ = 10; *Indices++ = 11; *Indices++ = 15;
*Indices++ = 10; *Indices++ = 15; *Indices++ = 14;
*Indices++ = 8; *Indices++ = 11; *Indices++ = 15;
*Indices++ = 8; *Indices++ = 15; *Indices++ = 12;
*Indices++ = 9; *Indices++ = 10; *Indices++ = 14;
*Indices++ = 9; *Indices++ = 14; *Indices++ = 13;
for (int x = 0; x < StudsX; x++)
{
for (int y = 0; y < StudsY; y++)
{
int CenterIndex = 16 + (StudSides * 2 + 1) * (x + StudsX * y);
int BaseIndex = CenterIndex + 1;
for (int Step = 0; Step < StudSides; Step++)
{
*Indices++ = CenterIndex;
*Indices++ = BaseIndex + Step * 2;
*Indices++ = BaseIndex + ((Step + 1) % StudSides) * 2;
*Indices++ = BaseIndex + Step * 2;
*Indices++ = BaseIndex + Step * 2 + 1;
*Indices++ = BaseIndex + ((Step + 1) % StudSides) * 2;
*Indices++ = BaseIndex + ((Step + 1) % StudSides) * 2;
*Indices++ = BaseIndex + Step * 2 + 1;
*Indices++ = BaseIndex + ((Step + 1) % StudSides) * 2 + 1;
}
}
}
*Indices++ = 0; *Indices++ = 1; *Indices++ = 1; *Indices++ = 2;
*Indices++ = 2; *Indices++ = 3; *Indices++ = 3; *Indices++ = 0;
*Indices++ = 4; *Indices++ = 5; *Indices++ = 5; *Indices++ = 6;
*Indices++ = 6; *Indices++ = 7; *Indices++ = 7; *Indices++ = 4;
*Indices++ = 0; *Indices++ = 4; *Indices++ = 1; *Indices++ = 5;
*Indices++ = 2; *Indices++ = 6; *Indices++ = 3; *Indices++ = 7;
*Indices++ = 8; *Indices++ = 9; *Indices++ = 9; *Indices++ = 10;
*Indices++ = 10; *Indices++ = 11; *Indices++ = 11; *Indices++ = 8;
*Indices++ = 12; *Indices++ = 13; *Indices++ = 13; *Indices++ = 14;
*Indices++ = 14; *Indices++ = 15; *Indices++ = 15; *Indices++ = 12;
*Indices++ = 8; *Indices++ = 12; *Indices++ = 9; *Indices++ = 13;
*Indices++ = 10; *Indices++ = 14; *Indices++ = 11; *Indices++ = 15;
for (int x = 0; x < StudsX; x++)
{
for (int y = 0; y < StudsY; y++)
{
int BaseIndex = 16 + (StudSides * 2 + 1) * (x + StudsX * y) + 1;
for (int Step = 0; Step < StudSides; Step++)
{
*Indices++ = BaseIndex + Step * 2;
*Indices++ = BaseIndex + ((Step + 1) % StudSides) * 2;
*Indices++ = BaseIndex + Step * 2 + 1;
*Indices++ = BaseIndex + ((Step + 1) % StudSides) * 2 + 1;
}
}
}
const int NumTriangles = ((StudSides * 3) * StudsX * StudsY + 28);
for (int Triangle = 0; Triangle < NumTriangles; Triangle++)
{
float* v1 = VertexBuffer + IndexBuffer[Triangle * 3] * 3;
float* v2 = VertexBuffer + IndexBuffer[Triangle * 3 + 1] * 3;
float* v3 = VertexBuffer + IndexBuffer[Triangle * 3 + 2] * 3;
fprintf(output, " 3 16 %f %f %f %f %f %f %f %f %f\n", v1[0] * 25, -v1[2] * 25, v1[1] * 25, v2[0] * 25, -v2[2] * 25, v2[1] * 25, v3[0] * 25, -v3[2] * 25, v3[1] * 25);
}
const int NumLines = ((StudSides * 2) * StudsX * StudsY + 24);
for (int Line = 0; Line < NumLines; Line++)
{
float* v1 = VertexBuffer + IndexBuffer[NumTriangles * 3 + Line * 2] * 3;
float* v2 = VertexBuffer + IndexBuffer[NumTriangles * 3 + Line * 2 + 1] * 3;
fprintf(output, " 2 24 %f %f %f %f %f %f\n", v1[0] * 25, -v1[2] * 25, v1[1] * 25, v2[0] * 25, -v2[2] * 25, v2[1] * 25);
}
}
fclose(output);
}
int main(int argc, char* argv[])
{
const char* Parts[][2] =
{
{ "3005", "Brick 1 x 1" },
{ "3004", "Brick 1 x 2" },
{ "3622", "Brick 1 x 3" },
{ "3010", "Brick 1 x 4" },
{ "3009", "Brick 1 x 6" },
{ "3008", "Brick 1 x 8" },
{ "6111", "Brick 1 x 10" },
{ "6112", "Brick 1 x 12" },
{ "2465", "Brick 1 x 16" },
{ "3003", "Brick 2 x 2" },
{ "3002", "Brick 2 x 3" },
{ "3001", "Brick 2 x 4" },
{ "2456", "Brick 2 x 6" },
{ "3007", "Brick 2 x 8" },
{ "3006", "Brick 2 x 10" },
{ "2356", "Brick 4 x 6" },
{ "6212", "Brick 4 x 10" },
{ "4202", "Brick 4 x 12" },
{ "30400", "Brick 4 x 18" },
{ "4201", "Brick 8 x 8" },
{ "4204", "Brick 8 x 16" },
{ "733", "Brick 10 x 10" },
{ "3024", "Plate 1 x 1" },
{ "3023", "Plate 1 x 2" },
{ "3623", "Plate 1 x 3" },
{ "3710", "Plate 1 x 4" },
{ "3666", "Plate 1 x 6" },
{ "3460", "Plate 1 x 8" },
{ "4477", "Plate 1 x 10" },
{ "60479", "Plate 1 x 12" },
{ "3022", "Plate 2 x 2" },
{ "3021", "Plate 2 x 3" },
{ "3020", "Plate 2 x 4" },
{ "3795", "Plate 2 x 6" },
{ "3034", "Plate 2 x 8" },
{ "3832", "Plate 2 x 10" },
{ "2445", "Plate 2 x 12" },
{ "91988", "Plate 2 x 14" },
{ "4282", "Plate 2 x 16" },
{ "3031", "Plate 4 x 4" },
{ "3032", "Plate 4 x 6" },
{ "3035", "Plate 4 x 8" },
{ "3030", "Plate 4 x 10" },
{ "3029", "Plate 4 x 12" },
{ "3958", "Plate 6 x 6" },
{ "3036", "Plate 6 x 8" },
{ "3033", "Plate 6 x 10" },
{ "3028", "Plate 6 x 12" },
{ "3456", "Plate 6 x 14" },
{ "3027", "Plate 6 x 16" },
{ "3026", "Plate 6 x 24" },
{ "41539", "Plate 8 x 8" },
{ "728", "Plate 8 x 11" },
{ "92438", "Plate 8 x 16" },
};
for (unsigned int PartIdx = 0; PartIdx < sizeof(Parts) / sizeof(Parts[0]); PartIdx++)
GeneratePart(Parts[PartIdx][0], Parts[PartIdx][1]);
}
-206
View File
@@ -1,206 +0,0 @@
/* zpipe.c: example of proper use of zlib's inflate() and deflate()
Not copyrighted -- provided to the public domain
Version 1.4 11 December 2005 Mark Adler */
/* Version history:
1.0 30 Oct 2004 First version
1.1 8 Nov 2004 Add void casting for unused return values
Use switch statement for inflate() return values
1.2 9 Nov 2004 Add assertions to document zlib guarantees
1.3 6 Apr 2005 Remove incorrect assertion in inf()
1.4 11 Dec 2005 Add hack to avoid MSDOS end-of-line conversions
Avoid some compiler warnings for input and output buffers
*/
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "zlib.h"
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
# include <fcntl.h>
# include <io.h>
# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
#else
# define SET_BINARY_MODE(file)
#endif
#define CHUNK 16384
/* Compress from file source to file dest until EOF on source.
def() returns Z_OK on success, Z_MEM_ERROR if memory could not be
allocated for processing, Z_STREAM_ERROR if an invalid compression
level is supplied, Z_VERSION_ERROR if the version of zlib.h and the
version of the library linked do not match, or Z_ERRNO if there is
an error reading or writing the files. */
int def(FILE *source, FILE *dest, int level)
{
int ret, flush;
unsigned have;
z_stream strm;
unsigned char in[CHUNK];
unsigned char out[CHUNK];
/* allocate deflate state */
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
ret = deflateInit(&strm, level);
if (ret != Z_OK)
return ret;
/* compress until end of file */
do {
strm.avail_in = fread(in, 1, CHUNK, source);
if (ferror(source)) {
(void)deflateEnd(&strm);
return Z_ERRNO;
}
flush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
strm.next_in = in;
/* run deflate() on input until output buffer not full, finish
compression if all of source has been read in */
do {
strm.avail_out = CHUNK;
strm.next_out = out;
ret = deflate(&strm, flush); /* no bad return value */
assert(ret != Z_STREAM_ERROR); /* state not clobbered */
have = CHUNK - strm.avail_out;
if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
(void)deflateEnd(&strm);
return Z_ERRNO;
}
} while (strm.avail_out == 0);
assert(strm.avail_in == 0); /* all input will be used */
/* done when last data in file processed */
} while (flush != Z_FINISH);
assert(ret == Z_STREAM_END); /* stream will be complete */
/* clean up and return */
(void)deflateEnd(&strm);
return Z_OK;
}
/* Decompress from file source to file dest until stream ends or EOF.
inf() returns Z_OK on success, Z_MEM_ERROR if memory could not be
allocated for processing, Z_DATA_ERROR if the deflate data is
invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and
the version of the library linked do not match, or Z_ERRNO if there
is an error reading or writing the files. */
int inf(FILE *source, FILE *dest)
{
int ret;
unsigned have;
z_stream strm;
unsigned char in[CHUNK];
unsigned char out[CHUNK];
/* allocate inflate state */
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.avail_in = 0;
strm.next_in = Z_NULL;
ret = inflateInit(&strm);
if (ret != Z_OK)
return ret;
/* decompress until deflate stream ends or end of file */
do {
strm.avail_in = fread(in, 1, CHUNK, source);
if (ferror(source)) {
(void)inflateEnd(&strm);
return Z_ERRNO;
}
if (strm.avail_in == 0)
break;
strm.next_in = in;
/* run inflate() on input until output buffer not full */
do {
strm.avail_out = CHUNK;
strm.next_out = out;
ret = inflate(&strm, Z_NO_FLUSH);
assert(ret != Z_STREAM_ERROR); /* state not clobbered */
switch (ret) {
case Z_NEED_DICT:
ret = Z_DATA_ERROR; /* and fall through */
case Z_DATA_ERROR:
case Z_MEM_ERROR:
(void)inflateEnd(&strm);
return ret;
}
have = CHUNK - strm.avail_out;
if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
(void)inflateEnd(&strm);
return Z_ERRNO;
}
} while (strm.avail_out == 0);
/* done when inflate() says it's done */
} while (ret != Z_STREAM_END);
/* clean up and return */
(void)inflateEnd(&strm);
return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
}
/* report a zlib or i/o error */
void zerr(int ret)
{
fputs("zpipe: ", stderr);
switch (ret) {
case Z_ERRNO:
if (ferror(stdin))
fputs("error reading stdin\n", stderr);
if (ferror(stdout))
fputs("error writing stdout\n", stderr);
break;
case Z_STREAM_ERROR:
fputs("invalid compression level\n", stderr);
break;
case Z_DATA_ERROR:
fputs("invalid or incomplete deflate data\n", stderr);
break;
case Z_MEM_ERROR:
fputs("out of memory\n", stderr);
break;
case Z_VERSION_ERROR:
fputs("zlib version mismatch!\n", stderr);
}
}
/* compress or decompress from stdin to stdout */
int main(int argc, char **argv)
{
int ret;
/* avoid end-of-line conversions */
SET_BINARY_MODE(stdin);
SET_BINARY_MODE(stdout);
/* do compression if no arguments */
if (argc == 1) {
ret = def(stdin, stdout, Z_DEFAULT_COMPRESSION);
if (ret != Z_OK)
zerr(ret);
return ret;
}
/* do decompression if -d specified */
else if (argc == 2 && strcmp(argv[1], "-d") == 0) {
ret = inf(stdin, stdout);
if (ret != Z_OK)
zerr(ret);
return ret;
}
/* otherwise, report usage */
else {
fputs("zpipe usage: zpipe [-d] < source > dest\n", stderr);
return 1;
}
}
-722
View File
@@ -1,722 +0,0 @@
#include "lc_global.h"
#include "LeoCAD.h"
#include <WindowsX.h>
#include "CADDoc.h"
#include "CADView.h"
#include "Tools.h"
#include "project.h"
#include "globals.h"
#include "system.h"
#include "camera.h"
#include "view.h"
#include "MainFrm.h"
#include "PiecePrv.h"
#include "lc_application.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BOOL GLWindowPreTranslateMessage(GLWindow *wnd, MSG *pMsg);
/////////////////////////////////////////////////////////////////////////////
// CCADView
IMPLEMENT_DYNCREATE(CCADView, CView)
BEGIN_MESSAGE_MAP(CCADView, CView)
//{{AFX_MSG_MAP(CCADView)
ON_WM_CREATE()
ON_WM_DESTROY()
ON_WM_SETCURSOR()
ON_WM_CAPTURECHANGED()
ON_WM_KEYDOWN()
ON_WM_KEYUP()
ON_WM_TIMER()
ON_COMMAND(ID_FILE_PRINT_PREVIEW, OnFilePrintPreview)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_NOTIFY(TBN_DROPDOWN, AFX_IDW_TOOLBAR, OnDropDown)
ON_MESSAGE(WM_LC_SET_STEP, OnSetStep)
ON_MESSAGE(WM_LC_SET_CURSOR, OnChangeCursor)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCADView construction/destruction
CCADView::CCADView()
{
m_hCursor = NULL;
m_pView = NULL;
}
CCADView::~CCADView()
{
}
BOOL CCADView::PreCreateWindow(CREATESTRUCT& cs)
{
#define CUSTOM_CLASSNAME _T("LeoCADOpenGLClass")
cs.style |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
// call base class PreCreateWindow to get the cs.lpszClass filled in with the MFC default class name
if(!CView::PreCreateWindow(cs))
return 0;
// Register the window class if it has not already been registered.
WNDCLASS wndcls;
HINSTANCE hInst = AfxGetInstanceHandle();
// check if our class is registered
if(!(::GetClassInfo(hInst, CUSTOM_CLASSNAME, &wndcls)))
{
// get default MFC class settings
if(::GetClassInfo(hInst, cs.lpszClass, &wndcls))
{
// set our class name
wndcls.lpszClassName = CUSTOM_CLASSNAME;
// change settings for your custom class
wndcls.style |= CS_OWNDC;
wndcls.hbrBackground = NULL;
// register class
if (!AfxRegisterClass(&wndcls))
AfxThrowResourceException();
}
else
AfxThrowResourceException();
}
// set our class name in CREATESTRUCT
cs.lpszClass = CUSTOM_CLASSNAME;
return 1; // we're all set
}
/////////////////////////////////////////////////////////////////////////////
// CCADView drawing
void CCADView::OnDraw(CDC* /*pDC*/)
{
}
/////////////////////////////////////////////////////////////////////////////
// CCADView printing
// Derived to use our version of the toolbar
void CCADView::OnFilePrintPreview()
{
#ifndef SHARED_HANDLERS
AFXPrintPreview(this);
#endif
}
BOOL CCADView::OnPreparePrinting(CPrintInfo* pInfo)
{
pInfo->m_pPD->m_pd.nMinPage = 1;
pInfo->m_pPD->m_pd.hInstance = AfxGetInstanceHandle();
pInfo->m_pPD->m_pd.Flags |= PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_NOSELECTION | PD_ENABLEPRINTHOOK;
pInfo->m_pPD->m_pd.lpfnPrintHook = PrintHookProc;
pInfo->m_pPD->m_pd.lCustData = (LONG)AfxGetMainWnd();
int cols = theApp.GetProfileInt("Default", "Print Columns", 1);
int rows = theApp.GetProfileInt("Default", "Print Rows", 1);
int Max = (lcGetActiveProject()->GetLastStep()/(rows*cols));
if (lcGetActiveProject()->GetLastStep()%(rows*cols) != 0)
Max++;
pInfo->SetMaxPage(Max);
if (pInfo->m_bPreview)
{
CFrameWndEx* pFrame = (CFrameWndEx*)AfxGetMainWnd();
POSITION pos = pFrame->m_listControlBars.GetHeadPosition();
while (pos != NULL)
{
CControlBar* pBar = (CControlBar*)pFrame->m_listControlBars.GetNext(pos);
CString str;
pBar->GetWindowText(str);
if (str == _T("Full Screen"))
{
AfxGetMainWnd()->SendMessage(WM_COMMAND, ID_VIEW_FULLSCREEN);
break;
}
}
}
return DoPreparePrinting(pInfo);
}
void CCADView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* pInfo)
{
int cols = theApp.GetProfileInt("Default", "Print Columns", 1);
int rows = theApp.GetProfileInt("Default", "Print Rows", 1);
int Max = (lcGetActiveProject()->GetLastStep()/(rows*cols));
if (lcGetActiveProject()->GetLastStep()%(rows*cols) != 0)
Max++;
pInfo->SetMaxPage(Max);
}
void CCADView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
int cols = theApp.GetProfileInt("Default","Print Columns", 1);
int rows = theApp.GetProfileInt("Default","Print Rows", 1);
Project* project = lcGetActiveProject();
if (rows < 1) rows = 1;
if (cols < 1) cols = 1;
CRect rc(0, 0, pDC->GetDeviceCaps(HORZRES), pDC->GetDeviceCaps(VERTRES));
pDC->DPtoLP(&rc);
int lpx = pDC->GetDeviceCaps(LOGPIXELSX);
int lpy = pDC->GetDeviceCaps(LOGPIXELSY);
rc.DeflateRect(lpx*theApp.GetProfileInt("Default","Margin Left", 50)/100,
lpy*theApp.GetProfileInt("Default","Margin Top", 50)/100,
lpx*theApp.GetProfileInt("Default","Margin Right", 50)/100,
lpy*theApp.GetProfileInt("Default","Margin Bottom", 50)/100);
int w = rc.Width()/cols, h = rc.Height()/rows; // cell size
float viewaspect = (float)m_pView->GetWidth()/(float)m_pView->GetHeight();
int pw = w, ph = h; // picture
int mx = 0, my = 0; // offset
if (w < h)
{
ph = (int)(w / viewaspect);
my = (h - ph)/2;
}
else
{
pw = (int)(h * viewaspect);
mx = (w - pw)/2;
}
int tw = pw, th = ph; // tile size
if (tw > 1024 || th > 1024)
tw = th = 1024;
HDC hMemDC = CreateCompatibleDC(GetDC()->m_hDC);
LPBITMAPINFOHEADER lpbi;
// Preparing bitmap header for DIB section
BITMAPINFO bi;
ZeroMemory(&bi, sizeof(BITMAPINFO));
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biWidth = tw;
bi.bmiHeader.biHeight = th;
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 24;
bi.bmiHeader.biCompression = BI_RGB;
bi.bmiHeader.biSizeImage = tw * th * 3;
bi.bmiHeader.biXPelsPerMeter = 2925;
bi.bmiHeader.biYPelsPerMeter = 2925;
HBITMAP hBm = CreateDIBSection(hMemDC, &bi, DIB_RGB_COLORS, (void **)&lpbi, NULL, (DWORD)0);
HBITMAP hBmOld = (HBITMAP)SelectObject(hMemDC, hBm);
GL_DisableVertexBufferObject();
View view(project, project->m_ActiveView);
view.SetCamera(project->m_ActiveView->mCamera, false);
view.CreateFromBitmap(hMemDC);
view.MakeCurrent();
view.OnSize(tw, th);
project->AddView(&view);
project->RenderInitialize();
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
lf.lfHeight = -MulDiv(50, pDC->GetDeviceCaps(LOGPIXELSY), 72);
lf.lfWeight = FW_BOLD;
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfQuality = PROOF_QUALITY;
strcpy(lf.lfFaceName , "Arial");
HFONT font = CreateFontIndirect(&lf);
HFONT OldFont = (HFONT)SelectObject(pDC->m_hDC, font);
pDC->SetTextAlign(TA_BASELINE|TA_CENTER|TA_NOUPDATECP);
float* bg = project->GetBackgroundColor();
pDC->SetTextColor(RGB(1.0f - bg[0], 1.0f - bg[1], 1.0f - bg[2]));
pDC->SetBkMode(TRANSPARENT);
HPEN hpOld = (HPEN)SelectObject(pDC->m_hDC,(HPEN)GetStockObject(BLACK_PEN));
unsigned short nOldTime = project->m_bAnimation ? project->m_nCurFrame : project->m_nCurStep;
UINT nRenderTime = 1+((pInfo->m_nCurPage-1)*rows*cols);
for (int r = 0; r < rows; r++)
for (int c = 0; c < cols; c++)
{
if (nRenderTime > project->GetLastStep())
continue;
if (project->m_bAnimation)
project->m_nCurFrame = nRenderTime;
else
project->m_nCurStep = nRenderTime;
project->CalculateStep();
FillRect(hMemDC, CRect(0,th,tw,0), (HBRUSH)GetStockObject(WHITE_BRUSH));
// Tile rendering
if (pw > tw || ph > th)
{
Camera* pCam = view.mCamera;
pCam->StartTiledRendering(tw, th, pw, ph, viewaspect);
do
{
project->Render(&view, true);
glFinish();
int tr, tc, ctw, cth;
pCam->GetTileInfo(&tr, &tc, &ctw, &cth);
lpbi = (LPBITMAPINFOHEADER)GlobalLock(MakeDib(hBm, 24));
BITMAPINFO bi;
ZeroMemory(&bi, sizeof(BITMAPINFO));
memcpy(&bi.bmiHeader, lpbi, sizeof(BITMAPINFOHEADER));
pDC->SetStretchBltMode(COLORONCOLOR);
int y = 0;
if (ph > th && tr != 0)
y = tr * th - (th - ph % th);
StretchDIBits(pDC->m_hDC, rc.left+1+(w*c)+mx + tc*tw, rc.top+1+(h*r)+my + y, ctw, cth, 0, 0, ctw, cth,
(LPBYTE) lpbi + lpbi->biSize + lpbi->biClrUsed * sizeof(RGBQUAD), &bi, DIB_RGB_COLORS, SRCCOPY);
if (lpbi)
GlobalFreePtr(lpbi);
} while (pCam->EndTile());
}
else
{
project->Render(&view, true);
glFinish();
lpbi = (LPBITMAPINFOHEADER)GlobalLock(MakeDib(hBm, 24));
BITMAPINFO bi;
ZeroMemory(&bi, sizeof(BITMAPINFO));
memcpy(&bi.bmiHeader, lpbi, sizeof(BITMAPINFOHEADER));
pDC->SetStretchBltMode(COLORONCOLOR);
StretchDIBits(pDC->m_hDC, rc.left+1+(w*c)+mx, rc.top+1+(h*r)+my, w-(2*mx), h-(2*my), 0, 0, pw, ph,
(LPBYTE) lpbi + lpbi->biSize + lpbi->biClrUsed * sizeof(RGBQUAD), &bi, DIB_RGB_COLORS, SRCCOPY);
if (lpbi)
GlobalFreePtr(lpbi);
}
DWORD dwPrint = theApp.GetProfileInt("Settings","Print", PRINT_NUMBERS|PRINT_BORDER);
if (dwPrint & PRINT_NUMBERS)
{
char tmp[4];
sprintf(tmp, "%d", nRenderTime);
CRect rcNumber(rc);
rcNumber.left += (w*c)+(int)(pDC->GetDeviceCaps(LOGPIXELSX)/2);
rcNumber.top += (h*r)+(int)(pDC->GetDeviceCaps(LOGPIXELSY)/2);
pDC->SetTextAlign(TA_TOP|TA_LEFT|TA_NOUPDATECP);
pDC->DrawText(tmp, strlen(tmp), rcNumber, DT_LEFT|DT_TOP|DT_SINGLELINE);
}
if (dwPrint & PRINT_BORDER)
{
pDC->MoveTo(rc.left+(w*c), rc.top+(h*r));
pDC->LineTo(rc.left+(w*(c+1)), rc.top+(h*r));
pDC->MoveTo(rc.left+(w*c), rc.top+(h*r));
pDC->LineTo(rc.left+(w*c), rc.top+(h*(r+1)));
pDC->MoveTo(rc.left+(w*(c+1)), rc.top+(h*r));
pDC->LineTo(rc.left+(w*(c+1)), rc.top+(h*(r+1)));
pDC->MoveTo(rc.left+(w*c), rc.top+(h*(r+1)));
pDC->LineTo(rc.left+(w*(c+1)), rc.top+(h*(r+1)));
}
nRenderTime++;
}
if (project->m_bAnimation)
project->m_nCurFrame = nOldTime;
else
project->m_nCurStep = (unsigned char)nOldTime;
view.DestroyContext();
SelectObject(hMemDC, hBmOld);
DeleteObject(hBm);
DeleteDC(hMemDC);
GL_EnableVertexBufferObject();
SelectObject(pDC->m_hDC, hpOld);
SelectObject(pDC->m_hDC, OldFont);
DeleteObject(font);
glFinish();
lf.lfHeight = -MulDiv(12, pDC->GetDeviceCaps(LOGPIXELSY), 72);
lf.lfWeight = FW_REGULAR;
font = CreateFontIndirect(&lf);
OldFont = (HFONT)SelectObject(pDC->m_hDC, font);
pDC->SetTextColor(RGB(0,0,0));
pDC->SetTextAlign(TA_TOP|TA_LEFT|TA_NOUPDATECP);
rc.top -= pDC->GetDeviceCaps(LOGPIXELSY)*theApp.GetProfileInt("Default","Margin Top", 50)/200;
rc.bottom += pDC->GetDeviceCaps(LOGPIXELSY)*theApp.GetProfileInt("Default","Margin Bottom", 50)/200;
PrintHeader(FALSE, pDC->GetSafeHdc(), rc, pInfo->m_nCurPage, pInfo->GetMaxPage(), FALSE);
PrintHeader(TRUE, pDC->GetSafeHdc(), rc, pInfo->m_nCurPage, pInfo->GetMaxPage(), FALSE);
SelectObject(pDC->m_hDC, OldFont);
DeleteObject(font);
}
void CCADView::PrintHeader(BOOL bFooter, HDC hDC, CRect rc, UINT nCurPage, UINT nMaxPage, BOOL bCatalog)
{
Project* project = lcGetActiveProject();
CString str,tmp;
UINT nFormat = DT_CENTER;
int r;
if (bFooter)
str = project->m_strFooter;
else
str = project->m_strHeader;
if (str.GetLength())
{
while ((r = str.Find("&L")) != -1)
{
nFormat = DT_LEFT;
tmp = str.Left(r);
tmp += str.Right(str.GetLength()-r-2);
str = tmp;
}
while ((r = str.Find("&C")) != -1)
{
nFormat = DT_CENTER;
tmp = str.Left(r);
tmp += str.Right(str.GetLength()-r-2);
str = tmp;
}
while ((r = str.Find("&R")) != -1)
{
nFormat = DT_RIGHT;
tmp = str.Left(r);
tmp += str.Right(str.GetLength()-r-2);
str = tmp;
}
while ((r = str.Find("&F")) != -1)
{
tmp = str.Left(r);
if (bCatalog)
tmp += "LeoCAD Pieces Catalog";
else
tmp += project->m_strTitle;
tmp += str.Right(str.GetLength()-r-2);
str = tmp;
}
while ((r = str.Find("&A")) != -1)
{
tmp = str.Left(r);
tmp += project->m_strAuthor;
tmp += str.Right(str.GetLength()-r-2);
str = tmp;
}
while ((r = str.Find("&N")) != -1)
{
tmp = str.Left(r);
tmp += project->m_strDescription;
tmp += str.Right(str.GetLength()-r-2);
str = tmp;
}
while ((r = str.Find("&D")) != -1)
{
char dbuffer [9];
_strdate( dbuffer );
tmp = str.Left(r);
tmp += dbuffer;
tmp += str.Right(str.GetLength()-r-2);
str = tmp;
}
while ((r = str.Find("&T")) != -1)
{
char tbuffer [9];
_strtime( tbuffer );
tmp = str.Left(r);
tmp += tbuffer;
tmp += str.Right(str.GetLength()-r-2);
str = tmp;
}
while ((r = str.Find("&P")) != -1)
{
char buf[5];
sprintf(buf, "%d", nCurPage);
tmp = str.Left(r);
tmp += buf;
tmp += str.Right(str.GetLength()-r-2);
str = tmp;
}
while ((r = str.Find("&O")) != -1)
{
char buf[5];
sprintf(buf, "%d", nMaxPage);
tmp = str.Left(r);
tmp += buf;
tmp += str.Right(str.GetLength()-r-2);
str = tmp;
}
}
if (bFooter)
nFormat |= DT_BOTTOM|DT_SINGLELINE;
else
nFormat |= DT_TOP|DT_SINGLELINE;
DrawText(hDC, (LPCTSTR)str, str.GetLength(), rc, nFormat);
}
void CCADView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// pfnwglMakeCurrent(m_pDC->GetSafeHdc(), m_hglRC);
}
/////////////////////////////////////////////////////////////////////////////
// CCADView diagnostics
#ifdef _DEBUG
void CCADView::AssertValid() const
{
CView::AssertValid();
}
void CCADView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCADDoc* CCADView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCADDoc)));
return (CCADDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCADView message handlers
int CCADView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
Project* project = lcGetActiveProject();
m_pView = new View(project, project->m_ActiveView);
if (project->m_ActiveView)
m_pView->SetCamera(project->m_ActiveView->mCamera, false);
else
m_pView->SetDefaultCamera();
m_pView->CreateFromWindow(m_hWnd);
m_pView->OnInitialUpdate();
SetTimer(IDT_LC_SAVETIMER, 5000, NULL);
return 0;
}
void CCADView::OnDestroy()
{
delete m_pView;
m_pView = NULL;
KillTimer(IDT_LC_SAVETIMER);
CView::OnDestroy();
}
void CCADView::OnDropDown(NMHDR* pNotifyStruct, LRESULT* pResult)
{
NMTOOLBAR* pNMToolBar = (NMTOOLBAR*)pNotifyStruct;
RECT rc;
::SendMessage(pNMToolBar->hdr.hwndFrom, TB_GETRECT, (WPARAM)pNMToolBar->iItem, (LPARAM)&rc);
CRect rect(rc);
rect.top = rect.bottom;
::ClientToScreen(pNMToolBar->hdr.hwndFrom, &rect.TopLeft());
if (pNMToolBar->iItem == ID_SNAP_ON)
{
POINT pt = { rect.left, rect.top + 1 };
SystemDoPopupMenu(2, pt.x, pt.y);
}
if (pNMToolBar->iItem == ID_LOCK_ON)
{
POINT pt = { rect.left, rect.top + 1 };
SystemDoPopupMenu(8, pt.x, pt.y);
}
*pResult = TBDDRET_DEFAULT;
}
LONG CCADView::OnChangeCursor(UINT lParam, LONG /*wParam*/)
{
UINT Cursor;
switch (m_pView->GetCursor())
{
case LC_CURSOR_DEFAULT: Cursor = NULL; break;
case LC_CURSOR_BRICK: Cursor = IDC_BRICK; break;
case LC_CURSOR_LIGHT: Cursor = IDC_LIGHT; break;
case LC_CURSOR_SPOTLIGHT: Cursor = IDC_SPOTLIGHT; break;
case LC_CURSOR_CAMERA: Cursor = IDC_CAMERA; break;
case LC_CURSOR_SELECT: Cursor = IDC_SELECT; break;
case LC_CURSOR_SELECT_GROUP: Cursor = IDC_SELECT_GROUP; break;
case LC_CURSOR_MOVE: Cursor = IDC_MOVE; break;
case LC_CURSOR_ROTATE: Cursor = IDC_ROTATE; break;
case LC_CURSOR_ROTATEX: Cursor = IDC_ROTX; break;
case LC_CURSOR_ROTATEY: Cursor = IDC_ROTY; break;
case LC_CURSOR_DELETE: Cursor = IDC_ERASER; break;
case LC_CURSOR_PAINT: Cursor = IDC_PAINT; break;
case LC_CURSOR_ZOOM: Cursor = IDC_ZOOM; break;
case LC_CURSOR_ZOOM_REGION: Cursor = IDC_ZOOM_REGION; break;
case LC_CURSOR_PAN: Cursor = IDC_PAN; break;
case LC_CURSOR_ROLL: Cursor = IDC_ROLL; break;
case LC_CURSOR_ROTATE_VIEW: Cursor = IDC_ANGLE; break;
default:
LC_ASSERT_FALSE("Unknown cursor type.");
}
if (Cursor)
{
m_hCursor = theApp.LoadCursor(Cursor);
SetCursor(m_hCursor);
}
else
m_hCursor = NULL;
return TRUE;
}
BOOL CCADView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if (CView::OnSetCursor(pWnd, nHitTest, message))
return TRUE;
OnChangeCursor(0, 0);
if (m_hCursor)
{
SetCursor(m_hCursor);
return TRUE;
}
return FALSE;
}
void CCADView::OnTimer(UINT nIDEvent)
{
if (nIDEvent == IDT_LC_SAVETIMER)
lcGetActiveProject()->CheckAutoSave();
CView::OnTimer(nIDEvent);
}
// lParam -> new step/frame
LONG CCADView::OnSetStep(UINT lParam, LONG /*wParam*/)
{
if (lParam > 0)
lcGetActiveProject()->HandleCommand(LC_VIEW_STEP_SET, lParam);
return TRUE;
}
void CCADView::OnCaptureChanged(CWnd *pWnd)
{
if (pWnd != this)
lcGetActiveProject()->HandleNotify(LC_CAPTURE_LOST, 0);
CView::OnCaptureChanged(pWnd);
}
void CCADView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
char nKey = nChar;
if (nChar >= VK_NUMPAD0 && nChar <= VK_NUMPAD9)
{
nKey = nChar - VK_NUMPAD0 + '0';
}
// Update cursor for multiple selection.
if (nChar == VK_CONTROL)
{
if (lcGetActiveProject()->GetCurAction() == LC_ACTION_SELECT)
{
POINT pt;
GetCursorPos(&pt);
CRect rc;
GetWindowRect(rc);
if (rc.PtInRect(pt))
OnSetCursor(this, HTCLIENT, 0);
}
}
lcGetActiveProject()->OnKeyDown(nKey, GetKeyState(VK_CONTROL) < 0, GetKeyState(VK_SHIFT) < 0);
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CCADView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// Update cursor for multiple selection.
if (nChar == VK_CONTROL)
{
if (lcGetActiveProject()->GetCurAction() == LC_ACTION_SELECT)
{
POINT pt;
GetCursorPos(&pt);
CRect rc;
GetWindowRect(rc);
if (rc.PtInRect(pt))
OnSetCursor(this, HTCLIENT, 0);
}
}
CView::OnKeyUp(nChar, nRepCnt, nFlags);
}
void CCADView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
// if (pActivateView && pActivateView->IsKindOf(RUNTIME_CLASS(CCADView)))
// lcGetActiveProject()->SetActiveView(((CCADView*)pActivateView)->m_pView);
CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}
LRESULT CCADView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if (m_pView)
{
MSG msg;
msg.message = message;
msg.wParam = wParam;
msg.lParam = lParam;
if (GLWindowPreTranslateMessage(m_pView, &msg))
return TRUE;
}
return CView::WindowProc(message, wParam, lParam);
}
-80
View File
@@ -1,80 +0,0 @@
#ifndef _CADVIEW_H_
#define _CADVIEW_H_
class View;
class CCADDoc;
class CCADView : public CView
{
protected: // create from serialization only
CCADView();
DECLARE_DYNCREATE(CCADView)
// Attributes
public:
CCADDoc* GetDocument();
void PrintHeader(BOOL bFooter, HDC hDC, CRect rc, UINT nCurPage, UINT nMaxPage, BOOL bCatalog);
// Operations
public:
View* GetView() const
{
return m_pView;
}
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCADView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);
virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CCADView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
// Generated message map functions
protected:
HCURSOR m_hCursor;
View* m_pView;
//{{AFX_MSG(CCADView)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnDestroy();
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
afx_msg void OnCaptureChanged(CWnd *pWnd);
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnFilePrintPreview();
//}}AFX_MSG
afx_msg void OnDropDown(NMHDR* pNotifyStruct, LRESULT* pResult);
afx_msg LONG OnSetStep(UINT lParam, LONG wParam);
afx_msg LONG OnChangeCursor(UINT lParam, LONG wParam);
DECLARE_MESSAGE_MAP()
};
#ifndef _DEBUG // debug version in CADView.cpp
inline CCADDoc* CCADView::GetDocument()
{ return (CCADDoc*)m_pDocument; }
#endif
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif // _CADVIEW_H_
-842
View File
@@ -1,842 +0,0 @@
#include "lc_global.h"
#include "leocad.h"
#include <WindowsX.h>
#include "Print.h"
#include "project.h"
#include "pieceinf.h"
#include "globals.h"
#include "CADView.h"
#include "Tools.h"
#include "Piece.h"
#include "lc_library.h"
#include "lc_application.h"
// TODO: rewrite everything
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);
lcPiecesLibrary *pLib = lcGetPiecesLibrary();
int bricks = 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);
PD->m_pd.lpfnPrintHook = PrintHookProc;
PD->m_pd.nFromPage = PD->m_pd.nMinPage = 1;
PD->m_pd.nMaxPage = bricks/(rows*cols);
if (bricks%(rows*cols) != 0) PD->m_pd.nMaxPage++;
PD->m_pd.nToPage = PD->m_pd.nMaxPage;
PD->m_pd.lCustData= (LONG)pMainFrame;
// bring up the print dialog and allow user to change things
if (theApp.DoPrintDialog(PD) != IDOK) return;
if (PD->m_pd.hDC == NULL) return;
// update page range
rows = theApp.GetProfileInt("Default","Catalog Rows", 10);
cols = theApp.GetProfileInt("Default","Catalog Columns", 3);
PD->m_pd.nMaxPage = bricks/(rows*cols);
if (bricks%(rows*cols) != 0) PD->m_pd.nMaxPage++;
// gather file to print to if print-to-file selected
CString strOutput;
if (PD->m_pd.Flags & PD_PRINTTOFILE)
{
// construct CFileDialog for browsing
CString strDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULTEXT));
CString strPrintDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULT));
CString strFilter(MAKEINTRESOURCE(AFX_IDS_PRINTFILTER));
CString strCaption(MAKEINTRESOURCE(AFX_IDS_PRINTCAPTION));
CFileDialog dlg(FALSE, strDef, strPrintDef,
OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, strFilter);
dlg.m_ofn.lpstrTitle = strCaption;
if (dlg.DoModal() != IDOK)
return;
// set output device to resulting path name
strOutput = dlg.GetPathName();
}
DOCINFO docInfo;
memset(&docInfo, 0, sizeof(DOCINFO));
docInfo.cbSize = sizeof(DOCINFO);
docInfo.lpszDocName = "LeoCAD pieces catalog";
CString strPortName;
int nFormatID;
if (strOutput.IsEmpty())
{
docInfo.lpszOutput = NULL;
strPortName = PD->GetPortName();
nFormatID = AFX_IDS_PRINTONPORT;
}
else
{
docInfo.lpszOutput = strOutput;
AfxGetFileTitle(strOutput, strPortName.GetBuffer(_MAX_PATH), _MAX_PATH);
nFormatID = AFX_IDS_PRINTTOFILE;
}
// setup the printing DC
SetAbortProc(PD->m_pd.hDC, _AfxAbortProc);
// disable main window while printing & init printing status dialog
pParent->EnableWindow(FALSE);
CPrintingDialog dlgPrintStatus(NULL);
CString strTemp;
dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_DOCNAME, "LeoCAD parts catalog");
dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PRINTERNAME, PD->GetDeviceName());
AfxFormatString1(strTemp, nFormatID, strPortName);
dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PORTNAME, strTemp);
dlgPrintStatus.ShowWindow(SW_SHOW);
dlgPrintStatus.UpdateWindow();
// start document printing process
if (StartDoc(PD->m_pd.hDC, &docInfo) == SP_ERROR)
{
pParent->EnableWindow(TRUE);
dlgPrintStatus.DestroyWindow();
AfxMessageBox(AFX_IDP_FAILED_TO_START_PRINT);
return;
}
// Guarantee values are in the valid range
UINT nEndPage = PD->m_pd.nToPage;
UINT nStartPage = PD->m_pd.nFromPage;
if (PD->PrintAll())
{
nEndPage = PD->m_pd.nMaxPage;
nStartPage = PD->m_pd.nMinPage;
}
if (nEndPage < PD->m_pd.nMinPage) nEndPage = PD->m_pd.nMinPage;
if (nEndPage > PD->m_pd.nMaxPage) nEndPage = PD->m_pd.nMaxPage;
if (nStartPage < PD->m_pd.nMinPage) nStartPage = PD->m_pd.nMinPage;
if (nStartPage > PD->m_pd.nMaxPage) nStartPage = PD->m_pd.nMaxPage;
int nStep = (nEndPage >= nStartPage) ? 1 : -1;
nEndPage = nEndPage + nStep;
VERIFY(strTemp.LoadString(AFX_IDS_PRINTPAGENUM));
// begin page printing loop
BOOL bError = FALSE;
// set up drawing rect to entire page (in logical coordinates)
CRect rectDraw (0, 0, GetDeviceCaps(PD->m_pd.hDC, HORZRES), GetDeviceCaps(PD->m_pd.hDC, VERTRES));
DPtoLP(PD->m_pd.hDC, (LPPOINT)(RECT*)&rectDraw, 2);
rectDraw.DeflateRect(
GetDeviceCaps(PD->m_pd.hDC, LOGPIXELSX)*theApp.GetProfileInt("Default","Margin Left", 50)/100,
GetDeviceCaps(PD->m_pd.hDC, LOGPIXELSY)*theApp.GetProfileInt("Default","Margin Top", 50)/100,
GetDeviceCaps(PD->m_pd.hDC, LOGPIXELSX)*theApp.GetProfileInt("Default","Margin Right", 50)/100,
GetDeviceCaps(PD->m_pd.hDC, LOGPIXELSY)*theApp.GetProfileInt("Default","Margin Bottom", 50)/100);
int w = rectDraw.Width()/cols;
int h = rectDraw.Height()/rows;
// Creating Compatible Memory Device Context
CDC *pMemDC = new CDC;
if (!pMemDC->CreateCompatibleDC(pView->GetDC()))
return;
// Preparing bitmap header for DIB section
BITMAPINFO bi;
ZeroMemory(&bi, sizeof(BITMAPINFO));
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biWidth = w;
bi.bmiHeader.biHeight = h;
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 24;
bi.bmiHeader.biCompression = BI_RGB;
bi.bmiHeader.biSizeImage = w * h * (24/8);
bi.bmiHeader.biXPelsPerMeter = 2925;
bi.bmiHeader.biYPelsPerMeter = 2925;
bi.bmiHeader.biClrUsed = 0;
bi.bmiHeader.biClrImportant = 0;
LPBITMAPINFOHEADER lpbi[1];
// Creating a DIB surface
HBITMAP hBm, hBmOld;
hBm = CreateDIBSection(pView->GetDC()->GetSafeHdc(), &bi, DIB_RGB_COLORS,
(void **)&lpbi, NULL, (DWORD)0);
if (!hBm)
return;
// Selecting the DIB Surface
hBmOld = (HBITMAP)::SelectObject(pMemDC->GetSafeHdc(), hBm);
if (!hBmOld)
return;
// Setting up a Pixel format for the DIB surface
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI,
PFD_TYPE_RGBA, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16,
0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 };
int pixelformat = ChoosePixelFormat(pMemDC->m_hDC, &pfd);
DescribePixelFormat(pMemDC->m_hDC, pixelformat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
SetPixelFormat(pMemDC->m_hDC, pixelformat, &pfd);
// Creating a OpenGL context
HGLRC hmemrc = wglCreateContext(pMemDC->GetSafeHdc());
// Setting up the current OpenGL context
GL_DisableVertexBufferObject();
wglMakeCurrent(pMemDC->GetSafeHdc(), hmemrc);
double aspect = (float)w/(float)h;
glMatrixMode(GL_MODELVIEW);
glViewport(0, 0, w, h);
// Sort pieces by description
struct BRICKSORT {
char name[64];
int actual;
struct BRICKSORT *next;
} start, *node, *previous, *news;
start.next = NULL;
for (int j = 0; j < pLib->mPieces.GetSize(); j++)
{
char* desc = pLib->mPieces[j]->m_strDescription;
if (desc[0] != '~')
continue;
// Find the correct location
previous = &start;
node = start.next;
while ((node) && (strcmp(desc, node->name) > 0))
{
node = node->next;
previous = previous->next;
}
news = (struct BRICKSORT*) malloc(sizeof(struct BRICKSORT));
news->next = node;
previous->next = news;
strcpy(news->name, desc);
news->actual = j;
}
node = start.next;
if (PD->PrintRange())
{
for (int j = 0; j < (int)(nStartPage - 1)*rows*cols; j++)
if (node)
node = node->next;
}
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
lf.lfHeight = -MulDiv(12, GetDeviceCaps(PD->m_pd.hDC, LOGPIXELSY), 72);
lf.lfWeight = FW_REGULAR;
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfQuality = PROOF_QUALITY;
strcpy (lf.lfFaceName , "Arial");
HFONT HeaderFont = CreateFontIndirect(&lf);
HFONT OldFont = (HFONT)SelectObject(PD->m_pd.hDC, HeaderFont);
SetBkMode(PD->m_pd.hDC, TRANSPARENT);
SetTextColor(PD->m_pd.hDC, 0x000000);
SetTextAlign (PD->m_pd.hDC, TA_TOP|TA_LEFT|TA_NOUPDATECP);
SetTextColor (pMemDC->m_hDC, 0x000000);
lf.lfHeight = -MulDiv(10, GetDeviceCaps(pMemDC->m_hDC, LOGPIXELSY), 72);
lf.lfWeight = FW_BOLD;
HFONT CatalogFont = CreateFontIndirect(&lf);
HFONT OldMemFont = (HFONT)SelectObject(pMemDC->m_hDC, CatalogFont);
HPEN hpOld = (HPEN)SelectObject(pMemDC->m_hDC,(HPEN)GetStockObject(BLACK_PEN));
for (UINT nCurPage = nStartPage; nCurPage != nEndPage; nCurPage += nStep)
{
// write current page
TCHAR szBuf[80];
wsprintf(szBuf, strTemp, nCurPage);
dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PAGENUM, szBuf);
// attempt to start the current page
if (StartPage(PD->m_pd.hDC) < 0)
{
bError = TRUE;
break;
}
int printed = 0;
// page successfully started, so now render the page
for (int r = 0; r < rows; r++)
for (int c = 0; c < cols; c++)
{
if (node == NULL) continue;
printed++;
glDepthFunc(GL_LEQUAL);
glClearColor(1,1,1,1);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
glDisable(GL_DITHER);
glShadeModel(GL_FLAT);
lcSetColor(lcGetActiveProject()->GetCurrentColor());
// dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_DOCNAME, node->name);
node = node->next;
PieceInfo* pInfo = pLib->mPieces[node->actual];
pInfo->ZoomExtents(30.0f, (float)aspect);
float pos[4] = { 0, 0, 10, 0 };
glLightfv(GL_LIGHT0, GL_POSITION, pos);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
FillRect(pMemDC->m_hDC, CRect(0,h,w,0), (HBRUSH)GetStockObject(WHITE_BRUSH));
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
pInfo->RenderPiece(lcGetActiveProject()->GetCurrentColor());
glFlush();
TextOut (pMemDC->m_hDC, 5, 5, pInfo->m_strDescription, strlen(pInfo->m_strDescription));
// BitBlt(PD->m_pd.hDC, rectDraw.left+(w*c), rectDraw.top+(h*r), w, h, pMemDC->m_hDC, 0, 0, SRCCOPY);
LPBITMAPINFOHEADER lpbi[1];
lpbi[0] = (LPBITMAPINFOHEADER)GlobalLock(MakeDib(hBm, 24));
BITMAPINFO bi;
ZeroMemory(&bi, sizeof(BITMAPINFO));
memcpy (&bi.bmiHeader, lpbi[0], sizeof(BITMAPINFOHEADER));
SetStretchBltMode(PD->m_pd.hDC, COLORONCOLOR);
StretchDIBits(PD->m_pd.hDC, rectDraw.left+(w*c), rectDraw.top+(h*r),
w, h, 0, 0, w, h, (LPBYTE) lpbi[0] + lpbi[0]->biSize + lpbi[0]->biClrUsed * sizeof(RGBQUAD),
&bi, DIB_RGB_COLORS, SRCCOPY);
if (lpbi[0]) GlobalFreePtr(lpbi[0]);
}
DWORD dwPrint = theApp.GetProfileInt("Settings","Print", PRINT_NUMBERS|PRINT_BORDER);
if (dwPrint & PRINT_BORDER)
for (int r = 0; r < rows; r++)
for (int c = 0; c < cols; c++)
{
if (printed == 0) continue;
printed--;
if (r == 0)
{
MoveToEx(PD->m_pd.hDC, rectDraw.left+(w*c), rectDraw.top+(h*r), NULL);
LineTo(PD->m_pd.hDC, rectDraw.left+(w*(c+1)), rectDraw.top+(h*r));
}
if (c == 0)
{
MoveToEx(PD->m_pd.hDC, rectDraw.left+(w*c), rectDraw.top+(h*r), NULL);
LineTo(PD->m_pd.hDC, rectDraw.left+(w*c), rectDraw.top+(h*(r+1)));
}
MoveToEx(PD->m_pd.hDC, rectDraw.left+(w*(c+1)), rectDraw.top+(h*r), NULL);
LineTo(PD->m_pd.hDC, rectDraw.left+(w*(c+1)), rectDraw.top+(h*(r+1)));
MoveToEx(PD->m_pd.hDC, rectDraw.left+(w*c), rectDraw.top+(h*(r+1)), NULL);
LineTo(PD->m_pd.hDC, rectDraw.left+(w*(c+1)), rectDraw.top+(h*(r+1)));
}
CRect r2 = rectDraw;
r2.top -= GetDeviceCaps(PD->m_pd.hDC, LOGPIXELSY)*theApp.GetProfileInt("Default","Margin Top", 50)/200;
r2.bottom += GetDeviceCaps(PD->m_pd.hDC, LOGPIXELSY)*theApp.GetProfileInt("Default","Margin Bottom", 50)/200;
pView->PrintHeader(FALSE, PD->m_pd.hDC, r2, nCurPage, nEndPage, TRUE);
pView->PrintHeader(TRUE, PD->m_pd.hDC, r2, nCurPage, nEndPage, TRUE);
if (EndPage(PD->m_pd.hDC) < 0 || !_AfxAbortProc(PD->m_pd.hDC, 0))
{
bError = TRUE;
break;
}
}
SelectObject(pMemDC->m_hDC, hpOld);
SelectObject(PD->m_pd.hDC, OldFont);
DeleteObject(HeaderFont);
SelectObject(pMemDC->m_hDC, OldMemFont);
DeleteObject(CatalogFont);
node = start.next;
while (node)
{
previous = node;
node = node->next;
free(previous);
}
GL_EnableVertexBufferObject();
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hmemrc);
SelectObject(pMemDC->GetSafeHdc(), hBmOld);
DeleteObject(hBm);
delete pMemDC;
// cleanup document printing process
if (!bError)
EndDoc(PD->m_pd.hDC);
else
AbortDoc(PD->m_pd.hDC);
pParent->EnableWindow();
dlgPrintStatus.DestroyWindow();
if (PD != NULL && PD->m_pd.hDC != NULL)
{
::DeleteDC(PD->m_pd.hDC);
PD->m_pd.hDC = NULL;
}
delete PD;
}
UINT PrintCatalogFunction (LPVOID pv)
{
PRINT_PARAMS* param = (PRINT_PARAMS*)pv;
PrintCatalogThread (param->pParent, param->pMainFrame);
param->pParent->EnableWindow (TRUE);
free(param);
return 0;
}
int PiecesUsedSortFunc(const lcPiecesUsedEntry& a, const lcPiecesUsedEntry& b, void* Data)
{
if (a.ColorIndex == b.ColorIndex)
{
if (a.Info < b.Info)
return -1;
else
return 1;
}
else
{
if (a.ColorIndex < b.ColorIndex)
return -1;
else
return 1;
}
return 0;
}
void FormatHeader(CString& Result, UINT& Align, const char* Format, const char* Title, const char* Author, const char* Description, int CurPage, int TotalPages)
{
char Buffer[128];
const char* Ptr = Format;
Result.Empty();
Align = DT_CENTER;
while (*Ptr)
{
if (*Ptr != '&')
{
Result.AppendChar(*Ptr);
Ptr++;
continue;
}
if (Ptr[1] == '&')
{
Result.AppendChar(*Ptr);
Ptr++;
Ptr++;
continue;
}
switch (Ptr[1])
{
case 'L':
Align = DT_LEFT;
Ptr++;
break;
case 'C':
Align = DT_CENTER;
Ptr++;
break;
case 'R':
Align = DT_RIGHT;
Ptr++;
break;
case 'F':
Result.Append(Title);
Ptr++;
break;
case 'A':
Result.Append(Author);
Ptr++;
break;
case 'N':
Result.Append(Description);
Ptr++;
break;
case 'D':
_strdate(Buffer);
Result.Append(Buffer);
Ptr++;
break;
case 'T':
_strtime(Buffer);
Result.Append(Buffer);
Ptr++;
break;
case 'P':
sprintf(Buffer, "%d", CurPage);
Result.Append(Buffer);
Ptr++;
break;
case 'O':
sprintf(Buffer, "%d", TotalPages);
Result.Append(Buffer);
Ptr++;
break;
case 0:
default:
Result.AppendChar(*Ptr);
break;
}
Ptr++;
}
}
static void PrintPiecesThread(void* pv)
{
CFrameWndEx* pFrame = (CFrameWndEx*)pv;
CView* pView = pFrame->GetActiveView();
CPrintDialog PD(FALSE, PD_ALLPAGES|PD_USEDEVMODECOPIES|PD_NOPAGENUMS|PD_NOSELECTION, pFrame);
if (theApp.DoPrintDialog(&PD) != IDOK)
return;
if (PD.m_pd.hDC == NULL)
return;
Project* project = lcGetActiveProject();
ObjArray<lcPiecesUsedEntry> PiecesUsed;
project->GetPiecesUsed(PiecesUsed);
PiecesUsed.Sort(PiecesUsedSortFunc, NULL);
// gather file to print to if print-to-file selected
CString strOutput;
if (PD.m_pd.Flags & PD_PRINTTOFILE)
{
CString strDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULTEXT));
CString strPrintDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULT));
CString strFilter(MAKEINTRESOURCE(AFX_IDS_PRINTFILTER));
CString strCaption(MAKEINTRESOURCE(AFX_IDS_PRINTCAPTION));
CFileDialog dlg(FALSE, strDef, strPrintDef,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, strFilter);
dlg.m_ofn.lpstrTitle = strCaption;
if (dlg.DoModal() != IDOK)
return;
strOutput = dlg.GetPathName();
}
CString DocName;
char* Ext = strrchr(project->m_strTitle, '.');
DocName.Format("LeoCAD - %.*s BOM", Ext ? Ext - project->m_strTitle : strlen(project->m_strTitle), project->m_strTitle);
DOCINFO docInfo;
memset(&docInfo, 0, sizeof(DOCINFO));
docInfo.cbSize = sizeof(DOCINFO);
docInfo.lpszDocName = DocName;
CString strPortName;
int nFormatID;
if (strOutput.IsEmpty())
{
docInfo.lpszOutput = NULL;
strPortName = PD.GetPortName();
nFormatID = AFX_IDS_PRINTONPORT;
}
else
{
docInfo.lpszOutput = strOutput;
AfxGetFileTitle(strOutput, strPortName.GetBuffer(_MAX_PATH), _MAX_PATH);
nFormatID = AFX_IDS_PRINTTOFILE;
}
SetAbortProc(PD.m_pd.hDC, _AfxAbortProc);
pFrame->EnableWindow(FALSE);
CPrintingDialog dlgPrintStatus(NULL);
CString strTemp;
dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_DOCNAME, DocName);
dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PRINTERNAME, PD.GetDeviceName());
AfxFormatString1(strTemp, nFormatID, strPortName);
dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PORTNAME, strTemp);
dlgPrintStatus.ShowWindow(SW_SHOW);
dlgPrintStatus.UpdateWindow();
if (StartDoc(PD.m_pd.hDC, &docInfo) == SP_ERROR)
{
pFrame->EnableWindow(TRUE);
dlgPrintStatus.DestroyWindow();
AfxMessageBox(AFX_IDP_FAILED_TO_START_PRINT);
return;
}
int ResX = GetDeviceCaps(PD.m_pd.hDC, LOGPIXELSX);
int ResY = GetDeviceCaps(PD.m_pd.hDC, LOGPIXELSY);
CRect RectDraw(0, 0, GetDeviceCaps(PD.m_pd.hDC, HORZRES), GetDeviceCaps(PD.m_pd.hDC, VERTRES));
DPtoLP(PD.m_pd.hDC, (LPPOINT)(RECT*)&RectDraw, 2);
RectDraw.DeflateRect((int)(ResX*(float)theApp.GetProfileInt("Default","Margin Left", 50)/100.0f),
(int)(ResY*(float)theApp.GetProfileInt("Default","Margin Top", 50)/100.0f),
(int)(ResX*(float)theApp.GetProfileInt("Default","Margin Right", 50)/100.0f),
(int)(ResY*(float)theApp.GetProfileInt("Default","Margin Bottom", 50)/100.0f));
CRect HeaderRect = RectDraw;
HeaderRect.top -= (int)(ResY*theApp.GetProfileInt("Default", "Margin Top", 50) / 200.0f);
HeaderRect.bottom += (int)(ResY*theApp.GetProfileInt("Default", "Margin Bottom", 50) / 200.0f);
int RowsPerPage = AfxGetApp()->GetProfileInt("Default", "Catalog Rows", 10);
int ColsPerPage = AfxGetApp()->GetProfileInt("Default", "Catalog Columns", 3);
int PicHeight = RectDraw.Height() / RowsPerPage;
int PicWidth = RectDraw.Width() / ColsPerPage;
int TotalRows = (PiecesUsed.GetSize() + ColsPerPage - 1) / ColsPerPage;
int TotalPages = (TotalRows + RowsPerPage - 1) / RowsPerPage;
int RowHeight = RectDraw.Height() / RowsPerPage;
int ColWidth = RectDraw.Width() / ColsPerPage;
PD.m_pd.nMinPage = 1;
PD.m_pd.nMaxPage = TotalPages + 1;
UINT EndPage = PD.m_pd.nToPage;
UINT StartPage = PD.m_pd.nFromPage;
if (PD.PrintAll())
{
EndPage = PD.m_pd.nMaxPage;
StartPage = PD.m_pd.nMinPage;
}
lcClamp(EndPage, PD.m_pd.nMinPage, PD.m_pd.nMaxPage);
lcClamp(StartPage, PD.m_pd.nMinPage, PD.m_pd.nMaxPage);
int StepPage = (EndPage >= StartPage) ? 1 : -1;
VERIFY(strTemp.LoadString(AFX_IDS_PRINTPAGENUM));
// begin page printing loop
BOOL bError = FALSE;
// Creating Compatible Memory Device Context
CDC *pMemDC = new CDC;
if (!pMemDC->CreateCompatibleDC(pView->GetDC()))
return;
BITMAPINFO bi;
ZeroMemory(&bi, sizeof(BITMAPINFO));
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biWidth = PicWidth;
bi.bmiHeader.biHeight = PicHeight;
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 24;
bi.bmiHeader.biCompression = BI_RGB;
bi.bmiHeader.biSizeImage = PicWidth * PicHeight * 3;
bi.bmiHeader.biXPelsPerMeter = 2925;
bi.bmiHeader.biYPelsPerMeter = 2925;
bi.bmiHeader.biClrUsed = 0;
bi.bmiHeader.biClrImportant = 0;
LPBITMAPINFOHEADER lpbi[1];
HBITMAP hBm, hBmOld;
hBm = CreateDIBSection(pView->GetDC()->GetSafeHdc(), &bi, DIB_RGB_COLORS, (void **)&lpbi, NULL, (DWORD)0);
if (!hBm)
return;
hBmOld = (HBITMAP)::SelectObject(pMemDC->GetSafeHdc(), hBm);
PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI,
PFD_TYPE_RGBA, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 };
int pixelformat = ChoosePixelFormat(pMemDC->m_hDC, &pfd);
DescribePixelFormat(pMemDC->m_hDC, pixelformat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
SetPixelFormat(pMemDC->m_hDC, pixelformat, &pfd);
HGLRC hmemrc = wglCreateContext(pMemDC->GetSafeHdc());
wglMakeCurrent(pMemDC->GetSafeHdc(), hmemrc);
GL_DisableVertexBufferObject();
float Aspect = (float)PicWidth/(float)PicHeight;
glViewport(0, 0, PicWidth, PicHeight);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(0.5f, 0.1f);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glClearColor(1, 1, 1, 1);
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
lf.lfHeight = -MulDiv(12, ResY, 72);
lf.lfWeight = FW_REGULAR;
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfQuality = PROOF_QUALITY;
strcpy (lf.lfFaceName , "Arial");
HFONT HeaderFont = CreateFontIndirect(&lf);
HFONT OldFont = (HFONT)SelectObject(PD.m_pd.hDC, HeaderFont);
SetBkMode(PD.m_pd.hDC, TRANSPARENT);
SetTextColor(PD.m_pd.hDC, 0x000000);
SetTextAlign(PD.m_pd.hDC, TA_CENTER|TA_NOUPDATECP);
DWORD PrintOptions = AfxGetApp()->GetProfileInt("Settings", "Print", PRINT_NUMBERS | PRINT_BORDER/*|PRINT_NAMES*/);
bool DrawNames = 1;//(PrintOptions & PRINT_NAMES) != 0;
bool Horizontal = 1;//(PrintOptions & PRINT_HORIZONTAL) != 0;
pMemDC->SetTextColor(0x000000);
pMemDC->SetBkMode(TRANSPARENT);
// lf.lfHeight = -MulDiv(40, GetDeviceCaps(pMemDC->m_hDC, LOGPIXELSY), 72);
// lf.lfWeight = FW_BOLD;
HFONT CatalogFont = CreateFontIndirect(&lf);
lf.lfHeight = -MulDiv(80, GetDeviceCaps(pMemDC->m_hDC, LOGPIXELSY), 72);
HFONT CountFont = CreateFontIndirect(&lf);
HFONT OldMemFont = (HFONT)SelectObject(pMemDC->m_hDC, CatalogFont);
HPEN hpOld = (HPEN)SelectObject(pMemDC->m_hDC, GetStockObject(BLACK_PEN));
for (UINT CurPage = StartPage; CurPage != EndPage; CurPage += StepPage)
{
TCHAR szBuf[80];
wsprintf(szBuf, strTemp, CurPage);
dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PAGENUM, szBuf);
if (::StartPage(PD.m_pd.hDC) < 0)
{
bError = TRUE;
break;
}
// Draw header and footer.
SelectObject(PD.m_pd.hDC, HeaderFont);
CString Header;
UINT Align;
FormatHeader(Header, Align, AfxGetApp()->GetProfileString("Default", "Catalog Header", ""), project->m_strTitle, project->m_strAuthor, project->m_strDescription, CurPage, TotalPages);
Align |= DT_TOP|DT_SINGLELINE;
DrawText(PD.m_pd.hDC, (LPCTSTR)Header, Header.GetLength(), HeaderRect, Align);
FormatHeader(Header, Align, AfxGetApp()->GetProfileString("Default", "Catalog Footer", "Page &P"), project->m_strTitle, project->m_strAuthor, project->m_strDescription, CurPage, TotalPages);
Align |= DT_BOTTOM|DT_SINGLELINE;
DrawText(PD.m_pd.hDC, (LPCTSTR)Header, Header.GetLength(), HeaderRect, Align);
int StartPiece = (CurPage - 1) * RowsPerPage * ColsPerPage;
int EndPiece = lcMin(StartPiece + RowsPerPage * ColsPerPage, PiecesUsed.GetSize());
for (int CurPiece = StartPiece; CurPiece < EndPiece; CurPiece++)
{
FillRect(pMemDC->m_hDC, CRect(0, PicHeight, PicWidth, 0), (HBRUSH)GetStockObject(WHITE_BRUSH));
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
PieceInfo* pInfo = PiecesUsed[CurPiece].Info;
pInfo->ZoomExtents(30.0f, Aspect);
pInfo->RenderPiece(PiecesUsed[CurPiece].ColorIndex);
glFinish();
// Draw description text at the bottom.
CRect TextRect(0, 0, PicWidth, PicHeight);
if (DrawNames)
{
SelectObject(pMemDC->m_hDC, CatalogFont);
pMemDC->DrawText(pInfo->m_strDescription, strlen(pInfo->m_strDescription), TextRect, DT_CALCRECT | DT_WORDBREAK);
TextRect.OffsetRect(0, PicHeight - TextRect.Height() - 5);
pMemDC->DrawText(pInfo->m_strDescription, strlen(pInfo->m_strDescription), TextRect, DT_WORDBREAK);
}
// Draw count.
SelectObject(pMemDC->m_hDC, CountFont);
TextRect = CRect(0, 0, PicWidth, TextRect.top);
TextRect.DeflateRect(5, 5);
char CountStr[16];
sprintf(CountStr, "%dx", PiecesUsed[CurPiece].Count);
pMemDC->DrawText(CountStr, strlen(CountStr), TextRect, DT_BOTTOM | DT_LEFT | DT_SINGLELINE);
LPBITMAPINFOHEADER lpbi[1];
lpbi[0] = (LPBITMAPINFOHEADER)GlobalLock(MakeDib(hBm, 24));
BITMAPINFO bi;
ZeroMemory(&bi, sizeof(BITMAPINFO));
memcpy (&bi.bmiHeader, lpbi[0], sizeof(BITMAPINFOHEADER));
SetStretchBltMode(PD.m_pd.hDC, COLORONCOLOR);
int CurRow, CurCol;
if (Horizontal)
{
CurRow = (CurPiece - StartPiece) / ColsPerPage;
CurCol = (CurPiece - StartPiece) % ColsPerPage;
}
else
{
CurRow = (CurPiece - StartPiece) % RowsPerPage;
CurCol = (CurPiece - StartPiece) / RowsPerPage;
}
int Left = RectDraw.left + ColWidth * CurCol + (ColWidth - PicWidth) / 2;
int Top = RectDraw.top + RowHeight * CurRow + (RowHeight - PicHeight) / 2;
StretchDIBits(PD.m_pd.hDC, Left, Top, PicWidth, PicHeight, 0, 0, PicWidth, PicHeight,
(LPBYTE)lpbi[0] + lpbi[0]->biSize + lpbi[0]->biClrUsed * sizeof(RGBQUAD), &bi, DIB_RGB_COLORS, SRCCOPY);
if (lpbi[0])
GlobalFreePtr(lpbi[0]);
}
if (::EndPage(PD.m_pd.hDC) < 0 || !_AfxAbortProc(PD.m_pd.hDC, 0))
{
bError = TRUE;
break;
}
}
SelectObject(pMemDC->m_hDC, hpOld);
SelectObject(PD.m_pd.hDC, OldFont);
DeleteObject(HeaderFont);
SelectObject(pMemDC->m_hDC, OldMemFont);
DeleteObject(CatalogFont);
DeleteObject(CountFont);
GL_EnableVertexBufferObject();
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hmemrc);
SelectObject(pMemDC->GetSafeHdc(), hBmOld);
DeleteObject(hBm);
delete pMemDC;
if (!bError)
EndDoc(PD.m_pd.hDC);
else
AbortDoc(PD.m_pd.hDC);
pFrame->EnableWindow();
dlgPrintStatus.DestroyWindow();
if (PD.m_pd.hDC != NULL)
{
::DeleteDC(PD.m_pd.hDC);
PD.m_pd.hDC = NULL;
}
}
UINT PrintPiecesFunction (LPVOID pv)
{
PrintPiecesThread(pv);
CFrameWndEx* pFrame = (CFrameWndEx*)pv;
pFrame->EnableWindow(TRUE);
return 0;
}
-1440
View File
File diff suppressed because it is too large Load Diff
-31
View File
@@ -1,31 +0,0 @@
#ifndef _PRINT_H_
#define _PRINT_H_
BOOL CALLBACK _AfxAbortProc(HDC, int);
UINT AFXAPI AfxGetFileTitle(LPCTSTR lpszPathName, LPTSTR lpszTitle, UINT nMax);
#define AFX_IDD_PRINTDLG 30722
struct PRINT_PARAMS
{
CWnd* pParent;
CFrameWndEx* pMainFrame;
};
class CPrintingDialog : public CDialog
{
public:
//{{AFX_DATA(CPrintingDialog)
enum { IDD = AFX_IDD_PRINTDLG };
//}}AFX_DATA
CPrintingDialog(CWnd* pParent);
virtual ~CPrintingDialog();
virtual BOOL OnInitDialog();
virtual void OnCancel();
};
UINT PrintCatalogFunction (LPVOID pv);
UINT PrintPiecesFunction (LPVOID pv);
#endif // _PRINT_H_