Gui: add method to convert between QPoint and SbVec2s considering device pixel ratio
This commit is contained in:
@@ -2424,6 +2424,34 @@ SbVec2s View3DInventorViewer::getPointOnScreen(const SbVec3f& pnt) const
|
||||
return SbVec2s(x, y);
|
||||
}
|
||||
|
||||
QPoint View3DInventorViewer::toQPoint(const SbVec2s& pnt) const
|
||||
{
|
||||
const SbViewportRegion& vp = this->getSoRenderManager()->getViewportRegion();
|
||||
const SbVec2s& vps = vp.getViewportSizePixels();
|
||||
int xpos = pnt[0];
|
||||
int ypos = vps[1] - pnt[0] - 1;
|
||||
|
||||
qreal dev_pix_ratio = devicePixelRatio();
|
||||
xpos = int(std::roundf(xpos / dev_pix_ratio));
|
||||
ypos = int(std::roundf(ypos / dev_pix_ratio));
|
||||
|
||||
return QPoint(xpos, ypos);
|
||||
}
|
||||
|
||||
SbVec2s View3DInventorViewer::fromQPoint(const QPoint& pnt) const
|
||||
{
|
||||
const SbViewportRegion& vp = this->getSoRenderManager()->getViewportRegion();
|
||||
const SbVec2s& vps = vp.getViewportSizePixels();
|
||||
int xpos = pnt.x();
|
||||
int ypos = pnt.y();
|
||||
|
||||
qreal dev_pix_ratio = devicePixelRatio();
|
||||
xpos = int(std::roundf(xpos * dev_pix_ratio));
|
||||
ypos = int(std::roundf(ypos * dev_pix_ratio));
|
||||
|
||||
return SbVec2s(short(xpos), vps[1] - short(ypos) - 1);
|
||||
}
|
||||
|
||||
void View3DInventorViewer::getNearPlane(SbVec3f& rcPt, SbVec3f& rcNormal) const
|
||||
{
|
||||
SoCamera* pCam = getSoRenderManager()->getCamera();
|
||||
|
||||
@@ -305,27 +305,48 @@ public:
|
||||
void setViewDirection(SbVec3f);
|
||||
/** Returns the up direction */
|
||||
SbVec3f getUpDirection() const;
|
||||
|
||||
/** Returns the orientation of the camera. */
|
||||
SbRotation getCameraOrientation() const;
|
||||
|
||||
/** Returns the 3d point on the focal plane to the given 2d point. */
|
||||
SbVec3f getPointOnFocalPlane(const SbVec2s&) const;
|
||||
|
||||
/** Returns the 2d coordinates on the screen to the given 3d point. */
|
||||
SbVec2s getPointOnScreen(const SbVec3f&) const;
|
||||
|
||||
/** Converts Inventor coordinates into Qt coordinates.
|
||||
* The conversion takes the device pixel ratio into account.
|
||||
*/
|
||||
QPoint toQPoint(const SbVec2s&) const;
|
||||
|
||||
/** Converts Qt coordinates into Inventor coordinates.
|
||||
* The conversion takes the device pixel ratio into account.
|
||||
*/
|
||||
SbVec2s fromQPoint(const QPoint&) const;
|
||||
|
||||
/** Returns the near plane represented by its normal and base point. */
|
||||
void getNearPlane(SbVec3f& rcPt, SbVec3f& rcNormal) const;
|
||||
|
||||
/** Returns the far plane represented by its normal and base point. */
|
||||
void getFarPlane(SbVec3f& rcPt, SbVec3f& rcNormal) const;
|
||||
|
||||
/** Adds or remove a manipulator to/from the scenegraph. */
|
||||
void toggleClippingPlane(int toggle=-1, bool beforeEditing=false,
|
||||
bool noManip=false, const Base::Placement &pla = Base::Placement());
|
||||
|
||||
/** Checks whether a clipping plane is set or not. */
|
||||
bool hasClippingPlane() const;
|
||||
|
||||
/** Project the given normalized 2d point onto the near plane */
|
||||
SbVec3f projectOnNearPlane(const SbVec2f&) const;
|
||||
|
||||
/** Project the given normalized 2d point onto the far plane */
|
||||
SbVec3f projectOnFarPlane(const SbVec2f&) const;
|
||||
|
||||
/** Project the given 2d point to a line */
|
||||
void projectPointToLine(const SbVec2s&, SbVec3f& pt1, SbVec3f& pt2) const;
|
||||
|
||||
/** Get the normalized position of the 2d point. */
|
||||
SbVec2f getNormalizedPosition(const SbVec2s&) const;
|
||||
//@}
|
||||
|
||||
@@ -1312,9 +1312,11 @@ Py::Object View3DInventorPy::getCursorPos(const Py::Tuple& args)
|
||||
throw Py::Exception();
|
||||
try {
|
||||
QPoint pos = getView3DIventorPtr()->mapFromGlobal(QCursor::pos());
|
||||
auto viewer = getView3DIventorPtr()->getViewer();
|
||||
SbVec2s vec = viewer->fromQPoint(pos);
|
||||
Py::Tuple tuple(2);
|
||||
tuple.setItem(0, Py::Int(pos.x()));
|
||||
tuple.setItem(1, Py::Int(getView3DIventorPtr()->height()-pos.y()-1));
|
||||
tuple.setItem(0, Py::Int(vec[0]));
|
||||
tuple.setItem(1, Py::Int(vec[1]));
|
||||
return tuple;
|
||||
}
|
||||
catch (const Py::Exception&) {
|
||||
|
||||
Reference in New Issue
Block a user