From 86a7ed44e0ed6185957ebc33b2da0677afa78438 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 1 Sep 2015 12:50:10 +0200 Subject: [PATCH 1/3] + fix various warnings with VC++ --- src/Mod/Draft/App/CMakeLists.txt | 2 +- src/Mod/Draft/App/PreCompiled.h | 4 ++++ src/Mod/Draft/App/dxf.cpp | 4 ++-- src/Mod/Path/libarea/AreaClipper.cpp | 19 +++++++++++-------- src/Mod/Sketcher/App/planegcs/Geo.cpp | 2 +- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/Mod/Draft/App/CMakeLists.txt b/src/Mod/Draft/App/CMakeLists.txt index 11ce0c4c8..87a357889 100644 --- a/src/Mod/Draft/App/CMakeLists.txt +++ b/src/Mod/Draft/App/CMakeLists.txt @@ -1,5 +1,5 @@ if(MSVC) - add_definitions(-DHAVE_ACOSH -DHAVE_ASINH -DHAVE_ATANH) + add_definitions(-DHAVE_ACOSH -DHAVE_ASINH -DHAVE_ATANH -D_CRT_SECURE_NO_WARNINGS) else(MSVC) add_definitions(-DHAVE_LIMITS_H -DHAVE_CONFIG_H) endif(MSVC) diff --git a/src/Mod/Draft/App/PreCompiled.h b/src/Mod/Draft/App/PreCompiled.h index 73e7bb7e9..f263d391d 100644 --- a/src/Mod/Draft/App/PreCompiled.h +++ b/src/Mod/Draft/App/PreCompiled.h @@ -37,6 +37,10 @@ # define BaseExport #endif +#ifdef _MSC_VER +# pragma warning(disable : 4275) +#endif + #ifdef _PreComp_ // standard diff --git a/src/Mod/Draft/App/dxf.cpp b/src/Mod/Draft/App/dxf.cpp index fed2fcad6..8c0cb51da 100644 --- a/src/Mod/Draft/App/dxf.cpp +++ b/src/Mod/Draft/App/dxf.cpp @@ -1419,10 +1419,10 @@ void CDxfRead::get_line() m_ifs->getline(m_str, 1024); char str[1024]; - int len = strlen(m_str); + size_t len = strlen(m_str); int j = 0; bool non_white_found = false; - for(int i = 0; i 1; j--)MakeLoop(p[j], p[j-1], p[j-2], radius); + for(std::size_t j = p.size()-1; j > 1; j--)MakeLoop(p[j], p[j-1], p[j-2], radius); MakeLoop(p[1], p[0], p[p.size()-1], radius); MakeLoop(p[0], p[p.size()-1], p[p.size()-2], radius); } @@ -260,7 +263,7 @@ static void OffsetWithLoops(const TPolyPolygon &pp, TPolyPolygon &pp_new, double const TPolygon& p = copy[i]; TPolygon p_new; p_new.resize(p.size()); - int size_minus_one = p.size() - 1; + std::size_t size_minus_one = p.size() - 1; for(unsigned int j = 0; j < p.size(); j++)p_new[j] = p[size_minus_one - j]; pp_new[i] = p_new; } @@ -337,7 +340,7 @@ static void OffsetSpansWithObrounds(const CArea& area, TPolyPolygon &pp_new, dou const TPolygon& p = copy[i]; TPolygon p_new; p_new.resize(p.size()); - int size_minus_one = p.size() - 1; + std::size_t size_minus_one = p.size() - 1; for(unsigned int j = 0; j < p.size(); j++)p_new[j] = p[size_minus_one - j]; pp_new[i] = p_new; } @@ -362,7 +365,7 @@ static void MakePolyPoly( const CArea& area, TPolyPolygon &pp, bool reverse = tr p.resize(pts_for_AddVertex.size()); if(reverse) { - unsigned int i = pts_for_AddVertex.size() - 1;// clipper wants them the opposite way to CArea + std::size_t i = pts_for_AddVertex.size() - 1;// clipper wants them the opposite way to CArea for(std::list::iterator It = pts_for_AddVertex.begin(); It != pts_for_AddVertex.end(); It++, i--) { p[i] = It->int_point(); diff --git a/src/Mod/Sketcher/App/planegcs/Geo.cpp b/src/Mod/Sketcher/App/planegcs/Geo.cpp index 554085548..10b02c36d 100644 --- a/src/Mod/Sketcher/App/planegcs/Geo.cpp +++ b/src/Mod/Sketcher/App/planegcs/Geo.cpp @@ -55,7 +55,7 @@ DeriVector2 DeriVector2::getNormalized() const { double l=length(); if(l==0.0) { - return DeriVector2(0, 0, dx/0.0, dy/0.0); + return DeriVector2(0, 0, dx, dy); } else { DeriVector2 rtn; rtn.x = x/l; From 9846e52ed96e3b81ff9bee2f41c4940cbcd276a4 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 1 Sep 2015 13:49:01 +0200 Subject: [PATCH 2/3] + fix flaws in class PropertyVectorDistance --- src/App/PropertyGeo.h | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/App/PropertyGeo.h b/src/App/PropertyGeo.h index c82650afa..e97c7e8a9 100644 --- a/src/App/PropertyGeo.h +++ b/src/App/PropertyGeo.h @@ -117,24 +117,9 @@ public: */ virtual ~PropertyVectorDistance(); - /** Sets the property - */ - void setValue(const Base::Vector3d &vec); - void setValue(double x, double y, double z); - - /** This method returns a string representation of the property - */ - const Base::Vector3d &getValue(void) const; const char* getEditorName(void) const { return "Gui::PropertyEditor::PropertyVectorDistanceItem"; } - - virtual unsigned int getMemSize (void) const { - return sizeof(Base::Vector3d); - } - -private: - Base::Vector3d _cVec; }; From 3a4e93bb3d511910d065c830c5b7ab408974d277 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 1 Sep 2015 14:59:14 +0200 Subject: [PATCH 3/3] + implement method getPointNormals --- src/Mod/Mesh/App/Mesh.cpp | 20 ++++++++++++++++++++ src/Mod/Mesh/App/Mesh.h | 1 + src/Mod/Mesh/App/MeshPy.xml | 8 ++++++++ src/Mod/Mesh/App/MeshPyImp.cpp | 16 ++++++++++++++++ 4 files changed, 45 insertions(+) diff --git a/src/Mod/Mesh/App/Mesh.cpp b/src/Mod/Mesh/App/Mesh.cpp index 17f7af8a5..dda001601 100644 --- a/src/Mod/Mesh/App/Mesh.cpp +++ b/src/Mod/Mesh/App/Mesh.cpp @@ -834,6 +834,26 @@ Base::Vector3d MeshObject::getPointNormal(unsigned long index) const return normal; } +std::vector MeshObject::getPointNormals() const +{ + std::vector temp = _kernel.CalcVertexNormals(); + + std::vector normals; + normals.reserve(temp.size()); + for (std::vector::iterator it = temp.begin(); it != temp.end(); ++it) { + Base::Vector3d normal = transformToOutside(*it); + // the normal is a vector, hence we must not apply the translation part + // of the transformation to the vector + normal.x -= _Mtrx[0][3]; + normal.y -= _Mtrx[1][3]; + normal.z -= _Mtrx[2][3]; + normal.Normalize(); + normals.push_back(normal); + } + + return normals; +} + void MeshObject::crossSections(const std::vector& planes, std::vector §ions, float fMinEps, bool bConnectPolygons) const { diff --git a/src/Mod/Mesh/App/Mesh.h b/src/Mod/Mesh/App/Mesh.h index d55d56711..74d224382 100644 --- a/src/Mod/Mesh/App/Mesh.h +++ b/src/Mod/Mesh/App/Mesh.h @@ -205,6 +205,7 @@ public: void setPoint(unsigned long, const Base::Vector3d& v); void smooth(int iterations, float d_max); Base::Vector3d getPointNormal(unsigned long) const; + std::vector getPointNormals() const; void crossSections(const std::vector&, std::vector §ions, float fMinEps = 1.0e-2f, bool bConnectPolygons = false) const; void cut(const Base::Polygon2D& polygon, const Base::ViewProjMethod& proj, CutType); diff --git a/src/Mod/Mesh/App/MeshPy.xml b/src/Mod/Mesh/App/MeshPy.xml index fd9949777..05d483f3e 100644 --- a/src/Mod/Mesh/App/MeshPy.xml +++ b/src/Mod/Mesh/App/MeshPy.xml @@ -155,6 +155,14 @@ Example: + + + + getPointNormals() + Get the normals of the points. + + + Get the number of segments which may also be 0 diff --git a/src/Mod/Mesh/App/MeshPyImp.cpp b/src/Mod/Mesh/App/MeshPyImp.cpp index 85ca92a02..f46eb00db 100644 --- a/src/Mod/Mesh/App/MeshPyImp.cpp +++ b/src/Mod/Mesh/App/MeshPyImp.cpp @@ -685,6 +685,22 @@ PyObject* MeshPy::setPoint(PyObject *args) Py_Return; } +PyObject* MeshPy::getPointNormals(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return NULL; + + PY_TRY { + std::vector normals = getMeshObjectPtr()->getPointNormals(); + Py::Tuple ary(normals.size()); + std::size_t numNormals = normals.size(); + for (std::size_t i=0; i