Skip to content

Commit

Permalink
Fixed bug in Search not checking if AP is running.
Browse files Browse the repository at this point in the history
  • Loading branch information
Xio1996 committed Jan 29, 2025
1 parent ba2f31b commit fcdde45
Show file tree
Hide file tree
Showing 7 changed files with 405 additions and 10 deletions.
9 changes: 9 additions & 0 deletions EAACP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@
</Compile>
<Compile Include="Settings.cs" />
<Compile Include="Stellarium.cs" />
<Compile Include="StellariumControl.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="StellariumControl.Designer.cs">
<DependentUpon>StellariumControl.cs</DependentUpon>
</Compile>
<EmbeddedResource Include="Config.resx">
<DependentUpon>Config.cs</DependentUpon>
</EmbeddedResource>
Expand Down Expand Up @@ -161,6 +167,9 @@
<EmbeddedResource Include="SearchResults1.resx">
<DependentUpon>SearchResults1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="StellariumControl.resx">
<DependentUpon>StellariumControl.cs</DependentUpon>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
Expand Down
6 changes: 6 additions & 0 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,12 @@ private void btnSearch_Click(object sender, EventArgs e)
// Store the search results for DSA and Search List display
List<string[]> listOfSearchResults;

if (!IsAPRunning())
{
Speak(AstroPlannerSpeak + " is not running");
return;
}

Speak("Searching");

APGetCmdResult apOut = APGetObjects(5, 2, "", CreateSearchParams(SearchRA, SearchDec));
Expand Down
49 changes: 43 additions & 6 deletions SearchResults1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public partial class SearchResults : Form
DataTable dtUniqueCatalogues = new DataTable();
int totalResults = 0;
string stellariumDSOFilter;
string displayMode = "All";

public frmCP EAACP;

Expand Down Expand Up @@ -143,8 +144,10 @@ private void UpdateSearchInfo(int viewCount)
this.Text = $"Search Results: {totalResults} objects, Current View: {viewCount} objects";
}

private void btnDrawSelection_Click(object sender, EventArgs e)
private void DrawSelectedObjects()
{
displayMode = "Selected";

DataTable Selected = new DataTable();

Selected.Columns.Add("ID");
Expand Down Expand Up @@ -193,19 +196,30 @@ private void btnDrawSelection_Click(object sender, EventArgs e)

Selected.Rows.Add(SelectedRow);
}

Stellarium.DrawObjects(Selected);

UpdateSearchInfo(dgvSearchResults.SelectedRows.Count);
}

private void btnPlotAll_Click(object sender, EventArgs e)
private void btnDrawSelection_Click(object sender, EventArgs e)
{
DrawSelectedObjects();
}

// Stop the catalogues filter from firing
private void ResetCatalogueFilter()
{
cbCataloguesFilter.SelectedIndexChanged -= cbCataloguesFilter_SelectedIndexChanged;
cbCataloguesFilter.SelectedIndex = 0;
cbCataloguesFilter.SelectedIndexChanged += cbCataloguesFilter_SelectedIndexChanged;
}

private void btnPlotAll_Click(object sender, EventArgs e)
{
displayMode = "All";

// Stop the catalogues filter from firing
ResetCatalogueFilter();

// Remove any filtering
dt.DefaultView.RowFilter = "";
Expand Down Expand Up @@ -273,7 +287,19 @@ private void btnOptions_Click(object sender, EventArgs e)
frmOpt.TopMost = true;
if (frmOpt.ShowDialog() == DialogResult.OK)
{

// If the user hs changed the display attributes then update the current plot selection on ext.
switch (displayMode)
{
case "All":
Stellarium.DrawObjects(dt);
break;
case "Filtered":
DrawCatalogueFiltered();
break;
case "Selected":
DrawSelectedObjects();
break;
}
}
}
}
Expand All @@ -293,8 +319,10 @@ private void btnCentreSelected_Click(object sender, EventArgs e)
}
}

private void cbCataloguesFilter_SelectedIndexChanged(object sender, EventArgs e)
private void DrawCatalogueFiltered()
{
displayMode = "Filtered";

string apCatalogue = cbCataloguesFilter.Text;
if (apCatalogue == "All Catalogues")
{
Expand All @@ -311,7 +339,11 @@ private void cbCataloguesFilter_SelectedIndexChanged(object sender, EventArgs e)

UpdateSearchInfo(dv.ToTable().Rows.Count);
}
}

private void cbCataloguesFilter_SelectedIndexChanged(object sender, EventArgs e)
{
DrawCatalogueFiltered();
}

private void btnAllCats_Click(object sender, EventArgs e)
Expand All @@ -331,7 +363,12 @@ private void btnDSOAll_Click(object sender, EventArgs e)

private void btnClearPlot_Click(object sender, EventArgs e)
{
displayMode = "All";
Stellarium.ClearObjects();

// Stop the catalogues filter from firing
ResetCatalogueFilter();

UpdateSearchInfo(0);
}

Expand Down
28 changes: 24 additions & 4 deletions Stellarium.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,34 @@ public string SetStelAction(string sName)
return result;
}

public string GetStelProperty(string sName)
private JsonDocument jsonStellariumProperties=null;

private bool GetStellariumProperties()
{
string sWebServiceURL = $"http://{IPAddress}:{Port}/api/stelproperty/list";
string result = GetRequest(sWebServiceURL);

if (result != "exception")
if (!string.IsNullOrEmpty(result))
{
if (result != "exception")
{
jsonStellariumProperties = JsonDocument.Parse(result);
return true;
}
}

return false;
}

public string GetStelProperty(string sName, bool usePersisted=false)
{
if (!usePersisted || jsonStellariumProperties==null)
{
GetStellariumProperties();
}

if (jsonStellariumProperties != null)
{
JsonDocument jsonStellariumProperties = JsonDocument.Parse(result);
if (jsonStellariumProperties.RootElement.TryGetProperty(sName, out JsonElement property))
{
property.TryGetProperty("value", out JsonElement value);
Expand All @@ -164,7 +184,7 @@ public string GetStelProperty(string sName)
}

sMsg = $"StelProp {sName}, {sMsg}";
return result;
return "";
}

public string SetStelProperty(string sName, string sValue)
Expand Down
169 changes: 169 additions & 0 deletions StellariumControl.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions StellariumControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace EAACP
{
public partial class StellariumControl : Form
{
private Stellarium Stellarium = new Stellarium();

public StellariumControl()
{
InitializeComponent();
}

private void StellariumControl_Load(object sender, EventArgs e)
{
bool bMP;
bool.TryParse(Stellarium.GetStelProperty("actionShow_Planets_ShowMinorBodyMarkers"), out bMP);
}
}
}
Loading

0 comments on commit fcdde45

Please sign in to comment.