Standard_EXPORT Handle_Standard_Type& NMTDS_StdMapNodeOfMapOfPassKeyBoolean_Type_() { static Handle_Standard_Type aType1 = STANDARD_TYPE(TCollection_MapNode); static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared); static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient); static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL}; static Handle_Standard_Type _aType = new Standard_Type("NMTDS_StdMapNodeOfMapOfPassKeyBoolean", sizeof(NMTDS_StdMapNodeOfMapOfPassKeyBoolean), 1, (Standard_Address)_Ancestors, (Standard_Address)NULL); return _aType; }
Standard_EXPORT Handle_Standard_Type& GEOMAlgo_IndexedDataMapNodeOfIndexedDataMapOfPassKeyShapeListOfShape_Type_() { static Handle_Standard_Type aType1 = STANDARD_TYPE(TCollection_MapNode); static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared); static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient); static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL}; static Handle_Standard_Type _aType = new Standard_Type("GEOMAlgo_IndexedDataMapNodeOfIndexedDataMapOfPassKeyShapeListOfShape", sizeof(GEOMAlgo_IndexedDataMapNodeOfIndexedDataMapOfPassKeyShapeListOfShape), 1, (Standard_Address)_Ancestors, (Standard_Address)NULL); return _aType; }
Standard_EXPORT Handle_Standard_Type& NMTDS_IndexedDataMapNodeOfIndexedDataMapOfShapeBox_Type_() { static Handle_Standard_Type aType1 = STANDARD_TYPE(TCollection_MapNode); static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared); static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient); static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL}; static Handle_Standard_Type _aType = new Standard_Type("NMTDS_IndexedDataMapNodeOfIndexedDataMapOfShapeBox", sizeof(NMTDS_IndexedDataMapNodeOfIndexedDataMapOfShapeBox), 1, (Standard_Address)_Ancestors, (Standard_Address)NULL); return _aType; }
Standard_EXPORT Handle_Standard_Type& NMTTools_ListNodeOfListOfCoupleOfShape_Type_() { static Handle_Standard_Type aType1 = STANDARD_TYPE(TCollection_MapNode); static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared); static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient); static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL}; static Handle_Standard_Type _aType = new Standard_Type("NMTTools_ListNodeOfListOfCoupleOfShape", sizeof(NMTTools_ListNodeOfListOfCoupleOfShape), 1, (Standard_Address)_Ancestors, (Standard_Address)NULL); return _aType; }
//======================================================================= //function : GetPosition //purpose : //======================================================================= gp_Ax3 GEOMUtils::GetPosition (const TopoDS_Shape& theShape) { gp_Ax3 aResult; if (theShape.IsNull()) return aResult; // Axes aResult.Transform(theShape.Location().Transformation()); if (theShape.ShapeType() == TopAbs_FACE) { Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(theShape)); if (!aGS.IsNull() && aGS->IsKind(STANDARD_TYPE(Geom_Plane))) { Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast(aGS); gp_Pln aPln = aGPlane->Pln(); aResult = aPln.Position(); // In case of reverse orinetation of the face invert the plane normal // (the face's normal does not mathc the plane's normal in this case) if(theShape.Orientation() == TopAbs_REVERSED) { gp_Dir Vx = aResult.XDirection(); gp_Dir N = aResult.Direction().Mirrored(Vx); gp_Pnt P = aResult.Location(); aResult = gp_Ax3(P, N, Vx); } } } // Origin gp_Pnt aPnt; TopAbs_ShapeEnum aShType = theShape.ShapeType(); if (aShType == TopAbs_VERTEX) { aPnt = BRep_Tool::Pnt(TopoDS::Vertex(theShape)); } else { if (aShType == TopAbs_COMPOUND) { aShType = GetTypeOfSimplePart(theShape); } GProp_GProps aSystem; if (aShType == TopAbs_EDGE || aShType == TopAbs_WIRE) BRepGProp::LinearProperties(theShape, aSystem); else if (aShType == TopAbs_FACE || aShType == TopAbs_SHELL) BRepGProp::SurfaceProperties(theShape, aSystem); else BRepGProp::VolumeProperties(theShape, aSystem); aPnt = aSystem.CentreOfMass(); } aResult.SetLocation(aPnt); return aResult; }
const Py::Object makeGeometryCurvePy(const Handle_Geom_Curve& c) { if (c->IsKind(STANDARD_TYPE(Geom_Circle))) { Handle_Geom_Circle circ = Handle_Geom_Circle::DownCast(c); return Py::asObject(new CirclePy(new GeomCircle(circ))); } else if (c->IsKind(STANDARD_TYPE(Geom_Ellipse))) { Handle_Geom_Ellipse ell = Handle_Geom_Ellipse::DownCast(c); return Py::asObject(new EllipsePy(new GeomEllipse(ell))); } else if (c->IsKind(STANDARD_TYPE(Geom_Hyperbola))) { Handle_Geom_Hyperbola hyp = Handle_Geom_Hyperbola::DownCast(c); return Py::asObject(new HyperbolaPy(new GeomHyperbola(hyp))); } else if (c->IsKind(STANDARD_TYPE(Geom_Line))) { Handle_Geom_Line lin = Handle_Geom_Line::DownCast(c); return Py::asObject(new GeometryCurvePy(new GeomLine(lin))); } else if (c->IsKind(STANDARD_TYPE(Geom_OffsetCurve))) { Handle_Geom_OffsetCurve oc = Handle_Geom_OffsetCurve::DownCast(c); return Py::asObject(new OffsetCurvePy(new GeomOffsetCurve(oc))); } else if (c->IsKind(STANDARD_TYPE(Geom_Parabola))) { Handle_Geom_Parabola par = Handle_Geom_Parabola::DownCast(c); return Py::asObject(new ParabolaPy(new GeomParabola(par))); } else if (c->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) { Handle_Geom_TrimmedCurve trc = Handle_Geom_TrimmedCurve::DownCast(c); return Py::asObject(new GeometryCurvePy(new GeomTrimmedCurve(trc))); } /*else if (c->IsKind(STANDARD_TYPE(Geom_BoundedCurve))) { Handle_Geom_BoundedCurve bc = Handle_Geom_BoundedCurve::DownCast(c); return Py::asObject(new GeometryCurvePy(new GeomBoundedCurve(bc))); }*/ else if (c->IsKind(STANDARD_TYPE(Geom_BezierCurve))) { Handle_Geom_BezierCurve bezier = Handle_Geom_BezierCurve::DownCast(c); return Py::asObject(new BezierCurvePy(new GeomBezierCurve(bezier))); } else if (c->IsKind(STANDARD_TYPE(Geom_BSplineCurve))) { Handle_Geom_BSplineCurve bspline = Handle_Geom_BSplineCurve::DownCast(c); return Py::asObject(new BSplineCurvePy(new GeomBSplineCurve(bspline))); } std::string err = "Unhandled curve type "; err += c->DynamicType()->Name(); throw Py::TypeError(err); }
void Surface::information() const { display_message(INFORMATION_MESSAGE, " %s", geomTypeString().c_str()); if (m_surface->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) { Handle_Geom_CylindricalSurface cylinder = Handle_Geom_CylindricalSurface::DownCast(m_surface); display_message(INFORMATION_MESSAGE, " with radius = %.3g", cylinder->Radius()); } else if (m_surface->DynamicType() == STANDARD_TYPE(Geom_Plane)) { Handle_Geom_Plane plane = Handle_Geom_Plane::DownCast(m_surface); Standard_Real a, b, c, d; plane->Coefficients(a, b, c, d); display_message(INFORMATION_MESSAGE, " with equation: %.3g x + %.3g y + %.3g z + %.3g = 0", a, b, c, d); } else if (m_surface->DynamicType() == STANDARD_TYPE(Geom_SphericalSurface)) { Handle_Geom_SphericalSurface sphere = Handle_Geom_SphericalSurface::DownCast(m_surface); display_message(INFORMATION_MESSAGE, " with area: %.3g", sphere->Area()); } display_message(INFORMATION_MESSAGE, "\n"); }
int convert_to_ifc(const TopoDS_Wire& wire, IfcSchema::IfcLoop*& loop, bool advanced) { bool polygonal = true; for (TopExp_Explorer exp(wire, TopAbs_EDGE); exp.More(); exp.Next()) { double a, b; Handle_Geom_Curve crv = BRep_Tool::Curve(TopoDS::Edge(exp.Current()), a, b); if (crv.IsNull()) { continue; } if (crv->DynamicType() != STANDARD_TYPE(Geom_Line)) { polygonal = false; break; } } if (!polygonal && !advanced) { return 0; } else if (polygonal && !advanced) { IfcSchema::IfcCartesianPoint::list::ptr points(new IfcSchema::IfcCartesianPoint::list); BRepTools_WireExplorer exp(wire); IfcSchema::IfcCartesianPoint* p; for (; exp.More(); exp.Next()) { if (convert_to_ifc(exp.CurrentVertex(), p, advanced)) { points->push(p); } else { return 0; } } loop = new IfcSchema::IfcPolyLoop(points); return 1; } else { IfcSchema::IfcOrientedEdge::list::ptr edges(new IfcSchema::IfcOrientedEdge::list); BRepTools_WireExplorer exp(wire); for (; exp.More(); exp.Next()) { IfcSchema::IfcEdge* edge; // With advanced set to true convert_to_ifc(TopoDS_Edge&) will always create an IfcOrientedEdge if (!convert_to_ifc(exp.Current(), edge, true)) { double a, b; if (BRep_Tool::Curve(TopoDS::Edge(exp.Current()), a, b).IsNull()) { continue; } else { return 0; } } edges->push(edge->as<IfcSchema::IfcOrientedEdge>()); } loop = new IfcSchema::IfcEdgeLoop(edges); return 1; } }
int convert_to_ifc(const TopoDS_Face& f, IfcSchema::IfcFace*& face, bool advanced) { Handle_Geom_Surface surf = BRep_Tool::Surface(f); TopExp_Explorer exp(f, TopAbs_WIRE); IfcSchema::IfcFaceBound::list::ptr bounds(new IfcSchema::IfcFaceBound::list); int index = 0; for (; exp.More(); exp.Next(), ++index) { IfcSchema::IfcLoop* loop; if (!convert_to_ifc(TopoDS::Wire(exp.Current()), loop, advanced)) { return 0; } IfcSchema::IfcFaceBound* bnd; if (index == 0) { bnd = new IfcSchema::IfcFaceOuterBound(loop, true); } else { bnd = new IfcSchema::IfcFaceBound(loop, true); } bounds->push(bnd); } const bool is_planar = surf->DynamicType() == STANDARD_TYPE(Geom_Plane); if (!is_planar && !advanced) { return 0; } if (is_planar && !advanced) { face = new IfcSchema::IfcFace(bounds); return 1; } else { #ifdef USE_IFC4 IfcSchema::IfcSurface* surface; if (!convert_to_ifc(surf, surface, advanced)) { return 0; } face = new IfcSchema::IfcAdvancedFace(bounds, surface, f.Orientation() == TopAbs_FORWARD); return 1; #else // No IfcAdvancedFace in Ifc2x3 return 0; #endif } }
//================================================================ // Function : DrawCurve // Purpose : displays a given curve 2d //================================================================ Handle_AIS_InteractiveObject OCCDemo_Presentation::drawCurve (const Handle_Geom2d_Curve& theCurve, const Quantity_Color& theColor, const Standard_Boolean toDisplay, const gp_Ax2& aPosition) { // create 3D curve in plane Handle(Geom_Curve) aCurve3d; if (theCurve->IsKind(STANDARD_TYPE(Geom2d_OffsetCurve))) { Handle(Geom2d_OffsetCurve) aOffCurve = Handle(Geom2d_OffsetCurve)::DownCast(theCurve); Handle(Geom_Curve) aBasCurve3d = GeomAPI::To3d (aOffCurve->BasisCurve(), gp_Pln(aPosition)); Standard_Real aDist = aOffCurve->Offset(); aCurve3d = new Geom_OffsetCurve (aBasCurve3d, aDist, aPosition.Direction()); } else { aCurve3d = GeomAPI::To3d (theCurve, gp_Pln(aPosition)); } return drawCurve (aCurve3d, theColor, toDisplay); }
int convert_to_ifc(const TopoDS_Edge& e, IfcSchema::IfcEdge*& edge, bool advanced) { double a, b; TopExp_Explorer exp(e, TopAbs_VERTEX); if (!exp.More()) return 0; TopoDS_Vertex v1 = TopoDS::Vertex(exp.Current()); exp.Next(); if (!exp.More()) return 0; TopoDS_Vertex v2 = TopoDS::Vertex(exp.Current()); IfcSchema::IfcVertex *vertex1, *vertex2; if (!(convert_to_ifc(v1, vertex1, advanced) && convert_to_ifc(v2, vertex2, advanced))) { return 0; } Handle_Geom_Curve crv = BRep_Tool::Curve(e, a, b); if (crv.IsNull()) { return 0; } if (crv->DynamicType() == STANDARD_TYPE(Geom_Line) && !advanced) { IfcSchema::IfcEdge* edge2 = new IfcSchema::IfcEdge(vertex1, vertex2); edge = new IfcSchema::IfcOrientedEdge(edge2, true); return 1; } else { IfcSchema::IfcCurve* curve; if (!convert_to_ifc(crv, curve, advanced)) { return 0; } /// @todo probably not correct const bool sense = e.Orientation() == TopAbs_FORWARD; IfcSchema::IfcEdge* edge2 = new IfcSchema::IfcEdgeCurve(vertex1, vertex2, curve, true); edge = new IfcSchema::IfcOrientedEdge(edge2, sense); return 1; } }
//======================================================================= //function : GEOMImpl_RotateDriver_Type_ //purpose : //======================================================================= Standard_EXPORT Handle_Standard_Type& GEOMImpl_RotateDriver_Type_() { static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver); if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver); static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared); if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient); if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient); static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL}; static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_RotateDriver", sizeof(GEOMImpl_RotateDriver), 1, (Standard_Address)_Ancestors, (Standard_Address)NULL); return _aType; }
Standard_EXPORT Handle_Standard_Type& GEOM_DataMapNodeOfDataMapOfAsciiStringTransient_Type_() { static Handle_Standard_Type aType1 = STANDARD_TYPE(TCollection_MapNode); if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TCollection_MapNode); static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared); if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient); if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient); static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL}; static Handle_Standard_Type _aType = new Standard_Type("GEOM_DataMapNodeOfDataMapOfAsciiStringTransient", sizeof(GEOM_DataMapNodeOfDataMapOfAsciiStringTransient), 1, (Standard_Address)_Ancestors, (Standard_Address)NULL); return _aType; }
TopoDS_Shape MakeBottle(const Standard_Real myWidth, const Standard_Real myHeight, const Standard_Real myThickness) { // Profile : Define Support Points gp_Pnt aPnt1(-myWidth / 2., 0, 0); gp_Pnt aPnt2(-myWidth / 2., -myThickness / 4., 0); gp_Pnt aPnt3(0, -myThickness / 2., 0); gp_Pnt aPnt4(myWidth / 2., -myThickness / 4., 0); gp_Pnt aPnt5(myWidth / 2., 0, 0); // Profile : Define the Geometry Handle(Geom_TrimmedCurve) anArcOfCircle = GC_MakeArcOfCircle(aPnt2,aPnt3,aPnt4); Handle(Geom_TrimmedCurve) aSegment1 = GC_MakeSegment(aPnt1, aPnt2); Handle(Geom_TrimmedCurve) aSegment2 = GC_MakeSegment(aPnt4, aPnt5); // Profile : Define the Topology TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge(aSegment1); TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge(anArcOfCircle); TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge(aSegment2); TopoDS_Wire aWire = BRepBuilderAPI_MakeWire(anEdge1, anEdge2, anEdge3); // Complete Profile gp_Ax1 xAxis = gp::OX(); gp_Trsf aTrsf; aTrsf.SetMirror(xAxis); BRepBuilderAPI_Transform aBRepTrsf(aWire, aTrsf); TopoDS_Shape aMirroredShape = aBRepTrsf.Shape(); TopoDS_Wire aMirroredWire = TopoDS::Wire(aMirroredShape); BRepBuilderAPI_MakeWire mkWire; mkWire.Add(aWire); mkWire.Add(aMirroredWire); TopoDS_Wire myWireProfile = mkWire.Wire(); // Body : Prism the Profile TopoDS_Face myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile); gp_Vec aPrismVec(0, 0, myHeight); TopoDS_Shape myBody = BRepPrimAPI_MakePrism(myFaceProfile, aPrismVec); // Body : Apply Fillets BRepFilletAPI_MakeFillet mkFillet(myBody); TopExp_Explorer anEdgeExplorer(myBody, TopAbs_EDGE); while(anEdgeExplorer.More()) { TopoDS_Edge anEdge = TopoDS::Edge(anEdgeExplorer.Current()); //Add edge to fillet algorithm mkFillet.Add(myThickness / 12., anEdge); anEdgeExplorer.Next(); } myBody = mkFillet.Shape(); // Body : Add the Neck gp_Pnt neckLocation(0, 0, myHeight); gp_Dir neckAxis = gp::DZ(); gp_Ax2 neckAx2(neckLocation, neckAxis); Standard_Real myNeckRadius = myThickness / 4.; Standard_Real myNeckHeight = myHeight / 10.; BRepPrimAPI_MakeCylinder MKCylinder(neckAx2, myNeckRadius, myNeckHeight); TopoDS_Shape myNeck = MKCylinder.Shape(); myBody = BRepAlgoAPI_Fuse(myBody, myNeck); // Body : Create a Hollowed Solid TopoDS_Face faceToRemove; Standard_Real zMax = -1; for(TopExp_Explorer aFaceExplorer(myBody, TopAbs_FACE); aFaceExplorer.More(); aFaceExplorer.Next()) { TopoDS_Face aFace = TopoDS::Face(aFaceExplorer.Current()); // Check if <aFace> is the top face of the bottle�s neck Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aFace); if(aSurface->DynamicType() == STANDARD_TYPE(Geom_Plane)) { Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(aSurface); gp_Pnt aPnt = aPlane->Location(); Standard_Real aZ = aPnt.Z(); if(aZ > zMax) { zMax = aZ; faceToRemove = aFace; } } } TopTools_ListOfShape facesToRemove; facesToRemove.Append(faceToRemove); myBody = BRepOffsetAPI_MakeThickSolid(myBody, facesToRemove, -myThickness / 50, 1.e-3); // Threading : Create Surfaces Handle(Geom_CylindricalSurface) aCyl1 = new Geom_CylindricalSurface(neckAx2, myNeckRadius * 0.99); Handle(Geom_CylindricalSurface) aCyl2 = new Geom_CylindricalSurface(neckAx2, myNeckRadius * 1.05); // Threading : Define 2D Curves gp_Pnt2d aPnt(2. * M_PI, myNeckHeight / 2.); gp_Dir2d aDir(2. * M_PI, myNeckHeight / 4.); gp_Ax2d anAx2d(aPnt, aDir); Standard_Real aMajor = 2. * M_PI; Standard_Real aMinor = myNeckHeight / 10; Handle(Geom2d_Ellipse) anEllipse1 = new Geom2d_Ellipse(anAx2d, aMajor, aMinor); Handle(Geom2d_Ellipse) anEllipse2 = new Geom2d_Ellipse(anAx2d, aMajor, aMinor / 4); Handle(Geom2d_TrimmedCurve) anArc1 = new Geom2d_TrimmedCurve(anEllipse1, 0, M_PI); Handle(Geom2d_TrimmedCurve) anArc2 = new Geom2d_TrimmedCurve(anEllipse2, 0, M_PI); gp_Pnt2d anEllipsePnt1 = anEllipse1->Value(0); gp_Pnt2d anEllipsePnt2 = anEllipse1->Value(M_PI); Handle(Geom2d_TrimmedCurve) aSegment = GCE2d_MakeSegment(anEllipsePnt1, anEllipsePnt2); // Threading : Build Edges and Wires TopoDS_Edge anEdge1OnSurf1 = BRepBuilderAPI_MakeEdge(anArc1, aCyl1); TopoDS_Edge anEdge2OnSurf1 = BRepBuilderAPI_MakeEdge(aSegment, aCyl1); TopoDS_Edge anEdge1OnSurf2 = BRepBuilderAPI_MakeEdge(anArc2, aCyl2); TopoDS_Edge anEdge2OnSurf2 = BRepBuilderAPI_MakeEdge(aSegment, aCyl2); TopoDS_Wire threadingWire1 = BRepBuilderAPI_MakeWire(anEdge1OnSurf1, anEdge2OnSurf1); TopoDS_Wire threadingWire2 = BRepBuilderAPI_MakeWire(anEdge1OnSurf2, anEdge2OnSurf2); BRepLib::BuildCurves3d(threadingWire1); BRepLib::BuildCurves3d(threadingWire2); // Create Threading BRepOffsetAPI_ThruSections aTool(Standard_True); aTool.AddWire(threadingWire1); aTool.AddWire(threadingWire2); aTool.CheckCompatibility(Standard_False); TopoDS_Shape myThreading = aTool.Shape(); // Building the Resulting Compound TopoDS_Compound aRes; BRep_Builder aBuilder; aBuilder.MakeCompound (aRes); aBuilder.Add (aRes, myBody); aBuilder.Add (aRes, myThreading); return aRes; }
int convert_to_ifc(const Handle_Geom_Curve& c, IfcSchema::IfcCurve*& curve, bool advanced) { if (c->DynamicType() == STANDARD_TYPE(Geom_Line)) { IfcSchema::IfcDirection* d; IfcSchema::IfcCartesianPoint* p; Handle_Geom_Line line = Handle_Geom_Line::DownCast(c); if (!convert_to_ifc(line->Position().Location(), p, advanced)) { return 0; } if (!convert_to_ifc(line->Position().Direction(), d, advanced)) { return 0; } IfcSchema::IfcVector* v = new IfcSchema::IfcVector(d, 1.); curve = new IfcSchema::IfcLine(p, v); return 1; } else if (c->DynamicType() == STANDARD_TYPE(Geom_Circle)) { IfcSchema::IfcAxis2Placement3D* ax; Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(c); convert_to_ifc(circle->Position(), ax, advanced); curve = new IfcSchema::IfcCircle(ax, circle->Radius()); return 1; } else if (c->DynamicType() == STANDARD_TYPE(Geom_Ellipse)) { IfcSchema::IfcAxis2Placement3D* ax; Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(c); convert_to_ifc(ellipse->Position(), ax, advanced); curve = new IfcSchema::IfcEllipse(ax, ellipse->MajorRadius(), ellipse->MinorRadius()); return 1; } #ifdef USE_IFC4 else if (c->DynamicType() == STANDARD_TYPE(Geom_BSplineCurve)) { Handle_Geom_BSplineCurve bspline = Handle_Geom_BSplineCurve::DownCast(c); IfcSchema::IfcCartesianPoint::list::ptr points(new IfcSchema::IfcCartesianPoint::list); TColgp_Array1OfPnt poles(1, bspline->NbPoles()); bspline->Poles(poles); for (int i = 1; i <= bspline->NbPoles(); ++i) { IfcSchema::IfcCartesianPoint* p; if (!convert_to_ifc(poles.Value(i), p, advanced)) { return 0; } points->push(p); } IfcSchema::IfcKnotType::IfcKnotType knot_spec = opencascade_knotspec_to_ifc(bspline->KnotDistribution()); std::vector<int> mults; std::vector<double> knots; std::vector<double> weights; TColStd_Array1OfInteger bspline_mults(1, bspline->NbKnots()); TColStd_Array1OfReal bspline_knots(1, bspline->NbKnots()); TColStd_Array1OfReal bspline_weights(1, bspline->NbPoles()); bspline->Multiplicities(bspline_mults); bspline->Knots(bspline_knots); bspline->Weights(bspline_weights); opencascade_array_to_vector(bspline_mults, mults); opencascade_array_to_vector(bspline_knots, knots); opencascade_array_to_vector(bspline_weights, weights); bool rational = false; for (std::vector<double>::const_iterator it = weights.begin(); it != weights.end(); ++it) { if ((*it) != 1.) { rational = true; break; } } if (rational) { curve = new IfcSchema::IfcRationalBSplineCurveWithKnots( bspline->Degree(), points, IfcSchema::IfcBSplineCurveForm::IfcBSplineCurveForm_UNSPECIFIED, bspline->IsClosed(), false, mults, knots, knot_spec, weights ); } else { curve = new IfcSchema::IfcBSplineCurveWithKnots( bspline->Degree(), points, IfcSchema::IfcBSplineCurveForm::IfcBSplineCurveForm_UNSPECIFIED, bspline->IsClosed(), false, mults, knots, knot_spec ); } return 1; } #endif return 0; }
GEntity::GeomType OCCEdge::geomType() const { if(curve.IsNull()){ if (curve2d->DynamicType() == STANDARD_TYPE(Geom_Circle)) return Circle; else if (curve2d->DynamicType() == STANDARD_TYPE(Geom_Line)) return Line; else if (curve2d->DynamicType() == STANDARD_TYPE(Geom_Ellipse)) return Ellipse; else if (curve2d->DynamicType() == STANDARD_TYPE(Geom_Parabola)) return Parabola; else if (curve2d->DynamicType() == STANDARD_TYPE(Geom_Hyperbola)) return Hyperbola; else if (curve2d->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) return TrimmedCurve; else if (curve2d->DynamicType() == STANDARD_TYPE(Geom_OffsetCurve)) return OffsetCurve; else if (curve2d->DynamicType() == STANDARD_TYPE(Geom_BSplineCurve)) return BSpline; else if (curve2d->DynamicType() == STANDARD_TYPE(Geom_BezierCurve)) return Bezier; else if (curve2d->DynamicType() == STANDARD_TYPE(Geom_Conic)) return Conic; return Unknown; } else{ if (curve->DynamicType() == STANDARD_TYPE(Geom_Circle)) return Circle; else if (curve->DynamicType() == STANDARD_TYPE(Geom_Line)) return Line; else if (curve->DynamicType() == STANDARD_TYPE(Geom_Parabola)) return Parabola; else if (curve->DynamicType() == STANDARD_TYPE(Geom_Hyperbola)) return Hyperbola; else if (curve->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) return TrimmedCurve; else if (curve->DynamicType() == STANDARD_TYPE(Geom_OffsetCurve)) return OffsetCurve; else if (curve->DynamicType() == STANDARD_TYPE(Geom_Ellipse)) return Ellipse; else if (curve->DynamicType() == STANDARD_TYPE(Geom_BSplineCurve)) return BSpline; else if (curve->DynamicType() == STANDARD_TYPE(Geom_BezierCurve)) return Bezier; else if (curve2d->DynamicType() == STANDARD_TYPE(Geom_Conic)) return Conic; return Unknown; } }
Entity::GeomType Surface::geomType() const { if (m_surface->DynamicType() == STANDARD_TYPE(Geom_BezierSurface)) { return BezierSurface; } else if (m_surface->DynamicType() == STANDARD_TYPE(Geom_BoundedSurface)) { return BoundaryLayerSurface; } else if (m_surface->DynamicType() == STANDARD_TYPE(Geom_BSplineSurface)) { return BSplineSurface; } else if (m_surface->DynamicType() == STANDARD_TYPE(Geom_ConicalSurface)) { return ConicalSurface; } else if (m_surface->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) { return Cylinder; } else if (m_surface->DynamicType() == STANDARD_TYPE(Geom_ElementarySurface)) { return ElementarySurface; } else if (m_surface->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface)) { return OffsetSurface; } else if (m_surface->DynamicType() == STANDARD_TYPE(Geom_Plane)) { return Plane; } else if (m_surface->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) { return RectangularTrimmedSurface; } else if (m_surface->DynamicType() == STANDARD_TYPE(Geom_SphericalSurface)) { return Sphere; } else if (m_surface->DynamicType() == STANDARD_TYPE(Geom_Surface)) { return GeomSurface; } else if (m_surface->DynamicType() == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion)) { return LinearExtrusionSurface; } else if (m_surface->DynamicType() == STANDARD_TYPE(Geom_SurfaceOfRevolution)) { return SurfaceOfRevolution; } else if (m_surface->DynamicType() == STANDARD_TYPE(Geom_SweptSurface)) { return SweptSurface; } else if (m_surface->DynamicType() == STANDARD_TYPE(Geom_ToroidalSurface)) { return Torus; } return Unknown; }
void SvgSerializer::write(path_object& p, const TopoDS_Wire& wire) { /* ShapeFix_Wire fix; Handle(ShapeExtend_WireData) data = new ShapeExtend_WireData; for (TopExp_Explorer edges(result, TopAbs_EDGE); edges.More(); edges.Next()) { data->Add(edges.Current()); } fix.Load(data); fix.FixReorder(); fix.FixConnected(); const TopoDS_Wire fixed_wire = fix.Wire(); */ bool first = true; util::string_buffer path; path.add(" <path style=\"stroke:black; fill:none;\" d=\""); for (TopExp_Explorer edges(wire, TopAbs_EDGE); edges.More(); edges.Next()) { const TopoDS_Edge& edge = TopoDS::Edge(edges.Current()); double u1, u2; Handle(Geom_Curve) curve = BRep_Tool::Curve(edge, u1, u2); const bool reversed = edge.Orientation() == TopAbs_REVERSED; gp_Pnt p1, p2; curve->D0(u1, p1); curve->D0(u2, p2); if (reversed) { std::swap(p1, p2); } if (first) { path.add("M"); addXCoordinate(path.add(p1.X())); path.add(","); addYCoordinate(path.add(p1.Y())); growBoundingBox(p1.X(), p1.Y()); } growBoundingBox(p2.X(), p2.Y()); Handle(Standard_Type) ty = curve->DynamicType(); if (ty == STANDARD_TYPE(Geom_Circle) || ty == STANDARD_TYPE(Geom_Ellipse)) { Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(curve); const bool mirrored = conic->Position().Axis().Direction().Z() < 0; double r1, r2; bool larger_arc_segment = (fmod(u2 - u1 + PI2, PI2) > M_PI); bool positive_direction = (u2 > u1); if (mirrored != reversed) { // In case the local coordinate system is mirrored // the direction is reversed. positive_direction = !positive_direction; } if (ty == STANDARD_TYPE(Geom_Circle)) { Handle(Geom_Circle) circle = Handle(Geom_Circle)::DownCast(curve); r1 = r2 = circle->Radius(); } else { Handle(Geom_Ellipse) ellipse = Handle(Geom_Ellipse)::DownCast(curve); r1 = ellipse->MajorRadius(); r2 = ellipse->MinorRadius(); } // Calculate the angle between 2d vecs to have signed result const gp_Dir& d = conic->Position().XDirection(); const gp_Dir2d d2(d.X(), d.Y()); const double ang = d2.Angle(gp::DX2d()); // Write radii path.add(" A"); addSizeComponent(path.add(r1)); path.add(","); addSizeComponent(path.add(r2)); // Write X-axis rotation { std::stringstream ss; ss << " " << ang << " "; path.add(ss.str()); } // Write large-arc-flag and sweep-flag path.add(std::string(1, '0'+static_cast<int>(larger_arc_segment))); path.add(","); path.add(std::string(1, '0'+static_cast<int>(positive_direction))); path.add(" "); // Write arc end point xcoords.push_back(path.add(p2.X())); path.add(","); ycoords.push_back(path.add(p2.Y())); } else { // Either a Geom_Line or something unimplemented, // drawn as a straight line segment. path.add(" L"); xcoords.push_back(path.add(p2.X())); path.add(","); ycoords.push_back(path.add(p2.Y())); } first = false; } path.add("\"/>\n"); p.second.push_back(path); }
STEPIMPORT_EXPORT TopoDS_Shape ImportSTEP (const TCollection_AsciiString& theFileName, const TCollection_AsciiString& /*theFormatName*/, TCollection_AsciiString& theError, const TDF_Label& theShapeLabel) { MESSAGE("Import STEP model from file " << theFileName.ToCString()); // Set "C" numeric locale to save numbers correctly //Kernel_Utils::Localizer loc; TopoDS_Shape aResShape; //VRV: OCC 4.0 migration STEPControl_Reader aReader; //VSR: 16/09/09: Convert to METERS Interface_Static::SetCVal("xstep.cascade.unit","M"); Interface_Static::SetIVal("read.step.ideas", 1); Interface_Static::SetIVal("read.step.nonmanifold", 1); //VRV: OCC 4.0 migration TopoDS_Compound compound; BRep_Builder B; B.MakeCompound(compound); try { #if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString()); if (status == IFSelect_RetDone) { Standard_Boolean failsonly = Standard_False; aReader.PrintCheckLoad(failsonly, IFSelect_ItemsByEntity); /* Root transfers */ Standard_Integer nbr = aReader.NbRootsForTransfer(); aReader.PrintCheckTransfer(failsonly, IFSelect_ItemsByEntity); for (Standard_Integer n = 1; n <= nbr; n++) { Standard_Boolean ok = aReader.TransferRoot(n); /* Collecting resulting entities */ Standard_Integer nbs = aReader.NbShapes(); if (!ok || nbs == 0) { // THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::ImportStep", SALOME::BAD_PARAM); continue; // skip empty root } /* For a single entity */ else if (nbr == 1 && nbs == 1) { aResShape = aReader.Shape(1); // ATTENTION: this is a workaround for mantis issue 0020442 remark 0010776 // It should be removed after patching OCCT for bug OCC22436 // (fix for OCCT is expected in service pack next to OCCT6.3sp12) if (aResShape.ShapeType() == TopAbs_COMPOUND) { int nbSub1 = 0; TopoDS_Shape currShape; TopoDS_Iterator It (aResShape, Standard_True, Standard_True); for (; It.More(); It.Next()) { nbSub1++; currShape = It.Value(); } if (nbSub1 == 1) aResShape = currShape; } // END workaround break; } for (Standard_Integer i = 1; i <= nbs; i++) { TopoDS_Shape aShape = aReader.Shape(i); if (aShape.IsNull()) { // THROW_SALOME_CORBA_EXCEPTION("Null shape in GEOM_Gen_i::ImportStep", SALOME::BAD_PARAM) ; //return aResShape; continue; } else { B.Add(compound, aShape); } } } if (aResShape.IsNull()) aResShape = compound; // BEGIN: Store names of sub-shapes from file TopTools_IndexedMapOfShape anIndices; TopExp::MapShapes(aResShape, anIndices); Handle(Interface_InterfaceModel) Model = aReader.WS()->Model(); Handle(XSControl_TransferReader) TR = aReader.WS()->TransferReader(); if (!TR.IsNull()) { Handle(Transfer_TransientProcess) TP = TR->TransientProcess(); Handle(Standard_Type) tPD = STANDARD_TYPE(StepBasic_ProductDefinition); Handle(Standard_Type) tShape = STANDARD_TYPE(StepShape_TopologicalRepresentationItem); Handle(Standard_Type) tGeom = STANDARD_TYPE(StepGeom_GeometricRepresentationItem); Standard_Integer nb = Model->NbEntities(); for (Standard_Integer ie = 1; ie <= nb; ie++) { Handle(Standard_Transient) enti = Model->Value(ie); Handle(TCollection_HAsciiString) aName; if ( enti->IsKind( tShape ) || enti->IsKind(tGeom)) { aName = Handle(StepRepr_RepresentationItem)::DownCast(enti)->Name(); } else if (enti->DynamicType() == tPD) { Handle(StepBasic_ProductDefinition) PD = Handle(StepBasic_ProductDefinition)::DownCast(enti); if (PD.IsNull()) continue; Handle(StepBasic_Product) Prod = PD->Formation()->OfProduct(); aName = Prod->Name(); } else { continue; } if ( aName->UsefullLength() < 1 ) continue; // skip 'N0NE' name if ( aName->UsefullLength() == 4 && toupper (aName->Value(1)) == 'N' && toupper (aName->Value(2)) == 'O' && toupper (aName->Value(3)) == 'N' && toupper (aName->Value(4)) == 'E') continue; // special check to pass names like "Open CASCADE STEP translator 6.3 1" TCollection_AsciiString aSkipName ("Open CASCADE STEP translator"); if (aName->Length() >= aSkipName.Length()) { if (aName->String().SubString(1, aSkipName.Length()).IsEqual(aSkipName)) continue; } TCollection_ExtendedString aNameExt (aName->ToCString()); // find target shape Handle(Transfer_Binder) binder = TP->Find(enti); if (binder.IsNull()) continue; TopoDS_Shape S = TransferBRep::ShapeResult(binder); if (S.IsNull()) continue; // as PRODUCT can be included in the main shape // several times, we look here for all iclusions. Standard_Integer isub, nbSubs = anIndices.Extent(); for (isub = 1; isub <= nbSubs; isub++) { TopoDS_Shape aSub = anIndices.FindKey(isub); if (aSub.IsPartner(S)) { TDF_Label L; if (enti->IsKind(tGeom)) { // check all named shapes using iterator TDF_ChildIDIterator anIt (theShapeLabel, TDataStd_Name::GetID(), Standard_True); for (; anIt.More(); anIt.Next()) { Handle(TDataStd_Name) nameAttr = Handle(TDataStd_Name)::DownCast(anIt.Value()); if (nameAttr.IsNull()) continue; TDF_Label Lab = nameAttr->Label(); Handle(TNaming_NamedShape) shAttr; if (Lab.FindAttribute(TNaming_NamedShape::GetID(), shAttr) && shAttr->Get().IsEqual(aSub)) L = Lab; } } // create label and set shape if (L.IsNull()) { TDF_TagSource aTag; L = aTag.NewChild(theShapeLabel); TNaming_Builder tnBuild (L); //tnBuild.Generated(S); tnBuild.Generated(aSub); } // set a name TDataStd_Name::Set(L, aNameExt); } } } } // END: Store names } else { // switch (status) { // case IFSelect_RetVoid: // theError = "Nothing created or No data to process"; // break; // case IFSelect_RetError: // theError = "Error in command or input data"; // break; // case IFSelect_RetFail: // theError = "Execution was run, but has failed"; // break; // case IFSelect_RetStop: // theError = "Execution has been stopped. Quite possible, an exception was raised"; // break; // default: // break; // } theError = "Wrong format of the imported file. Can't import file."; aResShape.Nullify(); } } catch (Standard_Failure) { Handle(Standard_Failure) aFail = Standard_Failure::Caught(); theError = aFail->GetMessageString(); aResShape.Nullify(); } // Return previous locale return aResShape; }
int convert_to_ifc(const Handle_Geom_Surface& s, IfcSchema::IfcSurface*& surface, bool advanced) { if (s->DynamicType() == STANDARD_TYPE(Geom_Plane)) { Handle_Geom_Plane plane = Handle_Geom_Plane::DownCast(s); IfcSchema::IfcAxis2Placement3D* place; /// @todo: Note that the Ax3 is converted to an Ax2 here if (!convert_to_ifc(plane->Position().Ax2(), place, advanced)) { return 0; } surface = new IfcSchema::IfcPlane(place); return 1; } #ifdef USE_IFC4 else if (s->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) { Handle_Geom_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast(s); IfcSchema::IfcAxis2Placement3D* place; /// @todo: Note that the Ax3 is converted to an Ax2 here if (!convert_to_ifc(cyl->Position().Ax2(), place, advanced)) { return 0; } surface = new IfcSchema::IfcCylindricalSurface(place, cyl->Radius()); return 1; } else if (s->DynamicType() == STANDARD_TYPE(Geom_BSplineSurface)) { typedef IfcTemplatedEntityListList<IfcSchema::IfcCartesianPoint> points_t; Handle_Geom_BSplineSurface bspline = Handle_Geom_BSplineSurface::DownCast(s); points_t::ptr points(new points_t); TColgp_Array2OfPnt poles(1, bspline->NbUPoles(), 1, bspline->NbVPoles()); bspline->Poles(poles); for (int i = 1; i <= bspline->NbUPoles(); ++i) { std::vector<IfcSchema::IfcCartesianPoint*> ps; ps.reserve(bspline->NbVPoles()); for (int j = 1; j <= bspline->NbVPoles(); ++j) { IfcSchema::IfcCartesianPoint* p; if (!convert_to_ifc(poles.Value(i, j), p, advanced)) { return 0; } ps.push_back(p); } points->push(ps); } IfcSchema::IfcKnotType::IfcKnotType knot_spec_u = opencascade_knotspec_to_ifc(bspline->UKnotDistribution()); IfcSchema::IfcKnotType::IfcKnotType knot_spec_v = opencascade_knotspec_to_ifc(bspline->VKnotDistribution()); if (knot_spec_u != knot_spec_v) { knot_spec_u = IfcSchema::IfcKnotType::IfcKnotType_UNSPECIFIED; } std::vector<int> umults; std::vector<int> vmults; std::vector<double> uknots; std::vector<double> vknots; std::vector< std::vector<double> > weights; TColStd_Array1OfInteger bspline_umults(1, bspline->NbUKnots()); TColStd_Array1OfInteger bspline_vmults(1, bspline->NbVKnots()); TColStd_Array1OfReal bspline_uknots(1, bspline->NbUKnots()); TColStd_Array1OfReal bspline_vknots(1, bspline->NbVKnots()); TColStd_Array2OfReal bspline_weights(1, bspline->NbUPoles(), 1, bspline->NbVPoles()); bspline->UMultiplicities(bspline_umults); bspline->VMultiplicities(bspline_vmults); bspline->UKnots(bspline_uknots); bspline->VKnots(bspline_vknots); bspline->Weights(bspline_weights); opencascade_array_to_vector(bspline_umults, umults); opencascade_array_to_vector(bspline_vmults, vmults); opencascade_array_to_vector(bspline_uknots, uknots); opencascade_array_to_vector(bspline_vknots, vknots); opencascade_array_to_vector2(bspline_weights, weights); bool rational = false; for (std::vector< std::vector<double> >::const_iterator it = weights.begin(); it != weights.end(); ++it) { for (std::vector<double>::const_iterator jt = it->begin(); jt != it->end(); ++jt) { if ((*jt) != 1.) { rational = true; break; } } } if (rational) { surface = new IfcSchema::IfcRationalBSplineSurfaceWithKnots( bspline->UDegree(), bspline->VDegree(), points, IfcSchema::IfcBSplineSurfaceForm::IfcBSplineSurfaceForm_UNSPECIFIED, bspline->IsUClosed(), bspline->IsVClosed(), false, umults, vmults, uknots, vknots, knot_spec_u, weights ); } else { surface = new IfcSchema::IfcBSplineSurfaceWithKnots( bspline->UDegree(), bspline->VDegree(), points, IfcSchema::IfcBSplineSurfaceForm::IfcBSplineSurfaceForm_UNSPECIFIED, bspline->IsUClosed(), bspline->IsVClosed(), false, umults, vmults, uknots, vknots, knot_spec_u ); } return 1; } #endif return 0; }
//======================================================================= //function : MergeEdges //purpose : auxilary //======================================================================= static Standard_Boolean MergeEdges(const TopTools_SequenceOfShape& SeqEdges, const TopoDS_Face& aFace, const Standard_Real Tol, TopoDS_Edge& anEdge) { // make chain for union BRep_Builder B; ShapeAnalysis_Edge sae; TopoDS_Edge FirstE = TopoDS::Edge(SeqEdges.Value(1)); TopoDS_Edge LastE = FirstE; TopoDS_Vertex VF = sae.FirstVertex(FirstE); TopoDS_Vertex VL = sae.LastVertex(LastE); TopTools_SequenceOfShape aChain; aChain.Append(FirstE); TColStd_MapOfInteger IndUsedEdges; IndUsedEdges.Add(1); Standard_Integer j; for(j=2; j<=SeqEdges.Length(); j++) { for(Standard_Integer k=2; k<=SeqEdges.Length(); k++) { if(IndUsedEdges.Contains(k)) continue; TopoDS_Edge edge = TopoDS::Edge(SeqEdges.Value(k)); TopoDS_Vertex VF2 = sae.FirstVertex(edge); TopoDS_Vertex VL2 = sae.LastVertex(edge); if(sae.FirstVertex(edge).IsSame(VL)) { aChain.Append(edge); LastE = edge; VL = sae.LastVertex(LastE); IndUsedEdges.Add(k); } else if(sae.LastVertex(edge).IsSame(VF)) { aChain.Prepend(edge); FirstE = edge; VF = sae.FirstVertex(FirstE); IndUsedEdges.Add(k); } } } if(aChain.Length()<SeqEdges.Length()) { MESSAGE ("can not create correct chain..."); return Standard_False; } // union edges in chain // first step: union lines and circles TopLoc_Location Loc; Standard_Real fp1,lp1,fp2,lp2; for(j=1; j<aChain.Length(); j++) { TopoDS_Edge edge1 = TopoDS::Edge(aChain.Value(j)); Handle(Geom_Curve) c3d1 = BRep_Tool::Curve(edge1,Loc,fp1,lp1); if(c3d1.IsNull()) break; while(c3d1->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) { Handle(Geom_TrimmedCurve) tc = Handle(Geom_TrimmedCurve)::DownCast(c3d1); c3d1 = tc->BasisCurve(); } TopoDS_Edge edge2 = TopoDS::Edge(aChain.Value(j+1)); Handle(Geom_Curve) c3d2 = BRep_Tool::Curve(edge2,Loc,fp2,lp2); if(c3d2.IsNull()) break; while(c3d2->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) { Handle(Geom_TrimmedCurve) tc = Handle(Geom_TrimmedCurve)::DownCast(c3d2); c3d2 = tc->BasisCurve(); } if( c3d1->IsKind(STANDARD_TYPE(Geom_Line)) && c3d2->IsKind(STANDARD_TYPE(Geom_Line)) ) { // union lines Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(c3d1); Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(c3d2); gp_Dir Dir1 = L1->Position().Direction(); gp_Dir Dir2 = L2->Position().Direction(); //if(!Dir1.IsEqual(Dir2,Precision::Angular())) { //if(!Dir1.IsParallel(Dir2,Precision::Angular())) { if(!Dir1.IsParallel(Dir2,Tol)) { continue; } // can union lines => create new edge TopoDS_Vertex V1 = sae.FirstVertex(edge1); gp_Pnt PV1 = BRep_Tool::Pnt(V1); TopoDS_Vertex V2 = sae.LastVertex(edge2); gp_Pnt PV2 = BRep_Tool::Pnt(V2); gp_Vec Vec(PV1,PV2); Handle(Geom_Line) L = new Geom_Line(gp_Ax1(PV1,Vec)); Standard_Real dist = PV1.Distance(PV2); Handle(Geom_TrimmedCurve) tc = new Geom_TrimmedCurve(L,0.0,dist); TopoDS_Edge E; B.MakeEdge (E,tc,Precision::Confusion()); B.Add (E,V1); B.Add (E,V2); B.UpdateVertex(V1, 0., E, 0.); B.UpdateVertex(V2, dist, E, 0.); //ShapeFix_Edge sfe; //sfe.FixAddPCurve(E,aFace,Standard_False); //sfe.FixSameParameter(E); aChain.Remove(j); aChain.SetValue(j,E); j--; } if( c3d1->IsKind(STANDARD_TYPE(Geom_Circle)) && c3d2->IsKind(STANDARD_TYPE(Geom_Circle)) ) { // union circles Handle(Geom_Circle) C1 = Handle(Geom_Circle)::DownCast(c3d1); Handle(Geom_Circle) C2 = Handle(Geom_Circle)::DownCast(c3d2); gp_Pnt P01 = C1->Location(); gp_Pnt P02 = C2->Location(); if (P01.Distance(P02) > Precision::Confusion()) continue; // can union circles => create new edge TopoDS_Vertex V1 = sae.FirstVertex(edge1); gp_Pnt PV1 = BRep_Tool::Pnt(V1); TopoDS_Vertex V2 = sae.LastVertex(edge2); gp_Pnt PV2 = BRep_Tool::Pnt(V2); TopoDS_Vertex VM = sae.LastVertex(edge1); gp_Pnt PVM = BRep_Tool::Pnt(VM); GC_MakeCircle MC (PV1,PVM,PV2); Handle(Geom_Circle) C = MC.Value(); TopoDS_Edge E; if (!MC.IsDone() || C.IsNull()) { // jfa for Mantis issue 0020228 if (PV1.Distance(PV2) > Precision::Confusion()) continue; // closed chain C = C1; B.MakeEdge (E,C,Precision::Confusion()); B.Add(E,V1); B.Add(E,V2); } else { gp_Pnt P0 = C->Location(); gp_Dir D1(gp_Vec(P0,PV1)); gp_Dir D2(gp_Vec(P0,PV2)); Standard_Real fpar = C->XAxis().Direction().Angle(D1); if(fabs(fpar)>Precision::Confusion()) { // check orientation gp_Dir ND = C->XAxis().Direction().Crossed(D1); if(ND.IsOpposite(C->Axis().Direction(),Precision::Confusion())) { fpar = -fpar; } } Standard_Real lpar = C->XAxis().Direction().Angle(D2); if(fabs(lpar)>Precision::Confusion()) { // check orientation gp_Dir ND = C->XAxis().Direction().Crossed(D2); if(ND.IsOpposite(C->Axis().Direction(),Precision::Confusion())) { lpar = -lpar; } } if(lpar<fpar) lpar += 2*M_PI; Handle(Geom_TrimmedCurve) tc = new Geom_TrimmedCurve(C,fpar,lpar); B.MakeEdge (E,tc,Precision::Confusion()); B.Add(E,V1); B.Add(E,V2); B.UpdateVertex(V1, fpar, E, 0.); B.UpdateVertex(V2, lpar, E, 0.); } aChain.Remove(j); aChain.SetValue(j,E); j--; } } if (j < aChain.Length()) { MESSAGE ("null curve3d in edge..."); return Standard_False; } if (aChain.Length() > 1) { // second step: union edges with various curves // skl for bug 0020052 from Mantis: perform such unions // only if curves are bspline or bezier bool NeedUnion = true; for(j=1; j<=aChain.Length(); j++) { TopoDS_Edge edge = TopoDS::Edge(aChain.Value(j)); Handle(Geom_Curve) c3d = BRep_Tool::Curve(edge,Loc,fp1,lp1); if(c3d.IsNull()) continue; while(c3d->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) { Handle(Geom_TrimmedCurve) tc = Handle(Geom_TrimmedCurve)::DownCast(c3d); c3d = tc->BasisCurve(); } if( ( c3d->IsKind(STANDARD_TYPE(Geom_BSplineCurve)) || c3d->IsKind(STANDARD_TYPE(Geom_BezierCurve)) ) ) continue; NeedUnion = false; break; } if(NeedUnion) { MESSAGE ("can not make analitical union => make approximation"); TopoDS_Wire W; B.MakeWire(W); for(j=1; j<=aChain.Length(); j++) { TopoDS_Edge edge = TopoDS::Edge(aChain.Value(j)); B.Add(W,edge); } Handle(BRepAdaptor_HCompCurve) Adapt = new BRepAdaptor_HCompCurve(W); Approx_Curve3d Conv(Adapt,Tol,GeomAbs_C1,9,1000); Handle(Geom_BSplineCurve) bc = Conv.Curve(); TopoDS_Edge E; B.MakeEdge (E,bc,Precision::Confusion()); B.Add (E,VF); B.Add (E,VL); aChain.SetValue(1,E); } else { MESSAGE ("can not make approximation for such types of curves"); return Standard_False; } } anEdge = TopoDS::Edge(aChain.Value(1)); return Standard_True; }