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);
48 //=================================================================================
49 // function : ~SMESHGUI_PatternWidget()
51 //=================================================================================
52 SMESHGUI_PatternWidget::~SMESHGUI_PatternWidget()
56 //=================================================================================
57 // function : SetPoints()
59 //=================================================================================
60 void SMESHGUI_PatternWidget::SetPoints (PointVector thePoints,
61 QValueVector<int> theKeys,
62 ConnectivityVector theConnections)
66 myConnections = theConnections;
68 if (!thePoints.size())
71 myMinU = myMaxU = (thePoints[0]).x;
72 myMinV = myMaxV = (thePoints[0]).y;
75 for (int i = 1; i < thePoints.size(); i++) {
92 static const int Shift = 4; // shift of the point number from point
93 static const int Border = 20;
95 //=================================================================================
96 // function : paintEvent()
98 //=================================================================================
99 void SMESHGUI_PatternWidget::paintEvent (QPaintEvent*)
101 QPainter paint (this);
102 paint.setBrush(Qt::SolidPattern);
105 const int aRadius = 3; // radius of a point
107 for (int i = 0; i < myKeys.size() && i < myPoints.size(); i++) {
108 SMESH::PointStruct aPoint = myPoints[ myKeys[i] ];
109 QPoint aQPnt = MapCoords(aPoint.x, aPoint.y);
111 paint.drawPie(aQPnt.x() - aRadius, aQPnt.y() - aRadius, aRadius*2, aRadius*2, 5760, 5760);
112 paint.drawText(aQPnt.x() + Shift, aQPnt.y() - Shift, QString::number(i+1));
116 for (int i = 0; i < myConnections.size(); i++) {
117 QValueVector<int> aCVector = myConnections[i];
119 if (aCVector.size() == 0)
122 SMESH::PointStruct aPoint = myPoints[ aCVector[0] ];
123 const QPoint aBeginPnt = MapCoords(aPoint.x, aPoint.y);
124 QPoint aFirstPnt = aBeginPnt, aSecondPnt;
126 for (int j = 1; j < aCVector.size(); j++) {
127 aPoint = myPoints[ aCVector[j] ];
128 aSecondPnt = MapCoords(aPoint.x, aPoint.y);
129 paint.drawLine(aFirstPnt, aSecondPnt);
130 aFirstPnt = aSecondPnt;
133 paint.drawLine(aBeginPnt, aSecondPnt);
137 //=================================================================================
138 // function : MapCoords()
140 //=================================================================================
141 QPoint SMESHGUI_PatternWidget::MapCoords (const double u, const double v)
143 int aWidth = width() - 2*Border;
144 int aHeight = height() - 2*Border;
146 double aUBound = myMaxU - myMinU;
147 double aVBound = myMaxV - myMinV;
149 double aUScale = aWidth/aUBound;
150 double aVScale = aHeight/aVBound;
153 aUScale <= aVScale ? aScale = aUScale : aScale = aVScale;
155 double aUMiddle = (myMaxU + myMinU)/2;
156 double aVMiddle = (myMaxV + myMinV)/2;
158 int x = int(aWidth/2 + (u - aUMiddle)*aScale + Border - Shift);
160 int y = int(aHeight/2 + (aVMiddle - v)*aScale + Border + Shift);
162 QPoint aPoint = QPoint(x, y);