| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2023 David Friedli <[email protected]> * |
| 3 |
* Copyright (c) 2023 Wandererfan <[email protected]> * |
| 4 |
* * |
| 5 |
* This file is part of FreeCAD. * |
| 6 |
* * |
| 7 |
* FreeCAD is free software: you can redistribute it and/or modify it * |
| 8 |
* under the terms of the GNU Lesser General Public License as * |
| 9 |
* published by the Free Software Foundation, either version 2.1 of the * |
| 10 |
* License, or (at your option) any later version. * |
| 11 |
* * |
| 12 |
* FreeCAD is distributed in the hope that it will be useful, but * |
| 13 |
* WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
| 15 |
* Lesser General Public License for more details. * |
| 16 |
* * |
| 17 |
* You should have received a copy of the GNU Lesser General Public * |
| 18 |
* License along with FreeCAD. If not, see * |
| 19 |
* <https://www.gnu.org/licenses/>. * |
| 20 |
* * |
| 21 |
**************************************************************************/ |
| 22 |
|
| 23 |
#ifndef MEASUREMANAGER_H |
| 24 |
#define MEASUREMANAGER_H |
| 25 |
|
| 26 |
|
| 27 |
#include <vector> |
| 28 |
#include <tuple> |
| 29 |
#include <functional> |
| 30 |
#include <string> |
| 31 |
#include <Python.h> |
| 32 |
#include <App/DocumentObject.h> |
| 33 |
#include <Base/Vector3D.h> |
| 34 |
#include <App/DocumentObserver.h> |
| 35 |
#include <Base/Interpreter.h> |
| 36 |
|
| 37 |
#include <FCGlobal.h> |
| 38 |
|
| 39 |
namespace App |
| 40 |
{ |
| 41 |
|
| 42 |
// Add your class methods and member variables here |
| 43 |
enum class MeasureElementType |
| 44 |
{ |
| 45 |
INVALID, |
| 46 |
POINT, |
| 47 |
LINE, |
| 48 |
LINESEGMENT, |
| 49 |
CIRCLE, |
| 50 |
ARC, |
| 51 |
CURVE, // Has a length but no radius or axis |
| 52 |
PLANE, |
| 53 |
CYLINDER, |
| 54 |
VOLUME, |
| 55 |
SURFACE, |
| 56 |
}; |
| 57 |
|
| 58 |
|
| 59 |
struct MeasureSelectionItem |
| 60 |
{ |
| 61 |
App::SubObjectT object; |
| 62 |
Base::Vector3d pickedPoint; |
| 63 |
}; |
| 64 |
|
| 65 |
|
| 66 |
using MeasureSelection = std::vector<MeasureSelectionItem>; |
| 67 |
using MeasureValidateMethod = std::function<bool(const MeasureSelection&)>; |
| 68 |
using MeasurePrioritizeMethod = std::function<bool(const MeasureSelection&)>; |
| 69 |
using MeasureTypeMethod = std::function<MeasureElementType(App::DocumentObject*, const char*)>; |
| 70 |
|
| 71 |
struct MeasureType |
| 72 |
{ |
| 73 |
std::string identifier; |
| 74 |
std::string label; |
| 75 |
std::string measureObject; |
| 76 |
|
| 77 |
// Checks if the measurement works with a given selection |
| 78 |
MeasureValidateMethod validatorCb; |
| 79 |
|
| 80 |
// Allows to prioritize this over other measurement types when the measurement type is picked |
| 81 |
// implicitly from the selection. Gets called only when validatorCb returned true for the given |
| 82 |
// selection |
| 83 |
MeasurePrioritizeMethod prioritizeCb; |
| 84 |
|
| 85 |
bool isPython; |
| 86 |
PyObject* pythonClass; |
| 87 |
}; |
| 88 |
|
| 89 |
struct MeasureHandler |
| 90 |
{ |
| 91 |
std::string module; |
| 92 |
MeasureTypeMethod typeCb; |
| 93 |
}; |
| 94 |
|
| 95 |
|
| 96 |
class AppExport MeasureManager |
| 97 |
{ |
| 98 |
public: |
| 99 |
MeasureManager(); |
| 100 |
|
| 101 |
static void addMeasureHandler(const char* module, MeasureTypeMethod typeCb); |
| 102 |
static bool hasMeasureHandler(const char* module); |
| 103 |
static MeasureHandler getMeasureHandler(const char* module); |
| 104 |
static MeasureHandler getMeasureHandler(const App::MeasureSelectionItem& selectionItem); |
| 105 |
static MeasureElementType getMeasureElementType(const App::MeasureSelectionItem& selectionItem); |
| 106 |
static void addMeasureType(MeasureType* measureType); |
| 107 |
static void addMeasureType(std::string id, |
| 108 |
std::string label, |
| 109 |
std::string measureObj, |
| 110 |
MeasureValidateMethod validatorCb, |
| 111 |
MeasurePrioritizeMethod prioritizeCb); |
| 112 |
static void addMeasureType(const char* id, |
| 113 |
const char* label, |
| 114 |
const char* measureObj, |
| 115 |
MeasureValidateMethod validatorCb, |
| 116 |
MeasurePrioritizeMethod prioritizeCb); |
| 117 |
static const std::vector<MeasureType*> getMeasureTypes(); |
| 118 |
static Py::Tuple getSelectionPy(const App::MeasureSelection& selection); |
| 119 |
static std::vector<MeasureType*> getValidMeasureTypes(App::MeasureSelection selection, |
| 120 |
std::string mode); |
| 121 |
|
| 122 |
|
| 123 |
private: |
| 124 |
static std::vector<MeasureHandler> _mMeasureHandlers; |
| 125 |
static std::vector<MeasureType*> _mMeasureTypes; |
| 126 |
}; |
| 127 |
|
| 128 |
|
| 129 |
} // namespace App |
| 130 |
|
| 131 |
#endif // MEASUREMANAGER_H |