public override bool Execute() { Ensure.AreEqual(Dependency[0].Integer % 3, 1); while (Dependency[0].Integer != Dependency.Count - 1) { AddDependency(InterpreterNames.Point3D); } var pointList = new Point3D[4]; var items = Dependency[0].Integer; var compoundShape = new TopoDSCompound(); var shapeBuilder = new BRepBuilder(); shapeBuilder.MakeCompound(compoundShape); var startIndex = 0; while (startIndex < items - 1) { pointList[0] = Dependency[startIndex + 1].TransformedPoint3D; pointList[1] = Dependency[startIndex + 2].TransformedPoint3D; pointList[2] = Dependency[startIndex + 3].TransformedPoint3D; pointList[3] = Dependency[startIndex + 4].TransformedPoint3D; var shape = SplineUtils.BuildSplineWire(pointList); shapeBuilder.Add(compoundShape, shape); startIndex += 3; } Shape = compoundShape; return(true); }
/// <summary> /// Cuts through all childs of the node with the TopoDS_Shape passed as parameter. /// It returns a compund made from the affected shapes /// </summary> /// <param name = "nodes"></param> /// <param name = "cutPrismShape"></param> private static TopoDSShape CutThroughAll(IEnumerable <SceneSelectedEntity> nodes, TopoDSShape cutPrismShape) { var compoundShape = new TopoDSCompound(); var shapeBuilder = new BRepBuilder(); shapeBuilder.MakeCompound(compoundShape); var resShape = (TopoDSShape)compoundShape; foreach (var cutShape in nodes) { var childNode = cutShape.Node; // Try to Cut through the object var topoShape = childNode.Get <NamedShapeInterpreter>().Shape; if (topoShape == null) { continue; } var cut = new BRepAlgoAPICut(topoShape, cutPrismShape); // Check if the shape was altered by the Cut if ((cut.HasGenerated == false) && (cut.HasModified == false)) { continue; } TopoDSShape shapeCut = null; try { shapeCut = cut.Shape; } catch (Exception) { Log.Info("Exception on create cut shape"); } if ((shapeCut != null) && (!shapeCut.IsNull)) { // Show the new shape as a new Node shapeBuilder.Add(resShape, shapeCut); } } return(resShape); }
public override bool Execute() { if (Dependency.Count < 2) { return(false); } var compoundShape = new TopoDSCompound(); var shapeBuilder = new BRepBuilder(); shapeBuilder.MakeCompound(compoundShape); var resShape = (TopoDSShape)compoundShape; var isFirstPoint = true; var second = new Point3D(); foreach (var childNode in Dependency.Children) { var point3D = childNode.TransformedPoint3D; if (isFirstPoint) { second = point3D; isFirstPoint = false; continue; } var first = second; second = point3D; var shapeCut = CreateLine(first, second); if (shapeCut != null) { shapeBuilder.Add(resShape, shapeCut); } } Shape = resShape; return(true); }
/// <summary> /// Cuts through all childs of the node with the TopoDS_Shape passed as parameter. /// It returns a compund made from the affected shapes /// </summary> /// <param name = "root"></param> /// <param name = "cutPrismShape"></param> /// <param name = "affectedNodes"></param> /// <param name = "shapeList"></param> private static TopoDSShape CutThroughAll(Node root, TopoDSShape cutPrismShape, ICollection <SceneSelectedEntity> affectedNodes, IEnumerable <int> shapeList) { var compoundShape = new TopoDSCompound(); var shapeBuilder = new BRepBuilder(); shapeBuilder.MakeCompound(compoundShape); var resShape = (TopoDSShape)compoundShape; foreach (var childNodeIndex in shapeList) { var childNode = new NodeBuilder(root[childNodeIndex]); var topoShape = childNode.Shape; if (topoShape == null) { continue; } BRepAlgoAPICut cut; var filler = new BOPToolsDSFiller(); try { filler.SetShapes(topoShape, cutPrismShape); if (!filler.IsDone) { continue; } filler.Perform(); cut = new BRepAlgoAPICut(topoShape, cutPrismShape, filler, true); if (!cut.IsDone) { continue; } // Check if the shape was altered by the Cut //if ((cut.HasGenerated == false) && (cut.HasModified == false)) // continue; } catch (Exception) { continue; } TopoDSShape shapeCut = null; try { shapeCut = cut.Shape; } catch (Exception) { Log.Info("Exception on create cut shape"); } if ((shapeCut == null) || (shapeCut.IsNull)) { continue; } // If Cut succeeded hide the original shape NodeUtils.Hide(childNode.Node); // Show the new shape as a new Node shapeBuilder.Add(resShape, shapeCut); // Add the affceted node into the affectedNodes list affectedNodes.Add(new SceneSelectedEntity(childNode.Node)); } return(resShape); }