place and connect two diagrams in recursive composition More...
#include <recSchema.h>
Inherits schema.
Public Member Functions | |
virtual void | place (double ox, double oy, int orientation) |
The two subschema are placed centered vertically, s2 on top of s1. | |
virtual void | draw (device &dev) |
Draw the two subschema s1 and s2 as well as the feedback connections between s1 and s2, and the feedfrom connections beetween s2 and s1. | |
virtual point | inputPoint (unsigned int i) const |
The input points s1 ~ s2. | |
virtual point | outputPoint (unsigned int i) const |
The output points s1 ~ s2. | |
Private Member Functions | |
recSchema (schema *s1, schema *s2, double width) | |
Constructor of a recursive schema (s1 ~ s2). | |
void | drawDelaySign (device &dev, double x, double y, double size) |
Draw the delay sign of a feedback connection. | |
void | drawFeedback (device &dev, const point &src, const point &dst, double dx) |
Draw a feedback connection between two points with an horizontal displacement dx. | |
void | drawFeedfront (device &dev, const point &src, const point &dst, double dx) |
Draw a feedfrom connection between two points with an horizontal displacement dx. | |
Private Attributes | |
schema * | fSchema1 |
schema * | fSchema2 |
vector< point > | fInputPoint |
vector< point > | fOutputPoint |
Friends | |
schema * | makeRecSchema (schema *s1, schema *s2) |
Creates a new recursive schema (s1 ~ s2). |
place and connect two diagrams in recursive composition
Definition at line 33 of file recSchema.h.
Constructor of a recursive schema (s1 ~ s2).
The two components are supposed to have the same width.
Definition at line 48 of file recSchema.cpp.
References fInputPoint, fOutputPoint, schema::inputs(), schema::outputs(), and schema::width().
00049 : schema( s1->inputs() - s2->outputs(), 00050 s1->outputs(), 00051 width, 00052 s1->height() + s2->height() ), 00053 fSchema1(s1), 00054 fSchema2(s2) 00055 { 00056 // this version only accepts legal expressions of same width 00057 assert(s1->inputs() >= s2->outputs()); 00058 assert(s1->outputs() >= s2->inputs()); 00059 assert(s1->width() >= s2->width()); 00060 00061 // create the input and output points 00062 for (unsigned int i=0; i<inputs(); i++) fInputPoint.push_back(point(0)); 00063 for (unsigned int i=0; i<outputs(); i++) fOutputPoint.push_back(point(0)); 00064 00065 }
void recSchema::draw | ( | device & | dev | ) | [virtual] |
Draw the two subschema s1 and s2 as well as the feedback connections between s1 and s2, and the feedfrom connections beetween s2 and s1.
Implements schema.
Definition at line 130 of file recSchema.cpp.
References schema::draw(), drawFeedback(), drawFeedfront(), dWire, fSchema1, fSchema2, inputPoint(), schema::inputPoint(), schema::inputs(), outputPoint(), schema::outputPoint(), schema::outputs(), schema::placed(), device::trait(), point::x, and point::y.
00131 { 00132 assert(placed()); 00133 00134 // draw the two subdiagrams 00135 fSchema1->draw(dev); 00136 fSchema2->draw(dev); 00137 00138 // draw the output lines 00139 for (unsigned int i=0; i<outputs(); i++) { 00140 point p = fSchema1->outputPoint(i); 00141 point q = outputPoint(i); 00142 dev.trait(p.x, p.y, q.x, q.y); 00143 } 00144 00145 // draw the input lines 00146 unsigned int skip = fSchema2->outputs(); 00147 for (unsigned int i=0; i<inputs(); i++) { 00148 point p = fSchema1->inputPoint(i+skip); 00149 point q = inputPoint(i); 00150 dev.trait(p.x, p.y, q.x, q.y); 00151 } 00152 00153 // draw the feedback connections to each fSchema2 input 00154 for (unsigned int i=0; i<fSchema2->inputs(); i++) { 00155 drawFeedback(dev, fSchema1->outputPoint(i), fSchema2->inputPoint(i), i*dWire); 00156 } 00157 00158 // draw the feedfront connections from each fSchema2 output 00159 for (unsigned int i=0; i<fSchema2->outputs(); i++) { 00160 drawFeedfront(dev, fSchema2->outputPoint(i), fSchema1->inputPoint(i), i*dWire); 00161 } 00162 }
void recSchema::drawDelaySign | ( | device & | dev, | |
double | x, | |||
double | y, | |||
double | size | |||
) | [private] |
Draw the delay sign of a feedback connection.
Definition at line 184 of file recSchema.cpp.
References device::trait().
Referenced by drawFeedback().
00185 { 00186 dev.trait(x-size/2, y, x-size/2, y-size); 00187 dev.trait(x-size/2, y-size, x+size/2, y-size); 00188 dev.trait(x+size/2, y-size, x+size/2, y); 00189 }
void recSchema::drawFeedback | ( | device & | dev, | |
const point & | src, | |||
const point & | dst, | |||
double | dx | |||
) | [private] |
Draw a feedback connection between two points with an horizontal displacement dx.
Definition at line 170 of file recSchema.cpp.
References drawDelaySign(), dWire, kLeftRight, schema::orientation(), device::trait(), point::x, and point::y.
Referenced by draw().
00171 { 00172 double ox = src.x + ((orientation()==kLeftRight) ? dx : -dx); 00173 double ct = (orientation()==kLeftRight) ? dWire/2 : -dWire/2; 00174 00175 drawDelaySign(dev, ox, src.y, ct); 00176 dev.trait(ox, src.y-ct, ox, dst.y); 00177 dev.trait(ox, dst.y, dst.x, dst.y); 00178 }
void recSchema::drawFeedfront | ( | device & | dev, | |
const point & | src, | |||
const point & | dst, | |||
double | dx | |||
) | [private] |
Draw a feedfrom connection between two points with an horizontal displacement dx.
Definition at line 196 of file recSchema.cpp.
References kLeftRight, schema::orientation(), device::trait(), point::x, and point::y.
Referenced by draw().
00197 { 00198 double ox = src.x + ((orientation()==kLeftRight) ? -dx : dx); 00199 00200 dev.trait(ox, src.y, src.x, src.y); 00201 dev.trait(ox, src.y, ox, dst.y); 00202 dev.trait(ox, dst.y, dst.x, dst.y); 00203 }
point recSchema::inputPoint | ( | unsigned int | i | ) | const [virtual] |
The input points s1 ~ s2.
Implements schema.
Definition at line 110 of file recSchema.cpp.
References fInputPoint.
Referenced by draw().
00111 { 00112 return fInputPoint[i]; 00113 }
point recSchema::outputPoint | ( | unsigned int | i | ) | const [virtual] |
The output points s1 ~ s2.
Implements schema.
Definition at line 119 of file recSchema.cpp.
References fOutputPoint.
Referenced by draw().
00120 { 00121 return fOutputPoint[i]; 00122 }
void recSchema::place | ( | double | ox, | |
double | oy, | |||
int | orientation | |||
) | [virtual] |
The two subschema are placed centered vertically, s2 on top of s1.
The input and output points are computed.
Implements schema.
Definition at line 71 of file recSchema.cpp.
References schema::beginPlace(), schema::endPlace(), fInputPoint, fOutputPoint, fSchema1, fSchema2, schema::height(), schema::inputPoint(), schema::inputs(), kLeftRight, kRightLeft, schema::outputPoint(), schema::outputs(), schema::place(), schema::width(), point::x, and point::y.
00072 { 00073 beginPlace(ox, oy, orientation); 00074 00075 double dx1 = (width() - fSchema1->width())/2; 00076 double dx2 = (width() - fSchema2->width())/2; 00077 00078 // place the two sub diagrams 00079 if (orientation == kLeftRight) { 00080 fSchema2->place(ox+dx2, oy, kRightLeft); 00081 fSchema1->place(ox+dx1, oy+fSchema2->height(), kLeftRight); 00082 } else { 00083 fSchema1->place(ox+dx1, oy, kRightLeft); 00084 fSchema2->place(ox+dx2, oy+fSchema1->height(), kLeftRight); 00085 } 00086 00087 00088 // adjust delta space to orientation 00089 if (orientation == kRightLeft) { dx1 = -dx1; } 00090 00091 // place input points 00092 for (unsigned int i=0; i<inputs(); i++) { 00093 point p = fSchema1->inputPoint(i+fSchema2->outputs()); 00094 fInputPoint[i] = point(p.x-dx1, p.y); 00095 } 00096 00097 // place output points 00098 for (unsigned int i=0; i<outputs(); i++) { 00099 point p = fSchema1->outputPoint(i); 00100 fOutputPoint[i] = point(p.x+dx1, p.y); 00101 } 00102 00103 endPlace(); 00104 }
Creates a new recursive schema (s1 ~ s2).
The smallest component is enlarged to the width of the other. The left and right horizontal margins are computed according to the number of internal connections.
Definition at line 34 of file recSchema.cpp.
00035 { 00036 schema* a = makeEnlargedSchema(s1, s2->width()); 00037 schema* b = makeEnlargedSchema(s2, s1->width()); 00038 double m = dWire * max(b->inputs(), b->outputs()); 00039 double w = a->width() + 2*m; 00040 00041 return new recSchema(a,b,w); 00042 }
vector<point> recSchema::fInputPoint [private] |
Definition at line 37 of file recSchema.h.
Referenced by inputPoint(), place(), and recSchema().
vector<point> recSchema::fOutputPoint [private] |
Definition at line 38 of file recSchema.h.
Referenced by outputPoint(), place(), and recSchema().
schema* recSchema::fSchema1 [private] |
Definition at line 35 of file recSchema.h.
schema* recSchema::fSchema2 [private] |
Definition at line 36 of file recSchema.h.