/* -*- C++ -*- This file is part of ViPEC Copyright (C) 1991-2001 Johan Rossouw (jrossouw@alcatel.altech.co.za) This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include #include #include #include #include #include "../images/block1port.xpm" #include QPixmap* Block1Port::pixmap_ = 0; //----------------------------------------------------------------- Block1Port::Block1Port( const QPoint& center ) : Component( center ), schematicData_(0), fileData_(0) {} //----------------------------------------------------------------- Block1Port::~Block1Port() {} //----------------------------------------------------------------- const QString& Block1Port::getCatagory() const { return Strings::BlockCatagory; } //----------------------------------------------------------------- const QString& Block1Port::getName() const { return Strings::Block1PortName; } //----------------------------------------------------------------- const QPixmap& Block1Port::getPixmap() const { if (!pixmap_) { pixmap_ = new QPixmap(block1port_xpm); } return *pixmap_; } //----------------------------------------------------------------- void Block1Port::initComponent() { boundingRect_ = QRect(-32, -32, 64, 64); addNode( 0, -32 ); addAttribute( Strings::AttrBlockname, "NAME" ); } //----------------------------------------------------------------- void Block1Port::drawSymbol(QPainter* p) { p->drawRect(-16,-24,32,32); p->drawLine( 0,-32, 0, -24); p->moveTo(0,8); p->lineTo(0,24); p->moveTo(-2,22); p->lineTo(2,22); p->moveTo(-4,20); p->lineTo(4,20); p->moveTo(-6,18); p->lineTo(6,18); p->save(); p->setPen( Qt::black ); QPoint point(-24,-4); VectorFont::instance()->draw('1', p, point ); p->restore(); } //----------------------------------------------------------------- bool Block1Port::initSweep() { QString name = name_; Attribute* attr = findAttribute( "NAME" ); ASSERT( attr ); name_ = attr->value_; bool changed = ( name == name_ ); //If data is from file, trash it. We do not check for file //updates at the moment if ( fileData_ ) { changed = TRUE; fileData_ = 0; } schematicData_ = 0; return changed; } //----------------------------------------------------------------- void Block1Port::addToAdmittanceMatrix( TReal freq, Matrix* yn ) { if ( (schematicData_ == 0) && (fileData_ == 0)) { Schematic* schematic = 0; schematic = MainWindow::instance()->getSchematic( name_ ); if ( schematic ) { if ( !schematic->isSolved() ) { Vector& frequencies = Setup::instance()->getFrequencyVector(); schematic->sweep( frequencies ); } if ( schematic->getNumberOfPorts() != 1) { throw Exception::NumberOfPortsDoesNotMatch(); } schematicData_ = &(schematic->getYData()); } else { //Not a schematic, so try to find a file with this name fileData_ = MainWindow::instance()->getFileData( name_ ); if ( fileData_ == 0 ) { throw Exception::NoSuchBlock(); } } } ASSERT( (schematicData_ != 0) || (fileData_ != 0) ); //Find data in set Matrix data; if ( schematicData_ != 0) { Utils::findParametersInData( freq, *schematicData_, data ); } else { Utils::findParametersInData( freq, *fileData_, data ); } //Add to nodal matrix yn->insertComponent( data(0,0), node(0)->getNodeNumber(), 0 ); }