Part/Sketcher: Grid - set grid orientation
========================================== Extend ViewProviderGridExtension so that it is aware of the absolute direction of the XY plane on which the grid is to be drawn. Fix the calculation of the cam origin.
This commit is contained in:
committed by
abdullahtahiriyo
parent
b4926c769e
commit
849f8ced13
@@ -79,6 +79,8 @@ public:
|
||||
void getClosestGridPoint(double &x, double &y) const;
|
||||
double getGridSize() const;
|
||||
|
||||
void setGridOrientation(Base::Vector3d origin, Base::Rotation rotation);
|
||||
|
||||
// Configurable parameters (to be configured by specific VP)
|
||||
int GridSizePixelThreshold = 15;
|
||||
int GridNumberSubdivision = 10;
|
||||
@@ -99,9 +101,14 @@ private:
|
||||
|
||||
void createEditModeInventorNodes();
|
||||
|
||||
SbVec3f camCenterOnSketch;
|
||||
Base::Vector3d getCamCenterInSketchCoordinates() const;
|
||||
|
||||
SbVec3f camCenterPointOnFocalPlane;
|
||||
float camMaxDimension;
|
||||
|
||||
Base::Vector3d gridOrigin;
|
||||
Base::Rotation gridRotation;
|
||||
|
||||
private:
|
||||
ViewProviderGridExtension * vp;
|
||||
|
||||
@@ -118,7 +125,7 @@ private:
|
||||
|
||||
|
||||
GridExtensionP::GridExtensionP(ViewProviderGridExtension * vp):
|
||||
camCenterOnSketch(SbVec3f(0., 0., 0.)),
|
||||
camCenterPointOnFocalPlane(SbVec3f(0., 0., 0.)),
|
||||
camMaxDimension(200.),
|
||||
vp(vp),
|
||||
GridRoot(nullptr)
|
||||
@@ -136,6 +143,12 @@ GridExtensionP::~GridExtensionP()
|
||||
GridRoot->unref();
|
||||
}
|
||||
|
||||
void GridExtensionP::setGridOrientation(Base::Vector3d origin, Base::Rotation rotation)
|
||||
{
|
||||
gridOrigin = origin;
|
||||
gridRotation = rotation;
|
||||
}
|
||||
|
||||
double GridExtensionP::getGridSize() const
|
||||
{
|
||||
return computedGridValue;
|
||||
@@ -169,10 +182,10 @@ bool GridExtensionP::checkCameraZoomChange(const Gui::View3DInventorViewer* view
|
||||
bool GridExtensionP::checkCameraTranslationChange(const Gui::View3DInventorViewer* viewer)
|
||||
{
|
||||
//Then we check if user moved by more than 10% of camera dimension (must be after updating camera dimension).
|
||||
SbVec3f newCamCenterOnSketch = viewer->getCenterPointOnFocalPlane();
|
||||
SbVec3f newCamCenterPointOnFocalPlane = viewer->getCenterPointOnFocalPlane();
|
||||
|
||||
if ((camCenterOnSketch - newCamCenterOnSketch).length() > 0.1 * camMaxDimension) {
|
||||
camCenterOnSketch = newCamCenterOnSketch;
|
||||
if ((camCenterPointOnFocalPlane - newCamCenterPointOnFocalPlane).length() > 0.1 * camMaxDimension) {
|
||||
camCenterPointOnFocalPlane = newCamCenterPointOnFocalPlane;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -305,8 +318,11 @@ void GridExtensionP::createGridPart(int numberSubdiv, bool subDivLines, bool div
|
||||
vts->vertex.setNum(2 * nlines);
|
||||
SbVec3f* vertex_coords = vts->vertex.startEditing();
|
||||
|
||||
float minX, minY, maxX, maxY, z;
|
||||
camCenterOnSketch.getValue(minX, minY, z);
|
||||
float minX, minY, maxX, maxY;
|
||||
Base::Vector3d camCenterOnSketch = getCamCenterInSketchCoordinates();
|
||||
minX = static_cast<float>(camCenterOnSketch.x);
|
||||
minY = static_cast<float>(camCenterOnSketch.y);
|
||||
|
||||
minX -= (gridDimension / 2);
|
||||
minY -= (gridDimension / 2);
|
||||
maxX = minX + gridDimension;
|
||||
@@ -348,6 +364,23 @@ void GridExtensionP::createGridPart(int numberSubdiv, bool subDivLines, bool div
|
||||
parent->addChild(grid);
|
||||
}
|
||||
|
||||
Base::Vector3d GridExtensionP::getCamCenterInSketchCoordinates() const
|
||||
{
|
||||
Base::Vector3d xaxis(1, 0, 0), yaxis(0, 1, 0);
|
||||
|
||||
gridRotation.multVec(xaxis,xaxis);
|
||||
gridRotation.multVec(yaxis,yaxis);
|
||||
|
||||
float x,y,z;
|
||||
camCenterPointOnFocalPlane.getValue(x, y, z);
|
||||
|
||||
Base::Vector3d center (x,y,z);
|
||||
|
||||
center.TransformToCoordinateSystem(gridOrigin, xaxis, yaxis);
|
||||
|
||||
return center;
|
||||
}
|
||||
|
||||
void GridExtensionP::setEnabled(bool enable)
|
||||
{
|
||||
enabled=enable;
|
||||
@@ -413,6 +446,11 @@ void ViewProviderGridExtension::drawGrid(bool cameraUpdate)
|
||||
pImpl->drawGrid(cameraUpdate);
|
||||
}
|
||||
|
||||
void ViewProviderGridExtension::setGridOrientation(Base::Vector3d origin, Base::Rotation rotation)
|
||||
{
|
||||
pImpl->setGridOrientation(origin, rotation);
|
||||
}
|
||||
|
||||
SoSeparator* ViewProviderGridExtension::getGridNode()
|
||||
{
|
||||
return pImpl->getGridRoot();
|
||||
|
||||
@@ -24,11 +24,14 @@
|
||||
#ifndef PARTGUI_VIEWPROVIDERGRIDEXTENSION_H
|
||||
#define PARTGUI_VIEWPROVIDERGRIDEXTENSION_H
|
||||
|
||||
#include <Gui/ViewProviderExtensionPython.h>
|
||||
#include <Mod/Part/PartGlobal.h>
|
||||
#include <Base/Vector3D.h>
|
||||
#include <Base/Rotation.h>
|
||||
#include <App/Material.h>
|
||||
#include <App/PropertyStandard.h>
|
||||
#include <App/PropertyUnits.h>
|
||||
#include <App/Material.h>
|
||||
#include <Gui/ViewProviderExtensionPython.h>
|
||||
|
||||
#include <Mod/Part/PartGlobal.h>
|
||||
|
||||
namespace PartGui {
|
||||
|
||||
@@ -55,6 +58,8 @@ public:
|
||||
|
||||
SoSeparator* getGridNode();
|
||||
|
||||
void setGridOrientation(Base::Vector3d origin, Base::Rotation rotation);
|
||||
|
||||
/** Return the distance to the closest point in the grid.
|
||||
* The point closer to the grid is returned by reference
|
||||
*/
|
||||
|
||||
@@ -2844,6 +2844,8 @@ bool ViewProviderSketch::setEdit(int ModNum)
|
||||
this->attachSelection();
|
||||
|
||||
auto gridnode = getGridNode();
|
||||
Base::Placement plm = getEditingPlacement();
|
||||
setGridOrientation(plm.getPosition(), plm.getRotation());
|
||||
addNodeToRoot(gridnode);
|
||||
setGridEnabled(true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user