Ejemplo n.º 1
0
        public List <ApplicationPlaceholderObject> AlignmentToNative(Alignment alignment)
        {
            var docObj = GetExistingElementByApplicationId(alignment.applicationId);

            //delete and re-create line
            //TODO: check if can be modified
            if (docObj != null)
            {
                Doc.Delete(docObj.Id);
            }

            var curves          = CurveToNative(alignment.curves);
            var placeholders    = new List <ApplicationPlaceholderObject>();
            var curveEnumerator = curves.GetEnumerator();

            while (curveEnumerator.MoveNext() && curveEnumerator.Current != null)
            {
                var           baseCurve  = curveEnumerator.Current as DB.Curve;
                DB.ModelCurve revitCurve = Doc.Create.NewModelCurve(baseCurve, NewSketchPlaneFromCurve(baseCurve, Doc));
                var           lineStyles = revitCurve.GetLineStyleIds().First();
                placeholders.Add(new ApplicationPlaceholderObject()
                {
                    applicationId = alignment.applicationId, ApplicationGeneratedId = revitCurve.UniqueId, NativeObject = revitCurve
                });
            }
            return(placeholders);
        }
        public CifGM.Alignment AlignmentToNative(Alignment alignment)
        {
            var baseCurve   = alignment.baseCurve;
            var nativeCurve = CurveToNative(baseCurve);

            ConsensusConnectionEdit con = ConsensusConnectionEdit.GetActive();

            con.StartTransientMode();
            AlignmentEdit alignmentEdit = (CifGM.Alignment.CreateFromElement(con, nativeCurve)) as AlignmentEdit;

            if (alignmentEdit.DomainObject == null)
            {
                return(null);
            }

            alignmentEdit.AddStationing(0, alignment.startStation, true);

            if (alignment.stationEquations != null)
            {
                var formatted = (List <string>)alignment["formattedStationEquations"];
                for (int i = 0; i < formatted.Count(); i++)
                {
                    var locationAlong = alignment.stationEquations[(i * 3) + 1];
                    var ahead         = formatted[i];
                    alignmentEdit.AddStationEquation(ahead, locationAlong);
                }
            }

            con.PersistTransients();

            return(null);
        }
Ejemplo n.º 3
0
        public Alignment AlignmentToSpeckle(CivilDB.Alignment alignment)
        {
            var _alignment = new Alignment();

            // get the alignment subentity curves
            List <ICurve> curves   = new List <ICurve>();
            var           stations = new List <double>();

            for (int i = 0; i < alignment.Entities.Count; i++)
            {
                var entity = alignment.Entities.GetEntityByOrder(i);

                var    polycurve = new Polycurve(units: ModelUnits, applicationId: entity.EntityId.ToString());
                var    segments  = new List <ICurve>();
                double length    = 0;
                for (int j = 0; j < entity.SubEntityCount; j++)
                {
                    CivilDB.AlignmentSubEntity subEntity = entity[j];
                    ICurve segment = null;
                    switch (subEntity.SubEntityType)
                    {
                    case CivilDB.AlignmentSubEntityType.Arc:
                        var arc = subEntity as CivilDB.AlignmentSubEntityArc;
                        segment = AlignmentArcToSpeckle(arc);
                        break;

                    case CivilDB.AlignmentSubEntityType.Line:
                        var line = subEntity as CivilDB.AlignmentSubEntityLine;
                        segment = AlignmentLineToSpeckle(line);
                        break;

                    case CivilDB.AlignmentSubEntityType.Spiral:
                        var spiral = subEntity as CivilDB.AlignmentSubEntitySpiral;
                        segment = AlignmentSpiralToSpeckle(spiral, alignment);
                        break;
                    }
                    if (segment != null)
                    {
                        length += subEntity.Length;
                        segments.Add(segment);
                    }
                }
                if (segments.Count == 1)
                {
                    curves.Add(segments[0]);
                }
                else
                {
                    polycurve.segments = segments;
                    polycurve.length   = length;

                    // add additional props like entity type
                    polycurve["alignmentType"] = entity.EntityType.ToString();
                    curves.Add(polycurve);
                }
            }

            // get display poly
            var poly = alignment.BaseCurve as Autodesk.AutoCAD.DatabaseServices.Polyline;

            using (Polyline2d poly2d = poly.ConvertTo(false))
            {
                _alignment.displayValue = CurveToSpeckle(poly2d.Spline.ToPolyline()) as Polyline;
            }

            _alignment.curves = curves;
            if (alignment.DisplayName != null)
            {
                _alignment.name = alignment.DisplayName;
            }
            if (alignment.StartingStation != null)
            {
                _alignment.startStation = alignment.StartingStation;
            }
            if (alignment.EndingStation != null)
            {
                _alignment.endStation = alignment.EndingStation;
            }

            // handle station equations
            var equations  = new List <double>();
            var directions = new List <bool>();

            foreach (var stationEquation in alignment.StationEquations)
            {
                equations.AddRange(new List <double> {
                    stationEquation.RawStationBack, stationEquation.StationBack, stationEquation.StationAhead
                });
                bool equationIncreasing = (stationEquation.EquationType.Equals(CivilDB.StationEquationType.Increasing)) ? true : false;
                directions.Add(equationIncreasing);
            }
            _alignment.stationEquations          = equations;
            _alignment.stationEquationDirections = directions;

            _alignment.units = ModelUnits;

            // add civil3d props if they exist
            if (alignment.SiteName != null)
            {
                _alignment["site"] = alignment.SiteName;
            }
            if (alignment.StyleName != null)
            {
                _alignment["style"] = alignment.StyleName;
            }

            return(_alignment);
        }
Ejemplo n.º 4
0
        public CivilDB.Alignment AlignmentToNative(Alignment alignment)
        {
            var name  = alignment.name ?? string.Empty;
            var layer = Doc.Database.LayerZero;

            BlockTableRecord modelSpaceRecord = Doc.Database.GetModelSpace();
            var civilDoc = CivilApplication.ActiveDocument;

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

            #region properties
            var site  = ObjectId.Null;
            var style = civilDoc.Styles.AlignmentStyles.First();
            var label = civilDoc.Styles.LabelSetStyles.AlignmentLabelSetStyles.First();

            // get site
            if (alignment["site"] != null)
            {
                var _site = alignment["site"] as string;
                if (_site != string.Empty)
                {
                    foreach (ObjectId docSite in civilDoc.GetSiteIds())
                    {
                        var siteEntity = Trans.GetObject(docSite, OpenMode.ForRead) as CivilDB.Site;
                        if (siteEntity.Name.Equals(_site))
                        {
                            site = docSite;
                            break;
                        }
                    }
                }
            }

            // get style
            if (alignment["style"] != null)
            {
                var _style = alignment["style"] as string;
                foreach (var docStyle in civilDoc.Styles.AlignmentStyles)
                {
                    var styleEntity = Trans.GetObject(docStyle, OpenMode.ForRead) as CivilDB.Styles.AlignmentStyle;
                    if (styleEntity.Name.Equals(_style))
                    {
                        style = docStyle;
                        break;
                    }
                }
            }

            // get labelset
            if (alignment["label"] != null)
            {
                var _label = alignment["label"] as string;
                foreach (var docLabelSet in civilDoc.Styles.LabelSetStyles.AlignmentLabelSetStyles)
                {
                    var labelEntity = Trans.GetObject(docLabelSet, OpenMode.ForRead) as CivilDB.Styles.AlignmentLabelSetStyle;
                    if (labelEntity.Name.Equals(_label))
                    {
                        label = docLabelSet;
                        break;
                    }
                }
            }
            #endregion

            // create alignment entity curves
            var id = CivilDB.Alignment.Create(civilDoc, name, site, layer, style, label);
            if (id == ObjectId.Null)
            {
                return(null);
            }
            var _alignment = Trans.GetObject(id, OpenMode.ForWrite) as CivilDB.Alignment;
            var entities   = _alignment.Entities;
            foreach (var curve in alignment.curves)
            {
                AddAlignmentEntity(curve, ref entities);
            }

            return(_alignment);
        }
        // alignments
        public Alignment AlignmentToSpeckle(CifGM.Alignment alignment)
        {
            var _alignment = new Alignment();

            CifGM.StationFormatSettings settings = CifGM.StationFormatSettings.GetStationFormatSettingsForModel(Model);
            var stationFormatter = new CifGM.StationingFormatter(alignment);

            _alignment.baseCurve = CurveToSpeckle(alignment.Element as DisplayableElement, ModelUnits);

            if (alignment.Name != null)
            {
                _alignment.name = alignment.Name;
            }

            if (alignment.FeatureName != null)
            {
                _alignment["featureName"] = alignment.FeatureName;
            }

            if (alignment.FeatureDefinition != null)
            {
                _alignment["featureDefinitionName"] = alignment.FeatureDefinition.Name;
            }

            var stationing = alignment.Stationing;

            if (stationing != null)
            {
                _alignment.startStation = stationing.StartStation;
                _alignment.endStation   = alignment.LinearGeometry.Length; // swap for end station

                var region = stationing.GetStationRegionFromDistanceAlong(stationing.StartStation);

                // handle station equations
                var equations         = new List <double>();
                var formattedEquation = new List <string>();
                //var directions = new List<bool>();
                foreach (var stationEquation in stationing.StationEquations)
                {
                    string stnVal = "";
                    stationFormatter.FormatStation(ref stnVal, stationEquation.DistanceAlong, settings);
                    formattedEquation.Add(stnVal);

                    // DistanceAlong represents Back Station/BackLocation, EquivalentStation represents Ahead Station
                    equations.AddRange(new List <double> {
                        stationEquation.DistanceAlong, stationEquation.DistanceAlong, stationEquation.EquivalentStation
                    });
                }
                _alignment.stationEquations             = equations;
                _alignment["formattedStationEquations"] = formattedEquation;
                //_alignment.stationEquationDirections = directions;
            }
            else
            {
                _alignment.startStation = 0;
            }

            _alignment.units = ModelUnits;

            return(_alignment);
        }