public static Node RotateNode(NodeBuilder nodeBuilder, Document document, gpAx1 axis, double angle) { if (FunctionNames.GetSolids().Contains(nodeBuilder.FunctionName)) { RotateSolids(nodeBuilder, axis, angle); return(null); } var sketchNode = nodeBuilder.Dependency[0].ReferenceBuilder.Node; var nodes = GetSketchNodes(sketchNode, document, true); foreach (var node in nodes) { var nb = new NodeBuilder(node); if (nb.FunctionName != FunctionNames.Point) { RotateSketchNode(nb, axis, angle); } //var transformInterpreter = node.Get<TransformationInterpreter>(); //transformInterpreter.RotateAroundAxis(axis, angle); //var nb1 = new NodeBuilder(node); //if (nb1.Node != null) // nb1.ExecuteFunction(); } return(sketchNode); }
private void SetRotateValue(object data) { BeginUpdate(); var nodeBuilder = new NodeBuilder(Parent); var mouseRotation = TransformationInterpreter.GetRotateTrsf((Point3D)data); var sketchNode = NodeBuilderUtils.FindBaseSketchNode(Parent); var document = sketchNode.Root.Get <DocumentContextInterpreter>().Document; if (!NodeUtils.NodeIsOnSketch(nodeBuilder)) { 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 shapeNodeBuilder = new NodeBuilder(node); if (FunctionNames.GetSolids().Contains(nodeBuilder.FunctionName)) { continue; } var affectedSketchNode = shapeNodeBuilder.Dependency[0].ReferenceBuilder.Node; if (affectedSketchNode != null) { var nb1 = new NodeBuilder(affectedSketchNode); if (nb1.Dependency[2].Reference == null) { sketchNodes.Add(affectedSketchNode); } } } document.Transact(); foreach (var solid in sketchNodes) { var nb = new NodeBuilder(solid); var trsfCurrent = nb.Node.Get <TransformationInterpreter>().CurrTransform; trsfCurrent = trsfCurrent.Multiplied(mouseRotation); // we need to invert the transformation to make it positive for the x-axis trsfCurrent = trsfCurrent.Inverted; var transformationInfo = new TransformationInfo { SketchIndex = solid.Index, Transformation = mouseRotation, TrsfIndex = TransformationInfo.maxTrsfIndex, RefSketchIndex = -2 }; TransformationInfo.maxTrsfIndex++; TransformationInterpreter.Transformations.Add(transformationInfo); nb.Node.Set <TransformationInterpreter>().CurrTransform = trsfCurrent; nb.ExecuteFunction(); } document.Commit("Rotated"); } EndVisualUpdate("Rotate object"); }
public static Node FindSketchNode(Node shapeNode) { if (shapeNode == null) { return(null); } var nodeBuilder = new NodeBuilder(shapeNode); var invalidShapes = new List <string> { string.Empty }; invalidShapes.AddRange(FunctionNames.GetSolids()); invalidShapes.Add(FunctionNames.VerticalLine); invalidShapes.Add(FunctionNames.HorizontalLine); invalidShapes.Add(FunctionNames.Spline); invalidShapes.Add(FunctionNames.SplinePath); invalidShapes.Add(FunctionNames.Face); invalidShapes.Add(FunctionNames.Plane); if (invalidShapes.Contains(nodeBuilder.FunctionName)) { return(null); } if (nodeBuilder.FunctionName == FunctionNames.Sketch) { return(shapeNode); } if (nodeBuilder.FunctionName == FunctionNames.Dimension) { var lineBuilder = nodeBuilder[0].ReferenceBuilder; var pointBuilder1 = lineBuilder[0].ReferenceBuilder; return(pointBuilder1[0].Reference); } if (nodeBuilder.FunctionName == FunctionNames.LineHints) { return(FindSketchNode(nodeBuilder[0].Reference)); } if (nodeBuilder.FunctionName == FunctionNames.Trim || nodeBuilder.FunctionName == FunctionNames.Fillet2D) { return(FindSketchNode(nodeBuilder[0].ReferenceList[0].Node)); } var pointBuilder = nodeBuilder[0].ReferenceBuilder; if (pointBuilder == null) { return(null); } if (pointBuilder.FunctionName == FunctionNames.Sketch) { return(pointBuilder.Node); } var sketchNode = pointBuilder[0].Reference; return(sketchNode); }
public static List <Node> GetSolidsNodes(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 FunctionNames.GetSolids().Contains(builder.FunctionName) select node); } return(results); }
public string GetNextIndexName(string shapeName) { if (!FunctionNames.GetSketchShapes().Contains(shapeName) && !FunctionNames.GetSolids().Contains(shapeName) && shapeName != FunctionNames.Sketch) { return(shapeName); } if (!Indexes.ContainsKey(shapeName)) { Indexes[shapeName] = 1; } else { if (!Freeze) { Indexes[shapeName]++; } } return(shapeName + "-" + Indexes[shapeName]); }
public static bool NodeIsOnSketch(NodeBuilder nodeBuilder) { var solids = new List <string>() { FunctionNames.Extrude, FunctionNames.Cut, FunctionNames.Boolean, FunctionNames.Fillet }; solids.AddRange(FunctionNames.GetSolids()); bool isOnSketch = !solids.Contains(nodeBuilder.FunctionName); if (!isOnSketch) { if (nodeBuilder.Shape.ShapeType == TopAbsShapeEnum.TopAbs_WIRE || nodeBuilder.Shape.ShapeType == TopAbsShapeEnum.TopAbs_VERTEX) { isOnSketch = true; } } return(isOnSketch); }
public void DisplayHandle(int handleIndex, Document editingDocument) { var handleType = GetHandleTypeAtIndex(handleIndex); var handleOrientation = GetPointLocation(handleIndex); if (handleOrientation == null) { return; } var length = CoreGlobalPreferencesSingleton.Instance.ZoomLevel; var height = 0.3; if (handleType == FunctionNames.AxisHandle) { var solids = new List <string>(); solids.AddRange(FunctionNames.GetSolids()); solids.Add(FunctionNames.Extrude); solids.Add(FunctionNames.Cut); if (Node.Get <FunctionInterpreter>() != null && solids.Contains(Node.Get <FunctionInterpreter>().Name)) { length *= 10; } else { height /= 10; } } var nodeBuilder = new NodeBuilder(editingDocument, handleType); nodeBuilder[0].Axis3D = new Axis(handleOrientation.Axis); nodeBuilder[1].Axis3D = new Axis(new gpAx1(handleOrientation.Location, handleOrientation.XDirection)); nodeBuilder[2].Real = length; nodeBuilder[3].Real = height; nodeBuilder.Node.Set <TransformationInterpreter>().Translate = new gpPnt(); nodeBuilder.Color = GetHandleColor(handleIndex); if (nodeBuilder.ExecuteFunction()) { _handles[nodeBuilder.Node] = handleIndex; } }
public static void Translate3DNode(NodeBuilder nodeBuilder, Document document, Point3D translateValue)//, Point3D oldValue) { { var list = NodeBuilderUtils.GetAllContained3DNodesIndexes(nodeBuilder.Node).Distinct().ToList(); var sketchNodes = new List <Node>(); //find if we are translating a stack of solids and if so, find the base solid foreach (var nodeIndex in list) { var node = document.Root[nodeIndex.Key]; var shapeNodeBuilder = new NodeBuilder(node); if (FunctionNames.GetSolids().Contains(nodeBuilder.FunctionName)) { continue; } var affectedSketchNode = shapeNodeBuilder.Dependency[0].ReferenceBuilder.Node; if (affectedSketchNode != null) { var nb1 = new NodeBuilder(affectedSketchNode); if (nb1.Dependency[2].Reference == null) { sketchNodes.Add(affectedSketchNode); } } } // if there are no stacked solids, find the base sketch for the solid we need to translate if (sketchNodes.Count == 0) { foreach (var nodeIndex in list) { var node = document.Root[nodeIndex.Key]; var shapeNodeBuilder = new NodeBuilder(node); if (FunctionNames.GetSolids().Contains(nodeBuilder.FunctionName)) { continue; } var affectedSketchNode = shapeNodeBuilder.Dependency[0].ReferenceBuilder.Node; if (affectedSketchNode != null) { sketchNodes.Add(affectedSketchNode); } } } if (sketchNodes.Count == 0) { return; } // use increments to avoid Cut occ bug foreach (var sketchNode in sketchNodes) { sketchNode.Set <DrawingAttributesInterpreter>().Disable(); var currentLocation = NodeBuilderUtils.GetTransformedAxis(new NodeBuilder(sketchNode)).Location; var currentValue = translateValue; while (Math.Abs(currentValue.X) > Precision.Confusion || Math.Abs(currentValue.Y) > Precision.Confusion || Math.Abs(currentValue.Z) > Precision.Confusion) { var currentTranslate = new Point3D(0, 0, 0); if (Math.Abs(currentValue.X) > 0) { if (Math.Abs(currentValue.X) < 10) { currentTranslate.X = currentValue.X; } else { currentTranslate.X = 10 * Math.Sign(currentValue.X); } currentValue.X -= currentTranslate.X; } if (Math.Abs(currentValue.Y) > 0) { if (Math.Abs(currentValue.Y) < 10) { currentTranslate.Y = currentValue.Y; } else { currentTranslate.Y = 10 * Math.Sign(currentValue.Y); } currentValue.Y -= currentTranslate.Y; } if (Math.Abs(currentValue.Z) > 0) { if (Math.Abs(currentValue.Z) < 10) { currentTranslate.Z = currentValue.Z; } else { currentTranslate.Z = 10 * Math.Sign(currentValue.Z); } currentValue.Z -= currentTranslate.Z; } ApplyTranslate(currentLocation, currentTranslate, sketchNode); } sketchNode.Set <DrawingAttributesInterpreter>().Enable(); } } }
/// <summary> /// A new sketch is created: if the user clicked on the face of a solid, that face's normal is used as axis for the new sketch, otherwise /// the default axis with position (0,0,0) and direction (0,0,1) is used. /// </summary> /// <param name="mouseData"></param> protected override void OnMouseDownAction(Mouse3DPosition mouseData) { base.OnMouseDownAction(mouseData); Log.Info("StartSketch - OnMouseDownAction"); //var checkSketch = new SketchCreator(Document, false); //if (checkSketch.CurrentSketch != null) return; Log.Info("StartSketch - OnMouseDownAction - current sketch null"); var sketchCreator = new SketchCreator(Document); var currentSketch = sketchCreator.CurrentSketch; var sketchNodeBuilder = new NodeBuilder(currentSketch); Inputs[InputNames.SelectionContainerPipe].Send(NotificationNames.BuildSelections, mouseData); var entities = Inputs[InputNames.SelectionContainerPipe].GetData(NotificationNames.GetEntities).Get <List <SceneSelectedEntity> >(); var selectedFace = (SelectionInfo)Inputs[InputNames.Mouse3DEventsPipe].GetData(NotificationNames.GetFace).Data; Document.Transact(); var transformationInfo = new TransformationInfo(); transformationInfo.SketchIndex = sketchNodeBuilder.Node.Index; Log.InfoFormat("StartSketch - OnMouseDownAction - selected entities count {0}", entities.Count); var normalOnPlane = new Axis(new Point3D(0, 0, 0), new Point3D(0, 0, 1)).GpAxis; if (Inputs[InputNames.Mouse3DEventsPipe].GetData(NotificationNames.GetPlane).Data != null) { normalOnPlane.Location = ((gpPln)Inputs[InputNames.Mouse3DEventsPipe].GetData(NotificationNames.GetPlane).Data).Axis.Location; normalOnPlane.Direction = ((gpPln)Inputs[InputNames.Mouse3DEventsPipe].GetData(NotificationNames.GetPlane).Data).Axis.Direction; if (selectedFace != null) { var _3DShapesFunctions = new List <string>(); _3DShapesFunctions.AddRange(new[] { FunctionNames.Sphere, FunctionNames.Box, FunctionNames.Cylinder, FunctionNames.Torus, FunctionNames.Cone, FunctionNames.Plane }); var nb = new NodeBuilder(selectedFace.selectedNode); if (nb.FunctionName == string.Empty || _3DShapesFunctions.Contains(nb.FunctionName)) { transformationInfo.RefSketchIndex = -1; } else { transformationInfo.RefSketchIndex = nb.Dependency[0].Reference.Index; var faces = GeomUtils.ExtractFaces(nb.Shape); var face = faces[selectedFace.face]; var orientation = face.Orientation(); if (orientation == TopAbsOrientation.TopAbs_REVERSED) { normalOnPlane.Direction = normalOnPlane.Direction.Reversed; } } } else { transformationInfo.RefSketchIndex = -1; } } else { var plane = new gpPln(new gpAx3()); Inputs[InputNames.Mouse3DEventsPipe].Send(NotificationNames.SetPlane, plane); transformationInfo.RefSketchIndex = -1; } if (selectedFace != null) { var nb = new NodeBuilder(selectedFace.selectedNode); if (nb.FunctionName != FunctionNames.Plane) { sketchNodeBuilder[2].Reference = nb.Node; sketchNodeBuilder[3].Integer = selectedFace.face; } } _sketchButton.Block(); sketchNodeBuilder[0].TransformedAxis3D = new Axis(new Point3D(0, 0, 0), new Point3D(0, 0, 1)).GpAxis; var transformation = sketchNodeBuilder.Node.Set <TransformationInterpreter>(); if (selectedFace != null) { var solids = new List <string> { string.Empty }; solids.AddRange(FunctionNames.GetSolids()); if (solids.Contains(new NodeBuilder(selectedFace.selectedNode).FunctionName)) { var oldSystemAxis = new gpAx3(new gpPnt(0, 0, 0), new gpDir(0, 0, 1)); var newSystemAxis = new gpAx3(normalOnPlane.Location, normalOnPlane.Direction); gpTrsf T = new gpTrsf(); T.SetTransformation(oldSystemAxis, newSystemAxis); transformation.CurrTransform = T.Inverted; } else { var allTrsfs = NodeBuilderUtils.GetTransformedAxis( new NodeBuilder(selectedFace.selectedNode).Dependency[0].ReferenceBuilder); gpTrsf T = new gpTrsf(); var oldSystemAxis = new gpAx3(new gpPnt(0, 0, 0), new gpDir(0, 0, 1)); // var oldSystemAxis = new gpAx3(allTrsfs.Location, allTrsfs.Direction); normalOnPlane.Direction = NodeBuilderUtils.RoundToPrecision(normalOnPlane.Direction); var newSystemAxis = new gpAx3(normalOnPlane.Location, normalOnPlane.Direction); // T.SetDisplacement(oldSystemAxis, newSystemAxis); T.SetTransformation(oldSystemAxis, newSystemAxis); transformation.CurrTransform = T.Inverted; } transformationInfo.Transformation = transformation.CurrTransform; } else { transformation.TranslateWith(new Point3D(normalOnPlane.Location)); transformationInfo.Transformation = transformation.CurrTransform; } transformationInfo.TrsfIndex = TransformationInfo.maxTrsfIndex; TransformationInfo.maxTrsfIndex++; TransformationInterpreter.Transformations.Add(transformationInfo); sketchNodeBuilder.ExecuteFunction(); AddNodeToTree(sketchNodeBuilder.Node); NodeBuilderUtils.HidePlanes(Document); HighlightCurrentSketchNodes(sketchNodeBuilder.Node); Document.Commit("sketch created"); BackToNeutralModifier(); }