あいまいなタイトルで申し訳ありません。この質問は、ここに投稿された以前の質問の続きです: Fortran 77 で C++ クラス オブジェクトを使用する必要があるのは、C++ から作成されたオブジェクトを Fortran で再利用することです。
私が扱っているコードは、非常に単純な 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 が変更されてから何らかの処理が行われていることがわかりますが、サイズはまったく変更されていません。つまり、オブジェクトが保存されていないことを意味します。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
どんな助けでも本当に感謝します!