if (!myFacesUpToDate) {
std::shared_ptr<GeomAPI_PlanarEdges> aWirePtr =
std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(myShape);
- std::list<std::shared_ptr<GeomAPI_Shape> > aFaces;
- GeomAlgoAPI_SketchBuilder::createFaces(aWirePtr->origin(), aWirePtr->dirX(),
- aWirePtr->norm(), aWirePtr, aFaces);
- std::list<std::shared_ptr<GeomAPI_Shape> >::iterator aFIter = aFaces.begin();
- for(; aFIter != aFaces.end(); aFIter++) {
- std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(*aFIter));
- if (aFace.get())
- myFaces.push_back(aFace);
+ if (aWirePtr.get()) {
+ std::list<std::shared_ptr<GeomAPI_Shape> > aFaces;
+ GeomAlgoAPI_SketchBuilder::createFaces(aWirePtr->origin(), aWirePtr->dirX(),
+ aWirePtr->norm(), aWirePtr, aFaces);
+ std::list<std::shared_ptr<GeomAPI_Shape> >::iterator aFIter = aFaces.begin();
+ for(; aFIter != aFaces.end(); aFIter++) {
+ std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(*aFIter));
+ if (aFace.get())
+ myFaces.push_back(aFace);
+ }
}
myFacesUpToDate = true;
}
#include <ModuleBase_ISelection.h>
#include <ModuleBase_IWorkshop.h>
+#include <ModelAPI_ResultConstruction.h>
+
ModuleBase_WidgetSelector::ModuleBase_WidgetSelector(QWidget* theParent,
ModuleBase_IWorkshop* theWorkshop,
const Config_WidgetAPI* theData,
}
//********************************************************************
-bool ModuleBase_WidgetSelector::acceptSubShape(const TopoDS_Shape& theShape) const
+bool ModuleBase_WidgetSelector::acceptSubShape(const GeomShapePtr& theShape,
+ const ResultPtr& theResult) const
{
- bool aValid = true;
- if (theShape.IsNull()) {
- aValid = true; // do not check the shape type if the shape is empty
- // extrusion uses a sketch object selectected in Object browser
+ bool aValid = false;
+
+ GeomShapePtr aShape = theShape;
+ if (!aShape.get() && theResult.get()) {
+ if (theResult.get())
+ aShape = theResult->shape();
}
- else {
- aValid = false;
- TopAbs_ShapeEnum aShapeType = theShape.ShapeType();
- QIntList aShapeTypes = getShapeTypes();
-
- QIntList::const_iterator anIt = aShapeTypes.begin(), aLast = aShapeTypes.end();
- for (; anIt != aLast; anIt++) {
- if (aShapeType == *anIt)
- aValid = true;
+ TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
+ if (aShape.get()) {
+ // Check that the selection corresponds to selection type
+ TopoDS_Shape aTopoShape = aShape->impl<TopoDS_Shape>();
+ aShapeType = aTopoShape.ShapeType();
+ }
+
+ QIntList aShapeTypes = getShapeTypes();
+ QIntList::const_iterator anIt = aShapeTypes.begin(), aLast = aShapeTypes.end();
+ for (; anIt != aLast; anIt++) {
+ if (aShapeType == *anIt)
+ aValid = true;
+ else if (*anIt == TopAbs_FACE) {
+ // try to process the construction shape only if there is no a selected shape in the viewer
+ if (!theShape.get() && theResult.get()) {
+ ResultConstructionPtr aCResult =
+ std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theResult);
+ aValid = aCResult.get() && aCResult->facesNum() > 0;
+ }
}
}
return aValid;
bool ModuleBase_WidgetSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
{
GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs);
- bool aValid = true;
- if (!aShape.get()) {
- ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
- if (aResult.get())
- aShape = aResult->shape();
- }
- if (aShape.get()) {
- // Check that the selection corresponds to selection type
- TopoDS_Shape aTopoShape = aShape->impl<TopoDS_Shape>();
- aValid = acceptSubShape(aTopoShape);
- }
+ ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
+ bool aValid = acceptSubShape(aShape, aResult);
+
if (aValid) {
// In order to avoid selection of the same object
ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
/// The methiod called when widget is activated
virtual void activateCustom();
- /// Returns true if selected shape corresponds to requested shape types
+ /// Returns true if selected shape corresponds to requested shape types.
+ /// If the widget type of shapes contains the faces item, the result is converted
+ /// to construction result and the method returns true if there is at least one face
+ /// in the construction.
/// \param theShape a shape
- bool acceptSubShape(const TopoDS_Shape& theShape) const;
+ /// \param theResult a selected result
+ bool acceptSubShape(const GeomShapePtr& theShape, const ResultPtr& theResult) const;
/// Return an object and geom shape by the viewer presentation
/// \param thePrs a selection