~ubuntu-branches/ubuntu/oneiric/kig/oneiric

« back to all changes in this revision

Viewing changes to objects/vector_type.cc

  • Committer: Bazaar Package Importer
  • Author(s): Harald Sitter
  • Date: 2011-07-10 11:57:38 UTC
  • Revision ID: james.westby@ubuntu.com-20110710115738-gdjnn1kctr49lmy9
Tags: upstream-4.6.90+repack
ImportĀ upstreamĀ versionĀ 4.6.90+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C)  2004  Dominique Devriese <devriese@kde.org>
 
2
 
 
3
// This program is free software; you can redistribute it and/or
 
4
// modify it under the terms of the GNU General Public License
 
5
// as published by the Free Software Foundation; either version 2
 
6
// of the License, or (at your option) any later version.
 
7
 
 
8
// This program is distributed in the hope that it will be useful,
 
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
// GNU General Public License for more details.
 
12
 
 
13
// You should have received a copy of the GNU General Public License
 
14
// along with this program; if not, write to the Free Software
 
15
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
16
// 02110-1301, USA.
 
17
 
 
18
#include "vector_type.h"
 
19
 
 
20
#include "point_imp.h"
 
21
#include "other_imp.h"
 
22
#include "bogus_imp.h"
 
23
 
 
24
static const ArgsParser::spec argsspecVector[] =
 
25
{
 
26
  { PointImp::stype(), I18N_NOOP( "Construct a vector from this point" ),
 
27
    I18N_NOOP( "Select the start point of the new vector..." ), true },
 
28
  { PointImp::stype(), I18N_NOOP( "Construct a vector to this point" ),
 
29
    I18N_NOOP( "Select the end point of the new vector..." ), true }
 
30
};
 
31
 
 
32
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( VectorType )
 
33
 
 
34
VectorType::VectorType()
 
35
  : ObjectABType( "Vector", argsspecVector, 2 )
 
36
{
 
37
}
 
38
 
 
39
VectorType::~VectorType()
 
40
{
 
41
}
 
42
 
 
43
const VectorType* VectorType::instance()
 
44
{
 
45
  static const VectorType t;
 
46
  return &t;
 
47
}
 
48
 
 
49
ObjectImp* VectorType::calcx( const Coordinate& a, const Coordinate& b ) const
 
50
{
 
51
  return new VectorImp( a, b );
 
52
}
 
53
 
 
54
const ObjectImpType* VectorType::resultId() const
 
55
{
 
56
  return VectorImp::stype();
 
57
}
 
58
 
 
59
static const ArgsParser::spec argsspecVectorSum[] =
 
60
{
 
61
  { VectorImp::stype(), I18N_NOOP( "Construct the vector sum of this vector and another one." ),
 
62
    I18N_NOOP( "Select the first of the two vectors of which you want to construct the sum..." ), false },
 
63
  { VectorImp::stype(), I18N_NOOP( "Construct the vector sum of this vector and the other one." ),
 
64
    I18N_NOOP( "Select the other of the two vectors of which you want to construct the sum..." ), false },
 
65
  { PointImp::stype(), I18N_NOOP( "Construct the vector sum starting at this point." ),
 
66
    I18N_NOOP( "Select the point to construct the sum vector in..." ), false }
 
67
};
 
68
 
 
69
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( VectorSumType )
 
70
 
 
71
VectorSumType::VectorSumType()
 
72
  : ArgsParserObjectType( "VectorSum", argsspecVectorSum, 3 )
 
73
{
 
74
}
 
75
 
 
76
VectorSumType::~VectorSumType()
 
77
{
 
78
}
 
79
 
 
80
const VectorSumType* VectorSumType::instance()
 
81
{
 
82
  static const VectorSumType t;
 
83
  return &t;
 
84
}
 
85
 
 
86
ObjectImp* VectorSumType::calc( const Args& args, const KigDocument& ) const
 
87
{
 
88
  if ( ! margsparser.checkArgs( args ) ) return new InvalidImp;
 
89
 
 
90
  const VectorImp& a = *static_cast<const VectorImp*>( args[0] );
 
91
  const VectorImp& b = *static_cast<const VectorImp*>( args[1] );
 
92
  const PointImp& p = *static_cast<const PointImp*>( args[2] );
 
93
 
 
94
  return new VectorImp( p.coordinate(), p.coordinate() + a.dir() + b.dir() );
 
95
}
 
96
 
 
97
const ObjectImpType* VectorSumType::resultId() const
 
98
{
 
99
  return VectorImp::stype();
 
100
}