Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/components/logical_inv.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                               logical_inv.cpp
00003                              -----------------
00004     begin                : Wed Sep 28 2005
00005     copyright            : (C) 2005 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 "logical_inv.h"
00018 #include "schematic.h"
00019 #include "node.h"
00020 #include "misc.h"
00021 
00022 
00023 Logical_Inv::Logical_Inv()
00024 {
00025   Type = isComponent;   // both analog and digital
00026   Description = QObject::tr("logical inverter");
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 = "Inv";
00044   Name  = "Y";
00045 }
00046 
00047 // -------------------------------------------------------
00048 QString Logical_Inv::vhdlCode(int NumPorts)
00049 {
00050   QString s = "  " + Ports.first()->Connection->Name + " <= not " +
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_Inv::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   else {
00085     s = "  not";
00086 
00087     if(NumPorts <= 0) { // no truth table simulation ?
00088       QString td = Props.at(1)->Value;
00089       if(!misc::Verilog_Delay(td, Name))
00090   return td;    // time has not VHDL format
00091       s += td;
00092     }
00093     s += " " + Name + " (" + pp->Connection->Name;  // output port
00094     pp = Ports.at(1);
00095     s += ", " + pp->Connection->Name; // first input port
00096     s += ");\n";
00097   }
00098   return s;
00099 }
00100 
00101 // -------------------------------------------------------
00102 void Logical_Inv::createSymbol()
00103 {
00104   int xr;
00105 
00106   if(Props.getLast()->Value.at(0) == 'D') {  // DIN symbol
00107     Lines.append(new Line( 15,-20, 15, 20,QPen(Qt::darkBlue,2)));
00108     Lines.append(new Line(-15,-20, 15,-20,QPen(Qt::darkBlue,2)));
00109     Lines.append(new Line(-15, 20, 15, 20,QPen(Qt::darkBlue,2)));
00110     Lines.append(new Line(-15,-20,-15, 20,QPen(Qt::darkBlue,2)));
00111 
00112     Texts.append(new Text(-11,-17, "1", Qt::darkBlue, 15.0));
00113     xr =  15;
00114   }
00115   else {   // old symbol
00116     Lines.append(new Line(-10,-20,-10,20, QPen(Qt::darkBlue,2)));
00117     Arcs.append(new Arc(-30,-20, 40, 30,  0, 16*90,QPen(Qt::darkBlue,2)));
00118     Arcs.append(new Arc(-30,-10, 40, 30,  0,-16*90,QPen(Qt::darkBlue,2)));
00119     Lines.append(new Line( 10,-5, 10, 5,QPen(Qt::darkBlue,2)));
00120     xr =  10;
00121   }
00122 
00123   Ellips.append(new Area(xr,-4, 8, 8,
00124                 QPen(Qt::darkBlue,0), QBrush(Qt::darkBlue)));
00125 
00126   Lines.append(new Line( xr, 0, 30, 0, QPen(Qt::darkBlue,2)));
00127   Lines.append(new Line(-30, 0,-xr, 0, QPen(Qt::darkBlue,2)));
00128   Ports.append(new Port( 30, 0));
00129   Ports.append(new Port(-30, 0));
00130 
00131   x1 = -30; y1 = -23;
00132   x2 =  30; y2 =  23;
00133 }
00134 
00135 // -------------------------------------------------------
00136 Component* Logical_Inv::newOne()
00137 {
00138   Logical_Inv* p = new Logical_Inv();
00139   p->Props.getLast()->Value = Props.getLast()->Value;
00140   p->recreate(0);
00141   return p;
00142 }
00143 
00144 // -------------------------------------------------------
00145 Element* Logical_Inv::info(QString& Name, char* &BitmapFile, bool getNewOne)
00146 {
00147   Name = QObject::tr("Inverter");
00148   BitmapFile = (char *) "inverter";
00149 
00150   if(getNewOne)  return new Logical_Inv();
00151   return 0;
00152 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines