748 return [(Gen_C_file,"")],"" |
748 return [(Gen_C_file,"")],"" |
749 |
749 |
750 def BlockTypesFactory(self): |
750 def BlockTypesFactory(self): |
751 def generate_svgui_block(generator, block, body, link): |
751 def generate_svgui_block(generator, block, body, link): |
752 name = block.getInstanceName() |
752 name = block.getInstanceName() |
753 type = block.getTypeName() |
|
754 block_infos = self.GetBlockType(type) |
|
755 block_id = self.GetElementIdFromName(name) |
753 block_id = self.GetElementIdFromName(name) |
756 if block_id == None: |
754 if block_id == None: |
757 raise ValueError, "No corresponding block found" |
755 raise ValueError, "No corresponding block found" |
|
756 type = block.getTypeName() |
|
757 block_infos = self.GetBlockType(type) |
|
758 current_location = ".".join(map(str, self.GetCurrentLocation())) |
758 if not generator.ComputedBlocks.get(name, False): |
759 if not generator.ComputedBlocks.get(name, False): |
759 for num, variable in enumerate(block.inputVariables.getVariable()): |
760 for num, variable in enumerate(block.inputVariables.getVariable()): |
760 connections = variable.connectionPointIn.getConnections() |
761 connections = variable.connectionPointIn.getConnections() |
761 if connections and len(connections) == 1: |
762 if connections and len(connections) == 1: |
762 parameter = "__Q%s%d_%d_%d"%(TYPECONVERSION[block_infos["inputs"][num][1]], bus_id, block_id, num) |
763 parameter = "%sQ%s%s.%d.%d"%("%", TYPECONVERSION[block_infos["inputs"][num][1]], current_location, block_id, num) |
763 value = generator.ComputeFBDExpression(body, connections[0]) |
764 value = generator.ComputeFBDExpression(body, connections[0]) |
764 generator.Program += (" %s := %s;\n"%(parameter, generator.ExtractModifier(variable, value))) |
765 generator.Program += (" %s := %s;\n"%(parameter, generator.ExtractModifier(variable, value))) |
765 generator.ComputedBlocks[name] = True |
766 generator.ComputedBlocks[name] = True |
766 if link: |
767 if link: |
767 connectionPoint = link.getPosition()[-1] |
768 connectionPoint = link.getPosition()[-1] |
768 for num, variable in enumerate(block.outputVariables.getVariable()): |
769 for num, variable in enumerate(block.outputVariables.getVariable()): |
769 blockPointx, blockPointy = variable.connectionPointOut.getRelPosition() |
770 blockPointx, blockPointy = variable.connectionPointOut.getRelPosition() |
770 if block.getX() + blockPointx == connectionPoint.getX() and block.getY() + blockPointy == connectionPoint.getY(): |
771 if block.getX() + blockPointx == connectionPoint.getX() and block.getY() + blockPointy == connectionPoint.getY(): |
771 return "__I%s%d_%d_%d"%(TYPECONVERSION[block_infos["outputs"][num][1]], bus_id, block_id, num) |
772 return "%sI%s%s.%d.%d"%("%", TYPECONVERSION[block_infos["outputs"][num][1]], current_location, block_id, num) |
772 raise ValueError, "No output variable found" |
773 raise ValueError, "No output variable found" |
773 else: |
774 else: |
774 return None |
775 return None |
|
776 |
|
777 def initialise_block(type, name): |
|
778 block_id = self.GetElementIdFromName(name) |
|
779 if block_id == None: |
|
780 raise ValueError, "No corresponding block found" |
|
781 block_infos = self.GetBlockType(type) |
|
782 current_location = ".".join(map(str, self.GetCurrentLocation())) |
|
783 variables = [] |
|
784 for num, (input_name, input_type, input_modifier) in enumerate(block_infos["inputs"]): |
|
785 variables.append((input_type, None, "%sQ%s%s.%d.%d"%("%", TYPECONVERSION[input_type], current_location, block_id, num), None)) |
|
786 for num, (output_name, output_type, output_modifier) in enumerate(block_infos["outputs"]): |
|
787 variables.append((output_type, None, "%sQ%s%s.%d.%d"%("%", TYPECONVERSION[input_type], current_location, block_id, num), None)) |
|
788 return variables |
775 |
789 |
776 return [{"name" : "SVGUI function blocks", "list" : |
790 return [{"name" : "SVGUI function blocks", "list" : |
777 [{"name" : "Container", "type" : "functionBlock", "extensible" : False, |
791 [{"name" : "Container", "type" : "functionBlock", "extensible" : False, |
778 "inputs" : [("Show","BOOL","none"),("Set State","BOOL","none")], |
792 "inputs" : [("Show","BOOL","none"),("Set State","BOOL","none")], |
779 "outputs" : [("Show","BOOL","none"),("State Changed","BOOL","none")], |
793 "outputs" : [("Show","BOOL","none"),("State Changed","BOOL","none")], |
780 "comment" : "SVGUI Container", |
794 "comment" : "SVGUI Container", |
781 "generate" : generate_svgui_block}, |
795 "generate" : generate_svgui_block, "initialise" : initialise_block}, |
782 {"name" : "Button", "type" : "functionBlock", "extensible" : False, |
796 {"name" : "Button", "type" : "functionBlock", "extensible" : False, |
783 "inputs" : [("Show","BOOL","none"),("Toggle","BOOL","none")], |
797 "inputs" : [("Show","BOOL","none"),("Toggle","BOOL","none")], |
784 "outputs" : [("Visible","BOOL","none"),("State","BOOL","none")], |
798 "outputs" : [("Visible","BOOL","none"),("State","BOOL","none")], |
785 "comment" : "SVGUI Button", |
799 "comment" : "SVGUI Button", |
786 "generate" : generate_svgui_block}, |
800 "generate" : generate_svgui_block, "initialise" : initialise_block}, |
787 {"name" : "TextCtrl", "type" : "functionBlock", "extensible" : False, |
801 {"name" : "TextCtrl", "type" : "functionBlock", "extensible" : False, |
788 "inputs" : [("Text","STRING","none"),("Set Text","BOOL","none")], |
802 "inputs" : [("Text","STRING","none"),("Set Text","BOOL","none")], |
789 "outputs" : [("Text","STRING","none"),("Text Changed","BOOL","none")], |
803 "outputs" : [("Text","STRING","none"),("Text Changed","BOOL","none")], |
790 "comment" : "SVGUI Text Control", |
804 "comment" : "SVGUI Text Control", |
791 "generate" : generate_svgui_block}, |
805 "generate" : generate_svgui_block, "initialise" : initialise_block}, |
792 {"name" : "ScrollBar", "type" : "functionBlock", "extensible" : False, |
806 {"name" : "ScrollBar", "type" : "functionBlock", "extensible" : False, |
793 "inputs" : [("Position","UINT","none"),("Set Position","BOOL","none")], |
807 "inputs" : [("Position","UINT","none"),("Set Position","BOOL","none")], |
794 "outputs" : [("Position","UINT","none"),("Position Changed","BOOL","none")], |
808 "outputs" : [("Position","UINT","none"),("Position Changed","BOOL","none")], |
795 "comment" : "SVGUI ScrollBar", |
809 "comment" : "SVGUI ScrollBar", |
796 "generate" : generate_svgui_block}, |
810 "generate" : generate_svgui_block, "initialise" : initialise_block}, |
797 {"name" : "NoteBook", "type" : "functionBlock", "extensible" : False, |
811 {"name" : "NoteBook", "type" : "functionBlock", "extensible" : False, |
798 "inputs" : [("Selected","UINT","none"),("Set Selected","BOOL","none")], |
812 "inputs" : [("Selected","UINT","none"),("Set Selected","BOOL","none")], |
799 "outputs" : [("Selected","UINT","none"),("Selected Changed","BOOL","none")], |
813 "outputs" : [("Selected","UINT","none"),("Selected Changed","BOOL","none")], |
800 "comment" : "SVGUI Notebook", |
814 "comment" : "SVGUI Notebook", |
801 "generate" : generate_svgui_block}, |
815 "generate" : generate_svgui_block, "initialise" : initialise_block}, |
802 {"name" : "RotatingCtrl", "type" : "functionBlock", "extensible" : False, |
816 {"name" : "RotatingCtrl", "type" : "functionBlock", "extensible" : False, |
803 "inputs" : [("Angle","REAL","none"),("Set Angle","BOOL","none")], |
817 "inputs" : [("Angle","REAL","none"),("Set Angle","BOOL","none")], |
804 "outputs" : [("Angle","REAL","none"),("Angle changed","BOOL","none")], |
818 "outputs" : [("Angle","REAL","none"),("Angle changed","BOOL","none")], |
805 "comment" : "SVGUI Rotating Control", |
819 "comment" : "SVGUI Rotating Control", |
806 "generate" : generate_svgui_block}, |
820 "generate" : generate_svgui_block, "initialise" : initialise_block}, |
807 {"name" : "Transform", "type" : "functionBlock", "extensible" : False, |
821 {"name" : "Transform", "type" : "functionBlock", "extensible" : False, |
808 "inputs" : [("X","REAL","none"),("Y","REAL","none"),("Scale X","REAL","none"),("Scale Y","REAL","none"),("Angle","REAL","none"),("Set","BOOL","none")], |
822 "inputs" : [("X","REAL","none"),("Y","REAL","none"),("Scale X","REAL","none"),("Scale Y","REAL","none"),("Angle","REAL","none"),("Set","BOOL","none")], |
809 "outputs" : [("X","REAL","none"),("Y","REAL","none"),("Scale X","REAL","none"),("Scale Y","REAL","none"),("Angle","REAL","none"),("Changed","BOOL","none")], |
823 "outputs" : [("X","REAL","none"),("Y","REAL","none"),("Scale X","REAL","none"),("Scale Y","REAL","none"),("Angle","REAL","none"),("Changed","BOOL","none")], |
810 "comment" : "SVGUI Transform", |
824 "comment" : "SVGUI Transform", |
811 "generate" : generate_svgui_block}, |
825 "generate" : generate_svgui_block, "initialise" : initialise_block}, |
812 ]} |
826 ]} |
813 ] |
827 ] |
814 |
828 |
815 def GetBlockType(self,type): |
829 def GetBlockType(self,type): |
816 for category in self.BlockTypesFactory(): |
830 for category in self.BlockTypesFactory(): |