Пример #1
1
        /// <summary>
        /// Form a Refernece plane from two end points in the Active view.  The cut vector is the Z Axis.
        /// </summary>
        /// <param name="start">The location where the bubble will be located</param>
        /// <param name="end">The other end</param>
        /// <returns></returns>
        public static ReferencePlane ByStartPointEndPoint( Point start, Point end )
        {
            if (start == null)
            {
                throw new ArgumentNullException("start");
            }

            if (end == null)
            {
                throw new ArgumentNullException("end");
            }

            return new ReferencePlane(  start.ToXyz(), 
                                        end.ToXyz(),
                                        (end.ToXyz() - start.ToXyz()).GetPerpendicular(),
                                        Document.ActiveView);
        }
Пример #2
0
        public void NurbsCurve()
        {
            // create spline
            var pts = new Autodesk.DesignScript.Geometry.Point[]
            {
                Autodesk.DesignScript.Geometry.Point.ByCoordinates(0,0,0),
                Autodesk.DesignScript.Geometry.Point.ByCoordinates(1,0,0),
                Autodesk.DesignScript.Geometry.Point.ByCoordinates(3,0,0),
                Autodesk.DesignScript.Geometry.Point.ByCoordinates(10,0,0)
            };

            var spline = Autodesk.DesignScript.Geometry.NurbsCurve.ByControlPoints(pts, 3);

            Assert.NotNull(spline);
            Assert.AreEqual(3, spline.Degree);
            var eval0 = spline.PointAtParameter(0);
            var eval1 = spline.PointAtParameter(1);

            var expectedPoint0 = Point.ByCoordinates(0, 0, 0);
            var expectedPoint1 = Point.ByCoordinates(10, 0, 0);

            Assert.AreEqual(0, expectedPoint0.DistanceTo(eval0), 1e-6);
            Assert.AreEqual(0, expectedPoint1.DistanceTo(eval1), 1e-6);

            var closestPoint0 = spline.ClosestPointTo(expectedPoint0);
            Assert.AreEqual(0, expectedPoint0.DistanceTo(closestPoint0), 1e-6);
        }
Пример #3
0
        public void ByPoints_PointArray_ProducesValidAdaptiveComponentAndLocations()
        {
            var pts = new Point[]
            {
                Point.ByCoordinates(0, 0, 0),
                Point.ByCoordinates(10, 0, 10),
                Point.ByCoordinates(20, 0, 0)
            };
            var fs = FamilySymbol.ByName("3PointAC");
            var ac = AdaptiveComponent.ByPoints(pts, fs);

            var locs = ac.Locations;

            var pairs = locs.Zip(pts, (point, point1) => new Tuple<Point, Point>(point, point1));

            // compares after unit conversion
            foreach (var pair in pairs)
                pair.Item1.ShouldBeApproximately(pair.Item2);

            var unconvertedPairs = pts.Zip(GetInternalPoints((FamilyInstance) ac.InternalElement), 
                (point, point1) => new Tuple<Point, XYZ>(point, point1));

            foreach (var pair in unconvertedPairs)
            {
                pair.Item1.ShouldBeApproximately(pair.Item2 * UnitConverter.HostToDynamoFactor);
            }

            Assert.NotNull(ac);
        }
Пример #4
0
        private InvWorkPoint(Point point, IObjectBinder binder)
        {
            this.point = point;
            this.binder = binder;

            if (binder.DocumentManager.ActiveAssemblyDoc != null)
            {
                this.binder.ContextManager.BindingContextManager = binder.DocumentManager.ActiveAssemblyDoc.ReferenceKeyManager;
            }
            else if (binder.DocumentManager.ActivePartDoc != null)
            {
                this.binder.ContextManager.BindingContextManager = binder.DocumentManager.ActivePartDoc.ReferenceKeyManager;
            }
            this.binder.ContextManager.BindingContextManager = binder.DocumentManager.ActiveAssemblyDoc.ReferenceKeyManager;
            Inventor.WorkPoint wp;
            if (this.binder.GetObjectFromTrace<Inventor.WorkPoint>(out wp))
            {
                InternalWorkPoint = wp;
                AssemblyWorkPointDef wpDef = (AssemblyWorkPointDef)wp.Definition;
                wpDef.Point = point.ToPoint();
            }

            else
            {
                wp = binder.DocumentManager.ActiveAssemblyDoc.ComponentDefinition.WorkPoints.AddFixed(point.ToPoint(), false);
                InternalWorkPoint = wp;
                this.binder.SetObjectForTrace<InvWorkPoint>(this.InternalWorkPoint);
            }
        }
Пример #5
0
        /// <summary>
        /// Internal constructor for the AdaptiveComponent wrapper
        /// </summary>
        /// <param name="pts">Points to use as reference</param>
        /// <param name="fs">FamilySymbol to place</param>
        private AdaptiveComponent(Point[] pts, FamilySymbol fs)
        {

            // if the family instance is present in trace...
            var oldFam =
                ElementBinder.GetElementFromTrace<Autodesk.Revit.DB.FamilyInstance>(Document);

            // just mutate it...
            if (oldFam != null)
            {
               InternalSetFamilyInstance(oldFam);
                if (fs.InternalFamilySymbol.Id != oldFam.Symbol.Id)
                   InternalSetFamilySymbol(fs);
                InternalSetPositions(pts.ToXyzs());
                return;
            }

            // otherwise create a new family instance...
            TransactionManager.Instance.EnsureInTransaction(Document);

            var fam = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(Element.Document, fs.InternalFamilySymbol);

            if (fam == null)
                throw new Exception("An adaptive component could not be found or created.");

            InternalSetFamilyInstance(fam);
            InternalSetPositions(pts.ToXyzs());

            TransactionManager.Instance.TransactionTaskDone();

            // remember this value
            ElementBinder.SetElementForTrace(this.InternalElement);
        }
Пример #6
0
 protected Cone(Point startPoint, Point endPoint, double startRadius, double endRadius,bool persist)
     : base(ByStartPointEndPointRadiusCore(startPoint, endPoint, startRadius, endRadius),persist)
 {
     InitializeGuaranteedProperties();
     StartPoint = startPoint;
     EndPoint = endPoint;
     StartRadius = startRadius;
     EndRadius = endRadius;
 }
Пример #7
0
 /// <summary>
 /// Creates a Zone by a orientation, Origin and a building
 /// </summary>
 /// <param name="name"></param>
 /// <param name="orientation">The Orientation relative to the building</param>
 /// <param name="origin">The starting point of the zone</param>
 /// <param name="multiplier"></param>
 public Zone(string name, double orientation, Point origin, int multiplier = 1)
 {
     Name = name;
     Orientation = orientation;
     Origin = origin;
     Multiplier = multiplier;
     BuildingSurfaces = new List<BuildingSurface>();
     SurfaceNumber = 1;
 }
Пример #8
0
 /// <summary>
 /// Creates a Zone by a orientation, Origin and a building
 /// </summary>
 /// <param name="name"></param>
 /// <param name="orientation">The Orientation relative to the building</param>
 /// <param name="origin">The starting point of the zone</param>
 public Zone(string name, double orientation, Point origin)
 {
     Name = name;
     Orientation = orientation;
     Origin = origin;
     Multiplier = 1;
     Surfaces = new List<Surface>();
     SurfaceNumber = 1;
 }
Пример #9
0
 protected RevolvedSurface(Curve profile, Point axisOrigin, Vector axisDirection, double startAngle, double sweepAngle, bool persist)
     : base(ByProfileAxisOriginDirectionAngleCore(profile, axisOrigin, axisDirection, startAngle, sweepAngle), persist)
 {
     InitializeGuaranteedProperties();
     Profile = profile;
     AxisOrigin = axisOrigin;
     AxisDirection = axisDirection;
     StartAngle = startAngle;
     SweepAngle = sweepAngle;
 }
Пример #10
0
        public void ByPoints_NullFamilySymbol()
        {
            var pts = new Point[]
            {
                Point.ByCoordinates(0, 0, 0),
                Point.ByCoordinates(10, 0, 10),
                Point.ByCoordinates(20, 0, 0)
            };

            Assert.Throws(typeof(ArgumentNullException), () => AdaptiveComponent.ByPoints(pts, null));
        }
Пример #11
0
        public void ByPoints_ShouldThrowExceptionWithNonMatchingNumberOfPoints()
        {
            var pts = new Point[]
            {
                Point.ByCoordinates(0, 0, 0),
                Point.ByCoordinates(10, 0, 10)
            };
            var fs = FamilySymbol.ByName("3PointAC");

            Assert.Throws(typeof (Exception), () => AdaptiveComponent.ByPoints(pts, fs));
        }
Пример #12
0
        public void ByPoints_ValidInput()
        {
            var pts = new Point[]
            {
                Point.ByCoordinates(0, 0, 0),
                Point.ByCoordinates(10, 0, 10),
                Point.ByCoordinates(20, 0, 0)
            };
            var fs = FamilySymbol.ByName("3PointAC");
            var ac = AdaptiveComponent.ByPoints(pts, fs);

            Assert.NotNull(ac);
        }
Пример #13
0
        public static Dictionary<string,object> ByOriginDirection(Point origin, Vector direction, int maxBounces, Elements.Views.View3D view)
        {
            var startpt = origin.ToXyz();
            var rayCount = 0;

            var bouncePts = new List<Point> {origin};
            var bounceElements = new List<Elements.Element>();

            for (int ctr = 1; ctr <= maxBounces; ctr++)
            {
                var referenceIntersector = new ReferenceIntersector((View3D)view.InternalElement);
                IList<ReferenceWithContext> references = referenceIntersector.Find(startpt, direction.ToXyz());
                ReferenceWithContext rClosest = null;
                rClosest = FindClosestReference(references);
                if (rClosest == null)
                {
                    break;
                }
                else
                {
                    var reference = rClosest.GetReference();
                    var referenceElement = DocumentManager.Instance.CurrentDBDocument.GetElement(reference);
                    var referenceObject = referenceElement.GetGeometryObjectFromReference(reference);
                    bounceElements.Add(referenceElement.ToDSType(true));
                    var endpt = reference.GlobalPoint;
                    if (startpt.IsAlmostEqualTo(endpt))
                    {
                        break;
                    }
                    else
                    {
                        rayCount = rayCount + 1;
                        var currFace = referenceObject as Face;
                        var endptUV = reference.UVPoint;
                        var FaceNormal = currFace.ComputeDerivatives(endptUV).BasisZ;  // face normal where ray hits
                        FaceNormal = rClosest.GetInstanceTransform().OfVector(FaceNormal); // transformation to get it in terms of document coordinates instead of the parent symbol
                        var directionMirrored = direction.ToXyz() - 2 * direction.ToXyz().DotProduct(FaceNormal) * FaceNormal; //http://www.fvastro.org/presentations/ray_tracing.htm
                        direction = directionMirrored.ToVector(); // get ready to shoot the next ray
                        startpt = endpt;
                        bouncePts.Add(endpt.ToPoint());
                    }
                }
            }

            return new Dictionary<string, object>
            {
                { "points", bouncePts },
                { "elements", bounceElements }
            };
        }
Пример #14
0
        public void Line_Basic()
        {
            var line = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(Point.ByCoordinates(1, 2, 3), Point.ByCoordinates(2, 4, 6));

            Console.WriteLine(line.PointAtParameter(0.5).ToXyz());

            var revitCurve = line.ToRevitType(false);

            Assert.NotNull(revitCurve);

            Assert.IsAssignableFrom <Autodesk.Revit.DB.Line>(revitCurve);

            var revitArc = (Autodesk.Revit.DB.Line)revitCurve;

            line.StartPoint.ShouldBeApproximately(revitArc.GetEndPoint(0).ToPoint(false));
            line.EndPoint.ShouldBeApproximately(revitArc.GetEndPoint(1).ToPoint(false));
        }
Пример #15
0
        public void ByEyePointAndTarget_ValidAbstractElement()
        {
            var eye    = Point.ByCoordinates(100, 100, 100);
            var target = Point.ByCoordinates(0, 1, 2);
            var name   = "treeView";

            var famSym  = FamilySymbol.ByName("Kousa Dogwood - 10'");
            var pt      = Point.ByCoordinates(0, 1, 2);
            var famInst = FamilyInstance.ByPoint(famSym, pt);

            object element = famInst;
            var    view    = AxonometricView.ByEyePointAndTarget(eye, target, element, name, false);

            Assert.NotNull(view);
            Assert.IsTrue(DocumentManager.Instance.ElementExistsInDocument(
                              new ElementUUID(view.InternalElement.UniqueId)));
        }
Пример #16
0
        /// <summary>
        /// Create an Advance Steel unbounded Rectangular Pattern at a Point
        /// </summary>
        /// <param name="connectionPoint"> Input Insertion point of Anchor Bolt Pattern </param>
        /// <param name="boltCS"> Input Anchor Bolt Coordinate System </param>
        /// <param name="noOfBoltsX"> Input No of Anchor Bolts in the X direction</param>
        /// <param name="noOfBoltsY"> Input No of Anchor Bolts in the Y direction</param>
        /// <param name="objectsToConnect"> Input Objects to be bolted </param>
        /// <param name="boltConnectionType"> Input Bolt Connection type - Shop Bolt Default</param>
        /// <param name="additionalAnchorBoltParameters"> Optional Input Anchor Bolt Build Properties </param>
        /// <returns name="rectangularAnchorPattern"> rectangularAnchorPattern</returns>
        public static RectangularAnchorPattern AtCentrePoint(Autodesk.DesignScript.Geometry.Point connectionPoint,
                                                             Autodesk.DesignScript.Geometry.CoordinateSystem boltCS,
                                                             [DefaultArgument("2;")] int noOfBoltsX,
                                                             [DefaultArgument("2;")] int noOfBoltsY,
                                                             IEnumerable <SteelDbObject> objectsToConnect,
                                                             [DefaultArgument("2;")] int boltConnectionType,
                                                             [DefaultArgument("null")] List <Property> additionalAnchorBoltParameters)
        {
            List <string> handlesList = Utils.GetSteelDbObjectsToConnect(objectsToConnect);

            var vx = Utils.ToAstVector3d(boltCS.XAxis, true);
            var vy = Utils.ToAstVector3d(boltCS.YAxis, true);

            additionalAnchorBoltParameters = PreSetValuesInListProps(additionalAnchorBoltParameters, noOfBoltsX, noOfBoltsY);

            return(new RectangularAnchorPattern(Utils.ToAstPoint(connectionPoint, true), handlesList, vx, vy, additionalAnchorBoltParameters, boltConnectionType));
        }
Пример #17
0
        public void Arc_Basic()
        {
            var circ = Autodesk.DesignScript.Geometry.Arc.ByCenterPointRadiusAngle(Point.ByCoordinates(1, 2, 3), 4,
                                                                                   0.4, 1.3, Vector.ByCoordinates(1, 2, 3));

            var revitCurve = circ.ToRevitType(false);

            Assert.NotNull(revitCurve);

            Assert.IsAssignableFrom <Autodesk.Revit.DB.Arc>(revitCurve);

            var revitArc = (Autodesk.Revit.DB.Arc)revitCurve;

            circ.CenterPoint.ShouldBeApproximately(revitArc.Center.ToPoint(false));
            circ.Radius.ShouldBeApproximately(revitArc.Radius);
            Math.Abs(circ.Normal.Dot(revitArc.Normal.ToVector())).ShouldBeApproximately(1);
        }
Пример #18
0
        /// <summary>
        /// Form a Refernece plane from two end points in the Active view.  The cut vector is the Z Axis.
        /// </summary>
        /// <param name="start">The location where the bubble will be located</param>
        /// <param name="end">The other end</param>
        /// <returns></returns>
        public static ReferencePlane ByStartPointEndPoint(Point start, Point end)
        {
            if (start == null)
            {
                throw new ArgumentNullException("start");
            }

            if (end == null)
            {
                throw new ArgumentNullException("end");
            }

            return(new ReferencePlane(start.ToXyz(),
                                      end.ToXyz(),
                                      (end.ToXyz() - start.ToXyz()).GetPerpendicular(),
                                      Document.ActiveView));
        }
Пример #19
0
        public void ByPointsOnCurve_ProducesValidAdaptiveComponentAndLocations()
        {
            // create spline
            var pts = new Autodesk.DesignScript.Geometry.Point[]
            {
                Point.ByCoordinates(0, 0, 0),
                Point.ByCoordinates(1, 0, 0),
                Point.ByCoordinates(3, 0, 0),
                Point.ByCoordinates(10, 0, 0),
                Point.ByCoordinates(12, 0, 0),
            };

            var spline = NurbsCurve.ByControlPoints(pts, 3);

            Assert.NotNull(spline);

            // build model curve from spline
            var modCurve = ModelCurve.ByCurve(spline);

            Assert.NotNull(modCurve);

            // obtain the family from the document
            var ft = FamilyType.ByName("3PointAC");

            // build the AC
            var parms = new double[] { 0, 0.5, 1 };

            var ac = AdaptiveComponent.ByParametersOnCurveReference(parms, modCurve, ft);

            // with unit conversion
            foreach (var pt in ac.Locations)
            {
                spline.DistanceTo(pt).ShouldBeApproximately(0);
            }

            // without unit conversion
            var unconvertedPoints = GetInternalPoints((FamilyInstance)ac.InternalElement);

            foreach (var pt in unconvertedPoints)
            {
                spline.DistanceTo(pt.ToPoint()).ShouldBeApproximately(0);
            }

            Assert.NotNull(ac);
        }
Пример #20
0
        /// <summary>
        /// Place an instance of a Model Group into the Autodesk Revit document, using a location and a group type.
        /// </summary>
        /// <param name="location">The point to place the group.</param>
        /// <param name="groupType">The type of group to place.</param>
        /// <returns>The new group instance.</returns>
        public static Group PlaceInstance(Autodesk.DesignScript.Geometry.Point location, Element groupType)
        {
            var internalType = groupType.InternalElement as Autodesk.Revit.DB.GroupType;

            if (internalType == null)
            {
                throw new InvalidOperationException(String.Format(Properties.Resources.InvalidGroupType, nameof(groupType)));
            }

            XYZ newLocation = location.ToRevitType(true);

            TransactionManager.Instance.EnsureInTransaction(Document);
            Group newGroup = Document.Create.PlaceGroup(newLocation, internalType).ToDSType(true) as Group;

            TransactionManager.Instance.TransactionTaskDone();

            return(newGroup);
        }
Пример #21
0
        internal List <Geo.Line> GetLinesAtParameter(tAgent[] agents, double parameter)
        {
            var lines = new List <Geo.Line>();

            Geo.Point p = GetFurtherIntersection(_faceIndexA, agents);
            lines.Add(Geo.Line.ByStartPointDirectionLength(_edge.PointAtParameter(parameter), _lineDirectionA, 1));
            if (!_isNaked)
            {
                p = GetFurtherIntersection(_faceIndexB, agents);
                lines.Add(Geo.Line.ByStartPointDirectionLength(_edge.PointAtParameter(parameter), _lineDirectionB, 1));
            }

            // Dispose
            {
                p.Dispose();
            }
            return(lines);
        }
Пример #22
0
        /// <summary>
        /// Create an Advance Steel Circular Anchor Pattern By Center Point and Dynamo Coordinate System
        /// </summary>
        /// <param name="point"> Input radius center point</param>
        /// <param name="anchorCS"> Input Dynamo Coordinate System</param>
        /// <param name="objectsToConnect"> Input Objects to be bolted </param>
        /// <param name="anchorBoltConnectionType"> Input Bolt Connection type - Shop Bolt Default</param>
        /// <param name="additionalAnchorBoltParameters"> Optional Input Bolt Build Properties </param>
        /// <returns name="circularAnchorPattern"> anchor</returns>
        public static CircularAnchorPattern AtCentrePoint(DynGeometry.Point point,
                                                          DynGeometry.CoordinateSystem anchorCS,
                                                          IEnumerable <SteelDbObject> objectsToConnect,
                                                          [DefaultArgument("2;")] int anchorBoltConnectionType,
                                                          [DefaultArgument("null")] List <Property> additionalAnchorBoltParameters)
        {
            SteelGeometry.Point3d astPointRef = Utils.ToAstPoint(point, true);

            var vx = Utils.ToAstVector3d(anchorCS.XAxis, true);
            var vy = Utils.ToAstVector3d(anchorCS.YAxis, true);

            vx = vx.Normalize();
            vy = vy.Normalize();

            IEnumerable <string> handles = Utils.GetSteelDbObjectsToConnect(objectsToConnect);

            return(new CircularAnchorPattern(astPointRef, handles, vx, vy, additionalAnchorBoltParameters, anchorBoltConnectionType));
        }
Пример #23
0
        private InvWorkPoint(Point point, IObjectBinder binder)
        {
            _binder = binder;
            Inventor.WorkPoint wp;
            if (_binder.GetObjectFromTrace <Inventor.WorkPoint>(out wp))
            {
                InternalWorkPoint = wp;
                AssemblyWorkPointDef wpDef = (AssemblyWorkPointDef)wp.Definition;
                wpDef.Point = point.ToPoint();
            }

            else
            {
                wp = PersistenceManager.ActiveAssemblyDoc.ComponentDefinition.WorkPoints.AddFixed(point.ToPoint(), false);
                InternalWorkPoint = wp;
                _binder.SetObjectForTrace <WorkPoint>(this.InternalWorkPoint);
            }
        }
Пример #24
0
        /// <summary>
        /// Callback method when gizmo is moved by user action.
        /// </summary>
        /// <param name="gizmo">Gizmo that moved.</param>
        /// <param name="offset">Offset by which the gizmo has moved.</param>
        /// <returns>New expected position of the Gizmo</returns>
        protected override Point OnGizmoMoved(IGizmo gizmo, Vector offset)
        {
            expectedPosition = origin.Add(offset);

            foreach (var item in indexedAxisNodePairs)
            {
                // When more than one input is connected to the same slider, this
                // method will decompose the axis corresponding to each input.
                var v      = GetFirstAxisComponent(item.Value.Item1);
                var amount = Math.Round(offset.Dot(v), 3);
                if (Math.Abs(amount) > 0.001)
                {
                    ModifyInputNode(item.Value.Item2, amount);
                }
            }

            return(expectedPosition);
        }
Пример #25
0
        public void ByCoordinates_ProducesValidFamilyInstanceWithCorrectLocation()
        {
            var famSym  = FamilyType.ByName("Box");
            var famInst = FamilyInstance.ByCoordinates(famSym, 0, 1, 2);

            Assert.NotNull(famInst);

            var position = famInst.Location;

            position.ShouldBeApproximately(Point.ByCoordinates(0, 1, 2));

            // no unit conversion
            var internalPos =
                InternalLocation(famInst.InternalElement as Autodesk.Revit.DB.FamilyInstance);

            (internalPos * UnitConverter.HostToDynamoFactor(SpecTypeId.Length)).ShouldBeApproximately(
                Point.ByCoordinates(0, 1, 2));
        }
Пример #26
0
        public void CurvesAreSimilar_Lines()
        {
            var a = Point.ByCoordinates(0, 0);
            var b = Point.ByCoordinates(1, 1);
            var c = Point.ByCoordinates(2, 2);

            var line1 = Line.ByStartPointEndPoint(a, b);
            var line2 = Line.ByStartPointEndPoint(b, a);
            var line3 = Line.ByStartPointEndPoint(a, c);

            var revitLine1 = line1.ToRevitType();
            var revitLine2 = line2.ToRevitType();
            var revitLine3 = line3.ToRevitType();

            Assert.True(CurveUtils.CurvesAreSimilar(revitLine1, revitLine1));
            Assert.False(CurveUtils.CurvesAreSimilar(revitLine1, revitLine2));
            Assert.False(CurveUtils.CurvesAreSimilar(revitLine1, revitLine3));
        }
Пример #27
0
        public static Dictionary <string, object> LocationData(global::Revit.Elements.Element viewport)
        {
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
            //obtain the element id from the sheet
            Autodesk.Revit.DB.Viewport internalViewport = (Autodesk.Revit.DB.Viewport)viewport.InternalElement;
            //obtain the box center of the viewport
            var boxCenterInternal = internalViewport.GetBoxCenter().ToPoint();

            //Construct new point at sheet elevation of 0
            Autodesk.DesignScript.Geometry.Point boxCenter =
                Autodesk.DesignScript.Geometry.Point.ByCoordinates(boxCenterInternal.X, boxCenterInternal.Y, 0);
            //this obtains the box outline
            var boxOutline = internalViewport.GetBoxOutline();
            var bBox       = BoundingBox.ByCorners(boxOutline.MaximumPoint.ToPoint(), boxOutline.MinimumPoint.ToPoint());
            var boxCuboid  = Cuboid.ByCorners(boxOutline.MaximumPoint.ToPoint(), boxOutline.MinimumPoint.ToPoint());
            //create plane that corresponds to sheet plane
            Plane boxPlane   = Plane.ByOriginNormal(boxOutline.MaximumPoint.ToPoint(), Vector.ZAxis());
            var   boxSurface = boxCuboid.Intersect(boxPlane);
            List <Autodesk.DesignScript.Geometry.Curve[]> boxCurves = new List <Autodesk.DesignScript.Geometry.Curve[]>();

            foreach (Surface surf in boxSurface)
            {
                boxCurves.Add(surf.PerimeterCurves());
            }
            List <Autodesk.DesignScript.Geometry.Curve> boxSheetCurves = new List <Autodesk.DesignScript.Geometry.Curve>();

            //pull the curves onto a plane at 0,0,0
            foreach (Autodesk.DesignScript.Geometry.Curve[] curve in boxCurves)
            {
                foreach (Autodesk.DesignScript.Geometry.Curve c in curve)
                {
                    boxSheetCurves.Add(c.PullOntoPlane(Plane.XY()));
                }
            }
            //returns the outputs
            var outInfo = new Dictionary <string, object>
            {
                { "bBox", bBox },
                { "boxCenter", boxCenter },
                { "boxOutline", boxSheetCurves }
            };

            return(outInfo);
        }
Пример #28
0
        public static List <Point> ByCoordinateSystems(IEnumerable <BoundingBox> boundingBoxes, double width, double height, double gap)
        {
            var locs = new List <Point>();

            var packer = new CygonRectanglePacker(width, height);

            foreach (var bbox in boundingBoxes)
            {
                var packLocation = UV.ByCoordinates();
                var w            = bbox.MaxPoint.X - bbox.MinPoint.X + gap;
                var h            = bbox.MaxPoint.Y - bbox.MinPoint.Y + gap;
                if (packer.TryPack(w, h, out packLocation))
                {
                    locs.Add(Point.ByCoordinates(packLocation.U, packLocation.V, 0));
                }
            }

            return(locs);
        }
Пример #29
0
        /// <summary>
        /// Implements the MouseMove event handler for the manipulator
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="mouseEventArgs"></param>
        protected virtual void MouseMove(object sender, MouseEventArgs mouseEventArgs)
        {
            if (!IsEnabled())
            {
                return;
            }

            var clickRay = BackgroundPreviewViewModel.GetClickRay(mouseEventArgs);

            if (clickRay == null)
            {
                return;
            }

            if (GizmoInAction == null)
            {
                HighlightGizmoOnRollOver(clickRay);
                return;
            }

            var offset = GizmoInAction.GetOffset(clickRay.GetOriginPoint(), clickRay.GetDirectionVector());

            if (offset.Length < 0.01)
            {
                return;
            }

            if (originAfterMove != null)
            {
                var offsetPos = originAfterMove.Add(offset);
                originAfterMove.Dispose();
                originAfterMove = offsetPos;
            }

            // Update input nodes attached to manipulator node
            // Doing this triggers a graph update on scheduler thread
            OnGizmoMoved(GizmoInAction, offset);

            // redraw manipulator at new position synchronously
            var packages = BuildRenderPackage();

            BackgroundPreviewViewModel.AddGeometryForRenderPackages(packages);
        }
Пример #30
0
        public static DS.Circle GetAsCircle(this DS.Curve curve)
        {
            if (!curve.IsClosed)
            {
                throw new ArgumentException("Curve is not closed, cannot be a Circle");
            }

            DS.Point start = curve.StartPoint;
            using (DS.Point midPoint = curve.PointAtParameter(0.5))
                using (DS.Point centre = DS.Point.ByCoordinates(Median(start.X, midPoint.X), Median(start.Y, midPoint.Y),
                                                                Median(start.Z, midPoint.Z)))
                {
                    return(DS.Circle.ByCenterPointRadiusNormal(
                               centre,
                               centre.DistanceTo(start),
                               curve.Normal
                               ));
                }
        }
Пример #31
0
        public void Circle_Basic()
        {
            var radius = 4;
            var circ   = Autodesk.DesignScript.Geometry.Circle.ByCenterPointRadiusNormal(
                Point.ByCoordinates(1, 2, 3), radius,
                Vector.ByCoordinates(0, 0, 1));

            var revitCurve = circ.ToRevitType();

            Assert.NotNull(revitCurve);

            Assert.IsAssignableFrom <Autodesk.Revit.DB.Arc>(revitCurve);

            var revitArc = (Autodesk.Revit.DB.Arc)revitCurve;

            circ.CenterPoint.AssertShouldBeApproximately(revitArc.Center.ToPoint());
            circ.Radius.AssertShouldBeApproximately(revitArc.Radius);
            circ.Normal.AssertShouldBeApproximately(revitArc.Normal.ToVector());
        }
Пример #32
0
        /// <summary>
        /// Create Advance Steel Variable Grating by Dynamo Rectangle and Point and Vectors
        /// </summary>
        /// <param name="origin"> Input Dynamo Point</param>
        /// <param name="xVector"> Input Dynamo X Vector</param>
        /// <param name="yVector"> Input Dynamo Y Vector</param>
        /// <param name="gratingClass"> Input Grating Class</param>
        /// <param name="gratingName"> Input Grating Size</param>
        /// <param name="width"> Input Grating Width</param>
        /// <param name="length"> Input Grating Length</param>
        /// <param name="additionalGratingParameters"> Optional Input Grating Build Properties </param>
        /// <returns name="variableGrating"> grating</returns>
        public static VariableGrating ByRectangularByPointAndVectors(Autodesk.DesignScript.Geometry.Point origin,
                                                                     Autodesk.DesignScript.Geometry.Vector xVector,
                                                                     Autodesk.DesignScript.Geometry.Vector yVector,
                                                                     string gratingClass,
                                                                     string gratingName,
                                                                     double width,
                                                                     double length,
                                                                     [DefaultArgument("null")] List <Property> additionalGratingParameters)
        {
            Autodesk.DesignScript.Geometry.CoordinateSystem coordinateSystem = Autodesk.DesignScript.Geometry.CoordinateSystem.ByOriginVectors(origin, xVector, yVector);

            additionalGratingParameters = PreSetDefaults(additionalGratingParameters, gratingClass, gratingName);

            return(new VariableGrating(Utils.ToAstPoint(coordinateSystem.Origin, true),
                                       Utils.ToAstVector3d(coordinateSystem.ZAxis, true),
                                       Utils.ToInternalDistanceUnits(width, true),
                                       Utils.ToInternalDistanceUnits(length, true),
                                       additionalGratingParameters));
        }
Пример #33
0
        Geo.Line GetMemberLineR(int faceIndex, int edgeIndex, bool rightHand)
        {
            Geo.Point p1 = mesh.faces[faceIndex].vertices[edgeIndex].ToPoint();
            Geo.Point p2 = mesh.faces[faceIndex].vertices[(edgeIndex + 1) % 4].ToPoint();
            Geo.Point p3 = mesh.faces[faceIndex].vertices[(edgeIndex + 2) % 4].ToPoint();

            Geo.Point memberPoint     = GetMemberPointOnEdge(faceIndex, edgeIndex, rightHand);
            Geo.Point nextMemberPoint = GetMemberPointOnEdge(faceIndex, (edgeIndex + 1) % 4, rightHand);

            Geo.Vector v1 = Geo.Vector.ByTwoPoints(p2, p1);
            Geo.Vector v2 = Geo.Vector.ByTwoPoints(p2, p3);

            double l = p2.DistanceTo(nextMemberPoint);
            double x = p2.DistanceTo(memberPoint);
            double a = 90 - v1.AngleWithVector(v2);

            a = (a * (Math.PI / 180));

            double d1 = x / (Math.Tan(a));
            double d2 = (x / Math.Sin(a)) - l;
            double d3 = Math.Cos(a);

            double length = d1 - (d2 / d3);

            Geo.Vector direction = v1.Cross(v1.Cross(v2));
            direction = direction.Reverse();

            var returnLine = Geo.Line.ByStartPointDirectionLength(memberPoint, direction, length);

            // Dispose

            /*{
             *  p1.Dispose();
             *  p2.Dispose();
             *  p3.Dispose();
             *  memberPoint.Dispose();
             *  nextMemberPoint.Dispose();
             *  v1.Dispose();
             *  v2.Dispose();
             *  direction.Dispose();
             * }*/
            return(returnLine);
        }
Пример #34
0
        public static Point PolygonCentroidByPoints(IList <Point> vertices)
        {
            var cx = 0.0;
            var cy = 0.0;

            double signedArea = 0.0;
            double x0         = 0.0; // Current vertex X
            double y0         = 0.0; // Current vertex Y
            double x1         = 0.0; // Next vertex X
            double y1         = 0.0; // Next vertex Y
            double a          = 0.0; // Partial signed area

            // For all vertices except last
            int i = 0;

            for (i = 0; i < vertices.Count - 1; ++i)
            {
                x0          = vertices[i].X;
                y0          = vertices[i].Y;
                x1          = vertices[i + 1].X;
                y1          = vertices[i + 1].Y;
                a           = x0 * y1 - x1 * y0;
                signedArea += a;
                cx         += (x0 + x1) * a;
                cy         += (y0 + y1) * a;
            }

            // Do last vertex
            x0          = vertices[i].X;
            y0          = vertices[i].Y;
            x1          = vertices[0].X;
            y1          = vertices[0].Y;
            a           = x0 * y1 - x1 * y0;
            signedArea += a;
            cx         += (x0 + x1) * a;
            cy         += (y0 + y1) * a;

            signedArea *= 0.5;
            cx         /= (6.0 * signedArea);
            cy         /= (6.0 * signedArea);

            return(Point.ByCoordinates(cx, cy, vertices[0].Z));
        }
Пример #35
0
        public static bool IsArc(this DS.Curve curve)
        {
            try
            {
                if (curve.IsClosed)
                {
                    return(false);
                }

                using (DS.Point midPoint = curve.PointAtParameter(0.5))
                    using (DS.Arc arc = DS.Arc.ByThreePoints(curve.StartPoint, midPoint, curve.EndPoint))
                    {
                        return(Threshold(arc.Length, curve.Length));
                    }
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Пример #36
0
        public static bool IsCircle(this DS.Curve curve)
        {
            try
            {
                if (!curve.IsClosed)
                {
                    return(false);
                }

                using (DS.Point midPoint = curve.PointAtParameter(0.5))
                {
                    double radius = curve.StartPoint.DistanceTo(midPoint) * 0.5;
                    return(Threshold(radius, (curve.Length) / (2 * Math.PI)));
                }
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Пример #37
0
        public static List <CoordinateSystem> CoordinateSystem(Revit.Elements.Element[] LinkInstance)
        {
            List <CoordinateSystem> coordinates = new List <CoordinateSystem>();
            var doc = DocumentManager.Instance.CurrentDBDocument;

            foreach (Revit.Elements.Element i in LinkInstance)
            {
                ElementId                            elementId = Spring.Elements.UnwrapElement(i);
                RevitLinkInstance                    elem      = doc.GetElement(elementId) as RevitLinkInstance;
                Autodesk.Revit.DB.Document           linkDoc   = elem.GetLinkDocument();
                Transform                            transform = elem.GetTransform();
                Autodesk.DesignScript.Geometry.Point point     = transform.Origin.ToPoint(true);
                Vector           bx = transform.BasisX.ToVector();
                Vector           by = transform.BasisY.ToVector();
                Vector           bz = transform.BasisZ.ToVector();
                CoordinateSystem x  = Autodesk.DesignScript.Geometry.CoordinateSystem.ByOriginVectors(point, bx, by, bz);
                coordinates.Add(x);
            }
            return(coordinates);
        }
Пример #38
0
        /// <summary>
        /// Implements the MouseDown event handler for the manipulator
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="mouseButtonEventArgs"></param>
        protected virtual void MouseDown(object sender, MouseButtonEventArgs mouseButtonEventArgs)
        {
            UpdatePosition();

            GizmoInAction = null; //Reset Drag.

            var gizmos = GetGizmos(false);

            if (!IsEnabled() || null == gizmos || !gizmos.Any())
            {
                return;
            }

            var ray = BackgroundPreviewViewModel.GetClickRay(mouseButtonEventArgs);

            if (ray == null)
            {
                return;
            }

            foreach (var item in gizmos)
            {
                using (var originPt = ray.GetOriginPoint())
                    using (var dirVec = ray.GetDirectionVector())
                    {
                        object hitObject;
                        if (item.HitTest(originPt, dirVec, out hitObject))
                        {
                            GizmoInAction = item;

                            var nodes = OnGizmoClick(item, hitObject).ToList();
                            if (nodes.Any())
                            {
                                WorkspaceModel.RecordModelsForModification(nodes);
                            }
                            newPosition = Origin;
                            return;
                        }
                    }
            }
        }
Пример #39
0
        public void ToRevitType_ExtensionMethod_DoesExpectedUnitConversion()
        {
            // testing
            var pts = new[]
            {
                Point.ByCoordinates(10, 2, 3)
                , Point.ByCoordinates(0, 2, 2)
                , Point.ByCoordinates(10, 4, 8)
                , Point.ByCoordinates(10, 2, 8)
                , Point.ByCoordinates(5, 5, 5)
            };

            var bspline = NurbsCurve.ByControlPoints(pts, 3);

            // do scaling for check
            var metersToFeet  = 1 / 0.3048;
            var bsplineScaled = (NurbsCurve)bspline.Scale(metersToFeet);

            // by default, performs conversion
            var revitCurve = bspline.ToRevitType();

            Assert.NotNull(revitCurve);
            Assert.IsAssignableFrom <Autodesk.Revit.DB.NurbSpline>(revitCurve);

            var revitSpline = (Autodesk.Revit.DB.NurbSpline)revitCurve;

            Assert.AreEqual(bsplineScaled.Degree, revitSpline.Degree);
            Assert.AreEqual(bsplineScaled.ControlPoints().Count(), revitSpline.CtrlPoints.Count);

            // We tesselate but not convert units. We are trying to find out if
            // ToRevitType did the conversion properly by comparing to a scaled
            // version of the original bspline (bsplineScaled)
            var tessPts = revitSpline.Tessellate().Select(x => x.ToPoint(false));

            //assert the tesselation is very close to original curve
            foreach (var pt in tessPts)
            {
                var closestPt = bsplineScaled.ClosestPointTo(pt);
                Assert.Less(closestPt.DistanceTo(pt), 1e-6);
            }
        }
Пример #40
0
        /// <summary>
        /// Create a Reference Point Element offset from a point along a vector
        /// </summary>
        /// <param name="basePoint"></param>
        /// <param name="direction"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        public static ReferencePoint ByPointVectorDistance(Point basePoint, Vector direction, double distance)
        {
            if (!Document.IsFamilyDocument)
            {
                throw new Exception("ReferencePoint Elements can only be created in a Family Document");
            }

            if (basePoint == null)
            {
                throw new ArgumentNullException("basePoint");
            }

            if (direction == null)
            {
                throw new ArgumentNullException("direction");
            }

            var pt = (Point)basePoint.Translate(direction.Scale(distance));

            return(new ReferencePoint(pt.ToXyz()));
        }
Пример #41
0
        /// <summary>
        /// Creates a Conduit by a curve.
        /// </summary>
        /// <param name="conduitType">Type of the conduit.</param>
        /// <param name="curve">The curve.</param>
        /// <returns></returns>
        public static Conduit ByCurve(Revit.Elements.Element conduitType, Autodesk.DesignScript.Geometry.Curve curve)
        {
            Utils.Log(string.Format("Conduit.ByCurve started...", ""));

            var totalTransform = RevitUtils.DocumentTotalTransform();

            UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument);
            var oType = conduitType.InternalElement as Autodesk.Revit.DB.Electrical.ConduitType;

            Autodesk.DesignScript.Geometry.Point start = curve.StartPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point;
            var s = start.ToXyz();

            Autodesk.DesignScript.Geometry.Point end = curve.EndPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point;
            var e = end.ToXyz();

            totalTransform.Dispose();

            Utils.Log(string.Format("Conduit.ByCurve completed.", ""));

            return(new Conduit(oType, s, e));
        }
Пример #42
0
        public void ByGeometry_ProvidesExpectedConversion()
        {
            // construct the cuboid in meters
            var c0     = Point.ByCoordinates(-1, -1, -1);
            var c1     = Point.ByCoordinates(1, 1, 1);
            var cuboid = Cuboid.ByCorners(c0, c1);

            // import
            var import = Revit.Elements.ImportInstance.ByGeometry(cuboid);

            // extract geometry
            var importGeometry = import.Geometry().First();

            Assert.IsAssignableFrom(typeof(Autodesk.DesignScript.Geometry.Solid), importGeometry);

            var solidImport = (Autodesk.DesignScript.Geometry.Solid)importGeometry;

            cuboid.Volume.ShouldBeApproximately(solidImport.Volume);
            cuboid.BoundingBox.MinPoint.ShouldBeApproximately(solidImport.BoundingBox.MinPoint);
            cuboid.BoundingBox.MaxPoint.ShouldBeApproximately(solidImport.BoundingBox.MaxPoint);
        }
Пример #43
0
        public void ByNameNumberTitleBlockAndView_ValidArgs()
        {
            ElementBinder.IsEnabled = false;

            var famSymName = "E1 30x42 Horizontal";
            var famName    = "E1 30 x 42 Horizontal";
            var titleBlock = FamilySymbol.ByFamilyAndName(Family.ByName(famName), famSymName);

            var famSym  = FamilySymbol.ByName("Kousa Dogwood - 10'");
            var pt      = Point.ByCoordinates(0, 1, 2);
            var famInst = FamilyInstance.ByPoint(famSym, pt);

            var view = SectionView.ByBoundingBox(famInst.BoundingBox);

            var sheetName   = "Poodle";
            var sheetNumber = "A1";

            var ele = Sheet.ByNameNumberTitleBlockAndView(sheetName, sheetNumber, titleBlock, view);

            Assert.NotNull(ele);
        }
Пример #44
0
        public void ByCurveAndEqualDivisions_InvalidDivisions()
        {
            // create spline
            var pts = new Autodesk.DesignScript.Geometry.Point[]
            {
                Point.ByCoordinates(0,0,0),
                Point.ByCoordinates(1,0,0),
                Point.ByCoordinates(3,0,0),
                Point.ByCoordinates(10,0,0),
                Point.ByCoordinates(12,0,0),
            };

            var spline = NurbsCurve.ByControlPoints(pts, 3);
            Assert.NotNull(spline);

            // build model curve from spline
            var modCurve = ModelCurve.ByCurve(spline);
            Assert.NotNull(modCurve);

            // build dividedPath
            Assert.Throws(typeof(Exception), () => DividedPath.ByCurveAndDivisions(modCurve.CurveReference, 0));
        }
Пример #45
0
        public void ByCurveAndEqualDivisions_ValidArgs()
        {
            // create spline
            var pts = new Autodesk.DesignScript.Geometry.Point[]
            {
                Point.ByCoordinates(0,0,0),
                Point.ByCoordinates(1,0,0),
                Point.ByCoordinates(3,0,0),
                Point.ByCoordinates(10,0,0),
                Point.ByCoordinates(12,0,0),
            };

            var spline = NurbsCurve.ByControlPoints( pts, 3 );
            Assert.NotNull(spline);

            // build model curve from spline
            var modCurve = ModelCurve.ByCurve(spline);
            Assert.NotNull(modCurve);

            // build dividedPath
            var divPath = DividedPath.ByCurveAndDivisions(modCurve.CurveReference, 5);
            Assert.NotNull(divPath);
        }
Пример #46
0
        /// <summary>
        /// Create an AdaptiveComponent from a list of points.
        /// </summary>
        /// <param name="points">The points to reference in the AdaptiveComponent</param>
        /// <param name="familySymbol">The family symbol to use to build the AdaptiveComponent</param>
        /// <returns></returns>
        public static AdaptiveComponent ByPoints( Point[] points, FamilySymbol familySymbol )
        {
            if (points == null)
            {
                throw new ArgumentNullException("points");
            }

            if (familySymbol == null)
            {
                throw new ArgumentNullException("familySymbol");
            }

            return new AdaptiveComponent(points, familySymbol);
        }
Пример #47
0
        private static IConeEntity ByStartPointEndPointRadiusCore(Point startPoint, Point endPoint, double startRadius, double endRadius)
        {
            if (startRadius.LessThanOrEqualTo(0.0))
                throw new System.ArgumentException(string.Format(Properties.Resources.LessThanZero, "start radius"), "startRadius");
            if (endRadius < 0.0)
                throw new System.ArgumentException(string.Format(Properties.Resources.LessThanZero, "end radius"), "endRadius");
            if (null == startPoint)
                throw new System.ArgumentNullException("startPoint");
            if (null == endPoint)
                throw new System.ArgumentNullException("endPoint");
            if (startPoint.DistanceTo(endPoint).EqualsTo(0.0))
                throw new System.ArgumentException(string.Format(Properties.Resources.IsZeroDistance, "start point", "end point"), "startPoint, endPoint");

            IConeEntity entity = HostFactory.Factory.ConeByPointsRadius(startPoint.PointEntity, endPoint.PointEntity, startRadius, endRadius);
            if (null == entity)
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "Cone.ByStartPointEndPointRadius"));
            return entity;
        }
Пример #48
0
 /// <summary>
 /// Construct a Surface by revolving the profile curve about an axis 
 /// defined by axisOrigin point and axisDirection Vector. startAngle 
 /// determines where the curve starts to revolve, sweepAngle determines 
 /// the extent of the revolve.
 /// </summary>
 /// <param name="profile">Profile Curve for revolve surface.</param>
 /// <param name="axisOrigin">Origin Point for axis of revolution.</param>
 /// <param name="axisDirection">Direction Vector for axis of revolution.</param>
 /// <param name="startAngle">Start Angle in degreee at which curve starts to revolve.</param>
 /// <param name="sweepAngle">Sweep Angle in degree to define the extent of revolve.</param>
 /// <returns>RevolvedSurface</returns>
 public static RevolvedSurface ByProfileAxisOriginDirectionAngle(Curve profile, Point axisOrigin, Vector axisDirection, double startAngle, double sweepAngle)
 {
     return new RevolvedSurface(profile, axisOrigin, axisDirection, startAngle, sweepAngle, true);
 }
Пример #49
0
        private static ISurfaceEntity ByProfileAxisOriginDirectionAngleCore(Curve profile, Point axisOrigin, Vector axisDirection, double startAngle, double sweepAngle)
        {
            if (null == profile)
                throw new System.ArgumentException(string.Format(Properties.Resources.NullArgument, "profile"), "profile");

            if (null == axisOrigin)
                throw new System.ArgumentException(string.Format(Properties.Resources.NullArgument, "axis origin"), "axisOrigin");

            if (null == axisDirection)
                throw new System.ArgumentException(string.Format(Properties.Resources.NullArgument, "axis direction"), "axisDirection");

            ISurfaceEntity entity = HostFactory.Factory.SurfaceByRevolve(profile.CurveEntity, axisOrigin.PointEntity, axisDirection.IVector, startAngle, sweepAngle);
            if (entity == null)
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "Surface.Revolve"));
            return entity;
        }
Пример #50
0
 private static Line LineBetweenPoints(Point origin, double scale, System.Windows.Point a, System.Windows.Point b)
 {
     var pt1 = Point.ByCoordinates((a.X * scale) + origin.X, ((-a.Y + 1) * scale) + origin.Y, origin.Z);
     var pt2 = Point.ByCoordinates((b.X * scale) + origin.X, ((-b.Y + 1) * scale) + origin.Y, origin.Z);
     var crv = Line.ByStartPointEndPoint(pt1, pt2);
     return crv;
 }
Пример #51
0
 /// <summary>
 /// Construct a Surface by revolving the profile curve about an axis
 /// defined by axisOrigin point and axisDirection Vector.
 /// Assuming sweep angle = 360 and start angle = 0.
 /// </summary>
 /// <param name="profile">Profile Curve for revolve surface.</param>
 /// <param name="axisOrigin">Origin Point for axis of revolution.</param>
 /// <param name="axisDirection">Direction Vector for axis of revolution.</param>
 /// <returns>RevolvedSurface</returns>
 public static RevolvedSurface ByProfileAxisOriginDirection(Curve profile, Point axisOrigin, Vector axisDirection)
 {
     return new RevolvedSurface(profile, axisOrigin, axisDirection, 0, 360, true);
 }
Пример #52
0
 public static Line ToOriginCenteredLine(Point origin, Vector axis)
 {
     return Line.ByStartPointEndPoint(origin.Add(axis.Scale(-axisScaleFactor)),
         origin.Add(axis.Scale(axisScaleFactor)));
 }
Пример #53
0
 /// <summary>
 /// Constructs a solid cone defined by a start and end point on its axis and the start and end radii of its base and top respectively.
 /// </summary>
 /// <param name="startPoint">The start point on the axis of the cone</param>
 /// <param name="endPoint">The end point on the axis of the cone</param>
 /// <param name="startRadius">The radius of the base of the cone</param>
 /// <param name="endRadius">The radius of the top of the cone</param>
 /// <returns></returns>
 public static Cone ByStartPointEndPointRadius(Point startPoint, Point endPoint, double startRadius, double endRadius)
 {
     return new Cone(startPoint, endPoint, startRadius, endRadius, true);
 }
Пример #54
0
        /// <summary>
        /// Callback method when gizmo is moved by user action.
        /// </summary>
        /// <param name="gizmo">Gizmo that moved.</param>
        /// <param name="offset">Offset by which the gizmo has moved.</param>
        /// <returns>New expected position of the Gizmo</returns>
        protected override Point OnGizmoMoved(IGizmo gizmo, Vector offset)
        {
            expectedPosition = origin.Add(offset);

            foreach (var item in indexedAxisNodePairs)
            {
                // When more than one input is connected to the same slider, this
                // method will decompose the axis corresponding to each input.
                var v = GetFirstAxisComponent(item.Value.Item1);
                var amount = Math.Round(offset.Dot(v), 3);
                if (Math.Abs(amount) > 0.001)
                    ModifyInputNode(item.Value.Item2, amount);
            }

            return expectedPosition;
        }
Пример #55
0
        /// <summary>
        /// Synchronize the origin with the node's value.
        /// </summary>
        protected override void UpdatePosition()
        {
            Active = false;
            if (Node == null || !indexedAxisNodePairs.Any()) return;

            if (origin == null)
            {
                origin = Point.Origin();
            }

            // hack: to prevent node mirror value lookup from throwing an exception
            var previousOrigin = Point.ByCoordinates(origin.X, origin.Y, origin.Z);
            try
            {
                //Node output could be a collection, consider the first item as origin.
                Point pt = GetFirstValueFromNode(Node) as Point;
                origin = pt != null ? Point.ByCoordinates(pt.X, pt.Y, pt.Z) : origin;
            }
            catch (Exception)
            {
                origin = previousOrigin;
            }

            if (origin == null)
            {
                origin = Point.Origin();
                return;
            }

            Active = true;
        }
Пример #56
0
        /// <summary>
        /// Implements the MouseDown event handler for the manipulator
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="mouseButtonEventArgs"></param>
        protected virtual void MouseDown(object sender, MouseButtonEventArgs mouseButtonEventArgs)
        {
            UpdatePosition();

            GizmoInAction = null; //Reset Drag.

            var gizmos = GetGizmos(false);
            if (!Active || !IsEnabled() || null == gizmos || !gizmos.Any()) return;

            var ray = BackgroundPreviewViewModel.GetClickRay(mouseButtonEventArgs);
            if (ray == null) return;

            foreach (var item in gizmos)
            {
                using(var originPt = ray.GetOriginPoint())
                using (var dirVec = ray.GetDirectionVector())
                {
                    object hitObject;
                    if (item.HitTest(originPt, dirVec, out hitObject))
                    {
                        GizmoInAction = item;

                        var nodes = OnGizmoClick(item, hitObject).ToList();
                        if (nodes.Any())
                        {
                            WorkspaceModel.RecordModelsForModification(nodes);
                        }
                        newPosition = Origin;
                        return;
                    }
                }
            }
        }
Пример #57
0
        /// <summary>
        /// Implements the MouseMove event handler for the manipulator
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="mouseEventArgs"></param>
        protected virtual void MouseMove(object sender, MouseEventArgs mouseEventArgs)
        {
            if (!IsEnabled()) return;

            var clickRay = BackgroundPreviewViewModel.GetClickRay(mouseEventArgs);
            if (clickRay == null) return;

            if (GizmoInAction == null)
            {
                HighlightGizmoOnRollOver(clickRay);
                return;
            }

            if (!CanMoveGizmo(GizmoInAction)) return;

            var offset = GizmoInAction.GetOffset(clickRay.GetOriginPoint(), clickRay.GetDirectionVector());
            if (offset.Length < 0.01) return;

            newPosition = OnGizmoMoved(GizmoInAction, offset);
        }
 public void GetDegreesOfFreedom(out int translationDegreesCount, out ObjectsEnumerator translationDegreesVectors, out int rotationDegreesCount, out ObjectsEnumerator rotationDegreesVectors, out Point dOFCenter)
 {
     InternalGetDegreesOfFreedom(out  translationDegreesCount, out  translationDegreesVectors, out  rotationDegreesCount, out  rotationDegreesVectors, out  dOFCenter);
 }
 private void InternalGetDegreesOfFreedom(out int translationDegreesCount, out ObjectsEnumerator translationDegreesVectors, out int rotationDegreesCount, out ObjectsEnumerator rotationDegreesVectors, out Point dOFCenter)
 {
     Inventor.Point dOFCenterInv;
     ComponentOccurrenceInstance.GetDegreesOfFreedom(out  translationDegreesCount, out  translationDegreesVectors, out  rotationDegreesCount, out  rotationDegreesVectors, out  dOFCenterInv);
     dOFCenter = dOFCenterInv.ToPoint();
 }
Пример #60
0
        //perhaps move to BuildingSurface?
        /// <summary>
        /// 
        /// </summary>
        /// <param name="surfaces"></param>
        /// <param name="zone"></param>
        /// <param name="centerpoint"></param>
        public static List<BuildingSurface> BuildingSurfacesByOrientation(List<Surface> surfaces, Zone zone, Point centerpoint)
        {
            var buildingSurfaces = new List<BuildingSurface>();

            foreach (var surface in surfaces)
                if (surface.NormalAtParameter(0.5, 0.5).AngleBetween(Vector.ByCoordinates(0, 0, 1)) < 0.01)
            {
                buildingSurfaces.Add(surface.PointAtParameter(0.5, 0.5).Z > centerpoint.Z
                    ? new BuildingSurface(surface, zone, "default", "Roof")
                    : new BuildingSurface(surface, zone, "default", "Floor", "default", "Ground"));
            }
            else
            {
                buildingSurfaces.Add(new BuildingSurface(surface, zone));
            }

            //Not working as intended...
            //foreach (var Surface in geometry)
            //{
            //    if (GetNormal(Surface).IsAlmostEqualTo(Vector.ByCoordinates(0, 0, 1)))
            //    {
            //        buildingSurfaces.Add(new BuildingSurface(Surface, zone, "default", "Roof"));
            //    }
            //    else if (GetNormal(Surface).IsAlmostEqualTo(Vector.ByCoordinates(0, 0, -1)))
            //    {
            //        buildingSurfaces.Add(new BuildingSurface(Surface, zone, "default", "Floor"));
            //    }
            //    else
            //    {
            //        buildingSurfaces.Add(new BuildingSurface(Surface, zone));
            //    }
            //}

            return buildingSurfaces;
        }