Ejemplo n.º 1
0
        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");
        }
        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);
            }
        }
Ejemplo n.º 3
0
        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();
                }
            }
        }