Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mouse selection #62

Merged
merged 3 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 5 additions & 33 deletions src/OgreWidget.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
/*/////////////////////////////////////////////////////////////////////////////////
/// A QtMeshEditor file
///
/// Copyright (c) HogPog Team (www.hogpog.com.br)
///
/// The MIT License
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
////////////////////////////////////////////////////////////////////////////////*/

#include <QDebug>
#include <QTimer>
#include <QCoreApplication>
Expand All @@ -40,8 +14,7 @@
#include "QtInputManager.h"

OgreWidget::OgreWidget( QWidget *parent ):
QWidget( parent ), mOgreRoot(0), mOgreWindow(NULL),
mCamera(0)
QWidget( parent )
{
setAttribute( Qt::WA_PaintOnScreen );
setAttribute( Qt::WA_OpaquePaintEvent );
Expand All @@ -58,19 +31,19 @@ OgreWidget::~OgreWidget()
if(mOgreWindow)
{
mOgreWindow->removeAllViewports();
mViewport = 0;
mViewport = nullptr;
}
if(mCamera)
{
delete mCamera;
mCamera = 0;
mCamera = nullptr;
}
if(mOgreRoot)
{
mOgreRoot->removeFrameListener(this);
mOgreRoot->detachRenderTarget(mOgreWindow);
mOgreWindow->setActive(false);
mOgreWindow = 0;
mOgreWindow = nullptr;
}

destroy();
Expand Down Expand Up @@ -192,10 +165,9 @@ void OgreWidget::resizeEvent(QResizeEvent *e)
mOgreWindow->windowMovedOrResized();
}
if(mCamera)
mCamera->setAspectRatio(((Ogre::Real)width()/ (Ogre::Real)height()) > 1 ? (Ogre::Real)width()/ (Ogre::Real)height() : 1);
mCamera->setAspectRatio((Ogre::Real)width()/(Ogre::Real)height());
update();
}

}

void OgreWidget::moveEvent(QMoveEvent *e)
Expand Down
10 changes: 5 additions & 5 deletions src/OgreWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ class OgreWidget : public QWidget, public Ogre::FrameListener
void focusOnWidget(OgreWidget* ogreWidget);

private:
Ogre::Root* mOgreRoot;
Ogre::RenderWindow* mOgreWindow;
Ogre::Viewport* mViewport;
Ogre::SceneManager* mSceneMgr;
SpaceCamera* mCamera;
Ogre::Root* mOgreRoot = nullptr;
Ogre::RenderWindow* mOgreWindow = nullptr;
Ogre::Viewport* mViewport = nullptr;
Ogre::SceneManager* mSceneMgr = nullptr;
SpaceCamera* mCamera = nullptr;
};

#endif //__OGREWIDGET_H__
50 changes: 12 additions & 38 deletions src/TransformOperator.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
/*/////////////////////////////////////////////////////////////////////////////////
/// A QtMeshEditor file
///
/// Copyright (c) HogPog Team (www.hogpog.com.br)
///
/// The MIT License
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
////////////////////////////////////////////////////////////////////////////////*/

#include <QtDebug>

#include "GlobalDefinitions.h"
Expand Down Expand Up @@ -119,37 +93,38 @@ TransformOperator::~TransformOperator()
if(m_pRayQuery)
{
pSceneMgr->destroyQuery(m_pRayQuery);
m_pRayQuery = 0;
m_pRayQuery = nullptr;
}
if(m_pVolQuery)
{
pSceneMgr->destroyQuery(m_pVolQuery);
m_pVolQuery =0;
m_pVolQuery = nullptr;
}

if(m_pRotationGizmo)
{
delete m_pRotationGizmo;
m_pRotationGizmo = 0;
m_pRotationGizmo = nullptr;
}

if(m_pTranslationGizmo)
{
delete m_pTranslationGizmo;
m_pTranslationGizmo = 0;
m_pTranslationGizmo = nullptr;
}
if(m_pSelectionBox)
{
delete m_pSelectionBox;
m_pSelectionBox = 0;
m_pSelectionBox = nullptr;
}

pSceneMgr->destroySceneNode(m_pTransformNode); //TODO destroy SelectionBoxNode
pSceneMgr->destroySceneNode(m_pTransformNode);
pSceneMgr->destroySceneNode(m_pSelectionBoxNode);
}

void TransformOperator::swap(int& x, int& y)
{
float temp = x;
int temp = x;
x = y; y = temp;
}
const Ogre::ColourValue& TransformOperator::getSelectionBoxColour() const
Expand Down Expand Up @@ -325,8 +300,8 @@ Ogre::Ray TransformOperator::rayFromScreenPoint(const QPoint& pos)
{
if(m_pActiveWidget)
{
int width = m_pActiveWidget->getViewport()->getActualWidth();
int height = m_pActiveWidget->getViewport()->getActualHeight();
int width = m_pActiveWidget->getViewport()->getActualWidth() / 2;
int height = m_pActiveWidget->getViewport()->getActualHeight() / 2;

Ogre::Real x = (Ogre::Real)(pos.x()) / (Ogre::Real)width;
Ogre::Real y = (Ogre::Real)(pos.y()) / (Ogre::Real)height;
Expand Down Expand Up @@ -453,8 +428,8 @@ void TransformOperator::mouseMoveEvent(QMouseEvent *e)
{
if(m_pSelectionBox->isVisible() && m_pActiveWidget)
{
int width = m_pActiveWidget->getViewport()->getActualWidth();
int height = m_pActiveWidget->getViewport()->getActualHeight();
int width = m_pActiveWidget->getViewport()->getActualWidth() / 2;
int height = m_pActiveWidget->getViewport()->getActualHeight() / 2;

float xStart = (float)(mScreenStart.x())/(float)width*2.0f-1.0f;
float xStop = (float)(e->pos().x())/(float)width*2.0f-1.0f;
Expand All @@ -463,7 +438,6 @@ void TransformOperator::mouseMoveEvent(QMouseEvent *e)

m_pSelectionBox->drawBox(xStart, yStart, xStop, yStop);
}

}
else if(mTransformState == TS_TRANSLATE && (!SelectionSet::getSingleton()->isEmpty()))
{
Expand Down
28 changes: 0 additions & 28 deletions src/TransformOperator.h
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
/*/////////////////////////////////////////////////////////////////////////////////
/// A QtMeshEditor file
///
/// Copyright (c) HogPog Team (www.hogpog.com.br)
///
/// The MIT License
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
////////////////////////////////////////////////////////////////////////////////*/

#ifndef TRANSFORM_OPERATOR_H
#define TRANSFORM_OPERATOR_H

Expand Down Expand Up @@ -54,8 +28,6 @@ class TransformOperator : public QObject, public QtMouseListener
static TransformOperator* getSingleton();
static void kill();



enum TransformState
{
TS_NONE,
Expand Down
32 changes: 32 additions & 0 deletions src/TransformOperator_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <Ogre.h>
#include "TransformOperator.h"

// Test if getSingleton returns a valid pointer
TEST(TransformOperatorTest, GetSingleton) {
TransformOperator* instance = TransformOperator::getSingleton();
EXPECT_NE(instance, nullptr);
}

// Test if getSingleton always returns the same instance
TEST(TransformOperatorTest, SingletonInstance) {
TransformOperator* instance1 = TransformOperator::getSingleton();
TransformOperator* instance2 = TransformOperator::getSingleton();
EXPECT_EQ(instance1, instance2);
}

// Test if kill deletes the instance
TEST(TransformOperatorTest, Kill) {
TransformOperator* instance = TransformOperator::getSingleton();
TransformOperator::kill();
TransformOperator* instance2 = TransformOperator::getSingleton();
EXPECT_NE(instance, instance2);
}

// Test if setTransformState sets the state correctly
TEST(TransformOperatorTest, SetSelectionBoxColour) {
TransformOperator* instance = TransformOperator::getSingleton();
instance->setSelectionBoxColour(Ogre::ColourValue(0.5, 0.5, 0.5, 1.0));
EXPECT_EQ(instance->getSelectionBoxColour(), Ogre::ColourValue(0.5, 0.5, 0.5, 1.0));
}
Loading