From 818a7a030d8168c0f1b73a1f66a17bd0f46b491c Mon Sep 17 00:00:00 2001 From: rnv Date: Tue, 17 Jan 2012 09:21:13 +0000 Subject: [PATCH] Fix remarks for the "0021383: [CEA 507] Plot2d Add analytic functions on curves" issue. --- src/Plot2d/Makefile.am | 16 +- src/Plot2d/Plot2d_AnaliticCurveDlg.cxx | 510 ------------- src/Plot2d/Plot2d_AnaliticCurveDlg.h | 94 --- src/Plot2d/Plot2d_AnaliticParcer.cxx | 272 ------- src/Plot2d/Plot2d_AnaliticParcer.h | 52 -- ...icCurve.cxx => Plot2d_AnalyticalCurve.cxx} | 198 +++-- ...aliticCurve.h => Plot2d_AnalyticalCurve.h} | 36 +- src/Plot2d/Plot2d_AnalyticalCurveDlg.cxx | 705 ++++++++++++++++++ 8 files changed, 862 insertions(+), 1021 deletions(-) delete mode 100644 src/Plot2d/Plot2d_AnaliticCurveDlg.cxx delete mode 100644 src/Plot2d/Plot2d_AnaliticCurveDlg.h delete mode 100644 src/Plot2d/Plot2d_AnaliticParcer.cxx delete mode 100644 src/Plot2d/Plot2d_AnaliticParcer.h rename src/Plot2d/{Plot2d_AnaliticCurve.cxx => Plot2d_AnalyticalCurve.cxx} (55%) mode change 100644 => 100755 rename src/Plot2d/{Plot2d_AnaliticCurve.h => Plot2d_AnalyticalCurve.h} (77%) mode change 100644 => 100755 create mode 100755 src/Plot2d/Plot2d_AnalyticalCurveDlg.cxx diff --git a/src/Plot2d/Makefile.am b/src/Plot2d/Makefile.am index 0aa21990a..bebc5b613 100755 --- a/src/Plot2d/Makefile.am +++ b/src/Plot2d/Makefile.am @@ -51,9 +51,9 @@ salomeinclude_HEADERS = \ if ENABLE_PYCONSOLE salomeinclude_HEADERS += \ - Plot2d_AnaliticCurve.h \ - Plot2d_AnaliticCurveDlg.h \ - Plot2d_AnaliticParcer.h + Plot2d_AnalyticalCurve.h \ + Plot2d_AnalyticalCurveDlg.h \ + Plot2d_AnalyticalParser.h endif @@ -78,9 +78,9 @@ dist_libPlot2d_la_SOURCES = \ if ENABLE_PYCONSOLE dist_libPlot2d_la_SOURCES += \ - Plot2d_AnaliticCurve.cxx \ - Plot2d_AnaliticCurveDlg.cxx \ - Plot2d_AnaliticParcer.cxx + Plot2d_AnalyticalCurve.cxx \ + Plot2d_AnalyticalCurveDlg.cxx \ + Plot2d_AnalyticalParser.cxx endif MOC_FILES = \ @@ -97,7 +97,7 @@ MOC_FILES = \ Plot2d_ToolTip_moc.cxx if ENABLE_PYCONSOLE -MOC_FILES += Plot2d_AnaliticCurveDlg_moc.cxx +MOC_FILES += Plot2d_AnalyticalCurveDlg_moc.cxx endif nodist_libPlot2d_la_SOURCES = $(MOC_FILES) @@ -119,7 +119,7 @@ dist_salomeres_DATA = \ resources/plot2d_print.png \ resources/plot2d_settings.png \ resources/plot2d_splines.png \ - resources/plot2d_analitic_curve.png \ + resources/plot2d_analytical_curve.png \ resources/plot2d_lmax_normalization.png \ resources/plot2d_lmin_normalization.png \ resources/plot2d_rmax_normalization.png \ diff --git a/src/Plot2d/Plot2d_AnaliticCurveDlg.cxx b/src/Plot2d/Plot2d_AnaliticCurveDlg.cxx deleted file mode 100644 index 62db6b8fa..000000000 --- a/src/Plot2d/Plot2d_AnaliticCurveDlg.cxx +++ /dev/null @@ -1,510 +0,0 @@ -// 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_AnaliticCurveDlg.cxx -// Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com) - -//Local includes -#include "Plot2d_AnaliticCurveDlg.h" -#include "Plot2d_AnaliticCurve.h" -#include "Plot2d_ViewFrame.h" - -//Qtx includes -#include -#include - -//SUIT includes -#include - -//Qt includes -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//qwt includes -#include -#include - - -//debug -#include - -// Controls -#define MIN 0 -#define MAX 10000 -#define STEP 1 -#define MAX_LINE_WIDTH 10 - - -/*! - Constructor -*/ -Plot2d_AnaliticCurveDlg::Plot2d_AnaliticCurveDlg( QWidget* parent, QwtPlot* plot ) - : QDialog( parent , Qt::WindowTitleHint | Qt::WindowSystemMenuHint ), - myPlot(plot) -{ - setWindowTitle( tr( "ANALITIC_CURVE_TLT" ) ); - QGridLayout* mainLayout = new QGridLayout(this); - - //Curves list widget - myCurvesList = new QListWidget( this ); - myCurvesList->setSelectionMode(QAbstractItemView::SingleSelection); - myCurvesList->setMaximumSize(QSize(150, 16777215)); - - //Curve parameters group box - myCurveParams = new QGroupBox( tr( "AC_CURVE_PARAMS" ), this ); - QGridLayout* paramsLayout = new QGridLayout( myCurveParams ); - - QLabel* formulaLabel = new QLabel( tr( "AC_FORMULA" ), myCurveParams ); - myFormula = new QLineEdit( myCurveParams ); - - QLabel* nbIntervalsLabel = new QLabel( tr( "AC_NB_INTERVALS" ), myCurveParams ); - myNbIntervals = new QtxIntSpinBox( 1, MAX, STEP, myCurveParams ); - - paramsLayout->addWidget( formulaLabel, 0, 0, 1, 1 ); - paramsLayout->addWidget( myFormula, 0, 1, 1, 1 ); - paramsLayout->addWidget( nbIntervalsLabel, 1, 0, 1, 1 ); - paramsLayout->addWidget( myNbIntervals, 1, 1, 1, 1 ); - - //Curve properties group box - myCurveProps = new QGroupBox( tr( "AC_CURVE_PROPS" ), this ); - QGridLayout* propsLayout = new QGridLayout( myCurveProps ); - - myAutoAssign = new QCheckBox( tr( "AC_AUTO_ASSIGN" ), myCurveProps ); - - QLabel* markerLabel = new QLabel( tr( "AC_MARKER_TYPE" ), myCurveProps ); - myMarkerType = new QComboBox( myCurveProps ); - - - QLabel* lineTypeLabel = new QLabel( tr( "AC_LINE_TYPE" ), myCurveProps ); - myLineType = new QComboBox( myCurveProps ); - - - QLabel* lineWidthLabel = new QLabel( tr( "AC_LINE_WIDTH" ), myCurveProps ); - myLineWidth = new QtxIntSpinBox( MIN, MAX_LINE_WIDTH, STEP, myCurveProps ); - - - - QLabel* colorLabel = new QLabel( tr("AC_CURVE_COLOR"), myCurveProps ); - myColor = new QtxColorButton(myCurveProps); - - propsLayout->addWidget( myAutoAssign, 0, 0, 1, 1 ); - propsLayout->addWidget( markerLabel, 1, 0, 1, 1 ); - propsLayout->addWidget( myMarkerType, 1, 1, 1, 1 ); - propsLayout->addWidget( lineTypeLabel, 2, 0, 1, 1 ); - propsLayout->addWidget( myLineType, 2, 1, 1, 1 ); - propsLayout->addWidget( lineWidthLabel, 3, 0, 1, 1 ); - propsLayout->addWidget( myLineWidth, 3, 1, 1, 1 ); - propsLayout->addWidget( colorLabel, 4, 0, 1, 1 ); - propsLayout->addWidget( myColor, 4, 1, 1, 1 ); - - propsLayout->addItem( new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding ), 3, 0, 1, 1 ); - propsLayout->addItem( new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding ), 3, 1, 1, 1 ); - - - //Add && Remove buttons - QPushButton* addButton = new QPushButton( tr("AC_ADD_BTN"), this ); - QPushButton* updateButton = new QPushButton( tr("AC_UPD_BTN"), this ); - QPushButton* removeButton = new QPushButton( tr("AC_REM_BTN"), this ); - - //Ok && Close buttons - QFrame* frame = new QFrame( this ); - QHBoxLayout* horizontalLayout = new QHBoxLayout(frame); - - frame->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum ) ); - frame->setFrameShape( QFrame::StyledPanel ); - frame->setFrameShadow( QFrame::Raised ); - - QPushButton* closeButton = new QPushButton( tr( "AC_CLOSE_BTN" ), frame ); - - - horizontalLayout->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) ); - horizontalLayout->addWidget( closeButton ); - horizontalLayout->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) ); - - - mainLayout->addWidget( myCurvesList, 0, 0, 3, 1 ); - mainLayout->addWidget( myCurveParams, 0, 1, 1, 5 ); - mainLayout->addWidget( myCurveProps, 1, 1, 1, 5 ); - mainLayout->addWidget( addButton, 2, 1, 1, 1 ); - mainLayout->addItem( new QSpacerItem( 13, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 2, 2, 1, 1 ); - mainLayout->addWidget( removeButton, 2, 3, 1, 1 ); - mainLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), 2, 4, 1, 1); - mainLayout->addWidget( updateButton, 2, 5, 1, 1); - mainLayout->addWidget(frame, 3, 0, 1, 6); - - //Fill combobox - QColor cl = myMarkerType->palette().color( QPalette::Text ); - QSize sz(16, 16); - myMarkerType->setIconSize(sz); - - myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::None ), tr( "NONE_MARKER_LBL" ) ); - myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::Circle ), tr( "CIRCLE_MARKER_LBL" ) ); - myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::Rectangle ), tr( "RECTANGLE_MARKER_LBL" ) ); - myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::Diamond ), tr( "DIAMOND_MARKER_LBL" ) ); - myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::DTriangle ), tr( "DTRIANGLE_MARKER_LBL" ) ); - myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::UTriangle ), tr( "UTRIANGLE_MARKER_LBL" ) ); - myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::LTriangle ), tr( "LTRIANGLE_MARKER_LBL" ) ); - myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::RTriangle ), tr( "RTRIANGLE_MARKER_LBL" ) ); - myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::Cross ), tr( "CROSS_MARKER_LBL" ) ); - myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::XCross ), tr( "XCROSS_MARKER_LBL" ) ); - - cl = myLineType->palette().color( QPalette::Text ); - QSize lsz( 40, 16 ); - myLineType->setIconSize( lsz ); - - myLineType->addItem( Plot2d::lineIcon( lsz, cl, Plot2d::NoPen ), tr( "NONE_LINE_LBL" ) ); - myLineType->addItem( Plot2d::lineIcon( lsz, cl, Plot2d::Solid ), tr( "SOLID_LINE_LBL" ) ); - myLineType->addItem( Plot2d::lineIcon( lsz, cl, Plot2d::Dash ), tr( "DASH_LINE_LBL" ) ); - myLineType->addItem( Plot2d::lineIcon( lsz, cl, Plot2d::Dot ), tr( "DOT_LINE_LBL" ) ); - myLineType->addItem( Plot2d::lineIcon( lsz, cl, Plot2d::DashDot ), tr( "DASHDOT_LINE_LBL" ) ); - myLineType->addItem( Plot2d::lineIcon( lsz, cl, Plot2d::DashDotDot ), tr( "DAHSDOTDOT_LINE_LBL" ) ); - - //Connections - connect( closeButton, SIGNAL( clicked() ), this, SLOT( reject() ) ); - connect( addButton, SIGNAL( clicked() ), this, SLOT( onAddCurve() ) ); - connect( myAutoAssign, SIGNAL( stateChanged(int) ), this, SLOT( onAutoAssign(int) ) ); - connect( removeButton, SIGNAL( clicked()), this, SLOT(onRemoveCurve())); - connect( updateButton, SIGNAL( clicked()), this, SLOT(onUpdateCurve())); - connectSelectionChanged(); - - //Default values - myNbIntervals->setValue(100); - checkState(); -} - -/*! - Destructor -*/ -Plot2d_AnaliticCurveDlg::~Plot2d_AnaliticCurveDlg() -{ -} - -void Plot2d_AnaliticCurveDlg::setCurveList( AnaliticCurveList& theList ) { - AnaliticCurveList::iterator it = theList.begin(); - QListWidgetItem* newItem = 0; - Plot2d_AnaliticCurve* curve; - for( ;it != theList.end(); it++ ) { - curve = *it; - if(!curve) continue; - newItem = new QListWidgetItem(curve->getName()); - newItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled); - newItem->setCheckState(Qt::Checked); - myCurvesList->addItem(newItem); - newItem->setCheckState(curve->isActive() ? Qt::Checked : Qt::Unchecked ); - QVariant var; - var.setValue((void*)curve); - newItem->setData(Qt::UserRole,var); - } - setCurrentCurve(newItem); - checkState(); -} - -/*! - Return list of the curves. -*/ -/*void Plot2d_AnaliticCurveDlg::reject() { - if( myCurvesList->count() == 0 ) - QDialog::reject(); - - QList items = myCurvesList->selectedItems(); - QListWidgetItem* item = items.size() > 0 ? items[0] : 0; - if(item) { - if(!checkItem(item)) { - showErrorMsg(); - return; - } else { - updateInView(myCurrentItem); - QDialog::reject(); - } - } -} -*/ - -/*! - Update curve parameters and curve properties. -*/ -void Plot2d_AnaliticCurveDlg::setCurrentCurve(QListWidgetItem* item, bool select) { - if(item) { - QVariant var = item->data(Qt::UserRole); - Plot2d_AnaliticCurve* curve = (Plot2d_AnaliticCurve*)var.value(); - if(curve) { - myFormula->setText( curve->getExpression() ); - myNbIntervals->setValue( curve->getNbIntervals() ); - myAutoAssign->setChecked( curve->isAutoAssign() ); - if(!curve->isAutoAssign()) { - myMarkerType->setCurrentIndex( curve->getMarker() ); - myLineType->setCurrentIndex( curve->getLine() ); - myLineWidth->setValue( curve->getLineWidth() ); - myColor->setColor( curve->getColor() ); - } else { - myMarkerType->setCurrentIndex( 0 ); - myLineType->setCurrentIndex( 0 ); - myLineWidth->setValue( 1 ); - myColor->setColor( QColor() ); - } - myCurrentItem = item; - if( select ) { - disconnectSelectionChanged(); - item->setSelected(true); - connectSelectionChanged(); - } - } - } -} - -/*! - Enable/Disable "curve parameters" and "curve properties" widgets. -*/ -void Plot2d_AnaliticCurveDlg::checkState() { - bool isEnable = myCurvesList->count() > 0; - myCurveParams->setEnabled(isEnable); - myCurveProps->setEnabled(isEnable); -} -/*! - Show error message - */ -void Plot2d_AnaliticCurveDlg::showErrorMsg() { - SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "AC_CANT_CALCULATE" ) ); -} - -/*! - Check the curve attached to the item. -*/ -bool Plot2d_AnaliticCurveDlg::checkItem(const QListWidgetItem* item) { - bool res = false; - if( !myFormula->text().isEmpty() && item ) { - QVariant var = item->data(Qt::UserRole); - Plot2d_AnaliticCurve* curve = (Plot2d_AnaliticCurve*)var.value(); - - if( curve ) { - curve->setExpression(myFormula->text()); - QwtScaleDiv* div = myPlot->axisScaleDiv(QwtPlot::xBottom); - curve->setRangeBegin(div->lowerBound()); - curve->setRangeEnd(div->upperBound()); - curve->setNbIntervals(myNbIntervals->value()); - curve->calculate(); - if( curve->state() == Plot2d_AnaliticCurve::StateOk ) - res = true; - } - } - return res; -} -/*! - Store properties of the curve attached to the item from "Curve properties" widget. -*/ -void Plot2d_AnaliticCurveDlg::storeProps( const QListWidgetItem* item) { - if( item ) { - QVariant var = item->data(Qt::UserRole); - Plot2d_AnaliticCurve* curve = (Plot2d_AnaliticCurve*)var.value(); - if(curve) { - curve->setAutoAssign(myAutoAssign->isChecked()); - curve->setName(item->text()); - curve->setActive(item->checkState() == Qt::Checked); - if(!myAutoAssign->isChecked()) { - curve->setMarker((Plot2d::MarkerType)myMarkerType->currentIndex()); - curve->setLine((Plot2d::LineType)myLineType->currentIndex()); - curve->setLineWidth(myLineWidth->value()); - curve->setColor(myColor->color()); - } - } - } -} - -/*! - Connect currentItemChanged signal. -*/ -void Plot2d_AnaliticCurveDlg::connectSelectionChanged() { - connect( myCurvesList, SIGNAL( itemSelectionChanged ()), - this, SLOT( onCurveSelectionChanged() ) ); -} - -/*! - Disconnect currentItemChanged signal. -*/ -void Plot2d_AnaliticCurveDlg::disconnectSelectionChanged() { - disconnect( myCurvesList, SIGNAL( itemSelectionChanged ()), - this, SLOT( onCurveSelectionChanged() ) ); -} - -/*! - Private slot. Called then "Add curve" button is clicked -*/ -void Plot2d_AnaliticCurveDlg::onAddCurve() { - /* QList items = myCurvesList->selectedItems(); - QListWidgetItem* item = items.size() > 0 ? items[0] : 0; - if(item) { - if(!checkItem(item)) { - showErrorMsg(); - return; - } - else { - updateInView(item); - } - } - */ - - Plot2d_AnaliticCurve* curve = new Plot2d_AnaliticCurve(); - QListWidgetItem* newItem = new QListWidgetItem(curve->getName()); - newItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled); - newItem->setCheckState(Qt::Checked); - myCurvesList->addItem(newItem); - QVariant var; - var.setValue((void*)curve); - newItem->setData(Qt::UserRole,var); - - bool autoFlag = curve->isAutoAssign(); - if(autoFlag) { - curve->autoFill(myPlot); - } - - setCurrentCurve(newItem); - checkState(); -} - -/*! - Private slot. Called then "Remove curve" button is clicked -*/ -void Plot2d_AnaliticCurveDlg::onRemoveCurve() { - disconnectSelectionChanged(); - QList items = myCurvesList->selectedItems(); - QListWidgetItem* selected = items.size() > 0 ? items[0] : 0; - int row = myCurvesList->row(selected); - int prevRow = (row == 0) ? 1 : row - 1; - if( selected ) { - QVariant var = selected->data(Qt::UserRole); - Plot2d_AnaliticCurve* curve = (Plot2d_AnaliticCurve*)var.value(); - if( curve ) { - if( curve->getAction() == Plot2d_AnaliticCurve::ActAddInView ) { - delete curve; - } else { - curve->setAction(Plot2d_AnaliticCurve::ActRemoveFromView); - updateInView(selected); - } - } - } - - if( prevRow >= 0 && prevRow < myCurvesList->count() ) { - myCurvesList->item(prevRow)->setSelected(true); - setCurrentCurve(myCurvesList->item(prevRow)); - } - - selected = myCurvesList->takeItem(row); - delete selected; - connectSelectionChanged(); - checkState(); -} - -/*! - Private slot. Called then selection in the curve list is changed. -*/ -void Plot2d_AnaliticCurveDlg::onCurveSelectionChanged() { - - QList items = myCurvesList->selectedItems(); - QListWidgetItem* selected = items.size() > 0 ? items[0] : 0; - - /* bool ok = myCurrentItem ? checkItem(myCurrentItem) : true; - - if(!ok) { - showErrorMsg(); - disconnectSelectionChanged(); - - if( selected ) - selected->setSelected(false); - - if( myCurrentItem ) { - myCurrentItem->setSelected(true); - myCurvesList->setCurrentItem(myCurrentItem); - } - - connectSelectionChanged(); - - } else { - updateInView(myCurrentItem); - */ - - if(selected) { - setCurrentCurve(selected, false); - } - //} -} - -/*! - Private slot. Called then "Auto assign" checkbox is clicked -*/ -void Plot2d_AnaliticCurveDlg::onAutoAssign(int state){ - bool flag = !state; - myMarkerType->setEnabled(flag); - myLineType->setEnabled(flag); - myLineWidth->setEnabled(flag); - myColor->setEnabled(flag); - - QList items = myCurvesList->selectedItems(); - QListWidgetItem* selected = items.size() > 0 ? items[0] : 0; - if(selected) { - QVariant var = selected->data(Qt::UserRole); - Plot2d_AnaliticCurve* curve = (Plot2d_AnaliticCurve*)var.value(); - if(curve) { - curve->setAutoAssign(state); - } - setCurrentCurve(selected); - } -} - -/*! - Update curve in the view -*/ -void Plot2d_AnaliticCurveDlg::updateInView( QListWidgetItem* item ) { - storeProps(item); - Plot2d_ViewFrame* fr = qobject_cast(parent()); - QVariant var = item->data(Qt::UserRole); - - Plot2d_AnaliticCurve* curve = (Plot2d_AnaliticCurve*)var.value(); - if( fr && curve ) { - fr->updateAnaliticCurve(curve, true); - } -} - -/*! - Private slot. Called then "Update Curve" checkbox is clicked -*/ -void Plot2d_AnaliticCurveDlg::onUpdateCurve() { - QList items = myCurvesList->selectedItems(); - int sz = items.size(); - if( sz > 0 ) { - QListWidgetItem* selected = items[0]; - - bool ok = myCurrentItem ? checkItem(myCurrentItem) : false; - if(!ok) { - showErrorMsg(); - return; - } else { - updateInView(selected); - } - } -} diff --git a/src/Plot2d/Plot2d_AnaliticCurveDlg.h b/src/Plot2d/Plot2d_AnaliticCurveDlg.h deleted file mode 100644 index ca26a160d..000000000 --- a/src/Plot2d/Plot2d_AnaliticCurveDlg.h +++ /dev/null @@ -1,94 +0,0 @@ -// 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_AnaliticCurveDlg.h -// Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com) - - -#ifndef PLOT2D_ANALITIC_CURVE_DLG_H -#define PLOT2D_ANALITIC_CURVE_DLG_H - -#include "Plot2d.h" -#include "Plot2d_AnaliticCurve.h" - -#include - - -class QListWidget; -class QListWidgetItem; -class QGroupBox; -class QLineEdit; -class QCheckBox; -class QComboBox; - -class QtxIntSpinBox; -class QtxColorButton; -class QwtPlot; - -class Plot2d_AnaliticCurve; -class Plot2d_ViewFrame; - -class PLOT2D_EXPORT Plot2d_AnaliticCurveDlg : public QDialog { - Q_OBJECT -public: - - Plot2d_AnaliticCurveDlg( QWidget* parent, QwtPlot* plot ); - ~Plot2d_AnaliticCurveDlg(); - - AnaliticCurveList getCurveList(); - void setCurveList( AnaliticCurveList& ); - -private: - void setCurrentCurve( QListWidgetItem* , bool = true); - void checkState(); - void showErrorMsg(); - bool checkItem(const QListWidgetItem* ); - void storeProps( const QListWidgetItem* ); - void connectSelectionChanged(); - void disconnectSelectionChanged(); - void updateInView(QListWidgetItem*); - -private slots: - void onAddCurve(); - void onRemoveCurve(); - void onAutoAssign(int); - void onUpdateCurve(); - void onCurveSelectionChanged( ); - -private: - QListWidget* myCurvesList; - - QGroupBox* myCurveParams; - QLineEdit* myFormula; - QtxIntSpinBox* myNbIntervals; - - QGroupBox* myCurveProps; - QCheckBox* myAutoAssign; - QComboBox* myMarkerType; - QComboBox* myLineType; - QtxIntSpinBox* myLineWidth; - QtxColorButton* myColor; - - QwtPlot* myPlot; - QListWidgetItem* myCurrentItem; -}; - -#endif //PLOT2D_ANALITIC_CURVE_DLG_H diff --git a/src/Plot2d/Plot2d_AnaliticParcer.cxx b/src/Plot2d/Plot2d_AnaliticParcer.cxx deleted file mode 100644 index 75ebf76f1..000000000 --- a/src/Plot2d/Plot2d_AnaliticParcer.cxx +++ /dev/null @@ -1,272 +0,0 @@ -// 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_AnaliticParcer.cxx -// Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com) -#include "Plot2d_AnaliticParcer.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 parcer -Plot2d_AnaliticParcer* Plot2d_AnaliticParcer::myParcer = 0; - -//Define the script -QString Plot2d_AnaliticParcer::myScript = QString(""); - -/*! - \brief Return the only instance of the Plot2d_AnaliticParcer - \return instance of the Plot2d_AnaliticParcer -*/ -Plot2d_AnaliticParcer* Plot2d_AnaliticParcer::parcer() -{ - if ( !myParcer ) - myParcer = new Plot2d_AnaliticParcer(); - return myParcer; -} - -/*! - \brief Constructor. - - Construct the parcer and initialize python interpritator. -*/ -Plot2d_AnaliticParcer::Plot2d_AnaliticParcer() -{ - /* 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_AnaliticParcer::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_AnaliticParcer::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 +=" coords.append([x,Y(x)]) \n"; - myScript +=" n = n+1 \n"; - myScript +=" return coords \n"; -} diff --git a/src/Plot2d/Plot2d_AnaliticParcer.h b/src/Plot2d/Plot2d_AnaliticParcer.h deleted file mode 100644 index 3db0cb0bf..000000000 --- a/src/Plot2d/Plot2d_AnaliticParcer.h +++ /dev/null @@ -1,52 +0,0 @@ -// 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_AnaliticParcer.h -// Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com) - -#ifndef PLOT2D_ANALITIC_PARCER_H -#define PLOT2D_ANALITIC_PARCER_H -#include - -#include "Plot2d.h" - -class PLOT2D_EXPORT Plot2d_AnaliticParcer { -public: - ~Plot2d_AnaliticParcer(); - - - static Plot2d_AnaliticParcer* parcer(); - int calculate( const QString&, const double, - const double, const int, - double**, double**); - -private: - Plot2d_AnaliticParcer(); - void initScript(); - -private: - static Plot2d_AnaliticParcer* myParcer; //!< instance of the parcer - PyObject* myMainMod; //!< main python module - PyObject* myMainDict; //!< main python dictionary - static QString myScript; //!< python script -}; - -#endif //PLOT2D_ANALITIC_PARCER_H diff --git a/src/Plot2d/Plot2d_AnaliticCurve.cxx b/src/Plot2d/Plot2d_AnalyticalCurve.cxx old mode 100644 new mode 100755 similarity index 55% rename from src/Plot2d/Plot2d_AnaliticCurve.cxx rename to src/Plot2d/Plot2d_AnalyticalCurve.cxx index b6052d51e..03197673a --- a/src/Plot2d/Plot2d_AnaliticCurve.cxx +++ b/src/Plot2d/Plot2d_AnalyticalCurve.cxx @@ -19,22 +19,25 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// File : Plot2d_AnaliticCurve.cxx +// File : Plot2d_AnalyticalCurve.cxx // Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com) -#include "Plot2d_AnaliticParcer.h" -#include "Plot2d_AnaliticCurve.h" +#include "Plot2d_AnalyticalParser.h" +#include "Plot2d_AnalyticalCurve.h" #include "Plot2d_PlotItems.h" +#include "Plot2d_Object.h" + +#include //Init static data; -int Plot2d_AnaliticCurve::myNbCurves = 0; +int Plot2d_AnalyticalCurve::myNbCurves = 0; /*! Constructor */ -Plot2d_AnaliticCurve::Plot2d_AnaliticCurve() : +Plot2d_AnalyticalCurve::Plot2d_AnalyticalCurve() : myAutoAssign(true), myColor( 0, 0, 0 ), myMarker( Plot2d::Circle ), @@ -45,26 +48,27 @@ Plot2d_AnaliticCurve::Plot2d_AnaliticCurve() : myRangeEnd(100.0), myNbIntervals(100), myExpression(""), - myAction(Plot2d_AnaliticCurve::ActAddInView), - myState(Plot2d_AnaliticCurve::StateNeedUpdate), + myAction(Plot2d_AnalyticalCurve::ActAddInView), + myState(Plot2d_AnalyticalCurve::StateNeedUpdate), myCurve(0), - myActive(true) + myActive(true), + myIsSelected(false) { - myName = QString("Analitic Curve %1").arg(++myNbCurves); + myName = QString("Analytical Curve %1").arg(++myNbCurves); } /*! Destructor */ -Plot2d_AnaliticCurve::~Plot2d_AnaliticCurve() +Plot2d_AnalyticalCurve::~Plot2d_AnalyticalCurve() { } /*! Copy constructor. Makes deep copy of data */ -Plot2d_AnaliticCurve::Plot2d_AnaliticCurve( const Plot2d_AnaliticCurve& curve ) +Plot2d_AnalyticalCurve::Plot2d_AnalyticalCurve( const Plot2d_AnalyticalCurve& curve ) { myAutoAssign = curve.isAutoAssign(); myColor = curve.getColor(); @@ -87,7 +91,7 @@ Plot2d_AnaliticCurve::Plot2d_AnaliticCurve( const Plot2d_AnaliticCurve& curve ) /*! operator=. Makes deep copy of data */ -Plot2d_AnaliticCurve& Plot2d_AnaliticCurve::operator=( const Plot2d_AnaliticCurve& curve ) +Plot2d_AnalyticalCurve& Plot2d_AnalyticalCurve::operator=( const Plot2d_AnalyticalCurve& curve ) { myAutoAssign = curve.isAutoAssign(); myColor = curve.getColor(); @@ -111,7 +115,7 @@ Plot2d_AnaliticCurve& Plot2d_AnaliticCurve::operator=( const Plot2d_AnaliticCurv /*! Create plot object for the curve */ -QwtPlotItem* Plot2d_AnaliticCurve::plotItem() +QwtPlotItem* Plot2d_AnalyticalCurve::plotItem() { if(!myCurve) { myCurve = new Plot2d_QwtPlotCurve(QString("")); @@ -123,7 +127,7 @@ QwtPlotItem* Plot2d_AnaliticCurve::plotItem() /*! Auto fill parameters of object by plot view */ -void Plot2d_AnaliticCurve::autoFill( const QwtPlot* thePlot ) +void Plot2d_AnalyticalCurve::autoFill( const QwtPlot* thePlot ) { QwtSymbol::Style typeMarker; QColor color; @@ -139,7 +143,7 @@ void Plot2d_AnaliticCurve::autoFill( const QwtPlot* thePlot ) /*! Updates curve fields */ -void Plot2d_AnaliticCurve::updatePlotItem() +void Plot2d_AnalyticalCurve::updatePlotItem() { if ( !myCurve ) return; @@ -148,21 +152,28 @@ void Plot2d_AnaliticCurve::updatePlotItem() if(!aCurve) return; - - QwtPlot* aPlot = aCurve->plot(); - if ( aPlot ) { - aCurve->detach(); - aCurve->attach( aPlot ); - } Qt::PenStyle ps = Plot2d::plot2qwtLine( getLine() ); QwtSymbol::Style ms = Plot2d::plot2qwtMarker( getMarker() ); - aCurve->setPen( QPen(getColor() , getLineWidth(), ps ) ); + QColor aColor = isSelected() ? Plot2d_Object::selectionColor() : getColor(); + int lineW = getLineWidth(); + if ( isSelected() ) lineW += (lineW == 0 ? 3 : 2); + + int markerS = isSelected() ? getMarkerSize() + 2 : getMarkerSize(); + + aCurve->setSelected(isSelected()); + + aCurve->setPen( QPen(aColor , lineW, ps ) ); + aCurve->setSymbol( QwtSymbol( ms, QBrush( aColor ), + QPen( aColor ), + QSize( markerS , markerS ) ) ); + + aCurve->setLegendPen(QPen(getColor(), getLineWidth(), ps )); + aCurve->setLegendSymbol( QwtSymbol( ms, QBrush( getColor() ), + QPen( getColor() ), + QSize( getMarkerSize() , getMarkerSize() ))); - aCurve->setSymbol( QwtSymbol( ms, QBrush( getColor() ), - QPen( getColor()), - QSize( getMarkerSize() , getMarkerSize() ) ) ); double *x, *y; long nb = getData( &x, &y ); aCurve->setData( x, y, nb ); @@ -173,17 +184,17 @@ void Plot2d_AnaliticCurve::updatePlotItem() /*! Calculate the curve points. */ -void Plot2d_AnaliticCurve::calculate() { - if( state() == Plot2d_AnaliticCurve::StateOk ) +void Plot2d_AnalyticalCurve::calculate() { + if( state() == Plot2d_AnalyticalCurve::StateOk ) return; if(myRangeBegin > myRangeEnd) return; - Plot2d_AnaliticParcer* parcer = Plot2d_AnaliticParcer::parcer(); + Plot2d_AnalyticalParser* parser = Plot2d_AnalyticalParser::parser(); double* x = 0; double* y = 0; - int nb = parcer->calculate(getExpression(), getRangeBegin(), getRangeEnd(), + int nb = parser->calculate(getExpression(), getRangeBegin(), getRangeEnd(), getNbIntervals(),&x,&y); if( nb > 0 ) { myPoints.clear(); @@ -193,17 +204,30 @@ void Plot2d_AnaliticCurve::calculate() { } delete x; delete y; - myState = Plot2d_AnaliticCurve::StateOk; - setAction(Plot2d_AnaliticCurve::ActUpdateInView); + myState = Plot2d_AnalyticalCurve::StateOk; + setAction(Plot2d_AnalyticalCurve::ActUpdateInView); + } +} +/*! + Checks that this curve can be computed for the input QwtPlot +*/ +bool Plot2d_AnalyticalCurve::checkCurve( const QwtPlot* thePlot) { + if( !myExpression.isEmpty() && thePlot ) { + const QwtScaleDiv* div = thePlot->axisScaleDiv(QwtPlot::xBottom); + setRangeBegin(div->lowerBound()); + setRangeEnd(div->upperBound()); + calculate(); } + return myState == Plot2d_AnalyticalCurve::StateOk; } + /*! Gets object's data */ -long Plot2d_AnaliticCurve::getData( double** theX, double** theY ) const +long Plot2d_AnalyticalCurve::getData( double** theX, double** theY ) const { - int aNPoints = getNbIntervals() + 1; + int aNPoints = myPoints.size(); *theX = new double[aNPoints]; *theY = new double[aNPoints]; for (int i = 0; i < aNPoints; i++) { @@ -216,18 +240,18 @@ long Plot2d_AnaliticCurve::getData( double** theX, double** theY ) const /*! Sets curves's AutoAssign flag - in this case attributes will be set automatically */ -void Plot2d_AnaliticCurve::setAutoAssign( bool on ) +void Plot2d_AnalyticalCurve::setAutoAssign( bool on ) { if( myAutoAssign != on ) { myAutoAssign = on; - setAction(Plot2d_AnaliticCurve::ActUpdateInView); + setAction(Plot2d_AnalyticalCurve::ActUpdateInView); } } /*! Gets curve's AutoAssign flag state */ -bool Plot2d_AnaliticCurve::isAutoAssign() const +bool Plot2d_AnalyticalCurve::isAutoAssign() const { return myAutoAssign; } @@ -235,18 +259,18 @@ bool Plot2d_AnaliticCurve::isAutoAssign() const /*! Sets curve's color. */ -void Plot2d_AnaliticCurve::setColor( const QColor& color ) +void Plot2d_AnalyticalCurve::setColor( const QColor& color ) { if(myColor != color) { myColor = color; - setAction(Plot2d_AnaliticCurve::ActUpdateInView); + setAction(Plot2d_AnalyticalCurve::ActUpdateInView); } } /*! Gets curve's color */ -QColor Plot2d_AnaliticCurve::getColor() const +QColor Plot2d_AnalyticalCurve::getColor() const { return myColor; } @@ -255,18 +279,18 @@ QColor Plot2d_AnaliticCurve::getColor() const /*! Sets marker type ( and resets AutoAssign flag ) */ -void Plot2d_AnaliticCurve::setMarker( Plot2d::MarkerType marker ) +void Plot2d_AnalyticalCurve::setMarker( Plot2d::MarkerType marker ) { if(myMarker != marker) { myMarker = marker; - setAction(Plot2d_AnaliticCurve::ActUpdateInView); + setAction(Plot2d_AnalyticalCurve::ActUpdateInView); } } /*! Gets marker type */ -Plot2d::MarkerType Plot2d_AnaliticCurve::getMarker() const +Plot2d::MarkerType Plot2d_AnalyticalCurve::getMarker() const { return myMarker; } @@ -274,18 +298,18 @@ Plot2d::MarkerType Plot2d_AnaliticCurve::getMarker() const /*! Sets new marker size */ -void Plot2d_AnaliticCurve::setMarkerSize( const int theSize ) +void Plot2d_AnalyticalCurve::setMarkerSize( const int theSize ) { if( myMarkerSize != theSize ) { myMarkerSize = theSize < 0 ? 0 : theSize; - setAction(Plot2d_AnaliticCurve::ActUpdateInView); + setAction(Plot2d_AnalyticalCurve::ActUpdateInView); } } /*! Gets marker size */ -int Plot2d_AnaliticCurve::getMarkerSize() const +int Plot2d_AnalyticalCurve::getMarkerSize() const { return myMarkerSize; } @@ -293,18 +317,18 @@ int Plot2d_AnaliticCurve::getMarkerSize() const /*! Sets line type */ -void Plot2d_AnaliticCurve::setLine( Plot2d::LineType line ) +void Plot2d_AnalyticalCurve::setLine( Plot2d::LineType line ) { if(myLine != line) { myLine = line; - setAction(Plot2d_AnaliticCurve::ActUpdateInView); + setAction(Plot2d_AnalyticalCurve::ActUpdateInView); } } /*! Gets line type */ -Plot2d::LineType Plot2d_AnaliticCurve::getLine() const +Plot2d::LineType Plot2d_AnalyticalCurve::getLine() const { return myLine; } @@ -313,18 +337,18 @@ Plot2d::LineType Plot2d_AnaliticCurve::getLine() const /*! Sets line width */ -void Plot2d_AnaliticCurve::setLineWidth( const int lineWidth ) +void Plot2d_AnalyticalCurve::setLineWidth( const int lineWidth ) { if( myLineWidth != lineWidth ) { myLineWidth = lineWidth < 0 ? 0 : lineWidth; - setAction(Plot2d_AnaliticCurve::ActUpdateInView); + setAction(Plot2d_AnalyticalCurve::ActUpdateInView); } } /*! Gets line width */ -int Plot2d_AnaliticCurve::getLineWidth() const +int Plot2d_AnalyticalCurve::getLineWidth() const { return myLineWidth; } @@ -332,18 +356,18 @@ int Plot2d_AnaliticCurve::getLineWidth() const /*! Sets number of points */ -void Plot2d_AnaliticCurve::setNbIntervals( const long nb ) +void Plot2d_AnalyticalCurve::setNbIntervals( const long nb ) { if( myNbIntervals != nb ) { myNbIntervals = nb < 1 ? 1 : nb; - myState = Plot2d_AnaliticCurve::StateNeedUpdate; + myState = Plot2d_AnalyticalCurve::StateNeedUpdate; } } /*! Gets number of points */ -long Plot2d_AnaliticCurve::getNbIntervals() const +long Plot2d_AnalyticalCurve::getNbIntervals() const { return myNbIntervals; } @@ -351,68 +375,68 @@ long Plot2d_AnaliticCurve::getNbIntervals() const /*! Sets X coordinate of the first curve points */ -void Plot2d_AnaliticCurve::setRangeBegin( const double coord) { +void Plot2d_AnalyticalCurve::setRangeBegin( const double coord) { if( myRangeBegin != coord ) { myRangeBegin = coord; - myState = Plot2d_AnaliticCurve::StateNeedUpdate; + myState = Plot2d_AnalyticalCurve::StateNeedUpdate; } } /*! Gets X coordinate of the first curve points */ -double Plot2d_AnaliticCurve::getRangeBegin() const { +double Plot2d_AnalyticalCurve::getRangeBegin() const { return myRangeBegin; } /*! Sets X coordinate of the last curve points */ -void Plot2d_AnaliticCurve::setRangeEnd( const double coord) { +void Plot2d_AnalyticalCurve::setRangeEnd( const double coord) { if( myRangeEnd != coord ) { myRangeEnd = coord; - myState = Plot2d_AnaliticCurve::StateNeedUpdate; + myState = Plot2d_AnalyticalCurve::StateNeedUpdate; } } /*! Gets X coordinate of the last curve points */ -double Plot2d_AnaliticCurve::getRangeEnd() const { +double Plot2d_AnalyticalCurve::getRangeEnd() const { return myRangeEnd; } /*! Sets the curve expression. */ -void Plot2d_AnaliticCurve::setExpression( const QString& expr ) { +void Plot2d_AnalyticalCurve::setExpression( const QString& expr ) { if( myExpression != expr ) { myExpression = expr; - myState = Plot2d_AnaliticCurve::StateNeedUpdate; + myState = Plot2d_AnalyticalCurve::StateNeedUpdate; } } /*! Gets the curve expression. */ -QString Plot2d_AnaliticCurve::getExpression() const { +QString Plot2d_AnalyticalCurve::getExpression() const { return myExpression; } /*! Sets the curve name. */ -void Plot2d_AnaliticCurve::setName( const QString& name ) { +void Plot2d_AnalyticalCurve::setName( const QString& name ) { if( myName != name ) { myName = name; - setAction(Plot2d_AnaliticCurve::ActUpdateInView); + setAction(Plot2d_AnalyticalCurve::ActUpdateInView); } } /*! Gets the curve name. */ -QString Plot2d_AnaliticCurve::getName() const { +QString Plot2d_AnalyticalCurve::getName() const { return myName; } @@ -420,14 +444,14 @@ QString Plot2d_AnaliticCurve::getName() const { /*! Sets the curve action. */ -void Plot2d_AnaliticCurve::setAction(const int act) { - if( act == Plot2d_AnaliticCurve::ActNothing ) { +void Plot2d_AnalyticalCurve::setAction(const int act) { + if( act == Plot2d_AnalyticalCurve::ActNothing ) { myAction = act; return; } - if(myAction != Plot2d_AnaliticCurve::ActAddInView && - myAction != Plot2d_AnaliticCurve::ActRemoveFromView) { + if(myAction != Plot2d_AnalyticalCurve::ActAddInView && + myAction != Plot2d_AnalyticalCurve::ActRemoveFromView) { myAction = act; } } @@ -435,30 +459,54 @@ void Plot2d_AnaliticCurve::setAction(const int act) { /*! Gets the curve action. */ -int Plot2d_AnaliticCurve::getAction() const { +int Plot2d_AnalyticalCurve::getAction() const { return myAction; } /*! Gets the curve state. */ -int Plot2d_AnaliticCurve::state() const { +int Plot2d_AnalyticalCurve::state() const { return myState; } /*! Sets the curve active status. */ -void Plot2d_AnaliticCurve::setActive(const bool on) { +void Plot2d_AnalyticalCurve::setActive(const bool on) { if( myActive != on ) { + if(myActive && !on) + setAction(Plot2d_AnalyticalCurve::ActUpdateInView); + else if(!myActive && on) { + setAction(Plot2d_AnalyticalCurve::ActAddInView); + myState = Plot2d_AnalyticalCurve::StateNeedUpdate; + } myActive = on; - setAction(Plot2d_AnaliticCurve::ActUpdateInView); } } /*! Gets the curve active status. */ -bool Plot2d_AnaliticCurve::isActive() const { +bool Plot2d_AnalyticalCurve::isActive() const { return myActive; } + + +/*! + Sets curve's selected property. +*/ +void Plot2d_AnalyticalCurve::setSelected(const bool on) { + if(myIsSelected != on) { + myIsSelected = on; + setAction(Plot2d_AnalyticalCurve::ActUpdateInView); + } + +} + +/*! + Gets curve's selected property. +*/ +bool Plot2d_AnalyticalCurve::isSelected() const { + return myIsSelected; +} diff --git a/src/Plot2d/Plot2d_AnaliticCurve.h b/src/Plot2d/Plot2d_AnalyticalCurve.h old mode 100644 new mode 100755 similarity index 77% rename from src/Plot2d/Plot2d_AnaliticCurve.h rename to src/Plot2d/Plot2d_AnalyticalCurve.h index 2cf9914b8..2fd9e099d --- a/src/Plot2d/Plot2d_AnaliticCurve.h +++ b/src/Plot2d/Plot2d_AnalyticalCurve.h @@ -19,11 +19,11 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// File : Plot2d_AnaliticCurve.h +// File : Plot2d_AnalyticalCurve.h // Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com) -#ifndef PLOT2D_ANALITIC_CURVE_H -#define PLOT2D_ANALITIC_CURVE_H +#ifndef PLOT2D_ANALYTICAL_CURVE_H +#define PLOT2D_ANALYTICAL_CURVE_H #include "Plot2d.h" @@ -32,7 +32,7 @@ class QwtPlot; class QwtPlotItem; -class PLOT2D_EXPORT Plot2d_AnaliticCurve +class PLOT2D_EXPORT Plot2d_AnalyticalCurve { public: @@ -54,20 +54,25 @@ public: StateNeedUpdate }; - Plot2d_AnaliticCurve(); - Plot2d_AnaliticCurve( const Plot2d_AnaliticCurve& ); - Plot2d_AnaliticCurve& operator= ( const Plot2d_AnaliticCurve& ); + Plot2d_AnalyticalCurve(); + Plot2d_AnalyticalCurve( const Plot2d_AnalyticalCurve& ); + Plot2d_AnalyticalCurve& operator= ( const Plot2d_AnalyticalCurve& ); - virtual ~Plot2d_AnaliticCurve(); + virtual ~Plot2d_AnalyticalCurve(); virtual QwtPlotItem* plotItem(); virtual void autoFill( const QwtPlot* ); virtual void updatePlotItem(); + virtual bool checkCurve( const QwtPlot* ); virtual void calculate(); long getData( double** , double** ) const; + void setSelected(const bool); + bool isSelected() const; + + void setAutoAssign( bool ); bool isAutoAssign( ) const; @@ -128,13 +133,24 @@ protected: int myState; QwtPlotItem* myCurve; bool myActive; + bool myIsSelected; private: static int myNbCurves; }; -typedef QList AnaliticCurveList; +typedef QList AnalyticalCurveList; + +class PLOT2D_EXPORT Plot2d_CurveContainer +{ +public: + virtual void addAnalyticalCurve( Plot2d_AnalyticalCurve* ) = 0; + virtual void removeAnalyticalCurve( Plot2d_AnalyticalCurve* ) = 0; + virtual void updateAnalyticalCurve( Plot2d_AnalyticalCurve*, bool = false ) = 0; + virtual void updateAnalyticalCurves() = 0; + virtual AnalyticalCurveList getAnalyticalCurves() const = 0; +}; -#endif //PLOT2D_ANALITIC_CURVE_H +#endif //PLOT2D_ANALYTICAL_CURVE_H diff --git a/src/Plot2d/Plot2d_AnalyticalCurveDlg.cxx b/src/Plot2d/Plot2d_AnalyticalCurveDlg.cxx new file mode 100755 index 000000000..a57dd27a7 --- /dev/null +++ b/src/Plot2d/Plot2d_AnalyticalCurveDlg.cxx @@ -0,0 +1,705 @@ +// 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.cxx +// Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com) + + + +// TODO : check what happens if invalid formula is given, e.g. x/0 +// TODO : check what happens if curve formala is valid in general but some there are some problems with calculating (e.g. logarithmic formulas and negative x) + +//Local includes +#include "Plot2d_AnalyticalCurveDlg.h" +#include "Plot2d_AnalyticalCurve.h" +#include "Plot2d_ViewFrame.h" + +//Qtx includes +#include +#include + +//SUIT includes +#include +#include +#include + +//Qt includes +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//qwt includes +#include + +// Controls +const int MIN_NB_INTERVALS = 1; +const int MAX_NB_INTERVALS = 10000; +const int STEP = 1; +const int MIN_LINE_WIDTH = 0; +const int MAX_LINE_WIDTH = 10; + +const char* PROP_TITLE = "title"; +const char* PROP_VISIBLE = "visible"; +const char* PROP_STATUS = "status"; +const char* PROP_FORMULA = "formula"; +const char* PROP_NBINTERVALS = "nb_intervals"; +const char* PROP_AUTOASSIGN = "auto_assign"; +const char* PROP_MARKERTYPE = "marker_type"; +const char* PROP_LINETYPE = "line_type"; +const char* PROP_LINEWIDTH = "line_width"; +const char* PROP_COLOR = "color"; + +/* + \class Plot2d_AnalyticalCurveDlg::UpdateLocker + \brief Update locker class + \internal +*/ +class Plot2d_AnalyticalCurveDlg::UpdateLocker +{ +public: + UpdateLocker( QObject* ); + ~UpdateLocker(); +private: + QObject* myObject; + bool myLocked; +}; + +Plot2d_AnalyticalCurveDlg::UpdateLocker::UpdateLocker( QObject* object ) : myObject( object ) +{ + myLocked = myObject->blockSignals( true ); +} + +Plot2d_AnalyticalCurveDlg::UpdateLocker::~UpdateLocker() +{ + myObject->blockSignals( myLocked ); +} + +/* + \class Plot2d_AnalyticalCurveDlg::Updater + \brief Auxiliary class used for handle update requests from sub-widgets + \internal +*/ + +Plot2d_AnalyticalCurveDlg::Updater::Updater( QWidget* parent ) : QObject( parent ) +{/*nothing to do*/} + +Plot2d_AnalyticalCurveDlg::Updater::~Updater() +{/*nothing to do*/} + +/*! + Constructor +*/ +Plot2d_AnalyticalCurveDlg::Plot2d_AnalyticalCurveDlg( Plot2d_CurveContainer* container, QWidget* parent ) + : QDialog( parent ), myContainer( container ) +{ + setModal( true ); + setWindowTitle( tr( "ANALYTICAL_CURVE_TLT" ) ); + setSizeGripEnabled( true ); + + // Curves list widget + myCurvesList = new QListWidget( this ); + myCurvesList->setSelectionMode( QAbstractItemView::SingleSelection ); + + // Curve parameters group box + myCurveParams = new QGroupBox( tr( "AC_CURVE_PARAMS" ), this ); + + QLabel* formulaLabel = new QLabel( tr( "AC_FORMULA" ), myCurveParams ); + myFormula = new QLineEdit( myCurveParams ); + QLabel* nbIntervalsLabel = new QLabel( tr( "AC_NB_INTERVALS" ), myCurveParams ); + myNbIntervals = new QtxIntSpinBox( MIN_NB_INTERVALS, MAX_NB_INTERVALS, STEP, myCurveParams ); + + QGridLayout* paramsLayout = new QGridLayout( myCurveParams ); + paramsLayout->addWidget( formulaLabel, 0, 0 ); + paramsLayout->addWidget( myFormula, 0, 1 ); + paramsLayout->addWidget( nbIntervalsLabel, 1, 0 ); + paramsLayout->addWidget( myNbIntervals, 1, 1 ); + + // Curve properties group box + myCurveProps = new QGroupBox( tr( "AC_CURVE_PROPS" ), this ); + + myAutoAssign = new QCheckBox( tr( "AC_AUTO_ASSIGN" ), myCurveProps ); + myPropsGrp = new QWidget( myCurveProps ); + QLabel* markerLabel = new QLabel( tr( "AC_MARKER_TYPE" ), myPropsGrp ); + myMarkerType = new QComboBox( myPropsGrp ); + QLabel* lineTypeLabel = new QLabel( tr( "AC_LINE_TYPE" ), myPropsGrp ); + myLineType = new QComboBox( myPropsGrp ); + QLabel* lineWidthLabel = new QLabel( tr( "AC_LINE_WIDTH" ), myPropsGrp ); + myLineWidth = new QtxIntSpinBox( MIN_LINE_WIDTH, MAX_LINE_WIDTH, STEP, myPropsGrp ); + QLabel* colorLabel = new QLabel( tr("AC_CURVE_COLOR"), myPropsGrp ); + myColor = new QtxColorButton( myPropsGrp ); + + QGridLayout* propsGrpLayout = new QGridLayout( myPropsGrp ); + propsGrpLayout->addWidget( markerLabel, 0, 0 ); + propsGrpLayout->addWidget( myMarkerType, 0, 1 ); + propsGrpLayout->addWidget( lineTypeLabel, 1, 0 ); + propsGrpLayout->addWidget( myLineType, 1, 1 ); + propsGrpLayout->addWidget( lineWidthLabel, 2, 0 ); + propsGrpLayout->addWidget( myLineWidth, 2, 1 ); + propsGrpLayout->addWidget( colorLabel, 3, 0 ); + propsGrpLayout->addWidget( myColor, 3, 1 ); + + QVBoxLayout* propsLayout = new QVBoxLayout( myCurveProps ); + propsLayout->addWidget( myAutoAssign ); + propsLayout->addWidget( myPropsGrp ); + + // Add && Remove buttons + myAddButton = new QPushButton( tr("AC_ADD_BTN"), this ); + myAddButton->setAutoDefault( true ); + myRemoveButton = new QPushButton( tr("AC_REM_BTN"), this ); + myRemoveButton->setAutoDefault( true ); + + // OK, Apply, Close, Help buttons + QPushButton* okButton = new QPushButton( tr( "AC_OK_BTN" ), this ); + okButton->setDefault( true ); + okButton->setAutoDefault( true ); + + QPushButton* applyButton = new QPushButton( tr( "AC_APPLY_BTN" ), this ); + applyButton->setAutoDefault( true ); + + QPushButton* cancelButton = new QPushButton( tr( "AC_CLOSE_BTN" ), this ); + cancelButton->setAutoDefault( true ); + QPushButton* helpButton = new QPushButton( tr( "AC_HELP_BTN" ), this ); + helpButton->setAutoDefault( true ); + QHBoxLayout* btnLayout = new QHBoxLayout; + btnLayout->addWidget( okButton ); + btnLayout->addWidget( applyButton ); + btnLayout->addStretch(); + btnLayout->addWidget( cancelButton ); + btnLayout->addWidget( helpButton ); + + QGridLayout* mainLayout = new QGridLayout( this ); + mainLayout->addWidget( myCurvesList, 0, 0, 3, 1 ); + mainLayout->addWidget( myCurveParams, 0, 1, 1, 2 ); + mainLayout->addWidget( myCurveProps, 1, 1, 1, 2 ); + mainLayout->addWidget( myAddButton, 2, 1 ); + mainLayout->addWidget( myRemoveButton, 2, 2 ); + mainLayout->addLayout( btnLayout, 3, 0, 1, 3 ); + + // Fill combo boxes + QColor cl = myMarkerType->palette().color( QPalette::Text ); // color to draw markers + QSize sz = QSize( 16, 16 ); // size of the icons for markers + myMarkerType->setIconSize( sz ); + + myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::None ), tr( "NONE_MARKER_LBL" ) ); + myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::Circle ), tr( "CIRCLE_MARKER_LBL" ) ); + myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::Rectangle ), tr( "RECTANGLE_MARKER_LBL" ) ); + myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::Diamond ), tr( "DIAMOND_MARKER_LBL" ) ); + myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::DTriangle ), tr( "DTRIANGLE_MARKER_LBL" ) ); + myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::UTriangle ), tr( "UTRIANGLE_MARKER_LBL" ) ); + myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::LTriangle ), tr( "LTRIANGLE_MARKER_LBL" ) ); + myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::RTriangle ), tr( "RTRIANGLE_MARKER_LBL" ) ); + myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::Cross ), tr( "CROSS_MARKER_LBL" ) ); + myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::XCross ), tr( "XCROSS_MARKER_LBL" ) ); + + cl = myLineType->palette().color( QPalette::Text ); // color to draw line types + sz = QSize( 40, 16 ); // size of the icons for line types + myLineType->setIconSize( sz ); + + myLineType->addItem( Plot2d::lineIcon( sz, cl, Plot2d::NoPen ), tr( "NONE_LINE_LBL" ) ); + myLineType->addItem( Plot2d::lineIcon( sz, cl, Plot2d::Solid ), tr( "SOLID_LINE_LBL" ) ); + myLineType->addItem( Plot2d::lineIcon( sz, cl, Plot2d::Dash ), tr( "DASH_LINE_LBL" ) ); + myLineType->addItem( Plot2d::lineIcon( sz, cl, Plot2d::Dot ), tr( "DOT_LINE_LBL" ) ); + myLineType->addItem( Plot2d::lineIcon( sz, cl, Plot2d::DashDot ), tr( "DASHDOT_LINE_LBL" ) ); + myLineType->addItem( Plot2d::lineIcon( sz, cl, Plot2d::DashDotDot ), tr( "DAHSDOTDOT_LINE_LBL" ) ); + + // Connections + myUpdater = new Updater( this ); + connect( myUpdater, SIGNAL( update() ), this, SLOT( updateCurve() ) ); + connect( myFormula, SIGNAL( textChanged( QString ) ), myUpdater, SIGNAL( update() ) ); + connect( myNbIntervals, SIGNAL( valueChanged( int ) ), myUpdater, SIGNAL( update() ) ); + connect( myAutoAssign, SIGNAL( stateChanged( int ) ), myUpdater, SIGNAL( update() ) ); + connect( myMarkerType, SIGNAL( activated( int ) ), myUpdater, SIGNAL( update() ) ); + connect( myLineType, SIGNAL( activated( int ) ), myUpdater, SIGNAL( update() ) ); + connect( myLineWidth, SIGNAL( valueChanged( int ) ), myUpdater, SIGNAL( update() ) ); + connect( myColor, SIGNAL( changed( QColor ) ), myUpdater, SIGNAL( update() ) ); + connect( myCurvesList, SIGNAL( itemChanged( QListWidgetItem* ) ), myUpdater, SIGNAL( update() ) ); + connect( myCurvesList, SIGNAL( itemSelectionChanged() ), this, SLOT( selectionChanged() ) ); + connect( myAddButton, SIGNAL( clicked() ), this, SLOT( addCurve() ) ); + connect( myRemoveButton, SIGNAL( clicked()), this, SLOT( removeCurve() ) ); + connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) ); + connect( applyButton, SIGNAL( clicked() ), this, SLOT( apply() ) ); + connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) ); + connect( helpButton, SIGNAL( clicked() ), this, SLOT( help() ) ); + + // Initialize dialog box + init(); +} + +/*! + Destructor +*/ +Plot2d_AnalyticalCurveDlg::~Plot2d_AnalyticalCurveDlg() +{ +} + +void Plot2d_AnalyticalCurveDlg::init() +{ + AnalyticalCurveList curves = myContainer->getAnalyticalCurves(); + foreach ( Plot2d_AnalyticalCurve* curve, curves ) { + QListWidgetItem* item = new QListWidgetItem( curve->getName() ); + item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled ); + item->setCheckState( curve->isActive() ? Qt::Checked : Qt::Unchecked ); + initPropsFromCurve(curve); + QVariant var; + var.setValue( (void*)curve ); + item->setData( Qt::UserRole, var ); + myCurvesList->addItem( item ); + + if ( !myCurvesList->currentItem() ) + myCurvesList->setCurrentItem( item ); + } + + selectionChanged(); +} + +/*! + /brief Store curve properties in the local map. +*/ +void Plot2d_AnalyticalCurveDlg::initPropsFromCurve(Plot2d_AnalyticalCurve* curve) { + myProperties[ curve ][ PROP_TITLE ] = curve->getName(); + myProperties[ curve ][ PROP_VISIBLE ] = curve->isActive(); + myProperties[ curve ][ PROP_FORMULA ] = curve->getExpression(); + myProperties[ curve ][ PROP_NBINTERVALS ] = (int)curve->getNbIntervals(); + myProperties[ curve ][ PROP_AUTOASSIGN ] = curve->isAutoAssign(); + myProperties[ curve ][ PROP_MARKERTYPE ] = curve->getMarker(); + myProperties[ curve ][ PROP_LINETYPE ] = curve->getLine(); + myProperties[ curve ][ PROP_LINEWIDTH ] = curve->getLineWidth(); + myProperties[ curve ][ PROP_COLOR ] = curve->getColor(); + myProperties[ curve ][ PROP_STATUS ] = ItemExisting; +} + +QwtPlot* Plot2d_AnalyticalCurveDlg::getPlot() { + Plot2d_ViewFrame* frame = dynamic_cast(myContainer); + if( frame ) + return frame->getPlot(); + return 0; +} + +/*! + /brief Store local copy on the curves properties into curves. +*/ +bool Plot2d_AnalyticalCurveDlg::processCurves() { + // update curves + + QwtPlot* plot = getPlot(); + if(!plot) + return false; + + PropMap::Iterator it; + for ( it = myProperties.begin(); it != myProperties.end(); ++it ) { + Plot2d_AnalyticalCurve* curve = it.key(); + if ( propStatus( curve ) == ItemRemoved ) { + myContainer->removeAnalyticalCurve( curve ); + continue; + } + curve->setName( propTitle( curve ) ); + curve->setActive( propVisible( curve ) ); + curve->setExpression( propFormula( curve ) ); + curve->setNbIntervals( propIntervals(curve) ); + bool prevValue = curve->isAutoAssign(); + curve->setAutoAssign( propAutoAssign( curve ) ); + if ( !curve->isAutoAssign() ) { + curve->setMarker( propMarkerType( curve ) ); + curve->setLine( propLineType( curve ) ); + curve->setLineWidth( propLineWidth( curve ) ); + curve->setColor( propColor( curve ) ); + } else { + if(!prevValue){ + curve->autoFill(plot); + } + } + + if (! curve->checkCurve(plot) ) { + QListWidgetItem* item = getItem(curve); + if(item) { + myCurvesList->setCurrentItem( item ); + SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "AC_CANT_CALCULATE" ) ); + } + return false; + } + + if ( propStatus( curve ) == ItemAdded ) { + myContainer->addAnalyticalCurve( curve ); + myProperties[ curve ][ PROP_STATUS ] = ItemExisting; + } + } + return true; +} + +/*! + \brief Private slot. Called when "Apply" button is clicked +*/ +void Plot2d_AnalyticalCurveDlg::apply() { + if(processCurves()) { + Plot2d_ViewFrame* f = dynamic_cast(myContainer); + if(f) + f->updateAnalyticalCurves(); + + AnalyticalCurveList curves = myContainer->getAnalyticalCurves(); + foreach ( Plot2d_AnalyticalCurve* curve, curves ) { + initPropsFromCurve(curve); + } + selectionChanged(); + } +} + +/*! + \brief Private slot. Called when "Ok" button is clicked +*/ +void Plot2d_AnalyticalCurveDlg::accept() +{ + if(processCurves()) + QDialog::accept(); +} + +/*! + \brief Private slot. Called when "Close" button is clicked +*/ +void Plot2d_AnalyticalCurveDlg::reject() +{ + // clean-up curves just created + PropMap::Iterator it; + for ( it = myProperties.begin(); it != myProperties.end(); ++it ) { + Plot2d_AnalyticalCurve* curve = it.key(); + if ( propStatus( curve ) == ItemAdded ) + delete curve; + } + QDialog::reject(); +} + +/*! + \brief Private slot. Called when "Add curve" button is clicked +*/ +void Plot2d_AnalyticalCurveDlg::addCurve() +{ + Plot2d_AnalyticalCurve* curve = new Plot2d_AnalyticalCurve(); + + if(curve->isAutoAssign()) { + QwtPlot* plot = getPlot(); + if(plot) + curve->autoFill(plot); + } + + QListWidgetItem* item = new QListWidgetItem(curve->getName()); + item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled ); + item->setCheckState( Qt::Checked ); + QVariant var; + var.setValue( (void*)curve ); + item->setData( Qt::UserRole, var ); + myCurvesList->addItem( item ); + + myProperties[ curve ][ PROP_STATUS ] = ItemAdded; + + myCurvesList->setCurrentItem( item ); +} + +/*! + \brief Private slot. Called when "Remove curve" button is clicked +*/ +void Plot2d_AnalyticalCurveDlg::removeCurve() +{ + QList items = myCurvesList->selectedItems(); + foreach( QListWidgetItem* item, items ) { + Plot2d_AnalyticalCurve* curve = (Plot2d_AnalyticalCurve*)( item->data( Qt::UserRole ).value() ); + delete item; + if ( propStatus( curve ) == ItemAdded ) { + myProperties.remove( curve ); + delete curve; + } + else { + myProperties[ curve ][ PROP_STATUS ] = ItemRemoved; + } + } +} + +/*! + \brief Private slot. Called when any curve property is changed. +*/ +void Plot2d_AnalyticalCurveDlg::updateCurve() +{ + UpdateLocker lock( myUpdater ); + + QListWidgetItem* item = selected(); + Plot2d_AnalyticalCurve* curve = selectedCurve(); + if ( item && curve ) { + myProperties[ curve ][ PROP_TITLE ] = item->text(); + myProperties[ curve ][ PROP_VISIBLE ] = item->checkState() == Qt::Checked; + myProperties[ curve ][ PROP_FORMULA ] = myFormula->text(); + myProperties[ curve ][ PROP_NBINTERVALS ] = myNbIntervals->value(); + myProperties[ curve ][ PROP_AUTOASSIGN ] = myAutoAssign->isChecked(); + myProperties[ curve ][ PROP_MARKERTYPE ] = myMarkerType->currentIndex(); + myProperties[ curve ][ PROP_LINETYPE ] = myLineType->currentIndex(); + myProperties[ curve ][ PROP_LINEWIDTH ] = myLineWidth->value(); + myProperties[ curve ][ PROP_COLOR ] = myColor->color(); + } + + updateState(); +} + +/*! + \brief Private slot. Update widgets state. +*/ +void Plot2d_AnalyticalCurveDlg::updateState() +{ + myPropsGrp->setEnabled( !myAutoAssign->isChecked() ); + myCurveParams->setEnabled( selectedCurve() != 0 ); + myCurveProps->setEnabled( selectedCurve() != 0 ); + myRemoveButton->setEnabled( selectedCurve() != 0 ); +} + +/*! + \brief Private slot. Called when selection in the curve list is changed. +*/ +void Plot2d_AnalyticalCurveDlg::selectionChanged() +{ + UpdateLocker lock( myUpdater ); + + Plot2d_AnalyticalCurve* curve = selectedCurve(); + + myFormula->setText( propFormula( curve ) ); + myNbIntervals->setValue( propIntervals( curve ) ); + myMarkerType->setCurrentIndex( (int)propMarkerType( curve ) ); + myLineType->setCurrentIndex( (int)propLineType( curve ) ); + myLineWidth->setValue( propLineWidth( curve ) ); + myColor->setColor( propColor( curve ) ); + myAutoAssign->setChecked( propAutoAssign( curve ) ); + + updateState(); +} + +/*! + \brief Show help page +*/ +void Plot2d_AnalyticalCurveDlg::help() +{ + SUIT_Application* app = SUIT_Session::session()->activeApplication(); + if ( app ) + app->onHelpContextModule( "GUI", "plot2d_analytical_curves.html" ); +} + +/*! + \brief Get currently selected list widget item +*/ +QListWidgetItem* Plot2d_AnalyticalCurveDlg::selected() const +{ + QList items = myCurvesList->selectedItems(); + return items.count() > 0 ? items[0] : 0; +} + +/*! + \brief Get widget item by the curve +*/ +QListWidgetItem* Plot2d_AnalyticalCurveDlg::getItem(Plot2d_AnalyticalCurve* theCurve) const +{ + int nb = myCurvesList->count(); + QListWidgetItem* item = 0; + for(int i = 0; i < nb ; i++) { + item = myCurvesList->item(i); + if(item->data( Qt::UserRole ).value() == theCurve) + break; + } + return item; +} + +/*! + \brief Get currently selected curve +*/ +Plot2d_AnalyticalCurve* Plot2d_AnalyticalCurveDlg::selectedCurve() const +{ + return selected() ? (Plot2d_AnalyticalCurve*)( selected()->data( Qt::UserRole ).value() ) : 0; +} + +/*! + \brief Get curve property: status +*/ +int Plot2d_AnalyticalCurveDlg::propStatus( Plot2d_AnalyticalCurve* curve, const int def ) +{ + int val = def; + if ( curve ) { + if ( !myProperties.contains( curve ) ) + myProperties[ curve ] = CurveProps(); + if ( !myProperties[ curve ].contains( PROP_STATUS ) ) + myProperties[ curve ][ PROP_STATUS ] = def; + QVariant v = myProperties[ curve ][ PROP_STATUS ]; + if ( v.isValid() && v.type() == QVariant::Int ) val = v.toInt(); + } + return val; +} + +/*! + \brief Get curve property: title +*/ +QString Plot2d_AnalyticalCurveDlg::propTitle( Plot2d_AnalyticalCurve* curve, const QString& def ) +{ + QString val = def; + if ( curve ) { + if ( !myProperties.contains( curve ) ) + myProperties[ curve ] = CurveProps(); + if ( !myProperties[ curve ].contains( PROP_TITLE ) ) + myProperties[ curve ][ PROP_TITLE ] = def; + QVariant v = myProperties[ curve ][ PROP_TITLE ]; + if ( v.isValid() && v.type() == QVariant::String ) val = v.toString(); + } + return val; +} + +/*! + \brief Get curve property: visible flag +*/ +bool Plot2d_AnalyticalCurveDlg::propVisible( Plot2d_AnalyticalCurve* curve, bool def ) +{ + bool val = def; + if ( curve ) { + if ( !myProperties.contains( curve ) ) + myProperties[ curve ] = CurveProps(); + if ( !myProperties[ curve ].contains( PROP_VISIBLE ) ) + myProperties[ curve ][ PROP_VISIBLE ] = def; + QVariant v = myProperties[ curve ][ PROP_VISIBLE ]; + if ( v.isValid() && v.type() == QVariant::Bool ) val = v.toBool(); + } + return val; +} + +/*! + \brief Get curve property: formula +*/ +QString Plot2d_AnalyticalCurveDlg::propFormula( Plot2d_AnalyticalCurve* curve, const QString& def ) +{ + QString val = def; + if ( curve ) { + if ( !myProperties.contains( curve ) ) + myProperties[ curve ] = CurveProps(); + if ( !myProperties[ curve ].contains( PROP_FORMULA ) ) + myProperties[ curve ][ PROP_FORMULA ] = def; + QVariant v = myProperties[ curve ][ PROP_FORMULA ]; + if ( v.isValid() && v.type() == QVariant::String ) val = v.toString(); + } + return val; +} + +/*! + \brief Get curve property: nb intervals +*/ +int Plot2d_AnalyticalCurveDlg::propIntervals( Plot2d_AnalyticalCurve* curve, int def ) +{ + int val = def; + if ( curve ) { + if ( !myProperties.contains( curve ) ) + myProperties[ curve ] = CurveProps(); + if ( !myProperties[ curve ].contains( PROP_NBINTERVALS ) ) + myProperties[ curve ][ PROP_NBINTERVALS ] = def; + QVariant v = myProperties[ curve ][ PROP_NBINTERVALS ]; + if ( v.isValid() && v.type() == QVariant::Int ) val = v.toInt(); + } + return val; +} + +/*! + \brief Get curve property: marker type +*/ +Plot2d::MarkerType Plot2d_AnalyticalCurveDlg::propMarkerType( Plot2d_AnalyticalCurve* curve, Plot2d::MarkerType def ) +{ + Plot2d::MarkerType val = def; + if ( curve ) { + if ( !myProperties.contains( curve ) ) + myProperties[ curve ] = CurveProps(); + if ( !myProperties[ curve ].contains( PROP_MARKERTYPE ) ) + myProperties[ curve ][ PROP_MARKERTYPE ] = def; + QVariant v = myProperties[ curve ][ PROP_MARKERTYPE ]; + if ( v.isValid() && v.type() == QVariant::Int ) val = (Plot2d::MarkerType)( v.toInt() ); + } + return val; +} + +/*! + \brief Get curve property: line type +*/ +Plot2d::LineType Plot2d_AnalyticalCurveDlg::propLineType( Plot2d_AnalyticalCurve* curve, Plot2d::LineType def ) +{ + Plot2d::LineType val = def; + if ( curve ) { + if ( !myProperties.contains( curve ) ) + myProperties[ curve ] = CurveProps(); + if ( !myProperties[ curve ].contains( PROP_LINETYPE ) ) + myProperties[ curve ][ PROP_LINETYPE ] = def; + QVariant v = myProperties[ curve ][ PROP_LINETYPE ]; + if ( v.isValid() && v.type() == QVariant::Int ) val = (Plot2d::LineType)( v.toInt() ); + } + return val; +} + +/*! + \brief Get curve property: line width +*/ +int Plot2d_AnalyticalCurveDlg::propLineWidth( Plot2d_AnalyticalCurve* curve, int def ) +{ + int val = def; + if ( curve ) { + if ( !myProperties.contains( curve ) ) + myProperties[ curve ] = CurveProps(); + if ( !myProperties[ curve ].contains( PROP_LINEWIDTH ) ) + myProperties[ curve ][ PROP_LINEWIDTH ] = def; + QVariant v = myProperties[ curve ][ PROP_LINEWIDTH ]; + if ( v.isValid() && v.type() == QVariant::Int ) val = v.toInt(); + } + return val; +} + +/*! + \brief Get curve property: color +*/ +QColor Plot2d_AnalyticalCurveDlg::propColor( Plot2d_AnalyticalCurve* curve, const QColor& def ) +{ + QColor val = def; + if ( curve ) { + if ( !myProperties.contains( curve ) ) + myProperties[ curve ] = CurveProps(); + if ( !myProperties[ curve ].contains( PROP_COLOR ) ) + myProperties[ curve ][ PROP_COLOR ] = def; + QVariant v = myProperties[ curve ][ PROP_COLOR ]; + if ( v.isValid() && v.type() == QVariant::Color ) val = v.value(); + } + return val; +} + +/*! + \brief Get curve property: auto-assign flag +*/ +bool Plot2d_AnalyticalCurveDlg::propAutoAssign( Plot2d_AnalyticalCurve* curve, bool def ) +{ + bool val = def; + if ( curve ) { + if ( !myProperties.contains( curve ) ) + myProperties[ curve ] = CurveProps(); + if ( !myProperties[ curve ].contains( PROP_AUTOASSIGN ) ) + myProperties[ curve ][ PROP_AUTOASSIGN ] = def; + QVariant v = myProperties[ curve ][ PROP_AUTOASSIGN ]; + if ( v.isValid() && v.type() == QVariant::Bool ) val = v.toBool(); + } + return val; +} -- 2.39.2