int OCCFace::createPolygonal(std::vector<OCCStruct3d> points) { try { BRepBuilderAPI_MakePolygon MP; for (unsigned i=0; i<points.size(); i++) { MP.Add(gp_Pnt(points[i].x, points[i].y, points[i].z)); } MP.Close(); if (!MP.IsDone()) { StdFail_NotDone::Raise("failed to create face");; } BRepBuilderAPI_MakeFace MF(MP.Wire(), false); this->setShape(MF.Face()); // possible fix shape if (!this->fixShape()) StdFail_NotDone::Raise("Shapes not valid"); } catch(Standard_Failure &err) { Handle_Standard_Failure e = Standard_Failure::Caught(); const Standard_CString msg = e->GetMessageString(); if (msg != NULL && strlen(msg) > 1) { setErrorMessage(msg); } else { setErrorMessage("Failed to create face"); } return 0; } return 1; }
App::DocumentObjectExecReturn *Part::Polygon::execute(void) { BRepBuilderAPI_MakePolygon poly; const std::vector<Base::Vector3d> nodes = Nodes.getValues(); for (std::vector<Base::Vector3d>::const_iterator it = nodes.begin(); it != nodes.end(); ++it) { gp_Pnt pnt(it->x, it->y, it->z); poly.Add(pnt); } if (Close.getValue()) poly.Close(); if (!poly.IsDone()) throw Base::CADKernelError("Cannot create polygon because less than two vertices are given"); TopoDS_Wire wire = poly.Wire(); this->Shape.setValue(wire); return App::DocumentObject::StdReturn; }
bool IfcGeom::Kernel::convert(const IfcSchema::IfcPolyLoop* l, TopoDS_Wire& result) { IfcSchema::IfcCartesianPoint::list::ptr points = l->Polygon(); // Parse and store the points in a sequence TColgp_SequenceOfPnt polygon; for(IfcSchema::IfcCartesianPoint::list::it it = points->begin(); it != points->end(); ++ it) { gp_Pnt pnt; IfcGeom::Kernel::convert(*it, pnt); polygon.Append(pnt); } // A loop should consist of at least three vertices int original_count = polygon.Length(); if (original_count < 3) { Logger::Message(Logger::LOG_ERROR, "Not enough edges for:", l->entity); return false; } // Remove points that are too close to one another remove_redundant_points_from_loop(polygon, true); int count = polygon.Length(); if (original_count - count != 0) { std::stringstream ss; ss << (original_count - count) << " edges removed for:"; Logger::Message(Logger::LOG_WARNING, ss.str(), l->entity); } if (count < 3) { Logger::Message(Logger::LOG_ERROR, "Not enough edges for:", l->entity); return false; } BRepBuilderAPI_MakePolygon w; for (int i = 1; i <= polygon.Length(); ++i) { w.Add(polygon.Value(i)); } w.Close(); result = w.Wire(); return true; }
void occQt::makeLoft() { // bottom wire. TopoDS_Edge aCircleEdge = BRepBuilderAPI_MakeEdge(gp_Circ(gp_Ax2(gp_Pnt(0.0, 80.0, 0.0), gp::DZ()), 1.5)); TopoDS_Wire aCircleWire = BRepBuilderAPI_MakeWire(aCircleEdge); // top wire. BRepBuilderAPI_MakePolygon aPolygon; aPolygon.Add(gp_Pnt(-3.0, 77.0, 6.0)); aPolygon.Add(gp_Pnt(3.0, 77.0, 6.0)); aPolygon.Add(gp_Pnt(3.0, 83.0, 6.0)); aPolygon.Add(gp_Pnt(-3.0, 83.0, 6.0)); aPolygon.Close(); BRepOffsetAPI_ThruSections aShellGenerator; BRepOffsetAPI_ThruSections aSolidGenerator(true); aShellGenerator.AddWire(aCircleWire); aShellGenerator.AddWire(aPolygon.Wire()); aSolidGenerator.AddWire(aCircleWire); aSolidGenerator.AddWire(aPolygon.Wire()); // translate the solid. gp_Trsf aTrsf; aTrsf.SetTranslation(gp_Vec(18.0, 0.0, 0.0)); BRepBuilderAPI_Transform aTransform(aSolidGenerator.Shape(), aTrsf); Handle_AIS_Shape anAisShell = new AIS_Shape(aShellGenerator.Shape()); Handle_AIS_Shape anAisSolid = new AIS_Shape(aTransform.Shape()); anAisShell->SetColor(Quantity_NOC_OLIVEDRAB); anAisSolid->SetColor(Quantity_NOC_PEACHPUFF); mContext->Display(anAisShell); mContext->Display(anAisSolid); }