My Project  0.0.16
QUCS Mapping
 All Classes Namespaces 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 
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(QPen::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(QPen::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 }