| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| |
|
| | #ifndef MEASURE_MEASUREBASE_H
|
| | #define MEASURE_MEASUREBASE_H
|
| |
|
| | #include <Mod/Measure/MeasureGlobal.h>
|
| |
|
| | #include <memory>
|
| | #include <QString>
|
| |
|
| | #include <App/DocumentObject.h>
|
| | #include <App/MeasureManager.h>
|
| | #include <App/DocumentObserver.h>
|
| | #include <App/PropertyStandard.h>
|
| | #include <App/PropertyUnits.h>
|
| | #include <App/FeaturePython.h>
|
| | #include <App/Link.h>
|
| | #include <Base/Quantity.h>
|
| | #include <Base/Placement.h>
|
| | #include <Base/Interpreter.h>
|
| |
|
| | #include <Mod/Part/App/MeasureInfo.h>
|
| | #include <Mod/Part/App/MeasureClient.h>
|
| |
|
| |
|
| | namespace Measure
|
| | {
|
| |
|
| | class MeasureExport MeasureBase: public App::DocumentObject
|
| | {
|
| | PROPERTY_HEADER_WITH_OVERRIDE(Measure::MeasureBase);
|
| |
|
| | public:
|
| | MeasureBase();
|
| | ~MeasureBase() override = default;
|
| |
|
| | App::PropertyPlacement Placement;
|
| |
|
| |
|
| |
|
| |
|
| | PyObject* getPyObject() override;
|
| |
|
| |
|
| | virtual void parseSelection(const App::MeasureSelection& selection);
|
| |
|
| |
|
| | virtual QString getResultString();
|
| |
|
| | virtual std::vector<std::string> getInputProps();
|
| | virtual App::Property* getResultProp()
|
| | {
|
| | return {};
|
| | }
|
| |
|
| |
|
| | virtual std::vector<App::DocumentObject*> getSubject() const;
|
| |
|
| | private:
|
| | Py::Object getProxyObject() const;
|
| |
|
| | protected:
|
| | void onDocumentRestored() override;
|
| | };
|
| |
|
| |
|
| | using MeasurePython = App::FeaturePythonT<MeasureBase>;
|
| |
|
| | template<typename T>
|
| | class MeasureExport MeasureBaseExtendable: public MeasureBase
|
| | {
|
| |
|
| | using GeometryHandler = std::function<Part::MeasureInfoPtr(const App::SubObjectT&)>;
|
| | using HandlerMap = std::map<std::string, GeometryHandler>;
|
| |
|
| |
|
| | public:
|
| | static void addGeometryHandler(const std::string& module, GeometryHandler callback)
|
| | {
|
| | _mGeometryHandlers[module] = callback;
|
| | }
|
| |
|
| | static GeometryHandler getGeometryHandler(const std::string& module)
|
| | {
|
| |
|
| | if (!hasGeometryHandler(module)) {
|
| | return {};
|
| | }
|
| |
|
| | return _mGeometryHandlers[module];
|
| | }
|
| |
|
| | static Part::MeasureInfoPtr getMeasureInfo(App::SubObjectT& subObjT)
|
| | {
|
| |
|
| |
|
| | App::DocumentObject* sub = subObjT.getSubObject();
|
| | if (!sub) {
|
| | return nullptr;
|
| | }
|
| |
|
| | if (sub->isDerivedFrom<App::Link>()) {
|
| | auto link = static_cast<App::Link*>(sub);
|
| | sub = link->getLinkedObject(true);
|
| | }
|
| |
|
| |
|
| | const char* className = sub->getTypeId().getName();
|
| | std::string mod = Base::Type::getModuleName(className);
|
| |
|
| | auto handler = getGeometryHandler(mod);
|
| | if (!handler) {
|
| | Base::Console().log(
|
| | "MeasureBaseExtendable::getMeasureInfo: No geometry handler "
|
| | "available for submitted element type"
|
| | );
|
| | return nullptr;
|
| | }
|
| |
|
| | return handler(subObjT);
|
| | }
|
| |
|
| | static void addGeometryHandlers(const std::vector<std::string>& modules, GeometryHandler callback)
|
| | {
|
| |
|
| |
|
| | for (auto& mod : modules) {
|
| | _mGeometryHandlers[mod] = callback;
|
| | }
|
| | }
|
| |
|
| |
|
| | static bool hasGeometryHandler(const std::string& module)
|
| | {
|
| | return (_mGeometryHandlers.count(module) > 0);
|
| | }
|
| |
|
| | private:
|
| | inline static HandlerMap _mGeometryHandlers = MeasureBaseExtendable<T>::HandlerMap();
|
| | };
|
| |
|
| |
|
| | }
|
| |
|
| |
|
| | #endif
|
| |
|