source: projectionDesigner/tag/ProjectionDesigner_1.1.5/projdesigner/include/interfaces.h @ 2

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