示例#1
0
int
Cad_AppInit(Tcl_Interp *interp)
{
/* Locate the BRL-CAD-specific Tcl scripts, set the auto_path */
    tclcad_auto_path(interp);

/* Initialize [incr Tcl] */
    /* NOTE: Calling "package require Itcl" here is apparently
     * insufficient without other changes elsewhere.  The Combination
     * Editor in mged fails with an iwidgets class already loaded
     * error if we don't perform Itcl_Init() here.
     */
    if (Itcl_Init(interp) == TCL_ERROR) {
	bu_log("Itcl_Init ERROR:\n%s\n", Tcl_GetStringResult(interp));
	return TCL_ERROR;
    }

#ifdef BWISH
/* Initialize [incr Tk] */
    if (Itk_Init(interp) == TCL_ERROR) {
	bu_log("Itk_Init ERROR:\n%s\n", Tcl_GetStringResult(interp));
	return TCL_ERROR;
    }
#endif

#ifdef IMPORT_ITCL
/* Import [incr Tcl] commands into the global namespace. */
    if (Tcl_Import(interp, Tcl_GetGlobalNamespace(interp),
		   "::itcl::*", /* allowOverwrite */ 1) != TCL_OK) {
	bu_log("Tcl_Import ERROR:\n%s\n", Tcl_GetStringResult(interp));
	return TCL_ERROR;
    }
#endif /* IMPORT_ITCL */

#ifdef BWISH

#  ifdef IMPORT_ITK
/* Import [incr Tk] commands into the global namespace */
    if (Tcl_Import(interp, Tcl_GetGlobalNamespace(interp),
		   "::itk::*", /* allowOverwrite */ 1) != TCL_OK) {
	bu_log("Tcl_Import ERROR:\n%s\n", Tcl_GetStringResult(interp));
	return TCL_ERROR;
    }
#  endif  /* IMPORT_ITK */

/* Initialize the Iwidgets package */
    if (Tcl_Eval(interp, "package require Iwidgets") != TCL_OK) {
	bu_log("Tcl_Eval ERROR:\n%s\n", Tcl_GetStringResult(interp));
	return TCL_ERROR;
    }

#  ifdef IMPORT_IWIDGETS
/* Import iwidgets into the global namespace */
    if (Tcl_Import(interp, Tcl_GetGlobalNamespace(interp),
		   "::iwidgets::*", /* allowOverwrite */ 1) != TCL_OK) {
	bu_log("Tcl_Import ERROR:\n%s\n", Tcl_GetStringResult(interp));
	return TCL_ERROR;
    }
#  endif  /* IMPORT_IWIDGETS */

#endif  /* BWISH */

#  ifdef IMPORT_ITCL
    if (Tcl_Eval(interp, "auto_mkindex_parser::slavehook { _%@namespace import -force ::itcl::* }") != TCL_OK) {
	bu_log("Tcl_Eval ERROR:\n%s\n", Tcl_GetStringResult(interp));
	return TCL_ERROR;
    }
#  endif

#ifdef BWISH
#  ifdef IMPORT_ITCL
    if (Tcl_Eval(interp, "auto_mkindex_parser::slavehook { _%@namespace import -force ::tk::* }") != TCL_OK) {
	bu_log("Tcl_Eval ERROR:\n%s\n", Tcl_GetStringResult(interp));
	return TCL_ERROR;
    }
#  endif
#  ifdef IMPORT_ITK
    if (Tcl_Eval(interp, "auto_mkindex_parser::slavehook { _%@namespace import -force ::itk::* }") != TCL_OK) {
	bu_log("Tcl_Eval ERROR:\n%s\n", Tcl_GetStringResult(interp));
	return TCL_ERROR;
    }
#  endif

/* Initialize libdm */
    if (Dm_Init(interp) == TCL_ERROR) {
	bu_log("Dm_Init ERROR:\n%s\n", Tcl_GetStringResult(interp));
	return TCL_ERROR;
    }

/* Initialize libfb */
    if (Fb_Init(interp) == TCL_ERROR) {
	bu_log("Fb_Init ERROR:\n%s\n", Tcl_GetStringResult(interp));
	return TCL_ERROR;
    }
#endif

/* Initialize libbu */
    if (Bu_Init(interp) == TCL_ERROR) {
	bu_log("Bu_Init ERROR:\n%s\n", Tcl_GetStringResult(interp));
	return TCL_ERROR;
    }

/* Initialize libbn */
    if (Bn_Init(interp) == TCL_ERROR) {
	bu_log("Bn_Init ERROR:\n%s\n", Tcl_GetStringResult(interp));
	return TCL_ERROR;
    }

/* Initialize librt */
    if (Rt_Init(interp) == TCL_ERROR) {
	bu_log("Rt_Init ERROR:\n%s\n", Tcl_GetStringResult(interp));
	return TCL_ERROR;
    }

    /* Initialize libtclcad's GED Object */
    if (Go_Init(interp) == TCL_ERROR) {
	bu_log("Go_Init ERROR:\n%s\n", Tcl_GetStringResult(interp));
	return TCL_ERROR;
    }

    /* Initialize command history object */
    Cho_Init(interp);

    return TCL_OK;
}
static AP_Result tk_new(AP_World *w, AP_Obj interp_name)
{
	AP_Result result;
	Tcl_Interp *interp;
	
	result = built_interp(w, &interp, &interp_name);

	// Similar to 2009 note above, this cause Tk_Init to fail (tk.tcl not found)
#if 0
	{
		Tcl_DString path;
		const char *elements[3];
		Tcl_DStringInit(&path);
		elements[0] = library_dir;
#ifdef macintosh
		elements[1] = "Tool Command Language";
#else
		elements[1] = "lib";
#endif
		elements[2] = "tk" TK_VERSION;
		Tcl_JoinPath(3, elements, &path);
		Tcl_SetVar(interp, (char *)"tk_library", path.string, TCL_GLOBAL_ONLY);
		Tcl_DStringFree(&path);
	}
#endif

	if (result == AP_SUCCESS) {
		int r = Tk_Init(interp);
		if (r != TCL_OK) {
			TclToPrologResult(w, NULL, interp, r);
			return AP_EXCEPTION;
		}


#ifdef ITCL
		r = Itk_Init(interp);
		if (r != TCL_OK) {
		  TclToPrologResult(w, NULL, interp, r);
		  return AP_EXCEPTION;
		}
		Tcl_StaticPackage(interp, (char *)"Itk", Itk_Init, (Tcl_PackageInitProc *) NULL);
		r = Tcl_Import(interp, Tcl_GetGlobalNamespace(interp),
			       (char *)"::itk::*", /* allowOverwrite */ 1);
		if (r != TCL_OK) {
		  TclToPrologResult(w, NULL, interp, r);
		  return AP_EXCEPTION;
		}

		r = Tcl_Eval(interp, (char *)"auto_mkindex_parser::slavehook { _%@namespace import -force ::itcl::* ::itk::* }");
		if (r != TCL_OK) {
		  TclToPrologResult(w, NULL, interp, r);
		  return AP_EXCEPTION;
		}
#endif

		/*Tcl_StaticPackage(interp, "Tk", Tk_Init, Tk_SafeInit);*/

	#ifdef macintosh
		//TkMacInitAppleEvents(interp);
		//TkMacInitMenus(interp);

		//Tcl_SetVar(interp, "tcl_rcRsrcName", "tclshrc", TCL_GLOBAL_ONLY);
	#endif		
	}
	
	return result;
}