Question about NodeEditor "Switch" Node
 1-20  21-26

Next
 From:  fcwilt
9984.1 
Hi,

I'm somewhat new to Node Editor.

I've used the Switch node in a couple of experiments and it does what I want - mostly.

Would it be possible to create a similar node that could handle more then two inputs?

If so there would be no need to cascade multiple Switch nodes to handle three (or more) inputs, as am I having to do now.

Thanks.

Frederick
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
9984.2 In reply to 9984.1 
So it looks like a macro would not work, due to the click switching.

I suppose that this widget node could be enlarged.

I look at the node as a single pole, double throw switch, such as would be used for a "three-way" hall light, controlled by two switches.

A double pole, double throw switch is two SPDT in one, etc for triple poleDT.

Two SPDT switches plus one DPDT switch can control a light from 3 locations. etc.

- Brian

EDITED: 13 Oct 2020 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
9984.3 In reply to 9984.2 
The Switch Widget is in the interface.js file, at the end.

1. Adding two more inputs and one more output is easy. Just copy the code. (no need to add input id numbers 2 and 3 and output ID 1?)

2. Adding the link is easy, just copy the code referencing inputs 0 and 1 and output 0, to reference inputs 2 and 3, and output 1.

3. Also to add is the connecting "wire". Probably duplicate (or add to) some particular portions of existing code for "ctx". (not tried)
Click switching switches both poles. They do not switch independently. So both wires would alter state together, upon click.

4. Also duplicate the code re: Numbers (numarray) / Points (pointarray) / Objects (objectlist), re inputs 2, 3, and output 1. (not tried)

Leave the original interface.js intact.
Add a new DPDT.js node.

As an amateur javascript programmer, Max's code is hard to understand.
Adding multiple inputs is done in other nodes, somehow.
No more time to play today, must go to work.

- Brian

EDITED: 20 Oct 2020 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  fcwilt
9984.4 In reply to 9984.3 
Hi,

Thanks for the reply.

I must apologize for not being clear.

I wasn't wanting more poles but rather more positions, so I could select from 3 or more inputs going to just one output.

Frederick
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  James (JFH)
9984.5 In reply to 9984.4 
Frederick

Attached is a nod file that contains a macro that does something similar to your request.
If it suits your purpose, rename macro as desired and save to macro folder for reuse.
If you require more than 3 choices you will need to modify to suit, however this is not a taunting task.

Hope this helps
James
https://www.instagram.com/nodeology/
Attachments:

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  fcwilt
9984.6 In reply to 9984.5 
Hi,

Thanks much, it works a treat.

So I rename the macro and export to the Moi macro directory?

Then to use it I import it?

Frederick
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
9984.7 
https://www.youtube.com/watch?v=f4OVZd5Faws

CCW click area, plus CW click area would be nice?

Dial or Rotary switch.

Four zones, each 3 step, 4 pole.

A DPDT, or 3PDT, or 4PDT would also find uses.

- B
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
9984.8 
SwDPDT.js is an extension node Widget, which performs like a Double Pole Double Throw switch.
To use it, save it in the nodeeditor extensions folder.
It is a modification to Max's Switch node.
The upper output is output (#0), same as for Switch node.
The NC output is a No Connection dummy output (#1) to line up output #2 for the second ctx "wire".

SwDPDT_demo.zip is a nod program to demo the connections. (Uses James circle/square technique, with second
switch chosing between rectangle and polygon.

Both switches change I/O state with the same mouseClick.
Both switches are the same datatype. Choose one of either numpoints, pointarrays, or objectlist for both switches..

- Brian

See second post down for updated files.

EDITED: 15 Oct 2020 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
9984.9 In reply to 9984.8 
So the input output linking "wire" is drawn on the javascript canvas with ctx methods/commands.
Possibly with nodeeditor modifications.
Google search of (ctx canvas javascript) brings up explanations and examples.
For example: https://www.w3docs.com/learn-javascript/canvas.html.
So drawing the second wire should be relatively easy.
Duplicate some code, and adjust the y values for "startpoint". "endpoint" may be the same y "offset".
- Brian
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
9984.10 In reply to 9984.9 
https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/bezierCurveTo

After study of the bezier inputs, and much trial and error, the second "wire" was successfully located in the node box.

Updated versions are here. For the 3 people who previously downloaded incomplete node, please re-download.

See post 14 for 3rd version of SwDPDT.js, in swDPDT_3.zip file.

- Brian

EDITED: 16 Oct 2020 by BEMFARMER

Attachments:

Image Attachments:
Size: 78.6 KB, Downloaded: 23 times, Dimensions: 732x553px
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
9984.11 In reply to 9984.10 
There is a bug in datatypes/colors. Upon reloading saved nod program, Outputs 1 and 2 are teal color.

EDITED: 15 Oct 2020 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  wayne hill (WAYNEHILL5202)
9984.12 In reply to 9984.11 
Hi Brian,

On the node javascript, add a ctx.save() before starting the ctx drawing and end with a ctx.restore();

Wayne

code:
SwDPDT2.prototype.onDrawForeground = function(ctx)
{
        ctx.save(); // save the context so we don't mess up others

	this.onDrawVectorSwitch(ctx);
        
        ctx.restore(); // restore context to what it was on entry
};

EDITED: 16 Oct 2020 by WAYNEHILL5202

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
9984.13 In reply to 9984.12 
Thank you Wayne, but the bug persists. I inserted your two ctx code lines in the prototype, around the existing this... code line.

The bug is that after the demo.nod is saved, when the demo.nod is reloaded, the NC output dot, and the output dot below it,
appear as numarrays, teal in color. (Yet the two gold wires are still connected to them.) The SwDPDT works initially, but the two numarray outputs
do not act as gold objects.

- Brian

It seems odd that Max's code for Switch, works fine on reload, but the modified code does not.
Maybe check some other node with two or three outputs?

For another node, I tried doing a "push button" "rotary" switch, with one output, and several inputs, sequentially individually connected to the output by mouse click,
but code would need some major alterations, not to mention understanding the existing code. The button option would probably not be appropriated for rotary.
Not a very standard switch. Maybe call it SinglePole4Throw? SP4T or SP5T, etc.?

EDITED: 16 Oct 2020 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
9984.14 In reply to 9984.13 
Split has dynamicOutputs.

Changing dynamicOutputs line to this.dynamicOutputs = ["*"];" seems to have cured the bug.

([0,1,2] would work too.)

Demo node file appears OK.
New zip of SwDPDT.js file below, named swDPDT_3

(Please delete old version, for those 3 people who downloaded it :-)

- Brian

EDITED: 16 Oct 2020 by BEMFARMER

Attachments:

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
9984.15 
Here is an experimental version of SwRotary.js, a "push button" rotary switch.

The TicTac version (Up Down counter) is working, as default mode.
The mode selection is not set up yet.

The Cycled version did not work. Needs a little more work.
Should cycle from pole 5 to pole 1.
Reverse Cycle could be another mode?

Button mode removed as not appropriate. Mouse up code not modified.

The "wire " is not changing colors.

Demo nod program attached as well.

Some of the code for the different beziers is still present, but commented out.
It was used to figure out which values to use for the different beziers, for proper alignment with poles.

- Brian

Have not tried any "Fork" versions.

See post 19 for "Final" working version.

EDITED: 20 Oct 2020 by BEMFARMER

Attachments:

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  fcwilt
9984.16 In reply to 9984.15 
Hi,

Why was Button mode not appropriate?

Thanks.

Frederick
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
9984.17 In reply to 9984.16 
Well, I am mistaken, the Button mode could be used to temporarily bump up one pole.
Or else slowly scan through poles? Scan mode?

So I'll plan on adding Button mode.

Note, Button mode means to change connection while the button is pressed, (mouse down), and revert when the button is released, (mouse up).

- Brian
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
9984.18 In reply to 9984.15 
Modifying one line corrects the wire color bug.
(Only Inputs which are hooked up show the the wire color matching the datatytpe, which is nice.)
(Also for SwDPDT, wire color is NOT neutral for non-hooked up inputs, call it a Bug in SwDPDT.)


// if (this.isInputConnected(this.internal.on*1)) { ctx.strokeStyle = LGraphCanvas.link_type_colors[this.inputs[0].type];}
if (this.isInputConnected(this.internal.poleIndex)) { ctx.strokeStyle = LGraphCanvas.link_type_colors[this.inputs[0].type];}

(No more corrections, due to short term Travel, so corrected SwRotary not updated yet.)

- Brian
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
9984.19 In reply to 9984.18 
With a vary minor addition, "Cycled" mode is working.
Both modes advance pole by pole, from first pole to last pole.
Then:
By push button, Cycled mode jumps from last pole to first pole. (delta = -5)
Or, By push button, Tic-tac mode reverses (delta = -1), from last pole to next to last pole, etc, back down to first pole.

Mode may be changed in the Info box.

Wire color is working.

"Final" version attached.
No plans for "Button" mode, at this time.

- Brian

EDITED: 20 Oct 2020 by BEMFARMER

Attachments:

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  fcwilt
9984.20 In reply to 9984.19 
Hi,

Thanks for the work.

I'm having a senior moment here - what do I do with this file?

Frederick
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All

 

 
Show messages:  1-20  21-26