]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #20204: Wrong sketch in master from 9.5.0 python script
authorArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Tue, 13 Oct 2020 20:08:45 +0000 (23:08 +0300)
committerArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Tue, 13 Oct 2020 20:08:45 +0000 (23:08 +0300)
Improve the orientation of the curve projected onto sketch plane.

CMakeCommon/UnitTest.cmake
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_Projection.cpp
src/SketchPlugin/SketchPlugin_Projection.h

index 730f12136d2b66a889079458772d84114e3110ee..6e47a80720389bda38030e991af0b2263507fb7d 100644 (file)
@@ -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)
index 85715599a3ad59a2f4826293fb927fc86962cdf4..3fcc4e38983062588a70b457fcd7732c1dbfbae7 100644 (file)
@@ -406,3 +406,7 @@ if(${SKETCHER_CHANGE_RADIUS_WHEN_MOVE})
     TestMovePoint.py
   )
 endif()
+
+ADD_RESTRICTED_TESTS(
+  Test20204.py
+)
\ No newline at end of file
index 9133b197d9b7e41ad005435b53e336ff9f70454c..48d4a7323e82ee7de6cc4b2b17053964193b328f 100644 (file)
@@ -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());
index aea956bc5fb72f683d138b3f166f8a05dc0d3d8e..cd39b8c1670987ac390860060b6c62789abe44fa 100644 (file)
@@ -126,7 +126,8 @@ private:
   /// \brief Fill attributes of the Arc feature
   bool fillArc(FeaturePtr& theProjection,
                const std::shared_ptr<GeomAPI_Curve>& theArc,
-               const std::shared_ptr<GeomAPI_Pln>& thePlane);
+               const std::shared_ptr<GeomAPI_Pln>& thePlane,
+               const std::shared_ptr<GeomAPI_Edge>& theOriginalEdge);
   /// \brief Fill attributes of the Circle feature
   bool fillCircle(FeaturePtr& theProjection,
                   const std::shared_ptr<GeomAPI_Curve>& theCircle,
@@ -138,7 +139,8 @@ private:
   /// \brief Fill attributes of the EllipticArc feature
   bool fillEllipticArc(FeaturePtr& theProjection,
                        const std::shared_ptr<GeomAPI_Curve>& theEllipticArc,
-                       const std::shared_ptr<GeomAPI_Pln>& thePlane);
+                       const std::shared_ptr<GeomAPI_Pln>& thePlane,
+                       const std::shared_ptr<GeomAPI_Edge>& theOriginalEdge);
   /// \brief Fill attributes of the B-spline feature
   bool fillBSpline(FeaturePtr& theProjection,
                    const std::shared_ptr<GeomAPI_Curve>& theCurve,