2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > Qt Solidworks零件中文特征名转换成英文

Qt Solidworks零件中文特征名转换成英文

时间:2021-06-20 13:58:38

相关推荐

Qt Solidworks零件中文特征名转换成英文

用Qt实现遍历Solidworks零件特征,将中文特征名改为中文。config.csv为中文转英文翻译文件,格式为:中文,english中文,english...,...

Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget){ui->setupUi(this);setWindowTitle("SW零件特征中文转英文");QFile *file = new QFile(QString("./config.csv"));if(file->open(QIODevice::ReadOnly) == false){QMessageBox::warning(this,"警告","翻译文件载入失败!");return;}while(!file->atEnd()){QString temp = QString::fromLocal8Bit(file->readLine());temp.chop(2);QStringList name = temp.split("/");swChinese.append(name.first());swEnglish.append(name.last());}swApp = NULL;ui->pushButton->setDisabled(true);}Widget::~Widget(){delete ui;}void Widget::on_pushButton_clicked(){ui->pushButton->setDisabled(true);QStringList fileNames = QFileDialog::getOpenFileNames(this,"选择SW零件文件","./","SW零件(*.SLDPRT)");for(int i = 0;i<fileNames.count();i++){//参数列表QList<QVariant> list;int error = 0;int warning = 0;list.append(fileNames.at(i));list.append(1);list.append(0);list.append("");list.append(error);list.append(warning);//打开指定的文件swApp->dynamicCall("OpenDoc6(QString,int,int,QString,int&,int&)",list);//获取活动模型零件QAxObject * swModel = swApp->querySubObject("ActiveDoc");//获取模型第一个特征QAxObject * swFeature = swModel->querySubObject("FirstFeature()");//遍历模型所有特征TraverseFeatures(swFeature,true);//保存文件swModel->dynamicCall("Save()");//关闭文件swApp->dynamicCall("QuitDoc(QString)",fileNames.at(i));}ui->pushButton->setDisabled(false);}//遍历零件的所有特征void Widget::TraverseFeatures(QAxObject *thisFeat, bool isTopLevel){QAxObject * curFeat = thisFeat;while(curFeat != NULL){//读取特征名QString featName = curFeat->dynamicCall("Name").toString();//特征名的字符数int count = featName.count();//保存特征名内的数字QString number;//循环检查名字内是否有数字for(int i = count-1;i>=0;i--){//是数字就单独保存if(featName.at(i).isNumber() == true){number.insert(0,featName.at(i));}else//不是就推出循环goto go;}// qDebug()<<featName;go://分离数字featName.remove(count-number.count(),number.count());// qDebug()<<featName;//获取索引号int index = swChinese.indexOf(featName);//qDebug()<<index;// qDebug()<<number;if(index != -1 ){curFeat->dynamicCall("SetName(QString)",swEnglish.at(index)+number);}//获取特征的第一个子特征QAxObject * subFeat = curFeat->querySubObject("GetFirstSubFeature()");//子特征存在while(subFeat != NULL){//递归遍历TraverseFeatures(subFeat,false);//获取下一个子特征QAxObject *nextSubFeat = subFeat->querySubObject("GetNextSubFeature()");subFeat = nextSubFeat;nextSubFeat = NULL;}subFeat = NULL;QAxObject *nextFeat;if(isTopLevel){nextFeat = curFeat->querySubObject("GetNextFeature()");}else{nextFeat = NULL;}curFeat = nextFeat;nextFeat = NULL;}}void Widget::on_pushButton_3_clicked(){ui->pushButton_3->setDisabled(true);if(swApp == NULL){//打开SW程序swApp = new QAxObject(QString("SldWorks.Application"),0);swApp->setProperty("Visible",true);ui->pushButton_3->setText("关闭SW");ui->pushButton->setDisabled(false);}else{//关闭SW程序swApp->dynamicCall("ExitApp()");delete swApp;swApp = NULL;ui->pushButton_3->setText("打开SW");ui->pushButton->setDisabled(true);}ui->pushButton_3->setDisabled(false);}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。