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.
526 lines
13 KiB
C++
526 lines
13 KiB
C++
#include "stdafx.h"
|
|
#include "SigmaView.h"
|
|
#include "SigmaDoc.h"
|
|
#include "FindReplacement.h"
|
|
#include "Util.h"
|
|
|
|
static CFindReplacement * GetFindReplacement(CSigmaView * pView);
|
|
static const char * GetTypeString(int elementType);
|
|
extern char* UnicodeToAscii(const WCHAR* str, char * buffer, int lenOfBuffer);
|
|
|
|
void ActiveElement(CSigmaView* pView, POSITION pos);
|
|
|
|
extern "C" __declspec(dllexport)
|
|
void FindReplacement_Start(CSigmaView * pView)
|
|
{
|
|
CFindReplacement * pTool = GetFindReplacement(pView);
|
|
if (pTool == nullptr)
|
|
return ;
|
|
|
|
pTool->Start();
|
|
}
|
|
|
|
//返回值 -1--出错 0--找到了 1--第一次查找 但没找到 2--已经搜索完了
|
|
extern "C" __declspec(dllexport)
|
|
int FindReplacement_FindNext(CSigmaView * pView, LPCTSTR findContent
|
|
,int bMatch, int bCapitalLower
|
|
, int elementType, bool onlyEditable)
|
|
{
|
|
if (findContent == nullptr)
|
|
return -1;
|
|
CFindReplacement * pTool = GetFindReplacement(pView);
|
|
if (pTool == nullptr)
|
|
return -1;
|
|
|
|
return pTool->FindNext(findContent, bMatch, bCapitalLower, elementType, onlyEditable);
|
|
}
|
|
|
|
extern "C" __declspec(dllexport)
|
|
int FindReplacement_Draw(CSigmaView * pView, HDC hdc)
|
|
{
|
|
CFindReplacement * pTool = GetFindReplacement(pView);
|
|
if (pTool == nullptr)
|
|
return -1;
|
|
|
|
CDC *pDC = CDC::FromHandle(hdc);
|
|
pTool->Draw(pDC);
|
|
|
|
return 1;
|
|
}
|
|
|
|
extern "C" __declspec(dllexport)
|
|
int FindReplacement_FindAll(CSigmaView * pView, LPCTSTR findContent, int bMatch, int bCapitalLower)
|
|
{
|
|
if (findContent == nullptr)
|
|
return -1;
|
|
CFindReplacement * pTool = GetFindReplacement(pView);
|
|
if (pTool == nullptr)
|
|
return -1;
|
|
|
|
pTool->FindAll(findContent, bMatch, bCapitalLower);
|
|
return -1;
|
|
}
|
|
extern "C" __declspec(dllexport)
|
|
int FindReplace_GetCurrentPostion(CSigmaView* pView, POSITION& pos) {
|
|
CFindReplacement * pTool = GetFindReplacement(pView);
|
|
if (pTool == nullptr)
|
|
return 0;
|
|
pos = pTool->GetCurrentPostion();
|
|
return 1;
|
|
}
|
|
extern "C" __declspec(dllexport)
|
|
bool FindPointByInfo(CSigmaView* pView, POSITION& posFind
|
|
, LPCTSTR elementName, double x, double y, LPCTSTR layerName)
|
|
{
|
|
posFind = 0;
|
|
if (pView == 0 || pView->m_pDoc == 0)
|
|
return false;
|
|
CSigmaDoc* pDoc = pView->m_pDoc;
|
|
CPtrList* valueList = pDoc->GetDraw()->GetValueList();
|
|
|
|
for (POSITION pos = valueList->GetHeadPosition(); pos != nullptr; valueList->GetNext(pos))
|
|
{
|
|
COne* pOne = pDoc->GetDraw()->GetAt(pos);
|
|
|
|
CString name = pOne->GetName();
|
|
if (elementName != name) {
|
|
continue;
|
|
}
|
|
CString strlayer = pOne->GetLayer()->GetName();
|
|
if (CString(layerName).GetLength() > 0 && !IsSameLayerName(strlayer, layerName))
|
|
{
|
|
continue;
|
|
}
|
|
int eleType = pOne->GetType();
|
|
if (eleType == DOUBLEFOX_POINT
|
|
|| eleType == DOUBLEFOX_XYZ)
|
|
{
|
|
CPointNameEx* pPoint = (CPointNameEx*)pOne->GetValue();
|
|
if (IsEqual(pPoint->x0, x) && IsEqual(pPoint->y0, y)) {
|
|
posFind = pos;
|
|
return true;
|
|
}
|
|
}
|
|
else if (eleType == DOUBLEFOX_TEXT)
|
|
{
|
|
CText* pPoint = (CText*)pOne->GetValue();
|
|
if (IsEqual(pPoint->x0, x) && IsEqual(pPoint->y0, y)) {
|
|
posFind = pos;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
extern "C" __declspec(dllexport)
|
|
int ActiveElementByName(CSigmaView* pView, LPCTSTR elementName, int elementType)
|
|
{
|
|
CFindReplacement * pTool = GetFindReplacement(pView);
|
|
if (pTool == nullptr)
|
|
return -1;
|
|
|
|
int nReturn = pTool->FindNext(elementName, TRUE, TRUE);
|
|
if (nReturn == 2)
|
|
{
|
|
FindReplacement_Start(pView);
|
|
nReturn = pTool->FindNext(elementName, TRUE, TRUE);
|
|
}
|
|
if (nReturn == 0)
|
|
{
|
|
POSITION pos = pTool->GetCurrentPostion();
|
|
ActiveElement(pView, pos);
|
|
}
|
|
|
|
return nReturn;
|
|
}
|
|
//返回被替换图元的数量
|
|
extern "C" __declspec(dllexport)
|
|
int FindReplacement_ReplaceAll(CSigmaView * pView, LPCTSTR strFind, LPCTSTR strReplace, BOOL bMatch, BOOL bCapitalLower)
|
|
{
|
|
if (strFind == nullptr || strReplace == nullptr)
|
|
return -1;
|
|
CFindReplacement * pTool = GetFindReplacement(pView);
|
|
if (pTool == nullptr)
|
|
return -1;
|
|
|
|
return pTool->ReplaceAll(strFind, strReplace, bMatch, bCapitalLower);
|
|
}
|
|
|
|
extern "C" __declspec(dllexport)
|
|
//返回值 -1--异常 0--替换失败 1--替换成功
|
|
int FindReplacement_Replace(CSigmaView * pView, LPCTSTR strFind, LPCTSTR strReplace, BOOL bMatch, BOOL bCapitalLower)
|
|
{
|
|
if (strFind == nullptr || strReplace == nullptr)
|
|
return -1;
|
|
CFindReplacement * pTool = GetFindReplacement(pView);
|
|
if (pTool == nullptr)
|
|
return -1;
|
|
|
|
return pTool->Replace(strFind, strReplace, bMatch, bCapitalLower);
|
|
}
|
|
|
|
extern "C" __declspec(dllexport)
|
|
int FindReplacement_GetCountOfElement(CSigmaView * pView)
|
|
{
|
|
CFindReplacement * pTool = GetFindReplacement(pView);
|
|
if (pTool == nullptr)
|
|
return -1;
|
|
|
|
return pTool->GetCountOfElement();
|
|
}
|
|
|
|
extern "C" __declspec(dllexport)
|
|
int FindReplacement_GetElementInfo(CSigmaView * pView, int id, ElementInfo * eleInfoOut)
|
|
{
|
|
CFindReplacement * pTool = GetFindReplacement(pView);
|
|
if (pTool == nullptr)
|
|
return -1;
|
|
|
|
if (pTool->GetElement(id, eleInfoOut))
|
|
return 1;
|
|
|
|
return -1;
|
|
}
|
|
|
|
extern "C" __declspec(dllexport)
|
|
void FindReplacement_ReleaseNativeMemoryOfElementInfo(ElementInfo * eleInfo)
|
|
{
|
|
if (eleInfo == nullptr)
|
|
return;
|
|
|
|
delete eleInfo->name;
|
|
eleInfo->name = 0;
|
|
eleInfo->lenOfName = 0;
|
|
|
|
delete eleInfo->layerName;
|
|
eleInfo->layerName = 0;
|
|
eleInfo->lenOfLayerName = 0;
|
|
|
|
delete eleInfo->markName;
|
|
eleInfo->markName = 0;
|
|
eleInfo->lenOfMarkName = 0;
|
|
}
|
|
|
|
//返回值 -3--写入文件失败 -2--打开文件失败 -1--出错 0--没有选中的元素 1--成功
|
|
extern "C" __declspec(dllexport)
|
|
int FindReplacement_SaveFindAllResult(CSigmaView * pView, LPCTSTR fileFullPath)
|
|
{
|
|
CFindReplacement * pTool = GetFindReplacement(pView);
|
|
if (pTool == nullptr)
|
|
return -1;
|
|
|
|
int count = pTool->GetCountOfElement();
|
|
if (count == 0)
|
|
return 0;
|
|
|
|
FILE* fw = NULL;
|
|
fw = fopen(fileFullPath, "wt");
|
|
if (fw == NULL)
|
|
return -2;
|
|
|
|
//保存文件头
|
|
|
|
if (fputs("序号,名称,类型,层位,层位,实际长度,面积,方位角,X,Y,Z\n", fw) == EOF)
|
|
{
|
|
fclose(fw);
|
|
return -2;
|
|
}
|
|
|
|
char nameBuffer[100];
|
|
char layerNameBuffer[100];
|
|
char markNameBuffer[100];
|
|
std::string nameStr;
|
|
std::string layerNameStr;
|
|
std::string markNameStr;
|
|
|
|
int pointCount = 0;
|
|
int curveCount = 0;
|
|
double lengthTotal = 0;
|
|
double areaTotal = 0;
|
|
double azimuthTotal = 0;
|
|
ElementInfo eleInfo;
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
nameStr.clear();
|
|
layerNameStr.clear();
|
|
markNameStr.clear();
|
|
|
|
if (pTool->GetElement(i, &eleInfo) == false)
|
|
goto FAIL;
|
|
|
|
if (UnicodeToAscii(eleInfo.name, nameBuffer, 100))
|
|
nameStr = nameBuffer;
|
|
|
|
if (UnicodeToAscii(eleInfo.layerName, layerNameBuffer, 100))
|
|
layerNameStr = layerNameBuffer;
|
|
|
|
if (UnicodeToAscii(eleInfo.markName, markNameBuffer, 100))
|
|
markNameStr = markNameBuffer;
|
|
|
|
//序号,名称,类型,层位,层位
|
|
//实际长度,面积,方位角,X,Y,Z\n"
|
|
fprintf(fw, "%d,%s,%s,%s,%s",
|
|
i + 1, nameStr.c_str(), GetTypeString(eleInfo.elementType),
|
|
layerNameStr.c_str(), markNameStr.c_str());
|
|
|
|
if (eleInfo.elementType == 1) //点
|
|
{
|
|
pointCount++;
|
|
fprintf(fw, ",,,,%.6f,%.6f,\n", eleInfo.x, eleInfo.y);
|
|
}
|
|
else if (eleInfo.elementType == 2) //曲线
|
|
{
|
|
curveCount++;
|
|
|
|
lengthTotal += eleInfo.length;
|
|
areaTotal += eleInfo.area;
|
|
azimuthTotal += eleInfo.azimuth;
|
|
fprintf(fw, ",%.6f,%.6f,%.6f,,,\n", eleInfo.length, eleInfo.area, eleInfo.azimuth);
|
|
}
|
|
else
|
|
fputs(",,,,,,\n", fw);
|
|
|
|
FindReplacement_ReleaseNativeMemoryOfElementInfo(&eleInfo);
|
|
} //end for
|
|
|
|
if (curveCount == 0 || pointCount == 0)
|
|
{
|
|
fclose(fw);
|
|
return 1;
|
|
}
|
|
|
|
fprintf(fw, "合计,,曲线:%d 点:%d,,,%.6f,%.6f,%.6f,,,\n", curveCount, pointCount, lengthTotal, areaTotal, azimuthTotal);
|
|
fclose(fw);
|
|
return 1;
|
|
FAIL:
|
|
//清空文件
|
|
remove(fileFullPath);
|
|
fclose(fw);
|
|
return -1;
|
|
}
|
|
|
|
static CFindReplacement * GetFindReplacement(CSigmaView * pView)
|
|
{
|
|
if (pView == 0)
|
|
return nullptr;
|
|
if (pView->m_pDoc == 0)
|
|
return nullptr;
|
|
|
|
CFindReplacement * pTool = pView->m_pDoc->GetFindReplacement();
|
|
if (pTool == 0)
|
|
return nullptr;
|
|
|
|
return pTool;
|
|
}
|
|
|
|
static const char * GetTypeString(int elementType)
|
|
{
|
|
switch (elementType)
|
|
{
|
|
case 1: return "点";// DOUBLEFOX_POINT
|
|
case 2: return "曲线";//DOUBLEFOX_CURVE
|
|
case 3: return "Draw";//DOUBLEFOX_DRAW
|
|
case 4: return "文本";//DOUBLEFOX_TEXT
|
|
case 5: return "椭圆";//DOUBLEFOX_ELLIPSE 5
|
|
case 6: return "圆";//DOUBLEFOX_CIRCLE 6
|
|
case 7: return "框";//DOUBLEFOX_FRAME 7
|
|
case 8: return "图片";//DOUBLEFOX_IMAGE 8
|
|
case 9: return "网格";//DOUBLEFOX_MESH 9
|
|
case 10: return "MXN";//DOUBLEFOX_MXN 应该不会选中
|
|
case 11: return "比例尺";//DOUBLEFOX_PROPORTION 11
|
|
case 12: return "DrawRect";//DOUBLEFOX_DRAW_RECT 12
|
|
case 13: return "圆弧";//DOUBLEFOX_ARC 13
|
|
case 14: return "Grid";//DOUBLEFOX_GRID 14
|
|
case 15: return "Net";//DOUBLEFOX_NET 15
|
|
case 16: return "Section";//DOUBLEFOX_SECTION 16
|
|
case 17: return "OtherDraw";//DOUBLEFOX_OTHERDRAW 17
|
|
case 18: return "XYDC";//DOUBLEFOX_XYDC 18
|
|
case 19: return "OLE";//DOUBLEFOX_OLE 19
|
|
case 20: return "TREE";//DOUBLEFOX_TREE 20
|
|
case 21: return "WMF";//DOUBLEFOX_WMF 21
|
|
case 22: return "Station";//DOUBLEFOX_STATION 22
|
|
case 23: return "CurveStation";//DOUBLEFOX_CURVE_STATION 23
|
|
case 24: return "TV";//DOUBLEFOX_TV 24
|
|
case 25: return "X点";//DOUBLEFOX_XPOINT 25
|
|
case 26: return "颜色标尺";//DOUBLEFOX_COLOR_RULER 26
|
|
case 27: return "文本";//DOUBLEFOX_MTEXT 27
|
|
case 28: return "符号";//DOUBLEFOX_INSERT
|
|
case 29: return "文件加密";//DOUBLEFOX_ENCRYPT
|
|
case 30: return "颜色条";//DOUBLEFOX_COLORBAR
|
|
case 31: return "刻度标尺";//DOUBLEFOX_SCALERULER
|
|
case 32: return "矩形曲线";//DOUBLEFOX_CRECT
|
|
case 33: return "十字点";//DOUBLEFOX_CROSSPOINT
|
|
case 34: return "测井";//DOUBLEFOX_WELLLOG
|
|
case 35: return "分数点";//DOUBLEFOX_TWOPOINT
|
|
case 36: return "路径充填";//DOUBLEFOX_PATHFILL
|
|
case 37: return "统计图";//DOUBLEFOX_CHART
|
|
case 38: return "水平井";//DOUBLEFOX_HORIZONTALWELL
|
|
case 39: return "矩形标注";//DOUBLEFOX_RECTLABEL
|
|
case 40: return "断层线";//DOUBLEFOX_FAULTLINE
|
|
case 41: return "组合块";//DOUBLEFOX_BLOCK
|
|
default:
|
|
return "";
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 根据图元名称查询,目前仅只支持点和线
|
|
*
|
|
* \param pXy 图件对象
|
|
* \param searchText 搜索内容
|
|
* \param ignoreCase 忽略大小写
|
|
* \param matchWholeWord 全内容匹配
|
|
* \return
|
|
*/
|
|
extern "C" __declspec(dllexport)
|
|
BSTR XySearchElement(CXy *pXy, wchar_t *searchText, bool ignoreCase, bool matchWholeWord)
|
|
{
|
|
CPtrList* value = pXy->GetValueList();
|
|
std::vector<CString> positions;
|
|
|
|
for (POSITION pos = value->GetHeadPosition(); pos != nullptr; value->GetNext(pos))
|
|
{
|
|
COne* pOne = (COne *)value->GetAt(pos);
|
|
CString name;
|
|
|
|
switch (pOne->GetType())
|
|
{
|
|
case DOUBLEFOX_XYZ:
|
|
case DOUBLEFOX_POINT:
|
|
{
|
|
CPointNameBase* pPoint = (CPointNameBase*)pOne->GetValue();
|
|
name = pPoint->GetName();
|
|
}
|
|
break;
|
|
|
|
case DOUBLEFOX_CURVE:
|
|
{
|
|
CCurveEx* pCurve = (CCurveEx*)pOne->GetValue();
|
|
name = pCurve->GetName();
|
|
}
|
|
break;
|
|
|
|
default:
|
|
continue;
|
|
}
|
|
|
|
if (SearchMatch(name, CString(searchText), ignoreCase, matchWholeWord))
|
|
{
|
|
CString posText;
|
|
posText.Format("%I64d", pos);
|
|
positions.push_back(posText);
|
|
}
|
|
}
|
|
|
|
CString result = JoinStrings(positions, ", ");
|
|
return result.AllocSysString();
|
|
}
|
|
|
|
extern "C" __declspec(dllexport)
|
|
BSTR SearchElement(CSigmaView *pView, wchar_t *searchText, bool ignoreCase, bool matchWholeWord)
|
|
{
|
|
return XySearchElement(pView->m_pDoc->m_pXy, searchText, ignoreCase, matchWholeWord);
|
|
}
|
|
|
|
extern "C" __declspec(dllexport)
|
|
bool XySearchElementByType(CXy *pXy, int elementType, intptr_t** arr, int* size)
|
|
{
|
|
CPositionList lstElement;
|
|
pXy->GetElement(elementType, lstElement, true);
|
|
if (lstElement.GetCount() == 0) {
|
|
return false;
|
|
}
|
|
|
|
static std::vector<intptr_t> posArray;
|
|
posArray.clear();
|
|
POSITION pos = lstElement.GetHeadPosition();
|
|
POSITION pt;
|
|
while (pos)
|
|
{
|
|
pt = lstElement.GetNext(pos);
|
|
intptr_t signedIntAddress = reinterpret_cast<intptr_t>(pt);
|
|
posArray.push_back(signedIntAddress);
|
|
}
|
|
*arr = posArray.data();
|
|
*size = static_cast<int>(posArray.size());
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 获取除指定类型的其它图元 POSITION
|
|
*
|
|
* \param pXy
|
|
* \param elementTypes
|
|
* \param elementTypeLength
|
|
* \param arr
|
|
* \param size
|
|
* \return
|
|
*/
|
|
extern "C" __declspec(dllexport)
|
|
bool XySearchElementExcludingType(CXy *pXy, int* elementTypes, int elementTypeLength, intptr_t** arr, int* size)
|
|
{
|
|
// 要排除的元素类型
|
|
std::vector<int> types;
|
|
for (int i = 0; i < elementTypeLength; i++)
|
|
{
|
|
types.push_back(elementTypes[i]);
|
|
}
|
|
|
|
static std::vector<intptr_t> posArray;
|
|
posArray.clear();
|
|
|
|
CPtrList* pValueList = pXy->GetValueList();
|
|
for (POSITION pos = pValueList->GetHeadPosition(); pos != nullptr; pValueList->GetNext(pos))
|
|
{
|
|
COne* pOne = pXy->GetAt(pos);
|
|
if (pOne == nullptr)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
// 排除 types 中的图元
|
|
if (Contains(types, pOne->GetType()))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
posArray.push_back(reinterpret_cast<intptr_t>(pos));
|
|
}
|
|
|
|
*arr = posArray.data();
|
|
*size = static_cast<int>(posArray.size());
|
|
|
|
return true;
|
|
}
|
|
|
|
extern "C" __declspec(dllexport)
|
|
bool XySearchElementByLayer(CXy *pXy, LPCTSTR layerName, intptr_t** arr, int* size)
|
|
{
|
|
static std::vector<intptr_t> posArray;
|
|
posArray.clear();
|
|
//std::vector<CString> positions;
|
|
CPositionList lstElement;
|
|
pXy->GetElement(layerName, lstElement, true, true);
|
|
if (lstElement.GetCount() == 0) {
|
|
return false;
|
|
}
|
|
POSITION pos = lstElement.GetHeadPosition();
|
|
POSITION pt;
|
|
while (pos)
|
|
{
|
|
pt = lstElement.GetNext(pos);
|
|
|
|
intptr_t signedIntAddress = reinterpret_cast<intptr_t>(pt);
|
|
posArray.push_back(signedIntAddress);
|
|
//CString posText;
|
|
//posText.Format("%ld", pt);
|
|
//positions.push_back(posText);
|
|
}
|
|
//CString result = JoinStrings(positions, ",");
|
|
//return result.AllocSysString();
|
|
*arr = posArray.data();
|
|
*size = static_cast<int>(posArray.size());
|
|
return true;
|
|
} |