示例#1
0
 // Get camera with specified name
 public Camera GetCamera(string name, Group parent)
 {
     // find the camera
     foreach (Camera camera in InnerList)
     {
         if ((camera.Name == name) && (camera.Parent == parent))
             return camera;
     }
     return null;
 }
示例#2
0
 // Get group with specified name
 public Group GetGroup(string name, Group parent)
 {
     // find the group
     foreach (Group group in InnerList)
     {
         if ((group.Name == name) && (group.Parent == parent))
             return group;
     }
     return null;
 }
示例#3
0
 // Get view with specified name
 public View GetView(string name, Group parent)
 {
     // find the view
     foreach (View view in InnerList)
     {
         if ((view.Name == name) && (view.Parent == parent))
             return view;
     }
     return null;
 }
示例#4
0
        // Load cameras
        private void LoadCameras(XmlTextReader reader, Group parent)
        {
            // load all groups
            while (reader.Name == "Group")
            {
                int	depth = reader.Depth;

                // create new group
                Group group = new Group(reader.GetAttribute("name"));
                group.ID = int.Parse(reader.GetAttribute("id"));
                group.Description = reader.GetAttribute("desc");
                group.Parent = parent;

                // add group
                camerasGroups.Add(group);

                if (group.ID >= nextCamerasGroupID)
                    nextCamerasGroupID = group.ID + 1;

                // move to next node
                reader.Read();

                // move to next element node
                while (reader.NodeType == XmlNodeType.EndElement)
                    reader.Read();
                // read children
                if (reader.Depth > depth)
                    LoadCameras(reader, group);
                //
                if (reader.Depth < depth)
                    return;
            }
            // load all cameras
            while (reader.Name == "Camera")
            {
                int	depth = reader.Depth;

                // create new camera
                Camera camera = new Camera(reader.GetAttribute("name"));

                camera.ID			= int.Parse(reader.GetAttribute("id"));
                camera.Description	= reader.GetAttribute("desc");
                camera.Parent		= parent;
                camera.Provider		= providers.GetProviderByName(reader.GetAttribute("provider"));

                // load configuration
                if (camera.Provider != null)
                    camera.Configuration = camera.Provider.LoadConfiguration(reader);

                // add camera
                cameras.Add(camera);

                if (camera.ID >= nextCameraID)
                    nextCameraID = camera.ID + 1;

                // move to next node
                reader.Read();

                // move to next element node
                while (reader.NodeType == XmlNodeType.EndElement)
                    reader.Read();
                if (reader.Depth < depth)
                    return;
            }
        }
示例#5
0
 // Delete views group
 // delete views group if it is empty or return false otherwise
 public bool DeleteViewsGroup(Group group)
 {
     // check if there are subgroups in the group
     foreach (Group g in viewsGroups)
     {
         if (g.Parent == group)
             return false;
     }
     // check if there are view in the group
     foreach (View v in views)
     {
         if (v.Parent == group)
             return false;
     }
     viewsGroups.Remove(group);
     // save
     SaveViews();
     return true;
 }
示例#6
0
 // Delete cameras group
 // delete cameras group if it is empty or return false otherwise
 public bool DeleteCamerasGroup(Group group)
 {
     // check if there are subgroups in the group
     foreach (Group g in camerasGroups)
     {
         if (g.Parent == group)
             return false;
     }
     // check if there are cameras in the group
     foreach (Camera c in cameras)
     {
         if (c.Parent == group)
             return false;
     }
     camerasGroups.Remove(group);
     // save
     SaveCameras();
     return true;
 }
示例#7
0
 // Check views group
 // check if there is already a group with such name
 // return true, if there is no such group
 public bool CheckViewsGroup(Group group)
 {
     foreach (Group g in viewsGroups)
     {
         if ((group.Name == g.Name) && (group.Parent == g.Parent) && ((group.ID == 0) || (group.ID != g.ID)))
             return false;
     }
     return true;
 }
示例#8
0
 // Ñheck if the cameras group is already exist
 private bool CheckCamerasGroup(Group group)
 {
     return config.CheckCamerasGroup(group);
 }
示例#9
0
        // save views of the parent group
        private void SaveViews(XmlTextWriter writer, Group parent)
        {
            foreach (Group group in viewsGroups)
            {
                if (group.Parent == parent)
                {
                    // new "Group" node
                    writer.WriteStartElement("Group");

                    // write node
                    writer.WriteAttributeString("id", group.ID.ToString());
                    writer.WriteAttributeString("name", group.Name);
                    writer.WriteAttributeString("desc", group.Description);

                    // write child groups
                    SaveViews(writer, group);

                    // close "Group" node
                    writer.WriteEndElement();
                }
            }
            foreach (View view in views)
            {
                if (view.Parent == parent)
                {
                    // new "View" node
                    writer.WriteStartElement("View");

                    // write node
                    writer.WriteAttributeString("id", view.ID.ToString());
                    writer.WriteAttributeString("name", view.Name);
                    writer.WriteAttributeString("desc", view.Description);

                    // view size
                    writer.WriteAttributeString("rows", view.Rows.ToString());
                    writer.WriteAttributeString("cols", view.Cols.ToString());
                    writer.WriteAttributeString("width", view.CellWidth.ToString());
                    writer.WriteAttributeString("height", view.CellHeight.ToString());

                    // write cameras
                    string[] strIDs = new string[View.MaxRows * View.MaxCols];
                    for (int i = 0, k = 0; i < View.MaxRows; i++)
                    {
                        for (int j = 0; j < View.MaxCols; j++, k++)
                        {
                            strIDs[k] = view.GetCamera(i, j).ToString();
                        }
                    }
                    writer.WriteAttributeString("cameras", string.Join(",", strIDs));

                    // close "View" node
                    writer.WriteEndElement();
                }
            }
        }
示例#10
0
 // Build views of specified parent
 private void BuildViewsTree(GroupCollection groups, ViewCollection views, Group parent, TreeNode parentNode)
 {
     // build all groups
     foreach (Group group in groups)
     {
         if (group.Parent == parent)
         {
             BuildViewsTree(groups, views, group, AddViewsGroup(group, parentNode));
         }
     }
     // build all views
     foreach (View view in views)
     {
         if (view.Parent == parent)
         {
             AddView(view, parentNode);
         }
     }
 }
示例#11
0
 // Build cameras of specified parent
 private void BuildCamerasTree(GroupCollection groups, CameraCollection cameras, Group parent, TreeNode parentNode)
 {
     // build all groups
     foreach (Group group in groups)
     {
         if (group.Parent == parent)
         {
             BuildCamerasTree(groups, cameras, group, AddCamerasGroup(group, parentNode));
         }
     }
     // build all cameras
     foreach (Camera camera in cameras)
     {
         if (camera.Parent == parent)
         {
             AddCamera(camera, parentNode);
         }
     }
 }
示例#12
0
        // Add views group
        public TreeNode AddViewsGroup(Group group, TreeNode parentNode)
        {
            // create new node
            TreeNode node = new TreeNode(group.Name, viewsFolderImage, viewsFolderSelectedImage);
            // add it to tree
            parentNode.Nodes.Add(node);

            return node;
        }
示例#13
0
        // Add camera group
        public TreeNode AddCamerasGroup(Group group, TreeNode parentNode)
        {
            // create new node
            TreeNode node = new TreeNode(group.Name, camerasFolderImage, camerasFolderSelectedImage);
            // add it to tree
            if (parentNode == null)
                Nodes.Add(node);
            else
                parentNode.Nodes.Add(node);

            return node;
        }
示例#14
0
 // Remove group from the collection
 public void Remove(Group group)
 {
     InnerList.Remove(group);
 }
示例#15
0
        // Load views
        private void LoadViews(XmlTextReader reader, Group parent)
        {
            // load all groups
            while (reader.Name == "Group")
            {
                int	depth = reader.Depth;

                // create new group
                Group group = new Group(reader.GetAttribute("name"));
                group.ID = int.Parse(reader.GetAttribute("id"));
                group.Description = reader.GetAttribute("desc");
                group.Parent = parent;

                // add group
                viewsGroups.Add(group);

                if (group.ID >= nextViewsGroupID)
                    nextViewsGroupID = group.ID + 1;

                // move to next node
                reader.Read();

                // move to next element node
                while (reader.NodeType == XmlNodeType.EndElement)
                    reader.Read();
                // read children
                if (reader.Depth > depth)
                    LoadViews(reader, group);
                //
                if (reader.Depth < depth)
                    return;
            }
            // load all views
            while (reader.Name == "View")
            {
                int	depth = reader.Depth;

                // create new camera
                View view = new View(reader.GetAttribute("name"));

                view.ID				= int.Parse(reader.GetAttribute("id"));
                view.Description	= reader.GetAttribute("desc");
                view.Parent			= parent;

                // view size
                view.Rows			= short.Parse(reader.GetAttribute("rows"));
                view.Cols			= short.Parse(reader.GetAttribute("cols"));
                view.CellWidth		= short.Parse(reader.GetAttribute("width"));
                view.CellHeight		= short.Parse(reader.GetAttribute("height"));

                // read cameras
                string[] strIDs = reader.GetAttribute("cameras").Split(',');
                for (int i = 0, k = 0; i < View.MaxRows; i++)
                {
                    for (int j = 0; j < View.MaxCols; j++, k++)
                    {
                        view.SetCamera(i, j, int.Parse(strIDs[k]));
                    }
                }

                // add view
                views.Add(view);

                if (view.ID >= nextViewID)
                    nextViewID = view.ID + 1;

                // move to next node
                reader.Read();

                // move to next element node
                while (reader.NodeType == XmlNodeType.EndElement)
                    reader.Read();
                if (reader.Depth < depth)
                    return;
            }
        }
示例#16
0
        // save cameras of the parent group
        private void SaveCameras(XmlTextWriter writer, Group parent)
        {
            foreach (Group group in camerasGroups)
            {
                if (group.Parent == parent)
                {
                    // new "Group" node
                    writer.WriteStartElement("Group");

                    // write node
                    writer.WriteAttributeString("id", group.ID.ToString());
                    writer.WriteAttributeString("name", group.Name);
                    writer.WriteAttributeString("desc", group.Description);

                    // write child groups
                    SaveCameras(writer, group);

                    // close "Group" node
                    writer.WriteEndElement();
                }
            }
            foreach (Camera camera in cameras)
            {
                if (camera.Parent == parent)
                {
                    // new "Camera" node
                    writer.WriteStartElement("Camera");

                    // write node
                    writer.WriteAttributeString("id", camera.ID.ToString());
                    writer.WriteAttributeString("name", camera.Name);
                    writer.WriteAttributeString("desc", camera.Description);

                    if (camera.Provider != null)
                    {
                        // write provider name
                        writer.WriteAttributeString("provider", camera.Provider.ProviderName);

                        if (camera.Configuration != null)
                        {
                            // write camera configuration
                            camera.Provider.SaveConfiguration(writer, camera.Configuration);
                        }
                    }

                    // close "Camera" node
                    writer.WriteEndElement();
                }
            }
        }
示例#17
0
        // On "Ok" button click
        private void okButton_Click(object sender, System.EventArgs e)
        {
            string	name = nameBox.Text.Replace('\\', ' ');

            if (checkGroupFunction != null)
            {
                Group tmpGroup = new Group(name);

                tmpGroup.ID = group.ID;
                tmpGroup.Parent = group.Parent;

                // check group
                if (checkGroupFunction(tmpGroup) == false)
                {
                    Color	tmp = this.nameBox.BackColor;

                    // highligh name edit box
                    this.nameBox.BackColor = Color.LightCoral;
                    // error message
                    MessageBox.Show(this, "A group with such name is already exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    // restore & focus name edit box
                    this.nameBox.BackColor = tmp;
                    this.nameBox.Focus();

                    return;
                }
            }

            // update groups name and description
            group.Name = name;
            group.Description = descriptionBox.Text;

            // close the dialog
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
示例#18
0
        // Add new camera group
        public void AddCamerasGroup(Group group)
        {
            group.ID = nextCamerasGroupID++;
            camerasGroups.Add(group);

            // save
            SaveCameras();
        }
示例#19
0
        // Add new views group
        public void AddViewsGroup(Group group)
        {
            group.ID = nextViewsGroupID++;
            viewsGroups.Add(group);

            // save
            SaveViews();
        }
示例#20
0
 // Ñheck if the views group is already exist
 private bool CheckViewsGroup(Group group)
 {
     return config.CheckViewsGroup(group);
 }
示例#21
0
 // Add new group to the collection
 public void Add(Group group)
 {
     InnerList.Add(group);
 }