| 1 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
/**************************************************************************** |
| 3 |
* * |
| 4 |
* Copyright (c) 2024 Kacper Donat <[email protected]> * |
| 5 |
* * |
| 6 |
* This file is part of FreeCAD. * |
| 7 |
* * |
| 8 |
* FreeCAD is free software: you can redistribute it and/or modify it * |
| 9 |
* under the terms of the GNU Lesser General Public License as * |
| 10 |
* published by the Free Software Foundation, either version 2.1 of the * |
| 11 |
* License, or (at your option) any later version. * |
| 12 |
* * |
| 13 |
* FreeCAD is distributed in the hope that it will be useful, but * |
| 14 |
* WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
| 16 |
* Lesser General Public License for more details. * |
| 17 |
* * |
| 18 |
* You should have received a copy of the GNU Lesser General Public * |
| 19 |
* License along with FreeCAD. If not, see * |
| 20 |
* <https://www.gnu.org/licenses/>. * |
| 21 |
* * |
| 22 |
***************************************************************************/ |
| 23 |
|
| 24 |
#ifndef APP_SERVICES_H |
| 25 |
#define APP_SERVICES_H |
| 26 |
|
| 27 |
#include "DocumentObject.h" |
| 28 |
|
| 29 |
#include <optional> |
| 30 |
#include <Base/Placement.h> |
| 31 |
|
| 32 |
namespace App |
| 33 |
{ |
| 34 |
|
| 35 |
/** |
| 36 |
* This service should provide placement of given sub object (like for example face). |
| 37 |
* This feature is not implemented in the core and so it must be provided by module. |
| 38 |
*/ |
| 39 |
class SubObjectPlacementProvider |
| 40 |
{ |
| 41 |
public: |
| 42 |
virtual ~SubObjectPlacementProvider() = default; |
| 43 |
|
| 44 |
/** |
| 45 |
* Returns placement of sub object relative to the base placement. |
| 46 |
*/ |
| 47 |
virtual Base::Placement calculate(SubObjectT object, Base::Placement basePlacement) const = 0; |
| 48 |
}; |
| 49 |
|
| 50 |
/** |
| 51 |
* This service should provide center of mass calculation; |
| 52 |
*/ |
| 53 |
class CenterOfMassProvider |
| 54 |
{ |
| 55 |
public: |
| 56 |
virtual ~CenterOfMassProvider() = default; |
| 57 |
|
| 58 |
virtual bool supports(DocumentObject* object) const = 0; |
| 59 |
virtual std::optional<Base::Vector3d> ofDocumentObject(DocumentObject* object) const = 0; |
| 60 |
}; |
| 61 |
|
| 62 |
/** |
| 63 |
* Default implementation for the center of mass contract |
| 64 |
* It always returns empty optional |
| 65 |
*/ |
| 66 |
class NullCenterOfMass final : public CenterOfMassProvider |
| 67 |
{ |
| 68 |
public: |
| 69 |
std::optional<Base::Vector3d> ofDocumentObject(DocumentObject* object) const override; |
| 70 |
bool supports(DocumentObject* object) const override; |
| 71 |
}; |
| 72 |
|
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
#endif // APP_SERVICES_H |