From: Artem Zhidkov Date: Tue, 13 Oct 2020 20:08:45 +0000 (+0300) Subject: Issue #20204: Wrong sketch in master from 9.5.0 python script X-Git-Tag: V9_6_0b1~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=dc91eb210a1a2709c1520c70dc94f3e3806d74d7;p=modules%2Fshaper.git Issue #20204: Wrong sketch in master from 9.5.0 python script Improve the orientation of the curve projected onto sketch plane. --- diff --git a/CMakeCommon/UnitTest.cmake b/CMakeCommon/UnitTest.cmake index 730f12136..6e47a8072 100644 --- a/CMakeCommon/UnitTest.cmake +++ b/CMakeCommon/UnitTest.cmake @@ -127,3 +127,54 @@ MACRO(ADD_UNIT_TESTS_API) ENDIF(EXISTS ${aTestFileName}) endforeach(eachFileName ${ARGN}) ENDMACRO(ADD_UNIT_TESTS_API) + + +function(ADD_RESTRICTED_TESTS) + SET(RESTRICTED_ROOT_DIR $ENV{RESTRICTED_ROOT_DIR} CACHE PATH "Path to the restricted repository") + + if (NOT EXISTS ${RESTRICTED_ROOT_DIR}) + message(WARNING "RESTRICTED_ROOT_DIR is not specified to run restricted tests") + return() + endif() + + if (WIN32) # different separators and path to libraries variable name + SET(_JUSTPATH "${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_BIN};${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_SWIG};${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_PLUGIN_FILES};${SUIT_LIB_DIR};${SALOME_KERNEL_LIBDIR};$ENV{PATH}") + STRING(REPLACE "\\" "/" _JUSTPATH "${_JUSTPATH}") + STRING(REPLACE ";" "\\;" _JUSTPATH "${_JUSTPATH}") + SET(_PYTHONPATH "${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_SWIG};${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_PLUGIN_FILES};${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_ADDONS};$ENV{PYTHONPATH}") + STRING(REPLACE "\\" "/" _PYTHONPATH "${_PYTHONPATH}") + STRING(REPLACE ";" "\\;" _PYTHONPATH "${_PYTHONPATH}") + else() + SET(_LD_LIBRARY_PATH "${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_BIN}:${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_SWIG}:${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_PLUGIN_FILES}:${SUIT_LIB_DIR}:${SALOME_KERNEL_LIBDIR}:$ENV{LD_LIBRARY_PATH}") + SET(_PYTHONPATH "${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_SWIG}:${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_PLUGIN_FILES}:${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_ADDONS}:$ENV{PYTHONPATH}") + endif() + + foreach(eachFileName ${ARGN}) + # Strip the ".py" suffix + GET_FILENAME_COMPONENT(aTestName ${eachFileName} NAME_WE) + + # Add "SubprojectName_" prefix + GET_FILENAME_COMPONENT(aSubprojectName ${CMAKE_CURRENT_SOURCE_DIR} NAME) + SET(aTestName "${aSubprojectName}_${aTestName}") + + # Full path to the python test file beeing executed + SET(aTestFileName "${RESTRICTED_ROOT_DIR}/SHAPER/bugs/${eachFileName}") + IF(EXISTS ${aTestFileName}) + ADD_TEST(NAME ${aTestName} + COMMAND ${PYTHON_EXECUTABLE} ${aTestFileName}) + if (WIN32) # different path to libraries variable name + SET_TESTS_PROPERTIES(${aTestName} PROPERTIES + ENVIRONMENT "PATH=${_JUSTPATH};PYTHONPATH=${_PYTHONPATH};SHAPER_UNIT_TEST_IN_PROGRESS=1" + LABELS "${aSubprojectName}") + else() + SET_TESTS_PROPERTIES(${aTestName} PROPERTIES + ENVIRONMENT "LD_LIBRARY_PATH=${_LD_LIBRARY_PATH};PYTHONPATH=${_PYTHONPATH};SHAPER_UNIT_TEST_IN_PROGRESS=1" + LABELS "${aSubprojectName}") + endif() + # Debug output... + #MESSAGE(STATUS "Test added: ${aTestName} file: ${aTestFileName}") + ELSE(EXISTS ${aTestFileName}) + MESSAGE(WARNING "Can not find the test file: ${aTestFileName}") + ENDIF(EXISTS ${aTestFileName}) + endforeach(eachFileName ${ARGN}) +endfunction(ADD_RESTRICTED_TESTS) diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 85715599a..3fcc4e389 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -406,3 +406,7 @@ if(${SKETCHER_CHANGE_RADIUS_WHEN_MOVE}) TestMovePoint.py ) endif() + +ADD_RESTRICTED_TESTS( + Test20204.py +) \ No newline at end of file diff --git a/src/SketchPlugin/SketchPlugin_Projection.cpp b/src/SketchPlugin/SketchPlugin_Projection.cpp index 9133b197d..48d4a7323 100644 --- a/src/SketchPlugin/SketchPlugin_Projection.cpp +++ b/src/SketchPlugin/SketchPlugin_Projection.cpp @@ -395,7 +395,7 @@ bool SketchPlugin_Projection::projectEdge(FeaturePtr& theProjection, const GeomE if (aProjectedCurve->isCircle()) { if (aProjectedCurve->isTrimmed()) { // ARC is a projection - isOk = fillArc(theProjection, aProjectedCurve, aSketchPlane); + isOk = fillArc(theProjection, aProjectedCurve, aSketchPlane, theEdge); } else { // CIRCLE is a projection @@ -405,7 +405,7 @@ bool SketchPlugin_Projection::projectEdge(FeaturePtr& theProjection, const GeomE else if (aProjectedCurve->isEllipse()) { if (aProjectedCurve->isTrimmed()) { // ELLIPTIC ARC is a projection - isOk = fillEllipticArc(theProjection, aProjectedCurve, aSketchPlane); + isOk = fillEllipticArc(theProjection, aProjectedCurve, aSketchPlane, theEdge); } else { // ELLIPSE is a projection @@ -420,7 +420,8 @@ bool SketchPlugin_Projection::projectEdge(FeaturePtr& theProjection, const GeomE bool SketchPlugin_Projection::fillArc(FeaturePtr& theProjection, const GeomCurvePtr& theArc, - const GeomPlanePtr& thePlane) + const GeomPlanePtr& thePlane, + const GeomEdgePtr& theOriginalEdge) { rebuildProjectedFeature(theProjection, ARC_PROJECTION(), SketchPlugin_Arc::ID()); @@ -432,6 +433,13 @@ bool SketchPlugin_Projection::fillArc(FeaturePtr& theProjection, bool isInversed = aNormalsDot < 0.; + GeomCirclePtr anOriginalCircle = theOriginalEdge->circle(); + if (anOriginalCircle) { + double aCirclesDot = anOriginalCircle->normal()->dot(aCircle.normal()); + if (aCirclesDot < 0.) + isInversed = !isInversed; + } + GeomPointPtr aCenter = thePlane->project(aCircle.center()); GeomPnt2dPtr aCenterInSketch = sketch()->to2D(aCenter); @@ -508,7 +516,8 @@ bool SketchPlugin_Projection::fillEllipse(FeaturePtr& theProjection, bool SketchPlugin_Projection::fillEllipticArc(FeaturePtr& theProjection, const GeomCurvePtr& theEllipticArc, - const GeomPlanePtr& thePlane) + const GeomPlanePtr& thePlane, + const GeomEdgePtr& theOriginalEdge) { rebuildProjectedFeature(theProjection, ARC_PROJECTION(), SketchPlugin_EllipticArc::ID()); @@ -520,6 +529,13 @@ bool SketchPlugin_Projection::fillEllipticArc(FeaturePtr& theProjection, bool isInversed = aNormalsDot < 0.; + GeomEllipsePtr anOriginalEllipse = theOriginalEdge->ellipse(); + if (anOriginalEllipse) { + double anEllipsesDot = anOriginalEllipse->normal()->dot(anEllipse.normal()); + if (anEllipsesDot < 0.) + isInversed = !isInversed; + } + GeomPointPtr aCenter = thePlane->project(anEllipse.center()); GeomPnt2dPtr aCenterInSketch = sketch()->to2D(aCenter); GeomPointPtr aFocus = thePlane->project(anEllipse.firstFocus()); diff --git a/src/SketchPlugin/SketchPlugin_Projection.h b/src/SketchPlugin/SketchPlugin_Projection.h index aea956bc5..cd39b8c16 100644 --- a/src/SketchPlugin/SketchPlugin_Projection.h +++ b/src/SketchPlugin/SketchPlugin_Projection.h @@ -126,7 +126,8 @@ private: /// \brief Fill attributes of the Arc feature bool fillArc(FeaturePtr& theProjection, const std::shared_ptr& theArc, - const std::shared_ptr& thePlane); + const std::shared_ptr& thePlane, + const std::shared_ptr& theOriginalEdge); /// \brief Fill attributes of the Circle feature bool fillCircle(FeaturePtr& theProjection, const std::shared_ptr& theCircle, @@ -138,7 +139,8 @@ private: /// \brief Fill attributes of the EllipticArc feature bool fillEllipticArc(FeaturePtr& theProjection, const std::shared_ptr& theEllipticArc, - const std::shared_ptr& thePlane); + const std::shared_ptr& thePlane, + const std::shared_ptr& theOriginalEdge); /// \brief Fill attributes of the B-spline feature bool fillBSpline(FeaturePtr& theProjection, const std::shared_ptr& theCurve,