Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to group extended PTZ commands in sub menues. #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion AddCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1513,9 +1513,22 @@ private void DdlPtzSelectedIndexChanged(object sender, EventArgs e)
CameraControl.PTZ.PTZSettings = ptz;
if (ptz.ExtendedCommands?.Command != null)
{
string subMenu = "", PTZ_SUBMENU_START = " ";
foreach (var extcmd in ptz.ExtendedCommands.Command)
{
lbExtended.Items.Add(new ListItem(extcmd.Name, extcmd.Value));
if ((extcmd.Value ?? "") != "")
{
lbExtended.Items.Add(new ListItem(subMenu + extcmd.Name, extcmd.Value));
}
else if ((extcmd.Name ?? MainForm.PTZ_SUBMENU_END) != MainForm.PTZ_SUBMENU_END)
{
lbExtended.Items.Add(new ListItem(subMenu + extcmd.Name + MainForm.PTZ_SUBMENU_NAME_SUFFIX, extcmd.Value));
subMenu = subMenu + PTZ_SUBMENU_START;
}
else
{
subMenu = subMenu.Substring(Math.Min(PTZ_SUBMENU_START.Length, subMenu.Length));
}
}
}
if (_loaded)
Expand Down
7 changes: 5 additions & 2 deletions Controls/CameraWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1798,8 +1798,11 @@ private void CheckPTZSchedule()
ptz.ExtendedCommands?.Command?.FirstOrDefault(p => p.Name == entry1.command);
if (extcmd != null)
{
Calibrating = true;
PTZ.SendPTZCommand(extcmd.Value);
if ((extcmd.Value ?? "") != "")
{
Calibrating = true;
PTZ.SendPTZCommand(extcmd.Value);
}
}
}
}
Expand Down
15 changes: 14 additions & 1 deletion Controls/PTZScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,22 @@ private void PTZScheduler_Load(object sender, EventArgs e)
CameraControl.PTZ.PTZSettings = ptz;
if (ptz.ExtendedCommands != null && ptz.ExtendedCommands.Command != null)
{
string subMenu = "", PTZ_SUBMENU_START = " ";
foreach (var extcmd in ptz.ExtendedCommands.Command)
{
ddlScheduleCommand.Items.Add(new MainForm.ListItem3(extcmd.Name, extcmd.Value));
if ((extcmd.Value ?? "") != "")
{
ddlScheduleCommand.Items.Add(new MainForm.ListItem3(subMenu + extcmd.Name, extcmd.Value));
}
else if ((extcmd.Name ?? MainForm.PTZ_SUBMENU_END) != MainForm.PTZ_SUBMENU_END)
{
ddlScheduleCommand.Items.Add(new MainForm.ListItem3(subMenu + extcmd.Name + MainForm.PTZ_SUBMENU_NAME_SUFFIX, extcmd.Value));
subMenu = subMenu + PTZ_SUBMENU_START;
}
else
{
subMenu = subMenu.Substring(Math.Min(PTZ_SUBMENU_START.Length, subMenu.Length));
}
}
}
}
Expand Down
19 changes: 16 additions & 3 deletions Controls/PTZTracking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,25 @@ private void PTZTracking_Load(object sender, EventArgs e)
CameraControl.PTZ.PTZSettings = ptz;
if (ptz.ExtendedCommands != null && ptz.ExtendedCommands.Command != null)
{
string subMenu = "", PTZ_SUBMENU_START = " ";
foreach (var extcmd in ptz.ExtendedCommands.Command)
{
ddlHomeCommand.Items.Add(new MainForm.ListItem3(extcmd.Name, extcmd.Value));
if (CameraControl.Camobject.settings.ptzautohomecommand == extcmd.Value)
if ((extcmd.Value ?? "") != "")
{
ddlHomeCommand.SelectedIndex = ddlHomeCommand.Items.Count - 1;
ddlHomeCommand.Items.Add(new MainForm.ListItem3(subMenu + extcmd.Name, extcmd.Value));
if (CameraControl.Camobject.settings.ptzautohomecommand == extcmd.Value)
{
ddlHomeCommand.SelectedIndex = ddlHomeCommand.Items.Count - 1;
}
}
else if ((extcmd.Name ?? MainForm.PTZ_SUBMENU_END) != MainForm.PTZ_SUBMENU_END)
{
ddlHomeCommand.Items.Add(new MainForm.ListItem3(subMenu + extcmd.Name + MainForm.PTZ_SUBMENU_NAME_SUFFIX, extcmd.Value));
subMenu = subMenu + PTZ_SUBMENU_START;
}
else
{
subMenu = subMenu.Substring(Math.Min(PTZ_SUBMENU_START.Length, subMenu.Length));
}
}
}
Expand Down
23 changes: 20 additions & 3 deletions MainForm_Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public partial class MainForm
private static List<objectsCommand> _remotecommands;
private static List<objectsCamera> _cameras;

public static string PTZ_SUBMENU_END = "..";
public static string PTZ_SUBMENU_NAME_SUFFIX = " >>";

public static void ReloadColors()
{
_backColor =
Expand Down Expand Up @@ -3515,16 +3518,30 @@ private void CameraControlMouseDown(object sender, MouseEventArgs e)
PTZSettings2Camera ptz = PTZs.SingleOrDefault(p => p.id == cameraControl.Camobject.ptz);
if (ptz?.ExtendedCommands?.Command != null)
{
var subMenus = new List<ToolStripItemCollection>() {
pTZToolStripMenuItem.DropDownItems
};

foreach (var extcmd in ptz.ExtendedCommands.Command)
{
ToolStripItem tsi = new ToolStripMenuItem
ToolStripMenuItem tsi = new ToolStripMenuItem
{
Text = extcmd.Name,
Tag =
cameraControl.Camobject.id + "|" + extcmd.Value
};
tsi.Click += TsiClick;
pTZToolStripMenuItem.DropDownItems.Add(tsi);
if ((extcmd.Value ?? "") != "")
{
tsi.Click += TsiClick;
subMenus[0].Add(tsi);
}
else if ((extcmd.Name ?? PTZ_SUBMENU_END) != PTZ_SUBMENU_END)
{
subMenus[0].Add(tsi);
subMenus.Insert(0, tsi.DropDownItems); // PTZ_SUBMENU_START
}
else if (subMenus.Count > 1)
subMenus.RemoveAt(0);
}
}
}
Expand Down
15 changes: 14 additions & 1 deletion PTZTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,22 @@ public CameraWindow CameraControl
PTZSettings2Camera ptz = MainForm.PTZs.Single(p => p.id == CameraControl.Camobject.ptz);
if (ptz.ExtendedCommands != null && ptz.ExtendedCommands.Command!=null)
{
string subMenu = "", PTZ_SUBMENU_START = " ";
foreach (var extcmd in ptz.ExtendedCommands.Command)
{
ddlExtended.Items.Add(new ListItem(extcmd.Name, extcmd.Value));
if ((extcmd.Value ?? "") != "")
{
ddlExtended.Items.Add(new ListItem(subMenu + extcmd.Name, extcmd.Value));
}
else if ((extcmd.Name ?? MainForm.PTZ_SUBMENU_END) != MainForm.PTZ_SUBMENU_END)
{
ddlExtended.Items.Add(new ListItem(subMenu + extcmd.Name + MainForm.PTZ_SUBMENU_NAME_SUFFIX, extcmd.Value));
subMenu = subMenu + PTZ_SUBMENU_START;
}
else
{
subMenu = subMenu.Substring(Math.Min(PTZ_SUBMENU_START.Length, subMenu.Length));
}
}
}
pnlController.Enabled = true;
Expand Down
6 changes: 6 additions & 0 deletions XML/PTZ2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@
<ZoomOut>command=16</ZoomOut>
</Commands>
<ExtendedCommands>
<Command Name="Call" />
<Command Name="GO Preset 1">command=31</Command>
<Command Name="GO Preset 2">command=33</Command>
<Command Name="GO Preset 3">command=35</Command>
Expand All @@ -775,6 +776,8 @@
<Command Name="GO Preset 6">command=41</Command>
<Command Name="GO Preset 7">command=43</Command>
<Command Name="GO Preset 8">command=45</Command>
<Command Name=".." />
<Command Name="Save" />
<Command Name="Set Preset 1">command=30</Command>
<Command Name="Set Preset 2">command=32</Command>
<Command Name="Set Preset 3">command=34</Command>
Expand All @@ -783,9 +786,12 @@
<Command Name="Set Preset 6">command=40</Command>
<Command Name="Set Preset 7">command=42</Command>
<Command Name="Set Preset 8">command=44</Command>
<Command Name=".." />
<Command Name="Patrol" />
<Command Name="Stop">command=1</Command>
<Command Name="Start H Patrol">command=20</Command>
<Command Name="Stop H Patrol">command=21</Command>
<Command Name=".." />
<Command Name="Switch ON">command=94</Command>
<Command Name="Switch OFF">command=95</Command>
</ExtendedCommands>
Expand Down