#include <SketchPlugin_SketchEntity.h>
PartSet_PreviewSketchPlane::PartSet_PreviewSketchPlane()
- : myPreviewIsDisplayed(false)
+ : myPreviewIsDisplayed(false), mySizeOfView(0), myIsUseSizeOfView(false)
{
}
theSketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
theSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
- myShape = GeomAlgoAPI_FaceBuilder::squareFace(anOrigin->pnt(), aNormal->dir(),
- Config_PropManager::integer(SKETCH_TAB_NAME, "planes_size"));
+
+ double aFaceSize = myIsUseSizeOfView ? mySizeOfView
+ : Config_PropManager::integer(SKETCH_TAB_NAME, "planes_size");
+ myShape = GeomAlgoAPI_FaceBuilder::squareFace(anOrigin->pnt(), aNormal->dir(), aFaceSize);
}
myPlane = createPreviewPlane();
}
myPreviewIsDisplayed = true;
}
+void PartSet_PreviewSketchPlane::setSizeOfView(double theSizeOfView, bool isUseSizeOfView)
+{
+ mySizeOfView = theSizeOfView;
+ myIsUseSizeOfView = isUseSizeOfView;
+}
+
AISObjectPtr PartSet_PreviewSketchPlane::createPreviewPlane()
{
if (myPlane.get()) {
void createSketchPlane(const std::shared_ptr<ModelAPI_CompositeFeature>& theSketch,
ModuleBase_IWorkshop* theWorkshop);
+ /// Returns whether custom size of view is set
+ /// \return boolean value
+ bool isUseSizeOfView() const { return myIsUseSizeOfView; }
+
+ /// Sets the size of default created face
+ /// \param theSizeOfView value
+ /// \param isUseSizeOfView state whether the size should be used
+ void setSizeOfView(double theSizeOfView, bool isUseSizeOfView);
+
private:
/// Create a square face by parameters
std::shared_ptr<GeomAPI_AISObject> createPreviewPlane();
bool myPreviewIsDisplayed;
std::shared_ptr<GeomAPI_AISObject> myPlane; //! visualized presentation
std::shared_ptr<GeomAPI_Shape> myShape; //! current shape to be displayed
+
+ double mySizeOfView; //! size that should be used by creating a default face
+ bool myIsUseSizeOfView; //! state if the size is custom or from preferences
};
#endif
\ No newline at end of file
void PartSet_WidgetSketchCreator::activateSelectionControl()
{
+ // reset previously set size of view needed on restart extrusion after Sketch
+ if (myModule->sketchMgr()->previewSketchPlane()->isUseSizeOfView())
+ myModule->sketchMgr()->previewSketchPlane()->setSizeOfView(0, false);
+
// we need to call activate here as the widget has no focus accepted controls
// if these controls are added here, activate will happens automatically after focusIn()
XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myModule->workshop());
// Set View size if a plane is selected
if (myPreviewPlanes->isPreviewDisplayed() &&
myPreviewPlanes->isPreviewShape(aValue->shape())) {
+ // set default plane size
+ bool isSetSizeOfView = false;
+ double aSizeOfView = 0;
QString aSizeOfViewStr = mySizeOfView->text();
if (!aSizeOfViewStr.isEmpty()) {
- bool isOk;
- double aSizeOfView = aSizeOfViewStr.toDouble(&isOk);
- if (isOk && aSizeOfView > 0) {
- Handle(V3d_View) aView3d = myWorkshop->viewer()->activeView();
- if (!aView3d.IsNull()) {
- Bnd_Box aBndBox;
- double aHalfSize = aSizeOfView/2.0;
- aBndBox.Update(-aHalfSize, -aHalfSize, -aHalfSize, aHalfSize, aHalfSize, aHalfSize);
- aView3d->FitAll(aBndBox, 0.01, false);
- }
+ aSizeOfView = aSizeOfViewStr.toDouble(&isSetSizeOfView);
+ if (isSetSizeOfView && aSizeOfView <= 0) {
+ isSetSizeOfView = false;
}
}
+ if (isSetSizeOfView)
+ myModule->sketchMgr()->previewSketchPlane()->setSizeOfView(aSizeOfView, true);
}
// manually deactivation because the widget was not activated as has no focus acceptin controls
deactivate();
PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
if (aModule) {
CompositeFeaturePtr aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
+ bool isSetSizeOfView = false;
+ double aSizeOfView = 0;
+ QString aSizeOfViewStr = mySizeOfView->text();
+ if (!aSizeOfViewStr.isEmpty()) {
+ aSizeOfView = aSizeOfViewStr.toDouble(&isSetSizeOfView);
+ if (isSetSizeOfView && aSizeOfView <= 0) {
+ isSetSizeOfView = false;
+ }
+ }
+ if (isSetSizeOfView)
+ aModule->sketchMgr()->previewSketchPlane()->setSizeOfView(aSizeOfView, true);
aModule->sketchMgr()->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
+ if (isSetSizeOfView)
+ aModule->sketchMgr()->previewSketchPlane()->setSizeOfView(aSizeOfView, false);
}
// 2. if the planes were displayed, change the view projection
const GeomShapePtr& aShape = thePrs->shape();
if (aRotate) {
myWorkshop->viewer()->setViewProjection(aXYZ.X(), aXYZ.Y(), aXYZ.Z(), aTwist);
}
- QString aSizeOfViewStr = mySizeOfView->text();
- if (!aSizeOfViewStr.isEmpty()) {
- bool isOk;
- double aSizeOfView = aSizeOfViewStr.toDouble(&isOk);
- if (isOk && aSizeOfView > 0) {
- Handle(V3d_View) aView3d = myWorkshop->viewer()->activeView();
- if (!aView3d.IsNull()) {
- Bnd_Box aBndBox;
- double aHalfSize = aSizeOfView/2.0;
- aBndBox.Update(-aHalfSize, -aHalfSize, -aHalfSize, aHalfSize, aHalfSize, aHalfSize);
- aView3d->FitAll(aBndBox, 0.01, false);
- }
- }
- }
PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
if (aModule)
aModule->onViewTransformed();