public override void UpdatePointPosition(int index, Mouse3DPosition vertex) { var nodeBuilder = new NodeBuilder(Node); if (nodeBuilder.FunctionName == FunctionNames.Trim) { return; } var gravityCenter = GeomUtils.ExtractGravityCenter(nodeBuilder.Shape); var newPoint = GetPointForIndex(vertex.Point, gravityCenter, index); var mouseTranslation = GeomUtils.BuildTranslation((gravityCenter), newPoint); var translateValue = newPoint.SubstractCoordinate(gravityCenter); var document = Dependency[0].Node.Root.Get <DocumentContextInterpreter>().Document; if (!NodeUtils.NodeIsOnSketch(nodeBuilder)) { NodeUtils.Translate3DNode(nodeBuilder, document, translateValue);//, gravityCenter); } else { var sketchNode = AutoGroupLogic.FindSketchNode(Node); NodeUtils.TranslateSketchNode(nodeBuilder, translateValue, sketchNode);// mouseTranslation); var constraintMapper = new ConstraintDocumentHelper(document, sketchNode); constraintMapper.SetMousePosition(Dependency[0].Reference.Index); var error = constraintMapper.ImpactAndSolve(Dependency[0].Node.Get <ReferenceInterpreter>().Node); } }
public void CutDeleteBaseTest2() { var document = TestUtils.DefaultsSetup(); var sketchCreator = new SketchCreator(document, false); var sketchNode = sketchCreator.BuildSketchNode(); document.Transact(); var circleBuilder = TestUtils.Circle(document, sketchNode, new Point3D(0, 0, 0), 10); TestUtils.Circle(document, sketchNode, new Point3D(20, 20, 0), 10); Assert.AreEqual(circleBuilder.LastExecute, true); sketchNode.Children[2].Set <MeshTopoShapeInterpreter>().Shape = AutoGroupLogic.RebuildSketchFace(sketchNode, document); var extrudeBuilder = new NodeBuilder(document, FunctionNames.Extrude); extrudeBuilder[0].Reference = sketchNode; extrudeBuilder[1].Integer = 0; extrudeBuilder[2].Real = 10; extrudeBuilder.ExecuteFunction(); Assert.AreEqual(extrudeBuilder.LastExecute, true); document.Commit("Extrude created"); document.Transact(); var volume = GeomUtils.GetSolidVolume(extrudeBuilder.Shape); Assert.AreEqual(volume, 2 * Math.PI * 1000); Assert.AreEqual(document.Root.Children.Count, 6); var sketchNode2 = sketchCreator.BuildSketchNode(); document.Commit("Second sketch created"); document.Transact(); TestUtils.Circle(document, sketchNode2, new Point3D(0, 0, 0), 5); sketchNode2.Children[2].Set <MeshTopoShapeInterpreter>().Shape = AutoGroupLogic.RebuildSketchFace(sketchNode2, document); var cutBuilder = new NodeBuilder(document, FunctionNames.Cut); cutBuilder[0].Reference = sketchNode2; cutBuilder[2].Integer = (int)ExtrusionTypes.MidPlane; cutBuilder[1].Real = 10000; cutBuilder.ExecuteFunction(); Assert.AreEqual(cutBuilder.LastExecute, true); volume = GeomUtils.GetSolidVolume(cutBuilder.Shape); Assert.AreEqual(volume, 2 * Math.PI * 1000 - Math.PI * 250); Assert.AreEqual(document.Root.Children.Count, 10); var nodeToDelete = document.Root[2]; NodeBuilderUtils.DeleteNode(nodeToDelete, document); document.Commit("Deleted"); document.Transact(); NodeUtils.RebuildAllSketchFaces(document); extrudeBuilder.ExecuteFunction(); cutBuilder.ExecuteFunction(); document.Commit("Finished"); Assert.IsTrue(cutBuilder.LastExecute); volume = GeomUtils.GetSolidVolume(cutBuilder.Shape); Assert.AreEqual(8, document.Root.Children.Count, "Circle is not deleted"); Assert.AreEqual(volume, Math.PI * 1000); }
public void ExtrudeSketchTest() { var document = TestUtils.DefaultsSetup(); var sketchCreator = new SketchCreator(document, false); var sketchNode = sketchCreator.BuildSketchNode(); document.Transact(); var circleBuilder = TestUtils.Circle(document, sketchNode, new Point3D(0, 0, 0), 10); TestUtils.Circle(document, sketchNode, new Point3D(20, 20, 0), 10); Assert.AreEqual(circleBuilder.LastExecute, true); sketchNode.Children[2].Set <MeshTopoShapeInterpreter>().Shape = AutoGroupLogic.RebuildSketchFace(sketchNode, document); var extrudeBuilder = new NodeBuilder(document, FunctionNames.Extrude); extrudeBuilder[0].Reference = sketchNode; extrudeBuilder[1].Integer = 0; extrudeBuilder[2].Real = 10; extrudeBuilder.ExecuteFunction(); Assert.AreEqual(extrudeBuilder.LastExecute, true); document.Commit("Extrude created"); document.Transact(); var volume = GeomUtils.GetSolidVolume(extrudeBuilder.Shape); Assert.AreEqual(volume, 2 * Math.PI * 1000); Assert.AreEqual(document.Root.Children.Count, 6); }
private void OnStepsCompleted() { if (OnStepsCompletedHandler != null) { OnStepsCompletedHandler(); } else { AutoCompleteDependencies(); } if (DocumentNodeBuilder != null && DocumentNodeBuilder.LastExecute) { AddToTreeOnComplete.Add(DocumentNodeBuilder.Node); } if (!AutoFace) { return; } var autoFaceNode = AutoGroupLogic.TryAutoGroup(Document, DocumentNodeBuilder.Node); if (autoFaceNode != null) { AddToTreeOnComplete.Add(autoFaceNode); } }
public static List <Node> GetVisibleSketchNodes(Document document) { var results = new List <Node>(); var visibleNodes = new List <Node>(); var root = document.Root; var found = true; while (found) { found = false; results.AddRange(from node in root.ChildrenList let builder = new NodeBuilder(node) where FunctionNames.GetSketchShapes().Contains(builder.FunctionName) select node); } var sketchNodes = new Dictionary <Node, bool>(); foreach (var node in results) { var sketchNode = AutoGroupLogic.FindSketchNode(node); if (!sketchNodes.ContainsKey(sketchNode)) { int index; sketchNodes.Add(sketchNode, SketchHas3DApplied(document, sketchNode, out index)); } if (!sketchNodes[sketchNode]) { visibleNodes.Add(node); } } return(visibleNodes); }
public static List <Node> GetSketchNodes(Node sketchNode, Document document, bool includeAuxiliaryNodes) { var results = new List <Node>(); var root = document.Root; var found = true; var functionNames = new List <string> { FunctionNames.Circle, FunctionNames.Ellipse, FunctionNames.LineTwoPoints, FunctionNames.Arc, FunctionNames.Arc3P, FunctionNames.Point }; if (includeAuxiliaryNodes) { functionNames.Add(FunctionNames.LineHints); } while (found) { found = false; results.AddRange(from node in root.ChildrenList let builder = new NodeBuilder(node) where functionNames.Contains(builder.FunctionName) let currentSketchNode = AutoGroupLogic.FindSketchNode(node) where currentSketchNode.Index == sketchNode.Index select node); } return(results); }
private void ApplyCut() { var cutType = cutBuilder[2].Integer; var cutDepth = cutBuilder[1].Real; Document.Transact(); var sketchNode = AutoGroupLogic.FindSketchNode(_selectedNode.Node); // Apply Cut on it cutBuilder = new NodeBuilder(TreeUtils.Cut(Document, sketchNode, cutDepth, cutType == 0? CutTypes.ToDepth:CutTypes.ThroughAll)); if (cutBuilder == null) { Document.Revert(); } else { cutBuilder.ExecuteFunction(); NodeUtils.SetSketchTransparency(Document, sketchNode, ObjectVisibility.Hidden); // Commit Document.Commit("Apply Cut"); UpdateView(); AddNodeToTree(cutBuilder.Node); ResetWorkingPlane(); } Inputs[InputNames.FacePickerPlane].Send(NotificationNames.Resume); BackToNeutralModifier(); //Inputs[InputNames.FacePickerPlane].Send(NotificationNames.Resume); }
private Point3D ExtractCenterAndRadius(Node node, ref double radius) { var nb = new NodeBuilder(node); if (node.Get <ShapeFunctionsInterface.Functions.FunctionInterpreter>().Name == FunctionNames.Arc) { var P1 = nb.Dependency[0].RefTransformedPoint3D; var P2 = nb.Dependency[1].RefTransformedPoint3D; radius = Math.Sqrt((P1.X - P2.X) * (P1.X - P2.X) + (P1.Y - P2.Y) * (P1.Y - P2.Y) + (P1.Z - P2.Z) * (P1.Z - P2.Z)); return(P1); } if (node.Get <ShapeFunctionsInterface.Functions.FunctionInterpreter>().Name == FunctionNames.Circle) { radius = nb.Dependency[1].Real; return(nb.Dependency[0].RefTransformedPoint3D); } if (node.Get <ShapeFunctionsInterface.Functions.FunctionInterpreter>().Name == FunctionNames.Arc3P) { var sketchNode = AutoGroupLogic.FindSketchNode(node); var sketchAx2 = GeomUtils.ExtractSketchNormal(sketchNode); var P1 = GeomUtils.Point3DTo2D(sketchAx2, nb.Dependency[0].RefTransformedPoint3D); var P2 = GeomUtils.Point3DTo2D(sketchAx2, nb.Dependency[1].RefTransformedPoint3D); var P3 = GeomUtils.Point3DTo2D(sketchAx2, nb.Dependency[2].RefTransformedPoint3D); var center = GeomUtils.CircleCenter(P1, P2, P3); radius = Math.Sqrt((P1.X - center.X) * (P1.X - center.X) + (P1.Y - center.Y) * (P1.Y - center.Y)); var centerPoint = GeomUtils.Point2DTo3D(sketchAx2, center); return(new Point3D(centerPoint)); } return(new Point3D(0, 0, 0)); }
public static void AddRectangleToNode(Document document, int point1, int point2) { if (!document.Root.Children.ContainsKey(point1) || !document.Root.Children.ContainsKey(point2)) { return; } var sketchNode = AutoGroupLogic.FindSketchNode(document.Root[point1]); var axis = new gpAx2(); axis.Axis = (sketchNode.Children[1].Get <Axis3DInterpreter>().Axis.GpAxis); var pointLinker = new SketchCreator(document).PointLinker; var point3Ds = new List <Point3D>(); var nb1 = new NodeBuilder(document.Root[point1]); var nb2 = new NodeBuilder(document.Root[point2]); var _firstPoint = nb1.Dependency[1].TransformedPoint3D; var _secondPoint = nb2.Dependency[1].TransformedPoint3D; var firstPoint2D = _firstPoint.ToPoint2D(axis); var secondPoint2D = _secondPoint.ToPoint2D(axis); var x1 = firstPoint2D.X; var y1 = firstPoint2D.Y; var x2 = secondPoint2D.X; var y2 = secondPoint2D.Y; point3Ds.Add(GeomUtils.Point2DTo3D(axis, x1, y1)); point3Ds.Add(GeomUtils.Point2DTo3D(axis, x2, y1)); point3Ds.Add(GeomUtils.Point2DTo3D(axis, x2, y2)); point3Ds.Add(GeomUtils.Point2DTo3D(axis, x1, y2)); document.Root.Remove(nb1.Node.Index); document.Root.Remove(nb2.Node.Index); BuildLine(document, pointLinker, point3Ds[0], point3Ds[1]); BuildLine(document, pointLinker, point3Ds[1], point3Ds[2]); BuildLine(document, pointLinker, point3Ds[2], point3Ds[3]); BuildLine(document, pointLinker, point3Ds[3], point3Ds[0]); }
protected override void OnMouseUpAction(Mouse3DPosition mouseData) { base.OnMouseUpAction(mouseData); _dragging = false; if (_extrudeStages == ExtrudeStages.SelectSketch) { var entities = Inputs[InputNames.SelectionContainerPipe].GetData(NotificationNames.GetEntities).Get <List <SceneSelectedEntity> >(); if (entities.Count <= 0) { return; } _sketchNode = AutoGroupLogic.FindSketchNode(entities[0].Node); Ensure.IsNotNull(_sketchNode); PreviewExtrudes(true); _extrudeStages = ExtrudeStages.SelectAutoFace; Inputs[InputNames.FacePickerPlane].Send(NotificationNames.Resume); } else if (_extrudeStages == ExtrudeStages.SelectAutoFace) { ProposeSelectedReferenceShape(_underMouseFace, mouseData); PreviewExtrudes(true); _extrudeStages = ExtrudeStages.ExtrudeAnimation; } else if (_extrudeStages == ExtrudeStages.ExtrudeAnimation) { } }
public void TranslateExtrudedSketchTest() { var document = TestUtils.DefaultsSetup(); var sketchCreator = new SketchCreator(document, false); var sketchNode = sketchCreator.BuildSketchNode(); document.Transact(); TestUtils.BuildRectangle(document, sketchNode, new Point3D(1, 1, 0), new Point3D(10, 1, 0), new Point3D(10, 13, 0), new Point3D(1, 13, 0)); sketchNode.Children[2].Set <MeshTopoShapeInterpreter>().Shape = AutoGroupLogic.RebuildSketchFace(sketchNode, document); var extrudeBuilder = new NodeBuilder(document, FunctionNames.Extrude); extrudeBuilder[0].Reference = sketchNode; extrudeBuilder[1].Integer = 0; extrudeBuilder[2].Real = 10; extrudeBuilder.ExecuteFunction(); Assert.AreEqual(extrudeBuilder.LastExecute, true); document.Commit("Extrude created"); document.Transact(); var volume = GeomUtils.GetSolidVolume(extrudeBuilder.Shape); Assert.AreEqual(volume, 1080); Assert.AreEqual(document.Root.Children.Count, 10); var sketchNodeBuilder = new NodeBuilder(document, FunctionNames.Sketch); sketchNodeBuilder[0].Axis3D = new Axis(new Point3D(0, 0, 0), new Point3D(0, 0, 1)); sketchNodeBuilder[2].Reference = extrudeBuilder.Node; sketchNodeBuilder[3].Integer = 3; sketchNodeBuilder.ExecuteFunction(); Assert.AreEqual(sketchNodeBuilder.LastExecute, true); Assert.AreEqual(document.Root.Children.Count, 11); //var circleBuilder = TestUtils.Circle(document, sketchNodeBuilder.Node, new Point3D(2, 13, 8), 5); //circleBuilder.ExecuteFunction(); var pointBuilder = new NodeBuilder(document, FunctionNames.Point); pointBuilder[0].Reference = sketchNode; pointBuilder[1].TransformedPoint3D = new Point3D(2, 13, 8); pointBuilder.ExecuteFunction(); var circle = new NodeBuilder(document, FunctionNames.Circle); circle[0].Reference = pointBuilder.Node; circle[1].Real = 5; circle.ExecuteFunction(); Assert.AreEqual(document.Root.Children.Count, 13); document.Commit("Circle drawn"); document.Transact(); NodeUtils.Translate3DNode(extrudeBuilder, document, new Point3D(11, 1, 0));//, new Point3D(1,1,0)); document.Commit("Translated"); Assert.AreEqual(pointBuilder[1].TransformedPoint3D, new Point3D(12, 13, 8)); document.Transact(); NodeUtils.Translate3DNode(extrudeBuilder, document, new Point3D(11, 11, 0));//, new Point3D(1, 1, 0)); Assert.AreEqual(pointBuilder[1].TransformedPoint3D, new Point3D(12, 23, 8)); }
private static int MakeFace(int l1, Document document) { var node = AutoGroupLogic.TryAutoGroup(document, document.Root[l1]); if (node == null) { return(-1); } return(node.Index); }
public void CloseShape() { LastCreatedShape = TreeUtils.AddLineToNode(_document, _lastPoint, _firstPoint).Node; var result = AutoGroupLogic.TryAutoGroup(_document, LastCreatedShape); if (result != null) { LastCreatedShape = result; } }
public override void OnActivate() { Inputs[InputNames.GeometricSolverPipe].Send(NotificationNames.DisableAll); var uiBuilder = ActionsGraph[InputNames.UiBuilderInput].Get <UiBuilder>(); var sketchControl = uiBuilder.GetItemAtPath("Ribbon/Modelling/Sketch/Sketch"); _sketchButton = (ISketchButton)sketchControl; if (Document.Root.Get <DocumentContextInterpreter>().ActiveSketch != -1) { var sketchNode = Document.Root[Document.Root.Get <DocumentContextInterpreter>().ActiveSketch]; // rebuild sketch faces sketchNode.Children[2].Set <MeshTopoShapeInterpreter>().Shape = null; var results = AutoGroupLogic.BuildAutoFaces(sketchNode, Document); Document.Transact(); if (results.Count > 0) { TopoDSShape finalShape = results[0]; // if there is more than one shape on the sketch, we need to sew the faces resulted from BuildAutoFaces for (int i = 1; i < results.Count; i++) { if (results[i] == null) { continue; } var sew = new BRepBuilderAPISewing(1.0e-06, true, true, true, false); sew.Add(finalShape); sew.Add(results[i]); var messg = new MessageProgressIndicator(); sew.Perform(messg); finalShape = sew.SewedShape; } sketchNode.Children[2].Set <MeshTopoShapeInterpreter>().Shape = finalShape; // we need to set transparency to 1 (don't show) before we set it to hidden sketchNode.Set <DrawingAttributesInterpreter>().Transparency = 1; sketchNode.Set <DrawingAttributesInterpreter>().Visibility = ObjectVisibility.Hidden; } int index; NodeUtils.SetSketchTransparency(Document, sketchNode, NodeUtils.SketchHas3DApplied(Document, sketchNode, out index) ? ObjectVisibility.Hidden : ObjectVisibility.ToBeDisplayed); } Inputs[InputNames.Mouse3DEventsPipe].Send(NotificationNames.SetPlane, new DataPackage(null)); Document.Root.Get <DocumentContextInterpreter>().ActiveSketch = -1; RemoveHighlightCurrentSketchNodes(); Document.Commit("reset active sketch"); _sketchButton.Unblock(); if (ActionsGraph.PendingAction != null && ActionsGraph.PendingAction.Name == ModifierNames.None) { Inputs[InputNames.SelectionContainerPipe].Send(NotificationNames.SwitchSelectionMode, TopAbsShapeEnum.TopAbs_FACE); } ActionsGraph.SwitchAction(ModifierNames.None); }
public static void RebuildDocumentFaces(Document document) { for (int i = 0; i < document.Root.Children.Count; i++) { var node = document.Root[i]; var nb = new NodeBuilder(node); if (nb.FunctionName != FunctionNames.Sketch) { continue; } node.Children[2].Set <MeshTopoShapeInterpreter>().Shape = AutoGroupLogic.RebuildSketchFace(node, document); } }
public int CutThroughAll(int sketchId) { if (!Document.Root.Children.ContainsKey(sketchId)) { return(-1); } var sketchNode = Document.Root[sketchId]; sketchNode.Children[2].Set <MeshTopoShapeInterpreter>().Shape = AutoGroupLogic.RebuildSketchFace(sketchNode, Document); var node = TreeUtils.Cut(Document, sketchNode, 100, CutTypes.ThroughAll); NodeUtils.SetSketchTransparency(Document, sketchNode, ObjectVisibility.Hidden); sketchNode.Set <DrawingAttributesInterpreter>().Visibility = ObjectVisibility.Hidden; return(node.Index); }
public void DrawTo(double x, double y, double z) { var newPoint = _lastPoint; newPoint.X += x; newPoint.Y += y; newPoint.Z += z; LastCreatedShape = TreeUtils.AddLineToNode(_document, _lastPoint, newPoint).Node; _lastPoint = newPoint; var result = AutoGroupLogic.TryAutoGroup(_document, LastCreatedShape); if (result != null) { LastCreatedShape = result; } }
public int Revolve(int shapeId, int lineId, double angle) { var sketchNode = Document.Root[shapeId]; if (sketchNode.Get <FunctionInterpreter>().Name == FunctionNames.Sketch) { sketchNode.Children[2].Set <MeshTopoShapeInterpreter>().Shape = AutoGroupLogic.RebuildSketchFace(sketchNode, Document); } var builder = new NodeBuilder(Document, FunctionNames.Revolve); builder[0].Reference = sketchNode; builder[1].Reference = Document.Root[lineId]; builder[2].Real = angle; builder.ExecuteFunction(); return(builder.Node.Index); }
private int BuildExtrude(int sketchId, double height, ExtrusionTypes type) { if (!Document.Root.Children.ContainsKey(sketchId)) { return(-1); } var sketchNode = Document.Root[sketchId]; sketchNode.Children[2].Set <MeshTopoShapeInterpreter>().Shape = AutoGroupLogic.RebuildSketchFace(sketchNode, Document); var extrudeBuilder = new NodeBuilder(Document, FunctionNames.Extrude); var sse = new SceneSelectedEntity(sketchNode); var nb = TreeUtils.Extrude(Document, sse, height, type); NodeUtils.SetSketchTransparency(Document, sketchNode, ObjectVisibility.Hidden); sketchNode.Set <DrawingAttributesInterpreter>().Visibility = ObjectVisibility.Hidden; return(nb.Node.Index); }
public static List <Node> GetSketchPoints(Node sketchNode, Document document) { var results = new List <Node>(); var root = document.Root; var found = true; while (found) { found = false; results.AddRange(from node in root.ChildrenList let builder = new NodeBuilder(node) where builder.FunctionName == FunctionNames.Point let currentSketchNode = AutoGroupLogic.FindSketchNode(node) where currentSketchNode.Index == sketchNode.Index select node); } return(results); }
public static NodeBuilder ExtrudeToDepth(Document document, int sketchId, double extrusionHeight) { if (!document.Root.Children.ContainsKey(sketchId)) { return(null); } var sketchNode = document.Root[sketchId]; sketchNode.Children[2].Set <MeshTopoShapeInterpreter>().Shape = AutoGroupLogic.RebuildSketchFace(sketchNode, document); var extrudeBuilder = new NodeBuilder(document, FunctionNames.Extrude); extrudeBuilder[0].Reference = sketchNode; extrudeBuilder[1].Integer = 0; extrudeBuilder[2].Real = extrusionHeight; extrudeBuilder.ExecuteFunction(); NodeUtils.SetSketchTransparency(document, sketchNode, ObjectVisibility.Hidden); sketchNode.Set <DrawingAttributesInterpreter>().Visibility = ObjectVisibility.Hidden; return(extrudeBuilder); }
public static void RebuildAllSketchFaces(Document document) { int shapeIndex = 0; var nodesToRebuild = new List <Node>(); foreach (var node in document.Root.Children) { if (node.Value.Get <FunctionInterpreter>().Name == FunctionNames.Sketch) { if (SketchHas3DApplied(document, node.Value, out shapeIndex)) { nodesToRebuild.Add(node.Value); } } } foreach (var node in nodesToRebuild) { node.Children[2].Set <MeshTopoShapeInterpreter>().Shape = AutoGroupLogic.RebuildSketchFace(node, document); } }
private void PerformRotate(NodeBuilder nodeBuilder, double value) { if (!NodeUtils.NodeIsOnSketch(nodeBuilder)) { var existingFaces = NodeUtils.GetDocumentFaces(Document); var list = NodeBuilderUtils.GetAllContained3DNodesIndexes(nodeBuilder.Node).Distinct().ToList(); var sketchNodes = new List <Node>(); foreach (var nodeIndex in list) { var node = Document.Root[nodeIndex.Key]; var affectedSketchNode = NodeUtils.RotateNode(new NodeBuilder(node), Document, _axis, value); if (affectedSketchNode != null) { sketchNodes.Add(affectedSketchNode); } } foreach (var sketchNode in sketchNodes) { sketchNode.Children[2].Set <MeshTopoShapeInterpreter>().Shape = AutoGroupLogic.RebuildSketchFace(sketchNode, Document); if (sketchNode.Children[2].Set <MeshTopoShapeInterpreter>().Shape != null) { if (nodeBuilder.Visibility == ObjectVisibility.Hidden) { nodeBuilder.Visibility = ObjectVisibility.ToBeDisplayed; } } } var newFaces = NodeUtils.GetDocumentFaces(Document); foreach (int face in newFaces.Except(existingFaces)) { Document.Root.Remove(face); } } else { NodeUtils.RotateSketchNode(nodeBuilder, _axis, value); } }
public CutDialog(Document document, V3dView view, SceneSelectedEntity sceneSelectedEntity) { InitializeComponent(); _document = document; _view = view; var selNode = sceneSelectedEntity.Node; var sketchNode = AutoGroupLogic.FindSketchNode(selNode); _cutNode = new NodeBuilder(document, FunctionNames.Cut); _cutNode[0].Reference = sketchNode; cutTypeComboBox.Items.Add(CutThroughAll); cutTypeComboBox.Items.Add(CutToDepth); cutTypeComboBox.SelectedIndex = 0; CutDepth = 100; UpdateView(); }
protected override bool ApplyFunction() { var builder = new NodeBuilder(Document, FunctionNames.Revolve); var sketchNode = AutoGroupLogic.FindSketchNode(FirstShape); Node node = FirstShape; if (sketchNode != null) { if (sketchNode.Children[2].Get <MeshTopoShapeInterpreter>() == null) { var tempFace = AutoGroupLogic.RebuildSketchFace(sketchNode, Document); if (tempFace != null) { sketchNode.Children[2].Set <MeshTopoShapeInterpreter>().Shape = tempFace; NodeUtils.SetSketchTransparency(Document, sketchNode, ObjectVisibility.Hidden); sketchNode.Set <DrawingAttributesInterpreter>().Transparency = 1; sketchNode.Set <DrawingAttributesInterpreter>().Visibility = ObjectVisibility.Hidden; Document.Commit("Sketch face generated"); node = sketchNode; } } else { node = sketchNode; } } builder[0].Reference = node; builder[1].Reference = SecondShape; builder[2].Real = 360.0; if (builder.ExecuteFunction()) { AddNodeToTree(builder.Node); if (node == sketchNode) { NodeUtils.SetSketchTransparency(Document, sketchNode, ObjectVisibility.Hidden); } return(true); } return(false); }
public static void AddArrayPatternNodes(Document document, int axis, int columnAxis, int shape, int rows, int columns, int rowDistance, int colDistance) { var indexColomns = 1; var node = document.Root[shape]; var axisNode = document.Root[axis]; var _axis = GeomUtils.ExtractAxis(new NodeBuilder(axisNode).Shape); var columnAxisNode = document.Root[columnAxis]; var _ColumnAxis = GeomUtils.ExtractAxis(new NodeBuilder(columnAxisNode).Shape); var reverseRows = 1; var reverseColumns = 1; for (var indexRows = 0; indexRows < rows; indexRows++) { for (; indexColomns < columns; indexColomns++) { var sourceCopyBuilder = new NodeBuilder(Document.CopyPaste(node)); sourceCopyBuilder.ShapeName = "Patterned" + sourceCopyBuilder.ShapeName.Substring(0, sourceCopyBuilder.ShapeName. Length - 1) + (indexRows * columns + indexColomns); sourceCopyBuilder.Node.Set <DrawingAttributesInterpreter>().Visibility = ObjectVisibility.ToBeDisplayed; var transformInterpreter = sourceCopyBuilder.Node.Get <TransformationInterpreter>(); transformInterpreter.ApplyGeneralArrayPattern(_axis, _ColumnAxis, indexRows * rowDistance * reverseRows, indexColomns * colDistance * reverseColumns); } indexColomns = 0; } var slectedNode = node; var sketchNode = AutoGroupLogic.FindSketchNode(slectedNode); NodeUtils.SetSketchTransparency(document, sketchNode, 0); var face = AutoGroupLogic.RebuildSketchFace(sketchNode, document); sketchNode.Children[2].Set <MeshTopoShapeInterpreter>().Shape = face; sketchNode.Set <DrawingAttributesInterpreter>().Transparency = 1; sketchNode.Set <DrawingAttributesInterpreter>().Visibility = ObjectVisibility.Hidden; NodeUtils.SetSketchTransparency(document, sketchNode, 0); }
public void GetSketchNodeTest() { var document = TestUtils.DefaultsSetup(); document.Transact(); var sketchCreator = new SketchCreator(document, false); var sketchNode = sketchCreator.BuildSketchNode(); var line = TestUtils.Line(document, sketchNode, new Point3D(10, 10, 0), new Point3D(10, 0, 0)); Assert.IsTrue(line.LastExecute); var sketchCreator2 = new SketchCreator(document, false); var sketchNode2 = sketchCreator2.BuildSketchNode(); var circle = TestUtils.Circle(document, sketchNode2, new Point3D(0, 0, 0), 5); Assert.IsTrue(circle.ExecuteFunction()); var sphereBuilder = new NodeBuilder(document, FunctionNames.Sphere); sphereBuilder[0].TransformedPoint3D = new Point3D(10, 10, 0); sphereBuilder[1].Real = 3; Assert.IsTrue(sphereBuilder.ExecuteFunction()); var firstNode = new NodeBuilder(AutoGroupLogic.FindSketchNode(line.Node)); Assert.AreEqual(firstNode.FunctionName, FunctionNames.Sketch); Assert.AreEqual(firstNode.ShapeName, "Sketch-1"); var secondNode = new NodeBuilder(AutoGroupLogic.FindSketchNode(circle.Node)); Assert.AreEqual(secondNode.FunctionName, FunctionNames.Sketch); Assert.AreEqual(secondNode.ShapeName, "Sketch-2"); Assert.IsNull(AutoGroupLogic.FindSketchNode(sphereBuilder.Node)); }
private void UpdatePoints() { var root = this.Builder.Node.Root; var pointNodes = from node in root.ChildrenList let builder = new NodeBuilder(node) where builder.FunctionName == FunctionNames.Point let currentSketchNode = AutoGroupLogic.FindSketchNode(node) where currentSketchNode.Index == this.Builder.Node.Index select node; var points = pointNodes.ToList(); var sketchAx2 = new gpAx2 { Axis = NodeBuilderUtils.GetTransformedAxis(Builder) }; var sketchPlane = new gpPln(new gpAx3(sketchAx2)); foreach (var point in points) { var nb = new NodeBuilder(point); var current = nb[1].TransformedPoint3D; var projectedPlane = GeomUtils.ProjectPointOnPlane(current.GpPnt, sketchPlane, Precision.Confusion); nb[1].TransformedPoint3D = new Point3D(projectedPlane); nb.ExecuteFunction(); } }
protected override void OnMouseUpAction(Mouse3DPosition mouseData) { base.OnMouseUpAction(mouseData); if (_extrudeStages == ExtrudeStages.SelectSketch) { var entities = Inputs[InputNames.SelectionContainerPipe].GetData(NotificationNames.GetEntities).Get <List <SceneSelectedEntity> >(); if (entities.Count <= 0) { return; } _sketchNode = AutoGroupLogic.FindSketchNode(entities[0].Node); if (_sketchNode == null) { return; } if (_sketchNode.Children[2].Get <MeshTopoShapeInterpreter>() == null) { // the sketch shape was not generated - this is the case when we open a file and perform extrude without any edits var tempFace = AutoGroupLogic.RebuildSketchFace(_sketchNode, Document); if (tempFace == null) { return; } _sketchNode.Children[2].Set <MeshTopoShapeInterpreter>().Shape = tempFace; NodeUtils.SetSketchTransparency(Document, _sketchNode, ObjectVisibility.Hidden); _sketchNode.Set <DrawingAttributesInterpreter>().Transparency = 1; _sketchNode.Set <DrawingAttributesInterpreter>().Visibility = ObjectVisibility.Hidden; Document.Commit("Sketch face generated"); } var face = _sketchNode.Children[2].Get <MeshTopoShapeInterpreter>().Shape; _shapePlane = GeomUtils.ExtractPlane(face); PreviewExtrude(false, mouseData); ResetWorkingPlane(); Inputs[InputNames.SelectionContainerPipe].Send(NotificationNames.Disable); _extrudeStages = ExtrudeStages.ExtrudeAnimation; } else if (_extrudeStages == ExtrudeStages.ExtrudeAnimation) { var sketchBuilder = new NodeBuilder(_sketchNode); var extrudeHeight = sketchBuilder[0].Axis3D.Location.Distance(mouseData.Point); if (extrudeHeight < 1e-12) { return; } PreviewExtrude(false, mouseData); NodeUtils.SetSketchTransparency(Document, _sketchNode, ObjectVisibility.Hidden); CommitFinal("Extrudes build"); Inputs[InputNames.FacePickerPlane].Send(NotificationNames.Resume); //Inputs[InputNames.SelectionContainerPipe].Send(NotificationNames.SwitchSelectionMode, // TopAbsShapeEnum.TopAbs_SOLID); RebuildTreeView(); UpdateView(); BackToNeutralModifier(); } }
public override bool Execute() { var axis = Dependency[1].ReferedShape; var angle = Dependency[2].Real / 180.0 * Math.PI; var revolvedNode = Dependency[0].ReferenceBuilder.Node; TopoDSShape originalShape = Dependency[0].ReferedShape; var sketchShapes = new List <Node>(); var nodesOnSketch = new List <Node>(); var sketchNode = NodeBuilderUtils.FindSketchNode(revolvedNode); var document = sketchNode.Root.Get <DocumentContextInterpreter>().Document; nodesOnSketch.AddRange(NodeUtils.GetSketchNodes(sketchNode, document, true)); if (revolvedNode.Get <FunctionInterpreter>().Name == FunctionNames.Sketch) { var face = revolvedNode.Children[2].Get <MeshTopoShapeInterpreter>().Shape; originalShape = AutoGroupLogic.RebuildFaces(face); } else { foreach (var node in nodesOnSketch) { if (node.Get <FunctionInterpreter>().Name != FunctionNames.Point && node.Index != Dependency[1].ReferenceBuilder.Node.Index) { sketchShapes.Add(node); } } } if (sketchShapes.Count > 0) { var shapes = new List <TopoDSShape>(); foreach (var node in sketchShapes) { var nb = new NodeBuilder(node); var tempShape = MakeRevolve(axis, nb.Shape, angle); if (tempShape != null) { shapes.Add(tempShape); } } TopoDSShape finalShape = null; if (shapes.Count > 0) { finalShape = shapes[0]; for (int i = 1; i < shapes.Count; i++) { if (shapes[i] == null) { continue; } var sew = new BRepBuilderAPISewing(1.0e-06, true, true, true, false); sew.Add(finalShape); sew.Add(shapes[i]); var messg = new MessageProgressIndicator(); sew.Perform(messg); finalShape = sew.SewedShape; } Shape = finalShape; foreach (var node in nodesOnSketch) { NodeUtils.Hide(node); } return(true); } } if (originalShape == null) { return(false); } Shape = MakeRevolve(axis, originalShape, angle); if (Shape == null) { return(false); } // Hide the referenece shape //NodeUtils.Hide(Dependency[0].Reference); foreach (var node in nodesOnSketch) { NodeUtils.Hide(node); } return(true); }