1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "YACSPrs_ServiceNode.h"
21 #include "YACSPrs_Def.h"
23 #include <SUIT_ResourceMgr.h>
27 #include <ServiceNode.hxx>
28 #include <ComponentInstance.hxx>
30 using namespace YACS::ENGINE;
32 void drawText1(QPainter& thePainter, const QString& theText,
33 const QRect& theRect, int theHAlign = Qt::AlignAuto)
35 int flags = theHAlign | Qt::AlignVCenter;
36 QRect r(theRect.x() + TEXT_MARGIN, theRect.y(),
37 theRect.width() - 2*TEXT_MARGIN, theRect.height());
39 QWMatrix aMat = thePainter.worldMatrix();
40 if (aMat.m11() != 1.0) {
41 // for scaled picture only
42 QRect r1 = aMat.mapRect(r);
43 QFont saved = thePainter.font();
45 if (f.pointSize() == -1) {
46 f.setPixelSize((int)(f.pixelSize()*aMat.m11()));
49 f.setPointSize((int)(f.pointSize()*aMat.m11()));
53 thePainter.setWorldMatrix(m);
54 thePainter.setFont(f);
55 thePainter.drawText(r1, flags, theText);
56 thePainter.setFont(saved);
60 thePainter.drawText(r, flags, theText);
68 YACSPrs_ServiceNode::YACSPrs_ServiceNode(SUIT_ResourceMgr* theMgr, QCanvas* theCanvas, YACS::ENGINE::Node* theNode):
69 YACSPrs_ElementaryNode(theMgr, theCanvas, theNode)
71 myServiceHeight = TITLE_HEIGHT;
72 myComponentHeight = TITLE_HEIGHT;
73 myMachineHeight = TITLE_HEIGHT;
75 setNodeColor(SERVICENODE_COLOR);
76 setNodeSubColor(SERVICENODE_SUBCOLOR);
78 setStoreColor(nodeColor());
79 setStoreSubColor(nodeSubColor());
81 //updatePorts(); // will be called in moveBy(...) function
82 moveBy(2*HOOKPOINT_SIZE,0);
90 YACSPrs_ServiceNode::~YACSPrs_ServiceNode()
94 int YACSPrs_ServiceNode::rtti() const
96 return 0;//YACSPrs_Canvas::Rtti_ServiceNode;
99 int YACSPrs_ServiceNode::getInfoHeight() const
101 return getTitleHeight() + NODE_SPACE +
102 getServiceHeight() + NODE_SPACE +
103 getComponentHeight() + NODE_SPACE +
104 getMachineHeight() + NODE_SPACE +
108 int YACSPrs_ServiceNode::getServiceHeight() const
110 return myServiceHeight;
113 int YACSPrs_ServiceNode::getComponentHeight() const
115 return myComponentHeight;
118 int YACSPrs_ServiceNode::getMachineHeight() const
120 return myMachineHeight;
123 QRect YACSPrs_ServiceNode::getServiceRect() const
125 QRect aPMRect = getPixmapRect(true,true);
126 int width = getTitleRect().width() - aPMRect.width() - NODE_MARGIN;
127 return QRect(aPMRect.right() + NODE_MARGIN, getTitleRect().bottom()+NODE_SPACE,
128 width, getServiceHeight());
131 QRect YACSPrs_ServiceNode::getComponentRect() const
133 QRect aPMRect = getPixmapRect(true,true);
134 int width = getTitleRect().width() - aPMRect.width() - NODE_MARGIN;
135 return QRect(aPMRect.right() + NODE_MARGIN, getServiceRect().bottom()+NODE_SPACE,
136 width, getComponentHeight());
139 QRect YACSPrs_ServiceNode::getMachineRect() const
141 QRect aPMRect = getPixmapRect(true,true);
142 int width = getTitleRect().width() - aPMRect.width() - NODE_MARGIN;
143 return QRect(aPMRect.right() + NODE_MARGIN, getComponentRect().bottom()+NODE_SPACE,
144 width, getMachineHeight());
147 QRect YACSPrs_ServiceNode::getStatusRect() const
149 QRect aPMRect = getPixmapRect(true,true);
150 int width = getTitleRect().width() - aPMRect.width() - NODE_MARGIN;
151 return QRect(aPMRect.right() + NODE_MARGIN, getMachineRect().bottom()+NODE_SPACE,
152 width, getStatusHeight());
155 QRect YACSPrs_ServiceNode::getWholeRect() const
157 return QRect(getStatusRect().topLeft()+QPoint(getStatusRect().width()/3+3,3),
158 getStatusRect().bottomRight()-QPoint(3,3));
161 QRect YACSPrs_ServiceNode::getPercentRect() const
163 int aPercentageW = (int)(getWholeRect().width()*( (getStoredPercentage() < 0) ? getPercentage() : getStoredPercentage() )/100.);
164 return QRect(getWholeRect().topLeft(), getWholeRect().bottomLeft()+QPoint(aPercentageW,0));
168 Update service, component, machine
170 void YACSPrs_ServiceNode::updateInfo()
175 void YACSPrs_ServiceNode::drawTitleShape(QPainter& thePainter)
177 // draw information: title, service, component, machine, status
178 int aXRnd = getTitleRect().width()*myXRnd/getServiceRect().width();
179 int aYRnd = getTitleRect().height()*myYRnd/TITLE_HEIGHT;
181 QPen savedP = thePainter.pen();
182 thePainter.setPen(thePainter.brush().color().dark(140));
185 thePainter.drawRoundRect(getTitleRect(),myXRnd,myYRnd);
187 thePainter.drawRoundRect(getServiceRect(),aXRnd,aYRnd);
189 thePainter.drawRoundRect(getComponentRect(),aXRnd,aYRnd);
191 thePainter.drawRoundRect(getMachineRect(),aXRnd,aYRnd);
193 thePainter.drawRoundRect(getStatusRect(),aXRnd,aYRnd);
196 thePainter.setPen(NoPen);
198 QBrush savedB = thePainter.brush();
200 thePainter.setBrush(savedB.color().light(130));
201 thePainter.drawRect(getWholeRect());
203 if ( getPercentRect().width() > 1 ) {
204 thePainter.setBrush(savedB.color().dark(160));
205 thePainter.drawRect(getPercentRect());
208 thePainter.setBrush(savedB);
211 thePainter.setPen(Qt::white);
213 ServiceNode* aSEngine = dynamic_cast<ServiceNode*>( myEngine );
214 drawText1(thePainter, QString(myEngine->getName()), getTitleRect(), Qt::AlignLeft);
215 drawText1(thePainter, QString( "Service: ") + QString( aSEngine ? aSEngine->getMethod() : "..." ), getServiceRect(), Qt::AlignLeft);
216 drawText1(thePainter, QString( "Component: " ) + QString( aSEngine ? aSEngine->getComponent()->getName() : "..." ), getComponentRect(), Qt::AlignLeft);
217 drawText1(thePainter, QString("Machine: ..."), getMachineRect(), Qt::AlignLeft);
219 int aMidX = getTitleRect().right()-getTitleRect().width()/2;
220 thePainter.drawLine(aMidX, getStatusRect().top()+2, aMidX, getStatusRect().bottom()-2);
222 QRect aStateRect(getStatusRect().x(), getStatusRect().y(), aMidX-getStatusRect().left(), TITLE_HEIGHT);
223 QRect aTimeRect(aMidX, getStatusRect().y(), 2*getStatusRect().width()/3, TITLE_HEIGHT);
225 drawText1(thePainter, myStatus, aStateRect, Qt::AlignLeft);
226 drawText1(thePainter, myTime, aTimeRect, Qt::AlignLeft);
227 drawText1(thePainter, QString::number(( (getStoredPercentage() < 0) ? getPercentage() : getStoredPercentage() ))+QString("%"), aTimeRect, Qt::AlignRight); // percentage
229 thePainter.setPen(savedP);
232 thePainter.setBrush(NoBrush);
234 aXRnd = getTitleRect().width()*myXRnd/getPixmapRect(true,true).width();
235 aYRnd = getTitleRect().height()*myYRnd/getPixmapRect(true,true).height();
236 thePainter.drawRoundRect(getPixmapRect(true,true),aXRnd,aYRnd);
237 QRect aPRect = getPixmapRect(true,true);
238 aPRect.setX(aPRect.x()+PIXMAP_MARGIN+2);
239 aPRect.setY(aPRect.y()+PIXMAP_MARGIN);
240 aPRect.setWidth(aPRect.width()-2*PIXMAP_MARGIN);
241 aPRect.setHeight(aPRect.height()-2*PIXMAP_MARGIN);
242 thePainter.drawPixmap(aPRect,myStatePixmap);
244 thePainter.setBrush(savedB);
247 QString YACSPrs_ServiceNode::getToolTipText(const QPoint& theMousePos, QRect& theRect) const
249 // Check if the tooltip for ports is needed
250 if (getBodyRect().contains(theMousePos, true) || getGateRect().contains(theMousePos, true))
251 return YACSPrs_ElementaryNode::getToolTipText(theMousePos,theRect);
253 // Return tooltip text for node
254 QString aText = QString("");
255 aText += QString("Name: %1\n").arg(getEngine()->getName());
256 aText += QString("Type: %1\n").arg("Service node");
257 theRect = getTitleRect();
258 theRect = theRect.unite(getServiceRect());
259 theRect = theRect.unite(getComponentRect());
260 theRect = theRect.unite(getMachineRect());
261 theRect = theRect.unite(getStatusRect());
262 theRect = theRect.unite(getPixmapRect());