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
//! 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
(*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
/*! 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:
myYScale = 1.0;
myXGap = 0;
myYGap = 0;
+ myXZoom = 1.0;
myZoom = 1.0;
myIsHigh = GL_FALSE;
return theRect.toQRect().contains( myRect->toQRect() );
}
+/*!
+ 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 );
+}
+
/*!
Sets zoom factor
\param zoom - zoom factor
//! 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
//! Gap for Y direction of rect
GLfloat myYGap;
+ //!\warning It is for ouv
+ GLfloat myXZoom;
//!\warning It is for ouv
GLfloat myZoom;
TransformState state = EnTrain;
QMouseEvent* me = ( QMouseEvent* )e;
- myButtonState = me->modifiers();
+ myButtonState = me->buttons();
if ( e->type() == QEvent::MouseButtonPress )
myButtonState |= me->button(); /* add pressed button */
myMajorBtn = mouseOnlyState;
}
- if ( e->type() == QEvent::MouseButtonRelease && mouseOnlyState == myMajorBtn )
+ if ( e->type() == QEvent::MouseButtonRelease )
{
state = Fin;
}
SketchState state = EnTrain;
QMouseEvent* me = (QMouseEvent*)e;
- myButtonState = me->modifiers();
+ myButtonState = me->buttons();
if ( e->type() == QEvent::MouseButtonPress )
myButtonState |= me->button(); /* add pressed button */
if ( activeModule() )
modName = activeModule()->name();
- if ( myWinGeom.contains( modName ) )
- desktop()->restoreState( myWinGeom[modName] );
+ // temporarily commented (for CATHARE)
+ //if ( myWinGeom.contains( modName ) )
+ // desktop()->restoreState( myWinGeom[modName] );
if ( !myWinVis.contains( modName ) )
return;
if ( po != desktop() )
continue;
- if ( dwMap.contains( dw->objectName() ) )
- dw->setVisible( dwMap[dw->objectName()] );
+ // temporarily commented (for CATHARE)
+ //if ( dwMap.contains( dw->objectName() ) )
+ // dw->setVisible( dwMap[dw->objectName()] );
}
}
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;
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 );
return aMinX;
}
+/*!
+ Gets curve's maxiaml abscissa
+*/
+double Plot2d_Curve::getMaxX() const
+{
+ QList<Plot2d_Point>::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
*/
return aMinY;
}
+/*!
+ Gets curve's maximal ordinate
+*/
+double Plot2d_Curve::getMaxY() const
+{
+ QList<Plot2d_Point>::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
// 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;
"................................"};
+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
*/
}
resMgr->setValue( "Plot2d", "VerScaleMode", myYMode );
+
+ if ( myTitleChangedByUser )
+ {
+ myPrefTitle = myTitle;
+ myPrefTitleChangedByUser = true;
+ }
+ if ( myXTitleChangedByUser )
+ {
+ myPrefXTitle = myXTitle;
+ myXPrefTitleChangedByUser = true;
+ }
+ if ( myYTitleChangedByUser )
+ {
+ myPrefYTitle = myYTitle;
+ myYPrefTitleChangedByUser = true;
+ }
}
/*!
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 );
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;
+ }
+}
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; }
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();
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
#include <qpixmap.h>
#include <qlineedit.h>
+#include <qevent.h>
+
/*!
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 ),
/*!
\return current edited item
*/
-QListBoxItem* QtxListBox::editedItem() const
+QListWidgetItem* QtxListBox::editedItem() const
{
return item( editedIndex() );
}
ensureItemVisible( myEditIndex );
- ed->setText( text( myEditIndex ) );
+ ed->setText( item( myEditIndex )->text() );
updateEditor();
ed->show();
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 ) );
}
/*!
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 ) );
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 ) );
}
/*!
void QtxListBox::clearValidator()
{
if ( editor() )
- editor()->clearValidator();
+ editor()->setValidator( 0 );
}
/*!
*/
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;
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 );
}
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();
}
*/
void QtxListBox::setContentsPos( int x, int y )
{
- QListBox::setContentsPos( x, y );
+ //qt4 QListWidget::setContentsPos( x, y );
updateEditor();
}
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 );
}
/*!
*/
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();
}
if ( isEditEnabled() )
startEdition( itemAt( e->pos() ) );
else
- QListBox::mouseDoubleClickEvent( e );
+ QListWidget::mouseDoubleClickEvent( e );
}
/*!
myEditor = new QLineEdit( viewport() );
- 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 );
}
/*!
*/
void QtxListBox::updateEditor()
{
+ /*qt4
if ( !editedItem() || !editor() )
return;
r.addCoords( pix->width() + 2, 0, 0, 0 );
editor()->setGeometry( r );
+ */
}
Q_OBJECT
public:
- QtxListBox( QWidget* = 0, const char* = 0, Qt::WindowFlags = 0 );
+ QtxListBox( QWidget* = 0 );
virtual ~QtxListBox();
bool isEditEnabled() const;
protected:
virtual void keyPressEvent( QKeyEvent* );
- virtual void viewportResizeEvent( QResizeEvent* );
+ virtual void resizeEvent( QResizeEvent* ); //qt4 viewportResizeEvent
virtual void mouseDoubleClickEvent( QMouseEvent* );
private:
*/
QtxWorkstackTabBar::QtxWorkstackTabBar( QWidget* parent )
: QTabBar( parent ),
+ myActive( false ),
myId( -1 )
{
setDrawBase( true );
* 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 )
{
}
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();
}
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;
+}
bool isSynchronizing() const;
+ QString lastSelectionSource() const;
+ bool isSynchronizationEnabled() const;
+ void setSynchronizationEnabled( const bool );
+
signals:
void selectionChanged();
int myIterations;
bool myAutoDelFilter;
bool myIsSelChangeEnabled;
+ bool myIsSynchronizationEnabled;
+ QString myLastSelectionSource;
friend class SUIT_Selector;
};
--- /dev/null
+// 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 "vtkCellData.h"
+#include "vtkObjectFactory.h"
+#include "vtkPointData.h"
+#include "vtkPolyData.h"
+#include "vtkRectilinearGrid.h"
+#include "vtkStructuredGrid.h"
+#include "vtkStructuredPoints.h"
+#include "vtkUnstructuredGrid.h"
+
+vtkCxxRevisionMacro(VTKViewer_MergeFilter, "$Revision$");
+vtkStandardNewMacro(VTKViewer_MergeFilter);
+
+class vtkFieldNode
+{
+public:
+ vtkFieldNode(const char* name, vtkDataSet* ptr=0)
+ {
+ int length = static_cast<int>(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;
+}
+
+VTKViewer_MergeFilter::~VTKViewer_MergeFilter()
+{
+ delete this->FieldList;
+}
+
+void VTKViewer_MergeFilter::SetScalars(vtkDataSet *input)
+{
+ this->vtkProcessObject::SetNthInput(1, input);
+}
+vtkDataSet *VTKViewer_MergeFilter::GetScalars()
+{
+ if (this->NumberOfInputs < 2)
+ {
+ return NULL;
+ }
+ return (vtkDataSet *)(this->Inputs[1]);
+}
+
+void VTKViewer_MergeFilter::SetVectors(vtkDataSet *input)
+{
+ this->vtkProcessObject::SetNthInput(2, input);
+}
+vtkDataSet *VTKViewer_MergeFilter::GetVectors()
+{
+ if (this->NumberOfInputs < 3)
+ {
+ return NULL;
+ }
+ return (vtkDataSet *)(this->Inputs[2]);
+}
+
+void VTKViewer_MergeFilter::SetNormals(vtkDataSet *input)
+{
+ this->vtkProcessObject::SetNthInput(3, input);
+}
+vtkDataSet *VTKViewer_MergeFilter::GetNormals()
+{
+ if (this->NumberOfInputs < 4)
+ {
+ return NULL;
+ }
+ return (vtkDataSet *)(this->Inputs[3]);
+}
+
+void VTKViewer_MergeFilter::SetTCoords(vtkDataSet *input)
+{
+ this->vtkProcessObject::SetNthInput(4, input);
+}
+vtkDataSet *VTKViewer_MergeFilter::GetTCoords()
+{
+ if (this->NumberOfInputs < 5)
+ {
+ return NULL;
+ }
+ return (vtkDataSet *)(this->Inputs[4]);
+}
+
+void VTKViewer_MergeFilter::SetTensors(vtkDataSet *input)
+{
+ this->vtkProcessObject::SetNthInput(5, input);
+}
+vtkDataSet *VTKViewer_MergeFilter::GetTensors()
+{
+ if (this->NumberOfInputs < 6)
+ {
+ return NULL;
+ }
+ return (vtkDataSet *)(this->Inputs[5]);
+}
+
+void VTKViewer_MergeFilter::AddField(const char* name, vtkDataSet* input)
+{
+ this->FieldList->Add(name, input);
+}
+
+void VTKViewer_MergeFilter::Execute()
+{
+ 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;
+ vtkDataSet *output = this->GetOutput();
+ vtkPointData *outputPD = output->GetPointData();
+ vtkCellData *outputCD = output->GetCellData();
+
+ vtkDebugMacro(<<"Merging data!");
+
+ // geometry needs to be copied
+ output->CopyStructure(this->GetInput());
+ if ( (numPts = this->GetInput()->GetNumberOfPoints()) < 1 )
+ {
+ vtkWarningMacro(<<"Nothing to merge!");
+ }
+ numCells = this->GetInput()->GetNumberOfCells();
+
+ if ( this->GetScalars() )
+ {
+ pd = this->GetScalars()->GetPointData();
+ scalars = pd->GetScalars();
+ if ( scalars != NULL )
+ {
+ numScalars = scalars->GetNumberOfTuples();
+ }
+ cd = this->GetScalars()->GetCellData();
+ cellScalars = cd->GetScalars();
+ if ( cellScalars != NULL )
+ {
+ numCellScalars = cellScalars->GetNumberOfTuples();
+ }
+ }
+
+ if ( this->GetVectors() )
+ {
+ pd = this->GetVectors()->GetPointData();
+ vectors = pd->GetVectors();
+ if ( vectors != NULL )
+ {
+ numVectors= vectors->GetNumberOfTuples();
+ }
+ cd = this->GetVectors()->GetCellData();
+ cellVectors = cd->GetVectors();
+ if ( cellVectors != NULL )
+ {
+ numCellVectors = cellVectors->GetNumberOfTuples();
+ }
+ }
+
+ if ( this->GetNormals() )
+ {
+ pd = this->GetNormals()->GetPointData();
+ normals = pd->GetNormals();
+ if ( normals != NULL )
+ {
+ numNormals= normals->GetNumberOfTuples();
+ }
+ cd = this->GetNormals()->GetCellData();
+ cellNormals = cd->GetNormals();
+ if ( cellNormals != NULL )
+ {
+ numCellNormals = cellNormals->GetNumberOfTuples();
+ }
+ }
+
+ if ( this->GetTCoords() )
+ {
+ pd = this->GetTCoords()->GetPointData();
+ tcoords = pd->GetTCoords();
+ if ( tcoords != NULL )
+ {
+ numTCoords= tcoords->GetNumberOfTuples();
+ }
+ cd = this->GetTCoords()->GetCellData();
+ cellTCoords = cd->GetTCoords();
+ if ( cellTCoords != NULL )
+ {
+ numCellTCoords = cellTCoords->GetNumberOfTuples();
+ }
+ }
+
+ if ( this->GetTensors() )
+ {
+ pd = this->GetTensors()->GetPointData();
+ tensors = pd->GetTensors();
+ if ( tensors != NULL )
+ {
+ numTensors = tensors->GetNumberOfTuples();
+ }
+ cd = this->GetTensors()->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);
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
+// 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).
+void VTKViewer_MergeFilter::ComputeInputUpdateExtents(vtkDataObject *vtkNotUsed(data))
+{
+ vtkDataSet *input;
+ int idx;
+
+ for (idx = 0; idx < this->NumberOfInputs; ++idx)
+ {
+ input = (vtkDataSet *)(this->Inputs[idx]);
+ if (input)
+ {
+ input->SetUpdateExtent(0, 1, 0);
+ input->RequestExactExtentOn();
+ }
+ }
+}
+
+void VTKViewer_MergeFilter::PrintSelf(ostream& os, vtkIndent indent)
+{
+ this->Superclass::PrintSelf(os,indent);
+
+}
+
--- /dev/null
+// 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 "vtkDataSetToDataSetFilter.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 vtkDataSetToDataSetFilter // RKV
+{
+public:
+ static VTKViewer_MergeFilter *New();
+ vtkTypeRevisionMacro(VTKViewer_MergeFilter,vtkDataSetToDataSetFilter);
+ void PrintSelf(ostream& os, vtkIndent indent);
+
+ // Description:
+ // Specify object from which to extract geometry information.
+ void SetGeometry(vtkDataSet *input) {this->SetInput(input);};
+ vtkDataSet *GetGeometry() {return this->GetInput();};
+
+ // 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
+ void Execute();
+ void ComputeInputUpdateExtents(vtkDataObject *data);
+
+ vtkFieldList* FieldList;
+private:
+ VTKViewer_MergeFilter(const VTKViewer_MergeFilter&); // Not implemented.
+ void operator=(const VTKViewer_MergeFilter&); // Not implemented.
+ };
+
+#endif
+
+