Logo Search packages:      
Sourcecode: cantor version File versions  Download package

extension.cpp

/*
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA  02110-1301, USA.

    ---
    Copyright (C) 2009 Alexander Rieder <alexanderrieder@gmail.com>
 */

#include "extension.h"
using namespace Cantor;

#include <QStringList>

#define EXTENSION_CONSTRUCTORS(name) name::name(QObject* parent) : Extension(#name,parent) {} \
                                     name::~name() {}


00030 Extension::Extension(const QString& name, QObject* parent) : QObject(parent)
{
    setObjectName(name);
}

Extension::~Extension()
{

}

EXTENSION_CONSTRUCTORS(HistoryExtension)
EXTENSION_CONSTRUCTORS(ScriptExtension)
EXTENSION_CONSTRUCTORS(CASExtension)
EXTENSION_CONSTRUCTORS(CalculusExtension)
EXTENSION_CONSTRUCTORS(PlotExtension)
EXTENSION_CONSTRUCTORS(AdvancedPlotExtension)
EXTENSION_CONSTRUCTORS(LinearAlgebraExtension)
EXTENSION_CONSTRUCTORS(VariableManagementExtension)

//implement this here, as it's ";" most of the time
00050 QString ScriptExtension::commandSeparator()
{
    return ";\n";
}

//implement this here, as it's "#" most of the time
00056 QString ScriptExtension::commentStartingSequence()
{
    return "#";
}

//implement this here, as it's "" most of the time
00062 QString ScriptExtension::commentEndingSequence()
{
    return "";
}


//some convenience functions, but normally backends have a special command to create
//these matrices/vectors.

00071 QString LinearAlgebraExtension::nullVector(int size, VectorType type)
{
    QStringList values;
    for (int i=0;i<size;i++)
        values<<"0";
    return createVector(values, type);
}

00079 QString LinearAlgebraExtension::identityMatrix(int size)
{
    Matrix m;
    for(int i=0;i<size;i++)
    {
        QStringList column;
        for(int j=0;j<size;j++)
            column<<((i==j) ? "1": "0");

        m<<column;
    }

    return createMatrix(m);
}

00094 QString LinearAlgebraExtension::nullMatrix(int rows, int columns)
{
    Matrix m;
    for(int i=0;i<rows;i++)
    {
        QStringList column;
        for(int j=0;j<columns;j++)
            column<<"0";

        m<<column;
    }

    return createMatrix(m);
}

00109 QString AdvancedPlotExtension::plotFunction2d(const QString& expression, const QVector<PlotDirective*> directives) const
{
    QString params="";
    foreach (PlotDirective* dir, directives)
    {
        QString param=dispatchDirective(*dir);
        if (param.length()>0)
            params+=separatorSymbol()+param;
    }
    return plotCommand()+"("+expression+params+")";
}

00121 QString AdvancedPlotExtension::dispatchDirective(const PlotDirective& directive) const
{
    const AcceptorBase* acceptor=dynamic_cast<const AcceptorBase*>(this);
    if (acceptor==NULL)
    {
        kDebug()<<"Plotting extension does not support any directives, but was asked to process one";
        return "";
    }
    return directive.dispatch(*acceptor);
}

00132 QString AdvancedPlotExtension::separatorSymbol() const
{
    return ",";
}

00137 QWidget* AdvancedPlotExtension::PlotDirective::widget(QWidget* parent)
{
    return new QWidget(parent);
}

00142 AdvancedPlotExtension::PlotDirective::PlotDirective()
{
}

AdvancedPlotExtension::PlotDirective::~PlotDirective()
{
}

00150 AdvancedPlotExtension::AcceptorBase::AcceptorBase() : m_widgets()
{
}

AdvancedPlotExtension::AcceptorBase::~AcceptorBase()
{
}

00158 const QVector<AdvancedPlotExtension::AcceptorBase::widgetProc>& AdvancedPlotExtension::AcceptorBase::widgets() const
{
    return m_widgets;
}

AdvancedPlotExtension::DirectiveProducer::DirectiveProducer(QWidget* parent) : QWidget(parent)
{
}

Generated by  Doxygen 1.6.0   Back to index