#include <ModuleBase_ISelection.h>
#include <ModuleBase_WidgetShapeSelector.h>
#include <ModuleBase_OperationFeature.h>
+#include <ModuleBase_ViewerPrs.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeSelection.h>
int shapesNbPoints(const ModuleBase_ISelection* theSelection)
{
- QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
+ QList<ModuleBase_ViewerPrsPtr> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
ModuleBase_ISelection::filterSelectionOnEqualPoints(aList);
int aCount = 0;
- foreach (ModuleBase_ViewerPrs aPrs, aList) {
- const TopoDS_Shape& aShape = aPrs.shape();
- if (!aShape.IsNull()) {
- if (aShape.ShapeType() == TopAbs_VERTEX)
+ foreach (ModuleBase_ViewerPrsPtr aPrs, aList) {
+ const GeomShapePtr& aShape = aPrs->shape();
+ if (aShape.get() && !aShape->isNull()) {
+ if (aShape->shapeType() == GeomAPI_Shape::VERTEX)
aCount++;
}
}
int shapesNbLines(const ModuleBase_ISelection* theSelection)
{
- QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
+ QList<ModuleBase_ViewerPrsPtr> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
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);
+ foreach(ModuleBase_ViewerPrsPtr aPrs, aList) {
+ const GeomShapePtr& aShape = aPrs->shape();
+ if (aShape.get() && !aShape->isNull()) {
+ if (aShape->shapeType() == GeomAPI_Shape::EDGE) {
+ const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
+ TopoDS_Edge aEdge = TopoDS::Edge(aTDShape);
Standard_Real aStart, aEnd;
Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
GeomAdaptor_Curve aAdaptor(aCurve);
if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
return isEmptySelectionValid(theOperation);
} else {
- QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
- ModuleBase_ViewerPrs aPrs;
+ QList<ModuleBase_ViewerPrsPtr> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
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);
+ foreach (ModuleBase_ViewerPrsPtr aPrs, aList) {
+ const GeomShapePtr& aShape = aPrs->shape();
+ if (aShape.get() && !aShape->isNull()) {
+ if (aShape->shapeType() == GeomAPI_Shape::EDGE) {
+ const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
+ TopoDS_Edge aEdge = TopoDS::Edge(aTDShape);
Standard_Real aStart, aEnd;
Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
GeomAdaptor_Curve aAdaptor(aCurve);
if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
return isEmptySelectionValid(theOperation);
} else {
- QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
+ QList<ModuleBase_ViewerPrsPtr> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
return (aList.count() == 1);
}
}
if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
return isEmptySelectionValid(theOperation);
} else {
- int aCount = shapesNbLines(theSelection);
- return (aCount > 0) && (aCount < 3);
+ int aCount = shapesNbPoints(theSelection);
+ return aCount == 1;
}
}
if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
return isEmptySelectionValid(theOperation);
} else {
- QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
+ QList<ModuleBase_ViewerPrsPtr> 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)
+ ModuleBase_ViewerPrsPtr aPrs = aList.first();
+ const GeomShapePtr& aShape = aPrs->shape();
+ if (!aShape.get() || aShape->isNull() || aShape->shapeType() != GeomAPI_Shape::EDGE)
return false;
-
- std::shared_ptr<GeomAPI_Shape> aShapePtr(new GeomAPI_Shape);
- aShapePtr->setImpl(new TopoDS_Shape(aShape));
- GeomAPI_Edge aEdge1(aShapePtr);
+ GeomAPI_Edge aEdge1(aShape);
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)
+ const GeomShapePtr& aShape2 = aPrs->shape();
+ if (!aShape2.get() || aShape2->isNull() || aShape2->shapeType() != GeomAPI_Shape::EDGE)
return false;
+ GeomAPI_Edge aEdge2(aShape2);
- 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())
if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
return isEmptySelectionValid(theOperation);
} else {
- QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
- ModuleBase_ViewerPrs aPrs;
+ QList<ModuleBase_ViewerPrsPtr> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
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()) {
+ foreach (ModuleBase_ViewerPrsPtr aPrs, aList) {
+ GeomShapePtr aShape = aPrs->shape();
+ if (aShape.get() && aShape->isEdge()) {
aCount++;
GeomAPI_Edge aEdge(aShape);
if (aEdge.isLine()) {
}
}
+bool PartSet_CollinearSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
+{
+ if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) {
+ return isEmptySelectionValid(theOperation);
+ } else {
+ int aCount = shapesNbLines(theSelection);
+ return (aCount > 0) && (aCount < 3);
+ }
+}
+
+bool PartSet_MiddlePointSelection::isValid(const ModuleBase_ISelection* theSelection, ModuleBase_Operation* theOperation) const
+{
+ if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0)
+ return isEmptySelectionValid(theOperation);
+ else
+ return shapesNbLines(theSelection) == 1 && shapesNbPoints(theSelection) == 1;
+}
+
std::string PartSet_DifferentObjectsValidator::errorMessage(
const PartSet_DifferentObjectsValidator::ErrorType& theType,
return true;
}
-bool PartSet_SketchEntityValidator::isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments,
- std::string& theError) const
-{
- bool isSketchEntities = true;
- std::set<std::string> anEntityKinds;
- std::string anEntityKindsStr;
- std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
- for (; anIt != aLast; anIt++) {
- anEntityKinds.insert(*anIt);
- if (!anEntityKindsStr.empty())
- anEntityKindsStr += ", ";
- anEntityKindsStr += *anIt;
- }
-
- std::string anAttributeType = theAttribute->attributeType();
- if (anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
- AttributeSelectionListPtr aSelectionListAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
- // all context objects should be sketch entities
- for (int i = 0, aSize = aSelectionListAttr->size(); i < aSize && isSketchEntities; i++) {
- AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
- ObjectPtr anObject = aSelectAttr->context();
- // a context of the selection attribute is a feature result. It can be a case when the result
- // of the feature is null, e.g. the feature is modified and has not been executed yet.
- // The validator returns an invalid result here. The case is an extrusion built on a sketch
- // feature. A new sketch element creation leads to an empty result.
- if (!anObject.get())
- isSketchEntities = false;
- else {
- FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
- isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end();
- }
- }
- }
- if (anAttributeType == ModelAPI_AttributeRefList::typeId()) {
- AttributeRefListPtr aRefListAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
- // all context objects should be sketch entities
- for (int i = 0, aSize = aRefListAttr->size(); i < aSize && isSketchEntities; i++) {
- ObjectPtr anObject = aRefListAttr->object(i);
- // a context of the selection attribute is a feature result. It can be a case when the result
- // of the feature is null, e.g. the feature is modified and has not been executed yet.
- // The validator returns an invalid result here. The case is an extrusion built on a sketch
- // feature. A new sketch element creation leads to an empty result.
- if (!anObject.get())
- isSketchEntities = false;
- else {
- FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
- isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end();
- }
- }
- }
- if (anAttributeType == ModelAPI_AttributeRefAttr::typeId()) {
- std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
- std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
- isSketchEntities = false;
- if (aRef->isObject()) {
- ObjectPtr anObject = aRef->object();
- if (anObject.get() != NULL) {
- FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
- if (aFeature.get() != NULL)
- isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end();
- }
- }
- }
- if (!isSketchEntities) {
- theError = "It refers to feature, which kind is not in the list: " + anEntityKindsStr;
- }
-
- return isSketchEntities;
-}
-
bool PartSet_CoincidentAttr::isValid(const AttributePtr& theAttribute,
const std::list<std::string>& theArguments,
std::string& theError) const
FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
QList<FeaturePtr> aCoinsideLines;
+ QList<FeaturePtr> aCoins;
bool isObject = aRefAttr->isObject();
ObjectPtr anObject = aRefAttr->object();
AttributePtr aAR = aRAttr->attr();
if (aAR->id() != SketchPlugin_Arc::CENTER_ID()) // ignore constraint to center of arc
aCoinList.insert(aConstrFeature);
- PartSet_Tools::findCoincidences(aConstrFeature, aCoinsideLines,
+ PartSet_Tools::findCoincidences(aConstrFeature, aCoinsideLines, aCoins,
SketchPlugin_ConstraintCoincidence::ENTITY_A());
- PartSet_Tools::findCoincidences(aConstrFeature, aCoinsideLines,
+ PartSet_Tools::findCoincidences(aConstrFeature, aCoinsideLines, aCoins,
SketchPlugin_ConstraintCoincidence::ENTITY_B());
}
}