source: projectionDesigner/trunk/projdesigner/include/interfaces.h

Last change on this file was 433, checked in by Torben Dannhauer, 11 years ago
File size: 16.6 KB
Line 
1#ifndef INTERFACES_H
2#define INTERFACES_H
3
4#include <QtGui>
5#include <QWidget>
6#include <QtXml>
7#include <QtOpenGL/QGLWidget>   // added! [ben 27Sep13]
8
9//#include <QGLViewer/frame.h>
10
11class ProjectorWidget;
12class ProjectorData;
13
14/**
15 * Projector plugin interface class to have common interface with all projector plugins.
16 *
17 */
18class ProjectorInterface
19{
20
21public:
22
23
24    /**
25     * Destructor (virtual because the class is pure virtual).
26     *
27     */
28    virtual ~ProjectorInterface() {}
29
30
31    /**
32     * Gets the name of the plugin.
33     *
34     * @return The name of the plugin.
35     *
36     */
37    virtual QString name(void) const = 0;
38
39
40    /**
41     * Gets the list of the available projectors.
42     *
43     * @return The list of the available projectors.
44     *
45     */
46    virtual QStringList projectors(void) const = 0;
47
48
49    /**
50     * Instanciates a new ProjectorWidget for the specified projector.
51     * This function is called by the QChannelWidget constructor, when the
52     * stackedWidget is built.
53     *
54     * @param projector A const reference on a string that contains the name of
55     *                  the projector, such as projectors() has returned it.
56     *
57     * @return A pointer on the new instanciated ProjectorWidget.
58     *
59     */
60    virtual ProjectorWidget *newProjectorWidget(const QString& projector) = 0;
61
62
63    /**
64     * Instanciates a new ProjectorData for the specified projector.
65     * This function is called by the Channel when it needs to create or copy
66     * some ProjectorData.
67     *
68     * @param projector A const reference on a string that contains the name of
69     *                  the projector, such as projectors() has returned it.
70     *
71     * @return A pointer on the new instanciated ProjectorData.
72     *
73     */
74    virtual ProjectorData *newProjectorData(const QString& projector) = 0;
75
76};
77
78
79/**
80 * Projector data class to store informations about Projectors.
81 * This class is not a pure virtual class, so projector plugins does not need to
82 * instanciate it if it is not necessary.
83 *
84 */
85class ProjectorData
86{
87
88public:
89
90
91    /**
92     * Constructor.
93     *
94     * @param plugin A pointer on the plugin that owns the projector.
95     *
96     */
97    ProjectorData(ProjectorInterface *plugin):
98        m_bShow(true),
99        m_bShowArea(true),
100        m_plugin(plugin)
101        {
102            Q_ASSERT(NULL!=plugin);
103        }
104
105
106    /**
107     * Copy constructor.
108     *
109     * @param data A const reference on the source data.
110     *
111     */
112    ProjectorData (const ProjectorData& data)
113        {
114            copy_from(data);
115        }
116
117
118    /**
119     * Destructor.
120     *
121     */
122    virtual ~ProjectorData() {}
123
124
125    /**
126     * Gets the ProjectorInterface which instanciated the ProjectorData.
127     *
128     * @return A pointer on the ProjectorInterface which instanciated the
129     *         ProjectorData.
130     *
131     */
132    ProjectorInterface* plugin() {return m_plugin;}
133
134
135    /**
136     * Gets the ProjectorInterface which instanciated the ProjectorData.
137     * This fonction differs from the previous one by the "const" attribute.
138     *
139     * @return A const pointer on the ProjectorInterface which instanciated the
140     *         ProjectorData.
141     *
142     */
143    const ProjectorInterface* plugin() const {return m_plugin;}
144
145
146    /**
147     * Draws the projector.
148     * This method draws the geometric projector data. For instance, for a
149     * standard projector, it draws the frustum in the scene.
150     *
151     * @param bSelected true if the projector is selected.
152     *
153     */
154    virtual void draw(bool bSelected) {Q_UNUSED(bSelected);}
155
156
157    /**
158     * Starts the rendering through the projector.
159     * For a standard projector, this is the call to 'glFrustum()'.
160     *
161     */
162    virtual void beginDraw(void){}
163
164
165    /**
166     * Ends the rendering through the projector.
167     * For a standard projector, this is the call to 'glPop...()'.
168     * This method restores the state of OpenGL before the call to beginDraw().
169     *
170     */
171    virtual void endDraw(void){}
172
173
174    /**
175     * Starts the projection of the image.
176     * This is used by Screen::draw(source) when source is
177     * PROJECT_SOURCE_PROJECTORAREA or PROJECT_SOURCE_EXPORT_BLENDING
178     *
179     */
180    virtual void beginProjection(void){}
181
182
183    /**
184     * Ends the projection of the image.
185     * This is used by Screen::draw(source) when source is
186     * PROJECT_SOURCE_PROJECTORAREA or PROJECT_SOURCE_EXPORT_BLENDING
187     *
188     */
189    virtual void endProjection(void){}
190
191
192    /**
193     * Sets the VisibleFar distance parameter.
194     *
195     * The Visible Far dist is used for the representation of the projector from
196     * outside. The name comes from the frustum case, but it is used for any
197     * kind of projector now.
198     *
199     * @param farDist The new visible-far distance.
200     *
201     */
202    virtual void setVisibleFar(float farDist) {Q_UNUSED(farDist);}
203
204
205    /**
206     * Copies the data from a ProjectorData.
207     *
208     * @param data A const-reference on the data to be copied.
209     *
210     * @return true if the copy suceeds, false otherwise.
211     *
212     */
213    virtual bool copy_from(const ProjectorData& data) {Q_ASSERT(m_plugin==data.m_plugin); m_bShow=data.m_bShow; m_bShowArea=data.m_bShowArea; return true;}
214
215
216    /**
217     * Check if 2 datas are equal.
218     *
219     * @param data A const-reference on the data to be checked.
220     * @return true if the datas are the same, false otherwise.
221     *
222     */
223    virtual bool is_equal_to(const ProjectorData& data) const {return m_plugin==data.m_plugin && m_bShow==data.m_bShow && m_bShowArea==data.m_bShowArea;}
224
225
226    /**
227     * Sets the Show parameter.
228     *
229     * @param bShow The new Show parameter.
230     *
231     */
232    void setShow(bool bShow) {m_bShow = bShow;}
233
234
235    /**
236     * Gets the Show parameter.
237     *
238     * @return The Show parameter.
239     *
240     */
241    bool getShow() const {return m_bShow;}
242
243
244    /**
245     * Sets the ShowArea parameter.
246     *
247     * @param bShow The new ShowArea parameter.
248     *
249     */
250    void setShowArea(bool bShowArea) {m_bShowArea = bShowArea;}
251
252
253    /**
254     * Gets the ShowArea parameter.
255     *
256     * @return The ShowArea parameter.
257     *
258     */
259    bool getShowArea() const {return m_bShowArea;}
260
261
262    /**
263     * Restore the export settings from XML data.
264     *
265     * @param element Parent XML element of the export settings data.
266     *
267     */
268    virtual void initFromDOMElement(const QDomElement& element) {if (!element.isNull()) {m_bShow=element.attribute("show").toLower()=="true"; m_bShowArea=element.attribute("showArea").toLower()=="true";}}
269
270
271    /**
272     * Store the current export settings as XML data.
273     *
274     * @param name XML node name of the data.
275     * @param doc XML document to store the data.
276     *
277     * @return Current export settings data as XML data.
278     *
279     */
280    virtual QDomElement domElement(const QString& name, QDomDocument& doc) const { QDomElement de = doc.createElement(name); de.setAttribute("show", (m_bShow?"true":"false")); de.setAttribute("showArea", (m_bShowArea?"true":"false")); return de;}
281
282
283    /**
284     * Gets the projector name.
285     * This is the name that is in the projector list of the
286     * ProjectorInterface::projectors().
287     *
288     * @return The name of the projector.
289     *
290     */
291    virtual const QString& projector(void) const = 0;
292
293
294    /**
295     * Gets the projector full name.
296     * This name can be used in the interface of Projection Designer to define in a unique way the projector.
297     *
298     * @return the fullname of the projector.
299     *
300     */
301    QString getFullName(void) const {
302        Q_ASSERT(m_plugin);
303        QString projector_fullname = projector();
304        projector_fullname += " (";
305        projector_fullname += m_plugin->name();
306        projector_fullname += ")";
307        return projector_fullname;
308    }
309
310protected:
311    bool m_bShow; ///< Visibility flag
312    bool m_bShowArea; ///< Area visibility flag
313
314private:
315    ProjectorInterface *m_plugin; ///< The ProjectorInterface in which the projector is.
316};
317
318
319/**
320 * Projector widget class implementation.
321 *
322 * The ProjectorWidget is used by the ChannelWidget, for the Projector part of
323 * each channel. Concerning the interface, the channel manager has a
324 * stackedWidget and a combo that are linked together. When the combo changes,
325 * the stackedWidget also changes. This defines the kind of projector to be used
326 * for the channel. The default plugin offers the frustum camera.
327 *
328 * Each widget has its own data. They can be retrieved using data().
329 *
330 */
331class ProjectorWidget: public QWidget
332{
333        Q_OBJECT
334
335public:
336
337
338    /**
339     * Default constructor.
340     *
341     */
342    ProjectorWidget(ProjectorInterface *plugin=NULL, QWidget* pParent=0, Qt::WFlags flag=0): QWidget(pParent, flag), m_plugin(plugin) {Q_ASSERT(NULL!=plugin);}
343
344
345    /**
346     * Destructor.
347     *
348     */
349    virtual ~ProjectorWidget() {}
350
351
352    /**
353     * Gets the projector interface associated with the widget.
354     *
355     * @return The associated projector interfacec.
356     *
357     */
358    ProjectorInterface* plugin() {return m_plugin;}
359
360
361    /**
362     * Updates the GUI.
363     *
364     * This method *must* be implemented by derived classes.
365     *
366     * @param data The data used to update the GUI. The data can be NULL. In
367     *             this case, the current data are used.
368     *
369     */
370    virtual void updateGUI(const ProjectorData* data) = 0;
371
372
373    /**
374     * Clears the widget.
375     *
376     * This can be used before disabling the widget.
377     *
378     */
379    virtual void clear(void) = 0;
380
381
382    /**
383     * Gets the data of the widget.
384     *
385     * @return The widget data.
386     *
387     */
388    virtual const ProjectorData& data(void) const = 0;
389
390
391signals:
392
393
394    /**
395     * Notify that data has changed.
396     *
397     * @param data The new data.
398     *
399     */
400    virtual void dataChanged(const ProjectorData&)=0;
401
402
403private:
404
405
406    ProjectorInterface *m_plugin; ///< The ProjectorInterface that owns the Widget.
407
408};
409
410Q_DECLARE_INTERFACE(ProjectorInterface,
411                    "jp.orihalcon.projdesigner.ProjectorInterface/1.0");
412
413
414
415//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
416
417
418class SceneContent;
419class SceneWidget;
420
421/**
422 * Scene Plugin Interface Implementation.
423 *
424 */
425class SceneInterface
426{
427
428public:
429
430
431    /**
432     * Destructor.
433     *
434     */
435    virtual ~SceneInterface() {}
436
437
438    /**
439     * Gets the name of the Interface.
440     *
441     * This name must be unique, to avoid conflicting plugins, just like the
442     * name of the interface is unique to avoid conflicting interfaces.
443     *
444     * @return The name of the interface.
445     *
446     */
447    virtual QString name(void) const = 0;
448
449
450    /**
451     * Gets the list of the available scenes.
452     *
453     * @return The list of the available scenes.
454     *
455     */
456    virtual QStringList scenes(void) const = 0;
457
458
459    /**
460     * Instanciates a new SceneContent for the specified scene.
461     *
462     * @param scene A const reference on a string that contains the name of the
463     *              scene, such as projectors() has returned it.
464     *
465     * @return A pointer on the new instanciated SceneContent.
466     *
467     */
468    virtual SceneContent *newSceneContent(const QString& scene) = 0;
469
470
471    /**
472     * Instanciates a new SceneWidget for the specified scene.
473     *
474     * @param scene A const reference on a string that contains the name of
475     *              the scene, such as scenes() has returned it.
476     *
477     * @return A pointer on the new instanciated SceneWidget.
478     *
479     */
480    virtual SceneWidget *newSceneWidget(const QString& scene) = 0;
481
482};
483
484/**
485 * Scene content class to store informations about Scenes.
486 * This class is not a pure virtual class, so scene plugins does not need to
487 * instanciate it if it is not necessary.
488 *
489 */
490class SceneContent
491{
492public:
493
494
495    /**
496     * Constructor.
497     *
498     * @param plugin A pointer on the plugin that owns the projector.
499     *
500     */
501    SceneContent(SceneInterface *plugin): m_plugin(plugin) {Q_ASSERT(NULL!=plugin);}
502
503
504    /**
505     * Copy constructor.
506     *
507     * @param data A const reference on the source content.
508     *
509     */
510    SceneContent (const SceneContent& content) {copy_from(content);}
511
512
513    /**
514     * Destructor.
515     *
516     */
517    virtual ~SceneContent() {}
518
519
520    /**
521     * Gets the SceneInterface which instanciated the SceneContent.
522     *
523     * @return A pointer on the SceneInterface which instanciated the
524     *         SceneContent.
525     *
526     */
527    SceneInterface* plugin() {return m_plugin;}
528
529
530    /**
531     * Gets the SceneInterface which instanciated the SceneContent.
532     * This fonction differs from the previous one by the "const" attribute.
533     *
534     * @return A const pointer on the SceneInterface which instanciated the
535     *         SceneContent.
536     *
537     */
538    const SceneInterface* plugin() const {return m_plugin;}
539
540
541    /**
542     * Copies the content from a SceneContent.
543     *
544     * @param content A const-reference on the content to be copied.
545     *
546     * @return true if the copy suceeds, false otherwise.
547     *
548     */
549    virtual bool copy_from(const SceneContent& content) {Q_ASSERT(m_plugin==content.m_plugin); Q_UNUSED(content); return true;}
550
551
552    /**
553     * Check if 2 contents are equal.
554     *
555     * @param content A const-reference on the content to be checked.
556     * @return true if the contents are the same, false otherwise.
557     *
558     */
559    virtual bool is_equal_to(const SceneContent& content) const {return m_plugin==content.m_plugin;}
560
561
562    /**
563     * Restore the export settings from XML content.
564     *
565     * @param element Parent XML element of the export settings content.
566     *
567     */
568    virtual void initFromDOMElement(const QDomElement& element) {if (!element.isNull()) {}}
569
570
571    /**
572     * Store the current export settings as XML content.
573     *
574     * @param name XML node name of the content.
575     * @param doc XML document to store the content.
576     *
577     * @return Current export settings content as XML content.
578     *
579     */
580    virtual QDomElement domElement(const QString& name, QDomDocument& doc) const { QDomElement de = doc.createElement(name); de.setAttribute("name", getFullName()); return de;}
581
582
583    /**
584     * Gets the scene name.
585     * This is the name that is in the scene list of the
586     * SceneInterface::scenes().
587     *
588     * @return the name of the scene.
589     *
590     */
591    virtual const QString& scene_name(void) const = 0;
592
593
594    /**
595     * Gets the scene full name.
596     * This name can be used in the interface of Projection Designer to define in a unique way the scene.
597     *
598     * @return The fullname of the scene.
599     *
600     */
601    QString getFullName(void) const {
602        Q_ASSERT(m_plugin);
603        QString scene_fullname = scene_name();
604        scene_fullname += " (";
605        scene_fullname += m_plugin->name();
606        scene_fullname += ")";
607        return scene_fullname;
608    }
609
610
611    /**
612     * Draws the scene.
613     * This method draws the geometric scene content. For instance, for a
614     * standard scene, it draws the frustum in the scene.
615     *
616     */
617    virtual void draw(QGLWidget *glWidget, const float* cameraMatrix) {Q_UNUSED(glWidget);Q_UNUSED(cameraMatrix);}
618
619
620    /**
621     * Resets the content.
622     *
623     * This method was added for the grids, to fix the fact that a
624     * "New project" did not clear the grids.
625     *
626     */
627    virtual void reset (void)=0;
628
629private:
630    SceneInterface *m_plugin; ///< The SceneInterface in which the scene is.
631};
632
633/**
634 * Scene widget class implementation.
635 *
636 * Each widget has its own content. They can be retrieved using content().
637 *
638 */
639class SceneWidget: public QWidget
640{
641        Q_OBJECT
642public:
643
644
645    /**
646     * Default constructor.
647     *
648     */
649    SceneWidget(SceneInterface *plugin=NULL, QWidget* pParent=0, Qt::WFlags flag=0): QWidget(pParent, flag), m_plugin(plugin) {Q_ASSERT(NULL!=plugin);}
650
651
652    /**
653     * Destructor.
654     *
655     */
656    virtual ~SceneWidget() {}
657
658
659    /**
660     * Gets the scene interface associated with the widget.
661     *
662     * @return The associated scene interfacec.
663     *
664     */
665    SceneInterface* plugin() {return m_plugin;}
666
667
668    /**
669     * Updates the GUI.
670     *
671     * This method *must* be implemented by derived classes.
672     *
673     * @param content The content used to update the GUI. The content can be
674     *                NULL. In this case, the current content are used.
675     *
676     */
677    virtual void updateGUI(const SceneContent* data) = 0;
678
679
680    /**
681     * Gets the content of the widget.
682     *
683     * @return The widget content.
684     *
685     */
686    virtual const SceneContent& content(void) const = 0;
687
688
689signals:
690
691
692    /**
693     * Notify that contents have changed.
694     *
695     * @param data The new contents.
696     *
697     */
698    virtual void dataChanged(const SceneContent&)=0;
699
700private:
701
702
703    SceneInterface *m_plugin; ///< The SceneInterface that owns the Widget.
704
705};
706
707Q_DECLARE_INTERFACE(SceneInterface,
708                    "jp.orihalcon.projdesigner.SceneInterface/1.0");
709
710#endif
Note: See TracBrowser for help on using the repository browser.