From: ptv Date: Fri, 7 Nov 2008 14:49:32 +0000 (+0000) Subject: porting GUITHARE to V5_1_0_a3 on Mandrake2008 X-Git-Tag: CTH_V14a~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6b99a8a92e0ff552e8458fe0b235f1d6fe10cbf9;p=modules%2Fgui.git porting GUITHARE to V5_1_0_a3 on Mandrake2008 --- diff --git a/src/DDS/DDS_DicGroup.cxx b/src/DDS/DDS_DicGroup.cxx index bc7dbc3ac..9aed49340 100644 --- a/src/DDS/DDS_DicGroup.cxx +++ b/src/DDS/DDS_DicGroup.cxx @@ -28,6 +28,8 @@ #include #include +#include + IMPLEMENT_STANDARD_HANDLE(DDS_DicGroup, MMgt_TShared) IMPLEMENT_STANDARD_RTTIEXT(DDS_DicGroup, MMgt_TShared) @@ -188,7 +190,9 @@ void DDS_DicGroup::FillDataMap( const LDOM_Element& theComponentData, const LDOM for( int i=1, n=myKeys.Length(); i<=n && !exist; i++ ) if( myKeys.Value( i )==anID ) { +#ifdef DEB cout << "Doubled key:" << anID << endl; +#endif exist = true; } if( !exist ) diff --git a/src/DDS/DDS_DicItem.cxx b/src/DDS/DDS_DicItem.cxx index 419946329..70fed5d86 100644 --- a/src/DDS/DDS_DicItem.cxx +++ b/src/DDS/DDS_DicItem.cxx @@ -32,6 +32,8 @@ #include #include +#include + IMPLEMENT_STANDARD_HANDLE(DDS_DicItem, MMgt_TShared) IMPLEMENT_STANDARD_RTTIEXT(DDS_DicItem, MMgt_TShared) diff --git a/src/GLViewer/GLViewer_Context.cxx b/src/GLViewer/GLViewer_Context.cxx index 496d79bed..984e53726 100644 --- a/src/GLViewer/GLViewer_Context.cxx +++ b/src/GLViewer/GLViewer_Context.cxx @@ -618,7 +618,12 @@ void GLViewer_Context::setSelected( GLViewer_Object* object, bool updateViewer ) } if( updateViewer ) - myGLViewer2d->activateDrawer( object, TRUE, TRUE ); + { + if( myUpdateAll ) + myGLViewer2d->updateAll(); + else + myGLViewer2d->activateDrawer( object, TRUE, TRUE ); + } } /*! diff --git a/src/GLViewer/GLViewer_Drawer.cxx b/src/GLViewer/GLViewer_Drawer.cxx index 6fbf36182..082e59574 100644 --- a/src/GLViewer/GLViewer_Drawer.cxx +++ b/src/GLViewer/GLViewer_Drawer.cxx @@ -894,6 +894,32 @@ void GLViewer_Drawer::drawRectangle( GLViewer_Rect* rect, QColor color ) glEnd(); } +/*! + Draws filled rectangle + \param rect - instance of primitive + \param fillingColor - color of filling +*/ +void GLViewer_Drawer::drawFilledRectangle( GLViewer_Rect* rect, QColor color ) +{ + if( !rect ) + return; + + float x1 = rect->left(); + float x2 = rect->right(); + float y1 = rect->bottom(); + float y2 = rect->top(); + + glColor3f( ( GLfloat )color.red() / 255, + ( GLfloat )color.green() / 255, + ( GLfloat )color.blue() / 255 ); + glBegin( GL_POLYGON ); + glVertex2f( x1, y1 ); + glVertex2f( x1, y2 ); + glVertex2f( x2, y2 ); + glVertex2f( x2, y1 ); + glEnd(); +} + /*! Saves object to file with format of HPGL \param hFile - file @@ -938,52 +964,6 @@ bool GLViewer_Drawer::translateToEMF( HDC hDC, GLViewer_CoordSystem* aViewerCS, } #endif -/*! - Draws rectangle - \param rect - instance of primitive - \param lineWidth - width of line - \param gap - gap of rectangle - \param color - color of primitive - \param filled - if it is true, then rectangle will be drawn filled with color "fillingColor" - \param fillingColor - color of filling -*/ -void GLViewer_Drawer::drawRectangle( GLViewer_Rect* rect, GLfloat lineWidth, GLfloat gap, - QColor color, bool filled, QColor fillingColor ) -{ - if( !rect ) - return; - - float x1 = rect->left() - gap; - float x2 = rect->right() + gap; - float y1 = rect->bottom() - gap; - float y2 = rect->top() + gap; - - if( filled ) - { - glColor3f( ( GLfloat )fillingColor.red() / 255, - ( GLfloat )fillingColor.green() / 255, - ( GLfloat )fillingColor.blue() / 255 ); - glBegin( GL_POLYGON ); - glVertex2f( x1, y1 ); - glVertex2f( x1, y2 ); - glVertex2f( x2, y2 ); - glVertex2f( x2, y1 ); - glEnd(); - } - - glColor3f( ( GLfloat )color.red() / 255, - ( GLfloat )color.green() / 255, - ( GLfloat )color.blue() / 255 ); - glLineWidth( lineWidth ); - - glBegin( GL_LINE_LOOP ); - glVertex2f( x1, y1 ); - glVertex2f( x1, y2 ); - glVertex2f( x2, y2 ); - glVertex2f( x2, y1 ); - glEnd(); -} - /*! Draws contour \param pntList - list of points diff --git a/src/GLViewer/GLViewer_Drawer.h b/src/GLViewer/GLViewer_Drawer.h index 859eecbc3..220e62ac3 100644 --- a/src/GLViewer/GLViewer_Drawer.h +++ b/src/GLViewer/GLViewer_Drawer.h @@ -399,11 +399,10 @@ public: //! Draw rectangle with predefined color static void drawRectangle( GLViewer_Rect* theRect, QColor = Qt::black ); + //! Draw filled rectangle with predefined color + static void drawFilledRectangle( GLViewer_Rect*, QColor = Qt::black ); + protected: - //! Draw basic primitives: rectangle, contour, polygon, vertex, cross, arrow - //* with predefined color - static void drawRectangle( GLViewer_Rect*, GLfloat, GLfloat = 0, QColor = Qt::black, - bool = false, QColor = Qt::white ); static void drawContour( GLViewer_Rect*, QColor, GLfloat, GLushort, bool ); static void drawContour( const GLViewer_PntList&, QColor, GLfloat ); static void drawPolygon( GLViewer_Rect*, QColor, GLushort, bool ); diff --git a/src/GLViewer/GLViewer_Geom.h b/src/GLViewer/GLViewer_Geom.h index 13397fce4..d0c4cd4ca 100644 --- a/src/GLViewer/GLViewer_Geom.h +++ b/src/GLViewer/GLViewer_Geom.h @@ -28,7 +28,7 @@ #include "GLViewer.h" #include -#include +#include #include //using namespace QGL; @@ -37,6 +37,8 @@ #pragma warning( disable:4251 ) #endif +#include + /*! Struct GLViewer_Pnt * Substitution of QPoint for OpenGL */ @@ -74,6 +76,9 @@ public: GLViewer_Rect( QRect theRect ) { myLeft = ( float )theRect.left(); myRight = ( float )theRect.right(); myTop = ( float )theRect.top(); myBottom = ( float )theRect.bottom(); } + GLViewer_Rect( QRectF theRect ) { + myLeft = theRect.left(); myRight = theRect.right(); + myTop = theRect.top(); myBottom = theRect.bottom(); } float left() const { return myLeft; } float right() const { return myRight; } @@ -96,6 +101,11 @@ public: ( int )( myRight - myLeft ), ( int )( myTop - myBottom ) ); } + //! \warning This method translate only rect format + QRectF toQRectF() { return QRectF( myLeft, myBottom, + myRight - myLeft, + myTop - myBottom ); } + //! On/off empty status void setIsEmpty( bool on ) { myIsEmpty = on; } //! Checks empty status diff --git a/src/GLViewer/GLViewer_Group.cxx b/src/GLViewer/GLViewer_Group.cxx index 646750490..3be5d4baa 100644 --- a/src/GLViewer/GLViewer_Group.cxx +++ b/src/GLViewer/GLViewer_Group.cxx @@ -141,6 +141,23 @@ void GLViewer_Group::dragingObjects( float x, float y, bool once ) (*it)->moveObject( x, y, true ); } +/*! + Updates horizontal zoom of object + \param sender - object to be updated + \param zoom - zoom coefficient +*/ +void GLViewer_Group::updateXZoom( GLViewer_Object* sender, float zoom ) +{ + OGIterator it = myList.begin(); + OGIterator end_it = myList.end(); + for( int i = 0; it != end_it; ++it, i++ ) + { + GLViewer_Object* anObject = *it; + if( anObject != sender ) + anObject->setXZoom( zoom, true, true ); + } +} + /*! Updates zoom of object \param sender - object to be updated diff --git a/src/GLViewer/GLViewer_Group.h b/src/GLViewer/GLViewer_Group.h index 620cd2f35..d44627c56 100644 --- a/src/GLViewer/GLViewer_Group.h +++ b/src/GLViewer/GLViewer_Group.h @@ -64,6 +64,8 @@ public: /*! Once = true, if this operation calls only one time for all object*/ void dragingObjects( float x, float y, bool once = false ); //!\warning it is for ouv + void updateXZoom( GLViewer_Object* sender, float zoom ); + //!\warning it is for ouv void updateZoom( GLViewer_Object* sender, float zoom ); private: diff --git a/src/GLViewer/GLViewer_Object.cxx b/src/GLViewer/GLViewer_Object.cxx index c6a920c81..40234b886 100644 --- a/src/GLViewer/GLViewer_Object.cxx +++ b/src/GLViewer/GLViewer_Object.cxx @@ -40,6 +40,7 @@ GLViewer_Object::GLViewer_Object() myYScale = 1.0; myXGap = 0; myYGap = 0; + myXZoom = 1.0; myZoom = 1.0; myIsHigh = GL_FALSE; @@ -94,7 +95,43 @@ int GLViewer_Object::getPriority() const */ GLboolean GLViewer_Object::isInside( GLViewer_Rect theRect ) { - return theRect.toQRect().contains( myRect->toQRect() ); + return theRect.toQRectF().contains( myRect->toQRectF() ); +} + +/*! + Sets horizontal zoom factor + \param zoom - zoom factor +*/ +GLboolean GLViewer_Object::setXZoom( GLfloat zoom, bool, bool ) +{ + if( myXZoom == zoom ) + return GL_FALSE; + + myXZoom = zoom; + return GL_TRUE; +} + +/*! + Performs horizontal zoom change by step + \param zoomIn - to increase to decrease zoom +*/ +GLboolean GLViewer_Object::updateXZoom( bool zoomIn ) +{ + float newZoom; + float step = zoomIn ? 1 : -1; + double epsilon = 0.001; + + if( myXZoom - 1 > epsilon ) + newZoom = ( myXZoom * 2 + step ) / 2; + else if( 1 - myXZoom > epsilon ) + newZoom = 2 / ( 2 / myXZoom - step ); + else + newZoom = zoomIn ? 3./2. : 2./3.; + + if( newZoom < 0.01 || newZoom > 100.0 ) + return GL_FALSE; + + return setXZoom( newZoom, true ); } /*! @@ -111,7 +148,7 @@ GLboolean GLViewer_Object::setZoom( GLfloat zoom, bool, bool ) } /*! - Performs zoom change by step + Performs vertical zoom change by step \param zoomIn - to increase to decrease zoom */ GLboolean GLViewer_Object::updateZoom( bool zoomIn ) diff --git a/src/GLViewer/GLViewer_Object.h b/src/GLViewer/GLViewer_Object.h index 503a5a038..8175d0040 100644 --- a/src/GLViewer/GLViewer_Object.h +++ b/src/GLViewer/GLViewer_Object.h @@ -137,6 +137,13 @@ public: //! Returns scale factors virtual void getScale( GLfloat& xScale, GLfloat& yScale ) const { xScale = myXScale; yScale = myYScale;} + //!\warning It is for ouv + virtual GLboolean setXZoom( GLfloat zoom, bool recompute, bool fromGroup = false ); + //!\warning It is for ouv + virtual GLfloat getXZoom() const { return myXZoom; } + //!\warning It is for ouv + virtual GLboolean updateXZoom( bool zoomIn ); + //!\warning It is for ouv virtual GLboolean setZoom( GLfloat zoom, bool recompute, bool fromGroup = false ); //!\warning It is for ouv @@ -271,6 +278,8 @@ protected: //! Gap for Y direction of rect GLfloat myYGap; + //!\warning It is for ouv + GLfloat myXZoom; //!\warning It is for ouv GLfloat myZoom; diff --git a/src/GLViewer/GLViewer_ViewFrame.cxx b/src/GLViewer/GLViewer_ViewFrame.cxx index 54ca3ce7e..86a3436d0 100644 --- a/src/GLViewer/GLViewer_ViewFrame.cxx +++ b/src/GLViewer/GLViewer_ViewFrame.cxx @@ -95,55 +95,55 @@ void GLViewer_ViewFrame::createActions() aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_DUMP" ) ), tr( "MNU_DUMP_VIEW" ), 0, this); aAction->setStatusTip(tr("DSC_DUMP_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView())); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onDumpView())); toolMgr()->registerAction( aAction, DumpId ); // FitAll aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_FITALL" ) ), tr( "MNU_FITALL" ), 0, this); aAction->setStatusTip(tr("DSC_FITALL")); - connect(aAction, SIGNAL(activated()), this, SLOT(onViewFitAll())); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onViewFitAll())); toolMgr()->registerAction( aAction, FitAllId ); // FitRect aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_FITAREA" ) ), tr( "MNU_FITRECT" ), 0, this); aAction->setStatusTip(tr("DSC_FITRECT")); - connect(aAction, SIGNAL(activated()), this, SLOT(onViewFitArea())); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onViewFitArea())); toolMgr()->registerAction( aAction, FitRectId ); // FitSelect aAction = new QtxAction(tr("MNU_FITSELECT"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_FITSELECT" ) ), tr( "MNU_FITSELECT" ), 0, this); aAction->setStatusTip(tr("DSC_FITSELECT")); - connect(aAction, SIGNAL(activated()), this, SLOT(onViewFitSelect())); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onViewFitSelect())); toolMgr()->registerAction( aAction, FitSelectId ); // Zoom aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_ZOOM" ) ), tr( "MNU_ZOOM_VIEW" ), 0, this); aAction->setStatusTip(tr("DSC_ZOOM_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(onViewZoom())); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onViewZoom())); toolMgr()->registerAction( aAction, ZoomId ); // Panning aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_PAN" ) ), tr( "MNU_PAN_VIEW" ), 0, this); aAction->setStatusTip(tr("DSC_PAN_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(onViewPan())); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onViewPan())); toolMgr()->registerAction( aAction, PanId ); // Global Panning aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_GLOBALPAN" ) ), tr( "MNU_GLOBALPAN_VIEW" ), 0, this); aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(onViewGlobalPan())); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onViewGlobalPan())); toolMgr()->registerAction( aAction, GlobalPanId ); aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_RESET" ) ), tr( "MNU_RESET_VIEW" ), 0, this); aAction->setStatusTip(tr("DSC_RESET_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(onViewReset())); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onViewReset())); toolMgr()->registerAction( aAction, ResetId ); } @@ -279,6 +279,20 @@ QImage GLViewer_ViewFrame::dumpView() return img; } +/*! + Saves image to file according to the format + \param image - image + \param fileName - name of file + \param format - string contains name of format (for example, "BMP"(default) or "JPEG", "JPG") +*/ +bool GLViewer_ViewFrame::dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format ) +{ + bool ok = SUIT_ViewWindow::dumpViewToFormat( img, fileName, format ); + if( ok ) + emit vfViewDumped( img, fileName, format ); + return ok; +} + /*! Start panning */ diff --git a/src/GLViewer/GLViewer_ViewFrame.h b/src/GLViewer/GLViewer_ViewFrame.h index f2fd165bf..ddc7eb537 100644 --- a/src/GLViewer/GLViewer_ViewFrame.h +++ b/src/GLViewer/GLViewer_ViewFrame.h @@ -80,6 +80,10 @@ public: signals: void vfDrawExternal( QPainter* ); void vfViewClosing( QCloseEvent* ); + void vfViewDumped( const QImage&, const QString&, const QString& ); + +protected: + virtual bool dumpViewToFormat( const QImage&, const QString& fileName, const QString& format ); protected: GLViewer_Viewer* myViewer; diff --git a/src/GLViewer/GLViewer_ViewPort2d.cxx b/src/GLViewer/GLViewer_ViewPort2d.cxx index 3293fd8ec..d8c70913c 100644 --- a/src/GLViewer/GLViewer_ViewPort2d.cxx +++ b/src/GLViewer/GLViewer_ViewPort2d.cxx @@ -34,8 +34,7 @@ #include "GLViewer_Grid.h" #include "GLViewer_Drawer.h" -// TODO: Porting to Qt4 -//#include +#include #include #include @@ -108,12 +107,11 @@ GLViewer_ViewPort2d::GLViewer_ViewPort2d( QWidget* parent, GLViewer_ViewFrame* t mypFirstPoint = NULL; mypLastPoint = NULL; - // TODO: Porting to Qt4 - /*myObjectTip = new QtxToolTip( myGLWidget );///GLViewer_ObjectTip( this ); - myObjectTip->setShowDelayTime( 60000 ); - connect( myObjectTip, SIGNAL( maybeTip( QPoint, QString&, QFont&, QRect&, QRect& ) ), - this, SLOT( onMaybeTip( QPoint, QString&, QFont&, QRect&, QRect& ) ) );*/ -// myGLWidget->installEventFilter( myObjectTip ); + myObjectTip = new QtxToolTip( myGLWidget );///GLViewer_ObjectTip( this ); + myObjectTip->setShowDelayTime( 60000 ); + connect( myObjectTip, SIGNAL( maybeTip( QPoint, QString&, QFont&, QRect&, QRect& ) ), + this, SLOT( onMaybeTip( QPoint, QString&, QFont&, QRect&, QRect& ) ) ); + //myGLWidget->installEventFilter( myObjectTip ); } /*! @@ -354,6 +352,9 @@ void GLViewer_ViewPort2d::mouseMoveEvent( QMouseEvent* e ) { emit vpMouseEvent( e ); + if( isPulling() ) + return; + if( myIsDragProcess == inDrag ) onDragObject( e ); @@ -400,6 +401,9 @@ void GLViewer_ViewPort2d::mouseReleaseEvent( QMouseEvent* e ) } emit vpMouseEvent( e ); + if( isPulling() ) + return; + if( myIsDragProcess == inDrag ) { bool isAnyMoved = false; @@ -1197,6 +1201,14 @@ void GLViewer_ViewPort2d::drawSelectByRect( int x, int y ) } +/*! + Returns tue if selection by rect is preformed +*/ +bool GLViewer_ViewPort2d::isSelectByRect() const +{ + return mypFirstPoint && mypLastPoint; +} + /*! Finishes rectangle selection */ @@ -1404,6 +1416,13 @@ void GLViewer_ViewPort2d::onMaybeTip( QPoint thePoint, QString& theText, QFont& theTextReg = QRect( thePoint.x(), thePoint.y() + cur_height, aSize.width(), aSize.height() ); theRegion = QRect( thePoint.x(), thePoint.y(), 1, 1 ); + + QPoint aBottomRightGlobal = mapToGlobal( theTextReg.bottomRight() ); + int dx = aBottomRightGlobal.x() - QApplication::desktop()->screenGeometry().width(); + int dy = aBottomRightGlobal.y() - QApplication::desktop()->screenGeometry().height(); + dx = dx < 0 ? 0 : -dx; + dy = dy < 0 ? 0 : -dy; + theTextReg.translate( dx, dy ); } } } diff --git a/src/GLViewer/GLViewer_ViewPort2d.h b/src/GLViewer/GLViewer_ViewPort2d.h index 03a4b149f..6aee4ddda 100644 --- a/src/GLViewer/GLViewer_ViewPort2d.h +++ b/src/GLViewer/GLViewer_ViewPort2d.h @@ -36,7 +36,6 @@ #include "GLViewer_Widget.h" #include "GLViewer_Geom.h" -#include #include #include @@ -44,6 +43,8 @@ #pragma warning( disable:4251 ) #endif +#include + class GLViewer_Compass; class GLViewer_Grid; class GLViewer_Object; @@ -61,9 +62,11 @@ class QRubberBand; class GLViewer_ViewPort2d: public GLViewer_ViewPort { Q_OBJECT + friend class GLViewer_Widget; +public: //! Dragging states - enum vpDragState{ noDrag, initDrag, inDrag }; + enum vpDragState{ noDrag = 0, initDrag, inDrag }; public: GLViewer_ViewPort2d( QWidget* parent, GLViewer_ViewFrame* theViewFrame = NULL ); @@ -119,7 +122,7 @@ public: void endRotation(); //! Checks of dragging process state - bool isDragProcess(){ return myIsDragProcess; } + int isDragProcess(){ return myIsDragProcess; } //! On/off compass void turnCompass( GLboolean on ); @@ -139,6 +142,9 @@ public: //! Pass rect into selector and update void finishSelectByRect(); + //! Pass rect into selector and update + bool isSelectByRect() const; + //! \warnign It is for ouv bool startPulling( GLViewer_Pnt ); //! \warnign It is for ouv diff --git a/src/GLViewer/GLViewer_Viewer.cxx b/src/GLViewer/GLViewer_Viewer.cxx index f850eeb41..bd2d28f11 100644 --- a/src/GLViewer/GLViewer_Viewer.cxx +++ b/src/GLViewer/GLViewer_Viewer.cxx @@ -652,7 +652,7 @@ bool GLViewer_ViewTransformer::eventFilter( QObject* o, QEvent* e ) TransformState state = EnTrain; QMouseEvent* me = ( QMouseEvent* )e; - myButtonState = me->modifiers(); + myButtonState = me->buttons(); if ( e->type() == QEvent::MouseButtonPress ) myButtonState |= me->button(); /* add pressed button */ @@ -664,7 +664,7 @@ bool GLViewer_ViewTransformer::eventFilter( QObject* o, QEvent* e ) myMajorBtn = mouseOnlyState; } - if ( e->type() == QEvent::MouseButtonRelease && mouseOnlyState == myMajorBtn ) + if ( e->type() == QEvent::MouseButtonRelease ) { state = Fin; } @@ -830,7 +830,7 @@ bool GLViewer_ViewSketcher::eventFilter( QObject* o, QEvent* e ) SketchState state = EnTrain; QMouseEvent* me = (QMouseEvent*)e; - myButtonState = me->modifiers(); + myButtonState = me->buttons(); if ( e->type() == QEvent::MouseButtonPress ) myButtonState |= me->button(); /* add pressed button */ diff --git a/src/GLViewer/GLViewer_Viewer.h b/src/GLViewer/GLViewer_Viewer.h index c12d5f901..c03557351 100644 --- a/src/GLViewer/GLViewer_Viewer.h +++ b/src/GLViewer/GLViewer_Viewer.h @@ -107,7 +107,7 @@ protected: virtual void startOperations( QMouseEvent* ) {} virtual bool updateOperations( QMouseEvent* ) { return false; } - virtual void finishOperations( QMouseEvent* ) {} + virtual bool finishOperations( QMouseEvent* ) { return false; } virtual void startOperations( QWheelEvent* ) {} protected slots: diff --git a/src/GLViewer/GLViewer_Viewer2d.cxx b/src/GLViewer/GLViewer_Viewer2d.cxx index f6f998697..712bebbbf 100644 --- a/src/GLViewer/GLViewer_Viewer2d.cxx +++ b/src/GLViewer/GLViewer_Viewer2d.cxx @@ -178,7 +178,7 @@ void GLViewer_Viewer2d::updateBorders() { GLViewer_Object* anObject = *it; GLViewer_Rect* aRect = anObject->getRect(); - if( !anObject->isSelectable() || !anObject->getVisible() ) + if( !anObject->isScalable() || !anObject->getVisible() ) continue; if( border->isEmpty() ) @@ -937,9 +937,15 @@ void GLViewer_Viewer2d::startOperations( QMouseEvent* e ) transPoint( x, y ); GLViewer_Pnt point( x, y ); - if( e->button() == Qt::LeftButton && !myGLContext->getCurrentObject() && vp->startPulling( point ) ) + // Try to start pooling if rectangular selection is performed + if( e->button() == Qt::LeftButton && !vp->isSelectByRect() && + !vp->isDragProcess() && vp->startPulling( point ) ) + { + vp->finishSelectByRect(); return; + } + // Start rectangular selection if pulling was not started if( e->button() == Qt::LeftButton && !(vp->currentBlock() & BS_Selection) && !myGLContext->getCurrentObject() ) vp->startSelectByRect( e->x(), e->y() ); } @@ -951,17 +957,30 @@ bool GLViewer_Viewer2d::updateOperations( QMouseEvent* e ) { GLViewer_ViewPort2d* vp = ( GLViewer_ViewPort2d* )((GLViewer_ViewFrame*)getActiveView())->getViewPort(); + float x = e->pos().x(); + float y = e->pos().y(); + transPoint( x, y ); + GLViewer_Pnt point( x, y ); + if( vp->isPulling() ) { - float x = e->pos().x(); - float y = e->pos().y(); - transPoint( x, y ); - - vp->drawPulling( GLViewer_Pnt( x, y ) ); + vp->drawPulling( point ); updateAll(); return true; } + /*if( vp->isDragProcess() == GLViewer_ViewPort2d::inDrag ) + return true;*/ + + if( e->button() == Qt::LeftButton ) + { + if( !vp->isSelectByRect() && !vp->isDragProcess() && vp->startPulling( point ) ) + { + vp->finishSelectByRect(); + return true; + } + } + if( !myGLContext->getCurrentObject() ) { vp->drawSelectByRect( e->x(), e->y() ); @@ -971,9 +990,11 @@ bool GLViewer_Viewer2d::updateOperations( QMouseEvent* e ) } /*! - Completes started operation on mouse event + Completes started operation on mouse event, Returns true if operation is considered + as completely finished and there is no point in performing other actions after finish + the operation. */ -void GLViewer_Viewer2d::finishOperations( QMouseEvent* e ) +bool GLViewer_Viewer2d::finishOperations( QMouseEvent* e ) { GLViewer_ViewPort2d* vp = ( GLViewer_ViewPort2d* )((GLViewer_ViewFrame*)getActiveView())->getViewPort(); @@ -981,7 +1002,10 @@ void GLViewer_Viewer2d::finishOperations( QMouseEvent* e ) { vp->finishPulling(); updateAll(); - return; + // Although operation is finished, FALSE is returned because base class try to + // perform selection in this case. In the other case it is impossible to perform + // selection of pulled port + return false; } if( !myGLContext->getCurrentObject() ) @@ -992,8 +1016,11 @@ void GLViewer_Viewer2d::finishOperations( QMouseEvent* e ) { bool append = bool ( e->modifiers() & GLViewer_Selector::appendKey() ); getSelector()->select( aSelRect, append ); + return true; } } + + return false; } /*! @@ -1006,7 +1033,10 @@ void GLViewer_Viewer2d::startOperations( QWheelEvent* e ) for( myGLContext->InitSelected(); myGLContext->MoreSelected(); myGLContext->NextSelected() ) { GLViewer_Object* anObject = myGLContext->SelectedObject(); - update = anObject->updateZoom( zoomIn ) || update; + if( e->modifiers() & Qt::ControlModifier ) + update = anObject->updateXZoom( zoomIn ) || update; + else + update = anObject->updateZoom( zoomIn ) || update; } emit wheelZoomChange( zoomIn ); diff --git a/src/GLViewer/GLViewer_Viewer2d.h b/src/GLViewer/GLViewer_Viewer2d.h index b31a4430a..5f7148b5c 100644 --- a/src/GLViewer/GLViewer_Viewer2d.h +++ b/src/GLViewer/GLViewer_Viewer2d.h @@ -209,7 +209,7 @@ protected: //! Updates started operations on mouse event virtual bool updateOperations( QMouseEvent* ); //! Completes started operations on mouse event - virtual void finishOperations( QMouseEvent* ); + virtual bool finishOperations( QMouseEvent* ); //! Starts any operations on mouse wheel event virtual void startOperations( QWheelEvent* ); diff --git a/src/GLViewer/GLViewer_Widget.cxx b/src/GLViewer/GLViewer_Widget.cxx index 5ad81e29c..e1de5e4c3 100644 --- a/src/GLViewer/GLViewer_Widget.cxx +++ b/src/GLViewer/GLViewer_Widget.cxx @@ -345,15 +345,16 @@ void GLViewer_Widget::resizeGL( int w, int h ) if( w < 1 ) w = 1; glViewport( 0, 0, w, h); + myViewPort->initResize( w, h ); + if( myStart ) { myWidth = w; myHeight = h; + myViewPort->fitAll(); myStart = GL_FALSE; } - myViewPort->initResize( w, h ); - glMatrixMode( GL_PROJECTION ); glLoadIdentity(); GLfloat w_c = w / 2., h_c = h / 2.; diff --git a/src/GLViewer/GLViewer_Widget.h b/src/GLViewer/GLViewer_Widget.h index c1edf7efe..fba0aa381 100644 --- a/src/GLViewer/GLViewer_Widget.h +++ b/src/GLViewer/GLViewer_Widget.h @@ -27,10 +27,13 @@ #include "GLViewer.h" +#ifdef WIN32 +#pragma warning( disable:4251 ) +#endif + #include class QFile; - class GLViewer_ViewPort2d; class GLViewer_CoordSystem; diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index c31a8aac4..bbeb04063 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -26,6 +26,10 @@ #include #endif +#ifdef WIN32 +#include +#endif + #include "LightApp_Application.h" #include "LightApp_Module.h" #include "LightApp_DataModel.h" @@ -144,8 +148,6 @@ #include #include -#include - #define FIRST_HELP_ID 1000000 #ifndef DISABLE_SALOMEOBJECT @@ -555,9 +557,11 @@ void LightApp_Application::createActions() if ( icon.isNull() ) { icon = modIcon; - INFOS ( "****************************************************************" << std::endl +#ifdef DEB + cout "****************************************************************" << std::endl << "* Icon for " << (*it).toLatin1().constData() << " not found. Using the default one." << std::endl - << "****************************************************************" << std::endl ); + << "****************************************************************" << std::endl ; +#endif } icon = Qtx::scaleIcon( icon, iconSize ); @@ -664,7 +668,7 @@ QString LightApp_Application::defaultModule() const modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration //! If there's the one and only module --> activate it automatically //! TODO: Possible improvement - default module can be taken from preferences - return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" ); + return aModuleNames.count() > 1 ? QString( "" ) : ( aModuleNames.count() ? aModuleNames.first() : "" ); } /*!On new window slot.*/ @@ -907,6 +911,20 @@ void LightApp_Application::onHelpContentsModule() QString quote("\""); anApp.prepend( quote ); anApp.append( quote ); + + if ( anApp.isEmpty() || anApp == "\"\"" ) + { + // try to find default browser + HRESULT hr; + static const int aLen = MAX_PATH + 100; + TCHAR szExe[ aLen ]; + DWORD cchExe = sizeof( TCHAR ) * aLen; + if ( SUCCEEDED(hr = AssocQueryString(0, ASSOCSTR_COMMAND, + TEXT(".html"), TEXT("open"), szExe, &cchExe))) + { + anApp = szExe; + } + } #endif QString aParams = resMgr->stringValue("ExternalBrowser", "parameters"); @@ -2451,6 +2469,13 @@ void LightApp_Application::updateDesktopTitle() aTitle += QString( " - [%1]" ).arg( sName ); } + QStringList anInfoList; + modules( anInfoList, false ); + + LightApp_Module* aModule = ( LightApp_Module* )activeModule(); + if( aModule && anInfoList.count() == 1 ) // to avoid a conflict between different modules + aTitle = aModule->updateDesktopTitle( aTitle ); + desktop()->setWindowTitle( aTitle ); } @@ -2985,10 +3010,12 @@ bool LightApp_Application::isLibExists( const QString& moduleTitle ) const if ( !isLibFound ) { - INFOS( "****************************************************************" << std::endl +#ifdef DEB + cout "****************************************************************" << std::endl << "* Warning: library " << lib.toLatin1().constData() << " cannot be found" << std::endl << "* Module " << moduleTitle.toLatin1().constData() << " will not be available in GUI mode" << std::endl - << "****************************************************************" << std::endl ); + << "****************************************************************" << std::endl ; +#endif } else if ( !isPythonModule ) return true; @@ -3060,7 +3087,7 @@ bool LightApp_Application::event( QEvent* e ) SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e; QString* d = ( QString* )ce->data(); if( SUIT_MessageBox::question(0, tr("WRN_WARNING"), - d ? *d : "", + d ? *d : QString( "" ), SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes ) showPreferences( tr( "PREF_APP" ) ); diff --git a/src/LightApp/LightApp_Dialog.cxx b/src/LightApp/LightApp_Dialog.cxx index 24c49c5d3..2309f97b8 100644 --- a/src/LightApp/LightApp_Dialog.cxx +++ b/src/LightApp/LightApp_Dialog.cxx @@ -269,7 +269,7 @@ QWidget* LightApp_Dialog::objectWg( const int theId, const int theWgId ) const */ QString LightApp_Dialog::objectText( const int theId ) const { - return myObjects.contains( theId ) ? myObjects[ theId ].myEdit->text() : ""; + return myObjects.contains( theId ) ? myObjects[ theId ].myEdit->text() : QString( "" ); } /*! diff --git a/src/LightApp/LightApp_Driver.cxx b/src/LightApp/LightApp_Driver.cxx index 08c1d2cdf..08b791f66 100644 --- a/src/LightApp/LightApp_Driver.cxx +++ b/src/LightApp/LightApp_Driver.cxx @@ -35,13 +35,24 @@ /*! Constructor.*/ LightApp_Driver::LightApp_Driver() -: myIsTemp( false ) +: myIsTemp( false ), + myCurrPos( 0 ), + myCurrBuff( 0 ), + myCurrFileIndex( 0 ), + myCurrIFile( 0 ), + mySizeToBeWritten( 0 ), + myFileSizes( 0 ), + myFileNameSizes( 0 ), + myCurrOFile( 0 ), + myNbFilles( 0 ) { } /*! Destructor.*/ LightApp_Driver::~LightApp_Driver() { + delete myFileSizes; + delete myFileNameSizes; } using namespace std; @@ -70,7 +81,7 @@ bool LightApp_Driver::SaveDatasInFile( const char* theFileName, bool isMultiFile aFileBufferSize += 4; //Add 4 bytes: a length of the module name aFileBufferSize += strlen(aModuleName[i])+1; std::string aName(aModuleName[i]); - PutFilesToStream(aName, aBuffer[i], aBufferSize[i], isMultiFile); + //PutFilesToStream(aName, aBuffer[i], aBufferSize[i], isMultiFile); aFileBufferSize += 8; //Add 8 bytes: a length of the buffer aFileBufferSize += aBufferSize[i]; i++; @@ -176,7 +187,8 @@ bool LightApp_Driver::ReadDatasFromFile( const char* theFileName, bool isMultiFi aCurrentPos += aBufferSize; // Put buffer to aListOfFiles and set to myMap - ListOfFiles aListOfFiles = PutStreamToFiles(aBuffer, aBufferSize, isMultiFile); + //ListOfFiles aListOfFiles = PutStreamToFiles(aBuffer, aBufferSize, isMultiFile); + ListOfFiles aListOfFiles; SetListOfFiles(aModuleName, aListOfFiles); delete[] aModuleName; @@ -222,180 +234,6 @@ void LightApp_Driver::SetListOfFiles( const char* theModuleName, const ListOfFil myMap[aName] = theListOfFiles; } -/*! - Converts files which was created from module into a byte sequence unsigned char -*/ -void LightApp_Driver::PutFilesToStream( const std::string& theModuleName, unsigned char*& theBuffer, - long& theBufferSize, bool theNamesOnly ) -{ - ListOfFiles aFiles = myMap[theModuleName]; - // aFiles must contain temporary directory name in its first item - // and names of files (relatively the temporary directory) in the others - - int i, aLength = aFiles.size() - 1; - if(aLength <= 0) { - theBufferSize = 0; - theBuffer = new unsigned char[theBufferSize]; - return; - } - //Get a temporary directory for saved a file - TCollection_AsciiString aTmpDir(const_cast(aFiles[0].c_str())); - - long aBufferSize = 0; - long aCurrentPos; - int aNbFiles = 0; - int* aFileNameSize= new int[aLength]; - long* aFileSize= new long[aLength]; - - //Determine the required size of the buffer - TCollection_AsciiString aFileName; - for (i = 0; i < aLength; i++) { - char* aFName = const_cast(aFiles[i+1].c_str()); - aFileName = aFName; - //Check if the file exists - if (!theNamesOnly) { // mpv 15.01.2003: if only file names must be stroed, then size of files is zero - TCollection_AsciiString aFullPath = aTmpDir + aFileName; - OSD_Path anOSDPath(aFullPath); - OSD_File anOSDFile(anOSDPath); - if(!anOSDFile.Exists()) continue; -#ifdef WIN32 - ifstream aFile(aFullPath.ToCString(), ios::binary); -#else - ifstream aFile(aFullPath.ToCString()); -#endif - aFile.seekg(0, ios::end); - aFileSize[i] = aFile.tellg(); - aBufferSize += aFileSize[i]; //Add a space to store the file - } - aFileNameSize[i] = strlen(aFName) + 1; - aBufferSize += aFileNameSize[i]; //Add a space to store the file name - aBufferSize += (theNamesOnly)?4:12; //Add 4 bytes: a length of the file name, - // 8 bytes: length of the file itself - aNbFiles++; - } - - aBufferSize += 4; //4 bytes for a number of the files that will be written to the stream; - theBuffer = new unsigned char[aBufferSize]; - if(theBuffer == NULL) { - theBufferSize = 0; - theBuffer = 0; - return; - } - //Initialize 4 bytes of the buffer by 0 - memset(theBuffer, 0, 4); - //Copy the number of files that will be written to the stream - memcpy(theBuffer, &aNbFiles, ((sizeof(int) > 4) ? 4 : sizeof(int))); - - aCurrentPos = 4; - - for(i = 0; i < aLength; i++) { - ifstream *aFile; - if (!theNamesOnly) { // mpv 15.01.2003: we don't open any file if theNamesOnly = true - TCollection_AsciiString aName(const_cast(aFiles[i+1].c_str())); - TCollection_AsciiString aFullPath = aTmpDir + aName; - OSD_Path anOSDPath(aFullPath); - OSD_File anOSDFile(anOSDPath); - if(!anOSDFile.Exists()) continue; -#ifdef WIN32 - aFile = new ifstream(aFullPath.ToCString(), ios::binary); -#else - aFile = new ifstream(aFullPath.ToCString()); -#endif - } - //Initialize 4 bytes of the buffer by 0 - memset((theBuffer + aCurrentPos), 0, 4); - //Copy the length of the file name to the buffer - memcpy((theBuffer + aCurrentPos), (aFileNameSize + i), ((sizeof(int) > 4) ? 4 : sizeof(int))); - aCurrentPos += 4; - - //Copy the file name to the buffer - char* aFName = const_cast(aFiles[i+1].c_str()); - memcpy((theBuffer + aCurrentPos), aFName, aFileNameSize[i]); - aCurrentPos += aFileNameSize[i]; - - if (!theNamesOnly) { // mpv 15.01.2003: we don't copy file content to the buffer if !theNamesOnly - //Initialize 8 bytes of the buffer by 0 - memset((theBuffer + aCurrentPos), 0, 8); - //Copy the length of the file to the buffer - memcpy((theBuffer + aCurrentPos), (aFileSize + i), ((sizeof(long) > 8) ? 8 : sizeof(long))); - aCurrentPos += 8; - - aFile->seekg(0, ios::beg); - aFile->read((char *)(theBuffer + aCurrentPos), aFileSize[i]); - aFile->close(); - delete(aFile); - aCurrentPos += aFileSize[i]; - } - } - delete[] aFileNameSize; - delete[] aFileSize; - - theBufferSize = aBufferSize; -} - -/*! - Converts a byte sequence to files and return list of them -*/ -LightApp_Driver::ListOfFiles LightApp_Driver::PutStreamToFiles( const unsigned char* theBuffer, - const long theBufferSize, bool theNamesOnly ) -{ - if(theBufferSize == 0 || theBuffer == 0) - return ListOfFiles(); - - // Create a temporary directory for the component's data files - std::string aDir = GetTmpDir(); - - // Remember that the files are in a temporary location that should be deleted - // when a study is closed - SetIsTemporary( true ); - - //Get a temporary directory for saving a file - TCollection_AsciiString aTmpDir(const_cast(aDir.c_str())); - - long aFileSize, aCurrentPos = 4; - int i, aFileNameSize, aNbFiles = 0; - - //Copy the number of files in the stream - memcpy(&aNbFiles, theBuffer, sizeof(int)); - - const int n = aNbFiles + 1; - ListOfFiles aFiles(n); - aFiles[0] = aDir; - - for(i = 0; i < aNbFiles; i++) { - //Put a length of the file name to aFileNameSize - memcpy(&aFileNameSize, (theBuffer + aCurrentPos), ((sizeof(int) > 4) ? 4 : sizeof(int))); - aCurrentPos += 4; - - char *aFileName = new char[aFileNameSize]; - //Put a file name to aFileName - memcpy(aFileName, (theBuffer + aCurrentPos), aFileNameSize); - aCurrentPos += aFileNameSize; - - //Put a length of the file to aFileSize - if (!theNamesOnly) { - memcpy(&aFileSize, (theBuffer + aCurrentPos), ((sizeof(long) > 8) ? 8 : sizeof(long))); - aCurrentPos += 8; - - TCollection_AsciiString aFullPath = aTmpDir + aFileName; - -#ifdef WIN32 - ofstream aFile(aFullPath.ToCString(), ios::out | ios::binary); -#else - ofstream aFile(aFullPath.ToCString()); -#endif - - aFile.write((char *)(theBuffer+aCurrentPos), aFileSize); - aFile.close(); - aCurrentPos += aFileSize; - } - std::string aStrFileName(aFileName); - aFiles[i+1] = aStrFileName; - delete[] aFileName; - } - return aFiles; -} - /*! Remove files. First item in is a directory with slash at the end. Other items are names of files. If is true, @@ -550,3 +388,462 @@ std::string LightApp_Driver::GetDirFromPath( const std::string& thePath ) { return aDirString.ToCString(); } +//============================================================================= +// Function : PutFilesToFirstStream +// Purpose : +//============================================================================= +bool LightApp_Driver::PutFilesToFirstStream( const std::string& theModuleName, unsigned char*& theBuffer, + long& theBufferSize, bool theNamesOnly ) +{ + myCurrPos = 0; + myCurrBuff = 0; + myCurrFileIndex = 0; + myCurrIFile = 0; + mySizeToBeWritten = 0; + if ( myFileSizes ) + { + delete[] myFileSizes; + myFileSizes = 0; + } + if ( myFileNameSizes ) + { + delete[] myFileNameSizes; + myFileNameSizes = 0; + } + + ListOfFiles aFiles = myMap[theModuleName]; + // aFiles must contain temporary directory name in its first item + // and names of files (relatively the temporary directory) in the others + + int i, aLength = aFiles.size() - 1; + if(aLength <= 0) { + theBufferSize = 0; + theBuffer = new unsigned char[theBufferSize]; + return true; + } + //Get a temporary directory for saved a file + TCollection_AsciiString aTmpDir(const_cast(aFiles[0].c_str())); + + int aNbFiles = 0; + myFileNameSizes = new size_t[aLength]; + myFileSizes = new size_t[aLength]; + + //Determine the required size of the buffer + TCollection_AsciiString aFileName; + for (i = 0; i < aLength; i++) + { + char* aFName = const_cast(aFiles[i+1].c_str()); + aFileName = aFName; + //Check if the file exists + if (!theNamesOnly) + { + TCollection_AsciiString aFullPath = aTmpDir + aFileName; + OSD_Path anOSDPath(aFullPath); + OSD_File anOSDFile(anOSDPath); + if(!anOSDFile.Exists()) + continue; +#ifdef WNT + ifstream aFile(aFullPath.ToCString(), ios::binary); +#else + ifstream aFile(aFullPath.ToCString()); +#endif + aFile.seekg(0, ios::end); + myFileSizes[i] = aFile.tellg(); + mySizeToBeWritten += myFileSizes[i]; //Add a space to store the file + } + myFileNameSizes[i] = strlen(aFName) + 1; + mySizeToBeWritten += myFileNameSizes[i]; //Add a space to store the file name + mySizeToBeWritten += (theNamesOnly)?4:12; //Add 4 bytes: a length of the file name, + // 8 bytes: length of the file itself + aNbFiles++; + } + + mySizeToBeWritten += 4; //4 bytes for a number of the files that will be written to the stream; + + size_t aCurrSize = mySizeToBeWritten <= GetMaxBuffSize() ? mySizeToBeWritten : GetMaxBuffSize(); + theBuffer = new unsigned char[ aCurrSize ]; + myCurrBuff = theBuffer; + + //Initialize 4 bytes of the buffer by 0 + memset( theBuffer, 0, 4); + //Copy the number of files that will be written to the stream + memcpy( theBuffer, &aNbFiles, ((sizeof(int) > 4) ? 4 : sizeof(int))); + + myCurrPos = 4; + int aCurrnetBuff = 0; + + for ( myCurrFileIndex = 0; myCurrFileIndex < aLength; myCurrFileIndex++ ) + { + if (!theNamesOnly) + { // mpv 15.01.2003: we don't open any file if theNamesOnly = true + TCollection_AsciiString aName(const_cast(aFiles[myCurrFileIndex+1].c_str())); + TCollection_AsciiString aFullPath = aTmpDir + aName; + OSD_Path anOSDPath(aFullPath); + OSD_File anOSDFile(anOSDPath); + if(!anOSDFile.Exists()) continue; +#ifdef WNT + myCurrIFile = new ifstream(aFullPath.ToCString(), ios::binary); +#else + myCurrIFile = new ifstream(aFullPath.ToCString()); +#endif + } + + //Initialize 4 bytes of the buffer by 0 + memset( (theBuffer + myCurrPos), 0, 4); + + //Copy the length of the file name to the buffer + memcpy((theBuffer + myCurrPos), (myFileNameSizes + myCurrFileIndex), ((sizeof(int) > 4) ? 4 : sizeof(int))); + myCurrPos += 4; + + //Copy the file name to the buffer + char* aFName = const_cast(aFiles[myCurrFileIndex+1].c_str()); + memcpy( myCurrBuff + myCurrPos, aFName, myFileNameSizes[ myCurrFileIndex ] ); + myCurrPos += myFileNameSizes[myCurrFileIndex]; + + if (!theNamesOnly) // mpv 15.01.2003: we don't copy file content to the buffer if !theNamesOnly + { + //Initialize 8 bytes of the buffer by 0 + memset( myCurrBuff + myCurrPos, 0, 8 ); + + //Copy the length of the file to the buffer + memcpy( myCurrBuff + myCurrPos, + (unsigned char*)(myFileSizes + myCurrFileIndex), ((sizeof(long) > 8) ? 8 : sizeof(long))); + myCurrPos += 8; + + // old code for small files + if ( aCurrSize < GetMaxBuffSize() ) + { + myCurrIFile->seekg(0, ios::beg); + myCurrIFile->read((char *)(theBuffer + myCurrPos), myFileSizes[myCurrFileIndex]); + myCurrIFile->close(); + delete(myCurrIFile); + myCurrIFile = 0; + myCurrPos += myFileSizes[myCurrFileIndex]; + mySizeToBeWritten = 0; + } + else // new code for big files + { + myCurrIFile->seekg(0, ios::beg); + int aPos = myCurrIFile->tellg(); + size_t aSizeToRead = GetMaxBuffSize() - myCurrPos; + if ( aSizeToRead > myFileSizes[myCurrFileIndex] - myCurrIFile->tellg() ) + aSizeToRead = myFileSizes[myCurrFileIndex] - myCurrIFile->tellg(); + myCurrIFile->read((char *)(theBuffer + myCurrPos), aSizeToRead ); + mySizeToBeWritten -= aSizeToRead - myCurrPos; + myCurrPos += aSizeToRead; + if ( myCurrPos == GetMaxBuffSize() ) + { + myCurrPos = 0; + break; + } + else // file was saved complitelly + { + myCurrIFile->close(); + delete(myCurrIFile); + myCurrIFile = 0; + } + if ( myCurrIFile ) + aPos = myCurrIFile->tellg(); + } + } + } + + if ( aCurrSize < GetMaxBuffSize() ) + theBufferSize = myCurrPos; + else + theBufferSize = GetMaxBuffSize(); + + return aCurrSize < GetMaxBuffSize(); +} + +//============================================================================= +// Function : HasUnsavedData +// Purpose : +//============================================================================= +bool LightApp_Driver::HasUnsavedData() const +{ + return myCurrIFile && mySizeToBeWritten; +} + +//============================================================================= +// Function : PutFilesToNextStream +// Purpose : +//============================================================================= +bool LightApp_Driver::PutFilesToNextStream( const std::string& theModuleName, unsigned char*& theBuffer, + long& theBufferSize, bool theNamesOnly ) +{ + if ( theNamesOnly || !HasUnsavedData() ) + return true; + + ListOfFiles aFiles = myMap[ theModuleName ]; + int aLength = aFiles.size() - 1; + if ( aLength <= 0 ) + return true; + + TCollection_AsciiString aTmpDir(const_cast(aFiles[0].c_str())); + + size_t aCurrSize = mySizeToBeWritten <= GetMaxBuffSize() ? mySizeToBeWritten : GetMaxBuffSize(); + + for ( ; myCurrFileIndex < aLength; myCurrFileIndex++ ) + { + TCollection_AsciiString aName(const_cast(aFiles[myCurrFileIndex+1].c_str())); + TCollection_AsciiString aFullPath = aTmpDir + aName; + OSD_Path anOSDPath(aFullPath); + OSD_File anOSDFile(anOSDPath); + if(!anOSDFile.Exists()) + continue; + + if ( !myCurrIFile ) + { +#ifdef WNT + myCurrIFile = new ifstream( aFullPath.ToCString(), ios::binary ); +#else + myCurrIFile = new ifstream( aFullPath.ToCString() ); +#endif + + myCurrIFile->seekg(0, ios::beg); + + //////////// + //Initialize 4 bytes of the buffer by 0 + memset( (myCurrBuff + myCurrPos), 0, 4); + //Copy the length of the file name to the buffer + memcpy((myCurrBuff + myCurrPos), ( myFileNameSizes + myCurrFileIndex ), ((sizeof(int) > 4) ? 4 : sizeof(int))); + myCurrPos += 4; + + //Copy the file name to the buffer + char* aFName = const_cast(aFiles[myCurrFileIndex+1].c_str()); + memcpy( myCurrBuff + myCurrPos, aFName, myFileNameSizes[ myCurrFileIndex ] ); + myCurrPos += myFileNameSizes[myCurrFileIndex]; + ///////////// + + //Initialize 8 bytes of the buffer by 0 + memset( myCurrBuff + myCurrPos, 0, 8 ); + + //Copy the length of the file to the buffer + memcpy( myCurrBuff + myCurrPos, + (unsigned char*)(myFileSizes + myCurrFileIndex), ((sizeof(long) > 8) ? 8 : sizeof(long))); + myCurrPos += 8; + } + + // old code for small files + if ( aCurrSize < GetMaxBuffSize() ) + { + //myCurrIFile->seekg(0, ios::beg); + size_t aSizeToRead = myFileSizes[myCurrFileIndex] - myCurrIFile->tellg(); + myCurrIFile->read((char *)(theBuffer + myCurrPos), aSizeToRead ); + myCurrIFile->close(); + delete(myCurrIFile); + myCurrIFile = 0; + myCurrPos += aSizeToRead; + mySizeToBeWritten = 0; + } + else // new code for big files + { + int aPos = myCurrIFile->tellg(); + size_t aFileSize = myFileSizes[myCurrFileIndex]; + size_t aSizeToRead = GetMaxBuffSize() - myCurrPos; + if ( aSizeToRead > myFileSizes[myCurrFileIndex] - myCurrIFile->tellg() ) + aSizeToRead = myFileSizes[myCurrFileIndex] - myCurrIFile->tellg(); + myCurrIFile->read((char *)(theBuffer + myCurrPos), aSizeToRead ); + mySizeToBeWritten -= aSizeToRead - myCurrPos; + myCurrPos += aSizeToRead; + if ( myCurrPos == GetMaxBuffSize() ) + { + myCurrPos = 0; + break; + } + else // file was saved complitelly + { + myCurrIFile->close(); + delete(myCurrIFile); + myCurrIFile = 0; + } + if ( myCurrIFile ) + aPos = myCurrIFile->tellg(); + } + } + + if ( aCurrSize < GetMaxBuffSize() ) + theBufferSize = myCurrPos - 1; + else + theBufferSize = GetMaxBuffSize(); + + return aCurrSize < GetMaxBuffSize(); +} + +//============================================================================= +// Function : PutFirstStreamToFiles +// Purpose : +//============================================================================= +void LightApp_Driver::PutFirstStreamToFiles( ListOfFiles& theListOfFiles, + const unsigned char* theBuffer, + const long theBufferSize, + bool theNamesOnly ) +{ + theListOfFiles.resize( 0 ); + myCurrPos = 0; + myCurrOFile = 0; + mySizeToBeWritten = 0; + + if ( theBufferSize == 0 || theBuffer == 0 ) + return; + + delete[] myFileSizes; + delete[] myFileNameSizes; + + // Create a temporary directory for the component's data files + std::string aDir = GetTmpDir(); + + // Remember that the files are in a temporary location that should be deleted + // when a study is closed + SetIsTemporary( true ); + + //Get a temporary directory for saving a file + TCollection_AsciiString aTmpDir(const_cast(aDir.c_str())); + + myCurrPos = 4; + + //Copy the number of files in the stream + memcpy(&myNbFilles, theBuffer, sizeof(int)); + + const int n = myNbFilles + 1; + theListOfFiles.resize( n ); + myFileSizes = new size_t[ n ]; + myFileNameSizes = new size_t[ n ]; + theListOfFiles[ 0 ] = aDir; + myFileSizes[ 0 ] = 0; + myFileNameSizes[ 0 ] = 0; + + for( myCurrFileIndex = 1; myCurrFileIndex <= myNbFilles; myCurrFileIndex++) + { + //Put a length of the file name to myFileNameSizes[ myCurrFileIndex ] + memcpy(&myFileNameSizes[ myCurrFileIndex ], (theBuffer + myCurrPos), ((sizeof(int) > 4) ? 4 : sizeof(int))); + myCurrPos += 4; + + char *aFileName = new char[ myFileNameSizes[ myCurrFileIndex ] ]; + //Put a file name to aFileName + memcpy(aFileName, (theBuffer + myCurrPos), myFileNameSizes[ myCurrFileIndex ]); + myCurrPos += myFileNameSizes[ myCurrFileIndex ]; + + //Put a length of the file to myFileSizes + if (!theNamesOnly) + { + memcpy(&myFileSizes[ myCurrFileIndex ], (theBuffer + myCurrPos), ((sizeof(long) > 8) ? 8 : sizeof(long))); + myCurrPos += 8; + + TCollection_AsciiString aFullPath = aTmpDir + aFileName; + +#ifdef WNT + myCurrOFile = new ofstream(aFullPath.ToCString(), ios::out | ios::binary); +#else + myCurrOFile = new ofstream(aFullPath.ToCString()); +#endif + + std::string aStrFileName( aFileName ); + theListOfFiles[ myCurrFileIndex ] = aStrFileName; + delete[] aFileName; + + if ( myFileSizes[ myCurrFileIndex ] <= theBufferSize - myCurrPos ) + { + // old code + myCurrOFile->write((char *)(theBuffer+myCurrPos), myFileSizes[ myCurrFileIndex ] ); + myCurrOFile->close(); + delete myCurrOFile; + myCurrOFile = 0; + myCurrPos += myFileSizes[ myCurrFileIndex ]; + myFileSizes[ myCurrFileIndex ] = 0; + } + else + { + // old code for big files + size_t aSize = theBufferSize - myCurrPos; + myCurrOFile->write((char *)( theBuffer + myCurrPos ), aSize ); + myFileSizes[ myCurrFileIndex ] -= aSize; + myCurrPos = 0; + break; + } + } + } +} + +//============================================================================= +// Function : PutNextStreamToFiles +// Purpose : +//============================================================================= +void LightApp_Driver::PutNextStreamToFiles( ListOfFiles& theListOfFiles, + const unsigned char* theBuffer, + const long theBufferSize, + bool theNamesOnly ) +{ + if ( theNamesOnly ) + return; + + std::string aDir = GetTmpDir(); + + //Get a temporary directory for saving a file + TCollection_AsciiString aTmpDir(const_cast(aDir.c_str())); + + if ( !myNbFilles ) + return; + + for( ; myCurrFileIndex <= myNbFilles; myCurrFileIndex++) + { + if ( !myCurrOFile ) + { + //Put a length of the file name to myFileNameSizes + //int myFileNameSizes; + memcpy(&myFileNameSizes[ myCurrFileIndex ], (theBuffer + myCurrPos), ((sizeof(int) > 4) ? 4 : sizeof(int))); + myCurrPos += 4; + + char *aFileName = new char[ myFileNameSizes[ myCurrFileIndex ] ]; + //Put a file name to aFileName + memcpy(aFileName, (theBuffer + myCurrPos), myFileNameSizes[ myCurrFileIndex ]); + myCurrPos += myFileNameSizes[ myCurrFileIndex ]; + + std::string aStrFileName( aFileName ); + theListOfFiles[ myCurrFileIndex ] = aStrFileName; + + //Put a length of the file to myFileSizes + if ( theNamesOnly ) + { + delete[] aFileName; + continue; + } + + memcpy(&myFileSizes[ myCurrFileIndex ], (theBuffer + myCurrPos), ((sizeof(long) > 8) ? 8 : sizeof(long))); + myCurrPos += 8; + + TCollection_AsciiString aFullPath = aTmpDir + aFileName; + +#ifdef WNT + myCurrOFile = new ofstream(aFullPath.ToCString(), ios::out | ios::binary); +#else + myCurrOFile = new ofstream(aFullPath.ToCString()); +#endif + + delete[] aFileName; + + } //if ( !myCurrOFile ) + + if ( myFileSizes[ myCurrFileIndex ] <= theBufferSize - myCurrPos ) + { + // old code + myCurrOFile->write((char *)(theBuffer+myCurrPos), myFileSizes[ myCurrFileIndex ] ); + myCurrOFile->close(); + delete myCurrOFile; + myCurrOFile = 0; + myCurrPos += myFileSizes[ myCurrFileIndex ]; + myFileSizes[ myCurrFileIndex ] = 0; + } + else + { + // old code for big files + size_t aFileSize = myFileSizes[ myCurrFileIndex ]; + size_t aSize = theBufferSize - myCurrPos; + myCurrOFile->write((char *)( theBuffer + myCurrPos ), aSize ); + myFileSizes[ myCurrFileIndex ] -= aSize; + myCurrPos = 0; + break; + } + } // for +} diff --git a/src/LightApp/LightApp_Driver.h b/src/LightApp/LightApp_Driver.h index 8089b35c3..5021551ce 100644 --- a/src/LightApp/LightApp_Driver.h +++ b/src/LightApp/LightApp_Driver.h @@ -25,6 +25,8 @@ #include "vector" #include "map" +#include + #ifdef WIN32 #pragma warning( disable:4251 ) #endif @@ -52,10 +54,27 @@ public: virtual void ClearDriverContents(); protected: + /* void PutFilesToStream(const std::string& theModuleName, unsigned char*& theBuffer, long& theBufferSize, bool theNamesOnly = false); ListOfFiles PutStreamToFiles(const unsigned char* theBuffer, const long theBufferSize, bool theNamesOnly = false); + */ + + // New save + bool PutFilesToFirstStream( const std::string& theModuleName, unsigned char*& theBuffer, + long& theBufferSize, bool theNamesOnly = false ); + bool PutFilesToNextStream( const std::string& theModuleName, unsigned char*& theBuffer, + long& theBufferSize, bool theNamesOnly = false ); + bool HasUnsavedData() const; + + // New read + void PutFirstStreamToFiles( ListOfFiles& theListOfFiles, const unsigned char* theBuffer, + const long theBufferSize, bool theNamesOnly = false); + void PutNextStreamToFiles( ListOfFiles& theListOfFiles, const unsigned char* theBuffer, + const long theBufferSize, bool theNamesOnly = false); + + inline static size_t GetMaxBuffSize(); std::string GetTmpDir(); std::string GetDirFromPath(const std::string& thePath); @@ -70,6 +89,36 @@ protected: private: bool myIsTemp; + + // reading/writing + int myCurrFileIndex; + + // writing + size_t myCurrPos; + unsigned char* myCurrBuff; + ifstream* myCurrIFile; + size_t mySizeToBeWritten; + size_t* myFileSizes; + size_t* myFileNameSizes; + + // reading + ofstream* myCurrOFile; + long myNbFilles; }; +inline size_t LightApp_Driver::GetMaxBuffSize() +{ + static size_t aValue = 0; + if ( !aValue ) + { + char* aVar = getenv( "HDF_BUFFER_SIZE" ); + if ( aVar ) + aValue = (size_t)atol( aVar ); + else + aValue = 50000000; + } + + return aValue; +} + #endif diff --git a/src/LightApp/LightApp_HDFDriver.cxx b/src/LightApp/LightApp_HDFDriver.cxx index 20aba1ec5..7ddff2f20 100644 --- a/src/LightApp/LightApp_HDFDriver.cxx +++ b/src/LightApp/LightApp_HDFDriver.cxx @@ -18,6 +18,7 @@ // #include "LightApp_HDFDriver.h" +#include "HDFexplorer.hxx" #include "HDFOI.hxx" // OCCT Includes @@ -68,13 +69,6 @@ bool LightApp_HDFDriver::SaveDatasInFile( const char* theFileName, bool isMultiF for (it = myMap.begin(); it != myMap.end(); ++it, ++tag) { std::string aName (it->first); char* aModuleName = const_cast(aName.c_str()); - unsigned char* aBuffer; - long aBufferSize; - PutFilesToStream(aName, aBuffer, aBufferSize, isMultiFile); - - //Handle(SALOMEDSImpl_SComponent) sco = itcomponent.Value(); - //TCollection_AsciiString scoid = sco->GetID(); - //hdf_sco_group = new HDFgroup(scoid.ToCString(), hdf_group_datacomponent); TCollection_AsciiString entry ("0:1:"); entry += TCollection_AsciiString(tag); @@ -84,14 +78,38 @@ bool LightApp_HDFDriver::SaveDatasInFile( const char* theFileName, bool isMultiF hdf_sco_group = new HDFgroup (entry.ToCString(), hdf_group_datacomponent); hdf_sco_group->CreateOnDisk(); - aHDFSize[0] = aBufferSize; + unsigned char* aBuffer; + long aBufferSize; + + /*while( LightApp_Driver::HasUnsavedData() ) + PutFilesToNextStream( aName, aBuffer, aBufferSize, isMultiFile );*/ - hdf_dataset = new HDFdataset ("FILE_STREAM", hdf_sco_group, HDF_STRING, aHDFSize, 1); + // first data set + TCollection_AsciiString aBaseName( (Standard_CString)"FILE_STREAM" ); + PutFilesToFirstStream( aName, aBuffer, aBufferSize, isMultiFile ); + aHDFSize[0] = aBufferSize; + hdf_dataset = new HDFdataset( aBaseName.ToCString(), hdf_sco_group, HDF_STRING, aHDFSize, 1); hdf_dataset->CreateOnDisk(); hdf_dataset->WriteOnDisk(aBuffer); //Save the stream in the HDF file hdf_dataset->CloseOnDisk(); hdf_dataset = 0; //will be deleted by hdf_sco_group destructor + // other data sets + int anIndex = 0; + while( LightApp_Driver::HasUnsavedData() ) + { + anIndex++; + TCollection_AsciiString aDataSetName = + aBaseName + TCollection_AsciiString( anIndex ); + PutFilesToNextStream( aName, aBuffer, aBufferSize, isMultiFile ); + aHDFSize[0] = aBufferSize; + hdf_dataset = new HDFdataset( aDataSetName.ToCString(), hdf_sco_group, HDF_STRING, aHDFSize, 1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk(aBuffer); //Save the stream in the HDF file + hdf_dataset->CloseOnDisk(); + hdf_dataset = 0; //will be deleted by hdf_sco_group destructor + } + // store multifile state aHDFSize[0] = 2; hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1); @@ -270,23 +288,47 @@ bool LightApp_HDFDriver::ReadDatasFromFile( const char* theFileName, bool isMult hdf_sco_group->OpenOnDisk(); // Read component data - unsigned char* aStreamFile = NULL; - int aStreamSize = 0; - if (hdf_sco_group->ExistInternalObject("FILE_STREAM")) { - HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group); - hdf_dataset->OpenOnDisk(); - aStreamSize = hdf_dataset->GetSize(); - aStreamFile = new unsigned char[aStreamSize]; - if (aStreamFile == NULL) { - isError = true; - } else { - hdf_dataset->ReadFromDisk(aStreamFile); + // read first file stream + TCollection_AsciiString aBaseName( (Standard_CString)"FILE_STREAM" ); + ListOfFiles aListOfFiles; + for ( int ds = 0; true; ds++ ) { + unsigned char* aStreamFile = NULL; + int aStreamSize = 0; + + TCollection_AsciiString aDataSetName = aBaseName; + if ( ds > 0 ) + aDataSetName = aBaseName + TCollection_AsciiString( ds ); + + if ( hdf_sco_group->ExistInternalObject( aDataSetName.ToCString() ) ) { + HDFdataset *hdf_dataset = new HDFdataset( aDataSetName.ToCString(), hdf_sco_group ); + hdf_dataset->OpenOnDisk(); + aStreamSize = hdf_dataset->GetSize(); + aStreamFile = new unsigned char[aStreamSize]; + if (aStreamFile == NULL) { + isError = true; + } else { + hdf_dataset->ReadFromDisk(aStreamFile); + } + + hdf_dataset->CloseOnDisk(); + hdf_dataset = 0; + } + else + break; + + if ( aStreamFile != NULL ) + { + if ( ds == 0 ) + PutFirstStreamToFiles( aListOfFiles, aStreamFile, aStreamSize, isMultiFile ); + else + PutNextStreamToFiles( aListOfFiles, aStreamFile, aStreamSize, isMultiFile ); + delete [] aStreamFile; } + } // for ( int i = 0; true; i++ ) - hdf_dataset->CloseOnDisk(); - hdf_dataset = 0; - } + char* aCompDataType = (char*)(mapEntryName[name].c_str()); + SetListOfFiles( aCompDataType, aListOfFiles ); HDFdataset *multifile_hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group); multifile_hdf_dataset->OpenOnDisk(); @@ -302,15 +344,6 @@ bool LightApp_HDFDriver::ReadDatasFromFile( const char* theFileName, bool isMult isASCII = (ASCIIfileState[0] == 'A') ? true : false; - if (aStreamFile != NULL) { - // Put buffer to aListOfFiles and set to myMap - ListOfFiles aListOfFiles = PutStreamToFiles(aStreamFile, aStreamSize, isMultiFile); - char* aCompDataType = (char*)(mapEntryName[name].c_str()); - SetListOfFiles(aCompDataType, aListOfFiles); - - delete [] aStreamFile; - } - hdf_sco_group->CloseOnDisk(); } } diff --git a/src/LightApp/LightApp_Module.cxx b/src/LightApp/LightApp_Module.cxx index 12a94b34a..25d3796b2 100644 --- a/src/LightApp/LightApp_Module.cxx +++ b/src/LightApp/LightApp_Module.cxx @@ -634,3 +634,13 @@ LightApp_Operation* LightApp_Module::operation( const int id ) const { return myOperations.contains( id ) ? myOperations[id] : 0; } + +/*! + * \brief Virtual public method called to custom update of the desktop title + * \param theTitle - current desktop title + * \return Modified desktop title +*/ +QString LightApp_Module::updateDesktopTitle( const QString& theTitle ) +{ + return theTitle; +} diff --git a/src/LightApp/LightApp_Module.h b/src/LightApp/LightApp_Module.h index d32fb1eb8..0bb886f6a 100644 --- a/src/LightApp/LightApp_Module.h +++ b/src/LightApp/LightApp_Module.h @@ -90,6 +90,9 @@ public: virtual LightApp_Displayer* displayer(); virtual LightApp_Selection* createSelection() const; + virtual QString updateDesktopTitle( const QString& ); + // Custom update desktop title + public slots: virtual bool activateModule( SUIT_Study* ); virtual bool deactivateModule( SUIT_Study* ); diff --git a/src/LightApp/LightApp_SelectionMgr.cxx b/src/LightApp/LightApp_SelectionMgr.cxx index c466bbe31..7e47b6507 100644 --- a/src/LightApp/LightApp_SelectionMgr.cxx +++ b/src/LightApp/LightApp_SelectionMgr.cxx @@ -265,7 +265,7 @@ void LightApp_SelectionMgr::AddOrRemoveIndex( const Handle(SALOME_InteractiveObj select 'subobjects' with given indexes */ void LightApp_SelectionMgr::selectObjects( const Handle(SALOME_InteractiveObject)& IObject, - TColStd_IndexedMapOfInteger theIndex, bool append ) + const TColStd_IndexedMapOfInteger& theIndex, bool append ) { SUIT_DataOwnerPtrList aList; diff --git a/src/LightApp/LightApp_SelectionMgr.h b/src/LightApp/LightApp_SelectionMgr.h index b1db5bfe4..8b117dc2d 100644 --- a/src/LightApp/LightApp_SelectionMgr.h +++ b/src/LightApp/LightApp_SelectionMgr.h @@ -70,7 +70,7 @@ public: bool modeShift ); void selectObjects( const Handle(SALOME_InteractiveObject)& IObject, - TColStd_IndexedMapOfInteger theIndex, bool append ); + const TColStd_IndexedMapOfInteger& theIndex, bool append ); void selectObjects( MapIOOfMapOfInteger theMapIO, bool append ); void selectedSubOwners( MapEntryOfMapOfInteger& theMap ); diff --git a/src/LightApp/LightApp_VTKSelector.cxx b/src/LightApp/LightApp_VTKSelector.cxx index bd4c4100d..61663b751 100644 --- a/src/LightApp/LightApp_VTKSelector.cxx +++ b/src/LightApp/LightApp_VTKSelector.cxx @@ -34,6 +34,7 @@ #ifndef DISABLE_SALOMEOBJECT #include "SALOME_Actor.h" #include "SALOME_ListIteratorOfListIO.hxx" + #include "LightApp_DataSubOwner.h" #endif @@ -85,6 +86,16 @@ LightApp_SVTKDataOwner return myIds; } +/*! + Sets dataowners ids list. +*/ +void +LightApp_SVTKDataOwner +::SetIds( const TColStd_IndexedMapOfInteger& theIds ) +{ + myIds = theIds; +} + /*! Gets selection mode. */ @@ -191,7 +202,14 @@ LightApp_VTKSelector for(; anIter.More(); anIter.Next()){ Handle(SALOME_InteractiveObject) anIO = anIter.Value(); if(anIO->hasEntry()) - aList.append(new LightApp_SVTKDataOwner(anIO,aViewMgr->getDesktop())); + { + LightApp_SVTKDataOwner* anOwner = + new LightApp_SVTKDataOwner( anIO, aViewMgr->getDesktop() ); + TColStd_IndexedMapOfInteger anIndex; + aSelector->GetIndex( anIO, anIndex ); + anOwner->SetIds( anIndex ); + aList.append( anOwner ); + } } } } @@ -224,11 +242,14 @@ LightApp_VTKSelector anAppendList.Append(anIO); aSelector->AddOrRemoveIndex(anIO,anOwner->GetIds(),false); - }else if(const LightApp_DataOwner* anOwner = dynamic_cast(aDataOwner)){ + }else if(const LightApp_DataSubOwner* anOwner = dynamic_cast(aDataOwner)){ Handle(SALOME_InteractiveObject) anIO = - new SALOME_InteractiveObject(anOwner->entry().toLatin1(),""); + new SALOME_InteractiveObject(anOwner->entry().toLatin1(),""); aSelector->AddIObject(anIO); anAppendList.Append(anIO); + TColStd_IndexedMapOfInteger aMap; + aMap.Add( anOwner->index() ); + aSelector->AddOrRemoveIndex( anIO,aMap, false ); } } // To remove IOs, which is not selected. diff --git a/src/LightApp/LightApp_VTKSelector.h b/src/LightApp/LightApp_VTKSelector.h index ff68f3507..cc500e069 100644 --- a/src/LightApp/LightApp_VTKSelector.h +++ b/src/LightApp/LightApp_VTKSelector.h @@ -25,6 +25,10 @@ #include +#ifdef WIN32 +#pragma warning( disable:4251 ) +#endif + class SUIT_Desktop; #ifndef DISABLE_VTKVIEWER @@ -55,6 +59,9 @@ class LIGHTAPP_EXPORT LightApp_SVTKDataOwner : public LightApp_DataOwner /*!Gets dataowners ids list.*/ const TColStd_IndexedMapOfInteger& GetIds() const; + /*!Sets dataowners ids list.*/ + void SetIds( const TColStd_IndexedMapOfInteger& ); + /*!Gets selection mode.*/ Selection_Mode GetMode() const; diff --git a/src/Plot2d/Makefile.am b/src/Plot2d/Makefile.am index fcc63aec1..bf2cc34a7 100755 --- a/src/Plot2d/Makefile.am +++ b/src/Plot2d/Makefile.am @@ -37,6 +37,7 @@ salomeinclude_HEADERS = \ Plot2d_ViewModel.h \ Plot2d_ViewWindow.h \ Plot2d_SetupCurveDlg.h \ + Plot2d_SetupCurvesDlg.h \ Plot2d_ToolTip.h dist_libPlot2d_la_SOURCES = \ @@ -50,6 +51,7 @@ dist_libPlot2d_la_SOURCES = \ Plot2d_ViewModel.cxx \ Plot2d_ViewWindow.cxx \ Plot2d_SetupCurveDlg.cxx \ + Plot2d_SetupCurvesDlg.cxx \ Plot2d_ToolTip.cxx MOC_FILES = \ @@ -60,6 +62,7 @@ MOC_FILES = \ Plot2d_ViewModel_moc.cxx \ Plot2d_ViewWindow_moc.cxx \ Plot2d_SetupCurveDlg_moc.cxx \ + Plot2d_SetupCurvesDlg_moc.cxx \ Plot2d_ToolTip_moc.cxx nodist_libPlot2d_la_SOURCES = $(MOC_FILES) @@ -79,7 +82,9 @@ dist_salomeres_DATA = \ resources/plot2d_points.png \ resources/plot2d_settings.png \ resources/plot2d_splines.png \ - resources/plot2d_zoom.png + resources/plot2d_zoom.png \ + resources/plot2d_curves_settings.png \ + resources/plot2d_minus.png nodist_salomeres_DATA = \ Plot2d_images.qm \ diff --git a/src/Plot2d/Plot2d_Curve.cxx b/src/Plot2d/Plot2d_Curve.cxx index d26164e73..fec976268 100755 --- a/src/Plot2d/Plot2d_Curve.cxx +++ b/src/Plot2d/Plot2d_Curve.cxx @@ -34,7 +34,8 @@ Plot2d_Curve::Plot2d_Curve() myMarker( Plot2d::Circle ), myLine( Plot2d::Solid ), myLineWidth( 0 ), - myYAxis( QwtPlot::yLeft ) + myYAxis( QwtPlot::yLeft ), + myNbMarkers( 1 ) { } @@ -60,6 +61,7 @@ Plot2d_Curve::Plot2d_Curve( const Plot2d_Curve& curve ) myLine = curve.getLine(); myLineWidth = curve.getLineWidth(); myPoints = curve.getPointList(); + myNbMarkers = curve.getNbMarkers(); } /*! @@ -77,6 +79,7 @@ Plot2d_Curve& Plot2d_Curve::operator=( const Plot2d_Curve& curve ) myLine = curve.getLine(); myLineWidth = curve.getLineWidth(); myPoints = curve.getPointList(); + myNbMarkers = curve.getNbMarkers(); return *this; } @@ -314,6 +317,23 @@ Plot2d::MarkerType Plot2d_Curve::getMarker() const return myMarker; } +/*! + Sets number of markers per step ( and resets AutoAssign flag ). +*/ +void Plot2d_Curve::setNbMarkers( const int nbMarkers ) +{ + myNbMarkers = nbMarkers; + myAutoAssign = false; +} + +/*! + Gets number of markers per step ( and resets AutoAssign flag ). +*/ +int Plot2d_Curve::getNbMarkers() const +{ + return myNbMarkers; +} + /*! Sets curve's line type and width ( and resets AutoAssign flag ) NOTE : A line width of 0 will produce a 1 pixel wide line using a fast algorithm for diagonals. @@ -377,6 +397,21 @@ double Plot2d_Curve::getMinX() const return aMinX; } +/*! + Gets curve's maxiaml abscissa +*/ +double Plot2d_Curve::getMaxX() const +{ + QList::const_iterator aIt; + double aMaxX = -1e150; + //int aCurrent = 0; + for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) { + if ( (*aIt).x > aMaxX ) + aMaxX = (*aIt).x; + } + return aMaxX; +} + /*! Gets curve's minimal ordinate */ @@ -392,6 +427,21 @@ double Plot2d_Curve::getMinY() const return aMinY; } +/*! + Gets curve's maximal ordinate +*/ +double Plot2d_Curve::getMaxY() const +{ + QList::const_iterator aIt; + double aMaxY = -1e150; + //int aCurrent = 0; + for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) { + if ( (*aIt).y > aMaxY ) + aMaxY = (*aIt).y; + } + return aMaxY; +} + /*! Changes text assigned to point of curve \param ind -- index of point diff --git a/src/Plot2d/Plot2d_Curve.h b/src/Plot2d/Plot2d_Curve.h index 3474a56b7..8692be8c9 100755 --- a/src/Plot2d/Plot2d_Curve.h +++ b/src/Plot2d/Plot2d_Curve.h @@ -85,6 +85,9 @@ public: void setMarker( Plot2d::MarkerType ); Plot2d::MarkerType getMarker() const; + void setNbMarkers( const int ); + int getNbMarkers() const; + void setLine( Plot2d::LineType, const int = 0 ); Plot2d::LineType getLine() const; int getLineWidth() const; @@ -97,6 +100,11 @@ public: // non-positive X/Y coordinate double getMinX() const; double getMinY() const; + // Protection against QwtCurve::drawLines() bug in Qwt 0.4.x: + // sometimes it crashes (FPE) if draws curve with big abciss or ordinate cooridates + // after curve with small values + double getMaxX() const; + double getMaxY() const; protected: bool myAutoAssign; @@ -106,6 +114,7 @@ protected: QString myVerUnits; QColor myColor; Plot2d::MarkerType myMarker; + int myNbMarkers; Plot2d::LineType myLine; int myLineWidth; QwtPlot::Axis myYAxis; diff --git a/src/Plot2d/Plot2d_SetupCurvesDlg.cxx b/src/Plot2d/Plot2d_SetupCurvesDlg.cxx new file mode 100755 index 000000000..de2671d8a --- /dev/null +++ b/src/Plot2d/Plot2d_SetupCurvesDlg.cxx @@ -0,0 +1,637 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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 +// +// SALOME Plot2d : implementation of desktop and GUI kernel +// +// File : Plot2d_SetupCurvesDlg.cxx +// Author : Sergey LITONIN + +#include "Plot2d_SetupCurvesDlg.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include "Plot2d.h" +#include +#include + +#define PIXMAP_COL 0 +#define TEXT_COL 1 +#define MARKER_COL 2 +#define COLOR_COL 3 +#define NB_MARKERS_COL 4 + + +/*! + \class Plot2d_SetupCurvesDlg::PixmapWg + \internal + \brief This class is derived from QWidget is intended for drawing curves symbol + inside its area. It contains QwtSymbol as its internal field and delegates paint + event to it for drawing +*/ +class Plot2d_SetupCurvesDlg::PixmapWg : public QWidget +{ +public: + PixmapWg( QWidget* theParent ); + virtual ~PixmapWg(); + + void setColor( const QColor& ); + void setMarkerType( const int ); + +protected: + virtual void paintEvent( QPaintEvent * event ); + +private: + QwtSymbol mySymbol; +}; + +Plot2d_SetupCurvesDlg::PixmapWg::PixmapWg( QWidget* theParent ) +: QWidget( theParent ) +{ + mySymbol.setSize( QSize( 8, 8 ) ); + mySymbol.setStyle( QwtSymbol::NoSymbol ); +} + +Plot2d_SetupCurvesDlg::PixmapWg::~PixmapWg() +{ + +} + +//============================================================================= +// Function : setColor +// Purpose : +//============================================================================= +void Plot2d_SetupCurvesDlg::PixmapWg::setColor( const QColor& theColor ) +{ + mySymbol.setBrush( QBrush( theColor ) ); + mySymbol.setPen( QPen( theColor ) ); +} + +//============================================================================= +// Function : setMarkerType +// Purpose : +//============================================================================= +void Plot2d_SetupCurvesDlg::PixmapWg::setMarkerType( const int theType ) +{ + QwtSymbol::Style aStyle = QwtSymbol::NoSymbol; + switch( theType ) + { + case Plot2d::Circle : aStyle = QwtSymbol::Ellipse; break; + case Plot2d::Rectangle: aStyle = QwtSymbol::Rect; break; + case Plot2d::Diamond : aStyle = QwtSymbol::Diamond; break; + case Plot2d::DTriangle: aStyle = QwtSymbol::DTriangle; break; + case Plot2d::UTriangle: aStyle = QwtSymbol::UTriangle; break; + case Plot2d::LTriangle: aStyle = QwtSymbol::LTriangle; break; + case Plot2d::RTriangle: aStyle = QwtSymbol::RTriangle; break; + case Plot2d::Cross : aStyle = QwtSymbol::Cross; break; + case Plot2d::XCross : aStyle = QwtSymbol::XCross; break; + } + + mySymbol.setStyle( aStyle ); +} + +//============================================================================= +// Function : paint +// Purpose : +//============================================================================= +void Plot2d_SetupCurvesDlg::PixmapWg::paintEvent( QPaintEvent* event ) +{ + QRect r = event->rect(); + /*int rm, lm, tm, bm; + if ( r.width() > 8 ) + { + rm = ( r.width() - 8 ) / 2; + lm = r.width() - 8 - rm; + } + if ( r.height() > 8 ) + { + tm = ( r.height() - 8 ) / 2; + bm = r.height() - 8 - tm; + } + + r.setLeft( r.left() + lm ); + r.setRight( r.right() - rm ); + r.setTop( r.top() + tm ); + r.setBottom( r.bottom() - bm );*/ + + QPainter p( this ); + mySymbol.draw( &p, r.center() ); +} + +/*! + \brief Constructor + \param theParent parent widget +*/ +Plot2d_SetupCurvesDlg::Plot2d_SetupCurvesDlg( QWidget* theParent ) +: QtxDialog( theParent, true, false, QtxDialog::OKCancel ) +{ + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + setWindowTitle( tr( "SETUP_CURVES" ) ); + + QFrame* aMainFrame = mainFrame(); + myGrp = new QtxGroupBox( aMainFrame ); + myGrp->setTitle( tr( "PARAMETERS" ) ); + QVBoxLayout* aLay = new QVBoxLayout( myGrp ); + aLay->setMargin( 0 ); + + // Create table + + myTable = new QTableWidget( myGrp ); + aLay->addWidget( myTable ); + + myTable->setRowCount( 0 ); + myTable->setColumnCount( 5 ); + + QStringList aLabels; + aLabels.append( tr( "FIG" ) ); + aLabels.append( tr( "TEXT" ) ); + aLabels.append( tr( "MARKER" ) ); + aLabels.append( tr( "COLOR" ) ); + aLabels.append( tr( "NB_MARKERS" ) ); + myTable->setHorizontalHeaderLabels( aLabels ); + myTable->verticalHeader()->hide(); + myTable->setSelectionMode( QTableWidget::NoSelection ); + + QComboBox* aCombo = new QComboBox( 0 ); + myTable->verticalHeader()->setDefaultSectionSize( aCombo->sizeHint().height() ); + delete aCombo; + + //myTable->setLeftMargin( 0 ); + int l, t, r, b; + myTable->getContentsMargins ( &l, &t, &r, &b ); + myTable->setContentsMargins ( 0, t, r, b ); + + myTable->horizontalHeader()->setResizeMode( PIXMAP_COL, QHeaderView::Fixed ); + myTable->horizontalHeader()->setResizeMode( TEXT_COL, QHeaderView::Fixed ); + myTable->horizontalHeader()->setResizeMode( MARKER_COL, QHeaderView::Fixed ); + myTable->horizontalHeader()->setResizeMode( COLOR_COL, QHeaderView::Fixed ); + myTable->horizontalHeader()->setResizeMode( NB_MARKERS_COL, QHeaderView::Fixed ); + myTable->horizontalHeader()->setHighlightSections( false ); + + // Minus button + QPixmap minusPix = aResMgr->loadPixmap( "Plot2d", tr( "ICON_MINUS" ) ); + myRemoveBtn = new QToolButton( 0 ); + myRemoveBtn->setIcon( minusPix ); + myRemoveBtn->setFixedSize( minusPix.size() /*+ QSize( 2, 2 )*/ ); + myGrp->insertTitleWidget( myRemoveBtn ); + + QVBoxLayout* aMainLay = new QVBoxLayout( aMainFrame ); + aMainLay->setMargin( 5 ); + aMainLay->addWidget( myGrp ); + + connect( myRemoveBtn, SIGNAL( clicked() ), SLOT( onRemove() ) ); + connect( myTable, SIGNAL( valueChanged( int, int ) ), SLOT( onValueChanged( int, int ) ) ); + + setButtonPosition( Right, Cancel ); +} + +/*! + \brief Destructor +*/ +Plot2d_SetupCurvesDlg::~Plot2d_SetupCurvesDlg() +{ +} + +/*! + \brief Insert combo-box widget in specified cell + \param theRow row + \param theCol column + \param theItems list of combo-box items + \param theCurrItem current combo-box item +*/ +void Plot2d_SetupCurvesDlg::setCombo( const int theRow, + const int theCol, + const QStringList& theItems, + const int theCurrItem, + const int theWidth ) +{ + QComboBox* aCombo = new QComboBox( myTable ); + aCombo->addItems( theItems ); + aCombo->setCurrentIndex( theCurrItem ); + if ( theWidth > 0 ) + aCombo->setFixedWidth( theWidth ); + myTable->setCellWidget( theRow, theCol, aCombo ); + connect( aCombo, SIGNAL( activated( int ) ), SLOT( onMarkerType() ) ); +} + +/*! + \brief Sets text in specified cell + \param theRow row + \param theCol column + \param theText text +*/ +void Plot2d_SetupCurvesDlg::setText( const int theRow, + const int theCol, + const QString& theText ) +{ + QTableWidgetItem* anItem = myTable->item( theRow, theCol ); + if ( !anItem ) + { + anItem = new QTableWidgetItem( theText ); + myTable->setItem( theRow, theCol, anItem ); + } + else + anItem->setText( theText ); +} + +//============================================================================= +// Function : SetParameters +// Purpose : +//============================================================================= +void Plot2d_SetupCurvesDlg::SetParameters( const QVector< int >& theMarker, + const QVector< QString >& theText, + const QVector< QColor >& theColor, + const QVector< int >& theNbMarkers ) +{ + int nbRows = qMax( qMax( theMarker.size(), theText.size()), + qMax( theColor.size(), theNbMarkers.size() ) ); + + myTable->setRowCount( nbRows ); + + const QStringList& aMarkers = getMarkers(); + + QFontMetrics fm( myTable->font() ); + int aTextLength = 0; + + // calculate width of combo-box + QStringList::const_iterator anIter; + int strWidth = 0; + for ( anIter = aMarkers.begin(); anIter != aMarkers.end(); ++anIter ) + strWidth = qMax( strWidth, fm.width( *anIter ) ); + strWidth += 20; + + for ( int i = 0; i < nbRows; i++ ) + { + // Pixmap + PixmapWg* aPixWg = new PixmapWg( myTable ) ; + myTable->setCellWidget( i, PIXMAP_COL, aPixWg ); + + // Marker type + setCombo( i, MARKER_COL, aMarkers, theMarker[ i ]/*, strWidth*/ ); + + // Text + + setText( i, TEXT_COL, theText[ i ] ); + aTextLength = qMax( aTextLength, fm.width( theText[ i ] ) ); + + // Color + QPushButton* aBtn = new QPushButton( myTable ); + myTable->setCellWidget( i, COLOR_COL, aBtn ); + setColor( aBtn, theColor[ i ] ); + connect( aBtn, SIGNAL( clicked() ), SLOT( onColorBtn() ) ); + + // Nb markers + setText( i, NB_MARKERS_COL, QString( "%1" ).arg( theNbMarkers[ i ] ) ); + } + + myTable->setColumnWidth( PIXMAP_COL, 24 ); + myTable->setColumnWidth( TEXT_COL, aTextLength + 10 ); + myTable->setColumnWidth( MARKER_COL, strWidth + 10 ); + myTable->setColumnWidth( COLOR_COL, fm.width( tr( "COLOR" ) ) + 10 ); + myTable->setColumnWidth( NB_MARKERS_COL, fm.width( tr( "NB_MARKERS" ) ) + 10 ); + int aWidth = myTable->columnWidth( PIXMAP_COL ) + myTable->columnWidth( TEXT_COL )+ + myTable->columnWidth( MARKER_COL ) + myTable->columnWidth( COLOR_COL ) + + myTable->columnWidth( NB_MARKERS_COL ); + + QFrame* aWg = (QFrame*)myTable->viewport()->parentWidget(); + + int fw = aWg->frameWidth(); + int lw = aWg->lineWidth(); + int mlw = aWg->midLineWidth(); + aWg->setFixedWidth( aWidth + 2 * fw ); + + myRemovedIndexes.clear(); + + updatePixmap( -1 ); +} + +//============================================================================= +// Function : GetParameters +// Purpose : +//============================================================================= +void Plot2d_SetupCurvesDlg::GetParameters( QVector< int >& theMarkers, + QVector< QString >& theTexts, + QVector< QColor >& theColors, + QVector< int >& theNbMarkers ) const +{ + int nbRows = myTable->rowCount(); + + theMarkers.resize( nbRows ); + theTexts.resize( nbRows ); + theColors.resize( nbRows ); + theNbMarkers.resize( nbRows ); + + for ( int i = 0; i < nbRows; i++ ) + { + // Marker type + QComboBox* aCombo = dynamic_cast( myTable->cellWidget( i, MARKER_COL ) ); + theMarkers[ i ] = aCombo ? aCombo->currentIndex() : -1; + + // Text + QTableWidgetItem* it = myTable->item( i, TEXT_COL ); + theTexts[ i ] = it ? it->text() : ""; + + // Color + QColor aColor; + QPushButton* aBtn = dynamic_cast< QPushButton* >( myTable->cellWidget( i, COLOR_COL ) ); + if ( aBtn ) + aColor = aBtn->palette().color( aBtn->backgroundRole() ); + + theColors[ i ] = aColor; + + // Nb markers + it = myTable->item( i, NB_MARKERS_COL ); + QString aStr = it ? it->text() : ""; + bool isOk = false; + int nbMarkers = aStr.toInt( &isOk ); + if ( isOk ) + theNbMarkers[ i ] = nbMarkers; + else + theNbMarkers[ i ] = -1; + } +} + +//============================================================================= +// Function : GetRemovedIndexes +// Purpose : +//============================================================================= +const QList< int >& Plot2d_SetupCurvesDlg::GetRemovedIndexes() const +{ + return myRemovedIndexes; +} + +//============================================================================= +// Function : acceptData +// Purpose : +//============================================================================= +bool Plot2d_SetupCurvesDlg::acceptData() const +{ + ((Plot2d_SetupCurvesDlg*)this)->setButtonFocus( OK ); + int nbRows = myTable->rowCount(); + for ( int i = 0; i < nbRows; i++ ) + { + QTableWidgetItem* it = myTable->item( i, NB_MARKERS_COL ); + QString aStr = it ? it->text() : ""; + bool isOk = false; + int nbMarkers = aStr.toInt( &isOk ); + if ( !isOk || nbMarkers<= 0 ) + { + SUIT_MessageBox::information( (QWidget*)this, tr( "PLOT2D_INSUFFICIENT_DATA" ), + tr( "PLOT2D_ENTER_VALID_DATA" ), tr( "BUT_OK" ) ); + return false; + } + } + + return true; +} + +//============================================================================= +// Function : getMarkers +// Purpose : +//============================================================================= +const QStringList& Plot2d_SetupCurvesDlg::getMarkers() const +{ + static QStringList aList; + + if ( aList.isEmpty() ) + { + aList.append( tr( "NONE_MARKER_LBL" ) ); + aList.append( tr( "CIRCLE_MARKER_LBL" ) ); + aList.append( tr( "RECTANGLE_MARKER_LBL" ) ); + aList.append( tr( "DIAMOND_MARKER_LBL" ) ); + aList.append( tr( "DTRIANGLE_MARKER_LBL" ) ); + aList.append( tr( "UTRIANGLE_MARKER_LBL" ) ); + aList.append( tr( "LTRIANGLE_MARKER_LBL" ) ); + aList.append( tr( "RTRIANGLE_MARKER_LBL" ) ); + aList.append( tr( "CROSS_MARKER_LBL" ) ); + aList.append( tr( "XCROSS_MARKER_LBL" ) ); + } + + return aList; +} + +//============================================================================= +// Function : onRemove +// Purpose : +//============================================================================= +void Plot2d_SetupCurvesDlg::onRemove( ) +{ + QList< int > toRemove; + + int aCurrRow = myTable->currentRow(); + int aCurrCol = myTable->currentColumn(); + + // get selected rows + QSet< int > aSelRows; + QList aRegs = myTable->selectedRanges(); + QList::iterator selIter; + for ( selIter = aRegs.begin(); selIter != aRegs.end(); ++selIter ) + { + const QTableWidgetSelectionRange& aReg = *selIter; + for ( int i = aReg.topRow(), n = aReg.bottomRow(); i < n; i++ ) + aSelRows.insert( i ); + } + + int i, n; + for ( i = 0, n = myTable->rowCount(); i < n; i++ ) + { + if ( aSelRows.contains( i ) || aCurrRow == i ) + toRemove.append( i ); + } + + if ( !toRemove.count() ) + return; + + int nbRemoved = 0; + QList< int >::iterator anIter; + for ( anIter = toRemove.begin(); anIter != toRemove.end(); ++anIter ) + { + int aRow = *anIter - nbRemoved; + myTable->removeRow( aRow ); + myRemovedIndexes.append( aRow ); + nbRemoved++; + } + + int nbRows = myTable->rowCount(); + if ( aCurrRow < nbRows && aCurrRow >= 0 && aCurrCol >= 0 ) + myTable->setCurrentCell( aCurrRow, aCurrCol ); + else if ( nbRows > 0 && aCurrCol >= 0 ) + myTable->setCurrentCell( nbRows - 1, aCurrCol ); +} + +//============================================================================= +// Function : onColorBtn +// Purpose : +//============================================================================= +void Plot2d_SetupCurvesDlg::onColorBtn() +{ + QObject* aSender = (QObject*)sender(); + if ( !aSender ) + return; + + QPushButton* aBtn = dynamic_cast< QPushButton* >( aSender ); + if ( !aBtn ) + return; + + QColor anOldColor = aBtn->palette().color( aBtn->backgroundRole() ); + QColor aNewColor = QColorDialog::getColor( anOldColor, this ); + if ( !aNewColor.isValid() ) + return; + + setColor( aBtn, aNewColor ); + + for ( int i = 0, n = myTable->rowCount(); i < n; i++ ) + { + QWidget* aWg = myTable->cellWidget( i, COLOR_COL ); + if ( aWg == aBtn ) + { + updatePixmap( i ); + break; + } + } +} + +//============================================================================= +// Function : onColorBtn +// Purpose : +//============================================================================= +void Plot2d_SetupCurvesDlg::onMarkerType() +{ + QObject* aSender = (QObject*)sender(); + if ( !aSender ) + return; + + QComboBox* aCombo = dynamic_cast< QComboBox* >( aSender ); + if ( !aCombo ) + return; + + for ( int i = 0, n = myTable->rowCount(); i < n; i++ ) + { + QWidget* aWg = myTable->cellWidget( i, MARKER_COL ); + if ( aWg == aCombo ) + { + updatePixmap( i ); + break; + } + } +} + +//============================================================================= +// Function : updatePixmap +// Purpose : +//============================================================================= +void Plot2d_SetupCurvesDlg::updatePixmap( const int theRow ) +{ + QList< int > aRows; + if ( theRow < 0 ) + { + for ( int i = 0, n = myTable->rowCount(); i < n; i++ ) + aRows.append( i ); + } + else + aRows.append( theRow ); + + QList< int >::iterator anIter; + for ( anIter = aRows.begin(); anIter != aRows.end(); ++anIter ) + { + int r = *anIter; + PixmapWg* aWg = dynamic_cast( myTable->cellWidget( r, PIXMAP_COL ) ); + if ( aWg ) + { + // Marker type + QComboBox* aCombo = dynamic_cast( myTable->cellWidget( r, MARKER_COL ) ); + int aMType = aCombo ? aCombo->currentIndex() : Plot2d::None; + aWg->setMarkerType( aMType ); + + // Color + QColor aColor; + QPushButton* aBtn = dynamic_cast< QPushButton* >( myTable->cellWidget( r, COLOR_COL ) ); + if ( aBtn ) + { + aColor = aBtn->palette().color( aBtn->backgroundRole() ); + aWg->setColor( aColor ); + } + + aWg->repaint(); + } + } +} + +//============================================================================= +// Function : onValueChanged +// Purpose : +//============================================================================= +void Plot2d_SetupCurvesDlg::onValueChanged( int theRow, int theCol ) +{ + if ( theCol == COLOR_COL || theCol == MARKER_COL ) + updatePixmap( theRow ); +} + +//============================================================================= +// Function : setColor +// Purpose : +//============================================================================= +void Plot2d_SetupCurvesDlg::setColor( QPushButton* theBtn, const QColor& theColor ) const +{ + QPalette aPal = theBtn->palette(); + aPal.setColor( theBtn->backgroundRole(), theColor ); + theBtn->setPalette( aPal ); + + /*theBtn->setPaletteBackgroundColor( theColor ); + + QPalette aPalette = theBtn->palette(); + aPalette.setColor( QColorGroup::Midlight, theColor ); + theBtn->setPalette( aPalette );*/ +} + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Plot2d/Plot2d_SetupCurvesDlg.h b/src/Plot2d/Plot2d_SetupCurvesDlg.h new file mode 100755 index 000000000..33364f821 --- /dev/null +++ b/src/Plot2d/Plot2d_SetupCurvesDlg.h @@ -0,0 +1,105 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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 +// +// SALOME Plot2d : implementation of desktop and GUI kernel +// +// File : Plot2d_SetupCurvesDlg.h +// Author : Sergey LITONIN + +#ifndef PLOT2D_SETUPCURVESDLG_H +#define PLOT2D_SETUPCURVESDLG_H + +#include "Plot2d.h" +#include +#include +#include + +class QtxGroupBox; +class QTableWidget; +class QwtLegend; +class QToolButton; + +#if defined WIN32 +#pragma warning( disable: 4251 ) +#endif + +/*! + \class Plot2d_SetupCurvesDlg + Dialog box for setup Plot2d curves parameters +*/ + +class PLOT2D_EXPORT Plot2d_SetupCurvesDlg : public QtxDialog +{ + Q_OBJECT + + class PixmapWg; + +public: + Plot2d_SetupCurvesDlg( QWidget* theParent = 0 ); + virtual ~Plot2d_SetupCurvesDlg(); + + void SetParameters( const QVector< int >& theMarker, + const QVector< QString >& theText, + const QVector< QColor >& theColor, + const QVector< int >& theNbMarkers ); + + void GetParameters( QVector< int >& theMarker, + QVector< QString >& theText, + QVector< QColor >& theColor, + QVector< int >& theNbMarkers ) const; + + const QList< int >& GetRemovedIndexes() const; + +protected: + + virtual bool acceptData() const; + +private slots: + + void onRemove(); + void onColorBtn(); + void onValueChanged( int, int ); + void onMarkerType(); + +private: + + const QStringList& getMarkers() const; + void updatePixmap( const int theRow ); + void setColor( QPushButton* theBtn, const QColor& theColor ) const; + void setCombo( const int theRow, + const int theCol, + const QStringList& theItems, + const int theCurrItem = 0, + const int theWidth = -1 ); + void setText( const int theRow, + const int theCol, + const QString& theText ); +private: + + QtxGroupBox* myGrp; + QTableWidget* myTable; + QToolButton* myRemoveBtn; + QList< int > myRemovedIndexes; +}; + +#endif + + + + + diff --git a/src/Plot2d/Plot2d_ViewFrame.cxx b/src/Plot2d/Plot2d_ViewFrame.cxx index b3fe3d4e6..d4152dd04 100755 --- a/src/Plot2d/Plot2d_ViewFrame.cxx +++ b/src/Plot2d/Plot2d_ViewFrame.cxx @@ -20,6 +20,7 @@ #include "Plot2d_Prs.h" #include "Plot2d_Curve.h" +#include "Plot2d_SetupCurvesDlg.h" #include "Plot2d_FitDataDlg.h" #include "Plot2d_ViewWindow.h" #include "Plot2d_SetupViewDlg.h" @@ -49,7 +50,6 @@ #include #include #include -#include #include #include #include @@ -60,6 +60,7 @@ #include #include +#include #define DEFAULT_LINE_WIDTH 0 // (default) line width #define DEFAULT_MARKER_SIZE 9 // default marker size @@ -144,6 +145,14 @@ const char* imageCrossCursor[] = { "................................"}; +QString Plot2d_ViewFrame::myPrefTitle = ""; +QString Plot2d_ViewFrame::myPrefXTitle = ""; +QString Plot2d_ViewFrame::myPrefYTitle = ""; + +bool Plot2d_ViewFrame::myPrefTitleChangedByUser = false; +bool Plot2d_ViewFrame::myXPrefTitleChangedByUser = false; +bool Plot2d_ViewFrame::myYPrefTitleChangedByUser = false; + /*! Constructor */ @@ -161,7 +170,9 @@ Plot2d_ViewFrame::Plot2d_ViewFrame( QWidget* parent, const QString& title ) myXGridMinorEnabled( false ), myYGridMinorEnabled( false ), myY2GridMinorEnabled( false ), myXGridMaxMajor( 8 ), myYGridMaxMajor( 8 ), myY2GridMaxMajor( 8 ), myXGridMaxMinor( 5 ), myYGridMaxMinor( 5 ), myY2GridMaxMinor( 5 ), - myXMode( 0 ), myYMode( 0 ), mySecondY( false ) + myXMode( 0 ), myYMode( 0 ), mySecondY( false ), + myTitleAutoUpdate( true ), myXTitleAutoUpdate( true ), myYTitleAutoUpdate( true ), + myTitleChangedByUser( false ), myXTitleChangedByUser( false ), myYTitleChangedByUser( false ) { setObjectName( title ); /* Plot 2d View */ @@ -231,6 +242,7 @@ void Plot2d_ViewFrame::DisplayAll() getCurves( clist ); for ( int i = 0; i < (int)clist.count(); i++ ) { updateCurve( clist.at( i ), false ); + emit curveDisplayed( clist.at( i ) ); } myPlot->replot(); } @@ -239,6 +251,10 @@ void Plot2d_ViewFrame::DisplayAll() */ void Plot2d_ViewFrame::EraseAll() { + CurveDict::iterator it = myPlot->getCurves().begin(); + for ( ; it != myPlot->getCurves().end(); it++ ) + emit curveErased( it.value() ); + myPlot->clear(); myPlot->getCurves().clear(); myPlot->replot(); @@ -379,6 +395,10 @@ void Plot2d_ViewFrame::readPreferences() int newYMode = resMgr->integerValue( "Plot2d", "VerScaleMode", myYMode ); newYMode = qMax( 0, qMin( 1, newYMode ) ); setVerScaleMode( newYMode, false ); + + myTitle = myPrefTitle; + myXTitle = myPrefXTitle; + myYTitle = myPrefYTitle; } /*! @@ -421,6 +441,22 @@ void Plot2d_ViewFrame::writePreferences() } resMgr->setValue( "Plot2d", "VerScaleMode", myYMode ); + + if ( myTitleChangedByUser ) + { + myPrefTitle = myTitle; + myPrefTitleChangedByUser = true; + } + if ( myXTitleChangedByUser ) + { + myPrefXTitle = myXTitle; + myXPrefTitleChangedByUser = true; + } + if ( myYTitleChangedByUser ) + { + myPrefYTitle = myYTitle; + myYPrefTitleChangedByUser = true; + } } /*! @@ -546,7 +582,7 @@ void Plot2d_ViewFrame::displayCurve( Plot2d_Curve* curve, bool update ) updateCurve( curve, update ); } else { - QwtPlotCurve* aPCurve = new QwtPlotCurve( curve->getVerTitle() ); + QwtPlotCurve* aPCurve = new Plot2d_PlotCurve( curve->getVerTitle() ); aPCurve->attach( myPlot ); //myPlot->setCurveYAxis(curveKey, curve->getYAxis()); @@ -565,6 +601,7 @@ void Plot2d_ViewFrame::displayCurve( Plot2d_Curve* curve, bool update ) curve->setColor( color ); curve->setLine( Plot2d::qwt2plotLine( typeLine ) ); curve->setMarker( Plot2d::qwt2plotMarker( typeMarker ) ); + myPlot->setCurveNbMarkers( curve, 1 ); } else { Qt::PenStyle ps = Plot2d::plot2qwtLine( curve->getLine() ); @@ -574,6 +611,7 @@ void Plot2d_ViewFrame::displayCurve( Plot2d_Curve* curve, bool update ) QBrush( curve->getColor() ), QPen( curve->getColor() ), QSize( myMarkerSize, myMarkerSize ) ) ); + myPlot->setCurveNbMarkers( curve, curve->getNbMarkers() ); } setCurveType( aPCurve, myCurveType ); aPCurve->setData( curve->horData(), curve->verData(), curve->nbPoints() ); @@ -581,6 +619,8 @@ void Plot2d_ViewFrame::displayCurve( Plot2d_Curve* curve, bool update ) updateTitles(); if ( update ) myPlot->replot(); + + emit curveDisplayed( curve ); } /*! @@ -617,6 +657,7 @@ void Plot2d_ViewFrame::eraseCurve( Plot2d_Curve* curve, bool update ) updateTitles(); if ( update ) myPlot->replot(); + emit curveErased( curve ); } } @@ -654,6 +695,9 @@ void Plot2d_ViewFrame::updateCurve( Plot2d_Curve* curve, bool update ) QPen( curve->getColor() ), QSize( myMarkerSize, myMarkerSize ) ) ); aPCurve->setData( curve->horData(), curve->verData(), curve->nbPoints() ); + Plot2d_PlotCurve* aPlot2dCurve = dynamic_cast< Plot2d_PlotCurve* >( aPCurve ); + if ( aPlot2dCurve ) + aPlot2dCurve->setNbMarkers( curve->getNbMarkers() ); } aPCurve->setTitle( curve->getVerTitle() ); aPCurve->setVisible( true ); @@ -907,14 +951,26 @@ void Plot2d_ViewFrame::onSettings() myY2GridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::yRight ) ); if ( dlg->exec() == QDialog::Accepted ) { // horizontal axis title + bool isTileChanged = dlg->getXTitle() != myXTitle; setTitle( dlg->isXTitleEnabled(), dlg->getXTitle(), XTitle, false ); + if ( isTileChanged ) + myXTitleChangedByUser = true; + // vertical left axis title + isTileChanged = dlg->getYTitle() != myYTitle; setTitle( dlg->isYTitleEnabled(), dlg->getYTitle(), YTitle, false ); + if ( isTileChanged ) + myYTitleChangedByUser = true; + if (mySecondY) // vertical right axis title setTitle( dlg->isY2TitleEnabled(), dlg->getY2Title(), Y2Title, false ); // main title + isTileChanged = dlg->getMainTitle() != myTitle; setTitle( dlg->isMainTitleEnabled(), dlg->getMainTitle(), MainTitle, true ); + if ( isTileChanged ) + myTitleChangedByUser = true; + // curve type if ( myCurveType != dlg->getCurveType() ) { setCurveType( dlg->getCurveType(), false ); @@ -961,6 +1017,139 @@ void Plot2d_ViewFrame::onSettings() delete dlg; } +/*! + "Curves settings" toolbar action slot +*/ +void Plot2d_ViewFrame::onCurvesSettings() +{ + Plot2d_SetupCurvesDlg* aDlg = new Plot2d_SetupCurvesDlg( this ); + + // Initialize dialog with legend + int nbCurves = myPlot->getCurves().count(); + if ( nbCurves == 0 ) + return; + + QVector< int > aMarkers( nbCurves ); + QVector< QString > aTexts( nbCurves ); + QVector< QColor > aColors( nbCurves ); + QVector< int > nbMarkers( nbCurves ); + + QList< Plot2d_Curve* > aCurves; + + CurveDict::iterator it = myPlot->getCurves().begin(); + int i = 0; + for ( i = 0; it != myPlot->getCurves().end(); it++, i++ ) + { + Plot2d_Curve* aCurve = it.value(); + if ( !aCurve ) + return; + + int aMarkerType = aCurve->getMarker(); + QString aText = aCurve->getHorTitle(); + if ( aText.isEmpty() ) + aText = aCurve->getVerTitle(); + QColor aColor = aCurve->getColor(); + int nbMarker = aCurve->getNbMarkers(); + + aMarkers[ i ] = aMarkerType; + aTexts[ i ] = aText; + aColors[ i ] = aColor; + nbMarkers[ i ] = nbMarker; + + aCurves.append( aCurve ); + } + + aDlg->SetParameters( aMarkers, aTexts, aColors, nbMarkers ); + + if ( aDlg->exec() != QDialog::Accepted ) + return; + + // Note: Indexes retrieved from dialog do not correspond to the real indexes of + // plot 2d curves. They correspond to the user actions. For example, if user removes + // first curve in dialog’s table two times. Then contents of list of indexes is + // equal (1, 1) although first and second curves must be removed. + const QList< int >& toRemove = aDlg->GetRemovedIndexes(); + QList< int >::const_iterator aRemIter; + for ( aRemIter = toRemove.begin(); aRemIter != toRemove.end(); ++aRemIter ) + { + int anIndex = *aRemIter; + if ( anIndex >= 0 && anIndex < (int)aCurves.count() ) + { + Plot2d_Curve* aCurve = aCurves[ anIndex ]; + aCurves.removeAt( anIndex ); + eraseCurve( aCurve ); + } + } + + QMap< int, Plot2d_Curve* > anIndexToCurve; + QList< Plot2d_Curve* >::iterator aCurvIter; + for ( i = 0, aCurvIter = aCurves.begin(); aCurvIter != aCurves.end(); ++aCurvIter, ++i ) + { + anIndexToCurve[ i ] = *aCurvIter; + } + + aDlg->GetParameters( aMarkers, aTexts, aColors, nbMarkers ); + + int n; + for ( i = 0, n = aMarkers.size(); i < n; i++ ) + { + Plot2d_Curve* aCurve = anIndexToCurve[ i ]; + aCurve->setAutoAssign( false ); + + // old values + Plot2d::MarkerType anOldMarker = aCurve->getMarker(); + QString anOldText = aCurve->getHorTitle(); + bool isHorTitle = true; + if ( anOldText.isEmpty() ) + { + anOldText = aCurve->getVerTitle(); + isHorTitle = false; + } + QColor anOldColor = aCurve->getColor(); + int anOldNbMarker = aCurve->getNbMarkers(); + + // new values + + Plot2d::MarkerType aMarker = (Plot2d::MarkerType)aMarkers[ i ]; + QString aText = aTexts[ i ]; + QColor aColor = aColors[ i ]; + int nbMarker = nbMarkers[ i ]; + + bool toUpdate = false; + + if ( anOldMarker != aMarker ) + { + aCurve->setMarker( aMarker ); + toUpdate = true; + } + if ( anOldText != aText ) + { + if ( isHorTitle ) + aCurve->setHorTitle( aText ); + else + aCurve->setVerTitle( aText ); + toUpdate = true; + } + if ( anOldColor != aColor ) + { + aCurve->setColor( aColor ); + toUpdate = true; + } + if ( anOldNbMarker != nbMarker ) + { + aCurve->setNbMarkers( nbMarker ); + toUpdate = true; + } + + if ( toUpdate ) + updateCurve( aCurve, false ); + } + + Repaint(); + + delete aDlg; +} + /*! "Fit Data" command slot */ @@ -1580,6 +1769,94 @@ public: ~Plot2d_QwtPlotZoomer() {}; }; + +/*! + Constructor +*/ +Plot2d_PlotCurve::Plot2d_PlotCurve( const QString& title ) +: QwtPlotCurve( title ), + myNbMarkers( 1 ) +{ +} + +Plot2d_PlotCurve::~Plot2d_PlotCurve() +{ +} + +/*! + Sets number of markers for steps. If number of markers is equal to 1 then + markers are displayed for steps only. If number of markers is equal to 3 + (for example) then markers are displayed for steps and two markers are + displayed between side by side steps. +*/ +void Plot2d_PlotCurve::setNbMarkers( const int theNbMarkers ) +{ + myNbMarkers = theNbMarkers; +} + +/*! + Gets number of markers for steps. If number of markers is equal to 1 then + markers are displayed for steps only. If number of markers is equal to 3 + (for example) then markers are displayed for steps and two markers are + displayed between side by side steps. +*/ +int Plot2d_PlotCurve::nbMarkers() const +{ + return myNbMarkers; +} + +/*! + Draws curve's markers +*/ +void Plot2d_PlotCurve::drawSymbols( QPainter *p, const QwtSymbol &symbol, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + int from, int to ) const +{ + p->setBrush( symbol.brush() ); + p->setPen( symbol.pen() ); + + QRect rect; + rect.setSize( QwtPainter::metricsMap().screenToLayout( symbol.size() ) ); + + if ( to > from && testPaintAttribute( PaintFiltered ) ) + { + QwtPlotCurve::drawSymbols( p, symbol, xMap, yMap, from, to ); + } + else + { + for ( int i = from; i <= to; i++ ) + { + const int u = xMap.transform(x(i)); + const int v = yMap.transform(y(i)); + + rect.moveCenter( QPoint( u, v ) ); + symbol.draw( p, rect ); + + // draw markers between current and previous step + if ( myNbMarkers > 1 && i >= 1 ) + { + int u_1 = xMap.transform( x( i - 1 ) ); + int v_1 = yMap.transform( y( i - 1 ) ); + + if ( u_1 == u ) + continue; + + double k = ( (double)( v_1 - v ) ) / ( u_1 - u ); + double b = v - k * u; + double step = ( (double)( u - u_1 ) ) / myNbMarkers; + for ( int ind = 1; ind < myNbMarkers; ind++ ) + { + int X = (int)( u_1 + step * ind ); + int Y = (int)( k * X + b ); + + rect.moveCenter( QPoint( X, Y ) ); + symbol.draw( p, rect ); + } + } + } + } +} + /*! Constructor */ @@ -1796,6 +2073,39 @@ Plot2d_Curve* Plot2d_Plot2d::getClosestCurve( QPoint p, double& distance, int& i return 0; } +/*! + Sets number of markers for steps. If number of markers is equal to 1 then + markers are displayed for steps only. If number of markers is equal to 3 + (for example) then markers are displayed for steps and two markers are + displayed between side by side steps. +*/ +bool Plot2d_Plot2d::setCurveNbMarkers( Plot2d_Curve* curve, const int nb ) +{ + Plot2d_PlotCurve* aPlotCurve = + dynamic_cast( myCurves.key( curve, 0 ) ); + if ( aPlotCurve ) + { + aPlotCurve->setNbMarkers( nb ); + return true; + } + else + return false; +} + + +/*! + Gets number of markers for steps. If number of markers is equal to 1 then + markers are displayed for steps only. If number of markers is equal to 3 + (for example) then markers are displayed for steps and two markers are + displayed between side by side steps. +*/ +int Plot2d_Plot2d::curveNbMarkers( Plot2d_Curve* curve ) const +{ + Plot2d_PlotCurve* aPlotCurve = + dynamic_cast( myCurves.key( curve, 0 ) ); + return aPlotCurve ? aPlotCurve->nbMarkers() : 0; +} + /*! Checks if marker belongs to any enitity */ @@ -2119,3 +2429,87 @@ void Plot2d_ViewFrame::customEvent( QEvent* ce ) if ( ce->type() == FITALL_EVENT ) fitAll(); } + +/*! + Verifies whether plot title must be generated automatically using curves titles +*/ +bool Plot2d_ViewFrame::isTitleChangedByUser( const ObjectType type ) +{ + switch ( type ) + { + case MainTitle: + return myPrefTitleChangedByUser || myTitleChangedByUser; + case XTitle: + return myXPrefTitleChangedByUser || myXTitleChangedByUser; + case YTitle: + return myYPrefTitleChangedByUser || myYTitleChangedByUser; + default: + return false; + } +} + +/*! + Verifies whether plot title must be generated automatically using curves titles +*/ +void Plot2d_ViewFrame::forgetLocalUserChanges( const ObjectType type ) +{ + switch ( type ) + { + case MainTitle: + myTitleChangedByUser = false; + break; + case XTitle: + myXTitleChangedByUser = false; + break; + case YTitle: + myYTitleChangedByUser = false; + break; + default: + break; + } +} + +/*! + Sets flag for automatic updates of titles in accordance with current set of curves + ( updateTitles method). You should call setAutoUpdateTitle( ObjType, false ) + if your application set titles itself and they can not be updated automatically. + By default titles are updated automatically. +*/ + +void Plot2d_ViewFrame::setAutoUpdateTitle( const ObjectType type, const bool upd ) +{ + switch ( type ) + { + case MainTitle: + myTitleAutoUpdate = upd; + break; + case XTitle: + myXTitleAutoUpdate = upd; + break; + case YTitle: + myYTitleAutoUpdate = upd; + break; + default: + break; + } +} + +/*! + Gets flag for automatic updates of titles in accordance with current set of curves + ( updateTitles method) +*/ +bool Plot2d_ViewFrame::getAutoUpdateTitle( const ObjectType type ) const +{ + switch ( type ) + { + case MainTitle: + return myTitleAutoUpdate; + case XTitle: + return myXTitleAutoUpdate; + case YTitle: + return myYTitleAutoUpdate; + default: + return true; + } +} + diff --git a/src/Plot2d/Plot2d_ViewFrame.h b/src/Plot2d/Plot2d_ViewFrame.h index c08c827ae..324220ff2 100755 --- a/src/Plot2d/Plot2d_ViewFrame.h +++ b/src/Plot2d/Plot2d_ViewFrame.h @@ -24,6 +24,7 @@ #include #include #include +#include class Plot2d_Plot2d; class Plot2d_Prs; @@ -107,6 +108,9 @@ public: void setTitle( bool enabled, const QString& title, ObjectType type, bool update = true ); QString getTitle( ObjectType type ) const; + bool isTitleChangedByUser( const ObjectType type ); + void forgetLocalUserChanges( const ObjectType type ); + void setFont( const QFont& font, ObjectType type, bool update = true ); void setHorScaleMode( const int mode, bool update = true ); int getHorScaleMode() const { return myXMode; } @@ -131,6 +135,9 @@ public: void incrementalPan ( const int incrX, const int incrY ); void incrementalZoom( const int incrX, const int incrY ); + void setAutoUpdateTitle( const ObjectType type, const bool upd ); + bool getAutoUpdateTitle( const ObjectType type ) const; + protected: int testOperation( const QMouseEvent& ); void readPreferences(); @@ -148,6 +155,7 @@ public slots: void onViewFitArea(); void onViewGlobalPan(); void onSettings(); + void onCurvesSettings(); void onFitData(); void onChangeBackground(); void onPanLeft(); @@ -169,6 +177,8 @@ signals: void vpCurveChanged(); void contextMenuRequested( QContextMenuEvent *e ); void legendClicked( QwtPlotItem* ); + void curveDisplayed( Plot2d_Curve* ); + void curveErased( Plot2d_Curve* ); protected: Plot2d_Plot2d* myPlot; @@ -189,6 +199,17 @@ protected: int myXMode, myYMode; double myXDistance, myYDistance, myYDistance2; bool mySecondY; + + bool myTitleAutoUpdate, myXTitleAutoUpdate, myYTitleAutoUpdate; + bool myTitleChangedByUser, myXTitleChangedByUser, myYTitleChangedByUser; + + static QString myPrefTitle; + static QString myPrefXTitle; + static QString myPrefYTitle; + + static bool myPrefTitleChangedByUser; + static bool myXPrefTitleChangedByUser; + static bool myYPrefTitleChangedByUser; }; class Plot2d_Plot2d : public QwtPlot @@ -219,6 +240,13 @@ public: CurveDict& getCurves() { return myCurves; } Plot2d_Curve* getClosestCurve( QPoint p, double& distance, int& index ); + long insertCurve( const QString &title, + int xAxis = xBottom, + int yAxis = yLeft ); + + bool setCurveNbMarkers( Plot2d_Curve* curve, const int nb ); + int curveNbMarkers( Plot2d_Curve* curve ) const; + public slots: virtual void polish(); @@ -233,4 +261,30 @@ protected: QwtPlotZoomer* myPlotZoomer; }; +//! The class is derived from QwtPlotCurve. +/*! + The class is derived from QwtPlotCurve. Its main purpose is redefining + drawSymbols virtual method in order to provide possibility to change + number of markers between steps. +*/ + +class Plot2d_PlotCurve : public QwtPlotCurve +{ +public: + Plot2d_PlotCurve( const QString &title ); + virtual ~Plot2d_PlotCurve(); + + void setNbMarkers( const int ); + int nbMarkers() const; + +protected: + + virtual void drawSymbols(QPainter *p, const QwtSymbol &, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + int from, int to) const; + +private: + int myNbMarkers; +}; + #endif diff --git a/src/Plot2d/Plot2d_ViewWindow.cxx b/src/Plot2d/Plot2d_ViewWindow.cxx index 84f551307..cc31f985a 100755 --- a/src/Plot2d/Plot2d_ViewWindow.cxx +++ b/src/Plot2d/Plot2d_ViewWindow.cxx @@ -145,6 +145,7 @@ void Plot2d_ViewWindow::contextMenuPopup( QMenu* thePopup ) // settings thePopup->addAction( mgr->action( CurvSettingsId ) ); + thePopup->addAction( mgr->action( CurvesSettingsId ) ); } /*! @@ -362,6 +363,14 @@ void Plot2d_ViewWindow::createActions() connect( aAction, SIGNAL( triggered( bool ) ), myViewFrame, SLOT( onSettings() ) ); mgr->registerAction( aAction, CurvSettingsId ); + // 8. Curves Settings + aAction = new QtxAction( tr( "TOT_CURVES_SETTINGS"), + aResMgr->loadPixmap("Plot2d", tr("ICON_CURVES_SETTINGS")), + tr("MEN_CURVES_SETTINGS"), 0, this); + aAction->setStatusTip( tr( "PRP_CURVES_SETTINGS") ); + connect( aAction, SIGNAL( activated() ), myViewFrame, SLOT( onCurvesSettings() ) ); + mgr->registerAction( aAction, CurvesSettingsId ); + // 9. Clone aAction = new QtxAction( tr( "MNU_CLONE_VIEW" ), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_CLONE_VIEW" ) ), @@ -401,6 +410,7 @@ void Plot2d_ViewWindow::createToolBar() mgr->append( toolMgr()->separator(), myToolBar ); mgr->append( LegendId, myToolBar ); mgr->append( CurvSettingsId, myToolBar ); + mgr->append( CurvesSettingsId, myToolBar ); mgr->append( CloneId, myToolBar ); } diff --git a/src/Plot2d/Plot2d_ViewWindow.h b/src/Plot2d/Plot2d_ViewWindow.h index 68795cd49..4cdb7c429 100755 --- a/src/Plot2d/Plot2d_ViewWindow.h +++ b/src/Plot2d/Plot2d_ViewWindow.h @@ -27,7 +27,6 @@ #include #include - #ifdef WIN32 #pragma warning( disable:4251 ) #endif @@ -52,7 +51,7 @@ public: PModeYLinearId, PModeYLogarithmicId, CurvPointsId, CurvLinesId, CurvSplinesId, LegendId, - CurvSettingsId, + CurvSettingsId, CurvesSettingsId, CloneId }; public: diff --git a/src/Plot2d/resources/Plot2d_images.ts b/src/Plot2d/resources/Plot2d_images.ts index 9f30f8668..58cf8b952 100644 --- a/src/Plot2d/resources/Plot2d_images.ts +++ b/src/Plot2d/resources/Plot2d_images.ts @@ -65,5 +65,13 @@ ICON_PLOT2D_SHOW_LEGEND plot2d_legend.png + + ICON_CURVES_SETTINGS + plot2d_curves_settings.png + + + ICON_MINUS + plot2d_minus.png + diff --git a/src/Plot2d/resources/Plot2d_msg_en.ts b/src/Plot2d/resources/Plot2d_msg_en.ts index 367bde8d0..dd862f3d8 100644 --- a/src/Plot2d/resources/Plot2d_msg_en.ts +++ b/src/Plot2d/resources/Plot2d_msg_en.ts @@ -423,6 +423,18 @@ Logarithmic scale for ordinate axis is not allowed. MEN_PLOT2D_SETTINGS &Settings + + TOT_CURVES_SETTINGS + Curves settings + + + MEN_CURVES_SETTINGS + Curves settings + + + PRP_CURVES_SETTINGS + Setups curves properties + CIRCLE_MARKER_LBL Circle @@ -502,4 +514,54 @@ Logarithmic scale for ordinate axis is not allowed. Plot2d scene:%M - viewer:%V + + Plot2d_SetupCurvesDlg + + SETUP_CURVES + Setup curves + + + PARAMETERS + Parameters + + + FIG + Fig + + + MARKER + Marker + + + TEXT + Text + + + COLOR + Color + + + NB_MARKERS + Nb markers + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Plot2d/resources/plot2d_curves_settings.png b/src/Plot2d/resources/plot2d_curves_settings.png new file mode 100755 index 000000000..53d4f2c31 Binary files /dev/null and b/src/Plot2d/resources/plot2d_curves_settings.png differ diff --git a/src/Plot2d/resources/plot2d_minus.png b/src/Plot2d/resources/plot2d_minus.png new file mode 100755 index 000000000..055182e1a Binary files /dev/null and b/src/Plot2d/resources/plot2d_minus.png differ diff --git a/src/Qtx/Makefile.am b/src/Qtx/Makefile.am index 1c8b6eac9..6eb89abb4 100755 --- a/src/Qtx/Makefile.am +++ b/src/Qtx/Makefile.am @@ -71,11 +71,10 @@ salomeinclude_HEADERS = \ QtxWorkspace.h \ QtxWorkspaceAction.h \ QtxWorkstack.h \ - QtxWorkstackAction.h - + QtxWorkstackAction.h \ + QtxListBox.h #VSR: not yet migrated to Qt4 files # \ - QtxListBox.h \ QtxTable.h # Libraries targets @@ -127,11 +126,11 @@ dist_libqtx_la_SOURCES = \ QtxWorkspace.cxx \ QtxWorkspaceAction.cxx \ QtxWorkstack.cxx \ - QtxWorkstackAction.cxx + QtxWorkstackAction.cxx \ + QtxListBox.cxx #VSR: not yet migrated to Qt4 files # \ - QtxListBox.cxx \ QtxTable.cxx #VSR: already migrated to Qt4 files @@ -174,11 +173,11 @@ MOC_FILES = \ QtxWorkspace_moc.cxx \ QtxWorkspaceAction_moc.cxx \ QtxWorkstack_moc.cxx \ - QtxWorkstackAction_moc.cxx + QtxWorkstackAction_moc.cxx \ + QtxListBox_moc.cxx #VSR: not yet migrated to Qt4 files # \ - QtxListBox_moc.cxx \ QtxTable_moc.cxx nodist_libqtx_la_SOURCES = $(MOC_FILES) diff --git a/src/Qtx/QtxListBox.cxx b/src/Qtx/QtxListBox.cxx index b4bdef35f..88cc527f8 100755 --- a/src/Qtx/QtxListBox.cxx +++ b/src/Qtx/QtxListBox.cxx @@ -24,19 +24,31 @@ #include #include +#ifdef WIN32 +#pragma warning ( disable: 4251 ) +#endif + +#include +#include + /*! Constructor */ -QtxListBox::QtxListBox( QWidget* parent, const char* name, WFlags f ) -: QListBox( parent, name, f ), +QtxListBox::QtxListBox( QWidget* parent ) +: QListWidget( parent ), myEditor( 0 ), myEditIndex( -1 ), myEditState( false ), myEditDefault( true ), myModifEnabled( true ) { - connect( this, SIGNAL( contentsMoving( int, int ) ), - this, SLOT( onContentsMoving( int, int ) ) ); + QScrollBar* hsb = horizontalScrollBar(); + if ( hsb ) + connect( hsb, SIGNAL( valueChanged( int ) ), SLOT( onContentsMoving() ) ); + + QScrollBar* vsb = horizontalScrollBar(); + if ( vsb ) + connect( vsb, SIGNAL( valueChanged( int ) ), SLOT( onContentsMoving() ) ); } /*! @@ -112,7 +124,7 @@ void QtxListBox::setModificationEnabled( bool on ) /*! \return current edited item */ -QListBoxItem* QtxListBox::editedItem() const +QListWidgetItem* QtxListBox::editedItem() const { return item( editedIndex() ); } @@ -144,7 +156,7 @@ void QtxListBox::startEdition( const int idx ) ensureItemVisible( myEditIndex ); - ed->setText( text( myEditIndex ) ); + ed->setText( item( myEditIndex )->text() ); updateEditor(); ed->show(); @@ -155,9 +167,9 @@ void QtxListBox::startEdition( const int idx ) Starts edition of item \param item - item to be edited */ -void QtxListBox::startEdition( const QListBoxItem* item ) +void QtxListBox::startEdition( const QListWidgetItem* item ) { - startEdition( index( item ) ); + startEdition( row( item ) ); } /*! @@ -178,14 +190,17 @@ void QtxListBox::endEdition( const bool action ) if ( action ) { - int cur = currentItem(); + int cur = currentRow(); + /*qt4 if ( pixmap( idx ) ) changeItem( *pixmap( idx ), ed->text(), idx ); else changeItem( ed->text(), idx ); + */ + item( idx )->setText( ed->text() ); - setCurrentItem( cur ); + setCurrentRow( cur ); emit itemEdited( idx ); emit itemEdited( item( idx ) ); @@ -201,19 +216,19 @@ void QtxListBox::ensureItemVisible( const int idx ) if ( idx < 0 ) return; - if ( itemVisible( idx ) ) - return; + //qt4 if ( itemVisible( idx ) ) + //qt4 return; - setTopItem( idx ); + //qt4 setTopItem( idx ); } /*! Ensures that the item is visible. \param item - item to be made visible */ -void QtxListBox::ensureItemVisible( const QListBoxItem* item ) +void QtxListBox::ensureItemVisible( const QListWidgetItem* item ) { - ensureItemVisible( index( item ) ); + ensureItemVisible( row( item ) ); } /*! @@ -233,7 +248,7 @@ const QValidator* QtxListBox::validator() const void QtxListBox::clearValidator() { if ( editor() ) - editor()->clearValidator(); + editor()->setValidator( 0 ); } /*! @@ -271,18 +286,18 @@ void QtxListBox::moveItemToBottom( const int idx ) */ void QtxListBox::moveItem( const int idx, const int step ) { - QListBoxItem* i = item( idx ); + QListWidgetItem* i = item( idx ); if ( !i || step == 0 ) return; - QListBoxItem* cur = item( currentItem() ); + QListWidgetItem* cur = currentItem(); - takeItem( i ); - insertItem( i, QMAX( 0, idx + step ) ); + takeItem( idx ); + insertItem( qMax( 0, idx + step ), i ); - setCurrentItem( index( cur ) ); + setCurrentItem( cur ); - int pos = index( i ); + int pos = row( i ); if ( myEditIndex == idx ) myEditIndex = pos; @@ -301,12 +316,12 @@ void QtxListBox::createItem( const int i ) if ( !isEditEnabled() ) return; - int idx = i < 0 ? currentItem() : i; + int idx = i < 0 ? currentRow() : i; idx = idx < 0 ? count() : idx; - idx = QMIN( (int)count(), idx ); + idx = qMin( (int)count(), idx ); - insertItem( "", idx ); - setCurrentItem( idx ); + insertItem( idx, "" ); + setCurrentRow( idx ); startEdition( idx ); } @@ -319,14 +334,14 @@ void QtxListBox::deleteItem( const int i ) if ( !isEditEnabled() ) return; - int idx = i < 0 ? currentItem() : i; + int idx = i < 0 ? currentRow() : i; if ( idx < 0 ) return; if ( editedIndex() == idx ) endEdition( defaultEditAction() ); - removeItem( idx ); + takeItem( idx ); updateEditor(); } @@ -336,7 +351,7 @@ void QtxListBox::deleteItem( const int i ) */ void QtxListBox::setContentsPos( int x, int y ) { - QListBox::setContentsPos( x, y ); + //qt4 QListWidget::setContentsPos( x, y ); updateEditor(); } @@ -354,14 +369,14 @@ bool QtxListBox::eventFilter( QObject* o, QEvent* e ) if ( e->type() == QEvent::KeyPress ) { QKeyEvent* ke = (QKeyEvent*)e; - if ( ke->key() == Key_Escape ) + if ( ke->key() == Qt::Key_Escape ) endEdition( false ); - else if ( ke->key() == Key_Enter || ke->key() == Key_Return ) + else if ( ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return ) endEdition( true ); } } - return QListBox::eventFilter( o, e ); + return QListWidget::eventFilter( o, e ); } /*! @@ -370,28 +385,28 @@ bool QtxListBox::eventFilter( QObject* o, QEvent* e ) */ void QtxListBox::keyPressEvent( QKeyEvent* e ) { - if ( e->key() == Key_Up && e->state() & ControlButton && isModificationEnabled() ) - moveItem( currentItem(), -1 ); - else if ( e->key() == Key_Down && e->state() & ControlButton && isModificationEnabled() ) - moveItem( currentItem(), 1 ); - else if ( e->key() == Key_Home && e->state() & ControlButton && isModificationEnabled() ) - moveItemToTop( currentItem() ); - else if ( e->key() == Key_End && e->state() & ControlButton && isModificationEnabled() ) - moveItemToBottom( currentItem() ); - else if ( e->key() == Key_Insert && e->state() & ControlButton ) - createItem( currentItem() ); - else if ( e->key() == Key_Delete && e->state() & ControlButton ) - deleteItem( currentItem() ); + if ( e->key() == Qt::Key_Up && e->modifiers() & Qt::ControlModifier && isModificationEnabled() ) + moveItem( currentRow(), -1 ); + else if ( e->key() == Qt::Key_Down && e->modifiers() & Qt::ControlModifier && isModificationEnabled() ) + moveItem( currentRow(), 1 ); + else if ( e->key() == Qt::Key_Home && e->modifiers() & Qt::ControlModifier && isModificationEnabled() ) + moveItemToTop( currentRow() ); + else if ( e->key() == Qt::Key_End && e->modifiers() & Qt::ControlModifier && isModificationEnabled() ) + moveItemToBottom( currentRow() ); + else if ( e->key() == Qt::Key_Insert && e->modifiers() & Qt::ControlModifier ) + createItem( currentRow() ); + else if ( e->key() == Qt::Key_Delete && e->modifiers() & Qt::ControlModifier ) + deleteItem( currentRow() ); else - QListBox::keyPressEvent( e ); + QListWidget::keyPressEvent( e ); } /*! Custom resize event handler */ -void QtxListBox::viewportResizeEvent( QResizeEvent* e ) +void QtxListBox::resizeEvent( QResizeEvent* e ) { - QListBox::viewportResizeEvent( e ); + QListWidget::resizeEvent( e ); updateEditor(); } @@ -404,13 +419,13 @@ void QtxListBox::mouseDoubleClickEvent( QMouseEvent* e ) if ( isEditEnabled() ) startEdition( itemAt( e->pos() ) ); else - QListBox::mouseDoubleClickEvent( e ); + QListWidget::mouseDoubleClickEvent( e ); } /*! Updates editor on contents moving */ -void QtxListBox::onContentsMoving( int, int ) +void QtxListBox::onContentsMoving() { updateEditor(); } @@ -437,15 +452,16 @@ void QtxListBox::createEditor() return; myEditor = new QLineEdit( viewport() ); + myEditor->setBackgroundRole( QPalette::Window ); - myEditor->setLineWidth( 1 ); - myEditor->setMidLineWidth( 0 ); - myEditor->setFrameStyle( QFrame::Box | QFrame::Plain ); + //qt4 myEditor->setLineWidth( 1 ); + //qt4 myEditor->setMidLineWidth( 0 ); + //qt4 myEditor->setFrameStyle( QFrame::Box | QFrame::Plain ); myEditor->installEventFilter( this ); myEditor->hide(); - addChild( myEditor ); + //qt4 addChild( myEditor ); } /*! @@ -456,16 +472,23 @@ void QtxListBox::updateEditor() if ( !editedItem() || !editor() ) return; - QRect r = itemRect( editedItem() ); + QRect r = visualItemRect( editedItem() ); if ( !r.isValid() ) return; - int m = editor()->lineWidth(); - r.addCoords( m, 0, 0, 0 ); - - const QPixmap* pix = pixmap( editedIndex() ); - if ( pix ) - r.addCoords( pix->width() + 2, 0, 0, 0 ); + //int m = /*editor()->lineWidth()*/ 1; + r.setLeft( r.left() + 1 ); + + QListWidgetItem* it = item( editedIndex() ); + if ( it ) + { + const QIcon pix = it->icon(); + if ( !pix.isNull() ) + { + QSize s = pix.actualSize( QSize( 100, 100 ) ); + r.setLeft( s.width() + 2 ); + } + } editor()->setGeometry( r ); } diff --git a/src/Qtx/QtxListBox.h b/src/Qtx/QtxListBox.h index e2e9076b4..8cb06c064 100755 --- a/src/Qtx/QtxListBox.h +++ b/src/Qtx/QtxListBox.h @@ -42,7 +42,7 @@ class QTX_EXPORT QtxListBox : public QListWidget//QListBox // This file isn't ye Q_OBJECT public: - QtxListBox( QWidget* = 0, const char* = 0, Qt::WindowFlags = 0 ); + QtxListBox( QWidget* = 0 ); virtual ~QtxListBox(); bool isEditEnabled() const; @@ -85,13 +85,13 @@ public slots: virtual void setContentsPos( int, int ); private slots: - void onContentsMoving( int, int ); + void onContentsMoving(); protected: virtual void keyPressEvent( QKeyEvent* ); - virtual void viewportResizeEvent( QResizeEvent* ); + virtual void resizeEvent( QResizeEvent* ); //qt4 viewportResizeEvent virtual void mouseDoubleClickEvent( QMouseEvent* ); - + private: QLineEdit* editor() const; void createEditor(); diff --git a/src/Qtx/QtxWorkstack.cxx b/src/Qtx/QtxWorkstack.cxx index a4bde05a2..4f6d31a89 100644 --- a/src/Qtx/QtxWorkstack.cxx +++ b/src/Qtx/QtxWorkstack.cxx @@ -514,6 +514,8 @@ void QtxWorkstackArea::removeWidget( QWidget* wid, const bool del ) if ( !myList.contains( wid ) ) return; + bool wasActive = wid == workstack()->activeWindow(); + if ( myBar->indexOf( widgetId( wid ) ) != -1 ) myBar->removeTab( myBar->indexOf( widgetId( wid ) ) ); @@ -524,12 +526,19 @@ void QtxWorkstackArea::removeWidget( QWidget* wid, const bool del ) myChild.remove( wid ); if ( del ) + { delete child( wid ); + if ( myList.isEmpty() ) + wasActive = false; + } if ( isNull() ) deleteLater(); else updateState(); + + if ( wasActive ) + emit activated( activeWidget() ); } /*! @@ -1173,7 +1182,8 @@ QtxWorkstackChild::~QtxWorkstackChild() if ( !widget() ) return; - disconnect( widget(), SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) ); + if( widget() ) + disconnect( widget(), SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) ); widget()->hide(); widget()->removeEventFilter( this ); @@ -1281,6 +1291,7 @@ void QtxWorkstackChild::childEvent( QChildEvent* e ) */ QtxWorkstackTabBar::QtxWorkstackTabBar( QWidget* parent ) : QTabBar( parent ), + myActive( false ), myId( -1 ) { setDrawBase( true ); diff --git a/src/STD/STD_Application.cxx b/src/STD/STD_Application.cxx index 9f8d9fb4f..d16cca864 100755 --- a/src/STD/STD_Application.cxx +++ b/src/STD/STD_Application.cxx @@ -97,8 +97,6 @@ void STD_Application::start() */ void STD_Application::closeApplication() { - if ( desktop() ) - savePreferences(); SUIT_Study* study = activeStudy(); if ( study ) @@ -113,6 +111,9 @@ void STD_Application::closeApplication() afterCloseDoc(); } + if ( desktop() ) + savePreferences(); + setDesktop( 0 ); SUIT_Application::closeApplication(); @@ -534,7 +535,7 @@ bool STD_Application::onSaveAsDoc() putInfo( tr( "INF_DOC_SAVING" ) + aName ); isOk = study->saveDocumentAs( aName ); - putInfo( isOk ? tr( "INF_DOC_SAVED" ).arg( aName ) : "" ); + putInfo( isOk ? tr( "INF_DOC_SAVED" ).arg( aName ) : QString( "" ) ); QApplication::restoreOverrideCursor(); diff --git a/src/SUIT/SUIT_DataBrowser.cxx b/src/SUIT/SUIT_DataBrowser.cxx index e9ee49087..aa099cb90 100644 --- a/src/SUIT/SUIT_DataBrowser.cxx +++ b/src/SUIT/SUIT_DataBrowser.cxx @@ -295,6 +295,20 @@ void SUIT_DataBrowser::setResizeOnExpandItem( const bool on ) myResizeOnExpandItem = on; } +/*! + Ensures that object obj is visible, scrolling the list view vertically + if necessary and opening (expanding) any parent items if this is required to show the item. +*/ +void SUIT_DataBrowser::ensureItemVisible( const SUIT_DataObject* obj ) +{ + SUIT_ProxyModel* m = qobject_cast( model() ); + if ( m ) { + QModelIndex index = m->index( obj ); + if( index.isValid() ) + treeView()->scrollTo( index ); + } +} + /*! \brief Initialize object browser. \param root root data object diff --git a/src/SUIT/SUIT_DataBrowser.h b/src/SUIT/SUIT_DataBrowser.h index 77d423f1d..d9d0e4caf 100644 --- a/src/SUIT/SUIT_DataBrowser.h +++ b/src/SUIT/SUIT_DataBrowser.h @@ -64,6 +64,8 @@ public: void setAutoSizeColumns( const bool on ); void setResizeOnExpandItem( const bool on ); + void ensureItemVisible( const SUIT_DataObject* ); + protected: virtual void contextMenuEvent( QContextMenuEvent* ); diff --git a/src/SUIT/SUIT_FileDlg.cxx b/src/SUIT/SUIT_FileDlg.cxx index 7572fba75..1c69220d6 100755 --- a/src/SUIT/SUIT_FileDlg.cxx +++ b/src/SUIT/SUIT_FileDlg.cxx @@ -511,6 +511,12 @@ QString SUIT_FileDlg::addExtension( const QString& fileName ) const // now we get the list of all extension masks and remove all which does not contain wildcard symbols QStringList extList = aPattern.split( "|", QString::SkipEmptyParts ); + + // This protection is added for GUITHARE application, (*.FORT21 fort21) filter. + // When user selects “fort21” file name then extension should not be added + if ( extList.contains( QFileInfo( fname ).baseName() ) ) + return fileName; + for ( int i = extList.count() - 1; i >= 0; i-- ) { if ( !extList[i].contains( "." ) ) extList.removeAt( i ); diff --git a/src/SUIT/SUIT_FileDlg.h b/src/SUIT/SUIT_FileDlg.h index 76309c67a..746d63e77 100755 --- a/src/SUIT/SUIT_FileDlg.h +++ b/src/SUIT/SUIT_FileDlg.h @@ -98,7 +98,7 @@ protected: virtual bool event( QEvent* ); QLineEdit* lineEdit() const; virtual bool acceptData(); - QString addExtension( const QString& ) const; + virtual QString addExtension( const QString& ) const; bool processPath( const QString& ); void addFilter( const QString& ); static bool hasWildCards( const QString& ); diff --git a/src/SUIT/SUIT_OverrideCursor.h b/src/SUIT/SUIT_OverrideCursor.h index 90e9dc7c4..37c26f6df 100755 --- a/src/SUIT/SUIT_OverrideCursor.h +++ b/src/SUIT/SUIT_OverrideCursor.h @@ -24,6 +24,10 @@ #include #include +#ifdef WIN32 +#pragma warning( disable:4251 ) +#endif + /*! \brief Class used for management cursors.*/ class SUIT_EXPORT SUIT_OverrideCursor { diff --git a/src/SUIT/SUIT_SelectionMgr.cxx b/src/SUIT/SUIT_SelectionMgr.cxx index a3f8a8e81..d3729f026 100755 --- a/src/SUIT/SUIT_SelectionMgr.cxx +++ b/src/SUIT/SUIT_SelectionMgr.cxx @@ -25,12 +25,13 @@ * Provide selection manager. Manipulate by selection filters, modes, data owners. */ -/*!constructor. initialize myIterations and myIsSelChangeEnabled.*/ +/*!constructor. initialize myIterations, myIsSelChangeEnabled and myIsSynchronizationEnabled.*/ SUIT_SelectionMgr::SUIT_SelectionMgr( const bool Feedback, QObject* p ) : QObject( p ), myIterations( Feedback ? 1 : 0 ), myAutoDelFilter( false ), -myIsSelChangeEnabled( true ) +myIsSelChangeEnabled( true ), +myIsSynchronizationEnabled( true ) { } @@ -144,17 +145,25 @@ void SUIT_SelectionMgr::selectionChanged( SUIT_Selector* sel ) SUIT_DataOwnerPtrList newOwners; filterOwners( owners, newOwners ); - for ( int i = 0; i < myIterations; i++ ) + if ( myIsSynchronizationEnabled ) { - for ( SelectorList::iterator it = mySelectors.begin(); it != mySelectors.end(); ++it ) + for ( int i = 0; i < myIterations; i++ ) { - // Temporary action(to avoid selection of the objects which don't pass the filters): - //if ( *it != sel ) - (*it)->setSelected( newOwners ); + for ( SelectorList::iterator it = mySelectors.begin(); it != mySelectors.end(); ++it ) + { + // Temporary action(to avoid selection of the objects which don't pass the filters): + //if ( *it != sel ) + (*it)->setSelected( newOwners ); + } } } + else + sel->setSelected( newOwners ); + myIsSelChangeEnabled = true; + myLastSelectionSource = sel->type(); + emit selectionChanged(); } @@ -345,3 +354,24 @@ void SUIT_SelectionMgr::filterOwners( const SUIT_DataOwnerPtrList& in, SUIT_Data out.append( *it ); } } + +/*! Gets type of last selector where selection has been changed. +*/ +QString SUIT_SelectionMgr::lastSelectionSource() const +{ + return myLastSelectionSource; +} + +/*! Verifies whether synchronization between selectors is enabled. +*/ +bool SUIT_SelectionMgr::isSynchronizationEnabled() const +{ + return myIsSynchronizationEnabled; +} + +/*! Enable or disable synchronization between selectors. +*/ +void SUIT_SelectionMgr::setSynchronizationEnabled( const bool on ) +{ + myIsSynchronizationEnabled = on; +} diff --git a/src/SUIT/SUIT_SelectionMgr.h b/src/SUIT/SUIT_SelectionMgr.h index ec2ecb9fa..8bef8ff5e 100755 --- a/src/SUIT/SUIT_SelectionMgr.h +++ b/src/SUIT/SUIT_SelectionMgr.h @@ -77,6 +77,10 @@ public: bool isSynchronizing() const; + QString lastSelectionSource() const; + bool isSynchronizationEnabled() const; + void setSynchronizationEnabled( const bool ); + signals: void selectionChanged(); @@ -99,6 +103,8 @@ private: int myIterations; bool myAutoDelFilter; bool myIsSelChangeEnabled; + bool myIsSynchronizationEnabled; + QString myLastSelectionSource; friend class SUIT_Selector; }; diff --git a/src/SUIT/SUIT_ViewManager.cxx b/src/SUIT/SUIT_ViewManager.cxx index ed32ea6f2..761bcab15 100755 --- a/src/SUIT/SUIT_ViewManager.cxx +++ b/src/SUIT/SUIT_ViewManager.cxx @@ -347,7 +347,7 @@ void SUIT_ViewManager::closeAllViews() */ QString SUIT_ViewManager::getType() const { - return (!myViewModel)? "": myViewModel->getType(); + return (!myViewModel)? QString( "" ): myViewModel->getType(); } /*! diff --git a/src/SVTK/SALOME_Actor.cxx b/src/SVTK/SALOME_Actor.cxx index 83305d7e5..4314d7c22 100644 --- a/src/SVTK/SALOME_Actor.cxx +++ b/src/SVTK/SALOME_Actor.cxx @@ -59,6 +59,7 @@ #include #include #include +#include #include #include @@ -122,6 +123,13 @@ namespace } +bool IsThisActorPicked(SALOME_Actor *theActor, vtkActor *anAct) { + if( anAct == theActor ) return true; + if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( anAct ) ) + return ( anActor->hasIO() && theActor->hasIO() && + theActor->getIO()->isSame( anActor->getIO() ) ); + return false; +} vtkStandardNewMacro(SALOME_Actor); @@ -448,7 +456,8 @@ SALOME_Actor myPointPicker->Pick( x, y, z, aRenderer ); int aVtkId = myPointPicker->GetPointId(); - if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) ) { + if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) + && IsThisActorPicked(this, myPointPicker->GetActor())) { // RKV int anObjId = GetNodeObjId( aVtkId ); myIsPreselected = (anObjId >= 0); if(myIsPreselected){ @@ -475,7 +484,8 @@ SALOME_Actor myCellPicker->Pick( x, y, z, aRenderer ); int aVtkId = myCellPicker->GetCellId(); - if ( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) && hasIO() ) { + if ( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) && hasIO() + && IsThisActorPicked(this, myCellPicker->GetActor())) { // RKV int anObjId = GetElemObjId (aVtkId ); if ( anObjId >= 0 ) { myIsPreselected = CheckDimensionId(aSelectionMode,this,anObjId); @@ -501,7 +511,8 @@ SALOME_Actor myCellPicker->Pick( x, y, z, aRenderer ); int aVtkId = myCellPicker->GetCellId(); - if ( aVtkId >= 0 && mySelector->IsValid( this, aVtkId )) { + if ( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) + && IsThisActorPicked(this, myCellPicker->GetActor())) { // RKV int anObjId = GetElemObjId( aVtkId ); if ( anObjId >= 0 ) { int anEdgeId = GetEdgeId(this,myCellPicker.GetPointer(),anObjId); @@ -587,7 +598,8 @@ SALOME_Actor myPointPicker->Pick( x, y, z, aRenderer ); int aVtkId = myPointPicker->GetPointId(); - if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) ) { + if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) + && IsThisActorPicked(this, myPointPicker->GetActor())) { // RKV int anObjId = GetNodeObjId( aVtkId ); if( anObjId >= 0 ) { mySelector->AddOrRemoveIndex( myIO, anObjId, anIsShift ); @@ -604,7 +616,8 @@ SALOME_Actor myCellPicker->Pick( x, y, z, aRenderer ); int aVtkId = myCellPicker->GetCellId(); - if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) ) { + if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) + && IsThisActorPicked(this, myCellPicker->GetActor())) { // RKV int anObjId = GetElemObjId( aVtkId ); if( anObjId >= 0 ) { if ( CheckDimensionId(aSelectionMode,this,anObjId) ) { @@ -620,7 +633,8 @@ SALOME_Actor myCellPicker->Pick( x, y, z, aRenderer ); int aVtkId = myCellPicker->GetCellId(); - if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) ) { + if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) + && IsThisActorPicked(this, myCellPicker->GetActor())) { // RKV int anObjId = GetElemObjId( aVtkId ); if( anObjId >= 0 ) { int anEdgeId = GetEdgeId(this,myCellPicker.GetPointer(),anObjId); @@ -671,7 +685,8 @@ SALOME_Actor vtkIdType anEnd = aVectorIds.size(); for(vtkIdType anId = 0; anId < anEnd; anId++ ) { int aPointId = aVectorIds[anId]; - if( aPointId >= 0 && mySelector->IsValid( this, aPointId, true ) ) { + if( aPointId >= 0 && mySelector->IsValid( this, aPointId, true ) + && IsThisActorPicked(this, myPointRectPicker->GetActor())) { // RKV int anObjId = GetNodeObjId( aPointId ); anIndexes.Add( anObjId ); } @@ -731,7 +746,8 @@ SALOME_Actor vtkIdType anEnd = aVectorIds.size(); for(vtkIdType anId = 0; anId < anEnd; anId++ ) { int aCellId = aVectorIds[anId]; - if ( !mySelector->IsValid( this, aCellId ) ) + if ( !mySelector->IsValid( this, aCellId ) + && !IsThisActorPicked(this, myCellRectPicker->GetActor())) // RKV continue; int anObjId = GetElemObjId( aCellId ); @@ -817,3 +833,17 @@ SALOME_Actor { myHighlightActor->SetProperty(theProperty); } + + +void +SALOME_Actor +::MapCells(const TColStd_IndexedMapOfInteger& theMapIndex, + vtkUnstructuredGrid* theUG) +{ + int aNbOfParts = theMapIndex.Extent(); + for(int ind = 1; ind <= aNbOfParts; ind++){ + int aPartId = theMapIndex( ind ); + if(vtkCell* aCell = GetElemCell(aPartId)) + theUG->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds()); + } +} diff --git a/src/SVTK/SALOME_Actor.h b/src/SVTK/SALOME_Actor.h index 4316ef3dc..ee81079b5 100644 --- a/src/SVTK/SALOME_Actor.h +++ b/src/SVTK/SALOME_Actor.h @@ -49,6 +49,7 @@ class vtkCellPicker; class vtkOutlineSource; class vtkInteractorStyle; class vtkRenderWindowInteractor; +class vtkUnstructuredGrid; class SVTK_Actor; class SVTK_RectPicker; @@ -202,6 +203,9 @@ class SVTK_EXPORT SALOME_Actor : public VTKViewer_Actor void SetHighlightProperty(vtkProperty* theProperty); + virtual void MapCells(const TColStd_IndexedMapOfInteger& theMapIndex, + vtkUnstructuredGrid* theUG); + protected: //---------------------------------------------------------------------------- vtkRenderWindowInteractor* myInteractor; diff --git a/src/SVTK/SVTK_Actor.cxx b/src/SVTK/SVTK_Actor.cxx index 8ccb82a8b..11bfa36c0 100644 --- a/src/SVTK/SVTK_Actor.cxx +++ b/src/SVTK/SVTK_Actor.cxx @@ -118,12 +118,7 @@ SVTK_Actor vtkDataSet *aSourceDataSet = theMapActor->GetInput(); CopyPoints(GetSource(),aSourceDataSet); - int aNbOfParts = theMapIndex.Extent(); - for(int ind = 1; ind <= aNbOfParts; ind++){ - int aPartId = theMapIndex( ind ); - if(vtkCell* aCell = theMapActor->GetElemCell(aPartId)) - myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds()); - } + theMapActor->MapCells(theMapIndex,myUnstructuredGrid.GetPointer()); UnShrink(); if(theMapActor->IsShrunk()){ diff --git a/src/SVTK/SVTK_CubeAxesActor2D.cxx b/src/SVTK/SVTK_CubeAxesActor2D.cxx index 4f109801c..f8e65b9b9 100644 --- a/src/SVTK/SVTK_CubeAxesActor2D.cxx +++ b/src/SVTK/SVTK_CubeAxesActor2D.cxx @@ -202,11 +202,12 @@ static void ChangeValues(vtkFloatingPointType* aArray1, { vtkFloatingPointType tmp=-1000; if (!theY){ - for (int i=0; i<4; i++){ + int i=0; + for (; i<4; i++){ tmp = aArray1[i]; aArray1[i] = aArray2[i]; aArray2[i] = tmp; } #ifndef WIN32 - for(int i=0;i<2; i++){ + for(i=0;i<2; i++){ #else for(i=0;i<2; i++){ #endif diff --git a/src/SVTK/SVTK_DeviceActor.cxx b/src/SVTK/SVTK_DeviceActor.cxx index e025131f3..eda9aae53 100644 --- a/src/SVTK/SVTK_DeviceActor.cxx +++ b/src/SVTK/SVTK_DeviceActor.cxx @@ -170,7 +170,7 @@ SVTK_DeviceActor ::SetInput(vtkDataSet* theDataSet) { myMapper->SetInput(theDataSet); - InitPipeLine(myMapper); + SetMapper(myMapper); } /*! diff --git a/src/SVTK/SVTK_InteractorStyle.cxx b/src/SVTK/SVTK_InteractorStyle.cxx index 0ec193589..937c0129f 100644 --- a/src/SVTK/SVTK_InteractorStyle.cxx +++ b/src/SVTK/SVTK_InteractorStyle.cxx @@ -186,6 +186,7 @@ SVTK_SelectionEvent* SVTK_InteractorStyle::GetSelectionEventFlipY() mySelectionEvent->myIsCtrl = Interactor->GetControlKey(); mySelectionEvent->myIsShift = Interactor->GetShiftKey(); + mySelectionEvent->myKeyCode = Interactor->GetKeyCode(); mySelectionEvent->myLastX = mySelectionEvent->myX; mySelectionEvent->myLastY = mySelectionEvent->myY; diff --git a/src/SVTK/SVTK_RectPicker.cxx b/src/SVTK/SVTK_RectPicker.cxx index 8d6cfe07b..79923503e 100644 --- a/src/SVTK/SVTK_RectPicker.cxx +++ b/src/SVTK/SVTK_RectPicker.cxx @@ -91,13 +91,21 @@ namespace //---------------------------------------------------------------------------- +/* RKV void + SelectVisiblePoints(int theSelection[4], + vtkRenderer *theRenderer, + vtkDataSet *theInput, + SVTK_RectPicker::TVectorIds& theVisibleIds, + SVTK_RectPicker::TVectorIds& theInVisibleIds, + vtkFloatingPointType theTolerance) */ void SelectVisiblePoints(int theSelection[4], vtkRenderer *theRenderer, vtkDataSet *theInput, SVTK_RectPicker::TVectorIds& theVisibleIds, SVTK_RectPicker::TVectorIds& theInVisibleIds, - vtkFloatingPointType theTolerance) + vtkFloatingPointType theTolerance, + bool isThrough) // RKV { theVisibleIds.clear(); theInVisibleIds.clear(); @@ -119,8 +127,14 @@ namespace GetCompositePerspectiveTransformMatrix( theRenderer->GetTiledAspectRatio(), 0, 1 ) ); // We grab the z-buffer for the selection region all at once and probe the resulting array. - float *aZPtr = theRenderer->GetRenderWindow()-> - GetZbufferData(theSelection[0], theSelection[1], theSelection[2], theSelection[3]); +// RKV float *aZPtr = theRenderer->GetRenderWindow()-> +// RKV GetZbufferData(theSelection[0], theSelection[1], theSelection[2], theSelection[3]); + // RKV : Begin + float *aZPtr = 0; + if (!isThrough) // Use Z-Buffer if only visible points should be taken + aZPtr = theRenderer->GetRenderWindow()-> + GetZbufferData(theSelection[0], theSelection[1], theSelection[2], theSelection[3]); + // RKV : End //cout<<"theSelection = {"<= theSelection[1] && aDX[1] <= theSelection[3]) { //cout<<"aPntId "< 0) goto ADD_VISIBLE; if(aRet < 0) goto ADD_INVISIBLE; - static int aMaxRadius = 5; - for(int aRadius = 1; aRadius < aMaxRadius; aRadius++){ + for(aRadius = 1; aRadius < aMaxRadius; aRadius++){ int aStartDX[2] = {aDX0 - aRadius, aDX1 - aRadius}; for(int i = 0; i <= aRadius; i++){ int aRet = Check(aZPtr,theSelection,theTolerance,aDX[2],aStartDX[0]++,aStartDX[1]); @@ -231,7 +252,8 @@ namespace vtkRenderer *theRenderer, vtkDataSet *theInput, SVTK_RectPicker::TVectorIds& theVectorIds, - vtkFloatingPointType theTolerance) +// RKV vtkFloatingPointType theTolerance) + vtkFloatingPointType theTolerance, bool isThrough) // RKV { theVectorIds.clear(); @@ -248,7 +270,8 @@ namespace theInput, aVisiblePntIds, anInVisiblePntIds, - theTolerance); +// RKV theTolerance); + theTolerance, isThrough); // RKV typedef std::set TIdsSet; TIdsSet aVisibleIds(aVisiblePntIds.begin(),aVisiblePntIds.end()); @@ -337,6 +360,7 @@ SVTK_RectPicker { this->Tolerance = 0.005; this->PickPoints = 1; + this->myIsThrough = false; // RKV : The old behaviour by default } SVTK_RectPicker @@ -457,7 +481,8 @@ SVTK_RectPicker aMapper->GetInput(), aVisibleIds, anInVisibleIds, - this->Tolerance); +// RKV this->Tolerance); + this->Tolerance, IsThrough()); // RKV if ( aVisibleIds.empty() ) { myPointIdsMap.erase(myPointIdsMap.find(anActor)); } @@ -467,7 +492,8 @@ SVTK_RectPicker theRenderer, aMapper->GetInput(), aVectorIds, - this->Tolerance); +// RKV this->Tolerance); + this->Tolerance, IsThrough()); // RKV if ( aVectorIds.empty() ) { myCellIdsMap.erase(myCellIdsMap.find(anActor)); } diff --git a/src/SVTK/SVTK_RectPicker.h b/src/SVTK/SVTK_RectPicker.h index 3a6576edb..59e152eab 100644 --- a/src/SVTK/SVTK_RectPicker.h +++ b/src/SVTK/SVTK_RectPicker.h @@ -93,6 +93,9 @@ class SVTK_EXPORT SVTK_RectPicker : public vtkAbstractPropPicker const TVectorIdsMap& GetCellIdsMap() const; + bool IsThrough() { return myIsThrough;} // RKV + void SetIsThrough(bool val) { myIsThrough = val;} // RKV + protected: SVTK_RectPicker(); ~SVTK_RectPicker(); @@ -112,6 +115,9 @@ class SVTK_EXPORT SVTK_RectPicker : public vtkAbstractPropPicker TVectorIdsMap myPointIdsMap; TVectorIdsMap myCellIdsMap; + bool myIsThrough; // RKV : Will the picker take all elements throuth selected + // volume inclung invizible elements + private: virtual int diff --git a/src/SVTK/SVTK_RenderWindowInteractor.cxx b/src/SVTK/SVTK_RenderWindowInteractor.cxx index 66287bf79..6f96493b5 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.cxx +++ b/src/SVTK/SVTK_RenderWindowInteractor.cxx @@ -245,10 +245,15 @@ void QVTK_RenderWindowInteractor ::mouseMoveEvent( QMouseEvent* event ) { + int keyCode = 0; + if ( event->modifiers() & Qt::AltModifier ) + keyCode = Qt::Key_Alt; + GetDevice()->SetEventInformationFlipY(event->x(), event->y(), event->modifiers() & Qt::ControlModifier, - event->modifiers() & Qt::ShiftModifier); + event->modifiers() & Qt::ShiftModifier, + keyCode); GetDevice()->MouseMoveEvent(); } @@ -260,10 +265,15 @@ void QVTK_RenderWindowInteractor ::mousePressEvent( QMouseEvent* event ) { + int keyCode = 0; + if ( event->modifiers() & Qt::AltModifier ) + keyCode = Qt::Key_Alt; + GetDevice()->SetEventInformationFlipY(event->x(), event->y(), event->modifiers() & Qt::ControlModifier, - event->modifiers() & Qt::ShiftModifier); + event->modifiers() & Qt::ShiftModifier, + keyCode); if( event->button() & Qt::LeftButton ) GetDevice()->LeftButtonPressEvent(); else if( event->button() & Qt::MidButton ) @@ -280,10 +290,15 @@ void QVTK_RenderWindowInteractor ::mouseReleaseEvent( QMouseEvent *event ) { + int keyCode = 0; + if ( event->modifiers() & Qt::AltModifier ) + keyCode = Qt::Key_Alt; + GetDevice()->SetEventInformationFlipY(event->x(), event->y(), event->modifiers() & Qt::ControlModifier, - event->modifiers() & Qt::ShiftModifier); + event->modifiers() & Qt::ShiftModifier, + keyCode); if( event->button() & Qt::LeftButton ) GetDevice()->LeftButtonReleaseEvent(); diff --git a/src/SVTK/SVTK_Selector.h b/src/SVTK/SVTK_Selector.h index 0d65de7e3..3cb1bed65 100644 --- a/src/SVTK/SVTK_Selector.h +++ b/src/SVTK/SVTK_Selector.h @@ -41,7 +41,7 @@ class Handle(VTKViewer_Filter); class SALOME_Actor; -class SVTK_SelectionEvent; +struct SVTK_SelectionEvent; class vtkRenderer; class Handle(SALOME_InteractiveObject); diff --git a/src/SVTK/SVTK_ViewModel.cxx b/src/SVTK/SVTK_ViewModel.cxx index 4fce1eb19..28cb85640 100644 --- a/src/SVTK/SVTK_ViewModel.cxx +++ b/src/SVTK/SVTK_ViewModel.cxx @@ -512,7 +512,8 @@ void SVTK_Viewer::EraseAll( const bool forced ) //if(!anObj.IsNull() && anObj->hasEntry() && aStudy) // ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),false,this); if(forced) - aRenderer->RemoveActor(anAct); + // RKV : aRenderer->RemoveActor(anAct); + anAct->RemoveFromRender(aRenderer); // RKV else{ // just erase actor anAct->SetVisibility( false ); diff --git a/src/Style/Style_Salome.cxx b/src/Style/Style_Salome.cxx index 0755b5d6a..a494b66d0 100644 --- a/src/Style/Style_Salome.cxx +++ b/src/Style/Style_Salome.cxx @@ -1614,8 +1614,10 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, if ( hover ) drawHoverRect(p, opt->rect, opt->palette.color( QPalette::Window ), aRad, Style_Tools::All, true); else { + QColor light = opt->palette.color( QPalette::Base ); + light.setAlpha( 255 ); Style_Tools::shadowRect( p, opt->rect, aRad, LINE_GR_MARGIN, SHADOW, - Style_Tools::All, opt->palette.color( QPalette::Base ), // getColor( Style_Model::fld_light_clr ), + Style_Tools::All, light, // getColor( Style_Model::fld_light_clr ), getColor( Style_Model::fld_dark_clr ), aBrdTopCol, aBrdBotCol, getBoolValue( Style_Model::all_antialized ), false ); } diff --git a/src/VTKViewer/Makefile.am b/src/VTKViewer/Makefile.am index 2454631e7..146f162b7 100755 --- a/src/VTKViewer/Makefile.am +++ b/src/VTKViewer/Makefile.am @@ -46,7 +46,9 @@ salomeinclude_HEADERS = \ VTKViewer_ViewManager.h \ VTKViewer_ViewModel.h \ VTKViewer_ViewWindow.h \ - VTKViewer_Functor.h + VTKViewer_Functor.h \ + VTKViewer_MergeFilter.h \ + VTKViewer_PassThroughFilter.h dist_libVTKViewer_la_SOURCES = \ VTKViewer_CellLocationsArray.cxx \ @@ -66,7 +68,9 @@ dist_libVTKViewer_la_SOURCES = \ VTKViewer_ViewManager.cxx \ VTKViewer_ViewModel.cxx \ VTKViewer_ConvexTool.cxx \ - VTKViewer_ViewWindow.cxx + VTKViewer_ViewWindow.cxx \ + VTKViewer_MergeFilter.cxx \ + VTKViewer_PassThroughFilter.cxx MOC_FILES = \ VTKViewer_RenderWindow_moc.cxx \ diff --git a/src/VTKViewer/VTKViewer_Actor.cxx b/src/VTKViewer/VTKViewer_Actor.cxx index 5c65df651..985e05920 100755 --- a/src/VTKViewer/VTKViewer_Actor.cxx +++ b/src/VTKViewer/VTKViewer_Actor.cxx @@ -77,7 +77,8 @@ VTKViewer_Actor myIsResolveCoincidentTopology(true), myStoreMapping(false), myGeomFilter(VTKViewer_GeometryFilter::New()), - myTransformFilter(VTKViewer_TransformFilter::New()) + myTransformFilter(VTKViewer_TransformFilter::New()), + myOpacity( 1. ) { vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor, myPolygonOffsetUnits); diff --git a/src/VTKViewer/VTKViewer_GeometryFilter.cxx b/src/VTKViewer/VTKViewer_GeometryFilter.cxx index a53421410..630b7870a 100755 --- a/src/VTKViewer/VTKViewer_GeometryFilter.cxx +++ b/src/VTKViewer/VTKViewer_GeometryFilter.cxx @@ -912,7 +912,8 @@ VTKViewer_GeometryFilter vtkIdType VTKViewer_GeometryFilter::GetElemObjId( int theVtkID ) { - if( myVTK2ObjIds.empty() || theVtkID > (int)myVTK2ObjIds.size() ) +// RKV if( myVTK2ObjIds.empty() || theVtkID > (int)myVTK2ObjIds.size() ) + if( myVTK2ObjIds.empty() || theVtkID >= (int)myVTK2ObjIds.size() ) // RKV return -1; #if defined __GNUC_2__ return myVTK2ObjIds[theVtkID]; diff --git a/src/VTKViewer/VTKViewer_MergeFilter.cxx b/src/VTKViewer/VTKViewer_MergeFilter.cxx new file mode 100755 index 000000000..727e08ca0 --- /dev/null +++ b/src/VTKViewer/VTKViewer_MergeFilter.cxx @@ -0,0 +1,529 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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 +// +#include "VTKViewer_MergeFilter.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +vtkCxxRevisionMacro(VTKViewer_MergeFilter, "$Revision$"); +vtkStandardNewMacro(VTKViewer_MergeFilter); + +class vtkFieldNode +{ +public: + vtkFieldNode(const char* name, vtkDataSet* ptr=0) + { + int length = static_cast(strlen(name)); + if (length > 0) + { + this->Name = new char[length+1]; + strcpy(this->Name, name); + } + else + { + this->Name = 0; + } + this->Ptr = ptr; + this->Next = 0; + } + ~vtkFieldNode() + { + delete[] this->Name; + } + + const char* GetName() + { + return Name; + } + vtkDataSet* Ptr; + vtkFieldNode* Next; +private: + vtkFieldNode(const vtkFieldNode&) {} + void operator=(const vtkFieldNode&) {} + char* Name; +}; + +class vtkFieldList +{ +public: + vtkFieldList() + { + this->First = 0; + this->Last = 0; + } + ~vtkFieldList() + { + vtkFieldNode* node = this->First; + vtkFieldNode* next; + while(node) + { + next = node->Next; + delete node; + node = next; + } + } + + + void Add(const char* name, vtkDataSet* ptr) + { + vtkFieldNode* newNode = new vtkFieldNode(name, ptr); + if (!this->First) + { + this->First = newNode; + this->Last = newNode; + } + else + { + this->Last->Next = newNode; + this->Last = newNode; + } + } + + friend class vtkFieldListIterator; + +private: + vtkFieldNode* First; + vtkFieldNode* Last; +}; + +class vtkFieldListIterator +{ +public: + vtkFieldListIterator(vtkFieldList* list) + { + this->List = list; + this->Position = 0; + } + void Begin() + { + this->Position = this->List->First; + } + void Next() + { + if (this->Position) + { + this->Position = this->Position->Next; + } + } + int End() + { + return this->Position ? 0 : 1; + } + vtkFieldNode* Get() + { + return this->Position; + } + +private: + vtkFieldNode* Position; + vtkFieldList* List; +}; + +//------------------------------------------------------------------------------ + +// Create object with no input or output. +VTKViewer_MergeFilter::VTKViewer_MergeFilter() +{ + this->FieldList = new vtkFieldList; + this->SetNumberOfInputPorts(6); +} + +VTKViewer_MergeFilter::~VTKViewer_MergeFilter() +{ + delete this->FieldList; +} + +vtkDataSet* VTKViewer_MergeFilter::GetGeometry() +{ + if (this->GetNumberOfInputConnections(0) < 1) + { + return NULL; + } + return vtkDataSet::SafeDownCast( + this->GetExecutive()->GetInputData(0, 0)); +} + +void VTKViewer_MergeFilter::SetScalars(vtkDataSet *input) +{ + this->SetInput(1, input); +} +vtkDataSet *VTKViewer_MergeFilter::GetScalars() +{ + if (this->GetNumberOfInputConnections(1) < 1) + { + return NULL; + } + return vtkDataSet::SafeDownCast( + this->GetExecutive()->GetInputData(1, 0)); +} + +void VTKViewer_MergeFilter::SetVectors(vtkDataSet *input) +{ + this->SetInput(2, input); +} +vtkDataSet *VTKViewer_MergeFilter::GetVectors() +{ + if (this->GetNumberOfInputConnections(2) < 1) + { + return NULL; + } + return vtkDataSet::SafeDownCast( + this->GetExecutive()->GetInputData(2, 0)); +} + +void VTKViewer_MergeFilter::SetNormals(vtkDataSet *input) +{ + this->SetInput(3, input); +} +vtkDataSet *VTKViewer_MergeFilter::GetNormals() +{ + if (this->GetNumberOfInputConnections(3) < 1) + { + return NULL; + } + return vtkDataSet::SafeDownCast( + this->GetExecutive()->GetInputData(3, 0)); +} + +void VTKViewer_MergeFilter::SetTCoords(vtkDataSet *input) +{ + this->SetInput(4, input); +} +vtkDataSet *VTKViewer_MergeFilter::GetTCoords() +{ + if (this->GetNumberOfInputConnections(4) < 1) + { + return NULL; + } + return vtkDataSet::SafeDownCast( + this->GetExecutive()->GetInputData(4, 0)); +} + +void VTKViewer_MergeFilter::SetTensors(vtkDataSet *input) +{ + this->SetInput(5, input); +} +vtkDataSet *VTKViewer_MergeFilter::GetTensors() +{ + if (this->GetNumberOfInputConnections(5) < 1) + { + return NULL; + } + return vtkDataSet::SafeDownCast( + this->GetExecutive()->GetInputData(5, 0)); +} + +void VTKViewer_MergeFilter::AddField(const char* name, vtkDataSet* input) +{ + this->FieldList->Add(name, input); +} + +int VTKViewer_MergeFilter::RequestData( + vtkInformation *vtkNotUsed(request), + vtkInformationVector **inputVector, + vtkInformationVector *outputVector) +{ + // get the info objects + vtkInformation *inInfo = inputVector[0]->GetInformationObject(0); + vtkInformation *outInfo = outputVector->GetInformationObject(0); + vtkInformation *scalarsInfo = inputVector[1]->GetInformationObject(0); + vtkInformation *vectorsInfo = inputVector[2]->GetInformationObject(0); + vtkInformation *normalsInfo = inputVector[3]->GetInformationObject(0); + vtkInformation *tCoordsInfo = inputVector[4]->GetInformationObject(0); + vtkInformation *tensorsInfo = inputVector[5]->GetInformationObject(0); + + // get the input and ouptut + vtkDataSet *input = vtkDataSet::SafeDownCast( + inInfo->Get(vtkDataObject::DATA_OBJECT())); + vtkDataSet *output = vtkDataSet::SafeDownCast( + outInfo->Get(vtkDataObject::DATA_OBJECT())); + vtkDataSet *scalarsData = 0; + vtkDataSet *vectorsData = 0; + vtkDataSet *normalsData = 0; + vtkDataSet *tCoordsData = 0; + vtkDataSet *tensorsData = 0; + if (scalarsInfo) + { + scalarsData = vtkDataSet::SafeDownCast( + scalarsInfo->Get(vtkDataObject::DATA_OBJECT())); + } + if (vectorsInfo) + { + vectorsData = vtkDataSet::SafeDownCast( + vectorsInfo->Get(vtkDataObject::DATA_OBJECT())); + } + if (normalsInfo) + { + normalsData = vtkDataSet::SafeDownCast( + normalsInfo->Get(vtkDataObject::DATA_OBJECT())); + } + if (tCoordsInfo) + { + tCoordsData = vtkDataSet::SafeDownCast( + tCoordsInfo->Get(vtkDataObject::DATA_OBJECT())); + } + if (tensorsInfo) + { + tensorsData = vtkDataSet::SafeDownCast( + tensorsInfo->Get(vtkDataObject::DATA_OBJECT())); + } + + vtkIdType numPts, numScalars=0, numVectors=0, numNormals=0, numTCoords=0; + vtkIdType numTensors=0; + vtkIdType numCells, numCellScalars=0, numCellVectors=0, numCellNormals=0; + vtkIdType numCellTCoords=0, numCellTensors=0; + vtkPointData *pd; + vtkDataArray *scalars = NULL; + vtkDataArray *vectors = NULL; + vtkDataArray *normals = NULL; + vtkDataArray *tcoords = NULL; + vtkDataArray *tensors = NULL; + vtkCellData *cd; + vtkDataArray *cellScalars = NULL; + vtkDataArray *cellVectors = NULL; + vtkDataArray *cellNormals = NULL; + vtkDataArray *cellTCoords = NULL; + vtkDataArray *cellTensors = NULL; + vtkPointData *outputPD = output->GetPointData(); + vtkCellData *outputCD = output->GetCellData(); + + vtkDebugMacro(<<"Merging data!"); + + // geometry needs to be copied + output->CopyStructure(input); + if ( (numPts = input->GetNumberOfPoints()) < 1 ) + { + vtkWarningMacro(<<"Nothing to merge!"); + } + numCells = input->GetNumberOfCells(); + + if ( scalarsData ) + { + pd = scalarsData->GetPointData(); + scalars = pd->GetScalars(); + if ( scalars != NULL ) + { + numScalars = scalars->GetNumberOfTuples(); + } + cd = scalarsData->GetCellData(); + cellScalars = cd->GetScalars(); + if ( cellScalars != NULL ) + { + numCellScalars = cellScalars->GetNumberOfTuples(); + } + } + + if ( vectorsData ) + { + pd = vectorsData->GetPointData(); + vectors = pd->GetVectors(); + if ( vectors != NULL ) + { + numVectors= vectors->GetNumberOfTuples(); + } + cd = vectorsData->GetCellData(); + cellVectors = cd->GetVectors(); + if ( cellVectors != NULL ) + { + numCellVectors = cellVectors->GetNumberOfTuples(); + } + } + + if ( normalsData ) + { + pd = normalsData->GetPointData(); + normals = pd->GetNormals(); + if ( normals != NULL ) + { + numNormals= normals->GetNumberOfTuples(); + } + cd = normalsData->GetCellData(); + cellNormals = cd->GetNormals(); + if ( cellNormals != NULL ) + { + numCellNormals = cellNormals->GetNumberOfTuples(); + } + } + + if ( tCoordsData ) + { + pd = tCoordsData->GetPointData(); + tcoords = pd->GetTCoords(); + if ( tcoords != NULL ) + { + numTCoords= tcoords->GetNumberOfTuples(); + } + cd = tCoordsData->GetCellData(); + cellTCoords = cd->GetTCoords(); + if ( cellTCoords != NULL ) + { + numCellTCoords = cellTCoords->GetNumberOfTuples(); + } + } + + if ( tensorsData ) + { + pd = tensorsData->GetPointData(); + tensors = pd->GetTensors(); + if ( tensors != NULL ) + { + numTensors = tensors->GetNumberOfTuples(); + } + cd = tensorsData->GetCellData(); + cellTensors = cd->GetTensors(); + if ( cellTensors != NULL ) + { + numCellTensors = cellTensors->GetNumberOfTuples(); + } + } + + // merge data only if it is consistent + if ( numPts == numScalars ) + { + outputPD->SetScalars(scalars); + } + if ( numCells == numCellScalars ) + { + outputCD->SetScalars(cellScalars); + } + + if ( numPts == numVectors ) + { + outputPD->SetVectors(vectors); + } + if ( numCells == numCellVectors ) + { + outputCD->SetVectors(cellVectors); + } + + if ( numPts == numNormals ) + { + outputPD->SetNormals(normals); + } + if ( numCells == numCellNormals ) + { + outputCD->SetNormals(cellNormals); + } + + if ( numPts == numTCoords ) + { + outputPD->SetTCoords(tcoords); + } + if ( numCells == numCellTCoords ) + { + outputCD->SetTCoords(cellTCoords); + } + + if ( numPts == numTensors ) + { + outputPD->SetTensors(tensors); + } + if ( numCells == numCellTensors ) + { + outputCD->SetTensors(cellTensors); + } + + vtkFieldListIterator it(this->FieldList); + vtkDataArray* da; + const char* name; + vtkIdType num; + for(it.Begin(); !it.End() ; it.Next()) + { + pd = it.Get()->Ptr->GetPointData(); + cd = it.Get()->Ptr->GetCellData(); + name = it.Get()->GetName(); + if ( (da=pd->GetArray(name)) ) + { + num = da->GetNumberOfTuples(); + if (num == numPts) + { + outputPD->AddArray(da); + } + } + if ( (da=cd->GetArray(name)) ) + { + num = da->GetNumberOfTuples(); +// RKV: Fixed to be able to pass through celldata arrays given by AddField() +// RKV if (num == numPts) + if (num == numCells) // RKV + { + outputCD->AddArray(da); + } + } + } + + return 1; +} + +//---------------------------------------------------------------------------- +// Trick: Abstract data types that may or may not be the same type +// (structured/unstructured), but the points/cells match up. +// Output/Geometry may be structured while ScalarInput may be +// unstructured (but really have same triagulation/topology as geometry). +// Just request all the input. Always generate all of the output (todo). +int VTKViewer_MergeFilter::RequestUpdateExtent( + vtkInformation *vtkNotUsed(request), + vtkInformationVector **inputVector, + vtkInformationVector *vtkNotUsed(outputVector)) +{ + vtkInformation *inputInfo; + int idx; + + for (idx = 0; idx < 6; ++idx) + { + inputInfo = inputVector[idx]->GetInformationObject(0); + if (inputInfo) + { + inputInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER(), + 0); + inputInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_PIECES(), + 1); + inputInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_GHOST_LEVELS(), + 0); + inputInfo->Set(vtkStreamingDemandDrivenPipeline::EXACT_EXTENT(), 1); + } + } + return 1; +} + +int VTKViewer_MergeFilter::FillInputPortInformation(int port, vtkInformation *info) +{ + int retval = this->Superclass::FillInputPortInformation(port, info); + if (port > 0) + { + info->Set(vtkAlgorithm::INPUT_IS_OPTIONAL(), 1); + } + return retval; +} + +void VTKViewer_MergeFilter::PrintSelf(ostream& os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os,indent); + +} + diff --git a/src/VTKViewer/VTKViewer_MergeFilter.h b/src/VTKViewer/VTKViewer_MergeFilter.h new file mode 100755 index 000000000..061888efd --- /dev/null +++ b/src/VTKViewer/VTKViewer_MergeFilter.h @@ -0,0 +1,98 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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 +// +#ifndef __VTKViewer_MergeFilter_h +#define __VTKViewer_MergeFilter_h + +#include "VTKViewer.h" // RKV +#include "vtkDataSetAlgorithm.h" + +class vtkFieldList; + +// .NAME VTKViewer_MergeFilter - extract separate components of data from different datasets +// .SECTION Description +// VTKViewer_MergeFilter is a filter that extracts separate components of data from +// different datasets and merges them into a single dataset. The output from +// this filter is of the same type as the input (i.e., vtkDataSet.) It treats +// both cell and point data set attributes. + +// RKV: The source is vtkMergeFilter. +// RKV: Fixed to be able to pass through celldata arrays given by AddField() + +//RKV class VTK_GRAPHICS_EXPORT VTKViewer_MergeFilter : public vtkDataSetToDataSetFilter +class VTKVIEWER_EXPORT VTKViewer_MergeFilter : public vtkDataSetAlgorithm // RKV +{ +public: + static VTKViewer_MergeFilter *New(); + vtkTypeRevisionMacro(VTKViewer_MergeFilter,vtkDataSetAlgorithm); + void PrintSelf(ostream& os, vtkIndent indent); + + // Description: + // Specify object from which to extract geometry information. + void SetGeometry(vtkDataSet *input) {this->SetInput(input);}; + vtkDataSet *GetGeometry(); + + // Description: + // Specify object from which to extract scalar information. + void SetScalars(vtkDataSet *); + vtkDataSet *GetScalars(); + + // Description: + // Set / get the object from which to extract vector information. + void SetVectors(vtkDataSet *); + vtkDataSet *GetVectors(); + + // Description: + // Set / get the object from which to extract normal information. + void SetNormals(vtkDataSet *); + vtkDataSet *GetNormals(); + + // Description: + // Set / get the object from which to extract texture coordinates + // information. + void SetTCoords(vtkDataSet *); + vtkDataSet *GetTCoords(); + + // Description: + // Set / get the object from which to extract tensor data. + void SetTensors(vtkDataSet *); + vtkDataSet *GetTensors(); + + // Description: + // Set the object from which to extract a field and the name + // of the field + void AddField(const char* name, vtkDataSet* input); + +protected: + VTKViewer_MergeFilter(); + ~VTKViewer_MergeFilter(); + + // Usual data generation method + int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *); + int RequestUpdateExtent(vtkInformation *, vtkInformationVector **, vtkInformationVector *); + int FillInputPortInformation(int port, vtkInformation *info); + + vtkFieldList* FieldList; +private: + VTKViewer_MergeFilter(const VTKViewer_MergeFilter&); // Not implemented. + void operator=(const VTKViewer_MergeFilter&); // Not implemented. + }; + +#endif + + diff --git a/src/VTKViewer/VTKViewer_ShrinkFilter.cxx b/src/VTKViewer/VTKViewer_ShrinkFilter.cxx index 3391c08c7..8751cd5eb 100755 --- a/src/VTKViewer/VTKViewer_ShrinkFilter.cxx +++ b/src/VTKViewer/VTKViewer_ShrinkFilter.cxx @@ -185,5 +185,5 @@ vtkIdType VTKViewer_ShrinkFilter::GetNodeObjId(int theVtkID) { if ( myVTK2ObjIds.empty() || theVtkID > (int)myVTK2ObjIds.size() ) return -1; - return myVTK2ObjIds.at(theVtkID); + return myVTK2ObjIds[theVtkID]; } diff --git a/src/VTKViewer/VTKViewer_Utilities.cxx b/src/VTKViewer/VTKViewer_Utilities.cxx index 09b764236..9133ee012 100755 --- a/src/VTKViewer/VTKViewer_Utilities.cxx +++ b/src/VTKViewer/VTKViewer_Utilities.cxx @@ -316,36 +316,4 @@ bool ComputeBBCenter(vtkRenderer* theRenderer, vtkFloatingPointType theCenter[3] } return false; - - /* - vtkFloatingPointType aBounds[6]; - int aCount = ComputeVisiblePropBounds(theRenderer,aBounds); - printf("aNewBndBox[0] = %f, aNewBndBox[1] = %f,\naNewBndBox[2] = %f, aNewBndBox[3] = %f,\naNewBndBox[4] = %f, aNewBndBox[5] = %f\n", - aBounds[0],aBounds[1],aBounds[2],aBounds[3],aBounds[4],aBounds[5]); - printf("aCount = %d\n",aCount); - - if(aCount){ - static vtkFloatingPointType MIN_DISTANCE = 1.0 / VTK_LARGE_FLOAT; - - vtkFloatingPointType aLength = aBounds[1]-aBounds[0]; - aLength = max((aBounds[3]-aBounds[2]),aLength); - aLength = max((aBounds[5]-aBounds[4]),aLength); - - if(aLength < MIN_DISTANCE) - return false; - - vtkFloatingPointType aWidth = - sqrt((aBounds[1]-aBounds[0])*(aBounds[1]-aBounds[0]) + - (aBounds[3]-aBounds[2])*(aBounds[3]-aBounds[2]) + - (aBounds[5]-aBounds[4])*(aBounds[5]-aBounds[4])); - - if(aWidth < MIN_DISTANCE) - return false; - - theCenter[0] = (aBounds[0] + aBounds[1])/2.0; - theCenter[1] = (aBounds[2] + aBounds[3])/2.0; - theCenter[2] = (aBounds[4] + aBounds[5])/2.0; - return true; - } - return false;*/ }