From be5e16f382eddee20b3b2730309a1fb3e8ddcaf0 Mon Sep 17 00:00:00 2001 From: Stuart Buchanan Date: Fri, 9 Feb 2018 17:26:57 +0000 Subject: [PATCH] Factory methods for FG1000 - Use Factories to handle multiple FG1000 calls better. - Fix DirectTo Map center. --- .../Instruments-3d/FG1000/Nasal/FG1000.nas | 28 +++++++++++++++++-- Aircraft/Instruments-3d/FG1000/Nasal/GUI.nas | 7 +++-- .../Interfaces/GenericInterfaceController.nas | 11 ++++++++ .../Nasal/MFDPages/DirectTo/DirectTo.nas | 2 +- gui/menubar.xml | 17 +++++++---- 5 files changed, 53 insertions(+), 12 deletions(-) diff --git a/Aircraft/Instruments-3d/FG1000/Nasal/FG1000.nas b/Aircraft/Instruments-3d/FG1000/Nasal/FG1000.nas index 9140698b7..aa85b9c95 100644 --- a/Aircraft/Instruments-3d/FG1000/Nasal/FG1000.nas +++ b/Aircraft/Instruments-3d/FG1000/Nasal/FG1000.nas @@ -17,6 +17,17 @@ io.load_nasal(nasal_dir ~ '/GUI.nas', "fg1000"); var FG1000 = { +_instance : nil, + +# Factory method +getInstance : func(EIS_Class = nil, EIS_SVG = nil) { + if (FG1000._instance == nil) { + FG1000._instance = FG1000.new(EIS_Class, EIS_SVG); + } + + return FG1000._instance; +}, + new : func(EIS_Class = nil, EIS_SVG = nil) { var obj = { parents : [FG1000], @@ -51,8 +62,18 @@ setEIS : func(EIS_Class, EIS_SVG) { me.EIS_SVG = EIS.SVG; }, -addMFD : func(index, targetcanvas=nil, screenObject=nil) { - if (me.displays[index] != nil) { +getDisplay : func(index) { + return me.displays[index]; +}, + +# Add an MFD, optionally setting the index. Returns the index of the MFD. +addMFD : func(index=nil, targetcanvas=nil, screenObject=nil) { + + if (index == nil) { + index = size(keys(me.displays)); + debug.dump(keys(me.displays)); + print("No index passed. Defaulting to " ~ index); + } else if (me.displays[index] != nil) { print("FG1000 Index " ~ index ~ " already exists!"); return } @@ -68,6 +89,7 @@ addMFD : func(index, targetcanvas=nil, screenObject=nil) { var mfd = fg1000.MFD.new(me, me.EIS_Class, me.EIS_SVG, targetcanvas, index); me.displays[index] = mfd; + return index; }, display : func(index, target_object=nil) { @@ -89,7 +111,7 @@ displayGUI : func(index, scale=1.0) { } var mfd_canvas = me.displays[index].getCanvas(); - var gui = fg1000.GUI.new(mfd_canvas, index, scale); + var gui = fg1000.GUI.new(me.displays[index], mfd_canvas, index, scale); }, getConfigStore : func() { diff --git a/Aircraft/Instruments-3d/FG1000/Nasal/GUI.nas b/Aircraft/Instruments-3d/FG1000/Nasal/GUI.nas index e7eedc94e..0ab4f0dcf 100644 --- a/Aircraft/Instruments-3d/FG1000/Nasal/GUI.nas +++ b/Aircraft/Instruments-3d/FG1000/Nasal/GUI.nas @@ -72,11 +72,11 @@ var GUI = { Id: 12, top_left: [1145, 830], bottom_right: [1200, 875] }, ], - new : func(mfd_canvas, device_id, scale = 1.0) + new : func(mfd, mfd_canvas, device_id, scale = 1.0) { var obj = { parents : [ GUI ], - mfd : nil, + mfd : mfd, eisPublisher : nil, navcomPublisher : nil, navcomUpdater : nil, @@ -171,6 +171,9 @@ var GUI = cleanup : func() { + # Clean up the MFD. Particularly important to stop if picking up + # Emesary notifications. + me.mfd.del(); # Clean up the window itself call(canvas.Window.del, [], me.window); }, diff --git a/Aircraft/Instruments-3d/FG1000/Nasal/Interfaces/GenericInterfaceController.nas b/Aircraft/Instruments-3d/FG1000/Nasal/Interfaces/GenericInterfaceController.nas index c72c21a87..339904b10 100644 --- a/Aircraft/Instruments-3d/FG1000/Nasal/Interfaces/GenericInterfaceController.nas +++ b/Aircraft/Instruments-3d/FG1000/Nasal/Interfaces/GenericInterfaceController.nas @@ -13,6 +13,17 @@ io.load_nasal(nasal_dir ~ 'Interfaces/GenericADCPublisher.nas', "fg1000"); var GenericInterfaceController = { + _instance : nil, + + # Factory method + getInstance : func() { + if (GenericInterfaceController._instance == nil) { + GenericInterfaceController._instance = GenericInterfaceController.new(); + } + + return GenericInterfaceController._instance; + }, + new : func() { var obj = { parents : [GenericInterfaceController], diff --git a/Aircraft/Instruments-3d/FG1000/Nasal/MFDPages/DirectTo/DirectTo.nas b/Aircraft/Instruments-3d/FG1000/Nasal/MFDPages/DirectTo/DirectTo.nas index 0fc3b9bc5..598cdc6a9 100644 --- a/Aircraft/Instruments-3d/FG1000/Nasal/MFDPages/DirectTo/DirectTo.nas +++ b/Aircraft/Instruments-3d/FG1000/Nasal/MFDPages/DirectTo/DirectTo.nas @@ -69,7 +69,7 @@ var DirectTo = # We will use the screen range for zooming. obj.DirectToChart.setRange(8.0); obj.DirectToChart.setScreenRange(300/2.0); - obj.DirectToChart.setTranslation(1045, 485); + obj.DirectToChart.setTranslation(860, 440); obj.DirectToChart.set("clip-frame", canvas.Element.LOCAL); obj.DirectToChart.set("clip", "rect(-160px, 160px, 160px, -160px)"); diff --git a/gui/menubar.xml b/gui/menubar.xml index e4c032ff2..21b95afc2 100644 --- a/gui/menubar.xml +++ b/gui/menubar.xml @@ -827,16 +827,21 @@ nasal