summaryrefslogtreecommitdiffstats
path: root/kig/misc/object_constructor.h
blob: 9b03ece09ed4a3618146862f665c6bf5093edea5 (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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
// Copyright (C) 2002-2003  Dominique Devriese <devriese@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.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
// 02110-1301, USA.

#ifndef KIG_MISC_OBJECT_CONSTRUCTOR_H
#define KIG_MISC_OBJECT_CONSTRUCTOR_H

#include "argsparser.h"
#include "object_hierarchy.h"

class KigPainter;
class KigDocument;
class KigGUIAction;
class KigWidget;
class ArgsParserObjectType;
class ObjectType;
class BaseConstructMode;

class TQString;
class TQCString;

/**
 * This class represents a way to construct a set of objects from a
 * set of other objects.  There are some important child classes, like
 * MacroConstructor, StandardObjectConstructor etc. ( see below )
 * Actually, it is more generic than that, it provides a way to do
 * _something_ with a set of objects, but for now, i only use it to
 * construct objects.  Maybe some day, i'll find something more
 * interesting to do with it, who knows... ;)
 */
class ObjectConstructor
{
public:
  virtual ~ObjectConstructor();

  virtual const TQString descriptiveName() const = 0;
  virtual const TQString description() const = 0;
  virtual const TQCString iconFileName( const bool canBeNull = false ) const = 0;

  /**
   * the following function is called in case of duplication of arguments
   * and returns true if this is acceptable; this will return false for
   * typical objects
   */
  virtual const bool isAlreadySelectedOK( const std::vector<ObjectCalcer*>& os, 
                              const int& ) const = 0;
  /**
   * can this constructor do something useful with \p os ?  return
   * ArgsParser::Complete, Valid or NotGood
   */
  virtual const int wantArgs( const std::vector<ObjectCalcer*>& os,
                              const KigDocument& d,
                              const KigWidget& v
    ) const = 0;

  /**
   * do something fun with \p os .. This func is only called if wantArgs
   * returned Complete.. handleArgs should <i>not</i> do any
   * drawing.. after somebody calls this function, he should
   * redrawScreen() himself..
   */
  virtual void handleArgs( const std::vector<ObjectCalcer*>& os,
                           KigPart& d,
                           KigWidget& v
    ) const = 0;

  /**
   * return a string describing what you would use \p o for if it were
   * selected...  \p o should be part of \p sel .
   */
  virtual TQString useText( const ObjectCalcer& o, const std::vector<ObjectCalcer*>& sel,
                           const KigDocument& d, const KigWidget& v
    ) const = 0;

  /**
   * return a string describing what argument you want next, if the
   * given selection of objects were selected.
   */
  virtual TQString selectStatement(
    const std::vector<ObjectCalcer*>& sel, const KigDocument& d,
    const KigWidget& w ) const = 0;

  /**
   * show a preliminary version of what you would do when \ref handleArgs
   * would be called..  E.g. if this constructor normally constructs a
   * locus through some 5 points, then it will try to draw a locus
   * through whatever number of points it gets..
   */
  virtual void handlePrelim( KigPainter& p,
                             const std::vector<ObjectCalcer*>& sel,
                             const KigDocument& d,
                             const KigWidget& v
    ) const = 0;

  virtual void plug( KigPart* doc, KigGUIAction* kact ) = 0;

  virtual bool isTransform() const = 0;
  virtual bool isTest() const;
  virtual bool isIntersection() const;

  /**
   * Which construct mode should be used for this ObjectConstructor.
   * In fact, this is not a pretty design.  The Kig
   * GUIAction-ObjectConstructor stuff should be reworked into a
   * general GUIAction, which just models something which can be
   * executed given a certain number of arguments.  The code for
   * drawPrelim and such should all be in the ConstructMode, and the
   * new GUIAction should just start the correct KigMode with the
   * correct arguments.
   *
   * This function is only overridden in TestConstructor.
   */
  virtual BaseConstructMode* constructMode( KigPart& doc );
};

/**
 * This class provides wraps ObjectConstructor in a more simple
 * interface for the most common object types..
 */
class StandardConstructorBase
  : public ObjectConstructor
{
  const char* mdescname;
  const char* mdesc;
  const char* miconfile;
  const ArgsParser& margsparser;
public:
  StandardConstructorBase( const char* descname,
                           const char* desc,
                           const char* iconfile,
                           const ArgsParser& parser );

  virtual ~StandardConstructorBase();

  const TQString descriptiveName() const;
  const TQString description() const;
  const TQCString iconFileName( const bool canBeNull = false ) const;

  const bool isAlreadySelectedOK( const std::vector<ObjectCalcer*>& os, 
                                  const int& ) const;
  virtual const int wantArgs(
    const std::vector<ObjectCalcer*>& os, const KigDocument& d,
    const KigWidget& v
    ) const;

  void handleArgs( const std::vector<ObjectCalcer*>& os,
                   KigPart& d,
                   KigWidget& v
    ) const;

  void handlePrelim( KigPainter& p, const std::vector<ObjectCalcer*>& sel,
                     const KigDocument& d, const KigWidget& v
    ) const;

  virtual void drawprelim( const ObjectDrawer& drawer, KigPainter& p, const std::vector<ObjectCalcer*>& parents,
                           const KigDocument& ) const = 0;

  TQString useText( const ObjectCalcer& o, const std::vector<ObjectCalcer*>& sel,
                   const KigDocument& d, const KigWidget& v ) const;

  TQString selectStatement(
    const std::vector<ObjectCalcer*>& sel, const KigDocument& d,
    const KigWidget& w ) const;

  virtual std::vector<ObjectHolder*> build(
    const std::vector<ObjectCalcer*>& os,
    KigDocument& d, KigWidget& w
    ) const = 0;
};

/**
 * A standard implementation of StandardConstructorBase for simple
 * types..
 */
class SimpleObjectTypeConstructor
  : public StandardConstructorBase
{
  const ArgsParserObjectType* mtype;
public:
  SimpleObjectTypeConstructor(
    const ArgsParserObjectType* t, const char* descname,
    const char* desc, const char* iconfile );

  ~SimpleObjectTypeConstructor();

  void drawprelim( const ObjectDrawer& drawer, KigPainter& p, const std::vector<ObjectCalcer*>& parents,
                   const KigDocument& ) const;

  std::vector<ObjectHolder*> build( const std::vector<ObjectCalcer*>& os,
                                    KigDocument& d,
                                    KigWidget& w ) const;

  void plug( KigPart* doc, KigGUIAction* kact );

  bool isTransform() const;
};

/**
 * A standard implementation of StandardConstructorBase for property
 * objects...
 */
class PropertyObjectConstructor
  : public StandardConstructorBase
{
  ArgsParser mparser;
  const char* mpropinternalname;
public:
  PropertyObjectConstructor(
    const ObjectImpType* imprequirement, const char* usetext,
    const char* selectstat, const char* descname, const char* desc,
    const char* iconfile, const char* propertyinternalname );

  ~PropertyObjectConstructor();

  void drawprelim( const ObjectDrawer& drawer, KigPainter& p, const std::vector<ObjectCalcer*>& parents,
                   const KigDocument& ) const;

  std::vector<ObjectHolder*> build( const std::vector<ObjectCalcer*>& os,
                                    KigDocument& d, KigWidget& w ) const;

  void plug( KigPart* doc, KigGUIAction* kact );

  bool isTransform() const;
};

/**
 * This class is the equivalent of \ref SimpleObjectTypeConstructor
 * for object types that are constructed in groups of more than one.
 * For example, the intersection of a circle and line in general
 * produces two points, in general.  Internally, we differentiate
 * betweem them by passing them a parameter of ( in this case ) 1 or
 * -1.  There are still other object types that work the same, and
 * they all require this sort of parameter.
 * E.g. CubicLineIntersectionType takes a parameter between 1 and 3.
 * This class knows about that, and constructs the objects along this
 * scheme..
 */
class MultiObjectTypeConstructor
  : public StandardConstructorBase
{
  const ArgsParserObjectType* mtype;
  std::vector<int> mparams;
  ArgsParser mparser;
public:
  MultiObjectTypeConstructor(
    const ArgsParserObjectType* t, const char* descname,
    const char* desc, const char* iconfile,
    const std::vector<int>& params );
  MultiObjectTypeConstructor(
    const ArgsParserObjectType* t, const char* descname,
    const char* desc, const char* iconfile,
    int a, int b, int c = -999, int d = -999 );
  ~MultiObjectTypeConstructor();

  void drawprelim( const ObjectDrawer& drawer, KigPainter& p, const std::vector<ObjectCalcer*>& parents,
                   const KigDocument& ) const;

  std::vector<ObjectHolder*> build(
    const std::vector<ObjectCalcer*>& os,
    KigDocument& d, KigWidget& w ) const;

  void plug( KigPart* doc, KigGUIAction* kact );

  bool isTransform() const;
};

/**
 * This class is a collection of some other ObjectConstructors, that
 * makes them appear to the user as a single ObjectConstructor.  It is
 * e.g. used for the "intersection" constructor.
 */
class MergeObjectConstructor
  : public ObjectConstructor
{
  const char* mdescname;
  const char* mdesc;
  const char* miconfilename;
  typedef std::vector<ObjectConstructor*> vectype;
  vectype mctors;
public:
  MergeObjectConstructor( const char* descname, const char* desc,
                          const char* iconfilename );
  ~MergeObjectConstructor();

  void merge( ObjectConstructor* e );

  const TQString descriptiveName() const;
  const TQString description() const;
  const TQCString iconFileName( const bool canBeNull = false ) const;

  const bool isAlreadySelectedOK( const std::vector<ObjectCalcer*>& os, 
                                  const int& ) const;
  const int wantArgs( const std::vector<ObjectCalcer*>& os,
                      const KigDocument& d,
                      const KigWidget& v
    ) const;

  TQString useText( const ObjectCalcer& o, const std::vector<ObjectCalcer*>& sel,
                   const KigDocument& d, const KigWidget& v ) const;

  TQString selectStatement(
    const std::vector<ObjectCalcer*>& sel, const KigDocument& d,
    const KigWidget& w ) const;

  void handleArgs( const std::vector<ObjectCalcer*>& os, KigPart& d, KigWidget& v ) const;

  void handlePrelim( KigPainter& p, const std::vector<ObjectCalcer*>& sel,
                     const KigDocument& d, const KigWidget& v ) const;

  void plug( KigPart* doc, KigGUIAction* kact );

  bool isTransform() const;
};

/**
 * MacroConstructor is a class that represents Kig macro's: these are
 * constructed by the user, and defined by a set of input and a set of
 * output objects.  The macro-constructor saves the way in which the
 * output objects have been built from the input objects, and when
 * given similar input objects, it will produce objects in the given
 * way.  The data is saved in a \ref ObjectHierarchy.
 */
class MacroConstructor
  : public ObjectConstructor
{
  ObjectHierarchy mhier;
  TQString mname;
  TQString mdesc;
  bool mbuiltin;
  TQCString miconfile;
  ArgsParser mparser;
public:
  MacroConstructor( const std::vector<ObjectCalcer*>& input, const std::vector<ObjectCalcer*>& output,
                    const TQString& name, const TQString& description,
                    const TQCString& iconfile = 0 );
  MacroConstructor( const ObjectHierarchy& hier, const TQString& name,
                    const TQString& desc,
                    const TQCString& iconfile = 0 );
  ~MacroConstructor();

  const ObjectHierarchy& hierarchy() const;

  const TQString descriptiveName() const;
  const TQString description() const;
  const TQCString iconFileName( const bool canBeNull = false ) const;

  const bool isAlreadySelectedOK( const std::vector<ObjectCalcer*>& os, 
                                  const int& ) const;
  const int wantArgs( const std::vector<ObjectCalcer*>& os, const KigDocument& d,
                      const KigWidget& v ) const;

  void handleArgs( const std::vector<ObjectCalcer*>& os, KigPart& d,
                   KigWidget& v ) const;

  TQString useText( const ObjectCalcer& o, const std::vector<ObjectCalcer*>& sel,
                   const KigDocument& d, const KigWidget& v
    ) const;

  TQString selectStatement(
    const std::vector<ObjectCalcer*>& sel, const KigDocument& d,
    const KigWidget& w ) const;

  void handlePrelim( KigPainter& p, const std::vector<ObjectCalcer*>& sel,
                     const KigDocument& d, const KigWidget& v
    ) const;

  void plug( KigPart* doc, KigGUIAction* kact );

  void setBuiltin( bool builtin );

  /**
   * is this the ctor for a transformation type.  We want to know this
   * cause transform types are shown separately in an object's RMB
   * menu..
   */
  bool isTransform() const;

  void setName( const TQString& name );
  void setDescription( const TQString& desc );
  void setIcon( TQCString& icon );
};

#endif