c++基础太弱,纠正一下,在PRO中使用包含目录就可以使用<>,将下载的opencascade文件通过make编译和安装,添加引用就可以了。
如果你依然对以下没用的操作感兴趣,请继续....
使用PYTHON转换一下包含的文件格式,OCC默认使用的 <XXXX.hxx> qt不能识别,需要转换为 "xxxx.hxx"
补充:在QT的pro文件里添加 INCLUDE += /home/XXXX/Documents/opencascade-7.0.0/src/XXXX ,在头文件里引用即可 比如 #include <gp_Pnt.hxx>
有知道怎么设置识别的请告诉我 谢谢
以下是python代码,从occ文件夹获取文件到qt程序下的目录
实现功能:指定需要使用的occ源代码文件,从源代码目录拷贝到指定文件夹,并将所有源代码头文件包含的文件也拷贝过来,同事将 #include <xxxx.hxx> 改为 #include "xxxx.hxx"
基本思路
1.设置默认需要的文件们,从源文件夹拷贝过来
2.将已经拷贝过来的文件添加列表sonsList
2.循环读取默认文件,将自己从list清除,检测#include <xxxx.hxx>
3.替换为 "xxxx.hxx"并记录到sonsList
4.从sonsList读取顶部的记录,递归查找
5.查找下一个默认定义的文件
#coding=utf-8
#get the file from occ
# copy the file and change its header include
import os
import os.path
import shutil
import re
def findStr(fml_s):
match = re.search('(^#include\s+)<(.*\.(hxx|lxx))>', fml_s)
if match:
ms = match.group()
fline = chStr(fml_s)
headername=match.group(2)
print('find' ,match.group(2))
print('find in line',fline)
return True, fml_s, headername
else:
return False, fml_s, ''
def chStr(fml_s):
fml_s = re.sub('<','"occ_math/',fml_s)
fml_s=re.sub('>','"',fml_s)
return fml_s
def getPack(fml_s): #get a package name from file name /occ defined it
match=re.match('[a-zA-Z0-9]+',fml_s)
#print(match.group())
return match.group()
def rmSuffix(fml_s):
match=re.match('(.+)\.+',fml_s)
print(match)
return match.group(1)
class findSons:
filename=''
occPath= ''
ffn=''
ct=0
def __init__(self,fml_sName,fml_soccPath):
self.filename=fml_sName
self.occPath=fml_soccPath
self.tgt_path='/home/kare/Documents//QtProg/mCons1/occ_math'
self.ffn=self.tgt_path+'/'+self.filename
def find(self,fml_s):
self.filename = fml_s
self.ffn = self.tgt_path + '/' + self.filename
fstr=''
fsize=os.path.getsize(self.ffn)
#copy self
lca_pkNam=getPack(self.filename)
lca_sName=self.occPath+'/'+lca_pkNam+'/'+self.filename
if(os.path.exists(lca_sName) and not os.path.exists(self.ffn)):
shutil.copy(lca_sName, tgt_path)
#remove self from globan list
for lca_sn1 in sonList: #remove self
if(lca_sn1==self.filename):
sonList.remove(lca_sn1)
break
print('self size:',fsize)
fh=open(self.ffn, 'r+')
fline=fh.readline()
while (fsize != fh.tell()): # read til ::,its shows that function start
brslt, fline, headername = findStr(fline) # find a name witf 'hxx'
if (brslt): # check it in copyfiles
print('find header->'+headername)
fline = chStr(fline)
packname=getPack(headername)
sFn=rmSuffix(headername)
hxx=self.occPath + '/' + packname +'/'+ sFn + '.' + 'hxx'
cxx=self.occPath + '/' + packname +'/'+ sFn + '.' + 'cxx'
lxx=self.occPath + '/' + packname +'/'+ sFn+ '.' + 'lxx'
thxx=self.tgt_path+'/'+ sFn + '.' + 'hxx'
tcxx=self.tgt_path+'/'+ sFn+ '.' + 'cxx'
tlxx=self.tgt_path+'/'+ sFn + '.' + 'lxx'
if (os.path.exists(hxx) and not os.path.exists(thxx)):
#self.sonList.append(fs2(sFn + '.' + 'hxx',self.occPath))
sonList.append(sFn+'.hxx')
shutil.copy(hxx, tgt_path)
if (os.path.exists(cxx) and not os.path.exists(tcxx)):
#self.sonList.append(fs2(sFn + '.' + 'cxx',self.occPath))
sonList.append(sFn+'.cxx')
shutil.copy(cxx, tgt_path)
if (os.path.exists(lxx) and not os.path.exists(tlxx)):
#self.sonList.append(fs2(sFn + '.' + 'lxx',self.occPath))
sonList.append(sFn+'.lxx')
shutil.copy(lxx, tgt_path)
fstr+=fline
fline=fh.readline()
fstr+=fline
fh.seek(0,0)
fh.write(fstr)
fh.close()
fline=fstr=''
def findRecursion(self):
while(len(sonList)!=0):
self.find(sonList[0])
self.ct+=1
class fs2(findSons):
pass
#default occ path
occ_path='/home/kare/Documents/opencascade-7.0.0/src'
tgt_path='/home/kare/Documents/QtProg/mCons1/occ_math'
copy_files=[] # files been copyed
lca_fileList=[]
#the files you want
occ_files=('math_Matrix','math_Vector','gp_Ax1')
occ_files_type=('hxx','cxx','lxx')
allPckName=[] # all kind of packname
for lca_name1 in occ_files: # get all packages name
lca_pckname=getPack(lca_name1)
if(lca_pckname not in allPckName):
allPckName.append(lca_pckname)
lca_str1=input('copyfile? y|n\r\n')
if(lca_str1=='y'):
#copy the files in define
for lca_pcknm in allPckName:
#get the files list
lca_fileList=os.listdir(occ_path + '/' + lca_pcknm)
print('package' + lca_pcknm)
for lca_file1 in lca_fileList: #all files in package
for lca_fnm1 in occ_files: # names be finding
if(lca_fnm1 in lca_file1):# type
print(occ_path +'/' + lca_pcknm + '/' + lca_file1)
shutil.copy(occ_path +'/' + lca_pcknm + '/' + lca_file1, tgt_path)
copy_files.append(lca_file1)
print('copy done,start aynlyzing')
os.chdir(tgt_path)
fstr=''
fline=''
nulLine=0 # space line number
bFindOrCh=False # find or change string
ct=[]
if len(copy_files)==0:
copy_files=os.listdir()
lca_fileList = os.listdir(tgt_path)
sonList=[]
print('start finding')
for lca_f in lca_fileList:
sonList.append(lca_f)
fs=findSons(lca_f,occ_path)
fs.findRecursion()
ct.append(fs.ct)
#remain file
shutil.copy(occ_path+'/'+'Standard/Standard_values.h',tgt_path)
print(ct)
print('======================done=======================')
这个脚本会从occ源文件目录拷贝到QT程序目录(需要在代码中设置)
有一个特殊的文件 Standard_Valued.h 需要手动在其他代码中修改引用 <xxxx.h> 为 "xxxx.h"
以下是QT测试代码,可以使用,还没有用到其他的,有问题再解决
#include "occ_math/gp_Pnt.hxx"
extern int testGp()
{
gp_Pnt p1(100,2,3);
cout<<p1.X()<<endl;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)