diff --git a/src/Mod/Inspection/App/AppInspection.cpp b/src/Mod/Inspection/App/AppInspection.cpp index 79c0bdab45..d2d79be171 100644 --- a/src/Mod/Inspection/App/AppInspection.cpp +++ b/src/Mod/Inspection/App/AppInspection.cpp @@ -28,13 +28,15 @@ #include "InspectionFeature.h" -namespace Inspection { -class Module : public Py::ExtensionModule +namespace Inspection +{ +class Module: public Py::ExtensionModule { public: - Module() : Py::ExtensionModule("Inspection") + Module() + : Py::ExtensionModule("Inspection") { - initialize("This module is the Inspection module."); // register with Python + initialize("This module is the Inspection module.");// register with Python } private: @@ -45,7 +47,7 @@ PyObject* initModule() return Base::Interpreter().addModule(new Module); } -} // namespace Inspection +}// namespace Inspection /* Python entry */ @@ -56,9 +58,10 @@ PyMOD_INIT_FUNC(Inspection) // PyObject* mod = Inspection::initModule(); Base::Console().Log("Loading Inspection module... done\n"); - + // clang-format off Inspection::PropertyDistanceList ::init(); Inspection::Feature ::init(); Inspection::Group ::init(); + // clang-format on PyMOD_Return(mod); } diff --git a/src/Mod/Inspection/App/InspectionFeature.cpp b/src/Mod/Inspection/App/InspectionFeature.cpp index 3af64c1b9a..ed495f271e 100644 --- a/src/Mod/Inspection/App/InspectionFeature.cpp +++ b/src/Mod/Inspection/App/InspectionFeature.cpp @@ -23,16 +23,16 @@ #include "PreCompiled.h" #ifndef _PreComp_ -#include #include +#include -#include #include #include +#include #include -#include #include #include +#include #include #include @@ -45,14 +45,14 @@ #include #include -#include #include #include #include #include +#include +#include #include #include -#include #include "InspectionFeature.h" @@ -60,7 +60,8 @@ using namespace Inspection; namespace sp = std::placeholders; -InspectActualMesh::InspectActualMesh(const Mesh::MeshObject& rMesh) : _mesh(rMesh.getKernel()) +InspectActualMesh::InspectActualMesh(const Mesh::MeshObject& rMesh) + : _mesh(rMesh.getKernel()) { Base::Matrix4D tmp; _clTrf = rMesh.getTransform(); @@ -85,9 +86,9 @@ Base::Vector3f InspectActualMesh::getPoint(unsigned long index) const // ---------------------------------------------------------------- -InspectActualPoints::InspectActualPoints(const Points::PointKernel& rPoints) : _rKernel(rPoints) -{ -} +InspectActualPoints::InspectActualPoints(const Points::PointKernel& rPoints) + : _rKernel(rPoints) +{} unsigned long InspectActualPoints::countPoints() const { @@ -102,7 +103,8 @@ Base::Vector3f InspectActualPoints::getPoint(unsigned long index) const // ---------------------------------------------------------------- -InspectActualShape::InspectActualShape(const Part::TopoShape& shape) : _rShape(shape) +InspectActualShape::InspectActualShape(const Part::TopoShape& shape) + : _rShape(shape) { Standard_Real deflection = _rShape.getAccuracy(); fetchPoints(deflection); @@ -142,158 +144,167 @@ Base::Vector3f InspectActualShape::getPoint(unsigned long index) const // ---------------------------------------------------------------- -namespace Inspection { - class MeshInspectGrid : public MeshCore::MeshGrid +namespace Inspection +{ +class MeshInspectGrid: public MeshCore::MeshGrid +{ +public: + MeshInspectGrid(const MeshCore::MeshKernel& mesh, float fGridLen, const Base::Matrix4D& mat) + : MeshCore::MeshGrid(mesh) + , _transform(mat) { - public: - MeshInspectGrid (const MeshCore::MeshKernel &mesh, float fGridLen, const Base::Matrix4D& mat) - : MeshCore::MeshGrid(mesh), _transform(mat) - { - Base::BoundBox3f clBBMesh = _pclMesh->GetBoundBox().Transformed(mat); - Rebuild(std::max((unsigned long)(clBBMesh.LengthX() / fGridLen), 1), - std::max((unsigned long)(clBBMesh.LengthY() / fGridLen), 1), - std::max((unsigned long)(clBBMesh.LengthZ() / fGridLen), 1)); - } + Base::BoundBox3f clBBMesh = _pclMesh->GetBoundBox().Transformed(mat); + Rebuild(std::max((unsigned long)(clBBMesh.LengthX() / fGridLen), 1), + std::max((unsigned long)(clBBMesh.LengthY() / fGridLen), 1), + std::max((unsigned long)(clBBMesh.LengthZ() / fGridLen), 1)); + } - void Validate (const MeshCore::MeshKernel& kernel) override - { - // do nothing - boost::ignore_unused(kernel); - } + void Validate(const MeshCore::MeshKernel& kernel) override + { + // do nothing + boost::ignore_unused(kernel); + } - void Validate () - { - // do nothing - } + void Validate() + { + // do nothing + } - bool Verify() const override - { - // do nothing - return true; - } + bool Verify() const override + { + // do nothing + return true; + } - protected: - void CalculateGridLength (unsigned long /*ulCtGrid*/, unsigned long /*ulMaxGrids*/) override - { - // do nothing - } +protected: + void CalculateGridLength(unsigned long /*ulCtGrid*/, unsigned long /*ulMaxGrids*/) override + { + // do nothing + } - void CalculateGridLength (int /*iCtGridPerAxis*/) override - { - // do nothing - } + void CalculateGridLength(int /*iCtGridPerAxis*/) override + { + // do nothing + } - unsigned long HasElements () const override - { - return _pclMesh->CountFacets(); - } + unsigned long HasElements() const override + { + return _pclMesh->CountFacets(); + } - void Pos (const Base::Vector3f &rclPoint, unsigned long &rulX, unsigned long &rulY, unsigned long &rulZ) const - { - rulX = (unsigned long)((rclPoint.x - _fMinX) / _fGridLenX); - rulY = (unsigned long)((rclPoint.y - _fMinY) / _fGridLenY); - rulZ = (unsigned long)((rclPoint.z - _fMinZ) / _fGridLenZ); + void Pos(const Base::Vector3f& rclPoint, + unsigned long& rulX, + unsigned long& rulY, + unsigned long& rulZ) const + { + rulX = (unsigned long)((rclPoint.x - _fMinX) / _fGridLenX); + rulY = (unsigned long)((rclPoint.y - _fMinY) / _fGridLenY); + rulZ = (unsigned long)((rclPoint.z - _fMinZ) / _fGridLenZ); - assert((rulX < _ulCtGridsX) && (rulY < _ulCtGridsY) && (rulZ < _ulCtGridsZ)); - } + assert((rulX < _ulCtGridsX) && (rulY < _ulCtGridsY) && (rulZ < _ulCtGridsZ)); + } - void AddFacet (const MeshCore::MeshGeomFacet &rclFacet, unsigned long ulFacetIndex) - { - unsigned long ulX1; - unsigned long ulY1; - unsigned long ulZ1; - unsigned long ulX2; - unsigned long ulY2; - unsigned long ulZ2; + void AddFacet(const MeshCore::MeshGeomFacet& rclFacet, unsigned long ulFacetIndex) + { + unsigned long ulX1; + unsigned long ulY1; + unsigned long ulZ1; + unsigned long ulX2; + unsigned long ulY2; + unsigned long ulZ2; - Base::BoundBox3f clBB; - clBB.Add(rclFacet._aclPoints[0]); - clBB.Add(rclFacet._aclPoints[1]); - clBB.Add(rclFacet._aclPoints[2]); + Base::BoundBox3f clBB; + clBB.Add(rclFacet._aclPoints[0]); + clBB.Add(rclFacet._aclPoints[1]); + clBB.Add(rclFacet._aclPoints[2]); - Pos(Base::Vector3f(clBB.MinX,clBB.MinY,clBB.MinZ), ulX1, ulY1, ulZ1); - Pos(Base::Vector3f(clBB.MaxX,clBB.MaxY,clBB.MaxZ), ulX2, ulY2, ulZ2); - + Pos(Base::Vector3f(clBB.MinX, clBB.MinY, clBB.MinZ), ulX1, ulY1, ulZ1); + Pos(Base::Vector3f(clBB.MaxX, clBB.MaxY, clBB.MaxZ), ulX2, ulY2, ulZ2); - if ((ulX1 < ulX2) || (ulY1 < ulY2) || (ulZ1 < ulZ2)) { - for (unsigned long ulX = ulX1; ulX <= ulX2; ulX++) { - for (unsigned long ulY = ulY1; ulY <= ulY2; ulY++) { - for (unsigned long ulZ = ulZ1; ulZ <= ulZ2; ulZ++) { - if (rclFacet.IntersectBoundingBox(GetBoundBox(ulX, ulY, ulZ))) - _aulGrid[ulX][ulY][ulZ].insert(ulFacetIndex); + + if ((ulX1 < ulX2) || (ulY1 < ulY2) || (ulZ1 < ulZ2)) { + for (unsigned long ulX = ulX1; ulX <= ulX2; ulX++) { + for (unsigned long ulY = ulY1; ulY <= ulY2; ulY++) { + for (unsigned long ulZ = ulZ1; ulZ <= ulZ2; ulZ++) { + if (rclFacet.IntersectBoundingBox(GetBoundBox(ulX, ulY, ulZ))) { + _aulGrid[ulX][ulY][ulZ].insert(ulFacetIndex); } } } } - else { - _aulGrid[ulX1][ulY1][ulZ1].insert(ulFacetIndex); + } + else { + _aulGrid[ulX1][ulY1][ulZ1].insert(ulFacetIndex); + } + } + + void InitGrid() override + { + unsigned long i, j; + + Base::BoundBox3f clBBMesh = _pclMesh->GetBoundBox().Transformed(_transform); + + float fLengthX = clBBMesh.LengthX(); + float fLengthY = clBBMesh.LengthY(); + float fLengthZ = clBBMesh.LengthZ(); + + _fGridLenX = (1.0f + fLengthX) / float(_ulCtGridsX); + _fMinX = clBBMesh.MinX - 0.5f; + + _fGridLenY = (1.0f + fLengthY) / float(_ulCtGridsY); + _fMinY = clBBMesh.MinY - 0.5f; + + _fGridLenZ = (1.0f + fLengthZ) / float(_ulCtGridsZ); + _fMinZ = clBBMesh.MinZ - 0.5f; + + _aulGrid.clear(); + _aulGrid.resize(_ulCtGridsX); + for (i = 0; i < _ulCtGridsX; i++) { + _aulGrid[i].resize(_ulCtGridsY); + for (j = 0; j < _ulCtGridsY; j++) { + _aulGrid[i][j].resize(_ulCtGridsZ); } } + } - void InitGrid () override - { - unsigned long i, j; + void RebuildGrid() override + { + _ulCtElements = _pclMesh->CountFacets(); + InitGrid(); - Base::BoundBox3f clBBMesh = _pclMesh->GetBoundBox().Transformed(_transform); - - float fLengthX = clBBMesh.LengthX(); - float fLengthY = clBBMesh.LengthY(); - float fLengthZ = clBBMesh.LengthZ(); - - _fGridLenX = (1.0f + fLengthX) / float(_ulCtGridsX); - _fMinX = clBBMesh.MinX - 0.5f; - - _fGridLenY = (1.0f + fLengthY) / float(_ulCtGridsY); - _fMinY = clBBMesh.MinY - 0.5f; - - _fGridLenZ = (1.0f + fLengthZ) / float(_ulCtGridsZ); - _fMinZ = clBBMesh.MinZ - 0.5f; - - _aulGrid.clear(); - _aulGrid.resize(_ulCtGridsX); - for (i = 0; i < _ulCtGridsX; i++) { - _aulGrid[i].resize(_ulCtGridsY); - for (j = 0; j < _ulCtGridsY; j++) - _aulGrid[i][j].resize(_ulCtGridsZ); - } + unsigned long i = 0; + MeshCore::MeshFacetIterator clFIter(*_pclMesh); + clFIter.Transform(_transform); + for (clFIter.Init(); clFIter.More(); clFIter.Next()) { + AddFacet(*clFIter, i++); } + } - void RebuildGrid () override - { - _ulCtElements = _pclMesh->CountFacets(); - InitGrid(); - - unsigned long i = 0; - MeshCore::MeshFacetIterator clFIter(*_pclMesh); - clFIter.Transform(_transform); - for (clFIter.Init(); clFIter.More(); clFIter.Next()) { - AddFacet(*clFIter, i++); - } - } +private: + Base::Matrix4D _transform; +}; +}// namespace Inspection - private: - Base::Matrix4D _transform; - }; -} - -InspectNominalMesh::InspectNominalMesh(const Mesh::MeshObject& rMesh, float offset) : _mesh(rMesh.getKernel()) +InspectNominalMesh::InspectNominalMesh(const Mesh::MeshObject& rMesh, float offset) + : _mesh(rMesh.getKernel()) { Base::Matrix4D tmp; _clTrf = rMesh.getTransform(); _bApply = _clTrf != tmp; // Max. limit of grid elements - float fMaxGridElements=8000000.0f; + float fMaxGridElements = 8000000.0f; Base::BoundBox3f box = _mesh.GetBoundBox().Transformed(rMesh.getTransform()); // estimate the minimum allowed grid length - float fMinGridLen = (float)pow((box.LengthX()*box.LengthY()*box.LengthZ()/fMaxGridElements), 0.3333f); + float fMinGridLen = + (float)pow((box.LengthX() * box.LengthY() * box.LengthZ() / fMaxGridElements), 0.3333f); float fGridLen = 5.0f * MeshCore::MeshAlgorithm(_mesh).GetAverageEdgeLength(); - // We want to avoid to get too small grid elements otherwise building up the grid structure would take - // too much time and memory. - // Having quite a dense grid speeds up more the following algorithms extremely. Due to the issue above it's - // always a compromise between speed and memory usage. + // We want to avoid to get too small grid elements otherwise building up the grid structure + // would take too much time and memory. Having quite a dense grid speeds up more the following + // algorithms extremely. Due to the issue above it's always a compromise between speed and + // memory usage. fGridLen = std::max(fMinGridLen, fGridLen); // build up grid structure to speed up algorithms @@ -309,8 +320,9 @@ InspectNominalMesh::~InspectNominalMesh() float InspectNominalMesh::getDistance(const Base::Vector3f& point) const { - if (!_box.IsInBox(point)) - return FLT_MAX; // must be inside bbox + if (!_box.IsInBox(point)) { + return FLT_MAX;// must be inside bbox + } std::vector indices; //_pGrid->GetElements(point, indices); @@ -320,7 +332,7 @@ float InspectNominalMesh::getDistance(const Base::Vector3f& point) const indices.insert(indices.begin(), inds.begin(), inds.end()); } - float fMinDist=FLT_MAX; + float fMinDist = FLT_MAX; bool positive = true; for (unsigned long it : indices) { MeshCore::MeshGeomFacet geomFace = _mesh.GetFacet(it); @@ -335,14 +347,16 @@ float InspectNominalMesh::getDistance(const Base::Vector3f& point) const } } - if (!positive) + if (!positive) { fMinDist = -fMinDist; + } return fMinDist; } // ---------------------------------------------------------------- -InspectNominalFastMesh::InspectNominalFastMesh(const Mesh::MeshObject& rMesh, float offset) : _mesh(rMesh.getKernel()) +InspectNominalFastMesh::InspectNominalFastMesh(const Mesh::MeshObject& rMesh, float offset) + : _mesh(rMesh.getKernel()) { const MeshCore::MeshKernel& kernel = rMesh.getKernel(); @@ -351,24 +365,25 @@ InspectNominalFastMesh::InspectNominalFastMesh(const Mesh::MeshObject& rMesh, fl _bApply = _clTrf != tmp; // Max. limit of grid elements - float fMaxGridElements=8000000.0f; + float fMaxGridElements = 8000000.0f; Base::BoundBox3f box = kernel.GetBoundBox().Transformed(rMesh.getTransform()); // estimate the minimum allowed grid length - float fMinGridLen = (float)pow((box.LengthX()*box.LengthY()*box.LengthZ()/fMaxGridElements), 0.3333f); + float fMinGridLen = + (float)pow((box.LengthX() * box.LengthY() * box.LengthZ() / fMaxGridElements), 0.3333f); float fGridLen = 5.0f * MeshCore::MeshAlgorithm(kernel).GetAverageEdgeLength(); - // We want to avoid to get too small grid elements otherwise building up the grid structure would take - // too much time and memory. - // Having quite a dense grid speeds up more the following algorithms extremely. Due to the issue above it's - // always a compromise between speed and memory usage. + // We want to avoid to get too small grid elements otherwise building up the grid structure + // would take too much time and memory. Having quite a dense grid speeds up more the following + // algorithms extremely. Due to the issue above it's always a compromise between speed and + // memory usage. fGridLen = std::max(fMinGridLen, fGridLen); // build up grid structure to speed up algorithms _pGrid = new MeshInspectGrid(kernel, fGridLen, rMesh.getTransform()); _box = box; _box.Enlarge(offset); - max_level = (unsigned long)(offset/fGridLen); + max_level = (unsigned long)(offset / fGridLen); } InspectNominalFastMesh::~InspectNominalFastMesh() @@ -382,11 +397,12 @@ InspectNominalFastMesh::~InspectNominalFastMesh() */ float InspectNominalFastMesh::getDistance(const Base::Vector3f& point) const { - if (!_box.IsInBox(point)) - return FLT_MAX; // must be inside bbox + if (!_box.IsInBox(point)) { + return FLT_MAX;// must be inside bbox + } std::set indices; -#if 0 // a point in a neighbour grid can be nearer +#if 0// a point in a neighbour grid can be nearer std::vector elements; _pGrid->GetElements(point, elements); indices.insert(elements.begin(), elements.end()); @@ -394,13 +410,15 @@ float InspectNominalFastMesh::getDistance(const Base::Vector3f& point) const unsigned long ulX, ulY, ulZ; _pGrid->Position(point, ulX, ulY, ulZ); unsigned long ulLevel = 0; - while (indices.empty() && ulLevel <= max_level) + while (indices.empty() && ulLevel <= max_level) { _pGrid->GetHull(ulX, ulY, ulZ, ulLevel++, indices); - if (indices.empty() || ulLevel==1) + } + if (indices.empty() || ulLevel == 1) { _pGrid->GetHull(ulX, ulY, ulZ, ulLevel, indices); + } #endif - float fMinDist=FLT_MAX; + float fMinDist = FLT_MAX; bool positive = true; for (unsigned long it : indices) { MeshCore::MeshGeomFacet geomFace = _mesh.GetFacet(it); @@ -415,18 +433,19 @@ float InspectNominalFastMesh::getDistance(const Base::Vector3f& point) const } } - if (!positive) + if (!positive) { fMinDist = -fMinDist; + } return fMinDist; } // ---------------------------------------------------------------- InspectNominalPoints::InspectNominalPoints(const Points::PointKernel& Kernel, float /*offset*/) - : _rKernel(Kernel) + : _rKernel(Kernel) { - int uGridPerAxis = 50; // totally 125.000 grid elements - this->_pGrid = new Points::PointsGrid (Kernel, uGridPerAxis); + int uGridPerAxis = 50;// totally 125.000 grid elements + this->_pGrid = new Points::PointsGrid(Kernel, uGridPerAxis); } InspectNominalPoints::~InspectNominalPoints() @@ -436,14 +455,14 @@ InspectNominalPoints::~InspectNominalPoints() float InspectNominalPoints::getDistance(const Base::Vector3f& point) const { - //TODO: Make faster + // TODO: Make faster std::set indices; - unsigned long x,y,z; - Base::Vector3d pointd(point.x,point.y,point.z); + unsigned long x, y, z; + Base::Vector3d pointd(point.x, point.y, point.z); _pGrid->Position(pointd, x, y, z); - _pGrid->GetElements(x,y,z,indices); + _pGrid->GetElements(x, y, z, indices); - double fMinDist=DBL_MAX; + double fMinDist = DBL_MAX; for (unsigned long it : indices) { Base::Vector3d pt = _rKernel.getPoint(it); double fDist = Base::Distance(pointd, pt); @@ -469,12 +488,11 @@ InspectNominalShape::InspectNominalShape(const TopoDS_Shape& shape, float /*radi TopExp_Explorer xp; xp.Init(_rShape, TopAbs_SHELL); if (xp.More()) { - distss->LoadS1(xp.Current()); - isSolid = true; + distss->LoadS1(xp.Current()); + isSolid = true; } - } - //distss->SetDeflection(radius); + // distss->SetDeflection(radius); } InspectNominalShape::~InspectNominalShape() @@ -484,22 +502,24 @@ InspectNominalShape::~InspectNominalShape() float InspectNominalShape::getDistance(const Base::Vector3f& point) const { - gp_Pnt pnt3d(point.x,point.y,point.z); + gp_Pnt pnt3d(point.x, point.y, point.z); BRepBuilderAPI_MakeVertex mkVert(pnt3d); distss->LoadS2(mkVert.Vertex()); - float fMinDist=FLT_MAX; + float fMinDist = FLT_MAX; if (distss->Perform() && distss->NbSolution() > 0) { fMinDist = (float)distss->Value(); // the shape is a solid, check if the vertex is inside if (isSolid) { - if (isInsideSolid(pnt3d)) + if (isInsideSolid(pnt3d)) { fMinDist = -fMinDist; + } } else if (fMinDist > 0) { // check if the distance was computed from a face - if (isBelowFace(pnt3d)) + if (isBelowFace(pnt3d)) { fMinDist = -fMinDist; + } } } return fMinDist; @@ -521,7 +541,7 @@ bool InspectNominalShape::isBelowFace(const gp_Pnt& pnt3d) const TopoDS_Shape face = distss->SupportOnShape1(index); Standard_Real u, v; distss->ParOnFaceS1(index, u, v); - //gp_Pnt pnt = distss->PointOnShape1(index); + // gp_Pnt pnt = distss->PointOnShape1(index); BRepGProp_Face props(TopoDS::Face(face)); gp_Vec normal; gp_Pnt center; @@ -560,7 +580,7 @@ void PropertyDistanceList::setValue(float lValue) { aboutToSetValue(); _lValueList.resize(1); - _lValueList[0]=lValue; + _lValueList[0] = lValue; hasSetValue(); } @@ -571,29 +591,30 @@ void PropertyDistanceList::setValues(const std::vector& values) hasSetValue(); } -PyObject *PropertyDistanceList::getPyObject() +PyObject* PropertyDistanceList::getPyObject() { PyObject* list = PyList_New(getSize()); - for (int i = 0;i values; values.resize(nSize); - for (Py_ssize_t i=0; iob_type->tp_name; throw Py::TypeError(error); } - + values[i] = (float)PyFloat_AsDouble(item); } @@ -601,7 +622,7 @@ void PropertyDistanceList::setPyObject(PyObject *value) } else if (PyFloat_Check(value)) { setValue((float)PyFloat_AsDouble(value)); - } + } else { std::string error = std::string("type must be float or list of float, not "); error += value->ob_type->tp_name; @@ -609,34 +630,35 @@ void PropertyDistanceList::setPyObject(PyObject *value) } } -void PropertyDistanceList::Save (Base::Writer &writer) const +void PropertyDistanceList::Save(Base::Writer& writer) const { if (writer.isForceXML()) { - writer.Stream() << writer.ind() << "" << std::endl; + writer.Stream() << writer.ind() << "" << std::endl; writer.incInd(); - for(int i = 0;i" << std::endl; + for (int i = 0; i < getSize(); i++) { + writer.Stream() << writer.ind() << "" << std::endl; + } writer.decInd(); - writer.Stream() << writer.ind() <<"" << std::endl; + writer.Stream() << writer.ind() << "" << std::endl; } else { - writer.Stream() << writer.ind() << "" << std::endl; + writer.Stream() << writer.ind() << "" << std::endl; } } -void PropertyDistanceList::Restore(Base::XMLReader &reader) +void PropertyDistanceList::Restore(Base::XMLReader& reader) { reader.readElement("FloatList"); - std::string file (reader.getAttribute("file") ); + std::string file(reader.getAttribute("file")); if (!file.empty()) { // initiate a file read - reader.addFile(file.c_str(),this); + reader.addFile(file.c_str(), this); } } -void PropertyDistanceList::SaveDocFile (Base::Writer &writer) const +void PropertyDistanceList::SaveDocFile(Base::Writer& writer) const { Base::OutputStream str(writer.Stream()); uint32_t uCt = (uint32_t)getSize(); @@ -646,10 +668,10 @@ void PropertyDistanceList::SaveDocFile (Base::Writer &writer) const } } -void PropertyDistanceList::RestoreDocFile(Base::Reader &reader) +void PropertyDistanceList::RestoreDocFile(Base::Reader& reader) { Base::InputStream str(reader); - uint32_t uCt=0; + uint32_t uCt = 0; str >> uCt; std::vector values(uCt); for (float& it : values) { @@ -658,66 +680,74 @@ void PropertyDistanceList::RestoreDocFile(Base::Reader &reader) setValues(values); } -App::Property *PropertyDistanceList::Copy() const +App::Property* PropertyDistanceList::Copy() const { - PropertyDistanceList *p= new PropertyDistanceList(); + PropertyDistanceList* p = new PropertyDistanceList(); p->_lValueList = _lValueList; return p; } -void PropertyDistanceList::Paste(const App::Property &from) +void PropertyDistanceList::Paste(const App::Property& from) { aboutToSetValue(); _lValueList = dynamic_cast(from)._lValueList; hasSetValue(); } -unsigned int PropertyDistanceList::getMemSize () const +unsigned int PropertyDistanceList::getMemSize() const { return static_cast(_lValueList.size() * sizeof(float)); } // ---------------------------------------------------------------- -namespace Inspection { +namespace Inspection +{ // helper class to use Qt's concurrent framework struct DistanceInspection { - DistanceInspection(float radius, InspectActualGeometry* a, + DistanceInspection(float radius, + InspectActualGeometry* a, std::vector n) - : radius(radius), actual(a), nominal(n) - { - } + : radius(radius) + , actual(a) + , nominal(n) + {} float mapped(unsigned long index) const { Base::Vector3f pnt = actual->getPoint(index); - float fMinDist=FLT_MAX; + float fMinDist = FLT_MAX; for (auto it : nominal) { float fDist = it->getDistance(pnt); - if (fabs(fDist) < fabs(fMinDist)) + if (fabs(fDist) < fabs(fMinDist)) { fMinDist = fDist; + } } - if (fMinDist > this->radius) + if (fMinDist > this->radius) { fMinDist = FLT_MAX; - else if (-fMinDist > this->radius) + } + else if (-fMinDist > this->radius) { fMinDist = -FLT_MAX; + } return fMinDist; } float radius; - InspectActualGeometry* actual; + InspectActualGeometry* actual; std::vector nominal; }; -// Helper internal class for QtConcurrent map operation. Holds sums-of-squares and counts for RMS calculation -class DistanceInspectionRMS { +// Helper internal class for QtConcurrent map operation. Holds sums-of-squares and counts for RMS +// calculation +class DistanceInspectionRMS +{ public: DistanceInspectionRMS() = default; - DistanceInspectionRMS& operator += (const DistanceInspectionRMS& rhs) + DistanceInspectionRMS& operator+=(const DistanceInspectionRMS& rhs) { this->m_numv += rhs.m_numv; this->m_sumsq += rhs.m_sumsq; @@ -725,38 +755,43 @@ public: } double getRMS() { - if (this->m_numv == 0) + if (this->m_numv == 0) { return 0.0; + } return sqrt(this->m_sumsq / (double)this->m_numv); } - int m_numv{0}; - double m_sumsq{0.0}; + int m_numv {0}; + double m_sumsq {0.0}; }; -} +}// namespace Inspection PROPERTY_SOURCE(Inspection::Feature, App::DocumentObject) Feature::Feature() { - ADD_PROPERTY(SearchRadius,(0.05)); - ADD_PROPERTY(Thickness,(0.0)); - ADD_PROPERTY(Actual,(nullptr)); - ADD_PROPERTY(Nominals,(nullptr)); - ADD_PROPERTY(Distances,(0.0)); + ADD_PROPERTY(SearchRadius, (0.05)); + ADD_PROPERTY(Thickness, (0.0)); + ADD_PROPERTY(Actual, (nullptr)); + ADD_PROPERTY(Nominals, (nullptr)); + ADD_PROPERTY(Distances, (0.0)); } Feature::~Feature() = default; short Feature::mustExecute() const { - if (SearchRadius.isTouched()) + if (SearchRadius.isTouched()) { return 1; - if (Thickness.isTouched()) + } + if (Thickness.isTouched()) { return 1; - if (Actual.isTouched()) + } + if (Actual.isTouched()) { return 1; - if (Nominals.isTouched()) + } + if (Nominals.isTouched()) { return 1; + } return 0; } @@ -765,8 +800,9 @@ App::DocumentObjectExecReturn* Feature::execute() bool useMultithreading = true; App::DocumentObject* pcActual = Actual.getValue(); - if (!pcActual) + if (!pcActual) { throw Base::ValueError("No actual geometry to inspect specified"); + } InspectActualGeometry* actual = nullptr; if (pcActual->getTypeId().isDerivedFrom(Mesh::Feature::getClassTypeId())) { @@ -786,6 +822,7 @@ App::DocumentObjectExecReturn* Feature::execute() throw Base::TypeError("Unknown geometric type"); } + // clang-format off // get a list of nominals std::vector inspectNominal; const std::vector& nominals = Nominals.getValues(); @@ -805,12 +842,14 @@ App::DocumentObjectExecReturn* Feature::execute() nominal = new InspectNominalShape(part->Shape.getValue(), this->SearchRadius.getValue()); } - if (nominal) + if (nominal) { inspectNominal.push_back(nominal); + } } + // clang-format on #if 0 -#if 1 // test with some huge data sets +#if 1// test with some huge data sets std::vector index(actual->countPoints()); std::generate(index.begin(), index.end(), Base::iotaGen(0)); DistanceInspection check(this->SearchRadius.getValue(), actual, inspectNominal); @@ -866,16 +905,16 @@ App::DocumentObjectExecReturn* Feature::execute() #else unsigned long count = actual->countPoints(); std::vector vals(count); - std::function fMap = [&](unsigned int index) - { + std::function fMap = [&](unsigned int index) { DistanceInspectionRMS res; Base::Vector3f pnt = actual->getPoint(index); float fMinDist = FLT_MAX; for (auto it : inspectNominal) { float fDist = it->getDistance(pnt); - if (fabs(fDist) < fabs(fMinDist)) + if (fabs(fDist) < fabs(fMinDist)) { fMinDist = fDist; + } } if (fMinDist > this->SearchRadius.getValue()) { @@ -899,18 +938,23 @@ App::DocumentObjectExecReturn* Feature::execute() // Build vector of increasing indices std::vector index(count); std::iota(index.begin(), index.end(), 0); - // Perform map-reduce operation : compute distances and update sum of squares for RMS computation - QFuture future = QtConcurrent::mappedReduced( - index, fMap, &DistanceInspectionRMS::operator+=); + // Perform map-reduce operation : compute distances and update sum of squares for RMS + // computation + QFuture future = + QtConcurrent::mappedReduced(index, fMap, &DistanceInspectionRMS::operator+=); // Setup progress bar Base::FutureWatcherProgress progress("Inspecting...", actual->countPoints()); QFutureWatcher watcher; - QObject::connect(&watcher, &QFutureWatcher::progressValueChanged, - &progress, &Base::FutureWatcherProgress::progressValueChanged); + QObject::connect(&watcher, + &QFutureWatcher::progressValueChanged, + &progress, + &Base::FutureWatcherProgress::progressValueChanged); // Keep UI responsive during computation QEventLoop loop; - QObject::connect(&watcher, &QFutureWatcher::finished, - &loop, &QEventLoop::quit); + QObject::connect(&watcher, + &QFutureWatcher::finished, + &loop, + &QEventLoop::quit); watcher.setFuture(future); loop.exec(); res = future.result(); @@ -921,18 +965,23 @@ App::DocumentObjectExecReturn* Feature::execute() str << "Inspecting " << this->Label.getValue() << "..."; Base::SequencerLauncher seq(str.str().c_str(), count); - for (unsigned int i = 0; i < count; i++) + for (unsigned int i = 0; i < count; i++) { res += fMap(i); + } } Base::Console().Message("RMS value for '%s' with search radius [%.4f,%.4f] is: %.4f\n", - this->Label.getValue(), -this->SearchRadius.getValue(), this->SearchRadius.getValue(), res.getRMS()); + this->Label.getValue(), + -this->SearchRadius.getValue(), + this->SearchRadius.getValue(), + res.getRMS()); Distances.setValues(vals); #endif delete actual; - for (auto it : inspectNominal) + for (auto it : inspectNominal) { delete it; + } return nullptr; } diff --git a/src/Mod/Inspection/App/InspectionFeature.h b/src/Mod/Inspection/App/InspectionFeature.h index d9c9f1bb86..8df16b0fbc 100644 --- a/src/Mod/Inspection/App/InspectionFeature.h +++ b/src/Mod/Inspection/App/InspectionFeature.h @@ -26,22 +26,32 @@ #include #include -#include #include +#include class TopoDS_Shape; class BRepExtrema_DistShapeShape; class gp_Pnt; -namespace MeshCore { +namespace MeshCore +{ class MeshKernel; class MeshGrid; -} +}// namespace MeshCore -namespace Mesh { class MeshObject; } -namespace Points { class PointsGrid; } -namespace Part { class TopoShape; } +namespace Mesh +{ +class MeshObject; +} +namespace Points +{ +class PointsGrid; +} +namespace Part +{ +class TopoShape; +} namespace Inspection { @@ -57,7 +67,7 @@ public: virtual Base::Vector3f getPoint(unsigned long) const = 0; }; -class InspectionExport InspectActualMesh : public InspectActualGeometry +class InspectionExport InspectActualMesh: public InspectActualGeometry { public: explicit InspectActualMesh(const Mesh::MeshObject& rMesh); @@ -71,7 +81,7 @@ private: Base::Matrix4D _clTrf; }; -class InspectionExport InspectActualPoints : public InspectActualGeometry +class InspectionExport InspectActualPoints: public InspectActualGeometry { public: explicit InspectActualPoints(const Points::PointKernel&); @@ -82,7 +92,7 @@ private: const Points::PointKernel& _rKernel; }; -class InspectionExport InspectActualShape : public InspectActualGeometry +class InspectionExport InspectActualShape: public InspectActualGeometry { public: explicit InspectActualShape(const Part::TopoShape&); @@ -106,7 +116,7 @@ public: virtual float getDistance(const Base::Vector3f&) const = 0; }; -class InspectionExport InspectNominalMesh : public InspectNominalGeometry +class InspectionExport InspectNominalMesh: public InspectNominalGeometry { public: InspectNominalMesh(const Mesh::MeshObject& rMesh, float offset); @@ -121,7 +131,7 @@ private: Base::Matrix4D _clTrf; }; -class InspectionExport InspectNominalFastMesh : public InspectNominalGeometry +class InspectionExport InspectNominalFastMesh: public InspectNominalGeometry { public: InspectNominalFastMesh(const Mesh::MeshObject& rMesh, float offset); @@ -137,7 +147,7 @@ protected: Base::Matrix4D _clTrf; }; -class InspectionExport InspectNominalPoints : public InspectNominalGeometry +class InspectionExport InspectNominalPoints: public InspectNominalGeometry { public: InspectNominalPoints(const Points::PointKernel&, float offset); @@ -149,7 +159,7 @@ private: Points::PointsGrid* _pGrid; }; -class InspectionExport InspectNominalShape : public InspectNominalGeometry +class InspectionExport InspectNominalShape: public InspectNominalGeometry { public: InspectNominalShape(const TopoDS_Shape&, float offset); @@ -163,7 +173,7 @@ private: private: BRepExtrema_DistShapeShape* distss; const TopoDS_Shape& _rShape; - bool isSolid{false}; + bool isSolid {false}; }; class InspectionExport PropertyDistanceList: public App::PropertyLists @@ -171,46 +181,54 @@ class InspectionExport PropertyDistanceList: public App::PropertyLists TYPESYSTEM_HEADER_WITH_OVERRIDE(); public: - /** * A constructor. * A more elaborate description of the constructor. */ PropertyDistanceList(); - + /** * A destructor. * A more elaborate description of the destructor. */ ~PropertyDistanceList() override; - + void setSize(int newSize) override; int getSize() const override; - /** Sets the property + /** Sets the property */ void setValue(float); - + /// index operator - float operator[] (const int idx) const {return _lValueList.operator[] (idx);} - - void set1Value (const int idx, float value){_lValueList.operator[] (idx) = value;} - void setValues (const std::vector& values); - - const std::vector &getValues() const{return _lValueList;} - - PyObject *getPyObject() override; - void setPyObject(PyObject *) override; - - void Save (Base::Writer &writer) const override; - void Restore(Base::XMLReader &reader) override; - - void SaveDocFile (Base::Writer &writer) const override; - void RestoreDocFile(Base::Reader &reader) override; - - Property *Copy() const override; - void Paste(const Property &from) override; - unsigned int getMemSize () const override; + float operator[](const int idx) const + { + return _lValueList.operator[](idx); + } + + void set1Value(const int idx, float value) + { + _lValueList.operator[](idx) = value; + } + void setValues(const std::vector& values); + + const std::vector& getValues() const + { + return _lValueList; + } + + PyObject* getPyObject() override; + void setPyObject(PyObject*) override; + + void Save(Base::Writer& writer) const override; + void Restore(Base::XMLReader& reader) override; + + void SaveDocFile(Base::Writer& writer) const override; + void RestoreDocFile(Base::Reader& reader) override; + + Property* Copy() const override; + void Paste(const Property& from) override; + unsigned int getMemSize() const override; private: std::vector _lValueList; @@ -221,7 +239,7 @@ private: /** The inspection feature. * \author Werner Mayer */ -class InspectionExport Feature : public App::DocumentObject +class InspectionExport Feature: public App::DocumentObject { PROPERTY_HEADER_WITH_OVERRIDE(Inspection::Feature); @@ -232,11 +250,11 @@ public: /** @name Properties */ //@{ - App::PropertyFloat SearchRadius; - App::PropertyFloat Thickness; - App::PropertyLink Actual; - App::PropertyLinkList Nominals; - PropertyDistanceList Distances; + App::PropertyFloat SearchRadius; + App::PropertyFloat Thickness; + App::PropertyLink Actual; + App::PropertyLinkList Nominals; + PropertyDistanceList Distances; //@} /** @name Actions */ @@ -248,10 +266,12 @@ public: /// returns the type name of the ViewProvider const char* getViewProviderName() const override - { return "InspectionGui::ViewProviderInspection"; } + { + return "InspectionGui::ViewProviderInspection"; + } }; -class InspectionExport Group : public App::DocumentObjectGroup +class InspectionExport Group: public App::DocumentObjectGroup { PROPERTY_HEADER_WITH_OVERRIDE(Inspection::Group); @@ -262,10 +282,12 @@ public: /// returns the type name of the ViewProvider const char* getViewProviderName() const override - { return "InspectionGui::ViewProviderInspectionGroup"; } + { + return "InspectionGui::ViewProviderInspectionGroup"; + } }; -} //namespace Inspection +}// namespace Inspection -#endif // INSPECTION_FEATURE_H +#endif// INSPECTION_FEATURE_H diff --git a/src/Mod/Inspection/App/PreCompiled.cpp b/src/Mod/Inspection/App/PreCompiled.cpp index 41bf7beded..2ac4ea20cd 100644 --- a/src/Mod/Inspection/App/PreCompiled.cpp +++ b/src/Mod/Inspection/App/PreCompiled.cpp @@ -20,4 +20,4 @@ * * ***************************************************************************/ -#include "PreCompiled.h" +#include "PreCompiled.h" diff --git a/src/Mod/Inspection/App/PreCompiled.h b/src/Mod/Inspection/App/PreCompiled.h index 29e9553e2b..e403b46123 100644 --- a/src/Mod/Inspection/App/PreCompiled.h +++ b/src/Mod/Inspection/App/PreCompiled.h @@ -19,17 +19,17 @@ * Suite 330, Boston, MA 02111-1307, USA * * * ***************************************************************************/ - + #ifndef APP_PRECOMPILED_H #define APP_PRECOMPILED_H #include #ifdef _MSC_VER -# pragma warning(disable : 4005) -# pragma warning(disable : 4251) -# pragma warning(disable : 4503) -# pragma warning(disable : 4786)// specifier longer then 255 chars +#pragma warning(disable : 4005) +#pragma warning(disable : 4251) +#pragma warning(disable : 4503) +#pragma warning(disable : 4786)// specifier longer then 255 chars #endif #ifdef _PreComp_ @@ -38,13 +38,13 @@ #include // OCC -#include #include #include +#include #include -#include #include #include +#include // boost #include @@ -55,7 +55,6 @@ #include #include -#endif //_PreComp_ +#endif//_PreComp_ #endif - diff --git a/src/Mod/Inspection/Gui/AppInspectionGui.cpp b/src/Mod/Inspection/Gui/AppInspectionGui.cpp index d7e141c894..ebb72595ff 100644 --- a/src/Mod/Inspection/Gui/AppInspectionGui.cpp +++ b/src/Mod/Inspection/Gui/AppInspectionGui.cpp @@ -35,13 +35,15 @@ void CreateInspectionCommands(); -namespace InspectionGui { -class Module : public Py::ExtensionModule +namespace InspectionGui +{ +class Module: public Py::ExtensionModule { public: - Module() : Py::ExtensionModule("InspectionGui") + Module() + : Py::ExtensionModule("InspectionGui") { - initialize("This module is the InspectionGui module."); // register with Python + initialize("This module is the InspectionGui module.");// register with Python } private: @@ -52,7 +54,7 @@ PyObject* initModule() return Base::Interpreter().addModule(new Module); } -} // namespace InspectionGui +}// namespace InspectionGui /* Python entry */ @@ -64,10 +66,12 @@ PyMOD_INIT_FUNC(InspectionGui) } // instantiating the commands + // clang-format off CreateInspectionCommands(); InspectionGui::ViewProviderInspection ::init(); InspectionGui::ViewProviderInspectionGroup ::init(); InspectionGui::Workbench ::init(); + // clang-format on // ADD YOUR CODE HERE // diff --git a/src/Mod/Inspection/Gui/PreCompiled.cpp b/src/Mod/Inspection/Gui/PreCompiled.cpp index 41bf7beded..2ac4ea20cd 100644 --- a/src/Mod/Inspection/Gui/PreCompiled.cpp +++ b/src/Mod/Inspection/Gui/PreCompiled.cpp @@ -20,4 +20,4 @@ * * ***************************************************************************/ -#include "PreCompiled.h" +#include "PreCompiled.h" diff --git a/src/Mod/Inspection/Gui/PreCompiled.h b/src/Mod/Inspection/Gui/PreCompiled.h index 6751f3a7c2..49ef730da0 100644 --- a/src/Mod/Inspection/Gui/PreCompiled.h +++ b/src/Mod/Inspection/Gui/PreCompiled.h @@ -26,10 +26,10 @@ #include #ifdef _MSC_VER -# pragma warning(disable : 4005) -# pragma warning(disable : 4251) -# pragma warning(disable : 4503) -# pragma warning(disable : 4786)// specifier longer then 255 chars +#pragma warning(disable : 4005) +#pragma warning(disable : 4251) +#pragma warning(disable : 4503) +#pragma warning(disable : 4786)// specifier longer then 255 chars #endif #ifdef _PreComp_ @@ -61,6 +61,6 @@ #include #include -#endif //_PreComp_ +#endif//_PreComp_ -#endif // GUI_PRECOMPILED_H +#endif// GUI_PRECOMPILED_H diff --git a/src/Mod/Inspection/Gui/ViewProviderInspection.cpp b/src/Mod/Inspection/Gui/ViewProviderInspection.cpp index e62b62bc6d..87a39b857b 100644 --- a/src/Mod/Inspection/Gui/ViewProviderInspection.cpp +++ b/src/Mod/Inspection/Gui/ViewProviderInspection.cpp @@ -23,27 +23,27 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include +#include +#include +#include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #endif #include @@ -64,14 +64,22 @@ using namespace InspectionGui; bool ViewProviderInspection::addflag = false; -App::PropertyFloatConstraint::Constraints ViewProviderInspection::floatRange = {1.0,64.0,1.0}; +App::PropertyFloatConstraint::Constraints ViewProviderInspection::floatRange = {1.0, 64.0, 1.0}; PROPERTY_SOURCE(InspectionGui::ViewProviderInspection, Gui::ViewProviderDocumentObject) ViewProviderInspection::ViewProviderInspection() { - ADD_PROPERTY_TYPE(OutsideGrayed,(false),"",(App::PropertyType) (App::Prop_Output|App::Prop_Hidden),""); - ADD_PROPERTY_TYPE(PointSize,(1.0),"Display",(App::PropertyType) (App::Prop_None/*App::Prop_Hidden*/),""); + ADD_PROPERTY_TYPE(OutsideGrayed, + (false), + "", + (App::PropertyType)(App::Prop_Output | App::Prop_Hidden), + ""); + ADD_PROPERTY_TYPE(PointSize, + (1.0), + "Display", + (App::PropertyType)(App::Prop_None /*App::Prop_Hidden*/), + ""); PointSize.setConstraints(&floatRange); pcColorRoot = new SoSeparator(); @@ -80,7 +88,7 @@ ViewProviderInspection::ViewProviderInspection() pcMatBinding->ref(); pcColorMat = new SoMaterial; pcColorMat->ref(); - pcColorStyle = new SoDrawStyle(); + pcColorStyle = new SoDrawStyle(); pcColorRoot->addChild(pcColorStyle); pcCoords = new SoCoordinate3; pcCoords->ref(); @@ -88,7 +96,7 @@ ViewProviderInspection::ViewProviderInspection() pcColorBar = new Gui::SoFCColorBar; pcColorBar->Attach(this); pcColorBar->ref(); - pcColorBar->setRange( -0.1f, 0.1f, 3 ); + pcColorBar->setRange(-0.1f, 0.1f, 3); pcLinkRoot = new SoGroup; pcLinkRoot->ref(); @@ -96,7 +104,7 @@ ViewProviderInspection::ViewProviderInspection() pcPointStyle->ref(); pcPointStyle->style = SoDrawStyle::POINTS; pcPointStyle->pointSize = PointSize.getValue(); - SelectionStyle.setValue(1); // BBOX + SelectionStyle.setValue(1);// BBOX } ViewProviderInspection::~ViewProviderInspection() @@ -119,7 +127,7 @@ void ViewProviderInspection::onChanged(const App::Property* prop) pcColorBar->Notify(0); } } - else if ( prop == &PointSize ) { + else if (prop == &PointSize) { pcPointStyle->pointSize = PointSize.getValue(); } else { @@ -139,20 +147,20 @@ void ViewProviderInspection::show() pcColorStyle->style = SoDrawStyle::FILLED; } -void ViewProviderInspection::attach(App::DocumentObject *pcFeat) +void ViewProviderInspection::attach(App::DocumentObject* pcFeat) { // creates the standard viewing modes inherited::attach(pcFeat); - SoShapeHints * flathints = new SoShapeHints; - flathints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE ; + SoShapeHints* flathints = new SoShapeHints; + flathints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE; flathints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE; SoGroup* pcColorShadedRoot = new SoGroup(); pcColorShadedRoot->addChild(flathints); // color shaded ------------------------------------------ - SoDrawStyle *pcFlatStyle = new SoDrawStyle(); + SoDrawStyle* pcFlatStyle = new SoDrawStyle(); pcFlatStyle->style = SoDrawStyle::FILLED; pcColorShadedRoot->addChild(pcFlatStyle); @@ -163,11 +171,12 @@ void ViewProviderInspection::attach(App::DocumentObject *pcFeat) addDisplayMaskMode(pcColorShadedRoot, "ColorShaded"); // Check for an already existing color bar - Gui::SoFCColorBar* pcBar = ((Gui::SoFCColorBar*)findFrontRootOfType(Gui::SoFCColorBar::getClassTypeId())); + Gui::SoFCColorBar* pcBar = + ((Gui::SoFCColorBar*)findFrontRootOfType(Gui::SoFCColorBar::getClassTypeId())); if (pcBar) { float fMin = pcColorBar->getMinValue(); float fMax = pcColorBar->getMaxValue(); - + // Attach to the foreign color bar and delete our own bar pcBar->Attach(this); pcBar->ref(); @@ -215,7 +224,8 @@ bool ViewProviderInspection::setupLines(const Data::ComplexGeoData* data) return true; } -bool ViewProviderInspection::setupPoints(const Data::ComplexGeoData* data, App::PropertyContainer* container) +bool ViewProviderInspection::setupPoints(const Data::ComplexGeoData* data, + App::PropertyContainer* container) { std::vector points; std::vector normals; @@ -227,14 +237,18 @@ bool ViewProviderInspection::setupPoints(const Data::ComplexGeoData* data, App:: } normals.reserve(normals_d.size()); - std::transform(normals_d.cbegin(), normals_d.cend(), std::back_inserter(normals), [](const Base::Vector3d& p){ - return Base::toVector(p); - }); + std::transform(normals_d.cbegin(), + normals_d.cend(), + std::back_inserter(normals), + [](const Base::Vector3d& p) { + return Base::toVector(p); + }); // If getPoints() doesn't deliver normals check a second property if (normals.empty() && container) { App::Property* propN = container->getPropertyByName("Normal"); - if (propN && propN->getTypeId().isDerivedFrom(Points::PropertyNormalList::getClassTypeId())) { + if (propN + && propN->getTypeId().isDerivedFrom(Points::PropertyNormalList::getClassTypeId())) { normals = static_cast(propN)->getValues(); } } @@ -255,9 +269,9 @@ void ViewProviderInspection::setupCoords(const std::vector& poin this->pcLinkRoot->addChild(this->pcCoords); this->pcCoords->point.setNum(points.size()); SbVec3f* pts = this->pcCoords->point.startEditing(); - for (size_t i=0; i < points.size(); i++) { + for (size_t i = 0; i < points.size(); i++) { const Base::Vector3d& p = points[i]; - pts[i].setValue((float)p.x,(float)p.y,(float)p.z); + pts[i].setValue((float)p.x, (float)p.y, (float)p.z); } this->pcCoords->point.finishEditing(); } @@ -268,7 +282,7 @@ void ViewProviderInspection::setupNormals(const std::vector& nor normalNode->vector.setNum(normals.size()); SbVec3f* norm = normalNode->vector.startEditing(); - std::size_t i=0; + std::size_t i = 0; for (const auto& it : normals) { norm[i++].setValue(it.x, it.y, it.z); } @@ -283,11 +297,11 @@ void ViewProviderInspection::setupLineIndexes(const std::vectorpcLinkRoot->addChild(line); line->coordIndex.setNum(3 * lines.size()); int32_t* indices = line->coordIndex.startEditing(); - unsigned long j=0; + unsigned long j = 0; for (const auto& it : lines) { - indices[3*j+0] = it.I1; - indices[3*j+1] = it.I2; - indices[3*j+2] = SO_END_LINE_INDEX; + indices[3 * j + 0] = it.I1; + indices[3 * j + 1] = it.I2; + indices[3 * j + 2] = SO_END_LINE_INDEX; j++; } line->coordIndex.finishEditing(); @@ -297,14 +311,14 @@ void ViewProviderInspection::setupFaceIndexes(const std::vectorpcLinkRoot->addChild(face); - face->coordIndex.setNum(4*faces.size()); + face->coordIndex.setNum(4 * faces.size()); int32_t* indices = face->coordIndex.startEditing(); - unsigned long j=0; + unsigned long j = 0; for (const auto& it : faces) { - indices[4*j+0] = it.I1; - indices[4*j+1] = it.I2; - indices[4*j+2] = it.I3; - indices[4*j+3] = SO_END_FACE_INDEX; + indices[4 * j + 0] = it.I1; + indices[4 * j + 1] = it.I2; + indices[4 * j + 2] = it.I3; + indices[4 * j + 3] = SO_END_FACE_INDEX; j++; } face->coordIndex.finishEditing(); @@ -314,8 +328,10 @@ void ViewProviderInspection::updateData(const App::Property* prop) { // set to the expected size if (prop->getTypeId().isDerivedFrom(App::PropertyLink::getClassTypeId())) { - App::GeoFeature* object = static_cast(prop)->getValue(); - const App::PropertyComplexGeoData* propData = object ? object->getPropertyOfGeometry() : nullptr; + App::GeoFeature* object = + static_cast(prop)->getValue(); + const App::PropertyComplexGeoData* propData = + object ? object->getPropertyOfGeometry() : nullptr; if (propData) { Gui::coinRemoveAllChildren(this->pcLinkRoot); @@ -331,8 +347,9 @@ void ViewProviderInspection::updateData(const App::Property* prop) // force an update of the Inventor data nodes if (this->pcObject) { App::Property* link = this->pcObject->getPropertyByName("Actual"); - if (link) + if (link) { updateData(link); + } setDistances(); } } @@ -340,7 +357,7 @@ void ViewProviderInspection::updateData(const App::Property* prop) if (strcmp(prop->getName(), "SearchRadius") == 0) { float fSearchRadius = ((App::PropertyFloat*)prop)->getValue(); this->search_radius = fSearchRadius; - pcColorBar->setRange( -fSearchRadius, fSearchRadius, 4 ); + pcColorBar->setRange(-fSearchRadius, fSearchRadius, 4); pcColorBar->Notify(0); } } @@ -353,8 +370,9 @@ SoSeparator* ViewProviderInspection::getFrontRoot() const void ViewProviderInspection::setDistances() { - if (!pcObject) + if (!pcObject) { return; + } App::Property* pDistances = pcObject->getPropertyByName("Distances"); if (!pDistances) { @@ -362,27 +380,32 @@ void ViewProviderInspection::setDistances() return; } if (pDistances->getTypeId() != Inspection::PropertyDistanceList::getClassTypeId()) { - SoDebugError::post("ViewProviderInspection::setDistances", - "Property 'Distances' has type %s (Inspection::PropertyDistanceList was expected)", pDistances->getTypeId().getName()); + SoDebugError::post( + "ViewProviderInspection::setDistances", + "Property 'Distances' has type %s (Inspection::PropertyDistanceList was expected)", + pDistances->getTypeId().getName()); return; } // distance values - const std::vector& fValues = static_cast(pDistances)->getValues(); + const std::vector& fValues = + static_cast(pDistances)->getValues(); if ((int)fValues.size() != this->pcCoords->point.getNum()) { pcMatBinding->value = SoMaterialBinding::OVERALL; return; } - if (pcColorMat->diffuseColor.getNum() != static_cast(fValues.size())) + if (pcColorMat->diffuseColor.getNum() != static_cast(fValues.size())) { pcColorMat->diffuseColor.setNum(static_cast(fValues.size())); - if (pcColorMat->transparency.getNum() != static_cast(fValues.size())) + } + if (pcColorMat->transparency.getNum() != static_cast(fValues.size())) { pcColorMat->transparency.setNum(static_cast(fValues.size())); + } - SbColor * cols = pcColorMat->diffuseColor.startEditing(); - float * tran = pcColorMat->transparency.startEditing(); + SbColor* cols = pcColorMat->diffuseColor.startEditing(); + float* tran = pcColorMat->transparency.startEditing(); - unsigned long j=0; + unsigned long j = 0; for (std::vector::const_iterator jt = fValues.begin(); jt != fValues.end(); ++jt, j++) { App::Color col = pcColorBar->getColor(*jt); cols[j] = SbColor(col.r, col.g, col.b); @@ -404,7 +427,7 @@ QIcon ViewProviderInspection::getIcon() const // Get the icon of the view provider to the associated feature QIcon px = inherited::getIcon(); App::Property* pActual = pcObject->getPropertyByName("Actual"); - if (pActual && pActual->getTypeId().isDerivedFrom( App::PropertyLink::getClassTypeId())) { + if (pActual && pActual->getTypeId().isDerivedFrom(App::PropertyLink::getClassTypeId())) { App::DocumentObject* docobj = ((App::PropertyLink*)pActual)->getValue(); if (docobj) { Gui::Document* doc = Gui::Application::Instance->getDocument(docobj->getDocument()); @@ -418,7 +441,7 @@ QIcon ViewProviderInspection::getIcon() const void ViewProviderInspection::setDisplayMode(const char* ModeName) { - if (strcmp("Visual Inspection",ModeName)==0) { + if (strcmp("Visual Inspection", ModeName) == 0) { setDistances(); setDisplayMaskMode("ColorShaded"); } @@ -434,30 +457,37 @@ std::vector ViewProviderInspection::getDisplayModes() const return StrList; } -void ViewProviderInspection::OnChange(Base::Subject &/*rCaller*/, int /*rcReason*/) +void ViewProviderInspection::OnChange(Base::Subject& /*rCaller*/, int /*rcReason*/) { setActiveMode(); } -namespace InspectionGui { +namespace InspectionGui +{ // Proxy class that receives an asynchronous custom event -class ViewProviderProxyObject : public QObject +class ViewProviderProxyObject: public QObject { public: - explicit ViewProviderProxyObject(QWidget* w) : QObject(nullptr), widget(w) {} + explicit ViewProviderProxyObject(QWidget* w) + : QObject(nullptr) + , widget(w) + {} ~ViewProviderProxyObject() override = default; - void customEvent(QEvent *) override + void customEvent(QEvent*) override { if (!widget.isNull()) { QList flags = widget->findChildren(); if (!flags.isEmpty()) { - int ret = QMessageBox::question(Gui::getMainWindow(), - QObject::tr("Remove annotations"), - QObject::tr("Do you want to remove all annotations?"), - QMessageBox::Yes,QMessageBox::No); + int ret = + QMessageBox::question(Gui::getMainWindow(), + QObject::tr("Remove annotations"), + QObject::tr("Do you want to remove all annotations?"), + QMessageBox::Yes, + QMessageBox::No); if (ret == QMessageBox::Yes) { - for (auto it : flags) + for (auto it : flags) { it->deleteLater(); + } } } } @@ -465,17 +495,19 @@ public: this->deleteLater(); } - static void addFlag(Gui::View3DInventorViewer* view, const QString& text, const SoPickedPoint * point) + static void + addFlag(Gui::View3DInventorViewer* view, const QString& text, const SoPickedPoint* point) { Gui::Flag* flag = new Gui::Flag; QPalette p; - p.setColor(QPalette::Window, QColor(85,0,127)); - p.setColor(QPalette::Text, QColor(220,220,220)); + p.setColor(QPalette::Window, QColor(85, 0, 127)); + p.setColor(QPalette::Text, QColor(220, 220, 220)); flag->setPalette(p); flag->setText(text); flag->setOrigin(point->getPoint()); Gui::GLFlagWindow* flags = nullptr; - std::list glItems = view->getGraphicsItemsOfType(Gui::GLFlagWindow::getClassTypeId()); + std::list glItems = + view->getGraphicsItemsOfType(Gui::GLFlagWindow::getClassTypeId()); if (glItems.empty()) { flags = new Gui::GLFlagWindow(view); view->addGraphicsItem(flags); @@ -489,19 +521,21 @@ public: private: QPointer widget; }; -} +}// namespace InspectionGui -void ViewProviderInspection::inspectCallback(void * ud, SoEventCallback * n) +void ViewProviderInspection::inspectCallback(void* ud, SoEventCallback* n) { - Gui::View3DInventorViewer* view = static_cast(n->getUserData()); + Gui::View3DInventorViewer* view = static_cast(n->getUserData()); const SoEvent* ev = n->getEvent(); if (ev->getTypeId() == SoMouseButtonEvent::getClassTypeId()) { - const SoMouseButtonEvent * mbe = static_cast(ev); + const SoMouseButtonEvent* mbe = static_cast(ev); - // Mark all incoming mouse button events as handled, especially, to deactivate the selection node + // Mark all incoming mouse button events as handled, especially, to deactivate the selection + // node n->getAction()->setHandled(); n->setHandled(); - if (mbe->getButton() == SoMouseButtonEvent::BUTTON2 && mbe->getState() == SoButtonEvent::UP) { + if (mbe->getButton() == SoMouseButtonEvent::BUTTON2 + && mbe->getState() == SoButtonEvent::UP) { n->setHandled(); // context-menu QMenu menu; @@ -516,9 +550,8 @@ void ViewProviderInspection::inspectCallback(void * ud, SoEventCallback * n) else if (cl == id) { // post an event to a proxy object to make sure to avoid problems // when opening a modal dialog - QApplication::postEvent( - new ViewProviderProxyObject(view->getGLWidget()), - new QEvent(QEvent::User)); + QApplication::postEvent(new ViewProviderProxyObject(view->getGLWidget()), + new QEvent(QEvent::User)); view->setEditing(false); view->getWidget()->setCursor(QCursor(Qt::ArrowCursor)); view->setRedirectToSceneGraph(false); @@ -527,8 +560,9 @@ void ViewProviderInspection::inspectCallback(void * ud, SoEventCallback * n) view->removeEventCallback(SoButtonEvent::getClassTypeId(), inspectCallback, ud); } } - else if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 && mbe->getState() == SoButtonEvent::UP) { - const SoPickedPoint * point = n->getPickedPoint(); + else if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 + && mbe->getState() == SoButtonEvent::UP) { + const SoPickedPoint* point = n->getPickedPoint(); if (!point) { Base::Console().Message("No point picked.\n"); return; @@ -541,11 +575,13 @@ void ViewProviderInspection::inspectCallback(void * ud, SoEventCallback * n) if (vp && vp->getTypeId().isDerivedFrom(ViewProviderInspection::getClassTypeId())) { ViewProviderInspection* that = static_cast(vp); QString info = that->inspectDistance(point); - Gui::getMainWindow()->setPaneText(1,info); - if (addflag) + Gui::getMainWindow()->setPaneText(1, info); + if (addflag) { ViewProviderProxyObject::addFlag(view, info, point); - else + } + else { Gui::ToolTip::showText(QCursor::pos(), info); + } } else { // the nearest picked point was not part of the view provider @@ -555,17 +591,21 @@ void ViewProviderInspection::inspectCallback(void * ud, SoEventCallback * n) action.apply(view->getSoRenderManager()->getSceneGraph()); const SoPickedPointList& pps = action.getPickedPointList(); - for (int i=0; igetViewProviderByPathFromTail(point->getPath()); - if (vp && vp->getTypeId().isDerivedFrom(ViewProviderInspection::getClassTypeId())) { + if (vp + && vp->getTypeId().isDerivedFrom( + ViewProviderInspection::getClassTypeId())) { ViewProviderInspection* self = static_cast(vp); QString info = self->inspectDistance(point); - Gui::getMainWindow()->setPaneText(1,info); - if (addflag) + Gui::getMainWindow()->setPaneText(1, info); + if (addflag) { ViewProviderProxyObject::addFlag(view, info, point); - else + } + else { Gui::ToolTip::showText(QCursor::pos(), info); + } break; } } @@ -574,9 +614,8 @@ void ViewProviderInspection::inspectCallback(void * ud, SoEventCallback * n) } // toggle between inspection and navigation mode else if (ev->getTypeId().isDerivedFrom(SoKeyboardEvent::getClassTypeId())) { - const SoKeyboardEvent * const ke = static_cast(ev); - if (ke->getState() == SoButtonEvent::DOWN && - ke->getKey() == SoKeyboardEvent::ESCAPE) { + const SoKeyboardEvent* const ke = static_cast(ev); + if (ke->getState() == SoButtonEvent::DOWN && ke->getKey() == SoKeyboardEvent::ESCAPE) { SbBool toggle = view->isRedirectedToSceneGraph(); view->setRedirectToSceneGraph(!toggle); n->setHandled(); @@ -584,29 +623,35 @@ void ViewProviderInspection::inspectCallback(void * ud, SoEventCallback * n) } } -namespace InspectionGui { -float calcArea (const SbVec3f& v1, const SbVec3f& v2, const SbVec3f& v3) +namespace InspectionGui { - SbVec3f a = v2-v1; - SbVec3f b = v3-v1; - return a.cross(b).length()/2.0f; -} - -bool calcWeights(const SbVec3f& v1, const SbVec3f& v2, const SbVec3f& v3, - const SbVec3f& p, float& w0, float& w1, float& w2) +float calcArea(const SbVec3f& v1, const SbVec3f& v2, const SbVec3f& v3) { - float fAreaABC = calcArea(v1,v2,v3); - float fAreaPBC = calcArea(p,v2,v3); - float fAreaPCA = calcArea(p,v3,v1); - float fAreaPAB = calcArea(p,v1,v2); - - w0=fAreaPBC/fAreaABC; - w1=fAreaPCA/fAreaABC; - w2=fAreaPAB/fAreaABC; - - return fabs(w0+w1+w2-1.0f)<0.001f; + SbVec3f a = v2 - v1; + SbVec3f b = v3 - v1; + return a.cross(b).length() / 2.0f; } + +bool calcWeights(const SbVec3f& v1, + const SbVec3f& v2, + const SbVec3f& v3, + const SbVec3f& p, + float& w0, + float& w1, + float& w2) +{ + float fAreaABC = calcArea(v1, v2, v3); + float fAreaPBC = calcArea(p, v2, v3); + float fAreaPCA = calcArea(p, v3, v1); + float fAreaPAB = calcArea(p, v1, v2); + + w0 = fAreaPBC / fAreaABC; + w1 = fAreaPCA / fAreaABC; + w2 = fAreaPAB / fAreaABC; + + return fabs(w0 + w1 + w2 - 1.0f) < 0.001f; } +}// namespace InspectionGui QString ViewProviderInspection::inspectDistance(const SoPickedPoint* pp) const { @@ -614,24 +659,28 @@ QString ViewProviderInspection::inspectDistance(const SoPickedPoint* pp) const const SoDetail* detail = pp->getDetail(pp->getPath()->getTail()); if (detail && detail->getTypeId() == SoFaceDetail::getClassTypeId()) { // get the distances of the three points of the picked facet - const SoFaceDetail * facedetail = static_cast(detail); + const SoFaceDetail* facedetail = static_cast(detail); App::Property* pDistance = this->pcObject->getPropertyByName("Distances"); - if (pDistance && pDistance->getTypeId() == Inspection::PropertyDistanceList::getClassTypeId()) { - Inspection::PropertyDistanceList* dist = static_cast(pDistance); + if (pDistance + && pDistance->getTypeId() == Inspection::PropertyDistanceList::getClassTypeId()) { + Inspection::PropertyDistanceList* dist = + static_cast(pDistance); int index1 = facedetail->getPoint(0)->getCoordinateIndex(); int index2 = facedetail->getPoint(1)->getCoordinateIndex(); int index3 = facedetail->getPoint(2)->getCoordinateIndex(); float fVal1 = (*dist)[index1]; float fVal2 = (*dist)[index2]; float fVal3 = (*dist)[index3]; - + App::Property* pActual = this->pcObject->getPropertyByName("Actual"); - if (pActual && pActual->getTypeId().isDerivedFrom( App::PropertyLink::getClassTypeId())) { + if (pActual + && pActual->getTypeId().isDerivedFrom(App::PropertyLink::getClassTypeId())) { float fSearchRadius = this->search_radius; if (fVal1 > fSearchRadius || fVal2 > fSearchRadius || fVal3 > fSearchRadius) { info = QObject::tr("Distance: > %1").arg(fSearchRadius); } - else if (fVal1 < -fSearchRadius || fVal2 < -fSearchRadius || fVal3 < -fSearchRadius) { + else if (fVal1 < -fSearchRadius || fVal2 < -fSearchRadius + || fVal3 < -fSearchRadius) { info = QObject::tr("Distance: < %1").arg(-fSearchRadius); } else { @@ -642,7 +691,8 @@ QString ViewProviderInspection::inspectDistance(const SoPickedPoint* pp) const SoPath* selectionPath = searchAction.getPath(); if (selectionPath) { - SoCoordinate3* coords = static_cast(selectionPath->getTail()); + SoCoordinate3* coords = + static_cast(selectionPath->getTail()); const SbVec3f& v1 = coords->point[index1]; const SbVec3f& v2 = coords->point[index2]; const SbVec3f& v3 = coords->point[index3]; @@ -659,13 +709,14 @@ QString ViewProviderInspection::inspectDistance(const SoPickedPoint* pp) const } else if (detail && detail->getTypeId() == SoPointDetail::getClassTypeId()) { // safe downward cast, know the type - const SoPointDetail * pointdetail = static_cast(detail); + const SoPointDetail* pointdetail = static_cast(detail); // get the distance of the picked point int index = pointdetail->getCoordinateIndex(); App::Property* prop = this->pcObject->getPropertyByName("Distances"); if (prop && prop->getTypeId() == Inspection::PropertyDistanceList::getClassTypeId()) { - Inspection::PropertyDistanceList* dist = static_cast(prop); + Inspection::PropertyDistanceList* dist = + static_cast(prop); float fVal = (*dist)[index]; info = QObject::tr("Distance: %1").arg(fVal); } @@ -691,6 +742,7 @@ ViewProviderInspectionGroup::~ViewProviderInspectionGroup() = default; */ QIcon ViewProviderInspectionGroup::getIcon() const { + // clang-format off static const char * const ScanViewOpen[]={ "16 16 10 1", "c c #000000", @@ -747,6 +799,7 @@ QIcon ViewProviderInspectionGroup::getIcon() const ".##############c", "..cccccccccccccc", "................"}; + // clang-format on QIcon groupIcon; groupIcon.addPixmap(QPixmap(ScanViewClosed), QIcon::Normal, QIcon::Off); diff --git a/src/Mod/Inspection/Gui/ViewProviderInspection.h b/src/Mod/Inspection/Gui/ViewProviderInspection.h index 56e91f1461..408a706c67 100644 --- a/src/Mod/Inspection/Gui/ViewProviderInspection.h +++ b/src/Mod/Inspection/Gui/ViewProviderInspection.h @@ -36,18 +36,20 @@ class SoDrawStyle; class SoSeparator; class SoCoordinate3; -namespace Gui { - class SoFCColorBar; - class View3DInventorViewer; -} +namespace Gui +{ +class SoFCColorBar; +class View3DInventorViewer; +}// namespace Gui -namespace InspectionGui { +namespace InspectionGui +{ /** * @author Werner Mayer */ -class ViewProviderInspection : public Gui::ViewProviderDocumentObject, - public Base::Observer{ +class ViewProviderInspection: public Gui::ViewProviderDocumentObject, public Base::Observer +{ using inherited = ViewProviderDocumentObject; PROPERTY_HEADER_WITH_OVERRIDE(InspectionGui::ViewProviderInspection); @@ -59,15 +61,16 @@ public: App::PropertyBool OutsideGrayed; App::PropertyFloatConstraint PointSize; - void attach(App::DocumentObject *pcFeat) override; + void attach(App::DocumentObject* pcFeat) override; /// Sets the viewing mode void setDisplayMode(const char* ModeName) override; /// Returns a list of all possible modes std::vector getDisplayModes() const override; /// Update colorbar after recomputation of distances. void updateData(const App::Property*) override; - /// Once the color bar settings has been changed this method gets called to update the feature's representation - void OnChange(Base::Subject &rCaller,int rcReason) override; + /// Once the color bar settings has been changed this method gets called to update the feature's + /// representation + void OnChange(Base::Subject& rCaller, int rcReason) override; QIcon getIcon() const override; /// Returns a color bar SoSeparator* getFrontRoot() const override; @@ -76,7 +79,7 @@ public: /// Show the object in the view void show() override; - static void inspectCallback(void * ud, SoEventCallback * n); + static void inspectCallback(void* ud, SoEventCallback* n); protected: void onChanged(const App::Property* prop) override; @@ -93,22 +96,22 @@ private: void setupFaceIndexes(const std::vector&); protected: - SoMaterial * pcColorMat; + SoMaterial* pcColorMat; SoMaterialBinding* pcMatBinding; - SoGroup * pcLinkRoot; + SoGroup* pcLinkRoot; Gui::SoFCColorBar* pcColorBar; - SoDrawStyle * pcColorStyle; - SoDrawStyle * pcPointStyle; - SoSeparator * pcColorRoot; - SoCoordinate3 * pcCoords; + SoDrawStyle* pcColorStyle; + SoDrawStyle* pcPointStyle; + SoSeparator* pcColorRoot; + SoCoordinate3* pcCoords; private: - float search_radius{FLT_MAX}; + float search_radius {FLT_MAX}; static bool addflag; static App::PropertyFloatConstraint::Constraints floatRange; }; -class ViewProviderInspectionGroup : public Gui::ViewProviderDocumentObjectGroup +class ViewProviderInspectionGroup: public Gui::ViewProviderDocumentObjectGroup { PROPERTY_HEADER_WITH_OVERRIDE(InspectionGui::ViewProviderInspectionGroup); @@ -120,8 +123,7 @@ public: QIcon getIcon() const override; }; -} // namespace InspectionGui +}// namespace InspectionGui -#endif // INSPECTIOGUI_VIEWPROVIDERINSPECTION_H - +#endif// INSPECTIOGUI_VIEWPROVIDERINSPECTION_H diff --git a/src/Mod/Inspection/Gui/VisualInspection.cpp b/src/Mod/Inspection/Gui/VisualInspection.cpp index e1c68ecd6e..5eae0c9e64 100644 --- a/src/Mod/Inspection/Gui/VisualInspection.cpp +++ b/src/Mod/Inspection/Gui/VisualInspection.cpp @@ -22,7 +22,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include #endif #include @@ -40,21 +40,22 @@ using namespace InspectionGui; -namespace InspectionGui { -class SingleSelectionItem : public QTreeWidgetItem +namespace InspectionGui +{ +class SingleSelectionItem: public QTreeWidgetItem { public: - explicit SingleSelectionItem (QTreeWidget* parent) - : QTreeWidgetItem(parent), _compItem(nullptr) - { - } + explicit SingleSelectionItem(QTreeWidget* parent) + : QTreeWidgetItem(parent) + , _compItem(nullptr) + {} - explicit SingleSelectionItem (QTreeWidgetItem* parent) - : QTreeWidgetItem (parent), _compItem(nullptr) - { - } + explicit SingleSelectionItem(QTreeWidgetItem* parent) + : QTreeWidgetItem(parent) + , _compItem(nullptr) + {} - ~SingleSelectionItem () override = default; + ~SingleSelectionItem() override = default; SingleSelectionItem* getCompetitiveItem() const { @@ -69,7 +70,7 @@ public: private: SingleSelectionItem* _compItem; }; -} +}// namespace InspectionGui /* TRANSLATOR InspectionGui::DlgVisualInspectionImp */ @@ -78,17 +79,24 @@ private: * name 'name' and widget flags set to 'f'. */ VisualInspection::VisualInspection(QWidget* parent, Qt::WindowFlags fl) - : QDialog(parent, fl), ui(new Ui_VisualInspection) + : QDialog(parent, fl) + , ui(new Ui_VisualInspection) { ui->setupUi(this); - connect(ui->treeWidgetActual, &QTreeWidget::itemClicked, - this, &VisualInspection::onActivateItem); - connect(ui->treeWidgetNominal, &QTreeWidget::itemClicked, - this, &VisualInspection::onActivateItem); - connect(ui->buttonBox, &QDialogButtonBox::helpRequested, - Gui::getMainWindow(), &Gui::MainWindow::whatsThis); + connect(ui->treeWidgetActual, + &QTreeWidget::itemClicked, + this, + &VisualInspection::onActivateItem); + connect(ui->treeWidgetNominal, + &QTreeWidget::itemClicked, + this, + &VisualInspection::onActivateItem); + connect(ui->buttonBox, + &QDialogButtonBox::helpRequested, + Gui::getMainWindow(), + &Gui::MainWindow::whatsThis); - //FIXME: Not used yet + // FIXME: Not used yet ui->textLabel2->hide(); ui->thickness->hide(); ui->searchRadius->setUnit(Base::Unit::Length); @@ -111,12 +119,11 @@ VisualInspection::VisualInspection(QWidget* parent, Qt::WindowFlags fl) std::vector obj = doc->getObjects(); Base::Type point = Base::Type::fromName("Points::Feature"); - Base::Type mesh = Base::Type::fromName("Mesh::Feature"); + Base::Type mesh = Base::Type::fromName("Mesh::Feature"); Base::Type shape = Base::Type::fromName("Part::Feature"); for (auto it : obj) { - if (it->getTypeId().isDerivedFrom(point) || - it->getTypeId().isDerivedFrom(mesh) || - it->getTypeId().isDerivedFrom(shape)) { + if (it->getTypeId().isDerivedFrom(point) || it->getTypeId().isDerivedFrom(mesh) + || it->getTypeId().isDerivedFrom(shape)) { Gui::ViewProvider* view = gui->getViewProvider(it); QIcon px = view->getIcon(); SingleSelectionItem* item1 = new SingleSelectionItem(ui->treeWidgetActual); @@ -150,8 +157,8 @@ VisualInspection::~VisualInspection() void VisualInspection::loadSettings() { - ParameterGrp::handle handle = App::GetApplication().GetParameterGroupByPath - ("User parameter:BaseApp/Preferences/Mod/Inspection/Inspection"); + ParameterGrp::handle handle = App::GetApplication().GetParameterGroupByPath( + "User parameter:BaseApp/Preferences/Mod/Inspection/Inspection"); double searchDistance = ui->searchRadius->value().getValue(); searchDistance = handle->GetFloat("SearchDistance", searchDistance); @@ -164,8 +171,8 @@ void VisualInspection::loadSettings() void VisualInspection::saveSettings() { - ParameterGrp::handle handle = App::GetApplication().GetParameterGroupByPath - ("User parameter:BaseApp/Preferences/Mod/Inspection/Inspection"); + ParameterGrp::handle handle = App::GetApplication().GetParameterGroupByPath( + "User parameter:BaseApp/Preferences/Mod/Inspection/Inspection"); double searchDistance = ui->searchRadius->value().getValue(); handle->SetFloat("SearchDistance", searchDistance); @@ -178,11 +185,12 @@ void VisualInspection::onActivateItem(QTreeWidgetItem* item) if (item) { SingleSelectionItem* sel = static_cast(item); SingleSelectionItem* cmp = sel->getCompetitiveItem(); - if (cmp && cmp->checkState(0) == Qt::Checked) + if (cmp && cmp->checkState(0) == Qt::Checked) { cmp->setCheckState(0, Qt::Unchecked); + } } - bool ok=false; + bool ok = false; for (QTreeWidgetItemIterator it(ui->treeWidgetActual); *it; ++it) { SingleSelectionItem* sel = (SingleSelectionItem*)*it; if (sel->checkState(0) == Qt::Checked) { @@ -193,7 +201,7 @@ void VisualInspection::onActivateItem(QTreeWidgetItem* item) if (ok) { ok = false; - for (QTreeWidgetItemIterator it (ui->treeWidgetNominal); *it; ++it) { + for (QTreeWidgetItemIterator it(ui->treeWidgetNominal); *it; ++it) { SingleSelectionItem* sel = (SingleSelectionItem*)*it; if (sel->checkState(0) == Qt::Checked) { ok = true; @@ -216,8 +224,9 @@ void VisualInspection::accept() QStringList nominalNames; for (QTreeWidgetItemIterator it(ui->treeWidgetNominal); *it; it++) { SingleSelectionItem* sel = (SingleSelectionItem*)*it; - if (sel->checkState(0) == Qt::Checked) + if (sel->checkState(0) == Qt::Checked) { nominalNames << sel->data(0, Qt::UserRole).toString(); + } } double searchRadius = ui->searchRadius->value().getValue(); @@ -228,33 +237,42 @@ void VisualInspection::accept() doc->openCommand(QT_TRANSLATE_NOOP("Command", "Visual Inspection")); // create a group - Gui::Command::runCommand( - Gui::Command::App, "App_activeDocument___InspectionGroup=App.ActiveDocument.addObject(\"Inspection::Group\",\"Inspection\")"); - + Gui::Command::runCommand(Gui::Command::App, + "App_activeDocument___InspectionGroup=App.ActiveDocument." + "addObject(\"Inspection::Group\",\"Inspection\")"); + // for each actual geometry create an inspection feature for (QTreeWidgetItemIterator it(ui->treeWidgetActual); *it; it++) { SingleSelectionItem* sel = (SingleSelectionItem*)*it; if (sel->checkState(0) == Qt::Checked) { QString actualName = sel->data(0, Qt::UserRole).toString(); Gui::Command::doCommand(Gui::Command::App, - "App_activeDocument___InspectionGroup.newObject(\"Inspection::Feature\",\"%s_Inspect\")", (const char*)actualName.toLatin1()); - Gui::Command::doCommand(Gui::Command::App, + "App_activeDocument___InspectionGroup.newObject(" + "\"Inspection::Feature\",\"%s_Inspect\")", + (const char*)actualName.toLatin1()); + Gui::Command::doCommand( + Gui::Command::App, "App.ActiveDocument.ActiveObject.Actual=App.ActiveDocument.%s\n" "App_activeDocument___activeObject___Nominals=list()\n" "App.ActiveDocument.ActiveObject.SearchRadius=%.3f\n" - "App.ActiveDocument.ActiveObject.Thickness=%.3f\n", (const char*)actualName.toLatin1(), searchRadius, thickness); + "App.ActiveDocument.ActiveObject.Thickness=%.3f\n", + (const char*)actualName.toLatin1(), + searchRadius, + thickness); for (const auto& it : nominalNames) { Gui::Command::doCommand(Gui::Command::App, - "App_activeDocument___activeObject___Nominals.append(App.ActiveDocument.%s)\n", (const char*)it.toLatin1()); + "App_activeDocument___activeObject___Nominals.append(" + "App.ActiveDocument.%s)\n", + (const char*)it.toLatin1()); } Gui::Command::doCommand(Gui::Command::App, - "App.ActiveDocument.ActiveObject.Nominals=App_activeDocument___activeObject___Nominals\n" - "del App_activeDocument___activeObject___Nominals\n"); + "App.ActiveDocument.ActiveObject.Nominals=App_" + "activeDocument___activeObject___Nominals\n" + "del App_activeDocument___activeObject___Nominals\n"); } } - Gui::Command::runCommand(Gui::Command::App, - "del App_activeDocument___InspectionGroup\n"); + Gui::Command::runCommand(Gui::Command::App, "del App_activeDocument___InspectionGroup\n"); doc->commitCommand(); doc->getDocument()->recompute(); @@ -263,18 +281,20 @@ void VisualInspection::accept() for (QTreeWidgetItemIterator it(ui->treeWidgetActual); *it; it++) { SingleSelectionItem* sel = (SingleSelectionItem*)*it; if (sel->checkState(0) == Qt::Checked) { - Gui::Command::doCommand(Gui::Command::App - , "Gui.ActiveDocument.getObject(\"%s\").Visibility=False" - , (const char*)sel->data(0, Qt::UserRole).toString().toLatin1()); + Gui::Command::doCommand( + Gui::Command::App, + "Gui.ActiveDocument.getObject(\"%s\").Visibility=False", + (const char*)sel->data(0, Qt::UserRole).toString().toLatin1()); } } for (QTreeWidgetItemIterator it(ui->treeWidgetNominal); *it; it++) { SingleSelectionItem* sel = (SingleSelectionItem*)*it; if (sel->checkState(0) == Qt::Checked) { - Gui::Command::doCommand(Gui::Command::App - , "Gui.ActiveDocument.getObject(\"%s\").Visibility=False" - , (const char*)sel->data(0, Qt::UserRole).toString().toLatin1()); + Gui::Command::doCommand( + Gui::Command::App, + "Gui.ActiveDocument.getObject(\"%s\").Visibility=False", + (const char*)sel->data(0, Qt::UserRole).toString().toLatin1()); } } } diff --git a/src/Mod/Inspection/Gui/VisualInspection.h b/src/Mod/Inspection/Gui/VisualInspection.h index ea22dd40fc..f1df1c19bc 100644 --- a/src/Mod/Inspection/Gui/VisualInspection.h +++ b/src/Mod/Inspection/Gui/VisualInspection.h @@ -29,15 +29,16 @@ class QTreeWidgetItem; class QPushButton; -namespace InspectionGui { +namespace InspectionGui +{ class Ui_VisualInspection; -class VisualInspection : public QDialog +class VisualInspection: public QDialog { Q_OBJECT public: explicit VisualInspection(QWidget* parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags()); - ~ VisualInspection() override; + ~VisualInspection() override; void accept() override; @@ -51,6 +52,6 @@ private: QPushButton* buttonOk; }; -} // namespace InspectionGui +}// namespace InspectionGui -#endif // INSPECTIONGUI_VISUALINSPECTION_H +#endif// INSPECTIONGUI_VISUALINSPECTION_H diff --git a/src/Mod/Inspection/Gui/Workbench.cpp b/src/Mod/Inspection/Gui/Workbench.cpp index 4caffeeed7..c2a02150d0 100644 --- a/src/Mod/Inspection/Gui/Workbench.cpp +++ b/src/Mod/Inspection/Gui/Workbench.cpp @@ -40,7 +40,7 @@ Workbench::~Workbench() = default; Gui::MenuItem* Workbench::setupMenuBar() const { Gui::MenuItem* root = StdWorkbench::setupMenuBar(); - Gui::MenuItem* item = root->findItem( "&Windows" ); + Gui::MenuItem* item = root->findItem("&Windows"); Gui::MenuItem* insp = new Gui::MenuItem; root->insertItem(item, insp); insp->setCommand("Inspection"); @@ -52,8 +52,8 @@ Gui::MenuItem* Workbench::setupMenuBar() const Gui::ToolBarItem* Workbench::setupToolBars() const { Gui::ToolBarItem* root = StdWorkbench::setupToolBars(); - //Gui::ToolBarItem* insp = new Gui::ToolBarItem(root); - //insp->setCommand( "Inspection Tools" ); - //*insp << "Inspection_VisualInspection"; + // Gui::ToolBarItem* insp = new Gui::ToolBarItem(root); + // insp->setCommand( "Inspection Tools" ); + //*insp << "Inspection_VisualInspection"; return root; } diff --git a/src/Mod/Inspection/Gui/Workbench.h b/src/Mod/Inspection/Gui/Workbench.h index 3706b88e67..e6457bb256 100644 --- a/src/Mod/Inspection/Gui/Workbench.h +++ b/src/Mod/Inspection/Gui/Workbench.h @@ -26,9 +26,10 @@ #include -namespace InspectionGui { +namespace InspectionGui +{ -class Workbench : public Gui::StdWorkbench +class Workbench: public Gui::StdWorkbench { TYPESYSTEM_HEADER_WITH_OVERRIDE(); @@ -41,7 +42,7 @@ protected: Gui::ToolBarItem* setupToolBars() const override; }; -} // namespace InspectionGui +}// namespace InspectionGui -#endif // Inspection_WORKBENCH_H +#endif// Inspection_WORKBENCH_H diff --git a/src/Mod/Inspection/Init.py b/src/Mod/Inspection/Init.py index 803687116c..16f51fcc6c 100644 --- a/src/Mod/Inspection/Init.py +++ b/src/Mod/Inspection/Init.py @@ -1,24 +1,24 @@ -#*************************************************************************** -#* Copyright (c) 2001,2002 Juergen Riegel * -#* * -#* This file is part of the FreeCAD CAx development system. * -#* * -#* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU Lesser General Public License (LGPL) * -#* as published by the Free Software Foundation; either version 2 of * -#* the License, or (at your option) any later version. * -#* for detail see the LICENCE text file. * -#* * -#* 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 Library General Public * -#* License along with FreeCAD; if not, write to the Free Software * -#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * -#* USA * -#* * -#***************************************************************************/ +# *************************************************************************** +# * Copyright (c) 2001,2002 Juergen Riegel * +# * * +# * This file is part of the FreeCAD CAx development system. * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * 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 Library General Public * +# * License along with FreeCAD; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# ***************************************************************************/ # FreeCAD init script of the Inspection module diff --git a/src/Mod/Inspection/InitGui.py b/src/Mod/Inspection/InitGui.py index 49cf1f7bba..20a4ca3e42 100644 --- a/src/Mod/Inspection/InitGui.py +++ b/src/Mod/Inspection/InitGui.py @@ -1,25 +1,25 @@ -#*************************************************************************** -#* Copyright (c) 2002,2003 Juergen Riegel * -#* * -#* This file is part of the FreeCAD CAx development system. * -#* * -#* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU Lesser General Public License (LGPL) * -#* as published by the Free Software Foundation; either version 2 of * -#* the License, or (at your option) any later version. * -#* for detail see the LICENCE text file. * -#* * -#* 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 Library General Public * -#* License along with FreeCAD; if not, write to the Free Software * -#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * -#* USA * -#* * -#***************************************************************************/ +# *************************************************************************** +# * Copyright (c) 2002,2003 Juergen Riegel * +# * * +# * This file is part of the FreeCAD CAx development system. * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * 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 Library General Public * +# * License along with FreeCAD; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# ***************************************************************************/ # Inspection gui init module # @@ -27,17 +27,23 @@ # This is the second one of three init scripts, the third one # runs when the gui is up -class InspectionWorkbench ( Workbench ): + +class InspectionWorkbench(Workbench): "Inspection workbench object" + def __init__(self): - self.__class__.Icon = FreeCAD.getResourceDir() + "Mod/Inspection/Resources/icons/InspectionWorkbench.svg" + self.__class__.Icon = ( + FreeCAD.getResourceDir() + "Mod/Inspection/Resources/icons/InspectionWorkbench.svg" + ) self.__class__.MenuText = "Inspection" self.__class__.ToolTip = "Inspection workbench" def Initialize(self): # load the module import InspectionGui + def GetClassName(self): return "InspectionGui::Workbench" + Gui.addWorkbench(InspectionWorkbench()) diff --git a/src/Mod/Inspection/InspectionGlobal.h b/src/Mod/Inspection/InspectionGlobal.h index 99f594df32..a5981c491e 100644 --- a/src/Mod/Inspection/InspectionGlobal.h +++ b/src/Mod/Inspection/InspectionGlobal.h @@ -29,19 +29,19 @@ // Inspection #ifndef InspectionExport #ifdef Inspection_EXPORTS -# define InspectionExport FREECAD_DECL_EXPORT +#define InspectionExport FREECAD_DECL_EXPORT #else -# define InspectionExport FREECAD_DECL_IMPORT +#define InspectionExport FREECAD_DECL_IMPORT #endif #endif // InspectionGui #ifndef InspectionGuiExport #ifdef InspectionGui_EXPORTS -# define InspectionGuiExport FREECAD_DECL_EXPORT +#define InspectionGuiExport FREECAD_DECL_EXPORT #else -# define InspectionGuiExport FREECAD_DECL_IMPORT +#define InspectionGuiExport FREECAD_DECL_IMPORT #endif #endif -#endif //INSPECTION_GLOBAL_H +#endif// INSPECTION_GLOBAL_H