1 // Copyright (C) 2003 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., 59 Temple Place - Suite 330, Boston, MA
18 #include "other_type.h"
20 #include "bogus_imp.h"
21 #include "point_imp.h"
22 #include "locus_imp.h"
24 #include "../misc/common.h"
25 #include "../misc/calcpaths.h"
26 #include "../misc/goniometry.h"
27 #include "../kig/kig_part.h"
28 #include "../kig/kig_view.h"
29 #include "../kig/kig_commands.h"
37 static const struct ArgsParser::spec argsspecLocus
[] =
39 { HierarchyImp::stype(), "hierarchy", "SHOULD NOT BE SEEN", false },
40 { CurveImp::stype(), "curve", "SHOULD NOT BE SEEN", false }
43 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( LocusType
)
45 LocusType::LocusType()
46 : ArgsParserObjectType( "Locus", argsspecLocus
, 2 )
50 LocusType::~LocusType()
54 ObjectImp
* LocusType::calc( const Args
& args
, const KigDocument
& ) const
58 assert( args
.size() >= 2 );
59 const Args
firsttwo( args
.begin(), args
.begin() + 2 );
60 Args
fixedargs( args
.begin() + 2, args
.end() );
62 if ( ! margsparser
.checkArgs( firsttwo
) ) return new InvalidImp
;
63 for ( Args::iterator i
= fixedargs
.begin(); i
!= fixedargs
.end(); ++i
)
64 if ( ! (*i
)->valid() )
65 return new InvalidImp
;
67 const ObjectHierarchy
& hier
=
68 static_cast<const HierarchyImp
*>( args
[0] )->data();
69 const CurveImp
* curveimp
= static_cast<const CurveImp
*>( args
[1] );
71 return new LocusImp( curveimp
->copy(), hier
.withFixedArgs( fixedargs
) );
74 bool LocusType::inherits( int type
) const
76 return type
== ID_LocusType
? true : Parent::inherits( type
);
79 const ObjectImpType
* LocusType::resultId() const
81 return LocusImp::stype();
84 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( CopyObjectType
)
86 CopyObjectType::CopyObjectType()
87 : ObjectType( "Copy" )
91 CopyObjectType::~CopyObjectType()
95 CopyObjectType
* CopyObjectType::instance()
97 static CopyObjectType t
;
101 bool CopyObjectType::inherits( int ) const
106 ObjectImp
* CopyObjectType::calc( const Args
& parents
, const KigDocument
& ) const
108 assert( parents
.size() == 1 );
109 return parents
[0]->copy();
112 const ObjectImpType
* CopyObjectType::impRequirement( const ObjectImp
*, const Args
& ) const
114 return ObjectImp::stype();
117 const ObjectImpType
* CopyObjectType::resultId() const
119 // we don't know what we return..
120 return ObjectImp::stype();
123 const ObjectImpType
* LocusType::impRequirement( const ObjectImp
* o
, const Args
& parents
) const
125 assert( parents
.size() >= 2 );
126 Args
firsttwo( parents
.begin(), parents
.begin() + 2 );
127 if ( o
== parents
[0] || o
== parents
[1] )
128 return margsparser
.impRequirement( o
, firsttwo
);
131 const HierarchyImp
* h
= dynamic_cast<const HierarchyImp
*>( parents
[0] );
134 PointImp
* p
= new PointImp( Coordinate() );
135 Args
hargs( parents
.begin()+ 2, parents
.end() );
136 hargs
.push_back( p
);
137 ArgsParser hparser
= h
->data().argParser();
138 const ObjectImpType
* ret
= hparser
.impRequirement( o
, hargs
);
143 return ObjectImp::stype();
147 const LocusType
* LocusType::instance()
149 static const LocusType t
;
153 std::vector
<ObjectCalcer
*> CopyObjectType::sortArgs( const std::vector
<ObjectCalcer
*>& os
) const
155 assert( os
.size() == 1 );
159 std::vector
<ObjectCalcer
*> LocusType::sortArgs( const std::vector
<ObjectCalcer
*>& args
) const
161 assert( args
.size() >= 2 );
162 std::vector
<ObjectCalcer
*> firsttwo( args
.begin(), args
.begin() + 2 );
163 firsttwo
= margsparser
.parse( firsttwo
);
164 std::copy( args
.begin() + 2, args
.end(), std::back_inserter( firsttwo
) );
168 Args
LocusType::sortArgs( const Args
& args
) const
170 assert( args
.size() >= 2 );
171 Args
firsttwo( args
.begin(), args
.begin() + 2 );
172 firsttwo
= margsparser
.parse( firsttwo
);
173 std::copy( args
.begin() + 2, args
.end(), std::back_inserter( firsttwo
) );
177 Args
CopyObjectType::sortArgs( const Args
& args
) const
179 assert( args
.size() == 1 );
183 bool CopyObjectType::isDefinedOnOrThrough( const ObjectImp
*, const Args
& ) const
185 // TODO: vragen aan parent ?
186 // TODO: translate the above TODO ?