You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
502 lines
22 KiB
502 lines
22 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
using Autodesk.AutoCAD.DatabaseServices;
|
|
using Autodesk.AutoCAD.Runtime;
|
|
using Autodesk.AutoCAD.Geometry;
|
|
using Autodesk.AutoCAD.ApplicationServices;
|
|
using Autodesk.AutoCAD.EditorInput;
|
|
|
|
using Teamcenter.Hello;
|
|
using Teamcenter.Soa.Client;
|
|
using Teamcenter.ClientX;
|
|
using Teamcenter.Services.Strong.Core;
|
|
using Teamcenter.Soa.Client.Model;
|
|
using Teamcenter.Soa.Exceptions;
|
|
using Teamcenter.Services.Strong.Query;
|
|
|
|
using Teamcenter.Services.Strong.Core._2007_06.DataManagement;
|
|
|
|
using User = Teamcenter.Soa.Client.Model.Strong.User;
|
|
using Folder = Teamcenter.Soa.Client.Model.Strong.Folder;
|
|
using Newstuff = Teamcenter.Soa.Client.Model.Strong.Newstuff_Folder;
|
|
using DataSet = Teamcenter.Soa.Client.Model.Strong.Dataset;
|
|
using WorkspaceObject = Teamcenter.Soa.Client.Model.Strong.WorkspaceObject;
|
|
using Item = Teamcenter.Soa.Client.Model.Strong.Item;
|
|
using ItemRevision = Teamcenter.Soa.Client.Model.Strong.ItemRevision;
|
|
using ImanQuery = Teamcenter.Soa.Client.Model.Strong.ImanQuery;
|
|
|
|
public struct ALLOBJECT
|
|
{
|
|
public TreeNode treenode;
|
|
public WorkspaceObject workobject;
|
|
public string name;
|
|
public string uid;
|
|
}
|
|
|
|
namespace HelloTeamcenter.form
|
|
{
|
|
public partial class OpenFromTC : Form
|
|
{
|
|
public List<ALLOBJECT> alllist = new List<ALLOBJECT>();
|
|
public List<ALLOBJECT> folderlist = new List<ALLOBJECT>();
|
|
public List<ALLOBJECT> itemlist = new List<ALLOBJECT>();
|
|
public List<ALLOBJECT> itemvisionlist = new List<ALLOBJECT>();
|
|
public List<ALLOBJECT> datasetlist = new List<ALLOBJECT>();
|
|
protected ArrayList datasetTypes;
|
|
public string[] enableTypes;
|
|
public OpenFromTC()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
public Document appodc;
|
|
public User user;
|
|
public bool first = true;
|
|
public Folder home = null;
|
|
public Folder newstuff = null;
|
|
Editor ed;
|
|
|
|
private void getTypes()
|
|
{
|
|
string path = "c:\\dataset_types.xml";
|
|
string root = "dataset";
|
|
string nodeName = "types";
|
|
ReaderCusXML xml = new ReaderCusXML(path, appodc);
|
|
xml.GetALL(root, nodeName);
|
|
xml.close();
|
|
datasetTypes = xml.list;
|
|
//showList();
|
|
}
|
|
|
|
private void showList()
|
|
{
|
|
ed.WriteMessage("-----------------------\n");
|
|
foreach (object o in datasetTypes)
|
|
{
|
|
ed.WriteMessage((string)o + "\n");
|
|
}
|
|
ed.WriteMessage("-----------------------\n");
|
|
}
|
|
|
|
private void OpenFromTC_Load(object sender, EventArgs e)
|
|
{
|
|
ed = appodc.Editor;
|
|
|
|
getTypes();
|
|
int length = datasetTypes.Count;
|
|
//ed.WriteMessage();
|
|
enableTypes = new string[length + 1];
|
|
int t = 0;
|
|
foreach (object o in datasetTypes)
|
|
{
|
|
enableTypes[t] = (string)o;
|
|
t++;
|
|
}
|
|
enableTypes[length] = "Folder";
|
|
|
|
ed.WriteMessage("enableTypes.Length =" + enableTypes.Length+"\n");
|
|
treeView1.Nodes.Clear();
|
|
TreeNode rootnode = new TreeNode("Home", 8, 8);
|
|
treeView1.Nodes.Add(rootnode);
|
|
|
|
WorkspaceObject[] contents = null;
|
|
DataManagementService dmService = DataManagementService.getService(Session.getConnection());
|
|
try
|
|
{
|
|
home = user.Home_folder;
|
|
newstuff = user.Newstuff_folder;
|
|
}
|
|
catch (NotLoadedException ex)
|
|
{
|
|
ed.WriteMessage(ex.Message);
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
ModelObject[] objects = { home };
|
|
String[] attributes = { "contents" };
|
|
dmService.RefreshObjects(objects);
|
|
dmService.GetProperties(objects, attributes);
|
|
contents = home.Contents;
|
|
}
|
|
catch (NotLoadedException ex) { ed.WriteMessage(ex.Message); }
|
|
//ALLOBJECT topobject = new ALLOBJECT();
|
|
//topobject.treenode = rootnode;
|
|
//topobject.workobject = home;
|
|
//alllist.Add(topobject);
|
|
//folderlist.Add(topobject);
|
|
for (int i = 0; i < contents.Length; i++)
|
|
{
|
|
WorkspaceObject childobj = contents[i];
|
|
ModelObject[] objects = { childobj };
|
|
String[] attributes = { "object_string" ,"object_type" };
|
|
dmService.RefreshObjects(objects);
|
|
dmService.GetProperties(objects, attributes);
|
|
string name = childobj.Object_string;
|
|
string type = childobj.Object_type;
|
|
ed.WriteMessage("选择的对象类型是:" + type+"\n");
|
|
if (childobj is Folder){
|
|
ALLOBJECT perobject = new ALLOBJECT();
|
|
perobject.workobject = childobj;
|
|
Folder fl = childobj as Folder;
|
|
if (type == "Newstuff Folder")
|
|
{
|
|
TreeNode childnode = new TreeNode(name, 7, 7);
|
|
perobject.treenode = childnode;
|
|
perobject.name = name;
|
|
perobject.uid = childobj.Uid;
|
|
rootnode.Nodes.Add(childnode);
|
|
}
|
|
else if (type == "Mail Folder")
|
|
{
|
|
TreeNode childnode = new TreeNode(name, 6, 6);
|
|
perobject.treenode = childnode;
|
|
perobject.name = name;
|
|
perobject.uid = childobj.Uid;
|
|
rootnode.Nodes.Add(childnode);
|
|
}
|
|
else
|
|
{
|
|
TreeNode childnode = new TreeNode(name, 1, 1);
|
|
perobject.treenode = childnode;
|
|
perobject.name = name;
|
|
perobject.uid = childobj.Uid;
|
|
rootnode.Nodes.Add(childnode);
|
|
}
|
|
alllist.Add(perobject);
|
|
folderlist.Add(perobject);
|
|
}
|
|
else if (childobj is Item)
|
|
{
|
|
ALLOBJECT perobject = new ALLOBJECT();
|
|
perobject.workobject = childobj;
|
|
Item item = childobj as Item;
|
|
TreeNode childnode = new TreeNode(name, 3, 3);
|
|
perobject.treenode = childnode;
|
|
perobject.name = name;
|
|
perobject.uid = childobj.Uid;
|
|
rootnode.Nodes.Add(childnode);
|
|
alllist.Add(perobject);
|
|
itemlist.Add(perobject);
|
|
}
|
|
}
|
|
foreach(TreeNode ch in rootnode.Nodes)
|
|
{
|
|
ch.EnsureVisible();
|
|
}
|
|
}
|
|
|
|
private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
|
|
{
|
|
//MessageBox.Show("获得");
|
|
ed.WriteMessage("tree view 双击事件...\n");
|
|
TreeNode nownode = this.treeView1.SelectedNode;
|
|
|
|
getChild(nownode);
|
|
foreach (TreeNode ch in nownode.Nodes)
|
|
{
|
|
ch.EnsureVisible();
|
|
}
|
|
}
|
|
|
|
private void getChild(TreeNode nownode)
|
|
{
|
|
nownode.Nodes.Clear();
|
|
DataManagementService dmService = DataManagementService.getService(Session.getConnection());
|
|
WorkspaceObject[] contents = null;
|
|
//dmService.GetProperties(objects, attributes);
|
|
string nodetext = nownode.Text;
|
|
int imageindex = nownode.SelectedImageIndex;
|
|
List<ALLOBJECT> templist = new List<ALLOBJECT>();
|
|
if (imageindex == 1) //处理文件夹对象
|
|
{
|
|
ed.WriteMessage("文件夹类型:\n");
|
|
foreach (ALLOBJECT perobject in folderlist)
|
|
{
|
|
if (perobject.treenode.Equals(nownode))
|
|
{
|
|
Folder fl = perobject.workobject as Folder;
|
|
ModelObject[] objects = { fl };
|
|
String[] attributes = { "contents" };
|
|
dmService.RefreshObjects(objects);
|
|
dmService.GetProperties(objects, attributes);
|
|
contents = fl.Contents;
|
|
for (int i = 0; i < contents.Length; i++)
|
|
{
|
|
WorkspaceObject childobj = contents[i];
|
|
ModelObject[] objects1 = { childobj };
|
|
String[] attributes1 = { "object_string", "object_type" };
|
|
dmService.RefreshObjects(objects1);
|
|
dmService.GetProperties(objects1, attributes1);
|
|
string name = childobj.Object_string;
|
|
string type = childobj.Object_type;
|
|
if (childobj is Folder)
|
|
{
|
|
ALLOBJECT inperobject = new ALLOBJECT();
|
|
inperobject.workobject = childobj;
|
|
Folder infl = childobj as Folder;
|
|
|
|
if (type == "Newstuff Folder")
|
|
{
|
|
TreeNode childnode = new TreeNode(name, 7, 7);
|
|
inperobject.treenode = childnode;
|
|
nownode.Nodes.Add(childnode);
|
|
}
|
|
else if (type == "Mail Folder")
|
|
{
|
|
TreeNode childnode = new TreeNode(name, 6, 6);
|
|
inperobject.treenode = childnode;
|
|
nownode.Nodes.Add(childnode);
|
|
}
|
|
else
|
|
{
|
|
TreeNode childnode = new TreeNode(name, 1, 1);
|
|
inperobject.treenode = childnode;
|
|
nownode.Nodes.Add(childnode);
|
|
}
|
|
templist.Add(inperobject);
|
|
folderlist.Add(inperobject);
|
|
}
|
|
else if (childobj is Item)
|
|
{
|
|
ALLOBJECT inperobject = new ALLOBJECT();
|
|
inperobject.workobject = childobj;
|
|
Item item = childobj as Item;
|
|
TreeNode childnode = new TreeNode(name, 3, 3);
|
|
inperobject.treenode = childnode;
|
|
nownode.Nodes.Add(childnode);
|
|
templist.Add(inperobject);
|
|
itemlist.Add(inperobject);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
if (templist.Count > 0 && templist != null)
|
|
{
|
|
alllist.AddRange(templist);
|
|
templist.Clear();
|
|
}
|
|
return;
|
|
|
|
}
|
|
else if (imageindex == 3) //处理Item对象
|
|
{
|
|
ed.WriteMessage("Item类型:\n");
|
|
foreach (ALLOBJECT perobject in itemlist)
|
|
{
|
|
if (perobject.treenode.Equals(nownode))
|
|
{
|
|
Item item = perobject.workobject as Item;
|
|
ModelObject[] itemrevisionlist = null;
|
|
ModelObject[] objects = { item };
|
|
String[] attributes = { "revision_list" };
|
|
dmService.RefreshObjects(objects);
|
|
dmService.GetProperties(objects, attributes);
|
|
itemrevisionlist = item.Revision_list;
|
|
for (int i = 0; i < itemrevisionlist.Length; i++)
|
|
{
|
|
ItemRevision itemrevision = itemrevisionlist[i] as ItemRevision;
|
|
ModelObject[] objects1 = { itemrevision };
|
|
String[] attributes1 = { "object_string", "object_type" };
|
|
dmService.RefreshObjects(objects1);
|
|
dmService.GetProperties(objects1, attributes1);
|
|
string name = itemrevision.Object_string;
|
|
string type = itemrevision.Object_type;
|
|
|
|
ALLOBJECT inperobject = new ALLOBJECT();
|
|
inperobject.workobject = itemrevision;
|
|
TreeNode childnode = new TreeNode(name, 4, 4);
|
|
inperobject.treenode = childnode;
|
|
nownode.Nodes.Add(childnode);
|
|
templist.Add(inperobject);
|
|
itemvisionlist.Add(inperobject);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
if (templist.Count > 0 && templist != null)
|
|
{
|
|
alllist.AddRange(templist);
|
|
templist.Clear();
|
|
}
|
|
return;
|
|
}
|
|
else if (imageindex == 4) //处理Item版本对象
|
|
{
|
|
ed.WriteMessage("ItemRevision类型:\n");
|
|
foreach (ALLOBJECT perobject in itemvisionlist)
|
|
{
|
|
if (perobject.treenode.Equals(nownode))
|
|
{
|
|
ItemRevision itemrevision = perobject.workobject as ItemRevision;
|
|
ExpandGRMRelationsPref myPref = new ExpandGRMRelationsPref();
|
|
RelationAndTypesFilter2 myFilter = new RelationAndTypesFilter2();
|
|
myFilter.RelationName = "IMAN_specification";
|
|
//String[] typeVec = { "D5DWG", "Folder" };
|
|
myFilter.ObjectTypeNames = enableTypes;
|
|
myPref.ExpItemRev = false;
|
|
RelationAndTypesFilter2[] myfilter = { myFilter };
|
|
myPref.Info = myfilter;
|
|
ModelObject[] objects1 = { itemrevision };
|
|
|
|
ExpandGRMRelationsResponse myResp = dmService.ExpandGRMRelationsForPrimary(objects1,myPref);
|
|
ExpandGRMRelationsOutput[] myoutput = myResp.Output;
|
|
for (int i = 0; i < myoutput.Length; i++)
|
|
{
|
|
ExpandGRMRelationsOutput one_out = myoutput[i];
|
|
for (int j = 0; j < one_out.OtherSideObjData.Length; j++)
|
|
{
|
|
ExpandGRMRelationsData otherSideData = one_out.OtherSideObjData[j];
|
|
for (int k = 0; k < otherSideData.OtherSideObjects.Length; k++)
|
|
{
|
|
Type typeinfo = otherSideData.OtherSideObjects[k].GetType();
|
|
string typename = typeinfo.Name;
|
|
ModelObject temp = otherSideData.OtherSideObjects[k];
|
|
//if (typename == "Folder")
|
|
if (temp is Folder)
|
|
{
|
|
Folder infold = temp as Folder;
|
|
|
|
ModelObject[] objects = { infold };
|
|
String[] attributes = { "object_string", "object_type" };
|
|
dmService.RefreshObjects(objects);
|
|
dmService.GetProperties(objects, attributes);
|
|
string name = infold.Object_string;
|
|
string type = infold.Object_type;
|
|
|
|
ALLOBJECT inperobject = new ALLOBJECT();
|
|
inperobject.workobject = infold;
|
|
TreeNode childnode = new TreeNode(name, 1, 1);
|
|
inperobject.treenode = childnode;
|
|
nownode.Nodes.Add(childnode);
|
|
templist.Add(inperobject);
|
|
folderlist.Add(inperobject);
|
|
}
|
|
else if (temp is DataSet)
|
|
{
|
|
DataSet dateset = temp as DataSet;
|
|
ModelObject[] objects = { dateset };
|
|
String[] attributes = { "object_string" ,"object_type"};
|
|
dmService.RefreshObjects(objects);
|
|
dmService.GetProperties(objects, attributes);
|
|
string name = dateset.Object_string;
|
|
string type = dateset.Object_type;
|
|
ed.WriteMessage("类型是:"+type);
|
|
ALLOBJECT inperobject = new ALLOBJECT();
|
|
inperobject.workobject = dateset;
|
|
inperobject.name = name;
|
|
TreeNode childnode = new TreeNode(name, 0, 0);
|
|
inperobject.treenode = childnode;
|
|
nownode.Nodes.Add(childnode);
|
|
templist.Add(inperobject);
|
|
datasetlist.Add(inperobject);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
if (templist.Count > 0 && templist != null)
|
|
{
|
|
alllist.AddRange(templist);
|
|
templist.Clear();
|
|
}
|
|
return;
|
|
}
|
|
else if (imageindex == 6)
|
|
{
|
|
ed.WriteMessage("Mail类型:\n");
|
|
}
|
|
else if (imageindex == 8)
|
|
{
|
|
ed.WriteMessage("Home类型:\n");
|
|
}
|
|
else if(imageindex == 7) //new stuffer foler 处理
|
|
{
|
|
alllist.Clear();
|
|
folderlist.Clear();
|
|
itemlist.Clear();
|
|
itemvisionlist.Clear();
|
|
datasetlist.Clear();
|
|
ed.WriteMessage("Newstuff类型:\n");
|
|
try
|
|
{
|
|
ModelObject[] objects = { newstuff };
|
|
String[] attributes = { "contents" };
|
|
dmService.RefreshObjects(objects);
|
|
dmService.GetProperties(objects, attributes);
|
|
contents = newstuff.Contents;
|
|
}
|
|
catch (NotLoadedException ex) { ed.WriteMessage(ex.Message); }
|
|
for (int i = 0; i < contents.Length; i++)
|
|
{
|
|
WorkspaceObject childobj = contents[i];
|
|
ModelObject[] objects = { childobj };
|
|
String[] attributes = { "object_string", "object_type" };
|
|
dmService.RefreshObjects(objects);
|
|
dmService.GetProperties(objects, attributes);
|
|
string name = childobj.Object_string;
|
|
string type = childobj.Object_type;
|
|
if (childobj is Folder)
|
|
{
|
|
ALLOBJECT perobject = new ALLOBJECT();
|
|
perobject.workobject = childobj;
|
|
Folder fl = childobj as Folder;
|
|
if (type == "Newstuff Folder")
|
|
{
|
|
TreeNode childnode = new TreeNode(name, 7, 7);
|
|
perobject.treenode = childnode;
|
|
perobject.name = name;
|
|
perobject.uid = childobj.Uid;
|
|
nownode.Nodes.Add(childnode);
|
|
}
|
|
else if (type == "Mail Folder")
|
|
{
|
|
TreeNode childnode = new TreeNode(name, 6, 6);
|
|
perobject.treenode = childnode;
|
|
perobject.name = name;
|
|
perobject.uid = childobj.Uid;
|
|
nownode.Nodes.Add(childnode);
|
|
}
|
|
else
|
|
{
|
|
TreeNode childnode = new TreeNode(name, 1, 1);
|
|
perobject.treenode = childnode;
|
|
perobject.name = name;
|
|
perobject.uid = childobj.Uid;
|
|
nownode.Nodes.Add(childnode);
|
|
}
|
|
alllist.Add(perobject);
|
|
folderlist.Add(perobject);
|
|
}
|
|
else if (childobj is Item)
|
|
{
|
|
ALLOBJECT perobject = new ALLOBJECT();
|
|
perobject.workobject = childobj;
|
|
Item item = childobj as Item;
|
|
TreeNode childnode = new TreeNode(name, 3, 3);
|
|
perobject.treenode = childnode;
|
|
perobject.name = name;
|
|
perobject.uid = childobj.Uid;
|
|
nownode.Nodes.Add(childnode);
|
|
alllist.Add(perobject);
|
|
itemlist.Add(perobject);
|
|
}
|
|
}
|
|
foreach (TreeNode ch in nownode.Nodes)
|
|
{
|
|
ch.EnsureVisible();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|