1
// Copyright (C) 2004 Dominique Devriese <devriese@kde.org>
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.
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.
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
18
#include "vector_type.h"
20
#include "point_imp.h"
21
#include "other_imp.h"
22
#include "bogus_imp.h"
24
static const ArgsParser::spec argsspecVector[] =
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 }
32
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( VectorType )
34
VectorType::VectorType()
35
: ObjectABType( "Vector", argsspecVector, 2 )
39
VectorType::~VectorType()
43
const VectorType* VectorType::instance()
45
static const VectorType t;
49
ObjectImp* VectorType::calcx( const Coordinate& a, const Coordinate& b ) const
51
return new VectorImp( a, b );
54
const ObjectImpType* VectorType::resultId() const
56
return VectorImp::stype();
59
static const ArgsParser::spec argsspecVectorSum[] =
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 }
69
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( VectorSumType )
71
VectorSumType::VectorSumType()
72
: ArgsParserObjectType( "VectorSum", argsspecVectorSum, 3 )
76
VectorSumType::~VectorSumType()
80
const VectorSumType* VectorSumType::instance()
82
static const VectorSumType t;
86
ObjectImp* VectorSumType::calc( const Args& args, const KigDocument& ) const
88
if ( ! margsparser.checkArgs( args ) ) return new InvalidImp;
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] );
94
return new VectorImp( p.coordinate(), p.coordinate() + a.dir() + b.dir() );
97
const ObjectImpType* VectorSumType::resultId() const
99
return VectorImp::stype();