// TDataStd_IntPackedMap - indexes of edges in composite element (for construction)
// TDataStd_Integer - type of the selected shape (for construction)
// TDF_Reference - from ReferenceAttribute, the context
-bool Model_AttributeSelection::setValue(const ResultPtr& theContext,
+bool Model_AttributeSelection::setValue(const ObjectPtr& theContext,
const std::shared_ptr<GeomAPI_Shape>& theSubShape, const bool theTemporarily)
{
- if (theTemporarily) { // just keep the stored without DF update
- myTmpContext = theContext;
+ if (theTemporarily &&
+ (!theContext.get() || theContext->groupName() != ModelAPI_Feature::group())) {
+ // just keep the stored without DF update
+ myTmpContext = std::dynamic_pointer_cast<ModelAPI_Result>(theContext);
myTmpSubShape = theSubShape;
owner()->data()->sendAttributeUpdated(this);
return true;
return false;
}
if (theContext->groupName() == ModelAPI_ResultBody::group()) {
+ ResultBodyPtr aContextBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theContext);
// do not select the whole shape for body:it is already must be in the data framework
// equal and null selected objects mean the same: object is equal to context,
- if (theContext->shape().get() &&
- (theContext->shape()->isEqual(theSubShape) || !theSubShape.get())) {
+ if (aContextBody->shape().get() &&
+ (aContextBody->shape()->isEqual(theSubShape) || !theSubShape.get())) {
aSelLab.ForgetAllAttributes(true);
TDataStd_UAttribute::Set(aSelLab, kSIMPLE_REF_ID);
} else {
- selectBody(theContext, theSubShape);
+ selectBody(aContextBody, theSubShape);
}
} else if (theContext->groupName() == ModelAPI_ResultConstruction::group()) {
+ ResultConstructionPtr aContextConstruction =
+ std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theContext);
aSelLab.ForgetAllAttributes(true); // to remove old selection data
std::shared_ptr<Model_ResultConstruction> aConstruction =
std::dynamic_pointer_cast<Model_ResultConstruction>(theContext);
std::shared_ptr<GeomAPI_Shape> aSubShape;
- if (theSubShape.get() && !theContext->shape()->isEqual(theSubShape))
+ if (theSubShape.get() && !aContextConstruction->shape()->isEqual(theSubShape))
aSubShape = theSubShape; // the whole context
if (aConstruction->isInfinite()) {
// For correct naming selection, put the shape into the naming structure.
// It seems sub-shapes are not needed: only this shape is (and can be ) selected.
TNaming_Builder aBuilder(aSelLab);
- aBuilder.Generated(theContext->shape()->impl<TopoDS_Shape>());
+ aBuilder.Generated(aContextConstruction->shape()->impl<TopoDS_Shape>());
}
int anIndex = aConstruction->select(theSubShape, owner()->document());
TDataStd_Integer::Set(aSelLab, anIndex);
} else if (theContext->groupName() == ModelAPI_ResultPart::group()) {
aSelLab.ForgetAllAttributes(true);
TDataStd_UAttribute::Set(aSelLab, kPART_REF_ID);
- selectPart(theContext, theSubShape);
+ selectPart(std::dynamic_pointer_cast<ModelAPI_Result>(theContext), theSubShape);
}
owner()->data()->sendAttributeUpdated(this);
}
void Model_AttributeSelection::setValueCenter(
- const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Edge>& theEdge,
+ const ObjectPtr& theContext, const std::shared_ptr<GeomAPI_Edge>& theEdge,
const CenterType theCenterType, const bool theTemporarily)
{
bool anUpdated = setValue(theContext, theEdge, theTemporarily);
return aResult;
}
+FeaturePtr Model_AttributeSelection::contextFeature() {
+ if (myTmpContext.get() || myTmpSubShape.get()) {
+ return FeaturePtr(); // feature can not be selected temporarily
+ }
+ return std::dynamic_pointer_cast<ModelAPI_Feature>(myRef.value());
+
+}
+
+
void Model_AttributeSelection::setObject(const std::shared_ptr<ModelAPI_Object>& theObject)
{
/// (used to remove immideately, without the following updates)
/// \returns true if attribute was updated
MODEL_EXPORT virtual bool setValue(
- const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
+ const ObjectPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
const bool theTemporarily = false);
/// Same as SetValue, but it takes an edge (on circular or elliptical curve)
/// and stores the vertex of the central point (for ellipse the first or the second focus point)
MODEL_EXPORT virtual void setValueCenter(
- const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Edge>& theEdge,
+ const ObjectPtr& theContext, const std::shared_ptr<GeomAPI_Edge>& theEdge,
const CenterType theCenterType,
const bool theTemporarily = false);
/// Returns the context of the selection (the whole shape owner)
MODEL_EXPORT virtual ResultPtr context();
+ /// Returns the context of the selection if the whole feature was selected
+ MODEL_EXPORT virtual FeaturePtr contextFeature();
+
/// Sets the feature object
MODEL_EXPORT virtual void setObject(const std::shared_ptr<ModelAPI_Object>& theObject);
#include <NCollection_List.hxx>
void Model_AttributeSelectionList::append(
- const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
+ const ObjectPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
const bool theTemporarily)
{
// do not use the degenerated edge as a shape, a list is not incremented in this case
}
if (myIsCashed && !theTemporarily) {
- myCash[theContext].push_back(theSubShape);
+ ResultPtr aResContext = std::dynamic_pointer_cast<ModelAPI_Result>(theContext);
+ if (aResContext.get())
+ myCash[aResContext].push_back(theSubShape);
}
int aNewTag = mySize->Get() + 1;
return mySize->Get();
}
-bool Model_AttributeSelectionList::isInList(const ResultPtr& theContext,
+bool Model_AttributeSelectionList::isInList(const ObjectPtr& theContext,
const std::shared_ptr<GeomAPI_Shape>& theSubShape,
const bool theTemporarily)
{
+ ResultPtr aResCont = std::dynamic_pointer_cast<ModelAPI_Result>(theContext);
if (myIsCashed) { // the cashing is active
- std::map<ResultPtr, std::list<std::shared_ptr<GeomAPI_Shape> > >::iterator aContext =
- myCash.find(theContext);
- if (aContext != myCash.end()) {
- // iterate shapes because "isSame" method must be called for each shape
- std::list<std::shared_ptr<GeomAPI_Shape> >::iterator aShapes = aContext->second.begin();
- for(; aShapes != aContext->second.end(); aShapes++) {
- if (!theSubShape.get()) {
- if (!aShapes->get() || (*aShapes)->isSame(aContext->first->shape()))
- return true;
- } else {
- // we need to call here isSame instead of isEqual to do not check shapes orientation
- if (theSubShape->isSame(*aShapes))
- return true;
+ if (aResCont.get()) {
+ std::map<ResultPtr, std::list<std::shared_ptr<GeomAPI_Shape> > >::iterator aContext =
+ myCash.find(aResCont);
+ if (aContext != myCash.end()) {
+ // iterate shapes because "isSame" method must be called for each shape
+ std::list<std::shared_ptr<GeomAPI_Shape> >::iterator aShapes = aContext->second.begin();
+ for(; aShapes != aContext->second.end(); aShapes++) {
+ if (!theSubShape.get()) {
+ if (!aShapes->get() || (*aShapes)->isSame(aContext->first->shape()))
+ return true;
+ } else {
+ // we need to call here isSame instead of isEqual to do not check shapes orientation
+ if (theSubShape->isSame(*aShapes))
+ return true;
+ }
}
}
+ return false;
}
- return false;
}
// no-cash method
for(int anIndex = size() - 1; anIndex >= 0; anIndex--) {
if (anAttr->context() == theContext) { // contexts are equal, so, check that values are also
std::shared_ptr<GeomAPI_Shape> aValue = anAttr->value();
if (!theSubShape.get()) {
- if (!aValue.get() || aValue->isSame(theContext->shape())) { // both are null
+ if (!aValue.get() || (aResCont.get() && aValue->isSame(aResCont->shape()))) {// both null
return true;
}
} else {
/// \param theTemporarily if it is true, do not store and name the added in the data framework
/// (used to remove immideately, without the following updates)
MODEL_EXPORT virtual void append(
- const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
+ const ObjectPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
const bool theTemporarily = false);
/// Adds the new reference to the end of the list by the naming name of the selected shape
/// \param theTemporarily if it is true, it checks also the temporary added item
/// \returns true if the pair is found in the attirbute
MODEL_EXPORT virtual bool isInList(
- const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
+ const ObjectPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
const bool theTemporarily = false);
/// The type of all elements selection
/// (used to remove immideately, without the following updates)
/// \returns true if attribute was updated
virtual bool setValue(
- const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
+ const ObjectPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
const bool theTemporarily = false) = 0;
/// Same as SetValue, but it takes an edge (on circular or elliptical curve)
/// and stores the vertex of the central point (for ellipse the first or the second focus point)
virtual void setValueCenter(
- const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Edge>& theEdge,
+ const ObjectPtr& theContext, const std::shared_ptr<GeomAPI_Edge>& theEdge,
const CenterType theCenterType,
const bool theTemporarily = false) = 0;
/// Returns the context of the selection (the whole shape owner)
virtual ResultPtr context() = 0;
+ /// Returns the context of the selection if the whole feature was selected
+ virtual std::shared_ptr<ModelAPI_Feature> contextFeature() = 0;
+
/// Updates the underlied selection due to the changes in the referenced objects
/// \returns false if update is failed
virtual bool update() = 0;
/// \param theSubShape selected sub-shape (if null, the whole context is selected)
/// \param theTemporarily if it is true, do not store and name the added in the data framework
/// (used to remove immediately, without the following updates)
- virtual void append(const ResultPtr& theContext,
+ virtual void append(const ObjectPtr& theContext,
const std::shared_ptr<GeomAPI_Shape>& theSubShape,
const bool theTemporarily = false) = 0;
/// \param theTemporarily if it is true, it checks also the temporary added item
/// \returns true if the pair is found in the attirbute
virtual bool isInList(
- const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
+ const ObjectPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
const bool theTemporarily = false) = 0;
/// The type of all elements selection