86 TYPECONVERSION = {"BOOL" : "X", "SINT" : "B", "INT" : "W", "DINT" : "D", "LINT" : "L", |
86 TYPECONVERSION = {"BOOL" : "X", "SINT" : "B", "INT" : "W", "DINT" : "D", "LINT" : "L", |
87 "USINT" : "B", "UINT" : "W", "UDINT" : "D", "ULINT" : "L", "REAL" : "D", "LREAL" : "L", |
87 "USINT" : "B", "UINT" : "W", "UDINT" : "D", "ULINT" : "L", "REAL" : "D", "LREAL" : "L", |
88 "STRING" : "B", "BYTE" : "B", "WORD" : "W", "DWORD" : "D", "LWORD" : "L", "WSTRING" : "W"} |
88 "STRING" : "B", "BYTE" : "B", "WORD" : "W", "DWORD" : "D", "LWORD" : "L", "WSTRING" : "W"} |
89 """ |
89 """ |
90 TYPECONVERSION = {"BOOL" : "X", "UINT" : "W","REAL" : "D","STRING" : "B"} |
90 TYPECONVERSION = {"BOOL" : "X", "UINT" : "W","REAL" : "D","STRING" : "B"} |
91 CTYPECONVERSION = {"BOOL" : "bool", "UINT" : "unsigned int", "STRING" : "char*", "REAL" : "float"} |
91 CTYPECONVERSION = {"BOOL" : "IEC_BOOL", "UINT" : "IEC_UINT", "STRING" : "IEC_STRING", "REAL" : "IEC_REAL"} |
92 CPRINTTYPECONVERSION = {"BOOL" : "d", "UINT" : "d", "STRING" : "s", "REAL" : "f"} |
92 CPRINTTYPECONVERSION = {"BOOL" : "d", "UINT" : "d", "STRING" : "s", "REAL" : "f"} |
93 class RootClass(DEFControler): |
93 class RootClass(DEFControler): |
94 |
94 |
95 def __init__(self): |
95 def __init__(self): |
96 DEFControler.__init__(self) |
96 DEFControler.__init__(self) |
126 return True |
126 return True |
127 |
127 |
128 def GenerateProgramHeadersPublicVars(self): |
128 def GenerateProgramHeadersPublicVars(self): |
129 fct = "" |
129 fct = "" |
130 fct += " void OnPlcOutEvent(wxEvent& event);\n\n" |
130 fct += " void OnPlcOutEvent(wxEvent& event);\n\n" |
131 fct += " void IN_"+self.BusNumber+"();\n" |
131 fct += " void Retrive();\n" |
132 fct += " void OUT_"+self.BusNumber+"();\n" |
132 fct += " void Publish();\n" |
133 fct += " void Initialize();\n" |
133 fct += " void Initialize();\n" |
134 fct += " void Print();\n" |
134 # fct += " void Print();\n" |
135 return fct |
135 return fct |
136 |
136 |
137 def GenerateIECVars(self): |
137 def GenerateIECVars(self): |
138 text = "" |
138 text = "" |
139 elementsTab = self.GetElementsTab() |
139 elementsTab = self.GetElementsTab() |
239 text += "int __publish_"+self.BusNumber+"()\n{\n" |
239 text += "int __publish_"+self.BusNumber+"()\n{\n" |
240 text += " if(myapp){" |
240 text += " if(myapp){" |
241 text += " myapp->Publish()" |
241 text += " myapp->Publish()" |
242 text += " }" |
242 text += " }" |
243 text += "}\n\n" |
243 text += "}\n\n" |
|
244 |
|
245 text += "IEC_STRING wxStringToIEC_STRING(wxString s)\n" |
|
246 text += "{\n" |
|
247 text += " STRING res = {0,""};\n" |
|
248 text += " for(int i=0; i<s.Length() && i<STR_MAX_LEN; i++)\n" |
|
249 text += " res.body[i] = s.GetChar(i);\n" |
|
250 text += " res.len = i;\n" |
|
251 text += " return res;\n" |
|
252 text += "}\n\n" |
|
253 |
244 |
254 |
245 return text |
255 return text |
246 |
256 |
247 def GenerateProgramEventTable(self): |
257 def GenerateProgramEventTable(self): |
248 evt = "" |
258 evt = "" |
674 container = True |
684 container = True |
675 elif type == "TextCtrl": |
685 elif type == "TextCtrl": |
676 if (not textctrl): |
686 if (not textctrl): |
677 fct += " SVGUITextCtrl* text;\n" |
687 fct += " SVGUITextCtrl* text;\n" |
678 fct += " text = (SVGUITextCtrl*)GetElementById(wxT(\""+element_id+"\"));\n" |
688 fct += " text = (SVGUITextCtrl*)GetElementById(wxT(\""+element_id+"\"));\n" |
679 fct += " _copy__IB"+self.BusNumber+"_"+element_id+"_1 = wxStringToStr(text->GetValue());\n" |
689 fct += " _copy__IB"+self.BusNumber+"_"+element_id+"_1 = wxStringToIEC_STRING(text->GetValue());\n" |
680 fct += " _copy__IX"+self.BusNumber+"_"+element_id+"_2 = true;\n\n" |
690 fct += " _copy__IX"+self.BusNumber+"_"+element_id+"_2 = true;\n\n" |
681 textctrl = True |
691 textctrl = True |
682 elif type == "ScrollBar": |
692 elif type == "ScrollBar": |
683 if (not scrollbar): |
693 if (not scrollbar): |
684 fct += " SVGUIScrollBar* scrollbar;\n" |
694 fct += " SVGUIScrollBar* scrollbar;\n" |
712 fct += " _copy__IX"+self.BusNumber+"_"+element_id+"_6 = true;\n\n" |
722 fct += " _copy__IX"+self.BusNumber+"_"+element_id+"_6 = true;\n\n" |
713 transform = True |
723 transform = True |
714 fct += "}\n\n" |
724 fct += "}\n\n" |
715 |
725 |
716 #DEBUG Fonction d'affichage |
726 #DEBUG Fonction d'affichage |
717 fct += "void Program::Print()\n{\n" |
727 # fct += "void Program::Print()\n{\n" |
718 for element in elementsTab: |
728 # for element in elementsTab: |
719 infos = element.getElementAttributes() |
729 # infos = element.getElementAttributes() |
720 for info in infos: |
730 # for info in infos: |
721 if info["name"] == "id": |
731 # if info["name"] == "id": |
722 element_id = str(info["value"]) |
732 # element_id = str(info["value"]) |
723 type = element.GetElementInfos()["type"] |
733 # type = element.GetElementInfos()["type"] |
724 FbdBlock = self.GetBlockType(type) |
734 # FbdBlock = self.GetBlockType(type) |
725 element_num_patte = 1 |
735 # element_num_patte = 1 |
726 for input in FbdBlock["inputs"]: |
736 # for input in FbdBlock["inputs"]: |
727 element_type = TYPECONVERSION[input[1]] |
737 # element_type = TYPECONVERSION[input[1]] |
728 c_type = CPRINTTYPECONVERSION[input[1]] |
738 # c_type = CPRINTTYPECONVERSION[input[1]] |
729 var = "_copy__Q"+element_type+self.BusNumber+"_"+element_id+"_"+str(element_num_patte) |
739 # var = "_copy__Q"+element_type+self.BusNumber+"_"+element_id+"_"+str(element_num_patte) |
730 fct +=" printf(\""+var+": %"+c_type+"\\n\","+var+");\n" |
740 # fct +=" printf(\""+var+": %"+c_type+"\\n\","+var+");\n" |
731 element_num_patte +=1 |
741 # element_num_patte +=1 |
732 element_num_patte = 1 |
742 # element_num_patte = 1 |
733 for output in FbdBlock["outputs"]: |
743 # for output in FbdBlock["outputs"]: |
734 element_type = TYPECONVERSION[output[1]] |
744 # element_type = TYPECONVERSION[output[1]] |
735 c_type = CPRINTTYPECONVERSION[output[1]] |
745 # c_type = CPRINTTYPECONVERSION[output[1]] |
736 var = "_copy__I"+element_type+self.BusNumber+"_"+element_id+"_"+str(element_num_patte) |
746 # var = "_copy__I"+element_type+self.BusNumber+"_"+element_id+"_"+str(element_num_patte) |
737 fct +=" printf(\""+var+": %"+c_type+"\\n\","+var+");\n" |
747 # fct +=" printf(\""+var+": %"+c_type+"\\n\","+var+");\n" |
738 element_num_patte +=1 |
748 # element_num_patte +=1 |
739 #fct +=" wxPostEvent(Program,wxEVT_PLCOUT);\n" |
749 #fct +=" wxPostEvent(Program,wxEVT_PLCOUT);\n" |
740 fct +="};\n\n" |
750 # fct +="};\n\n" |
741 return fct |
751 return fct |
742 |
752 |
743 def PlugGenerate_C(self, buildpath, locations, logger): |
753 def PlugGenerate_C(self, buildpath, locations, logger): |
744 current_location = self.GetCurrentLocation() |
754 current_location = self.GetCurrentLocation() |
745 self.BusNumber = "_".join(map(lambda x:str(x), current_location)) |
755 self.BusNumber = "_".join(map(lambda x:str(x), current_location)) |