00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "decorateSchema.h"
00023 #include <iostream>
00024 #include <assert.h>
00025
00026 using namespace std;
00027
00031 schema* makeDecorateSchema ( schema* s, double margin, const string& text )
00032 {
00033 return new decorateSchema (s, margin, text);
00034 }
00035
00036
00043 decorateSchema::decorateSchema( schema* s, double margin, const string& text )
00044 : schema(s->inputs(), s->outputs(), s->width()+2*margin, s->height()+2*margin),
00045 fSchema(s),
00046 fMargin(margin),
00047 fText(text)
00048 {
00049 for (unsigned int i=0; i<inputs(); i++) fInputPoint.push_back(point(0));
00050 for (unsigned int i=0; i<outputs(); i++) fOutputPoint.push_back(point(0));
00051 }
00052
00053
00059 void decorateSchema::place(double ox, double oy, int orientation)
00060 {
00061 beginPlace(ox, oy, orientation);
00062
00063 fSchema->place(ox+fMargin, oy+fMargin, orientation);
00064
00065 double m = fMargin;
00066 if (orientation == kRightLeft) {
00067 m = -m;
00068 }
00069
00070 for (unsigned int i=0; i < inputs(); i++) {
00071 point p = fSchema->inputPoint(i);
00072 fInputPoint[i] = point(p.x-m, p.y);
00073 }
00074
00075 for (unsigned int i=0; i < outputs(); i++) {
00076 point p = fSchema->outputPoint(i);
00077 fOutputPoint[i] = point(p.x+m, p.y);
00078 }
00079
00080 endPlace();
00081 }
00082
00086 point decorateSchema::inputPoint(unsigned int i) const
00087 {
00088 assert (placed());
00089 assert (i < inputs());
00090 return fInputPoint[i];
00091 }
00092
00096 point decorateSchema::outputPoint(unsigned int i) const
00097 {
00098 assert (placed());
00099 assert (i < outputs());
00100 return fOutputPoint[i];
00101 }
00102
00107 void decorateSchema::draw(device& dev)
00108 {
00109 assert(placed());
00110
00111 fSchema->draw(dev);
00112
00113
00114 for (unsigned int i=0; i<inputs(); i++) {
00115 point p = inputPoint(i);
00116 point q = fSchema->inputPoint(i);
00117 dev.trait(p.x, p.y, q.x, q.y);
00118 }
00119
00120
00121 for (unsigned int i=0; i<outputs(); i++) {
00122 point p = outputPoint(i);
00123 point q = fSchema->outputPoint(i);
00124 dev.trait(p.x, p.y, q.x, q.y);
00125 }
00126
00127
00128 double tw = (2+fText.size())*dLetter*0.75;
00129 double x0 = x() + fMargin/2;
00130 double y0 = y() + fMargin/2;
00131 double x1 = x() + width() - fMargin/2;
00132 double y1 = y() + height() - fMargin/2;
00133
00134 double tl = x() + fMargin;
00135 double tr = min(tl+tw, x1);
00136
00137
00138 dev.dasharray(x0, y0, x0, y1);
00139 dev.dasharray(x0, y1, x1, y1);
00140 dev.dasharray(x1, y1, x1, y0);
00141 dev.dasharray(x0, y0, tl, y0);
00142 dev.dasharray(tr, y0, x1, y0);
00143
00144
00145 dev.label(tl, y0, fText.c_str());
00146 }