Cura.qml 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937
  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. Image
  301. {
  302. id: logo
  303. anchors
  304. {
  305. left: parent.left
  306. leftMargin: UM.Theme.getSize("default_margin").width;
  307. bottom: parent.bottom
  308. bottomMargin: UM.Theme.getSize("default_margin").height;
  309. }
  310. source: UM.Theme.getImage("logo");
  311. width: UM.Theme.getSize("logo").width;
  312. height: UM.Theme.getSize("logo").height;
  313. z: -1;
  314. sourceSize.width: width;
  315. sourceSize.height: height;
  316. }
  317. Toolbar
  318. {
  319. id: toolbar;
  320. property int mouseX: base.mouseX
  321. property int mouseY: base.mouseY
  322. anchors {
  323. top: openFileButton.bottom;
  324. topMargin: UM.Theme.getSize("window_margin").height;
  325. left: parent.left;
  326. }
  327. }
  328. Topbar
  329. {
  330. id: topbar
  331. anchors.left:parent.left
  332. anchors.right: parent.right
  333. anchors.top: parent.top
  334. monitoringPrint: base.showPrintMonitor
  335. onStartMonitoringPrint: base.showPrintMonitor = true
  336. onStopMonitoringPrint: base.showPrintMonitor = false
  337. }
  338. Sidebar
  339. {
  340. id: sidebar;
  341. anchors
  342. {
  343. top: topbar.bottom;
  344. bottom: parent.bottom;
  345. right: parent.right;
  346. }
  347. z: 1
  348. width: UM.Theme.getSize("sidebar").width;
  349. monitoringPrint: base.showPrintMonitor
  350. }
  351. Button
  352. {
  353. id: viewModeButton
  354. anchors
  355. {
  356. top: toolbar.bottom;
  357. topMargin: UM.Theme.getSize("window_margin").height;
  358. left: parent.left;
  359. }
  360. text: catalog.i18nc("@action:button","View Mode");
  361. iconSource: UM.Theme.getIcon("viewmode");
  362. style: UM.Theme.styles.tool_button;
  363. tooltip: "";
  364. enabled: !PrintInformation.preSliced
  365. menu: ViewMenu { }
  366. }
  367. Rectangle
  368. {
  369. id: viewportOverlay
  370. color: UM.Theme.getColor("viewport_overlay")
  371. anchors
  372. {
  373. top: topbar.bottom
  374. bottom: parent.bottom
  375. left:parent.left
  376. right: sidebar.left
  377. }
  378. visible: opacity > 0
  379. opacity: base.showPrintMonitor ? 1 : 0
  380. Behavior on opacity { NumberAnimation { duration: 100; } }
  381. MouseArea {
  382. anchors.fill: parent
  383. acceptedButtons: Qt.AllButtons
  384. onWheel: wheel.accepted = true
  385. }
  386. }
  387. Loader
  388. {
  389. sourceComponent: Cura.MachineManager.printerOutputDevices.length > 0 ? Cura.MachineManager.printerOutputDevices[0].monitorItem: null
  390. visible: base.showPrintMonitor
  391. anchors.horizontalCenter: parent.horizontalCenter
  392. anchors.verticalCenter: parent.verticalCenter
  393. anchors.horizontalCenterOffset: - UM.Theme.getSize("sidebar").width / 2
  394. anchors.verticalCenterOffset: UM.Theme.getSize("sidebar_header").height / 2
  395. property real maximumWidth: viewportOverlay.width
  396. property real maximumHeight: viewportOverlay.height
  397. }
  398. UM.MessageStack
  399. {
  400. anchors
  401. {
  402. horizontalCenter: parent.horizontalCenter
  403. horizontalCenterOffset: -(UM.Theme.getSize("sidebar").width/ 2)
  404. top: parent.verticalCenter;
  405. bottom: parent.bottom;
  406. }
  407. }
  408. }
  409. }
  410. UM.PreferencesDialog
  411. {
  412. id: preferences
  413. Component.onCompleted:
  414. {
  415. //; Remove & re-add the general page as we want to use our own instead of uranium standard.
  416. removePage(0);
  417. insertPage(0, catalog.i18nc("@title:tab","General"), Qt.resolvedUrl("Preferences/GeneralPage.qml"));
  418. removePage(1);
  419. insertPage(1, catalog.i18nc("@title:tab","Settings"), Qt.resolvedUrl("Preferences/SettingVisibilityPage.qml"));
  420. insertPage(2, catalog.i18nc("@title:tab", "Printers"), Qt.resolvedUrl("Preferences/MachinesPage.qml"));
  421. insertPage(3, catalog.i18nc("@title:tab", "Materials"), Qt.resolvedUrl("Preferences/MaterialsPage.qml"));
  422. insertPage(4, catalog.i18nc("@title:tab", "Profiles"), Qt.resolvedUrl("Preferences/ProfilesPage.qml"));
  423. //Force refresh
  424. setPage(0);
  425. }
  426. onVisibleChanged:
  427. {
  428. // When the dialog closes, switch to the General page.
  429. // This prevents us from having a heavy page like Setting Visiblity active in the background.
  430. setPage(0);
  431. }
  432. }
  433. WorkspaceSummaryDialog
  434. {
  435. id: saveWorkspaceDialog
  436. onYes: UM.OutputDeviceManager.requestWriteToDevice("local_file", PrintInformation.jobName, { "filter_by_machine": false, "file_type": "workspace" })
  437. }
  438. Connections
  439. {
  440. target: Cura.Actions.preferences
  441. onTriggered: preferences.visible = true
  442. }
  443. MessageDialog
  444. {
  445. id: newProjectDialog
  446. modality: Qt.ApplicationModal
  447. title: catalog.i18nc("@title:window", "New project")
  448. 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.")
  449. standardButtons: StandardButton.Yes | StandardButton.No
  450. icon: StandardIcon.Question
  451. onYes:
  452. {
  453. CuraApplication.deleteAll();
  454. Cura.Actions.resetProfile.trigger();
  455. }
  456. }
  457. Connections
  458. {
  459. target: Cura.Actions.newProject
  460. onTriggered:
  461. {
  462. if(Printer.platformActivity || Cura.MachineManager.hasUserSettings)
  463. {
  464. newProjectDialog.visible = true
  465. }
  466. }
  467. }
  468. Connections
  469. {
  470. target: Cura.Actions.addProfile
  471. onTriggered:
  472. {
  473. preferences.show();
  474. preferences.setPage(4);
  475. // Create a new profile after a very short delay so the preference page has time to initiate
  476. createProfileTimer.start();
  477. }
  478. }
  479. Connections
  480. {
  481. target: Cura.Actions.configureMachines
  482. onTriggered:
  483. {
  484. preferences.visible = true;
  485. preferences.setPage(2);
  486. }
  487. }
  488. Connections
  489. {
  490. target: Cura.Actions.manageProfiles
  491. onTriggered:
  492. {
  493. preferences.visible = true;
  494. preferences.setPage(4);
  495. }
  496. }
  497. Connections
  498. {
  499. target: Cura.Actions.manageMaterials
  500. onTriggered:
  501. {
  502. preferences.visible = true;
  503. preferences.setPage(3)
  504. }
  505. }
  506. Connections
  507. {
  508. target: Cura.Actions.configureSettingVisibility
  509. onTriggered:
  510. {
  511. preferences.visible = true;
  512. preferences.setPage(1);
  513. preferences.getCurrentItem().scrollToSection(source.key);
  514. }
  515. }
  516. Timer
  517. {
  518. id: createProfileTimer
  519. repeat: false
  520. interval: 1
  521. onTriggered: preferences.getCurrentItem().createProfile()
  522. }
  523. // BlurSettings is a way to force the focus away from any of the setting items.
  524. // We need to do this in order to keep the bindings intact.
  525. Connections
  526. {
  527. target: Cura.MachineManager
  528. onBlurSettings:
  529. {
  530. contentItem.forceActiveFocus()
  531. }
  532. }
  533. ContextMenu {
  534. id: contextMenu
  535. }
  536. Connections
  537. {
  538. target: Cura.Actions.quit
  539. onTriggered: CuraApplication.closeApplication();
  540. }
  541. Connections
  542. {
  543. target: Cura.Actions.toggleFullScreen
  544. onTriggered: base.toggleFullscreen();
  545. }
  546. FileDialog
  547. {
  548. id: openDialog;
  549. //: File open dialog title
  550. title: catalog.i18nc("@title:window","Open file(s)")
  551. modality: UM.Application.platform == "linux" ? Qt.NonModal : Qt.WindowModal;
  552. selectMultiple: true
  553. nameFilters: UM.MeshFileHandler.supportedReadFileTypes;
  554. folder: CuraApplication.getDefaultPath("dialog_load_path")
  555. onAccepted:
  556. {
  557. // Because several implementations of the file dialog only update the folder
  558. // when it is explicitly set.
  559. var f = folder;
  560. folder = f;
  561. CuraApplication.setDefaultPath("dialog_load_path", folder);
  562. handleOpenFileUrls(fileUrls);
  563. }
  564. // Yeah... I know... it is a mess to put all those things here.
  565. // There are lots of user interactions in this part of the logic, such as showing a warning dialog here and there,
  566. // etc. This means it will come back and forth from time to time between QML and Python. So, separating the logic
  567. // and view here may require more effort but make things more difficult to understand.
  568. function handleOpenFileUrls(fileUrlList)
  569. {
  570. // look for valid project files
  571. var projectFileUrlList = [];
  572. var hasGcode = false;
  573. var nonGcodeFileList = [];
  574. for (var i in fileUrlList)
  575. {
  576. var endsWithG = /\.g$/;
  577. var endsWithGcode = /\.gcode$/;
  578. if (endsWithG.test(fileUrlList[i]) || endsWithGcode.test(fileUrlList[i]))
  579. {
  580. continue;
  581. }
  582. else if (CuraApplication.checkIsValidProjectFile(fileUrlList[i]))
  583. {
  584. projectFileUrlList.push(fileUrlList[i]);
  585. }
  586. nonGcodeFileList.push(fileUrlList[i]);
  587. }
  588. hasGcode = nonGcodeFileList.length < fileUrlList.length;
  589. // show a warning if selected multiple files together with Gcode
  590. var hasProjectFile = projectFileUrlList.length > 0;
  591. var selectedMultipleFiles = fileUrlList.length > 1;
  592. if (selectedMultipleFiles && hasGcode)
  593. {
  594. infoMultipleFilesWithGcodeDialog.selectedMultipleFiles = selectedMultipleFiles;
  595. infoMultipleFilesWithGcodeDialog.hasProjectFile = hasProjectFile;
  596. infoMultipleFilesWithGcodeDialog.fileUrls = nonGcodeFileList.slice();
  597. infoMultipleFilesWithGcodeDialog.projectFileUrlList = projectFileUrlList.slice();
  598. infoMultipleFilesWithGcodeDialog.open();
  599. }
  600. else
  601. {
  602. handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrlList, projectFileUrlList);
  603. }
  604. }
  605. function handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrlList, projectFileUrlList)
  606. {
  607. // we only allow opening one project file
  608. if (selectedMultipleFiles && hasProjectFile)
  609. {
  610. openFilesIncludingProjectsDialog.fileUrls = fileUrlList.slice();
  611. openFilesIncludingProjectsDialog.show();
  612. return;
  613. }
  614. if (hasProjectFile)
  615. {
  616. var projectFile = projectFileUrlList[0];
  617. // check preference
  618. var choice = UM.Preferences.getValue("cura/choice_on_open_project");
  619. if (choice == "open_as_project")
  620. {
  621. openFilesIncludingProjectsDialog.loadProjectFile(projectFile);
  622. }
  623. else if (choice == "open_as_model")
  624. {
  625. openFilesIncludingProjectsDialog.loadModelFiles([projectFile].slice());
  626. }
  627. else // always ask
  628. {
  629. // ask whether to open as project or as models
  630. askOpenAsProjectOrModelsDialog.fileUrl = projectFile;
  631. askOpenAsProjectOrModelsDialog.show();
  632. }
  633. }
  634. else
  635. {
  636. openFilesIncludingProjectsDialog.loadModelFiles(fileUrlList.slice());
  637. }
  638. }
  639. }
  640. MessageDialog
  641. {
  642. id: pluginInstallDialog
  643. title: catalog.i18nc("@window:title", "Install Plugin");
  644. standardButtons: StandardButton.Ok
  645. modality: Qt.ApplicationModal
  646. }
  647. MessageDialog {
  648. id: infoMultipleFilesWithGcodeDialog
  649. title: catalog.i18nc("@title:window", "Open File(s)")
  650. icon: StandardIcon.Information
  651. standardButtons: StandardButton.Ok
  652. 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.")
  653. property var selectedMultipleFiles
  654. property var hasProjectFile
  655. property var fileUrls
  656. property var projectFileUrlList
  657. onAccepted:
  658. {
  659. openDialog.handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrls, projectFileUrlList);
  660. }
  661. }
  662. Connections
  663. {
  664. target: Cura.Actions.open
  665. onTriggered: openDialog.open()
  666. }
  667. OpenFilesIncludingProjectsDialog
  668. {
  669. id: openFilesIncludingProjectsDialog
  670. }
  671. AskOpenAsProjectOrModelsDialog
  672. {
  673. id: askOpenAsProjectOrModelsDialog
  674. }
  675. EngineLog
  676. {
  677. id: engineLog;
  678. }
  679. Connections
  680. {
  681. target: Cura.Actions.showProfileFolder
  682. onTriggered:
  683. {
  684. var path = UM.Resources.getPath(UM.Resources.Preferences, "");
  685. if(Qt.platform.os == "windows") {
  686. path = path.replace(/\\/g,"/");
  687. }
  688. Qt.openUrlExternally(path);
  689. }
  690. }
  691. AddMachineDialog
  692. {
  693. id: addMachineDialog
  694. onMachineAdded:
  695. {
  696. machineActionsWizard.firstRun = addMachineDialog.firstRun
  697. machineActionsWizard.start(id)
  698. }
  699. }
  700. // Dialog to handle first run machine actions
  701. UM.Wizard
  702. {
  703. id: machineActionsWizard;
  704. title: catalog.i18nc("@title:window", "Add Printer")
  705. property var machine;
  706. function start(id)
  707. {
  708. var actions = Cura.MachineActionManager.getFirstStartActions(id)
  709. resetPages() // Remove previous pages
  710. for (var i = 0; i < actions.length; i++)
  711. {
  712. actions[i].displayItem.reset()
  713. machineActionsWizard.appendPage(actions[i].displayItem, catalog.i18nc("@title", actions[i].label));
  714. }
  715. //Only start if there are actions to perform.
  716. if (actions.length > 0)
  717. {
  718. machineActionsWizard.currentPage = 0;
  719. show()
  720. }
  721. }
  722. }
  723. MessageDialog
  724. {
  725. id: messageDialog
  726. modality: Qt.ApplicationModal
  727. onAccepted: CuraApplication.messageBoxClosed(clickedButton)
  728. onApply: CuraApplication.messageBoxClosed(clickedButton)
  729. onDiscard: CuraApplication.messageBoxClosed(clickedButton)
  730. onHelp: CuraApplication.messageBoxClosed(clickedButton)
  731. onNo: CuraApplication.messageBoxClosed(clickedButton)
  732. onRejected: CuraApplication.messageBoxClosed(clickedButton)
  733. onReset: CuraApplication.messageBoxClosed(clickedButton)
  734. onYes: CuraApplication.messageBoxClosed(clickedButton)
  735. }
  736. Connections
  737. {
  738. target: Printer
  739. onShowMessageBox:
  740. {
  741. messageDialog.title = title
  742. messageDialog.text = text
  743. messageDialog.informativeText = informativeText
  744. messageDialog.detailedText = detailedText
  745. messageDialog.standardButtons = buttons
  746. messageDialog.icon = icon
  747. messageDialog.visible = true
  748. }
  749. }
  750. DiscardOrKeepProfileChangesDialog
  751. {
  752. id: discardOrKeepProfileChangesDialog
  753. }
  754. Connections
  755. {
  756. target: Printer
  757. onShowDiscardOrKeepProfileChanges:
  758. {
  759. discardOrKeepProfileChangesDialog.show()
  760. }
  761. }
  762. Connections
  763. {
  764. target: Cura.Actions.addMachine
  765. onTriggered: addMachineDialog.visible = true;
  766. }
  767. AboutDialog
  768. {
  769. id: aboutDialog
  770. }
  771. Connections
  772. {
  773. target: Cura.Actions.about
  774. onTriggered: aboutDialog.visible = true;
  775. }
  776. Connections
  777. {
  778. target: Printer
  779. onRequestAddPrinter:
  780. {
  781. addMachineDialog.visible = true
  782. addMachineDialog.firstRun = false
  783. }
  784. }
  785. Timer
  786. {
  787. id: startupTimer;
  788. interval: 100;
  789. repeat: false;
  790. running: true;
  791. onTriggered:
  792. {
  793. if(!base.visible)
  794. {
  795. base.visible = true;
  796. restart();
  797. }
  798. else if(Cura.MachineManager.activeMachineId == null || Cura.MachineManager.activeMachineId == "")
  799. {
  800. addMachineDialog.open();
  801. }
  802. }
  803. }
  804. }