Exemple #1
0
        public void MixedOpenClosedWires()
        {
            // Remove first segment to create open wires
            var sketch1 = TestSketchGenerator.CreateRectangle(5.0, 5.0);

            sketch1.DeleteSegment(sketch1.Segments[0]);
            var body1 = sketch1.Body;

            var sketch2 = TestSketchGenerator.CreateRectangle(4.0, 4.0);

            sketch2.DeleteSegment(sketch2.Segments[0]);
            sketch2.MergePoints(0, 1);
            var body2 = sketch2.Body;

            body2.Position = body2.Position.Translated(new Vec(0, 0, 10.0));
            body2.Rotation = new Quaternion(20.0.ToRad(), 20.0.ToRad(), 0.0);

            var sketch3 = TestSketchGenerator.CreateRectangle(5.0, 5.0);

            sketch3.DeleteSegment(sketch3.Segments[0]);
            var body3 = sketch3.Body;

            body3.Position = body3.Position.Translated(new Vec(0, 5.0, 20.0));
            body3.Rotation = new Quaternion(40.0.ToRad(), 40.0.ToRad(), 0.0);

            var loft = Loft.Create(body1, new[] { new BodyShapeOperand(body2), new BodyShapeOperand(body3) });

            Assert.IsFalse(loft.Make(Shape.MakeFlags.None)); // Sections must be all closed or all open
        }
Exemple #2
0
        public void CappingModeNoneOutAngular()
        {
            var body1 = TestSketchGenerator.CreateRectangle(5.0, 5.0).Body;

            var body3 = TestSketchGenerator.CreateRectangle(5.0, 5.0).Body;

            body3.Position = body3.Position.Translated(new Vec(0, 5.0, 20.0));
            body3.Rotation = new Quaternion(40.0.ToRad(), 40.0.ToRad(), 0.0);

            var loft = Loft.Create(body1, new[] { new BodyShapeOperand(body3) });

            loft.ThickenDirection  = Loft.Direction.Outwards;
            loft.ThickenCornerType = Loft.CornerType.Angular;

            loft.StartCapping = Loft.CappingMode.None;
            loft.EndCapping   = Loft.CappingMode.None;
            Assert.IsTrue(loft.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(loft, Path.Combine(_BasePath, "CappingModeNoneBoth_OutAngular"));

            loft.StartCapping = Loft.CappingMode.None;
            loft.EndCapping   = Loft.CappingMode.Flat;
            Assert.IsTrue(loft.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(loft, Path.Combine(_BasePath, "CappingModeNoneStart_OutAngular"));

            loft.StartCapping = Loft.CappingMode.Flat;
            loft.EndCapping   = Loft.CappingMode.None;
            Assert.IsTrue(loft.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(loft, Path.Combine(_BasePath, "CappingModeNoneEnd_OutAngular"));
        }
Exemple #3
0
        public void OpenWiresRect(Loft.Direction direction, Loft.CornerType cornerType)
        {
            // Remove first segment to create open wires
            var sketch1 = TestSketchGenerator.CreateRectangle(5.0, 5.0);

            sketch1.DeleteSegment(sketch1.Segments[0]);
            var body1 = sketch1.Body;

            var sketch2 = TestSketchGenerator.CreateRectangle(4.0, 4.0);

            sketch2.DeleteSegment(sketch2.Segments[0]);
            var body2 = sketch2.Body;

            body2.Position = body2.Position.Translated(new Vec(0, 0, 10.0));
            body2.Rotation = new Quaternion(20.0.ToRad(), 20.0.ToRad(), 0.0);

            var sketch3 = TestSketchGenerator.CreateRectangle(5.0, 5.0);

            sketch3.DeleteSegment(sketch3.Segments[0]);
            var body3 = sketch3.Body;

            body3.Position = body3.Position.Translated(new Vec(0, 5.0, 20.0));
            body3.Rotation = new Quaternion(40.0.ToRad(), 40.0.ToRad(), 0.0);

            var loft = Loft.Create(body1, new[] { new BodyShapeOperand(body2), new BodyShapeOperand(body3) });

            loft.ThickenDirection  = direction;
            loft.ThickenCornerType = cornerType;
            Assert.IsTrue(loft.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(loft, Path.Combine(_BasePath, $"OpenWiresRect_{direction}_{cornerType}"));
        }
Exemple #4
0
        /***************************************************/


        private static List <Loft> DeformedShapeSection(Bar bar, List <BarDeformation> deformations, double scaleFactor = 1.0)
        {
            Vector tan     = bar.Tangent();
            Vector unitTan = tan.Normalise();
            Vector normal  = bar.Normal();
            Vector yAxis   = normal.CrossProduct(unitTan);


            List <Point> pts = new List <Point>();

            IEnumerable <ICurve> sectionCurves = bar.Extrude(false).Select(x => (x as BH.oM.Geometry.Extrusion).Curve);

            List <Loft> lofts = new List <Loft>();

            foreach (ICurve sectionCurve in sectionCurves)
            {
                Loft loft = new Loft();
                foreach (BarDeformation defo in deformations)
                {
                    ICurve curve = sectionCurve.IRotate(bar.StartNode.Position(), unitTan, defo.RX * scaleFactor);
                    Vector disp  = unitTan * defo.UX * scaleFactor + yAxis * defo.UY * scaleFactor + normal * defo.UZ * scaleFactor;
                    disp += tan * defo.Position;
                    loft.Curves.Add(curve.ITranslate(disp));
                }
                lofts.Add(loft);
            }


            return(lofts);
        }
Exemple #5
0
        public void MultipleUnsorted3()
        {
            var body1 = TestSketchGenerator.CreateRectangle(5.0, 5.0).Body;

            var body2 = TestSketchGenerator.CreateCircleWithArcs(3.0, 4).Body;

            body2.Position = body2.Position.Translated(new Vec(0, 0, 10.0));
            body2.Rotation = new Quaternion(20.0.ToRad(), 20.0.ToRad(), 0.0);

            var body3 = TestSketchGenerator.CreateRectangle(5.0, 5.0).Body;

            body3.Position = body3.Position.Translated(new Vec(0, 5.0, 20.0));
            body3.Rotation = new Quaternion(40.0.ToRad(), 40.0.ToRad(), 0.0);

            var body4 = TestSketchGenerator.CreateCircleWithArcs(3.0, 4).Body;

            body4.Position = body4.Position.Translated(new Vec(10, 0, 30.0));
            body4.Rotation = new Quaternion(20.0.ToRad(), 60.0.ToRad(), 0.0);

            var body5 = TestSketchGenerator.CreateRectangle(5.0, 5.0).Body;

            body5.Position = body5.Position.Translated(new Vec(20, 0.0, 40.0));
            body5.Rotation = new Quaternion(20.0.ToRad(), 80.0.ToRad(), 0.0);

            var body6 = TestSketchGenerator.CreateCircleWithArcs(3.0, 4).Body;

            body6.Position = body6.Position.Translated(new Vec(30, 0.0, 40.0));
            body6.Rotation = new Quaternion(0.0.ToRad(), 110.0.ToRad(), 0.0);

            var loft = Loft.Create(body4, new[] { new BodyShapeOperand(body2), new BodyShapeOperand(body6),
                                                  new BodyShapeOperand(body3), new BodyShapeOperand(body5), new BodyShapeOperand(body1) });

            Assert.IsTrue(loft.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(loft, Path.Combine(_BasePath, "MultipleUnsorted3"));
        }
Exemple #6
0
        /***************************************************/


        private static List <Loft> DeformedShapeSection(Bar bar, List <BarDisplacement> deformations, double scaleFactor = 1.0)
        {
            Vector tan = bar.Tangent();

            List <Point> pts = new List <Point>();

            IEnumerable <ICurve> sectionCurves = bar.Extrude(false).Select(x => (x as BH.oM.Geometry.Extrusion).Curve);

            List <Loft> lofts = new List <Loft>();

            foreach (ICurve sectionCurve in sectionCurves)
            {
                Loft loft = new Loft();
                foreach (BarDisplacement defo in deformations)
                {
                    //ICurve curve = sectionCurve.IRotate(bar.StartNode.Position(), tan, defo.RX * scaleFactor);
                    //Vector disp = unitTan * defo.UX * scaleFactor + yAxis * defo.UY * scaleFactor + normal * defo.UZ * scaleFactor;
                    Vector disp = new Vector {
                        X = defo.UX * scaleFactor, Y = defo.UY * scaleFactor, Z = defo.UZ * scaleFactor
                    };
                    disp += tan * defo.Position;
                    loft.Curves.Add(sectionCurve.ITranslate(disp));
                }
                lofts.Add(loft);
            }


            return(lofts);
        }
        public void AddSections()
        {
            var ctx = Context.Current;

            var body1 = TestSketchGenerator.CreateRectangle(5.0, 5.0).Body;

            var body2 = TestSketchGenerator.CreateRectangle(5.0, 5.0).Body;

            body2.Position = body2.Position.Translated(new Vec(0, 0, 10.0));
            body2.Rotation = new Quaternion(20.0.ToRad(), 20.0.ToRad(), 0.0);

            Loft.Create(body1, new[] { new BodyShapeOperand(body2) });

            var body3 = TestSketchGenerator.CreateRectangle(5.0, 5.0).Body;

            body3.Position = body3.Position.Translated(new Vec(0, 5.0, 20.0));
            body3.Rotation = new Quaternion(40.0.ToRad(), 40.0.ToRad(), 0.0);

            Assert.Multiple(() =>
            {
                ctx.ViewportController.ZoomFitAll();
                // Select Loft Body
                ctx.SelectAt(176, 405);
                ctx.WorkspaceController.StartTool(new CreateLoftTool());

                // Add and Finish
                ctx.SelectAt(349, 164);
                ctx.WorkspaceController.CancelTool(ctx.WorkspaceController.CurrentTool, false);
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "AddSections00"));
                Assert.IsNull(ctx.WorkspaceController.CurrentTool);
            });
        }
Exemple #8
0
    public override void OnInspectorGUI()
    {
        Loft myTarget = (Loft)target;



        DrawDefaultInspector();
    }
Exemple #9
0
        public static List <Point> Points(Loft g)
        {
            List <Point> controlPts = new List <Point>();

            foreach (ICurve curve in g.Curves)
            {
                controlPts.AddRange(curve.IControlPoints());
            }
            return(controlPts);
        }
Exemple #10
0
        /***************************************************/

        public static bool IsPlanar(this Loft surface, double tolerance = Tolerance.Distance)
        {
            List <Point> controlPts = new List <Point>();

            foreach (ICurve curve in surface.Curves)
            {
                controlPts.AddRange(curve.IControlPoints());
            }
            return(controlPts.IsCoplanar(tolerance));
        }
Exemple #11
0
        /***************************************************/

        public static bool IsInPlane(this Loft surface, Plane plane, double tolerance = Tolerance.Distance)
        {
            foreach (ICurve c in surface.Curves)
            {
                if (!c.IIsInPlane(plane, tolerance))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #12
0
        public void DifferentEdgeCount()
        {
            var body1 = TestSketchGenerator.CreateRectangle(5.0, 5.0).Body;
            var body2 = TestSketchGenerator.CreateCircleWithArcs(3.0, 5).Body;

            body2.Position = body2.Position.Translated(new Vec(0, 0, 10.0));
            body2.Rotation = new Quaternion(20.0.ToRad(), 20.0.ToRad(), 0.0);

            var loft = Loft.Create(body1, new[] { new BodyShapeOperand(body2) });

            Assert.IsFalse(loft.Make(Shape.MakeFlags.None));
        }
Exemple #13
0
        public void SimpleRect()
        {
            var body1 = TestSketchGenerator.CreateRectangle(5.0, 5.0).Body;
            var body2 = TestSketchGenerator.CreateRectangle(5.0, 5.0).Body;

            body2.Position = body2.Position.Translated(new Vec(0, 0, 10.0));
            body2.Rotation = new Quaternion(20.0.ToRad(), 20.0.ToRad(), 0.0);

            var loft = Loft.Create(body1, new[] { new BodyShapeOperand(body2) });

            Assert.IsTrue(loft.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(loft, Path.Combine(_BasePath, "SimpleRect"));
        }
        //--------------------------------------------------------------------------------------------------

        public override bool Start()
        {
            _TargetBody = WorkspaceController.Selection.SelectedEntities.FirstOrDefault() as Body;
            if (_TargetBody == null)
            {
                return(false);
            }

            if (_TargetBody?.Shape?.ShapeType != ShapeType.Sketch)
            {
                if (_TargetBody.Shape is Loft)
                {
                    _LoftShape = _TargetBody.Shape as Loft;
                }
                else
                {
                    return(false);
                }
            }

            if (WorkspaceController.Selection.SelectedEntities.Count > 1)
            {
                foreach (var entity in WorkspaceController.Selection.SelectedEntities.Skip(1))
                {
                    var body = entity as Body;
                    if (body == null)
                    {
                        continue;
                    }

                    _AddOperand(body);
                }
                InteractiveContext.Current.UndoHandler.Commit();

                Stop();

                WorkspaceController.Selection.SelectEntity(_TargetBody);
                WorkspaceController.Invalidate();
                return(false);
            }

            if (!_StartToolAction())
            {
                return(false);
            }

            StatusText = "Select section sketches.";
            WorkspaceController.HudManager?.SetCursor(Cursors.SelectShape);
            return(true);
        }
Exemple #15
0
        public void SkipAdditionalWiresInSections()
        {
            var sketch1 = TestSketchGenerator.CreateRectangle(5.0, 5.0);
            var body1   = sketch1.Body;
            var body2   = TestSketchGenerator.CreateRectangle(5.0, 5.0).Body;

            body2.Position = body2.Position.Translated(new Vec(0, 0, 10.0));
            body2.Rotation = new Quaternion(20.0.ToRad(), 20.0.ToRad(), 0.0);

            sketch1.AddSegment(new SketchSegmentLine(sketch1.AddPoint(new Pnt2d(20, 20)), sketch1.AddPoint(new Pnt2d(22, 22))));

            var loft = Loft.Create(body1, new[] { new BodyShapeOperand(body2) });

            Assert.IsTrue(loft.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(loft, Path.Combine(_BasePath, "SimpleRect"));
        }
        //--------------------------------------------------------------------------------------------------

        void _AddOperand(Body operandBody)
        {
            if (operandBody?.Shape?.ShapeType == ShapeType.Sketch)
            {
                if (_LoftShape == null)
                {
                    _LoftShape = Loft.Create(_TargetBody, new[] { new BodyShapeOperand(operandBody) });
                }
                else
                {
                    _TargetBody.SaveTopologyUndo();
                    _LoftShape.AddOperand(new BodyShapeOperand(operandBody));
                }
                operandBody.IsVisible = false;
            }
        }
Exemple #17
0
        /***************************************************/

        public static BoundingBox Bounds(this Loft surface)
        {
            List <ICurve> curves = surface.Curves;

            if (curves.Count == 0)
            {
                return(null);
            }

            BoundingBox box = curves[0].IBounds();

            for (int i = 1; i < curves.Count; i++)
            {
                box += curves[i].IBounds();
            }

            return(box);
        }
 public JsonResult CreateLoft(Loft obj)
 {
     try
     {
         //add
         DataProvider.Entities.Lofts.Add(obj);
         DataProvider.Entities.SaveChanges();
         return(Json(new JsonResponse()
         {
             Success = true,
             Message = ConstantData.ResponseMessage.SuccessCreate
         }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception)
     {
         return(Json(new JsonResponse()
         {
             Success = false,
             Message = ConstantData.ResponseMessage.Error
         }, JsonRequestBehavior.AllowGet));
     }
 }
Exemple #19
0
        public void CappingModeNoneWithBezierSegments()
        {
            var sketch1 = Sketch.Create();

            sketch1.Points.Add(0, new Pnt2d(-59.051143806531094, 8.435877686647295));
            sketch1.Points.Add(1, new Pnt2d(-37.379664921868205, 11.053908692848184));
            sketch1.Points.Add(2, new Pnt2d(-51.924281622984239, 23.27138672178565));
            sketch1.Points.Add(3, new Pnt2d(-72.437392749422088, 25.059793263066492));
            sketch1.Segments.Add(0, new SketchSegmentBezier(0, 1, 2));
            sketch1.Segments.Add(1, new SketchSegmentBezier(0, 3, 2));
            Assume.That(sketch1.Make(Shape.MakeFlags.None));
            var body1 = Body.Create(sketch1);

            var sketch2 = Sketch.Create();

            sketch2.Points.Add(0, new Pnt2d(-51.131337703967631, 30.284053556015575));
            sketch2.Points.Add(1, new Pnt2d(-35.343442485191737, 8.4680528900707));
            sketch2.Points.Add(2, new Pnt2d(-58.881758993184889, 2.8705264034138014));
            sketch2.Points.Add(3, new Pnt2d(-78.401338536398725, 25.978263950894874));
            sketch2.Segments.Add(0, new SketchSegmentBezier(0, 1, 2));
            sketch2.Segments.Add(1, new SketchSegmentBezier(2, 3, 0));
            Assume.That(sketch2.Make(Shape.MakeFlags.None));
            var body2 = Body.Create(sketch2);

            TransformUtils.Translate(body2, new Vec(0, 0, 23.0534323259767));

            var loft = Loft.Create(body1, new[] { new BodyShapeOperand(body2) });

            loft.EndCapping = Loft.CappingMode.None;

            loft.ThickenDirection = Loft.Direction.Inwards;
            Assert.IsTrue(loft.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(loft, Path.Combine(_BasePath, "CappingModeNoneWithBezierSegmentsIn"));

            loft.ThickenDirection = Loft.Direction.Outwards;
            Assert.IsTrue(loft.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(loft, Path.Combine(_BasePath, "CappingModeNoneWithBezierSegmentsOut"));
        }
Exemple #20
0
        public void CappingModeNoneWithCircle()
        {
            // For OCCT_30055, the join type must be Intersect.

            var body1 = TestSketchGenerator.CreateRectangle(5.0, 5.0).Body;

            var body2 = TestSketchGenerator.CreateCircleWithArcs(3.0, 4).Body;

            body2.Position = body2.Position.Translated(new Vec(0, 0, 10.0));
            body2.Rotation = new Quaternion(20.0.ToRad(), 20.0.ToRad(), 0.0);

            var body3 = TestSketchGenerator.CreateRectangle(5.0, 5.0).Body;

            body3.Position = body3.Position.Translated(new Vec(0, 5.0, 20.0));
            body3.Rotation = new Quaternion(40.0.ToRad(), 40.0.ToRad(), 0.0);

            var loft = Loft.Create(body1, new[] { new BodyShapeOperand(body2), new BodyShapeOperand(body3) });

            loft.StartCapping = Loft.CappingMode.None;
            loft.EndCapping   = Loft.CappingMode.None;
            Assert.IsTrue(loft.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(loft, Path.Combine(_BasePath, "CappingModeNoneWithCircle"));
        }
Exemple #21
0
        public void OpenWiresRect()
        {
            // For OCCT_30054, the join type must be Intersect.

            // Remove first segment to create open wires
            var sketch1 = TestSketchGenerator.CreateRectangle(5.0, 5.0);

            sketch1.DeleteSegment(sketch1.Segments[0]);
            var body1 = sketch1.Body;

            var sketch2 = TestSketchGenerator.CreateRectangle(4.0, 4.0);

            sketch2.DeleteSegment(sketch2.Segments[0]);
            var body2 = sketch2.Body;

            body2.Position = body2.Position.Translated(new Vec(0, 0, 10.0));
            body2.Rotation = new Quaternion(20.0.ToRad(), 20.0.ToRad(), 0.0);

            var sketch3 = TestSketchGenerator.CreateRectangle(5.0, 5.0);

            sketch3.DeleteSegment(sketch3.Segments[0]);
            var body3 = sketch3.Body;

            body3.Position = body3.Position.Translated(new Vec(0, 5.0, 20.0));
            body3.Rotation = new Quaternion(40.0.ToRad(), 40.0.ToRad(), 0.0);

            var loft = Loft.Create(body1, new[] { new BodyShapeOperand(body2), new BodyShapeOperand(body3) });

            loft.ThickenDirection = Loft.Direction.Outwards;
            Assert.IsTrue(loft.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(loft, Path.Combine(_BasePath, "OpenWiresRect_Out"));

            loft.ThickenDirection = Loft.Direction.Inwards;
            Assert.IsTrue(loft.Make(Shape.MakeFlags.None));
            AssertHelper.IsSameModel(loft, Path.Combine(_BasePath, "OpenWiresRect_In"));
        }
 public JsonResult UpdateLoft(Loft obj)
 {
     try
     {
         //update
         var data = DataProvider.Entities.Lofts.Find(obj.Id);
         data.LoftDegress = obj.LoftDegress;
         data.OrderNumber = obj.OrderNumber;
         DataProvider.Entities.SaveChanges();
         return(Json(new JsonResponse()
         {
             Success = true,
             Message = ConstantData.ResponseMessage.SuccessUpdate
         }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception)
     {
         return(Json(new JsonResponse()
         {
             Success = false,
             Message = ConstantData.ResponseMessage.Error
         }, JsonRequestBehavior.AllowGet));
     }
 }
Exemple #23
0
        /***************************************************/

        public static Loft Transform(this Loft surface, TransformMatrix transform)
        {
            return(new Loft {
                Curves = surface.Curves.Select(x => x.ITransform(transform)).ToList()
            });
        }
Exemple #24
0
        /***************************************************/

        public static Loft Rotate(this Loft surface, Point origin, Vector axis, double rad)
        {
            TransformMatrix rotationMatrix = Create.RotationMatrix(origin, axis, rad);

            return(Transform(surface, rotationMatrix));
        }
Exemple #25
0
 public static List <Polyline> ToPolyline(this Loft loft)
 {
     return(loft.IExternalEdges().Select(x => x.ICollapseToPolyline(BH.oM.Geometry.Tolerance.Angle)).ToList());
 }
Exemple #26
0
        /***************************************************/

        public static Loft ProjectAlong(this Loft surface, Plane plane, Vector vector)
        {
            return(new Loft {
                Curves = surface.Curves.Select(x => x.IProjectAlong(plane, vector)).ToList()
            });
        }
Exemple #27
0
 public static Point ClosestPoint(this Loft surface, Point point)
 {
     throw new NotImplementedException();
 }
Exemple #28
0
        /***************************************************/

        public static Loft Scale(this Loft surface, Point origin, Vector scaleVector)
        {
            TransformMatrix scaleMatrix = Create.ScaleMatrix(origin, scaleVector);

            return(Transform(surface, scaleMatrix));
        }
Exemple #29
0
        /***************************************************/

        public static Loft Translate(this Loft surface, Vector transform)
        {
            return(new Loft {
                Curves = surface.Curves.Select(x => x.ITranslate(transform)).ToList()
            });
        }
Exemple #30
0
        /***************************************************/

        public static Loft Project(this Loft surface, Plane p)
        {
            return(new Loft {
                Curves = surface.Curves.Select(x => x.IProject(p)).ToList()
            });
        }