controlDock_cameraTab.cpp 4.39 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include "controlDock_cameraTab.h"

#include <QMessageBox>

#include "schnapps.h"
#include "camera.h"
#include "view.h"

namespace CGoGN
{

namespace SCHNApps
{

ControlDock_CameraTab::ControlDock_CameraTab(SCHNApps* s) :
	m_schnapps(s),
17
	m_selectedCamera(NULL),
Pierre Kraemer's avatar
Pierre Kraemer committed
18 19 20 21 22
	b_updatingUI(false)
{
	setupUi(this);

	connect(button_addCamera, SIGNAL(clicked()), this, SLOT(addCameraButtonClicked()));
23
	connect(list_cameras, SIGNAL(itemSelectionChanged()), this, SLOT(selectedCameraChanged()));
Pierre Kraemer's avatar
Pierre Kraemer committed
24 25 26 27 28 29 30 31 32 33
	connect(group_projectionType, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(cameraProjectionChanged(QAbstractButton*)));
	connect(check_drawCamera, SIGNAL(clicked(bool)), this, SLOT(cameraDrawClicked(bool)));
	connect(check_drawCameraPath, SIGNAL(clicked(bool)), this, SLOT(cameraDrawPathClicked(bool)));

	connect(m_schnapps, SIGNAL(cameraAdded(Camera*)), this, SLOT(cameraAdded(Camera*)));
	connect(m_schnapps, SIGNAL(cameraRemoved(Camera*)), this, SLOT(cameraRemoved(Camera*)));
}

void ControlDock_CameraTab::addCameraButtonClicked()
{
34 35
	if (!b_updatingUI)
		m_schnapps->addCamera();
Pierre Kraemer's avatar
Pierre Kraemer committed
36 37
}

38
void ControlDock_CameraTab::selectedCameraChanged()
Pierre Kraemer's avatar
Pierre Kraemer committed
39
{
40
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
41
	{
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
		Camera* old = m_selectedCamera;

		if (old)
		{
			disconnect(m_selectedCamera, SIGNAL(projectionTypeChanged(int)), this, SLOT(selectedCameraProjectionTypeChanged(int)));
			disconnect(m_selectedCamera, SIGNAL(drawChanged(bool)), this, SLOT(selectedCameraDrawChanged(bool)));
			disconnect(m_selectedCamera, SIGNAL(drawPathChanged(bool)), this, SLOT(selectedCameraDrawPathChanged(bool)));
		}

		QList<QListWidgetItem*> items = list_cameras->selectedItems();
		if(!items.empty())
		{
			QString selectedCameraName = items[0]->text();
			m_selectedCamera = m_schnapps->getCamera(selectedCameraName);

			connect(m_selectedCamera, SIGNAL(projectionTypeChanged(int)), this, SLOT(selectedCameraProjectionTypeChanged(int)));
			connect(m_selectedCamera, SIGNAL(drawChanged(bool)), this, SLOT(selectedCameraDrawChanged(bool)));
			connect(m_selectedCamera, SIGNAL(drawPathChanged(bool)), this, SLOT(selectedCameraDrawPathChanged(bool)));
		}
		else
			m_selectedCamera = NULL;

		updateSelectedCameraInfo();
Pierre Kraemer's avatar
Pierre Kraemer committed
65 66 67 68 69
	}
}

void ControlDock_CameraTab::cameraProjectionChanged(QAbstractButton* b)
{
Sylvain Thery's avatar
Sylvain Thery committed
70
	if (!b_updatingUI && m_selectedCamera)
Pierre Kraemer's avatar
Pierre Kraemer committed
71 72
	{
		if(radio_orthographicProjection->isChecked())
73
			m_selectedCamera->setProjectionType(qglviewer::Camera::ORTHOGRAPHIC);
Pierre Kraemer's avatar
Pierre Kraemer committed
74
		else if(radio_perspectiveProjection->isChecked())
75
			m_selectedCamera->setProjectionType(qglviewer::Camera::PERSPECTIVE);
Pierre Kraemer's avatar
Pierre Kraemer committed
76 77 78 79 80
	}
}

void ControlDock_CameraTab::cameraDrawClicked(bool b)
{
81
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
82
	{
83
		m_selectedCamera->setDraw(b);
Pierre Kraemer's avatar
Pierre Kraemer committed
84 85 86 87 88
	}
}

void ControlDock_CameraTab::cameraDrawPathClicked(bool b)
{
89
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
90
	{
91
		m_selectedCamera->setDrawPath(b);
Pierre Kraemer's avatar
Pierre Kraemer committed
92 93 94 95 96
	}
}



97 98


Pierre Kraemer's avatar
Pierre Kraemer committed
99 100 101
void ControlDock_CameraTab::cameraAdded(Camera* c)
{
	b_updatingUI = true;
102
	list_cameras->addItem(c->getName());
Pierre Kraemer's avatar
Pierre Kraemer committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116
	b_updatingUI = false;
}

void ControlDock_CameraTab::cameraRemoved(Camera* c)
{
	QList<QListWidgetItem*> items = list_cameras->findItems(c->getName(), Qt::MatchExactly);
	if(!items.empty())
	{
		b_updatingUI = true;
		delete items[0];
		b_updatingUI = false;
	}
}

117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142




void ControlDock_CameraTab::selectedCameraProjectionTypeChanged(int t)
{
	b_updatingUI = true;
	switch(t)
	{
		case qglviewer::Camera::ORTHOGRAPHIC : radio_orthographicProjection->setChecked(true); break;
		case qglviewer::Camera::PERSPECTIVE : radio_perspectiveProjection->setChecked(true); break;
	}
	b_updatingUI = false;
}

void ControlDock_CameraTab::selectedCameraDrawChanged(bool b)
{
	b_updatingUI = true;
	if(b)
		check_drawCamera->setCheckState(Qt::Checked);
	else
		check_drawCamera->setCheckState(Qt::Unchecked);
	b_updatingUI = false;
}

void ControlDock_CameraTab::selectedCameraDrawPathChanged(bool b)
Pierre Kraemer's avatar
Pierre Kraemer committed
143
{
144 145 146 147 148 149
	b_updatingUI = true;
	if(b)
		check_drawCameraPath->setCheckState(Qt::Checked);
	else
		check_drawCameraPath->setCheckState(Qt::Unchecked);
	b_updatingUI = false;
Pierre Kraemer's avatar
Pierre Kraemer committed
150 151 152 153
}



154 155 156


void ControlDock_CameraTab::updateSelectedCameraInfo()
Pierre Kraemer's avatar
Pierre Kraemer committed
157 158 159
{
	b_updatingUI = true;

160
	if(m_selectedCamera->getProjectionType() == qglviewer::Camera::PERSPECTIVE)
Pierre Kraemer's avatar
Pierre Kraemer committed
161
		radio_perspectiveProjection->setChecked(true);
162
	else if(m_selectedCamera->getProjectionType() == qglviewer::Camera::ORTHOGRAPHIC)
Pierre Kraemer's avatar
Pierre Kraemer committed
163 164
		radio_orthographicProjection->setChecked(true);

165
	check_drawCamera->setChecked(m_selectedCamera->getDraw());
Pierre Kraemer's avatar
Pierre Kraemer committed
166

167
	check_drawCameraPath->setChecked(m_selectedCamera->getDrawPath());
Pierre Kraemer's avatar
Pierre Kraemer committed
168 169 170 171 172 173 174

	b_updatingUI = false;
}

} // namespace SCHNApps

} // namespace CGoGN