~ubuntu-branches/debian/sid/librecad/sid

« back to all changes in this revision

Viewing changes to src/lib/filters/rs_filterinterface.h

  • Committer: Bazaar Package Importer
  • Author(s): Scott Howard
  • Date: 2011-02-03 19:04:09 UTC
  • Revision ID: james.westby@ubuntu.com-20110203190409-202riehiqzmkydth
Tags: upstream-1.0.0~beta5
ImportĀ upstreamĀ versionĀ 1.0.0~beta5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** This file is part of the LibreCAD project, a 2D CAD program
 
4
**
 
5
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
 
6
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
 
7
**
 
8
**
 
9
** This program is free software; you can redistribute it and/or modify
 
10
** it under the terms of the GNU General Public License as published by 
 
11
** the Free Software Foundation; either version 2 of the License, or
 
12
** (at your option) any later version.
 
13
**
 
14
** This program is distributed in the hope that it will be useful,
 
15
** but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
** GNU General Public License for more details.
 
18
** 
 
19
** You should have received a copy of the GNU General Public License
 
20
** along with this program; if not, write to the Free Software
 
21
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
22
**
 
23
** This copyright notice MUST APPEAR in all copies of the script!  
 
24
**
 
25
**********************************************************************/
 
26
 
 
27
 
 
28
#ifndef RS_FILTERINTERFACE_H
 
29
#define RS_FILTERINTERFACE_H
 
30
 
 
31
#include "rs_graphic.h"
 
32
 
 
33
#include "rs_string.h"
 
34
#include "rs_valuelist.h"
 
35
 
 
36
#include "rs_debug.h"
 
37
 
 
38
/**
 
39
 * This is the interface that must be implemented for all 
 
40
 * format filter classes. The RS_FileIO class 
 
41
 * uses the methods defined in here to interact with the format
 
42
 * filter classes.
 
43
 *
 
44
 * @author Andrew Mustun
 
45
 */
 
46
class RS_FilterInterface {
 
47
public:
 
48
    /**
 
49
     * Constructor.
 
50
     */
 
51
    RS_FilterInterface() {
 
52
                //std::cout << "RS_FilterInterface\n";
 
53
        //graphic = NULL;
 
54
    }
 
55
 
 
56
    /**
 
57
     * Destructor.
 
58
     */
 
59
    virtual ~RS_FilterInterface() {}
 
60
 
 
61
    /**
 
62
     * Checks if this filter can import the given file type.
 
63
     *
 
64
     * @retval true if the filter can import the file type 
 
65
     * @retval false otherwise.
 
66
     */
 
67
    virtual bool canImport(RS2::FormatType t) {
 
68
        return !(importFormats.find(t)==importFormats.end());
 
69
    }
 
70
 
 
71
    /**
 
72
     * Checks if this filter can export the given file type.
 
73
     *
 
74
     * @return true if the filter can export the file type, 
 
75
     *         false otherwise.
 
76
     */
 
77
    virtual bool canExport(RS2::FormatType t) {
 
78
        return !(exportFormats.find(t)==exportFormats.end());
 
79
    }
 
80
 
 
81
    /**
 
82
     * The implementation of this method in a inherited format
 
83
     * class should read a file from disk and put the entities
 
84
     * into the current entity container.
 
85
     */
 
86
    virtual bool fileImport(RS_Graphic& g, const RS_String& file, RS2::FormatType type) = 0;
 
87
 
 
88
    /**
 
89
     * The implementation of this method in a inherited format
 
90
     * class should write the entities in the current entity container
 
91
     * to a file on the disk.
 
92
     */
 
93
    virtual bool fileExport(RS_Graphic& g, const RS_String& file, RS2::FormatType type) = 0;
 
94
 
 
95
protected:
 
96
    /**
 
97
     * Adds a file extension which can be imported by this filter.
 
98
     */
 
99
    void addImportFormat(RS2::FormatType type) {
 
100
        RS_DEBUG->print("Filter can import %d", (int)type);
 
101
        importFormats += type;
 
102
    }
 
103
 
 
104
    /**
 
105
     * Adds a file extension which can be exported by this filter.
 
106
     */
 
107
    void addExportFormat(RS2::FormatType type) {
 
108
        RS_DEBUG->print("Filter can export %d", (int)type);
 
109
        exportFormats += type;
 
110
    }
 
111
 
 
112
protected:
 
113
    //! Pointer to the graphic we currently operate on.
 
114
    //RS_Graphic* graphic;
 
115
 
 
116
    //! Vector of file extensions this filter can import.
 
117
    RS_ValueList<RS2::FormatType> importFormats;
 
118
 
 
119
    //! Vector of file extensions this filter can export.
 
120
    RS_ValueList<RS2::FormatType> exportFormats;
 
121
};
 
122
 
 
123
#endif