Salome HOME
Fix size of the returned vector in planar case
[modules/smesh.git] / src / SMESH / SMESH_MeshEditor.cxx
index f9d0348c79d4fa19f71d878b98a8bbe20bbd3f1a..a3d2b226e49a9f2ffb7b73fa9e297d0347c7e835 100644 (file)
@@ -12867,9 +12867,23 @@ namespace // utils for MakePolyLine
 
     bool Extend( const gp_XYZ& plnNorm, const gp_XYZ& plnOrig );
 
+    bool ReachSamePoint( const Path& other );
+
     static void Remove( std::vector< Path > & paths, size_t& i );
   };
 
+  //================================================================================
+  /*!
+   * \brief Return true if this Path meats another
+   */
+  //================================================================================
+
+  bool Path::ReachSamePoint( const Path& other )
+  {
+    return ( mySrcPntInd != other.mySrcPntInd &&
+             myFace == other.myFace );
+  }
+
   //================================================================================
   /*!
    * \brief Remove a path from a vector
@@ -12884,12 +12898,15 @@ namespace // utils for MakePolyLine
       if ( i < j )
       {
         paths[ i ].myPoints.swap( paths[ j ].myPoints );
-        paths[ i ].myFace     = paths[ j ].myFace;
-        paths[ i ].myNodeInd1 = paths[ j ].myNodeInd1;
-        paths[ i ].myNodeInd2 = paths[ j ].myNodeInd2;
-        paths[ i ].myNode1    = paths[ j ].myNode1;
-        paths[ i ].myNode2    = paths[ j ].myNode2;
-        paths[ i ].myLength   = paths[ j ].myLength;
+        paths[ i ].myLength    = paths[ j ].myLength;
+        paths[ i ].mySrcPntInd = paths[ j ].mySrcPntInd;
+        paths[ i ].myFace      = paths[ j ].myFace;
+        paths[ i ].myNode1     = paths[ j ].myNode1;
+        paths[ i ].myNode2     = paths[ j ].myNode2;
+        paths[ i ].myNodeInd1  = paths[ j ].myNodeInd1;
+        paths[ i ].myNodeInd2  = paths[ j ].myNodeInd2;
+        paths[ i ].myDot1      = paths[ j ].myDot1;
+        paths[ i ].myDot2      = paths[ j ].myDot2;
       }
     }
     paths.pop_back();
@@ -13056,7 +13073,7 @@ namespace // utils for MakePolyLine
       if ( polySeg.myNode2[1] ) p2 = 0.5 * ( p2 + SMESH_NodeXYZ( polySeg.myNode2[1] ));
 
       gp_XYZ plnNorm = ( p1 - p2 ) ^ polySeg.myVector.XYZ();
-      gp_XYZ plnOrig = SMESH_NodeXYZ( polySeg.myNode1[0] );
+      gp_XYZ plnOrig = p2;
 
       // find paths connecting the 2 end points of polySeg
 
@@ -13139,9 +13156,7 @@ namespace // utils for MakePolyLine
           // join paths that reach same point
           for ( size_t j = 0; j < paths.size(); ++j )
           {
-            if ( i != j &&
-                 paths[i].myFace == paths[j].myFace &&
-                 paths[i].mySrcPntInd != paths[j].mySrcPntInd )
+            if ( i != j && paths[i].ReachSamePoint( paths[j] ))
             {
               double   distLast = ( paths[i].myPoints.back() - paths[j].myPoints.back() ).Modulus();
               double fullLength = ( paths[i].myLength + paths[j].myLength + distLast );
@@ -13194,6 +13209,7 @@ void SMESH_MeshEditor::MakePolyLine( TListOfPolySegments&   theSegments,
   // get cutting planes
 
   std::vector< bool > isVectorOK( theSegments.size(), true );
+  const double planarCoef = 0.333; // plane height in planar case
 
   for ( size_t iSeg = 0; iSeg < theSegments.size(); ++iSeg )
   {
@@ -13216,8 +13232,16 @@ void SMESH_MeshEditor::MakePolyLine( TListOfPolySegments&   theSegments,
       if ( polySeg.myMidProjPoint.Distance( pMid ) < Precision::Confusion() )
       {
         SMESH_MeshAlgos::FaceNormal( face, const_cast< gp_XYZ& >( polySeg.myVector.XYZ() ));
-        polySeg.myMidProjPoint = pMid + polySeg.myVector.XYZ();
+        polySeg.myMidProjPoint = pMid + polySeg.myVector.XYZ() * ( p1 - p2 ).Modulus() * planarCoef;
       }
+      else
+      {
+        polySeg.myVector = polySeg.myMidProjPoint.XYZ() - pMid;
+      }
+    }
+    else
+    {
+      polySeg.myVector = plnNorm ^ ( p1 - p2 );
     }
   }
 
@@ -13265,21 +13289,24 @@ void SMESH_MeshEditor::MakePolyLine( TListOfPolySegments&   theSegments,
 
     // return a vector
 
+    gp_XYZ pMid = 0.5 * ( path.myPoints[0] + path.myPoints.back() );
     if ( isVectorOK[ iSeg ])
     {
       // find the most distance point of a path
       double maxDist = 0;
       for ( size_t iP = 1; iP < path.myPoints.size(); ++iP )
       {
-        double dist = theSegments[iSeg].myVector * ( path.myPoints[iP] - path.myPoints[0] );
+        double dist = Abs( theSegments[iSeg].myVector * ( path.myPoints[iP] - path.myPoints[0] ));
         if ( dist > maxDist )
         {
           maxDist = dist;
           theSegments[iSeg].myMidProjPoint = path.myPoints[iP];
         }
       }
+      if ( maxDist < Precision::Confusion() ) // planar case
+        theSegments[iSeg].myMidProjPoint =
+          pMid + theSegments[iSeg].myVector.XYZ().Normalized() * path.myLength * planarCoef;
     }
-    gp_XYZ pMid = 0.5 * ( path.myPoints[0] + path.myPoints.back() );
     theSegments[iSeg].myVector = gp_Vec( pMid, theSegments[iSeg].myMidProjPoint );
   }