]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
Issue 0020899: EDF 1434: Bad color in the pre-visualization of the 3D sketcher
authorvsr <vsr@opencascade.com>
Thu, 10 Jun 2010 14:52:53 +0000 (14:52 +0000)
committervsr <vsr@opencascade.com>
Thu, 10 Jun 2010 14:52:53 +0000 (14:52 +0000)
src/EntityGUI/EntityGUI_3DSketcherDlg.cxx
src/GEOMImpl/GEOMImpl_3DSketcherDriver.cxx

index cd93e922eae5213e47caf393f35b6b45b235dd02..43e6e8981c13367e8d558777705a0253a1fdc070 100755 (executable)
 #include <LightApp_Application.h>
 #include <LightApp_SelectionMgr.h>
 
-#include <BRep_Tool.hxx>
-#include <TopExp.hxx>
-#include <TopExp_Explorer.hxx>
-#include <TopoDS_Vertex.hxx>
-#include <TopoDS.hxx>
+//#include <BRep_Tool.hxx>
+//#include <TopExp.hxx>
+//#include <TopExp_Explorer.hxx>
+//#include <TopoDS_Vertex.hxx>
+//#include <TopoDS.hxx>
 #include <TColStd_IndexedMapOfInteger.hxx>
-#include <BRepBuilderAPI_Transform.hxx>
-#include <BRepBuilderAPI_MakeWire.hxx>
+//#include <BRepBuilderAPI_Transform.hxx>
+//#include <BRepBuilderAPI_MakeWire.hxx>
+#include <BRepBuilderAPI_MakeVertex.hxx>
+#include <BRepBuilderAPI_MakePolygon.hxx>
+#include <BRepBuilderAPI_MakeEdge.hxx>
 
 class Locker
 {
@@ -596,13 +599,48 @@ void EntityGUI_3DSketcherDlg::displayPreview( GEOM::GEOM_Object_ptr object,
 // Function : createShapes
 // Purpose  : Create applyed wire, and last segment from entry object
 //================================================================
-bool EntityGUI_3DSketcherDlg::createShapes( GEOM::GEOM_Object_ptr theObject,
+bool EntityGUI_3DSketcherDlg::createShapes( GEOM::GEOM_Object_ptr /*theObject*/,
                                             TopoDS_Shape&         theApplyedWire,
                                             TopoDS_Shape&         theLastSegment )
 {
+  QList<gp_Pnt> points;
+  foreach( XYZ xyz, myPointsList) {
+    gp_Pnt p(xyz.x, xyz.y, xyz.z);
+    if ( points.isEmpty() || points.last().Distance(p) > gp::Resolution())
+      points << p;
+  } 
+  
+  if ( points.count() == 1 ) {
+    // only one point is created
+    BRepBuilderAPI_MakeVertex mkVertex (points.last());
+    theApplyedWire = mkVertex.Shape();
+  }
+  else if ( points.count() > 1 ) {
+    // wire is created
+    BRepBuilderAPI_MakePolygon mkWire;
+    foreach( gp_Pnt p, points )
+      mkWire.Add(p);
+    theApplyedWire = mkWire.Shape();
+  }
+
+  XYZ curxyz = getCurrentPoint();
+  gp_Pnt curpnt(curxyz.x, curxyz.y, curxyz.z);
+  
+  if ( points.isEmpty() || points.last().Distance(curpnt) <= gp::Resolution() ) {
+    BRepBuilderAPI_MakeVertex mkVertex (curpnt);
+    theLastSegment = mkVertex.Shape();
+  }
+  else {
+    BRepBuilderAPI_MakeEdge mkEdge(points.last(), curpnt);
+    theLastSegment = mkEdge.Shape();
+  }
+
+  /* VSR: old algorithm does not work properly, see bug 0020899
   TopoDS_Shape aShape;
-  if ( !GEOMBase::GetShape( theObject, aShape ) ||
-       aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX )
+  if ( !GEOMBase::GetShape( theObject, aShape ) )
+    return false;
+
+  if( aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX )
     return false;
 
   theApplyedWire = aShape;
@@ -628,7 +666,8 @@ bool EntityGUI_3DSketcherDlg::createShapes( GEOM::GEOM_Object_ptr theObject,
   else if ( !theLastSegment.IsNull() ) {
     TopExp_Explorer vertexExp( theLastSegment, TopAbs_VERTEX );
     theApplyedWire = vertexExp.Current();
-  }
+    }
+  */
 
   return true;
 }
index f33fa29b9cd2578ed87815834cbd27a021a122bc..6f0adcf50bb8e4615d87ac8c349ccc274a2e89d5 100755 (executable)
@@ -69,24 +69,31 @@ Standard_Integer GEOMImpl_3DSketcherDriver::Execute(TFunction_Logbook& log) cons
   TopoDS_Shape aShape;
 
   Handle(TColStd_HArray1OfReal) aCoordsArray = aCI.GetCoordinates();
-
-  BRepBuilderAPI_MakePolygon aMakePoly;
   int anArrayLength = aCoordsArray->Length();
-  double x, y, z;
-  gp_Pnt aPnt;
-  for (int i = 0; i <=(anArrayLength - 3); i+=3) {
-    x = aCoordsArray->Value(i+1);
-    y = aCoordsArray->Value(i+2);
-    z = aCoordsArray->Value(i+3);
-    aPnt = gp_Pnt(x, y, z);
-    aMakePoly.Add(aPnt);
+
+  std::list<gp_Pnt> points;
+  
+  for (int i = 0; i <= (anArrayLength-3); i += 3) {
+    gp_Pnt aPnt = gp_Pnt(aCoordsArray->Value(i+1), aCoordsArray->Value(i+2), aCoordsArray->Value(i+3));
+    if (points.empty() || aPnt.Distance(points.back()) > gp::Resolution())
+      points.push_back(aPnt);
   }
-  if ( anArrayLength == 3) { // Only Start Point
-    BRepBuilderAPI_MakeVertex mkVertex (aPnt);
+
+  if ( points.size() == 1) { // Only Start Point
+    BRepBuilderAPI_MakeVertex mkVertex (points.back());
     aShape = mkVertex.Shape();
   }
-  else { // Make Wire
-    if (aCoordsArray->Value(1) == x && aCoordsArray->Value(2) == y && aCoordsArray->Value(3) == z)
+  else if ( points.size() > 1) { // Make Wire
+    BRepBuilderAPI_MakePolygon aMakePoly;
+    std::list<gp_Pnt>::iterator it;
+    for (it = points.begin(); it != points.end(); ++it) {
+      aMakePoly.Add(*it);
+    }
+
+    if (points.size() > 2 && 
+       points.back().X() == points.front().X() && 
+       points.back().Y() == points.front().Y() && 
+       points.back().Z() == points.front().Z())
       aMakePoly.Close();
     
     if (aMakePoly.IsDone())