Qucs-GUI  0.0.18
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
node.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  node.cpp - description
3  -------------------
4  begin : Sat Sep 20 2003
5  copyright : (C) 2003 by Michael Margraf
6  email : michael.margraf@alumni.tu-berlin.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 #include <QtGui>
18 #include "node.h"
19 
20 #include "viewpainter.h"
21 #include "wirelabel.h"
22 
23 Node::Node(int _x, int _y)
24 {
25  Label = 0;
26  Type = isNode;
27  State = 0;
28  DType = "";
29 
30  cx = _x;
31  cy = _y;
32 }
33 
35 {
36 }
37 
38 // -------------------------------------------------------------
40 {
41  switch(Connections.count()) {
42  case 1: if(Label)
43  p->fillRect(cx-2, cy-2, 4, 4, Qt::darkBlue); // open but labeled
44  else {
45  p->Painter->setPen(QPen(Qt::red,1)); // node is open
46  p->drawEllipse(cx-4, cy-4, 8, 8);
47  }
48  return;
49  case 2: if(Connections.getFirst()->Type == isWire)
50  if(Connections.getLast()->Type == isWire) return;
51  p->fillRect(cx-2, cy-2, 4, 4, Qt::darkBlue);
52  break;
53  default: p->Painter->setBrush(Qt::darkBlue); // more than 2 connections
54  p->Painter->setPen(QPen(Qt::darkBlue,1));
55  p->drawEllipse(cx-3, cy-3, 6, 6);
56  p->Painter->setBrush(Qt::NoBrush);
57  break;
58  }
59 }
60 
61 // ----------------------------------------------------------------
62 bool Node::getSelected(int x_, int y_)
63 {
64  if(cx-5 <= x_) if(cx+5 >= x_) if(cy-5 <= y_) if(cy+5 >= y_)
65  return true;
66 
67  return false;
68 }
69 
70 // ----------------------------------------------------------------
71 void Node::setName(const QString& Name_, const QString& Value_, int x_, int y_)
72 {
73  if(Name_.isEmpty() && Value_.isEmpty()) {
74  if(Label) delete Label;
75  Label = 0;
76  return;
77  }
78 
79  if(!Label) Label = new WireLabel(Name_, cx, cy, x_, y_, isNodeLabel);
80  else Label->setName(Name_);
81  Label->pOwner = this;
82  Label->initValue = Value_;
83 }
QPainter * Painter
Definition: viewpainter.h:58
int Type
Definition: element.h:152
void setName(const QString &, const QString &, int x_=0, int y_=0)
Definition: node.cpp:71
QString DType
Definition: node.h:41
#define isNodeLabel
Definition: element.h:126
void paint(ViewPainter *)
Definition: node.cpp:39
int State
Definition: node.h:42
void setName(const QString &Name_)
Definition: wirelabel.cpp:196
int cx
Definition: element.h:153
void fillRect(int, int, int, int, const QColor &)
Q3PtrList< Element > Connections
Definition: node.h:39
bool getSelected(int, int)
Definition: node.cpp:62
~Node()
Definition: node.cpp:34
Conductor * pOwner
Definition: wirelabel.h:42
int cy
Definition: element.h:153
WireLabel * Label
Definition: element.h:163
Node(int, int)
Definition: node.cpp:23
#define isWire
Definition: element.h:118
QString initValue
Definition: wirelabel.h:46
void drawEllipse(int, int, int, int)
#define isNode
Definition: element.h:116