示例#1
0
        //--------------------------------------------------------------------------------------------------


        public BodyShapeTreeBody(BodyShapeOperand bodyOperand, BodyShapeTreeItem parent, ObservableCollection <BodyShapeTreeItem> currentList)
            : base(parent)
        {
            BodyOperand = bodyOperand;
            if (parent == null)
            {
                // Are we operand 0?
                var supposedParent      = currentList.LastOrDefault();
                var supposedParentShape = (supposedParent as BodyShapeTreeShape)?.Shape as ModifierBase;
                if (supposedParentShape?.Operands.FirstOrDefault() == bodyOperand)
                {
                    ParentShape = supposedParentShape;
                }
            }
            else
            {
                ParentShape = (parent as BodyShapeTreeShape)?.Shape as ModifierBase;
            }

            // Set inactive, if
            // - the parent was not active
            // - the last sibling was not active
            if ((parent == null || parent.IsInactive) &&
                (!currentList.Any() || currentList.Last().IsInactive))
            {
                IsInactive = true;
            }

            currentList.Add(this);
        }
        //--------------------------------------------------------------------------------------------------

        public override void OnDeserialized(SerializationContext context)
        {
            base.OnDeserialized(context);

            if (context.Scope == SerializationScope.CopyPaste && _UpdateAssociatedShape() != null)
            {
                // Check if the back reference is still valid
                if (_AssociatedShape.Guid != Guid)
                {
                    // Create Clone
                    var boxJoint2 = new BoxJoint();
                    boxJoint2.AddOperand(new BodyShapeOperand(Body, this));
                    boxJoint2.RemoveExcess    = _RemoveExcess;
                    boxJoint2.IsFirst         = !_IsFirst;
                    boxJoint2.ReverseOrder    = _ReverseOrder;
                    boxJoint2.Ratio           = 1.0 - _Ratio;
                    boxJoint2.CustomBoxRatios = _CustomBoxRatios;

                    _AssociatedShape.Body.AddShape(boxJoint2);
                    Operands[1] = new BodyShapeOperand(boxJoint2.Body, boxJoint2);

                    RaisePropertyChanged(nameof(BoxCount));
                    RaisePropertyChanged(nameof(ReverseOrder));
                    RaisePropertyChanged(nameof(Ratio));
                    RaisePropertyChanged(nameof(CustomBoxRatios));
                }
            }

            _UpdateAssociatedShape();
        }
示例#3
0
        //--------------------------------------------------------------------------------------------------

        public static (Body target, IShapeOperand[] operands) CreateBooleanBodies(bool bigsize)
        {
            var target = Body.Create(new Box()
            {
                DimensionX = 20,
                DimensionY = 20,
                DimensionZ = 10,
            });

            target.Position = new Pnt(-10, -10, 0);

            var operands = new IShapeOperand[2];
            var body     = Body.Create(new Cylinder()
            {
                Radius = bigsize ? 20 : 10,
                Height = 15
            });

            body.Position = new Pnt(10, 10, 0);
            operands[0]   = new BodyShapeOperand(body);

            body = Body.Create(new Sphere()
            {
                Radius = 15
            });
            body.Position = new Pnt(-10, -10, 0);
            operands[1]   = new BodyShapeOperand(body);

            return(target, operands);
        }
示例#4
0
    //--------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------


    #region Helper

    Body _CreateBodies(bool bigsize)
    {
        var target = Body.Create(new Box()
        {
            DimensionX = 20,
            DimensionY = 20,
            DimensionZ = 10,
        });

        target.Position = new Pnt(10, 10, 0);

        var operands = new IShapeOperand[2];
        var body     = Body.Create(new Cylinder()
        {
            Radius = bigsize ? 20 : 10,
            Height = 15
        });

        body.Position = new Pnt(0, 10, 0);
        operands[0]   = new BodyShapeOperand(body);

        body = Body.Create(new Sphere()
        {
            Radius = 15
        });
        body.Position = new Pnt(10, 10, 5);

        return(target);
    }
示例#5
0
        //--------------------------------------------------------------------------------------------------

        public void UpdateBodyOperand(BodyShapeOperand newOp)
        {
            if (newOp != BodyOperand)
            {
                BodyOperand = newOp;
                RaisePropertyChanged();
            }

            RaisePropertyChanged(nameof(ShapeDescription));
        }