|
|
package com.connor.kwc.createDWG;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import org.eclipse.core.commands.AbstractHandler;
|
|
|
import org.eclipse.core.commands.ExecutionEvent;
|
|
|
import org.eclipse.core.commands.ExecutionException;
|
|
|
import com.connor.kwc.createBom.Util;
|
|
|
import com.teamcenter.rac.aif.AbstractAIFApplication;
|
|
|
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
|
|
import com.teamcenter.rac.aifrcp.AIFUtility;
|
|
|
import com.teamcenter.rac.kernel.TCComponent;
|
|
|
import com.teamcenter.rac.kernel.TCComponentDataset;
|
|
|
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
|
|
import com.teamcenter.rac.kernel.TCComponentTcFile;
|
|
|
import com.teamcenter.rac.kernel.TCException;
|
|
|
import com.teamcenter.rac.kernel.TCSession;
|
|
|
import com.teamcenter.rac.util.MessageBox;
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* @ClassName: CreateDWGHandler
|
|
|
* @Description: 根据用户选择菜单创建图纸数据集
|
|
|
* @author hcj
|
|
|
* @date 2023年12月22日
|
|
|
*
|
|
|
*/
|
|
|
public class CreateDWGHandler extends AbstractHandler {
|
|
|
|
|
|
private TCSession session;
|
|
|
private String type;
|
|
|
|
|
|
@Override
|
|
|
public Object execute(ExecutionEvent arg0) throws ExecutionException {
|
|
|
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
|
|
|
try {
|
|
|
new Thread() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
// 获取tc当前选择的操作
|
|
|
InterfaceAIFComponent target = app.getTargetComponent();
|
|
|
session = (TCSession) target.getSession();
|
|
|
String[] sxx = Util.getSXX(session, "KWC_DWGTemplateItemList");
|
|
|
|
|
|
ArrayList<String> itemTypeList = new ArrayList<>(Arrays.asList(sxx));
|
|
|
if (target instanceof TCComponentItemRevision) {
|
|
|
TCComponentItemRevision revision = (TCComponentItemRevision) target;
|
|
|
try {
|
|
|
if (itemTypeList.contains(revision.getStringProperty("object_type"))) {
|
|
|
String[] uidtemp = Util.getSXX(session, "KWC_DWGTemplateUID");
|
|
|
Map<String, String> templateMap = new HashMap<String, String>();
|
|
|
for (String str : uidtemp) {
|
|
|
String[] split = str.split("=");
|
|
|
templateMap.put(split[0], split[1]);
|
|
|
}
|
|
|
String id = arg0.getCommand().getId();
|
|
|
if (id.endsWith("A0")) {
|
|
|
createdataSetForUID(revision, templateMap, "A0");
|
|
|
} else if (id.endsWith("A1")) {
|
|
|
createdataSetForUID(revision, templateMap, "A1");
|
|
|
} else if (id.endsWith("A2")) {
|
|
|
createdataSetForUID(revision, templateMap, "A2");
|
|
|
} else if (id.endsWith("A3")) {
|
|
|
createdataSetForUID(revision, templateMap, "A3");
|
|
|
} else if (id.endsWith("A4")) {
|
|
|
createdataSetForUID(revision, templateMap, "A4");
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
MessageBox.post("选择的对象类型不存在于【KWC_DWGTemplateItemList】,请重新选择", "提示",
|
|
|
MessageBox.INFORMATION);
|
|
|
return;
|
|
|
}
|
|
|
} catch (TCException e) {
|
|
|
// TODO Auto-generated catch block
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}.start();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public void createdataSetForUID(TCComponentItemRevision revision, Map<String, String> templateMap, String key)
|
|
|
throws TCException {
|
|
|
if (templateMap.containsKey(key)) {
|
|
|
TCComponent dataseTcComponent = session.stringToComponent(templateMap.get(key));
|
|
|
if (dataseTcComponent instanceof TCComponentDataset) {
|
|
|
TCComponentDataset dataset = (TCComponentDataset) dataseTcComponent;
|
|
|
TCComponentDataset saveAs = dataset.saveAs(null);
|
|
|
saveAs.setStringProperty("object_name", revision.getStringProperty("item_id"));
|
|
|
TCComponentTcFile[] tcFiles = saveAs.getTcFiles();
|
|
|
tcFiles[0].setStringProperty("object_name", revision.getStringProperty("item_id") + ".dwg");
|
|
|
revision.add("IMAN_specification", saveAs);
|
|
|
MessageBox.post("创建成功", "提示", MessageBox.INFORMATION);
|
|
|
return;
|
|
|
}
|
|
|
} else {
|
|
|
MessageBox.post("首选项【KWC_DWGTemplateUID】没有匹配的ID值", "提示", MessageBox.INFORMATION);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|