Squashed commit of the following:

commit 8853bf442b6e1a98699fa90fca5eb30b3f6d3a5e
Author: Ian Rees <ian.rees@gmail.com>
Date:   Tue Jul 29 15:46:59 2014 +1200

    Refactoring and small fix in constraint icon bounding boxes

commit c03e4c13d8fd657e18e3c78d16bbdef209f8c779
Author: Ian Rees <ian.rees@gmail.com>
Date:   Mon Jul 28 15:41:15 2014 +1200

    Implemented picking of individual constraints from combined icons

commit 254aaab450fe6646bee7542c532c454af91b6597
Author: Ian Rees <ian.rees@gmail.com>
Date:   Mon Jul 28 13:04:18 2014 +1200

    Added bounding boxes for combined constraint icons

commit 4f0738ec30220fbf1abdea14dd121d0a134e5dfd
Author: Ian Rees <ian.rees@gmail.com>
Date:   Sat Jul 26 18:53:33 2014 +1200

    Added screenCoordsOfPath() to View3DInventorViewer

commit 14e2dc7b4aa79db97cbacd2c848728a66276d644
Author: Ian Rees <ian.rees@gmail.com>
Date:   Sun Jul 20 14:24:27 2014 +1200

    Bit of code to make constraint icon text rendering nicer.

    This won't be useful unless the font changes, but wanted to add it while
    I was thinking about it.

commit 8020d2d62214d71875cbae101d5ac5e96d998201
Author: Ian Rees <ian.rees@gmail.com>
Date:   Sun Jul 20 13:54:51 2014 +1200

    Fixed an off-by-one in ViewProviderSketch::combineConstratintIcons

    Bug resulted in icons occasionally not being combined into groups,
    when they should've been.

commit 20d92a3ccc1f795be1cb86f6f92045518dc8eb81
Author: Ian Rees <ian.rees@gmail.com>
Date:   Tue Jul 15 19:38:20 2014 +1200

    Fixed a bug that was introduced two commits ago.

commit 69e1ea848e3bc3c8c372c539f30a7b4d2a563aa2
Author: Ian Rees <ian.rees@gmail.com>
Date:   Tue Jul 15 15:33:30 2014 +1200

    Fixed dumb copy-and-paste error

commit a998b75a905cc31e1f4f49869e81ecaef5858b69
Author: Ian Rees <ian.rees@gmail.com>
Date:   Sun Jul 13 18:39:22 2014 +1200

    Fixed crash reported by sponssi

    More info at http://forum.freecadweb.org/viewtopic.php?f=10&t=6965&p=56590

commit 27b7b804790dda5164c7ef0b9418f6c160228859
Author: Ian Rees <ian.rees@gmail.com>
Date:   Thu Jul 10 13:32:16 2014 +1200

    Cleaning up my git repo for FreeCAD.

    This branch now has just the Sketcher icon fixes, plus a few random comment edits.
This commit is contained in:
wmayer
2014-07-30 00:35:26 +02:00
parent 1349b7cbf2
commit 4f71c3543e
6 changed files with 884 additions and 245 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
/***************************************************************************
* Copyright (c) 2009 Jürgen Riegel <juergen.riegel@web.de> *
* Copyright (c) 2009 J<EFBFBD>rgen Riegel <juergen.riegel@web.de> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
@@ -25,6 +25,7 @@
#define SKETCHERGUI_VIEWPROVIDERSKETCH_H
#include <Mod/Part/Gui/ViewProvider2DObject.h>
#include <Inventor/SbImage.h>
#include <Inventor/SbColor.h>
#include <Base/Tools2D.h>
#include <Gui/Selection.h>
@@ -38,11 +39,16 @@ class SoSeparator;
class SbLine;
class SbVec3f;
class SoCoordinate3;
class SoInfo;
class SoPointSet;
class SoTransform;
class SoLineSet;
class SoMarkerSet;
class SoImage;
class QImage;
class QColor;
class SoText2;
class SoTranslation;
class SbString;
@@ -56,6 +62,7 @@ namespace Gui {
}
namespace Sketcher {
class Constraint;
class Sketch;
class SketchObject;
}
@@ -88,10 +95,13 @@ public:
App::PropertyBool Autoconstraints;
/// draw constraint icon given the constraint id
/// Draw all constraint icons
/*! Except maybe the radius and lock ones? */
void drawConstraintIcons();
/// draw the sketch in the inventor nodes
void draw(bool temp=false);
/// draw the edit curve
void drawEdit(const std::vector<Base::Vector2D> &EditCurve);
@@ -135,13 +145,23 @@ public:
/** @name helper functions */
//@{
/// give the coordinates of a line on the sketch plane in sketcher (2D) coordinates
void getCoordsOnSketchPlane(double &u, double &v,const SbVec3f &point, const SbVec3f &normal);
void getCoordsOnSketchPlane(double &u, double &v, const SbVec3f &point,
const SbVec3f &normal);
/// give projecting line of position
void getProjectingLine(const SbVec2s&, const Gui::View3DInventorViewer *viewer, SbLine&) const;
void getProjectingLine(const SbVec2s&,
const Gui::View3DInventorViewer *viewer,
SbLine&) const;
/// helper to detect preselection
bool detectPreselection(const SoPickedPoint *Point, int &PtIndex,int &GeoIndex, int &ConstrIndex, int &CrossIndex);
bool detectPreselection(const SoPickedPoint *Point,
const Gui::View3DInventorViewer *viewer,
const SbVec2s &cursorPos);
/// Helper for detectPreselection(), for constraints only.
std::set<int> detectPreselectionConstr(const SoPickedPoint *Point,
const Gui::View3DInventorViewer *viewer,
const SbVec2s &cursorPos);
/// box selection method
void doBoxSelection(const SbVec2s &startPos, const SbVec2s &endPos,
@@ -167,7 +187,6 @@ public:
int getPreselectPoint(void) const;
int getPreselectCurve(void) const;
int getPreselectCross(void) const;
int getPreselectConstraint(void) const;
//@}
/** @name base class implementer */
@@ -190,6 +209,7 @@ public:
//@}
friend class DrawSketchHandler;
friend struct ::EditData;
/// signals if the constraints list has changed
boost::signal<void ()> signalConstraintsChanged;
@@ -221,6 +241,80 @@ protected:
/// build up the visual of the constraints
void rebuildConstraintsVisual(void);
/** @name Protected helpers for drawing constraint icons*/
//@{
QString iconTypeFromConstraint(Sketcher::Constraint *constraint);
/// Returns a QColor object appropriate for constraint with given id
/*! In the case of combined icons, the icon color is chosen based on
* the constraint with the highest priority from constrColorPriority()
*/
QColor constrColor(int constraintId);
/// Used by drawMergedConstraintIcons to decide what color to make icons
/*! See constrColor() */
int constrColorPriority(int constraintId);
/// Internal type used for drawing constraint icons
struct constrIconQueueItem {
/// Type of constraint the icon represents. Eg: "small/Constraint_PointOnObject_sm"
QString type;
/// Internal constraint ID number
/// These map to results of getSketchObject()->Constraints.getValues()
int constraintId;
/// Label to be rendered with this icon, if any
QString label;
/// Absolute coordinates of the constraint icon
SbVec3f position;
/// Pointer to the SoImage object where the icon should be written
SoImage *destination;
/// Pointer to SoInfo object where we store the constraint IDs that the icon refers to
SoInfo *infoPtr;
};
/// Internal type used for drawing constraint icons
typedef std::vector<constrIconQueueItem> IconQueue;
/// For constraint icon bounding boxes
typedef std::pair<QRect, std::set<int> > ConstrIconBB;
/// For constraint icon bounding boxes
typedef std::vector<ConstrIconBB> ConstrIconBBVec;
void combineConstraintIcons(IconQueue iconQueue);
/// Renders an icon for a single constraint and sends it to Coin
void drawTypicalConstraintIcon(const constrIconQueueItem &i);
/// Combines multiple constraint icons and sends them to Coin
void drawMergedConstraintIcons(IconQueue iconQueue);
/// Helper for drawMergedConstraintIcons and drawTypicalConstraintIcon
QImage renderConstrIcon(const QString &type,
const QColor &iconColor,
const QStringList &labels,
const QList<QColor> &labelColors,
//! Gets populated with bounding boxes (in icon
//! image coordinates) for the icon at left, then
//! labels for different constraints.
std::vector<QRect> *boundingBoxes = NULL,
//! If not NULL, gets set to the number of pixels
//! that the text extends below the icon base.
int *vPad = NULL);
/// Copies a QImage constraint icon into a SoImage*
/*! Used by drawTypicalConstraintIcon() and drawMergedConstraintIcons() */
void sendConstraintIconToCoin(const QImage &icon, SoImage *soImagePtr);
/// Essentially a version of sendConstraintIconToCoin, with a blank icon
void clearCoinImage(SoImage *soImagePtr);
/// Returns the size that Coin should display the indicated image at
SbVec3s getDisplayedSize(const SoImage *) const;
//@}
void setPositionText(const Base::Vector2D &Pos, const SbString &txt);
void setPositionText(const Base::Vector2D &Pos);
void resetPositionText(void);