Cura.qml 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986
  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. visible: machineExtruderCount.properties.value > 1
  167. NozzleMenu { title: Cura.MachineManager.activeDefinitionVariantsName; visible: Cura.MachineManager.hasVariants; extruderIndex: index }
  168. MaterialMenu { title: catalog.i18nc("@title:menu", "&Material"); visible: Cura.MachineManager.hasMaterials; extruderIndex: index }
  169. ProfileMenu { title: catalog.i18nc("@title:menu", "&Profile"); }
  170. MenuSeparator { }
  171. MenuItem { text: catalog.i18nc("@action:inmenu", "Set as Active Extruder"); onTriggered: Cura.ExtruderManager.setActiveExtruderIndex(model.index) }
  172. }
  173. onObjectAdded: settingsMenu.insertItem(index, object)
  174. onObjectRemoved: settingsMenu.removeItem(object)
  175. }
  176. NozzleMenu { title: Cura.MachineManager.activeDefinitionVariantsName; visible: machineExtruderCount.properties.value <= 1 && Cura.MachineManager.hasVariants }
  177. MaterialMenu { title: catalog.i18nc("@title:menu", "&Material"); visible: machineExtruderCount.properties.value <= 1 && Cura.MachineManager.hasMaterials }
  178. ProfileMenu { title: catalog.i18nc("@title:menu", "&Profile"); visible: machineExtruderCount.properties.value <= 1 }
  179. MenuSeparator { }
  180. MenuItem { action: Cura.Actions.configureSettingVisibility }
  181. }
  182. Menu
  183. {
  184. id: extension_menu
  185. title: catalog.i18nc("@title:menu menubar:toplevel","E&xtensions");
  186. Instantiator
  187. {
  188. id: extensions
  189. model: UM.ExtensionModel { }
  190. Menu
  191. {
  192. id: sub_menu
  193. title: model.name;
  194. visible: actions != null
  195. enabled: actions != null
  196. Instantiator
  197. {
  198. model: actions
  199. MenuItem
  200. {
  201. text: model.text
  202. onTriggered: extensions.model.subMenuTriggered(name, model.text)
  203. }
  204. onObjectAdded: sub_menu.insertItem(index, object)
  205. onObjectRemoved: sub_menu.removeItem(object)
  206. }
  207. }
  208. onObjectAdded: extension_menu.insertItem(index, object)
  209. onObjectRemoved: extension_menu.removeItem(object)
  210. }
  211. }
  212. Menu
  213. {
  214. id: plugin_menu
  215. title: catalog.i18nc("@title:menu menubar:toplevel", "P&lugins")
  216. MenuItem { action: Cura.Actions.browsePlugins }
  217. MenuItem { action: Cura.Actions.configurePlugins }
  218. }
  219. Menu
  220. {
  221. title: catalog.i18nc("@title:menu menubar:toplevel","P&references");
  222. MenuItem { action: Cura.Actions.preferences; }
  223. }
  224. Menu
  225. {
  226. //: Help menu
  227. title: catalog.i18nc("@title:menu menubar:toplevel","&Help");
  228. MenuItem { action: Cura.Actions.showProfileFolder; }
  229. MenuItem { action: Cura.Actions.documentation; }
  230. MenuItem { action: Cura.Actions.reportBug; }
  231. MenuSeparator { }
  232. MenuItem { action: Cura.Actions.about; }
  233. }
  234. }
  235. UM.SettingPropertyProvider
  236. {
  237. id: machineExtruderCount
  238. containerStackId: Cura.MachineManager.activeMachineId
  239. key: "machine_extruder_count"
  240. watchedProperties: [ "value" ]
  241. storeIndex: 0
  242. }
  243. Item
  244. {
  245. id: contentItem;
  246. y: menu.height
  247. width: parent.width;
  248. height: parent.height - menu.height;
  249. Keys.forwardTo: menu
  250. DropArea
  251. {
  252. anchors.fill: parent;
  253. onDropped:
  254. {
  255. if (drop.urls.length > 0)
  256. {
  257. // As the drop area also supports plugins, first check if it's a plugin that was dropped.
  258. if (drop.urls.length == 1)
  259. {
  260. if (PluginRegistry.isPluginFile(drop.urls[0]))
  261. {
  262. // Try to install plugin & close.
  263. var result = PluginRegistry.installPlugin(drop.urls[0]);
  264. pluginInstallDialog.text = result.message;
  265. if (result.status == "ok")
  266. {
  267. pluginInstallDialog.icon = StandardIcon.Information;
  268. }
  269. else if (result.status == "duplicate")
  270. {
  271. pluginInstallDialog.icon = StandardIcon.Warning;
  272. }
  273. else
  274. {
  275. pluginInstallDialog.icon = StandardIcon.Critical;
  276. }
  277. pluginInstallDialog.open();
  278. return;
  279. }
  280. }
  281. openDialog.handleOpenFileUrls(drop.urls);
  282. }
  283. }
  284. }
  285. JobSpecs
  286. {
  287. id: jobSpecs
  288. anchors
  289. {
  290. bottom: parent.bottom;
  291. right: sidebar.left;
  292. bottomMargin: UM.Theme.getSize("default_margin").height;
  293. rightMargin: UM.Theme.getSize("default_margin").width;
  294. }
  295. }
  296. Button
  297. {
  298. id: openFileButton;
  299. text: catalog.i18nc("@action:button","Open File");
  300. iconSource: UM.Theme.getIcon("load")
  301. style: UM.Theme.styles.tool_button
  302. tooltip: ""
  303. anchors
  304. {
  305. top: topbar.bottom;
  306. topMargin: UM.Theme.getSize("default_margin").height;
  307. left: parent.left;
  308. }
  309. action: Cura.Actions.open;
  310. }
  311. Toolbar
  312. {
  313. id: toolbar;
  314. property int mouseX: base.mouseX
  315. property int mouseY: base.mouseY
  316. anchors {
  317. top: openFileButton.bottom;
  318. topMargin: UM.Theme.getSize("window_margin").height;
  319. left: parent.left;
  320. }
  321. }
  322. ObjectsList
  323. {
  324. id: objectsList;
  325. visible: UM.Preferences.getValue("cura/use_multi_build_plate");
  326. anchors
  327. {
  328. bottom: parent.bottom;
  329. left: parent.left;
  330. }
  331. }
  332. Topbar
  333. {
  334. id: topbar
  335. anchors.left: parent.left
  336. anchors.right: parent.right
  337. anchors.top: parent.top
  338. }
  339. Loader
  340. {
  341. id: sidebar
  342. property bool collapsed: false;
  343. property var initialWidth: UM.Theme.getSize("sidebar").width;
  344. function callExpandOrCollapse() {
  345. if (collapsed) {
  346. sidebar.visible = true;
  347. sidebar.initialWidth = UM.Theme.getSize("sidebar").width;
  348. viewportRect = Qt.rect(0, 0, (base.width - sidebar.width) / base.width, 1.0);
  349. expandSidebarAnimation.start();
  350. } else {
  351. viewportRect = Qt.rect(0, 0, 1, 1.0);
  352. collapseSidebarAnimation.start();
  353. }
  354. collapsed = !collapsed;
  355. UM.Preferences.setValue("cura/sidebar_collapsed", collapsed);
  356. }
  357. anchors
  358. {
  359. top: topbar.top
  360. bottom: parent.bottom
  361. }
  362. width: initialWidth
  363. x: base.width - sidebar.width
  364. source: UM.Controller.activeStage.sidebarComponent
  365. NumberAnimation {
  366. id: collapseSidebarAnimation
  367. target: sidebar
  368. properties: "x"
  369. to: base.width
  370. duration: 100
  371. }
  372. NumberAnimation {
  373. id: expandSidebarAnimation
  374. target: sidebar
  375. properties: "x"
  376. to: base.width - sidebar.width
  377. duration: 100
  378. }
  379. Component.onCompleted:
  380. {
  381. var sidebar_collapsed = UM.Preferences.getValue("cura/sidebar_collapsed");
  382. if (sidebar_collapsed)
  383. {
  384. sidebar.collapsed = true;
  385. viewportRect = Qt.rect(0, 0, 1, 1.0)
  386. collapseSidebarAnimation.start();
  387. }
  388. }
  389. }
  390. Loader
  391. {
  392. id: main
  393. anchors
  394. {
  395. top: topbar.bottom
  396. bottom: parent.bottom
  397. left: parent.left
  398. right: sidebar.left
  399. }
  400. MouseArea
  401. {
  402. visible: UM.Controller.activeStage.mainComponent != ""
  403. anchors.fill: parent
  404. acceptedButtons: Qt.AllButtons
  405. onWheel: wheel.accepted = true
  406. }
  407. source: UM.Controller.activeStage.mainComponent
  408. }
  409. UM.MessageStack
  410. {
  411. anchors
  412. {
  413. horizontalCenter: parent.horizontalCenter
  414. horizontalCenterOffset: -(UM.Theme.getSize("sidebar").width/ 2)
  415. top: parent.verticalCenter;
  416. bottom: parent.bottom;
  417. }
  418. }
  419. }
  420. }
  421. // Expand or collapse sidebar
  422. Connections
  423. {
  424. target: Cura.Actions.expandSidebar
  425. onTriggered: sidebar.callExpandOrCollapse()
  426. }
  427. UM.PreferencesDialog
  428. {
  429. id: preferences
  430. Component.onCompleted:
  431. {
  432. //; Remove & re-add the general page as we want to use our own instead of uranium standard.
  433. removePage(0);
  434. insertPage(0, catalog.i18nc("@title:tab","General"), Qt.resolvedUrl("Preferences/GeneralPage.qml"));
  435. removePage(1);
  436. insertPage(1, catalog.i18nc("@title:tab","Settings"), Qt.resolvedUrl("Preferences/SettingVisibilityPage.qml"));
  437. insertPage(2, catalog.i18nc("@title:tab", "Printers"), Qt.resolvedUrl("Preferences/MachinesPage.qml"));
  438. insertPage(3, catalog.i18nc("@title:tab", "Materials"), Qt.resolvedUrl("Preferences/MaterialsPage.qml"));
  439. insertPage(4, catalog.i18nc("@title:tab", "Profiles"), Qt.resolvedUrl("Preferences/ProfilesPage.qml"));
  440. //Force refresh
  441. setPage(0);
  442. }
  443. onVisibleChanged:
  444. {
  445. // When the dialog closes, switch to the General page.
  446. // This prevents us from having a heavy page like Setting Visiblity active in the background.
  447. setPage(0);
  448. }
  449. }
  450. WorkspaceSummaryDialog
  451. {
  452. id: saveWorkspaceDialog
  453. onYes: UM.OutputDeviceManager.requestWriteToDevice("local_file", PrintInformation.jobName, { "filter_by_machine": false, "file_type": "workspace" })
  454. }
  455. Connections
  456. {
  457. target: Cura.Actions.preferences
  458. onTriggered: preferences.visible = true
  459. }
  460. Connections
  461. {
  462. target: CuraApplication
  463. onShowPreferencesWindow: preferences.visible = true
  464. }
  465. MessageDialog
  466. {
  467. id: newProjectDialog
  468. modality: Qt.ApplicationModal
  469. title: catalog.i18nc("@title:window", "New project")
  470. 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.")
  471. standardButtons: StandardButton.Yes | StandardButton.No
  472. icon: StandardIcon.Question
  473. onYes:
  474. {
  475. CuraApplication.deleteAll();
  476. Cura.Actions.resetProfile.trigger();
  477. }
  478. }
  479. Connections
  480. {
  481. target: Cura.Actions.newProject
  482. onTriggered:
  483. {
  484. if(Printer.platformActivity || Cura.MachineManager.hasUserSettings)
  485. {
  486. newProjectDialog.visible = true
  487. }
  488. }
  489. }
  490. Connections
  491. {
  492. target: Cura.Actions.addProfile
  493. onTriggered:
  494. {
  495. preferences.show();
  496. preferences.setPage(4);
  497. // Create a new profile after a very short delay so the preference page has time to initiate
  498. createProfileTimer.start();
  499. }
  500. }
  501. Connections
  502. {
  503. target: Cura.Actions.configureMachines
  504. onTriggered:
  505. {
  506. preferences.visible = true;
  507. preferences.setPage(2);
  508. }
  509. }
  510. Connections
  511. {
  512. target: Cura.Actions.manageProfiles
  513. onTriggered:
  514. {
  515. preferences.visible = true;
  516. preferences.setPage(4);
  517. }
  518. }
  519. Connections
  520. {
  521. target: Cura.Actions.manageMaterials
  522. onTriggered:
  523. {
  524. preferences.visible = true;
  525. preferences.setPage(3)
  526. }
  527. }
  528. Connections
  529. {
  530. target: Cura.Actions.configureSettingVisibility
  531. onTriggered:
  532. {
  533. preferences.visible = true;
  534. preferences.setPage(1);
  535. preferences.getCurrentItem().scrollToSection(source.key);
  536. }
  537. }
  538. // show the installed plugins page in the preferences dialog
  539. Connections
  540. {
  541. target: Cura.Actions.configurePlugins
  542. onTriggered:
  543. {
  544. preferences.visible = true
  545. preferences.setPage(5)
  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. }