File: clippingDialog.C

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 239,848 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; makefile: 93
file content (119 lines) | stat: -rw-r--r-- 3,159 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
// $Id:

#include <BALL/VIEW/DIALOGS/clippingDialog.h>
#include <BALL/VIEW/KERNEL/mainControl.h>
#include <BALL/VIEW/KERNEL/message.h>
#include <BALL/VIEW/KERNEL/common.h>

namespace BALL
{
	namespace VIEW
	{

ClippingDialog::ClippingDialog(QWidget* parent, const char* name)
	:	QDialog(parent),
		Ui_ClippingDialogData()
{
#ifdef BALL_VIEW_DEBUG
	Log.error() << "new ClippingDialog " << this << std::endl;
#endif

	setupUi(this);
	
  // signals and slots connections
  connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
  connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );

	setObjectName(name);
}

ClippingDialog::~ClippingDialog()
{
#ifdef BALL_VIEW_DEBUG
	Log.error() << "deleting ClippingDialog " << this << std::endl;
#endif
}

int ClippingDialog::exec()
{
	if (clipping_plane_ == 0) return QDialog::Rejected;

	MainControl* mc = getMainControl();
	if (mc == 0) return QDialog::Rejected;

	RepresentationManager& pm = mc->getRepresentationManager();

 	listview->setColumnCount(3);
	listview->setRowCount(pm.getRepresentations().size());
	listview->setHorizontalHeaderItem(0, new QTableWidgetItem());
	listview->setHorizontalHeaderItem(1, new QTableWidgetItem());
	listview->setHorizontalHeaderItem(2, new QTableWidgetItem());
 	listview->horizontalHeaderItem(0)->setText("Model");
 	listview->horizontalHeaderItem(1)->setText("Coloring");
 	listview->horizontalHeaderItem(2)->setText("Properties");
	listview->setColumnWidth(0, 140);
	listview->setColumnWidth(1, 140);
	listview->setColumnWidth(2, 140);

	const ModelInformation& mi = mc->getModelInformation();

	Position row= 0;
	RepresentationList::const_iterator it = pm.getRepresentations().begin();
	for (; it != pm.getRepresentations().end(); it++)
	{
		const Representation& rep = **it;

		QTableWidgetItem* item = new QTableWidgetItem(rep.getName().c_str());
		item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
		item->setCheckState(Qt::Checked);

		if (!clipping_plane_->getRepresentations().has(*it)) item->setCheckState(Qt::Unchecked);
		listview->setItem(row, 0, item);

		item = new QTableWidgetItem(mi.getColoringName(rep.getColoringMethod()).c_str());
		listview->setItem(row, 1, item);

		item = new QTableWidgetItem(rep.getProperties().c_str());
		listview->setItem(row, 2, item);
		row++;
	}

	raise();
	return QDialog::exec();
}


void ClippingDialog::accept()
{
	hide();

	if (clipping_plane_ == 0 || getMainControl() == 0) 
	{
		BALLVIEW_DEBUG
		return;
	}

	clipping_plane_->getRepresentations().clear();

	std::list<Representation*> lreps = getMainControl()->getRepresentationManager().getRepresentations();
	vector<const Representation*> reps;
	reps.resize(lreps.size());
	copy(lreps.begin(), lreps.end(), reps.begin());

	for (Position pos = 0; pos < (Position)listview->rowCount(); pos++)
	{
		const QTableWidgetItem& item = *listview->item(pos, 0);
		if (item.checkState() == Qt::Checked)
		{
			clipping_plane_->getRepresentations().insert(reps[pos]);
		}
	}

	getMainControl()->redrawAllRepresentations();
}


} } // namespaces