Exemplo n.º 1
0
        public override void BakeGeometry(RhinoDoc doc, ObjectAttributes att, List <Guid> obj_ids)
        {
            // Bake as blocks to save memory, file size and make it possible to edit all at once
            for (var i = 0; i < _moduleGeometry.Count; i++)
            {
                var directGeometry          = _moduleGeometry[i];
                var directAttributes        = Enumerable.Repeat(att.Duplicate(), directGeometry.Count);
                var referencedObjects       = _moduleGuids[i].Select(guid => doc.Objects.FindId(guid)).Where(obj => obj != null);
                var referencedGeometry      = referencedObjects.Select(obj => obj.Geometry);
                var referencedAttributes    = referencedObjects.Select(obj => obj.Attributes);
                var referencedNewAttributes = referencedAttributes.Select(originalAttributes => {
                    var mainAttributesDuplicate         = att.Duplicate();
                    mainAttributesDuplicate.ObjectColor = originalAttributes.ColorSource == ObjectColorSource.ColorFromObject
                    ? originalAttributes.ObjectColor
                    : doc.Layers[originalAttributes.LayerIndex].Color;
                    mainAttributesDuplicate.ColorSource   = ObjectColorSource.ColorFromObject;
                    mainAttributesDuplicate.MaterialIndex = originalAttributes.MaterialSource == ObjectMaterialSource.MaterialFromObject
                    ? originalAttributes.MaterialIndex
                    : doc.Layers[originalAttributes.LayerIndex].RenderMaterialIndex;
                    mainAttributesDuplicate.MaterialSource = ObjectMaterialSource.MaterialFromObject;
                    mainAttributesDuplicate.LinetypeIndex  = originalAttributes.LinetypeSource == ObjectLinetypeSource.LinetypeFromObject ?
                                                             originalAttributes.LinetypeIndex
                    : doc.Layers[originalAttributes.LayerIndex].LinetypeIndex;
                    mainAttributesDuplicate.LinetypeSource = ObjectLinetypeSource.LinetypeFromObject;
                    mainAttributesDuplicate.LayerIndex     = originalAttributes.LayerIndex;
                    return(mainAttributesDuplicate);
                });
                var geometry   = directGeometry.Concat(referencedGeometry).ToList();
                var attributes = directAttributes.Concat(referencedNewAttributes).ToList();
                var name       = _moduleNames[i];
                var transforms = _moduleTransforms[i];
                // Only bake if the module appears in any slots
                if (transforms.Count > 0)
                {
                    var newName = name;
                    while (doc.InstanceDefinitions.Any(inst => inst.Name == newName))
                    {
                        newName += "_1";
                    }

                    var instanceIndex = doc.InstanceDefinitions.Add(newName,
                                                                    "Geometry of module " + name,
                                                                    Point3d.Origin,
                                                                    geometry,
                                                                    attributes);
                    var blockAttributes = att.Duplicate();
                    blockAttributes.LayerIndex = doc.Layers.CurrentLayerIndex;
                    foreach (var transfrom in transforms)
                    {
                        obj_ids.Add(
                            doc.Objects.AddInstanceObject(instanceIndex, transfrom, blockAttributes)
                            );
                    }
                }
            }
        }
Exemplo n.º 2
0
        public override void BakeGeometry(RhinoDoc doc, ObjectAttributes att, List <Guid> obj_ids)
        {
            if (att == null)
            {
                att = doc.CreateDefaultAttributes();
            }
            var layerIndex = doc.Layers.CurrentLayerIndex;

            foreach (var line in _explicitLines)
            {
                var lineAttributes = att.Duplicate();
                lineAttributes.ObjectColor = line.Color;
                lineAttributes.ColorSource = ObjectColorSource.ColorFromObject;
                lineAttributes.LayerIndex  = layerIndex;
                obj_ids.Add(doc.Objects.AddLine(line.Line, lineAttributes));
            }

            foreach (var line in _typedLines)
            {
                var lineAttributes = att.Duplicate();
                lineAttributes.ObjectColor = line.Color;
                lineAttributes.ColorSource = ObjectColorSource.ColorFromObject;
                lineAttributes.LayerIndex  = layerIndex;
                obj_ids.Add(doc.Objects.AddLine(line.Line, lineAttributes));

                var oneQuarterPoint = line.Line.From + (line.Line.To - line.Line.From) / 4;

                var dotAttributes = att.Duplicate();
                dotAttributes.ObjectColor = line.Color;
                dotAttributes.ColorSource = ObjectColorSource.ColorFromObject;
                dotAttributes.LayerIndex  = layerIndex;
                obj_ids.Add(doc.Objects.AddTextDot(line.Type, oneQuarterPoint, dotAttributes));
            }

            foreach (var line in _outLines)
            {
                var lineAttributes = att.Duplicate();
                lineAttributes.ObjectColor = line.Color;
                lineAttributes.ColorSource = ObjectColorSource.ColorFromObject;
                lineAttributes.LayerIndex  = layerIndex;
                obj_ids.Add(doc.Objects.AddLine(line.Line, lineAttributes));

                var dotAttributes = att.Duplicate();
                dotAttributes.ObjectColor = line.Color;
                dotAttributes.ColorSource = ObjectColorSource.ColorFromObject;
                dotAttributes.LayerIndex  = layerIndex;
                obj_ids.Add(doc.Objects.AddTextDot(Config.OUTER_MODULE_NAME, line.Line.To, dotAttributes));
            }
        }
Exemplo n.º 3
0
        public override void BakeGeometry(RhinoDoc doc, ObjectAttributes att, List <Guid> obj_ids)
        {
            List <GH_Colour> cu = ((GH_Structure <GH_Colour>)Params.Input[3].VolatileData).FlattenData();
            List <GH_Curve>  lu = ((GH_Structure <GH_Curve>)Params.Output[0].VolatileData).FlattenData();
            List <GH_Colour> cd = ((GH_Structure <GH_Colour>)Params.Input[4].VolatileData).FlattenData();
            List <GH_Curve>  ld = ((GH_Structure <GH_Curve>)Params.Output[1].VolatileData).FlattenData();

            if (lu.Count != 0 && cu.Count != 0)
            {
                foreach (GH_Curve c in lu)
                {
                    if (!c.IsValid)
                    {
                        continue;
                    }
                    ObjectAttributes oa = att.Duplicate();
                    oa.ColorSource = ObjectColorSource.ColorFromObject;
                    oa.ObjectColor = cu[0].Value;
                    Guid id = Guid.Empty;
                    c.BakeGeometry(doc, oa, ref id);
                    obj_ids.Add(id);
                }
            }

            if (ld.Count == 0 || cd.Count == 0)
            {
                return;
            }
            foreach (GH_Curve c in ld)
            {
                if (!c.IsValid)
                {
                    continue;
                }
                ObjectAttributes oa = att.Duplicate();
                oa.ColorSource = ObjectColorSource.ColorFromObject;
                oa.ObjectColor = cd[0].Value;
                Guid id = Guid.Empty;
                c.BakeGeometry(doc, oa, ref id);
                obj_ids.Add(id);
            }
        }
Exemplo n.º 4
0
        public bool BakeGeometry(RhinoDoc doc, ObjectAttributes baking_attributes, out Guid obj_guid)
        {
            if (Value != null)
            {
                var att = baking_attributes.Duplicate();

                var str_id = this.Id > 0 ? Id.ToString() : "0"; // string.Empty;

                string fix_literal = this.FixLiteral
                                     .Replace("PP", "PXPYPZ")
                                     .Replace("MM", "MXMYMZ");

                if (fix_literal == "F")
                {
                    fix_literal = "PXPYPZMXMYMZ";
                }

                // set user strings
                att.SetUserString("SOF_OBJ_TYPE", "SLN");
                att.SetUserString("SOF_ID", str_id);

                if (this.GroupId > 0)
                {
                    att.SetUserString("SOF_GRP", this.GroupId.ToString());
                }
                if (this.SectionId > 0)
                {
                    att.SetUserString("SOF_STYP", "B");
                    att.SetUserString("SOF_STYP2", "E");
                    att.SetUserString("SOF_SNO", this.SectionId.ToString());
                    att.SetUserString("SOF_SNOE", "SOF_PROP_COMBO_NONE");
                }
                att.SetUserString("SOF_SDIV", "0.0");

                if (DirectionLocalZ.Length > 1.0E-6)
                {
                    att.SetUserString("SOF_DRX", DirectionLocalZ.X.ToString("F6"));
                    att.SetUserString("SOF_DRY", DirectionLocalZ.Y.ToString("F6"));
                    att.SetUserString("SOF_DRZ", DirectionLocalZ.Z.ToString("F6"));
                }

                if (string.IsNullOrEmpty(fix_literal) == false)
                {
                    att.SetUserString("SOF_FIX", fix_literal);
                }

                obj_guid = doc.Objects.AddCurve(Value, att);
            }
            else
            {
                obj_guid = new Guid();
            }
            return(true);
        }
Exemplo n.º 5
0
        public bool BakeGeometry(RhinoDoc doc, ObjectAttributes baking_attributes, out Guid obj_guid)
        {
            if (Value != null)
            {
                var att = baking_attributes.Duplicate();

                att.SetUserString("SOF_OBJ_TYPE", "SPT");
                att.SetUserString("SOF_ID", Math.Max(0, Id).ToString());

                if (DirectionLocalX.Length > 1.0E-6)
                {
                    var dir_x = DirectionLocalX; dir_x.Unitize();

                    att.SetUserString("SOF_SX", dir_x.X.ToString("F6"));
                    att.SetUserString("SOF_SY", dir_x.Y.ToString("F6"));
                    att.SetUserString("SOF_SZ", dir_x.Z.ToString("F6"));
                }
                if (DirectionLocalZ.Length > 1.0E-6)
                {
                    var dir_z = DirectionLocalZ; dir_z.Unitize();

                    att.SetUserString("SOF_NX", DirectionLocalZ.X.ToString("F6"));
                    att.SetUserString("SOF_NY", DirectionLocalZ.Y.ToString("F6"));
                    att.SetUserString("SOF_NZ", DirectionLocalZ.Z.ToString("F6"));
                }

                if (string.IsNullOrEmpty(fixLiteral) == false)
                {
                    string fix_literal = FixLiteral.Replace("PP", "PXPYPZ").Replace("MM", "MXMYMZ");

                    if (fix_literal == "F")
                    {
                        fix_literal = "PXPYPZMXMYMZ";
                    }

                    att.SetUserString("SOF_FIX", fix_literal);
                }

                if (string.IsNullOrWhiteSpace(UserText) == false)
                {
                    att.SetUserString("SOF_USERTXT", UserText);
                }

                obj_guid = doc.Objects.AddPoint(Value.Location, att);
            }
            else
            {
                obj_guid = new Guid();
            }
            return(true);
        }
Exemplo n.º 6
0
        public bool BakeGeometry(RhinoDoc doc, ObjectAttributes baking_attributes, out Guid obj_guid)
        {
            if (Value != null)
            {
                var att = baking_attributes.Duplicate();

                string fix_literal = this.FixLiteral
                                     .Replace("PP", "PXPYPZ")
                                     .Replace("MM", "MXMYMZ");

                if (fix_literal == "F")
                {
                    fix_literal = "PXPYPZMXMYMZ";
                }


                att.SetUserString("SOF_OBJ_TYPE", "SPT");
                att.SetUserString("SOF_ID", this.Id.ToString());

                if (DirectionLocalX.Length > 1.0E-6)
                {
                    att.SetUserString("SOF_SX", this.DirectionLocalX.X.ToString("F6"));
                    att.SetUserString("SOF_SY", this.DirectionLocalX.Y.ToString("F6"));
                    att.SetUserString("SOF_SZ", this.DirectionLocalX.Z.ToString("F6"));
                }
                if (DirectionLocalZ.Length > 1.0E-6)
                {
                    att.SetUserString("SOF_NX", this.DirectionLocalZ.X.ToString("F6"));
                    att.SetUserString("SOF_NY", this.DirectionLocalZ.Y.ToString("F6"));
                    att.SetUserString("SOF_NZ", this.DirectionLocalZ.Z.ToString("F6"));
                }

                if (string.IsNullOrEmpty(fix_literal) == false)
                {
                    att.SetUserString("SOF_FIX", fix_literal);
                }


                obj_guid = doc.Objects.AddPoint(Value.Location, att);
            }
            else
            {
                obj_guid = new Guid();
            }
            return(true);
        }
Exemplo n.º 7
0
        public bool BakeGeometry(RhinoDoc doc, ObjectAttributes baking_attributes, out Guid obj_guid)
        {
            if (Value != null)
            {
                var att = baking_attributes.Duplicate();

                var id_str  = this.Id > 0 ? Id.ToString() : "0";
                var grp_str = this.GroupId.ToString();
                var mno_str = this.MaterialId.ToString();
                var mrf_str = this.ReinforcementId.ToString();
                var t_str   = this.Thickness.ToString();

                att.SetUserString("SOF_OBJ_TYPE", "SAR");
                att.SetUserString("SOF_ID", id_str);
                att.SetUserString("SOF_T", Thickness.ToString());
                if (GroupId > 0)
                {
                    att.SetUserString("SOF_GRP", GroupId.ToString());
                }
                if (MaterialId > 0)
                {
                    att.SetUserString("SOF_MNO", MaterialId.ToString());
                }
                if (ReinforcementId > 0)
                {
                    att.SetUserString("SOF_MRF", ReinforcementId.ToString());
                }

                if (DirectionLocalX.Length > 1.0e-6)
                {
                    att.SetUserString("SOF_DRX", DirectionLocalX.X.ToString("F6"));
                    att.SetUserString("SOF_DRX", DirectionLocalX.Y.ToString("F6"));
                    att.SetUserString("SOF_DRZ", DirectionLocalX.Z.ToString("F6"));
                }

                obj_guid = doc.Objects.AddBrep(Value, att);
            }
            else
            {
                obj_guid = new Guid();
            }
            return(true);
        }
Exemplo n.º 8
0
        public override void BakeGeometry(RhinoDoc doc, ObjectAttributes att, List <Guid> obj_ids)
        {
            List <GH_Colour> colour = ((GH_Structure <GH_Colour>)Params.Output[0].VolatileData).FlattenData();
            List <GH_Curve>  curve  = ((GH_Structure <GH_Curve>)Params.Input[0].VolatileData).FlattenData();

            for (var i = 0; i < curve.Count; i++)
            {
                GH_Curve c = curve[i];
                if (!c.IsValid)
                {
                    continue;
                }
                ObjectAttributes oa = att.Duplicate();
                oa.ColorSource = ObjectColorSource.ColorFromObject;
                oa.ObjectColor = colour[i].Value;
                Guid id = Guid.Empty;
                c.BakeGeometry(doc, oa, ref id);
                obj_ids.Add(id);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Bakes the <see cref="Cage"/> in color hinting its entropy. Required
        /// by Grasshopper.
        /// </summary>
        /// <param name="doc">The doc.</param>
        /// <param name="att">The att.</param>
        /// <param name="obj_ids">The obj_ids.</param>
        public void BakeGeometry(RhinoDoc doc, ObjectAttributes att, List <Guid> obj_ids)
        {
            if (att == null)
            {
                att = doc.CreateDefaultAttributes();
            }

            var color = Config.CAGE_UNKNOWN_COLOR;

            if (AllowsAnyModule)
            {
                color = Config.CAGE_EVERYTHING_COLOR;
            }

            if (IsContradictory || !IsValid)
            {
                color = Config.CAGE_NONE_COLOR;
            }

            var partsCount = AllowedPartNames.Count;

            if (partsCount == 1 && AllPartsCount != 0)
            {
                color = Config.CAGE_ONE_COLOR;
            }

            if (partsCount != 1 && AllPartsCount != 0)
            {
                var t = (double)partsCount / AllPartsCount;
                color = InterpolateColor(Config.CAGE_TWO_COLOR, Config.CAGE_EVERYTHING_COLOR, t);
            }

            var cageAttributes = att.Duplicate();

            cageAttributes.ObjectColor = color;
            cageAttributes.ColorSource = ObjectColorSource.ColorFromObject;

            obj_ids.Add(doc.Objects.AddBox(Cage, cageAttributes));
        }
        public bool BakeElement
        (
            IDictionary <DB.ElementId, Guid> idMap,
            bool overwrite,
            RhinoDoc doc,
            ObjectAttributes att,
            out Guid guid
        )
        {
            // 1. Check if is already cloned
            if (idMap.TryGetValue(Id, out guid))
            {
                return(true);
            }

            // 3. Update if necessary
            if (Value is DB.CurveElement curve)
            {
                att      = att.Duplicate();
                att.Name = DisplayName;
                if (Category.BakeElement(idMap, false, doc, att, out var layerGuid))
                {
                    att.LayerIndex = doc.Layers.FindId(layerGuid).Index;
                }

                guid = doc.Objects.Add(curve.GeometryCurve.ToCurve(), att);

                if (guid != Guid.Empty)
                {
                    idMap.Add(Id, guid);
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 11
0
        public bool BakeGeometry(RhinoDoc doc, ObjectAttributes att, out Guid obj_guid)
        {
            obj_guid = Guid.Empty;

            if (att == null)
            {
                att = doc.CreateDefaultAttributes();
            }

            string id    = Guid.NewGuid().ToString();
            int    idxGr = doc.Groups.Add("IG-" + id);
            int    idxLy = doc.Layers.Add("IG-" + id, Color.Aqua);

            ObjectAttributes att1 = att.Duplicate();

            att1.AddToGroup(idxGr);
            att1.LayerIndex = idxLy;

            Line        ln;
            List <long> edgesID = new List <long>();
            long        data1, data2;
            Point3d     p1, p2;
            int         next, count;

            int[] hf;

            foreach (int elementID in ElementsKeys)
            {
                IElement e = GetElementWithKey(elementID);

                for (int halfFacetID = 1; halfFacetID <= e.HalfFacetsCount; halfFacetID++)
                {
                    e.GetHalfFacet(halfFacetID, out hf);

                    count = 1;
                    if (e.TopologicDimension == 3)
                    {
                        count = hf.Length;
                    }
                    for (int i = 0; i < count; i++)
                    {
                        next = i + 1;
                        if (i == count - 1)
                        {
                            if (count > 1)
                            {
                                next = 0;
                            }
                            else
                            {
                                next = 1;
                            }
                        }
                        data1 = (Int64)hf[i] << 32 | (Int64)hf[next];
                        data2 = (Int64)hf[next] << 32 | (Int64)hf[i];
                        if (!edgesID.Contains(data1) && !edgesID.Contains(data2))
                        {
                            p1 = GetVertexWithKey(hf[i]).RhinoPoint;
                            p2 = GetVertexWithKey(hf[next]).RhinoPoint;
                            ln = new Line(p1, p2);
                            doc.Objects.AddLine(ln, att1);
                            edgesID.Add(data1);
                        }
                    }
                }
            }
            return(true);
        }
Exemplo n.º 12
0
        public override void BakeGeometry(RhinoDoc doc, ObjectAttributes att, List <Guid> obj_ids)
        {
            // TODO: Bakes into "Default" layer for some reason
            var sourceReferencedObjects = _sourceModuleGuids
                                          .Select(guid => doc.Objects.FindId(guid))
                                          .Where(obj => obj != null);
            var sourceReferencedAttributes = sourceReferencedObjects.Select(obj => obj.Attributes);
            var sourceNewAttributes        = sourceReferencedAttributes.Select(originalAttributes => {
                var mainAttributesDuplicate            = att.Duplicate();
                mainAttributesDuplicate.ObjectColor    = originalAttributes.ObjectColor;
                mainAttributesDuplicate.ColorSource    = originalAttributes.ColorSource;
                mainAttributesDuplicate.MaterialIndex  = originalAttributes.MaterialIndex;
                mainAttributesDuplicate.MaterialSource = originalAttributes.MaterialSource;
                mainAttributesDuplicate.LinetypeIndex  = originalAttributes.LinetypeIndex;
                mainAttributesDuplicate.LinetypeSource = originalAttributes.LinetypeSource;
                return(mainAttributesDuplicate);
            });
            var sourceData = _sourceModuleReferencedGeometry
                             .Zip(sourceNewAttributes, (geo, attrib) => new { geo, attrib });

            var sourceGroupId = doc.Groups.Add(_ruleString + " Source");

            foreach (var geometry in _sourceModuleGeometry)
            {
                var geomId = doc.Objects.Add(geometry, att);
                doc.Groups.AddToGroup(sourceGroupId, geomId);
                obj_ids.Add(geomId);
            }

            foreach (var item in sourceData)
            {
                var geometry   = item.geo;
                var attributes = item.attrib;
                var geomId     = doc.Objects.Add(geometry, attributes);
                doc.Groups.AddToGroup(sourceGroupId, geomId);
                obj_ids.Add(geomId);
            }

            var targetReferencedObjects = _targetModuleGuids
                                          .Select(guid => doc.Objects.FindId(guid))
                                          .Where(obj => obj != null);
            var targetReferencedAttributes = targetReferencedObjects.Select(obj => obj.Attributes);
            var targetNewAttributes        = targetReferencedAttributes.Select(originalAttributes => {
                var mainAttributesDuplicate            = att.Duplicate();
                mainAttributesDuplicate.ObjectColor    = originalAttributes.ObjectColor;
                mainAttributesDuplicate.ColorSource    = originalAttributes.ColorSource;
                mainAttributesDuplicate.MaterialIndex  = originalAttributes.MaterialIndex;
                mainAttributesDuplicate.MaterialSource = originalAttributes.MaterialSource;
                mainAttributesDuplicate.LinetypeIndex  = originalAttributes.LinetypeIndex;
                mainAttributesDuplicate.LinetypeSource = originalAttributes.LinetypeSource;
                return(mainAttributesDuplicate);
            });
            var targetData = _targetModuleReferencedGeometry
                             .Zip(targetNewAttributes, (geo, attrib) => new { geo, attrib });

            var targetGroupId = doc.Groups.Add(_ruleString + " Target");

            foreach (var geometry in _targetModuleGeometry)
            {
                var geomId = doc.Objects.Add(geometry, att);
                doc.Groups.AddToGroup(targetGroupId, geomId);
                obj_ids.Add(geomId);
            }

            foreach (var item in targetData)
            {
                var geometry   = item.geo;
                var attributes = item.attrib;
                var geomId     = doc.Objects.Add(geometry, attributes);
                doc.Groups.AddToGroup(targetGroupId, geomId);
                obj_ids.Add(geomId);
            }
        }
        public new bool BakeElement
        (
            IDictionary <DB.ElementId, Guid> idMap,
            bool overwrite,
            RhinoDoc doc,
            ObjectAttributes att,
            out Guid guid
        )
        {
            // 1. Check if is already cloned
            if (idMap.TryGetValue(Id, out guid))
            {
                return(true);
            }

            // 3. Update if necessary
            if (Value is DB.FamilyInstance element)
            {
                using (var options = new DB.Options()
                {
                    DetailLevel = DB.ViewDetailLevel.Fine
                })
                {
                    using (var context = GeometryDecoder.Context.Push())
                    {
                        context.Element         = element;
                        context.GraphicsStyleId = element.Category?.GetGraphicsStyle(DB.GraphicsStyleType.Projection)?.Id ?? DB.ElementId.InvalidElementId;
                        context.MaterialId      = element.Category?.Material?.Id ?? DB.ElementId.InvalidElementId;

                        using (var geometry = element.GetGeometry(options))
                        {
                            if (geometry is DB.GeometryElement geometryElement)
                            {
                                var transform      = element.GetTransform();
                                var location       = new Plane(transform.Origin.ToPoint3d(), transform.BasisX.ToVector3d(), transform.BasisY.ToVector3d());
                                var worldToElement = Transform.PlaneToPlane(location, Plane.WorldXY);

                                if (BakeGeometryElement(idMap, overwrite, doc, att, worldToElement, element, geometry, out var idefIndex))
                                {
                                    att      = att.Duplicate();
                                    att.Name = element.get_Parameter(DB.BuiltInParameter.ALL_MODEL_MARK)?.AsString() ?? string.Empty;
                                    att.Url  = element.get_Parameter(DB.BuiltInParameter.ALL_MODEL_URL)?.AsString() ?? string.Empty;

                                    var category = Category;
                                    if (category is object && category.BakeElement(idMap, false, doc, att, out var layerGuid))
                                    {
                                        att.LayerIndex = doc.Layers.FindId(layerGuid).Index;
                                    }

                                    guid = doc.Objects.AddInstanceObject(idefIndex, Transform.PlaneToPlane(Plane.WorldXY, location), att);
                                }
                            }

                            if (guid != Guid.Empty)
                            {
                                idMap.Add(Id, guid);
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
Exemplo n.º 14
0
        public bool BakeGeometry(RhinoDoc doc, ObjectAttributes baking_attributes, out Guid obj_guid)
        {
            if (Value != null)
            {
                var att = baking_attributes.Duplicate();

                // set user strings
                att.SetUserString("SOF_OBJ_TYPE", "SLN");
                att.SetUserString("SOF_ID", Math.Max(0, Id).ToString());

                if (GroupId > 0)
                {
                    att.SetUserString("SOF_GRP", GroupId.ToString());
                }
                if (SectionIdStart > 0)
                {
                    att.SetUserString("SOF_STYP", ElementType);
                    att.SetUserString("SOF_STYP2", "E");
                    att.SetUserString("SOF_SNO", SectionIdStart.ToString());

                    if (SectionIdEnd > 0)
                    {
                        att.SetUserString("SOF_SNOE", SectionIdEnd.ToString());
                    }
                    else
                    {
                        att.SetUserString("SOF_SNOE", "SOF_PROP_COMBO_NONE");
                    }
                }

                if (ElementSize != 0.0)
                {
                    att.SetUserString("SOF_SDIV", ElementSize.ToString());
                }

                if (DirectionLocalZ.Length > 1.0E-6)
                {
                    var dir_z = DirectionLocalZ; dir_z.Unitize();

                    att.SetUserString("SOF_DRX", dir_z.X.ToString("F6"));
                    att.SetUserString("SOF_DRY", dir_z.Y.ToString("F6"));
                    att.SetUserString("SOF_DRZ", dir_z.Z.ToString("F6"));
                }

                if (string.IsNullOrWhiteSpace(fixLiteral) == false)
                {
                    string fix_literal = FixLiteral.Replace("PP", "PXPYPZ").Replace("MM", "MXMYMZ");

                    if (fix_literal == "F")
                    {
                        fix_literal = "PXPYPZMXMYMZ";
                    }

                    att.SetUserString("SOF_FIX", fix_literal);
                }

                if (string.IsNullOrWhiteSpace(UserText) == false)
                {
                    att.SetUserString("SOF_USERTXT", UserText);
                }

                obj_guid = doc.Objects.AddCurve(Value, att);
            }
            else
            {
                obj_guid = new Guid();
            }
            return(true);
        }
Exemplo n.º 15
0
        public bool BakeGeometry(RhinoDoc doc, ObjectAttributes baking_attributes, out Guid obj_guid)
        {
            if (Value != null)
            {
                var att = baking_attributes.Duplicate();

                att.SetUserString("SOF_OBJ_TYPE", "SAR");
                att.SetUserString("SOF_ID", Math.Max(0, Id).ToString());

                if (GroupId > 0)
                {
                    att.SetUserString("SOF_GRP", GroupId.ToString());
                }
                if (MaterialId > 0)
                {
                    att.SetUserString("SOF_MNO", MaterialId.ToString());
                }
                if (ReinforcementId > 0)
                {
                    att.SetUserString("SOF_MRF", ReinforcementId.ToString());
                }

                att.SetUserString("SOF_T", Thickness.ToString());
                att.SetUserString("SOF_QREF", Alignment);

                if (MeshOptions == "AUTO")
                {
                    att.SetUserString("SOF_MCTL", "0");
                }
                else if (MeshOptions == "REGM")
                {
                    att.SetUserString("SOF_MCTL", "1");
                }
                else if (MeshOptions == "SNGQ")
                {
                    att.SetUserString("SOF_MCTL", "2");
                }
                else if (MeshOptions == "OFF")
                {
                    att.SetUserString("SOF_MCTL", "-1");
                }

                if (ElementSize != 0.0)
                {
                    att.SetUserString("SOF_HMIN", ElementSize.ToString());
                }

                if (DirectionLocalX.Length > 1.0e-6)
                {
                    var dir_x = DirectionLocalX; dir_x.Unitize();

                    att.SetUserString("SOF_DRX", dir_x.X.ToString("F6"));
                    att.SetUserString("SOF_DRY", dir_x.Y.ToString("F6"));
                    att.SetUserString("SOF_DRZ", dir_x.Z.ToString("F6"));
                }

                if (string.IsNullOrWhiteSpace(UserText) == false)
                {
                    att.SetUserString("SOF_USERTXT", UserText);
                }

                obj_guid = doc.Objects.AddBrep(Value, att);
            }
            else
            {
                obj_guid = new Guid();
            }
            return(true);
        }