Files
coco df489d5640 a
2026-07-03 16:05:30 +08:00

186 lines
4.6 KiB
C++

// Scriptor3D.cpp: implementation of the Scriptor3D class.
//
//////////////////////////////////////////////////////////////////////
#include "geomative.h"
#include "Scriptor3D.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Scriptor3D::Scriptor3D()
{
}
Scriptor3D::~Scriptor3D()
{
}
void Scriptor3D::create(const char *name, int flags)
{
m_rect.x0 = 1;
m_rect.y0 = 1;
m_rect.x1 = 12;
m_rect.y1 = 12;
m_scr = scr_create(name,ONLY_45DIAGONAL, &m_rect, 0, 0);
}
void Scriptor3D::SetRect(int x0, int y0, int x1, int y1)
{
rect_init(&m_rect, x0, y0, x1, y1);
scr_set_rect(m_scr, &m_rect);
}
void Scriptor3D::set_zone(bool enable, int zonec, int *zonev)
{
scr_set_zone(m_scr, enable, zonec, zonev);
}
BOOL Scriptor3D::generate()
{
return scr_generate(m_scr);
}
struct _rect * Scriptor3D::get_rect()
{
return scr_get_rect(m_scr);
}
int Scriptor3D::get_pole_count()
{
return scr_get_pole_count(m_scr);
}
BOOL Scriptor3D::set_pole_start(int startpole)
{
return scr_set_pole_start(m_scr, startpole);
}
int Scriptor3D::get_pole_start()
{
return scr_get_pole_start(m_scr);
}
void Scriptor3D::destroy()
{
scr_destroy(m_scr);
}
struct _point * Scriptor3D::get_points()
{
return scr_get_points(m_scr);
}
void Scriptor3D::_save_scr()
{
struct _rect rect = { 1, 1, 12, 12 };
struct _rect *r;
struct _point *node, *head = NULL;
int length;
FILE *fd;
char *buf = NULL;
if (!m_scr)
return;
head = scr_get_points(m_scr);
if (!head)
goto __exit;
buf = new char[512];
if (!buf)
{
printf("buffer alloc failed!\n");
goto __exit;
}
/* 只写 & 创建 打开 */
{
r = scr_get_rect(m_scr);
_snprintf(buf, 512, "disk/sd/%s(%d,%d,%d,%d).scr",
scr_get_name(m_scr),
r->x0, r->y0, r->x1, r->y1);
fd = fopen(buf, "wb+");
}
if (fd < 0)
{
printf("open \"%s\" for write failed!\n", scr_get_name(m_scr));
goto __exit;
}
{
time_t now;
struct tm *ptm;
time(&now);
ptm = localtime(&now); //取得当地时间
r = scr_get_rect(m_scr);
length = _snprintf(buf, 512, "<?xml version = \"1.0\" encoding = \"ansi\" ?>\r\n");
fwrite(buf, 1, length, fd);
length = _snprintf(buf, 512, "<script>\r\n");
fwrite(buf, 1, length, fd);
length = _snprintf(buf, 512, "\t<cn>%s</cn>\r\n", scr_get_name(m_scr));
fwrite(buf, 1, length, fd);
length = _snprintf(buf, 512, "\t<name>%s</name>\r\n", scr_get_name(m_scr));
fwrite(buf, 1, length, fd);
length = _snprintf(buf, 512, "\t<type>%d</type>\r\n", scr_get_type(m_scr));
fwrite(buf, 1, length, fd);
length = _snprintf(buf, 512, "\t<description>%s</description>\r\n", scr_get_name(m_scr));
fwrite(buf, 1, length, fd);
length = _snprintf(buf, 512, "\t<definer>jimmy.lee</definer>\r\n");
fwrite(buf, 1, length, fd);
length = _snprintf(buf, 512, "\t<date>%04d-%02d-%02d</date>\r\n", (1900 + ptm->tm_year), (1 + ptm->tm_mon), ptm->tm_mday);
fwrite(buf, 1, length, fd);
length = _snprintf(buf, 512, "\t<rect>%d, %d, %d, %d</rect>\r\n", r->x0, r->y0, r->x1, r->y1);
fwrite(buf, 1, length, fd);
length = _snprintf(buf, 512, "\t<pole_count>%d</pole_count>\r\n", scr_get_pole_count(m_scr));
fwrite(buf, 1, length, fd);
length = _snprintf(buf, 512, "\t<pole_start>%d</pole_start>\r\n", scr_get_pole_start(m_scr));
fwrite(buf, 1, length, fd);
length = _snprintf(buf, 512, "\t<rect>%d, %d, %d, %d</rect>\r\n", r->x0, r->y0, r->x1, r->y1);
length = _snprintf(buf, 512, "\t<channel_count>1</channel_count>\r\n");
fwrite(buf, 1, length, fd);
length = _snprintf(buf, 512, "\t<channel>\r\n");
fwrite(buf, 1, length, fd);
length = _snprintf(buf, 512, "\t\t<ar>1:1</ar>\r\n");
fwrite(buf, 1, length, fd);
length = _snprintf(buf, 512, "\t</channel>\r\n");
fwrite(buf, 1, length, fd);
length = _snprintf(buf, 512, "\t<layout>\r\n");
fwrite(buf, 1, length, fd);
}
for (node = head; node;)
{
length = _snprintf(buf, 512, "\t\t<array tsn = \"%d\" ch = \"1\" c1 = \"%d\" c2 = \"%d\" n = \"1\">\r\n", node->TSN, node->A, node->B);
fwrite(buf, 1, length, fd);
length = _snprintf(buf, 512, "\t\t\t<ch n=\"1\" ks=\"%f\">%d, %d</ch>\r\n", node->KS, node->M, node->N);
fwrite(buf, 1, length, fd);
length = _snprintf(buf, 512, "\t\t</array>\r\n");
fwrite(buf, 1, length, fd);
if (node->next == head)
break;
node = node->next;
}
length = _snprintf(buf, 512, "\t</layout>\r\n");
fwrite(buf, 1, length, fd);
length = _snprintf(buf, 512, "</script>\r\n");
fwrite(buf, 1, length, fd);
__exit:
if (fd >= 0)
fclose(fd);
if (buf)
delete buf;
return;
}