提交OSGFramework

This commit is contained in:
zhaolei 2026-01-17 12:49:42 +08:00
parent 1b8d989d18
commit e855edcfa8
4 changed files with 861 additions and 0 deletions

View File

@ -0,0 +1,224 @@
/**
* @file VecCoordinate.h
* @brief
* @date 2014-5-26
* @author: liyonggang
*/
#ifndef PAI_FRAME_CVECCOORDINATE_H
#define PAI_FRAME_CVECCOORDINATE_H
#pragma warning( push ,0)
#include <QUuid>
// #include <Vec2d>
// #include <Vec3f>
// #include <Matrix>
#include "OSGFramework.h"
// #include "VecGeoToGeoNormalCoordinate.h"
// #include "VecWindowDocument.h"
// #include "2DWindowViewInfo.h"
#pragma warning( pop )
BEGIN_OSGGRAPHICS_NAMESPACE
class CVecSceneManager;
END_OSGGRAPHICS_NAMESPACE;
BEGIN_OSGGRAPHICS_NAMESPACE;
enum eCoordType
{
//原始的用户业务坐标
eCoord_GEO,//深度,工程值
//归一化的用户业务坐标统一用户业务坐标到OSG的坐标系
eCoord_GEONormal,//对数变换、倒置坐标轴
// OSG 物体局部坐标系. 就是平常渲染时给OSG::Geometry的顶点坐标
eCoord_OSGLocal, //道内横向刻度
// OSG 全局模型坐标系,( transform by CVecSceneManager Global Model transform)
eCoord_OSGGlobal,//窗口中坐标
//相机坐标系,眼睛坐标系( 视图矩阵变化后)
eCoord_OSGCameraEye,
// 投影矩阵变化后的归一化三维坐标(x,y,z的范围都是(-1,1) )
eCoord_OSGNormal,
// OSG的视口二维像素坐标( Y轴正方向是由下到上 )
eCoord_OSGPixel,
// QT Widget的窗口二维像素坐标( Y轴正方向是由上到下 )
eCoord_GDIPixel,
// 厘米单位坐标( Y轴正方向是由上到下 )
eCoord_GDICM,
};
// /**
// * @class IVecCoordinate
// * @brief 通用的坐标转换:任意两种坐标之间的转换
// */
// class OSGFRAMEWORK_EXPORT IVecCoordinate
// {
// public:
// IVecCoordinate();
// virtual ~IVecCoordinate();
// /**
// * @brief 把点从一个坐标系统转换另外一个坐标系统
// * @param ObjectID Object ID,特别是在转为Well Section Geo坐标时有正确的Objecct ID
// * @param eInCoordType 输入点的坐标系统
// * @param inCoord 输入的顶点
// * @param eOutCoordType输出的坐标系统类型
// * @param outCoord 输出的顶点
// */
// virtual void ConvertCoord( const QUuid &ObjectID,eCoordType eInCoordType, osg::Vec3f inCoord,
// eCoordType eOutCoordType,osg::Vec3f& outCoord) = 0 ;
// /**
// * @brief 把点从一个坐标系统转换另外一个坐标系统
// * @param ObjectID Object ID,特别是在转为Well Section Geo坐标时有正确的Objecct ID
// * @param eInCoordType 输入点的坐标系统
// * @param inCoord 输入的顶点
// * @param eOutCoordType输出的坐标系统类型
// * @param outCoord 输出的顶点
// */
// virtual void ConvertCoordDouble( const QUuid &ObjectID,eCoordType eInCoordType, osg::Vec3d inCoord,
// eCoordType eOutCoordType,osg::Vec3d& outCoord ) = 0 ;
// /**
// * @brief 把"长度"从一个坐标系统转换到另外一个坐标系统
// * @param ObjectID Object ID,特别是在转为Well Section Geo坐标时有正确的Objecct ID
// * @param eInCoordType 输入点的坐标系统
// * @param inCoord 输入的长度
// * @param eOutCoordType输出的坐标系统类型
// * @param outCoord 输出的长度
// * @param bAbs 输出的长度是否取绝对值
// */
// virtual void ConvertDeltaCoord( const QUuid &ObjectID,eCoordType eInCoordType, osg::Vec3d inCoord,
// eCoordType eOutCoordType,osg::Vec3d& outCoord ,bool bAbs) = 0;
// };
// /**
// * @class IVecCoordinate
// * @brief 通用的坐标转换:任意两种坐标之间的转换
// */
// class OSGFRAMEWORK_EXPORT CVecCoordinate : public IVecCoordinate
// {
// public:
// CVecCoordinate();
// virtual void InitSceneManager(CVecSceneManager *ppSceneManager);
// /**
// * @brief 把点从一个坐标系统转换另外一个坐标系统
// * @param ObjectID Object ID,特别是在转为Well Section Geo坐标时有正确的Objecct ID
// * @param eInCoordType 输入点的坐标系统
// * @param inCoord 输入的顶点
// * @param eOutCoordType输出的坐标系统类型
// * @param outCoord 输出的顶点
// */
// virtual void ConvertCoord( const QUuid &ObjectID,eCoordType eInCoordType, osg::Vec3f inCoord,
// eCoordType eOutCoordType,osg::Vec3f& outCoord) ;
// virtual void ConvertCoordDoubleNoGEONormal( const QUuid &ObjectID,eCoordType eInCoordType, osg::Vec3d inCoord,
// eCoordType eOutCoordType,osg::Vec3d& outCoord );
// /**
// * @brief 把点从一个坐标系统转换另外一个坐标系统
// * @param ObjectID Object ID,特别是在转为Well Section Geo坐标时有正确的Objecct ID
// * @param eInCoordType 输入点的坐标系统
// * @param inCoord 输入的顶点
// * @param eOutCoordType输出的坐标系统类型
// * @param outCoord 输出的顶点
// */
// virtual void ConvertCoordDouble( const QUuid &ObjectID,eCoordType eInCoordType, osg::Vec3d inCoord,
// eCoordType eOutCoordType,osg::Vec3d& outCoord ) ;
// /**
// * @brief 把"长度"从一个坐标系统转换到另外一个坐标系统
// * @param ObjectID Object ID,特别是在转为Well Section Geo坐标时有正确的Objecct ID
// * @param eInCoordType 输入点的坐标系统
// * @param inCoord 输入的长度
// * @param eOutCoordType输出的坐标系统类型
// * @param outCoord 输出的长度
// * @param bAbs 输出的长度是否取绝对值
// */
// void ConvertDeltaCoord( const QUuid &ObjectID,eCoordType eInCoordType, osg::Vec3d inCoord,
// eCoordType eOutCoordType,osg::Vec3d& outCoord ,bool bAbs) ;
// //同ConvertCoordDouble只处理X坐标
// virtual double ConvertX( const QUuid &ObjectID,eCoordType eInCoordType, double x,
// eCoordType eOutCoordType );
// //同ConvertCoordDouble只处理Y坐标
// virtual double ConvertY( const QUuid &ObjectID,eCoordType eInCoordType, double y,
// eCoordType eOutCoordType );
// //同ConvertDeltaCoord只处理X方向长度
// virtual double ConvertDeltaX( const QUuid &ObjectID,eCoordType eInCoordType, double x,
// eCoordType eOutCoordType,bool bAbs ) ;
// //同ConvertDeltaCoord只处理Y方向长度
// virtual double ConvertDeltaY( const QUuid &ObjectID,eCoordType eInCoordType, double y,
// eCoordType eOutCoordType,bool bAbs) ;
// /**
// * @brief 每厘米像素数
// */
// void SetPixelPerCm(QPrinter *pDC);
// void SetPixelPerCm(QPainter *pDC);
// void SetPixelPerCm(double PixelPerCm);
// double GetPixelPerCm();
// /**
// * @brief 像素转为厘米
// */
// double PixelToCM( double fPixel );
// /**
// * @breif 返回对于指定的坐标系而言每个像素对应的高度
// * @param objectID 对象ID,通常为空
// * @param eOutCoordType 结果坐标系的类型
// */
// double HeightPerPixel(const QUuid& objectID,eCoordType eOutCoordType);
// /**
// * @breif 返回对于指定的坐标系而言每个像素对应的高度
// * @param objectID 对象ID,通常为空
// * @param eOutCoordType 结果坐标系的类型
// */
// double WidthPerPixel(const QUuid& objectID,eCoordType eOutCoordType);
// virtual osg::Vec3d TransfromGeo_GeoNormal(const QUuid &ObjectID, osg::Vec3d in, bool bPositive);
// bool IsXYSwap( eCoordType eInCoordType,eCoordType eOutCoordType );
// private:
// typedef osg::Vec3d (*TransfromCoordinateFunc)(CVecCoordinate *pCoordinate, const QUuid &ObjectID,osg::Vec3d in, bool bPositive);
// //坐标系统之间相互转换的函数。每个函数只负责相邻的两个坐标系之间的转换
// static osg::Vec3d TransfromGeo_GeoNormal(CVecCoordinate *pCoordinate,const QUuid &ObjectID, osg::Vec3d in, bool bPositive);
// static osg::Vec3d TransfromGeoNormal_OSGLocal(CVecCoordinate *pCoordinate,const QUuid &ObjectID, osg::Vec3d in, bool bPositive);
// static osg::Vec3d TransfromOSGLocal_Global(CVecCoordinate *pCoordinate, const QUuid &ObjectID,osg::Vec3d in, bool bPositive);
// static osg::Vec3d TransfromOSGGlobal_EyePosition(CVecCoordinate *pCoordinate,const QUuid &ObjectID, osg::Vec3d in, bool bPositive);
// static osg::Vec3d TransfromEye_NormalizedPosition(CVecCoordinate *pCoordinate,const QUuid &ObjectID, osg::Vec3d in, bool bPositive);
// static osg::Vec3d TransfromOSGNormalizedPosition_Pixel(CVecCoordinate *pCoordinate,const QUuid &ObjectID, osg::Vec3d in, bool bPositive);
// static osg::Vec3d TransfromOSGPixel_GDIPixel(CVecCoordinate *pCoordinate,const QUuid &ObjectID, osg::Vec3d in, bool bPositive);
// static osg::Vec3d TransfromGDIPixel_GDICM(CVecCoordinate *pCoordinate,const QUuid &ObjectID, osg::Vec3d in, bool bPositive);
// protected:
// C2DWindowViewInfo *m_pWindowViewInfo;
// bool m_bInitWindowViewInfo;
// protected:
// std::vector< TransfromCoordinateFunc > m_vTransfromCoordinateFunc;// 坐标转换的函数指针数组
// public:
// CVecSceneManager *m_pSceneManager;
// CVecGeoToGeoNormalCoordinate m_GeoToGeoNormalCoordinate;
// double dPixelPerCm;
// osg::Matrixd m_WindowMatrix;
// osg::Matrixd m_ProjectMatrix;
// osg::Matrixd m_ViewMatrix;
// };
END_OSGGRAPHICS_NAMESPACE;
using namespace pai::graphics;
#endif

View File

@ -0,0 +1,202 @@
/**
* @file VecViewCommand.h
* @brief Action插件集合管理类
* @date 2014-5-26
* @author: liyonggang
*/
#ifndef PAI_FRAME_OSGVIEWCOMMAND_H
#define PAI_FRAME_OSGVIEWCOMMAND_H
#pragma warning( push ,0)
#include <QAction>
#include "OSGFramework.h"
#include "BaseObject.h"
#pragma warning( pop )
#pragma warning( disable: 4251 )
BEGIN_OSGGRAPHICS_NAMESPACE;
class CVecSceneManager;
/**
* @class Action的数据描述
*/
struct OSGFRAMEWORK_EXPORT sAction
{
public:
sAction();
sAction( QString strIcon1,std::wstring strText1,bool bChecked1,bool bCheckAble1 ,QUuid DigitizerIDOrBuilderOjectID,QString slotFunctionName1,QKeySequence keyShortcut1 = QKeySequence () );
public:
QString strIcon;
std::wstring strText;
bool bChecked;
bool bCheckAble;
QUuid m_DigitizerIDOrBuilderOjectID;//(开关digitizer ID) 或 (显示隐藏UI builder的object ID)
QKeySequence keyShortcut;
QString slotFunctionName;
};
/**
* @class Action插件集合管理类
*/
class OSGFRAMEWORK_EXPORT CVecViewCommand : public QObject
{
Q_OBJECT
public:
/**
* @brief
*/
CVecViewCommand( );
void InitSceneManager( CVecSceneManager *pSceneManager );
CVecSceneManager* GetSceneManager();
/**
* @brief Action,Actioin
* @param viewCommandID : command ID
* @bChecked : Checkable的Action,Checked
*/
bool DoAction( QUuid viewCommandID,bool bChecked );
/**
* @brief Command ID查找QAction
*/
QAction* GetAction( QUuid viewCommandID,bool bCreateIfNotExist = true );
/**
* @brief Action checked and Enabled
*/
bool GetActionVisble( QUuid viewCommandID );
//返回当前视口安装的所有的Action
QMap<QUuid,QObject* >& GetAllActions();
/**
* @brief QAction
*/
static void BuildActionGeneral( CVecViewCommand &viewCommand,QUuid viewCommandID );
/**
* @brief view commandID查找Digitizer ID
*/
static QUuid GetDigitizerIDByViewCommandID( QUuid viewCommandID );
// Action槽函数
private slots:
void slotActionClicked(bool bChecked);
private:
//批量的根据插件注册的元数据创建QAction
void CreatActions( QList<QUuid> listviewCommandID );
// Cache Action
void AddUIElementToMap( QUuid viewCommandID,QObject *pAction );
// 根据插件注册的元数据创建QAction
QAction* _CreateAction( QUuid viewCommandID );
private:
CVecSceneManager *m_pSceneMgr;
QMap<QUuid/*Action ID*/,QObject* /*Action*/ >m_mapUIElement; //cache Action
};
typedef void (*BUILDUIELEMENT_FUNC )(CVecViewCommand &,QUuid);
typedef void (*UIELEMENTACTION_FUNC )(CVecViewCommand &,QUuid,bool);
/**
* @class Action函数指针Action""
*/
struct OSGFRAMEWORK_EXPORT sUIELEMENTFunction
{
public:
sUIELEMENTFunction()
{
buildFunc = NULL;
ActionSlot = NULL;
}
sUIELEMENTFunction( BUILDUIELEMENT_FUNC buildFunc1,UIELEMENTACTION_FUNC ActionSlot1 )
{
buildFunc = buildFunc1;
ActionSlot = ActionSlot1;
}
BUILDUIELEMENT_FUNC buildFunc;
UIELEMENTACTION_FUNC ActionSlot;
};
/**
* @brief ViewComand的创建和槽的函数指针
*/
OSGFRAMEWORK_EXPORT QMap< QUuid/*Action ID*/,sUIELEMENTFunction >& GetmapUIElementFunc();
/**
* @brief View Command
* @param viewCommandID :Command ID
* @param s : Command ()
* @param pSlotAction: Command对应的""
*/
OSGFRAMEWORK_EXPORT void RegisterViewAction( QUuid viewCommandID,sAction s,UIELEMENTACTION_FUNC pSlotAction);
/**
* @brief ViewComand的元数据:
*/
OSGFRAMEWORK_EXPORT QMap<QUuid/*Action ID*/,sAction >& _GetMapActionData();
OSGFRAMEWORK_EXPORT CVecViewCommand& GetGlobalCommand();
/**
* @class View Command注册的元数据
*/
struct OSGFRAMEWORK_EXPORT sRegisterViewAction
{
QUuid actionID;
sAction s;
UIELEMENTACTION_FUNC pSlotAction;
};
/**
* @class View Command自动注册的辅助类
*/
class OSGFRAMEWORK_EXPORT CRegisterViewActionAuto
{
public:
CRegisterViewActionAuto( sRegisterViewAction *pRegisterViewAction )
{
while( pRegisterViewAction )
{
if( (*pRegisterViewAction).actionID.isNull() ) break;
RegisterViewAction( pRegisterViewAction->actionID, pRegisterViewAction->s, pRegisterViewAction->pSlotAction );
++pRegisterViewAction;
}
}
};
//view Comand 插件注册宏
#define BEGIN_REGISTER_VIEWCOMMAND()\
sRegisterViewAction g_sRegisterViewActionData[]={\
#define END_REGISTER_VIEWCOMMAND()\
,{QUuid(),sAction(),NULL } };\
CRegisterViewActionAuto g_CRegisterViewActionAuto( g_sRegisterViewActionData );
//自动注册示例代码
//BEGIN_REGISTER_VIEWCOMMAND()
//VIEW_COMMAND_ITEM( GetViewCmdID_ViewAll(),"viewall.png" , "View All",false,false,"",_SlotViewAll)
//END_REGISTER_VIEWCOMMAND()
#define VIEW_COMMAND_ITEM( viewCommandID,actionIcon,actionText, actionbChecked, actionbCheckAble,DigitizerIDOrBuilderOjectID,slotFunction )\
{ viewCommandID,sAction( actionIcon,actionText,actionbChecked,actionbCheckAble,DigitizerIDOrBuilderOjectID,#slotFunction),slotFunction }
#define VIEW_COMMAND_ITEM_SHORCUT( viewCommandID,actionIcon,actionText, actionbChecked, actionbCheckAble,DigitizerIDOrBuilderOjectID,slotFunction,actionshortcut )\
{ viewCommandID,sAction( actionIcon,actionText,actionbChecked,actionbCheckAble,DigitizerIDOrBuilderOjectID,#slotFunction,actionshortcut),slotFunction }
END_OSGGRAPHICS_NAMESPACE;
using namespace pai::graphics;
#endif

View File

@ -0,0 +1,73 @@
#-------------------------------------------------
#
# Project created by QtCreator 2024-07-11T18:44:51
#
#-------------------------------------------------
QT += core gui widgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = OSGFramework
TEMPLATE = lib
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += OSGFRAMEWORK_LIB
DEFINES += _WINDOWS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
CONFIG += console \
# static \
c++11 \
shared\
dll
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
CONFIG(debug, debug|release){
DESTDIR = ../../Bin
TARGET = $$join(TARGET,,,d) #为debug版本生成的文件增加d的后缀
} else {
DESTDIR = ../../Bin
TARGET = $$join(TARGET,,,)
}
FORMS +=
HEADERS += \
../include/VecViewCommand.h \
SOURCES += \
VecViewCommand.cpp
INCLUDEPATH += ../include
INCLUDEPATH += ../CallManage
INCLUDEPATH += ../../Slfio/include
INCLUDEPATH += ../../common
INCLUDEPATH += ../../BaseFun/include
INCLUDEPATH += ../../OSGDataModel/include
INCLUDEPATH += ../../DataMgr/include
CONFIG(debug, debug|release){
LIBS += -L../../Bin -lslfiod
LIBS += -L../../Bin -lBaseFund
LIBS += -L../../Bin -lOSGDataModeld
LIBS += -L../../Bin -lDataMgrd
} else {
LIBS += -L../../Bin -lslfio
LIBS += -L../../Bin -lBaseFun
LIBS += -L../../Bin -lOSGDataModel
LIBS += -L../../Bin -lDataMgr
}

View File

@ -0,0 +1,362 @@
#pragma warning(push, 0)
#include <assert.h>
#include <QCoreApplication>
#include <QColorDialog>
#include "VecViewCommand.h"
// #include "VecSceneManager.h"
#include "geometryutils.h"
#include "ObjectID.h"
// #include "PaiAction.h"
#pragma warning(pop)
BEGIN_OSGGRAPHICS_NAMESPACE;
sAction::sAction()
{
bChecked = false;
bCheckAble = false;
}
sAction::sAction( QString strIcon1,std::wstring strText1,bool bChecked1,bool bCheckAble1 ,
QUuid DigitizerIDOrBuilderOjectID,QString slotFunctionName1,QKeySequence keyShortcut1 )
{
strIcon = strIcon1;
strText = strText1;
bChecked = bChecked1;
bCheckAble = bCheckAble1;
keyShortcut = keyShortcut1;
m_DigitizerIDOrBuilderOjectID = DigitizerIDOrBuilderOjectID;
slotFunctionName = slotFunctionName1;
}
QMap<QUuid,sAction > *g_pMapAction = NULL;
OSGFRAMEWORK_EXPORT QMap<QUuid,sAction >& _GetMapActionData()
{
if( !g_pMapAction )
{
g_pMapAction = new QMap<QUuid,sAction >();
}
return *g_pMapAction ;
}
QUuid CVecViewCommand::GetDigitizerIDByViewCommandID( QUuid viewCommandID )
{
QMap<QUuid,sAction >& map = _GetMapActionData();
if( !map.contains( viewCommandID ) )
{
return QUuid();
}
//得到digitizer ID or Builder object ID
QUuid DigitizerID = map[viewCommandID].m_DigitizerIDOrBuilderOjectID;
if( DigitizerID.isNull( ) ) return DigitizerID;
// //是否是digitizer ID
// if( !CVecDigitizer::GetFatory().IsSupport( DigitizerID ) )
// {
// DigitizerID = QUuid();
// }
return DigitizerID;
}
bool _SlotDigitizerOrBuilder( CVecViewCommand &viewCommand,QUuid viewCommandID,bool bShow )
{
//无viewCommandID
QMap<QUuid,sAction >& map = _GetMapActionData();
if( !map.contains( viewCommandID ) )
{
return false;
}
//得到digitizer ID or Builder object ID
QUuid id = map[viewCommandID].m_DigitizerIDOrBuilderOjectID;
if( id.isNull( ) ) return false ;
bool bSucces(false);
// //处理digitizer ID
// if( CVecDigitizer::GetFatory().IsSupport( id ) )
// {
// //特殊处理Well Section window pick ID
// if( id == GetDigitizerID_Pick() )
// {
// if(viewCommand.GetSceneManager()->GetVecWindow()->GetWindowType() ==GetWindowTypeID_QtWellSection()) id = GetDigitizerID_QtWellWindowPick();
// else if(viewCommand.GetSceneManager()->GetVecWindow()->GetWindowType() == GetWindowTypeID_QtMultiWellSection()) id = GetDigitizerID_MultiWell();
// else if(viewCommand.GetSceneManager()->GetVecWindow()->GetWindowType() == GetWindowTypeID_QtGeoGuideSection() ) id = GetDigitizerID_QtWellWindowPick() ;
// }
// bSucces = true;
// if( bShow)
// {
// viewCommand.GetSceneManager()->GetEventHander().SwitchDigitizer( id,QUuid() );
// }else
// {
// ///此处特殊处理 单井窗口
// if(viewCommand.GetSceneManager()->GetVecWindow()->GetWindowType() ==GetWindowTypeID_QtWellSection()) viewCommand.DoAction( GetDigitizerID_QtWellWindowPick(),true );
// else if(viewCommand.GetSceneManager()->GetVecWindow()->GetWindowType() == GetWindowTypeID_QtMultiWellSection()) viewCommand.DoAction( GetDigitizerID_MultiWell(),true );
// else if(viewCommand.GetSceneManager()->GetVecWindow()->GetWindowType() == GetWindowTypeID_QtGeoGuideSection() ) viewCommand.DoAction( GetDigitizerID_QtWellWindowPick(),true );
// else
// {
// viewCommand.DoAction( GetDigitizerID_Pick(),true );
// }
// }
// }else
// {
// //处理Builder Object ID
// CVecNodeBuilder *pBuilder = viewCommand.GetSceneManager()->GetBuilder( id );
// if( pBuilder )
// {
// bSucces = true;
// pBuilder->SetEnable( bShow );
// }
// }
return bSucces;
}
void CVecViewCommand::BuildActionGeneral(CVecViewCommand &viewCommand,QUuid viewCommandID)
{
viewCommand.AddUIElementToMap( viewCommandID,viewCommand._CreateAction(viewCommandID) );
}
CVecSceneManager* CVecViewCommand::GetSceneManager()
{
return m_pSceneMgr;
}
QMap< QUuid,sUIELEMENTFunction >* g_MapAction = NULL;
OSGFRAMEWORK_EXPORT QMap< QUuid,sUIELEMENTFunction >& GetmapUIElementFunc()
{
if( !g_MapAction )
{
g_MapAction = new QMap< QUuid,sUIELEMENTFunction >();
}
return *g_MapAction;
}
CVecViewCommand::CVecViewCommand()
{
m_pSceneMgr = NULL;
}
void CVecViewCommand::slotActionClicked(bool bChecked )
{
QAction *pAction = dynamic_cast<QAction *>( this->sender() );
if( pAction )
{
DoAction( (QUuid)( pAction->data().toString() ),bChecked );
}
}
bool CVecViewCommand::DoAction(QUuid viewCommandID,bool bChecked)
{
QUuid currentid;
// if(m_pSceneMgr&&m_pSceneMgr->GetCurrentDigitzer()) currentid=m_pSceneMgr->GetCurrentDigitzer()->GetDigitizerID();
//CWaitCursor waitCursor;
bool bSuccess(true);
// set action state
QAction* pAction = GetAction( viewCommandID );
if( pAction )
{
pAction->setChecked( bChecked );
}
//执行槽函数
UIELEMENTACTION_FUNC pActionSlot = GetmapUIElementFunc().value(viewCommandID).ActionSlot;
if( pActionSlot )
{
bSuccess = true;
(*pActionSlot)(*this,viewCommandID,bChecked);
}else
{
bSuccess = _SlotDigitizerOrBuilder( *this,viewCommandID,bChecked );
}
// 收集Action互斥数据
QList< QList< QUuid > > listMutexAll;
if( listMutexAll.empty() )
{
QList<QUuid> listViewPostion;
listViewPostion << GetViewCmdID_ViewAbove() << GetViewCmdID_ViewBelow() << GetViewCmdID_ViewEast()
<< GetViewCmdID_ViewWest()<< GetViewCmdID_ViewSouth()<< GetViewCmdID_ViewNorth();
listMutexAll << listViewPostion;
// digitizer Action互斥
QList<QUuid> listDigitizerModel;
{
QMap<QUuid,sAction >&mapAction = _GetMapActionData();
QMap<QUuid,sAction >::Iterator it = mapAction.begin();
for( ; it!= mapAction.end() ; ++it )
{
// if( CVecDigitizer::GetFatory().IsSupport( it.value().m_DigitizerIDOrBuilderOjectID ) )
// {
// listDigitizerModel << it.key();
// }
}
}
listMutexAll << listDigitizerModel;
}
//执行Action互斥
if( bChecked )
{
foreach( QList< QUuid > listMutex,listMutexAll )
{
if( !listMutex.contains(viewCommandID) ) continue;
foreach( QUuid eOther,listMutex )
{
if( eOther != viewCommandID )
{
QAction *pActionOther = GetAction( eOther );
if( pActionOther )
{
pActionOther->setChecked( false );
}
}
}
break;
}
}
return bSuccess ;
}
QAction* CVecViewCommand::GetAction( QUuid viewCommandID,bool bCreateIfNotExist )
{
//创建Action
if( !m_mapUIElement.contains( viewCommandID ) )
{
QList< QUuid > listTypes;
listTypes << viewCommandID;
if( bCreateIfNotExist )
{
CreatActions( listTypes );
}
}
if(m_mapUIElement.contains( viewCommandID ) )
{
return dynamic_cast<QAction* >( m_mapUIElement.value( viewCommandID ) );
}
return NULL;
}
void CVecViewCommand::CreatActions( QList<QUuid> listUIElementType )
{
QMap<QUuid,sAction >&mapAction = _GetMapActionData();
foreach( QUuid viewCommandID,listUIElementType )
{
//已经有了
if( m_mapUIElement.contains( viewCommandID ) )
{
continue;
}
// 如果是有ID,但Digitizer 或Builder都没有实现那么就不创建此Action
if( mapAction.contains( viewCommandID ) )
{
QUuid id = mapAction[viewCommandID].m_DigitizerIDOrBuilderOjectID;
// if( !id.isNull() )
// {
// bool bDigitizerID = CVecDigitizer::GetFatory().IsSupport( id ) ;
// bool bBuilderID = false;
// if( m_pSceneMgr )
// {
// bBuilderID = m_pSceneMgr->GetBuilder( id ) ? true : false;
// }
// if( (!bDigitizerID) && (!bBuilderID) )
// {
// continue;
// }
// }
}
//创建此Action
BUILDUIELEMENT_FUNC pCreateFunction = GetmapUIElementFunc().value( viewCommandID).buildFunc;
if( pCreateFunction )
{
(*pCreateFunction)(*this,viewCommandID);
}
}
}
QAction* CVecViewCommand::_CreateAction( QUuid viewCommandID )
{
QMap<QUuid,sAction >&mapAction = _GetMapActionData();
if( !mapAction.contains(viewCommandID) ) return NULL;
// 根据插件注册的元数据创建QAction
QAction *pAction( NULL );
{
sAction &sAction = mapAction[viewCommandID];
// pAction = new gui::PaiAction( sAction.strIcon.isEmpty() ? QIcon() : QIcon( ::GetImagePath() + sAction.strIcon ),
// QStringFromWCharArray(sAction.strText.c_str(),-1 ),m_pSceneMgr ? dynamic_cast<QObject*>(m_pSceneMgr->GetVecViwer()) : (QObject*)this );
pAction->setData( viewCommandID.toString() );
pAction->setCheckable( sAction.bCheckAble );
pAction->setChecked( sAction.bChecked );
if( !sAction.keyShortcut.isEmpty() )
{
pAction->setShortcut( sAction.keyShortcut );
}
connect( pAction,SIGNAL(triggered ( bool )),SLOT(slotActionClicked(bool)) );
}
return pAction ;
}
void CVecViewCommand::AddUIElementToMap( QUuid viewCommandID,QObject *pUI )
{
m_mapUIElement[viewCommandID] = pUI;
//Do action
QAction *pAction = dynamic_cast<QAction *>(pUI );
if( pAction && pAction->isCheckable() )
{
DoAction( viewCommandID,pAction->isChecked() );
}
}
bool CVecViewCommand::GetActionVisble( QUuid viewCommandID )
{
bool bVisble(false);
QAction *pAction = GetAction( viewCommandID,false );
if( pAction )
{
bVisble = pAction->isChecked() && pAction->isEnabled();
}
return bVisble ;
}
void CVecViewCommand::InitSceneManager(CVecSceneManager *pSceneManager)
{
m_pSceneMgr = pSceneManager;
}
QMap<QUuid,QObject* >& CVecViewCommand::GetAllActions()
{
return m_mapUIElement;
}
OSGFRAMEWORK_EXPORT void RegisterViewAction( QUuid viewCommandID,sAction s,UIELEMENTACTION_FUNC pSlotAction)
{
_GetMapActionData()[ viewCommandID ] = s;
GetmapUIElementFunc()[ viewCommandID ] = sUIELEMENTFunction( CVecViewCommand::BuildActionGeneral,
pSlotAction );
}
OSGFRAMEWORK_EXPORT CVecViewCommand& GetGlobalCommand()
{
static CVecViewCommand s;
return s;
}
END_OSGGRAPHICS_NAMESPACE;