#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
{
// 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;
else if ( !theLastSegment.IsNull() ) {
TopExp_Explorer vertexExp( theLastSegment, TopAbs_VERTEX );
theApplyedWire = vertexExp.Current();
- }
+ }
+ */
return true;
}
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())