wxWidgets AddRoot() on wxTreeCtrl fails to add more then one node - c++

I'm using wxWidgets 2.8.11 on Windows 7 64 Bit. I created a wxTreeCtrl control, which as the name suggests, is a tree control. You can add Root nodes by calling AddRoot(), however it seems to only work the first time of calling it.
Here is the code where I create the Tree:
newHandler-> sendPacketTree = new wxTreeCtrl(newHandler->sendGroupBox,4,wxPoint(7,12),wxSize(newHandler->sendGroupBox->GetSize().x-14,newHandler->sendGroupBox->GetSize().y-20),wxTR_DEFAULT_STYLE);
Here is what I'm doing just as a test:
this->sendPacketTree->AddRoot(wxT("Test1"));
this->sendPacketTree->AddRoot(wxT("Test2"));
However, only the first root node appears in the Tree, and the second node doesn't appear (or any other node after the first node for that matter)
Does anyone know why this is happening, or how I can get around this? I'm stumped.

I found a solution on my own. I thought that AddRoot() allowed you to add more then one root. It turns out you can only have one root, but you are able to hide the actual "root", and any children of the root will look like a root with the wxTR_HIDE_ROOT style set.

Related

C++11 Trouble accessing node by name with rapidxml::first_node

I am confused as to why I can find the node by name through next_sibling. But when I try to use first_node I am getting a segfault.
The parent node containing all the nodes I need to find.
rapidxml::xml_node<> *xmlnode_chd = xml_doc->first_node();
The two lines to access the node
xmlnode_chd->first_node()->next_sibling("name_to_find")->name(); //Works
xmlnode_chd->first_node("name_to_find")->name(); //Fails
To my understanding a sibling node has the same parent. I thought that the logic between these two statements was the same. I am probably overlooking something simple.

Root Cern Export Data: export a specific data type

as i wrote in the title, i'm trying to export data from a tree, i've followed this. It's work but i've problem when i try to export a specific branch. The Print for the Tree, when i try to export the branch named "ADCVal" there is a crash. I think the problem is that "ADCVal" is a vector so i have to extract every element. How can i modify the code and associate to a variable every element of the branch.
I know it might seem like a simple question but my c++/root knowledge are really poor. Thank all.
As a starting point you can use the MakeClass method, this writes the code for you:
root org.root
root [0]
Attaching file org.root as _file0...
(TFile *) 0x2670460
root [1] .ls
TFile** org.root
TFile* org.root
KEY: TTree SomeTree SomeTree
root [2] SomeTree->MakeClass("removeme")
Info in <TTreePlayer::MakeClass>: Files: removeme.h and removeme.C generated from TTree: B02DD
(Int_t) 0
root [3]
You can then have a look in removeme.h to see how to use SetBranchAddress with an array. It boils down to
Float_t ADCVal[10];
tr->SetBranchAddress("ADCVal", ADCVal);
and then you can access ADCVal[0], ADCVal[1], ... after calling tr->GetEntry(i);

Getting the node depth of current node

I have made a user cut callback that adds some cuts to the model I am working on. This works perfectly fine. I want to add these cuts, only to the top nodes of the search tree. The problem is, that I cannot figure out how to retrieve the depth of the current node. I have made a node callback that increments an integer variable every time it is called. This means that I can just do nothing in the cut callback when this integer exceeds some number. But then I do not now, if cplex has fx. only created nodes on left branches, meaning that no cuts are added to nodes on right branches or vise versa.
Looking in the documentation for node callbacks
http://pic.dhe.ibm.com/infocenter/cosinfoc/v12r4/index.jsp?opic=%2Filog.odms.cplex.help%2Frefpythoncplex%2Fhtml%2Fcplex.callbacks.NodeCallback-class.html
I see that there is a getDepth() method, that takes as argument a node identifier. But how to get this identifier, I simply cannot figure out.
CPLEX version 12.10.0.0 has the method
getCurrentNodeDepth()
You can call it inside your ILOUSERCUTCALLBACK method and it will give the current node depth as a long value.
You can check for more details here:
https://www.ibm.com/support/knowledgecenter/SSSA5P_12.10.0/ilog.odms.cplex.help/refdotnetcplex/html/M_ILOG_CPLEX_Cplex_MIPCallback_GetCurrentNodeDepth.htm
I was trying the same thing in C++.
I was trying to work with the function getDepth(), that takes as argument a node identifier.
But I couldn't figure out how to obtain the node identifier.
It is not clear from the documentation, but:
When the node callback is invoked, the next node to be processed is the node at index 0.
Then, to know the depth of the current node, you need to use index 0 as the identifier.
Using the callable library:
CPXgetcallbacknodeinfo(env, cbdata, wherefrom, 0, CPX_CALLBACK_INFO_NODE_DEPTH, &depth);
Sorry, I do not know much about the concert technology.

Replace root node for Document

I found a memory leak in my application using libxml++ due to an XML document where I replace the root node. I took good care for removing any child nodes, but using the xmlpp::Document interface I find no way to replace the root node.
This is a sample of the offending code:
xmlpp::Document Doc;
Doc.create_root_node("root");
// Populate the document
// [...]
void ReplaceRootNode(const xmlpp::Element* NewRootNode)
{
// Remove all root node children
xmlpp::Element* RootNode = Doc.get_root_node();
const xmlpp::Node::NodeList Children = RootNode->get_children();
xmlpp::Node::NodeList::const_iterator itChild = Children.begin();
while (itChild != Children.end()) {
RootNode->remove_child(*itChild++);
}
// Replace root node
Doc.create_root_node_by_import(NewRootNode); // Leak: memory for previous root node is not freed
}
The solution I came up with so far is to edit the document's root node to change it's name and attributes but. Is there a simpler way to avoid this leak which does not involve edition of previous root node's name and attributes?
I work around this by setting the document to an empty Document object (Doc = xmlpp:Document()) before calling create_root_node_by_import instead of removing the root's child nodes explicitly. This appears to cause the previous contents of Doc to be freed.
I first encountered this problem several years ago, and it still does not appear to be fixed in recent versions of libxml++. Surely they must be aware of it. Could this case somehow be using create_root_node_by_import in an unintended fashion? I would not have thought so, but OTOH this seems too important not to fix.

Changing the Total Number of Recent Files

I'd like the user to be able to edit the number of recent files shown in the File menu of my MFC application. I've used two very good references:
http://www.codeproject.com/KB/menus/changemru.aspx
http://www.microsoft.com/msj/0899/c/c0899.aspx
It involves deleting and recreating the CRecentFileList object stored in CWinApp::m_pRecentFileList. Unfortunately, I find that the menu is not updated properly after replacing the CRecentFileList. See code snippet below:
void CMyWinApp::SetMRUListSize( int size )
{
// size guaranteed to be between 1 and 16
delete m_pRecentFileList ;
LoadStdProfileSettings( size ) ;
}
What can I do to ensure that what is drawn into the File menu is synchronized with m_pRecentFileList after I recreate the object?
My CApp derives from CWinApp. In initInstance, you have this line:
LoadStdProfileSettings(10);
At the end of InitInstance, add this code:
m_pmf->m_pRecentFileList = m_pRecentFileList;
Here m_pmf is my MainFrame class and I created a member CMainFrame::m_pRecentFileList of type CRecentFileList which is in the MFC source file filelist.cpp. m_pRecentFileList on the right is protected and CMainFrame doesn't have access to it from outside InitInstance, but you can make a functional copy here.
At the end of CMainFrame::OnClose, force a registry update by:
m_pRecentFileList->WriteList();
// Force registry update on exit. This doesn't work without forcing.
I don't even have to rebuild m_pRecentFileList, the MRU mechanism updates it correctly. Example: 5 MRU items, the first is moved to another directory and can no longer be found. Stepping through the code in the debugger shows that the bad entry is removed from the list. For some reason, the updated list isn't saved correctly unless I force it as explained above. I originally thought the problem might have something to do with privileges (64-bit Win7), but running the app as admin didn't help.
Some of Microsoft's documentation suggest you should call CWinApp::LoadStdProfileSettings from within InitInstance. This suggests to me that it's something done once during initialisation rather than at run time.
Have you tried fully implementing the second of the two links you provided? My guess is you need to add the second part instead of the call to CWinApp::LoadStdProfileSettings:
m_pRecentFileList = new CRecentFileList(0, strSection, strEntryFormat, nCount);
if(m_pRecentFileList)
{
bReturn = TRUE;
// Reload list of MRU files from registry
m_pRecentFileList->ReadList();
}
[Edit] Apparently m_pRecentFileList points to an CRecentFileList Class . Have you tried calling CRecentFileList::UpdateMenu?
There's another CodeProject example which might help too.