/** * @file * * @author Mamadou Babaei * * @section LICENSE * * (The MIT License) * * Copyright (c) 2020 - 2024 SenseGlove * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * @section DESCRIPTION * * */ #include "SGCoreImpl/SGHandProfileImpl.h" #include #include "Containers/StringConv.h" #include "Runtime/Launch/Resources/Version.h" #include "SGBuildHacks/SGInclude_Core_HandInterpolator.h" #include "SGBuildHacks/SGInclude_Core_HandProfile.h" #include "SGBuildHacks/SGInclude_Core_NovaGloveHandProfile.h" #include "SGBuildHacks/SGInclude_Core_SenseGloveHandProfile.h" #include "SGCoreImpl/SGNovaGloveHandProfileImpl.h" #include "SGCoreImpl/SGSenseGloveHandProfileImpl.h" struct FSGHandProfileImpl::FImpl { /************************ * Member variables ************************/ FHandProfileType HandProfile; /************************ * Owner object ************************/ FSGHandProfileImpl* Owner; /************************ * Constructor / Destructor ************************/ explicit FImpl(FSGHandProfileImpl* InOwner); ~FImpl(); /************************ * Default copy constructor & copy assignment operator ************************/ FImpl(const FImpl& Rhs) = default; FImpl& operator=(const FImpl& Rhs) = default; }; FSGHandProfileImpl FSGHandProfileImpl::Default(const bool bRightHanded) { return FSGHandProfileImpl(FHandProfileType::Default(bRightHanded)); } FSGHandProfileImpl FSGHandProfileImpl::Deserialize(const FString& SerializedString) { std::string Serialized(TCHAR_TO_UTF8(*SerializedString)); const FSGHandProfileImpl HandProfile(FHandProfileType::Deserialize(MoveTemp(Serialized))); return HandProfile; } const FString& FSGHandProfileImpl::GetProfileDirectory() { static const FString Directory(UTF8_TO_TCHAR(FHandProfileType::GetProfileDirectory().c_str())); return Directory; } const FString& FSGHandProfileImpl::GetLeftHandFileName() { static const FString FileName(UTF8_TO_TCHAR(FHandProfileType::GetLeftHandFileName().c_str())); return FileName; } const FString& FSGHandProfileImpl::GetRightHandFileName() { static const FString FileName(UTF8_TO_TCHAR(FHandProfileType::GetRightHandFileName().c_str())); return FileName; } const FString& FSGHandProfileImpl::GetProfileFileName(const bool bRightHanded) { static const FString FileName(UTF8_TO_TCHAR(FHandProfileType::GetProfileFileName(bRightHanded).c_str())); return FileName; } bool FSGHandProfileImpl::GetLatestProfile(const bool bRightHanded, FSGHandProfileImpl& OutLatestProfile) { FHandProfileType LatestProfile; const bool bResult = FHandProfileType::GetLatestProfile(bRightHanded, LatestProfile); OutLatestProfile = FSGHandProfileImpl(OutLatestProfile); return bResult; } bool FSGHandProfileImpl::StoreProfile(const FSGHandProfileImpl& ProfileToStore) { return FHandProfileType::StoreProfile(ProfileToStore.ToHandProfile()); } bool FSGHandProfileImpl::ResetCalibration(const bool bRightHanded, const bool bOnDisk) { return FHandProfileType::ResetCalibration(bRightHanded, bOnDisk); } void FSGHandProfileImpl::ResetCalibration(const bool bOnDisk) { /// NOTE /// Due to overload method with a default parameter value, the compiler will get confused and stops with the error: /// "call to 'ResetCalibration' is ambiguous" /// So: void (*RC)(bool) = &FHandProfileType::ResetCalibration; RC(bOnDisk); } FSGHandProfileImpl::FSGHandProfileImpl() : Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) { } FSGHandProfileImpl::FSGHandProfileImpl(const bool bRightHanded, const FSGSenseGloveHandProfileImpl& SenseGloveHandProfile, const FSGNovaGloveHandProfileImpl& NovaGloveHandProfile) : Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) { Pimpl->HandProfile = FHandProfileType( bRightHanded, SenseGloveHandProfile.ToSenseGloveHandProfile(), NovaGloveHandProfile.ToNovaGloveHandProfile()); } FSGHandProfileImpl::FSGHandProfileImpl(const FHandProfileType& SenseGloveHandProfile) : Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) { Pimpl->HandProfile = SenseGloveHandProfile; } FSGHandProfileImpl::FSGHandProfileImpl(const FSGHandProfileImpl& Rhs) : Pimpl(TUniquePtr(new FImpl{*Rhs.Pimpl}, PimplDeleter)) { Pimpl->Owner = this; } FSGHandProfileImpl::FSGHandProfileImpl(FSGHandProfileImpl&& Rhs) SG_NOEXCEPT = default; FSGHandProfileImpl::~FSGHandProfileImpl() = default; FSGHandProfileImpl& FSGHandProfileImpl::operator=(const FSGHandProfileImpl& Rhs) { *Pimpl = *Rhs.Pimpl; Pimpl->Owner = this; return *this; } FSGHandProfileImpl& FSGHandProfileImpl::operator=(FSGHandProfileImpl&& Rhs) SG_NOEXCEPT = default; const FSGHandProfileImpl::FHandProfileType& FSGHandProfileImpl::ToHandProfile( ) const { return Pimpl->HandProfile; } bool FSGHandProfileImpl::IsRight() const { return Pimpl->HandProfile.IsRight(); } FSGSenseGloveHandProfileImpl FSGHandProfileImpl::GetSenseGloveHandProfile() const { return FSGSenseGloveHandProfileImpl(Pimpl->HandProfile.GetSenseGloveHandProfile()); } FSGNovaGloveHandProfileImpl FSGHandProfileImpl::GetNovaGloveHandProfile() const { return FSGNovaGloveHandProfileImpl(Pimpl->HandProfile.GetNovaGloveHandProfile()); } bool FSGHandProfileImpl::Equals(const FSGHandProfileImpl& HandProfileImpl) const { return Pimpl->HandProfile.Equals(HandProfileImpl.ToHandProfile()); } void FSGHandProfileImpl::Reset() { Pimpl->HandProfile.Reset(); } FString FSGHandProfileImpl::Serialize() const { const FString Serialized(UTF8_TO_TCHAR(Pimpl->HandProfile.Serialize().c_str())); return Serialized; } FSGHandProfileImpl::FImpl::FImpl(FSGHandProfileImpl* InOwner) : Owner(InOwner) { } FSGHandProfileImpl::FImpl::~FImpl() = default; void FSGHandProfileImpl::FImplDeleter::operator()(const FImpl* P) const { delete P; }