1547 lines
32 KiB
C
1547 lines
32 KiB
C
/*
|
|
* File : scriptor.c
|
|
* COPYRIGHT (C) 2014, Co., Ltd
|
|
*
|
|
* Change Logs:
|
|
* Date Author Notes
|
|
* 2013-04-14 jimmy.lee initial implementation
|
|
* 2015-01-15 jimmy.lee add Schlumberger, WennerAlfa, WennerBeta algorithm.
|
|
*/
|
|
#include "scriptor.h"
|
|
|
|
//#include <stdbool.h>
|
|
#include <stdarg.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include <math.h>
|
|
|
|
|
|
// typedef int int;
|
|
//
|
|
// #ifndef TRUE
|
|
// # define TRUE 1
|
|
// #endif
|
|
// #ifndef FALSE
|
|
// # define FALSE 0
|
|
// #endif
|
|
// #ifndef NULL
|
|
// # define NULL 0
|
|
// #endif
|
|
// #define rect_width(r) (abs((r)->x1 - (r)->x0))
|
|
// #define rect_height(r) (abs((r)->y1 - (r)->y0))
|
|
|
|
__inline int _abs(int x)
|
|
{
|
|
return ((x) > 0) ? (x) : -(x);
|
|
}
|
|
|
|
int rect_width(struct _rect *r)
|
|
{
|
|
return (_abs((r)->x1 - (r)->x0));
|
|
}
|
|
int rect_height(struct _rect *r)
|
|
{
|
|
return (_abs((r)->y1 - (r)->y0));
|
|
}
|
|
void rect_init(struct _rect *r, int x0, int y0, int x1, int y1)
|
|
{
|
|
(r)->x0 = x0;
|
|
(r)->y0 = y0;
|
|
(r)->x1 = x1;
|
|
(r)->y1 = y1;
|
|
|
|
}
|
|
//class CGeoScriptor
|
|
struct _scriptor
|
|
{
|
|
const char *name;
|
|
unsigned int flags;
|
|
int type;
|
|
struct _point *point_head;
|
|
struct _rect rect;
|
|
int pole_start;//, pole_count;
|
|
int byTestLineDirection;
|
|
struct _pos step;
|
|
struct
|
|
{
|
|
double x;
|
|
double y;
|
|
}spacing;
|
|
struct _pos C1, C2, P1, P2;
|
|
int zone[8];
|
|
};
|
|
static void _Append(struct _point *point_head, struct _point *points)
|
|
{
|
|
struct _point *point_tail;
|
|
if (!point_head | !points)
|
|
return;
|
|
|
|
point_tail = points->prev;
|
|
|
|
point_head->prev->next = points;
|
|
points->prev = point_head->prev;
|
|
|
|
point_head->prev = point_tail;
|
|
point_tail->next = point_head;
|
|
}
|
|
|
|
|
|
|
|
static void _Remove(struct _point *point)
|
|
{
|
|
if (!point)
|
|
return;
|
|
|
|
point->next->prev = point->prev;
|
|
point->prev->next = point->next;
|
|
|
|
point->next = point->prev = point;
|
|
}
|
|
|
|
static void _Flush(struct _point *point_head)
|
|
{
|
|
struct _point *node;
|
|
|
|
if (!point_head)
|
|
return;
|
|
|
|
while (point_head)
|
|
{
|
|
node = point_head->prev;
|
|
point_head->prev = node->prev;
|
|
node->prev->next = point_head;
|
|
if (node == point_head)
|
|
point_head = NULL;
|
|
free(node);
|
|
}
|
|
return;
|
|
}
|
|
|
|
// int CGeoScriptor::InTrig(struct _pos *a, int n, struct _pos *p1, struct _pos *p2)
|
|
// {
|
|
// if (!a || !p1 || !p2)
|
|
// return FALSE;
|
|
// return (((n*a->x)*(n*a->x) + (n*a->y)*(n*a->y)) ==
|
|
// ((p2->x - p1->x)*(p2->x - p1->x) + (p2->y - p1->y)*(p2->y - p1->y)));
|
|
// }
|
|
// 不再使用三角函数判断, 直接判断三点是不是在一条线上.
|
|
static int _InTrig(struct _pos *a, int n, struct _pos *p0, struct _pos *p1)
|
|
{
|
|
if (!a || !p0 || !p1)
|
|
return 0;
|
|
return (((p1->x - p0->x) == a->x * n) && ((p1->y - p0->y) == a->y * n));
|
|
}
|
|
//将坐标轴的位置转换成电极序号,按照正常坐标轴的次序排列,也就是从左右倒有递增
|
|
int pos_to_pole_by_noraml_axis(struct _rect *rect, int start, int x_step, int y_step, struct _pos *pos)
|
|
{
|
|
struct _pos m; // 矩阵大小
|
|
struct _pos p; // 相对位置
|
|
int pole;
|
|
int PoleCount;
|
|
if (!pos || pos->x == -1 || pos->y == -1)
|
|
return -1;
|
|
|
|
m.x = rect_width(rect) + 1;//横坐标宽度(一行有多少个电极)
|
|
m.y = rect_height(rect) + 1;//纵坐标宽度(纵向有多少个电极)
|
|
|
|
p.x = pos->x - rect->x0;//当前点的X坐标
|
|
p.y = pos->y - rect->y0;//当前点的Y坐标
|
|
|
|
if (p.x < 0 || p.y < 0)
|
|
return -1;
|
|
|
|
PoleCount = 0;//一行横坐标上的点击数量
|
|
|
|
//计算加上步长以后,每行的电极数量
|
|
PoleCount = rect_width(rect) * x_step + 1;
|
|
|
|
//电极序号在该行从左到右递增
|
|
pole = PoleCount * p.y + (y_step - 1) * p.y + (p.x + p.x * (x_step - 1));
|
|
|
|
return (pole + start);
|
|
}
|
|
|
|
int pos_to_pole(struct _rect *rect, int start, int x_step, int y_step, struct _pos *pos)
|
|
{
|
|
struct _pos m; // 矩阵大小
|
|
struct _pos p; // 相对位置
|
|
int pole;
|
|
int PoleCount;
|
|
if (!pos || pos->x == -1 || pos->y == -1)
|
|
return -1;
|
|
|
|
m.x = rect_width(rect) + 1;//横坐标宽度(一行有多少个电极)
|
|
m.y = rect_height(rect) + 1;//纵坐标宽度(纵向有多少个电极)
|
|
|
|
p.x = pos->x - rect->x0;//当前点的X坐标
|
|
p.y = pos->y - rect->y0;//当前点的Y坐标
|
|
|
|
if (p.x < 0 || p.y < 0)
|
|
return -1;
|
|
|
|
PoleCount = 0;//一行横坐标上的点击数量
|
|
|
|
//计算加上步长以后,每行的电极数量
|
|
PoleCount = rect_width(rect) * x_step + 1;
|
|
|
|
if (p.y % 2 == 0)//
|
|
{//偶数行,电极序号在该行从左到右递增
|
|
pole = PoleCount * p.y + (y_step - 1) * p.y + (p.x + p.x * (x_step - 1));
|
|
}
|
|
else
|
|
{//奇数行,电极序号在该行从左到右递减
|
|
pole = PoleCount * (p.y + 1) + (y_step - 1) * p.y - (p.x * x_step + 1);
|
|
}
|
|
|
|
// pole = (p.y % 2) ?
|
|
// (m.x * (p.y + 1) - p.x - 1) ://奇数行,默认以0为其实电极,故有"p.x - 1"
|
|
// (m.x * (p.y + 0) + p.x);//偶数行
|
|
|
|
return (pole + start);
|
|
}
|
|
|
|
int pole_to_pos_by_normal_axis(struct _rect *rect, int start, int x_step, int y_step, struct _pos *pos, int pole)
|
|
{
|
|
struct _pos m = { 0 }; // 矩阵大小
|
|
struct _pos p = { 0 }; // 相对位置
|
|
int Xcount = 0;//横坐标电极总数
|
|
|
|
m.x = rect_width(rect) + 1;
|
|
m.y = rect_height(rect) + 1;
|
|
|
|
|
|
pole -= start;
|
|
|
|
Xcount = (m.x - 1) * (x_step - 1) + m.x + (y_step - 1);
|
|
|
|
//计算纵坐标位置
|
|
if (0 != Xcount)
|
|
p.y = pole / Xcount;
|
|
|
|
if (0 != x_step)
|
|
p.x = (pole % Xcount) / x_step;
|
|
|
|
|
|
pos->x = p.x + rect->x0;
|
|
pos->y = p.y + rect->y0;
|
|
|
|
|
|
return 1;
|
|
}
|
|
|
|
int pole_to_pos(struct _rect *rect, int start, int x_step, int y_step, struct _pos *pos, int pole)
|
|
{
|
|
struct _pos m; // 矩阵大小
|
|
struct _pos p; // 相对位置
|
|
int Xcount = 0;//横坐标电极总数
|
|
|
|
m.x = rect_width(rect) + 1;
|
|
m.y = rect_height(rect) + 1;
|
|
|
|
// p.y = pole / m.x;
|
|
// p.x = (p.y % 2) ?
|
|
// (m.x - pole % m.x - 1) :
|
|
// (pole % m.x);
|
|
|
|
pole -= start;
|
|
|
|
Xcount = (m.x - 1) * (x_step - 1) + m.x + (y_step - 1);
|
|
|
|
//计算纵坐标位置
|
|
if (Xcount != 0)
|
|
{
|
|
p.y = pole / Xcount;
|
|
}
|
|
|
|
if (p.y % 2)
|
|
{//奇数行
|
|
if (x_step != 0)
|
|
p.x = ( (Xcount - (y_step - 1) ) - (pole % Xcount +1) ) / x_step;
|
|
// p.x = ( pole - p.y* Xcount (Xcount - y_step - 1 ) - (pole % Xcount) + 1) / x_step;
|
|
|
|
}
|
|
else
|
|
{
|
|
//偶数行
|
|
if (x_step != 0)
|
|
p.x = (pole % Xcount) / x_step;
|
|
}
|
|
|
|
pos->x = p.x + rect->x0;
|
|
pos->y = p.y + rect->y0;
|
|
|
|
|
|
return 1;
|
|
}
|
|
|
|
/*
|
|
*iLineDirection 电缆布线方向,当值为0时,可以用于计算二维的坐标
|
|
*/
|
|
int pole_to_pos_3d(struct _rect *rect, int start, int x_step, int y_step, struct _pos *pos, int iElecNum, int iLineDirection)
|
|
{
|
|
struct _pos m; // 矩阵大小
|
|
struct _pos p; // 相对位置
|
|
m.x = rect_width(rect) + 1;
|
|
m.y = rect_height(rect) + 1;
|
|
|
|
switch (iLineDirection)
|
|
{
|
|
case 0://电缆布线X方向
|
|
{
|
|
if ((iElecNum / m.x) % 2 == 0)
|
|
{
|
|
//pos.x = iElecNum % X_ELEC_NUMBER;
|
|
pos->x = iElecNum % m.x - 1;
|
|
pos->y = iElecNum / m.x;
|
|
if (iElecNum / m.x != 0 && iElecNum % m.x == 0)
|
|
{
|
|
pos->x = 0;
|
|
pos->y = iElecNum / m.x - 1;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//pos.x = X_ELEC_NUMBER - iElecNum % X_ELEC_NUMBER + 1;
|
|
pos->x = m.x - iElecNum % m.x;
|
|
pos->y = iElecNum / m.x;
|
|
if (iElecNum / m.x != 0 && iElecNum % m.x == 0)//说明是偶数行
|
|
{
|
|
//pos.x = X_ELEC_NUMBER;
|
|
pos->x = m.x - 1;
|
|
pos->y = iElecNum / m.x - 1;
|
|
}
|
|
|
|
}
|
|
}
|
|
break;
|
|
case 1://电缆布线Y方向
|
|
{
|
|
if ((iElecNum / m.y) % 2 == 0)
|
|
{
|
|
//pos.x = iElecNum % X_ELEC_NUMBER;
|
|
pos->y = iElecNum % m.y - 1;
|
|
pos->x = iElecNum / m.y;
|
|
if (iElecNum / m.y != 0 && iElecNum % m.y == 0)
|
|
{
|
|
pos->y = 0;
|
|
pos->x = iElecNum / m.y - 1;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//pos.x = X_ELEC_NUMBER - iElecNum % X_ELEC_NUMBER + 1;
|
|
pos->y = m.y - iElecNum % m.y;
|
|
pos->x = iElecNum / m.y;
|
|
if (iElecNum / m.y != 0 && iElecNum % m.y == 0)//说明是偶数行
|
|
{
|
|
//pos.x = X_ELEC_NUMBER;
|
|
pos->y = m.y - 1;
|
|
pos->x = iElecNum / m.y - 1;
|
|
}
|
|
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
static struct _point *_PolePole(struct _rect *rect, struct _pos *a, int n, double spacing_x, double spacing_y)
|
|
{
|
|
struct _pos C1, P1;
|
|
struct _point *point_head = NULL;
|
|
struct _point *point;
|
|
|
|
if (a->x == 0 && a->y == 0 || n <= 0)
|
|
return NULL;
|
|
|
|
struct _pos k;
|
|
double Kx = 0, Ky = 0;
|
|
for (C1.y = rect->y0; C1.y <= rect->y1; C1.y++)
|
|
{
|
|
P1.y = C1.y + a->y;
|
|
|
|
if (P1.y > rect->y1 || P1.y < rect->y0)
|
|
continue;
|
|
|
|
for (C1.x = rect->x0; C1.x <= rect->x1; C1.x++)
|
|
{
|
|
P1.x = C1.x + a->x;
|
|
|
|
if (P1.x > rect->x1 || P1.x < rect->x0)
|
|
continue;
|
|
|
|
point = (struct _point *)malloc(sizeof(struct _point));
|
|
if (point)
|
|
{
|
|
k.x = P1.x - C1.x;
|
|
k.y = P1.y - C1.y;
|
|
|
|
Kx = (double)(k.x * spacing_x);
|
|
Ky = (double)(k.y * spacing_y);
|
|
|
|
point->C1.x = C1.x;
|
|
point->C1.y = C1.y;
|
|
|
|
point->C2.x = -1;
|
|
point->C2.y = -1;
|
|
|
|
point->P1.x = P1.x;
|
|
point->P1.y = P1.y;
|
|
|
|
point->P2.x = -1;
|
|
point->P2.y = -1;
|
|
|
|
point->KS = 2 * 3.1415926 * sqrt(1.0 * Kx * Kx + Ky * Ky);
|
|
|
|
if (!point_head)
|
|
{
|
|
point_head = point;
|
|
point->next = point->prev = point;
|
|
}
|
|
else
|
|
{
|
|
point_head->prev->next = point;
|
|
point->prev = point_head->prev;
|
|
point_head->prev = point;
|
|
point->next = point_head;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return point_head;
|
|
}
|
|
|
|
static struct _point *_Gradient(struct _rect *rect, struct _pos *C1, struct _pos *C2, double spacing_x, double spacing_y)
|
|
{
|
|
struct _pos P1, P2;
|
|
struct _point *point_head = NULL;
|
|
int n;
|
|
|
|
for (P1.x = rect->x0; P1.x < rect->x1; P1.x++)
|
|
{
|
|
// for (P2.x = P1.x + 1; P2.x <= rect->x1; P2.x++)
|
|
// {
|
|
P2.x = P1.x + 1;
|
|
for (P1.y = rect->y0; P1.y <= rect->y1; P1.y++)
|
|
{
|
|
struct _point *point;
|
|
P2.y = P1.y;
|
|
point = (struct _point *)malloc(sizeof(struct _point));
|
|
if (point)
|
|
{
|
|
struct _pos a;
|
|
double k = 0.0;
|
|
double Kx = 0.0, Ky = 0.0;
|
|
|
|
point->C1.x = -1; // C1->x;
|
|
point->C1.y = -1; // C1->y;
|
|
|
|
point->C2.x = -1; // C2->x;
|
|
point->C2.y = -1; // C2->y;
|
|
|
|
point->P1.x = P1.x;
|
|
point->P1.y = P1.y;
|
|
|
|
point->P2.x = P2.x;
|
|
point->P2.y = P2.y;
|
|
|
|
a.x = P1.x - C1->x;
|
|
a.y = P1.y - C1->y;
|
|
Kx = (double)(a.x * spacing_x);
|
|
Ky = (double)(a.y * spacing_y);
|
|
k += 1.0 / sqrt(1.0 * Kx * Kx + Ky * Ky); // 1/AM
|
|
|
|
a.x = P2.x - C2->x;
|
|
a.y = P2.y - C2->y;
|
|
Kx = (double)(a.x * spacing_x);
|
|
Ky = (double)(a.y * spacing_y);
|
|
k += 1.0 / sqrt(1.0 * Kx * Kx + Ky * Ky); // 1/BN
|
|
|
|
a.x = P2.x - C1->x;
|
|
a.y = P2.y - C1->y;
|
|
Kx = (double)(a.x * spacing_x);
|
|
Ky = (double)(a.y * spacing_y);
|
|
k -= 1.0 / sqrt(1.0 * Kx * Kx + Ky * Ky); // 1/AN
|
|
|
|
a.x = P1.x - C2->x;
|
|
a.y = P1.y - C2->y;
|
|
Kx = (double)(a.x * spacing_x);
|
|
Ky = (double)(a.y * spacing_y);
|
|
k -= 1.0 / sqrt(1.0 * Kx * Kx + Ky * Ky); // 1/BM
|
|
|
|
k = (k > 0.0) ? k : -k;
|
|
point->KS = 2 * 3.1415926 / k;
|
|
|
|
if (!point_head)
|
|
{
|
|
point_head = point;
|
|
point->next = point->prev = point;
|
|
}
|
|
else
|
|
{
|
|
point_head->prev->next = point;
|
|
point->prev = point_head->prev;
|
|
point_head->prev = point;
|
|
point->next = point_head;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
return point_head;
|
|
}
|
|
|
|
//0716日注释,中梯扫面,需求有变动
|
|
// static struct _point *_Gradient(struct _rect *rect, struct _pos *C1, struct _pos *C2, double spacing_x, double spacing_y)
|
|
// {
|
|
// struct _pos P1, P2;
|
|
// struct _point *point_head = NULL;
|
|
// int n;
|
|
//
|
|
// for (P1.x = rect->x0; P1.x < rect->x1; P1.x++)
|
|
// {
|
|
// for (P2.x = P1.x + 1; P2.x <= rect->x1; P2.x++)
|
|
// {
|
|
// for (P1.y = rect->y0; P1.y <= rect->y1; P1.y++)
|
|
// {
|
|
// struct _point *point;
|
|
// P2.y = P1.y;
|
|
// point = (struct _point *)malloc(sizeof(struct _point));
|
|
// if (point)
|
|
// {
|
|
// struct _pos a;
|
|
// double k = 0.0;
|
|
// double Kx = 0.0, Ky = 0.0;
|
|
//
|
|
// point->C1.x = -1; // C1->x;
|
|
// point->C1.y = -1; // C1->y;
|
|
//
|
|
// point->C2.x = -1; // C2->x;
|
|
// point->C2.y = -1; // C2->y;
|
|
//
|
|
// point->P1.x = P1.x;
|
|
// point->P1.y = P1.y;
|
|
//
|
|
// point->P2.x = P2.x;
|
|
// point->P2.y = P2.y;
|
|
//
|
|
// a.x = P1.x - C1->x;
|
|
// a.y = P1.y - C1->y;
|
|
// Kx = (double)(a.x * spacing_x);
|
|
// Ky = (double)(a.y * spacing_y);
|
|
// k += 1.0 / sqrt(1.0 * Kx * Kx + Ky * Ky); // 1/AM
|
|
//
|
|
// a.x = P2.x - C2->x;
|
|
// a.y = P2.y - C2->y;
|
|
// Kx = (double)(a.x * spacing_x);
|
|
// Ky = (double)(a.y * spacing_y);
|
|
// k += 1.0 / sqrt(1.0 * Kx * Kx + Ky * Ky); // 1/BN
|
|
//
|
|
// a.x = P2.x - C1->x;
|
|
// a.y = P2.y - C1->y;
|
|
// Kx = (double)(a.x * spacing_x);
|
|
// Ky = (double)(a.y * spacing_y);
|
|
// k -= 1.0 / sqrt(1.0 * Kx * Kx + Ky * Ky); // 1/AN
|
|
//
|
|
// a.x = P1.x - C2->x;
|
|
// a.y = P1.y - C2->y;
|
|
// Kx = (double)(a.x * spacing_x);
|
|
// Ky = (double)(a.y * spacing_y);
|
|
// k -= 1.0 / sqrt(1.0 * Kx * Kx + Ky * Ky); // 1/BM
|
|
//
|
|
// k = (k > 0.0) ? k : -k;
|
|
// point->KS = 2 * 3.1415926 / k;
|
|
//
|
|
// if (!point_head)
|
|
// {
|
|
// point_head = point;
|
|
// point->next = point->prev = point;
|
|
// }
|
|
// else
|
|
// {
|
|
// point_head->prev->next = point;
|
|
// point->prev = point_head->prev;
|
|
// point_head->prev = point;
|
|
// point->next = point_head;
|
|
//
|
|
// }
|
|
// }
|
|
// }
|
|
//
|
|
// }
|
|
//
|
|
// }
|
|
//
|
|
// return point_head;
|
|
// }
|
|
|
|
static struct _point *_PoleDipole(struct _rect *rect, struct _pos *a, int n, double spacing_x, double spacing_y)
|
|
{
|
|
struct _pos C1, P1, P2;
|
|
struct _point *point_head = NULL;
|
|
double Kx = 0.0,Ky = 0.0;
|
|
|
|
if (a->x == 0 && a->y == 0 || n <= 0)
|
|
return NULL;
|
|
|
|
for (C1.y = rect->y0; C1.y <= rect->y1; C1.y++)
|
|
{
|
|
P1.y = C1.y + a->y * n;
|
|
P2.y = P1.y + a->y;
|
|
|
|
if (P2.y > rect->y1 || P2.y < rect->y0)
|
|
continue;
|
|
|
|
for (C1.x = rect->x0; C1.x <= rect->x1; C1.x++)
|
|
{
|
|
P1.x = C1.x + a->x * n;
|
|
P2.x = P1.x + a->x;
|
|
|
|
if (P2.x > rect->x1 || P2.x < rect->x0)
|
|
continue;
|
|
|
|
if (_InTrig(a, n, &C1, &P1) &&
|
|
_InTrig(a, 1, &P1, &P2))
|
|
{
|
|
struct _point *point = (struct _point *)malloc(sizeof(struct _point));
|
|
if (point)
|
|
{
|
|
point->C1.x = C1.x;
|
|
point->C1.y = C1.y;
|
|
|
|
point->C2.x = -1;
|
|
point->C2.y = -1;
|
|
|
|
point->P1.x = P1.x;
|
|
point->P1.y = P1.y;
|
|
|
|
point->P2.x = P2.x;
|
|
point->P2.y = P2.y;
|
|
|
|
Kx = (double)(a->x * spacing_x);
|
|
Ky = (double)(a->y * spacing_y);
|
|
|
|
point->KS = 2 * 3.1415926 * n * (n + 1) * sqrt(1.0 * Kx * Kx + Ky * Ky);
|
|
|
|
if (!point_head)
|
|
{
|
|
point_head = point;
|
|
point->next = point->prev = point;
|
|
}
|
|
else
|
|
{
|
|
point_head->prev->next = point;
|
|
point->prev = point_head->prev;
|
|
point_head->prev = point;
|
|
point->next = point_head;
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
return point_head;
|
|
|
|
}
|
|
static struct _point *_DipoleDipole(struct _rect *rect, struct _pos *a, int n, double spacing_x, double spacing_y)
|
|
{
|
|
struct _pos C1, C2, P1, P2;
|
|
struct _point *point_head = NULL;
|
|
double Kx = 0.0, Ky = 0.0;
|
|
|
|
if (a->x == 0 && a->y == 0 || n <= 0)
|
|
return NULL;
|
|
|
|
for (C2.y = rect->y0; C2.y <= rect->y1; C2.y++)
|
|
{
|
|
C1.y = C2.y + a->y;
|
|
P1.y = C1.y + a->y * n;
|
|
P2.y = P1.y + a->y;
|
|
|
|
if (P2.y > rect->y1 || P2.y < rect->y0)
|
|
continue;
|
|
|
|
for (C2.x = rect->x0; C2.x <= rect->x1; C2.x++)
|
|
{
|
|
C1.x = C2.x + a->x;
|
|
P1.x = C1.x + a->x * n;
|
|
P2.x = P1.x + a->x;
|
|
|
|
if (P2.x > rect->x1 || P2.x < rect->x0)
|
|
continue;
|
|
|
|
if (_InTrig(a, 1, &C2, &C1) &&
|
|
_InTrig(a, n, &C1, &P1) &&
|
|
_InTrig(a, 1, &P1, &P2))
|
|
{
|
|
struct _point *point = (struct _point *)malloc(sizeof(struct _point));
|
|
if (point)
|
|
{
|
|
point->C1.x = C1.x;
|
|
point->C1.y = C1.y;
|
|
|
|
point->C2.x = C2.x;
|
|
point->C2.y = C2.y;
|
|
|
|
point->P1.x = P1.x;
|
|
point->P1.y = P1.y;
|
|
|
|
point->P2.x = P2.x;
|
|
point->P2.y = P2.y;
|
|
|
|
|
|
Kx = (double)(a->x * spacing_x);
|
|
Ky = (double)(a->y * spacing_y);
|
|
|
|
point->KS = 3.1415926 * n * (n + 1) * (n + 2) * sqrt(1.0 * Kx * Kx + Ky * Ky);
|
|
if (!point_head)
|
|
{
|
|
point_head = point;
|
|
point->next = point->prev = point;
|
|
}
|
|
else
|
|
{
|
|
point_head->prev->next = point;
|
|
point->prev = point_head->prev;
|
|
point_head->prev = point;
|
|
point->next = point_head;
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
return point_head;
|
|
|
|
}
|
|
static struct _point *_Schlumberger(struct _rect *rect, struct _pos *a, int n, double spacing_x, double spacing_y)
|
|
{
|
|
struct _pos C1, C2, P1, P2;
|
|
struct _point *point_head = NULL;
|
|
double Kx = 0.0, Ky = 0.0;
|
|
|
|
if (a->x == 0 && a->y == 0 || n <= 0)
|
|
return NULL;
|
|
|
|
for (C1.y = rect->y0; C1.y <= rect->y1; C1.y++)
|
|
{
|
|
C1.y = C1.y + a->y * (0);
|
|
P1.y = C1.y + a->y * (0 + n);
|
|
P2.y = C1.y + a->y * (0 + n + 1);
|
|
C2.y = C1.y + a->y * (0 + n + 1 + n);
|
|
|
|
if (C2.y > rect->y1 || C2.y < rect->y0)
|
|
continue;
|
|
|
|
for (C1.x = rect->x0; C1.x <= rect->x1; C1.x++)
|
|
{
|
|
C1.x = C1.x + a->x * (0);
|
|
P1.x = C1.x + a->x * (0 + n);
|
|
P2.x = C1.x + a->x * (0 + n + 1);
|
|
C2.x = C1.x + a->x * (0 + n + 1 + n);
|
|
|
|
if (C2.x > rect->x1 || C2.x < rect->x0)
|
|
continue;
|
|
|
|
if (_InTrig(a, n, &C1, &P1) &&
|
|
_InTrig(a, 1, &P1, &P2) &&
|
|
_InTrig(a, n, &P2, &C2))
|
|
{
|
|
struct _point *point = (struct _point *)malloc(sizeof(struct _point));
|
|
if (point)
|
|
{
|
|
point->C1.x = C1.x;
|
|
point->C1.y = C1.y;
|
|
|
|
point->C2.x = C2.x;
|
|
point->C2.y = C2.y;
|
|
|
|
point->P1.x = P1.x;
|
|
point->P1.y = P1.y;
|
|
|
|
point->P2.x = P2.x;
|
|
point->P2.y = P2.y;
|
|
|
|
Kx = (double)(a->x * spacing_x);
|
|
Ky = (double)(a->y * spacing_y);
|
|
|
|
point->KS = 3.1415926 * n * (n + 1) * sqrt(1.0 * Kx * Kx + Ky * Ky);
|
|
if (!point_head)
|
|
{
|
|
point_head = point;
|
|
point->next = point->prev = point;
|
|
}
|
|
else
|
|
{
|
|
point_head->prev->next = point;
|
|
point->prev = point_head->prev;
|
|
point_head->prev = point;
|
|
point->next = point_head;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
return point_head;
|
|
|
|
}
|
|
static struct _point *_WennerAlfa(struct _rect *rect, struct _pos *a, int n, double spacing_x, double spacing_y)
|
|
{
|
|
struct _pos C1, C2, P1, P2;
|
|
struct _point *point_head = NULL;
|
|
double Kx = 0.0, Ky = 0.0;
|
|
|
|
if (a->x == 0 && a->y == 0 || n <= 0)
|
|
return NULL;
|
|
|
|
for (C1.y = rect->y0; C1.y <= rect->y1; C1.y++)
|
|
{
|
|
C1.y = C1.y + a->y * (0);
|
|
P1.y = C1.y + a->y * (0 + 1);
|
|
P2.y = C1.y + a->y * (0 + 1 + 1);
|
|
C2.y = C1.y + a->y * (0 + 1 + 1 + 1);
|
|
|
|
if (C2.y > rect->y1 || C2.y < rect->y0)
|
|
continue;
|
|
|
|
for (C1.x = rect->x0; C1.x <= rect->x1; C1.x++)
|
|
{
|
|
C1.x = C1.x + a->x * (0);
|
|
P1.x = C1.x + a->x * (0 + 1);
|
|
P2.x = C1.x + a->x * (0 + 1 + 1);
|
|
C2.x = C1.x + a->x * (0 + 1 + 1 + 1);
|
|
|
|
if (C2.x > rect->x1 || C2.x < rect->x0)
|
|
continue;
|
|
|
|
if (_InTrig(a, 1, &C1, &P1) &&
|
|
_InTrig(a, 1, &P1, &P2) &&
|
|
_InTrig(a, 1, &P2, &C2))
|
|
{
|
|
struct _point *point = (struct _point *)malloc(sizeof(struct _point));
|
|
if (point)
|
|
{
|
|
point->C1.x = C1.x;
|
|
point->C1.y = C1.y;
|
|
|
|
point->C2.x = C2.x;
|
|
point->C2.y = C2.y;
|
|
|
|
point->P1.x = P1.x;
|
|
point->P1.y = P1.y;
|
|
|
|
point->P2.x = P2.x;
|
|
point->P2.y = P2.y;
|
|
|
|
Kx = (double)(a->x * spacing_x);
|
|
Ky = (double)(a->y * spacing_y);
|
|
|
|
point->KS = 3.1415926 * 2.0 * sqrt(1.0 * Kx * Kx + Ky * Ky);
|
|
if (!point_head)
|
|
{
|
|
point_head = point;
|
|
point->next = point->prev = point;
|
|
}
|
|
else
|
|
{
|
|
point_head->prev->next = point;
|
|
point->prev = point_head->prev;
|
|
point_head->prev = point;
|
|
point->next = point_head;
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
return point_head;
|
|
|
|
}
|
|
static struct _point *_WennerBeta(struct _rect *rect, struct _pos *a, int n, double spacing_x, double spacing_y)
|
|
{
|
|
struct _pos C1, C2, P1, P2;
|
|
struct _point *point_head = NULL;
|
|
double Kx = 0.0, Ky = 0.0;
|
|
|
|
if (a->x == 0 && a->y == 0 || n <= 0)
|
|
return NULL;
|
|
|
|
for (C2.y = rect->y0; C2.y <= rect->y1; C2.y++)
|
|
{
|
|
C2.y = C2.y + a->y * (0);
|
|
C1.y = C2.y + a->y * (0 + 1);
|
|
P1.y = C2.y + a->y * (0 + 1 + 1);
|
|
P2.y = C2.y + a->y * (0 + 1 + 1 + 1);
|
|
|
|
if (P2.y > rect->y1 || P2.y < rect->y0)
|
|
continue;
|
|
|
|
for (C2.x = rect->x0; C2.x <= rect->x1; C2.x++)
|
|
{
|
|
C2.x = C2.x + a->x * (0);
|
|
C1.x = C2.x + a->x * (0 + 1);
|
|
P1.x = C2.x + a->x * (0 + 1 + 1);
|
|
P2.x = C2.x + a->x * (0 + 1 + 1 + 1);
|
|
|
|
if (P2.x > rect->x1 || P2.x < rect->x0)
|
|
continue;
|
|
|
|
if (_InTrig(a, 1, &C2, &C1) &&
|
|
_InTrig(a, 1, &C1, &P1) &&
|
|
_InTrig(a, 1, &P1, &P2))
|
|
{
|
|
|
|
struct _point *point = NULL;
|
|
point = (struct _point *)malloc(sizeof(struct _point));
|
|
|
|
if (point)
|
|
{
|
|
point->C1.x = C1.x;
|
|
point->C1.y = C1.y;
|
|
|
|
point->C2.x = C2.x;
|
|
point->C2.y = C2.y;
|
|
|
|
point->P1.x = P1.x;
|
|
point->P1.y = P1.y;
|
|
|
|
point->P2.x = P2.x;
|
|
point->P2.y = P2.y;
|
|
|
|
Kx = (double)(a->x * spacing_x);
|
|
Ky = (double)(a->y * spacing_y);
|
|
|
|
point->KS = 3.1415926 * 6.0 * sqrt(1.0 * Kx * Kx + Ky * Ky);
|
|
point->next = point->prev = point;
|
|
if (!point_head)
|
|
{
|
|
point_head = point;
|
|
}
|
|
else
|
|
{
|
|
point_head->prev->next = point;
|
|
point->prev = point_head->prev;
|
|
point_head->prev = point;
|
|
point->next = point_head;
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
return point_head;
|
|
|
|
}
|
|
|
|
// 只针对"Pole-Dipole"和"Dipole-Dipole"生成, 对"Pole-Pole"直接调用PolePole()接口.
|
|
static struct _point *_Genarate(struct _rect *rect, int zone, int type, int is_diagonal45, double spacing_x, double spacing_y)
|
|
{
|
|
// TODO: 在此添加控件通知处理程序代码
|
|
struct _pos a;
|
|
struct _rect a_rect;
|
|
struct _point *point_head = NULL;
|
|
int n, m;
|
|
struct _point *(*func)(struct _rect *rect, struct _pos *a, int n, double spacing_x, double spacing_y);
|
|
switch (type)
|
|
{
|
|
case MEDIUM_TYPE_PoleDipole:
|
|
func = _PoleDipole;
|
|
m = max(rect_width(rect), rect_height(rect));
|
|
break;
|
|
case MEDIUM_TYPE_DipoleDipole:
|
|
func = _DipoleDipole;
|
|
m = max(rect_width(rect), rect_height(rect));
|
|
break;
|
|
case MEDIUM_TYPE_Schlumberger:
|
|
func = _Schlumberger;
|
|
m = max(rect_width(rect), rect_height(rect));
|
|
break;
|
|
case MEDIUM_TYPE_WennerAlfa:
|
|
func = _WennerAlfa;
|
|
m = 1;
|
|
break;
|
|
case MEDIUM_TYPE_WennerBeta:
|
|
func = _WennerBeta;
|
|
m = 1;
|
|
break;
|
|
case MEDIUM_TYPE_PolePole:
|
|
func = _PolePole;
|
|
// m = max(rect_width(rect), rect_height(rect));
|
|
m = 1;
|
|
break;
|
|
default:
|
|
return NULL;
|
|
}
|
|
|
|
switch (zone)
|
|
{
|
|
case 0:
|
|
a_rect.x0 = 0;
|
|
a_rect.x1 = +(rect->x1 - rect->x0);
|
|
a_rect.y0 = 0;
|
|
a_rect.y1 = 0;
|
|
break;
|
|
|
|
case 1:
|
|
a_rect.x0 = 1;
|
|
a_rect.x1 = +(rect->x1 - rect->x0);
|
|
a_rect.y0 = 1;
|
|
a_rect.y1 = +(rect->y1 - rect->y0);
|
|
break;
|
|
|
|
case 2:
|
|
a_rect.x0 = 0;
|
|
a_rect.x1 = 0;
|
|
a_rect.y0 = 0;
|
|
a_rect.y1 = +(rect->y1 - rect->y0);
|
|
break;
|
|
|
|
case 3:
|
|
a_rect.x0 = -(rect->x1 - rect->x0);
|
|
a_rect.x1 = -1;
|
|
a_rect.y0 = 1;
|
|
a_rect.y1 = +(rect->y1 - rect->y0);
|
|
break;
|
|
|
|
case 4:
|
|
a_rect.x0 = -(rect->x1 - rect->x0);
|
|
a_rect.x1 = 0;
|
|
a_rect.y0 = 0;
|
|
a_rect.y1 = 0;
|
|
break;
|
|
|
|
case 5:
|
|
a_rect.x0 = -(rect->x1 - rect->x0);
|
|
a_rect.x1 = -1;
|
|
a_rect.y0 = -(rect->y1 - rect->y0);
|
|
a_rect.y1 = -1;
|
|
break;
|
|
|
|
case 6:
|
|
a_rect.x0 = 0;
|
|
a_rect.x1 = 0;
|
|
a_rect.y0 = -(rect->y1 - rect->y0);
|
|
a_rect.y1 = 0;
|
|
break;
|
|
|
|
case 7:
|
|
a_rect.x0 = 1;
|
|
a_rect.x1 = +(rect->x1 - rect->x0);
|
|
a_rect.y0 = -(rect->y1 - rect->y0);
|
|
a_rect.y1 = -1;
|
|
break;
|
|
default:
|
|
return NULL;
|
|
}
|
|
|
|
for (n = 1; n <= m; n++)
|
|
{
|
|
for (a.y = a_rect.y0; a.y <= a_rect.y1; a.y++)
|
|
{
|
|
for (a.x = a_rect.x0; a.x <= a_rect.x1; a.x++)
|
|
{
|
|
static struct _point *points;
|
|
if (is_diagonal45 && _abs(a.x) != _abs(a.y) && a.x * a.y != 0)
|
|
continue;
|
|
|
|
points = func(rect, &a, n, spacing_x, spacing_y);
|
|
|
|
if (!point_head)
|
|
point_head = points;
|
|
else
|
|
_Append(point_head, points);
|
|
}
|
|
}
|
|
}
|
|
return point_head;
|
|
}
|
|
|
|
// 应用接口
|
|
int scr_generate(struct _scriptor *scr)
|
|
{
|
|
int index;
|
|
struct _point *points, *node;
|
|
|
|
if (!scr || scr->type < 0)
|
|
return 0;
|
|
|
|
// if (scr->type == MEDIUM_TYPE_PolePole)
|
|
// {
|
|
// scr->point_head = _PolePole(&scr->rect);
|
|
// goto __convert;
|
|
// }
|
|
if (scr->type == MEDIUM_TYPE_Gradient)
|
|
{
|
|
scr->point_head = _Gradient(&scr->rect, &scr->C1, &scr->C2, scr->spacing.x, scr->spacing.y);
|
|
goto __convert;
|
|
}
|
|
for (index = 0; index < sizeof(scr->zone) / sizeof(scr->zone[0]); index++)
|
|
{
|
|
if (1 == scr->zone[index])
|
|
{
|
|
|
|
if (scr->flags & ONLY_45DIAGONAL)
|
|
points = _Genarate(&scr->rect, index, scr->type, 1, scr->spacing.x, scr->spacing.y);
|
|
else
|
|
points = _Genarate(&scr->rect, index, scr->type, 0, scr->spacing.x, scr->spacing.y);
|
|
if (!scr->point_head)
|
|
scr->point_head = points;
|
|
else
|
|
_Append(scr->point_head, points);
|
|
|
|
|
|
//if (scr->flags & ONLY_45DIAGONAL)
|
|
// points = _Genarate(&scr->rect, index, scr->type, 1, scr->spacing.x, scr->spacing.y, scr->byTestLineDirection);
|
|
//else
|
|
// points = _Genarate(&scr->rect, index, scr->type, 0, scr->spacing.x, scr->spacing.y, scr->byTestLineDirection);
|
|
//if (!scr->point_head)
|
|
// scr->point_head = points;
|
|
//else
|
|
// _Append(scr->point_head, points);
|
|
}
|
|
}
|
|
__convert:
|
|
index = 1;
|
|
for (node = scr->point_head; node;)
|
|
{
|
|
node->TSN = index++;
|
|
if (MEDIUM_TYPE_PolePole == scr->type)
|
|
{
|
|
node->A = pos_to_pole_by_noraml_axis(&scr->rect, scr->pole_start, scr->step.x,scr->step.y, &node->C1);
|
|
node->B = pos_to_pole_by_noraml_axis(&scr->rect, scr->pole_start, scr->step.x,scr->step.y, &node->C2);
|
|
node->M = pos_to_pole_by_noraml_axis(&scr->rect, scr->pole_start, scr->step.x,scr->step.y, &node->P1);
|
|
node->N = pos_to_pole_by_noraml_axis(&scr->rect, scr->pole_start, scr->step.x,scr->step.y, &node->P2);
|
|
}
|
|
else
|
|
{
|
|
node->A = pos_to_pole(&scr->rect, scr->pole_start, scr->step.x,scr->step.y, &node->C1);
|
|
node->B = pos_to_pole(&scr->rect, scr->pole_start, scr->step.x,scr->step.y, &node->C2);
|
|
node->M = pos_to_pole(&scr->rect, scr->pole_start, scr->step.x,scr->step.y, &node->P1);
|
|
node->N = pos_to_pole(&scr->rect, scr->pole_start, scr->step.x,scr->step.y, &node->P2);
|
|
}
|
|
|
|
if (node->next == scr->point_head)
|
|
break;
|
|
node = node->next;
|
|
}
|
|
|
|
return 1;
|
|
|
|
// str = scr->zone;
|
|
// while (str && *str)
|
|
// {
|
|
// struct _point *points;
|
|
// zone_index = atoi(str);
|
|
// if (scr->flags & ONLY_45DIAGONAL)
|
|
// points = _Genarate(&scr->rect, zone_index, scr->type, 1);
|
|
// else
|
|
// points = _Genarate(&scr->rect, zone_index, scr->type, 0);
|
|
// if (!scr->point_head)
|
|
// scr->point_head = points;
|
|
// else
|
|
// _Append(scr->point_head, points);
|
|
//
|
|
// if (str = strchr(str, ','))
|
|
// str += 1;
|
|
// }
|
|
// return 1;
|
|
}
|
|
|
|
const char *scr_get_name(struct _scriptor *scr)
|
|
{
|
|
if (scr)
|
|
return scr->name;
|
|
return NULL;
|
|
}
|
|
|
|
int scr_set_name(struct _scriptor *scr, const char *name)
|
|
{
|
|
if (!scr || !name)
|
|
return MEDIUM_TYPE_UNKNOW;
|
|
if (scr->name)
|
|
free((char *)scr->name);
|
|
// scr->name = strdup(name);
|
|
{
|
|
scr->name = malloc(strlen(name) + 1);
|
|
strcpy((char *)scr->name, name);
|
|
}
|
|
|
|
if (0 == strcmp(name, "Pole-Pole"))
|
|
{
|
|
scr->type = MEDIUM_TYPE_PolePole;
|
|
}
|
|
else
|
|
if (0 == strcmp(name, "Pole-Dipole"))
|
|
{
|
|
scr->type = MEDIUM_TYPE_PoleDipole;
|
|
}
|
|
else
|
|
if (0 == strcmp(name, "Dipole-Dipole"))
|
|
{
|
|
scr->type = MEDIUM_TYPE_DipoleDipole;
|
|
}
|
|
else
|
|
if (0 == strcmp(name, "Schlumberger"))
|
|
{
|
|
scr->type = MEDIUM_TYPE_Schlumberger;
|
|
}
|
|
else
|
|
if (0 == strcmp(name, "WennerAlfa"))
|
|
{
|
|
scr->type = MEDIUM_TYPE_WennerAlfa;
|
|
}
|
|
else
|
|
if (0 == strcmp(name, "WennerBeta"))
|
|
{
|
|
scr->type = MEDIUM_TYPE_WennerBeta;
|
|
}
|
|
else
|
|
if (0 == strcmp(name, "Gradient"))
|
|
{
|
|
scr->type = MEDIUM_TYPE_Gradient;
|
|
}
|
|
else
|
|
{
|
|
scr->type = MEDIUM_TYPE_UNKNOW;
|
|
}
|
|
return scr->type;
|
|
}
|
|
|
|
int scr_get_type(struct _scriptor *scr)
|
|
{
|
|
if (scr)
|
|
return scr->type;
|
|
return MEDIUM_TYPE_UNKNOW;
|
|
}
|
|
unsigned int scr_get_flags(struct _scriptor *scr)
|
|
{
|
|
if (scr)
|
|
return scr->flags;
|
|
return 0;
|
|
}
|
|
void scr_set_flags(struct _scriptor *scr, unsigned int flags, int enable)
|
|
{
|
|
if (!scr)
|
|
return;
|
|
if (enable)
|
|
scr->flags |= flags;
|
|
else
|
|
scr->flags &= ~flags;
|
|
|
|
}
|
|
struct _rect *scr_get_rect(struct _scriptor *scr)
|
|
{
|
|
if (scr)
|
|
return &scr->rect;
|
|
return NULL;
|
|
}
|
|
void scr_set_rect(struct _scriptor *scr, struct _rect *rect)
|
|
{
|
|
if (!scr || !rect)
|
|
return;
|
|
scr->rect.x0 = rect->x0;
|
|
scr->rect.x1 = rect->x1;
|
|
scr->rect.y0 = rect->y0;
|
|
scr->rect.y1 = rect->y1;
|
|
|
|
|
|
// 12的倍数
|
|
// scr->pole_count = (scr->pole_count % 12) ? (scr->pole_count / 12 + 1) * 12 : scr->pole_count;
|
|
}
|
|
|
|
void scr_set_zone(struct _scriptor *scr, int enable, int zonec, int zonev[])
|
|
{
|
|
int zone_index, i;
|
|
if (!scr)
|
|
return;
|
|
|
|
for (i = 0; i < zonec; i++)
|
|
{
|
|
zone_index = zonev[i];
|
|
if (zone_index >= 0 &&
|
|
zone_index < sizeof(scr->zone) / sizeof(scr->zone[0]))
|
|
scr->zone[zone_index] = enable;
|
|
}
|
|
}
|
|
int scr_get_zone(struct _scriptor *scr, int zone_index)
|
|
{
|
|
if (scr &&
|
|
zone_index >= 0 &&
|
|
zone_index < sizeof(scr->zone) / sizeof(scr->zone[0]))
|
|
{
|
|
return scr->zone[zone_index];
|
|
}
|
|
return 0;
|
|
}
|
|
int scr_get_pole_count(struct _scriptor *scr)
|
|
{
|
|
// if (scr)
|
|
// {
|
|
// int pole_count = (rect_width(&scr->rect) * scr->step.x + 1) * (rect_height(&scr->rect) * scr->step.y + 1);
|
|
// return pole_count;
|
|
// }
|
|
|
|
if (scr)
|
|
{
|
|
//横向电极总数
|
|
int line_count = ( rect_width(&scr->rect) + 1 ) + ( rect_width(&scr->rect) * (scr->step.x - 1) ) + (scr->step.y - 1);
|
|
|
|
//横向电极总数*纵向坐标
|
|
int pole_count = line_count * (rect_height(&scr->rect) + 1 ) - (scr->step.y - 1);
|
|
|
|
return pole_count;
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
int scr_get_pole_start(struct _scriptor *scr)
|
|
{
|
|
if (scr)
|
|
return scr->pole_start;
|
|
return 0;
|
|
}
|
|
int scr_set_pole_start(struct _scriptor *scr, int startpole)
|
|
{
|
|
if (scr && startpole > 0 && startpole < scr_get_pole_count(scr))
|
|
{
|
|
scr->pole_start = startpole;
|
|
return 1;
|
|
}
|
|
return 0;
|
|
|
|
}
|
|
int scr_init_pole(struct _scriptor *scr, const char *tag, int x, int y)
|
|
{
|
|
if (!scr || !tag)
|
|
return -1;
|
|
switch (tag[0])
|
|
{
|
|
case 'C':
|
|
case 'c':
|
|
if ('1' == tag[1])
|
|
{
|
|
scr->C1.x = x;
|
|
scr->C1.y = y;
|
|
}
|
|
else
|
|
if ('2' == tag[1])
|
|
{
|
|
scr->C2.x = x;
|
|
scr->C2.y = y;
|
|
}
|
|
else
|
|
return -1;
|
|
break;
|
|
case 'P':
|
|
case 'p':
|
|
if ('1' == tag[1])
|
|
{
|
|
scr->P1.x = x;
|
|
scr->P1.y = y;
|
|
}
|
|
else
|
|
if ('2' == tag[1])
|
|
{
|
|
scr->P2.x = x;
|
|
scr->P2.y = y;
|
|
}
|
|
else
|
|
return -1;
|
|
break;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
struct _point *scr_get_points(struct _scriptor *scr)
|
|
{
|
|
if (scr)
|
|
return scr->point_head;
|
|
return NULL;
|
|
}
|
|
// CGeoScriptor 初始化
|
|
void scr_append_points(struct _scriptor *scr, struct _point *points)
|
|
{
|
|
if (scr)
|
|
_Append(scr->point_head, points);
|
|
}
|
|
void scr_remove_point(struct _scriptor *scr, struct _point *point)
|
|
{
|
|
if (!point)
|
|
return;
|
|
if (point = point->next)
|
|
scr->point_head = NULL;//最后一个
|
|
_Remove(point);
|
|
}
|
|
void scr_flush_points(struct _scriptor *scr)
|
|
{
|
|
if (scr)
|
|
{
|
|
_Flush(scr->point_head);
|
|
scr->point_head = NULL;
|
|
}
|
|
}
|
|
|
|
int scr_init(struct _scriptor *scr, const char *name, int flags, struct _rect *rect, int zonec, int zonev[])
|
|
{
|
|
if (!scr)
|
|
return 0;
|
|
memset(scr, 0, sizeof(struct _scriptor));
|
|
|
|
scr->type = scr_set_name(scr, name);
|
|
scr->flags = flags;
|
|
|
|
scr_set_rect(scr, rect);
|
|
// 默认从1号电极开始
|
|
scr->pole_start = 1;
|
|
|
|
memset(&scr->zone, 0, sizeof(scr->zone));
|
|
scr_set_zone(scr, 1, zonec, zonev);
|
|
|
|
scr->point_head = NULL;
|
|
|
|
return 1;
|
|
}
|
|
struct _scriptor *scr_create(const char *name, int flags, struct _rect *rect, int zone_count, ...)
|
|
{
|
|
va_list args;
|
|
struct _scriptor *scr = malloc(sizeof(struct _scriptor));
|
|
|
|
if (!scr)
|
|
return NULL;
|
|
|
|
va_start(args, zone_count);
|
|
scr_init(scr, name, flags, rect, zone_count, (int *)args);
|
|
va_end(args);
|
|
|
|
return scr;
|
|
}
|
|
void scr_destroy(struct _scriptor *scr)
|
|
{
|
|
if (!scr)
|
|
return;
|
|
if (scr->name)
|
|
{
|
|
free((char *)scr->name);
|
|
scr->name = NULL;
|
|
}
|
|
_Flush(scr->point_head);
|
|
scr->point_head = NULL;
|
|
free(scr);
|
|
}
|
|
|
|
int scr_set_pole_step(struct _scriptor *scr, int x_step, int y_step)
|
|
{
|
|
if (x_step < 0 || y_step < 0 || !scr)
|
|
{
|
|
return 0;//FALSE
|
|
}
|
|
|
|
scr->step.x = x_step;
|
|
|
|
scr->step.y = y_step;
|
|
|
|
return 1;//TRUE
|
|
}
|
|
|
|
int scr_get_pole_step(struct _scriptor *scr, int *x_step, int *y_step)
|
|
{
|
|
if (!scr)
|
|
return 0;
|
|
|
|
*x_step = scr->step.x;
|
|
|
|
*y_step = scr->step.y;
|
|
}
|
|
|
|
int scr_set_spacing(struct _scriptor *scr, double spacing_x, double spacing_y)
|
|
{
|
|
if (spacing_x < 0 || spacing_y < 0 || !scr)
|
|
{
|
|
return 0;//FALSE
|
|
}
|
|
|
|
scr->spacing.x = spacing_x;
|
|
|
|
scr->spacing.y = spacing_y;
|
|
|
|
return 1;//TRUE
|
|
|
|
}
|
|
int scr_get_spacing(struct _scriptor *scr, double *spacing_x, double *spacing_y)
|
|
{
|
|
if (!scr)
|
|
return 0;
|
|
|
|
*spacing_x = scr->spacing.x;
|
|
|
|
*spacing_y = scr->spacing.y;
|
|
|
|
}
|
|
|
|
/*
|
|
CString CovertVarToCString(const VARIANT& vtVal)
|
|
{
|
|
CString strText = _T("");
|
|
switch(vtVal.vt)
|
|
{
|
|
case VT_UI1:
|
|
strText.Format(_T("%d"),vtVal.bVal);
|
|
break;
|
|
|
|
case VT_I2:
|
|
strText.Format("%d",vtVal.iVal);
|
|
break;
|
|
|
|
case VT_I4:
|
|
strText.Format(_T("%d"),vtVal.lVal);
|
|
break;
|
|
|
|
case VT_I8:
|
|
strText.Format(_T("%d"),vtVal.llVal);
|
|
break;
|
|
|
|
case VT_INT:
|
|
strText.Format(_T("%d"),vtVal.intVal);
|
|
break;
|
|
|
|
case VT_R4:
|
|
strText.Format(_T("%f"),vtVal.fltVal);
|
|
break;
|
|
|
|
case VT_R8:
|
|
strText.Format(_T("%f"),vtVal.dblVal);
|
|
break;
|
|
|
|
case VT_BSTR:
|
|
strText=(CString)vtVal.bstrVal;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
return strText;
|
|
}
|
|
*/ |