Browse Source

program nodes wip

Martin Kunz 4 years ago
parent
commit
e0bb5b1554

+ 6 - 2
src/main/java/urgrip/installation/URGripInstallationNodeView.java

@@ -3,7 +3,9 @@ package urgrip.installation;
 import com.ur.urcap.api.contribution.installation.swing.SwingInstallationNodeView;
 import com.ur.urcap.api.domain.data.DataModel;
 import com.ur.urcap.api.domain.io.IO;
+import com.ur.urcap.api.domain.io.IOModel;
 import urgrip.programnodes.Style;
+import urgrip.toolbar.IOHandler;
 
 import javax.swing.*;
 import javax.swing.text.SimpleAttributeSet;
@@ -67,7 +69,9 @@ public class URGripInstallationNodeView implements SwingInstallationNodeView<URG
 		jcb.addActionListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent actionEvent) {
-				installationNode.setValue(key, (String) jcb.getSelectedItem());
+				String value=(String) jcb.getSelectedItem();
+				installationNode.setValue(key, value);
+				installationNode.setValue(key+"_NR", String.valueOf(value));
 			}
 		});
 		JLabel jl=new JLabel(key);
@@ -109,7 +113,7 @@ public class URGripInstallationNodeView implements SwingInstallationNodeView<URG
 	public void setIO(Collection<IO> ios, DataModel model) {
 		Vector<String> iov=new Vector<>();
 		for(IO io: ios)
-			iov.add(io.getName());
+			iov.add(io.getDefaultName());
 
 		getCBFromBox(ddGripClose).setModel(new DefaultComboBoxModel(iov));
 		getCBFromBox(ddGripClose).setSelectedItem(model.get(KEY_GRIP_CLOSE, KEY_GRIP_CLOSE_DEFAULT));

+ 12 - 6
src/main/java/urgrip/programnodes/GripperBlowoutNodeContribution.java

@@ -9,6 +9,8 @@ import com.ur.urcap.api.domain.undoredo.UndoRedoManager;
 import com.ur.urcap.api.domain.userinteraction.keyboard.KeyboardInputCallback;
 import com.ur.urcap.api.domain.userinteraction.keyboard.KeyboardInputFactory;
 import com.ur.urcap.api.domain.userinteraction.keyboard.KeyboardNumberInput;
+import urgrip.installation.URGripInstallationNodeContribution;
+import urgrip.toolbar.IOHandler;
 
 public class GripperBlowoutNodeContribution implements ProgramNodeContribution {
     private static final String KEY_DELAY = "KEY_DELAY";
@@ -17,7 +19,6 @@ public class GripperBlowoutNodeContribution implements ProgramNodeContribution {
     private final KeyboardInputFactory keyboardFactory;
     private final GripperBlowoutNodeView view;
     private final DataModel model;
-
     public GripperBlowoutNodeContribution(ProgramAPIProvider apiProvider, GripperBlowoutNodeView view, DataModel model) {
         this.programAPI = apiProvider.getProgramAPI();
         this.undoRedoManager = apiProvider.getProgramAPI().getUndoRedoManager();
@@ -28,12 +29,13 @@ public class GripperBlowoutNodeContribution implements ProgramNodeContribution {
 
     @Override
     public void openView() {
-        view.setSpeed(model.get(KEY_DELAY, 20));
+
+        view.setDelay(model.get(KEY_DELAY, 20));
     }
 
     @Override
     public void closeView() {
-        model.set(KEY_DELAY, view.getSpeed());
+        model.set(KEY_DELAY, view.getDelay());
     }
 
     @Override
@@ -43,7 +45,11 @@ public class GripperBlowoutNodeContribution implements ProgramNodeContribution {
 
     @Override
     public void generateScript(ScriptWriter writer) {
-        writer.appendLine("write_output_integer_register(3," + 3 + ")");
+        String ioName=programAPI.getInstallationNode(URGripInstallationNodeContribution.class).getBlowoutIO();
+        int idx = IOHandler.getIOIndex(ioName);
+       //  writer.appendLine("set_standard_digital_out("+ idx +"," + true + ")");
+      //   writer.appendLine("set_standard_digital_out("+ idx +"," + true + ")");
+
         writer.writeChildren();
     }
 
@@ -58,7 +64,7 @@ public class GripperBlowoutNodeContribution implements ProgramNodeContribution {
             @Override
             public void onOk(Integer value) {
                 model.set(KEY_DELAY, value);
-                view.setPosition(value);
+                view.setDelay(value);
             }
         };
     }
@@ -74,7 +80,7 @@ public class GripperBlowoutNodeContribution implements ProgramNodeContribution {
             @Override
             public void onOk(Integer value) {
                 model.set(KEY_DELAY, value);
-                view.setSpeed(value);
+                view.setDelay(value);
             }
         };
     }

+ 13 - 19
src/main/java/urgrip/programnodes/GripperBlowoutNodeView.java

@@ -17,7 +17,7 @@ import java.awt.event.MouseEvent;
 public class GripperBlowoutNodeView implements SwingProgramNodeView<GripperBlowoutNodeContribution>{
 
     private final Style style;
-    private JTextField jtfPosition, jtfSpeed;
+    private JTextField jtfDelay;
 
     public GripperBlowoutNodeView(Style style) {
         this.style = style;
@@ -34,21 +34,21 @@ public class GripperBlowoutNodeView implements SwingProgramNodeView<GripperBlowo
     private Box createInputSpeed(final ContributionProvider<GripperBlowoutNodeContribution> provider) {
         Box inputBox = Box.createHorizontalBox();
         inputBox.setAlignmentX(Component.LEFT_ALIGNMENT);
-        inputBox.add(new JLabel("Speed %:"));
+        inputBox.add(new JLabel("Delay (ms):"));
         inputBox.add(createHorizontalSpacing());
 
-        jtfSpeed = new JTextField();
-        jtfSpeed.setFocusable(false);
-        jtfSpeed.setPreferredSize(style.getInputfieldSize());
-        jtfSpeed.setMaximumSize(jtfSpeed.getPreferredSize());
-        jtfSpeed.addMouseListener(new MouseAdapter() {
+        jtfDelay = new JTextField();
+        jtfDelay.setFocusable(false);
+        jtfDelay.setPreferredSize(style.getInputfieldSize());
+        jtfDelay.setMaximumSize(jtfDelay.getPreferredSize());
+        jtfDelay.addMouseListener(new MouseAdapter() {
             @Override
             public void mousePressed(MouseEvent e) {
                 KeyboardNumberInput keyboardInput = provider.get().getKeyboardForSpeedField();
-                keyboardInput.show(jtfSpeed, provider.get().getCallbackForSpeedField());
+                keyboardInput.show(jtfDelay, provider.get().getCallbackForSpeedField());
             }
         });
-        inputBox.add(jtfSpeed);
+        inputBox.add(jtfDelay);
         return inputBox;
     }
 
@@ -60,19 +60,13 @@ public class GripperBlowoutNodeView implements SwingProgramNodeView<GripperBlowo
         return Box.createRigidArea(new Dimension(style.getHorizontalSpacing(), 0));
     }
 
-    public void setPosition(Integer value) {
-        jtfPosition.setText(value.toString());
-    }
 
-    public void setSpeed(Integer value) {
-        jtfSpeed.setText(value.toString());
+    public void setDelay(Integer value) {
+        jtfDelay.setText(value.toString());
     }
 
-    public Integer getPosition() {
-        return Integer.parseInt(jtfPosition.getText());
-    }
-    public Integer getSpeed() {
-        return Integer.parseInt(jtfSpeed.getText());
+    public Integer getDelay() {
+        return Integer.parseInt(jtfDelay.getText());
     }
 
 

+ 1 - 2
src/main/java/urgrip/programnodes/GripperCoupleNodeView.java

@@ -12,7 +12,6 @@ import java.awt.event.MouseEvent;
 public class GripperCoupleNodeView implements SwingProgramNodeView<GripperCoupleNodeContribution>{
 
     private final Style style;
-    private JTextField jtfPosition, jtfSpeed;
     private JRadioButton coupleButton, decoubleButton;
 
     public GripperCoupleNodeView(Style style) {
@@ -30,8 +29,8 @@ public class GripperCoupleNodeView implements SwingProgramNodeView<GripperCouple
     private Box createInput(final ContributionProvider<GripperCoupleNodeContribution> provider) {
         Box inputBox = Box.createHorizontalBox();
         inputBox.setAlignmentX(Component.LEFT_ALIGNMENT);
+        inputBox.add(new JLabel("Action:"));
         inputBox.add(createHorizontalSpacing());
-
         coupleButton = new JRadioButton("Couple");
         decoubleButton = new JRadioButton("Decouple");
         ButtonGroup group = new ButtonGroup();

+ 1 - 2
src/main/java/urgrip/programnodes/GripperGripNodeView.java

@@ -12,7 +12,6 @@ import java.awt.event.MouseEvent;
 public class GripperGripNodeView implements SwingProgramNodeView<GripperGripNodeContribution>{
 
     private final Style style;
-    private JTextField jtfPosition, jtfSpeed;
     private JRadioButton gripButton, ungripButton;
 
     public GripperGripNodeView(Style style) {
@@ -30,7 +29,7 @@ public class GripperGripNodeView implements SwingProgramNodeView<GripperGripNode
     private Box createInputSpeed(final ContributionProvider<GripperGripNodeContribution> provider) {
         Box inputBox = Box.createHorizontalBox();
         inputBox.setAlignmentX(Component.LEFT_ALIGNMENT);
-        inputBox.add(new JLabel("Speed %:"));
+        inputBox.add(new JLabel("Action:"));
         inputBox.add(createHorizontalSpacing());
         gripButton = new JRadioButton("Grip");
         ungripButton = new JRadioButton("Ungrip");

+ 12 - 0
src/main/java/urgrip/toolbar/IOHandler.java

@@ -2,9 +2,12 @@ package urgrip.toolbar;
 
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import com.ur.urcap.api.domain.io.AnalogIO;
 import com.ur.urcap.api.domain.io.DigitalIO;
+import com.ur.urcap.api.domain.io.IO;
 import com.ur.urcap.api.domain.io.IOModel;
 
 public class IOHandler {
@@ -57,6 +60,15 @@ public class IOHandler {
         return null;
     }
 
+    private final static Pattern ioPattern = Pattern.compile("\\[(.*?)\\]");
+    public static int getIOIndex(String ioName) {
+        Matcher m = ioPattern.matcher(ioName);
+        if(m.find()) {
+            return Integer.parseInt(m.group(1));
+        }
+        return -1;
+    }
+
     /*Returns an AnalogIO object found by its default name
      * Default names are:
      *  analog_in[0]

+ 1 - 0
src/main/java/urgrip/toolbar/MyToolbarContribution.java

@@ -55,6 +55,7 @@ class MyToolbarContribution implements SwingToolbarContribution {
         ioCoupleOpen = 	ioHandler.getDigitalIO(installationNode.getCoupleOpenIO());
         blowout = 	ioHandler.getDigitalIO(installationNode.getBlowoutIO());
         waitfor = 	ioHandler.getDigitalIO(installationNode.getWaitforIO());
+
     }
 
     public void buildUI(JPanel jPanel) {