+ return aPlotMarker;
+}
+
+QwtPlotGrid* Plot2d_Plot2d::grid() const
+{
+ return myGrid;
+};
+
+QwtPlotZoomer* Plot2d_Plot2d::zoomer() const
+{
+ return myPlotZoomer;
+}
+
+/*!
+ Updates identifiers of Y axis type in the legend.
+*/
+void Plot2d_Plot2d::updateYAxisIdentifiers()
+{
+ bool enableYLeft = false, enableYRight = false;
+ const QwtPlotItemList& items = itemList();
+ QwtPlotItemIterator it;
+ for ( it = items.begin(); it != items.end(); it++ ) {
+ QwtPlotItem* item = *it;
+ if ( item ) {
+ enableYLeft |= item->yAxis() == QwtPlot::yLeft;
+ enableYRight |= item->yAxis() == QwtPlot::yRight;
+ }
+ }
+
+ // if several curves are attached to different axes
+ // display corresponding identifiers in the legend,
+ // otherwise hide them
+ for ( it = items.begin(); it != items.end(); it++ ) {
+ QwtPlotItem* item = *it;
+ if ( Plot2d_QwtPlotCurve* aPCurve = dynamic_cast<Plot2d_QwtPlotCurve*>( item ) )
+ aPCurve->setYAxisIdentifierEnabled( enableYLeft && enableYRight );
+ if ( item && item->isVisible() && legend() )
+ item->updateLegend( item, item->legendData() );
+ }
+}
+
+// Methods to manage axis graduations
+
+/* Create definition and graduations of axes
+ */
+void Plot2d_Plot2d::createAxisScaleDraw()
+{
+ myScaleDraw = new Plot2d_AxisScaleDraw( this);
+}
+
+
+/* Stock X axis's ticks in the drawing zone
+*/
+void Plot2d_Plot2d::applyTicks()
+{
+ myScaleDraw->applyTicks();
+}
+
+
+/* Unactivate automatic ticks drawing (call to method Plot2d_AxisScaleDraw::draw() )
+ * Parameters :
+ * - number call to ticks drawing (for information) : numcall
+ */
+void Plot2d_Plot2d::unactivAxisScaleDraw( int numcall)
+{
+ // Memorize X axis (myScaleDraw already exists) in the drawing zone
+ //setAxisScaleDraw( QwtPlot::xBottom, myScaleDraw); // heritage of QwtPlot
+
+ myScaleDraw->unactivTicksDrawing( numcall);
+}
+
+
+/* Draw ticks and labels on X axis of the drawing zone
+ * Draw systems' names under the X axis of the drawing zone
+ * Draw vertical segments between X axis's intervals of the systems
+ * Parameters :
+ * - left and right margins for ticks : XLeftMargin, XRightMargin
+ * - for each named system :
+ * positions and labels for ticks on X axis : devicesPosLabelTicks
+ *
+ * The true drawings will be realized by the method Plot2d_AxisScaleDraw::draw()
+ * PB: who call il ?
+ */
+void Plot2d_Plot2d::displayXTicksAndLabels(
+ double XLeftMargin, double XRightMargin,
+ const QList< QPair< QString, QMap<double, QString> > > & devicesPosLabelTicks)
+ // name position label
+ // system tick tick
+{
+ //std::cout << "Plot2d_Plot2d::displayXTicksAndLabels() 1" << std::endl;
+
+ int nbDevices = devicesPosLabelTicks.size();
+ //
+ //std::cout << " Nombre de systemes = " << nbDevices << std::endl;
+ if (nbDevices == 0) return;
+
+ // For drawing systems' names, their positions must be in the allTicks list
+ // (cf class Plot2d_AxisScaleDraw)
+
+ // Liste of ticks' positions and systems' names
+ QList<double> allTicks;
+
+ double devXmin, devXmax; // X interval of a system
+ double gapXmin, gapXmax; // 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
+
+ // 1)- Search for the system whose X interval is the most to the left
+
+ int ileftDev = 0;
+ double XminMin = 1.e+12;
+
+ if (nbDevices > 1)
+ {
+ for (int idev=0; idev < nbDevices; idev++)
+ {
+ QPair< QString, QMap<double,QString> > paire = devicesPosLabelTicks.at(idev);
+
+ QString deviceLabel = paire.first;
+
+ // Ticks' map of the system
+ QMap<double,QString> devPosLabelTicks = paire.second;
+
+ QList<double> posTicks = devPosLabelTicks.keys();
+
+ // List's items increasing sorting
+ qSort( posTicks.begin(), posTicks.end() ); // iterators
+
+ // X interval for the system
+ devXmin = posTicks.first();
+ devXmax = posTicks.last();
+
+ if (devXmin < XminMin)
+ {
+ XminMin = devXmin;
+ ileftDev = idev;
+ }
+ }
+ }
+
+ // 2)- Ticks, systems' names, verticals segments
+
+ for (int idev=0; idev < nbDevices; idev++)
+ {
+ QPair< QString, QMap<double,QString> > paire = devicesPosLabelTicks.at(idev);
+
+ QString deviceLabel = paire.first;
+
+ std::string std_label = deviceLabel.toStdString();
+ //const char *c_label = std_label.c_str();
+ //std::cout << " deviceLabel: |" << c_label << "|" << std::endl;
+
+ // Ticks' map of the system
+ QMap<double,QString> devPosLabelTicks = paire.second;
+
+ int nbTicks = devPosLabelTicks.size();
+
+ QList<double> posTicks = devPosLabelTicks.keys();
+
+ // List's items increasing sorting
+ qSort( posTicks.begin(), posTicks.end() ); // iterators
+
+ // X interval for the system
+ devXmin = posTicks.first();
+ devXmax = posTicks.last();
+
+ // Stock ticks' positions and labels on X axis
+ double pos;
+ QString label;
+ //
+ for (int itic=0; itic < nbTicks; itic++)
+ {
+ pos = posTicks.at(itic);
+ label = devPosLabelTicks[pos];
+
+ myScaleDraw->setLabelTick( pos, label, false);
+
+ std::string std_label = label.toStdString();
+ //const char *c_label = std_label.c_str();
+ //std::cout << " tick " << itic << " : pos= " << pos << ", label= |" << c_label << "|" << std::endl;
+ }
+ allTicks.append( posTicks);
+
+ // Compute the position of the system's label
+ if (idev == ileftDev)
+ {
+ devLabPos = devXmin + 0.25*(devXmax - devXmin);
+ }
+ else
+ {
+ devLabPos = devXmin + 0.50*(devXmax - devXmin);
+ }
+ allTicks.append( devLabPos);
+
+ // Stock position and name of the system under X axis
+ myScaleDraw->setLabelTick( devLabPos, deviceLabel, true);
+
+ if (idev > 0)
+ {
+ // Create the vertical segment between the current system and the next
+ gapXmax = devXmin;
+ segmentPos = gapXmin + 0.5*(gapXmax - gapXmin);
+
+ createSeparationLine( segmentPos);
+ }
+ gapXmin = devXmax;
+ }
+
+ // List's items increasing sorting
+ qSort( allTicks.begin(), allTicks.end() ); // iterators
+
+ // Stock the interval of X's values
+ double lowerBound = allTicks.first() - XLeftMargin;
+ double upperBound = allTicks.last() + XRightMargin;
+ myScaleDraw->setInterval( lowerBound, upperBound);
+
+ // For each system, stock the position of the X's ticks and those of the name
+ myScaleDraw->setTicks( allTicks); // do not draw the ticks
+
+ // Memorize the X axis in the drawing zone
+ setAxisScaleDraw( QwtPlot::xBottom, myScaleDraw); // heritage of QwtPlot
+
+ //std::cout << "Plot2d_Plot2d::displayXTicksAndLabels() 1" << std::endl;
+}
+
+
+/* Create vertical segment between two curves
+ */
+void Plot2d_Plot2d::createSeparationLine( double Xpos)
+{
+ QwtPlotMarker* aPlotMarker = new QwtPlotMarker();
+
+ aPlotMarker->setLineStyle( QwtPlotMarker::VLine);
+ aPlotMarker->setXValue( Xpos);
+ aPlotMarker->setLinePen( QPen(Qt::black));
+ aPlotMarker->attach(this); // Add to drawing zone
+ // To deallocate in EraseAll()
+ mySeparationLineList.append( aPlotMarker);
+}
+
+void Plot2d_Plot2d::clearSeparationLineList()
+{
+ mySeparationLineList.clear();
+}
+
+/* Set type of legend symbol
+ */
+void Plot2d_Plot2d::setLegendSymbolType( const int type )
+{
+ myLegendSymbolType = type;
+}
+
+/* Get type of legend symbol
+ */
+int Plot2d_Plot2d::getLegendSymbolType()
+{
+ return myLegendSymbolType;
+}
+
+/*!
+ Creates presentation of object
+ Default implementation is empty
+*/
+Plot2d_Prs* Plot2d_ViewFrame::CreatePrs( const char* /*entry*/ )
+{
+ return 0;
+}
+
+/*!
+ Copies preferences from other viewframe
+ \param vf - other view frame
+*/
+void Plot2d_ViewFrame::copyPreferences( Plot2d_ViewFrame* vf )
+{
+ if( !vf )
+ return;
+
+ myCurveType = vf->myCurveType;
+ myShowLegend = vf->myShowLegend;
+ myLegendPos = vf->myLegendPos;
+ myLegendSymbolType = vf->myLegendSymbolType;
+ myLegendFont = vf->myLegendFont;
+ mySelectedLegendFontColor = vf->mySelectedLegendFontColor;
+ myMarkerSize = vf->myMarkerSize;
+ myBackground = vf->myBackground;
+ mySelectionColor = vf->mySelectionColor;
+ myTitle = vf->myTitle;
+ myXTitle = vf->myXTitle;
+ myYTitle = vf->myYTitle;
+ myY2Title = vf->myY2Title;
+ myTitleEnabled = vf->myTitleEnabled;
+ myXTitleEnabled = vf->myXTitleEnabled;
+ myYTitleEnabled = vf->myYTitleEnabled;
+ myY2TitleEnabled = vf->myY2TitleEnabled;
+ myXGridMajorEnabled = vf->myXGridMajorEnabled;
+ myYGridMajorEnabled = vf->myYGridMajorEnabled;
+ myY2GridMajorEnabled = vf->myY2GridMajorEnabled;
+ myXGridMinorEnabled = vf->myXGridMinorEnabled;
+ myYGridMinorEnabled = vf->myYGridMinorEnabled;
+ myY2GridMinorEnabled = vf->myY2GridMinorEnabled;
+ myXGridMaxMajor = vf->myXGridMaxMajor;
+ myYGridMaxMajor = vf->myYGridMaxMajor;
+ myY2GridMaxMajor = vf->myY2GridMaxMajor;
+ myXGridMaxMinor = vf->myXGridMaxMinor;
+ myYGridMaxMinor = vf->myYGridMaxMinor;
+ myY2GridMaxMinor = vf->myY2GridMaxMinor;
+ myXMode = vf->myXMode;
+ myYMode = vf->myYMode;
+ mySecondY = vf->mySecondY;
+}
+
+/*!
+ Updates titles according to curves
+*/
+#define BRACKETIZE(x) QString( "[ " ) + x + QString( " ]" )
+void Plot2d_ViewFrame::updateTitles( const bool update )
+{
+ ObjectDict::iterator it = myObjects.begin();
+ QStringList aXTitles;
+ QStringList aYTitles;
+ QStringList aY2Titles;
+ QStringList aXUnits;
+ QStringList aYUnits;
+ QStringList aY2Units;
+ QStringList aTables;
+ int i = 0;
+
+ Plot2d_Object* anObject;
+ for ( ; it != myObjects.end(); it++ ) {
+ // collect titles and units from all curves...
+ anObject = it.value();
+ QString xTitle = anObject->getHorTitle().trimmed();
+ QString yTitle = anObject->getVerTitle().trimmed();
+ QString xUnits = anObject->getHorUnits().trimmed();
+ QString yUnits = anObject->getVerUnits().trimmed();
+
+ if ( anObject->getYAxis() == QwtPlot::yLeft ) {
+ if ( !aYTitles.contains( yTitle ) )
+ aYTitles.append( yTitle );
+ if ( !aYUnits.contains( yUnits ) )
+ aYUnits.append( yUnits );
+ }
+ else {
+ if ( !aY2Titles.contains( yTitle ) )
+ aY2Titles.append( yTitle );
+ if ( !aY2Units.contains( yUnits ) )
+ aY2Units.append( yUnits );
+ }
+ if ( !aXTitles.contains( xTitle ) )
+ aXTitles.append( xTitle );
+ if ( !aXUnits.contains( xUnits ) )
+ aXUnits.append( xUnits );
+
+ QString aName = anObject->getTableTitle();
+ if( !aName.isEmpty() && !aTables.contains( aName ) )
+ aTables.append( aName );
+ ++i;
+ }
+ // ... and update plot 2d view
+ QString xUnits, yUnits, y2Units;
+ if ( aXUnits.count() == 1 && !aXUnits[0].isEmpty() )
+ xUnits = BRACKETIZE( aXUnits[0] );
+ if ( aYUnits.count() == 1 && !aYUnits[0].isEmpty())
+ yUnits = BRACKETIZE( aYUnits[0] );
+ if ( aY2Units.count() == 1 && !aY2Units[0].isEmpty())
+ y2Units = BRACKETIZE( aY2Units[0] );
+ QString xTitle, yTitle, y2Title;
+ if ( aXTitles.count() == 1 && aXUnits.count() == 1 )
+ xTitle = aXTitles[0];
+ if ( aYTitles.count() == 1 )
+ yTitle = aYTitles[0];
+ if ( mySecondY && aY2Titles.count() == 1 )
+ y2Title = aY2Titles[0];
+
+ if ( !xTitle.isEmpty() && !xUnits.isEmpty() )
+ xTitle += " ";
+ if ( !yTitle.isEmpty() && !yUnits.isEmpty() )
+ yTitle += " ";
+ if ( !y2Title.isEmpty() && !y2Units.isEmpty() )
+ y2Title += " ";
+
+ setTitle( myXTitleEnabled, xTitle + xUnits, XTitle, false );
+ setTitle( myYTitleEnabled, yTitle + yUnits, YTitle, false );
+ if ( mySecondY )
+ setTitle( myY2TitleEnabled, y2Title + y2Units, Y2Title, false );
+ if( myIsDefTitle )
+ setTitle( true, aTables.join("; "), MainTitle, false );
+
+ // do update if necessary
+ if ( update ) {
+ myPlot->replot();
+ }
+}
+
+/*!
+ Outputs content of viewframe to file
+ \param file - file name
+ \param format - file format
+*/
+bool Plot2d_ViewFrame::print( const QString& file, const QString& format ) const
+{
+#ifdef WIN32
+ return false;
+
+#else
+ bool res = false;
+ if( myPlot )
+ {
+ QPaintDevice* pd = 0;
+ if( format=="PS" || format=="EPS" || format == "PDF" )
+ {
+ QPrinter* pr = new QPrinter( QPrinter::HighResolution );
+ if(format == "PDF")
+ pr->setOutputFormat(QPrinter::PdfFormat);
+ pr->setPageSize( QPrinter::A4 );
+ pr->setOutputFileName( file );
+ pr->setPrintProgram( "" );
+ pd = pr;
+ }
+
+ if( pd )
+ {
+ QwtPlotRenderer* pr = new QwtPlotRenderer();
+ pr->renderTo( myPlot, *pd );
+ res = true;
+ delete pd;
+ }
+ }
+ return res;
+#endif
+
+}
+
+/**
+ * Print Plot2d window
+ */
+void Plot2d_ViewFrame::printPlot( QPainter* p, const QRectF& rect) const
+{
+ QwtPlotRenderer* pr = new QwtPlotRenderer();
+ pr->render( myPlot, p, rect );
+}
+
+/*!
+ \return string with all visual parameters
+*/
+QString Plot2d_ViewFrame::getVisualParameters()
+{
+
+ return getXmlVisualParameters();
+
+ /*
+ RNV: Old case, now visual parameters stored in the XML format.
+ //
+ double xmin, xmax, ymin, ymax, y2min, y2max;
+ getFitRanges( xmin, xmax, ymin, ymax, y2min, y2max );
+ QString retStr;
+ //Store font in the visual parameters string as:
+ //
+ // ...*FontFamily|FontSize|B|I|U|r:g:b*...
+
+ retStr.sprintf( "%d*%d*%d*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%s|%i|%i|%i|%i|%i:%i:%i",
+ myXMode, myYMode, mySecondY, xmin, xmax, ymin, ymax, y2min, y2max,
+ qPrintable(myLegendFont.family()), myLegendFont.pointSize(),myLegendFont.bold(),
+ myLegendFont.italic(), myLegendFont.underline(),myLegendColor.red(),
+ myLegendColor.green(), myLegendColor.blue());
+
+ //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
+ AnalyticalCurveList::iterator it = myAnalyticalCurves.begin();
+ Plot2d_AnalyticalCurve* c = 0;
+ bool isAuto;
+ for( ; it != myAnalyticalCurves.end(); it++) {
+ c = (*it);
+ if(!c) continue;
+ QString curveString("");
+ isAuto = c->isAutoAssign();
+ curveString.sprintf("*%s|%i|%s|%i|%i",
+ qPrintable(c->getName()),
+ c->isActive(),
+ qPrintable(c->getExpression()),
+ c->getNbIntervals(),
+ isAuto);
+
+ retStr+=curveString;
+ if(!isAuto) {
+ QString optCurveString("");
+ optCurveString.sprintf("|%i|%i|%i|%i:%i:%i",
+ (int)c->getMarker(),
+ (int)c->getLine(),
+ c->getLineWidth(),
+ c->getColor().red(),
+ c->getColor().green(),
+ c->getColor().blue());
+ retStr+=optCurveString;
+ }
+ }
+ retStr += QString( "*%1" ).arg( Qtx::colorToString( backgroundColor() ) );
+ return retStr;
+ */
+}
+
+/*!
+ Restores all visual parameters from string
+*/
+void Plot2d_ViewFrame::setVisualParameters( const QString& parameters )
+{
+ if(setXmlVisualParameters(parameters))
+ return;
+
+ double xmin, xmax;
+ QStringList paramsLst = parameters.split( '*' );
+ if ( paramsLst.size() >= 9 ) {
+ double ymin, ymax, y2min, y2max;
+ myXMode = paramsLst[0].toInt();
+ myYMode = paramsLst[1].toInt();
+ mySecondY = (bool)paramsLst[2].toInt();
+ xmin = paramsLst[3].toDouble();
+ xmax = paramsLst[4].toDouble();
+ ymin = paramsLst[5].toDouble();
+ ymax = paramsLst[6].toDouble();
+ y2min = paramsLst[7].toDouble();
+ y2max = paramsLst[8].toDouble();
+
+ if (mySecondY)
+ setTitle( myY2TitleEnabled, myY2Title, Y2Title, false );
+ setHorScaleMode( myXMode, /*update=*/false );
+ setVerScaleMode( myYMode, /*update=*/false );
+
+ if (mySecondY) {
+ QwtScaleMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
+ myYDistance2 = yMap2.s2() - yMap2.s1();
+ }
+
+ fitData( 0, xmin, xmax, ymin, ymax, y2min, y2max );
+ fitData( 0, xmin, xmax, ymin, ymax, y2min, y2max );
+ }
+
+ //Restore legend font
+ if(paramsLst.size() >= 10) {
+ QStringList fontList = paramsLst[9].split( '|' );
+ if(fontList.size() == 6) {
+ myLegendFont = QFont(fontList[0]);
+ myLegendFont.setPointSize(fontList[1].toInt());
+ myLegendFont.setBold(fontList[2].toInt());
+ myLegendFont.setItalic(fontList[3].toInt());
+ myLegendFont.setUnderline(fontList[4].toInt());
+ QStringList colorList = fontList[5].split(":");
+ setLegendFont( myLegendFont );
+
+ if(colorList.size() == 3) {
+ myLegendColor = QColor(colorList[0].toInt(),
+ colorList[1].toInt(),
+ colorList[2].toInt());
+ setLegendFontColor( myLegendColor );
+ }
+ }
+ }
+
+#ifndef NO_ANALYTICAL_CURVES
+ //Restore all Analytical curves
+ int startCurveIndex = 10;
+ if( paramsLst.size() >= startCurveIndex+1 ) {
+ for( int i=startCurveIndex; i<paramsLst.size() ; i++ ) {
+ QStringList curveLst = paramsLst[i].split("|");
+ if( curveLst.size() == 5 || curveLst.size() == 9 ) {
+ Plot2d_AnalyticalCurve* c = new Plot2d_AnalyticalCurve();
+ c->setName(curveLst[0]);
+ c->setActive(curveLst[1].toInt());
+ c->setExpression(curveLst[2]);
+ c->setNbIntervals(curveLst[3].toLong());
+ c->setAutoAssign(curveLst[4].toInt());
+ if( !c->isAutoAssign() ) {
+ c->setMarker((Plot2d::MarkerType)curveLst[5].toInt());
+ c->setLine((Plot2d::LineType)curveLst[6].toInt());
+ c->setLineWidth(curveLst[7].toInt());
+ QStringList colorList = curveLst[8].split(":");
+ if( colorList.size() == 3 ) {
+ c->setColor(QColor(colorList[0].toInt(),
+ colorList[1].toInt(),
+ colorList[2].toInt()));
+ }
+ } else {
+ c->autoFill( myPlot );
+ }
+ addAnalyticalCurve(c);
+ updateAnalyticalCurve(c);
+ }
+ else if( curveLst.size() == 1 ) {
+ // background color can be set here
+ QColor c;
+ if ( Qtx::stringToColor( paramsLst[i], c ) )
+ setBackgroundColor( c );
+ }
+ }
+ myPlot->replot();
+ }
+#endif
+}
+
+/*!
+ Store visual parameters in xml format.
+*/
+QString Plot2d_ViewFrame::getXmlVisualParameters() {
+ QString retStr;
+ QXmlStreamWriter aWriter(&retStr);
+ aWriter.setAutoFormatting(true);
+
+ //Ranges
+ aWriter.writeStartDocument();
+ aWriter.writeStartElement("ViewState");
+ aWriter.writeStartElement("Range");
+ double xmin, xmax, ymin, ymax, y2min, y2max;
+ getFitRanges( xmin, xmax, ymin, ymax, y2min, y2max );
+ aWriter.writeAttribute("Xmin", QString("").sprintf("%.12e",xmin));
+ aWriter.writeAttribute("Xmax", QString("").sprintf("%.12e",xmax));
+ aWriter.writeAttribute("Ymin", QString("").sprintf("%.12e",ymin));
+ aWriter.writeAttribute("Ymax", QString("").sprintf("%.12e",ymax));
+ aWriter.writeAttribute("Y2min", QString("").sprintf("%.12e",y2min));
+ aWriter.writeAttribute("Y2max", QString("").sprintf("%.12e",y2max));
+ aWriter.writeEndElement();
+
+ //Display mode
+ aWriter.writeStartElement("DisplayMode");
+ aWriter.writeAttribute("SecondAxis", QString("").sprintf("%d",mySecondY));
+ aWriter.writeStartElement("ScaleMode");
+ aWriter.writeAttribute("Xscale", QString("").sprintf("%d",myXMode));
+ aWriter.writeAttribute("Yscale", QString("").sprintf("%d",myYMode));
+ aWriter.writeEndElement();
+ aWriter.writeStartElement("NormalizationMode");
+ aWriter.writeAttribute("LeftMin", QString("").sprintf("%d",myNormLMin));
+ aWriter.writeAttribute("LeftMax", QString("").sprintf("%d",myNormLMax));
+ aWriter.writeAttribute("RightMin", QString("").sprintf("%d",myNormRMin));
+ aWriter.writeAttribute("RightMax", QString("").sprintf("%d",myNormRMax));
+ aWriter.writeEndElement();
+ aWriter.writeEndElement();
+
+ //Legend
+ aWriter.writeStartElement("Legend");
+ aWriter.writeAttribute("Visibility", QString("").sprintf("%d", myShowLegend));
+ aWriter.writeStartElement("LegendFont");
+ aWriter.writeAttribute("Family", myLegendFont.family());
+ aWriter.writeAttribute("Size", QString("").sprintf("%d",myLegendFont.pointSize()));
+ aWriter.writeAttribute("Bold", QString("").sprintf("%d",myLegendFont.bold()));
+ aWriter.writeAttribute("Italic", QString("").sprintf("%d",myLegendFont.italic()));
+ aWriter.writeAttribute("Underline", QString("").sprintf("%d",myLegendFont.underline()));
+ aWriter.writeAttribute("R", QString("").sprintf("%d",myLegendColor.red()));
+ aWriter.writeAttribute("G", QString("").sprintf("%d",myLegendColor.green()));
+ aWriter.writeAttribute("B", QString("").sprintf("%d",myLegendColor.blue()));
+ aWriter.writeEndElement();
+ aWriter.writeEndElement();
+
+#ifndef NO_ANALYTICAL_CURVES
+ //AnalyticalCurve
+ aWriter.writeStartElement("AnalyticalCurves");
+ AnalyticalCurveList::iterator it = myAnalyticalCurves.begin();
+ Plot2d_AnalyticalCurve* c = 0;
+ bool isAuto;
+ int id = 1;
+ for( ; it != myAnalyticalCurves.end(); it++) {
+ c = (*it);
+ if(!c) continue;
+ aWriter.writeStartElement(QString("AnalyticalCurve_%1").arg(id));
+ isAuto = c->isAutoAssign();
+ 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("isAuto", QString("").sprintf("%d",isAuto));
+ if(!isAuto) {
+ aWriter.writeAttribute("Marker", QString("").sprintf("%d",(int)c->getMarker()));
+ aWriter.writeAttribute("Line", QString("").sprintf("%d",(int)c->getLine()));
+ aWriter.writeAttribute("LineWidth", QString("").sprintf("%d",c->getLineWidth()));
+ aWriter.writeAttribute("R", QString("").sprintf("%d",c->getColor().red()));
+ aWriter.writeAttribute("G", QString("").sprintf("%d",c->getColor().green()));
+ aWriter.writeAttribute("B", QString("").sprintf("%d",c->getColor().blue()));
+ }
+ aWriter.writeEndElement();
+ id++;
+ }
+ aWriter.writeEndElement(); //AnalyticalCurve
+#endif
+
+ //Background
+ aWriter.writeStartElement(QString("Background"));
+ aWriter.writeStartElement(QString("BackgroundColor"));
+ aWriter.writeAttribute("R", QString("").sprintf("%d",backgroundColor().red()));
+ aWriter.writeAttribute("G", QString("").sprintf("%d",backgroundColor().green()));
+ aWriter.writeAttribute("B", QString("").sprintf("%d",backgroundColor().blue()));
+ aWriter.writeEndElement();
+ aWriter.writeEndElement();
+
+
+ aWriter.writeEndDocument();
+ return retStr;
+}
+/*!
+ Restore visual parameters from xml format.
+*/
+bool Plot2d_ViewFrame::setXmlVisualParameters(const QString& parameters) {
+ QXmlStreamReader aReader(parameters);
+ double xmin, xmax, ymin, ymax, y2min, y2max;
+ bool leftMin,leftMax,rightMin,rightMax;
+ leftMin = leftMax = rightMin = rightMax = false;
+ while(!aReader.atEnd()) {
+ aReader.readNext();
+ if (aReader.isStartElement()) {
+ QXmlStreamAttributes aAttr = aReader.attributes();
+ if(aReader.name() == "Range") {
+ xmin = aAttr.value("Xmin").toString().toDouble();
+ xmax = aAttr.value("Xmax").toString().toDouble();
+ ymin = aAttr.value("Ymin").toString().toDouble();
+ ymax = aAttr.value("Ymax").toString().toDouble();
+ y2min = aAttr.value("Y2min").toString().toDouble();
+ y2max = aAttr.value("Y2max").toString().toDouble();
+ } else if(aReader.name() == "DisplayMode") {
+ mySecondY = aAttr.value("Y2max").toString().toDouble();
+ } else if(aReader.name() == "ScaleMode") {
+ myXMode = aAttr.value("Xscale").toString().toInt();
+ myYMode = aAttr.value("Yscale").toString().toInt();
+ } else if(aReader.name() == "NormalizationMode") {
+ leftMin = (bool)aAttr.value("LeftMin").toString().toInt();
+ leftMax = (bool)aAttr.value("LeftMax").toString().toInt();
+ rightMin = (bool)aAttr.value("RightMin").toString().toInt();
+ rightMax = (bool)aAttr.value("RightMax").toString().toInt();
+ } else if(aReader.name() == "Legend") {
+ myShowLegend = (bool)aAttr.value("Visibility").toString().toInt();
+ } else if (aReader.name() == "LegendFont") {
+ myLegendFont = QFont(aAttr.value("Family").toString());
+ myLegendFont.setPointSize(aAttr.value("Size").toString().toInt());
+ myLegendFont.setBold((bool)aAttr.value("Bold").toString().toInt());
+ myLegendFont.setItalic((bool)aAttr.value("Italic").toString().toInt());
+ myLegendFont.setUnderline((bool)aAttr.value("Underline").toString().toInt());
+ myLegendColor = QColor(aAttr.value("R").toString().toInt(),
+ aAttr.value("G").toString().toInt(),
+ aAttr.value("B").toString().toInt());
+ setLegendFontColor( myLegendColor );
+ setLegendFont(myLegendFont);
+ } else if(aReader.name().toString().indexOf("AnalyticalCurve_") >= 0) {
+#ifndef NO_ANALYTICAL_CURVES
+ Plot2d_AnalyticalCurve* c = new Plot2d_AnalyticalCurve();
+ c->setName(aAttr.value("Name").toString());
+ c->setActive((bool)aAttr.value("IsActive").toString().toInt());
+ c->setExpression(aAttr.value("Expression").toString());
+ c->setNbIntervals(aAttr.value("NbIntervals").toString().toLong());
+ c->setAutoAssign((bool)aAttr.value("isAuto").toString().toInt());
+ if( !c->isAutoAssign() ) {
+ c->setMarker((Plot2d::MarkerType)aAttr.value("Marker").toString().toInt());
+ c->setLine((Plot2d::LineType)aAttr.value("Line").toString().toInt());
+ c->setLineWidth(aAttr.value("LineWidth").toString().toInt());
+ c->setColor(QColor(aAttr.value("R").toString().toInt(),
+ aAttr.value("G").toString().toInt(),
+ aAttr.value("B").toString().toInt()));
+ } else {
+ c->autoFill( myPlot );
+ }
+ addAnalyticalCurve(c);
+ updateAnalyticalCurve(c);
+#endif
+ } else if(aReader.name().toString() == "BackgroundColor") {
+ setBackgroundColor(QColor(aAttr.value("R").toString().toInt(),
+ aAttr.value("G").toString().toInt(),
+ aAttr.value("B").toString().toInt()));
+ }
+ }
+ }
+
+ if(aReader.hasError())
+ return false;
+
+ if (mySecondY)
+ setTitle( myY2TitleEnabled, myY2Title, Y2Title, false );
+ setHorScaleMode( myXMode, /*update=*/false );
+ setVerScaleMode( myYMode, /*update=*/false );
+ if (mySecondY) {
+ QwtScaleMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
+ myYDistance2 = yMap2.s2() - yMap2.s1();
+ }
+ setNormLMinMode(leftMin);
+ setNormLMaxMode(leftMax);
+ setNormRMinMode(rightMin);
+ setNormRMaxMode(rightMax);
+
+ showLegend( myShowLegend, false );
+
+ fitData( 0, xmin, xmax, ymin, ymax, y2min, y2max );
+ return true;
+}
+
+/*!
+ Incremental zooming operation
+*/
+void Plot2d_ViewFrame::incrementalPan( const int incrX, const int incrY ) {
+ QwtScaleMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
+ QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
+
+ myPlot->setAxisScale( QwtPlot::yLeft,
+ myPlot->invTransform( QwtPlot::yLeft, yMap.transform( yMap.s1() )-incrY ),
+ myPlot->invTransform( QwtPlot::yLeft, yMap.transform( yMap.s2() )-incrY ) );
+ myPlot->setAxisScale( QwtPlot::xBottom,
+ myPlot->invTransform( QwtPlot::xBottom, xMap.transform( xMap.s1() )-incrX ),
+ myPlot->invTransform( QwtPlot::xBottom, xMap.transform( xMap.s2() )-incrX ) );
+ if (mySecondY) {
+ QwtScaleMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
+ myPlot->setAxisScale( QwtPlot::yRight,
+ myPlot->invTransform( QwtPlot::yRight, y2Map.transform( y2Map.s1() )-incrY ),
+ myPlot->invTransform( QwtPlot::yRight, y2Map.transform( y2Map.s2() )-incrY ) );
+ }
+ myPlot->replot();
+}
+
+/*!
+ Incremental panning operation
+*/
+void Plot2d_ViewFrame::incrementalZoom( const int incrX, const int incrY ) {
+ QwtScaleMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
+ QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
+
+ myPlot->setAxisScale( QwtPlot::yLeft, yMap.s1(),
+ myPlot->invTransform( QwtPlot::yLeft, yMap.transform( yMap.s2() ) + incrY ) );
+ myPlot->setAxisScale( QwtPlot::xBottom, xMap.s1(),
+ myPlot->invTransform( QwtPlot::xBottom, xMap.transform( xMap.s2() ) - incrX ) );
+ if (mySecondY) {
+ QwtScaleMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
+ myPlot->setAxisScale( QwtPlot::yRight, y2Map.s1(),
+ myPlot->invTransform( QwtPlot::yRight, y2Map.transform( y2Map.s2() ) + incrY ) );
+ }
+ myPlot->replot();
+}
+
+/*
+ Update plot item
+*/
+void Plot2d_ViewFrame::updatePlotItem(Plot2d_Object* theObject, QwtPlotItem* theItem) {
+ theObject->updatePlotItem( theItem );
+ Plot2d_Curve* c = dynamic_cast<Plot2d_Curve*>(theObject);
+ QwtPlotCurve* cu = dynamic_cast<QwtPlotCurve*>(theItem);
+ Plot2d_NormalizeAlgorithm* aNormAlgo;
+ if(c && cu) {
+ if(c->getYAxis() == QwtPlot::yRight)
+ aNormAlgo = myRNormAlgo;
+ else
+ aNormAlgo = myLNormAlgo;
+ if(aNormAlgo->getNormalizationMode() != Plot2d_NormalizeAlgorithm::NormalizeNone) {
+ AlgoPlot2dOutputData aResultData = aNormAlgo->getOutput();
+ AlgoPlot2dOutputData::iterator itTmp = aResultData.find(theObject);
+ double *xNew,*yNew;
+ int size = itTmp.value().size();
+ xNew = new double[size];
+ yNew = new double[size];
+ int j = 0;
+ for (; j < size; ++j) {
+ xNew[j] = itTmp.value().at(j).first;
+ yNew[j] = itTmp.value().at(j).second;
+ }
+ cu->setSamples(xNew, yNew,j);
+ delete [] xNew;
+ delete [] yNew;
+ if(aNormAlgo->getNormalizationMode() != Plot2d_NormalizeAlgorithm::NormalizeNone) {
+ QString name = c->getName().isEmpty() ? c->getVerTitle() : c->getName();
+ name = name + QString("(B=%1, K=%2)");
+ name = name.arg(aNormAlgo->getBkoef(c)).arg(aNormAlgo->getKkoef(c));
+ cu->setTitle(name);
+ }
+ }
+ }
+}
+
+/**
+ *
+ */
+QwtPlotCanvas* Plot2d_ViewFrame::getPlotCanvas() const
+{
+ return myPlot ? (QwtPlotCanvas*)myPlot->canvas() : 0;
+}
+
+/*!
+ return closest curve if it exist, else 0
+*/
+Plot2d_Curve* Plot2d_ViewFrame::getClosestCurve( QPoint p, double& distance, int& index ) const
+{
+ CurveDict aCurves = getCurves();
+ CurveDict::iterator it = aCurves.begin();
+ Plot2d_Curve* pCurve = 0;
+ distance = -1.;
+ for ( ; it != aCurves.end(); it++ ) {
+ QwtPlotCurve* aCurve = it.key();
+ if ( !aCurve )
+ continue;
+ double d;
+ int i = aCurve->closestPoint( p, &d );
+ if ( i > -1 && ( distance < 0 || d < distance ) ) {
+ pCurve = it.value();
+ distance = d;
+ index = i;
+ }
+ }
+ return pCurve;
+}
+
+#ifndef NO_ANALYTICAL_CURVES
+/*!
+ \brief Deselect all analytical curves.
+*/
+void Plot2d_ViewFrame::deselectAnalyticalCurves() {
+ foreach(Plot2d_AnalyticalCurve* c, myAnalyticalCurves) {
+ c->setSelected(false);
+ }
+}
+#endif
+
+/*!
+ \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
+
+/*!
+ Performs incremental panning to the left
+*/
+void Plot2d_ViewFrame::onPanLeft()
+{
+ this->incrementalPan( -INCREMENT_FOR_OP, 0 );
+#ifndef NO_ANALYTICAL_CURVES
+ updateAnalyticalCurves();
+#endif
+}
+
+/*!
+ Performs incremental panning to the right
+*/
+void Plot2d_ViewFrame::onPanRight()
+{
+ this->incrementalPan( INCREMENT_FOR_OP, 0 );
+#ifndef NO_ANALYTICAL_CURVES
+ updateAnalyticalCurves();
+#endif
+}
+
+/*!
+ Performs incremental panning to the top
+*/
+void Plot2d_ViewFrame::onPanUp()
+{
+ this->incrementalPan( 0, -INCREMENT_FOR_OP );
+#ifndef NO_ANALYTICAL_CURVES
+ updateAnalyticalCurves();
+#endif
+}
+
+/*!
+ Performs incremental panning to the bottom
+*/
+void Plot2d_ViewFrame::onPanDown()
+{
+ this->incrementalPan( 0, INCREMENT_FOR_OP );
+#ifndef NO_ANALYTICAL_CURVES
+ updateAnalyticalCurves();
+#endif
+}
+
+/*!
+ Performs incremental zooming in
+*/
+void Plot2d_ViewFrame::onZoomIn()
+{
+ this->incrementalZoom( INCREMENT_FOR_OP, INCREMENT_FOR_OP );
+#ifndef NO_ANALYTICAL_CURVES
+ updateAnalyticalCurves();
+#endif
+}
+
+/*!
+ Performs incremental zooming out
+*/
+void Plot2d_ViewFrame::onZoomOut()
+{
+ this->incrementalZoom( -INCREMENT_FOR_OP, -INCREMENT_FOR_OP );
+#ifndef NO_ANALYTICAL_CURVES
+ updateAnalyticalCurves();
+#endif
+}
+
+/*!
+ Schedules a FitAll operation by putting it to the application's
+ event queue. This ensures that other important events (show, resize, etc.)
+ are processed first.
+*/
+void Plot2d_ViewFrame::customEvent( QEvent* ce )
+{
+ if ( ce->type() == FITALL_EVENT )
+ fitAll();
+}
+
+
+/*!
+ * Return Plot2d_Object by the QwtPlotItem
+ *
+*/
+Plot2d_Object* Plot2d_ViewFrame::getPlotObject( QwtPlotItem* plotItem ) const {
+
+ ObjectDict::const_iterator it = myObjects.begin();
+ for( ; it != myObjects.end(); ++it ) {
+ if ( it.key() == plotItem ) {
+ return it.value();
+ }
+ }
+ return 0;
+}
+
+Plot2d_ScaleDraw::Plot2d_ScaleDraw( char f, int prec )
+ : QwtScaleDraw(),
+ myFormat(f),
+ myPrecision(prec)
+{
+ invalidateCache();
+}
+
+QwtText Plot2d_ScaleDraw::label( double value ) const
+{
+ QwtScaleMap m = scaleMap();
+ QString str1 = QwtScaleDraw::label( m.s1() ).text();
+ QString str2 = QwtScaleDraw::label( m.s2() ).text();
+ if ( str1 == str2 ) {
+ double aDist = fabs(scaleMap().s2()-scaleMap().s1())/5;
+ int precision = 0;
+ while (aDist < 1 ) {
+ precision++;
+ aDist *= 10.;
+ }
+ if ( precision > 0 && value > 0 )
+ return QLocale::system().toString( value,'f', precision );
+ }
+
+ return QwtScaleDraw::label( value );
+}
+
+Plot2d_YScaleDraw::Plot2d_YScaleDraw()
+ : QwtScaleDraw()
+{
+}
+
+QwtText Plot2d_YScaleDraw::label( double value ) const
+{
+ // Axis labels format
+ QString strD = QString( "%1").arg( value, 10, 'e', 3); // format 10.3e
+
+ return QwtText( strD);
+}
+
+/* Definition of X axis graduations
+ */
+const QString Plot2d_AxisScaleDraw::DEVICE_FONT = QString("Times");
+const int Plot2d_AxisScaleDraw::DEVICE_FONT_SIZE = 12;
+const int Plot2d_AxisScaleDraw::DEVICE_BY = 40;
+
+Plot2d_AxisScaleDraw::Plot2d_AxisScaleDraw( Plot2d_Plot2d* plot)
+: myPlot(plot)
+{
+ myLowerBound = -1;
+ myUpperBound = -1;
+ setLabelAlignment(Qt::AlignRight);
+ setLabelRotation(45.);
+
+ applyTicks();
+
+ myActivTicksDrawing = true;
+ myNumTicksDrawingCall = 1;
+}
+
+
+Plot2d_AxisScaleDraw::~Plot2d_AxisScaleDraw()
+{
+}
+
+
+/* Unactivate automatic ticks drawing
+ */
+void Plot2d_AxisScaleDraw::unactivTicksDrawing( int numcall)
+{
+ myActivTicksDrawing = false;
+ myNumTicksDrawingCall = numcall;
+}
+
+
+/* Draw X ticks and labels.
+ * Draw systems names under X axis.
+ * Overload the same name QwtScaleDraw method.
+ * (PB: who call automaticaly this method)
+ */
+void Plot2d_AxisScaleDraw::draw( QPainter* painter, const QPalette & palette) const
+{
+ //std::cout << "Plot2d_AxisScaleDraw::draw() : activ= " << myActivTicksDrawing
+ // << " numcall= " << myNumTicksDrawingCall << std::endl;
+
+ if (!myActivTicksDrawing) return;
+
+ //std::cout << "Plot2d_AxisScaleDraw::draw()" << std::endl;
+
+ QList<double> major_ticks = scaleDiv().ticks(QwtScaleDiv::MajorTick);
+ QList<double> medium_ticks = scaleDiv().ticks(QwtScaleDiv::MediumTick);
+ QList<double> minor_ticks = scaleDiv().ticks(QwtScaleDiv::MinorTick);
+
+ medium_ticks.clear();
+ minor_ticks.clear();
+ major_ticks.clear();
+
+ major_ticks.append( myTicks);
+
+ QwtScaleDiv aScaleDiv = myPlot->axisScaleDiv( QwtPlot::xBottom );
+ aScaleDiv.setTicks( QwtScaleDiv::MajorTick, major_ticks );
+ aScaleDiv.setTicks( QwtScaleDiv::MediumTick, medium_ticks );
+ aScaleDiv.setTicks( QwtScaleDiv::MinorTick, minor_ticks );
+ myPlot->setAxisScaleDiv( QwtPlot::xBottom, aScaleDiv );
+
+ QwtScaleDraw *scale = myPlot->axisScaleDraw(QwtPlot::xBottom);
+ ((Plot2d_AxisScaleDraw*)(scale))->applyTicks();
+
+ QwtScaleDraw::draw( painter, palette);
+
+ for (int i = 0; i < myTicks.size(); i++)
+ {
+ drawLabel( painter, myTicks[i]);
+ }
+
+ //std::cout << "Ok for Plot2d_AxisScaleDraw::draw()" << std::endl;
+}
+
+
+QwtText Plot2d_AxisScaleDraw::label( double value) const
+{
+ if (myLabelX.contains(value))
+ return myLabelX[value];
+
+ return QwtText(QString::number(value, 'f', 1));
+}
+
+
+/* Stock position and label of a X tick
+ */
+void Plot2d_AxisScaleDraw::setLabelTick( double value, QString label, bool isDevice)
+{
+ //qDebug()<< "setLabelTick ( " << value << ","<< label <<" )";
+ if ( isDevice )
+ {
+ // For systems names under X axis
+ myLabelDevice[value] = label;
+ }
+ else
+ {
+ // For X axis graduations
+ myLabelX[value] = label;
+ }
+}
+
+
+/* Stock ticks positions of a system, and draw them
+ */
+void Plot2d_AxisScaleDraw::setTicks(const QList<double> aTicks)
+{
+ //std::cout << " Plot2d_AxisScaleDraw::setTicks()" << std::endl;
+ myTicks = aTicks;
+
+ applyTicks();
+}
+
+
+void Plot2d_AxisScaleDraw::setInterval(double lowerBound, double upperBound)
+{
+ myLowerBound = lowerBound;
+ myUpperBound = upperBound;
+ myPlot->setAxisScale( QwtPlot::xBottom, myLowerBound, myUpperBound );
+}
+
+
+/* Stock X ticks in drawing zone
+ */
+void Plot2d_AxisScaleDraw::applyTicks()
+{
+ //std::cout << " Plot2d_AxisScaleDraw::applyTicks()" << std::endl;
+
+ QList<double> major_ticks = scaleDiv().ticks(QwtScaleDiv::MajorTick);
+ QList<double> medium_ticks = scaleDiv().ticks(QwtScaleDiv::MediumTick);
+ QList<double> minor_ticks = scaleDiv().ticks(QwtScaleDiv::MinorTick);
+
+ medium_ticks.clear();
+ minor_ticks.clear();
+
+ QwtScaleDiv aQwtScaleDiv = myPlot->axisScaleDiv( QwtPlot::xBottom );
+ aQwtScaleDiv.setTicks( QwtScaleDiv::MajorTick, myTicks );
+ aQwtScaleDiv.setTicks( QwtScaleDiv::MediumTick, medium_ticks );
+ aQwtScaleDiv.setTicks( QwtScaleDiv::MinorTick, minor_ticks );
+ myPlot->setAxisScaleDiv( QwtPlot::xBottom, aQwtScaleDiv );
+
+ QwtScaleDiv* aScaleDiv = (QwtScaleDiv*) &scaleDiv();
+
+ aScaleDiv->setTicks(QwtScaleDiv::MajorTick, myTicks);
+ aScaleDiv->setTicks(QwtScaleDiv::MediumTick, medium_ticks);
+ aScaleDiv->setTicks(QwtScaleDiv::MinorTick, minor_ticks);
+
+ if (myLowerBound != -1 && myUpperBound != -1)
+ aScaleDiv->setInterval(myLowerBound, myUpperBound);
+
+ //for (int i = 0; i < myTicks.size(); i++){
+ // QPoint p = labelPosition( i );
+ // qDebug() << i<< ") applyTicks -> LABEL" <<p;
+ //}
+}
+
+
+void Plot2d_AxisScaleDraw::drawLabel( QPainter* painter, double value) const
+{
+ //std::cout << " Plot2d_AxisScaleDraw::drawLabel( " << value << " ) : "; //<< std::endl;
+
+ //qDebug() << "drawLabel ( " <<value<<" )";
+ if ( myLabelDevice.contains(value) )
+ {
+ QString deviceLabel = myLabelDevice[value];
+ //
+ std::string std_label = deviceLabel.toStdString();
+ //const char *c_label = std_label.c_str();
+ //std::cout << " deviceLabel= |" << c_label << "|" << std::endl;
+
+ QPointF p = labelPosition( value );
+ p += QPoint(0, DEVICE_BY);
+ QFont prevf = painter->font();
+ //QColor prevc = (painter->pen()).color();
+
+ QFont devicef( DEVICE_FONT, DEVICE_FONT_SIZE, QFont::Bold);
+ //
+ //painter->setPen( QColor("blue") );
+ painter->setFont( devicef );
+ painter->drawText( p, myLabelDevice[value] );
+ //painter->setPen( prevc );
+ painter->setFont( prevf );
+ }
+ if ( myLabelX.contains(value) )
+ {
+ QString xLabel = myLabelX[value];
+ //
+ std::string std_label = xLabel.toStdString();
+ //const char *c_label = std_label.c_str();
+ //std::cout << " xLabel= |" << c_label << "|" << std::endl;
+
+ QwtScaleDraw::drawLabel( painter, value );
+ }
+}
+
+
+void Plot2d_AxisScaleDraw::drawTick( QPainter* painter, double value, int len) const
+{
+ //qDebug() << "drawTick ( " <<value<<" , "<<len<<" ) " ;
+ //qDebug() << "myLabelX" << myLabelX;
+ //
+ if ( myLabelX.contains(value) )
+ {
+ QwtScaleDraw::drawTick( painter, value, len);
+ }
+}
+
+
+/* Management of tooltips associated with markers for curves points or others points
+ */
+const double Plot2d_QwtPlotPicker::BOUND_HV_SIZE = 0.2;
+
+Plot2d_QwtPlotPicker::Plot2d_QwtPlotPicker( int xAxis,
+ int yAxis,
+ RubberBand rubberBand,
+ DisplayMode trackerMode,
+ QwtPlotCanvas *canvas)
+: QwtPlotPicker( xAxis,
+ yAxis,
+ rubberBand,
+ trackerMode,
+ canvas) // of drawing zone QwtPlot
+{
+}
+
+Plot2d_QwtPlotPicker::Plot2d_QwtPlotPicker( int xAxis,
+ int yAxis,
+ QwtPlotCanvas *canvas)
+: QwtPlotPicker( xAxis,
+ yAxis,
+ canvas)
+{
+}
+
+Plot2d_QwtPlotPicker::~Plot2d_QwtPlotPicker()
+{
+}
+// http://www.qtcentre.org/threads/22751-How-do-i-select-a-QwtPlotMarker-using-a-QPlotPicker
+
+/* Return the tooltip associated with a point when the mouse cursor pass near
+ */
+QwtText Plot2d_QwtPlotPicker::trackerText( const QPoint & pos ) const
+{
+ for (QList<QwtPlotMarker* >::const_iterator pMarkerIt = pMarkers.begin();pMarkerIt != pMarkers.end(); ++pMarkerIt )
+ {
+ QwtPlotMarker* pMarker = *pMarkerIt;
+ if ( pMarker != NULL )
+ {
+ const QwtSymbol* symb=pMarker->symbol();
+ const QSize& sz=symb->size();
+ const QwtScaleMap yMapRef=plot()->canvasMap(QwtPlot::yLeft);
+ const QwtScaleMap xMap=plot()->canvasMap(pMarker->xAxis());
+ const QwtScaleMap yMap=plot()->canvasMap(pMarker->yAxis());
+ QwtDoubleRect bound0=pMarker->boundingRect();
+ int x1 = qRound(xMap.transform(bound0.left()));
+ int x2 = qRound(xMap.transform(bound0.right()));
+ int y1 = qRound(yMap.transform(bound0.top()));
+ int y2 = qRound(yMap.transform(bound0.bottom()));
+
+ if ( x2 < x1 )
+ qSwap(x1, x2);
+ if ( y2 < y1 )
+ qSwap(y1, y2);
+
+ QRect bound00=QRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
+ QPoint toto(xMap.transform(pos.x()),yMapRef.transform(pos.y()));
+ bound00.setX(bound00.x()-sz.width());
+ bound00.setY(bound00.y()-sz.height());
+ bound00.setWidth(bound00.width()+sz.width());
+ bound00.setHeight(bound00.height()+sz.height());
+ if( bound00.contains(toto) )
+ {
+ return pMarkersToolTip[pMarker];
+ }
+ }
+ }
+ return QwtText();