-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgensvg.cpp
More file actions
executable file
·67 lines (55 loc) · 2.17 KB
/
Copy pathgensvg.cpp
File metadata and controls
executable file
·67 lines (55 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <fstream>
#include "Proteine.hpp"
#include "AcideAmine.hpp"
#include <vector>
using namespace std;
// Constant declarations specifying the dimensions of the image and
// the rectangular bar.
// Prolog for the SVG image
void header(ofstream& myfile, int IMG_WIDTH, int IMG_HEIGHT) {
myfile << "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" << endl
<< "<svg width=\"" << IMG_WIDTH
<< "\" height=\"" << IMG_HEIGHT << "\">" << endl
<< "<title>Proteine</title>" << endl;
}
// Epilog for the SVG image
void footer(ofstream& myfile) {
myfile << "</svg>" << endl;
}
// Generation a line
void line(int x1, int y1, int x2, int y2, ofstream& myfile) {
myfile << "<line x1=\"" << x1 <<"\" y1=\"" << y1 <<"\" x2=\"" << x2 << "\" y2=\"" << y2 << "\" style=\"stroke:black;stroke-width:1\" />" << endl;
}
// Generation a dotted line, contact of two acide anime type H not linked
void lien(int x1, int y1, int x2, int y2, ofstream& myfile) {
myfile << "<line stroke-dasharray=\"2 1\" x1=\"" << x1 <<"\" y1=\"" << y1 <<"\" x2=\"" << x2 << "\" y2=\"" << y2 << "\" style=\"stroke:black;stroke-width:1\" />" << endl;
}
// Generation a circle
void circle(int x, int y, char v, ofstream& myfile) {
if (v == 'H')
myfile << "<circle cx=\"" << x << "\" cy=\"" << y << "\" r=\"6\" fill=\"black\" />" << endl;
else
myfile << "<circle cx=\"" << x << "\" cy=\"" << y << "\" r=\"6\" stroke=\"black\" stroke-width=\"1\" fill=\"white\" />" << endl;
}
// Read input and generate SVG image
void showProtein(Proteine p) {
int IMG_WIDTH = p.l*40;
int IMG_HEIGHT = p.l*40;
int coeff = 20;
ofstream myfile;
myfile.open ("example.svg");
header(myfile, IMG_WIDTH, IMG_HEIGHT);
for (unsigned int i=0; i< p.typeHL.size(); i++) {
lien(p.typeHL[i]->x*coeff, p.typeHL[i]->y*coeff, p.typeHR[i]->x*coeff, p.typeHR[i]->y*coeff, myfile);
}
for (int i = 0; i < p.l; i++) {
vector<AcideAmine*> lst = p.proteine;
if (i != p.l-1) {
line(lst[i]->x*coeff, lst[i]->y*coeff, lst[i+1]->x*coeff, lst[i+1]->y*coeff, myfile);
}
circle(lst[i]->x*coeff, lst[i]->y*coeff, lst[i]->valeur, myfile);
}
footer(myfile);
myfile.close();
}