| 1 |
//--------------------------------------------------------------------------- |
| 2 |
// Bit Information |
| 3 |
//--------------------------------------------------------------------------- |
| 4 |
#include <stdlib.h> |
| 5 |
#include "QBitbox.h" |
| 6 |
//--------------------------------------------------------------------------- |
| 7 |
QBitbox::QBitbox(int index) :QCircuit(0,index) { |
| 8 |
Name = GetTypeStr(); |
| 9 |
Text = "|0>"; |
| 10 |
Index = index; |
| 11 |
Enabled = true; |
| 12 |
state = BIT_DOWN; |
| 13 |
} |
| 14 |
//--------------------------------------------------------------------------- |
| 15 |
QBitbox::QBitbox(int x, int y, string Param) :QCircuit(0,y) { |
| 16 |
Name = GetTypeStr(); |
| 17 |
Text = "|0>"; |
| 18 |
Index = y; |
| 19 |
Enabled = true; |
| 20 |
state = BIT_DOWN; |
| 21 |
SetState(atoi(Param.c_str())); |
| 22 |
} |
| 23 |
//--------------------------------------------------------------------------- |
| 24 |
void |
| 25 |
QBitbox::Draw(QDraw *qDraw) { |
| 26 |
int GridSize = qDraw->GetGridSize(); |
| 27 |
int UnitSize = qDraw->GetUnitSize(); |
| 28 |
int d = (GridSize-UnitSize)/2; |
| 29 |
int x1 = d; |
| 30 |
int y1 = Index * GridSize+d; |
| 31 |
int x2 = x1 + UnitSize; |
| 32 |
int y2 = y1 + UnitSize; |
| 33 |
|
| 34 |
qDraw->SetBrushColor(clWhite); |
| 35 |
qDraw->FillRect(x1,y1,x2,y2); |
| 36 |
|
| 37 |
if (!Enabled) { |
| 38 |
qDraw->SetBrushColor(clRed); |
| 39 |
} else { |
| 40 |
qDraw->SetBrushColor(clBlack); |
| 41 |
} |
| 42 |
|
| 43 |
qDraw->FrameRect(x1,y1,x2,y2); |
| 44 |
|
| 45 |
qDraw->SetBrushColor(clWhite); |
| 46 |
ostringstream os; |
| 47 |
os << "|" << state << ">"; |
| 48 |
qDraw->TextOut(x1+UnitSize/2,y1+UnitSize/2,os.str()); |
| 49 |
} |
| 50 |
//--------------------------------------------------------------------------- |
| 51 |
string |
| 52 |
QBitbox::GetCalcText(void) { |
| 53 |
if (state == BIT_DOWN) { |
| 54 |
return "blank"; |
| 55 |
} |
| 56 |
ostringstream os; |
| 57 |
os << "NOT(q[" << Y << "])"; |
| 58 |
return os.str(); |
| 59 |
} |
| 60 |
//--------------------------------------------------------------------------- |
| 61 |
void |
| 62 |
QBitbox::DrawPS(QPSDraw *psDraw) { |
| 63 |
|
| 64 |
if (!Enabled) |
| 65 |
return; |
| 66 |
int GridSize = psDraw->GetGridSize(); |
| 67 |
int UnitSize = psDraw->GetUnitSize(); |
| 68 |
int d = (GridSize-UnitSize)/2; |
| 69 |
int x1 = d; |
| 70 |
int y1 = Index * GridSize+d; |
| 71 |
|
| 72 |
psDraw->FillRect(GridSize*X,GridSize*Y,GridSize*X+GridSize,GridSize*Y+GridSize); |
| 73 |
psDraw->TextOut(x1+UnitSize/2,y1+UnitSize/2,Text.c_str()); |
| 74 |
} |
| 75 |
//--------------------------------------------------------------------------- |
| 76 |
string |
| 77 |
QBitbox::GetParam(void) { |
| 78 |
ostringstream os; |
| 79 |
os << state; |
| 80 |
return os.str(); |
| 81 |
} |
| 82 |
//--------------------------------------------------------------------------- |
| 83 |
void |
| 84 |
QBitbox::Reverse(int y) { |
| 85 |
Index = y - Index; |
| 86 |
Y = y - Y; |
| 87 |
} |
| 88 |
//--------------------------------------------------------------------------- |
| 89 |
TRect |
| 90 |
QBitbox::GetOccupiedRect() { |
| 91 |
return TRect(X, Y, X + 1, Y + 1); |
| 92 |
} |
| 93 |
//--------------------------------------------------------------------------- |
| 94 |
void |
| 95 |
QBitbox::SetState(int st) { |
| 96 |
state = st; |
| 97 |
if (state == BIT_DOWN) { |
| 98 |
Text = "|0>"; |
| 99 |
} else { |
| 100 |
Text = "|1>"; |
| 101 |
} |
| 102 |
} |
| 103 |
//--------------------------------------------------------------------------- |
| 104 |
int |
| 105 |
QBitbox::GetState() { |
| 106 |
return state; |
| 107 |
} |
| 108 |
//--------------------------------------------------------------------------- |
| 109 |
QCircuit* |
| 110 |
QBitbox::Clone() { |
| 111 |
QBitbox *qb = new QBitbox(Index); |
| 112 |
qb->SetState(GetState()); |
| 113 |
qb->Enabled = Enabled; |
| 114 |
return (QCircuit*)qb; |
| 115 |
} |
| 116 |
//--------------------------------------------------------------------------- |
| 117 |
|