From 0b3222f523f130a37a68000f203405c019e8db18 Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 10 Jun 2010 14:52:53 +0000 Subject: [PATCH] Issue 0020899: EDF 1434: Bad color in the pre-visualization of the 3D sketcher --- src/EntityGUI/EntityGUI_3DSketcherDlg.cxx | 61 ++++++++++++++++++---- src/GEOMImpl/GEOMImpl_3DSketcherDriver.cxx | 35 ++++++++----- 2 files changed, 71 insertions(+), 25 deletions(-) diff --git a/src/EntityGUI/EntityGUI_3DSketcherDlg.cxx b/src/EntityGUI/EntityGUI_3DSketcherDlg.cxx index cd93e922e..43e6e8981 100755 --- a/src/EntityGUI/EntityGUI_3DSketcherDlg.cxx +++ b/src/EntityGUI/EntityGUI_3DSketcherDlg.cxx @@ -39,14 +39,17 @@ #include #include -#include -#include -#include -#include -#include +//#include +//#include +//#include +//#include +//#include #include -#include -#include +//#include +//#include +#include +#include +#include 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 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; } diff --git a/src/GEOMImpl/GEOMImpl_3DSketcherDriver.cxx b/src/GEOMImpl/GEOMImpl_3DSketcherDriver.cxx index f33fa29b9..6f0adcf50 100755 --- a/src/GEOMImpl/GEOMImpl_3DSketcherDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_3DSketcherDriver.cxx @@ -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 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::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()) -- 2.39.2