Cura.qml 32 KB

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