Node connections widget (Update: source included)

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
eber
Halfling
Posts: 42
Joined: Sun Mar 09, 2008 2:54 am
Location: Southern California
Contact:

Node connections widget (Update: source included)

Post by eber »

Inspired by novaumas and the Teddy Incident animation editor I sat down and wrote a fairly simple node connection widget/control for wxWidgets. This type of editing seems pretty popular which is why i'm posting here. There are some problems, mostly just visual bugs. Though the functionality seems to work with little hassle.

ImageImage

Shown here is a custom 'node' containing a wxSpinButton that puts its value into a float output port. The output port can be connected to any number of input ports. In this case the nodes with the input ports just read the incoming value and set the window label. Nothing fancy, but with this basic structure you can create more node types and even port types to make your own script of sorts.

I will make the source available soon (it's got a lot of test junk code hanging around).

Sorry it's not Ogre specific, but I use it with Ogre and I know a few people around here would like something similar.
Last edited by eber on Thu Oct 23, 2008 2:14 pm, edited 1 time in total.
eber
Halfling
Posts: 42
Joined: Sun Mar 09, 2008 2:54 am
Location: Southern California
Contact:

Post by eber »

Did a quick sweep over the code and stuck it up on a repo:

http://code.google.com/p/junkyardcode/s ... unk/connex

If you know how to fix any of them problems;
- blinking on paint
- no transparency
- whatever else

Just post in this thread or pm me and I'll update the repo.

Image

and with a few more connections:

ImageImage

Things I'd like to add/fix:
- 'Space'/area panning
- Event interface for undo/redo system
- Serialization support
- Better skinning (icons, transparencies, custom connection lines etc)
- Memory clean-up
- Culling connections on paint
- Easier way to align controls within a node with their corresponding ports
User avatar
novaumas
Greenskin
Posts: 107
Joined: Mon Jan 21, 2008 9:44 am
Location: Barcelona
x 4
Contact:

Post by novaumas »

Thanks for sharing!

I haven't tested it because I don't have wxWidgets. I can't help much on the technical part there.

I have skimmed through your code though, and it looks quite nice. I'd hide all those public attributes though :)

It looks much better than what I had when I started anyway.

My biggest recommendation would be to plan the undo/redo redo stuff and multiple selection from the beginning, or it will come back to bite you in the ass later on.
eber
Halfling
Posts: 42
Joined: Sun Mar 09, 2008 2:54 am
Location: Southern California
Contact:

Post by eber »

Yeah, I've had to write a couple in-house editors before so I know what a pain shoeing in undo/redo functionality can be.

That said, I'm not sure I want to add much more than an event interface or it may become too bloated and hard to customize. I haven't thought about it much yet to be honest, but it's definitely high on my to-do list.

Thanks for the input. (yeah, going to clean up the code some more...just not that high prio right now ;)
User avatar
volca
Gnome
Posts: 393
Joined: Thu Dec 08, 2005 9:57 pm
x 1
Contact:

Post by volca »

Tried, and won't compile:

Code: Select all

connexnodeext.h
is missing.

One fix i needed to do - unsigned int can differ in size with pointer. size_t should be the same:

Code: Select all

class wxConnexPortClass
{
public:
        const char*     m_Name;
        size_t          m_RunTimeID;

        wxConnexPortClass( const char* name ) { m_Name = name; m_RunTimeID = (size_t)(name); }
};
As a bonus, here's a cmake script I quickly threw together for building this (needs more love though :) ):

Code: Select all

cmake_minimum_required(VERSION 2.6)

project (connex)


SET(CMAKE_CXX_WARNING_LEVEL 4)

IF(CMAKE_COMPILER_IS_GNUCXX)
    SET(CMAKE_C_FLAGS_DEBUG "-g -O3")
    SET(CMAKE_CXX_FLAGS_DEBUG "-g -O3")
    SET(CMAKE_CXX_FLAGS_DISTRIBUTION "-g -O3")
    SET(CMAKE_C_FLAGS_DISTRIBUTION "-g -O3")
    SET(CMAKE_CXX_FLAGS "-g")
ENDIF(CMAKE_COMPILER_IS_GNUCXX)


# Various modules used for library path detections.
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})

FIND_PACKAGE(wxWidgets REQUIRED mono)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${wxWidgets_CXX_FLAGS}")
ADD_DEFINITIONS( ${wxWidgets_DEFINITIONS} )

include_directories(
    ${wxWidgets_INCLUDE_DIRS}
)

add_executable(connex
    connex.cpp
    connex_example.cpp
    connex_example.h
    connex.h
    connexnode.cpp
    connexnode.h
    connexspace.cpp
    connexspace.h
)

target_link_libraries(connex
    ${wxWidgets_LIBRARIES}
)
Image
eber
Halfling
Posts: 42
Joined: Sun Mar 09, 2008 2:54 am
Location: Southern California
Contact:

Post by eber »

Ah! Good catch.

connex_example.h was connexnodeext.h in my test environment.

I'm updating the repo right now.

Thanks for giving it a try! Did you make anything out of it, or just build it?
User avatar
volca
Gnome
Posts: 393
Joined: Thu Dec 08, 2005 9:57 pm
x 1
Contact:

Post by volca »

Didn't have success building yet (and am doing so just for fun atm, even though there can/will be numerous fun usages for such a code) :)

Two more fixes for you:
(Now I don't know if these are perfectly ok, but wxString does not get created automagically from std::string here on gentoo with wx 2.8 )

connex_example.cpp (around lines 56 and 88, respectively):

Code: Select all

SetLabel( wxString("Output: ", wxConvUTF8) + wxString::Format(wxT("%f"), (float)val / 1000.0f) );

SetLabel( wxString("Input: ", wxConvUTF8) + wxString::Format(wxT("%f"), ((wxConnexPortFloat*)port)->m_Float) );
Now I get compilation errors in connexspace.cpp (and I don't have any experience with wx so leave them up to you):

Code: Select all

junkyardcode-read-only/connex/connexnode.cpp: In member function ‘void wxConnexNode::OnPaint(wxPaintEvent&)’:
junkyardcode-read-only/connex/connexnode.cpp:114: error: ‘OnPaint’ is not a member of ‘wxWindow’
junkyardcode-read-only/connex/connexnode.cpp: In member function ‘void wxConnexNode::OnMouseEvent(wxMouseEvent&)’:
junkyardcode-read-only/connex/connexnode.cpp:123: error: no matching function for call to ‘wxConnexNode::GetPort(wxPoint)’
junkyardcode-read-only/connex/connexnode.cpp:62: note: candidates are: wxConnexPortBase* wxConnexNode::GetPort(wxPoint&)
junkyardcode-read-only/connex/connexnode.cpp:138: error: no matching function for call to ‘wxConnexNode::GetPort(wxPoint)’
junkyardcode-read-only/connex/connexnode.cpp:62: note: candidates are: wxConnexPortBase* wxConnexNode::GetPort(wxPoint&)
junkyardcode-read-only/connex/connexnode.cpp:150: error: no matching function for call to ‘wxConnexNode::GetPort(wxPoint)’
junkyardcode-read-only/connex/connexnode.cpp:62: note: candidates are: wxConnexPortBase* wxConnexNode::GetPort(wxPoint&)
And as a side note, you don't have newlines at the ends of files, and this fact makes my gcc unhappy :D
Image
eber
Halfling
Posts: 42
Joined: Sun Mar 09, 2008 2:54 am
Location: Southern California
Contact:

Post by eber »

Good stuff. I really love MSVC but I guess the compiler can be a little too nice sometimes ;]

I've checked in what I hope are fixes for all the errors you mentioned.

Keep'em coming :)

*edit*

My environment is:
Windows XP
MSVC 2005 SP1
wxWidgets 2.8.9 (static libs)
Last edited by eber on Fri Oct 24, 2008 4:36 pm, edited 1 time in total.
User avatar
volca
Gnome
Posts: 393
Joined: Thu Dec 08, 2005 9:57 pm
x 1
Contact:

Post by volca »

Okay then :)

Code: Select all

junkyardcode-read-only/connex/connexspace.cpp: In member function ‘void wxConnexSpace::OnMouseEvent(wxMouseEvent&)’:
junkyardcode-read-only/connex/connexspace.cpp:223: error: ‘GetWindowChild’ was not declared in this scope
The only one i got when compiling the files straight from svn.


Edit: Well, that one was easy, the condition did nothing, so commenting out helped. Now it compiles just fine :)

Is there any little main code to test this on?
Last edited by volca on Fri Oct 24, 2008 4:40 pm, edited 1 time in total.
Image
eber
Halfling
Posts: 42
Joined: Sun Mar 09, 2008 2:54 am
Location: Southern California
Contact:

Post by eber »

I can comment that out as it's not even being used. Updated svn again.
eber
Halfling
Posts: 42
Joined: Sun Mar 09, 2008 2:54 am
Location: Southern California
Contact:

Post by eber »

I should also point out that the connex_example files are really just very basic examples of what you *could* do and as such shouldn't really be built together with the other files if you're making a lib. I guess it shouldn't hurt if you're just testing though.

I'm planning on making an extension to this, with some 'standard' widgets, but it's' not high prio right now.
User avatar
volca
Gnome
Posts: 393
Joined: Thu Dec 08, 2005 9:57 pm
x 1
Contact:

Post by volca »

I dunno much how wx works but it seems to me the best way to handle the insides of the nodes would be making a widget container out of those nodes.
Aside from a few public member variables the code looks ok to me, good work :) (not that I'm a good judge ;) )

I'd still appreciate a small test app though :)
Image
eber
Halfling
Posts: 42
Joined: Sun Mar 09, 2008 2:54 am
Location: Southern California
Contact:

Post by eber »

wxConnexNode inherits from wxWindow, so you can put any control or widget in there. As long as wxWidgets supports it, so should connex.

If you have a wxWidgets application up you can just add a wxConnexSpace as a child and play around with it there, but sure I'll see if I can make a bare-bones sample.
eber
Halfling
Posts: 42
Joined: Sun Mar 09, 2008 2:54 am
Location: Southern California
Contact:

Post by eber »

Just a quick update, I've added a wxApp in the example code, so you should be able to run what's in the repo if you have the right libs and headers.
User avatar
martignasse
Gnoblar
Posts: 3
Joined: Mon Apr 11, 2005 1:09 pm
Location: Lyon FRANCE

Post by martignasse »

hi,

I just tried on VCExpress and compile fine.

I'm interested by this concept of "schematic view", i think i'll use/modify it in the future.
My needs are different has i prefer to have the control properties (childs) in a separate panel.
If you know how to fix any of them problems;
- blinking on paint
- no transparency
- whatever else
Things I'd like to add/fix:
- 'Space'/area panning
- Event interface for undo/redo system
- Serialization support
- Better skinning (icons, transparencies, custom connection lines etc)
- Memory clean-up
- Culling connections on paint
- Easier way to align controls within a node with their corresponding ports
If i make some of those, i'll let you know

Thanks for sharing :)
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Post by jacmoe »

Extremely useful!
Thanks for sharing! Kudos. :)
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
eber
Halfling
Posts: 42
Joined: Sun Mar 09, 2008 2:54 am
Location: Southern California
Contact:

Post by eber »

Glad you like it. I haven't had any time to play around with my editor stuff for a while now, way to busy at work trying to push a title out the door.

The code is far from bug free, but if you have any fixes/patches or re-writes don't hesitate to drop me a PM.
My needs are different has i prefer to have the control properties (childs) in a separate panel.
You mean you would have the nodes basically empty apart from the ports, and have the control children/parameters in a different window? There's nothing holding you back from doing this with the current code I believe. Though I just might not understand what you want to do :]
User avatar
martignasse
Gnoblar
Posts: 3
Joined: Mon Apr 11, 2005 1:09 pm
Location: Lyon FRANCE

Post by martignasse »

eber wrote: You mean you would have the nodes basically empty apart from the ports, and have the control children/parameters in a different window?
Yes, excactly
eber
Halfling
Posts: 42
Joined: Sun Mar 09, 2008 2:54 am
Location: Southern California
Contact:

Post by eber »

Yeah, then there's nothing holding you back with what's currently in the repo.
Last edited by eber on Tue Feb 24, 2009 12:14 pm, edited 1 time in total.
bharling
Gremlin
Posts: 166
Joined: Fri Jun 30, 2006 1:04 pm

Post by bharling »

Hi,

I hope you don't mind, but I ported this to wxPython and changed a few things:

http://pasteall.org/3107/python

I haven't yet copied over your license details, or properly given you credit, but I'll rectify that soon in the next version I promise - sorry!

I added anti-aliasing by using a Graphics Context DC instead of the normal PaintDC, and also cut out a couple of the draw calls that didn't seem to be required.

Thanks for your code it has been a great help, I hope to carry on and complete a full material editor using it.
Was here
eber
Halfling
Posts: 42
Joined: Sun Mar 09, 2008 2:54 am
Location: Southern California
Contact:

Post by eber »

Hey awesome! I haven't had a chance to look at it yet, but any improvements in the visuals is a big plus. I'm rather new to wxwidgets, and as such probably do many things improperly but I'll get it eventually :] Do you have a lot of experience with it? What I really want is a way to have vector graphics (zoomable views etc) without having to resort to using opengl or some other custom rasterizer :/

Don't worry too much about credits etc, as long as the license is open (BSD/MIT) I'm happy.
bharling
Gremlin
Posts: 166
Joined: Fri Jun 30, 2006 1:04 pm

Post by bharling »

Hi!

dont have a great deal of experience with wxWidgets either really! I know wxPython does provide some extensions to the standard wx toolkit though, like floatCanvas, which does enable the panning / zooming of vector graphics, but the downside is that you can't use regular wxWindows in it ( as far as I know ).

With the Graphics Context modification I did, all the graphics are drawn as vectors with antialiasing, but zooming doesn't work ( currently ). I also changed the main container window to a wxScrolledWindow, but haven't actually got it to scroll yet.
Was here
eber
Halfling
Posts: 42
Joined: Sun Mar 09, 2008 2:54 am
Location: Southern California
Contact:

Post by eber »

Ok. Thnx for the reply.

I guess I'll see how far I get with wxScrolledWindow before ditching the 'standard' canvas all together.
bharling
Gremlin
Posts: 166
Joined: Fri Jun 30, 2006 1:04 pm

Post by bharling »

Back again :)

have been slaving at this to try and reduce the flicker and make it all draw nicely with only limited success... The code is waay too messy to post anywhere yet, but essentially what i did was:

1) Tried to call as few refreshes as possible, on any window.
2) delegated the 'cables' to windows of their own, that render transparent ( but still flicker!! :x ) and use a buffered DC to draw to. The windows size themselves to fit the spline of the cable.
3) used a wx.GCDC to draw everything, giving quick antialiasing

Its still definitely not perfect, but the plus side is that only the bits of the diagram that move get redrawn, so in general the interface wont slow down with more nodes. Also I tried out some simple operators assigned to nodes, and it all worked very well surprisingly. Next step is to design some Ogre Material / shader nodes.

Anyway heres some screenshots:

http://imagebin.org/31532

http://imagebin.org/31533

cheers !
Was here
eber
Halfling
Posts: 42
Joined: Sun Mar 09, 2008 2:54 am
Location: Southern California
Contact:

Post by eber »

Hey bharling that's some mighty fine work there! Coloring looks good and I really like the collapsible node windows, very useful I'm sure! Interesting idea moving the splines to a window though I think I'll just keep the current solution with the addition of culling at paint.

I'm going to look at the rendering issues (blinking) in a couple weeks, I just don't have the time right now. Crunch mode at the office. Come to think of it I doubt I have any time until next year. If you find the issue feel free to PM me or post the solution/problem.
Post Reply