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.
199 lines
4.7 KiB
C++
199 lines
4.7 KiB
C++
#include "stdafx.h"
|
|
#include "SigmaView.h"
|
|
#include "DrawOperator\StyleLibraryManager.h"
|
|
#include "Util.h"
|
|
|
|
#include "ActionListItem.h"
|
|
#include <ActionEmbellishItem.h>
|
|
|
|
/*
|
|
* 初始化样式库
|
|
*/
|
|
extern "C" __declspec(dllexport)
|
|
bool StyleLibraryInit(const LPCSTR strNewPath, bool bNotJudgeSamePath)
|
|
{
|
|
return AfxGetStyleLibMgr().InitLib(strNewPath, bNotJudgeSamePath);
|
|
}
|
|
|
|
/**
|
|
* 列出所有样式分组
|
|
*
|
|
* \return 由逗号(,)分割的分组字符串
|
|
*/
|
|
extern "C" __declspec(dllexport)
|
|
BSTR StyleLibraryListGroup()
|
|
{
|
|
return JoinStrings(AfxGetStyleLibMgr().ListGroup(), ",").AllocSysString();
|
|
}
|
|
|
|
|
|
/**
|
|
* 列出该分组下面的所有样式
|
|
*
|
|
* \return 由逗号(,)分割的分组字符串
|
|
*/
|
|
extern "C" __declspec(dllexport)
|
|
BSTR StyleLibraryListStyle(LPCSTR group)
|
|
{
|
|
std::shared_ptr<StyleManager::CStyleLibraryItem> pItem = AfxGetStyleLibMgr().Find(group);
|
|
if (pItem != nullptr)
|
|
{
|
|
return JoinStrings(pItem->ListStyle(), ",").AllocSysString();
|
|
}
|
|
return CString().AllocSysString();
|
|
}
|
|
|
|
/**
|
|
* 创建新的分组
|
|
*
|
|
* \param strNewFile 组名
|
|
*/
|
|
extern "C" __declspec(dllexport)
|
|
void StyleLibraryAddNewGroup(const LPCSTR strNewFile)
|
|
{
|
|
AfxGetStyleLibMgr().AddNewGroup(strNewFile);
|
|
}
|
|
|
|
/**
|
|
* 移除所有分组
|
|
*/
|
|
extern "C" __declspec(dllexport)
|
|
void StyleLibraryRemoveAll(void)
|
|
{
|
|
AfxGetStyleLibMgr().RemoveAll();
|
|
}
|
|
|
|
/**
|
|
* 移除指定分组
|
|
*
|
|
* \param strNewFile
|
|
*/
|
|
extern "C" __declspec(dllexport)
|
|
void StyleLibraryRemoveGroup(const LPCSTR strNewFile)
|
|
{
|
|
AfxGetStyleLibMgr().RemoveGroup(strNewFile);
|
|
}
|
|
|
|
/**
|
|
* 重命名某个分组
|
|
*
|
|
* \param oldFile 旧名称
|
|
* \param newFile 新名称
|
|
* \return
|
|
*/
|
|
extern "C" __declspec(dllexport)
|
|
bool StyleLibraryRenameGroup(const LPCSTR oldFile, const LPCSTR newFile)
|
|
{
|
|
return AfxGetStyleLibMgr().RenameGroup(oldFile, newFile);
|
|
}
|
|
|
|
/**
|
|
* 保存所有样式
|
|
*
|
|
* \return
|
|
*/
|
|
extern "C" __declspec(dllexport)
|
|
bool StyleLibrarySaveAll()
|
|
{
|
|
return AfxGetStyleLibMgr().SaveAll();
|
|
}
|
|
|
|
/**
|
|
* 设置样式到目标图层
|
|
*
|
|
* \param pView pView
|
|
* \param group 样式组名称
|
|
* \param style 样式名称
|
|
* \param targetLayer 目标图层名
|
|
* \return
|
|
*/
|
|
extern "C" __declspec(dllexport)
|
|
bool StyleLibraryApplyStyleTo(CSigmaView * pView, LPCSTR group, LPCSTR style, LPCSTR targetLayer)
|
|
{
|
|
assert(pView != nullptr);
|
|
|
|
CXy *pXy = pView->m_pDoc->m_pXy;
|
|
CLayer* pLayer = pXy->FindLayer(targetLayer);
|
|
if (pLayer == nullptr)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
std::unique_ptr<CActionEmbellishItem> pActionItem = std::make_unique<CActionEmbellishItem>(pView->m_pDoc, ActionTypeLayerEmbellishCurveAdd, pLayer);
|
|
pActionItem->SetOldHowToView(pLayer); // 备份老修饰
|
|
|
|
bool result = AfxGetStyleLibMgr().ApplyStyleTo(group, style, pXy, targetLayer);
|
|
if (result)
|
|
{
|
|
pActionItem->SetNewHowToView(pLayer);
|
|
pView->m_pDoc->SetActionItem(pActionItem.release());
|
|
}
|
|
return result;
|
|
}
|
|
|
|
extern "C" __declspec(dllexport)
|
|
bool StyleLibraryApplyStyleToElement(CSigmaView * pView, LPCSTR group, LPCSTR style, POSITION posElement)
|
|
{
|
|
int styleType =AfxGetStyleLibMgr().GetStyleType(group, style);
|
|
//为了修饰的Redo/Undo
|
|
CXy *pXy = pView->m_pDoc->m_pXy;
|
|
COne* pOne = pXy->GetAt(posElement);
|
|
bool bSuccess = false;
|
|
//CActionEmbellishItem* pActionItem = new CActionEmbellishItem(pView->m_pDoc, 0, pOne);
|
|
std::unique_ptr<CActionEmbellishItem> pActionItem = std::make_unique<CActionEmbellishItem>(pView->m_pDoc, 0, pOne);
|
|
pActionItem->SetOldHowToView(pOne); //备份老修饰
|
|
if (pOne->GetType() == DOUBLEFOX_POINT || pOne->GetType() == DOUBLEFOX_XYZ || pOne->GetType() == DOUBLEFOX_XPOINT)
|
|
{
|
|
if (styleType == 2 || styleType == 3) {
|
|
if (pOne->HowToViewPoint)
|
|
delete pOne->HowToViewPoint;
|
|
pOne->HowToViewPoint = new CHowToViewPoint();
|
|
CHowToViewPoint* pHtp = (AfxGetStyleLibMgr().GetHowToViewPoint(group, style));
|
|
if (pHtp != nullptr)
|
|
{
|
|
*pOne->HowToViewPoint = *pHtp;
|
|
pActionItem->SetNewHowToView(pOne); //备份新修饰
|
|
bSuccess = true;
|
|
}
|
|
}
|
|
}
|
|
else if (pOne->GetType() == DOUBLEFOX_CURVE)
|
|
{
|
|
if (styleType == 1 || styleType == 3)
|
|
{
|
|
if (pOne->HowToViewCurve)
|
|
delete pOne->HowToViewCurve;
|
|
pOne->HowToViewCurve = new CHowToViewCurve();
|
|
CHowToViewCurve* pHtc = (AfxGetStyleLibMgr().GetHowToViewCurve(group, style));
|
|
if (pHtc != nullptr)
|
|
{
|
|
*pOne->HowToViewCurve = *pHtc;
|
|
pActionItem->SetNewHowToView(pOne); //备份新修饰
|
|
bSuccess = true;
|
|
}
|
|
}
|
|
}
|
|
if (bSuccess == false) {
|
|
//delete pActionItem;
|
|
return false;
|
|
}
|
|
pView->m_pDoc->SetActionItem(pActionItem.release());
|
|
return bSuccess;
|
|
}
|
|
|
|
/**
|
|
* 渲染样式
|
|
*
|
|
* \param group 组名称
|
|
* \param style 样式名称
|
|
* \param hdc HDC
|
|
* \param width 宽度
|
|
* \param height 高度
|
|
* \return 成功/失败,失败大概率是分组或样式不存在
|
|
*/
|
|
extern "C" __declspec(dllexport)
|
|
bool StyleLibraryRenderStyle(LPCSTR group, LPCTSTR style, HDC hdc, int width, int height)
|
|
{
|
|
return AfxGetStyleLibMgr().RenderStyle(group, style, hdc, width, height);
|
|
}
|