我很抱歉这个模糊的标题。这个问题是之前发布的问题的延续:在 fortran 77 中使用 C++ 类对象我需要做的是重用在 Fortran 中从 C++ 创建的对象。
我正在处理的代码是一个非常简单的 Fortran 代码:
C23456
program main
C Pointers to C++ classes. Never use them!
C Just pass them to the C++ functions.
integer*4 shapeToMesh
integer*4 faceMap
integer*4 edgeMap
integer*4 vertexMap
C We have to append //CHAR(0) to the string since it must be
C Null terminated
call readstep('cube.stp'//CHAR(0),isuccess,shapeToMesh)
call createfacemap(shapeToMesh,faceMap)
end
其中shapeToMesh
是一个类对象,其中包含从输入步骤文件中解析的几何图形。faceMap
edgeMap
vertexMap
是分别为每个面边和顶点分配唯一整数的对象
现在readstep
or readstep_
(请注意,这些是 C++)函数运行良好,代码如下:
//SuccessInt contains information about successful loading
//of file. 1 for success, 0 for failure
void readstep_(char* inputFile,int* successInt, TopoDS_Shape** shape){
//Print out the filename received from fortan for debug reasons
int len = strlen(inputFile);
std::cout << "Input file ";
for(int i=0; i<len; i++)
std::cout << inputFile[i];
std::cout << std::endl<< std::endl;
//This has a private contructor. So I must first declare
//and then call the constructor.
STEPControl_Reader reader;
reader = STEPControl_Reader();
int succeed = reader.ReadFile(inputFile);
if(!succeed){
std::cout << "There was an error with the input file" << std::endl;
(*successInt) = succeed;
return;
}
reader.NbRootsForTransfer();
reader.TransferRoots();
//Assign memory, then opject
*shape = new TopoDS_Shape();
**shape = reader.OneShape();
(*successInt) = succeed;
return;
}
正如您可能已经从我的 Fortran 代码段中看到的那样,接下来我要做的是创建一个包含我在形状中的面孔的列表。为此,我调用createfacemap
orcreatefacemap_
函数,其代码如下所示:
void createfacemap_(TopoDS_Shape** shape, TopTools_IndexedMapOfShape** map){
TopoDS_Shape ashape = TopoDS_Shape();
ashape = (**shape);
if(ashape.IsNull())
std::cout << "Shape is null";
*map = new TopTools_IndexedMapOfShape();
TopExp::MapShapes(ashape,TopAbs_FACE,(**map));
std::cout << "Faces: " << (**map).Extent() << std::endl;
return;
}
但是我得到的结果不是 6 个面孔,而是 0 个面孔。为了进一步调查,我使用一个点调试了程序。结果可以在截图中看到
可以看出,由于 NbBuckets 发生了变化,map 变量被初始化并进行了一些处理,但是大小根本没有变化,这意味着没有存储任何对象。我正在使用 openCASCADE 库。以下是相关参考资料:
http://dev.opencascade.org/doc/refman/html/class_topo_d_s___shape.html http://dev.opencascade.org/doc/refman/html/class_top_exp.html http://dev.opencascade.org/doc/ refman/html/class_top_tools___indexed_map_of_shape.html
任何帮助将非常感激!