public static object ToNative(this SpeckleAnnotation annot)
        {
            if (annot.Plane != null)
            {
                // TEXT ENTITIY
                var textEntity = new TextEntity()
                {
                    Text       = annot.Text,
                    Plane      = annot.Plane.ToNative(),
                    FontIndex  = Rhino.RhinoDoc.ActiveDoc.Fonts.FindOrCreate(annot.FontName, ( bool )annot.Bold, ( bool )annot.Italic),
                    TextHeight = ( double )annot.TextHeight
                };
#if R6
                var dimStyleIndex = Rhino.RhinoDoc.ActiveDoc.DimStyles.Add("Speckle");
                var dimStyle      = new Rhino.DocObjects.DimensionStyle
                {
                    TextHeight = ( double )annot.TextHeight,
                    Font       = new Rhino.DocObjects.Font(annot.FontName, Rhino.DocObjects.Font.FontWeight.Bold, Rhino.DocObjects.Font.FontStyle.Italic, false, false)
                };
                Rhino.RhinoDoc.ActiveDoc.DimStyles.Modify(dimStyle, dimStyleIndex, true);

                textEntity.DimensionStyleId = Rhino.RhinoDoc.ActiveDoc.DimStyles[dimStyleIndex].Id;
#endif

                return(textEntity);
            }
            else
            {
                // TEXT DOT!
                var myTextdot = new TextDot(annot.Text, annot.Location.ToNative().Location);
                myTextdot.UserDictionary.ReplaceContentsWith(annot.Properties.ToNative());
                return(myTextdot);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="area"></param>
 /// <param name="units"></param>
 /// <param name="dimStyle"></param>
 /// <param name="alternate"></param>
 /// <returns></returns>
 public static string FormatArea(double area, UnitSystem units, Rhino.DocObjects.DimensionStyle dimStyle, bool alternate)
 {
     using (var sw = new StringWrapper())
     {
         IntPtr pString            = sw.NonConstPointer;
         IntPtr const_ptr_dimstyle = dimStyle == null ? IntPtr.Zero : dimStyle.ConstPointer();
         UnsafeNativeMethods.ON_TextContext_FormatArea(area, units, const_ptr_dimstyle, alternate, pString);
         return(sw.ToString());
     }
 }
Exemplo n.º 3
0
        private Mesh GenerateJointArmLabel(Point3d origin, Vector3d direction, string label, double length)
        {
            Polyline innerPoly;
            var      innerProfile = GetProfile(InnerWallRadius, direction);

            innerProfile.TryGetPolyline(out innerPoly);

            var pSideMid = (innerPoly[1] + innerPoly[0]) / 2 + origin;

            Vector3d dir1 = length < 0 ? direction : -direction;
            Vector3d dir3 = pSideMid - origin;
            Vector3d dir2 = Vector3d.CrossProduct(dir3, dir1);

            dir1.Unitize();
            dir2.Unitize();
            dir3.Unitize();

            var textHeight   = Math.Sqrt(OuterWallRadius * OuterWallRadius - InnerWallRadius * InnerWallRadius) / 1.5;
            var embossHeight = (OuterWallRadius - InnerWallRadius) * 1.2;

            Vector3d startTextOffset = (length < 0 ? -direction : direction) * (Math.Abs(length) - (OuterWallRadius - InnerWallRadius));

            Point3d planeOrigin = Point3d.Add(origin, startTextOffset);

            planeOrigin = Point3d.Add(planeOrigin, dir3 * (pSideMid - origin).Length);

            JointArmLabel[label] = planeOrigin;

            var plane = new Plane(planeOrigin, dir1, dir2);

            plane.UpdateEquation();

            var style = new Rhino.DocObjects.DimensionStyle();

            style.TextHorizontalAlignment = Rhino.DocObjects.TextHorizontalAlignment.Left;
            style.TextVerticalAlignment   = Rhino.DocObjects.TextVerticalAlignment.Middle;
            style.TextHeight = 1;
            var prefFont = Rhino.DocObjects.Font.InstalledFonts("Lucida Console");

            if (prefFont.Length > 0)
            {
                style.Font = prefFont.First();
            }

            var writingPlane = new Plane(planeOrigin, new Vector3d(0, 0, 1)); // Must write to flat plane for some reason

            TextEntity textEnt = TextEntity.Create(label, writingPlane, style, false, Math.Abs(length), 0);

            textEnt.SetBold(true);

            var meshes = textEnt.CreateExtrusions(style, embossHeight)
                         .Where(b => b != null)
                         .SelectMany(b => Mesh.CreateFromBrep(b.ToBrep(), MeshingParameters.FastRenderMesh));

            var scaleTrans = Transform.Scale(writingPlane, textHeight, textHeight, 1);
            var trans      = Transform.PlaneToPlane(writingPlane, plane);

            if (meshes.Count() > 0)
            {
                var mesh = meshes.First();
                foreach (var m in meshes.Skip(1))
                {
                    mesh.Append(m);
                }
                mesh.Weld(Tolerance);
                mesh.Normals.ComputeNormals();
                mesh.UnifyNormals();
                mesh.Normals.ComputeNormals();
                mesh.Transform(scaleTrans);
                mesh.Transform(trans);
                return(mesh);
            }

            return(null);
        }