On 22.04.2010 16:39, HOLWERDA Klaas wrote: > > Are those objects at the same level? Meaning children of the same parent > object, in your case likely the top/root object? > Maybe you should actualy combine all those objects in a single object (group > them), by adding as children to a simple a2dCanvasObject. This is good if > they always belong together. > Else, what kind of objects do we talk about here, circle polygons?? > Understand that every a2dCanvasObject has a Matrix, to position the object, > but on top of that the objects itself can have its own vertexes. So maybe > that is the problem. If they show up at the right position in the drawing, > they are right, and you are propably mistaken in only taking GetPosX etc. > from the matrix. In case of e.g. a polygon, all vertexes of the polygon are > first transformed by the polygon its matrix. >
> > It looks like you are taking the coordinates of the previously added object > :-) > So did you check what object you are actualy using (pointer/address)? > > You can always save as CVG and see what is in the file. That will give you > where things are. > Noup, everything is ok with me - the objects are of the same level (for instance, a Resistor and a Capacitor in the wires sample) and they're added to the root object in the same document. Here, I created an example for the wires sample; in this sample, when adding a Resistor, a Capacitor should be added just above the added Resistor. But, just as I predicted, the same thing as in my app happens - the first Capacitor ends up in the upper left corner (in my app it is the lower right corner, but my y-axis has an opposite direction; why the right/left difference? I have no clue), and the second Capacitors is above the first Resistor (instead of the second one), the third one is above the second Resistor etc. Clearly it is the same behavior, and all due to the wrong coordinates of the Resistor. Here's the sample, just paste the code in wires.cpp and add an EVT_DO handler in the event table: void MyFrame::OnDoEvent(a2dCommandProcessorEvent& evt) { if (!GetEvtHandlerEnabled()) return; if (evt.GetCommand()->GetCommandId() == &a2dCommand_AddObject::Id) { a2dCommand_AddObject *command = (a2dCommand_AddObject*) evt.GetCommand(); Resistor *elem = dynamic_cast<Resistor*> (command->GetCanvasObject()); if (!elem) return; Capacitor *block = new Capacitor( wxT("C9"), wxT("100p") ); // position the new element just below the "if" element double x = elem->GetPosX(); double y = elem->GetPosY(); double height = elem->GetBboxHeight(); double width = elem->GetBboxWidth(); double newX = x + width/2 - block->GetBboxWidth()/2; double newY = y + height + 20; block->SetPosXY(newX, newY); GetCanvas()->GetCanvasDocument()->GetRootObject()->Append(block); } } >> >> 2. Is there any way to undo/redo a group of commands? I see there is >> talk about it on the main page, but I can't find any obvious >> commands/methods that will allow me to undo a group of commands... > > Yes. > > OpenCommandGroup( true ); > CloseCommandGroup(); > > Look for documnetation of those functions. > > void a2dBaseTool::OpenCommandGroupNamed( const wxString&name ) > { > wxASSERT_MSG( !m_commandgroup, wxT("Unclosed command group") ); > > m_commandgroup = GetCanvasCommandProcessor()->CommandGroupBegin( name ); > } > > void a2dBaseTool::CloseCommandGroup() > { > if ( m_commandgroup&& this == m_controller->GetFirstTool() ) > { > if( GetCanvasView() ) > { > GetCanvasCommandProcessor()->CommandGroupEnd( m_commandgroup ); > } > m_commandgroup = 0; > } > } > > So the trick is in the GetCanvasCommandProcessor(), which has hierarchy. > Ah, cool :). I saw those, but for who-knows-what reason I thought they're only for internal use :D. Thanks. While we're at undo/redo functionality, I must point out the some tools still expect the canvas popup menu to have TC_UNDO (Undo menu item) and TC_REDO (Redo menu item) - if they aren't there (and I don't want them there, I need something else), the app crashes when using a tool (I use the a2dGraphicsMasterTool and the a2dDragNewTool). Here's the stack trace of the crash: ASSERT INFO: ./src/common/menucmn.cpp(886): assert "item" failed in GetLabel(): wxMenu::GetLabel: no such item BACKTRACE: [1] wxMenuBase::GetLabel(int) cons) /home/ioannes/Desktop/wxGTK-2.8.10/./src/common/menucmn.cpp:886 [2] wxMenuBase::GetLabelText(int) cons) /usr/local/include/wx-2.8/wx/menu.h:383 [3] a2dStToolContr::OnSetmenuStrings(a2dCommandProcessorEvent&) /home/ioannes/Desktop/wxart2d-svn/wxart2d/trunk/wxArt2D/modules/editor/src/sttool.cpp:248 [4] a2dEvtHandler::SearchEventTable(a2dEventTable&, wxEvent&) /home/ioannes/Desktop/wxart2d-svn/wxart2d/trunk/wxArt2D/modules/general/src/comevt.cpp:255 [5] a2dEvtHandler::ProcessEvent(wxEvent&) /home/ioannes/Desktop/wxart2d-svn/wxart2d/trunk/wxArt2D/modules/general/src/comevt.cpp:205 [6] a2dToolContr::ProcessEvent(wxEvent&) /home/ioannes/Desktop/wxart2d-svn/wxart2d/trunk/wxArt2D/modules/canvas/src/tools.cpp:293 [7] a2dCanvasView::ProcessEvent(wxEvent&) /home/ioannes/Desktop/wxart2d-svn/wxart2d/trunk/wxArt2D/modules/canvas/src/drawer.cpp:1014 [8] a2dEventDistributer::ProcessEvent(wxEvent&) /home/ioannes/Desktop/wxart2d-svn/wxart2d/trunk/wxArt2D/modules/general/src/comevt.cpp:1321 [9] a2dCommandProcessor::SetMenuStrings() /home/ioannes/Desktop/wxart2d-svn/wxart2d/trunk/wxArt2D/modules/general/src/comevt.cpp:1177 [10] a2dCommandProcessor::Store(a2dCommand*) /home/ioannes/Desktop/wxart2d-svn/wxart2d/trunk/wxArt2D/modules/general/src/comevt.cpp:1088 [11] a2dCommandProcessor::CommandGroupBegin(wxString const&) /home/ioannes/Desktop/wxart2d-svn/wxart2d/trunk/wxArt2D/modules/general/src/comevt.cpp:1271 [12] a2dBaseTool::OpenCommandGroupNamed(wxString const&) /home/ioannes/Desktop/wxart2d-svn/wxart2d/trunk/wxArt2D/modules/canvas/src/tools.cpp:918 [13] a2dBaseTool::OpenCommandGroup(bool) /home/ioannes/Desktop/wxart2d-svn/wxart2d/trunk/wxArt2D/modules/canvas/src/tools.cpp:909 [14] a2dBaseTool::EnterBusyMode() /home/ioannes/Desktop/wxart2d-svn/wxart2d/trunk/wxArt2D/modules/canvas/src/tools.cpp:789 [15] a2dStTool::EnterBusyMode() /home/ioannes/Desktop/wxart2d-svn/wxart2d/trunk/wxArt2D/modules/editor/src/sttool.cpp:962 [16] a2dDragTool::EnterBusyMode() /home/ioannes/Desktop/wxart2d-svn/wxart2d/trunk/wxArt2D/modules/editor/src/sttool.cpp:2772 [17] a2dDragNewTool::EnterBusyMode() /home/ioannes/Desktop/wxart2d-svn/wxart2d/trunk/wxArt2D/modules/editor/src/sttool.cpp:3401 [18] a2dDragNewTool::OnMouseEvent(wxMouseEvent&) /home/ioannes/Desktop/wxart2d-svn/wxart2d/trunk/wxArt2D/modules/editor/src/sttool.cpp:3349 [19] a2dEvtHandler::SearchEventTable(a2dEventTable&, wxEvent&) /home/ioannes/Desktop/wxart2d-svn/wxart2d/trunk/wxArt2D/modules/general/src/comevt.cpp:255 [20] a2dEvtHandler::ProcessEvent(wxEvent&) /home/ioannes/Desktop/wxart2d-svn/wxart2d/trunk/wxArt2D/modules/general/src/comevt.cpp:205 [21] a2dBaseTool::ProcessEvent(wxEvent&) /home/ioannes/Desktop/wxart2d-svn/wxart2d/trunk/wxArt2D/modules/canvas/src/tools.cpp:727 [22] a2dToolContr::ToolsProcessEvent(wxEvent&) /home/ioannes/Desktop/wxart2d-svn/wxart2d/trunk/wxArt2D/modules/canvas/src/tools.cpp:324 [23] a2dToolContr::ProcessEvent(wxEvent&) /home/ioannes/Desktop/wxart2d-svn/wxart2d/trunk/wxArt2D/modules/canvas/src/tools.cpp:296 [24] a2dCanvasView::ProcessEvent(wxEvent&) /home/ioannes/Desktop/wxart2d-svn/wxart2d/trunk/wxArt2D/modules/canvas/src/drawer.cpp:1014 [25] a2dViewWindow<wxWindow>::ProcessEvent(wxEvent&) /home/ioannes/Desktop/wxart2d-svn/wxart2d/trunk/wxArt2D/modules/docview/include/docviewref.h:3973 [26] wxWindow::GTKProcessEvent(wxEvent&) cons) /home/ioannes/Desktop/wxGTK-2.8.10/./src/gtk/window.cpp:1434 [27] gtk_window_motion_notify_callback() /home/ioannes/Desktop/wxGTK-2.8.10/./src/gtk/window.cpp:1786 [28] g_closure_invoke() [29] g_signal_emit_valist() [30] g_signal_emit() [31] gtk_propagate_event() [32] gtk_main_do_event() [33] g_main_context_dispatch() [34] g_main_loop_run() [35] gtk_main() [36] wxEventLoop::Run() /home/ioannes/Desktop/wxGTK-2.8.10/./src/gtk/evtloop.cpp:76 Also, if you remember, I said that the a2dStToolContr::SetDefaultBehavior(wxTC_NoContextMenu) method doesn't work because the menu keep popping up. Well, it seems that it works, but the a2dStToolContr's internal flag regulating the behavior gets overrun by some tools - after invoking that method on my controller, I pushed an a2dGraphicsMasterTool on the stack and inside its constructor I found this: controller->SetDefaultBehavior( wxTC_NoDefaultKeys | wxTC_NoDefaultMouseActions ); This is, in my opinion, wrong because of what I just said - it overruns the behavior the user set. It should go something like this: controller->SetDefaultBehavior(controller->GetDefaultBehavior() | wxTC_NoDefaultKeys | wxTC_NoDefaultMouseActions ); or if there are any unwanted flags set, they can easily be stripped away, temporarily or permanently. Anyway, I don't need this behavior anymore, I just needed it to get rid of the menu during some testing, but the defaults are fine for me now so I'm just pointing out on something that might be a bug/error :). > > You need to check the event for the document, if it is yours, the event is > for you. > In principle there can be N Canvases on one Document. Or even One Canvas on N > Documents. > So this is how it should be. > Did that, everything works, thanks :). > > Oke, very likely some start up problem?? default size means most of the time > something fitting in the parent. > But as you do know, is oke it think. > > > Well if you can find example doing the same I could debug it, else it does > not help me. > Huh, I'm in a bit of hurry right now so I can't make you a proper example... I don't know why exactly it failed, I just know that wxDefaultSize (that is, {-1,-1}) caused an assertion to fail while creating a canvas. I'll try to make an example later and send it to you. > > vdraws example its a2dConnector has > > void a2dConnector::OnDisConnectView( a2dTemplateEvent& event ) > Hehe, this helped, thank you :). Although the OnDisConnectView is not used with the wxNotebookConnector, the wxNotebookConnector::OnCloseView is so I put my code there and now everything works perfectly :). Kind regards, Ioannes -- Infinite diversity in infinite combinations ------------------------------------------------------------------------------ _______________________________________________ Wxart2d-users_dev mailing list Wxart2d-users_dev@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wxart2d-users_dev