Neither in #18332 nor in any of the referenced issues a reason is given why the placement of the coordinate axes must be changed.
Only doing it to make the client code look more consistent is not a valid reason.

This change breaks forward and backward compatibility and with #18717 we already have a hard to solve issue. Furthermore, at this
point of time it's not even clear what other collateral damage the change may cause.

So, this commit hides all the implementation details of the DatumElement and restores the original placement for the axes.
This commit makes the line migration code obsolete
This commit is contained in:
wmayer
2024-12-29 22:01:00 +01:00
parent 90d8c34631
commit ad314fea7e
5 changed files with 60 additions and 45 deletions

View File

@@ -45,6 +45,7 @@ PROPERTY_SOURCE(App::Point, App::DatumElement)
PROPERTY_SOURCE(App::LocalCoordinateSystem, App::GeoFeature)
DatumElement::DatumElement(bool hideRole)
: baseDir{0.0, 0.0, 1.0}
{
ADD_PROPERTY_TYPE(Role,
(""),
@@ -63,7 +64,7 @@ DatumElement::~DatumElement() = default;
bool DatumElement::getCameraAlignmentDirection(Base::Vector3d& direction, const char* subname) const
{
Q_UNUSED(subname);
Placement.getValue().getRotation().multVec(Base::Vector3d(0., 0., 1.), direction);
Placement.getValue().getRotation().multVec(baseDir, direction);
return true;
}
@@ -95,13 +96,35 @@ Base::Vector3d DatumElement::getBasePoint() const
Base::Vector3d DatumElement::getDirection() const
{
Base::Vector3d dir(0.0, 0.0, 1.0);
Base::Vector3d dir(baseDir);
Base::Placement plc = Placement.getValue();
Base::Rotation rot = plc.getRotation();
rot.multVec(dir, dir);
return dir;
}
Base::Vector3d DatumElement::getBaseDirection() const
{
return baseDir;
}
void DatumElement::setBaseDirection(const Base::Vector3d& dir)
{
baseDir = dir;
}
// ----------------------------------------------------------------------------
Line::Line()
{
setBaseDirection(Base::Vector3d(1, 0, 0));
}
Point::Point()
{
setBaseDirection(Base::Vector3d(0, 0, 0));
}
// ----------------------------------------------------------------------------
LocalCoordinateSystem::LocalCoordinateSystem()
@@ -221,9 +244,9 @@ const std::vector<LocalCoordinateSystem::SetupData>& LocalCoordinateSystem::getS
{
static const std::vector<SetupData> setupData = {
// clang-format off
{App::Line::getClassTypeId(), AxisRoles[0], tr("X-axis"), Base::Rotation(Base::Vector3d(1, 1, 1), M_PI * 2 / 3)},
{App::Line::getClassTypeId(), AxisRoles[1], tr("Y-axis"), Base::Rotation(Base::Vector3d(-1, 1, 1), M_PI * 2 / 3)},
{App::Line::getClassTypeId(), AxisRoles[2], tr("Z-axis"), Base::Rotation()},
{App::Line::getClassTypeId(), AxisRoles[0], tr("X-axis"), Base::Rotation()},
{App::Line::getClassTypeId(), AxisRoles[1], tr("Y-axis"), Base::Rotation(Base::Vector3d(1, 1, 1), M_PI * 2 / 3)},
{App::Line::getClassTypeId(), AxisRoles[2], tr("Z-axis"), Base::Rotation(Base::Vector3d(1,-1, 1), M_PI * 2 / 3)},
{App::Plane::getClassTypeId(), PlaneRoles[0], tr("XY-plane"), Base::Rotation()},
{App::Plane::getClassTypeId(), PlaneRoles[1], tr("XZ-plane"), Base::Rotation(1.0, 0.0, 0.0, 1.0)},
{App::Plane::getClassTypeId(), PlaneRoles[2], tr("YZ-plane"), Base::Rotation(Base::Vector3d(1, 1, 1), M_PI * 2 / 3)},
@@ -233,7 +256,7 @@ const std::vector<LocalCoordinateSystem::SetupData>& LocalCoordinateSystem::getS
return setupData;
}
DatumElement* LocalCoordinateSystem::createDatum(SetupData& data)
DatumElement* LocalCoordinateSystem::createDatum(const SetupData& data)
{
App::Document* doc = getDocument();
std::string objName = doc->getUniqueObjectName(data.role);
@@ -297,10 +320,6 @@ void LocalCoordinateSystem::onDocumentRestored()
// In 0.22 origins did not have point.
migrateOriginPoint();
// In 0.22 the axis placement were wrong. The X axis had identity placement instead of the Z.
// This was fixed but we need to migrate old files.
migrateXAxisPlacement();
}
void LocalCoordinateSystem::migrateOriginPoint()
@@ -314,33 +333,12 @@ void LocalCoordinateSystem::migrateOriginPoint()
if (std::none_of(features.begin(), features.end(), isOrigin)) {
auto data = getData(PointRoles[0]);
auto* origin = createDatum(data);
origin->purgeTouched();
features.push_back(origin);
OriginFeatures.setValues(features);
}
}
void LocalCoordinateSystem::migrateXAxisPlacement()
{
constexpr const double tolerance = 1e-5;
auto features = OriginFeatures.getValues();
const auto& setupData = getSetupData();
for (auto* obj : features) {
auto* feature = dynamic_cast <App::DatumElement*> (obj);
if (!feature) { continue; }
for (auto data : setupData) {
// ensure the rotation is correct for the role
if (std::strcmp(feature->Role.getValue(), data.role) == 0) {
if (!feature->Placement.getValue().getRotation().isSame(data.rot, tolerance)) {
feature->Placement.setValue(Base::Placement(Base::Vector3d(), data.rot));
getDocument()->setStatus(App::Document::MigrateLCS, true);
}
break;
}
}
}
}
// ----------------------------------------------------------------------------
LocalCoordinateSystem::LCSExtension::LCSExtension(LocalCoordinateSystem* obj)