示例#1
0
        protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect)
        {
            //isDetectingCollisions = Booleans[Resources.DetectCollisionsText].Value;
            isCreatingBreaks = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsCreatingBreakLines].IsEnabledCommandBoolean.Value;
            breakAngle       = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsCreatingBreakLines].Values[Resources.BreakLinesMinimumAngle].Value * Math.PI / 180;
            dashSize         = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsCreatingBreakLines].Values[Resources.BreakLinesDashSize].Value / ActiveWindow.Units.Length.ConversionFactor;
            if (!isCreatingBreaks)
            {
                breakAngle = 0;
                dashSize   = 0;
            }

            IDesignBody designBody = Window.ActiveWindow.ActiveContext.SingleSelection as IDesignBody;
            IDesignFace designFace = null;

            if (designBody == null)
            {
                designFace = Window.ActiveWindow.ActiveContext.SingleSelection as IDesignFace;
                if (designFace != null)
                {
                    designBody = designFace.GetAncestor <IDesignBody>();
                }
                else
                {
                    return;
                }
            }

            bool isPlanarBody = true;

            foreach (DesignFace face in designBody.Master.Faces)
            {
                if (face.Shape.Geometry is Plane)
                {
                    continue;
                }

                isPlanarBody = false;
                face.SetColor(null, Color.Red);
            }

            if (!isPlanarBody)
            {
                Application.ReportStatus(Resources.UnfoldNotPlanarError, StatusMessageType.Error, null);
                return;
            }

            Face startFace = null;

            if (designFace != null)
            {
                startFace = designFace.Master.Shape;
            }

            Unfold(designBody.Master.Shape.Body, startFace, isDetectingCollisions, isCreatingBreaks, breakAngle, dashSize);

            Settings.Default.IsUnfoldingWithBreaks       = isCreatingBreaks;
            Settings.Default.UnfoldingWithBreaksAngle    = breakAngle * 180 / Math.PI;
            Settings.Default.UnfoldingWithBreaksDashSize = dashSize / ActiveWindow.Units.Length.ConversionFactor;
        }
 public static Color GetVisibleColor(this IDesignBody iDesignBody)
 {
     return(iDesignBody.Master.GetColor(null) ?? iDesignBody.Master.Layer.GetColor(null));
 }
示例#3
0
 public static Box GetBoundingBox(this IDesignBody iDesBody, Matrix trans)
 {
     Debug.Assert(trans == Matrix.Identity, "Warning: GetBoundingBox(this IDesignBody iDesBody, Matrix trans) not tested with trans != Matrix.Identity");
     return(iDesBody.Master.GetBoundingBox(trans * iDesBody.TransformToMaster.Inverse * trans.Inverse));
 }
示例#4
0
        static void ZBitmap_Executing(object sender, EventArgs e)
        {
            Window      activeWindow = Window.ActiveWindow;
            IDesignBody boxIDesBody  = activeWindow.GetAllSelectedIDesignBodies().FirstOrDefault();

            if (boxIDesBody == null)
            {
                return;
            }

            SaveFileDialog dialog = new SaveFileDialog();

            dialog.Filter = "PNG Files (*.png)|*.png";
            DialogResult result = dialog.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            string fileName = dialog.FileName;

            Box box    = boxIDesBody.GetBoundingBox(Matrix.Identity);
            int xCount = (int)(box.Size.X / resolution);
            int yCount = (int)(box.Size.Y / resolution);

            double min = box.MinCorner.Z;
            double max = box.MaxCorner.Z;

            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(xCount, yCount);
            for (int i = 0; i < xCount; i++)
            {
                double x = (double)i * resolution;

                for (int j = 0; j < yCount; j++)
                {
                    double       y   = (double)j * resolution;
                    CurveSegment ray = CurveSegment.Create(
                        Line.Create(Point.Create(x, y, 0), Direction.DirZ),
                        Interval.Create(-1000, 1000)                         // Interval.Create(double.MinValue, double.MaxValue) throws an exception when we calculate the intersections
                        );

                    foreach (IPart iPart in (activeWindow.Scene.Root as Part).WalkParts())
                    {
                        foreach (IDesignBody iDesBody in iPart.Bodies)
                        {
                            if (iDesBody.IsVisible(null) == false)
                            {
                                continue;
                            }

                            if (iDesBody.Master == boxIDesBody)
                            {
                                continue;
                            }

                            foreach (IDesignFace iDesFace in iDesBody.Faces)
                            {
                                ICollection <IntPoint <SurfaceEvaluation, CurveEvaluation> > intersections = iDesFace.Shape.IntersectCurve(ray);
                                double maxZ = double.MinValue;
                                foreach (IntPoint <SurfaceEvaluation, CurveEvaluation> intersection in intersections)
                                {
                                    maxZ = Math.Max(intersection.Point.Z, maxZ);
                                }

                                int intensity = (int)(255 * Interpolation.Clamp(min, max, maxZ, 0, 1));
                                bitmap.SetPixel(i, yCount - j - 1, System.Drawing.Color.FromArgb(intensity, intensity, intensity));
                            }
                        }
                    }
                }
            }

            bitmap.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
        }
        protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect)
        {
            double surfaceDeviation = Values[Resources.TesselateSurfaceDeviationText].Value / ActiveWindow.Units.Length.ConversionFactor;
            double angleDeviation   = Values[Resources.TesselateAngleDeviationText].Value / ActiveWindow.Units.Angle.ConversionFactor;

            ICollection <Face> faces       = null;
            IDesignBody        iDesignBody = Window.ActiveWindow.ActiveContext.SingleSelection as IDesignBody;

            if (iDesignBody != null)
            {
                faces = (iDesignBody.Master.Shape as Body).Faces;
            }
            else
            {
                ICollection <IDesignFace> iDesignFaces = Window.ActiveWindow.ActiveContext.GetSelection <IDesignFace>();
                foreach (IDesignFace iDesignFace in iDesignFaces)
                {
                    iDesignBody = iDesignFace.GetAncestor <DesignBody>();
                    continue; // TBD: handle multiple selection of faces across different DesignBodies
                }

                if (iDesignBody != null)
                {
                    List <Face> modelerFaces = new List <Face>();
                    foreach (DesignFace designFace in iDesignFaces)
                    {
                        if (designFace.GetAncestor <DesignBody>() == iDesignBody)
                        {
                            modelerFaces.Add(designFace.Shape as Face);
                        }
                    }
                    if (modelerFaces.Count > 0)
                    {
                        faces = modelerFaces;
                    }
                }
                else
                {
                    return;
                }
            }

            iDesignBody.SetVisibility(null, false);
            Body body = iDesignBody.Shape as Body;

            IDictionary <Face, FaceTessellation> tessellationMap = body.GetTessellation(faces, FacetSense.RightHanded, new TessellationOptions(surfaceDeviation, angleDeviation));

            Body        testfacetBody = null;
            List <Body> facetBodies   = new List <Body>();

            Point[] points = new Point[3];

            foreach (FaceTessellation faceTessellation in tessellationMap.Values)
            {
                IList <FacetVertex> vertices = faceTessellation.Vertices;
                foreach (FacetStrip facetStrip in faceTessellation.FacetStrips)
                {
                    foreach (Facet facet in facetStrip.Facets)
                    {
                        points[0] = vertices[facet.Vertex0].Position;
                        points[1] = vertices[facet.Vertex1].Position;
                        points[2] = vertices[facet.Vertex2].Position;

                        testfacetBody = ShapeHelper.CreatePolygon(points, null, 0);
                        if (testfacetBody != null)
                        {
                            facetBodies.Add(testfacetBody);
                        }
                    }
                }
            }

            // when the topology has holes (e.g. an annulus made with one surface), non-manifold vertices can occur when merging triangles around the hole.  The workaround is to merge the fragment lumps.
            facetBodies = new List <Body>(facetBodies.TryUnionBodies());
            facetBodies = new List <Body>(facetBodies.TryUnionBodies());
            foreach (Body facetBody in facetBodies)
            {
                DesignBody.Create(iDesignBody.GetAncestor <Part>(), "Tesselation", facetBody);
            }
        }
示例#6
0
        protected override void OnExecute(Command command, ExecutionContext context, Rectangle buttonRect)
        {
            if (Window.ActiveWindow.ActiveContext.SingleSelection is IDesignBody)
            {
                // reset all necessary parameters
                Settings.Default.Dimension        = 0; // Save that 3D Dimension is chosen
                Settings.Default.forceCount       = 0;
                Settings.Default.forces           = "";
                Settings.Default.bearingLoadCount = 0;
                Settings.Default.bearingLoads     = "";
                Settings.Default.xLength          = 0;
                Settings.Default.yLength          = 0;
                Settings.Default.zLength          = 0;
                Settings.Default.Save();

                Form form = new CreateCrossSectionForm();
                form.StartPosition = FormStartPosition.Manual;

                Screen    screen = Screen.PrimaryScreen;
                Rectangle bounds = screen.Bounds;

                // Show form in left bottom corner
                form.Location = (new System.Drawing.Point(bounds.X + (int)(bounds.Width * 0.05), bounds.Height - 258 - (int)(bounds.Height * 0.1))); // 523 = form Width, 258 Form Height


                DialogResult dr = form.ShowDialog();
                // Show testDialog as a modal dialog and determine if DialogResult = OK.

                Settings set      = Settings.Default;
                double   distance = set.distance;

                if (dr == DialogResult.OK)
                {
                    //MessageBox.Show("OK, distance : "+ distance);



                    // Create points with selected distance
                    bool teilbar = true;
                    int  count   = 1;   // point number

                    // parameters to find origin of body
                    double Xursprung = double.MaxValue;
                    double Yursprung = double.MaxValue;
                    double Zursprung = double.MaxValue;

                    double Xmax = double.MinValue;
                    double Ymax = double.MinValue;
                    double Zmax = double.MinValue;


                    Part mainPart = Window.ActiveWindow.Document.MainPart;
                    Window.ActiveWindow.InteractionMode = InteractionMode.Solid;
                    Window.ActiveWindow.ZoomSelection();

                    //var allBodies = new List<IDesignBody>();
                    //GatherBodies(mainPart, allBodies); // gets all bodies in window

                    IDocObject Ibody = Window.ActiveWindow.ActiveContext.SingleSelection;

                    IDesignBody designBody = (IDesignBody)Ibody;


                    DesignBody body = designBody.Master;
                    body.Name  = "DesignSpace";
                    body.Style = BodyStyle.Transparent;          // Make Block transparent
                    body.SetVisibility(null, false);


                    foreach (IDesignFace b in designBody.Faces)
                    {
                        foreach (IDesignEdge e in b.Edges)
                        {
                            SpaceClaim.Api.V19.Geometry.Point p1 = e.Shape.StartPoint;
                            SpaceClaim.Api.V19.Geometry.Point p2 = e.Shape.EndPoint;

                            // Locate minimum point of block
                            if (p1.X < Xursprung)
                            {
                                Xursprung = p1.X;
                            }
                            if (p2.X < Xursprung)
                            {
                                Xursprung = p2.X;
                            }

                            if (p1.Y < Yursprung)
                            {
                                Yursprung = p1.Y;
                            }
                            if (p2.Y < Yursprung)
                            {
                                Yursprung = p2.Y;
                            }

                            if (p1.Z < Zursprung)
                            {
                                Zursprung = p1.Z;
                            }
                            if (p2.Z < Zursprung)
                            {
                                Zursprung = p2.Z;
                            }

                            // Locate max value of x, y and z
                            if (p1.X > Xmax)
                            {
                                Xmax = p1.X;
                            }
                            if (p2.X > Xmax)
                            {
                                Xmax = p2.X;
                            }

                            if (p1.Y > Ymax)
                            {
                                Ymax = p1.Y;
                            }
                            if (p2.Y > Ymax)
                            {
                                Ymax = p2.Y;
                            }

                            if (p1.Z > Zmax)
                            {
                                Zmax = p1.Z;
                            }
                            if (p2.Z > Zmax)
                            {
                                Zmax = p2.Z;
                            }

                            // Check if distance is a factor of length, height or width
                            if ((e.Shape.Length * 1000) % distance > -0.001 && (e.Shape.Length * 1000) % distance < 0.001)
                            {
                            }
                            else
                            {
                                teilbar = false;
                            }
                        }
                    }

                    if (teilbar)
                    {
                        // Create all points in block

                        for (double z = Zursprung; z <= Zmax + 0.001; z += distance / 1000)
                        {
                            for (double y = Yursprung; y <= Ymax + 0.001; y += distance / 1000)
                            {
                                for (double x = Xursprung; x <= Xmax + 0.001; x += distance / 1000)
                                {
                                    SpaceClaim.Api.V19.Geometry.Point point = SpaceClaim.Api.V19.Geometry.Point.Create(x, y, z);
                                    DatumPoint P1 = DatumPoint.Create(Window.ActiveWindow.Document.MainPart, "P" + count, point);

                                    count++;
                                }
                            }
                        }

                        // save length
                        set.xLength = (Xmax - Xursprung) * 1000;
                        set.yLength = (Ymax - Yursprung) * 1000;
                        set.zLength = (Zmax - Zursprung) * 1000;



                        set.Save();


                        createCSV2(decimal.Parse("" + set.xLength), decimal.Parse("" + set.yLength), decimal.Parse("" + set.zLength), decimal.Parse("" + set.distance), set.csv2Path);

                        // Set camera position
                        Window.ActiveWindow.SetProjection(Frame.Create(SpaceClaim.Api.V19.Geometry.Point.Origin, -Direction.DirZ), 0.1);
                    }
                    else
                    {
                        MessageBox.Show("Distance is not a factor of length, height or width of block!", "Info");

                        body.Name = "DesignSpace";
                        body.SetVisibility(null, true);

                        Settings.Default.CrossSecFormOpened = false;
                        Settings.Default.Save();
                    }
                }
                else if (dr == DialogResult.Cancel)
                {
                    //MessageBox.Show("Canceled!");
                }

                Settings.Default.CrossSecFormOpened = true;
                Settings.Default.Save();
            }
            else
            {
                MessageBox.Show("Select a body in document first!", "Info");
            }
        }
示例#7
0
        static void Forstnerize_Executing(object sender, EventArgs e)
        {
            Window activeWindow = Window.ActiveWindow;

            IDesignBody forstnerBody    = null;
            Box         faceBoundingBox = Box.Empty;

            foreach (IDesignFace iDesignFace in activeWindow.ActiveContext.GetSelection <IDesignFace>())
            {
                forstnerBody     = iDesignFace.GetAncestor <IDesignBody>();
                faceBoundingBox |= iDesignFace.Shape.GetBoundingBox(Matrix.Identity);
            }
            if (forstnerBody == null || faceBoundingBox == Box.Empty)
            {
                return;
            }

            Part      part      = Part.Create(activeWindow.Document, "Forstner Bottoms");
            Component component = Component.Create(activeWindow.Scene as Part, part);

            Box    bodyBoundingBox = forstnerBody.Shape.GetBoundingBox(Matrix.Identity);
            Plane  topPlane        = Plane.Create(Frame.Create(bodyBoundingBox.MaxCorner, Direction.DirX, Direction.DirY));
            double xSpacing        = diameter * Math.Sqrt(3) / 2;
            double ySpacing        = diameter * 3 / 4;
            bool   shortRow        = false;

            for (double y = faceBoundingBox.MinCorner.Y; y < faceBoundingBox.MaxCorner.Y; y += ySpacing)
            {
                for (double x = shortRow ? faceBoundingBox.MinCorner.X + xSpacing / 2 : faceBoundingBox.MinCorner.X; x < faceBoundingBox.MaxCorner.X; x += xSpacing)
                {
                    List <IDesignBody> referenceBodies = new List <IDesignBody>();
                    referenceBodies.Add(DesignBody.Create(
                                            Part.Create(activeWindow.Document, "Temp"),
                                            "Target Copy",
                                            forstnerBody.Master.Shape.Copy()
                                            ));

                    Point       lowerPoint = Point.Create(x, y, bodyBoundingBox.MinCorner.Z);
                    Point       upperPoint = Point.Create(x, y, bodyBoundingBox.MaxCorner.Z);
                    IDesignBody drillBody  = ShapeHelper.CreateCylinder(lowerPoint, upperPoint, diameter, activeWindow.Scene as Part);

                    ICollection <IDesignBody> outputBodies = new List <IDesignBody>();
                    try {
                        //XXX					outputBodies = drillBody.Subtract(referenceBodies);
                    }
                    finally {
                        //outputBodies = new List<IDesignBody>();
                    }

                    // Find the top of the faces created by the intersection of the cylinder and the target.  The top of the bounding box of all faces except the top face and the cylinder of the drill are perfect.
                    Box      bottomBox     = Box.Empty;
                    Cylinder drillCylinder = Cylinder.Create(
                        Frame.Create(lowerPoint, Direction.DirX, Direction.DirY),
                        diameter / 2
                        );

                    bool hasTop = false;
                    foreach (IDesignBody iDesignBody in outputBodies)
                    {
                        foreach (IDesignFace iDesignFace in iDesignBody.Faces)
                        {
                            Plane plane = iDesignFace.Shape.Geometry as Plane;
                            if (plane != null)
                            {
                                if (AddInHelper.isCooincident(plane, topPlane))
                                {
                                    hasTop = true;
                                    continue;
                                }
                            }

                            Cylinder cylinder = iDesignFace.Shape.Geometry as Cylinder;
                            if (cylinder != null)
                            {
                                if (AddInHelper.isCooincident(cylinder, drillCylinder))
                                {
                                    continue;
                                }
                            }

                            bottomBox |= iDesignFace.Shape.GetBoundingBox(Matrix.Identity);
                        }
                        iDesignBody.Delete();
                    }

                    if (!bottomBox.IsEmpty && hasTop)
                    {
                        Point      bottomPoint = Point.Create(lowerPoint.X, lowerPoint.Y, bottomBox.MaxCorner.Z);
                        DesignBody bottomBody  = ShapeHelper.CreateCircle(Frame.Create(bottomPoint, Direction.DirX, Direction.DirY), diameter, part);
                        //AddInHelper.CreateCircle(Frame.Create(bottomPoint, Direction.DirX, Direction.DirY), 0.001, part);
                        foreach (DesignFace designFace in bottomBody.Faces)
                        {
                            NoteHelper.AnnotateFace(designFace.GetAncestor <Part>(), designFace, activeWindow.Units.Length.Format(-bottomPoint.Z), diameter / 5, Direction.DirZ);
                        }
                    }
                }
                shortRow = !shortRow;
            }
        }