#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Tools.h>
+#include <ModelAPI_ResultBody.h>
#include <Config_WidgetAPI.h>
#include <Events_Error.h>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <list>
-#include <stdexcept>
-#include <xstring>
+#include <string>
typedef QMap<QString, TopAbs_ShapeEnum> ShapeTypes;
static ShapeTypes MyShapeTypes;
boost::shared_ptr<ModelAPI_AttributeSelection> aSelect =
boost::dynamic_pointer_cast<ModelAPI_AttributeSelection>(aData->attribute(attributeID()));
- ResultBodyPtr aBody = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(mySelectedObject);
- if (aBody)
+ ResultPtr aBody = boost::dynamic_pointer_cast<ModelAPI_Result>(mySelectedObject);
+ if (aBody) {
aSelect->setValue(aBody, myShape);
+ updateObject(myFeature);
+ return true;
+ }
} else {
boost::shared_ptr<ModelAPI_AttributeReference> aRef =
boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(attributeID()));
if (!(aObject && aObject->isSame(mySelectedObject))) {
aRef->setValue(mySelectedObject);
updateObject(myFeature);
+ return true;
}
}
- return true;
+ return false;
}
//********************************************************************
ObjectPtr aObject = aObjects.first();
if ((!mySelectedObject) && (!aObject))
return;
- if (mySelectedObject && aObject && mySelectedObject->isSame(aObject))
+
+ // Check that the selected object is result (others can not be accepted)
+ ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(aObject);
+ if (!aRes)
+ return;
+
+ if (myFeature) {
+ // We can not select a result of our feature
+ const std::list<boost::shared_ptr<ModelAPI_Result>>& aResList = myFeature->results();
+ std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
+ for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
+ if ((*aIt) == aRes)
+ return;
+ }
+ }
+ // Check that object belongs to active document or PartSet
+ DocumentPtr aDoc = aRes->document();
+ SessionPtr aMgr = ModelAPI_Session::get();
+ if (!(aDoc == aMgr->activeDocument()) || (aDoc == aMgr->moduleDocument()))
+ return;
+
+ // Check that the result has a shape
+ GeomShapePtr aShape = ModelAPI_Tools::shape(aRes);
+ if (!aShape)
return;
// Get sub-shapes from local selection
- boost::shared_ptr<GeomAPI_Shape> aShape;
if (myUseSubShapes) {
NCollection_List<TopoDS_Shape> aShapeList;
- myWorkshop->selection()->selectedShapes(aShapeList);
+ std::list<ObjectPtr> aOwners;
+ myWorkshop->selection()->selectedShapes(aShapeList, aOwners);
if (aShapeList.Extent() > 0) {
aShape = boost::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
aShape->setImpl(new TopoDS_Shape(aShapeList.First()));
return;
}
setObject(aObject, aShape);
+ //activateSelection(false);
emit focusOutWidget(this);
}
}
//********************************************************************
void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObj, boost::shared_ptr<GeomAPI_Shape> theShape)
{
- if (mySelectedObject == theObj)
- return;
mySelectedObject = theObj;
myShape = theShape;
if (mySelectedObject) {
if (!myUseSubShapes) {
static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TOHIDE);
ModelAPI_EventCreator::get()->sendUpdated(mySelectedObject, anEvent);
- Events_Loop::loop()->flush(anEvent);
}
}
updateSelectionName();
bool ModuleBase_WidgetShapeSelector::isAccepted(const ObjectPtr theResult) const
{
ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(theResult);
- if (myFeature) {
- // We can not select a result of our feature
- const std::list<boost::shared_ptr<ModelAPI_Result>>& aRes = myFeature->results();
- std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
- for (aIt = aRes.cbegin(); aIt != aRes.cend(); ++aIt) {
- if ((*aIt) == aResult)
- return false;
- }
- }
- // Check that object belongs to active document or PartSet
- DocumentPtr aDoc = aResult->document();
- SessionPtr aMgr = ModelAPI_Session::get();
- if (!(aDoc == aMgr->activeDocument()) || (aDoc == aMgr->moduleDocument()))
- return false;
// Check that the shape of necessary type
boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);