コード例 #1
0
        private void LoadControl(OSAE.OSAEObject obj)
        {
            Dispatcher.Invoke((Action)(() =>
            {
                string sStateMatch = "";

                if (obj.Type == "CONTROL USER SELECTOR")
                {
                    userSelectorControl = new UserSelector(obj, gAppName);
                  //  userSelectorControl.MouseRightButtonDown += new MouseButtonEventHandler(State_Image_MouseRightButtonDown);
                    userSelectorControl.Location.X = Double.Parse(obj.Property("X").Value);
                    userSelectorControl.Location.Y = Double.Parse(obj.Property("Y").Value);
                    userSelectorControl._ScreenLocation = gAppLocation;
                    canGUI.Children.Add(userSelectorControl);
                    Canvas.SetLeft(userSelectorControl, userSelectorControl.Location.X * gWidthRatio);
                    Canvas.SetTop(userSelectorControl, userSelectorControl.Location.Y * gHeightRatio);
                    Canvas.SetZIndex(userSelectorControl, 5);
                    controlTypes.Add(typeof(UserSelector));
                    userSelectorControl.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                }
                else if (obj.Type == "CONTROL SCREEN OBJECTS")
                {
                    screenObjectControl = new ScreenObjectList(obj,gCurrentScreen,gCurrentUser);
              //      screenObjectControl.MouseRightButtonDown += new MouseButtonEventHandler(State_Image_MouseRightButtonDown);
                    screenObjectControl.Location.X = Double.Parse(obj.Property("X").Value);
                    screenObjectControl.Location.Y = Double.Parse(obj.Property("Y").Value);
                    screenObjectControl._ScreenLocation = gAppLocation;
                    screenObjectControl.Visibility = System.Windows.Visibility.Hidden;

                    canGUI.Children.Add(screenObjectControl);
                    Canvas.SetLeft(screenObjectControl, screenObjectControl.Location.X * gWidthRatio);
                    Canvas.SetTop(screenObjectControl, screenObjectControl.Location.Y * gHeightRatio);
                    Canvas.SetZIndex(screenObjectControl, 5);
                    screenObjectControl.ControlWidth = screenObjectControl.Width;
                    screenObjectControl.ControlHeight = screenObjectControl.Height;
                    controlTypes.Add(typeof(ScreenObjectList));
                    screenObjectControl.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                }
                else if (obj.Type == "CONTROL STATE IMAGE")
                {
                    StateImage stateImageControl = new StateImage(obj, gAppName);

                    foreach (OSAE.OSAEObjectProperty p in obj.Properties)
                    {
                        try
                        {
                            if (p.Value.ToLower() == stateImageControl.CurState.ToLower())
                                sStateMatch = p.Name.Substring(0, p.Name.LastIndexOf(' '));
                        }
                        catch (Exception ex)
                        {
                            Log.Error("Error finding object ", ex);
                            return;
                        }
                    }
                    try
                    {
                        int dZ = Int32.Parse(obj.Property("ZOrder").Value);
                        stateImageControl.MouseRightButtonDown += new MouseButtonEventHandler(State_Image_MouseRightButtonDown);
                        stateImageControl.Location.X = Double.Parse(obj.Property(sStateMatch + " X").Value);
                        stateImageControl.Location.Y = Double.Parse(obj.Property(sStateMatch + " Y").Value);
                        double dOpacity = Convert.ToDouble(stateImageControl.LightLevel) / 100.00;
                        //Opacity is new and unknow in 044
                        stateImageControl.Opacity = dOpacity;
                        canGUI.Children.Add(stateImageControl);
                        Canvas.SetLeft(stateImageControl, stateImageControl.Location.X * gWidthRatio);
                        Canvas.SetTop(stateImageControl, stateImageControl.Location.Y * gHeightRatio);
                        Canvas.SetZIndex(stateImageControl, dZ);
                        stateImageControl.Width = stateImageControl.ImageWidth * gWidthRatio;
                        stateImageControl.Height = stateImageControl.ImageHeight * gHeightRatio;
                        stateImages.Add(stateImageControl);
                        controlTypes.Add(typeof(StateImage));
                        stateImageControl.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Error updating screenObject", ex);
                        return;
                    }
                }
                else if (obj.Type == "CONTROL PROPERTY LABEL")
                {
                    if (gDebug) Log.Debug("Loading PropertyLabelControl: " + obj.Name);
                    try
                    {
                        PropertyLabel pl = new PropertyLabel(obj);
                        pl.MouseRightButtonDown += new MouseButtonEventHandler(Property_Label_MouseRightButtonDown);
                        canGUI.Children.Add(pl);
                        int dZ = Int32.Parse(obj.Property("ZOrder").Value);
                        pl.Location.X = Double.Parse(obj.Property("X").Value);
                        pl.Location.Y = Double.Parse(obj.Property("Y").Value);
                        Canvas.SetLeft(pl, pl.Location.X * gWidthRatio);
                        Canvas.SetTop(pl, pl.Location.Y * gHeightRatio);
                        Canvas.SetZIndex(pl, dZ);
                        propLabels.Add(pl);
                        controlTypes.Add(typeof(PropertyLabel));
                        pl.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Error updating PropertyLabelControl", ex);
                        return;
                    }
                }
                else if (obj.Type == "CONTROL STATIC LABEL")
                {
                    if (gDebug) Log.Debug("Loading PropertyLabelControl: " + obj.Name);
                    try
                    {

                        OSAE.UI.Controls.StaticLabel sl = new OSAE.UI.Controls.StaticLabel(obj);
                        canGUI.Children.Add(sl);
                        int dZ = Int32.Parse(obj.Property("ZOrder").Value);
                        sl.Location.X = Double.Parse(obj.Property("X").Value);
                        sl.Location.Y = Double.Parse(obj.Property("Y").Value);
                        Canvas.SetLeft(sl, sl.Location.X * gWidthRatio);
                        Canvas.SetTop(sl, sl.Location.Y * gHeightRatio);
                        Canvas.SetZIndex(sl, dZ);
                        staticLabels.Add(sl);
                        controlTypes.Add(typeof(OSAE.UI.Controls.StaticLabel));
                        sl.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    }
                    catch (Exception ex)
                    {
                            Log.Error("Error updating PropertyLabelControl", ex);
                            return;
                    }
                }
                else if (obj.Type == "CONTROL TIMER LABEL")
                {
                    if (gDebug) Log.Debug("Loading PropertyTimerControl: " + obj.Name);
                    try
                    {

                        OSAE.UI.Controls.TimerLabel tl = new OSAE.UI.Controls.TimerLabel(obj);
                        tl.MouseRightButtonDown += new MouseButtonEventHandler(Timer_Label_MouseRightButtonDown);
                        canGUI.Children.Add(tl);
                        int dZ = Int32.Parse(obj.Property("ZOrder").Value);
                        tl.Location.X = Double.Parse(obj.Property("X").Value);
                        tl.Location.Y = Double.Parse(obj.Property("Y").Value);
                        Canvas.SetLeft(tl, tl.Location.X * gWidthRatio);
                        Canvas.SetTop(tl, tl.Location.Y * gHeightRatio);
                        Canvas.SetZIndex(tl, dZ);
                        timerLabels.Add(tl);
                        controlTypes.Add(typeof(OSAE.UI.Controls.TimerLabel));
                        tl.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Error updating PropertyTimerControl", ex);
                        return;
                    }
                }
                else if (obj.Type == "CONTROL CLICK IMAGE")
                {
                    try
                    {
                        ClickImage ClickImageControl = new ClickImage(obj, gAppName, gCurrentUser);
                        ClickImageControl.MouseRightButtonDown += new MouseButtonEventHandler(Click_Image_MouseRightButtonDown);
                        canGUI.Children.Add(ClickImageControl);
                        double dX = Convert.ToDouble(obj.Property("X").Value);
                        double dY = Convert.ToDouble(obj.Property("Y").Value);
                        int dZ = Convert.ToInt32(obj.Property("ZOrder").Value);
                        Canvas.SetLeft(ClickImageControl, dX * gWidthRatio);
                        Canvas.SetTop(ClickImageControl, dY * gHeightRatio);
                        Canvas.SetZIndex(ClickImageControl, dZ);
                        ClickImageControl.Location.X = dX;
                        ClickImageControl.Location.Y = dY;
                        ClickImageControl.Width = ClickImageControl.ImageWidth * gWidthRatio;
                        ClickImageControl.Height = ClickImageControl.ImageHeight * gHeightRatio;
                        clickImages.Add(ClickImageControl);
                        controlTypes.Add(typeof(ClickImage));
                        ClickImageControl.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    }
                    catch (MySqlException myerror)
                    { MessageBox.Show("GUI Error Load Click Image: " + myerror.Message); }
                }
                else if (obj.Type == "CONTROL NAVIGATION IMAGE")
                {
                    try
                    {
                        NavigationImage navImageControl = new NavigationImage(obj.Property("Screen").Value, obj);
                        navImageControl.MouseLeftButtonUp += new MouseButtonEventHandler(Navigaton_Image_MouseLeftButtonUp);
                        navImageControl.MouseRightButtonDown += new MouseButtonEventHandler(Navigaton_Image_MouseRightButtonDown);
                        canGUI.Children.Add(navImageControl);
                        double dX = Convert.ToDouble(obj.Property("X").Value);
                        double dY = Convert.ToDouble(obj.Property("Y").Value);
                        int dZ = Convert.ToInt32(obj.Property("ZOrder").Value);
                        Canvas.SetLeft(navImageControl, dX * gWidthRatio);
                        Canvas.SetTop(navImageControl, dY * gHeightRatio);
                        Canvas.SetZIndex(navImageControl, dZ);
                        navImageControl.Location.X = dX;
                        navImageControl.Location.Y = dY;
                        navImageControl.Width = navImageControl.ImageWidth * gWidthRatio;
                        navImageControl.Height = navImageControl.ImageHeight * gHeightRatio;
                        navImages.Add(navImageControl);
                        controlTypes.Add(typeof(NavigationImage));
                        navImageControl.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    }
                    catch (MySqlException myerror)
                    { MessageBox.Show("GUI Error Load Navigation Image: " + myerror.Message); }
                }
                else if (obj.Type == "CONTROL CAMERA VIEWER")
                {
                    try
                    {
                        string stream = OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Property("Object Name").Value, "Stream Address").Value;
                        VideoStreamViewer vsv = new VideoStreamViewer(stream, obj, gAppName);
                        vsv.MouseRightButtonDown += new MouseButtonEventHandler(VideoStreamViewer_MouseRightButtonDown);
                        canGUI.Children.Add(vsv);
                        double dX = Convert.ToDouble(obj.Property("X").Value);
                        double dY = Convert.ToDouble(obj.Property("Y").Value);
                        int dZ = Convert.ToInt32(obj.Property("ZOrder").Value);
                        Canvas.SetLeft(vsv, dX * gWidthRatio);
                        Canvas.SetTop(vsv, dY * gHeightRatio);
                        Canvas.SetZIndex(vsv, dZ);
                        vsv.Location.X = dX;
                        vsv.Location.Y = dY;
                        cameraViewers.Add(vsv);
                        controlTypes.Add(typeof(VideoStreamViewer));
                        vsv.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    }
                    catch (MySqlException myerror)
                    { MessageBox.Show("GUI Error Load Camera Viewer: " + myerror.Message); }
                }
                else if (obj.BaseType == "USER CONTROL")
                {
                    string sUCType = obj.Property("Control Type").Value;
                    sUCType = sUCType.Replace("USER CONTROL ", "");
                    OSAE.Types.AvailablePlugin selectedPlugin = GlobalUserControls.OSAEUserControls.AvailablePlugins.Find(sUCType);
                    selectedPlugin.Instance.InitializeMainCtrl(obj, gAppName, gCurrentUser);
                    dynamic uc = new UserControl();
                    uc = selectedPlugin.Instance.mainCtrl;
                    uc.MouseRightButtonDown += new MouseButtonEventHandler(UserControl_MouseRightButtonDown);
                    uc.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    double dX = Convert.ToDouble(obj.Property("X").Value);
                    double dY = Convert.ToDouble(obj.Property("Y").Value);
                    int dZ = Convert.ToInt32(obj.Property("ZOrder").Value);
                    Canvas.SetLeft(uc, dX * gWidthRatio);
                    Canvas.SetTop(uc, dY * gHeightRatio);
                    Canvas.SetZIndex(uc, dZ);
                    uc.setLocation(dX, dY);
                    uc.Width = uc.ControlWidth * gWidthRatio;
                    uc.Height = uc.ControlHeight * gHeightRatio;
                    canGUI.Children.Add(uc);
                    userControls.Add(uc);
                    controlTypes.Add(uc.GetType());
                }
                else if (obj.Type == "CONTROL BROWSER")
                {
                    if (gDebug) Log.Debug("Loading BrowserControl: " + obj.Name);
                    try
                    {
                        OSAE.UI.Controls.BrowserFrame bf = new OSAE.UI.Controls.BrowserFrame(obj);
                        bf.MouseRightButtonDown += new MouseButtonEventHandler(Broswer_Control_MouseRightButtonDown);
                        //OSAE.UI.Controls.StaticLabel sl = new OSAE.UI.Controls.StaticLabel(obj);
                        canGUI.Children.Add(bf);
                        int dZ = Int32.Parse(obj.Property("ZOrder").Value);
                        bf.Location.X = Double.Parse(obj.Property("X").Value);
                        bf.Location.Y = Double.Parse(obj.Property("Y").Value);
                        bf.Width = Double.Parse(obj.Property("Width").Value) * gWidthRatio;
                        bf.Height = Double.Parse(obj.Property("Height").Value) * gHeightRatio;
                        bf.ControlWidth = bf.Width;
                        bf.ControlHeight = bf.Height;
                        Canvas.SetLeft(bf, bf.Location.X * gWidthRatio);
                        Canvas.SetTop(bf, bf.Location.Y * gHeightRatio);
                        Canvas.SetZIndex(bf, dZ);
                        browserFrames.Add(bf);
                        controlTypes.Add(typeof(OSAE.UI.Controls.BrowserFrame));
                        //
                        bf.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Error updating BrowserControl", ex);
                        return;
                    }
                }
            }));
        }