Base: misc patches

Convenience macros/function (in Interpreter.h)

* FC_PY_GetObject/Callable(), look for callables in a python object,
  which will be used in future patch to improve performance in various
  python observer/features.

* pyCall(WithKeywords)(), helper function to invoke the callable

Matrix4D:

* hasScale(), check if there is any scale in the transformation. If so,
  further check if the scale is uniform or not. This will be used in
  future patch for Part::TopoShape to decide which type of transform to
  apply.

Placement:

* translate/rotate(), new convenience API

Rotation:

* isSame/multiVec(), new convenience API

Polygon2d:

* Intersect(), GetCenter(), new convenience API.

FlagToggler:

* New class for exception safe flag toggling, similar to StateLocker
  but with template (actually, FlagToggler is added earlier by me).

BitsetLocker:

* New class for exception manipulation of a std::bitset variable.
This commit is contained in:
Zheng, Lei
2019-07-06 17:10:17 +08:00
committed by wmayer
parent 59417068f5
commit 3fcbf71fb5
12 changed files with 230 additions and 2 deletions

View File

@@ -187,6 +187,33 @@ private:
// ----------------------------------------------------------------------------
template<typename Flag=bool>
struct FlagToggler {
Flag &flag;
bool toggled;
FlagToggler(Flag &_flag)
:flag(_flag),toggled(true)
{
flag = !flag;
}
FlagToggler(Flag &_flag, Flag check)
:flag(_flag),toggled(check==_flag)
{
if(toggled)
flag = !flag;
}
~FlagToggler() {
if(toggled)
flag = !flag;
}
};
// ----------------------------------------------------------------------------
template<typename Status, class Object>
class ObjectStatusLocker
{
@@ -217,6 +244,23 @@ private:
// ----------------------------------------------------------------------------
template<typename T>
class BitsetLocker
{
public:
BitsetLocker(T& flags, std::size_t flag, bool value = true)
: flags(flags), flag(flag)
{ oldValue = flags.test(flag); flags.set(flag,value); }
~BitsetLocker()
{ flags.set(flag,oldValue); }
private:
T &flags;
std::size_t flag;
bool oldValue;
};
// ----------------------------------------------------------------------------
class ConnectionBlocker {
typedef boost::signals2::connection Connection;
typedef boost::signals2::shared_connection_block ConnectionBlock;