Files
Plugin/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGHandProfileImpl.cpp
T

273 lines
8.0 KiB
C++
Raw Normal View History

2022-11-02 22:43:14 +01:00
/**
* @file
*
* @author Mamadou Babaei <mamadou@senseglove.com>
*
* @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/SGHandProfileImpl.h"
#include <string>
#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()
:
#if SG_CPP17
2022-11-02 22:43:14 +01:00
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
#else
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}))
#endif /* SG_CPP17 */
2022-11-02 22:43:14 +01:00
{
}
FSGHandProfileImpl::FSGHandProfileImpl(const bool bRightHanded,
const FSGSenseGloveHandProfileImpl& SenseGloveHandProfile,
const FSGNovaGloveHandProfileImpl& NovaGloveHandProfile)
:
#if SG_CPP17
2022-11-02 22:43:14 +01:00
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
#else
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}))
#endif /* SG_CPP17 */
2022-11-02 22:43:14 +01:00
{
Pimpl->HandProfile = FHandProfileType(
bRightHanded, SenseGloveHandProfile.ToSenseGloveHandProfile(), NovaGloveHandProfile.ToNovaGloveHandProfile());
}
FSGHandProfileImpl::FSGHandProfileImpl(const FHandProfileType& SenseGloveHandProfile)
:
#if SG_CPP17
2022-11-02 22:43:14 +01:00
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
#else
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}))
#endif /* SG_CPP17 */
2022-11-02 22:43:14 +01:00
{
Pimpl->HandProfile = SenseGloveHandProfile;
}
FSGHandProfileImpl::FSGHandProfileImpl(const FSGHandProfileImpl& Rhs)
:
#if SG_CPP17
2022-11-02 22:43:14 +01:00
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{*Rhs.Pimpl}, PimplDeleter))
#else
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{*Rhs.Pimpl}))
#endif /* SG_CPP17 */
2022-11-02 22:43:14 +01:00
{
Pimpl->Owner = this;
}
FSGHandProfileImpl::FSGHandProfileImpl(FSGHandProfileImpl&& Rhs)
#if SG_CPP17
noexcept
#endif /* SG_CPP17 */
= default;
2022-11-02 22:43:14 +01:00
FSGHandProfileImpl::~FSGHandProfileImpl() = default;
FSGHandProfileImpl& FSGHandProfileImpl::operator=(const FSGHandProfileImpl& Rhs)
{
*Pimpl = *Rhs.Pimpl;
Pimpl->Owner = this;
return *this;
}
FSGHandProfileImpl& FSGHandProfileImpl::operator=(FSGHandProfileImpl&& Rhs)
#if SG_CPP17
noexcept
#endif /* SG_CPP17 */
2022-11-02 22:43:14 +01:00
= default;
const FSGHandProfileImpl::FHandProfileType& FSGHandProfileImpl::ToHandProfile(
) const
{
return Pimpl->HandProfile;
}
bool FSGHandProfileImpl::IsRight() const
{
return Pimpl->HandProfile.IsRight();
}
void FSGHandProfileImpl::SetIsRight(const bool bRightHanded) const
{
Pimpl->HandProfile.SetIsRight(bRightHanded);
}
FSGSenseGloveHandProfileImpl FSGHandProfileImpl::GetSenseGloveHandProfile() const
{
return FSGSenseGloveHandProfileImpl(Pimpl->HandProfile.GetSenseGloveHandProfile());
}
void FSGHandProfileImpl::SetSenseGloveHandProfile(const FSGSenseGloveHandProfileImpl& SenseGloveHandProfile)
{
Pimpl->HandProfile.SetSenseGloveHandProfile(SenseGloveHandProfile.ToSenseGloveHandProfile());
}
FSGNovaGloveHandProfileImpl FSGHandProfileImpl::GetNovaGloveHandProfile() const
{
return FSGNovaGloveHandProfileImpl(Pimpl->HandProfile.GetNovaGloveHandProfile());
}
void FSGHandProfileImpl::SetNovaGloveHandProfile(const FSGNovaGloveHandProfileImpl& NovaGloveHandProfile)
{
Pimpl->HandProfile.SetNovaGloveHandProfile(NovaGloveHandProfile.ToNovaGloveHandProfile());
}
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;
}