2013-04-01 19:05:47 +06:00
|
|
|
// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
|
2004-12-01 15:48:31 +05:00
|
|
|
//
|
2012-08-09 16:03:55 +06:00
|
|
|
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
|
|
|
|
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
|
2005-06-07 19:22:20 +06:00
|
|
|
//
|
2012-08-09 16:03:55 +06:00
|
|
|
// 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.
|
2005-06-07 19:22:20 +06:00
|
|
|
//
|
2012-08-09 16:03:55 +06:00
|
|
|
// 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.
|
2005-06-07 19:22:20 +06:00
|
|
|
//
|
2012-08-09 16:03:55 +06:00
|
|
|
// 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
|
2005-06-07 19:22:20 +06:00
|
|
|
//
|
2012-08-09 16:03:55 +06:00
|
|
|
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
|
2004-12-01 15:48:31 +05:00
|
|
|
//
|
2012-08-09 16:03:55 +06:00
|
|
|
|
2009-02-17 10:27:49 +05:00
|
|
|
// SMESH SMESHGUI : GUI for SMESH component
|
|
|
|
// File : SMESHGUI_PatternWidget.cxx
|
|
|
|
// Author : Michael ZORIN, Open CASCADE S.A.S.
|
|
|
|
// SMESH includes
|
2004-12-01 15:48:31 +05:00
|
|
|
//
|
|
|
|
#include "SMESHGUI_PatternWidget.h"
|
|
|
|
|
2009-02-17 10:27:49 +05:00
|
|
|
// Qt includes
|
|
|
|
#include <QPainter>
|
2004-12-01 15:48:31 +05:00
|
|
|
|
2009-02-17 10:27:49 +05:00
|
|
|
const int Shift = 4; // shift of the point number from point
|
|
|
|
const int Border = 20; // border size
|
|
|
|
const int Radius = 3; // radius of a point
|
2004-12-01 15:48:31 +05:00
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// class : SMESHGUI_PatternWidget()
|
2005-06-07 19:22:20 +06:00
|
|
|
// purpose :
|
2004-12-01 15:48:31 +05:00
|
|
|
//=================================================================================
|
2009-02-17 10:27:49 +05:00
|
|
|
SMESHGUI_PatternWidget::SMESHGUI_PatternWidget( QWidget* parent )
|
|
|
|
: QFrame( parent )
|
2004-12-01 15:48:31 +05:00
|
|
|
{
|
2009-02-17 10:27:49 +05:00
|
|
|
myMinU = myMinV = myMaxU = myMaxV = 0;
|
|
|
|
setMinimumHeight( 150 );
|
2004-12-01 15:48:31 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : ~SMESHGUI_PatternWidget()
|
2005-06-07 19:22:20 +06:00
|
|
|
// purpose :
|
2004-12-01 15:48:31 +05:00
|
|
|
//=================================================================================
|
|
|
|
SMESHGUI_PatternWidget::~SMESHGUI_PatternWidget()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
2005-06-07 19:22:20 +06:00
|
|
|
// function : SetPoints()
|
|
|
|
// purpose :
|
2004-12-01 15:48:31 +05:00
|
|
|
//=================================================================================
|
2009-02-17 10:27:49 +05:00
|
|
|
void SMESHGUI_PatternWidget::SetPoints( const PointVector& thePoints,
|
|
|
|
const QVector<int>& theKeys,
|
|
|
|
const ConnectivityVector& theConnections )
|
2004-12-01 15:48:31 +05:00
|
|
|
{
|
2009-02-17 10:27:49 +05:00
|
|
|
myPoints = thePoints;
|
|
|
|
myKeys = theKeys;
|
|
|
|
myConnections = theConnections;
|
2005-06-07 19:22:20 +06:00
|
|
|
|
2009-02-17 10:27:49 +05:00
|
|
|
if ( myPoints.isEmpty() )
|
2004-12-01 15:48:31 +05:00
|
|
|
return;
|
2005-06-07 19:22:20 +06:00
|
|
|
|
2009-02-17 10:27:49 +05:00
|
|
|
myMinU = myMaxU = myPoints[0].x;
|
|
|
|
myMinV = myMaxV = myPoints[0].y;
|
|
|
|
|
|
|
|
for ( int i = 1; i < myPoints.size(); i++ ) {
|
|
|
|
myMinU = qMin( myPoints[i].x, myMinU );
|
|
|
|
myMaxU = qMax( myPoints[i].x, myMaxU );
|
|
|
|
myMinV = qMin( myPoints[i].y, myMinV );
|
|
|
|
myMaxV = qMax( myPoints[i].y, myMaxV );
|
2005-06-07 19:22:20 +06:00
|
|
|
}
|
|
|
|
|
2004-12-01 15:48:31 +05:00
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
2005-06-07 19:22:20 +06:00
|
|
|
// function : paintEvent()
|
|
|
|
// purpose :
|
2004-12-01 15:48:31 +05:00
|
|
|
//=================================================================================
|
2009-02-17 10:27:49 +05:00
|
|
|
void SMESHGUI_PatternWidget::paintEvent( QPaintEvent* )
|
2004-12-01 15:48:31 +05:00
|
|
|
{
|
2009-02-17 10:27:49 +05:00
|
|
|
QPainter painter( this );
|
|
|
|
painter.setBrush( Qt::SolidPattern );
|
2005-06-07 19:22:20 +06:00
|
|
|
|
2009-02-17 10:27:49 +05:00
|
|
|
// Draw points
|
|
|
|
for ( int i = 0; i < myKeys.size() && i < myPoints.size(); i++ ) {
|
2005-06-07 19:22:20 +06:00
|
|
|
SMESH::PointStruct aPoint = myPoints[ myKeys[i] ];
|
2009-02-17 10:27:49 +05:00
|
|
|
QPoint aQPnt = mapCoords( aPoint.x, aPoint.y );
|
2005-06-07 19:22:20 +06:00
|
|
|
|
2009-02-17 10:27:49 +05:00
|
|
|
painter.drawPie( aQPnt.x() - Radius, aQPnt.y() - Radius,
|
2012-08-09 16:03:55 +06:00
|
|
|
Radius * 2, Radius * 2, 0, 360 * 16 );
|
2009-02-17 10:27:49 +05:00
|
|
|
painter.drawText( aQPnt.x() + Shift, aQPnt.y() - Shift,
|
2012-08-09 16:03:55 +06:00
|
|
|
QString::number( i+1 ) );
|
2005-06-07 19:22:20 +06:00
|
|
|
}
|
|
|
|
|
2009-02-17 10:27:49 +05:00
|
|
|
// Draw lines
|
|
|
|
for ( int i = 0; i < myConnections.size(); i++ ) {
|
|
|
|
QVector<int> aCVector = myConnections[i];
|
2005-06-07 19:22:20 +06:00
|
|
|
|
2009-02-17 10:27:49 +05:00
|
|
|
if ( aCVector.isEmpty() )
|
2005-06-07 19:22:20 +06:00
|
|
|
continue;
|
|
|
|
|
|
|
|
SMESH::PointStruct aPoint = myPoints[ aCVector[0] ];
|
2009-02-17 10:27:49 +05:00
|
|
|
const QPoint aBeginPnt = mapCoords( aPoint.x, aPoint.y );
|
2005-06-07 19:22:20 +06:00
|
|
|
QPoint aFirstPnt = aBeginPnt, aSecondPnt;
|
|
|
|
|
2009-02-17 10:27:49 +05:00
|
|
|
for ( int j = 1; j < aCVector.size(); j++ ) {
|
2005-06-07 19:22:20 +06:00
|
|
|
aPoint = myPoints[ aCVector[j] ];
|
2009-02-17 10:27:49 +05:00
|
|
|
aSecondPnt = mapCoords( aPoint.x, aPoint.y );
|
|
|
|
painter.drawLine( aFirstPnt, aSecondPnt );
|
2005-06-07 19:22:20 +06:00
|
|
|
aFirstPnt = aSecondPnt;
|
2004-12-01 15:48:31 +05:00
|
|
|
}
|
|
|
|
|
2009-02-17 10:27:49 +05:00
|
|
|
painter.drawLine( aBeginPnt, aSecondPnt );
|
2005-06-07 19:22:20 +06:00
|
|
|
}
|
|
|
|
}
|
2004-12-01 15:48:31 +05:00
|
|
|
|
|
|
|
//=================================================================================
|
2009-02-17 10:27:49 +05:00
|
|
|
// function : mapCoords()
|
2005-06-07 19:22:20 +06:00
|
|
|
// purpose :
|
2004-12-01 15:48:31 +05:00
|
|
|
//=================================================================================
|
2009-02-17 10:27:49 +05:00
|
|
|
QPoint SMESHGUI_PatternWidget::mapCoords( const double u, const double v )
|
2004-12-01 15:48:31 +05:00
|
|
|
{
|
2009-02-17 10:27:49 +05:00
|
|
|
int aWidth = width() - 2 * Border;
|
|
|
|
int aHeight = height() - 2 * Border;
|
2004-12-01 15:48:31 +05:00
|
|
|
|
|
|
|
double aUBound = myMaxU - myMinU;
|
|
|
|
double aVBound = myMaxV - myMinV;
|
2005-06-07 19:22:20 +06:00
|
|
|
|
2009-02-17 10:27:49 +05:00
|
|
|
double aUScale = aWidth / aUBound;
|
|
|
|
double aVScale = aHeight / aVBound;
|
2005-06-07 19:22:20 +06:00
|
|
|
|
2004-12-01 15:48:31 +05:00
|
|
|
double aScale;
|
|
|
|
aUScale <= aVScale ? aScale = aUScale : aScale = aVScale;
|
|
|
|
|
2009-02-17 10:27:49 +05:00
|
|
|
double aUMiddle = ( myMaxU + myMinU ) / 2;
|
|
|
|
double aVMiddle = ( myMaxV + myMinV ) / 2;
|
2005-06-07 19:22:20 +06:00
|
|
|
|
2009-02-17 10:27:49 +05:00
|
|
|
int x = int( aWidth / 2 + ( u - aUMiddle ) * aScale + Border - Shift );
|
2005-06-07 19:22:20 +06:00
|
|
|
|
2009-02-17 10:27:49 +05:00
|
|
|
int y = int( aHeight / 2 + ( aVMiddle - v ) * aScale + Border + Shift );
|
2005-06-07 19:22:20 +06:00
|
|
|
|
2009-02-17 10:27:49 +05:00
|
|
|
return QPoint( x, y );
|
2004-12-01 15:48:31 +05:00
|
|
|
}
|