2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 //-----------------------------------------------------------------------------
25 // classes used for describing geometry information from q3map feedback
30 #include "debugging/debugging.h"
33 #include "iselection.h"
37 #include "mainframe.h"
42 void Feedback_draw2D( VIEWTYPE viewType ){
43 g_DbgDlg.draw2D( viewType );
46 void CSelectMsg::saxStartElement( message_info_t *ctx, const xmlChar *name, const xmlChar **attrs ){
47 if ( string_equal( reinterpret_cast<const char*>( name ), "select" ) ) {
49 ESelectState = SELECT_MESSAGE;
54 ASSERT_MESSAGE( string_equal( reinterpret_cast<const char*>( name ), "brush" ), "FEEDBACK PARSE ERROR" );
55 ASSERT_MESSAGE( ESelectState == SELECT_MESSAGE, "FEEDBACK PARSE ERROR" );
56 ESelectState = SELECT_BRUSH;
57 globalOutputStream() << message.c_str() << '\n';
61 void CSelectMsg::saxEndElement( message_info_t *ctx, const xmlChar *name ){
62 if ( string_equal( reinterpret_cast<const char*>( name ), "select" ) ) {
66 void CSelectMsg::saxCharacters( message_info_t *ctx, const xmlChar *ch, int len ){
67 if ( ESelectState == SELECT_MESSAGE ) {
68 message.write( reinterpret_cast<const char*>( ch ), len );
72 brush.write( reinterpret_cast<const char*>( ch ), len );
76 IGL2DWindow* CSelectMsg::Highlight(){
77 GlobalSelectionSystem().setSelectedAll( false );
78 int entitynum, brushnum;
79 if ( sscanf( reinterpret_cast<const char*>( brush.c_str() ), "%i %i", &entitynum, &brushnum ) == 2 ) {
80 SelectBrush( entitynum, brushnum );
85 void CPointMsg::saxStartElement( message_info_t *ctx, const xmlChar *name, const xmlChar **attrs ){
86 if ( string_equal( reinterpret_cast<const char*>( name ), "pointmsg" ) ) {
88 EPointState = POINT_MESSAGE;
93 ASSERT_MESSAGE( string_equal( reinterpret_cast<const char*>( name ), "point" ), "FEEDBACK PARSE ERROR" );
94 ASSERT_MESSAGE( EPointState == POINT_MESSAGE, "FEEDBACK PARSE ERROR" );
95 EPointState = POINT_POINT;
96 globalOutputStream() << message.c_str() << '\n';
100 void CPointMsg::saxEndElement( message_info_t *ctx, const xmlChar *name ){
101 if ( string_equal( reinterpret_cast<const char*>( name ), "pointmsg" ) ) {
103 else if ( string_equal( reinterpret_cast<const char*>( name ), "point" ) ) {
104 sscanf( point.c_str(), "%g %g %g", &( pt[0] ), &( pt[1] ), &( pt[2] ) );
109 void CPointMsg::saxCharacters( message_info_t *ctx, const xmlChar *ch, int len ){
110 if ( EPointState == POINT_MESSAGE ) {
111 message.write( reinterpret_cast<const char*>( ch ), len );
115 ASSERT_MESSAGE( EPointState == POINT_POINT, "FEEDBACK PARSE ERROR" );
116 point.write( reinterpret_cast<const char*>( ch ), len );
120 IGL2DWindow* CPointMsg::Highlight(){
124 void CPointMsg::DropHighlight(){
127 void CPointMsg::Draw2D( VIEWTYPE vt ){
128 int nDim1 = ( vt == YZ ) ? 1 : 0;
129 int nDim2 = ( vt == XY ) ? 1 : 2;
131 glColor3f( 1.0f,0.0f,0.0f );
132 glBegin( GL_POINTS );
133 glVertex2f( pt[nDim1], pt[nDim2] );
135 glBegin( GL_LINE_LOOP );
136 glVertex2f( pt[nDim1] - 8, pt[nDim2] - 8 );
137 glVertex2f( pt[nDim1] + 8, pt[nDim2] - 8 );
138 glVertex2f( pt[nDim1] + 8, pt[nDim2] + 8 );
139 glVertex2f( pt[nDim1] - 8, pt[nDim2] + 8 );
143 void CWindingMsg::saxStartElement( message_info_t *ctx, const xmlChar *name, const xmlChar **attrs ){
144 if ( string_equal( reinterpret_cast<const char*>( name ), "windingmsg" ) ) {
146 EPointState = WINDING_MESSAGE;
151 ASSERT_MESSAGE( string_equal( reinterpret_cast<const char*>( name ), "winding" ), "FEEDBACK PARSE ERROR" );
152 ASSERT_MESSAGE( EPointState == WINDING_MESSAGE, "FEEDBACK PARSE ERROR" );
153 EPointState = WINDING_WINDING;
154 globalOutputStream() << message.c_str() << '\n';
158 void CWindingMsg::saxEndElement( message_info_t *ctx, const xmlChar *name ){
159 if ( string_equal( reinterpret_cast<const char*>( name ), "windingmsg" ) ) {
161 else if ( string_equal( reinterpret_cast<const char*>( name ), "winding" ) ) {
162 const char* c = winding.c_str();
163 sscanf( c, "%i ", &numpoints );
166 for (; i < numpoints; i++ )
168 c = strchr( c + 1, '(' );
169 if ( c ) { // even if we are given the number of points when the cycle begins .. don't trust it too much
170 sscanf( c, "(%g %g %g)", &wt[i][0], &wt[i][1], &wt[i][2] );
180 void CWindingMsg::saxCharacters( message_info_t *ctx, const xmlChar *ch, int len ){
181 if ( EPointState == WINDING_MESSAGE ) {
182 message.write( reinterpret_cast<const char*>( ch ), len );
186 ASSERT_MESSAGE( EPointState == WINDING_WINDING, "FEEDBACK PARSE ERROR" );
187 winding.write( reinterpret_cast<const char*>( ch ), len );
191 IGL2DWindow* CWindingMsg::Highlight(){
195 void CWindingMsg::DropHighlight(){
198 void CWindingMsg::Draw2D( VIEWTYPE vt ){
201 int nDim1 = ( vt == YZ ) ? 1 : 0;
202 int nDim2 = ( vt == XY ) ? 1 : 2;
203 glColor3f( 1.0f,0.f,0.0f );
206 glBegin( GL_POINTS );
207 for ( i = 0; i < numpoints; i++ )
208 glVertex2f( wt[i][nDim1], wt[i][nDim2] );
212 glEnable( GL_BLEND );
213 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
214 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
215 glColor4f( 0.133f,0.4f,1.0f,0.5f );
216 glBegin( GL_POLYGON );
217 for ( i = 0; i < numpoints; i++ )
218 glVertex2f( wt[i][nDim1], wt[i][nDim2] );
220 glDisable( GL_BLEND );
223 // triggered when the user selects an entry in the feedback box
224 static void feedback_selection_changed( GtkTreeSelection* selection, gpointer data ){
225 g_DbgDlg.DropHighlight();
228 GtkTreeIter selected;
229 if ( gtk_tree_selection_get_selected( selection, &model, &selected ) ) {
230 GtkTreePath* path = gtk_tree_model_get_path( model, &selected );
231 g_DbgDlg.SetHighlight( gtk_tree_path_get_indices( path )[0] );
232 gtk_tree_path_free( path );
236 void CDbgDlg::DropHighlight(){
237 if ( m_pHighlight != 0 ) {
238 m_pHighlight->DropHighlight();
244 void CDbgDlg::SetHighlight( gint row ){
245 ISAXHandler *h = GetElement( row );
247 m_pDraw2D = h->Highlight();
252 ISAXHandler *CDbgDlg::GetElement( std::size_t row ){
253 return static_cast<ISAXHandler *>( g_ptr_array_index( m_pFeedbackElements, gint( row ) ) );
256 void CDbgDlg::Init(){
259 // free all the ISAXHandler*, clean it
260 while ( m_pFeedbackElements->len )
262 static_cast<ISAXHandler *>( g_ptr_array_index( m_pFeedbackElements, 0 ) )->Release();
263 g_ptr_array_remove_index( m_pFeedbackElements, 0 );
266 if ( m_clist != NULL ) {
267 gtk_list_store_clear( m_clist );
271 void CDbgDlg::Push( ISAXHandler *pHandler ){
273 g_ptr_array_add( m_pFeedbackElements, (void *)pHandler );
275 if ( !GetWidget() ) {
279 // put stuff in the list
280 gtk_list_store_clear( m_clist );
281 for ( std::size_t i = 0; i < static_cast<std::size_t>( m_pFeedbackElements->len ); ++i )
284 gtk_list_store_append( m_clist, &iter );
285 gtk_list_store_set( m_clist, &iter, 0, GetElement( i )->getName(), -1 );
291 ui::Window CDbgDlg::BuildDialog(){
292 ui::Window window = MainFrame_getWindow().create_floating_window("Q3Map debug window" );
294 ui::Widget scr = ui::ScrolledWindow();
295 gtk_widget_show( scr );
296 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( scr ) );
297 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
298 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
301 ui::ListStore store = ui::ListStore(gtk_list_store_new( 1, G_TYPE_STRING ));
303 ui::Widget view = ui::TreeView(ui::TreeModel( GTK_TREE_MODEL( store ) ));
304 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( view ), FALSE );
307 auto renderer = ui::CellRendererText();
308 GtkTreeViewColumn* column = ui::TreeViewColumn( "", renderer, {{"text", 0}} );
309 gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
313 GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) );
314 gtk_tree_selection_set_mode( selection, GTK_SELECTION_BROWSE );
315 g_signal_connect( G_OBJECT( selection ), "changed", G_CALLBACK( feedback_selection_changed ), NULL );
318 gtk_widget_show( view );
320 gtk_container_add( GTK_CONTAINER( scr ), view );
322 g_object_unref( G_OBJECT( store ) );