Debian Codegraph @

src/App/GeoFeature.h

raw
1 /***************************************************************************
2 * Copyright (c) 2002 Jürgen Riegel <[email protected]> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23
24 #ifndef APP_GEOFEATURE_H
25 #define APP_GEOFEATURE_H
26
27 #include "DocumentObject.h"
28 #include "PropertyGeo.h"
29 #include "MappedElement.h"
30 #include "Material.h"
31 #include "ComplexGeoData.h"
32
33 namespace App
34 {
35
36
37 /** Base class of all geometric document objects.
38 */
39 class AppExport GeoFeature: public App::DocumentObject
40 {
41 PROPERTY_HEADER_WITH_OVERRIDE(App::GeoFeature);
42
43 public:
44 PropertyPlacement Placement;
45 PropertyString _ElementMapVersion;
46
47 /// Constructor
48 GeoFeature();
49 ~GeoFeature() override;
50
51 /**
52 * @brief transformPlacement applies transform to placement of this shape.
53 * Override this function to propagate the change of placement to base
54 * features, for example. By the time of writing this comment, the function
55 * was only called by alignment task (Edit->Alignment)
56 * @param transform (input).
57 */
58 virtual void transformPlacement(const Base::Placement& transform);
59 /**
60 * This method returns the main property of a geometric object that holds
61 * the actual geometry. For a part object this is the Shape property, for
62 * a mesh object the Mesh property and so on.
63 * The default implementation returns null.
64 */
65 virtual const PropertyComplexGeoData* getPropertyOfGeometry() const;
66 /**
67 * @brief getPyObject returns the Python binding object
68 * @return the Python binding object
69 */
70 PyObject* getPyObject() override;
71
72 /// Specify the type of element name to return when calling getElementName()
73 enum ElementNameType
74 {
75 /// Normal usage
76 Normal = 0,
77 /// For importing
78 Import = 1,
79 /// For exporting
80 Export = 2,
81 };
82
83 /** Return the new and old style sub-element name
84 *
85 * @param name: input name
86 * @param type: desired element name type to return
87 *
88 * @return a struct with the newName and oldName. New element name may be empty.
89 */
90 virtual ElementNamePair getElementName( // NOLINT(google-default-arguments)
91 const char* name,
92 ElementNameType type = Normal) const;
93
94 /** Resolve both the new and old style element name
95 *
96 * @param obj: top parent object
97 * @param subname: subname reference
98 * @param elementName: output of a pair(newElementName,oldElementName)
99 * @param append: Whether to include subname prefix into the returned
100 * element name
101 * @param type: the type of element name to request
102 * @param filter: If none zero, then only perform lookup when the element
103 * owner object is the same as this filter
104 * @param element: return the start of element name in subname
105 *
106 * @return Return the owner object of the element
107 */
108 static DocumentObject* resolveElement(const App::DocumentObject* obj,
109 const char* subname,
110 ElementNamePair& elementName,
111 bool append = false,
112 ElementNameType type = Normal,
113 const DocumentObject* filter = nullptr,
114 const char** element = nullptr,
115 GeoFeature** geo = nullptr);
116
117 /**
118 * @brief Deprecated. Calculates the placement in the global reference coordinate system
119 *
120 * Deprecated: This does not handle App::Links correctly. Use getGlobalPlacement() instead.
121 * In FreeCAD the GeoFeature placement describes the local placement of the object in its parent
122 * coordinate system. This is however not always the same as the global reference system. If the
123 * object is in a GeoFeatureGroup, hence in another local coordinate system, the Placement
124 * property does only give the local transformation. This function can be used to calculate the
125 * placement of the object in the global reference coordinate system taking all stacked local
126 * systems into account.
127 *
128 * @return Base::Placement The transformation from the global reference coordinate system
129 */
130 Base::Placement globalPlacement() const;
131 /**
132 * @brief Virtual function to get an App::Material object describing the appearance
133 *
134 * The appearance properties are described by the underlying features material. This can not
135 * be accessed directly from within the Gui module. This virtual function will return a
136 * App::Material object describing the appearance properties of the material.
137 *
138 * @return App::Material the appearance properties of the object material
139 */
140 virtual App::Material getMaterialAppearance() const;
141
142 /**
143 * @brief Virtual function to set the appearance with an App::Material object
144 *
145 * The appearance properties are described by the underlying features material. This cannot
146 * be accessed directly from within the Gui module. This virtual function will set the
147 * appearance from an App::Material object.
148 */
149 virtual void setMaterialAppearance(const App::Material& material);
150
151 /**
152 * @brief Virtual function to get the camera alignment direction
153 *
154 * Finds a directionZ to align the camera with.
155 * May also find an optional directionX which could be used for horizontal or vertical alignment.
156 *
157 * @return bool whether or not a directionZ is found.
158 */
159 virtual bool getCameraAlignmentDirection(Base::Vector3d& directionZ,
160 Base::Vector3d& directionX,
161 const char* subname = nullptr) const;
162 /** Search sub element using internal cached geometry
163 *
164 * @param element: element name
165 * @param options: search options
166 * @param tol: coordinate tolerance
167 * @param atol: angle tolerance
168 *
169 * @return Returns a list of found element reference to the new geometry.
170 * The returned value will be invalidated when the geometry is changed.
171 *
172 * Before changing the property of geometry, GeoFeature will internally
173 * make a snapshot of all referenced element geometry. After change, user
174 * code may call this function to search for the new element name that
175 * reference to the same geometry of the old element.
176 */
177 virtual const std::vector<std::string>&
178 searchElementCache(const std::string& element,
179 Data::SearchOptions options = Data::SearchOption::CheckGeometry,
180 double tol = 1e-7,
181 double atol = 1e-10) const;
182
183 static bool hasMissingElement(const char* subname);
184
185 /// Return the object that owns the shape that contains the give element name
186 virtual DocumentObject* getElementOwner(const Data::MappedName& /*name*/) const
187 {
188 return nullptr;
189 }
190
191 virtual std::vector<const char*> getElementTypes(bool all = true) const;
192
193 /// Return the higher level element names of the given element
194 virtual std::vector<Data::IndexedName> getHigherElements(const char* name,
195 bool silent = false) const;
196
197 static Base::Placement getPlacementFromProp(DocumentObject* obj, const char* propName);
198 static Base::Placement
199 getGlobalPlacement(DocumentObject* targetObj, DocumentObject* rootObj, const std::string& sub);
200 static Base::Placement getGlobalPlacement(DocumentObject* targetObj, PropertyXLinkSub* prop);
201 static Base::Placement getGlobalPlacement(const DocumentObject* obj);
202
203 protected:
204 void onChanged(const Property* prop) override;
205 void onDocumentRestored() override;
206 void updateElementReference();
207
208 protected:
209 ElementNamePair _getElementName(const char* name, const Data::MappedElement& mapped) const;
210 };
211
212 } // namespace App
213
214
215 #endif // APP_GEOFEATURE_H