|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2021-10-7 11:13:58
|
显示全部楼层
module Tzbm_Common
class BaseMain_01KJ < UI::WebDialog
#attr_accessor :dialog_title, :scrollable, :pref_key, :width, :height, :left, :top, :resizable;
attr_accessor :m_PtArr,:pt1,:pt2,:m_BaseEnt1,:m_BaseEnt2;
=begin
def initialize(dialog_title="XXX",\
scrollable=true,\
pref_key="",\
width=368,\
height=600,\
left=72,\
top=145,\
resizable=true)
super(dialog_title,scrollable,pref_key,width,height,left,top,resizable);
=end
def initialize(dialog_title="XXX",\
scrollable=true,\
pref_key="",\
width=385,\
height=975,\
left=72,\
top=145,\
resizable=true)
super(dialog_title,scrollable,pref_key,width,height,left,top,resizable);
#创建界面
@dialog_title=dialog_title;
@scrollable=scrollable;
@pref_key=pref_key;
@width=width;
@height=height;
@left=left;
@top=top;
@resizable=true;
@mDrawBase=Tzbm_Common: rawBase_01KJ.new;
#人机交互基本参数
@coordsLength=1000000.m;#坐标轴长度
@ip1= Sketchup::InputPoint.new
@ip2= Sketchup::InputPoint.new
@pt1=Geom: oint3d.new(0,0,0);
@pt2=Geom: oint3d.new(0,0,0);
@state=0;
@m_PtArr=Array.new();
@mValueStr="";#SB_VCB_VALUE对应的文字
@mAxisOn=0;#0:开;1:关
@mSystemObj=Tzbm_Common::SystemVariableClass_01KJ.new();
@mSystemObj.m_Key=" ixelWinSize";
tmpSize=@mSystemObj.getValue();
if tmpSize.class==NilClass
@m_PixelWinSize=5;
else
@m_PixelWinSize=tmpSize.to_i;
end
@m_PixelWinStr="第1点:";
@m_PtNum=1;
@mOsnap=0;
#关闭窗口
set_on_close do
Sketchup.active_model.select_tool nil;
end
end
def activate
puts 'Your tool has been activated.'
end
def deactivate(view)
close;
$Plan01Loader.exitTool;
view.invalidate;
end
def onCancel(flags, view)
reset(view)
end
def reset(view)
@state=0;
@ip1.clear;
@ip2.clear;
@pt1=Geom: oint3d.new;
@pt2=Geom: oint3d.new;
if( view )
view.tooltip = nil;
view.invalidate;
end
@m_PtArr.clear;
@mValueStr="";
@mAxisOn=0;
@m_PixelWinStr="第1点:";
@m_PtNum=1;
@mOsnap=0;
end
def onMouseMove(flags, x, y, view)
#puts("@ip1.valid?=<"+@ip1.valid?.to_s+">");
if (@state==0)
@ip1.pick view,x,y; #将视口坐标(view,x,y)转换为InputPoint类变量@ip1
@pt1=@ip1.position;
view.tooltip=@ip1.tooltip;
view.invalidate;
else
#自动关系开启
if @mOsnap==0
@ip2.pick view,x,y,@ip1; #将视口坐标(view,x,y)转换为InputPoint类变量@ip2
#自动关系关闭
else
@ip2.pick view,x,y;
end
@pt2=@ip2.position;
#自动捕捉开启
if @mOsnap==0
view.tooltip=@ip2.tooltip;
end
view.invalidate;
end
end
def draw(view)
if (@m_PtArr.class==Array and !@m_PtArr.empty?)
@ip1 = Sketchup::InputPoint.new(@m_PtArr.last);
#@pt1 = @m_PtArr.last;
end
if (@state==0)
if (@ip1.valid? )
@ip1.draw(view);
@pt1=@ip1.position;
self.drawAxis(@pt1,view) if (@mAxisOn==0);
self.drawPixelWin(@pt1, view);
end
else
if (@ip2.valid? )
#自动捕捉开启
if @mOsnap==0
@ip2.draw(view);
end
@pt2=@ip2.position;
self.drawAxis(@pt2,view) if (@mAxisOn==0);
self.drawPixelWin(@pt2, view);
if @m_PtArr.class!=NilClass
self.drawViewLine(view, @pt2);
end
tmpPt=@m_PtArr.last;
if tmpPt.class==Geom: oint3d
@mValueStr=@pt2.distance(tmpPt).to_s;
Sketchup.set_status_text @mValueStr, SB_VCB_VALUE
end
end
end
##更新光标尺寸
@mSystemObj.m_Key=" ixelWinSize";
tmpPixelWinSize=@mSystemObj.getValue().to_i;
if tmpPixelWinSize.class!=NilClass
@m_PixelWinSize=tmpPixelWinSize;
end
end
def onLButtonDown(flags, x, y, view)
if (@state==0)
@ip1.pick view,x,y;
if (@ip1.valid?)
@pt1=@ip1.position;
tmpPt=@pt1;
#使用像素框功能点选实体
mSelector=Tzbm_Common::SelectClass_01KJ.new();
mSelector.m_Point1=tmpPt;
mSelector.m_PixelWinSize=@m_PixelWinSize;
tmpEntSel=mSelector.selectPoint();
#根据程序需要筛选获得所需的点选实体集
tmpEntArr=Array.new();
tmpEntSel.each{|ent|
if ent.class==Sketchup::Edge
if ent.curve.class==Sketchup::ArcCurve
tmpEntArr.push(ent.curve);
else
tmpEntArr.push(ent);
end
elsif ent.class==Sketchup::Group and \
((ent.class==Sketchup::Group and ent.get_attribute("EntityAttribute","EntityClass")=="Line_01KJ") or \
(ent.class==Sketchup::Group and ent.get_attribute("EntityAttribute","EntityClass")=="Arc_01KJ") or \
(ent.class==Sketchup::Group and ent.get_attribute("EntityAttribute","EntityClass")=="ElevationText_01KJ"))
tmpEntArr.push(ent);
end
}
tmpEntArr.uniq!();
if tmpEntArr.size>0
#计算特征点
tmpOsMode=@mSystemObj.getKeyValue("OsMode").to_i;
tmpPtNew=@mDrawBase.mMath.getOsModePoint(tmpEntArr,tmpPt,tmpOsMode);
@m_BaseEnt1=tmpEntArr[0];
@pt1=tmpPtNew;
end
@m_PtArr.push(@pt1.clone);
@state=1;
@m_PtNum+=1;
@m_PixelWinStr="第"+@m_PtNum.to_s+"点:";
end
else
#@ip2.pick view,x,y,@ip1;
#自动关系开启
if @mOsnap==0
@ip2.pick view,x,y,@ip1; #将视口坐标(view,x,y)转换为InputPoint类变量@ip2
#自动关系关闭
else
@ip2.pick view,x,y;
end
if (@ip2.valid?)
@pt2=@ip2.position;
tmpPt=@pt2;
#使用像素框功能点选实体
mSelector=Tzbm_Common::SelectClass_01KJ.new();
mSelector.m_Point1=tmpPt;
mSelector.m_PixelWinSize=@m_PixelWinSize;
tmpEntSel=mSelector.selectPoint();
#根据程序需要筛选获得所需的点选实体集
tmpEntArr=Array.new();
tmpEntSel.each{|ent|
if ent.class==Sketchup::Edge
if ent.curve.class==Sketchup::ArcCurve
tmpEntArr.push(ent.curve);
else
tmpEntArr.push(ent);
end
elsif ent.class==Sketchup::Group and \
((ent.class==Sketchup::Group and ent.get_attribute("EntityAttribute","EntityClass")=="Line_01KJ") or \
(ent.class==Sketchup::Group and ent.get_attribute("EntityAttribute","EntityClass")=="Arc_01KJ") or \
(ent.class==Sketchup::Group and ent.get_attribute("EntityAttribute","EntityClass")=="ElevationText_01KJ"))
tmpEntArr.push(ent);
end
}
tmpEntArr.uniq!();
if tmpEntArr.size>0
#计算特征点
tmpOsMode=@mSystemObj.getKeyValue("OsMode").to_i;
tmpPtNew=@mDrawBase.mMath.getOsModePoint(tmpEntArr,tmpPt,tmpOsMode);
@m_BaseEnt2=tmpEntArr[0];
@pt2=tmpPtNew;
end
@m_PtArr.push(@pt2.clone);
@m_PixelWinStr="第1点:";
@m_PtNum+=1;
@m_PixelWinStr="第"+@m_PtNum.to_s+"点:";
#@ip1.copy! @ip2;
#@pt1=@pt2;
end
end
end
|
|