Ruby程序架构
本帖最后由 tzbm123456 于 2021-10-7 01:51 编辑module Tzbm_CadDraw
module PdTextLineCreate
class Main < Tzbm_Common::BaseMain_01KJ
attr_accessor :Interface, :shape;
attr_accessor :m_Point1, :m_Point2, :m_Point3, :m_TextPoint;
def initialize()
#<创建界面位置和大小>
@dialog_title="01建筑 · 建筑单体:创建窗";
super(@dialog_title);
#以下参数不改变
#@scrollable=true;
#@pref_key="";
#以下参数主要本程序控制
@width=368;
@height=460;
set_size @width, @height
#以下参数主要由BaseMain_01KJ控制
#@left=72;
#@top=145;
#set_position(@left,@top);
#以下参数不改变
#@resizable=true;
#</创建界面位置和大小>
#以下为新增内容......
#path="E:/A1_IT/12212/TZBM_VER3/00_01工具集_V3/002_绘制/001DrawLine/drawLine.html"
$plan01siteurl_ = "E:/A1_IT/_01KJ/_01BIM/"
path = $plan01siteurl_+ "html/CadDraw/_003Text/_003021PdTextCreate.html";
set_url path;
show;
#回调函数
add_action_callback("init") do |dlg, params|
initValue();
end
add_action_callback("SetValues") do |dlg, params|
strArr = params.split("&");
p strArr;
@interface.m_Material=strArr;
@interface.m_Layer=strArr;
@interface.m_Depth=strArr.to_f.mm;
@interface.m_Text=strArr;
@interface.m_TextStyle=strArr;
@interface.m_NumeratorText=strArr;
@interface.m_DenominatorText=strArr;
@interface.m_TextHeight=strArr.to_f.mm;
@interface.m_LineWidth=strArr.to_f.mm;
@interface.m_OriginCategory=strArr.to_i;
@interface.m_OriginType=strArr.to_i;
@interface.m_OriginWidth=strArr.to_f.mm;
#更新全局变量
@interface.setGobalParam();
end
set_on_close do
Sketchup.active_model.select_tool nil
end
end
def initValue()
@interface = Interface.new self;
@shape = Shape.new self;
end
def deactivate view
super(view);
#以下为新增内容......
end
def onCancel(flag, view)
super(flag, view);
#以下为新增内容......
end
def reset(view)
super(view);
#以下为新增内容......
end
def onMouseMove(flags, x, y, view)
super(flags, x, y, view);
#以下为新增内容......
tmpStr=@pt2.x.to_i.to_s+","+@pt2.y.to_i.to_s+","+@pt2.z.to_i.to_s
execute_script "$('#spCoord').val('#{@pt2}')";
end
def draw(view)
super(view);
#以下为新增内容......
end
def onLButtonDown(flags, x, y, view)
super(flags, x, y, view);
#以下为新增内容......
#setHtmlValue();
end
def onRButtonUp(flags,x,y,view)
super(flags, x, y, view);
#以下为新增内容......
@shape.createEntity();
self.reset(view);
end
def onKeyDown(key, repeat, flags, view)
super(key, repeat, flags, view);
#以下为新增内容......
#setHtmlValue();
#Tab键
if (key==9)
#puts("key=<"+key.to_s+">");
reset(view)
elsif key==192
@shape.createEntity();
self.reset(view);
end
end
def onUserText(text, view)
super(text, view);
#以下为新增内容......
#setHtmlValue();
end
end
class Interface
attr_accessor :main;
attr_accessor :m_Material,:m_Layer,:m_Depth;
attr_accessor :m_Text,:m_TextStyle,:m_NumeratorText,:m_DenominatorText,:m_TextHeight;
attr_accessor :m_LineWidth,:m_OriginCategory,:m_OriginType,:m_OriginWidth;
def initialize(main)
@main=main;
@model=Sketchup.active_model;
init();
setHtml();
setHtmlValue();
end
def init()
if $mPTC_Material.class!=NilClass
@m_Material=$mPTC_Material;
else
@m_Material="Material0";
$mPTC_Material=@m_Material
end
if $mPTC_Layer.class!=NilClass
@m_Layer=$mPTC_Layer;
else
@m_Layer="Layer0";
$mPTC_Layer=@m_Layer
end
if $mPTC_Depth.class!=NilClass
@m_Depth=$mPTC_Depth;
else
@m_Depth=0.mm;
$mPTC_Depth=@m_Depth
end
if $mPTC_Text.class!=NilClass
@m_Text=$mPTC_Text;
else
@m_Text="详见施工图";
$mPTC_Text=@m_Text
end
if $mPTC_TextStyle.class!=NilClass
@m_TextStyle=$mPTC_TextStyle;
else
@m_TextStyle="Standard";
$mPTC_TextStyle=@m_TextStyle
end
if $mPTC_NumeratorText.class!=NilClass
@m_NumeratorText=$mPTC_NumeratorText;
else
@m_NumeratorText="2A";
$mPTC_NumeratorText=@m_NumeratorText
end
if $mPTC_DenominatorText.class!=NilClass
@m_DenominatorText=$mPTC_DenominatorText;
else
@m_DenominatorText="6";
$mPTC_DenominatorText=@m_DenominatorText
end
if $mPTC_TextHeight.class!=NilClass
@m_TextHeight=$mPTC_TextHeight;
else
@m_TextHeight=300.mm;
$mPTC_TextHeight=@m_TextHeight
end
if $mPTC_LineWidth.class!=NilClass
@m_LineWidth=$mPTC_LineWidth;
else
@m_LineWidth=30.mm;
$mPTC_LineWidth=@m_LineWidth
end
end
def setHtml()
#1、设置材质下拉列表
tmpMaterials=@model.materials
tmpMatArr=tmpMaterials.to_a;
tmpMatStrArr=Array.new();
tmpMatArr.each{|mMat|
tmpMatStrArr.push(mMat.name);
}
styleHtml="";
tmpMatStrArr.each{|strName|
styleHtml += "<option value='#{strName}'>#{strName}</option>"
}
@main.execute_script "$('#Material').html(\"#{styleHtml}\")" #执行字符串
#2、设置图层下拉列表
tmpLayers=@model.layers
tmpLayerArr=tmpLayers.to_a;
tmpLayerStrArr=Array.new();
tmpLayerArr.each{|mLayer|
tmpLayerStrArr.push(mLayer.name);
}
styleHtml="";
tmpLayerStrArr.each{|strName|
styleHtml += "<option value='#{strName}'>#{strName}</option>"
}
@main.execute_script "$('#Layer').html(\"#{styleHtml}\")" #执行字符串
#3、设置文字样式下拉列表
#打开字形名称文件
mTextFontFileStr = Sketchup.find_support_file "TextFont.01KJ", "Plugins/01BIM/style"
mTextFontFile = open(mTextFontFileStr,"r");
mStrArr=mTextFontFile.readlines;
mTextFontFile.close;
#添加新增字形名称下拉列表
styleHtml="";
mStrArr.each{|mStr|
tmpArr=mStr.chomp.split(",");
tmpStr1=tmpArr;
if (tmpStr1!="")
styleHtml += "<option value='#{tmpStr1}'>#{tmpStr1}</option>"
end
}
@main.execute_script "$('#TextStyle').html(\"#{styleHtml}\")" #执行字符串
end
def setHtmlValue()
###传递$plan01siteurl_ad变量值至Html界面
@main.execute_script "initFrame('#{$plan01siteurl_ad}')";
@main.execute_script "$('#Material').val('#{@m_Material}')";
@main.execute_script "$('#Layer').val('#{@m_Layer}')";
@main.execute_script "$('#Depth').val('#{@m_Depth}')";
end
#设置全局参数变量
def setGobalParam()
$mPTC_Material=@m_Material
$mPTC_Layer=@m_Layer
$mPTC_Depth=@m_Depth
$mPTC_Text=@m_Text
$mPTC_TextStyle=@m_TextStyle
$mPTC_NumeratorText=@m_NumeratorText
$mPTC_DenominatorText=@m_DenominatorText
end
end
本帖最后由 tzbm123456 于 2021-2-28 20:08 编辑
class Shape
attr_accessor :m_Point1, :m_Point2, :m_Point3, :m_TextPoint;
attr_accessor :m_Material,:m_Layer,:m_Depth;
attr_accessor :m_Text,:m_TextStyle,:m_DenominatorText,:m_m_NumeratorText,:m_TextHeight;
attr_accessor :m_LineWidth,:m_OriginCategory,:m_OriginType,:m_OriginWidth;
def initialize(main)
@main = main;
end
def setValueFromMain()
@m_Point1=@main.m_Point1;
@m_Point2=@main.m_Point2;
@m_Point3=@main.m_Point3;
@m_TextPoint=@main.m_TextPoint;
@m_Material=@main.interface.m_Material;
@m_Layer=@main.interface.m_Layer;
@m_Depth=@main.interface.m_Depth;
@m_Text=@main.interface.m_Text;
@m_TextStyle=@main.interface.m_TextStyle;
@m_NumeratorText=@main.interface.m_NumeratorText;
@m_DenominatorText=@main.interface.m_DenominatorText;
@m_TextHeight=@main.interface.m_TextHeight;
@m_LineWidth=@main.interface.m_LineWidth;
@m_OriginCategory=@main.interface.m_OriginCategory;
@m_OriginType=@main.interface.m_OriginType;
@m_OriginWidth=@main.interface.m_OriginWidth;
end
##功能函数绘制直线
def createEntity()
#传值
setValueFromMain();
#绘制
end
end
end
end
Sketchup.active_model.select_tool Tzbm_CadDraw::PdTextLineCreate::Main.new;
p 20210228
页:
[1]