1 // Copyright (C) 2010-2020 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 <PyInterp_Utils.h> // GUI - must come first to avoid conflict on the token "slots" defined in both Qt and Python ...
24 #include "test_curveplot.hxx"
28 #include "CurvePlot.hxx"
30 #include <PyInterp_Interp.h> // GUI
32 #include <QApplication>
33 #include <QDesktopWidget>
34 #include <QMainWindow>
37 #include <QVBoxLayout>
38 #include <QDockWidget>
39 #include <QPushButton>
41 using namespace CURVEPLOT;
43 /* The real test is in this function ! */
44 void TestCurvePlot::onClicked()
47 std::cout << "click\n" << std::endl;
49 /* Now the real test: */
50 // std::vector<double> x = {1.0,2.0,3.0,4.0,5.0,6.0,7.0};
51 std::vector<double> x;
52 for (int i=1; i <= 7; i++)
53 x.push_back(double(i));
54 //std::vector<double> y = {1.0,4.0,9.0,16.0,25.0,36.0,49.0};
55 std::vector<double> y;
56 for (int i=0; i < 7; i++)
57 y.push_back(double(i*i));
58 // std::vector<double> x(2000);
59 // std::vector<double> y(2000);
60 // for(int i = 0 ; i < x.size(); i++)
65 ColumnVector xx(ColumnVector::BuildFromStdVector(x));
66 ColumnVector yy(ColumnVector::BuildFromStdVector(y));
67 // std::string s = xx.toStdString();
68 // std::cout << "test xx: " << s << std::endl;
69 std::cout << "setting X label " << CurvePlot::SetXLabel("tôtô") << std::endl;
70 /*PlotID crv_id = */CurvePlot::AddCurve(xx, yy, ps_id, "the cérve", "th x", "the y-s", false);
71 std::cout << "setting X label " << CurvePlot::SetXLabel("tôtô") << std::endl;
75 * Similar to: SUIT_PYTHON::init_python() from GUI
76 * or KERNEL_PYTHON::init_python() from KERNEL
80 if (!Py_IsInitialized()){
81 // Python is not initialized
82 Py_Initialize(); // Initialize the interpreter
84 PyRun_SimpleString("import threading\n");
86 PyThreadState *pts = PyGILState_GetThisThreadState();
87 PyEval_ReleaseThread(pts);
91 /* Little hack to gather widgets created on the Python side */
92 void getWigdets(QApplication * app, QWidget *& crvBrowser, QWidget *& tabWidget)
94 QList<QWidget *> lst(app->topLevelWidgets());
97 foreach(QWidget * w, lst)
99 if (w->objectName() == QString("TabWidget"))
101 if (w->objectName() == QString("CurveTreeDockWidget"))
106 int main(int argc, char ** argv)
109 /* The below part is done automatically in SALOME context */
110 QApplication app (argc, argv);
111 QDesktopWidget * dw = app.desktop();
114 mw.resize((int)(dw->width()*0.25), (int)(dw->height()*0.7));
117 initPython(); // mimic SALOME Python's initialisation.
118 InitializeCurvePlot();
121 // Make sure the first instanciation of CurvePlot is made in test mode!
122 CurvePlot::ToggleCurveBrowser(false);
123 CurvePlot::GetInstance(true);
125 QWidget * crvBrowser = 0, * tabWidget = 0;
126 getWigdets(&app, crvBrowser, tabWidget);
127 QDockWidget * dock = new QDockWidget(&mw);
128 QPushButton * but = new QPushButton("Hello");
129 TestCurvePlot * t2d = new TestCurvePlot();
130 but->connect(but, SIGNAL(clicked()), t2d, SLOT(onClicked()));
131 QWidget * w = new QWidget(dock);
133 QVBoxLayout * vbl = new QVBoxLayout(w);
136 vbl->addWidget(crvBrowser);
137 mw.addDockWidget(Qt::LeftDockWidgetArea, dock);
138 mw.setCentralWidget(tabWidget);
144 Py_Finalize(); // must be after GIL release