Cura.qml 31 KB

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