コード例 #1
0
        protected override NewPrimitive ConvertCore(SnappedSphere snapped)
        {
            var result = new NewSphere();

            result.Center.Value = snapped.CenterResult;
            result.Radius.Value = snapped.RadiusResult;
            return(result);
        }
コード例 #2
0
        public void Init(NewSphere newSphere)
        {
            Contract.Requires(newSphere != null);
            Contract.Requires(newSphere.Radius > 0);

            Model = model = newSphere;
            UpdateFromModel();
        }
コード例 #3
0
 public NewSphereViewModel(
     UiState uiState = null,
     ICurveAssigner curveAssigner     = null,
     IEventAggregator eventAggregator = null,
     IConstrainedOptimizer optimizer  = null)
     : base(uiState, curveAssigner, eventAggregator, optimizer)
 {
     radius             = 0.1;
     model              = new NewSphere();
     model.Radius.Value = radius;
 }
コード例 #4
0
        private Visual3D CreateSphereView(NewSphere sphereData)
        {
            Contract.Requires(sphereData != null);
            Contract.Ensures(Contract.Result <Visual3D>() != null);

            var sphere = new Sphere();

            sphere.Bind(Sphere.CenterProperty, () => sphereData.Center, center => center.Value);
            sphere.Bind(Sphere.RadiusProperty, () => sphereData.Radius, radius => radius.Value);

            sphere.Material = new DiffuseMaterial {
                Brush = Brushes.White
            };

            return(sphere);
        }
コード例 #5
0
        public NewPrimitive AddNewPrimitive(PrimitiveKinds primitiveKind, LineRange lineRange)
        {
            var pos3d = uiState.SketchPlane.PointFromRay(lineRange);

            if (pos3d != null)
            {
                undoHistory.Push();
                switch (primitiveKind)
                {
                case PrimitiveKinds.Cylinder:
                    var newCylinder = new NewCylinder();
                    newCylinder.Center.Value   = pos3d.Value;
                    newCylinder.Axis.Value     = sketchPlane.YAxis;
                    newCylinder.Diameter.Value = 0.2;
                    newCylinder.Length.Value   = 0.3;
                    sessionData.NewPrimitives.Add(newCylinder);
                    break;

                case PrimitiveKinds.Cone:
                    var newCone = new NewCone();
                    newCone.Center.Value       = pos3d.Value;
                    newCone.Axis.Value         = sketchPlane.YAxis;
                    newCone.TopRadius.Value    = 0.1;
                    newCone.BottomRadius.Value = 0.2;
                    newCone.Length.Value       = 0.3;
                    sessionData.NewPrimitives.Add(newCone);
                    break;

                case PrimitiveKinds.Sphere:
                    var newSphere = new NewSphere();
                    newSphere.Center.Value = pos3d.Value;
                    newSphere.Radius.Value = 0.2;
                    sessionData.NewPrimitives.Add(newSphere);
                    break;

                case PrimitiveKinds.SGC:
                    var newSGC = new NewStraightGenCylinder();
                    newSGC.Center.Value = pos3d.Value;
                    newSGC.Axis.Value   = sketchPlane.YAxis;
                    newSGC.Length.Value = 0.3;
                    newSGC.Components   = SgcComponents.CreateNonLinear(20, 0.075, 0.05, 0.1);
                    sessionData.NewPrimitives.Add(newSGC);
                    break;

                case PrimitiveKinds.BGC:
                    var newBGC = new NewBendedGenCylinder();
                    newBGC.Center.Value = pos3d.Value;
                    newBGC.Axis.Value   = sketchPlane.YAxis;
                    newBGC.Length.Value = 0.3;
                    newBGC.Components   = BgcComponents.Create(20, 0.075, 0.15, newBGC.Center.Value, newBGC.Axis.Value, newBGC.Length.Value);
                    sessionData.NewPrimitives.Add(newBGC);
                    break;

                case PrimitiveKinds.Cuboid:
                    var      newCuboid = new NewCuboid();
                    Vector3D H         = new Vector3D(0, 1, 0);
                    Vector3D W         = new Vector3D(1, 0, 0);
                    Vector3D D         = new Vector3D(0, 0, -1);
                    newCuboid.Center.Value = pos3d.Value;
                    newCuboid.H.Value      = H;
                    newCuboid.W.Value      = W;
                    newCuboid.D.Value      = D;
                    newCuboid.Width.Value  = 0.3;
                    newCuboid.Height.Value = 0.3;
                    newCuboid.Depth.Value  = 0.3;
                    sessionData.NewPrimitives.Add(newCuboid);
                    break;

                default:
                    Trace.Fail("Invalid primitive kind");
                    break;
                }
                sessionData.NewPrimitives.Last().UpdateCurvesGeometry();
                return(sessionData.NewPrimitives.Last());
            }
            else
            {
                return(null);
            }
        }