-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnode.h
109 lines (101 loc) · 3.45 KB
/
node.h
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#ifndef MESHLANG_NODE
#define MESHLANG_NODE
#include "hbb.h"
#include <set>
#include <map>
#include <unordered_map>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <fstream>
#include <sstream>
#include <stdio.h>
#include <QDebug>
namespace meshlang{
struct variable{//变量
std::string name,type;
inline variable():name(),type(){}
inline variable(const std::string & n,const std::string & t){
name = n;
type = t;
}
inline variable(const variable & n){
name = n.name;
type = n.type;
}
inline const variable & operator=(const variable & n){
name = n.name;
type = n.type;
return * this;
}
};
struct function{//函数
std::string name;
std::vector<variable> input,output;
HBB::vec size;//方框大小
std::unordered_map<std::string,std::string> types;
bool isPrivate;
};
struct node;
struct line;
struct line{//连线
variable var;
node * start , * end;
int startId , endId;
HBB::vec startPosi;
HBB::vec endPosi;
HBB::AABB * em;
void remove(bool erst=true,bool ered=true);
};
struct node{
function * type;
HBB::vec position; //在图中的位置
std::vector<std::set<line*> > input , output;
std::unordered_map<std::string,std::string> initval;
line * trueThen;
line * falseThen;
int id;
std::set<line*> last;
HBB::AABB * em;
std::string name;
void getClickStatus(const HBB::vec & p , int & mode /* 1 input , 2 output , 3 center */ , int & port);
void getPortPosition(HBB::vec & p , int mode /* 1 input , 2 output , 3 center */ , int port);
int compileFlag;
};
struct functions{
std::map<std::string,function * > funcs;
function * addFunc(const std::string & name,const std::vector<variable> & input,const std::vector<variable> & output);
~functions();
};
struct program:functions{
std::set<node * > nodes;
std::map<int,node * > nodeMap;
std::set<line * > lines;
HBB elements;
HBB elementlines;
node * addNode(const std::string & name,const HBB::vec & tposition,int id=0);
void addModule(const std::string & name,const std::vector<variable> & input,const std::vector<variable> & output,const HBB::vec & posi);
void removeNode(node *);
virtual void editNode(node *)=0;
line * link(node * a,int ida,node * b,int idb);
line * link(int a,int ida,int b,int idb);
void removeLine(line * ,bool erst=true,bool ered=true);
program();
~program();
void clickTwoPoint(const HBB::vec & a , const HBB::vec & b);
void clickToEdit(const HBB::vec & a);
void clickToRemove(const HBB::vec & a);
virtual void getInsertingName(std::string & name)=0;
virtual void showMenu()=0;
virtual void saveNotes(FILE * fp)=0;
virtual void addNote(const std::string & text,const HBB::vec & posi)=0;
virtual bool editNote(const HBB::vec & a)=0;
void import(const std::string & path);
void save(const std::string & path);
private:
int lineNum;
int nodeId;
};
}
#endif