]> icculus.org git repositories - taylor/freespace2.git/blob - src/pofview/objecttree.cpp
added copyright header
[taylor/freespace2.git] / src / pofview / objecttree.cpp
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
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
6  * the source.
7  */
8
9 // ObjectTree.cpp : implementation file
10 //
11
12 #include "stdafx.h"
13 #include "pofview.h"
14 #include "objecttree.h"
15 #include "pofviewdoc.h"
16 #include "pofviewview.h"
17
18
19 #include "model.h"
20
21 #ifdef _DEBUG
22 #define new DEBUG_NEW
23 #undef THIS_FILE
24 static char THIS_FILE[] = __FILE__;
25 #endif
26
27 /////////////////////////////////////////////////////////////////////////////
28 // CObjectTree dialog
29
30
31 CObjectTree::CObjectTree(CWnd* pParent /*=NULL*/)
32         : CDialog(CObjectTree::IDD, pParent)
33 {
34         //{{AFX_DATA_INIT(CObjectTree)
35         //}}AFX_DATA_INIT
36
37         m_pv = NULL;
38 }
39
40
41 void CObjectTree::DoDataExchange(CDataExchange* pDX)
42 {
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);
59         //}}AFX_DATA_MAP
60 }
61
62
63 BEGIN_MESSAGE_MAP(CObjectTree, CDialog)
64         //{{AFX_MSG_MAP(CObjectTree)
65         ON_NOTIFY(TVN_SELCHANGED, IDC_TREE1, OnSelchangedTree1)
66         //}}AFX_MSG_MAP
67 END_MESSAGE_MAP()
68
69 /////////////////////////////////////////////////////////////////////////////
70 // CObjectTree message handlers
71
72
73 void CObjectTree::add_model(polymodel *pm, int sm, HTREEITEM parent )
74 {
75         int i;
76         HTREEITEM citem;
77
78         // check for live debris
79         if ( !strnicmp("debris-", pm->submodel[sm].name, strlen("debris-")) ) {
80                 char debris_name[256];
81
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);
87
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 );
91                                 return;
92                         }
93                 }
94         }
95
96         if ( parent != NULL )
97                 citem = m_tree.InsertItem( pm->submodel[sm].name, parent );
98         else
99                 citem = m_tree.InsertItem( pm->submodel[sm].name );
100
101         m_tree.SetItemData( citem, sm );
102
103         for (i=pm->submodel[sm].first_child; i>-1; i = pm->submodel[i].next_sibling )   {
104                 add_model(pm, i, citem );
105         }
106
107 }
108
109 BOOL CObjectTree::OnInitDialog() 
110 {
111         CDialog::OnInitDialog();
112
113         {       
114                 CPofViewView * pv = (CPofViewView * )m_pv;
115                 if ( pv )       {
116                         CPofViewDoc* pDoc = pv->GetDocument();
117                         if ( pDoc->m_model_num > -1 )   {
118                                 polymodel * pm = model_get(pDoc->m_model_num);
119
120                                 int i;
121
122                                 sprintf( m_title, "%s's subobjects", pDoc->GetTitle() );
123
124                                 SetWindowText(m_title);
125                                                 
126                                 //m_tree.DeleteAllItems();
127
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);
134                                                 }
135                                         }
136                                 }
137
138                                 // Expand to make all tree visible for searching when adding live debris
139                                 ExpandAll();
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);
146                                                 }
147                                         }
148                                 }
149                                 CollapseAll();
150
151                         } else {
152                                 sprintf( m_title, "%s's subobjects", pDoc->GetTitle() );
153
154                                 SetWindowText(m_title);
155                         }
156
157                 }
158
159
160
161
162         }
163         
164         return TRUE;  // return TRUE unless you set the focus to a control
165                       // EXCEPTION: OCX Property Pages should return FALSE
166 }
167
168
169 void CObjectTree::MyCreate(void * pv)
170 {
171         m_pv = pv;
172
173         if (!GetSafeHwnd())
174                 Create(CObjectTree::IDD);
175
176         SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
177 }
178
179 void CObjectTree::OnSelchangedTree1(NMHDR* pNMHDR, LRESULT* pResult) 
180 {
181         NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
182         
183         if (pNMTreeView->hdr.code == TVN_SELCHANGED )           {
184                 CPofViewView * pv = (CPofViewView * )m_pv;
185                 if ( pv )       {
186                         CPofViewDoc* pDoc = pv->GetDocument();
187                         polymodel * pm = model_get(pDoc->m_model_num);
188                         bsp_info * sm = &pm->submodel[pNMTreeView->itemNew.lParam];
189
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("");
196
197                         m_txt_pof_info.SetWindowText("");
198
199
200                         if ( pm )       {
201                                 char tmp[1024];
202
203                                 sprintf( tmp, "%d.%02d", pm->version/100, pm->version %100 );
204                                 m_txt_bspgen_version.SetWindowText(tmp);
205
206                                 m_txt_name.SetWindowText(sm->name);
207
208                                 sprintf( tmp, "%d", submodel_get_num_polys(pDoc->m_model_num,pNMTreeView->itemNew.lParam) );
209                                 m_txt_num_polies.SetWindowText(tmp);
210
211                                 sprintf( tmp, "%d", submodel_get_num_verts(pDoc->m_model_num,pNMTreeView->itemNew.lParam) );
212                                 m_txt_num_verts.SetWindowText(tmp);
213
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;
219                                 }
220
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;
227                                         }
228                                 } else {
229                                         m_txt_movement_axis.SetWindowText("");
230                                 }
231
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);
244
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);
251                                 } else {
252                                         m_txt_pof_info.SetWindowText(pm->debug_info);
253                                 }
254
255                                 
256                         } else {
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("");
262                         }
263                 }
264                 
265         }
266         
267         *pResult = 0;
268 }
269
270 // Expand the tree making all first level visible
271 void CObjectTree::ExpandAll()
272 {
273         HTREEITEM citem;
274
275         for (citem = m_tree.GetFirstVisibleItem(); citem != NULL; citem = m_tree.GetNextVisibleItem(citem)) {
276                 m_tree.Expand(citem, TVE_EXPAND);
277         }
278
279 }
280
281 // Collapse all first level
282 void CObjectTree::CollapseAll()
283 {
284         HTREEITEM citem;
285
286         for (citem = m_tree.GetFirstVisibleItem(); citem != NULL; citem = m_tree.GetNextVisibleItem(citem)) {
287                 m_tree.Expand(citem, TVE_COLLAPSE);
288         }
289
290 }
291
292
293