2025-01-12 17:35:51 +00:00
|
|
|
|
#include "ZoomManager.h"
|
|
|
|
|
|
2025-03-13 00:42:41 +00:00
|
|
|
|
#include <osgEarthUtil/EarthManipulator>
|
|
|
|
|
|
2025-01-12 17:35:51 +00:00
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "common/SpdLogger.h"
|
|
|
|
|
#include "viewer/OsgViewUI.h"
|
|
|
|
|
#include "common/RecourceHelper.h"
|
2025-03-13 00:42:41 +00:00
|
|
|
|
#include "scene/OEScene.h"
|
2025-01-12 17:35:51 +00:00
|
|
|
|
|
2025-03-13 00:42:41 +00:00
|
|
|
|
ZoomManager::ZoomManager(OEScene* oeScene)
|
|
|
|
|
: oeScene_(oeScene)
|
2025-01-12 17:35:51 +00:00
|
|
|
|
{
|
|
|
|
|
zoom = 0.0;
|
|
|
|
|
state = ZoomManager::DEFAULT;
|
|
|
|
|
|
|
|
|
|
_canvasZoom = new osgWidget::Canvas("Zoom");
|
|
|
|
|
_canvasZoom->setOrigin(733, 350);
|
|
|
|
|
_canvasZoom->getBackground()->setColor(0, 0, 0, 0);
|
|
|
|
|
_canvasZoom->setVisibilityMode(osgWidget::Window::VM_ENTIRE);
|
|
|
|
|
_canvasZoom->setStrata(osgWidget::Window::STRATA_FOREGROUND);
|
|
|
|
|
|
|
|
|
|
const std::string texturePath = RecourceHelper::Get().GetResourcesPath().toStdString();
|
2025-03-13 00:42:41 +00:00
|
|
|
|
_lessen = new ZoomWidget("lessen", 18, 20, texturePath + "/northarrow/zoom_down.png",
|
|
|
|
|
"lessen", osgWidget::Widget::LAYER_TOP, this);
|
|
|
|
|
_enlargement = new ZoomWidget("enlargement", 18, 20,
|
|
|
|
|
texturePath + "/northarrow/zoom_up.png", "enlargement",
|
|
|
|
|
osgWidget::Widget::LAYER_TOP, this);
|
|
|
|
|
_zoomBackground = new BackGroundWidget("zoomBackground", 18, 144,
|
|
|
|
|
texturePath + "/northarrow/zoomactive.png");
|
|
|
|
|
_bar = new ZoomWidget("bar", 17, 10,
|
|
|
|
|
texturePath + "/northarrow/zoombar_norm.png", "bar",
|
|
|
|
|
osgWidget::Widget::LAYER_TOP, this);
|
|
|
|
|
_bar_ = new BackGroundWidget("bar_", 18, 12,
|
|
|
|
|
texturePath + "/northarrow/zoombar_norm_.png");
|
|
|
|
|
_zoomBackground_shadow = new BackGroundWidget("background_shadow", 18, 144,
|
|
|
|
|
texturePath + "/northarrow/zoombackground.png");
|
2025-01-12 17:35:51 +00:00
|
|
|
|
|
|
|
|
|
_canvasZoom->addWidget(_lessen, 0, 0);
|
|
|
|
|
_canvasZoom->addWidget(_enlargement, 0, 124);
|
|
|
|
|
_canvasZoom->addWidget(_bar_, 0, 66);
|
|
|
|
|
_canvasZoom->addWidget(_bar, 0, 67);
|
|
|
|
|
_canvasZoom->addWidget(_zoomBackground, 0, 0);
|
|
|
|
|
_canvasZoom->addWidget(_zoomBackground_shadow, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ZoomManager::~ZoomManager(void)
|
|
|
|
|
{
|
|
|
|
|
delete _canvasZoom;
|
|
|
|
|
|
|
|
|
|
delete _lessen;
|
|
|
|
|
delete _enlargement;
|
|
|
|
|
delete _zoomBackground;
|
|
|
|
|
delete _bar;
|
|
|
|
|
delete _bar_;
|
|
|
|
|
delete _zoomBackground_shadow;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ZoomManager::ResetCanvasPosition(double x, double y)
|
|
|
|
|
{
|
|
|
|
|
_canvasZoom->setOrigin(x - 100 + 33, y - 250);
|
|
|
|
|
_canvasZoom->resize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ZoomManager::SendZoom()
|
|
|
|
|
{
|
|
|
|
|
_zoomNum[0] = zoom;
|
2025-03-13 00:42:41 +00:00
|
|
|
|
slotZoom();
|
2025-01-12 17:35:51 +00:00
|
|
|
|
//emit signalZoom(QVariant(_zoomNum[0]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ZoomManager::AttachViewUI(OsgViewUI* ui) {
|
|
|
|
|
dyt_check(nullptr != ui);
|
|
|
|
|
|
|
|
|
|
ui->addChild(_canvasZoom);
|
|
|
|
|
}
|
2025-03-13 00:42:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ZoomManager::slotZoom() {
|
|
|
|
|
double val = _zoomNum[0];
|
|
|
|
|
double dx = val*(-1.0)*(0.0005);// dx不起作用
|
|
|
|
|
double dy = val*(-1.0)*(0.0005);
|
|
|
|
|
|
|
|
|
|
// dx *= getSettings()->getMouseSensitivity();
|
|
|
|
|
// dy *= getSettings()->getMouseSensitivity();
|
|
|
|
|
|
|
|
|
|
double minAlt = 500.0;
|
|
|
|
|
double maxAlt = 35000000.0;
|
|
|
|
|
auto em = oeScene_->GetManipulater();
|
|
|
|
|
auto vp = em->getViewpoint();
|
|
|
|
|
vp.setRange(vp.getRange() * 1.1);
|
|
|
|
|
em->setViewpoint(vp);
|
|
|
|
|
//
|
|
|
|
|
// double scale = 1.0f + dy;
|
|
|
|
|
// double distance = em->getDistance() * scale;
|
|
|
|
|
// distance = std::max(distance, maxAlt);
|
|
|
|
|
//
|
|
|
|
|
// // if (!OEScene::GetSrs()->isGeographic())
|
|
|
|
|
// // {
|
|
|
|
|
// // osg::Viewport* vp = oeScene_->GetViewport();
|
|
|
|
|
// // if (vp)
|
|
|
|
|
// // {
|
|
|
|
|
// // double ar = vp->width() / vp->height();
|
|
|
|
|
// // double y = distance * tan(0.5*osg::DegreesToRadians(em->));
|
|
|
|
|
// // double x = y * ar;
|
|
|
|
|
// //
|
|
|
|
|
// // osgEarth::GeoExtent extentMap = oeScene_->getMap()->getProfile()->getExtent();
|
|
|
|
|
// //
|
|
|
|
|
// // if ((_center.y() - y) < extentMap.yMin())
|
|
|
|
|
// // {
|
|
|
|
|
// // return;
|
|
|
|
|
// // }
|
|
|
|
|
// // if ((_center.y() + y) > extentMap.yMax())
|
|
|
|
|
// // {
|
|
|
|
|
// // return;
|
|
|
|
|
// // }
|
|
|
|
|
// // }
|
|
|
|
|
// // }
|
|
|
|
|
//
|
|
|
|
|
// em->setDistance(distance);
|
|
|
|
|
}
|
|
|
|
|
|