📄 utilobj.cpp
字号:
{
double RetVal = 0.0;
switch (select){
case SIZE_SYMBOL: RetVal = 3.0; break;
case SIZE_SYM_LINE: RetVal = 0.2; break;
case SIZE_DATA_LINE:
switch(cUnits) {
case 1: return Line_1.width;
case 2: return Line_2.width;
default: return Line_0.width;
}
case SIZE_TEXT: RetVal = _TXH; break;
case SIZE_GRECT_TOP: RetVal = 0.0; break;
case SIZE_GRECT_BOTTOM: RetVal = 110.0; break;
case SIZE_GRECT_LEFT: RetVal = 0.0; break;
case SIZE_GRECT_RIGHT: RetVal = 160.0; break;
case SIZE_DRECT_TOP: RetVal = 10.0; break;
case SIZE_DRECT_BOTTOM: RetVal = 90.0; break;
case SIZE_DRECT_LEFT: RetVal = 25.0; break;
case SIZE_DRECT_RIGHT: RetVal = 140.0; break;
case SIZE_PATLENGTH:
case SIZE_DATA_LINE_PAT:
switch(cUnits) {
case 1: return Line_1.patlength;
case 2: return Line_2.patlength;
default: return Line_0.patlength;
}
case SIZE_AXIS_TICKS: RetVal = 2.0; break;
case SIZE_TICK_LABELS: RetVal = _TXH; break;
case SIZE_WHISKER:
case SIZE_ERRBAR: RetVal = 3.0; break;
case SIZE_WHISKER_LINE:
case SIZE_AXIS_LINE:
case SIZE_BAR_LINE:
case SIZE_ERRBAR_LINE:
switch(cUnits) {
case 1: return OutLine_1.width;
case 2: return OutLine_2.width;
default: return OutLine_0.width;
}
case SIZE_BOX:
case SIZE_BAR: RetVal = 10.0; break;
case SIZE_BUBBLE_LINE: RetVal = 0.4; break;
case SIZE_BUBBLE_HATCH_LINE: RetVal = 0.1; break;
case SIZE_ARROW_LINE: RetVal = 0.4; break;
case SIZE_ARROW_CAPWIDTH: RetVal = 3.0; break;
case SIZE_ARROW_CAPLENGTH: RetVal = 4.0; break;
case SIZE_HAIRLINE: RetVal = 0.1; break;
case SIZE_SEGLINE: RetVal = 0.4; break;
case SIZE_CELLWIDTH: RetVal = 20.0; break;
case SIZE_CELLTEXT: RetVal = 4.5*ss_txt; break;
case SIZE_RRECT_RAD:
return rrect_rad ? *rrect_rad : GetSize(SIZE_SYMBOL)/2.0;
default: return 0.0;
}
switch(cUnits) {
case 1: RetVal /= 10.0; break;
case 2: RetVal = NiceValue(RetVal/25.4); break;
}
return RetVal;
}
DWORD
Default::Color(int select)
{
switch (select){
case COL_ERROR_LINE:
case COL_WHISKER:
case COL_SYM_LINE: return 0x00000000L;
case COL_SYM_FILL: return 0x00ffffffL;
case COL_ARROW:
case COL_DATA_LINE: return Line_0.color;
case COL_TEXT: return 0x00000000L;
case COL_BG: return 0x00ffffffL;
case COL_AXIS: return axis_color;
case COL_BAR_LINE: return OutLine_0.color;
case COL_BAR_FILL: return 0x00ffffffL;
case COL_BUBBLE_LINE:
case COL_BUBBLE_FILLLINE: return 0x00ff0000L;
case COL_BUBBLE_FILL: return 0x00ffc0c0L;
case COL_DRECT: return 0x00ffffffL;
case COL_GRECT: return 0x00ffffffL;
case COL_GRECTLINE: return 0x00e0e0e0L;
case COL_POLYLINE: return pl ? pl->color : OutLine_0.color;
case COL_POLYGON: return pgl ? pgl->color : OutLine_0.color;
default: return 0x00C0C0C0L; //Error
}
}
LineDEF *
Default::GetLine()
{
switch (cUnits) {
case 1: return &Line_1;
case 2: return &Line_2;
default: return &Line_0;
}
}
void
Default::SetLine(int u, LineDEF *l, int which)
{
double lw, pl;
LineDEF *l1, *l2, *l3;
switch (which) {
case 0: l1 = &Line_0; l2 = &Line_1; l3 = &Line_2; break;
case 1: l1 = &FillLine_0; l2 = &FillLine_1; l3 = &FillLine_2; break;
case 2: l1 = &OutLine_0; l2 = &OutLine_1; l3 = &OutLine_2; break;
default: return;
}
l1->color = l2->color = l3->color = l->color;
l1->pattern = l2->pattern = l3->pattern = l->pattern;
switch (u) {
case 1:
lw = l->width*10.0; pl = l->patlength*10.0;
l1->width = lw; l1->patlength = pl;
l2->width = l->width; l2->patlength = l->patlength;
l3->patlength = NiceValue(pl/25.4);
l3->patlength = NiceValue(pl/25.4);
break;
case 2:
lw = NiceValue(l->width*25.4); pl = NiceValue(l->patlength*25.4);
l1->width = lw; l1->patlength = pl;
l2->width = lw/10.0; l2->patlength = pl/10.0;
l3->width = l->width; l3->patlength = l->patlength;
break;
default:
lw = l->width; pl = l->patlength;
l1->width = l->width; l1->patlength = l->patlength;
l2->width = lw/10.0; l2->patlength = pl/10.0;
l3->patlength = NiceValue(pl/25.4);
l3->patlength = NiceValue(pl/25.4);
break;
}
}
FillDEF *
Default::GetFill()
{
switch (cUnits) {
case 1: return &Fill_1;
case 2: return &Fill_2;
default: return &Fill_0;
}
}
void
Default::SetFill(int u, FillDEF *fd)
{
memcpy(&Fill_0, fd, sizeof(FillDEF));
memcpy(&Fill_1, fd, sizeof(FillDEF));
memcpy(&Fill_2, fd, sizeof(FillDEF));
if(fd->hatch) SetLine(u, fd->hatch, 1);
Fill_0.hatch = &FillLine_0;
Fill_1.hatch = &FillLine_1;
Fill_2.hatch = &FillLine_2;
}
LineDEF *
Default::GetOutLine()
{
switch (cUnits) {
case 1: return &OutLine_1;
case 2: return &OutLine_2;
default: return &OutLine_0;
}
}
LineDEF *
Default::plLineDEF(LineDEF *ld)
{
if(ld) {
if(pl) free(pl);
if(pl = (LineDEF *)malloc(sizeof(LineDEF))) memcpy(pl, ld, sizeof(LineDEF));
}
if(pl) return pl;
else return GetOutLine();
}
LineDEF *
Default::pgLineDEF(LineDEF *ol)
{
if(ol) {
if(pgl) free(pgl);
if(pgl = (LineDEF *)malloc(sizeof(LineDEF))) memcpy(pgl, ol, sizeof(LineDEF));
}
if(pgl) return pgl;
else return GetOutLine();
}
FillDEF *
Default::pgFillDEF(FillDEF *fd)
{
if(fd) {
if(pg) free(pg);
if(pg = (FillDEF *)malloc(sizeof(FillDEF))){
memcpy(pg, fd, sizeof(FillDEF));
if(pg->hatch) {
if(pg_fl) free(pg_fl);
if(pg_fl = (LineDEF *)malloc(sizeof(LineDEF)))
memcpy(pg_fl, pg->hatch, sizeof(LineDEF));
pg->hatch = pg_fl;
}
}
}
if(pg) return pg;
else return GetFill();
}
double
Default::rrectRad(double rad)
{
if(!rrect_rad)rrect_rad=(double*)malloc(sizeof(double));
if(rrect_rad) return (*rrect_rad = rad);
return 0.0;
}
void
Default::FileHistory(char *path)
{
char *tmp_path = 0L, *tmp;
char **history[] = {&File1, &File2, &File3, &File4, &File5, &File6};
int i;
if(path && (tmp_path=strdup(path))){
for(i=strlen(path); i > 0 && tmp_path[i] != '/' && tmp_path[i] != '\\'; i--);
tmp_path[i] = 0;
if(currPath) free(currPath);
if(strlen(tmp_path)) currPath = strdup(tmp_path);
else currPath = 0L;
strcpy(tmp_path, path);
if(File1 && strcmp(File1, tmp_path)) {
for(i = 0; i < 6 && tmp_path; i++) {
if(i && *history[i] && !strcmp(File1, *history[i])){
free(*history[i]);
*history[i] = tmp_path;
tmp_path = 0L;
break;
}
if(*history[i]) {
if(strcmp(tmp_path, *history[i])){
tmp = *history[i];
*history[i] = tmp_path;
tmp_path = tmp;
}
else {
free(tmp_path);
tmp_path = 0L;
}
}
else{
tmp = *history[i];
*history[i] = tmp_path;
tmp_path = tmp;
}
}
}
if(!(*history[0])) {
*history[0] = tmp_path;
tmp_path = 0L;
}
}
if(tmp_path) free(tmp_path);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Chache file input for read operations
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#define CharCacheSize 1024
ReadCache::ReadCache()
{
Cache = 0L;
idx = max = 0;
eof = true;
}
ReadCache::~ReadCache()
{
if(Cache) free(Cache);
Cache = 0L;
}
bool
ReadCache::Open(char *name)
{
idx = max = 0;
eof = true;
if(!name) iFile = 0; //use stdin
else if(-1 ==(iFile = open(name, O_BINARY))) return false;
Cache = (unsigned char *)malloc((unsigned)(CharCacheSize + 1));
if(Cache) return true;
return false;
}
void
ReadCache::Close()
{
close(iFile);
if(Cache) free(Cache);
Cache = 0L;
}
unsigned char
ReadCache::Getc()
{
if(Cache){
if(idx < max) return (last = Cache[idx++]);
else {
do {
max = read(iFile, Cache, CharCacheSize);
if(max <=0) {
eof = true;
return 0;
}
else eof = false;
}while(max == 0);
idx = 1;
return(last = Cache[0]);
}
}
return 0;
}
unsigned char *
ReadCache::GetField()
{
int i;
static unsigned char *ret;
if(Cache && max) {
while(idx < max && Cache[idx] < 43) idx++;
if(idx == max){
if(max == CharCacheSize) {
max = read(iFile, Cache, CharCacheSize);
idx = 0;
return GetField();
}
else return 0L;
}
i = idx;
while(i < max && Cache[i] > 32 && Cache[i] <= 'z') i++;
if(i == max) {
for(i = 0; (Line[i] = Getc()) >32 && Line[i] <= 'z' && i < 4096; i++);
Line[i] = 0;
return Line;
}
else {
ret = Cache+idx;
idx = i;
return ret;
}
}
return 0L;
}
void
ReadCache::ReadLine(char *dest, int size)
{
int i=0;
unsigned char c;
dest[0] = 0;
do {
c = Getc();
if(c == 0x09) c = 0x32; // tab to space
if(c > 31) dest[i++] = (char)c;
}while(c && c != 0x0a && i < size);
dest[i] = 0;
}
bool
ReadCache::GetInt(long *in)
{
unsigned char *field;
field = GetField();
if(field && field[0]) {
*in = atol((char*)field);
if(*in == 0 && field[0] == '}') return false;
return true;
}
return false;
}
bool
ReadCache::GetFloat(double *fn)
{
unsigned char *field;
field = GetField();
if(field && field[0]) {
*fn = atof((char*)field);
if(*fn == 0.0 && field[0] == '}') return false;
return true;
}
return false;
}
unsigned char
ReadCache::Lastc()
{
return last;
}
bool
ReadCache::IsEOF()
{
return eof;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Process memory block as if file input
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MemCache::MemCache(unsigned char *ptr)
:ReadCache()
{
if(ptr) {
Cache = (unsigned char*) strdup((char*)ptr);
max = strlen((char*)Cache);
eof = false;
}
}
MemCache::~MemCache()
{
if(Cache) free(Cache);
Cache = 0L;
}
unsigned char
MemCache::Getc()
{
if(Cache){
if(idx < max) return (last = Cache[idx++]);
else {
eof = true;
return 0;
}
}
return 0;
}
unsigned char *
MemCache::GetField()
{
int i;
static unsigned char *ret;
if(Cache && max) {
while(idx < max && Cache[idx] < 43) idx++;
i = idx;
while(i < max && Cache[i] > 32 && Cache[i] <= 'z') i++;
ret = Cache+idx;
idx = i;
return ret;
}
return 0L;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Process Undo
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#define UNDO_RING_SIZE 0x100
#define UNDO_IDX_MASK 0xff
UndoObj::UndoObj()
{
buff = buff0 = (UndoInfo**)calloc(UNDO_RING_SIZE, sizeof(UndoInfo*));
stub1 = ndisp = 0; busy = false;
pcb = &stub1; cdisp = ldisp = 0L; buffers = 0L;
}
UndoObj::~UndoObj()
{
Flu
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -