using TopoDS; using BRep; using BRepBuilderAPI; using Geom; using gp; using System; using System.Collections.Generic; using System.Text; using TopExp; using GC; using BRepPrimAPI; using TopAbs; using TopTools; using BRepOffsetAPI; namespace OCCTest { public class HollowedCylinder { public TopoDS_Compound compound; public bool test = false; public string monString; public HollowedCylinder(double myRadius, double myHeight, double myThickness) { // Profile : Define Support Points gp_Pnt aPnt1 = new gp_Pnt(-myRadius / 2f, 0f, 0f); gp_Pnt aPnt2 = new gp_Pnt(myRadius / 2f, 0f, 0f); gp_Pnt aPnt3 = new gp_Pnt(0f, -myRadius / 2f, 0f); // Profile : Define the Geometry GC_MakeArcOfCircle anArcOfCircle = new GC_MakeArcOfCircle(aPnt1, aPnt2, aPnt3); // trace a line between 1 and 2, but passing by 3 // Profile : Define the Topology //TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge(anArcOfCircle); BRepBuilderAPI_MakeEdge aMakeEdge2 = new BRepBuilderAPI_MakeEdge(anArcOfCircle.Value()); TopoDS_Edge anEdge2 = aMakeEdge2.Edge(); //TopoDS_Wire aWire = BRepBuilderAPI_MakeWire(anEdge2); BRepBuilderAPI_MakeWire aMakeWire = new BRepBuilderAPI_MakeWire(anEdge2); TopoDS_Wire aWire = aMakeWire.Wire(); // Complete Profile //gp_Ax1 xAxis = gp::OX(); // origine 0,0,0 avec dir 1,0,0 gp_Pnt aOrigin = new gp_Pnt(0f, 0f, 0f); gp_Dir dir= new gp_Dir(1f, 0f, 0f); gp_Ax1 axis= new gp_Ax1(aOrigin, dir); gp_Trsf aTrsf= new gp_Trsf(); aTrsf.SetMirror(axis); // ok j'ai pas compris, il definit pas de plan pour sa reflection du coup ...? et du coup c'est pour obtenir une matrice de transformation ?? donc on se limite au plan du câble et on fait une reflection par rapport à l'axe.. okok TopoDS_Wire aMirroredWire = aWire; BRepBuilderAPI_Transform aBRepTrsf= new BRepBuilderAPI_Transform(aMirroredWire, aTrsf, true); // application de la matrice supposée //TopoDS_Shape aMirroredShape = aBRepTrsf.Shape(); /**/ //TopoDS_Wire aMirroredWire = TopoDS.TopoDS_Wire.wire(aMirroredShape); BRepBuilderAPI_MakeWire mkWire= new BRepBuilderAPI_MakeWire(); mkWire.Add(aWire); mkWire.Add(aMirroredWire); TopoDS_Wire myWireProfile = mkWire.Wire(); /**/ // Body : Prism the Profile // bordel y a pas de constructeur entre plusieurs wires, en gros je peux faire entre une surface et un wire puis rajouter d'autres wire mais ce faisant j'obtiens plutôt une grande surface plutôt qu'une bande circulaire (je crois?) //TopoDS_Face myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile); BRepBuilderAPI_MakeFace myMakeFaceProfile = new BRepBuilderAPI_MakeFace(myWireProfile); TopoDS_Face myFaceProfile = myMakeFaceProfile.Face(); gp_Vec aPrismVec=new gp_Vec(0, 0, myHeight); //TopoDS_Shape myBody = BRepPrimAPI_MakePrism(myFaceProfile, aPrismVec); BRepPrimAPI_MakePrism myMakeBody = new BRepPrimAPI_MakePrism(myFaceProfile, aPrismVec); TopoDS_Shape myBody = myMakeBody.Shape(); /**/ // Body : Create a Hollowed Solid TopoDS_Face faceTopToRemove= new TopoDS_Face(); TopoDS_Face faceBotToRemove = new TopoDS_Face(); double zMax = -1; double zMin = 1; for (TopExp_Explorer aFaceExplorer=new TopExp_Explorer(myBody, TopAbs_ShapeEnum.TopAbs_FACE); aFaceExplorer.More(); aFaceExplorer.Next()) { //TopoDS_Face aFace = TopoDS::Face(aFaceExplorer.Current()); TopoDS_Face aFace = new TopoDS_Face(); //aFace = (TopoDS_Face)aFaceExplorer.Current(); aFace = TopoDS.TopoDS.ToFace(aFaceExplorer.Current()); // Check if is the top face of the bottle's neck //Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aFace); Geom_Surface aSurface = BRep_Tool.Surface(aFace); //if (aSurface->DynamicType() == STANDARD_TYPE(Geom_Plane)) if (aSurface.GetType().ToString() == Geom_Plane.get_type_name()) //Standard.Standard_Type { //Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(aSurface); Geom_Plane aPlane = Geom_Plane.DownCast(aSurface); gp_Pnt aPnt = aPlane.Location(); double aZ = aPnt.Z(); if (aZ > zMax) { zMax = aZ; faceTopToRemove = aFace; } if (aZ < zMin) { zMin = aZ; faceBotToRemove = aFace; } } } TopTools_ListOfShape facesToRemove= new TopTools_ListOfShape(); facesToRemove.Append(faceTopToRemove); facesToRemove.Append(faceBotToRemove); try { //myBody = BRepOffsetAPI_MakeThickSolid(myBody, facesToRemove, -myThickness, 0.001); // à quoi correspond le 1.e-3 ? BRepOffsetAPI_MakeThickSolid myMakeThickBody = new BRepOffsetAPI_MakeThickSolid(myBody, facesToRemove, -myThickness, 0.001); /*BRepOffsetAPI_MakeThickSolid myMakeThickBody = new BRepOffsetAPI_MakeThickSolid(); myMakeThickBody.MakeThickSolidByJoin(myBody, facesToRemove, -myThickness, 0.001); /*myBody = myMakeThickBody.Shape();//*/ } catch (Exception e) { Console.WriteLine(e); monString = e.ToString(); } /* // Building the Resulting Compound TopoDS_Compound aRes= new TopoDS_Compound(); BRep_Builder aBuilder= new BRep_Builder(); aBuilder.MakeCompound(ref aRes); TopoDS_Shape myRefOut = new TopoDS_Shape(); myRefOut = aRes.EmptyCopied(); aBuilder.Add(ref myRefOut, myBody); //return aRes; this.compound = aRes;//*/ test = true; } } }