Issue 0020899: EDF 1434: Bad color in the pre-visualization of the 3D sketcher

This commit is contained in:
vsr 2010-06-10 14:52:53 +00:00
parent 01f5a34efc
commit 0b3222f523
2 changed files with 71 additions and 25 deletions

View File

@ -39,14 +39,17 @@
#include <LightApp_Application.h> #include <LightApp_Application.h>
#include <LightApp_SelectionMgr.h> #include <LightApp_SelectionMgr.h>
#include <BRep_Tool.hxx> //#include <BRep_Tool.hxx>
#include <TopExp.hxx> //#include <TopExp.hxx>
#include <TopExp_Explorer.hxx> //#include <TopExp_Explorer.hxx>
#include <TopoDS_Vertex.hxx> //#include <TopoDS_Vertex.hxx>
#include <TopoDS.hxx> //#include <TopoDS.hxx>
#include <TColStd_IndexedMapOfInteger.hxx> #include <TColStd_IndexedMapOfInteger.hxx>
#include <BRepBuilderAPI_Transform.hxx> //#include <BRepBuilderAPI_Transform.hxx>
#include <BRepBuilderAPI_MakeWire.hxx> //#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepBuilderAPI_MakePolygon.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
class Locker class Locker
{ {
@ -596,13 +599,48 @@ void EntityGUI_3DSketcherDlg::displayPreview( GEOM::GEOM_Object_ptr object,
// Function : createShapes // Function : createShapes
// Purpose : Create applyed wire, and last segment from entry object // 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& theApplyedWire,
TopoDS_Shape& theLastSegment ) 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; TopoDS_Shape aShape;
if ( !GEOMBase::GetShape( theObject, aShape ) || if ( !GEOMBase::GetShape( theObject, aShape ) )
aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX ) return false;
if( aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX )
return false; return false;
theApplyedWire = aShape; theApplyedWire = aShape;
@ -629,6 +667,7 @@ bool EntityGUI_3DSketcherDlg::createShapes( GEOM::GEOM_Object_ptr theObject,
TopExp_Explorer vertexExp( theLastSegment, TopAbs_VERTEX ); TopExp_Explorer vertexExp( theLastSegment, TopAbs_VERTEX );
theApplyedWire = vertexExp.Current(); theApplyedWire = vertexExp.Current();
} }
*/
return true; return true;
} }

View File

@ -69,24 +69,31 @@ Standard_Integer GEOMImpl_3DSketcherDriver::Execute(TFunction_Logbook& log) cons
TopoDS_Shape aShape; TopoDS_Shape aShape;
Handle(TColStd_HArray1OfReal) aCoordsArray = aCI.GetCoordinates(); Handle(TColStd_HArray1OfReal) aCoordsArray = aCI.GetCoordinates();
BRepBuilderAPI_MakePolygon aMakePoly;
int anArrayLength = aCoordsArray->Length(); int anArrayLength = aCoordsArray->Length();
double x, y, z;
gp_Pnt aPnt; std::list<gp_Pnt> points;
for (int i = 0; i <=(anArrayLength - 3); i+=3) {
x = aCoordsArray->Value(i+1); for (int i = 0; i <= (anArrayLength-3); i += 3) {
y = aCoordsArray->Value(i+2); gp_Pnt aPnt = gp_Pnt(aCoordsArray->Value(i+1), aCoordsArray->Value(i+2), aCoordsArray->Value(i+3));
z = aCoordsArray->Value(i+3); if (points.empty() || aPnt.Distance(points.back()) > gp::Resolution())
aPnt = gp_Pnt(x, y, z); points.push_back(aPnt);
aMakePoly.Add(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(); aShape = mkVertex.Shape();
} }
else { // Make Wire else if ( points.size() > 1) { // Make Wire
if (aCoordsArray->Value(1) == x && aCoordsArray->Value(2) == y && aCoordsArray->Value(3) == z) 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(); aMakePoly.Close();
if (aMakePoly.IsDone()) if (aMakePoly.IsDone())