Cura.qml 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
  1. // Copyright (c) 2017 Ultimaker B.V.
  2. // Cura is released under the terms of the AGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Controls 1.1
  5. import QtQuick.Controls.Styles 1.1
  6. import QtQuick.Layouts 1.1
  7. import QtQuick.Dialogs 1.1
  8. import UM 1.3 as UM
  9. import Cura 1.0 as Cura
  10. import "Menus"
  11. UM.MainWindow
  12. {
  13. id: base
  14. //: Cura application window title
  15. title: catalog.i18nc("@title:window","Cura");
  16. viewportRect: Qt.rect(0, 0, (base.width - sidebar.width) / base.width, 1.0)
  17. property bool showPrintMonitor: false
  18. Connections
  19. {
  20. target: Printer
  21. onShowPrintMonitor:
  22. {
  23. if (show)
  24. {
  25. topbar.startMonitoringPrint()
  26. }
  27. else
  28. {
  29. topbar.stopMonitoringPrint()
  30. }
  31. }
  32. }
  33. Component.onCompleted:
  34. {
  35. CuraApplication.setMinimumWindowSize(UM.Theme.getSize("window_minimum_size"))
  36. // Workaround silly issues with QML Action's shortcut property.
  37. //
  38. // Currently, there is no way to define shortcuts as "Application Shortcut".
  39. // This means that all Actions are "Window Shortcuts". The code for this
  40. // implements a rather naive check that just checks if any of the action's parents
  41. // are a window. Since the "Actions" object is a singleton it has no parent by
  42. // default. If we set its parent to something contained in this window, the
  43. // shortcut will activate properly because one of its parents is a window.
  44. //
  45. // This has been fixed for QtQuick Controls 2 since the Shortcut item has a context property.
  46. Cura.Actions.parent = backgroundItem
  47. }
  48. Item
  49. {
  50. id: backgroundItem;
  51. anchors.fill: parent;
  52. UM.I18nCatalog{id: catalog; name:"cura"}
  53. signal hasMesh(string name) //this signal sends the filebase name so it can be used for the JobSpecs.qml
  54. function getMeshName(path){
  55. //takes the path the complete path of the meshname and returns only the filebase
  56. var fileName = path.slice(path.lastIndexOf("/") + 1)
  57. var fileBase = fileName.slice(0, fileName.indexOf("."))
  58. return fileBase
  59. }
  60. //DeleteSelection on the keypress backspace event
  61. Keys.onPressed: {
  62. if (event.key == Qt.Key_Backspace)
  63. {
  64. Cura.Actions.deleteSelection.trigger()
  65. }
  66. }
  67. UM.ApplicationMenu
  68. {
  69. id: menu
  70. window: base
  71. Menu
  72. {
  73. id: fileMenu
  74. title: catalog.i18nc("@title:menu menubar:toplevel","&File");
  75. MenuItem
  76. {
  77. action: Cura.Actions.newProject;
  78. }
  79. MenuItem
  80. {
  81. action: Cura.Actions.open;
  82. }
  83. RecentFilesMenu { }
  84. MenuSeparator { }
  85. MenuItem
  86. {
  87. text: catalog.i18nc("@action:inmenu menubar:file", "&Save Selection to File");
  88. enabled: UM.Selection.hasSelection;
  89. iconName: "document-save-as";
  90. onTriggered: UM.OutputDeviceManager.requestWriteSelectionToDevice("local_file", PrintInformation.jobName, { "filter_by_machine": false, "preferred_mimetype": "application/vnd.ms-package.3dmanufacturing-3dmodel+xml"});
  91. }
  92. MenuItem
  93. {
  94. id: saveAsMenu
  95. text: catalog.i18nc("@title:menu menubar:file", "Save &As...")
  96. onTriggered:
  97. {
  98. var localDeviceId = "local_file";
  99. UM.OutputDeviceManager.requestWriteToDevice(localDeviceId, PrintInformation.jobName, { "filter_by_machine": false, "preferred_mimetype": "application/vnd.ms-package.3dmanufacturing-3dmodel+xml"});
  100. }
  101. }
  102. MenuItem
  103. {
  104. id: saveWorkspaceMenu
  105. text: catalog.i18nc("@title:menu menubar:file","Save project")
  106. onTriggered:
  107. {
  108. if(UM.Preferences.getValue("cura/dialog_on_project_save"))
  109. {
  110. saveWorkspaceDialog.open()
  111. }
  112. else
  113. {
  114. UM.OutputDeviceManager.requestWriteToDevice("local_file", PrintInformation.jobName, { "filter_by_machine": false, "file_type": "workspace" })
  115. }
  116. }
  117. }
  118. MenuItem { action: Cura.Actions.reloadAll; }
  119. MenuSeparator { }
  120. MenuItem { action: Cura.Actions.quit; }
  121. }
  122. Menu
  123. {
  124. title: catalog.i18nc("@title:menu menubar:toplevel","&Edit");
  125. MenuItem { action: Cura.Actions.undo; }
  126. MenuItem { action: Cura.Actions.redo; }
  127. MenuSeparator { }
  128. MenuItem { action: Cura.Actions.selectAll; }
  129. MenuItem { action: Cura.Actions.arrangeAll; }
  130. MenuItem { action: Cura.Actions.deleteSelection; }
  131. MenuItem { action: Cura.Actions.deleteAll; }
  132. MenuItem { action: Cura.Actions.resetAllTranslation; }
  133. MenuItem { action: Cura.Actions.resetAll; }
  134. MenuSeparator { }
  135. MenuItem { action: Cura.Actions.groupObjects;}
  136. MenuItem { action: Cura.Actions.mergeObjects;}
  137. MenuItem { action: Cura.Actions.unGroupObjects;}
  138. }
  139. ViewMenu { title: catalog.i18nc("@title:menu", "&View") }
  140. Menu
  141. {
  142. id: settingsMenu
  143. title: catalog.i18nc("@title:menu", "&Settings")
  144. PrinterMenu { title: catalog.i18nc("@title:menu menubar:toplevel", "&Printer") }
  145. Instantiator
  146. {
  147. model: Cura.ExtrudersModel { simpleNames: true }
  148. Menu {
  149. title: model.name
  150. visible: machineExtruderCount.properties.value > 1
  151. NozzleMenu { title: Cura.MachineManager.activeDefinitionVariantsName; visible: Cura.MachineManager.hasVariants; extruderIndex: index }
  152. MaterialMenu { title: catalog.i18nc("@title:menu", "&Material"); visible: Cura.MachineManager.hasMaterials; extruderIndex: index }
  153. ProfileMenu { title: catalog.i18nc("@title:menu", "&Profile"); }
  154. MenuSeparator { }
  155. MenuItem { text: catalog.i18nc("@action:inmenu", "Set as Active Extruder"); onTriggered: ExtruderManager.setActiveExtruderIndex(model.index) }
  156. }
  157. onObjectAdded: settingsMenu.insertItem(index, object)
  158. onObjectRemoved: settingsMenu.removeItem(object)
  159. }
  160. NozzleMenu { title: Cura.MachineManager.activeDefinitionVariantsName; visible: machineExtruderCount.properties.value <= 1 && Cura.MachineManager.hasVariants }
  161. MaterialMenu { title: catalog.i18nc("@title:menu", "&Material"); visible: machineExtruderCount.properties.value <= 1 && Cura.MachineManager.hasMaterials }
  162. ProfileMenu { title: catalog.i18nc("@title:menu", "&Profile"); visible: machineExtruderCount.properties.value <= 1 }
  163. MenuSeparator { }
  164. MenuItem { action: Cura.Actions.configureSettingVisibility }
  165. }
  166. Menu
  167. {
  168. id: extension_menu
  169. title: catalog.i18nc("@title:menu menubar:toplevel","E&xtensions");
  170. Instantiator
  171. {
  172. id: extensions
  173. model: UM.ExtensionModel { }
  174. Menu
  175. {
  176. id: sub_menu
  177. title: model.name;
  178. visible: actions != null
  179. enabled:actions != null
  180. Instantiator
  181. {
  182. model: actions
  183. MenuItem
  184. {
  185. text: model.text
  186. onTriggered: extensions.model.subMenuTriggered(name, model.text)
  187. }
  188. onObjectAdded: sub_menu.insertItem(index, object)
  189. onObjectRemoved: sub_menu.removeItem(object)
  190. }
  191. }
  192. onObjectAdded: extension_menu.insertItem(index, object)
  193. onObjectRemoved: extension_menu.removeItem(object)
  194. }
  195. }
  196. Menu
  197. {
  198. title: catalog.i18nc("@title:menu menubar:toplevel","P&references");
  199. MenuItem { action: Cura.Actions.preferences; }
  200. }
  201. Menu
  202. {
  203. //: Help menu
  204. title: catalog.i18nc("@title:menu menubar:toplevel","&Help");
  205. MenuItem { action: Cura.Actions.showProfileFolder; }
  206. MenuItem { action: Cura.Actions.documentation; }
  207. MenuItem { action: Cura.Actions.reportBug; }
  208. MenuSeparator { }
  209. MenuItem { action: Cura.Actions.about; }
  210. }
  211. }
  212. UM.SettingPropertyProvider
  213. {
  214. id: machineExtruderCount
  215. containerStackId: Cura.MachineManager.activeMachineId
  216. key: "machine_extruder_count"
  217. watchedProperties: [ "value" ]
  218. storeIndex: 0
  219. }
  220. Item
  221. {
  222. id: contentItem;
  223. y: menu.height
  224. width: parent.width;
  225. height: parent.height - menu.height;
  226. Keys.forwardTo: menu
  227. DropArea
  228. {
  229. anchors.fill: parent;
  230. onDropped:
  231. {
  232. if (drop.urls.length > 0)
  233. {
  234. // As the drop area also supports plugins, first check if it's a plugin that was dropped.
  235. if (drop.urls.length == 1)
  236. {
  237. if (PluginRegistry.isPluginFile(drop.urls[0]))
  238. {
  239. // Try to install plugin & close.
  240. var result = PluginRegistry.installPlugin(drop.urls[0]);
  241. pluginInstallDialog.text = result.message;
  242. if (result.status == "ok")
  243. {
  244. pluginInstallDialog.icon = StandardIcon.Information;
  245. }
  246. else if (result.status == "duplicate")
  247. {
  248. pluginInstallDialog.icon = StandardIcon.Warning;
  249. }
  250. else
  251. {
  252. pluginInstallDialog.icon = StandardIcon.Critical;
  253. }
  254. pluginInstallDialog.open();
  255. return;
  256. }
  257. }
  258. openDialog.handleOpenFileUrls(drop.urls);
  259. }
  260. }
  261. }
  262. JobSpecs
  263. {
  264. id: jobSpecs
  265. anchors
  266. {
  267. bottom: parent.bottom;
  268. right: sidebar.left;
  269. bottomMargin: UM.Theme.getSize("default_margin").height;
  270. rightMargin: UM.Theme.getSize("default_margin").width;
  271. }
  272. }
  273. Loader
  274. {
  275. id: view_panel
  276. property bool hugBottom: parent.height < viewModeButton.y + viewModeButton.height + height + UM.Theme.getSize("default_margin").height
  277. anchors.bottom: parent.bottom // panel is always anchored to the bottom only, because dynamically switching between bottom and top results in stretching the height
  278. anchors.bottomMargin: hugBottom ? 0 : parent.height - (viewModeButton.y + viewModeButton.height + height + UM.Theme.getSize("default_margin").height)
  279. anchors.left: viewModeButton.left;
  280. anchors.leftMargin: hugBottom ? viewModeButton.width + UM.Theme.getSize("default_margin").width : 0
  281. property var buttonTarget: Qt.point(viewModeButton.x + viewModeButton.width / 2, viewModeButton.y + viewModeButton.height / 2)
  282. height: childrenRect.height;
  283. source: UM.ActiveView.valid ? UM.ActiveView.activeViewPanel : "";
  284. }
  285. Button
  286. {
  287. id: openFileButton;
  288. text: catalog.i18nc("@action:button","Open File");
  289. iconSource: UM.Theme.getIcon("load")
  290. style: UM.Theme.styles.tool_button
  291. tooltip: '';
  292. anchors
  293. {
  294. top: topbar.bottom;
  295. topMargin: UM.Theme.getSize("default_margin").height;
  296. left: parent.left;
  297. }
  298. action: Cura.Actions.open;
  299. }
  300. Toolbar
  301. {
  302. id: toolbar;
  303. property int mouseX: base.mouseX
  304. property int mouseY: base.mouseY
  305. anchors {
  306. top: openFileButton.bottom;
  307. topMargin: UM.Theme.getSize("window_margin").height;
  308. left: parent.left;
  309. }
  310. }
  311. Topbar
  312. {
  313. id: topbar
  314. anchors.left:parent.left
  315. anchors.right: parent.right
  316. anchors.top: parent.top
  317. monitoringPrint: base.showPrintMonitor
  318. onStartMonitoringPrint: base.showPrintMonitor = true
  319. onStopMonitoringPrint: base.showPrintMonitor = false
  320. }
  321. Sidebar
  322. {
  323. id: sidebar;
  324. anchors
  325. {
  326. top: topbar.bottom;
  327. bottom: parent.bottom;
  328. right: parent.right;
  329. }
  330. z: 1
  331. width: UM.Theme.getSize("sidebar").width;
  332. monitoringPrint: base.showPrintMonitor
  333. }
  334. Button
  335. {
  336. id: viewModeButton
  337. anchors
  338. {
  339. top: toolbar.bottom;
  340. topMargin: UM.Theme.getSize("window_margin").height;
  341. left: parent.left;
  342. }
  343. text: catalog.i18nc("@action:button","View Mode");
  344. iconSource: UM.Theme.getIcon("viewmode");
  345. style: UM.Theme.styles.tool_button;
  346. tooltip: "";
  347. enabled: !PrintInformation.preSliced
  348. menu: ViewMenu { }
  349. }
  350. Rectangle
  351. {
  352. id: viewportOverlay
  353. color: UM.Theme.getColor("viewport_overlay")
  354. anchors
  355. {
  356. top: topbar.bottom
  357. bottom: parent.bottom
  358. left:parent.left
  359. right: sidebar.left
  360. }
  361. visible: opacity > 0
  362. opacity: base.showPrintMonitor ? 1 : 0
  363. Behavior on opacity { NumberAnimation { duration: 100; } }
  364. MouseArea {
  365. anchors.fill: parent
  366. acceptedButtons: Qt.AllButtons
  367. onWheel: wheel.accepted = true
  368. }
  369. }
  370. Loader
  371. {
  372. sourceComponent: Cura.MachineManager.printerOutputDevices.length > 0 ? Cura.MachineManager.printerOutputDevices[0].monitorItem: null
  373. visible: base.showPrintMonitor
  374. anchors.horizontalCenter: parent.horizontalCenter
  375. anchors.verticalCenter: parent.verticalCenter
  376. anchors.horizontalCenterOffset: - UM.Theme.getSize("sidebar").width / 2
  377. anchors.verticalCenterOffset: UM.Theme.getSize("sidebar_header").height / 2
  378. property real maximumWidth: viewportOverlay.width
  379. property real maximumHeight: viewportOverlay.height
  380. }
  381. UM.MessageStack
  382. {
  383. anchors
  384. {
  385. horizontalCenter: parent.horizontalCenter
  386. horizontalCenterOffset: -(UM.Theme.getSize("sidebar").width/ 2)
  387. top: parent.verticalCenter;
  388. bottom: parent.bottom;
  389. }
  390. }
  391. }
  392. }
  393. UM.PreferencesDialog
  394. {
  395. id: preferences
  396. Component.onCompleted:
  397. {
  398. //; Remove & re-add the general page as we want to use our own instead of uranium standard.
  399. removePage(0);
  400. insertPage(0, catalog.i18nc("@title:tab","General"), Qt.resolvedUrl("Preferences/GeneralPage.qml"));
  401. removePage(1);
  402. insertPage(1, catalog.i18nc("@title:tab","Settings"), Qt.resolvedUrl("Preferences/SettingVisibilityPage.qml"));
  403. insertPage(2, catalog.i18nc("@title:tab", "Printers"), Qt.resolvedUrl("Preferences/MachinesPage.qml"));
  404. insertPage(3, catalog.i18nc("@title:tab", "Materials"), Qt.resolvedUrl("Preferences/MaterialsPage.qml"));
  405. insertPage(4, catalog.i18nc("@title:tab", "Profiles"), Qt.resolvedUrl("Preferences/ProfilesPage.qml"));
  406. //Force refresh
  407. setPage(0);
  408. }
  409. onVisibleChanged:
  410. {
  411. // When the dialog closes, switch to the General page.
  412. // This prevents us from having a heavy page like Setting Visiblity active in the background.
  413. setPage(0);
  414. }
  415. }
  416. WorkspaceSummaryDialog
  417. {
  418. id: saveWorkspaceDialog
  419. onYes: UM.OutputDeviceManager.requestWriteToDevice("local_file", PrintInformation.jobName, { "filter_by_machine": false, "file_type": "workspace" })
  420. }
  421. Connections
  422. {
  423. target: Cura.Actions.preferences
  424. onTriggered: preferences.visible = true
  425. }
  426. MessageDialog
  427. {
  428. id: newProjectDialog
  429. modality: Qt.ApplicationModal
  430. title: catalog.i18nc("@title:window", "New project")
  431. text: catalog.i18nc("@info:question", "Are you sure you want to start a new project? This will clear the build plate and any unsaved settings.")
  432. standardButtons: StandardButton.Yes | StandardButton.No
  433. icon: StandardIcon.Question
  434. onYes:
  435. {
  436. CuraApplication.deleteAll();
  437. Cura.Actions.resetProfile.trigger();
  438. }
  439. }
  440. Connections
  441. {
  442. target: Cura.Actions.newProject
  443. onTriggered:
  444. {
  445. if(Printer.platformActivity || Cura.MachineManager.hasUserSettings)
  446. {
  447. newProjectDialog.visible = true
  448. }
  449. }
  450. }
  451. Connections
  452. {
  453. target: Cura.Actions.addProfile
  454. onTriggered:
  455. {
  456. preferences.show();
  457. preferences.setPage(4);
  458. // Create a new profile after a very short delay so the preference page has time to initiate
  459. createProfileTimer.start();
  460. }
  461. }
  462. Connections
  463. {
  464. target: Cura.Actions.configureMachines
  465. onTriggered:
  466. {
  467. preferences.visible = true;
  468. preferences.setPage(2);
  469. }
  470. }
  471. Connections
  472. {
  473. target: Cura.Actions.manageProfiles
  474. onTriggered:
  475. {
  476. preferences.visible = true;
  477. preferences.setPage(4);
  478. }
  479. }
  480. Connections
  481. {
  482. target: Cura.Actions.manageMaterials
  483. onTriggered:
  484. {
  485. preferences.visible = true;
  486. preferences.setPage(3)
  487. }
  488. }
  489. Connections
  490. {
  491. target: Cura.Actions.configureSettingVisibility
  492. onTriggered:
  493. {
  494. preferences.visible = true;
  495. preferences.setPage(1);
  496. preferences.getCurrentItem().scrollToSection(source.key);
  497. }
  498. }
  499. Timer
  500. {
  501. id: createProfileTimer
  502. repeat: false
  503. interval: 1
  504. onTriggered: preferences.getCurrentItem().createProfile()
  505. }
  506. // BlurSettings is a way to force the focus away from any of the setting items.
  507. // We need to do this in order to keep the bindings intact.
  508. Connections
  509. {
  510. target: Cura.MachineManager
  511. onBlurSettings:
  512. {
  513. contentItem.forceActiveFocus()
  514. }
  515. }
  516. ContextMenu {
  517. id: contextMenu
  518. }
  519. Connections
  520. {
  521. target: Cura.Actions.quit
  522. onTriggered: CuraApplication.closeApplication();
  523. }
  524. Connections
  525. {
  526. target: Cura.Actions.toggleFullScreen
  527. onTriggered: base.toggleFullscreen();
  528. }
  529. FileDialog
  530. {
  531. id: openDialog;
  532. //: File open dialog title
  533. title: catalog.i18nc("@title:window","Open file(s)")
  534. modality: UM.Application.platform == "linux" ? Qt.NonModal : Qt.WindowModal;
  535. selectMultiple: true
  536. nameFilters: UM.MeshFileHandler.supportedReadFileTypes;
  537. folder: CuraApplication.getDefaultPath("dialog_load_path")
  538. onAccepted:
  539. {
  540. // Because several implementations of the file dialog only update the folder
  541. // when it is explicitly set.
  542. var f = folder;
  543. folder = f;
  544. CuraApplication.setDefaultPath("dialog_load_path", folder);
  545. handleOpenFileUrls(fileUrls);
  546. }
  547. // Yeah... I know... it is a mess to put all those things here.
  548. // There are lots of user interactions in this part of the logic, such as showing a warning dialog here and there,
  549. // etc. This means it will come back and forth from time to time between QML and Python. So, separating the logic
  550. // and view here may require more effort but make things more difficult to understand.
  551. function handleOpenFileUrls(fileUrlList)
  552. {
  553. // look for valid project files
  554. var projectFileUrlList = [];
  555. var hasGcode = false;
  556. var nonGcodeFileList = [];
  557. for (var i in fileUrlList)
  558. {
  559. var endsWithG = /\.g$/;
  560. var endsWithGcode = /\.gcode$/;
  561. if (endsWithG.test(fileUrlList[i]) || endsWithGcode.test(fileUrlList[i]))
  562. {
  563. continue;
  564. }
  565. else if (CuraApplication.checkIsValidProjectFile(fileUrlList[i]))
  566. {
  567. projectFileUrlList.push(fileUrlList[i]);
  568. }
  569. nonGcodeFileList.push(fileUrlList[i]);
  570. }
  571. hasGcode = nonGcodeFileList.length < fileUrlList.length;
  572. // show a warning if selected multiple files together with Gcode
  573. var hasProjectFile = projectFileUrlList.length > 0;
  574. var selectedMultipleFiles = fileUrlList.length > 1;
  575. if (selectedMultipleFiles && hasGcode)
  576. {
  577. infoMultipleFilesWithGcodeDialog.selectedMultipleFiles = selectedMultipleFiles;
  578. infoMultipleFilesWithGcodeDialog.hasProjectFile = hasProjectFile;
  579. infoMultipleFilesWithGcodeDialog.fileUrls = nonGcodeFileList.slice();
  580. infoMultipleFilesWithGcodeDialog.projectFileUrlList = projectFileUrlList.slice();
  581. infoMultipleFilesWithGcodeDialog.open();
  582. }
  583. else
  584. {
  585. handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrlList, projectFileUrlList);
  586. }
  587. }
  588. function handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrlList, projectFileUrlList)
  589. {
  590. // we only allow opening one project file
  591. if (selectedMultipleFiles && hasProjectFile)
  592. {
  593. openFilesIncludingProjectsDialog.fileUrls = fileUrlList.slice();
  594. openFilesIncludingProjectsDialog.show();
  595. return;
  596. }
  597. if (hasProjectFile)
  598. {
  599. var projectFile = projectFileUrlList[0];
  600. // check preference
  601. var choice = UM.Preferences.getValue("cura/choice_on_open_project");
  602. if (choice == "open_as_project")
  603. {
  604. openFilesIncludingProjectsDialog.loadProjectFile(projectFile);
  605. }
  606. else if (choice == "open_as_model")
  607. {
  608. openFilesIncludingProjectsDialog.loadModelFiles([projectFile].slice());
  609. }
  610. else // always ask
  611. {
  612. // ask whether to open as project or as models
  613. askOpenAsProjectOrModelsDialog.fileUrl = projectFile;
  614. askOpenAsProjectOrModelsDialog.show();
  615. }
  616. }
  617. else
  618. {
  619. openFilesIncludingProjectsDialog.loadModelFiles(fileUrlList.slice());
  620. }
  621. }
  622. }
  623. MessageDialog
  624. {
  625. id: pluginInstallDialog
  626. title: catalog.i18nc("@window:title", "Install Plugin");
  627. standardButtons: StandardButton.Ok
  628. modality: Qt.ApplicationModal
  629. }
  630. MessageDialog {
  631. id: infoMultipleFilesWithGcodeDialog
  632. title: catalog.i18nc("@title:window", "Open File(s)")
  633. icon: StandardIcon.Information
  634. standardButtons: StandardButton.Ok
  635. text: catalog.i18nc("@text:window", "We have found one or more G-Code files within the files you have selected. You can only open one G-Code file at a time. If you want to open a G-Code file, please just select only one.")
  636. property var selectedMultipleFiles
  637. property var hasProjectFile
  638. property var fileUrls
  639. property var projectFileUrlList
  640. onAccepted:
  641. {
  642. openDialog.handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrls, projectFileUrlList);
  643. }
  644. }
  645. Connections
  646. {
  647. target: Cura.Actions.open
  648. onTriggered: openDialog.open()
  649. }
  650. OpenFilesIncludingProjectsDialog
  651. {
  652. id: openFilesIncludingProjectsDialog
  653. }
  654. AskOpenAsProjectOrModelsDialog
  655. {
  656. id: askOpenAsProjectOrModelsDialog
  657. }
  658. EngineLog
  659. {
  660. id: engineLog;
  661. }
  662. Connections
  663. {
  664. target: Cura.Actions.showProfileFolder
  665. onTriggered:
  666. {
  667. var path = UM.Resources.getPath(UM.Resources.Preferences, "");
  668. if(Qt.platform.os == "windows") {
  669. path = path.replace(/\\/g,"/");
  670. }
  671. Qt.openUrlExternally(path);
  672. }
  673. }
  674. AddMachineDialog
  675. {
  676. id: addMachineDialog
  677. onMachineAdded:
  678. {
  679. machineActionsWizard.firstRun = addMachineDialog.firstRun
  680. machineActionsWizard.start(id)
  681. }
  682. }
  683. // Dialog to handle first run machine actions
  684. UM.Wizard
  685. {
  686. id: machineActionsWizard;
  687. title: catalog.i18nc("@title:window", "Add Printer")
  688. property var machine;
  689. function start(id)
  690. {
  691. var actions = Cura.MachineActionManager.getFirstStartActions(id)
  692. resetPages() // Remove previous pages
  693. for (var i = 0; i < actions.length; i++)
  694. {
  695. actions[i].displayItem.reset()
  696. machineActionsWizard.appendPage(actions[i].displayItem, catalog.i18nc("@title", actions[i].label));
  697. }
  698. //Only start if there are actions to perform.
  699. if (actions.length > 0)
  700. {
  701. machineActionsWizard.currentPage = 0;
  702. show()
  703. }
  704. }
  705. }
  706. MessageDialog
  707. {
  708. id: messageDialog
  709. modality: Qt.ApplicationModal
  710. onAccepted: CuraApplication.messageBoxClosed(clickedButton)
  711. onApply: CuraApplication.messageBoxClosed(clickedButton)
  712. onDiscard: CuraApplication.messageBoxClosed(clickedButton)
  713. onHelp: CuraApplication.messageBoxClosed(clickedButton)
  714. onNo: CuraApplication.messageBoxClosed(clickedButton)
  715. onRejected: CuraApplication.messageBoxClosed(clickedButton)
  716. onReset: CuraApplication.messageBoxClosed(clickedButton)
  717. onYes: CuraApplication.messageBoxClosed(clickedButton)
  718. }
  719. Connections
  720. {
  721. target: Printer
  722. onShowMessageBox:
  723. {
  724. messageDialog.title = title
  725. messageDialog.text = text
  726. messageDialog.informativeText = informativeText
  727. messageDialog.detailedText = detailedText
  728. messageDialog.standardButtons = buttons
  729. messageDialog.icon = icon
  730. messageDialog.visible = true
  731. }
  732. }
  733. DiscardOrKeepProfileChangesDialog
  734. {
  735. id: discardOrKeepProfileChangesDialog
  736. }
  737. Connections
  738. {
  739. target: Printer
  740. onShowDiscardOrKeepProfileChanges:
  741. {
  742. discardOrKeepProfileChangesDialog.show()
  743. }
  744. }
  745. Connections
  746. {
  747. target: Cura.Actions.addMachine
  748. onTriggered: addMachineDialog.visible = true;
  749. }
  750. AboutDialog
  751. {
  752. id: aboutDialog
  753. }
  754. Connections
  755. {
  756. target: Cura.Actions.about
  757. onTriggered: aboutDialog.visible = true;
  758. }
  759. Connections
  760. {
  761. target: Printer
  762. onRequestAddPrinter:
  763. {
  764. addMachineDialog.visible = true
  765. addMachineDialog.firstRun = false
  766. }
  767. }
  768. Timer
  769. {
  770. id: startupTimer;
  771. interval: 100;
  772. repeat: false;
  773. running: true;
  774. onTriggered:
  775. {
  776. if(!base.visible)
  777. {
  778. base.visible = true;
  779. restart();
  780. }
  781. else if(Cura.MachineManager.activeMachineId == null || Cura.MachineManager.activeMachineId == "")
  782. {
  783. addMachineDialog.open();
  784. }
  785. }
  786. }
  787. }