1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498
|
/*
SPDX-FileCopyrightText: 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
/** \file tool.h
* \brief Note class
*/
// TODO: split this file
#ifndef STEPCORE_TOOL_H
#define STEPCORE_TOOL_H
#include "world.h"
#include "types.h"
#include <QByteArray>
#include <QHash>
#include <QStringList>
namespace StepCore
{
/** \ingroup tools
* \brief Image embedded in Note
*/
class NoteImage: public Item
{
STEPCORE_OBJECT(NoteImage)
public:
/** Constructs NoteImage */
explicit NoteImage(const QString& name = QString(),
const QByteArray& image = QByteArray())
: Item(name), _image(image) {}
/** Get image data */
const QByteArray& image() const { return _image; }
/** Set image data */
void setImage(const QByteArray& image) { _image = image; }
protected:
QByteArray _image;
};
/** \ingroup tools
* \brief LaTeX formula embedded in Note
*/
class NoteFormula: public NoteImage
{
STEPCORE_OBJECT(NoteFormula)
public:
/** Constructs NoteFormula */
explicit NoteFormula(const QString& name = QString(),
const QByteArray& image = QByteArray(),
const QString& code = QString())
: NoteImage(name, image), _code(code) {}
/** Get formula code */
const QString& code() const { return _code; }
/** Set formula code */
void setCode(const QString& code) { _code = code; }
protected:
QString _code;
};
/** \ingroup tools
* \brief Textual note item
*
* Actual displaying of the Note should be
* implemented by application
*/
class Note: public ItemGroup, public Tool
{
STEPCORE_OBJECT(Note)
public:
/** Constructs Note */
explicit Note(const Vector2d &position = Vector2d::Zero(),
const Vector2d &size = Vector2d(250,100), const QString &text = QString());
/** Get position of the note */
const Vector2d& position() const { return _position; }
/** Set position of the note */
void setPosition(const Vector2d& position) { _position = position; }
/** Get size of the note */
const Vector2d& size() const { return _size; }
/** Set size of the note */
void setSize(const Vector2d& size) { _size = size.array().abs(); }
/** Get note text */
const QString& text() const { return _text; }
/** Set note text */
void setText(const QString& text) { _text = text; }
protected:
Vector2d _position;
Vector2d _size;
QString _text;
};
/** \ingroup tools
* \brief Graph item
*
* Actual updating and displaying of the Graph
* should be implemented by application
*/
class Graph: public Item, public Tool
{
STEPCORE_OBJECT(Graph)
public:
/** Constructs Graph */
explicit Graph(const Vector2d &position = Vector2d::Zero(), const Vector2d &size = Vector2d(400,300));
/** Get position of the graph */
const Vector2d& position() const { return _position; }
/** Set position of the graph */
void setPosition(const Vector2d& position) { _position = position; }
/** Get size of the graph */
const Vector2d& size() const { return _size; }
/** Set size of the graph */
void setSize(const Vector2d& size) { _size = size.array().abs(); }
/** Get pointer to the objects for X axis */
Object* objectX() const { return _objectX; }
/** Set pointer to the objects for X axis */
void setObjectX(Object* objectX) { _objectX = objectX; }
/** Get name of the property for X axis */
QString propertyX() const { return _propertyX; }
/** Set name of the property for X axis */
void setPropertyX(const QString& propertyX) { _propertyX = propertyX; }
/** Get vector index for the X axis */
int indexX() const { return _indexX; }
/** Set vector index for the X axis */
void setIndexX(int indexX) { _indexX = indexX; }
/** Get pointer to the objects for Y axis */
Object* objectY() const { return _objectY; }
/** Set pointer to the objects for Y axis */
void setObjectY(Object* objectY) { _objectY = objectY; }
/** Get name of the property for Y axis */
QString propertyY() const { return _propertyY; }
/** Set name of the property for Y axis */
void setPropertyY(const QString& propertyY) { _propertyY = propertyY; }
/** Get vector index for the Y axis */
int indexY() const { return _indexY; }
/** Set vector index for the Y axis */
void setIndexY(int indexY) { _indexY = indexY; }
/** Get auto-limits for X axis */
bool autoLimitsX() const { return _autoLimitsX; }
/** Set auto-limits for X axis */
void setAutoLimitsX(bool autoLimitsX) { _autoLimitsX = autoLimitsX; }
/** Get auto-limits for Y axis */
bool autoLimitsY() const { return _autoLimitsY; }
/** Set auto-limits for Y axis */
void setAutoLimitsY(bool autoLimitsY) { _autoLimitsY = autoLimitsY; }
/** Get limits for X axis */
const Vector2d& limitsX() const { return _limitsX; }
/** Set limits for X axis */
void setLimitsX(const Vector2d& limitsX) { _limitsX = limitsX; }
/** Get limits for Y axis */
const Vector2d& limitsY() const { return _limitsY; }
/** Set limits for Y axis */
void setLimitsY(const Vector2d& limitsY) { _limitsY = limitsY; }
/** Get show-lines flag */
bool showLines() const { return _showLines; }
/** Set show-lines flag */
void setShowLines(bool showLines) { _showLines = showLines; }
/** Get show-points flag */
bool showPoints() const { return _showPoints; }
/** Set show-points flag */
void setShowPoints(bool showPoints) { _showPoints = showPoints; }
/** Get points list */
const Vector2dList& points() const { return _points; }
/** Set points list */
void setPoints(const Vector2dList& points) { _points = points; }
/** Get pointer to the property for X axis (or zero if not defined) */
const MetaProperty* propertyXPtr() const {
return _objectX ? _objectX->metaObject()->property(_propertyX) : nullptr;
}
/** Get pointer to the property for Y axis (or zero if not defined) */
const MetaProperty* propertyYPtr() const {
return _objectY ? _objectY->metaObject()->property(_propertyY) : nullptr;
}
/** Returns true if X-axis data source is valid */
bool isValidX() const;
/** Returns true if Y-axis data source is valid */
bool isValidY() const;
/** Returns true if X- and Y-axis data source is valid */
bool isValid() const { return isValidX() && isValidY(); }
/** Get current point value */
Vector2d currentValue() const { return currentValue(nullptr); }
/** Get current point value
* \param ok Will indicate success of operation (if not null) */
Vector2d currentValue(bool* ok) const;
/** Get current point value and add it to points list
* \param ok Will indicate success of operation (if not null) */
Vector2d recordPoint(bool* ok = nullptr);
/** Clear points list */
void clearPoints() { _points.clear(); }
/** Return units of propertyX */
QString unitsX() const;
/** Return units of propertyY */
QString unitsY() const;
//void worldItemRemoved(Item* item);
//void setWorld(World* world);
protected:
Vector2d _position;
Vector2d _size;
Object* _objectX;
QString _propertyX;
int _indexX;
Object* _objectY;
QString _propertyY;
int _indexY;
bool _autoLimitsX;
bool _autoLimitsY;
Vector2d _limitsX;
Vector2d _limitsY;
bool _showLines;
bool _showPoints;
Vector2dList _points;
};
/** \ingroup tools
* \brief Meter to observe properties of other objects
*
* Actual displaying of the Meter and its user interaction
* should be implemented by application
*/
class Meter: public Item, public Tool
{
STEPCORE_OBJECT(Meter)
public:
/** Constructs Meter */
explicit Meter(const Vector2d &position = Vector2d::Zero(), const Vector2d &size = Vector2d(70,24));
/** Get position of the meter */
const Vector2d& position() const { return _position; }
/** Set position of the meter */
void setPosition(const Vector2d& position) { _position = position; }
/** Get size of the meter */
const Vector2d& size() const { return _size; }
/** Set size of the meter */
void setSize(const Vector2d& size) { _size = size.array().abs(); }
/** Get pointer to the observed object */
Object* object() const { return _object; }
/** Set pointer to the observed object */
void setObject(Object* object) { _object = object; }
/** Get name of the observed property */
QString property() const { return _property; }
/** Set name of the observed property */
void setProperty(const QString& property) { _property = property; }
/** Get vector index of the observed property */
int index() const { return _index; }
/** Set vector index of the observed property */
void setIndex(int index) { _index = index; }
/** Get display digits */
int digits() const { return _digits; }
/** Set display digits */
void setDigits(int digits) { _digits = digits; }
/** Returns true if observed property is valid */
bool isValid() const;
/** Get pointer to the observed property */
const MetaProperty* propertyPtr() const {
return _object ? _object->metaObject()->property(_property) : nullptr;
}
/** Get value of the observed property */
double value() const { return value(nullptr); }
/** Set value of the controlled property */
virtual void setValue(double) {}
/** Get value of the observed property
* \param ok Will indicate success of operation (if not null) */
double value(bool* ok) const;
/** Return units of measured property */
QString units() const;
//void worldItemRemoved(Item* item);
//void setWorld(World* world);
protected:
Vector2d _position;
Vector2d _size;
Object* _object;
QString _property;
int _index;
int _digits;
};
/** \ingroup tools
* \brief Controller item to control properties of other objects
*
* Actual displaying of the Controller and its user interaction
* should be implemented by application
*/
class Controller: public Item, public Tool
{
STEPCORE_OBJECT(Controller)
public:
/** Constructs Controller */
explicit Controller(const Vector2d &position = Vector2d::Zero(), const Vector2d &size = Vector2d(200,60));
/** Get position of the Controller */
const Vector2d& position() const { return _position; }
/** Set position of the Controller */
void setPosition(const Vector2d& position) { _position = position; }
/** Get size of the Controller */
const Vector2d& size() const { return _size; }
/** Set size of the Controller */
void setSize(const Vector2d& size) { _size = size.array().abs(); }
/** Get pointer to the controlled object */
Object* object() const { return _object; }
/** Set pointer to the controlled object */
void setObject(Object* object) { _object = object; }
/** Get name of the controlled property */
QString property() const { return _property; }
/** Set name of the controlled property */
void setProperty(const QString& property) { _property = property; }
/** Get vector index of the controlled property */
int index() const { return _index; }
/** Set vector index of the controlled property */
void setIndex(int index) { _index = index; }
/** Get GUI slider limits */
const Vector2d& limits() const { return _limits; }
/** Set GUI slider limits */
void setLimits(const Vector2d& limits) { _limits = limits; }
/** Get GUI increase shortcut */
const QString& decreaseShortcut() const { return _decreaseShortcut; }
/** Set GUI increase shortcut */
void setDecreaseShortcut(const QString& decreaseShortcut) { _decreaseShortcut = decreaseShortcut; }
/** Get GUI decrease shortcut */
const QString& increaseShortcut() const { return _increaseShortcut; }
/** Set GUI decrease shortcut */
void setIncreaseShortcut(const QString& increaseShortcut) { _increaseShortcut = increaseShortcut; }
/** Get increment step */
double increment() const { return _increment; }
/** Set increment step */
void setIncrement(double increment) { _increment = increment; }
/** Returns true if controlled property is valid */
bool isValid() const;
/** Get pointer to the controlled property */
const MetaProperty* propertyPtr() const {
return _object ? _object->metaObject()->property(_property) : nullptr;
}
/** Get value of the controlled property */
double value() const { return value(nullptr); }
/** Set value of the controlled property */
void setValue(double value) { setValue(value, nullptr); }
/** Get value of the controlled property
* \param ok Will indicate success of operation (if not null) */
double value(bool* ok) const;
/** Set value of the controlled property
* \param value New value for the property
* \param ok Will indicate success of operation (if not null) */
void setValue(double value, bool* ok);
/** Return units of measured property */
QString units() const;
//void worldItemRemoved(Item* item);
//void setWorld(World* world);
protected:
Vector2d _position;
Vector2d _size;
Object* _object;
QString _property;
int _index;
Vector2d _limits;
QString _decreaseShortcut;
QString _increaseShortcut;
double _increment;
};
class Particle;
class RigidBody;
/** \ingroup tools
* \brief Traces position of the body
*
* Actual displaying of the Traces and its user interaction
* should be implemented by application
*/
class Tracer: public Item, public Tool
{
STEPCORE_OBJECT(Tracer)
public:
/** Constructs Spring */
explicit Tracer(Object* body = nullptr, const Vector2d& localPosition = Vector2d::Zero());
/** Get pointer to the first body */
Object* body() const { return _body; }
/** Set pointer to the first connected body */
void setBody(Object* body);
/** Local position of the tracer on the body
* or in the world (if the tracer is not connected) */
Vector2d localPosition() const { return _localPosition; }
/** Set local position of the tracer on the body
* or in the world (if the tracer is not connected) */
void setLocalPosition(const Vector2d& localPosition) { _localPosition = localPosition; }
/** Position of the tracer */
Vector2d position() const;
/** Get points list */
const Vector2dList& points() const { return _points; }
/** Set points list */
void setPoints(const Vector2dList& points) { _points = points; }
/** Get current position value and add it to points list */
Vector2d recordPoint() { Vector2d p = position(); _points.push_back(p); return p; }
/** Clear points list */
void clearPoints() { _points.clear(); }
//void worldItemRemoved(Item* item);
//void setWorld(World* world);
protected:
Object* _body;
Vector2d _localPosition;
Vector2dList _points;
Particle* _p;
RigidBody* _r;
};
} // namespace StepCore
#endif
|