515 lines
12 KiB
C++
515 lines
12 KiB
C++
#pragma warning( push ,0)
|
|
#include <cassert>
|
|
#include <algorithm>
|
|
|
|
#include <QFile>
|
|
|
|
#include "BaseObject.h"
|
|
#include "ObjectID.h"
|
|
// #include "ObjProject.h"
|
|
// #include "ObjWell.h"
|
|
// #include "ObjWelllogRound.h"
|
|
// #include "ObjDiscreteWellLog.h"
|
|
#pragma warning( pop )
|
|
|
|
BEGIN_OSGDATAMODEL_NAMESPACE;
|
|
|
|
sObjectClassIDKey::sObjectClassIDKey()
|
|
{
|
|
|
|
}
|
|
|
|
sObjectClassIDKey::sObjectClassIDKey( QUuid ObjectClassID )
|
|
{
|
|
m_ObjectClassID = ObjectClassID ;
|
|
}
|
|
|
|
bool sObjectClassIDKey::operator !=( const sObjectClassIDKey& s )
|
|
{
|
|
return m_ObjectClassID != s.m_ObjectClassID;
|
|
}
|
|
|
|
bool sObjectClassIDKey::operator < ( const sObjectClassIDKey& s ) const
|
|
{
|
|
return m_ObjectClassID < s.m_ObjectClassID;
|
|
}
|
|
|
|
|
|
// CBaseObjectImpl::~CBaseObjectImpl()
|
|
// {
|
|
// DeleteAllChild();
|
|
// }
|
|
|
|
|
|
// QString CPaiObjectHelper::GetUniqueChildName(PaiObject *pPaiObject,QString strPreFixName )
|
|
// {
|
|
// if(! pPaiObject->GetObjectByName ( strPreFixName ) )
|
|
// return strPreFixName;
|
|
// return pPaiObject->GetNextChildName(strPreFixName);
|
|
// }
|
|
|
|
// void CBaseObjectImpl::Init(QUuid classID)
|
|
// {
|
|
// m_classTypeID = classID;
|
|
// }
|
|
|
|
// QUuid CBaseObjectImpl::GetTypeID() const
|
|
// {
|
|
// return m_classTypeID;
|
|
// }
|
|
|
|
|
|
// PaiObject *CPaiObjectHelper::GetRoot(PaiObject * pThis)
|
|
// {
|
|
// PaiObject *pRoot = pThis;
|
|
// while( pRoot && pRoot->GetParent() )
|
|
// {
|
|
// pRoot = pRoot->GetParent();
|
|
// }
|
|
|
|
// return pRoot;
|
|
// }
|
|
|
|
// bool CBaseObject::Contains(const QUuid& id)
|
|
// {
|
|
// if(this->m_pPaiObject != NULL)
|
|
// {
|
|
// return NULL != (m_pPaiObject->GetObject(id));
|
|
// }
|
|
// return false;
|
|
// }
|
|
|
|
// std::vector<CBaseObject*> CPaiObjectHelper::GetAllSymbolObject( CBaseObject * pOSGObject )
|
|
// {
|
|
// std::vector<PaiObject*> vAllChildrenandSelf;
|
|
// std::vector<CBaseObject*> vAllChildren;
|
|
// CPaiObjectHelper::RecursionGetAllChild( dynamic_cast<PaiObject*>(pOSGObject),vAllChildrenandSelf);
|
|
// foreach (PaiObject* pChild,vAllChildrenandSelf)
|
|
// {
|
|
// QString t_name = pChild->GetName();
|
|
// if ( !(pChild->GetChildrenCount()) )
|
|
// {
|
|
// //判断是否为图像 如果不是则continue
|
|
// if (t_name.right(4).left(1) != ".") continue;
|
|
// if( dynamic_cast<CBaseObject*>( pChild ) )
|
|
// vAllChildren.push_back(dynamic_cast<CBaseObject*>( pChild ));
|
|
// }
|
|
// }
|
|
// return vAllChildren;
|
|
// }
|
|
|
|
// CBaseObject * CPaiObjectHelper::GetSubtree( CBaseObject * pThis,QString strRelativeFolderPath )
|
|
// {
|
|
// QStringList folderNamelist = strRelativeFolderPath.split("/");
|
|
|
|
// CBaseObject * pViewObject= pThis;
|
|
// foreach ( QString strfolderName, folderNamelist )
|
|
// {
|
|
// pViewObject = dynamic_cast<CBaseObject*>(GetChildByName(dynamic_cast<PaiObject*>(pViewObject),strfolderName) );
|
|
// if( !pViewObject) return NULL;
|
|
// }
|
|
// return pViewObject;
|
|
// }
|
|
|
|
// PaiObject* CPaiObjectHelper::GetChildByName(PaiObject*pObject,QString name)
|
|
// {
|
|
// QList<PaiObject*> lstChildren;
|
|
// pObject->GetChildren(lstChildren);
|
|
|
|
// foreach(PaiObject * pChildObject, lstChildren)
|
|
// {
|
|
// if((pChildObject->GetName()) == name) return pChildObject;
|
|
// }
|
|
// return NULL;
|
|
// }
|
|
|
|
|
|
// pai::ios::welllog::DataObject* CBaseObjectImpl::GetDbObject()
|
|
// {
|
|
// return NULL;
|
|
// }
|
|
|
|
// bool CPaiObjectHelper::SerializeDB( CObjectArchive &ar,pai::ios::welllog::DataObject *pDbObject ,pai::objectmodel::PaiObject *pPaiObject )
|
|
// {
|
|
// if( ar.IsStoring() )
|
|
// {
|
|
// //保存到数据库
|
|
// long long dataID = 0;
|
|
// if( pDbObject )
|
|
// {
|
|
// dataID = pDbObject->GetDataID();
|
|
// if( pPaiObject )
|
|
// {
|
|
// pDbObject->SetName( pPaiObject->GetName().toStdString() );
|
|
// }
|
|
// if( dataID==0 )
|
|
// {
|
|
// pai::datamodel::CObjDiscreteWellLog *discreteWellLog = dynamic_cast<pai::datamodel::CObjDiscreteWellLog*>(pPaiObject);
|
|
// if(discreteWellLog)
|
|
// {
|
|
// discreteWellLog->SaveDBObject();
|
|
|
|
// }
|
|
// else
|
|
// {
|
|
// pDbObject->Save();
|
|
// }
|
|
|
|
// }else
|
|
// {
|
|
// pDbObject->Update();
|
|
// }
|
|
// dataID = pDbObject->GetDataID();
|
|
// }
|
|
// ar<< dataID;
|
|
// }else
|
|
// {
|
|
// long long dataID(0);
|
|
// ar >> dataID;
|
|
// if( pDbObject && dataID > 0)
|
|
// {
|
|
// pDbObject->SetDataID( dataID );
|
|
// pDbObject->Get( dataID );
|
|
// }
|
|
// }
|
|
// return true;
|
|
// }
|
|
|
|
CObjectGenralFactory< sObjectClassIDKey,CBaseObject >& CBaseObject::GetFatory()
|
|
{
|
|
static COSGObjectFactory fatory;
|
|
return fatory;
|
|
}
|
|
|
|
|
|
/*void CPaiObjectHelper::RecursionGetAllChild(PaiObject* pThis,std::vector<PaiObject*> &vChild)
|
|
{
|
|
if( !pThis ) return;
|
|
|
|
vChild.push_back( pThis ) ;
|
|
|
|
QList<PaiObject*>vChildThis ;
|
|
pThis->GetChildren(vChildThis);
|
|
foreach( PaiObject *pChild,vChildThis )
|
|
{
|
|
RecursionGetAllChild(pChild, vChild );
|
|
}
|
|
}
|
|
|
|
void CPaiObjectHelper::RecursionGetAllChildren( PaiObject* pThis,std::vector<CBaseObject*> &vChild )
|
|
{
|
|
std::vector<PaiObject*> vPaiChild;
|
|
RecursionGetAllChild( pThis,vPaiChild );
|
|
|
|
foreach( PaiObject* pObject,vPaiChild )
|
|
{
|
|
if( dynamic_cast<CBaseObject*>( pObject ) )
|
|
{
|
|
vChild.push_back( dynamic_cast<CBaseObject*>( pObject ) );
|
|
}
|
|
}
|
|
}*/
|
|
|
|
// void CBaseObjectImpl::Delete()
|
|
// {
|
|
// // PaiObject*pPai=GetParent();
|
|
// // if(pPai) pPai->RemoveChild(this,false);
|
|
// // SetParent(NULL);
|
|
// DeleteAllChild();
|
|
// delete this;
|
|
// }
|
|
|
|
// bool CBaseObjectImpl::Serialize( CObjectArchive &ar )
|
|
// {
|
|
// pai::ios::welllog::DataObject* pDbObject = GetDbObject();
|
|
|
|
// QFile *pFile = dynamic_cast<QFile *>( ar.GetDevice() );
|
|
// bool bToDisk = pFile ? true :false;
|
|
|
|
// if(ar.IsStoring())
|
|
// {
|
|
// BEGIN_WRITE_OBJECT( ar,1 );
|
|
|
|
// BEGIN_WRITE_BLOCK( ar, 1);
|
|
|
|
// //保存到数据库
|
|
// if( bToDisk &&pDbObject)
|
|
// {
|
|
// CPaiObjectHelper::SerializeDB( ar,pDbObject,this );
|
|
// }
|
|
|
|
// //保存自己的信息
|
|
// ar << GetID();
|
|
// ar << GetName();
|
|
// ar <<GetGhostName();
|
|
// //save 所有的孩子
|
|
// if( bToDisk )
|
|
// {
|
|
// QList<PaiObject*> lstChildren;
|
|
// GetChildren(lstChildren);
|
|
// int nChildCout = lstChildren.size();
|
|
// ar << nChildCout;
|
|
// for( long i = 0 ; i< nChildCout;++i )
|
|
// {
|
|
// CBaseObject* pChild = dynamic_cast<CBaseObject*>( lstChildren[i] );
|
|
// assert( pChild );
|
|
// ar << lstChildren[i] ->GetTypeID().toString();
|
|
// pChild->Serialize( ar );
|
|
// }
|
|
// }
|
|
// END_WRITE_BLOCK( ar, 1 );
|
|
|
|
// END_WRITE_OBJECT( ar );
|
|
// }
|
|
// else
|
|
// {
|
|
// BEGIN_READ_OBJECT( ar,1 );
|
|
|
|
// BEGIN_READ_BLOCK( 1 );
|
|
|
|
// if( bToDisk &&pDbObject)
|
|
// {
|
|
// CPaiObjectHelper::SerializeDB( ar,pDbObject,this );
|
|
// }
|
|
|
|
// //加载自己的信息
|
|
// QString strTmp;
|
|
// ar >> strTmp;
|
|
// SetID(strTmp );
|
|
|
|
// QString strName;
|
|
// ar >> strName;
|
|
// SetName( strName);
|
|
// QString gstrName;
|
|
// ar >>gstrName;
|
|
// SetGhostName(gstrName);
|
|
// //加载所有的孩子
|
|
// if( bToDisk )
|
|
// {
|
|
// DeleteAllChild();
|
|
// int nChildCout(0);
|
|
// ar >> nChildCout;
|
|
// for( long i = 0 ; i< nChildCout;++i )
|
|
// {
|
|
// ar >> strTmp;
|
|
// QUuid classID = QUuid(strTmp);
|
|
// CBaseObject *pChild = GetFatory().CreateObject( classID );
|
|
// PaiObject *pPaiObject = dynamic_cast<PaiObject *>( pChild );
|
|
// CBaseObjectImpl *pChildImp = dynamic_cast<CBaseObjectImpl *>( pChild );
|
|
// if( pChildImp )
|
|
// {
|
|
// pChildImp->Init( classID );
|
|
// }
|
|
// if( pChild )
|
|
// {
|
|
// pChild->Serialize( ar );
|
|
// AddChild( pPaiObject );
|
|
// }else
|
|
// {
|
|
// assert( false);
|
|
// ar.SkipObject();
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// END_READ_BLOCK( 1 );
|
|
|
|
// END_READ_OBJECT( ar );
|
|
// }
|
|
// return true;
|
|
// }
|
|
|
|
CBaseObject *CBaseObject::CloneObject()
|
|
{
|
|
// PaiObject *pPaiObject = this->GetPaiObject();
|
|
// if( pPaiObject )
|
|
// {
|
|
// CBaseObject *pClone = GetFatory().CreateObject( pPaiObject->GetTypeID() );
|
|
// if( pClone )
|
|
// {
|
|
// pClone->CopyFrom( this );
|
|
// pClone->GetPaiObject()->SetID(QUuid::createUuid());
|
|
// return pClone;
|
|
// }
|
|
// }
|
|
|
|
return NULL;
|
|
}
|
|
|
|
CBaseObject *CBaseObject::GhostObject()
|
|
{
|
|
return NULL;
|
|
// CBaseObjectImpl* result=dynamic_cast<CBaseObjectImpl*>(CloneObject());
|
|
// if(!result) return NULL;
|
|
// result->SetGhostName(result->GetPaiObject()->GetName()+OBJ_GHOST_MARK+QString::fromStdString(GenTimeStamp()));
|
|
// result->SetVisibleOnTree(false);
|
|
// return result;
|
|
}
|
|
|
|
void CBaseObject::CopyFrom( CBaseObject *pOSGObjectOther )
|
|
{
|
|
// QByteArray byteArr;
|
|
// {
|
|
// CObjectArchive ar( byteArr, eStore );
|
|
// pOSGObjectOther->Serialize( ar );
|
|
// }
|
|
// CObjectArchive ar( byteArr, eLoad );
|
|
// this->Serialize( ar );
|
|
}
|
|
// void CBaseObject::SetTemplateKey(QVariant TemplateKey)
|
|
// {
|
|
// m_TemplateKey=TemplateKey;
|
|
// }
|
|
|
|
// QVariant CBaseObject::GetTemplateKey()
|
|
// {
|
|
// if(m_TemplateKey!=QVariant()) return m_TemplateKey;
|
|
// PaiObject* paiObject = this->GetPaiObject();
|
|
// if(paiObject != NULL)
|
|
// {
|
|
// // QUuid val=QUuid::createUuid();
|
|
// // m_TemplateKey=QVariant(val);
|
|
// return QVariant(paiObject->GetTypeID());
|
|
// }
|
|
// return QVariant();
|
|
// }
|
|
|
|
// bool CBaseObjectImpl::HasChildren(PaiObject* pChild)
|
|
// {
|
|
// QList<PaiObject*> objectList;
|
|
// PaiObject::GetChildren(objectList);
|
|
// if(objectList.size() > 0)
|
|
// {
|
|
// foreach(PaiObject* obj,objectList)
|
|
// {
|
|
// if(obj == pChild)
|
|
// {
|
|
// return true;
|
|
// }
|
|
// }
|
|
// }
|
|
// return false;
|
|
// }
|
|
// bool CBaseObjectImpl::AddChild(PaiObject* pChild, bool mountNow )
|
|
// {
|
|
// CObjProject::AddIDMap( pChild->GetID(),dynamic_cast<CBaseObject *>( pChild) );
|
|
// QUuid id=GetTypeID();
|
|
// if(id==GetClassID_SingleWellMapFolder()
|
|
// ||id==GetClassID_WorkflowFolder()
|
|
// ||id==GetClassID_SingleMethodFolder()
|
|
// )
|
|
// {
|
|
// if(GetChildrenCount()==0){
|
|
// PaiObject *pPai=GetParent();
|
|
// CObjProject::RemoveIDMap( dynamic_cast<CBaseObject*>(this ) );
|
|
// if(pPai)
|
|
// pPai->RemoveChild(this,false);
|
|
// SetVisibleOnTree(true);
|
|
// CObjProject::AddIDMap( GetID(), dynamic_cast<CBaseObject *>( this));
|
|
// pPai=GetParent();
|
|
// if(pPai)
|
|
// pPai->AddChild(this,MountOnTree);
|
|
// }
|
|
|
|
// }
|
|
// if(mountNow) return PaiObject::AddChild( pChild,MountOnTree );
|
|
// else return PaiObject::AddChild( pChild,MountNoTree );
|
|
// }
|
|
|
|
// bool CBaseObjectImpl::InsertChild(int iIndex,PaiObject* pChild)
|
|
// {
|
|
// CObjProject::AddIDMap( pChild->GetID(), dynamic_cast<CBaseObject *>( pChild));
|
|
// /*
|
|
// if(pChild&&pChild->GetParent()&&pChild->GetParent()) {
|
|
// QList<PaiObject *>lists;
|
|
// pChild->GetParent()->GetChildren(lists);
|
|
// if(lists.size()<iIndex) {
|
|
// pChild->GetParent()->AddChild(pChild);
|
|
// }
|
|
// else if(iIndex<1) {
|
|
// iIndex=0;
|
|
// return PaiObject::InsertChild( iIndex, pChild );
|
|
// }
|
|
// return true;
|
|
// }
|
|
// */
|
|
// return PaiObject::InsertChild( iIndex, pChild );
|
|
// }
|
|
|
|
// bool CBaseObjectImpl::RemoveChild(PaiObject* pChild, bool bDelete )
|
|
// {
|
|
// CObjProject::RemoveIDMap( dynamic_cast<CBaseObject*>(pChild ) );
|
|
// // m_EventAgent.RemoveObjectChild(this, pChild );
|
|
// return PaiObject::RemoveChild( pChild,bDelete );
|
|
|
|
// }
|
|
// bool CBaseObjectImpl::isExistsName(QString name)
|
|
// {
|
|
// QList<PaiObject*> objs;
|
|
// if(this->GetParent() != NULL)
|
|
// {
|
|
// GetParent()->GetChildren(objs);
|
|
// }
|
|
// foreach(PaiObject* obj, objs)
|
|
// {
|
|
// if(obj != NULL && obj != this && obj->GetName().compare(name,Qt::CaseInsensitive)==0)
|
|
// {
|
|
// return true;
|
|
// }
|
|
// }
|
|
// return false;
|
|
// }
|
|
|
|
|
|
// void CBaseObjectImpl::DeleteAllChild()
|
|
// {
|
|
// QList<PaiObject*>::iterator it = m_children.begin();
|
|
// while ( it != m_children.end() )
|
|
// {
|
|
// PaiObject* pChild = (*it);
|
|
// // m_EventAgent.RemoveObjectChild(this, pChild );
|
|
// CObjProject::RemoveIDMap( dynamic_cast<CBaseObject*>( pChild ) );
|
|
// pChild->Delete();
|
|
// ++it;
|
|
// }
|
|
// m_children.clear();
|
|
// }
|
|
|
|
// void CBaseObjectImpl::SetVisibleOnTree(bool visible)
|
|
// {
|
|
// SetFlagEnable(PaiObject::VisibibleOnTree,visible);
|
|
// }
|
|
|
|
// CBaseObjectImpl::CBaseObjectImpl()
|
|
// {
|
|
|
|
// }
|
|
|
|
// bool CBaseObjectImpl::TakeChild(PaiObject* pChild)
|
|
// {
|
|
// if( m_children.contains( pChild ) )
|
|
// {
|
|
// // m_EventAgent.RemoveObjectChild( this,pChild );
|
|
// m_children.removeAll( pChild );
|
|
// return true;
|
|
// }
|
|
// return false;
|
|
// }
|
|
// int CBaseObjectImpl::GetChildPos(PaiObject* pChild)
|
|
// {
|
|
// int o=-1;
|
|
// for(int i=0;i<m_children.size();i++)
|
|
// {
|
|
// if(pChild==m_children.at(i)) {
|
|
// o=i;
|
|
// break;
|
|
// }
|
|
// }
|
|
// return o;
|
|
// }
|
|
// void CBaseObjectImpl::MoveChild(int From,int To)
|
|
// {
|
|
// m_children.move(From,To);
|
|
// }
|
|
END_OSGDATAMODEL_NAMESPACE
|