From: vsv Date: Mon, 12 Aug 2019 14:03:06 +0000 (+0300) Subject: Task 2.6: Creation of horizontal and vertical constraints “on a fly” X-Git-Tag: V9_4_0a2~4^2~147 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fa11a339e5c069c847d5f8762e25861025947a56;p=modules%2Fshaper.git Task 2.6: Creation of horizontal and vertical constraints “on a fly” --- diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp index 0b0dc4bb2..637e37b4e 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp @@ -58,6 +58,8 @@ ConstructionPlugin_Plugin::ConstructionPlugin_Plugin() PLANE_SIZE, "0", "1000"); Config_PropManager::registerProp(SKETCH_TAB_NAME, "planes_thickness", "Thickness", Config_Prop::IntSpin, SKETCH_WIDTH); + Config_PropManager::registerProp(SKETCH_TAB_NAME, "angular_tolerance", "Angular tolerance", + Config_Prop::DblSpin, "0.04"); Config_PropManager::registerProp(SKETCH_TAB_NAME, "rotate_to_plane", "Rotate to plane when selected", Config_Prop::Boolean, "false"); diff --git a/src/GeomAPI/GeomAPI_Dir2d.h b/src/GeomAPI/GeomAPI_Dir2d.h index c525e8c3f..1b7a0d35d 100644 --- a/src/GeomAPI/GeomAPI_Dir2d.h +++ b/src/GeomAPI/GeomAPI_Dir2d.h @@ -66,5 +66,8 @@ class GeomAPI_Dir2d : public GeomAPI_Interface double angle(const std::shared_ptr& theArg) const; }; +//! Pointer on the object +typedef std::shared_ptr GeomDir2dPtr; + #endif diff --git a/src/GeomAPI/GeomAPI_Lin2d.h b/src/GeomAPI/GeomAPI_Lin2d.h index 3fdda3048..725c28f1f 100644 --- a/src/GeomAPI/GeomAPI_Lin2d.h +++ b/src/GeomAPI/GeomAPI_Lin2d.h @@ -76,5 +76,9 @@ class GeomAPI_Lin2d : public GeomAPI_Interface std::shared_ptr shiftedLocation(double theShift) const; }; + +//! Pointer on the object +typedef std::shared_ptr GeomLine2dPtr; + #endif diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index e9dbb6a38..8d1b0a024 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -895,6 +895,7 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)), mySketchMgr, SLOT(onShowConstraintsToggle(int, bool))); connect(aLabelWgt, SIGNAL(showFreePoints(bool)), mySketchMgr, SLOT(onShowPoints(bool))); + connect(aLabelWgt, SIGNAL(autoConstraints(bool)), sketchReentranceMgr(), SLOT(onAutoConstraints(bool))); aLabelWgt->setShowPointsState(mySketchMgr->isShowFreePointsShown()); aWgt = aLabelWgt; } else if (theType == "sketch-2dpoint_selector") { diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index 07c3160e6..3f29ba661 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -344,6 +344,8 @@ public slots: /// Process sketch plane selected event void onPlaneSelected(const std::shared_ptr& thePln); + /// The slot is called when user checks "Show free points" button + /// \param toShow a state of the check box void onShowPoints(bool toShow); private slots: diff --git a/src/PartSet/PartSet_SketcherReentrantMgr.cpp b/src/PartSet/PartSet_SketcherReentrantMgr.cpp index 1e117834c..cd95a10e4 100644 --- a/src/PartSet/PartSet_SketcherReentrantMgr.cpp +++ b/src/PartSet/PartSet_SketcherReentrantMgr.cpp @@ -31,6 +31,9 @@ #include "GeomDataAPI_Point2D.h" +#include "GeomAPI_Lin2d.h" +#include "GeomAPI_Dir2d.h" + #include #include #include @@ -51,6 +54,8 @@ #include #include #include +#include +#include #include #include @@ -69,7 +74,8 @@ PartSet_SketcherReentrantMgr::PartSet_SketcherReentrantMgr(ModuleBase_IWorkshop* myRestartingMode(RM_None), myIsFlagsBlocked(false), myIsInternalEditOperation(false), - myNoMoreWidgetsAttribute("") + myNoMoreWidgetsAttribute(""), + myIsAutoConstraints(true) { } @@ -171,6 +177,8 @@ bool PartSet_SketcherReentrantMgr::processMouseMoved(ModuleBase_IViewWindow* the workshop()->selector()->clearSelection(); myPreviousFeature = aFOperation->feature(); + if (myIsAutoConstraints) + addConstraints(myPreviousFeature); restartOperation(); myPreviousFeature = FeaturePtr(); @@ -821,3 +829,45 @@ void PartSet_SketcherReentrantMgr::setInternalActiveWidget(ModuleBase_ModelWidge aPropertyPanel->setInternalActiveWidget(theWidget); } } + +void PartSet_SketcherReentrantMgr::onAutoConstraints(bool isOn) +{ + myIsAutoConstraints = isOn; +} + +void PartSet_SketcherReentrantMgr::addConstraints(const FeaturePtr& theFeature) +{ + static GeomDir2dPtr myHorDir(new GeomAPI_Dir2d(1, 0)); + static GeomDir2dPtr myVertDir(new GeomAPI_Dir2d(0, 1)); + + if (theFeature->getKind() == SketchPlugin_Line::ID()) { + std::shared_ptr aData = theFeature->data(); + std::shared_ptr aPoint1 = + std::dynamic_pointer_cast(aData->attribute(SketchPlugin_Line::START_ID())); + std::shared_ptr aPoint2 = + std::dynamic_pointer_cast(aData->attribute(SketchPlugin_Line::END_ID())); + if (aPoint1.get() && aPoint2.get()) { + GeomLine2dPtr aLine(new GeomAPI_Lin2d(aPoint1->pnt(), aPoint2->pnt())); + GeomDir2dPtr aDir = aLine->direction(); + double aHorAngle = fabs(myHorDir->angle(aDir)); + double aVertAngle = fabs(myVertDir->angle(aDir)); + if (aHorAngle > M_PI/2.) + aHorAngle = M_PI - aHorAngle; + if (aVertAngle > M_PI/2.) + aVertAngle = M_PI - aVertAngle; + + double aTolerance = Config_PropManager::real(SKETCH_TAB_NAME, "angular_tolerance"); + CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch(); + FeaturePtr aFeature; + if (aHorAngle < aTolerance) + // Add horizontal constraint + aFeature = aSketch->addFeature(SketchPlugin_ConstraintHorizontal::ID()); + else if (aVertAngle < aTolerance) + // Add vertical constraint + aFeature = aSketch->addFeature(SketchPlugin_ConstraintVertical::ID()); + + if (aFeature.get()) + aFeature->refattr(SketchPlugin_Constraint::ENTITY_A())->setObject(theFeature->firstResult()); + } + } +} diff --git a/src/PartSet/PartSet_SketcherReentrantMgr.h b/src/PartSet/PartSet_SketcherReentrantMgr.h index fc2f6723c..91ab34ebc 100644 --- a/src/PartSet/PartSet_SketcherReentrantMgr.h +++ b/src/PartSet/PartSet_SketcherReentrantMgr.h @@ -131,6 +131,15 @@ public: /// \param theMessage a message of reentrant operation void setReentrantPreSelection(const std::shared_ptr& theMessage); + bool isAutoConstraints() const { return myIsAutoConstraints; } + + +public slots: + /// The slot is called when user checks "Automatic constraints" button + /// \param isOn a state of the check box + void onAutoConstraints(bool isOn); + + private slots: /// SLOT, that is called by a widget activating in the property panel /// If the 'internal' edit operation is started, it activates the first widget selection @@ -211,6 +220,8 @@ private: void setInternalActiveWidget(ModuleBase_ModelWidget* theWidget); + void addConstraints(const FeaturePtr& theFeature); + private: ModuleBase_IWorkshop* myWorkshop; /// the workshop @@ -227,6 +238,8 @@ private: ObjectPtr mySelectedObject; /// cashed selected object std::shared_ptr mySelectedAttribute; /// cashed selected attribute std::shared_ptr myClickedSketchPoint; /// cashed clicked point + + bool myIsAutoConstraints; }; #endif diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index 231c512fa..3f4c8d829 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -21,6 +21,7 @@ #include "PartSet_Tools.h" #include "PartSet_Module.h" #include "PartSet_PreviewPlanes.h" +#include "PartSet_SketcherReentrantMgr.h" #include "SketchPlugin_SketchEntity.h" @@ -171,6 +172,10 @@ myIsSelection(false) connect(myShowPoints, SIGNAL(toggled(bool)), this, SIGNAL(showFreePoints(bool))); aLayout->addWidget(myShowPoints); + myAutoConstraints = new QCheckBox(tr("Automatic constraints"), this); + connect(myAutoConstraints, SIGNAL(toggled(bool)), this, SIGNAL(autoConstraints(bool))); + aLayout->addWidget(myAutoConstraints); + QPushButton* aPlaneBtn = new QPushButton(tr("Change sketch plane"), aSecondWgt); connect(aPlaneBtn, SIGNAL(clicked(bool)), SLOT(onChangePlane())); aLayout->addWidget(aPlaneBtn); @@ -508,6 +513,13 @@ bool PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(const ModuleBase_View void PartSet_WidgetSketchLabel::activateCustom() { + PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); + if (aModule) { + bool isBlocked = myAutoConstraints->blockSignals(true); + myAutoConstraints->setChecked(aModule->sketchReentranceMgr()->isAutoConstraints()); + myAutoConstraints->blockSignals(isBlocked); + } + std::shared_ptr aPlane = plane(); if (aPlane.get()) { myStackWidget->setCurrentIndex(1); diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index 74a16f224..b4158194b 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -118,8 +118,14 @@ signals: /// \param theState a state of the check box void showConstraintToggled(int theType, bool theState); + /// The signal is emitted when user checks "Show free points" button + /// \param toShow a state of the check box void showFreePoints(bool toShow); + /// The signal is emitted when user checks "Automatic constraints" button + /// \param isOn a state of the check box + void autoConstraints(bool isOn); + protected: /// Creates a backup of the current values of the attribute /// It should be realized in the specific widget because of different @@ -223,6 +229,7 @@ private: QCheckBox* myViewInverted; QCheckBox* myRemoveExternal; QCheckBox* myShowPoints; + QCheckBox* myAutoConstraints; QMap myShowConstraints;