1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_PatternWidget.cxx
25 // Author : Michael ZORIN
29 #include "SMESHGUI_PatternWidget.h"
36 //=================================================================================
37 // class : SMESHGUI_PatternWidget()
39 //=================================================================================
40 SMESHGUI_PatternWidget::SMESHGUI_PatternWidget( QWidget* parent, const char* name, WFlags fl )
41 : QFrame( parent, name, WStyle_Customize)
43 myMinU = myMinV = myMaxU = myMaxV = 0;
44 setMinimumHeight(150);
50 //=================================================================================
51 // function : ~SMESHGUI_PatternWidget()
53 //=================================================================================
54 SMESHGUI_PatternWidget::~SMESHGUI_PatternWidget()
59 //=================================================================================
60 // function : SMESHGUI_PatternWidget::SetPoints
62 //=================================================================================
63 void SMESHGUI_PatternWidget::SetPoints( PointVector thePoints, QValueVector<int> theKeys, ConnectivityVector theConnections )
67 myConnections = theConnections;
69 if (!thePoints.size())
72 myMinU = myMaxU = (thePoints[0]).x;
73 myMinV = myMaxV = (thePoints[0]).y;
76 for (int i = 1; i < thePoints.size(); i++)
94 static const int Shift = 4; // shift of the point number from point
95 static const int Border = 20;
97 //=================================================================================
98 // function : SMESHGUI_PatternWidget::paintEvent
100 //=================================================================================
101 void SMESHGUI_PatternWidget::paintEvent( QPaintEvent * )
103 QPainter paint( this );
104 paint.setBrush (Qt::SolidPattern );
107 const int aRadius = 3; // radius of a point
109 for (int i = 0; i < myKeys.size() && i < myPoints.size(); i++)
111 SMESH::PointStruct aPoint = myPoints[ myKeys[i] ];
112 QPoint aQPnt = MapCoords( aPoint.x, aPoint.y);
114 paint.drawPie( aQPnt.x() - aRadius, aQPnt.y() - aRadius, aRadius*2, aRadius*2, 5760, 5760 );
115 paint.drawText( aQPnt.x() + Shift, aQPnt.y() - Shift, QString::number( i+1 ) );
119 for (int i = 0; i < myConnections.size(); i++)
121 QValueVector<int> aCVector = myConnections[i];
123 if ( aCVector.size() == 0 )
126 SMESH::PointStruct aPoint = myPoints[ aCVector[0] ];
127 const QPoint aBeginPnt = MapCoords( aPoint.x, aPoint.y);
128 QPoint aFirstPnt = aBeginPnt, aSecondPnt;
130 for (int j = 1; j < aCVector.size(); j++)
132 aPoint = myPoints[ aCVector[j] ];
133 aSecondPnt = MapCoords( aPoint.x, aPoint.y);
134 paint.drawLine(aFirstPnt, aSecondPnt);
135 aFirstPnt = aSecondPnt;
138 paint.drawLine(aBeginPnt, aSecondPnt);
143 //=================================================================================
144 // function : SMESHGUI_PatternWidget::MapCoords
146 //=================================================================================
147 QPoint SMESHGUI_PatternWidget::MapCoords( const double u, const double v )
149 int aWidth = width() - 2*Border;
150 int aHeight = height() - 2*Border;
152 double aUBound = myMaxU - myMinU;
153 double aVBound = myMaxV - myMinV;
155 double aUScale = aWidth/aUBound;
156 double aVScale = aHeight/aVBound;
159 aUScale <= aVScale ? aScale = aUScale : aScale = aVScale;
161 double aUMiddle = ( myMaxU + myMinU )/2;
162 double aVMiddle = ( myMaxV + myMinV )/2;
164 int x = int( aWidth/2 + (u - aUMiddle)*aScale + Border - Shift);
166 int y = int( aHeight/2 + (aVMiddle - v)*aScale + Border + Shift);
168 QPoint aPoint = QPoint(x, y);