return aEmptyPln;
}
+
+bool isEmptySelectionValid(ModuleBase_Operation* theOperation)
+{
+ 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;
+}
+
bool PartSet_DistanceSelection::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;
+ return isEmptySelectionValid(theOperation);
} else {
int aCount = shapesNbPoints(theSelection) + shapesNbLines(theSelection);
return (aCount > 0) && (aCount < 3);
bool PartSet_LengthSelection::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;
+ return isEmptySelectionValid(theOperation);
} else {
int aCount = shapesNbLines(theSelection);
return (aCount == 1);
bool PartSet_PerpendicularSelection::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;
+ return isEmptySelectionValid(theOperation);
} else {
int aCount = shapesNbLines(theSelection);
return (aCount > 0) && (aCount < 3);
bool PartSet_ParallelSelection::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;
+ return isEmptySelectionValid(theOperation);
} 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;
+ return isEmptySelectionValid(theOperation);
} else {
QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
ModuleBase_ViewerPrs aPrs;
bool PartSet_RigidSelection::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;
+ return isEmptySelectionValid(theOperation);
} else {
QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
return (aList.count() == 1);
bool PartSet_CoincidentSelection::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;
+ return isEmptySelectionValid(theOperation);
} else {
// Coincident can be applied to points and to lines
int aCount = shapesNbPoints(theSelection);
bool PartSet_HVDirSelection::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;
+ return isEmptySelectionValid(theOperation);
} else {
int aCount = shapesNbLines(theSelection);
return (aCount == 1);
bool PartSet_FilletSelection::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;
+ return isEmptySelectionValid(theOperation);
} else {
int aCount = shapesNbLines(theSelection);
return (aCount > 0) && (aCount < 3);
bool PartSet_TangentSelection::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;
+ return isEmptySelectionValid(theOperation);
} else {
QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
if ((aList.size() == 0) || (aList.size() > 2))
bool PartSet_AngleSelection::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;
+ return isEmptySelectionValid(theOperation);
} else {
int aCount = shapesNbLines(theSelection);
return (aCount > 0) && (aCount < 3);
}
}
+bool PartSet_EqualSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
+{
+ if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+ return isEmptySelectionValid(theOperation);
+ } else {
+ QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
+ ModuleBase_ViewerPrs aPrs;
+ int aCount = 0;
+ int aType = 0;
+ foreach (ModuleBase_ViewerPrs aPrs, aList) {
+ std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
+ aShape->setImpl(new TopoDS_Shape(aPrs.shape()));
+ if (aShape->isEdge()) {
+ aCount++;
+ GeomAPI_Edge aEdge(aShape);
+ if (aEdge.isLine()) {
+ if (aCount == 1)
+ aType = 1;
+ else if (aType != 1)
+ return false;
+ } else if (aEdge.isCircle()) {
+ if (aCount == 1)
+ aType = 2;
+ else if (aType != 2)
+ return false;
+ } else if (aEdge.isArc()) {
+ if (aCount == 1)
+ aType = 3;
+ else if (aType != 3)
+ return false;
+ }
+ } else
+ return false;
+ }
+ return (aCount > 0) && (aCount < 3);
+ }
+}
+
+
std::string PartSet_DifferentObjectsValidator::errorMessage(
const PartSet_DifferentObjectsValidator::ErrorType& theType,
const std::string& thEqualObject, const std::string& theFirstAttribute,
void XGUI_ActionsMgr::update()
{
- FeaturePtr anActiveFeature = FeaturePtr();
- ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
- (myOperationMgr->currentOperation());
- if (aFOperation) {
- anActiveFeature = aFOperation->feature();
- if(anActiveFeature.get()) {
- setAllEnabled(false);
- QString aFeatureId = QString::fromStdString(anActiveFeature->getKind());
- setActionEnabled(aFeatureId, true);
- }
- setNestedStackEnabled(aFOperation);
+ XGUI_Selection* aSelection = myWorkshop->selector()->selection();
+ if (aSelection->getSelected(ModuleBase_ISelection::Viewer).size() > 0) {
+ updateOnViewSelection();
} else {
- setAllEnabled(true);
- setNestedCommandsEnabled(false);
+ FeaturePtr anActiveFeature = FeaturePtr();
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (myOperationMgr->currentOperation());
+ if (aFOperation) {
+ anActiveFeature = aFOperation->feature();
+ if(anActiveFeature.get()) {
+ setAllEnabled(false);
+ QString aFeatureId = QString::fromStdString(anActiveFeature->getKind());
+ setActionEnabled(aFeatureId, true);
+ }
+ setNestedStackEnabled(aFOperation);
+ } else {
+ setAllEnabled(true);
+ setNestedCommandsEnabled(false);
+ }
+ // TODO(SBH): Get defaults state of actions from XML and remove the following method
+ updateByDocumentKind();
+ updateCheckState();
+ updateByPlugins(anActiveFeature);
}
- // TODO(SBH): Get defaults state of actions from XML and remove the following method
- updateByDocumentKind();
- updateCheckState();
- updateByPlugins(anActiveFeature);
}
void XGUI_ActionsMgr::updateCheckState()
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));
+ if (aSelValidator)
+ setActionEnabled(aId, aSelValidator->isValid(aSelection, theOperation));
}
}
}