summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmpovrayrenderwidget.h
blob: 0e3a77862416519f90b89d4919dc617352711906 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
**************************************************************************
                                 description
                             --------------------
    copyright            : (C) 2001-2002 by Andreas Zehender
    email                : zehender@kde.org
**************************************************************************

**************************************************************************
*                                                                        *
*  This program is free software; you can redistribute it and/or modify  *
*  it under the terms of the GNU General Public License as published by  *
*  the Free Software Foundation; either version 2 of the License, or     *
*  (at your option) any later version.                                   *
*                                                                        *
**************************************************************************/

#ifndef PMPOVRAYRENDERWIDGET_H
#define PMPOVRAYRENDERWIDGET_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <tqwidget.h>
#include <tqcstring.h>
#include <tqimage.h>
#include <tqbuffer.h>
#include <tqstringlist.h>

#include "pmrendermode.h"
#include "pmdragwidget.h"

class TDEProcess;
class TDEConfig;
class KURL;
class KTempFile;

/**
 * Widget that calls povray to render a scene and
 * displays the output.
 */
class PMPovrayRenderWidget : public PMDragWidget
{
   Q_OBJECT
  
public:
   /**
    * Standard constructor
    */
   PMPovrayRenderWidget( TQWidget* parent = 0, const char* name = 0 );
   /**
    * destructor
    */
   virtual ~PMPovrayRenderWidget( );

   /**
    * Starts rendering for the povray code in the byte array with
    * render mode m.
    * @see PMRenderMode
    */
   bool render( const TQByteArray& scene, const PMRenderMode& m,
                const KURL& documentURL );

   /**
    * Returns the povray text output
    */
   TQString povrayOutput( ) const { return m_povrayOutput; }
   /**
    * Returns the rendered image
    */
   TQImage image( ) const { return m_image; }
   
   static void saveConfig( TDEConfig* cfg );
   static void restoreConfig( TDEConfig* cfg );

   /**
    * Returns the povray command
    */
   static TQString povrayCommand( ) { return s_povrayCommand; }
   /**
    * Sets the povray command
    */
   static void setPovrayCommand( const TQString& c ) { s_povrayCommand = c; }
   /**
    * Returns the library paths
    */
   static TQStringList povrayLibraryPaths( ) { return s_libraryPaths; }
   /**
    * Sets the library paths
    */
   static void setPovrayLibraryPaths( const TQStringList& slist )
   { s_libraryPaths = slist; }
   virtual TQSize sizeHint( ) const;

   virtual void startDrag( );
signals:
   /**
    * Emitted when rendering has finished
    */
   void finished( int exitStatus );
   /**
    * Provides progress information
    */
   void progress( int percent );
   /**
    * Provides progress imformation
    */
   void lineFinished( int line );
   /**
    * The povray output text
    */
   void povrayMessage( const TQString& msg );
   
public slots:
   /**
    * Kills rendering
    */
   void killRendering( );
   /**
    * Suspends rendering
    */
   void suspendRendering( );
   /**
    * Resumes rendering
    */
   void resumeRendering( );

protected slots:
   /**
    * Receive povray messages
    */
   void slotPovrayMessage( TDEProcess* proc, char* buffer, int buflen );
   /**
    * Receive rendered image
    */
   void slotPovrayImage( TDEProcess* proc, char* buffer, int buflen );
   /**
    * Called when output has been written to the povray process
    */
   //void slotWroteStdin( TDEProcess* proc );
   /**
    * Called when the process has finished
    */
   void slotRenderingFinished( TDEProcess* proc );
   
protected:
   virtual void paintEvent( TQPaintEvent* );
      
private:
   void setPixel( int x, int y, uint c );
   void cleanup( );
   
   TDEProcess* m_pProcess;
   bool m_bSuspended;
   PMRenderMode m_renderMode;
   TQImage m_image;
   bool m_rcvHeader;
   unsigned char m_header[18];
   int m_rcvHeaderBytes;
   int m_skipBytes;
   int m_bytespp;
   int m_rcvPixels;
   int m_progress;
   unsigned char m_restBytes[4];
   int m_numRestBytes;
   int m_line;
   int m_column;
   TQPixmap m_pixmap;
   bool m_bPixmapUpToDate;
   TQString m_povrayOutput;
   KTempFile* m_pTempFile;

   static TQString s_povrayCommand;
   static TQStringList s_libraryPaths;
};

#endif