History

Code cleanup

atlante45 committed 13 years ago

Commit 867303e1 parent 27b03385 files · +15 −175Browse files

Showing the changes to interface/src/Application.cpp (1 of 5 files). Show all

Unified · Split

interface/src/Application.cpp+11−167
@@ -1194,183 +1194,27 @@ void Application::exportVoxels() { · 1193 unmodified lines
11941194 _window->activateWindow();
11951195 }
11961196
1197−const char* IMPORT_FILE_TYPES = "Sparse Voxel Octree Files, Square PNG, Schematic Files (*.svo *.png *.schematic)";
1198−void Application::importVoxelsToClipboard() {
1199− QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
1200− QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Import Voxels to Clipboard"), desktopLocation,
1201− tr(IMPORT_FILE_TYPES));
1202−
1203− QByteArray fileNameAscii = fileNameString.toLocal8Bit();
1204− const char* fileName = fileNameAscii.data();
1205−
1206− _clipboard.killLocalVoxels();
1207− if (fileNameString.endsWith(".png", Qt::CaseInsensitive)) {
1208− _clipboard.readFromSquareARGB32Pixels(fileName);
1209− } else if (fileNameString.endsWith(".svo", Qt::CaseInsensitive)) {
1210− _clipboard.readFromSVOFile(fileName);
1211− } else if (fileNameString.endsWith(".schematic", Qt::CaseInsensitive)) {
1212− _clipboard.readFromSchematicFile(fileName);
1213− }
1214−
1215− // restore the main window's active state
1216− _window->activateWindow();
1217−}
1218−
12191197 void Application::importVoxels() {
12201198 _pasteMode = false;
12211199
12221200 if (_voxelImporter.exec()) {
12231201 qDebug("[DEBUG] Import succedded.\n");
1224− _pasteMode = true;
1225− } else {
1226− qDebug("[DEBUG] Import failed.\n");
1227− }
1228−
1229− return;
1230−
1231− QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
1232−
1233− QStringList fileNameStringList = QFileDialog::getOpenFileNames(_glWidget, tr("Import Voxels"), desktopLocation,
1234− tr(IMPORT_FILE_TYPES));
1235−
1236−
1237− // remember the "selected" voxel point before we do any importing...
1238− float originalX = _mouseVoxel.x;
1239− float originalZ = _mouseVoxel.z;
1240−
1241− const int PNG_TYPE_NAME_LENGTH = 4;
1242− const int SVO_TYPE_NAME_LENGTH = 4;
1243− const int SCH_TYPE_NAME_LENGTH = 10;
1244−
1245− // assume this is where we'll place it if filename doesn't have tiling
1246− int unspecifiedColumnNum = 1;
1247− int unspecifiedRowNum = 1;
1248−
1249− // if they select multiple files, but they don't specify the tiling, we
1250− // will tile them to this size
1251− int unspecifiedSquare = (sqrt(fileNameStringList.size()) + 0.5);
1252− qDebug("unspecifiedSquare: %d\n", unspecifiedSquare);
1253−
1254− for (int i = 0; i < fileNameStringList.size(); i++) {
1255− QString fileNameString = fileNameStringList.at(i);
1256− QString extension;
1257− QByteArray fileNameAscii = fileNameString.toLocal8Bit();
1258− const char* fileName = fileNameAscii.data();
1259−
1260− int fileTypeNameLength = 0;
1261− VoxelTree importVoxels;
1262− if (fileNameString.endsWith(".png", Qt::CaseInsensitive)) {
1263− extension = QString(".png");
1264− QImage pngImage = QImage(fileName);
1265− fileTypeNameLength = PNG_TYPE_NAME_LENGTH;
1266− if (pngImage.height() != pngImage.width()) {
1267− qDebug("ERROR: Bad PNG size: height != width.\n");
1268− return;
1269− }
1270−
1271− const uint32_t* pixels;
1272− if (pngImage.format() == QImage::Format_ARGB32) {
1273− pixels = reinterpret_cast<const uint32_t*>(pngImage.constBits());
1274− } else {
1275− QImage tmp = pngImage.convertToFormat(QImage::Format_ARGB32);
1276− pixels = reinterpret_cast<const uint32_t*>(tmp.constBits());
1277− }
1278−
1279− importVoxels.readFromSquareARGB32Pixels(fileName);
1280− } else if (fileNameString.endsWith(".svo", Qt::CaseInsensitive)) {
1281− extension = QString(".svo");
1282− importVoxels.readFromSVOFile(fileName);
1283− fileTypeNameLength = SVO_TYPE_NAME_LENGTH;
1284− } else if (fileNameString.endsWith(".schematic", Qt::CaseInsensitive)) {
1285− extension = QString(".schematic");
1286− importVoxels.readFromSchematicFile(fileName);
1287− fileTypeNameLength = SCH_TYPE_NAME_LENGTH;
1288− }
1289−
1290− // Where we plan to place this
1291− int columnNum = 1;
1292− int rowNum = 1;
1293− bool isTileLocationUnspecified = false;
1294−
1295− // If we're in multi-file mode, then look for tiling specification in the file name
1296− if (fileNameStringList.size() > 1) {
1297− int indexOfFirstPeriod = fileNameString.indexOf('.');
1298−
1299− //qDebug("indexOfFirstPeriod: %d\n", indexOfFirstPeriod);
13001202
1301− // If the first period, is the extension, then this is not a grid name;
1302− if (fileNameString.mid(indexOfFirstPeriod, fileNameString.length() - indexOfFirstPeriod) == extension) {
1303− qDebug("not a valid grid name... treat like tile Location Unspecified\n");
1304− isTileLocationUnspecified = true;
1305− } else {
1306− QString fileCoord = fileNameString.mid(indexOfFirstPeriod + 1,
1307− fileNameString.length() - indexOfFirstPeriod - fileTypeNameLength - 1);
1308−
1309− //qDebug() << "fileCoord: " << fileCoord << "\n";
1310− indexOfFirstPeriod = fileCoord.indexOf('.');
1311−
1312− //qDebug("indexOfFirstPeriod: %d\n", indexOfFirstPeriod);
1313−
1314− QString columnNumString = fileCoord.right(fileCoord.length() - indexOfFirstPeriod - 1);
1315− QString rowNumString = fileCoord.left(indexOfFirstPeriod);
1316−
1317− //qDebug() << "columnNumString: " << columnNumString << "\n";
1318− //qDebug() << "rowNumString: " << rowNumString << "\n";
1319−
1320− columnNum = columnNumString.toFloat();
1321− rowNum = rowNumString.toFloat();
1322−
1323− // If there are no "grid sections" in the filename, then we're going to get
1324− if (columnNum < 1 || rowNum < 1) {
1325− qDebug("not a valid grid name... treat like tile Location Unspecified\n");
1326− isTileLocationUnspecified = true;
1327− }
1328− }
1329− }
1330−
1331− if (isTileLocationUnspecified) {
1332− qDebug("tile Location is Unspecified... \n");
1333− columnNum = unspecifiedColumnNum;
1334− rowNum = unspecifiedRowNum;
1335−
1336− unspecifiedColumnNum++;
1337− if (unspecifiedColumnNum > unspecifiedSquare) {
1338− unspecifiedColumnNum = 1;
1339− unspecifiedRowNum++;
1340− }
1341− }
1342− qDebug("columnNum: %d\t rowNum: %d\n", columnNum, rowNum);
1343−
1344− _mouseVoxel.x = originalX + (columnNum - 1) * _mouseVoxel.s;
1345− _mouseVoxel.z = originalZ + (rowNum - 1) * _mouseVoxel.s;
1346−
1347− VoxelNode* selectedNode = _voxels.getVoxelAt(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
1348−
1349− // Recurse the Import Voxels tree, where everything is root relative, and send all the colored voxels to
1350− // the server as an set voxel message, this will also rebase the voxels to the new location
1351− unsigned char* calculatedOctCode = NULL;
1352− SendVoxelsOperationArgs args;
1353−
1354− // we only need the selected voxel to get the newBaseOctCode, which we can actually calculate from the
1355− // voxel size/position details.
1356− if (selectedNode) {
1357− args.newBaseOctCode = selectedNode->getOctalCode();
1203+ if (_voxelImporter.getimportIntoClipboard()) {
1204+ _clipboard.killLocalVoxels();
1205+ _voxelImporter.getVoxelSystem()->copySubTreeIntoNewTree(
1206+ _voxelImporter.getVoxelSystem()->getVoxelAt(0, 0, 0, 1),
1207+ &_clipboard,
1208+ true);
13581209 } else {
1359− args.newBaseOctCode = calculatedOctCode = pointToVoxel(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s);
1360− }
1361−
1362− qDebug("column:%d, row:%d, voxel:%f,%f,%f,%f\n", columnNum, rowNum, _mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s );
1363−
1364− // send the insert/paste of these voxels
1365− importVoxels.recurseTreeWithOperation(sendVoxelsOperation, &args);
1366− _voxelEditSender.flushQueue();
1367−
1368− if (calculatedOctCode) {
1369− delete[] calculatedOctCode;
1210+ _pasteMode = true;
13701211 }
13711212
1213+
1214+ } else {
1215+ qDebug("[DEBUG] Import failed.\n");
13721216 }
1373−
1217+
13741218 // restore the main window's active state
13751219 _window->activateWindow();
13761220 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t