⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 module.cpp

📁 This a framework to test new ideas in transmission technology. Actual development is a LDPC-coder in
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*******************************************************************************//*  Project:        SOFTWARE RADIO - LCM Laboratoire de Communications Mobiles *//*  -------------------------------------------------------------------------- *//*  Filename:       module.cpp                                                 *//*  Description:    Class implementing a module -- a subsystem of the software *//*                  radio system.                                              *//*  -------------------------------------------------------------------------- *//*  Date:           January 09 2003                                            *//*  Version:        v1.0                                                       *//*  Author:         Braure Jerome, Ferreiro Jose                               *//*                  Communication Systems (9th semester) - EPFL                *//*  Changelog:    04/03/01 - ineiti - Adjust box-sizes for different fonts                        Adjust font-size for larger strings    04/05/13 - ineiti - Cleaned up font-sizing                        Added profiling-information*//*******************************************************************************//*******************************************************************************//*  This program is free software; you can redistribute it and/or modify it    *//*  under the terms of the GNU General Public License as published by the Free *//*  Software Foundation; either version 2 of the License, or (at your option)  *//*  any later version.                                                         *//*******************************************************************************/#include <qapplication.h>#include <qfont.h>#include <qlayout.h>#include "module.h"#include "defines.h"#include "parameter_types.h"#include "parameters.h"#include "global.h"#include "mainsub.h"#include "image.h"#include "show.h"#include "confwind.h"/*******************************************************************************//* Function:    Module() - (constuctor)                                        *//* Description: Constructs an instance of class Module.                        *//* Inputs:      name:             [optional] name of the module: this string   *//*                                is the one that is displayed on the GUI.     *//*              number:           [optional] number of the module: this number *//*                                corresponds to the directory's name in /sdb/.*//*              greatestPortUsed: [optional] max{portNb : port is used}.       *//*******************************************************************************/Module::Module( FifoCmd *r, QCanvas *ca, int i, bool t ):  radio(r), canvas( ca ), id(i), isThin( t ){    if ( !canvas ){    cout << "Module needs a real canvas\n";    exit(1);  }  name = radio->getName( id );  configWin = NULL;  portList.setAutoDelete( true );  statsList.setAutoDelete( true );  configList.setAutoDelete( true );  inputFeet.setAutoDelete( true );  outputFeet.setAutoDelete( true );  profValues[0] = qMakePair( 0LL, 0LL );  profValues[1] = qMakePair( 0LL, -1LL );  width = MODULE_MIN_WIDTH;  height = MODULE_MIN_HEIGHT;  canvasFont = QFont( "Helvetica", 10 );  // In profiling-mode, we need one more line  double lines = isProfiling ? 4.5 : 3.5;  height = MAXIMUM( height,                    (int)( QFontMetrics( canvasFont ).height() * lines ) );  x = MODULE_LEFT_OFFSET;  y = MODULE_Y_INTERVAL;  // Set up config  QStringList config = radio->getConfig( id );  for ( uint index = 0; index < config.count(); index++ ){    int type;    unsigned long flags;    QStringList args( QStringList::split( ",", config[ index ] ) );    type = args[1].toInt();    flags = args[2].toULong();    if ( type == INT || type == DOUBLE || type == STRING128 ||	 type == COMPLEX || type == DOUBLE_COMPLEX ) {      configList.append( new Config( radio, id, index ) );    }  }  // Set up stats  memset( displayStats, 0, sizeof( Stats* ) * MAX_STATS_DISPLAY );  QStringList lStats = radio->getStats( id );  int statsCnt = 0;  for ( uint index = 0; index < lStats.count(); index++ ){    int type;    unsigned long flags;    QStringList args( QStringList::split( ",", lStats[ index ] ) );    type = args[1].toInt();    flags = args[2].toULong();    if ( type != UNDEFINED ){      // type = INT, DOUBLE, STRING128, COMPLEX, BLOCK or IMAGE      Stats *stats = new Stats( radio, id, index );      statsList.append( stats );      if ( stats->isShown() && stats->isValue() ){	if ( statsCnt < MAX_STATS_DISPLAY ){	  displayStats[ statsCnt++ ] = stats;	}      }    }  }  // Get number of inputs  QStringList inputs = radio->getInputs( id );  numberIn = inputs.count();  for ( int in = 0; in < numberIn; in++ ){    inputFeet.append( new QCanvasRectangle( 0, 0, LEG_WIDTH, LEG_LENGTH,					    canvas ) );    inputFeet.at(in)->setPen( QPen( LEG_COLOR ) );    inputFeet.at(in)->setBrush( QBrush( LEG_COLOR ) );  }  // Get outputs  QStringList outputs = radio->getOutputs( id );  numberOut = outputs.count();  for ( int out=0; out < numberOut; out++ ){    addPort( new Port( radio, id, out ) );    outputFeet.append( new QCanvasRectangle( 0, 0, LEG_WIDTH, LEG_LENGTH,					     canvas ) );    outputFeet.at(out)->setPen( QPen( LEG_COLOR ) );    outputFeet.at(out)->setBrush( QBrush( LEG_COLOR ) );  }  // Set up canvas-stuff  canvasRectangle = new QCanvasRectangle( 0, 0, 0, 0, canvas );  canvasText = new QCanvasText( canvas );  reset();}Module::~Module(){  delete( canvasRectangle );  delete( canvasText );}/*******************************************************************************//* Function:    setX()                                                         *//* Description: Sets the x coordinate of the module (upper left corner) to the *//*              given number while keeping the original width.                 *//* Inputs:      x: x coordinate on the canvas.                                 *//* Returns:     void.                                                          *//*******************************************************************************/void Module::setX( int x ) {  this->x = x;}/*******************************************************************************//* Function:    setY()                                                         *//* Description: Sets the y coordinate of the module (upper left corner) to the *//*              given number while keeping the original height.                *//* Inputs:      y: y coordinate on the canvas.                                 *//* Returns:     void.                                                          *//*******************************************************************************/void Module::setY( int y ) {  this->y = y;}/*******************************************************************************//* Function:    setNumberIn()                                                  *//* Description: Sets the number of input ports and how many of them are        *//*              effectively in use (connected to an existing module).          *//* Inputs:      numberOfPorts:     total number of input ports.                *//*              numberOfPortsUsed: number of input ports that are used.        *//* Returns:     void.                                                          *//*******************************************************************************/void Module::setNumberIn( int numberOfPorts, int numberOfPortsUsed ) {  if ( numberOfPorts > 128 ) {    cout << "Asking for more than 128 input-ports !?!\n" << endl;    numberOfPorts = 0;  }  numberIn = numberOfPorts;  numberInUsed = numberOfPortsUsed;  inLinkSpace = ( int ) ( numberInUsed - 0.5 ) * LINK_Y_INTERVAL;}/*******************************************************************************//* Function:    setNumberOut()                                                 *//* Description: Sets the number of output ports and how many of them are       *//*              effectively in use (connected to an existing module).          *//* Inputs:      numberOfPorts:     total number of output ports.               *//*              numberOfPortsUsed: number of output ports that are used.       *//* Returns:     void.                                                          *//*******************************************************************************/void Module::setNumberOut( int numberOfPorts, int numberOfPortsUsed ) {  if ( numberOfPorts > 128 ) {    cout << "Asking for more than 128 output-ports !?!\n" << endl;    numberOfPorts = 0;  }  numberOut = numberOfPorts;  numberOutUsed = numberOfPortsUsed;  outLinkSpace = ( int ) ( numberOutUsed - 0.5 ) * LINK_Y_INTERVAL;}/*******************************************************************************//* Function:    updateFont()                                                   *//* Description: Updates the font-size so that the line fits in                 *//* Inputs:      s: the new line                                                *//* Returns:     s                                                              *//*******************************************************************************/QString Module::updateFont( QString s ){  while ( QFontMetrics( canvasFont ).width( s ) > width - 10 ){    if ( canvasFont.pointSize() < 2 ){      break;    }    canvasFont.setPointSize( canvasFont.pointSize() - 1 );  }    return s;}bool Module::reset(){  if ( radio->getName( id ).isEmpty() ){    return false;  }  visible = false;  zone = -1;  inLinkSpace = 0;  outLinkSpace = 0;  upperNeighbor = lowerNeighbor = -1;  inputLinkVect.clear();  outputLinkVect.clear();  if ( !isThin ){    // In profiling-mode, we need one more line    double lines = isProfiling ? 2.5 : 1.5;    lines += MAX_STATS_DISPLAY;    height = MAXIMUM( height, 		      (int)( QFontMetrics( canvasFont ).height() * lines ) );    legInterval = LEG_INTERVAL;  }  greatestPortUsed = 0;  // Get inputs  QStringList inputs = radio->getInputs( id );  numberInUsed = 0;  greatestPortUsed = MAXIMUM( numberIn, greatestPortUsed );  for ( int toPort=0; toPort < numberIn; toPort++ ){    QStringList args( QStringList::split( ",", inputs[ toPort ] ) );        int fromModule = args[0].toInt();    int fromPort = args[1].toInt();    if ( fromModule >= 0 ){      numberInUsed++;    }    addInputLink( new IOLink( fromModule, fromPort, id, toPort ) );  }  // Get outputs  QStringList outputs = radio->getOutputs( id );  numberOutUsed = 0;  greatestPortUsed = MAXIMUM( numberOut, greatestPortUsed );  for ( int fromPort=0; fromPort < numberOut; fromPort++ ){    QStringList args( QStringList::split( ",", outputs[ fromPort ] ) );    int toModule = args[0].toInt();    int toPort = args[1].toInt();    if ( toModule >= 0 ){      numberOutUsed++;    }    addOutputLink( new IOLink( id, fromPort, toModule, toPort ) );  }  // Update stats  for ( uint s=0; s<statsList.count(); s++ ){    statsList.at(s)->update();  }  return true;}void Module::hide(){  canvasText->hide();  canvasRectangle->hide();  for ( uint in=0; in<inputFeet.count(); in++ ){    inputFeet.at(in)->hide();  }  for ( uint out=0; out<outputFeet.count(); out++ ){    outputFeet.at(out)->hide();  }}/*******************************************************************************//* Function:    show()                                                         *//* Description: Draws the module on the canvas.                                *//* Returns:     void.                                                          *//*******************************************************************************/void Module::show( ) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -