Cura.qml 32 KB

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