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/InterfaceFindReplace.cpp

526 lines
13 KiB
C++

1 month ago
#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();
}
//<2F><><EFBFBD><EFBFBD>ֵ -1--<2D><><EFBFBD><EFBFBD> 0--<2D>ҵ<EFBFBD><D2B5><EFBFBD> 1--<2D><>һ<EFBFBD>β<EFBFBD><CEB2><EFBFBD> <20><>û<EFBFBD>ҵ<EFBFBD> 2--<2D>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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;
}
//<2F><><EFBFBD>ر<EFBFBD><D8B1>滻ͼԪ<CDBC><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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)
//<2F><><EFBFBD><EFBFBD>ֵ -1--<2D>쳣 0--<2D>滻ʧ<E6BBBB><CAA7> 1--<2D><EFBFBD>ɹ<EFBFBD>
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;
}
//<2F><><EFBFBD><EFBFBD>ֵ -3--д<><D0B4><EFBFBD>ļ<EFBFBD>ʧ<EFBFBD><CAA7> -2--<2D><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʧ<EFBFBD><CAA7> -1--<2D><><EFBFBD><EFBFBD> 0--û<><C3BB>ѡ<EFBFBD>е<EFBFBD>Ԫ<EFBFBD><D4AA> 1--<2D>ɹ<EFBFBD>
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;
//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ͷ
if (fputs("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>,<2C><>λ,<2C><>λ,ʵ<>ʳ<EFBFBD><CAB3><EFBFBD>,<2C><><EFBFBD><EFBFBD>,<2C><>λ<EFBFBD><CEBB>,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;
//<2F><><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>,<2C><>λ,<2C><>λ
//ʵ<>ʳ<EFBFBD><CAB3><EFBFBD>,<2C><><EFBFBD><EFBFBD>,<2C><>λ<EFBFBD><CEBB>,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) //<2F><>
{
pointCount++;
fprintf(fw, ",,,,%.6f,%.6f,\n", eleInfo.x, eleInfo.y);
}
else if (eleInfo.elementType == 2) //<2F><><EFBFBD><EFBFBD>
{
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, "<EFBFBD>ϼ<EFBFBD>,,<2C><><EFBFBD><EFBFBD>:%d <20><>:%d,,,%.6f,%.6f,%.6f,,,\n", curveCount, pointCount, lengthTotal, areaTotal, azimuthTotal);
fclose(fw);
return 1;
FAIL:
//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
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 "<EFBFBD><EFBFBD>";// DOUBLEFOX_POINT
case 2: return "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";//DOUBLEFOX_CURVE
case 3: return "Draw";//DOUBLEFOX_DRAW
case 4: return "<EFBFBD>ı<EFBFBD>";//DOUBLEFOX_TEXT
case 5: return "<EFBFBD><EFBFBD>Բ";//DOUBLEFOX_ELLIPSE 5
case 6: return "Բ";//DOUBLEFOX_CIRCLE 6
case 7: return "<EFBFBD><EFBFBD>";//DOUBLEFOX_FRAME 7
case 8: return "ͼƬ";//DOUBLEFOX_IMAGE 8
case 9: return "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";//DOUBLEFOX_MESH 9
case 10: return "MXN";//DOUBLEFOX_MXN Ӧ<>ò<EFBFBD><C3B2><EFBFBD>ѡ<EFBFBD><D1A1>
case 11: return "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";//DOUBLEFOX_PROPORTION 11
case 12: return "DrawRect";//DOUBLEFOX_DRAW_RECT 12
case 13: return "Բ<EFBFBD><EFBFBD>";//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<EFBFBD><EFBFBD>";//DOUBLEFOX_XPOINT 25
case 26: return "<EFBFBD><EFBFBD>ɫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";//DOUBLEFOX_COLOR_RULER 26
case 27: return "<EFBFBD>ı<EFBFBD>";//DOUBLEFOX_MTEXT 27
case 28: return "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";//DOUBLEFOX_INSERT
case 29: return "<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";//DOUBLEFOX_ENCRYPT
case 30: return "<EFBFBD><EFBFBD>ɫ<EFBFBD><EFBFBD>";//DOUBLEFOX_COLORBAR
case 31: return "<EFBFBD>̶ȱ<EFBFBD><EFBFBD><EFBFBD>";//DOUBLEFOX_SCALERULER
case 32: return "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";//DOUBLEFOX_CRECT
case 33: return "ʮ<EFBFBD>ֵ<EFBFBD>";//DOUBLEFOX_CROSSPOINT
case 34: return "<EFBFBD>";//DOUBLEFOX_WELLLOG
case 35: return "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";//DOUBLEFOX_TWOPOINT
case 36: return "·<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";//DOUBLEFOX_PATHFILL
case 37: return "ͳ<EFBFBD><EFBFBD>ͼ";//DOUBLEFOX_CHART
case 38: return "ˮƽ<EFBFBD><EFBFBD>";//DOUBLEFOX_HORIZONTALWELL
case 39: return "<EFBFBD><EFBFBD><EFBFBD>α<EFBFBD>ע";//DOUBLEFOX_RECTLABEL
case 40: return "<EFBFBD>ϲ<EFBFBD><EFBFBD><EFBFBD>";//DOUBLEFOX_FAULTLINE
case 41: return "<EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD>";//DOUBLEFOX_BLOCK
default:
return "";
}
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼԪ<EFBFBD><EFBFBD><EFBFBD>Ʋ<EFBFBD>ѯ<EFBFBD><EFBFBD>Ŀǰ<EFBFBD><EFBFBD>ֻ֧<EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* \param pXy ͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* \param searchText <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* \param ignoreCase <EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD>Сд
* \param matchWholeWord ȫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD><EFBFBD>
* \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;
}
/**
* <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼԪ 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)
{
// Ҫ<>ų<EFBFBD><C5B3><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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;
}
// <20>ų<EFBFBD> types <20>е<EFBFBD>ͼԪ
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;
}