#include <GeomValidators_Tools.h>
#include <ModuleBase_ISelection.h>
#include <ModuleBase_WidgetShapeSelector.h>
+#include <ModuleBase_OperationFeature.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeSelection.h>
return aCount;
}
-bool PartSet_DistanceSelection::isValid(const ModuleBase_ISelection* theSelection) const
+
+std::shared_ptr<GeomAPI_Pln> sketcherPlane(ModuleBase_Operation* theOperation)
{
- int aCount = shapesNbPoints(theSelection) + shapesNbLines(theSelection);
- return (aCount > 0) && (aCount < 3);
+ std::shared_ptr<GeomAPI_Pln> aEmptyPln;
+ if (theOperation) {
+ ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+ if (aFeatureOp) {
+ CompositeFeaturePtr aFeature =
+ std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeatureOp->feature());
+ if (aFeature && (aFeature->getKind() == SketchPlugin_Sketch::ID()))
+ return PartSet_Tools::sketchPlane(aFeature);
+ }
+ }
+ return aEmptyPln;
}
-bool PartSet_LengthSelection::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_DistanceSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
{
- int aCount = shapesNbLines(theSelection);
- return (aCount == 1);
+ if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+ ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+ if (!aFeatureOp->isEditOperation()) {
+ return true;
+ }
+ std::shared_ptr<GeomAPI_Pln> aPlane = sketcherPlane(theOperation);
+ if (aPlane.get())
+ return true;
+ else
+ return false;
+ } else {
+ int aCount = shapesNbPoints(theSelection) + shapesNbLines(theSelection);
+ return (aCount > 0) && (aCount < 3);
+ }
}
-bool PartSet_PerpendicularSelection::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_LengthSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
{
- int aCount = shapesNbLines(theSelection);
- return (aCount > 0) && (aCount < 3);
+ if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+ ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+ if (!aFeatureOp->isEditOperation()) {
+ return true;
+ }
+ std::shared_ptr<GeomAPI_Pln> aPlane = sketcherPlane(theOperation);
+ if (aPlane.get())
+ return true;
+ else
+ return false;
+ } else {
+ int aCount = shapesNbLines(theSelection);
+ return (aCount == 1);
+ }
}
-bool PartSet_ParallelSelection::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_PerpendicularSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
{
- int aCount = shapesNbLines(theSelection);
- return (aCount > 0) && (aCount < 3);
+ if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+ ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+ if (!aFeatureOp->isEditOperation()) {
+ return true;
+ }
+ std::shared_ptr<GeomAPI_Pln> aPlane = sketcherPlane(theOperation);
+ if (aPlane.get())
+ return true;
+ else
+ return false;
+ } else {
+ int aCount = shapesNbLines(theSelection);
+ return (aCount > 0) && (aCount < 3);
+ }
}
-bool PartSet_RadiusSelection::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_ParallelSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
{
- QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
- ModuleBase_ViewerPrs aPrs;
- int aCount = 0;
- foreach (ModuleBase_ViewerPrs aPrs, aList) {
- const TopoDS_Shape& aShape = aPrs.shape();
- if (!aShape.IsNull()) {
- if (aShape.ShapeType() == TopAbs_EDGE) {
- TopoDS_Edge aEdge = TopoDS::Edge(aShape);
- Standard_Real aStart, aEnd;
- Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
- GeomAdaptor_Curve aAdaptor(aCurve);
- if (aAdaptor.GetType() == GeomAbs_Circle)
- aCount++;
+ if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+ ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+ if (!aFeatureOp->isEditOperation()) {
+ return true;
+ }
+ std::shared_ptr<GeomAPI_Pln> aPlane = sketcherPlane(theOperation);
+ if (aPlane.get())
+ return true;
+ else
+ return false;
+ } else {
+ int aCount = shapesNbLines(theSelection);
+ return (aCount > 0) && (aCount < 3);
+ }
+}
+
+bool PartSet_RadiusSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
+{
+ if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+ ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+ if (!aFeatureOp->isEditOperation()) {
+ return true;
+ }
+ std::shared_ptr<GeomAPI_Pln> aPlane = sketcherPlane(theOperation);
+ if (aPlane.get())
+ return true;
+ else
+ return false;
+ } else {
+ QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
+ ModuleBase_ViewerPrs aPrs;
+ int aCount = 0;
+ foreach (ModuleBase_ViewerPrs aPrs, aList) {
+ const TopoDS_Shape& aShape = aPrs.shape();
+ if (!aShape.IsNull()) {
+ if (aShape.ShapeType() == TopAbs_EDGE) {
+ TopoDS_Edge aEdge = TopoDS::Edge(aShape);
+ Standard_Real aStart, aEnd;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
+ GeomAdaptor_Curve aAdaptor(aCurve);
+ if (aAdaptor.GetType() == GeomAbs_Circle)
+ aCount++;
+ }
}
}
+ return (aCount == 1);
}
- return (aCount == 1);
}
-bool PartSet_RigidSelection::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_RigidSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
{
- QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
- return (aList.count() == 1);
+ if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+ ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+ if (!aFeatureOp->isEditOperation()) {
+ return true;
+ }
+ std::shared_ptr<GeomAPI_Pln> aPlane = sketcherPlane(theOperation);
+ if (aPlane.get())
+ return true;
+ else
+ return false;
+ } else {
+ QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
+ return (aList.count() == 1);
+ }
}
-bool PartSet_CoincidentSelection::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_CoincidentSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
{
- // Coincident can be applied to points and to lines
- int aCount = shapesNbPoints(theSelection);
- aCount += shapesNbLines(theSelection);
- return (aCount > 0) && (aCount < 3);
+ if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+ ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+ if (!aFeatureOp->isEditOperation()) {
+ return true;
+ }
+ std::shared_ptr<GeomAPI_Pln> aPlane = sketcherPlane(theOperation);
+ if (aPlane.get())
+ return true;
+ else
+ return false;
+ } else {
+ // Coincident can be applied to points and to lines
+ int aCount = shapesNbPoints(theSelection);
+ aCount += shapesNbLines(theSelection);
+ return (aCount > 0) && (aCount < 3);
+ }
}
-bool PartSet_HVDirSelection::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_HVDirSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
{
- int aCount = shapesNbLines(theSelection);
- return (aCount == 1);
+ if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+ ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+ if (!aFeatureOp->isEditOperation()) {
+ return true;
+ }
+ std::shared_ptr<GeomAPI_Pln> aPlane = sketcherPlane(theOperation);
+ if (aPlane.get())
+ return true;
+ else
+ return false;
+ } else {
+ int aCount = shapesNbLines(theSelection);
+ return (aCount == 1);
+ }
}
-bool PartSet_FilletSelection::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_FilletSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
{
- int aCount = shapesNbLines(theSelection);
- return (aCount > 0) && (aCount < 3);
+ if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+ ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+ if (!aFeatureOp->isEditOperation()) {
+ return true;
+ }
+ std::shared_ptr<GeomAPI_Pln> aPlane = sketcherPlane(theOperation);
+ if (aPlane.get())
+ return true;
+ else
+ return false;
+ } else {
+ int aCount = shapesNbLines(theSelection);
+ return (aCount > 0) && (aCount < 3);
+ }
}
-bool PartSet_TangentSelection::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_TangentSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
{
- QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
- if ((aList.size() == 0) || (aList.size() > 2))
- return false;
-
- ModuleBase_ViewerPrs aPrs = aList.first();
- const TopoDS_Shape& aShape = aPrs.shape();
- if (aShape.IsNull())
- return false;
-
- if (aShape.ShapeType() != TopAbs_EDGE)
- return false;
-
- std::shared_ptr<GeomAPI_Shape> aShapePtr(new GeomAPI_Shape);
- aShapePtr->setImpl(new TopoDS_Shape(aShape));
- GeomAPI_Edge aEdge1(aShapePtr);
-
- if (aEdge1.isLine() || aEdge1.isArc()) {
- if (aList.size() == 2) {
- // Check second selection
- aPrs = aList.last();
- const TopoDS_Shape& aShape2 = aPrs.shape();
- if (aShape2.IsNull())
- return false;
-
- if (aShape2.ShapeType() != TopAbs_EDGE)
- return false;
-
- std::shared_ptr<GeomAPI_Shape> aShapePtr2(new GeomAPI_Shape);
- aShapePtr2->setImpl(new TopoDS_Shape(aShape2));
- GeomAPI_Edge aEdge2(aShapePtr2);
- if (aEdge1.isLine() && aEdge2.isArc())
- return true;
- else if (aEdge1.isArc() && aEdge2.isLine())
- return true;
- else
- return false;
- } else
+ if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+ ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+ if (!aFeatureOp->isEditOperation()) {
+ return true;
+ }
+ std::shared_ptr<GeomAPI_Pln> aPlane = sketcherPlane(theOperation);
+ if (aPlane.get())
return true;
+ else
+ return false;
+ } else {
+ QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
+ if ((aList.size() == 0) || (aList.size() > 2))
+ return false;
+
+ ModuleBase_ViewerPrs aPrs = aList.first();
+ const TopoDS_Shape& aShape = aPrs.shape();
+ if (aShape.IsNull())
+ return false;
+
+ if (aShape.ShapeType() != TopAbs_EDGE)
+ return false;
+
+ std::shared_ptr<GeomAPI_Shape> aShapePtr(new GeomAPI_Shape);
+ aShapePtr->setImpl(new TopoDS_Shape(aShape));
+ GeomAPI_Edge aEdge1(aShapePtr);
+
+ if (aEdge1.isLine() || aEdge1.isArc()) {
+ if (aList.size() == 2) {
+ // Check second selection
+ aPrs = aList.last();
+ const TopoDS_Shape& aShape2 = aPrs.shape();
+ if (aShape2.IsNull())
+ return false;
+
+ if (aShape2.ShapeType() != TopAbs_EDGE)
+ return false;
+
+ std::shared_ptr<GeomAPI_Shape> aShapePtr2(new GeomAPI_Shape);
+ aShapePtr2->setImpl(new TopoDS_Shape(aShape2));
+ GeomAPI_Edge aEdge2(aShapePtr2);
+ if (aEdge1.isLine() && aEdge2.isArc())
+ return true;
+ else if (aEdge1.isArc() && aEdge2.isLine())
+ return true;
+ else
+ return false;
+ } else
+ return true;
+ }
+ return false;
}
- return false;
}
-bool PartSet_AngleSelection::isValid(const ModuleBase_ISelection* theSelection) const
+bool PartSet_AngleSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
{
- int aCount = shapesNbLines(theSelection);
- return (aCount > 0) && (aCount < 3);
+ if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+ ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+ if (!aFeatureOp->isEditOperation()) {
+ return true;
+ }
+ std::shared_ptr<GeomAPI_Pln> aPlane = sketcherPlane(theOperation);
+ if (aPlane.get())
+ return true;
+ else
+ return false;
+ } else {
+ int aCount = shapesNbLines(theSelection);
+ return (aCount > 0) && (aCount < 3);
+ }
}
std::string PartSet_DifferentObjectsValidator::errorMessage(
//! A class to validate a selection for Distance constraint operation
class PartSet_DistanceSelection : public ModuleBase_SelectionValidator
{
- protected:
- PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+public:
+ PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const;
};
//! \ingroup Validators
//! A class to validate a selection for Length constraint operation
class PartSet_LengthSelection : public ModuleBase_SelectionValidator
{
- protected:
- PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+public:
+ PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const;
};
//! \ingroup Validators
//! A class to validate a selection for Perpendicular constraint operation
class PartSet_PerpendicularSelection : public ModuleBase_SelectionValidator
{
- protected:
- PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+public:
+ PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const;
};
//! \ingroup Validators
//! A class to validate a selection for Parallel constraint operation
class PartSet_ParallelSelection : public ModuleBase_SelectionValidator
{
- protected:
- PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+public:
+ PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const;
};
//! \ingroup Validators
//! A class to validate a selection for Radius constraint operation
class PartSet_RadiusSelection : public ModuleBase_SelectionValidator
{
- protected:
- PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+public:
+ PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const;
};
//! \ingroup Validators
//! A class to validate a selection for Rigid constraint operation
class PartSet_RigidSelection : public ModuleBase_SelectionValidator
{
- protected:
- PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+public:
+ PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const;
};
//! A class to validate a selection for coincedence constraint operation
class PartSet_CoincidentSelection : public ModuleBase_SelectionValidator
{
- protected:
- PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+public:
+ PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const;
};
//! \ingroup Validators
//! A class to validate a selection for Horizontal and Vertical constraints operation
class PartSet_HVDirSelection : public ModuleBase_SelectionValidator
{
- protected:
- PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+public:
+ PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const;
};
//! \ingroup Validators
//! A class to validate a selection for Tangential constraints operation
class PartSet_TangentSelection : public ModuleBase_SelectionValidator
{
- protected:
- PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+public:
+ PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const;
};
//! \ingroup Validators
//! A class to validate a selection for Fillet constraints operation
class PartSet_FilletSelection : public ModuleBase_SelectionValidator
{
- protected:
- PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+public:
+ PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const;
};
//! \ingroup Validators
//! A class to validate a selection for Angle constraints operation
class PartSet_AngleSelection : public ModuleBase_SelectionValidator
{
- protected:
- PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+public:
+ PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const;
};
////////////// Attribute validators ////////////////
if (aIdList.isEmpty())
return;
+ ModuleBase_Operation* theOperation = myOperationMgr->currentOperation();
//QString aFeatureId = QString::fromStdString(anActiveFeature->getKind());
XGUI_Selection* aSelection = myWorkshop->selector()->selection();
// only viewer selection is processed
- if (aSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
- // it seems that this code is not nesessary anymore. It leads to incorrect case:
- // sketch operation start, click in any place in the viewer. The result is all nested
- // entities are enabled(but the sketch plane is not selected yet). Any sketch operation
- // can be started but will be incorrect on preview build before it uses the sketch unset plane.
- /*foreach(QString aFeatureId, aIdList) {
- foreach(QString aId, nestedCommands(aFeatureId)) {
- setActionEnabled(aId, true);
- }
- }*/
- } else {
- SessionPtr aMgr = ModelAPI_Session::get();
- ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
- foreach(QString aFeatureId, aIdList) {
- foreach(QString aId, nestedCommands(aFeatureId)) {
- ModelAPI_ValidatorsFactory::Validators aValidators;
- aFactory->validators(aId.toStdString(), aValidators);
- ModelAPI_ValidatorsFactory::Validators::iterator aValidatorIt = aValidators.begin();
- for (; aValidatorIt != aValidators.end(); ++aValidatorIt) {
- const ModuleBase_SelectionValidator* aSelValidator =
- dynamic_cast<const ModuleBase_SelectionValidator*>(aFactory->validator(aValidatorIt->first));
- if (!aSelValidator)
- continue;
- setActionEnabled(aId, aSelValidator->isValid(aSelection, aValidatorIt->second));
- }
+ SessionPtr aMgr = ModelAPI_Session::get();
+ ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+ foreach(QString aFeatureId, aIdList) {
+ foreach(QString aId, nestedCommands(aFeatureId)) {
+ ModelAPI_ValidatorsFactory::Validators aValidators;
+ aFactory->validators(aId.toStdString(), aValidators);
+ ModelAPI_ValidatorsFactory::Validators::iterator aValidatorIt = aValidators.begin();
+ for (; aValidatorIt != aValidators.end(); ++aValidatorIt) {
+ const ModuleBase_SelectionValidator* aSelValidator =
+ dynamic_cast<const ModuleBase_SelectionValidator*>(aFactory->validator(aValidatorIt->first));
+ if (!aSelValidator)
+ continue;
+ setActionEnabled(aId, aSelValidator->isValid(aSelection, theOperation));
}
}
}