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

kig

  • sources
  • kde-4.14
  • kdeedu
  • kig
  • objects
angle_type.cc
Go to the documentation of this file.
1 // Copyright (C) 2003 Dominique Devriese <devriese@kde.org>
2 // Copyright (C) 2004 Pino Toscano <toscano.pino@tiscali.it>
3 
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 // 02110-1301, USA.
18 
19 #include "angle_type.h"
20 
21 #include "bogus_imp.h"
22 #include "other_imp.h"
23 #include "point_imp.h"
24 #include "../misc/calcpaths.h"
25 #include "../misc/common.h"
26 #include "../misc/goniometry.h"
27 #include "../misc/kiginputdialog.h"
28 #include "../kig/kig_commands.h"
29 #include "../kig/kig_part.h"
30 #include "../kig/kig_view.h"
31 
32 #include <functional>
33 #include <algorithm>
34 #include <cmath>
35 #include <math.h>
36 
37 #include <qstringlist.h>
38 
39 static const char* constructanglethroughpoint =
40  I18N_NOOP( "Construct an angle through this point" );
41 
42 static const ArgsParser::spec argsspecAngle[] =
43 {
44  { PointImp::stype(), constructanglethroughpoint,
45  I18N_NOOP( "Select a point that the first half-line of the angle should go through..." ), true },
46  { PointImp::stype(), I18N_NOOP( "Construct an angle at this point" ),
47  I18N_NOOP( "Select the point to construct the angle in..." ), true },
48  { PointImp::stype(), constructanglethroughpoint,
49  I18N_NOOP( "Select a point that the second half-line of the angle should go through..." ), true }
50 };
51 
52 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( AngleType )
53 
54 AngleType::AngleType()
55  : ArgsParserObjectType( "Angle", argsspecAngle, 3 )
56 {
57 }
58 
59 AngleType::~AngleType()
60 {
61 }
62 
63 const AngleType* AngleType::instance()
64 {
65  static const AngleType t;
66  return &t;
67 }
68 
69 ObjectImp* AngleType::calc( const Args& parents, const KigDocument& ) const
70 {
71  if ( ! margsparser.checkArgs( parents, 2 ) ) return new InvalidImp;
72 
73  std::vector<Coordinate> points;
74  for ( uint i = 0; i < parents.size(); ++i )
75  points.push_back(
76  static_cast<const PointImp*>( parents[i] )->coordinate() );
77 
78  Coordinate lvect = points[0] - points[1];
79  Coordinate rvect;
80  bool markRightAngle = true;
81 
82  if ( points.size() == 3 )
83  {
84  rvect = points[2] - points[1];
85  }
86  else
87  {
88  rvect = lvect.orthogonal();
89  markRightAngle = false; // angle is still incomplete
90  }
91 
92  double startangle = atan2( lvect.y, lvect.x );
93  double endangle = atan2( rvect.y, rvect.x );
94  double anglelength = endangle - startangle;
95  if ( anglelength < 0 ) anglelength += 2* M_PI;
96  if ( startangle < 0 ) startangle += 2*M_PI;
97 
98  return new AngleImp( points[1], startangle, anglelength, markRightAngle );
99 }
100 
101 const ObjectImpType* AngleType::resultId() const
102 {
103  return AngleImp::stype();
104 }
105 
106 QStringList AngleType::specialActions() const
107 {
108  QStringList ret;
109 
110  ret << i18n( "Set Si&ze" );
111  ret << i18n( "Toggle &Right Angle Mark" );
112 
113  return ret;
114 }
115 
116 void AngleType::executeAction(
117  int i, ObjectHolder&, ObjectTypeCalcer& t,
118  KigPart& d, KigWidget& w, NormalMode& ) const
119 {
120  if ( i == 0 )
121  {
122  std::vector<ObjectCalcer*> parents = t.parents();
123 
124  assert( margsparser.checkArgs( parents ) );
125 
126  Coordinate a = static_cast<const PointImp*>( parents[0]->imp() )->coordinate();
127  Coordinate b = static_cast<const PointImp*>( parents[1]->imp() )->coordinate();
128  Coordinate c = static_cast<const PointImp*>( parents[2]->imp() )->coordinate();
129 
130  Coordinate lvect = a - b;
131  Coordinate rvect = c - b;
132 
133  double startangle = atan2( lvect.y, lvect.x );
134  double endangle = atan2( rvect.y, rvect.x );
135  double anglelength = endangle - startangle;
136  if ( anglelength < 0 ) anglelength += 2* M_PI;
137  if ( startangle < 0 ) startangle += 2*M_PI;
138 
139  Goniometry go( anglelength, Goniometry::Rad );
140  go.convertTo( Goniometry::Deg );
141 
142  bool ok;
143  Goniometry newsize = KigInputDialog::getAngle( &w, &ok, go );
144  if ( !ok )
145  return;
146  newsize.convertTo( Goniometry::Rad );
147 
148  double newcangle = startangle + newsize.value();
149  Coordinate cdir( cos( newcangle ), sin( newcangle ) );
150  Coordinate nc = b + cdir.normalize( rvect.length() );
151 
152  MonitorDataObjects mon( getAllParents( parents ) );
153  parents[2]->move( nc, d.document() );
154  KigCommand* kc = new KigCommand( d, i18n( "Resize Angle" ) );
155  mon.finish( kc );
156  d.history()->push( kc );
157  }
158  else if ( i == 1 )
159  {
160  AngleImp * angleImp = const_cast< AngleImp * >( dynamic_cast< const AngleImp *>( t.imp() ) );
161 
162  angleImp->setMarkRightAngle( !angleImp->markRightAngle() );
163  d.redrawScreen();
164  }
165 }
166 
167 KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( HalfAngleType )
168 
169 HalfAngleType::HalfAngleType()
170  : ArgsParserObjectType( "HalfAngle", argsspecAngle, 3 )
171 {
172 }
173 
174 HalfAngleType::~HalfAngleType()
175 {
176 }
177 
178 const HalfAngleType* HalfAngleType::instance()
179 {
180  static const HalfAngleType t;
181  return &t;
182 }
183 
184 ObjectImp* HalfAngleType::calc( const Args& parents, const KigDocument& ) const
185 {
186  if ( ! margsparser.checkArgs( parents, 2 ) ) return new InvalidImp;
187 
188  std::vector<Coordinate> points;
189  for ( uint i = 0; i < parents.size(); ++i )
190  points.push_back(
191  static_cast<const PointImp*>( parents[i] )->coordinate() );
192 
193  Coordinate lvect = points[0] - points[1];
194  Coordinate rvect;
195  if ( points.size() == 3 )
196  rvect = points[2] - points[1];
197  else
198  {
199  rvect = lvect.orthogonal();
200  }
201 
202  double startangle = atan2( lvect.y, lvect.x );
203  double endangle = atan2( rvect.y, rvect.x );
204  double anglelength = endangle - startangle;
205  if ( anglelength < 0 ) anglelength += 2 * M_PI;
206  if ( startangle < 0 ) startangle += 2 * M_PI;
207 
208  if ( anglelength > M_PI )
209  {
210  startangle += anglelength;
211  anglelength = 2 * M_PI - anglelength;
212  if ( startangle > 2 * M_PI ) startangle -= 2 * M_PI;
213  if ( anglelength < 0 ) anglelength += 2 * M_PI;
214  }
215 
216  return new AngleImp( points[1], startangle, anglelength, true );
217 }
218 
219 const ObjectImpType* HalfAngleType::resultId() const
220 {
221  return AngleImp::stype();
222 }
223 
HalfAngleType::calc
ObjectImp * calc(const Args &args, const KigDocument &) const
Definition: angle_type.cc:184
ObjectImpType
Instances of this class represent a certain ObjectImp type.
Definition: object_imp.h:95
HalfAngleType::resultId
const ObjectImpType * resultId() const
returns the ObjectImp id of the ObjectImp's produced by this ObjectType.
Definition: angle_type.cc:219
Goniometry
Manage an angle and convert it from/to other goniometric systems.
Definition: goniometry.h:28
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE(SegmentAxisType)
point_imp.h
ArgsParserObjectType
This is a convenience subclass of ObjectType that a type should inherit from if its parents can be sp...
Definition: object_type.h:113
AngleType::calc
ObjectImp * calc(const Args &args, const KigDocument &) const
Definition: angle_type.cc:69
KigCommand
a KigCommand represents almost every action performed in Kig.
Definition: kig_commands.h:44
AngleType
Definition: angle_type.h:24
Goniometry::Deg
Definition: goniometry.h:31
AngleType::instance
static const AngleType * instance()
Definition: angle_type.cc:63
KigPart::document
const KigDocument & document() const
Definition: kig_part.cpp:986
KigPart::history
QUndoStack * history()
Definition: kig_part.cpp:630
HalfAngleType::instance
static const HalfAngleType * instance()
Definition: angle_type.cc:178
ObjectTypeCalcer
This is an ObjectCalcer that uses one of the various ObjectType's to calculate its ObjectImp...
Definition: object_calcer.h:183
angle_type.h
Coordinate
The Coordinate class is the basic class representing a 2D location by its x and y components...
Definition: coordinate.h:33
Coordinate::length
double length() const
Length.
Definition: coordinate.cpp:144
ArgsParserObjectType::margsparser
const ArgsParser margsparser
Definition: object_type.h:117
getAllParents
std::vector< ObjectCalcer * > getAllParents(const std::vector< ObjectCalcer * > &objs)
This function returns all objects above the given in the dependency graph.
Definition: calcpaths.cc:229
Coordinate::normalize
const Coordinate normalize(double length=1) const
Normalize.
Definition: coordinate.cpp:154
KigPart::redrawScreen
void redrawScreen()
Definition: kig_part.cpp:977
ObjectHolder
An ObjectHolder represents an object as it is known to the document.
Definition: object_holder.h:40
ObjectTypeCalcer::imp
const ObjectImp * imp() const
Returns the ObjectImp of this ObjectCalcer.
Definition: object_calcer.cc:100
bogus_imp.h
AngleType::resultId
const ObjectImpType * resultId() const
returns the ObjectImp id of the ObjectImp's produced by this ObjectType.
Definition: angle_type.cc:101
PointImp
An ObjectImp representing a point.
Definition: point_imp.h:27
Args
std::vector< const ObjectImp * > Args
Definition: objects/common.h:47
AngleType::executeAction
void executeAction(int i, ObjectHolder &o, ObjectTypeCalcer &c, KigPart &d, KigWidget &w, NormalMode &m) const
execute the i 'th action from the specialActions above.
Definition: angle_type.cc:116
MonitorDataObjects
this class monitors a set of DataObjects for changes and returns an appropriate ChangeObjectImpsComma...
Definition: kig_commands.h:153
AngleImp::markRightAngle
bool markRightAngle() const
Definition: other_imp.h:89
KigWidget
This class is the real widget showing the document.
Definition: kig_view.h:50
ArgsParser::checkArgs
bool checkArgs(const std::vector< ObjectCalcer * > &os) const
Definition: argsparser.cpp:222
QStringList
ArgsParser::spec
Definition: argsparser.h:113
MonitorDataObjects::finish
void finish(KigCommand *comm)
add the generated KigCommandTasks to the command comm .
Definition: kig_commands.cpp:227
KigInputDialog::getAngle
static Goniometry getAngle(QWidget *parent, bool *ok, const Goniometry &g)
Static convenience function to get an angle incapsulated in a Goniometry class.
Definition: kiginputdialog.cc:286
Goniometry::Rad
Definition: goniometry.h:31
AngleImp::setMarkRightAngle
void setMarkRightAngle(bool markRightAngle)
Definition: other_imp.h:91
PointImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing PointImp's.
Definition: point_imp.cc:159
AngleImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the AngleImp type.
Definition: other_imp.cc:597
constructanglethroughpoint
static const char * constructanglethroughpoint
Definition: angle_type.cc:39
KigDocument
KigDocument is the class holding the real data in a Kig document.
Definition: kig_document.h:36
ObjectTypeCalcer::parents
std::vector< ObjectCalcer * > parents() const
Returns the parent ObjectCalcer's of this ObjectCalcer.
Definition: object_calcer.cc:105
Coordinate::x
double x
X Component.
Definition: coordinate.h:126
Coordinate::orthogonal
const Coordinate orthogonal() const
Orthogonal.
Definition: coordinate.cpp:149
Coordinate::y
double y
Y Component.
Definition: coordinate.h:129
ObjectImp
The ObjectImp class represents the behaviour of an object after it is calculated. ...
Definition: object_imp.h:226
KigPart
This is a "Part".
Definition: kig_part.h:68
AngleType::specialActions
QStringList specialActions() const
return i18n'd names for the special actions.
Definition: angle_type.cc:106
NormalMode
Definition: normal.h:26
uint
unsigned int uint
Definition: object_imp.h:87
QUndoStack::push
void push(QUndoCommand *cmd)
Goniometry::convertTo
void convertTo(Goniometry::System system)
Set the system of the current angle to system and convert the value to the new system using convert()...
Definition: goniometry.cc:64
HalfAngleType
Definition: angle_type.h:39
InvalidImp
This ObjectImp represents an invalid object.
Definition: bogus_imp.h:61
other_imp.h
AngleImp
An ObjectImp representing an angle.
Definition: other_imp.h:28
Goniometry::value
double value() const
Definition: goniometry.cc:54
argsspecAngle
static const ArgsParser::spec argsspecAngle[]
Definition: angle_type.cc:42
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:12:05 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
  • 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