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