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;
        }
        // Identify if hole and if has width / radius less than specified
        //------------------------------------------------------------------


        private bool IsHole(IDesignFace face, double radius)
        {
            // Take face and find the adjacent faces
            var adjFaces    = face.AdjacentFaces;
            var adjFaceList = new List <IDesignFace>();

            // Hole type [1] Cyl plane with two adjacent planes at 90 degrees
            if (adjFaceList.Count == 2)
            {
                // if 2 adjacent planes
                if (adjFaceList[0].Shape.GetGeometry <Plane>() != null && adjFaceList[1].Shape.GetGeometry <Plane>() != null)
                {
                    // Get the angles of both planes
                    return(true);
                }
                else
                {
                    return(false);
                }
            }


            else
            {
                return(false);
            }
        }
Beispiel #3
0
        // static Create method follows the API convention and parent should be first argument
        public static OscillatorPart Create(HandleTypeEnum handleType, IDesignFace iDesignFace, PointUV pointUV, double span, double position)
        {
            var widget = new OscillatorPart(handleType, iDesignFace, pointUV, span, position);

            widget.Initialize();
            return(widget);
        }
Beispiel #4
0
        void Reset()
        {
            oscillatorParts       = new List <OscillatorPart>();
            oscillatorIDesignFace = null;

            Rendering      = null;
            SelectionTypes = new[] { typeof(DesignFace), typeof(CustomObject) };
            StatusText     = "Place a new oscillator handle.";
        }
Beispiel #5
0
 // creates a new custom object and a wrapper for it
 protected OscillatorPart(HandleTypeEnum handleType, IDesignFace iDesignFace, PointUV pointUV, double span, double position)
     : base(iDesignFace.GetAncestor <Part>())
 {
     this.handleTypeInt = (int)handleType;
     this.iDesignFace   = iDesignFace;
     this.pointUV       = pointUV;
     this.span          = span;
     this.position      = position;
 }
Beispiel #6
0
        // static Create method follows the API convention and parent should be first argument
        public static FaceToolPathObject Create(IDesignFace desFace, FaceToolPath toolPath, Color color)
        {
            Debug.Assert(desFace == null || desFace.Master.Shape == toolPath.Face);
            FaceToolPathObject toolPathObj = null;

            WriteBlock.ExecuteTask("New toolpath", () => toolPathObj = new FaceToolPathObject(desFace, toolPath, color));
            toolPathObj.Initialize();

            //    IList<CutterLocation> cutterLocations;
            //    toolPath.TryGetCutterLocations(out cutterLocations);
            //    toolPathObj.cutterLocations = cutterLocations;
            return(toolPathObj);
        }
Beispiel #7
0
        // creates a new custom object and a wrapper for it
        protected FaceToolPathObject(IDesignFace iDesFace, FaceToolPath toolPath, Color color)
            : base(Window.ActiveWindow.Scene as Part)
        {
            this.toolPath = toolPath;
            this.iDesFace = iDesFace;
            this.color    = color;

            if (iDesFace != null)
            {
                IDesFace = iDesFace;
                iDesFace.KeepAlive(true);
            }

            allUVPaths.Add(this);
        }
Beispiel #8
0
        protected override bool OnDragStart(ScreenPoint cursorPos, Line cursorRay)
        {
            //SelectionTypes = new Type[0]; // disable preselection while dragging

            OscillatorPart oscillatorPart = OscillatorPart.GetWrapper(InteractionContext.Preselection as CustomObject);

            if (oscillatorPart == null)
            {
                return(false);
            }

            Point?pointOnCustom = InteractionContext.PreselectionPoint;

            if (pointOnCustom == null)
            {
                oscillatorPart = null;
                return(false);
            }

            switch (oscillatorPart.HandleType)
            {
            case HandleTypeEnum.Base:
                var iDesignFace = InteractionContext.Preselection as IDesignFace;
                if (iDesignFace == null)
                {
                    return(false);
                }

                SurfaceEvaluation eval = iDesignFace.Shape.GetSingleRayIntersection(cursorRay);
                if (eval == null)
                {
                    return(false);
                }

                oscillatorIDesignFace = iDesignFace;
                oscillatorPointUV     = eval.Param;

                StatusText = "Drag to move the oscillator.";
                break;

            case HandleTypeEnum.Start:
            case HandleTypeEnum.End:
                break;
            }

            return(false);
        }
Beispiel #9
0
        static Frame?GetFrameFromPoint(IDesignFace designFace, Point startPoint)
        {
            SurfaceEvaluation evaluation = designFace.Shape.Geometry.ProjectPoint(startPoint);
            Point             point      = evaluation.Point;
            PointUV           pointUV    = evaluation.Param;
            Direction         dirU       = (designFace.Shape.Geometry.Evaluate(PointUV.Create(pointUV.U + 0.0001, pointUV.V)).Point.Vector
                                            - designFace.Shape.Geometry.Evaluate(PointUV.Create(pointUV.U - 0.0001, pointUV.V)).Point.Vector).Direction;
            Direction dirV = Direction.Cross(evaluation.Normal, dirU);

            Frame frame = Frame.Create(point, dirU, dirV);

            if (designFace.Shape.IsReversed)
            {
                return(Frame.Create(frame.Origin, -frame.DirX, frame.DirY));
            }

            return(frame);
        }
Beispiel #10
0
        protected override void OnDragMove(ScreenPoint cursorPos, Line cursorRay)
        {
            if (oscillatorParts == null || oscillatorParts.Count == 0)
            {
                return;
            }

            var iDesignFace = InteractionContext.Preselection as IDesignFace;

            if (iDesignFace == null)
            {
                return;
            }

            oscillatorIDesignFace = iDesignFace;
            oscillatorPointUV     = oscillatorIDesignFace.Shape.GetSingleRayIntersection(cursorRay).Param;

            Apply("Modify Oscillator");
        }
Beispiel #11
0
        protected override bool OnMouseMove(ScreenPoint cursorPos, Line cursorRay, MouseButtons button)
        {
            if (button != MouseButtons.None)
            {
                return(false);
            }

            IDocObject  preselection = InteractionContext.Preselection;
            IDesignFace iDesignFace  = null;

            OscillatorPart existingOscillatorHandle = OscillatorPart.GetWrapper(preselection as CustomObject);

            if (existingOscillatorHandle != null)
            {
                iDesignFace = existingOscillatorHandle.IDesignFace;
            }
            if (iDesignFace == null)
            {
                iDesignFace = preselection as DesignFace;
            }
            if (iDesignFace == null)             // selection filtering is not applied if you (pre)select in the tree
            {
                return(false);
            }

            SurfaceEvaluation eval = iDesignFace.Shape.GetSingleRayIntersection(cursorRay);

            if (eval == null)
            {
                return(false);
            }

            Rendering = Graphic.Create(null, null, OscillatorPart.GetGraphics(iDesignFace, eval.Param, 0.05, 0, HandleTypeEnum.All));

            return(false);            // if we return true, the preselection won't update
        }
        static Frame? GetFrameFromPoint(IDesignFace designFace, Point startPoint)
        {
            SurfaceEvaluation evaluation = designFace.Shape.Geometry.ProjectPoint(startPoint);
            Point point = evaluation.Point;
            PointUV pointUV = evaluation.Param;
            Direction dirU = (designFace.Shape.Geometry.Evaluate(PointUV.Create(pointUV.U + 0.0001, pointUV.V)).Point.Vector
                            - designFace.Shape.Geometry.Evaluate(PointUV.Create(pointUV.U - 0.0001, pointUV.V)).Point.Vector).Direction;
            Direction dirV = Direction.Cross(evaluation.Normal, dirU);

            Frame frame = Frame.Create(point, dirU, dirV);

            if (designFace.Shape.IsReversed)
                return Frame.Create(frame.Origin, -frame.DirX, frame.DirY);

            return frame;
        }
        protected override void OnExecute(Command command, ExecutionContext context, Rectangle buttonRect)
        {
            Settings set = Settings.Default;

            if (Window.ActiveWindow.ActiveContext.SingleSelection is DesignFace)
            {
                // Reset all necessary parameteres
                Settings.Default.Dimension        = 1; // Save that 2D 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.

                if (dr == DialogResult.OK)
                {
                    try
                    {
                        int    count    = 1;            // node number
                        double distance = set.distance; // point distance
                        bool   teilbar  = true;

                        // Values to find origin of face
                        double Xursprung = double.MaxValue;
                        double Zursprung = double.MaxValue;

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


                        double length = 0;
                        double width  = 0;

                        IDocObject face = Window.ActiveWindow.ActiveContext.SingleSelection;

                        IDesignFace designFace = (IDesignFace)face;


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

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

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

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


                            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 x = Xursprung; x <= Xmax + 0.001; x += distance / 1000)
                                {
                                    SpaceClaim.Api.V19.Geometry.Point point = SpaceClaim.Api.V19.Geometry.Point.Create(x, 0, z);
                                    DatumPoint P1 = DatumPoint.Create(Window.ActiveWindow.Document.MainPart, "P" + count, point);

                                    count++;
                                }
                            }

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

                            set.Dimension = 1;

                            set.Save();

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

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

                            Settings.Default.CrossSecFormOpened = false;
                            Settings.Default.Save();
                        }
                    }
                    catch (Exception es)
                    {
                        MessageBox.Show("");
                    }
                }
                else if (dr == DialogResult.Cancel)
                {
                    //MessageBox.Show("Canceled!");
                }
            }
            else
            {
                MessageBox.Show("Select a face in document first!", "Info");
            }
        }
Beispiel #14
0
 public static FaceToolPathObject Create(IDesignFace desFace)
 {
     return(Create(desFace, DefaultToolPath, DefaultColor));
 }
Beispiel #15
0
        protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect)
        {
            double lengthConversion = ActiveWindow.Units.Length.ConversionFactor;

            int  numberOfTeethL = (int)Values[Resources.NumberOfTeethLText].Value;
            int  numberOfTeethR = (int)Values[Resources.NumberOfTeethRText].Value;
            bool isInternalL    = numberOfTeethL < 0;
            bool isInternalR    = numberOfTeethR < 0;

            numberOfTeethL = Math.Abs(numberOfTeethL);
            numberOfTeethR = Math.Abs(numberOfTeethR);

            double pressureAngle     = Values[Resources.PressureAngleText].Value * Math.PI / 180;
            double module            = Values[Resources.ModuleText].Value / lengthConversion;
            double dedendumClearance = Values[Resources.DedendumClearanceText].Value;
            double depth             = Values[Resources.DepthText].Value / lengthConversion;

            bool useTrochoidalInterferenceRemoval = Booleans[Resources.UseTrochoidalText].Value;
            bool addDedendumClearance             = Booleans[Resources.AddDedendumClearance].Value;

            if (!addDedendumClearance)
            {
                dedendumClearance = 0;
            }

            bool   isBevel        = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsBevelText].IsEnabledCommandBoolean.Value;
            double bevelAngle     = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsBevelText].Values[Resources.BevelAngleText].Value * Math.PI / 180;
            double bevelKneeRatio = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsBevelText].Values[Resources.BevelKneeRatioText].Value;

            bool   isHelical    = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsHelicalText].IsEnabledCommandBoolean.Value;
            double helicalAngle = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsHelicalText].Values[Resources.HelicalAngleText].Value * Math.PI / 180;

            if (!isHelical)
            {
                helicalAngle = 0;
            }

            bool   isScrew          = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsScrewText].IsEnabledCommandBoolean.Value;
            double screwAngle       = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsScrewText].Values[Resources.ScrewAngleText].Value * Math.PI / 180;
            double screwAngleOffset = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsScrewText].Values[Resources.ScrewAngleBiasText].Value * Math.PI / 180;

            if (!isScrew)
            {
                screwAngle       = 0;
                screwAngleOffset = 0;
            }

            double screwAngleAverage = screwAngle / 2;
            double screwAngleL       = screwAngleAverage + screwAngleOffset;
            double screwAngleR       = screwAngleAverage - screwAngleOffset;

            bool   isHypoid     = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsHypoidText].IsEnabledCommandBoolean.Value;
            double hypoidAngle  = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsHypoidText].Values[Resources.HypoidAngleText].Value * Math.PI / 180;
            double hypoidOffset = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsHypoidText].Values[Resources.HypoidOffsetText].Value / lengthConversion;

            if (!isHypoid)
            {
                hypoidAngle  = 0;
                hypoidOffset = 0;
            }

            Frame frame = Frame.World;
            //Circle circle = SelectedCircle(ActiveWindow);
            //if (circle != null)
            //    frame = circle.Frame;

            List <ITrimmedCurve> selectedCurves = ActiveWindow.GetAllSelectedITrimmedCurves().ToList();

            if (selectedCurves.Count == 2 && selectedCurves[0].Geometry is Circle && selectedCurves[0].Geometry is Circle)
            {
                Circle     circle0    = (Circle)selectedCurves[0].Geometry;
                Circle     circle1    = (Circle)selectedCurves[1].Geometry;
                Separation separation = circle0.Axis.GetClosestSeparation(circle1.Axis);

                if (Accuracy.LengthIsZero(separation.Distance))
                {
                    throw new NotImplementedException("Distance between axes is zero; only hypoid implemented.");
                }

                isHypoid     = true;
                hypoidAngle  = AddInHelper.AngleBetween(circle0.Axis.Direction, circle1.Axis.Direction);
                hypoidOffset = ((circle0.Frame.Origin - separation.PointA).Magnitude - depth / 2) / Math.Cos(hypoidAngle / 2);

                double radiusAApprox = separation.Distance * circle0.Radius / (circle0.Radius + circle1.Radius);
                double radiusBApprox = separation.Distance - radiusAApprox;
                numberOfTeethR = (int)Math.Round((double)numberOfTeethL / radiusAApprox * radiusBApprox);
                module         = radiusAApprox * 2 / numberOfTeethL;

                Point     midpoint = separation.PointA + (separation.PointA - separation.PointB) * numberOfTeethL / numberOfTeethR;
                Direction sideSide = (circle0.Frame.Origin - circle1.Frame.Origin).Direction;
                frame = Frame.Create(midpoint, Direction.Cross(sideSide, -(midpoint - circle0.GetClosestSeparation(circle1).PointA).Direction), sideSide);
            }

            double hypoidAngleL = Math.Atan(Math.Sin(hypoidAngle) / (Math.Cos(hypoidAngle) + (double)numberOfTeethR / numberOfTeethL));
            double hypoidAngleR = Math.Atan(Math.Sin(hypoidAngle) / (Math.Cos(hypoidAngle) + (double)numberOfTeethL / numberOfTeethR));

            Gear gearL = null;
            Gear gearR = null;

            var          gearDataL     = new GearData(numberOfTeethL, pressureAngle, module, dedendumClearance, isInternalL, screwAngleL);
            var          gearDataR     = new GearData(numberOfTeethR, pressureAngle, module, dedendumClearance, isInternalR, screwAngleR);
            ToothProfile toothProfileL = GetGearProfileFromOptions(gearDataL, gearDataR, useTrochoidalInterferenceRemoval, addDedendumClearance);
            ToothProfile toothProfileR = GetGearProfileFromOptions(gearDataR, gearDataL, useTrochoidalInterferenceRemoval, addDedendumClearance);

            if (isBevel)
            {
                gearL = BevelGear.Create(ActiveIPart, gearDataL, gearDataR, toothProfileL, helicalAngle, bevelAngle, bevelKneeRatio, depth);
                gearR = BevelGear.Create(ActiveIPart, gearDataR, gearDataL, toothProfileR, -helicalAngle, bevelAngle, bevelKneeRatio, depth);
            }
            else if (isHypoid)
            {
                gearL = HypoidGear.Create(ActiveIPart, gearDataL, gearDataR, toothProfileL, helicalAngle, hypoidAngleL, hypoidOffset, bevelKneeRatio, depth);
                gearR = HypoidGear.Create(ActiveIPart, gearDataR, gearDataL, toothProfileR, -helicalAngle, hypoidAngleR, hypoidOffset, bevelKneeRatio, depth);
            }
            else
            {
                gearL = StraightGear.Create(ActiveIPart, gearDataL, gearDataR, toothProfileL, helicalAngle, screwAngleL, depth);
                gearR = StraightGear.Create(ActiveIPart, gearDataR, gearDataL, toothProfileR, -helicalAngle, screwAngleR, depth);
            }

            Line zAxis = Line.Create(Point.Origin, Direction.DirZ);

            gearL.Component.Transform(
                Matrix.CreateMapping(frame) *
                Matrix.CreateRotation(zAxis, Math.PI) *
                gearL.TransformToTangent *
                Matrix.CreateRotation(zAxis, gearDataL.PitchAngle * ((double)1 / 2 + (gearDataL.NumberOfTeeth % 2 == 0 && !isHypoid ? -1 : 0)))
                );

            gearR.Component.Transform(
                Matrix.CreateMapping(frame) *
                gearR.TransformToTangent *
                Matrix.CreateRotation(zAxis, gearDataR.PitchAngle * ((double)1 / 2 + (gearDataR.NumberOfTeeth % 2 == 0 && !isHypoid ? -1 : 0)))
                );


            //		if (gearDataR.NumberOfTeeth % 2 == 0)
            //			gearR.Component.Transform(Matrix.CreateRotation(Line.Create(Point.Origin, Direction.DirZ), gearDataR.PitchAngle));

            //gearR.Component.Transform(gearR.TransformToTangent);

            Part        parent       = ActiveIPart.Master;
            IDesignFace pitchCircleL = gearL.Component.Content.Bodies.Where(b => b.Master == gearL.PitchCircleDesBody).First().Faces.First();
            IDesignFace pitchCircleR = gearR.Component.Content.Bodies.Where(b => b.Master == gearR.PitchCircleDesBody).First().Faces.First();

            Part        gearMountPart      = Part.Create(parent.Document, String.Format(Resources.GearMountPartName, gearDataL.NumberOfTeeth, gearDataR.NumberOfTeeth));
            Component   gearMountComponent = Component.Create(parent, gearMountPart);
            DesignBody  mountBodyL         = DesignBody.Create(gearMountPart, string.Format(Resources.MountBodyName, gearDataL.NumberOfTeeth), pitchCircleL.Master.Shape.Body.CreateTransformedCopy(pitchCircleL.TransformToMaster.Inverse));
            DesignBody  mountBodyR         = DesignBody.Create(gearMountPart, string.Format(Resources.MountBodyName, gearDataR.NumberOfTeeth), pitchCircleR.Master.Shape.Body.CreateTransformedCopy(pitchCircleR.TransformToMaster.Inverse));
            IDesignFace mountCircleL       = gearMountComponent.Content.Bodies.Where(b => b.Master == mountBodyL).First().Faces.First();
            IDesignFace mountCircleR       = gearMountComponent.Content.Bodies.Where(b => b.Master == mountBodyR).First().Faces.First();

            Layer mountLayer = NoteHelper.CreateOrGetLayer(ActiveDocument, Resources.GearMountAlignmentCircleLayer, System.Drawing.Color.LightGray);

            mountLayer.SetVisible(null, false);
            mountBodyL.Layer = mountLayer;
            mountBodyR.Layer = mountLayer;

            MatingCondition matingCondition;

            matingCondition = AnchorCondition.Create(parent, gearMountComponent);
            matingCondition = AlignCondition.Create(parent, mountCircleL, pitchCircleL);
            matingCondition = AlignCondition.Create(parent, mountCircleR, pitchCircleR);
            //		matingCondition = TangentCondition.Create(parent, pitchCircleL, pitchCircleR);
            GearCondition gearCondition = GearCondition.Create(parent, pitchCircleL, pitchCircleR);

            if (gearDataL.IsInternal ^ gearDataR.IsInternal)
            {
                gearCondition.IsBelt = true;
            }

            ActiveWindow.InteractionMode = InteractionMode.Solid;

            Settings.Default.NumberOfTeethL       = numberOfTeethL;
            Settings.Default.NumberOfTeethR       = numberOfTeethR;
            Settings.Default.PressureAngleDegrees = pressureAngle * 180 / Math.PI;
            Settings.Default.Module            = module;
            Settings.Default.Depth             = depth;
            Settings.Default.DedendumClearance = dedendumClearance;

            Settings.Default.UseTrochoidalInterferenceRemoval = useTrochoidalInterferenceRemoval;
            Settings.Default.AddDedendumClearace = addDedendumClearance;

            Settings.Default.IsBevel = isBevel;
            if (isBevel)
            {
                Settings.Default.BevelAngle     = bevelAngle * 180 / Math.PI;
                Settings.Default.BevelKneeRatio = bevelKneeRatio;
            }

            Settings.Default.IsHelical    = isHelical;
            Settings.Default.HelicalAngle = helicalAngle * 180 / Math.PI;

            Settings.Default.IsScrew          = isScrew;
            Settings.Default.ScrewAngle       = screwAngle * 180 / Math.PI;
            Settings.Default.ScrewAngleOffset = screwAngleOffset * 180 / Math.PI;

            Settings.Default.IsHypoid     = isHypoid;
            Settings.Default.HypoidAngle  = hypoidAngle * 180 / Math.PI;
            Settings.Default.HypoidOffset = hypoidOffset * lengthConversion;

            Settings.Default.Save();
        }
Beispiel #16
0
        public static ICollection <Graphic> GetGraphics(IDesignFace iDesignFace, PointUV pointUV, double span, double position, HandleTypeEnum handleType)
        {
            Debug.Assert(iDesignFace != null);

            Window activeWindow = Window.ActiveWindow;
            var    graphics     = new List <Graphic>();

            var primitives = new List <Primitive>();

            SurfaceEvaluation eval   = iDesignFace.Shape.Geometry.Evaluate(pointUV);
            Point             point  = eval.Point;
            Direction         normal = eval.Normal;

            double pixelSize      = activeWindow.ActiveContext.GetPixelSize(point);
            double shaftDiameter  = 4 * pixelSize;
            double handleDiameter = 8 * pixelSize;
            double handleHeight   = 4 * pixelSize;

            Point  startPoint          = point - (normal * (span * (position + 1) / 2 - handleHeight));
            Point  endPoint            = startPoint + normal * (span + 2 * handleHeight);
            Vector handleHalfThickness = normal * handleHeight / 2;

            bool isDrawingAll = handleType == HandleTypeEnum.All;
            var  mesh         = new List <Primitive>();
            var  style        = new GraphicStyle
            {
                EnableDepthBuffer = true,
                LineColor         = Color.DimGray,
                LineWidth         = 1,
                FillColor         = Color.DimGray
            };

            switch (handleType)
            {
            case HandleTypeEnum.All:
            case HandleTypeEnum.Shaft:
                mesh.AddRange(ShapeHelper.CreateCylinderMesh(startPoint, endPoint, shaftDiameter, 8));
                graphics.Add(Graphic.Create(style, mesh));

                if (isDrawingAll)
                {
                    goto case HandleTypeEnum.Base;
                }
                else
                {
                    break;
                }

            case HandleTypeEnum.Base:
                mesh.AddRange(ShapeHelper.CreateCylinderMesh(point - handleHalfThickness, point + handleHalfThickness, handleDiameter, 12));
                style.LineColor = Color.DodgerBlue;
                style.FillColor = Color.DodgerBlue;
                graphics.Add(Graphic.Create(style, mesh));

                if (isDrawingAll)
                {
                    goto case HandleTypeEnum.Start;
                }
                else
                {
                    break;
                }

            case HandleTypeEnum.Start:
                mesh.AddRange(ShapeHelper.CreateCylinderMesh(startPoint - handleHalfThickness, startPoint + handleHalfThickness, handleDiameter, 12));
                style.LineColor = Color.DarkViolet;
                style.FillColor = Color.DarkViolet;
                graphics.Add(Graphic.Create(style, mesh));

                if (isDrawingAll)
                {
                    goto case HandleTypeEnum.End;
                }
                else
                {
                    break;
                }

            case HandleTypeEnum.End:
                mesh.AddRange(ShapeHelper.CreateCylinderMesh(endPoint - handleHalfThickness, endPoint + handleHalfThickness, handleDiameter, 12));
                style.LineColor = Color.DarkViolet;
                style.FillColor = Color.DarkViolet;
                graphics.Add(Graphic.Create(style, mesh));

                break;
            }

            return(graphics);
        }
        protected override void OnExecute(Command command, ExecutionContext context, Rectangle buttonRect)
        {
            /*
             * Provide dialogue box and user inputs what they want to locate
             * These selections are Tori, Small Holes or Small Volumes
             * For Small Volumes and Holes the user will need to input a value
             * Each will be handled seperately and find matching bodies in all part design bodies
             * All will be then added to a final selection list for the user
             */

            // Instance common functions class
            InstanceClasses.CommonSpaceClaimFunctions FunctionsClass = new InstanceClasses.CommonSpaceClaimFunctions();

            // Variables
            Window window = Window.ActiveWindow;

            window.SetTool(new ToolClass());
            Document           doc          = window.Document;
            Part               rootPart     = doc.MainPart;
            InteractionContext interContext = window.ActiveContext;

            List <IDesignBody>        selectionBodies  = new List <IDesignBody>();
            List <IDesignBody>        matchingBodies   = new List <IDesignBody>();
            List <Face>               facesList        = new List <Face>();
            List <IDesignFace>        iFacesList       = new List <IDesignFace>();
            List <IDesignFace>        ifinalFacesList  = new List <IDesignFace>();
            ICollection <IDesignFace> IcollectionFaces = null;

            double minradius;
            double minVolume;
            double minFace;

            bool findCone   = false;
            bool findTori   = false;
            bool findHoles  = false;
            bool findVolume = false;
            bool findFace   = false;

#pragma warning disable CS0219 // The variable 'faceCounter' is assigned but its value is never used
            int faceCounter = 0;
#pragma warning restore CS0219 // The variable 'faceCounter' is assigned but its value is never used


#pragma warning disable CS0219 // The variable 'intMode' is assigned but its value is never used
            InteractionMode intMode = InteractionMode.Solid;
#pragma warning restore CS0219 // The variable 'intMode' is assigned but its value is never used



            if (window == null)
            {
                return;
            }

            #region Dialogue

            // Create dialogue box
            using (var dialogue = new UI.BodySelectForm())
            {
                if (dialogue.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                var nameAndRendering = new List <KeyValuePair <string, Graphic> >();
                var partToGraphic    = new Dictionary <Part, Graphic>();

                var style = new GraphicStyle
                {
                    EnableDepthBuffer = true
                };

                findCone   = dialogue.LocateCone;
                findTori   = dialogue.LocateTori;
                findHoles  = dialogue.LocateHoles;
                findVolume = dialogue.LocateVolume;
                findFace   = dialogue.LocateFace;

                minradius = dialogue.minRadius;
                minVolume = dialogue.minVolume;
                minFace   = dialogue.minFace;
            }

            #endregion

            // Gather all design bodies
            //-----------------------------------------------
            selectionBodies.AddRange(FunctionsClass.GatherAllVisibleBodies(rootPart, window));

            // Check if each body fits wanted criteria
            //-----------------------------------------------
            foreach (IDesignBody iDesBod in selectionBodies)
            {
                DesignBody master = iDesBod.Master;
                Body       body   = master.Shape;

                var faces = body.Faces;
                facesList.AddRange(faces);
                var iFaces = iDesBod.Faces;
                iFacesList.AddRange(iFaces);

                Matrix masterTrans  = iDesBod.TransformToMaster;
                Matrix reverseTrans = masterTrans.Inverse;

                // If body fits volume criteria
                //----------------------------------------
                if (findVolume && body.Volume * 1e6 < minVolume)
                {
                    matchingBodies.Add(iDesBod);
                }
                else
                {
                    // If body fits tori or hole criteria
                    //----------------------------------------
                    for (int i = 0; i < iFacesList.Count; i++)
                    {
                        IDesignFace face = iFacesList[i];

                        if (face.Area * 1e4 < minFace)
                        {
                            ifinalFacesList.Clear();
                            ifinalFacesList.Add(face);
                            window.ActiveTool.CreateIndicator(ifinalFacesList);
                        }

                        if (face.Shape.GetGeometry <Cone>() != null && findCone)
                        {
                            ifinalFacesList.Clear();
                            ifinalFacesList.Add(face);
                            window.ActiveTool.CreateIndicator(ifinalFacesList);
                        }

                        if (face.Shape.GetGeometry <Torus>() != null && findTori)
                        {
                            ifinalFacesList.Clear();
                            ifinalFacesList.Add(face);
                            window.ActiveTool.CreateIndicator(ifinalFacesList);
                        }
                        else if (face.Shape.GetGeometry <Cylinder>() != null && face.Shape.GetGeometry <Cylinder>().Radius * 1e2 < minradius && findHoles)
                        {
                            //FunctionsClass.ColourFace(facesList[i], master);
                            ifinalFacesList.Clear();
                            ifinalFacesList.Add(face);
                            window.ActiveTool.CreateIndicator(ifinalFacesList);
                            var radius = face.Shape.GetGeometry <Cylinder>().Radius;

                            /*
                             * if (IsHole(face, radius))
                             * {
                             *  ifinalFacesList.Clear();
                             *  ifinalFacesList.Add(face);
                             *  window.ActiveTool.CreateIndicator(ifinalFacesList);
                             * }
                             */
                        }
                        else
                        {
                            // Set all the other face to slightly translucent
                            //FunctionsClass.SetFacetranslucent(face, master);
                        }
                    }
                }

                facesList.Clear();
                iFacesList.Clear();
            }
            //ICollection<IDocObject> bodyCollection = null;

            // For each matching body change the colour to red
            //----------------------------------------------------
            foreach (IDesignBody finalBody in matchingBodies)
            {
                //bodyCollection.Add(finalBody);
                DesignBody finalMaster = finalBody.Master;
                finalMaster.SetColor(null, Color.Red);
            }
            var point = Point.Create(1, 1, 1);
            IcollectionFaces = ifinalFacesList;

            // Also set them as selected by the user
            //----------------------------------------------------
            //interContext.Selection = bodyCollection;
        }
Beispiel #18
0
        protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect)
        {
            base.OnExecute(command, context, buttonRect);

            Window activeWindow = Window.ActiveWindow;
            Part   activePart   = (activeWindow.Scene as Part);

            Layer tabLayer = NoteHelper.CreateOrGetLayer(activeWindow.ActiveContext.Context.Document, "Tabs", System.Drawing.Color.Fuchsia);

            IDesignEdge iDesignEdge = activeWindow.ActiveContext.SingleSelection as IDesignEdge;

            if (iDesignEdge == null)
            {
                return;
            }

            if (iDesignEdge.Faces.Count != 1)
            {
                return;
            }

            IDesignFace iDesignFace = null;

            foreach (IDesignFace testFace in iDesignEdge.Faces)
            {
                iDesignFace = testFace;
            }

            Debug.Assert(iDesignFace != null);

            Point startPoint = iDesignEdge.Shape.StartPoint;
            Point endPoint   = iDesignEdge.Shape.EndPoint;

            if (areTabsFlipped)
            {
                Point tempPoint = startPoint;
                startPoint = endPoint;
                endPoint   = tempPoint;
            }

            SurfaceEvaluation surfEval   = iDesignFace.Shape.ProjectPoint(startPoint);
            Direction         faceNormal = surfEval.Normal;
            Point             midpoint   = startPoint + (endPoint - startPoint) / 2;
            Double            edgeLength = iDesignEdge.Shape.Length;
            Direction         xDir       = (endPoint - startPoint).Direction;

            List <Window> tabWindows = null;
            string        tabFile    = string.Empty;

            if (!isTabStartSlot)
            {
                tabFile = @"C:\Users\bcr.SPACECLAIM\Documents\Models\Dodecahedron Foldcrease\Tab-Circle-Male.scdoc";
            }
            else
            {
                tabFile = @"C:\Users\bcr.SPACECLAIM\Documents\Models\Dodecahedron Foldcrease\Tab-Circle-Female.scdoc";
            }

            try {
                tabWindows = new List <Window>(Document.Open(tabFile, ImportOptions.Create()));
            }
            catch (Exception exception) {
                System.Windows.Forms.MessageBox.Show(SpaceClaim.Api.V10.Application.MainWindow, exception.Message);
            }

            DesignBody tabDesignBody = null;

            foreach (DesignBody testBody in (tabWindows[0].Scene as Part).Bodies)
            {
                tabDesignBody = testBody;
            }

            Debug.Assert(tabDesignBody != null);

            tabDesignBody = DesignBody.Create(activePart, "tab", tabDesignBody.Shape.Body.Copy());

            foreach (Window window in tabWindows)
            {
                window.Delete();
            }

            Matrix scale = Matrix.CreateScale(edgeLength / 0.02, Point.Origin);
            Matrix trans = Matrix.CreateMapping(Frame.Create(midpoint, xDir, Direction.Cross(faceNormal, xDir)));

            tabDesignBody.Transform(trans * scale);
            tabDesignBody.Layer = tabLayer;
        }