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

172 lines
3.9 KiB
C++

#include "stdafx.h"
#include "SigmaView.h"
#include "SectionDoc.h"
#include "ItemSelect.h"
#include "ItemPointAdd.h"
#include "ItemPointProcess.h"
#include "ItemCurveProcess.h"
static CItemSelect * GetItemSelectFromView(CSigmaView * pView);
wchar_t * AsciiToUnicodeChar(const char * str);
CItemPointProcess * GetItemPointProcess(CSigmaView *pView)
{
if (pView == NULL)
return nullptr;
CItem * pItem = pView->GetItem();
if (pItem == NULL)
return nullptr;
CItemPointProcess * item = dynamic_cast<CItemPointProcess *>(pItem);
return item;
}
CItemCurveProcess * GetItemCurveProcess(CSigmaView *pView)
{
if (pView == NULL)
return nullptr;
CItem * pItem = pView->GetItem();
if (pItem == NULL)
return nullptr;
CItemCurveProcess * item = dynamic_cast<CItemCurveProcess *>(pItem);
return item;
}
extern "C" __declspec(dllexport)
int PointProcessSetIdea(CSigmaView * pView, int idea)
{
CItemPointProcess * pItem = GetItemPointProcess(pView);
if (pItem != nullptr) {
pItem->SetProcessIdea(idea);
}
else {
return 0;
}
return 1;
}
extern "C" __declspec(dllexport)
int PointProcessGetCount(CSigmaView * pView)
{
CItemPointProcess * pItem = GetItemPointProcess(pView);
if (pItem != nullptr)
{
return pItem->m_processCount;
}
return 0;
}
extern "C" __declspec(dllexport)
void PointProcessSetStyle(CSigmaView * pView, BYTE * buffPoint, int bufLen)
{
CHowToViewPoint htp;
BOOL bSuccess = htp.ReadMemory(buffPoint, bufLen, 3);
if (bSuccess == FALSE) {
return;
}
CItemPointProcess * pItem = GetItemPointProcess(pView);
if (pItem!=nullptr)
{
pItem->SetPointStyle(htp);
}
}
extern "C" __declspec(dllexport)
void CurveProcessSetStyle(CSigmaView * pView, BYTE * buffPoint, int bufLen)
{
CHowToViewCurve htc;
BOOL bSuccess = htc.ReadMemory(buffPoint, bufLen, 3);
if (bSuccess == FALSE) {
return;
}
CItemCurveProcess * pItem = GetItemCurveProcess(pView);
if (pItem != nullptr)
{
htc.EnableDrawSourceCurve(FALSE);
pItem->SetCurveStyle(htc);
}
}
//函数功能:获得元素的索引、层位、类型、名称、颜色属性
//参数说明:pView View类
// propertyStringOut 输出此元素的字符串
//返回值:-1 出错 整数 propertyStringOut字符串的长度
extern "C" __declspec(dllexport)
int ElementProperty_GetSimpleProperty(CSigmaView * pView, wchar_t ** propertyStringOut)
{
*propertyStringOut = 0;
if (pView->m_pDoc == 0)
return -1;
CItemSelect * pItemSelect = GetItemSelectFromView(pView);
if (pItemSelect == 0)
return -1;
CPositionList selection;
CListForEach(pos, pItemSelect->m_selection) {
selection.AddTail(pItemSelect->m_selection.GetAt(pos));
}
// 如果什么都没选中,那就显示当前元素的相关信息
if (selection.IsEmpty()) {
CPoint point = pView->GetLastRightButtonPoint();
CPoint2D dp = pView->m_pDoc->GetDC().GetReal(point);
for (POSITION pos : pView->m_pDoc->GetSelectedItems(dp)) {
selection.AddTail(pos);
}
}
CString propertysStr;
CListForEach(pos, selection) {
POSITION pt = selection.GetAt(pos);
COne* pOne = pView->m_pDoc->GetDraw()->GetAt(pt);
if (pOne == NULL)
return -1;
CString propertyStr;
propertyStr.Format("%I64d;%s;%s;%s;%ld", (__int64)pt,
pOne->GetLayer()->GetPathName(),
pView->m_pDoc->GetElementTypeString(pt),
pOne->GetName(),
pOne->color);
propertysStr += propertyStr + "\r\n";
}
LPTSTR buf = propertysStr.GetBuffer();
size_t len = strlen(buf);
if (len == 0)
{
return -1;
}
assert(len >= 2);
propertysStr.Delete((int)len - 2, 2);
wchar_t * propertyWStr = AsciiToUnicodeChar(buf);
len = wcslen(propertyWStr);
if (len == 0)
{
return -1;
}
*propertyStringOut = propertyWStr;
return (int)len;
}
extern "C" __declspec(dllexport)
void ElementProperty_ReleaseString(void * pStr)
{
delete pStr;
}
static CItemSelect * GetItemSelectFromView(CSigmaView * pView)
{
if (pView == NULL)
return 0;
CItem * pItem = pView->GetItem();
if (pItem == NULL)
return 0;
CItemSelect * itemSelect = dynamic_cast<CItemSelect *>(pItem);
return itemSelect;
}