From: rnv Date: Tue, 17 Jan 2012 09:33:05 +0000 (+0000) Subject: Fix remarks for the "0021383: [CEA 507] Plot2d Add analytic functions on curves"... X-Git-Tag: pxsxl1~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6fad14e92dfda30c10dd3fe34b592d521d2ead63;p=modules%2Fgui.git Fix remarks for the "0021383: [CEA 507] Plot2d Add analytic functions on curves" issue. --- diff --git a/doc/salome/gui/images/analytical_curves_dlg.png b/doc/salome/gui/images/analytical_curves_dlg.png new file mode 100755 index 000000000..6bddc84cc Binary files /dev/null and b/doc/salome/gui/images/analytical_curves_dlg.png differ diff --git a/doc/salome/gui/input/plot2d_viewer.doc b/doc/salome/gui/input/plot2d_viewer.doc index 17efc2c4c..1c664f75e 100644 --- a/doc/salome/gui/input/plot2d_viewer.doc +++ b/doc/salome/gui/input/plot2d_viewer.doc @@ -144,8 +144,37 @@ or ordinate) of all points displayed in the viewer is greater than zero. XY plots will be displayed with these defined properties.
+\anchor analytical_curve +\image html plot2d_analytical_curve.png +
Analytical curves - provides an access to the analytical curves dialog box, +that allows to add, remove and modify analytical curves for the Plot 2d Viewer.
+ +
+ +\image html analytical_curves_dlg.png + +The options are as follows:
+Curve parameters: + +Curve properties: + + +
+ \image html plot2d_clone.png
Clone view - opens a new duplicate scene.
+
\image html plot2d_print.png diff --git a/src/LightApp/LightApp_Plot2dSelector.cxx b/src/LightApp/LightApp_Plot2dSelector.cxx index 05b7c514d..88f4f9327 100755 --- a/src/LightApp/LightApp_Plot2dSelector.cxx +++ b/src/LightApp/LightApp_Plot2dSelector.cxx @@ -22,6 +22,7 @@ #include "LightApp_DataOwner.h" #include "LightApp_DataObject.h" #include "LightApp_Application.h" +#include "SUIT_SelectionMgr.h" #include @@ -36,6 +37,7 @@ LightApp_Plot2dSelector::LightApp_Plot2dSelector( Plot2d_Viewer* v, SUIT_Selecti { if ( v ) connect( v, SIGNAL( legendSelected( const QString& ) ), this, SLOT( onSelectionChanged( const QString& ) ) ); + connect( v, SIGNAL( clearSelected() ), this, SLOT( onClearSelected( ) ) ); } /*! @@ -81,3 +83,9 @@ void LightApp_Plot2dSelector::onSelectionChanged( const QString& entry ) selectionChanged(); myCurEntry = QString(); } + +/*!On clear selected.*/ +void LightApp_Plot2dSelector::onClearSelected( ) +{ + selectionMgr()->clearSelected(); +} \ No newline at end of file diff --git a/src/LightApp/LightApp_Plot2dSelector.h b/src/LightApp/LightApp_Plot2dSelector.h index 4032fa8ed..7a39fa04b 100755 --- a/src/LightApp/LightApp_Plot2dSelector.h +++ b/src/LightApp/LightApp_Plot2dSelector.h @@ -45,6 +45,7 @@ public: private slots: void onSelectionChanged( const QString& ); + void onClearSelected(); protected: virtual void getSelection( SUIT_DataOwnerPtrList& ) const; diff --git a/src/Plot2d/Plot2d_AnalyticalCurveDlg.cxx b/src/Plot2d/Plot2d_AnalyticalCurveDlg.cxx index a57dd27a7..580d5d68d 100755 --- a/src/Plot2d/Plot2d_AnalyticalCurveDlg.cxx +++ b/src/Plot2d/Plot2d_AnalyticalCurveDlg.cxx @@ -499,7 +499,7 @@ void Plot2d_AnalyticalCurveDlg::help() { SUIT_Application* app = SUIT_Session::session()->activeApplication(); if ( app ) - app->onHelpContextModule( "GUI", "plot2d_analytical_curves.html" ); + app->onHelpContextModule( "GUI", "plot2d_viewer_page.html", "analytical_curve" ); } /*! diff --git a/src/Plot2d/Plot2d_AnalyticalCurveDlg.h b/src/Plot2d/Plot2d_AnalyticalCurveDlg.h new file mode 100755 index 000000000..d49ff754d --- /dev/null +++ b/src/Plot2d/Plot2d_AnalyticalCurveDlg.h @@ -0,0 +1,129 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : Plot2d_AnalyticalCurveDlg.h +// Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com) + + +#ifndef PLOT2D_ANALYTICAL_CURVE_DLG_H +#define PLOT2D_ANALYTICAL_CURVE_DLG_H + +#include "Plot2d.h" +#include "Plot2d_AnalyticalCurve.h" + +#include +#include + +class QListWidget; +class QListWidgetItem; +class QGroupBox; +class QLineEdit; +class QCheckBox; +class QComboBox; +class QPushButton; + +class QtxIntSpinBox; +class QtxColorButton; +class QwtPlot; + +class Plot2d_AnalyticalCurve; +class Plot2d_CurveContainer; +class Plot2d_ViewFrame; + +class PLOT2D_EXPORT Plot2d_AnalyticalCurveDlg : public QDialog +{ + Q_OBJECT + + class Updater; + class UpdateLocker; + + enum { ItemExisting, ItemAdded, ItemRemoved }; + +public: + Plot2d_AnalyticalCurveDlg( Plot2d_CurveContainer*, QWidget* ); + ~Plot2d_AnalyticalCurveDlg(); + + void accept(); + void reject(); + +private: + + void init(); + void initPropsFromCurve(Plot2d_AnalyticalCurve*); + QListWidgetItem* selected() const; + Plot2d_AnalyticalCurve* selectedCurve() const; + QListWidgetItem* getItem(Plot2d_AnalyticalCurve*) const; + bool processCurves(); + QwtPlot* getPlot(); + int propStatus( Plot2d_AnalyticalCurve* = 0, const int def = ItemExisting ); + QString propTitle( Plot2d_AnalyticalCurve* = 0, const QString& def = "" ); + bool propVisible( Plot2d_AnalyticalCurve* = 0, bool def = true ); + QString propFormula( Plot2d_AnalyticalCurve* = 0, const QString& def = "" ); + int propIntervals( Plot2d_AnalyticalCurve* = 0, int def = 100 ); + Plot2d::MarkerType propMarkerType( Plot2d_AnalyticalCurve* = 0, Plot2d::MarkerType def = Plot2d::None ); + Plot2d::LineType propLineType( Plot2d_AnalyticalCurve* = 0, Plot2d::LineType def = Plot2d::NoPen ); + int propLineWidth( Plot2d_AnalyticalCurve* = 0, int def = 0 ); + QColor propColor( Plot2d_AnalyticalCurve* = 0, const QColor& def = QColor() ); + bool propAutoAssign( Plot2d_AnalyticalCurve* = 0, bool def = true ); + +private slots: + void addCurve(); + void removeCurve(); + void updateCurve(); + void updateState(); + void selectionChanged(); + void help(); + void apply(); + +private: + typedef QMap CurveProps; + typedef QMap PropMap; + + Plot2d_CurveContainer* myContainer; + PropMap myProperties; + Updater* myUpdater; + + QListWidget* myCurvesList; + QGroupBox* myCurveParams; + QLineEdit* myFormula; + QtxIntSpinBox* myNbIntervals; + QGroupBox* myCurveProps; + QCheckBox* myAutoAssign; + QWidget* myPropsGrp; + QComboBox* myMarkerType; + QComboBox* myLineType; + QtxIntSpinBox* myLineWidth; + QtxColorButton* myColor; + QPushButton* myAddButton; + QPushButton* myRemoveButton; +}; + +class Plot2d_AnalyticalCurveDlg::Updater : public QObject +{ + Q_OBJECT +public: + Updater( QWidget* parent ); + ~Updater(); +signals: + void update(); +}; + +#endif //PLOT2D_ANALYTICAL_CURVE_DLG_H diff --git a/src/Plot2d/Plot2d_AnalyticalParser.cxx b/src/Plot2d/Plot2d_AnalyticalParser.cxx new file mode 100755 index 000000000..f10a562f0 --- /dev/null +++ b/src/Plot2d/Plot2d_AnalyticalParser.cxx @@ -0,0 +1,276 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : Plot2d_AnalyticalParser.cxx +// Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com) +#include "Plot2d_AnalyticalParser.h" +#include + + +/* ================================== + * =========== PYTHON ============== + * ==================================*/ + +typedef struct { + PyObject_HEAD + int softspace; + std::string *out; + } PyStdOut; + +static void +PyStdOut_dealloc(PyStdOut *self) +{ + PyObject_Del(self); +} + +static PyObject * +PyStdOut_write(PyStdOut *self, PyObject *args) +{ + char *c; + int l; + if (!PyArg_ParseTuple(args, "t#:write",&c, &l)) + return NULL; + + //std::cerr << c ; + *(self->out)=*(self->out)+c; + + Py_INCREF(Py_None); + return Py_None; +} + +static PyMethodDef PyStdOut_methods[] = { + {"write", (PyCFunction)PyStdOut_write, METH_VARARGS, + PyDoc_STR("write(string) -> None")}, + {NULL, NULL} /* sentinel */ +}; + +static PyMemberDef PyStdOut_memberlist[] = { + {(char*)"softspace", T_INT, offsetof(PyStdOut, softspace), 0, + (char*)"flag indicating that a space needs to be printed; used by print"}, + {NULL} /* Sentinel */ +}; + +static PyTypeObject PyStdOut_Type = { + /* The ob_type field must be initialized in the module init function + * to be portable to Windows without using C++. */ + PyObject_HEAD_INIT(NULL) + 0, /*ob_size*/ + "PyOut", /*tp_name*/ + sizeof(PyStdOut), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor)PyStdOut_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + PyObject_GenericGetAttr, /*tp_getattro*/ + /* softspace is writable: we must supply tp_setattro */ + PyObject_GenericSetAttr, /* tp_setattro */ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT, /*tp_flags*/ + 0, /*tp_doc*/ + 0, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + PyStdOut_methods, /*tp_methods*/ + PyStdOut_memberlist, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + 0, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ +}; + +PyObject * newPyStdOut( std::string& out ) +{ + PyStdOut *self; + self = PyObject_New(PyStdOut, &PyStdOut_Type); + if (self == NULL) + return NULL; + self->softspace = 0; + self->out=&out; + return (PyObject*)self; +} + + +////////////////////////END PYTHON/////////////////////////// + + +//! The only one instance of Parser +Plot2d_AnalyticalParser* Plot2d_AnalyticalParser::myParser = 0; + +//Define the script +QString Plot2d_AnalyticalParser::myScript = QString(""); + +/*! + \brief Return the only instance of the Plot2d_AnalyticalParser + \return instance of the Plot2d_AnalyticalParser +*/ +Plot2d_AnalyticalParser* Plot2d_AnalyticalParser::parser() +{ + if ( !myParser ) + myParser = new Plot2d_AnalyticalParser(); + return myParser; +} + +/*! + \brief Constructor. + + Construct the Parser and initialize python interpritator. +*/ +Plot2d_AnalyticalParser::Plot2d_AnalyticalParser() +{ + /* Initialize the Python interpreter */ + if (Py_IsInitialized()) { + PyGILState_STATE gstate = PyGILState_Ensure(); + myMainMod = PyImport_AddModule("__main__"); + myMainDict = PyModule_GetDict(myMainMod); + PyGILState_Release(gstate); + initScript(); + } +} + +int Plot2d_AnalyticalParser::calculate( const QString& theExpr, + const double theMin, + const double theMax, + const int theNbStep, + double** theX, + double** theY) { + + QString aPyScript = myScript; + aPyScript = aPyScript.arg(theExpr); + int result = -1; + PyGILState_STATE gstate = PyGILState_Ensure(); + PyObject* obj = PyRun_String(qPrintable(aPyScript), Py_file_input, myMainDict, NULL); + + if(obj == NULL) { + PyErr_Print(); + PyGILState_Release(gstate); + return result; + + } else { + Py_DECREF(obj); + } + + PyObject* func = NULL; + PyObject* f_y = NULL; + + if(PyObject_HasAttrString(myMainMod, "Y")) { + f_y = PyObject_GetAttrString(myMainMod, "Y"); + } + + if(PyObject_HasAttrString(myMainMod, "coordCalculator")) { + func = PyObject_GetAttrString(myMainMod, "coordCalculator"); + } + + PyObject* new_stderr = NULL; + + if( f_y == NULL || func == NULL ) { + fflush(stderr); + std::string err_description=""; + new_stderr = newPyStdOut(err_description); + PySys_SetObject((char*)"stderr", new_stderr); + PyErr_Print(); + PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__")); + Py_DECREF(new_stderr); + PyGILState_Release(gstate); + return result; + } + + PyObject* coords; + coords = PyObject_CallFunction(func,(char*)"(d, d, i)", theMin, theMax, theNbStep ); + + new_stderr = NULL; + + if (coords == NULL){ + fflush(stderr); + std::string err_description=""; + new_stderr = newPyStdOut(err_description); + PySys_SetObject((char*)"stderr", new_stderr); + PyErr_Print(); + PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__")); + Py_DECREF(new_stderr); + PyGILState_Release(gstate); + return result; + } + + Py_ssize_t size = PyList_Size( coords ); + if( size <= 0 ) { + Py_DECREF(coords); + return result; + } + + result = size; + + *theX = new double[size]; + *theY = new double[size]; + + for ( Py_ssize_t i = 0; i< size; ++i ) { + PyObject* coord = PyList_GetItem( coords, i ); + (*theX)[i] = PyFloat_AsDouble(PyList_GetItem(coord, 0)); + (*theY)[i] = PyFloat_AsDouble(PyList_GetItem(coord, 1)); + } + + PyGILState_Release(gstate); + return result; +} + +/*! + \brief Initialize python script. +*/ +void Plot2d_AnalyticalParser::initScript() { + myScript.clear(); + myScript += "from math import * \n"; + myScript += "def Y(x): \n"; + myScript += " return "; + myScript += "%1\n"; + + myScript += "def coordCalculator(xmin, xmax, nstep): \n"; + myScript += " coords = [] \n"; + myScript += " xstep = (xmax - xmin) / nstep \n"; + myScript += " n = 0 \n"; + myScript += " while n <= nstep : \n"; + myScript += " x = xmin + n*xstep \n"; + myScript += " try: \n"; + myScript += " y = Y(x) \n"; + myScript += " coords.append([x,y]) \n"; + myScript += " except ValueError, ZeroDivisionError: \n"; + myScript += " pass \n"; + myScript += " n = n+1 \n"; + myScript += " return coords \n"; +} diff --git a/src/Plot2d/Plot2d_AnalyticalParser.h b/src/Plot2d/Plot2d_AnalyticalParser.h new file mode 100755 index 000000000..37b55d981 --- /dev/null +++ b/src/Plot2d/Plot2d_AnalyticalParser.h @@ -0,0 +1,52 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : Plot2d_AnalyticalParser.h +// Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com) + +#ifndef PLOT2D_ANALYTICAL_Parser_H +#define PLOT2D_ANALYTICAL_Parser_H +#include + +#include "Plot2d.h" + +class PLOT2D_EXPORT Plot2d_AnalyticalParser { +public: + ~Plot2d_AnalyticalParser(); + + + static Plot2d_AnalyticalParser* parser(); + int calculate( const QString&, const double, + const double, const int, + double**, double**); + +private: + Plot2d_AnalyticalParser(); + void initScript(); + +private: + static Plot2d_AnalyticalParser* myParser; //!< instance of the Parser + PyObject* myMainMod; //!< main python module + PyObject* myMainDict; //!< main python dictionary + static QString myScript; //!< python script +}; + +#endif //PLOT2D_ANALYTICAL_Parser_H diff --git a/src/Plot2d/Plot2d_ViewFrame.cxx b/src/Plot2d/Plot2d_ViewFrame.cxx index ff36d6b5d..3bb45f3de 100755 --- a/src/Plot2d/Plot2d_ViewFrame.cxx +++ b/src/Plot2d/Plot2d_ViewFrame.cxx @@ -28,10 +28,8 @@ #include "Plot2d_FitDataDlg.h" #include "Plot2d_ViewWindow.h" #include "Plot2d_SetupViewDlg.h" -#ifndef DISABLE_PYCONSOLE -#include "Plot2d_AnaliticCurveDlg.h" -#include "Plot2d_AnaliticCurve.h" -#endif +#include "Plot2d_AnalyticalCurveDlg.h" +#include "Plot2d_AnalyticalCurve.h" #include "Plot2d_ToolTip.h" #include "SUIT_Tools.h" @@ -66,7 +64,6 @@ #include #include -#include #include #include @@ -1602,24 +1599,38 @@ void Plot2d_ViewFrame::onSettings() delete dlg; } -#ifndef DISABLE_PYCONSOLE /*! - "Analitic Curves" toolbar action slot + "Analytical Curves" toolbar action slot */ -void Plot2d_ViewFrame::onAnaliticCurve() { - Plot2d_AnaliticCurveDlg* dlg = new Plot2d_AnaliticCurveDlg(this, myPlot); - dlg->setCurveList(myAnaliticCurves); - dlg->exec(); - delete dlg; -} +void Plot2d_ViewFrame::onAnalyticalCurve() +{ +#ifndef DISABLE_PYCONSOLE + Plot2d_AnalyticalCurveDlg dlg( this, this ); + dlg.exec(); + updateAnalyticalCurves(); #endif +} +void Plot2d_ViewFrame::addAnalyticalCurve( Plot2d_AnalyticalCurve* theCurve) +{ +#ifndef DISABLE_PYCONSOLE + myAnalyticalCurves.append(theCurve); +#endif +} +void Plot2d_ViewFrame::removeAnalyticalCurve( Plot2d_AnalyticalCurve* theCurve) +{ #ifndef DISABLE_PYCONSOLE + theCurve->setAction(Plot2d_AnalyticalCurve::ActRemoveFromView); +#endif +} + /* - Update analitic curve + Update Analytical curve */ -void Plot2d_ViewFrame::updateAnaliticCurve(Plot2d_AnaliticCurve* c, bool updateView){ +void Plot2d_ViewFrame::updateAnalyticalCurve(Plot2d_AnalyticalCurve* c, bool updateView) +{ +#ifndef DISABLE_PYCONSOLE if(!c) return; QwtScaleDiv* div = myPlot->axisScaleDiv(QwtPlot::xBottom); c->setRangeBegin(div->lowerBound()); @@ -1629,17 +1640,17 @@ void Plot2d_ViewFrame::updateAnaliticCurve(Plot2d_AnaliticCurve* c, bool updateV QwtPlotItem* item = c->plotItem(); switch( c->getAction() ) { - case Plot2d_AnaliticCurve::ActAddInView: + case Plot2d_AnalyticalCurve::ActAddInView: if( c->isActive() ) { + c->updatePlotItem(); item->attach( myPlot ); + item->show(); } - myAnaliticCurves.append(c); - c->setAction(Plot2d_AnaliticCurve::ActNothing); + c->setAction(Plot2d_AnalyticalCurve::ActNothing); break; - case Plot2d_AnaliticCurve::ActUpdateInView: + case Plot2d_AnalyticalCurve::ActUpdateInView: if(c->isActive()) { - item->attach( myPlot ); c->updatePlotItem(); item->show(); } else { @@ -1647,33 +1658,56 @@ void Plot2d_ViewFrame::updateAnaliticCurve(Plot2d_AnaliticCurve* c, bool updateV item->detach(); } - c->setAction(Plot2d_AnaliticCurve::ActNothing); + c->setAction(Plot2d_AnalyticalCurve::ActNothing); break; - case Plot2d_AnaliticCurve::ActRemoveFromView: + case Plot2d_AnalyticalCurve::ActRemoveFromView: item->hide(); item->detach(); - myAnaliticCurves.removeAll(c); + myAnalyticalCurves.removeAll(c); delete c; break; } if(updateView) myPlot->replot(); -} #endif +} -#ifndef DISABLE_PYCONSOLE /* - Update analitic curves + Update Analytical curves */ -void Plot2d_ViewFrame::updateAnaliticCurves() { - AnaliticCurveList::iterator it = myAnaliticCurves.begin(); - for( ; it != myAnaliticCurves.end(); it++) { - updateAnaliticCurve(*it); +void Plot2d_ViewFrame::updateAnalyticalCurves() +{ +#ifndef DISABLE_PYCONSOLE + AnalyticalCurveList::iterator it = myAnalyticalCurves.begin(); + for( ; it != myAnalyticalCurves.end(); it++) { + updateAnalyticalCurve(*it); } myPlot->replot(); +#endif } + +/*! + Return list of the alalytical curves. +*/ +AnalyticalCurveList Plot2d_ViewFrame::getAnalyticalCurves() const +{ + return myAnalyticalCurves; +} + +/*! + Get analytical curve by plot item. +*/ +Plot2d_AnalyticalCurve* Plot2d_ViewFrame::getAnalyticalCurve(QwtPlotItem * theItem) { +#ifndef DISABLE_PYCONSOLE + AnalyticalCurveList::iterator it = myAnalyticalCurves.begin(); + for( ; it != myAnalyticalCurves.end(); it++) { + if((*it)->plotItem() == theItem); + return (*it); + } + return 0; #endif +} /*! "Fit Data" command slot @@ -1690,9 +1724,7 @@ void Plot2d_ViewFrame::onFitData() fitData(mode,xMin,xMax,yMin,yMax,y2Min,y2Max); } delete dlg; -#ifndef DISABLE_PYCONSOLE - updateAnaliticCurves(); -#endif + updateAnalyticalCurves(); } /*! @@ -2362,11 +2394,9 @@ void Plot2d_ViewFrame::plotMouseReleased( const QMouseEvent& me ) me.pos(), me.globalPos() ); emit contextMenuRequested( &aEvent ); } -#ifndef DISABLE_PYCONSOLE else { - updateAnaliticCurves(); + updateAnalyticalCurves(); } -#endif myPlot->canvas()->setCursor( QCursor( Qt::CrossCursor ) ); myPlot->defaultPicker(); @@ -2399,9 +2429,7 @@ void Plot2d_ViewFrame::wheelEvent(QWheelEvent* event) myPlot->replot(); if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase(); myPnt = event->pos(); -#ifndef DISABLE_PYCONSOLE - updateAnaliticCurves(); -#endif + updateAnalyticalCurves(); } /*! @@ -3217,15 +3245,14 @@ QString Plot2d_ViewFrame::getVisualParameters() myLegendFont.italic(), myLegendFont.underline(),myLegendColor.red(), myLegendColor.green(), myLegendColor.blue()); -#ifndef DISABLE_PYCONSOLE - //store all analitic curves + //store all Analytical curves //store each curve in the following format // ...*Name|isActive|Expresion|NbInervals|isAutoAssign[|MarkerType|LineType|LineWidth|r:g:b] // parameters in the [ ] is optional in case if isAutoAssign == true - AnaliticCurveList::iterator it = myAnaliticCurves.begin(); - Plot2d_AnaliticCurve* c = 0; + AnalyticalCurveList::iterator it = myAnalyticalCurves.begin(); + Plot2d_AnalyticalCurve* c = 0; bool isAuto; - for( ; it != myAnaliticCurves.end(); it++) { + for( ; it != myAnalyticalCurves.end(); it++) { c = (*it); if(!c) continue; QString curveString(""); @@ -3250,7 +3277,6 @@ QString Plot2d_ViewFrame::getVisualParameters() retStr+=optCurveString; } } -#endif return retStr; } @@ -3308,14 +3334,13 @@ void Plot2d_ViewFrame::setVisualParameters( const QString& parameters ) } } -#ifndef DISABLE_PYCONSOLE - //Restore all analitical curves + //Restore all Analyticalal curves int startCurveIndex = 10; if( paramsLst.size() >= startCurveIndex+1 ) { for( int i=startCurveIndex; isetName(curveLst[0]); c->setActive(curveLst[1].toInt()); c->setExpression(curveLst[2]); @@ -3334,13 +3359,12 @@ void Plot2d_ViewFrame::setVisualParameters( const QString& parameters ) } else { c->autoFill( myPlot ); } - c->setAction(Plot2d_AnaliticCurve::ActAddInView); - updateAnaliticCurve(c); + addAnalyticalCurve(c); + updateAnalyticalCurve(c); } } myPlot->replot(); } -#endif } /*! @@ -3449,6 +3473,25 @@ Plot2d_Curve* Plot2d_ViewFrame::getClosestCurve( QPoint p, double& distance, int return 0; } +/*! + \brief Deselect all analytical curves. +*/ +void Plot2d_ViewFrame::deselectAnalyticalCurves() { + foreach(Plot2d_AnalyticalCurve* c, myAnalyticalCurves) { + c->setSelected(false); + } +} + +/*! + \brief Deselect all objects, except analytical curves. +*/ +void Plot2d_ViewFrame::deselectObjects() { + ObjectDict::const_iterator it = myObjects.begin(), aLast = myObjects.end(); + for ( ; it != aLast; it++ ) { + it.value()->setSelected(false); + } +} + #define INCREMENT_FOR_OP 10 /*! @@ -3457,9 +3500,7 @@ Plot2d_Curve* Plot2d_ViewFrame::getClosestCurve( QPoint p, double& distance, int void Plot2d_ViewFrame::onPanLeft() { this->incrementalPan( -INCREMENT_FOR_OP, 0 ); -#ifndef DISABLE_PYCONSOLE - updateAnaliticCurves(); -#endif + updateAnalyticalCurves(); } /*! @@ -3468,9 +3509,7 @@ void Plot2d_ViewFrame::onPanLeft() void Plot2d_ViewFrame::onPanRight() { this->incrementalPan( INCREMENT_FOR_OP, 0 ); -#ifndef DISABLE_PYCONSOLE - updateAnaliticCurves(); -#endif + updateAnalyticalCurves(); } /*! @@ -3479,9 +3518,7 @@ void Plot2d_ViewFrame::onPanRight() void Plot2d_ViewFrame::onPanUp() { this->incrementalPan( 0, -INCREMENT_FOR_OP ); -#ifndef DISABLE_PYCONSOLE - updateAnaliticCurves(); -#endif + updateAnalyticalCurves(); } /*! @@ -3490,9 +3527,7 @@ void Plot2d_ViewFrame::onPanUp() void Plot2d_ViewFrame::onPanDown() { this->incrementalPan( 0, INCREMENT_FOR_OP ); -#ifndef DISABLE_PYCONSOLE - updateAnaliticCurves(); -#endif + updateAnalyticalCurves(); } /*! @@ -3501,9 +3536,7 @@ void Plot2d_ViewFrame::onPanDown() void Plot2d_ViewFrame::onZoomIn() { this->incrementalZoom( INCREMENT_FOR_OP, INCREMENT_FOR_OP ); -#ifndef DISABLE_PYCONSOLE - updateAnaliticCurves(); -#endif + updateAnalyticalCurves(); } /*! @@ -3512,9 +3545,7 @@ void Plot2d_ViewFrame::onZoomIn() void Plot2d_ViewFrame::onZoomOut() { this->incrementalZoom( -INCREMENT_FOR_OP, -INCREMENT_FOR_OP ); -#ifndef DISABLE_PYCONSOLE - updateAnaliticCurves(); -#endif + updateAnalyticalCurves(); } /*! diff --git a/src/Plot2d/Plot2d_ViewFrame.h b/src/Plot2d/Plot2d_ViewFrame.h index 69eb8bfdd..63a10e25c 100755 --- a/src/Plot2d/Plot2d_ViewFrame.h +++ b/src/Plot2d/Plot2d_ViewFrame.h @@ -25,9 +25,7 @@ #include "Plot2d.h" #include "Plot2d_Curve.h" -#ifndef DISABLE_PYCONSOLE -#include "Plot2d_AnaliticCurve.h" -#endif +#include "Plot2d_AnalyticalCurve.h" #include "Plot2d_NormalizeAlgorithm.h" #include @@ -58,7 +56,7 @@ class Plot2d_QwtPlotPicker; typedef QMultiHash CurveDict; typedef QMultiHash ObjectDict; -class PLOT2D_EXPORT Plot2d_ViewFrame : public QWidget +class PLOT2D_EXPORT Plot2d_ViewFrame : public QWidget, public Plot2d_CurveContainer { Q_OBJECT @@ -153,10 +151,16 @@ public: void getFitRangeByCurves( double&, double&, double&, double&, double&, double& ); -#ifndef DISABLE_PYCONSOLE - void updateAnaliticCurves(); - void updateAnaliticCurve( Plot2d_AnaliticCurve*, bool = false ); -#endif + + void addAnalyticalCurve( Plot2d_AnalyticalCurve* ); + void removeAnalyticalCurve( Plot2d_AnalyticalCurve* ); + void updateAnalyticalCurve( Plot2d_AnalyticalCurve*, bool = false ); + void updateAnalyticalCurves(); + void deselectAnalyticalCurves(); + void deselectObjects(); + + AnalyticalCurveList getAnalyticalCurves() const; + Plot2d_AnalyticalCurve* getAnalyticalCurve(QwtPlotItem *); /* view parameters */ void copyPreferences( Plot2d_ViewFrame* ); @@ -241,6 +245,10 @@ protected: void setCurveType( QwtPlotCurve*, int ); bool hasPlotObject( Plot2d_Object* ) const; + + + + public slots: void onViewPan(); void onViewZoom(); @@ -248,9 +256,7 @@ public slots: void onViewFitArea(); void onViewGlobalPan(); void onSettings(); -#ifndef DISABLE_PYCONSOLE - void onAnaliticCurve(); -#endif + void onAnalyticalCurve(); void onFitData(); void onChangeBackground(); void onPanLeft(); @@ -298,9 +304,7 @@ protected: double myXDistance, myYDistance, myYDistance2; bool mySecondY; ObjectDict myObjects; -#ifndef DISABLE_PYCONSOLE - AnaliticCurveList myAnaliticCurves; -#endif + AnalyticalCurveList myAnalyticalCurves; Plot2d_NormalizeAlgorithm* myLNormAlgo; Plot2d_NormalizeAlgorithm* myRNormAlgo; bool myIsDefTitle; diff --git a/src/Plot2d/Plot2d_ViewWindow.cxx b/src/Plot2d/Plot2d_ViewWindow.cxx index a9cfe63b7..1dfa2d22a 100755 --- a/src/Plot2d/Plot2d_ViewWindow.cxx +++ b/src/Plot2d/Plot2d_ViewWindow.cxx @@ -432,16 +432,17 @@ void Plot2d_ViewWindow::createActions() connect( aAction, SIGNAL( triggered( bool ) ), myViewFrame, SLOT( onSettings() ) ); mgr->registerAction( aAction, CurvSettingsId ); - // 9. Analitic curves - aAction = new QtxAction( tr( "TOT_PLOT2D_ANALITIC_CURVES" ), - aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_ANALITIC_CURVES" ) ), - tr( "MEN_PLOT2D_ANALITIC_CURVES" ), + // 9. Analytical curves +#ifndef DISABLE_PYCONSOLE + aAction = new QtxAction( tr( "TOT_PLOT2D_ANALYTICAL_CURVES" ), + aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_ANALYTICAL_CURVES" ) ), + tr( "MEN_PLOT2D_ANALYTICAL_CURVES" ), 0, this ); - aAction->setStatusTip( tr( "PRP_PLOT2D_ANALITIC_CURVES" ) ); - connect( aAction, SIGNAL( triggered( bool ) ), myViewFrame, SLOT( onAnaliticCurve() ) ); - mgr->registerAction( aAction, AnaliticCurveId ); - + aAction->setStatusTip( tr( "PRP_PLOT2D_ANALYTICAL_CURVES" ) ); + connect( aAction, SIGNAL( triggered( bool ) ), myViewFrame, SLOT( onAnalyticalCurve() ) ); + mgr->registerAction( aAction, AnalyticalCurveId ); +#endif // 10. Clone aAction = new QtxAction( tr( "MNU_CLONE_VIEW" ), @@ -499,7 +500,7 @@ void Plot2d_ViewWindow::createToolBar() mgr->append( toolMgr()->separator(), myToolBar ); mgr->append( LegendId, myToolBar ); mgr->append( CurvSettingsId, myToolBar ); - mgr->append( AnaliticCurveId, myToolBar ); + mgr->append( AnalyticalCurveId, myToolBar ); mgr->append( CloneId, myToolBar ); mgr->append( PrintId, myToolBar ); } diff --git a/src/Plot2d/Plot2d_ViewWindow.h b/src/Plot2d/Plot2d_ViewWindow.h index 66975732d..ffa44da2c 100755 --- a/src/Plot2d/Plot2d_ViewWindow.h +++ b/src/Plot2d/Plot2d_ViewWindow.h @@ -59,7 +59,7 @@ public: LegendId, CurvSettingsId, CloneId, PrintId, - AnaliticCurveId }; + AnalyticalCurveId }; public: Plot2d_ViewWindow( SUIT_Desktop*, Plot2d_Viewer* ); diff --git a/src/Plot2d/resources/Plot2d_images.ts b/src/Plot2d/resources/Plot2d_images.ts index 5841ec8a0..33028818f 100644 --- a/src/Plot2d/resources/Plot2d_images.ts +++ b/src/Plot2d/resources/Plot2d_images.ts @@ -72,8 +72,8 @@ plot2d_settings.png - ICON_PLOT2D_ANALITIC_CURVES - plot2d_analitic_curve.png + ICON_PLOT2D_ANALYTICAL_CURVES + plot2d_analytical_curve.png ICON_PLOT2D_CURVES_LINES diff --git a/src/Plot2d/resources/Plot2d_msg_en.ts b/src/Plot2d/resources/Plot2d_msg_en.ts index d312ff17d..b363b48e8 100644 --- a/src/Plot2d/resources/Plot2d_msg_en.ts +++ b/src/Plot2d/resources/Plot2d_msg_en.ts @@ -228,8 +228,8 @@ Settings - TOT_PLOT2D_ANALITIC_CURVES - Analytic curves + TOT_PLOT2D_ANALYTICAL_CURVES + Analytical curves TOT_PLOT2D_NORMALIZE_MODE_LMAX @@ -394,8 +394,8 @@ Logarithmic scale for ordinate axis is not allowed. Zoom the view - PRP_PLOT2D_ANALITIC_CURVES - Setups analytic curves properties + PRP_PLOT2D_ANALYTICAL_CURVES + Setups analytical curves properties PRP_PLOT2D_NORMALIZE_MODE_LMAX @@ -522,8 +522,8 @@ Logarithmic scale for ordinate axis is not allowed. &Settings - MEN_PLOT2D_ANALITIC_CURVES - Analytic curves + MEN_PLOT2D_ANALYTICAL_CURVES + Analytical curves CIRCLE_MARKER_LBL @@ -673,10 +673,10 @@ Logarithmic scale for ordinate axis is not allowed. - Plot2d_AnaliticCurveDlg + Plot2d_AnalyticalCurveDlg - ANALITIC_CURVE_TLT - Analitic curves properties + ANALYTICAL_CURVE_TLT + Analytical curves properties AC_CURVE_PARAMS @@ -723,9 +723,13 @@ Logarithmic scale for ordinate axis is not allowed. Remove curve - AC_UPD_BTN - Update Curve + AC_OK_BTN + Ok + + AC_APPLY_BTN + Apply + AC_CANT_CALCULATE Can't calculate curve. @@ -735,6 +739,11 @@ Please, check input parameters!!! AC_CLOSE_BTN &Close + + AC_HELP_BTN + Help + + Plot2d_SetupCurveScaleDlg diff --git a/src/Plot2d/resources/Plot2d_msg_fr.ts b/src/Plot2d/resources/Plot2d_msg_fr.ts index 53be6d0ac..8ba2de9b1 100755 --- a/src/Plot2d/resources/Plot2d_msg_fr.ts +++ b/src/Plot2d/resources/Plot2d_msg_fr.ts @@ -204,7 +204,7 @@ Paramètres - TOT_PLOT2D_ANALITIC_CURVES + TOT_PLOT2D_ANALYTICAL_CURVES Courbes analytiques @@ -354,7 +354,7 @@ L'échelle logarithmique de l'ordonnée n'est pas permise.Zoomer la vue - PRP_PLOT2D_ANALITIC_CURVES + PRP_PLOT2D_ANALYTICAL_CURVES Réglage des propriétés des courbes analytiques @@ -450,7 +450,7 @@ L'échelle logarithmique de l'ordonnée n'est pas permise.&Paramètres - MEN_PLOT2D_ANALITIC_CURVES + MEN_PLOT2D_ANALYTICAL_CURVES Courbes analytiques @@ -601,9 +601,9 @@ L'échelle logarithmique de l'ordonnée n'est pas permise. - Plot2d_AnaliticCurveDlg + Plot2d_AnalyticalCurveDlg - ANALITIC_CURVE_TLT + ANALYTICAL_CURVE_TLT Propriétés des courbes analytiques diff --git a/src/Plot2d/resources/plot2d_analitic_curve.png b/src/Plot2d/resources/plot2d_analitic_curve.png deleted file mode 100755 index 7ceb5f220..000000000 Binary files a/src/Plot2d/resources/plot2d_analitic_curve.png and /dev/null differ diff --git a/src/Plot2d/resources/plot2d_analytical_curve.png b/src/Plot2d/resources/plot2d_analytical_curve.png new file mode 100755 index 000000000..7ceb5f220 Binary files /dev/null and b/src/Plot2d/resources/plot2d_analytical_curve.png differ diff --git a/src/SPlot2d/SPlot2d_ViewModel.cxx b/src/SPlot2d/SPlot2d_ViewModel.cxx index 0c4d53a9b..c1e8b6cce 100644 --- a/src/SPlot2d/SPlot2d_ViewModel.cxx +++ b/src/SPlot2d/SPlot2d_ViewModel.cxx @@ -79,7 +79,8 @@ using namespace std; Constructor */ SPlot2d_Viewer::SPlot2d_Viewer( bool theAutoDel ) -: Plot2d_Viewer( theAutoDel ) +: Plot2d_Viewer( theAutoDel ), + myDeselectAnalytical(true) { } @@ -406,6 +407,23 @@ void SPlot2d_Viewer::onLegendClicked( QwtPlotItem* plotItem ) Plot2d_ViewFrame* aViewFrame = getActiveViewFrame(); if(aViewFrame == NULL) return; + bool isAnalytical = false; + AnalyticalCurveList curves = aViewFrame->getAnalyticalCurves(); + foreach ( Plot2d_AnalyticalCurve* curve, curves ) { + if(plotItem == curve->plotItem()) { + isAnalytical = true; + curve->setSelected(true); + } else { + curve->setSelected(false); + } + } + if(isAnalytical) { + myDeselectAnalytical = false; + emit clearSelected(); + aViewFrame->updateAnalyticalCurves(); + myDeselectAnalytical = true; + return; + } Plot2d_Object* anObject = aViewFrame->getPlotObject(plotItem); @@ -423,7 +441,7 @@ void SPlot2d_Viewer::onLegendClicked( QwtPlotItem* plotItem ) if(!anEntry.isEmpty()) emit legendSelected( anEntry ); - } + } } /*! @@ -473,7 +491,11 @@ void SPlot2d_Viewer::setObjectsSelected( SALOME_ListIO& theList ) { o->setSelected(false); aViewFrame->updateObject(o); } - } + } + if( myDeselectAnalytical ) { + aViewFrame->deselectAnalyticalCurves(); + aViewFrame->updateAnalyticalCurves(); + } aViewFrame->Repaint(); } } diff --git a/src/SPlot2d/SPlot2d_ViewModel.h b/src/SPlot2d/SPlot2d_ViewModel.h index f29904fd8..8a31b3da1 100644 --- a/src/SPlot2d/SPlot2d_ViewModel.h +++ b/src/SPlot2d/SPlot2d_ViewModel.h @@ -88,6 +88,9 @@ protected slots: signals: void legendSelected( const QString& ); + void clearSelected(); +private: + bool myDeselectAnalytical; };