| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2015 Stefan Tröger <[email protected]> * |
| 3 |
* Copyright (c) 2015 Alexander Golubev (Fat-Zer) <[email protected]> * |
| 4 |
* Copyright (c) 2024 Ondsel (PL Boyer) <[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 DATUMS_H |
| 25 |
#define DATUMS_H |
| 26 |
|
| 27 |
#include "GeoFeature.h" |
| 28 |
#include "GeoFeatureGroupExtension.h" |
| 29 |
#include "QCoreApplication" |
| 30 |
|
| 31 |
namespace Base |
| 32 |
{ |
| 33 |
class Rotation; |
| 34 |
} |
| 35 |
|
| 36 |
namespace App |
| 37 |
{ |
| 38 |
class LocalCoordinateSystem; |
| 39 |
|
| 40 |
class AppExport DatumElement: public App::GeoFeature |
| 41 |
{ |
| 42 |
PROPERTY_HEADER_WITH_OVERRIDE(App::DatumElement); |
| 43 |
|
| 44 |
public: |
| 45 |
/// additional information about the feature usage (e.g. "BasePlane-XY" or "Axis-X") |
| 46 |
PropertyString Role; |
| 47 |
|
| 48 |
/// Constructor |
| 49 |
DatumElement(bool hideRole = true); |
| 50 |
~DatumElement() override; |
| 51 |
|
| 52 |
/// Finds the origin object this plane belongs to |
| 53 |
App::LocalCoordinateSystem* getLCS() const; |
| 54 |
Base::Vector3d getBasePoint() const; |
| 55 |
Base::Vector3d getDirection() const; |
| 56 |
Base::Vector3d getBaseDirection() const; |
| 57 |
|
| 58 |
bool getCameraAlignmentDirection(Base::Vector3d& directionZ, Base::Vector3d& directionX, const char* subname) const override; |
| 59 |
|
| 60 |
/// Returns true if this DatumElement is part of a App::Origin. |
| 61 |
bool isOriginFeature() const; |
| 62 |
|
| 63 |
protected: |
| 64 |
void setBaseDirection(const Base::Vector3d& dir); |
| 65 |
|
| 66 |
private: |
| 67 |
Base::Vector3d baseDir; |
| 68 |
}; |
| 69 |
|
| 70 |
class AppExport Plane: public App::DatumElement |
| 71 |
{ |
| 72 |
PROPERTY_HEADER_WITH_OVERRIDE(App::DatumElement); |
| 73 |
|
| 74 |
public: |
| 75 |
const char* getViewProviderName() const override |
| 76 |
{ |
| 77 |
return "Gui::ViewProviderPlane"; |
| 78 |
} |
| 79 |
}; |
| 80 |
|
| 81 |
class AppExport Line: public App::DatumElement |
| 82 |
{ |
| 83 |
PROPERTY_HEADER_WITH_OVERRIDE(App::DatumElement); |
| 84 |
|
| 85 |
public: |
| 86 |
Line(); |
| 87 |
const char* getViewProviderName() const override |
| 88 |
{ |
| 89 |
return "Gui::ViewProviderLine"; |
| 90 |
} |
| 91 |
}; |
| 92 |
|
| 93 |
class AppExport Point: public App::DatumElement |
| 94 |
{ |
| 95 |
PROPERTY_HEADER_WITH_OVERRIDE(App::DatumElement); |
| 96 |
|
| 97 |
public: |
| 98 |
Point(); |
| 99 |
const char* getViewProviderName() const override |
| 100 |
{ |
| 101 |
return "Gui::ViewProviderPoint"; |
| 102 |
} |
| 103 |
}; |
| 104 |
|
| 105 |
class AppExport LocalCoordinateSystem: public App::GeoFeature, public App::GeoFeatureGroupExtension |
| 106 |
{ |
| 107 |
PROPERTY_HEADER_WITH_EXTENSIONS(App::LocalCoordinateSystem); |
| 108 |
Q_DECLARE_TR_FUNCTIONS(App::LocalCoordinateSystem) |
| 109 |
|
| 110 |
public: |
| 111 |
/// Constructor |
| 112 |
LocalCoordinateSystem(); |
| 113 |
~LocalCoordinateSystem() override; |
| 114 |
|
| 115 |
/// returns the type name of the ViewProvider |
| 116 |
const char* getViewProviderName() const override |
| 117 |
{ |
| 118 |
return "Gui::ViewProviderCoordinateSystem"; |
| 119 |
} |
| 120 |
|
| 121 |
bool getCameraAlignmentDirection(Base::Vector3d& directionZ, Base::Vector3d& directionX, const char* subname) const override; |
| 122 |
|
| 123 |
/** @name Axis and plane access |
| 124 |
* This functions returns casted axis and planes objects and asserts they are set correctly |
| 125 |
* otherwise Base::Exception is thrown. |
| 126 |
*/ |
| 127 |
///@{ |
| 128 |
// returns origin point |
| 129 |
App::Point* getOrigin() const |
| 130 |
{ |
| 131 |
return getPoint(PointRoles[0]); |
| 132 |
} |
| 133 |
|
| 134 |
// returns X axis |
| 135 |
App::Line* getX() const |
| 136 |
{ |
| 137 |
return getAxis(AxisRoles[0]); |
| 138 |
} |
| 139 |
// returns Y axis |
| 140 |
App::Line* getY() const |
| 141 |
{ |
| 142 |
return getAxis(AxisRoles[1]); |
| 143 |
} |
| 144 |
// returns Z axis |
| 145 |
App::Line* getZ() const |
| 146 |
{ |
| 147 |
return getAxis(AxisRoles[2]); |
| 148 |
} |
| 149 |
|
| 150 |
// returns XY plane |
| 151 |
App::Plane* getXY() const |
| 152 |
{ |
| 153 |
return getPlane(PlaneRoles[0]); |
| 154 |
} |
| 155 |
// returns XZ plane |
| 156 |
App::Plane* getXZ() const |
| 157 |
{ |
| 158 |
return getPlane(PlaneRoles[1]); |
| 159 |
} |
| 160 |
// returns YZ plane |
| 161 |
App::Plane* getYZ() const |
| 162 |
{ |
| 163 |
return getPlane(PlaneRoles[2]); |
| 164 |
} |
| 165 |
|
| 166 |
/// Returns all axis objects to iterate on them |
| 167 |
std::vector<App::Line*> axes() const |
| 168 |
{ |
| 169 |
return {getX(), getY(), getZ()}; |
| 170 |
} |
| 171 |
|
| 172 |
/// Returns all base planes objects to iterate on them |
| 173 |
std::vector<App::Plane*> planes() const |
| 174 |
{ |
| 175 |
return {getXY(), getXZ(), getYZ()}; |
| 176 |
} |
| 177 |
|
| 178 |
/// Returns all controlled objects (both planes and axis) to iterate on them |
| 179 |
std::vector<App::DatumElement*> baseObjects() const |
| 180 |
{ |
| 181 |
return {getX(), getY(), getZ(), getXY(), getXZ(), getYZ(), getOrigin()}; |
| 182 |
} |
| 183 |
|
| 184 |
/// Returns an axis by it's name |
| 185 |
App::DatumElement* getDatumElement(const char* role) const; |
| 186 |
|
| 187 |
/// Returns an axis by it's name |
| 188 |
App::Line* getAxis(const char* role) const; |
| 189 |
|
| 190 |
/// Returns an axis by it's name |
| 191 |
App::Plane* getPlane(const char* role) const; |
| 192 |
|
| 193 |
/// Returns a point by it's name |
| 194 |
App::Point* getPoint(const char* role) const; |
| 195 |
///@} |
| 196 |
|
| 197 |
/// Returns true on changing DatumElement set |
| 198 |
short mustExecute() const override; |
| 199 |
|
| 200 |
/// Axis types |
| 201 |
static constexpr const char* AxisRoles[3] = {"X_Axis", "Y_Axis", "Z_Axis"}; |
| 202 |
/// Baseplane types |
| 203 |
static constexpr const char* PlaneRoles[3] = {"XY_Plane", "XZ_Plane", "YZ_Plane"}; |
| 204 |
/// Points types |
| 205 |
static constexpr const char* PointRoles[1] = {"Origin"}; |
| 206 |
|
| 207 |
virtual bool isOrigin() const |
| 208 |
{ |
| 209 |
return false; |
| 210 |
} |
| 211 |
|
| 212 |
// Axis links |
| 213 |
PropertyLinkList OriginFeatures; |
| 214 |
|
| 215 |
// GeoFeatureGroupExtension overrides: |
| 216 |
bool extensionGetSubObject(DocumentObject*& ret, |
| 217 |
const char* subname, |
| 218 |
PyObject**, |
| 219 |
Base::Matrix4D*, |
| 220 |
bool, |
| 221 |
int) const override; |
| 222 |
|
| 223 |
// Reimplement the hasObject because LCS doesn't use Group but stores objects in OriginFeatures for whatever reason. |
| 224 |
bool hasObject(const DocumentObject* obj, bool recursive = false) const override; |
| 225 |
|
| 226 |
protected: |
| 227 |
/// Checks integrity of the LCS |
| 228 |
App::DocumentObjectExecReturn* execute() override; |
| 229 |
/// Creates all corresponding Axes and Planes objects for the LCS if they aren't linked yet |
| 230 |
void setupObject() override; |
| 231 |
/// Removes all planes and axis if they are still linked to the document |
| 232 |
void unsetupObject() override; |
| 233 |
void onDocumentRestored() override; |
| 234 |
|
| 235 |
private: |
| 236 |
struct SetupData; |
| 237 |
void setupDatumElement(App::PropertyLink& featProp, const SetupData& data); |
| 238 |
|
| 239 |
struct SetupData |
| 240 |
{ |
| 241 |
Base::Type type; |
| 242 |
const char* role = nullptr; |
| 243 |
QString label; |
| 244 |
Base::Rotation rot; |
| 245 |
}; |
| 246 |
static const std::vector<SetupData>& getSetupData(); |
| 247 |
|
| 248 |
DatumElement* createDatum(const SetupData& data); |
| 249 |
SetupData getData(const char* role); |
| 250 |
|
| 251 |
void migrateOriginPoint(); |
| 252 |
}; |
| 253 |
|
| 254 |
} // namespace App |
| 255 |
|
| 256 |
#endif /* end of include guard: DATUMS_H */ |