logplus/OSGFramework/src/VecViewCommand.cpp

363 lines
9.8 KiB
C++
Raw Normal View History

2026-01-17 12:49:42 +08:00
#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;