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");
double angle(const std::shared_ptr<GeomAPI_Dir2d>& theArg) const;
};
+//! Pointer on the object
+typedef std::shared_ptr<GeomAPI_Dir2d> GeomDir2dPtr;
+
#endif
std::shared_ptr<GeomAPI_Pnt2d> shiftedLocation(double theShift) const;
};
+
+//! Pointer on the object
+typedef std::shared_ptr<GeomAPI_Lin2d> GeomLine2dPtr;
+
#endif
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") {
/// Process sketch plane selected event
void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& 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:
#include "GeomDataAPI_Point2D.h"
+#include "GeomAPI_Lin2d.h"
+#include "GeomAPI_Dir2d.h"
+
#include <ModuleBase_IPropertyPanel.h>
#include <ModuleBase_ISelectionActivate.h>
#include <ModuleBase_OperationFeature.h>
#include <SketchPlugin_Point.h>
#include <SketchPlugin_Trim.h>
#include <SketchPlugin_Split.h>
+#include <SketchPlugin_ConstraintHorizontal.h>
+#include <SketchPlugin_ConstraintVertical.h>
#include <XGUI_Workshop.h>
#include <XGUI_ModuleConnector.h>
myRestartingMode(RM_None),
myIsFlagsBlocked(false),
myIsInternalEditOperation(false),
- myNoMoreWidgetsAttribute("")
+ myNoMoreWidgetsAttribute(""),
+ myIsAutoConstraints(true)
{
}
workshop()->selector()->clearSelection();
myPreviousFeature = aFOperation->feature();
+ if (myIsAutoConstraints)
+ addConstraints(myPreviousFeature);
restartOperation();
myPreviousFeature = FeaturePtr();
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<ModelAPI_Data> aData = theFeature->data();
+ std::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::START_ID()));
+ std::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(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());
+ }
+ }
+}
/// \param theMessage a message of reentrant operation
void setReentrantPreSelection(const std::shared_ptr<Events_Message>& 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
void setInternalActiveWidget(ModuleBase_ModelWidget* theWidget);
+ void addConstraints(const FeaturePtr& theFeature);
+
private:
ModuleBase_IWorkshop* myWorkshop; /// the workshop
ObjectPtr mySelectedObject; /// cashed selected object
std::shared_ptr<ModelAPI_Attribute> mySelectedAttribute; /// cashed selected attribute
std::shared_ptr<GeomAPI_Pnt2d> myClickedSketchPoint; /// cashed clicked point
+
+ bool myIsAutoConstraints;
};
#endif
#include "PartSet_Tools.h"
#include "PartSet_Module.h"
#include "PartSet_PreviewPlanes.h"
+#include "PartSet_SketcherReentrantMgr.h"
#include "SketchPlugin_SketchEntity.h"
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);
void PartSet_WidgetSketchLabel::activateCustom()
{
+ PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
+ if (aModule) {
+ bool isBlocked = myAutoConstraints->blockSignals(true);
+ myAutoConstraints->setChecked(aModule->sketchReentranceMgr()->isAutoConstraints());
+ myAutoConstraints->blockSignals(isBlocked);
+ }
+
std::shared_ptr<GeomAPI_Pln> aPlane = plane();
if (aPlane.get()) {
myStackWidget->setCurrentIndex(1);
/// \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
QCheckBox* myViewInverted;
QCheckBox* myRemoveExternal;
QCheckBox* myShowPoints;
+ QCheckBox* myAutoConstraints;
QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*> myShowConstraints;