#include "Plot2d_ViewFrame.h"
#include "Plot2d_SetupViewDlg.h"
+#include "Plot2d_Prs.h"
+
#include "QAD_Desktop.h"
#include "QAD_ResourceMgr.h"
#include "QAD_FileDlg.h"
#include <qtoolbar.h>
#include <qtoolbutton.h>
#include <qcursor.h>
+#include <qcolordialog.h>
#include <qwt_math.h>
#include <qwt_plot_canvas.h>
#include <stdlib.h>
#include <SALOMEconfig.h>
#include CORBA_SERVER_HEADER(SALOMEDS)
#include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
+using namespace std;
#define DEFAULT_LINE_WIDTH 0 // (default) line width
#define DEFAULT_MARKER_SIZE 9 // default marker size
fitDataAction->setStatusTip ( tr( "PRP_PLOT2D_FITDATA" ) );
myActions.insert( FitDataId, fitDataAction );
connect( fitDataAction, SIGNAL( activated() ), this, SLOT( onFitData() ) );
+
+ // Change background
+ QActionP* changeBGAction = new QActionP ( tr( "TOT_PLOT2D_CHANGE_BACKGROUND"),
+ tr( "MEN_PLOT2D_CHANGE_BACKGROUND" ), 0, this );
+ fitDataAction->setStatusTip ( tr( "PRP_PLOT2D_CHANGE_BACKGROUND" ) );
+ myActions.insert( ChangeBackgroundId, changeBGAction );
+ connect( changeBGAction, SIGNAL( activated() ), this, SLOT( onChangeBackground() ) );
}
/*!
Gets window's central widget
// settings
myPopup->insertSeparator();
myActions[ SettingsId ]->addTo( myPopup );
+ // Change background
+ myPopup->insertSeparator();
+ myActions[ ChangeBackgroundId ]->addTo( myPopup );
}
}
/*!
*/
bool Plot2d_ViewFrame::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
{
- return ( getCurveByIO( IObject ) != NULL );
+ if( getCurveByIO( IObject ) != NULL )
+ return 1;
+ else{
+ if(!IObject.IsNull()){
+ QIntDictIterator<Plot2d_Curve> it(myCurves);
+ for(; it.current();++it){
+ if(it.current()->hasIO() && it.current()->getTableIO()->isSame(IObject))
+ return 1;
+ }}
+ }
+ return 0;
}
/*!
Returns true if interactive object is presented in the viewer and displayed
Plot2d_Curve* curve = getCurveByIO( IObject );
if ( curve )
eraseCurve( curve, update );
+ // it can be table or container object selected
+ QAD_Study* activeStudy = QAD_Application::getDesktop()->getActiveStudy();
+ SALOMEDS::SObject_var aSO = activeStudy->getStudyDocument()->FindObjectID(IObject->getEntry());
+ if ( !aSO->_is_nil() ) {
+ SALOMEDS::ChildIterator_var aIter = activeStudy->getStudyDocument()->NewChildIterator( aSO );
+ for ( ; aIter->More(); aIter->Next() ) {
+ SALOMEDS::SObject_var aChildSO = aIter->Value();
+ SALOMEDS::SObject_var refSO;
+ if ( aChildSO->ReferencedObject( refSO ) && !refSO->_is_nil() )
+ aChildSO = refSO;
+ curve = getCurveByIO( new SALOME_InteractiveObject( aChildSO->GetID(), "", "" ) );
+ if ( curve )
+ eraseCurve( curve, update );
+ }
+ }
}
/*!
Actually this method just re-displays all curves which are presented in the viewer
getCurves( clist );
for ( int i = 0; i < clist.count(); i++ ) {
updateCurve( clist.at( i ), false );
- }
+ }
myPlot->replot();
}
/*!
*/
QString Plot2d_ViewFrame::getInfo( const QPoint& pnt )
{
- QString info;
- info.sprintf( "X : %g\tY : %g",
- myPlot->invTransform( QwtPlot::xBottom, pnt.x() ),
- myPlot->invTransform( QwtPlot::yLeft, pnt.y() ) );
- info = tr( "INF_COORDINATES" ) + " : " + info;
+ bool xFound = false, yFound = false;
+ double xCoord, yCoord;
+ const QwtScaleDiv* aXscale = myPlot->axisScale( QwtPlot::xBottom );
+ for ( int i = 0; i < aXscale->majCnt(); i++ ) {
+ double majXmark = aXscale->majMark( i );
+ int xmark = myPlot->transform( QwtPlot::xBottom, majXmark );
+ if ( xmark-2 == pnt.x() ) {
+ xCoord = majXmark;
+ xFound = true;
+ MESSAGE("Plot2d_ViewFrame::getInfo : close maj X mark("<<i<<") = "<<majXmark<<" "<<xmark<<" "<<pnt.x());
+ break;
+ }
+ }
+ if ( !xFound ) {
+ for ( int i = 0; i < aXscale->minCnt(); i++ ) {
+ double minXmark = aXscale->minMark( i );
+ int xmark = myPlot->transform( QwtPlot::xBottom, minXmark );
+ if ( xmark-2 == pnt.x() ) {
+ xCoord = minXmark;
+ xFound = true;
+ MESSAGE("Plot2d_ViewFrame::getInfo : close min X mark("<<i<<") = "<<minXmark<<" "<<xmark<<" "<<pnt.x());
+ break;
+ }
+ }
+ }
+ const QwtScaleDiv* aYscale = myPlot->axisScale( QwtPlot::yLeft );
+ for ( int i = 0; i < aYscale->majCnt(); i++ ) {
+ double majYmark = aYscale->majMark( i );
+ int ymark = myPlot->transform( QwtPlot::yLeft, majYmark );
+ if ( ymark-2 == pnt.y() ) {
+ yCoord = majYmark;
+ yFound = true;
+ break;
+ }
+ }
+ if ( !yFound ) {
+ for ( int i = 0; i < aYscale->minCnt(); i++ ) {
+ double minYmark = aYscale->minMark( i );
+ int ymark = myPlot->transform( QwtPlot::yLeft, minYmark );
+ if ( ymark-2 == pnt.y() ) {
+ yCoord = minYmark;
+ yFound = true;
+ break;
+ }
+ }
+ }
+ QString strX = QString::number( xFound ? xCoord : myPlot->invTransform( QwtPlot::xBottom, pnt.x() ) ).stripWhiteSpace();
+ if ( strX == "-0" )
+ strX = "0";
+ QString strY = QString::number( yFound ? yCoord : myPlot->invTransform( QwtPlot::yLeft, pnt.y() ) ).stripWhiteSpace();
+ if ( strY == "-0" )
+ strY = "0";
+ QString info = tr("INF_COORDINATES").arg( strX ).arg( strY );
return info;
}
/*!
QSize( myMarkerSize, myMarkerSize ) ) );
}
myPlot->setCurveTitle( curveKey, curve->getVerTitle() );
+ myPlot->setCurveData( curveKey, curve->horData(), curve->verData(), curve->nbPoints() );
myPlot->curve( curveKey )->setEnabled( true );
updateTitles();
if ( update )
}
delete dlg;
}
+/*!
+ Change background color
+*/
+void Plot2d_ViewFrame::onChangeBackground()
+{
+ QColor selColor = QColorDialog::getColor ( backgroundColor(), this );
+ if ( selColor.isValid() ) {
+ setBackgroundColor( selColor );
+ }
+}
/*!
Sets curve type
*/
if ( myOperation != NoOpId) {
if ( myOperation == ZoomId ) {
- QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
- QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
-
- myPlot->setAxisScale( QwtPlot::yLeft,
- myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ),
- myPlot->invTransform( QwtPlot::yLeft, yMap.i2() + dy ) );
- myPlot->setAxisScale( QwtPlot::xBottom,
- myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ),
- myPlot->invTransform( QwtPlot::xBottom, xMap.i2() - dx ) );
- myPlot->replot();
+ this->incrementalZoom( dx, dy );
myPnt = me.pos();
}
else if ( myOperation == PanId ) {
- QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
- QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
-
- myPlot->setAxisScale( QwtPlot::yLeft,
- myPlot->invTransform( QwtPlot::yLeft, yMap.i1()-dy ),
- myPlot->invTransform( QwtPlot::yLeft, yMap.i2()-dy ) );
- myPlot->setAxisScale( QwtPlot::xBottom,
- myPlot->invTransform( QwtPlot::xBottom, xMap.i1()-dx ),
- myPlot->invTransform( QwtPlot::xBottom, xMap.i2()-dx ) );
- myPlot->replot();
+ this->incrementalPan( dx, dy );
myPnt = me.pos();
}
}
}
return false;
}
+
+//==========================================================
+/*!
+ * Plot2d_ViewFrame::Display
+ * Display presentation
+ */
+//==========================================================
+void Plot2d_ViewFrame::Display( const SALOME_Prs2d* prs )
+{
+ // try do downcast object
+ const Plot2d_Prs* aPlot2dPrs = dynamic_cast<const Plot2d_Prs*>( prs );
+ if ( !aPlot2dPrs || aPlot2dPrs->IsNull() )
+ return;
+
+ // display all curves from presentation
+ Plot2d_CurveContainer aCurves = aPlot2dPrs->GetObjects();
+ displayCurves( aCurves );
+}
+
+//==========================================================
+/*!
+ * Plot2d_ViewFrame::Erase
+ * Erase presentation
+ */
+//==========================================================
+void Plot2d_ViewFrame::Erase( const SALOME_Prs2d* prs, const bool )
+{
+ // try do downcast object
+ const Plot2d_Prs* aPlot2dPrs = dynamic_cast<const Plot2d_Prs*>( prs );
+ if ( !aPlot2dPrs || aPlot2dPrs->IsNull() )
+ return;
+
+ // erase all curves from presentation
+ Plot2d_CurveContainer aCurves = aPlot2dPrs->GetObjects();
+ eraseCurves( aCurves );
+}
+
+//==========================================================
+/*!
+ * Plot2d_ViewFrame::CreatePrs
+ * Create presentation by entry
+ */
+//==========================================================
+SALOME_Prs* Plot2d_ViewFrame::CreatePrs( const char* entry )
+{
+ Plot2d_Prs* prs = new Plot2d_Prs();
+ if ( entry ) {
+ QIntDictIterator<Plot2d_Curve> it( myCurves );
+ for ( ; it.current(); ++it ) {
+ if ( it.current()->hasIO() && !strcmp( it.current()->getIO()->getEntry(), entry ) ) {
+ prs->AddObject( it.current() );
+ }
+ }
+ }
+ return prs;
+}
+
+//==========================================================
+/*!
+ * Plot2d_ViewFrame::BeforeDisplay
+ * Axiluary method called before displaying of objects
+ */
+//==========================================================
+void Plot2d_ViewFrame::BeforeDisplay( SALOME_Displayer* d )
+{
+ d->BeforeDisplay( this, SALOME_Plot2dViewType() );
+}
+
+//==========================================================
+/*!
+ * Plot2d_ViewFrame::AfterDisplay
+ * Axiluary method called after displaying of objects
+ */
+//==========================================================
+void Plot2d_ViewFrame::AfterDisplay( SALOME_Displayer* d )
+{
+ d->AfterDisplay( this, SALOME_Plot2dViewType() );
+}
+
+#define INCREMENT_FOR_OP 10
+
+//=======================================================================
+// Plot2d_ViewFrame::onPanLeft
+// Performs incremental panning to the left
+//=======================================================================
+void Plot2d_ViewFrame::onPanLeft()
+{
+ this->incrementalPan( -INCREMENT_FOR_OP, 0 );
+}
+
+//=======================================================================
+// Plot2d_ViewFrame::onPanRight
+// Performs incremental panning to the right
+//=======================================================================
+void Plot2d_ViewFrame::onPanRight()
+{
+ this->incrementalPan( INCREMENT_FOR_OP, 0 );
+}
+
+//=======================================================================
+// Plot2d_ViewFrame::onPanUp
+// Performs incremental panning to the top
+//=======================================================================
+void Plot2d_ViewFrame::onPanUp()
+{
+ this->incrementalPan( 0, -INCREMENT_FOR_OP );
+}
+
+//=======================================================================
+// Plot2d_ViewFrame::onPanDown
+// Performs incremental panning to the bottom
+//=======================================================================
+void Plot2d_ViewFrame::onPanDown()
+{
+ this->incrementalPan( 0, INCREMENT_FOR_OP );
+}
+
+//=======================================================================
+// Plot2d_ViewFrame::onZoomIn
+// Performs incremental zooming in
+//=======================================================================
+void Plot2d_ViewFrame::onZoomIn()
+{
+ this->incrementalZoom( INCREMENT_FOR_OP, INCREMENT_FOR_OP );
+}
+
+//=======================================================================
+// Plot2d_ViewFrame::onZoomOut
+// Performs incremental zooming out
+//=======================================================================
+void Plot2d_ViewFrame::onZoomOut()
+{
+ this->incrementalZoom( -INCREMENT_FOR_OP, -INCREMENT_FOR_OP );
+}
+
+//=======================================================================
+// Plot2d_ViewFrame::incrementalPan
+// Incremental zooming operation
+//=======================================================================
+void Plot2d_ViewFrame::incrementalPan( const int incrX, const int incrY ) {
+ QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
+ QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
+
+ myPlot->setAxisScale( QwtPlot::yLeft,
+ myPlot->invTransform( QwtPlot::yLeft, yMap.i1()-incrY ),
+ myPlot->invTransform( QwtPlot::yLeft, yMap.i2()-incrY ) );
+ myPlot->setAxisScale( QwtPlot::xBottom,
+ myPlot->invTransform( QwtPlot::xBottom, xMap.i1()-incrX ),
+ myPlot->invTransform( QwtPlot::xBottom, xMap.i2()-incrX ) );
+ myPlot->replot();
+}
+
+//=======================================================================
+// Plot2d_ViewFrame::incrementalZoom
+// Incremental panning operation
+//=======================================================================
+void Plot2d_ViewFrame::incrementalZoom( const int incrX, const int incrY ) {
+ QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
+ QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
+
+ myPlot->setAxisScale( QwtPlot::yLeft,
+ myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ),
+ myPlot->invTransform( QwtPlot::yLeft, yMap.i2() + incrY ) );
+ myPlot->setAxisScale( QwtPlot::xBottom,
+ myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ),
+ myPlot->invTransform( QwtPlot::xBottom, xMap.i2() - incrX ) );
+ myPlot->replot();
+}
+