|
1 | 1 | /*************************************************************************** |
2 | | - * Copyright (c) 2015 Stefan Tröger <[email protected]> * |
| 2 | + * Copyright (c) 2015 Stefan Tröger <[email protected]> * |
3 | 3 | * Copyright (c) 2015 Alexander Golubev (Fat-Zer) <[email protected]> * |
4 | 4 | * Copyright (c) 2024 Ondsel (PL Boyer) <[email protected]> * |
5 | 5 | * * |
6 | | - * This file is part of the FreeCAD CAx development system. * |
| 6 | + * This file is part of FreeCAD. * |
7 | 7 | * * |
8 | | - * This library is free software; you can redistribute it and/or * |
9 | | - * modify it under the terms of the GNU Library General Public * |
10 | | - * License as published by the Free Software Foundation; either * |
11 | | - * version 2 of the License, or (at your option) any later version. * |
| 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 | 12 | * * |
13 | | - * This library is distributed in the hope that it will be useful, * |
14 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
15 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
16 | | - * GNU Library General Public License for more details. * |
| 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 | 17 | * * |
18 | | - * You should have received a copy of the GNU Library General Public * |
19 | | - * License along with this library; see the file COPYING.LIB. If not, * |
20 | | - * write to the Free Software Foundation, Inc., 59 Temple Place, * |
21 | | - * Suite 330, Boston, MA 02111-1307, USA * |
| 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/>. * |
22 | 21 | * * |
23 | 22 | ***************************************************************************/ |
24 | 23 |
|
@@ -207,9 +206,9 @@ const std::vector<LocalCoordinateSystem::SetupData>& LocalCoordinateSystem::getS |
207 | 206 | { |
208 | 207 | static const std::vector<SetupData> setupData = { |
209 | 208 | // clang-format off |
210 | | - {App::Line::getClassTypeId(), AxisRoles[0], tr("X-axis"), Base::Rotation()}, |
211 | | - {App::Line::getClassTypeId(), AxisRoles[1], tr("Y-axis"), Base::Rotation(Base::Vector3d(1, 1, 1), M_PI * 2 / 3)}, |
212 | | - {App::Line::getClassTypeId(), AxisRoles[2], tr("Z-axis"), Base::Rotation(Base::Vector3d(1,-1, 1), M_PI * 2 / 3)}, |
| 209 | + {App::Line::getClassTypeId(), AxisRoles[0], tr("X-axis"), Base::Rotation(Base::Vector3d(1, 1, 1), M_PI * 2 / 3)}, |
| 210 | + {App::Line::getClassTypeId(), AxisRoles[1], tr("Y-axis"), Base::Rotation(Base::Vector3d(-1, 1, 1), M_PI * 2 / 3)}, |
| 211 | + {App::Line::getClassTypeId(), AxisRoles[2], tr("Z-axis"), Base::Rotation()}, |
213 | 212 | {App::Plane::getClassTypeId(), PlaneRoles[0], tr("XY-plane"), Base::Rotation()}, |
214 | 213 | {App::Plane::getClassTypeId(), PlaneRoles[1], tr("XZ-plane"), Base::Rotation(1.0, 0.0, 0.0, 1.0)}, |
215 | 214 | {App::Plane::getClassTypeId(), PlaneRoles[2], tr("YZ-plane"), Base::Rotation(Base::Vector3d(1, 1, 1), M_PI * 2 / 3)}, |
@@ -277,6 +276,56 @@ void LocalCoordinateSystem::unsetupObject() |
277 | 276 | } |
278 | 277 | } |
279 | 278 |
|
| 279 | +void LocalCoordinateSystem::onDocumentRestored() |
| 280 | +{ |
| 281 | + GeoFeature::onDocumentRestored(); |
| 282 | + |
| 283 | + // In 0.22 origins did not have point. |
| 284 | + migrateOriginPoint(); |
| 285 | + |
| 286 | + // In 0.22 the axis placement were wrong. The X axis had identity placement instead of the Z. |
| 287 | + // This was fixed but we need to migrate old files. |
| 288 | + migrateXAxisPlacement(); |
| 289 | +} |
| 290 | + |
| 291 | +void LocalCoordinateSystem::migrateOriginPoint() |
| 292 | +{ |
| 293 | + auto features = OriginFeatures.getValues(); |
| 294 | + |
| 295 | + auto isOrigin = [](App::DocumentObject* obj) { |
| 296 | + return obj->isDerivedFrom<App::DatumElement>() && |
| 297 | + strcmp(static_cast<App::DatumElement*>(obj)->Role.getValue(), PointRoles[0]) == 0; |
| 298 | + }; |
| 299 | + if (std::none_of(features.begin(), features.end(), isOrigin)) { |
| 300 | + auto data = getData(PointRoles[0]); |
| 301 | + auto* origin = createDatum(data); |
| 302 | + features.push_back(origin); |
| 303 | + OriginFeatures.setValues(features); |
| 304 | + } |
| 305 | +} |
| 306 | + |
| 307 | +void LocalCoordinateSystem::migrateXAxisPlacement() |
| 308 | +{ |
| 309 | + constexpr const double tolerance = 1e-5; |
| 310 | + auto features = OriginFeatures.getValues(); |
| 311 | + |
| 312 | + const auto& setupData = getSetupData(); |
| 313 | + for (auto* obj : features) { |
| 314 | + auto* feature = dynamic_cast <App::DatumElement*> (obj); |
| 315 | + if (!feature) { continue; } |
| 316 | + for (auto data : setupData) { |
| 317 | + // ensure the rotation is correct for the role |
| 318 | + if (std::strcmp(feature->Role.getValue(), data.role) == 0) { |
| 319 | + if (!feature->Placement.getValue().getRotation().isSame(data.rot, tolerance)) { |
| 320 | + feature->Placement.setValue(Base::Placement(Base::Vector3d(), data.rot)); |
| 321 | + getDocument()->setStatus(App::Document::MigrateLCS, true); |
| 322 | + } |
| 323 | + break; |
| 324 | + } |
| 325 | + } |
| 326 | + } |
| 327 | +} |
| 328 | + |
280 | 329 | // ---------------------------------------------------------------------------- |
281 | 330 |
|
282 | 331 | LocalCoordinateSystem::LCSExtension::LCSExtension(LocalCoordinateSystem* obj) |
|
0 commit comments