//---------------------------------------- void CFieldsTreeCtrl::UpdateFieldDescription(const wxTreeItemId& id) { if (!id.IsOk()) { return; } CFieldsTreeItemData* itemData = GetItemDataValue(id);; if (itemData == NULL) { return; } CField* field = itemData->GetField(); if (field == NULL) { return; } itemData->SetSplittedFieldDescr(field); wxString str; if (field->GetUnit().empty()) { str.Printf(wxT("%s"), field->GetName().c_str()); } else { str.Printf(wxT("%s (%s)"), field->GetName().c_str(), field->GetUnit().c_str()); } SetItemText(id, str); Refresh(); }
//---------------------------------------- wxString CFieldsTreeCtrl::GetFieldUnit(const wxTreeItemId& item) { CUnit unit; CFieldsTreeItemData* itemData = item.IsOk() ? dynamic_cast<CFieldsTreeItemData*>(GetItemData(item)) : NULL; CField* field = NULL; if (itemData != NULL) { field = itemData->GetField(); } if (field == NULL) { return unit.GetText().c_str(); } return field->GetUnit().c_str(); }
int main (int argc, char *argv[]) { string FileName; CStringArray InputFiles; CProduct *Product = NULL; bool Error = false; bool Help = false; if (argc != 2) Error = true; else if ((strcmp(argv[1], "-h") == 0) || (strcmp(argv[1], "--help") == 0)) Help = true; else { FileName.assign(argv[1]); if (! CTools::FileExists(FileName)) { cerr << "ERROR: Data file '" << FileName << "' not found" << endl << endl; Error = true; } InputFiles.push_back(FileName); } if (Error || Help) { cerr << "Usage : " << argv[0] << " [ -h | --help] FileName" << endl; cerr << "Where FileName is the name of a file to show" << endl; } if (Help) cerr << endl << "Displays the fields available for a product file" << endl; if (Error || Help) return 2; if (getenv(BRATHL_ENVVAR) == NULL) { CTools::SetDataDirForExecutable(argv[0]); } try { // auto_ptr<CTrace>pTrace(CTrace::GetInstance()); // construct the product Product = CProduct::Construct(InputFiles); Product->Open(FileName); CTreeField *Tree = Product->GetTreeField(); if (Tree->GetRoot() != NULL) { Tree->SetWalkDownRootPivot(); do { CField *field = dynamic_cast<CField*>(Tree->GetWalkCurrent()->GetData()); if (field == NULL) { throw CException("ERROR at least one of the tree object is not a CField object", BRATHL_INCONSISTENCY_ERROR); } if (typeid(*field) == typeid(CFieldRecord)) continue; if ((typeid(*field) == typeid(CFieldArray)) && (! field->IsFixedSize())) continue; string Unit = field->GetUnit(); cout << CTools::Format("%-20s", field->GetRecordName().c_str()) << field->GetFullName(); if (Unit != "") cout << " (" << Unit << ")"; cout << endl; } while (Tree->SubTreeWalkDown()); } delete Product; return 0; } catch (CException &e) { cerr << "BRAT ERROR: " << e.what() << endl; return 1; } catch (exception &e) { cerr << "BRAT RUNTIME ERROR: " << e.what() << endl; return 254; } catch (...) { cerr << "BRAT FATAL ERROR: Unexpected error" << endl; return 255; } }
//---------------------------------------- wxTreeItemId CFieldsTreeCtrl::InsertField(const wxTreeItemId& parentId, CObjectTreeNode* node) { int32_t depth = node->GetLevel(); long numChildren = node->ChildCount(); CField *field = dynamic_cast<CField*>(node->GetData()); if (field == NULL) { wxMessageBox("ERROR in CFieldsTreeCtrl::InsertField - at least one of the tree object is not a CField object", "Error", wxOK | wxICON_ERROR); return parentId; } if ((typeid(*field) == typeid(CFieldIndex)) && field->IsVirtual()) { return parentId; } if ( depth <= 1 ) { wxString str; str.Printf(wxT("%s"), field->GetName().c_str()); // here we pass to AppendItem() normal and selected item images (we // suppose that selected image follows the normal one in the enum) int32_t image = TreeCtrlIcon_Folder; int32_t imageSel = image + 1; wxTreeItemId id = AddRoot(str, image, image, new CFieldsTreeItemData(field)); return id; } bool hasChildren = numChildren > 0; wxString str; if (field->GetUnit().empty()) { str.Printf(wxT("%s"), field->GetName().c_str()); } else { str.Printf(wxT("%s (%s)"), field->GetName().c_str(), field->GetUnit().c_str()); } /* // at depth 1 elements won't have any more children if ( hasChildren ) { str.Printf(wxT("%s"), field->GetName().c_str()); } else { str.Printf(wxT("%s child %d.%d"), wxT("File"), folder, n + 1); } */ // here we pass to AppendItem() normal and selected item images (we // suppose that selected image follows the normal one in the enum) int32_t image = (hasChildren) ? TreeCtrlIcon_Folder : TreeCtrlIcon_File; int32_t imageSel = image + 1; //wxTreeItemId id = AppendItem(idParent, str, image, imageSel, // new MyTreeItemData(str)); wxTreeItemId id = AppendItem(parentId, str, image, imageSel, new CFieldsTreeItemData(field)); //Expand(parentId); if ( (typeid(*field) == typeid(CFieldRecord)) || ( (typeid(*field) == typeid(CFieldArray)) && (field->IsFixedSize() == false) ) ) { SetItemBold(id, true); //SetItemFont(parentId, *wxSWISS_FONT); //SetItemFont(rootId, *wxITALIC_FONT); } // and now we also set the expanded one (only for the folders) if ( hasChildren ) { SetItemImage(id, TreeCtrlIcon_FolderOpened, wxTreeItemIcon_Expanded); } // remember the last child for OnEnsureVisible() if ( !hasChildren ) { m_lastItem = id; } wxTreeItemId returnId; if (hasChildren) { returnId = id; } else { returnId = parentId; CObjectTreeNode* parentNode = node->GetParent(); while (parentNode != NULL) { if (parentNode->m_current == parentNode->GetChildren().end()) { returnId = GetItemParent(returnId); parentNode = parentNode->GetParent(); } else { break; } } } return returnId; }