Exemple #1
0
        public void ColorFromLayer()
        {
            var ctx = Context.Current;

            ctx.Layers.ActiveLayer.Color = new Color(1, 0, 0);

            var plane = DatumPlane.Create();

            Assert.AreEqual("DatumPlane_1", plane.Name);
            ctx.Document.Add(plane);
            ctx.ViewportController.ZoomFitAll();

            Assert.Multiple(() =>
            {
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "ColorFromLayer01"));

                ctx.Layers.ActiveLayer.Color = new Color(0, 1, 0);
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "ColorFromLayer02"));

                var layer = new Layer()
                {
                    Color = new Color(0, 0, 1)
                };
                ctx.Layers.Add(layer);
                plane.Layer = layer;
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "ColorFromLayer03"));
            });
        }
Exemple #2
0
        public void Transform()
        {
            var ctx = Context.Current;

            var plane = DatumPlane.Create();

            ctx.Document.Add(plane);

            ctx.ViewportController.ZoomFitAll();

            Assert.Multiple(() =>
            {
                ctx.ClickAt(300, 300);
                Assert.That(ctx.WorkspaceController.Selection.SelectedEntities.SequenceEqual(new[] { plane }));
                Assert.That(WorkspaceCommands.Transform.CanExecute());
                WorkspaceCommands.Transform.Execute();
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "Transform01"));

                ctx.MoveTo(219, 267);
                ctx.ViewportController.MouseDown();
                ctx.MoveTo(151, 313);
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "Transform02")); // AIS local transformation working

                ctx.ViewportController.MouseUp(false);
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "Transform03")); // Updating transformation working
            });
        }
Exemple #3
0
        public void Create()
        {
            var ctx = Context.Current;

            var plane = DatumPlane.Create();

            Assert.AreEqual("DatumPlane_1", plane.Name);
            ctx.Document.Add(plane);

            ctx.ViewportController.ZoomFitAll();
            AssertHelper.IsSameViewport(Path.Combine(_BasePath, "Create01"));
        }
Exemple #4
0
        public void CreateWithImage()
        {
            var ctx = Context.Current;

            var imagePlane = DatumPlane.Create();

            imagePlane.ImageFilePath = _SourceImagePath;
            ctx.Document.Add(imagePlane);

            ctx.ViewportController.ZoomFitAll();
            AssertHelper.IsSameViewport(Path.Combine(_BasePath, "CreateWithImage01"));
        }
Exemple #5
0
        public static void AnnotateFace(Part targetPart, DesignFace face, string comment, double textHeight, Direction?direction)
        {
            string annotationPlanePartName = "Annotation Planes";
            Part   part = null;

            foreach (Part testPart in targetPart.Document.Parts)
            {
                if (testPart.Name == annotationPlanePartName)
                {
                    part = testPart;
                }
            }

            if (part == null)
            {
                part = Part.Create(targetPart.Document, annotationPlanePartName);
                Component component = Component.Create(targetPart, part);
            }

            Plane plane = GetPlaneCenteredOnFace(face);

            if (direction != null)
            {
                Direction dirX = Direction.DirX;
                if (direction.Value != Direction.DirZ)
                {
                    dirX = direction.Value.ArbitraryPerpendicular;
                }

                plane = Plane.Create(Frame.Create(plane.Frame.Origin, dirX, Direction.Cross(direction.Value, dirX)));
            }

            Layer planeLayer = CreateOrGetLayer(targetPart.Document, Resources.AnnotationPlaneLayerNameText, System.Drawing.Color.Black);

            planeLayer.SetVisible(null, false);
            Layer noteLayer = CreateOrGetLayer(targetPart.Document, Resources.AnnotationLayerNameText, System.Drawing.Color.DarkRed);

            DatumPlane datum = DatumPlane.Create(part, Resources.AnnotationPlaneNameText, plane);

            datum.Layer = planeLayer;

            PointUV location = PointUV.Origin;
            Note    note     = Note.Create(datum, location, TextPoint.Center, textHeight, comment);

            note.SetFontName(DraftingFont.Asme);
            note.Layer = noteLayer;
            note.SetColor(null, null);
        }
Exemple #6
0
        public void Clone()
        {
            var ctx = Context.Current;

            ctx.Workspace.GridEnabled = true;
            ctx.Workspace.GridStep    = 15.0;

            var datumPlane = DatumPlane.Create();

            datumPlane.Position = new Pnt(5, 10, 10);
            ctx.Document.Add(datumPlane);
            ctx.WorkspaceController.Selection.SelectEntity(datumPlane);

            Assert.IsTrue(WorkspaceCommands.DuplicateEntity.CanExecute());
            WorkspaceCommands.DuplicateEntity.Execute();
            Assert.AreEqual(2, ctx.Document.Cast <DatumPlane>().Count());
        }
        protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect)
        {
            //isDetectingCollisions = Booleans[Resources.DetectCollisionsText].Value;
            //isCreatingDashes = Booleans[Resources.CreateDashesText].Value;

            Part part = Window.ActiveWindow.Scene as Part;

            if (part == null)
            {
                return;
            }

            Layer curveLayer = NoteHelper.CreateOrGetLayer(Window.ActiveWindow.Document, Resources.FlatMediumEngravingLayerName, System.Drawing.Color.Green);
            Layer planeLayer = NoteHelper.CreateOrGetLayer(part.Document, Resources.AnnotationPlanesLayerName, Color.Gray);

            planeLayer.SetVisible(null, false);
            foreach (Component component in part.Components)
            {
                Body body = component.Content.Bodies.First().Master.Shape.Copy();
                body.Transform(component.Content.TransformToMaster.Inverse);
                Face startFace = body.Faces.First();

                string      name        = component.Content.Master.Name;
                FlatPattern flatPattern = new FlatPattern(body, startFace, isDetectingCollisions, false, 0, 0, name);
                flatPattern.Render();

                DatumPlane datumPlane = DatumPlane.Create(flatPattern.FlatPart, Resources.AnnotationPlaneName, flatPattern.PaperPlane);
                datumPlane.Layer = planeLayer;
                PointUV center = flatPattern.PaperPlane.ProjectPoint(flatPattern.GetBoundingBox(Matrix.Identity).Center).Param;
                Note    note   = Note.Create(datumPlane, center, TextPoint.Center, 0.01, name);
                note.Layer = NoteHelper.CreateOrGetLayer(part.Document, Resources.AnnotationLayerName, System.Drawing.Color.DarkViolet);

                foreach (FlatBody flatBody in flatPattern.FlatBodies)
                {
                    foreach (FlatFace flatFace in flatBody.FlatFaces)
                    {
                        foreach (ITrimmedCurve iTrimmedCurve in part.Curves.Select(c => c.Shape).Where(c => c.AreEndPointsOnFace(flatFace.SourceFace)))
                        {
                            var designCurve = DesignCurve.Create(flatBody.FlatPart, iTrimmedCurve);
                            designCurve.Transform(flatFace.Transform);
                            designCurve.Layer = curveLayer;
                        }
                    }
                }
            }
        }
Exemple #8
0
        public void CreateOnDatumPlane()
        {
            var ctx = Context.Current;

            ctx.Workspace.GridEnabled = true;
            ctx.Workspace.GridStep    = 15.0;

            var datumPlane = DatumPlane.Create();

            datumPlane.Position = new Pnt(5, 10, 10);
            ctx.Document.Add(datumPlane);
            ctx.ViewportController.ZoomFitAll();

            ctx.WorkspaceController.StartTool(new CreateSketchTool(CreateSketchTool.CreateMode.Interactive));
            ctx.ClickAt(300, 300);
            var sketchEditTool = ctx.WorkspaceController.CurrentTool as SketchEditorTool;

            Assert.NotNull(sketchEditTool);
            Assert.AreEqual(sketchEditTool.Sketch.Body.Position, datumPlane.Position);
        }
Exemple #9
0
        public void Select()
        {
            var ctx = Context.Current;

            var datumPlane = DatumPlane.Create();

            ctx.Document.Add(datumPlane);

            Assert.Multiple(() =>
            {
                ctx.ViewportController.ZoomFitAll();
                ctx.MoveTo(300, 300);
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "Select01"));

                ctx.ClickAt(300, 300);
                Assert.That(ctx.WorkspaceController.Selection.SelectedEntities.SequenceEqual(new[] { datumPlane }));
                ctx.MoveTo(1, 1);
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "Select02"));
            });
        }
Exemple #10
0
        public void SelectAsWorkingPlane()
        {
            var ctx = Context.Current;

            ctx.Workspace.GridEnabled = true;
            ctx.Workspace.GridStep    = 15.0;

            var datumPlane = DatumPlane.Create();

            datumPlane.Position = new Pnt(5, 10, 10);
            ctx.Document.Add(datumPlane);
            ctx.ViewportController.ZoomFitAll();

            Assert.Multiple(() =>
            {
                WorkspaceCommands.AlignWorkingPlane.Execute();
                ctx.ClickAt(300, 300);
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "SelectAsWorkingPlane01"));
            });
        }
Exemple #11
0
        public void SelectInSelectionContext()
        {
            var ctx = Context.Current;

            var datumPlane = DatumPlane.Create();

            ctx.Document.Add(datumPlane);
            ctx.ViewportController.ZoomFitAll();

            Assert.Multiple(() =>
            {
                var selCtx = ctx.WorkspaceController.Selection.OpenContext(SelectionContext.Options.IncludeAll);
                ctx.ClickAt(300, 300);
                Assert.That(ctx.WorkspaceController.Selection.SelectedEntities.SequenceEqual(new[] { datumPlane }));

                ctx.WorkspaceController.Selection.CloseContext(selCtx);
                ctx.WorkspaceController.Selection.SelectEntity(null);
                ctx.ClickAt(300, 300);
                Assert.That(ctx.WorkspaceController.Selection.SelectedEntities.SequenceEqual(new[] { datumPlane }));
            });
        }
Exemple #12
0
        public void IsolateSelection()
        {
            var ctx = Context.Current;

            var datumPlane = DatumPlane.Create();

            ctx.Document.Add(datumPlane);
            ctx.ViewportController.ZoomFitAll();
            var body1 = TestData.GetBodyFromBRep(@"SourceData\BRep\ImprintRingFace.brep");

            Assert.Multiple(() =>
            {
                ctx.WorkspaceController.Selection.SelectEntity(body1);
                WorkspaceCommands.ToggleIsolateSelection.Execute();
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "IsolateSelection01"));
                WorkspaceCommands.ToggleIsolateSelection.Execute();

                ctx.WorkspaceController.Selection.SelectEntity(datumPlane);
                WorkspaceCommands.ToggleIsolateSelection.Execute();
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "IsolateSelection02"));
            });
        }
Exemple #13
0
        public void HideWithLayer()
        {
            var ctx = Context.Current;

            var datumPlane = DatumPlane.Create();

            ctx.Document.Add(datumPlane);
            ctx.ViewportController.ZoomFitAll();

            Assert.Multiple(() =>
            {
                ctx.Document.Layers.ActiveLayer.IsVisible = false;
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "HideWithLayer01"));
                ctx.ClickAt(300, 300);
                Assert.AreEqual(0, ctx.WorkspaceController.Selection.SelectedEntities.Count);

                ctx.Document.Layers.ActiveLayer.IsVisible = true;
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "HideWithLayer02"));
                ctx.ClickAt(300, 300);
                Assert.AreEqual(1, ctx.WorkspaceController.Selection.SelectedEntities.Count);
            });
        }
Exemple #14
0
        private static void c_Executing(object sender, CommandExecutingEventArgs e)
        {
            Window aw = Window.ActiveWindow;

            // section plane. It is not null only if sketch or section mode is on.
            Plane sP = aw.ActiveContext.SectionPlane;

            if (sP != null)
            {
                int sw = aw.Size.Width;
                int sh = aw.Size.Height;
                // get screen center, right-mid and upper mid
                System.Drawing.Point sm = new System.Drawing.Point((int)Math.Round(sw * 0.5), (int)Math.Round(sh * 0.5));
                System.Drawing.Point sr = new System.Drawing.Point(sw, sm.Y);
                System.Drawing.Point su = new System.Drawing.Point(sm.X, 1);
                // screen center projection onto section plane in model coordinates
                Point mm;
                if (sP.TryIntersectLine(aw.ActiveContext.GetCursorRay(sm), out mm))
                {
                    // get projections of right mid and upper mid and use these projections
                    // to define bas vectors.
                    Point mr, mu;
                    sP.TryIntersectLine(aw.ActiveContext.GetCursorRay(sr), out mr);
                    sP.TryIntersectLine(aw.ActiveContext.GetCursorRay(su), out mu);
                    Vector bx  = mr - mm;
                    Vector bz  = Vector.Cross(bx, mu - mm); // normal to section plane looking to us
                    Vector by  = Vector.Cross(bz, bx);
                    double ext = bx.Magnitude;
                    // rotate view to look perpendicular to section plane
                    double fe = ext * Math.Min(sw, sh) / Math.Max(sw, sh) * 2;
                    aw.SetProjection(Frame.Create(mm, bx.Direction, by.Direction), fe);

                    // generate string for clipboard
                    string f3 = " {0:G5} {1:G5} {2:G5} ";
                    string f1 = " {0:G5} ";
                    string pc = "";

                    // or command
                    pc  = "or";
                    pc += string.Format(f3, nullify(mm.X * cc), nullify(mm.Y * cc), nullify(mm.Z * cc));
                    // bas command
                    bx  = bx.Direction.UnitVector;
                    by  = by.Direction.UnitVector;
                    pc += "bas";
                    pc += string.Format(f3, nullify(bx.X), nullify(bx.Y), nullify(bx.Z));
                    pc += string.Format(f3, nullify(by.X), nullify(by.Y), nullify(by.Z));
                    // ext command
                    pc += "ext";
                    pc += string.Format(f1, ext * cc);

                    // tune formatting
                    pc = pc.Replace(",", ".");
                    pc = pc.Replace("E+000", " ");
                    pc = pc.Replace("E-000", " ");
                    pc = pc.Replace("E+00", "E+");
                    pc = pc.Replace("E-00", "E-");
                    pc = pc.Replace("E+0", "E+");
                    pc = pc.Replace("E-0", "E-");

                    // put to clipboard
                    ClipBoard.SetText(pc);
                }
                else
                {
                    SpaceClaim.Api.V16.Application.ReportStatus("Section plane exists but cannot intersect with cursor ray", StatusMessageType.Information, null);
                }
            }
            else
            {
                // try to read plot commands from clipboard
                Frame  fr;
                double ext;
                if (TryParseClipboard(out fr, out ext))
                {
                    // If clipboard parsed, add a new plane to the model
                    DatumPlane.Create(aw.Document.MainPart, "MCNP plot plane", Plane.Create(fr));
                }
                else
                {
                    SpaceClaim.Api.V16.Application.ReportStatus("Clipboard does not contain MCNP plot commands.", StatusMessageType.Warning, null);
                }
            }
        }
Exemple #15
0
 public static void Print(this Plane plane, Part part = null)
 {
     DatumPlane.Create(part ?? MainPart, GetDebugString(plane), plane);
 }
        protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect)
        {
            base.OnExecute(command, context, buttonRect);

            List <ITrimmedCurve> trimmedCurves = new List <ITrimmedCurve>();

            foreach (ITrimmedCurve trimmedCurve in activeWindow.GetAllSelectedITrimmedCurves())
            {
                trimmedCurves.Add(trimmedCurve);
            }

            TrimmedCurveChain curveChain = new TrimmedCurveChain(trimmedCurves);
            double            length     = curveChain.Length;

            int count = (int)Math.Floor(length / dashMinSize / 2) * 2;

            if (curveChain.StartPoint != curveChain.EndPoint)             // odd number when not closed curve
            {
                count++;
            }

            List <DesignCurve> dashes    = new List <DesignCurve>();
            double             lastParam = curveChain.Bounds.Start;
            Point lastPoint;

            Debug.Assert(curveChain.TryGetPointAlongCurve(lastParam, out lastPoint));
            for (int i = 0; i < count; i++)
            {
                Point point;
                if (curveChain.TryGetPointAlongCurve(lastParam -= length / count, out point))
                {
                    if (i % 2 == 1)
                    {
                        DesignCurve dash = DesignCurve.Create(part, CurveSegment.Create(lastPoint, point));
                        dash.Layer = dashLayer;
                        dashes.Add(dash);
                    }
#if false // tori
                    ShapeHelper.CreateTorus(
                        new Point[] { point, lastPoint }.Average(),
                        (point - lastPoint).Direction,
                        0.188 * inches,
                        0.75 * inches,
                        part
                        );
#endif
                    lastPoint = point;
                }
            }
#if false // cylinders
            for (int i = 1; i < count; i++)
            {
                CurveEvaluation eval = dashes[i].Shape.Geometry.Evaluate(dashes[i].Shape.Bounds.Start);
                Direction       dir1 = eval.Tangent;

                eval = dashes[i - 1].Shape.Geometry.Evaluate(dashes[i - 1].Shape.Bounds.End);
                Direction dir2 = eval.Tangent;

                if (dir1 == dir2)
                {
                    DatumPlane.Create(part, "miter parallel", Plane.Create(Frame.Create(eval.Point, eval.Tangent.ArbitraryPerpendicular, Direction.Cross(eval.Tangent.ArbitraryPerpendicular, eval.Tangent))));
                    continue;
                }

                Direction averageDir = (dir1.UnitVector + dir2.UnitVector).Direction;
                Direction xDir       = Direction.Cross(averageDir, dir1);
                //	DatumPlane.Create(part, "miter", Plane.Create(Frame.Create(eval.Point, xDir, Direction.Cross(xDir, averageDir))));
                double offset = 0.0001 / 2;
                ShapeHelper.CreateCylinder(eval.Point + averageDir * offset, eval.Point - averageDir * offset, 7 * inches, part);
            }
#endif
        }