qmg_init.cpp
来自「算断裂的」· C++ 代码 · 共 565 行 · 第 1/2 页
CPP
565 行
// ------------------------------------------------------------------// qmg_init.cpp//// This file contains the entry routine for qmg under tcl/tk.// It also defines the brep and simpcomp types, and conversion routines.// ------------------------------------------------------------------// Copyright (c) 1999 by Cornell University. All rights reserved.// // See the accompanying file 'Copyright' for authorship information,// the terms of the license governing this software, and disclaimers// concerning this software.// ------------------------------------------------------------------// This file is part of the QMG software. // Version 2.0 of QMG, release date September 3, 1999// ------------------------------------------------------------------extern "C" {#include "tcl.h"}typedef char* CKalloc_return_type;#include "qbrep_constr.h"#include "qsimpcomp.h"#include "qerr.h"// Routines in this file.namespace QMG { namespace FrontEnd { using namespace QMG; int set_tcl_lib(Tcl_Interp* interp); Brep_From_FrontEnd get_brep_from_obj(Tcl_Interp* interp, Tcl_Obj* obj, int& returncode); Tcl_Obj* new_simpcomp_obj(Cptc_MshDesc* mesh); SimpComplex_From_FrontEnd get_simpcomp_from_obj(Tcl_Interp* interp, Tcl_Obj* obj, int& returncode); Tcl_Obj* new_brep_obj(Cptc_GeomDesc* geo); Object_Type_Code get_obj_type(Tcl_Interp* interp, Tcl_Obj* obj); }}extern "C" { int qmg_init(Tcl_Interp* interp); static int gm_enable_string_rep(ClientData, Tcl_Interp*, int, Tcl_Obj* const[]); static void BrepFreeInternalRep(Tcl_Obj* obj); static void BrepDupInternalRep(Tcl_Obj* src, Tcl_Obj* dest); static void BrepUpdateStringRep(Tcl_Obj* obj); static int BrepSetFromAny(Tcl_Interp* interp, Tcl_Obj* obj); static void SimpCompFreeInternalRep(Tcl_Obj* obj); static void SimpCompDupInternalRep(Tcl_Obj* src, Tcl_Obj* dest); static void SimpCompUpdateStringRep(Tcl_Obj* obj); static int SimpCompSetFromAny(Tcl_Interp* interp, Tcl_Obj* obj); }namespace { Tcl_ObjType brep_type; Tcl_ObjType simpcomp_type; bool enable_string_rep = false;}// external routines:extern "C" { char* getenv(const char*); int gm_meshgen(ClientData, Tcl_Interp*, int, Tcl_Obj* const[]); int gm_read(ClientData, Tcl_Interp*, int, Tcl_Obj* const[]); int gm_write(ClientData, Tcl_Interp*, int, Tcl_Obj* const[]); int gmchecktri(ClientData, Tcl_Interp*, int, Tcl_Obj* const[]); int gmset(ClientData, Tcl_Interp*, int, Tcl_Obj* const[]); int gm_obj2list(ClientData, Tcl_Interp*, int, Tcl_Obj* const[]); int gm_vizp(ClientData, Tcl_Interp*, int, Tcl_Obj* const[]); int gmapply(ClientData, Tcl_Interp*, int, Tcl_Obj* const[]); int gm_polytri(ClientData, Tcl_Interp*, int, Tcl_Obj* const[]); int gmboundary(ClientData, Tcl_Interp*, int, Tcl_Obj* const[]); int gm_objtype(ClientData, Tcl_Interp*, int, Tcl_Obj* const[]); int gm_list2obj(ClientData, Tcl_Interp*, int, Tcl_Obj* const[]); int gmxdr_read(ClientData, Tcl_Interp*, int, Tcl_Obj* const[]); int gmxdr_write(ClientData, Tcl_Interp*, int, Tcl_Obj* const[]); int gmmeshsize(ClientData, Tcl_Interp*, int, Tcl_Obj* const[]); int gmdouble(ClientData, Tcl_Interp*, int, Tcl_Obj* const[]); // int gmraisedeg(ClientData, Tcl_Interp*, int, Tcl_Obj* const[]); int gmchecknormals(ClientData, Tcl_Interp*, int, Tcl_Obj* const[]); int gmcoarsetopo(ClientData, Tcl_Interp*, int, Tcl_Obj* const[]); int gm_mcompo(ClientData, Tcl_Interp*, int, Tcl_Obj* const[]); int gm_whichcompiler(ClientData, Tcl_Interp*, int, Tcl_Obj* const[]);#if 0 int intline(ClientData, Tcl_Interp*, int, Tcl_Obj* const[]); int brepnrml(ClientData, Tcl_Interp*, int, Tcl_Obj* const[]);#endif int dde_openurl(ClientData, Tcl_Interp*, int, char**); void cptc_free_geo(Cptc_GeomDesc* geo); Cptc_GeomDesc* cptc_clone_geo(Cptc_GeomDesc* geo); void cptc_free_mesh(Cptc_MshDesc* msh); Cptc_MshDesc* cptc_clone_mesh(Cptc_MshDesc* msh);}namespace QMG { extern Object_Type_Code read_header_from_istream(istream& istr, int& line_count);}// ------------------------------------------------------------------// This routine inserts the variable "qmg_library" into the global// namespace by reading the environment variable QMG_ROOT.intQMG::FrontEnd::set_tcl_lib(Tcl_Interp* interp) { char* path = getenv("QMG_ROOT"); int returncode; if (path) { Tcl_SetVar(interp, "qmg_library", path, 0); Tcl_VarEval(interp, "append qmg_library", " /tcl", 0); returncode = TCL_OK; } else { Tcl_SetVar(interp, "qmg_library", QMG_DEFAULT_ROOT, 0); Tcl_VarEval(interp, "append qmg_library", " /tcl", 0); returncode = TCL_OK; } return returncode;} extern "C" { // ------------------------------------------------------------------ // This Tcl function enables string rep for brep and simplicial // complexes. If string rep is not enabled, then an attempt // to convert to a string trashes the object. static int gm_enable_string_rep(ClientData, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[]) { if (objc != 2) { Tcl_WrongNumArgs(interp, 1, objv, "<int>"); return TCL_ERROR; } int v; int returncode = Tcl_GetIntFromObj(interp, objv[1], &v); if (returncode != TCL_OK) return returncode; if (v != 0 && v != 1) { interp -> result = "Argument to gm_enable_string_rep must be 0 or 1"; return TCL_ERROR; } if (v == 1) enable_string_rep = true; else enable_string_rep = false; return TCL_OK; } // ------------------------------------------------------------------ // Routine to free the internal rep of a brep. static void BrepFreeInternalRep(Tcl_Obj* obj) {#ifdef DEBUGGING if (obj -> typePtr != &brep_type) QMG::throw_error("BrepFreeInternalRep called on non-brep");#endif Cptc_GeomDesc* geo = static_cast<Cptc_GeomDesc*>(obj -> internalRep.otherValuePtr); cptc_free_geo(geo); return; } // ------------------------------------------------------------------ // Routine to free the internal rep of a mesh. static void SimpCompFreeInternalRep(Tcl_Obj* obj) {#ifdef DEBUGGING if (obj -> typePtr != &simpcomp_type) QMG::throw_error("SimpCompFreeInternalRep called on non-simpcomp");#endif Cptc_MshDesc* msh = static_cast<Cptc_MshDesc*>(obj -> internalRep.otherValuePtr); cptc_free_mesh(msh); return; } // ------------------------------------------------------------------ // Routine to clone a brep. static void BrepDupInternalRep(Tcl_Obj* src, Tcl_Obj* dest) {#ifdef DEBUGGING if (src -> typePtr != &brep_type) QMG::throw_error("BrepDupInternalRep called on non-brep");#endif Cptc_GeomDesc* srcgeo = static_cast<Cptc_GeomDesc*>(src -> internalRep.otherValuePtr); Cptc_GeomDesc* destgeo = cptc_clone_geo(srcgeo); dest -> internalRep.otherValuePtr = static_cast<void*>(destgeo); dest -> typePtr = &brep_type; } // ------------------------------------------------------------------ // Routine to clone a simplicial complex static void SimpCompDupInternalRep(Tcl_Obj* src, Tcl_Obj* dest) {#ifdef DEBUGGING if (src -> typePtr != &simpcomp_type) QMG::throw_error("SimpCompDupInternalRep called on non-simpcomp");#endif Cptc_MshDesc* srcmsh = static_cast<Cptc_MshDesc*>(src -> internalRep.otherValuePtr); Cptc_MshDesc* destmsh = cptc_clone_mesh(srcmsh); dest -> internalRep.otherValuePtr = static_cast<void*>(destmsh); dest -> typePtr = &simpcomp_type; } // ------------------------------------------------------------------ // Routine to compute the string rep of a brep. static void BrepUpdateStringRep(Tcl_Obj* obj) { using namespace QMG; #ifdef DEBUGGING if (obj -> typePtr != &brep_type) QMG::throw_error("BrepUpdateStringRep called on non-brep");#endif if (enable_string_rep) { Cptc_GeomDesc* geo = static_cast<Cptc_GeomDesc*>(obj -> internalRep.otherValuePtr); Brep_From_FrontEnd brep(geo); ostringstream ostr; ostr << static_cast<Brep&>(brep); string s(ostr.str()); const char* s1 = s.c_str(); int l = strlen(s1); obj -> bytes = static_cast<char*>(ckalloc((l + 1) * sizeof(char))); strcpy(obj -> bytes, s1); obj -> length = l; } else { const char* errmsg = "Brep_to_string_conversion_disabled"; int l = strlen(errmsg); obj -> bytes = static_cast<char*>(ckalloc((l + 1) * sizeof(char))); strcpy(obj -> bytes, errmsg); obj -> length = l; } } // ------------------------------------------------------------------ // Routine to compute the string rep of a mesh. static void SimpCompUpdateStringRep(Tcl_Obj* obj) { using namespace QMG; #ifdef DEBUGGING if (obj -> typePtr != &simpcomp_type) QMG::throw_error("SimpCompUpdateStringRep called on non-simpcomp");#endif if (enable_string_rep) { Cptc_MshDesc* msh = static_cast<Cptc_MshDesc*>(obj -> internalRep.otherValuePtr); SimpComplex_From_FrontEnd sc(msh); ostringstream ostr; ostr << static_cast<SimpComplex&>(sc); string s(ostr.str()); const char* s1 = s.c_str(); int l = strlen(s1); obj -> bytes = static_cast<char*>(ckalloc((l + 1) * sizeof(char))); strcpy(obj -> bytes, s1); obj -> length = l; } else { const char* errmsg = "SimpComp_to_string_conversion_disabled"; int l = strlen(errmsg); obj -> bytes = static_cast<char*>(ckalloc((l + 1) * sizeof(char))); strcpy(obj -> bytes, errmsg); obj -> length = l; } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?