#include <QString>
#include <QDebug>
#include "mapapi.h"
#include "sitapi.h"
#include "seekapi.h"
#include "rscapi.h"
#include "mapcreat.h"
#include "maptype.h"
HOBJ createPolygonObject(HMAP hmap, RECT* rect, int bgColor, int fgColor) {
HOBJ hobj = mapCreateObject(hmap, IDDOUBLE2, 0);
if (hobj != 0) {
if (mapRegisterDrawObject(hobj, 0, LOCAL_SQUARE) != 0) {
IMGPOLYGONGLASS fill;
memset((void*) &fill, 0, sizeof(fill));
fill.Color = bgColor;
fill.Transparency = 100;
mapAppendDraw(hobj, IMG_POLYGONGLASS, (const char*) &fill);
IMGLINE border;
memset((void*) &border, 0, sizeof(border));
border.Color = fgColor;
border.Thick = PIX2MKM(2);
mapAppendDraw(hobj, IMG_LINE, (const char*) &border);
double x1 = rect->left;
double y1 = rect->top;
double x2 = rect->right;
double y2 = rect->bottom;
mapPictureToPlane(hmap, &x1, &y1);
mapPictureToPlane(hmap, &x2, &y2);
mapAppendPointPlane(hobj, x1, y1, 0);
mapAppendPointPlane(hobj, x2, y1, 0);
mapAppendPointPlane(hobj, x2, y2, 0);
mapAppendPointPlane(hobj, x1, y2, 0);
mapAppendPointPlane(hobj, x1, y1, 0);
mapCommitObject(hobj);
} else {
qDebug() << "mapRegisterDrawObject error";
}
} else {
qDebug() << "mapCreateObject error";
}
return hobj;
}
HOBJ createLineObject(HMAP hmap, RECT* rect, int fgColor) {
HOBJ hobj = mapCreateObject(hmap, IDDOUBLE2, 0);
if (hobj != 0) {
if (mapRegisterDrawObject(hobj, 0, LOCAL_LINE) != 0) {
IMGLINE border;
memset((void*) &border, 0, sizeof(border));
border.Color = fgColor;
border.Thick = PIX2MKM(2);
mapAppendDraw(hobj, IMG_LINE, (const char*) &border);
double x1 = rect->left;
double y1 = rect->top;
double x2 = rect->right;
double y2 = rect->bottom;
mapPictureToPlane(hmap, &x1, &y1);
mapPictureToPlane(hmap, &x2, &y2);
mapAppendPointPlane(hobj, x1, y1, 0);
mapAppendPointPlane(hobj, x2, y1, 0);
mapAppendPointPlane(hobj, x2, y2, 0);
mapAppendPointPlane(hobj, x1, y2, 0);
mapAppendPointPlane(hobj, x1, y1, 0);
mapCommitObject(hobj);
} else {
qDebug() << "mapRegisterDrawObject error";
}
} else {
qDebug() << "mapCreateObject error";
}
return hobj;
}
HOBJ createObjectByKey(HMAP hmap, const char * key, int x, int y) {
HOBJ hobj = mapCreateObject(hmap, IDDOUBLE2, 0);
double x1 = x;
double y1 = y;
mapPictureToPlane(hmap, &x1, &y1);
if (hobj != 0) {
if (mapRegisterObjectByKey(hobj, key) != 0) {
mapAppendPointPlane(hobj, x1, y1, 0);
mapCommitObject(hobj);
} else {
qDebug() << "mapRegisterObjectByKey error";
}
} else {
qDebug() << "mapCreateObject error";
}
return hobj;
}
//создает карту с объектами для проведения теста
HMAP createMapForTest(QString* aName, QString* aClassifierName) {
CREATESITEUN cs;
memset((void*) &cs, 0, sizeof(cs));
cs.Length = sizeof(CREATESITEUN);
cs.EllipsoideKind = 9;
cs.MapType = 16;
cs.Reserve = 0;
HMAP hmap = mapCreateSiteUn((const WCHAR*) aName->constData(),
(const WCHAR*) aClassifierName->constData(), &cs);
if (hmap != 0) {
mapSetRealShowScale(hmap, 200000.);
//создадим рамку
RECT borderRect;
borderRect.left = 0;
borderRect.top = 0;
borderRect.right = 2000;
borderRect.bottom = 2000;
createLineObject(hmap, &borderRect, 0x00FF00);
//прямоугольники - примитивы
int w = 30;
int h = 30;
for (int i = 0; i < 3; i++) {
RECT rect1;
rect1.left = 900 + (i * 100);
rect1.top = 1000;
rect1.right = rect1.left + w;
rect1.bottom = rect1.top + h;
HOBJ hobj = createPolygonObject(hmap, &rect1, 0x00FFFF,
0xFF << (8 * i));
mapFreeObject(hobj);
}
//и какой-нибудь знак из классификатора
createObjectByKey(hmap, "009991001040", 1000, 1000);
} else {
qDebug() << "mapCreateSiteUn error";
}
return hmap;
}
// тест поиска объектов
int main(int argc, char ** argv) {
QString* siteName = new QString("/home/user/temp/testSearchByFrame.sitx");
QString* rscName = new QString("/home/user/temp/operator.rsc");
HMAP hmap = createMapForTest(siteName, rscName);
if (hmap != 0) {
mapCloseMap(hmap);
} else {
qDebug() << "createMapForTest error";
}
//переоткрываем карту
hmap = mapOpenAnyData((const WCHAR*) siteName->constData());
if (hmap != 0) {
mapSetRealShowScale(hmap, 200000.);
qDebug() << "map real object count: " << mapGetRealObjectCount(hmap, 1);
//ищем объекты без установки области поиска
HSELECT hselect = mapCreateSiteSelectContext(hmap, hmap);
mapSetDrawObjectsFlag(hselect, 1);
HOBJ result = mapCreateSiteObject(hmap, hmap, IDDOUBLE2, 0L);
long rc = mapSeekSelectObject(hmap, result, hselect, WO_FIRST);
int count = 0;
while (rc) {
count++;
rc = mapSeekSelectObject(hmap, result, hselect, WO_NEXT);
}
qDebug() << "search result count: " << count;
mapFreeObject(result);
mapDeleteSelectContext(hselect);
//ищем объекты по области равной габаритам карты
DFRAME frame;
mapGetTotalBorder(hmap, &frame, PP_PLANE);
hselect = mapCreateSiteSelectContext(hmap, hmap);
mapSetDrawObjectsFlag(hselect, 1);
mapSelectSeekAreaFrame(hselect, &frame, 0, 0,
SO_SEEKINSIDEANDCROSS, 1, 0);
result = mapCreateSiteObject(hmap, hmap, IDDOUBLE2, 0L);
rc = mapSeekSelectObject(hmap, result, hselect, WO_FIRST);
count = 0;
while (rc) {
count++;
rc = mapSeekSelectObject(hmap, result, hselect, WO_NEXT);
}
qDebug() << "search result by frame count: " << count;
mapFreeObject(result);
mapDeleteSelectContext(hselect);
mapCloseMap(hmap);
} else {
qDebug() << "mapOpenAnyData error";
}
}
|