| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2014 Jürgen Riegel <[email protected]> * |
| 3 |
* Copyright (c) 2015 Alexander Golubev (Fat-Zer) <[email protected]> * |
| 4 |
* * |
| 5 |
* This file is part of the FreeCAD CAx development system. * |
| 6 |
* * |
| 7 |
* This library is free software; you can redistribute it and/or * |
| 8 |
* modify it under the terms of the GNU Library General Public * |
| 9 |
* License as published by the Free Software Foundation; either * |
| 10 |
* version 2 of the License, or (at your option) any later version. * |
| 11 |
* * |
| 12 |
* This library is distributed in the hope that it will be useful, * |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 15 |
* GNU Library General Public License for more details. * |
| 16 |
* * |
| 17 |
* You should have received a copy of the GNU Library General Public * |
| 18 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 19 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 20 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 21 |
* * |
| 22 |
***************************************************************************/ |
| 23 |
|
| 24 |
|
| 25 |
#ifndef APP_GeoFeatureGroup_H |
| 26 |
#define APP_GeoFeatureGroup_H |
| 27 |
|
| 28 |
#include <unordered_set> |
| 29 |
#include "DocumentObject.h" |
| 30 |
#include "GroupExtension.h" |
| 31 |
#include "PropertyGeo.h" |
| 32 |
|
| 33 |
|
| 34 |
namespace App |
| 35 |
{ |
| 36 |
|
| 37 |
/** |
| 38 |
* @brief The base class for placeable group of DocumentObjects. It represents a local coordnate |
| 39 |
* system |
| 40 |
* |
| 41 |
* This class is the FreeCAD way of representing local coordinate systems. It groups its children |
| 42 |
* beneath it and transforms them all with the GeoFeatureGroup placement. A few important |
| 43 |
* properties: |
| 44 |
* - Every child that belongs to the CS must be in the Group property. Even if a sketch is part of a |
| 45 |
* pad, it must be in the Group property of the same GeoFeatureGroup as pad. This also holds for |
| 46 |
* normal GroupExtensions. They can be added to a GeoFeatureGroup, but all objects that the group |
| 47 |
* holds must also be added to the GeoFeatureGroup |
| 48 |
* - Objects can be only in a single GeoFeatureGroup. It is not allowed to have a document object in |
| 49 |
* multiple GeoFeatureGroups |
| 50 |
* - PropertyLinks between different GeoFeatureGroups are forbidden. There are special link |
| 51 |
* properties that allow such cross-CS links. |
| 52 |
* - Expressions can cross GeoFeatureGroup borders |
| 53 |
*/ |
| 54 |
class AppExport GeoFeatureGroupExtension: public App::GroupExtension |
| 55 |
{ |
| 56 |
using inherited = App::GroupExtension; |
| 57 |
EXTENSION_PROPERTY_HEADER_WITH_OVERRIDE(App::GeoFeatureGroupExtension); |
| 58 |
|
| 59 |
public: |
| 60 |
PropertyPlacement& placement(); |
| 61 |
|
| 62 |
void initExtension(ExtensionContainer* obj) override; |
| 63 |
|
| 64 |
/** |
| 65 |
* @brief transformPlacement applies transform to placement of this shape. |
| 66 |
* Override this function to propagate the change of placement to base |
| 67 |
* features. |
| 68 |
* @param transform (input). |
| 69 |
*/ |
| 70 |
virtual void transformPlacement(const Base::Placement& transform); |
| 71 |
|
| 72 |
/// Constructor |
| 73 |
GeoFeatureGroupExtension(); |
| 74 |
~GeoFeatureGroupExtension() override; |
| 75 |
|
| 76 |
void extensionOnChanged(const Property* p) override; |
| 77 |
|
| 78 |
/** Returns the geo feature group which contains this object. |
| 79 |
* In case this object is not part of any geoFeatureGroup 0 is returned. |
| 80 |
* Unlike DocumentObjectGroup::getGroupOfObject searches only for GeoFeatureGroups |
| 81 |
* @param obj the object to search for |
| 82 |
*/ |
| 83 |
static DocumentObject* getGroupOfObject(const DocumentObject* obj); |
| 84 |
|
| 85 |
/** |
| 86 |
* @brief Calculates the global placement of this group |
| 87 |
* |
| 88 |
* The returned placement describes the transformation from the global reference coordinate |
| 89 |
* system to the local coordinate system of this geo feature group. If this group has a no |
| 90 |
* parent GeoFeatureGroup the returned placement is the one of this group. For multiple stacked |
| 91 |
* GeoFeatureGroups the returned Placement is the combination of all parent placements including |
| 92 |
* the one of this group. |
| 93 |
* @return Base::Placement The transformation from global reference system to the groups local |
| 94 |
* system |
| 95 |
*/ |
| 96 |
Base::Placement globalGroupPlacement(); |
| 97 |
|
| 98 |
/// Returns true if the given DocumentObject is DocumentObjectGroup but not GeoFeatureGroup |
| 99 |
static bool isNonGeoGroup(const DocumentObject* obj) |
| 100 |
{ |
| 101 |
return obj->hasExtension(GroupExtension::getExtensionClassTypeId()) |
| 102 |
&& !obj->hasExtension(GeoFeatureGroupExtension::getExtensionClassTypeId()); |
| 103 |
} |
| 104 |
|
| 105 |
bool extensionGetSubObject(DocumentObject*& ret, |
| 106 |
const char* subname, |
| 107 |
PyObject** pyObj, |
| 108 |
Base::Matrix4D* mat, |
| 109 |
bool transform, |
| 110 |
int depth) const override; |
| 111 |
|
| 112 |
bool extensionGetSubObjects(std::vector<std::string>& ret, int reason) const override; |
| 113 |
|
| 114 |
std::vector<DocumentObject*> addObjects(std::vector<DocumentObject*> obj) override; |
| 115 |
std::vector<DocumentObject*> removeObjects(std::vector<DocumentObject*> obj) override; |
| 116 |
|
| 117 |
/// Collects all links that are relevant for the coordinate system, meaning all recursive links |
| 118 |
/// to obj and from obj excluding expressions and stopping the recursion at other |
| 119 |
/// geofeaturegroups. The result is the combination of CSOutList and CSInList. |
| 120 |
static std::vector<App::DocumentObject*> getCSRelevantLinks(const App::DocumentObject* obj); |
| 121 |
/// Checks if the links of the given object comply with all GeoFeatureGroup requirements, that |
| 122 |
/// means if normal links are only within the parent GeoFeatureGroup. |
| 123 |
static bool areLinksValid(const App::DocumentObject* obj); |
| 124 |
/// Checks if the given link complies with all GeoFeatureGroup requirements, that means |
| 125 |
/// if normal links are only within the parent GeoFeatureGroup. |
| 126 |
static bool isLinkValid(App::Property* link); |
| 127 |
// Returns all objects that are wrongly linked from this object, meaning which are out of scope |
| 128 |
// of the links of obj |
| 129 |
static void getInvalidLinkObjects(const App::DocumentObject* obj, |
| 130 |
std::vector<App::DocumentObject*>& vec); |
| 131 |
|
| 132 |
private: |
| 133 |
Base::Placement recursiveGroupPlacement(GeoFeatureGroupExtension* group, |
| 134 |
std::unordered_set<GeoFeatureGroupExtension*>& history); |
| 135 |
static std::vector<App::DocumentObject*> |
| 136 |
getScopedObjectsFromLinks(const App::DocumentObject*, LinkScope scope = LinkScope::Local); |
| 137 |
static std::vector<App::DocumentObject*> |
| 138 |
getScopedObjectsFromLink(App::Property*, LinkScope scope = LinkScope::Local); |
| 139 |
|
| 140 |
/// Collects GeoFeatureGroup relevant objects that are linked from the given one. That means all |
| 141 |
/// linked objects except GeoFeatureGroups. Expressions links are ignored. Only local scope |
| 142 |
/// links are considered. There is no recursion. An exception is thrown when there are |
| 143 |
/// dependency loops. |
| 144 |
static void getCSOutList(const App::DocumentObject* obj, |
| 145 |
std::vector<App::DocumentObject*>& vec); |
| 146 |
/// Collects GeoFeatureGroup relevant objects that link to the given one. That means all objects |
| 147 |
/// except GeoFeatureGroups. Expression links are ignored. Only local scope links are relevant, |
| 148 |
/// and there is no recursion. An exception is thrown when there are dependency loops. |
| 149 |
static void getCSInList(const App::DocumentObject* obj, std::vector<App::DocumentObject*>& vec); |
| 150 |
|
| 151 |
static void recursiveCSRelevantLinks(const App::DocumentObject* obj, |
| 152 |
std::vector<App::DocumentObject*>& vec); |
| 153 |
}; |
| 154 |
|
| 155 |
using GeoFeatureGroupExtensionPython = |
| 156 |
ExtensionPythonT<GroupExtensionPythonT<GeoFeatureGroupExtension>>; |
| 157 |
|
| 158 |
|
| 159 |
} // namespace App |
| 160 |
|
| 161 |
|
| 162 |
#endif // APP_GeoFeatureGroup_H |