Cura.qml 32 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. 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. BuildplateMenu { title: catalog.i18nc("@title:menu", "&Build plate"); visible: Cura.MachineManager.hasVariantBuildplates }
  177. NozzleMenu { title: Cura.MachineManager.activeDefinitionVariantsName; visible: machineExtruderCount.properties.value <= 1 && Cura.MachineManager.hasVariants }
  178. MaterialMenu { title: catalog.i18nc("@title:menu", "&Material"); visible: machineExtruderCount.properties.value <= 1 && Cura.MachineManager.hasMaterials }
  179. ProfileMenu { title: catalog.i18nc("@title:menu", "&Profile"); visible: machineExtruderCount.properties.value <= 1 }
  180. MenuSeparator { }
  181. MenuItem { action: Cura.Actions.configureSettingVisibility }
  182. }
  183. Menu
  184. {
  185. id: extension_menu
  186. title: catalog.i18nc("@title:menu menubar:toplevel","E&xtensions");
  187. Instantiator
  188. {
  189. id: extensions
  190. model: UM.ExtensionModel { }
  191. Menu
  192. {
  193. id: sub_menu
  194. title: model.name;
  195. visible: actions != null
  196. enabled: actions != null
  197. Instantiator
  198. {
  199. model: actions
  200. MenuItem
  201. {
  202. text: model.text
  203. onTriggered: extensions.model.subMenuTriggered(name, model.text)
  204. }
  205. onObjectAdded: sub_menu.insertItem(index, object)
  206. onObjectRemoved: sub_menu.removeItem(object)
  207. }
  208. }
  209. onObjectAdded: extension_menu.insertItem(index, object)
  210. onObjectRemoved: extension_menu.removeItem(object)
  211. }
  212. }
  213. Menu
  214. {
  215. id: plugin_menu
  216. title: catalog.i18nc("@title:menu menubar:toplevel", "P&lugins")
  217. MenuItem { action: Cura.Actions.browsePlugins }
  218. MenuItem { action: Cura.Actions.configurePlugins }
  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. }
  410. UM.MessageStack
  411. {
  412. anchors
  413. {
  414. horizontalCenter: parent.horizontalCenter
  415. horizontalCenterOffset: -(Math.floor(UM.Theme.getSize("sidebar").width/ 2))
  416. top: parent.verticalCenter;
  417. bottom: parent.bottom;
  418. }
  419. }
  420. }
  421. }
  422. // Expand or collapse sidebar
  423. Connections
  424. {
  425. target: Cura.Actions.expandSidebar
  426. onTriggered: sidebar.callExpandOrCollapse()
  427. }
  428. UM.PreferencesDialog
  429. {
  430. id: preferences
  431. Component.onCompleted:
  432. {
  433. //; Remove & re-add the general page as we want to use our own instead of uranium standard.
  434. removePage(0);
  435. insertPage(0, catalog.i18nc("@title:tab","General"), Qt.resolvedUrl("Preferences/GeneralPage.qml"));
  436. removePage(1);
  437. insertPage(1, catalog.i18nc("@title:tab","Settings"), Qt.resolvedUrl("Preferences/SettingVisibilityPage.qml"));
  438. insertPage(2, catalog.i18nc("@title:tab", "Printers"), Qt.resolvedUrl("Preferences/MachinesPage.qml"));
  439. insertPage(3, catalog.i18nc("@title:tab", "Materials"), Qt.resolvedUrl("Preferences/MaterialsPage.qml"));
  440. insertPage(4, catalog.i18nc("@title:tab", "Profiles"), Qt.resolvedUrl("Preferences/ProfilesPage.qml"));
  441. //Force refresh
  442. setPage(0);
  443. }
  444. onVisibleChanged:
  445. {
  446. // When the dialog closes, switch to the General page.
  447. // This prevents us from having a heavy page like Setting Visiblity active in the background.
  448. setPage(0);
  449. }
  450. }
  451. WorkspaceSummaryDialog
  452. {
  453. id: saveWorkspaceDialog
  454. onYes: UM.OutputDeviceManager.requestWriteToDevice("local_file", PrintInformation.jobName, { "filter_by_machine": false, "file_type": "workspace" })
  455. }
  456. Connections
  457. {
  458. target: Cura.Actions.preferences
  459. onTriggered: preferences.visible = true
  460. }
  461. Connections
  462. {
  463. target: CuraApplication
  464. onShowPreferencesWindow: preferences.visible = true
  465. }
  466. MessageDialog
  467. {
  468. id: newProjectDialog
  469. modality: Qt.ApplicationModal
  470. title: catalog.i18nc("@title:window", "New project")
  471. 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.")
  472. standardButtons: StandardButton.Yes | StandardButton.No
  473. icon: StandardIcon.Question
  474. onYes:
  475. {
  476. CuraApplication.deleteAll();
  477. Cura.Actions.resetProfile.trigger();
  478. }
  479. }
  480. Connections
  481. {
  482. target: Cura.Actions.newProject
  483. onTriggered:
  484. {
  485. if(Printer.platformActivity || Cura.MachineManager.hasUserSettings)
  486. {
  487. newProjectDialog.visible = true
  488. }
  489. }
  490. }
  491. Connections
  492. {
  493. target: Cura.Actions.addProfile
  494. onTriggered:
  495. {
  496. preferences.show();
  497. preferences.setPage(4);
  498. // Create a new profile after a very short delay so the preference page has time to initiate
  499. createProfileTimer.start();
  500. }
  501. }
  502. Connections
  503. {
  504. target: Cura.Actions.configureMachines
  505. onTriggered:
  506. {
  507. preferences.visible = true;
  508. preferences.setPage(2);
  509. }
  510. }
  511. Connections
  512. {
  513. target: Cura.Actions.manageProfiles
  514. onTriggered:
  515. {
  516. preferences.visible = true;
  517. preferences.setPage(4);
  518. }
  519. }
  520. Connections
  521. {
  522. target: Cura.Actions.manageMaterials
  523. onTriggered:
  524. {
  525. preferences.visible = true;
  526. preferences.setPage(3)
  527. }
  528. }
  529. Connections
  530. {
  531. target: Cura.Actions.configureSettingVisibility
  532. onTriggered:
  533. {
  534. preferences.visible = true;
  535. preferences.setPage(1);
  536. preferences.getCurrentItem().scrollToSection(source.key);
  537. }
  538. }
  539. // show the installed plugins page in the preferences dialog
  540. Connections
  541. {
  542. target: Cura.Actions.configurePlugins
  543. onTriggered:
  544. {
  545. preferences.visible = true
  546. preferences.setPage(5)
  547. }
  548. }
  549. UM.ExtensionModel {
  550. id: curaExtensions
  551. }
  552. // show the plugin browser dialog
  553. Connections
  554. {
  555. target: Cura.Actions.browsePlugins
  556. onTriggered: {
  557. curaExtensions.callExtensionMethod("Plugin Browser", "browsePlugins")
  558. }
  559. }
  560. Timer
  561. {
  562. id: createProfileTimer
  563. repeat: false
  564. interval: 1
  565. onTriggered: preferences.getCurrentItem().createProfile()
  566. }
  567. // BlurSettings is a way to force the focus away from any of the setting items.
  568. // We need to do this in order to keep the bindings intact.
  569. Connections
  570. {
  571. target: Cura.MachineManager
  572. onBlurSettings:
  573. {
  574. contentItem.forceActiveFocus()
  575. }
  576. }
  577. ContextMenu {
  578. id: contextMenu
  579. }
  580. Connections
  581. {
  582. target: Cura.Actions.quit
  583. onTriggered: CuraApplication.closeApplication();
  584. }
  585. Connections
  586. {
  587. target: Cura.Actions.toggleFullScreen
  588. onTriggered: base.toggleFullscreen();
  589. }
  590. FileDialog
  591. {
  592. id: openDialog;
  593. //: File open dialog title
  594. title: catalog.i18nc("@title:window","Open file(s)")
  595. modality: UM.Application.platform == "linux" ? Qt.NonModal : Qt.WindowModal;
  596. selectMultiple: true
  597. nameFilters: UM.MeshFileHandler.supportedReadFileTypes;
  598. folder: CuraApplication.getDefaultPath("dialog_load_path")
  599. onAccepted:
  600. {
  601. // Because several implementations of the file dialog only update the folder
  602. // when it is explicitly set.
  603. var f = folder;
  604. folder = f;
  605. CuraApplication.setDefaultPath("dialog_load_path", folder);
  606. handleOpenFileUrls(fileUrls);
  607. }
  608. // Yeah... I know... it is a mess to put all those things here.
  609. // There are lots of user interactions in this part of the logic, such as showing a warning dialog here and there,
  610. // etc. This means it will come back and forth from time to time between QML and Python. So, separating the logic
  611. // and view here may require more effort but make things more difficult to understand.
  612. function handleOpenFileUrls(fileUrlList)
  613. {
  614. // look for valid project files
  615. var projectFileUrlList = [];
  616. var hasGcode = false;
  617. var nonGcodeFileList = [];
  618. for (var i in fileUrlList)
  619. {
  620. var endsWithG = /\.g$/;
  621. var endsWithGcode = /\.gcode$/;
  622. if (endsWithG.test(fileUrlList[i]) || endsWithGcode.test(fileUrlList[i]))
  623. {
  624. continue;
  625. }
  626. else if (CuraApplication.checkIsValidProjectFile(fileUrlList[i]))
  627. {
  628. projectFileUrlList.push(fileUrlList[i]);
  629. }
  630. nonGcodeFileList.push(fileUrlList[i]);
  631. }
  632. hasGcode = nonGcodeFileList.length < fileUrlList.length;
  633. // show a warning if selected multiple files together with Gcode
  634. var hasProjectFile = projectFileUrlList.length > 0;
  635. var selectedMultipleFiles = fileUrlList.length > 1;
  636. if (selectedMultipleFiles && hasGcode)
  637. {
  638. infoMultipleFilesWithGcodeDialog.selectedMultipleFiles = selectedMultipleFiles;
  639. infoMultipleFilesWithGcodeDialog.hasProjectFile = hasProjectFile;
  640. infoMultipleFilesWithGcodeDialog.fileUrls = nonGcodeFileList.slice();
  641. infoMultipleFilesWithGcodeDialog.projectFileUrlList = projectFileUrlList.slice();
  642. infoMultipleFilesWithGcodeDialog.open();
  643. }
  644. else
  645. {
  646. handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrlList, projectFileUrlList);
  647. }
  648. }
  649. function handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrlList, projectFileUrlList)
  650. {
  651. // we only allow opening one project file
  652. if (selectedMultipleFiles && hasProjectFile)
  653. {
  654. openFilesIncludingProjectsDialog.fileUrls = fileUrlList.slice();
  655. openFilesIncludingProjectsDialog.show();
  656. return;
  657. }
  658. if (hasProjectFile)
  659. {
  660. var projectFile = projectFileUrlList[0];
  661. // check preference
  662. var choice = UM.Preferences.getValue("cura/choice_on_open_project");
  663. if (choice == "open_as_project")
  664. {
  665. openFilesIncludingProjectsDialog.loadProjectFile(projectFile);
  666. }
  667. else if (choice == "open_as_model")
  668. {
  669. openFilesIncludingProjectsDialog.loadModelFiles([projectFile].slice());
  670. }
  671. else // always ask
  672. {
  673. // ask whether to open as project or as models
  674. askOpenAsProjectOrModelsDialog.fileUrl = projectFile;
  675. askOpenAsProjectOrModelsDialog.show();
  676. }
  677. }
  678. else
  679. {
  680. openFilesIncludingProjectsDialog.loadModelFiles(fileUrlList.slice());
  681. }
  682. }
  683. }
  684. MessageDialog
  685. {
  686. id: pluginInstallDialog
  687. title: catalog.i18nc("@window:title", "Install Plugin");
  688. standardButtons: StandardButton.Ok
  689. modality: Qt.ApplicationModal
  690. }
  691. MessageDialog {
  692. id: infoMultipleFilesWithGcodeDialog
  693. title: catalog.i18nc("@title:window", "Open File(s)")
  694. icon: StandardIcon.Information
  695. standardButtons: StandardButton.Ok
  696. 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.")
  697. property var selectedMultipleFiles
  698. property var hasProjectFile
  699. property var fileUrls
  700. property var projectFileUrlList
  701. onAccepted:
  702. {
  703. openDialog.handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrls, projectFileUrlList);
  704. }
  705. }
  706. Connections
  707. {
  708. target: Cura.Actions.open
  709. onTriggered: openDialog.open()
  710. }
  711. OpenFilesIncludingProjectsDialog
  712. {
  713. id: openFilesIncludingProjectsDialog
  714. }
  715. AskOpenAsProjectOrModelsDialog
  716. {
  717. id: askOpenAsProjectOrModelsDialog
  718. }
  719. EngineLog
  720. {
  721. id: engineLog;
  722. }
  723. Connections
  724. {
  725. target: Cura.Actions.showProfileFolder
  726. onTriggered:
  727. {
  728. var path = UM.Resources.getPath(UM.Resources.Preferences, "");
  729. if(Qt.platform.os == "windows") {
  730. path = path.replace(/\\/g,"/");
  731. }
  732. Qt.openUrlExternally(path);
  733. }
  734. }
  735. AddMachineDialog
  736. {
  737. id: addMachineDialog
  738. onMachineAdded:
  739. {
  740. machineActionsWizard.firstRun = addMachineDialog.firstRun
  741. machineActionsWizard.start(id)
  742. }
  743. }
  744. // Dialog to handle first run machine actions
  745. UM.Wizard
  746. {
  747. id: machineActionsWizard;
  748. title: catalog.i18nc("@title:window", "Add Printer")
  749. property var machine;
  750. function start(id)
  751. {
  752. var actions = Cura.MachineActionManager.getFirstStartActions(id)
  753. resetPages() // Remove previous pages
  754. for (var i = 0; i < actions.length; i++)
  755. {
  756. actions[i].displayItem.reset()
  757. machineActionsWizard.appendPage(actions[i].displayItem, catalog.i18nc("@title", actions[i].label));
  758. }
  759. //Only start if there are actions to perform.
  760. if (actions.length > 0)
  761. {
  762. machineActionsWizard.currentPage = 0;
  763. show()
  764. }
  765. }
  766. }
  767. MessageDialog
  768. {
  769. id: messageDialog
  770. modality: Qt.ApplicationModal
  771. onAccepted: CuraApplication.messageBoxClosed(clickedButton)
  772. onApply: CuraApplication.messageBoxClosed(clickedButton)
  773. onDiscard: CuraApplication.messageBoxClosed(clickedButton)
  774. onHelp: CuraApplication.messageBoxClosed(clickedButton)
  775. onNo: CuraApplication.messageBoxClosed(clickedButton)
  776. onRejected: CuraApplication.messageBoxClosed(clickedButton)
  777. onReset: CuraApplication.messageBoxClosed(clickedButton)
  778. onYes: CuraApplication.messageBoxClosed(clickedButton)
  779. }
  780. Connections
  781. {
  782. target: CuraApplication
  783. onShowMessageBox:
  784. {
  785. messageDialog.title = title
  786. messageDialog.text = text
  787. messageDialog.informativeText = informativeText
  788. messageDialog.detailedText = detailedText
  789. messageDialog.standardButtons = buttons
  790. messageDialog.icon = icon
  791. messageDialog.visible = true
  792. }
  793. }
  794. DiscardOrKeepProfileChangesDialog
  795. {
  796. id: discardOrKeepProfileChangesDialog
  797. }
  798. Connections
  799. {
  800. target: CuraApplication
  801. onShowDiscardOrKeepProfileChanges:
  802. {
  803. discardOrKeepProfileChangesDialog.show()
  804. }
  805. }
  806. Connections
  807. {
  808. target: Cura.Actions.addMachine
  809. onTriggered: addMachineDialog.visible = true;
  810. }
  811. AboutDialog
  812. {
  813. id: aboutDialog
  814. }
  815. Connections
  816. {
  817. target: Cura.Actions.about
  818. onTriggered: aboutDialog.visible = true;
  819. }
  820. Connections
  821. {
  822. target: CuraApplication
  823. onRequestAddPrinter:
  824. {
  825. addMachineDialog.visible = true
  826. addMachineDialog.firstRun = false
  827. }
  828. }
  829. Timer
  830. {
  831. id: startupTimer;
  832. interval: 100;
  833. repeat: false;
  834. running: true;
  835. onTriggered:
  836. {
  837. if(!base.visible)
  838. {
  839. base.visible = true;
  840. }
  841. // check later if the user agreement dialog has been closed
  842. if (CuraApplication.needToShowUserAgreement)
  843. {
  844. restart();
  845. }
  846. else if(Cura.MachineManager.activeMachineId == null || Cura.MachineManager.activeMachineId == "")
  847. {
  848. addMachineDialog.open();
  849. }
  850. }
  851. }
  852. }