Updated....8/4/12
here's some of the most main problem I faced while coding, and how I solved them ;), or not :(
selection: as we know, canvas or even grid container is the most useful for simulation job (we need to use drag drop as we like, easy to access canvas.children.add or remove ....). but the problem here that selection property not supported in canvas. :( so we need to create custom selection service so (if you searched the internet) you'll find that the best way to do that is by add list and create new event for each child (gate in our case) when mouse down to add this gate to our selection list and when clicking other thing clear this selection... and so on. Fixed
single selection. done.
select all done.
clear selection... (some cases wasn't working correctly) done! by (call clear selection on each new selection if we're in single select case)
Multi-select: .... not working yet ... (as alpha solution one click Ctrl in keyboard, but found problem with clear select with it ... ? ) done
set selected property for gates from main window (when selection operation is called). done
Rotation: I can rotate any gate(s). but cannot save the original location done
rotation Origin problem solved.
copy/paste/cut: well, not so hard when you get how to make selection but check the new code to see what I mean .... I'll just talk here about copy operation (hardest one)
the copy operation is about to get selected gate to clipboard and then create new instance got same copied gate to our simulation area but..... when I tried to add copied gate to canvas(the container) I'll get error message telling me that this control already exist and I've to remove it 1st then I can added....
So, I did tricky way (maybe not that good but it's working nice) checking what is the copied gate then create new instance as same (using switch case). I know, not pro but ... it did the job. Fixed
Zoom: when zooming my canvas (which is in Scroll Viewer) the scroll bar not enabled( when zoom in) ?? after checking back that was render transform problem, so by change it to layout transform problem fixed and all now working correctly :). Fixed
read about this here and about the difference from here.
How to move the Start/End point of connected wire(s): when moving the connected gates with it, the connector(Wire) should be refreshed and re-calc it end/start point to stay connected to it gate(s) for now it won't work cuz the main idea should be similer to move the output values to connected gates dynamically when value has changed ... etc
however, I'm working on Dependency property changed / INotify property changed ... and should solve the problem !?
Move connected wires when it's gate(s) location changed: "Working on!"
for now I'm working on it using Data binding (?) and it's working great when creating static controls and when create the binding in " Xaml Code " but when I'm trying to create new instances at runtime "Dynamic gates" in code I cannot apply the binding (not working in this case ?) and this is my latest
Notes:
Current data binding (using data context and data context changed) not working good:
Cannot use it with normal gates (AND, OR, NOR, .. etc.).
Cannot use the data context to bind like in xAml in Code (binding from code not working ... or I don't know how to make it work ?).
But, I did some tricks like:
the event Data Context changed now implemented in each gate from it's own class (no need to create new one at runtime and while creating new instance)
Save/open commands: old one's not good enough (got many bugs... save is OK. But, sometimes fail with open ). So, now I'm working on new save/open using classic XML files, and the problem is how to serialize(Save my gates, connections with all other needed Info to XML) and then De-serialize XML file (to open it Elements as UIElements to add it to my current simulation area correctly) ???
"New" and other "File" Menu commands: cannot be done 100% till get all other works done.
How to do this :
AND : UserControl, AbsGate ?: this is the error message: "Error 1 Class 'GateDesigner.LED' cannot have multiple base classes ..."
and MSDN says: "The most common cause of this error message is attempting to use multiple inheritance. A class in C# may only inherit directly from one class. However, a class can implement any number of interfaces. "
So, the only way by using interfaces here :(
Advantages: now everything I need to access any property I need in each gates .... in other words the problem SOLVED
Disadvantages: I'll need to add many properties (all properties in my interface should be reimplemented in all gates classes).
However, It works perfectly after using this way and now we can :
Start/Stop Drag&Drop as needed.
detect when I'm start connections between gates.
detect which terminal I'm connecting to (is it Input1, input2 or output in normal gates).
get the gate ID, Name(Type), Input/Output values,
know when some terminal is connected or not
If this gate is IO gate or normal gate (helpful in many things like: to now which gate is the source and the target, creating connection rules, can I connect to/from ... and other things )
improved selection property
So, I can say it's done(Fixed) too ;)
Connection problem..: I just can send the 1st value of source gate to target gate when connecting... fixed !
Others: this section contain some unfinished things like: selection effects in some gates, do more things like ... save setting to file and read on each application start-up, Incomplete stuffs like when hover on some gate terminal we get it as output while it's input :( ,...... and some other small bugs but, it's not a big deal, I'm working on to solve it ASAP, just need more time and some help to get them all work Inshallah :)