Beispiel #1
0
 public static void AutoZoom(Viewport3D vp, StepViewTransform tran)
 {
     if (TooBig(vp))
     {
         while (TooBig(vp) && (tran.Zoom >= 0.1))
         {
             tran.AddToZoom(-0.1);
         }
         while (!TooBig(vp))
         {
             tran.AddToZoom(0.01);
         }
         if (tran.Zoom >= 0.01)
         {
             tran.AddToZoom(-0.01);
         }
     }
     else
     {
         while (!TooBig(vp))
         {
             tran.AddToZoom(0.1);
         }
         while (TooBig(vp))
         {
             tran.AddToZoom(-0.01);
         }
     }
 }
Beispiel #2
0
 public static StepViewTransform GetViewTransformFor(Step st)
 {
     if (!vts.ContainsKey(st))
     {
         StepViewTransform vt = new StepViewTransform(st, true);
         vts[st] = vt;
     }
     return(vts[st]);
 }
Beispiel #3
0
        private static Model3DGroup SetupView(Viewport3D vp, StepViewTransform vt)
        {
            Model3DGroup grp = new Model3DGroup();

            PerspectiveCamera myPCamera = new PerspectiveCamera();

            myPCamera.Position      = new Point3D(0, 0, 200);
            myPCamera.LookDirection = new Vector3D(0, 0, -1);
            myPCamera.UpDirection   = new Vector3D(0, 1, 0);
            myPCamera.FieldOfView   = 60;
            vp.Camera           = myPCamera;
            vp.Camera.Transform = vt.tran;

            grp.Children.Add(new AmbientLight(Color.FromArgb(0xff, 0x80, 0x80, 0x80)));

            DirectionalLight myDirectionalLight = new DirectionalLight();

            myDirectionalLight.Color     = Color.FromArgb(0xff, 0x80, 0x80, 0x80);
            myDirectionalLight.Direction = new Vector3D(0, 0, -1);
            myDirectionalLight.Transform = vt.tran;
            grp.Children.Add(myDirectionalLight);

            return(grp);
        }
Beispiel #4
0
        public void MakeView(Step st)
        {
            if (this.vp == null)
            {
                this.vp = new Viewport3D();
            }
            else
            {
                this.vp.Children.Clear();
            }

            if (this.bCloneTran)
            {
                this.tran = new StepViewTransform(st, false);
            }
            else
            {
                this.tran = StepViewTransform.GetViewTransformFor(st);
            }

            this.m3dgrp = SetupView(this.vp, this.tran);
            this.cs     = st.Result;

            ModelVisual3D myModelVisual3D = new ModelVisual3D();

            myModelVisual3D.Content = this.m3dgrp;
            this.vp.Children.Add(myModelVisual3D);

            if (this.bAnimate)
            {
                this.movers = new List <VectorTranslateTransform3D>();
            }
            else
            {
                this.movers = null;
            }

            this.bunch = st.GetBunch(this.bAnimate);

            this.models = new List <PartialModel>();

            List <Face> highlights;

            if (this.bShowHighlights)
            {
                highlights = st.GetHighlightedFacesForThisStep();
            }
            else
            {
                highlights = null;
            }

            if (this.bunch.notmoving != null)
            {
                foreach (TriBag bag in this.bunch.notmoving)
                {
                    MakeModels(bag, null, highlights);

                    if (this.bShowLines)
                    {
                        MakeLineVisual(bag.lines, null);
                    }
                    if (this.bShowFaceLabels)
                    {
                        foreach (Face f in st.facesToBeLabeled)
                        {
                            if (bag.solid == f.solid)
                            {
                                CreateFaceLabel(this.vp, f, null);
                            }
                        }
                    }
                }
            }

            if (this.bunch.moving != null)
            {
                TranslateTransform3D       ttmove = new TranslateTransform3D(0, 0, 0);
                VectorTranslateTransform3D vtt    = new VectorTranslateTransform3D(ttmove, this.bunch.vec, 0);
                this.movers.Add(vtt);

                foreach (TriBag bag in this.bunch.moving)
                {
                    MakeModels(bag, ttmove, highlights);

                    if (this.bShowLines)
                    {
                        MakeLineVisual(bag.lines, ttmove);
                    }

                    if (this.bShowFaceLabels)
                    {
                        foreach (Face f in st.facesToBeLabeled)
                        {
                            if (bag.solid == f.solid)
                            {
                                CreateFaceLabel(this.vp, f, ttmove);
                            }
                        }
                    }
                }
            }

            if (this.bShowAnnotations)
            {
                CreateAnnotations(st.annotations_PP);
            }

            if (this.bShowAxes)
            {
                CreateAxes();
            }

            foreach (PartialModel pm in this.models)
            {
                this.m3dgrp.Children.Add(pm.gm3d);
            }

            if (
                (this.width > 0) &&
                (this.height > 0)
                )
            {
                this.vp.Width  = this.width;
                this.vp.Height = this.height;
                this.vp.Measure(new Size(this.width, this.height));
                this.vp.Arrange(new Rect(0, 0, this.width, this.height));
                this.vp.UpdateLayout();

                wpfmisc.FixLines(this.vp);

                if (this.bAutoZoom)
                {
                    wpfmisc.AutoZoom(this.vp, this.tran);
                    wpfmisc.FixLines(this.vp);
                }

                if (this.bStaticLines)
                {
                    List <ScreenSpaceLines3D> remove = new List <ScreenSpaceLines3D>();
                    List <ModelVisual3D>      add    = new List <ModelVisual3D>();
                    foreach (ModelVisual3D mv3d in this.vp.Children)
                    {
                        if (mv3d is ScreenSpaceLines3D)
                        {
                            ScreenSpaceLines3D ss    = mv3d as ScreenSpaceLines3D;
                            ModelVisual3D      plain = new ModelVisual3D();
                            plain.Content = ss.Content;
                            add.Add(plain);
                            remove.Add(ss);
                        }
                    }
                    foreach (ModelVisual3D mv3d in add)
                    {
                        this.vp.Children.Add(mv3d);
                    }
                    foreach (ScreenSpaceLines3D ss in remove)
                    {
                        this.vp.Children.Remove(ss);
                    }
                }
            }
        }