00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "blockSchema.h"
00024 #include <assert.h>
00025
00026 using namespace std;
00027
00028 static double quantize(int n)
00029 {
00030 int q = 3;
00031 return dLetter * (q *((n+q-1)/q));
00032 }
00033
00040 schema* makeBlockSchema ( unsigned int inputs,
00041 unsigned int outputs,
00042 const string& text,
00043 const string& color,
00044 const string& link )
00045 {
00046
00047 double minimal = 3*dWire;
00048 double w = 2*dHorz + max( minimal, quantize(text.size()) );
00049 double h = 2*dVert + max( minimal, max(inputs, outputs) * dWire );
00050
00051 return new blockSchema(inputs, outputs, w, h, text, color, link);
00052 }
00053
00060 blockSchema::blockSchema ( unsigned int inputs,
00061 unsigned int outputs,
00062 double width,
00063 double height,
00064 const string& text,
00065 const string& color,
00066 const string& link )
00067
00068 : schema( inputs, outputs, width, height ),
00069 fText(text),
00070 fColor(color),
00071 fLink(link)
00072 {
00073 for (unsigned int i=0; i<inputs; i++) fInputPoint.push_back(point(0));
00074 for (unsigned int i=0; i<outputs; i++) fOutputPoint.push_back(point(0));
00075 }
00076
00082 void blockSchema::place(double x, double y, int orientation)
00083 {
00084 beginPlace(x, y, orientation);
00085
00086 placeInputPoints();
00087 placeOutputPoints();
00088
00089 endPlace();
00090 }
00091
00095 point blockSchema::inputPoint(unsigned int i) const
00096 {
00097 assert (placed());
00098 assert (i < inputs());
00099 return fInputPoint[i];
00100 }
00101
00105 point blockSchema::outputPoint(unsigned int i) const
00106 {
00107 assert (placed());
00108 assert (i < outputs());
00109 return fOutputPoint[i];
00110 }
00111
00116 void blockSchema::placeInputPoints()
00117 {
00118 int N = inputs();
00119
00120 if (orientation() == kLeftRight) {
00121
00122 double px = x();
00123 double py = y() + (height() - dWire*(N-1))/2;
00124
00125 for (int i=0; i<N; i++) {
00126 fInputPoint[i] = point(px, py+i*dWire);
00127 }
00128
00129 } else {
00130
00131 double px = x() + width();
00132 double py = y() + height() - (height() - dWire*(N-1))/2;
00133
00134 for (int i=0; i<N; i++) {
00135 fInputPoint[i] = point(px, py-i*dWire);
00136 }
00137 }
00138 }
00139
00140
00145 void blockSchema::placeOutputPoints()
00146 {
00147 int N = outputs();
00148
00149 if (orientation() == kLeftRight) {
00150
00151 double px = x() + width();
00152 double py = y() + (height() - dWire*(N-1))/2;
00153
00154 for (int i=0; i<N; i++) {
00155 fOutputPoint[i] = point(px, py + i*dWire);
00156 }
00157
00158 } else {
00159
00160 double px = x();
00161 double py = y() + height() - (height() - dWire*(N-1))/2;
00162
00163 for (int i=0; i<N; i++) {
00164 fOutputPoint[i] = point(px, py - i*dWire);
00165 }
00166 }
00167 }
00168
00169
00174 void blockSchema::draw(device& dev)
00175 {
00176 assert(placed());
00177
00178 drawRectangle(dev);
00179 drawText(dev);
00180 drawOrientationMark(dev);
00181 drawInputWires(dev);
00182 drawOutputWires(dev);
00183 }
00184
00188 void blockSchema::drawRectangle(device& dev)
00189 {
00190 dev.rect( x() + dHorz,
00191 y() + dVert,
00192 width() - 2*dHorz,
00193 height() - 2*dVert,
00194 fColor.c_str(),
00195 fLink.c_str()
00196 );
00197 }
00198
00199
00203 void blockSchema::drawText(device& dev)
00204 {
00205 dev.text( x() + width()/2,
00206 y() + height()/2,
00207 fText.c_str()
00208 );
00209 }
00210
00215 void blockSchema::drawOrientationMark(device& dev)
00216 {
00217 double px, py;
00218
00219 if (orientation() == kLeftRight) {
00220 px = x() + dHorz;
00221 py = y() + dVert;
00222 } else {
00223 px = x() + width() - dHorz;
00224 py = y() + height() - dVert;
00225 }
00226
00227 dev.markSens( px, py, orientation() );
00228 }
00229
00234 void blockSchema::drawInputWires(device& dev)
00235 {
00236 double dx = (orientation() == kLeftRight) ? dHorz : -dHorz;
00237
00238 for (unsigned int i=0; i<inputs(); i++) {
00239 point p = fInputPoint[i];
00240 dev.trait(p.x, p.y, p.x+dx, p.y);
00241 dev.fleche(p.x+dx, p.y, 0, orientation());
00242 }
00243 }
00244
00249 void blockSchema::drawOutputWires(device& dev)
00250 {
00251 double dx = (orientation() == kLeftRight) ? dHorz : -dHorz;
00252
00253 for (unsigned int i=0; i<outputs(); i++) {
00254 point p = fOutputPoint[i];
00255 dev.trait(p.x, p.y, p.x-dx, p.y);
00256 }
00257 }
00258
00259