📄 u_3dfile.pas
字号:
//
// 读取三维图纸结构的单元 基类
// 张河阳 2007-4-20
unit u_3DFile;
interface
uses xmldom, XMLIntf, msxmldom, XMLDoc,SysUtils,Variants;
Type T3DFile=class //基类
private
protected
FXML:IXmlDocument;
ffilename:string;
FOutPath:string;
FRootNode:IXMLNOde;
function ADDXMLNode(ParentNode:IXMLNode; obj: variant):IXMLNode;
function OutputXML: boolean; virtual;
public
constructor Create(FileName:string;OutPath:string); virtual;
destructor Destroy; virtual;
published
end;
//对于UG或PROE图纸,只负现解板XML不用去读结构,
Type T3DXML=class(T3DFile) // 解析XML的基类
private
procedure ReWriteXML(inNode, outNode: IXMLNode);overload;
protected
procedure ReWriteXML;overload;virtual;
function OutputXML:boolean;override;
public
published
end;
implementation
{ T3DFile }
function T3DFile.ADDXMLNode(ParentNode: IXMLNode; obj: variant): IXMLNode;
var
atrNode:IXMLNode;
begin
if Parentnode=nil then result:=FRootNode.AddChild('NODE')
else result:=ParentNode.AddChild('NODE');
atrNode:=self.FXML.CreateNode('FILEPATH',ntAttribute);
atrNode.NodeValue:=obj;
result.AttributeNodes.Add(atrNode);
end;
constructor T3DFile.Create(FileName, OutPath: string);
begin
FXML:=TXMLDocument.Create(nil);
//FXML.DOMVendor:=GetDomVendor('MSXML');
self.ffilename:=FileName;
self.FOutPath:=OutPath;
FXML.Active:=true;
FRootNode:=FXML.AddChild('Model') ;
end;
destructor T3DFile.Destroy;
begin
self.FXML:=nil;
end;
function T3DFile.OutputXML: boolean;
begin
result:=false;
if Fileexists(self.FOutPath) then deletefile(self.FOutPath);
try
self.FXML.SaveToFile(FOutPath);
result:=true;
except
end;
end;
{ T3DXML }
function T3DXML.OutputXML: boolean;
begin
self.ReWriteXML;
result:=inherited OutputXML;
end;
procedure T3DXML.ReWriteXML(inNode:IXMlNode;outNode:IXMLNode);
var
i:integer;
ovar:OleVariant;
anode:IXMLNode;
begin
for i:=0 to inNode.ChildNodes.Count-1 do
begin
ovar:=inNode.ChildNodes.Nodes[i].Attributes['Name'];
if (ovar<>null) and (ovar='FILEPATH') then
begin
ovar:=inNode.ChildNodes.Nodes[i].Attributes['Value'];
if (ovar<>null) then anode:=self.ADDXMLNode(outNode,ovar);
end;
end;
for i:=0 to inNode.ChildNodes.Count-1 do
begin
ReWriteXML(inNode.ChildNodes.Nodes[i],anode);
end;
end;
procedure T3DXML.ReWriteXML;
var
inxml:IXmlDocument; //只能申明为接口,申明为IXMLDocument在构造时不能用Nil
i:integer;
begin
inxml:=TXMLDocument.Create(nil);
inxml.LoadFromFile(FFileName);
inxml.Active:=true;
for i:=0 to inxml.ChildNodes.Count-1 do
begin
self.ReWriteXML(inxml.ChildNodes.Nodes[i],nil);
end;
inxml.Active:=false;
inxml:=nil;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -