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
32 #include "debugging/debugging.h"
35 #include "iselection.h"
39 #include "mainframe.h"
44 void Feedback_draw2D( VIEWTYPE viewType ){
45 g_DbgDlg.draw2D( viewType );
48 void CSelectMsg::saxStartElement( message_info_t *ctx, const xmlChar *name, const xmlChar **attrs ){
49 if ( string_equal( reinterpret_cast<const char*>( name ), "select" ) ) {
51 ESelectState = SELECT_MESSAGE;
56 ASSERT_MESSAGE( string_equal( reinterpret_cast<const char*>( name ), "brush" ), "FEEDBACK PARSE ERROR" );
57 ASSERT_MESSAGE( ESelectState == SELECT_MESSAGE, "FEEDBACK PARSE ERROR" );
58 ESelectState = SELECT_BRUSH;
59 globalOutputStream() << message.c_str() << '\n';
63 void CSelectMsg::saxEndElement( message_info_t *ctx, const xmlChar *name ){
64 if ( string_equal( reinterpret_cast<const char*>( name ), "select" ) ) {
68 void CSelectMsg::saxCharacters( message_info_t *ctx, const xmlChar *ch, int len ){
69 if ( ESelectState == SELECT_MESSAGE ) {
70 message.write( reinterpret_cast<const char*>( ch ), len );
74 brush.write( reinterpret_cast<const char*>( ch ), len );
78 IGL2DWindow* CSelectMsg::Highlight(){
79 GlobalSelectionSystem().setSelectedAll( false );
80 int entitynum, brushnum;
81 if ( sscanf( reinterpret_cast<const char*>( brush.c_str() ), "%i %i", &entitynum, &brushnum ) == 2 ) {
82 SelectBrush( entitynum, brushnum );
87 void CPointMsg::saxStartElement( message_info_t *ctx, const xmlChar *name, const xmlChar **attrs ){
88 if ( string_equal( reinterpret_cast<const char*>( name ), "pointmsg" ) ) {
90 EPointState = POINT_MESSAGE;
95 ASSERT_MESSAGE( string_equal( reinterpret_cast<const char*>( name ), "point" ), "FEEDBACK PARSE ERROR" );
96 ASSERT_MESSAGE( EPointState == POINT_MESSAGE, "FEEDBACK PARSE ERROR" );
97 EPointState = POINT_POINT;
98 globalOutputStream() << message.c_str() << '\n';
102 void CPointMsg::saxEndElement( message_info_t *ctx, const xmlChar *name ){
103 if ( string_equal( reinterpret_cast<const char*>( name ), "pointmsg" ) ) {
105 else if ( string_equal( reinterpret_cast<const char*>( name ), "point" ) ) {
106 sscanf( point.c_str(), "%g %g %g", &( pt[0] ), &( pt[1] ), &( pt[2] ) );
111 void CPointMsg::saxCharacters( message_info_t *ctx, const xmlChar *ch, int len ){
112 if ( EPointState == POINT_MESSAGE ) {
113 message.write( reinterpret_cast<const char*>( ch ), len );
117 ASSERT_MESSAGE( EPointState == POINT_POINT, "FEEDBACK PARSE ERROR" );
118 point.write( reinterpret_cast<const char*>( ch ), len );
122 IGL2DWindow* CPointMsg::Highlight(){
126 void CPointMsg::DropHighlight(){
129 void CPointMsg::Draw2D( VIEWTYPE vt ){
130 int nDim1 = ( vt == YZ ) ? 1 : 0;
131 int nDim2 = ( vt == XY ) ? 1 : 2;
133 glColor3f( 1.0f,0.0f,0.0f );
134 glBegin( GL_POINTS );
135 glVertex2f( pt[nDim1], pt[nDim2] );
137 glBegin( GL_LINE_LOOP );
138 glVertex2f( pt[nDim1] - 8, pt[nDim2] - 8 );
139 glVertex2f( pt[nDim1] + 8, pt[nDim2] - 8 );
140 glVertex2f( pt[nDim1] + 8, pt[nDim2] + 8 );
141 glVertex2f( pt[nDim1] - 8, pt[nDim2] + 8 );
145 void CWindingMsg::saxStartElement( message_info_t *ctx, const xmlChar *name, const xmlChar **attrs ){
146 if ( string_equal( reinterpret_cast<const char*>( name ), "windingmsg" ) ) {
148 EPointState = WINDING_MESSAGE;
153 ASSERT_MESSAGE( string_equal( reinterpret_cast<const char*>( name ), "winding" ), "FEEDBACK PARSE ERROR" );
154 ASSERT_MESSAGE( EPointState == WINDING_MESSAGE, "FEEDBACK PARSE ERROR" );
155 EPointState = WINDING_WINDING;
156 globalOutputStream() << message.c_str() << '\n';
160 void CWindingMsg::saxEndElement( message_info_t *ctx, const xmlChar *name ){
161 if ( string_equal( reinterpret_cast<const char*>( name ), "windingmsg" ) ) {
163 else if ( string_equal( reinterpret_cast<const char*>( name ), "winding" ) ) {
164 const char* c = winding.c_str();
165 sscanf( c, "%i ", &numpoints );
168 for (; i < numpoints; i++ )
170 c = strchr( c + 1, '(' );
171 if ( c ) { // even if we are given the number of points when the cycle begins .. don't trust it too much
172 sscanf( c, "(%g %g %g)", &wt[i][0], &wt[i][1], &wt[i][2] );
182 void CWindingMsg::saxCharacters( message_info_t *ctx, const xmlChar *ch, int len ){
183 if ( EPointState == WINDING_MESSAGE ) {
184 message.write( reinterpret_cast<const char*>( ch ), len );
188 ASSERT_MESSAGE( EPointState == WINDING_WINDING, "FEEDBACK PARSE ERROR" );
189 winding.write( reinterpret_cast<const char*>( ch ), len );
193 IGL2DWindow* CWindingMsg::Highlight(){
197 void CWindingMsg::DropHighlight(){
200 void CWindingMsg::Draw2D( VIEWTYPE vt ){
203 int nDim1 = ( vt == YZ ) ? 1 : 0;
204 int nDim2 = ( vt == XY ) ? 1 : 2;
205 glColor3f( 1.0f,0.f,0.0f );
208 glBegin( GL_POINTS );
209 for ( i = 0; i < numpoints; i++ )
210 glVertex2f( wt[i][nDim1], wt[i][nDim2] );
214 glEnable( GL_BLEND );
215 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
216 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
217 glColor4f( 0.133f,0.4f,1.0f,0.5f );
218 glBegin( GL_POLYGON );
219 for ( i = 0; i < numpoints; i++ )
220 glVertex2f( wt[i][nDim1], wt[i][nDim2] );
222 glDisable( GL_BLEND );
225 // triggered when the user selects an entry in the feedback box
226 static void feedback_selection_changed( GtkTreeSelection* selection, gpointer data ){
227 g_DbgDlg.DropHighlight();
230 GtkTreeIter selected;
231 if ( gtk_tree_selection_get_selected( selection, &model, &selected ) ) {
232 GtkTreePath* path = gtk_tree_model_get_path( model, &selected );
233 g_DbgDlg.SetHighlight( gtk_tree_path_get_indices( path )[0] );
234 gtk_tree_path_free( path );
238 void CDbgDlg::DropHighlight(){
239 if ( m_pHighlight != 0 ) {
240 m_pHighlight->DropHighlight();
246 void CDbgDlg::SetHighlight( gint row ){
247 ISAXHandler *h = GetElement( row );
249 m_pDraw2D = h->Highlight();
254 ISAXHandler *CDbgDlg::GetElement( std::size_t row ){
255 return static_cast<ISAXHandler *>( g_ptr_array_index( m_pFeedbackElements, gint( row ) ) );
258 void CDbgDlg::Init(){
261 // free all the ISAXHandler*, clean it
262 while ( m_pFeedbackElements->len )
264 static_cast<ISAXHandler *>( g_ptr_array_index( m_pFeedbackElements, 0 ) )->Release();
265 g_ptr_array_remove_index( m_pFeedbackElements, 0 );
273 void CDbgDlg::Push( ISAXHandler *pHandler ){
275 g_ptr_array_add( m_pFeedbackElements, (void *)pHandler );
277 if ( !GetWidget() ) {
281 // put stuff in the list
283 for ( std::size_t i = 0; i < static_cast<std::size_t>( m_pFeedbackElements->len ); ++i )
285 m_clist.append(0, GetElement(i)->getName());
291 ui::Window CDbgDlg::BuildDialog(){
292 auto window = MainFrame_getWindow().create_floating_window("Q3Map debug window" );
294 auto scr = ui::ScrolledWindow(ui::New);
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(store ));
304 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( view ), FALSE );
307 auto renderer = ui::CellRendererText(ui::New);
308 GtkTreeViewColumn* column = ui::TreeViewColumn( "", renderer, {{"text", 0}} );
309 gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
313 auto selection = ui::TreeSelection(gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) ));
314 gtk_tree_selection_set_mode( selection, GTK_SELECTION_BROWSE );
315 selection.connect( "changed", G_CALLBACK( feedback_selection_changed ), NULL );