1 // Copyright (C) 2010-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Adrien BRUNETON
22 #include "test_curveplot.hxx"
24 #include <PyInterp_Utils.h> // GUI
27 #include "CurvePlot.hxx"
29 #include <PyInterp_Interp.h> // GUI
31 #include <QApplication>
32 #include <QDesktopWidget>
33 #include <QMainWindow>
36 #include <QVBoxLayout>
37 #include <QDockWidget>
38 #include <QPushButton>
40 using namespace CURVEPLOT;
42 /* The real test is in this function ! */
43 void TestCurvePlot::onClicked()
46 std::cout << "click\n" << std::endl;
48 /* Now the real test: */
49 // std::vector<double> x = {1.0,2.0,3.0,4.0,5.0,6.0,7.0};
50 std::vector<double> x;
51 for (int i=1; i <= 7; i++)
52 x.push_back(double(i));
53 //std::vector<double> y = {1.0,4.0,9.0,16.0,25.0,36.0,49.0};
54 std::vector<double> y;
55 for (int i=0; i < 7; i++)
56 y.push_back(double(i*i));
57 // std::vector<double> x(2000);
58 // std::vector<double> y(2000);
59 // for(int i = 0 ; i < x.size(); i++)
64 ColumnVector xx(ColumnVector::BuildFromStdVector(x));
65 ColumnVector yy(ColumnVector::BuildFromStdVector(y));
66 // std::string s = xx.toStdString();
67 // std::cout << "test xx: " << s << std::endl;
68 std::cout << "setting X label " << CurvePlot::SetXLabel("tôtô") << std::endl;
69 PlotID crv_id = CurvePlot::AddCurve(xx, yy, ps_id, "the cérve", "th x", "the y-s", false);
70 std::cout << "setting X label " << CurvePlot::SetXLabel("tôtô") << std::endl;
75 if (!Py_IsInitialized()){
76 // Python is not initialized
77 Py_Initialize(); // Initialize the interpreter
79 PyEval_InitThreads(); // Create (and acquire) the Python global interpreter lock (GIL)
84 /* Little hack to gather widgets created on the Python side */
85 void getWigdets(QApplication * app, QWidget *& crvBrowser, QWidget *& tabWidget)
87 QList<QWidget *> lst(app->topLevelWidgets());
90 foreach(QWidget * w, lst)
92 if (w->objectName() == QString("TabWidget"))
94 if (w->objectName() == QString("CurveTreeDockWidget"))
99 int main(int argc, char ** argv)
102 /* The below part is done automatically in SALOME context */
103 QApplication app (argc, argv);
104 QDesktopWidget * dw = app.desktop();
107 mw.resize((int)(dw->width()*0.25), (int)(dw->height()*0.7));
111 InitializeCurvePlot();
114 // Make sure the first instanciation of CurvePlot is made in test mode!
115 CurvePlot::ToggleCurveBrowser(false);
116 CurvePlot::GetInstance(true);
118 QWidget * crvBrowser = 0, * tabWidget = 0;
119 getWigdets(&app, crvBrowser, tabWidget);
120 QDockWidget * dock = new QDockWidget(&mw);
121 QPushButton * but = new QPushButton("Hello");
122 TestCurvePlot * t2d = new TestCurvePlot();
123 but->connect(but, SIGNAL(clicked()), t2d, SLOT(onClicked()));
124 QWidget * w = new QWidget(dock);
126 QVBoxLayout * vbl = new QVBoxLayout(w);
129 vbl->addWidget(crvBrowser);
130 mw.addDockWidget(Qt::LeftDockWidgetArea, dock);
131 mw.setCentralWidget(tabWidget);
137 Py_Finalize(); // must be after GIL release