bool SweepWidget::isPathValid(const Gui::SelectionObject& sel) const { const App::DocumentObject* path = sel.getObject(); if (!(path && path->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))) return false; const std::vector<std::string>& sub = sel.getSubNames(); TopoDS_Shape pathShape; const Part::TopoShape& shape = static_cast<const Part::Feature*>(path)->Shape.getValue(); if (!sub.empty()) { try { BRepBuilderAPI_MakeWire mkWire; for (std::vector<std::string>::const_iterator it = sub.begin(); it != sub.end(); ++it) { TopoDS_Shape subshape = shape.getSubShape(it->c_str()); mkWire.Add(TopoDS::Edge(subshape)); } pathShape = mkWire.Wire(); } catch (...) { return false; } } else if (shape._Shape.ShapeType() == TopAbs_EDGE) { pathShape = shape._Shape; } else if (shape._Shape.ShapeType() == TopAbs_WIRE) { BRepBuilderAPI_MakeWire mkWire(TopoDS::Wire(shape._Shape)); pathShape = mkWire.Wire(); } return (!pathShape.IsNull()); }
bool SweepWidget::isPathValid(const Gui::SelectionObject& sel) const { const App::DocumentObject* path = sel.getObject(); if (!(path && path->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))) return false; const std::vector<std::string>& sub = sel.getSubNames(); TopoDS_Shape pathShape; const Part::TopoShape& shape = static_cast<const Part::Feature*>(path)->Shape.getValue(); if (!sub.empty()) { try { BRepBuilderAPI_MakeWire mkWire; for (std::vector<std::string>::const_iterator it = sub.begin(); it != sub.end(); ++it) { TopoDS_Shape subshape = shape.getSubShape(it->c_str()); mkWire.Add(TopoDS::Edge(subshape)); } pathShape = mkWire.Wire(); } catch (...) { return false; } } else if (shape._Shape.ShapeType() == TopAbs_EDGE) { pathShape = shape._Shape; } else if (shape._Shape.ShapeType() == TopAbs_WIRE) { BRepBuilderAPI_MakeWire mkWire(TopoDS::Wire(shape._Shape)); pathShape = mkWire.Wire(); } else if (shape._Shape.ShapeType() == TopAbs_COMPOUND) { try { TopoDS_Iterator it(shape._Shape); for (; it.More(); it.Next()) { if ((it.Value().ShapeType() != TopAbs_EDGE) && (it.Value().ShapeType() != TopAbs_WIRE)) { return false; } } Handle(TopTools_HSequenceOfShape) hEdges = new TopTools_HSequenceOfShape(); Handle(TopTools_HSequenceOfShape) hWires = new TopTools_HSequenceOfShape(); for (TopExp_Explorer xp(shape._Shape, TopAbs_EDGE); xp.More(); xp.Next()) hEdges->Append(xp.Current()); ShapeAnalysis_FreeBounds::ConnectEdgesToWires(hEdges, Precision::Confusion(), Standard_True, hWires); int len = hWires->Length(); if (len != 1) return false; pathShape = hWires->Value(1); } catch (...) { return false; } } return (!pathShape.IsNull()); }