-
Notifications
You must be signed in to change notification settings - Fork 1
/
LADGraph.h
162 lines (147 loc) · 5.16 KB
/
LADGraph.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//---------------------------------------------------------------------------
#ifndef LADGraphH
#define LADGraphH
#include <vcl.h>
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.Grids.hpp>
#include <System.ImageList.hpp>
#include <Vcl.ImgList.hpp>
#include <Vcl.ExtCtrls.hpp>
//---------------------------------------------------------------------------
//#define debug
#define AND "A"
#define OR "O"
#define NOT "N"
#define OT "V"
#define SET "S"
#define RES "R"
#define MOV "B"
#define TF "C"
#define TN "T"
#define TmF "c"
#define TmN "t"
#define INCC "+"
#define DECC "-"
#define RESC "="
//---------------------------------------------------------------------------
#define COIL "0"
#define LINE "1"
#define LINE_DF "2"
#define LINE_U "3"
#define LINE_UF "4"
#define LINE_UD "5"
#define LINE_X "6"
#define NC "7"
#define NO "8"
#define RE "9"
#define SE "10"
#define TOF "11"
#define TON "12"
#define LINE_FU "13"
#define LINE_UDF "14"
#define LINE_DOW "15"
#define CINC "16"
#define CDEC "17"
#define CRES "18"
#define DELIM "|"
#define ACT_DELIM "\r"
//---------------------------------------------------------------------------
#define MINUSX 0
typedef struct Nets
{
TStringGrid *Grid;
int idx;
Nets *PrevGrid;
Nets *NextGrid;
}Nets;
typedef struct CellParam
{
UnicodeString Param;
UnicodeString Value;
UnicodeString Value2;
}CellParam;
class TMyGrid: public TStringGrid
{
public:
using TStringGrid::DeleteRow;
using TStringGrid::MoveRow;
using TStringGrid::DeleteColumn;
using TStringGrid::MoveColumn;
};
class TLadGraph
{
private:
TImageList *Data;
int GetCenterV(TRect Rect);
int GetCenterH(TRect Rect);
void DrawCelll(TStringGrid *Grid ,CellParam * param, TRect Rect, int ACol, int ARow);
void SetGridParams(Nets * s);
UnicodeString SetCellParam(CellParam * Param);
void CanGridsResize(TStringGrid *Grid);
bool AddContactOrT(TStringGrid *Grid, CellParam *param);
bool AddRelays(TStringGrid *Grid, CellParam *param);
bool AddDownContactOrT(TStringGrid *Grid, CellParam *param);
UnicodeString CompileGraph(TStringGrid *Grid);
CellParam GetCellParam(UnicodeString CellText);
bool isFBD(CellParam param);
bool isCoil(CellParam param);
bool isAnd(CellParam param);
bool isOr(CellParam param);
UnicodeString ReplaceData(UnicodeString Data, UnicodeString From, UnicodeString To);
UnicodeString CompileCell(CellParam param);
void DecompileBuffer(TStringGrid *Grid, UnicodeString Buffer);
void DecompileBuffer2(TStringGrid *Grid, UnicodeString Buffer);
CellParam DeCompileCell(UnicodeString &s);
UnicodeString GetCurrentCell(TStringGrid *Grid);
void AddUp(TStringGrid *Grid, CellParam param);
void AddDown(TStringGrid *Grid, CellParam param);
UnicodeString CompileRowString(TStringGrid *Grid, int Arow, int StartCol, int & EndCol);
void InsertCol(TStringGrid *Grid, int CurCol);
void InsertRow(TStringGrid *Grid, int CurRow);
void DeleteRow(TStringGrid *Grid, int Row);
void DeleteCol(TStringGrid *Grid, int Col);
void MyTextOut(TStringGrid *Grid, int x, int y, UnicodeString Text);
TStringGrid * CurrentGrid;
void CompressThisGrid(TStringGrid *Grid);
void CompressThisRows(TStringGrid *Grid);
void CompressThisCols(TStringGrid *Grid);
void AlignCols();
void AlignCols_Minus();
void InvalidateGrids();
void ClearAllActions();
public:
Nets *nets;
int Networks;
TLadGraph(TImageList *list);
void DrawCell(TObject *Sender, int ACol, int ARow, TRect Rect);
TStringGrid * CreateNetwork(TWinControl* AOwner, TWinControl * Parrent);
void OnGridsResize();
void SetCurrentGrid(TStringGrid *Grid);
TStringGrid * GetCurrentGrid();
bool Add_NC(TStringGrid *Grid, UnicodeString Parameter);
bool Add_NO(TStringGrid *Grid, UnicodeString Parameter);
bool Add_TON(TStringGrid *Grid, UnicodeString TimerName, int Sec);
bool Add_TOF(TStringGrid *Grid, UnicodeString TimerName, int Sec);
bool Add_Coil(TStringGrid *Grid, UnicodeString Parameter);
bool Add_SET_Coil(TStringGrid *Grid, UnicodeString Parameter);
bool Add_RESET_Coil(TStringGrid *Grid, UnicodeString Parameter);
bool Add_DOWN_NC(TStringGrid *Grid, UnicodeString Parameter);
bool Add_DOWN_NO(TStringGrid *Grid, UnicodeString Parameter);
bool Add_DOWN_TON(TStringGrid *Grid, UnicodeString Parameter, int Sec);
bool Add_DOWN_TOF(TStringGrid *Grid, UnicodeString Parameter, int Sec);
bool DeleteFBD(TStringGrid *Grid);
bool DeleteCurrentAction(bool Silent);
UnicodeString CompileLADProgramm();
void BuildLADProgramm(UnicodeString Prog, TWinControl* AOwner, TWinControl * Parrent, TDrawCellEvent DrawEv, TNotifyEvent OnClick);
bool CurrentCellIsFBD();
bool CoilTypeIsDirect(Nets *net, UnicodeString &CoilName);
bool CellIsTimer(TStringGrid *Grid, int Arow, int Acol, int &TimerIndex);
void TLadGraph::UpdateConditionNames(int upper_limit);
bool TLadGraph::Add_CRES(TStringGrid *Grid, UnicodeString CounterName, int reset_val);
bool TLadGraph::Add_CINC(TStringGrid *Grid, UnicodeString CounterName, int period);
bool TLadGraph::Add_CDEC(TStringGrid *Grid, UnicodeString CounterName, int period);
};
#endif