Ejemplo n.º 1
0
 public async Task SaveForm(TextEntity entity)
 {
     if (entity.Id.IsNullOrZero())
     {
         entity.Create();
         await this.BaseRepository().Insert(entity);
     }
     else
     {
         await this.BaseRepository().Update(entity);
     }
 }
Ejemplo n.º 2
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var view = doc.Views.ActiveView;

            if (null == view)
            {
                return(Result.Failure);
            }

            var plane = view.ActiveViewport.ConstructionPlane();

            var dimstyle = doc.DimStyles.FindName("TestDimStyle");

            if (null == dimstyle)
            {
                dimstyle = new DimensionStyle
                {
                    TextHeight = 2,
                    TextHorizontalAlignment     = TextHorizontalAlignment.Center,
                    LeaderTextVerticalAlignment = TextVerticalAlignment.Bottom,
                    Name           = "TestDimStyle",
                    DimensionScale = 1,
                    Font           = new Rhino.DocObjects.Font("Book Antiqua")
                };

                var dimstyle_index = doc.DimStyles.Add(dimstyle, false);
                if (dimstyle_index >= 0 && dimstyle_index < doc.DimStyles.Count)
                {
                    dimstyle = doc.DimStyles[dimstyle_index];
                }
                else
                {
                    return(Result.Failure);
                }
            }

            var text_entity = TextEntity.Create("Hello Rhino!", plane, dimstyle, false, 0, 0.0);

            text_entity.GetBoundingBox(plane, out var box);
            var corners = box.GetCorners();

            var points = new Point3d[] { corners[0], corners[1], corners[2], corners[3], corners[0] };

            doc.Objects.AddPolyline(points);

            text_entity.IsValidWithLog(out var log);
            doc.Objects.AddText(text_entity);

            doc.Views.Redraw();

            return(Result.Success);
        }
Ejemplo 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);
        }