File indexing completed on 2024-04-21 03:40:36

0001 /*************************************************************************************
0002  *  Copyright (C) 2010-2012 by Percy Camilo T. Aucahuasi <percy.camilo.ta@gmail.com> * 
0003  *                                                                                   *
0004  *  This program is free software; you can redistribute it and/or                    *
0005  *  modify it under the terms of the GNU General Public License                      *
0006  *  as published by the Free Software Foundation; either version 2                   *
0007  *  of the License, or (at your option) any later version.                           *
0008  *                                                                                   *
0009  *  This program is distributed in the hope that it will be useful,                  *
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of                   *
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                    *
0012  *  GNU General Public License for more details.                                     *
0013  *                                                                                   *
0014  *  You should have received a copy of the GNU General Public License                *
0015  *  along with this program; if not, write to the Free Software                      *
0016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA   *
0017  *************************************************************************************/
0018 
0019 #include <QMainWindow>
0020 #include <QTreeView>
0021 #include <QSplitter>
0022 #include <QVBoxLayout>
0023 #include <QStatusBar>
0024 #include <QApplication>
0025 
0026 #include "analitzaplot/surface.h"
0027 #include "analitzaplot/spacecurve.h"
0028 #include "analitzaplot/plotsmodel.h"
0029 #include "plotsview3d_es.h"
0030 #include <plotsfactory.h>
0031 #include <analitza/expression.h>
0032 #include <QCommandLineParser>
0033 
0034 using namespace Analitza;
0035 
0036 int main(int argc, char *argv[])
0037 {
0038     QApplication app(argc, argv);
0039     app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
0040     QCommandLineParser parser;
0041     parser.setApplicationDescription(QStringLiteral("PlotView3DTest"));
0042     parser.addOption(QCommandLineOption(QStringLiteral("all-disabled"), app.tr("marks all the plots as not visible")));
0043     parser.addOption(QCommandLineOption(QStringLiteral("simple-rotation"), app.tr("doesn't let you rotate the Z axis")));
0044     parser.addHelpOption();
0045     parser.process(app);
0046 
0047     QMainWindow *mainWindow = new QMainWindow();
0048     mainWindow->setMinimumSize(640, 480);
0049     mainWindow->statusBar()->show();
0050 
0051     QSplitter *central = new QSplitter(Qt::Horizontal, mainWindow);
0052     central->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
0053 
0054     PlotsModel *model = new PlotsModel(central);
0055 
0056     QTreeView *viewsource = new QTreeView(central);
0057     viewsource->setModel(model);
0058 
0059     //BEGIN test calls
0060     PlotsFactory* s = PlotsFactory::self();
0061     model->addPlot(s->requestPlot(Analitza::Expression(QStringLiteral("t->vector{cos(t), sin(t), t}")), Dim3D).create(Qt::green, QStringLiteral("curve")));
0062     model->addPlot(s->requestPlot(Analitza::Expression(QStringLiteral("t->vector {t,t**2,t}")), Dim3D).create(Qt::green, QStringLiteral("parametric")));
0063     model->addPlot(s->requestPlot(Analitza::Expression(QStringLiteral("(t,p)->2")), Dim3D).create(Qt::darkGreen, QStringLiteral("sphere-sphcoords")));
0064     model->addPlot(s->requestPlot(Analitza::Expression(QStringLiteral("(r,p)->p")), Dim3D).create(Qt::magenta, QStringLiteral("cyl")));
0065     model->addPlot(s->requestPlot(Analitza::Expression(QStringLiteral("piecewise{(x^2 + y^2 +z^2 < 35)?2 - (cos(x + (1+power(5,0.5))/2*y) + cos(x - (1+power(5,0.5))/2*y) + cos(y + (1+power(5,0.5))/2*z) + cos(y - (1+power(5,0.5))/2*z) + cos(z - (1+power(5,0.5))/2*x) + cos(z + (1+power(5,0.5))/2*x)),?1}=0")), Dim3D).create(QColor(40, 87, 159), QStringLiteral("complex")));
0066     model->addPlot(s->requestPlot(Analitza::Expression(QStringLiteral("(x^2 + y^2 - 1) * ( x^2 + z^2 - 1) = 1")), Dim3D).create(Qt::cyan, QStringLiteral("implicit 0")));
0067     model->addPlot(s->requestPlot(Analitza::Expression(QStringLiteral("(x,y)->(x*x-y*y)/8")), Dim3D).create(Qt::yellow, QStringLiteral("z-map")));
0068     model->addPlot(s->requestPlot(Analitza::Expression(QStringLiteral("x*x+y*y-z*z= 1/2")), Dim3D).create(Qt::darkBlue, QStringLiteral("implicit 2")));
0069     //END test calls
0070 
0071     if(parser.isSet(QStringLiteral("all-disabled")))
0072         for(int i=0; i<model->rowCount(); i++)
0073             model->setData(model->index(i), false, Qt::CheckStateRole);
0074 
0075 
0076     central->addWidget(viewsource);
0077     PlotsView3DES *view3des = new PlotsView3DES(central);
0078     view3des->setSelectionModel(viewsource->selectionModel());
0079     view3des->setUseSimpleRotation(parser.isSet(QStringLiteral("simple-rotation")));
0080     view3des->setModel(model);
0081     central->addWidget(view3des);
0082     view3des->setFocus();
0083 
0084     central->setStretchFactor(1, 2);
0085     mainWindow->setCentralWidget(central);
0086     mainWindow->show();
0087 
0088     return app.exec();
0089 }