Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/node.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           node.cpp  -  description
00003                              -------------------
00004     begin                : Sat Sep 20 2003
00005     copyright            : (C) 2003 by Michael Margraf
00006     email                : michael.margraf@alumni.tu-berlin.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 #include "node.h"
00018 
00019 #include "viewpainter.h"
00020 #include "wirelabel.h"
00021 
00022 #include <QPainter>
00023 
00024 Node::Node(int _x, int _y)
00025 {
00026   Label = 0;
00027   Type  = isNode;
00028   State = 0;
00029   DType = "";
00030 
00031   cx = _x;
00032   cy = _y;
00033 }
00034 
00035 Node::~Node()
00036 {
00037 }
00038 
00039 // -------------------------------------------------------------
00040 void Node::paint(ViewPainter *p)
00041 {
00042   switch(Connections.count()) {
00043     case 1:  if(Label)
00044                p->fillRect(cx-2, cy-2, 4, 4, Qt::darkBlue); // open but labeled
00045              else {
00046                p->Painter->setPen(QPen(Qt::red,1));  // node is open
00047                p->drawEllipse(cx-4, cy-4, 8, 8);
00048              }
00049              return;
00050     case 2:  if(Connections.getFirst()->Type == isWire)
00051                if(Connections.getLast()->Type == isWire) return;
00052              p->fillRect(cx-2, cy-2, 4, 4, Qt::darkBlue);
00053              break;
00054     default: p->Painter->setBrush(Qt::darkBlue);  // more than 2 connections
00055        p->Painter->setPen(QPen(Qt::darkBlue,1));
00056        p->drawEllipse(cx-3, cy-3, 6, 6);
00057        p->Painter->setBrush(Qt::NoBrush);
00058              break;
00059   }
00060 }
00061 
00062 // ----------------------------------------------------------------
00063 bool Node::getSelected(int x_, int y_)
00064 {
00065   if(cx-5 <= x_) if(cx+5 >= x_) if(cy-5 <= y_) if(cy+5 >= y_)
00066     return true;
00067 
00068   return false;
00069 }
00070 
00071 // ----------------------------------------------------------------
00072 void Node::setName(const QString& Name_, const QString& Value_, int x_, int y_)
00073 {
00074   if(Name_.isEmpty() && Value_.isEmpty()) {
00075     if(Label) delete Label;
00076     Label = 0;
00077     return;
00078   }
00079 
00080   if(!Label) Label = new WireLabel(Name_, cx, cy, x_, y_, isNodeLabel);
00081   else Label->setName(Name_);
00082   Label->pOwner = this;
00083   Label->initValue = Value_;
00084 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines