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.

204 lines
4.4 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.

#pragma once
#include <osg/Geode>
#include <osg/Group>
#include <osg/Switch>
#include <osgGA/GUIEventAdapter>
#include <osgGA/GUIActionAdapter>
#include "../Assist/XJOSGCommon.h"
#include "XJObjectManager/XJObject.h"
#include "ViewCommon.h"
//模型的维度,二维或三维
enum ModelDimension {MODEL_2D, MODEL_3D};
class CXJOSGObject : public /*osg::Group*/osg::Geode
{
public:
enum {OSG_BASE_KEY = 10000};
//构造函数
CXJOSGObject();
CXJOSGObject(CXJObject * pobj);
//虚构函数
virtual ~CXJOSGObject();
/***************虚函数,在子类中需要重写********************/
//创建显示对象
virtual osg::Geode* CreateObject() = 0;
//更新显示对象
virtual int Update(EOSGUpdateType updateType = UPDATE_ALL);
virtual int SetValue(CXJObject *obj);
//设置当前显示对象的颜色
void SetColor(const osg::Vec4& color){m_color = color;}
osg::Vec4& GetColor(){return m_color;}
//设置显示对象的前一个颜色
void SetPreColor(const osg::Vec4& color){m_preColor = color;}
osg::Vec4& GetPreColor(){return m_preColor;}
//设置视图对象的高亮颜色
void SetHilightColor(const osg::Vec4& color) {m_hilightColor = color;}
osg::Vec4 GetHilightColor() {return m_hilightColor;}
int GetKey(){return m_3dKey;}
//设置显示对象的类型
void SetType(EXJObjectType type){m_type = type;}
EXJObjectType GetType(){return m_type;}
//设置对象的显示状态
void SetVisible(bool visible)
{
if(m_pObject)
{
m_pObject->SetVisibility(visible);
m_visible = visible;
}
}
bool GetVisible(){return m_visible;}
//设置显示对象的透明度级别
void SetTransparencyLevel(float translevel);
float GetTransparencyLevel() {return m_color[3];}
//设置显示对象的透明度
void SetTransparency(bool transparent)
{
if(m_pObject)
{
m_pObject->SetTransparent(transparent);
m_transparent = transparent;
m_nTransparent = m_pObject->GetTransparentDegree();
}
if (transparent)
{
m_color[3] = m_nTransparent;
m_hilightColor[3] = m_nTransparent;
}
else
{
m_color[3] = 1.0;
m_hilightColor[3] = 1.0;
}
}
//获取显示对象的透明状态
bool GetTransparencyStatus();
//设置显示对象的线框显示状态
void SetWireframe(bool wireframe)
{
if(m_pObject)
{
m_pObject->SetWireframe(wireframe);
m_wireframe = wireframe;
}
}
bool GetWireframe(){return m_wireframe;}
//设置视图对象的高亮状态默认情况下是false
bool GetHilightStatus() const {return m_bHiLightStatus;}
void SetHilightStatus(bool _status) {m_bHiLightStatus = _status;}
void SetSwitchParent(osg::Switch *parent){m_switch = parent;}
osg::Switch* GetSwitchParent() {return m_switch;}
void SetMatrixTransformParent(osg::MatrixTransform *parent){m_mt = parent;}
osg::MatrixTransform* GetMatrixTransformParent() {return m_mt;}
void SetRoot(osg::Group *root){m_root = root;}
osg::Group* GetRoot() {return m_root;}
//获得模型的维度
ModelDimension GetModelDimesion() {return m_2Dor3D;}
//删除临时显示对象
virtual void DeleteTempOSGObject() {}
//获取视图对象关联的基础对象
CXJObject* GetOmObject() const {return m_pObject;}
void SetOmObject(CXJObject* pObj) {m_pObject = pObj;}
/*******************鼠标操作************************/
virtual bool selectedAndMove(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ) {return true;}
//Hilight selected obj with color
void HilightWithColor(osg::Vec4& color = osg::Vec4(0.7, 0.0, 0.0, 1.0));
//unlight selected color;
void UnHilight();
virtual void HilightWithShowSize() {}
virtual void UnHlightWithShowSize() {}
void SetHilightIdx(unsigned idx) { m_hilightIdx = idx; }
protected:
virtual void UpdatePosition();
//更新颜色函数
virtual void UpdateColor();
//更新线框
virtual void UpdateWireframe();
//更新等值线
virtual void UpdateIsopleth();
//更新透明度
virtual void UpdateVisible();
//更新网格点
virtual void UpdateMeshPoint();
virtual void UpdateWell();
virtual void UpdateFault();
private:
//创建每个对象的3dKey
int Generate3DKey();
protected:
//每个CXJOSGObj都需要关联一个CXJObject*
CXJObject* m_pObject;
osg::Group* m_root;
osg::Switch* m_switch;
osg::MatrixTransform* m_mt;
int m_3dKey;
//模型的维度是2维还是3维默认是3维
ModelDimension m_2Dor3D;
EXJObjectType m_type;
//m_color为当前颜色m_preColor为上一个颜色
osg::Vec4 m_color;
osg::Vec4 m_preColor;
osg::Vec4 m_hilightColor;
bool m_bHiLightStatus; //高亮状态默认为false
//bool m_bSelected;
bool m_visible;
bool m_wireframe;
bool m_transparent;
float m_nTransparent;
EDisplayModel m_displayModel;
unsigned int m_hilightIdx;
};