Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/components/logical_buf.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                               logical_buf.cpp
00003                              -----------------
00004     begin                : Sat Nov 8 2008
00005     copyright            : (C) 2008 by Stefan Jahn
00006     email                : stefan@lkcc.org
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 "logical_buf.h"
00018 #include "schematic.h"
00019 #include "node.h"
00020 #include "misc.h"
00021 
00022 
00023 Logical_Buf::Logical_Buf()
00024 {
00025   Type = isComponent;   // both analog and digital
00026   Description = QObject::tr("logical buffer");
00027 
00028   // the list order must be preserved !!!
00029   Props.append(new Property("V", "1 V", false,
00030     QObject::tr("voltage of high level")));
00031   Props.append(new Property("t", "0", false,
00032     QObject::tr("delay time")));
00033   Props.append(new Property("TR", "10", false,
00034     QObject::tr("transfer function scaling factor")));
00035 
00036   // this must be the last property in the list !!!
00037   Props.append(new Property("Symbol", "old", false,
00038     QObject::tr("schematic symbol")+" [old, DIN40900]"));
00039 
00040   createSymbol();
00041   tx = x1+4;
00042   ty = y2+4;
00043   Model = "Buf";
00044   Name  = "Y";
00045 }
00046 
00047 // -------------------------------------------------------
00048 QString Logical_Buf::vhdlCode(int NumPorts)
00049 {
00050   QString s = "  " + Ports.first()->Connection->Name + " <= " +
00051               Ports.last()->Connection->Name;
00052 
00053   if(NumPorts <= 0) { // no truth table simulation ?
00054     QString td = Props.at(1)->Value;
00055     if(!misc::VHDL_Delay(td, Name)) return td;
00056     s += td;
00057   }
00058 
00059   s += ";\n";
00060   return s;
00061 }
00062 
00063 // -------------------------------------------------------
00064 QString Logical_Buf::verilogCode(int NumPorts)
00065 {
00066   bool synthesize = true;
00067   Port *pp = Ports.at(0);
00068   QString s ("");
00069 
00070   if (synthesize) {
00071     s = "  assign";
00072 
00073     if(NumPorts <= 0) { // no truth table simulation ?
00074       QString td = Props.at(1)->Value;
00075       if(!misc::Verilog_Delay(td, Name)) return td;
00076       s += td;
00077     }
00078     s += " ";
00079     s += pp->Connection->Name + " = ";  // output port
00080     pp = Ports.at(1);
00081     s += pp->Connection->Name;          // input port
00082     s += ";\n";
00083   }
00084   return s;
00085 }
00086 
00087 // -------------------------------------------------------
00088 void Logical_Buf::createSymbol()
00089 {
00090   int xr;
00091 
00092   if(Props.getLast()->Value.at(0) == 'D') {  // DIN symbol
00093     Lines.append(new Line( 15,-20, 15, 20,QPen(Qt::darkBlue,2)));
00094     Lines.append(new Line(-15,-20, 15,-20,QPen(Qt::darkBlue,2)));
00095     Lines.append(new Line(-15, 20, 15, 20,QPen(Qt::darkBlue,2)));
00096     Lines.append(new Line(-15,-20,-15, 20,QPen(Qt::darkBlue,2)));
00097 
00098     Texts.append(new Text(-11,-17, "1", Qt::darkBlue, 15.0));
00099     xr =  15;
00100   }
00101   else {   // old symbol
00102     Lines.append(new Line(-10,-20,-10,20, QPen(Qt::darkBlue,2)));
00103     Arcs.append(new Arc(-30,-20, 40, 30,  0, 16*90,QPen(Qt::darkBlue,2)));
00104     Arcs.append(new Arc(-30,-10, 40, 30,  0,-16*90,QPen(Qt::darkBlue,2)));
00105     Lines.append(new Line( 10,-5, 10, 5,QPen(Qt::darkBlue,2)));
00106     xr =  10;
00107   }
00108 
00109   Lines.append(new Line( xr, 0, 30, 0, QPen(Qt::darkBlue,2)));
00110   Lines.append(new Line(-30, 0,-xr, 0, QPen(Qt::darkBlue,2)));
00111   Ports.append(new Port( 30, 0));
00112   Ports.append(new Port(-30, 0));
00113 
00114   x1 = -30; y1 = -23;
00115   x2 =  30; y2 =  23;
00116 }
00117 
00118 // -------------------------------------------------------
00119 Component* Logical_Buf::newOne()
00120 {
00121   Logical_Buf* p = new Logical_Buf();
00122   p->Props.getLast()->Value = Props.getLast()->Value;
00123   p->recreate(0);
00124   return p;
00125 }
00126 
00127 // -------------------------------------------------------
00128 Element* Logical_Buf::info(QString& Name, char* &BitmapFile, bool getNewOne)
00129 {
00130   Name = QObject::tr("Buffer");
00131   BitmapFile = (char *) "buffer";
00132 
00133   if(getNewOne)  return new Logical_Buf();
00134   return 0;
00135 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines