tzbm123456 发表于 2021-10-7 11:19:48

选择基础类:SelectClass

本帖最后由 tzbm123456 于 2021-10-7 11:20 编辑

选择基础类:SelectClass2021年10月07日

tzbm123456 发表于 2021-10-7 11:21:57

module Tzbm_Common
class SelectClass_01KJ
        Verson="3.0";
        DevelopCompany="重庆天筑比盟科技公司"
        Developer="李总";
        DevelopTime="2019.06.30";
        DevelopAddress="凤凰湾";       
        ###################################################################################################################################
        def self.getVerson
                return Verson;
        end


        def self.getDevelopCompany
                return DevelopCompany;
        end


        def self.getDeveloper
                return Developer;
        end


        def self.getDevelopTime
                return DevelopTime;
        end


        def self.getDevelopAddress
                return DevelopAddress;
        end
       
        ###################################################################################################################################
        attr_accessor :m_View,:m_Point1,:m_Point2,:m_Point3,:m_Point4,:m_PointList,:m_CenterPoint,:m_Radius,:m_Key;       
        attr_accessor :m_PixelWinSize;
        ###################################################################################################################################       
       
        def initialize()
                ### 长方形四点
                @m_Point1=Geom::Point3d.new(0,0,0);
                @m_Point2=Geom::Point3d.new(1.m,0,0);
                @m_Point3=Geom::Point3d.new(1.m,1.m,0);
                @m_Point4=Geom::Point3d.new(0,1.m,0);
               
                @m_PointList=[@m_Point1,@m_Point2,@m_Point3,@m_Point4];
                ### 园形中心点
                @m_CenterPoint=Geom::Point3d.new(0,0,0);
                ### 园形半径
                @m_Radius=0.5.m;
                @m_Key=0;
                ### 光标尺寸
                m_SV=Tzbm_Common::SystemVariableClass_01KJ.new();
                m_SV.m_Key="PixelWinSize";
                tmpSize=m_SV.getValue();
                if tmpSize.class==NilClass
                        @m_PixelWinSize=5;
                else
                        @m_PixelWinSize=tmpSize.to_i;
                end
                ### 当前激活视图
                @m_View=Sketchup.active_model.active_view;
        end
        #Function 1,已知某点空间坐标,返回穿越该点空间坐标对应的屏幕坐标点的所有实体,@m_PixelWinSize为光标大小参数
        def selectPoint3d(mPoint)
                if @m_PixelWinSize==0
                        tmpPickHelper=@m_View.pick_helper;
                        tmpScreenPt=@m_View.screen_coords(mPoint);
                        tmpPH=tmpPickHelper.do_pick(tmpScreenPt.x,tmpScreenPt.y);
                        tmpEnts=tmpPickHelper.all_picked;
                else
                        tmpPickHelper=@m_View.pick_helper;
                        tmpScreenPt=@m_View.screen_coords(mPoint);
                        tmpPt1=Geom::Point3d.new(tmpScreenPt.x-@m_PixelWinSize,tmpScreenPt.y-@m_PixelWinSize,0);
                        tmpPt2=Geom::Point3d.new(tmpPt1.x+@m_PixelWinSize*2,tmpPt1.y+@m_PixelWinSize*2,0);
                        num_picked = tmpPickHelper.window_pick(tmpPt1, tmpPt2, Sketchup::PickHelper::PICK_CROSSING);
                        tmpEnts=tmpPickHelper.all_picked;
                end
                tmpEnts.uniq!()
                #Sketchup.active_model.selection.add tmpEnts
                #UI.messagebox tmpEnts.size
                #UI.messagebox tmpEnts
                #UI.messagebox tmpEnts.description
               
                #UI.messagebox tmpPickHelper.count.times ;
                ###保留Edge、Face、Group、ComponentInstance
                tmpArr=Array.new();
                tmpEnts.each{|ent|
                        if ent.class==Sketchup::Edge
                                tmpArr.push(ent);
                        elsif ent.class==Sketchup::Face
                                tmpArr.push(ent);
                        elsif ent.class==Sketchup::Group
                                tmpArr.push(ent);
                        elsif ent.class==Sketchup::ComponentInstance
                                tmpArr.push(ent);
                        elsif ent.class==Sketchup::ConstructionLine
                                tmpArr.push(ent);
                        end
                }
                return tmpArr;
        end
        #Function 2,返回穿越@m_Point1点对应的屏幕坐标点的所有实体
        def selectPoint()
                tmpPoint=@m_Point1;               
                tmpArr=selectPoint3d(tmpPoint);
                return tmpArr;
        end
        #Function 3,已知两点空间坐标,返回穿越两点空间坐标对应的屏幕坐标点连线的所有实体
        def selectLineSegment(mPoint1,mPoint2)
                tmpPickHelper=@m_View.pick_helper;
                tmpScreenPt1=@m_View.screen_coords(mPoint1);
                tmpScreenPt2=@m_View.screen_coords(mPoint2);


                numX=(tmpScreenPt2.x-tmpScreenPt1.x).to_inch.ceil.abs;
                numY=(tmpScreenPt2.y-tmpScreenPt1.y).to_inch.ceil.abs;


                num=nil;
                if numX>numY
                        num=numX;
                else
                        num=numY;
                end
                tmpDeltaX=(tmpScreenPt2.x-tmpScreenPt1.x)/num;
                tmpDeltaY=(tmpScreenPt2.y-tmpScreenPt1.y)/num;
                tmpEnts=[];
                for i in 0...num
                        tmpX=tmpScreenPt1.x+tmpDeltaX*i;
                        tmpY=tmpScreenPt1.y+tmpDeltaY*i;
                        tmpPickHelper.do_pick(tmpX,tmpY);
                        arr=tmpPickHelper.all_picked;
                        tmpEnts+=arr
                end
                tmpEnts.uniq!;


                tmpArr=[];
                tmpEnts.each{|ent|
                        if ent.class==Sketchup::Edge or ent.class==Sketchup::Face or \
                                ent.class==Sketchup::Group or ent.class==Sketchup::ComponentInstance
                                        tmpArr.push(ent);
                        end
                }
                return tmpArr;
        end
        #Function 4,返回穿越@m_Point1和@m_Point2两点对应的屏幕坐标点连线的所有实体
        def selectLine()
                tmpPt1=@m_Point1;
                tmpPt2=@m_Point2;               
                tmpArr=selectLineSegment(tmpPt1,tmpPt2);
                return tmpArr;
        end
        #Function 5,返回穿越@m_PointList点数组对应的屏幕坐标点连线的所有实体
        def selectPolyLine()
                if (@m_PointList.class!=Array)
                        puts("@m_PointList.class=<"+@m_PointList.class.to_s+">,不为Array类型,返回false!");
                        tmpValue=false;
                elsif (@m_PointList.empty?)
                        puts("@m_PointList.为空数组,返回false!");
                        tmpValue=false;
                elsif (@m_PointList.size==1)
                        tmpPoint=@m_PointList;
                        tmpValue=selectPoint3d(tmpPoint);
                else
                        tmpValue=Array.new();
                        for i in 0...@m_PointList.size-1
                                tmpPt1=@m_PointList;
                                tmpPt2=@m_PointList;
                                tmpArr=selectLineSegment(tmpPt1,tmpPt2);
                                tmpValue+=tmpArr;
                        end
                        tmpValue.uniq!;
                end
                return tmpValue;
        end
        #Function 6,返回穿越或包含于@m_PointList点数组对应的屏幕坐标点连线围合范围内的所有实体
        def selectArea()
               
        end
end
end
p "20190630"

页: [1]
查看完整版本: 选择基础类:SelectClass