Cura.qml 32 KB

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