#include <ModelAPI_Object.h>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_Tools.h>
+#include <ModelAPI_ResultBody.h>
bool GeomValidators_BodyShapes::isValid(const AttributePtr& theAttribute,
const std::list<std::string>& theArguments,
AttributeSelectionPtr anAttrSelection =
std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
ResultPtr aContext = anAttrSelection->context();
- if(!aContext.get()) {
+ FeaturePtr aContextFeature = anAttrSelection->contextFeature();
+ if (!(aContext.get() || aContextFeature.get())) {
theError = "Error: Context is empty.";
return false;
}
-
- ResultConstructionPtr aResultConstruction =
- std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
- if(aResultConstruction.get()) {
- theError = "Error: Result construction selected.";
- return false;
- }
- // additional check that the selected object is top-level result
- if (theArguments.size() > 0 && *(theArguments.rbegin()) == "toplevel") {
- if (ModelAPI_Tools::bodyOwner(aContext).get()) {
- theError = "Error: Only higher level shape allowed.";
+ if (aContext.get()) {
+ ResultConstructionPtr aResultConstruction =
+ std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+ if (aResultConstruction.get()) {
+ theError = "Error: Result construction selected.";
+ return false;
+ }
+ // additional check that the selected object is top-level result
+ if (theArguments.size() > 0 && *(theArguments.rbegin()) == "toplevel") {
+ if (ModelAPI_Tools::bodyOwner(aContext).get()) {
+ theError = "Error: Only higher level shape allowed.";
+ return false;
+ }
+ }
+ } else {
+ std::list<ResultPtr> aResList = aContextFeature->results();
+ std::list<ResultPtr>::const_iterator aIt;
+ for (aIt = aResList.cbegin(); aIt != aResList.cend(); aIt++) {
+ ResultPtr aRes = (*aIt);
+ ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aRes);
+ if (aBody.get())
+ break;
+ }
+ if (aIt == aResList.cend()) {
+ theError = "Error: Feature doesn't creates body.";
return false;
}
}
#include <GeomDataAPI_Point2D.h>
#include <ModelAPI_Result.h>
+#include <ModelAPI_Feature.h>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeSelectionList.h>
GeomShapePtr aShape = anAttr->value();
if (aShape.get())
aValid = isValidShape(aShape, theShapeType, theError);
- else
- aValid = isValidObject(anAttr->context(), theShapeType, theError);
+ else {
+ if (anAttr->context().get())
+ aValid = isValidObject(anAttr->context(), theShapeType, theError);
+ else
+ aValid = isValidObject(anAttr->contextFeature(), theShapeType, theError);
+ }
}
else if (anAttributeType == ModelAPI_AttributeRefAttr::typeId()) {
AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
theError = "The attribute with the %1 type is not processed";
theError.arg(anAttributeType);
}
+ if (aValid)
+ theError = "";
return aValid;
}
}
else {
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
- if( theShapeType==Plane )
- {
- ResultConstructionPtr aResultConstruction =
- std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theObject);
- FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
- const std::string& aKind = aFeature->getKind();
- return aResult.get() != NULL && aKind == "Plane";
- }
- if (!aResult.get()) {
- aValid = false;
- theError = "The result is empty";
- }
- else {
- aValid = isValidShape(aResult->shape(), theShapeType, theError);
+ if (aResult.get()) {
+ if (theShapeType == Plane)
+ {
+ ResultConstructionPtr aResultConstruction =
+ std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theObject);
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+ const std::string& aKind = aFeature->getKind();
+ return aResult.get() != NULL && aKind == "Plane";
+ }
+ if (!aResult.get()) {
+ aValid = false;
+ theError = "The result is empty";
+ } else {
+ aValid = isValidShape(aResult->shape(), theShapeType, theError);
+ }
+ } else {
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
+ if (aFeature.get() && (theShapeType == CompSolid))
+ return aValid;
+ else {
+ aValid = false;
+ theError = "The feature has to produce a compsolid";
+ }
}
}
return aValid;
} else if (aType == ModelAPI_AttributeSelection::typeId()) {
AttributeSelectionPtr aSelectAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
if (aSelectAttr.get() != NULL) {
- aSelectAttr->setValue(aResult, theShape, theTemporarily);
+ aSelectAttr->setValue(theObject, theShape, theTemporarily);
}
}
if (aType == ModelAPI_AttributeSelectionList::typeId()) {
AttributeSelectionListPtr aSelectionListAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
if (!theCheckIfAttributeHasObject ||
- !aSelectionListAttr->isInList(aResult, theShape, theTemporarily))
- aSelectionListAttr->append(aResult, theShape, theTemporarily);
+ !aSelectionListAttr->isInList(theObject, theShape, theTemporarily))
+ aSelectionListAttr->append(theObject, theShape, theTemporarily);
}
else if (aType == ModelAPI_AttributeRefList::typeId()) {
AttributeRefListPtr aRefListAttr =
{
ModuleBase_ISelection* aSelection = myWorkshop->selection();
theObject = aSelection->getResult(thePrs);
+ if (!theObject.get())
+ theObject = thePrs->object();
theShape = aSelection->getShape(thePrs);
}
anOwner = new StdSelect_BRepOwner(aTDShape, anIO);
myPresentedObject = aResult;
}
- else
- aValid = false; // only results with a shape can be filtered
+ else {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(thePrs->object());
+ if (aFeature.get()) {
+ // Use feature as a reference to all its results
+ myPresentedObject = aFeature;
+ } else
+ aValid = false; // only results with a shape can be filtered
+ }
}
// checks the owner by the AIS context activated filters
if (!anOwner.IsNull()) {
void XGUI_SelectionMgr::onObjectBrowserSelection()
{
QList<ModuleBase_ViewerPrsPtr> aSelectedPrs =
- myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser);
-
- QList<ModuleBase_ViewerPrsPtr> aTmpList = aSelectedPrs;
- ObjectPtr aObject;
- FeaturePtr aFeature;
- foreach(ModuleBase_ViewerPrsPtr aPrs, aTmpList) {
- aObject = aPrs->object();
- if (aObject.get()) {
- aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
- if (aFeature.get()) {
- std::list<ResultPtr> allRes;
- ModelAPI_Tools::allResults(aFeature, allRes);
- for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
- aSelectedPrs.append(std::shared_ptr<ModuleBase_ViewerPrs>(
- new ModuleBase_ViewerPrs(*aRes, GeomShapePtr(), NULL)));
+ myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser);
+ XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+ if (!myWorkshop->operationMgr()->hasOperation()) {
+
+ QList<ModuleBase_ViewerPrsPtr> aTmpList = aSelectedPrs;
+ ObjectPtr aObject;
+ FeaturePtr aFeature;
+ // Select all results of a selected feature in viewer
+ foreach(ModuleBase_ViewerPrsPtr aPrs, aSelectedPrs) {
+ aObject = aPrs->object();
+ if (aObject.get()) {
+ aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
+ if (aFeature.get()) {
+ std::list<ResultPtr> allRes;
+ ModelAPI_Tools::allResults(aFeature, allRes);
+ for (std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
+ aTmpList.append(std::shared_ptr<ModuleBase_ViewerPrs>(
+ new ModuleBase_ViewerPrs(*aRes, GeomShapePtr(), NULL)));
+ }
}
}
}
+ aDisplayer->setSelected(aTmpList);
+ } else {
+ aDisplayer->setSelected(aSelectedPrs);
}
- XGUI_Displayer* aDisplayer = myWorkshop->displayer();
- aDisplayer->setSelected(aSelectedPrs);
emit selectionChanged();
}