找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 627|回复: 2

[求助] 关于填充图案的解析

[复制链接]

已领礼包: 19个

财富等级: 恭喜发财

发表于 2017-1-19 10:03:58 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×

大家好, 想实现如下图的功能:

114758zm22mcxx32fmxqgx.png.thumb.jpg.png
将目前版本的CAD中支持的填充图案,在.NET 的FORM程序加载出来,不知道CAD有没有类似直接读取PAT文件内容后生成Image格式的方法?
如果没有需要自己读取格式后生成吗?

谢谢大家;
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 1304个

财富等级: 财源广进

发表于 2017-1-19 10:06:48 | 显示全部楼层
我只是路过打酱油的
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 13个

财富等级: 恭喜发财

发表于 2017-1-20 00:34:33 | 显示全部楼层

.下面是.net通过DrawableOverrule实现填充的代码,你可以看看是否有帮助


If you need an entity to appear hatched temporarily, drawable overrule can be used for this purpose. Drawing the hatch pattern from an WorldDraw / ViewportDraw can be simple or a little complex depending on the pattern that you want to use. To let the hatch pattern correctly fill the boundary, a clip boundary can be created in your overrule. This simplifies the overrule implementation as the pattern can be created to cover the entity while the clip boundary takes care of clipping it to the actual entity bounds.

Here are two screenshots before and after clipping


0.jpg
1.jpg

Here is a sample code to hatch a circle with the cross pattern using DrawableOverrule



public  class  HatchedCircleOverrule  
        : DrawableOverrule
{
        public  override  bool  IsApplicable(RXObject subject)
        {
                Circle circle = subject as  Circle;

                if  (circle.Database == null )
                        return  false ;

                return  true ;
        }

        public  override  void  ViewportDraw
                (Drawable drawable, ViewportDraw vd)
        {
                base .ViewportDraw(drawable, vd);

                Circle circle = (Circle)drawable;
                Point3d cenPt = circle.Center;

                ClipBoundary cb = new  ClipBoundary();
                cb.DrawBoundary = false ;
                FrontAndBackClipping clipping 
                        = vd.Viewport.FrontAndBackClipping;
                cb.ClippingBack = clipping.ClipBack;
                cb.ClippingFront = clipping.ClipFront;
                cb.NormalVector = vd.Viewport.ViewDirection;
                cb.BackClipZ = clipping.Back;
                cb.FrontClipZ = clipping.Front;

                Point2dCollection clipPts 
                        = new  Point2dCollection();

                double  paramIncr = 
                        (circle.EndParam - circle.StartParam) / 100;
                double  param = circle.StartParam;
                Plane pln = new  Plane(cenPt, circle.Normal);
                for  (int  cnt = 0; cnt < 100; cnt++)
                {
                        clipPts.Add(
                                circle.GetPointAtParameter(param).Convert2d(pln));
                        param += paramIncr;
                }
                clipPts.Add(
                        circle.GetPointAtParameter(circle.EndParam).Convert2d(pln));
                cb.SetAptPoints(clipPts);
                vd.Geometry.PushClipBoundary(cb);

                vd.SubEntityTraits.TrueColor 
                        = new  EntityColor(0, 255, 0);

                Point3dCollection vertices 
                        = new  Point3dCollection();

                int  divs = 8;
                double  delX = circle.Diameter / divs;
                double  delY = circle.Diameter / divs;

                for  (int  row = 0; row <= divs; row++)
                {
                        Point3d currPt = 
                                cenPt 
                                - Vector3d.XAxis * circle.Radius 
                                - Vector3d.YAxis * circle.Radius 
                                + Vector3d.YAxis * row * delY;

                        for  (int  col = 0; col <= divs; col++)
                        {
                                vertices.Clear();
                                vertices.Add(
                                        currPt + Vector3d.XAxis * delX * 0.25);
                                vertices.Add(
                                        currPt - Vector3d.XAxis * delX * 0.25);
                                vd.Geometry.Polyline(
                                        vertices, Vector3d.ZAxis, new  IntPtr (-1));

                                vertices.Clear();
                                vertices.Add(
                                        currPt + Vector3d.YAxis * delY * 0.25);
                                vertices.Add(
                                        currPt - Vector3d.YAxis * delY * 0.25);
                                vd.Geometry.Polyline(
                                        vertices, Vector3d.ZAxis, new  IntPtr (-1));

                                currPt = currPt + Vector3d.XAxis * delX;
                        }
                }

                vd.Geometry.PopClipBoundary();
        }

        public  override  bool  WorldDraw
                (Drawable drawable, WorldDraw wd)
        {
                base .WorldDraw(drawable, wd);

                // call viewportdraw 
                return  false ;
        }
}

public  class  Commands  : IExtensionApplication
{
        private  static  HatchedCircleOverrule  _hco;

        void  IExtensionApplication.Initialize() { }

        void  IExtensionApplication.Terminate()
        {
                if  (_hco != null )
                {
                        Overrule.RemoveOverrule
                                (RXClass.GetClass(typeof (Circle)), _hco);
                        _hco.Dispose();
                        _hco = null ;
                }
        }

        [CommandMethod("StartOR" )]
        public  void  StartORMethod()
        {
                Document doc 
                        = Application .DocumentManager.MdiActiveDocument;
                if  (_hco == null )
                {
                        _hco = new  HatchedCircleOverrule ();
                        _hco.SetCustomFilter();
                        Overrule.AddOverrule
                                (RXClass.GetClass(typeof (Circle)), 
                                _hco, true );
                        Overrule.Overruling = true ;
                }
                doc.Editor.WriteMessage("\nOverruling started !" );
                doc.Editor.Regen();
        }

        [CommandMethod("StopOR" )]
        public  void  StopORMethod()
        {
                Document doc 
                        = Application .DocumentManager.MdiActiveDocument;

                if  (_hco != null )
                {
                        Overrule.RemoveOverrule(
                                RXClass.GetClass(typeof (Circle)), _hco);
                        Overrule.Overruling = false ;
                        _hco.Dispose();
                        _hco = null ;
                }
                doc.Editor.WriteMessage("\nOverruling stopped !" );
                doc.Editor.Regen();
        }
}

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-9-24 18:26 , Processed in 0.404430 second(s), 34 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表