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/InterfaceSymbolLibraryManag...

403 lines
10 KiB
C++

#include "stdafx.h"
#include "DrawOperator\LibraryManager.h"
#include "SigmaView.h"
#include "DrawOperator\MapStringToPtrNoCase.h"
#include "Util.h"
bool GetXySymbolNames(CXy * pXy, BYTE *& symbolNames, int & buffLen)
{
if (pXy == nullptr)
{
buffLen = 0;
return false;
}
CMapStringToPtrNoCase* pMarks = pXy->GetMark();
if (pMarks == nullptr|| pMarks->GetCount()==0)
{
buffLen = 0;
return false;
}
CString markNames;
CString strMarkName;
void* pDraw = NULL;
POSITION p = pMarks->GetStartPosition();
while (p)
{
pMarks->GetNextAssoc(p, strMarkName, pDraw);
if (pDraw == NULL) continue;
//strMarkName = ((CXy*)pDraw)->m_strName;
strMarkName.AppendChar(';');
markNames += strMarkName;
strMarkName.ReleaseBuffer();
}
CStringToBufferUtf8(markNames, symbolNames, buffLen);
return true;
}
bool GetXyCurrentSymbolNames(CXy* pXy, BYTE*& symbolNames, int& buffLen)
{
if (pXy == nullptr)
{
buffLen = 0;
return false;
}
CStringList markStrList;
pXy->GetNewUsing(markStrList);
if (markStrList.IsEmpty())
{
buffLen = 0;
symbolNames = nullptr; // È·±£Ö¸Õ밲ȫ
return false;
}
CString markNames;
POSITION pos = markStrList.GetHeadPosition();
while (pos != nullptr)
{
CString strMarkName = markStrList.GetNext(pos);
if (!strMarkName.IsEmpty())
{
markNames += strMarkName;
markNames.AppendChar(';');
}
}
CStringToBufferUtf8(markNames, symbolNames, buffLen);
return true;
}
bool RemoveXySymbol(CXy* pXy, CXy* pxySymbol)
{
CMapStringToPtrNoCase* pMarks = pXy->GetMark();
CMemFile fw(10240U);
CString strMarkName;
void* pDraw = NULL;
POSITION p = pMarks->GetStartPosition();
while (p)
{
pMarks->GetNextAssoc(p, strMarkName, pDraw);
if (pDraw == NULL) continue;
if ((CXy*)pDraw == pxySymbol)
{
pXy->RemoveMark(strMarkName);
return true;
}
}
return false;
}
extern "C" __declspec(dllexport)
void ResetSymbol(CSigmaView* pView)
{
CXy* pXy = pView->m_pDoc->m_pXy;
if (pXy->GetCount() > 0)
{
pXy->PositionNew(0);
}
}
extern "C" __declspec(dllexport)
bool XyDrawSymbol(CXy * pXy, HDC hdcMem, int width, int height)
{
if (pXy == NULL) return FALSE;
CDC *pDC = CDC::FromHandle(hdcMem);
CXyDC xyDC; xyDC.Create(pDC);
CRect rt(0, 0, width - 1, height - 1);
rt.DeflateRect(3, 3);
CRect8 rect(1e100, -1e100, -1e100, 1e100);
if (pXy->GetCount() > 0)
{
pXy->GetRange(rect);
pXy->m_range = rect;
xyDC.Extend(rect, rt, EXTEND_MODE_CENTER);
pXy->Draw(xyDC);
}
pDC->SelectStockObject(NULL_BRUSH);
pDC->SelectStockObject(BLACK_PEN);
pDC->Rectangle(0, 0, width - 1, height - 1);
pDC->SelectStockObject(WHITE_PEN);
pDC->Rectangle(1, 1, width - 2, height - 2);
return TRUE;
}
extern "C" __declspec(dllexport)
bool XyDrawSymbolFill(CXy * pXy, HDC hdcMem, int width, int height)
{
if (pXy == NULL) return FALSE;
CDC *pDC = CDC::FromHandle(hdcMem);
CXyDC xyDC; xyDC.Create(pDC);
CRect rt(0, 0, width, height);
CRect8 rect(1e100, -1e100, -1e100, 1e100);
if (pXy->GetCount() > 0)
{
pXy->GetRange(rect);
pXy->m_range = rect;
xyDC.Extend(rect, rt, EXTEND_MODE_CENTER);
pXy->Draw(xyDC);
}
return TRUE;
}
extern "C" __declspec(dllexport)
bool InitLibrary(LPCTSTR strNewPath, BYTE*& buffNodes, int& buffLen, BOOL bNotJudgeSamePath)
{
bool bInitSucess = AfxGetMarkLibMgr()->InitLib(strNewPath, bNotJudgeSamePath);
CMemFile fw(10240U);
//¼ÓÔØ·ûºÅ¿âÖеķûºÅ
//if (IsLoadMark())
{
CString fullTree;
CString strTreePath;
CLibraryItem *pItem;
POSITION pos = AfxGetMarkLibMgr()->m_libXy.GetHeadPosition();
while (pos)
{
pItem = (CLibraryItem*)AfxGetMarkLibMgr()->m_libXy.GetNext(pos);
//strTreePath = AfxGetMarkLibMgr()->GetTreePathName(pItem->m_strFileName);
strTreePath = pItem->m_strFileName;
strTreePath.AppendChar(';');
fullTree += strTreePath;
strTreePath.ReleaseBuffer();
}
CStringToBufferUtf8(fullTree, buffNodes, buffLen);
}
return TRUE;
}
extern "C" __declspec(dllexport)
bool GetLibraryPath(BYTE*& pathData, int& buffLen)
{
CStringToBufferUtf8(AfxGetMarkLibMgr()->m_strPath, pathData, buffLen);
return true;
}
extern "C" __declspec(dllexport)
bool LibraryAddNewGroup(LPCSTR fileName)
{
AfxGetMarkLibMgr()->AddNewGroup(fileName);
return true;
}
extern "C" __declspec(dllexport)
void LibraryRemoveGroup(LPCSTR fileName)
{
AfxGetMarkLibMgr()->RemoveGroup(fileName);
}
extern "C" __declspec(dllexport)
void LibraryReloadGroup(LPCSTR fileName)
{
if (fileName == nullptr)
{
TRACE("fileName ²»ÄÜΪ nullptr\n");
return;
}
AfxGetMarkLibMgr()->ReloadGroup(fileName);
}
extern "C" __declspec(dllexport)
BOOL LibraryRenameGroup(LPCSTR fileName, LPCTSTR fileNew)
{
return AfxGetMarkLibMgr()->RenameGroup(fileName, fileNew);
}
extern "C" __declspec(dllexport)
bool LibrarySaveAll()
{
return AfxGetMarkLibMgr()->SaveAll();
}
extern "C" __declspec(dllexport)
bool GetLibrarySymbolNames(LPCTSTR fileName, BYTE*& symbolNames, int& buffLen)
{
POSITION pos = AfxGetMarkLibMgr()->Find(fileName);
if (pos == NULL) return NULL;
CLibraryItem *pItem = AfxGetMarkLibMgr()->GetAt(pos);
int r = pItem->Read();
CXy *pXy = pItem->m_pxy;
return GetXySymbolNames(pXy, symbolNames, buffLen);
}
extern "C" __declspec(dllexport)
bool GetDrawerSymbolNames(CSigmaView* pView, BYTE *& symbolNames, int & buffLen)
{
CXy* pXy = pView->m_pDoc->m_pXy;
return GetXySymbolNames(pXy, symbolNames, buffLen);
}
extern "C" __declspec(dllexport)
bool GetDrawerCurrentSymbolNames(CSigmaView* pView, BYTE*& symbolNames, int& buffLen)
{
CXy* pXy = pView->m_pDoc->m_pXy;
return GetXyCurrentSymbolNames(pXy, symbolNames, buffLen);
}
extern "C" __declspec(dllexport)
bool RemoveLibrarySymbol(LPCTSTR fileName, CXy* pxySymbol)
{
POSITION pos = AfxGetMarkLibMgr()->Find(fileName);
if (pos == NULL) return NULL;
CLibraryItem *pItem = AfxGetMarkLibMgr()->GetAt(pos);
int r = pItem->Read();
CXy *pXy = pItem->m_pxy;
return RemoveXySymbol(pXy, pxySymbol);
}
extern "C" __declspec(dllexport)
bool RemoveDrawerSymbol(CSigmaView* pView, CXy* pxySymbol)
{
CXy* pXy = pView->m_pDoc->m_pXy;
return RemoveXySymbol(pXy, pxySymbol);
}
bool CreateXySymbol(CXy* pItemXy, LPCTSTR symbolName, CXy*& pSymbolXy)
{
pSymbolXy = new CXy;
pSymbolXy->m_strName = symbolName;
int nResult = pItemXy->AddMark(pSymbolXy);
if (nResult == 0)
{
delete pSymbolXy;
pSymbolXy = nullptr;
return FALSE;
}
return TRUE;
}
extern "C" __declspec(dllexport)
int XyAddBufferData(CXy * pXy, LPCTSTR data);
extern "C" __declspec(dllexport)
int XyAddDataAsSymble(CXy * pXy, LPCTSTR data, LPCTSTR symbolName, bool overwrite)
{
CXy* pSymbolXy = new CXy;
int nResult = XyAddBufferData(pSymbolXy, data);
pSymbolXy->m_strName = symbolName;
nResult = pXy->AddMark(pSymbolXy, overwrite);
//delete pSymbolXy;
return nResult;
}
extern "C" __declspec(dllexport)
bool CreateLibrarySymbol(LPCTSTR fileName, LPCTSTR symbolName, CXy*& pSymbolXy)
{
POSITION pos = AfxGetMarkLibMgr()->Find(fileName);
if (pos == NULL) return FALSE;
CXy* pItemXy = AfxGetMarkLibMgr()->GetItemXy(pos);
return CreateXySymbol(pItemXy, symbolName, pSymbolXy);
}
extern "C" __declspec(dllexport)
bool CreateDrawerSymbol(CSigmaView* pView, LPCTSTR symbolName, CXy*& pSymbolXy)
{
CXy* pItemXy = pView->m_pDoc->m_pXy;
return CreateXySymbol(pItemXy, symbolName, pSymbolXy);
}
extern "C" __declspec(dllexport)
bool LibraryCopySymbol(LPCTSTR fileName, CXy* pSymbolXy, LPCTSTR symbolName, CXy*& pSymbolNew)
{
POSITION pos = AfxGetMarkLibMgr()->Find(fileName);
if (pos == NULL) return FALSE;
CXy* pItemXy = AfxGetMarkLibMgr()->GetItemXy(pos);
pSymbolNew = new CXy;
*pSymbolNew = *pSymbolXy;
pSymbolNew->m_strName = symbolName;
return pItemXy->AddMark(pSymbolNew, false);
}
extern "C" __declspec(dllexport)
bool DrawerCopySymbol(CSigmaView* pView, CXy* pSymbolXy, LPCTSTR symbolName, CXy*& pSymbolNew)
{
CXy* pItemXy = pView->m_pDoc->m_pXy;
pSymbolNew = new CXy;
*pSymbolNew = *pSymbolXy;
pSymbolNew->m_strName = symbolName;
return pItemXy->AddMark(pSymbolNew, true);
}
extern "C" __declspec(dllexport)
bool DrawerCopyAllSymbol(CXy* pXySource, CXy* pXyDest, bool overwrite)
{
CMapStringToPtrNoCase* pMarks = pXySource->GetMark();
if (pMarks == nullptr || pMarks->GetCount() == 0)
{
return false;
}
CString strMarkName;
void* pDraw = NULL;
POSITION p = pMarks->GetStartPosition();
while (p)
{
pMarks->GetNextAssoc(p, strMarkName, pDraw);
if (pDraw == NULL) continue;
CXy* pXyFind = (CXy*)pDraw;
CXy* pSymbolNew = new CXy;
*pSymbolNew = *pXyFind;
pSymbolNew->m_strName = strMarkName;
pXyDest->AddMark(pSymbolNew, overwrite);
}
return true;
}
extern "C" __declspec(dllexport)
bool LibaryDrawSymbol(LPCTSTR fileName, LPCTSTR symbolName, HDC hdcMem, int width, int height, CXy*& pXy)
{
pXy = AfxGetMarkLibMgr()->FindMark(fileName, symbolName);
return XyDrawSymbol(pXy, hdcMem, width, height);
}
extern "C" __declspec(dllexport)
bool DrawerDrawSymbol(CSigmaView* pView, LPCTSTR symbolName, HDC hdcMem, int width, int height, CXy*& pXy)
{
pXy = (CXy*)(pView->m_pDoc->m_pXy->FindMark(symbolName));
return XyDrawSymbol(pXy, hdcMem, width, height);
}
extern "C" __declspec(dllexport)
bool LibaryDrawSymbolFill(LPCTSTR fileName, LPCTSTR symbolName, HDC hdcMem, int width, int height, CXy*& pXy)
{
pXy = AfxGetMarkLibMgr()->FindMark(fileName, symbolName);
return XyDrawSymbolFill(pXy, hdcMem, width, height);
}
extern "C" __declspec(dllexport)
bool DrawerDrawSymbolFill(CSigmaView* pView, LPCTSTR symbolName, HDC hdcMem, int width, int height, CXy*& pXy)
{
if (pView == nullptr) {
return false;
}
pXy = (CXy*)(pView->m_pDoc->m_pXy->FindMark(symbolName));
return XyDrawSymbolFill(pXy, hdcMem, width, height);
}
extern "C" __declspec(dllexport)
bool SetDrawXyName(CXy* pXy, LPCTSTR fileName, LPCTSTR newName)
{
AfxGetMarkLibMgr()->ReNameMark(fileName, pXy->m_strName, newName);
//pXy->m_strName = newName;
return TRUE;
}
extern "C" __declspec(dllexport)
void RenameSymble(CSigmaView* pView, LPCTSTR oldName, LPCTSTR newName) {
CXy* pXy = pView->m_pDoc->m_pXy;
//if(pXy->mark.GetCount())
void *v = NULL;
pXy->mark.Lookup(oldName, v);
pXy->mark.RemoveKey(oldName);
CXy* pMark = (CXy*)v;
pMark->m_strName = newName;
pXy->mark.SetAt(newName, pMark);
pXy->PositionNew(2);
}
extern "C" __declspec(dllexport)
bool GetDrawXyName(CXy* pXy, BYTE *& symbolName, int & buffLen)
{
CStringToBufferUtf8(pXy->m_strName, symbolName, buffLen);
return TRUE;
}