2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
9 // ObjectTree.cpp : implementation file
14 #include "objecttree.h"
15 #include "pofviewdoc.h"
16 #include "pofviewview.h"
24 static char THIS_FILE[] = __FILE__;
27 /////////////////////////////////////////////////////////////////////////////
31 CObjectTree::CObjectTree(CWnd* pParent /*=NULL*/)
32 : CDialog(CObjectTree::IDD, pParent)
34 //{{AFX_DATA_INIT(CObjectTree)
41 void CObjectTree::DoDataExchange(CDataExchange* pDX)
43 CDialog::DoDataExchange(pDX);
44 //{{AFX_DATA_MAP(CObjectTree)
45 DDX_Control(pDX, IDC_TXT_POF_INFO, m_txt_pof_info);
46 DDX_Control(pDX, IDC_TXT_DETAIL6, m_txt_detail6);
47 DDX_Control(pDX, IDC_TXT_DETAIL5, m_txt_detail5);
48 DDX_Control(pDX, IDC_TXT_DETAIL4, m_txt_detail4);
49 DDX_Control(pDX, IDC_TXT_DETAIL3, m_txt_detail3);
50 DDX_Control(pDX, IDC_TXT_DETAIIL1, m_txt_detail1);
51 DDX_Control(pDX, IDC_TXT_DETAIL2, m_txt_detail2);
52 DDX_Control(pDX, IDC_TXT_BSPGEN_VERSION, m_txt_bspgen_version);
53 DDX_Control(pDX, IDC_TXT_MOVEMENT_AXIS, m_txt_movement_axis);
54 DDX_Control(pDX, IDC_TXT_MOVEMENT_TYPE, m_txt_movement_type);
55 DDX_Control(pDX, IDC_TXT_NAME, m_txt_name);
56 DDX_Control(pDX, IDC_TXT_NUMPOLIES, m_txt_num_polies);
57 DDX_Control(pDX, IDC_TXT_NUM_VERTICES, m_txt_num_verts);
58 DDX_Control(pDX, IDC_TREE1, m_tree);
63 BEGIN_MESSAGE_MAP(CObjectTree, CDialog)
64 //{{AFX_MSG_MAP(CObjectTree)
65 ON_NOTIFY(TVN_SELCHANGED, IDC_TREE1, OnSelchangedTree1)
69 /////////////////////////////////////////////////////////////////////////////
70 // CObjectTree message handlers
73 void CObjectTree::add_model(polymodel *pm, int sm, HTREEITEM parent )
78 // check for live debris
79 if ( !strnicmp("debris-", pm->submodel[sm].name, strlen("debris-")) ) {
80 char debris_name[256];
82 // traverse the tree and put live debris with correct submodel
83 for (citem = m_tree.GetFirstVisibleItem(); citem != NULL; citem = m_tree.GetNextVisibleItem(citem)) {
84 CString item_text = m_tree.GetItemText(citem);
85 strcpy(debris_name, "debris-");
86 strcat(debris_name, item_text);
88 if ( strstr(pm->submodel[sm].name, debris_name) ) {
89 citem = m_tree.InsertItem( pm->submodel[sm].name, citem );
90 m_tree.SetItemData( citem, sm );
97 citem = m_tree.InsertItem( pm->submodel[sm].name, parent );
99 citem = m_tree.InsertItem( pm->submodel[sm].name );
101 m_tree.SetItemData( citem, sm );
103 for (i=pm->submodel[sm].first_child; i>-1; i = pm->submodel[i].next_sibling ) {
104 add_model(pm, i, citem );
109 BOOL CObjectTree::OnInitDialog()
111 CDialog::OnInitDialog();
114 CPofViewView * pv = (CPofViewView * )m_pv;
116 CPofViewDoc* pDoc = pv->GetDocument();
117 if ( pDoc->m_model_num > -1 ) {
118 polymodel * pm = model_get(pDoc->m_model_num);
122 sprintf( m_title, "%s's subobjects", pDoc->GetTitle() );
124 SetWindowText(m_title);
126 //m_tree.DeleteAllItems();
128 // add all base submodels (ie, without parents) except live debris
129 for (i=0; i<pm->n_models; i++) {
130 if ( pm->submodel[i].parent < 0) {
131 // add if *not* live debris
132 if ( strnicmp("debris-", pm->submodel[i].name, strlen("debris-")) ) {
133 add_model(pm, i, NULL);
138 // Expand to make all tree visible for searching when adding live debris
140 // Now add any live debris
141 for (i=0; i<pm->n_models; i++) {
142 if ( pm->submodel[i].parent < 0) {
143 // add if live debris
144 if ( !strnicmp("debris-", pm->submodel[i].name, strlen("debris-")) ) {
145 add_model(pm, i, NULL);
152 sprintf( m_title, "%s's subobjects", pDoc->GetTitle() );
154 SetWindowText(m_title);
164 return TRUE; // return TRUE unless you set the focus to a control
165 // EXCEPTION: OCX Property Pages should return FALSE
169 void CObjectTree::MyCreate(void * pv)
174 Create(CObjectTree::IDD);
176 SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
179 void CObjectTree::OnSelchangedTree1(NMHDR* pNMHDR, LRESULT* pResult)
181 NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
183 if (pNMTreeView->hdr.code == TVN_SELCHANGED ) {
184 CPofViewView * pv = (CPofViewView * )m_pv;
186 CPofViewDoc* pDoc = pv->GetDocument();
187 polymodel * pm = model_get(pDoc->m_model_num);
188 bsp_info * sm = &pm->submodel[pNMTreeView->itemNew.lParam];
190 m_txt_detail1.SetWindowText("");
191 m_txt_detail2.SetWindowText("");
192 m_txt_detail3.SetWindowText("");
193 m_txt_detail4.SetWindowText("");
194 m_txt_detail5.SetWindowText("");
195 m_txt_detail6.SetWindowText("");
197 m_txt_pof_info.SetWindowText("");
203 sprintf( tmp, "%d.%02d", pm->version/100, pm->version %100 );
204 m_txt_bspgen_version.SetWindowText(tmp);
206 m_txt_name.SetWindowText(sm->name);
208 sprintf( tmp, "%d", submodel_get_num_polys(pDoc->m_model_num,pNMTreeView->itemNew.lParam) );
209 m_txt_num_polies.SetWindowText(tmp);
211 sprintf( tmp, "%d", submodel_get_num_verts(pDoc->m_model_num,pNMTreeView->itemNew.lParam) );
212 m_txt_num_verts.SetWindowText(tmp);
214 switch( sm->movement_type ) {
215 case -1: m_txt_movement_type.SetWindowText("None");break;
216 case 0: m_txt_movement_type.SetWindowText("Positional");break;
217 case 1: m_txt_movement_type.SetWindowText("Rotational");break;
218 default: m_txt_movement_type.SetWindowText("?Unknown?");break;
221 if (sm->movement_type==1) {
222 switch(sm->movement_axis) {
223 case 0:m_txt_movement_axis.SetWindowText("X (Pitch)");break;
224 case 1:m_txt_movement_axis.SetWindowText("Y (Bank)");break;
225 case 2:m_txt_movement_axis.SetWindowText("Z (Heading)");break;
226 default:m_txt_movement_axis.SetWindowText("?Unknown?");break;
229 m_txt_movement_axis.SetWindowText("");
232 if ( sm->num_details > 0 )
233 m_txt_detail1.SetWindowText(pm->submodel[sm->details[0]].name);
234 if ( sm->num_details > 1 )
235 m_txt_detail2.SetWindowText(pm->submodel[sm->details[1]].name);
236 if ( sm->num_details > 2 )
237 m_txt_detail3.SetWindowText(pm->submodel[sm->details[2]].name);
238 if ( sm->num_details > 3 )
239 m_txt_detail4.SetWindowText(pm->submodel[sm->details[3]].name);
240 if ( sm->num_details > 4 )
241 m_txt_detail5.SetWindowText(pm->submodel[sm->details[4]].name);
242 if ( sm->num_details > 5 )
243 m_txt_detail6.SetWindowText(pm->submodel[sm->details[5]].name);
245 if ( sm->i_replace > -1 ) {
246 sprintf( tmp, "%s\n[I replace %s]", pm->debug_info, pm->submodel[sm->i_replace].name );
247 m_txt_pof_info.SetWindowText(tmp);
248 } else if ( sm->my_replacement > -1 ) {
249 sprintf( tmp, "%s\n[My replacment %s]", pm->debug_info, pm->submodel[sm->my_replacement].name );
250 m_txt_pof_info.SetWindowText(tmp);
252 m_txt_pof_info.SetWindowText(pm->debug_info);
257 m_txt_name.SetWindowText("");
258 m_txt_num_polies.SetWindowText("");
259 m_txt_num_verts.SetWindowText("");
260 m_txt_movement_axis.SetWindowText("");
261 m_txt_movement_type.SetWindowText("");
270 // Expand the tree making all first level visible
271 void CObjectTree::ExpandAll()
275 for (citem = m_tree.GetFirstVisibleItem(); citem != NULL; citem = m_tree.GetNextVisibleItem(citem)) {
276 m_tree.Expand(citem, TVE_EXPAND);
281 // Collapse all first level
282 void CObjectTree::CollapseAll()
286 for (citem = m_tree.GetFirstVisibleItem(); citem != NULL; citem = m_tree.GetNextVisibleItem(citem)) {
287 m_tree.Expand(citem, TVE_COLLAPSE);