Sequential composition. More...
#include <seqSchema.h>
Inherits schema.
Public Member Functions | |
virtual void | place (double ox, double oy, int orientation) |
Place the two components horizontally with enough space for the connections. | |
virtual void | draw (device &dev) |
Draw the two components as well as the internal wires. | |
virtual point | inputPoint (unsigned int i) const |
The input points are the input points of the first component. | |
virtual point | outputPoint (unsigned int i) const |
The output points are the output points of the second component. | |
Private Member Functions | |
seqSchema (schema *s1, schema *s2, double hgap) | |
Constructor for a sequential schema (s1:s2). | |
void | drawInternalWires (device &dev) |
Draw the internal wires aligning the vertical segments in a symetric way when possible. | |
Private Attributes | |
schema * | fSchema1 |
schema * | fSchema2 |
double | fHorzGap |
Friends | |
schema * | makeSeqSchema (schema *s1, schema *s2) |
Make a sequential schema. |
Sequential composition.
Place and connect two diagrams in sequence. The constructor is private because one should use the makeSeqSchema function instead.
Definition at line 36 of file seqSchema.h.
Constructor for a sequential schema (s1:s2).
The components s1 and s2 are supposed to be "compatible" (s1 : n->m and s2 : m->q)
Definition at line 62 of file seqSchema.cpp.
References schema::inputs(), and schema::outputs().
00063 : schema( s1->inputs(), 00064 s2->outputs(), 00065 s1->width() + hgap + s2->width(), 00066 max(s1->height(), s2->height()) ), 00067 fSchema1(s1), 00068 fSchema2(s2), 00069 fHorzGap(hgap) 00070 { 00071 assert(s1->outputs() == s2->inputs()); 00072 }
void seqSchema::draw | ( | device & | dev | ) | [virtual] |
Draw the two components as well as the internal wires.
Implements schema.
Definition at line 125 of file seqSchema.cpp.
References schema::draw(), drawInternalWires(), fSchema1, fSchema2, schema::inputs(), schema::outputs(), and schema::placed().
00126 { 00127 assert(placed()); 00128 assert(fSchema1->outputs() == fSchema2->inputs()); 00129 00130 fSchema1->draw(dev); 00131 fSchema2->draw(dev); 00132 drawInternalWires(dev); 00133 }
void seqSchema::drawInternalWires | ( | device & | dev | ) | [private] |
Draw the internal wires aligning the vertical segments in a symetric way when possible.
Definition at line 141 of file seqSchema.cpp.
References direction(), dWire, fHorzGap, fSchema1, fSchema2, schema::inputPoint(), schema::inputs(), kDownDir, kLeftRight, kUpDir, schema::orientation(), schema::outputPoint(), schema::outputs(), device::trait(), point::x, and point::y.
Referenced by draw().
00142 { 00143 assert (fSchema1->outputs() == fSchema2->inputs()); 00144 00145 const int N = fSchema1->outputs(); 00146 double dx = 0; 00147 double mx = 0; 00148 int dir =-1; 00149 00150 if (orientation() == kLeftRight) { 00151 // draw left right cables 00152 for (int i=0; i<N; i++) { 00153 point src = fSchema1->outputPoint(i); 00154 point dst = fSchema2->inputPoint(i); 00155 int d = direction(src,dst); 00156 if (d != dir) { 00157 // compute attributes of new direction 00158 switch (d) { 00159 case kUpDir : mx = 0; dx = dWire; break; 00160 case kDownDir : mx = fHorzGap; dx = -dWire; break; 00161 default : mx = 0; dx = 0; break; 00162 } 00163 dir = d; 00164 } else { 00165 // move in same direction 00166 mx = mx +dx; 00167 } 00168 if (src.y == dst.y) { 00169 // draw straight cable 00170 dev.trait(src.x, src.y, dst.x, dst.y); 00171 } else { 00172 // draw zizag cable 00173 dev.trait(src.x, src.y, src.x+mx, src.y); 00174 dev.trait(src.x+mx, src.y, src.x+mx, dst.y); 00175 dev.trait(src.x+mx, dst.y, dst.x, dst.y); 00176 } 00177 } 00178 } else { 00179 // draw right left cables 00180 for (int i=0; i<N; i++) { 00181 point src = fSchema1->outputPoint(i); 00182 point dst = fSchema2->inputPoint(i); 00183 int d = direction(src,dst); 00184 if (d != dir) { 00185 // compute attributes of new direction 00186 switch (d) { 00187 case kUpDir : mx = -fHorzGap; dx = dWire; break; 00188 case kDownDir : mx = 0; dx = -dWire; break; 00189 default : mx = 0; dx = 0; break; 00190 } 00191 dir = d; 00192 } else { 00193 // move in same direction 00194 mx = mx +dx; 00195 } 00196 if (src.y == dst.y) { 00197 // draw straight cable 00198 dev.trait(src.x, src.y, dst.x, dst.y); 00199 } else { 00200 // draw zizag cable 00201 dev.trait(src.x, src.y, src.x+mx, src.y); 00202 dev.trait(src.x+mx, src.y, src.x+mx, dst.y); 00203 dev.trait(src.x+mx, dst.y, dst.x, dst.y); 00204 } 00205 } 00206 } 00207 }
point seqSchema::inputPoint | ( | unsigned int | i | ) | const [virtual] |
The input points are the input points of the first component.
Implements schema.
Definition at line 103 of file seqSchema.cpp.
References fSchema1, and schema::inputPoint().
00104 { 00105 return fSchema1->inputPoint(i); 00106 }
point seqSchema::outputPoint | ( | unsigned int | i | ) | const [virtual] |
The output points are the output points of the second component.
Implements schema.
Definition at line 112 of file seqSchema.cpp.
References fSchema2, and schema::outputPoint().
00113 { 00114 return fSchema2->outputPoint(i); 00115 }
void seqSchema::place | ( | double | ox, | |
double | oy, | |||
int | orientation | |||
) | [virtual] |
Place the two components horizontally with enough space for the connections.
Implements schema.
Definition at line 82 of file seqSchema.cpp.
References schema::beginPlace(), schema::endPlace(), fHorzGap, fSchema1, fSchema2, schema::height(), kLeftRight, max(), schema::place(), and schema::width().
00083 { 00084 beginPlace(ox, oy, orientation); 00085 00086 double y1 = max(0.0, 0.5*(fSchema2->height() - fSchema1->height())); 00087 double y2 = max(0.0, 0.5*(fSchema1->height() - fSchema2->height())); 00088 00089 if (orientation == kLeftRight) { 00090 fSchema1->place(ox, oy+y1, orientation); 00091 fSchema2->place(ox+fSchema1->width()+fHorzGap, oy+y2, orientation); 00092 } else { 00093 fSchema2->place(ox, oy+y2, orientation); 00094 fSchema1->place(ox+fSchema2->width()+fHorzGap, oy+y1, orientation); 00095 } 00096 endPlace(); 00097 }
Make a sequential schema.
May add cables to ensure the internal connections are between the same number of outputs and inputs. Compute an horizontal gap based on the number of upward and downward connections.
Definition at line 43 of file seqSchema.cpp.
00044 { 00045 unsigned int o = s1->outputs(); 00046 unsigned int i = s2->inputs(); 00047 00048 schema* a = (o < i) ? makeParSchema(s1, makeCableSchema(i-o)) : s1; 00049 schema* b = (o > i) ? makeParSchema(s2, makeCableSchema(o-i)) : s2; 00050 00051 return new seqSchema(a, b, computeHorzGap(a,b)); 00052 }
double seqSchema::fHorzGap [private] |
Definition at line 40 of file seqSchema.h.
Referenced by drawInternalWires(), and place().
schema* seqSchema::fSchema1 [private] |
Definition at line 38 of file seqSchema.h.
Referenced by draw(), drawInternalWires(), inputPoint(), and place().
schema* seqSchema::fSchema2 [private] |
Definition at line 39 of file seqSchema.h.
Referenced by draw(), drawInternalWires(), outputPoint(), and place().