Exemplo n.º 1
0
        private static void CreateFilledRegion(Document doc, SpatialObjectWrapper so)
        {
            try
            {
                var filledRegionType = new FilteredElementCollector(doc).OfClass(typeof(FilledRegionType)).FirstElementId();
                if (filledRegionType == null || filledRegionType == ElementId.InvalidElementId)
                {
                    return;
                }

                var curves = new List <CurveLoop>();
                var loop   = new CurveLoop();
                foreach (var curve in so.Room2D.FloorBoundary.GetCurves(so.Level.Elevation))
                {
                    //doc.Create.NewDetailCurve(doc.ActiveView, curve);
                    loop.Append(curve);
                }
                curves.Add(loop);

                FilledRegion.Create(doc, filledRegionType, doc.ActiveView.Id, curves);
            }
            catch (Exception e)
            {
                _logger.Fatal(e);
            }
        }
Exemplo n.º 2
0
        public LoadArea(FilledRegion filledRegion, Options options)
        {
            try
            {
                FilledRegion = filledRegion;
                ElementId    = filledRegion.Id;
                Load         = double.Parse(filledRegion.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).AsString(), CultureInfo.InvariantCulture);

                //Create a new solid from the element solid
                Face        face   = ir.GetFace(filledRegion, options);
                IList <XYZ> source = new List <XYZ>();
                foreach (CurveLoop curveLoop in face.GetEdgesAsCurveLoops())
                {
                    foreach (Curve curve in curveLoop)
                    {
                        source.Add(curve.GetEndPoint(0));
                        source.Add(curve.GetEndPoint(1));
                    }
                }
                source = source.DistinctBy(xyz => new { X = xyz.X.Round4(), Y = xyz.Y.Round4() }).ToList();
                source = tr.ConvexHull(source.ToList());
                Path   = ir.CreatePath(source);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw new Exception(e.Message);
            }
        }
Exemplo n.º 3
0
        public void CreateFilledRegion(Document doc, ViewSection intElev, BoundingBoxXYZ roombb)
        {
            List <CurveLoop> filledRegionBoundaries = FilledRegionBoundary(intElev);
            ElementId        filledRegionTypeId     = new FilteredElementCollector(doc)
                                                      .OfClass(typeof(FilledRegionType))
                                                      .Select(f => f as FilledRegionType)
                                                      .Where(f => f != null &&
                                                             f.BackgroundPatternColor.Red == 255 &&
                                                             f.BackgroundPatternColor.Blue == 255 &&
                                                             f.BackgroundPatternColor.Green == 255 &&
                                                             f.IsMasking == true)
                                                      .Select(f => f.Id)
                                                      .FirstOrDefault();

            FilledRegion region = FilledRegion.Create(doc, filledRegionTypeId, intElev.Id, filledRegionBoundaries);
            // set inside and outside lineweight

            Element lineStyle = FilledRegion.GetValidLineStyleIdsForFilledRegion(doc)
                                .Select(id => doc.GetElement(id))
                                .Where(el => el.Name.Contains("05") && el.Name.ToLower().Contains("solid"))
                                .FirstOrDefault();


            region.SetLineStyleId(lineStyle.Id);
        }
        List <XYZ> GetBoundaryCorners(FilledRegion region)
        {
            List <XYZ> result = new List <XYZ>();

            ElementId id = new ElementId(
                region.Id.IntegerValue - 1);

            Sketch sketch = region.Document.GetElement(
                id) as Sketch;

            if (null != sketch)
            {
                CurveArray curves = sketch.Profile.get_Item(0);

                if (null != curves)
                {
                    foreach (Curve cur in curves)
                    {
                        XYZ corner = cur.GetEndPoint(0);
                        result.Add(corner);
                    }
                }
            }
            return(result);
        }
        List<XYZ> GetBoundaryCorners( FilledRegion region )
        {
            List<XYZ> result = new List<XYZ>();

              ElementId id = new ElementId(
            region.Id.IntegerValue - 1 );

              Sketch sketch = region.Document.GetElement(
            id ) as Sketch;

              if( null != sketch )
              {
            CurveArray curves = sketch.Profile.get_Item( 0 );

            if( null != curves )
            {
              foreach( Curve cur in curves )
              {
            XYZ corner = cur.GetEndPoint( 0 );
            result.Add( corner );
              }
            }
              }
              return result;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets all the line styles in the document
        /// </summary>
        /// <param name="doc">UI Document</param>
        /// <returns>List of line styles</returns>
        public List <Element> GetLineStyles(Document doc)
        {
            List <Element> lineStyleList = FilledRegion.GetValidLineStyleIdsForFilledRegion(doc)
                                           .Select(id => doc.GetElement(id))
                                           .ToList();

            return(lineStyleList);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates a filled region for the elevatin using the previously found boundaries
        /// and the user selected filled region type and line style
        /// </summary>
        /// <param name="doc">UI Document</param>
        /// <param name="intElev">Interior Elevation</param>
        /// <param name="filledRegionId">Id of user selected filled region</param>
        /// <param name="lineStyle">Id of user selected line style</param>
        public void CreateFilledRegion(Document doc, ViewSection intElev, ElementId filledRegionId, ElementId lineStyle)
        {
            List <CurveLoop> filledRegionBoundaries = FilledRegionBoundary(intElev);

            FilledRegion region = FilledRegion.Create(doc, filledRegionId, intElev.Id, filledRegionBoundaries);

            region.SetLineStyleId(lineStyle);
        }
Exemplo n.º 8
0
        /***************************************************/

        public static IBHoMObject FromRevit(this FilledRegion filledRegion, Discipline discipline, Transform transform = null, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            switch (discipline)
            {
            default:
                return(filledRegion.DraftingInstanceFromRevit(settings, refObjects));
            }
        }
Exemplo n.º 9
0
        /***************************************************/
        /****               Public Methods              ****/
        /***************************************************/

        public static DraftingInstance DraftingInstanceFromRevit(this FilledRegion filledRegion, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            settings = settings.DefaultIfNull();

            DraftingInstance draftingInstance = refObjects.GetValue <DraftingInstance>(filledRegion.Id);

            if (draftingInstance != null)
            {
                return(draftingInstance);
            }

            View view = filledRegion.Document.GetElement(filledRegion.OwnerViewId) as View;

            if (view == null)
            {
                return(null);
            }

            InstanceProperties instanceProperties = (filledRegion.Document.GetElement(filledRegion.GetTypeId()) as ElementType).InstancePropertiesFromRevit(settings, refObjects) as InstanceProperties;

            List <ICurve> curves = new List <oM.Geometry.ICurve>();

            foreach (CurveLoop loop in filledRegion.GetBoundaries())
            {
                curves.Add(loop.FromRevit());
            }

            List <PlanarSurface> surfaces = BH.Engine.Geometry.Create.PlanarSurface(curves);

            if (surfaces.Count == 1)
            {
                draftingInstance = new DraftingInstance {
                    Properties = instanceProperties, ViewName = view.Name, Location = surfaces[0]
                }
            }
            ;
            else
            {
                draftingInstance = new DraftingInstance {
                    Properties = instanceProperties, ViewName = view.Name, Location = new PolySurface {
                        Surfaces = surfaces.Cast <ISurface>().ToList()
                    }
                }
            };

            draftingInstance.Name = filledRegion.Name;

            //Set identifiers, parameters & custom data
            draftingInstance.SetIdentifiers(filledRegion);
            draftingInstance.CopyParameters(filledRegion, settings.ParameterSettings);
            draftingInstance.SetProperties(filledRegion, settings.ParameterSettings);

            refObjects.AddOrReplace(filledRegion.Id, draftingInstance);
            return(draftingInstance);
        }

        /***************************************************/
    }
Exemplo n.º 10
0
        private void DrawNormSpecGraph()
        {
            LinePlot lpTemp = new LinePlot();

            plotTemplateSpectrum.Clear();

            // add masks;
            int num = lbRanges.SelectedIndex;

            for (int i = 0; i < cutMask.Size(); i++)
            {
                NPlot.VerticalLine vl1 = new VerticalLine(this.cutMask.GetLeftBound(i));
                NPlot.VerticalLine vl2 = new VerticalLine(this.cutMask.GetRightBound(i));
                NPlot.FilledRegion fr  = new FilledRegion(vl1, vl2);
                fr.Brush = Brushes.Coral;
                if (num == i)
                {
                    fr.Brush = Brushes.Aqua;
                }
                plotTemplateSpectrum.Add(fr);
            }

            // add normalized observed spectrum;
            if (this.normSpectrum != null)
            {
                LinePlot lpObsNorm = new LinePlot();
                lpObsNorm.Color        = Color.Red;
                lpObsNorm.AbscissaData = this.normSpectrum.LambdaSet;
                lpObsNorm.OrdinateData = this.normSpectrum.FluxSet;
                plotTemplateSpectrum.Add(lpObsNorm);
            }

            // add normalized template spectrum;
            if (this.temCutSpectrum != null)
            {
                lpTemp.Color        = Color.Blue;
                lpTemp.AbscissaData = this.temCutSpectrum.LambdaSet;
                lpTemp.OrdinateData = this.temCutSpectrum.FluxSet;
                plotTemplateSpectrum.Add(lpTemp);
            }

            // add horizontal line;
            NPlot.HorizontalLine hl = new HorizontalLine(1.0, Color.DarkGray);
            plotTemplateSpectrum.Add(hl);


            plotTemplateSpectrum.XAxis1.WorldMax = this.cropLambdaMax;
            plotTemplateSpectrum.XAxis1.WorldMin = this.cropLambdaMin;
            plotTemplateSpectrum.Title           = "Normalized spectrum";
            plotTemplateSpectrum.YAxis1.Label    = "Norm. Flux";
            plotTemplateSpectrum.XAxis1.Label    = "Wavelength";

            plotTemplateSpectrum.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalDrag());
            plotTemplateSpectrum.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.VerticalDrag());
            plotTemplateSpectrum.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(true));

            plotTemplateSpectrum.Refresh();
        }
Exemplo n.º 11
0
        private void DrawObsSpecGraph()
        {
            plotObsSpectrum.Clear();

            // add masks;
            int num = lbRanges.SelectedIndex;

            for (int i = 0; i < cutMask.Size(); i++)
            {
                NPlot.VerticalLine vl1 = new VerticalLine(this.cutMask.GetLeftBound(i));
                NPlot.VerticalLine vl2 = new VerticalLine(this.cutMask.GetRightBound(i));
                NPlot.FilledRegion fr  = new FilledRegion(vl1, vl2);
                fr.Brush = Brushes.Coral;
                if (num == i)
                {
                    fr.Brush = Brushes.Gray;
                }
                plotObsSpectrum.Add(fr);
            }

            // add observed spectrum;
            if (this.obsSpectrum != null)
            {
                LinePlot lp = new LinePlot();
                lp.AbscissaData = this.obsSpectrum.LambdaSet;
                lp.OrdinateData = this.obsSpectrum.FluxSet;
                lp.Pen          = new Pen(Color.Black, 1.0f);
                plotObsSpectrum.Add(lp);
            }

            // add continum;
            if (this.contSpectrum != null)
            {
                LinePlot lpCont = new LinePlot(this.contSpectrum.FluxSet, this.contSpectrum.LambdaSet);
                lpCont.Pen = new Pen(Color.Red, 2.0f);
                plotObsSpectrum.Add(lpCont);
            }

            // add rejected points;
            if (this.rejectSpectrum != null && this.rejectSpectrum.Size > 0)
            {
                PointPlot ppRej = new PointPlot();
                ppRej.AbscissaData = this.rejectSpectrum.LambdaSet;
                ppRej.OrdinateData = this.rejectSpectrum.FluxSet;
                ppRej.Marker       = new Marker(Marker.MarkerType.Diamond, 4, Color.Red);
                plotObsSpectrum.Add(ppRej);
            }

            plotObsSpectrum.Title        = "Observed spectrum";
            plotObsSpectrum.YAxis1.Label = "Flux";
            plotObsSpectrum.XAxis1.Label = "Lambda";

            plotObsSpectrum.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalDrag());
            plotObsSpectrum.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.VerticalDrag());
            plotObsSpectrum.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(true));

            plotObsSpectrum.Refresh();
        }
        private void CreateDimensions(
            FilledRegion filledRegion,
            XYZ dimensionDirection,
            string typeName)
        {
            var document = filledRegion.Document;

            var view = (View)document.GetElement(
                filledRegion.OwnerViewId);

            var edgesDirection = dimensionDirection.CrossProduct(
                view.ViewDirection);

            var edges = FindRegionEdges(filledRegion)
                        .Where(x => IsEdgeDirectionSatisfied(x, edgesDirection))
                        .ToList();

            if (edges.Count < 2)
            {
                return;
            }

            // Se hace este ajuste para que la distancia no
            // depende de la escala. <<<<<< evaluar para
            // información de acotado y etiquetado!!!

            //var shift = UnitUtils.ConvertToInternalUnits(
            //  5 * view.Scale, DisplayUnitType.DUT_MILLIMETERS ) // 2020
            //  * edgesDirection;

            var shift = UnitUtils.ConvertToInternalUnits(
                5 * view.Scale, UnitTypeId.Millimeters) // 2021
                        * edgesDirection;

            var dimensionLine = Line.CreateUnbound(
                filledRegion.get_BoundingBox(view).Min + shift,
                dimensionDirection);

            var references = new ReferenceArray();

            foreach (var edge in edges)
            {
                references.Append(edge.Reference);
            }

            Dimension dim = document.Create.NewDimension(
                view, dimensionLine, references);

            ElementId dr_id = DimensionTypeId(
                document, typeName);

            if (dr_id != null)
            {
                dim.ChangeTypeId(dr_id);
            }
        }
Exemplo n.º 13
0
    void glVertex2i(float x, float y, bool IsEdge)
    {
#if UNI
        //Debug.Log(  x + " , " + y );
        //BezierPath.SpawnCube( new Vector3( x / 10.0f , y / 10.0f ) );
        FilledRegion.Add(new Vector3(x, y), IsEdge);
#else
        Trace.WriteLine(x + " , " + y);
#endif
    }
Exemplo n.º 14
0
        public static Face GetFace(FilledRegion fr, Options options)
        {
            GeometryElement geometryElement = fr.get_Geometry(options);

            foreach (GeometryObject go in geometryElement)
            {
                Solid solid = go as Solid;
                return(solid.Faces.get_Item(0));
            }
            return(null);
        }
Exemplo n.º 15
0
        /// <summary>
        /// 获取详图区域的Edges
        /// </summary>
        public static List <Edge> Edges(this FilledRegion filledRegion, View _view)
        {
            Options options = new Options();

            options.View = _view;
            options.ComputeReferences = true;
            GeometryElement geometryElement = filledRegion.get_Geometry(options);

            Solid solid = geometryElement.First() as Solid;

            return(solid.Edges.ToIEnumerable().ToList());
        }
Exemplo n.º 16
0
        public void PlotTest()
        {
            plotSurface.Clear();

            // can plot different types.
            ArrayList l = new ArrayList();

            l.Add((int)2);
            l.Add((double)1.0);
            l.Add((float)3.0);
            l.Add((int)5.0);

            LinePlot lp1 = new LinePlot(new double[] { 4.0, 3.0, 5.0, 8.0 });

            lp1.Pen       = new Pen(Color.LightBlue);
            lp1.Pen.Width = 2.0f;

            //lp.AbscissaData = new StartStep( 0.0, 2.0 );

            LinePlot lp2 = new LinePlot(new double[] { 2.0, 1.0, 4.0, 5.0 });

            lp2.Pen       = new Pen(Color.LightBlue);
            lp2.Pen.Width = 2.0f;

            FilledRegion fr = new FilledRegion(lp1, lp2);

            plotSurface.Add(fr);

            plotSurface.Add(new Grid());
            plotSurface.Add(lp1);
            plotSurface.Add(lp2);

            ArrowItem a = new ArrowItem(new PointD(2, 4), -50.0f, "Arrow");

            a.HeadOffset = 5;
            a.ArrowColor = Color.Red;
            a.TextColor  = Color.Purple;
            plotSurface.Add(a);

            MarkerItem m = new MarkerItem(new Marker(Marker.MarkerType.TriangleDown, 8, Color.ForestGreen), 1.38, 2.9);

            plotSurface.Add(m);

            plotSurface.XAxis1.TicksCrossAxis = true;

            ((LinearAxis)plotSurface.XAxis1).LargeTickValue = -4.1;
            ((LinearAxis)plotSurface.XAxis1).AutoScaleText  = true;
            ((LinearAxis)plotSurface.XAxis1).TicksIndependentOfPhysicalExtent = true;
            //plotSurface.XAxis1.Label = "Hello world";

            plotSurface.Refresh();
        }
Exemplo n.º 17
0
        public PriceAction()
        {
            plotSurface = new NPlot.Bitmap.PlotSurface2D(700, 500);

            string infoText = "";

            infoText += "Simple CandlePlot example. Demonstrates - \n";
            infoText += " * Setting candle plot datapoints using arrays \n";
            infoText += " * Plot Zoom interaction using MouseWheel ";

            plotSurface.Clear();

            FilledRegion fr = new FilledRegion(
                new VerticalLine(1.2),
                new VerticalLine(2.4));

            fr.Brush = Brushes.BlanchedAlmond;
            plotSurface.Add(fr);

            // note that arrays can be of any type you like.
            int[]          opens  = { 1, 2, 1, 2, 1, 3 };
            double[]       closes = { 2, 2, 2, 1, 2, 1 };
            float[]        lows   = { 0, 1, 1, 1, 0, 0 };
            System.Int64[] highs  = { 3, 2, 3, 3, 3, 4 };
            int[]          times  = { 0, 1, 2, 3, 4, 5 };

            CandlePlot cp = new CandlePlot();

            cp.CloseData    = closes;
            cp.OpenData     = opens;
            cp.LowData      = lows;
            cp.HighData     = highs;
            cp.AbscissaData = times;
            plotSurface.Add(cp);

            HorizontalLine line = new HorizontalLine(1.2);

            line.LengthScale = 0.89f;
            plotSurface.Add(line, -10);

            VerticalLine line2 = new VerticalLine(1.2);

            line2.LengthScale = 0.89f;
            plotSurface.Add(line2);

            plotSurface.AddInteraction(new PlotZoom());

            plotSurface.Title = "Line in the Title Number 1\nFollowed by another title line\n and another";
            plotSurface.Refresh();
        }
Exemplo n.º 18
0
        /// <summary>
        /// 获取详图区域的详图线
        /// </summary>
        public static List <DetailCurve> DetailCurves(this FilledRegion filledRegion, Document doc)
        {
            ElementClassFilter elementClassFilter = new ElementClassFilter(typeof(CurveElement));
            List <ElementId>   detailLineIds      = filledRegion.GetDependentElements(elementClassFilter).ToList();

            List <DetailCurve> detailCurves = new List <DetailCurve>();

            foreach (ElementId elementId in detailLineIds)
            {
                DetailCurve detailCurve = doc.GetElement(elementId) as DetailCurve;
                detailCurves.Add(detailCurve);
            }
            return(detailCurves);
        }
Exemplo n.º 19
0
        public void ByCurves_ValidArgs()
        {
            Autodesk.Revit.DB.FilteredElementCollector collector = new Autodesk.Revit.DB.FilteredElementCollector(Revit.Application.Document.Current.InternalDocument).OfClass(typeof(Autodesk.Revit.DB.FilledRegionType));
            FilledRegionType type = FilledRegionType.FromExisting((Autodesk.Revit.DB.FilledRegionType)collector.FirstOrDefault(), true);

            Assert.NotNull(type);

            Polygon polygon = Polygon.RegularPolygon(Circle.ByCenterPointRadius(Point.ByCoordinates(0, 0, 0), 10), 4);

            Assert.NotNull(polygon);

            var reg = FilledRegion.ByCurves(Revit.Application.Document.Current.ActiveView, polygon.Curves().ToList(), type);

            Assert.NotNull(reg);
        }
Exemplo n.º 20
0
        private static IEnumerable <Edge> FindRegionEdges(FilledRegion filledRegion)
        {
            var view = (View)filledRegion.Document.GetElement(filledRegion.OwnerViewId);

            var options = new Options
            {
                View = view,
                ComputeReferences = true
            };

            return(filledRegion
                   .get_Geometry(options)
                   .OfType <Solid>()
                   .SelectMany(x => x.Edges.Cast <Edge>()));
        }
Exemplo n.º 21
0
        /// <summary>
        /// 生成填充区域
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="typeId"></param>
        /// <param name="viewId"></param>
        /// <param name="loop"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static ElementId CreateFilledRegion(Document doc, ElementId typeId, ElementId viewId, List <CurveLoop> loop, String name = "")
        {
            FilledRegion region = null;

            using (Transaction tran = new Transaction(doc, "FilledRegion"))
            {
                tran.Start();
                region = FilledRegion.Create(doc, typeId, viewId, loop);
                if (!String.IsNullOrEmpty(name))
                {
                    region.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).Set(name);
                }
                tran.Commit();
            }
            return(region.Id);
        }
Exemplo n.º 22
0
        /// <summary>
        /// 在有元素内 抓取所有障碍物线圈
        /// </summary>
        public List <CurveLoop> RegionGrabobstaclesLineLoop(Document doc, List <Element> selEles)
        {
            List <CurveLoop> obstacleLineLoops = new List <CurveLoop>();

            foreach (Element _ele in selEles)
            {
                if (_ele is FilledRegion)
                {
                    if (_ele.Name == "详图填充区域")
                    {
                        FilledRegion filledRegion = _ele as FilledRegion;
                        obstacleLineLoops.AddRange(filledRegion.GetBoundaries());
                    }
                }
            }
            return(obstacleLineLoops);
        }
Exemplo n.º 23
0
        private void checkBox13_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox cbx = (CheckBox)sender;

            if (cbx.Checked == true)
            {
                LinePlot lp3 = new LinePlot();
                int[]    p   = new int[10] {
                    1, 2, 3, 4, 5, 4, 3, 2, 1, 3
                };
                int[] X = new int[10] {
                    1, 2, 3, 4, 5, 6, 7, 8, 9, 10
                };
                lp3.OrdinateData = p;
                lp3.AbscissaData = X;
                lp3.Pen          = new Pen(Color.Orange);
                lp3.Pen.Width    = 2;
                lp3.Label        = " 价格";

                LinePlot lp4 = new LinePlot();
                int[]    p2  = new int[10] {
                    1, 1, 1, 1, 1, 1, 1, 1, 1, 1
                };

                lp4.OrdinateData = p2;
                lp4.AbscissaData = X;
                lp4.Pen          = new Pen(Color.Orange);
                lp4.Pen.Width    = 2;
                lp4.Label        = " 价格";


                fr = new FilledRegion(lp3, lp4);

                fr.Brush = Brushes.BlanchedAlmond;
                this.myPlot.Add(fr);
            }
            else
            {
                if (fr != null)
                {
                    this.myPlot.Remove(fr, false);
                }
            }
            myPlot.Refresh();
        }
Exemplo n.º 24
0
        /***************************************************/

        private static Element ToRevitElement(this DraftingInstance draftingInstance, FilledRegionType regionType, View view, RevitSettings settings)
        {
            ISurface location = draftingInstance.Location as ISurface;

            List <PlanarSurface> surfaces = new List <PlanarSurface>();

            if (location is PlanarSurface)
            {
                surfaces.Add((PlanarSurface)location);
            }
            else if (location is PolySurface)
            {
                PolySurface polySurface = (PolySurface)location;
                if (polySurface.Surfaces.Any(x => !(x is PlanarSurface)))
                {
                    draftingInstance.InvalidRegionSurfaceError();
                    return(null);
                }

                surfaces = polySurface.Surfaces.Cast <PlanarSurface>().ToList();
            }
            else
            {
                draftingInstance.InvalidRegionSurfaceError();
                return(null);
            }

            List <CurveLoop> loops = new List <CurveLoop>();

            foreach (PlanarSurface surface in surfaces)
            {
                foreach (ICurve curve in surface.Edges())
                {
                    loops.Add(curve.ToRevitCurveLoop());
                }
            }

            if (loops.Count != 0)
            {
                return(FilledRegion.Create(view.Document, regionType.Id, view.Id, loops));
            }

            return(null);
        }
            private static void CreateDimensions(
                FilledRegion filledRegion,
                XYZ dimensionDirection)
            {
                var document = filledRegion.Document;

                var view = (View)document.GetElement(
                    filledRegion.OwnerViewId);

                var edgesDirection = dimensionDirection.CrossProduct(
                    view.ViewDirection);

                var edges = FindRegionEdges(filledRegion)
                            .Where(x => IsEdgeDirectionSatisfied(x, edgesDirection))
                            .ToList();

                if (edges.Count < 2)
                {
                    return;
                }

                //var shift = UnitUtils.ConvertToInternalUnits(
                //  -10 * view.Scale, DisplayUnitType.DUT_MILLIMETERS ) // 2020
                //  * edgesDirection;

                var shift = UnitUtils.ConvertToInternalUnits(
                    -10 * view.Scale, UnitTypeId.Millimeters) // 2021
                            * edgesDirection;

                var dimensionLine = Line.CreateUnbound(
                    filledRegion.get_BoundingBox(view).Min
                    + shift, dimensionDirection);

                var references = new ReferenceArray();

                foreach (var edge in edges)
                {
                    references.Append(edge.Reference);
                }

                document.Create.NewDimension(view, dimensionLine,
                                             references);
            }
Exemplo n.º 26
0
        public void CreatePlot(InteractivePlotSurface2D plotSurface)
        {
            plotSurface.Clear();

            FilledRegion fr = new FilledRegion(
                new VerticalLine(1.2),
                new VerticalLine(2.4));

            fr.Brush = Brushes.BlanchedAlmond;
            plotSurface.Add(fr);

            // note that arrays can be of any type you like.
            int[]          opens  = { 1, 2, 1, 2, 1, 3 };
            double[]       closes = { 2, 2, 2, 1, 2, 1 };
            float[]        lows   = { 0, 1, 1, 1, 0, 0 };
            System.Int64[] highs  = { 3, 2, 3, 3, 3, 4 };
            int[]          times  = { 0, 1, 2, 3, 4, 5 };

            CandlePlot cp = new CandlePlot();

            cp.CloseData    = closes;
            cp.OpenData     = opens;
            cp.LowData      = lows;
            cp.HighData     = highs;
            cp.AbscissaData = times;
            plotSurface.Add(cp);

            HorizontalLine line = new HorizontalLine(1.2);

            line.LengthScale = 0.89f;
            plotSurface.Add(line, -10);

            VerticalLine line2 = new VerticalLine(1.2);

            line2.LengthScale = 0.89f;
            plotSurface.Add(line2);

            plotSurface.AddInteraction(new PlotZoom());

            plotSurface.Title = "Line in the Title Number 1\nFollowed by another title line\n and another";
            plotSurface.Refresh();
        }
Exemplo n.º 27
0
        public void ByCircle_ValidArgs()
        {
            Autodesk.Revit.DB.FilteredElementCollector collector = new Autodesk.Revit.DB.FilteredElementCollector(Revit.Application.Document.Current.InternalDocument).OfClass(typeof(Autodesk.Revit.DB.FilledRegionType));
            FilledRegionType type = FilledRegionType.FromExisting((Autodesk.Revit.DB.FilledRegionType)collector.FirstOrDefault(), true);

            Assert.NotNull(type);

            Circle c = Circle.ByCenterPointRadius(Point.ByCoordinates(0, 0, 0), 10);

            Assert.NotNull(c);

            Curve[] curves = c.ApproximateWithArcAndLineSegments();

            // Approximate With Arc and Lines returns one Curve which is not closed. Seems odd.
            if (curves.Count() > 0 && curves[0].IsClosed)
            {
                var reg = FilledRegion.ByCurves(Revit.Application.Document.Current.ActiveView, curves, type);
                Assert.NotNull(reg);
            }
        }
Exemplo n.º 28
0
        private void checkBox9_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox cbx = (CheckBox)sender;

            if (cbx.Checked == true)
            {
                fr = new FilledRegion(new VerticalLine(1.2), new VerticalLine(2.4));

                fr.Brush = Brushes.BlanchedAlmond;
                this.myPlot.Add(fr);
            }
            else
            {
                if (fr != null)
                {
                    this.myPlot.Remove(fr, false);
                }
            }
            myPlot.Refresh();
        }
Exemplo n.º 29
0
    public FilledPoly MakeFilledPoly(List <Vector3> poly)
    {
        FilledRegion.Clear( );

        CustomSampler edgeTablesampler = CustomSampler.Create("initEdgeTable");
        CustomSampler drawDinoSampler  = CustomSampler.Create("drawDino");
        CustomSampler scanFillSampler  = CustomSampler.Create("scanFillSampler");

        edgeTablesampler.Begin( );
        initEdgeTable( );
        edgeTablesampler.End( );

        drawDinoSampler.Begin( );
        drawPolyDino(poly);
        drawDinoSampler.End( );
        //printf( "\nTable" );
        //printTable( );
        scanFillSampler.Begin( );
        ScanlineFill( );//actual calling of scanline filling..
        scanFillSampler.End( );
        return(FilledRegion);
    }
        /// <summary>
        /// Exports an element as an annotation.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="filledRegion">The filled region element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        public static void Export(ExporterIFC exporterIFC, FilledRegion filledRegion,
            GeometryElement geometryElement, ProductWrapper productWrapper)
        {
            if (filledRegion == null || geometryElement == null)
                return;

            IFCFile file = exporterIFC.GetFile();
            using (IFCTransaction transaction = new IFCTransaction(file))
            {
                IList<CurveLoop> boundaries = filledRegion.GetBoundaries();
                if (boundaries.Count == 0)
                    return;

                Plane plane = null;
                try
                {
                    plane = boundaries[0].GetPlane();
                }
                catch
                {
                    return;
                }

                Transform orientTrf = Transform.Identity;
                orientTrf.BasisX = plane.XVec; orientTrf.BasisY = plane.YVec; orientTrf.BasisZ = plane.Normal;
                orientTrf.Origin = plane.Origin;
                XYZ projectionDirection = plane.Normal;

                IList<IList<CurveLoop>> sortedLoops = ExporterIFCUtils.SortCurveLoops(boundaries);
                if (sortedLoops.Count == 0)
                    return;

                FilledRegionType filledRegionType = filledRegion.Document.GetElement(filledRegion.GetTypeId()) as FilledRegionType;
                Color color = filledRegionType != null ? CategoryUtil.GetSafeColor(filledRegionType.Color) : new Color(0, 0, 0);
                ElementId fillPatternId = filledRegionType != null ? filledRegionType.FillPatternId : ElementId.InvalidElementId;
                ElementId categoryId = CategoryUtil.GetSafeCategoryId(filledRegion);

                using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, filledRegion, null, orientTrf))
                {
                    foreach (IList<CurveLoop> curveLoopList in sortedLoops)
                    {
                        IFCAnyHandle outerCurve = null;
                        HashSet<IFCAnyHandle> innerCurves = null;
                        for (int ii = 0; ii < curveLoopList.Count; ii++)
                        {
                            IFCAnyHandle ifcCurve = GeometryUtil.CreateIFCCurveFromCurveLoop(exporterIFC, curveLoopList[ii], plane, projectionDirection);
                            if (ii == 0)
                                outerCurve = ifcCurve;
                            else
                            {
                                if (innerCurves == null)
                                    innerCurves = new HashSet<IFCAnyHandle>();
                                innerCurves.Add(ifcCurve);
                            }
                        }

                        IFCAnyHandle representItem = IFCInstanceExporter.CreateAnnotationFillArea(file, outerCurve, innerCurves);
                        file.CreateStyle(exporterIFC, representItem, color, fillPatternId);

                        HashSet<IFCAnyHandle> bodyItems = new HashSet<IFCAnyHandle>();
                        bodyItems.Add(representItem);
                        IFCAnyHandle bodyRepHnd = RepresentationUtil.CreateAnnotationSetRep(exporterIFC, filledRegion, categoryId,
                            exporterIFC.Get2DContextHandle(), bodyItems);

                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyRepHnd))
                            return;

                        List<IFCAnyHandle> shapeReps = new List<IFCAnyHandle>();
                        shapeReps.Add(bodyRepHnd);

                        IFCAnyHandle productShape = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, shapeReps);
                        IFCAnyHandle annotation = IFCInstanceExporter.CreateAnnotation(file, GUIDUtil.CreateGUID(), exporterIFC.GetOwnerHistoryHandle(),
                            null, null, null, setter.LocalPlacement, productShape);

                        productWrapper.AddAnnotation(annotation, setter.LevelInfo, true);
                    }
                }

                transaction.Commit();
            }
        }
        /// <summary>
        /// Pick a DWG import instance, extract polylines
        /// from it visible in the current view and create
        /// filled regions from them.
        /// </summary>
        public void ProcessVisible(UIDocument uidoc)
        {
            Document doc         = uidoc.Document;
            View     active_view = doc.ActiveView;

            List <GeometryObject> visible_dwg_geo
                = new List <GeometryObject>();

            // Pick Import Instance

            Reference r = uidoc.Selection.PickObject(
                ObjectType.Element,
                new JtElementsOfClassSelectionFilter <ImportInstance>());

            var import = doc.GetElement(r) as ImportInstance;

            // Get Geometry

            var ge = import.get_Geometry(new Options());

            foreach (var go in ge)
            {
                if (go is GeometryInstance)
                {
                    var gi = go as GeometryInstance;

                    var ge2 = gi.GetInstanceGeometry();

                    if (ge2 != null)
                    {
                        foreach (var obj in ge2)
                        {
                            // Only work on PolyLines

                            if (obj is PolyLine)
                            {
                                // Use the GraphicsStyle to get the
                                // DWG layer linked to the Category
                                // for visibility.

                                var gStyle = doc.GetElement(
                                    obj.GraphicsStyleId) as GraphicsStyle;

                                // Check if the layer is visible in the view.

                                if (!active_view.GetCategoryHidden(
                                        gStyle.GraphicsStyleCategory.Id))
                                {
                                    visible_dwg_geo.Add(obj);
                                }
                            }
                        }
                    }
                }
            }

            // Do something with the info

            if (visible_dwg_geo.Count > 0)
            {
                // Retrieve first filled region type

                var filledType = new FilteredElementCollector(doc)
                                 .WhereElementIsElementType()
                                 .OfClass(typeof(FilledRegionType))
                                 .OfType <FilledRegionType>()
                                 .First();

                using (var t = new Transaction(doc))
                {
                    t.Start("ProcessDWG");

                    foreach (var obj in visible_dwg_geo)
                    {
                        var poly = obj as PolyLine;

                        // Draw a filled region for each polyline

                        if (null != poly)
                        {
                            // Create loops for detail region

                            var curveLoop = new CurveLoop();

                            var points = poly.GetCoordinates();

                            for (int i = 0; i < points.Count - 1; ++i)
                            {
                                curveLoop.Append(Line.CreateBound(
                                                     points[i], points[i + 1]));
                            }

                            FilledRegion.Create(doc,
                                                filledType.Id, active_view.Id,
                                                new List <CurveLoop>()
                            {
                                curveLoop
                            });
                        }
                    }
                    t.Commit();
                }
            }
        }
Exemplo n.º 32
0
        /// <summary>
        /// Exports an element as an annotation.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="filledRegion">The filled region element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        public static void Export(ExporterIFC exporterIFC, FilledRegion filledRegion,
                                  GeometryElement geometryElement, ProductWrapper productWrapper)
        {
            if (filledRegion == null || geometryElement == null)
            {
                return;
            }

            // Check the intended IFC entity or type name is in the exclude list specified in the UI
            Common.Enums.IFCEntityType elementClassTypeEnum = Common.Enums.IFCEntityType.IfcAnnotation;
            if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum))
            {
                return;
            }

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction transaction = new IFCTransaction(file))
            {
                IList <CurveLoop> boundaries = filledRegion.GetBoundaries();
                if (boundaries.Count == 0)
                {
                    return;
                }

                Plane plane = null;
                try
                {
                    plane = boundaries[0].GetPlane();
                }
                catch
                {
                    return;
                }

                Transform orientTrf           = GeometryUtil.CreateTransformFromPlane(plane);
                XYZ       projectionDirection = plane.Normal;

                IList <IList <CurveLoop> > sortedLoops = ExporterIFCUtils.SortCurveLoops(boundaries);
                if (sortedLoops.Count == 0)
                {
                    return;
                }

                FilledRegionType filledRegionType = filledRegion.Document.GetElement(filledRegion.GetTypeId()) as FilledRegionType;
                Color            color            = filledRegionType != null?CategoryUtil.GetSafeColor(filledRegionType.ForegroundPatternColor) : new Color(0, 0, 0);

                ElementId foregroundPatternId = filledRegionType != null ? filledRegionType.ForegroundPatternId : ElementId.InvalidElementId;
                ElementId categoryId          = CategoryUtil.GetSafeCategoryId(filledRegion);

                using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, filledRegion, null, orientTrf))
                {
                    foreach (IList <CurveLoop> curveLoopList in sortedLoops)
                    {
                        IFCAnyHandle           outerCurve  = null;
                        HashSet <IFCAnyHandle> innerCurves = null;
                        for (int ii = 0; ii < curveLoopList.Count; ii++)
                        {
                            IFCAnyHandle ifcCurve = GeometryUtil.CreateIFCCurveFromCurveLoop(exporterIFC, curveLoopList[ii], orientTrf, projectionDirection);
                            if (ii == 0)
                            {
                                outerCurve = ifcCurve;
                            }
                            else
                            {
                                if (innerCurves == null)
                                {
                                    innerCurves = new HashSet <IFCAnyHandle>();
                                }
                                innerCurves.Add(ifcCurve);
                            }
                        }

                        IFCAnyHandle representItem = IFCInstanceExporter.CreateAnnotationFillArea(file, outerCurve, innerCurves);
                        file.CreateStyle(exporterIFC, representItem, color, foregroundPatternId);

                        HashSet <IFCAnyHandle> bodyItems = new HashSet <IFCAnyHandle>();
                        bodyItems.Add(representItem);
                        IFCAnyHandle bodyRepHnd = RepresentationUtil.CreateAnnotationSetRep(exporterIFC, filledRegion, categoryId,
                                                                                            exporterIFC.Get2DContextHandle(), bodyItems);

                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyRepHnd))
                        {
                            return;
                        }

                        List <IFCAnyHandle> shapeReps = new List <IFCAnyHandle>();
                        shapeReps.Add(bodyRepHnd);

                        IFCAnyHandle productShape = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, shapeReps);
                        IFCAnyHandle annotation   = IFCInstanceExporter.CreateAnnotation(exporterIFC, filledRegion, GUIDUtil.CreateGUID(), ExporterCacheManager.OwnerHistoryHandle,
                                                                                         setter.LocalPlacement, productShape);

                        productWrapper.AddAnnotation(annotation, setter.LevelInfo, true);
                    }
                }

                transaction.Commit();
            }
        }