VariableType ScilabJavaEnvironmentWrapper::isunwrappable(int id) const { JavaVM * vm = getScilabJavaVM(); int type = ScilabJavaObject::isUnwrappable(vm, id); return (VariableType)type; }
/* ** Register ScilabView to Controller. ** Must be done after Graphics models are created. */ void ScilabView::registerToController(void) { org_scilab_modules_graphic_objects::CallGraphicController::registerScilabView(getScilabJavaVM()); m_figureList.get_allocator().allocate(4096); m_handleList.get_allocator().allocate(4096); m_uidList.get_allocator().allocate(4096); }
/*--------------------------------------------------------------------------*/ BOOL ExecuteInitialHooks(void) { JNIEnv * currentENV = getScilabJNIEnv(); JavaVM * currentJVM = getScilabJavaVM(); jint result = (*currentJVM)->AttachCurrentThread(currentJVM, (void **) ¤tENV, NULL) ; if (result == 0) { jclass cls = NULL; cls = (*currentENV)->FindClass(currentENV, "org/scilab/modules/core/Scilab"); catchIfJavaException(_("Could not access to the Main Scilab Class:\n")); if (cls) { jmethodID mid = NULL; mid = (*currentENV)->GetStaticMethodID(currentENV, cls, "executeInitialHooks", "()V"); if (mid) { (*currentENV)->CallStaticVoidMethod(currentENV, cls, mid); } catchIfJavaException(_("Cannot execute initial hooks. Error:\n")); return TRUE; } } return FALSE; }
/*--------------------------------------------------------------------------*/ int sci_getlookandfeel(char *fname, void* pvApiCtx) { CheckInputArgument(pvApiCtx, 0, 0); CheckOutputArgument(pvApiCtx, 1, 1); org_scilab_modules_gui_utils::LookAndFeelManager * lnf = 0; try { lnf = new org_scilab_modules_gui_utils::LookAndFeelManager(getScilabJavaVM()); } catch (const GiwsException::JniException & e) { Scierror(999, _("%s: A Java exception arisen:\n%s"), fname, e.whatStr().c_str()); return 1; } if (lnf) { static int n1 = 0, m1 = 0; char *look = lnf->getCurrentLookAndFeel(); if (look) { m1 = (int)strlen(look); n1 = 1; if (createSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, look)) { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } if (look) { delete[]look; look = NULL; } delete lnf; AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else { delete lnf; Scierror(999, _("%s: An error occurred: %s.\n"), fname, _("Impossible to get current look and feel")); return 1; } } else { Scierror(999, _("%s: No more memory.\n"), fname); return 1; } return 0; }
int ScilabJavaEnvironmentWrapper::wrap(char * x, const bool isRef) const { JavaVM * vm = getScilabJavaVM(); if (isRef) { return wrapAsDirectBuffer(vm, x, 1); } return wrap(vm, (byte *)x); }
int ScilabJavaEnvironmentWrapper::wrap(double * x, int xSize, int xSizeCol, const bool isRef) const { JavaVM * vm = getScilabJavaVM(); if (isRef) { return wrapAsDirectBuffer(vm, x, xSize * xSizeCol); } return wrap(vm, x, xSize, xSizeCol); }
int ScilabJavaEnvironmentWrapper::wrapBool(int * x, int xSize, const bool isRef) const { JavaVM * vm = getScilabJavaVM(); if (isRef) { return wrapAsDirectBuffer(vm, x, xSize); } return wrap<int, bool>(vm, x, xSize); }
int ScilabJavaEnvironmentWrapper::wrap(unsigned long long * x, int xSize, const bool isRef) const { JavaVM * vm = getScilabJavaVM(); if (isRef) { return wrapAsDirectBuffer(vm, (long long *)x, xSize); } return wrap(vm, (long long *)x, xSize); }
int ScilabJavaEnvironmentWrapper::wrap(unsigned char * x, int xSize, int xSizeCol, const bool isRef) const { JavaVM * vm = getScilabJavaVM(); if (isRef) { return wrapAsDirectBuffer(vm, (char *)x, xSize * xSizeCol); } return wrap(vm, (byte *)x, xSize, xSizeCol); }
int ScilabJavaEnvironmentWrapper::wrap(unsigned int * x, const bool isRef) const { JavaVM * vm = getScilabJavaVM(); if (isRef) { return wrapAsDirectBuffer(vm, (int *)x, 1); } return wrap(vm, (int *)x); }
/*---------------------------------------------------------------------------------*/ char * exportToFile(char * figureUID, const char * fileName, ExportFileType fileType, const float jpegCompressionQuality, ExportOrientation orientation) { return org_scilab_modules_graphic_export::FileExporter::fileExport(getScilabJavaVM(), figureUID, (char *)fileName, fileType, jpegCompressionQuality, orientation); }
/*--------------------------------------------------------------------------*/ int sci_xinit(char * fname, void *pvApiCtx) { SciErr err; int * addr = 0; char * path = 0; char * realPath = 0; CheckInputArgument(pvApiCtx, 1, 1); err = getVarAddressFromPosition(pvApiCtx, 1, &addr); if (err.iErr) { printError(&err, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (!isStringType(pvApiCtx, addr) || !checkVarDimension(pvApiCtx, addr, 1, 1)) { Scierror(999, gettext("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1); return 0; } if (getAllocatedSingleString(pvApiCtx, addr, &path) != 0) { Scierror(999, _("%s: No more memory.\n"), fname); return 0; } realPath = expandPathVariable(path); if (realPath) { org_scilab_modules_graphic_export::Driver::setPath(getScilabJavaVM(), realPath); FREE(realPath); } else { Scierror(999, _("%s: Invalid path: %s.\n"), fname, path); return 0; } freeAllocatedSingleString(path); LhsVar(1) = 0; PutLhsVar(); return 0; }
void ScilabJavaEnvironmentWrapper::unwrapstring(int id, const ScilabStringStackAllocator & allocator) const { JNIEnv * curEnv = NULL; JavaVM * vm = getScilabJavaVM(); vm->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL); jstring res = static_cast<jstring>(curEnv->CallStaticObjectMethod(ScilabJavaObjectClass_, unwrapStringID_ , id)); char * addr = const_cast<char *>(curEnv->GetStringUTFChars(res, 0)); allocator.allocate(1, 1, &addr); curEnv->ReleaseStringUTFChars(res, addr); curEnv->DeleteLocalRef(res); if (curEnv->ExceptionCheck()) { throw GiwsException::JniCallMethodException(curEnv); } }
void ScilabJavaEnvironmentWrapper::unwraprowstring(int id, const ScilabStringStackAllocator & allocator) const { JNIEnv * curEnv = NULL; JavaVM * vm = getScilabJavaVM(); vm->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL); jobjectArray res = static_cast<jobjectArray>(curEnv->CallStaticObjectMethod(ScilabJavaObjectClass_, unwrapRowStringID_ , id)); if (curEnv->ExceptionCheck()) { throw GiwsException::JniCallMethodException(curEnv); } jint lenRow = curEnv->GetArrayLength(res); jboolean isCopy = JNI_FALSE; char ** addr = new char*[lenRow]; jstring * resString = new jstring[lenRow]; for (jsize i = 0; i < lenRow; i++) { resString[i] = reinterpret_cast<jstring>(curEnv->GetObjectArrayElement(res, i)); addr[i] = const_cast<char *>(curEnv->GetStringUTFChars(resString[i], &isCopy)); } allocator.allocate(1, lenRow, addr); for (jsize i = 0; i < lenRow; i++) { curEnv->ReleaseStringUTFChars(resString[i], addr[i]); curEnv->DeleteLocalRef(resString[i]); } delete[] addr; delete[] resString; curEnv->DeleteLocalRef(res); if (curEnv->ExceptionCheck()) { throw GiwsException::JniCallMethodException(curEnv); } }
/*--------------------------------------------------------------------------*/ types::Function::ReturnValue sci_notify(types::typed_list &in, int _iRetCount, types::typed_list &out) { types::String* pString = NULL; wchar_t* wcsInput = NULL; if (in.size() != 1) { Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), "notify" , 1); return types::Function::Error; } if (in[0]->isString() == false) { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), "notify", 1); return types::Function::Error; } pString = in[0]->getAs<types::String>(); if (pString->isScalar() == FALSE) { Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), "notify" , 1); return types::Function::Error; } wcsInput = pString->get(0); char* strInput = wide_string_to_UTF8(wcsInput); try { org_scilab_modules_action_binding_utils::Signal::notify(getScilabJavaVM(), strInput); } catch (const GiwsException::JniException & e) { Scierror(999, _("%s: A Java exception arisen:\n%s"), "notify", e.whatStr().c_str()); FREE(strInput); return types::Function::Error; } FREE(strInput); return types::Function::OK; }
void ScilabJavaEnvironmentWrapper::unwrapmatshort(int id, const ScilabShortStackAllocator & allocator) const { JavaVM * vm = getScilabJavaVM(); unwrapMat<jshort, short>(vm, id, allocator); }
int ScilabJavaEnvironmentWrapper::wrap(char ** x, int xSize, int xSizeCol, const bool isRef) const { JavaVM * vm = getScilabJavaVM(); return wrap(vm, (char const**)x, xSize, xSizeCol); }
/*--------------------------------------------------------------------------*/ int sci_buildDoc(char *fname, void* pvApiCtx) { std::string exportFormat; std::string SciPath = getSCI(); /* Scilab path */ std::string masterXML; /* Which file contains all the doc stuff */ std::string masterXMLTMP; std::string outputDirectory; /* Working directory */ std::string outputDirectoryTMP; std::string language; std::string styleSheet; /* the CSS */ char * fileToExec = NULL; SciErr sciErr; int *piAddr = NULL; int iRet = 0; CheckRhs(0, 4); CheckLhs(1, 1); styleSheet = SciPath + PATHTOCSS; if (Rhs < 1) { exportFormat = DEFAULTEXPORT; } else { char* pstData = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (!isStringType(pvApiCtx, piAddr)) { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1); return 0; // Wrong type string } iRet = getAllocatedSingleString(pvApiCtx, piAddr, &pstData); if (iRet) { freeAllocatedSingleString(pstData); return iRet; } exportFormat = std::string(pstData); freeAllocatedSingleString(pstData); } if (Rhs < 3) /* Language not provided */ { wchar_t* l = getlanguage(); language = wide_string_to_UTF8(l); free(l); } else { char* pstData = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 3); return 0; } if (!isStringType(pvApiCtx, piAddr)) { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 3); return 0; // Wrong type string } if (!isScalar(pvApiCtx, piAddr)) { wchar_t* pwstLang = getlanguage(); language = wide_string_to_UTF8(pwstLang); free(pwstLang); } else { iRet = getAllocatedSingleString(pvApiCtx, piAddr, &pstData); if (iRet) { freeAllocatedSingleString(pstData); return iRet; } language = std::string(pstData); freeAllocatedSingleString(pstData); } } if (Rhs < 2) { /* Update the path with the localization */ masterXMLTMP = std::string("/modules/helptools/master_") + language + std::string("_help.xml"); masterXML = SciPath + masterXMLTMP; } else { char* pstData = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); return 0; } if (!isStringType(pvApiCtx, piAddr)) { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 2); return 0; // Wrong type string } iRet = getAllocatedSingleString(pvApiCtx, piAddr, &pstData); if (iRet) { freeAllocatedSingleString(pstData); return iRet; } masterXML = std::string(pstData); freeAllocatedSingleString(pstData); } if (Rhs == 4) { char* pstData = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 4); return 0; } if (!isStringType(pvApiCtx, piAddr)) { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 4); return 0; // Wrong type string } iRet = getAllocatedSingleString(pvApiCtx, piAddr, &pstData); if (iRet) { freeAllocatedSingleString(pstData); return iRet; } outputDirectory = std::string(pstData) + std::string("/scilab_") + language + std::string("_help/"); freeAllocatedSingleString(pstData); } else /* Scilab help */ { /* Update the path with the localization */ if (exportFormat != "jar-only") { outputDirectoryTMP = std::string("/modules/helptools/") + std::string(exportFormat) + std::string("/scilab_") + language + std::string("_help/"); } else { outputDirectoryTMP = std::string("/modules/helptools/") + std::string("javaHelp") + std::string("/scilab_") + language + std::string("_help/"); } outputDirectory = SciPath + outputDirectoryTMP; } #ifdef _MSC_VER __slashToAntislash(&outputDirectory); __slashToAntislash(&styleSheet); __slashToAntislash(&masterXML); #endif try { org_scilab_modules_helptools::SciDocMain * doc = new org_scilab_modules_helptools::SciDocMain(getScilabJavaVM()); if (doc->setOutputDirectory((char *)outputDirectory.c_str())) { doc->setWorkingLanguage((char *)language.c_str()); doc->setExportFormat((char *)exportFormat.c_str()); doc->setIsToolbox(Rhs == 4); fileToExec = doc->process((char *)masterXML.c_str(), (char *)styleSheet.c_str()); } else { Scierror(999, _("%s: Could find or create the working directory %s.\n"), fname, outputDirectory.c_str()); return FALSE; } if (doc != NULL) { delete doc; } } catch (GiwsException::JniException ex) { Scierror(999, _("%s: Error while building documentation: %s.\n"), fname, ex.getJavaDescription().c_str()); Scierror(999, _("%s: Execution Java stack: %s.\n"), fname, ex.getJavaStackTrace().c_str()); Scierror(999, _ ("If Scilab is started in a chroot, you might want to try to set the two environment variables: SCI_DISABLE_TK=1 SCI_JAVA_ENABLE_HEADLESS=1\n")); return FALSE; } if (fileToExec) { createMatrixOfString(pvApiCtx, Rhs + 1, 1, 1, &fileToExec); delete [] fileToExec; } else { createEmptyMatrix(pvApiCtx, Rhs + 1); } LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }
int ScilabJavaEnvironmentWrapper::wrapFloat(double * x, int xSize, int xSizeCol, const bool isRef) const { JavaVM * vm = getScilabJavaVM(); return wrap<double, float>(vm, x, xSize, xSizeCol); }
void ScilabJavaEnvironmentWrapper::unwrapmatfloat(int id, const ScilabFloatStackAllocator & allocator) const { JavaVM * vm = getScilabJavaVM(); unwrapMat<jfloat, double, float>(vm, id, allocator); }
void ScilabJavaEnvironmentWrapper::unwrapmatstring(int id, const ScilabStringStackAllocator & allocator) const { JNIEnv * curEnv = NULL; JavaVM * vm = getScilabJavaVM(); vm->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL); jobjectArray res = static_cast<jobjectArray>(curEnv->CallStaticObjectMethod(ScilabJavaObjectClass_, unwrapMatStringID_, id)); if (curEnv->ExceptionCheck()) { throw GiwsException::JniCallMethodException(curEnv); } jint lenRow = curEnv->GetArrayLength(res); jboolean isCopy = JNI_FALSE; jobjectArray oneDim = reinterpret_cast<jobjectArray>(curEnv->GetObjectArrayElement(res, 0)); jint lenCol = curEnv->GetArrayLength(oneDim); char ** addr = new char*[lenRow * lenCol]; jstring * resString = new jstring[lenRow * lenCol]; for (int i = 0; i < lenRow; i++) { oneDim = reinterpret_cast<jobjectArray>(curEnv->GetObjectArrayElement(res, i)); if (helper.getMethodOfConv()) { for (int j = 0; j < lenCol; j++) { resString[j * lenRow + i] = reinterpret_cast<jstring>(curEnv->GetObjectArrayElement(oneDim, j)); addr[j * lenRow + i] = const_cast<char *>(curEnv->GetStringUTFChars(resString[j * lenRow + i], &isCopy)); } } else { for (int j = 0; j < lenCol; j++) { resString[i * lenCol + j] = reinterpret_cast<jstring>(curEnv->GetObjectArrayElement(oneDim, j)); addr[i * lenCol + j] = const_cast<char *>(curEnv->GetStringUTFChars(resString[i * lenCol + j], &isCopy)); } } curEnv->DeleteLocalRef(oneDim); } if (helper.getMethodOfConv()) { allocator.allocate(lenRow, lenCol, addr); } else { allocator.allocate(lenCol, lenRow, addr); } for (int i = 0; i < lenRow * lenCol; i++) { curEnv->ReleaseStringUTFChars(resString[i], addr[i]); curEnv->DeleteLocalRef(resString[i]); } delete[] addr; delete[] resString; curEnv->DeleteLocalRef(res); if (curEnv->ExceptionCheck()) { throw GiwsException::JniCallMethodException(curEnv); } }
void ScilabJavaEnvironmentWrapper::unwrapmatboolean(int id, const ScilabBooleanStackAllocator & allocator) const { JavaVM * vm = getScilabJavaVM(); unwrapMat<jboolean, int, bool>(vm, id, allocator); }
void ScilabJavaEnvironmentWrapper::unwrapmatdouble(int id, const ScilabDoubleStackAllocator & allocator) const { JavaVM * vm = getScilabJavaVM(); unwrapMat<jdouble, double>(vm, id, allocator); }
void ScilabJavaEnvironmentWrapper::unwrapmatchar(int id, const ScilabCharStackAllocator & allocator) const { JavaVM * vm = getScilabJavaVM(); unwrapMat<jbyte, char>(vm, id, allocator); }
/*--------------------------------------------------------------------------*/ int sci_setlookandfeel(char *fname, unsigned long fname_len) { CheckRhs(0, 1); CheckLhs(0, 1); org_scilab_modules_gui_utils::LookAndFeelManager * lnf = 0; if (Rhs == 0) { try { lnf = new org_scilab_modules_gui_utils::LookAndFeelManager(getScilabJavaVM()); } catch (const GiwsException::JniException & e) { Scierror(999, _("%s: A Java exception arisen:\n%s"), fname, e.whatStr().c_str()); return FALSE; } if (lnf) { int n1 = 1; int *paramoutINT = (int *)MALLOC(sizeof(int)); *paramoutINT = (int)booltoBOOL(lnf->setSystemLookAndFeel()); delete lnf; n1 = 1; CreateVarFromPtr(Rhs + 1, const_cast<char *>(MATRIX_OF_BOOLEAN_DATATYPE), &n1, &n1, ¶moutINT); LhsVar(1) = Rhs + 1; if (paramoutINT) { FREE(paramoutINT); paramoutINT = NULL; } PutLhsVar(); } else { Scierror(999, _("%s: No more memory.\n"), fname); } } else if (GetType(1) == sci_strings) { int m1, n1 = 0, l1 = 0; char *looknfeel = NULL; GetRhsVar(1, const_cast<char *>(STRING_DATATYPE), &m1, &n1, &l1); looknfeel = cstk(l1); try { lnf = new org_scilab_modules_gui_utils::LookAndFeelManager(getScilabJavaVM()); } catch (const GiwsException::JniException & e) { Scierror(999, _("%s: A Java exception arisen:\n%s"), fname, e.whatStr().c_str()); return FALSE; } if (lnf) { int *paramoutINT = (int *)MALLOC(sizeof(int)); *paramoutINT = (int)booltoBOOL(lnf->setLookAndFeel(looknfeel)); delete lnf; n1 = 1; CreateVarFromPtr(Rhs + 1, const_cast<char *>(MATRIX_OF_BOOLEAN_DATATYPE), &n1, &n1, ¶moutINT); LhsVar(1) = Rhs + 1; if (paramoutINT) { FREE(paramoutINT); paramoutINT = NULL; } PutLhsVar(); } else { Scierror(999, _("%s: No more memory.\n"), fname); } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1); } return 0; }
/* ** Reove ScilabView from Controller. */ void ScilabView::unregisterToController(void) { org_scilab_modules_graphic_objects::CallGraphicController::unregisterScilabView(getScilabJavaVM()); }
void ScilabJavaEnvironmentWrapper::unwrapmatint(int id, const ScilabIntStackAllocator & allocator) const { JavaVM * vm = getScilabJavaVM(); unwrapMat<jint, int>(vm, id, allocator); }
/*--------------------------------------------------------------------------*/ int sci_getinstalledlookandfeels(char *fname, unsigned long fname_len) { SciErr sciErr; CheckInputArgument(pvApiCtx, 0, 0); CheckOutputArgument(pvApiCtx, 1, 1); org_scilab_modules_gui_utils::LookAndFeelManager * lnf = 0; try { lnf = new org_scilab_modules_gui_utils::LookAndFeelManager(getScilabJavaVM()); } catch (const GiwsException::JniException & e) { Scierror(999, _("%s: A Java exception arisen:\n%s"), fname, e.whatStr().c_str()); return 1; } if (lnf) { char **lookandfeels = NULL; int nbElems = 0; int nbCol = 0; lookandfeels = lnf->getInstalledLookAndFeels(); nbElems = lnf->numbersOfInstalledLookAndFeels(); nbCol = 1; sciErr = createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbElems, nbCol, lookandfeels); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } if (lookandfeels) { int i = 0; for (i = 0; i < nbElems; i++) { if (lookandfeels[i]) { delete[]lookandfeels[i]; } } delete[]lookandfeels; lookandfeels = NULL; } delete lnf; AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; returnArguments(pvApiCtx); } else { Scierror(999, _("%s: No more memory.\n"), fname); } return 0; }
void ScilabJavaEnvironmentWrapper::unwrapmatlong(int id, const ScilabLongStackAllocator & allocator) const { JavaVM * vm = getScilabJavaVM(); unwrapMat<jlong, int, long long>(vm, id, allocator); }