There are different algorithms used to compute the orientation of a new sketch and the orientation of the view.
Explicitly set up vector to the view orientation to match the sketch orientation.
virtual void setViewProjection( double theX, double theY, double theZ,
double theTwist ) = 0;
+ //! Sets the view projection and up direction
+ /// \param theX the X projection value
+ /// \param theY the Y projection value
+ /// \param theZ the Z projection value
+ /// \param theUpX the X value of the up direction vector
+ /// \param theUpY the Y value of the up direction vector
+ /// \param theUpZ the Z value of the up direction vector
+ virtual void setViewProjection( double theX, double theY, double theZ,
+ double theUpX, double theUpY, double theUpZ) = 0;
+
/// Add selection filter to the viewer
/// \param theFilter a selection filter
virtual void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) = 0;
theSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
if (aNormal.get() && aNormal->isInitialized() &&
- anOrigin.get() && anOrigin->isInitialized())
- aPlane = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(anOrigin->pnt(), aNormal->dir()));
+ anOrigin.get() && anOrigin->isInitialized()) {
+ std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ theSketch->data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
+ if (aDirX.get() && aDirX->isInitialized()) {
+ std::shared_ptr<GeomAPI_Ax3> anAxes = std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(anOrigin->pnt(), aDirX->dir(), aNormal->dir()));
+ aPlane = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(anAxes));
+ }
+ else {
+ aPlane = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(anOrigin->pnt(), aNormal->dir()));
+ }
+ }
return aPlane;
}
#define DBL_MAX 1.7976931348623158e+308
#endif
+
+
+//=============================================================================
+//function : setViewProjection
+//purpose : Set the view projection with a specific plane orientation
+//=============================================================================
+static void setViewProjection(ModuleBase_IWorkshop* theWorkshop, const GeomPlanePtr thePlane, bool theReversed)
+{
+ GeomDirPtr aDirection = thePlane->direction();
+ GeomDirPtr aXDirection = thePlane->xDirection();
+ gp_Dir aNormDir = aDirection->impl<gp_Dir>();
+ gp_Dir aXDirPln = aXDirection->impl<gp_Dir>();
+ if (theReversed) {
+ aNormDir.Reverse();
+ aXDirPln.Reverse();
+ }
+
+ gp_Dir aYDirPln = aNormDir.Crossed(aXDirPln);
+
+ // Set the view projection and up direction
+ theWorkshop->viewer()->setViewProjection(aNormDir.X(), aNormDir.Y(), aNormDir.Z(), aYDirPln.X(), aYDirPln.Y(), aYDirPln.Z());
+}
+
+
PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent,
ModuleBase_IWorkshop* theWorkshop,
const Config_WidgetAPI* theData,
}
// 2. if the planes were displayed, change the view projection
- std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
- gp_XYZ aXYZ = aDir->impl<gp_Dir>().XYZ();
- double aTwist = 0.0;
-
// Rotate view if the sketcher plane is selected only from preview planes
// Preview planes are created only if there is no any shape
bool aRotate = Config_PropManager::boolean(SKETCH_TAB_NAME, "rotate_to_plane");
if (aRotate) {
- myWorkshop->viewer()->setViewProjection(aXYZ.X(), aXYZ.Y(), aXYZ.Z(), aTwist);
+ bool aReversed = myViewInverted->isChecked();
+ setViewProjection(myWorkshop, aPlane, aReversed);
}
if (isSetSizeOfView && aSizeOfView > 0) {
Handle(V3d_View) aView3d = myWorkshop->viewer()->activeView();
{
std::shared_ptr<GeomAPI_Pln> aPlane = plane();
if (aPlane.get()) {
- std::shared_ptr<GeomAPI_Dir> aDirection = aPlane->direction();
- gp_Dir aDir = aDirection->impl<gp_Dir>();
- if (myViewInverted->isChecked())
- aDir.Reverse();
- myWorkshop->viewer()->setViewProjection(aDir.X(), aDir.Y(), aDir.Z(), 0.);
+ bool aReversed = myViewInverted->isChecked();
+ setViewProjection(myWorkshop, aPlane, aReversed);
+
PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
if (aModule)
aModule->onViewTransformed();
}
}
+//**********************************************
+void SHAPERGUI_SalomeViewer::setViewProjection(double theX, double theY, double theZ, double theUpX, double theUpY, double theUpZ)
+{
+ if (!mySelector)
+ return;
+
+ SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
+ OCCViewer_ViewFrame* aVFrame = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());
+ if (aVFrame) {
+ Handle(V3d_View) aView3d = aVFrame->getViewPort()->getView();
+ if (!aView3d.IsNull()) {
+ aView3d->SetProj(theX, theY, theZ);
+ aView3d->SetUp (theUpX, theUpY, theUpZ);
+ aView3d->FitAll(0.01, false);
+ if (aView3d->Depth() < 0.1)
+ aView3d->DepthFitAll();
+ }
+ }
+}
+
//***************************************
void SHAPERGUI_SalomeViewer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
{
virtual void setViewProjection( double theX, double theY, double theZ,
double theTwist );
+ //! Sets the view projection and up direction
+ /// \param theX the X projection value
+ /// \param theY the Y projection value
+ /// \param theZ the Z projection value
+ /// \param theUpX the X value of the up direction vector
+ /// \param theUpY the Y value of the up direction vector
+ /// \param theUpZ the Z value of the up direction vector
+ virtual void setViewProjection( double theX, double theY, double theZ,
+ double theUpX, double theUpY, double theUpZ);
+
/// Set selector
/// \param theSel a selector instance
void setSelector(SHAPERGUI_OCCSelector* theSel);
}
}
+void XGUI_ViewerProxy::setViewProjection(double theX, double theY, double theZ, double theUpX, double theUpY, double theUpZ)
+{
+ Handle(V3d_View) aView3d = activeView();
+ if (!aView3d.IsNull()) {
+ aView3d->SetProj(theX, theY, theZ);
+ aView3d->SetUp (theUpX, theUpY, theUpZ);
+ aView3d->FitAll(0.01, false);
+ if (aView3d->Depth() < 0.1)
+ aView3d->DepthFitAll();
+ }
+}
+
void XGUI_ViewerProxy::fitAll()
{
#ifdef HAVE_SALOME
virtual void setViewProjection( double theX, double theY, double theZ,
double theTwist );
+ //! Sets the view projection and up direction
+ /// \param theX the X projection value
+ /// \param theY the Y projection value
+ /// \param theZ the Z projection value
+ /// \param theUpX the X value of the up direction vector
+ /// \param theUpY the Y value of the up direction vector
+ /// \param theUpZ the Z value of the up direction vector
+ virtual void setViewProjection( double theX, double theY, double theZ,
+ double theUpX, double theUpY, double theUpZ);
+
//! Sets the view fitted all
virtual void fitAll();