You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kev/Drawer/Module/GeoSigmaDraw/InterfaceAddPoint.cpp

563 lines
14 KiB
C++

#include "stdafx.h"
#include "SigmaView.h"
#include "SectionDoc.h"
#include "ItemPointAdd.h"
#include "ItemPointCrossAdd.h"
#include "ActionAddItem.h"
#include "..\..\SSBase\VoronoiMap\PolygonTreeInterface.h"
#pragma pack(1)
struct Point2D
{
LPCTSTR pointName;
double x;
double y;
double z;
double angle;
};
#pragma pack()
#pragma pack(1)
struct CrossPoint2D
{
double x;
double y;
double angle;
LPCTSTR name1;
LPCTSTR name2;
LPCTSTR name3;
LPCTSTR name4;
};
#pragma pack()
#pragma pack(1)
struct FractionPoint
{
double x;
double y;
double angle;
LPCTSTR numeratorString;
LPCTSTR denominatorString;
};
#pragma pack()
static CPointNameEx * CreatePoint(double x, double y, double z, double angle, const char * pointName);
static CItemPointAdd * GetItemPointAddFromView(CSigmaView * pView);
static CItemPointCrossAdd * GetItemPointCrossAddFromView(CSigmaView * pView);
static CPointCrossName* CreateCrossPoint(CrossPoint2D * pt);
static CPointTwoName * CreateFractionPoint(FractionPoint * point);
//TODO:函数GetPoint2DFromItem重命名为PointAdd_GetPosition()
extern "C" __declspec(dllexport)
int GetPoint2DFromItem(CSigmaView* pView, Point2D * ptOut)
{
ptOut->x = ptOut->y = 0;
CItemPointAdd * itemPoint = GetItemPointAddFromView(pView);
if (itemPoint == NULL)
return -1;
double x = 0;
double y = 0;
double z = 0;
if (itemPoint->GetPoint(&x, &y, &z))
{
ptOut->x = x;
ptOut->y = y;
ptOut->z = z;
return 1;
}
return -2; //TODO:改成-1
}
extern "C" __declspec(dllexport)
void CancelDisplayPointInItem(CSigmaView* pView)
{
CItemPointAdd * itemPoint = GetItemPointAddFromView(pView);
if (itemPoint == NULL)
return;
itemPoint->ClearDisplayPoint();
}
//mode=0,单点.model=1,连续.
extern "C" __declspec(dllexport)
void ChangePointAddedMode(CSigmaView* pView, int mode)
{
CItemPointAdd * itemPoint = GetItemPointAddFromView(pView);
if (itemPoint == NULL)
return;
if (mode == 0)
itemPoint->SetMode(CItemPointAdd::POINT_MODE_SINGLE);
else if (mode == 1)
itemPoint->SetMode(CItemPointAdd::POINT_MODE_CONTINUE);
else
itemPoint->SetMode(CItemPointAdd::POINT_MODE_SINGLE);
}
//函数功能:设置待添加点的类型
//参数说明:type 0--普通点 1--分数点
extern "C" __declspec(dllexport)
int AddPoint2D_SetPointType(CSigmaView * pView, int type)
{
CItemPointAdd * pItem = GetItemPointAddFromView(pView);
if (pItem == 0)
return -1;
pItem->SetPointType((CItemPointAdd::POINT_TYPE)type);
return 1;
}
extern "C" __declspec(dllexport)
int AddPoint2DToDoc(CSigmaView * pView, Point2D * ptOut)
{
CItemPointAdd * pItem = GetItemPointAddFromView(pView);
if (pItem == 0)
return -1;
CPointNameEx * pt = CreatePoint(ptOut->x, ptOut->y, ptOut->z, ptOut->angle, ptOut->pointName);
POSITION pos = pItem->AddElement(pt, DOUBLEFOX_POINT);
return 1;
}
extern "C" __declspec(dllexport)
void PointAdd_UpdateDraw(CSigmaView * pView)
{
CItemPointAdd * pItem = GetItemPointAddFromView(pView);
if (pItem == 0)
return;
pItem->UpdateDraw();
}
extern "C" __declspec(dllexport)
int AddFractionPointToDoc(CSigmaView * pView, FractionPoint * ptOut)
{
CItemPointAdd * pItem = GetItemPointAddFromView(pView);
if (pItem == 0)
return -1;
CPointTwoName * pt = CreateFractionPoint(ptOut);
POSITION pos = pItem->AddElement(pt, DOUBLEFOX_TWOPOINT);
NBase::CPositionList items;
items.AddTail(pos);
pView->m_pDoc->SetActionItem(new CActionAddItem(pView->m_pDoc, IDS_STRING_ACTION_ADD, items));
return 1;
}
extern "C" __declspec(dllexport)
POSITION AddPoint(CSigmaView * pView, LPCTSTR layerName, Point2D ptOut)
{
CXy * pXy = pView->m_pDoc->m_pXy;
CLayer * pLayer = pXy->FindAddLayer(layerName);
pXy->SetCurrentLayer(pLayer);
CPointNameEx* pPoint = new CPointNameEx;
pPoint->x0 = ptOut.x;
pPoint->y0 = ptOut.y;
pPoint->z0 = ptOut.z;
pPoint->angle = ptOut.angle;
pPoint->SetName(ptOut.pointName);
COne *pOne = pXy->CreateOne(pPoint, DOUBLEFOX_POINT);
pOne->SetLayer(pLayer);
//pOne->SetColor(0);
pOne->SetViewState(LAYER_ViewEdit);
POSITION pos = pView->m_pDoc->m_pXy->AddTailOne(pOne);
pView->m_pDoc->SetActionItem(new CActionAddItem(pView->m_pDoc, IDS_STRING_ACTION_ADD, pOne));
return pos;
}
extern "C" __declspec(dllexport)
int AddPoints(CSigmaView * pView, Point2D *pPoints, int len, LPCTSTR layerName)
{
CXy * pXy = pView->m_pDoc->m_pXy;
CLayer * pLayer = pXy->FindAddLayer(layerName);
pXy->SetCurrentLayer(pLayer);
NBase::CPositionList items;
for (int i = 0; i < len; i++)
{
Point2D &ptOut = pPoints[i];
CPointNameEx* pPoint = new CPointNameEx;
pPoint->x0 = ptOut.x;
pPoint->y0 = ptOut.y;
pPoint->z0 = ptOut.z;
pPoint->angle = ptOut.angle;
pPoint->SetName(ptOut.pointName);
COne* pOne = pXy->CreateOne(pPoint, DOUBLEFOX_POINT);
pOne->SetLayer(pLayer);
//pOne->SetColor(0);
pOne->SetViewState(LAYER_ViewEdit);
POSITION pos = pView->m_pDoc->m_pXy->AddTailOne(pOne);
items.AddTail(pos);
}
pView->m_pDoc->SetActionItem(new CActionAddItem(pView->m_pDoc, IDS_STRING_ACTION_ADD, items));
return items.GetCount();
}
extern "C" __declspec(dllexport)
int AddPointSetDefaultName(CSigmaView * pView, LPCTSTR pointName)
{
CItemPointAdd * pItem = GetItemPointAddFromView(pView);
if (pItem == NULL)
return -2;
pItem->SetPointDefaultName(pointName);
return 1;
}
extern "C" __declspec(dllexport)
int AddPointSetDefaultZ(CSigmaView * pView, double z)
{
CItemPointAdd * pItem = GetItemPointAddFromView(pView);
if (pItem == NULL)
return -2;
pItem->SetPointDefaultZ(z);
return 1;
}
extern "C" __declspec(dllexport)
int AddPointNameToItem(CSigmaView * pView, HDC hdcMem, LPCTSTR pointName)
{
CItemPointAdd * pItem = GetItemPointAddFromView(pView);
if (pItem == NULL)
return -2;
pItem->SetBackGroundDC(pView->m_pImgDC);
CDC *pDC = CDC::FromHandle(hdcMem);
pItem->SetPointName(pDC, pointName);
return 1;
}
extern "C" __declspec(dllexport)
int AddNumeratorNameToItem(CSigmaView * pView, HDC hdcMem, LPCTSTR numeratorName)
{
CItemPointAdd * pItem = GetItemPointAddFromView(pView);
if (pItem == NULL)
return -2;
pItem->SetBackGroundDC(pView->m_pImgDC);
CDC *pDC = CDC::FromHandle(hdcMem);
pItem->SetNumeratorString(pDC, numeratorName);
return 1;
}
extern "C" __declspec(dllexport)
int AddDenominatorNameToItem(CSigmaView * pView, HDC hdcMem, LPCTSTR denominatorName)
{
CItemPointAdd * pItem = GetItemPointAddFromView(pView);
if (pItem == NULL)
return -2;
pItem->SetBackGroundDC(pView->m_pImgDC);
CDC *pDC = CDC::FromHandle(hdcMem);
pItem->SetDenominatorString(pDC, denominatorName);
return 1;
}
extern "C" __declspec(dllexport)
int AddPointSetAngle(CSigmaView * pView, HDC hdcMem, double angle)
{
CItemPointAdd * pItem = GetItemPointAddFromView(pView);
if (pItem == NULL)
return -2;
CDC *pDC = CDC::FromHandle(hdcMem);
pItem->SetPointAngle(pDC, angle);
return 1;
}
extern "C" __declspec(dllexport)
int AddPointSetX(CSigmaView * pView, HDC hdcMem, double x)
{
CItemPointAdd * pItem = GetItemPointAddFromView(pView);
if (pItem == NULL)
return -2;
CDC *pDC = CDC::FromHandle(hdcMem);
pItem->SetPointX(pDC, x);
return 1;
}
extern "C" __declspec(dllexport)
int AddPointSetY(CSigmaView * pView, HDC hdcMem, double y)
{
CItemPointAdd * pItem = GetItemPointAddFromView(pView);
if (pItem == NULL)
return -2;
CDC *pDC = CDC::FromHandle(hdcMem);
pItem->SetPointY(pDC, y);
return 1;
}
extern "C" __declspec(dllexport)
int AddPointSetZ(CSigmaView * pView, HDC hdcMem, double z)
{
CItemPointAdd * pItem = GetItemPointAddFromView(pView);
if (pItem == NULL)
return -2;
CDC *pDC = CDC::FromHandle(hdcMem);
pItem->SetPointZ(pDC, z);
return 1;
}
extern "C" __declspec(dllexport)
int ChangeAnglgeToItem(CSigmaView * pView, double angle)
{
CItemPointAdd * itemPoint = GetItemPointAddFromView(pView);
if (itemPoint == 0)
return -1;
itemPoint->ChangeAngle(angle);
return 1;
}
extern "C" __declspec(dllexport)
int CrossPoint_GetPosition(CSigmaView* pView, CrossPoint2D * ptOut)
{
ptOut->x = ptOut->y = 0;
CItemPointCrossAdd * itemPointCross = GetItemPointCrossAddFromView(pView);
if (itemPointCross == NULL)
return -1;
double x = 0;
double y = 0;
double z = 0;
if (itemPointCross->GetPoint(&x, &y, &z))
{
ptOut->x = x;
ptOut->y = y;
return 1;
}
return -1;
}
int XyInsertBufferDataBefore(CXy * pXy, LPCTSTR data, POSITION posDest, NBase::CPositionList& selections)
{
CMemFile memFile;
memFile.Write(data, lstrlen(data) * sizeof(TCHAR));
memFile.SeekToBegin();
CXy* pxyMerge = new CXy;
int nReturn = pxyMerge->DFD_Read(memFile);
pXy->MoveInBefore(pxyMerge, selections, posDest);
delete pxyMerge;
return nReturn;
}
extern "C" __declspec(dllexport)
int InsertBufferDataBefore(CSigmaView * pView, LPCTSTR data, POSITION posDest)
{
CXy* pXy = pView->m_pDoc->m_pXy;
NBase::CPositionList selections;
int nReturn = XyInsertBufferDataBefore(pXy, data, posDest, selections);
if (selections.GetSize() > 0)
{
CSigmaDoc* pDoc = pView->m_pDoc;
CActionAddItem * pAction = new CActionAddItem(pDoc, ID_CURVE_MERGE, selections);
pDoc->SetActionItem(pAction);
}
return nReturn;
}
extern "C" __declspec(dllexport)
int XyAddBufferData(CXy * pXy, LPCTSTR data)
{
CMemFile memFile;
memFile.Write(data, lstrlen(data) * sizeof(TCHAR));
memFile.SeekToBegin();
int nReturn = pXy->DFD_Read(memFile);
return nReturn;
}
extern "C" __declspec(dllexport)
int XyAddPolygonTree(CXy * pXy, CPolygonTreeInterface* pPolygonTree, LPCTSTR layerName)
{
// 轮廓线
CLayer * pLayerOld = pXy->GetCurrentLayer();
CLayer * pLayer = pXy->FindAddLayer(layerName);
pXy->SetCurrentLayer(pLayer);
int N = pPolygonTree->GetResultPolygons().size();
for (int i = 0; i < N; i++)
{
CPolyline* polyline = pPolygonTree->GetResultPolygons().at(i);
NBase::CPointList pointList;
for (int i = 0; i < polyline->GetSize(); i++)
{
CPointXYZ pt = polyline->GetPoint(i);
NBase::dfPoint point;
point.x0 = pt.x0;
point.y0 = pt.y0;
pointList.AddTail(point);
}
CCurveEx* pCurve = new CCurveEx();
pCurve->SetPoints(pointList, 2);
POSITION pos = pXy->AddElement(pCurve, DOUBLEFOX_CURVE);
}
pXy->SetCurrentLayer(pLayerOld);
return 0;
}
extern "C" __declspec(dllexport)
int AddBufferData(CSigmaView * pView, LPCTSTR data)
{
CXy* pXy = pView->m_pDoc->m_pXy;
CMemFile memFile;
memFile.Write(data, lstrlen(data) * sizeof(TCHAR));
memFile.SeekToBegin();
NBase::CPositionList lstPos;
int nReturn = pXy->DFD_Read(memFile, lstPos, -1);
if (lstPos.GetSize() > 0)
{
CSigmaDoc* pDoc = pView->m_pDoc;
CActionAddItem * pAction = new CActionAddItem(pDoc, ID_CURVE_MERGE, lstPos);
pDoc->SetActionItem(pAction);
}
return nReturn;
}
extern "C" __declspec(dllexport)
int AddElementByBuffer(CSigmaView * pView, BYTE* buffElement, int buffLen, int elementType, int dataFormat)
{
CXy* pxy = pView->m_pDoc->m_pXy;
CWellGroup* pWellGroup = new CWellGroup;
COne* pOne = pxy->CreateOne(pWellGroup, elementType); // WELL_GROUP
pOne->ReadMemory(buffElement, -1, buffLen, dataFormat);
pxy->AddTailOne(pOne);
return 1;
}
extern "C" __declspec(dllexport)
int CrossPoint_Add(CSigmaView * pView, CrossPoint2D * ptOut)
{
CItemPointCrossAdd * itemPointCross = GetItemPointCrossAddFromView(pView);
if (itemPointCross == NULL)
return -1;
CPointCrossName * pt = CreateCrossPoint(ptOut);
itemPointCross->AddElement(pt, DOUBLEFOX_CROSSPOINT);
return 1;
}
extern "C" __declspec(dllexport)
int CrossPoint_ChangeMode(CSigmaView * pView, int mode)
{
if (mode != 0 && mode != 1)
return -1;
CItemPointCrossAdd * itemPointCross = GetItemPointCrossAddFromView(pView);
if (itemPointCross == NULL)
return -1;
if (mode == 0)
itemPointCross->SetMode(CItemPointAdd::POINT_MODE_SINGLE);
else if (mode == 1)
itemPointCross->SetMode(CItemPointAdd::POINT_MODE_CONTINUE);
else
itemPointCross->SetMode(CItemPointAdd::POINT_MODE_SINGLE);
return 1;
}
extern "C" __declspec(dllexport)
int CrossPoint_SetNames(CSigmaView * pView, LPCTSTR name1, LPCTSTR name2, LPCTSTR name3, LPCTSTR name4)
{
if (pView == 0)
return -1;
CItemPointCrossAdd * itemPointCross = GetItemPointCrossAddFromView(pView);
if (itemPointCross == NULL)
return -1;
itemPointCross->SetName1(name1);
itemPointCross->SetName2(name2);
itemPointCross->SetName3(name3);
itemPointCross->SetName4(name4);
return 1;
}
static CPointNameEx * CreatePoint(double x, double y, double z, double angle, const char * pointName)
{
CPointNameEx* pPoint = new CPointNameEx;
pPoint->x0 = x;
pPoint->y0 = y;
pPoint->z0 = z;
pPoint->angle = angle;
pPoint->SetName(pointName);
return pPoint;
}
static CPointTwoName * CreateFractionPoint(FractionPoint * point)
{
CPointTwoName * pPoint = new CPointTwoName;
pPoint->x0 = point->x;
pPoint->y0 = point->y;
pPoint->angle = point->angle;
pPoint->m_name1.SetName(point->numeratorString);
pPoint->m_name2.SetName(point->denominatorString);
return pPoint;
}
static CItemPointAdd * GetItemPointAddFromView(CSigmaView * pView)
{
if (pView == NULL)
return 0;
CItem * pItem = pView->GetItem();
if (pItem == NULL)
return 0;
CItemPointAdd * itemPoint = dynamic_cast<CItemPointAdd *>(pItem);
if (itemPoint == NULL)
return 0;
return itemPoint;
}
static CItemPointCrossAdd * GetItemPointCrossAddFromView(CSigmaView * pView)
{
if (pView == NULL)
return 0;
CItem * pItem = pView->GetItem();
if (pItem == NULL)
return 0;
CItemPointCrossAdd * itemPointCross = dynamic_cast<CItemPointCrossAdd *>(pItem);
if (itemPointCross == NULL)
return 0;
return itemPointCross;
}
static CPointCrossName * CreateCrossPoint(CrossPoint2D * pt)
{
CPointCrossName* pPoint = new CPointCrossName;
pPoint->x0 = pt->x;
pPoint->y0 = pt->y;
pPoint->angle = pt->angle;
pPoint->m_name1.SetName(pt->name1);
pPoint->m_name2.SetName(pt->name2);
pPoint->m_name3.SetName(pt->name3);
pPoint->m_name4.SetName(pt->name4);
return pPoint;
}