// 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, "\r\n"); fwrite(buf, 1, length, fd); length = _snprintf(buf, 512, "\r\n"); fwrite(buf, 1, length, fd); __exit: if (fd >= 0) fclose(fd); if (buf) delete buf; return; }