Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "SMESHGUI_PatternWidget.h"
00029
00030
00031 #include <QPainter>
00032
00033 const int Shift = 4;
00034 const int Border = 20;
00035 const int Radius = 3;
00036
00037
00038
00039
00040
00041 SMESHGUI_PatternWidget::SMESHGUI_PatternWidget( QWidget* parent )
00042 : QFrame( parent )
00043 {
00044 myMinU = myMinV = myMaxU = myMaxV = 0;
00045 setMinimumHeight( 150 );
00046 }
00047
00048
00049
00050
00051
00052 SMESHGUI_PatternWidget::~SMESHGUI_PatternWidget()
00053 {
00054 }
00055
00056
00057
00058
00059
00060 void SMESHGUI_PatternWidget::SetPoints( const PointVector& thePoints,
00061 const QVector<int>& theKeys,
00062 const ConnectivityVector& theConnections )
00063 {
00064 myPoints = thePoints;
00065 myKeys = theKeys;
00066 myConnections = theConnections;
00067
00068 if ( myPoints.isEmpty() )
00069 return;
00070
00071 myMinU = myMaxU = myPoints[0].x;
00072 myMinV = myMaxV = myPoints[0].y;
00073
00074 for ( int i = 1; i < myPoints.size(); i++ ) {
00075 myMinU = qMin( myPoints[i].x, myMinU );
00076 myMaxU = qMax( myPoints[i].x, myMaxU );
00077 myMinV = qMin( myPoints[i].y, myMinV );
00078 myMaxV = qMax( myPoints[i].y, myMaxV );
00079 }
00080
00081 repaint();
00082 }
00083
00084
00085
00086
00087
00088 void SMESHGUI_PatternWidget::paintEvent( QPaintEvent* )
00089 {
00090 QPainter painter( this );
00091 painter.setBrush( Qt::SolidPattern );
00092
00093
00094 for ( int i = 0; i < myKeys.size() && i < myPoints.size(); i++ ) {
00095 SMESH::PointStruct aPoint = myPoints[ myKeys[i] ];
00096 QPoint aQPnt = mapCoords( aPoint.x, aPoint.y );
00097
00098 painter.drawPie( aQPnt.x() - Radius, aQPnt.y() - Radius,
00099 Radius * 2, Radius * 2, 0, 360 * 16 );
00100 painter.drawText( aQPnt.x() + Shift, aQPnt.y() - Shift,
00101 QString::number( i+1 ) );
00102 }
00103
00104
00105 for ( int i = 0; i < myConnections.size(); i++ ) {
00106 QVector<int> aCVector = myConnections[i];
00107
00108 if ( aCVector.isEmpty() )
00109 continue;
00110
00111 SMESH::PointStruct aPoint = myPoints[ aCVector[0] ];
00112 const QPoint aBeginPnt = mapCoords( aPoint.x, aPoint.y );
00113 QPoint aFirstPnt = aBeginPnt, aSecondPnt;
00114
00115 for ( int j = 1; j < aCVector.size(); j++ ) {
00116 aPoint = myPoints[ aCVector[j] ];
00117 aSecondPnt = mapCoords( aPoint.x, aPoint.y );
00118 painter.drawLine( aFirstPnt, aSecondPnt );
00119 aFirstPnt = aSecondPnt;
00120 }
00121
00122 painter.drawLine( aBeginPnt, aSecondPnt );
00123 }
00124 }
00125
00126
00127
00128
00129
00130 QPoint SMESHGUI_PatternWidget::mapCoords( const double u, const double v )
00131 {
00132 int aWidth = width() - 2 * Border;
00133 int aHeight = height() - 2 * Border;
00134
00135 double aUBound = myMaxU - myMinU;
00136 double aVBound = myMaxV - myMinV;
00137
00138 double aUScale = aWidth / aUBound;
00139 double aVScale = aHeight / aVBound;
00140
00141 double aScale;
00142 aUScale <= aVScale ? aScale = aUScale : aScale = aVScale;
00143
00144 double aUMiddle = ( myMaxU + myMinU ) / 2;
00145 double aVMiddle = ( myMaxV + myMinV ) / 2;
00146
00147 int x = int( aWidth / 2 + ( u - aUMiddle ) * aScale + Border - Shift );
00148
00149 int y = int( aHeight / 2 + ( aVMiddle - v ) * aScale + Border + Shift );
00150
00151 return QPoint( x, y );
00152 }