public override bool Execute() { var firstShape = Dependency[0].ReferedShape; var secondShape = Dependency[1].ReferedShape; if (firstShape.IsSame(secondShape)) { return(false); } NodeUtils.Hide(Dependency[0].Reference); NodeUtils.Hide(Dependency[1].Reference); switch (Dependency[2].Integer) { case (int)BooleanOperations.Substract: var cut = new BRepAlgoAPICut(firstShape, secondShape); if (!cut.IsDone) { return(false); } if ((cut.HasGenerated == false) && (cut.HasModified == false)) { return(false); } Shape = cut.Shape; break; case (int)BooleanOperations.Add: var fuse = new BRepAlgoAPIFuse(firstShape, secondShape); if (!fuse.IsDone) { return(false); } if ((fuse.HasGenerated == false) && (fuse.HasModified == false)) { return(false); } Shape = fuse.Shape; break; case (int)BooleanOperations.Intersect: var common = new BRepAlgoAPICommon(firstShape, secondShape); if (!common.IsDone) { return(false); } if ((common.HasGenerated == false) && (common.HasModified == false)) { return(false); } Shape = common.Shape; break; } return(true); }
private static TopoDSShape BuildAxisShapeHandle(gpAx1 mainAxis, double arrowLength, double arrowWidth) { var cylinderShape = GeomUtils.MakeCylinder(mainAxis, arrowWidth, arrowLength * 3 / 4, GeomUtils.DegreesToRadians(360)); var coneVector = new gpVec(mainAxis.Direction); coneVector.Multiply(arrowLength * 3 / 4); var coneLocation = mainAxis.Translated(coneVector); var cone = GeomUtils.MakeCone(coneLocation, arrowWidth * 1.5, 0, arrowLength / 4, GeomUtils.DegreesToRadians(360)); var fuse = new BRepAlgoAPIFuse(cylinderShape, cone); return(fuse.Shape); }
/// <summary> /// Detects coliding faces in the first list received as parameter and puts them in the second list /// </summary> /// <param name="candidates"></param> /// <param name="results"></param> private static void DetectColidingCandidates(List <Node> candidates, List <Node> results) { var shapes = new List <ShapeInfo>(); int k = 0; foreach (var node in candidates) { var shape = node.Get <TopoDsShapeInterpreter>(); var area = GeomUtils.GetFaceArea(shape.Shape); if (area > 0) { var shapeInfo = new ShapeInfo { Shape = shape.Shape, Area = area, Node = node, Processed = 0 }; shapes.Add(shapeInfo); } } shapes = shapes.OrderByDescending(x => x.Area).ToList(); var iterations = 0; for (int i = 0; i < shapes.Count; i++) { if (shapes[i].Processed == 1) { continue; } for (int j = i + 1; j < shapes.Count; j++) { if (shapes[j].Processed == 1) { continue; } var cut = new BRepAlgoAPICommon(shapes[i].Shape, shapes[j].Shape); var shapeCommon = cut.Shape; var fuse = new BRepAlgoAPIFuse(shapes[i].Shape, shapes[j].Shape); var fusedShape = fuse.Shape; var fuseArea = GeomUtils.GetFaceArea(fusedShape); iterations++; if (Math.Abs(fuseArea - shapes[i].Area) < Precision.Confusion) { if (!results.Contains(shapes[i].Node)) { results.Add(shapes[i].Node); } if (!results.Contains(shapes[j].Node)) { results.Add(shapes[j].Node); } shapes[j].Processed = 1; } //if ((shapeCommon != null) && (!shapeCommon.IsNull)) //{ // var areaCommon = GeomUtils.GetFaceArea(shapeCommon); // if (Math.Abs(areaCommon - shapes[j].Area) < Precision.Confusion) // { // if (RelativePosition(shapes[j].Shape, shapes[i].Shape) == 1 && !results.Contains(shapes[j].Node)) // { // results.Add(shapes[j].Node); // shapes[j].Processed = 1; // } // if(!results.Contains(shapes[i].Node)) // { // results.Add(shapes[i].Node); // } // } //} } } }