Ejemplo n.º 1
0
        private void viewChooseButton_Click(object sender, EventArgs e)
        {
            // Click on 'Choose front/rear...' buttons
            if (camSetDetailsListView.SelectedItems.Count == 1)
            {
                try
                {
                    bool         isForFront = (sender == viewChooseFrontButton);
                    DialogResult dr         = _CamViewSelectorDialog.ShowDialog(this);

                    if (dr == DialogResult.OK)
                    {
                        Cursor = Cursors.WaitCursor;

                        Cameras.ViewType currentViewType = (Cameras.ViewType)Enum.Parse(typeof(Cameras.ViewType), camSetDetailsListView.SelectedItems[0].Tag.ToString());

                        if (_CamViewSelectorDialog.ChosenCameraId == null && _CamViewSelectorDialog.ChosenViewId == null)
                        {
                            // View deletion
                            _RemoveCameraView(customCameraIdLabel.Text, currentViewType, isForFront);
                        }
                        else
                        {
                            // View customization
                            Cameras.ViewType chosenViewType = (Cameras.ViewType)Enum.Parse(typeof(Cameras.ViewType), _CamViewSelectorDialog.ChosenViewId);

                            _CustomizeCameraView(customCameraIdLabel.Text,
                                                 currentViewType,
                                                 _CamViewSelectorDialog.ChosenCameraId,
                                                 chosenViewType, isForFront);
                        }

                        // Refresh
                        _RefreshCameraIKContents();

                        // Modification flag
                        _IsCameraModified = true;

                        StatusBarLogManager.ShowEvent(this, _STATUS_CHOOSING_VIEW_OK);
                    }
                }
                catch (Exception ex)
                {
                    MessageBoxes.ShowError(this, ex);
                }
                finally
                {
                    Cursor = Cursors.Default;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// What the instruction should do
        /// </summary>
        protected void _CommonProcess()
        {
            // Common parameters
            string camId           = _GetParameter(PatchInstructionParameter.ParameterName.cameraIKIdentifier);
            string hoodView        = _GetParameter(PatchInstructionParameter.ParameterName.newHoodView);
            string hoodBackView    = _GetParameter(PatchInstructionParameter.ParameterName.newHoodBackView);
            string cockpitView     = _GetParameter(PatchInstructionParameter.ParameterName.newCockpitView);
            string cockpitBackView = _GetParameter(PatchInstructionParameter.ParameterName.newCockpitBackView);

            // Parameter validation
            string hoodCamId = hoodView.Split(Tools.SYMBOL_VALUE_SEPARATOR)[0];

            Cameras.ViewType hoodViewType  = _ValidateViewType(hoodView.Split(Tools.SYMBOL_VALUE_SEPARATOR)[1]);
            string           hoodBackCamId = hoodBackView.Split(Tools.SYMBOL_VALUE_SEPARATOR)[0];

            Cameras.ViewType hoodBackViewType = _ValidateViewType(hoodBackView.Split(Tools.SYMBOL_VALUE_SEPARATOR)[1]);
            string           cockpitCamId     = cockpitView.Split(Tools.SYMBOL_VALUE_SEPARATOR)[0];

            Cameras.ViewType cockpitViewType  = _ValidateViewType(cockpitView.Split(Tools.SYMBOL_VALUE_SEPARATOR)[1]);
            string           cockpitBackCamId = cockpitBackView.Split(Tools.SYMBOL_VALUE_SEPARATOR)[0];

            Cameras.ViewType cockpitBackViewType = _ValidateViewType(cockpitBackView.Split(Tools.SYMBOL_VALUE_SEPARATOR)[1]);

            // Loading current camera
            string  currentCamFile = LibraryConstants.GetSpecialFile(LibraryConstants.TduSpecialFile.CamerasBin);
            Cameras currentCameras = TduFile.GetFile(currentCamFile) as Cameras;

            if (currentCameras == null || !currentCameras.Exists)
            {
                throw new Exception("Unable to load current camera data: " + currentCamFile);
            }

            // Loading default camera
            Cameras defaultCameras = TduFile.GetFile(camReferenceFilename) as Cameras;

            if (defaultCameras == null || !defaultCameras.Exists)
            {
                throw new Exception("Unable to load new camera data: " + camReferenceFilename);
            }

            // Views
            VehicleSlotsHelper.InitReference(Tools.WorkingPath + LibraryConstants.FOLDER_XML);

            _Customize(currentCameras, defaultCameras, camId, Cameras.ViewType.Hood, hoodCamId, hoodViewType);
            _Customize(currentCameras, defaultCameras, camId, Cameras.ViewType.Hood_Back, hoodBackCamId, hoodBackViewType);
            _Customize(currentCameras, defaultCameras, camId, Cameras.ViewType.Cockpit, cockpitCamId, cockpitViewType);
            _Customize(currentCameras, defaultCameras, camId, Cameras.ViewType.Cockpit_Back, cockpitBackCamId, cockpitBackViewType);

            // Saving
            currentCameras.Save();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Removes specified view from camera
        /// </summary>
        /// <param name="cameraId"></param>
        /// <param name="viewType"></param>
        /// <param name="isForFront"></param>
        private void _RemoveCameraView(string cameraId, Cameras.ViewType viewType, bool isForFront)
        {
            if (!string.IsNullOrEmpty(cameraId) && viewType != Cameras.ViewType.Unknown)
            {
                // Getting entry
                Cameras.CamEntry currentEntry = _CameraData.GetEntryByCameraId(cameraId);

                if (currentEntry.isValid)
                {
                    Cameras.ViewType currentViewType = (isForFront ? viewType : viewType + 20);

                    _CameraData.RemoveView(currentEntry, currentViewType);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sets new view on a custom camera
        /// </summary>
        /// <param name="cameraId"></param>
        /// <param name="viewType"></param>
        /// <param name="newCameraId"></param>
        /// <param name="newViewType"></param>
        /// <param name="isForFront"></param>
        private void _CustomizeCameraView(string cameraId, Cameras.ViewType viewType, string newCameraId, Cameras.ViewType newViewType, bool isForFront)
        {
            if (!string.IsNullOrEmpty(cameraId) && !string.IsNullOrEmpty(newCameraId))
            {
                // Getting entry
                Cameras.CamEntry currentEntry = _CameraData.GetEntryByCameraId(cameraId);

                if (currentEntry.isValid)
                {
                    // Goal is to replace current view (front or back one) with specified
                    Cameras.CamEntry baseEntry       = VehicleSlotsHelper.DefaultCameras.GetEntryByCameraId(newCameraId);
                    Cameras.ViewType currentViewType = (isForFront ? viewType : viewType + 20);

                    if (baseEntry.isValid)
                    {
                        VehicleSlotsHelper.CustomizeCameraView(_CameraData, currentEntry, currentViewType, baseEntry, newViewType);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns label for custom view
        /// </summary>
        /// <param name="view"></param>
        /// <returns></returns>
        private static string _GetCustomViewLabel(Cameras.View view)
        {
            string returnedLabel = _LABEL_DEFAULT_CAM_VIEW;

            if (view.isValid)
            {
                // Getting view information
                ushort           parentCameraId = view.parentCameraId;
                ushort           cameraId       = view.cameraId;
                Cameras.ViewType viewType       = view.type;

                if (parentCameraId != 0)
                {
                    cameraId = view.parentCameraId;
                    viewType = view.parentType;
                }

                string parentVehicleName = null;

                if (VehicleSlotsHelper.CamReference.ContainsKey(cameraId.ToString()))
                {
                    parentVehicleName = VehicleSlotsHelper.CamReference[cameraId.ToString()];
                }
                else if (VehicleSlotsHelper.NewCamReference.ContainsKey(cameraId.ToString()))
                {
                    parentVehicleName = VehicleSlotsHelper.NewCamReference[cameraId.ToString()];
                }

                if (parentVehicleName != null)
                {
                    returnedLabel = string.Format(_FORMAT_CAM_VIEW, parentVehicleName, viewType);
                }
            }

            return(returnedLabel);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Changes camera source and/or target position(s)
        /// </summary>
        /// <param name="cameraData"></param>
        /// <param name="entry"></param>
        /// <param name="viewType"></param>
        /// <param name="sourcePosition"></param>
        /// <param name="targetPosition"></param>
        public static void CustomizeCameraPosition(Cameras cameraData, Cameras.CamEntry entry, Cameras.ViewType viewType, Cameras.Position sourcePosition, Cameras.Position targetPosition)
        {
            if (cameraData != null)
            {
                Cameras.View baseView = Cameras.GetViewByType(entry, viewType);

                if (baseView.isValid)
                {
                    List <Cameras.View> currentViews = entry.views;

                    currentViews.Remove(baseView);

                    baseView.source = sourcePosition;
                    baseView.target = targetPosition;

                    currentViews.Add(baseView);
                    entry.views = currentViews;

                    // Updating entry
                    cameraData.UpdateEntry(entry);
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Replaces specified camera view with data taken into another one. If view does not exist, it is created then added to entry.
        /// </summary>
        /// <param name="cameraData"></param>
        /// <param name="currentEntry"></param>
        /// <param name="currentViewType"></param>
        /// <param name="baseEntry"></param>
        /// <param name="baseViewType"></param>
        public static void CustomizeCameraView(Cameras cameraData, Cameras.CamEntry currentEntry, Cameras.ViewType currentViewType, Cameras.CamEntry baseEntry, Cameras.ViewType baseViewType)
        {
            if (cameraData != null)
            {
                Cameras.View baseView      = Cameras.GetViewByType(baseEntry, baseViewType);
                Cameras.View viewToReplace = Cameras.GetViewByType(currentEntry, currentViewType);

                if (baseView.isValid)
                {
                    Cameras.View newView = baseView;

                    newView.cameraId = currentEntry.id;
                    // Set to empty to get enough place
                    newView.name           = "";
                    newView.parentCameraId = baseView.cameraId;
                    newView.parentType     = baseView.type;
                    newView.type           = currentViewType;

                    if (viewToReplace.isValid)
                    {
                        // Replace mode : searching for view to replace
                        List <Cameras.View> currentViews = currentEntry.views;

                        if (currentViews.Contains(viewToReplace))
                        {
                            currentViews.Remove(viewToReplace);
                        }

                        currentViews.Add(newView);
                        currentEntry.views = currentViews;
                    }
                    else
                    {
                        // Add mode >>> disabled if view count bigger than original one :(
                        ushort originalViewCount = cameraData.Index[newView.cameraId];

                        if (currentEntry.views.Count + 1 > originalViewCount)
                        {
                            throw new Exception("You can't add views for now... hope that'll be solved in the future.");
                        }

                        currentEntry.views.Add(newView);
                    }

                    // Updating entry
                    cameraData.UpdateEntry(currentEntry);
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Customizes specified camera view
        /// </summary>
        /// <param name="currentData"></param>
        /// <param name="defaultData"></param>
        /// <param name="camToChange"></param>
        /// <param name="viewToChange"></param>
        /// <param name="camIdToTake"></param>
        /// <param name="viewToTake"></param>
        private static void _Customize(Cameras currentData, Cameras defaultData, string camToChange, Cameras.ViewType viewToChange, string camIdToTake, Cameras.ViewType viewToTake)
        {
            Cameras.CamEntry entryToChange = currentData.GetEntryByCameraId(camToChange);
            Cameras.CamEntry entryToTake   = defaultData.GetEntryByCameraId(camIdToTake);

            VehicleSlotsHelper.CustomizeCameraView(currentData, entryToChange, viewToChange, entryToTake, viewToTake);
        }