{"action":"created","comment":{"url":"https://api.github.com/repos/openscad/openscad/pulls/comments/244537919","pull_request_review_id":188443167,"id":244537919,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI0NDUzNzkxOQ==","diff_hunk":"@@ -2013,6 +2017,166 @@ void MainWindow::csgRender()\n \tcompileEnded();\n }\n \n+\n+void MainWindow::action3DPrint()\n+{\n+\t//Keeps track of how many times we've exported and tries to create slightly unique filenames.\n+\t//Not mission critical, since non-unique file names are fine for the API, just harder to \n+\t//differentiate between in customer support later.\n+\tstatic unsigned int printCounter=0;\n+\t\n+\tsetCurrentOutput();\n+\tPRINT(\"3D Printing...\");\n+\t\n+\tunsigned int dim = 3;\n+\t\n+\tQUrl partUrl;\n+\t\n+\t//Where we hold our temporary stl file name:\n+\tchar tempStlFileName[L_tmpnam];\n+\t\n+\tsetCurrentOutput();\n+\n+\t//Make sure we can export:\n+\tif (! canExport(dim))\n+\t{\n+\t\tPRINT(\"Cannot 3D Print due to errors.\");\n+\t\treturn;\n+    }\n+\t\n+\t//Create a temporary file name valid on all systems:\n+\tQTemporaryFile exportFile;\n+\t//Open the file so we can get the name:\n+\tif ( ! exportFile.open())\n+\t{\n+\t\tPRINT(\"Could not open temporary file.\");\n+\t\treturn;\n+\t}\n+\tQString exportFilename=exportFile.fileName();\n+\t\n+\t//Render the stl to a temporary file:\n+\texportFileByName(this->root_geom, FileFormat::STL,\n+\t\texportFilename.toLocal8Bit().constData(),\n+\t\texportFilename.toUtf8());\n+\t\n+\t//Create a name that the order process will use to refer to the file. Base it off of the\n+\t//project name\n+\tQString userFacingName=\"unsaved.stl\";\n+\tif (!this->fileName.isEmpty()) {\n+\t\tQString fileBasename = QFileInfo(this->fileName).baseName();\n+\t\tuserFacingName = fileBasename.append(\"_\").append(QString::number(printCounter++)).append(\".stl\");\n+\t}\n+\t\n+\t//Upload the file to the 3D Printing server and get the corresponding url to see it.\n+\t//The result is put in partUrl.\n+\tbool uploadWorked=uploadStlAndGetPartUrl(exportFilename, userFacingName, partUrl);\n+\tsetCurrentOutput();\n+\n+\t//Check the result:\n+\tif (! uploadWorked)\n+\t{\n+\t\tPRINT(\"An error occured while contacting the 3D Print API.\");\n+\t\treturn;\n+\t}\n+\t\n+\t//PRINT(\"partUrl:\");\n+\t//PRINT(partUrl);\n+\t\n+\t//Open the url in the default browser:\n+\tQDesktopServices::openUrl ( partUrl );\n+}\n+\n+//This function uploads an stl to the 3D printing API endpoint and returns a url that, \n+//when accessed, will show the stl file as a part that can be configured and added to the \n+//shopping cart.  Returns True if successful.\n+//\n+//Inputs:\n+//    exportFilename  - The path to the temporary file that has the stl export in it.\n+//    userFacingName  - Then name we should give the file when it is uploaded for the order process.\n+//Outputs:\n+//    partUrl         - The resulting url to go to next to continue the order process.\n+bool MainWindow::uploadStlAndGetPartUrl(const QString & exportFilename, const QString &userFacingName, QUrl &partUrl)\n+{\n+\tsetCurrentOutput();\n+\t\n+\t//Create a request:\n+\tQNetworkRequest request(QUrl(\"https://print.openscad.org/api/v1/part-upload/\"));\n+\t\n+\t//Set the content header:\n+\trequest.setHeader(QNetworkRequest::ContentTypeHeader, \"application/json\");\n+\t\n+\t//Get the file name from the file path:\n+\tQString fileNameBase=QFileInfo(exportFilename).fileName();\n+\t\n+\t//Create the request:\n+\tQJsonObject jsonInput;\n+\t\n+\t//Start building the json request:\n+\tjsonInput.insert(\"fileName\", userFacingName);\n+\t\n+\t//Read our stl file:\n+\tQFile file(exportFilename);\n+\tif (!file.open(QIODevice::ReadOnly))\n+\t{\n+\t\tPRINT(\"Unable to open exported stl file.\");\n+\t\treturn false;\n+\t}\n+\t\n+\t//Convert it to base 64:\n+\tQString stlFileB64=file.readAll().toBase64();\n+\t\n+\t//Base 64-encoded file contents:\n+\tjsonInput.insert(\"file\", stlFileB64);\n+\t\n+\t////Pring the input json:\n+\t//PRINT(\"Sending this JSON:\");\n+\t//PRINT(QString(QJsonDocument(jsonInput).toJson()).toLocal8Bit().constData());\n+\t\n+\t//Create a network access manager:\n+\tQNetworkAccessManager nam;\n+\t\n+\t//Send the post:\n+\tQNetworkReply *reply = nam.post(request, QJsonDocument(jsonInput).toJson());\n+\n+\t//Wait for the reply:\n+\twhile(!reply->isFinished())\n+\t{\n+\t\tqApp->processEvents();\n+\t}\n+\t\n+\tQVariant statusCodeV = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);  \n+\t\n+\t//Clean up the reply object:\n+\treply->deleteLater();\n+\t\n+\tchar statusStr[250];\n+\t\n+\tif (statusCodeV.toInt()!=200)","path":"src/mainwin.cc","position":158,"original_position":163,"commit_id":"ac1819c49a91472b7e3920100ccfc1547b5f39b1","original_commit_id":"af1c98a2ad0c20e9f16f3393088f221a47313150","user":{"login":"printathing","id":2925813,"node_id":"MDQ6VXNlcjI5MjU4MTM=","avatar_url":"https://avatars0.githubusercontent.com/u/2925813?v=4","gravatar_id":"","url":"https://api.github.com/users/printathing","html_url":"https://github.com/printathing","followers_url":"https://api.github.com/users/printathing/followers","following_url":"https://api.github.com/users/printathing/following{/other_user}","gists_url":"https://api.github.com/users/printathing/gists{/gist_id}","starred_url":"https://api.github.com/users/printathing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/printathing/subscriptions","organizations_url":"https://api.github.com/users/printathing/orgs","repos_url":"https://api.github.com/users/printathing/repos","events_url":"https://api.github.com/users/printathing/events{/privacy}","received_events_url":"https://api.github.com/users/printathing/received_events","type":"User","site_admin":false},"body":"Ok, how about if I accept 200 or 201?  Seems like there are some other 20x codes I don't fully understand yet so I'm more comfortable with keeping it more localized.","created_at":"2018-12-30T15:31:54Z","updated_at":"2018-12-30T15:31:54Z","html_url":"https://github.com/openscad/openscad/pull/2642#discussion_r244537919","pull_request_url":"https://api.github.com/repos/openscad/openscad/pulls/2642","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/openscad/openscad/pulls/comments/244537919"},"html":{"href":"https://github.com/openscad/openscad/pull/2642#discussion_r244537919"},"pull_request":{"href":"https://api.github.com/repos/openscad/openscad/pulls/2642"}},"in_reply_to_id":243771467},"pull_request":{"url":"https://api.github.com/repos/openscad/openscad/pulls/2642","id":240650798,"node_id":"MDExOlB1bGxSZXF1ZXN0MjQwNjUwNzk4","html_url":"https://github.com/openscad/openscad/pull/2642","diff_url":"https://github.com/openscad/openscad/pull/2642.diff","patch_url":"https://github.com/openscad/openscad/pull/2642.patch","issue_url":"https://api.github.com/repos/openscad/openscad/issues/2642","number":2642,"state":"open","locked":false,"title":"3D Printing Integration","user":{"login":"printathing","id":2925813,"node_id":"MDQ6VXNlcjI5MjU4MTM=","avatar_url":"https://avatars0.githubusercontent.com/u/2925813?v=4","gravatar_id":"","url":"https://api.github.com/users/printathing","html_url":"https://github.com/printathing","followers_url":"https://api.github.com/users/printathing/followers","following_url":"https://api.github.com/users/printathing/following{/other_user}","gists_url":"https://api.github.com/users/printathing/gists{/gist_id}","starred_url":"https://api.github.com/users/printathing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/printathing/subscriptions","organizations_url":"https://api.github.com/users/printathing/orgs","repos_url":"https://api.github.com/users/printathing/repos","events_url":"https://api.github.com/users/printathing/events{/privacy}","received_events_url":"https://api.github.com/users/printathing/received_events","type":"User","site_admin":false},"body":"This pull requests adds 3d Printing capabilities to the OpenSCAD workflow.  I have tested it on an Ubuntu 18.04 machine with one set of compiler flags, successfully.  It should definitely be tested on other OS's and with different sets of compiler flags as well to get any bugs out.  \r\n\r\nTODO:\r\n* [x] Review\r\n* [ ] Handle Qt4 builds\r\n* [ ] Resolve handling of async response (busy loop vs. dialog vs. background)\r\n* [ ] Dialog for initial run (for enabling the feature)","created_at":"2018-12-22T19:44:14Z","updated_at":"2018-12-30T15:31:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6b1ad4e7957ec67216855dc4ed4e6106e0a0ee32","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/openscad/openscad/pulls/2642/commits","review_comments_url":"https://api.github.com/repos/openscad/openscad/pulls/2642/comments","review_comment_url":"https://api.github.com/repos/openscad/openscad/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openscad/openscad/issues/2642/comments","statuses_url":"https://api.github.com/repos/openscad/openscad/statuses/ac1819c49a91472b7e3920100ccfc1547b5f39b1","head":{"label":"printathing:master","ref":"master","sha":"ac1819c49a91472b7e3920100ccfc1547b5f39b1","user":{"login":"printathing","id":2925813,"node_id":"MDQ6VXNlcjI5MjU4MTM=","avatar_url":"https://avatars0.githubusercontent.com/u/2925813?v=4","gravatar_id":"","url":"https://api.github.com/users/printathing","html_url":"https://github.com/printathing","followers_url":"https://api.github.com/users/printathing/followers","following_url":"https://api.github.com/users/printathing/following{/other_user}","gists_url":"https://api.github.com/users/printathing/gists{/gist_id}","starred_url":"https://api.github.com/users/printathing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/printathing/subscriptions","organizations_url":"https://api.github.com/users/printathing/orgs","repos_url":"https://api.github.com/users/printathing/repos","events_url":"https://api.github.com/users/printathing/events{/privacy}","received_events_url":"https://api.github.com/users/printathing/received_events","type":"User","site_admin":false},"repo":{"id":161666955,"node_id":"MDEwOlJlcG9zaXRvcnkxNjE2NjY5NTU=","name":"openscad","full_name":"printathing/openscad","private":false,"owner":{"login":"printathing","id":2925813,"node_id":"MDQ6VXNlcjI5MjU4MTM=","avatar_url":"https://avatars0.githubusercontent.com/u/2925813?v=4","gravatar_id":"","url":"https://api.github.com/users/printathing","html_url":"https://github.com/printathing","followers_url":"https://api.github.com/users/printathing/followers","following_url":"https://api.github.com/users/printathing/following{/other_user}","gists_url":"https://api.github.com/users/printathing/gists{/gist_id}","starred_url":"https://api.github.com/users/printathing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/printathing/subscriptions","organizations_url":"https://api.github.com/users/printathing/orgs","repos_url":"https://api.github.com/users/printathing/repos","events_url":"https://api.github.com/users/printathing/events{/privacy}","received_events_url":"https://api.github.com/users/printathing/received_events","type":"User","site_admin":false},"html_url":"https://github.com/printathing/openscad","description":"OpenSCAD - The Programmers Solid 3D CAD Modeller  ","fork":true,"url":"https://api.github.com/repos/printathing/openscad","forks_url":"https://api.github.com/repos/printathing/openscad/forks","keys_url":"https://api.github.com/repos/printathing/openscad/keys{/key_id}","collaborators_url":"https://api.github.com/repos/printathing/openscad/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/printathing/openscad/teams","hooks_url":"https://api.github.com/repos/printathing/openscad/hooks","issue_events_url":"https://api.github.com/repos/printathing/openscad/issues/events{/number}","events_url":"https://api.github.com/repos/printathing/openscad/events","assignees_url":"https://api.github.com/repos/printathing/openscad/assignees{/user}","branches_url":"https://api.github.com/repos/printathing/openscad/branches{/branch}","tags_url":"https://api.github.com/repos/printathing/openscad/tags","blobs_url":"https://api.github.com/repos/printathing/openscad/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/printathing/openscad/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/printathing/openscad/git/refs{/sha}","trees_url":"https://api.github.com/repos/printathing/openscad/git/trees{/sha}","statuses_url":"https://api.github.com/repos/printathing/openscad/statuses/{sha}","languages_url":"https://api.github.com/repos/printathing/openscad/languages","stargazers_url":"https://api.github.com/repos/printathing/openscad/stargazers","contributors_url":"https://api.github.com/repos/printathing/openscad/contributors","subscribers_url":"https://api.github.com/repos/printathing/openscad/subscribers","subscription_url":"https://api.github.com/repos/printathing/openscad/subscription","commits_url":"https://api.github.com/repos/printathing/openscad/commits{/sha}","git_commits_url":"https://api.github.com/repos/printathing/openscad/git/commits{/sha}","comments_url":"https://api.github.com/repos/printathing/openscad/comments{/number}","issue_comment_url":"https://api.github.com/repos/printathing/openscad/issues/comments{/number}","contents_url":"https://api.github.com/repos/printathing/openscad/contents/{+path}","compare_url":"https://api.github.com/repos/printathing/openscad/compare/{base}...{head}","merges_url":"https://api.github.com/repos/printathing/openscad/merges","archive_url":"https://api.github.com/repos/printathing/openscad/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/printathing/openscad/downloads","issues_url":"https://api.github.com/repos/printathing/openscad/issues{/number}","pulls_url":"https://api.github.com/repos/printathing/openscad/pulls{/number}","milestones_url":"https://api.github.com/repos/printathing/openscad/milestones{/number}","notifications_url":"https://api.github.com/repos/printathing/openscad/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/printathing/openscad/labels{/name}","releases_url":"https://api.github.com/repos/printathing/openscad/releases{/id}","deployments_url":"https://api.github.com/repos/printathing/openscad/deployments","created_at":"2018-12-13T16:37:43Z","updated_at":"2018-12-24T18:49:34Z","pushed_at":"2018-12-24T18:49:32Z","git_url":"git://github.com/printathing/openscad.git","ssh_url":"git@github.com:printathing/openscad.git","clone_url":"https://github.com/printathing/openscad.git","svn_url":"https://github.com/printathing/openscad","homepage":"openscad.org","size":58636,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"openscad:master","ref":"master","sha":"f2848902e8264f2fd068694741de6aaaec33f452","user":{"login":"openscad","id":466370,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ2NjM3MA==","avatar_url":"https://avatars1.githubusercontent.com/u/466370?v=4","gravatar_id":"","url":"https://api.github.com/users/openscad","html_url":"https://github.com/openscad","followers_url":"https://api.github.com/users/openscad/followers","following_url":"https://api.github.com/users/openscad/following{/other_user}","gists_url":"https://api.github.com/users/openscad/gists{/gist_id}","starred_url":"https://api.github.com/users/openscad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openscad/subscriptions","organizations_url":"https://api.github.com/users/openscad/orgs","repos_url":"https://api.github.com/users/openscad/repos","events_url":"https://api.github.com/users/openscad/events{/privacy}","received_events_url":"https://api.github.com/users/openscad/received_events","type":"Organization","site_admin":false},"repo":{"id":1049088,"node_id":"MDEwOlJlcG9zaXRvcnkxMDQ5MDg4","name":"openscad","full_name":"openscad/openscad","private":false,"owner":{"login":"openscad","id":466370,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ2NjM3MA==","avatar_url":"https://avatars1.githubusercontent.com/u/466370?v=4","gravatar_id":"","url":"https://api.github.com/users/openscad","html_url":"https://github.com/openscad","followers_url":"https://api.github.com/users/openscad/followers","following_url":"https://api.github.com/users/openscad/following{/other_user}","gists_url":"https://api.github.com/users/openscad/gists{/gist_id}","starred_url":"https://api.github.com/users/openscad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openscad/subscriptions","organizations_url":"https://api.github.com/users/openscad/orgs","repos_url":"https://api.github.com/users/openscad/repos","events_url":"https://api.github.com/users/openscad/events{/privacy}","received_events_url":"https://api.github.com/users/openscad/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/openscad/openscad","description":"OpenSCAD - The Programmers Solid 3D CAD Modeller  ","fork":false,"url":"https://api.github.com/repos/openscad/openscad","forks_url":"https://api.github.com/repos/openscad/openscad/forks","keys_url":"https://api.github.com/repos/openscad/openscad/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openscad/openscad/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openscad/openscad/teams","hooks_url":"https://api.github.com/repos/openscad/openscad/hooks","issue_events_url":"https://api.github.com/repos/openscad/openscad/issues/events{/number}","events_url":"https://api.github.com/repos/openscad/openscad/events","assignees_url":"https://api.github.com/repos/openscad/openscad/assignees{/user}","branches_url":"https://api.github.com/repos/openscad/openscad/branches{/branch}","tags_url":"https://api.github.com/repos/openscad/openscad/tags","blobs_url":"https://api.github.com/repos/openscad/openscad/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openscad/openscad/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openscad/openscad/git/refs{/sha}","trees_url":"https://api.github.com/repos/openscad/openscad/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openscad/openscad/statuses/{sha}","languages_url":"https://api.github.com/repos/openscad/openscad/languages","stargazers_url":"https://api.github.com/repos/openscad/openscad/stargazers","contributors_url":"https://api.github.com/repos/openscad/openscad/contributors","subscribers_url":"https://api.github.com/repos/openscad/openscad/subscribers","subscription_url":"https://api.github.com/repos/openscad/openscad/subscription","commits_url":"https://api.github.com/repos/openscad/openscad/commits{/sha}","git_commits_url":"https://api.github.com/repos/openscad/openscad/git/commits{/sha}","comments_url":"https://api.github.com/repos/openscad/openscad/comments{/number}","issue_comment_url":"https://api.github.com/repos/openscad/openscad/issues/comments{/number}","contents_url":"https://api.github.com/repos/openscad/openscad/contents/{+path}","compare_url":"https://api.github.com/repos/openscad/openscad/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openscad/openscad/merges","archive_url":"https://api.github.com/repos/openscad/openscad/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openscad/openscad/downloads","issues_url":"https://api.github.com/repos/openscad/openscad/issues{/number}","pulls_url":"https://api.github.com/repos/openscad/openscad/pulls{/number}","milestones_url":"https://api.github.com/repos/openscad/openscad/milestones{/number}","notifications_url":"https://api.github.com/repos/openscad/openscad/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openscad/openscad/labels{/name}","releases_url":"https://api.github.com/repos/openscad/openscad/releases{/id}","deployments_url":"https://api.github.com/repos/openscad/openscad/deployments","created_at":"2010-11-03T20:25:33Z","updated_at":"2018-12-30T09:56:40Z","pushed_at":"2018-12-30T13:15:23Z","git_url":"git://github.com/openscad/openscad.git","ssh_url":"git@github.com:openscad/openscad.git","clone_url":"https://github.com/openscad/openscad.git","svn_url":"https://github.com/openscad/openscad","homepage":"openscad.org","size":58626,"stargazers_count":2414,"watchers_count":2414,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":608,"mirror_url":null,"archived":false,"open_issues_count":588,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":608,"open_issues":588,"watchers":2414,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openscad/openscad/pulls/2642"},"html":{"href":"https://github.com/openscad/openscad/pull/2642"},"issue":{"href":"https://api.github.com/repos/openscad/openscad/issues/2642"},"comments":{"href":"https://api.github.com/repos/openscad/openscad/issues/2642/comments"},"review_comments":{"href":"https://api.github.com/repos/openscad/openscad/pulls/2642/comments"},"review_comment":{"href":"https://api.github.com/repos/openscad/openscad/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openscad/openscad/pulls/2642/commits"},"statuses":{"href":"https://api.github.com/repos/openscad/openscad/statuses/ac1819c49a91472b7e3920100ccfc1547b5f39b1"}},"author_association":"NONE"}}
{"actor":{"display_login":"printathing"}}