您的位置:首页 > 其它

[Map 3D开发实战系列] Map Resource Explorer 之三-- 添加AutoCAD风格的Palette界面

2011-01-30 17:41 465 查看
目录

[Map3D开发实战系列]MapResourceExplorer背景介绍--Kickoff

[Map3D开发实战系列]MapResourceExplorer之二--运行和调试

在前面的文章中介绍了如何在VisualStudio中建立项目开发Map3D的应用程序,并且编写了一个非常简单的命令行命令。在Map3D中通过netload命令加载我们的自定义程序集后,输入自定义命令即可调用相关的自定义函数还实现我们的功能。通过这种形式,我们可以写很多自定义命令来开发更多的自定义的功能来扩展Map3D。但实际项目过程中,不光会用的自定义的命令,还经常会有界面,比如还可能会有一个对话框等等可视化的元素。这一节主要讲一下如果在AutoCADMap3D开发中来添加用户界面。

前文我们说过,Map3D是基于AutoCAD基础之上的产品,AutoCAD.NETAPI提供的丰富的API来创建与AutoCAD风格一致的界面。在Map3D中创建界面,主要是应用AutoCAD.NETAPI来完成。.Netframework3.0的发布,让WPF技术也如火如荼的发展起来。AutoCAD的Ribbon界面也是采用的WPF技术。为了使得我们的程序界面也和AutoCAD界面风格一致,我们也采用WPF技术来做界面。

在AutoCAD中添加一个WPF的Palette其实还是挺简单的。首先在我们的工程中添加一个基于WPF的用户控件。





你可以在这个WPF用户控件中来使用XAML来定义你的界面,也可以用MicrosoftBlend等工具来设计你的用户界面,这不是我们讨论的重点,如果你对WPF界面设计感兴趣,可以参考MSDN或者其他资料。现在我们关心的是有了这样的WPF界面之后,如何在AutoCAD中调用。

在AutoCAD中,我们可以利用AutoCAD.NETAPI来创建一个Palette,并把这个WPF用户控件加入到Palette中。请看下面的代码:

//(C)Copyright2002-2009byAutodesk,Inc.
//
//Permissiontouse,copy,modify,anddistributethissoftwarein
//objectcodeformforanypurposeandwithoutfeeisherebygranted,
//providedthattheabovecopyrightnoticeappearsinallcopiesand
//thatboththatcopyrightnoticeandthelimitedwarrantyand
//restrictedrightsnoticebelowappearinallsupporting
//documentation.
//
//AUTODESKPROVIDESTHISPROGRAM"ASIS"ANDWITHALLFAULTS.
//AUTODESKSPECIFICALLYDISCLAIMSANYIMPLIEDWARRANTYOF
//MERCHANTABILITYORFITNESSFORAPARTICULARUSE.AUTODESK,INC.
//DOESNOTWARRANTTHATTHEOPERATIONOFTHEPROGRAMWILLBE
//UNINTERRUPTEDORERRORFREE.
//
//Use,duplication,ordisclosurebytheU.S.Governmentissubjectto
//restrictionssetforthinFAR52.227-19(CommercialComputer
//Software-RestrictedRights)andDFAR252.227-7013(c)(1)(ii)
//(RightsinTechnicalDataandComputerSoftware),asapplicable.
//

usingSystem;
usingAutodesk.AutoCAD.Runtime;
usingAutodesk.AutoCAD.ApplicationServices;
usingAutodesk.AutoCAD.DatabaseServices;
usingAutodesk.AutoCAD.Geometry;
usingAutodesk.AutoCAD.EditorInput;
usingAutodesk.AutoCAD.Windows;

namespaceMyPaletteWebcast
{

publicclassMyPlugin:IExtensionApplication
{

publicvoidInitialize()
{
//Initializeyourplug-inapplicationhere
}

publicvoidTerminate()
{
//Doplug-inapplicationcleanuphere
}

//createareferencetothemodelesspalettesetwindow
staticPaletteSetps=null;
staticUserControl1myUserControl=null;

//DefineCommand"MyCommand"
[CommandMethod("MyCommand")]
staticpublicvoidMyCommand()//Thismethodcanhaveanyname
{
//checktoseeifthepsiscreated
if(ps==null)
{
//createaninstanceoftheps
ps=newPaletteSet("MyCommand");
myUserControl=newUserControl1();
ps.AddVisual("MyPalette",myUserControl);
}
//showthepaletteset
ps.Visible=true;
}
}

}
启动AutoCAD,Map3D或者Civil3D,通过netload命令加载自定义程序集,然后输入自定义命令MyCommand即可调出AutoCAD风格的自定义的Palette。

.csharpcode,.csharpcodepre
{
font-size:small;
color:black;
font-family:consolas,"CourierNew",courier,monospace;
background-color:#ffffff;
/*white-space:pre;*/
}
.csharpcodepre{margin:0em;}
.csharpcode.rem{color:#008000;}
.csharpcode.kwrd{color:#0000ff;}
.csharpcode.str{color:#006080;}
.csharpcode.op{color:#0000c0;}
.csharpcode.preproc{color:#cc6633;}
.csharpcode.asp{background-color:#ffff00;}
.csharpcode.html{color:#800000;}
.csharpcode.attr{color:#ff0000;}
.csharpcode.alt
{
background-color:#f4f4f4;
width:100%;
margin:0em;
}
.csharpcode.lnum{color:#606060;}





通过这样简单的代码,我们就可以定义一个自定义命令MyCommand,在这个命令执行时,创建一个Palette加载WPF用户控件,并显示出来。是不是很简单?你也可以试试看。

好了,今天先到这里,以后我们将继续记录Map3D开发实战的进展情况。

Cheers,

Daniel
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐