Windchill10x建模.docx
- 文档编号:26217189
- 上传时间:2023-06-17
- 格式:DOCX
- 页数:9
- 大小:17.62KB
Windchill10x建模.docx
《Windchill10x建模.docx》由会员分享,可在线阅读,更多相关《Windchill10x建模.docx(9页珍藏版)》请在冰豆网上搜索。
Windchill10x建模
Windchill10.x建模
WIndchill10.x建模
一、在Windchill中建一个简单的模型
第一步,编辑java文件
创建com.acme.example.SimpleExample和com.acme.example.SimpleExampleLink文件
packagecom.acme.example;
importwt.fc.InvalidAttributeException;
importwt.fc.WTObject;
importwt.inf.container.WTContained;
importwt.util.WTException;
importwt.util.WTPropertyVetoException;
importcom.ptc.windchill.annotations.metadata.*;
@GenAsPersistable(
superClass=WTObject.class,
interfaces={WTContained.class},
properties={@GeneratedProperty(
name="name",
type=String.class,
constraints=@PropertyConstraints(required=true))})
publicclassSimpleExampleextends_SimpleExample{
staticfinallongserialVersionUID=1;
publicstaticSimpleExamplenewSimpleExample()throwsWTException{
finalSimpleExampleinstance=newSimpleExample();
instance.initialize();
returninstance;
}
@Override
publicvoidcheckAttributes()throwsInvalidAttributeException{
super.checkAttributes();
try{
nameValidate(name);
}catch(WTPropertyVetoExceptionwtpve){
thrownewInvalidAttributeException(wtpve);
}
}
}
packagecom.acme.example;
importwt.fc.ObjectToObjectLink;
importwt.util.WTException;
importcom.ptc.windchill.annotations.metadata.*;
@GenAsBinaryLink(
superClass=ObjectToObjectLink.class,
roleA=@GeneratedRole(name="parent",type=SimpleExample.class),
roleB=@GeneratedRole(name="child",type=SimpleExample.class))
publicclassSimpleExampleLinkextends_SimpleExampleLink{
staticfinallongserialVersionUID=1;
publicstaticSimpleExampleLinknewSimpleExampleLink(
finalSimpleExampleparent,finalSimpleExamplechild)
throwsWTException{
finalSimpleExampleLinkinstance=newSimpleExampleLink();
instance.initialize(parent,child);
returninstance;
}
}
第二步,编译模型的java文件
ant-fbin/tools.xmlclass-Dclass.includes=com/acme/example/*
命令执行之后,会在
第三步,生成sql文件
ant-fbin/tools.xmlsql_script-Dgen.input=com.acme.example.*
命令执行之后,在
第四步,导入sql文件
Cddb/sql3
Sqlpluswind/wind@WIND
@Make_pkg_sql3_Table.sql
@Make_pkg_sql3_Index.sql
第五步,Start/restarttheMethodServer
二、GenAs介绍
1、GenAsPersistable和GenAsBinaryLink提供三种机制指定数据库中的列:
1.properties(一个GeneratedPropertys的数组)表示strings,
numbers,booleans等等.
2.foreignKeys(一个GeneratedForeignKeys的数组)参考其他持久化对象(andarestoredasaclassname/keypair)
3.roleA/roleB(仅有GenAsBinaryLink中使用)一种特殊形式的外键,用来表述关联关系
2、常用注释介绍:
@GenAsPersistable创建持久化对象,并将该类映射为一张表表
@GenAsBinaryLink创建两个持久对象关联关系的对象,并将这种关联关系映射为一张表
@GeneratedRole和@GenAsBinaryLink一起使用用来描述link关系
@GeneratedProperty生成属性
@PropertyConstraints指定约束,(required=true)则需要进行验证,需要重写方法checkAttributes()
@GeneratedForeignKey指定外键
@GeneratedForeignKey(name="ContainerLink",
foreignKeyRole=@ForeignKeyRole(name="container",
type=wt.inf.container.WTContainer.class,
referenceType=wt.inf.container.WTContainerRef.class,
supportedAPI=SupportedAPI.PRIVATE,
constraints=@PropertyConstraints(required=true)),
myRole=@MyRole(name="contents",supportedAPI=SupportedAPI.PRIVATE))
@DerivedProperty控制外键关联对象属性的调用
@DerivedProperty(name="c",derivedFrom="a.b.c")
@DerivedProperty(name="name",derivedFrom="master>name")
三、创建并注册服务(Service)
1、创建Helper类
packagecom.acme.example;
importwt.services.ServiceFactory;
/**
*Helpersarenotinstantiatedandshouldconsistofonlystaticfields/methods
**/
publicfinalclassExampleHelper{
/**UsetheServiceFactorytoacquireaninstanceoftheservice.**/
publicstaticfinalExampleServiceservice=ServiceFactory
.getService(ExampleService.class);
}
2、创建服务接口
packagecom.acme.example;
importwt.method.RemoteInterface;
importwt.util.WTException;
/**RemoteInterfaceannotationisrequiredforallserviceinterfaces**/
@RemoteInterface
publicinterfaceExampleService{
/**AllinterfacemethodsarecallableviaRMIandmustthrowWTException**/
SimpleExamplecreateSimpleExampleByName(finalStringname)
throwsWTException;
}
3、创建标准服务类
packagecom.acme.example;
importwt.fc.PersistenceHelper;
importwt.services.StandardManager;
importwt.util.WTException;
importwt.util.WTPropertyVetoException;
/**servicemustextendStandardManager,implementserviceinterface**/
publicclassStandardExampleServiceextendsStandardManagerimplements
ExampleService{
/**MethodServerrefectivelycallsthisAPIduringstartup**/
publicstaticStandardExampleServicenewStandardExampleService()
throwsWTException{
finalStandardExampleServiceinstance=newStandardExampleService();
instance.initialize();
returninstance;
}
@Override
publicSimpleExamplecreateSimpleExampleByName(finalStringname)
throwsWTException{
finalSimpleExampleexample=SimpleExample.newSimpleExample();
try{
example.setName(name);
}catch(WTPropertyVetoExceptionwtpve){
thrownewWTException(wtpve);
}
return(SimpleExample)PersistenceHelper.manager.store(example);
}
}
4、在site.xconf文件中注册服务
targetFile="codebase/wt.properties"value="com.acme.example.ExampleService/com.acme.example. StandardExampleService"/> 四、本地化显示信息 1、创建exampleModelRB.rbInfo ResourceInfo.class=wt.tools.resource.MetadataResourceInfo #EntryFormat(valuesequaltodefaultvaluearenotincluded) # # # # # # # # # # # #EntryContents SimpleExample.value=Simple SimpleExample.name.value=aka 2、创建exampleResource.java packagecom.acme.example; importwt.util.resource.*; /**ThisexampleblatantlyplagiarizedfromtheJavaDoc.**/ @RBUUID("com.acme.example.exampleResource") publicclassexampleResourceextendsWTListResourceBundle{ @RBEntry("Thisisthelocalizedtextwithasinglesubstitution: \"{0}\".") @RBComment("Anexampleentry.") @RBArgComment0("Anystring...") publicstaticfinalStringEXAMPLE_STRING="0"; } 3、执行如下命令: ant-fbin/tools.xmlbundle-Dbundle.input=com.acme.example.* ant-fbin/tools.xmlclass-Dclass.includes=com/acme/example/exampleResource.java 五、枚举类型 1、创建ComputerType.java文件 packagecom.acme.example; importcom.ptc.windchill.annotations.metadata.*; @GenAsEnumeratedType publicclassComputerTypeextends_ComputerType{ publicstaticfinalComputerTypeDESKTOP=toComputerType("desktop"); publicstaticfinalComputerTypeLAPTOP=toComputerType("laptop"); publicstaticfinalComputerTypeSERVER=toComputerType("server"); } 2、创建ComputerTypeRB.rbInfo文件 RB文件对应的是枚举值,RB文件的命名格式为 ResourceInfo.class=wt.tools.resource.EnumResourceInfo desktop.value=Desktop desktop.order=10 laptop.value=Laptop laptop.order=20 laptop.defaultValue=true server.value=Server server.order=30 3、执行命令 ant-fbin/tools.xmlbundle-Dbundle.input=com.acme.example.* ant-fbin/tools.xmlclass-Dclass.includes=com/acme/example/ComputerType.java 六、Eclipse集成开发 七、部署客制化建模 1.注册模型 associationRegistry.properties,和 descendentRegistry.properties) 2.添加编译的类文件,包括*.class、*.ClassInfo.ser和*.RB.ser 3.更新数据库(包括索引).
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Windchill10x 建模