]> icculus.org git repositories - taylor/freespace2.git/blob - src/pofview/objecttree.cpp
Initial revision
[taylor/freespace2.git] / src / pofview / objecttree.cpp
1 // ObjectTree.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5 #include "pofview.h"
6 #include "objecttree.h"
7 #include "pofviewdoc.h"
8 #include "pofviewview.h"
9
10
11 #include "model.h"
12
13 #ifdef _DEBUG
14 #define new DEBUG_NEW
15 #undef THIS_FILE
16 static char THIS_FILE[] = __FILE__;
17 #endif
18
19 /////////////////////////////////////////////////////////////////////////////
20 // CObjectTree dialog
21
22
23 CObjectTree::CObjectTree(CWnd* pParent /*=NULL*/)
24         : CDialog(CObjectTree::IDD, pParent)
25 {
26         //{{AFX_DATA_INIT(CObjectTree)
27         //}}AFX_DATA_INIT
28
29         m_pv = NULL;
30 }
31
32
33 void CObjectTree::DoDataExchange(CDataExchange* pDX)
34 {
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);
51         //}}AFX_DATA_MAP
52 }
53
54
55 BEGIN_MESSAGE_MAP(CObjectTree, CDialog)
56         //{{AFX_MSG_MAP(CObjectTree)
57         ON_NOTIFY(TVN_SELCHANGED, IDC_TREE1, OnSelchangedTree1)
58         //}}AFX_MSG_MAP
59 END_MESSAGE_MAP()
60
61 /////////////////////////////////////////////////////////////////////////////
62 // CObjectTree message handlers
63
64
65 void CObjectTree::add_model(polymodel *pm, int sm, HTREEITEM parent )
66 {
67         int i;
68         HTREEITEM citem;
69
70         // check for live debris
71         if ( !strnicmp("debris-", pm->submodel[sm].name, strlen("debris-")) ) {
72                 char debris_name[256];
73
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);
79
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 );
83                                 return;
84                         }
85                 }
86         }
87
88         if ( parent != NULL )
89                 citem = m_tree.InsertItem( pm->submodel[sm].name, parent );
90         else
91                 citem = m_tree.InsertItem( pm->submodel[sm].name );
92
93         m_tree.SetItemData( citem, sm );
94
95         for (i=pm->submodel[sm].first_child; i>-1; i = pm->submodel[i].next_sibling )   {
96                 add_model(pm, i, citem );
97         }
98
99 }
100
101 BOOL CObjectTree::OnInitDialog() 
102 {
103         CDialog::OnInitDialog();
104
105         {       
106                 CPofViewView * pv = (CPofViewView * )m_pv;
107                 if ( pv )       {
108                         CPofViewDoc* pDoc = pv->GetDocument();
109                         if ( pDoc->m_model_num > -1 )   {
110                                 polymodel * pm = model_get(pDoc->m_model_num);
111
112                                 int i;
113
114                                 sprintf( m_title, "%s's subobjects", pDoc->GetTitle() );
115
116                                 SetWindowText(m_title);
117                                                 
118                                 //m_tree.DeleteAllItems();
119
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);
126                                                 }
127                                         }
128                                 }
129
130                                 // Expand to make all tree visible for searching when adding live debris
131                                 ExpandAll();
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);
138                                                 }
139                                         }
140                                 }
141                                 CollapseAll();
142
143                         } else {
144                                 sprintf( m_title, "%s's subobjects", pDoc->GetTitle() );
145
146                                 SetWindowText(m_title);
147                         }
148
149                 }
150
151
152
153
154         }
155         
156         return TRUE;  // return TRUE unless you set the focus to a control
157                       // EXCEPTION: OCX Property Pages should return FALSE
158 }
159
160
161 void CObjectTree::MyCreate(void * pv)
162 {
163         m_pv = pv;
164
165         if (!GetSafeHwnd())
166                 Create(CObjectTree::IDD);
167
168         SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
169 }
170
171 void CObjectTree::OnSelchangedTree1(NMHDR* pNMHDR, LRESULT* pResult) 
172 {
173         NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
174         
175         if (pNMTreeView->hdr.code == TVN_SELCHANGED )           {
176                 CPofViewView * pv = (CPofViewView * )m_pv;
177                 if ( pv )       {
178                         CPofViewDoc* pDoc = pv->GetDocument();
179                         polymodel * pm = model_get(pDoc->m_model_num);
180                         bsp_info * sm = &pm->submodel[pNMTreeView->itemNew.lParam];
181
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("");
188
189                         m_txt_pof_info.SetWindowText("");
190
191
192                         if ( pm )       {
193                                 char tmp[1024];
194
195                                 sprintf( tmp, "%d.%02d", pm->version/100, pm->version %100 );
196                                 m_txt_bspgen_version.SetWindowText(tmp);
197
198                                 m_txt_name.SetWindowText(sm->name);
199
200                                 sprintf( tmp, "%d", submodel_get_num_polys(pDoc->m_model_num,pNMTreeView->itemNew.lParam) );
201                                 m_txt_num_polies.SetWindowText(tmp);
202
203                                 sprintf( tmp, "%d", submodel_get_num_verts(pDoc->m_model_num,pNMTreeView->itemNew.lParam) );
204                                 m_txt_num_verts.SetWindowText(tmp);
205
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;
211                                 }
212
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;
219                                         }
220                                 } else {
221                                         m_txt_movement_axis.SetWindowText("");
222                                 }
223
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);
236
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);
243                                 } else {
244                                         m_txt_pof_info.SetWindowText(pm->debug_info);
245                                 }
246
247                                 
248                         } else {
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("");
254                         }
255                 }
256                 
257         }
258         
259         *pResult = 0;
260 }
261
262 // Expand the tree making all first level visible
263 void CObjectTree::ExpandAll()
264 {
265         HTREEITEM citem;
266
267         for (citem = m_tree.GetFirstVisibleItem(); citem != NULL; citem = m_tree.GetNextVisibleItem(citem)) {
268                 m_tree.Expand(citem, TVE_EXPAND);
269         }
270
271 }
272
273 // Collapse all first level
274 void CObjectTree::CollapseAll()
275 {
276         HTREEITEM citem;
277
278         for (citem = m_tree.GetFirstVisibleItem(); citem != NULL; citem = m_tree.GetNextVisibleItem(citem)) {
279                 m_tree.Expand(citem, TVE_COLLAPSE);
280         }
281
282 }
283
284
285