1 // ObjectTree.cpp : implementation file
6 #include "objecttree.h"
7 #include "pofviewdoc.h"
8 #include "pofviewview.h"
16 static char THIS_FILE[] = __FILE__;
19 /////////////////////////////////////////////////////////////////////////////
23 CObjectTree::CObjectTree(CWnd* pParent /*=NULL*/)
24 : CDialog(CObjectTree::IDD, pParent)
26 //{{AFX_DATA_INIT(CObjectTree)
33 void CObjectTree::DoDataExchange(CDataExchange* pDX)
35 CDialog::DoDataExchange(pDX);
36 //{{AFX_DATA_MAP(CObjectTree)
37 DDX_Control(pDX, IDC_TXT_POF_INFO, m_txt_pof_info);
38 DDX_Control(pDX, IDC_TXT_DETAIL6, m_txt_detail6);
39 DDX_Control(pDX, IDC_TXT_DETAIL5, m_txt_detail5);
40 DDX_Control(pDX, IDC_TXT_DETAIL4, m_txt_detail4);
41 DDX_Control(pDX, IDC_TXT_DETAIL3, m_txt_detail3);
42 DDX_Control(pDX, IDC_TXT_DETAIIL1, m_txt_detail1);
43 DDX_Control(pDX, IDC_TXT_DETAIL2, m_txt_detail2);
44 DDX_Control(pDX, IDC_TXT_BSPGEN_VERSION, m_txt_bspgen_version);
45 DDX_Control(pDX, IDC_TXT_MOVEMENT_AXIS, m_txt_movement_axis);
46 DDX_Control(pDX, IDC_TXT_MOVEMENT_TYPE, m_txt_movement_type);
47 DDX_Control(pDX, IDC_TXT_NAME, m_txt_name);
48 DDX_Control(pDX, IDC_TXT_NUMPOLIES, m_txt_num_polies);
49 DDX_Control(pDX, IDC_TXT_NUM_VERTICES, m_txt_num_verts);
50 DDX_Control(pDX, IDC_TREE1, m_tree);
55 BEGIN_MESSAGE_MAP(CObjectTree, CDialog)
56 //{{AFX_MSG_MAP(CObjectTree)
57 ON_NOTIFY(TVN_SELCHANGED, IDC_TREE1, OnSelchangedTree1)
61 /////////////////////////////////////////////////////////////////////////////
62 // CObjectTree message handlers
65 void CObjectTree::add_model(polymodel *pm, int sm, HTREEITEM parent )
70 // check for live debris
71 if ( !strnicmp("debris-", pm->submodel[sm].name, strlen("debris-")) ) {
72 char debris_name[256];
74 // traverse the tree and put live debris with correct submodel
75 for (citem = m_tree.GetFirstVisibleItem(); citem != NULL; citem = m_tree.GetNextVisibleItem(citem)) {
76 CString item_text = m_tree.GetItemText(citem);
77 strcpy(debris_name, "debris-");
78 strcat(debris_name, item_text);
80 if ( strstr(pm->submodel[sm].name, debris_name) ) {
81 citem = m_tree.InsertItem( pm->submodel[sm].name, citem );
82 m_tree.SetItemData( citem, sm );
89 citem = m_tree.InsertItem( pm->submodel[sm].name, parent );
91 citem = m_tree.InsertItem( pm->submodel[sm].name );
93 m_tree.SetItemData( citem, sm );
95 for (i=pm->submodel[sm].first_child; i>-1; i = pm->submodel[i].next_sibling ) {
96 add_model(pm, i, citem );
101 BOOL CObjectTree::OnInitDialog()
103 CDialog::OnInitDialog();
106 CPofViewView * pv = (CPofViewView * )m_pv;
108 CPofViewDoc* pDoc = pv->GetDocument();
109 if ( pDoc->m_model_num > -1 ) {
110 polymodel * pm = model_get(pDoc->m_model_num);
114 sprintf( m_title, "%s's subobjects", pDoc->GetTitle() );
116 SetWindowText(m_title);
118 //m_tree.DeleteAllItems();
120 // add all base submodels (ie, without parents) except live debris
121 for (i=0; i<pm->n_models; i++) {
122 if ( pm->submodel[i].parent < 0) {
123 // add if *not* live debris
124 if ( strnicmp("debris-", pm->submodel[i].name, strlen("debris-")) ) {
125 add_model(pm, i, NULL);
130 // Expand to make all tree visible for searching when adding live debris
132 // Now add any live debris
133 for (i=0; i<pm->n_models; i++) {
134 if ( pm->submodel[i].parent < 0) {
135 // add if live debris
136 if ( !strnicmp("debris-", pm->submodel[i].name, strlen("debris-")) ) {
137 add_model(pm, i, NULL);
144 sprintf( m_title, "%s's subobjects", pDoc->GetTitle() );
146 SetWindowText(m_title);
156 return TRUE; // return TRUE unless you set the focus to a control
157 // EXCEPTION: OCX Property Pages should return FALSE
161 void CObjectTree::MyCreate(void * pv)
166 Create(CObjectTree::IDD);
168 SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
171 void CObjectTree::OnSelchangedTree1(NMHDR* pNMHDR, LRESULT* pResult)
173 NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
175 if (pNMTreeView->hdr.code == TVN_SELCHANGED ) {
176 CPofViewView * pv = (CPofViewView * )m_pv;
178 CPofViewDoc* pDoc = pv->GetDocument();
179 polymodel * pm = model_get(pDoc->m_model_num);
180 bsp_info * sm = &pm->submodel[pNMTreeView->itemNew.lParam];
182 m_txt_detail1.SetWindowText("");
183 m_txt_detail2.SetWindowText("");
184 m_txt_detail3.SetWindowText("");
185 m_txt_detail4.SetWindowText("");
186 m_txt_detail5.SetWindowText("");
187 m_txt_detail6.SetWindowText("");
189 m_txt_pof_info.SetWindowText("");
195 sprintf( tmp, "%d.%02d", pm->version/100, pm->version %100 );
196 m_txt_bspgen_version.SetWindowText(tmp);
198 m_txt_name.SetWindowText(sm->name);
200 sprintf( tmp, "%d", submodel_get_num_polys(pDoc->m_model_num,pNMTreeView->itemNew.lParam) );
201 m_txt_num_polies.SetWindowText(tmp);
203 sprintf( tmp, "%d", submodel_get_num_verts(pDoc->m_model_num,pNMTreeView->itemNew.lParam) );
204 m_txt_num_verts.SetWindowText(tmp);
206 switch( sm->movement_type ) {
207 case -1: m_txt_movement_type.SetWindowText("None");break;
208 case 0: m_txt_movement_type.SetWindowText("Positional");break;
209 case 1: m_txt_movement_type.SetWindowText("Rotational");break;
210 default: m_txt_movement_type.SetWindowText("?Unknown?");break;
213 if (sm->movement_type==1) {
214 switch(sm->movement_axis) {
215 case 0:m_txt_movement_axis.SetWindowText("X (Pitch)");break;
216 case 1:m_txt_movement_axis.SetWindowText("Y (Bank)");break;
217 case 2:m_txt_movement_axis.SetWindowText("Z (Heading)");break;
218 default:m_txt_movement_axis.SetWindowText("?Unknown?");break;
221 m_txt_movement_axis.SetWindowText("");
224 if ( sm->num_details > 0 )
225 m_txt_detail1.SetWindowText(pm->submodel[sm->details[0]].name);
226 if ( sm->num_details > 1 )
227 m_txt_detail2.SetWindowText(pm->submodel[sm->details[1]].name);
228 if ( sm->num_details > 2 )
229 m_txt_detail3.SetWindowText(pm->submodel[sm->details[2]].name);
230 if ( sm->num_details > 3 )
231 m_txt_detail4.SetWindowText(pm->submodel[sm->details[3]].name);
232 if ( sm->num_details > 4 )
233 m_txt_detail5.SetWindowText(pm->submodel[sm->details[4]].name);
234 if ( sm->num_details > 5 )
235 m_txt_detail6.SetWindowText(pm->submodel[sm->details[5]].name);
237 if ( sm->i_replace > -1 ) {
238 sprintf( tmp, "%s\n[I replace %s]", pm->debug_info, pm->submodel[sm->i_replace].name );
239 m_txt_pof_info.SetWindowText(tmp);
240 } else if ( sm->my_replacement > -1 ) {
241 sprintf( tmp, "%s\n[My replacment %s]", pm->debug_info, pm->submodel[sm->my_replacement].name );
242 m_txt_pof_info.SetWindowText(tmp);
244 m_txt_pof_info.SetWindowText(pm->debug_info);
249 m_txt_name.SetWindowText("");
250 m_txt_num_polies.SetWindowText("");
251 m_txt_num_verts.SetWindowText("");
252 m_txt_movement_axis.SetWindowText("");
253 m_txt_movement_type.SetWindowText("");
262 // Expand the tree making all first level visible
263 void CObjectTree::ExpandAll()
267 for (citem = m_tree.GetFirstVisibleItem(); citem != NULL; citem = m_tree.GetNextVisibleItem(citem)) {
268 m_tree.Expand(citem, TVE_EXPAND);
273 // Collapse all first level
274 void CObjectTree::CollapseAll()
278 for (citem = m_tree.GetFirstVisibleItem(); citem != NULL; citem = m_tree.GetNextVisibleItem(citem)) {
279 m_tree.Expand(citem, TVE_COLLAPSE);