/**
 * fSpy
 * Copyright (c) 2020 - Per Gantelius
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */ import * as React from 'react' ; import { connect } from 'react-redux' ; import { Dispatch } from 'redux' ; import { AppAction , setCalibrationMode , setImageOpacity , setPrincipalPointMode1VP , setPrincipalPointMode2VP , setQuadModeEnabled , setReferenceDistanceUnit , setReferenceDistance , setReferenceDistanceAxis , setCameraPreset , setCameraSensorSize , setFirstVanishingPointAxis , setSecondVanishingPointAxis , setAbsoluteFocalLength1VP , setOverlay3DGuide } from '../actions' ; import SettingsPanel from '../components/settings-panel/settings-panel' ; import { CalibrationMode , GlobalSettings , Overlay3DGuide } from '../types/global-settings' ; import { StoreState } from '../types/store-state' ; import { CalibrationSettings1VP , CalibrationSettings2VP , PrincipalPointMode1VP , PrincipalPointMode2VP , Axis , ReferenceDistanceUnit , CalibrationSettingsBase } from '../types/calibration-settings' ; export interface SettingsContainerProps { isVisible : boolean ; globalSettings : GlobalSettings ; calibrationSettingsBase : CalibrationSettingsBase ; calibrationSettings1VP : CalibrationSettings1VP ; calibrationSettings2VP : CalibrationSettings2VP ; onCalibrationModeChange ( calibrationMode ) : void ; onImageOpacityChange ( opacity ) : void ; onOverlay3DGuideChange ( overlay3DGuide ) : void ; onPrincipalPointModeChange1VP ( principalPointMode ) : void ; onPrincipalPointModeChange2VP ( principalPointMode ) : void ; onQuadModeEnabledChange ( quadModeEnabled ) : void ; onFirstVanishingPointAxisChange ( axis ) : void ; onSecondVanishingPointAxisChange ( axis ) : void ; onAbsoluteFocalLengthChange1VP ( absoluteFocalLength ) : void ; onReferenceDistanceAxisChange ( axis ) : void ; onReferenceDistanceUnitChange ( unit ) : void ; onReferenceDistanceChange ( distance ) : void ; onCameraPresetChange ( cameraPreset ) : void ; onSensorSizeChange ( width , height ) : void ; } class SettingsContainer extends React . PureComponent < SettingsContainerProps > { render ( ) { if ( ! this . props . isVisible ) { return null ; } return ( < SettingsPanel { ... this . props } / > ) ; } } export function mapStateToProps ( state ) { return { globalSettings : state . globalSettings , calibrationSettingsBase : state . calibrationSettingsBase , calibrationSettings1VP : state . calibrationSettings1VP , calibrationSettings2VP : state . calibrationSettings2VP } ; } export function mapDispatchToProps ( dispatch ) { return { onCalibrationModeChange : ( calibrationMode ) => { dispatch ( setCalibrationMode ( calibrationMode ) ) ; } , onImageOpacityChange : ( opacity ) => { dispatch ( setImageOpacity ( opacity ) ) ; } , onOverlay3DGuideChange : ( overlay3DGuide ) => { dispatch ( setOverlay3DGuide ( overlay3DGuide ) ) ; } , onPrincipalPointModeChange1VP : ( principalPointMode ) => { dispatch ( setPrincipalPointMode1VP ( principalPointMode ) ) ; } , onPrincipalPointModeChange2VP : ( principalPointMode ) => { dispatch ( setPrincipalPointMode2VP ( principalPointMode ) ) ; } , onQuadModeEnabledChange : ( quadModeEnabled ) => { dispatch ( setQuadModeEnabled ( quadModeEnabled ) ) ; } , onFirstVanishingPointAxisChange : ( axis ) => { dispatch ( setFirstVanishingPointAxis ( axis ) ) ; } , onSecondVanishingPointAxisChange : ( axis ) => { dispatch ( setSecondVanishingPointAxis ( axis ) ) ; } , onAbsoluteFocalLengthChange1VP : ( absoluteFocalLength ) => { dispatch ( setAbsoluteFocalLength1VP ( absoluteFocalLength ) ) ; } , onReferenceDistanceAxisChange : ( axis ) => { dispatch ( setReferenceDistanceAxis ( axis ) ) ; } , onReferenceDistanceUnitChange : ( unit ) => { dispatch ( setReferenceDistanceUnit ( unit ) ) ; } , onReferenceDistanceChange : ( distance ) => { dispatch ( setReferenceDistance ( distance ) ) ; } , onCameraPresetChange : ( cameraPreset ) => { dispatch ( setCameraPreset ( cameraPreset ) ) ; } , onSensorSizeChange : ( width , height ) => { dispatch ( setCameraSensorSize ( width , height ) ) ; } } ; } export default connect ( mapStateToProps , mapDispatchToProps ) ( SettingsContainer ) ;