File: exportGeometryDialog.C

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 239,888 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; makefile: 95
file content (306 lines) | stat: -rw-r--r-- 8,233 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//

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

#include <BALL/VIEW/PRIMITIVES/box.h>
#include <BALL/VIEW/PRIMITIVES/disc.h>
#include <BALL/VIEW/PRIMITIVES/gridVisualisation.h>
#include <BALL/VIEW/PRIMITIVES/label.h>
#include <BALL/VIEW/PRIMITIVES/mesh.h>
#include <BALL/VIEW/PRIMITIVES/simpleBox.h>

#include <QtWidgets/QFileDialog>
#include <QtWidgets/QMessageBox>
#include <QtWidgets/QLineEdit>


namespace BALL
{
	namespace VIEW
	{

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

	setupUi(this);

  // signals and slots connections
	QObject::connect( browse_button, SIGNAL( clicked() ), this, SLOT( browseFiles() ) );
  QObject::connect( prototyping_radio, SIGNAL( clicked() ), this, SLOT( protomode() ) );
  QObject::connect( view_radio, SIGNAL( clicked() ), this, SLOT( viewmode() ) );

	setObjectName(name);
}

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



int ExportGeometryDialog::exec()
{
	MainControl* mc = getMainControl();
	if (mc == 0) return QDialog::Rejected;

	RepresentationManager& rm = mc->getRepresentationManager();

	//creation of the listpart of the GUI
	listview->setColumnCount(3);
	listview->setRowCount(rm.getRepresentations().size());
	listview->setHorizontalHeaderItem(0, new QTableWidgetItem());
	listview->setHorizontalHeaderItem(1, new QTableWidgetItem());
	listview->setHorizontalHeaderItem(2, new QTableWidgetItem());
	listview->horizontalHeaderItem(0)->setText(tr("Model"));
	listview->horizontalHeaderItem(1)->setText(tr("Coloring"));
	listview->horizontalHeaderItem(2)->setText(tr("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 = rm.getRepresentations().begin();

	//filling of the list: as "for viewing" is the standard configuration all reps are checkable 
	for (; it != rm.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);

		//the same represantations are checked as in BALLView
		if ( (*it)->isHidden() )
		{
			item->setCheckState(Qt::Unchecked);
		}
		else
		{
			item->setCheckState(Qt::Checked);
		}

		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++;
	}
	split_ = false;
	raise();
	return QDialog::exec();
}


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

	//before we do anything at all we have to store the information which representations are now visible
	//as the export works by switching them on and off => saving base stats
	MainControl* mc = getMainControl();
	RepresentationManager& rm = mc->getRepresentationManager();
	RepresentationList::const_iterator rit;

	Position count = 0;

	rit = rm.getRepresentations().begin();
	for (; rit != rm.getRepresentations().end(); rit++)
	{
		if(!((*rit)->isHidden()))
		{
			basestats[count]=true;
			(*rit)->setHidden(true);
		}
		else
		{
			basestats[count]=false;
		}
		count ++;
	}

//we have to get to know which representations the user wants to export:
	for (Position pos = 0; pos < (Position)listview->rowCount(); pos++)
	{
		const QTableWidgetItem& item = *listview->item(pos, 0);
		if (item.checkState() == Qt::Checked)
		{
			reps[pos] = true;
		}
		else
		{
			reps[pos] = false;
		}
	}

	//now we look whether we have to split them into several files:
	if ((prototyping_radio->isChecked()) || (split_radio->isChecked()))
	{
		split_ = true;
	}
	else
	{
		split_ = false;
	}

	setFilename(file_edit->displayText());
}


	void ExportGeometryDialog::browseFiles()
	{
		QString fname = QFileDialog::getSaveFileName(0, tr("Export as 3D file"), getMainControl()->getWorkingDir().c_str(), "*.*");
		if (fname == QString::null)
		{
			return;
		}
		setFilename(fname);
		file_edit->setText(fname);
	}

	bool ExportGeometryDialog::split()
	{
		return split_;
	}

	void ExportGeometryDialog::protomode()
	{
		MainControl* mc = getMainControl();
		if (mc == 0) return;

		RepresentationManager& rm = mc->getRepresentationManager();

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

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

			list<GeometricObject*>::const_iterator git = (*it)->getGeometricObjects().begin();
			for (; git != (*it)->getGeometricObjects().end(); git++)
			{
				//now we test if the geo object is printable
				//all geometric objects that are just helpers as the grid but are not exported are counted as printable
				// mesh (5) is the only real printable representation
				//
				// TODO: what about spheres, e.g.??
                if (! (	 RTTI::isKindOf<Box> (*git)
                             ||RTTI::isKindOf<Disc>(*git)
                             ||RTTI::isKindOf<GridVisualisation>(*git)
                             ||RTTI::isKindOf<Label>(*git)
                             ||RTTI::isKindOf<Mesh>(*git)
                             ||RTTI::isKindOf<SimpleBox>(*git)
							)
					 )
				{
					printable=false;
					break;
				}

			}

			if (printable)
			//item is the same as normal
			{

				QTableWidgetItem* item = new QTableWidgetItem(rep.getName().c_str());
				item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
				if ( (*it)->isHidden() )
				{
					item->setCheckState(Qt::Unchecked);
				}
				else
				{
					item->setCheckState(Qt::Checked);
				}

				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++;
			}
			else
			{
				QTableWidgetItem* item = new QTableWidgetItem(rep.getName().c_str());
				item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsEnabled );
				item->setCheckState(Qt::Unchecked);

				listview->setItem(row, 0, item);

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

				item = new QTableWidgetItem(rep.getProperties().c_str());
				item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsEnabled );
				listview->setItem(row, 2, item);
				row++;
			}
		}
		raise();
	}

	void ExportGeometryDialog::viewmode()
	{
		MainControl* mc = getMainControl();
		if (mc == 0) return;

		RepresentationManager& rm = mc->getRepresentationManager();

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

		Position row= 0;
		RepresentationList::const_iterator it = rm.getRepresentations().begin();
		for (; it != rm.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);
			if ( (*it)->isHidden() )
			{
				item->setCheckState(Qt::Unchecked);
			}
			else
			{
				item->setCheckState(Qt::Checked);
			}

			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();

	}
} } // namespaces