/** * @file * * @author Mamadou Babaei * * @section LICENSE * * (The MIT License) * * Copyright (c) 2020 - 2022 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/SGSenseGloveHandProfileImpl.h" #include #include #include "Containers/StringConv.h" #include "Runtime/Launch/Resources/Version.h" #include "SGBuildHacks/SGInclude_Core_HandInterpolator.h" #include "SGBuildHacks/SGInclude_Core_Quat.h" #include "SGBuildHacks/SGInclude_Core_Vect3D.h" #include "SGCoreImpl/SGCoreEnumCast.h" #include "SGCoreImpl/SGHandInterpolatorImpl.h" #include "SGCoreImpl/SGVect3DImpl.h" #include "SGUtils/SGArrayUtils.h" struct FSGSenseGloveHandProfileImpl::FImpl { /************************ * Member variables ************************/ FSenseGloveHandProfileType SenseGloveHandProfile; /************************ * Owner object ************************/ FSGSenseGloveHandProfileImpl* Owner; /************************ * Constructor / Destructor ************************/ explicit FImpl(FSGSenseGloveHandProfileImpl* InOwner); ~FImpl(); /************************ * Default copy constructor & copy assignment operator ************************/ FImpl(const FImpl& Rhs) = default; FImpl& operator=(const FImpl& Rhs) = default; }; FSGSenseGloveHandProfileImpl FSGSenseGloveHandProfileImpl::Default(const bool bRightHanded) { FSGSenseGloveHandProfileImpl SenseGloveHandProfileImpl(FSenseGloveHandProfileType::Default(bRightHanded)); return SenseGloveHandProfileImpl; } FSGSenseGloveHandProfileImpl FSGSenseGloveHandProfileImpl::Deserialize(const FString& SerializedString) { std::string Serialized(TCHAR_TO_UTF8(*SerializedString)); const FSGSenseGloveHandProfileImpl HandProfile(FSenseGloveHandProfileType::Deserialize(MoveTemp(Serialized))); return HandProfile; } const FVector& FSGSenseGloveHandProfileImpl::GetDefaultThimbleOffset() { static const FVector DefaultThimbleOffset( FSGVect3DImpl(FSenseGloveHandProfileType::GetDefaultThimbleOffset()).ToFVector()); return DefaultThimbleOffset; } FSGSenseGloveHandProfileImpl::FSGSenseGloveHandProfileImpl() : #if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 && SG_CPP17 ) Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) #else Pimpl(TUniquePtr(new FImpl{this})) #endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 && SG_CPP17 ) */ { } FSGSenseGloveHandProfileImpl::FSGSenseGloveHandProfileImpl(const bool bRightHanded, const FSGHandInterpolatorImpl& Interpolator, const ESGThumbSolver ThumbSolver, const ESGFingerSolver FingerSolver, const TArray& FingerThimbleOffset) : #if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 && SG_CPP17 ) Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) #else Pimpl(TUniquePtr(new FImpl{this})) #endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 && SG_CPP17 ) */ { std::vector FingerThimbleOffsetVector{ FSGArrayUtils::ToMillimeters(FingerThimbleOffset) }; Pimpl->SenseGloveHandProfile = FSenseGloveHandProfileType( bRightHanded, Interpolator.ToHandInterpolator(), FSGCoreEnumCast::ToEThumbSolver(ThumbSolver), FSGCoreEnumCast::ToEFingerSolver(FingerSolver), MoveTemp(FingerThimbleOffsetVector)); } FSGSenseGloveHandProfileImpl::FSGSenseGloveHandProfileImpl(const FSenseGloveHandProfileType& SenseGloveHandProfile) : #if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 && SG_CPP17 ) Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) #else Pimpl(TUniquePtr(new FImpl{this})) #endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 && SG_CPP17 ) */ { Pimpl->SenseGloveHandProfile = SenseGloveHandProfile; } FSGSenseGloveHandProfileImpl::FSGSenseGloveHandProfileImpl(const FSGSenseGloveHandProfileImpl& Rhs) : #if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 && SG_CPP17 ) Pimpl(TUniquePtr(new FImpl{*Rhs.Pimpl}, PimplDeleter)) #else Pimpl(TUniquePtr(new FImpl{*Rhs.Pimpl})) #endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 && SG_CPP17 ) */ { Pimpl->Owner = this; } FSGSenseGloveHandProfileImpl::FSGSenseGloveHandProfileImpl(FSGSenseGloveHandProfileImpl&& Rhs) #if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 && SG_CPP17 ) noexcept #endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 && SG_CPP17 ) */ = default; FSGSenseGloveHandProfileImpl::~FSGSenseGloveHandProfileImpl() = default; FSGSenseGloveHandProfileImpl& FSGSenseGloveHandProfileImpl::operator=(const FSGSenseGloveHandProfileImpl& Rhs) { *Pimpl = *Rhs.Pimpl; Pimpl->Owner = this; return *this; } FSGSenseGloveHandProfileImpl& FSGSenseGloveHandProfileImpl::operator=(FSGSenseGloveHandProfileImpl&& Rhs) #if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 && SG_CPP17 ) noexcept #endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 && SG_CPP17 ) */ = default; const FSGSenseGloveHandProfileImpl::FSenseGloveHandProfileType& FSGSenseGloveHandProfileImpl::ToSenseGloveHandProfile( ) const { return Pimpl->SenseGloveHandProfile; } bool FSGSenseGloveHandProfileImpl::IsRight() const { return Pimpl->SenseGloveHandProfile.IsRight(); } void FSGSenseGloveHandProfileImpl::SetIsRight(const bool bRightHanded) { Pimpl->SenseGloveHandProfile.SetIsRight(bRightHanded); } FSGHandInterpolatorImpl FSGSenseGloveHandProfileImpl::GetInterpolationSet() const { const FSGHandInterpolatorImpl HandInterpolatorImpl( FSGHandInterpolatorImpl::FHandInterpolatorType(Pimpl->SenseGloveHandProfile.GetInterpolationSet())); return HandInterpolatorImpl; } void FSGSenseGloveHandProfileImpl::SetInterpolationSet(const FSGHandInterpolatorImpl& InterpolationSet) { Pimpl->SenseGloveHandProfile.SetInterpolationSet(InterpolationSet.ToHandInterpolator()); } ESGThumbSolver FSGSenseGloveHandProfileImpl::GetThumbSolver() const { return FSGCoreEnumCast::ToESGThumbSolver(Pimpl->SenseGloveHandProfile.GetThumbSolver()); } void FSGSenseGloveHandProfileImpl::SetThumbSolver(const ESGThumbSolver ThumbSolver) { Pimpl->SenseGloveHandProfile.SetThumbSolver(FSGCoreEnumCast::ToEThumbSolver(ThumbSolver)); } ESGFingerSolver FSGSenseGloveHandProfileImpl::GetFingerSolver() const { return FSGCoreEnumCast::ToESGFingerSolver(Pimpl->SenseGloveHandProfile.GetFingerSolver()); } void FSGSenseGloveHandProfileImpl::SetFingerSolver(const ESGFingerSolver FingerSolver) { Pimpl->SenseGloveHandProfile.SetFingerSolver(FSGCoreEnumCast::ToEFingerSolver(FingerSolver)); } TArray FSGSenseGloveHandProfileImpl::GetFingerThimbleOffset() const { const TArray FingerThimbleOffset{ FSGArrayUtils::FromMillimeters( Pimpl->SenseGloveHandProfile.GetFingerThimbleOffset()) }; return FingerThimbleOffset; } void FSGSenseGloveHandProfileImpl::SetFingerThimbleOffset(const TArray& FingerThimbleOffset) { std::vector FingerThimbleOffsetVector{ FSGArrayUtils::ToMillimeters(FingerThimbleOffset) }; Pimpl->SenseGloveHandProfile.SetFingerThimbleOffset(MoveTemp(FingerThimbleOffsetVector)); } bool FSGSenseGloveHandProfileImpl::Equals(const FSGSenseGloveHandProfileImpl& SenseGloveHandProfileImpl) const { return Pimpl->SenseGloveHandProfile.Equals(SenseGloveHandProfileImpl.ToSenseGloveHandProfile()); } void FSGSenseGloveHandProfileImpl::Reset() { Pimpl->SenseGloveHandProfile.Reset(); } FString FSGSenseGloveHandProfileImpl::Serialize() const { const FString Serialized(UTF8_TO_TCHAR(Pimpl->SenseGloveHandProfile.Serialize().c_str())); return Serialized; } FSGSenseGloveHandProfileImpl::FImpl::FImpl(FSGSenseGloveHandProfileImpl* InOwner) : Owner(InOwner) { } FSGSenseGloveHandProfileImpl::FImpl::~FImpl() = default; void FSGSenseGloveHandProfileImpl::FImplDeleter::operator()(const FImpl* P) const { delete P; }