/*************************************************************************** * Copyright (c) 2023 David Friedli * * Copyright (c) 2023 Wandererfan * * * * This file is part of FreeCAD. * * * * FreeCAD is free software: you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as * * published by the Free Software Foundation, either version 2.1 of the * * License, or (at your option) any later version. * * * * FreeCAD is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with FreeCAD. If not, see * * . * * * **************************************************************************/ #ifndef MEASUREMANAGER_H #define MEASUREMANAGER_H #include #include #include #include #include #include #include #include #include #include namespace App { // Add your class methods and member variables here enum class MeasureElementType { INVALID, POINT, LINE, LINESEGMENT, CIRCLE, ARC, CURVE, // Has a length but no radius or axis PLANE, CYLINDER, Volume, }; struct MeasureSelectionItem { App::SubObjectT object; Base::Vector3d pickedPoint; }; using MeasureSelection = std::vector; using MeasureValidateMethod = std::function; using MeasurePrioritizeMethod = std::function; using MeasureTypeMethod = std::function; struct MeasureType { std::string identifier; std::string label; std::string measureObject; // Checks if the measurement works with a given selection MeasureValidateMethod validatorCb; // Allows to prioritize this over other measurement types when the measurement type is picked implicitly from the selection. // Gets called only when validatorCb returned true for the given selection MeasurePrioritizeMethod prioritizeCb; bool isPython; PyObject* pythonClass; }; struct MeasureHandler { std::string module; MeasureTypeMethod typeCb; }; class AppExport MeasureManager { public: MeasureManager(); static void addMeasureHandler(const char* module, MeasureTypeMethod typeCb); static bool hasMeasureHandler(const char* module); static MeasureHandler getMeasureHandler(const char* module); static void addMeasureType(MeasureType* measureType); static void addMeasureType(std::string id, std::string label, std::string measureObj, MeasureValidateMethod validatorCb, MeasurePrioritizeMethod prioritizeCb); static void addMeasureType(const char* id, const char* label, const char* measureObj, MeasureValidateMethod validatorCb, MeasurePrioritizeMethod prioritizeCb); static const std::vector getMeasureTypes(); static Py::Tuple getSelectionPy(const App::MeasureSelection& selection); static std::vector getValidMeasureTypes(App::MeasureSelection selection, std::string mode); private: static std::vector _mMeasureHandlers; static std::vector _mMeasureTypes; }; } // namespace App #endif // MEASUREMANAGER_H