• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kig

  • sources
  • kde-4.12
  • kdeedu
  • kig
  • objects
locus_imp.cc
Go to the documentation of this file.
1 // Copyright (C) 2003 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 "locus_imp.h"
19 
20 #include "bogus_imp.h"
21 #include "point_imp.h"
22 #include "../misc/object_hierarchy.h"
23 #include "../misc/kigpainter.h"
24 #include "../misc/coordinate.h"
25 #include "../misc/common.h"
26 #include "../misc/kignumerics.h"
27 #include "../misc/equation.h"
28 #include "../kig/kig_view.h"
29 #include "../kig/kig_document.h"
30 
31 #include <klocale.h>
32 
33 #include <cmath>
34 
35 using namespace std;
36 
37 LocusImp::~LocusImp()
38 {
39  delete mcurve;
40 }
41 
42 ObjectImp* LocusImp::transform( const Transformation& t ) const
43 {
44  return new LocusImp( mcurve->copy(), mhier.transformFinalObject( t ) );
45 }
46 
47 void LocusImp::draw( KigPainter& p ) const
48 {
49  p.drawCurve( this );
50 }
51 
52 bool LocusImp::contains( const Coordinate& p, int width, const KigWidget& w ) const
53 {
54  return internalContainsPoint( p, w.screenInfo().normalMiss( width ), w.document() );
55 }
56 
57 bool LocusImp::inRect( const Rect&, int, const KigWidget& ) const
58 {
59  // TODO ?
60  return false;
61 }
62 
63 const Coordinate LocusImp::getPoint( double param, const KigDocument& doc ) const
64 {
65  Coordinate arg = mcurve->getPoint( param, doc );
66  if ( ! arg.valid() ) return arg;
67  PointImp argimp( arg );
68  Args args;
69  args.push_back( &argimp );
70  vector<ObjectImp*> calcret = mhier.calc( args, doc );
71  assert( calcret.size() == 1 );
72  ObjectImp* imp = calcret.front();
73  Coordinate ret;
74  if ( imp->inherits( PointImp::stype() ) )
75  {
76  doc.mcachedparam = param;
77  ret = static_cast<PointImp*>( imp )->coordinate();
78  }
79  else
80  ret = Coordinate::invalidCoord();
81 
82  delete imp;
83  return ret;
84 }
85 
86 LocusImp::LocusImp( CurveImp* curve, const ObjectHierarchy& hier )
87  : mcurve( curve ), mhier( hier )
88 {
89 }
90 
91 int LocusImp::numberOfProperties() const
92 {
93  return Parent::numberOfProperties() + 1;
94 }
95 
96 const QByteArrayList LocusImp::propertiesInternalNames() const
97 {
98  QByteArrayList l = Parent::propertiesInternalNames();
99  l << "cartesian-equation";
100  assert( l.size() == LocusImp::numberOfProperties() );
101  return l;
102 }
103 
104 const QByteArrayList LocusImp::properties() const
105 {
106  QByteArrayList l = Parent::properties();
107  l << I18N_NOOP( "Cartesian Equation" );
108  assert( l.size() == LocusImp::numberOfProperties() );
109  return l;
110 }
111 
112 const ObjectImpType* LocusImp::impRequirementForProperty( int which ) const
113 {
114  return Parent::impRequirementForProperty( which );
115 }
116 
117 const char* LocusImp::iconForProperty( int which ) const
118 {
119  int pnum = 0;
120  if ( which < Parent::numberOfProperties() )
121  return Parent::iconForProperty( which );
122  if ( which == Parent::numberOfProperties() + pnum++ )
123  return "kig_text"; // cartesian equation string
124  else
125  assert( false );
126  return "";
127 }
128 
129 ObjectImp* LocusImp::property( int which, const KigDocument& w ) const
130 {
131  int pnum = 0;
132 
133  if ( which < Parent::numberOfProperties() )
134  return Parent::property( which, w );
135  if ( which == Parent::numberOfProperties() + pnum++ )
136  return new StringImp( cartesianEquationString( w ) );
137  else
138  assert( false );
139  return new InvalidImp;
140 }
141 
142 LocusImp* LocusImp::copy() const
143 {
144  return new LocusImp( mcurve->copy(), mhier );
145 }
146 
147 const CurveImp* LocusImp::curve() const
148 {
149  return mcurve;
150 }
151 
152 const ObjectHierarchy& LocusImp::hierarchy() const
153 {
154  return mhier;
155 }
156 
164 void LocusImp::getInterval( double& x1, double& x2,
165  double incr,const Coordinate& p,
166  const KigDocument& doc) const
167 {
168  double mm = getDist( x1, p, doc);
169  double mm1 = getDist( x2, p, doc);
170  if( mm <= mm1 ) return;
171  else
172  {
173  double x3 = x2 + incr;
174  double mm2 = getDist (x3, p, doc);
175  while( mm > mm1 && mm1 > mm2 )
176  {
177  x1 = x2;
178  x2 = x3;
179  x3 = x2 + incr;
180  mm = mm1;
181  mm1 = mm2;
182  mm2 = getDist (x3, p, doc);
183  }
184  x2=x3;
185  }
186 }
187 
188 void LocusImp::visit( ObjectImpVisitor* vtor ) const
189 {
190  vtor->visit( this );
191 }
192 
193 bool LocusImp::equals( const ObjectImp& rhs ) const
194 {
195  return rhs.inherits( LocusImp::stype() ) &&
196  static_cast<const LocusImp&>( rhs ).curve()->equals( *curve() ) &&
197  static_cast<const LocusImp&>( rhs ).hierarchy() == hierarchy();
198 }
199 
200 const ObjectImpType* LocusImp::stype()
201 {
202  static const ObjectImpType t(
203  Parent::stype(), "locus",
204  I18N_NOOP( "locus" ),
205  I18N_NOOP( "Select this locus" ),
206  I18N_NOOP( "Select locus %1" ),
207  I18N_NOOP( "Remove a Locus" ),
208  I18N_NOOP( "Add a Locus" ),
209  I18N_NOOP( "Move a Locus" ),
210  I18N_NOOP( "Attach to this locus" ),
211  I18N_NOOP( "Show a Locus" ),
212  I18N_NOOP( "Hide a Locus" )
213  );
214  return &t;
215 }
216 
217 const ObjectImpType* LocusImp::type() const
218 {
219  return LocusImp::stype();
220 }
221 
222 bool LocusImp::containsPoint( const Coordinate& p, const KigDocument& doc ) const
223 {
224  return internalContainsPoint( p, test_threshold, doc );
225 }
226 
227 bool LocusImp::internalContainsPoint( const Coordinate& p, double threshold, const KigDocument& doc ) const
228 {
229  double param = getParam( p, doc );
230  double dist = getDist( param, p, doc );
231  return fabs( dist ) <= threshold;
232 }
233 
234 bool LocusImp::isPropertyDefinedOnOrThroughThisImp( int which ) const
235 {
236  return Parent::isPropertyDefinedOnOrThroughThisImp( which );
237 }
238 
239 Rect LocusImp::surroundingRect() const
240 {
241  // it's probably possible to calculate this, if it exists, but we
242  // don't for now.
243  return Rect::invalidRect();
244 }
245 
246 /*
247 
248 --- moved in CurveImp ---
249 
250 double LocusImp::revert (int n) const
251 
252 QString LocusImp::cartesianEquationString (const KigDocument& doc ) const
253 {
254 
255  */
locus_imp.h
LocusImp
LocusImp is an imp that consists of a copy of the curveimp that the moving point moves over...
Definition: locus_imp.h:57
ObjectImpType
Instances of this class represent a certain ObjectImp type.
Definition: object_imp.h:95
ObjectImp::inherits
bool inherits(const ObjectImpType *t) const
Returns true if this ObjectImp inherits the ObjectImp type represented by t.
Definition: object_imp.cc:279
ObjectHierarchy
Definition: object_hierarchy.h:30
LocusImp::propertiesInternalNames
const QByteArrayList propertiesInternalNames() const
Definition: locus_imp.cc:96
point_imp.h
StringImp
This ObjectImp is a BogusImp containing only a string value.
Definition: bogus_imp.h:167
ScreenInfo::normalMiss
double normalMiss(int width) const
Definition: screeninfo.cc:88
KigPainter::drawCurve
void drawCurve(const CurveImp *curve)
draw a generic curve...
Definition: kigpainter.cpp:757
LocusImp::curve
const CurveImp * curve() const
Definition: locus_imp.cc:147
ObjectImpVisitor::visit
void visit(const ObjectImp *imp)
Definition: object_imp.cc:81
ObjectImp::impRequirementForProperty
virtual const ObjectImpType * impRequirementForProperty(int which) const
Definition: object_imp.cc:76
LocusImp::impRequirementForProperty
const ObjectImpType * impRequirementForProperty(int which) const
Definition: locus_imp.cc:112
ObjectImp::property
virtual ObjectImp * property(int which, const KigDocument &d) const
Definition: object_imp.cc:70
Rect
This file is part of Kig, a KDE program for Interactive Geometry...
Definition: rect.h:34
CurveImp::cartesianEquationString
QString cartesianEquationString(const KigDocument &w) const
Definition: curve_imp.cc:276
LocusImp::getPoint
const Coordinate getPoint(double param, const KigDocument &) const
Definition: locus_imp.cc:63
ObjectImp::propertiesInternalNames
virtual const QByteArrayList propertiesInternalNames() const
Definition: object_imp.cc:63
Rect::invalidRect
static Rect invalidRect()
Definition: rect.cc:305
Coordinate
The Coordinate class is the basic class representing a 2D location by its x and y components...
Definition: coordinate.h:33
LocusImp::inRect
bool inRect(const Rect &r, int width, const KigWidget &) const
Definition: locus_imp.cc:57
LocusImp::~LocusImp
~LocusImp()
Definition: locus_imp.cc:37
LocusImp::containsPoint
bool containsPoint(const Coordinate &p, const KigDocument &d) const
Return whether this Curve contains the given point.
Definition: locus_imp.cc:222
LocusImp::stype
static const ObjectImpType * stype()
Definition: locus_imp.cc:200
LocusImp::transform
ObjectImp * transform(const Transformation &) const
Return this ObjectImp, transformed by the transformation t.
Definition: locus_imp.cc:42
KigWidget::screenInfo
const ScreenInfo & screenInfo() const
the part of the document we're currently showing i.e.
Definition: kig_view.cpp:272
test_threshold
const double test_threshold
Definition: common.cpp:510
ObjectImp::iconForProperty
virtual const char * iconForProperty(int which) const
Definition: object_imp.cc:187
KigPainter
KigPainter is an extended QPainter.
Definition: kigpainter.h:51
bogus_imp.h
LocusImp::surroundingRect
Rect surroundingRect() const
Definition: locus_imp.cc:239
PointImp
An ObjectImp representing a point.
Definition: point_imp.h:27
Args
std::vector< const ObjectImp * > Args
Definition: objects/common.h:47
LocusImp::LocusImp
LocusImp(CurveImp *, const ObjectHierarchy &)
Definition: locus_imp.cc:86
Transformation
Class representing a transformation.
Definition: kigtransform.h:37
LocusImp::property
ObjectImp * property(int which, const KigDocument &w) const
Definition: locus_imp.cc:129
KigWidget
This class is the real widget showing the document.
Definition: kig_view.h:50
KigWidget::document
const KigDocument & document() const
Definition: kig_view.cpp:460
LocusImp::type
const ObjectImpType * type() const
Returns the lowermost ObjectImpType that this object is an instantiation of.
Definition: locus_imp.cc:217
ObjectImp::isPropertyDefinedOnOrThroughThisImp
virtual bool isPropertyDefinedOnOrThroughThisImp(int which) const
Definition: object_imp.cc:326
LocusImp::draw
void draw(KigPainter &p) const
Definition: locus_imp.cc:47
LocusImp::iconForProperty
const char * iconForProperty(int which) const
Definition: locus_imp.cc:117
CurveImp::copy
virtual CurveImp * copy() const =0
Returns a copy of this ObjectImp.
LocusImp::properties
const QByteArrayList properties() const
Definition: locus_imp.cc:104
Coordinate::invalidCoord
static Coordinate invalidCoord()
Create an invalid Coordinate.
Definition: coordinate.cpp:171
PointImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing PointImp's.
Definition: point_imp.cc:159
CurveImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the CurveImp type.
Definition: curve_imp.cc:27
LocusImp::contains
bool contains(const Coordinate &p, int width, const KigWidget &) const
Definition: locus_imp.cc:52
KigDocument
KigDocument is the class holding the real data in a Kig document.
Definition: kig_document.h:36
KigDocument::mcachedparam
double mcachedparam
Definition: kig_document.h:71
LocusImp::hierarchy
const ObjectHierarchy & hierarchy() const
Definition: locus_imp.cc:152
LocusImp::numberOfProperties
int numberOfProperties() const
Definition: locus_imp.cc:91
LocusImp::copy
LocusImp * copy() const
Returns a copy of this ObjectImp.
Definition: locus_imp.cc:142
QByteArrayList
QList< QByteArray > QByteArrayList
Definition: objects/common.h:50
ObjectImp
The ObjectImp class represents the behaviour of an object after it is calculated. ...
Definition: object_imp.h:226
CurveImp::getDist
double getDist(double param, const Coordinate &p, const KigDocument &doc) const
This function returns the distance between the point with parameter param and point p...
Definition: curve_imp.cc:137
LocusImp::equals
bool equals(const ObjectImp &rhs) const
Returns true if this ObjectImp is equal to rhs.
Definition: locus_imp.cc:193
ObjectImp::equals
virtual bool equals(const ObjectImp &rhs) const =0
Returns true if this ObjectImp is equal to rhs.
LocusImp::internalContainsPoint
bool internalContainsPoint(const Coordinate &p, double threshold, const KigDocument &doc) const
Definition: locus_imp.cc:227
LocusImp::isPropertyDefinedOnOrThroughThisImp
bool isPropertyDefinedOnOrThroughThisImp(int which) const
Definition: locus_imp.cc:234
CurveImp::getParam
virtual double getParam(const Coordinate &point, const KigDocument &) const
Definition: curve_imp.cc:149
ObjectImp::numberOfProperties
virtual int numberOfProperties() const
Definition: object_imp.cc:58
Coordinate::valid
bool valid() const
Return whether this is a valid Coordinate.
Definition: coordinate.cpp:176
ObjectImpVisitor
Definition: object_imp.h:56
LocusImp::visit
void visit(ObjectImpVisitor *vtor) const
Definition: locus_imp.cc:188
ObjectImp::properties
virtual const QByteArrayList properties() const
Definition: object_imp.cc:51
InvalidImp
This ObjectImp represents an invalid object.
Definition: bogus_imp.h:61
CurveImp
This class represents a curve: something which is composed of points, like a line, a circle, a locus.
Definition: curve_imp.h:27
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:39 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kig

Skip menu "kig"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal