diff --git a/src/Gui/Command.cpp b/src/Gui/Command.cpp index c7a830945c..a3ddb24cd8 100644 --- a/src/Gui/Command.cpp +++ b/src/Gui/Command.cpp @@ -294,6 +294,12 @@ Application *Command::getGuiApplication() return Application::Instance; } +App::Document* Command::getActiveDocument() const +{ + Gui::Document* doc = getActiveGuiDocument(); + return doc ? doc->getDocument() : nullptr; +} + Gui::Document* Command::getActiveGuiDocument() const { return getGuiApplication()->activeDocument(); @@ -304,22 +310,14 @@ App::Document* Command::getDocument(const char* Name) const if (Name) { return App::GetApplication().getDocument(Name); } - else { - Gui::Document * pcDoc = getGuiApplication()->activeDocument(); - if (pcDoc) - return pcDoc->getDocument(); - else - return nullptr; - } + + return getActiveDocument(); } App::DocumentObject* Command::getObject(const char* Name) const { - App::Document*pDoc = getDocument(); - if (pDoc) - return pDoc->getObject(Name); - else - return nullptr; + App::Document* pDoc = getDocument(); + return pDoc ? pDoc->getObject(Name) : nullptr; } int Command::_busy; diff --git a/src/Gui/Command.h b/src/Gui/Command.h index db158d0596..ca644a9fba 100644 --- a/src/Gui/Command.h +++ b/src/Gui/Command.h @@ -379,6 +379,8 @@ public: static Application* getGuiApplication(); /// Get a reference to the selection static Gui::SelectionSingleton& getSelection(); + /// Get pointer to the active app document + App::Document* getActiveDocument() const; /// Get pointer to the active gui document Gui::Document* getActiveGuiDocument() const; /** Get pointer to the named or active App document diff --git a/src/Mod/Points/App/Points.cpp b/src/Mod/Points/App/Points.cpp index e603bb6a17..169f29491a 100644 --- a/src/Mod/Points/App/Points.cpp +++ b/src/Mod/Points/App/Points.cpp @@ -99,6 +99,21 @@ void PointKernel::transformGeometry(const Base::Matrix4D& rclMat) #endif } +void PointKernel::moveGeometry(const Base::Vector3d& vec) +{ + Base::Vector3f offset = Base::toVector(vec); + std::vector& kernel = getBasicPoints(); +#ifdef _MSC_VER + Concurrency::parallel_for_each(kernel.begin(), kernel.end(), [offset](value_type& value) { + value += offset; + }); +#else + QtConcurrent::blockingMap(kernel, [offset](value_type& value) { + value += offset; + }); +#endif +} + Base::BoundBox3d PointKernel::getBoundBox() const { Base::BoundBox3d bnd; diff --git a/src/Mod/Points/App/Points.h b/src/Mod/Points/App/Points.h index 8ddec22a1e..23e149acfa 100644 --- a/src/Mod/Points/App/Points.h +++ b/src/Mod/Points/App/Points.h @@ -106,6 +106,7 @@ public: double Accuracy, uint16_t flags = 0) const override; void transformGeometry(const Base::Matrix4D& rclMat) override; + void moveGeometry(const Base::Vector3d& vec); Base::BoundBox3d getBoundBox() const override; /** @name I/O */ diff --git a/src/Mod/Points/App/PointsGrid.h b/src/Mod/Points/App/PointsGrid.h index 948bd045fa..bbb5833bf4 100644 --- a/src/Mod/Points/App/PointsGrid.h +++ b/src/Mod/Points/App/PointsGrid.h @@ -31,10 +31,10 @@ #include "Points.h" -#define POINTS_CT_GRID 256 // Default value for number of elements per grid -#define POINTS_MAX_GRIDS 100000 // Default value for maximum number of grids -#define POINTS_CT_GRID_PER_AXIS 20 -#define PONTSGRID_BBOX_EXTENSION 10.0f +static constexpr int POINTS_CT_GRID = 256; // Default value for number of elements per grid +static constexpr int POINTS_MAX_GRIDS = 100000; // Default value for maximum number of grids +static constexpr int POINTS_CT_GRID_PER_AXIS = 20; +static constexpr float PONTSGRID_BBOX_EXTENSION = 10.0F; namespace Points @@ -203,7 +203,7 @@ public: protected: /** Adds a new point element to the grid structure. \a rclPt is the geometric point and \a * ulPtIndex the corresponding index in the point kernel. */ - void AddPoint(const Base::Vector3d& rclPt, unsigned long ulPtIndex, float fEpsilon = 0.0f); + void AddPoint(const Base::Vector3d& rclPt, unsigned long ulPtIndex, float fEpsilon = 0.0F); /** Returns the grid numbers to the given point \a rclPoint. */ void Pos(const Base::Vector3d& rclPoint, unsigned long& rulX, @@ -329,11 +329,9 @@ private: inline Base::BoundBox3d PointsGrid::GetBoundBox(unsigned long ulX, unsigned long ulY, unsigned long ulZ) const { - double fX {}, fY {}, fZ {}; - - fX = _fMinX + (double(ulX) * _fGridLenX); - fY = _fMinY + (double(ulY) * _fGridLenY); - fZ = _fMinZ + (double(ulZ) * _fGridLenZ); + double fX = _fMinX + (double(ulX) * _fGridLenX); + double fY = _fMinY + (double(ulY) * _fGridLenY); + double fZ = _fMinZ + (double(ulZ) * _fGridLenZ); return Base::BoundBox3d(fX, fY, fZ, fX + _fGridLenX, fY + _fGridLenY, fZ + _fGridLenZ); } diff --git a/src/Mod/Points/Gui/Command.cpp b/src/Mod/Points/Gui/Command.cpp index 5aaa6683b8..0663980f2c 100644 --- a/src/Mod/Points/Gui/Command.cpp +++ b/src/Mod/Points/Gui/Command.cpp @@ -89,13 +89,13 @@ void CmdPointsImport::activated(int iMsg) if (!fn.isEmpty()) { fn = Base::Tools::escapeEncodeFilename(fn); - Gui::Document* doc = getActiveGuiDocument(); + App::Document* doc = getActiveDocument(); openCommand(QT_TRANSLATE_NOOP("Command", "Import points")); addModule(Command::App, "Points"); doCommand(Command::Doc, "Points.insert(\"%s\", \"%s\")", fn.toUtf8().data(), - doc->getDocument()->getName()); + doc->getName()); commitCommand(); updateActive(); @@ -105,8 +105,7 @@ void CmdPointsImport::activated(int iMsg) * origin had inaccuracies in the relative positioning of the points due to * imprecise floating point variables used in COIN **/ - auto* pcFtr = dynamic_cast(doc->getDocument()->getActiveObject()); - if (pcFtr) { + if (auto pcFtr = dynamic_cast(doc->getActiveObject())) { auto points = pcFtr->Points.getValue(); auto bbox = points.getBoundBox(); auto center = bbox.GetCenter(); @@ -123,11 +122,9 @@ void CmdPointsImport::activated(int iMsg) auto ret = msgBox.exec(); if (ret == QMessageBox::Yes) { - Points::PointKernel translatedPoints; - for (const auto& point : points) { - translatedPoints.push_back(point - center); - } - pcFtr->Points.setValue(translatedPoints); + Points::PointKernel* kernel = pcFtr->Points.startEditing(); + kernel->moveGeometry(-center); + pcFtr->Points.finishEditing(); } } }