Salome HOME
Copyright update 2022
[modules/gui.git] / src / Plot2d / Plot2d_ViewFrame.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 083f80b..6046482
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022  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
@@ -6,7 +6,7 @@
 // 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.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 #include <qwt_plot_zoomer.h>
 #include <qwt_curve_fitter.h>
 #include <qwt_plot_renderer.h>
+#include <qwt_legend.h>
+#include <qwt_scale_widget.h>
 
 #include <stdlib.h>
 #include <limits>
-#include <qprinter.h>
-
-#include <qwt_legend.h>
-#include <qwt_scale_widget.h>
 
 #define DEFAULT_LINE_WIDTH     0     // (default) line width
 #define DEFAULT_MARKER_SIZE    9     // default marker size
@@ -769,12 +767,12 @@ QVector< QVector<QwtPlotCurve *> > Plot2d_ViewFrame::displayPlot2dCurveList( con
       icur2 = icur1 + groupSize -1;
 
       // For all curves in one group
-      double XgroupMin, XgroupMax;
-      double YgroupMin, YgroupMax;
+      double XgroupMin = 0., XgroupMax = 0.;
+      double YgroupMin = 0., YgroupMax = 0.;
 
       // For one curve
-      double XcurveMin, XcurveMax;
-      double YcurveMin, YcurveMax;
+      double XcurveMin = 0., XcurveMax = 0.;
+      double YcurveMin = 0., YcurveMax = 0.;
       double *Xval;
       double *Yval;
       int nbPoints;
@@ -979,7 +977,7 @@ Plot2d_Curve* Plot2d_ViewFrame::createPlot2dCurve( QString & title,
                                                    int lineWidth,
                                                    QColor & lineColor,
                                                    QwtSymbol::Style markerKind,
-                                                   Plot2d_QwtPlotPicker* picker,
+                                                   Plot2d_QwtPlotPicker* /*picker*/,
                                                    bool toDraw,
                                                    bool displayLegend)
 {
@@ -1094,7 +1092,7 @@ QwtPlotCurve *Plot2d_ViewFrame::createSegment( double *X, double *Y, int nbPoint
   aPCurve->setSamples( X, Y, nbPoint);
 
   aPCurve->setPen( QPen( lineColor, lineWidth, lineKind));
-  QwtSymbol* aSymbol;
+  QwtSymbol* aSymbol = new QwtSymbol();
   aSymbol->setStyle( markerKind );
   aPCurve->setSymbol( aSymbol );
 
@@ -1642,10 +1640,10 @@ void Plot2d_ViewFrame::getFitRangeByMarkers(double& xMin,  double& xMax,
 */
 int Plot2d_ViewFrame::testOperation( const QMouseEvent& me )
 {
-  int btn = me.button() | me.modifiers();
-  const int zoomBtn = Qt::ControlModifier | Qt::LeftButton;
-  const int panBtn  = Qt::ControlModifier | Qt::MidButton;
-  const int fitBtn  = Qt::ControlModifier | Qt::RightButton;
+  int btn = (int)me.button() | (int)me.modifiers();
+  const int zoomBtn = (int)Qt::ControlModifier | (int)Qt::LeftButton;
+  const int panBtn  = (int)Qt::ControlModifier | (int)Qt::MidButton;
+  const int fitBtn  = (int)Qt::ControlModifier | (int)Qt::RightButton;
 
   int op = NoOpId;
   if ( btn == zoomBtn ) {
@@ -1849,25 +1847,19 @@ void Plot2d_ViewFrame::onSettings()
 */
 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
+  myAnalyticalCurves.append(theCurve);
 }
 
 void Plot2d_ViewFrame::removeAnalyticalCurve( Plot2d_AnalyticalCurve* theCurve)
 {
-#ifndef DISABLE_PYCONSOLE
-       theCurve->setAction(Plot2d_AnalyticalCurve::ActRemoveFromView);
-#endif
+  theCurve->setAction(Plot2d_AnalyticalCurve::ActRemoveFromView);
 }
 
 /*
@@ -1875,7 +1867,6 @@ void Plot2d_ViewFrame::removeAnalyticalCurve( Plot2d_AnalyticalCurve* theCurve)
 */
 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());
@@ -1909,14 +1900,11 @@ void Plot2d_ViewFrame::updateAnalyticalCurve(Plot2d_AnalyticalCurve* c, bool upd
   case Plot2d_AnalyticalCurve::ActRemoveFromView:
     item->hide();
     item->detach();
-    myAnalyticalCurves.removeAll(c);
-    delete c;
     break;
   }
 
   if(updateView)
     myPlot->replot();
-#endif
 }
 
 /*
@@ -1924,13 +1912,22 @@ void Plot2d_ViewFrame::updateAnalyticalCurve(Plot2d_AnalyticalCurve* c, bool upd
 */
 void Plot2d_ViewFrame::updateAnalyticalCurves()
 {
-#ifndef DISABLE_PYCONSOLE
   AnalyticalCurveList::iterator it = myAnalyticalCurves.begin();
+  AnalyticalCurveList toDelete;
   for( ; it != myAnalyticalCurves.end(); it++) {
-    updateAnalyticalCurve(*it);
+    Plot2d_AnalyticalCurve* c = (*it);
+    updateAnalyticalCurve(c);
+    if(c && c->getAction() == Plot2d_AnalyticalCurve::ActRemoveFromView)
+      toDelete.push_back(c);
+  }
+  it = toDelete.begin();
+  for( ; it != toDelete.end(); it++) {
+    Plot2d_AnalyticalCurve* c = (*it);
+    myAnalyticalCurves.removeAll(c);
+    delete c;
+    c = NULL;
   }
   myPlot->replot();
-#endif
 }
 
 /*!
@@ -1938,21 +1935,19 @@ void Plot2d_ViewFrame::updateAnalyticalCurves()
 */
 AnalyticalCurveList Plot2d_ViewFrame::getAnalyticalCurves() const
 {
-  return myAnalyticalCurves;
+  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);
+    if((*it)->plotItem() == theItem)
+      return (*it);
   }
   return 0;
-#endif
 }
 #endif
 
@@ -2000,6 +1995,13 @@ void Plot2d_ViewFrame::setCurveType( int curveType, bool update )
     if ( crv )
       setCurveType( crv, myCurveType );
   }
+  for(int i=0 ; i < myAnalyticalCurves.count(); i++) {
+    QwtPlotCurve* aPCurve = dynamic_cast<QwtPlotCurve*>( myAnalyticalCurves[i]->plotItem() );
+    Plot2d_AnalyticalCurve* aCurve = dynamic_cast<Plot2d_AnalyticalCurve*>( myAnalyticalCurves[i] );
+    if ( aPCurve && aCurve ) {
+      setCurveType( aPCurve, myCurveType );
+    }
+  }
   if ( update )
     myPlot->replot();
   emit vpCurveChanged();
@@ -2431,9 +2433,9 @@ void Plot2d_ViewFrame::setHorScaleMode( const int mode, bool update )
   // non-positive X/Y coordinate
   if ( mode && !isXLogEnabled() ){
 #ifndef NO_SUIT
-    SUIT_MessageBox::warning(this, tr("WARNING"), tr("WRN_XLOG_NOT_ALLOWED"));
+    SUIT_MessageBox::warning(this, tr("WRN_WARNING"), tr("WRN_XLOG_NOT_ALLOWED"));
 #else
-    QMessageBox::warning(this, tr("WARNING"), tr("WRN_XLOG_NOT_ALLOWED"));
+    QMessageBox::warning(this, tr("WRN_WARNING"), tr("WRN_XLOG_NOT_ALLOWED"));
 #endif
     return;
   }
@@ -2474,9 +2476,9 @@ void Plot2d_ViewFrame::setVerScaleMode( const int mode, bool update )
   // non-positive X/Y coordinate
   if ( mode && !isYLogEnabled() ){
 #ifndef NO_SUIT
-    SUIT_MessageBox::warning(this, tr("WARNING"), tr("WRN_YLOG_NOT_ALLOWED"));
+    SUIT_MessageBox::warning(this, tr("WRN_WARNING"), tr("WRN_YLOG_NOT_ALLOWED"));
 #else
-    QMessageBox::warning(this, tr("WARNING"), tr("WRN_YLOG_NOT_ALLOWED"));
+    QMessageBox::warning(this, tr("WRN_WARNING"), tr("WRN_YLOG_NOT_ALLOWED"));
 #endif
     return;
   }
@@ -2688,7 +2690,7 @@ void Plot2d_ViewFrame::plotMousePressed( const QMouseEvent& me )
     }
   }
   else {
-    int btn = me.button() | me.modifiers();
+    int btn = (int)me.button() | (int)me.modifiers();
     if (btn == Qt::RightButton) {
       QMouseEvent* aEvent = new QMouseEvent(QEvent::MouseButtonPress,
                                             me.pos(), me.button(), me.buttons(), me.modifiers() );
@@ -2848,7 +2850,7 @@ bool Plot2d_ViewFrame::hasPlotObject( Plot2d_Object* object ) const
 /*!
   Sets curve type
 */
-void Plot2d_ViewFrame::setCurveType( QwtPlotCurve* curve, int curveType )
+void Plot2d_ViewFrame::setCurveType( QwtPlotCurve* curve, int /*curveType*/ )
 {
   if ( !curve )
     return;
@@ -3174,7 +3176,7 @@ QwtPlotMarker* Plot2d_Plot2d::createMarkerAndTooltip( QwtSymbol* symbol,
 QwtPlotGrid* Plot2d_Plot2d::grid() const
 {
   return myGrid;
-};
+}
 
 QwtPlotZoomer* Plot2d_Plot2d::zoomer() const
 {
@@ -3271,7 +3273,7 @@ void Plot2d_Plot2d::displayXTicksAndLabels(
   QList<double> allTicks;
 
   double devXmin, devXmax;  // X interval of a system
-  double gapXmin, gapXmax;  // X interval between two systems
+  double gapXmin = 0., gapXmax = 0.;  // X interval between two systems
   double devLabPos;         // Label's position of a system
   double segmentPos;  // Position of the vertical segment between current system and the next
 
@@ -3836,7 +3838,7 @@ QString Plot2d_ViewFrame::getXmlVisualParameters() {
     aWriter.writeAttribute("Name",c->getName());
     aWriter.writeAttribute("IsActive", QString("").sprintf("%d",       c->isActive()));
                aWriter.writeAttribute("Expression", c->getExpression());
-    aWriter.writeAttribute("NbIntervals", QString("").sprintf("%d",    c->getNbIntervals()));
+    aWriter.writeAttribute("NbIntervals", QString("").sprintf("%ld",   c->getNbIntervals()));
     aWriter.writeAttribute("isAuto", QString("").sprintf("%d",isAuto));
     if(!isAuto) {
       aWriter.writeAttribute("Marker", QString("").sprintf("%d",(int)c->getMarker()));
@@ -3870,7 +3872,7 @@ QString Plot2d_ViewFrame::getXmlVisualParameters() {
 */
 bool Plot2d_ViewFrame::setXmlVisualParameters(const QString& parameters) {
   QXmlStreamReader aReader(parameters);
-  double xmin, xmax, ymin, ymax, y2min, y2max;
+  double xmin = 0., xmax = 0., ymin = 0., ymax = 0., y2min = 0., y2max = 0.;
   bool leftMin,leftMax,rightMin,rightMax;
   leftMin = leftMax = rightMin = rightMax = false;
   while(!aReader.atEnd()) {
@@ -4304,6 +4306,12 @@ void Plot2d_AxisScaleDraw::draw( QPainter* painter, const QPalette & palette) co
 }
 
 
+double Plot2d_AxisScaleDraw::extent( const QFont &font ) const
+{
+  QFontMetrics fm( font );
+  return QwtScaleDraw::extent( font ) + fm.height() * 2;
+}
+
 QwtText Plot2d_AxisScaleDraw::label( double value) const
 {
   if (myLabelX.contains(value))