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.

391 lines
9.2 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

//////////////////////////////////////////////////////////////////////////////
//文件 One.h
//主要功能:
//
//程序编写: 2005-12-07
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_ONE_H__84CE3923_A99C_4888_AE1B_131E3FC6A3FB__INCLUDED_)
#define AFX_ONE_H__84CE3923_A99C_4888_AE1B_131E3FC6A3FB__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "xydc.h"
#include "layer.h"
#include "howtoviewcurve.h"
#include "howtoviewpoint.h"
#include "TypeDefine.h"
//m_ViewState的状态
#define VIEW_STATE LAYER_ViewEdit
#define UNVIEW_STATE LAYER_NotViewNotEdit
template <typename T>
struct always_false : std::false_type {};
class AFX_EXT_CLASS COne : public CObject
{
protected:
DECLARE_SERIAL(COne);
private:
int m_type; //element type
int m_ViewState; //元素浏览状态,VIEW_STATE为可视,其它均为不可视,缺省为可视状态
public:
COne();
virtual ~COne();
/**
* 获取 id
*
* \return
*/
int64_t GetId() const;
/**
* 设置 id
*
* \param id
*/
void SetId(int64_t id);
const CString& GetLayerName() const;
void Serialize(CArchive& ar, const short& ver);
virtual void Write(CFile &fw, const short& ver);
virtual void WriteDML(CFile &fw, const short& ver, int nBaseTabNum);
virtual int ReadDML(CFile &fr, const short& ver);
virtual void WritePCG(CFile &fw, const short& ver, int nBaseTabNum);
virtual BOOL WriteMemory(BYTE*& outBuffer, const short& ver, int& destLen, int formatCode);
virtual BOOL ReadMemory(BYTE* bufferBYTE, const short& ver, int len, int formatCode);
// 写图元的概要信息
virtual BOOL WriteSummaryMemory(BYTE*& outBuffer, const short& ver, int& destLen, int formatCode);
virtual BOOL ReadSummaryMemory(BYTE* bufferBYTE, const short& ver, int len, int formatCode);
virtual void Draw(CXyDC& dc);
virtual void GetRange(CRect8& range);
virtual void GetRange(CPoint3D& minPoint, CPoint3D& maxPoint);
CRect8 GetRect(void);
// 判断该元素是否在指定的范围内
virtual BOOL IsInRange(CRect8& range);
// type为校正类型,比如两点校位、四点校位等;pValue为类对象指针如CCalibrate2、CCalibrate4等
virtual void Calibrate(int type, void* pValue);
virtual void Clear(void);
virtual void ClearValue(void);
virtual CHowToViewPoint* GetHowToViewPoint(void);
virtual CHowToViewCurve* GetHowToViewCurve(void);
void CopySetHowToViewPoint(CHowToViewPoint* pHTVP);
void CopySetHowToViewCurve(CHowToViewCurve* pHTVC);
//bReplace=0 时表示不管符号指针是否为空都重新定位符号指针
//bReplace=1 时表示符号指针不为空才根据符号名称重新定位符号指针
//bReplace=2 时表示符号指针不为空时根据符号指定的名称重新设定插入的符号名称
int PositionNew(int bReplace=1, BOOL bIncludeLayerEmbellish=FALSE);
void GetNewUsing(CStringList& arrValue, BOOL bIncludeLayerEmbellish=FALSE);
void *m_pParentXY; //pointer a CXy of parent
void *value; //element pointer
COLORREF color;
CLayer *m_pLayer; //CLayer*
CHowToViewCurve* HowToViewCurve; //CHowToViewCurve*
CHowToViewPoint* HowToViewPoint; //CHowToViewPoint*
CHyperlinkMulti* pHyperlink;
int GetType(void);
int SetType(int nType);
void SetValue(void* pValue, int type);
/**
* 安全的设置值,遗憾的是:由于有多种类型对应同一个类的情况,所以它只支持大部分类型
* @param pValue 带类型的值
*/
template <typename T>
void SetValueSafe(T* pValue)
{
int type = MatchType<T>();
m_type = type;
value = pValue;
}
void* GetValue(void);
/**
* 安全的获取值,如果类型不匹配,将抛出异常,避免错误到处蔓延
*/
template <typename T>
T* GetValueSafe()
{
int type = MatchType<T>();
if (type != m_type)
{
throw std::runtime_error("Type mismatch: Expected " + std::to_string(type) + ", but got " + std::to_string(m_type));
}
return reinterpret_cast<T*>(value);
}
CLayer* GetLayer(void);
CLayer* SetLayer(CLayer* pLayer);
long GetDisplayColor(void);
int Replace(COLORREF cOldColor, COLORREF cNewColor);
int SetColor(COLORREF cNewColor); //设置所有的文字、曲线等颜色
template <typename T>
int MatchType()
{
if constexpr (std::is_same_v<T, CCurveEx>)
{
return DOUBLEFOX_CURVE;
}
else if constexpr (std::is_same_v<T, CArc>)
{
return DOUBLEFOX_ARC;
}
else if constexpr (std::is_same_v<T, CPointNameEx>)
{
return DOUBLEFOX_POINT;
}
else if constexpr (std::is_same_v<T, CPointCrossName>)
{
return DOUBLEFOX_CROSSPOINT;
}
else if constexpr (std::is_same_v<T, CPointTwoName>)
{
return DOUBLEFOX_TWOPOINT;
}
else if constexpr (std::is_same_v<T, CXPointName>)
{
return DOUBLEFOX_XPOINT;
}
else if constexpr (std::is_same_v<T, CCurveRect>)
{
return DOUBLEFOX_CRECT;
}
else if constexpr (std::is_same_v<T, CInsertOld>)
{
return DOUBLEFOX_INSERT;
}
else if constexpr (std::is_same_v<T, CInsertDraw>)
{
return DOUBLEFOX_DRAW;
}
else if constexpr (std::is_same_v<T, CInsertDrawRect>)
{
return DOUBLEFOX_DRAW_RECT;
}
else if constexpr (std::is_same_v<T, CProportion>)
{
return DOUBLEFOX_PROPORTION;
}
else if constexpr (std::is_same_v<T, CText>)
{
return DOUBLEFOX_TEXT;
}
else if constexpr (std::is_same_v<T, CEllipse>)
{
return DOUBLEFOX_ELLIPSE;
}
else if constexpr (std::is_same_v<T, CCircle>)
{
return DOUBLEFOX_CIRCLE;
}
else if constexpr (std::is_same_v<T, CFrame>)
{
return DOUBLEFOX_FRAME;
}
else if constexpr (std::is_same_v<T, CImageInsert>)
{
return DOUBLEFOX_IMAGE;
}
else if constexpr (std::is_same_v<T, CMesh>)
{
return DOUBLEFOX_MESH;
}
else if constexpr (std::is_same_v<T, CMxn>)
{
return DOUBLEFOX_MXN;
}
else if constexpr (std::is_same_v<T, CSection>)
{
return DOUBLEFOX_SECTION;
}
else if constexpr (std::is_same_v<T, CGridding>)
{
return DOUBLEFOX_GRID;
}
else if constexpr (std::is_same_v<T, CNet>)
{
return DOUBLEFOX_NET;
}
else if constexpr (std::is_same_v<T, COtherDraw>)
{
return DOUBLEFOX_OTHERDRAW;
}
else if constexpr (std::is_same_v<T, COleObject>)
{
return DOUBLEFOX_OLE;
}
else if constexpr (std::is_same_v<T, CTree>)
{
return DOUBLEFOX_TREE;
}
else if constexpr (std::is_same_v<T, CMetaFile>)
{
return DOUBLEFOX_WMF;
}
else if constexpr (std::is_same_v<T, CStation>)
{
return DOUBLEFOX_STATION;
}
else if constexpr (std::is_same_v<T, CMText>)
{
return DOUBLEFOX_MTEXT;
}
else if constexpr (std::is_same_v<T, CScaleRuler>)
{
return DOUBLEFOX_SCALERULER;
}
else if constexpr (std::is_same_v<T, CXyBlock>)
{
return DOUBLEFOX_BLOCK;
}
else if constexpr (std::is_same_v<T, CHorizontalWell>)
{
return DOUBLEFOX_HORIZONTALWELL;
}
else if constexpr (std::is_same_v<T, CRectLabel>)
{
return DOUBLEFOX_RECTLABEL;
}
else if constexpr (std::is_same_v<T, C3DCurveSection>)
{
return DOUBLEFOX_3D_SURVEY_SECTION;
}
else if constexpr (std::is_same_v<T, CFaultLine>)
{
return DOUBLEFOX_FAULTLINE;
}
else if constexpr (std::is_same_v<T, CWellGroup>)
{
return WELL_GROUP;
}
else
{
static_assert(always_false<T>::value, "Unsupported type");
}
}
public:
BOOL IsCanEdit(void);
BOOL IsView(void);
void SetViewState(int nView);
int GetViewState();
void operator=(const COne& one);
CString GetName(void);
BOOL SetName(LPCTSTR lpszOneName);
CHyperlinkMulti* GetHyperlink(void);
void SetHyperlink(CHyperlinkMulti* ph);
void SetHyperlink(CString strCommand);
void CopySetHyperlink(CHyperlinkMulti* ph);
void TransformPoint(float* matrix, double& x0, double& y0, BOOL bUndo);
void TransformPoint(float* matrix, CPoint2D& pt, BOOL bUndo);
BOOL Transform(CXyDC* pDC, float* matrix, BOOL bUndo=FALSE);//matrix length is 6
int TransformImage(CXyDC* pDC, float* matrix, BOOL bUndo);
void Transform(CXyDC* pDC, float* matrix, double& x, double& y, BOOL bUndo);
void Offset(double dx, double dy);
void ScaleCoor(double xs, double ys, double dx, double dy);
void ScaleProperty(double sx, double sy, BOOL bPersonalEmbellish, BOOL bOwnerProperties);
void Rotate(double xs, double ys, double angle);
void ScaleCoordinate(double sx, double sy, int mode); //mode=0:加1:减2:乘3:除
void ExchangeXY(void); //交换XY坐标
void ExchangeXY(CProjection& xyz); //转换到指定投影坐标
void CloneOtherParameter(const COne& one);
private:
void SerializeHowToCurve(CArchive& ar, const short& ver);
void SerializeHowToPoint(CArchive& ar, const short& ver);
void SerializeHyperlink(CArchive& ar, const short& ver);
/**
* 判断是否是线及其派出类
*
* \return
*/
bool IsCurveDerived() const;
/**
* 判断是否是 CPointNameBase 及其派生类
*
* \return
*/
bool IsCPointNameBaseDerived() const;
bool IsCXyBlockDerived() const;
bool IsCNetDerived() const;
CString m_layerName;
};
AFX_INLINE int COne::GetType(void)
{
return m_type;
}
AFX_INLINE int COne::SetType(int nType)
{
int tt=m_type;
m_type=nType;
return tt;
}
AFX_INLINE void* COne::GetValue(void)
{
return value;
}
AFX_INLINE BOOL COne::IsView(void)
{
return (m_ViewState==VIEW_STATE) ? TRUE:FALSE;
}
AFX_INLINE CLayer* COne::GetLayer(void)
{
return this->m_pLayer;
}
AFX_INLINE CLayer* COne::SetLayer(CLayer* pLayer)
{
return m_pLayer=pLayer;
}
AFX_INLINE void COne::SetViewState(int nView)
{
m_ViewState=nView;
}
AFX_INLINE int COne::GetViewState()
{
return m_ViewState;
}
AFX_INLINE CHyperlinkMulti* COne::GetHyperlink(void)
{
return pHyperlink;
}
#endif // !defined(AFX_ONE_H__84CE3923_A99C_4888_AE1B_131E3FC6A3FB__INCLUDED_)