File indexing completed on 2024-05-26 11:22:05

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-or-later
0003     SPDX-FileCopyrightText: 2009 Alexander Rieder <alexanderrieder@gmail.com>
0004     SPDX-FileCopyrightText: 2019 Alexander Semke <alexander.semke@web.de>
0005 */
0006 
0007 #include "maximabackend.h"
0008 #include "maximaextensions.h"
0009 #include "maximasession.h"
0010 #include "maximasettingswidget.h"
0011 #include "settings.h"
0012 
0013 #include <KPluginFactory>
0014 
0015 MaximaBackend::MaximaBackend( QObject* parent,const QList<QVariant> args ) : Cantor::Backend( parent,args )
0016 {
0017     //initialize the supported extensions
0018     new MaximaHistoryExtension(this);
0019     new MaximaScriptExtension(this);
0020     new MaximaCASExtension(this);
0021     new MaximaCalculusExtension(this);
0022     new MaximaLinearAlgebraExtension(this);
0023     new MaximaPlotExtension(this);
0024     new MaximaVariableManagementExtension(this);
0025 }
0026 
0027 MaximaBackend::~MaximaBackend()
0028 {
0029     qDebug()<<"Destroying MaximaBackend";
0030 }
0031 
0032 QString MaximaBackend::id() const
0033 {
0034     return QLatin1String("maxima");
0035 }
0036 
0037 QString MaximaBackend::version() const
0038 {
0039     return QLatin1String("5.41, 5.42");
0040 }
0041 
0042 Cantor::Session* MaximaBackend::createSession()
0043 {
0044     qDebug()<<"Spawning a new Maxima session";
0045 
0046     return new MaximaSession(this);
0047 }
0048 
0049 Cantor::Backend::Capabilities MaximaBackend::capabilities() const
0050 {
0051     Cantor::Backend::Capabilities cap =
0052         Cantor::Backend::LaTexOutput |
0053         Cantor::Backend::InteractiveMode|
0054         Cantor::Backend::SyntaxHighlighting|
0055         Cantor::Backend::Completion |
0056         Cantor::Backend::SyntaxHelp;
0057     if(MaximaSettings::self()->variableManagement())
0058         cap |= Cantor::Backend::VariableManagement;
0059 
0060     return cap;
0061 }
0062 
0063 bool MaximaBackend::requirementsFullfilled(QString* const reason) const
0064 {
0065     const QString& path = MaximaSettings::self()->path().toLocalFile();
0066     return Cantor::Backend::checkExecutable(QLatin1String("Maxima"), path, reason);
0067 }
0068 
0069 QUrl MaximaBackend::helpUrl() const
0070 {
0071     return QUrl(i18nc("the url to the documentation of Maxima, please check if there is a translated version and use the correct url",
0072             "http://maxima.sourceforge.net/docs/manual/en/maxima.html"));
0073 }
0074 
0075 QString MaximaBackend::defaultHelp() const
0076 {
0077     //taken from https://maxima.sourceforge.io/docs/manual/maxima_5.html
0078     //@tranlators: don't tranlate Maxima's keywords here ("describe", "true", "false", etc.) which are put inside of <i></i>
0079     return i18n("<h1>Maxima's Help System</h1>"
0080                 "<h2>Function <i>apropos</i></h2>"
0081                 "Searches for Maxima names which have name appearing anywhere within them; <i>name</i> must be a string or symbol. Thus, <i>apropos(exp)</i> returns a list of all the flags and functions which have exp as part of their name, such as <i>expand</i>, <i>exp</i>, and <i>exponentialize</i>. So, if you can only remember part of the name of a Maxima command or variable, you can use this command to find the rest of the name. Similarly, you can type <i>apropos(tr_)</i> to find a list of many of the switches relating to the translator, most of which begin with <i>tr_</i>.<br><br>"
0082                 "<i>apropos(\"\")</i> returns a list with all Maxima names.<br><br>"
0083                 "<i>apropos</i> returns the empty list [], if no name is found.<br><br>"
0084                 "<h2>Function <i>describe</i></h2>"
0085                 "<i>describe(string)</i> is equivalent to describe(string, exact).<br><br>"
0086                 "<i>describe(string, exact)</i> finds an item with title equal (case-insensitive) to string, if there is any such item.<br><br>"
0087                 "<i>describe(string, inexact)</i> finds all documented items which contain string in their titles. If there is more than one such item, Maxima asks the user to select an item or items to display.<br><br>"
0088                 "<i>? foo</i> (with a space between <i>?</i> and <i>foo</i>) is equivalent to <i>describe(\"foo\", exact)</i>, and <i>?? foo</i> is equivalent to <i>describe(\"foo\", inexact)</i>.<br><br>"
0089                 "<i>describe("", inexact)</i> yields a list of all topics documented in the on-line manual.<br><br>"
0090                 "<i>describe</i> quotes its argument. <i>describe</i> returns <i>true</i> if some documentation is found, otherwise <i>false</i>.<br>"
0091                 "<h2>Function <i>example</i></h2>"
0092                 "<i>example(topic)</i> displays some examples of <i>topic</i>, which is a symbol or a string. To get examples for operators like <i>if</i>, <i>do</i>, or <i>lambda</i> the argument must be a string, e.g. <i>example(\"do\")</i>. <i>example</i> is not case sensitive. Most topics are function names.<br><br>"
0093                 "<i>example()</i> returns the list of all recognized topics.<br><br>"
0094                 "The name of the file containing the examples is given by the global option variable <i>manual_demo</i>, which defaults to <i>\"manual.demo\"</i>.<br><br>"
0095                 "<i>example</i> quotes its argument. <i>example</i> returns <i>done</i> unless no examples are found or there is no argument, in which case <i>example</i> returns the list of all recognized topics."
0096                 );
0097 }
0098 
0099 QWidget* MaximaBackend::settingsWidget(QWidget* parent) const
0100 {
0101     return new MaximaSettingsWidget(parent, id());
0102 }
0103 
0104 KConfigSkeleton* MaximaBackend::config() const
0105 {
0106     return MaximaSettings::self();
0107 }
0108 
0109 QString MaximaBackend::description() const
0110 {
0111     return i18n("<b>Maxima</b> is a system for the manipulation of symbolic and numerical expressions, "\
0112                 "including differentiation, integration, Taylor series, Laplace transforms, "\
0113                 "ordinary differential equations, systems of linear equations, polynomials, and sets, "\
0114                 "lists, vectors, matrices, and tensors. Maxima yields high precision numeric results "\
0115                 "by using exact fractions, arbitrary precision integers, and variable precision "\
0116                 "floating point numbers. Maxima can plot functions and data in two and three dimensions.");
0117 }
0118 
0119 K_PLUGIN_FACTORY_WITH_JSON(maximabackend, "maximabackend.json", registerPlugin<MaximaBackend>();)
0120 #include "maximabackend.moc"